@wordpress/block-editor 15.8.1-next.16d95556a.0 → 15.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/block-inspector/edit-contents.js +19 -23
- package/build/components/block-inspector/edit-contents.js.map +3 -3
- package/build/components/block-inspector/index.js +7 -1
- package/build/components/block-inspector/index.js.map +2 -2
- package/build/components/block-list/block.js +4 -0
- package/build/components/block-list/block.js.map +2 -2
- package/build/components/block-list/index.js +2 -1
- package/build/components/block-list/index.js.map +2 -2
- package/build/components/block-list/use-block-props/index.js +3 -1
- package/build/components/block-list/use-block-props/index.js.map +2 -2
- package/build/components/block-list/use-block-props/use-is-hovered.js +16 -10
- package/build/components/block-list/use-block-props/use-is-hovered.js.map +2 -2
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js +27 -5
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +2 -2
- package/build/components/block-lock/modal.js +5 -5
- package/build/components/block-lock/modal.js.map +2 -2
- package/build/components/block-lock/use-block-lock.js +10 -13
- package/build/components/block-lock/use-block-lock.js.map +2 -2
- package/build/components/block-settings-menu-controls/edit-section-menu-item.js +64 -0
- package/build/components/block-settings-menu-controls/edit-section-menu-item.js.map +7 -0
- package/build/components/block-settings-menu-controls/index.js +9 -1
- package/build/components/block-settings-menu-controls/index.js.map +2 -2
- package/build/components/block-toolbar/block-toolbar-icon.js +9 -9
- package/build/components/block-toolbar/block-toolbar-icon.js.map +2 -2
- package/build/components/block-tools/index.js +56 -45
- package/build/components/block-tools/index.js.map +3 -3
- package/build/components/block-variation-transforms/index.js +32 -5
- package/build/components/block-variation-transforms/index.js.map +2 -2
- package/build/components/block-visibility/toolbar.js +1 -1
- package/build/components/block-visibility/toolbar.js.map +1 -1
- package/build/components/border-radius-control/single-input-control.js +1 -0
- package/build/components/border-radius-control/single-input-control.js.map +2 -2
- package/build/components/content-only-controls/fields-dropdown-menu.js +66 -0
- package/build/components/content-only-controls/fields-dropdown-menu.js.map +7 -0
- package/build/components/content-only-controls/index.js +444 -0
- package/build/components/content-only-controls/index.js.map +7 -0
- package/build/components/content-only-controls/link/index.js +193 -0
- package/build/components/content-only-controls/link/index.js.map +7 -0
- package/build/components/content-only-controls/media/index.js +264 -0
- package/build/components/content-only-controls/media/index.js.map +7 -0
- package/build/components/content-only-controls/rich-text/index.js +188 -0
- package/build/components/content-only-controls/rich-text/index.js.map +7 -0
- package/build/components/content-only-controls/use-inspector-popover-placement.js +41 -0
- package/build/components/content-only-controls/use-inspector-popover-placement.js.map +7 -0
- package/build/components/font-family/index.js +1 -15
- package/build/components/font-family/index.js.map +2 -2
- package/build/components/global-styles/dimensions-panel.js +35 -2
- package/build/components/global-styles/dimensions-panel.js.map +2 -2
- package/build/components/global-styles/hooks.js +1 -1
- package/build/components/global-styles/hooks.js.map +2 -2
- package/build/components/global-styles/typography-panel.js +1 -2
- package/build/components/global-styles/typography-panel.js.map +2 -2
- package/build/components/inserter/media-tab/media-tab.js +1 -33
- package/build/components/inserter/media-tab/media-tab.js.map +3 -3
- package/build/components/inspector-controls-tabs/content-tab.js +6 -2
- package/build/components/inspector-controls-tabs/content-tab.js.map +3 -3
- package/build/components/inspector-controls-tabs/index.js +7 -1
- package/build/components/inspector-controls-tabs/index.js.map +2 -2
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -1
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +2 -2
- package/build/components/link-control/index.js +15 -7
- package/build/components/link-control/index.js.map +2 -2
- package/build/components/list-view/block-select-button.js +7 -8
- package/build/components/list-view/block-select-button.js.map +2 -2
- package/build/components/list-view/block.js +9 -7
- package/build/components/list-view/block.js.map +2 -2
- package/build/components/media-placeholder/index.js +18 -35
- package/build/components/media-placeholder/index.js.map +3 -3
- package/build/components/media-placeholder/utils.js +60 -0
- package/build/components/media-placeholder/utils.js.map +7 -0
- package/build/components/media-replace-flow/index.js +24 -33
- package/build/components/media-replace-flow/index.js.map +3 -3
- package/build/components/use-block-commands/index.js +1 -1
- package/build/components/use-block-commands/index.js.map +2 -2
- package/build/components/use-block-display-information/index.js +21 -1
- package/build/components/use-block-display-information/index.js.map +3 -3
- package/build/components/use-block-drop-zone/index.js +1 -5
- package/build/components/use-block-drop-zone/index.js.map +2 -2
- package/build/hooks/block-bindings.js +52 -61
- package/build/hooks/block-bindings.js.map +3 -3
- package/build/hooks/dimensions.js +3 -3
- package/build/hooks/dimensions.js.map +2 -2
- package/build/hooks/metadata.js +1 -1
- package/build/hooks/metadata.js.map +2 -2
- package/build/hooks/use-content-only-section-edit.js +67 -0
- package/build/hooks/use-content-only-section-edit.js.map +7 -0
- package/build/hooks/utils.js +5 -1
- package/build/hooks/utils.js.map +2 -2
- package/build/layouts/constrained.js +2 -2
- package/build/layouts/constrained.js.map +2 -2
- package/build/private-apis.js +2 -3
- package/build/private-apis.js.map +3 -3
- package/build/store/private-keys.js +3 -0
- package/build/store/private-keys.js.map +2 -2
- package/build/store/private-selectors.js +41 -2
- package/build/store/private-selectors.js.map +2 -2
- package/build/store/selectors.js +6 -4
- package/build/store/selectors.js.map +2 -2
- package/build/utils/fit-text-utils.js +9 -1
- package/build/utils/fit-text-utils.js.map +2 -2
- package/build-module/components/block-inspector/edit-contents.js +9 -23
- package/build-module/components/block-inspector/edit-contents.js.map +2 -2
- package/build-module/components/block-inspector/index.js +7 -1
- package/build-module/components/block-inspector/index.js.map +2 -2
- package/build-module/components/block-list/block.js +4 -0
- package/build-module/components/block-list/block.js.map +2 -2
- package/build-module/components/block-list/index.js +2 -1
- package/build-module/components/block-list/index.js.map +2 -2
- package/build-module/components/block-list/use-block-props/index.js +3 -1
- package/build-module/components/block-list/use-block-props/index.js.map +2 -2
- package/build-module/components/block-list/use-block-props/use-is-hovered.js +16 -10
- package/build-module/components/block-list/use-block-props/use-is-hovered.js.map +2 -2
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js +27 -5
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +2 -2
- package/build-module/components/block-lock/modal.js +5 -5
- package/build-module/components/block-lock/modal.js.map +2 -2
- package/build-module/components/block-lock/use-block-lock.js +10 -13
- package/build-module/components/block-lock/use-block-lock.js.map +2 -2
- package/build-module/components/block-settings-menu-controls/edit-section-menu-item.js +29 -0
- package/build-module/components/block-settings-menu-controls/edit-section-menu-item.js.map +7 -0
- package/build-module/components/block-settings-menu-controls/index.js +9 -1
- package/build-module/components/block-settings-menu-controls/index.js.map +2 -2
- package/build-module/components/block-toolbar/block-toolbar-icon.js +10 -10
- package/build-module/components/block-toolbar/block-toolbar-icon.js.map +2 -2
- package/build-module/components/block-tools/index.js +56 -45
- package/build-module/components/block-tools/index.js.map +2 -2
- package/build-module/components/block-variation-transforms/index.js +32 -5
- package/build-module/components/block-variation-transforms/index.js.map +2 -2
- package/build-module/components/block-visibility/toolbar.js +1 -1
- package/build-module/components/block-visibility/toolbar.js.map +1 -1
- package/build-module/components/border-radius-control/single-input-control.js +1 -0
- package/build-module/components/border-radius-control/single-input-control.js.map +2 -2
- package/build-module/components/content-only-controls/fields-dropdown-menu.js +45 -0
- package/build-module/components/content-only-controls/fields-dropdown-menu.js.map +7 -0
- package/build-module/components/content-only-controls/index.js +420 -0
- package/build-module/components/content-only-controls/index.js.map +7 -0
- package/build-module/components/content-only-controls/link/index.js +160 -0
- package/build-module/components/content-only-controls/link/index.js.map +7 -0
- package/build-module/components/content-only-controls/media/index.js +242 -0
- package/build-module/components/content-only-controls/media/index.js.map +7 -0
- package/build-module/components/content-only-controls/rich-text/index.js +160 -0
- package/build-module/components/content-only-controls/rich-text/index.js.map +7 -0
- package/build-module/components/content-only-controls/use-inspector-popover-placement.js +16 -0
- package/build-module/components/content-only-controls/use-inspector-popover-placement.js.map +7 -0
- package/build-module/components/font-family/index.js +1 -15
- package/build-module/components/font-family/index.js.map +2 -2
- package/build-module/components/global-styles/dimensions-panel.js +35 -2
- package/build-module/components/global-styles/dimensions-panel.js.map +2 -2
- package/build-module/components/global-styles/hooks.js +1 -1
- package/build-module/components/global-styles/hooks.js.map +2 -2
- package/build-module/components/global-styles/typography-panel.js +1 -2
- package/build-module/components/global-styles/typography-panel.js.map +2 -2
- package/build-module/components/inserter/media-tab/media-tab.js +2 -34
- package/build-module/components/inserter/media-tab/media-tab.js.map +2 -2
- package/build-module/components/inspector-controls-tabs/content-tab.js +7 -3
- package/build-module/components/inspector-controls-tabs/content-tab.js.map +2 -2
- package/build-module/components/inspector-controls-tabs/index.js +7 -1
- package/build-module/components/inspector-controls-tabs/index.js.map +2 -2
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -1
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +2 -2
- package/build-module/components/link-control/index.js +16 -8
- package/build-module/components/link-control/index.js.map +2 -2
- package/build-module/components/list-view/block-select-button.js +14 -9
- package/build-module/components/list-view/block-select-button.js.map +2 -2
- package/build-module/components/list-view/block.js +9 -7
- package/build-module/components/list-view/block.js.map +2 -2
- package/build-module/components/media-placeholder/index.js +19 -36
- package/build-module/components/media-placeholder/index.js.map +2 -2
- package/build-module/components/media-placeholder/utils.js +35 -0
- package/build-module/components/media-placeholder/utils.js.map +7 -0
- package/build-module/components/media-replace-flow/index.js +24 -33
- package/build-module/components/media-replace-flow/index.js.map +2 -2
- package/build-module/components/use-block-commands/index.js +1 -1
- package/build-module/components/use-block-commands/index.js.map +2 -2
- package/build-module/components/use-block-display-information/index.js +21 -1
- package/build-module/components/use-block-display-information/index.js.map +3 -3
- package/build-module/components/use-block-drop-zone/index.js +1 -5
- package/build-module/components/use-block-drop-zone/index.js.map +2 -2
- package/build-module/hooks/block-bindings.js +57 -62
- package/build-module/hooks/block-bindings.js.map +2 -2
- package/build-module/hooks/dimensions.js +3 -3
- package/build-module/hooks/dimensions.js.map +2 -2
- package/build-module/hooks/metadata.js +1 -1
- package/build-module/hooks/metadata.js.map +2 -2
- package/build-module/hooks/use-content-only-section-edit.js +46 -0
- package/build-module/hooks/use-content-only-section-edit.js.map +7 -0
- package/build-module/hooks/utils.js +5 -1
- package/build-module/hooks/utils.js.map +2 -2
- package/build-module/layouts/constrained.js +2 -2
- package/build-module/layouts/constrained.js.map +2 -2
- package/build-module/private-apis.js +3 -3
- package/build-module/private-apis.js.map +2 -2
- package/build-module/store/private-keys.js +2 -0
- package/build-module/store/private-keys.js.map +2 -2
- package/build-module/store/private-selectors.js +37 -2
- package/build-module/store/private-selectors.js.map +2 -2
- package/build-module/store/selectors.js +6 -4
- package/build-module/store/selectors.js.map +2 -2
- package/build-module/utils/fit-text-utils.js +9 -1
- package/build-module/utils/fit-text-utils.js.map +2 -2
- package/build-style/content-rtl.css +3 -0
- package/build-style/content.css +3 -0
- package/build-style/style-rtl.css +145 -4
- package/build-style/style.css +145 -4
- package/package.json +38 -37
- package/src/components/block-inspector/edit-contents.js +10 -29
- package/src/components/block-inspector/index.js +4 -2
- package/src/components/block-list/block.js +6 -0
- package/src/components/block-list/content.scss +5 -0
- package/src/components/block-list/index.js +3 -1
- package/src/components/block-list/use-block-props/index.js +3 -1
- package/src/components/block-list/use-block-props/use-is-hovered.js +24 -12
- package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +34 -3
- package/src/components/block-lock/modal.js +6 -5
- package/src/components/block-lock/use-block-lock.js +10 -14
- package/src/components/block-patterns-list/stories/{index.story.js → index.story.jsx} +3 -1
- package/src/components/block-settings-menu-controls/edit-section-menu-item.js +39 -0
- package/src/components/block-settings-menu-controls/index.js +8 -1
- package/src/components/block-toolbar/block-toolbar-icon.js +14 -10
- package/src/components/block-tools/index.js +15 -2
- package/src/components/block-tools/style.scss +4 -0
- package/src/components/block-variation-transforms/index.js +96 -35
- package/src/components/block-visibility/toolbar.js +1 -1
- package/src/components/border-radius-control/single-input-control.js +1 -0
- package/src/components/content-only-controls/fields-dropdown-menu.js +53 -0
- package/src/components/content-only-controls/index.js +560 -0
- package/src/components/content-only-controls/link/index.js +200 -0
- package/src/components/content-only-controls/link/styles.scss +23 -0
- package/src/components/content-only-controls/media/index.js +306 -0
- package/src/components/content-only-controls/media/styles.scss +47 -0
- package/src/components/content-only-controls/rich-text/index.js +179 -0
- package/src/components/content-only-controls/rich-text/styles.scss +24 -0
- package/src/components/content-only-controls/styles.scss +44 -0
- package/src/components/content-only-controls/use-inspector-popover-placement.js +19 -0
- package/src/components/font-family/README.md +0 -9
- package/src/components/font-family/index.js +1 -16
- package/src/components/font-family/stories/{index.story.js → index.story.jsx} +0 -1
- package/src/components/global-styles/dimensions-panel.js +36 -0
- package/src/components/global-styles/hooks.js +1 -1
- package/src/components/global-styles/typography-panel.js +0 -1
- package/src/components/inserter/media-tab/media-tab.js +2 -44
- package/src/components/inspector-controls-tabs/content-tab.js +12 -4
- package/src/components/inspector-controls-tabs/index.js +4 -1
- package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -5
- package/src/components/link-control/index.js +36 -12
- package/src/components/list-view/block-select-button.js +15 -10
- package/src/components/list-view/block.js +9 -7
- package/src/components/media-placeholder/index.js +21 -46
- package/src/components/media-placeholder/test/get-computed-accept-attribute.js +164 -0
- package/src/components/media-placeholder/utils.js +65 -0
- package/src/components/media-replace-flow/index.js +25 -42
- package/src/components/use-block-commands/index.js +1 -1
- package/src/components/use-block-display-information/index.js +30 -2
- package/src/components/use-block-drop-zone/index.js +1 -5
- package/src/hooks/block-bindings.js +71 -82
- package/src/hooks/dimensions.js +8 -3
- package/src/hooks/metadata.js +1 -1
- package/src/hooks/test/metadata.js +1 -1
- package/src/hooks/use-content-only-section-edit.js +63 -0
- package/src/hooks/utils.js +4 -0
- package/src/layouts/constrained.js +8 -2
- package/src/private-apis.js +2 -2
- package/src/store/private-keys.js +1 -0
- package/src/store/private-selectors.js +121 -5
- package/src/store/selectors.js +6 -4
- package/src/store/test/private-selectors.js +242 -0
- package/src/style.scss +1 -1
- package/src/utils/fit-text-utils.js +19 -1
- package/tsconfig.json +1 -0
- package/build/components/media-upload-modal/index.js +0 -29
- package/build/components/media-upload-modal/index.js.map +0 -7
- package/build-module/components/media-upload-modal/index.js +0 -8
- package/build-module/components/media-upload-modal/index.js.map +0 -7
- package/src/components/font-family/style.scss +0 -7
- package/src/components/media-upload-modal/index.js +0 -18
- /package/src/components/alignment-control/stories/{aliginment-toolbar.story.js → aliginment-toolbar.story.jsx} +0 -0
- /package/src/components/alignment-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-alignment-matrix-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-draggable/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-heading-level-dropdown/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-mover/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-title/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/border-radius-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/date-format-picker/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/dimensions-tool/stories/{aspect-ratio-tool.story.js → aspect-ratio-tool.story.jsx} +0 -0
- /package/src/components/dimensions-tool/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/dimensions-tool/stories/{scale-tool.story.js → scale-tool.story.jsx} +0 -0
- /package/src/components/dimensions-tool/stories/{width-height-tool.story.js → width-height-tool.story.jsx} +0 -0
- /package/src/components/height-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/inserter/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/line-height-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/plain-text/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/resolution-tool/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/tabbed-sidebar/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/text-alignment-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/text-decoration-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/text-transform-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/unit-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/url-popover/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/warning/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/writing-mode-control/stories/{index.story.js → index.story.jsx} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/use-block-drop-zone/index.js"],
|
|
4
|
-
"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\thasBlockSupport,\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';\nimport { unlock } from '../../lock-unlock';\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\tif ( ! rect ) {\n\t\t\t\treturn;\n\t\t\t}\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 * Checks if the given element is an insertion point.\n *\n * @param {EventTarget|null} targetToCheck - The element to check.\n * @param {Document} ownerDocument - The owner document of the element.\n * @return {boolean} True if the element is a insertion point, false otherwise.\n */\nfunction isInsertionPoint( targetToCheck, ownerDocument ) {\n\tconst { defaultView } = ownerDocument;\n\n\treturn !! (\n\t\tdefaultView &&\n\t\ttargetToCheck instanceof defaultView.HTMLElement &&\n\t\ttargetToCheck.closest( '[data-is-insertion-point]' )\n\t);\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, getBlockVariations, getGroupingBlockName } =\n\t\tuseSelect( blocksStore );\n\tconst {\n\t\tcanInsertBlockType,\n\t\tgetBlockListSettings,\n\t\tgetBlocks,\n\t\tgetBlockIndex,\n\t\tgetDraggedBlockClientIds,\n\t\tgetBlockNamesByClientId,\n\t\tgetAllowedBlocks,\n\t\tisDragging,\n\t\tisGroupable,\n\t\tisZoomOut,\n\t\tgetSectionRootClientId,\n\t\tgetBlockParents,\n\t} = unlock( useSelect( blockEditorStore ) );\n\tconst {\n\t\tshowInsertionPoint,\n\t\thideInsertionPoint,\n\t\tstartDragging,\n\t\tstopDragging,\n\t} = unlock( useDispatch( 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\tif ( ! isDragging() ) {\n\t\t\t\t\t// When dragging from the desktop, no drag start event is fired.\n\t\t\t\t\t// So, ensure that the drag state is set when the user drags over a drop zone.\n\t\t\t\t\tstartDragging();\n\t\t\t\t}\n\n\t\t\t\tconst draggedBlockClientIds = getDraggedBlockClientIds();\n\t\t\t\tconst targetParents = [\n\t\t\t\t\ttargetRootClientId,\n\t\t\t\t\t...getBlockParents( targetRootClientId, true ),\n\t\t\t\t];\n\n\t\t\t\t// Check if the target is within any of the dragged blocks.\n\t\t\t\tconst isTargetWithinDraggedBlocks = draggedBlockClientIds.some(\n\t\t\t\t\t( clientId ) => targetParents.includes( clientId )\n\t\t\t\t);\n\n\t\t\t\tif ( isTargetWithinDraggedBlocks ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\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\n\t\t\t\tconst draggedBlockNames = getBlockNamesByClientId(\n\t\t\t\t\tdraggedBlockClientIds\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\n\t\t\t\tif ( ! isBlockDroppingAllowed ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst sectionRootClientId = getSectionRootClientId();\n\n\t\t\t\t// In Zoom Out mode, if the target is not the section root provided by settings then\n\t\t\t\t// do not allow dropping as the drop target is not within the root (that which is\n\t\t\t\t// treated as \"the content\" by Zoom Out Mode).\n\t\t\t\tif (\n\t\t\t\t\tisZoomOut() &&\n\t\t\t\t\tsectionRootClientId !== targetRootClientId\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst blocks = getBlocks( targetRootClientId )\n\t\t\t\t\t// Filter out blocks that are hidden\n\t\t\t\t\t.filter( ( block ) => {\n\t\t\t\t\t\treturn ! (\n\t\t\t\t\t\t\thasBlockSupport(\n\t\t\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\t\t\t'blockVisibility',\n\t\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t\t) &&\n\t\t\t\t\t\t\tblock.attributes?.metadata?.blockVisibility ===\n\t\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t);\n\t\t\t\t\t} );\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\tconst blockElement = ownerDocument.getElementById(\n\t\t\t\t\t\t\t\t`block-${ clientId }`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn blockElement\n\t\t\t\t\t\t\t\t? blockElement.getBoundingClientRect()\n\t\t\t\t\t\t\t\t: null;\n\t\t\t\t\t\t},\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 dropTargetPosition = 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\tconst [ targetIndex, operation, nearestSide ] =\n\t\t\t\t\tdropTargetPosition;\n\n\t\t\t\tconst isTargetIndexEmptyDefaultBlock =\n\t\t\t\t\tblocksData[ targetIndex ]?.isUnmodifiedDefaultBlock;\n\n\t\t\t\tif (\n\t\t\t\t\tisZoomOut() &&\n\t\t\t\t\t! isTargetIndexEmptyDefaultBlock &&\n\t\t\t\t\toperation !== 'insert'\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( operation === 'group' ) {\n\t\t\t\t\tconst targetBlock = blocks[ targetIndex ];\n\t\t\t\t\tconst areAllImages = [\n\t\t\t\t\t\ttargetBlock.name,\n\t\t\t\t\t\t...draggedBlockNames,\n\t\t\t\t\t].every( ( name ) => name === 'core/image' );\n\t\t\t\t\tconst canInsertGalleryBlock = canInsertBlockType(\n\t\t\t\t\t\t'core/gallery',\n\t\t\t\t\t\ttargetRootClientId\n\t\t\t\t\t);\n\t\t\t\t\tconst areGroupableBlocks = isGroupable( [\n\t\t\t\t\t\ttargetBlock.clientId,\n\t\t\t\t\t\tgetDraggedBlockClientIds(),\n\t\t\t\t\t] );\n\t\t\t\t\tconst groupBlockVariations = getBlockVariations(\n\t\t\t\t\t\tgetGroupingBlockName(),\n\t\t\t\t\t\t'block'\n\t\t\t\t\t);\n\t\t\t\t\tconst canInsertRow =\n\t\t\t\t\t\tgroupBlockVariations &&\n\t\t\t\t\t\tgroupBlockVariations.find(\n\t\t\t\t\t\t\t( { name } ) => name === 'group-row'\n\t\t\t\t\t\t);\n\n\t\t\t\t\t// If the dragged blocks and the target block are all images,\n\t\t\t\t\t// check if it is creatable either a Row variation or a Gallery block.\n\t\t\t\t\tif (\n\t\t\t\t\t\tareAllImages &&\n\t\t\t\t\t\t! canInsertGalleryBlock &&\n\t\t\t\t\t\t( ! areGroupableBlocks || ! canInsertRow )\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\t// If the dragged blocks and the target block are not all images,\n\t\t\t\t\t// check if it is creatable a Row variation.\n\t\t\t\t\tif (\n\t\t\t\t\t\t! areAllImages &&\n\t\t\t\t\t\t( ! areGroupableBlocks || ! canInsertRow )\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\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\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\tisDragging,\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\tgetSectionRootClientId,\n\t\t\t\tisZoomOut,\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\tstartDragging,\n\t\t\t\tshowInsertionPoint,\n\t\t\t\tcanInsertBlockType,\n\t\t\t\tisGroupable,\n\t\t\t\tgetBlockVariations,\n\t\t\t\tgetGroupingBlockName,\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( event ) {\n\t\t\tconst { ownerDocument } = event.currentTarget;\n\n\t\t\t// If the drag event is leaving the drop zone and entering an insertion point,\n\t\t\t// do not hide the insertion point as it is conceptually within the dropzone.\n\t\t\tif (\n\t\t\t\tisInsertionPoint( event.relatedTarget, ownerDocument ) ||\n\t\t\t\tisInsertionPoint( event.target, ownerDocument )\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\tstopDragging();\n\t\t\thideInsertionPoint();\n\t\t},\n\t} );\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAoD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AAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,QAAI,+BAAQ,yBAAa,aAAAA,KAAiB,CAAE;AAE5C,QAAM,kBAAc,yBAAAC;AAAA,IACnB,WAAW,cAAc,YAAY,WAAW,cAAc,UAC3D,sBACA;AAAA,IACH,WAAW;AAAA,IACX;AAAA,MACC,WAAW,WAAW;AAAA,MACtB,aAAa,WAAW;AAAA,IACzB;AAAA,EACD;AACA,QAAM,gBAAY;AAAA,QACjB;AAAA,MACC,CAAE,OAAO,kBAAmB;AAC3B,YAAK,CAAE,WAAW,GAAI;AAGrB,wBAAc;AAAA,QACf;AAEA,cAAM,wBAAwB,yBAAyB;AACvD,cAAM,gBAAgB;AAAA,UACrB;AAAA,UACA,GAAG,gBAAiB,oBAAoB,IAAK;AAAA,QAC9C;AAGA,cAAM,8BAA8B,sBAAsB;AAAA,UACzD,CAAE,aAAc,cAAc,SAAU,QAAS;AAAA,QAClD;AAEA,YAAK,6BAA8B;AAClC;AAAA,QACD;AAEA,cAAM,gBAAgB,iBAAkB,kBAAmB;AAC3D,cAAM,kBAAkB,wBAAyB;AAAA,UAChD;AAAA,QACD,CAAE,EAAG,CAAE;AAEP,cAAM,oBAAoB;AAAA,UACzB;AAAA,QACD;AACA,cAAM,yBAAyB;AAAA,UAC9B;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACD;AAEA,YAAK,CAAE,wBAAyB;AAC/B;AAAA,QACD;AAEA,cAAM,sBAAsB,uBAAuB;AAKnD,YACC,UAAU,KACV,wBAAwB,oBACvB;AACD;AAAA,QACD;AAEA,cAAM,SAAS,UAAW,kBAAmB,EAE3C,OAAQ,CAAE,UAAW;AACrB,iBAAO,MACN
|
|
4
|
+
"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\thasBlockSupport,\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';\nimport { unlock } from '../../lock-unlock';\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\tif ( ! rect ) {\n\t\t\t\treturn;\n\t\t\t}\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 * Checks if the given element is an insertion point.\n *\n * @param {EventTarget|null} targetToCheck - The element to check.\n * @param {Document} ownerDocument - The owner document of the element.\n * @return {boolean} True if the element is a insertion point, false otherwise.\n */\nfunction isInsertionPoint( targetToCheck, ownerDocument ) {\n\tconst { defaultView } = ownerDocument;\n\n\treturn !! (\n\t\tdefaultView &&\n\t\ttargetToCheck instanceof defaultView.HTMLElement &&\n\t\ttargetToCheck.closest( '[data-is-insertion-point]' )\n\t);\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, getBlockVariations, getGroupingBlockName } =\n\t\tuseSelect( blocksStore );\n\tconst {\n\t\tcanInsertBlockType,\n\t\tgetBlockListSettings,\n\t\tgetBlocks,\n\t\tgetBlockIndex,\n\t\tgetDraggedBlockClientIds,\n\t\tgetBlockNamesByClientId,\n\t\tgetAllowedBlocks,\n\t\tisDragging,\n\t\tisGroupable,\n\t\tisZoomOut,\n\t\tgetSectionRootClientId,\n\t\tgetBlockParents,\n\t} = unlock( useSelect( blockEditorStore ) );\n\tconst {\n\t\tshowInsertionPoint,\n\t\thideInsertionPoint,\n\t\tstartDragging,\n\t\tstopDragging,\n\t} = unlock( useDispatch( 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\tif ( ! isDragging() ) {\n\t\t\t\t\t// When dragging from the desktop, no drag start event is fired.\n\t\t\t\t\t// So, ensure that the drag state is set when the user drags over a drop zone.\n\t\t\t\t\tstartDragging();\n\t\t\t\t}\n\n\t\t\t\tconst draggedBlockClientIds = getDraggedBlockClientIds();\n\t\t\t\tconst targetParents = [\n\t\t\t\t\ttargetRootClientId,\n\t\t\t\t\t...getBlockParents( targetRootClientId, true ),\n\t\t\t\t];\n\n\t\t\t\t// Check if the target is within any of the dragged blocks.\n\t\t\t\tconst isTargetWithinDraggedBlocks = draggedBlockClientIds.some(\n\t\t\t\t\t( clientId ) => targetParents.includes( clientId )\n\t\t\t\t);\n\n\t\t\t\tif ( isTargetWithinDraggedBlocks ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\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\n\t\t\t\tconst draggedBlockNames = getBlockNamesByClientId(\n\t\t\t\t\tdraggedBlockClientIds\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\n\t\t\t\tif ( ! isBlockDroppingAllowed ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst sectionRootClientId = getSectionRootClientId();\n\n\t\t\t\t// In Zoom Out mode, if the target is not the section root provided by settings then\n\t\t\t\t// do not allow dropping as the drop target is not within the root (that which is\n\t\t\t\t// treated as \"the content\" by Zoom Out Mode).\n\t\t\t\tif (\n\t\t\t\t\tisZoomOut() &&\n\t\t\t\t\tsectionRootClientId !== targetRootClientId\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst blocks = getBlocks( targetRootClientId )\n\t\t\t\t\t// Filter out blocks that are hidden\n\t\t\t\t\t.filter( ( block ) => {\n\t\t\t\t\t\treturn ! (\n\t\t\t\t\t\t\thasBlockSupport( block.name, 'visibility', true ) &&\n\t\t\t\t\t\t\tblock.attributes?.metadata?.blockVisibility ===\n\t\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t);\n\t\t\t\t\t} );\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\tconst blockElement = ownerDocument.getElementById(\n\t\t\t\t\t\t\t\t`block-${ clientId }`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn blockElement\n\t\t\t\t\t\t\t\t? blockElement.getBoundingClientRect()\n\t\t\t\t\t\t\t\t: null;\n\t\t\t\t\t\t},\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 dropTargetPosition = 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\tconst [ targetIndex, operation, nearestSide ] =\n\t\t\t\t\tdropTargetPosition;\n\n\t\t\t\tconst isTargetIndexEmptyDefaultBlock =\n\t\t\t\t\tblocksData[ targetIndex ]?.isUnmodifiedDefaultBlock;\n\n\t\t\t\tif (\n\t\t\t\t\tisZoomOut() &&\n\t\t\t\t\t! isTargetIndexEmptyDefaultBlock &&\n\t\t\t\t\toperation !== 'insert'\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( operation === 'group' ) {\n\t\t\t\t\tconst targetBlock = blocks[ targetIndex ];\n\t\t\t\t\tconst areAllImages = [\n\t\t\t\t\t\ttargetBlock.name,\n\t\t\t\t\t\t...draggedBlockNames,\n\t\t\t\t\t].every( ( name ) => name === 'core/image' );\n\t\t\t\t\tconst canInsertGalleryBlock = canInsertBlockType(\n\t\t\t\t\t\t'core/gallery',\n\t\t\t\t\t\ttargetRootClientId\n\t\t\t\t\t);\n\t\t\t\t\tconst areGroupableBlocks = isGroupable( [\n\t\t\t\t\t\ttargetBlock.clientId,\n\t\t\t\t\t\tgetDraggedBlockClientIds(),\n\t\t\t\t\t] );\n\t\t\t\t\tconst groupBlockVariations = getBlockVariations(\n\t\t\t\t\t\tgetGroupingBlockName(),\n\t\t\t\t\t\t'block'\n\t\t\t\t\t);\n\t\t\t\t\tconst canInsertRow =\n\t\t\t\t\t\tgroupBlockVariations &&\n\t\t\t\t\t\tgroupBlockVariations.find(\n\t\t\t\t\t\t\t( { name } ) => name === 'group-row'\n\t\t\t\t\t\t);\n\n\t\t\t\t\t// If the dragged blocks and the target block are all images,\n\t\t\t\t\t// check if it is creatable either a Row variation or a Gallery block.\n\t\t\t\t\tif (\n\t\t\t\t\t\tareAllImages &&\n\t\t\t\t\t\t! canInsertGalleryBlock &&\n\t\t\t\t\t\t( ! areGroupableBlocks || ! canInsertRow )\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\t// If the dragged blocks and the target block are not all images,\n\t\t\t\t\t// check if it is creatable a Row variation.\n\t\t\t\t\tif (\n\t\t\t\t\t\t! areAllImages &&\n\t\t\t\t\t\t( ! areGroupableBlocks || ! canInsertRow )\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\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\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\tisDragging,\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\tgetSectionRootClientId,\n\t\t\t\tisZoomOut,\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\tstartDragging,\n\t\t\t\tshowInsertionPoint,\n\t\t\t\tcanInsertBlockType,\n\t\t\t\tisGroupable,\n\t\t\t\tgetBlockVariations,\n\t\t\t\tgetGroupingBlockName,\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( event ) {\n\t\t\tconst { ownerDocument } = event.currentTarget;\n\n\t\t\t// If the drag event is leaving the drop zone and entering an insertion point,\n\t\t\t// do not hide the insertion point as it is conceptually within the dropzone.\n\t\t\tif (\n\t\t\t\tisInsertionPoint( event.relatedTarget, ownerDocument ) ||\n\t\t\t\tisInsertionPoint( event.target, ownerDocument )\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthrottled.cancel();\n\t\t\thideInsertionPoint();\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\tstopDragging();\n\t\t\thideInsertionPoint();\n\t\t},\n\t} );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAoD;AACpD,qBAAsC;AACtC,qBAGO;AACP,kBAAsB;AACtB,oBAIO;AAKP,+BAA2B;AAC3B,kBAIO;AACP,mBAA0C;AAC1C,yBAAuB;AAEvB,IAAM,qBAAqB;AAC3B,IAAM,+BAA+B;AACrC,IAAM,8BAA8B;AAiC7B,SAAS,sBACf,YACA,UACA,cAAc,YACd,UAAU,CAAC,GACV;AACD,QAAM,eACL,gBAAgB,eACb,CAAE,QAAQ,OAAQ,IAClB,CAAE,OAAO,QAAS;AAEtB,MAAI,eAAe;AACnB,MAAI,iBAAiB;AACrB,MAAI,cAAc;AAClB,MAAI,mBAAmB;AACvB,MAAI,cAAc;AAElB,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA,iBAAiB;AAAA,EAClB,IAAI;AAGJ,MAAK,mBAAmB,2BAA2B,cAAe;AACjE,UAAM,OAAO,gBAAgB,sBAAsB;AACnD,UAAM,CAAE,UAAU,IAAK,QAAI,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,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA;AAAA,EACD;AAEA,aAAO,eAAAC,2BAAa;AAAA,IACnB;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR,WAAY,OAAQ;AAInB,gBAAW,OAAO,MAAM,cAAc,aAAc;AAAA,IACrD;AAAA,IACA,YAAa,OAAQ;AACpB,YAAM,EAAE,cAAc,IAAI,MAAM;AAIhC,UACC,iBAAkB,MAAM,eAAe,aAAc,KACrD,iBAAkB,MAAM,QAAQ,aAAc,GAC7C;AACD;AAAA,MACD;AAEA,gBAAU,OAAO;AACjB,yBAAmB;AAAA,IACpB;AAAA,IACA,YAAY;AACX,gBAAU,OAAO;AACjB,mBAAa;AACb,yBAAmB;AAAA,IACpB;AAAA,EACD,CAAE;AACH;",
|
|
6
6
|
"names": ["blocksStore", "blockEditorStore", "useOnBlockDrop", "getIsUnmodifiedDefaultBlock", "useDropZone"]
|
|
7
7
|
}
|
|
@@ -49,7 +49,6 @@ var import_block_edit = require("../components/block-edit");
|
|
|
49
49
|
var import_store = require("../store");
|
|
50
50
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
51
51
|
var { Menu } = (0, import_lock_unlock.unlock)(import_components.privateApis);
|
|
52
|
-
var EMPTY_OBJECT = {};
|
|
53
52
|
var getAttributeType = (blockName, attribute) => {
|
|
54
53
|
const _attributeType = (0, import_blocks.getBlockType)(blockName).attributes?.[attribute]?.type;
|
|
55
54
|
return _attributeType === "rich-text" ? "string" : _attributeType;
|
|
@@ -79,14 +78,15 @@ function BlockBindingsPanelMenuContent({ attribute, binding, sources }) {
|
|
|
79
78
|
},
|
|
80
79
|
[clientId, attribute]
|
|
81
80
|
);
|
|
82
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu, { placement: isMobile ? "bottom-start" : "left-start", children: Object.entries(sources).map(([sourceKey,
|
|
83
|
-
const sourceDataItems =
|
|
84
|
-
(item) => item
|
|
81
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu, { placement: isMobile ? "bottom-start" : "left-start", children: Object.entries(sources).map(([sourceKey, data]) => {
|
|
82
|
+
const sourceDataItems = data.filter(
|
|
83
|
+
(item) => item.type === attributeType
|
|
85
84
|
);
|
|
86
85
|
const noItemsAvailable = !sourceDataItems || sourceDataItems.length === 0;
|
|
87
86
|
if (noItemsAvailable) {
|
|
88
87
|
return null;
|
|
89
88
|
}
|
|
89
|
+
const source = (0, import_blocks.getBlockBindingsSource)(sourceKey);
|
|
90
90
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
91
91
|
Menu,
|
|
92
92
|
{
|
|
@@ -96,17 +96,21 @@ function BlockBindingsPanelMenuContent({ attribute, binding, sources }) {
|
|
|
96
96
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu.Popover, { gutter: 8, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu.Group, { children: sourceDataItems.map((item) => {
|
|
97
97
|
const itemBindings = {
|
|
98
98
|
source: sourceKey,
|
|
99
|
-
args: item
|
|
99
|
+
args: item.args || {
|
|
100
100
|
key: item.key
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
let values = {};
|
|
104
|
+
try {
|
|
105
|
+
values = source.getValues({
|
|
106
|
+
select,
|
|
107
|
+
context: blockContext,
|
|
108
|
+
bindings: {
|
|
109
|
+
[attribute]: itemBindings
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
} catch (e) {
|
|
113
|
+
}
|
|
110
114
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
111
115
|
Menu.CheckboxItem,
|
|
112
116
|
{
|
|
@@ -134,7 +138,7 @@ function BlockBindingsPanelMenuContent({ attribute, binding, sources }) {
|
|
|
134
138
|
) ?? // Deprecate key dependency in 7.0.
|
|
135
139
|
item.key === binding?.args?.key,
|
|
136
140
|
children: [
|
|
137
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu.ItemLabel, { children: item
|
|
141
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu.ItemLabel, { children: item.label }),
|
|
138
142
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu.ItemHelpText, { children: values[attribute] })
|
|
139
143
|
]
|
|
140
144
|
},
|
|
@@ -151,14 +155,15 @@ function BlockBindingsPanelMenuContent({ attribute, binding, sources }) {
|
|
|
151
155
|
}
|
|
152
156
|
function BlockBindingsAttribute({ attribute, binding, sources, blockName }) {
|
|
153
157
|
const { source: sourceName, args } = binding || {};
|
|
154
|
-
const
|
|
158
|
+
const data = sources?.[sourceName];
|
|
159
|
+
const source = (0, import_blocks.getBlockBindingsSource)(sourceName);
|
|
155
160
|
let displayText;
|
|
156
161
|
let isValid = true;
|
|
157
162
|
const isNotBound = binding === void 0;
|
|
158
163
|
if (isNotBound) {
|
|
159
164
|
const attributeType = getAttributeType(blockName, attribute);
|
|
160
165
|
const hasCompatibleSources = Object.values(sources).some(
|
|
161
|
-
(
|
|
166
|
+
(items) => items.some((item) => item.type === attributeType)
|
|
162
167
|
);
|
|
163
168
|
if (!hasCompatibleSources) {
|
|
164
169
|
displayText = (0, import_i18n.__)("No sources available");
|
|
@@ -169,11 +174,8 @@ function BlockBindingsAttribute({ attribute, binding, sources, blockName }) {
|
|
|
169
174
|
} else if (!source) {
|
|
170
175
|
isValid = false;
|
|
171
176
|
displayText = (0, import_i18n.__)("Source not registered");
|
|
172
|
-
if (Object.keys(sources).length === 0) {
|
|
173
|
-
displayText = (0, import_i18n.__)("No sources available");
|
|
174
|
-
}
|
|
175
177
|
} else {
|
|
176
|
-
displayText =
|
|
178
|
+
displayText = data?.find((item) => (0, import_es6.default)(item.args, args))?.label || source?.label || sourceName;
|
|
177
179
|
}
|
|
178
180
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { className: "block-editor-bindings__item", spacing: 0, children: [
|
|
179
181
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalText, { truncate: true, children: attribute }),
|
|
@@ -249,60 +251,51 @@ var BlockBindingsPanel = ({ name: blockName, metadata }) => {
|
|
|
249
251
|
const blockContext = (0, import_element.useContext)(import_block_context.default);
|
|
250
252
|
const { removeAllBlockBindings } = (0, import_block_bindings.useBlockBindingsUtils)();
|
|
251
253
|
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
|
|
252
|
-
const
|
|
253
|
-
const { sources, canUpdateBlockBindings, bindableAttributes } = (0, import_data.useSelect)(
|
|
254
|
+
const { canUpdateBlockBindings, bindableAttributes } = (0, import_data.useSelect)(
|
|
254
255
|
(select) => {
|
|
255
256
|
const { __experimentalBlockBindingsSupportedAttributes } = select(import_store.store).getSettings();
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
257
|
+
return {
|
|
258
|
+
canUpdateBlockBindings: select(import_store.store).getSettings().canUpdateBlockBindings,
|
|
259
|
+
bindableAttributes: __experimentalBlockBindingsSupportedAttributes?.[blockName]
|
|
260
|
+
};
|
|
261
|
+
},
|
|
262
|
+
[blockName]
|
|
263
|
+
);
|
|
264
|
+
const sources = (0, import_data.useSelect)(
|
|
265
|
+
(select) => {
|
|
266
|
+
const { getAllBlockBindingsSources } = (0, import_lock_unlock.unlock)(
|
|
267
|
+
select(import_blocks.store)
|
|
268
|
+
);
|
|
269
|
+
const data = {};
|
|
270
|
+
Object.entries(getAllBlockBindingsSources()).forEach(
|
|
271
|
+
([sourceName, source]) => {
|
|
272
|
+
if (!source.getFieldsList) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
266
275
|
const context = {};
|
|
267
|
-
if (usesContext?.length) {
|
|
268
|
-
for (const key of usesContext) {
|
|
276
|
+
if (source.usesContext?.length) {
|
|
277
|
+
for (const key of source.usesContext) {
|
|
269
278
|
context[key] = blockContext[key];
|
|
270
279
|
}
|
|
271
280
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
data: fieldsListResult || [],
|
|
279
|
-
label,
|
|
280
|
-
getValues
|
|
281
|
-
};
|
|
282
|
-
} else {
|
|
283
|
-
_sources[sourceName] = {
|
|
284
|
-
data: [],
|
|
285
|
-
label,
|
|
286
|
-
getValues
|
|
287
|
-
};
|
|
281
|
+
const items = source.getFieldsList({
|
|
282
|
+
select,
|
|
283
|
+
context
|
|
284
|
+
});
|
|
285
|
+
if (items?.length) {
|
|
286
|
+
data[sourceName] = items;
|
|
288
287
|
}
|
|
289
288
|
}
|
|
290
289
|
);
|
|
291
|
-
return
|
|
292
|
-
sources: Object.values(_sources).length > 0 ? _sources : EMPTY_OBJECT,
|
|
293
|
-
canUpdateBlockBindings: select(import_store.store).getSettings().canUpdateBlockBindings,
|
|
294
|
-
bindableAttributes: _bindableAttributes
|
|
295
|
-
};
|
|
290
|
+
return data;
|
|
296
291
|
},
|
|
297
|
-
[blockContext
|
|
292
|
+
[blockContext]
|
|
298
293
|
);
|
|
299
294
|
if (!bindableAttributes || bindableAttributes.length === 0) {
|
|
300
295
|
return null;
|
|
301
296
|
}
|
|
302
297
|
const { bindings } = metadata || {};
|
|
303
|
-
const hasCompatibleData = Object.
|
|
304
|
-
(source) => source.data && source.data.length > 0
|
|
305
|
-
);
|
|
298
|
+
const hasCompatibleData = Object.keys(sources).length > 0;
|
|
306
299
|
const readOnly = !canUpdateBlockBindings || !hasCompatibleData;
|
|
307
300
|
if (bindings === void 0 && !hasCompatibleData) {
|
|
308
301
|
return null;
|
|
@@ -326,9 +319,7 @@ var BlockBindingsPanel = ({ name: blockName, metadata }) => {
|
|
|
326
319
|
const hasCompatibleDataForAttribute = Object.values(
|
|
327
320
|
sources
|
|
328
321
|
).some(
|
|
329
|
-
(
|
|
330
|
-
(item) => item?.type === attributeType
|
|
331
|
-
)
|
|
322
|
+
(data) => data.some((item) => item.type === attributeType)
|
|
332
323
|
);
|
|
333
324
|
const isAttributeReadOnly = readOnly || !hasCompatibleDataForAttribute;
|
|
334
325
|
return isAttributeReadOnly ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/block-bindings.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { getBlockBindingsSources, getBlockType } from '@wordpress/blocks';\nimport {\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalItem as Item,\n\t__experimentalText as Text,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalVStack as VStack,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { useContext } from '@wordpress/element';\nimport { useViewportMatch } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { useBlockBindingsUtils } from '../utils/block-bindings';\nimport { unlock } from '../lock-unlock';\nimport InspectorControls from '../components/inspector-controls';\nimport BlockContext from '../components/block-context';\nimport { useBlockEditContext } from '../components/block-edit';\nimport { store as blockEditorStore } from '../store';\n\nconst { Menu } = unlock( componentsPrivateApis );\n\nconst EMPTY_OBJECT = {};\n\n/**\n * Get the normalized attribute type for block bindings.\n * Converts 'rich-text' to 'string' since rich-text is stored as string.\n *\n * @param {string} blockName The block name.\n * @param {string} attribute The attribute name.\n * @return {string} The normalized attribute type.\n */\nconst getAttributeType = ( blockName, attribute ) => {\n\tconst _attributeType =\n\t\tgetBlockType( blockName ).attributes?.[ attribute ]?.type;\n\treturn _attributeType === 'rich-text' ? 'string' : _attributeType;\n};\n\nconst useToolsPanelDropdownMenuProps = () => {\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\treturn ! isMobile\n\t\t? {\n\t\t\t\tpopoverProps: {\n\t\t\t\t\tplacement: 'left-start',\n\t\t\t\t\t// For non-mobile, inner sidebar width (248px) - button width (24px) - border (1px) + padding (16px) + spacing (20px)\n\t\t\t\t\toffset: 259,\n\t\t\t\t},\n\t\t }\n\t\t: {};\n};\n\nfunction BlockBindingsPanelMenuContent( { attribute, binding, sources } ) {\n\tconst { clientId } = useBlockEditContext();\n\tconst { updateBlockBindings } = useBlockBindingsUtils();\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\tconst blockContext = useContext( BlockContext );\n\tconst { attributeType, select } = useSelect(\n\t\t( _select ) => {\n\t\t\tconst { name: blockName } =\n\t\t\t\t_select( blockEditorStore ).getBlock( clientId );\n\t\t\treturn {\n\t\t\t\tattributeType: getAttributeType( blockName, attribute ),\n\t\t\t\tselect: _select,\n\t\t\t};\n\t\t},\n\t\t[ clientId, attribute ]\n\t);\n\treturn (\n\t\t<Menu placement={ isMobile ? 'bottom-start' : 'left-start' }>\n\t\t\t{ Object.entries( sources ).map( ( [ sourceKey, source ] ) => {\n\t\t\t\t// Only show sources that have compatible data for this specific attribute.\n\t\t\t\tconst sourceDataItems = source.data?.filter(\n\t\t\t\t\t( item ) => item?.type === attributeType\n\t\t\t\t);\n\n\t\t\t\tconst noItemsAvailable =\n\t\t\t\t\t! sourceDataItems || sourceDataItems.length === 0;\n\n\t\t\t\tif ( noItemsAvailable ) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\treturn (\n\t\t\t\t\t<Menu\n\t\t\t\t\t\tkey={ sourceKey }\n\t\t\t\t\t\tplacement={ isMobile ? 'bottom-start' : 'left-start' }\n\t\t\t\t\t>\n\t\t\t\t\t\t<Menu.SubmenuTriggerItem>\n\t\t\t\t\t\t\t<Menu.ItemLabel>{ source.label }</Menu.ItemLabel>\n\t\t\t\t\t\t</Menu.SubmenuTriggerItem>\n\t\t\t\t\t\t<Menu.Popover gutter={ 8 }>\n\t\t\t\t\t\t\t<Menu.Group>\n\t\t\t\t\t\t\t\t{ sourceDataItems.map( ( item ) => {\n\t\t\t\t\t\t\t\t\tconst itemBindings = {\n\t\t\t\t\t\t\t\t\t\tsource: sourceKey,\n\t\t\t\t\t\t\t\t\t\targs: item?.args || {\n\t\t\t\t\t\t\t\t\t\t\tkey: item.key,\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\tconst values = source.getValues( {\n\t\t\t\t\t\t\t\t\t\tselect,\n\t\t\t\t\t\t\t\t\t\tcontext: blockContext,\n\t\t\t\t\t\t\t\t\t\tbindings: {\n\t\t\t\t\t\t\t\t\t\t\t[ attribute ]: itemBindings,\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\treturn (\n\t\t\t\t\t\t\t\t\t\t<Menu.CheckboxItem\n\t\t\t\t\t\t\t\t\t\t\tkey={\n\t\t\t\t\t\t\t\t\t\t\t\tsourceKey +\n\t\t\t\t\t\t\t\t\t\t\t\t\tJSON.stringify(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\titem.args\n\t\t\t\t\t\t\t\t\t\t\t\t\t) || item.key\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\tconst isCurrentlySelected =\n\t\t\t\t\t\t\t\t\t\t\t\t\tfastDeepEqual(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tbinding?.args,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\titem.args\n\t\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\t// Deprecate key dependency in 7.0.\n\t\t\t\t\t\t\t\t\t\t\t\t\titem.key ===\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tbinding?.args?.key;\n\n\t\t\t\t\t\t\t\t\t\t\t\tif ( isCurrentlySelected ) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t// Unset if the same item is selected again.\n\t\t\t\t\t\t\t\t\t\t\t\t\tupdateBlockBindings( {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t[ attribute ]:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tundefined,\n\t\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} else {\n\t\t\t\t\t\t\t\t\t\t\t\t\tupdateBlockBindings( {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t[ attribute ]:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\titemBindings,\n\t\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}\n\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t\tname={ attribute + '-binding' }\n\t\t\t\t\t\t\t\t\t\t\tvalue={ values[ attribute ] }\n\t\t\t\t\t\t\t\t\t\t\tchecked={\n\t\t\t\t\t\t\t\t\t\t\t\tfastDeepEqual(\n\t\t\t\t\t\t\t\t\t\t\t\t\tbinding?.args,\n\t\t\t\t\t\t\t\t\t\t\t\t\titem.args\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// Deprecate key dependency in 7.0.\n\t\t\t\t\t\t\t\t\t\t\t\titem.key === binding?.args?.key\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\t\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t\t{ item?.label }\n\t\t\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t<Menu.ItemHelpText>\n\t\t\t\t\t\t\t\t\t\t\t\t{ values[ attribute ] }\n\t\t\t\t\t\t\t\t\t\t\t</Menu.ItemHelpText>\n\t\t\t\t\t\t\t\t\t\t</Menu.CheckboxItem>\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</Menu.Group>\n\t\t\t\t\t\t</Menu.Popover>\n\t\t\t\t\t</Menu>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</Menu>\n\t);\n}\n\nfunction BlockBindingsAttribute( { attribute, binding, sources, blockName } ) {\n\tconst { source: sourceName, args } = binding || {};\n\tconst source = sources?.[ sourceName ];\n\n\tlet displayText;\n\tlet isValid = true;\n\tconst isNotBound = binding === undefined;\n\n\tif ( isNotBound ) {\n\t\t// Check if there are any compatible sources for this attribute type.\n\t\tconst attributeType = getAttributeType( blockName, attribute );\n\n\t\tconst hasCompatibleSources = Object.values( sources ).some( ( src ) =>\n\t\t\tsrc.data?.some( ( item ) => item?.type === attributeType )\n\t\t);\n\n\t\tif ( ! hasCompatibleSources ) {\n\t\t\tdisplayText = __( 'No sources available' );\n\t\t} else {\n\t\t\tdisplayText = __( 'Not connected' );\n\t\t}\n\t\tisValid = true;\n\t} else if ( ! source ) {\n\t\t// If there's a binding but the source is not found, it's invalid.\n\t\tisValid = false;\n\t\tdisplayText = __( 'Source not registered' );\n\t\tif ( Object.keys( sources ).length === 0 ) {\n\t\t\tdisplayText = __( 'No sources available' );\n\t\t}\n\t} else {\n\t\tdisplayText =\n\t\t\tsource.data?.find( ( item ) => fastDeepEqual( item.args, args ) )\n\t\t\t\t?.label ||\n\t\t\tsource.label ||\n\t\t\tsourceName;\n\t}\n\n\treturn (\n\t\t<VStack className=\"block-editor-bindings__item\" spacing={ 0 }>\n\t\t\t<Text truncate>{ attribute }</Text>\n\t\t\t<Text\n\t\t\t\ttruncate\n\t\t\t\tvariant={ isValid ? 'muted' : undefined }\n\t\t\t\tisDestructive={ ! isValid }\n\t\t\t>\n\t\t\t\t{ displayText }\n\t\t\t</Text>\n\t\t</VStack>\n\t);\n}\n\nfunction ReadOnlyBlockBindingsPanelItem( {\n\tattribute,\n\tbinding,\n\tsources,\n\tblockName,\n} ) {\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\n\treturn (\n\t\t<ToolsPanelItem hasValue={ () => !! binding } label={ attribute }>\n\t\t\t<Menu placement={ isMobile ? 'bottom-start' : 'left-start' }>\n\t\t\t\t<Menu.TriggerButton render={ <Item /> } disabled>\n\t\t\t\t\t<BlockBindingsAttribute\n\t\t\t\t\t\tattribute={ attribute }\n\t\t\t\t\t\tbinding={ binding }\n\t\t\t\t\t\tsources={ sources }\n\t\t\t\t\t\tblockName={ blockName }\n\t\t\t\t\t/>\n\t\t\t\t</Menu.TriggerButton>\n\t\t\t</Menu>\n\t\t</ToolsPanelItem>\n\t);\n}\n\nfunction EditableBlockBindingsPanelItem( {\n\tattribute,\n\tbinding,\n\tsources,\n\tblockName,\n} ) {\n\tconst { updateBlockBindings } = useBlockBindingsUtils();\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\n\treturn (\n\t\t<ToolsPanelItem\n\t\t\thasValue={ () => !! binding }\n\t\t\tlabel={ attribute }\n\t\t\tonDeselect={ () => {\n\t\t\t\tupdateBlockBindings( {\n\t\t\t\t\t[ attribute ]: undefined,\n\t\t\t\t} );\n\t\t\t} }\n\t\t>\n\t\t\t<Menu placement={ isMobile ? 'bottom-start' : 'left-start' }>\n\t\t\t\t<Menu.TriggerButton render={ <Item /> }>\n\t\t\t\t\t<BlockBindingsAttribute\n\t\t\t\t\t\tattribute={ attribute }\n\t\t\t\t\t\tbinding={ binding }\n\t\t\t\t\t\tsources={ sources }\n\t\t\t\t\t\tblockName={ blockName }\n\t\t\t\t\t/>\n\t\t\t\t</Menu.TriggerButton>\n\t\t\t\t<Menu.Popover gutter={ isMobile ? 8 : 36 }>\n\t\t\t\t\t<BlockBindingsPanelMenuContent\n\t\t\t\t\t\tattribute={ attribute }\n\t\t\t\t\t\tbinding={ binding }\n\t\t\t\t\t\tsources={ sources }\n\t\t\t\t\t/>\n\t\t\t\t</Menu.Popover>\n\t\t\t</Menu>\n\t\t</ToolsPanelItem>\n\t);\n}\n\nexport const BlockBindingsPanel = ( { name: blockName, metadata } ) => {\n\tconst blockContext = useContext( BlockContext );\n\tconst { removeAllBlockBindings } = useBlockBindingsUtils();\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\t// Use useSelect to ensure sources are updated whenever there are updates in block context\n\t// or when underlying data changes.\n\t// Still needs a fix regarding _sources scope.\n\tconst _sources = {};\n\tconst { sources, canUpdateBlockBindings, bindableAttributes } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { __experimentalBlockBindingsSupportedAttributes } =\n\t\t\t\tselect( blockEditorStore ).getSettings();\n\t\t\tconst _bindableAttributes =\n\t\t\t\t__experimentalBlockBindingsSupportedAttributes?.[ blockName ];\n\t\t\tif ( ! _bindableAttributes || _bindableAttributes.length === 0 ) {\n\t\t\t\treturn EMPTY_OBJECT;\n\t\t\t}\n\n\t\t\tconst registeredSources = getBlockBindingsSources();\n\t\t\tObject.entries( registeredSources ).forEach(\n\t\t\t\t( [\n\t\t\t\t\tsourceName,\n\t\t\t\t\t{ getFieldsList, usesContext, label, getValues },\n\t\t\t\t] ) => {\n\t\t\t\t\t// Populate context.\n\t\t\t\t\tconst context = {};\n\t\t\t\t\tif ( usesContext?.length ) {\n\t\t\t\t\t\tfor ( const key of usesContext ) {\n\t\t\t\t\t\t\tcontext[ key ] = blockContext[ key ];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif ( getFieldsList ) {\n\t\t\t\t\t\tconst fieldsListResult = getFieldsList( {\n\t\t\t\t\t\t\tselect,\n\t\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t} );\n\t\t\t\t\t\t_sources[ sourceName ] = {\n\t\t\t\t\t\t\tdata: fieldsListResult || [],\n\t\t\t\t\t\t\tlabel,\n\t\t\t\t\t\t\tgetValues,\n\t\t\t\t\t\t};\n\t\t\t\t\t} else {\n\t\t\t\t\t\t/*\n\t\t\t\t\t\t * Include sources without getFieldsList if they are already used in a binding.\n\t\t\t\t\t\t * This allows them to be displayed in read-only mode.\n\t\t\t\t\t\t */\n\t\t\t\t\t\t_sources[ sourceName ] = {\n\t\t\t\t\t\t\tdata: [],\n\t\t\t\t\t\t\tlabel,\n\t\t\t\t\t\t\tgetValues,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tsources:\n\t\t\t\t\tObject.values( _sources ).length > 0\n\t\t\t\t\t\t? _sources\n\t\t\t\t\t\t: EMPTY_OBJECT,\n\t\t\t\tcanUpdateBlockBindings:\n\t\t\t\t\tselect( blockEditorStore ).getSettings()\n\t\t\t\t\t\t.canUpdateBlockBindings,\n\t\t\t\tbindableAttributes: _bindableAttributes,\n\t\t\t};\n\t\t},\n\t\t[ blockContext, blockName ]\n\t);\n\t// Return early if there are no bindable attributes.\n\tif ( ! bindableAttributes || bindableAttributes.length === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst { bindings } = metadata || {};\n\n\t// Check if all sources have empty data arrays.\n\tconst hasCompatibleData = Object.values( sources ).some(\n\t\t( source ) => source.data && source.data.length > 0\n\t);\n\n\t// Lock the UI when the user can't update bindings or there are no fields to connect to.\n\tconst readOnly = ! canUpdateBlockBindings || ! hasCompatibleData;\n\n\tif ( bindings === undefined && ! hasCompatibleData ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<InspectorControls group=\"bindings\">\n\t\t\t<ToolsPanel\n\t\t\t\tlabel={ __( 'Attributes' ) }\n\t\t\t\tresetAll={ () => {\n\t\t\t\t\tremoveAllBlockBindings();\n\t\t\t\t} }\n\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\tclassName=\"block-editor-bindings__panel\"\n\t\t\t>\n\t\t\t\t<ItemGroup isBordered isSeparated>\n\t\t\t\t\t{ bindableAttributes.map( ( attribute ) => {\n\t\t\t\t\t\tconst binding = bindings?.[ attribute ];\n\n\t\t\t\t\t\t// Check if this specific attribute has compatible data from any source.\n\t\t\t\t\t\tconst attributeType = getAttributeType(\n\t\t\t\t\t\t\tblockName,\n\t\t\t\t\t\t\tattribute\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst hasCompatibleDataForAttribute = Object.values(\n\t\t\t\t\t\t\tsources\n\t\t\t\t\t\t).some( ( source ) =>\n\t\t\t\t\t\t\tsource.data?.some(\n\t\t\t\t\t\t\t\t( item ) => item?.type === attributeType\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst isAttributeReadOnly =\n\t\t\t\t\t\t\treadOnly || ! hasCompatibleDataForAttribute;\n\n\t\t\t\t\t\treturn isAttributeReadOnly ? (\n\t\t\t\t\t\t\t<ReadOnlyBlockBindingsPanelItem\n\t\t\t\t\t\t\t\tkey={ attribute }\n\t\t\t\t\t\t\t\tattribute={ attribute }\n\t\t\t\t\t\t\t\tbinding={ binding }\n\t\t\t\t\t\t\t\tsources={ sources }\n\t\t\t\t\t\t\t\tblockName={ blockName }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<EditableBlockBindingsPanelItem\n\t\t\t\t\t\t\t\tkey={ attribute }\n\t\t\t\t\t\t\t\tattribute={ attribute }\n\t\t\t\t\t\t\t\tbinding={ binding }\n\t\t\t\t\t\t\t\tsources={ sources }\n\t\t\t\t\t\t\t\tblockName={ blockName }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t);\n\t\t\t\t\t} ) }\n\t\t\t\t</ItemGroup>\n\t\t\t\t{ /*\n\t\t\t\t\tUse a div element to make the ToolsPanelHiddenInnerWrapper\n\t\t\t\t\ttoggle the visibility of this help text automatically.\n\t\t\t\t*/ }\n\t\t\t\t<Text as=\"div\" variant=\"muted\">\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Attributes connected to custom fields or other dynamic data.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t</Text>\n\t\t\t</ToolsPanel>\n\t\t</InspectorControls>\n\t);\n};\n\nexport default {\n\tedit: BlockBindingsPanel,\n\tattributeKeys: [ 'metadata' ],\n\thasSupport( name ) {\n\t\treturn ! [\n\t\t\t'core/post-date',\n\t\t\t'core/navigation-link',\n\t\t\t'core/navigation-submenu',\n\t\t].includes( name );\n\t},\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA0B;AAK1B,kBAAmB;AACnB,
|
|
6
|
-
"names": ["componentsPrivateApis", "BlockContext", "blockEditorStore", "fastDeepEqual", "VStack", "Text", "ToolsPanelItem", "Item", "InspectorControls", "ToolsPanel", "ItemGroup"]
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tgetBlockBindingsSource,\n\tgetBlockType,\n\tstore as blockStore,\n} from '@wordpress/blocks';\nimport {\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalItem as Item,\n\t__experimentalText as Text,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalVStack as VStack,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { useContext } from '@wordpress/element';\nimport { useViewportMatch } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { useBlockBindingsUtils } from '../utils/block-bindings';\nimport { unlock } from '../lock-unlock';\nimport InspectorControls from '../components/inspector-controls';\nimport BlockContext from '../components/block-context';\nimport { useBlockEditContext } from '../components/block-edit';\nimport { store as blockEditorStore } from '../store';\n\nconst { Menu } = unlock( componentsPrivateApis );\n\n/**\n * Get the normalized attribute type for block bindings.\n * Converts 'rich-text' to 'string' since rich-text is stored as string.\n *\n * @param {string} blockName The block name.\n * @param {string} attribute The attribute name.\n * @return {string} The normalized attribute type.\n */\nconst getAttributeType = ( blockName, attribute ) => {\n\tconst _attributeType =\n\t\tgetBlockType( blockName ).attributes?.[ attribute ]?.type;\n\treturn _attributeType === 'rich-text' ? 'string' : _attributeType;\n};\n\nconst useToolsPanelDropdownMenuProps = () => {\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\treturn ! isMobile\n\t\t? {\n\t\t\t\tpopoverProps: {\n\t\t\t\t\tplacement: 'left-start',\n\t\t\t\t\t// For non-mobile, inner sidebar width (248px) - button width (24px) - border (1px) + padding (16px) + spacing (20px)\n\t\t\t\t\toffset: 259,\n\t\t\t\t},\n\t\t }\n\t\t: {};\n};\n\nfunction BlockBindingsPanelMenuContent( { attribute, binding, sources } ) {\n\tconst { clientId } = useBlockEditContext();\n\tconst { updateBlockBindings } = useBlockBindingsUtils();\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\tconst blockContext = useContext( BlockContext );\n\tconst { attributeType, select } = useSelect(\n\t\t( _select ) => {\n\t\t\tconst { name: blockName } =\n\t\t\t\t_select( blockEditorStore ).getBlock( clientId );\n\t\t\treturn {\n\t\t\t\tattributeType: getAttributeType( blockName, attribute ),\n\t\t\t\tselect: _select,\n\t\t\t};\n\t\t},\n\t\t[ clientId, attribute ]\n\t);\n\treturn (\n\t\t<Menu placement={ isMobile ? 'bottom-start' : 'left-start' }>\n\t\t\t{ Object.entries( sources ).map( ( [ sourceKey, data ] ) => {\n\t\t\t\t// Only show sources that have compatible data for this specific attribute.\n\t\t\t\tconst sourceDataItems = data.filter(\n\t\t\t\t\t( item ) => item.type === attributeType\n\t\t\t\t);\n\n\t\t\t\tconst noItemsAvailable =\n\t\t\t\t\t! sourceDataItems || sourceDataItems.length === 0;\n\n\t\t\t\tif ( noItemsAvailable ) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tconst source = getBlockBindingsSource( sourceKey );\n\n\t\t\t\treturn (\n\t\t\t\t\t<Menu\n\t\t\t\t\t\tkey={ sourceKey }\n\t\t\t\t\t\tplacement={ isMobile ? 'bottom-start' : 'left-start' }\n\t\t\t\t\t>\n\t\t\t\t\t\t<Menu.SubmenuTriggerItem>\n\t\t\t\t\t\t\t<Menu.ItemLabel>{ source.label }</Menu.ItemLabel>\n\t\t\t\t\t\t</Menu.SubmenuTriggerItem>\n\t\t\t\t\t\t<Menu.Popover gutter={ 8 }>\n\t\t\t\t\t\t\t<Menu.Group>\n\t\t\t\t\t\t\t\t{ sourceDataItems.map( ( item ) => {\n\t\t\t\t\t\t\t\t\tconst itemBindings = {\n\t\t\t\t\t\t\t\t\t\tsource: sourceKey,\n\t\t\t\t\t\t\t\t\t\targs: item.args || {\n\t\t\t\t\t\t\t\t\t\t\tkey: item.key,\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\tlet values = {};\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tvalues = source.getValues( {\n\t\t\t\t\t\t\t\t\t\t\tselect,\n\t\t\t\t\t\t\t\t\t\t\tcontext: blockContext,\n\t\t\t\t\t\t\t\t\t\t\tbindings: {\n\t\t\t\t\t\t\t\t\t\t\t\t[ attribute ]: itemBindings,\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} catch ( e ) {}\n\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<Menu.CheckboxItem\n\t\t\t\t\t\t\t\t\t\t\tkey={\n\t\t\t\t\t\t\t\t\t\t\t\tsourceKey +\n\t\t\t\t\t\t\t\t\t\t\t\t\tJSON.stringify(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\titem.args\n\t\t\t\t\t\t\t\t\t\t\t\t\t) || item.key\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\tconst isCurrentlySelected =\n\t\t\t\t\t\t\t\t\t\t\t\t\tfastDeepEqual(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tbinding?.args,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\titem.args\n\t\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\t// Deprecate key dependency in 7.0.\n\t\t\t\t\t\t\t\t\t\t\t\t\titem.key ===\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tbinding?.args?.key;\n\n\t\t\t\t\t\t\t\t\t\t\t\tif ( isCurrentlySelected ) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t// Unset if the same item is selected again.\n\t\t\t\t\t\t\t\t\t\t\t\t\tupdateBlockBindings( {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t[ attribute ]:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tundefined,\n\t\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} else {\n\t\t\t\t\t\t\t\t\t\t\t\t\tupdateBlockBindings( {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t[ attribute ]:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\titemBindings,\n\t\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}\n\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t\tname={ attribute + '-binding' }\n\t\t\t\t\t\t\t\t\t\t\tvalue={ values[ attribute ] }\n\t\t\t\t\t\t\t\t\t\t\tchecked={\n\t\t\t\t\t\t\t\t\t\t\t\tfastDeepEqual(\n\t\t\t\t\t\t\t\t\t\t\t\t\tbinding?.args,\n\t\t\t\t\t\t\t\t\t\t\t\t\titem.args\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// Deprecate key dependency in 7.0.\n\t\t\t\t\t\t\t\t\t\t\t\titem.key === binding?.args?.key\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\t\t<Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t\t\t\t\t</Menu.ItemLabel>\n\t\t\t\t\t\t\t\t\t\t\t<Menu.ItemHelpText>\n\t\t\t\t\t\t\t\t\t\t\t\t{ values[ attribute ] }\n\t\t\t\t\t\t\t\t\t\t\t</Menu.ItemHelpText>\n\t\t\t\t\t\t\t\t\t\t</Menu.CheckboxItem>\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</Menu.Group>\n\t\t\t\t\t\t</Menu.Popover>\n\t\t\t\t\t</Menu>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</Menu>\n\t);\n}\n\nfunction BlockBindingsAttribute( { attribute, binding, sources, blockName } ) {\n\tconst { source: sourceName, args } = binding || {};\n\tconst data = sources?.[ sourceName ];\n\tconst source = getBlockBindingsSource( sourceName );\n\n\tlet displayText;\n\tlet isValid = true;\n\tconst isNotBound = binding === undefined;\n\n\tif ( isNotBound ) {\n\t\t// Check if there are any compatible sources for this attribute type.\n\t\tconst attributeType = getAttributeType( blockName, attribute );\n\n\t\tconst hasCompatibleSources = Object.values( sources ).some( ( items ) =>\n\t\t\titems.some( ( item ) => item.type === attributeType )\n\t\t);\n\n\t\tif ( ! hasCompatibleSources ) {\n\t\t\tdisplayText = __( 'No sources available' );\n\t\t} else {\n\t\t\tdisplayText = __( 'Not connected' );\n\t\t}\n\t\tisValid = true;\n\t} else if ( ! source ) {\n\t\t// If there's a binding but the source is not found, it's invalid.\n\t\tisValid = false;\n\t\tdisplayText = __( 'Source not registered' );\n\t} else {\n\t\tdisplayText =\n\t\t\tdata?.find( ( item ) => fastDeepEqual( item.args, args ) )?.label ||\n\t\t\tsource?.label ||\n\t\t\tsourceName;\n\t}\n\n\treturn (\n\t\t<VStack className=\"block-editor-bindings__item\" spacing={ 0 }>\n\t\t\t<Text truncate>{ attribute }</Text>\n\t\t\t<Text\n\t\t\t\ttruncate\n\t\t\t\tvariant={ isValid ? 'muted' : undefined }\n\t\t\t\tisDestructive={ ! isValid }\n\t\t\t>\n\t\t\t\t{ displayText }\n\t\t\t</Text>\n\t\t</VStack>\n\t);\n}\n\nfunction ReadOnlyBlockBindingsPanelItem( {\n\tattribute,\n\tbinding,\n\tsources,\n\tblockName,\n} ) {\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\n\treturn (\n\t\t<ToolsPanelItem hasValue={ () => !! binding } label={ attribute }>\n\t\t\t<Menu placement={ isMobile ? 'bottom-start' : 'left-start' }>\n\t\t\t\t<Menu.TriggerButton render={ <Item /> } disabled>\n\t\t\t\t\t<BlockBindingsAttribute\n\t\t\t\t\t\tattribute={ attribute }\n\t\t\t\t\t\tbinding={ binding }\n\t\t\t\t\t\tsources={ sources }\n\t\t\t\t\t\tblockName={ blockName }\n\t\t\t\t\t/>\n\t\t\t\t</Menu.TriggerButton>\n\t\t\t</Menu>\n\t\t</ToolsPanelItem>\n\t);\n}\n\nfunction EditableBlockBindingsPanelItem( {\n\tattribute,\n\tbinding,\n\tsources,\n\tblockName,\n} ) {\n\tconst { updateBlockBindings } = useBlockBindingsUtils();\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\n\treturn (\n\t\t<ToolsPanelItem\n\t\t\thasValue={ () => !! binding }\n\t\t\tlabel={ attribute }\n\t\t\tonDeselect={ () => {\n\t\t\t\tupdateBlockBindings( {\n\t\t\t\t\t[ attribute ]: undefined,\n\t\t\t\t} );\n\t\t\t} }\n\t\t>\n\t\t\t<Menu placement={ isMobile ? 'bottom-start' : 'left-start' }>\n\t\t\t\t<Menu.TriggerButton render={ <Item /> }>\n\t\t\t\t\t<BlockBindingsAttribute\n\t\t\t\t\t\tattribute={ attribute }\n\t\t\t\t\t\tbinding={ binding }\n\t\t\t\t\t\tsources={ sources }\n\t\t\t\t\t\tblockName={ blockName }\n\t\t\t\t\t/>\n\t\t\t\t</Menu.TriggerButton>\n\t\t\t\t<Menu.Popover gutter={ isMobile ? 8 : 36 }>\n\t\t\t\t\t<BlockBindingsPanelMenuContent\n\t\t\t\t\t\tattribute={ attribute }\n\t\t\t\t\t\tbinding={ binding }\n\t\t\t\t\t\tsources={ sources }\n\t\t\t\t\t/>\n\t\t\t\t</Menu.Popover>\n\t\t\t</Menu>\n\t\t</ToolsPanelItem>\n\t);\n}\n\nexport const BlockBindingsPanel = ( { name: blockName, metadata } ) => {\n\tconst blockContext = useContext( BlockContext );\n\tconst { removeAllBlockBindings } = useBlockBindingsUtils();\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\t// Use useSelect to ensure sources are updated whenever there are updates in block context\n\t// or when underlying data changes.\n\tconst { canUpdateBlockBindings, bindableAttributes } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { __experimentalBlockBindingsSupportedAttributes } =\n\t\t\t\tselect( blockEditorStore ).getSettings();\n\n\t\t\treturn {\n\t\t\t\tcanUpdateBlockBindings:\n\t\t\t\t\tselect( blockEditorStore ).getSettings()\n\t\t\t\t\t\t.canUpdateBlockBindings,\n\t\t\t\tbindableAttributes:\n\t\t\t\t\t__experimentalBlockBindingsSupportedAttributes?.[\n\t\t\t\t\t\tblockName\n\t\t\t\t\t],\n\t\t\t};\n\t\t},\n\t\t[ blockName ]\n\t);\n\n\tconst sources = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getAllBlockBindingsSources } = unlock(\n\t\t\t\tselect( blockStore )\n\t\t\t);\n\t\t\tconst data = {};\n\t\t\tObject.entries( getAllBlockBindingsSources() ).forEach(\n\t\t\t\t( [ sourceName, source ] ) => {\n\t\t\t\t\tif ( ! source.getFieldsList ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst context = {};\n\t\t\t\t\tif ( source.usesContext?.length ) {\n\t\t\t\t\t\tfor ( const key of source.usesContext ) {\n\t\t\t\t\t\t\tcontext[ key ] = blockContext[ key ];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst items = source.getFieldsList( {\n\t\t\t\t\t\tselect,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t} );\n\t\t\t\t\tif ( items?.length ) {\n\t\t\t\t\t\tdata[ sourceName ] = items;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\t\t\treturn data;\n\t\t},\n\t\t[ blockContext ]\n\t);\n\n\t// Return early if there are no bindable attributes.\n\tif ( ! bindableAttributes || bindableAttributes.length === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst { bindings } = metadata || {};\n\n\tconst hasCompatibleData = Object.keys( sources ).length > 0;\n\n\t// Lock the UI when the user can't update bindings or there are no fields to connect to.\n\tconst readOnly = ! canUpdateBlockBindings || ! hasCompatibleData;\n\n\tif ( bindings === undefined && ! hasCompatibleData ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<InspectorControls group=\"bindings\">\n\t\t\t<ToolsPanel\n\t\t\t\tlabel={ __( 'Attributes' ) }\n\t\t\t\tresetAll={ () => {\n\t\t\t\t\tremoveAllBlockBindings();\n\t\t\t\t} }\n\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\tclassName=\"block-editor-bindings__panel\"\n\t\t\t>\n\t\t\t\t<ItemGroup isBordered isSeparated>\n\t\t\t\t\t{ bindableAttributes.map( ( attribute ) => {\n\t\t\t\t\t\tconst binding = bindings?.[ attribute ];\n\n\t\t\t\t\t\t// Check if this specific attribute has compatible data from any source.\n\t\t\t\t\t\tconst attributeType = getAttributeType(\n\t\t\t\t\t\t\tblockName,\n\t\t\t\t\t\t\tattribute\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst hasCompatibleDataForAttribute = Object.values(\n\t\t\t\t\t\t\tsources\n\t\t\t\t\t\t).some( ( data ) =>\n\t\t\t\t\t\t\tdata.some( ( item ) => item.type === attributeType )\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst isAttributeReadOnly =\n\t\t\t\t\t\t\treadOnly || ! hasCompatibleDataForAttribute;\n\n\t\t\t\t\t\treturn isAttributeReadOnly ? (\n\t\t\t\t\t\t\t<ReadOnlyBlockBindingsPanelItem\n\t\t\t\t\t\t\t\tkey={ attribute }\n\t\t\t\t\t\t\t\tattribute={ attribute }\n\t\t\t\t\t\t\t\tbinding={ binding }\n\t\t\t\t\t\t\t\tsources={ sources }\n\t\t\t\t\t\t\t\tblockName={ blockName }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<EditableBlockBindingsPanelItem\n\t\t\t\t\t\t\t\tkey={ attribute }\n\t\t\t\t\t\t\t\tattribute={ attribute }\n\t\t\t\t\t\t\t\tbinding={ binding }\n\t\t\t\t\t\t\t\tsources={ sources }\n\t\t\t\t\t\t\t\tblockName={ blockName }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t);\n\t\t\t\t\t} ) }\n\t\t\t\t</ItemGroup>\n\t\t\t\t{ /*\n\t\t\t\t\tUse a div element to make the ToolsPanelHiddenInnerWrapper\n\t\t\t\t\ttoggle the visibility of this help text automatically.\n\t\t\t\t*/ }\n\t\t\t\t<Text as=\"div\" variant=\"muted\">\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Attributes connected to custom fields or other dynamic data.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t</Text>\n\t\t\t</ToolsPanel>\n\t\t</InspectorControls>\n\t);\n};\n\nexport default {\n\tedit: BlockBindingsPanel,\n\tattributeKeys: [ 'metadata' ],\n\thasSupport( name ) {\n\t\treturn ! [\n\t\t\t'core/post-date',\n\t\t\t'core/navigation-link',\n\t\t\t'core/navigation-submenu',\n\t\t].includes( name );\n\t},\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA0B;AAK1B,kBAAmB;AACnB,oBAIO;AACP,wBAQO;AACP,kBAA0B;AAC1B,qBAA2B;AAC3B,qBAAiC;AAKjC,4BAAsC;AACtC,yBAAuB;AACvB,gCAA8B;AAC9B,2BAAyB;AACzB,wBAAoC;AACpC,mBAA0C;AAsEnC;AApEP,IAAM,EAAE,KAAK,QAAI,2BAAQ,kBAAAA,WAAsB;AAU/C,IAAM,mBAAmB,CAAE,WAAW,cAAe;AACpD,QAAM,qBACL,4BAAc,SAAU,EAAE,aAAc,SAAU,GAAG;AACtD,SAAO,mBAAmB,cAAc,WAAW;AACpD;AAEA,IAAM,iCAAiC,MAAM;AAC5C,QAAM,eAAW,iCAAkB,UAAU,GAAI;AACjD,SAAO,CAAE,WACN;AAAA,IACA,cAAc;AAAA,MACb,WAAW;AAAA;AAAA,MAEX,QAAQ;AAAA,IACT;AAAA,EACA,IACA,CAAC;AACL;AAEA,SAAS,8BAA+B,EAAE,WAAW,SAAS,QAAQ,GAAI;AACzE,QAAM,EAAE,SAAS,QAAI,uCAAoB;AACzC,QAAM,EAAE,oBAAoB,QAAI,6CAAsB;AACtD,QAAM,eAAW,iCAAkB,UAAU,GAAI;AACjD,QAAM,mBAAe,2BAAY,qBAAAC,OAAa;AAC9C,QAAM,EAAE,eAAe,OAAO,QAAI;AAAA,IACjC,CAAE,YAAa;AACd,YAAM,EAAE,MAAM,UAAU,IACvB,QAAS,aAAAC,KAAiB,EAAE,SAAU,QAAS;AAChD,aAAO;AAAA,QACN,eAA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AA,EAAK,IAAG,OAAM,SAAQ,SACtB,sDAAC,OACE;AAAA,UACD;AAAA,QACD,GACD,GACD;AAAA;AAAA;AAAA,EACD,GACD;AAEF;AAEA,IAAO,yBAAQ;AAAA,EACd,MAAM;AAAA,EACN,eAAe,CAAE,UAAW;AAAA,EAC5B,WAAY,MAAO;AAClB,WAAO,CAAE;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,IACD,EAAE,SAAU,IAAK;AAAA,EAClB;AACD;",
|
|
6
|
+
"names": ["componentsPrivateApis", "BlockContext", "blockEditorStore", "fastDeepEqual", "VStack", "Text", "ToolsPanelItem", "Item", "blockStore", "InspectorControls", "ToolsPanel", "ItemGroup"]
|
|
7
7
|
}
|
|
@@ -163,15 +163,15 @@ function hasDimensionsSupport(blockName, feature = "any") {
|
|
|
163
163
|
return true;
|
|
164
164
|
}
|
|
165
165
|
if (feature === "any") {
|
|
166
|
-
return !!(support?.aspectRatio || !!support?.minHeight);
|
|
166
|
+
return !!(support?.aspectRatio || !!support?.minHeight || !!support?.width);
|
|
167
167
|
}
|
|
168
168
|
return !!support?.[feature];
|
|
169
169
|
}
|
|
170
170
|
var dimensions_default = {
|
|
171
171
|
useBlockProps,
|
|
172
|
-
attributeKeys: ["minHeight", "style"],
|
|
172
|
+
attributeKeys: ["minHeight", "width", "style"],
|
|
173
173
|
hasSupport(name) {
|
|
174
|
-
return hasDimensionsSupport(name
|
|
174
|
+
return hasDimensionsSupport(name);
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
177
|
function useBlockProps({ name, minHeight, style }) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/dimensions.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { Platform, useState, useEffect, useCallback } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport InspectorControls from '../components/inspector-controls';\nimport {\n\tDimensionsPanel as StylesDimensionsPanel,\n\tuseHasDimensionsPanel,\n} from '../components/global-styles';\nimport { MarginVisualizer, PaddingVisualizer } from './spacing-visualizer';\nimport { store as blockEditorStore } from '../store';\nimport { unlock } from '../lock-unlock';\nimport { cleanEmptyObject, shouldSkipSerialization } from './utils';\n\nexport const DIMENSIONS_SUPPORT_KEY = 'dimensions';\nexport const SPACING_SUPPORT_KEY = 'spacing';\nexport const ALL_SIDES = [ 'top', 'right', 'bottom', 'left' ];\nexport const AXIAL_SIDES = [ 'vertical', 'horizontal' ];\n\nfunction useVisualizer() {\n\tconst [ property, setProperty ] = useState( false );\n\tconst { hideBlockInterface, showBlockInterface } = unlock(\n\t\tuseDispatch( blockEditorStore )\n\t);\n\tuseEffect( () => {\n\t\tif ( ! property ) {\n\t\t\tshowBlockInterface();\n\t\t} else {\n\t\t\thideBlockInterface();\n\t\t}\n\t}, [ property, showBlockInterface, hideBlockInterface ] );\n\n\treturn [ property, setProperty ];\n}\n\nfunction DimensionsInspectorControl( { children, resetAllFilter } ) {\n\tconst attributesResetAllFilter = useCallback(\n\t\t( attributes ) => {\n\t\t\tconst existingStyle = attributes.style;\n\t\t\tconst updatedStyle = resetAllFilter( existingStyle );\n\t\t\treturn {\n\t\t\t\t...attributes,\n\t\t\t\tstyle: updatedStyle,\n\t\t\t};\n\t\t},\n\t\t[ resetAllFilter ]\n\t);\n\n\treturn (\n\t\t<InspectorControls\n\t\t\tgroup=\"dimensions\"\n\t\t\tresetAllFilter={ attributesResetAllFilter }\n\t\t>\n\t\t\t{ children }\n\t\t</InspectorControls>\n\t);\n}\n\nexport function DimensionsPanel( { clientId, name, setAttributes, settings } ) {\n\tconst isEnabled = useHasDimensionsPanel( settings );\n\tconst value = useSelect(\n\t\t( select ) => {\n\t\t\t// Early return to avoid subscription when disabled\n\t\t\tif ( ! isEnabled ) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn select( blockEditorStore ).getBlockAttributes( clientId )\n\t\t\t\t?.style;\n\t\t},\n\t\t[ clientId, isEnabled ]\n\t);\n\tconst [ visualizedProperty, setVisualizedProperty ] = useVisualizer();\n\tconst onChange = ( newStyle ) => {\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t} );\n\t};\n\n\tif ( ! isEnabled ) {\n\t\treturn null;\n\t}\n\n\tconst defaultDimensionsControls = getBlockSupport( name, [\n\t\tDIMENSIONS_SUPPORT_KEY,\n\t\t'__experimentalDefaultControls',\n\t] );\n\tconst defaultSpacingControls = getBlockSupport( name, [\n\t\tSPACING_SUPPORT_KEY,\n\t\t'__experimentalDefaultControls',\n\t] );\n\tconst defaultControls = {\n\t\t...defaultDimensionsControls,\n\t\t...defaultSpacingControls,\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<StylesDimensionsPanel\n\t\t\t\tas={ DimensionsInspectorControl }\n\t\t\t\tpanelId={ clientId }\n\t\t\t\tsettings={ settings }\n\t\t\t\tvalue={ value }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tdefaultControls={ defaultControls }\n\t\t\t\tonVisualize={ setVisualizedProperty }\n\t\t\t/>\n\t\t\t{ !! settings?.spacing?.padding &&\n\t\t\t\tvisualizedProperty === 'padding' && (\n\t\t\t\t\t<PaddingVisualizer\n\t\t\t\t\t\tforceShow={ visualizedProperty === 'padding' }\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t{ !! settings?.spacing?.margin &&\n\t\t\t\tvisualizedProperty === 'margin' && (\n\t\t\t\t\t<MarginVisualizer\n\t\t\t\t\t\tforceShow={ visualizedProperty === 'margin' }\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t</>\n\t);\n}\n\n/**\n * Determine whether there is block support for dimensions.\n *\n * @param {string} blockName Block name.\n * @param {string} feature Background image feature to check for.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasDimensionsSupport( blockName, feature = 'any' ) {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst support = getBlockSupport( blockName, DIMENSIONS_SUPPORT_KEY );\n\n\tif ( support === true ) {\n\t\treturn true;\n\t}\n\n\tif ( feature === 'any' ) {\n\t\treturn !! (
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,qBAA2D;AAC3D,kBAAuC;AACvC,oBAAgC;AAChC,wBAAuB;AAKvB,gCAA8B;AAC9B,2BAGO;AACP,gCAAoD;AACpD,mBAA0C;AAC1C,yBAAuB;AACvB,mBAA0D;AAqCxD;AAnCK,IAAM,yBAAyB;AAC/B,IAAM,sBAAsB;AAC5B,IAAM,YAAY,CAAE,OAAO,SAAS,UAAU,MAAO;AACrD,IAAM,cAAc,CAAE,YAAY,YAAa;AAEtD,SAAS,gBAAgB;AACxB,QAAM,CAAE,UAAU,WAAY,QAAI,yBAAU,KAAM;AAClD,QAAM,EAAE,oBAAoB,mBAAmB,QAAI;AAAA,QAClD,yBAAa,aAAAA,KAAiB;AAAA,EAC/B;AACA,gCAAW,MAAM;AAChB,QAAK,CAAE,UAAW;AACjB,yBAAmB;AAAA,IACpB,OAAO;AACN,yBAAmB;AAAA,IACpB;AAAA,EACD,GAAG,CAAE,UAAU,oBAAoB,kBAAmB,CAAE;AAExD,SAAO,CAAE,UAAU,WAAY;AAChC;AAEA,SAAS,2BAA4B,EAAE,UAAU,eAAe,GAAI;AACnE,QAAM,+BAA2B;AAAA,IAChC,CAAE,eAAgB;AACjB,YAAM,gBAAgB,WAAW;AACjC,YAAM,eAAe,eAAgB,aAAc;AACnD,aAAO;AAAA,QACN,GAAG;AAAA,QACH,OAAO;AAAA,MACR;AAAA,IACD;AAAA,IACA,CAAE,cAAe;AAAA,EAClB;AAEA,SACC;AAAA,IAAC,0BAAAC;AAAA,IAAA;AAAA,MACA,OAAM;AAAA,MACN,gBAAiB;AAAA,MAEf;AAAA;AAAA,EACH;AAEF;AAEO,SAAS,gBAAiB,EAAE,UAAU,MAAM,eAAe,SAAS,GAAI;AAC9E,QAAM,gBAAY,4CAAuB,QAAS;AAClD,QAAM,YAAQ;AAAA,IACb,CAAE,WAAY;AAEb,UAAK,CAAE,WAAY;AAClB,eAAO;AAAA,MACR;AACA,aAAO,OAAQ,aAAAD,KAAiB,EAAE,mBAAoB,QAAS,GAC5D;AAAA,IACJ;AAAA,IACA,CAAE,UAAU,SAAU;AAAA,EACvB;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { Platform, useState, useEffect, useCallback } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport InspectorControls from '../components/inspector-controls';\nimport {\n\tDimensionsPanel as StylesDimensionsPanel,\n\tuseHasDimensionsPanel,\n} from '../components/global-styles';\nimport { MarginVisualizer, PaddingVisualizer } from './spacing-visualizer';\nimport { store as blockEditorStore } from '../store';\nimport { unlock } from '../lock-unlock';\nimport { cleanEmptyObject, shouldSkipSerialization } from './utils';\n\nexport const DIMENSIONS_SUPPORT_KEY = 'dimensions';\nexport const SPACING_SUPPORT_KEY = 'spacing';\nexport const ALL_SIDES = [ 'top', 'right', 'bottom', 'left' ];\nexport const AXIAL_SIDES = [ 'vertical', 'horizontal' ];\n\nfunction useVisualizer() {\n\tconst [ property, setProperty ] = useState( false );\n\tconst { hideBlockInterface, showBlockInterface } = unlock(\n\t\tuseDispatch( blockEditorStore )\n\t);\n\tuseEffect( () => {\n\t\tif ( ! property ) {\n\t\t\tshowBlockInterface();\n\t\t} else {\n\t\t\thideBlockInterface();\n\t\t}\n\t}, [ property, showBlockInterface, hideBlockInterface ] );\n\n\treturn [ property, setProperty ];\n}\n\nfunction DimensionsInspectorControl( { children, resetAllFilter } ) {\n\tconst attributesResetAllFilter = useCallback(\n\t\t( attributes ) => {\n\t\t\tconst existingStyle = attributes.style;\n\t\t\tconst updatedStyle = resetAllFilter( existingStyle );\n\t\t\treturn {\n\t\t\t\t...attributes,\n\t\t\t\tstyle: updatedStyle,\n\t\t\t};\n\t\t},\n\t\t[ resetAllFilter ]\n\t);\n\n\treturn (\n\t\t<InspectorControls\n\t\t\tgroup=\"dimensions\"\n\t\t\tresetAllFilter={ attributesResetAllFilter }\n\t\t>\n\t\t\t{ children }\n\t\t</InspectorControls>\n\t);\n}\n\nexport function DimensionsPanel( { clientId, name, setAttributes, settings } ) {\n\tconst isEnabled = useHasDimensionsPanel( settings );\n\tconst value = useSelect(\n\t\t( select ) => {\n\t\t\t// Early return to avoid subscription when disabled\n\t\t\tif ( ! isEnabled ) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn select( blockEditorStore ).getBlockAttributes( clientId )\n\t\t\t\t?.style;\n\t\t},\n\t\t[ clientId, isEnabled ]\n\t);\n\n\tconst [ visualizedProperty, setVisualizedProperty ] = useVisualizer();\n\tconst onChange = ( newStyle ) => {\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t} );\n\t};\n\n\tif ( ! isEnabled ) {\n\t\treturn null;\n\t}\n\n\tconst defaultDimensionsControls = getBlockSupport( name, [\n\t\tDIMENSIONS_SUPPORT_KEY,\n\t\t'__experimentalDefaultControls',\n\t] );\n\tconst defaultSpacingControls = getBlockSupport( name, [\n\t\tSPACING_SUPPORT_KEY,\n\t\t'__experimentalDefaultControls',\n\t] );\n\tconst defaultControls = {\n\t\t...defaultDimensionsControls,\n\t\t...defaultSpacingControls,\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<StylesDimensionsPanel\n\t\t\t\tas={ DimensionsInspectorControl }\n\t\t\t\tpanelId={ clientId }\n\t\t\t\tsettings={ settings }\n\t\t\t\tvalue={ value }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tdefaultControls={ defaultControls }\n\t\t\t\tonVisualize={ setVisualizedProperty }\n\t\t\t/>\n\t\t\t{ !! settings?.spacing?.padding &&\n\t\t\t\tvisualizedProperty === 'padding' && (\n\t\t\t\t\t<PaddingVisualizer\n\t\t\t\t\t\tforceShow={ visualizedProperty === 'padding' }\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t{ !! settings?.spacing?.margin &&\n\t\t\t\tvisualizedProperty === 'margin' && (\n\t\t\t\t\t<MarginVisualizer\n\t\t\t\t\t\tforceShow={ visualizedProperty === 'margin' }\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t</>\n\t);\n}\n\n/**\n * Determine whether there is block support for dimensions.\n *\n * @param {string} blockName Block name.\n * @param {string} feature Background image feature to check for.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasDimensionsSupport( blockName, feature = 'any' ) {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst support = getBlockSupport( blockName, DIMENSIONS_SUPPORT_KEY );\n\n\tif ( support === true ) {\n\t\treturn true;\n\t}\n\n\tif ( feature === 'any' ) {\n\t\treturn !! (\n\t\t\tsupport?.aspectRatio ||\n\t\t\t!! support?.minHeight ||\n\t\t\t!! support?.width\n\t\t);\n\t}\n\n\treturn !! support?.[ feature ];\n}\n\nexport default {\n\tuseBlockProps,\n\tattributeKeys: [ 'minHeight', 'width', 'style' ],\n\thasSupport( name ) {\n\t\treturn hasDimensionsSupport( name );\n\t},\n};\n\nfunction useBlockProps( { name, minHeight, style } ) {\n\tif (\n\t\t! hasDimensionsSupport( name, 'aspectRatio' ) ||\n\t\tshouldSkipSerialization( name, DIMENSIONS_SUPPORT_KEY, 'aspectRatio' )\n\t) {\n\t\treturn {};\n\t}\n\n\tconst className = clsx( {\n\t\t'has-aspect-ratio': !! style?.dimensions?.aspectRatio,\n\t} );\n\n\t// Allow dimensions-based inline style overrides to override any global styles rules that\n\t// might be set for the block, and therefore affect the display of the aspect ratio.\n\tconst inlineStyleOverrides = {};\n\n\t// Apply rules to unset incompatible styles.\n\t// Note that a set `aspectRatio` will win out if both an aspect ratio and a minHeight are set.\n\t// This is because the aspect ratio is a newer block support, so (in theory) any aspect ratio\n\t// that is set should be intentional and should override any existing minHeight. The Cover block\n\t// and dimensions controls have logic that will manually clear the aspect ratio if a minHeight\n\t// is set.\n\tif ( style?.dimensions?.aspectRatio ) {\n\t\t// To ensure the aspect ratio does not get overridden by `minHeight` unset any existing rule.\n\t\tinlineStyleOverrides.minHeight = 'unset';\n\t} else if ( minHeight || style?.dimensions?.minHeight ) {\n\t\t// To ensure the minHeight does not get overridden by `aspectRatio` unset any existing rule.\n\t\tinlineStyleOverrides.aspectRatio = 'unset';\n\t}\n\n\treturn { className, style: inlineStyleOverrides };\n}\n\n/**\n * @deprecated\n */\nexport function useCustomSides() {\n\tdeprecated( 'wp.blockEditor.__experimentalUseCustomSides', {\n\t\tsince: '6.3',\n\t\tversion: '6.4',\n\t} );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,qBAA2D;AAC3D,kBAAuC;AACvC,oBAAgC;AAChC,wBAAuB;AAKvB,gCAA8B;AAC9B,2BAGO;AACP,gCAAoD;AACpD,mBAA0C;AAC1C,yBAAuB;AACvB,mBAA0D;AAqCxD;AAnCK,IAAM,y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A,EACnC;AACD;AAEA,SAAS,cAAe,EAAE,MAAM,WAAW,MAAM,GAAI;AACpD,MACC,CAAE,qBAAsB,MAAM,aAAc,SAC5C,sCAAyB,MAAM,wBAAwB,aAAc,GACpE;AACD,WAAO,CAAC;AAAA,EACT;AAEA,QAAM,gBAAY,YAAAC,SAAM;AAAA,IACvB,oBAAoB,CAAC,CAAE,OAAO,YAAY;AAAA,EAC3C,CAAE;AAIF,QAAM,uBAAuB,CAAC;AAQ9B,MAAK,OAAO,YAAY,aAAc;AAErC,yBAAqB,YAAY;AAAA,EAClC,WAAY,aAAa,OAAO,YAAY,WAAY;AAEvD,yBAAqB,cAAc;AAAA,EACpC;AAEA,SAAO,EAAE,WAAW,OAAO,qBAAqB;AACjD;AAKO,SAAS,iBAAiB;AAChC,wBAAAC,SAAY,+CAA+C;AAAA,IAC1D,OAAO;AAAA,IACP,SAAS;AAAA,EACV,CAAE;AACH;",
|
|
6
6
|
"names": ["blockEditorStore", "InspectorControls", "StylesDimensionsPanel", "clsx", "deprecated"]
|
|
7
7
|
}
|
package/build/hooks/metadata.js
CHANGED
|
@@ -60,7 +60,7 @@ function addTransforms(result, source, index, results) {
|
|
|
60
60
|
if (sourceMetadata.name && !result.attributes?.metadata?.name && (0, import_blocks.hasBlockSupport)(result.name, "renaming", true)) {
|
|
61
61
|
preservedMetadata.name = sourceMetadata.name;
|
|
62
62
|
}
|
|
63
|
-
if (sourceMetadata.blockVisibility !== void 0 && !result.attributes?.metadata?.blockVisibility && (0, import_blocks.hasBlockSupport)(result.name, "
|
|
63
|
+
if (sourceMetadata.blockVisibility !== void 0 && !result.attributes?.metadata?.blockVisibility && (0, import_blocks.hasBlockSupport)(result.name, "visibility", true)) {
|
|
64
64
|
preservedMetadata.blockVisibility = sourceMetadata.blockVisibility;
|
|
65
65
|
}
|
|
66
66
|
if (Object.keys(preservedMetadata).length > 0) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/metadata.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { hasBlockSupport } from '@wordpress/blocks';\n\nconst META_ATTRIBUTE_NAME = 'metadata';\n\n/**\n * Filters registered block settings, extending attributes to include `metadata`.\n *\n * see: https://github.com/WordPress/gutenberg/pull/40393/files#r864632012\n *\n * @param {Object} blockTypeSettings Original block settings.\n * @return {Object} Filtered block settings.\n */\nexport function addMetaAttribute( blockTypeSettings ) {\n\t// Allow blocks to specify their own attribute definition with default values if needed.\n\tif ( blockTypeSettings?.attributes?.[ META_ATTRIBUTE_NAME ]?.type ) {\n\t\treturn blockTypeSettings;\n\t}\n\n\tblockTypeSettings.attributes = {\n\t\t...blockTypeSettings.attributes,\n\t\t[ META_ATTRIBUTE_NAME ]: {\n\t\t\ttype: 'object',\n\t\t},\n\t};\n\n\treturn blockTypeSettings;\n}\n\n/**\n * Add metadata transforms.\n *\n * @param {Object} result The transformed block.\n * @param {Array} source Original blocks transformed.\n * @param {number} index Index of the transformed block.\n * @param {Array} results All blocks that resulted from the transformation.\n * @return {Object} Modified transformed block.\n */\nexport function addTransforms( result, source, index, results ) {\n\t// If the condition verifies we are probably in the presence of a wrapping transform\n\t// e.g: nesting paragraphs in a group or columns and in that case the metadata should not be kept.\n\tif ( results.length === 1 && result.innerBlocks.length === source.length ) {\n\t\treturn result;\n\t}\n\n\t// If we are transforming one block to multiple blocks or multiple blocks to one block,\n\t// we ignore the metadata during the transform.\n\tif (\n\t\t( results.length === 1 && source.length > 1 ) ||\n\t\t( results.length > 1 && source.length === 1 )\n\t) {\n\t\treturn result;\n\t}\n\n\t// If we are transforming multiple blocks to multiple blocks with different counts,\n\t// we ignore the metadata during the transform.\n\tif (\n\t\tresults.length > 1 &&\n\t\tsource.length > 1 &&\n\t\tresults.length !== source.length\n\t) {\n\t\treturn result;\n\t}\n\n\tconst sourceMetadata = source[ index ]?.attributes?.metadata;\n\n\tif ( ! sourceMetadata ) {\n\t\treturn result;\n\t}\n\n\tconst preservedMetadata = {};\n\n\t// Notes\n\tif ( sourceMetadata.noteId && ! result.attributes?.metadata?.noteId ) {\n\t\tpreservedMetadata.noteId = sourceMetadata.noteId;\n\t}\n\n\t// Custom name\n\tif (\n\t\tsourceMetadata.name &&\n\t\t! result.attributes?.metadata?.name &&\n\t\thasBlockSupport( result.name, 'renaming', true )\n\t) {\n\t\tpreservedMetadata.name = sourceMetadata.name;\n\t}\n\n\t// Block visibility\n\tif (\n\t\tsourceMetadata.blockVisibility !== undefined &&\n\t\t! result.attributes?.metadata?.blockVisibility &&\n\t\thasBlockSupport( result.name, '
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAA0B;AAC1B,oBAAgC;AAEhC,IAAM,sBAAsB;AAUrB,SAAS,iBAAkB,mBAAoB;AAErD,MAAK,mBAAmB,aAAc,mBAAoB,GAAG,MAAO;AACnE,WAAO;AAAA,EACR;AAEA,oBAAkB,aAAa;AAAA,IAC9B,GAAG,kBAAkB;AAAA,IACrB,CAAE,mBAAoB,GAAG;AAAA,MACxB,MAAM;AAAA,IACP;AAAA,EACD;AAEA,SAAO;AACR;AAWO,SAAS,cAAe,QAAQ,QAAQ,OAAO,SAAU;AAG/D,MAAK,QAAQ,WAAW,KAAK,OAAO,YAAY,WAAW,OAAO,QAAS;AAC1E,WAAO;AAAA,EACR;AAIA,MACG,QAAQ,WAAW,KAAK,OAAO,SAAS,KACxC,QAAQ,SAAS,KAAK,OAAO,WAAW,GACzC;AACD,WAAO;AAAA,EACR;AAIA,MACC,QAAQ,SAAS,KACjB,OAAO,SAAS,KAChB,QAAQ,WAAW,OAAO,QACzB;AACD,WAAO;AAAA,EACR;AAEA,QAAM,iBAAiB,OAAQ,KAAM,GAAG,YAAY;AAEpD,MAAK,CAAE,gBAAiB;AACvB,WAAO;AAAA,EACR;AAEA,QAAM,oBAAoB,CAAC;AAG3B,MAAK,eAAe,UAAU,CAAE,OAAO,YAAY,UAAU,QAAS;AACrE,sBAAkB,SAAS,eAAe;AAAA,EAC3C;AAGA,MACC,eAAe,QACf,CAAE,OAAO,YAAY,UAAU,YAC/B,+BAAiB,OAAO,MAAM,YAAY,IAAK,GAC9C;AACD,sBAAkB,OAAO,eAAe;AAAA,EACzC;AAGA,MACC,eAAe,oBAAoB,UACnC,CAAE,OAAO,YAAY,UAAU,uBAC/B,+BAAiB,OAAO,MAAM,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { hasBlockSupport } from '@wordpress/blocks';\n\nconst META_ATTRIBUTE_NAME = 'metadata';\n\n/**\n * Filters registered block settings, extending attributes to include `metadata`.\n *\n * see: https://github.com/WordPress/gutenberg/pull/40393/files#r864632012\n *\n * @param {Object} blockTypeSettings Original block settings.\n * @return {Object} Filtered block settings.\n */\nexport function addMetaAttribute( blockTypeSettings ) {\n\t// Allow blocks to specify their own attribute definition with default values if needed.\n\tif ( blockTypeSettings?.attributes?.[ META_ATTRIBUTE_NAME ]?.type ) {\n\t\treturn blockTypeSettings;\n\t}\n\n\tblockTypeSettings.attributes = {\n\t\t...blockTypeSettings.attributes,\n\t\t[ META_ATTRIBUTE_NAME ]: {\n\t\t\ttype: 'object',\n\t\t},\n\t};\n\n\treturn blockTypeSettings;\n}\n\n/**\n * Add metadata transforms.\n *\n * @param {Object} result The transformed block.\n * @param {Array} source Original blocks transformed.\n * @param {number} index Index of the transformed block.\n * @param {Array} results All blocks that resulted from the transformation.\n * @return {Object} Modified transformed block.\n */\nexport function addTransforms( result, source, index, results ) {\n\t// If the condition verifies we are probably in the presence of a wrapping transform\n\t// e.g: nesting paragraphs in a group or columns and in that case the metadata should not be kept.\n\tif ( results.length === 1 && result.innerBlocks.length === source.length ) {\n\t\treturn result;\n\t}\n\n\t// If we are transforming one block to multiple blocks or multiple blocks to one block,\n\t// we ignore the metadata during the transform.\n\tif (\n\t\t( results.length === 1 && source.length > 1 ) ||\n\t\t( results.length > 1 && source.length === 1 )\n\t) {\n\t\treturn result;\n\t}\n\n\t// If we are transforming multiple blocks to multiple blocks with different counts,\n\t// we ignore the metadata during the transform.\n\tif (\n\t\tresults.length > 1 &&\n\t\tsource.length > 1 &&\n\t\tresults.length !== source.length\n\t) {\n\t\treturn result;\n\t}\n\n\tconst sourceMetadata = source[ index ]?.attributes?.metadata;\n\n\tif ( ! sourceMetadata ) {\n\t\treturn result;\n\t}\n\n\tconst preservedMetadata = {};\n\n\t// Notes\n\tif ( sourceMetadata.noteId && ! result.attributes?.metadata?.noteId ) {\n\t\tpreservedMetadata.noteId = sourceMetadata.noteId;\n\t}\n\n\t// Custom name\n\tif (\n\t\tsourceMetadata.name &&\n\t\t! result.attributes?.metadata?.name &&\n\t\thasBlockSupport( result.name, 'renaming', true )\n\t) {\n\t\tpreservedMetadata.name = sourceMetadata.name;\n\t}\n\n\t// Block visibility\n\tif (\n\t\tsourceMetadata.blockVisibility !== undefined &&\n\t\t! result.attributes?.metadata?.blockVisibility &&\n\t\thasBlockSupport( result.name, 'visibility', true )\n\t) {\n\t\tpreservedMetadata.blockVisibility = sourceMetadata.blockVisibility;\n\t}\n\n\tif ( Object.keys( preservedMetadata ).length > 0 ) {\n\t\treturn {\n\t\t\t...result,\n\t\t\tattributes: {\n\t\t\t\t...result.attributes,\n\t\t\t\tmetadata: {\n\t\t\t\t\t...result.attributes.metadata,\n\t\t\t\t\t...preservedMetadata,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\treturn result;\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/metadata/addMetaAttribute',\n\taddMetaAttribute\n);\n\naddFilter(\n\t'blocks.switchToBlockType.transformedBlock',\n\t'core/metadata/addTransforms',\n\taddTransforms\n);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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