@wordpress/block-editor 8.4.0 → 8.5.2
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-alignment-control/ui.js +1 -1
- package/build/components/block-alignment-control/ui.js.map +1 -1
- package/build/components/block-content-overlay/index.js +13 -4
- package/build/components/block-content-overlay/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/index.js +8 -0
- package/build/components/block-lock/index.js.map +1 -1
- package/build/components/block-lock/menu-item.js +9 -15
- package/build/components/block-lock/menu-item.js.map +1 -1
- package/build/components/block-lock/modal.js +35 -23
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-lock/toolbar.js +11 -16
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-lock/use-block-lock.js +50 -0
- package/build/components/block-lock/use-block-lock.js.map +1 -0
- package/build/components/block-mover/index.js +4 -0
- package/build/components/block-mover/index.js.map +1 -1
- package/build/components/block-pattern-setup/index.js +37 -22
- package/build/components/block-pattern-setup/index.js.map +1 -1
- package/build/components/block-pattern-setup/setup-toolbar.js +1 -1
- package/build/components/block-pattern-setup/setup-toolbar.js.map +1 -1
- package/build/components/block-preview/auto.js +6 -3
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-preview/index.js +4 -2
- package/build/components/block-preview/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 +8 -3
- 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 +48 -9
- 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/link-control/index.js +6 -7
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/list-view/block-select-button.js +19 -6
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/block.js +18 -3
- 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 +290 -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 +264 -21
- package/build/store/selectors.js.map +1 -1
- package/build/store/utils.js +27 -0
- package/build/store/utils.js.map +1 -0
- 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-alignment-control/ui.js +2 -2
- package/build-module/components/block-alignment-control/ui.js.map +1 -1
- package/build-module/components/block-content-overlay/index.js +13 -4
- package/build-module/components/block-content-overlay/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/index.js +1 -0
- package/build-module/components/block-lock/index.js.map +1 -1
- package/build-module/components/block-lock/menu-item.js +8 -13
- package/build-module/components/block-lock/menu-item.js.map +1 -1
- package/build-module/components/block-lock/modal.js +34 -24
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-lock/toolbar.js +10 -14
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-lock/use-block-lock.js +41 -0
- package/build-module/components/block-lock/use-block-lock.js.map +1 -0
- 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-pattern-setup/index.js +39 -24
- package/build-module/components/block-pattern-setup/index.js.map +1 -1
- package/build-module/components/block-pattern-setup/setup-toolbar.js +1 -1
- package/build-module/components/block-pattern-setup/setup-toolbar.js.map +1 -1
- package/build-module/components/block-preview/auto.js +6 -3
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-preview/index.js +4 -2
- package/build-module/components/block-preview/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 +9 -4
- 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 +48 -9
- 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/link-control/index.js +6 -7
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +17 -6
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/block.js +18 -3
- 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 +277 -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 +250 -21
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/utils.js +20 -0
- package/build-module/store/utils.js.map +1 -0
- package/build-module/utils/dom.js +2 -1
- package/build-module/utils/dom.js.map +1 -1
- package/build-style/style-rtl.css +142 -101
- package/build-style/style.css +142 -101
- 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-alignment-control/ui.js +2 -2
- package/src/components/block-content-overlay/index.js +19 -2
- 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/index.js +1 -0
- package/src/components/block-lock/menu-item.js +6 -19
- package/src/components/block-lock/modal.js +52 -23
- package/src/components/block-lock/style.scss +7 -5
- package/src/components/block-lock/toolbar.js +7 -14
- package/src/components/block-lock/use-block-lock.js +45 -0
- package/src/components/block-mover/index.js +3 -0
- package/src/components/block-mover/style.scss +4 -0
- package/src/components/block-pattern-setup/index.js +84 -59
- package/src/components/block-pattern-setup/setup-toolbar.js +3 -1
- package/src/components/block-pattern-setup/style.scss +32 -26
- package/src/components/block-preview/auto.js +10 -1
- package/src/components/block-preview/index.js +2 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +62 -4
- package/src/components/block-switcher/index.js +15 -3
- package/src/components/block-switcher/style.scss +15 -4
- package/src/components/block-switcher/test/__snapshots__/index.js.snap +15 -13
- 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 +55 -10
- 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/link-control/index.js +5 -5
- package/src/components/list-view/block-select-button.js +13 -3
- package/src/components/list-view/block.js +24 -8
- 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 +341 -32
- package/src/store/defaults.js +7 -2
- package/src/store/reducer.js +25 -10
- package/src/store/selectors.js +329 -26
- package/src/store/test/selectors.js +242 -5
- package/src/store/utils.js +19 -0
- 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
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { findKey } from 'lodash';
|
|
1
5
|
/**
|
|
2
6
|
* WordPress dependencies
|
|
3
7
|
*/
|
|
8
|
+
|
|
4
9
|
import { useRef } from '@wordpress/element';
|
|
5
10
|
import { useRefEffect } from '@wordpress/compose';
|
|
6
|
-
import {
|
|
11
|
+
import { insert, toHTMLString } from '@wordpress/rich-text';
|
|
7
12
|
import { getBlockTransforms, findTransform } from '@wordpress/blocks';
|
|
8
13
|
import { useDispatch } from '@wordpress/data';
|
|
9
14
|
/**
|
|
@@ -11,7 +16,31 @@ import { useDispatch } from '@wordpress/data';
|
|
|
11
16
|
*/
|
|
12
17
|
|
|
13
18
|
import { store as blockEditorStore } from '../../store';
|
|
14
|
-
import { preventEventDiscovery } from './prevent-event-discovery';
|
|
19
|
+
import { preventEventDiscovery } from './prevent-event-discovery'; // A robust way to retain selection position through various
|
|
20
|
+
// transforms is to insert a special character at the position and
|
|
21
|
+
// then recover it.
|
|
22
|
+
|
|
23
|
+
const START_OF_SELECTED_AREA = '\u0086';
|
|
24
|
+
|
|
25
|
+
function findSelection(blocks) {
|
|
26
|
+
let i = blocks.length;
|
|
27
|
+
|
|
28
|
+
while (i--) {
|
|
29
|
+
const attributeKey = findKey(blocks[i].attributes, v => typeof v === 'string' && v.indexOf(START_OF_SELECTED_AREA) !== -1);
|
|
30
|
+
|
|
31
|
+
if (attributeKey) {
|
|
32
|
+
blocks[i].attributes[attributeKey] = blocks[i].attributes[attributeKey].replace(START_OF_SELECTED_AREA, '');
|
|
33
|
+
return blocks[i].clientId;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const nestedSelection = findSelection(blocks[i].innerBlocks);
|
|
37
|
+
|
|
38
|
+
if (nestedSelection) {
|
|
39
|
+
return nestedSelection;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
15
44
|
export function useInputRules(props) {
|
|
16
45
|
const {
|
|
17
46
|
__unstableMarkLastChangeAsPersistent,
|
|
@@ -23,7 +52,8 @@ export function useInputRules(props) {
|
|
|
23
52
|
function inputRule() {
|
|
24
53
|
const {
|
|
25
54
|
value,
|
|
26
|
-
onReplace
|
|
55
|
+
onReplace,
|
|
56
|
+
selectionChange
|
|
27
57
|
} = propsRef.current;
|
|
28
58
|
|
|
29
59
|
if (!onReplace) {
|
|
@@ -59,9 +89,10 @@ export function useInputRules(props) {
|
|
|
59
89
|
}
|
|
60
90
|
|
|
61
91
|
const content = toHTMLString({
|
|
62
|
-
value:
|
|
92
|
+
value: insert(value, START_OF_SELECTED_AREA, 0, start)
|
|
63
93
|
});
|
|
64
94
|
const block = transformation.transform(content);
|
|
95
|
+
selectionChange(findSelection([block]));
|
|
65
96
|
onReplace([block]);
|
|
66
97
|
|
|
67
98
|
__unstableMarkAutomaticChange();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-input-rules.js"],"names":["useRef","useRefEffect","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-input-rules.js"],"names":["findKey","useRef","useRefEffect","insert","toHTMLString","getBlockTransforms","findTransform","useDispatch","store","blockEditorStore","preventEventDiscovery","START_OF_SELECTED_AREA","findSelection","blocks","i","length","attributeKey","attributes","v","indexOf","replace","clientId","nestedSelection","innerBlocks","useInputRules","props","__unstableMarkLastChangeAsPersistent","__unstableMarkAutomaticChange","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":"AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,QAAxB;AAEA;AACA;AACA;;AACA,SAASC,MAAT,QAAuB,oBAAvB;AACA,SAASC,YAAT,QAA6B,oBAA7B;AACA,SAASC,MAAT,EAAiBC,YAAjB,QAAqC,sBAArC;AACA,SAASC,kBAAT,EAA6BC,aAA7B,QAAkD,mBAAlD;AACA,SAASC,WAAT,QAA4B,iBAA5B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,qBAAT,QAAsC,2BAAtC,C,CAEA;AACA;AACA;;AACA,MAAMC,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,GAAGhB,OAAO,CAC3Ba,MAAM,CAAEC,CAAF,CAAN,CAAYG,UADe,EAEzBC,CAAF,IACC,OAAOA,CAAP,KAAa,QAAb,IACAA,CAAC,CAACC,OAAF,CAAWR,sBAAX,MAAwC,CAAC,CAJf,CAA5B;;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,EAE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AA,oCAAoC;;AACpC0B,QAAAA,QAAQ,CAAE,EACT,GAAGG,WADM;AAETI,UAAAA,aAAa,EAAE3B,KAAK,CAAC2B;AAFZ,SAAF,CAAR;;AAIAhC,QAAAA,6BAA6B;AAC7B;AACD;;AAEDG,IAAAA,OAAO,CAAC8B,gBAAR,CAA0B,OAA1B,EAAmCX,OAAnC;AACAnB,IAAAA,OAAO,CAAC8B,gBAAR,CAA0B,gBAA1B,EAA4CX,OAA5C;AACA,WAAO,MAAM;AACZnB,MAAAA,OAAO,CAAC+B,mBAAR,CAA6B,OAA7B,EAAsCZ,OAAtC;AACAnB,MAAAA,OAAO,CAAC+B,mBAAR,CAA6B,gBAA7B,EAA+CZ,OAA/C;AACA,KAHD;AAIA,GAtFkB,EAsFhB,EAtFgB,CAAnB;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"]}
|
|
@@ -29,6 +29,10 @@ const SkipToSelectedBlock = _ref => {
|
|
|
29
29
|
onClick: onClick
|
|
30
30
|
}, __('Skip to the selected block')) : null;
|
|
31
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/skip-to-selected-block/README.md
|
|
34
|
+
*/
|
|
35
|
+
|
|
32
36
|
|
|
33
37
|
export default withSelect(select => {
|
|
34
38
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/skip-to-selected-block/index.js"],"names":["withSelect","__","Button","store","blockEditorStore","__unstableUseBlockRef","useBlockRef","SkipToSelectedBlock","selectedBlockClientId","ref","onClick","current","focus","select","getBlockSelectionStart"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,UAAT,QAA2B,iBAA3B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,MAAT,QAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,qBAAqB,IAAIC,WAAlC,QAAqD,8CAArD;;AAEA,MAAMC,mBAAmB,GAAG,QAAiC;AAAA,MAA/B;AAAEC,IAAAA;AAAF,GAA+B;AAC5D,QAAMC,GAAG,GAAGH,WAAW,CAAEE,qBAAF,CAAvB;;AACA,QAAME,OAAO,GAAG,MAAM;AACrBD,IAAAA,GAAG,CAACE,OAAJ,CAAYC,KAAZ;AACA,GAFD;;AAIA,SAAOJ,qBAAqB,GAC3B,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,WADT;AAEC,IAAA,SAAS,EAAC,qCAFX;AAGC,IAAA,OAAO,EAAGE;AAHX,KAKGT,EAAE,CAAE,4BAAF,CALL,CAD2B,GAQxB,IARJ;AASA,CAfD
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/skip-to-selected-block/index.js"],"names":["withSelect","__","Button","store","blockEditorStore","__unstableUseBlockRef","useBlockRef","SkipToSelectedBlock","selectedBlockClientId","ref","onClick","current","focus","select","getBlockSelectionStart"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,UAAT,QAA2B,iBAA3B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,MAAT,QAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,qBAAqB,IAAIC,WAAlC,QAAqD,8CAArD;;AAEA,MAAMC,mBAAmB,GAAG,QAAiC;AAAA,MAA/B;AAAEC,IAAAA;AAAF,GAA+B;AAC5D,QAAMC,GAAG,GAAGH,WAAW,CAAEE,qBAAF,CAAvB;;AACA,QAAME,OAAO,GAAG,MAAM;AACrBD,IAAAA,GAAG,CAACE,OAAJ,CAAYC,KAAZ;AACA,GAFD;;AAIA,SAAOJ,qBAAqB,GAC3B,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,WADT;AAEC,IAAA,SAAS,EAAC,qCAFX;AAGC,IAAA,OAAO,EAAGE;AAHX,KAKGT,EAAE,CAAE,4BAAF,CALL,CAD2B,GAQxB,IARJ;AASA,CAfD;AAiBA;AACA;AACA;;;AACA,eAAeD,UAAU,CAAIa,MAAF,IAAc;AACxC,SAAO;AACNL,IAAAA,qBAAqB,EAAEK,MAAM,CAC5BT,gBAD4B,CAAN,CAErBU,sBAFqB;AADjB,GAAP;AAKA,CANwB,CAAV,CAMVP,mBANU,CAAf","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"]}
|
|
@@ -21,11 +21,15 @@ import useMultiSelection from './use-multi-selection';
|
|
|
21
21
|
import useTabNav from './use-tab-nav';
|
|
22
22
|
import useArrowNav from './use-arrow-nav';
|
|
23
23
|
import useSelectAll from './use-select-all';
|
|
24
|
+
import useDragSelection from './use-drag-selection';
|
|
25
|
+
import useSelectionObserver from './use-selection-observer';
|
|
26
|
+
import useClickSelection from './use-click-selection';
|
|
27
|
+
import useInput from './use-input';
|
|
24
28
|
import { store as blockEditorStore } from '../../store';
|
|
25
29
|
export function useWritingFlow() {
|
|
26
30
|
const [before, ref, after] = useTabNav();
|
|
27
31
|
const hasMultiSelection = useSelect(select => select(blockEditorStore).hasMultiSelection(), []);
|
|
28
|
-
return [before, useMergeRefs([ref, useMultiSelection(), useSelectAll(), useArrowNav(), useRefEffect(node => {
|
|
32
|
+
return [before, useMergeRefs([ref, useInput(), useDragSelection(), useSelectionObserver(), useClickSelection(), useMultiSelection(), useSelectAll(), useArrowNav(), useRefEffect(node => {
|
|
29
33
|
node.tabIndex = -1;
|
|
30
34
|
node.contentEditable = hasMultiSelection;
|
|
31
35
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/index.js"],"names":["classNames","useSelect","__","useMergeRefs","useRefEffect","forwardRef","useMultiSelection","useTabNav","useArrowNav","useSelectAll","store","blockEditorStore","useWritingFlow","before","ref","after","hasMultiSelection","select","node","tabIndex","contentEditable","setAttribute","removeAttribute","WritingFlow","forwardedRef","children","props","className"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,EAAuBC,YAAvB,QAA2C,oBAA3C;AACA,SAASC,UAAT,QAA2B,oBAA3B;AAEA;AACA;AACA;;AACA,OAAOC,iBAAP,MAA8B,uBAA9B;AACA,OAAOC,SAAP,MAAsB,eAAtB;AACA,OAAOC,WAAP,MAAwB,iBAAxB;AACA,OAAOC,YAAP,MAAyB,kBAAzB;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA,OAAO,SAASC,cAAT,GAA0B;AAChC,QAAM,CAAEC,MAAF,EAAUC,GAAV,EAAeC,KAAf,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/index.js"],"names":["classNames","useSelect","__","useMergeRefs","useRefEffect","forwardRef","useMultiSelection","useTabNav","useArrowNav","useSelectAll","useDragSelection","useSelectionObserver","useClickSelection","useInput","store","blockEditorStore","useWritingFlow","before","ref","after","hasMultiSelection","select","node","tabIndex","contentEditable","setAttribute","removeAttribute","WritingFlow","forwardedRef","children","props","className"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,EAAuBC,YAAvB,QAA2C,oBAA3C;AACA,SAASC,UAAT,QAA2B,oBAA3B;AAEA;AACA;AACA;;AACA,OAAOC,iBAAP,MAA8B,uBAA9B;AACA,OAAOC,SAAP,MAAsB,eAAtB;AACA,OAAOC,WAAP,MAAwB,iBAAxB;AACA,OAAOC,YAAP,MAAyB,kBAAzB;AACA,OAAOC,gBAAP,MAA6B,sBAA7B;AACA,OAAOC,oBAAP,MAAiC,0BAAjC;AACA,OAAOC,iBAAP,MAA8B,uBAA9B;AACA,OAAOC,QAAP,MAAqB,aAArB;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA,OAAO,SAASC,cAAT,GAA0B;AAChC,QAAM,CAAEC,MAAF,EAAUC,GAAV,EAAeC,KAAf,IAAyBZ,SAAS,EAAxC;AACA,QAAMa,iBAAiB,GAAGnB,SAAS,CAChCoB,MAAF,IAAcA,MAAM,CAAEN,gBAAF,CAAN,CAA2BK,iBAA3B,EADoB,EAElC,EAFkC,CAAnC;AAKA,SAAO,CACNH,MADM,EAENd,YAAY,CAAE,CACbe,GADa,EAEbL,QAAQ,EAFK,EAGbH,gBAAgB,EAHH,EAIbC,oBAAoB,EAJP,EAKbC,iBAAiB,EALJ,EAMbN,iBAAiB,EANJ,EAObG,YAAY,EAPC,EAQbD,WAAW,EARE,EASbJ,YAAY,CACTkB,IAAF,IAAY;AACXA,IAAAA,IAAI,CAACC,QAAL,GAAgB,CAAC,CAAjB;AACAD,IAAAA,IAAI,CAACE,eAAL,GAAuBJ,iBAAvB;;AAEA,QAAK,CAAEA,iBAAP,EAA2B;AAC1B;AACA;;AAEDE,IAAAA,IAAI,CAACG,YAAL,CACC,YADD,EAECvB,EAAE,CAAE,0BAAF,CAFH;AAKA,WAAO,MAAM;AACZoB,MAAAA,IAAI,CAACI,eAAL,CAAsB,YAAtB;AACA,KAFD;AAGA,GAjBU,EAkBX,CAAEN,iBAAF,CAlBW,CATC,CAAF,CAFN,EAgCND,KAhCM,CAAP;AAkCA;;AAED,SAASQ,WAAT,OAA8CC,YAA9C,EAA6D;AAAA,MAAvC;AAAEC,IAAAA,QAAF;AAAY,OAAGC;AAAf,GAAuC;AAC5D,QAAM,CAAEb,MAAF,EAAUC,GAAV,EAAeC,KAAf,IAAyBH,cAAc,EAA7C;AACA,SACC,8BACGC,MADH,EAEC,kCACMa,KADN;AAEC,IAAA,GAAG,EAAG3B,YAAY,CAAE,CAAEe,GAAF,EAAOU,YAAP,CAAF,CAFnB;AAGC,IAAA,SAAS,EAAG5B,UAAU,CACrB8B,KAAK,CAACC,SADe,EAErB,2BAFqB;AAHvB,MAQGF,QARH,CAFD,EAYGV,KAZH,CADD;AAgBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAed,UAAU,CAAEsB,WAAF,CAAzB","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"]}
|
|
@@ -8,7 +8,7 @@ import { find, reverse } from 'lodash';
|
|
|
8
8
|
|
|
9
9
|
import { computeCaretRect, focus, isHorizontalEdge, isVerticalEdge, placeCaretAtHorizontalEdge, placeCaretAtVerticalEdge, isRTL } from '@wordpress/dom';
|
|
10
10
|
import { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';
|
|
11
|
-
import { useSelect
|
|
11
|
+
import { useSelect } from '@wordpress/data';
|
|
12
12
|
import { useRefEffect } from '@wordpress/compose';
|
|
13
13
|
/**
|
|
14
14
|
* Internal dependencies
|
|
@@ -101,19 +101,12 @@ export function getClosestTabbable(target, isReverse, containerElement, onlyVert
|
|
|
101
101
|
export default function useArrowNav() {
|
|
102
102
|
const {
|
|
103
103
|
getSelectedBlockClientId,
|
|
104
|
-
getMultiSelectedBlocksStartClientId,
|
|
105
104
|
getMultiSelectedBlocksEndClientId,
|
|
106
105
|
getPreviousBlockClientId,
|
|
107
106
|
getNextBlockClientId,
|
|
108
|
-
getFirstMultiSelectedBlockClientId,
|
|
109
|
-
getLastMultiSelectedBlockClientId,
|
|
110
107
|
getSettings,
|
|
111
108
|
hasMultiSelection
|
|
112
109
|
} = useSelect(blockEditorStore);
|
|
113
|
-
const {
|
|
114
|
-
multiSelect,
|
|
115
|
-
selectBlock
|
|
116
|
-
} = useDispatch(blockEditorStore);
|
|
117
110
|
return useRefEffect(node => {
|
|
118
111
|
// Here a DOMRect is stored while moving the caret vertically so
|
|
119
112
|
// vertical position of the start position can be restored. This is to
|
|
@@ -123,33 +116,6 @@ export default function useArrowNav() {
|
|
|
123
116
|
function onMouseDown() {
|
|
124
117
|
verticalRect = null;
|
|
125
118
|
}
|
|
126
|
-
|
|
127
|
-
function expandSelection(isReverse) {
|
|
128
|
-
const selectedBlockClientId = getSelectedBlockClientId();
|
|
129
|
-
const selectionStartClientId = getMultiSelectedBlocksStartClientId();
|
|
130
|
-
const selectionEndClientId = getMultiSelectedBlocksEndClientId();
|
|
131
|
-
const selectionBeforeEndClientId = getPreviousBlockClientId(selectionEndClientId || selectedBlockClientId);
|
|
132
|
-
const selectionAfterEndClientId = getNextBlockClientId(selectionEndClientId || selectedBlockClientId);
|
|
133
|
-
const nextSelectionEndClientId = isReverse ? selectionBeforeEndClientId : selectionAfterEndClientId;
|
|
134
|
-
|
|
135
|
-
if (nextSelectionEndClientId) {
|
|
136
|
-
if (selectionStartClientId === nextSelectionEndClientId) {
|
|
137
|
-
selectBlock(nextSelectionEndClientId);
|
|
138
|
-
} else {
|
|
139
|
-
multiSelect(selectionStartClientId || selectedBlockClientId, nextSelectionEndClientId);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function moveSelection(isReverse) {
|
|
145
|
-
const selectedFirstClientId = getFirstMultiSelectedBlockClientId();
|
|
146
|
-
const selectedLastClientId = getLastMultiSelectedBlockClientId();
|
|
147
|
-
const focusedBlockClientId = isReverse ? selectedFirstClientId : selectedLastClientId;
|
|
148
|
-
|
|
149
|
-
if (focusedBlockClientId) {
|
|
150
|
-
selectBlock(focusedBlockClientId);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
119
|
/**
|
|
154
120
|
* Returns true if the given target field is the last in its block which
|
|
155
121
|
* can be considered for tab transition. For example, in a block with
|
|
@@ -192,12 +158,6 @@ export default function useArrowNav() {
|
|
|
192
158
|
} = ownerDocument;
|
|
193
159
|
|
|
194
160
|
if (hasMultiSelection()) {
|
|
195
|
-
if (isNav) {
|
|
196
|
-
const action = isShift ? expandSelection : moveSelection;
|
|
197
|
-
action(isReverse);
|
|
198
|
-
event.preventDefault();
|
|
199
|
-
}
|
|
200
|
-
|
|
201
161
|
return;
|
|
202
162
|
} // When presing any key other than up or down, the initial vertical
|
|
203
163
|
// position must ALWAYS be reset. The vertical position is saved so
|
|
@@ -245,10 +205,9 @@ export default function useArrowNav() {
|
|
|
245
205
|
|
|
246
206
|
if ( // Ensure that there is a target block.
|
|
247
207
|
(isReverse && selectionBeforeEndClientId || !isReverse && selectionAfterEndClientId) && isTabbableEdge(target, isReverse) && isNavEdge(target, isReverse)) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
event.preventDefault();
|
|
208
|
+
node.contentEditable = true; // Firefox doesn't automatically move focus.
|
|
209
|
+
|
|
210
|
+
node.focus();
|
|
252
211
|
}
|
|
253
212
|
} else if (isVertical && isVerticalEdge(target, isReverse) && !keepCaretInsideBlock) {
|
|
254
213
|
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":["find","reverse","computeCaretRect","focus","isHorizontalEdge","isVerticalEdge","placeCaretAtHorizontalEdge","placeCaretAtVerticalEdge","isRTL","UP","DOWN","LEFT","RIGHT","useSelect","useDispatch","useRefEffect","isInSameBlock","store","blockEditorStore","isNavigationCandidate","element","keyCode","hasModifier","isVertical","tagName","getClosestTabbable","target","isReverse","containerElement","onlyVertical","focusableNodes","focusable","slice","indexOf","targetRect","getBoundingClientRect","isTabCandidate","node","tabbable","isTabbableIndex","isContentEditable","contentEditable","nodeRect","left","right","useArrowNav","getSelectedBlockClientId","getMultiSelectedBlocksStartClientId","getMultiSelectedBlocksEndClientId","getPreviousBlockClientId","getNextBlockClientId","getFirstMultiSelectedBlockClientId","getLastMultiSelectedBlockClientId","getSettings","hasMultiSelection","multiSelect","selectBlock","verticalRect","onMouseDown","expandSelection","selectedBlockClientId","selectionStartClientId","selectionEndClientId","selectionBeforeEndClientId","selectionAfterEndClientId","nextSelectionEndClientId","moveSelection","selectedFirstClientId","selectedLastClientId","focusedBlockClientId","isTabbableEdge","closestTabbable","onKeyDown","event","isUp","isDown","isLeft","isRight","isHorizontal","isNav","isShift","shiftKey","ctrlKey","altKey","metaKey","isNavEdge","ownerDocument","defaultView","action","preventDefault","defaultPrevented","isReverseDir","keepCaretInsideBlock","getSelection","isCollapsed","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,OAAf,QAA8B,QAA9B;AAEA;AACA;AACA;;AACA,SACCC,gBADD,EAECC,KAFD,EAGCC,gBAHD,EAICC,cAJD,EAKCC,0BALD,EAMCC,wBAND,EAOCC,KAPD,QAQO,gBARP;AASA,SAASC,EAAT,EAAaC,IAAb,EAAmBC,IAAnB,EAAyBC,KAAzB,QAAsC,qBAAtC;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,SAASC,aAAT,QAA8B,iBAA9B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,qBAAT,CAAgCC,OAAhC,EAAyCC,OAAzC,EAAkDC,WAAlD,EAAgE;AACtE,QAAMC,UAAU,GAAGF,OAAO,KAAKZ,EAAZ,IAAkBY,OAAO,KAAKX,IAAjD,CADsE,CAGtE;;AACA,MAAKa,UAAU,IAAI,CAAED,WAArB,EAAmC;AAClC,WAAO,IAAP;AACA,GANqE,CAQtE;;;AACA,QAAM;AAAEE,IAAAA;AAAF,MAAcJ,OAApB;AACA,SAAOI,OAAO,KAAK,OAAZ,IAAuBA,OAAO,KAAK,UAA1C;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,kBAAT,CACNC,MADM,EAENC,SAFM,EAGNC,gBAHM,EAINC,YAJM,EAKL;AACD;AACA;AACA,MA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CADd,IAEA,CAAEiE,oBAHI,EAIL;AACD,cAAMrB,eAAe,GAAG9C,kBAAkB,CACzCC,MADyC,EAEzCC,SAFyC,EAGzCU,IAHyC,EAIzC,IAJyC,CAA1C;;AAOA,YAAKkC,eAAL,EAAuB;AACtBhE,UAAAA,wBAAwB,CACvBgE,eADuB,EAEvB5C,SAFuB,EAGvB8B,YAHuB,CAAxB;AAKAgB,UAAAA,KAAK,CAACgB,cAAN;AACA;AACD,OApBM,MAoBA,IACNX,YAAY,IACZS,WAAW,CAACM,YAAZ,GAA2BC,WAD3B,IAEA1F,gBAAgB,CAAEsB,MAAF,EAAUiE,YAAV,CAFhB,IAGA,CAAEC,oBAJI,EAKL;AACD,cAAMrB,eAAe,GAAG9C,kBAAkB,CACzCC,MADyC,EAEzCiE,YAFyC,EAGzCtD,IAHyC,CAA1C;AAKA/B,QAAAA,0BAA0B,CAAEiE,eAAF,EAAmB5C,SAAnB,CAA1B;AACA8C,QAAAA,KAAK,CAACgB,cAAN;AACA;AACD;;AAEDpD,IAAAA,IAAI,CAAC0D,gBAAL,CAAuB,WAAvB,EAAoCrC,WAApC;AACArB,IAAAA,IAAI,CAAC0D,gBAAL,CAAuB,SAAvB,EAAkCvB,SAAlC;AACA,WAAO,MAAM;AACZnC,MAAAA,IAAI,CAAC2D,mBAAL,CAA0B,WAA1B,EAAuCtC,WAAvC;AACArB,MAAAA,IAAI,CAAC2D,mBAAL,CAA0B,SAA1B,EAAqCxB,SAArC;AACA,KAHD;AAIA,GAnMkB,EAmMhB,EAnMgB,CAAnB;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":["find","reverse","computeCaretRect","focus","isHorizontalEdge","isVerticalEdge","placeCaretAtHorizontalEdge","placeCaretAtVerticalEdge","isRTL","UP","DOWN","LEFT","RIGHT","useSelect","useRefEffect","isInSameBlock","store","blockEditorStore","isNavigationCandidate","element","keyCode","hasModifier","isVertical","tagName","getClosestTabbable","target","isReverse","containerElement","onlyVertical","focusableNodes","focusable","slice","indexOf","targetRect","getBoundingClientRect","isTabCandidate","node","tabbable","isTabbableIndex","isContentEditable","contentEditable","nodeRect","left","right","useArrowNav","getSelectedBlockClientId","getMultiSelectedBlocksEndClientId","getPreviousBlockClientId","getNextBlockClientId","getSettings","hasMultiSelection","verticalRect","onMouseDown","isTabbableEdge","closestTabbable","onKeyDown","event","isUp","isDown","isLeft","isRight","isHorizontal","isNav","isShift","shiftKey","ctrlKey","altKey","metaKey","isNavEdge","ownerDocument","defaultView","defaultPrevented","isReverseDir","keepCaretInsideBlock","selectedBlockClientId","selectionEndClientId","selectionBeforeEndClientId","selectionAfterEndClientId","preventDefault","getSelection","isCollapsed","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,OAAf,QAA8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AK,CAACsB,cAAN;AACA;AACD,OApBM,MAoBA,IACNjB,YAAY,IACZS,WAAW,CAACS,YAAZ,GAA2BC,WAD3B,IAEA5E,gBAAgB,CAAEqB,MAAF,EAAU+C,YAAV,CAFhB,IAGA,CAAEC,oBAJI,EAKL;AACD,cAAMnB,eAAe,GAAG9B,kBAAkB,CACzCC,MADyC,EAEzC+C,YAFyC,EAGzCpC,IAHyC,CAA1C;AAKA9B,QAAAA,0BAA0B,CAAEgD,eAAF,EAAmB5B,SAAnB,CAA1B;AACA8B,QAAAA,KAAK,CAACsB,cAAN;AACA;AACD;;AAED1C,IAAAA,IAAI,CAAC6C,gBAAL,CAAuB,WAAvB,EAAoC7B,WAApC;AACAhB,IAAAA,IAAI,CAAC6C,gBAAL,CAAuB,SAAvB,EAAkC1B,SAAlC;AACA,WAAO,MAAM;AACZnB,MAAAA,IAAI,CAAC8C,mBAAL,CAA0B,WAA1B,EAAuC9B,WAAvC;AACAhB,MAAAA,IAAI,CAAC8C,mBAAL,CAA0B,SAA1B,EAAqC3B,SAArC;AACA,KAHD;AAIA,GAtJkB,EAsJhB,EAtJgB,CAAnB;AAuJA","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 } 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,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
+
import { useRefEffect } from '@wordpress/compose';
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { store as blockEditorStore } from '../../store';
|
|
11
|
+
import { getBlockClientId } from '../../utils/dom';
|
|
12
|
+
export default function useClickSelection() {
|
|
13
|
+
const {
|
|
14
|
+
multiSelect,
|
|
15
|
+
selectBlock
|
|
16
|
+
} = useDispatch(blockEditorStore);
|
|
17
|
+
const {
|
|
18
|
+
isSelectionEnabled,
|
|
19
|
+
getBlockParents,
|
|
20
|
+
getBlockSelectionStart,
|
|
21
|
+
hasMultiSelection
|
|
22
|
+
} = useSelect(blockEditorStore);
|
|
23
|
+
return useRefEffect(node => {
|
|
24
|
+
function onMouseDown(event) {
|
|
25
|
+
// The main button.
|
|
26
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
|
|
27
|
+
if (!isSelectionEnabled() || event.button !== 0) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const startClientId = getBlockSelectionStart();
|
|
32
|
+
const clickedClientId = getBlockClientId(event.target);
|
|
33
|
+
|
|
34
|
+
if (event.shiftKey) {
|
|
35
|
+
if (startClientId !== clickedClientId) {
|
|
36
|
+
node.contentEditable = true; // Firefox doesn't automatically move focus.
|
|
37
|
+
|
|
38
|
+
node.focus();
|
|
39
|
+
}
|
|
40
|
+
} else if (hasMultiSelection()) {
|
|
41
|
+
// Allow user to escape out of a multi-selection to a
|
|
42
|
+
// singular selection of a block via click. This is handled
|
|
43
|
+
// here since focus handling excludes blocks when there is
|
|
44
|
+
// multiselection, as focus can be incurred by starting a
|
|
45
|
+
// multiselection (focus moved to first block's multi-
|
|
46
|
+
// controls).
|
|
47
|
+
selectBlock(clickedClientId);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
node.addEventListener('mousedown', onMouseDown);
|
|
52
|
+
return () => {
|
|
53
|
+
node.removeEventListener('mousedown', onMouseDown);
|
|
54
|
+
};
|
|
55
|
+
}, [multiSelect, selectBlock, isSelectionEnabled, getBlockParents, getBlockSelectionStart, hasMultiSelection]);
|
|
56
|
+
}
|
|
57
|
+
//# 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":["useSelect","useDispatch","useRefEffect","store","blockEditorStore","getBlockClientId","useClickSelection","multiSelect","selectBlock","isSelectionEnabled","getBlockParents","getBlockSelectionStart","hasMultiSelection","node","onMouseDown","event","button","startClientId","clickedClientId","target","shiftKey","contentEditable","focus","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,gBAAT,QAAiC,iBAAjC;AAEA,eAAe,SAASC,iBAAT,GAA6B;AAC3C,QAAM;AAAEC,IAAAA,WAAF;AAAeC,IAAAA;AAAf,MAA+BP,WAAW,CAAEG,gBAAF,CAAhD;AACA,QAAM;AACLK,IAAAA,kBADK;AAELC,IAAAA,eAFK;AAGLC,IAAAA,sBAHK;AAILC,IAAAA;AAJK,MAKFZ,SAAS,CAAEI,gBAAF,CALb;AAMA,SAAOF,YAAY,CAChBW,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,GAAGb,gBAAgB,CAAEU,KAAK,CAACI,MAAR,CAAxC;;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;AACAJ,QAAAA,WAAW,CAAEU,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,GAlCiB,EAmClB,CACCP,WADD,EAECC,WAFD,EAGCC,kBAHD,EAICC,eAJD,EAKCC,sBALD,EAMCC,iBAND,CAnCkB,CAAnB;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"]}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
+
import { useRefEffect } from '@wordpress/compose';
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { store as blockEditorStore } from '../../store';
|
|
11
|
+
/**
|
|
12
|
+
* Sets the `contenteditable` wrapper element to `value`.
|
|
13
|
+
*
|
|
14
|
+
* @param {HTMLElement} node Block element.
|
|
15
|
+
* @param {boolean} value `contentEditable` value (true or false)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
function setContentEditableWrapper(node, value) {
|
|
19
|
+
node.contentEditable = value; // Firefox doesn't automatically move focus.
|
|
20
|
+
|
|
21
|
+
if (value) node.focus();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Sets a multi-selection based on the native selection across blocks.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
export default function useDragSelection() {
|
|
29
|
+
const {
|
|
30
|
+
startMultiSelect,
|
|
31
|
+
stopMultiSelect
|
|
32
|
+
} = useDispatch(blockEditorStore);
|
|
33
|
+
const {
|
|
34
|
+
isSelectionEnabled,
|
|
35
|
+
hasMultiSelection
|
|
36
|
+
} = useSelect(blockEditorStore);
|
|
37
|
+
return useRefEffect(node => {
|
|
38
|
+
const {
|
|
39
|
+
ownerDocument
|
|
40
|
+
} = node;
|
|
41
|
+
const {
|
|
42
|
+
defaultView
|
|
43
|
+
} = ownerDocument;
|
|
44
|
+
let anchorElement;
|
|
45
|
+
let rafId;
|
|
46
|
+
|
|
47
|
+
function onMouseUp() {
|
|
48
|
+
stopMultiSelect(); // Equivalent to attaching the listener once.
|
|
49
|
+
|
|
50
|
+
defaultView.removeEventListener('mouseup', onMouseUp); // The browser selection won't have updated yet at this point,
|
|
51
|
+
// so wait until the next animation frame to get the browser
|
|
52
|
+
// selection.
|
|
53
|
+
|
|
54
|
+
rafId = defaultView.requestAnimationFrame(() => {
|
|
55
|
+
if (hasMultiSelection()) {
|
|
56
|
+
return;
|
|
57
|
+
} // If the selection is complete (on mouse up), and no
|
|
58
|
+
// multiple blocks have been selected, set focus back to the
|
|
59
|
+
// anchor element. if the anchor element contains the
|
|
60
|
+
// selection. Additionally, the contentEditable wrapper can
|
|
61
|
+
// now be disabled again.
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
setContentEditableWrapper(node, false);
|
|
65
|
+
const selection = defaultView.getSelection();
|
|
66
|
+
|
|
67
|
+
if (selection.rangeCount) {
|
|
68
|
+
const {
|
|
69
|
+
commonAncestorContainer
|
|
70
|
+
} = selection.getRangeAt(0);
|
|
71
|
+
|
|
72
|
+
if (anchorElement.contains(commonAncestorContainer)) {
|
|
73
|
+
anchorElement.focus();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function onMouseLeave(_ref) {
|
|
80
|
+
let {
|
|
81
|
+
buttons,
|
|
82
|
+
target
|
|
83
|
+
} = _ref;
|
|
84
|
+
|
|
85
|
+
// The primary button must be pressed to initiate selection.
|
|
86
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
|
|
87
|
+
if (buttons !== 1) {
|
|
88
|
+
return;
|
|
89
|
+
} // Check the attribute, not the contentEditable attribute. All
|
|
90
|
+
// child elements of the content editable wrapper are editable
|
|
91
|
+
// and return true for this property. We only want to start
|
|
92
|
+
// multi selecting when the mouse leaves the wrapper.
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if (!target.getAttribute('contenteditable')) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!isSelectionEnabled()) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
anchorElement = ownerDocument.activeElement;
|
|
104
|
+
startMultiSelect(); // `onSelectionStart` is called after `mousedown` and
|
|
105
|
+
// `mouseleave` (from a block). The selection ends when
|
|
106
|
+
// `mouseup` happens anywhere in the window.
|
|
107
|
+
|
|
108
|
+
defaultView.addEventListener('mouseup', onMouseUp); // Allow cross contentEditable selection by temporarily making
|
|
109
|
+
// all content editable. We can't rely on using the store and
|
|
110
|
+
// React because re-rending happens too slowly. We need to be
|
|
111
|
+
// able to select across instances immediately.
|
|
112
|
+
|
|
113
|
+
setContentEditableWrapper(node, true);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
node.addEventListener('mouseout', onMouseLeave);
|
|
117
|
+
return () => {
|
|
118
|
+
node.removeEventListener('mouseout', onMouseLeave);
|
|
119
|
+
defaultView.removeEventListener('mouseup', onMouseUp);
|
|
120
|
+
defaultView.cancelAnimationFrame(rafId);
|
|
121
|
+
};
|
|
122
|
+
}, [startMultiSelect, stopMultiSelect, isSelectionEnabled, hasMultiSelection]);
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=use-drag-selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-drag-selection.js"],"names":["useSelect","useDispatch","useRefEffect","store","blockEditorStore","setContentEditableWrapper","node","value","contentEditable","focus","useDragSelection","startMultiSelect","stopMultiSelect","isSelectionEnabled","hasMultiSelection","ownerDocument","defaultView","anchorElement","rafId","onMouseUp","removeEventListener","requestAnimationFrame","selection","getSelection","rangeCount","commonAncestorContainer","getRangeAt","contains","onMouseLeave","buttons","target","getAttribute","activeElement","addEventListener","cancelAnimationFrame"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,yBAAT,CAAoCC,IAApC,EAA0CC,KAA1C,EAAkD;AACjDD,EAAAA,IAAI,CAACE,eAAL,GAAuBD,KAAvB,CADiD,CAEjD;;AACA,MAAKA,KAAL,EAAaD,IAAI,CAACG,KAAL;AACb;AAED;AACA;AACA;;;AACA,eAAe,SAASC,gBAAT,GAA4B;AAC1C,QAAM;AAAEC,IAAAA,gBAAF;AAAoBC,IAAAA;AAApB,MAAwCX,WAAW,CACxDG,gBADwD,CAAzD;AAGA,QAAM;AAAES,IAAAA,kBAAF;AAAsBC,IAAAA;AAAtB,MAA4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B,GApB4B,CAsB5C;AACA;AACA;;AACAK,MAAAA,WAAW,CAACiB,gBAAZ,CAA8B,SAA9B,EAAyCd,SAAzC,EAzB4C,CA2B5C;AACA;AACA;AACA;;AACAd,MAAAA,yBAAyB,CAAEC,IAAF,EAAQ,IAAR,CAAzB;AACA;;AAEDA,IAAAA,IAAI,CAAC2B,gBAAL,CAAuB,UAAvB,EAAmCL,YAAnC;AAEA,WAAO,MAAM;AACZtB,MAAAA,IAAI,CAACc,mBAAL,CAA0B,UAA1B,EAAsCQ,YAAtC;AACAZ,MAAAA,WAAW,CAACI,mBAAZ,CAAiC,SAAjC,EAA4CD,SAA5C;AACAH,MAAAA,WAAW,CAACkB,oBAAZ,CAAkChB,KAAlC;AACA,KAJD;AAKA,GApFiB,EAqFlB,CACCP,gBADD,EAECC,eAFD,EAGCC,kBAHD,EAICC,iBAJD,CArFkB,CAAnB;AA4FA","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';\n\n/**\n * Sets the `contenteditable` wrapper element to `value`.\n *\n * @param {HTMLElement} node Block element.\n * @param {boolean} value `contentEditable` value (true or false)\n */\nfunction setContentEditableWrapper( node, value ) {\n\tnode.contentEditable = value;\n\t// Firefox doesn't automatically move focus.\n\tif ( value ) node.focus();\n}\n\n/**\n * Sets a multi-selection based on the native selection across blocks.\n */\nexport default function useDragSelection() {\n\tconst { startMultiSelect, stopMultiSelect } = useDispatch(\n\t\tblockEditorStore\n\t);\n\tconst { isSelectionEnabled, hasMultiSelection } = useSelect(\n\t\tblockEditorStore\n\t);\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tlet anchorElement;\n\t\t\tlet rafId;\n\n\t\t\tfunction onMouseUp() {\n\t\t\t\tstopMultiSelect();\n\t\t\t\t// Equivalent to attaching the listener once.\n\t\t\t\tdefaultView.removeEventListener( 'mouseup', onMouseUp );\n\t\t\t\t// The browser selection won't have updated yet at this point,\n\t\t\t\t// so wait until the next animation frame to get the browser\n\t\t\t\t// selection.\n\t\t\t\trafId = defaultView.requestAnimationFrame( () => {\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\t// If the selection is complete (on mouse up), and no\n\t\t\t\t\t// multiple blocks have been selected, set focus back to the\n\t\t\t\t\t// anchor element. if the anchor element contains the\n\t\t\t\t\t// selection. Additionally, the contentEditable wrapper can\n\t\t\t\t\t// now be disabled again.\n\t\t\t\t\tsetContentEditableWrapper( node, false );\n\n\t\t\t\t\tconst selection = defaultView.getSelection();\n\n\t\t\t\t\tif ( selection.rangeCount ) {\n\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\tcommonAncestorContainer,\n\t\t\t\t\t\t} = selection.getRangeAt( 0 );\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tanchorElement.contains( commonAncestorContainer )\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tanchorElement.focus();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tfunction onMouseLeave( { buttons, target } ) {\n\t\t\t\t// The primary button must be pressed to initiate selection.\n\t\t\t\t// See https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\n\t\t\t\tif ( buttons !== 1 ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Check the attribute, not the contentEditable attribute. All\n\t\t\t\t// child elements of the content editable wrapper are editable\n\t\t\t\t// and return true for this property. We only want to start\n\t\t\t\t// multi selecting when the mouse leaves the wrapper.\n\t\t\t\tif ( ! target.getAttribute( 'contenteditable' ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( ! isSelectionEnabled() ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tanchorElement = ownerDocument.activeElement;\n\t\t\t\tstartMultiSelect();\n\n\t\t\t\t// `onSelectionStart` is called after `mousedown` and\n\t\t\t\t// `mouseleave` (from a block). The selection ends when\n\t\t\t\t// `mouseup` happens anywhere in the window.\n\t\t\t\tdefaultView.addEventListener( 'mouseup', onMouseUp );\n\n\t\t\t\t// Allow cross contentEditable selection by temporarily making\n\t\t\t\t// all content editable. We can't rely on using the store and\n\t\t\t\t// React because re-rending happens too slowly. We need to be\n\t\t\t\t// able to select across instances immediately.\n\t\t\t\tsetContentEditableWrapper( node, true );\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'mouseout', onMouseLeave );\n\n\t\t\treturn () => {\n\t\t\t\tnode.removeEventListener( 'mouseout', onMouseLeave );\n\t\t\t\tdefaultView.removeEventListener( 'mouseup', onMouseUp );\n\t\t\t\tdefaultView.cancelAnimationFrame( rafId );\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tstartMultiSelect,\n\t\t\tstopMultiSelect,\n\t\t\tisSelectionEnabled,\n\t\t\thasMultiSelection,\n\t\t]\n\t);\n}\n"]}
|