@wordpress/block-editor 12.17.0 → 12.18.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 +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/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/effects-panel.js +7 -1
- package/build/components/global-styles/effects-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +3 -2
- 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/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/effects.js +66 -0
- package/build/hooks/effects.js.map +1 -0
- package/build/hooks/index.js +15 -2
- 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 +6 -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 +11 -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/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/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 +3 -2
- 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/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/effects.js +51 -0
- package/build-module/hooks/effects.js.map +1 -0
- package/build-module/hooks/index.js +3 -2
- 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 +6 -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 +13 -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/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/effects-panel.js +16 -1
- package/src/components/global-styles/hooks.js +2 -0
- package/src/components/global-styles/typography-panel.js +45 -13
- 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/effects.js +57 -0
- package/src/hooks/index.js +2 -2
- package/src/hooks/index.native.js +1 -0
- package/src/hooks/style.js +8 -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 +26 -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
|
@@ -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
|
+
}
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useSelect } from '@wordpress/data';
|
|
5
|
-
import { useState, useCallback } from '@wordpress/element';
|
|
5
|
+
import { useState, useCallback, useEffect } from '@wordpress/element';
|
|
6
6
|
import {
|
|
7
7
|
useThrottle,
|
|
8
8
|
__experimentalUseDropZone as useDropZone,
|
|
9
|
+
usePrevious,
|
|
9
10
|
} from '@wordpress/compose';
|
|
10
11
|
import { isRTL } from '@wordpress/i18n';
|
|
11
12
|
|
|
@@ -304,6 +305,7 @@ export function getListViewDropTarget( blocksData, position, rtl = false ) {
|
|
|
304
305
|
|
|
305
306
|
return {
|
|
306
307
|
rootClientId: candidateBlockData.clientId,
|
|
308
|
+
clientId: candidateBlockData.clientId,
|
|
307
309
|
blockIndex: newBlockIndex,
|
|
308
310
|
dropPosition: 'inside',
|
|
309
311
|
};
|
|
@@ -396,15 +398,30 @@ export function getListViewDropTarget( blocksData, position, rtl = false ) {
|
|
|
396
398
|
};
|
|
397
399
|
}
|
|
398
400
|
|
|
401
|
+
// Throttle options need to be defined outside of the hook to avoid
|
|
402
|
+
// re-creating the object on every render. This is due to a limitation
|
|
403
|
+
// of the `useThrottle` hook, where the options object is included
|
|
404
|
+
// in the dependency array for memoization.
|
|
405
|
+
const EXPAND_THROTTLE_OPTIONS = {
|
|
406
|
+
leading: false, // Don't call the function immediately on the first call.
|
|
407
|
+
trailing: true, // Do call the function on the last call.
|
|
408
|
+
};
|
|
409
|
+
|
|
399
410
|
/**
|
|
400
411
|
* A react hook for implementing a drop zone in list view.
|
|
401
412
|
*
|
|
402
|
-
* @param {Object} props
|
|
403
|
-
* @param {?HTMLElement} [props.dropZoneElement]
|
|
413
|
+
* @param {Object} props Named parameters.
|
|
414
|
+
* @param {?HTMLElement} [props.dropZoneElement] Optional element to be used as the drop zone.
|
|
415
|
+
* @param {Object} [props.expandedState] The expanded state of the blocks in the list view.
|
|
416
|
+
* @param {Function} [props.setExpandedState] Function to set the expanded state of a list of block clientIds.
|
|
404
417
|
*
|
|
405
418
|
* @return {WPListViewDropZoneTarget} The drop target.
|
|
406
419
|
*/
|
|
407
|
-
export default function useListViewDropZone( {
|
|
420
|
+
export default function useListViewDropZone( {
|
|
421
|
+
dropZoneElement,
|
|
422
|
+
expandedState,
|
|
423
|
+
setExpandedState,
|
|
424
|
+
} ) {
|
|
408
425
|
const {
|
|
409
426
|
getBlockRootClientId,
|
|
410
427
|
getBlockIndex,
|
|
@@ -420,6 +437,55 @@ export default function useListViewDropZone( { dropZoneElement } ) {
|
|
|
420
437
|
|
|
421
438
|
const rtl = isRTL();
|
|
422
439
|
|
|
440
|
+
const previousRootClientId = usePrevious( targetRootClientId );
|
|
441
|
+
|
|
442
|
+
const maybeExpandBlock = useCallback(
|
|
443
|
+
( _expandedState, _target ) => {
|
|
444
|
+
// If the user is attempting to drop a block inside a collapsed block,
|
|
445
|
+
// that is, using a nesting gesture flagged by 'inside' dropPosition,
|
|
446
|
+
// expand the block within the list view, if it isn't already.
|
|
447
|
+
const { rootClientId } = _target || {};
|
|
448
|
+
if ( ! rootClientId ) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
if (
|
|
452
|
+
_target?.dropPosition === 'inside' &&
|
|
453
|
+
! _expandedState[ rootClientId ]
|
|
454
|
+
) {
|
|
455
|
+
setExpandedState( {
|
|
456
|
+
type: 'expand',
|
|
457
|
+
clientIds: [ rootClientId ],
|
|
458
|
+
} );
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
[ setExpandedState ]
|
|
462
|
+
);
|
|
463
|
+
|
|
464
|
+
// Throttle the maybeExpandBlock function to avoid expanding the block
|
|
465
|
+
// too quickly when the user is dragging over the block. This is to
|
|
466
|
+
// avoid expanding the block when the user is just passing over it.
|
|
467
|
+
const throttledMaybeExpandBlock = useThrottle(
|
|
468
|
+
maybeExpandBlock,
|
|
469
|
+
500,
|
|
470
|
+
EXPAND_THROTTLE_OPTIONS
|
|
471
|
+
);
|
|
472
|
+
|
|
473
|
+
useEffect( () => {
|
|
474
|
+
if (
|
|
475
|
+
target?.dropPosition !== 'inside' ||
|
|
476
|
+
previousRootClientId !== target?.rootClientId
|
|
477
|
+
) {
|
|
478
|
+
throttledMaybeExpandBlock.cancel();
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
throttledMaybeExpandBlock( expandedState, target );
|
|
482
|
+
}, [
|
|
483
|
+
expandedState,
|
|
484
|
+
previousRootClientId,
|
|
485
|
+
target,
|
|
486
|
+
throttledMaybeExpandBlock,
|
|
487
|
+
] );
|
|
488
|
+
|
|
423
489
|
const draggedBlockClientIds = getDraggedBlockClientIds();
|
|
424
490
|
const throttled = useThrottle(
|
|
425
491
|
useCallback(
|
|
@@ -484,7 +550,7 @@ export default function useListViewDropZone( { dropZoneElement } ) {
|
|
|
484
550
|
rtl,
|
|
485
551
|
]
|
|
486
552
|
),
|
|
487
|
-
|
|
553
|
+
50
|
|
488
554
|
);
|
|
489
555
|
|
|
490
556
|
const ref = useDropZone( {
|
|
@@ -496,6 +562,9 @@ export default function useListViewDropZone( { dropZoneElement } ) {
|
|
|
496
562
|
},
|
|
497
563
|
onDragLeave() {
|
|
498
564
|
throttled.cancel();
|
|
565
|
+
// Use `null` value to indicate that the drop target is not valid,
|
|
566
|
+
// but that the drag is still active. This allows for styling rules
|
|
567
|
+
// that are active only when a user drags outside of the list view.
|
|
499
568
|
setTarget( null );
|
|
500
569
|
},
|
|
501
570
|
onDragOver( event ) {
|
|
@@ -506,7 +575,10 @@ export default function useListViewDropZone( { dropZoneElement } ) {
|
|
|
506
575
|
},
|
|
507
576
|
onDragEnd() {
|
|
508
577
|
throttled.cancel();
|
|
509
|
-
|
|
578
|
+
// Use `undefined` value to indicate that the drag has concluded.
|
|
579
|
+
// This allows styling rules that are active only when a user is
|
|
580
|
+
// dragging to be removed.
|
|
581
|
+
setTarget( undefined );
|
|
510
582
|
},
|
|
511
583
|
} );
|
|
512
584
|
|