@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
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
isRTL,
|
|
17
17
|
} from '@wordpress/dom';
|
|
18
18
|
import { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';
|
|
19
|
-
import { useSelect
|
|
19
|
+
import { useSelect } from '@wordpress/data';
|
|
20
20
|
import { useRefEffect } from '@wordpress/compose';
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -120,16 +120,12 @@ export function getClosestTabbable(
|
|
|
120
120
|
export default function useArrowNav() {
|
|
121
121
|
const {
|
|
122
122
|
getSelectedBlockClientId,
|
|
123
|
-
getMultiSelectedBlocksStartClientId,
|
|
124
123
|
getMultiSelectedBlocksEndClientId,
|
|
125
124
|
getPreviousBlockClientId,
|
|
126
125
|
getNextBlockClientId,
|
|
127
|
-
getFirstMultiSelectedBlockClientId,
|
|
128
|
-
getLastMultiSelectedBlockClientId,
|
|
129
126
|
getSettings,
|
|
130
127
|
hasMultiSelection,
|
|
131
128
|
} = useSelect( blockEditorStore );
|
|
132
|
-
const { multiSelect, selectBlock } = useDispatch( blockEditorStore );
|
|
133
129
|
return useRefEffect( ( node ) => {
|
|
134
130
|
// Here a DOMRect is stored while moving the caret vertically so
|
|
135
131
|
// vertical position of the start position can be restored. This is to
|
|
@@ -140,44 +136,6 @@ export default function useArrowNav() {
|
|
|
140
136
|
verticalRect = null;
|
|
141
137
|
}
|
|
142
138
|
|
|
143
|
-
function expandSelection( isReverse ) {
|
|
144
|
-
const selectedBlockClientId = getSelectedBlockClientId();
|
|
145
|
-
const selectionStartClientId = getMultiSelectedBlocksStartClientId();
|
|
146
|
-
const selectionEndClientId = getMultiSelectedBlocksEndClientId();
|
|
147
|
-
const selectionBeforeEndClientId = getPreviousBlockClientId(
|
|
148
|
-
selectionEndClientId || selectedBlockClientId
|
|
149
|
-
);
|
|
150
|
-
const selectionAfterEndClientId = getNextBlockClientId(
|
|
151
|
-
selectionEndClientId || selectedBlockClientId
|
|
152
|
-
);
|
|
153
|
-
const nextSelectionEndClientId = isReverse
|
|
154
|
-
? selectionBeforeEndClientId
|
|
155
|
-
: selectionAfterEndClientId;
|
|
156
|
-
|
|
157
|
-
if ( nextSelectionEndClientId ) {
|
|
158
|
-
if ( selectionStartClientId === nextSelectionEndClientId ) {
|
|
159
|
-
selectBlock( nextSelectionEndClientId );
|
|
160
|
-
} else {
|
|
161
|
-
multiSelect(
|
|
162
|
-
selectionStartClientId || selectedBlockClientId,
|
|
163
|
-
nextSelectionEndClientId
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function moveSelection( isReverse ) {
|
|
170
|
-
const selectedFirstClientId = getFirstMultiSelectedBlockClientId();
|
|
171
|
-
const selectedLastClientId = getLastMultiSelectedBlockClientId();
|
|
172
|
-
const focusedBlockClientId = isReverse
|
|
173
|
-
? selectedFirstClientId
|
|
174
|
-
: selectedLastClientId;
|
|
175
|
-
|
|
176
|
-
if ( focusedBlockClientId ) {
|
|
177
|
-
selectBlock( focusedBlockClientId );
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
139
|
/**
|
|
182
140
|
* Returns true if the given target field is the last in its block which
|
|
183
141
|
* can be considered for tab transition. For example, in a block with
|
|
@@ -218,12 +176,6 @@ export default function useArrowNav() {
|
|
|
218
176
|
const { defaultView } = ownerDocument;
|
|
219
177
|
|
|
220
178
|
if ( hasMultiSelection() ) {
|
|
221
|
-
if ( isNav ) {
|
|
222
|
-
const action = isShift ? expandSelection : moveSelection;
|
|
223
|
-
action( isReverse );
|
|
224
|
-
event.preventDefault();
|
|
225
|
-
}
|
|
226
|
-
|
|
227
179
|
return;
|
|
228
180
|
}
|
|
229
181
|
|
|
@@ -278,10 +230,9 @@ export default function useArrowNav() {
|
|
|
278
230
|
isTabbableEdge( target, isReverse ) &&
|
|
279
231
|
isNavEdge( target, isReverse )
|
|
280
232
|
) {
|
|
281
|
-
|
|
282
|
-
//
|
|
283
|
-
|
|
284
|
-
event.preventDefault();
|
|
233
|
+
node.contentEditable = true;
|
|
234
|
+
// Firefox doesn't automatically move focus.
|
|
235
|
+
node.focus();
|
|
285
236
|
}
|
|
286
237
|
} else if (
|
|
287
238
|
isVertical &&
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
+
import { useRefEffect } from '@wordpress/compose';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { store as blockEditorStore } from '../../store';
|
|
11
|
+
import { getBlockClientId } from '../../utils/dom';
|
|
12
|
+
|
|
13
|
+
export default function useClickSelection() {
|
|
14
|
+
const { multiSelect, selectBlock } = useDispatch( blockEditorStore );
|
|
15
|
+
const {
|
|
16
|
+
isSelectionEnabled,
|
|
17
|
+
getBlockParents,
|
|
18
|
+
getBlockSelectionStart,
|
|
19
|
+
hasMultiSelection,
|
|
20
|
+
} = useSelect( blockEditorStore );
|
|
21
|
+
return useRefEffect(
|
|
22
|
+
( node ) => {
|
|
23
|
+
function onMouseDown( event ) {
|
|
24
|
+
// The main button.
|
|
25
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
|
|
26
|
+
if ( ! isSelectionEnabled() || event.button !== 0 ) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const startClientId = getBlockSelectionStart();
|
|
31
|
+
const clickedClientId = getBlockClientId( event.target );
|
|
32
|
+
|
|
33
|
+
if ( event.shiftKey ) {
|
|
34
|
+
if ( startClientId !== clickedClientId ) {
|
|
35
|
+
node.contentEditable = true;
|
|
36
|
+
// Firefox doesn't automatically move focus.
|
|
37
|
+
node.focus();
|
|
38
|
+
}
|
|
39
|
+
} else if ( hasMultiSelection() ) {
|
|
40
|
+
// Allow user to escape out of a multi-selection to a
|
|
41
|
+
// singular selection of a block via click. This is handled
|
|
42
|
+
// here since focus handling excludes blocks when there is
|
|
43
|
+
// multiselection, as focus can be incurred by starting a
|
|
44
|
+
// multiselection (focus moved to first block's multi-
|
|
45
|
+
// controls).
|
|
46
|
+
selectBlock( clickedClientId );
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
node.addEventListener( 'mousedown', onMouseDown );
|
|
51
|
+
|
|
52
|
+
return () => {
|
|
53
|
+
node.removeEventListener( 'mousedown', onMouseDown );
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
[
|
|
57
|
+
multiSelect,
|
|
58
|
+
selectBlock,
|
|
59
|
+
isSelectionEnabled,
|
|
60
|
+
getBlockParents,
|
|
61
|
+
getBlockSelectionStart,
|
|
62
|
+
hasMultiSelection,
|
|
63
|
+
]
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
+
import { useRefEffect } from '@wordpress/compose';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { store as blockEditorStore } from '../../store';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Sets the `contenteditable` wrapper element to `value`.
|
|
14
|
+
*
|
|
15
|
+
* @param {HTMLElement} node Block element.
|
|
16
|
+
* @param {boolean} value `contentEditable` value (true or false)
|
|
17
|
+
*/
|
|
18
|
+
function setContentEditableWrapper( node, value ) {
|
|
19
|
+
node.contentEditable = value;
|
|
20
|
+
// Firefox doesn't automatically move focus.
|
|
21
|
+
if ( value ) node.focus();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Sets a multi-selection based on the native selection across blocks.
|
|
26
|
+
*/
|
|
27
|
+
export default function useDragSelection() {
|
|
28
|
+
const { startMultiSelect, stopMultiSelect } = useDispatch(
|
|
29
|
+
blockEditorStore
|
|
30
|
+
);
|
|
31
|
+
const { isSelectionEnabled, hasMultiSelection } = useSelect(
|
|
32
|
+
blockEditorStore
|
|
33
|
+
);
|
|
34
|
+
return useRefEffect(
|
|
35
|
+
( node ) => {
|
|
36
|
+
const { ownerDocument } = node;
|
|
37
|
+
const { defaultView } = ownerDocument;
|
|
38
|
+
|
|
39
|
+
let anchorElement;
|
|
40
|
+
let rafId;
|
|
41
|
+
|
|
42
|
+
function onMouseUp() {
|
|
43
|
+
stopMultiSelect();
|
|
44
|
+
// Equivalent to attaching the listener once.
|
|
45
|
+
defaultView.removeEventListener( 'mouseup', onMouseUp );
|
|
46
|
+
// The browser selection won't have updated yet at this point,
|
|
47
|
+
// so wait until the next animation frame to get the browser
|
|
48
|
+
// selection.
|
|
49
|
+
rafId = defaultView.requestAnimationFrame( () => {
|
|
50
|
+
if ( hasMultiSelection() ) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// If the selection is complete (on mouse up), and no
|
|
55
|
+
// multiple blocks have been selected, set focus back to the
|
|
56
|
+
// anchor element. if the anchor element contains the
|
|
57
|
+
// selection. Additionally, the contentEditable wrapper can
|
|
58
|
+
// now be disabled again.
|
|
59
|
+
setContentEditableWrapper( node, false );
|
|
60
|
+
|
|
61
|
+
const selection = defaultView.getSelection();
|
|
62
|
+
|
|
63
|
+
if ( selection.rangeCount ) {
|
|
64
|
+
const {
|
|
65
|
+
commonAncestorContainer,
|
|
66
|
+
} = selection.getRangeAt( 0 );
|
|
67
|
+
|
|
68
|
+
if (
|
|
69
|
+
anchorElement.contains( commonAncestorContainer )
|
|
70
|
+
) {
|
|
71
|
+
anchorElement.focus();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} );
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function onMouseLeave( { buttons, target } ) {
|
|
78
|
+
// The primary button must be pressed to initiate selection.
|
|
79
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
|
|
80
|
+
if ( buttons !== 1 ) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Check the attribute, not the contentEditable attribute. All
|
|
85
|
+
// child elements of the content editable wrapper are editable
|
|
86
|
+
// and return true for this property. We only want to start
|
|
87
|
+
// multi selecting when the mouse leaves the wrapper.
|
|
88
|
+
if ( ! target.getAttribute( 'contenteditable' ) ) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if ( ! isSelectionEnabled() ) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
anchorElement = ownerDocument.activeElement;
|
|
97
|
+
startMultiSelect();
|
|
98
|
+
|
|
99
|
+
// `onSelectionStart` is called after `mousedown` and
|
|
100
|
+
// `mouseleave` (from a block). The selection ends when
|
|
101
|
+
// `mouseup` happens anywhere in the window.
|
|
102
|
+
defaultView.addEventListener( 'mouseup', onMouseUp );
|
|
103
|
+
|
|
104
|
+
// Allow cross contentEditable selection by temporarily making
|
|
105
|
+
// all content editable. We can't rely on using the store and
|
|
106
|
+
// React because re-rending happens too slowly. We need to be
|
|
107
|
+
// able to select across instances immediately.
|
|
108
|
+
setContentEditableWrapper( node, true );
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
node.addEventListener( 'mouseout', onMouseLeave );
|
|
112
|
+
|
|
113
|
+
return () => {
|
|
114
|
+
node.removeEventListener( 'mouseout', onMouseLeave );
|
|
115
|
+
defaultView.removeEventListener( 'mouseup', onMouseUp );
|
|
116
|
+
defaultView.cancelAnimationFrame( rafId );
|
|
117
|
+
};
|
|
118
|
+
},
|
|
119
|
+
[
|
|
120
|
+
startMultiSelect,
|
|
121
|
+
stopMultiSelect,
|
|
122
|
+
isSelectionEnabled,
|
|
123
|
+
hasMultiSelection,
|
|
124
|
+
]
|
|
125
|
+
);
|
|
126
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
+
import { useRefEffect } from '@wordpress/compose';
|
|
6
|
+
import { ENTER, BACKSPACE, DELETE } from '@wordpress/keycodes';
|
|
7
|
+
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
import { store as blockEditorStore } from '../../store';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Handles input for selections across blocks.
|
|
16
|
+
*/
|
|
17
|
+
export default function useInput() {
|
|
18
|
+
const {
|
|
19
|
+
__unstableIsFullySelected,
|
|
20
|
+
getSelectedBlockClientIds,
|
|
21
|
+
__unstableIsSelectionMergeable,
|
|
22
|
+
hasMultiSelection,
|
|
23
|
+
} = useSelect( blockEditorStore );
|
|
24
|
+
const {
|
|
25
|
+
replaceBlocks,
|
|
26
|
+
__unstableSplitSelection,
|
|
27
|
+
removeBlocks,
|
|
28
|
+
__unstableDeleteSelection,
|
|
29
|
+
__unstableExpandSelection,
|
|
30
|
+
} = useDispatch( blockEditorStore );
|
|
31
|
+
|
|
32
|
+
return useRefEffect( ( node ) => {
|
|
33
|
+
function onKeyDown( event ) {
|
|
34
|
+
if ( event.defaultPrevented ) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if ( ! hasMultiSelection() ) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if ( event.keyCode === ENTER ) {
|
|
43
|
+
node.contentEditable = false;
|
|
44
|
+
event.preventDefault();
|
|
45
|
+
if ( __unstableIsFullySelected() ) {
|
|
46
|
+
replaceBlocks(
|
|
47
|
+
getSelectedBlockClientIds(),
|
|
48
|
+
createBlock( getDefaultBlockName() )
|
|
49
|
+
);
|
|
50
|
+
} else {
|
|
51
|
+
__unstableSplitSelection();
|
|
52
|
+
}
|
|
53
|
+
} else if (
|
|
54
|
+
event.keyCode === BACKSPACE ||
|
|
55
|
+
event.keyCode === DELETE
|
|
56
|
+
) {
|
|
57
|
+
node.contentEditable = false;
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
if ( __unstableIsFullySelected() ) {
|
|
60
|
+
removeBlocks( getSelectedBlockClientIds() );
|
|
61
|
+
} else if ( __unstableIsSelectionMergeable() ) {
|
|
62
|
+
__unstableDeleteSelection( event.keyCode === DELETE );
|
|
63
|
+
} else {
|
|
64
|
+
__unstableExpandSelection();
|
|
65
|
+
}
|
|
66
|
+
} else if (
|
|
67
|
+
// If key.length is longer than 1, it's a control key that doesn't
|
|
68
|
+
// input anything.
|
|
69
|
+
event.key.length === 1 &&
|
|
70
|
+
! ( event.metaKey || event.ctrlKey )
|
|
71
|
+
) {
|
|
72
|
+
node.contentEditable = false;
|
|
73
|
+
if ( __unstableIsSelectionMergeable() ) {
|
|
74
|
+
__unstableDeleteSelection( event.keyCode === DELETE );
|
|
75
|
+
} else {
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
// Safari does not stop default behaviour with either
|
|
78
|
+
// event.preventDefault() or node.contentEditable = false, so
|
|
79
|
+
// remove the selection to stop browser manipulation.
|
|
80
|
+
node.ownerDocument.defaultView
|
|
81
|
+
.getSelection()
|
|
82
|
+
.removeAllRanges();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function onCompositionStart( event ) {
|
|
88
|
+
if ( ! hasMultiSelection() ) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
node.contentEditable = false;
|
|
93
|
+
|
|
94
|
+
if ( __unstableIsSelectionMergeable() ) {
|
|
95
|
+
__unstableDeleteSelection();
|
|
96
|
+
} else {
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
// Safari does not stop default behaviour with either
|
|
99
|
+
// event.preventDefault() or node.contentEditable = false, so
|
|
100
|
+
// remove the selection to stop browser manipulation.
|
|
101
|
+
node.ownerDocument.defaultView.getSelection().removeAllRanges();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
node.addEventListener( 'keydown', onKeyDown );
|
|
106
|
+
node.addEventListener( 'compositionstart', onCompositionStart );
|
|
107
|
+
return () => {
|
|
108
|
+
node.removeEventListener( 'keydown', onKeyDown );
|
|
109
|
+
node.removeEventListener( 'compositionstart', onCompositionStart );
|
|
110
|
+
};
|
|
111
|
+
}, [] );
|
|
112
|
+
}
|
|
@@ -15,32 +15,6 @@ import { useSelect } from '@wordpress/data';
|
|
|
15
15
|
import { store as blockEditorStore } from '../../store';
|
|
16
16
|
import { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* Returns for the deepest node at the start or end of a container node. Ignores
|
|
20
|
-
* any text nodes that only contain HTML formatting whitespace.
|
|
21
|
-
*
|
|
22
|
-
* @param {Element} node Container to search.
|
|
23
|
-
* @param {string} type 'start' or 'end'.
|
|
24
|
-
*/
|
|
25
|
-
function getDeepestNode( node, type ) {
|
|
26
|
-
const child = type === 'start' ? 'firstChild' : 'lastChild';
|
|
27
|
-
const sibling = type === 'start' ? 'nextSibling' : 'previousSibling';
|
|
28
|
-
|
|
29
|
-
while ( node[ child ] ) {
|
|
30
|
-
node = node[ child ];
|
|
31
|
-
|
|
32
|
-
while (
|
|
33
|
-
node.nodeType === node.TEXT_NODE &&
|
|
34
|
-
/^[ \t\n]*$/.test( node.data ) &&
|
|
35
|
-
node[ sibling ]
|
|
36
|
-
) {
|
|
37
|
-
node = node[ sibling ];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return node;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
18
|
function selector( select ) {
|
|
45
19
|
const {
|
|
46
20
|
isMultiSelecting,
|
|
@@ -48,6 +22,7 @@ function selector( select ) {
|
|
|
48
22
|
hasMultiSelection,
|
|
49
23
|
getSelectedBlockClientId,
|
|
50
24
|
getSelectedBlocksInitialCaretPosition,
|
|
25
|
+
__unstableIsFullySelected,
|
|
51
26
|
} = select( blockEditorStore );
|
|
52
27
|
|
|
53
28
|
return {
|
|
@@ -56,6 +31,7 @@ function selector( select ) {
|
|
|
56
31
|
hasMultiSelection: hasMultiSelection(),
|
|
57
32
|
selectedBlockClientId: getSelectedBlockClientId(),
|
|
58
33
|
initialPosition: getSelectedBlocksInitialCaretPosition(),
|
|
34
|
+
isFullSelection: __unstableIsFullySelected(),
|
|
59
35
|
};
|
|
60
36
|
}
|
|
61
37
|
|
|
@@ -66,6 +42,7 @@ export default function useMultiSelection() {
|
|
|
66
42
|
multiSelectedBlockClientIds,
|
|
67
43
|
hasMultiSelection,
|
|
68
44
|
selectedBlockClientId,
|
|
45
|
+
isFullSelection,
|
|
69
46
|
} = useSelect( selector, [] );
|
|
70
47
|
const selectedRef = useBlockRef( selectedBlockClientId );
|
|
71
48
|
// These must be in the right DOM order.
|
|
@@ -120,9 +97,7 @@ export default function useMultiSelection() {
|
|
|
120
97
|
return;
|
|
121
98
|
}
|
|
122
99
|
|
|
123
|
-
|
|
124
|
-
// when dragging blocks into another block.
|
|
125
|
-
if ( ! startRef.current || ! endRef.current ) {
|
|
100
|
+
if ( ! isFullSelection ) {
|
|
126
101
|
return;
|
|
127
102
|
}
|
|
128
103
|
|
|
@@ -136,17 +111,18 @@ export default function useMultiSelection() {
|
|
|
136
111
|
// BEFORE selection.
|
|
137
112
|
node.focus();
|
|
138
113
|
|
|
114
|
+
// The block refs might not be immediately available
|
|
115
|
+
// when dragging blocks into another block.
|
|
116
|
+
if ( ! startRef.current || ! endRef.current ) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
139
120
|
const selection = defaultView.getSelection();
|
|
140
121
|
const range = ownerDocument.createRange();
|
|
141
122
|
|
|
142
123
|
// These must be in the right DOM order.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const startNode = getDeepestNode( startRef.current, 'start' );
|
|
146
|
-
const endNode = getDeepestNode( endRef.current, 'end' );
|
|
147
|
-
|
|
148
|
-
range.setStartBefore( startNode );
|
|
149
|
-
range.setEndAfter( endNode );
|
|
124
|
+
range.setStartBefore( startRef.current );
|
|
125
|
+
range.setEndAfter( endRef.current );
|
|
150
126
|
|
|
151
127
|
selection.removeAllRanges();
|
|
152
128
|
selection.addRange( range );
|
|
@@ -157,6 +133,7 @@ export default function useMultiSelection() {
|
|
|
157
133
|
multiSelectedBlockClientIds,
|
|
158
134
|
selectedBlockClientId,
|
|
159
135
|
initialPosition,
|
|
136
|
+
isFullSelection,
|
|
160
137
|
]
|
|
161
138
|
);
|
|
162
139
|
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
+
import { useRefEffect } from '@wordpress/compose';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { store as blockEditorStore } from '../../store';
|
|
11
|
+
import { getBlockClientId } from '../../utils/dom';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Extract the selection start node from the selection. When the anchor node is
|
|
15
|
+
* not a text node, the selection offset is the index of a child node.
|
|
16
|
+
*
|
|
17
|
+
* @param {Selection} selection The selection.
|
|
18
|
+
*
|
|
19
|
+
* @return {Element} The selection start node.
|
|
20
|
+
*/
|
|
21
|
+
function extractSelectionStartNode( selection ) {
|
|
22
|
+
const { anchorNode, anchorOffset } = selection;
|
|
23
|
+
|
|
24
|
+
if ( anchorNode.nodeType === anchorNode.TEXT_NODE ) {
|
|
25
|
+
return anchorNode;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return anchorNode.childNodes[ anchorOffset ];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Extract the selection end node from the selection. When the focus node is not
|
|
33
|
+
* a text node, the selection offset is the index of a child node. The selection
|
|
34
|
+
* reaches up to but excluding that child node.
|
|
35
|
+
*
|
|
36
|
+
* @param {Selection} selection The selection.
|
|
37
|
+
*
|
|
38
|
+
* @return {Element} The selection start node.
|
|
39
|
+
*/
|
|
40
|
+
function extractSelectionEndNode( selection ) {
|
|
41
|
+
const { focusNode, focusOffset } = selection;
|
|
42
|
+
|
|
43
|
+
if ( focusNode.nodeType === focusNode.TEXT_NODE ) {
|
|
44
|
+
return focusNode;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return focusNode.childNodes[ focusOffset - 1 ];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function findDepth( a, b ) {
|
|
51
|
+
let depth = 0;
|
|
52
|
+
|
|
53
|
+
while ( a[ depth ] === b[ depth ] ) {
|
|
54
|
+
depth++;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return depth;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Sets the `contenteditable` wrapper element to `value`.
|
|
62
|
+
*
|
|
63
|
+
* @param {HTMLElement} node Block element.
|
|
64
|
+
* @param {boolean} value `contentEditable` value (true or false)
|
|
65
|
+
*/
|
|
66
|
+
function setContentEditableWrapper( node, value ) {
|
|
67
|
+
node.contentEditable = value;
|
|
68
|
+
// Firefox doesn't automatically move focus.
|
|
69
|
+
if ( value ) node.focus();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Sets a multi-selection based on the native selection across blocks.
|
|
74
|
+
*/
|
|
75
|
+
export default function useSelectionObserver() {
|
|
76
|
+
const { multiSelect, selectBlock, selectionChange } = useDispatch(
|
|
77
|
+
blockEditorStore
|
|
78
|
+
);
|
|
79
|
+
const { getBlockParents } = useSelect( blockEditorStore );
|
|
80
|
+
return useRefEffect(
|
|
81
|
+
( node ) => {
|
|
82
|
+
const { ownerDocument } = node;
|
|
83
|
+
const { defaultView } = ownerDocument;
|
|
84
|
+
|
|
85
|
+
function onSelectionChange() {
|
|
86
|
+
const selection = defaultView.getSelection();
|
|
87
|
+
|
|
88
|
+
// If no selection is found, end multi selection and disable the
|
|
89
|
+
// contentEditable wrapper.
|
|
90
|
+
if ( ! selection.rangeCount || selection.isCollapsed ) {
|
|
91
|
+
setContentEditableWrapper( node, false );
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const clientId = getBlockClientId(
|
|
96
|
+
extractSelectionStartNode( selection )
|
|
97
|
+
);
|
|
98
|
+
const endClientId = getBlockClientId(
|
|
99
|
+
extractSelectionEndNode( selection )
|
|
100
|
+
);
|
|
101
|
+
const isSingularSelection = clientId === endClientId;
|
|
102
|
+
|
|
103
|
+
if ( isSingularSelection ) {
|
|
104
|
+
selectBlock( clientId );
|
|
105
|
+
} else {
|
|
106
|
+
const startPath = [
|
|
107
|
+
...getBlockParents( clientId ),
|
|
108
|
+
clientId,
|
|
109
|
+
];
|
|
110
|
+
const endPath = [
|
|
111
|
+
...getBlockParents( endClientId ),
|
|
112
|
+
endClientId,
|
|
113
|
+
];
|
|
114
|
+
const depth = findDepth( startPath, endPath );
|
|
115
|
+
|
|
116
|
+
multiSelect( startPath[ depth ], endPath[ depth ] );
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function addListeners() {
|
|
121
|
+
ownerDocument.addEventListener(
|
|
122
|
+
'selectionchange',
|
|
123
|
+
onSelectionChange
|
|
124
|
+
);
|
|
125
|
+
defaultView.addEventListener( 'mouseup', onSelectionChange );
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function removeListeners() {
|
|
129
|
+
ownerDocument.removeEventListener(
|
|
130
|
+
'selectionchange',
|
|
131
|
+
onSelectionChange
|
|
132
|
+
);
|
|
133
|
+
defaultView.removeEventListener( 'mouseup', onSelectionChange );
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function resetListeners() {
|
|
137
|
+
removeListeners();
|
|
138
|
+
addListeners();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
addListeners();
|
|
142
|
+
// We must allow rich text to set selection first. This ensures that
|
|
143
|
+
// our `selectionchange` listener is always reset to be called after
|
|
144
|
+
// the rich text one.
|
|
145
|
+
node.addEventListener( 'focusin', resetListeners );
|
|
146
|
+
return () => {
|
|
147
|
+
removeListeners();
|
|
148
|
+
node.removeEventListener( 'focusin', resetListeners );
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
[ multiSelect, selectBlock, selectionChange, getBlockParents ]
|
|
152
|
+
);
|
|
153
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { focus } from '@wordpress/dom';
|
|
4
|
+
import { focus, isFormElement } from '@wordpress/dom';
|
|
5
5
|
import { TAB, ESCAPE } from '@wordpress/keycodes';
|
|
6
6
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
7
7
|
import { useRefEffect, useMergeRefs } from '@wordpress/compose';
|
|
@@ -12,16 +12,6 @@ import { useRef } from '@wordpress/element';
|
|
|
12
12
|
*/
|
|
13
13
|
import { store as blockEditorStore } from '../../store';
|
|
14
14
|
|
|
15
|
-
function isFormElement( element ) {
|
|
16
|
-
const { tagName } = element;
|
|
17
|
-
return (
|
|
18
|
-
tagName === 'INPUT' ||
|
|
19
|
-
tagName === 'BUTTON' ||
|
|
20
|
-
tagName === 'SELECT' ||
|
|
21
|
-
tagName === 'TEXTAREA'
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
15
|
export default function useTabNav() {
|
|
26
16
|
const container = useRef();
|
|
27
17
|
const focusCaptureBeforeRef = useRef();
|