@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
package/src/store/reducer.js
CHANGED
|
@@ -1278,17 +1278,24 @@ function selectionHelper( state = {}, action ) {
|
|
|
1278
1278
|
export function selection( state = {}, action ) {
|
|
1279
1279
|
switch ( action.type ) {
|
|
1280
1280
|
case 'SELECTION_CHANGE':
|
|
1281
|
+
if ( action.clientId ) {
|
|
1282
|
+
return {
|
|
1283
|
+
selectionStart: {
|
|
1284
|
+
clientId: action.clientId,
|
|
1285
|
+
attributeKey: action.attributeKey,
|
|
1286
|
+
offset: action.startOffset,
|
|
1287
|
+
},
|
|
1288
|
+
selectionEnd: {
|
|
1289
|
+
clientId: action.clientId,
|
|
1290
|
+
attributeKey: action.attributeKey,
|
|
1291
|
+
offset: action.endOffset,
|
|
1292
|
+
},
|
|
1293
|
+
};
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1281
1296
|
return {
|
|
1282
|
-
selectionStart:
|
|
1283
|
-
|
|
1284
|
-
attributeKey: action.attributeKey,
|
|
1285
|
-
offset: action.startOffset,
|
|
1286
|
-
},
|
|
1287
|
-
selectionEnd: {
|
|
1288
|
-
clientId: action.clientId,
|
|
1289
|
-
attributeKey: action.attributeKey,
|
|
1290
|
-
offset: action.endOffset,
|
|
1291
|
-
},
|
|
1297
|
+
selectionStart: action.start || state.selectionStart,
|
|
1298
|
+
selectionEnd: action.end || state.selectionEnd,
|
|
1292
1299
|
};
|
|
1293
1300
|
case 'RESET_SELECTION':
|
|
1294
1301
|
const { selectionStart, selectionEnd } = action;
|
|
@@ -1298,6 +1305,14 @@ export function selection( state = {}, action ) {
|
|
|
1298
1305
|
};
|
|
1299
1306
|
case 'MULTI_SELECT':
|
|
1300
1307
|
const { start, end } = action;
|
|
1308
|
+
|
|
1309
|
+
if (
|
|
1310
|
+
start === state.selectionStart?.clientId &&
|
|
1311
|
+
end === state.selectionEnd?.clientId
|
|
1312
|
+
) {
|
|
1313
|
+
return state;
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1301
1316
|
return {
|
|
1302
1317
|
selectionStart: { clientId: start },
|
|
1303
1318
|
selectionEnd: { clientId: end },
|
package/src/store/selectors.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import {
|
|
5
5
|
castArray,
|
|
6
|
-
flatMap,
|
|
7
6
|
first,
|
|
8
7
|
isArray,
|
|
9
8
|
isBoolean,
|
|
@@ -28,10 +27,12 @@ import {
|
|
|
28
27
|
hasBlockSupport,
|
|
29
28
|
getPossibleBlockTransformations,
|
|
30
29
|
parse,
|
|
30
|
+
switchToBlockType,
|
|
31
31
|
} from '@wordpress/blocks';
|
|
32
32
|
import { Platform } from '@wordpress/element';
|
|
33
33
|
import { applyFilters } from '@wordpress/hooks';
|
|
34
34
|
import { symbol } from '@wordpress/icons';
|
|
35
|
+
import { __ } from '@wordpress/i18n';
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* A block selection object.
|
|
@@ -215,26 +216,35 @@ export const __unstableGetClientIdsTree = createSelector(
|
|
|
215
216
|
);
|
|
216
217
|
|
|
217
218
|
/**
|
|
218
|
-
* Returns an array containing the clientIds of all descendants
|
|
219
|
-
* of the
|
|
219
|
+
* Returns an array containing the clientIds of all descendants of the blocks
|
|
220
|
+
* given. Returned ids are ordered first by the order of the ids given, then
|
|
221
|
+
* by the order that they appear in the editor.
|
|
220
222
|
*
|
|
221
223
|
* @param {Object} state Global application state.
|
|
222
224
|
* @param {Array} clientIds Array of blocks to inspect.
|
|
223
225
|
*
|
|
224
226
|
* @return {Array} ids of descendants.
|
|
225
227
|
*/
|
|
226
|
-
export const getClientIdsOfDescendants = (
|
|
227
|
-
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
228
|
+
export const getClientIdsOfDescendants = createSelector(
|
|
229
|
+
( state, clientIds ) => {
|
|
230
|
+
const collectedIds = [];
|
|
231
|
+
for ( const givenId of clientIds ) {
|
|
232
|
+
for ( const descendantId of getBlockOrder( state, givenId ) ) {
|
|
233
|
+
collectedIds.push(
|
|
234
|
+
descendantId,
|
|
235
|
+
...getClientIdsOfDescendants( state, [ descendantId ] )
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return collectedIds;
|
|
240
|
+
},
|
|
241
|
+
( state ) => [ state.blocks.order ]
|
|
242
|
+
);
|
|
234
243
|
|
|
235
244
|
/**
|
|
236
|
-
* Returns an array containing the clientIds of the top-level blocks
|
|
237
|
-
*
|
|
245
|
+
* Returns an array containing the clientIds of the top-level blocks and
|
|
246
|
+
* their descendants of any depth (for nested blocks). Ids are returned
|
|
247
|
+
* in the same order that they appear in the editor.
|
|
238
248
|
*
|
|
239
249
|
* @param {Object} state Global application state.
|
|
240
250
|
*
|
|
@@ -242,11 +252,14 @@ export const getClientIdsOfDescendants = ( state, clientIds ) =>
|
|
|
242
252
|
*/
|
|
243
253
|
export const getClientIdsWithDescendants = createSelector(
|
|
244
254
|
( state ) => {
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
255
|
+
const collectedIds = [];
|
|
256
|
+
for ( const topLevelId of getBlockOrder( state ) ) {
|
|
257
|
+
collectedIds.push(
|
|
258
|
+
topLevelId,
|
|
259
|
+
...getClientIdsOfDescendants( state, [ topLevelId ] )
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
return collectedIds;
|
|
250
263
|
},
|
|
251
264
|
( state ) => [ state.blocks.order ]
|
|
252
265
|
);
|
|
@@ -895,6 +908,102 @@ export function getMultiSelectedBlocksEndClientId( state ) {
|
|
|
895
908
|
return selectionEnd.clientId || null;
|
|
896
909
|
}
|
|
897
910
|
|
|
911
|
+
/**
|
|
912
|
+
* Returns true if the selection is not partial.
|
|
913
|
+
*
|
|
914
|
+
* @param {Object} state Editor state.
|
|
915
|
+
*
|
|
916
|
+
* @return {boolean} Whether the selection is mergeable.
|
|
917
|
+
*/
|
|
918
|
+
export function __unstableIsFullySelected( state ) {
|
|
919
|
+
const selectionAnchor = getSelectionStart( state );
|
|
920
|
+
const selectionFocus = getSelectionEnd( state );
|
|
921
|
+
return (
|
|
922
|
+
! selectionAnchor.attributeKey &&
|
|
923
|
+
! selectionFocus.attributeKey &&
|
|
924
|
+
typeof selectionAnchor.offset === 'undefined' &&
|
|
925
|
+
typeof selectionFocus.offset === 'undefined'
|
|
926
|
+
);
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
/**
|
|
930
|
+
* Check whether the selection is mergeable.
|
|
931
|
+
*
|
|
932
|
+
* @param {Object} state Editor state.
|
|
933
|
+
* @param {boolean} isForward Whether to merge forwards.
|
|
934
|
+
*
|
|
935
|
+
* @return {boolean} Whether the selection is mergeable.
|
|
936
|
+
*/
|
|
937
|
+
export function __unstableIsSelectionMergeable( state, isForward ) {
|
|
938
|
+
const selectionAnchor = getSelectionStart( state );
|
|
939
|
+
const selectionFocus = getSelectionEnd( state );
|
|
940
|
+
|
|
941
|
+
// It's not mergeable if the start and end are within the same block.
|
|
942
|
+
if ( selectionAnchor.clientId === selectionFocus.clientId ) return false;
|
|
943
|
+
|
|
944
|
+
// It's not mergeable if there's no rich text selection.
|
|
945
|
+
if (
|
|
946
|
+
! selectionAnchor.attributeKey ||
|
|
947
|
+
! selectionFocus.attributeKey ||
|
|
948
|
+
typeof selectionAnchor.offset === 'undefined' ||
|
|
949
|
+
typeof selectionFocus.offset === 'undefined'
|
|
950
|
+
)
|
|
951
|
+
return false;
|
|
952
|
+
|
|
953
|
+
const anchorRootClientId = getBlockRootClientId(
|
|
954
|
+
state,
|
|
955
|
+
selectionAnchor.clientId
|
|
956
|
+
);
|
|
957
|
+
const focusRootClientId = getBlockRootClientId(
|
|
958
|
+
state,
|
|
959
|
+
selectionFocus.clientId
|
|
960
|
+
);
|
|
961
|
+
|
|
962
|
+
// It's not mergeable if the selection doesn't start and end in the same
|
|
963
|
+
// block list. Maybe in the future it should be allowed.
|
|
964
|
+
if ( anchorRootClientId !== focusRootClientId ) {
|
|
965
|
+
return false;
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
const blockOrder = getBlockOrder( state, anchorRootClientId );
|
|
969
|
+
const anchorIndex = blockOrder.indexOf( selectionAnchor.clientId );
|
|
970
|
+
const focusIndex = blockOrder.indexOf( selectionFocus.clientId );
|
|
971
|
+
|
|
972
|
+
// Reassign selection start and end based on order.
|
|
973
|
+
let selectionStart, selectionEnd;
|
|
974
|
+
|
|
975
|
+
if ( anchorIndex > focusIndex ) {
|
|
976
|
+
selectionStart = selectionFocus;
|
|
977
|
+
selectionEnd = selectionAnchor;
|
|
978
|
+
} else {
|
|
979
|
+
selectionStart = selectionAnchor;
|
|
980
|
+
selectionEnd = selectionFocus;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
const targetBlockClientId = isForward
|
|
984
|
+
? selectionEnd.clientId
|
|
985
|
+
: selectionStart.clientId;
|
|
986
|
+
const blockToMergeClientId = isForward
|
|
987
|
+
? selectionStart.clientId
|
|
988
|
+
: selectionEnd.clientId;
|
|
989
|
+
|
|
990
|
+
const targetBlock = getBlock( state, targetBlockClientId );
|
|
991
|
+
const targetBlockType = getBlockType( targetBlock.name );
|
|
992
|
+
|
|
993
|
+
if ( ! targetBlockType.merge ) return false;
|
|
994
|
+
|
|
995
|
+
const blockToMerge = getBlock( state, blockToMergeClientId );
|
|
996
|
+
|
|
997
|
+
// It's mergeable if the blocks are of the same type.
|
|
998
|
+
if ( blockToMerge.name === targetBlock.name ) return true;
|
|
999
|
+
|
|
1000
|
+
// If the blocks are of a different type, try to transform the block being
|
|
1001
|
+
// merged into the same type of block.
|
|
1002
|
+
const blocksToMerge = switchToBlockType( blockToMerge, targetBlock.name );
|
|
1003
|
+
|
|
1004
|
+
return blocksToMerge && blocksToMerge.length;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
898
1007
|
/**
|
|
899
1008
|
* Returns an array containing all block client IDs in the editor in the order
|
|
900
1009
|
* they appear. Optionally accepts a root client ID of the block list for which
|
|
@@ -1284,10 +1393,28 @@ const canInsertBlockTypeUnmemoized = (
|
|
|
1284
1393
|
parentName
|
|
1285
1394
|
);
|
|
1286
1395
|
|
|
1396
|
+
let hasBlockAllowedAncestor = true;
|
|
1397
|
+
const blockAllowedAncestorBlocks = blockType.ancestor;
|
|
1398
|
+
if ( blockAllowedAncestorBlocks ) {
|
|
1399
|
+
const ancestors = [
|
|
1400
|
+
rootClientId,
|
|
1401
|
+
...getBlockParents( state, rootClientId ),
|
|
1402
|
+
];
|
|
1403
|
+
|
|
1404
|
+
hasBlockAllowedAncestor = some( ancestors, ( ancestorClientId ) =>
|
|
1405
|
+
checkAllowList(
|
|
1406
|
+
blockAllowedAncestorBlocks,
|
|
1407
|
+
getBlockName( state, ancestorClientId )
|
|
1408
|
+
)
|
|
1409
|
+
);
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1287
1412
|
const canInsert =
|
|
1288
|
-
|
|
1289
|
-
hasParentAllowedBlock ===
|
|
1290
|
-
|
|
1413
|
+
hasBlockAllowedAncestor &&
|
|
1414
|
+
( ( hasParentAllowedBlock === null &&
|
|
1415
|
+
hasBlockAllowedParent === null ) ||
|
|
1416
|
+
hasParentAllowedBlock === true ||
|
|
1417
|
+
hasBlockAllowedParent === true );
|
|
1291
1418
|
|
|
1292
1419
|
if ( ! canInsert ) {
|
|
1293
1420
|
return canInsert;
|
|
@@ -1442,6 +1569,23 @@ export function canMoveBlocks( state, clientIds, rootClientId = null ) {
|
|
|
1442
1569
|
);
|
|
1443
1570
|
}
|
|
1444
1571
|
|
|
1572
|
+
/**
|
|
1573
|
+
* Determines if the given block type can be locked/unlocked by a user.
|
|
1574
|
+
*
|
|
1575
|
+
* @param {Object} state Editor state.
|
|
1576
|
+
* @param {(string|Object)} nameOrType Block name or type object.
|
|
1577
|
+
*
|
|
1578
|
+
* @return {boolean} Whether a given block type can be locked/unlocked.
|
|
1579
|
+
*/
|
|
1580
|
+
export function canLockBlockType( state, nameOrType ) {
|
|
1581
|
+
if ( ! hasBlockSupport( nameOrType, 'lock', true ) ) {
|
|
1582
|
+
return false;
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
// Use block editor settings as the default value.
|
|
1586
|
+
return !! state.settings?.canLockBlocks;
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1445
1589
|
/**
|
|
1446
1590
|
* Returns information about how recently and frequently a block has been inserted.
|
|
1447
1591
|
*
|
|
@@ -1767,6 +1911,7 @@ export const getInserterItems = createSelector(
|
|
|
1767
1911
|
*/
|
|
1768
1912
|
export const getBlockTransformItems = createSelector(
|
|
1769
1913
|
( state, blocks, rootClientId = null ) => {
|
|
1914
|
+
const [ sourceBlock ] = blocks;
|
|
1770
1915
|
const buildBlockTypeTransformItem = buildBlockTypeItem( state, {
|
|
1771
1916
|
buildScope: 'transform',
|
|
1772
1917
|
} );
|
|
@@ -1780,20 +1925,32 @@ export const getBlockTransformItems = createSelector(
|
|
|
1780
1925
|
blockTypeTransformItems,
|
|
1781
1926
|
( { name } ) => name
|
|
1782
1927
|
);
|
|
1928
|
+
|
|
1929
|
+
// Consider unwraping the highest priority.
|
|
1930
|
+
itemsByName[ '*' ] = {
|
|
1931
|
+
frecency: +Infinity,
|
|
1932
|
+
id: '*',
|
|
1933
|
+
isDisabled: false,
|
|
1934
|
+
name: '*',
|
|
1935
|
+
title: __( 'Unwrap' ),
|
|
1936
|
+
icon: itemsByName[ sourceBlock.name ]?.icon,
|
|
1937
|
+
};
|
|
1938
|
+
|
|
1783
1939
|
const possibleTransforms = getPossibleBlockTransformations(
|
|
1784
1940
|
blocks
|
|
1785
1941
|
).reduce( ( accumulator, block ) => {
|
|
1786
|
-
if (
|
|
1942
|
+
if ( block === '*' ) {
|
|
1943
|
+
accumulator.push( itemsByName[ '*' ] );
|
|
1944
|
+
} else if ( itemsByName[ block?.name ] ) {
|
|
1787
1945
|
accumulator.push( itemsByName[ block.name ] );
|
|
1788
1946
|
}
|
|
1789
1947
|
return accumulator;
|
|
1790
1948
|
}, [] );
|
|
1791
|
-
|
|
1949
|
+
return orderBy(
|
|
1792
1950
|
possibleTransforms,
|
|
1793
1951
|
( block ) => itemsByName[ block.name ].frecency,
|
|
1794
1952
|
'desc'
|
|
1795
1953
|
);
|
|
1796
|
-
return possibleBlockTransformations;
|
|
1797
1954
|
},
|
|
1798
1955
|
( state, rootClientId ) => [
|
|
1799
1956
|
state.blockListSettings[ rootClientId ],
|
|
@@ -146,6 +146,41 @@ describe( 'selectors', () => {
|
|
|
146
146
|
parent: [ 'core/post-content' ],
|
|
147
147
|
} );
|
|
148
148
|
|
|
149
|
+
registerBlockType( 'core/test-block-ancestor', {
|
|
150
|
+
save: ( props ) => props.attributes.text,
|
|
151
|
+
category: 'text',
|
|
152
|
+
title: 'Test Block required as ancestor',
|
|
153
|
+
icon: 'test',
|
|
154
|
+
keywords: [ 'testing' ],
|
|
155
|
+
} );
|
|
156
|
+
|
|
157
|
+
registerBlockType( 'core/test-block-parent', {
|
|
158
|
+
save: ( props ) => props.attributes.text,
|
|
159
|
+
category: 'text',
|
|
160
|
+
title: 'Test Block required as parent',
|
|
161
|
+
icon: 'test',
|
|
162
|
+
keywords: [ 'testing' ],
|
|
163
|
+
} );
|
|
164
|
+
|
|
165
|
+
registerBlockType( 'core/test-block-requires-ancestor', {
|
|
166
|
+
save: ( props ) => props.attributes.text,
|
|
167
|
+
category: 'text',
|
|
168
|
+
title: 'Test Block that requires ancestor',
|
|
169
|
+
icon: 'test',
|
|
170
|
+
keywords: [ 'testing' ],
|
|
171
|
+
ancestor: [ 'core/test-block-ancestor' ],
|
|
172
|
+
} );
|
|
173
|
+
|
|
174
|
+
registerBlockType( 'core/test-block-requires-ancestor-parent', {
|
|
175
|
+
save: ( props ) => props.attributes.text,
|
|
176
|
+
category: 'text',
|
|
177
|
+
title: 'Test Block that requires both ancestor and parent',
|
|
178
|
+
icon: 'test',
|
|
179
|
+
keywords: [ 'testing' ],
|
|
180
|
+
parent: [ 'core/test-block-parent' ],
|
|
181
|
+
ancestor: [ 'core/test-block-ancestor' ],
|
|
182
|
+
} );
|
|
183
|
+
|
|
149
184
|
setFreeformContentHandlerName( 'core/test-freeform' );
|
|
150
185
|
|
|
151
186
|
cachedSelectors.forEach( ( { clear } ) => clear() );
|
|
@@ -158,6 +193,10 @@ describe( 'selectors', () => {
|
|
|
158
193
|
unregisterBlockType( 'core/test-block-c' );
|
|
159
194
|
unregisterBlockType( 'core/test-freeform' );
|
|
160
195
|
unregisterBlockType( 'core/post-content-child' );
|
|
196
|
+
unregisterBlockType( 'core/test-block-ancestor' );
|
|
197
|
+
unregisterBlockType( 'core/test-block-parent' );
|
|
198
|
+
unregisterBlockType( 'core/test-block-requires-ancestor' );
|
|
199
|
+
unregisterBlockType( 'core/test-block-requires-ancestor-parent' );
|
|
161
200
|
|
|
162
201
|
setFreeformContentHandlerName( undefined );
|
|
163
202
|
} );
|
|
@@ -448,7 +487,7 @@ describe( 'selectors', () => {
|
|
|
448
487
|
} );
|
|
449
488
|
|
|
450
489
|
describe( 'getClientIdsOfDescendants', () => {
|
|
451
|
-
it( 'should return the ids of any descendants, given an array of clientIds', () => {
|
|
490
|
+
it( 'should return the ids of any descendants in sequential order, given an array of clientIds', () => {
|
|
452
491
|
const state = {
|
|
453
492
|
blocks: {
|
|
454
493
|
byClientId: {
|
|
@@ -541,8 +580,8 @@ describe( 'selectors', () => {
|
|
|
541
580
|
getClientIdsOfDescendants( state, [ 'uuid-10' ] )
|
|
542
581
|
).toEqual( [
|
|
543
582
|
'uuid-12',
|
|
544
|
-
'uuid-14',
|
|
545
583
|
'uuid-16',
|
|
584
|
+
'uuid-14',
|
|
546
585
|
'uuid-18',
|
|
547
586
|
'uuid-24',
|
|
548
587
|
'uuid-26',
|
|
@@ -553,7 +592,7 @@ describe( 'selectors', () => {
|
|
|
553
592
|
} );
|
|
554
593
|
|
|
555
594
|
describe( 'getClientIdsWithDescendants', () => {
|
|
556
|
-
it( 'should return the ids for top-level blocks and their descendants of any depth (for nested blocks).', () => {
|
|
595
|
+
it( 'should return the ids for top-level blocks and their descendants of any depth (for nested blocks) in sequential order.', () => {
|
|
557
596
|
const state = {
|
|
558
597
|
blocks: {
|
|
559
598
|
byClientId: {
|
|
@@ -645,15 +684,15 @@ describe( 'selectors', () => {
|
|
|
645
684
|
'uuid-6',
|
|
646
685
|
'uuid-8',
|
|
647
686
|
'uuid-10',
|
|
648
|
-
'uuid-22',
|
|
649
687
|
'uuid-12',
|
|
650
|
-
'uuid-14',
|
|
651
688
|
'uuid-16',
|
|
689
|
+
'uuid-14',
|
|
652
690
|
'uuid-18',
|
|
653
691
|
'uuid-24',
|
|
654
692
|
'uuid-26',
|
|
655
693
|
'uuid-28',
|
|
656
694
|
'uuid-30',
|
|
695
|
+
'uuid-22',
|
|
657
696
|
] );
|
|
658
697
|
} );
|
|
659
698
|
} );
|
|
@@ -2475,6 +2514,198 @@ describe( 'selectors', () => {
|
|
|
2475
2514
|
canInsertBlockType( state, 'core/post-content-child' )
|
|
2476
2515
|
).toBe( true );
|
|
2477
2516
|
} );
|
|
2517
|
+
|
|
2518
|
+
it( 'should allow blocks to be inserted in a descendant of a required ancestor', () => {
|
|
2519
|
+
const state = {
|
|
2520
|
+
blocks: {
|
|
2521
|
+
byClientId: {
|
|
2522
|
+
block1: { name: 'core/test-block-ancestor' },
|
|
2523
|
+
block2: { name: 'core/block' },
|
|
2524
|
+
},
|
|
2525
|
+
attributes: {
|
|
2526
|
+
block1: {},
|
|
2527
|
+
block2: {},
|
|
2528
|
+
},
|
|
2529
|
+
parents: {
|
|
2530
|
+
block2: 'block1',
|
|
2531
|
+
},
|
|
2532
|
+
},
|
|
2533
|
+
blockListSettings: {
|
|
2534
|
+
block1: {},
|
|
2535
|
+
block2: {},
|
|
2536
|
+
},
|
|
2537
|
+
settings: {},
|
|
2538
|
+
};
|
|
2539
|
+
expect(
|
|
2540
|
+
canInsertBlockType(
|
|
2541
|
+
state,
|
|
2542
|
+
'core/test-block-requires-ancestor',
|
|
2543
|
+
'block2'
|
|
2544
|
+
)
|
|
2545
|
+
).toBe( true );
|
|
2546
|
+
} );
|
|
2547
|
+
|
|
2548
|
+
it( 'should allow blocks to be inserted if both parent and ancestor restrictions are met', () => {
|
|
2549
|
+
const state = {
|
|
2550
|
+
blocks: {
|
|
2551
|
+
byClientId: {
|
|
2552
|
+
block1: { name: 'core/test-block-ancestor' },
|
|
2553
|
+
block2: { name: 'core/block' },
|
|
2554
|
+
block3: { name: 'core/test-block-parent' },
|
|
2555
|
+
},
|
|
2556
|
+
attributes: {
|
|
2557
|
+
block1: {},
|
|
2558
|
+
block2: {},
|
|
2559
|
+
block3: {},
|
|
2560
|
+
},
|
|
2561
|
+
parents: {
|
|
2562
|
+
block2: 'block1',
|
|
2563
|
+
block3: 'block2',
|
|
2564
|
+
},
|
|
2565
|
+
},
|
|
2566
|
+
blockListSettings: {
|
|
2567
|
+
block1: {},
|
|
2568
|
+
block2: {},
|
|
2569
|
+
block3: {},
|
|
2570
|
+
},
|
|
2571
|
+
settings: {},
|
|
2572
|
+
};
|
|
2573
|
+
expect(
|
|
2574
|
+
canInsertBlockType(
|
|
2575
|
+
state,
|
|
2576
|
+
'core/test-block-requires-ancestor-parent',
|
|
2577
|
+
'block3'
|
|
2578
|
+
)
|
|
2579
|
+
).toBe( true );
|
|
2580
|
+
} );
|
|
2581
|
+
|
|
2582
|
+
it( 'should deny blocks from being inserted outside a required ancestor', () => {
|
|
2583
|
+
const state = {
|
|
2584
|
+
blocks: {
|
|
2585
|
+
byClientId: {
|
|
2586
|
+
block1: { name: 'core/test-block-ancestor' },
|
|
2587
|
+
block2: { name: 'core/block' },
|
|
2588
|
+
block3: { name: 'core/block' },
|
|
2589
|
+
},
|
|
2590
|
+
attributes: {
|
|
2591
|
+
block1: {},
|
|
2592
|
+
block2: {},
|
|
2593
|
+
block3: {},
|
|
2594
|
+
},
|
|
2595
|
+
parents: {
|
|
2596
|
+
block3: 'block2',
|
|
2597
|
+
},
|
|
2598
|
+
},
|
|
2599
|
+
blockListSettings: {
|
|
2600
|
+
block1: {},
|
|
2601
|
+
block2: {},
|
|
2602
|
+
block3: {},
|
|
2603
|
+
},
|
|
2604
|
+
settings: {},
|
|
2605
|
+
};
|
|
2606
|
+
expect(
|
|
2607
|
+
canInsertBlockType(
|
|
2608
|
+
state,
|
|
2609
|
+
'core/test-block-requires-ancestor',
|
|
2610
|
+
'block3'
|
|
2611
|
+
)
|
|
2612
|
+
).toBe( false );
|
|
2613
|
+
} );
|
|
2614
|
+
|
|
2615
|
+
it( 'should deny blocks from being inserted outside of a required ancestor, even if parent matches', () => {
|
|
2616
|
+
const state = {
|
|
2617
|
+
blocks: {
|
|
2618
|
+
byClientId: {
|
|
2619
|
+
block1: { name: 'core/test-block-ancestor' },
|
|
2620
|
+
block2: { name: 'core/block' },
|
|
2621
|
+
block3: { name: 'core/test-block-parent' },
|
|
2622
|
+
},
|
|
2623
|
+
attributes: {
|
|
2624
|
+
block1: {},
|
|
2625
|
+
block2: {},
|
|
2626
|
+
block3: {},
|
|
2627
|
+
},
|
|
2628
|
+
parents: {
|
|
2629
|
+
block3: 'block2',
|
|
2630
|
+
},
|
|
2631
|
+
},
|
|
2632
|
+
blockListSettings: {
|
|
2633
|
+
block1: {},
|
|
2634
|
+
block2: {},
|
|
2635
|
+
block3: {},
|
|
2636
|
+
},
|
|
2637
|
+
settings: {},
|
|
2638
|
+
};
|
|
2639
|
+
expect(
|
|
2640
|
+
canInsertBlockType(
|
|
2641
|
+
state,
|
|
2642
|
+
'core/test-block-requires-ancestor-parent',
|
|
2643
|
+
'block3'
|
|
2644
|
+
)
|
|
2645
|
+
).toBe( false );
|
|
2646
|
+
} );
|
|
2647
|
+
|
|
2648
|
+
it( 'should deny blocks from being inserted inside ancestor if parent restricts allowedBlocks', () => {
|
|
2649
|
+
const state = {
|
|
2650
|
+
blocks: {
|
|
2651
|
+
byClientId: {
|
|
2652
|
+
block1: { name: 'core/test-block-ancestor' },
|
|
2653
|
+
block2: { name: 'core/block' },
|
|
2654
|
+
},
|
|
2655
|
+
attributes: {
|
|
2656
|
+
block1: {},
|
|
2657
|
+
block2: {},
|
|
2658
|
+
},
|
|
2659
|
+
parents: {
|
|
2660
|
+
block2: 'block1',
|
|
2661
|
+
},
|
|
2662
|
+
},
|
|
2663
|
+
blockListSettings: {
|
|
2664
|
+
block1: {},
|
|
2665
|
+
block2: {
|
|
2666
|
+
allowedBlocks: [],
|
|
2667
|
+
},
|
|
2668
|
+
},
|
|
2669
|
+
settings: {},
|
|
2670
|
+
};
|
|
2671
|
+
expect(
|
|
2672
|
+
canInsertBlockType(
|
|
2673
|
+
state,
|
|
2674
|
+
'core/test-block-requires-ancestor',
|
|
2675
|
+
'block2'
|
|
2676
|
+
)
|
|
2677
|
+
).toBe( false );
|
|
2678
|
+
} );
|
|
2679
|
+
|
|
2680
|
+
it( 'should deny blocks from being inserted inside ancestor if parent restriction is not met', () => {
|
|
2681
|
+
const state = {
|
|
2682
|
+
blocks: {
|
|
2683
|
+
byClientId: {
|
|
2684
|
+
block1: { name: 'core/test-block-ancestor' },
|
|
2685
|
+
block2: { name: 'core/block' },
|
|
2686
|
+
},
|
|
2687
|
+
attributes: {
|
|
2688
|
+
block1: {},
|
|
2689
|
+
block2: {},
|
|
2690
|
+
},
|
|
2691
|
+
parents: {
|
|
2692
|
+
block2: 'block1',
|
|
2693
|
+
},
|
|
2694
|
+
},
|
|
2695
|
+
blockListSettings: {
|
|
2696
|
+
block1: {},
|
|
2697
|
+
block2: {},
|
|
2698
|
+
},
|
|
2699
|
+
settings: {},
|
|
2700
|
+
};
|
|
2701
|
+
expect(
|
|
2702
|
+
canInsertBlockType(
|
|
2703
|
+
state,
|
|
2704
|
+
'core/test-block-requires-ancestor-parent',
|
|
2705
|
+
'block2'
|
|
2706
|
+
)
|
|
2707
|
+
).toBe( false );
|
|
2708
|
+
} );
|
|
2478
2709
|
} );
|
|
2479
2710
|
|
|
2480
2711
|
describe( 'canInsertBlocks', () => {
|
|
@@ -2681,6 +2912,8 @@ describe( 'selectors', () => {
|
|
|
2681
2912
|
'core/test-block-a',
|
|
2682
2913
|
'core/test-block-b',
|
|
2683
2914
|
'core/test-freeform',
|
|
2915
|
+
'core/test-block-ancestor',
|
|
2916
|
+
'core/test-block-parent',
|
|
2684
2917
|
'core/block/1',
|
|
2685
2918
|
'core/block/2',
|
|
2686
2919
|
] );
|
|
@@ -2695,6 +2928,8 @@ describe( 'selectors', () => {
|
|
|
2695
2928
|
'core/test-block-a',
|
|
2696
2929
|
'core/test-block-b',
|
|
2697
2930
|
'core/test-freeform',
|
|
2931
|
+
'core/test-block-ancestor',
|
|
2932
|
+
'core/test-block-parent',
|
|
2698
2933
|
'core/block/1',
|
|
2699
2934
|
'core/block/2',
|
|
2700
2935
|
] );
|
|
@@ -2727,6 +2962,7 @@ describe( 'selectors', () => {
|
|
|
2727
2962
|
},
|
|
2728
2963
|
},
|
|
2729
2964
|
controlledInnerBlocks: {},
|
|
2965
|
+
parents: {},
|
|
2730
2966
|
},
|
|
2731
2967
|
preferences: {
|
|
2732
2968
|
insertUsage: {},
|
|
@@ -2935,6 +3171,7 @@ describe( 'selectors', () => {
|
|
|
2935
3171
|
},
|
|
2936
3172
|
},
|
|
2937
3173
|
controlledInnerBlocks: {},
|
|
3174
|
+
parents: {},
|
|
2938
3175
|
},
|
|
2939
3176
|
preferences: {
|
|
2940
3177
|
insertUsage: {},
|
package/src/utils/dom.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const BLOCK_SELECTOR = '.block-editor-block-list__block';
|
|
2
2
|
const APPENDER_SELECTOR = '.block-list-appender';
|
|
3
|
+
const BLOCK_APPENDER_CLASS = '.block-editor-button-block-appender';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Returns true if two elements are contained within the same block.
|
|
@@ -25,7 +26,7 @@ export function isInSameBlock( a, b ) {
|
|
|
25
26
|
*/
|
|
26
27
|
export function isInsideRootBlock( blockElement, element ) {
|
|
27
28
|
const parentBlock = element.closest(
|
|
28
|
-
[ BLOCK_SELECTOR, APPENDER_SELECTOR ].join( ',' )
|
|
29
|
+
[ BLOCK_SELECTOR, APPENDER_SELECTOR, BLOCK_APPENDER_CLASS ].join( ',' )
|
|
29
30
|
);
|
|
30
31
|
return parentBlock === blockElement;
|
|
31
32
|
}
|