@wordpress/block-editor 8.3.1 → 8.5.1
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 +4 -0
- package/README.md +56 -18
- 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-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/block-html.js +4 -1
- package/build/components/block-list/block-html.js.map +1 -1
- package/build/components/block-list/block.js +4 -1
- package/build/components/block-list/block.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 +22 -6
- 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 +40 -0
- package/build/components/block-lock/index.js.map +1 -0
- package/build/components/block-lock/menu-item.js +52 -0
- package/build/components/block-lock/menu-item.js.map +1 -0
- package/build/components/block-lock/modal.js +155 -0
- package/build/components/block-lock/modal.js.map +1 -0
- package/build/components/block-lock/toolbar.js +65 -0
- package/build/components/block-lock/toolbar.js.map +1 -0
- package/build/components/block-lock/use-block-lock.js +53 -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 +75 -10
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-settings-menu-controls/index.js +19 -9
- package/build/components/block-settings-menu-controls/index.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 +8 -6
- 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 +24 -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/border-radius-control/index.js +0 -1
- package/build/components/border-radius-control/index.js.map +1 -1
- package/build/components/border-radius-control/utils.js +1 -1
- package/build/components/border-radius-control/utils.js.map +1 -1
- package/build/components/colors-gradients/control.js +3 -1
- package/build/components/colors-gradients/control.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/date-format-picker/index.js +132 -0
- package/build/components/date-format-picker/index.js.map +1 -0
- 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 +27 -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 +15 -6
- package/build/components/line-height-control/index.js.map +1 -1
- package/build/components/list-view/block-select-button.js +18 -23
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/block.js +38 -13
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +16 -13
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/index.js +7 -1
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/use-block-selection.js +9 -2
- package/build/components/list-view/use-block-selection.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 +27 -5
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/index.native.js +13 -9
- package/build/components/rich-text/index.native.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/url-popover/image-url-input-ui.js +11 -27
- package/build/components/url-popover/image-url-input-ui.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/anchor.js +7 -6
- package/build/hooks/anchor.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 +77 -5
- 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 +82 -15
- package/build/layouts/flex.js.map +1 -1
- package/build/layouts/flow.js +22 -13
- 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 -1
- 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 +197 -23
- 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-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/block-html.js +5 -2
- package/build-module/components/block-list/block-html.js.map +1 -1
- package/build-module/components/block-list/block.js +5 -2
- package/build-module/components/block-list/block.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 +22 -6
- 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 +5 -0
- package/build-module/components/block-lock/index.js.map +1 -0
- package/build-module/components/block-lock/menu-item.js +39 -0
- package/build-module/components/block-lock/menu-item.js.map +1 -0
- package/build-module/components/block-lock/modal.js +138 -0
- package/build-module/components/block-lock/modal.js.map +1 -0
- package/build-module/components/block-lock/toolbar.js +51 -0
- package/build-module/components/block-lock/toolbar.js.map +1 -0
- package/build-module/components/block-lock/use-block-lock.js +44 -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 +75 -12
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-settings-menu-controls/index.js +18 -9
- package/build-module/components/block-settings-menu-controls/index.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 +8 -6
- 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 +19 -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/border-radius-control/index.js +0 -1
- package/build-module/components/border-radius-control/index.js.map +1 -1
- package/build-module/components/border-radius-control/utils.js +1 -1
- package/build-module/components/border-radius-control/utils.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +3 -1
- package/build-module/components/colors-gradients/control.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/date-format-picker/index.js +122 -0
- package/build-module/components/date-format-picker/index.js.map +1 -0
- 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 +3 -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 +14 -5
- package/build-module/components/line-height-control/index.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +19 -23
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/block.js +36 -13
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +16 -13
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/index.js +7 -1
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/use-block-selection.js +10 -3
- package/build-module/components/list-view/use-block-selection.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 +26 -5
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +13 -9
- package/build-module/components/rich-text/index.native.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/url-popover/image-url-input-ui.js +12 -28
- package/build-module/components/url-popover/image-url-input-ui.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/anchor.js +7 -6
- package/build-module/hooks/anchor.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 +75 -7
- 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 +81 -16
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/layouts/flow.js +20 -13
- 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 -1
- 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 +186 -22
- 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 +248 -49
- package/build-style/style.css +248 -49
- package/build-types/utils/dom.d.ts.map +1 -1
- package/package.json +28 -27
- package/src/components/alignment-control/index.js +9 -4
- package/src/components/block-alignment-control/index.js +9 -4
- 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/block-html.js +8 -4
- package/src/components/block-list/block.js +5 -1
- 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 +27 -6
- 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 +4 -0
- package/src/components/block-lock/menu-item.js +39 -0
- package/src/components/block-lock/modal.js +194 -0
- package/src/components/block-lock/style.scss +70 -0
- package/src/components/block-lock/toolbar.js +51 -0
- package/src/components/block-lock/use-block-lock.js +49 -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 +109 -9
- package/src/components/block-settings-menu-controls/index.js +33 -12
- 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/README.md +6 -1
- package/src/components/block-title/index.js +2 -2
- package/src/components/block-title/test/index.js +43 -1
- package/src/components/block-title/use-block-display-title.js +10 -7
- 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 +24 -2
- package/src/components/block-toolbar/style.scss +10 -0
- package/src/components/block-tools/index.js +0 -19
- package/src/components/block-tools/style.scss +27 -0
- 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/border-radius-control/index.js +0 -1
- package/src/components/border-radius-control/test/utils.js +4 -0
- package/src/components/border-radius-control/utils.js +2 -1
- package/src/components/button-block-appender/style.scss +5 -1
- package/src/components/color-palette/test/__snapshots__/control.js.snap +70 -4
- package/src/components/colors-gradients/control.js +1 -1
- package/src/components/colors-gradients/style.scss +6 -0
- 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/date-format-picker/README.md +58 -0
- package/src/components/date-format-picker/index.js +161 -0
- package/src/components/date-format-picker/style.scss +31 -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 +3 -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 +11 -6
- package/src/components/link-control/README.md +1 -1
- package/src/components/list-view/block-select-button.js +14 -31
- package/src/components/list-view/block.js +55 -13
- package/src/components/list-view/branch.js +37 -15
- package/src/components/list-view/index.js +6 -0
- package/src/components/list-view/style.scss +56 -14
- package/src/components/list-view/use-block-selection.js +15 -2
- 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 +25 -2
- package/src/components/rich-text/index.native.js +24 -8
- 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/url-popover/image-url-input-ui.js +16 -29
- 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/anchor.js +8 -6
- 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 +91 -12
- package/src/hooks/layout.js +11 -1
- package/src/hooks/style.js +40 -4
- package/src/hooks/test/gap.js +66 -0
- 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 +93 -6
- package/src/layouts/flow.js +28 -12
- package/src/store/actions.js +349 -32
- package/src/store/defaults.js +7 -1
- package/src/store/reducer.js +25 -10
- package/src/store/selectors.js +229 -27
- package/src/store/test/selectors.js +305 -5
- package/src/style.scss +2 -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,205 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.setContentEditableWrapper = setContentEditableWrapper;
|
|
7
|
-
exports.useMultiSelection = useMultiSelection;
|
|
8
|
-
|
|
9
|
-
var _data = require("@wordpress/data");
|
|
10
|
-
|
|
11
|
-
var _compose = require("@wordpress/compose");
|
|
12
|
-
|
|
13
|
-
var _store = require("../../../store");
|
|
14
|
-
|
|
15
|
-
var _dom = require("../../../utils/dom");
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* WordPress dependencies
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Internal dependencies
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Sets the `contenteditable` wrapper element to `value`.
|
|
27
|
-
*
|
|
28
|
-
* @param {HTMLElement} node Block element.
|
|
29
|
-
* @param {boolean} value `contentEditable` value (true or false)
|
|
30
|
-
*/
|
|
31
|
-
function setContentEditableWrapper(node, value) {
|
|
32
|
-
// Since `closest` considers `node` as a candidate, use `parentElement`.
|
|
33
|
-
node.parentElement.closest('[contenteditable]').contentEditable = value;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Sets a multi-selection based on the native selection across blocks.
|
|
37
|
-
*
|
|
38
|
-
* @param {string} clientId Block client ID.
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
function useMultiSelection(clientId) {
|
|
43
|
-
const {
|
|
44
|
-
startMultiSelect,
|
|
45
|
-
stopMultiSelect,
|
|
46
|
-
multiSelect,
|
|
47
|
-
selectBlock
|
|
48
|
-
} = (0, _data.useDispatch)(_store.store);
|
|
49
|
-
const {
|
|
50
|
-
isSelectionEnabled,
|
|
51
|
-
isBlockSelected,
|
|
52
|
-
getBlockParents,
|
|
53
|
-
getBlockSelectionStart,
|
|
54
|
-
hasMultiSelection
|
|
55
|
-
} = (0, _data.useSelect)(_store.store);
|
|
56
|
-
return (0, _compose.useRefEffect)(node => {
|
|
57
|
-
const {
|
|
58
|
-
ownerDocument
|
|
59
|
-
} = node;
|
|
60
|
-
const {
|
|
61
|
-
defaultView
|
|
62
|
-
} = ownerDocument;
|
|
63
|
-
let anchorElement;
|
|
64
|
-
let rafId;
|
|
65
|
-
|
|
66
|
-
function onSelectionChange(_ref) {
|
|
67
|
-
let {
|
|
68
|
-
isSelectionEnd
|
|
69
|
-
} = _ref;
|
|
70
|
-
const selection = defaultView.getSelection(); // If no selection is found, end multi selection and disable the
|
|
71
|
-
// contentEditable wrapper.
|
|
72
|
-
|
|
73
|
-
if (!selection.rangeCount || selection.isCollapsed) {
|
|
74
|
-
setContentEditableWrapper(node, false);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const endClientId = (0, _dom.getBlockClientId)(selection.focusNode);
|
|
79
|
-
const isSingularSelection = clientId === endClientId;
|
|
80
|
-
|
|
81
|
-
if (isSingularSelection) {
|
|
82
|
-
selectBlock(clientId); // If the selection is complete (on mouse up), and no
|
|
83
|
-
// multiple blocks have been selected, set focus back to the
|
|
84
|
-
// anchor element. if the anchor element contains the
|
|
85
|
-
// selection. Additionally, the contentEditable wrapper can
|
|
86
|
-
// now be disabled again.
|
|
87
|
-
|
|
88
|
-
if (isSelectionEnd) {
|
|
89
|
-
setContentEditableWrapper(node, false);
|
|
90
|
-
|
|
91
|
-
if (selection.rangeCount) {
|
|
92
|
-
const {
|
|
93
|
-
commonAncestorContainer
|
|
94
|
-
} = selection.getRangeAt(0);
|
|
95
|
-
|
|
96
|
-
if (anchorElement.contains(commonAncestorContainer)) {
|
|
97
|
-
anchorElement.focus();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
} else {
|
|
102
|
-
const startPath = [...getBlockParents(clientId), clientId];
|
|
103
|
-
const endPath = [...getBlockParents(endClientId), endClientId];
|
|
104
|
-
const depth = Math.min(startPath.length, endPath.length) - 1;
|
|
105
|
-
multiSelect(startPath[depth], endPath[depth]);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function onSelectionEnd() {
|
|
110
|
-
ownerDocument.removeEventListener('selectionchange', onSelectionChange); // Equivalent to attaching the listener once.
|
|
111
|
-
|
|
112
|
-
defaultView.removeEventListener('mouseup', onSelectionEnd); // 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
|
-
|
|
116
|
-
rafId = defaultView.requestAnimationFrame(() => {
|
|
117
|
-
onSelectionChange({
|
|
118
|
-
isSelectionEnd: true
|
|
119
|
-
});
|
|
120
|
-
stopMultiSelect();
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function onMouseLeave(_ref2) {
|
|
125
|
-
let {
|
|
126
|
-
buttons
|
|
127
|
-
} = _ref2;
|
|
128
|
-
|
|
129
|
-
// The primary button must be pressed to initiate selection.
|
|
130
|
-
// See https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
|
|
131
|
-
if (buttons !== 1) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (!isSelectionEnabled() || !isBlockSelected(clientId)) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
anchorElement = ownerDocument.activeElement;
|
|
140
|
-
startMultiSelect(); // `onSelectionStart` is called after `mousedown` and
|
|
141
|
-
// `mouseleave` (from a block). The selection ends when
|
|
142
|
-
// `mouseup` happens anywhere in the window.
|
|
143
|
-
|
|
144
|
-
ownerDocument.addEventListener('selectionchange', onSelectionChange);
|
|
145
|
-
defaultView.addEventListener('mouseup', onSelectionEnd); // Allow cross contentEditable selection by temporarily making
|
|
146
|
-
// all content editable. We can't rely on using the store and
|
|
147
|
-
// React because re-rending happens too slowly. We need to be
|
|
148
|
-
// able to select across instances immediately.
|
|
149
|
-
|
|
150
|
-
setContentEditableWrapper(node, true);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function onMouseDown(event) {
|
|
154
|
-
// The main button.
|
|
155
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
|
|
156
|
-
if (!isSelectionEnabled() || event.button !== 0) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (event.shiftKey) {
|
|
161
|
-
const blockSelectionStart = getBlockSelectionStart(); // By checking `blockSelectionStart` to be set, we handle the
|
|
162
|
-
// case where we select a single block. We also have to check
|
|
163
|
-
// the selectionEnd (clientId) not to be included in the
|
|
164
|
-
// `blockSelectionStart`'s parents because the click event is
|
|
165
|
-
// propagated.
|
|
166
|
-
|
|
167
|
-
const startParents = getBlockParents(blockSelectionStart);
|
|
168
|
-
|
|
169
|
-
if (blockSelectionStart && blockSelectionStart !== clientId && !(startParents !== null && startParents !== void 0 && startParents.includes(clientId))) {
|
|
170
|
-
const startPath = [...startParents, blockSelectionStart];
|
|
171
|
-
const endPath = [...getBlockParents(clientId), clientId];
|
|
172
|
-
const depth = Math.min(startPath.length, endPath.length) - 1;
|
|
173
|
-
const start = startPath[depth];
|
|
174
|
-
const end = endPath[depth]; // Handle the case of having selected a parent block and
|
|
175
|
-
// then shift+click on a child.
|
|
176
|
-
|
|
177
|
-
if (start !== end) {
|
|
178
|
-
setContentEditableWrapper(node, true);
|
|
179
|
-
multiSelect(start, end);
|
|
180
|
-
event.preventDefault();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
} else if (hasMultiSelection()) {
|
|
184
|
-
// Allow user to escape out of a multi-selection to a
|
|
185
|
-
// singular selection of a block via click. This is handled
|
|
186
|
-
// here since focus handling excludes blocks when there is
|
|
187
|
-
// multiselection, as focus can be incurred by starting a
|
|
188
|
-
// multiselection (focus moved to first block's multi-
|
|
189
|
-
// controls).
|
|
190
|
-
selectBlock(clientId);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
node.addEventListener('mousedown', onMouseDown);
|
|
195
|
-
node.addEventListener('mouseleave', onMouseLeave);
|
|
196
|
-
return () => {
|
|
197
|
-
node.removeEventListener('mousedown', onMouseDown);
|
|
198
|
-
node.removeEventListener('mouseleave', onMouseLeave);
|
|
199
|
-
ownerDocument.removeEventListener('selectionchange', onSelectionChange);
|
|
200
|
-
defaultView.removeEventListener('mouseup', onSelectionEnd);
|
|
201
|
-
defaultView.cancelAnimationFrame(rafId);
|
|
202
|
-
};
|
|
203
|
-
}, [clientId, startMultiSelect, stopMultiSelect, multiSelect, selectBlock, isSelectionEnabled, isBlockSelected, getBlockParents]);
|
|
204
|
-
}
|
|
205
|
-
//# sourceMappingURL=use-multi-selection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-list/use-block-props/use-multi-selection.js"],"names":["setContentEditableWrapper","node","value","parentElement","closest","contentEditable","useMultiSelection","clientId","startMultiSelect","stopMultiSelect","multiSelect","selectBlock","blockEditorStore","isSelectionEnabled","isBlockSelected","getBlockParents","getBlockSelectionStart","hasMultiSelection","ownerDocument","defaultView","anchorElement","rafId","onSelectionChange","isSelectionEnd","selection","getSelection","rangeCount","isCollapsed","endClientId","focusNode","isSingularSelection","commonAncestorContainer","getRangeAt","contains","focus","startPath","endPath","depth","Math","min","length","onSelectionEnd","removeEventListener","requestAnimationFrame","onMouseLeave","buttons","activeElement","addEventListener","onMouseDown","event","button","shiftKey","blockSelectionStart","startParents","includes","start","end","preventDefault","cancelAnimationFrame"],"mappings":";;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,yBAAT,CAAoCC,IAApC,EAA0CC,KAA1C,EAAkD;AACxD;AACAD,EAAAA,IAAI,CAACE,aAAL,CAAmBC,OAAnB,CAA4B,mBAA5B,EAAkDC,eAAlD,GAAoEH,KAApE;AACA;AAED;AACA;AACA;AACA;AACA;;;AACO,SAASI,iBAAT,CAA4BC,QAA5B,EAAuC;AAC7C,QAAM;AACLC,IAAAA,gBADK;AAELC,IAAAA,eAFK;AAGLC,IAAAA,WAHK;AAILC,IAAAA;AAJK,MAKF,uBAAaC,YAAb,CALJ;AAMA,QAAM;AACLC,IAAAA,kBADK;AAELC,IAAAA,eAFK;AAGLC,IAAAA,eAHK;AAILC,IAAAA,sBAJK;AAKLC,IAAAA;AALK,MAMF,qBAAWL,YAAX,CANJ;AAOA,SAAO,2BACJX,IAAF,IAAY;AACX,UAAM;AAAEi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wCE,YAAxC;AACA1B,MAAAA,aAAa,CAACwB,mBAAd,CACC,iBADD,EAECpB,iBAFD;AAIAH,MAAAA,WAAW,CAACuB,mBAAZ,CAAiC,SAAjC,EAA4CD,cAA5C;AACAtB,MAAAA,WAAW,CAACuC,oBAAZ,CAAkCrC,KAAlC;AACA,KATD;AAUA,GA5KK,EA6KN,CACCd,QADD,EAECC,gBAFD,EAGCC,eAHD,EAICC,WAJD,EAKCC,WALD,EAMCE,kBAND,EAOCC,eAPD,EAQCC,eARD,CA7KM,CAAP;AAwLA","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\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 */\nexport function setContentEditableWrapper( node, value ) {\n\t// Since `closest` considers `node` as a candidate, use `parentElement`.\n\tnode.parentElement.closest( '[contenteditable]' ).contentEditable = value;\n}\n\n/**\n * Sets a multi-selection based on the native selection across blocks.\n *\n * @param {string} clientId Block client ID.\n */\nexport function useMultiSelection( clientId ) {\n\tconst {\n\t\tstartMultiSelect,\n\t\tstopMultiSelect,\n\t\tmultiSelect,\n\t\tselectBlock,\n\t} = useDispatch( blockEditorStore );\n\tconst {\n\t\tisSelectionEnabled,\n\t\tisBlockSelected,\n\t\tgetBlockParents,\n\t\tgetBlockSelectionStart,\n\t\thasMultiSelection,\n\t} = useSelect( blockEditorStore );\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 onSelectionChange( { isSelectionEnd } ) {\n\t\t\t\tconst selection = defaultView.getSelection();\n\n\t\t\t\t// If no selection is found, end multi selection and disable the\n\t\t\t\t// contentEditable wrapper.\n\t\t\t\tif ( ! selection.rangeCount || selection.isCollapsed ) {\n\t\t\t\t\tsetContentEditableWrapper( node, false );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst endClientId = getBlockClientId( selection.focusNode );\n\t\t\t\tconst isSingularSelection = clientId === endClientId;\n\n\t\t\t\tif ( isSingularSelection ) {\n\t\t\t\t\tselectBlock( clientId );\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\tif ( isSelectionEnd ) {\n\t\t\t\t\t\tsetContentEditableWrapper( node, false );\n\n\t\t\t\t\t\tif ( selection.rangeCount ) {\n\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\tcommonAncestorContainer,\n\t\t\t\t\t\t\t} = selection.getRangeAt( 0 );\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tanchorElement.contains(\n\t\t\t\t\t\t\t\t\tcommonAncestorContainer\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tanchorElement.focus();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst startPath = [\n\t\t\t\t\t\t...getBlockParents( clientId ),\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t];\n\t\t\t\t\tconst endPath = [\n\t\t\t\t\t\t...getBlockParents( endClientId ),\n\t\t\t\t\t\tendClientId,\n\t\t\t\t\t];\n\t\t\t\t\tconst depth =\n\t\t\t\t\t\tMath.min( startPath.length, endPath.length ) - 1;\n\n\t\t\t\t\tmultiSelect( startPath[ depth ], endPath[ depth ] );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onSelectionEnd() {\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'selectionchange',\n\t\t\t\t\tonSelectionChange\n\t\t\t\t);\n\t\t\t\t// Equivalent to attaching the listener once.\n\t\t\t\tdefaultView.removeEventListener( 'mouseup', onSelectionEnd );\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\tonSelectionChange( { isSelectionEnd: true } );\n\t\t\t\t\tstopMultiSelect();\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tfunction onMouseLeave( { buttons } ) {\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\tif ( ! isSelectionEnabled() || ! isBlockSelected( clientId ) ) {\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\townerDocument.addEventListener(\n\t\t\t\t\t'selectionchange',\n\t\t\t\t\tonSelectionChange\n\t\t\t\t);\n\t\t\t\tdefaultView.addEventListener( 'mouseup', onSelectionEnd );\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\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\tif ( event.shiftKey ) {\n\t\t\t\t\tconst blockSelectionStart = getBlockSelectionStart();\n\t\t\t\t\t// By checking `blockSelectionStart` to be set, we handle the\n\t\t\t\t\t// case where we select a single block. We also have to check\n\t\t\t\t\t// the selectionEnd (clientId) not to be included in the\n\t\t\t\t\t// `blockSelectionStart`'s parents because the click event is\n\t\t\t\t\t// propagated.\n\t\t\t\t\tconst startParents = getBlockParents( blockSelectionStart );\n\t\t\t\t\tif (\n\t\t\t\t\t\tblockSelectionStart &&\n\t\t\t\t\t\tblockSelectionStart !== clientId &&\n\t\t\t\t\t\t! startParents?.includes( clientId )\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst startPath = [\n\t\t\t\t\t\t\t...startParents,\n\t\t\t\t\t\t\tblockSelectionStart,\n\t\t\t\t\t\t];\n\t\t\t\t\t\tconst endPath = [\n\t\t\t\t\t\t\t...getBlockParents( clientId ),\n\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t];\n\t\t\t\t\t\tconst depth =\n\t\t\t\t\t\t\tMath.min( startPath.length, endPath.length ) - 1;\n\t\t\t\t\t\tconst start = startPath[ depth ];\n\t\t\t\t\t\tconst end = endPath[ depth ];\n\t\t\t\t\t\t// Handle the case of having selected a parent block and\n\t\t\t\t\t\t// then shift+click on a child.\n\t\t\t\t\t\tif ( start !== end ) {\n\t\t\t\t\t\t\tsetContentEditableWrapper( node, true );\n\t\t\t\t\t\t\tmultiSelect( start, end );\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t}\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( clientId );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\t\t\tnode.addEventListener( 'mouseleave', onMouseLeave );\n\n\t\t\treturn () => {\n\t\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\t\tnode.removeEventListener( 'mouseleave', onMouseLeave );\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'selectionchange',\n\t\t\t\t\tonSelectionChange\n\t\t\t\t);\n\t\t\t\tdefaultView.removeEventListener( 'mouseup', onSelectionEnd );\n\t\t\t\tdefaultView.cancelAnimationFrame( rafId );\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tclientId,\n\t\t\tstartMultiSelect,\n\t\t\tstopMultiSelect,\n\t\t\tmultiSelect,\n\t\t\tselectBlock,\n\t\t\tisSelectionEnabled,\n\t\t\tisBlockSelected,\n\t\t\tgetBlockParents,\n\t\t]\n\t);\n}\n"]}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.useScrollIntoView = useScrollIntoView;
|
|
9
|
-
|
|
10
|
-
var _domScrollIntoView = _interopRequireDefault(require("dom-scroll-into-view"));
|
|
11
|
-
|
|
12
|
-
var _element = require("@wordpress/element");
|
|
13
|
-
|
|
14
|
-
var _data = require("@wordpress/data");
|
|
15
|
-
|
|
16
|
-
var _dom = require("@wordpress/dom");
|
|
17
|
-
|
|
18
|
-
var _store = require("../../../store");
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* External dependencies
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* WordPress dependencies
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* WordPress dependencies
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Internal dependencies
|
|
34
|
-
*/
|
|
35
|
-
function useScrollIntoView(clientId) {
|
|
36
|
-
const ref = (0, _element.useRef)();
|
|
37
|
-
const isSelectionEnd = (0, _data.useSelect)(select => {
|
|
38
|
-
const {
|
|
39
|
-
isBlockSelected,
|
|
40
|
-
getBlockSelectionEnd
|
|
41
|
-
} = select(_store.store);
|
|
42
|
-
return isBlockSelected(clientId) || getBlockSelectionEnd() === clientId;
|
|
43
|
-
}, [clientId]); // Note that we can't use `useRefEffect` here, since an element change does
|
|
44
|
-
// not mean we can scroll. `isSelectionEnd` should be the sole dependency,
|
|
45
|
-
// while with `useRefEffect`, the element is a dependency as well.
|
|
46
|
-
|
|
47
|
-
(0, _element.useEffect)(() => {
|
|
48
|
-
if (!isSelectionEnd) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const extentNode = ref.current;
|
|
53
|
-
|
|
54
|
-
if (!extentNode) {
|
|
55
|
-
return;
|
|
56
|
-
} // If the block is focused, the browser will already have scrolled into
|
|
57
|
-
// view if necessary.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (extentNode.contains(extentNode.ownerDocument.activeElement)) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const scrollContainer = (0, _dom.getScrollContainer)(extentNode) || extentNode.ownerDocument.defaultView; // If there's no scroll container, it follows that there's no scrollbar
|
|
65
|
-
// and thus there's no need to try to scroll into view.
|
|
66
|
-
|
|
67
|
-
if (!scrollContainer) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
(0, _domScrollIntoView.default)(extentNode, scrollContainer, {
|
|
72
|
-
onlyScrollIfNeeded: true
|
|
73
|
-
});
|
|
74
|
-
}, [isSelectionEnd]);
|
|
75
|
-
return ref;
|
|
76
|
-
}
|
|
77
|
-
//# 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":["useScrollIntoView","clientId","ref","isSelectionEnd","select","isBlockSelected","getBlockSelectionEnd","blockEditorStore","extentNode","current","contains","ownerDocument","activeElement","scrollContainer","defaultView","onlyScrollIfNeeded"],"mappings":";;;;;;;;;AAGA;;AAQA;;AACA;;AACA;;AAKA;;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AACA;AACA;AACA;;AAKA;AACA;AACA;AAGO,SAASA,iBAAT,CAA4BC,QAA5B,EAAuC;AAC7C,QAAMC,GAAG,GAAG,sBAAZ;AACA,QAAMC,cAAc,GAAG,qBACpBC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA,eAAF;AAAmBC,MAAAA;AAAnB,QAA4CF,MAAM,CACvDG,YADuD,CAAxD;AAIA,WACCF,eAAe,CAAEJ,QAAF,CAAf,IACAK,oBAAoB,OAAOL,QAF5B;AAIA,GAVqB,EAWtB,CAAEA,QAAF,CAXsB,CAAvB,CAF6C,CAgB7C;AACA;AACA;;AACA,0BAAW,MAAM;AAChB,QAAK,CAAEE,cAAP,EAAwB;AACvB;AACA;;AAED,UAAMK,UAAU,GAAGN,GAAG,CAACO,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,GACpB,6BAAoBL,UAApB,KACAA,UAAU,CAACG,aAAX,CAAyBG,WAF1B,CAjBgB,CAqBhB;AACA;;AACA,QAAK,CAAED,eAAP,EAAyB;AACxB;AACA;;AAED,oCAAgBL,UAAhB,EAA4BK,eAA5B,EAA6C;AAC5CE,MAAAA,kBAAkB,EAAE;AADwB,KAA7C;AAGA,GA9BD,EA8BG,CAAEZ,cAAF,CA9BH;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,192 +0,0 @@
|
|
|
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
|
-
/**
|
|
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
|
-
|
|
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
|
-
* Sets a multi-selection based on the native selection across blocks.
|
|
25
|
-
*
|
|
26
|
-
* @param {string} clientId Block client ID.
|
|
27
|
-
*/
|
|
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(node => {
|
|
44
|
-
const {
|
|
45
|
-
ownerDocument
|
|
46
|
-
} = node;
|
|
47
|
-
const {
|
|
48
|
-
defaultView
|
|
49
|
-
} = ownerDocument;
|
|
50
|
-
let anchorElement;
|
|
51
|
-
let rafId;
|
|
52
|
-
|
|
53
|
-
function onSelectionChange(_ref) {
|
|
54
|
-
let {
|
|
55
|
-
isSelectionEnd
|
|
56
|
-
} = _ref;
|
|
57
|
-
const selection = defaultView.getSelection(); // If no selection is found, end multi selection and disable the
|
|
58
|
-
// contentEditable wrapper.
|
|
59
|
-
|
|
60
|
-
if (!selection.rangeCount || selection.isCollapsed) {
|
|
61
|
-
setContentEditableWrapper(node, false);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const endClientId = getBlockClientId(selection.focusNode);
|
|
66
|
-
const isSingularSelection = clientId === endClientId;
|
|
67
|
-
|
|
68
|
-
if (isSingularSelection) {
|
|
69
|
-
selectBlock(clientId); // If the selection is complete (on mouse up), and no
|
|
70
|
-
// multiple blocks have been selected, set focus back to the
|
|
71
|
-
// anchor element. if the anchor element contains the
|
|
72
|
-
// selection. Additionally, the contentEditable wrapper can
|
|
73
|
-
// now be disabled again.
|
|
74
|
-
|
|
75
|
-
if (isSelectionEnd) {
|
|
76
|
-
setContentEditableWrapper(node, false);
|
|
77
|
-
|
|
78
|
-
if (selection.rangeCount) {
|
|
79
|
-
const {
|
|
80
|
-
commonAncestorContainer
|
|
81
|
-
} = selection.getRangeAt(0);
|
|
82
|
-
|
|
83
|
-
if (anchorElement.contains(commonAncestorContainer)) {
|
|
84
|
-
anchorElement.focus();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
} else {
|
|
89
|
-
const startPath = [...getBlockParents(clientId), clientId];
|
|
90
|
-
const endPath = [...getBlockParents(endClientId), endClientId];
|
|
91
|
-
const depth = Math.min(startPath.length, endPath.length) - 1;
|
|
92
|
-
multiSelect(startPath[depth], endPath[depth]);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function onSelectionEnd() {
|
|
97
|
-
ownerDocument.removeEventListener('selectionchange', onSelectionChange); // Equivalent to attaching the listener once.
|
|
98
|
-
|
|
99
|
-
defaultView.removeEventListener('mouseup', onSelectionEnd); // The browser selection won't have updated yet at this point,
|
|
100
|
-
// so wait until the next animation frame to get the browser
|
|
101
|
-
// selection.
|
|
102
|
-
|
|
103
|
-
rafId = defaultView.requestAnimationFrame(() => {
|
|
104
|
-
onSelectionChange({
|
|
105
|
-
isSelectionEnd: true
|
|
106
|
-
});
|
|
107
|
-
stopMultiSelect();
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function onMouseLeave(_ref2) {
|
|
112
|
-
let {
|
|
113
|
-
buttons
|
|
114
|
-
} = _ref2;
|
|
115
|
-
|
|
116
|
-
// The primary button must be pressed to initiate selection.
|
|
117
|
-
// See https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
|
|
118
|
-
if (buttons !== 1) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (!isSelectionEnabled() || !isBlockSelected(clientId)) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
anchorElement = ownerDocument.activeElement;
|
|
127
|
-
startMultiSelect(); // `onSelectionStart` is called after `mousedown` and
|
|
128
|
-
// `mouseleave` (from a block). The selection ends when
|
|
129
|
-
// `mouseup` happens anywhere in the window.
|
|
130
|
-
|
|
131
|
-
ownerDocument.addEventListener('selectionchange', onSelectionChange);
|
|
132
|
-
defaultView.addEventListener('mouseup', onSelectionEnd); // Allow cross contentEditable selection by temporarily making
|
|
133
|
-
// all content editable. We can't rely on using the store and
|
|
134
|
-
// React because re-rending happens too slowly. We need to be
|
|
135
|
-
// able to select across instances immediately.
|
|
136
|
-
|
|
137
|
-
setContentEditableWrapper(node, true);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function onMouseDown(event) {
|
|
141
|
-
// The main button.
|
|
142
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
|
|
143
|
-
if (!isSelectionEnabled() || event.button !== 0) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (event.shiftKey) {
|
|
148
|
-
const blockSelectionStart = getBlockSelectionStart(); // By checking `blockSelectionStart` to be set, we handle the
|
|
149
|
-
// case where we select a single block. We also have to check
|
|
150
|
-
// the selectionEnd (clientId) not to be included in the
|
|
151
|
-
// `blockSelectionStart`'s parents because the click event is
|
|
152
|
-
// propagated.
|
|
153
|
-
|
|
154
|
-
const startParents = getBlockParents(blockSelectionStart);
|
|
155
|
-
|
|
156
|
-
if (blockSelectionStart && blockSelectionStart !== clientId && !(startParents !== null && startParents !== void 0 && startParents.includes(clientId))) {
|
|
157
|
-
const startPath = [...startParents, blockSelectionStart];
|
|
158
|
-
const endPath = [...getBlockParents(clientId), clientId];
|
|
159
|
-
const depth = Math.min(startPath.length, endPath.length) - 1;
|
|
160
|
-
const start = startPath[depth];
|
|
161
|
-
const end = endPath[depth]; // Handle the case of having selected a parent block and
|
|
162
|
-
// then shift+click on a child.
|
|
163
|
-
|
|
164
|
-
if (start !== end) {
|
|
165
|
-
setContentEditableWrapper(node, true);
|
|
166
|
-
multiSelect(start, end);
|
|
167
|
-
event.preventDefault();
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
} else if (hasMultiSelection()) {
|
|
171
|
-
// Allow user to escape out of a multi-selection to a
|
|
172
|
-
// singular selection of a block via click. This is handled
|
|
173
|
-
// here since focus handling excludes blocks when there is
|
|
174
|
-
// multiselection, as focus can be incurred by starting a
|
|
175
|
-
// multiselection (focus moved to first block's multi-
|
|
176
|
-
// controls).
|
|
177
|
-
selectBlock(clientId);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
node.addEventListener('mousedown', onMouseDown);
|
|
182
|
-
node.addEventListener('mouseleave', onMouseLeave);
|
|
183
|
-
return () => {
|
|
184
|
-
node.removeEventListener('mousedown', onMouseDown);
|
|
185
|
-
node.removeEventListener('mouseleave', onMouseLeave);
|
|
186
|
-
ownerDocument.removeEventListener('selectionchange', onSelectionChange);
|
|
187
|
-
defaultView.removeEventListener('mouseup', onSelectionEnd);
|
|
188
|
-
defaultView.cancelAnimationFrame(rafId);
|
|
189
|
-
};
|
|
190
|
-
}, [clientId, startMultiSelect, stopMultiSelect, multiSelect, selectBlock, isSelectionEnabled, isBlockSelected, getBlockParents]);
|
|
191
|
-
}
|
|
192
|
-
//# sourceMappingURL=use-multi-selection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-list/use-block-props/use-multi-selection.js"],"names":["useSelect","useDispatch","useRefEffect","store","blockEditorStore","getBlockClientId","setContentEditableWrapper","node","value","parentElement","closest","contentEditable","useMultiSelection","clientId","startMultiSelect","stopMultiSelect","multiSelect","selectBlock","isSelectionEnabled","isBlockSelected","getBlockParents","getBlockSelectionStart","hasMultiSelection","ownerDocument","defaultView","anchorElement","rafId","onSelectionChange","isSelectionEnd","selection","getSelection","rangeCount","isCollapsed","endClientId","focusNode","isSingularSelection","commonAncestorContainer","getRangeAt","contains","focus","startPath","endPath","depth","Math","min","length","onSelectionEnd","removeEventListener","requestAnimationFrame","onMouseLeave","buttons","activeElement","addEventListener","onMouseDown","event","button","shiftKey","blockSelectionStart","startParents","includes","start","end","preventDefault","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,gBAA1C;AACA,SAASC,gBAAT,QAAiC,oBAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,yBAAT,CAAoCC,IAApC,EAA0CC,KAA1C,EAAkD;AACxD;AACAD,EAAAA,IAAI,CAACE,aAAL,CAAmBC,OAAnB,CAA4B,mBAA5B,EAAkDC,eAAlD,GAAoEH,KAApE;AACA;AAED;AACA;AACA;AACA;A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AiCO,IAAKxC,iBAAiB,EAAtB,EAA2B;AACjC;AACA;AACA;AACA;AACA;AACA;AACAL,QAAAA,WAAW,CAAEJ,QAAF,CAAX;AACA;AACD;;AAEDN,IAAAA,IAAI,CAAC6C,gBAAL,CAAuB,WAAvB,EAAoCC,WAApC;AACA9C,IAAAA,IAAI,CAAC6C,gBAAL,CAAuB,YAAvB,EAAqCH,YAArC;AAEA,WAAO,MAAM;AACZ1C,MAAAA,IAAI,CAACwC,mBAAL,CAA0B,WAA1B,EAAuCM,WAAvC;AACA9C,MAAAA,IAAI,CAACwC,mBAAL,CAA0B,YAA1B,EAAwCE,YAAxC;AACA1B,MAAAA,aAAa,CAACwB,mBAAd,CACC,iBADD,EAECpB,iBAFD;AAIAH,MAAAA,WAAW,CAACuB,mBAAZ,CAAiC,SAAjC,EAA4CD,cAA5C;AACAtB,MAAAA,WAAW,CAACuC,oBAAZ,CAAkCrC,KAAlC;AACA,KATD;AAUA,GA5KiB,EA6KlB,CACCb,QADD,EAECC,gBAFD,EAGCC,eAHD,EAICC,WAJD,EAKCC,WALD,EAMCC,kBAND,EAOCC,eAPD,EAQCC,eARD,CA7KkB,CAAnB;AAwLA","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\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 */\nexport function setContentEditableWrapper( node, value ) {\n\t// Since `closest` considers `node` as a candidate, use `parentElement`.\n\tnode.parentElement.closest( '[contenteditable]' ).contentEditable = value;\n}\n\n/**\n * Sets a multi-selection based on the native selection across blocks.\n *\n * @param {string} clientId Block client ID.\n */\nexport function useMultiSelection( clientId ) {\n\tconst {\n\t\tstartMultiSelect,\n\t\tstopMultiSelect,\n\t\tmultiSelect,\n\t\tselectBlock,\n\t} = useDispatch( blockEditorStore );\n\tconst {\n\t\tisSelectionEnabled,\n\t\tisBlockSelected,\n\t\tgetBlockParents,\n\t\tgetBlockSelectionStart,\n\t\thasMultiSelection,\n\t} = useSelect( blockEditorStore );\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 onSelectionChange( { isSelectionEnd } ) {\n\t\t\t\tconst selection = defaultView.getSelection();\n\n\t\t\t\t// If no selection is found, end multi selection and disable the\n\t\t\t\t// contentEditable wrapper.\n\t\t\t\tif ( ! selection.rangeCount || selection.isCollapsed ) {\n\t\t\t\t\tsetContentEditableWrapper( node, false );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst endClientId = getBlockClientId( selection.focusNode );\n\t\t\t\tconst isSingularSelection = clientId === endClientId;\n\n\t\t\t\tif ( isSingularSelection ) {\n\t\t\t\t\tselectBlock( clientId );\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\tif ( isSelectionEnd ) {\n\t\t\t\t\t\tsetContentEditableWrapper( node, false );\n\n\t\t\t\t\t\tif ( selection.rangeCount ) {\n\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\tcommonAncestorContainer,\n\t\t\t\t\t\t\t} = selection.getRangeAt( 0 );\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tanchorElement.contains(\n\t\t\t\t\t\t\t\t\tcommonAncestorContainer\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tanchorElement.focus();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst startPath = [\n\t\t\t\t\t\t...getBlockParents( clientId ),\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t];\n\t\t\t\t\tconst endPath = [\n\t\t\t\t\t\t...getBlockParents( endClientId ),\n\t\t\t\t\t\tendClientId,\n\t\t\t\t\t];\n\t\t\t\t\tconst depth =\n\t\t\t\t\t\tMath.min( startPath.length, endPath.length ) - 1;\n\n\t\t\t\t\tmultiSelect( startPath[ depth ], endPath[ depth ] );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onSelectionEnd() {\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'selectionchange',\n\t\t\t\t\tonSelectionChange\n\t\t\t\t);\n\t\t\t\t// Equivalent to attaching the listener once.\n\t\t\t\tdefaultView.removeEventListener( 'mouseup', onSelectionEnd );\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\tonSelectionChange( { isSelectionEnd: true } );\n\t\t\t\t\tstopMultiSelect();\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tfunction onMouseLeave( { buttons } ) {\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\tif ( ! isSelectionEnabled() || ! isBlockSelected( clientId ) ) {\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\townerDocument.addEventListener(\n\t\t\t\t\t'selectionchange',\n\t\t\t\t\tonSelectionChange\n\t\t\t\t);\n\t\t\t\tdefaultView.addEventListener( 'mouseup', onSelectionEnd );\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\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\tif ( event.shiftKey ) {\n\t\t\t\t\tconst blockSelectionStart = getBlockSelectionStart();\n\t\t\t\t\t// By checking `blockSelectionStart` to be set, we handle the\n\t\t\t\t\t// case where we select a single block. We also have to check\n\t\t\t\t\t// the selectionEnd (clientId) not to be included in the\n\t\t\t\t\t// `blockSelectionStart`'s parents because the click event is\n\t\t\t\t\t// propagated.\n\t\t\t\t\tconst startParents = getBlockParents( blockSelectionStart );\n\t\t\t\t\tif (\n\t\t\t\t\t\tblockSelectionStart &&\n\t\t\t\t\t\tblockSelectionStart !== clientId &&\n\t\t\t\t\t\t! startParents?.includes( clientId )\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst startPath = [\n\t\t\t\t\t\t\t...startParents,\n\t\t\t\t\t\t\tblockSelectionStart,\n\t\t\t\t\t\t];\n\t\t\t\t\t\tconst endPath = [\n\t\t\t\t\t\t\t...getBlockParents( clientId ),\n\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t];\n\t\t\t\t\t\tconst depth =\n\t\t\t\t\t\t\tMath.min( startPath.length, endPath.length ) - 1;\n\t\t\t\t\t\tconst start = startPath[ depth ];\n\t\t\t\t\t\tconst end = endPath[ depth ];\n\t\t\t\t\t\t// Handle the case of having selected a parent block and\n\t\t\t\t\t\t// then shift+click on a child.\n\t\t\t\t\t\tif ( start !== end ) {\n\t\t\t\t\t\t\tsetContentEditableWrapper( node, true );\n\t\t\t\t\t\t\tmultiSelect( start, end );\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t}\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( clientId );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\t\t\tnode.addEventListener( 'mouseleave', onMouseLeave );\n\n\t\t\treturn () => {\n\t\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\t\tnode.removeEventListener( 'mouseleave', onMouseLeave );\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'selectionchange',\n\t\t\t\t\tonSelectionChange\n\t\t\t\t);\n\t\t\t\tdefaultView.removeEventListener( 'mouseup', onSelectionEnd );\n\t\t\t\tdefaultView.cancelAnimationFrame( rafId );\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tclientId,\n\t\t\tstartMultiSelect,\n\t\t\tstopMultiSelect,\n\t\t\tmultiSelect,\n\t\t\tselectBlock,\n\t\t\tisSelectionEnabled,\n\t\t\tisBlockSelected,\n\t\t\tgetBlockParents,\n\t\t]\n\t);\n}\n"]}
|
|
@@ -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"]}
|