Пример #1
0
 private async Task OnItemKeyDownAsync(int index)
 {
     if (KeyboardInteractions && !AppliedDisabled)
     {
         await OnKeyDown.InvokeAsync(index);
     }
 }
Пример #2
0
        private async void KeyDownHandler(KeyboardEventArgs args)
        {
            // check for a right key press so we can open the submenu if it exists
            if (args.Key == "ArrowRight" && !isSubMenuOpen)
            {
                await SetSubmenu.InvokeAsync(this.Key);
            }

            // send it to the parent ContextualMenu so we can use a left key press to close the menu.
            await OnKeyDown.InvokeAsync(args);
        }
Пример #3
0
        /// <summary>
        /// Overrides KeyDown event, intercepts Arrow Up/Down and uses them to add/substract the value manually by the step value.
        /// Relying on the browser mean the steps are each integer multiple from <see cref="Min"/> up until <see cref="Max"/>.
        /// This align the behaviour with the spinner buttons.
        /// </summary>
        /// <remarks>https://try.mudblazor.com/snippet/QamlkdvmBtrsuEtb</remarks>
        protected async Task InterceptArrowKey(KeyboardEventArgs obj)
        {
            if (Disabled || ReadOnly)
            {
                return;
            }

            if (obj.Type == "keydown")//KeyDown or repeat, blazor never fires InvokeKeyPress
            {
                if (obj.Key == "ArrowUp")
                {
                    _keyDownPreventDefault = true;
                    if (RuntimeLocation.IsServerSide)
                    {
                        var value = Value;
                        await Task.Delay(1);

                        Value = value;
                    }
                    await Increment();

                    return;
                }
                else if (obj.Key == "ArrowDown")
                {
                    _keyDownPreventDefault = true;
                    if (RuntimeLocation.IsServerSide)
                    {
                        var value = Value;
                        await Task.Delay(1);

                        Value = value;
                    }
                    await Decrement();

                    return;
                }
            }

            _keyDownPreventDefault = KeyDownPreventDefault;
            OnKeyDown.InvokeAsync(obj).AndForget();
        }
Пример #4
0
        protected async Task HandleKeydown(KeyboardEventArgs obj)
        {
            if (Disabled || ReadOnly)
            {
                return;
            }
            switch (obj.Key)
            {
            case "ArrowUp":
                await Increment();

                break;

            case "ArrowDown":
                await Decrement();

                break;
            }
            OnKeyDown.InvokeAsync(obj).AndForget();
        }
 private void KeyDownHandler(KeyboardEventArgs keyboardEventArgs)
 {
     OnKeyDown.InvokeAsync(keyboardEventArgs);
 }
Пример #6
0
 protected internal Task KeyDown(KeyboardEventArgs e)
 {
     return(OnKeyDown.InvokeAsync(e));
 }
Пример #7
0
        /// <summary>
        /// Overrides KeyDown event, intercepts Arrow Up/Down and uses them to add/substract the value manually by the step value.
        /// Relying on the browser mean the steps are each integer multiple from <see cref="Min"/> up until <see cref="Max"/>.
        /// This align the behaviour with the spinner buttons.
        /// </summary>
        /// <remarks>https://try.mudblazor.com/snippet/QamlkdvmBtrsuEtb</remarks>
        protected async Task InterceptKeydown(KeyboardEventArgs obj)
        {
            if (Disabled || ReadOnly)
            {
                return;
            }

            if (obj.Type == "keydown") //KeyDown or repeat, blazor never fires InvokeKeyPress
            {
                switch (obj.Key)
                {
                case "ArrowUp":
                    if (RuntimeLocation.IsServerSide)
                    {
                        if (!Immediate)
                        {
                            _key++;
                            await Task.Delay(1);
                            await Increment();

                            await Task.Delay(1);

                            _ = FocusAsync();
                        }
                        else
                        {
                            await Increment();
                        }
                    }
                    else
                    {
                        await Increment();

                        _elementReference.ForceRender(true);
                    }

                    return;

                case "ArrowDown":
                    if (RuntimeLocation.IsServerSide)
                    {
                        if (!Immediate)
                        {
                            _key++;
                            await Task.Delay(1);
                            await Decrement();

                            await Task.Delay(1);

                            _ = FocusAsync();
                        }
                        else
                        {
                            await Decrement();
                        }
                    }
                    else
                    {
                        await Decrement();

                        _elementReference.ForceRender(true);
                    }
                    return;

                // various navigation keys
                case "ArrowLeft":
                case "ArrowRight":
                case "Tab":
                case "Backspace":
                case "Delete":
                    break;

                //copy/paste
                case "v":
                case "c":
                    if (obj.CtrlKey is false)
                    {
                        _keyDownPreventDefault = true;
                        return;
                    }

                    break;

                default:
                    var acceptableKeyTypes = new Regex("^[0-9,.-]$");
                    var isMatch            = acceptableKeyTypes.Match(obj.Key).Success;
                    if (isMatch is false)
                    {
                        _keyDownPreventDefault = true;
                        return;
                    }
                    break;
                }
            }

            OnKeyDown.InvokeAsync(obj).AndForget();
        }
