@wordpress/block-editor 8.4.0 → 8.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +56 -19
- package/build/components/alignment-control/index.js +13 -6
- package/build/components/alignment-control/index.js.map +1 -1
- package/build/components/block-alignment-control/index.js +13 -6
- package/build/components/block-alignment-control/index.js.map +1 -1
- package/build/components/block-draggable/index.js +2 -3
- package/build/components/block-draggable/index.js.map +1 -1
- package/build/components/block-icon/index.js +4 -0
- package/build/components/block-icon/index.js.map +1 -1
- package/build/components/block-inspector/index.js +6 -1
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +1 -6
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-block-props/use-focus-first-element.js +14 -17
- package/build/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
- package/build/components/block-list/use-block-props/use-focus-handler.js +7 -1
- package/build/components/block-list/use-block-props/use-focus-handler.js.map +1 -1
- package/build/components/block-list-appender/index.js +6 -1
- package/build/components/block-list-appender/index.js.map +1 -1
- package/build/components/block-lock/menu-item.js +9 -0
- package/build/components/block-lock/menu-item.js.map +1 -1
- package/build/components/block-lock/modal.js +4 -13
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-lock/toolbar.js +11 -3
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-mover/index.js +4 -0
- package/build/components/block-mover/index.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +50 -5
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-switcher/index.js +1 -1
- package/build/components/block-switcher/index.js.map +1 -1
- package/build/components/block-title/index.js +2 -2
- package/build/components/block-title/index.js.map +1 -1
- package/build/components/block-title/use-block-display-title.js +1 -1
- package/build/components/block-title/use-block-display-title.js.map +1 -1
- package/build/components/block-toolbar/block-name-context.js +17 -0
- package/build/components/block-toolbar/block-name-context.js.map +1 -0
- package/build/components/block-toolbar/block-toolbar-last-item.js +20 -0
- package/build/components/block-toolbar/block-toolbar-last-item.js.map +1 -0
- package/build/components/block-toolbar/index.js +20 -5
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-tools/index.js +0 -16
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/block-variation-transforms/index.js +92 -47
- package/build/components/block-variation-transforms/index.js.map +1 -1
- package/build/components/block-vertical-alignment-control/index.js +13 -6
- package/build/components/block-vertical-alignment-control/index.js.map +1 -1
- package/build/components/contrast-checker/index.js +4 -0
- package/build/components/contrast-checker/index.js.map +1 -1
- package/build/components/convert-to-group-buttons/index.js +8 -0
- package/build/components/convert-to-group-buttons/index.js.map +1 -1
- package/build/components/convert-to-group-buttons/toolbar.js +105 -0
- package/build/components/convert-to-group-buttons/toolbar.js.map +1 -0
- package/build/components/copy-handler/index.js +4 -0
- package/build/components/copy-handler/index.js.map +1 -1
- package/build/components/font-sizes/font-size-picker.js +4 -0
- package/build/components/font-sizes/font-size-picker.js.map +1 -1
- package/build/components/iframe/index.js +6 -9
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/index.js +18 -0
- package/build/components/index.js.map +1 -1
- package/build/components/justify-content-control/index.js +13 -6
- package/build/components/justify-content-control/index.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js +1 -1
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/line-height-control/index.js +10 -3
- package/build/components/line-height-control/index.js.map +1 -1
- package/build/components/list-view/block-select-button.js +25 -6
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/block.js +5 -1
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +1 -1
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/media-replace-flow/index.js +4 -0
- package/build/components/media-replace-flow/index.js.map +1 -1
- package/build/components/multi-selection-inspector/index.js +1 -1
- package/build/components/multi-selection-inspector/index.js.map +1 -1
- package/build/components/rich-text/index.js +26 -4
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/split-value.js +12 -2
- package/build/components/rich-text/split-value.js.map +1 -1
- package/build/components/rich-text/use-firefox-compat.js +49 -0
- package/build/components/rich-text/use-firefox-compat.js.map +1 -0
- package/build/components/rich-text/use-input-rules.js +34 -2
- package/build/components/rich-text/use-input-rules.js.map +1 -1
- package/build/components/skip-to-selected-block/index.js +4 -0
- package/build/components/skip-to-selected-block/index.js.map +1 -1
- package/build/components/writing-flow/index.js +9 -1
- package/build/components/writing-flow/index.js.map +1 -1
- package/build/components/writing-flow/use-arrow-nav.js +3 -44
- package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build/components/writing-flow/use-click-selection.js +68 -0
- package/build/components/writing-flow/use-click-selection.js.map +1 -0
- package/build/components/writing-flow/use-drag-selection.js +134 -0
- package/build/components/writing-flow/use-drag-selection.js.map +1 -0
- package/build/components/writing-flow/use-input.js +116 -0
- package/build/components/writing-flow/use-input.js.map +1 -0
- package/build/components/writing-flow/use-multi-selection.js +18 -38
- package/build/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build/components/writing-flow/use-selection-observer.js +161 -0
- package/build/components/writing-flow/use-selection-observer.js.map +1 -0
- package/build/components/writing-flow/use-tab-nav.js +1 -8
- package/build/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build/hooks/border-color.js +3 -3
- package/build/hooks/border-color.js.map +1 -1
- package/build/hooks/border.js +0 -14
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/color.js +20 -17
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/font-family.js +5 -1
- package/build/hooks/font-family.js.map +1 -1
- package/build/hooks/font-size.js +4 -2
- package/build/hooks/font-size.js.map +1 -1
- package/build/hooks/gap.js +23 -16
- package/build/hooks/gap.js.map +1 -1
- package/build/hooks/layout.js +7 -2
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/style.js +34 -3
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/utils.js +29 -0
- package/build/hooks/utils.js.map +1 -1
- package/build/layouts/flex.js +76 -12
- package/build/layouts/flex.js.map +1 -1
- package/build/layouts/flow.js +9 -4
- package/build/layouts/flow.js.map +1 -1
- package/build/store/actions.js +297 -51
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +5 -2
- package/build/store/defaults.js.map +1 -1
- package/build/store/reducer.js +25 -13
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +142 -18
- package/build/store/selectors.js.map +1 -1
- package/build/utils/dom.js +2 -1
- package/build/utils/dom.js.map +1 -1
- package/build-module/components/alignment-control/index.js +12 -4
- package/build-module/components/alignment-control/index.js.map +1 -1
- package/build-module/components/block-alignment-control/index.js +12 -4
- package/build-module/components/block-alignment-control/index.js.map +1 -1
- package/build-module/components/block-draggable/index.js +2 -3
- package/build-module/components/block-draggable/index.js.map +1 -1
- package/build-module/components/block-icon/index.js +4 -0
- package/build-module/components/block-icon/index.js.map +1 -1
- package/build-module/components/block-inspector/index.js +6 -1
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +1 -4
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-focus-first-element.js +15 -17
- package/build-module/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-focus-handler.js +7 -1
- package/build-module/components/block-list/use-block-props/use-focus-handler.js.map +1 -1
- package/build-module/components/block-list-appender/index.js +6 -1
- package/build-module/components/block-list-appender/index.js.map +1 -1
- package/build-module/components/block-lock/menu-item.js +9 -0
- package/build-module/components/block-lock/menu-item.js.map +1 -1
- package/build-module/components/block-lock/modal.js +5 -14
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-lock/toolbar.js +11 -3
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-mover/index.js +4 -0
- package/build-module/components/block-mover/index.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +50 -7
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-switcher/index.js +2 -2
- package/build-module/components/block-switcher/index.js.map +1 -1
- package/build-module/components/block-title/index.js +2 -2
- package/build-module/components/block-title/index.js.map +1 -1
- package/build-module/components/block-title/use-block-display-title.js +1 -1
- package/build-module/components/block-title/use-block-display-title.js.map +1 -1
- package/build-module/components/block-toolbar/block-name-context.js +9 -0
- package/build-module/components/block-toolbar/block-name-context.js.map +1 -0
- package/build-module/components/block-toolbar/block-toolbar-last-item.js +11 -0
- package/build-module/components/block-toolbar/block-toolbar-last-item.js.map +1 -0
- package/build-module/components/block-toolbar/index.js +16 -4
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-tools/index.js +0 -16
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/block-variation-transforms/index.js +95 -49
- package/build-module/components/block-variation-transforms/index.js.map +1 -1
- package/build-module/components/block-vertical-alignment-control/index.js +12 -4
- package/build-module/components/block-vertical-alignment-control/index.js.map +1 -1
- package/build-module/components/contrast-checker/index.js +4 -0
- package/build-module/components/contrast-checker/index.js.map +1 -1
- package/build-module/components/convert-to-group-buttons/index.js +2 -1
- package/build-module/components/convert-to-group-buttons/index.js.map +1 -1
- package/build-module/components/convert-to-group-buttons/toolbar.js +90 -0
- package/build-module/components/convert-to-group-buttons/toolbar.js.map +1 -0
- package/build-module/components/copy-handler/index.js +4 -0
- package/build-module/components/copy-handler/index.js.map +1 -1
- package/build-module/components/font-sizes/font-size-picker.js +4 -0
- package/build-module/components/font-sizes/font-size-picker.js.map +1 -1
- package/build-module/components/iframe/index.js +6 -9
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/index.js +2 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/justify-content-control/index.js +12 -4
- package/build-module/components/justify-content-control/index.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/index.js +1 -1
- package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/line-height-control/index.js +9 -2
- package/build-module/components/line-height-control/index.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +22 -6
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/block.js +5 -1
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +1 -1
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/media-replace-flow/index.js +4 -0
- package/build-module/components/media-replace-flow/index.js.map +1 -1
- package/build-module/components/multi-selection-inspector/index.js +2 -2
- package/build-module/components/multi-selection-inspector/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +25 -4
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/split-value.js +12 -2
- package/build-module/components/rich-text/split-value.js.map +1 -1
- package/build-module/components/rich-text/use-firefox-compat.js +39 -0
- package/build-module/components/rich-text/use-firefox-compat.js.map +1 -0
- package/build-module/components/rich-text/use-input-rules.js +35 -4
- package/build-module/components/rich-text/use-input-rules.js.map +1 -1
- package/build-module/components/skip-to-selected-block/index.js +4 -0
- package/build-module/components/skip-to-selected-block/index.js.map +1 -1
- package/build-module/components/writing-flow/index.js +5 -1
- package/build-module/components/writing-flow/index.js.map +1 -1
- package/build-module/components/writing-flow/use-arrow-nav.js +4 -45
- package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build-module/components/writing-flow/use-click-selection.js +57 -0
- package/build-module/components/writing-flow/use-click-selection.js.map +1 -0
- package/build-module/components/writing-flow/use-drag-selection.js +124 -0
- package/build-module/components/writing-flow/use-drag-selection.js.map +1 -0
- package/build-module/components/writing-flow/use-input.js +104 -0
- package/build-module/components/writing-flow/use-input.js.map +1 -0
- package/build-module/components/writing-flow/use-multi-selection.js +18 -37
- package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build-module/components/writing-flow/use-selection-observer.js +150 -0
- package/build-module/components/writing-flow/use-selection-observer.js.map +1 -0
- package/build-module/components/writing-flow/use-tab-nav.js +1 -9
- package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build-module/hooks/border-color.js +5 -5
- package/build-module/hooks/border-color.js.map +1 -1
- package/build-module/hooks/border.js +0 -12
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/color.js +19 -18
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/font-family.js +3 -1
- package/build-module/hooks/font-family.js.map +1 -1
- package/build-module/hooks/font-size.js +4 -3
- package/build-module/hooks/font-size.js.map +1 -1
- package/build-module/hooks/gap.js +22 -15
- package/build-module/hooks/gap.js.map +1 -1
- package/build-module/hooks/layout.js +7 -2
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/style.js +33 -3
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/utils.js +26 -0
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/layouts/flex.js +76 -13
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/layouts/flow.js +9 -5
- package/build-module/layouts/flow.js.map +1 -1
- package/build-module/store/actions.js +286 -49
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +5 -2
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/reducer.js +25 -13
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +138 -19
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/dom.js +2 -1
- package/build-module/utils/dom.js.map +1 -1
- package/build-style/style-rtl.css +107 -74
- package/build-style/style.css +107 -74
- package/build-types/utils/dom.d.ts.map +1 -1
- package/package.json +28 -28
- package/src/components/alignment-control/index.js +9 -4
- package/src/components/block-alignment-control/index.js +9 -4
- package/src/components/block-draggable/index.js +2 -5
- package/src/components/block-icon/index.js +3 -0
- package/src/components/block-inspector/index.js +4 -0
- package/src/components/block-list/style.scss +4 -5
- package/src/components/block-list/use-block-props/index.js +0 -5
- package/src/components/block-list/use-block-props/use-focus-first-element.js +19 -26
- package/src/components/block-list/use-block-props/use-focus-handler.js +8 -0
- package/src/components/block-list-appender/index.js +5 -0
- package/src/components/block-lock/menu-item.js +8 -1
- package/src/components/block-lock/modal.js +18 -13
- package/src/components/block-lock/style.scss +6 -3
- package/src/components/block-lock/toolbar.js +12 -2
- package/src/components/block-mover/index.js +3 -0
- package/src/components/block-mover/style.scss +4 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +62 -4
- package/src/components/block-switcher/index.js +2 -2
- package/src/components/block-switcher/style.scss +8 -1
- package/src/components/block-switcher/test/index.js +2 -2
- package/src/components/block-title/index.js +2 -2
- package/src/components/block-title/use-block-display-title.js +1 -1
- package/src/components/block-toolbar/block-name-context.js +8 -0
- package/src/components/block-toolbar/block-toolbar-last-item.js +12 -0
- package/src/components/block-toolbar/index.js +18 -2
- package/src/components/block-toolbar/style.scss +6 -0
- package/src/components/block-tools/index.js +0 -19
- package/src/components/block-tools/style.scss +3 -5
- package/src/components/block-variation-transforms/index.js +105 -36
- package/src/components/block-variation-transforms/style.scss +1 -1
- package/src/components/block-vertical-alignment-control/index.js +9 -4
- package/src/components/button-block-appender/style.scss +5 -1
- package/src/components/contrast-checker/index.js +3 -0
- package/src/components/convert-to-group-buttons/index.js +6 -1
- package/src/components/convert-to-group-buttons/toolbar.js +87 -0
- package/src/components/copy-handler/index.js +3 -0
- package/src/components/font-sizes/font-size-picker.js +3 -0
- package/src/components/iframe/index.js +5 -7
- package/src/components/index.js +2 -0
- package/src/components/justify-content-control/index.js +9 -4
- package/src/components/keyboard-shortcuts/index.js +1 -1
- package/src/components/line-height-control/index.js +8 -3
- package/src/components/list-view/block-select-button.js +21 -3
- package/src/components/list-view/block.js +8 -1
- package/src/components/list-view/branch.js +1 -1
- package/src/components/list-view/style.scss +56 -14
- package/src/components/media-placeholder/README.md +8 -0
- package/src/components/media-replace-flow/index.js +3 -0
- package/src/components/multi-selection-inspector/index.js +2 -2
- package/src/components/rich-text/index.js +24 -1
- package/src/components/rich-text/split-value.js +5 -1
- package/src/components/rich-text/use-firefox-compat.js +39 -0
- package/src/components/rich-text/use-input-rules.js +40 -3
- package/src/components/skip-to-selected-block/index.js +3 -0
- package/src/components/url-input/style.scss +3 -2
- package/src/components/writing-flow/index.js +8 -0
- package/src/components/writing-flow/readme.md +28 -0
- package/src/components/writing-flow/use-arrow-nav.js +4 -53
- package/src/components/writing-flow/use-click-selection.js +65 -0
- package/src/components/writing-flow/use-drag-selection.js +126 -0
- package/src/components/writing-flow/use-input.js +112 -0
- package/src/components/writing-flow/use-multi-selection.js +13 -36
- package/src/components/writing-flow/use-selection-observer.js +153 -0
- package/src/components/writing-flow/use-tab-nav.js +1 -11
- package/src/hooks/border-color.js +5 -5
- package/src/hooks/border.js +0 -13
- package/src/hooks/color.js +51 -24
- package/src/hooks/font-family.js +5 -2
- package/src/hooks/font-size.js +10 -7
- package/src/hooks/gap.js +25 -17
- package/src/hooks/layout.js +11 -1
- package/src/hooks/style.js +40 -4
- package/src/hooks/test/gap.js +25 -1
- package/src/hooks/test/style.js +94 -0
- package/src/hooks/test/utils.js +1 -1
- package/src/hooks/utils.js +26 -0
- package/src/layouts/flex.js +89 -5
- package/src/layouts/flow.js +15 -4
- package/src/store/actions.js +349 -32
- package/src/store/defaults.js +7 -2
- package/src/store/reducer.js +25 -10
- package/src/store/selectors.js +181 -24
- package/src/store/test/selectors.js +242 -5
- package/src/utils/dom.js +2 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/block-list/use-block-props/use-multi-selection.js +0 -205
- package/build/components/block-list/use-block-props/use-multi-selection.js.map +0 -1
- package/build/components/block-list/use-block-props/use-scroll-into-view.js +0 -77
- package/build/components/block-list/use-block-props/use-scroll-into-view.js.map +0 -1
- package/build-module/components/block-list/use-block-props/use-multi-selection.js +0 -192
- package/build-module/components/block-list/use-block-props/use-multi-selection.js.map +0 -1
- package/build-module/components/block-list/use-block-props/use-scroll-into-view.js +0 -63
- package/build-module/components/block-list/use-block-props/use-scroll-into-view.js.map +0 -1
- package/src/components/block-list/use-block-props/use-multi-selection.js +0 -227
- package/src/components/block-list/use-block-props/use-scroll-into-view.js +0 -73
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import scrollIntoView from 'dom-scroll-into-view';
|
|
5
|
-
/**
|
|
6
|
-
* WordPress dependencies
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* WordPress dependencies
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { useEffect, useRef } from '@wordpress/element';
|
|
14
|
-
import { useSelect } from '@wordpress/data';
|
|
15
|
-
import { getScrollContainer } from '@wordpress/dom';
|
|
16
|
-
/**
|
|
17
|
-
* Internal dependencies
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import { store as blockEditorStore } from '../../../store';
|
|
21
|
-
export function useScrollIntoView(clientId) {
|
|
22
|
-
const ref = useRef();
|
|
23
|
-
const isSelectionEnd = useSelect(select => {
|
|
24
|
-
const {
|
|
25
|
-
isBlockSelected,
|
|
26
|
-
getBlockSelectionEnd
|
|
27
|
-
} = select(blockEditorStore);
|
|
28
|
-
return isBlockSelected(clientId) || getBlockSelectionEnd() === clientId;
|
|
29
|
-
}, [clientId]); // Note that we can't use `useRefEffect` here, since an element change does
|
|
30
|
-
// not mean we can scroll. `isSelectionEnd` should be the sole dependency,
|
|
31
|
-
// while with `useRefEffect`, the element is a dependency as well.
|
|
32
|
-
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
if (!isSelectionEnd) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const extentNode = ref.current;
|
|
39
|
-
|
|
40
|
-
if (!extentNode) {
|
|
41
|
-
return;
|
|
42
|
-
} // If the block is focused, the browser will already have scrolled into
|
|
43
|
-
// view if necessary.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (extentNode.contains(extentNode.ownerDocument.activeElement)) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const scrollContainer = getScrollContainer(extentNode) || extentNode.ownerDocument.defaultView; // If there's no scroll container, it follows that there's no scrollbar
|
|
51
|
-
// and thus there's no need to try to scroll into view.
|
|
52
|
-
|
|
53
|
-
if (!scrollContainer) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
scrollIntoView(extentNode, scrollContainer, {
|
|
58
|
-
onlyScrollIfNeeded: true
|
|
59
|
-
});
|
|
60
|
-
}, [isSelectionEnd]);
|
|
61
|
-
return ref;
|
|
62
|
-
}
|
|
63
|
-
//# sourceMappingURL=use-scroll-into-view.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-list/use-block-props/use-scroll-into-view.js"],"names":["scrollIntoView","useEffect","useRef","useSelect","getScrollContainer","store","blockEditorStore","useScrollIntoView","clientId","ref","isSelectionEnd","select","isBlockSelected","getBlockSelectionEnd","extentNode","current","contains","ownerDocument","activeElement","scrollContainer","defaultView","onlyScrollIfNeeded"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,cAAP,MAA2B,sBAA3B;AAEA;AACA;AACA;;AACA;AACA;AACA;;AACA,SAASC,SAAT,EAAoBC,MAApB,QAAkC,oBAAlC;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,kBAAT,QAAmC,gBAAnC;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,gBAA1C;AAEA,OAAO,SAASC,iBAAT,CAA4BC,QAA5B,EAAuC;AAC7C,QAAMC,GAAG,GAAGP,MAAM,EAAlB;AACA,QAAMQ,cAAc,GAAGP,SAAS,CAC7BQ,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA,eAAF;AAAmBC,MAAAA;AAAnB,QAA4CF,MAAM,CACvDL,gBADuD,CAAxD;AAIA,WACCM,eAAe,CAAEJ,QAAF,CAAf,IACAK,oBAAoB,OAAOL,QAF5B;AAIA,GAV8B,EAW/B,CAAEA,QAAF,CAX+B,CAAhC,CAF6C,CAgB7C;AACA;AACA;;AACAP,EAAAA,SAAS,CAAE,MAAM;AAChB,QAAK,CAAES,cAAP,EAAwB;AACvB;AACA;;AAED,UAAMI,UAAU,GAAGL,GAAG,CAACM,OAAvB;;AAEA,QAAK,CAAED,UAAP,EAAoB;AACnB;AACA,KATe,CAWhB;AACA;;;AACA,QAAKA,UAAU,CAACE,QAAX,CAAqBF,UAAU,CAACG,aAAX,CAAyBC,aAA9C,CAAL,EAAqE;AACpE;AACA;;AAED,UAAMC,eAAe,GACpBf,kBAAkB,CAAEU,UAAF,CAAlB,IACAA,UAAU,CAACG,aAAX,CAAyBG,WAF1B,CAjBgB,CAqBhB;AACA;;AACA,QAAK,CAAED,eAAP,EAAyB;AACxB;AACA;;AAEDnB,IAAAA,cAAc,CAAEc,UAAF,EAAcK,eAAd,EAA+B;AAC5CE,MAAAA,kBAAkB,EAAE;AADwB,KAA/B,CAAd;AAGA,GA9BQ,EA8BN,CAAEX,cAAF,CA9BM,CAAT;AAgCA,SAAOD,GAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport scrollIntoView from 'dom-scroll-into-view';\n\n/**\n * WordPress dependencies\n */\n/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { getScrollContainer } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../../store';\n\nexport function useScrollIntoView( clientId ) {\n\tconst ref = useRef();\n\tconst isSelectionEnd = useSelect(\n\t\t( select ) => {\n\t\t\tconst { isBlockSelected, getBlockSelectionEnd } = select(\n\t\t\t\tblockEditorStore\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\tisBlockSelected( clientId ) ||\n\t\t\t\tgetBlockSelectionEnd() === clientId\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\t// Note that we can't use `useRefEffect` here, since an element change does\n\t// not mean we can scroll. `isSelectionEnd` should be the sole dependency,\n\t// while with `useRefEffect`, the element is a dependency as well.\n\tuseEffect( () => {\n\t\tif ( ! isSelectionEnd ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst extentNode = ref.current;\n\n\t\tif ( ! extentNode ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the block is focused, the browser will already have scrolled into\n\t\t// view if necessary.\n\t\tif ( extentNode.contains( extentNode.ownerDocument.activeElement ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst scrollContainer =\n\t\t\tgetScrollContainer( extentNode ) ||\n\t\t\textentNode.ownerDocument.defaultView;\n\n\t\t// If there's no scroll container, it follows that there's no scrollbar\n\t\t// and thus there's no need to try to scroll into view.\n\t\tif ( ! scrollContainer ) {\n\t\t\treturn;\n\t\t}\n\n\t\tscrollIntoView( extentNode, scrollContainer, {\n\t\t\tonlyScrollIfNeeded: true,\n\t\t} );\n\t}, [ isSelectionEnd ] );\n\n\treturn ref;\n}\n"]}
|
|
@@ -1,227 +0,0 @@
|
|
|
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
|
-
* Sets the `contenteditable` wrapper element to `value`.
|
|
15
|
-
*
|
|
16
|
-
* @param {HTMLElement} node Block element.
|
|
17
|
-
* @param {boolean} value `contentEditable` value (true or false)
|
|
18
|
-
*/
|
|
19
|
-
export function setContentEditableWrapper( node, value ) {
|
|
20
|
-
// Since `closest` considers `node` as a candidate, use `parentElement`.
|
|
21
|
-
node.parentElement.closest( '[contenteditable]' ).contentEditable = value;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Sets a multi-selection based on the native selection across blocks.
|
|
26
|
-
*
|
|
27
|
-
* @param {string} clientId Block client ID.
|
|
28
|
-
*/
|
|
29
|
-
export function useMultiSelection( clientId ) {
|
|
30
|
-
const {
|
|
31
|
-
startMultiSelect,
|
|
32
|
-
stopMultiSelect,
|
|
33
|
-
multiSelect,
|
|
34
|
-
selectBlock,
|
|
35
|
-
} = useDispatch( blockEditorStore );
|
|
36
|
-
const {
|
|
37
|
-
isSelectionEnabled,
|
|
38
|
-
isBlockSelected,
|
|
39
|
-
getBlockParents,
|
|
40
|
-
getBlockSelectionStart,
|
|
41
|
-
hasMultiSelection,
|
|
42
|
-
} = useSelect( blockEditorStore );
|
|
43
|
-
return useRefEffect(
|
|
44
|
-
( node ) => {
|
|
45
|
-
const { ownerDocument } = node;
|
|
46
|
-
const { defaultView } = ownerDocument;
|
|
47
|
-
|
|
48
|
-
let anchorElement;
|
|
49
|
-
let rafId;
|
|
50
|
-
|
|
51
|
-
function onSelectionChange( { isSelectionEnd } ) {
|
|
52
|
-
const selection = defaultView.getSelection();
|
|
53
|
-
|
|
54
|
-
// If no selection is found, end multi selection and disable the
|
|
55
|
-
// contentEditable wrapper.
|
|
56
|
-
if ( ! selection.rangeCount || selection.isCollapsed ) {
|
|
57
|
-
setContentEditableWrapper( node, false );
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const endClientId = getBlockClientId( selection.focusNode );
|
|
62
|
-
const isSingularSelection = clientId === endClientId;
|
|
63
|
-
|
|
64
|
-
if ( isSingularSelection ) {
|
|
65
|
-
selectBlock( clientId );
|
|
66
|
-
|
|
67
|
-
// If the selection is complete (on mouse up), and no
|
|
68
|
-
// multiple blocks have been selected, set focus back to the
|
|
69
|
-
// anchor element. if the anchor element contains the
|
|
70
|
-
// selection. Additionally, the contentEditable wrapper can
|
|
71
|
-
// now be disabled again.
|
|
72
|
-
if ( isSelectionEnd ) {
|
|
73
|
-
setContentEditableWrapper( node, false );
|
|
74
|
-
|
|
75
|
-
if ( selection.rangeCount ) {
|
|
76
|
-
const {
|
|
77
|
-
commonAncestorContainer,
|
|
78
|
-
} = selection.getRangeAt( 0 );
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
anchorElement.contains(
|
|
82
|
-
commonAncestorContainer
|
|
83
|
-
)
|
|
84
|
-
) {
|
|
85
|
-
anchorElement.focus();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
const startPath = [
|
|
91
|
-
...getBlockParents( clientId ),
|
|
92
|
-
clientId,
|
|
93
|
-
];
|
|
94
|
-
const endPath = [
|
|
95
|
-
...getBlockParents( endClientId ),
|
|
96
|
-
endClientId,
|
|
97
|
-
];
|
|
98
|
-
const depth =
|
|
99
|
-
Math.min( startPath.length, endPath.length ) - 1;
|
|
100
|
-
|
|
101
|
-
multiSelect( startPath[ depth ], endPath[ depth ] );
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function onSelectionEnd() {
|
|
106
|
-
ownerDocument.removeEventListener(
|
|
107
|
-
'selectionchange',
|
|
108
|
-
onSelectionChange
|
|
109
|
-
);
|
|
110
|
-
// Equivalent to attaching the listener once.
|
|
111
|
-
defaultView.removeEventListener( 'mouseup', onSelectionEnd );
|
|
112
|
-
// The browser selection won't have updated yet at this point,
|
|
113
|
-
// so wait until the next animation frame to get the browser
|
|
114
|
-
// selection.
|
|
115
|
-
rafId = defaultView.requestAnimationFrame( () => {
|
|
116
|
-
onSelectionChange( { isSelectionEnd: true } );
|
|
117
|
-
stopMultiSelect();
|
|
118
|
-
} );
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function onMouseLeave( { buttons } ) {
|
|
122
|
-
// The primary button must be pressed to initiate selection.
|
|
123
|
-
// See https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
|
|
124
|
-
if ( buttons !== 1 ) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if ( ! isSelectionEnabled() || ! isBlockSelected( clientId ) ) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
anchorElement = ownerDocument.activeElement;
|
|
133
|
-
startMultiSelect();
|
|
134
|
-
|
|
135
|
-
// `onSelectionStart` is called after `mousedown` and
|
|
136
|
-
// `mouseleave` (from a block). The selection ends when
|
|
137
|
-
// `mouseup` happens anywhere in the window.
|
|
138
|
-
ownerDocument.addEventListener(
|
|
139
|
-
'selectionchange',
|
|
140
|
-
onSelectionChange
|
|
141
|
-
);
|
|
142
|
-
defaultView.addEventListener( 'mouseup', onSelectionEnd );
|
|
143
|
-
|
|
144
|
-
// Allow cross contentEditable selection by temporarily making
|
|
145
|
-
// all content editable. We can't rely on using the store and
|
|
146
|
-
// React because re-rending happens too slowly. We need to be
|
|
147
|
-
// able to select across instances immediately.
|
|
148
|
-
setContentEditableWrapper( node, true );
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function onMouseDown( event ) {
|
|
152
|
-
// The main button.
|
|
153
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
|
|
154
|
-
if ( ! isSelectionEnabled() || event.button !== 0 ) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if ( event.shiftKey ) {
|
|
159
|
-
const blockSelectionStart = getBlockSelectionStart();
|
|
160
|
-
// By checking `blockSelectionStart` to be set, we handle the
|
|
161
|
-
// case where we select a single block. We also have to check
|
|
162
|
-
// the selectionEnd (clientId) not to be included in the
|
|
163
|
-
// `blockSelectionStart`'s parents because the click event is
|
|
164
|
-
// propagated.
|
|
165
|
-
const startParents = getBlockParents( blockSelectionStart );
|
|
166
|
-
if (
|
|
167
|
-
blockSelectionStart &&
|
|
168
|
-
blockSelectionStart !== clientId &&
|
|
169
|
-
! startParents?.includes( clientId )
|
|
170
|
-
) {
|
|
171
|
-
const startPath = [
|
|
172
|
-
...startParents,
|
|
173
|
-
blockSelectionStart,
|
|
174
|
-
];
|
|
175
|
-
const endPath = [
|
|
176
|
-
...getBlockParents( clientId ),
|
|
177
|
-
clientId,
|
|
178
|
-
];
|
|
179
|
-
const depth =
|
|
180
|
-
Math.min( startPath.length, endPath.length ) - 1;
|
|
181
|
-
const start = startPath[ depth ];
|
|
182
|
-
const end = endPath[ depth ];
|
|
183
|
-
// Handle the case of having selected a parent block and
|
|
184
|
-
// then shift+click on a child.
|
|
185
|
-
if ( start !== end ) {
|
|
186
|
-
setContentEditableWrapper( node, true );
|
|
187
|
-
multiSelect( start, end );
|
|
188
|
-
event.preventDefault();
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
} else if ( hasMultiSelection() ) {
|
|
192
|
-
// Allow user to escape out of a multi-selection to a
|
|
193
|
-
// singular selection of a block via click. This is handled
|
|
194
|
-
// here since focus handling excludes blocks when there is
|
|
195
|
-
// multiselection, as focus can be incurred by starting a
|
|
196
|
-
// multiselection (focus moved to first block's multi-
|
|
197
|
-
// controls).
|
|
198
|
-
selectBlock( clientId );
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
node.addEventListener( 'mousedown', onMouseDown );
|
|
203
|
-
node.addEventListener( 'mouseleave', onMouseLeave );
|
|
204
|
-
|
|
205
|
-
return () => {
|
|
206
|
-
node.removeEventListener( 'mousedown', onMouseDown );
|
|
207
|
-
node.removeEventListener( 'mouseleave', onMouseLeave );
|
|
208
|
-
ownerDocument.removeEventListener(
|
|
209
|
-
'selectionchange',
|
|
210
|
-
onSelectionChange
|
|
211
|
-
);
|
|
212
|
-
defaultView.removeEventListener( 'mouseup', onSelectionEnd );
|
|
213
|
-
defaultView.cancelAnimationFrame( rafId );
|
|
214
|
-
};
|
|
215
|
-
},
|
|
216
|
-
[
|
|
217
|
-
clientId,
|
|
218
|
-
startMultiSelect,
|
|
219
|
-
stopMultiSelect,
|
|
220
|
-
multiSelect,
|
|
221
|
-
selectBlock,
|
|
222
|
-
isSelectionEnabled,
|
|
223
|
-
isBlockSelected,
|
|
224
|
-
getBlockParents,
|
|
225
|
-
]
|
|
226
|
-
);
|
|
227
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import scrollIntoView from 'dom-scroll-into-view';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* WordPress dependencies
|
|
11
|
-
*/
|
|
12
|
-
import { useEffect, useRef } from '@wordpress/element';
|
|
13
|
-
import { useSelect } from '@wordpress/data';
|
|
14
|
-
import { getScrollContainer } from '@wordpress/dom';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Internal dependencies
|
|
18
|
-
*/
|
|
19
|
-
import { store as blockEditorStore } from '../../../store';
|
|
20
|
-
|
|
21
|
-
export function useScrollIntoView( clientId ) {
|
|
22
|
-
const ref = useRef();
|
|
23
|
-
const isSelectionEnd = useSelect(
|
|
24
|
-
( select ) => {
|
|
25
|
-
const { isBlockSelected, getBlockSelectionEnd } = select(
|
|
26
|
-
blockEditorStore
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
isBlockSelected( clientId ) ||
|
|
31
|
-
getBlockSelectionEnd() === clientId
|
|
32
|
-
);
|
|
33
|
-
},
|
|
34
|
-
[ clientId ]
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
// Note that we can't use `useRefEffect` here, since an element change does
|
|
38
|
-
// not mean we can scroll. `isSelectionEnd` should be the sole dependency,
|
|
39
|
-
// while with `useRefEffect`, the element is a dependency as well.
|
|
40
|
-
useEffect( () => {
|
|
41
|
-
if ( ! isSelectionEnd ) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const extentNode = ref.current;
|
|
46
|
-
|
|
47
|
-
if ( ! extentNode ) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// If the block is focused, the browser will already have scrolled into
|
|
52
|
-
// view if necessary.
|
|
53
|
-
if ( extentNode.contains( extentNode.ownerDocument.activeElement ) ) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const scrollContainer =
|
|
58
|
-
getScrollContainer( extentNode ) ||
|
|
59
|
-
extentNode.ownerDocument.defaultView;
|
|
60
|
-
|
|
61
|
-
// If there's no scroll container, it follows that there's no scrollbar
|
|
62
|
-
// and thus there's no need to try to scroll into view.
|
|
63
|
-
if ( ! scrollContainer ) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
scrollIntoView( extentNode, scrollContainer, {
|
|
68
|
-
onlyScrollIfNeeded: true,
|
|
69
|
-
} );
|
|
70
|
-
}, [ isSelectionEnd ] );
|
|
71
|
-
|
|
72
|
-
return ref;
|
|
73
|
-
}
|