@wordpress/patterns 2.2.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/build/components/pattern-convert-button.js +4 -1
- package/build/components/pattern-convert-button.js.map +1 -1
- package/build/components/pattern-overrides-block-controls.js +1 -1
- package/build/components/pattern-overrides-block-controls.js.map +1 -1
- package/build/components/pattern-overrides-controls.js +6 -6
- package/build/components/pattern-overrides-controls.js.map +1 -1
- package/build/components/patterns-manage-button.js +9 -2
- package/build/components/patterns-manage-button.js.map +1 -1
- package/build/components/reset-overrides-control.js +1 -3
- package/build/components/reset-overrides-control.js.map +1 -1
- package/build-module/components/pattern-convert-button.js +4 -1
- package/build-module/components/pattern-convert-button.js.map +1 -1
- package/build-module/components/pattern-overrides-block-controls.js +1 -1
- package/build-module/components/pattern-overrides-block-controls.js.map +1 -1
- package/build-module/components/pattern-overrides-controls.js +6 -6
- package/build-module/components/pattern-overrides-controls.js.map +1 -1
- package/build-module/components/patterns-manage-button.js +9 -2
- package/build-module/components/patterns-manage-button.js.map +1 -1
- package/build-module/components/reset-overrides-control.js +2 -4
- package/build-module/components/reset-overrides-control.js.map +1 -1
- package/package.json +16 -16
- package/src/components/pattern-convert-button.js +4 -1
- package/src/components/pattern-overrides-block-controls.js +1 -1
- package/src/components/pattern-overrides-controls.js +15 -12
- package/src/components/patterns-manage-button.js +9 -6
- package/src/components/reset-overrides-control.js +4 -8
package/CHANGELOG.md
CHANGED
|
@@ -78,7 +78,10 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
78
78
|
(0, _blocks.hasBlockSupport)(block.name, 'reusable', true)) &&
|
|
79
79
|
// Hide when current doesn't have permission to do that.
|
|
80
80
|
// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.
|
|
81
|
-
!!canUser('create',
|
|
81
|
+
!!canUser('create', {
|
|
82
|
+
kind: 'postType',
|
|
83
|
+
name: 'wp_block'
|
|
84
|
+
});
|
|
82
85
|
return _canConvert;
|
|
83
86
|
}, [clientIds, rootClientId]);
|
|
84
87
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_blocks","require","_blockEditor","_element","_components","_icons","_data","_coreData","_i18n","_notices","_store","_createPatternModal","_interopRequireDefault","_lockUnlock","_constants","_jsxRuntime","PatternConvertButton","clientIds","rootClientId","closeBlockSettingsMenu","createSuccessNotice","useDispatch","noticesStore","replaceBlocks","blockEditorStore","setEditingPattern","unlock","patternsStore","isModalOpen","setIsModalOpen","useState","canConvert","useSelect","select","_getBlocksByClientId","canUser","coreStore","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","rootId","length","undefined","blocks","isReusable","isReusableBlock","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","hasBlockSupport","name","getContent","useCallback","serialize","handleSuccess","pattern","wp_pattern_sync_status","PATTERN_SYNC_TYPES","unsynced","newBlock","createBlock","id","clientId","sprintf","__","title","raw","type","jsxs","Fragment","children","jsx","MenuItem","icon","symbol","onClick","default","content","onSuccess","onError","onClose"],"sources":["@wordpress/patterns/src/components/pattern-convert-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\thasBlockSupport,\n\tisReusableBlock,\n\tcreateBlock,\n\tserialize,\n} from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useState, useCallback } from '@wordpress/element';\nimport { MenuItem } from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CreatePatternModal from './create-pattern-modal';\nimport { unlock } from '../lock-unlock';\nimport { PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Menu control to convert block(s) to a pattern block.\n *\n * @param {Object} props Component props.\n * @param {string[]} props.clientIds Client ids of selected blocks.\n * @param {string} props.rootClientId ID of the currently selected top-level block.\n * @param {()=>void} props.closeBlockSettingsMenu Callback to close the block settings menu dropdown.\n * @return {import('react').ComponentType} The menu control or null.\n */\nexport default function PatternConvertButton( {\n\tclientIds,\n\trootClientId,\n\tcloseBlockSettingsMenu,\n} ) {\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst { replaceBlocks } = useDispatch( blockEditorStore );\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { setEditingPattern } = unlock( useDispatch( patternsStore ) );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst canConvert = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst {\n\t\t\t\tgetBlocksByClientId,\n\t\t\t\tcanInsertBlockType,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst rootId =\n\t\t\t\trootClientId ||\n\t\t\t\t( clientIds.length > 0\n\t\t\t\t\t? getBlockRootClientId( clientIds[ 0 ] )\n\t\t\t\t\t: undefined );\n\n\t\t\tconst blocks = getBlocksByClientId( clientIds ) ?? [];\n\n\t\t\tconst isReusable =\n\t\t\t\tblocks.length === 1 &&\n\t\t\t\tblocks[ 0 ] &&\n\t\t\t\tisReusableBlock( blocks[ 0 ] ) &&\n\t\t\t\t!! select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_block',\n\t\t\t\t\tblocks[ 0 ].attributes.ref\n\t\t\t\t);\n\n\t\t\tconst _canConvert =\n\t\t\t\t// Hide when this is already a synced pattern.\n\t\t\t\t! isReusable &&\n\t\t\t\t// Hide when patterns are disabled.\n\t\t\t\tcanInsertBlockType( 'core/block', rootId ) &&\n\t\t\t\tblocks.every(\n\t\t\t\t\t( block ) =>\n\t\t\t\t\t\t// Guard against the case where a regular block has *just* been converted.\n\t\t\t\t\t\t!! block &&\n\t\t\t\t\t\t// Hide on invalid blocks.\n\t\t\t\t\t\tblock.isValid &&\n\t\t\t\t\t\t// Hide when block doesn't support being made into a pattern.\n\t\t\t\t\t\thasBlockSupport( block.name, 'reusable', true )\n\t\t\t\t) &&\n\t\t\t\t// Hide when current doesn't have permission to do that.\n\t\t\t\t// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.\n\t\t\t\t!! canUser( 'create', 'blocks' );\n\n\t\t\treturn _canConvert;\n\t\t},\n\t\t[ clientIds, rootClientId ]\n\t);\n\tconst { getBlocksByClientId } = useSelect( blockEditorStore );\n\tconst getContent = useCallback(\n\t\t() => serialize( getBlocksByClientId( clientIds ) ),\n\t\t[ getBlocksByClientId, clientIds ]\n\t);\n\n\tif ( ! canConvert ) {\n\t\treturn null;\n\t}\n\n\tconst handleSuccess = ( { pattern } ) => {\n\t\tif ( pattern.wp_pattern_sync_status !== PATTERN_SYNC_TYPES.unsynced ) {\n\t\t\tconst newBlock = createBlock( 'core/block', {\n\t\t\t\tref: pattern.id,\n\t\t\t} );\n\n\t\t\treplaceBlocks( clientIds, newBlock );\n\t\t\tsetEditingPattern( newBlock.clientId, true );\n\t\t\tcloseBlockSettingsMenu();\n\t\t}\n\n\t\tcreateSuccessNotice(\n\t\t\tpattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Unsynced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Synced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t ),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'convert-to-pattern-success',\n\t\t\t}\n\t\t);\n\t\tsetIsModalOpen( false );\n\t};\n\treturn (\n\t\t<>\n\t\t\t<MenuItem\n\t\t\t\ticon={ symbol }\n\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\taria-expanded={ isModalOpen }\n\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t>\n\t\t\t\t{ __( 'Create pattern' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<CreatePatternModal\n\t\t\t\t\tcontent={ getContent }\n\t\t\t\t\tonSuccess={ ( pattern ) => {\n\t\t\t\t\t\thandleSuccess( pattern );\n\t\t\t\t\t} }\n\t\t\t\t\tonError={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AAMA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AACA,IAAAQ,QAAA,GAAAR,OAAA;AAIA,IAAAS,MAAA,GAAAT,OAAA;AACA,IAAAU,mBAAA,GAAAC,sBAAA,CAAAX,OAAA;AACA,IAAAY,WAAA,GAAAZ,OAAA;AACA,IAAAa,UAAA,GAAAb,OAAA;AAAkD,IAAAc,WAAA,GAAAd,OAAA;AAvBlD;AACA;AACA;;AAeA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACe,SAASe,oBAAoBA,CAAE;EAC7CC,SAAS;EACTC,YAAY;EACZC;AACD,CAAC,EAAG;EACH,MAAM;IAAEC;EAAoB,CAAC,GAAG,IAAAC,iBAAW,E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AE,UAAU;MAChBN,EAAE,EAAE;IACL,CACD,CAAC;IACDpC,cAAc,CAAE,KAAM,CAAC;EACxB,CAAC;EACD,oBACC,IAAAd,WAAA,CAAAyD,IAAA,EAAAzD,WAAA,CAAA0D,QAAA;IAAAC,QAAA,gBACC,IAAA3D,WAAA,CAAA4D,GAAA,EAACvE,WAAA,CAAAwE,QAAQ;MACRC,IAAI,EAAGC,aAAQ;MACfC,OAAO,EAAGA,CAAA,KAAMlD,cAAc,CAAE,IAAK,CAAG;MACxC,iBAAgBD,WAAa;MAC7B,iBAAc,QAAQ;MAAA8C,QAAA,EAEpB,IAAAN,QAAE,EAAE,gBAAiB;IAAC,CACf,CAAC,EACTxC,WAAW,iBACZ,IAAAb,WAAA,CAAA4D,GAAA,EAAChE,mBAAA,CAAAqE,OAAkB;MAClBC,OAAO,EAAG1B,UAAY;MACtB2B,SAAS,EAAKvB,OAAO,IAAM;QAC1BD,aAAa,CAAEC,OAAQ,CAAC;MACzB,CAAG;MACHwB,OAAO,EAAGA,CAAA,KAAM;QACftD,cAAc,CAAE,KAAM,CAAC;MACxB,CAAG;MACHuD,OAAO,EAAGA,CAAA,KAAM;QACfvD,cAAc,CAAE,KAAM,CAAC;MACxB;IAAG,CACH,CACD;EAAA,CACA,CAAC;AAEL","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_blocks","require","_blockEditor","_element","_components","_icons","_data","_coreData","_i18n","_notices","_store","_createPatternModal","_interopRequireDefault","_lockUnlock","_constants","_jsxRuntime","PatternConvertButton","clientIds","rootClientId","closeBlockSettingsMenu","createSuccessNotice","useDispatch","noticesStore","replaceBlocks","blockEditorStore","setEditingPattern","unlock","patternsStore","isModalOpen","setIsModalOpen","useState","canConvert","useSelect","select","_getBlocksByClientId","canUser","coreStore","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","rootId","length","undefined","blocks","isReusable","isReusableBlock","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","hasBlockSupport","name","kind","getContent","useCallback","serialize","handleSuccess","pattern","wp_pattern_sync_status","PATTERN_SYNC_TYPES","unsynced","newBlock","createBlock","id","clientId","sprintf","__","title","raw","type","jsxs","Fragment","children","jsx","MenuItem","icon","symbol","onClick","default","content","onSuccess","onError","onClose"],"sources":["@wordpress/patterns/src/components/pattern-convert-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\thasBlockSupport,\n\tisReusableBlock,\n\tcreateBlock,\n\tserialize,\n} from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useState, useCallback } from '@wordpress/element';\nimport { MenuItem } from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CreatePatternModal from './create-pattern-modal';\nimport { unlock } from '../lock-unlock';\nimport { PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Menu control to convert block(s) to a pattern block.\n *\n * @param {Object} props Component props.\n * @param {string[]} props.clientIds Client ids of selected blocks.\n * @param {string} props.rootClientId ID of the currently selected top-level block.\n * @param {()=>void} props.closeBlockSettingsMenu Callback to close the block settings menu dropdown.\n * @return {import('react').ComponentType} The menu control or null.\n */\nexport default function PatternConvertButton( {\n\tclientIds,\n\trootClientId,\n\tcloseBlockSettingsMenu,\n} ) {\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst { replaceBlocks } = useDispatch( blockEditorStore );\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { setEditingPattern } = unlock( useDispatch( patternsStore ) );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst canConvert = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst {\n\t\t\t\tgetBlocksByClientId,\n\t\t\t\tcanInsertBlockType,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst rootId =\n\t\t\t\trootClientId ||\n\t\t\t\t( clientIds.length > 0\n\t\t\t\t\t? getBlockRootClientId( clientIds[ 0 ] )\n\t\t\t\t\t: undefined );\n\n\t\t\tconst blocks = getBlocksByClientId( clientIds ) ?? [];\n\n\t\t\tconst isReusable =\n\t\t\t\tblocks.length === 1 &&\n\t\t\t\tblocks[ 0 ] &&\n\t\t\t\tisReusableBlock( blocks[ 0 ] ) &&\n\t\t\t\t!! select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_block',\n\t\t\t\t\tblocks[ 0 ].attributes.ref\n\t\t\t\t);\n\n\t\t\tconst _canConvert =\n\t\t\t\t// Hide when this is already a synced pattern.\n\t\t\t\t! isReusable &&\n\t\t\t\t// Hide when patterns are disabled.\n\t\t\t\tcanInsertBlockType( 'core/block', rootId ) &&\n\t\t\t\tblocks.every(\n\t\t\t\t\t( block ) =>\n\t\t\t\t\t\t// Guard against the case where a regular block has *just* been converted.\n\t\t\t\t\t\t!! block &&\n\t\t\t\t\t\t// Hide on invalid blocks.\n\t\t\t\t\t\tblock.isValid &&\n\t\t\t\t\t\t// Hide when block doesn't support being made into a pattern.\n\t\t\t\t\t\thasBlockSupport( block.name, 'reusable', true )\n\t\t\t\t) &&\n\t\t\t\t// Hide when current doesn't have permission to do that.\n\t\t\t\t// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.\n\t\t\t\t!! canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_block',\n\t\t\t\t} );\n\n\t\t\treturn _canConvert;\n\t\t},\n\t\t[ clientIds, rootClientId ]\n\t);\n\tconst { getBlocksByClientId } = useSelect( blockEditorStore );\n\tconst getContent = useCallback(\n\t\t() => serialize( getBlocksByClientId( clientIds ) ),\n\t\t[ getBlocksByClientId, clientIds ]\n\t);\n\n\tif ( ! canConvert ) {\n\t\treturn null;\n\t}\n\n\tconst handleSuccess = ( { pattern } ) => {\n\t\tif ( pattern.wp_pattern_sync_status !== PATTERN_SYNC_TYPES.unsynced ) {\n\t\t\tconst newBlock = createBlock( 'core/block', {\n\t\t\t\tref: pattern.id,\n\t\t\t} );\n\n\t\t\treplaceBlocks( clientIds, newBlock );\n\t\t\tsetEditingPattern( newBlock.clientId, true );\n\t\t\tcloseBlockSettingsMenu();\n\t\t}\n\n\t\tcreateSuccessNotice(\n\t\t\tpattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Unsynced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Synced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t ),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'convert-to-pattern-success',\n\t\t\t}\n\t\t);\n\t\tsetIsModalOpen( false );\n\t};\n\treturn (\n\t\t<>\n\t\t\t<MenuItem\n\t\t\t\ticon={ symbol }\n\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\taria-expanded={ isModalOpen }\n\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t>\n\t\t\t\t{ __( 'Create pattern' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<CreatePatternModal\n\t\t\t\t\tcontent={ getContent }\n\t\t\t\t\tonSuccess={ ( pattern ) => {\n\t\t\t\t\t\thandleSuccess( pattern );\n\t\t\t\t\t} }\n\t\t\t\t\tonError={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\t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,CACf,CAAC,EACTzC,WAAW,iBACZ,IAAAb,WAAA,CAAA6D,GAAA,EAACjE,mBAAA,CAAAsE,OAAkB;MAClBC,OAAO,EAAG1B,UAAY;MACtB2B,SAAS,EAAKvB,OAAO,IAAM;QAC1BD,aAAa,CAAEC,OAAQ,CAAC;MACzB,CAAG;MACHwB,OAAO,EAAGA,CAAA,KAAM;QACfvD,cAAc,CAAE,KAAM,CAAC;MACxB,CAAG;MACHwD,OAAO,EAAGA,CAAA,KAAM;QACfxD,cAAc,CAAE,KAAM,CAAC;MACxB;IAAG,CACH,CACD;EAAA,CACA,CAAC;AAEL","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_i18n","_components","_blocks","_data","_icons","_blockEditor","_lockUnlock","_constants","_jsxRuntime","useBlockDisplayTitle","unlock","blockEditorPrivateApis","PatternOverridesToolbarIndicator","clientIds","isSingleBlockSelected","length","icon","firstBlockName","useSelect","select","getBlockAttributes","getBlockNamesByClientId","blockEditorStore","getBlockType","getActiveBlockVariation","blocksStore","blockTypeNames","_firstBlockTypeName","firstBlockType","_icon","match","isSelectionOfSameType","Set","size","copy","metadata","name","firstBlockTitle","clientId","maximumLength","blockDescription","sprintf","__","toLowerCase","descriptionId","useId","jsx","ToolbarItem","children","toggleProps","DropdownMenu","className","label","popoverProps","placement","Fragment","BlockIcon","showColors","
|
|
1
|
+
{"version":3,"names":["_element","require","_i18n","_components","_blocks","_data","_icons","_blockEditor","_lockUnlock","_constants","_jsxRuntime","useBlockDisplayTitle","unlock","blockEditorPrivateApis","PatternOverridesToolbarIndicator","clientIds","isSingleBlockSelected","length","icon","firstBlockName","useSelect","select","getBlockAttributes","getBlockNamesByClientId","blockEditorStore","getBlockType","getActiveBlockVariation","blocksStore","blockTypeNames","_firstBlockTypeName","firstBlockType","_icon","match","isSelectionOfSameType","Set","size","copy","metadata","name","firstBlockTitle","clientId","maximumLength","blockDescription","sprintf","__","toLowerCase","descriptionId","useId","jsx","ToolbarItem","children","toggleProps","DropdownMenu","className","label","popoverProps","placement","Fragment","BlockIcon","showColors","description","menuProps","orientation","__experimentalText","id","PatternOverridesBlockControls","hasPatternOverrides","hasParentPattern","getSelectedBlockClientIds","getBlockParentsByBlockName","selectedClientIds","_hasPatternOverrides","every","_getBlockAttributes$m","Object","values","bindings","some","binding","source","PATTERN_OVERRIDES_BINDING_SOURCE","_hasParentPattern","BlockControls","group"],"sources":["@wordpress/patterns/src/components/pattern-overrides-block-controls.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useId } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tDropdownMenu,\n\tToolbarItem,\n\t__experimentalText as Text,\n} from '@wordpress/components';\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\nimport { copy } from '@wordpress/icons';\nimport {\n\tstore as blockEditorStore,\n\tBlockIcon,\n\tprivateApis as blockEditorPrivateApis,\n\tBlockControls,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\nimport { PATTERN_OVERRIDES_BINDING_SOURCE } from '../constants';\n\nconst { useBlockDisplayTitle } = unlock( blockEditorPrivateApis );\n\nfunction PatternOverridesToolbarIndicator( { clientIds } ) {\n\tconst isSingleBlockSelected = clientIds.length === 1;\n\tconst { icon, firstBlockName } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockAttributes, getBlockNamesByClientId } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { getBlockType, getActiveBlockVariation } =\n\t\t\t\tselect( blocksStore );\n\t\t\tconst blockTypeNames = getBlockNamesByClientId( clientIds );\n\t\t\tconst _firstBlockTypeName = blockTypeNames[ 0 ];\n\t\t\tconst firstBlockType = getBlockType( _firstBlockTypeName );\n\t\t\tlet _icon;\n\t\t\tif ( isSingleBlockSelected ) {\n\t\t\t\tconst match = getActiveBlockVariation(\n\t\t\t\t\t_firstBlockTypeName,\n\t\t\t\t\tgetBlockAttributes( clientIds[ 0 ] )\n\t\t\t\t);\n\t\t\t\t// Take into account active block variations.\n\t\t\t\t_icon = match?.icon || firstBlockType.icon;\n\t\t\t} else {\n\t\t\t\tconst isSelectionOfSameType =\n\t\t\t\t\tnew Set( blockTypeNames ).size === 1;\n\t\t\t\t// When selection consists of blocks of multiple types, display an\n\t\t\t\t// appropriate icon to communicate the non-uniformity.\n\t\t\t\t_icon = isSelectionOfSameType ? firstBlockType.icon : copy;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\ticon: _icon,\n\t\t\t\tfirstBlockName: getBlockAttributes( clientIds[ 0 ] ).metadata\n\t\t\t\t\t.name,\n\t\t\t};\n\t\t},\n\t\t[ clientIds, isSingleBlockSelected ]\n\t);\n\tconst firstBlockTitle = useBlockDisplayTitle( {\n\t\tclientId: clientIds[ 0 ],\n\t\tmaximumLength: 35,\n\t} );\n\n\tconst blockDescription = isSingleBlockSelected\n\t\t? sprintf(\n\t\t\t\t/* translators: %1s: The block type's name; %2s: The block's user-provided name (the same as the override name). */\n\t\t\t\t__( 'This %1$s is editable using the \"%2$s\" override.' ),\n\t\t\t\tfirstBlockTitle.toLowerCase(),\n\t\t\t\tfirstBlockName\n\t\t )\n\t\t: __( 'These blocks are editable using overrides.' );\n\n\tconst descriptionId = useId();\n\n\treturn (\n\t\t<ToolbarItem>\n\t\t\t{ ( toggleProps ) => (\n\t\t\t\t<DropdownMenu\n\t\t\t\t\tclassName=\"patterns-pattern-overrides-toolbar-indicator\"\n\t\t\t\t\tlabel={ firstBlockTitle }\n\t\t\t\t\tpopoverProps={ {\n\t\t\t\t\t\tplacement: 'bottom-start',\n\t\t\t\t\t\tclassName:\n\t\t\t\t\t\t\t'patterns-pattern-overrides-toolbar-indicator__popover',\n\t\t\t\t\t} }\n\t\t\t\t\ticon={\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\t\t\tclassName=\"patterns-pattern-overrides-toolbar-indicator-icon\"\n\t\t\t\t\t\t\t\tshowColors\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\ttoggleProps={ {\n\t\t\t\t\t\tdescription: blockDescription,\n\t\t\t\t\t\t...toggleProps,\n\t\t\t\t\t} }\n\t\t\t\t\tmenuProps={ {\n\t\t\t\t\t\torientation: 'both',\n\t\t\t\t\t\t'aria-describedby': descriptionId,\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ () => (\n\t\t\t\t\t\t<Text id={ descriptionId }>{ blockDescription }</Text>\n\t\t\t\t\t) }\n\t\t\t\t</DropdownMenu>\n\t\t\t) }\n\t\t</ToolbarItem>\n\t);\n}\n\nexport default function PatternOverridesBlockControls() {\n\tconst { clientIds, hasPatternOverrides, hasParentPattern } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockAttributes,\n\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\tgetBlockParentsByBlockName,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst selectedClientIds = getSelectedBlockClientIds();\n\t\t\tconst _hasPatternOverrides = selectedClientIds.every(\n\t\t\t\t( clientId ) =>\n\t\t\t\t\tObject.values(\n\t\t\t\t\t\tgetBlockAttributes( clientId )?.metadata?.bindings ?? {}\n\t\t\t\t\t).some(\n\t\t\t\t\t\t( binding ) =>\n\t\t\t\t\t\t\tbinding?.source === PATTERN_OVERRIDES_BINDING_SOURCE\n\t\t\t\t\t)\n\t\t\t);\n\t\t\tconst _hasParentPattern = selectedClientIds.every(\n\t\t\t\t( clientId ) =>\n\t\t\t\t\tgetBlockParentsByBlockName( clientId, 'core/block', true )\n\t\t\t\t\t\t.length > 0\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tclientIds: selectedClientIds,\n\t\t\t\thasPatternOverrides: _hasPatternOverrides,\n\t\t\t\thasParentPattern: _hasParentPattern,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\treturn hasPatternOverrides && hasParentPattern ? (\n\t\t<BlockControls group=\"parent\">\n\t\t\t<PatternOverridesToolbarIndicator clientIds={ clientIds } />\n\t\t</BlockControls>\n\t) : null;\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAKA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AAUA,IAAAO,WAAA,GAAAP,OAAA;AACA,IAAAQ,UAAA,GAAAR,OAAA;AAAgE,IAAAS,WAAA,GAAAT,OAAA;AAxBhE;AACA;AACA;;AAkBA;AACA;AACA;;AAIA,MAAM;EAAEU;AAAqB,CAAC,GAAG,IAAAC,kBAAM,EAAEC,wBAAuB,CAAC;AAEjE,SAASC,gCAAgCA,CAAE;EAAEC;AAAU,CAAC,EAAG;EAC1D,MAAMC,qBAAqB,GAAGD,SAAS,CAACE,MAAM,KAAK,CAAC;EACpD,MAAM;IAAEC,IAAI;IAAEC;EAAe,CAAC,GAAG,IAAAC,eAAS,EACvCC,MAAM,IAAM;IACb,MAAM;MAAEC,kBAAkB;MAAEC;IAAwB,CAAC,GACpDF,MAAM,CAAEG,kBAAiB,CAAC;IAC3B,MAAM;MAAEC,YAAY;MAAEC;IAAwB,CAAC,GAC9CL,MAAM,CAAEM,aAAY,CAAC;IACtB,MAAMC,cAAc,GAAGL,uBAAuB,CAAER,SAAU,CAAC;IAC3D,MAAMc,mBAAmB,GAAGD,cAAc,CAAE,CAAC,CAAE;IAC/C,MAAME,cAAc,GAAGL,YAAY,CAAEI,mBAAoB,CAAC;IAC1D,IAAIE,KAAK;IACT,IAAKf,qBAAqB,EAAG;MAC5B,MAAMgB,KAAK,GAAGN,uBAAuB,CACpCG,mBAAmB,EACnBP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E7B,QAAQ,EAAE,YAAY,EAAE,IAAK,CAAC,CACxDvB,MAAM,GAAG,CACb,CAAC;IACD,OAAO;MACNF,SAAS,EAAEuD,iBAAiB;MAC5BJ,mBAAmB,EAAEK,oBAAoB;MACzCJ,gBAAgB,EAAEc;IACnB,CAAC;EACF,CAAC,EACD,EACD,CAAC;EAED,OAAOf,mBAAmB,IAAIC,gBAAgB,gBAC7C,IAAAzD,WAAA,CAAAsC,GAAA,EAACzC,YAAA,CAAA2E,aAAa;IAACC,KAAK,EAAC,QAAQ;IAAAjC,QAAA,eAC5B,IAAAxC,WAAA,CAAAsC,GAAA,EAAClC,gCAAgC;MAACC,SAAS,EAAGA;IAAW,CAAE;EAAC,CAC9C,CAAC,GACb,IAAI;AACT","ignoreList":[]}
|
|
@@ -47,7 +47,7 @@ function PatternOverridesControls({
|
|
|
47
47
|
const [showDisallowOverridesModal, setShowDisallowOverridesModal] = (0, _element.useState)(false);
|
|
48
48
|
const hasName = !!attributes.metadata?.name;
|
|
49
49
|
const defaultBindings = attributes.metadata?.bindings?.__default;
|
|
50
|
-
const
|
|
50
|
+
const hasOverrides = hasName && defaultBindings?.source === _constants.PATTERN_OVERRIDES_BINDING_SOURCE;
|
|
51
51
|
const isConnectedToOtherSources = defaultBindings?.source && defaultBindings.source !== _constants.PATTERN_OVERRIDES_BINDING_SOURCE;
|
|
52
52
|
function updateBindings(isChecked, customName) {
|
|
53
53
|
const prevBindings = attributes?.metadata?.bindings;
|
|
@@ -69,7 +69,7 @@ function PatternOverridesControls({
|
|
|
69
69
|
return null;
|
|
70
70
|
}
|
|
71
71
|
const hasUnsupportedImageAttributes = blockName === 'core/image' && (!!attributes.caption?.length || !!attributes.href?.length);
|
|
72
|
-
const helpText = hasUnsupportedImageAttributes ? (0, _i18n.__)(`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`) : (0, _i18n.__)('Allow changes to this block throughout instances of this pattern.');
|
|
72
|
+
const helpText = !hasOverrides && hasUnsupportedImageAttributes ? (0, _i18n.__)(`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`) : (0, _i18n.__)('Allow changes to this block throughout instances of this pattern.');
|
|
73
73
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
74
74
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.InspectorControls, {
|
|
75
75
|
group: "advanced",
|
|
@@ -83,15 +83,15 @@ function PatternOverridesControls({
|
|
|
83
83
|
variant: "secondary",
|
|
84
84
|
"aria-haspopup": "dialog",
|
|
85
85
|
onClick: () => {
|
|
86
|
-
if (
|
|
86
|
+
if (hasOverrides) {
|
|
87
87
|
setShowDisallowOverridesModal(true);
|
|
88
88
|
} else {
|
|
89
89
|
setShowAllowOverridesModal(true);
|
|
90
90
|
}
|
|
91
91
|
},
|
|
92
|
-
disabled: hasUnsupportedImageAttributes,
|
|
93
|
-
|
|
94
|
-
children:
|
|
92
|
+
disabled: !hasOverrides && hasUnsupportedImageAttributes,
|
|
93
|
+
accessibleWhenDisabled: true,
|
|
94
|
+
children: hasOverrides ? (0, _i18n.__)('Disable overrides') : (0, _i18n.__)('Enable overrides')
|
|
95
95
|
})
|
|
96
96
|
})
|
|
97
97
|
}), showAllowOverridesModal && /*#__PURE__*/(0, _jsxRuntime.jsx)(_allowOverridesModal.AllowOverridesModal, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_blockEditor","_components","_i18n","_constants","_allowOverridesModal","_jsxRuntime","removeBindings","bindings","updatedBindings","__default","Object","keys","length","undefined","addBindings","source","PATTERN_OVERRIDES_BINDING_SOURCE","PatternOverridesControls","attributes","setAttributes","name","blockName","controlId","useId","showAllowOverridesModal","setShowAllowOverridesModal","useState","showDisallowOverridesModal","setShowDisallowOverridesModal","hasName","metadata","defaultBindings","
|
|
1
|
+
{"version":3,"names":["_element","require","_blockEditor","_components","_i18n","_constants","_allowOverridesModal","_jsxRuntime","removeBindings","bindings","updatedBindings","__default","Object","keys","length","undefined","addBindings","source","PATTERN_OVERRIDES_BINDING_SOURCE","PatternOverridesControls","attributes","setAttributes","name","blockName","controlId","useId","showAllowOverridesModal","setShowAllowOverridesModal","useState","showDisallowOverridesModal","setShowDisallowOverridesModal","hasName","metadata","defaultBindings","hasOverrides","isConnectedToOtherSources","updateBindings","isChecked","customName","prevBindings","updatedMetadata","hasUnsupportedImageAttributes","caption","href","helpText","__","jsxs","Fragment","children","jsx","InspectorControls","group","BaseControl","id","label","help","Button","__next40pxDefaultSize","className","variant","onClick","disabled","accessibleWhenDisabled","AllowOverridesModal","initialName","onClose","onSave","newName","DisallowOverridesModal","_default","exports","default"],"sources":["@wordpress/patterns/src/components/pattern-overrides-controls.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useId } from '@wordpress/element';\nimport { InspectorControls } from '@wordpress/block-editor';\nimport { BaseControl, Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_OVERRIDES_BINDING_SOURCE } from '../constants';\nimport {\n\tAllowOverridesModal,\n\tDisallowOverridesModal,\n} from './allow-overrides-modal';\n\nfunction removeBindings( bindings ) {\n\tlet updatedBindings = { ...bindings };\n\tdelete updatedBindings.__default;\n\tif ( ! Object.keys( updatedBindings ).length ) {\n\t\tupdatedBindings = undefined;\n\t}\n\treturn updatedBindings;\n}\n\nfunction addBindings( bindings ) {\n\treturn {\n\t\t...bindings,\n\t\t__default: { source: PATTERN_OVERRIDES_BINDING_SOURCE },\n\t};\n}\n\nfunction PatternOverridesControls( {\n\tattributes,\n\tsetAttributes,\n\tname: blockName,\n} ) {\n\tconst controlId = useId();\n\tconst [ showAllowOverridesModal, setShowAllowOverridesModal ] =\n\t\tuseState( false );\n\tconst [ showDisallowOverridesModal, setShowDisallowOverridesModal ] =\n\t\tuseState( false );\n\n\tconst hasName = !! attributes.metadata?.name;\n\tconst defaultBindings = attributes.metadata?.bindings?.__default;\n\tconst hasOverrides =\n\t\thasName && defaultBindings?.source === PATTERN_OVERRIDES_BINDING_SOURCE;\n\tconst isConnectedToOtherSources =\n\t\tdefaultBindings?.source &&\n\t\tdefaultBindings.source !== PATTERN_OVERRIDES_BINDING_SOURCE;\n\n\tfunction updateBindings( isChecked, customName ) {\n\t\tconst prevBindings = attributes?.metadata?.bindings;\n\t\tconst updatedBindings = isChecked\n\t\t\t? addBindings( prevBindings )\n\t\t\t: removeBindings( prevBindings );\n\n\t\tconst updatedMetadata = {\n\t\t\t...attributes.metadata,\n\t\t\tbindings: updatedBindings,\n\t\t};\n\n\t\tif ( customName ) {\n\t\t\tupdatedMetadata.name = customName;\n\t\t}\n\n\t\tsetAttributes( {\n\t\t\tmetadata: updatedMetadata,\n\t\t} );\n\t}\n\n\t// Avoid overwriting other (e.g. meta) bindings.\n\tif ( isConnectedToOtherSources ) {\n\t\treturn null;\n\t}\n\n\tconst hasUnsupportedImageAttributes =\n\t\tblockName === 'core/image' &&\n\t\t( !! attributes.caption?.length || !! attributes.href?.length );\n\n\tconst helpText =\n\t\t! hasOverrides && hasUnsupportedImageAttributes\n\t\t\t? __(\n\t\t\t\t\t`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`\n\t\t\t )\n\t\t\t: __(\n\t\t\t\t\t'Allow changes to this block throughout instances of this pattern.'\n\t\t\t );\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<BaseControl\n\t\t\t\t\tid={ controlId }\n\t\t\t\t\tlabel={ __( 'Overrides' ) }\n\t\t\t\t\thelp={ helpText }\n\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tclassName=\"pattern-overrides-control__allow-overrides-button\"\n\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tif ( hasOverrides ) {\n\t\t\t\t\t\t\t\tsetShowDisallowOverridesModal( true );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tsetShowAllowOverridesModal( true );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tdisabled={\n\t\t\t\t\t\t\t! hasOverrides && hasUnsupportedImageAttributes\n\t\t\t\t\t\t}\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t>\n\t\t\t\t\t\t{ hasOverrides\n\t\t\t\t\t\t\t? __( 'Disable overrides' )\n\t\t\t\t\t\t\t: __( 'Enable overrides' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</BaseControl>\n\t\t\t</InspectorControls>\n\n\t\t\t{ showAllowOverridesModal && (\n\t\t\t\t<AllowOverridesModal\n\t\t\t\t\tinitialName={ attributes.metadata?.name }\n\t\t\t\t\tonClose={ () => setShowAllowOverridesModal( false ) }\n\t\t\t\t\tonSave={ ( newName ) => {\n\t\t\t\t\t\tupdateBindings( true, newName );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showDisallowOverridesModal && (\n\t\t\t\t<DisallowOverridesModal\n\t\t\t\t\tonClose={ () => setShowDisallowOverridesModal( false ) }\n\t\t\t\t\tonSave={ () => updateBindings( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default PatternOverridesControls;\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,oBAAA,GAAAL,OAAA;AAGiC,IAAAM,WAAA,GAAAN,OAAA;AAfjC;AACA;AACA;;AAMA;AACA;AACA;;AAOA,SAASO,cAAcA,CAAEC,QAAQ,EAAG;EACnC,IAAIC,eAAe,GAAG;IAAE,GAAGD;EAAS,CAAC;EACrC,O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DqB,sBAAsB;UAAAd,QAAA,EAEpBd,YAAY,GACX,IAAAW,QAAE,EAAE,mBAAoB,CAAC,GACzB,IAAAA,QAAE,EAAE,kBAAmB;QAAC,CACpB;MAAC,CACG;IAAC,CACI,CAAC,EAElBnB,uBAAuB,iBACxB,IAAAnB,WAAA,CAAA0C,GAAA,EAAC3C,oBAAA,CAAAyD,mBAAmB;MACnBC,WAAW,EAAG5C,UAAU,CAACY,QAAQ,EAAEV,IAAM;MACzC2C,OAAO,EAAGA,CAAA,KAAMtC,0BAA0B,CAAE,KAAM,CAAG;MACrDuC,MAAM,EAAKC,OAAO,IAAM;QACvB/B,cAAc,CAAE,IAAI,EAAE+B,OAAQ,CAAC;MAChC;IAAG,CACH,CACD,EACCtC,0BAA0B,iBAC3B,IAAAtB,WAAA,CAAA0C,GAAA,EAAC3C,oBAAA,CAAA8D,sBAAsB;MACtBH,OAAO,EAAGA,CAAA,KAAMnC,6BAA6B,CAAE,KAAM,CAAG;MACxDoC,MAAM,EAAGA,CAAA,KAAM9B,cAAc,CAAE,KAAM;IAAG,CACxC,CACD;EAAA,CACA,CAAC;AAEL;AAAC,IAAAiC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcpD,wBAAwB","ignoreList":[]}
|
|
@@ -41,12 +41,19 @@ function PatternsManageButton({
|
|
|
41
41
|
const reusableBlock = getBlock(clientId);
|
|
42
42
|
return {
|
|
43
43
|
canRemove: canRemoveBlock(clientId),
|
|
44
|
-
isVisible: !!reusableBlock && (0, _blocks.isReusableBlock)(reusableBlock) && !!canUser('update',
|
|
44
|
+
isVisible: !!reusableBlock && (0, _blocks.isReusableBlock)(reusableBlock) && !!canUser('update', {
|
|
45
|
+
kind: 'postType',
|
|
46
|
+
name: 'wp_block',
|
|
47
|
+
id: reusableBlock.attributes.ref
|
|
48
|
+
}),
|
|
45
49
|
innerBlockCount: getBlockCount(clientId),
|
|
46
50
|
// The site editor and templates both check whether the user
|
|
47
51
|
// has edit_theme_options capabilities. We can leverage that here
|
|
48
52
|
// and omit the manage patterns link if the user can't access it.
|
|
49
|
-
managePatternsUrl: canUser('create',
|
|
53
|
+
managePatternsUrl: canUser('create', {
|
|
54
|
+
kind: 'postType',
|
|
55
|
+
name: 'wp_template'
|
|
56
|
+
}) ? (0, _url.addQueryArgs)('site-editor.php', {
|
|
50
57
|
path: '/patterns'
|
|
51
58
|
}) : (0, _url.addQueryArgs)('edit.php', {
|
|
52
59
|
post_type: 'wp_block'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_i18n","_blocks","_data","_blockEditor","_url","_coreData","_store","_lockUnlock","_jsxRuntime","PatternsManageButton","clientId","canRemove","isVisible","managePatternsUrl","useSelect","select","getBlock","canRemoveBlock","getBlockCount","blockEditorStore","canUser","coreStore","reusableBlock","isReusableBlock","attributes","ref","innerBlockCount","addQueryArgs","path","post_type","convertSyncedPatternToStatic","unlock","useDispatch","patternsStore","jsxs","Fragment","children","jsx","MenuItem","onClick","__","href","_default","exports","default"],"sources":["@wordpress/patterns/src/components/patterns-manage-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nfunction PatternsManageButton( { clientId } ) {\n\tconst { canRemove, isVisible, managePatternsUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, canRemoveBlock, getBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst reusableBlock = getBlock( clientId );\n\n\t\t\treturn {\n\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\tisVisible:\n\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t!! canUser(\n\t\t\t\t\t\
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_blocks","_data","_blockEditor","_url","_coreData","_store","_lockUnlock","_jsxRuntime","PatternsManageButton","clientId","canRemove","isVisible","managePatternsUrl","useSelect","select","getBlock","canRemoveBlock","getBlockCount","blockEditorStore","canUser","coreStore","reusableBlock","isReusableBlock","kind","name","id","attributes","ref","innerBlockCount","addQueryArgs","path","post_type","convertSyncedPatternToStatic","unlock","useDispatch","patternsStore","jsxs","Fragment","children","jsx","MenuItem","onClick","__","href","_default","exports","default"],"sources":["@wordpress/patterns/src/components/patterns-manage-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nfunction PatternsManageButton( { clientId } ) {\n\tconst { canRemove, isVisible, managePatternsUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, canRemoveBlock, getBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst reusableBlock = getBlock( clientId );\n\n\t\t\treturn {\n\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\tisVisible:\n\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t!! canUser( 'update', {\n\t\t\t\t\t\tkind: 'postType',\n\t\t\t\t\t\tname: 'wp_block',\n\t\t\t\t\t\tid: reusableBlock.attributes.ref,\n\t\t\t\t\t} ),\n\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t// The site editor and templates both check whether the user\n\t\t\t\t// has edit_theme_options capabilities. We can leverage that here\n\t\t\t\t// and omit the manage patterns link if the user can't access it.\n\t\t\t\tmanagePatternsUrl: canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_template',\n\t\t\t\t} )\n\t\t\t\t\t? addQueryArgs( 'site-editor.php', {\n\t\t\t\t\t\t\tpath: '/patterns',\n\t\t\t\t\t } )\n\t\t\t\t\t: addQueryArgs( 'edit.php', {\n\t\t\t\t\t\t\tpost_type: 'wp_block',\n\t\t\t\t\t } ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { convertSyncedPatternToStatic } = unlock(\n\t\tuseDispatch( patternsStore )\n\t);\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ canRemove && (\n\t\t\t\t<MenuItem\n\t\t\t\t\tonClick={ () => convertSyncedPatternToStatic( clientId ) }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Detach' ) }\n\t\t\t\t</MenuItem>\n\t\t\t) }\n\t\t\t<MenuItem href={ managePatternsUrl }>\n\t\t\t\t{ __( 'Manage patterns' ) }\n\t\t\t</MenuItem>\n\t\t</>\n\t);\n}\n\nexport default PatternsManageButton;\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,IAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,WAAA,GAAAR,OAA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AG;IAClB,OAAO,IAAI;EACZ;EAEA,oBACC,IAAAJ,WAAA,CAAA6B,IAAA,EAAA7B,WAAA,CAAA8B,QAAA;IAAAC,QAAA,GACG5B,SAAS,iBACV,IAAAH,WAAA,CAAAgC,GAAA,EAAC1C,WAAA,CAAA2C,QAAQ;MACRC,OAAO,EAAGA,CAAA,KAAMT,4BAA4B,CAAEvB,QAAS,CAAG;MAAA6B,QAAA,EAExD,IAAAI,QAAE,EAAE,QAAS;IAAC,CACP,CACV,eACD,IAAAnC,WAAA,CAAAgC,GAAA,EAAC1C,WAAA,CAAA2C,QAAQ;MAACG,IAAI,EAAG/B,iBAAmB;MAAA0B,QAAA,EACjC,IAAAI,QAAE,EAAE,iBAAkB;IAAC,CAChB,CAAC;EAAA,CACV,CAAC;AAEL;AAAC,IAAAE,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEctC,oBAAoB","ignoreList":[]}
|
|
@@ -64,13 +64,11 @@ function ResetOverridesControl(props) {
|
|
|
64
64
|
[CONTENT]: newOverrides
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.
|
|
68
|
-
group: "other",
|
|
67
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.__unstableBlockToolbarLastItem, {
|
|
69
68
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToolbarGroup, {
|
|
70
69
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToolbarButton, {
|
|
71
70
|
onClick: onClick,
|
|
72
71
|
disabled: !isOverriden,
|
|
73
|
-
__experimentalIsFocusable: true,
|
|
74
72
|
children: (0, _i18n.__)('Reset')
|
|
75
73
|
})
|
|
76
74
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_blockEditor","require","_components","_data","_i18n","_jsxRuntime","CONTENT","ResetOverridesControl","props","name","attributes","metadata","registry","useRegistry","isOverriden","useSelect","select","getBlockAttributes","getBlockParentsByBlockName","blockEditorStore","patternClientId","clientId","overrides","hasOwnProperty","onClick","updateBlockAttributes","__unstableMarkLastChangeAsPersistent","dispatch","newOverrides","Object","keys","length","undefined","jsx","
|
|
1
|
+
{"version":3,"names":["_blockEditor","require","_components","_data","_i18n","_jsxRuntime","CONTENT","ResetOverridesControl","props","name","attributes","metadata","registry","useRegistry","isOverriden","useSelect","select","getBlockAttributes","getBlockParentsByBlockName","blockEditorStore","patternClientId","clientId","overrides","hasOwnProperty","onClick","updateBlockAttributes","__unstableMarkLastChangeAsPersistent","dispatch","newOverrides","Object","keys","length","undefined","jsx","__unstableBlockToolbarLastItem","children","ToolbarGroup","ToolbarButton","disabled","__"],"sources":["@wordpress/patterns/src/components/reset-overrides-control.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tstore as blockEditorStore,\n\t__unstableBlockToolbarLastItem as BlockToolbarLastItem,\n} from '@wordpress/block-editor';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\n\nconst CONTENT = 'content';\n\nexport default function ResetOverridesControl( props ) {\n\tconst name = props.attributes.metadata?.name;\n\tconst registry = useRegistry();\n\tconst isOverriden = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! name ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { getBlockAttributes, getBlockParentsByBlockName } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst [ patternClientId ] = getBlockParentsByBlockName(\n\t\t\t\tprops.clientId,\n\t\t\t\t'core/block',\n\t\t\t\ttrue\n\t\t\t);\n\n\t\t\tif ( ! patternClientId ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst overrides = getBlockAttributes( patternClientId )[ CONTENT ];\n\n\t\t\tif ( ! overrides ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\treturn overrides.hasOwnProperty( name );\n\t\t},\n\t\t[ props.clientId, name ]\n\t);\n\n\tfunction onClick() {\n\t\tconst { getBlockAttributes, getBlockParentsByBlockName } =\n\t\t\tregistry.select( blockEditorStore );\n\t\tconst [ patternClientId ] = getBlockParentsByBlockName(\n\t\t\tprops.clientId,\n\t\t\t'core/block',\n\t\t\ttrue\n\t\t);\n\n\t\tif ( ! patternClientId ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst overrides = getBlockAttributes( patternClientId )[ CONTENT ];\n\n\t\tif ( ! overrides.hasOwnProperty( name ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { updateBlockAttributes, __unstableMarkLastChangeAsPersistent } =\n\t\t\tregistry.dispatch( blockEditorStore );\n\t\t__unstableMarkLastChangeAsPersistent();\n\n\t\tlet newOverrides = { ...overrides };\n\t\tdelete newOverrides[ name ];\n\n\t\tif ( ! Object.keys( newOverrides ).length ) {\n\t\t\tnewOverrides = undefined;\n\t\t}\n\n\t\tupdateBlockAttributes( patternClientId, {\n\t\t\t[ CONTENT ]: newOverrides,\n\t\t} );\n\t}\n\n\treturn (\n\t\t<BlockToolbarLastItem>\n\t\t\t<ToolbarGroup>\n\t\t\t\t<ToolbarButton onClick={ onClick } disabled={ ! isOverriden }>\n\t\t\t\t\t{ __( 'Reset' ) }\n\t\t\t\t</ToolbarButton>\n\t\t\t</ToolbarGroup>\n\t\t</BlockToolbarLastItem>\n\t);\n}\n"],"mappings":";;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAIA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAAqC,IAAAI,WAAA,GAAAJ,OAAA;AATrC;AACA;AACA;;AASA,MAAMK,OAAO,GAAG,SAAS;AAEV,SAASC,qBAAqBA,CAAEC,KAAK,EAAG;EACtD,MAAMC,IAAI,GAAGD,KAAK,CAACE,UAAU,CAACC,QAAQ,EAAEF,IAAI;EAC5C,MAAMG,QAAQ,GAAG,IAAAC,i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,MAAM,CAACC,IAAI,CAAEF,YAAa,CAAC,CAACG,MAAM,EAAG;MAC3CH,YAAY,GAAGI,SAAS;IACzB;IAEAP,qBAAqB,CAAEL,eAAe,EAAE;MACvC,CAAEd,OAAO,GAAIsB;IACd,CAAE,CAAC;EACJ;EAEA,oBACC,IAAAvB,WAAA,CAAA4B,GAAA,EAACjC,YAAA,CAAAkC,8BAAoB;IAAAC,QAAA,eACpB,IAAA9B,WAAA,CAAA4B,GAAA,EAAC/B,WAAA,CAAAkC,YAAY;MAAAD,QAAA,eACZ,IAAA9B,WAAA,CAAA4B,GAAA,EAAC/B,WAAA,CAAAmC,aAAa;QAACb,OAAO,EAAGA,OAAS;QAACc,QAAQ,EAAG,CAAExB,WAAa;QAAAqB,QAAA,EAC1D,IAAAI,QAAE,EAAE,OAAQ;MAAC,CACD;IAAC,CACH;EAAC,CACM,CAAC;AAEzB","ignoreList":[]}
|
|
@@ -73,7 +73,10 @@ export default function PatternConvertButton({
|
|
|
73
73
|
hasBlockSupport(block.name, 'reusable', true)) &&
|
|
74
74
|
// Hide when current doesn't have permission to do that.
|
|
75
75
|
// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.
|
|
76
|
-
!!canUser('create',
|
|
76
|
+
!!canUser('create', {
|
|
77
|
+
kind: 'postType',
|
|
78
|
+
name: 'wp_block'
|
|
79
|
+
});
|
|
77
80
|
return _canConvert;
|
|
78
81
|
}, [clientIds, rootClientId]);
|
|
79
82
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["hasBlockSupport","isReusableBlock","createBlock","serialize","store","blockEditorStore","useState","useCallback","MenuItem","symbol","useSelect","useDispatch","coreStore","__","sprintf","noticesStore","patternsStore","CreatePatternModal","unlock","PATTERN_SYNC_TYPES","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","PatternConvertButton","clientIds","rootClientId","closeBlockSettingsMenu","createSuccessNotice","replaceBlocks","setEditingPattern","isModalOpen","setIsModalOpen","canConvert","select","_getBlocksByClientId","canUser","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","rootId","length","undefined","blocks","isReusable","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","name","getContent","handleSuccess","pattern","wp_pattern_sync_status","unsynced","newBlock","id","clientId","title","raw","type","children","icon","onClick","content","onSuccess","onError","onClose"],"sources":["@wordpress/patterns/src/components/pattern-convert-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\thasBlockSupport,\n\tisReusableBlock,\n\tcreateBlock,\n\tserialize,\n} from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useState, useCallback } from '@wordpress/element';\nimport { MenuItem } from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CreatePatternModal from './create-pattern-modal';\nimport { unlock } from '../lock-unlock';\nimport { PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Menu control to convert block(s) to a pattern block.\n *\n * @param {Object} props Component props.\n * @param {string[]} props.clientIds Client ids of selected blocks.\n * @param {string} props.rootClientId ID of the currently selected top-level block.\n * @param {()=>void} props.closeBlockSettingsMenu Callback to close the block settings menu dropdown.\n * @return {import('react').ComponentType} The menu control or null.\n */\nexport default function PatternConvertButton( {\n\tclientIds,\n\trootClientId,\n\tcloseBlockSettingsMenu,\n} ) {\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst { replaceBlocks } = useDispatch( blockEditorStore );\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { setEditingPattern } = unlock( useDispatch( patternsStore ) );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst canConvert = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst {\n\t\t\t\tgetBlocksByClientId,\n\t\t\t\tcanInsertBlockType,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst rootId =\n\t\t\t\trootClientId ||\n\t\t\t\t( clientIds.length > 0\n\t\t\t\t\t? getBlockRootClientId( clientIds[ 0 ] )\n\t\t\t\t\t: undefined );\n\n\t\t\tconst blocks = getBlocksByClientId( clientIds ) ?? [];\n\n\t\t\tconst isReusable =\n\t\t\t\tblocks.length === 1 &&\n\t\t\t\tblocks[ 0 ] &&\n\t\t\t\tisReusableBlock( blocks[ 0 ] ) &&\n\t\t\t\t!! select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_block',\n\t\t\t\t\tblocks[ 0 ].attributes.ref\n\t\t\t\t);\n\n\t\t\tconst _canConvert =\n\t\t\t\t// Hide when this is already a synced pattern.\n\t\t\t\t! isReusable &&\n\t\t\t\t// Hide when patterns are disabled.\n\t\t\t\tcanInsertBlockType( 'core/block', rootId ) &&\n\t\t\t\tblocks.every(\n\t\t\t\t\t( block ) =>\n\t\t\t\t\t\t// Guard against the case where a regular block has *just* been converted.\n\t\t\t\t\t\t!! block &&\n\t\t\t\t\t\t// Hide on invalid blocks.\n\t\t\t\t\t\tblock.isValid &&\n\t\t\t\t\t\t// Hide when block doesn't support being made into a pattern.\n\t\t\t\t\t\thasBlockSupport( block.name, 'reusable', true )\n\t\t\t\t) &&\n\t\t\t\t// Hide when current doesn't have permission to do that.\n\t\t\t\t// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.\n\t\t\t\t!! canUser( 'create', '
|
|
1
|
+
{"version":3,"names":["hasBlockSupport","isReusableBlock","createBlock","serialize","store","blockEditorStore","useState","useCallback","MenuItem","symbol","useSelect","useDispatch","coreStore","__","sprintf","noticesStore","patternsStore","CreatePatternModal","unlock","PATTERN_SYNC_TYPES","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","PatternConvertButton","clientIds","rootClientId","closeBlockSettingsMenu","createSuccessNotice","replaceBlocks","setEditingPattern","isModalOpen","setIsModalOpen","canConvert","select","_getBlocksByClientId","canUser","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","rootId","length","undefined","blocks","isReusable","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","name","kind","getContent","handleSuccess","pattern","wp_pattern_sync_status","unsynced","newBlock","id","clientId","title","raw","type","children","icon","onClick","content","onSuccess","onError","onClose"],"sources":["@wordpress/patterns/src/components/pattern-convert-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\thasBlockSupport,\n\tisReusableBlock,\n\tcreateBlock,\n\tserialize,\n} from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useState, useCallback } from '@wordpress/element';\nimport { MenuItem } from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CreatePatternModal from './create-pattern-modal';\nimport { unlock } from '../lock-unlock';\nimport { PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Menu control to convert block(s) to a pattern block.\n *\n * @param {Object} props Component props.\n * @param {string[]} props.clientIds Client ids of selected blocks.\n * @param {string} props.rootClientId ID of the currently selected top-level block.\n * @param {()=>void} props.closeBlockSettingsMenu Callback to close the block settings menu dropdown.\n * @return {import('react').ComponentType} The menu control or null.\n */\nexport default function PatternConvertButton( {\n\tclientIds,\n\trootClientId,\n\tcloseBlockSettingsMenu,\n} ) {\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst { replaceBlocks } = useDispatch( blockEditorStore );\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { setEditingPattern } = unlock( useDispatch( patternsStore ) );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst canConvert = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst {\n\t\t\t\tgetBlocksByClientId,\n\t\t\t\tcanInsertBlockType,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst rootId =\n\t\t\t\trootClientId ||\n\t\t\t\t( clientIds.length > 0\n\t\t\t\t\t? getBlockRootClientId( clientIds[ 0 ] )\n\t\t\t\t\t: undefined );\n\n\t\t\tconst blocks = getBlocksByClientId( clientIds ) ?? [];\n\n\t\t\tconst isReusable =\n\t\t\t\tblocks.length === 1 &&\n\t\t\t\tblocks[ 0 ] &&\n\t\t\t\tisReusableBlock( blocks[ 0 ] ) &&\n\t\t\t\t!! select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_block',\n\t\t\t\t\tblocks[ 0 ].attributes.ref\n\t\t\t\t);\n\n\t\t\tconst _canConvert =\n\t\t\t\t// Hide when this is already a synced pattern.\n\t\t\t\t! isReusable &&\n\t\t\t\t// Hide when patterns are disabled.\n\t\t\t\tcanInsertBlockType( 'core/block', rootId ) &&\n\t\t\t\tblocks.every(\n\t\t\t\t\t( block ) =>\n\t\t\t\t\t\t// Guard against the case where a regular block has *just* been converted.\n\t\t\t\t\t\t!! block &&\n\t\t\t\t\t\t// Hide on invalid blocks.\n\t\t\t\t\t\tblock.isValid &&\n\t\t\t\t\t\t// Hide when block doesn't support being made into a pattern.\n\t\t\t\t\t\thasBlockSupport( block.name, 'reusable', true )\n\t\t\t\t) &&\n\t\t\t\t// Hide when current doesn't have permission to do that.\n\t\t\t\t// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.\n\t\t\t\t!! canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_block',\n\t\t\t\t} );\n\n\t\t\treturn _canConvert;\n\t\t},\n\t\t[ clientIds, rootClientId ]\n\t);\n\tconst { getBlocksByClientId } = useSelect( blockEditorStore );\n\tconst getContent = useCallback(\n\t\t() => serialize( getBlocksByClientId( clientIds ) ),\n\t\t[ getBlocksByClientId, clientIds ]\n\t);\n\n\tif ( ! canConvert ) {\n\t\treturn null;\n\t}\n\n\tconst handleSuccess = ( { pattern } ) => {\n\t\tif ( pattern.wp_pattern_sync_status !== PATTERN_SYNC_TYPES.unsynced ) {\n\t\t\tconst newBlock = createBlock( 'core/block', {\n\t\t\t\tref: pattern.id,\n\t\t\t} );\n\n\t\t\treplaceBlocks( clientIds, newBlock );\n\t\t\tsetEditingPattern( newBlock.clientId, true );\n\t\t\tcloseBlockSettingsMenu();\n\t\t}\n\n\t\tcreateSuccessNotice(\n\t\t\tpattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Unsynced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Synced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t ),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'convert-to-pattern-success',\n\t\t\t}\n\t\t);\n\t\tsetIsModalOpen( false );\n\t};\n\treturn (\n\t\t<>\n\t\t\t<MenuItem\n\t\t\t\ticon={ symbol }\n\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\taria-expanded={ isModalOpen }\n\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t>\n\t\t\t\t{ __( 'Create pattern' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<CreatePatternModal\n\t\t\t\t\tcontent={ getContent }\n\t\t\t\t\tonSuccess={ ( pattern ) => {\n\t\t\t\t\t\thandleSuccess( pattern );\n\t\t\t\t\t} }\n\t\t\t\t\tonError={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,eAAe,EACfC,eAAe,EACfC,WAAW,EACXC,SAAS,QACH,mBAAmB;AAC1B,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,QAAQ,EAAEC,WAAW,QAAQ,oBAAoB;AAC1D,SAASC,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,MAAM,QAAQ,kBAAkB;AACzC,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASP,KAAK,IAAIQ,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASV,KAAK,IAAIW,YAAY,QAAQ,oBAAoB;AAC1D;AACA;AACA;AACA,SAASX,KAAK,IAAIY,aAAa,QAAQ,UAAU;AACjD,OAAOC,kBAAkB,MAAM,wBAAwB;AACvD,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,kBAAkB,QAAQ,cAAc;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AARA,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,QAAA,IAAAC,SAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AASA,eAAe,SAASC,oBAAoBA,CAAE;EAC7CC,SAAS;EACTC,YAAY;EACZC;AACD,CAAC,EAAG;EACH,MAAM;IAAEC;EAAoB,CAAC,GAAGnB,WAAW,CAAEI,YAAa,CAAC;EAC3D,MAAM;IAAEgB;EAAc,CAAC,GAAGpB,WAAW,CAAEN,gBAAiB,CAAC;EACzD;EACA;EACA,MAAM;IAA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,gBACC9C,IAAA,CAACb,QAAQ;MACR4D,IAAI,EAAG3D,MAAQ;MACf4D,OAAO,EAAGA,CAAA,KAAMnC,cAAc,CAAE,IAAK,CAAG;MACxC,iBAAgBD,WAAa;MAC7B,iBAAc,QAAQ;MAAAkC,QAAA,EAEpBtD,EAAE,CAAE,gBAAiB;IAAC,CACf,CAAC,EACToB,WAAW,iBACZZ,IAAA,CAACJ,kBAAkB;MAClBqD,OAAO,EAAGd,UAAY;MACtBe,SAAS,EAAKb,OAAO,IAAM;QAC1BD,aAAa,CAAEC,OAAQ,CAAC;MACzB,CAAG;MACHc,OAAO,EAAGA,CAAA,KAAM;QACftC,cAAc,CAAE,KAAM,CAAC;MACxB,CAAG;MACHuC,OAAO,EAAGA,CAAA,KAAM;QACfvC,cAAc,CAAE,KAAM,CAAC;MACxB;IAAG,CACH,CACD;EAAA,CACA,CAAC;AAEL","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useId","__","sprintf","DropdownMenu","ToolbarItem","__experimentalText","Text","store","blocksStore","useSelect","copy","blockEditorStore","BlockIcon","privateApis","blockEditorPrivateApis","BlockControls","unlock","PATTERN_OVERRIDES_BINDING_SOURCE","jsx","_jsx","Fragment","_Fragment","useBlockDisplayTitle","PatternOverridesToolbarIndicator","clientIds","isSingleBlockSelected","length","icon","firstBlockName","select","getBlockAttributes","getBlockNamesByClientId","getBlockType","getActiveBlockVariation","blockTypeNames","_firstBlockTypeName","firstBlockType","_icon","match","isSelectionOfSameType","Set","size","metadata","name","firstBlockTitle","clientId","maximumLength","blockDescription","toLowerCase","descriptionId","children","toggleProps","className","label","popoverProps","placement","showColors","
|
|
1
|
+
{"version":3,"names":["useId","__","sprintf","DropdownMenu","ToolbarItem","__experimentalText","Text","store","blocksStore","useSelect","copy","blockEditorStore","BlockIcon","privateApis","blockEditorPrivateApis","BlockControls","unlock","PATTERN_OVERRIDES_BINDING_SOURCE","jsx","_jsx","Fragment","_Fragment","useBlockDisplayTitle","PatternOverridesToolbarIndicator","clientIds","isSingleBlockSelected","length","icon","firstBlockName","select","getBlockAttributes","getBlockNamesByClientId","getBlockType","getActiveBlockVariation","blockTypeNames","_firstBlockTypeName","firstBlockType","_icon","match","isSelectionOfSameType","Set","size","metadata","name","firstBlockTitle","clientId","maximumLength","blockDescription","toLowerCase","descriptionId","children","toggleProps","className","label","popoverProps","placement","showColors","description","menuProps","orientation","id","PatternOverridesBlockControls","hasPatternOverrides","hasParentPattern","getSelectedBlockClientIds","getBlockParentsByBlockName","selectedClientIds","_hasPatternOverrides","every","_getBlockAttributes$m","Object","values","bindings","some","binding","source","_hasParentPattern","group"],"sources":["@wordpress/patterns/src/components/pattern-overrides-block-controls.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useId } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tDropdownMenu,\n\tToolbarItem,\n\t__experimentalText as Text,\n} from '@wordpress/components';\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\nimport { copy } from '@wordpress/icons';\nimport {\n\tstore as blockEditorStore,\n\tBlockIcon,\n\tprivateApis as blockEditorPrivateApis,\n\tBlockControls,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\nimport { PATTERN_OVERRIDES_BINDING_SOURCE } from '../constants';\n\nconst { useBlockDisplayTitle } = unlock( blockEditorPrivateApis );\n\nfunction PatternOverridesToolbarIndicator( { clientIds } ) {\n\tconst isSingleBlockSelected = clientIds.length === 1;\n\tconst { icon, firstBlockName } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockAttributes, getBlockNamesByClientId } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { getBlockType, getActiveBlockVariation } =\n\t\t\t\tselect( blocksStore );\n\t\t\tconst blockTypeNames = getBlockNamesByClientId( clientIds );\n\t\t\tconst _firstBlockTypeName = blockTypeNames[ 0 ];\n\t\t\tconst firstBlockType = getBlockType( _firstBlockTypeName );\n\t\t\tlet _icon;\n\t\t\tif ( isSingleBlockSelected ) {\n\t\t\t\tconst match = getActiveBlockVariation(\n\t\t\t\t\t_firstBlockTypeName,\n\t\t\t\t\tgetBlockAttributes( clientIds[ 0 ] )\n\t\t\t\t);\n\t\t\t\t// Take into account active block variations.\n\t\t\t\t_icon = match?.icon || firstBlockType.icon;\n\t\t\t} else {\n\t\t\t\tconst isSelectionOfSameType =\n\t\t\t\t\tnew Set( blockTypeNames ).size === 1;\n\t\t\t\t// When selection consists of blocks of multiple types, display an\n\t\t\t\t// appropriate icon to communicate the non-uniformity.\n\t\t\t\t_icon = isSelectionOfSameType ? firstBlockType.icon : copy;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\ticon: _icon,\n\t\t\t\tfirstBlockName: getBlockAttributes( clientIds[ 0 ] ).metadata\n\t\t\t\t\t.name,\n\t\t\t};\n\t\t},\n\t\t[ clientIds, isSingleBlockSelected ]\n\t);\n\tconst firstBlockTitle = useBlockDisplayTitle( {\n\t\tclientId: clientIds[ 0 ],\n\t\tmaximumLength: 35,\n\t} );\n\n\tconst blockDescription = isSingleBlockSelected\n\t\t? sprintf(\n\t\t\t\t/* translators: %1s: The block type's name; %2s: The block's user-provided name (the same as the override name). */\n\t\t\t\t__( 'This %1$s is editable using the \"%2$s\" override.' ),\n\t\t\t\tfirstBlockTitle.toLowerCase(),\n\t\t\t\tfirstBlockName\n\t\t )\n\t\t: __( 'These blocks are editable using overrides.' );\n\n\tconst descriptionId = useId();\n\n\treturn (\n\t\t<ToolbarItem>\n\t\t\t{ ( toggleProps ) => (\n\t\t\t\t<DropdownMenu\n\t\t\t\t\tclassName=\"patterns-pattern-overrides-toolbar-indicator\"\n\t\t\t\t\tlabel={ firstBlockTitle }\n\t\t\t\t\tpopoverProps={ {\n\t\t\t\t\t\tplacement: 'bottom-start',\n\t\t\t\t\t\tclassName:\n\t\t\t\t\t\t\t'patterns-pattern-overrides-toolbar-indicator__popover',\n\t\t\t\t\t} }\n\t\t\t\t\ticon={\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\t\t\tclassName=\"patterns-pattern-overrides-toolbar-indicator-icon\"\n\t\t\t\t\t\t\t\tshowColors\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\ttoggleProps={ {\n\t\t\t\t\t\tdescription: blockDescription,\n\t\t\t\t\t\t...toggleProps,\n\t\t\t\t\t} }\n\t\t\t\t\tmenuProps={ {\n\t\t\t\t\t\torientation: 'both',\n\t\t\t\t\t\t'aria-describedby': descriptionId,\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ () => (\n\t\t\t\t\t\t<Text id={ descriptionId }>{ blockDescription }</Text>\n\t\t\t\t\t) }\n\t\t\t\t</DropdownMenu>\n\t\t\t) }\n\t\t</ToolbarItem>\n\t);\n}\n\nexport default function PatternOverridesBlockControls() {\n\tconst { clientIds, hasPatternOverrides, hasParentPattern } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockAttributes,\n\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\tgetBlockParentsByBlockName,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst selectedClientIds = getSelectedBlockClientIds();\n\t\t\tconst _hasPatternOverrides = selectedClientIds.every(\n\t\t\t\t( clientId ) =>\n\t\t\t\t\tObject.values(\n\t\t\t\t\t\tgetBlockAttributes( clientId )?.metadata?.bindings ?? {}\n\t\t\t\t\t).some(\n\t\t\t\t\t\t( binding ) =>\n\t\t\t\t\t\t\tbinding?.source === PATTERN_OVERRIDES_BINDING_SOURCE\n\t\t\t\t\t)\n\t\t\t);\n\t\t\tconst _hasParentPattern = selectedClientIds.every(\n\t\t\t\t( clientId ) =>\n\t\t\t\t\tgetBlockParentsByBlockName( clientId, 'core/block', true )\n\t\t\t\t\t\t.length > 0\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tclientIds: selectedClientIds,\n\t\t\t\thasPatternOverrides: _hasPatternOverrides,\n\t\t\t\thasParentPattern: _hasParentPattern,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\treturn hasPatternOverrides && hasParentPattern ? (\n\t\t<BlockControls group=\"parent\">\n\t\t\t<PatternOverridesToolbarIndicator clientIds={ clientIds } />\n\t\t</BlockControls>\n\t) : null;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAK,QAAQ,oBAAoB;AAC1C,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SACCC,YAAY,EACZC,WAAW,EACXC,kBAAkB,IAAIC,IAAI,QACpB,uBAAuB;AAC9B,SAASC,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;AACxD,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,IAAI,QAAQ,kBAAkB;AACvC,SACCH,KAAK,IAAII,gBAAgB,EACzBC,SAAS,EACTC,WAAW,IAAIC,sBAAsB,EACrCC,aAAa,QACP,yBAAyB;;AAEhC;AACA;AACA;AACA,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,gCAAgC,QAAQ,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,QAAA,IAAAC,SAAA;AAEhE,MAAM;EAAEC;AAAqB,CAAC,GAAGN,MAAM,CAAEF,sBAAuB,CAAC;AAEjE,SAASS,gCAAgCA,CAAE;EAAEC;AAAU,CAAC,EAAG;EAC1D,MAAMC,qBAAqB,GAAGD,SAAS,CAACE,MAAM,KAAK,CAAC;EACpD,MAAM;IAAEC,IAAI;IAAEC;EAAe,CAAC,GAAGnB,SAAS,CACvCoB,MAAM,IAAM;IACb,MAAM;MAAEC,kBAAkB;MAAEC;IAAwB,CAAC,GACpDF,MAAM,CAAElB,gBAAiB,CAAC;IAC3B,MAAM;MAAEqB,YAAY;MAAEC;IAAwB,CAAC,G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,CACH,CAAC;IACD,MAAM2D,iBAAiB,GAAGV,iBAAiB,CAACE,KAAK,CAC9CvB,QAAQ,IACToB,0BAA0B,CAAEpB,QAAQ,EAAE,YAAY,EAAE,IAAK,CAAC,CACxDnB,MAAM,GAAG,CACb,CAAC;IACD,OAAO;MACNF,SAAS,EAAE0C,iBAAiB;MAC5BJ,mBAAmB,EAAEK,oBAAoB;MACzCJ,gBAAgB,EAAEa;IACnB,CAAC;EACF,CAAC,EACD,EACD,CAAC;EAED,OAAOd,mBAAmB,IAAIC,gBAAgB,gBAC7C5C,IAAA,CAACJ,aAAa;IAAC8D,KAAK,EAAC,QAAQ;IAAA3B,QAAA,eAC5B/B,IAAA,CAACI,gCAAgC;MAACC,SAAS,EAAGA;IAAW,CAAE;EAAC,CAC9C,CAAC,GACb,IAAI;AACT","ignoreList":[]}
|
|
@@ -42,7 +42,7 @@ function PatternOverridesControls({
|
|
|
42
42
|
const [showDisallowOverridesModal, setShowDisallowOverridesModal] = useState(false);
|
|
43
43
|
const hasName = !!attributes.metadata?.name;
|
|
44
44
|
const defaultBindings = attributes.metadata?.bindings?.__default;
|
|
45
|
-
const
|
|
45
|
+
const hasOverrides = hasName && defaultBindings?.source === PATTERN_OVERRIDES_BINDING_SOURCE;
|
|
46
46
|
const isConnectedToOtherSources = defaultBindings?.source && defaultBindings.source !== PATTERN_OVERRIDES_BINDING_SOURCE;
|
|
47
47
|
function updateBindings(isChecked, customName) {
|
|
48
48
|
const prevBindings = attributes?.metadata?.bindings;
|
|
@@ -64,7 +64,7 @@ function PatternOverridesControls({
|
|
|
64
64
|
return null;
|
|
65
65
|
}
|
|
66
66
|
const hasUnsupportedImageAttributes = blockName === 'core/image' && (!!attributes.caption?.length || !!attributes.href?.length);
|
|
67
|
-
const helpText = hasUnsupportedImageAttributes ? __(`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`) : __('Allow changes to this block throughout instances of this pattern.');
|
|
67
|
+
const helpText = !hasOverrides && hasUnsupportedImageAttributes ? __(`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`) : __('Allow changes to this block throughout instances of this pattern.');
|
|
68
68
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
69
69
|
children: [/*#__PURE__*/_jsx(InspectorControls, {
|
|
70
70
|
group: "advanced",
|
|
@@ -78,15 +78,15 @@ function PatternOverridesControls({
|
|
|
78
78
|
variant: "secondary",
|
|
79
79
|
"aria-haspopup": "dialog",
|
|
80
80
|
onClick: () => {
|
|
81
|
-
if (
|
|
81
|
+
if (hasOverrides) {
|
|
82
82
|
setShowDisallowOverridesModal(true);
|
|
83
83
|
} else {
|
|
84
84
|
setShowAllowOverridesModal(true);
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
|
-
disabled: hasUnsupportedImageAttributes,
|
|
88
|
-
|
|
89
|
-
children:
|
|
87
|
+
disabled: !hasOverrides && hasUnsupportedImageAttributes,
|
|
88
|
+
accessibleWhenDisabled: true,
|
|
89
|
+
children: hasOverrides ? __('Disable overrides') : __('Enable overrides')
|
|
90
90
|
})
|
|
91
91
|
})
|
|
92
92
|
}), showAllowOverridesModal && /*#__PURE__*/_jsx(AllowOverridesModal, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useState","useId","InspectorControls","BaseControl","Button","__","PATTERN_OVERRIDES_BINDING_SOURCE","AllowOverridesModal","DisallowOverridesModal","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","removeBindings","bindings","updatedBindings","__default","Object","keys","length","undefined","addBindings","source","PatternOverridesControls","attributes","setAttributes","name","blockName","controlId","showAllowOverridesModal","setShowAllowOverridesModal","showDisallowOverridesModal","setShowDisallowOverridesModal","hasName","metadata","defaultBindings","
|
|
1
|
+
{"version":3,"names":["useState","useId","InspectorControls","BaseControl","Button","__","PATTERN_OVERRIDES_BINDING_SOURCE","AllowOverridesModal","DisallowOverridesModal","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","removeBindings","bindings","updatedBindings","__default","Object","keys","length","undefined","addBindings","source","PatternOverridesControls","attributes","setAttributes","name","blockName","controlId","showAllowOverridesModal","setShowAllowOverridesModal","showDisallowOverridesModal","setShowDisallowOverridesModal","hasName","metadata","defaultBindings","hasOverrides","isConnectedToOtherSources","updateBindings","isChecked","customName","prevBindings","updatedMetadata","hasUnsupportedImageAttributes","caption","href","helpText","children","group","id","label","help","__next40pxDefaultSize","className","variant","onClick","disabled","accessibleWhenDisabled","initialName","onClose","onSave","newName"],"sources":["@wordpress/patterns/src/components/pattern-overrides-controls.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useId } from '@wordpress/element';\nimport { InspectorControls } from '@wordpress/block-editor';\nimport { BaseControl, Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_OVERRIDES_BINDING_SOURCE } from '../constants';\nimport {\n\tAllowOverridesModal,\n\tDisallowOverridesModal,\n} from './allow-overrides-modal';\n\nfunction removeBindings( bindings ) {\n\tlet updatedBindings = { ...bindings };\n\tdelete updatedBindings.__default;\n\tif ( ! Object.keys( updatedBindings ).length ) {\n\t\tupdatedBindings = undefined;\n\t}\n\treturn updatedBindings;\n}\n\nfunction addBindings( bindings ) {\n\treturn {\n\t\t...bindings,\n\t\t__default: { source: PATTERN_OVERRIDES_BINDING_SOURCE },\n\t};\n}\n\nfunction PatternOverridesControls( {\n\tattributes,\n\tsetAttributes,\n\tname: blockName,\n} ) {\n\tconst controlId = useId();\n\tconst [ showAllowOverridesModal, setShowAllowOverridesModal ] =\n\t\tuseState( false );\n\tconst [ showDisallowOverridesModal, setShowDisallowOverridesModal ] =\n\t\tuseState( false );\n\n\tconst hasName = !! attributes.metadata?.name;\n\tconst defaultBindings = attributes.metadata?.bindings?.__default;\n\tconst hasOverrides =\n\t\thasName && defaultBindings?.source === PATTERN_OVERRIDES_BINDING_SOURCE;\n\tconst isConnectedToOtherSources =\n\t\tdefaultBindings?.source &&\n\t\tdefaultBindings.source !== PATTERN_OVERRIDES_BINDING_SOURCE;\n\n\tfunction updateBindings( isChecked, customName ) {\n\t\tconst prevBindings = attributes?.metadata?.bindings;\n\t\tconst updatedBindings = isChecked\n\t\t\t? addBindings( prevBindings )\n\t\t\t: removeBindings( prevBindings );\n\n\t\tconst updatedMetadata = {\n\t\t\t...attributes.metadata,\n\t\t\tbindings: updatedBindings,\n\t\t};\n\n\t\tif ( customName ) {\n\t\t\tupdatedMetadata.name = customName;\n\t\t}\n\n\t\tsetAttributes( {\n\t\t\tmetadata: updatedMetadata,\n\t\t} );\n\t}\n\n\t// Avoid overwriting other (e.g. meta) bindings.\n\tif ( isConnectedToOtherSources ) {\n\t\treturn null;\n\t}\n\n\tconst hasUnsupportedImageAttributes =\n\t\tblockName === 'core/image' &&\n\t\t( !! attributes.caption?.length || !! attributes.href?.length );\n\n\tconst helpText =\n\t\t! hasOverrides && hasUnsupportedImageAttributes\n\t\t\t? __(\n\t\t\t\t\t`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`\n\t\t\t )\n\t\t\t: __(\n\t\t\t\t\t'Allow changes to this block throughout instances of this pattern.'\n\t\t\t );\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<BaseControl\n\t\t\t\t\tid={ controlId }\n\t\t\t\t\tlabel={ __( 'Overrides' ) }\n\t\t\t\t\thelp={ helpText }\n\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tclassName=\"pattern-overrides-control__allow-overrides-button\"\n\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tif ( hasOverrides ) {\n\t\t\t\t\t\t\t\tsetShowDisallowOverridesModal( true );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tsetShowAllowOverridesModal( true );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tdisabled={\n\t\t\t\t\t\t\t! hasOverrides && hasUnsupportedImageAttributes\n\t\t\t\t\t\t}\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t>\n\t\t\t\t\t\t{ hasOverrides\n\t\t\t\t\t\t\t? __( 'Disable overrides' )\n\t\t\t\t\t\t\t: __( 'Enable overrides' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</BaseControl>\n\t\t\t</InspectorControls>\n\n\t\t\t{ showAllowOverridesModal && (\n\t\t\t\t<AllowOverridesModal\n\t\t\t\t\tinitialName={ attributes.metadata?.name }\n\t\t\t\t\tonClose={ () => setShowAllowOverridesModal( false ) }\n\t\t\t\t\tonSave={ ( newName ) => {\n\t\t\t\t\t\tupdateBindings( true, newName );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showDisallowOverridesModal && (\n\t\t\t\t<DisallowOverridesModal\n\t\t\t\t\tonClose={ () => setShowDisallowOverridesModal( false ) }\n\t\t\t\t\tonSave={ () => updateBindings( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default PatternOverridesControls;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,KAAK,QAAQ,oBAAoB;AACpD,SAASC,iBAAiB,QAAQ,yBAAyB;AAC3D,SAASC,WAAW,EAAEC,MAAM,QAAQ,uBAAuB;AAC3D,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA,SAASC,gCAAgC,QAAQ,cAAc;AAC/D,SACCC,mBAAmB,EACnBC,sBAAsB,QAChB,yBAAyB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,QAAA,IAAAC,SAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AAEjC,SAASC,cAAcA,CAAEC,QAAQ,EAAG;EACnC,IAAIC,eAAe,GAAG;IAAE,GAAGD;EAAS,CAAC;EACrC,OAAOC,e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;MACnBqD,WAAW,EAAGlC,UAAU,CAACU,QAAQ,EAAER,IAAM;MACzCiC,OAAO,EAAGA,CAAA,KAAM7B,0BAA0B,CAAE,KAAM,CAAG;MACrD8B,MAAM,EAAKC,OAAO,IAAM;QACvBvB,cAAc,CAAE,IAAI,EAAEuB,OAAQ,CAAC;MAChC;IAAG,CACH,CACD,EACC9B,0BAA0B,iBAC3BvB,IAAA,CAACF,sBAAsB;MACtBqD,OAAO,EAAGA,CAAA,KAAM3B,6BAA6B,CAAE,KAAM,CAAG;MACxD4B,MAAM,EAAGA,CAAA,KAAMtB,cAAc,CAAE,KAAM;IAAG,CACxC,CACD;EAAA,CACA,CAAC;AAEL;AAEA,eAAef,wBAAwB","ignoreList":[]}
|
|
@@ -36,12 +36,19 @@ function PatternsManageButton({
|
|
|
36
36
|
const reusableBlock = getBlock(clientId);
|
|
37
37
|
return {
|
|
38
38
|
canRemove: canRemoveBlock(clientId),
|
|
39
|
-
isVisible: !!reusableBlock && isReusableBlock(reusableBlock) && !!canUser('update',
|
|
39
|
+
isVisible: !!reusableBlock && isReusableBlock(reusableBlock) && !!canUser('update', {
|
|
40
|
+
kind: 'postType',
|
|
41
|
+
name: 'wp_block',
|
|
42
|
+
id: reusableBlock.attributes.ref
|
|
43
|
+
}),
|
|
40
44
|
innerBlockCount: getBlockCount(clientId),
|
|
41
45
|
// The site editor and templates both check whether the user
|
|
42
46
|
// has edit_theme_options capabilities. We can leverage that here
|
|
43
47
|
// and omit the manage patterns link if the user can't access it.
|
|
44
|
-
managePatternsUrl: canUser('create',
|
|
48
|
+
managePatternsUrl: canUser('create', {
|
|
49
|
+
kind: 'postType',
|
|
50
|
+
name: 'wp_template'
|
|
51
|
+
}) ? addQueryArgs('site-editor.php', {
|
|
45
52
|
path: '/patterns'
|
|
46
53
|
}) : addQueryArgs('edit.php', {
|
|
47
54
|
post_type: 'wp_block'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["MenuItem","__","isReusableBlock","useSelect","useDispatch","store","blockEditorStore","addQueryArgs","coreStore","patternsStore","unlock","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","PatternsManageButton","clientId","canRemove","isVisible","managePatternsUrl","select","getBlock","canRemoveBlock","getBlockCount","canUser","reusableBlock","attributes","ref","innerBlockCount","path","post_type","convertSyncedPatternToStatic","children","onClick","href"],"sources":["@wordpress/patterns/src/components/patterns-manage-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nfunction PatternsManageButton( { clientId } ) {\n\tconst { canRemove, isVisible, managePatternsUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, canRemoveBlock, getBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst reusableBlock = getBlock( clientId );\n\n\t\t\treturn {\n\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\tisVisible:\n\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t!! canUser(\n\t\t\t\t\t\
|
|
1
|
+
{"version":3,"names":["MenuItem","__","isReusableBlock","useSelect","useDispatch","store","blockEditorStore","addQueryArgs","coreStore","patternsStore","unlock","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","PatternsManageButton","clientId","canRemove","isVisible","managePatternsUrl","select","getBlock","canRemoveBlock","getBlockCount","canUser","reusableBlock","kind","name","id","attributes","ref","innerBlockCount","path","post_type","convertSyncedPatternToStatic","children","onClick","href"],"sources":["@wordpress/patterns/src/components/patterns-manage-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nfunction PatternsManageButton( { clientId } ) {\n\tconst { canRemove, isVisible, managePatternsUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, canRemoveBlock, getBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst reusableBlock = getBlock( clientId );\n\n\t\t\treturn {\n\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\tisVisible:\n\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t!! canUser( 'update', {\n\t\t\t\t\t\tkind: 'postType',\n\t\t\t\t\t\tname: 'wp_block',\n\t\t\t\t\t\tid: reusableBlock.attributes.ref,\n\t\t\t\t\t} ),\n\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t// The site editor and templates both check whether the user\n\t\t\t\t// has edit_theme_options capabilities. We can leverage that here\n\t\t\t\t// and omit the manage patterns link if the user can't access it.\n\t\t\t\tmanagePatternsUrl: canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_template',\n\t\t\t\t} )\n\t\t\t\t\t? addQueryArgs( 'site-editor.php', {\n\t\t\t\t\t\t\tpath: '/patterns',\n\t\t\t\t\t } )\n\t\t\t\t\t: addQueryArgs( 'edit.php', {\n\t\t\t\t\t\t\tpost_type: 'wp_block',\n\t\t\t\t\t } ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { convertSyncedPatternToStatic } = unlock(\n\t\tuseDispatch( patternsStore )\n\t);\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ canRemove && (\n\t\t\t\t<MenuItem\n\t\t\t\t\tonClick={ () => convertSyncedPatternToStatic( clientId ) }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Detach' ) }\n\t\t\t\t</MenuItem>\n\t\t\t) }\n\t\t\t<MenuItem href={ managePatternsUrl }>\n\t\t\t\t{ __( 'Manage patterns' ) }\n\t\t\t</MenuItem>\n\t\t</>\n\t);\n}\n\nexport default PatternsManageButton;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SAASF,KAAK,IAAIG,SAAS,QAAQ,sBAAsB;;AAEzD;AACA;AACA;AACA,SAASH,KAAK,IAAII,aAAa,QAAQ,UAAU;AACjD,SAASC,MAAM,QAAQ,gBAAgB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,QAAA,IAAAC,SAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AAExC,SAASC,oBAAoBA,CAAE;EAAEC;AAAS,CAAC,EAAG;EAC7C,MAAM;IAAEC,SAAS;IAAEC,SAAS;IAAEC;EAAkB,CAAC,GAAGlB,SAAS,CAC1DmB,MAAM,IAAM;IACb,MAAM;MAAEC,QAAQ;MAAEC,cAAc;MAAEC;IAAc,CAAC,GAChDH,MAAM,CAAEhB,gBAAiB,CAAC;IAC3B,MAAM;MAAE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,CACV,CAAC;AAEL;AAEA,eAAegB,oBAAoB","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { store as blockEditorStore,
|
|
4
|
+
import { store as blockEditorStore, __unstableBlockToolbarLastItem as BlockToolbarLastItem } from '@wordpress/block-editor';
|
|
5
5
|
import { ToolbarButton, ToolbarGroup } from '@wordpress/components';
|
|
6
6
|
import { useRegistry, useSelect } from '@wordpress/data';
|
|
7
7
|
import { __ } from '@wordpress/i18n';
|
|
@@ -57,13 +57,11 @@ export default function ResetOverridesControl(props) {
|
|
|
57
57
|
[CONTENT]: newOverrides
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
return /*#__PURE__*/_jsx(
|
|
61
|
-
group: "other",
|
|
60
|
+
return /*#__PURE__*/_jsx(BlockToolbarLastItem, {
|
|
62
61
|
children: /*#__PURE__*/_jsx(ToolbarGroup, {
|
|
63
62
|
children: /*#__PURE__*/_jsx(ToolbarButton, {
|
|
64
63
|
onClick: onClick,
|
|
65
64
|
disabled: !isOverriden,
|
|
66
|
-
__experimentalIsFocusable: true,
|
|
67
65
|
children: __('Reset')
|
|
68
66
|
})
|
|
69
67
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["store","blockEditorStore","
|
|
1
|
+
{"version":3,"names":["store","blockEditorStore","__unstableBlockToolbarLastItem","BlockToolbarLastItem","ToolbarButton","ToolbarGroup","useRegistry","useSelect","__","jsx","_jsx","CONTENT","ResetOverridesControl","props","name","attributes","metadata","registry","isOverriden","select","getBlockAttributes","getBlockParentsByBlockName","patternClientId","clientId","overrides","hasOwnProperty","onClick","updateBlockAttributes","__unstableMarkLastChangeAsPersistent","dispatch","newOverrides","Object","keys","length","undefined","children","disabled"],"sources":["@wordpress/patterns/src/components/reset-overrides-control.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tstore as blockEditorStore,\n\t__unstableBlockToolbarLastItem as BlockToolbarLastItem,\n} from '@wordpress/block-editor';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\n\nconst CONTENT = 'content';\n\nexport default function ResetOverridesControl( props ) {\n\tconst name = props.attributes.metadata?.name;\n\tconst registry = useRegistry();\n\tconst isOverriden = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! name ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { getBlockAttributes, getBlockParentsByBlockName } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst [ patternClientId ] = getBlockParentsByBlockName(\n\t\t\t\tprops.clientId,\n\t\t\t\t'core/block',\n\t\t\t\ttrue\n\t\t\t);\n\n\t\t\tif ( ! patternClientId ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst overrides = getBlockAttributes( patternClientId )[ CONTENT ];\n\n\t\t\tif ( ! overrides ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\treturn overrides.hasOwnProperty( name );\n\t\t},\n\t\t[ props.clientId, name ]\n\t);\n\n\tfunction onClick() {\n\t\tconst { getBlockAttributes, getBlockParentsByBlockName } =\n\t\t\tregistry.select( blockEditorStore );\n\t\tconst [ patternClientId ] = getBlockParentsByBlockName(\n\t\t\tprops.clientId,\n\t\t\t'core/block',\n\t\t\ttrue\n\t\t);\n\n\t\tif ( ! patternClientId ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst overrides = getBlockAttributes( patternClientId )[ CONTENT ];\n\n\t\tif ( ! overrides.hasOwnProperty( name ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { updateBlockAttributes, __unstableMarkLastChangeAsPersistent } =\n\t\t\tregistry.dispatch( blockEditorStore );\n\t\t__unstableMarkLastChangeAsPersistent();\n\n\t\tlet newOverrides = { ...overrides };\n\t\tdelete newOverrides[ name ];\n\n\t\tif ( ! Object.keys( newOverrides ).length ) {\n\t\t\tnewOverrides = undefined;\n\t\t}\n\n\t\tupdateBlockAttributes( patternClientId, {\n\t\t\t[ CONTENT ]: newOverrides,\n\t\t} );\n\t}\n\n\treturn (\n\t\t<BlockToolbarLastItem>\n\t\t\t<ToolbarGroup>\n\t\t\t\t<ToolbarButton onClick={ onClick } disabled={ ! isOverriden }>\n\t\t\t\t\t{ __( 'Reset' ) }\n\t\t\t\t</ToolbarButton>\n\t\t\t</ToolbarGroup>\n\t\t</BlockToolbarLastItem>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,KAAK,IAAIC,gBAAgB,EACzBC,8BAA8B,IAAIC,oBAAoB,QAChD,yBAAyB;AAChC,SAASC,aAAa,EAAEC,YAAY,QAAQ,uBAAuB;AACnE,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,EAAE,QAAQ,iBAAiB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAErC,MAAMC,OAAO,GAAG,SAAS;AAEzB,eAAe,SAASC,qBAAqBA,CAAEC,KAAK,EAAG;EACtD,MAAMC,IAAI,GAAGD,KAAK,CAACE,UAAU,CAACC,QAAQ,EAAEF,IAAI;EAC5C,MAAMG,QAAQ,GAAGX,WAAW,CAAC,CAAC;EAC9B,MAAMY,WAAW,GAAGX,SAAS,CAC1BY,MAAM,IAAM;IACb,IAAK,CAAEL,IAAI,EAAG;MACb;IACD;IAEA,MAAM;MAAEM,kBAAkB;MAAEC;IAA2B,CAAC,GACvDF,MAAM,CAAElB,gBAAiB,CAAC;IAC3B,MAAM,CAAEqB,eAAe,CAAE,GAAGD,0BAA0B,CACrDR,KAAK,CAACU,QAAQ,EACd,YAAY,EACZ,IACD,CAAC;IAED,IAAK,CAAED,eAAe,EAAG;MACxB;IACD;IAEA,MAAME,SAAS,GAAGJ,kBAAkB,CAAEE,eAAgB,CAAC,CAAEX,OAAO,CAAE;IAElE,IAAK,CAAEa,SAAS,EAAG;MAClB;IACD;IAEA,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ED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/patterns",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Management of user pattern editing.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -32,20 +32,20 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/runtime": "^7.16.0",
|
|
35
|
-
"@wordpress/a11y": "^4.
|
|
36
|
-
"@wordpress/block-editor": "^13.
|
|
37
|
-
"@wordpress/blocks": "^13.
|
|
38
|
-
"@wordpress/components": "^28.
|
|
39
|
-
"@wordpress/compose": "^7.
|
|
40
|
-
"@wordpress/core-data": "^7.
|
|
41
|
-
"@wordpress/data": "^10.
|
|
42
|
-
"@wordpress/element": "^6.
|
|
43
|
-
"@wordpress/html-entities": "^4.
|
|
44
|
-
"@wordpress/i18n": "^5.
|
|
45
|
-
"@wordpress/icons": "^10.
|
|
46
|
-
"@wordpress/notices": "^5.
|
|
47
|
-
"@wordpress/private-apis": "^1.
|
|
48
|
-
"@wordpress/url": "^4.
|
|
35
|
+
"@wordpress/a11y": "^4.4.0",
|
|
36
|
+
"@wordpress/block-editor": "^13.4.0",
|
|
37
|
+
"@wordpress/blocks": "^13.4.0",
|
|
38
|
+
"@wordpress/components": "^28.4.0",
|
|
39
|
+
"@wordpress/compose": "^7.4.0",
|
|
40
|
+
"@wordpress/core-data": "^7.4.0",
|
|
41
|
+
"@wordpress/data": "^10.4.0",
|
|
42
|
+
"@wordpress/element": "^6.4.0",
|
|
43
|
+
"@wordpress/html-entities": "^4.4.0",
|
|
44
|
+
"@wordpress/i18n": "^5.4.0",
|
|
45
|
+
"@wordpress/icons": "^10.4.0",
|
|
46
|
+
"@wordpress/notices": "^5.4.0",
|
|
47
|
+
"@wordpress/private-apis": "^1.4.0",
|
|
48
|
+
"@wordpress/url": "^4.4.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"react": "^18.0.0",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "363edb39b8dda8727f652e42cbb8497732693ed2"
|
|
58
58
|
}
|
|
@@ -86,7 +86,10 @@ export default function PatternConvertButton( {
|
|
|
86
86
|
) &&
|
|
87
87
|
// Hide when current doesn't have permission to do that.
|
|
88
88
|
// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.
|
|
89
|
-
!! canUser( 'create',
|
|
89
|
+
!! canUser( 'create', {
|
|
90
|
+
kind: 'postType',
|
|
91
|
+
name: 'wp_block',
|
|
92
|
+
} );
|
|
90
93
|
|
|
91
94
|
return _canConvert;
|
|
92
95
|
},
|
|
@@ -44,7 +44,7 @@ function PatternOverridesControls( {
|
|
|
44
44
|
|
|
45
45
|
const hasName = !! attributes.metadata?.name;
|
|
46
46
|
const defaultBindings = attributes.metadata?.bindings?.__default;
|
|
47
|
-
const
|
|
47
|
+
const hasOverrides =
|
|
48
48
|
hasName && defaultBindings?.source === PATTERN_OVERRIDES_BINDING_SOURCE;
|
|
49
49
|
const isConnectedToOtherSources =
|
|
50
50
|
defaultBindings?.source &&
|
|
@@ -79,13 +79,14 @@ function PatternOverridesControls( {
|
|
|
79
79
|
blockName === 'core/image' &&
|
|
80
80
|
( !! attributes.caption?.length || !! attributes.href?.length );
|
|
81
81
|
|
|
82
|
-
const helpText =
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
const helpText =
|
|
83
|
+
! hasOverrides && hasUnsupportedImageAttributes
|
|
84
|
+
? __(
|
|
85
|
+
`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`
|
|
86
|
+
)
|
|
87
|
+
: __(
|
|
88
|
+
'Allow changes to this block throughout instances of this pattern.'
|
|
89
|
+
);
|
|
89
90
|
|
|
90
91
|
return (
|
|
91
92
|
<>
|
|
@@ -101,16 +102,18 @@ function PatternOverridesControls( {
|
|
|
101
102
|
variant="secondary"
|
|
102
103
|
aria-haspopup="dialog"
|
|
103
104
|
onClick={ () => {
|
|
104
|
-
if (
|
|
105
|
+
if ( hasOverrides ) {
|
|
105
106
|
setShowDisallowOverridesModal( true );
|
|
106
107
|
} else {
|
|
107
108
|
setShowAllowOverridesModal( true );
|
|
108
109
|
}
|
|
109
110
|
} }
|
|
110
|
-
disabled={
|
|
111
|
-
|
|
111
|
+
disabled={
|
|
112
|
+
! hasOverrides && hasUnsupportedImageAttributes
|
|
113
|
+
}
|
|
114
|
+
accessibleWhenDisabled
|
|
112
115
|
>
|
|
113
|
-
{
|
|
116
|
+
{ hasOverrides
|
|
114
117
|
? __( 'Disable overrides' )
|
|
115
118
|
: __( 'Enable overrides' ) }
|
|
116
119
|
</Button>
|
|
@@ -28,16 +28,19 @@ function PatternsManageButton( { clientId } ) {
|
|
|
28
28
|
isVisible:
|
|
29
29
|
!! reusableBlock &&
|
|
30
30
|
isReusableBlock( reusableBlock ) &&
|
|
31
|
-
!! canUser(
|
|
32
|
-
'
|
|
33
|
-
'
|
|
34
|
-
reusableBlock.attributes.ref
|
|
35
|
-
),
|
|
31
|
+
!! canUser( 'update', {
|
|
32
|
+
kind: 'postType',
|
|
33
|
+
name: 'wp_block',
|
|
34
|
+
id: reusableBlock.attributes.ref,
|
|
35
|
+
} ),
|
|
36
36
|
innerBlockCount: getBlockCount( clientId ),
|
|
37
37
|
// The site editor and templates both check whether the user
|
|
38
38
|
// has edit_theme_options capabilities. We can leverage that here
|
|
39
39
|
// and omit the manage patterns link if the user can't access it.
|
|
40
|
-
managePatternsUrl: canUser( 'create',
|
|
40
|
+
managePatternsUrl: canUser( 'create', {
|
|
41
|
+
kind: 'postType',
|
|
42
|
+
name: 'wp_template',
|
|
43
|
+
} )
|
|
41
44
|
? addQueryArgs( 'site-editor.php', {
|
|
42
45
|
path: '/patterns',
|
|
43
46
|
} )
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import {
|
|
5
5
|
store as blockEditorStore,
|
|
6
|
-
|
|
6
|
+
__unstableBlockToolbarLastItem as BlockToolbarLastItem,
|
|
7
7
|
} from '@wordpress/block-editor';
|
|
8
8
|
import { ToolbarButton, ToolbarGroup } from '@wordpress/components';
|
|
9
9
|
import { useRegistry, useSelect } from '@wordpress/data';
|
|
@@ -79,16 +79,12 @@ export default function ResetOverridesControl( props ) {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
return (
|
|
82
|
-
<
|
|
82
|
+
<BlockToolbarLastItem>
|
|
83
83
|
<ToolbarGroup>
|
|
84
|
-
<ToolbarButton
|
|
85
|
-
onClick={ onClick }
|
|
86
|
-
disabled={ ! isOverriden }
|
|
87
|
-
__experimentalIsFocusable
|
|
88
|
-
>
|
|
84
|
+
<ToolbarButton onClick={ onClick } disabled={ ! isOverriden }>
|
|
89
85
|
{ __( 'Reset' ) }
|
|
90
86
|
</ToolbarButton>
|
|
91
87
|
</ToolbarGroup>
|
|
92
|
-
</
|
|
88
|
+
</BlockToolbarLastItem>
|
|
93
89
|
);
|
|
94
90
|
}
|