Пример #8
0
 protected virtual Task HandleKeyDown(KeyboardEventArgs args)
 {
     return(OnKeyDown.InvokeAsync(args));
 }
Пример #9
0
        public override async Task EventCallback(string eventName, string eventJson)
        {
            var jsonOptions = new JsonSerializerOptions {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            };

            switch (eventName)
            {
            case "OnDidCompositionEnd":
                await OnDidCompositionEnd.InvokeAsync(this);

                break;

            case "OnDidCompositionStart":
                await OnDidCompositionStart.InvokeAsync(this);

                break;

            case "OnContextMenu":
                if (eventJson != null)
                {
                    await OnContextMenu.InvokeAsync(
                        JsonSerializer.Deserialize <EditorMouseEvent>(eventJson, jsonOptions));
                }
                break;

            case "OnDidBlurEditorText":
                await OnDidBlurEditorText.InvokeAsync(this);

                break;

            case "OnDidBlurEditorWidget":
                await OnDidBlurEditorWidget.InvokeAsync(this);

                break;

            case "OnDidChangeConfiguration":
                await OnDidChangeConfiguration.InvokeAsync(this);

                break;

            case "OnDidChangeCursorPosition":
                await OnDidChangeCursorPosition.InvokeAsync(
                    JsonSerializer.Deserialize <CursorPositionChangedEvent>(eventJson, jsonOptions));

                break;

            case "OnDidChangeCursorSelection":
                await OnDidChangeCursorSelection.InvokeAsync(
                    JsonSerializer.Deserialize <CursorSelectionChangedEvent>(eventJson, jsonOptions));

                break;

            case "OnDidChangeModel":
                await OnDidChangeModel.InvokeAsync(
                    JsonSerializer.Deserialize <ModelChangedEvent>(eventJson, jsonOptions));

                break;

            case "OnDidChangeModelContent":
                await OnDidChangeModelContent.InvokeAsync(
                    JsonSerializer.Deserialize <ModelContentChangedEvent>(eventJson, jsonOptions));

                break;

            case "OnDidChangeModelDecorations":
                await OnDidChangeModelDecorations.InvokeAsync(
                    JsonSerializer.Deserialize <ModelDecorationsChangedEvent>(eventJson, jsonOptions));

                break;

            case "OnDidChangeModelLanguage":
                await OnDidChangeModelLanguage.InvokeAsync(
                    JsonSerializer.Deserialize <ModelLanguageChangedEvent>(eventJson, jsonOptions));

                break;

            case "OnDidChangeModelLanguageConfiguration":
                await OnDidChangeModelLanguageConfiguration.InvokeAsync(
                    JsonSerializer.Deserialize <ModelLanguageConfigurationChangedEvent>(eventJson, jsonOptions));

                break;

            case "OnDidChangeModelOptions":
                await OnDidChangeModelOptions.InvokeAsync(
                    JsonSerializer.Deserialize <ModelOptionsChangedEvent>(eventJson, jsonOptions));

                break;

            case "OnDidContentSizeChange":
                await OnDidContentSizeChange.InvokeAsync(
                    JsonSerializer.Deserialize <ContentSizeChangedEvent>(eventJson, jsonOptions));

                break;

            case "OnDidFocusEditorText":
                await OnDidFocusEditorText.InvokeAsync(this);

                break;

            case "OnDidFocusEditorWidget":
                await OnDidFocusEditorWidget.InvokeAsync(this);

                break;

            case "OnDidLayoutChange":
                if (eventJson != null)
                {
                    await OnDidLayoutChange.InvokeAsync(
                        JsonSerializer.Deserialize <EditorLayoutInfo>(eventJson, jsonOptions));
                }
                break;

            case "OnDidPaste":
                if (eventJson != null)
                {
                    await OnDidPaste.InvokeAsync(JsonSerializer.Deserialize <PasteEvent>(eventJson, jsonOptions));
                }
                break;

            case "OnDidScrollChange":
                if (eventJson != null)
                {
                    await OnDidScrollChange.InvokeAsync(
                        JsonSerializer.Deserialize <ScrollEvent>(eventJson, jsonOptions));
                }
                break;

            case "OnKeyDown":
                if (eventJson != null)
                {
                    await OnKeyDown.InvokeAsync(JsonSerializer.Deserialize <KeyboardEvent>(eventJson, jsonOptions));
                }
                break;

            case "OnKeyUp":
                if (eventJson != null)
                {
                    await OnKeyUp.InvokeAsync(JsonSerializer.Deserialize <KeyboardEvent>(eventJson, jsonOptions));
                }
                break;

            case "OnMouseDown":
                if (eventJson != null)
                {
                    await OnMouseDown.InvokeAsync(
                        JsonSerializer.Deserialize <EditorMouseEvent>(eventJson, jsonOptions));
                }
                break;

            case "OnMouseLeave":
                if (eventJson != null)
                {
                    await OnMouseLeave.InvokeAsync(
                        JsonSerializer.Deserialize <EditorMouseEvent>(eventJson, jsonOptions));
                }
                break;

            case "OnMouseMove":
                if (eventJson != null)
                {
                    await OnMouseMove.InvokeAsync(
                        JsonSerializer.Deserialize <EditorMouseEvent>(eventJson, jsonOptions));
                }
                break;

            case "OnMouseUp":
                if (eventJson != null)
                {
                    await OnMouseUp.InvokeAsync(
                        JsonSerializer.Deserialize <EditorMouseEvent>(eventJson, jsonOptions));
                }
                break;
            }

            await base.EventCallback(eventName, eventJson);
        }
