@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
|
@@ -22,13 +22,6 @@ const elementData = [
|
|
|
22
22
|
bottom: 900,
|
|
23
23
|
right: 400,
|
|
24
24
|
},
|
|
25
|
-
// Fourth block wraps to the next row/column.
|
|
26
|
-
{
|
|
27
|
-
top: 0,
|
|
28
|
-
left: 400,
|
|
29
|
-
bottom: 300,
|
|
30
|
-
right: 800,
|
|
31
|
-
},
|
|
32
25
|
];
|
|
33
26
|
|
|
34
27
|
const mapElements =
|
|
@@ -73,7 +66,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
73
66
|
const orientation = 'vertical';
|
|
74
67
|
|
|
75
68
|
it( 'returns `0` when the position is nearest to the start of the first block', () => {
|
|
76
|
-
const position = { x:
|
|
69
|
+
const position = { x: 32, y: 0 };
|
|
77
70
|
|
|
78
71
|
const result = getDropTargetPosition(
|
|
79
72
|
verticalBlocksData,
|
|
@@ -85,7 +78,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
85
78
|
} );
|
|
86
79
|
|
|
87
80
|
it( 'returns `1` when the position is nearest to the end of the first block', () => {
|
|
88
|
-
const position = { x:
|
|
81
|
+
const position = { x: 32, y: 190 };
|
|
89
82
|
|
|
90
83
|
const result = getDropTargetPosition(
|
|
91
84
|
verticalBlocksData,
|
|
@@ -97,7 +90,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
97
90
|
} );
|
|
98
91
|
|
|
99
92
|
it( 'returns `1` when the position is nearest to the start of the second block', () => {
|
|
100
|
-
const position = { x:
|
|
93
|
+
const position = { x: 32, y: 210 };
|
|
101
94
|
|
|
102
95
|
const result = getDropTargetPosition(
|
|
103
96
|
verticalBlocksData,
|
|
@@ -109,7 +102,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
109
102
|
} );
|
|
110
103
|
|
|
111
104
|
it( 'returns `2` when the position is nearest to the end of the second block', () => {
|
|
112
|
-
const position = { x:
|
|
105
|
+
const position = { x: 32, y: 450 };
|
|
113
106
|
|
|
114
107
|
const result = getDropTargetPosition(
|
|
115
108
|
verticalBlocksData,
|
|
@@ -121,7 +114,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
121
114
|
} );
|
|
122
115
|
|
|
123
116
|
it( 'returns `2` when the position is nearest to the start of the third block', () => {
|
|
124
|
-
const position = { x:
|
|
117
|
+
const position = { x: 32, y: 510 };
|
|
125
118
|
|
|
126
119
|
const result = getDropTargetPosition(
|
|
127
120
|
verticalBlocksData,
|
|
@@ -133,7 +126,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
133
126
|
} );
|
|
134
127
|
|
|
135
128
|
it( 'returns `3` when the position is nearest to the end of the third block', () => {
|
|
136
|
-
const position = { x:
|
|
129
|
+
const position = { x: 32, y: 880 };
|
|
137
130
|
|
|
138
131
|
const result = getDropTargetPosition(
|
|
139
132
|
verticalBlocksData,
|
|
@@ -145,7 +138,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
145
138
|
} );
|
|
146
139
|
|
|
147
140
|
it( 'returns `3` when the position is past the end of the third block', () => {
|
|
148
|
-
const position = { x:
|
|
141
|
+
const position = { x: 32, y: 920 };
|
|
149
142
|
|
|
150
143
|
const result = getDropTargetPosition(
|
|
151
144
|
verticalBlocksData,
|
|
@@ -155,9 +148,8 @@ describe( 'getDropTargetPosition', () => {
|
|
|
155
148
|
|
|
156
149
|
expect( result ).toEqual( [ 3, 'insert' ] );
|
|
157
150
|
} );
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const position = { x: 401, y: 0 };
|
|
151
|
+
it( 'returns group with index 0 when position is close to the right of the first block', () => {
|
|
152
|
+
const position = { x: 372, y: 0 };
|
|
161
153
|
|
|
162
154
|
const result = getDropTargetPosition(
|
|
163
155
|
verticalBlocksData,
|
|
@@ -165,11 +157,10 @@ describe( 'getDropTargetPosition', () => {
|
|
|
165
157
|
orientation
|
|
166
158
|
);
|
|
167
159
|
|
|
168
|
-
expect( result ).toEqual( [
|
|
160
|
+
expect( result ).toEqual( [ 0, 'group', 'right' ] );
|
|
169
161
|
} );
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const position = { x: 401, y: 300 };
|
|
162
|
+
it( 'returns group with index 1 when position is close to the left of the second block', () => {
|
|
163
|
+
const position = { x: 12, y: 212 };
|
|
173
164
|
|
|
174
165
|
const result = getDropTargetPosition(
|
|
175
166
|
verticalBlocksData,
|
|
@@ -177,7 +168,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
177
168
|
orientation
|
|
178
169
|
);
|
|
179
170
|
|
|
180
|
-
expect( result ).toEqual( [
|
|
171
|
+
expect( result ).toEqual( [ 1, 'group', 'left' ] );
|
|
181
172
|
} );
|
|
182
173
|
} );
|
|
183
174
|
|
|
@@ -267,30 +258,6 @@ describe( 'getDropTargetPosition', () => {
|
|
|
267
258
|
|
|
268
259
|
expect( result ).toEqual( [ 3, 'insert' ] );
|
|
269
260
|
} );
|
|
270
|
-
|
|
271
|
-
it( 'returns `3` when the position is nearest to the start of the last block', () => {
|
|
272
|
-
const position = { x: 0, y: 401 };
|
|
273
|
-
|
|
274
|
-
const result = getDropTargetPosition(
|
|
275
|
-
horizontalBlocksData,
|
|
276
|
-
position,
|
|
277
|
-
orientation
|
|
278
|
-
);
|
|
279
|
-
|
|
280
|
-
expect( result ).toEqual( [ 3, 'insert' ] );
|
|
281
|
-
} );
|
|
282
|
-
|
|
283
|
-
it( 'returns `4` when the position is nearest to the end of the last block', () => {
|
|
284
|
-
const position = { x: 300, y: 401 };
|
|
285
|
-
|
|
286
|
-
const result = getDropTargetPosition(
|
|
287
|
-
horizontalBlocksData,
|
|
288
|
-
position,
|
|
289
|
-
orientation
|
|
290
|
-
);
|
|
291
|
-
|
|
292
|
-
expect( result ).toEqual( [ 4, 'insert' ] );
|
|
293
|
-
} );
|
|
294
261
|
} );
|
|
295
262
|
|
|
296
263
|
describe( 'Unmodified default blocks', () => {
|
|
@@ -316,14 +283,18 @@ describe( 'getDropTargetPosition', () => {
|
|
|
316
283
|
|
|
317
284
|
// Dropping above the first block.
|
|
318
285
|
expect(
|
|
319
|
-
getDropTargetPosition(
|
|
286
|
+
getDropTargetPosition(
|
|
287
|
+
blocksData,
|
|
288
|
+
{ x: 32, y: 0 },
|
|
289
|
+
orientation
|
|
290
|
+
)
|
|
320
291
|
).toEqual( [ 0, 'replace' ] );
|
|
321
292
|
|
|
322
293
|
// Dropping on the top half of the first block.
|
|
323
294
|
expect(
|
|
324
295
|
getDropTargetPosition(
|
|
325
296
|
blocksData,
|
|
326
|
-
{ x:
|
|
297
|
+
{ x: 32, y: 20 },
|
|
327
298
|
orientation
|
|
328
299
|
)
|
|
329
300
|
).toEqual( [ 0, 'replace' ] );
|
|
@@ -332,7 +303,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
332
303
|
expect(
|
|
333
304
|
getDropTargetPosition(
|
|
334
305
|
blocksData,
|
|
335
|
-
{ x:
|
|
306
|
+
{ x: 32, y: 200 },
|
|
336
307
|
orientation
|
|
337
308
|
)
|
|
338
309
|
).toEqual( [ 0, 'replace' ] );
|
|
@@ -341,7 +312,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
341
312
|
expect(
|
|
342
313
|
getDropTargetPosition(
|
|
343
314
|
blocksData,
|
|
344
|
-
{ x:
|
|
315
|
+
{ x: 32, y: 211 },
|
|
345
316
|
orientation
|
|
346
317
|
)
|
|
347
318
|
).toEqual( [ 0, 'replace' ] );
|
|
@@ -350,7 +321,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
350
321
|
expect(
|
|
351
322
|
getDropTargetPosition(
|
|
352
323
|
blocksData,
|
|
353
|
-
{ x:
|
|
324
|
+
{ x: 32, y: 219 },
|
|
354
325
|
orientation
|
|
355
326
|
)
|
|
356
327
|
).toEqual( [ 0, 'replace' ] );
|
|
@@ -359,7 +330,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
359
330
|
expect(
|
|
360
331
|
getDropTargetPosition(
|
|
361
332
|
blocksData,
|
|
362
|
-
{ x:
|
|
333
|
+
{ x: 32, y: 230 },
|
|
363
334
|
orientation
|
|
364
335
|
)
|
|
365
336
|
).toEqual( [ 0, 'replace' ] );
|
|
@@ -368,7 +339,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
368
339
|
expect(
|
|
369
340
|
getDropTargetPosition(
|
|
370
341
|
blocksData,
|
|
371
|
-
{ x:
|
|
342
|
+
{ x: 32, y: 410 },
|
|
372
343
|
orientation
|
|
373
344
|
)
|
|
374
345
|
).toEqual( [ 2, 'insert' ] );
|
|
@@ -377,7 +348,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
377
348
|
expect(
|
|
378
349
|
getDropTargetPosition(
|
|
379
350
|
blocksData,
|
|
380
|
-
{ x:
|
|
351
|
+
{ x: 32, y: 421 },
|
|
381
352
|
orientation
|
|
382
353
|
)
|
|
383
354
|
).toEqual( [ 2, 'insert' ] );
|
|
@@ -410,7 +381,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
410
381
|
expect(
|
|
411
382
|
getDropTargetPosition(
|
|
412
383
|
blocksData,
|
|
413
|
-
{ x:
|
|
384
|
+
{ x: 32, y: 20 },
|
|
414
385
|
orientation
|
|
415
386
|
)
|
|
416
387
|
).toEqual( [ 0, 'insert' ] );
|
|
@@ -419,7 +390,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
419
390
|
expect(
|
|
420
391
|
getDropTargetPosition(
|
|
421
392
|
blocksData,
|
|
422
|
-
{ x:
|
|
393
|
+
{ x: 32, y: 200 },
|
|
423
394
|
orientation
|
|
424
395
|
)
|
|
425
396
|
).toEqual( [ 1, 'replace' ] );
|
|
@@ -428,7 +399,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
428
399
|
expect(
|
|
429
400
|
getDropTargetPosition(
|
|
430
401
|
blocksData,
|
|
431
|
-
{ x:
|
|
402
|
+
{ x: 32, y: 211 },
|
|
432
403
|
orientation
|
|
433
404
|
)
|
|
434
405
|
).toEqual( [ 1, 'replace' ] );
|
|
@@ -437,7 +408,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
437
408
|
expect(
|
|
438
409
|
getDropTargetPosition(
|
|
439
410
|
blocksData,
|
|
440
|
-
{ x:
|
|
411
|
+
{ x: 32, y: 219 },
|
|
441
412
|
orientation
|
|
442
413
|
)
|
|
443
414
|
).toEqual( [ 1, 'replace' ] );
|
|
@@ -446,7 +417,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
446
417
|
expect(
|
|
447
418
|
getDropTargetPosition(
|
|
448
419
|
blocksData,
|
|
449
|
-
{ x:
|
|
420
|
+
{ x: 32, y: 230 },
|
|
450
421
|
orientation
|
|
451
422
|
)
|
|
452
423
|
).toEqual( [ 1, 'replace' ] );
|
|
@@ -455,7 +426,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
455
426
|
expect(
|
|
456
427
|
getDropTargetPosition(
|
|
457
428
|
blocksData,
|
|
458
|
-
{ x:
|
|
429
|
+
{ x: 32, y: 410 },
|
|
459
430
|
orientation
|
|
460
431
|
)
|
|
461
432
|
).toEqual( [ 1, 'replace' ] );
|
|
@@ -464,7 +435,7 @@ describe( 'getDropTargetPosition', () => {
|
|
|
464
435
|
expect(
|
|
465
436
|
getDropTargetPosition(
|
|
466
437
|
blocksData,
|
|
467
|
-
{ x:
|
|
438
|
+
{ x: 32, y: 421 },
|
|
468
439
|
orientation
|
|
469
440
|
)
|
|
470
441
|
).toEqual( [ 1, 'replace' ] );
|
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
import { useCallback } from '@wordpress/element';
|
|
5
5
|
import {
|
|
6
6
|
cloneBlock,
|
|
7
|
+
createBlock,
|
|
7
8
|
findTransform,
|
|
8
9
|
getBlockTransforms,
|
|
9
10
|
pasteHandler,
|
|
11
|
+
store as blocksStore,
|
|
10
12
|
} from '@wordpress/blocks';
|
|
11
13
|
import { useDispatch, useSelect, useRegistry } from '@wordpress/data';
|
|
12
14
|
import { getFilesFromDataTransfer } from '@wordpress/dom';
|
|
@@ -61,6 +63,8 @@ export function parseDropEvent( event ) {
|
|
|
61
63
|
* @param {Function} moveBlocks A function that moves blocks.
|
|
62
64
|
* @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.
|
|
63
65
|
* @param {Function} clearSelectedBlock A function that clears block selection.
|
|
66
|
+
* @param {string} operation The type of operation to perform on drop. Could be `insert` or `replace` or `group`.
|
|
67
|
+
* @param {Function} getBlock A function that returns a block given its client id.
|
|
64
68
|
* @return {Function} The event handler for a block drop event.
|
|
65
69
|
*/
|
|
66
70
|
export function onBlockDrop(
|
|
@@ -70,7 +74,9 @@ export function onBlockDrop(
|
|
|
70
74
|
getClientIdsOfDescendants,
|
|
71
75
|
moveBlocks,
|
|
72
76
|
insertOrReplaceBlocks,
|
|
73
|
-
clearSelectedBlock
|
|
77
|
+
clearSelectedBlock,
|
|
78
|
+
operation,
|
|
79
|
+
getBlock
|
|
74
80
|
) {
|
|
75
81
|
return ( event ) => {
|
|
76
82
|
const {
|
|
@@ -113,6 +119,21 @@ export function onBlockDrop(
|
|
|
113
119
|
return;
|
|
114
120
|
}
|
|
115
121
|
|
|
122
|
+
// If the user is dropping a block over another block, replace both blocks
|
|
123
|
+
// with a group block containing them
|
|
124
|
+
if ( operation === 'group' ) {
|
|
125
|
+
const blocksToInsert = sourceClientIds.map( ( clientId ) =>
|
|
126
|
+
getBlock( clientId )
|
|
127
|
+
);
|
|
128
|
+
insertOrReplaceBlocks(
|
|
129
|
+
blocksToInsert,
|
|
130
|
+
true,
|
|
131
|
+
null,
|
|
132
|
+
sourceClientIds
|
|
133
|
+
);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
116
137
|
const isAtSameLevel = sourceRootClientId === targetRootClientId;
|
|
117
138
|
const draggedBlockCount = sourceClientIds.length;
|
|
118
139
|
|
|
@@ -202,7 +223,7 @@ export default function useOnBlockDrop(
|
|
|
202
223
|
targetBlockIndex,
|
|
203
224
|
options = {}
|
|
204
225
|
) {
|
|
205
|
-
const { operation = 'insert' } = options;
|
|
226
|
+
const { operation = 'insert', nearestSide = 'right' } = options;
|
|
206
227
|
const {
|
|
207
228
|
canInsertBlockType,
|
|
208
229
|
getBlockIndex,
|
|
@@ -210,7 +231,10 @@ export default function useOnBlockDrop(
|
|
|
210
231
|
getBlockOrder,
|
|
211
232
|
getBlocksByClientId,
|
|
212
233
|
getSettings,
|
|
234
|
+
getBlock,
|
|
235
|
+
isGroupable,
|
|
213
236
|
} = useSelect( blockEditorStore );
|
|
237
|
+
const { getBlockType, getGroupingBlockName } = useSelect( blocksStore );
|
|
214
238
|
const {
|
|
215
239
|
insertBlocks,
|
|
216
240
|
moveBlocksToPosition,
|
|
@@ -222,12 +246,63 @@ export default function useOnBlockDrop(
|
|
|
222
246
|
const registry = useRegistry();
|
|
223
247
|
|
|
224
248
|
const insertOrReplaceBlocks = useCallback(
|
|
225
|
-
(
|
|
249
|
+
(
|
|
250
|
+
blocks,
|
|
251
|
+
updateSelection = true,
|
|
252
|
+
initialPosition = 0,
|
|
253
|
+
clientIdsToReplace = []
|
|
254
|
+
) => {
|
|
255
|
+
const clientIds = getBlockOrder( targetRootClientId );
|
|
256
|
+
const clientId = clientIds[ targetBlockIndex ];
|
|
257
|
+
const blocksClientIds = blocks.map( ( block ) => block.clientId );
|
|
258
|
+
const areGroupableBlocks = isGroupable( [
|
|
259
|
+
...blocksClientIds,
|
|
260
|
+
clientId,
|
|
261
|
+
] );
|
|
226
262
|
if ( operation === 'replace' ) {
|
|
227
|
-
const clientIds = getBlockOrder( targetRootClientId );
|
|
228
|
-
const clientId = clientIds[ targetBlockIndex ];
|
|
229
|
-
|
|
230
263
|
replaceBlocks( clientId, blocks, undefined, initialPosition );
|
|
264
|
+
} else if ( operation === 'group' && areGroupableBlocks ) {
|
|
265
|
+
const targetBlock = getBlock( clientId );
|
|
266
|
+
if ( nearestSide === 'left' ) {
|
|
267
|
+
blocks.push( targetBlock );
|
|
268
|
+
} else {
|
|
269
|
+
blocks.unshift( targetBlock );
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const groupInnerBlocks = blocks.map( ( block ) => {
|
|
273
|
+
return createBlock(
|
|
274
|
+
block.name,
|
|
275
|
+
block.attributes,
|
|
276
|
+
block.innerBlocks
|
|
277
|
+
);
|
|
278
|
+
} );
|
|
279
|
+
|
|
280
|
+
const areAllImages = blocks.every( ( block ) => {
|
|
281
|
+
return block.name === 'core/image';
|
|
282
|
+
} );
|
|
283
|
+
|
|
284
|
+
const galleryBlock = !! getBlockType( 'core/gallery' );
|
|
285
|
+
|
|
286
|
+
const wrappedBlocks = createBlock(
|
|
287
|
+
areAllImages && galleryBlock
|
|
288
|
+
? 'core/gallery'
|
|
289
|
+
: getGroupingBlockName(),
|
|
290
|
+
{
|
|
291
|
+
layout: {
|
|
292
|
+
type: 'flex',
|
|
293
|
+
flexWrap: areAllImages ? null : 'nowrap',
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
groupInnerBlocks
|
|
297
|
+
);
|
|
298
|
+
// Need to make sure both the target block and the block being dragged are replaced
|
|
299
|
+
// otherwise the dragged block will be duplicated.
|
|
300
|
+
replaceBlocks(
|
|
301
|
+
[ clientId, ...clientIdsToReplace ],
|
|
302
|
+
wrappedBlocks,
|
|
303
|
+
undefined,
|
|
304
|
+
initialPosition
|
|
305
|
+
);
|
|
231
306
|
} else {
|
|
232
307
|
insertBlocks(
|
|
233
308
|
blocks,
|
|
@@ -239,12 +314,16 @@ export default function useOnBlockDrop(
|
|
|
239
314
|
}
|
|
240
315
|
},
|
|
241
316
|
[
|
|
242
|
-
operation,
|
|
243
317
|
getBlockOrder,
|
|
244
|
-
insertBlocks,
|
|
245
|
-
replaceBlocks,
|
|
246
|
-
targetBlockIndex,
|
|
247
318
|
targetRootClientId,
|
|
319
|
+
targetBlockIndex,
|
|
320
|
+
operation,
|
|
321
|
+
replaceBlocks,
|
|
322
|
+
getBlock,
|
|
323
|
+
nearestSide,
|
|
324
|
+
getBlockType,
|
|
325
|
+
getGroupingBlockName,
|
|
326
|
+
insertBlocks,
|
|
248
327
|
]
|
|
249
328
|
);
|
|
250
329
|
|
|
@@ -297,7 +376,9 @@ export default function useOnBlockDrop(
|
|
|
297
376
|
getClientIdsOfDescendants,
|
|
298
377
|
moveBlocks,
|
|
299
378
|
insertOrReplaceBlocks,
|
|
300
|
-
clearSelectedBlock
|
|
379
|
+
clearSelectedBlock,
|
|
380
|
+
operation,
|
|
381
|
+
getBlock
|
|
301
382
|
);
|
|
302
383
|
const _onFilesDrop = onFilesDrop(
|
|
303
384
|
targetRootClientId,
|
package/src/hooks/block-hooks.js
CHANGED
|
@@ -55,8 +55,7 @@ function BlockHooksControlPure( { name, clientId } ) {
|
|
|
55
55
|
const _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce(
|
|
56
56
|
( clientIds, block ) => {
|
|
57
57
|
// If the block doesn't exist anywhere in the block tree,
|
|
58
|
-
// we know that we have to
|
|
59
|
-
// it to disabled.
|
|
58
|
+
// we know that we have to set the toggle to disabled.
|
|
60
59
|
if ( getGlobalBlockCount( block.name ) === 0 ) {
|
|
61
60
|
return clientIds;
|
|
62
61
|
}
|
|
@@ -83,7 +82,7 @@ function BlockHooksControlPure( { name, clientId } ) {
|
|
|
83
82
|
}
|
|
84
83
|
|
|
85
84
|
const hookedBlock = candidates?.find(
|
|
86
|
-
( candidate ) => name ===
|
|
85
|
+
( candidate ) => candidate.name === block.name
|
|
87
86
|
);
|
|
88
87
|
|
|
89
88
|
// If the block exists in the designated location, we consider it hooked
|
|
@@ -96,13 +95,8 @@ function BlockHooksControlPure( { name, clientId } ) {
|
|
|
96
95
|
}
|
|
97
96
|
|
|
98
97
|
// If no hooked block was found in any of its designated locations,
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
// block inspector panel.
|
|
102
|
-
return {
|
|
103
|
-
...clientIds,
|
|
104
|
-
[ block.name ]: false,
|
|
105
|
-
};
|
|
98
|
+
// we set the toggle to disabled.
|
|
99
|
+
return clientIds;
|
|
106
100
|
},
|
|
107
101
|
{}
|
|
108
102
|
);
|
|
@@ -118,13 +112,7 @@ function BlockHooksControlPure( { name, clientId } ) {
|
|
|
118
112
|
|
|
119
113
|
const { insertBlock, removeBlock } = useDispatch( blockEditorStore );
|
|
120
114
|
|
|
121
|
-
|
|
122
|
-
const hookedBlocksForCurrentBlockIfNotPresentElsewhere =
|
|
123
|
-
hookedBlocksForCurrentBlock?.filter(
|
|
124
|
-
( block ) => hookedBlockClientIds?.[ block.name ] !== false
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
if ( ! hookedBlocksForCurrentBlockIfNotPresentElsewhere.length ) {
|
|
115
|
+
if ( ! hookedBlocksForCurrentBlock.length ) {
|
|
128
116
|
return null;
|
|
129
117
|
}
|
|
130
118
|
|
|
@@ -4,40 +4,23 @@
|
|
|
4
4
|
import { ToolbarButton, MenuItem } from '@wordpress/components';
|
|
5
5
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
6
6
|
import { __ } from '@wordpress/i18n';
|
|
7
|
-
import {
|
|
7
|
+
import { useCallback } from '@wordpress/element';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Internal dependencies
|
|
11
11
|
*/
|
|
12
12
|
import { store as blockEditorStore } from '../store';
|
|
13
13
|
import { BlockControls, BlockSettingsMenuControls } from '../components';
|
|
14
|
+
import { unlock } from '../lock-unlock';
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
( select ) => {
|
|
21
|
-
const { isBlockSelected, hasSelectedInnerBlock } =
|
|
22
|
-
select( blockEditorStore );
|
|
23
|
-
return (
|
|
24
|
-
isBlockSelected( clientId ) ||
|
|
25
|
-
hasSelectedInnerBlock( clientId, true )
|
|
26
|
-
);
|
|
27
|
-
},
|
|
28
|
-
[ clientId ]
|
|
29
|
-
);
|
|
30
|
-
useEffect( () => {
|
|
31
|
-
if ( ! isBlockOrDescendantSelected ) {
|
|
32
|
-
stopEditingAsBlock();
|
|
33
|
-
}
|
|
34
|
-
}, [ isBlockOrDescendantSelected, stopEditingAsBlock ] );
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
16
|
+
// The implementation of content locking is mainly in this file, although the mechanism
|
|
17
|
+
// to stop temporarily editing as blocks when an outside block is selected is on component StopEditingAsBlocksOnOutsideSelect
|
|
18
|
+
// at block-editor/src/components/block-list/index.js.
|
|
19
|
+
// Besides the components on this file and the file referenced above the implementation
|
|
20
|
+
// also includes artifacts on the store (actions, reducers, and selector).
|
|
37
21
|
|
|
38
22
|
function ContentLockControlsPure( { clientId, isSelected } ) {
|
|
39
23
|
const { getBlockListSettings, getSettings } = useSelect( blockEditorStore );
|
|
40
|
-
const focusModeToRevert = useRef();
|
|
41
24
|
const { templateLock, isLockedByParent, isEditingAsBlocks } = useSelect(
|
|
42
25
|
( select ) => {
|
|
43
26
|
const {
|
|
@@ -61,31 +44,15 @@ function ContentLockControlsPure( { clientId, isSelected } ) {
|
|
|
61
44
|
updateBlockListSettings,
|
|
62
45
|
__unstableSetTemporarilyEditingAsBlocks,
|
|
63
46
|
} = useDispatch( blockEditorStore );
|
|
47
|
+
const { stopEditingAsBlocks } = unlock( useDispatch( blockEditorStore ) );
|
|
64
48
|
const isContentLocked =
|
|
65
49
|
! isLockedByParent && templateLock === 'contentOnly';
|
|
66
50
|
const { __unstableMarkNextChangeAsNotPersistent, updateBlockAttributes } =
|
|
67
51
|
useDispatch( blockEditorStore );
|
|
68
52
|
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
templateLock: 'contentOnly',
|
|
73
|
-
} );
|
|
74
|
-
updateBlockListSettings( clientId, {
|
|
75
|
-
...getBlockListSettings( clientId ),
|
|
76
|
-
templateLock: 'contentOnly',
|
|
77
|
-
} );
|
|
78
|
-
updateSettings( { focusMode: focusModeToRevert.current } );
|
|
79
|
-
__unstableSetTemporarilyEditingAsBlocks();
|
|
80
|
-
}, [
|
|
81
|
-
clientId,
|
|
82
|
-
updateSettings,
|
|
83
|
-
updateBlockListSettings,
|
|
84
|
-
getBlockListSettings,
|
|
85
|
-
__unstableMarkNextChangeAsNotPersistent,
|
|
86
|
-
updateBlockAttributes,
|
|
87
|
-
__unstableSetTemporarilyEditingAsBlocks,
|
|
88
|
-
] );
|
|
53
|
+
const stopEditingAsBlockCallback = useCallback( () => {
|
|
54
|
+
stopEditingAsBlocks( clientId );
|
|
55
|
+
}, [ clientId, stopEditingAsBlocks ] );
|
|
89
56
|
|
|
90
57
|
if ( ! isContentLocked && ! isEditingAsBlocks ) {
|
|
91
58
|
return null;
|
|
@@ -99,16 +66,8 @@ function ContentLockControlsPure( { clientId, isSelected } ) {
|
|
|
99
66
|
<>
|
|
100
67
|
{ showStopEditingAsBlocks && (
|
|
101
68
|
<>
|
|
102
|
-
<StopEditingAsBlocksOnOutsideSelect
|
|
103
|
-
clientId={ clientId }
|
|
104
|
-
stopEditingAsBlock={ stopEditingAsBlock }
|
|
105
|
-
/>
|
|
106
69
|
<BlockControls group="other">
|
|
107
|
-
<ToolbarButton
|
|
108
|
-
onClick={ () => {
|
|
109
|
-
stopEditingAsBlock();
|
|
110
|
-
} }
|
|
111
|
-
>
|
|
70
|
+
<ToolbarButton onClick={ stopEditingAsBlockCallback }>
|
|
112
71
|
{ __( 'Done' ) }
|
|
113
72
|
</ToolbarButton>
|
|
114
73
|
</BlockControls>
|
|
@@ -127,11 +86,12 @@ function ContentLockControlsPure( { clientId, isSelected } ) {
|
|
|
127
86
|
...getBlockListSettings( clientId ),
|
|
128
87
|
templateLock: false,
|
|
129
88
|
} );
|
|
130
|
-
focusModeToRevert
|
|
89
|
+
const focusModeToRevert =
|
|
131
90
|
getSettings().focusMode;
|
|
132
91
|
updateSettings( { focusMode: true } );
|
|
133
92
|
__unstableSetTemporarilyEditingAsBlocks(
|
|
134
|
-
clientId
|
|
93
|
+
clientId,
|
|
94
|
+
focusModeToRevert
|
|
135
95
|
);
|
|
136
96
|
onClose();
|
|
137
97
|
} }
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { hasBlockSupport } from '@wordpress/blocks';
|
|
5
|
+
import { useSelect } from '@wordpress/data';
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import StylesEffectsPanel, {
|
|
10
|
+
useHasEffectsPanel,
|
|
11
|
+
} from '../components/global-styles/effects-panel';
|
|
12
|
+
import { InspectorControls } from '../components';
|
|
13
|
+
import { store as blockEditorStore } from '../store';
|
|
14
|
+
import { cleanEmptyObject } from './utils';
|
|
15
|
+
|
|
16
|
+
export const SHADOW_SUPPORT_KEY = 'shadow';
|
|
17
|
+
export const EFFECTS_SUPPORT_KEYS = [ SHADOW_SUPPORT_KEY ];
|
|
18
|
+
|
|
19
|
+
export function hasEffectsSupport( blockName ) {
|
|
20
|
+
return EFFECTS_SUPPORT_KEYS.some( ( key ) =>
|
|
21
|
+
hasBlockSupport( blockName, key )
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function EffectsInspectorControl( { children, resetAllFilter } ) {
|
|
26
|
+
return (
|
|
27
|
+
<InspectorControls group="effects" resetAllFilter={ resetAllFilter }>
|
|
28
|
+
{ children }
|
|
29
|
+
</InspectorControls>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
export function EffectsPanel( { clientId, setAttributes, settings } ) {
|
|
33
|
+
const isEnabled = useHasEffectsPanel( settings );
|
|
34
|
+
const value = useSelect(
|
|
35
|
+
( select ) =>
|
|
36
|
+
select( blockEditorStore ).getBlockAttributes( clientId )?.style,
|
|
37
|
+
[ clientId ]
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const onChange = ( newStyle ) => {
|
|
41
|
+
setAttributes( { style: cleanEmptyObject( newStyle ) } );
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
if ( ! isEnabled ) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<StylesEffectsPanel
|
|
50
|
+
as={ EffectsInspectorControl }
|
|
51
|
+
panelId={ clientId }
|
|
52
|
+
settings={ settings }
|
|
53
|
+
value={ value }
|
|
54
|
+
onChange={ onChange }
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
}
|
package/src/hooks/index.js
CHANGED
|
@@ -25,9 +25,9 @@ import layout from './layout';
|
|
|
25
25
|
import childLayout from './layout-child';
|
|
26
26
|
import contentLockUI from './content-lock-ui';
|
|
27
27
|
import './metadata';
|
|
28
|
-
import customFields from './custom-fields';
|
|
29
28
|
import blockHooks from './block-hooks';
|
|
30
29
|
import blockRenaming from './block-renaming';
|
|
30
|
+
import './use-bindings-attributes';
|
|
31
31
|
|
|
32
32
|
createBlockEditFilter(
|
|
33
33
|
[
|
|
@@ -39,7 +39,6 @@ createBlockEditFilter(
|
|
|
39
39
|
position,
|
|
40
40
|
layout,
|
|
41
41
|
contentLockUI,
|
|
42
|
-
window.__experimentalConnections ? customFields : null,
|
|
43
42
|
blockHooks,
|
|
44
43
|
blockRenaming,
|
|
45
44
|
].filter( Boolean )
|
|
@@ -70,6 +69,7 @@ createBlockSaveFilter( [
|
|
|
70
69
|
export { useCustomSides } from './dimensions';
|
|
71
70
|
export { useLayoutClasses, useLayoutStyles } from './layout';
|
|
72
71
|
export { getBorderClassesAndStyles, useBorderProps } from './use-border-props';
|
|
72
|
+
export { getShadowClassesAndStyles, useShadowProps } from './use-shadow-props';
|
|
73
73
|
export { getColorClassesAndStyles, useColorProps } from './use-color-props';
|
|
74
74
|
export { getSpacingClassesAndStyles } from './use-spacing-props';
|
|
75
75
|
export { getTypographyClassesAndStyles } from './use-typography-props';
|