@wordpress/patterns 2.12.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/duplicate-pattern-modal.js +1 -1
- package/build/components/duplicate-pattern-modal.js.map +1 -1
- package/build/components/pattern-convert-button.js +10 -1
- package/build/components/pattern-convert-button.js.map +1 -1
- package/build-module/components/duplicate-pattern-modal.js +1 -1
- package/build-module/components/duplicate-pattern-modal.js.map +1 -1
- package/build-module/components/pattern-convert-button.js +11 -2
- package/build-module/components/pattern-convert-button.js.map +1 -1
- package/package.json +2 -2
- package/src/components/duplicate-pattern-modal.js +1 -1
- package/src/components/pattern-convert-button.js +11 -1
package/CHANGELOG.md
CHANGED
|
@@ -26,7 +26,7 @@ function getTermLabels(pattern, categories) {
|
|
|
26
26
|
if (pattern.type !== _constants.PATTERN_TYPES.user) {
|
|
27
27
|
return categories.core?.filter(category => pattern.categories?.includes(category.name)).map(category => category.label);
|
|
28
28
|
}
|
|
29
|
-
return categories.user?.filter(category => pattern.wp_pattern_category
|
|
29
|
+
return categories.user?.filter(category => pattern.wp_pattern_category?.includes(category.id)).map(category => category.label);
|
|
30
30
|
}
|
|
31
31
|
function useDuplicatePatternProps({
|
|
32
32
|
pattern,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_coreData","require","_data","_i18n","_notices","_createPatternModal","_interopRequireDefault","_constants","_jsxRuntime","getTermLabels","pattern","categories","type","PATTERN_TYPES","user","core","filter","category","includes","name","map","label","wp_pattern_category","id","useDuplicatePatternProps","onSuccess","createSuccessNotice","useDispatch","noticesStore","useSelect","select","getUserPatternCategories","getBlockPatternCategories","coreStore","content","defaultCategories","defaultSyncType","PATTERN_SYNC_TYPES","unsynced","wp_pattern_sync_status","full","defaultTitle","sprintf","_x","title","raw","newPattern","DuplicatePatternModal","onClose","duplicatedProps","jsx","default","modalTitle","__","confirmLabel","onError"],"sources":["@wordpress/patterns/src/components/duplicate-pattern-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport CreatePatternModal from './create-pattern-modal';\nimport { PATTERN_SYNC_TYPES, PATTERN_TYPES } from '../constants';\n\nfunction getTermLabels( pattern, categories ) {\n\t// Theme patterns rely on core pattern categories.\n\tif ( pattern.type !== PATTERN_TYPES.user ) {\n\t\treturn categories.core\n\t\t\t?.filter( ( category ) =>\n\t\t\t\tpattern.categories?.includes( category.name )\n\t\t\t)\n\t\t\t.map( ( category ) => category.label );\n\t}\n\n\treturn categories.user\n\t\t?.filter( ( category ) =>\n\t\t\tpattern.wp_pattern_category
|
|
1
|
+
{"version":3,"names":["_coreData","require","_data","_i18n","_notices","_createPatternModal","_interopRequireDefault","_constants","_jsxRuntime","getTermLabels","pattern","categories","type","PATTERN_TYPES","user","core","filter","category","includes","name","map","label","wp_pattern_category","id","useDuplicatePatternProps","onSuccess","createSuccessNotice","useDispatch","noticesStore","useSelect","select","getUserPatternCategories","getBlockPatternCategories","coreStore","content","defaultCategories","defaultSyncType","PATTERN_SYNC_TYPES","unsynced","wp_pattern_sync_status","full","defaultTitle","sprintf","_x","title","raw","newPattern","DuplicatePatternModal","onClose","duplicatedProps","jsx","default","modalTitle","__","confirmLabel","onError"],"sources":["@wordpress/patterns/src/components/duplicate-pattern-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport CreatePatternModal from './create-pattern-modal';\nimport { PATTERN_SYNC_TYPES, PATTERN_TYPES } from '../constants';\n\nfunction getTermLabels( pattern, categories ) {\n\t// Theme patterns rely on core pattern categories.\n\tif ( pattern.type !== PATTERN_TYPES.user ) {\n\t\treturn categories.core\n\t\t\t?.filter( ( category ) =>\n\t\t\t\tpattern.categories?.includes( category.name )\n\t\t\t)\n\t\t\t.map( ( category ) => category.label );\n\t}\n\n\treturn categories.user\n\t\t?.filter( ( category ) =>\n\t\t\tpattern.wp_pattern_category?.includes( category.id )\n\t\t)\n\t\t.map( ( category ) => category.label );\n}\n\nexport function useDuplicatePatternProps( { pattern, onSuccess } ) {\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst categories = useSelect( ( select ) => {\n\t\tconst { getUserPatternCategories, getBlockPatternCategories } =\n\t\t\tselect( coreStore );\n\n\t\treturn {\n\t\t\tcore: getBlockPatternCategories(),\n\t\t\tuser: getUserPatternCategories(),\n\t\t};\n\t} );\n\tif ( ! pattern ) {\n\t\treturn null;\n\t}\n\treturn {\n\t\tcontent: pattern.content,\n\t\tdefaultCategories: getTermLabels( pattern, categories ),\n\t\tdefaultSyncType:\n\t\t\tpattern.type !== PATTERN_TYPES.user // Theme patterns are unsynced by default.\n\t\t\t\t? PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t: pattern.wp_pattern_sync_status || PATTERN_SYNC_TYPES.full,\n\t\tdefaultTitle: sprintf(\n\t\t\t/* translators: %s: Existing pattern title */\n\t\t\t_x( '%s (Copy)', 'pattern' ),\n\t\t\ttypeof pattern.title === 'string'\n\t\t\t\t? pattern.title\n\t\t\t\t: pattern.title.raw\n\t\t),\n\t\tonSuccess: ( { pattern: newPattern } ) => {\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: The new pattern's title e.g. 'Call to action (copy)'.\n\t\t\t\t\t_x( '\"%s\" duplicated.', 'pattern' ),\n\t\t\t\t\tnewPattern.title.raw\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'patterns-create',\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tonSuccess?.( { pattern: newPattern } );\n\t\t},\n\t};\n}\n\nexport default function DuplicatePatternModal( {\n\tpattern,\n\tonClose,\n\tonSuccess,\n} ) {\n\tconst duplicatedProps = useDuplicatePatternProps( { pattern, onSuccess } );\n\tif ( ! pattern ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<CreatePatternModal\n\t\t\tmodalTitle={ __( 'Duplicate pattern' ) }\n\t\t\tconfirmLabel={ __( 'Duplicate' ) }\n\t\t\tonClose={ onClose }\n\t\t\tonError={ onClose }\n\t\t\t{ ...duplicatedProps }\n\t\t/>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAKA,IAAAI,mBAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AAAiE,IAAAO,WAAA,GAAAP,OAAA;AAZjE;AACA;AACA;;AAMA;AACA;AACA;;AAIA,SAASQ,aAAaA,CAAEC,OAAO,EAAEC,UAAU,EAAG;EAC7C;EACA,IAAKD,OAAO,CAACE,IAAI,KAAKC,wBAAa,CAACC,IAAI,EAAG;IAC1C,OAAOH,UAAU,CAACI,IAAI,EACnBC,MAAM,CAAIC,QAAQ,IACnBP,OAAO,CAACC,UAAU,EAAEO,QAAQ,CAAED,QAAQ,CAACE,IAAK,CAC7C,CAAC,CACAC,GAAG,CAAIH,QAAQ,IAAMA,QAAQ,CAACI,KAAM,CAAC;EACxC;EAEA,OAAOV,UAAU,CAACG,IAAI,EACnBE,MAAM,CAAIC,QAAQ,IACnBP,OAAO,CAACY,mBAAmB,EAAEJ,QAAQ,CAAED,QAAQ,CAACM,EAAG,CACpD,CAAC,CACAH,GAAG,CAAIH,QAAQ,IAAMA,QAAQ,CAACI,KAAM,CAAC;AACxC;AAEO,SAAS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AAO,EAAEoC;MAAW,CAAE,CAAC;IACvC;EACD,CAAC;AACF;AAEe,SAASC,qBAAqBA,CAAE;EAC9CrC,OAAO;EACPsC,OAAO;EACPvB;AACD,CAAC,EAAG;EACH,MAAMwB,eAAe,GAAGzB,wBAAwB,CAAE;IAAEd,OAAO;IAAEe;EAAU,CAAE,CAAC;EAC1E,IAAK,CAAEf,OAAO,EAAG;IAChB,OAAO,IAAI;EACZ;EACA,oBACC,IAAAF,WAAA,CAAA0C,GAAA,EAAC7C,mBAAA,CAAA8C,OAAkB;IAClBC,UAAU,EAAG,IAAAC,QAAE,EAAE,mBAAoB,CAAG;IACxCC,YAAY,EAAG,IAAAD,QAAE,EAAE,WAAY,CAAG;IAClCL,OAAO,EAAGA,OAAS;IACnBO,OAAO,EAAGP,OAAS;IAAA,GACdC;EAAe,CACpB,CAAC;AAEJ","ignoreList":[]}
|
|
@@ -64,6 +64,15 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
64
64
|
} = select(_blockEditor.store);
|
|
65
65
|
const rootId = rootClientId || (clientIds.length > 0 ? getBlockRootClientId(clientIds[0]) : undefined);
|
|
66
66
|
const blocks = (_getBlocksByClientId = getBlocksByClientId(clientIds)) !== null && _getBlocksByClientId !== void 0 ? _getBlocksByClientId : [];
|
|
67
|
+
|
|
68
|
+
// Check if the block has reusable support defined.
|
|
69
|
+
const hasReusableBlockSupport = blockName => {
|
|
70
|
+
const blockType = (0, _blocks.getBlockType)(blockName);
|
|
71
|
+
const hasParent = blockType && 'parent' in blockType;
|
|
72
|
+
|
|
73
|
+
// If the block has a parent, check with false as default, otherwise with true.
|
|
74
|
+
return (0, _blocks.hasBlockSupport)(blockName, 'reusable', !hasParent);
|
|
75
|
+
};
|
|
67
76
|
const isReusable = blocks.length === 1 && blocks[0] && (0, _blocks.isReusableBlock)(blocks[0]) && !!select(_coreData.store).getEntityRecord('postType', 'wp_block', blocks[0].attributes.ref);
|
|
68
77
|
const _canConvert =
|
|
69
78
|
// Hide when this is already a synced pattern.
|
|
@@ -75,7 +84,7 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
75
84
|
// Hide on invalid blocks.
|
|
76
85
|
block.isValid &&
|
|
77
86
|
// Hide when block doesn't support being made into a pattern.
|
|
78
|
-
(
|
|
87
|
+
hasReusableBlockSupport(block.name)) &&
|
|
79
88
|
// Hide when current doesn't have permission to do that.
|
|
80
89
|
// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.
|
|
81
90
|
!!canUser('create', {
|
|
@@ -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","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\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,W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AC;MAC5ChD,sBAAsB,CAAC,CAAC;IACzB;IAEAC,mBAAmB,CAClBwC,OAAO,CAACC,sBAAsB,KAAKC,6BAAkB,CAACC,QAAQ,GAC3D,IAAAK,aAAO;IACP;IACA,IAAAC,QAAE,EAAE,8BAA+B,CAAC,EACpCT,OAAO,CAACU,KAAK,CAACC,GACd,CAAC,GACD,IAAAH,aAAO;IACP;IACA,IAAAC,QAAE,EAAE,4BAA6B,CAAC,EAClCT,OAAO,CAACU,KAAK,CAACC,GACd,CAAC,EACJ;MACCC,IAAI,EAAE,UAAU;MAChBN,EAAE,EAAE;IACL,CACD,CAAC;IACDrC,cAAc,CAAE,KAAM,CAAC;EACxB,CAAC;EACD,oBACC,IAAAd,WAAA,CAAA0D,IAAA,EAAA1D,WAAA,CAAA2D,QAAA;IAAAC,QAAA,gBACC,IAAA5D,WAAA,CAAA6D,GAAA,EAACxE,WAAA,CAAAyE,QAAQ;MACRC,IAAI,EAAGC,aAAQ;MACfC,OAAO,EAAGA,CAAA,KAAMnD,cAAc,CAAE,IAAK,CAAG;MACxC,iBAAgBD,WAAa;MAC7B,iBAAc,QAAQ;MAAA+C,QAAA,EAEpB,IAAAN,QAAE,EAAE,gBAAiB;IAAC,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
|
+
{"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","hasReusableBlockSupport","blockName","blockType","getBlockType","hasParent","hasBlockSupport","isReusable","isReusableBlock","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","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\tgetBlockType,\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\t// Check if the block has reusable support defined.\n\t\t\tconst hasReusableBlockSupport = ( blockName ) => {\n\t\t\t\tconst blockType = getBlockType( blockName );\n\t\t\t\tconst hasParent = blockType && 'parent' in blockType;\n\n\t\t\t\t// If the block has a parent, check with false as default, otherwise with true.\n\t\t\t\treturn hasBlockSupport( blockName, 'reusable', ! hasParent );\n\t\t\t};\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\thasReusableBlockSupport( block.name )\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":";;;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AAOA,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;AAxBlD;AACA;AACA;;AAgBA;AACA;AACA;;AAMA;AACA;AACA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AAC;AAEL","ignoreList":[]}
|
|
@@ -17,7 +17,7 @@ function getTermLabels(pattern, categories) {
|
|
|
17
17
|
if (pattern.type !== PATTERN_TYPES.user) {
|
|
18
18
|
return categories.core?.filter(category => pattern.categories?.includes(category.name)).map(category => category.label);
|
|
19
19
|
}
|
|
20
|
-
return categories.user?.filter(category => pattern.wp_pattern_category
|
|
20
|
+
return categories.user?.filter(category => pattern.wp_pattern_category?.includes(category.id)).map(category => category.label);
|
|
21
21
|
}
|
|
22
22
|
export function useDuplicatePatternProps({
|
|
23
23
|
pattern,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["store","coreStore","useDispatch","useSelect","__","_x","sprintf","noticesStore","CreatePatternModal","PATTERN_SYNC_TYPES","PATTERN_TYPES","jsx","_jsx","getTermLabels","pattern","categories","type","user","core","filter","category","includes","name","map","label","wp_pattern_category","id","useDuplicatePatternProps","onSuccess","createSuccessNotice","select","getUserPatternCategories","getBlockPatternCategories","content","defaultCategories","defaultSyncType","unsynced","wp_pattern_sync_status","full","defaultTitle","title","raw","newPattern","DuplicatePatternModal","onClose","duplicatedProps","modalTitle","confirmLabel","onError"],"sources":["@wordpress/patterns/src/components/duplicate-pattern-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport CreatePatternModal from './create-pattern-modal';\nimport { PATTERN_SYNC_TYPES, PATTERN_TYPES } from '../constants';\n\nfunction getTermLabels( pattern, categories ) {\n\t// Theme patterns rely on core pattern categories.\n\tif ( pattern.type !== PATTERN_TYPES.user ) {\n\t\treturn categories.core\n\t\t\t?.filter( ( category ) =>\n\t\t\t\tpattern.categories?.includes( category.name )\n\t\t\t)\n\t\t\t.map( ( category ) => category.label );\n\t}\n\n\treturn categories.user\n\t\t?.filter( ( category ) =>\n\t\t\tpattern.wp_pattern_category
|
|
1
|
+
{"version":3,"names":["store","coreStore","useDispatch","useSelect","__","_x","sprintf","noticesStore","CreatePatternModal","PATTERN_SYNC_TYPES","PATTERN_TYPES","jsx","_jsx","getTermLabels","pattern","categories","type","user","core","filter","category","includes","name","map","label","wp_pattern_category","id","useDuplicatePatternProps","onSuccess","createSuccessNotice","select","getUserPatternCategories","getBlockPatternCategories","content","defaultCategories","defaultSyncType","unsynced","wp_pattern_sync_status","full","defaultTitle","title","raw","newPattern","DuplicatePatternModal","onClose","duplicatedProps","modalTitle","confirmLabel","onError"],"sources":["@wordpress/patterns/src/components/duplicate-pattern-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport CreatePatternModal from './create-pattern-modal';\nimport { PATTERN_SYNC_TYPES, PATTERN_TYPES } from '../constants';\n\nfunction getTermLabels( pattern, categories ) {\n\t// Theme patterns rely on core pattern categories.\n\tif ( pattern.type !== PATTERN_TYPES.user ) {\n\t\treturn categories.core\n\t\t\t?.filter( ( category ) =>\n\t\t\t\tpattern.categories?.includes( category.name )\n\t\t\t)\n\t\t\t.map( ( category ) => category.label );\n\t}\n\n\treturn categories.user\n\t\t?.filter( ( category ) =>\n\t\t\tpattern.wp_pattern_category?.includes( category.id )\n\t\t)\n\t\t.map( ( category ) => category.label );\n}\n\nexport function useDuplicatePatternProps( { pattern, onSuccess } ) {\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst categories = useSelect( ( select ) => {\n\t\tconst { getUserPatternCategories, getBlockPatternCategories } =\n\t\t\tselect( coreStore );\n\n\t\treturn {\n\t\t\tcore: getBlockPatternCategories(),\n\t\t\tuser: getUserPatternCategories(),\n\t\t};\n\t} );\n\tif ( ! pattern ) {\n\t\treturn null;\n\t}\n\treturn {\n\t\tcontent: pattern.content,\n\t\tdefaultCategories: getTermLabels( pattern, categories ),\n\t\tdefaultSyncType:\n\t\t\tpattern.type !== PATTERN_TYPES.user // Theme patterns are unsynced by default.\n\t\t\t\t? PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t: pattern.wp_pattern_sync_status || PATTERN_SYNC_TYPES.full,\n\t\tdefaultTitle: sprintf(\n\t\t\t/* translators: %s: Existing pattern title */\n\t\t\t_x( '%s (Copy)', 'pattern' ),\n\t\t\ttypeof pattern.title === 'string'\n\t\t\t\t? pattern.title\n\t\t\t\t: pattern.title.raw\n\t\t),\n\t\tonSuccess: ( { pattern: newPattern } ) => {\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: The new pattern's title e.g. 'Call to action (copy)'.\n\t\t\t\t\t_x( '\"%s\" duplicated.', 'pattern' ),\n\t\t\t\t\tnewPattern.title.raw\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'patterns-create',\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tonSuccess?.( { pattern: newPattern } );\n\t\t},\n\t};\n}\n\nexport default function DuplicatePatternModal( {\n\tpattern,\n\tonClose,\n\tonSuccess,\n} ) {\n\tconst duplicatedProps = useDuplicatePatternProps( { pattern, onSuccess } );\n\tif ( ! pattern ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<CreatePatternModal\n\t\t\tmodalTitle={ __( 'Duplicate pattern' ) }\n\t\t\tconfirmLabel={ __( 'Duplicate' ) }\n\t\t\tonClose={ onClose }\n\t\t\tonError={ onClose }\n\t\t\t{ ...duplicatedProps }\n\t\t/>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,EAAE,EAAEC,EAAE,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]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { hasBlockSupport, isReusableBlock, createBlock, serialize } from '@wordpress/blocks';
|
|
4
|
+
import { hasBlockSupport, isReusableBlock, createBlock, serialize, getBlockType } from '@wordpress/blocks';
|
|
5
5
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
6
6
|
import { useState, useCallback } from '@wordpress/element';
|
|
7
7
|
import { MenuItem } from '@wordpress/components';
|
|
@@ -57,6 +57,15 @@ export default function PatternConvertButton({
|
|
|
57
57
|
} = select(blockEditorStore);
|
|
58
58
|
const rootId = rootClientId || (clientIds.length > 0 ? getBlockRootClientId(clientIds[0]) : undefined);
|
|
59
59
|
const blocks = (_getBlocksByClientId = getBlocksByClientId(clientIds)) !== null && _getBlocksByClientId !== void 0 ? _getBlocksByClientId : [];
|
|
60
|
+
|
|
61
|
+
// Check if the block has reusable support defined.
|
|
62
|
+
const hasReusableBlockSupport = blockName => {
|
|
63
|
+
const blockType = getBlockType(blockName);
|
|
64
|
+
const hasParent = blockType && 'parent' in blockType;
|
|
65
|
+
|
|
66
|
+
// If the block has a parent, check with false as default, otherwise with true.
|
|
67
|
+
return hasBlockSupport(blockName, 'reusable', !hasParent);
|
|
68
|
+
};
|
|
60
69
|
const isReusable = blocks.length === 1 && blocks[0] && isReusableBlock(blocks[0]) && !!select(coreStore).getEntityRecord('postType', 'wp_block', blocks[0].attributes.ref);
|
|
61
70
|
const _canConvert =
|
|
62
71
|
// Hide when this is already a synced pattern.
|
|
@@ -68,7 +77,7 @@ export default function PatternConvertButton({
|
|
|
68
77
|
// Hide on invalid blocks.
|
|
69
78
|
block.isValid &&
|
|
70
79
|
// Hide when block doesn't support being made into a pattern.
|
|
71
|
-
|
|
80
|
+
hasReusableBlockSupport(block.name)) &&
|
|
72
81
|
// Hide when current doesn't have permission to do that.
|
|
73
82
|
// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.
|
|
74
83
|
!!canUser('create', {
|
|
@@ -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","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,EAAAC,QAAA,IAAAC,SAAA,EAAAC,IAAA,IAAAC,KAA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nD,OAAO;IACP;IACAD,EAAE,CAAE,4BAA6B,CAAC,EAClC6C,OAAO,CAACM,KAAK,CAACC,GACd,CAAC,EACJ;MACCC,IAAI,EAAE,UAAU;MAChBJ,EAAE,EAAE;IACL,CACD,CAAC;IACD5B,cAAc,CAAE,KAAM,CAAC;EACxB,CAAC;EACD,oBACCT,KAAA,CAAAF,SAAA;IAAA4C,QAAA,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
|
+
{"version":3,"names":["hasBlockSupport","isReusableBlock","createBlock","serialize","getBlockType","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","hasReusableBlockSupport","blockName","blockType","hasParent","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\tgetBlockType,\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\t// Check if the block has reusable support defined.\n\t\t\tconst hasReusableBlockSupport = ( blockName ) => {\n\t\t\t\tconst blockType = getBlockType( blockName );\n\t\t\t\tconst hasParent = blockType && 'parent' in blockType;\n\n\t\t\t\t// If the block has a parent, check with false as default, otherwise with true.\n\t\t\t\treturn hasBlockSupport( blockName, 'reusable', ! hasParent );\n\t\t\t};\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\thasReusableBlockSupport( block.name )\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,EACTC,YAAY,QACN,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,EAAAC,QAAA,IAAAC,SAAA,EAAAC,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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OAAO,CAACM,KAAK,CAACC,GACd,CAAC,GACDvD,OAAO;IACP;IACAD,EAAE,CAAE,4BAA6B,CAAC,EAClCiD,OAAO,CAACM,KAAK,CAACC,GACd,CAAC,EACJ;MACCC,IAAI,EAAE,UAAU;MAChBJ,EAAE,EAAE;IACL,CACD,CAAC;IACDhC,cAAc,CAAE,KAAM,CAAC;EACxB,CAAC;EACD,oBACCT,KAAA,CAAAF,SAAA;IAAAgD,QAAA,gBACClD,IAAA,CAACb,QAAQ;MACRgE,IAAI,EAAG/D,MAAQ;MACfgE,OAAO,EAAGA,CAAA,KAAMvC,cAAc,CAAE,IAAK,CAAG;MACxC,iBAAgBD,WAAa;MAC7B,iBAAc,QAAQ;MAAAsC,QAAA,EAEpB1D,EAAE,CAAE,gBAAiB;IAAC,CACf,CAAC,EACToB,WAAW,iBACZZ,IAAA,CAACJ,kBAAkB;MAClByD,OAAO,EAAGd,UAAY;MACtBe,SAAS,EAAKb,OAAO,IAAM;QAC1BD,aAAa,CAAEC,OAAQ,CAAC;MACzB,CAAG;MACHc,OAAO,EAAGA,CAAA,KAAM;QACf1C,cAAc,CAAE,KAAM,CAAC;MACxB,CAAG;MACH2C,OAAO,EAAGA,CAAA,KAAM;QACf3C,cAAc,CAAE,KAAM,CAAC;MACxB;IAAG,CACH,CACD;EAAA,CACA,CAAC;AAEL","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/patterns",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.13.0",
|
|
4
4
|
"description": "Management of user pattern editing.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "cce81c13739c2a8b53d91df90c4f037cb68c2665"
|
|
59
59
|
}
|
|
@@ -24,7 +24,7 @@ function getTermLabels( pattern, categories ) {
|
|
|
24
24
|
|
|
25
25
|
return categories.user
|
|
26
26
|
?.filter( ( category ) =>
|
|
27
|
-
pattern.wp_pattern_category
|
|
27
|
+
pattern.wp_pattern_category?.includes( category.id )
|
|
28
28
|
)
|
|
29
29
|
.map( ( category ) => category.label );
|
|
30
30
|
}
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
isReusableBlock,
|
|
7
7
|
createBlock,
|
|
8
8
|
serialize,
|
|
9
|
+
getBlockType,
|
|
9
10
|
} from '@wordpress/blocks';
|
|
10
11
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
11
12
|
import { useState, useCallback } from '@wordpress/element';
|
|
@@ -60,6 +61,15 @@ export default function PatternConvertButton( {
|
|
|
60
61
|
|
|
61
62
|
const blocks = getBlocksByClientId( clientIds ) ?? [];
|
|
62
63
|
|
|
64
|
+
// Check if the block has reusable support defined.
|
|
65
|
+
const hasReusableBlockSupport = ( blockName ) => {
|
|
66
|
+
const blockType = getBlockType( blockName );
|
|
67
|
+
const hasParent = blockType && 'parent' in blockType;
|
|
68
|
+
|
|
69
|
+
// If the block has a parent, check with false as default, otherwise with true.
|
|
70
|
+
return hasBlockSupport( blockName, 'reusable', ! hasParent );
|
|
71
|
+
};
|
|
72
|
+
|
|
63
73
|
const isReusable =
|
|
64
74
|
blocks.length === 1 &&
|
|
65
75
|
blocks[ 0 ] &&
|
|
@@ -82,7 +92,7 @@ export default function PatternConvertButton( {
|
|
|
82
92
|
// Hide on invalid blocks.
|
|
83
93
|
block.isValid &&
|
|
84
94
|
// Hide when block doesn't support being made into a pattern.
|
|
85
|
-
|
|
95
|
+
hasReusableBlockSupport( block.name )
|
|
86
96
|
) &&
|
|
87
97
|
// Hide when current doesn't have permission to do that.
|
|
88
98
|
// Blocks refers to the wp_block post type, this checks the ability to create a post of that type.
|