/// <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);
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        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);
                }
            }
        }
Пример #4
0
        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();
            }
        }
Пример #5
0
        protected override async Task OnFirstAfterRenderAsync()
        {
            dotNetObjectRef = dotNetObjectRef ?? JSRunner.CreateDotNetObjectRef(new NumericEditAdapter(this));
            await JSRunner.InitializeNumericEdit(dotNetObjectRef, ElementId, ElementRef, Decimals, DecimalsSeparator, Step);

            await base.OnFirstAfterRenderAsync();
        }
Пример #6
0
        public override void Dispose()
        {
            JSRunner.DestroyNumericEdit(ElementId, ElementRef);
            JSRunner.DisposeDotNetObjectRef(dotNetObjectRef);

            base.Dispose();
        }
Пример #7
0
        /// <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);
        }
Пример #8
0
        /// <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();
            }
        }
Пример #9
0
        /// <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);
        }
Пример #10
0
        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);
            }
        }
Пример #11
0
        /// <inheritdoc/>
        protected async Task OnClickHandler( MouseEventArgs e )
        {
            if ( Disabled || ReadOnly )
                return;

            await JSRunner.ActivateDatePicker( ElementId, DateFormat );
        }
Пример #12
0
        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();
        }
Пример #13
0
        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();
        }
Пример #14
0
        /// <inheritdoc/>
        protected override async Task OnFirstAfterRenderAsync()
        {
            dotNetObjectRef ??= JSRunner.CreateDotNetObjectRef(new FileEditAdapter(this));

            await JSRunner.InitializeFileEdit(dotNetObjectRef, ElementRef, ElementId);

            await base.OnFirstAfterRenderAsync();
        }
Пример #15
0
        protected override void Dispose(bool disposing)
        {
            if (disposing && Rendered)
            {
                JSRunner.DestroyTextEdit(ElementRef, ElementId);
            }

            base.Dispose(disposing);
        }
Пример #16
0
        /// <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);
        }
Пример #17
0
        protected async Task OnClickHandler()
        {
            if (!string.IsNullOrEmpty(anchorTarget))
            {
                await JSRunner.ScrollIntoView(anchorTarget);
            }

            await Clicked.InvokeAsync(null);
        }
Пример #18
0
        protected override void OnInitialized()
        {
            ExecuteAfterRender(async() =>
            {
                await JSRunner.InitializeTooltip(ElementId, ElementRef);
            });

            base.OnInitialized();
        }
Пример #19
0
        /// <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));
        }
Пример #20
0
        /// <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);
        }
Пример #21
0
        /// <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);
        }
Пример #22
0
        /// <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);
        }
Пример #23
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                JSRunner.DestroyButton(ElementId);
            }

            base.Dispose(disposing);
        }
Пример #24
0
        /// <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();
            }
        }
Пример #25
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                JSRunner.DestroyNumericEdit(ElementId, ElementRef);
                JSRunner.DisposeDotNetObjectRef(dotNetObjectRef);
            }

            base.Dispose(disposing);
        }
Пример #26
0
        /// <inheritdoc/>
        protected override void Dispose(bool disposing)
        {
            if (disposing && Rendered)
            {
                JSRunner.DestroyFileEdit(ElementRef, ElementId);
                JSRunner.DisposeDotNetObjectRef(dotNetObjectRef);
            }

            base.Dispose(disposing);
        }
Пример #27
0
        public void Dispose()
        {
            // make sure to unregister listener
            if (isRegistered)
            {
                isRegistered = false;

                JSRunner.UnregisterClosableComponent(this);
                JSRunner.DisposeDotNetObjectRef(dotNetObjectRef);
            }
        }
Пример #28
0
        protected override async Task OnFirstAfterRenderAsync()
        {
            dotNetObjectRef ??= JSRunner.CreateDotNetObjectRef(new BreakpointActivatorAdapter(this));

            if (Rendered)
            {
                _ = JSRunner.RegisterBreakpointComponent(dotNetObjectRef, ElementId);
            }

            await base.OnFirstAfterRenderAsync();
        }
Пример #29
0
        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();
        }
Пример #30
0
        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);
            }
        }