@wordpress/block-editor 8.4.0 → 8.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +56 -19
- package/build/components/alignment-control/index.js +13 -6
- package/build/components/alignment-control/index.js.map +1 -1
- package/build/components/block-alignment-control/index.js +13 -6
- package/build/components/block-alignment-control/index.js.map +1 -1
- package/build/components/block-draggable/index.js +2 -3
- package/build/components/block-draggable/index.js.map +1 -1
- package/build/components/block-icon/index.js +4 -0
- package/build/components/block-icon/index.js.map +1 -1
- package/build/components/block-inspector/index.js +6 -1
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +1 -6
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-block-props/use-focus-first-element.js +14 -17
- package/build/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
- package/build/components/block-list/use-block-props/use-focus-handler.js +7 -1
- package/build/components/block-list/use-block-props/use-focus-handler.js.map +1 -1
- package/build/components/block-list-appender/index.js +6 -1
- package/build/components/block-list-appender/index.js.map +1 -1
- package/build/components/block-lock/menu-item.js +9 -0
- package/build/components/block-lock/menu-item.js.map +1 -1
- package/build/components/block-lock/modal.js +4 -13
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-lock/toolbar.js +11 -3
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-mover/index.js +4 -0
- package/build/components/block-mover/index.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +50 -5
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-switcher/index.js +1 -1
- package/build/components/block-switcher/index.js.map +1 -1
- package/build/components/block-title/index.js +2 -2
- package/build/components/block-title/index.js.map +1 -1
- package/build/components/block-title/use-block-display-title.js +1 -1
- package/build/components/block-title/use-block-display-title.js.map +1 -1
- package/build/components/block-toolbar/block-name-context.js +17 -0
- package/build/components/block-toolbar/block-name-context.js.map +1 -0
- package/build/components/block-toolbar/block-toolbar-last-item.js +20 -0
- package/build/components/block-toolbar/block-toolbar-last-item.js.map +1 -0
- package/build/components/block-toolbar/index.js +20 -5
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-tools/index.js +0 -16
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/block-variation-transforms/index.js +92 -47
- package/build/components/block-variation-transforms/index.js.map +1 -1
- package/build/components/block-vertical-alignment-control/index.js +13 -6
- package/build/components/block-vertical-alignment-control/index.js.map +1 -1
- package/build/components/contrast-checker/index.js +4 -0
- package/build/components/contrast-checker/index.js.map +1 -1
- package/build/components/convert-to-group-buttons/index.js +8 -0
- package/build/components/convert-to-group-buttons/index.js.map +1 -1
- package/build/components/convert-to-group-buttons/toolbar.js +105 -0
- package/build/components/convert-to-group-buttons/toolbar.js.map +1 -0
- package/build/components/copy-handler/index.js +4 -0
- package/build/components/copy-handler/index.js.map +1 -1
- package/build/components/font-sizes/font-size-picker.js +4 -0
- package/build/components/font-sizes/font-size-picker.js.map +1 -1
- package/build/components/iframe/index.js +6 -9
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/index.js +18 -0
- package/build/components/index.js.map +1 -1
- package/build/components/justify-content-control/index.js +13 -6
- package/build/components/justify-content-control/index.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js +1 -1
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/line-height-control/index.js +10 -3
- package/build/components/line-height-control/index.js.map +1 -1
- package/build/components/list-view/block-select-button.js +25 -6
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/block.js +5 -1
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +1 -1
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/media-replace-flow/index.js +4 -0
- package/build/components/media-replace-flow/index.js.map +1 -1
- package/build/components/multi-selection-inspector/index.js +1 -1
- package/build/components/multi-selection-inspector/index.js.map +1 -1
- package/build/components/rich-text/index.js +26 -4
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/split-value.js +12 -2
- package/build/components/rich-text/split-value.js.map +1 -1
- package/build/components/rich-text/use-firefox-compat.js +49 -0
- package/build/components/rich-text/use-firefox-compat.js.map +1 -0
- package/build/components/rich-text/use-input-rules.js +34 -2
- package/build/components/rich-text/use-input-rules.js.map +1 -1
- package/build/components/skip-to-selected-block/index.js +4 -0
- package/build/components/skip-to-selected-block/index.js.map +1 -1
- package/build/components/writing-flow/index.js +9 -1
- package/build/components/writing-flow/index.js.map +1 -1
- package/build/components/writing-flow/use-arrow-nav.js +3 -44
- package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build/components/writing-flow/use-click-selection.js +68 -0
- package/build/components/writing-flow/use-click-selection.js.map +1 -0
- package/build/components/writing-flow/use-drag-selection.js +134 -0
- package/build/components/writing-flow/use-drag-selection.js.map +1 -0
- package/build/components/writing-flow/use-input.js +116 -0
- package/build/components/writing-flow/use-input.js.map +1 -0
- package/build/components/writing-flow/use-multi-selection.js +18 -38
- package/build/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build/components/writing-flow/use-selection-observer.js +161 -0
- package/build/components/writing-flow/use-selection-observer.js.map +1 -0
- package/build/components/writing-flow/use-tab-nav.js +1 -8
- package/build/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build/hooks/border-color.js +3 -3
- package/build/hooks/border-color.js.map +1 -1
- package/build/hooks/border.js +0 -14
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/color.js +20 -17
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/font-family.js +5 -1
- package/build/hooks/font-family.js.map +1 -1
- package/build/hooks/font-size.js +4 -2
- package/build/hooks/font-size.js.map +1 -1
- package/build/hooks/gap.js +23 -16
- package/build/hooks/gap.js.map +1 -1
- package/build/hooks/layout.js +7 -2
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/style.js +34 -3
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/utils.js +29 -0
- package/build/hooks/utils.js.map +1 -1
- package/build/layouts/flex.js +76 -12
- package/build/layouts/flex.js.map +1 -1
- package/build/layouts/flow.js +9 -4
- package/build/layouts/flow.js.map +1 -1
- package/build/store/actions.js +297 -51
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +5 -2
- package/build/store/defaults.js.map +1 -1
- package/build/store/reducer.js +25 -13
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +142 -18
- package/build/store/selectors.js.map +1 -1
- package/build/utils/dom.js +2 -1
- package/build/utils/dom.js.map +1 -1
- package/build-module/components/alignment-control/index.js +12 -4
- package/build-module/components/alignment-control/index.js.map +1 -1
- package/build-module/components/block-alignment-control/index.js +12 -4
- package/build-module/components/block-alignment-control/index.js.map +1 -1
- package/build-module/components/block-draggable/index.js +2 -3
- package/build-module/components/block-draggable/index.js.map +1 -1
- package/build-module/components/block-icon/index.js +4 -0
- package/build-module/components/block-icon/index.js.map +1 -1
- package/build-module/components/block-inspector/index.js +6 -1
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +1 -4
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-focus-first-element.js +15 -17
- package/build-module/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-focus-handler.js +7 -1
- package/build-module/components/block-list/use-block-props/use-focus-handler.js.map +1 -1
- package/build-module/components/block-list-appender/index.js +6 -1
- package/build-module/components/block-list-appender/index.js.map +1 -1
- package/build-module/components/block-lock/menu-item.js +9 -0
- package/build-module/components/block-lock/menu-item.js.map +1 -1
- package/build-module/components/block-lock/modal.js +5 -14
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-lock/toolbar.js +11 -3
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-mover/index.js +4 -0
- package/build-module/components/block-mover/index.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +50 -7
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-switcher/index.js +2 -2
- package/build-module/components/block-switcher/index.js.map +1 -1
- package/build-module/components/block-title/index.js +2 -2
- package/build-module/components/block-title/index.js.map +1 -1
- package/build-module/components/block-title/use-block-display-title.js +1 -1
- package/build-module/components/block-title/use-block-display-title.js.map +1 -1
- package/build-module/components/block-toolbar/block-name-context.js +9 -0
- package/build-module/components/block-toolbar/block-name-context.js.map +1 -0
- package/build-module/components/block-toolbar/block-toolbar-last-item.js +11 -0
- package/build-module/components/block-toolbar/block-toolbar-last-item.js.map +1 -0
- package/build-module/components/block-toolbar/index.js +16 -4
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-tools/index.js +0 -16
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/block-variation-transforms/index.js +95 -49
- package/build-module/components/block-variation-transforms/index.js.map +1 -1
- package/build-module/components/block-vertical-alignment-control/index.js +12 -4
- package/build-module/components/block-vertical-alignment-control/index.js.map +1 -1
- package/build-module/components/contrast-checker/index.js +4 -0
- package/build-module/components/contrast-checker/index.js.map +1 -1
- package/build-module/components/convert-to-group-buttons/index.js +2 -1
- package/build-module/components/convert-to-group-buttons/index.js.map +1 -1
- package/build-module/components/convert-to-group-buttons/toolbar.js +90 -0
- package/build-module/components/convert-to-group-buttons/toolbar.js.map +1 -0
- package/build-module/components/copy-handler/index.js +4 -0
- package/build-module/components/copy-handler/index.js.map +1 -1
- package/build-module/components/font-sizes/font-size-picker.js +4 -0
- package/build-module/components/font-sizes/font-size-picker.js.map +1 -1
- package/build-module/components/iframe/index.js +6 -9
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/index.js +2 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/justify-content-control/index.js +12 -4
- package/build-module/components/justify-content-control/index.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/index.js +1 -1
- package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/line-height-control/index.js +9 -2
- package/build-module/components/line-height-control/index.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +22 -6
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/block.js +5 -1
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +1 -1
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/media-replace-flow/index.js +4 -0
- package/build-module/components/media-replace-flow/index.js.map +1 -1
- package/build-module/components/multi-selection-inspector/index.js +2 -2
- package/build-module/components/multi-selection-inspector/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +25 -4
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/split-value.js +12 -2
- package/build-module/components/rich-text/split-value.js.map +1 -1
- package/build-module/components/rich-text/use-firefox-compat.js +39 -0
- package/build-module/components/rich-text/use-firefox-compat.js.map +1 -0
- package/build-module/components/rich-text/use-input-rules.js +35 -4
- package/build-module/components/rich-text/use-input-rules.js.map +1 -1
- package/build-module/components/skip-to-selected-block/index.js +4 -0
- package/build-module/components/skip-to-selected-block/index.js.map +1 -1
- package/build-module/components/writing-flow/index.js +5 -1
- package/build-module/components/writing-flow/index.js.map +1 -1
- package/build-module/components/writing-flow/use-arrow-nav.js +4 -45
- package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build-module/components/writing-flow/use-click-selection.js +57 -0
- package/build-module/components/writing-flow/use-click-selection.js.map +1 -0
- package/build-module/components/writing-flow/use-drag-selection.js +124 -0
- package/build-module/components/writing-flow/use-drag-selection.js.map +1 -0
- package/build-module/components/writing-flow/use-input.js +104 -0
- package/build-module/components/writing-flow/use-input.js.map +1 -0
- package/build-module/components/writing-flow/use-multi-selection.js +18 -37
- package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build-module/components/writing-flow/use-selection-observer.js +150 -0
- package/build-module/components/writing-flow/use-selection-observer.js.map +1 -0
- package/build-module/components/writing-flow/use-tab-nav.js +1 -9
- package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build-module/hooks/border-color.js +5 -5
- package/build-module/hooks/border-color.js.map +1 -1
- package/build-module/hooks/border.js +0 -12
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/color.js +19 -18
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/font-family.js +3 -1
- package/build-module/hooks/font-family.js.map +1 -1
- package/build-module/hooks/font-size.js +4 -3
- package/build-module/hooks/font-size.js.map +1 -1
- package/build-module/hooks/gap.js +22 -15
- package/build-module/hooks/gap.js.map +1 -1
- package/build-module/hooks/layout.js +7 -2
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/style.js +33 -3
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/utils.js +26 -0
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/layouts/flex.js +76 -13
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/layouts/flow.js +9 -5
- package/build-module/layouts/flow.js.map +1 -1
- package/build-module/store/actions.js +286 -49
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +5 -2
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/reducer.js +25 -13
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +138 -19
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/dom.js +2 -1
- package/build-module/utils/dom.js.map +1 -1
- package/build-style/style-rtl.css +107 -74
- package/build-style/style.css +107 -74
- package/build-types/utils/dom.d.ts.map +1 -1
- package/package.json +28 -28
- package/src/components/alignment-control/index.js +9 -4
- package/src/components/block-alignment-control/index.js +9 -4
- package/src/components/block-draggable/index.js +2 -5
- package/src/components/block-icon/index.js +3 -0
- package/src/components/block-inspector/index.js +4 -0
- package/src/components/block-list/style.scss +4 -5
- package/src/components/block-list/use-block-props/index.js +0 -5
- package/src/components/block-list/use-block-props/use-focus-first-element.js +19 -26
- package/src/components/block-list/use-block-props/use-focus-handler.js +8 -0
- package/src/components/block-list-appender/index.js +5 -0
- package/src/components/block-lock/menu-item.js +8 -1
- package/src/components/block-lock/modal.js +18 -13
- package/src/components/block-lock/style.scss +6 -3
- package/src/components/block-lock/toolbar.js +12 -2
- package/src/components/block-mover/index.js +3 -0
- package/src/components/block-mover/style.scss +4 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +62 -4
- package/src/components/block-switcher/index.js +2 -2
- package/src/components/block-switcher/style.scss +8 -1
- package/src/components/block-switcher/test/index.js +2 -2
- package/src/components/block-title/index.js +2 -2
- package/src/components/block-title/use-block-display-title.js +1 -1
- package/src/components/block-toolbar/block-name-context.js +8 -0
- package/src/components/block-toolbar/block-toolbar-last-item.js +12 -0
- package/src/components/block-toolbar/index.js +18 -2
- package/src/components/block-toolbar/style.scss +6 -0
- package/src/components/block-tools/index.js +0 -19
- package/src/components/block-tools/style.scss +3 -5
- package/src/components/block-variation-transforms/index.js +105 -36
- package/src/components/block-variation-transforms/style.scss +1 -1
- package/src/components/block-vertical-alignment-control/index.js +9 -4
- package/src/components/button-block-appender/style.scss +5 -1
- package/src/components/contrast-checker/index.js +3 -0
- package/src/components/convert-to-group-buttons/index.js +6 -1
- package/src/components/convert-to-group-buttons/toolbar.js +87 -0
- package/src/components/copy-handler/index.js +3 -0
- package/src/components/font-sizes/font-size-picker.js +3 -0
- package/src/components/iframe/index.js +5 -7
- package/src/components/index.js +2 -0
- package/src/components/justify-content-control/index.js +9 -4
- package/src/components/keyboard-shortcuts/index.js +1 -1
- package/src/components/line-height-control/index.js +8 -3
- package/src/components/list-view/block-select-button.js +21 -3
- package/src/components/list-view/block.js +8 -1
- package/src/components/list-view/branch.js +1 -1
- package/src/components/list-view/style.scss +56 -14
- package/src/components/media-placeholder/README.md +8 -0
- package/src/components/media-replace-flow/index.js +3 -0
- package/src/components/multi-selection-inspector/index.js +2 -2
- package/src/components/rich-text/index.js +24 -1
- package/src/components/rich-text/split-value.js +5 -1
- package/src/components/rich-text/use-firefox-compat.js +39 -0
- package/src/components/rich-text/use-input-rules.js +40 -3
- package/src/components/skip-to-selected-block/index.js +3 -0
- package/src/components/url-input/style.scss +3 -2
- package/src/components/writing-flow/index.js +8 -0
- package/src/components/writing-flow/readme.md +28 -0
- package/src/components/writing-flow/use-arrow-nav.js +4 -53
- package/src/components/writing-flow/use-click-selection.js +65 -0
- package/src/components/writing-flow/use-drag-selection.js +126 -0
- package/src/components/writing-flow/use-input.js +112 -0
- package/src/components/writing-flow/use-multi-selection.js +13 -36
- package/src/components/writing-flow/use-selection-observer.js +153 -0
- package/src/components/writing-flow/use-tab-nav.js +1 -11
- package/src/hooks/border-color.js +5 -5
- package/src/hooks/border.js +0 -13
- package/src/hooks/color.js +51 -24
- package/src/hooks/font-family.js +5 -2
- package/src/hooks/font-size.js +10 -7
- package/src/hooks/gap.js +25 -17
- package/src/hooks/layout.js +11 -1
- package/src/hooks/style.js +40 -4
- package/src/hooks/test/gap.js +25 -1
- package/src/hooks/test/style.js +94 -0
- package/src/hooks/test/utils.js +1 -1
- package/src/hooks/utils.js +26 -0
- package/src/layouts/flex.js +89 -5
- package/src/layouts/flow.js +15 -4
- package/src/store/actions.js +349 -32
- package/src/store/defaults.js +7 -2
- package/src/store/reducer.js +25 -10
- package/src/store/selectors.js +181 -24
- package/src/store/test/selectors.js +242 -5
- package/src/utils/dom.js +2 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/block-list/use-block-props/use-multi-selection.js +0 -205
- package/build/components/block-list/use-block-props/use-multi-selection.js.map +0 -1
- package/build/components/block-list/use-block-props/use-scroll-into-view.js +0 -77
- package/build/components/block-list/use-block-props/use-scroll-into-view.js.map +0 -1
- package/build-module/components/block-list/use-block-props/use-multi-selection.js +0 -192
- package/build-module/components/block-list/use-block-props/use-multi-selection.js.map +0 -1
- package/build-module/components/block-list/use-block-props/use-scroll-into-view.js +0 -63
- package/build-module/components/block-list/use-block-props/use-scroll-into-view.js.map +0 -1
- package/src/components/block-list/use-block-props/use-multi-selection.js +0 -227
- package/src/components/block-list/use-block-props/use-scroll-into-view.js +0 -73
|
@@ -28,10 +28,20 @@ function splitValue(_ref) {
|
|
|
28
28
|
|
|
29
29
|
if (!onReplace || !onSplit) {
|
|
30
30
|
return;
|
|
31
|
-
}
|
|
31
|
+
} // Ensure the value has a selection. This might happen when trying to split
|
|
32
|
+
// an empty value before there was a `selectionchange` event.
|
|
33
|
+
|
|
32
34
|
|
|
35
|
+
const {
|
|
36
|
+
start = 0,
|
|
37
|
+
end = 0
|
|
38
|
+
} = value;
|
|
39
|
+
const valueWithEnsuredSelection = { ...value,
|
|
40
|
+
start,
|
|
41
|
+
end
|
|
42
|
+
};
|
|
33
43
|
const blocks = [];
|
|
34
|
-
const [before, after] = (0, _richText.split)(
|
|
44
|
+
const [before, after] = (0, _richText.split)(valueWithEnsuredSelection);
|
|
35
45
|
const hasPastedBlocks = pastedBlocks.length > 0;
|
|
36
46
|
let lastPastedBlockIndex = -1; // Consider the after value to be the original it is not empty and the
|
|
37
47
|
// before value *is* empty.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/split-value.js"],"names":["splitValue","value","pastedBlocks","onReplace","onSplit","onSplitMiddle","multilineTag","blocks","before","after","hasPastedBlocks","length","lastPastedBlockIndex","isAfterOriginal","push","indexToSelect","initialPosition"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACO,SAASA,UAAT,OAOH;AAAA,MAPwB;AAC3BC,IAAAA,KAD2B;AAE3BC,IAAAA,YAAY,GAAG,EAFY;AAG3BC,IAAAA,SAH2B;AAI3BC,IAAAA,OAJ2B;AAK3BC,IAAAA,aAL2B;AAM3BC,IAAAA;AAN2B,GAOxB;;AACH,MAAK,CAAEH,SAAF,IAAe,CAAEC,OAAtB,EAAgC;AAC/B;AACA
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/split-value.js"],"names":["splitValue","value","pastedBlocks","onReplace","onSplit","onSplitMiddle","multilineTag","start","end","valueWithEnsuredSelection","blocks","before","after","hasPastedBlocks","length","lastPastedBlockIndex","isAfterOriginal","push","indexToSelect","initialPosition"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACO,SAASA,UAAT,OAOH;AAAA,MAPwB;AAC3BC,IAAAA,KAD2B;AAE3BC,IAAAA,YAAY,GAAG,EAFY;AAG3BC,IAAAA,SAH2B;AAI3BC,IAAAA,OAJ2B;AAK3BC,IAAAA,aAL2B;AAM3BC,IAAAA;AAN2B,GAOxB;;AACH,MAAK,CAAEH,SAAF,IAAe,CAAEC,OAAtB,EAAgC;AAC/B;AACA,GAHE,CAKH;AACA;;;AACA,QAAM;AAAEG,IAAAA,KAAK,GAAG,CAAV;AAAaC,IAAAA,GAAG,GAAG;AAAnB,MAAyBP,KAA/B;AACA,QAAMQ,yBAAyB,GAAG,EAAE,GAAGR,KAAL;AAAYM,IAAAA,KAAZ;AAAmBC,IAAAA;AAAnB,GAAlC;AACA,QAAME,MAAM,GAAG,EAAf;AACA,QAAM,CAAEC,MAAF,EAAUC,KAAV,IAAoB,qBAAOH,yBAAP,CAA1B;AACA,QAAMI,eAAe,GAAGX,YAAY,CAACY,MAAb,GAAsB,CAA9C;AACA,MAAIC,oBAAoB,GAAG,CAAC,CAA5B,CAZG,CAcH;AACA;;AACA,QAAMC,eAAe,GAAG,uBAASL,MAAT,KAAqB,CAAE,uBAASC,KAAT,CAA/C,CAhBG,CAkBH;AACA;AACA;AACA;;AACA,MAAK,CAAEC,eAAF,IAAqB,CAAE,uBAASF,MAAT,CAA5B,EAAgD;AAC/CD,IAAAA,MAAM,CAACO,IAAP,CACCb,OAAO,CACN,4BAAc;AACbH,MAAAA,KAAK,EAAEU,MADM;AAEbL,MAAAA;AAFa,KAAd,CADM,EAKN,CAAEU,eALI,CADR;AASAD,IAAAA,oBAAoB,IAAI,CAAxB;AACA;;AAED,MAAKF,eAAL,EAAuB;AACtBH,IAAAA,MAAM,CAACO,IAAP,CAAa,GAAGf,YAAhB;AACAa,IAAAA,oBAAoB,IAAIb,YAAY,CAACY,MAArC;AACA,GAHD,MAGO,IAAKT,aAAL,EAAqB;AAC3BK,IAAAA,MAAM,CAACO,IAAP,CAAaZ,aAAa,EAA1B;AACA,GAxCE,CA0CH;AACA;AACA;AACA;;;AACA,MACCQ,eAAe,GACZ,CAAE,uBAASD,KAAT,CADU,GAEZ,CAAEP,aAAF,IAAmB,CAAE,uBAASO,KAAT,CAHzB,EAIE;AACDF,IAAAA,MAAM,CAACO,IAAP,CACCb,OAAO,CACN,4BAAc;AACbH,MAAAA,KAAK,EAAEW,KADM;AAEbN,MAAAA;AAFa,KAAd,CADM,EAKNU,eALM,CADR;AASA,GA5DE,CA8DH;AACA;;;AACA,QAAME,aAAa,GAAGL,eAAe,GAAGE,oBAAH,GAA0B,CAA/D,CAhEG,CAkEH;AACA;;AACA,QAAMI,eAAe,GAAGN,eAAe,GAAG,CAAC,CAAJ,GAAQ,CAA/C;AAEAV,EAAAA,SAAS,CAAEO,MAAF,EAAUQ,aAAV,EAAyBC,eAAzB,CAAT;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { isEmpty, split, toHTMLString } from '@wordpress/rich-text';\n\n/*\n * Signals to the RichText owner that the block can be replaced with two blocks\n * as a result of splitting the block by pressing enter, or with blocks as a\n * result of splitting the block by pasting block content in the instance.\n */\nexport function splitValue( {\n\tvalue,\n\tpastedBlocks = [],\n\tonReplace,\n\tonSplit,\n\tonSplitMiddle,\n\tmultilineTag,\n} ) {\n\tif ( ! onReplace || ! onSplit ) {\n\t\treturn;\n\t}\n\n\t// Ensure the value has a selection. This might happen when trying to split\n\t// an empty value before there was a `selectionchange` event.\n\tconst { start = 0, end = 0 } = value;\n\tconst valueWithEnsuredSelection = { ...value, start, end };\n\tconst blocks = [];\n\tconst [ before, after ] = split( valueWithEnsuredSelection );\n\tconst hasPastedBlocks = pastedBlocks.length > 0;\n\tlet lastPastedBlockIndex = -1;\n\n\t// Consider the after value to be the original it is not empty and the\n\t// before value *is* empty.\n\tconst isAfterOriginal = isEmpty( before ) && ! isEmpty( after );\n\n\t// Create a block with the content before the caret if there's no pasted\n\t// blocks, or if there are pasted blocks and the value is not empty. We do\n\t// not want a leading empty block on paste, but we do if split with e.g. the\n\t// enter key.\n\tif ( ! hasPastedBlocks || ! isEmpty( before ) ) {\n\t\tblocks.push(\n\t\t\tonSplit(\n\t\t\t\ttoHTMLString( {\n\t\t\t\t\tvalue: before,\n\t\t\t\t\tmultilineTag,\n\t\t\t\t} ),\n\t\t\t\t! isAfterOriginal\n\t\t\t)\n\t\t);\n\t\tlastPastedBlockIndex += 1;\n\t}\n\n\tif ( hasPastedBlocks ) {\n\t\tblocks.push( ...pastedBlocks );\n\t\tlastPastedBlockIndex += pastedBlocks.length;\n\t} else if ( onSplitMiddle ) {\n\t\tblocks.push( onSplitMiddle() );\n\t}\n\n\t// If there's pasted blocks, append a block with non empty content / after\n\t// the caret. Otherwise, do append an empty block if there is no\n\t// `onSplitMiddle` prop, but if there is and the content is empty, the\n\t// middle block is enough to set focus in.\n\tif (\n\t\thasPastedBlocks\n\t\t\t? ! isEmpty( after )\n\t\t\t: ! onSplitMiddle || ! isEmpty( after )\n\t) {\n\t\tblocks.push(\n\t\t\tonSplit(\n\t\t\t\ttoHTMLString( {\n\t\t\t\t\tvalue: after,\n\t\t\t\t\tmultilineTag,\n\t\t\t\t} ),\n\t\t\t\tisAfterOriginal\n\t\t\t)\n\t\t);\n\t}\n\n\t// If there are pasted blocks, set the selection to the last one. Otherwise,\n\t// set the selection to the second block.\n\tconst indexToSelect = hasPastedBlocks ? lastPastedBlockIndex : 1;\n\n\t// If there are pasted blocks, move the caret to the end of the selected\n\t// block Otherwise, retain the default value.\n\tconst initialPosition = hasPastedBlocks ? -1 : 0;\n\n\tonReplace( blocks, indexToSelect, initialPosition );\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useFirefoxCompat = useFirefoxCompat;
|
|
7
|
+
|
|
8
|
+
var _compose = require("@wordpress/compose");
|
|
9
|
+
|
|
10
|
+
var _data = require("@wordpress/data");
|
|
11
|
+
|
|
12
|
+
var _store = require("../../store");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* WordPress dependencies
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Internal dependencies
|
|
20
|
+
*/
|
|
21
|
+
function useFirefoxCompat() {
|
|
22
|
+
const {
|
|
23
|
+
isMultiSelecting
|
|
24
|
+
} = (0, _data.useSelect)(_store.store);
|
|
25
|
+
return (0, _compose.useRefEffect)(element => {
|
|
26
|
+
function onFocus() {
|
|
27
|
+
if (!isMultiSelecting()) {
|
|
28
|
+
return;
|
|
29
|
+
} // This is a little hack to work around focus issues with nested
|
|
30
|
+
// editable elements in Firefox. For some reason the editable child
|
|
31
|
+
// element sometimes regains focus, while it should not be focusable
|
|
32
|
+
// and focus should remain on the editable parent element.
|
|
33
|
+
// To do: try to find the cause of the shifting focus.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
const parentEditable = element.parentElement.closest('[contenteditable="true"]');
|
|
37
|
+
|
|
38
|
+
if (parentEditable) {
|
|
39
|
+
parentEditable.focus();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
element.addEventListener('focus', onFocus);
|
|
44
|
+
return () => {
|
|
45
|
+
element.removeEventListener('focus', onFocus);
|
|
46
|
+
};
|
|
47
|
+
}, []);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=use-firefox-compat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-firefox-compat.js"],"names":["useFirefoxCompat","isMultiSelecting","blockEditorStore","element","onFocus","parentEditable","parentElement","closest","focus","addEventListener","removeEventListener"],"mappings":";;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;AAGO,SAASA,gBAAT,GAA4B;AAClC,QAAM;AAAEC,IAAAA;AAAF,MAAuB,qBAAWC,YAAX,CAA7B;AACA,SAAO,2BAAgBC,OAAF,IAAe;AACnC,aAASC,OAAT,GAAmB;AAClB,UAAK,CAAEH,gBAAgB,EAAvB,EAA4B;AAC3B;AACA,OAHiB,CAKlB;AACA;AACA;AACA;AACA;;;AACA,YAAMI,cAAc,GAAGF,OAAO,CAACG,aAAR,CAAsBC,OAAtB,CACtB,0BADsB,CAAvB;;AAIA,UAAKF,cAAL,EAAsB;AACrBA,QAAAA,cAAc,CAACG,KAAf;AACA;AACD;;AAEDL,IAAAA,OAAO,CAACM,gBAAR,CAA0B,OAA1B,EAAmCL,OAAnC;AACA,WAAO,MAAM;AACZD,MAAAA,OAAO,CAACO,mBAAR,CAA6B,OAA7B,EAAsCN,OAAtC;AACA,KAFD;AAGA,GAxBM,EAwBJ,EAxBI,CAAP;AAyBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRefEffect } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\nexport function useFirefoxCompat() {\n\tconst { isMultiSelecting } = useSelect( blockEditorStore );\n\treturn useRefEffect( ( element ) => {\n\t\tfunction onFocus() {\n\t\t\tif ( ! isMultiSelecting() ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// This is a little hack to work around focus issues with nested\n\t\t\t// editable elements in Firefox. For some reason the editable child\n\t\t\t// element sometimes regains focus, while it should not be focusable\n\t\t\t// and focus should remain on the editable parent element.\n\t\t\t// To do: try to find the cause of the shifting focus.\n\t\t\tconst parentEditable = element.parentElement.closest(\n\t\t\t\t'[contenteditable=\"true\"]'\n\t\t\t);\n\n\t\t\tif ( parentEditable ) {\n\t\t\t\tparentEditable.focus();\n\t\t\t}\n\t\t}\n\n\t\telement.addEventListener( 'focus', onFocus );\n\t\treturn () => {\n\t\t\telement.removeEventListener( 'focus', onFocus );\n\t\t};\n\t}, [] );\n}\n"]}
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useInputRules = useInputRules;
|
|
7
7
|
|
|
8
|
+
var _lodash = require("lodash");
|
|
9
|
+
|
|
8
10
|
var _element = require("@wordpress/element");
|
|
9
11
|
|
|
10
12
|
var _compose = require("@wordpress/compose");
|
|
@@ -19,6 +21,10 @@ var _store = require("../../store");
|
|
|
19
21
|
|
|
20
22
|
var _preventEventDiscovery = require("./prevent-event-discovery");
|
|
21
23
|
|
|
24
|
+
/**
|
|
25
|
+
* External dependencies
|
|
26
|
+
*/
|
|
27
|
+
|
|
22
28
|
/**
|
|
23
29
|
* WordPress dependencies
|
|
24
30
|
*/
|
|
@@ -26,6 +32,30 @@ var _preventEventDiscovery = require("./prevent-event-discovery");
|
|
|
26
32
|
/**
|
|
27
33
|
* Internal dependencies
|
|
28
34
|
*/
|
|
35
|
+
// A robust way to retain selection position through various
|
|
36
|
+
// transforms is to insert a special character at the position and
|
|
37
|
+
// then recover it.
|
|
38
|
+
const START_OF_SELECTED_AREA = '\u0086';
|
|
39
|
+
|
|
40
|
+
function findSelection(blocks) {
|
|
41
|
+
let i = blocks.length;
|
|
42
|
+
|
|
43
|
+
while (i--) {
|
|
44
|
+
const attributeKey = (0, _lodash.findKey)(blocks[i].attributes, v => typeof v === 'string' && v.indexOf(START_OF_SELECTED_AREA) !== -1);
|
|
45
|
+
|
|
46
|
+
if (attributeKey) {
|
|
47
|
+
blocks[i].attributes[attributeKey] = blocks[i].attributes[attributeKey].replace(START_OF_SELECTED_AREA, '');
|
|
48
|
+
return blocks[i].clientId;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const nestedSelection = findSelection(blocks[i].innerBlocks);
|
|
52
|
+
|
|
53
|
+
if (nestedSelection) {
|
|
54
|
+
return nestedSelection;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
29
59
|
function useInputRules(props) {
|
|
30
60
|
const {
|
|
31
61
|
__unstableMarkLastChangeAsPersistent,
|
|
@@ -37,7 +67,8 @@ function useInputRules(props) {
|
|
|
37
67
|
function inputRule() {
|
|
38
68
|
const {
|
|
39
69
|
value,
|
|
40
|
-
onReplace
|
|
70
|
+
onReplace,
|
|
71
|
+
selectionChange
|
|
41
72
|
} = propsRef.current;
|
|
42
73
|
|
|
43
74
|
if (!onReplace) {
|
|
@@ -73,9 +104,10 @@ function useInputRules(props) {
|
|
|
73
104
|
}
|
|
74
105
|
|
|
75
106
|
const content = (0, _richText.toHTMLString)({
|
|
76
|
-
value: (0, _richText.
|
|
107
|
+
value: (0, _richText.insert)(value, START_OF_SELECTED_AREA, 0, start)
|
|
77
108
|
});
|
|
78
109
|
const block = transformation.transform(content);
|
|
110
|
+
selectionChange(findSelection([block]));
|
|
79
111
|
onReplace([block]);
|
|
80
112
|
|
|
81
113
|
__unstableMarkAutomaticChange();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-input-rules.js"],"names":["useInputRules","props","__unstableMarkLastChangeAsPersistent","__unstableMarkAutomaticChange","blockEditorStore","propsRef","current","element","inputRule","value","onReplace","start","text","characterBefore","slice","trimmedTextBefore","trim","prefixTransforms","filter","type","transformation","prefix","content","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-input-rules.js"],"names":["START_OF_SELECTED_AREA","findSelection","blocks","i","length","attributeKey","attributes","v","indexOf","replace","clientId","nestedSelection","innerBlocks","useInputRules","props","__unstableMarkLastChangeAsPersistent","__unstableMarkAutomaticChange","blockEditorStore","propsRef","current","element","inputRule","value","onReplace","selectionChange","start","text","characterBefore","slice","trimmedTextBefore","trim","prefixTransforms","filter","type","transformation","prefix","content","block","transform","onInput","event","inputType","onChange","__unstableAllowPrefixTransformations","formatTypes","transformed","reduce","accumlator","__unstableInputRule","activeFormats","addEventListener","removeEventListener"],"mappings":";;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AAOA;AACA;AACA;AAIA;AACA;AACA;AACA,MAAMA,sBAAsB,GAAG,QAA/B;;AAEA,SAASC,aAAT,CAAwBC,MAAxB,EAAiC;AAChC,MAAIC,CAAC,GAAGD,MAAM,CAACE,MAAf;;AAEA,SAAQD,CAAC,EAAT,EAAc;AACb,UAAME,YAAY,GAAG,qBACpBH,MAAM,CAAEC,CAAF,CAAN,CAAYG,UADQ,EAElBC,CAAF,IACC,OAAOA,CAAP,KAAa,QAAb,IACAA,CAAC,CAACC,OAAF,CAAWR,sBAAX,MAAwC,CAAC,CAJtB,CAArB;;AAOA,QAAKK,YAAL,EAAoB;AACnBH,MAAAA,MAAM,CAAEC,CAAF,CAAN,CAAYG,UAAZ,CAAwBD,YAAxB,IAAyCH,MAAM,CAAEC,CAAF,CAAN,CAAYG,UAAZ,CACxCD,YADwC,EAEvCI,OAFuC,CAE9BT,sBAF8B,EAEN,EAFM,CAAzC;AAGA,aAAOE,MAAM,CAAEC,CAAF,CAAN,CAAYO,QAAnB;AACA;;AAED,UAAMC,eAAe,GAAGV,aAAa,CAAEC,MAAM,CAAEC,CAAF,CAAN,CAAYS,WAAd,CAArC;;AAEA,QAAKD,eAAL,EAAuB;AACtB,aAAOA,eAAP;AACA;AACD;AACD;;AAEM,SAASE,aAAT,CAAwBC,KAAxB,EAAgC;AACtC,QAAM;AACLC,IAAAA,oCADK;AAELC,IAAAA;AAFK,MAGF,uBAAaC,YAAb,CAHJ;AAIA,QAAMC,QAAQ,GAAG,qBAAQJ,KAAR,CAAjB;AACAI,EAAAA,QAAQ,CA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CAAP;AAuFA","sourcesContent":["/**\n * External dependencies\n */\nimport { findKey } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { useRefEffect } from '@wordpress/compose';\nimport { insert, toHTMLString } from '@wordpress/rich-text';\nimport { getBlockTransforms, findTransform } from '@wordpress/blocks';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { preventEventDiscovery } from './prevent-event-discovery';\n\n// A robust way to retain selection position through various\n// transforms is to insert a special character at the position and\n// then recover it.\nconst START_OF_SELECTED_AREA = '\\u0086';\n\nfunction findSelection( blocks ) {\n\tlet i = blocks.length;\n\n\twhile ( i-- ) {\n\t\tconst attributeKey = findKey(\n\t\t\tblocks[ i ].attributes,\n\t\t\t( v ) =>\n\t\t\t\ttypeof v === 'string' &&\n\t\t\t\tv.indexOf( START_OF_SELECTED_AREA ) !== -1\n\t\t);\n\n\t\tif ( attributeKey ) {\n\t\t\tblocks[ i ].attributes[ attributeKey ] = blocks[ i ].attributes[\n\t\t\t\tattributeKey\n\t\t\t].replace( START_OF_SELECTED_AREA, '' );\n\t\t\treturn blocks[ i ].clientId;\n\t\t}\n\n\t\tconst nestedSelection = findSelection( blocks[ i ].innerBlocks );\n\n\t\tif ( nestedSelection ) {\n\t\t\treturn nestedSelection;\n\t\t}\n\t}\n}\n\nexport function useInputRules( props ) {\n\tconst {\n\t\t__unstableMarkLastChangeAsPersistent,\n\t\t__unstableMarkAutomaticChange,\n\t} = useDispatch( blockEditorStore );\n\tconst propsRef = useRef( props );\n\tpropsRef.current = props;\n\treturn useRefEffect( ( element ) => {\n\t\tfunction inputRule() {\n\t\t\tconst { value, onReplace, selectionChange } = propsRef.current;\n\n\t\t\tif ( ! onReplace ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { start, text } = value;\n\t\t\tconst characterBefore = text.slice( start - 1, start );\n\n\t\t\t// The character right before the caret must be a plain space.\n\t\t\tif ( characterBefore !== ' ' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst trimmedTextBefore = text.slice( 0, start ).trim();\n\t\t\tconst prefixTransforms = getBlockTransforms( 'from' ).filter(\n\t\t\t\t( { type } ) => type === 'prefix'\n\t\t\t);\n\t\t\tconst transformation = findTransform(\n\t\t\t\tprefixTransforms,\n\t\t\t\t( { prefix } ) => {\n\t\t\t\t\treturn trimmedTextBefore === prefix;\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif ( ! transformation ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst content = toHTMLString( {\n\t\t\t\tvalue: insert( value, START_OF_SELECTED_AREA, 0, start ),\n\t\t\t} );\n\t\t\tconst block = transformation.transform( content );\n\n\t\t\tselectionChange( findSelection( [ block ] ) );\n\t\t\tonReplace( [ block ] );\n\t\t\t__unstableMarkAutomaticChange();\n\t\t}\n\n\t\tfunction onInput( event ) {\n\t\t\tconst { inputType, type } = event;\n\t\t\tconst {\n\t\t\t\tvalue,\n\t\t\t\tonChange,\n\t\t\t\t__unstableAllowPrefixTransformations,\n\t\t\t\tformatTypes,\n\t\t\t} = propsRef.current;\n\n\t\t\t// Only run input rules when inserting text.\n\t\t\tif ( inputType !== 'insertText' && type !== 'compositionend' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( __unstableAllowPrefixTransformations && inputRule ) {\n\t\t\t\tinputRule();\n\t\t\t}\n\n\t\t\tconst transformed = formatTypes.reduce(\n\t\t\t\t( accumlator, { __unstableInputRule } ) => {\n\t\t\t\t\tif ( __unstableInputRule ) {\n\t\t\t\t\t\taccumlator = __unstableInputRule( accumlator );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn accumlator;\n\t\t\t\t},\n\t\t\t\tpreventEventDiscovery( value )\n\t\t\t);\n\n\t\t\tif ( transformed !== value ) {\n\t\t\t\t__unstableMarkLastChangeAsPersistent();\n\t\t\t\tonChange( {\n\t\t\t\t\t...transformed,\n\t\t\t\t\tactiveFormats: value.activeFormats,\n\t\t\t\t} );\n\t\t\t\t__unstableMarkAutomaticChange();\n\t\t\t}\n\t\t}\n\n\t\telement.addEventListener( 'input', onInput );\n\t\telement.addEventListener( 'compositionend', onInput );\n\t\treturn () => {\n\t\t\telement.removeEventListener( 'input', onInput );\n\t\t\telement.removeEventListener( 'compositionend', onInput );\n\t\t};\n\t}, [] );\n}\n"]}
|
|
@@ -40,6 +40,10 @@ const SkipToSelectedBlock = _ref => {
|
|
|
40
40
|
onClick: onClick
|
|
41
41
|
}, (0, _i18n.__)('Skip to the selected block')) : null;
|
|
42
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/skip-to-selected-block/README.md
|
|
45
|
+
*/
|
|
46
|
+
|
|
43
47
|
|
|
44
48
|
var _default = (0, _data.withSelect)(select => {
|
|
45
49
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/skip-to-selected-block/index.js"],"names":["SkipToSelectedBlock","selectedBlockClientId","ref","onClick","current","focus","select","blockEditorStore","getBlockSelectionStart"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AAXA;AACA;AACA;;AAKA;AACA;AACA;AAIA,MAAMA,mBAAmB,GAAG,QAAiC;AAAA,MAA/B;AAAEC,IAAAA;AAAF,GAA+B;AAC5D,QAAMC,GAAG,GAAG,yCAAaD,qBAAb,CAAZ;;AACA,QAAME,OAAO,GAAG,MAAM;AACrBD,IAAAA,GAAG,CAACE,OAAJ,CAAYC,KAAZ;AACA,GAFD;;AAIA,SAAOJ,qBAAqB,GAC3B,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,WADT;AAEC,IAAA,SAAS,EAAC,qCAFX;AAGC,IAAA,OAAO,EAAGE;AAHX,KAKG,cAAI,4BAAJ,CALH,CAD2B,GAQxB,IARJ;AASA,CAfD
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/skip-to-selected-block/index.js"],"names":["SkipToSelectedBlock","selectedBlockClientId","ref","onClick","current","focus","select","blockEditorStore","getBlockSelectionStart"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AAXA;AACA;AACA;;AAKA;AACA;AACA;AAIA,MAAMA,mBAAmB,GAAG,QAAiC;AAAA,MAA/B;AAAEC,IAAAA;AAAF,GAA+B;AAC5D,QAAMC,GAAG,GAAG,yCAAaD,qBAAb,CAAZ;;AACA,QAAME,OAAO,GAAG,MAAM;AACrBD,IAAAA,GAAG,CAACE,OAAJ,CAAYC,KAAZ;AACA,GAFD;;AAIA,SAAOJ,qBAAqB,GAC3B,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,WADT;AAEC,IAAA,SAAS,EAAC,qCAFX;AAGC,IAAA,OAAO,EAAGE;AAHX,KAKG,cAAI,4BAAJ,CALH,CAD2B,GAQxB,IARJ;AASA,CAfD;AAiBA;AACA;AACA;;;eACe,sBAAcG,MAAF,IAAc;AACxC,SAAO;AACNL,IAAAA,qBAAqB,EAAEK,MAAM,CAC5BC,YAD4B,CAAN,CAErBC,sBAFqB;AADjB,GAAP;AAKA,CANc,EAMVR,mBANU,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { withSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';\n\nconst SkipToSelectedBlock = ( { selectedBlockClientId } ) => {\n\tconst ref = useBlockRef( selectedBlockClientId );\n\tconst onClick = () => {\n\t\tref.current.focus();\n\t};\n\n\treturn selectedBlockClientId ? (\n\t\t<Button\n\t\t\tvariant=\"secondary\"\n\t\t\tclassName=\"block-editor-skip-to-selected-block\"\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ __( 'Skip to the selected block' ) }\n\t\t</Button>\n\t) : null;\n};\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/skip-to-selected-block/README.md\n */\nexport default withSelect( ( select ) => {\n\treturn {\n\t\tselectedBlockClientId: select(\n\t\t\tblockEditorStore\n\t\t).getBlockSelectionStart(),\n\t};\n} )( SkipToSelectedBlock );\n"]}
|
|
@@ -28,6 +28,14 @@ var _useArrowNav = _interopRequireDefault(require("./use-arrow-nav"));
|
|
|
28
28
|
|
|
29
29
|
var _useSelectAll = _interopRequireDefault(require("./use-select-all"));
|
|
30
30
|
|
|
31
|
+
var _useDragSelection = _interopRequireDefault(require("./use-drag-selection"));
|
|
32
|
+
|
|
33
|
+
var _useSelectionObserver = _interopRequireDefault(require("./use-selection-observer"));
|
|
34
|
+
|
|
35
|
+
var _useClickSelection = _interopRequireDefault(require("./use-click-selection"));
|
|
36
|
+
|
|
37
|
+
var _useInput = _interopRequireDefault(require("./use-input"));
|
|
38
|
+
|
|
31
39
|
var _store = require("../../store");
|
|
32
40
|
|
|
33
41
|
/**
|
|
@@ -44,7 +52,7 @@ var _store = require("../../store");
|
|
|
44
52
|
function useWritingFlow() {
|
|
45
53
|
const [before, ref, after] = (0, _useTabNav.default)();
|
|
46
54
|
const hasMultiSelection = (0, _data.useSelect)(select => select(_store.store).hasMultiSelection(), []);
|
|
47
|
-
return [before, (0, _compose.useMergeRefs)([ref, (0, _useMultiSelection.default)(), (0, _useSelectAll.default)(), (0, _useArrowNav.default)(), (0, _compose.useRefEffect)(node => {
|
|
55
|
+
return [before, (0, _compose.useMergeRefs)([ref, (0, _useInput.default)(), (0, _useDragSelection.default)(), (0, _useSelectionObserver.default)(), (0, _useClickSelection.default)(), (0, _useMultiSelection.default)(), (0, _useSelectAll.default)(), (0, _useArrowNav.default)(), (0, _compose.useRefEffect)(node => {
|
|
48
56
|
node.tabIndex = -1;
|
|
49
57
|
node.contentEditable = hasMultiSelection;
|
|
50
58
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/index.js"],"names":["useWritingFlow","before","ref","after","hasMultiSelection","select","blockEditorStore","node","tabIndex","contentEditable","setAttribute","removeAttribute","WritingFlow","forwardedRef","children","props","className"],"mappings":";;;;;;;;;;AAWA;;;;AARA;;AAKA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/index.js"],"names":["useWritingFlow","before","ref","after","hasMultiSelection","select","blockEditorStore","node","tabIndex","contentEditable","setAttribute","removeAttribute","WritingFlow","forwardedRef","children","props","className"],"mappings":";;;;;;;;;;AAWA;;;;AARA;;AAKA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAxBA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AAWO,SAASA,cAAT,GAA0B;AAChC,QAAM,CAAEC,MAAF,EAAUC,GAAV,EAAeC,KAAf,IAAyB,yBAA/B;AACA,QAAMC,iBAAiB,GAAG,qBACvBC,MAAF,IAAcA,MAAM,CAAEC,YAAF,CAAN,CAA2BF,iBAA3B,EADW,EAEzB,EAFyB,CAA1B;AAKA,SAAO,CACNH,MADM,EAEN,2BAAc,CACbC,GADa,EAEb,wBAFa,EAGb,gCAHa,EAIb,oCAJa,EAKb,iCALa,EAMb,iCANa,EAOb,4BAPa,EAQb,2BARa,EASb,2BACGK,IAAF,IAAY;AACXA,IAAAA,IAAI,CAACC,QAAL,GAAgB,CAAC,CAAjB;AACAD,IAAAA,IAAI,CAACE,eAAL,GAAuBL,iBAAvB;;AAEA,QAAK,CAAEA,iBAAP,EAA2B;AAC1B;AACA;;AAEDG,IAAAA,IAAI,CAACG,YAAL,CACC,YADD,EAEC,cAAI,0BAAJ,CAFD;AAKA,WAAO,MAAM;AACZH,MAAAA,IAAI,CAACI,eAAL,CAAsB,YAAtB;AACA,KAFD;AAGA,GAjBF,EAkBC,CAAEP,iBAAF,CAlBD,CATa,CAAd,CAFM,EAgCND,KAhCM,CAAP;AAkCA;;AAED,SAASS,WAAT,OAA8CC,YAA9C,EAA6D;AAAA,MAAvC;AAAEC,IAAAA,QAAF;AAAY,OAAGC;AAAf,GAAuC;AAC5D,QAAM,CAAEd,MAAF,EAAUC,GAAV,EAAeC,KAAf,IAAyBH,cAAc,EAA7C;AACA,SACC,qDACGC,MADH,EAEC,8DACMc,KADN;AAEC,IAAA,GAAG,EAAG,2BAAc,CAAEb,GAAF,EAAOW,YAAP,CAAd,CAFP;AAGC,IAAA,SAAS,EAAG,yBACXE,KAAK,CAACC,SADK,EAEX,2BAFW;AAHb,MAQGF,QARH,CAFD,EAYGX,KAZH,CADD;AAgBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;eACe,yBAAYS,WAAZ,C","sourcesContent":["/**\n * External dependencies\n */\nimport classNames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { useMergeRefs, useRefEffect } from '@wordpress/compose';\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useMultiSelection from './use-multi-selection';\nimport useTabNav from './use-tab-nav';\nimport useArrowNav from './use-arrow-nav';\nimport useSelectAll from './use-select-all';\nimport useDragSelection from './use-drag-selection';\nimport useSelectionObserver from './use-selection-observer';\nimport useClickSelection from './use-click-selection';\nimport useInput from './use-input';\nimport { store as blockEditorStore } from '../../store';\n\nexport function useWritingFlow() {\n\tconst [ before, ref, after ] = useTabNav();\n\tconst hasMultiSelection = useSelect(\n\t\t( select ) => select( blockEditorStore ).hasMultiSelection(),\n\t\t[]\n\t);\n\n\treturn [\n\t\tbefore,\n\t\tuseMergeRefs( [\n\t\t\tref,\n\t\t\tuseInput(),\n\t\t\tuseDragSelection(),\n\t\t\tuseSelectionObserver(),\n\t\t\tuseClickSelection(),\n\t\t\tuseMultiSelection(),\n\t\t\tuseSelectAll(),\n\t\t\tuseArrowNav(),\n\t\t\tuseRefEffect(\n\t\t\t\t( node ) => {\n\t\t\t\t\tnode.tabIndex = -1;\n\t\t\t\t\tnode.contentEditable = hasMultiSelection;\n\n\t\t\t\t\tif ( ! hasMultiSelection ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tnode.setAttribute(\n\t\t\t\t\t\t'aria-label',\n\t\t\t\t\t\t__( 'Multiple selected blocks' )\n\t\t\t\t\t);\n\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tnode.removeAttribute( 'aria-label' );\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\t[ hasMultiSelection ]\n\t\t\t),\n\t\t] ),\n\t\tafter,\n\t];\n}\n\nfunction WritingFlow( { children, ...props }, forwardedRef ) {\n\tconst [ before, ref, after ] = useWritingFlow();\n\treturn (\n\t\t<>\n\t\t\t{ before }\n\t\t\t<div\n\t\t\t\t{ ...props }\n\t\t\t\tref={ useMergeRefs( [ ref, forwardedRef ] ) }\n\t\t\t\tclassName={ classNames(\n\t\t\t\t\tprops.className,\n\t\t\t\t\t'block-editor-writing-flow'\n\t\t\t\t) }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t\t{ after }\n\t\t</>\n\t);\n}\n\n/**\n * Handles selection and navigation across blocks. This component should be\n * wrapped around BlockList.\n *\n * @param {Object} props Component properties.\n * @param {WPElement} props.children Children to be rendered.\n */\nexport default forwardRef( WritingFlow );\n"]}
|
|
@@ -119,19 +119,12 @@ function getClosestTabbable(target, isReverse, containerElement, onlyVertical) {
|
|
|
119
119
|
function useArrowNav() {
|
|
120
120
|
const {
|
|
121
121
|
getSelectedBlockClientId,
|
|
122
|
-
getMultiSelectedBlocksStartClientId,
|
|
123
122
|
getMultiSelectedBlocksEndClientId,
|
|
124
123
|
getPreviousBlockClientId,
|
|
125
124
|
getNextBlockClientId,
|
|
126
|
-
getFirstMultiSelectedBlockClientId,
|
|
127
|
-
getLastMultiSelectedBlockClientId,
|
|
128
125
|
getSettings,
|
|
129
126
|
hasMultiSelection
|
|
130
127
|
} = (0, _data.useSelect)(_store.store);
|
|
131
|
-
const {
|
|
132
|
-
multiSelect,
|
|
133
|
-
selectBlock
|
|
134
|
-
} = (0, _data.useDispatch)(_store.store);
|
|
135
128
|
return (0, _compose.useRefEffect)(node => {
|
|
136
129
|
// Here a DOMRect is stored while moving the caret vertically so
|
|
137
130
|
// vertical position of the start position can be restored. This is to
|
|
@@ -141,33 +134,6 @@ function useArrowNav() {
|
|
|
141
134
|
function onMouseDown() {
|
|
142
135
|
verticalRect = null;
|
|
143
136
|
}
|
|
144
|
-
|
|
145
|
-
function expandSelection(isReverse) {
|
|
146
|
-
const selectedBlockClientId = getSelectedBlockClientId();
|
|
147
|
-
const selectionStartClientId = getMultiSelectedBlocksStartClientId();
|
|
148
|
-
const selectionEndClientId = getMultiSelectedBlocksEndClientId();
|
|
149
|
-
const selectionBeforeEndClientId = getPreviousBlockClientId(selectionEndClientId || selectedBlockClientId);
|
|
150
|
-
const selectionAfterEndClientId = getNextBlockClientId(selectionEndClientId || selectedBlockClientId);
|
|
151
|
-
const nextSelectionEndClientId = isReverse ? selectionBeforeEndClientId : selectionAfterEndClientId;
|
|
152
|
-
|
|
153
|
-
if (nextSelectionEndClientId) {
|
|
154
|
-
if (selectionStartClientId === nextSelectionEndClientId) {
|
|
155
|
-
selectBlock(nextSelectionEndClientId);
|
|
156
|
-
} else {
|
|
157
|
-
multiSelect(selectionStartClientId || selectedBlockClientId, nextSelectionEndClientId);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function moveSelection(isReverse) {
|
|
163
|
-
const selectedFirstClientId = getFirstMultiSelectedBlockClientId();
|
|
164
|
-
const selectedLastClientId = getLastMultiSelectedBlockClientId();
|
|
165
|
-
const focusedBlockClientId = isReverse ? selectedFirstClientId : selectedLastClientId;
|
|
166
|
-
|
|
167
|
-
if (focusedBlockClientId) {
|
|
168
|
-
selectBlock(focusedBlockClientId);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
137
|
/**
|
|
172
138
|
* Returns true if the given target field is the last in its block which
|
|
173
139
|
* can be considered for tab transition. For example, in a block with
|
|
@@ -210,12 +176,6 @@ function useArrowNav() {
|
|
|
210
176
|
} = ownerDocument;
|
|
211
177
|
|
|
212
178
|
if (hasMultiSelection()) {
|
|
213
|
-
if (isNav) {
|
|
214
|
-
const action = isShift ? expandSelection : moveSelection;
|
|
215
|
-
action(isReverse);
|
|
216
|
-
event.preventDefault();
|
|
217
|
-
}
|
|
218
|
-
|
|
219
179
|
return;
|
|
220
180
|
} // When presing any key other than up or down, the initial vertical
|
|
221
181
|
// position must ALWAYS be reset. The vertical position is saved so
|
|
@@ -263,10 +223,9 @@ function useArrowNav() {
|
|
|
263
223
|
|
|
264
224
|
if ( // Ensure that there is a target block.
|
|
265
225
|
(isReverse && selectionBeforeEndClientId || !isReverse && selectionAfterEndClientId) && isTabbableEdge(target, isReverse) && isNavEdge(target, isReverse)) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
event.preventDefault();
|
|
226
|
+
node.contentEditable = true; // Firefox doesn't automatically move focus.
|
|
227
|
+
|
|
228
|
+
node.focus();
|
|
270
229
|
}
|
|
271
230
|
} else if (isVertical && (0, _dom.isVerticalEdge)(target, isReverse) && !keepCaretInsideBlock) {
|
|
272
231
|
const closestTabbable = getClosestTabbable(target, isReverse, node, true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-arrow-nav.js"],"names":["isNavigationCandidate","element","keyCode","hasModifier","isVertical","UP","DOWN","tagName","getClosestTabbable","target","isReverse","containerElement","onlyVertical","focusableNodes","focus","focusable","find","slice","indexOf","targetRect","getBoundingClientRect","isTabCandidate","node","tabbable","isTabbableIndex","isContentEditable","contentEditable","nodeRect","left","right","useArrowNav","getSelectedBlockClientId","getMultiSelectedBlocksStartClientId","getMultiSelectedBlocksEndClientId","getPreviousBlockClientId","getNextBlockClientId","getFirstMultiSelectedBlockClientId","getLastMultiSelectedBlockClientId","getSettings","hasMultiSelection","blockEditorStore","multiSelect","selectBlock","verticalRect","onMouseDown","expandSelection","selectedBlockClientId","selectionStartClientId","selectionEndClientId","selectionBeforeEndClientId","selectionAfterEndClientId","nextSelectionEndClientId","moveSelection","selectedFirstClientId","selectedLastClientId","focusedBlockClientId","isTabbableEdge","closestTabbable","onKeyDown","event","isUp","isDown","isLeft","LEFT","isRight","RIGHT","isHorizontal","isNav","isShift","shiftKey","ctrlKey","altKey","metaKey","isNavEdge","isVerticalEdge","isHorizontalEdge","ownerDocument","defaultView","action","preventDefault","defaultPrevented","isReverseDir","keepCaretInsideBlock","getSelection","isCollapsed","addEventListener","removeEventListener"],"mappings":";;;;;;;;;AAGA;;AAKA;;AASA;;AACA;;AACA;;AAKA;;AACA;;AAzBA;AACA;AACA;;AAGA;AACA;AACA;;AAcA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,qBAAT,CAAgCC,OAAhC,EAAyCC,OAAzC,EAAkDC,WAAlD,EAAgE;AACtE,QAAMC,UAAU,GAAGF,OAAO,KAAKG,YAAZ,IAAkBH,OAAO,KAAKI,cAAjD,CADsE,CAGtE;;AACA,MAAKF,UAAU,IAAI,CAAED,WAArB,EAAmC;AAClC,WAAO,IAAP;AACA,GANqE,CAQtE;;;AACA,QAAM;AAAEI,IAAAA;AAAF,MAAcN,OAApB;AACA,SAAOM,OAAO,KAAK,OAAZ,IAAuBA,OAAO,KAAK,UAA1C;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,kBAAT,CACNC,MADM,EAENC,SAFM,EAGNC,gBAHM,EAINC,YAJM,EAKL;AACD;AACA;AACA,MAAIC,cAAc,GAAGC,WAAM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Y,IAHyC,EAIzC,IAJyC,CAA1C;;AAOA,YAAKmC,eAAL,EAAuB;AACtB,6CACCA,eADD,EAEC/C,SAFD,EAGCiC,YAHD;AAKAgB,UAAAA,KAAK,CAACoB,cAAN;AACA;AACD,OApBM,MAoBA,IACNb,YAAY,IACZW,WAAW,CAACM,YAAZ,GAA2BC,WAD3B,IAEA,2BAAkB3E,MAAlB,EAA0BwE,YAA1B,CAFA,IAGA,CAAEC,oBAJI,EAKL;AACD,cAAMzB,eAAe,GAAGjD,kBAAkB,CACzCC,MADyC,EAEzCwE,YAFyC,EAGzC3D,IAHyC,CAA1C;AAKA,6CAA4BmC,eAA5B,EAA6C/C,SAA7C;AACAiD,QAAAA,KAAK,CAACoB,cAAN;AACA;AACD;;AAEDzD,IAAAA,IAAI,CAAC+D,gBAAL,CAAuB,WAAvB,EAAoCzC,WAApC;AACAtB,IAAAA,IAAI,CAAC+D,gBAAL,CAAuB,SAAvB,EAAkC3B,SAAlC;AACA,WAAO,MAAM;AACZpC,MAAAA,IAAI,CAACgE,mBAAL,CAA0B,WAA1B,EAAuC1C,WAAvC;AACAtB,MAAAA,IAAI,CAACgE,mBAAL,CAA0B,SAA1B,EAAqC5B,SAArC;AACA,KAHD;AAIA,GAnMM,EAmMJ,EAnMI,CAAP;AAoMA","sourcesContent":["/**\n * External dependencies\n */\nimport { find, reverse } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tcomputeCaretRect,\n\tfocus,\n\tisHorizontalEdge,\n\tisVerticalEdge,\n\tplaceCaretAtHorizontalEdge,\n\tplaceCaretAtVerticalEdge,\n\tisRTL,\n} from '@wordpress/dom';\nimport { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { isInSameBlock } from '../../utils/dom';\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Returns true if the element should consider edge navigation upon a keyboard\n * event of the given directional key code, or false otherwise.\n *\n * @param {Element} element HTML element to test.\n * @param {number} keyCode KeyboardEvent keyCode to test.\n * @param {boolean} hasModifier Whether a modifier is pressed.\n *\n * @return {boolean} Whether element should consider edge navigation.\n */\nexport function isNavigationCandidate( element, keyCode, hasModifier ) {\n\tconst isVertical = keyCode === UP || keyCode === DOWN;\n\n\t// Currently, all elements support unmodified vertical navigation.\n\tif ( isVertical && ! hasModifier ) {\n\t\treturn true;\n\t}\n\n\t// Native inputs should not navigate horizontally.\n\tconst { tagName } = element;\n\treturn tagName !== 'INPUT' && tagName !== 'TEXTAREA';\n}\n\n/**\n * Returns the optimal tab target from the given focused element in the desired\n * direction. A preference is made toward text fields, falling back to the block\n * focus stop if no other candidates exist for the block.\n *\n * @param {Element} target Currently focused text field.\n * @param {boolean} isReverse True if considering as the first field.\n * @param {Element} containerElement Element containing all blocks.\n * @param {boolean} onlyVertical Whether to only consider tabbable elements\n * that are visually above or under the\n * target.\n *\n * @return {?Element} Optimal tab target, if one exists.\n */\nexport function getClosestTabbable(\n\ttarget,\n\tisReverse,\n\tcontainerElement,\n\tonlyVertical\n) {\n\t// Since the current focus target is not guaranteed to be a text field, find\n\t// all focusables. Tabbability is considered later.\n\tlet focusableNodes = focus.focusable.find( containerElement );\n\n\tif ( isReverse ) {\n\t\tfocusableNodes = reverse( focusableNodes );\n\t}\n\n\t// Consider as candidates those focusables after the current target. It's\n\t// assumed this can only be reached if the target is focusable (on its\n\t// keydown event), so no need to verify it exists in the set.\n\tfocusableNodes = focusableNodes.slice(\n\t\tfocusableNodes.indexOf( target ) + 1\n\t);\n\n\tlet targetRect;\n\n\tif ( onlyVertical ) {\n\t\ttargetRect = target.getBoundingClientRect();\n\t}\n\n\tfunction isTabCandidate( node ) {\n\t\t// Not a candidate if the node is not tabbable.\n\t\tif ( ! focus.tabbable.isTabbableIndex( node ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Skip focusable elements such as links within content editable nodes.\n\t\tif ( node.isContentEditable && node.contentEditable !== 'true' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( onlyVertical ) {\n\t\t\tconst nodeRect = node.getBoundingClientRect();\n\n\t\t\tif (\n\t\t\t\tnodeRect.left >= targetRect.right ||\n\t\t\t\tnodeRect.right <= targetRect.left\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn find( focusableNodes, isTabCandidate );\n}\n\nexport default function useArrowNav() {\n\tconst {\n\t\tgetSelectedBlockClientId,\n\t\tgetMultiSelectedBlocksStartClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetPreviousBlockClientId,\n\t\tgetNextBlockClientId,\n\t\tgetFirstMultiSelectedBlockClientId,\n\t\tgetLastMultiSelectedBlockClientId,\n\t\tgetSettings,\n\t\thasMultiSelection,\n\t} = useSelect( blockEditorStore );\n\tconst { multiSelect, selectBlock } = useDispatch( blockEditorStore );\n\treturn useRefEffect( ( node ) => {\n\t\t// Here a DOMRect is stored while moving the caret vertically so\n\t\t// vertical position of the start position can be restored. This is to\n\t\t// recreate browser behaviour across blocks.\n\t\tlet verticalRect;\n\n\t\tfunction onMouseDown() {\n\t\t\tverticalRect = null;\n\t\t}\n\n\t\tfunction expandSelection( isReverse ) {\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\t\t\tconst selectionStartClientId = getMultiSelectedBlocksStartClientId();\n\t\t\tconst selectionEndClientId = getMultiSelectedBlocksEndClientId();\n\t\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t);\n\t\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t);\n\t\t\tconst nextSelectionEndClientId = isReverse\n\t\t\t\t? selectionBeforeEndClientId\n\t\t\t\t: selectionAfterEndClientId;\n\n\t\t\tif ( nextSelectionEndClientId ) {\n\t\t\t\tif ( selectionStartClientId === nextSelectionEndClientId ) {\n\t\t\t\t\tselectBlock( nextSelectionEndClientId );\n\t\t\t\t} else {\n\t\t\t\t\tmultiSelect(\n\t\t\t\t\t\tselectionStartClientId || selectedBlockClientId,\n\t\t\t\t\t\tnextSelectionEndClientId\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfunction moveSelection( isReverse ) {\n\t\t\tconst selectedFirstClientId = getFirstMultiSelectedBlockClientId();\n\t\t\tconst selectedLastClientId = getLastMultiSelectedBlockClientId();\n\t\t\tconst focusedBlockClientId = isReverse\n\t\t\t\t? selectedFirstClientId\n\t\t\t\t: selectedLastClientId;\n\n\t\t\tif ( focusedBlockClientId ) {\n\t\t\t\tselectBlock( focusedBlockClientId );\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Returns true if the given target field is the last in its block which\n\t\t * can be considered for tab transition. For example, in a block with\n\t\t * two text fields, this would return true when reversing from the first\n\t\t * of the two fields, but false when reversing from the second.\n\t\t *\n\t\t * @param {Element} target Currently focused text field.\n\t\t * @param {boolean} isReverse True if considering as the first field.\n\t\t *\n\t\t * @return {boolean} Whether field is at edge for tab transition.\n\t\t */\n\t\tfunction isTabbableEdge( target, isReverse ) {\n\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\ttarget,\n\t\t\t\tisReverse,\n\t\t\t\tnode\n\t\t\t);\n\t\t\treturn (\n\t\t\t\t! closestTabbable || ! isInSameBlock( target, closestTabbable )\n\t\t\t);\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\n\t\t\tconst { keyCode, target } = event;\n\t\t\tconst isUp = keyCode === UP;\n\t\t\tconst isDown = keyCode === DOWN;\n\t\t\tconst isLeft = keyCode === LEFT;\n\t\t\tconst isRight = keyCode === RIGHT;\n\t\t\tconst isReverse = isUp || isLeft;\n\t\t\tconst isHorizontal = isLeft || isRight;\n\t\t\tconst isVertical = isUp || isDown;\n\t\t\tconst isNav = isHorizontal || isVertical;\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst hasModifier =\n\t\t\t\tisShift || event.ctrlKey || event.altKey || event.metaKey;\n\t\t\tconst isNavEdge = isVertical ? isVerticalEdge : isHorizontalEdge;\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tif ( hasMultiSelection() ) {\n\t\t\t\tif ( isNav ) {\n\t\t\t\t\tconst action = isShift ? expandSelection : moveSelection;\n\t\t\t\t\taction( isReverse );\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// When presing any key other than up or down, the initial vertical\n\t\t\t// position must ALWAYS be reset. The vertical position is saved so\n\t\t\t// it can be restored as well as possible on sebsequent vertical\n\t\t\t// arrow key presses. It may not always be possible to restore the\n\t\t\t// exact same position (such as at an empty line), so it wouldn't be\n\t\t\t// good to compute the position right before any vertical arrow key\n\t\t\t// press.\n\t\t\tif ( ! isVertical ) {\n\t\t\t\tverticalRect = null;\n\t\t\t} else if ( ! verticalRect ) {\n\t\t\t\tverticalRect = computeCaretRect( defaultView );\n\t\t\t}\n\n\t\t\t// Abort if navigation has already been handled (e.g. RichText\n\t\t\t// inline boundaries).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! isNav ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Abort if our current target is not a candidate for navigation\n\t\t\t// (e.g. preserve native input behaviors).\n\t\t\tif ( ! isNavigationCandidate( target, keyCode, hasModifier ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In the case of RTL scripts, right means previous and left means\n\t\t\t// next, which is the exact reverse of LTR.\n\t\t\tconst isReverseDir = isRTL( target ) ? ! isReverse : isReverse;\n\t\t\tconst { keepCaretInsideBlock } = getSettings();\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\n\t\t\tif ( isShift ) {\n\t\t\t\tconst selectionEndClientId = getMultiSelectedBlocksEndClientId();\n\t\t\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\t\t\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\n\t\t\t\tif (\n\t\t\t\t\t// Ensure that there is a target block.\n\t\t\t\t\t( ( isReverse && selectionBeforeEndClientId ) ||\n\t\t\t\t\t\t( ! isReverse && selectionAfterEndClientId ) ) &&\n\t\t\t\t\tisTabbableEdge( target, isReverse ) &&\n\t\t\t\t\tisNavEdge( target, isReverse )\n\t\t\t\t) {\n\t\t\t\t\t// Shift key is down, and there is multi selection or we're\n\t\t\t\t\t// at the end of the current block.\n\t\t\t\t\texpandSelection( isReverse );\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisVertical &&\n\t\t\t\tisVerticalEdge( target, isReverse ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverse,\n\t\t\t\t\tnode,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\n\t\t\t\tif ( closestTabbable ) {\n\t\t\t\t\tplaceCaretAtVerticalEdge(\n\t\t\t\t\t\tclosestTabbable,\n\t\t\t\t\t\tisReverse,\n\t\t\t\t\t\tverticalRect\n\t\t\t\t\t);\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisHorizontal &&\n\t\t\t\tdefaultView.getSelection().isCollapsed &&\n\t\t\t\tisHorizontalEdge( target, isReverseDir ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverseDir,\n\t\t\t\t\tnode\n\t\t\t\t);\n\t\t\t\tplaceCaretAtHorizontalEdge( closestTabbable, isReverse );\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-arrow-nav.js"],"names":["isNavigationCandidate","element","keyCode","hasModifier","isVertical","UP","DOWN","tagName","getClosestTabbable","target","isReverse","containerElement","onlyVertical","focusableNodes","focus","focusable","find","slice","indexOf","targetRect","getBoundingClientRect","isTabCandidate","node","tabbable","isTabbableIndex","isContentEditable","contentEditable","nodeRect","left","right","useArrowNav","getSelectedBlockClientId","getMultiSelectedBlocksEndClientId","getPreviousBlockClientId","getNextBlockClientId","getSettings","hasMultiSelection","blockEditorStore","verticalRect","onMouseDown","isTabbableEdge","closestTabbable","onKeyDown","event","isUp","isDown","isLeft","LEFT","isRight","RIGHT","isHorizontal","isNav","isShift","shiftKey","ctrlKey","altKey","metaKey","isNavEdge","isVerticalEdge","isHorizontalEdge","ownerDocument","defaultView","defaultPrevented","isReverseDir","keepCaretInsideBlock","selectedBlockClientId","selectionEndClientId","selectionBeforeEndClientId","selectionAfterEndClientId","preventDefault","getSelection","isCollapsed","addEventListener","removeEventListener"],"mappings":";;;;;;;;;AAGA;;AAKA;;AASA;;AACA;;AACA;;AAKA;;AACA;;AAzBA;AACA;AACA;;AAGA;AACA;AACA;;AAcA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,qBAAT,CAAgCC,OAAhC,EAAyCC,OAAzC,EAAkDC,WAAlD,EAAgE;AACtE,QAAMC,UAAU,GAAGF,OAAO,KAAKG,YAAZ,IAAkBH,OAAO,KAAKI,cAAj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**\n * External dependencies\n */\nimport { find, reverse } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tcomputeCaretRect,\n\tfocus,\n\tisHorizontalEdge,\n\tisVerticalEdge,\n\tplaceCaretAtHorizontalEdge,\n\tplaceCaretAtVerticalEdge,\n\tisRTL,\n} from '@wordpress/dom';\nimport { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';\nimport { useSelect } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { isInSameBlock } from '../../utils/dom';\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Returns true if the element should consider edge navigation upon a keyboard\n * event of the given directional key code, or false otherwise.\n *\n * @param {Element} element HTML element to test.\n * @param {number} keyCode KeyboardEvent keyCode to test.\n * @param {boolean} hasModifier Whether a modifier is pressed.\n *\n * @return {boolean} Whether element should consider edge navigation.\n */\nexport function isNavigationCandidate( element, keyCode, hasModifier ) {\n\tconst isVertical = keyCode === UP || keyCode === DOWN;\n\n\t// Currently, all elements support unmodified vertical navigation.\n\tif ( isVertical && ! hasModifier ) {\n\t\treturn true;\n\t}\n\n\t// Native inputs should not navigate horizontally.\n\tconst { tagName } = element;\n\treturn tagName !== 'INPUT' && tagName !== 'TEXTAREA';\n}\n\n/**\n * Returns the optimal tab target from the given focused element in the desired\n * direction. A preference is made toward text fields, falling back to the block\n * focus stop if no other candidates exist for the block.\n *\n * @param {Element} target Currently focused text field.\n * @param {boolean} isReverse True if considering as the first field.\n * @param {Element} containerElement Element containing all blocks.\n * @param {boolean} onlyVertical Whether to only consider tabbable elements\n * that are visually above or under the\n * target.\n *\n * @return {?Element} Optimal tab target, if one exists.\n */\nexport function getClosestTabbable(\n\ttarget,\n\tisReverse,\n\tcontainerElement,\n\tonlyVertical\n) {\n\t// Since the current focus target is not guaranteed to be a text field, find\n\t// all focusables. Tabbability is considered later.\n\tlet focusableNodes = focus.focusable.find( containerElement );\n\n\tif ( isReverse ) {\n\t\tfocusableNodes = reverse( focusableNodes );\n\t}\n\n\t// Consider as candidates those focusables after the current target. It's\n\t// assumed this can only be reached if the target is focusable (on its\n\t// keydown event), so no need to verify it exists in the set.\n\tfocusableNodes = focusableNodes.slice(\n\t\tfocusableNodes.indexOf( target ) + 1\n\t);\n\n\tlet targetRect;\n\n\tif ( onlyVertical ) {\n\t\ttargetRect = target.getBoundingClientRect();\n\t}\n\n\tfunction isTabCandidate( node ) {\n\t\t// Not a candidate if the node is not tabbable.\n\t\tif ( ! focus.tabbable.isTabbableIndex( node ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Skip focusable elements such as links within content editable nodes.\n\t\tif ( node.isContentEditable && node.contentEditable !== 'true' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( onlyVertical ) {\n\t\t\tconst nodeRect = node.getBoundingClientRect();\n\n\t\t\tif (\n\t\t\t\tnodeRect.left >= targetRect.right ||\n\t\t\t\tnodeRect.right <= targetRect.left\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn find( focusableNodes, isTabCandidate );\n}\n\nexport default function useArrowNav() {\n\tconst {\n\t\tgetSelectedBlockClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetPreviousBlockClientId,\n\t\tgetNextBlockClientId,\n\t\tgetSettings,\n\t\thasMultiSelection,\n\t} = useSelect( blockEditorStore );\n\treturn useRefEffect( ( node ) => {\n\t\t// Here a DOMRect is stored while moving the caret vertically so\n\t\t// vertical position of the start position can be restored. This is to\n\t\t// recreate browser behaviour across blocks.\n\t\tlet verticalRect;\n\n\t\tfunction onMouseDown() {\n\t\t\tverticalRect = null;\n\t\t}\n\n\t\t/**\n\t\t * Returns true if the given target field is the last in its block which\n\t\t * can be considered for tab transition. For example, in a block with\n\t\t * two text fields, this would return true when reversing from the first\n\t\t * of the two fields, but false when reversing from the second.\n\t\t *\n\t\t * @param {Element} target Currently focused text field.\n\t\t * @param {boolean} isReverse True if considering as the first field.\n\t\t *\n\t\t * @return {boolean} Whether field is at edge for tab transition.\n\t\t */\n\t\tfunction isTabbableEdge( target, isReverse ) {\n\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\ttarget,\n\t\t\t\tisReverse,\n\t\t\t\tnode\n\t\t\t);\n\t\t\treturn (\n\t\t\t\t! closestTabbable || ! isInSameBlock( target, closestTabbable )\n\t\t\t);\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\n\t\t\tconst { keyCode, target } = event;\n\t\t\tconst isUp = keyCode === UP;\n\t\t\tconst isDown = keyCode === DOWN;\n\t\t\tconst isLeft = keyCode === LEFT;\n\t\t\tconst isRight = keyCode === RIGHT;\n\t\t\tconst isReverse = isUp || isLeft;\n\t\t\tconst isHorizontal = isLeft || isRight;\n\t\t\tconst isVertical = isUp || isDown;\n\t\t\tconst isNav = isHorizontal || isVertical;\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst hasModifier =\n\t\t\t\tisShift || event.ctrlKey || event.altKey || event.metaKey;\n\t\t\tconst isNavEdge = isVertical ? isVerticalEdge : isHorizontalEdge;\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tif ( hasMultiSelection() ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// When presing any key other than up or down, the initial vertical\n\t\t\t// position must ALWAYS be reset. The vertical position is saved so\n\t\t\t// it can be restored as well as possible on sebsequent vertical\n\t\t\t// arrow key presses. It may not always be possible to restore the\n\t\t\t// exact same position (such as at an empty line), so it wouldn't be\n\t\t\t// good to compute the position right before any vertical arrow key\n\t\t\t// press.\n\t\t\tif ( ! isVertical ) {\n\t\t\t\tverticalRect = null;\n\t\t\t} else if ( ! verticalRect ) {\n\t\t\t\tverticalRect = computeCaretRect( defaultView );\n\t\t\t}\n\n\t\t\t// Abort if navigation has already been handled (e.g. RichText\n\t\t\t// inline boundaries).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! isNav ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Abort if our current target is not a candidate for navigation\n\t\t\t// (e.g. preserve native input behaviors).\n\t\t\tif ( ! isNavigationCandidate( target, keyCode, hasModifier ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In the case of RTL scripts, right means previous and left means\n\t\t\t// next, which is the exact reverse of LTR.\n\t\t\tconst isReverseDir = isRTL( target ) ? ! isReverse : isReverse;\n\t\t\tconst { keepCaretInsideBlock } = getSettings();\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\n\t\t\tif ( isShift ) {\n\t\t\t\tconst selectionEndClientId = getMultiSelectedBlocksEndClientId();\n\t\t\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\t\t\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\n\t\t\t\tif (\n\t\t\t\t\t// Ensure that there is a target block.\n\t\t\t\t\t( ( isReverse && selectionBeforeEndClientId ) ||\n\t\t\t\t\t\t( ! isReverse && selectionAfterEndClientId ) ) &&\n\t\t\t\t\tisTabbableEdge( target, isReverse ) &&\n\t\t\t\t\tisNavEdge( target, isReverse )\n\t\t\t\t) {\n\t\t\t\t\tnode.contentEditable = true;\n\t\t\t\t\t// Firefox doesn't automatically move focus.\n\t\t\t\t\tnode.focus();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisVertical &&\n\t\t\t\tisVerticalEdge( target, isReverse ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverse,\n\t\t\t\t\tnode,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\n\t\t\t\tif ( closestTabbable ) {\n\t\t\t\t\tplaceCaretAtVerticalEdge(\n\t\t\t\t\t\tclosestTabbable,\n\t\t\t\t\t\tisReverse,\n\t\t\t\t\t\tverticalRect\n\t\t\t\t\t);\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisHorizontal &&\n\t\t\t\tdefaultView.getSelection().isCollapsed &&\n\t\t\t\tisHorizontalEdge( target, isReverseDir ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverseDir,\n\t\t\t\t\tnode\n\t\t\t\t);\n\t\t\t\tplaceCaretAtHorizontalEdge( closestTabbable, isReverse );\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useClickSelection;
|
|
7
|
+
|
|
8
|
+
var _data = require("@wordpress/data");
|
|
9
|
+
|
|
10
|
+
var _compose = require("@wordpress/compose");
|
|
11
|
+
|
|
12
|
+
var _store = require("../../store");
|
|
13
|
+
|
|
14
|
+
var _dom = require("../../utils/dom");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal dependencies
|
|
22
|
+
*/
|
|
23
|
+
function useClickSelection() {
|
|
24
|
+
const {
|
|
25
|
+
multiSelect,
|
|
26
|
+
selectBlock
|
|
27
|
+
} = (0, _data.useDispatch)(_store.store);
|
|
28
|
+
const {
|
|
29
|
+
isSelectionEnabled,
|
|
30
|
+
getBlockParents,
|
|
31
|
+
getBlockSelectionStart,
|
|
32
|
+
hasMultiSelection
|
|
33
|
+
} = (0, _data.useSelect)(_store.store);
|
|
34
|
+
return (0, _compose.useRefEffect)(node => {
|
|
35
|
+
function onMouseDown(event) {
|
|
36
|
+
// The main button.
|
|
37
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
|
|
38
|
+
if (!isSelectionEnabled() || event.button !== 0) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const startClientId = getBlockSelectionStart();
|
|
43
|
+
const clickedClientId = (0, _dom.getBlockClientId)(event.target);
|
|
44
|
+
|
|
45
|
+
if (event.shiftKey) {
|
|
46
|
+
if (startClientId !== clickedClientId) {
|
|
47
|
+
node.contentEditable = true; // Firefox doesn't automatically move focus.
|
|
48
|
+
|
|
49
|
+
node.focus();
|
|
50
|
+
}
|
|
51
|
+
} else if (hasMultiSelection()) {
|
|
52
|
+
// Allow user to escape out of a multi-selection to a
|
|
53
|
+
// singular selection of a block via click. This is handled
|
|
54
|
+
// here since focus handling excludes blocks when there is
|
|
55
|
+
// multiselection, as focus can be incurred by starting a
|
|
56
|
+
// multiselection (focus moved to first block's multi-
|
|
57
|
+
// controls).
|
|
58
|
+
selectBlock(clickedClientId);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
node.addEventListener('mousedown', onMouseDown);
|
|
63
|
+
return () => {
|
|
64
|
+
node.removeEventListener('mousedown', onMouseDown);
|
|
65
|
+
};
|
|
66
|
+
}, [multiSelect, selectBlock, isSelectionEnabled, getBlockParents, getBlockSelectionStart, hasMultiSelection]);
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=use-click-selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-click-selection.js"],"names":["useClickSelection","multiSelect","selectBlock","blockEditorStore","isSelectionEnabled","getBlockParents","getBlockSelectionStart","hasMultiSelection","node","onMouseDown","event","button","startClientId","clickedClientId","target","shiftKey","contentEditable","focus","addEventListener","removeEventListener"],"mappings":";;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;AAIe,SAASA,iBAAT,GAA6B;AAC3C,QAAM;AAAEC,IAAAA,WAAF;AAAeC,IAAAA;AAAf,MAA+B,uBAAaC,YAAb,CAArC;AACA,QAAM;AACLC,IAAAA,kBADK;AAELC,IAAAA,eAFK;AAGLC,IAAAA,sBAHK;AAILC,IAAAA;AAJK,MAKF,qBAAWJ,YAAX,CALJ;AAMA,SAAO,2BACJK,IAAF,IAAY;AACX,aAASC,WAAT,CAAsBC,KAAtB,EAA8B;AAC7B;AACA;AACA,UAAK,CAAEN,kBAAkB,EAApB,IAA0BM,KAAK,CAACC,MAAN,KAAiB,CAAhD,EAAoD;AACnD;AACA;;AAED,YAAMC,aAAa,GAAGN,sBAAsB,EAA5C;AACA,YAAMO,eAAe,GAAG,2BAAkBH,KAAK,CAACI,MAAxB,CAAxB;;AAEA,UAAKJ,KAAK,CAACK,QAAX,EAAsB;AACrB,YAAKH,aAAa,KAAKC,eAAvB,EAAyC;AACxCL,UAAAA,IAAI,CAACQ,eAAL,GAAuB,IAAvB,CADwC,CAExC;;AACAR,UAAAA,IAAI,CAACS,KAAL;AACA;AACD,OAND,MAMO,IAAKV,iBAAiB,EAAtB,EAA2B;AACjC;AACA;AACA;AACA;AACA;AACA;AACAL,QAAAA,WAAW,CAAEW,eAAF,CAAX;AACA;AACD;;AAEDL,IAAAA,IAAI,CAACU,gBAAL,CAAuB,WAAvB,EAAoCT,WAApC;AAEA,WAAO,MAAM;AACZD,MAAAA,IAAI,CAACW,mBAAL,CAA0B,WAA1B,EAAuCV,WAAvC;AACA,KAFD;AAGA,GAlCK,EAmCN,CACCR,WADD,EAECC,WAFD,EAGCE,kBAHD,EAICC,eAJD,EAKCC,sBALD,EAMCC,iBAND,CAnCM,CAAP;AA4CA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { getBlockClientId } from '../../utils/dom';\n\nexport default function useClickSelection() {\n\tconst { multiSelect, selectBlock } = useDispatch( blockEditorStore );\n\tconst {\n\t\tisSelectionEnabled,\n\t\tgetBlockParents,\n\t\tgetBlockSelectionStart,\n\t\thasMultiSelection,\n\t} = useSelect( blockEditorStore );\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tfunction onMouseDown( event ) {\n\t\t\t\t// The main button.\n\t\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button\n\t\t\t\tif ( ! isSelectionEnabled() || event.button !== 0 ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst startClientId = getBlockSelectionStart();\n\t\t\t\tconst clickedClientId = getBlockClientId( event.target );\n\n\t\t\t\tif ( event.shiftKey ) {\n\t\t\t\t\tif ( startClientId !== clickedClientId ) {\n\t\t\t\t\t\tnode.contentEditable = true;\n\t\t\t\t\t\t// Firefox doesn't automatically move focus.\n\t\t\t\t\t\tnode.focus();\n\t\t\t\t\t}\n\t\t\t\t} else if ( hasMultiSelection() ) {\n\t\t\t\t\t// Allow user to escape out of a multi-selection to a\n\t\t\t\t\t// singular selection of a block via click. This is handled\n\t\t\t\t\t// here since focus handling excludes blocks when there is\n\t\t\t\t\t// multiselection, as focus can be incurred by starting a\n\t\t\t\t\t// multiselection (focus moved to first block's multi-\n\t\t\t\t\t// controls).\n\t\t\t\t\tselectBlock( clickedClientId );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\n\t\t\treturn () => {\n\t\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tmultiSelect,\n\t\t\tselectBlock,\n\t\t\tisSelectionEnabled,\n\t\t\tgetBlockParents,\n\t\t\tgetBlockSelectionStart,\n\t\t\thasMultiSelection,\n\t\t]\n\t);\n}\n"]}
|