Пример #10
0
        /// <summary>
        /// Overrides KeyDown event, intercepts Arrow Up/Down and uses them to add/substract the value manually by the step value.
        /// Relying on the browser mean the steps are each integer multiple from <see cref="Min"/> up until <see cref="Max"/>.
        /// This align the behaviour with the spinner buttons.
        /// </summary>
        /// <remarks>https://try.mudblazor.com/snippet/QamlkdvmBtrsuEtb</remarks>
        protected async Task InterceptKeydown(KeyboardEventArgs obj)
        {
            if (Disabled || ReadOnly)
            {
                return;
            }
            //Server side and WASM have different (opposite) behaviour. We need to set initial value false on BSS (line 24) and true on WASM (line 204).
            //Changing _keyDownPreventDefault value didn't work with Increment or Decrement methods in this method, so it have to be determined false before the method starts.
            if (RuntimeLocation.IsClientSide)
            {
                _keyDownPreventDefault = false;
            }
            if (obj.Type == "keydown") //KeyDown or repeat, blazor never fires InvokeKeyPress
            {
                switch (obj.Key)
                {
                case "ArrowUp":
                    _key++;
                    await Task.Delay(1);
                    await Increment();

                    await Task.Delay(1);

                    await _elementReference.FocusAsync();

                    return;

                case "ArrowDown":
                    _key++;
                    await Task.Delay(1);
                    await Decrement();

                    await Task.Delay(1);

                    await _elementReference.FocusAsync();

                    return;

                // various navigation keys
                case "ArrowLeft":
                case "ArrowRight":
                case "Tab":
                case "Backspace":
                case "Delete":
                case "Enter":
                case "NumpadEnter":
                    break;

                //copy/paste
                case "v":
                case "c":
                case "a":
                    if (obj.CtrlKey is false)
                    {
                        _keyDownPreventDefault = true;
                        _key++;
                        StateHasChanged();
                        await Task.Delay(1);

                        await _elementReference.FocusAsync();

                        return;
                    }

                    break;

                default:
                    //Check the shift key for AZERTY keyboard support 'Shift' and copy, paste, select all execution for 'Ctrl'.
                    if (obj.Key != "Shift" && obj.Key != "Control")
                    {
                        var acceptableKeyTypes = new Regex("^[0-9,.-]$");
                        var isMatch            = acceptableKeyTypes.Match(obj.Key).Success;
                        if (isMatch is false)
                        {
                            _keyDownPreventDefault = true;
                            _key++;
                            StateHasChanged();
                            await Task.Delay(1);

                            await _elementReference.FocusAsync();

                            return;
                        }
                        break;
                    }
                    else
                    {
                        return;
                    }
                }
            }
            //Component will work properly even we delete this line.
            OnKeyDown.InvokeAsync(obj).AndForget();
        }
