@wordpress/block-editor 12.16.1-next.79a6196f.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 +6 -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-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/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 +14 -0
- 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 +7 -6
- 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/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-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/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 +2 -0
- 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 +9 -8
- 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/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-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/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 -0
- 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 +10 -6
- 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/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/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/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/utils/block-variation-transforms.js +0 -38
- package/src/utils/test/block-variation-transforms.js +0 -94
|
@@ -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
|
@@ -27,6 +27,7 @@ import contentLockUI from './content-lock-ui';
|
|
|
27
27
|
import './metadata';
|
|
28
28
|
import blockHooks from './block-hooks';
|
|
29
29
|
import blockRenaming from './block-renaming';
|
|
30
|
+
import './use-bindings-attributes';
|
|
30
31
|
|
|
31
32
|
createBlockEditFilter(
|
|
32
33
|
[
|
|
@@ -68,6 +69,7 @@ createBlockSaveFilter( [
|
|
|
68
69
|
export { useCustomSides } from './dimensions';
|
|
69
70
|
export { useLayoutClasses, useLayoutStyles } from './layout';
|
|
70
71
|
export { getBorderClassesAndStyles, useBorderProps } from './use-border-props';
|
|
72
|
+
export { getShadowClassesAndStyles, useShadowProps } from './use-shadow-props';
|
|
71
73
|
export { getColorClassesAndStyles, useColorProps } from './use-color-props';
|
|
72
74
|
export { getSpacingClassesAndStyles } from './use-spacing-props';
|
|
73
75
|
export { getTypographyClassesAndStyles } from './use-typography-props';
|
|
@@ -28,6 +28,7 @@ createBlockSaveFilter( [
|
|
|
28
28
|
] );
|
|
29
29
|
|
|
30
30
|
export { getBorderClassesAndStyles, useBorderProps } from './use-border-props';
|
|
31
|
+
export { getShadowClassesAndStyles, useShadowProps } from './use-shadow-props';
|
|
31
32
|
export { getColorClassesAndStyles, useColorProps } from './use-color-props';
|
|
32
33
|
export { getSpacingClassesAndStyles } from './use-spacing-props';
|
|
33
34
|
export { useCachedTruthy } from './use-cached-truthy';
|
package/src/hooks/style.js
CHANGED
|
@@ -27,6 +27,11 @@ import {
|
|
|
27
27
|
SPACING_SUPPORT_KEY,
|
|
28
28
|
DimensionsPanel,
|
|
29
29
|
} from './dimensions';
|
|
30
|
+
import {
|
|
31
|
+
EFFECTS_SUPPORT_KEYS,
|
|
32
|
+
SHADOW_SUPPORT_KEY,
|
|
33
|
+
EffectsPanel,
|
|
34
|
+
} from './effects';
|
|
30
35
|
import {
|
|
31
36
|
shouldSkipSerialization,
|
|
32
37
|
useStyleOverride,
|
|
@@ -37,6 +42,7 @@ import { useBlockEditingMode } from '../components/block-editing-mode';
|
|
|
37
42
|
|
|
38
43
|
const styleSupportKeys = [
|
|
39
44
|
...TYPOGRAPHY_SUPPORT_KEYS,
|
|
45
|
+
...EFFECTS_SUPPORT_KEYS,
|
|
40
46
|
BORDER_SUPPORT_KEY,
|
|
41
47
|
COLOR_SUPPORT_KEY,
|
|
42
48
|
DIMENSIONS_SUPPORT_KEY,
|
|
@@ -110,6 +116,7 @@ const skipSerializationPathsEdit = {
|
|
|
110
116
|
[ `${ SPACING_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [
|
|
111
117
|
SPACING_SUPPORT_KEY,
|
|
112
118
|
],
|
|
119
|
+
[ `${ SHADOW_SUPPORT_KEY }` ]: [ SHADOW_SUPPORT_KEY ],
|
|
113
120
|
};
|
|
114
121
|
|
|
115
122
|
/**
|
|
@@ -336,6 +343,7 @@ function BlockStyleControls( {
|
|
|
336
343
|
<TypographyPanel { ...passedProps } />
|
|
337
344
|
<BorderPanel { ...passedProps } />
|
|
338
345
|
<DimensionsPanel { ...passedProps } />
|
|
346
|
+
<EffectsPanel { ...passedProps } />
|
|
339
347
|
</>
|
|
340
348
|
);
|
|
341
349
|
}
|
package/src/hooks/supports.js
CHANGED
|
@@ -59,8 +59,10 @@ const TYPOGRAPHY_SUPPORT_KEYS = [
|
|
|
59
59
|
WRITING_MODE_SUPPORT_KEY,
|
|
60
60
|
LETTER_SPACING_SUPPORT_KEY,
|
|
61
61
|
];
|
|
62
|
+
const EFFECTS_SUPPORT_KEYS = [ 'shadow' ];
|
|
62
63
|
const SPACING_SUPPORT_KEY = 'spacing';
|
|
63
64
|
const styleSupportKeys = [
|
|
65
|
+
...EFFECTS_SUPPORT_KEYS,
|
|
64
66
|
...TYPOGRAPHY_SUPPORT_KEYS,
|
|
65
67
|
BORDER_SUPPORT_KEY,
|
|
66
68
|
COLOR_SUPPORT_KEY,
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { hasEffectsSupport } from '../effects';
|
|
5
|
+
|
|
6
|
+
describe( 'effects', () => {
|
|
7
|
+
describe( 'hasEffectsSupport', () => {
|
|
8
|
+
it( 'should return false if the block does not support effects', () => {
|
|
9
|
+
const settings = {
|
|
10
|
+
supports: {
|
|
11
|
+
shadow: false,
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
expect( hasEffectsSupport( settings ) ).toBe( false );
|
|
16
|
+
} );
|
|
17
|
+
|
|
18
|
+
it( 'should return true if the block supports effects', () => {
|
|
19
|
+
const settings = {
|
|
20
|
+
supports: {
|
|
21
|
+
shadow: true,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
expect( hasEffectsSupport( settings ) ).toBe( true );
|
|
26
|
+
} );
|
|
27
|
+
|
|
28
|
+
it( 'should return true if the block supports effects and other features', () => {
|
|
29
|
+
const settings = {
|
|
30
|
+
supports: {
|
|
31
|
+
shadow: true,
|
|
32
|
+
align: true,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
expect( hasEffectsSupport( settings ) ).toBe( true );
|
|
37
|
+
} );
|
|
38
|
+
} );
|
|
39
|
+
} );
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useSelect } from '@wordpress/data';
|
|
5
|
-
import {
|
|
5
|
+
import { memo } from '@wordpress/element';
|
|
6
6
|
import { PanelBody } from '@wordpress/components';
|
|
7
7
|
import { __ } from '@wordpress/i18n';
|
|
8
8
|
|
|
@@ -57,4 +57,4 @@ function TypographyPanelPure( { clientId, setAttributes, settings } ) {
|
|
|
57
57
|
// We don't want block controls to re-render when typing inside a block. `pure`
|
|
58
58
|
// will prevent re-renders unless props change, so only pass the needed props
|
|
59
59
|
// and not the whole attributes object.
|
|
60
|
-
export const TypographyPanel =
|
|
60
|
+
export const TypographyPanel = memo( TypographyPanelPure );
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { getBlockType } from '@wordpress/blocks';
|
|
5
|
+
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
6
|
+
import { useRegistry, useSelect } from '@wordpress/data';
|
|
7
|
+
import { addFilter } from '@wordpress/hooks';
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import { store as blockEditorStore } from '../store';
|
|
12
|
+
import { useBlockEditContext } from '../components/block-edit/context';
|
|
13
|
+
import { unlock } from '../lock-unlock';
|
|
14
|
+
|
|
15
|
+
/** @typedef {import('@wordpress/compose').WPHigherOrderComponent} WPHigherOrderComponent */
|
|
16
|
+
/** @typedef {import('@wordpress/blocks').WPBlockSettings} WPBlockSettings */
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Given a binding of block attributes, returns a higher order component that
|
|
20
|
+
* overrides its `attributes` and `setAttributes` props to sync any changes needed.
|
|
21
|
+
*
|
|
22
|
+
* @return {WPHigherOrderComponent} Higher-order component.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const BLOCK_BINDINGS_ALLOWED_BLOCKS = {
|
|
26
|
+
'core/paragraph': [ 'content' ],
|
|
27
|
+
'core/heading': [ 'content' ],
|
|
28
|
+
'core/image': [ 'url', 'title', 'alt' ],
|
|
29
|
+
'core/button': [ 'url', 'text', 'linkTarget' ],
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const createEditFunctionWithBindingsAttribute = () =>
|
|
33
|
+
createHigherOrderComponent(
|
|
34
|
+
( BlockEdit ) => ( props ) => {
|
|
35
|
+
const { clientId, name: blockName } = useBlockEditContext();
|
|
36
|
+
const { getBlockBindingsSource } = unlock(
|
|
37
|
+
useSelect( blockEditorStore )
|
|
38
|
+
);
|
|
39
|
+
const { getBlockAttributes, updateBlockAttributes } =
|
|
40
|
+
useSelect( blockEditorStore );
|
|
41
|
+
|
|
42
|
+
const updatedAttributes = getBlockAttributes( clientId );
|
|
43
|
+
if ( updatedAttributes?.metadata?.bindings ) {
|
|
44
|
+
Object.entries( updatedAttributes.metadata.bindings ).forEach(
|
|
45
|
+
( [ attributeName, settings ] ) => {
|
|
46
|
+
const source = getBlockBindingsSource(
|
|
47
|
+
settings.source.name
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
if ( source ) {
|
|
51
|
+
// Second argument (`updateMetaValue`) will be used to update the value in the future.
|
|
52
|
+
const {
|
|
53
|
+
placeholder,
|
|
54
|
+
useValue: [ metaValue = null ] = [],
|
|
55
|
+
} = source.useSource(
|
|
56
|
+
props,
|
|
57
|
+
settings.source.attributes
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
if ( placeholder && ! metaValue ) {
|
|
61
|
+
// If the attribute is `src` or `href`, a placeholder can't be used because it is not a valid url.
|
|
62
|
+
// Adding this workaround until attributes and metadata fields types are improved and include `url`.
|
|
63
|
+
const htmlAttribute =
|
|
64
|
+
getBlockType( blockName ).attributes[
|
|
65
|
+
attributeName
|
|
66
|
+
].attribute;
|
|
67
|
+
if (
|
|
68
|
+
htmlAttribute === 'src' ||
|
|
69
|
+
htmlAttribute === 'href'
|
|
70
|
+
) {
|
|
71
|
+
updatedAttributes[ attributeName ] = null;
|
|
72
|
+
} else {
|
|
73
|
+
updatedAttributes[ attributeName ] =
|
|
74
|
+
placeholder;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if ( metaValue ) {
|
|
79
|
+
updatedAttributes[ attributeName ] = metaValue;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const registry = useRegistry();
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<>
|
|
90
|
+
<BlockEdit
|
|
91
|
+
key="edit"
|
|
92
|
+
attributes={ updatedAttributes }
|
|
93
|
+
setAttributes={ ( newAttributes, blockId ) =>
|
|
94
|
+
registry.batch( () =>
|
|
95
|
+
updateBlockAttributes( blockId, newAttributes )
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
{ ...props }
|
|
99
|
+
/>
|
|
100
|
+
</>
|
|
101
|
+
);
|
|
102
|
+
},
|
|
103
|
+
'useBoundAttributes'
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Filters a registered block's settings to enhance a block's `edit` component
|
|
108
|
+
* to upgrade bound attributes.
|
|
109
|
+
*
|
|
110
|
+
* @param {WPBlockSettings} settings Registered block settings.
|
|
111
|
+
*
|
|
112
|
+
* @return {WPBlockSettings} Filtered block settings.
|
|
113
|
+
*/
|
|
114
|
+
function shimAttributeSource( settings ) {
|
|
115
|
+
if ( ! ( settings.name in BLOCK_BINDINGS_ALLOWED_BLOCKS ) ) {
|
|
116
|
+
return settings;
|
|
117
|
+
}
|
|
118
|
+
settings.edit = createEditFunctionWithBindingsAttribute()( settings.edit );
|
|
119
|
+
|
|
120
|
+
return settings;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
addFilter(
|
|
124
|
+
'blocks.registerBlockType',
|
|
125
|
+
'core/editor/custom-sources-backwards-compatibility/shim-attribute-source',
|
|
126
|
+
shimAttributeSource
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// Add the context to all blocks.
|
|
130
|
+
addFilter(
|
|
131
|
+
'blocks.registerBlockType',
|
|
132
|
+
'core/block-bindings-ui',
|
|
133
|
+
( settings, name ) => {
|
|
134
|
+
if ( ! ( name in BLOCK_BINDINGS_ALLOWED_BLOCKS ) ) {
|
|
135
|
+
return settings;
|
|
136
|
+
}
|
|
137
|
+
const contextItems = [ 'postId', 'postType', 'queryId' ];
|
|
138
|
+
const usesContextArray = settings.usesContext;
|
|
139
|
+
const oldUsesContextArray = new Set( usesContextArray );
|
|
140
|
+
contextItems.forEach( ( item ) => {
|
|
141
|
+
if ( ! oldUsesContextArray.has( item ) ) {
|
|
142
|
+
usesContextArray.push( item );
|
|
143
|
+
}
|
|
144
|
+
} );
|
|
145
|
+
settings.usesContext = usesContextArray;
|
|
146
|
+
return settings;
|
|
147
|
+
}
|
|
148
|
+
);
|