@wordpress/block-editor 15.10.1-next.ba3aee3a2.0 → 15.11.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-bindings/attribute-control.cjs +1 -1
- package/build/components/block-bindings/attribute-control.cjs.map +1 -1
- package/build/components/block-bindings/source-fields-list.cjs +1 -1
- package/build/components/block-bindings/source-fields-list.cjs.map +1 -1
- package/build/components/block-edit/context.cjs +5 -0
- package/build/components/block-edit/context.cjs.map +2 -2
- package/build/components/block-edit/index.cjs +3 -0
- package/build/components/block-edit/index.cjs.map +2 -2
- package/build/components/block-inspector/index.cjs +2 -9
- package/build/components/block-inspector/index.cjs.map +2 -2
- package/build/components/block-list/block.cjs +3 -0
- package/build/components/block-list/block.cjs.map +2 -2
- package/build/components/block-tools/index.cjs +82 -70
- package/build/components/block-tools/index.cjs.map +2 -2
- package/build/components/block-visibility/block-visibility-info.cjs +0 -59
- package/build/components/block-visibility/block-visibility-info.cjs.map +3 -3
- package/build/components/block-visibility/constants.cjs +10 -5
- package/build/components/block-visibility/constants.cjs.map +2 -2
- package/build/components/block-visibility/index.cjs +13 -5
- package/build/components/block-visibility/index.cjs.map +3 -3
- package/build/components/block-visibility/modal.cjs +397 -0
- package/build/components/block-visibility/modal.cjs.map +7 -0
- package/build/components/block-visibility/toolbar.cjs +1 -1
- package/build/components/block-visibility/toolbar.cjs.map +2 -2
- package/build/components/block-visibility/use-block-visibility.cjs +13 -17
- package/build/components/block-visibility/use-block-visibility.cjs.map +2 -2
- package/build/components/block-visibility/utils.cjs +81 -0
- package/build/components/block-visibility/utils.cjs.map +7 -0
- package/build/components/block-visibility/viewport-menu-item.cjs +61 -0
- package/build/components/block-visibility/viewport-menu-item.cjs.map +7 -0
- package/build/components/block-visibility/viewport-toolbar.cjs +89 -0
- package/build/components/block-visibility/viewport-toolbar.cjs.map +7 -0
- package/build/components/button-block-appender/index.cjs +23 -19
- package/build/components/button-block-appender/index.cjs.map +2 -2
- package/build/components/font-sizes/font-size-picker.cjs +2 -1
- package/build/components/font-sizes/font-size-picker.cjs.map +2 -2
- package/build/components/inner-blocks/use-inner-block-template-sync.cjs +1 -1
- package/build/components/inner-blocks/use-inner-block-template-sync.cjs.map +1 -1
- package/build/components/inserter/menu.cjs +6 -2
- package/build/components/inserter/menu.cjs.map +2 -2
- package/build/components/inspector-controls/fill.cjs +4 -25
- package/build/components/inspector-controls/fill.cjs.map +2 -2
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.cjs +6 -6
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.cjs.map +2 -2
- package/build/components/list-view/block-select-button.cjs +2 -2
- package/build/components/list-view/block-select-button.cjs.map +2 -2
- package/build/components/list-view/block.cjs +39 -22
- package/build/components/list-view/block.cjs.map +2 -2
- package/build/components/rich-text/index.cjs +1 -1
- package/build/components/rich-text/index.cjs.map +1 -1
- package/build/components/url-input/index.cjs +2 -0
- package/build/components/url-input/index.cjs.map +2 -2
- package/build/components/use-block-commands/index.cjs +1 -1
- package/build/components/use-block-commands/index.cjs.map +2 -2
- package/build/hooks/block-fields/index.cjs +92 -217
- package/build/hooks/block-fields/index.cjs.map +3 -3
- package/build/hooks/block-fields/link/index.cjs +13 -32
- package/build/hooks/block-fields/link/index.cjs.map +2 -2
- package/build/hooks/block-fields/media/index.cjs +36 -67
- package/build/hooks/block-fields/media/index.cjs.map +2 -2
- package/build/hooks/block-fields/rich-text/index.cjs +1 -5
- package/build/hooks/block-fields/rich-text/index.cjs.map +2 -2
- package/build/hooks/cross-origin-isolation.cjs +102 -0
- package/build/hooks/cross-origin-isolation.cjs.map +7 -0
- package/build/hooks/index.cjs +3 -1
- package/build/hooks/index.cjs.map +3 -3
- package/build/hooks/list-view.cjs +27 -10
- package/build/hooks/list-view.cjs.map +2 -2
- package/build/hooks/utils.cjs +3 -2
- package/build/hooks/utils.cjs.map +2 -2
- package/build/layouts/flex.cjs +6 -2
- package/build/layouts/flex.cjs.map +2 -2
- package/build/store/private-selectors.cjs +33 -1
- package/build/store/private-selectors.cjs.map +3 -3
- package/build/store/reducer.cjs +1 -1
- package/build/store/reducer.cjs.map +1 -1
- package/build/store/selectors.cjs +14 -9
- package/build/store/selectors.cjs.map +2 -2
- package/build-module/components/block-bindings/attribute-control.mjs +1 -1
- package/build-module/components/block-bindings/attribute-control.mjs.map +1 -1
- package/build-module/components/block-bindings/source-fields-list.mjs +1 -1
- package/build-module/components/block-bindings/source-fields-list.mjs.map +1 -1
- package/build-module/components/block-edit/context.mjs +4 -0
- package/build-module/components/block-edit/context.mjs.map +2 -2
- package/build-module/components/block-edit/index.mjs +4 -0
- package/build-module/components/block-edit/index.mjs.map +2 -2
- package/build-module/components/block-inspector/index.mjs +2 -9
- package/build-module/components/block-inspector/index.mjs.map +2 -2
- package/build-module/components/block-list/block.mjs +3 -0
- package/build-module/components/block-list/block.mjs.map +2 -2
- package/build-module/components/block-tools/index.mjs +85 -73
- package/build-module/components/block-tools/index.mjs.map +2 -2
- package/build-module/components/block-visibility/block-visibility-info.mjs +0 -59
- package/build-module/components/block-visibility/block-visibility-info.mjs.map +3 -3
- package/build-module/components/block-visibility/constants.mjs +8 -4
- package/build-module/components/block-visibility/constants.mjs.map +2 -2
- package/build-module/components/block-visibility/index.mjs +13 -6
- package/build-module/components/block-visibility/index.mjs.map +2 -2
- package/build-module/components/block-visibility/modal.mjs +384 -0
- package/build-module/components/block-visibility/modal.mjs.map +7 -0
- package/build-module/components/block-visibility/toolbar.mjs +1 -1
- package/build-module/components/block-visibility/toolbar.mjs.map +2 -2
- package/build-module/components/block-visibility/use-block-visibility.mjs +13 -13
- package/build-module/components/block-visibility/use-block-visibility.mjs.map +2 -2
- package/build-module/components/block-visibility/utils.mjs +55 -0
- package/build-module/components/block-visibility/utils.mjs.map +7 -0
- package/build-module/components/block-visibility/viewport-menu-item.mjs +40 -0
- package/build-module/components/block-visibility/viewport-menu-item.mjs.map +7 -0
- package/build-module/components/block-visibility/viewport-toolbar.mjs +68 -0
- package/build-module/components/block-visibility/viewport-toolbar.mjs.map +7 -0
- package/build-module/components/button-block-appender/index.mjs +23 -19
- package/build-module/components/button-block-appender/index.mjs.map +2 -2
- package/build-module/components/font-sizes/font-size-picker.mjs +2 -1
- package/build-module/components/font-sizes/font-size-picker.mjs.map +2 -2
- package/build-module/components/inner-blocks/use-inner-block-template-sync.mjs +1 -1
- package/build-module/components/inner-blocks/use-inner-block-template-sync.mjs.map +1 -1
- package/build-module/components/inserter/menu.mjs +6 -2
- package/build-module/components/inserter/menu.mjs.map +2 -2
- package/build-module/components/inspector-controls/fill.mjs +6 -22
- package/build-module/components/inspector-controls/fill.mjs.map +2 -2
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.mjs +6 -6
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.mjs.map +2 -2
- package/build-module/components/list-view/block-select-button.mjs +2 -2
- package/build-module/components/list-view/block-select-button.mjs.map +2 -2
- package/build-module/components/list-view/block.mjs +39 -22
- package/build-module/components/list-view/block.mjs.map +2 -2
- package/build-module/components/rich-text/index.mjs +1 -1
- package/build-module/components/rich-text/index.mjs.map +1 -1
- package/build-module/components/url-input/index.mjs +2 -0
- package/build-module/components/url-input/index.mjs.map +2 -2
- package/build-module/components/use-block-commands/index.mjs +1 -1
- package/build-module/components/use-block-commands/index.mjs.map +2 -2
- package/build-module/hooks/block-fields/index.mjs +85 -218
- package/build-module/hooks/block-fields/index.mjs.map +2 -2
- package/build-module/hooks/block-fields/link/index.mjs +13 -32
- package/build-module/hooks/block-fields/link/index.mjs.map +2 -2
- package/build-module/hooks/block-fields/media/index.mjs +36 -67
- package/build-module/hooks/block-fields/media/index.mjs.map +2 -2
- package/build-module/hooks/block-fields/rich-text/index.mjs +1 -5
- package/build-module/hooks/block-fields/rich-text/index.mjs.map +2 -2
- package/build-module/hooks/cross-origin-isolation.mjs +100 -0
- package/build-module/hooks/cross-origin-isolation.mjs.map +7 -0
- package/build-module/hooks/index.mjs +3 -1
- package/build-module/hooks/index.mjs.map +2 -2
- package/build-module/hooks/list-view.mjs +27 -10
- package/build-module/hooks/list-view.mjs.map +2 -2
- package/build-module/hooks/utils.mjs +5 -3
- package/build-module/hooks/utils.mjs.map +2 -2
- package/build-module/layouts/flex.mjs +6 -2
- package/build-module/layouts/flex.mjs.map +2 -2
- package/build-module/store/private-selectors.mjs +34 -1
- package/build-module/store/private-selectors.mjs.map +2 -2
- package/build-module/store/reducer.mjs +1 -1
- package/build-module/store/reducer.mjs.map +1 -1
- package/build-module/store/selectors.mjs +14 -9
- package/build-module/store/selectors.mjs.map +2 -2
- package/build-style/content-rtl.css +4 -1
- package/build-style/content.css +4 -1
- package/build-style/style-rtl.css +48 -0
- package/build-style/style.css +48 -0
- package/package.json +39 -39
- package/src/components/block-bindings/attribute-control.js +1 -1
- package/src/components/block-bindings/source-fields-list.js +1 -1
- package/src/components/block-edit/context.js +3 -0
- package/src/components/block-edit/index.js +6 -0
- package/src/components/block-inspector/index.js +2 -6
- package/src/components/block-list/block.js +3 -0
- package/src/components/block-list/block.native.js +5 -0
- package/src/components/block-list/content.scss +4 -1
- package/src/components/block-patterns-list/stories/index.story.jsx +1 -1
- package/src/components/block-tools/index.js +45 -33
- package/src/components/block-visibility/block-visibility-info.js +0 -1
- package/src/components/block-visibility/constants.js +7 -3
- package/src/components/block-visibility/index.js +21 -3
- package/src/components/block-visibility/modal.js +358 -0
- package/src/components/block-visibility/style.scss +58 -0
- package/src/components/block-visibility/test/use-block-visibility.js +12 -56
- package/src/components/block-visibility/test/utils.js +266 -0
- package/src/components/block-visibility/toolbar.js +1 -1
- package/src/components/block-visibility/use-block-visibility.js +18 -21
- package/src/components/block-visibility/utils.js +95 -0
- package/src/components/block-visibility/viewport-menu-item.js +42 -0
- package/src/components/block-visibility/viewport-toolbar.js +88 -0
- package/src/components/button-block-appender/index.js +2 -2
- package/src/components/font-sizes/font-size-picker.js +1 -0
- package/src/components/inner-blocks/use-inner-block-template-sync.js +1 -1
- package/src/components/inserter/menu.js +6 -2
- package/src/components/inspector-controls/fill.js +10 -20
- package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +11 -8
- package/src/components/list-view/block-select-button.js +2 -2
- package/src/components/list-view/block.js +47 -25
- package/src/components/rich-text/index.js +1 -1
- package/src/components/url-input/index.js +2 -0
- package/src/components/use-block-commands/index.js +4 -3
- package/src/hooks/block-fields/index.js +127 -292
- package/src/hooks/block-fields/link/index.js +13 -51
- package/src/hooks/block-fields/media/index.js +35 -106
- package/src/hooks/block-fields/rich-text/index.js +1 -5
- package/src/hooks/block-fields/styles.scss +2 -0
- package/src/hooks/cross-origin-isolation.js +143 -0
- package/src/hooks/index.js +3 -1
- package/src/hooks/list-view.js +40 -10
- package/src/hooks/utils.js +4 -0
- package/src/layouts/flex.js +8 -3
- package/src/layouts/test/flex.js +53 -0
- package/src/store/private-selectors.js +64 -1
- package/src/store/reducer.js +1 -1
- package/src/store/selectors.js +21 -15
- package/src/store/test/private-selectors.js +80 -0
- package/src/style.scss +1 -0
- package/src/components/block-visibility/styles.scss +0 -10
- /package/src/components/block-icon/stories/{index.story.js → index.story.ts} +0 -0
- /package/src/components/contrast-checker/stories/{index.story.js → index.story.ts} +0 -0
|
@@ -170,7 +170,7 @@ var getQuickActionsCommands = () => function useQuickActionsCommands() {
|
|
|
170
170
|
const canRemove = canRemoveBlocks(clientIds);
|
|
171
171
|
const canToggleBlockVisibility = blocks.every(
|
|
172
172
|
({ clientId }) => hasBlockSupport(getBlockName(clientId), "visibility", true)
|
|
173
|
-
);
|
|
173
|
+
) && !window.__experimentalHideBlocksBasedOnScreenSize;
|
|
174
174
|
const commands = [];
|
|
175
175
|
if (canDuplicate) {
|
|
176
176
|
commands.push({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/use-block-commands/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\thasBlockSupport,\n\tstore as blocksStore,\n\tswitchToBlockType,\n\tisTemplatePart,\n} from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useCommandLoader } from '@wordpress/commands';\nimport {\n\tcopy,\n\ttrash as remove,\n\tplus as add,\n\tgroup,\n\tungroup,\n\tseen,\n\tunseen,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport BlockIcon from '../block-icon';\nimport { store as blockEditorStore } from '../../store';\nimport { cleanEmptyObject } from '../../hooks/utils';\n\nconst getTransformCommands = () =>\n\tfunction useTransformCommands() {\n\t\tconst { replaceBlocks, multiSelect } = useDispatch( blockEditorStore );\n\t\tconst {\n\t\t\tblocks,\n\t\t\tclientIds,\n\t\t\tcanRemove,\n\t\t\tpossibleBlockTransformations,\n\t\t\tinvalidSelection,\n\t\t} = useSelect( ( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\tgetBlockTransformItems,\n\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\tgetBlocksByClientId,\n\t\t\t\tcanRemoveBlocks,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst selectedBlockClientIds = getSelectedBlockClientIds();\n\t\t\tconst selectedBlocks = getBlocksByClientId(\n\t\t\t\tselectedBlockClientIds\n\t\t\t);\n\n\t\t\t// selectedBlocks can have `null`s when something tries to call `selectBlock` with an inexistent clientId.\n\t\t\t// These nulls will cause fatal errors down the line.\n\t\t\t// In order to prevent discrepancies between selectedBlockClientIds and selectedBlocks, we effectively treat the entire selection as invalid.\n\t\t\t// @see https://github.com/WordPress/gutenberg/pull/59410#issuecomment-2006304536\n\t\t\tif ( selectedBlocks.filter( ( block ) => ! block ).length > 0 ) {\n\t\t\t\treturn {\n\t\t\t\t\tinvalidSelection: true,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst rootClientId = getBlockRootClientId(\n\t\t\t\tselectedBlockClientIds[ 0 ]\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tblocks: selectedBlocks,\n\t\t\t\tclientIds: selectedBlockClientIds,\n\t\t\t\tpossibleBlockTransformations: getBlockTransformItems(\n\t\t\t\t\tselectedBlocks,\n\t\t\t\t\trootClientId\n\t\t\t\t),\n\t\t\t\tcanRemove: canRemoveBlocks( selectedBlockClientIds ),\n\t\t\t\tinvalidSelection: false,\n\t\t\t};\n\t\t}, [] );\n\n\t\tif ( invalidSelection ) {\n\t\t\treturn {\n\t\t\t\tisLoading: false,\n\t\t\t\tcommands: [],\n\t\t\t};\n\t\t}\n\t\tconst isTemplate = blocks.length === 1 && isTemplatePart( blocks[ 0 ] );\n\n\t\tfunction selectForMultipleBlocks( insertedBlocks ) {\n\t\t\tif ( insertedBlocks.length > 1 ) {\n\t\t\t\tmultiSelect(\n\t\t\t\t\tinsertedBlocks[ 0 ].clientId,\n\t\t\t\t\tinsertedBlocks[ insertedBlocks.length - 1 ].clientId\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Simple block transformation based on the `Block Transforms` API.\n\t\tfunction onBlockTransform( name ) {\n\t\t\tconst newBlocks = switchToBlockType( blocks, name );\n\t\t\treplaceBlocks( clientIds, newBlocks );\n\t\t\tselectForMultipleBlocks( newBlocks );\n\t\t}\n\n\t\t/**\n\t\t * The `isTemplate` check is a stopgap solution here.\n\t\t * Ideally, the Transforms API should handle this\n\t\t * by allowing to exclude blocks from wildcard transformations.\n\t\t */\n\t\tconst hasPossibleBlockTransformations =\n\t\t\t!! possibleBlockTransformations.length && canRemove && ! isTemplate;\n\n\t\tif (\n\t\t\t! clientIds ||\n\t\t\tclientIds.length < 1 ||\n\t\t\t! hasPossibleBlockTransformations\n\t\t) {\n\t\t\treturn { isLoading: false, commands: [] };\n\t\t}\n\n\t\tconst commands = possibleBlockTransformations.map(\n\t\t\t( transformation ) => {\n\t\t\t\tconst { name, title, icon } = transformation;\n\t\t\t\treturn {\n\t\t\t\t\tname:\n\t\t\t\t\t\t'core/block-editor/transform-to-' +\n\t\t\t\t\t\tname.replace( '/', '-' ),\n\t\t\t\t\t/* translators: %s: Block or block variation name. */\n\t\t\t\t\tlabel: sprintf( __( 'Transform to %s' ), title ),\n\t\t\t\t\ticon: <BlockIcon icon={ icon } />,\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tonBlockTransform( name );\n\t\t\t\t\t\tclose();\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t);\n\n\t\treturn { isLoading: false, commands };\n\t};\n\nconst getQuickActionsCommands = () =>\n\tfunction useQuickActionsCommands() {\n\t\tconst { clientIds, isUngroupable, isGroupable } = useSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst {\n\t\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\t\tisUngroupable: _isUngroupable,\n\t\t\t\t\tisGroupable: _isGroupable,\n\t\t\t\t} = select( blockEditorStore );\n\t\t\t\tconst selectedBlockClientIds = getSelectedBlockClientIds();\n\n\t\t\t\treturn {\n\t\t\t\t\tclientIds: selectedBlockClientIds,\n\t\t\t\t\tisUngroupable: _isUngroupable(),\n\t\t\t\t\tisGroupable: _isGroupable(),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[]\n\t\t);\n\t\tconst {\n\t\t\tcanInsertBlockType,\n\t\t\tgetBlockRootClientId,\n\t\t\tgetBlocksByClientId,\n\t\t\tcanRemoveBlocks,\n\t\t\tgetBlockName,\n\t\t} = useSelect( blockEditorStore );\n\t\tconst { getDefaultBlockName, getGroupingBlockName } =\n\t\t\tuseSelect( blocksStore );\n\n\t\tconst blocks = getBlocksByClientId( clientIds );\n\n\t\tconst {\n\t\t\tremoveBlocks,\n\t\t\treplaceBlocks,\n\t\t\tduplicateBlocks,\n\t\t\tinsertAfterBlock,\n\t\t\tinsertBeforeBlock,\n\t\t\tupdateBlockAttributes,\n\t\t} = useDispatch( blockEditorStore );\n\n\t\tconst onGroup = () => {\n\t\t\tif ( ! blocks.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst groupingBlockName = getGroupingBlockName();\n\n\t\t\t// Activate the `transform` on `core/group` which does the conversion.\n\t\t\tconst newBlocks = switchToBlockType( blocks, groupingBlockName );\n\n\t\t\tif ( ! newBlocks ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\treplaceBlocks( clientIds, newBlocks );\n\t\t};\n\t\tconst onUngroup = () => {\n\t\t\tif ( ! blocks.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst innerBlocks = blocks[ 0 ].innerBlocks;\n\n\t\t\tif ( ! innerBlocks.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\treplaceBlocks( clientIds, innerBlocks );\n\t\t};\n\n\t\tif ( ! clientIds || clientIds.length < 1 ) {\n\t\t\treturn { isLoading: false, commands: [] };\n\t\t}\n\n\t\tconst rootClientId = getBlockRootClientId( clientIds[ 0 ] );\n\t\tconst canInsertDefaultBlock = canInsertBlockType(\n\t\t\tgetDefaultBlockName(),\n\t\t\trootClientId\n\t\t);\n\t\tconst canDuplicate = blocks.every( ( block ) => {\n\t\t\treturn (\n\t\t\t\t!! block &&\n\t\t\t\thasBlockSupport( block.name, 'multiple', true ) &&\n\t\t\t\tcanInsertBlockType( block.name, rootClientId )\n\t\t\t);\n\t\t} );\n\t\tconst canRemove = canRemoveBlocks( clientIds );\n\n\t\tconst canToggleBlockVisibility
|
|
5
|
-
"mappings": ";AAGA,SAAS,IAAI,eAAe;AAC5B;AAAA,EACC;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,OACM;AACP,SAAS,WAAW,mBAAmB;AACvC,SAAS,wBAAwB;AACjC;AAAA,EACC;AAAA,EACA,SAAS;AAAA,EACT,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAKP,OAAO,eAAe;AACtB,SAAS,SAAS,wBAAwB;AAC1C,SAAS,wBAAwB;AA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QAAK,CAAE,OAAO,QAAS;AACtB;AAAA,IACD;AAEA,UAAM,oBAAoB,qBAAqB;AAG/C,UAAM,YAAY,kBAAmB,QAAQ,iBAAkB;AAE/D,QAAK,CAAE,WAAY;AAClB;AAAA,IACD;AACA,kBAAe,WAAW,SAAU;AAAA,EACrC;AACA,QAAM,YAAY,MAAM;AACvB,QAAK,CAAE,OAAO,QAAS;AACtB;AAAA,IACD;AAEA,UAAM,cAAc,OAAQ,CAAE,EAAE;AAEhC,QAAK,CAAE,YAAY,QAAS;AAC3B;AAAA,IACD;AAEA,kBAAe,WAAW,WAAY;AAAA,EACvC;AAEA,MAAK,CAAE,aAAa,UAAU,SAAS,GAAI;AAC1C,WAAO,EAAE,WAAW,OAAO,UAAU,CAAC,EAAE;AAAA,EACzC;AAEA,QAAM,eAAe,qBAAsB,UAAW,CAAE,CAAE;AAC1D,QAAM,wBAAwB;AAAA,IAC7B,oBAAoB;AAAA,IACpB;AAAA,EACD;AACA,QAAM,eAAe,OAAO,MAAO,CAAE,UAAW;AAC/C,WACC,CAAC,CAAE,SACH,gBAAiB,MAAM,MAAM,YAAY,IAAK,KAC9C,mBAAoB,MAAM,MAAM,YAAa;AAAA,EAE/C,CAAE;AACF,QAAM,YAAY,gBAAiB,SAAU;AAE7C,QAAM,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\thasBlockSupport,\n\tstore as blocksStore,\n\tswitchToBlockType,\n\tisTemplatePart,\n} from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useCommandLoader } from '@wordpress/commands';\nimport {\n\tcopy,\n\ttrash as remove,\n\tplus as add,\n\tgroup,\n\tungroup,\n\tseen,\n\tunseen,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport BlockIcon from '../block-icon';\nimport { store as blockEditorStore } from '../../store';\nimport { cleanEmptyObject } from '../../hooks/utils';\n\nconst getTransformCommands = () =>\n\tfunction useTransformCommands() {\n\t\tconst { replaceBlocks, multiSelect } = useDispatch( blockEditorStore );\n\t\tconst {\n\t\t\tblocks,\n\t\t\tclientIds,\n\t\t\tcanRemove,\n\t\t\tpossibleBlockTransformations,\n\t\t\tinvalidSelection,\n\t\t} = useSelect( ( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\tgetBlockTransformItems,\n\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\tgetBlocksByClientId,\n\t\t\t\tcanRemoveBlocks,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst selectedBlockClientIds = getSelectedBlockClientIds();\n\t\t\tconst selectedBlocks = getBlocksByClientId(\n\t\t\t\tselectedBlockClientIds\n\t\t\t);\n\n\t\t\t// selectedBlocks can have `null`s when something tries to call `selectBlock` with an inexistent clientId.\n\t\t\t// These nulls will cause fatal errors down the line.\n\t\t\t// In order to prevent discrepancies between selectedBlockClientIds and selectedBlocks, we effectively treat the entire selection as invalid.\n\t\t\t// @see https://github.com/WordPress/gutenberg/pull/59410#issuecomment-2006304536\n\t\t\tif ( selectedBlocks.filter( ( block ) => ! block ).length > 0 ) {\n\t\t\t\treturn {\n\t\t\t\t\tinvalidSelection: true,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst rootClientId = getBlockRootClientId(\n\t\t\t\tselectedBlockClientIds[ 0 ]\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tblocks: selectedBlocks,\n\t\t\t\tclientIds: selectedBlockClientIds,\n\t\t\t\tpossibleBlockTransformations: getBlockTransformItems(\n\t\t\t\t\tselectedBlocks,\n\t\t\t\t\trootClientId\n\t\t\t\t),\n\t\t\t\tcanRemove: canRemoveBlocks( selectedBlockClientIds ),\n\t\t\t\tinvalidSelection: false,\n\t\t\t};\n\t\t}, [] );\n\n\t\tif ( invalidSelection ) {\n\t\t\treturn {\n\t\t\t\tisLoading: false,\n\t\t\t\tcommands: [],\n\t\t\t};\n\t\t}\n\t\tconst isTemplate = blocks.length === 1 && isTemplatePart( blocks[ 0 ] );\n\n\t\tfunction selectForMultipleBlocks( insertedBlocks ) {\n\t\t\tif ( insertedBlocks.length > 1 ) {\n\t\t\t\tmultiSelect(\n\t\t\t\t\tinsertedBlocks[ 0 ].clientId,\n\t\t\t\t\tinsertedBlocks[ insertedBlocks.length - 1 ].clientId\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Simple block transformation based on the `Block Transforms` API.\n\t\tfunction onBlockTransform( name ) {\n\t\t\tconst newBlocks = switchToBlockType( blocks, name );\n\t\t\treplaceBlocks( clientIds, newBlocks );\n\t\t\tselectForMultipleBlocks( newBlocks );\n\t\t}\n\n\t\t/**\n\t\t * The `isTemplate` check is a stopgap solution here.\n\t\t * Ideally, the Transforms API should handle this\n\t\t * by allowing to exclude blocks from wildcard transformations.\n\t\t */\n\t\tconst hasPossibleBlockTransformations =\n\t\t\t!! possibleBlockTransformations.length && canRemove && ! isTemplate;\n\n\t\tif (\n\t\t\t! clientIds ||\n\t\t\tclientIds.length < 1 ||\n\t\t\t! hasPossibleBlockTransformations\n\t\t) {\n\t\t\treturn { isLoading: false, commands: [] };\n\t\t}\n\n\t\tconst commands = possibleBlockTransformations.map(\n\t\t\t( transformation ) => {\n\t\t\t\tconst { name, title, icon } = transformation;\n\t\t\t\treturn {\n\t\t\t\t\tname:\n\t\t\t\t\t\t'core/block-editor/transform-to-' +\n\t\t\t\t\t\tname.replace( '/', '-' ),\n\t\t\t\t\t/* translators: %s: Block or block variation name. */\n\t\t\t\t\tlabel: sprintf( __( 'Transform to %s' ), title ),\n\t\t\t\t\ticon: <BlockIcon icon={ icon } />,\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tonBlockTransform( name );\n\t\t\t\t\t\tclose();\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t);\n\n\t\treturn { isLoading: false, commands };\n\t};\n\nconst getQuickActionsCommands = () =>\n\tfunction useQuickActionsCommands() {\n\t\tconst { clientIds, isUngroupable, isGroupable } = useSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst {\n\t\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\t\tisUngroupable: _isUngroupable,\n\t\t\t\t\tisGroupable: _isGroupable,\n\t\t\t\t} = select( blockEditorStore );\n\t\t\t\tconst selectedBlockClientIds = getSelectedBlockClientIds();\n\n\t\t\t\treturn {\n\t\t\t\t\tclientIds: selectedBlockClientIds,\n\t\t\t\t\tisUngroupable: _isUngroupable(),\n\t\t\t\t\tisGroupable: _isGroupable(),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[]\n\t\t);\n\t\tconst {\n\t\t\tcanInsertBlockType,\n\t\t\tgetBlockRootClientId,\n\t\t\tgetBlocksByClientId,\n\t\t\tcanRemoveBlocks,\n\t\t\tgetBlockName,\n\t\t} = useSelect( blockEditorStore );\n\t\tconst { getDefaultBlockName, getGroupingBlockName } =\n\t\t\tuseSelect( blocksStore );\n\n\t\tconst blocks = getBlocksByClientId( clientIds );\n\n\t\tconst {\n\t\t\tremoveBlocks,\n\t\t\treplaceBlocks,\n\t\t\tduplicateBlocks,\n\t\t\tinsertAfterBlock,\n\t\t\tinsertBeforeBlock,\n\t\t\tupdateBlockAttributes,\n\t\t} = useDispatch( blockEditorStore );\n\n\t\tconst onGroup = () => {\n\t\t\tif ( ! blocks.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst groupingBlockName = getGroupingBlockName();\n\n\t\t\t// Activate the `transform` on `core/group` which does the conversion.\n\t\t\tconst newBlocks = switchToBlockType( blocks, groupingBlockName );\n\n\t\t\tif ( ! newBlocks ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\treplaceBlocks( clientIds, newBlocks );\n\t\t};\n\t\tconst onUngroup = () => {\n\t\t\tif ( ! blocks.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst innerBlocks = blocks[ 0 ].innerBlocks;\n\n\t\t\tif ( ! innerBlocks.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\treplaceBlocks( clientIds, innerBlocks );\n\t\t};\n\n\t\tif ( ! clientIds || clientIds.length < 1 ) {\n\t\t\treturn { isLoading: false, commands: [] };\n\t\t}\n\n\t\tconst rootClientId = getBlockRootClientId( clientIds[ 0 ] );\n\t\tconst canInsertDefaultBlock = canInsertBlockType(\n\t\t\tgetDefaultBlockName(),\n\t\t\trootClientId\n\t\t);\n\t\tconst canDuplicate = blocks.every( ( block ) => {\n\t\t\treturn (\n\t\t\t\t!! block &&\n\t\t\t\thasBlockSupport( block.name, 'multiple', true ) &&\n\t\t\t\tcanInsertBlockType( block.name, rootClientId )\n\t\t\t);\n\t\t} );\n\t\tconst canRemove = canRemoveBlocks( clientIds );\n\n\t\tconst canToggleBlockVisibility =\n\t\t\tblocks.every( ( { clientId } ) =>\n\t\t\t\thasBlockSupport( getBlockName( clientId ), 'visibility', true )\n\t\t\t) && ! window.__experimentalHideBlocksBasedOnScreenSize;\n\n\t\tconst commands = [];\n\n\t\tif ( canDuplicate ) {\n\t\t\tcommands.push( {\n\t\t\t\tname: 'duplicate',\n\t\t\t\tlabel: __( 'Duplicate' ),\n\t\t\t\tcallback: () => duplicateBlocks( clientIds, true ),\n\t\t\t\ticon: copy,\n\t\t\t} );\n\t\t}\n\n\t\tif ( canInsertDefaultBlock ) {\n\t\t\tcommands.push(\n\t\t\t\t{\n\t\t\t\t\tname: 'add-before',\n\t\t\t\t\tlabel: __( 'Add before' ),\n\t\t\t\t\tcallback: () => {\n\t\t\t\t\t\tconst clientId = Array.isArray( clientIds )\n\t\t\t\t\t\t\t? clientIds[ 0 ]\n\t\t\t\t\t\t\t: clientId;\n\t\t\t\t\t\tinsertBeforeBlock( clientId );\n\t\t\t\t\t},\n\t\t\t\t\ticon: add,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: 'add-after',\n\t\t\t\t\tlabel: __( 'Add after' ),\n\t\t\t\t\tcallback: () => {\n\t\t\t\t\t\tconst clientId = Array.isArray( clientIds )\n\t\t\t\t\t\t\t? clientIds[ clientIds.length - 1 ]\n\t\t\t\t\t\t\t: clientId;\n\t\t\t\t\t\tinsertAfterBlock( clientId );\n\t\t\t\t\t},\n\t\t\t\t\ticon: add,\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\tif ( isGroupable ) {\n\t\t\tcommands.push( {\n\t\t\t\tname: 'Group',\n\t\t\t\tlabel: __( 'Group' ),\n\t\t\t\tcallback: onGroup,\n\t\t\t\ticon: group,\n\t\t\t} );\n\t\t}\n\n\t\tif ( isUngroupable ) {\n\t\t\tcommands.push( {\n\t\t\t\tname: 'ungroup',\n\t\t\t\tlabel: __( 'Ungroup' ),\n\t\t\t\tcallback: onUngroup,\n\t\t\t\ticon: ungroup,\n\t\t\t} );\n\t\t}\n\n\t\tif ( canRemove ) {\n\t\t\tcommands.push( {\n\t\t\t\tname: 'remove',\n\t\t\t\tlabel: __( 'Delete' ),\n\t\t\t\tcallback: () => removeBlocks( clientIds, true ),\n\t\t\t\ticon: remove,\n\t\t\t} );\n\t\t}\n\n\t\tif ( canToggleBlockVisibility ) {\n\t\t\tconst hasHiddenBlock = blocks.some(\n\t\t\t\t( block ) =>\n\t\t\t\t\tblock.attributes.metadata?.blockVisibility === false\n\t\t\t);\n\n\t\t\tcommands.push( {\n\t\t\t\tname: 'core/toggle-block-visibility',\n\t\t\t\tlabel: hasHiddenBlock ? __( 'Show' ) : __( 'Hide' ),\n\t\t\t\tcallback: () => {\n\t\t\t\t\tconst attributesByClientId = Object.fromEntries(\n\t\t\t\t\t\tblocks?.map( ( { clientId, attributes } ) => [\n\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmetadata: cleanEmptyObject( {\n\t\t\t\t\t\t\t\t\t...attributes?.metadata,\n\t\t\t\t\t\t\t\t\tblockVisibility: hasHiddenBlock\n\t\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t\t: false,\n\t\t\t\t\t\t\t\t} ),\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\tupdateBlockAttributes( clientIds, attributesByClientId, {\n\t\t\t\t\t\tuniqueByBlock: true,\n\t\t\t\t\t} );\n\t\t\t\t},\n\t\t\t\ticon: hasHiddenBlock ? seen : unseen,\n\t\t\t} );\n\t\t}\n\n\t\treturn {\n\t\t\tisLoading: false,\n\t\t\tcommands: commands.map( ( command ) => ( {\n\t\t\t\t...command,\n\t\t\t\tname: 'core/block-editor/action-' + command.name,\n\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\tcommand.callback();\n\t\t\t\t\tclose();\n\t\t\t\t},\n\t\t\t} ) ),\n\t\t};\n\t};\n\nexport const useBlockCommands = () => {\n\tuseCommandLoader( {\n\t\tname: 'core/block-editor/blockTransforms',\n\t\thook: getTransformCommands(),\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/block-editor/blockQuickActions',\n\t\thook: getQuickActionsCommands(),\n\t\tcontext: 'block-selection-edit',\n\t} );\n};\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,IAAI,eAAe;AAC5B;AAAA,EACC;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,OACM;AACP,SAAS,WAAW,mBAAmB;AACvC,SAAS,wBAAwB;AACjC;AAAA,EACC;AAAA,EACA,SAAS;AAAA,EACT,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAKP,OAAO,eAAe;AACtB,SAAS,SAAS,wBAAwB;AAC1C,SAAS,wBAAwB;AAmGtB;AAjGX,IAAM,uBAAuB,MAC5B,SAAS,uBAAuB;AAC/B,QAAM,EAAE,eAAe,YAAY,IAAI,YAAa,gBAAiB;AACrE,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,IAAI,UAAW,CAAE,WAAY;AAC5B,UAAM;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AAA,IACX,UAAU,SAAS,IAAK,CAAE,aAAe;AAAA,MACxC,GAAG;AAAA,MACH,MAAM,8BAA8B,QAAQ;AAAA,MAC5C,UAAU,CAAE,EAAE,MAAM,MAAO;AAC1B,gBAAQ,SAAS;AACjB,cAAM;AAAA,MACP;AAAA,IACD,EAAI;AAAA,EACL;AACD;AAEM,IAAM,mBAAmB,MAAM;AACrC,mBAAkB;AAAA,IACjB,MAAM;AAAA,IACN,MAAM,qBAAqB;AAAA,EAC5B,CAAE;AACF,mBAAkB;AAAA,IACjB,MAAM;AAAA,IACN,MAAM,wBAAwB;AAAA,IAC9B,SAAS;AAAA,EACV,CAAE;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,195 +1,85 @@
|
|
|
1
1
|
// packages/block-editor/src/hooks/block-fields/index.js
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
privateApis as blocksPrivateApis,
|
|
4
|
+
getBlockType
|
|
5
|
+
} from "@wordpress/blocks";
|
|
4
6
|
import {
|
|
5
7
|
__experimentalHStack as HStack,
|
|
6
8
|
__experimentalTruncate as Truncate
|
|
7
9
|
} from "@wordpress/components";
|
|
8
|
-
import {
|
|
10
|
+
import { useSelect } from "@wordpress/data";
|
|
9
11
|
import { DataForm } from "@wordpress/dataviews";
|
|
10
12
|
import { useContext, useState, useMemo } from "@wordpress/element";
|
|
13
|
+
import { __ } from "@wordpress/i18n";
|
|
14
|
+
import { store as blockEditorStore } from "../../store/index.mjs";
|
|
11
15
|
import { unlock } from "../../lock-unlock.mjs";
|
|
12
16
|
import BlockIcon from "../../components/block-icon/index.mjs";
|
|
13
17
|
import useBlockDisplayTitle from "../../components/block-title/use-block-display-title.mjs";
|
|
14
18
|
import useBlockDisplayInformation from "../../components/use-block-display-information/index.mjs";
|
|
15
19
|
import FieldsDropdownMenu from "./fields-dropdown-menu.mjs";
|
|
16
20
|
import { PrivateBlockContext } from "../../components/block-list/private-block-context.mjs";
|
|
17
|
-
import
|
|
21
|
+
import InspectorControls from "../../components/inspector-controls/fill.mjs";
|
|
18
22
|
import RichText from "./rich-text/index.mjs";
|
|
19
23
|
import Media from "./media/index.mjs";
|
|
20
24
|
import Link from "./link/index.mjs";
|
|
21
25
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
22
26
|
var { fieldsKey, formKey } = unlock(blocksPrivateApis);
|
|
23
|
-
|
|
24
|
-
richtext: RichText,
|
|
25
|
-
media: Media,
|
|
26
|
-
link: Link
|
|
27
|
-
};
|
|
28
|
-
function createConfiguredControl(config) {
|
|
29
|
-
const { control, ...controlConfig } = config;
|
|
30
|
-
const ControlComponent = CONTROLS[control];
|
|
31
|
-
if (!ControlComponent) {
|
|
32
|
-
throw new Error(`Control type "${control}" not found`);
|
|
33
|
-
}
|
|
27
|
+
function createConfiguredControl(ControlComponent, config = {}) {
|
|
34
28
|
return function ConfiguredControl(props) {
|
|
35
|
-
return /* @__PURE__ */ jsx(ControlComponent, { ...props, config
|
|
29
|
+
return /* @__PURE__ */ jsx(ControlComponent, { ...props, config });
|
|
36
30
|
};
|
|
37
31
|
}
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
type: "image",
|
|
45
|
-
poster: "",
|
|
46
|
-
featuredImage: false,
|
|
47
|
-
link: ""
|
|
48
|
-
};
|
|
49
|
-
const result = {};
|
|
50
|
-
if (fieldDef?.mapping) {
|
|
51
|
-
Object.keys(fieldDef.mapping).forEach((key) => {
|
|
52
|
-
result[key] = value?.[key] ?? defaults[key] ?? "";
|
|
53
|
-
});
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
Object.keys(defaults).forEach((key) => {
|
|
57
|
-
result[key] = value?.[key] ?? defaults[key];
|
|
58
|
-
});
|
|
59
|
-
return result;
|
|
60
|
-
}
|
|
61
|
-
function denormalizeMediaValue(value, fieldDef) {
|
|
62
|
-
if (!fieldDef.mapping) {
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
const result = {};
|
|
66
|
-
Object.entries(fieldDef.mapping).forEach(([key]) => {
|
|
67
|
-
if (key in value) {
|
|
68
|
-
result[key] = value[key];
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
return result;
|
|
72
|
-
}
|
|
73
|
-
function normalizeLinkValue(value, fieldDef) {
|
|
74
|
-
const defaults = {
|
|
75
|
-
url: "",
|
|
76
|
-
rel: "",
|
|
77
|
-
linkTarget: "",
|
|
78
|
-
destination: ""
|
|
79
|
-
};
|
|
80
|
-
const result = {};
|
|
81
|
-
if (fieldDef?.mapping) {
|
|
82
|
-
Object.keys(fieldDef.mapping).forEach((key) => {
|
|
83
|
-
result[key] = value?.[key] ?? defaults[key] ?? "";
|
|
84
|
-
});
|
|
85
|
-
return result;
|
|
86
|
-
}
|
|
87
|
-
Object.keys(defaults).forEach((key) => {
|
|
88
|
-
result[key] = value?.[key] ?? defaults[key];
|
|
89
|
-
});
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
function denormalizeLinkValue(value, fieldDef) {
|
|
93
|
-
if (!fieldDef.mapping) {
|
|
94
|
-
return value;
|
|
95
|
-
}
|
|
96
|
-
const result = {};
|
|
97
|
-
Object.entries(fieldDef.mapping).forEach(([key]) => {
|
|
98
|
-
if (key in value) {
|
|
99
|
-
result[key] = value[key];
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
function BlockFields({ clientId, blockType, attributes, setAttributes }) {
|
|
32
|
+
function BlockFields({
|
|
33
|
+
clientId,
|
|
34
|
+
blockType,
|
|
35
|
+
setAttributes,
|
|
36
|
+
isCollapsed = false
|
|
37
|
+
}) {
|
|
105
38
|
const blockTitle = useBlockDisplayTitle({
|
|
106
39
|
clientId,
|
|
107
40
|
context: "list-view"
|
|
108
41
|
});
|
|
109
42
|
const blockInformation = useBlockDisplayInformation(clientId);
|
|
110
43
|
const blockTypeFields = blockType?.[fieldsKey];
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
44
|
+
const attributes = useSelect(
|
|
45
|
+
(select) => select(blockEditorStore).getBlockAttributes(clientId),
|
|
46
|
+
[clientId]
|
|
47
|
+
);
|
|
48
|
+
const computedForm = useMemo(() => {
|
|
49
|
+
if (!isCollapsed) {
|
|
50
|
+
return blockType?.[formKey];
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
...blockType?.[formKey],
|
|
54
|
+
fields: [blockType?.[formKey]?.fields?.[0]]
|
|
55
|
+
};
|
|
56
|
+
}, [blockType, isCollapsed]);
|
|
57
|
+
const [form, setForm] = useState(computedForm);
|
|
114
58
|
const dataFormFields = useMemo(() => {
|
|
115
59
|
if (!blockTypeFields?.length) {
|
|
116
60
|
return [];
|
|
117
61
|
}
|
|
118
62
|
return blockTypeFields.map((fieldDef) => {
|
|
119
|
-
const ControlComponent = CONTROLS[fieldDef.type];
|
|
120
|
-
const defaultValues = {};
|
|
121
|
-
if (fieldDef.mapping && blockType?.attributes) {
|
|
122
|
-
Object.entries(fieldDef.mapping).forEach(
|
|
123
|
-
([key, attrKey]) => {
|
|
124
|
-
defaultValues[key] = blockType.attributes[attrKey]?.defaultValue ?? void 0;
|
|
125
|
-
}
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
63
|
const field = {
|
|
129
|
-
|
|
130
|
-
label: fieldDef.label,
|
|
131
|
-
type: fieldDef.type,
|
|
132
|
-
// Use the field's type; DataForm will use built-in or custom Edit
|
|
133
|
-
config: { ...fieldDef.args, defaultValues },
|
|
134
|
-
hideLabelFromVision: fieldDef.id === "content",
|
|
135
|
-
// getValue and setValue handle the mapping to block attributes
|
|
136
|
-
getValue: ({ item }) => {
|
|
137
|
-
if (fieldDef.mapping) {
|
|
138
|
-
const mappedValue = {};
|
|
139
|
-
Object.entries(fieldDef.mapping).forEach(
|
|
140
|
-
([key, attrKey]) => {
|
|
141
|
-
mappedValue[key] = item[attrKey];
|
|
142
|
-
}
|
|
143
|
-
);
|
|
144
|
-
if (fieldDef.type === "media") {
|
|
145
|
-
return normalizeMediaValue(mappedValue, fieldDef);
|
|
146
|
-
}
|
|
147
|
-
if (fieldDef.type === "link") {
|
|
148
|
-
return normalizeLinkValue(mappedValue, fieldDef);
|
|
149
|
-
}
|
|
150
|
-
return mappedValue;
|
|
151
|
-
}
|
|
152
|
-
return item[fieldDef.id];
|
|
153
|
-
},
|
|
154
|
-
setValue: ({ item, value }) => {
|
|
155
|
-
if (fieldDef.mapping) {
|
|
156
|
-
let denormalizedValue = value;
|
|
157
|
-
if (fieldDef.type === "media") {
|
|
158
|
-
denormalizedValue = denormalizeMediaValue(
|
|
159
|
-
value,
|
|
160
|
-
fieldDef
|
|
161
|
-
);
|
|
162
|
-
} else if (fieldDef.type === "link") {
|
|
163
|
-
denormalizedValue = denormalizeLinkValue(
|
|
164
|
-
value,
|
|
165
|
-
fieldDef
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
const updates = {};
|
|
169
|
-
Object.entries(fieldDef.mapping).forEach(
|
|
170
|
-
([key, attrKey]) => {
|
|
171
|
-
if (key in denormalizedValue) {
|
|
172
|
-
updates[attrKey] = denormalizedValue[key];
|
|
173
|
-
} else {
|
|
174
|
-
updates[attrKey] = item[attrKey];
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
);
|
|
178
|
-
return updates;
|
|
179
|
-
}
|
|
180
|
-
return { [fieldDef.id]: value };
|
|
181
|
-
}
|
|
64
|
+
...fieldDef
|
|
182
65
|
};
|
|
183
|
-
if (
|
|
184
|
-
field.Edit = createConfiguredControl({
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
66
|
+
if ("string" === typeof fieldDef.Edit && fieldDef.Edit === "rich-text") {
|
|
67
|
+
field.Edit = createConfiguredControl(RichText, {
|
|
68
|
+
clientId
|
|
69
|
+
});
|
|
70
|
+
} else if ("string" === typeof fieldDef.Edit && fieldDef.Edit === "link") {
|
|
71
|
+
field.Edit = createConfiguredControl(Link);
|
|
72
|
+
} else if ("object" === typeof fieldDef.Edit && fieldDef.Edit.control === "media") {
|
|
73
|
+
field.Edit = createConfiguredControl(Media, {
|
|
74
|
+
...fieldDef.Edit
|
|
188
75
|
});
|
|
189
76
|
}
|
|
190
77
|
return field;
|
|
191
78
|
});
|
|
192
|
-
}, [blockTypeFields,
|
|
79
|
+
}, [blockTypeFields, clientId]);
|
|
80
|
+
if (!blockTypeFields?.length) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
193
83
|
const handleToggleField = (fieldId) => {
|
|
194
84
|
setForm((prev) => {
|
|
195
85
|
if (prev.fields?.includes(fieldId)) {
|
|
@@ -204,34 +94,27 @@ function BlockFields({ clientId, blockType, attributes, setAttributes }) {
|
|
|
204
94
|
};
|
|
205
95
|
});
|
|
206
96
|
};
|
|
207
|
-
if (!blockTypeFields?.length) {
|
|
208
|
-
return null;
|
|
209
|
-
}
|
|
210
97
|
return /* @__PURE__ */ jsxs("div", { className: "block-editor-block-fields__container", children: [
|
|
211
98
|
/* @__PURE__ */ jsx("div", { className: "block-editor-block-fields__header", children: /* @__PURE__ */ jsxs(HStack, { spacing: 1, children: [
|
|
212
|
-
/* @__PURE__ */
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
Truncate,
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
visibleFields: form.fields,
|
|
232
|
-
onToggleField: handleToggleField
|
|
233
|
-
}
|
|
234
|
-
)
|
|
99
|
+
isCollapsed && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
100
|
+
/* @__PURE__ */ jsx(
|
|
101
|
+
BlockIcon,
|
|
102
|
+
{
|
|
103
|
+
className: "block-editor-block-fields__header-icon",
|
|
104
|
+
icon: blockInformation?.icon
|
|
105
|
+
}
|
|
106
|
+
),
|
|
107
|
+
/* @__PURE__ */ jsx("h2", { className: "block-editor-block-fields__header-title", children: /* @__PURE__ */ jsx(Truncate, { numberOfLines: 1, children: blockTitle }) }),
|
|
108
|
+
/* @__PURE__ */ jsx(
|
|
109
|
+
FieldsDropdownMenu,
|
|
110
|
+
{
|
|
111
|
+
fields: dataFormFields,
|
|
112
|
+
visibleFields: form.fields,
|
|
113
|
+
onToggleField: handleToggleField
|
|
114
|
+
}
|
|
115
|
+
)
|
|
116
|
+
] }),
|
|
117
|
+
!isCollapsed && /* @__PURE__ */ jsx("h2", { className: "block-editor-block-fields__header-title", children: __("Content") })
|
|
235
118
|
] }) }),
|
|
236
119
|
/* @__PURE__ */ jsx(
|
|
237
120
|
DataForm,
|
|
@@ -244,44 +127,28 @@ function BlockFields({ clientId, blockType, attributes, setAttributes }) {
|
|
|
244
127
|
)
|
|
245
128
|
] });
|
|
246
129
|
}
|
|
247
|
-
|
|
248
|
-
(
|
|
249
|
-
|
|
130
|
+
function hasBlockFieldsSupport(blockName) {
|
|
131
|
+
return !!(window?.__experimentalContentOnlyInspectorFields && getBlockType(blockName)?.[fieldsKey]);
|
|
132
|
+
}
|
|
133
|
+
function BlockFieldsPanel(props) {
|
|
134
|
+
const { blockType, isSelectionWithinCurrentSection } = useContext(PrivateBlockContext);
|
|
135
|
+
return /* @__PURE__ */ jsx(InspectorControls, { group: "content", children: /* @__PURE__ */ jsx(
|
|
136
|
+
BlockFields,
|
|
137
|
+
{
|
|
138
|
+
...props,
|
|
250
139
|
blockType,
|
|
251
|
-
isSelectionWithinCurrentSection
|
|
252
|
-
isSectionBlock,
|
|
253
|
-
blockEditingMode,
|
|
254
|
-
isSelected
|
|
255
|
-
} = useContext(PrivateBlockContext);
|
|
256
|
-
const shouldShowBlockFields = window?.__experimentalContentOnlyInspectorFields;
|
|
257
|
-
const blockTypeFields = blockType?.[fieldsKey];
|
|
258
|
-
if (!shouldShowBlockFields || !blockTypeFields?.length) {
|
|
259
|
-
return /* @__PURE__ */ jsx(BlockEdit, { ...props }, "edit");
|
|
140
|
+
isCollapsed: isSelectionWithinCurrentSection
|
|
260
141
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
blockType
|
|
274
|
-
}
|
|
275
|
-
)
|
|
276
|
-
}
|
|
277
|
-
),
|
|
278
|
-
!isSelectionWithinCurrentSection && isSelected && /* @__PURE__ */ jsx(PrivateInspectorControlsFill, { group: "content", children: /* @__PURE__ */ jsx(BlockFields, { ...props, blockType }) })
|
|
279
|
-
] });
|
|
280
|
-
}
|
|
281
|
-
);
|
|
282
|
-
addFilter(
|
|
283
|
-
"editor.BlockEdit",
|
|
284
|
-
"core/content-only-controls/block-fields",
|
|
285
|
-
withBlockFields
|
|
286
|
-
);
|
|
142
|
+
) });
|
|
143
|
+
}
|
|
144
|
+
var block_fields_default = {
|
|
145
|
+
edit: BlockFieldsPanel,
|
|
146
|
+
hasSupport: hasBlockFieldsSupport,
|
|
147
|
+
attributeKeys: [],
|
|
148
|
+
supportsPatternEditing: true
|
|
149
|
+
};
|
|
150
|
+
export {
|
|
151
|
+
BlockFieldsPanel,
|
|
152
|
+
block_fields_default as default
|
|
153
|
+
};
|
|
287
154
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/block-fields/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\nimport {\n\t__experimentalHStack as HStack,\n\t__experimentalTruncate as Truncate,\n} from '@wordpress/components';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { DataForm } from '@wordpress/dataviews';\nimport { useContext, useState, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport BlockIcon from '../../components/block-icon';\nimport useBlockDisplayTitle from '../../components/block-title/use-block-display-title';\nimport useBlockDisplayInformation from '../../components/use-block-display-information';\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\nimport FieldsDropdownMenu from './fields-dropdown-menu';\nimport { PrivateBlockContext } from '../../components/block-list/private-block-context';\nimport { PrivateInspectorControlsFill } from '../../components/inspector-controls/fill';\n\n// controls\nimport RichText from './rich-text';\nimport Media from './media';\nimport Link from './link';\n\nconst CONTROLS = {\n\trichtext: RichText,\n\tmedia: Media,\n\tlink: Link,\n};\n\n/**\n * Creates a configured control component that wraps a custom control\n * and passes configuration as props.\n *\n * @param {Object} config - The control configuration\n * @param {string} config.control - The control type (key in CONTROLS map)\n * @return {Function} A wrapped control component\n */\nfunction createConfiguredControl( config ) {\n\tconst { control, ...controlConfig } = config;\n\tconst ControlComponent = CONTROLS[ control ];\n\n\tif ( ! ControlComponent ) {\n\t\tthrow new Error( `Control type \"${ control }\" not found` );\n\t}\n\n\treturn function ConfiguredControl( props ) {\n\t\treturn <ControlComponent { ...props } config={ controlConfig } />;\n\t};\n}\n\n/**\n * Normalize a media value to a canonical structure.\n * Only includes properties that are present in the field's mapping (if provided).\n *\n * @param {Object} value - The mapped value from the block attributes (with canonical keys)\n * @param {Object} fieldDef - Optional field definition containing the mapping\n * @return {Object} Normalized media value with canonical properties\n */\nfunction normalizeMediaValue( value, fieldDef ) {\n\tconst defaults = {\n\t\tid: null,\n\t\turl: '',\n\t\tcaption: '',\n\t\talt: '',\n\t\ttype: 'image',\n\t\tposter: '',\n\t\tfeaturedImage: false,\n\t\tlink: '',\n\t};\n\n\tconst result = {};\n\n\t// If there's a mapping, only include properties that are in it\n\tif ( fieldDef?.mapping ) {\n\t\tObject.keys( fieldDef.mapping ).forEach( ( key ) => {\n\t\t\tresult[ key ] = value?.[ key ] ?? defaults[ key ] ?? '';\n\t\t} );\n\t\treturn result;\n\t}\n\n\t// Without mapping, include all default properties\n\tObject.keys( defaults ).forEach( ( key ) => {\n\t\tresult[ key ] = value?.[ key ] ?? defaults[ key ];\n\t} );\n\treturn result;\n}\n\n/**\n * Denormalize a media value from canonical structure back to mapped keys.\n * Only includes properties that are present in the field's mapping.\n *\n * @param {Object} value - The normalized media value\n * @param {Object} fieldDef - The field definition containing the mapping\n * @return {Object} Value with only mapped properties\n */\nfunction denormalizeMediaValue( value, fieldDef ) {\n\tif ( ! fieldDef.mapping ) {\n\t\treturn value;\n\t}\n\n\tconst result = {};\n\tObject.entries( fieldDef.mapping ).forEach( ( [ key ] ) => {\n\t\tif ( key in value ) {\n\t\t\tresult[ key ] = value[ key ];\n\t\t}\n\t} );\n\treturn result;\n}\n\n/**\n * Normalize a link value to a canonical structure.\n * Only includes properties that are present in the field's mapping (if provided).\n *\n * @param {Object} value - The mapped value from the block attributes (with canonical keys)\n * @param {Object} fieldDef - Optional field definition containing the mapping\n * @return {Object} Normalized link value with canonical properties\n */\nfunction normalizeLinkValue( value, fieldDef ) {\n\tconst defaults = {\n\t\turl: '',\n\t\trel: '',\n\t\tlinkTarget: '',\n\t\tdestination: '',\n\t};\n\n\tconst result = {};\n\n\t// If there's a mapping, only include properties that are in it\n\tif ( fieldDef?.mapping ) {\n\t\tObject.keys( fieldDef.mapping ).forEach( ( key ) => {\n\t\t\tresult[ key ] = value?.[ key ] ?? defaults[ key ] ?? '';\n\t\t} );\n\t\treturn result;\n\t}\n\n\t// Without mapping, include all default properties\n\tObject.keys( defaults ).forEach( ( key ) => {\n\t\tresult[ key ] = value?.[ key ] ?? defaults[ key ];\n\t} );\n\treturn result;\n}\n\n/**\n * Denormalize a link value from canonical structure back to mapped keys.\n * Only includes properties that are present in the field's mapping.\n *\n * @param {Object} value - The normalized link value\n * @param {Object} fieldDef - The field definition containing the mapping\n * @return {Object} Value with only mapped properties\n */\nfunction denormalizeLinkValue( value, fieldDef ) {\n\tif ( ! fieldDef.mapping ) {\n\t\treturn value;\n\t}\n\n\tconst result = {};\n\tObject.entries( fieldDef.mapping ).forEach( ( [ key ] ) => {\n\t\tif ( key in value ) {\n\t\t\tresult[ key ] = value[ key ];\n\t\t}\n\t} );\n\treturn result;\n}\n\nfunction BlockFields( { clientId, blockType, attributes, setAttributes } ) {\n\tconst blockTitle = useBlockDisplayTitle( {\n\t\tclientId,\n\t\tcontext: 'list-view',\n\t} );\n\tconst blockInformation = useBlockDisplayInformation( clientId );\n\n\tconst blockTypeFields = blockType?.[ fieldsKey ];\n\n\tconst [ form, setForm ] = useState( () => {\n\t\treturn blockType?.[ formKey ];\n\t} );\n\n\t// Build DataForm fields with proper structure\n\tconst dataFormFields = useMemo( () => {\n\t\tif ( ! blockTypeFields?.length ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn blockTypeFields.map( ( fieldDef ) => {\n\t\t\tconst ControlComponent = CONTROLS[ fieldDef.type ];\n\n\t\t\tconst defaultValues = {};\n\t\t\tif ( fieldDef.mapping && blockType?.attributes ) {\n\t\t\t\tObject.entries( fieldDef.mapping ).forEach(\n\t\t\t\t\t( [ key, attrKey ] ) => {\n\t\t\t\t\t\tdefaultValues[ key ] =\n\t\t\t\t\t\t\tblockType.attributes[ attrKey ]?.defaultValue ??\n\t\t\t\t\t\t\tundefined;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst field = {\n\t\t\t\tid: fieldDef.id,\n\t\t\t\tlabel: fieldDef.label,\n\t\t\t\ttype: fieldDef.type, // Use the field's type; DataForm will use built-in or custom Edit\n\t\t\t\tconfig: { ...fieldDef.args, defaultValues },\n\t\t\t\thideLabelFromVision: fieldDef.id === 'content',\n\t\t\t\t// getValue and setValue handle the mapping to block attributes\n\t\t\t\tgetValue: ( { item } ) => {\n\t\t\t\t\tif ( fieldDef.mapping ) {\n\t\t\t\t\t\t// Extract mapped properties from the block attributes\n\t\t\t\t\t\tconst mappedValue = {};\n\t\t\t\t\t\tObject.entries( fieldDef.mapping ).forEach(\n\t\t\t\t\t\t\t( [ key, attrKey ] ) => {\n\t\t\t\t\t\t\t\tmappedValue[ key ] = item[ attrKey ];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// Normalize to canonical structure based on field type\n\t\t\t\t\t\tif ( fieldDef.type === 'media' ) {\n\t\t\t\t\t\t\treturn normalizeMediaValue( mappedValue, fieldDef );\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif ( fieldDef.type === 'link' ) {\n\t\t\t\t\t\t\treturn normalizeLinkValue( mappedValue, fieldDef );\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// For other types, return as-is\n\t\t\t\t\t\treturn mappedValue;\n\t\t\t\t\t}\n\t\t\t\t\t// For simple id-based fields, use the id as the attribute key\n\t\t\t\t\treturn item[ fieldDef.id ];\n\t\t\t\t},\n\t\t\t\tsetValue: ( { item, value } ) => {\n\t\t\t\t\tif ( fieldDef.mapping ) {\n\t\t\t\t\t\t// Denormalize from canonical structure back to mapped keys\n\t\t\t\t\t\tlet denormalizedValue = value;\n\t\t\t\t\t\tif ( fieldDef.type === 'media' ) {\n\t\t\t\t\t\t\tdenormalizedValue = denormalizeMediaValue(\n\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\tfieldDef\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else if ( fieldDef.type === 'link' ) {\n\t\t\t\t\t\t\tdenormalizedValue = denormalizeLinkValue(\n\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\tfieldDef\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Build an object with all mapped attributes\n\t\t\t\t\t\tconst updates = {};\n\t\t\t\t\t\tObject.entries( fieldDef.mapping ).forEach(\n\t\t\t\t\t\t\t( [ key, attrKey ] ) => {\n\t\t\t\t\t\t\t\t// If key is explicitly in value, use it (even if undefined to allow clearing)\n\t\t\t\t\t\t\t\t// Otherwise, preserve the old value\n\t\t\t\t\t\t\t\tif ( key in denormalizedValue ) {\n\t\t\t\t\t\t\t\t\tupdates[ attrKey ] =\n\t\t\t\t\t\t\t\t\t\tdenormalizedValue[ key ];\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tupdates[ attrKey ] = item[ attrKey ];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn updates;\n\t\t\t\t\t}\n\t\t\t\t\t// For simple id-based fields, use the id as the attribute key\n\t\t\t\t\treturn { [ fieldDef.id ]: value };\n\t\t\t\t},\n\t\t\t};\n\n\t\t\t// Only add custom Edit component if one exists for this type\n\t\t\tif ( ControlComponent ) {\n\t\t\t\t// Use EditConfig pattern: Edit is an object with control type and config props\n\t\t\t\tfield.Edit = createConfiguredControl( {\n\t\t\t\t\tcontrol: fieldDef.type,\n\t\t\t\t\tclientId,\n\t\t\t\t\tfieldDef,\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\treturn field;\n\t\t} );\n\t}, [ blockTypeFields, blockType?.attributes, clientId ] );\n\n\tconst handleToggleField = ( fieldId ) => {\n\t\tsetForm( ( prev ) => {\n\t\t\tif ( prev.fields?.includes( fieldId ) ) {\n\t\t\t\treturn {\n\t\t\t\t\t...prev,\n\t\t\t\t\tfields: prev.fields.filter( ( id ) => id !== fieldId ),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...prev,\n\t\t\t\tfields: [ ...( prev.fields || [] ), fieldId ],\n\t\t\t};\n\t\t} );\n\t};\n\n\tif ( ! blockTypeFields?.length ) {\n\t\t// TODO - we might still want to show a placeholder for blocks with no fields.\n\t\t// for example, a way to select the block.\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<div className=\"block-editor-block-fields__container\">\n\t\t\t<div className=\"block-editor-block-fields__header\">\n\t\t\t\t<HStack spacing={ 1 }>\n\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\tclassName=\"block-editor-block-fields__header-icon\"\n\t\t\t\t\t\ticon={ blockInformation?.icon }\n\t\t\t\t\t/>\n\t\t\t\t\t<Truncate\n\t\t\t\t\t\tclassName=\"block-editor-block-fields__header-title\"\n\t\t\t\t\t\tnumberOfLines={ 1 }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ blockTitle }\n\t\t\t\t\t</Truncate>\n\t\t\t\t\t<FieldsDropdownMenu\n\t\t\t\t\t\tfields={ dataFormFields }\n\t\t\t\t\t\tvisibleFields={ form.fields }\n\t\t\t\t\t\tonToggleField={ handleToggleField }\n\t\t\t\t\t/>\n\t\t\t\t</HStack>\n\t\t\t</div>\n\t\t\t<DataForm\n\t\t\t\tdata={ attributes }\n\t\t\t\tfields={ dataFormFields }\n\t\t\t\tform={ form }\n\t\t\t\tonChange={ setAttributes }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nconst withBlockFields = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst {\n\t\t\tblockType,\n\t\t\tisSelectionWithinCurrentSection,\n\t\t\tisSectionBlock,\n\t\t\tblockEditingMode,\n\t\t\tisSelected,\n\t\t} = useContext( PrivateBlockContext );\n\n\t\tconst shouldShowBlockFields =\n\t\t\twindow?.__experimentalContentOnlyInspectorFields;\n\t\tconst blockTypeFields = blockType?.[ fieldsKey ];\n\n\t\tif ( ! shouldShowBlockFields || ! blockTypeFields?.length ) {\n\t\t\treturn <BlockEdit key=\"edit\" { ...props } />;\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit key=\"edit\" { ...props } />\n\t\t\t\t{\n\t\t\t\t\t// Display the controls of all inner blocks for section/pattern editing.\n\t\t\t\t\tisSelectionWithinCurrentSection &&\n\t\t\t\t\t\t( isSectionBlock ||\n\t\t\t\t\t\t\tblockEditingMode === 'contentOnly' ) && (\n\t\t\t\t\t\t\t<PrivateInspectorControlsFill\n\t\t\t\t\t\t\t\tgroup=\"content\"\n\t\t\t\t\t\t\t\tforceDisplayControls\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<BlockFields\n\t\t\t\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\t\t\t\tblockType={ blockType }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</PrivateInspectorControlsFill>\n\t\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\t{ ! isSelectionWithinCurrentSection && isSelected && (\n\t\t\t\t\t<PrivateInspectorControlsFill group=\"content\">\n\t\t\t\t\t\t<BlockFields { ...props } blockType={ blockType } />\n\t\t\t\t\t</PrivateInspectorControlsFill>\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t}\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/content-only-controls/block-fields',\n\twithBlockFields\n);\n"],
|
|
5
|
-
"mappings": ";AAGA
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as blocksPrivateApis,\n\tgetBlockType,\n} from '@wordpress/blocks';\nimport {\n\t__experimentalHStack as HStack,\n\t__experimentalTruncate as Truncate,\n} from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { DataForm } from '@wordpress/dataviews';\nimport { useContext, useState, useMemo } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\nimport BlockIcon from '../../components/block-icon';\nimport useBlockDisplayTitle from '../../components/block-title/use-block-display-title';\nimport useBlockDisplayInformation from '../../components/use-block-display-information';\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\nimport FieldsDropdownMenu from './fields-dropdown-menu';\nimport { PrivateBlockContext } from '../../components/block-list/private-block-context';\nimport InspectorControls from '../../components/inspector-controls/fill';\n\n// controls\nimport RichText from './rich-text';\nimport Media from './media';\nimport Link from './link';\n\n/**\n * Creates a configured control component that wraps a custom control\n * and passes configuration as props.\n *\n * @param {Component} ControlComponent The React component for the control.\n * @param {Object} config The control configuration passed as a prop.\n *\n * @return {Function} A wrapped control component\n */\nfunction createConfiguredControl( ControlComponent, config = {} ) {\n\treturn function ConfiguredControl( props ) {\n\t\treturn <ControlComponent { ...props } config={ config } />;\n\t};\n}\n\n/**\n * Component that renders a DataForm for a single block's attributes\n * @param {Object} props\n * @param {string} props.clientId The clientId of the block.\n * @param {Object} props.blockType The blockType definition.\n * @param {Function} props.setAttributes Action to set the block's attributes.\n * @param {boolean} props.isCollapsed Whether the DataForm is rendered as 'collapsed' with only the first field\n * displayed by default. When collapsed a dropdown is displayed to allow\n * displaying additional fields. The block's title is displayed as the title.\n * The collapsed mode is often used when multiple BlockForms are shown together.\n */\nfunction BlockFields( {\n\tclientId,\n\tblockType,\n\tsetAttributes,\n\tisCollapsed = false,\n} ) {\n\tconst blockTitle = useBlockDisplayTitle( {\n\t\tclientId,\n\t\tcontext: 'list-view',\n\t} );\n\tconst blockInformation = useBlockDisplayInformation( clientId );\n\n\tconst blockTypeFields = blockType?.[ fieldsKey ];\n\n\tconst attributes = useSelect(\n\t\t( select ) => select( blockEditorStore ).getBlockAttributes( clientId ),\n\t\t[ clientId ]\n\t);\n\n\tconst computedForm = useMemo( () => {\n\t\tif ( ! isCollapsed ) {\n\t\t\treturn blockType?.[ formKey ];\n\t\t}\n\n\t\t// For a collapsed form only show the first field by default.\n\t\treturn {\n\t\t\t...blockType?.[ formKey ],\n\t\t\tfields: [ blockType?.[ formKey ]?.fields?.[ 0 ] ],\n\t\t};\n\t}, [ blockType, isCollapsed ] );\n\n\tconst [ form, setForm ] = useState( computedForm );\n\n\t// Build DataForm fields with proper structure\n\tconst dataFormFields = useMemo( () => {\n\t\tif ( ! blockTypeFields?.length ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn blockTypeFields.map( ( fieldDef ) => {\n\t\t\tconst field = {\n\t\t\t\t...fieldDef,\n\t\t\t};\n\n\t\t\t// These should be custom Edit components, not replaced here.\n\t\t\t//\n\t\t\t// - rich-text control: it needs clientId\n\t\t\t// - link control: does not need anything extra\n\t\t\t// - media control: needs the Edit config\n\t\t\tif (\n\t\t\t\t'string' === typeof fieldDef.Edit &&\n\t\t\t\tfieldDef.Edit === 'rich-text'\n\t\t\t) {\n\t\t\t\tfield.Edit = createConfiguredControl( RichText, {\n\t\t\t\t\tclientId,\n\t\t\t\t} );\n\t\t\t} else if (\n\t\t\t\t'string' === typeof fieldDef.Edit &&\n\t\t\t\tfieldDef.Edit === 'link'\n\t\t\t) {\n\t\t\t\tfield.Edit = createConfiguredControl( Link );\n\t\t\t} else if (\n\t\t\t\t'object' === typeof fieldDef.Edit &&\n\t\t\t\tfieldDef.Edit.control === 'media'\n\t\t\t) {\n\t\t\t\tfield.Edit = createConfiguredControl( Media, {\n\t\t\t\t\t...fieldDef.Edit,\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\treturn field;\n\t\t} );\n\t}, [ blockTypeFields, clientId ] );\n\n\tif ( ! blockTypeFields?.length ) {\n\t\t// TODO - we might still want to show a placeholder for blocks with no fields.\n\t\t// for example, a way to select the block.\n\t\treturn null;\n\t}\n\n\tconst handleToggleField = ( fieldId ) => {\n\t\tsetForm( ( prev ) => {\n\t\t\tif ( prev.fields?.includes( fieldId ) ) {\n\t\t\t\treturn {\n\t\t\t\t\t...prev,\n\t\t\t\t\tfields: prev.fields.filter( ( id ) => id !== fieldId ),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...prev,\n\t\t\t\tfields: [ ...( prev.fields || [] ), fieldId ],\n\t\t\t};\n\t\t} );\n\t};\n\n\treturn (\n\t\t<div className=\"block-editor-block-fields__container\">\n\t\t\t<div className=\"block-editor-block-fields__header\">\n\t\t\t\t<HStack spacing={ 1 }>\n\t\t\t\t\t{ isCollapsed && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\tclassName=\"block-editor-block-fields__header-icon\"\n\t\t\t\t\t\t\t\ticon={ blockInformation?.icon }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<h2 className=\"block-editor-block-fields__header-title\">\n\t\t\t\t\t\t\t\t<Truncate numberOfLines={ 1 }>\n\t\t\t\t\t\t\t\t\t{ blockTitle }\n\t\t\t\t\t\t\t\t</Truncate>\n\t\t\t\t\t\t\t</h2>\n\t\t\t\t\t\t\t<FieldsDropdownMenu\n\t\t\t\t\t\t\t\tfields={ dataFormFields }\n\t\t\t\t\t\t\t\tvisibleFields={ form.fields }\n\t\t\t\t\t\t\t\tonToggleField={ handleToggleField }\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\t{ ! isCollapsed && (\n\t\t\t\t\t\t<h2 className=\"block-editor-block-fields__header-title\">\n\t\t\t\t\t\t\t{ __( 'Content' ) }\n\t\t\t\t\t\t</h2>\n\t\t\t\t\t) }\n\t\t\t\t</HStack>\n\t\t\t</div>\n\t\t\t<DataForm\n\t\t\t\tdata={ attributes }\n\t\t\t\tfields={ dataFormFields }\n\t\t\t\tform={ form }\n\t\t\t\tonChange={ setAttributes }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nfunction hasBlockFieldsSupport( blockName ) {\n\treturn !! (\n\t\twindow?.__experimentalContentOnlyInspectorFields &&\n\t\tgetBlockType( blockName )?.[ fieldsKey ]\n\t);\n}\n\nexport function BlockFieldsPanel( props ) {\n\tconst { blockType, isSelectionWithinCurrentSection } =\n\t\tuseContext( PrivateBlockContext );\n\n\treturn (\n\t\t<InspectorControls group=\"content\">\n\t\t\t<BlockFields\n\t\t\t\t{ ...props }\n\t\t\t\tblockType={ blockType }\n\t\t\t\tisCollapsed={ isSelectionWithinCurrentSection }\n\t\t\t/>\n\t\t</InspectorControls>\n\t);\n}\n\n/**\n * Export block support definition.\n */\nexport default {\n\tedit: BlockFieldsPanel,\n\thasS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AAO,SAAU,GACf;AAAA,qBACD,iCACC;AAAA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,MAAO,kBAAkB;AAAA;AAAA,QAC1B;AAAA,QACA,oBAAC,QAAG,WAAU,2CACb,8BAAC,YAAS,eAAgB,GACvB,sBACH,GACD;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,QAAS;AAAA,YACT,eAAgB,KAAK;AAAA,YACrB,eAAgB;AAAA;AAAA,QACjB;AAAA,SACD;AAAA,MAEC,CAAE,eACH,oBAAC,QAAG,WAAU,2CACX,aAAI,SAAU,GACjB;AAAA,OAEF,GACD;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,MAAO;AAAA,QACP,QAAS;AAAA,QACT;AAAA,QACA,UAAW;AAAA;AAAA,IACZ;AAAA,KACD;AAEF;AAEA,SAAS,sBAAuB,WAAY;AAC3C,SAAO,CAAC,EACP,QAAQ,4CACR,aAAc,SAAU,IAAK,SAAU;AAEzC;AAEO,SAAS,iBAAkB,OAAQ;AACzC,QAAM,EAAE,WAAW,gCAAgC,IAClD,WAAY,mBAAoB;AAEjC,SACC,oBAAC,qBAAkB,OAAM,WACxB;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACL;AAAA,MACA,aAAc;AAAA;AAAA,EACf,GACD;AAEF;AAKA,IAAO,uBAAQ;AAAA,EACd,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,eAAe,CAAC;AAAA,EAChB,wBAAwB;AACzB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -42,16 +42,11 @@ function getUpdatedLinkAttributes({
|
|
|
42
42
|
rel: updatedRel || void 0
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
function Link({ data, field, onChange
|
|
45
|
+
function Link({ data, field, onChange }) {
|
|
46
46
|
const [isLinkControlOpen, setIsLinkControlOpen] = useState(false);
|
|
47
47
|
const { popoverProps } = useInspectorPopoverPlacement({
|
|
48
48
|
isControl: true
|
|
49
49
|
});
|
|
50
|
-
const { fieldDef } = config;
|
|
51
|
-
const updateAttributes = (newValue) => {
|
|
52
|
-
const mappedChanges = field.setValue({ item: data, value: newValue });
|
|
53
|
-
onChange(mappedChanges);
|
|
54
|
-
};
|
|
55
50
|
const value = field.getValue({ item: data });
|
|
56
51
|
const url = value?.url;
|
|
57
52
|
const rel = value?.rel || "";
|
|
@@ -115,34 +110,20 @@ function Link({ data, field, onChange, config = {} }) {
|
|
|
115
110
|
rel,
|
|
116
111
|
...newValues
|
|
117
112
|
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
} else if (key === "rel") {
|
|
125
|
-
updateValue[key] = updatedAttrs.rel;
|
|
126
|
-
} else if (key === "target" || key === "linkTarget") {
|
|
127
|
-
updateValue[key] = updatedAttrs.linkTarget;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
updateAttributes(updateValue);
|
|
113
|
+
onChange(
|
|
114
|
+
field.setValue({
|
|
115
|
+
item: data,
|
|
116
|
+
value: updatedAttrs
|
|
117
|
+
})
|
|
118
|
+
);
|
|
133
119
|
},
|
|
134
120
|
onRemove: () => {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
updateAttributes(removeValue);
|
|
121
|
+
onChange(
|
|
122
|
+
field.setValue({
|
|
123
|
+
item: data,
|
|
124
|
+
value: {}
|
|
125
|
+
})
|
|
126
|
+
);
|
|
146
127
|
}
|
|
147
128
|
}
|
|
148
129
|
)
|