/// <summary> /// Disposes all the used resources. /// </summary> /// <param name="disposing">True if object is disposing.</param> protected override async ValueTask DisposeAsync(bool disposing) { if (disposing && Rendered) { // make sure to unregister listener if (jsRegistered) { jsRegistered = false; var task = JSRunner.UnregisterClosableComponent(this); try { await task; } catch when(task.IsCanceled) { } } DisposeDotNetObjectRef(dotNetObjectRef); dotNetObjectRef = null; if (Theme != null) { Theme.Changed -= OnThemeChanged; } } await base.DisposeAsync(disposing); }
/// <inheritdoc/> protected override async ValueTask DisposeAsync(bool disposing) { if (disposing && Rendered) { var task = JSRunner.DestroyFileEdit(ElementRef, ElementId); try { await task; } catch { if (!task.IsCanceled) { throw; } } DisposeDotNetObjectRef(dotNetObjectRef); LocalizerService.LocalizationChanged -= OnLocalizationChanged; } await base.DisposeAsync(disposing); }
protected override async Task <ParseValue <IReadOnlyList <TValue> > > ParseValueFromStringAsync(string value) { if (string.IsNullOrEmpty(value)) { return(ParseValue <IReadOnlyList <TValue> > .Empty); } if (Multiple) { // when multiple selection is enabled we need to use javascript to get the list of selected items var multipleValues = await JSRunner.GetSelectedOptions <TValue>(ElementId); return(new ParseValue <IReadOnlyList <TValue> >(true, multipleValues, null)); } else { if (Converters.TryChangeType <TValue>(value, out var result)) { return(new ParseValue <IReadOnlyList <TValue> >(true, new TValue[] { result }, null)); } else { return(ParseValue <IReadOnlyList <TValue> > .Empty); } } }
public override async Task SetParametersAsync(ParameterView parameters) { await base.SetParametersAsync(parameters); if (Multiple && parameters.TryGetValue <IReadOnlyList <TValue> >(nameof(SelectedValues), out var selectedValues)) { // For Multiple mode we need to update select options DOM through the javascript or otherwise // the newly selected values would not be re-rendered and not visible on the UI. ExecuteAfterRender(async() => await JSRunner.SetSelectedOptions(ElementId, selectedValues)); } if (ParentValidation != null) { if (Multiple) { if (parameters.TryGetValue <Expression <Func <IReadOnlyList <TValue> > > >(nameof(SelectedValuesExpression), out var expression)) { await ParentValidation.InitializeInputExpression(expression); } } else { if (parameters.TryGetValue <Expression <Func <TValue> > >(nameof(SelectedValueExpression), out var expression)) { await ParentValidation.InitializeInputExpression(expression); } } await InitializeValidation(); } }
protected override async Task OnFirstAfterRenderAsync() { dotNetObjectRef = dotNetObjectRef ?? JSRunner.CreateDotNetObjectRef(new NumericEditAdapter(this)); await JSRunner.InitializeNumericEdit(dotNetObjectRef, ElementId, ElementRef, Decimals, DecimalsSeparator, Step); await base.OnFirstAfterRenderAsync(); }
public override void Dispose() { JSRunner.DestroyNumericEdit(ElementId, ElementRef); JSRunner.DisposeDotNetObjectRef(dotNetObjectRef); base.Dispose(); }
/// <inheritdoc/> protected override async ValueTask DisposeAsync(bool disposing) { if (disposing) { // make sure to unregister listener if (Rendered) { var task = JSRunner.UnregisterBreakpointComponent(this); try { await task; } catch when(task.IsCanceled) { } DisposeDotNetObjectRef(dotNetObjectRef); dotNetObjectRef = null; } if (NavigationBreakpoint != Breakpoint.None) { NavigationManager.LocationChanged -= OnLocationChanged; } } await base.DisposeAsync(disposing); }
/// <inheritdoc/> public override async Task SetParametersAsync(ParameterView parameters) { var decimalsChanged = parameters.TryGetValue(nameof(Decimals), out int decimals) && !Decimals.IsEqual(decimals); if (Rendered && decimalsChanged) { ExecuteAfterRender(async() => await JSRunner.UpdateNumericEdit(ElementRef, ElementId, new { Decimals = new { Changed = decimalsChanged, Value = decimals }, })); } await base.SetParametersAsync(parameters); if (ParentValidation != null) { if (parameters.TryGetValue <Expression <Func <TValue> > >(nameof(ValueExpression), out var expression)) { await ParentValidation.InitializeInputExpression(expression); } if (parameters.TryGetValue <string>(nameof(Pattern), out var pattern)) { // make sure we get the newest value var value = parameters.TryGetValue <TValue>(nameof(Value), out var inValue) ? inValue : InternalValue; await ParentValidation.InitializeInputPattern(pattern, value); } await InitializeValidation(); } }
/// <inheritdoc/> protected override async ValueTask DisposeAsync(bool disposing) { if (disposing) { // remove button from parents ParentDropdown?.NotifyButtonRemoved(this); ParentAddons?.NotifyButtonRemoved(this); if (Rendered) { var task = JSRunner.DestroyButton(ElementId); try { await task; } catch when(task.IsCanceled) { } } if (command != null) { command.CanExecuteChanged -= OnCanExecuteChanged; } if (Theme != null) { Theme.Changed -= OnThemeChanged; } } await base.DisposeAsync(disposing); }
protected async Task HandleOnChanged(UIChangeEventArgs e) { if (IsMultiple) { // when multiple selection is enabled we need to use javascript to get the list of selected items internalMultiValue = await JSRunner.GetSelectedOptions <TValue>(ElementId); // changed event must be called before validation await SelectedValuesChanged.InvokeAsync(internalMultiValue); ParentValidation?.UpdateInputValue(internalMultiValue); } else { if (Converters.TryChangeType <TValue>(e.Value, out var value)) { internalValue = value; } else { internalValue = default; } // changed event must be called before validation await SelectedValueChanged.InvokeAsync(internalValue); ParentValidation?.UpdateInputValue(internalValue); } }
/// <inheritdoc/> protected async Task OnClickHandler( MouseEventArgs e ) { if ( Disabled || ReadOnly ) return; await JSRunner.ActivateDatePicker( ElementId, DateFormat ); }
private void HandleOpenState(bool isOpen) { if (modalBackdrop != null) { modalBackdrop.IsOpen = isOpen; } // TODO: find a way to remove javascript if (isOpen) { ExecuteAfterRender(async() => { await JSRunner.AddClassToBody("modal-open"); }); } else { ExecuteAfterRender(async() => { await JSRunner.RemoveClassFromBody("modal-open"); }); } DirtyClasses(); DirtyStyles(); }
protected override async Task OnFirstAfterRenderAsync() { dotNetObjectRef ??= JSRunner.CreateDotNetObjectRef(new BreakpointActivatorAdapter(this)); if (Rendered) { _ = JSRunner.RegisterBreakpointComponent(dotNetObjectRef, ElementId); if (Mode != BarMode.Horizontal) { // Check if we need to collapse the Bar based on the current screen width against the breakpoint defined for this component. // This needs to be run to set the inital state, RegisterBreakpointComponent and OnBreakpoint will handle // additional changes to responsive breakpoints from there. isBroken = BreakpointActivatorAdapter.IsBroken(Breakpoint, await JSRunner.GetBreakpoint()); if (Visible == isBroken) { Visible = !isBroken; StateHasChanged(); } } } await base.OnFirstAfterRenderAsync(); }
/// <inheritdoc/> protected override async Task OnFirstAfterRenderAsync() { dotNetObjectRef ??= JSRunner.CreateDotNetObjectRef(new FileEditAdapter(this)); await JSRunner.InitializeFileEdit(dotNetObjectRef, ElementRef, ElementId); await base.OnFirstAfterRenderAsync(); }
protected override void Dispose(bool disposing) { if (disposing && Rendered) { JSRunner.DestroyTextEdit(ElementRef, ElementId); } base.Dispose(disposing); }
/// <summary> /// Makes sure that the table header is properly sized. /// </summary> /// <returns>A task that represents the asynchronous operation.</returns> protected virtual ValueTask InitializeTableFixedHeader() { if (FixedHeader) { return(JSRunner.InitializeTableFixedHeader(ElementRef, ElementId)); } return(ValueTask.CompletedTask); }
protected async Task OnClickHandler() { if (!string.IsNullOrEmpty(anchorTarget)) { await JSRunner.ScrollIntoView(anchorTarget); } await Clicked.InvokeAsync(null); }
protected override void OnInitialized() { ExecuteAfterRender(async() => { await JSRunner.InitializeTooltip(ElementId, ElementRef); }); base.OnInitialized(); }
/// <inheritdoc/> public override Task SetParametersAsync(ParameterView parameters) { if (parameters.TryGetValue <string>(nameof(Text), out var text) && Text != text) { ExecuteAfterRender(async() => await JSRunner.UpdateTooltipContent(ElementRef, ElementId, text)); } return(base.SetParametersAsync(parameters)); }
/// <summary> /// Handles the element onclick event. /// </summary> /// <returns>A task that represents the asynchronous operation.</returns> protected async Task OnClickHandler(MouseEventArgs e) { if (Disabled || ReadOnly) { return; } await JSRunner.ActivateTimePicker(ElementRef, ElementId, Parsers.InternalTimeFormat); }
/// <summary> /// If table has <see cref="FixedHeader"/> enabled, it will scroll position to the provided row. /// </summary> /// <param name="row">Zero-based index of table row to scroll to.</param> /// <returns>A task that represents the asynchronous operation.</returns> public ValueTask ScrollToRow(int row) { if (FixedHeader) { return(JSRunner.FixedHeaderScrollTableToRow(ElementRef, ElementId, row)); } return(ValueTask.CompletedTask); }
/// <summary> /// If table has <see cref="FixedHeader"/> enabled, it will scroll position to the provided pixels. /// </summary> /// <param name="pixels">Offset in pixels from the top of the table.</param> /// <returns>A task that represents the asynchronous operation.</returns> public ValueTask ScrollToPixels(int pixels) { if (FixedHeader) { return(JSRunner.FixedHeaderScrollTableToPixels(ElementRef, ElementId, pixels)); } return(ValueTask.CompletedTask); }
protected override void Dispose(bool disposing) { if (disposing) { JSRunner.DestroyButton(ElementId); } base.Dispose(disposing); }
/// <inheritdoc/> public override async Task SetParametersAsync(ParameterView parameters) { var dateChanged = parameters.TryGetValue <TValue>(nameof(Date), out var date) && !Date.Equals(date); var minChanged = parameters.TryGetValue(nameof(Min), out DateTimeOffset? min) && !Min.IsEqual(min); var maxChanged = parameters.TryGetValue(nameof(Max), out DateTimeOffset? max) && !Max.IsEqual(max); var firstDayOfWeekChanged = parameters.TryGetValue(nameof(FirstDayOfWeek), out DayOfWeek firstDayOfWeek) && !FirstDayOfWeek.IsEqual(firstDayOfWeek); var displayFormatChanged = parameters.TryGetValue(nameof(DisplayFormat), out string displayFormat) && DisplayFormat != displayFormat; var timeAs24hrChanged = parameters.TryGetValue(nameof(TimeAs24hr), out bool timeAs24hr) && TimeAs24hr != timeAs24hr; if (dateChanged) { var dateString = FormatValueAsString(date); await CurrentValueHandler(dateString); if (Rendered) { ExecuteAfterRender(async() => await JSRunner.UpdateDatePickerValue(ElementRef, ElementId, dateString)); } } if (Rendered && (minChanged || maxChanged || firstDayOfWeekChanged || displayFormatChanged || timeAs24hrChanged)) { ExecuteAfterRender(async() => await JSRunner.UpdateDatePickerOptions(ElementRef, ElementId, new { FirstDayOfWeek = new { Changed = firstDayOfWeekChanged, Value = firstDayOfWeek }, DisplayFormat = new { Changed = displayFormatChanged, Value = DateTimeFormatConverter.Convert(displayFormat) }, TimeAs24hr = new { Changed = timeAs24hrChanged, Value = timeAs24hr }, Min = new { Changed = minChanged, Value = min?.ToString(DateFormat) }, Max = new { Changed = maxChanged, Value = max?.ToString(DateFormat) }, })); } // Let blazor do its thing! await base.SetParametersAsync(parameters); if (ParentValidation != null) { if (parameters.TryGetValue <Expression <Func <TValue> > >(nameof(DateExpression), out var expression)) { await ParentValidation.InitializeInputExpression(expression); } if (parameters.TryGetValue <string>(nameof(Pattern), out var pattern)) { // make sure we get the newest value var value = parameters.TryGetValue <TValue>(nameof(Date), out var inDate) ? inDate : InternalValue; await ParentValidation.InitializeInputPattern(pattern, value); } await InitializeValidation(); } }
protected override void Dispose(bool disposing) { if (disposing) { JSRunner.DestroyNumericEdit(ElementId, ElementRef); JSRunner.DisposeDotNetObjectRef(dotNetObjectRef); } base.Dispose(disposing); }
/// <inheritdoc/> protected override void Dispose(bool disposing) { if (disposing && Rendered) { JSRunner.DestroyFileEdit(ElementRef, ElementId); JSRunner.DisposeDotNetObjectRef(dotNetObjectRef); } base.Dispose(disposing); }
public void Dispose() { // make sure to unregister listener if (isRegistered) { isRegistered = false; JSRunner.UnregisterClosableComponent(this); JSRunner.DisposeDotNetObjectRef(dotNetObjectRef); } }
protected override async Task OnFirstAfterRenderAsync() { dotNetObjectRef ??= JSRunner.CreateDotNetObjectRef(new BreakpointActivatorAdapter(this)); if (Rendered) { _ = JSRunner.RegisterBreakpointComponent(dotNetObjectRef, ElementId); } await base.OnFirstAfterRenderAsync(); }
protected override async Task OnFirstAfterRenderAsync() { await JSRunner.InitializeTimePicker(ElementRef, ElementId, new { Default = FormatValueAsString(Time), Min = Min?.ToString(Parsers.InternalTimeFormat), Max = Max?.ToString(Parsers.InternalTimeFormat), }); await base.OnFirstAfterRenderAsync(); }
protected virtual async Task OnInputHandler(ChangeEventArgs e) { if (Options.ChangeTextOnKeyPress) { var caret = await JSRunner.GetCaret(ElementRef); await CurrentValueHandler(e?.Value?.ToString()); await JSRunner.SetCaret(ElementRef, caret); } }