@wordpress/block-editor 12.17.0 → 12.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +32 -0
- package/build/components/block-draggable/index.js +11 -3
- package/build/components/block-draggable/index.js.map +1 -1
- package/build/components/block-edit/context.js +3 -1
- package/build/components/block-edit/context.js.map +1 -1
- package/build/components/block-edit/index.js +4 -2
- package/build/components/block-edit/index.js.map +1 -1
- package/build/components/block-editing-mode/index.js +6 -3
- package/build/components/block-editing-mode/index.js.map +1 -1
- package/build/components/block-inspector/index.js +5 -2
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/block.js +4 -3
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/block.native.js +9 -5
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/index.js +30 -4
- package/build/components/block-list/index.js.map +1 -1
- package/build/components/block-list/private-block-context.js +1 -1
- package/build/components/block-list/private-block-context.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +1 -1
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-lock/toolbar.js +8 -2
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-popover/inbetween.js +15 -3
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-preview/auto.js +1 -1
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-removal-warning-modal/index.js +3 -2
- package/build/components/block-removal-warning-modal/index.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +2 -4
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-switcher/block-transformations-menu.js +12 -1
- package/build/components/block-switcher/block-transformations-menu.js.map +1 -1
- package/build/components/block-switcher/index.js +119 -90
- package/build/components/block-switcher/index.js.map +1 -1
- package/build/components/block-tools/insertion-point.js +10 -3
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/dimensions-tool/aspect-ratio-tool.js +2 -1
- package/build/components/dimensions-tool/aspect-ratio-tool.js.map +1 -1
- package/build/components/font-sizes/fluid-utils.js +7 -1
- package/build/components/font-sizes/fluid-utils.js.map +1 -1
- package/build/components/global-styles/border-panel.js +5 -14
- package/build/components/global-styles/border-panel.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +30 -5
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/effects-panel.js +7 -1
- package/build/components/global-styles/effects-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +11 -8
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +31 -14
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +6 -0
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/iframe/get-compatibility-styles.js +99 -0
- package/build/components/iframe/get-compatibility-styles.js.map +1 -0
- package/build/components/iframe/index.js +2 -3
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/index.js +16 -2
- package/build/components/index.js.map +1 -1
- package/build/components/index.native.js +16 -2
- package/build/components/index.native.js.map +1 -1
- package/build/components/inspector-controls/groups.js +2 -0
- package/build/components/inspector-controls/groups.js.map +1 -1
- package/build/components/inspector-controls-tabs/styles-tab.js +3 -0
- package/build/components/inspector-controls-tabs/styles-tab.js.map +1 -1
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +3 -2
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
- package/build/components/link-control/link-preview.js +30 -26
- package/build/components/link-control/link-preview.js.map +1 -1
- package/build/components/link-control/search-input.js +1 -9
- package/build/components/link-control/search-input.js.map +1 -1
- package/build/components/list-view/block-contents.js +3 -1
- package/build/components/list-view/block-contents.js.map +1 -1
- package/build/components/list-view/block.js +10 -1
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +29 -8
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/drop-indicator.js +100 -32
- package/build/components/list-view/drop-indicator.js.map +1 -1
- package/build/components/list-view/index.js +52 -4
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/leaf.js +2 -2
- package/build/components/list-view/leaf.js.map +1 -1
- package/build/components/list-view/use-list-view-block-indexes.js +30 -0
- package/build/components/list-view/use-list-view-block-indexes.js.map +1 -0
- package/build/components/list-view/use-list-view-drop-zone.js +56 -5
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/list-view/utils.js +92 -0
- package/build/components/list-view/utils.js.map +1 -1
- package/build/components/provider/index.js +1 -1
- package/build/components/provider/index.js.map +1 -1
- package/build/components/recursion-provider/index.js +21 -0
- package/build/components/recursion-provider/index.js.map +1 -1
- package/build/components/rich-text/index.js +30 -6
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/native/index.native.js +9 -9
- package/build/components/rich-text/native/index.native.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +30 -7
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-on-block-drop/index.js +50 -8
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/hooks/block-hooks.js +5 -14
- package/build/hooks/block-hooks.js.map +1 -1
- package/build/hooks/content-lock-ui.js +17 -42
- package/build/hooks/content-lock-ui.js.map +1 -1
- package/build/hooks/dimensions.js +71 -1
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/effects.js +66 -0
- package/build/hooks/effects.js.map +1 -0
- package/build/hooks/index.js +17 -4
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/index.native.js +13 -0
- package/build/hooks/index.native.js.map +1 -1
- package/build/hooks/style.js +9 -2
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/supports.js +2 -1
- package/build/hooks/supports.js.map +1 -1
- package/build/hooks/typography.native.js +2 -2
- package/build/hooks/typography.native.js.map +1 -1
- package/build/hooks/use-bindings-attributes.js +115 -0
- package/build/hooks/use-bindings-attributes.js.map +1 -0
- package/build/hooks/use-shadow-props.js +46 -0
- package/build/hooks/use-shadow-props.js.map +1 -0
- package/build/hooks/utils.js +12 -7
- package/build/hooks/utils.js.map +1 -1
- package/build/index.js +14 -0
- package/build/index.js.map +1 -1
- package/build/store/actions.js +10 -6
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +2 -0
- package/build/store/index.js.map +1 -1
- package/build/store/private-actions.js +37 -0
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +60 -9
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +44 -3
- package/build/store/reducer.js.map +1 -1
- package/build/store/resolvers.js +27 -0
- package/build/store/resolvers.js.map +1 -0
- package/build/store/selectors.js +94 -56
- package/build/store/selectors.js.map +1 -1
- package/build/store/utils.js +5 -26
- package/build/store/utils.js.map +1 -1
- package/build/utils/index.js +0 -16
- package/build/utils/index.js.map +1 -1
- package/build/utils/math.js +13 -0
- package/build/utils/math.js.map +1 -1
- package/build/utils/object.js +17 -0
- package/build/utils/object.js.map +1 -1
- package/build/utils/transform-styles/index.js +37 -27
- package/build/utils/transform-styles/index.js.map +1 -1
- package/build-module/components/block-draggable/index.js +11 -3
- package/build-module/components/block-draggable/index.js.map +1 -1
- package/build-module/components/block-edit/context.js +1 -0
- package/build-module/components/block-edit/context.js.map +1 -1
- package/build-module/components/block-edit/index.js +5 -3
- package/build-module/components/block-edit/index.js.map +1 -1
- package/build-module/components/block-editing-mode/index.js +7 -4
- package/build-module/components/block-editing-mode/index.js.map +1 -1
- package/build-module/components/block-inspector/index.js +5 -2
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/block.js +6 -5
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/block.native.js +11 -7
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/index.js +31 -5
- package/build-module/components/block-list/index.js.map +1 -1
- package/build-module/components/block-list/private-block-context.js +1 -1
- package/build-module/components/block-list/private-block-context.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-lock/toolbar.js +8 -2
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +15 -3
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-preview/auto.js +3 -3
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-removal-warning-modal/index.js +3 -2
- package/build-module/components/block-removal-warning-modal/index.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +2 -4
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-switcher/block-transformations-menu.js +12 -1
- package/build-module/components/block-switcher/block-transformations-menu.js.map +1 -1
- package/build-module/components/block-switcher/index.js +116 -86
- package/build-module/components/block-switcher/index.js.map +1 -1
- package/build-module/components/block-tools/insertion-point.js +10 -3
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/dimensions-tool/aspect-ratio-tool.js +2 -1
- package/build-module/components/dimensions-tool/aspect-ratio-tool.js.map +1 -1
- package/build-module/components/font-sizes/fluid-utils.js +7 -1
- package/build-module/components/font-sizes/fluid-utils.js.map +1 -1
- package/build-module/components/global-styles/border-panel.js +5 -14
- package/build-module/components/global-styles/border-panel.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +30 -5
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/effects-panel.js +7 -1
- package/build-module/components/global-styles/effects-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +11 -8
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +32 -15
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +6 -0
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/iframe/get-compatibility-styles.js +93 -0
- package/build-module/components/iframe/get-compatibility-styles.js.map +1 -0
- package/build-module/components/iframe/index.js +2 -3
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/index.js +1 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/index.native.js +1 -1
- package/build-module/components/index.native.js.map +1 -1
- package/build-module/components/inspector-controls/groups.js +2 -0
- package/build-module/components/inspector-controls/groups.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/styles-tab.js +3 -0
- package/build-module/components/inspector-controls-tabs/styles-tab.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +3 -2
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
- package/build-module/components/link-control/link-preview.js +32 -28
- package/build-module/components/link-control/link-preview.js.map +1 -1
- package/build-module/components/link-control/search-input.js +1 -8
- package/build-module/components/link-control/search-input.js.map +1 -1
- package/build-module/components/list-view/block-contents.js +3 -1
- package/build-module/components/list-view/block-contents.js.map +1 -1
- package/build-module/components/list-view/block.js +10 -1
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +30 -9
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/drop-indicator.js +99 -32
- package/build-module/components/list-view/drop-indicator.js.map +1 -1
- package/build-module/components/list-view/index.js +54 -6
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/leaf.js +2 -2
- package/build-module/components/list-view/leaf.js.map +1 -1
- package/build-module/components/list-view/use-list-view-block-indexes.js +23 -0
- package/build-module/components/list-view/use-list-view-block-indexes.js.map +1 -0
- package/build-module/components/list-view/use-list-view-drop-zone.js +58 -7
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/list-view/utils.js +91 -0
- package/build-module/components/list-view/utils.js.map +1 -1
- package/build-module/components/provider/index.js +1 -1
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/recursion-provider/index.js +17 -0
- package/build-module/components/recursion-provider/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +30 -6
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/native/index.native.js +9 -9
- package/build-module/components/rich-text/native/index.native.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +31 -8
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/index.js +51 -9
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/hooks/block-hooks.js +5 -14
- package/build-module/hooks/block-hooks.js.map +1 -1
- package/build-module/hooks/content-lock-ui.js +19 -43
- package/build-module/hooks/content-lock-ui.js.map +1 -1
- package/build-module/hooks/dimensions.js +70 -2
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/effects.js +51 -0
- package/build-module/hooks/effects.js.map +1 -0
- package/build-module/hooks/index.js +5 -3
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/index.native.js +1 -0
- package/build-module/hooks/index.native.js.map +1 -1
- package/build-module/hooks/style.js +9 -2
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/supports.js +2 -1
- package/build-module/hooks/supports.js.map +1 -1
- package/build-module/hooks/typography.native.js +2 -2
- package/build-module/hooks/typography.native.js.map +1 -1
- package/build-module/hooks/use-bindings-attributes.js +112 -0
- package/build-module/hooks/use-bindings-attributes.js.map +1 -0
- package/build-module/hooks/use-shadow-props.js +39 -0
- package/build-module/hooks/use-shadow-props.js.map +1 -0
- package/build-module/hooks/utils.js +14 -9
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/store/actions.js +10 -6
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +2 -0
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/private-actions.js +35 -0
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +53 -8
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +43 -3
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/resolvers.js +20 -0
- package/build-module/store/resolvers.js.map +1 -0
- package/build-module/store/selectors.js +89 -52
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/utils.js +3 -23
- package/build-module/store/utils.js.map +1 -1
- package/build-module/utils/index.js +0 -1
- package/build-module/utils/index.js.map +1 -1
- package/build-module/utils/math.js +12 -0
- package/build-module/utils/math.js.map +1 -1
- package/build-module/utils/object.js +16 -0
- package/build-module/utils/object.js.map +1 -1
- package/build-module/utils/transform-styles/index.js +36 -27
- package/build-module/utils/transform-styles/index.js.map +1 -1
- package/build-style/content-rtl.css +33 -16
- package/build-style/content.css +33 -16
- 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 +169 -114
- package/build-style/style.css +169 -114
- package/package.json +31 -31
- package/src/components/block-canvas/style.scss +8 -1
- package/src/components/block-draggable/index.js +16 -5
- package/src/components/block-edit/context.js +1 -0
- package/src/components/block-edit/index.js +4 -0
- package/src/components/block-editing-mode/index.js +12 -7
- package/src/components/block-inspector/index.js +5 -2
- package/src/components/block-list/block.js +5 -4
- package/src/components/block-list/block.native.js +13 -3
- package/src/components/block-list/content.scss +34 -5
- package/src/components/block-list/index.js +52 -16
- package/src/components/block-list/private-block-context.js +1 -1
- package/src/components/block-list/use-in-between-inserter.js +1 -2
- package/src/components/block-lock/toolbar.js +10 -2
- package/src/components/block-popover/inbetween.js +22 -2
- package/src/components/block-preview/auto.js +3 -3
- package/src/components/block-removal-warning-modal/index.js +3 -2
- package/src/components/block-settings-menu/block-settings-dropdown.js +2 -7
- package/src/components/block-switcher/block-transformations-menu.js +18 -1
- package/src/components/block-switcher/index.js +133 -111
- package/src/components/block-switcher/style.scss +6 -4
- package/src/components/block-switcher/test/index.js +113 -230
- package/src/components/block-toolbar/style.scss +22 -18
- package/src/components/block-tools/insertion-point.js +15 -2
- package/src/components/block-tools/style.scss +8 -7
- package/src/components/dimensions-tool/aspect-ratio-tool.js +4 -1
- package/src/components/font-sizes/fluid-utils.js +8 -2
- package/src/components/font-sizes/test/fluid-utils.js +9 -0
- package/src/components/global-styles/border-panel.js +7 -17
- package/src/components/global-styles/dimensions-panel.js +50 -1
- package/src/components/global-styles/effects-panel.js +16 -1
- package/src/components/global-styles/hooks.js +11 -6
- package/src/components/global-styles/typography-panel.js +45 -13
- package/src/components/global-styles/use-global-styles-output.js +6 -0
- package/src/components/iframe/get-compatibility-styles.js +120 -0
- package/src/components/iframe/index.js +2 -3
- package/src/components/index.js +4 -2
- package/src/components/index.native.js +4 -2
- package/src/components/inspector-controls/groups.js +2 -0
- package/src/components/inspector-controls-tabs/styles-tab.js +1 -0
- package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +2 -0
- package/src/components/link-control/link-preview.js +31 -55
- package/src/components/link-control/search-input.js +1 -9
- package/src/components/link-control/style.scss +31 -85
- package/src/components/link-control/test/index.js +2 -1
- package/src/components/list-view/block-contents.js +5 -1
- package/src/components/list-view/block.js +9 -0
- package/src/components/list-view/branch.js +30 -10
- package/src/components/list-view/drop-indicator.js +139 -46
- package/src/components/list-view/index.js +74 -3
- package/src/components/list-view/leaf.js +2 -2
- package/src/components/list-view/style.scss +102 -13
- package/src/components/list-view/test/use-list-view-drop-zone.js +4 -0
- package/src/components/list-view/test/utils.js +218 -1
- package/src/components/list-view/use-list-view-block-indexes.js +29 -0
- package/src/components/list-view/use-list-view-drop-zone.js +78 -6
- package/src/components/list-view/utils.js +116 -0
- package/src/components/provider/index.js +3 -1
- package/src/components/recursion-provider/README.md +2 -2
- package/src/components/recursion-provider/index.js +17 -0
- package/src/components/rich-text/index.js +48 -10
- package/src/components/rich-text/native/index.native.js +10 -10
- package/src/components/use-block-drop-zone/index.js +60 -19
- package/src/components/use-block-drop-zone/test/index.js +32 -61
- package/src/components/use-on-block-drop/index.js +92 -11
- package/src/hooks/block-hooks.js +5 -17
- package/src/hooks/content-lock-ui.js +15 -55
- package/src/hooks/dimensions.js +74 -3
- package/src/hooks/effects.js +57 -0
- package/src/hooks/index.js +4 -2
- package/src/hooks/index.native.js +1 -0
- package/src/hooks/style.js +12 -0
- package/src/hooks/supports.js +2 -0
- package/src/hooks/test/effects.js +39 -0
- package/src/hooks/typography.native.js +2 -2
- package/src/hooks/use-bindings-attributes.js +148 -0
- package/src/hooks/use-shadow-props.js +37 -0
- package/src/hooks/utils.js +30 -10
- package/src/index.js +2 -0
- package/src/store/actions.js +9 -4
- package/src/store/index.js +2 -0
- package/src/store/private-actions.js +32 -0
- package/src/store/private-selectors.js +78 -21
- package/src/store/reducer.js +49 -2
- package/src/store/resolvers.js +17 -0
- package/src/store/selectors.js +169 -161
- package/src/store/test/registry-selectors.js +431 -0
- package/src/store/test/selectors.js +14 -400
- package/src/store/utils.js +10 -33
- package/src/style.scss +0 -1
- package/src/utils/index.js +0 -1
- package/src/utils/math.js +12 -0
- package/src/utils/object.js +16 -0
- package/src/utils/transform-styles/index.js +52 -37
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/iframe/use-compatibility-styles.js +0 -100
- package/build/components/iframe/use-compatibility-styles.js.map +0 -1
- package/build/hooks/custom-fields.js +0 -106
- package/build/hooks/custom-fields.js.map +0 -1
- package/build/utils/block-variation-transforms.js +0 -42
- package/build/utils/block-variation-transforms.js.map +0 -1
- package/build-module/components/iframe/use-compatibility-styles.js +0 -94
- package/build-module/components/iframe/use-compatibility-styles.js.map +0 -1
- package/build-module/hooks/custom-fields.js +0 -99
- package/build-module/hooks/custom-fields.js.map +0 -1
- package/build-module/utils/block-variation-transforms.js +0 -35
- package/build-module/utils/block-variation-transforms.js.map +0 -1
- package/src/components/block-switcher/test/__snapshots__/index.js.snap +0 -116
- package/src/components/contrast-checker/style.scss +0 -3
- package/src/components/iframe/use-compatibility-styles.js +0 -122
- package/src/hooks/custom-fields.js +0 -115
- package/src/utils/block-variation-transforms.js +0 -38
- package/src/utils/test/block-variation-transforms.js +0 -94
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* WordPress dependencies
|
|
3
8
|
*/
|
|
@@ -28,8 +33,9 @@ import { __ } from '@wordpress/i18n';
|
|
|
28
33
|
*/
|
|
29
34
|
import ListViewBranch from './branch';
|
|
30
35
|
import { ListViewContext } from './context';
|
|
31
|
-
import
|
|
36
|
+
import ListViewDropIndicatorPreview from './drop-indicator';
|
|
32
37
|
import useBlockSelection from './use-block-selection';
|
|
38
|
+
import useListViewBlockIndexes from './use-list-view-block-indexes';
|
|
33
39
|
import useListViewClientIds from './use-list-view-client-ids';
|
|
34
40
|
import useListViewDropZone from './use-list-view-drop-zone';
|
|
35
41
|
import useListViewExpandSelectedItem from './use-list-view-expand-selected-item';
|
|
@@ -105,6 +111,7 @@ function ListViewComponent(
|
|
|
105
111
|
const instanceId = useInstanceId( ListViewComponent );
|
|
106
112
|
const { clientIdsTree, draggedClientIds, selectedClientIds } =
|
|
107
113
|
useListViewClientIds( { blocks, rootClientId } );
|
|
114
|
+
const blockIndexes = useListViewBlockIndexes( clientIdsTree );
|
|
108
115
|
|
|
109
116
|
const { getBlock } = useSelect( blockEditorStore );
|
|
110
117
|
const { visibleBlockCount, shouldShowInnerBlocks } = useSelect(
|
|
@@ -132,6 +139,8 @@ function ListViewComponent(
|
|
|
132
139
|
|
|
133
140
|
const { ref: dropZoneRef, target: blockDropTarget } = useListViewDropZone( {
|
|
134
141
|
dropZoneElement,
|
|
142
|
+
expandedState,
|
|
143
|
+
setExpandedState,
|
|
135
144
|
} );
|
|
136
145
|
const elementRef = useRef();
|
|
137
146
|
const treeGridRef = useMergeRefs( [ elementRef, dropZoneRef, ref ] );
|
|
@@ -210,11 +219,55 @@ function ListViewComponent(
|
|
|
210
219
|
[ updateBlockSelection ]
|
|
211
220
|
);
|
|
212
221
|
|
|
222
|
+
const firstDraggedBlockClientId = draggedClientIds?.[ 0 ];
|
|
223
|
+
|
|
224
|
+
// Convert a blockDropTarget into indexes relative to the blocks in the list view.
|
|
225
|
+
// These values are used to determine which blocks should be displaced to make room
|
|
226
|
+
// for the drop indicator. See `ListViewBranch` and `getDragDisplacementValues`.
|
|
227
|
+
const { blockDropTargetIndex, blockDropPosition, firstDraggedBlockIndex } =
|
|
228
|
+
useMemo( () => {
|
|
229
|
+
let _blockDropTargetIndex, _firstDraggedBlockIndex;
|
|
230
|
+
|
|
231
|
+
if ( blockDropTarget?.clientId ) {
|
|
232
|
+
const foundBlockIndex =
|
|
233
|
+
blockIndexes[ blockDropTarget.clientId ];
|
|
234
|
+
// If dragging below or inside the block, treat the drop target as the next block.
|
|
235
|
+
_blockDropTargetIndex =
|
|
236
|
+
foundBlockIndex === undefined ||
|
|
237
|
+
blockDropTarget?.dropPosition === 'top'
|
|
238
|
+
? foundBlockIndex
|
|
239
|
+
: foundBlockIndex + 1;
|
|
240
|
+
} else if ( blockDropTarget === null ) {
|
|
241
|
+
// A `null` value is used to indicate that the user is dragging outside of the list view.
|
|
242
|
+
_blockDropTargetIndex = null;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if ( firstDraggedBlockClientId ) {
|
|
246
|
+
const foundBlockIndex =
|
|
247
|
+
blockIndexes[ firstDraggedBlockClientId ];
|
|
248
|
+
_firstDraggedBlockIndex =
|
|
249
|
+
foundBlockIndex === undefined ||
|
|
250
|
+
blockDropTarget?.dropPosition === 'top'
|
|
251
|
+
? foundBlockIndex
|
|
252
|
+
: foundBlockIndex + 1;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return {
|
|
256
|
+
blockDropTargetIndex: _blockDropTargetIndex,
|
|
257
|
+
blockDropPosition: blockDropTarget?.dropPosition,
|
|
258
|
+
firstDraggedBlockIndex: _firstDraggedBlockIndex,
|
|
259
|
+
};
|
|
260
|
+
}, [ blockDropTarget, blockIndexes, firstDraggedBlockClientId ] );
|
|
261
|
+
|
|
213
262
|
const contextValue = useMemo(
|
|
214
263
|
() => ( {
|
|
264
|
+
blockDropPosition,
|
|
265
|
+
blockDropTargetIndex,
|
|
266
|
+
blockIndexes,
|
|
215
267
|
draggedClientIds,
|
|
216
268
|
expandedState,
|
|
217
269
|
expand,
|
|
270
|
+
firstDraggedBlockIndex,
|
|
218
271
|
collapse,
|
|
219
272
|
BlockSettingsMenu,
|
|
220
273
|
listViewInstanceId: instanceId,
|
|
@@ -225,9 +278,13 @@ function ListViewComponent(
|
|
|
225
278
|
rootClientId,
|
|
226
279
|
} ),
|
|
227
280
|
[
|
|
281
|
+
blockDropPosition,
|
|
282
|
+
blockDropTargetIndex,
|
|
283
|
+
blockIndexes,
|
|
228
284
|
draggedClientIds,
|
|
229
285
|
expandedState,
|
|
230
286
|
expand,
|
|
287
|
+
firstDraggedBlockIndex,
|
|
231
288
|
collapse,
|
|
232
289
|
BlockSettingsMenu,
|
|
233
290
|
instanceId,
|
|
@@ -267,7 +324,8 @@ function ListViewComponent(
|
|
|
267
324
|
|
|
268
325
|
return (
|
|
269
326
|
<AsyncModeProvider value={ true }>
|
|
270
|
-
<
|
|
327
|
+
<ListViewDropIndicatorPreview
|
|
328
|
+
draggedBlockClientId={ firstDraggedBlockClientId }
|
|
271
329
|
listViewRef={ elementRef }
|
|
272
330
|
blockDropTarget={ blockDropTarget }
|
|
273
331
|
/>
|
|
@@ -278,7 +336,11 @@ function ListViewComponent(
|
|
|
278
336
|
) }
|
|
279
337
|
<TreeGrid
|
|
280
338
|
id={ id }
|
|
281
|
-
className=
|
|
339
|
+
className={ classnames( 'block-editor-list-view-tree', {
|
|
340
|
+
'is-dragging':
|
|
341
|
+
draggedClientIds?.length > 0 &&
|
|
342
|
+
blockDropTargetIndex !== undefined,
|
|
343
|
+
} ) }
|
|
282
344
|
aria-label={ __( 'Block navigation structure' ) }
|
|
283
345
|
ref={ treeGridRef }
|
|
284
346
|
onCollapseRow={ collapseRow }
|
|
@@ -286,6 +348,15 @@ function ListViewComponent(
|
|
|
286
348
|
onFocusRow={ focusRow }
|
|
287
349
|
applicationAriaLabel={ __( 'Block navigation structure' ) }
|
|
288
350
|
aria-describedby={ describedById }
|
|
351
|
+
style={ {
|
|
352
|
+
'--wp-admin--list-view-dragged-items-height':
|
|
353
|
+
draggedClientIds?.length
|
|
354
|
+
? `${
|
|
355
|
+
BLOCK_LIST_ITEM_HEIGHT *
|
|
356
|
+
( draggedClientIds.length - 1 )
|
|
357
|
+
}px`
|
|
358
|
+
: null,
|
|
359
|
+
} }
|
|
289
360
|
>
|
|
290
361
|
<ListViewContext.Provider value={ contextValue }>
|
|
291
362
|
<ListViewBranch
|
|
@@ -21,6 +21,7 @@ const AnimatedTreeGridRow = animated( TreeGridRow );
|
|
|
21
21
|
const ListViewLeaf = forwardRef(
|
|
22
22
|
(
|
|
23
23
|
{
|
|
24
|
+
isDragged,
|
|
24
25
|
isSelected,
|
|
25
26
|
position,
|
|
26
27
|
level,
|
|
@@ -33,8 +34,7 @@ const ListViewLeaf = forwardRef(
|
|
|
33
34
|
ref
|
|
34
35
|
) => {
|
|
35
36
|
const animationRef = useMovingAnimation( {
|
|
36
|
-
|
|
37
|
-
adjustScrolling: false,
|
|
37
|
+
clientId: props[ 'data-block' ],
|
|
38
38
|
enableAnimation: true,
|
|
39
39
|
triggerAnimationOnChange: path,
|
|
40
40
|
} );
|
|
@@ -9,11 +9,22 @@
|
|
|
9
9
|
margin: (-$grid-unit-15) (-$grid-unit-15 * 0.5) 0;
|
|
10
10
|
width: calc(100% + #{ $grid-unit-15 });
|
|
11
11
|
}
|
|
12
|
+
|
|
13
|
+
// Without setting `pointer-events: none`, when dragging over list view items,
|
|
14
|
+
// Safari calls onDropZoneLeave causing flickering in the position of the drop indicator.
|
|
15
|
+
// https://bugs.webkit.org/show_bug.cgi?id=66547
|
|
16
|
+
// See: https://github.com/WordPress/gutenberg/pull/56625
|
|
17
|
+
&.is-dragging tbody {
|
|
18
|
+
pointer-events: none;
|
|
19
|
+
}
|
|
12
20
|
}
|
|
13
21
|
|
|
14
22
|
.block-editor-list-view-leaf {
|
|
15
23
|
// Use position relative for row animation.
|
|
16
24
|
position: relative;
|
|
25
|
+
// Set the initial translate position to ensure the UI in Safari doesn't jump
|
|
26
|
+
// when rows later receive the is-displacement-up or is-displacement-down class.
|
|
27
|
+
transform: translateY(0);
|
|
17
28
|
|
|
18
29
|
&.is-draggable,
|
|
19
30
|
&.is-draggable .block-editor-list-view-block-contents {
|
|
@@ -128,6 +139,66 @@
|
|
|
128
139
|
border-radius: 0;
|
|
129
140
|
}
|
|
130
141
|
|
|
142
|
+
// List view items will be displaced up or down relative to their original position
|
|
143
|
+
// when a user is dragging a block within the list view. This creates a space for a
|
|
144
|
+
// visual indicator of where the block will be placed when dropped. The `normal` state
|
|
145
|
+
// is used to allow rows to smoothly transition back into their original position,
|
|
146
|
+
// without attaching the transition to the list view leaf itself. This prevents rows
|
|
147
|
+
// from animating too much once the user has dropped the block.
|
|
148
|
+
&.is-displacement-normal {
|
|
149
|
+
transition: transform 0.2s;
|
|
150
|
+
transform: translateY(0);
|
|
151
|
+
@include reduce-motion("transition");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
&.is-displacement-up {
|
|
155
|
+
transition: transform 0.2s;
|
|
156
|
+
transform: translateY(-36px);
|
|
157
|
+
@include reduce-motion("transition");
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
&.is-displacement-down {
|
|
161
|
+
transition: transform 0.2s;
|
|
162
|
+
transform: translateY(36px);
|
|
163
|
+
@include reduce-motion("transition");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Collapse multi-selections down into a single row space while dragging. The following
|
|
167
|
+
// rules ensure that during a multi-selection, the space for additional blocks is factored in
|
|
168
|
+
// when displacing up and down. The result is that there should only ever be a single row's
|
|
169
|
+
// worth of space for the visual indicator of where a block will be placed when dropped.
|
|
170
|
+
&.is-after-dragged-blocks {
|
|
171
|
+
transition: transform 0.2s;
|
|
172
|
+
transform: translateY(calc(var(--wp-admin--list-view-dragged-items-height, 36px) * -1));
|
|
173
|
+
@include reduce-motion("transition");
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
&.is-after-dragged-blocks.is-displacement-up {
|
|
177
|
+
transition: transform 0.2s;
|
|
178
|
+
transform: translateY(calc(-36px + var(--wp-admin--list-view-dragged-items-height, 36px) * -1));
|
|
179
|
+
@include reduce-motion("transition");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
&.is-after-dragged-blocks.is-displacement-down {
|
|
183
|
+
transition: transform 0.2s;
|
|
184
|
+
transform: translateY(calc(36px + var(--wp-admin--list-view-dragged-items-height, 36px) * -1));
|
|
185
|
+
@include reduce-motion("transition");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// To ensure displaced rows behave correctly, ensure that blocks that are currently being dragged
|
|
189
|
+
// are visually hidden. The below rules are used in favor of `display: none` to ensure that
|
|
190
|
+
// there is no flicker when a user begins to drag a block.
|
|
191
|
+
&.is-dragging {
|
|
192
|
+
opacity: 0;
|
|
193
|
+
// The row's left position is set to 0 to ensure that the animation
|
|
194
|
+
// when dropping a block animates from the correct position.
|
|
195
|
+
left: 0;
|
|
196
|
+
// Ensure the dragged element does not otherwise affect dropping to
|
|
197
|
+
// other positions.
|
|
198
|
+
pointer-events: none;
|
|
199
|
+
z-index: -9999;
|
|
200
|
+
}
|
|
201
|
+
|
|
131
202
|
// List View renders a fixed number of items and relies on each item having a fixed height of 36px.
|
|
132
203
|
// If this value changes, we should also change the itemHeight value set in useFixedWindowList.
|
|
133
204
|
// See: https://github.com/WordPress/gutenberg/pull/35230 for additional context.
|
|
@@ -159,6 +230,7 @@
|
|
|
159
230
|
}
|
|
160
231
|
}
|
|
161
232
|
|
|
233
|
+
&.is-nesting .block-editor-list-view-block-contents,
|
|
162
234
|
.block-editor-list-view-block-contents:focus {
|
|
163
235
|
box-shadow: none;
|
|
164
236
|
|
|
@@ -173,11 +245,6 @@
|
|
|
173
245
|
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
|
|
174
246
|
z-index: 2;
|
|
175
247
|
pointer-events: none;
|
|
176
|
-
|
|
177
|
-
// Hide focus styles while a user is dragging blocks/files etc.
|
|
178
|
-
.is-dragging-components-draggable & {
|
|
179
|
-
box-shadow: none;
|
|
180
|
-
}
|
|
181
248
|
}
|
|
182
249
|
}
|
|
183
250
|
|
|
@@ -186,14 +253,10 @@
|
|
|
186
253
|
right: 0;
|
|
187
254
|
}
|
|
188
255
|
|
|
256
|
+
&.is-nesting .block-editor-list-view__menu,
|
|
189
257
|
.block-editor-list-view-block__menu:focus {
|
|
190
258
|
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
|
|
191
259
|
z-index: 1;
|
|
192
|
-
|
|
193
|
-
// Hide focus styles while a user is dragging blocks/files etc.
|
|
194
|
-
.is-dragging-components-draggable & {
|
|
195
|
-
box-shadow: none;
|
|
196
|
-
}
|
|
197
260
|
}
|
|
198
261
|
|
|
199
262
|
&.is-visible .block-editor-list-view-block-contents {
|
|
@@ -370,6 +433,14 @@
|
|
|
370
433
|
}
|
|
371
434
|
}
|
|
372
435
|
|
|
436
|
+
// First level of indentation is aria-level 2, max indent is 8.
|
|
437
|
+
// Indent is a full icon size, plus 4px which optically aligns child icons to the text label above.
|
|
438
|
+
$block-navigation-max-indent: 8;
|
|
439
|
+
|
|
440
|
+
.block-editor-list-view-draggable-chip {
|
|
441
|
+
opacity: 0.8;
|
|
442
|
+
}
|
|
443
|
+
|
|
373
444
|
.block-editor-list-view-block__contents-cell,
|
|
374
445
|
.block-editor-list-view-appender__cell {
|
|
375
446
|
.block-editor-list-view-block__contents-container,
|
|
@@ -386,9 +457,6 @@
|
|
|
386
457
|
cursor: pointer;
|
|
387
458
|
}
|
|
388
459
|
|
|
389
|
-
// First level of indentation is aria-level 2, max indent is 8.
|
|
390
|
-
// Indent is a full icon size, plus 4px which optically aligns child icons to the text label above.
|
|
391
|
-
$block-navigation-max-indent: 8;
|
|
392
460
|
.block-editor-list-view-leaf[aria-level] .block-editor-list-view__expander {
|
|
393
461
|
margin-left: ( $icon-size ) * $block-navigation-max-indent + 4 * ( $block-navigation-max-indent - 1 );
|
|
394
462
|
}
|
|
@@ -443,6 +511,27 @@ $block-navigation-max-indent: 8;
|
|
|
443
511
|
}
|
|
444
512
|
}
|
|
445
513
|
|
|
514
|
+
.block-editor-list-view-drop-indicator--preview {
|
|
515
|
+
pointer-events: none;
|
|
516
|
+
|
|
517
|
+
// If the drop indicator's popover ever extends to the edge of the screen,
|
|
518
|
+
// avoid any scrollbars by hiding the overflow.
|
|
519
|
+
.components-popover__content {
|
|
520
|
+
overflow: hidden !important;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
.block-editor-list-view-drop-indicator__line {
|
|
524
|
+
background: rgba(var(--wp-admin-theme-color--rgb), 0.04);
|
|
525
|
+
height: 36px;
|
|
526
|
+
border-radius: 4px;
|
|
527
|
+
overflow: hidden;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
.block-editor-list-view-drop-indicator__line--darker {
|
|
531
|
+
background: rgba(var(--wp-admin-theme-color--rgb), 0.09);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
446
535
|
.block-editor-list-view-placeholder {
|
|
447
536
|
padding: 0;
|
|
448
537
|
margin: 0;
|
|
@@ -127,6 +127,7 @@ describe( 'getListViewDropTarget', () => {
|
|
|
127
127
|
|
|
128
128
|
expect( target ).toEqual( {
|
|
129
129
|
blockIndex: 0,
|
|
130
|
+
clientId: 'block-1',
|
|
130
131
|
dropPosition: 'inside',
|
|
131
132
|
rootClientId: 'block-1',
|
|
132
133
|
} );
|
|
@@ -142,6 +143,7 @@ describe( 'getListViewDropTarget', () => {
|
|
|
142
143
|
|
|
143
144
|
expect( target ).toEqual( {
|
|
144
145
|
blockIndex: 0,
|
|
146
|
+
clientId: 'block-3',
|
|
145
147
|
dropPosition: 'inside',
|
|
146
148
|
rootClientId: 'block-3',
|
|
147
149
|
} );
|
|
@@ -244,6 +246,7 @@ describe( 'getListViewDropTarget', () => {
|
|
|
244
246
|
|
|
245
247
|
expect( target ).toEqual( {
|
|
246
248
|
blockIndex: 1,
|
|
249
|
+
clientId: 'block-1',
|
|
247
250
|
dropPosition: 'inside',
|
|
248
251
|
rootClientId: 'block-1',
|
|
249
252
|
} );
|
|
@@ -277,6 +280,7 @@ describe( 'getListViewDropTarget', () => {
|
|
|
277
280
|
|
|
278
281
|
expect( target ).toEqual( {
|
|
279
282
|
blockIndex: 0,
|
|
283
|
+
clientId: 'block-1',
|
|
280
284
|
dropPosition: 'inside',
|
|
281
285
|
rootClientId: 'block-1',
|
|
282
286
|
} );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { getCommonDepthClientIds } from '../utils';
|
|
4
|
+
import { getCommonDepthClientIds, getDragDisplacementValues } from '../utils';
|
|
5
5
|
|
|
6
6
|
describe( 'getCommonDepthClientIds', () => {
|
|
7
7
|
it( 'should return start and end when no depth is provided', () => {
|
|
@@ -48,3 +48,220 @@ describe( 'getCommonDepthClientIds', () => {
|
|
|
48
48
|
expect( result ).toEqual( { start: 'start-3', end: 'clicked-id' } );
|
|
49
49
|
} );
|
|
50
50
|
} );
|
|
51
|
+
|
|
52
|
+
describe( 'getDragDisplacementValues', () => {
|
|
53
|
+
const blockIndexes = {
|
|
54
|
+
'block-a': 0,
|
|
55
|
+
'block-b': 1,
|
|
56
|
+
'block-c': 2,
|
|
57
|
+
'block-d': 3,
|
|
58
|
+
'block-e': 4,
|
|
59
|
+
'block-f': 5,
|
|
60
|
+
'block-g': 6,
|
|
61
|
+
'block-h': 7,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
it( 'should return displacement of normal when block is after dragged block and drop target', () => {
|
|
65
|
+
const result = getDragDisplacementValues( {
|
|
66
|
+
blockIndexes,
|
|
67
|
+
blockDropTargetIndex: 3,
|
|
68
|
+
blockDropPosition: 'bottom',
|
|
69
|
+
clientId: 'block-h',
|
|
70
|
+
firstDraggedBlockIndex: 5,
|
|
71
|
+
isDragged: false,
|
|
72
|
+
} );
|
|
73
|
+
|
|
74
|
+
expect( result ).toEqual( {
|
|
75
|
+
displacement: 'normal',
|
|
76
|
+
isAfterDraggedBlocks: true,
|
|
77
|
+
isNesting: false,
|
|
78
|
+
} );
|
|
79
|
+
} );
|
|
80
|
+
|
|
81
|
+
it( 'should return displacement of up when block is after dragged block and before the drop target', () => {
|
|
82
|
+
const result = getDragDisplacementValues( {
|
|
83
|
+
blockIndexes,
|
|
84
|
+
blockDropTargetIndex: 7,
|
|
85
|
+
blockDropPosition: 'bottom',
|
|
86
|
+
clientId: 'block-d',
|
|
87
|
+
firstDraggedBlockIndex: 2,
|
|
88
|
+
isDragged: false,
|
|
89
|
+
} );
|
|
90
|
+
|
|
91
|
+
expect( result ).toEqual( {
|
|
92
|
+
displacement: 'up',
|
|
93
|
+
isAfterDraggedBlocks: true,
|
|
94
|
+
isNesting: false,
|
|
95
|
+
} );
|
|
96
|
+
} );
|
|
97
|
+
|
|
98
|
+
it( 'should return displacement of down when block is before dragged block and after the drop target', () => {
|
|
99
|
+
const result = getDragDisplacementValues( {
|
|
100
|
+
blockIndexes,
|
|
101
|
+
blockDropTargetIndex: 1,
|
|
102
|
+
blockDropPosition: 'bottom',
|
|
103
|
+
clientId: 'block-d',
|
|
104
|
+
firstDraggedBlockIndex: 6,
|
|
105
|
+
isDragged: false,
|
|
106
|
+
} );
|
|
107
|
+
|
|
108
|
+
expect( result ).toEqual( {
|
|
109
|
+
displacement: 'down',
|
|
110
|
+
isAfterDraggedBlocks: false,
|
|
111
|
+
isNesting: false,
|
|
112
|
+
} );
|
|
113
|
+
} );
|
|
114
|
+
|
|
115
|
+
it( 'should return isNesting of true when block is just before the drop target and drop position is inside', () => {
|
|
116
|
+
const result = getDragDisplacementValues( {
|
|
117
|
+
blockIndexes,
|
|
118
|
+
blockDropTargetIndex: 1,
|
|
119
|
+
blockDropPosition: 'inside',
|
|
120
|
+
clientId: 'block-a',
|
|
121
|
+
firstDraggedBlockIndex: 6,
|
|
122
|
+
isDragged: false,
|
|
123
|
+
} );
|
|
124
|
+
|
|
125
|
+
expect( result ).toEqual( {
|
|
126
|
+
displacement: 'normal',
|
|
127
|
+
isAfterDraggedBlocks: false,
|
|
128
|
+
isNesting: true,
|
|
129
|
+
} );
|
|
130
|
+
} );
|
|
131
|
+
|
|
132
|
+
it( 'should return isNesting of false when block is not just before the drop target and drop position is inside', () => {
|
|
133
|
+
const result = getDragDisplacementValues( {
|
|
134
|
+
blockIndexes,
|
|
135
|
+
blockDropTargetIndex: 1,
|
|
136
|
+
blockDropPosition: 'inside',
|
|
137
|
+
clientId: 'block-b',
|
|
138
|
+
firstDraggedBlockIndex: 6,
|
|
139
|
+
isDragged: false,
|
|
140
|
+
} );
|
|
141
|
+
|
|
142
|
+
expect( result ).toEqual( {
|
|
143
|
+
displacement: 'down',
|
|
144
|
+
isAfterDraggedBlocks: false,
|
|
145
|
+
isNesting: false,
|
|
146
|
+
} );
|
|
147
|
+
} );
|
|
148
|
+
|
|
149
|
+
it( 'should return displacement of up when drop target index is null and block is after dragged block', () => {
|
|
150
|
+
const result = getDragDisplacementValues( {
|
|
151
|
+
blockIndexes,
|
|
152
|
+
blockDropTargetIndex: null,
|
|
153
|
+
blockDropPosition: 'bottom',
|
|
154
|
+
clientId: 'block-h',
|
|
155
|
+
firstDraggedBlockIndex: 5,
|
|
156
|
+
isDragged: false,
|
|
157
|
+
} );
|
|
158
|
+
|
|
159
|
+
expect( result ).toEqual( {
|
|
160
|
+
displacement: 'up',
|
|
161
|
+
isAfterDraggedBlocks: true,
|
|
162
|
+
isNesting: false,
|
|
163
|
+
} );
|
|
164
|
+
} );
|
|
165
|
+
|
|
166
|
+
it( 'should return displacement of normal when drop target index is null and block is before dragged block', () => {
|
|
167
|
+
const result = getDragDisplacementValues( {
|
|
168
|
+
blockIndexes,
|
|
169
|
+
blockDropTargetIndex: null,
|
|
170
|
+
blockDropPosition: 'bottom',
|
|
171
|
+
clientId: 'block-c',
|
|
172
|
+
firstDraggedBlockIndex: 5,
|
|
173
|
+
isDragged: false,
|
|
174
|
+
} );
|
|
175
|
+
|
|
176
|
+
expect( result ).toEqual( {
|
|
177
|
+
displacement: 'normal',
|
|
178
|
+
isAfterDraggedBlocks: false,
|
|
179
|
+
isNesting: false,
|
|
180
|
+
} );
|
|
181
|
+
} );
|
|
182
|
+
|
|
183
|
+
it( 'should return displacement of normal when dragging a file (no dragged block) and the block is before the target index', () => {
|
|
184
|
+
const result = getDragDisplacementValues( {
|
|
185
|
+
blockIndexes,
|
|
186
|
+
blockDropTargetIndex: 3,
|
|
187
|
+
blockDropPosition: 'bottom',
|
|
188
|
+
clientId: 'block-b',
|
|
189
|
+
firstDraggedBlockIndex: undefined,
|
|
190
|
+
isDragged: false,
|
|
191
|
+
} );
|
|
192
|
+
|
|
193
|
+
expect( result ).toEqual( {
|
|
194
|
+
displacement: 'normal',
|
|
195
|
+
isAfterDraggedBlocks: false,
|
|
196
|
+
isNesting: false,
|
|
197
|
+
} );
|
|
198
|
+
} );
|
|
199
|
+
|
|
200
|
+
it( 'should return displacement of down when dragging a file (no dragged block) and the block is after the target index', () => {
|
|
201
|
+
const result = getDragDisplacementValues( {
|
|
202
|
+
blockIndexes,
|
|
203
|
+
blockDropTargetIndex: 3,
|
|
204
|
+
blockDropPosition: 'bottom',
|
|
205
|
+
clientId: 'block-h',
|
|
206
|
+
firstDraggedBlockIndex: undefined,
|
|
207
|
+
isDragged: false,
|
|
208
|
+
} );
|
|
209
|
+
|
|
210
|
+
expect( result ).toEqual( {
|
|
211
|
+
displacement: 'down',
|
|
212
|
+
isAfterDraggedBlocks: false,
|
|
213
|
+
isNesting: false,
|
|
214
|
+
} );
|
|
215
|
+
} );
|
|
216
|
+
|
|
217
|
+
it( 'should return displacement of normal when dragging a file (no dragged block) and dragging outside the list view (drop target of null)', () => {
|
|
218
|
+
const result = getDragDisplacementValues( {
|
|
219
|
+
blockIndexes,
|
|
220
|
+
blockDropTargetIndex: null,
|
|
221
|
+
blockDropPosition: 'bottom',
|
|
222
|
+
clientId: 'block-h',
|
|
223
|
+
firstDraggedBlockIndex: undefined,
|
|
224
|
+
isDragged: false,
|
|
225
|
+
} );
|
|
226
|
+
|
|
227
|
+
expect( result ).toEqual( {
|
|
228
|
+
displacement: 'normal',
|
|
229
|
+
isAfterDraggedBlocks: false,
|
|
230
|
+
isNesting: false,
|
|
231
|
+
} );
|
|
232
|
+
} );
|
|
233
|
+
|
|
234
|
+
it( 'should return undefined displacement if the target index is undefined', () => {
|
|
235
|
+
const result = getDragDisplacementValues( {
|
|
236
|
+
blockIndexes,
|
|
237
|
+
blockDropTargetIndex: undefined,
|
|
238
|
+
blockDropPosition: 'bottom',
|
|
239
|
+
clientId: 'block-h',
|
|
240
|
+
firstDraggedBlockIndex: undefined,
|
|
241
|
+
isDragged: false,
|
|
242
|
+
} );
|
|
243
|
+
|
|
244
|
+
expect( result ).toEqual( {
|
|
245
|
+
displacement: undefined,
|
|
246
|
+
isAfterDraggedBlocks: false,
|
|
247
|
+
isNesting: false,
|
|
248
|
+
} );
|
|
249
|
+
} );
|
|
250
|
+
|
|
251
|
+
it( 'should return all undefined values if the block is dragged', () => {
|
|
252
|
+
const result = getDragDisplacementValues( {
|
|
253
|
+
blockIndexes,
|
|
254
|
+
blockDropTargetIndex: 3,
|
|
255
|
+
blockDropPosition: 'bottom',
|
|
256
|
+
clientId: 'block-h',
|
|
257
|
+
firstDraggedBlockIndex: 7,
|
|
258
|
+
isDragged: true,
|
|
259
|
+
} );
|
|
260
|
+
|
|
261
|
+
expect( result ).toEqual( {
|
|
262
|
+
displacement: undefined,
|
|
263
|
+
isAfterDraggedBlocks: undefined,
|
|
264
|
+
isNesting: undefined,
|
|
265
|
+
} );
|
|
266
|
+
} );
|
|
267
|
+
} );
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useMemo } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
export default function useListViewBlockIndexes( blocks ) {
|
|
7
|
+
const blockIndexes = useMemo( () => {
|
|
8
|
+
const indexes = {};
|
|
9
|
+
|
|
10
|
+
let currentGlobalIndex = 0;
|
|
11
|
+
|
|
12
|
+
const traverseBlocks = ( blockList ) => {
|
|
13
|
+
blockList.forEach( ( block ) => {
|
|
14
|
+
indexes[ block.clientId ] = currentGlobalIndex;
|
|
15
|
+
currentGlobalIndex++;
|
|
16
|
+
|
|
17
|
+
if ( block.innerBlocks.length > 0 ) {
|
|
18
|
+
traverseBlocks( block.innerBlocks );
|
|
19
|
+
}
|
|
20
|
+
} );
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
traverseBlocks( blocks );
|
|
24
|
+
|
|
25
|
+
return indexes;
|
|
26
|
+
}, [ blocks ] );
|
|
27
|
+
|
|
28
|
+
return blockIndexes;
|
|
29
|
+
}
|