@wordpress/block-editor 12.1.0 → 12.2.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/build/autocompleters/block.js +13 -5
- package/build/autocompleters/block.js.map +1 -1
- package/build/components/block-breadcrumb/index.js +6 -3
- package/build/components/block-breadcrumb/index.js.map +1 -1
- package/build/components/block-editing-mode/index.js +84 -0
- package/build/components/block-editing-mode/index.js.map +1 -0
- package/build/components/block-list/block-list-block-context.js +15 -0
- package/build/components/block-list/block-list-block-context.js.map +1 -0
- package/build/components/block-list/block.js +29 -37
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/block.native.js +14 -22
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/index.native.js +107 -108
- package/build/components/block-list/index.native.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +2 -2
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +7 -5
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-list-appender/index.js +15 -1
- package/build/components/block-list-appender/index.js.map +1 -1
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js +19 -4
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build/components/block-styles/preview-panel.js +1 -2
- package/build/components/block-styles/preview-panel.js.map +1 -1
- package/build/components/block-switcher/block-transformations-menu.js +8 -0
- package/build/components/block-switcher/block-transformations-menu.js.map +1 -1
- package/build/components/block-switcher/block-variation-transformations.js +125 -0
- package/build/components/block-switcher/block-variation-transformations.js.map +1 -0
- package/build/components/block-switcher/index.js +34 -12
- package/build/components/block-switcher/index.js.map +1 -1
- package/build/components/block-switcher/pattern-transformations-menu.js +3 -3
- package/build/components/block-switcher/pattern-transformations-menu.js.map +1 -1
- package/build/components/block-toolbar/index.js +9 -7
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js +5 -3
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/block-tools/insertion-point.js +11 -5
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/convert-to-group-buttons/index.js +7 -2
- package/build/components/convert-to-group-buttons/index.js.map +1 -1
- package/build/components/convert-to-group-buttons/index.native.js +87 -3
- package/build/components/convert-to-group-buttons/index.native.js.map +1 -1
- package/build/components/convert-to-group-buttons/use-convert-to-group-button-props.js +23 -37
- package/build/components/convert-to-group-buttons/use-convert-to-group-button-props.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +3 -2
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/iframe/index.js +14 -7
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/inner-blocks/index.js +2 -1
- package/build/components/inner-blocks/index.js.map +1 -1
- package/build/components/inner-blocks/index.native.js +7 -7
- package/build/components/inner-blocks/index.native.js.map +1 -1
- package/build/components/inner-blocks/use-nested-settings-update.js +13 -5
- package/build/components/inner-blocks/use-nested-settings-update.js.map +1 -1
- package/build/components/inserter/index.js +3 -7
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inserter/quick-inserter.js +2 -4
- package/build/components/inserter/quick-inserter.js.map +1 -1
- package/build/components/inserter/search-results.js +19 -6
- package/build/components/inserter/search-results.js.map +1 -1
- package/build/components/list-view/appender.js +6 -1
- package/build/components/list-view/appender.js.map +1 -1
- package/build/components/list-view/block-contents.js +4 -2
- package/build/components/list-view/block-contents.js.map +1 -1
- package/build/components/list-view/block.js +21 -25
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +1 -3
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/index.js +14 -7
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/use-list-view-client-ids.js +27 -3
- package/build/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build/components/publish-date-time-picker/index.js +0 -2
- package/build/components/publish-date-time-picker/index.js.map +1 -1
- package/build/components/url-input/index.js +3 -0
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +25 -15
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-resize-canvas/index.js +8 -1
- package/build/components/use-resize-canvas/index.js.map +1 -1
- package/build/components/writing-flow/use-arrow-nav.js +13 -7
- package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build/hooks/align.js +3 -7
- package/build/hooks/align.js.map +1 -1
- package/build/hooks/behaviors.js +115 -0
- package/build/hooks/behaviors.js.map +1 -0
- package/build/hooks/dimensions.js +0 -30
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/duotone.js +4 -8
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/index.js +2 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/layout.js +8 -9
- package/build/hooks/layout.js.map +1 -1
- package/build/private-apis.js +4 -7
- package/build/private-apis.js.map +1 -1
- package/build/store/private-actions.js +46 -0
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +88 -0
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +36 -1
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +28 -18
- package/build/store/selectors.js.map +1 -1
- package/build/utils/order-inserter-block-items.js +41 -0
- package/build/utils/order-inserter-block-items.js.map +1 -0
- package/build-module/autocompleters/block.js +12 -5
- package/build-module/autocompleters/block.js.map +1 -1
- package/build-module/components/block-breadcrumb/index.js +5 -3
- package/build-module/components/block-breadcrumb/index.js.map +1 -1
- package/build-module/components/block-editing-mode/index.js +72 -0
- package/build-module/components/block-editing-mode/index.js.map +1 -0
- package/build-module/components/block-list/block-list-block-context.js +6 -0
- package/build-module/components/block-list/block-list-block-context.js.map +1 -0
- package/build-module/components/block-list/block.js +26 -34
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/block.native.js +14 -22
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/index.native.js +108 -110
- package/build-module/components/block-list/index.native.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +1 -1
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +6 -5
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-list-appender/index.js +15 -1
- package/build-module/components/block-list-appender/index.js.map +1 -1
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js +18 -4
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build-module/components/block-styles/preview-panel.js +1 -2
- package/build-module/components/block-styles/preview-panel.js.map +1 -1
- package/build-module/components/block-switcher/block-transformations-menu.js +7 -0
- package/build-module/components/block-switcher/block-transformations-menu.js.map +1 -1
- package/build-module/components/block-switcher/block-variation-transformations.js +108 -0
- package/build-module/components/block-switcher/block-variation-transformations.js.map +1 -0
- package/build-module/components/block-switcher/index.js +33 -12
- package/build-module/components/block-switcher/index.js.map +1 -1
- package/build-module/components/block-switcher/pattern-transformations-menu.js +3 -3
- package/build-module/components/block-switcher/pattern-transformations-menu.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +8 -7
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js +4 -3
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/block-tools/insertion-point.js +11 -5
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/convert-to-group-buttons/index.js +7 -2
- package/build-module/components/convert-to-group-buttons/index.js.map +1 -1
- package/build-module/components/convert-to-group-buttons/index.native.js +76 -1
- package/build-module/components/convert-to-group-buttons/index.native.js.map +1 -1
- package/build-module/components/convert-to-group-buttons/use-convert-to-group-button-props.js +22 -36
- package/build-module/components/convert-to-group-buttons/use-convert-to-group-button-props.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +3 -2
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/iframe/index.js +15 -8
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/inner-blocks/index.js +2 -1
- package/build-module/components/inner-blocks/index.js.map +1 -1
- package/build-module/components/inner-blocks/index.native.js +7 -6
- package/build-module/components/inner-blocks/index.native.js.map +1 -1
- package/build-module/components/inner-blocks/use-nested-settings-update.js +13 -5
- package/build-module/components/inner-blocks/use-nested-settings-update.js.map +1 -1
- package/build-module/components/inserter/index.js +3 -7
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inserter/quick-inserter.js +2 -4
- package/build-module/components/inserter/quick-inserter.js.map +1 -1
- package/build-module/components/inserter/search-results.js +16 -6
- package/build-module/components/inserter/search-results.js.map +1 -1
- package/build-module/components/list-view/appender.js +6 -2
- package/build-module/components/list-view/appender.js.map +1 -1
- package/build-module/components/list-view/block-contents.js +4 -2
- package/build-module/components/list-view/block-contents.js.map +1 -1
- package/build-module/components/list-view/block.js +20 -25
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +1 -3
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/index.js +15 -8
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/use-list-view-client-ids.js +26 -3
- package/build-module/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build-module/components/publish-date-time-picker/index.js +0 -2
- package/build-module/components/publish-date-time-picker/index.js.map +1 -1
- package/build-module/components/url-input/index.js +3 -0
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +25 -16
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-resize-canvas/index.js +8 -1
- package/build-module/components/use-resize-canvas/index.js.map +1 -1
- package/build-module/components/writing-flow/use-arrow-nav.js +13 -7
- package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build-module/hooks/align.js +3 -6
- package/build-module/hooks/align.js.map +1 -1
- package/build-module/hooks/behaviors.js +97 -0
- package/build-module/hooks/behaviors.js.map +1 -0
- package/build-module/hooks/dimensions.js +0 -28
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/duotone.js +3 -6
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/layout.js +7 -9
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/private-apis.js +3 -5
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/private-actions.js +42 -0
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +79 -0
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +34 -1
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +26 -17
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/order-inserter-block-items.js +32 -0
- package/build-module/utils/order-inserter-block-items.js.map +1 -0
- package/build-style/content-rtl.css +32 -13
- package/build-style/content.css +32 -13
- package/build-style/default-editor-styles-rtl.css +1 -1
- package/build-style/default-editor-styles.css +1 -1
- package/build-style/style-rtl.css +19 -64
- package/build-style/style.css +20 -64
- package/package.json +32 -31
- package/src/autocompleters/block.js +15 -7
- package/src/components/block-breadcrumb/index.js +11 -3
- package/src/components/block-editing-mode/index.js +71 -0
- package/src/components/block-list/block-list-block-context.js +6 -0
- package/src/components/block-list/block.js +38 -56
- package/src/components/block-list/block.native.js +30 -41
- package/src/components/block-list/content.scss +5 -5
- package/src/components/block-list/index.native.js +164 -153
- package/src/components/block-list/test/index.native.js +2 -2
- package/src/components/block-list/use-block-props/index.js +1 -1
- package/src/components/block-list/use-in-between-inserter.js +7 -3
- package/src/components/block-list-appender/index.js +22 -4
- package/src/components/block-mobile-toolbar/block-actions-menu.native.js +23 -0
- package/src/components/block-mover/style.scss +1 -0
- package/src/components/block-styles/preview-panel.js +1 -3
- package/src/components/block-switcher/block-transformations-menu.js +12 -0
- package/src/components/block-switcher/block-variation-transformations.js +115 -0
- package/src/components/block-switcher/index.js +38 -5
- package/src/components/block-switcher/pattern-transformations-menu.js +5 -5
- package/src/components/block-switcher/style.scss +6 -5
- package/src/components/block-toolbar/index.js +10 -11
- package/src/components/block-tools/block-contextual-toolbar.js +4 -5
- package/src/components/block-tools/insertion-point.js +23 -9
- package/src/components/button-block-appender/content.scss +22 -0
- package/src/components/convert-to-group-buttons/index.js +9 -2
- package/src/components/convert-to-group-buttons/index.native.js +79 -1
- package/src/components/convert-to-group-buttons/use-convert-to-group-button-props.js +32 -38
- package/src/components/global-styles/dimensions-panel.js +3 -2
- package/src/components/global-styles/style.scss +3 -0
- package/src/components/iframe/index.js +22 -12
- package/src/components/inner-blocks/README.md +5 -0
- package/src/components/inner-blocks/index.js +2 -0
- package/src/components/inner-blocks/index.native.js +16 -6
- package/src/components/inner-blocks/use-nested-settings-update.js +20 -3
- package/src/components/inserter/index.js +1 -9
- package/src/components/inserter/quick-inserter.js +0 -2
- package/src/components/inserter/search-results.js +32 -6
- package/src/components/list-view/appender.js +3 -2
- package/src/components/list-view/block-contents.js +8 -2
- package/src/components/list-view/block.js +29 -35
- package/src/components/list-view/branch.js +1 -7
- package/src/components/list-view/index.js +17 -4
- package/src/components/list-view/style.scss +2 -5
- package/src/components/list-view/use-list-view-client-ids.js +21 -4
- package/src/components/publish-date-time-picker/index.js +0 -2
- package/src/components/url-input/README.md +6 -0
- package/src/components/url-input/index.js +1 -0
- package/src/components/use-block-drop-zone/index.js +31 -17
- package/src/components/use-resize-canvas/index.js +9 -1
- package/src/components/writing-flow/test/index.js +15 -0
- package/src/components/writing-flow/use-arrow-nav.js +17 -4
- package/src/hooks/align.js +3 -11
- package/src/hooks/behaviors.js +104 -0
- package/src/hooks/dimensions.js +0 -40
- package/src/hooks/duotone.js +3 -11
- package/src/hooks/index.js +1 -0
- package/src/hooks/layout.js +10 -18
- package/src/private-apis.js +2 -4
- package/src/store/private-actions.js +39 -0
- package/src/store/private-selectors.js +95 -0
- package/src/store/reducer.js +27 -0
- package/src/store/selectors.js +25 -15
- package/src/store/test/private-actions.js +32 -1
- package/src/store/test/private-selectors.js +158 -0
- package/src/store/test/reducer.js +48 -0
- package/src/style.scss +0 -3
- package/src/utils/order-inserter-block-items.js +26 -0
- package/build/components/block-list/block-list-compact.native.js +0 -75
- package/build/components/block-list/block-list-compact.native.js.map +0 -1
- package/build/components/off-canvas-editor/appender.js +0 -125
- package/build/components/off-canvas-editor/appender.js.map +0 -1
- package/build/components/off-canvas-editor/block-contents.js +0 -141
- package/build/components/off-canvas-editor/block-contents.js.map +0 -1
- package/build/components/off-canvas-editor/block-select-button.js +0 -126
- package/build/components/off-canvas-editor/block-select-button.js.map +0 -1
- package/build/components/off-canvas-editor/block.js +0 -297
- package/build/components/off-canvas-editor/block.js.map +0 -1
- package/build/components/off-canvas-editor/branch.js +0 -197
- package/build/components/off-canvas-editor/branch.js.map +0 -1
- package/build/components/off-canvas-editor/context.js +0 -19
- package/build/components/off-canvas-editor/context.js.map +0 -1
- package/build/components/off-canvas-editor/drop-indicator.js +0 -118
- package/build/components/off-canvas-editor/drop-indicator.js.map +0 -1
- package/build/components/off-canvas-editor/expander.js +0 -41
- package/build/components/off-canvas-editor/expander.js.map +0 -1
- package/build/components/off-canvas-editor/index.js +0 -236
- package/build/components/off-canvas-editor/index.js.map +0 -1
- package/build/components/off-canvas-editor/leaf-more-menu.js +0 -148
- package/build/components/off-canvas-editor/leaf-more-menu.js.map +0 -1
- package/build/components/off-canvas-editor/leaf.js +0 -60
- package/build/components/off-canvas-editor/leaf.js.map +0 -1
- package/build/components/off-canvas-editor/link-ui.js +0 -186
- package/build/components/off-canvas-editor/link-ui.js.map +0 -1
- package/build/components/off-canvas-editor/update-attributes.js +0 -108
- package/build/components/off-canvas-editor/update-attributes.js.map +0 -1
- package/build/components/off-canvas-editor/use-block-selection.js +0 -139
- package/build/components/off-canvas-editor/use-block-selection.js.map +0 -1
- package/build/components/off-canvas-editor/use-inserted-block.js +0 -58
- package/build/components/off-canvas-editor/use-inserted-block.js.map +0 -1
- package/build/components/off-canvas-editor/use-list-view-client-ids.js +0 -33
- package/build/components/off-canvas-editor/use-list-view-client-ids.js.map +0 -1
- package/build/components/off-canvas-editor/use-list-view-drop-zone.js +0 -235
- package/build/components/off-canvas-editor/use-list-view-drop-zone.js.map +0 -1
- package/build/components/off-canvas-editor/use-list-view-expand-selected-item.js +0 -60
- package/build/components/off-canvas-editor/use-list-view-expand-selected-item.js.map +0 -1
- package/build/components/off-canvas-editor/utils.js +0 -60
- package/build/components/off-canvas-editor/utils.js.map +0 -1
- package/build-module/components/block-list/block-list-compact.native.js +0 -60
- package/build-module/components/block-list/block-list-compact.native.js.map +0 -1
- package/build-module/components/off-canvas-editor/appender.js +0 -108
- package/build-module/components/off-canvas-editor/appender.js.map +0 -1
- package/build-module/components/off-canvas-editor/block-contents.js +0 -121
- package/build-module/components/off-canvas-editor/block-contents.js.map +0 -1
- package/build-module/components/off-canvas-editor/block-select-button.js +0 -107
- package/build-module/components/off-canvas-editor/block-select-button.js.map +0 -1
- package/build-module/components/off-canvas-editor/block.js +0 -273
- package/build-module/components/off-canvas-editor/block.js.map +0 -1
- package/build-module/components/off-canvas-editor/branch.js +0 -179
- package/build-module/components/off-canvas-editor/branch.js.map +0 -1
- package/build-module/components/off-canvas-editor/context.js +0 -7
- package/build-module/components/off-canvas-editor/context.js.map +0 -1
- package/build-module/components/off-canvas-editor/drop-indicator.js +0 -111
- package/build-module/components/off-canvas-editor/drop-indicator.js.map +0 -1
- package/build-module/components/off-canvas-editor/expander.js +0 -32
- package/build-module/components/off-canvas-editor/expander.js.map +0 -1
- package/build-module/components/off-canvas-editor/index.js +0 -213
- package/build-module/components/off-canvas-editor/index.js.map +0 -1
- package/build-module/components/off-canvas-editor/leaf-more-menu.js +0 -130
- package/build-module/components/off-canvas-editor/leaf-more-menu.js.map +0 -1
- package/build-module/components/off-canvas-editor/leaf.js +0 -45
- package/build-module/components/off-canvas-editor/leaf.js.map +0 -1
- package/build-module/components/off-canvas-editor/link-ui.js +0 -166
- package/build-module/components/off-canvas-editor/link-ui.js.map +0 -1
- package/build-module/components/off-canvas-editor/update-attributes.js +0 -97
- package/build-module/components/off-canvas-editor/update-attributes.js.map +0 -1
- package/build-module/components/off-canvas-editor/use-block-selection.js +0 -124
- package/build-module/components/off-canvas-editor/use-block-selection.js.map +0 -1
- package/build-module/components/off-canvas-editor/use-inserted-block.js +0 -47
- package/build-module/components/off-canvas-editor/use-inserted-block.js.map +0 -1
- package/build-module/components/off-canvas-editor/use-list-view-client-ids.js +0 -24
- package/build-module/components/off-canvas-editor/use-list-view-client-ids.js.map +0 -1
- package/build-module/components/off-canvas-editor/use-list-view-drop-zone.js +0 -220
- package/build-module/components/off-canvas-editor/use-list-view-drop-zone.js.map +0 -1
- package/build-module/components/off-canvas-editor/use-list-view-expand-selected-item.js +0 -50
- package/build-module/components/off-canvas-editor/use-list-view-expand-selected-item.js.map +0 -1
- package/build-module/components/off-canvas-editor/utils.js +0 -44
- package/build-module/components/off-canvas-editor/utils.js.map +0 -1
- package/src/components/block-list/block-list-compact.native.js +0 -63
- package/src/components/off-canvas-editor/README.md +0 -5
- package/src/components/off-canvas-editor/appender.js +0 -124
- package/src/components/off-canvas-editor/block-contents.js +0 -156
- package/src/components/off-canvas-editor/block-select-button.js +0 -128
- package/src/components/off-canvas-editor/block.js +0 -347
- package/src/components/off-canvas-editor/branch.js +0 -238
- package/src/components/off-canvas-editor/context.js +0 -8
- package/src/components/off-canvas-editor/drop-indicator.js +0 -126
- package/src/components/off-canvas-editor/expander.js +0 -26
- package/src/components/off-canvas-editor/index.js +0 -271
- package/src/components/off-canvas-editor/leaf-more-menu.js +0 -158
- package/src/components/off-canvas-editor/leaf.js +0 -52
- package/src/components/off-canvas-editor/link-ui.js +0 -167
- package/src/components/off-canvas-editor/style.scss +0 -34
- package/src/components/off-canvas-editor/test/use-inserted-block.js +0 -108
- package/src/components/off-canvas-editor/test/utils.js +0 -50
- package/src/components/off-canvas-editor/update-attributes.js +0 -99
- package/src/components/off-canvas-editor/use-block-selection.js +0 -169
- package/src/components/off-canvas-editor/use-inserted-block.js +0 -47
- package/src/components/off-canvas-editor/use-list-view-client-ids.js +0 -29
- package/src/components/off-canvas-editor/use-list-view-drop-zone.js +0 -260
- package/src/components/off-canvas-editor/use-list-view-expand-selected-item.js +0 -58
- package/src/components/off-canvas-editor/utils.js +0 -58
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { speak } from '@wordpress/a11y';
|
|
5
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
6
|
-
import { useDispatch, useSelect } from '@wordpress/data';
|
|
7
|
-
import { useCallback } from '@wordpress/element';
|
|
8
|
-
import { UP, DOWN, HOME, END } from '@wordpress/keycodes';
|
|
9
|
-
import { store as blocksStore } from '@wordpress/blocks';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
import { store as blockEditorStore } from '../../store';
|
|
15
|
-
import { getCommonDepthClientIds } from './utils';
|
|
16
|
-
|
|
17
|
-
export default function useBlockSelection() {
|
|
18
|
-
const { clearSelectedBlock, multiSelect, selectBlock } =
|
|
19
|
-
useDispatch( blockEditorStore );
|
|
20
|
-
const {
|
|
21
|
-
getBlockName,
|
|
22
|
-
getBlockParents,
|
|
23
|
-
getBlockSelectionStart,
|
|
24
|
-
getBlockSelectionEnd,
|
|
25
|
-
getSelectedBlockClientIds,
|
|
26
|
-
hasMultiSelection,
|
|
27
|
-
hasSelectedBlock,
|
|
28
|
-
} = useSelect( blockEditorStore );
|
|
29
|
-
|
|
30
|
-
const { getBlockType } = useSelect( blocksStore );
|
|
31
|
-
|
|
32
|
-
const updateBlockSelection = useCallback(
|
|
33
|
-
async ( event, clientId, destinationClientId ) => {
|
|
34
|
-
if ( ! event?.shiftKey ) {
|
|
35
|
-
selectBlock( clientId );
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// To handle multiple block selection via the `SHIFT` key, prevent
|
|
40
|
-
// the browser default behavior of opening the link in a new window.
|
|
41
|
-
event.preventDefault();
|
|
42
|
-
|
|
43
|
-
const isKeyPress =
|
|
44
|
-
event.type === 'keydown' &&
|
|
45
|
-
( event.keyCode === UP ||
|
|
46
|
-
event.keyCode === DOWN ||
|
|
47
|
-
event.keyCode === HOME ||
|
|
48
|
-
event.keyCode === END );
|
|
49
|
-
|
|
50
|
-
// Handle clicking on a block when no blocks are selected, and return early.
|
|
51
|
-
if (
|
|
52
|
-
! isKeyPress &&
|
|
53
|
-
! hasSelectedBlock() &&
|
|
54
|
-
! hasMultiSelection()
|
|
55
|
-
) {
|
|
56
|
-
selectBlock( clientId, null );
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const selectedBlocks = getSelectedBlockClientIds();
|
|
61
|
-
const clientIdWithParents = [
|
|
62
|
-
...getBlockParents( clientId ),
|
|
63
|
-
clientId,
|
|
64
|
-
];
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
isKeyPress &&
|
|
68
|
-
! selectedBlocks.some( ( blockId ) =>
|
|
69
|
-
clientIdWithParents.includes( blockId )
|
|
70
|
-
)
|
|
71
|
-
) {
|
|
72
|
-
// Ensure that shift-selecting blocks via the keyboard only
|
|
73
|
-
// expands the current selection if focusing over already
|
|
74
|
-
// selected blocks. Otherwise, clear the selection so that
|
|
75
|
-
// a user can create a new selection entirely by keyboard.
|
|
76
|
-
await clearSelectedBlock();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
let startTarget = getBlockSelectionStart();
|
|
80
|
-
let endTarget = clientId;
|
|
81
|
-
|
|
82
|
-
// Handle keyboard behavior for selecting multiple blocks.
|
|
83
|
-
if ( isKeyPress ) {
|
|
84
|
-
if ( ! hasSelectedBlock() && ! hasMultiSelection() ) {
|
|
85
|
-
// Set the starting point of the selection to the currently
|
|
86
|
-
// focused block, if there are no blocks currently selected.
|
|
87
|
-
// This ensures that as the selection is expanded or contracted,
|
|
88
|
-
// the starting point of the selection is anchored to that block.
|
|
89
|
-
startTarget = clientId;
|
|
90
|
-
}
|
|
91
|
-
if ( destinationClientId ) {
|
|
92
|
-
// If the user presses UP or DOWN, we want to ensure that the block they're
|
|
93
|
-
// moving to is the target for selection, and not the currently focused one.
|
|
94
|
-
endTarget = destinationClientId;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const startParents = getBlockParents( startTarget );
|
|
99
|
-
const endParents = getBlockParents( endTarget );
|
|
100
|
-
|
|
101
|
-
const { start, end } = getCommonDepthClientIds(
|
|
102
|
-
startTarget,
|
|
103
|
-
endTarget,
|
|
104
|
-
startParents,
|
|
105
|
-
endParents
|
|
106
|
-
);
|
|
107
|
-
await multiSelect( start, end, null );
|
|
108
|
-
|
|
109
|
-
// Announce deselected block, or number of deselected blocks if
|
|
110
|
-
// the total number of blocks deselected is greater than one.
|
|
111
|
-
const updatedSelectedBlocks = getSelectedBlockClientIds();
|
|
112
|
-
|
|
113
|
-
// If the selection is greater than 1 and the Home or End keys
|
|
114
|
-
// were used to generate the selection, then skip announcing the
|
|
115
|
-
// deselected blocks.
|
|
116
|
-
if (
|
|
117
|
-
( event.keyCode === HOME || event.keyCode === END ) &&
|
|
118
|
-
updatedSelectedBlocks.length > 1
|
|
119
|
-
) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const selectionDiff = selectedBlocks.filter(
|
|
124
|
-
( blockId ) => ! updatedSelectedBlocks.includes( blockId )
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
let label;
|
|
128
|
-
if ( selectionDiff.length === 1 ) {
|
|
129
|
-
const title = getBlockType(
|
|
130
|
-
getBlockName( selectionDiff[ 0 ] )
|
|
131
|
-
)?.title;
|
|
132
|
-
if ( title ) {
|
|
133
|
-
label = sprintf(
|
|
134
|
-
/* translators: %s: block name */
|
|
135
|
-
__( '%s deselected.' ),
|
|
136
|
-
title
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
} else if ( selectionDiff.length > 1 ) {
|
|
140
|
-
label = sprintf(
|
|
141
|
-
/* translators: %s: number of deselected blocks */
|
|
142
|
-
__( '%s blocks deselected.' ),
|
|
143
|
-
selectionDiff.length
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if ( label ) {
|
|
148
|
-
speak( label );
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
[
|
|
152
|
-
clearSelectedBlock,
|
|
153
|
-
getBlockName,
|
|
154
|
-
getBlockType,
|
|
155
|
-
getBlockParents,
|
|
156
|
-
getBlockSelectionStart,
|
|
157
|
-
getBlockSelectionEnd,
|
|
158
|
-
getSelectedBlockClientIds,
|
|
159
|
-
hasMultiSelection,
|
|
160
|
-
hasSelectedBlock,
|
|
161
|
-
multiSelect,
|
|
162
|
-
selectBlock,
|
|
163
|
-
]
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
return {
|
|
167
|
-
updateBlockSelection,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { store as blockEditorStore } from '../../store';
|
|
10
|
-
|
|
11
|
-
export const useInsertedBlock = ( insertedBlockClientId ) => {
|
|
12
|
-
const { insertedBlockAttributes, insertedBlockName } = useSelect(
|
|
13
|
-
( select ) => {
|
|
14
|
-
const { getBlockName, getBlockAttributes } =
|
|
15
|
-
select( blockEditorStore );
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
insertedBlockAttributes: getBlockAttributes(
|
|
19
|
-
insertedBlockClientId
|
|
20
|
-
),
|
|
21
|
-
insertedBlockName: getBlockName( insertedBlockClientId ),
|
|
22
|
-
};
|
|
23
|
-
},
|
|
24
|
-
[ insertedBlockClientId ]
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
const { updateBlockAttributes } = useDispatch( blockEditorStore );
|
|
28
|
-
|
|
29
|
-
const setInsertedBlockAttributes = ( _updatedAttributes ) => {
|
|
30
|
-
if ( ! insertedBlockClientId ) return;
|
|
31
|
-
updateBlockAttributes( insertedBlockClientId, _updatedAttributes );
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
if ( ! insertedBlockClientId ) {
|
|
35
|
-
return {
|
|
36
|
-
insertedBlockAttributes: undefined,
|
|
37
|
-
insertedBlockName: undefined,
|
|
38
|
-
setInsertedBlockAttributes,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
insertedBlockAttributes,
|
|
44
|
-
insertedBlockName,
|
|
45
|
-
setInsertedBlockAttributes,
|
|
46
|
-
};
|
|
47
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { useSelect } from '@wordpress/data';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
import { store as blockEditorStore } from '../../store';
|
|
11
|
-
|
|
12
|
-
export default function useListViewClientIds( blocks ) {
|
|
13
|
-
return useSelect(
|
|
14
|
-
( select ) => {
|
|
15
|
-
const {
|
|
16
|
-
getDraggedBlockClientIds,
|
|
17
|
-
getSelectedBlockClientIds,
|
|
18
|
-
__unstableGetClientIdsTree,
|
|
19
|
-
} = select( blockEditorStore );
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
selectedClientIds: getSelectedBlockClientIds(),
|
|
23
|
-
draggedClientIds: getDraggedBlockClientIds(),
|
|
24
|
-
clientIdsTree: blocks ? blocks : __unstableGetClientIdsTree(),
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
[ blocks ]
|
|
28
|
-
);
|
|
29
|
-
}
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useSelect } from '@wordpress/data';
|
|
5
|
-
import { useState, useCallback } from '@wordpress/element';
|
|
6
|
-
import {
|
|
7
|
-
useThrottle,
|
|
8
|
-
__experimentalUseDropZone as useDropZone,
|
|
9
|
-
} from '@wordpress/compose';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
import {
|
|
15
|
-
getDistanceToNearestEdge,
|
|
16
|
-
isPointContainedByRect,
|
|
17
|
-
} from '../../utils/math';
|
|
18
|
-
import useOnBlockDrop from '../use-on-block-drop';
|
|
19
|
-
import { store as blockEditorStore } from '../../store';
|
|
20
|
-
|
|
21
|
-
/** @typedef {import('../../utils/math').WPPoint} WPPoint */
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* The type of a drag event.
|
|
25
|
-
*
|
|
26
|
-
* @typedef {'default'|'file'|'html'} WPDragEventType
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* An array representing data for blocks in the DOM used by drag and drop.
|
|
31
|
-
*
|
|
32
|
-
* @typedef {Object} WPListViewDropZoneBlocks
|
|
33
|
-
* @property {string} clientId The client id for the block.
|
|
34
|
-
* @property {string} rootClientId The root client id for the block.
|
|
35
|
-
* @property {number} blockIndex The block's index.
|
|
36
|
-
* @property {Element} element The DOM element representing the block.
|
|
37
|
-
* @property {number} innerBlockCount The number of inner blocks the block has.
|
|
38
|
-
* @property {boolean} isDraggedBlock Whether the block is currently being dragged.
|
|
39
|
-
* @property {boolean} canInsertDraggedBlocksAsSibling Whether the dragged block can be a sibling of this block.
|
|
40
|
-
* @property {boolean} canInsertDraggedBlocksAsChild Whether the dragged block can be a child of this block.
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* An object containing details of a drop target.
|
|
45
|
-
*
|
|
46
|
-
* @typedef {Object} WPListViewDropZoneTarget
|
|
47
|
-
* @property {string} blockIndex The insertion index.
|
|
48
|
-
* @property {string} rootClientId The root client id for the block.
|
|
49
|
-
* @property {string|undefined} clientId The client id for the block.
|
|
50
|
-
* @property {'top'|'bottom'|'inside'} dropPosition The position relative to the block that the user is dropping to.
|
|
51
|
-
* 'inside' refers to nesting as an inner block.
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Determines whether the user positioning the dragged block to nest as an
|
|
56
|
-
* inner block.
|
|
57
|
-
*
|
|
58
|
-
* Presently this is determined by whether the cursor is on the right hand side
|
|
59
|
-
* of the block.
|
|
60
|
-
*
|
|
61
|
-
* @param {WPPoint} point The point representing the cursor position when dragging.
|
|
62
|
-
* @param {DOMRect} rect The rectangle.
|
|
63
|
-
*/
|
|
64
|
-
function isNestingGesture( point, rect ) {
|
|
65
|
-
const blockCenterX = rect.left + rect.width / 2;
|
|
66
|
-
return point.x > blockCenterX;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Block navigation is always a vertical list, so only allow dropping
|
|
70
|
-
// to the above or below a block.
|
|
71
|
-
const ALLOWED_DROP_EDGES = [ 'top', 'bottom' ];
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Given blocks data and the cursor position, compute the drop target.
|
|
75
|
-
*
|
|
76
|
-
* @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.
|
|
77
|
-
* @param {WPPoint} position The point representing the cursor position when dragging.
|
|
78
|
-
*
|
|
79
|
-
* @return {WPListViewDropZoneTarget | undefined} An object containing data about the drop target.
|
|
80
|
-
*/
|
|
81
|
-
function getListViewDropTarget( blocksData, position ) {
|
|
82
|
-
let candidateEdge;
|
|
83
|
-
let candidateBlockData;
|
|
84
|
-
let candidateDistance;
|
|
85
|
-
let candidateRect;
|
|
86
|
-
|
|
87
|
-
for ( const blockData of blocksData ) {
|
|
88
|
-
if ( blockData.isDraggedBlock ) {
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const rect = blockData.element.getBoundingClientRect();
|
|
93
|
-
const [ distance, edge ] = getDistanceToNearestEdge(
|
|
94
|
-
position,
|
|
95
|
-
rect,
|
|
96
|
-
ALLOWED_DROP_EDGES
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
const isCursorWithinBlock = isPointContainedByRect( position, rect );
|
|
100
|
-
if (
|
|
101
|
-
candidateDistance === undefined ||
|
|
102
|
-
distance < candidateDistance ||
|
|
103
|
-
isCursorWithinBlock
|
|
104
|
-
) {
|
|
105
|
-
candidateDistance = distance;
|
|
106
|
-
|
|
107
|
-
const index = blocksData.indexOf( blockData );
|
|
108
|
-
const previousBlockData = blocksData[ index - 1 ];
|
|
109
|
-
|
|
110
|
-
// If dragging near the top of a block and the preceding block
|
|
111
|
-
// is at the same level, use the preceding block as the candidate
|
|
112
|
-
// instead, as later it makes determining a nesting drop easier.
|
|
113
|
-
if (
|
|
114
|
-
edge === 'top' &&
|
|
115
|
-
previousBlockData &&
|
|
116
|
-
previousBlockData.rootClientId === blockData.rootClientId &&
|
|
117
|
-
! previousBlockData.isDraggedBlock
|
|
118
|
-
) {
|
|
119
|
-
candidateBlockData = previousBlockData;
|
|
120
|
-
candidateEdge = 'bottom';
|
|
121
|
-
candidateRect =
|
|
122
|
-
previousBlockData.element.getBoundingClientRect();
|
|
123
|
-
} else {
|
|
124
|
-
candidateBlockData = blockData;
|
|
125
|
-
candidateEdge = edge;
|
|
126
|
-
candidateRect = rect;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// If the mouse position is within the block, break early
|
|
130
|
-
// as the user would intend to drop either before or after
|
|
131
|
-
// this block.
|
|
132
|
-
//
|
|
133
|
-
// This solves an issue where some rows in the list view
|
|
134
|
-
// tree overlap slightly due to sub-pixel rendering.
|
|
135
|
-
if ( isCursorWithinBlock ) {
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if ( ! candidateBlockData ) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const isDraggingBelow = candidateEdge === 'bottom';
|
|
146
|
-
|
|
147
|
-
// If the user is dragging towards the bottom of the block check whether
|
|
148
|
-
// they might be trying to nest the block as a child.
|
|
149
|
-
// If the block already has inner blocks, this should always be treated
|
|
150
|
-
// as nesting since the next block in the tree will be the first child.
|
|
151
|
-
if (
|
|
152
|
-
isDraggingBelow &&
|
|
153
|
-
candidateBlockData.canInsertDraggedBlocksAsChild &&
|
|
154
|
-
( candidateBlockData.innerBlockCount > 0 ||
|
|
155
|
-
isNestingGesture( position, candidateRect ) )
|
|
156
|
-
) {
|
|
157
|
-
return {
|
|
158
|
-
rootClientId: candidateBlockData.clientId,
|
|
159
|
-
blockIndex: 0,
|
|
160
|
-
dropPosition: 'inside',
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// If dropping as a sibling, but block cannot be inserted in
|
|
165
|
-
// this context, return early.
|
|
166
|
-
if ( ! candidateBlockData.canInsertDraggedBlocksAsSibling ) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const offset = isDraggingBelow ? 1 : 0;
|
|
171
|
-
return {
|
|
172
|
-
rootClientId: candidateBlockData.rootClientId,
|
|
173
|
-
clientId: candidateBlockData.clientId,
|
|
174
|
-
blockIndex: candidateBlockData.blockIndex + offset,
|
|
175
|
-
dropPosition: candidateEdge,
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* A react hook for implementing a drop zone in list view.
|
|
181
|
-
*
|
|
182
|
-
* @return {WPListViewDropZoneTarget} The drop target.
|
|
183
|
-
*/
|
|
184
|
-
export default function useListViewDropZone() {
|
|
185
|
-
const {
|
|
186
|
-
getBlockRootClientId,
|
|
187
|
-
getBlockIndex,
|
|
188
|
-
getBlockCount,
|
|
189
|
-
getDraggedBlockClientIds,
|
|
190
|
-
canInsertBlocks,
|
|
191
|
-
} = useSelect( blockEditorStore );
|
|
192
|
-
const [ target, setTarget ] = useState();
|
|
193
|
-
const { rootClientId: targetRootClientId, blockIndex: targetBlockIndex } =
|
|
194
|
-
target || {};
|
|
195
|
-
|
|
196
|
-
const onBlockDrop = useOnBlockDrop( targetRootClientId, targetBlockIndex );
|
|
197
|
-
|
|
198
|
-
const draggedBlockClientIds = getDraggedBlockClientIds();
|
|
199
|
-
const throttled = useThrottle(
|
|
200
|
-
useCallback(
|
|
201
|
-
( event, currentTarget ) => {
|
|
202
|
-
const position = { x: event.clientX, y: event.clientY };
|
|
203
|
-
const isBlockDrag = !! draggedBlockClientIds?.length;
|
|
204
|
-
|
|
205
|
-
const blockElements = Array.from(
|
|
206
|
-
currentTarget.querySelectorAll( '[data-block]' )
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
const blocksData = blockElements.map( ( blockElement ) => {
|
|
210
|
-
const clientId = blockElement.dataset.block;
|
|
211
|
-
const rootClientId = getBlockRootClientId( clientId );
|
|
212
|
-
|
|
213
|
-
return {
|
|
214
|
-
clientId,
|
|
215
|
-
rootClientId,
|
|
216
|
-
blockIndex: getBlockIndex( clientId ),
|
|
217
|
-
element: blockElement,
|
|
218
|
-
isDraggedBlock: isBlockDrag
|
|
219
|
-
? draggedBlockClientIds.includes( clientId )
|
|
220
|
-
: false,
|
|
221
|
-
innerBlockCount: getBlockCount( clientId ),
|
|
222
|
-
canInsertDraggedBlocksAsSibling: isBlockDrag
|
|
223
|
-
? canInsertBlocks(
|
|
224
|
-
draggedBlockClientIds,
|
|
225
|
-
rootClientId
|
|
226
|
-
)
|
|
227
|
-
: true,
|
|
228
|
-
canInsertDraggedBlocksAsChild: isBlockDrag
|
|
229
|
-
? canInsertBlocks( draggedBlockClientIds, clientId )
|
|
230
|
-
: true,
|
|
231
|
-
};
|
|
232
|
-
} );
|
|
233
|
-
|
|
234
|
-
const newTarget = getListViewDropTarget( blocksData, position );
|
|
235
|
-
|
|
236
|
-
if ( newTarget ) {
|
|
237
|
-
setTarget( newTarget );
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
[ draggedBlockClientIds ]
|
|
241
|
-
),
|
|
242
|
-
200
|
|
243
|
-
);
|
|
244
|
-
|
|
245
|
-
const ref = useDropZone( {
|
|
246
|
-
onDrop: onBlockDrop,
|
|
247
|
-
onDragOver( event ) {
|
|
248
|
-
// `currentTarget` is only available while the event is being
|
|
249
|
-
// handled, so get it now and pass it to the thottled function.
|
|
250
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget
|
|
251
|
-
throttled( event, event.currentTarget );
|
|
252
|
-
},
|
|
253
|
-
onDragEnd() {
|
|
254
|
-
throttled.cancel();
|
|
255
|
-
setTarget( null );
|
|
256
|
-
},
|
|
257
|
-
} );
|
|
258
|
-
|
|
259
|
-
return { ref, target };
|
|
260
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useEffect, useState } from '@wordpress/element';
|
|
5
|
-
import { useSelect } from '@wordpress/data';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
import { store as blockEditorStore } from '../../store';
|
|
11
|
-
|
|
12
|
-
export default function useListViewExpandSelectedItem( {
|
|
13
|
-
firstSelectedBlockClientId,
|
|
14
|
-
setExpandedState,
|
|
15
|
-
} ) {
|
|
16
|
-
const [ selectedTreeId, setSelectedTreeId ] = useState( null );
|
|
17
|
-
const { selectedBlockParentClientIds } = useSelect(
|
|
18
|
-
( select ) => {
|
|
19
|
-
const { getBlockParents } = select( blockEditorStore );
|
|
20
|
-
return {
|
|
21
|
-
selectedBlockParentClientIds: getBlockParents(
|
|
22
|
-
firstSelectedBlockClientId,
|
|
23
|
-
false
|
|
24
|
-
),
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
[ firstSelectedBlockClientId ]
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const parentClientIds =
|
|
31
|
-
Array.isArray( selectedBlockParentClientIds ) &&
|
|
32
|
-
selectedBlockParentClientIds.length
|
|
33
|
-
? selectedBlockParentClientIds
|
|
34
|
-
: null;
|
|
35
|
-
|
|
36
|
-
// Expand tree when a block is selected.
|
|
37
|
-
useEffect( () => {
|
|
38
|
-
// If the selectedTreeId is the same as the selected block,
|
|
39
|
-
// it means that the block was selected using the block list tree.
|
|
40
|
-
if ( selectedTreeId === firstSelectedBlockClientId ) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// If the selected block has parents, get the top-level parent.
|
|
45
|
-
if ( parentClientIds ) {
|
|
46
|
-
// If the selected block has parents,
|
|
47
|
-
// expand the tree branch.
|
|
48
|
-
setExpandedState( {
|
|
49
|
-
type: 'expand',
|
|
50
|
-
clientIds: selectedBlockParentClientIds,
|
|
51
|
-
} );
|
|
52
|
-
}
|
|
53
|
-
}, [ firstSelectedBlockClientId ] );
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
setSelectedTreeId,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
5
|
-
|
|
6
|
-
export const getBlockPositionDescription = ( position, siblingCount, level ) =>
|
|
7
|
-
sprintf(
|
|
8
|
-
/* translators: 1: The numerical position of the block. 2: The total number of blocks. 3. The level of nesting for the block. */
|
|
9
|
-
__( 'Block %1$d of %2$d, Level %3$d' ),
|
|
10
|
-
position,
|
|
11
|
-
siblingCount,
|
|
12
|
-
level
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Returns true if the client ID occurs within the block selection or multi-selection,
|
|
17
|
-
* or false otherwise.
|
|
18
|
-
*
|
|
19
|
-
* @param {string} clientId Block client ID.
|
|
20
|
-
* @param {string|string[]} selectedBlockClientIds Selected block client ID, or an array of multi-selected blocks client IDs.
|
|
21
|
-
*
|
|
22
|
-
* @return {boolean} Whether the block is in multi-selection set.
|
|
23
|
-
*/
|
|
24
|
-
export const isClientIdSelected = ( clientId, selectedBlockClientIds ) =>
|
|
25
|
-
Array.isArray( selectedBlockClientIds ) && selectedBlockClientIds.length
|
|
26
|
-
? selectedBlockClientIds.indexOf( clientId ) !== -1
|
|
27
|
-
: selectedBlockClientIds === clientId;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* From a start and end clientId of potentially different nesting levels,
|
|
31
|
-
* return the nearest-depth ids that have a common level of depth in the
|
|
32
|
-
* nesting hierarchy. For multiple block selection, this ensure that the
|
|
33
|
-
* selection is always at the same nesting level, and not split across
|
|
34
|
-
* separate levels.
|
|
35
|
-
*
|
|
36
|
-
* @param {string} startId The first id of a selection.
|
|
37
|
-
* @param {string} endId The end id of a selection, usually one that has been clicked on.
|
|
38
|
-
* @param {string[]} startParents An array of ancestor ids for the start id, in descending order.
|
|
39
|
-
* @param {string[]} endParents An array of ancestor ids for the end id, in descending order.
|
|
40
|
-
* @return {Object} An object containing the start and end ids.
|
|
41
|
-
*/
|
|
42
|
-
export function getCommonDepthClientIds(
|
|
43
|
-
startId,
|
|
44
|
-
endId,
|
|
45
|
-
startParents,
|
|
46
|
-
endParents
|
|
47
|
-
) {
|
|
48
|
-
const startPath = [ ...startParents, startId ];
|
|
49
|
-
const endPath = [ ...endParents, endId ];
|
|
50
|
-
const depth = Math.min( startPath.length, endPath.length ) - 1;
|
|
51
|
-
const start = startPath[ depth ];
|
|
52
|
-
const end = endPath[ depth ];
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
start,
|
|
56
|
-
end,
|
|
57
|
-
};
|
|
58
|
-
}
|