@wordpress/block-editor 12.17.0 → 12.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +32 -0
- package/build/components/block-draggable/index.js +11 -3
- package/build/components/block-draggable/index.js.map +1 -1
- package/build/components/block-edit/context.js +3 -1
- package/build/components/block-edit/context.js.map +1 -1
- package/build/components/block-edit/index.js +4 -2
- package/build/components/block-edit/index.js.map +1 -1
- package/build/components/block-editing-mode/index.js +6 -3
- package/build/components/block-editing-mode/index.js.map +1 -1
- package/build/components/block-inspector/index.js +5 -2
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/block.js +4 -3
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/block.native.js +9 -5
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/index.js +30 -4
- package/build/components/block-list/index.js.map +1 -1
- package/build/components/block-list/private-block-context.js +1 -1
- package/build/components/block-list/private-block-context.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +1 -1
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-lock/toolbar.js +8 -2
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-popover/inbetween.js +15 -3
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-preview/auto.js +1 -1
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-removal-warning-modal/index.js +3 -2
- package/build/components/block-removal-warning-modal/index.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +2 -4
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-switcher/block-transformations-menu.js +12 -1
- package/build/components/block-switcher/block-transformations-menu.js.map +1 -1
- package/build/components/block-switcher/index.js +119 -90
- package/build/components/block-switcher/index.js.map +1 -1
- package/build/components/block-tools/insertion-point.js +10 -3
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/dimensions-tool/aspect-ratio-tool.js +2 -1
- package/build/components/dimensions-tool/aspect-ratio-tool.js.map +1 -1
- package/build/components/font-sizes/fluid-utils.js +7 -1
- package/build/components/font-sizes/fluid-utils.js.map +1 -1
- package/build/components/global-styles/border-panel.js +5 -14
- package/build/components/global-styles/border-panel.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +30 -5
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/effects-panel.js +7 -1
- package/build/components/global-styles/effects-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +11 -8
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +31 -14
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +6 -0
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/iframe/get-compatibility-styles.js +99 -0
- package/build/components/iframe/get-compatibility-styles.js.map +1 -0
- package/build/components/iframe/index.js +2 -3
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/index.js +16 -2
- package/build/components/index.js.map +1 -1
- package/build/components/index.native.js +16 -2
- package/build/components/index.native.js.map +1 -1
- package/build/components/inspector-controls/groups.js +2 -0
- package/build/components/inspector-controls/groups.js.map +1 -1
- package/build/components/inspector-controls-tabs/styles-tab.js +3 -0
- package/build/components/inspector-controls-tabs/styles-tab.js.map +1 -1
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +3 -2
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
- package/build/components/link-control/link-preview.js +30 -26
- package/build/components/link-control/link-preview.js.map +1 -1
- package/build/components/link-control/search-input.js +1 -9
- package/build/components/link-control/search-input.js.map +1 -1
- package/build/components/list-view/block-contents.js +3 -1
- package/build/components/list-view/block-contents.js.map +1 -1
- package/build/components/list-view/block.js +10 -1
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +29 -8
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/drop-indicator.js +100 -32
- package/build/components/list-view/drop-indicator.js.map +1 -1
- package/build/components/list-view/index.js +52 -4
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/leaf.js +2 -2
- package/build/components/list-view/leaf.js.map +1 -1
- package/build/components/list-view/use-list-view-block-indexes.js +30 -0
- package/build/components/list-view/use-list-view-block-indexes.js.map +1 -0
- package/build/components/list-view/use-list-view-drop-zone.js +56 -5
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/list-view/utils.js +92 -0
- package/build/components/list-view/utils.js.map +1 -1
- package/build/components/provider/index.js +1 -1
- package/build/components/provider/index.js.map +1 -1
- package/build/components/recursion-provider/index.js +21 -0
- package/build/components/recursion-provider/index.js.map +1 -1
- package/build/components/rich-text/index.js +30 -6
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/native/index.native.js +9 -9
- package/build/components/rich-text/native/index.native.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +30 -7
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-on-block-drop/index.js +50 -8
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/hooks/block-hooks.js +5 -14
- package/build/hooks/block-hooks.js.map +1 -1
- package/build/hooks/content-lock-ui.js +17 -42
- package/build/hooks/content-lock-ui.js.map +1 -1
- package/build/hooks/dimensions.js +71 -1
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/effects.js +66 -0
- package/build/hooks/effects.js.map +1 -0
- package/build/hooks/index.js +17 -4
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/index.native.js +13 -0
- package/build/hooks/index.native.js.map +1 -1
- package/build/hooks/style.js +9 -2
- package/build/hooks/style.js.map +1 -1
- package/build/hooks/supports.js +2 -1
- package/build/hooks/supports.js.map +1 -1
- package/build/hooks/typography.native.js +2 -2
- package/build/hooks/typography.native.js.map +1 -1
- package/build/hooks/use-bindings-attributes.js +115 -0
- package/build/hooks/use-bindings-attributes.js.map +1 -0
- package/build/hooks/use-shadow-props.js +46 -0
- package/build/hooks/use-shadow-props.js.map +1 -0
- package/build/hooks/utils.js +12 -7
- package/build/hooks/utils.js.map +1 -1
- package/build/index.js +14 -0
- package/build/index.js.map +1 -1
- package/build/store/actions.js +10 -6
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +2 -0
- package/build/store/index.js.map +1 -1
- package/build/store/private-actions.js +37 -0
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +60 -9
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +44 -3
- package/build/store/reducer.js.map +1 -1
- package/build/store/resolvers.js +27 -0
- package/build/store/resolvers.js.map +1 -0
- package/build/store/selectors.js +94 -56
- package/build/store/selectors.js.map +1 -1
- package/build/store/utils.js +5 -26
- package/build/store/utils.js.map +1 -1
- package/build/utils/index.js +0 -16
- package/build/utils/index.js.map +1 -1
- package/build/utils/math.js +13 -0
- package/build/utils/math.js.map +1 -1
- package/build/utils/object.js +17 -0
- package/build/utils/object.js.map +1 -1
- package/build/utils/transform-styles/index.js +37 -27
- package/build/utils/transform-styles/index.js.map +1 -1
- package/build-module/components/block-draggable/index.js +11 -3
- package/build-module/components/block-draggable/index.js.map +1 -1
- package/build-module/components/block-edit/context.js +1 -0
- package/build-module/components/block-edit/context.js.map +1 -1
- package/build-module/components/block-edit/index.js +5 -3
- package/build-module/components/block-edit/index.js.map +1 -1
- package/build-module/components/block-editing-mode/index.js +7 -4
- package/build-module/components/block-editing-mode/index.js.map +1 -1
- package/build-module/components/block-inspector/index.js +5 -2
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/block.js +6 -5
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/block.native.js +11 -7
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/index.js +31 -5
- package/build-module/components/block-list/index.js.map +1 -1
- package/build-module/components/block-list/private-block-context.js +1 -1
- package/build-module/components/block-list/private-block-context.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-lock/toolbar.js +8 -2
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +15 -3
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-preview/auto.js +3 -3
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-removal-warning-modal/index.js +3 -2
- package/build-module/components/block-removal-warning-modal/index.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +2 -4
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-switcher/block-transformations-menu.js +12 -1
- package/build-module/components/block-switcher/block-transformations-menu.js.map +1 -1
- package/build-module/components/block-switcher/index.js +116 -86
- package/build-module/components/block-switcher/index.js.map +1 -1
- package/build-module/components/block-tools/insertion-point.js +10 -3
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/dimensions-tool/aspect-ratio-tool.js +2 -1
- package/build-module/components/dimensions-tool/aspect-ratio-tool.js.map +1 -1
- package/build-module/components/font-sizes/fluid-utils.js +7 -1
- package/build-module/components/font-sizes/fluid-utils.js.map +1 -1
- package/build-module/components/global-styles/border-panel.js +5 -14
- package/build-module/components/global-styles/border-panel.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +30 -5
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/effects-panel.js +7 -1
- package/build-module/components/global-styles/effects-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +11 -8
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +32 -15
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +6 -0
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/iframe/get-compatibility-styles.js +93 -0
- package/build-module/components/iframe/get-compatibility-styles.js.map +1 -0
- package/build-module/components/iframe/index.js +2 -3
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/index.js +1 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/index.native.js +1 -1
- package/build-module/components/index.native.js.map +1 -1
- package/build-module/components/inspector-controls/groups.js +2 -0
- package/build-module/components/inspector-controls/groups.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/styles-tab.js +3 -0
- package/build-module/components/inspector-controls-tabs/styles-tab.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +3 -2
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
- package/build-module/components/link-control/link-preview.js +32 -28
- package/build-module/components/link-control/link-preview.js.map +1 -1
- package/build-module/components/link-control/search-input.js +1 -8
- package/build-module/components/link-control/search-input.js.map +1 -1
- package/build-module/components/list-view/block-contents.js +3 -1
- package/build-module/components/list-view/block-contents.js.map +1 -1
- package/build-module/components/list-view/block.js +10 -1
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +30 -9
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/drop-indicator.js +99 -32
- package/build-module/components/list-view/drop-indicator.js.map +1 -1
- package/build-module/components/list-view/index.js +54 -6
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/leaf.js +2 -2
- package/build-module/components/list-view/leaf.js.map +1 -1
- package/build-module/components/list-view/use-list-view-block-indexes.js +23 -0
- package/build-module/components/list-view/use-list-view-block-indexes.js.map +1 -0
- package/build-module/components/list-view/use-list-view-drop-zone.js +58 -7
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/list-view/utils.js +91 -0
- package/build-module/components/list-view/utils.js.map +1 -1
- package/build-module/components/provider/index.js +1 -1
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/recursion-provider/index.js +17 -0
- package/build-module/components/recursion-provider/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +30 -6
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/native/index.native.js +9 -9
- package/build-module/components/rich-text/native/index.native.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +31 -8
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/index.js +51 -9
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/hooks/block-hooks.js +5 -14
- package/build-module/hooks/block-hooks.js.map +1 -1
- package/build-module/hooks/content-lock-ui.js +19 -43
- package/build-module/hooks/content-lock-ui.js.map +1 -1
- package/build-module/hooks/dimensions.js +70 -2
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/effects.js +51 -0
- package/build-module/hooks/effects.js.map +1 -0
- package/build-module/hooks/index.js +5 -3
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/index.native.js +1 -0
- package/build-module/hooks/index.native.js.map +1 -1
- package/build-module/hooks/style.js +9 -2
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/hooks/supports.js +2 -1
- package/build-module/hooks/supports.js.map +1 -1
- package/build-module/hooks/typography.native.js +2 -2
- package/build-module/hooks/typography.native.js.map +1 -1
- package/build-module/hooks/use-bindings-attributes.js +112 -0
- package/build-module/hooks/use-bindings-attributes.js.map +1 -0
- package/build-module/hooks/use-shadow-props.js +39 -0
- package/build-module/hooks/use-shadow-props.js.map +1 -0
- package/build-module/hooks/utils.js +14 -9
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/store/actions.js +10 -6
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +2 -0
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/private-actions.js +35 -0
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +53 -8
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +43 -3
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/resolvers.js +20 -0
- package/build-module/store/resolvers.js.map +1 -0
- package/build-module/store/selectors.js +89 -52
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/utils.js +3 -23
- package/build-module/store/utils.js.map +1 -1
- package/build-module/utils/index.js +0 -1
- package/build-module/utils/index.js.map +1 -1
- package/build-module/utils/math.js +12 -0
- package/build-module/utils/math.js.map +1 -1
- package/build-module/utils/object.js +16 -0
- package/build-module/utils/object.js.map +1 -1
- package/build-module/utils/transform-styles/index.js +36 -27
- package/build-module/utils/transform-styles/index.js.map +1 -1
- package/build-style/content-rtl.css +33 -16
- package/build-style/content.css +33 -16
- package/build-style/default-editor-styles-rtl.css +1 -1
- package/build-style/default-editor-styles.css +1 -1
- package/build-style/style-rtl.css +169 -114
- package/build-style/style.css +169 -114
- package/package.json +31 -31
- package/src/components/block-canvas/style.scss +8 -1
- package/src/components/block-draggable/index.js +16 -5
- package/src/components/block-edit/context.js +1 -0
- package/src/components/block-edit/index.js +4 -0
- package/src/components/block-editing-mode/index.js +12 -7
- package/src/components/block-inspector/index.js +5 -2
- package/src/components/block-list/block.js +5 -4
- package/src/components/block-list/block.native.js +13 -3
- package/src/components/block-list/content.scss +34 -5
- package/src/components/block-list/index.js +52 -16
- package/src/components/block-list/private-block-context.js +1 -1
- package/src/components/block-list/use-in-between-inserter.js +1 -2
- package/src/components/block-lock/toolbar.js +10 -2
- package/src/components/block-popover/inbetween.js +22 -2
- package/src/components/block-preview/auto.js +3 -3
- package/src/components/block-removal-warning-modal/index.js +3 -2
- package/src/components/block-settings-menu/block-settings-dropdown.js +2 -7
- package/src/components/block-switcher/block-transformations-menu.js +18 -1
- package/src/components/block-switcher/index.js +133 -111
- package/src/components/block-switcher/style.scss +6 -4
- package/src/components/block-switcher/test/index.js +113 -230
- package/src/components/block-toolbar/style.scss +22 -18
- package/src/components/block-tools/insertion-point.js +15 -2
- package/src/components/block-tools/style.scss +8 -7
- package/src/components/dimensions-tool/aspect-ratio-tool.js +4 -1
- package/src/components/font-sizes/fluid-utils.js +8 -2
- package/src/components/font-sizes/test/fluid-utils.js +9 -0
- package/src/components/global-styles/border-panel.js +7 -17
- package/src/components/global-styles/dimensions-panel.js +50 -1
- package/src/components/global-styles/effects-panel.js +16 -1
- package/src/components/global-styles/hooks.js +11 -6
- package/src/components/global-styles/typography-panel.js +45 -13
- package/src/components/global-styles/use-global-styles-output.js +6 -0
- package/src/components/iframe/get-compatibility-styles.js +120 -0
- package/src/components/iframe/index.js +2 -3
- package/src/components/index.js +4 -2
- package/src/components/index.native.js +4 -2
- package/src/components/inspector-controls/groups.js +2 -0
- package/src/components/inspector-controls-tabs/styles-tab.js +1 -0
- package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +2 -0
- package/src/components/link-control/link-preview.js +31 -55
- package/src/components/link-control/search-input.js +1 -9
- package/src/components/link-control/style.scss +31 -85
- package/src/components/link-control/test/index.js +2 -1
- package/src/components/list-view/block-contents.js +5 -1
- package/src/components/list-view/block.js +9 -0
- package/src/components/list-view/branch.js +30 -10
- package/src/components/list-view/drop-indicator.js +139 -46
- package/src/components/list-view/index.js +74 -3
- package/src/components/list-view/leaf.js +2 -2
- package/src/components/list-view/style.scss +102 -13
- package/src/components/list-view/test/use-list-view-drop-zone.js +4 -0
- package/src/components/list-view/test/utils.js +218 -1
- package/src/components/list-view/use-list-view-block-indexes.js +29 -0
- package/src/components/list-view/use-list-view-drop-zone.js +78 -6
- package/src/components/list-view/utils.js +116 -0
- package/src/components/provider/index.js +3 -1
- package/src/components/recursion-provider/README.md +2 -2
- package/src/components/recursion-provider/index.js +17 -0
- package/src/components/rich-text/index.js +48 -10
- package/src/components/rich-text/native/index.native.js +10 -10
- package/src/components/use-block-drop-zone/index.js +60 -19
- package/src/components/use-block-drop-zone/test/index.js +32 -61
- package/src/components/use-on-block-drop/index.js +92 -11
- package/src/hooks/block-hooks.js +5 -17
- package/src/hooks/content-lock-ui.js +15 -55
- package/src/hooks/dimensions.js +74 -3
- package/src/hooks/effects.js +57 -0
- package/src/hooks/index.js +4 -2
- package/src/hooks/index.native.js +1 -0
- package/src/hooks/style.js +12 -0
- package/src/hooks/supports.js +2 -0
- package/src/hooks/test/effects.js +39 -0
- package/src/hooks/typography.native.js +2 -2
- package/src/hooks/use-bindings-attributes.js +148 -0
- package/src/hooks/use-shadow-props.js +37 -0
- package/src/hooks/utils.js +30 -10
- package/src/index.js +2 -0
- package/src/store/actions.js +9 -4
- package/src/store/index.js +2 -0
- package/src/store/private-actions.js +32 -0
- package/src/store/private-selectors.js +78 -21
- package/src/store/reducer.js +49 -2
- package/src/store/resolvers.js +17 -0
- package/src/store/selectors.js +169 -161
- package/src/store/test/registry-selectors.js +431 -0
- package/src/store/test/selectors.js +14 -400
- package/src/store/utils.js +10 -33
- package/src/style.scss +0 -1
- package/src/utils/index.js +0 -1
- package/src/utils/math.js +12 -0
- package/src/utils/object.js +16 -0
- package/src/utils/transform-styles/index.js +52 -37
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/iframe/use-compatibility-styles.js +0 -100
- package/build/components/iframe/use-compatibility-styles.js.map +0 -1
- package/build/hooks/custom-fields.js +0 -106
- package/build/hooks/custom-fields.js.map +0 -1
- package/build/utils/block-variation-transforms.js +0 -42
- package/build/utils/block-variation-transforms.js.map +0 -1
- package/build-module/components/iframe/use-compatibility-styles.js +0 -94
- package/build-module/components/iframe/use-compatibility-styles.js.map +0 -1
- package/build-module/hooks/custom-fields.js +0 -99
- package/build-module/hooks/custom-fields.js.map +0 -1
- package/build-module/utils/block-variation-transforms.js +0 -35
- package/build-module/utils/block-variation-transforms.js.map +0 -1
- package/src/components/block-switcher/test/__snapshots__/index.js.snap +0 -116
- package/src/components/contrast-checker/style.scss +0 -3
- package/src/components/iframe/use-compatibility-styles.js +0 -122
- package/src/hooks/custom-fields.js +0 -115
- package/src/utils/block-variation-transforms.js +0 -38
- package/src/utils/test/block-variation-transforms.js +0 -94
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useDispatch","useSelect","useRegistry","useCallback","useState","useThrottle","__experimentalUseDropZone","useDropZone","isRTL","isUnmodifiedDefaultBlock","getIsUnmodifiedDefaultBlock","store","blocksStore","useOnBlockDrop","getDistanceToNearestEdge","isPointContainedByRect","blockEditorStore","THRESHOLD_DISTANCE","MINIMUM_HEIGHT_FOR_THRESHOLD","MINIMUM_WIDTH_FOR_THRESHOLD","getDropTargetPosition","blocksData","position","orientation","options","allowedEdges","nearestIndex","insertPosition","minDistance","Infinity","dropZoneElement","parentBlockOrientation","rootBlockIndex","rect","getBoundingClientRect","distance","edge","height","isRightToLeft","width","forEach","blockIndex","adjacentIndex","isNearestBlockUnmodifiedDefaultBlock","isAdjacentBlockUnmodifiedDefaultBlock","insertionIndex","isDropTargetValid","getBlockType","allowedBlocks","draggedBlockNames","targetBlockName","areBlocksAllowed","allowedBlockNames","map","name","every","includes","draggedBlockTypes","targetMatchesDraggedBlockParents","block","allowedParentName","parent","useBlockDropZone","rootClientId","targetRootClientId","parentClientId","parentBlockClientId","isDisabled","registry","dropTarget","setDropTarget","index","operation","getBlockListSettings","getBlocks","getBlockIndex","getDraggedBlockClientIds","getBlockNamesByClientId","getAllowedBlocks","showInsertionPoint","hideInsertionPoint","onBlockDrop","throttled","event","ownerDocument","isBlockDroppingAllowed","blocks","length","batch","clientId","getElementById","targetIndex","x","clientX","y","clientY","undefined","insertionPointClientId","onDrop","onDragOver","currentTarget","onDragLeave","cancel","onDragEnd"],"sources":["@wordpress/block-editor/src/components/use-block-drop-zone/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect, useRegistry } from '@wordpress/data';\nimport { useCallback, useState } from '@wordpress/element';\nimport {\n\tuseThrottle,\n\t__experimentalUseDropZone as useDropZone,\n} from '@wordpress/compose';\nimport { isRTL } from '@wordpress/i18n';\nimport {\n\tisUnmodifiedDefaultBlock as getIsUnmodifiedDefaultBlock,\n\tstore as blocksStore,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport useOnBlockDrop from '../use-on-block-drop';\nimport {\n\tgetDistanceToNearestEdge,\n\tisPointContainedByRect,\n} from '../../utils/math';\nimport { store as blockEditorStore } from '../../store';\n\nconst THRESHOLD_DISTANCE = 30;\nconst MINIMUM_HEIGHT_FOR_THRESHOLD = 120;\nconst MINIMUM_WIDTH_FOR_THRESHOLD = 120;\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n/** @typedef {import('../use-on-block-drop/types').WPDropOperation} WPDropOperation */\n\n/**\n * The orientation of a block list.\n *\n * @typedef {'horizontal'|'vertical'|undefined} WPBlockListOrientation\n */\n\n/**\n * The insert position when dropping a block.\n *\n * @typedef {'before'|'after'} WPInsertPosition\n */\n\n/**\n * @typedef {Object} WPBlockData\n * @property {boolean} isUnmodifiedDefaultBlock Is the block unmodified default block.\n * @property {() => DOMRect} getBoundingClientRect Get the bounding client rect of the block.\n * @property {number} blockIndex The index of the block.\n */\n\n/**\n * Get the drop target position from a given drop point and the orientation.\n *\n * @param {WPBlockData[]} blocksData The block data list.\n * @param {WPPoint} position The position of the item being dragged.\n * @param {WPBlockListOrientation} orientation The orientation of the block list.\n * @param {Object} options Additional options.\n * @return {[number, WPDropOperation]} The drop target position.\n */\nexport function getDropTargetPosition(\n\tblocksData,\n\tposition,\n\torientation = 'vertical',\n\toptions = {}\n) {\n\tconst allowedEdges =\n\t\torientation === 'horizontal'\n\t\t\t? [ 'left', 'right' ]\n\t\t\t: [ 'top', 'bottom' ];\n\n\tlet nearestIndex = 0;\n\tlet insertPosition = 'before';\n\tlet minDistance = Infinity;\n\n\tconst {\n\t\tdropZoneElement,\n\t\tparentBlockOrientation,\n\t\trootBlockIndex = 0,\n\t} = options;\n\n\t// Allow before/after when dragging over the top/bottom edges of the drop zone.\n\tif ( dropZoneElement && parentBlockOrientation !== 'horizontal' ) {\n\t\tconst rect = dropZoneElement.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge( position, rect, [\n\t\t\t'top',\n\t\t\t'bottom',\n\t\t] );\n\n\t\t// If dragging over the top or bottom of the drop zone, insert the block\n\t\t// before or after the parent block. This only applies to blocks that use\n\t\t// a drop zone element, typically container blocks such as Group or Cover.\n\t\tif (\n\t\t\trect.height > MINIMUM_HEIGHT_FOR_THRESHOLD &&\n\t\t\tdistance < THRESHOLD_DISTANCE\n\t\t) {\n\t\t\tif ( edge === 'top' ) {\n\t\t\t\treturn [ rootBlockIndex, 'before' ];\n\t\t\t}\n\t\t\tif ( edge === 'bottom' ) {\n\t\t\t\treturn [ rootBlockIndex + 1, 'after' ];\n\t\t\t}\n\t\t}\n\t}\n\n\tconst isRightToLeft = isRTL();\n\n\t// Allow before/after when dragging over the left/right edges of the drop zone.\n\tif ( dropZoneElement && parentBlockOrientation === 'horizontal' ) {\n\t\tconst rect = dropZoneElement.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge( position, rect, [\n\t\t\t'left',\n\t\t\t'right',\n\t\t] );\n\n\t\t// If dragging over the left or right of the drop zone, insert the block\n\t\t// before or after the parent block. This only applies to blocks that use\n\t\t// a drop zone element, typically container blocks such as Group.\n\t\tif (\n\t\t\trect.width > MINIMUM_WIDTH_FOR_THRESHOLD &&\n\t\t\tdistance < THRESHOLD_DISTANCE\n\t\t) {\n\t\t\tif (\n\t\t\t\t( isRightToLeft && edge === 'right' ) ||\n\t\t\t\t( ! isRightToLeft && edge === 'left' )\n\t\t\t) {\n\t\t\t\treturn [ rootBlockIndex, 'before' ];\n\t\t\t}\n\t\t\tif (\n\t\t\t\t( isRightToLeft && edge === 'left' ) ||\n\t\t\t\t( ! isRightToLeft && edge === 'right' )\n\t\t\t) {\n\t\t\t\treturn [ rootBlockIndex + 1, 'after' ];\n\t\t\t}\n\t\t}\n\t}\n\n\tblocksData.forEach(\n\t\t( { isUnmodifiedDefaultBlock, getBoundingClientRect, blockIndex } ) => {\n\t\t\tconst rect = getBoundingClientRect();\n\n\t\t\tlet [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\t\tposition,\n\t\t\t\trect,\n\t\t\t\tallowedEdges\n\t\t\t);\n\t\t\t// Prioritize the element if the point is inside of an unmodified default block.\n\t\t\tif (\n\t\t\t\tisUnmodifiedDefaultBlock &&\n\t\t\t\tisPointContainedByRect( position, rect )\n\t\t\t) {\n\t\t\t\tdistance = 0;\n\t\t\t}\n\n\t\t\tif ( distance < minDistance ) {\n\t\t\t\t// Where the dropped block will be inserted on the nearest block.\n\t\t\t\tinsertPosition =\n\t\t\t\t\tedge === 'bottom' ||\n\t\t\t\t\t( ! isRightToLeft && edge === 'right' ) ||\n\t\t\t\t\t( isRightToLeft && edge === 'left' )\n\t\t\t\t\t\t? 'after'\n\t\t\t\t\t\t: 'before';\n\n\t\t\t\t// Update the currently known best candidate.\n\t\t\t\tminDistance = distance;\n\t\t\t\tnearestIndex = blockIndex;\n\t\t\t}\n\t\t}\n\t);\n\n\tconst adjacentIndex =\n\t\tnearestIndex + ( insertPosition === 'after' ? 1 : -1 );\n\tconst isNearestBlockUnmodifiedDefaultBlock =\n\t\t!! blocksData[ nearestIndex ]?.isUnmodifiedDefaultBlock;\n\tconst isAdjacentBlockUnmodifiedDefaultBlock =\n\t\t!! blocksData[ adjacentIndex ]?.isUnmodifiedDefaultBlock;\n\n\t// If both blocks are not unmodified default blocks then just insert between them.\n\tif (\n\t\t! isNearestBlockUnmodifiedDefaultBlock &&\n\t\t! isAdjacentBlockUnmodifiedDefaultBlock\n\t) {\n\t\t// If the user is dropping to the trailing edge of the block\n\t\t// add 1 to the index to represent dragging after.\n\t\tconst insertionIndex =\n\t\t\tinsertPosition === 'after' ? nearestIndex + 1 : nearestIndex;\n\t\treturn [ insertionIndex, 'insert' ];\n\t}\n\n\t// Otherwise, replace the nearest unmodified default block.\n\treturn [\n\t\tisNearestBlockUnmodifiedDefaultBlock ? nearestIndex : adjacentIndex,\n\t\t'replace',\n\t];\n}\n\n/**\n * Check if the dragged blocks can be dropped on the target.\n * @param {Function} getBlockType\n * @param {Object[]} allowedBlocks\n * @param {string[]} draggedBlockNames\n * @param {string} targetBlockName\n * @return {boolean} Whether the dragged blocks can be dropped on the target.\n */\nexport function isDropTargetValid(\n\tgetBlockType,\n\tallowedBlocks,\n\tdraggedBlockNames,\n\ttargetBlockName\n) {\n\t// At root level allowedBlocks is undefined and all blocks are allowed.\n\t// Otherwise, check if all dragged blocks are allowed.\n\tlet areBlocksAllowed = true;\n\tif ( allowedBlocks ) {\n\t\tconst allowedBlockNames = allowedBlocks?.map( ( { name } ) => name );\n\n\t\tareBlocksAllowed = draggedBlockNames.every( ( name ) =>\n\t\t\tallowedBlockNames?.includes( name )\n\t\t);\n\t}\n\n\t// Work out if dragged blocks have an allowed parent and if so\n\t// check target block matches the allowed parent.\n\tconst draggedBlockTypes = draggedBlockNames.map( ( name ) =>\n\t\tgetBlockType( name )\n\t);\n\tconst targetMatchesDraggedBlockParents = draggedBlockTypes.every(\n\t\t( block ) => {\n\t\t\tconst [ allowedParentName ] = block?.parent || [];\n\t\t\tif ( ! allowedParentName ) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\treturn allowedParentName === targetBlockName;\n\t\t}\n\t);\n\n\treturn areBlocksAllowed && targetMatchesDraggedBlockParents;\n}\n\n/**\n * @typedef {Object} WPBlockDropZoneConfig\n * @property {?HTMLElement} dropZoneElement Optional element to be used as the drop zone.\n * @property {string} rootClientId The root client id for the block list.\n */\n\n/**\n * A React hook that can be used to make a block list handle drag and drop.\n *\n * @param {WPBlockDropZoneConfig} dropZoneConfig configuration data for the drop zone.\n */\nexport default function useBlockDropZone( {\n\tdropZoneElement,\n\t// An undefined value represents a top-level block. Default to an empty\n\t// string for this so that `targetRootClientId` can be easily compared to\n\t// values returned by the `getRootBlockClientId` selector, which also uses\n\t// an empty string to represent top-level blocks.\n\trootClientId: targetRootClientId = '',\n\tparentClientId: parentBlockClientId = '',\n\tisDisabled = false,\n} = {} ) {\n\tconst registry = useRegistry();\n\tconst [ dropTarget, setDropTarget ] = useState( {\n\t\tindex: null,\n\t\toperation: 'insert',\n\t} );\n\n\tconst { getBlockType } = useSelect( blocksStore );\n\tconst {\n\t\tgetBlockListSettings,\n\t\tgetBlocks,\n\t\tgetBlockIndex,\n\t\tgetDraggedBlockClientIds,\n\t\tgetBlockNamesByClientId,\n\t\tgetAllowedBlocks,\n\t} = useSelect( blockEditorStore );\n\tconst { showInsertionPoint, hideInsertionPoint } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst onBlockDrop = useOnBlockDrop(\n\t\tdropTarget.operation === 'before' || dropTarget.operation === 'after'\n\t\t\t? parentBlockClientId\n\t\t\t: targetRootClientId,\n\t\tdropTarget.index,\n\t\t{\n\t\t\toperation: dropTarget.operation,\n\t\t}\n\t);\n\tconst throttled = useThrottle(\n\t\tuseCallback(\n\t\t\t( event, ownerDocument ) => {\n\t\t\t\tconst allowedBlocks = getAllowedBlocks( targetRootClientId );\n\t\t\t\tconst targetBlockName = getBlockNamesByClientId( [\n\t\t\t\t\ttargetRootClientId,\n\t\t\t\t] )[ 0 ];\n\t\t\t\tconst draggedBlockNames = getBlockNamesByClientId(\n\t\t\t\t\tgetDraggedBlockClientIds()\n\t\t\t\t);\n\t\t\t\tconst isBlockDroppingAllowed = isDropTargetValid(\n\t\t\t\t\tgetBlockType,\n\t\t\t\t\tallowedBlocks,\n\t\t\t\t\tdraggedBlockNames,\n\t\t\t\t\ttargetBlockName\n\t\t\t\t);\n\t\t\t\tif ( ! isBlockDroppingAllowed ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst blocks = getBlocks( targetRootClientId );\n\n\t\t\t\t// The block list is empty, don't show the insertion point but still allow dropping.\n\t\t\t\tif ( blocks.length === 0 ) {\n\t\t\t\t\tregistry.batch( () => {\n\t\t\t\t\t\tsetDropTarget( {\n\t\t\t\t\t\t\tindex: 0,\n\t\t\t\t\t\t\toperation: 'insert',\n\t\t\t\t\t\t} );\n\t\t\t\t\t\tshowInsertionPoint( targetRootClientId, 0, {\n\t\t\t\t\t\t\toperation: 'insert',\n\t\t\t\t\t\t} );\n\t\t\t\t\t} );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst blocksData = blocks.map( ( block ) => {\n\t\t\t\t\tconst clientId = block.clientId;\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tisUnmodifiedDefaultBlock:\n\t\t\t\t\t\t\tgetIsUnmodifiedDefaultBlock( block ),\n\t\t\t\t\t\tgetBoundingClientRect: () =>\n\t\t\t\t\t\t\townerDocument\n\t\t\t\t\t\t\t\t.getElementById( `block-${ clientId }` )\n\t\t\t\t\t\t\t\t.getBoundingClientRect(),\n\t\t\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\t\t};\n\t\t\t\t} );\n\n\t\t\t\tconst [ targetIndex, operation ] = getDropTargetPosition(\n\t\t\t\t\tblocksData,\n\t\t\t\t\t{ x: event.clientX, y: event.clientY },\n\t\t\t\t\tgetBlockListSettings( targetRootClientId )?.orientation,\n\t\t\t\t\t{\n\t\t\t\t\t\tdropZoneElement,\n\t\t\t\t\t\tparentBlockClientId,\n\t\t\t\t\t\tparentBlockOrientation: parentBlockClientId\n\t\t\t\t\t\t\t? getBlockListSettings( parentBlockClientId )\n\t\t\t\t\t\t\t\t\t?.orientation\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\trootBlockIndex: getBlockIndex( targetRootClientId ),\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\tsetDropTarget( {\n\t\t\t\t\t\tindex: targetIndex,\n\t\t\t\t\t\toperation,\n\t\t\t\t\t} );\n\n\t\t\t\t\tconst insertionPointClientId = [\n\t\t\t\t\t\t'before',\n\t\t\t\t\t\t'after',\n\t\t\t\t\t].includes( operation )\n\t\t\t\t\t\t? parentBlockClientId\n\t\t\t\t\t\t: targetRootClientId;\n\n\t\t\t\t\tshowInsertionPoint( insertionPointClientId, targetIndex, {\n\t\t\t\t\t\toperation,\n\t\t\t\t\t} );\n\t\t\t\t} );\n\t\t\t},\n\t\t\t[\n\t\t\t\tgetAllowedBlocks,\n\t\t\t\ttargetRootClientId,\n\t\t\t\tgetBlockNamesByClientId,\n\t\t\t\tgetDraggedBlockClientIds,\n\t\t\t\tgetBlockType,\n\t\t\t\tgetBlocks,\n\t\t\t\tgetBlockListSettings,\n\t\t\t\tdropZoneElement,\n\t\t\t\tparentBlockClientId,\n\t\t\t\tgetBlockIndex,\n\t\t\t\tregistry,\n\t\t\t\tshowInsertionPoint,\n\t\t\t]\n\t\t),\n\t\t200\n\t);\n\n\treturn useDropZone( {\n\t\tdropZoneElement,\n\t\tisDisabled,\n\t\tonDrop: onBlockDrop,\n\t\tonDragOver( event ) {\n\t\t\t// `currentTarget` is only available while the event is being\n\t\t\t// handled, so get it now and pass it to the thottled function.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget\n\t\t\tthrottled( event, event.currentTarget.ownerDocument );\n\t\t},\n\t\tonDragLeave() {\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t},\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACrE,SAASC,WAAW,EAAEC,QAAQ,QAAQ,oBAAoB;AAC1D,SACCC,WAAW,EACXC,yBAAyB,IAAIC,WAAW,QAClC,oBAAoB;AAC3B,SAASC,KAAK,QAAQ,iBAAiB;AACvC,SACCC,wBAAwB,IAAIC,2BAA2B,EACvDC,KAAK,IAAIC,WAAW,QACd,mBAAmB;;AAE1B;AACA;AACA;AACA,OAAOC,cAAc,MAAM,sBAAsB;AACjD,SACCC,wBAAwB,EACxBC,sBAAsB,QAChB,kBAAkB;AACzB,S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A,EAAG;MACXrB,SAAS,CAACoB,MAAM,CAAC,CAAC;MAClBtB,kBAAkB,CAAC,CAAC;IACrB;EACD,CAAE,CAAC;AACJ"}
|
|
1
|
+
{"version":3,"names":["useDispatch","useSelect","useRegistry","useCallback","useState","useThrottle","__experimentalUseDropZone","useDropZone","isRTL","isUnmodifiedDefaultBlock","getIsUnmodifiedDefaultBlock","store","blocksStore","useOnBlockDrop","getDistanceToNearestEdge","isPointContainedByRect","isPointWithinTopAndBottomBoundariesOfRect","blockEditorStore","THRESHOLD_DISTANCE","MINIMUM_HEIGHT_FOR_THRESHOLD","MINIMUM_WIDTH_FOR_THRESHOLD","getDropTargetPosition","blocksData","position","orientation","options","allowedEdges","nearestIndex","insertPosition","minDistance","Infinity","targetBlockIndex","nearestSide","dropZoneElement","parentBlockOrientation","rootBlockIndex","rect","getBoundingClientRect","distance","edge","height","isRightToLeft","width","forEach","blockIndex","blockOrientation","sideDistance","sideEdge","isPointInsideRect","adjacentIndex","isNearestBlockUnmodifiedDefaultBlock","isAdjacentBlockUnmodifiedDefaultBlock","insertionIndex","isDropTargetValid","getBlockType","allowedBlocks","draggedBlockNames","targetBlockName","areBlocksAllowed","allowedBlockNames","map","name","every","includes","draggedBlockTypes","targetMatchesDraggedBlockParents","block","allowedParentName","parent","useBlockDropZone","rootClientId","targetRootClientId","parentClientId","parentBlockClientId","isDisabled","registry","dropTarget","setDropTarget","index","operation","getBlockListSettings","getBlocks","getBlockIndex","getDraggedBlockClientIds","getBlockNamesByClientId","getAllowedBlocks","showInsertionPoint","hideInsertionPoint","onBlockDrop","throttled","event","ownerDocument","isBlockDroppingAllowed","blocks","length","batch","clientId","getElementById","targetIndex","x","clientX","y","clientY","undefined","insertionPointClientId","onDrop","onDragOver","currentTarget","onDragLeave","cancel","onDragEnd"],"sources":["@wordpress/block-editor/src/components/use-block-drop-zone/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect, useRegistry } from '@wordpress/data';\nimport { useCallback, useState } from '@wordpress/element';\nimport {\n\tuseThrottle,\n\t__experimentalUseDropZone as useDropZone,\n} from '@wordpress/compose';\nimport { isRTL } from '@wordpress/i18n';\nimport {\n\tisUnmodifiedDefaultBlock as getIsUnmodifiedDefaultBlock,\n\tstore as blocksStore,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport useOnBlockDrop from '../use-on-block-drop';\nimport {\n\tgetDistanceToNearestEdge,\n\tisPointContainedByRect,\n\tisPointWithinTopAndBottomBoundariesOfRect,\n} from '../../utils/math';\nimport { store as blockEditorStore } from '../../store';\n\nconst THRESHOLD_DISTANCE = 30;\nconst MINIMUM_HEIGHT_FOR_THRESHOLD = 120;\nconst MINIMUM_WIDTH_FOR_THRESHOLD = 120;\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n/** @typedef {import('../use-on-block-drop/types').WPDropOperation} WPDropOperation */\n\n/**\n * The orientation of a block list.\n *\n * @typedef {'horizontal'|'vertical'|undefined} WPBlockListOrientation\n */\n\n/**\n * The insert position when dropping a block.\n *\n * @typedef {'before'|'after'} WPInsertPosition\n */\n\n/**\n * @typedef {Object} WPBlockData\n * @property {boolean} isUnmodifiedDefaultBlock Is the block unmodified default block.\n * @property {() => DOMRect} getBoundingClientRect Get the bounding client rect of the block.\n * @property {number} blockIndex The index of the block.\n */\n\n/**\n * Get the drop target position from a given drop point and the orientation.\n *\n * @param {WPBlockData[]} blocksData The block data list.\n * @param {WPPoint} position The position of the item being dragged.\n * @param {WPBlockListOrientation} orientation The orientation of the block list.\n * @param {Object} options Additional options.\n * @return {[number, WPDropOperation]} The drop target position.\n */\nexport function getDropTargetPosition(\n\tblocksData,\n\tposition,\n\torientation = 'vertical',\n\toptions = {}\n) {\n\tconst allowedEdges =\n\t\torientation === 'horizontal'\n\t\t\t? [ 'left', 'right' ]\n\t\t\t: [ 'top', 'bottom' ];\n\n\tlet nearestIndex = 0;\n\tlet insertPosition = 'before';\n\tlet minDistance = Infinity;\n\tlet targetBlockIndex = null;\n\tlet nearestSide = 'right';\n\n\tconst {\n\t\tdropZoneElement,\n\t\tparentBlockOrientation,\n\t\trootBlockIndex = 0,\n\t} = options;\n\n\t// Allow before/after when dragging over the top/bottom edges of the drop zone.\n\tif ( dropZoneElement && parentBlockOrientation !== 'horizontal' ) {\n\t\tconst rect = dropZoneElement.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge( position, rect, [\n\t\t\t'top',\n\t\t\t'bottom',\n\t\t] );\n\n\t\t// If dragging over the top or bottom of the drop zone, insert the block\n\t\t// before or after the parent block. This only applies to blocks that use\n\t\t// a drop zone element, typically container blocks such as Group or Cover.\n\t\tif (\n\t\t\trect.height > MINIMUM_HEIGHT_FOR_THRESHOLD &&\n\t\t\tdistance < THRESHOLD_DISTANCE\n\t\t) {\n\t\t\tif ( edge === 'top' ) {\n\t\t\t\treturn [ rootBlockIndex, 'before' ];\n\t\t\t}\n\t\t\tif ( edge === 'bottom' ) {\n\t\t\t\treturn [ rootBlockIndex + 1, 'after' ];\n\t\t\t}\n\t\t}\n\t}\n\n\tconst isRightToLeft = isRTL();\n\n\t// Allow before/after when dragging over the left/right edges of the drop zone.\n\tif ( dropZoneElement && parentBlockOrientation === 'horizontal' ) {\n\t\tconst rect = dropZoneElement.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge( position, rect, [\n\t\t\t'left',\n\t\t\t'right',\n\t\t] );\n\n\t\t// If dragging over the left or right of the drop zone, insert the block\n\t\t// before or after the parent block. This only applies to blocks that use\n\t\t// a drop zone element, typically container blocks such as Group.\n\t\tif (\n\t\t\trect.width > MINIMUM_WIDTH_FOR_THRESHOLD &&\n\t\t\tdistance < THRESHOLD_DISTANCE\n\t\t) {\n\t\t\tif (\n\t\t\t\t( isRightToLeft && edge === 'right' ) ||\n\t\t\t\t( ! isRightToLeft && edge === 'left' )\n\t\t\t) {\n\t\t\t\treturn [ rootBlockIndex, 'before' ];\n\t\t\t}\n\t\t\tif (\n\t\t\t\t( isRightToLeft && edge === 'left' ) ||\n\t\t\t\t( ! isRightToLeft && edge === 'right' )\n\t\t\t) {\n\t\t\t\treturn [ rootBlockIndex + 1, 'after' ];\n\t\t\t}\n\t\t}\n\t}\n\n\tblocksData.forEach(\n\t\t( {\n\t\t\tisUnmodifiedDefaultBlock,\n\t\t\tgetBoundingClientRect,\n\t\t\tblockIndex,\n\t\t\tblockOrientation,\n\t\t} ) => {\n\t\t\tconst rect = getBoundingClientRect();\n\n\t\t\tlet [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\t\tposition,\n\t\t\t\trect,\n\t\t\t\tallowedEdges\n\t\t\t);\n\t\t\t// If the the point is close to a side, prioritize that side.\n\t\t\tconst [ sideDistance, sideEdge ] = getDistanceToNearestEdge(\n\t\t\t\tposition,\n\t\t\t\trect,\n\t\t\t\t[ 'left', 'right' ]\n\t\t\t);\n\n\t\t\tconst isPointInsideRect = isPointContainedByRect( position, rect );\n\n\t\t\t// Prioritize the element if the point is inside of an unmodified default block.\n\t\t\tif ( isUnmodifiedDefaultBlock && isPointInsideRect ) {\n\t\t\t\tdistance = 0;\n\t\t\t} else if (\n\t\t\t\torientation === 'vertical' &&\n\t\t\t\tblockOrientation !== 'horizontal' &&\n\t\t\t\t( ( isPointInsideRect && sideDistance < THRESHOLD_DISTANCE ) ||\n\t\t\t\t\t( ! isPointInsideRect &&\n\t\t\t\t\t\tisPointWithinTopAndBottomBoundariesOfRect(\n\t\t\t\t\t\t\tposition,\n\t\t\t\t\t\t\trect\n\t\t\t\t\t\t) ) )\n\t\t\t) {\n\t\t\t\t/**\n\t\t\t\t * This condition should only apply when the layout is vertical (otherwise there's\n\t\t\t\t * no need to create a Row) and dropzones should only activate when the block is\n\t\t\t\t * either within and close to the sides of the target block or on its outer sides.\n\t\t\t\t */\n\t\t\t\ttargetBlockIndex = blockIndex;\n\t\t\t\tnearestSide = sideEdge;\n\t\t\t}\n\n\t\t\tif ( distance < minDistance ) {\n\t\t\t\t// Where the dropped block will be inserted on the nearest block.\n\t\t\t\tinsertPosition =\n\t\t\t\t\tedge === 'bottom' ||\n\t\t\t\t\t( ! isRightToLeft && edge === 'right' ) ||\n\t\t\t\t\t( isRightToLeft && edge === 'left' )\n\t\t\t\t\t\t? 'after'\n\t\t\t\t\t\t: 'before';\n\n\t\t\t\t// Update the currently known best candidate.\n\t\t\t\tminDistance = distance;\n\t\t\t\tnearestIndex = blockIndex;\n\t\t\t}\n\t\t}\n\t);\n\n\tconst adjacentIndex =\n\t\tnearestIndex + ( insertPosition === 'after' ? 1 : -1 );\n\tconst isNearestBlockUnmodifiedDefaultBlock =\n\t\t!! blocksData[ nearestIndex ]?.isUnmodifiedDefaultBlock;\n\tconst isAdjacentBlockUnmodifiedDefaultBlock =\n\t\t!! blocksData[ adjacentIndex ]?.isUnmodifiedDefaultBlock;\n\n\t// If the target index is set then group with the block at that index.\n\tif ( targetBlockIndex !== null ) {\n\t\treturn [ targetBlockIndex, 'group', nearestSide ];\n\t}\n\t// If both blocks are not unmodified default blocks then just insert between them.\n\tif (\n\t\t! isNearestBlockUnmodifiedDefaultBlock &&\n\t\t! isAdjacentBlockUnmodifiedDefaultBlock\n\t) {\n\t\t// If the user is dropping to the trailing edge of the block\n\t\t// add 1 to the index to represent dragging after.\n\t\tconst insertionIndex =\n\t\t\tinsertPosition === 'after' ? nearestIndex + 1 : nearestIndex;\n\t\treturn [ insertionIndex, 'insert' ];\n\t}\n\n\t// Otherwise, replace the nearest unmodified default block.\n\treturn [\n\t\tisNearestBlockUnmodifiedDefaultBlock ? nearestIndex : adjacentIndex,\n\t\t'replace',\n\t];\n}\n\n/**\n * Check if the dragged blocks can be dropped on the target.\n * @param {Function} getBlockType\n * @param {Object[]} allowedBlocks\n * @param {string[]} draggedBlockNames\n * @param {string} targetBlockName\n * @return {boolean} Whether the dragged blocks can be dropped on the target.\n */\nexport function isDropTargetValid(\n\tgetBlockType,\n\tallowedBlocks,\n\tdraggedBlockNames,\n\ttargetBlockName\n) {\n\t// At root level allowedBlocks is undefined and all blocks are allowed.\n\t// Otherwise, check if all dragged blocks are allowed.\n\tlet areBlocksAllowed = true;\n\tif ( allowedBlocks ) {\n\t\tconst allowedBlockNames = allowedBlocks?.map( ( { name } ) => name );\n\n\t\tareBlocksAllowed = draggedBlockNames.every( ( name ) =>\n\t\t\tallowedBlockNames?.includes( name )\n\t\t);\n\t}\n\n\t// Work out if dragged blocks have an allowed parent and if so\n\t// check target block matches the allowed parent.\n\tconst draggedBlockTypes = draggedBlockNames.map( ( name ) =>\n\t\tgetBlockType( name )\n\t);\n\tconst targetMatchesDraggedBlockParents = draggedBlockTypes.every(\n\t\t( block ) => {\n\t\t\tconst [ allowedParentName ] = block?.parent || [];\n\t\t\tif ( ! allowedParentName ) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\treturn allowedParentName === targetBlockName;\n\t\t}\n\t);\n\n\treturn areBlocksAllowed && targetMatchesDraggedBlockParents;\n}\n\n/**\n * @typedef {Object} WPBlockDropZoneConfig\n * @property {?HTMLElement} dropZoneElement Optional element to be used as the drop zone.\n * @property {string} rootClientId The root client id for the block list.\n */\n\n/**\n * A React hook that can be used to make a block list handle drag and drop.\n *\n * @param {WPBlockDropZoneConfig} dropZoneConfig configuration data for the drop zone.\n */\nexport default function useBlockDropZone( {\n\tdropZoneElement,\n\t// An undefined value represents a top-level block. Default to an empty\n\t// string for this so that `targetRootClientId` can be easily compared to\n\t// values returned by the `getRootBlockClientId` selector, which also uses\n\t// an empty string to represent top-level blocks.\n\trootClientId: targetRootClientId = '',\n\tparentClientId: parentBlockClientId = '',\n\tisDisabled = false,\n} = {} ) {\n\tconst registry = useRegistry();\n\tconst [ dropTarget, setDropTarget ] = useState( {\n\t\tindex: null,\n\t\toperation: 'insert',\n\t} );\n\n\tconst { getBlockType } = useSelect( blocksStore );\n\tconst {\n\t\tgetBlockListSettings,\n\t\tgetBlocks,\n\t\tgetBlockIndex,\n\t\tgetDraggedBlockClientIds,\n\t\tgetBlockNamesByClientId,\n\t\tgetAllowedBlocks,\n\t} = useSelect( blockEditorStore );\n\tconst { showInsertionPoint, hideInsertionPoint } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst onBlockDrop = useOnBlockDrop(\n\t\tdropTarget.operation === 'before' || dropTarget.operation === 'after'\n\t\t\t? parentBlockClientId\n\t\t\t: targetRootClientId,\n\t\tdropTarget.index,\n\t\t{\n\t\t\toperation: dropTarget.operation,\n\t\t\tnearestSide: dropTarget.nearestSide,\n\t\t}\n\t);\n\tconst throttled = useThrottle(\n\t\tuseCallback(\n\t\t\t( event, ownerDocument ) => {\n\t\t\t\tconst allowedBlocks = getAllowedBlocks( targetRootClientId );\n\t\t\t\tconst targetBlockName = getBlockNamesByClientId( [\n\t\t\t\t\ttargetRootClientId,\n\t\t\t\t] )[ 0 ];\n\t\t\t\tconst draggedBlockNames = getBlockNamesByClientId(\n\t\t\t\t\tgetDraggedBlockClientIds()\n\t\t\t\t);\n\t\t\t\tconst isBlockDroppingAllowed = isDropTargetValid(\n\t\t\t\t\tgetBlockType,\n\t\t\t\t\tallowedBlocks,\n\t\t\t\t\tdraggedBlockNames,\n\t\t\t\t\ttargetBlockName\n\t\t\t\t);\n\t\t\t\tif ( ! isBlockDroppingAllowed ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst blocks = getBlocks( targetRootClientId );\n\n\t\t\t\t// The block list is empty, don't show the insertion point but still allow dropping.\n\t\t\t\tif ( blocks.length === 0 ) {\n\t\t\t\t\tregistry.batch( () => {\n\t\t\t\t\t\tsetDropTarget( {\n\t\t\t\t\t\t\tindex: 0,\n\t\t\t\t\t\t\toperation: 'insert',\n\t\t\t\t\t\t} );\n\t\t\t\t\t\tshowInsertionPoint( targetRootClientId, 0, {\n\t\t\t\t\t\t\toperation: 'insert',\n\t\t\t\t\t\t} );\n\t\t\t\t\t} );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst blocksData = blocks.map( ( block ) => {\n\t\t\t\t\tconst clientId = block.clientId;\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tisUnmodifiedDefaultBlock:\n\t\t\t\t\t\t\tgetIsUnmodifiedDefaultBlock( block ),\n\t\t\t\t\t\tgetBoundingClientRect: () =>\n\t\t\t\t\t\t\townerDocument\n\t\t\t\t\t\t\t\t.getElementById( `block-${ clientId }` )\n\t\t\t\t\t\t\t\t.getBoundingClientRect(),\n\t\t\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\t\t\tblockOrientation:\n\t\t\t\t\t\t\tgetBlockListSettings( clientId )?.orientation,\n\t\t\t\t\t};\n\t\t\t\t} );\n\n\t\t\t\tconst [ targetIndex, operation, nearestSide ] =\n\t\t\t\t\tgetDropTargetPosition(\n\t\t\t\t\t\tblocksData,\n\t\t\t\t\t\t{ x: event.clientX, y: event.clientY },\n\t\t\t\t\t\tgetBlockListSettings( targetRootClientId )?.orientation,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdropZoneElement,\n\t\t\t\t\t\t\tparentBlockClientId,\n\t\t\t\t\t\t\tparentBlockOrientation: parentBlockClientId\n\t\t\t\t\t\t\t\t? getBlockListSettings( parentBlockClientId )\n\t\t\t\t\t\t\t\t\t\t?.orientation\n\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\trootBlockIndex: getBlockIndex( targetRootClientId ),\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\tsetDropTarget( {\n\t\t\t\t\t\tindex: targetIndex,\n\t\t\t\t\t\toperation,\n\t\t\t\t\t\tnearestSide,\n\t\t\t\t\t} );\n\n\t\t\t\t\tconst insertionPointClientId = [\n\t\t\t\t\t\t'before',\n\t\t\t\t\t\t'after',\n\t\t\t\t\t].includes( operation )\n\t\t\t\t\t\t? parentBlockClientId\n\t\t\t\t\t\t: targetRootClientId;\n\n\t\t\t\t\tshowInsertionPoint( insertionPointClientId, targetIndex, {\n\t\t\t\t\t\toperation,\n\t\t\t\t\t\tnearestSide,\n\t\t\t\t\t} );\n\t\t\t\t} );\n\t\t\t},\n\t\t\t[\n\t\t\t\tgetAllowedBlocks,\n\t\t\t\ttargetRootClientId,\n\t\t\t\tgetBlockNamesByClientId,\n\t\t\t\tgetDraggedBlockClientIds,\n\t\t\t\tgetBlockType,\n\t\t\t\tgetBlocks,\n\t\t\t\tgetBlockListSettings,\n\t\t\t\tdropZoneElement,\n\t\t\t\tparentBlockClientId,\n\t\t\t\tgetBlockIndex,\n\t\t\t\tregistry,\n\t\t\t\tshowInsertionPoint,\n\t\t\t]\n\t\t),\n\t\t200\n\t);\n\n\treturn useDropZone( {\n\t\tdropZoneElement,\n\t\tisDisabled,\n\t\tonDrop: onBlockDrop,\n\t\tonDragOver( event ) {\n\t\t\t// `currentTarget` is only available while the event is being\n\t\t\t// handled, so get it now and pass it to the thottled function.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget\n\t\t\tthrottled( event, event.currentTarget.ownerDocument );\n\t\t},\n\t\tonDragLeave() {\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t},\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACrE,SAASC,WAAW,EAAEC,QAAQ,QAAQ,oBAAoB;AAC1D,SACCC,WAAW,EACXC,yBAAyB,IAAIC,WAAW,QAClC,oBAAoB;AAC3B,SAASC,KAAK,QAAQ,iBAAiB;AACvC,SACCC,wBAAwB,IAAIC,2BAA2B,EACvDC,KAAK,IAAIC,WAAW,QACd,mBAAmB;;AAE1B;AACA;AACA;AACA,OAAOC,cAAc,MAAM,sBAAsB;AACjD,SACCC,wBAAwB,EACxBC,sBAAsB,EACtBC,yCAAyC,QACnC,kBAAkB;AACzB,SAASL,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AC;MAEH,MAAMwE,sBAAsB,GAAG,CAC9B,QAAQ,EACR,OAAO,CACP,CAACzC,QAAQ,CAAEgB,SAAU,CAAC,GACpBN,mBAAmB,GACnBF,kBAAkB;MAErBe,kBAAkB,CAAEkB,sBAAsB,EAAEN,WAAW,EAAE;QACxDnB,SAAS;QACT/C;MACD,CAAE,CAAC;IACJ,CAAE,CAAC;EACJ,CAAC,EACD,CACCqD,gBAAgB,EAChBd,kBAAkB,EAClBa,uBAAuB,EACvBD,wBAAwB,EACxB7B,YAAY,EACZ2B,SAAS,EACTD,oBAAoB,EACpB/C,eAAe,EACfwC,mBAAmB,EACnBS,aAAa,EACbP,QAAQ,EACRW,kBAAkB,CAEpB,CAAC,EACD,GACD,CAAC;EAED,OAAO/E,WAAW,CAAE;IACnB0B,eAAe;IACfyC,UAAU;IACV+B,MAAM,EAAEjB,WAAW;IACnBkB,UAAUA,CAAEhB,KAAK,EAAG;MACnB;MACA;MACA;MACAD,SAAS,CAAEC,KAAK,EAAEA,KAAK,CAACiB,aAAa,CAAChB,aAAc,CAAC;IACtD,CAAC;IACDiB,WAAWA,CAAA,EAAG;MACbnB,SAAS,CAACoB,MAAM,CAAC,CAAC;MAClBtB,kBAAkB,CAAC,CAAC;IACrB,CAAC;IACDuB,SAASA,CAAA,EAAG;MACXrB,SAAS,CAACoB,MAAM,CAAC,CAAC;MAClBtB,kBAAkB,CAAC,CAAC;IACrB;EACD,CAAE,CAAC;AACJ"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useCallback } from '@wordpress/element';
|
|
5
|
-
import { cloneBlock, findTransform, getBlockTransforms, pasteHandler } from '@wordpress/blocks';
|
|
5
|
+
import { cloneBlock, createBlock, findTransform, getBlockTransforms, pasteHandler, store as blocksStore } from '@wordpress/blocks';
|
|
6
6
|
import { useDispatch, useSelect, useRegistry } from '@wordpress/data';
|
|
7
7
|
import { getFilesFromDataTransfer } from '@wordpress/dom';
|
|
8
8
|
|
|
@@ -50,9 +50,11 @@ export function parseDropEvent(event) {
|
|
|
50
50
|
* @param {Function} moveBlocks A function that moves blocks.
|
|
51
51
|
* @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.
|
|
52
52
|
* @param {Function} clearSelectedBlock A function that clears block selection.
|
|
53
|
+
* @param {string} operation The type of operation to perform on drop. Could be `insert` or `replace` or `group`.
|
|
54
|
+
* @param {Function} getBlock A function that returns a block given its client id.
|
|
53
55
|
* @return {Function} The event handler for a block drop event.
|
|
54
56
|
*/
|
|
55
|
-
export function onBlockDrop(targetRootClientId, targetBlockIndex, getBlockIndex, getClientIdsOfDescendants, moveBlocks, insertOrReplaceBlocks, clearSelectedBlock) {
|
|
57
|
+
export function onBlockDrop(targetRootClientId, targetBlockIndex, getBlockIndex, getClientIdsOfDescendants, moveBlocks, insertOrReplaceBlocks, clearSelectedBlock, operation, getBlock) {
|
|
56
58
|
return event => {
|
|
57
59
|
const {
|
|
58
60
|
srcRootClientId: sourceRootClientId,
|
|
@@ -83,6 +85,14 @@ export function onBlockDrop(targetRootClientId, targetBlockIndex, getBlockIndex,
|
|
|
83
85
|
if (sourceClientIds.includes(targetRootClientId) || getClientIdsOfDescendants(sourceClientIds).some(id => id === targetRootClientId)) {
|
|
84
86
|
return;
|
|
85
87
|
}
|
|
88
|
+
|
|
89
|
+
// If the user is dropping a block over another block, replace both blocks
|
|
90
|
+
// with a group block containing them
|
|
91
|
+
if (operation === 'group') {
|
|
92
|
+
const blocksToInsert = sourceClientIds.map(clientId => getBlock(clientId));
|
|
93
|
+
insertOrReplaceBlocks(blocksToInsert, true, null, sourceClientIds);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
86
96
|
const isAtSameLevel = sourceRootClientId === targetRootClientId;
|
|
87
97
|
const draggedBlockCount = sourceClientIds.length;
|
|
88
98
|
|
|
@@ -150,7 +160,8 @@ export function onHTMLDrop(insertOrReplaceBlocks) {
|
|
|
150
160
|
*/
|
|
151
161
|
export default function useOnBlockDrop(targetRootClientId, targetBlockIndex, options = {}) {
|
|
152
162
|
const {
|
|
153
|
-
operation = 'insert'
|
|
163
|
+
operation = 'insert',
|
|
164
|
+
nearestSide = 'right'
|
|
154
165
|
} = options;
|
|
155
166
|
const {
|
|
156
167
|
canInsertBlockType,
|
|
@@ -158,8 +169,14 @@ export default function useOnBlockDrop(targetRootClientId, targetBlockIndex, opt
|
|
|
158
169
|
getClientIdsOfDescendants,
|
|
159
170
|
getBlockOrder,
|
|
160
171
|
getBlocksByClientId,
|
|
161
|
-
getSettings
|
|
172
|
+
getSettings,
|
|
173
|
+
getBlock,
|
|
174
|
+
isGroupable
|
|
162
175
|
} = useSelect(blockEditorStore);
|
|
176
|
+
const {
|
|
177
|
+
getBlockType,
|
|
178
|
+
getGroupingBlockName
|
|
179
|
+
} = useSelect(blocksStore);
|
|
163
180
|
const {
|
|
164
181
|
insertBlocks,
|
|
165
182
|
moveBlocksToPosition,
|
|
@@ -169,15 +186,40 @@ export default function useOnBlockDrop(targetRootClientId, targetBlockIndex, opt
|
|
|
169
186
|
removeBlocks
|
|
170
187
|
} = useDispatch(blockEditorStore);
|
|
171
188
|
const registry = useRegistry();
|
|
172
|
-
const insertOrReplaceBlocks = useCallback((blocks, updateSelection = true, initialPosition = 0) => {
|
|
189
|
+
const insertOrReplaceBlocks = useCallback((blocks, updateSelection = true, initialPosition = 0, clientIdsToReplace = []) => {
|
|
190
|
+
const clientIds = getBlockOrder(targetRootClientId);
|
|
191
|
+
const clientId = clientIds[targetBlockIndex];
|
|
192
|
+
const blocksClientIds = blocks.map(block => block.clientId);
|
|
193
|
+
const areGroupableBlocks = isGroupable([...blocksClientIds, clientId]);
|
|
173
194
|
if (operation === 'replace') {
|
|
174
|
-
const clientIds = getBlockOrder(targetRootClientId);
|
|
175
|
-
const clientId = clientIds[targetBlockIndex];
|
|
176
195
|
replaceBlocks(clientId, blocks, undefined, initialPosition);
|
|
196
|
+
} else if (operation === 'group' && areGroupableBlocks) {
|
|
197
|
+
const targetBlock = getBlock(clientId);
|
|
198
|
+
if (nearestSide === 'left') {
|
|
199
|
+
blocks.push(targetBlock);
|
|
200
|
+
} else {
|
|
201
|
+
blocks.unshift(targetBlock);
|
|
202
|
+
}
|
|
203
|
+
const groupInnerBlocks = blocks.map(block => {
|
|
204
|
+
return createBlock(block.name, block.attributes, block.innerBlocks);
|
|
205
|
+
});
|
|
206
|
+
const areAllImages = blocks.every(block => {
|
|
207
|
+
return block.name === 'core/image';
|
|
208
|
+
});
|
|
209
|
+
const galleryBlock = !!getBlockType('core/gallery');
|
|
210
|
+
const wrappedBlocks = createBlock(areAllImages && galleryBlock ? 'core/gallery' : getGroupingBlockName(), {
|
|
211
|
+
layout: {
|
|
212
|
+
type: 'flex',
|
|
213
|
+
flexWrap: areAllImages ? null : 'nowrap'
|
|
214
|
+
}
|
|
215
|
+
}, groupInnerBlocks);
|
|
216
|
+
// Need to make sure both the target block and the block being dragged are replaced
|
|
217
|
+
// otherwise the dragged block will be duplicated.
|
|
218
|
+
replaceBlocks([clientId, ...clientIdsToReplace], wrappedBlocks, undefined, initialPosition);
|
|
177
219
|
} else {
|
|
178
220
|
insertBlocks(blocks, targetBlockIndex, targetRootClientId, updateSelection, initialPosition);
|
|
179
221
|
}
|
|
180
|
-
}, [
|
|
222
|
+
}, [getBlockOrder, targetRootClientId, targetBlockIndex, operation, replaceBlocks, getBlock, nearestSide, getBlockType, getGroupingBlockName, insertBlocks]);
|
|
181
223
|
const moveBlocks = useCallback((sourceClientIds, sourceRootClientId, insertIndex) => {
|
|
182
224
|
if (operation === 'replace') {
|
|
183
225
|
const sourceBlocks = getBlocksByClientId(sourceClientIds);
|
|
@@ -193,7 +235,7 @@ export default function useOnBlockDrop(targetRootClientId, targetBlockIndex, opt
|
|
|
193
235
|
moveBlocksToPosition(sourceClientIds, sourceRootClientId, targetRootClientId, insertIndex);
|
|
194
236
|
}
|
|
195
237
|
}, [operation, getBlockOrder, getBlocksByClientId, moveBlocksToPosition, registry, removeBlocks, replaceBlocks, targetBlockIndex, targetRootClientId]);
|
|
196
|
-
const _onDrop = onBlockDrop(targetRootClientId, targetBlockIndex, getBlockIndex, getClientIdsOfDescendants, moveBlocks, insertOrReplaceBlocks, clearSelectedBlock);
|
|
238
|
+
const _onDrop = onBlockDrop(targetRootClientId, targetBlockIndex, getBlockIndex, getClientIdsOfDescendants, moveBlocks, insertOrReplaceBlocks, clearSelectedBlock, operation, getBlock);
|
|
197
239
|
const _onFilesDrop = onFilesDrop(targetRootClientId, getSettings, updateBlockAttributes, canInsertBlockType, insertOrReplaceBlocks);
|
|
198
240
|
const _onHTMLDrop = onHTMLDrop(insertOrReplaceBlocks);
|
|
199
241
|
return event => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useCallback","cloneBlock","findTransform","getBlockTransforms","pasteHandler","useDispatch","useSelect","useRegistry","getFilesFromDataTransfer","store","blockEditorStore","parseDropEvent","event","result","srcRootClientId","srcClientIds","srcIndex","type","blocks","dataTransfer","Object","assign","JSON","parse","getData","err","onBlockDrop","targetRootClientId","targetBlockIndex","getBlockIndex","getClientIdsOfDescendants","moveBlocks","insertOrReplaceBlocks","clearSelectedBlock","sourceRootClientId","sourceClientIds","dropType","blocksToInsert","map","block","sourceBlockIndex","includes","some","id","isAtSameLevel","draggedBlockCount","length","insertIndex","onFilesDrop","getSettings","updateBlockAttributes","canInsertBlockType","files","mediaUpload","transformation","transform","blockName","isMatch","onHTMLDrop","HTML","mode","useOnBlockDrop","options","operation","getBlockOrder","getBlocksByClientId","insertBlocks","moveBlocksToPosition","replaceBlocks","removeBlocks","registry","updateSelection","initialPosition","clientIds","clientId","undefined","sourceBlocks","targetBlockClientIds","targetBlockClientId","batch","_onDrop","_onFilesDrop","_onHTMLDrop","html"],"sources":["@wordpress/block-editor/src/components/use-on-block-drop/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport {\n\tcloneBlock,\n\tfindTransform,\n\tgetBlockTransforms,\n\tpasteHandler,\n} from '@wordpress/blocks';\nimport { useDispatch, useSelect, useRegistry } from '@wordpress/data';\nimport { getFilesFromDataTransfer } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('react').SyntheticEvent} SyntheticEvent */\n/** @typedef {import('./types').WPDropOperation} WPDropOperation */\n\n/**\n * Retrieve the data for a block drop event.\n *\n * @param {SyntheticEvent} event The drop event.\n *\n * @return {Object} An object with block drag and drop data.\n */\nexport function parseDropEvent( event ) {\n\tlet result = {\n\t\tsrcRootClientId: null,\n\t\tsrcClientIds: null,\n\t\tsrcIndex: null,\n\t\ttype: null,\n\t\tblocks: null,\n\t};\n\n\tif ( ! event.dataTransfer ) {\n\t\treturn result;\n\t}\n\n\ttry {\n\t\tresult = Object.assign(\n\t\t\tresult,\n\t\t\tJSON.parse( event.dataTransfer.getData( 'wp-blocks' ) )\n\t\t);\n\t} catch ( err ) {\n\t\treturn result;\n\t}\n\n\treturn result;\n}\n\n/**\n * A function that returns an event handler function for block drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Function} getBlockIndex A function that gets the index of a block.\n * @param {Function} getClientIdsOfDescendants A function that gets the client ids of descendant blocks.\n * @param {Function} moveBlocks A function that moves blocks.\n * @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.\n * @param {Function} clearSelectedBlock A function that clears block selection.\n * @return {Function} The event handler for a block drop event.\n */\nexport function onBlockDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\tgetBlockIndex,\n\tgetClientIdsOfDescendants,\n\tmoveBlocks,\n\tinsertOrReplaceBlocks,\n\tclearSelectedBlock\n) {\n\treturn ( event ) => {\n\t\tconst {\n\t\t\tsrcRootClientId: sourceRootClientId,\n\t\t\tsrcClientIds: sourceClientIds,\n\t\t\ttype: dropType,\n\t\t\tblocks,\n\t\t} = parseDropEvent( event );\n\n\t\t// If the user is inserting a block.\n\t\tif ( dropType === 'inserter' ) {\n\t\t\tclearSelectedBlock();\n\t\t\tconst blocksToInsert = blocks.map( ( block ) =>\n\t\t\t\tcloneBlock( block )\n\t\t\t);\n\t\t\tinsertOrReplaceBlocks( blocksToInsert, true, null );\n\t\t}\n\n\t\t// If the user is moving a block.\n\t\tif ( dropType === 'block' ) {\n\t\t\tconst sourceBlockIndex = getBlockIndex( sourceClientIds[ 0 ] );\n\n\t\t\t// If the user is dropping to the same position, return early.\n\t\t\tif (\n\t\t\t\tsourceRootClientId === targetRootClientId &&\n\t\t\t\tsourceBlockIndex === targetBlockIndex\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the user is attempting to drop a block within its own\n\t\t\t// nested blocks, return early as this would create infinite\n\t\t\t// recursion.\n\t\t\tif (\n\t\t\t\tsourceClientIds.includes( targetRootClientId ) ||\n\t\t\t\tgetClientIdsOfDescendants( sourceClientIds ).some(\n\t\t\t\t\t( id ) => id === targetRootClientId\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isAtSameLevel = sourceRootClientId === targetRootClientId;\n\t\t\tconst draggedBlockCount = sourceClientIds.length;\n\n\t\t\t// If the block is kept at the same level and moved downwards,\n\t\t\t// subtract to take into account that the blocks being dragged\n\t\t\t// were removed from the block list above the insertion point.\n\t\t\tconst insertIndex =\n\t\t\t\tisAtSameLevel && sourceBlockIndex < targetBlockIndex\n\t\t\t\t\t? targetBlockIndex - draggedBlockCount\n\t\t\t\t\t: targetBlockIndex;\n\n\t\t\tmoveBlocks( sourceClientIds, sourceRootClientId, insertIndex );\n\t\t}\n\t};\n}\n\n/**\n * A function that returns an event handler function for block-related file drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {Function} getSettings A function that gets the block editor settings.\n * @param {Function} updateBlockAttributes A function that updates a block's attributes.\n * @param {Function} canInsertBlockType A function that returns checks whether a block type can be inserted.\n * @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.\n *\n * @return {Function} The event handler for a block-related file drop event.\n */\nexport function onFilesDrop(\n\ttargetRootClientId,\n\tgetSettings,\n\tupdateBlockAttributes,\n\tcanInsertBlockType,\n\tinsertOrReplaceBlocks\n) {\n\treturn ( files ) => {\n\t\tif ( ! getSettings().mediaUpload ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst transformation = findTransform(\n\t\t\tgetBlockTransforms( 'from' ),\n\t\t\t( transform ) =>\n\t\t\t\ttransform.type === 'files' &&\n\t\t\t\tcanInsertBlockType( transform.blockName, targetRootClientId ) &&\n\t\t\t\ttransform.isMatch( files )\n\t\t);\n\n\t\tif ( transformation ) {\n\t\t\tconst blocks = transformation.transform(\n\t\t\t\tfiles,\n\t\t\t\tupdateBlockAttributes\n\t\t\t);\n\t\t\tinsertOrReplaceBlocks( blocks );\n\t\t}\n\t};\n}\n\n/**\n * A function that returns an event handler function for block-related HTML drop events.\n *\n * @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.\n *\n * @return {Function} The event handler for a block-related HTML drop event.\n */\nexport function onHTMLDrop( insertOrReplaceBlocks ) {\n\treturn ( HTML ) => {\n\t\tconst blocks = pasteHandler( { HTML, mode: 'BLOCKS' } );\n\n\t\tif ( blocks.length ) {\n\t\t\tinsertOrReplaceBlocks( blocks );\n\t\t}\n\t};\n}\n\n/**\n * A React hook for handling block drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Object} options The optional options.\n * @param {WPDropOperation} [options.operation] The type of operation to perform on drop. Could be `insert` or `replace` for now.\n *\n * @return {Function} A function to be passed to the onDrop handler.\n */\nexport default function useOnBlockDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\toptions = {}\n) {\n\tconst { operation = 'insert' } = options;\n\tconst {\n\t\tcanInsertBlockType,\n\t\tgetBlockIndex,\n\t\tgetClientIdsOfDescendants,\n\t\tgetBlockOrder,\n\t\tgetBlocksByClientId,\n\t\tgetSettings,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\tinsertBlocks,\n\t\tmoveBlocksToPosition,\n\t\tupdateBlockAttributes,\n\t\tclearSelectedBlock,\n\t\treplaceBlocks,\n\t\tremoveBlocks,\n\t} = useDispatch( blockEditorStore );\n\tconst registry = useRegistry();\n\n\tconst insertOrReplaceBlocks = useCallback(\n\t\t( blocks, updateSelection = true, initialPosition = 0 ) => {\n\t\t\tif ( operation === 'replace' ) {\n\t\t\t\tconst clientIds = getBlockOrder( targetRootClientId );\n\t\t\t\tconst clientId = clientIds[ targetBlockIndex ];\n\n\t\t\t\treplaceBlocks( clientId, blocks, undefined, initialPosition );\n\t\t\t} else {\n\t\t\t\tinsertBlocks(\n\t\t\t\t\tblocks,\n\t\t\t\t\ttargetBlockIndex,\n\t\t\t\t\ttargetRootClientId,\n\t\t\t\t\tupdateSelection,\n\t\t\t\t\tinitialPosition\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\toperation,\n\t\t\tgetBlockOrder,\n\t\t\tinsertBlocks,\n\t\t\treplaceBlocks,\n\t\t\ttargetBlockIndex,\n\t\t\ttargetRootClientId,\n\t\t]\n\t);\n\n\tconst moveBlocks = useCallback(\n\t\t( sourceClientIds, sourceRootClientId, insertIndex ) => {\n\t\t\tif ( operation === 'replace' ) {\n\t\t\t\tconst sourceBlocks = getBlocksByClientId( sourceClientIds );\n\t\t\t\tconst targetBlockClientIds =\n\t\t\t\t\tgetBlockOrder( targetRootClientId );\n\t\t\t\tconst targetBlockClientId =\n\t\t\t\t\ttargetBlockClientIds[ targetBlockIndex ];\n\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\t// Remove the source blocks.\n\t\t\t\t\tremoveBlocks( sourceClientIds, false );\n\t\t\t\t\t// Replace the target block with the source blocks.\n\t\t\t\t\treplaceBlocks(\n\t\t\t\t\t\ttargetBlockClientId,\n\t\t\t\t\t\tsourceBlocks,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t0\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\tsourceClientIds,\n\t\t\t\t\tsourceRootClientId,\n\t\t\t\t\ttargetRootClientId,\n\t\t\t\t\tinsertIndex\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\toperation,\n\t\t\tgetBlockOrder,\n\t\t\tgetBlocksByClientId,\n\t\t\tmoveBlocksToPosition,\n\t\t\tregistry,\n\t\t\tremoveBlocks,\n\t\t\treplaceBlocks,\n\t\t\ttargetBlockIndex,\n\t\t\ttargetRootClientId,\n\t\t]\n\t);\n\n\tconst _onDrop = onBlockDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\tgetBlockIndex,\n\t\tgetClientIdsOfDescendants,\n\t\tmoveBlocks,\n\t\tinsertOrReplaceBlocks,\n\t\tclearSelectedBlock\n\t);\n\tconst _onFilesDrop = onFilesDrop(\n\t\ttargetRootClientId,\n\t\tgetSettings,\n\t\tupdateBlockAttributes,\n\t\tcanInsertBlockType,\n\t\tinsertOrReplaceBlocks\n\t);\n\tconst _onHTMLDrop = onHTMLDrop( insertOrReplaceBlocks );\n\n\treturn ( event ) => {\n\t\tconst files = getFilesFromDataTransfer( event.dataTransfer );\n\t\tconst html = event.dataTransfer.getData( 'text/html' );\n\n\t\t/**\n\t\t * From Windows Chrome 96, the `event.dataTransfer` returns both file object and HTML.\n\t\t * The order of the checks is important to recognise the HTML drop.\n\t\t */\n\t\tif ( html ) {\n\t\t\t_onHTMLDrop( html );\n\t\t} else if ( files.length ) {\n\t\t\t_onFilesDrop( files );\n\t\t} else {\n\t\t\t_onDrop( event );\n\t\t}\n\t};\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,oBAAoB;AAChD,SACCC,UAAU,EACVC,aAAa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B,EAChBC,aAAa,EACbC,yBAAyB,EACzBC,UAAU,EACVC,qBAAqB,EACrBC,kBACD,CAAC;EACD,MAAMgD,YAAY,GAAGjC,WAAW,CAC/BrB,kBAAkB,EAClBsB,WAAW,EACXC,qBAAqB,EACrBC,kBAAkB,EAClBnB,qBACD,CAAC;EACD,MAAMkD,WAAW,GAAGxB,UAAU,CAAE1B,qBAAsB,CAAC;EAEvD,OAASpB,KAAK,IAAM;IACnB,MAAMwC,KAAK,GAAG5C,wBAAwB,CAAEI,KAAK,CAACO,YAAa,CAAC;IAC5D,MAAMgE,IAAI,GAAGvE,KAAK,CAACO,YAAY,CAACK,OAAO,CAAE,WAAY,CAAC;;IAEtD;AACF;AACA;AACA;IACE,IAAK2D,IAAI,EAAG;MACXD,WAAW,CAAEC,IAAK,CAAC;IACpB,CAAC,MAAM,IAAK/B,KAAK,CAACN,MAAM,EAAG;MAC1BmC,YAAY,CAAE7B,KAAM,CAAC;IACtB,CAAC,MAAM;MACN4B,OAAO,CAAEpE,KAAM,CAAC;IACjB;EACD,CAAC;AACF"}
|
|
1
|
+
{"version":3,"names":["useCallback","cloneBlock","createBlock","findTransform","getBlockTransforms","pasteHandler","store","blocksStore","useDispatch","useSelect","useRegistry","getFilesFromDataTransfer","blockEditorStore","parseDropEvent","event","result","srcRootClientId","srcClientIds","srcIndex","type","blocks","dataTransfer","Object","assign","JSON","parse","getData","err","onBlockDrop","targetRootClientId","targetBlockIndex","getBlockIndex","getClientIdsOfDescendants","moveBlocks","insertOrReplaceBlocks","clearSelectedBlock","operation","getBlock","sourceRootClientId","sourceClientIds","dropType","blocksToInsert","map","block","sourceBlockIndex","includes","some","id","clientId","isAtSameLevel","draggedBlockCount","length","insertIndex","onFilesDrop","getSettings","updateBlockAttributes","canInsertBlockType","files","mediaUpload","transformation","transform","blockName","isMatch","onHTMLDrop","HTML","mode","useOnBlockDrop","options","nearestSide","getBlockOrder","getBlocksByClientId","isGroupable","getBlockType","getGroupingBlockName","insertBlocks","moveBlocksToPosition","replaceBlocks","removeBlocks","registry","updateSelection","initialPosition","clientIdsToReplace","clientIds","blocksClientIds","areGroupableBlocks","undefined","targetBlock","push","unshift","groupInnerBlocks","name","attributes","innerBlocks","areAllImages","every","galleryBlock","wrappedBlocks","layout","flexWrap","sourceBlocks","targetBlockClientIds","targetBlockClientId","batch","_onDrop","_onFilesDrop","_onHTMLDrop","html"],"sources":["@wordpress/block-editor/src/components/use-on-block-drop/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport {\n\tcloneBlock,\n\tcreateBlock,\n\tfindTransform,\n\tgetBlockTransforms,\n\tpasteHandler,\n\tstore as blocksStore,\n} from '@wordpress/blocks';\nimport { useDispatch, useSelect, useRegistry } from '@wordpress/data';\nimport { getFilesFromDataTransfer } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('react').SyntheticEvent} SyntheticEvent */\n/** @typedef {import('./types').WPDropOperation} WPDropOperation */\n\n/**\n * Retrieve the data for a block drop event.\n *\n * @param {SyntheticEvent} event The drop event.\n *\n * @return {Object} An object with block drag and drop data.\n */\nexport function parseDropEvent( event ) {\n\tlet result = {\n\t\tsrcRootClientId: null,\n\t\tsrcClientIds: null,\n\t\tsrcIndex: null,\n\t\ttype: null,\n\t\tblocks: null,\n\t};\n\n\tif ( ! event.dataTransfer ) {\n\t\treturn result;\n\t}\n\n\ttry {\n\t\tresult = Object.assign(\n\t\t\tresult,\n\t\t\tJSON.parse( event.dataTransfer.getData( 'wp-blocks' ) )\n\t\t);\n\t} catch ( err ) {\n\t\treturn result;\n\t}\n\n\treturn result;\n}\n\n/**\n * A function that returns an event handler function for block drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Function} getBlockIndex A function that gets the index of a block.\n * @param {Function} getClientIdsOfDescendants A function that gets the client ids of descendant blocks.\n * @param {Function} moveBlocks A function that moves blocks.\n * @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.\n * @param {Function} clearSelectedBlock A function that clears block selection.\n * @param {string} operation The type of operation to perform on drop. Could be `insert` or `replace` or `group`.\n * @param {Function} getBlock A function that returns a block given its client id.\n * @return {Function} The event handler for a block drop event.\n */\nexport function onBlockDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\tgetBlockIndex,\n\tgetClientIdsOfDescendants,\n\tmoveBlocks,\n\tinsertOrReplaceBlocks,\n\tclearSelectedBlock,\n\toperation,\n\tgetBlock\n) {\n\treturn ( event ) => {\n\t\tconst {\n\t\t\tsrcRootClientId: sourceRootClientId,\n\t\t\tsrcClientIds: sourceClientIds,\n\t\t\ttype: dropType,\n\t\t\tblocks,\n\t\t} = parseDropEvent( event );\n\n\t\t// If the user is inserting a block.\n\t\tif ( dropType === 'inserter' ) {\n\t\t\tclearSelectedBlock();\n\t\t\tconst blocksToInsert = blocks.map( ( block ) =>\n\t\t\t\tcloneBlock( block )\n\t\t\t);\n\t\t\tinsertOrReplaceBlocks( blocksToInsert, true, null );\n\t\t}\n\n\t\t// If the user is moving a block.\n\t\tif ( dropType === 'block' ) {\n\t\t\tconst sourceBlockIndex = getBlockIndex( sourceClientIds[ 0 ] );\n\n\t\t\t// If the user is dropping to the same position, return early.\n\t\t\tif (\n\t\t\t\tsourceRootClientId === targetRootClientId &&\n\t\t\t\tsourceBlockIndex === targetBlockIndex\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the user is attempting to drop a block within its own\n\t\t\t// nested blocks, return early as this would create infinite\n\t\t\t// recursion.\n\t\t\tif (\n\t\t\t\tsourceClientIds.includes( targetRootClientId ) ||\n\t\t\t\tgetClientIdsOfDescendants( sourceClientIds ).some(\n\t\t\t\t\t( id ) => id === targetRootClientId\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the user is dropping a block over another block, replace both blocks\n\t\t\t// with a group block containing them\n\t\t\tif ( operation === 'group' ) {\n\t\t\t\tconst blocksToInsert = sourceClientIds.map( ( clientId ) =>\n\t\t\t\t\tgetBlock( clientId )\n\t\t\t\t);\n\t\t\t\tinsertOrReplaceBlocks(\n\t\t\t\t\tblocksToInsert,\n\t\t\t\t\ttrue,\n\t\t\t\t\tnull,\n\t\t\t\t\tsourceClientIds\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isAtSameLevel = sourceRootClientId === targetRootClientId;\n\t\t\tconst draggedBlockCount = sourceClientIds.length;\n\n\t\t\t// If the block is kept at the same level and moved downwards,\n\t\t\t// subtract to take into account that the blocks being dragged\n\t\t\t// were removed from the block list above the insertion point.\n\t\t\tconst insertIndex =\n\t\t\t\tisAtSameLevel && sourceBlockIndex < targetBlockIndex\n\t\t\t\t\t? targetBlockIndex - draggedBlockCount\n\t\t\t\t\t: targetBlockIndex;\n\n\t\t\tmoveBlocks( sourceClientIds, sourceRootClientId, insertIndex );\n\t\t}\n\t};\n}\n\n/**\n * A function that returns an event handler function for block-related file drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {Function} getSettings A function that gets the block editor settings.\n * @param {Function} updateBlockAttributes A function that updates a block's attributes.\n * @param {Function} canInsertBlockType A function that returns checks whether a block type can be inserted.\n * @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.\n *\n * @return {Function} The event handler for a block-related file drop event.\n */\nexport function onFilesDrop(\n\ttargetRootClientId,\n\tgetSettings,\n\tupdateBlockAttributes,\n\tcanInsertBlockType,\n\tinsertOrReplaceBlocks\n) {\n\treturn ( files ) => {\n\t\tif ( ! getSettings().mediaUpload ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst transformation = findTransform(\n\t\t\tgetBlockTransforms( 'from' ),\n\t\t\t( transform ) =>\n\t\t\t\ttransform.type === 'files' &&\n\t\t\t\tcanInsertBlockType( transform.blockName, targetRootClientId ) &&\n\t\t\t\ttransform.isMatch( files )\n\t\t);\n\n\t\tif ( transformation ) {\n\t\t\tconst blocks = transformation.transform(\n\t\t\t\tfiles,\n\t\t\t\tupdateBlockAttributes\n\t\t\t);\n\t\t\tinsertOrReplaceBlocks( blocks );\n\t\t}\n\t};\n}\n\n/**\n * A function that returns an event handler function for block-related HTML drop events.\n *\n * @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.\n *\n * @return {Function} The event handler for a block-related HTML drop event.\n */\nexport function onHTMLDrop( insertOrReplaceBlocks ) {\n\treturn ( HTML ) => {\n\t\tconst blocks = pasteHandler( { HTML, mode: 'BLOCKS' } );\n\n\t\tif ( blocks.length ) {\n\t\t\tinsertOrReplaceBlocks( blocks );\n\t\t}\n\t};\n}\n\n/**\n * A React hook for handling block drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Object} options The optional options.\n * @param {WPDropOperation} [options.operation] The type of operation to perform on drop. Could be `insert` or `replace` for now.\n *\n * @return {Function} A function to be passed to the onDrop handler.\n */\nexport default function useOnBlockDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\toptions = {}\n) {\n\tconst { operation = 'insert', nearestSide = 'right' } = options;\n\tconst {\n\t\tcanInsertBlockType,\n\t\tgetBlockIndex,\n\t\tgetClientIdsOfDescendants,\n\t\tgetBlockOrder,\n\t\tgetBlocksByClientId,\n\t\tgetSettings,\n\t\tgetBlock,\n\t\tisGroupable,\n\t} = useSelect( blockEditorStore );\n\tconst { getBlockType, getGroupingBlockName } = useSelect( blocksStore );\n\tconst {\n\t\tinsertBlocks,\n\t\tmoveBlocksToPosition,\n\t\tupdateBlockAttributes,\n\t\tclearSelectedBlock,\n\t\treplaceBlocks,\n\t\tremoveBlocks,\n\t} = useDispatch( blockEditorStore );\n\tconst registry = useRegistry();\n\n\tconst insertOrReplaceBlocks = useCallback(\n\t\t(\n\t\t\tblocks,\n\t\t\tupdateSelection = true,\n\t\t\tinitialPosition = 0,\n\t\t\tclientIdsToReplace = []\n\t\t) => {\n\t\t\tconst clientIds = getBlockOrder( targetRootClientId );\n\t\t\tconst clientId = clientIds[ targetBlockIndex ];\n\t\t\tconst blocksClientIds = blocks.map( ( block ) => block.clientId );\n\t\t\tconst areGroupableBlocks = isGroupable( [\n\t\t\t\t...blocksClientIds,\n\t\t\t\tclientId,\n\t\t\t] );\n\t\t\tif ( operation === 'replace' ) {\n\t\t\t\treplaceBlocks( clientId, blocks, undefined, initialPosition );\n\t\t\t} else if ( operation === 'group' && areGroupableBlocks ) {\n\t\t\t\tconst targetBlock = getBlock( clientId );\n\t\t\t\tif ( nearestSide === 'left' ) {\n\t\t\t\t\tblocks.push( targetBlock );\n\t\t\t\t} else {\n\t\t\t\t\tblocks.unshift( targetBlock );\n\t\t\t\t}\n\n\t\t\t\tconst groupInnerBlocks = blocks.map( ( block ) => {\n\t\t\t\t\treturn createBlock(\n\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\tblock.attributes,\n\t\t\t\t\t\tblock.innerBlocks\n\t\t\t\t\t);\n\t\t\t\t} );\n\n\t\t\t\tconst areAllImages = blocks.every( ( block ) => {\n\t\t\t\t\treturn block.name === 'core/image';\n\t\t\t\t} );\n\n\t\t\t\tconst galleryBlock = !! getBlockType( 'core/gallery' );\n\n\t\t\t\tconst wrappedBlocks = createBlock(\n\t\t\t\t\tareAllImages && galleryBlock\n\t\t\t\t\t\t? 'core/gallery'\n\t\t\t\t\t\t: getGroupingBlockName(),\n\t\t\t\t\t{\n\t\t\t\t\t\tlayout: {\n\t\t\t\t\t\t\ttype: 'flex',\n\t\t\t\t\t\t\tflexWrap: areAllImages ? null : 'nowrap',\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgroupInnerBlocks\n\t\t\t\t);\n\t\t\t\t// Need to make sure both the target block and the block being dragged are replaced\n\t\t\t\t// otherwise the dragged block will be duplicated.\n\t\t\t\treplaceBlocks(\n\t\t\t\t\t[ clientId, ...clientIdsToReplace ],\n\t\t\t\t\twrappedBlocks,\n\t\t\t\t\tundefined,\n\t\t\t\t\tinitialPosition\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tinsertBlocks(\n\t\t\t\t\tblocks,\n\t\t\t\t\ttargetBlockIndex,\n\t\t\t\t\ttargetRootClientId,\n\t\t\t\t\tupdateSelection,\n\t\t\t\t\tinitialPosition\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tgetBlockOrder,\n\t\t\ttargetRootClientId,\n\t\t\ttargetBlockIndex,\n\t\t\toperation,\n\t\t\treplaceBlocks,\n\t\t\tgetBlock,\n\t\t\tnearestSide,\n\t\t\tgetBlockType,\n\t\t\tgetGroupingBlockName,\n\t\t\tinsertBlocks,\n\t\t]\n\t);\n\n\tconst moveBlocks = useCallback(\n\t\t( sourceClientIds, sourceRootClientId, insertIndex ) => {\n\t\t\tif ( operation === 'replace' ) {\n\t\t\t\tconst sourceBlocks = getBlocksByClientId( sourceClientIds );\n\t\t\t\tconst targetBlockClientIds =\n\t\t\t\t\tgetBlockOrder( targetRootClientId );\n\t\t\t\tconst targetBlockClientId =\n\t\t\t\t\ttargetBlockClientIds[ targetBlockIndex ];\n\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\t// Remove the source blocks.\n\t\t\t\t\tremoveBlocks( sourceClientIds, false );\n\t\t\t\t\t// Replace the target block with the source blocks.\n\t\t\t\t\treplaceBlocks(\n\t\t\t\t\t\ttargetBlockClientId,\n\t\t\t\t\t\tsourceBlocks,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t0\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\tmoveBlocksToPosition(\n\t\t\t\t\tsourceClientIds,\n\t\t\t\t\tsourceRootClientId,\n\t\t\t\t\ttargetRootClientId,\n\t\t\t\t\tinsertIndex\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\toperation,\n\t\t\tgetBlockOrder,\n\t\t\tgetBlocksByClientId,\n\t\t\tmoveBlocksToPosition,\n\t\t\tregistry,\n\t\t\tremoveBlocks,\n\t\t\treplaceBlocks,\n\t\t\ttargetBlockIndex,\n\t\t\ttargetRootClientId,\n\t\t]\n\t);\n\n\tconst _onDrop = onBlockDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\tgetBlockIndex,\n\t\tgetClientIdsOfDescendants,\n\t\tmoveBlocks,\n\t\tinsertOrReplaceBlocks,\n\t\tclearSelectedBlock,\n\t\toperation,\n\t\tgetBlock\n\t);\n\tconst _onFilesDrop = onFilesDrop(\n\t\ttargetRootClientId,\n\t\tgetSettings,\n\t\tupdateBlockAttributes,\n\t\tcanInsertBlockType,\n\t\tinsertOrReplaceBlocks\n\t);\n\tconst _onHTMLDrop = onHTMLDrop( insertOrReplaceBlocks );\n\n\treturn ( event ) => {\n\t\tconst files = getFilesFromDataTransfer( event.dataTransfer );\n\t\tconst html = event.dataTransfer.getData( 'text/html' );\n\n\t\t/**\n\t\t * From Windows Chrome 96, the `event.dataTransfer` returns both file object and HTML.\n\t\t * The order of the checks is important to recognise the HTML drop.\n\t\t */\n\t\tif ( html ) {\n\t\t\t_onHTMLDrop( html );\n\t\t} else if ( files.length ) {\n\t\t\t_onFilesDrop( files );\n\t\t} else {\n\t\t\t_onDrop( event );\n\t\t}\n\t};\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,oBAAoB;AAChD,SACCC,UAAU,EACVC,WAAW,EACXC,aAAa,EACbC,kBAAkB,EAClBC,YAAY,EACZC,KAAK,IAAIC,WAAW,QACd,mBAAmB;AAC1B,SAASC,WAAW,EAAEC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACrE,SAASC,wBAAwB,QAAQ,gBAAgB;;AAEzD;AACA;AACA;AACA,SAASL,KAAK,IAAIM,gBAAgB,QAAQ,aAAa;;AAEvD;AACA;;AAEA;AACA;AACA;AACA;AACA;A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CAAC,EACD,CACChB,SAAS,EACTiC,aAAa,EACbC,mBAAmB,EACnBK,oBAAoB,EACpBG,QAAQ,EACRD,YAAY,EACZD,aAAa,EACb9C,gBAAgB,EAChBD,kBAAkB,CAEpB,CAAC;EAED,MAAM0E,OAAO,GAAG3E,WAAW,CAC1BC,kBAAkB,EAClBC,gBAAgB,EAChBC,aAAa,EACbC,yBAAyB,EACzBC,UAAU,EACVC,qBAAqB,EACrBC,kBAAkB,EAClBC,SAAS,EACTC,QACD,CAAC;EACD,MAAMmE,YAAY,GAAGnD,WAAW,CAC/BxB,kBAAkB,EAClByB,WAAW,EACXC,qBAAqB,EACrBC,kBAAkB,EAClBtB,qBACD,CAAC;EACD,MAAMuE,WAAW,GAAG1C,UAAU,CAAE7B,qBAAsB,CAAC;EAEvD,OAASpB,KAAK,IAAM;IACnB,MAAM2C,KAAK,GAAG9C,wBAAwB,CAAEG,KAAK,CAACO,YAAa,CAAC;IAC5D,MAAMqF,IAAI,GAAG5F,KAAK,CAACO,YAAY,CAACK,OAAO,CAAE,WAAY,CAAC;;IAEtD;AACF;AACA;AACA;IACE,IAAKgF,IAAI,EAAG;MACXD,WAAW,CAAEC,IAAK,CAAC;IACpB,CAAC,MAAM,IAAKjD,KAAK,CAACN,MAAM,EAAG;MAC1BqD,YAAY,CAAE/C,KAAM,CAAC;IACtB,CAAC,MAAM;MACN8C,OAAO,CAAEzF,KAAM,CAAC;IACjB;EACD,CAAC;AACF"}
|
|
@@ -45,8 +45,7 @@ function BlockHooksControlPure({
|
|
|
45
45
|
} = select(blockEditorStore);
|
|
46
46
|
const _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce((clientIds, block) => {
|
|
47
47
|
// If the block doesn't exist anywhere in the block tree,
|
|
48
|
-
// we know that we have to
|
|
49
|
-
// it to disabled.
|
|
48
|
+
// we know that we have to set the toggle to disabled.
|
|
50
49
|
if (getGlobalBlockCount(block.name) === 0) {
|
|
51
50
|
return clientIds;
|
|
52
51
|
}
|
|
@@ -68,7 +67,7 @@ function BlockHooksControlPure({
|
|
|
68
67
|
candidates = getBlock(clientId).innerBlocks;
|
|
69
68
|
break;
|
|
70
69
|
}
|
|
71
|
-
const hookedBlock = candidates?.find(candidate => name ===
|
|
70
|
+
const hookedBlock = candidates?.find(candidate => candidate.name === block.name);
|
|
72
71
|
|
|
73
72
|
// If the block exists in the designated location, we consider it hooked
|
|
74
73
|
// and show the toggle as enabled.
|
|
@@ -80,13 +79,8 @@ function BlockHooksControlPure({
|
|
|
80
79
|
}
|
|
81
80
|
|
|
82
81
|
// If no hooked block was found in any of its designated locations,
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
// block inspector panel.
|
|
86
|
-
return {
|
|
87
|
-
...clientIds,
|
|
88
|
-
[block.name]: false
|
|
89
|
-
};
|
|
82
|
+
// we set the toggle to disabled.
|
|
83
|
+
return clientIds;
|
|
90
84
|
}, {});
|
|
91
85
|
if (Object.values(_hookedBlockClientIds).length > 0) {
|
|
92
86
|
return _hookedBlockClientIds;
|
|
@@ -97,10 +91,7 @@ function BlockHooksControlPure({
|
|
|
97
91
|
insertBlock,
|
|
98
92
|
removeBlock
|
|
99
93
|
} = useDispatch(blockEditorStore);
|
|
100
|
-
|
|
101
|
-
// Remove toggle if block isn't present in the designated location but elsewhere in the block tree.
|
|
102
|
-
const hookedBlocksForCurrentBlockIfNotPresentElsewhere = hookedBlocksForCurrentBlock?.filter(block => hookedBlockClientIds?.[block.name] !== false);
|
|
103
|
-
if (!hookedBlocksForCurrentBlockIfNotPresentElsewhere.length) {
|
|
94
|
+
if (!hookedBlocksForCurrentBlock.length) {
|
|
104
95
|
return null;
|
|
105
96
|
}
|
|
106
97
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","Fragment","useMemo","__experimentalHStack","HStack","PanelBody","ToggleControl","createBlock","store","blocksStore","useDispatch","useSelect","BlockIcon","InspectorControls","blockEditorStore","EMPTY_OBJECT","BlockHooksControlPure","name","clientId","blockTypes","select","getBlockTypes","hookedBlocksForCurrentBlock","filter","blockHooks","blockIndex","rootClientId","innerBlocksLength","getBlock","getBlockIndex","getBlockRootClientId","innerBlocks","length","hookedBlockClientIds","getGlobalBlockCount","_hookedBlockClientIds","reduce","clientIds","block","relativePosition","candidates","hookedBlock","find","candidate","Object","values","insertBlock","removeBlock","hookedBlocksForCurrentBlockIfNotPresentElsewhere","groupedHookedBlocks","groups","namespace","split","push","insertBlockIntoDesignatedLocation","createElement","className","title","initialOpen","keys","map","vendor","key","checked","label","justify","icon","onChange","edit","hasSupport"],"sources":["@wordpress/block-editor/src/hooks/block-hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Fragment, useMemo } from '@wordpress/element';\nimport {\n\t__experimentalHStack as HStack,\n\tPanelBody,\n\tToggleControl,\n} from '@wordpress/components';\nimport { createBlock, store as blocksStore } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { BlockIcon, InspectorControls } from '../components';\nimport { store as blockEditorStore } from '../store';\n\nconst EMPTY_OBJECT = {};\n\nfunction BlockHooksControlPure( { name, clientId } ) {\n\tconst blockTypes = useSelect(\n\t\t( select ) => select( blocksStore ).getBlockTypes(),\n\t\t[]\n\t);\n\n\tconst hookedBlocksForCurrentBlock = useMemo(\n\t\t() =>\n\t\t\tblockTypes?.filter(\n\t\t\t\t( { blockHooks } ) => blockHooks && name in blockHooks\n\t\t\t),\n\t\t[ blockTypes, name ]\n\t);\n\n\tconst { blockIndex, rootClientId, innerBlocksLength } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, getBlockIndex, getBlockRootClientId } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\treturn {\n\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\tinnerBlocksLength: getBlock( clientId )?.innerBlocks?.length,\n\t\t\t\trootClientId: getBlockRootClientId( clientId ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst hookedBlockClientIds = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, getGlobalBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\tconst _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce(\n\t\t\t\t( clientIds, block ) => {\n\t\t\t\t\t// If the block doesn't exist anywhere in the block tree,\n\t\t\t\t\t// we know that we have to display the toggle for it, and set\n\t\t\t\t\t// it to disabled.\n\t\t\t\t\tif ( getGlobalBlockCount( block.name ) === 0 ) {\n\t\t\t\t\t\treturn clientIds;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst relativePosition = block?.blockHooks?.[ name ];\n\t\t\t\t\tlet candidates;\n\n\t\t\t\t\tswitch ( relativePosition ) {\n\t\t\t\t\t\tcase 'before':\n\t\t\t\t\t\tcase 'after':\n\t\t\t\t\t\t\t// Any of the current block's siblings (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked block (inserted `before` or `after` the current one), as the block\n\t\t\t\t\t\t\t// might've been automatically inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlock( rootClientId )?.innerBlocks;\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\tcase 'first_child':\n\t\t\t\t\t\tcase 'last_child':\n\t\t\t\t\t\t\t// Any of the current block's child blocks (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked first or last child block, as the block might've been automatically\n\t\t\t\t\t\t\t// inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlock( clientId ).innerBlocks;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst hookedBlock = candidates?.find(\n\t\t\t\t\t\t( candidate ) => name === candidate.name\n\t\t\t\t\t);\n\n\t\t\t\t\t// If the block exists in the designated location, we consider it hooked\n\t\t\t\t\t// and show the toggle as enabled.\n\t\t\t\t\tif ( hookedBlock ) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...clientIds,\n\t\t\t\t\t\t\t[ block.name ]: hookedBlock.clientId,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// If no hooked block was found in any of its designated locations,\n\t\t\t\t\t// but it exists elsewhere in the block tree, we consider it manually inserted.\n\t\t\t\t\t// In this case, we take note and will remove the corresponding toggle from the\n\t\t\t\t\t// block inspector panel.\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...clientIds,\n\t\t\t\t\t\t[ block.name ]: false,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tif ( Object.values( _hookedBlockClientIds ).length > 0 ) {\n\t\t\t\treturn _hookedBlockClientIds;\n\t\t\t}\n\n\t\t\treturn EMPTY_OBJECT;\n\t\t},\n\t\t[ hookedBlocksForCurrentBlock, name, clientId, rootClientId ]\n\t);\n\n\tconst { insertBlock, removeBlock } = useDispatch( blockEditorStore );\n\n\t// Remove toggle if block isn't present in the designated location but elsewhere in the block tree.\n\tconst hookedBlocksForCurrentBlockIfNotPresentElsewhere =\n\t\thookedBlocksForCurrentBlock?.filter(\n\t\t\t( block ) => hookedBlockClientIds?.[ block.name ] !== false\n\t\t);\n\n\tif ( ! hookedBlocksForCurrentBlockIfNotPresentElsewhere.length ) {\n\t\treturn null;\n\t}\n\n\t// Group by block namespace (i.e. prefix before the slash).\n\tconst groupedHookedBlocks = hookedBlocksForCurrentBlock.reduce(\n\t\t( groups, block ) => {\n\t\t\tconst [ namespace ] = block.name.split( '/' );\n\t\t\tif ( ! groups[ namespace ] ) {\n\t\t\t\tgroups[ namespace ] = [];\n\t\t\t}\n\t\t\tgroups[ namespace ].push( block );\n\t\t\treturn groups;\n\t\t},\n\t\t{}\n\t);\n\n\tconst insertBlockIntoDesignatedLocation = ( block, relativePosition ) => {\n\t\tswitch ( relativePosition ) {\n\t\t\tcase 'before':\n\t\t\tcase 'after':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\trelativePosition === 'after' ? blockIndex + 1 : blockIndex,\n\t\t\t\t\trootClientId, // Insert as a child of the current block's parent\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\n\t\t\tcase 'first_child':\n\t\t\tcase 'last_child':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\t// TODO: It'd be great if insertBlock() would accept negative indices for insertion.\n\t\t\t\t\trelativePosition === 'first_child' ? 0 : innerBlocksLength,\n\t\t\t\t\tclientId, // Insert as a child of the current block.\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\treturn (\n\t\t<InspectorControls>\n\t\t\t<PanelBody\n\t\t\t\tclassName=\"block-editor-hooks__block-hooks\"\n\t\t\t\ttitle={ __( 'Plugins' ) }\n\t\t\t\tinitialOpen={ true }\n\t\t\t>\n\t\t\t\t{ Object.keys( groupedHookedBlocks ).map( ( vendor ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<Fragment key={ vendor }>\n\t\t\t\t\t\t\t<h3>{ vendor }</h3>\n\t\t\t\t\t\t\t{ groupedHookedBlocks[ vendor ].map( ( block ) => {\n\t\t\t\t\t\t\t\tconst checked =\n\t\t\t\t\t\t\t\t\tblock.name in hookedBlockClientIds;\n\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\t\t\tchecked={ checked }\n\t\t\t\t\t\t\t\t\t\tkey={ block.title }\n\t\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\t\t<HStack justify=\"flex-start\">\n\t\t\t\t\t\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\t\t\t\t\t\ticon={ block.icon }\n\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t<span>{ block.title }</span>\n\t\t\t\t\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\tif ( ! checked ) {\n\t\t\t\t\t\t\t\t\t\t\t\t// Create and insert block.\n\t\t\t\t\t\t\t\t\t\t\t\tconst relativePosition =\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.blockHooks[ name ];\n\t\t\t\t\t\t\t\t\t\t\t\tinsertBlockIntoDesignatedLocation(\n\t\t\t\t\t\t\t\t\t\t\t\t\tcreateBlock( block.name ),\n\t\t\t\t\t\t\t\t\t\t\t\t\trelativePosition\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t// Remove block.\n\t\t\t\t\t\t\t\t\t\t\tremoveBlock(\n\t\t\t\t\t\t\t\t\t\t\t\thookedBlockClientIds[\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.name\n\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</Fragment>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n}\n\nexport default {\n\tedit: BlockHooksControlPure,\n\thasSupport() {\n\t\treturn true;\n\t},\n};\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,EAAEC,OAAO,QAAQ,oBAAoB;AACtD,SACCC,oBAAoB,IAAIC,MAAM,EAC9BC,SAAS,EACTC,aAAa,QACP,uBAAuB;AAC9B,SAASC,WAAW,EAAEC,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;AACrE,S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GD;IAAQ,GACvBN,aAAA,aAAMM,MAAY,CAAC,EACjBZ,mBAAmB,CAAEY,MAAM,CAAE,CAACD,GAAG,CAAItB,KAAK,IAAM;MACjD,MAAMyB,OAAO,IACZzB,KAAK,CAACrB,IAAI,IAAIgB,oBAAoB;MAEnC,OACCsB,aAAA,CAACjD,aAAa;QACbyD,OAAO,EAAGA,OAAS;QACnBD,GAAG,EAAGxB,KAAK,CAACmB,KAAO;QACnBO,KAAK,EACJT,aAAA,CAACnD,MAAM;UAAC6D,OAAO,EAAC;QAAY,GAC3BV,aAAA,CAAC3C,SAAS;UACTsD,IAAI,EAAG5B,KAAK,CAAC4B;QAAM,CACnB,CAAC,EACFX,aAAA,eAAQjB,KAAK,CAACmB,KAAa,CACpB,CACR;QACDU,QAAQ,EAAGA,CAAA,KAAM;UAChB,IAAK,CAAEJ,OAAO,EAAG;YAChB;YACA,MAAMxB,gBAAgB,GACrBD,KAAK,CAACd,UAAU,CAAEP,IAAI,CAAE;YACzBqC,iCAAiC,CAChC/C,WAAW,CAAE+B,KAAK,CAACrB,IAAK,CAAC,EACzBsB,gBACD,CAAC;YACD;UACD;;UAEA;UACAQ,WAAW,CACVd,oBAAoB,CACnBK,KAAK,CAACrB,IAAI,CACV,EACD,KACD,CAAC;QACF;MAAG,CACH,CAAC;IAEJ,CAAE,CACO,CAAC;EAEb,CAAE,CACQ,CACO,CAAC;AAEtB;AAEA,eAAe;EACdmD,IAAI,EAAEpD,qBAAqB;EAC3BqD,UAAUA,CAAA,EAAG;IACZ,OAAO,IAAI;EACZ;AACD,CAAC"}
|
|
1
|
+
{"version":3,"names":["__","Fragment","useMemo","__experimentalHStack","HStack","PanelBody","ToggleControl","createBlock","store","blocksStore","useDispatch","useSelect","BlockIcon","InspectorControls","blockEditorStore","EMPTY_OBJECT","BlockHooksControlPure","name","clientId","blockTypes","select","getBlockTypes","hookedBlocksForCurrentBlock","filter","blockHooks","blockIndex","rootClientId","innerBlocksLength","getBlock","getBlockIndex","getBlockRootClientId","innerBlocks","length","hookedBlockClientIds","getGlobalBlockCount","_hookedBlockClientIds","reduce","clientIds","block","relativePosition","candidates","hookedBlock","find","candidate","Object","values","insertBlock","removeBlock","groupedHookedBlocks","groups","namespace","split","push","insertBlockIntoDesignatedLocation","createElement","className","title","initialOpen","keys","map","vendor","key","checked","label","justify","icon","onChange","edit","hasSupport"],"sources":["@wordpress/block-editor/src/hooks/block-hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Fragment, useMemo } from '@wordpress/element';\nimport {\n\t__experimentalHStack as HStack,\n\tPanelBody,\n\tToggleControl,\n} from '@wordpress/components';\nimport { createBlock, store as blocksStore } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { BlockIcon, InspectorControls } from '../components';\nimport { store as blockEditorStore } from '../store';\n\nconst EMPTY_OBJECT = {};\n\nfunction BlockHooksControlPure( { name, clientId } ) {\n\tconst blockTypes = useSelect(\n\t\t( select ) => select( blocksStore ).getBlockTypes(),\n\t\t[]\n\t);\n\n\tconst hookedBlocksForCurrentBlock = useMemo(\n\t\t() =>\n\t\t\tblockTypes?.filter(\n\t\t\t\t( { blockHooks } ) => blockHooks && name in blockHooks\n\t\t\t),\n\t\t[ blockTypes, name ]\n\t);\n\n\tconst { blockIndex, rootClientId, innerBlocksLength } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, getBlockIndex, getBlockRootClientId } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\treturn {\n\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\tinnerBlocksLength: getBlock( clientId )?.innerBlocks?.length,\n\t\t\t\trootClientId: getBlockRootClientId( clientId ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst hookedBlockClientIds = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, getGlobalBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\tconst _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce(\n\t\t\t\t( clientIds, block ) => {\n\t\t\t\t\t// If the block doesn't exist anywhere in the block tree,\n\t\t\t\t\t// we know that we have to set the toggle to disabled.\n\t\t\t\t\tif ( getGlobalBlockCount( block.name ) === 0 ) {\n\t\t\t\t\t\treturn clientIds;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst relativePosition = block?.blockHooks?.[ name ];\n\t\t\t\t\tlet candidates;\n\n\t\t\t\t\tswitch ( relativePosition ) {\n\t\t\t\t\t\tcase 'before':\n\t\t\t\t\t\tcase 'after':\n\t\t\t\t\t\t\t// Any of the current block's siblings (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked block (inserted `before` or `after` the current one), as the block\n\t\t\t\t\t\t\t// might've been automatically inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlock( rootClientId )?.innerBlocks;\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\tcase 'first_child':\n\t\t\t\t\t\tcase 'last_child':\n\t\t\t\t\t\t\t// Any of the current block's child blocks (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked first or last child block, as the block might've been automatically\n\t\t\t\t\t\t\t// inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlock( clientId ).innerBlocks;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst hookedBlock = candidates?.find(\n\t\t\t\t\t\t( candidate ) => candidate.name === block.name\n\t\t\t\t\t);\n\n\t\t\t\t\t// If the block exists in the designated location, we consider it hooked\n\t\t\t\t\t// and show the toggle as enabled.\n\t\t\t\t\tif ( hookedBlock ) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...clientIds,\n\t\t\t\t\t\t\t[ block.name ]: hookedBlock.clientId,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// If no hooked block was found in any of its designated locations,\n\t\t\t\t\t// we set the toggle to disabled.\n\t\t\t\t\treturn clientIds;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tif ( Object.values( _hookedBlockClientIds ).length > 0 ) {\n\t\t\t\treturn _hookedBlockClientIds;\n\t\t\t}\n\n\t\t\treturn EMPTY_OBJECT;\n\t\t},\n\t\t[ hookedBlocksForCurrentBlock, name, clientId, rootClientId ]\n\t);\n\n\tconst { insertBlock, removeBlock } = useDispatch( blockEditorStore );\n\n\tif ( ! hookedBlocksForCurrentBlock.length ) {\n\t\treturn null;\n\t}\n\n\t// Group by block namespace (i.e. prefix before the slash).\n\tconst groupedHookedBlocks = hookedBlocksForCurrentBlock.reduce(\n\t\t( groups, block ) => {\n\t\t\tconst [ namespace ] = block.name.split( '/' );\n\t\t\tif ( ! groups[ namespace ] ) {\n\t\t\t\tgroups[ namespace ] = [];\n\t\t\t}\n\t\t\tgroups[ namespace ].push( block );\n\t\t\treturn groups;\n\t\t},\n\t\t{}\n\t);\n\n\tconst insertBlockIntoDesignatedLocation = ( block, relativePosition ) => {\n\t\tswitch ( relativePosition ) {\n\t\t\tcase 'before':\n\t\t\tcase 'after':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\trelativePosition === 'after' ? blockIndex + 1 : blockIndex,\n\t\t\t\t\trootClientId, // Insert as a child of the current block's parent\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\n\t\t\tcase 'first_child':\n\t\t\tcase 'last_child':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\t// TODO: It'd be great if insertBlock() would accept negative indices for insertion.\n\t\t\t\t\trelativePosition === 'first_child' ? 0 : innerBlocksLength,\n\t\t\t\t\tclientId, // Insert as a child of the current block.\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\treturn (\n\t\t<InspectorControls>\n\t\t\t<PanelBody\n\t\t\t\tclassName=\"block-editor-hooks__block-hooks\"\n\t\t\t\ttitle={ __( 'Plugins' ) }\n\t\t\t\tinitialOpen={ true }\n\t\t\t>\n\t\t\t\t{ Object.keys( groupedHookedBlocks ).map( ( vendor ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<Fragment key={ vendor }>\n\t\t\t\t\t\t\t<h3>{ vendor }</h3>\n\t\t\t\t\t\t\t{ groupedHookedBlocks[ vendor ].map( ( block ) => {\n\t\t\t\t\t\t\t\tconst checked =\n\t\t\t\t\t\t\t\t\tblock.name in hookedBlockClientIds;\n\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\t\t\tchecked={ checked }\n\t\t\t\t\t\t\t\t\t\tkey={ block.title }\n\t\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\t\t<HStack justify=\"flex-start\">\n\t\t\t\t\t\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\t\t\t\t\t\ticon={ block.icon }\n\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t<span>{ block.title }</span>\n\t\t\t\t\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\tif ( ! checked ) {\n\t\t\t\t\t\t\t\t\t\t\t\t// Create and insert block.\n\t\t\t\t\t\t\t\t\t\t\t\tconst relativePosition =\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.blockHooks[ name ];\n\t\t\t\t\t\t\t\t\t\t\t\tinsertBlockIntoDesignatedLocation(\n\t\t\t\t\t\t\t\t\t\t\t\t\tcreateBlock( block.name ),\n\t\t\t\t\t\t\t\t\t\t\t\t\trelativePosition\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t// Remove block.\n\t\t\t\t\t\t\t\t\t\t\tremoveBlock(\n\t\t\t\t\t\t\t\t\t\t\t\thookedBlockClientIds[\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.name\n\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</Fragment>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n}\n\nexport default {\n\tedit: BlockHooksControlPure,\n\thasSupport() {\n\t\treturn true;\n\t},\n};\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,EAAEC,OAAO,QAAQ,oBAAoB;AACtD,SACCC,oBAAoB,IAAIC,MAAM,EAC9BC,SAAS,EACTC,aAAa,QACP,uBAAuB;AAC9B,SAASC,WAAW,EAAEC,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;AACrE,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;;AAExD;AACA;AACA;AACA,SAASC,SAAS,EAAEC,iBAAiB,QAAQ,eAAe;AAC5D,SAASL,KAAK,IAAIM,gBAAgB,QAAQ,UAAU;AAEpD,MAAMC,YAAY,GAAG,CAAC,CAAC;AAEvB,SAASC,qBAAqBA,CAAE;EAAEC,IAAI;EAAEC;AAAS,CAAC,EAAG;EACpD,MAAMC,UAAU,GAAGR,SAAS,CACzBS,MAAM,IAAMA,MAAM,CAAEX,WAAY,CAAC,CAACY,aAAa,CAAC,CAAC,EACnD,EACD,CAAC;EAED,MAAMC,2BAA2B,GAAGpB,OAAO,CAC1C,MACCiB,UAAU,EAAEI,MAAM,CACjB,CAAE;IAAEC;EA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,CAAC,EACzBsB,gBACD,CAAC;YACD;UACD;;UAEA;UACAQ,WAAW,CACVd,oBAAoB,CACnBK,KAAK,CAACrB,IAAI,CACV,EACD,KACD,CAAC;QACF;MAAG,CACH,CAAC;IAEJ,CAAE,CACO,CAAC;EAEb,CAAE,CACQ,CACO,CAAC;AAEtB;AAEA,eAAe;EACdkD,IAAI,EAAEnD,qBAAqB;EAC3BoD,UAAUA,CAAA,EAAG;IACZ,OAAO,IAAI;EACZ;AACD,CAAC"}
|
|
@@ -5,31 +5,21 @@ import { createElement, Fragment } from "react";
|
|
|
5
5
|
import { ToolbarButton, MenuItem } from '@wordpress/components';
|
|
6
6
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
7
7
|
import { __ } from '@wordpress/i18n';
|
|
8
|
-
import {
|
|
8
|
+
import { useCallback } from '@wordpress/element';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Internal dependencies
|
|
12
12
|
*/
|
|
13
13
|
import { store as blockEditorStore } from '../store';
|
|
14
14
|
import { BlockControls, BlockSettingsMenuControls } from '../components';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} = select(blockEditorStore);
|
|
24
|
-
return isBlockSelected(clientId) || hasSelectedInnerBlock(clientId, true);
|
|
25
|
-
}, [clientId]);
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
if (!isBlockOrDescendantSelected) {
|
|
28
|
-
stopEditingAsBlock();
|
|
29
|
-
}
|
|
30
|
-
}, [isBlockOrDescendantSelected, stopEditingAsBlock]);
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
15
|
+
import { unlock } from '../lock-unlock';
|
|
16
|
+
|
|
17
|
+
// The implementation of content locking is mainly in this file, although the mechanism
|
|
18
|
+
// to stop temporarily editing as blocks when an outside block is selected is on component StopEditingAsBlocksOnOutsideSelect
|
|
19
|
+
// at block-editor/src/components/block-list/index.js.
|
|
20
|
+
// Besides the components on this file and the file referenced above the implementation
|
|
21
|
+
// also includes artifacts on the store (actions, reducers, and selector).
|
|
22
|
+
|
|
33
23
|
function ContentLockControlsPure({
|
|
34
24
|
clientId,
|
|
35
25
|
isSelected
|
|
@@ -38,7 +28,6 @@ function ContentLockControlsPure({
|
|
|
38
28
|
getBlockListSettings,
|
|
39
29
|
getSettings
|
|
40
30
|
} = useSelect(blockEditorStore);
|
|
41
|
-
const focusModeToRevert = useRef();
|
|
42
31
|
const {
|
|
43
32
|
templateLock,
|
|
44
33
|
isLockedByParent,
|
|
@@ -60,39 +49,26 @@ function ContentLockControlsPure({
|
|
|
60
49
|
updateBlockListSettings,
|
|
61
50
|
__unstableSetTemporarilyEditingAsBlocks
|
|
62
51
|
} = useDispatch(blockEditorStore);
|
|
52
|
+
const {
|
|
53
|
+
stopEditingAsBlocks
|
|
54
|
+
} = unlock(useDispatch(blockEditorStore));
|
|
63
55
|
const isContentLocked = !isLockedByParent && templateLock === 'contentOnly';
|
|
64
56
|
const {
|
|
65
57
|
__unstableMarkNextChangeAsNotPersistent,
|
|
66
58
|
updateBlockAttributes
|
|
67
59
|
} = useDispatch(blockEditorStore);
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
templateLock: 'contentOnly'
|
|
72
|
-
});
|
|
73
|
-
updateBlockListSettings(clientId, {
|
|
74
|
-
...getBlockListSettings(clientId),
|
|
75
|
-
templateLock: 'contentOnly'
|
|
76
|
-
});
|
|
77
|
-
updateSettings({
|
|
78
|
-
focusMode: focusModeToRevert.current
|
|
79
|
-
});
|
|
80
|
-
__unstableSetTemporarilyEditingAsBlocks();
|
|
81
|
-
}, [clientId, updateSettings, updateBlockListSettings, getBlockListSettings, __unstableMarkNextChangeAsNotPersistent, updateBlockAttributes, __unstableSetTemporarilyEditingAsBlocks]);
|
|
60
|
+
const stopEditingAsBlockCallback = useCallback(() => {
|
|
61
|
+
stopEditingAsBlocks(clientId);
|
|
62
|
+
}, [clientId, stopEditingAsBlocks]);
|
|
82
63
|
if (!isContentLocked && !isEditingAsBlocks) {
|
|
83
64
|
return null;
|
|
84
65
|
}
|
|
85
66
|
const showStopEditingAsBlocks = isEditingAsBlocks && !isContentLocked;
|
|
86
67
|
const showStartEditingAsBlocks = !isEditingAsBlocks && isContentLocked && isSelected;
|
|
87
|
-
return createElement(Fragment, null, showStopEditingAsBlocks && createElement(Fragment, null, createElement(
|
|
88
|
-
clientId: clientId,
|
|
89
|
-
stopEditingAsBlock: stopEditingAsBlock
|
|
90
|
-
}), createElement(BlockControls, {
|
|
68
|
+
return createElement(Fragment, null, showStopEditingAsBlocks && createElement(Fragment, null, createElement(BlockControls, {
|
|
91
69
|
group: "other"
|
|
92
70
|
}, createElement(ToolbarButton, {
|
|
93
|
-
onClick:
|
|
94
|
-
stopEditingAsBlock();
|
|
95
|
-
}
|
|
71
|
+
onClick: stopEditingAsBlockCallback
|
|
96
72
|
}, __('Done')))), showStartEditingAsBlocks && createElement(BlockSettingsMenuControls, null, ({
|
|
97
73
|
onClose
|
|
98
74
|
}) => createElement(MenuItem, {
|
|
@@ -105,11 +81,11 @@ function ContentLockControlsPure({
|
|
|
105
81
|
...getBlockListSettings(clientId),
|
|
106
82
|
templateLock: false
|
|
107
83
|
});
|
|
108
|
-
focusModeToRevert
|
|
84
|
+
const focusModeToRevert = getSettings().focusMode;
|
|
109
85
|
updateSettings({
|
|
110
86
|
focusMode: true
|
|
111
87
|
});
|
|
112
|
-
__unstableSetTemporarilyEditingAsBlocks(clientId);
|
|
88
|
+
__unstableSetTemporarilyEditingAsBlocks(clientId, focusModeToRevert);
|
|
113
89
|
onClose();
|
|
114
90
|
}
|
|
115
91
|
}, __('Modify'))));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ToolbarButton","MenuItem","useDispatch","useSelect","__","
|
|
1
|
+
{"version":3,"names":["ToolbarButton","MenuItem","useDispatch","useSelect","__","useCallback","store","blockEditorStore","BlockControls","BlockSettingsMenuControls","unlock","ContentLockControlsPure","clientId","isSelected","getBlockListSettings","getSettings","templateLock","isLockedByParent","isEditingAsBlocks","select","__unstableGetContentLockingParent","getTemplateLock","__unstableGetTemporarilyEditingAsBlocks","updateSettings","updateBlockListSettings","__unstableSetTemporarilyEditingAsBlocks","stopEditingAsBlocks","isContentLocked","__unstableMarkNextChangeAsNotPersistent","updateBlockAttributes","stopEditingAsBlockCallback","showStopEditingAsBlocks","showStartEditingAsBlocks","createElement","Fragment","group","onClick","onClose","undefined","focusModeToRevert","focusMode","edit","hasSupport"],"sources":["@wordpress/block-editor/src/hooks/content-lock-ui.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { ToolbarButton, MenuItem } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\nimport { BlockControls, BlockSettingsMenuControls } from '../components';\nimport { unlock } from '../lock-unlock';\n\n// The implementation of content locking is mainly in this file, although the mechanism\n// to stop temporarily editing as blocks when an outside block is selected is on component StopEditingAsBlocksOnOutsideSelect\n// at block-editor/src/components/block-list/index.js.\n// Besides the components on this file and the file referenced above the implementation\n// also includes artifacts on the store (actions, reducers, and selector).\n\nfunction ContentLockControlsPure( { clientId, isSelected } ) {\n\tconst { getBlockListSettings, getSettings } = useSelect( blockEditorStore );\n\tconst { templateLock, isLockedByParent, isEditingAsBlocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\t__unstableGetContentLockingParent,\n\t\t\t\tgetTemplateLock,\n\t\t\t\t__unstableGetTemporarilyEditingAsBlocks,\n\t\t\t} = select( blockEditorStore );\n\t\t\treturn {\n\t\t\t\ttemplateLock: getTemplateLock( clientId ),\n\t\t\t\tisLockedByParent:\n\t\t\t\t\t!! __unstableGetContentLockingParent( clientId ),\n\t\t\t\tisEditingAsBlocks:\n\t\t\t\t\t__unstableGetTemporarilyEditingAsBlocks() === clientId,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst {\n\t\tupdateSettings,\n\t\tupdateBlockListSettings,\n\t\t__unstableSetTemporarilyEditingAsBlocks,\n\t} = useDispatch( blockEditorStore );\n\tconst { stopEditingAsBlocks } = unlock( useDispatch( blockEditorStore ) );\n\tconst isContentLocked =\n\t\t! isLockedByParent && templateLock === 'contentOnly';\n\tconst { __unstableMarkNextChangeAsNotPersistent, updateBlockAttributes } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst stopEditingAsBlockCallback = useCallback( () => {\n\t\tstopEditingAsBlocks( clientId );\n\t}, [ clientId, stopEditingAsBlocks ] );\n\n\tif ( ! isContentLocked && ! isEditingAsBlocks ) {\n\t\treturn null;\n\t}\n\n\tconst showStopEditingAsBlocks = isEditingAsBlocks && ! isContentLocked;\n\tconst showStartEditingAsBlocks =\n\t\t! isEditingAsBlocks && isContentLocked && isSelected;\n\n\treturn (\n\t\t<>\n\t\t\t{ showStopEditingAsBlocks && (\n\t\t\t\t<>\n\t\t\t\t\t<BlockControls group=\"other\">\n\t\t\t\t\t\t<ToolbarButton onClick={ stopEditingAsBlockCallback }>\n\t\t\t\t\t\t\t{ __( 'Done' ) }\n\t\t\t\t\t\t</ToolbarButton>\n\t\t\t\t\t</BlockControls>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ showStartEditingAsBlocks && (\n\t\t\t\t<BlockSettingsMenuControls>\n\t\t\t\t\t{ ( { onClose } ) => (\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\t\t\t\tupdateBlockAttributes( clientId, {\n\t\t\t\t\t\t\t\t\ttemplateLock: undefined,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\tupdateBlockListSettings( clientId, {\n\t\t\t\t\t\t\t\t\t...getBlockListSettings( clientId ),\n\t\t\t\t\t\t\t\t\ttemplateLock: false,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\tconst focusModeToRevert =\n\t\t\t\t\t\t\t\t\tgetSettings().focusMode;\n\t\t\t\t\t\t\t\tupdateSettings( { focusMode: true } );\n\t\t\t\t\t\t\t\t__unstableSetTemporarilyEditingAsBlocks(\n\t\t\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\t\t\tfocusModeToRevert\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Modify' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t) }\n\t\t\t\t</BlockSettingsMenuControls>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default {\n\tedit: ContentLockControlsPure,\n\thasSupport() {\n\t\treturn true;\n\t},\n};\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,uBAAuB;AAC/D,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,WAAW,QAAQ,oBAAoB;;AAEhD;AACA;AACA;AACA,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,UAAU;AACpD,SAASC,aAAa,EAAEC,yBAAyB,QAAQ,eAAe;AACxE,SAASC,MAAM,QAAQ,gBAAgB;;AAEvC;AACA;AACA;AACA;AACA;;AAEA,SAASC,uBAAuBA,CAAE;EAAEC,QAAQ;EAAEC;AAAW,CAAC,EAAG;EAC5D,MAAM;IAAEC,oBAAoB;IAAEC;EAAY,CAAC,GAAGZ,SAAS,CAAEI,gBAAiB,CAAC;EAC3E,MAAM;IAAES,YAAY;IAAEC,gBAAgB;IAAEC;EAAkB,CAAC,GAAGf,SAAS,CACpEgB,MAAM,IAAM;IACb,MAAM;MACLC,iCAAiC;MACjCC,eAAe;MACfC;IACD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