Пример #11
0
        /// <summary>
        /// Overrides KeyDown event, intercepts Arrow Up/Down and uses them to add/substract the value manually by the step value.
        /// Relying on the browser mean the steps are each integer multiple from <see cref="Min"/> up until <see cref="Max"/>.
        /// This aligns the behaviour with the spinner buttons.
        /// </summary>
        /// <remarks>https://try.mudblazor.com/snippet/QamlkdvmBtrsuEtb</remarks>
        protected async Task InterceptKeydown(KeyboardEventArgs obj)
        {
            if (Disabled || ReadOnly)
            {
                return;
            }
            //Server side and WASM have different (opposite) behaviour. We need to set initial value false on BSS and true on WASM
            if (RuntimeLocation.IsClientSide)
            {
                _keyDownPreventDefault = false;
            }
            if (obj.Type == "keydown") //KeyDown or repeat, blazor never fires InvokeKeyPress
            {
                switch (obj.Key)
                {
                case "ArrowUp":
                    _key++;
                    await Task.Delay(1);
                    await Increment();

                    await Task.Delay(1);

                    await _elementReference.FocusAsync();

                    break;

                case "ArrowDown":
                    _key++;
                    await Task.Delay(1);
                    await Decrement();

                    await Task.Delay(1);

                    await _elementReference.FocusAsync();

                    break;

                case "ArrowLeft":
                case "ArrowRight":
                case "Tab":
                case "Backspace":
                case "Delete":
                case "Enter":
                case "NumpadEnter":
                case "Home":
                case "End":
                    break;

                //copy/paste
                case "v":
                case "c":
                case "a":
                    if (obj.CtrlKey is false)
                    {
                        _keyDownPreventDefault = true;
                        _key++;
                        StateHasChanged();
                        await Task.Delay(1);

                        await _elementReference.FocusAsync();
                    }
                    break;

                default:
                    //Check the shift key for AZERTY keyboard support 'Shift' and copy, paste, select all execution for 'Ctrl'.
                    if (obj.Key != "Shift" && obj.Key != "Control")
                    {
                        var acceptableKeyTypes = new Regex("^[0-9,.-]$");
                        var isMatch            = acceptableKeyTypes.Match(obj.Key).Success;
                        if (isMatch is false)
                        {
                            _keyDownPreventDefault = true;
                            _key++;
                            StateHasChanged();
                            await Task.Delay(1);

                            await _elementReference.FocusAsync();
                        }
                    }
                    break;
                }
            }
            OnKeyDown.InvokeAsync(obj).AndForget();
        }