@wordpress/patterns 1.6.0 → 1.8.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/category-selector.js +2 -1
- package/build/components/category-selector.js.map +1 -1
- package/build/components/create-pattern-modal.js +7 -4
- package/build/components/create-pattern-modal.js.map +1 -1
- package/build/components/duplicate-pattern-modal.js +3 -3
- package/build/components/duplicate-pattern-modal.js.map +1 -1
- package/build/components/index.js +4 -2
- package/build/components/index.js.map +1 -1
- package/build/components/pattern-convert-button.js +7 -4
- package/build/components/pattern-convert-button.js.map +1 -1
- package/build/components/patterns-manage-button.js +4 -5
- package/build/components/patterns-manage-button.js.map +1 -1
- package/build/constants.js +3 -3
- package/build/constants.js.map +1 -1
- package/build/private-apis.js +1 -1
- package/build/private-apis.js.map +1 -1
- package/build-module/components/category-selector.js +2 -1
- package/build-module/components/category-selector.js.map +1 -1
- package/build-module/components/create-pattern-modal.js +8 -5
- package/build-module/components/create-pattern-modal.js.map +1 -1
- package/build-module/components/duplicate-pattern-modal.js +4 -4
- package/build-module/components/duplicate-pattern-modal.js.map +1 -1
- package/build-module/components/index.js +4 -2
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/pattern-convert-button.js +7 -4
- package/build-module/components/pattern-convert-button.js.map +1 -1
- package/build-module/components/patterns-manage-button.js +4 -5
- package/build-module/components/patterns-manage-button.js.map +1 -1
- package/build-module/constants.js +1 -1
- package/build-module/constants.js.map +1 -1
- package/build-module/private-apis.js +2 -2
- package/build-module/private-apis.js.map +1 -1
- package/build-style/style-rtl.css +6 -9
- package/build-style/style.css +6 -9
- package/package.json +16 -16
- package/src/components/category-selector.js +1 -0
- package/src/components/create-pattern-modal.js +10 -4
- package/src/components/duplicate-pattern-modal.js +7 -6
- package/src/components/index.js +2 -1
- package/src/components/pattern-convert-button.js +10 -4
- package/src/components/patterns-manage-button.js +37 -40
- package/src/components/style.scss +9 -14
- package/src/constants.js +1 -2
- package/src/private-apis.js +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Modal","Button","TextControl","__experimentalHStack","HStack","__experimentalVStack","VStack","ToggleControl","__","useState","useMemo","useDispatch","useSelect","store","noticesStore","coreStore","PATTERN_DEFAULT_CATEGORY","PATTERN_SYNC_TYPES","patternsStore","CategorySelector","CATEGORY_SLUG","unlock","CreatePatternModal","confirmLabel","defaultCategories","className","content","modalTitle","onClose","onError","onSuccess","defaultSyncType","full","defaultTitle","syncType","setSyncType","categoryTerms","setCategoryTerms","title","setTitle","isSaving","setIsSaving","createPattern","saveEntityRecord","invalidateResolution","createErrorNotice","corePatternCategories","userPatternCategories","select","getUserPatternCategories","getBlockPatternCategories","categoryMap","uniqueCategories","Map","forEach","category","has","label","name","set","value","onCreate","patternTitle","sync","categories","Promise","all","map","termName","findOrCreateTerm","newPattern","pattern","categoryId","error","message","type","id","term","existingTerm","get","termData","slug","newTerm","throwOnError","code","data","term_id","createElement","onRequestClose","overlayClassName","onSubmit","event","preventDefault","spacing","__nextHasNoMarginBottom","onChange","placeholder","help","checked","unsynced","justify","variant","onClick","isBusy"],"sources":["@wordpress/patterns/src/components/create-pattern-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tModal,\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tToggleControl,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState, useMemo } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_DEFAULT_CATEGORY, PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CategorySelector, { CATEGORY_SLUG } from './category-selector';\nimport { unlock } from '../lock-unlock';\n\nexport default function CreatePatternModal( {\n\tconfirmLabel = __( 'Create' ),\n\tdefaultCategories = [],\n\tclassName = 'patterns-menu-items__convert-modal',\n\tcontent,\n\tmodalTitle = __( 'Create pattern' ),\n\tonClose,\n\tonError,\n\tonSuccess,\n\tdefaultSyncType = PATTERN_SYNC_TYPES.full,\n\tdefaultTitle = '',\n} ) {\n\tconst [ syncType, setSyncType ] = useState( defaultSyncType );\n\tconst [ categoryTerms, setCategoryTerms ] = useState( defaultCategories );\n\tconst [ title, setTitle ] = useState( defaultTitle );\n\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\tconst { createPattern } = unlock( useDispatch( patternsStore ) );\n\tconst { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tconst { corePatternCategories, userPatternCategories } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getUserPatternCategories, getBlockPatternCategories } =\n\t\t\t\tselect( coreStore );\n\n\t\t\treturn {\n\t\t\t\tcorePatternCategories: getBlockPatternCategories(),\n\t\t\t\tuserPatternCategories: getUserPatternCategories(),\n\t\t\t};\n\t\t}\n\t);\n\n\tconst categoryMap = useMemo( () => {\n\t\t// Merge the user and core pattern categories and remove any duplicates.\n\t\tconst uniqueCategories = new Map();\n\t\t[ ...userPatternCategories, ...corePatternCategories ].forEach(\n\t\t\t( category ) => {\n\t\t\t\tif (\n\t\t\t\t\t! uniqueCategories.has( category.label ) &&\n\t\t\t\t\t// There are two core categories with `Post` label so explicitly remove the one with\n\t\t\t\t\t// the `query` slug to avoid any confusion.\n\t\t\t\t\tcategory.name !== 'query'\n\t\t\t\t) {\n\t\t\t\t\t// We need to store the name separately as this is used as the slug in the\n\t\t\t\t\t// taxonomy and may vary from the label.\n\t\t\t\t\tuniqueCategories.set( category.label, {\n\t\t\t\t\t\tlabel: category.label,\n\t\t\t\t\t\tvalue: category.label,\n\t\t\t\t\t\tname: category.name,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t\treturn uniqueCategories;\n\t}, [ userPatternCategories, corePatternCategories ] );\n\n\tasync function onCreate( patternTitle, sync ) {\n\t\tif ( ! title || isSaving ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSaving( true );\n\t\t\tconst categories = await Promise.all(\n\t\t\t\tcategoryTerms.map( ( termName ) =>\n\t\t\t\t\tfindOrCreateTerm( termName )\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tconst newPattern = await createPattern(\n\t\t\t\tpatternTitle,\n\t\t\t\tsync,\n\t\t\t\ttypeof content === 'function' ? content() : content,\n\t\t\t\tcategories\n\t\t\t);\n\t\t\tonSuccess( {\n\t\t\t\tpattern: newPattern,\n\t\t\t\tcategoryId: PATTERN_DEFAULT_CATEGORY,\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-create',\n\t\t\t} );\n\t\t\tonError?.();\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t\tsetCategoryTerms( [] );\n\t\t\tsetTitle( '' );\n\t\t}\n\t}\n\n\t/**\n\t * @param {string} term\n\t * @return {Promise<number>} The pattern category id.\n\t */\n\tasync function findOrCreateTerm( term ) {\n\t\ttry {\n\t\t\t// We need to match any existing term to the correct slug to prevent duplicates, eg.\n\t\t\t// the core `Headers` category uses the singular `header` as the slug.\n\t\t\tconst existingTerm = categoryMap.get( term );\n\t\t\tconst termData = existingTerm\n\t\t\t\t? { name: existingTerm.label, slug: existingTerm.name }\n\t\t\t\t: { name: term };\n\t\t\tconst newTerm = await saveEntityRecord(\n\t\t\t\t'taxonomy',\n\t\t\t\tCATEGORY_SLUG,\n\t\t\t\ttermData,\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tinvalidateResolution( 'getUserPatternCategories' );\n\t\t\treturn newTerm.id;\n\t\t} catch ( error ) {\n\t\t\tif ( error.code !== 'term_exists' ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn error.data.term_id;\n\t\t}\n\t}\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle }\n\t\t\tonRequestClose={ () => {\n\t\t\t\tonClose();\n\t\t\t\tsetTitle( '' );\n\t\t\t} }\n\t\t\toverlayClassName={ className }\n\t\t>\n\t\t\t<form\n\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tonCreate( title, syncType );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\tplaceholder={ __( 'My pattern' ) }\n\t\t\t\t\t\tclassName=\"patterns-create-modal__name-input\"\n\t\t\t\t\t/>\n\t\t\t\t\t<CategorySelector\n\t\t\t\t\t\tcategoryTerms={ categoryTerms }\n\t\t\t\t\t\tonChange={ setCategoryTerms }\n\t\t\t\t\t\tcategoryMap={ categoryMap }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Synced' ) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Editing the pattern will update it anywhere it is used.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ syncType === PATTERN_SYNC_TYPES.full }\n\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\tsyncType === PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t\t\t? PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t\t\t\t\t\t: PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\taria-disabled={ ! title || isSaving }\n\t\t\t\t\t\t\tisBusy={ isSaving }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ confirmLabel }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t</Modal>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SACCA,KAAK,EACLC,MAAM,EACNC,WAAW,EACXC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,EAC9BC,aAAa,QACP,uBAAuB;AAC9B,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,EAAEC,OAAO,QAAQ,oBAAoB;AACtD,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,KAAK,IAAIC,YAAY,QAAQ,oBAAoB;AAC1D,SAASD,KAAK,IAAIE,SAAS,QAAQ,sBAAsB;;AAEzD;AACA;AACA;AACA,SAASC,wBAAwB,EAAEC,kBAAkB,QAAQ,cAAc;;AAE3E;AACA;AACA;AACA,SAASJ,KAAK,IAAIK,aAAa,QAAQ,UAAU;AACjD,OAAOC,gBAAgB,IAAIC,aAAa,QAAQ,qBAAqB;AACrE,SAASC,MAAM,QAAQ,gBAAgB;AAEvC,eAAe,SAASC,kBAAkBA,CAAE;EAC3CC,YAAY,GAAGf,EAAE,CAAE,QAAS,CAAC;EAC7BgB,iBAAiB,GAAG,EAAE;EACtBC,S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fyD,QAAQ,EAAGxD,QAAU;IACrByD,WAAW,EAAGxF,EAAE,CAAE,YAAa,CAAG;IAClCiB,SAAS,EAAC;EAAmC,CAC7C,CAAC,EACF8D,aAAA,CAACpE,gBAAgB;IAChBiB,aAAa,EAAGA,aAAe;IAC/B2D,QAAQ,EAAG1D,gBAAkB;IAC7Bc,WAAW,EAAGA;EAAa,CAC3B,CAAC,EACFoC,aAAA,CAAChF,aAAa;IACbkD,KAAK,EAAGjD,EAAE,CAAE,QAAS,CAAG;IACxByF,IAAI,EAAGzF,EAAE,CACR,yDACD,CAAG;IACH0F,OAAO,EAAGhE,QAAQ,KAAKjB,kBAAkB,CAACe,IAAM;IAChD+D,QAAQ,EAAGA,CAAA,KAAM;MAChB5D,WAAW,CACVD,QAAQ,KAAKjB,kBAAkB,CAACe,IAAI,GACjCf,kBAAkB,CAACkF,QAAQ,GAC3BlF,kBAAkB,CAACe,IACvB,CAAC;IACF;EAAG,CACH,CAAC,EACFuD,aAAA,CAACnF,MAAM;IAACgG,OAAO,EAAC;EAAO,GACtBb,aAAA,CAACtF,MAAM;IACNoG,OAAO,EAAC,UAAU;IAClBC,OAAO,EAAGA,CAAA,KAAM;MACf1E,OAAO,CAAC,CAAC;MACTW,QAAQ,CAAE,EAAG,CAAC;IACf;EAAG,GAED/B,EAAE,CAAE,QAAS,CACR,CAAC,EAET+E,aAAA,CAACtF,MAAM;IACNoG,OAAO,EAAC,SAAS;IACjB1B,IAAI,EAAC,QAAQ;IACb,iBAAgB,CAAErC,KAAK,IAAIE,QAAU;IACrC+D,MAAM,EAAG/D;EAAU,GAEjBjB,YACK,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
1
|
+
{"version":3,"names":["Modal","Button","TextControl","__experimentalHStack","HStack","__experimentalVStack","VStack","ToggleControl","__","_x","useState","useMemo","useDispatch","useSelect","store","noticesStore","coreStore","PATTERN_DEFAULT_CATEGORY","PATTERN_SYNC_TYPES","patternsStore","CategorySelector","CATEGORY_SLUG","unlock","CreatePatternModal","confirmLabel","defaultCategories","className","content","modalTitle","onClose","onError","onSuccess","defaultSyncType","full","defaultTitle","syncType","setSyncType","categoryTerms","setCategoryTerms","title","setTitle","isSaving","setIsSaving","createPattern","saveEntityRecord","invalidateResolution","createErrorNotice","corePatternCategories","userPatternCategories","select","getUserPatternCategories","getBlockPatternCategories","categoryMap","uniqueCategories","Map","forEach","category","has","label","name","set","value","onCreate","patternTitle","sync","categories","Promise","all","map","termName","findOrCreateTerm","newPattern","pattern","categoryId","error","message","type","id","term","existingTerm","get","termData","slug","newTerm","throwOnError","code","data","term_id","createElement","onRequestClose","overlayClassName","onSubmit","event","preventDefault","spacing","onChange","placeholder","__nextHasNoMarginBottom","__next40pxDefaultSize","help","checked","unsynced","justify","variant","onClick","isBusy"],"sources":["@wordpress/patterns/src/components/create-pattern-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tModal,\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tToggleControl,\n} from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport { useState, useMemo } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_DEFAULT_CATEGORY, PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CategorySelector, { CATEGORY_SLUG } from './category-selector';\nimport { unlock } from '../lock-unlock';\n\nexport default function CreatePatternModal( {\n\tconfirmLabel = __( 'Create' ),\n\tdefaultCategories = [],\n\tclassName = 'patterns-menu-items__convert-modal',\n\tcontent,\n\tmodalTitle = __( 'Create pattern' ),\n\tonClose,\n\tonError,\n\tonSuccess,\n\tdefaultSyncType = PATTERN_SYNC_TYPES.full,\n\tdefaultTitle = '',\n} ) {\n\tconst [ syncType, setSyncType ] = useState( defaultSyncType );\n\tconst [ categoryTerms, setCategoryTerms ] = useState( defaultCategories );\n\tconst [ title, setTitle ] = useState( defaultTitle );\n\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\tconst { createPattern } = unlock( useDispatch( patternsStore ) );\n\tconst { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tconst { corePatternCategories, userPatternCategories } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getUserPatternCategories, getBlockPatternCategories } =\n\t\t\t\tselect( coreStore );\n\n\t\t\treturn {\n\t\t\t\tcorePatternCategories: getBlockPatternCategories(),\n\t\t\t\tuserPatternCategories: getUserPatternCategories(),\n\t\t\t};\n\t\t}\n\t);\n\n\tconst categoryMap = useMemo( () => {\n\t\t// Merge the user and core pattern categories and remove any duplicates.\n\t\tconst uniqueCategories = new Map();\n\t\t[ ...userPatternCategories, ...corePatternCategories ].forEach(\n\t\t\t( category ) => {\n\t\t\t\tif (\n\t\t\t\t\t! uniqueCategories.has( category.label ) &&\n\t\t\t\t\t// There are two core categories with `Post` label so explicitly remove the one with\n\t\t\t\t\t// the `query` slug to avoid any confusion.\n\t\t\t\t\tcategory.name !== 'query'\n\t\t\t\t) {\n\t\t\t\t\t// We need to store the name separately as this is used as the slug in the\n\t\t\t\t\t// taxonomy and may vary from the label.\n\t\t\t\t\tuniqueCategories.set( category.label, {\n\t\t\t\t\t\tlabel: category.label,\n\t\t\t\t\t\tvalue: category.label,\n\t\t\t\t\t\tname: category.name,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t\treturn uniqueCategories;\n\t}, [ userPatternCategories, corePatternCategories ] );\n\n\tasync function onCreate( patternTitle, sync ) {\n\t\tif ( ! title || isSaving ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSaving( true );\n\t\t\tconst categories = await Promise.all(\n\t\t\t\tcategoryTerms.map( ( termName ) =>\n\t\t\t\t\tfindOrCreateTerm( termName )\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tconst newPattern = await createPattern(\n\t\t\t\tpatternTitle,\n\t\t\t\tsync,\n\t\t\t\ttypeof content === 'function' ? content() : content,\n\t\t\t\tcategories\n\t\t\t);\n\t\t\tonSuccess( {\n\t\t\t\tpattern: newPattern,\n\t\t\t\tcategoryId: PATTERN_DEFAULT_CATEGORY,\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-create',\n\t\t\t} );\n\t\t\tonError?.();\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t\tsetCategoryTerms( [] );\n\t\t\tsetTitle( '' );\n\t\t}\n\t}\n\n\t/**\n\t * @param {string} term\n\t * @return {Promise<number>} The pattern category id.\n\t */\n\tasync function findOrCreateTerm( term ) {\n\t\ttry {\n\t\t\t// We need to match any existing term to the correct slug to prevent duplicates, eg.\n\t\t\t// the core `Headers` category uses the singular `header` as the slug.\n\t\t\tconst existingTerm = categoryMap.get( term );\n\t\t\tconst termData = existingTerm\n\t\t\t\t? { name: existingTerm.label, slug: existingTerm.name }\n\t\t\t\t: { name: term };\n\t\t\tconst newTerm = await saveEntityRecord(\n\t\t\t\t'taxonomy',\n\t\t\t\tCATEGORY_SLUG,\n\t\t\t\ttermData,\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tinvalidateResolution( 'getUserPatternCategories' );\n\t\t\treturn newTerm.id;\n\t\t} catch ( error ) {\n\t\t\tif ( error.code !== 'term_exists' ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn error.data.term_id;\n\t\t}\n\t}\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle }\n\t\t\tonRequestClose={ () => {\n\t\t\t\tonClose();\n\t\t\t\tsetTitle( '' );\n\t\t\t} }\n\t\t\toverlayClassName={ className }\n\t\t>\n\t\t\t<form\n\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tonCreate( title, syncType );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\tplaceholder={ __( 'My pattern' ) }\n\t\t\t\t\t\tclassName=\"patterns-create-modal__name-input\"\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t/>\n\t\t\t\t\t<CategorySelector\n\t\t\t\t\t\tcategoryTerms={ categoryTerms }\n\t\t\t\t\t\tonChange={ setCategoryTerms }\n\t\t\t\t\t\tcategoryMap={ categoryMap }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t\t'Synced',\n\t\t\t\t\t\t\t'Option that makes an individual pattern synchronized'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Sync this pattern across multiple locations.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ syncType === PATTERN_SYNC_TYPES.full }\n\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\tsyncType === PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t\t\t? PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t\t\t\t\t\t: PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\taria-disabled={ ! title || isSaving }\n\t\t\t\t\t\t\tisBusy={ isSaving }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ confirmLabel }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t</Modal>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SACCA,KAAK,EACLC,MAAM,EACNC,WAAW,EACXC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,EAC9BC,aAAa,QACP,uBAAuB;AAC9B,SAASC,EAAE,EAAEC,EAAE,QAAQ,iBAAiB;AACxC,SAASC,QAAQ,EAAEC,OAAO,QAAQ,oBAAoB;AACtD,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,KAAK,IAAIC,YAAY,QAAQ,oBAAoB;AAC1D,SAASD,KAAK,IAAIE,SAAS,QAAQ,sBAAsB;;AAEzD;AACA;AACA;AACA,SAASC,wBAAwB,EAAEC,kBAAkB,QAAQ,cAAc;;AAE3E;AACA;AACA;AACA,SAASJ,KAAK,IAAIK,aAAa,QAAQ,UAAU;AACjD,OAAOC,gBAAgB,IAAIC,aAAa,QAAQ,qBAAqB;AACrE,SAASC,MAAM,QAAQ,gBAAgB;AAEvC,eAAe,SAASC,kBAAkBA,CAAE;EAC3CC,YAAY,GAAGhB,EAAE,CAAE,QAAS,CAAC;EAC7BiB,iBAAiB,GAAG,EAAE;EACtBC,SAAS,GAAG,oCAAoC;EAChDC,OAAO;EACPC,UAAU,GAA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a,CAAG;IAClCkB,SAAS,EAAC,mCAAmC;IAC7CuE,uBAAuB;IACvBC,qBAAqB;EAAA,CACrB,CAAC,EACFV,aAAA,CAACpE,gBAAgB;IAChBiB,aAAa,EAAGA,aAAe;IAC/B0D,QAAQ,EAAGzD,gBAAkB;IAC7Bc,WAAW,EAAGA;EAAa,CAC3B,CAAC,EACFoC,aAAA,CAACjF,aAAa;IACbmD,KAAK,EAAGjD,EAAE,CACT,QAAQ,EACR,sDACD,CAAG;IACH0F,IAAI,EAAG3F,EAAE,CACR,8CACD,CAAG;IACH4F,OAAO,EAAGjE,QAAQ,KAAKjB,kBAAkB,CAACe,IAAM;IAChD8D,QAAQ,EAAGA,CAAA,KAAM;MAChB3D,WAAW,CACVD,QAAQ,KAAKjB,kBAAkB,CAACe,IAAI,GACjCf,kBAAkB,CAACmF,QAAQ,GAC3BnF,kBAAkB,CAACe,IACvB,CAAC;IACF;EAAG,CACH,CAAC,EACFuD,aAAA,CAACpF,MAAM;IAACkG,OAAO,EAAC;EAAO,GACtBd,aAAA,CAACvF,MAAM;IACNiG,qBAAqB;IACrBK,OAAO,EAAC,UAAU;IAClBC,OAAO,EAAGA,CAAA,KAAM;MACf3E,OAAO,CAAC,CAAC;MACTW,QAAQ,CAAE,EAAG,CAAC;IACf;EAAG,GAEDhC,EAAE,CAAE,QAAS,CACR,CAAC,EAETgF,aAAA,CAACvF,MAAM;IACNiG,qBAAqB;IACrBK,OAAO,EAAC,SAAS;IACjB3B,IAAI,EAAC,QAAQ;IACb,iBAAgB,CAAErC,KAAK,IAAIE,QAAU;IACrCgE,MAAM,EAAGhE;EAAU,GAEjBjB,YACK,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
@@ -11,10 +11,10 @@ import { store as noticesStore } from '@wordpress/notices';
|
|
|
11
11
|
* Internal dependencies
|
|
12
12
|
*/
|
|
13
13
|
import CreatePatternModal from './create-pattern-modal';
|
|
14
|
-
import { PATTERN_SYNC_TYPES } from '../constants';
|
|
14
|
+
import { PATTERN_SYNC_TYPES, PATTERN_TYPES } from '../constants';
|
|
15
15
|
function getTermLabels(pattern, categories) {
|
|
16
|
-
// Theme patterns
|
|
17
|
-
if (
|
|
16
|
+
// Theme patterns rely on core pattern categories.
|
|
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
20
|
return categories.user?.filter(category => pattern.wp_pattern_category.includes(category.id)).map(category => category.label);
|
|
@@ -43,7 +43,7 @@ export default function DuplicatePatternModal({
|
|
|
43
43
|
const duplicatedProps = {
|
|
44
44
|
content: pattern.content,
|
|
45
45
|
defaultCategories: getTermLabels(pattern, categories),
|
|
46
|
-
defaultSyncType:
|
|
46
|
+
defaultSyncType: pattern.type !== PATTERN_TYPES.user // Theme patterns are unsynced by default.
|
|
47
47
|
? PATTERN_SYNC_TYPES.unsynced : pattern.wp_pattern_sync_status || PATTERN_SYNC_TYPES.full,
|
|
48
48
|
defaultTitle: sprintf( /* translators: %s: Existing pattern title */
|
|
49
49
|
__('%s (Copy)'), typeof pattern.title === 'string' ? pattern.title : pattern.title.raw)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["store","coreStore","useDispatch","useSelect","__","sprintf","noticesStore","CreatePatternModal","PATTERN_SYNC_TYPES","getTermLabels","pattern","categories","
|
|
1
|
+
{"version":3,"names":["store","coreStore","useDispatch","useSelect","__","sprintf","noticesStore","CreatePatternModal","PATTERN_SYNC_TYPES","PATTERN_TYPES","getTermLabels","pattern","categories","type","user","core","filter","category","includes","name","map","label","wp_pattern_category","id","DuplicatePatternModal","onClose","onSuccess","createSuccessNotice","select","getUserPatternCategories","getBlockPatternCategories","duplicatedProps","content","defaultCategories","defaultSyncType","unsynced","wp_pattern_sync_status","full","defaultTitle","title","raw","handleOnSuccess","newPattern","createElement","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 { __, 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 default function DuplicatePatternModal( {\n\tpattern,\n\tonClose,\n\tonSuccess,\n} ) {\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\n\tif ( ! pattern ) {\n\t\treturn null;\n\t}\n\n\tconst duplicatedProps = {\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__( '%s (Copy)' ),\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};\n\n\tfunction handleOnSuccess( { pattern: newPattern } ) {\n\t\tcreateSuccessNotice(\n\t\t\tsprintf(\n\t\t\t\t// translators: %s: The new pattern's title e.g. 'Call to action (copy)'.\n\t\t\t\t__( '\"%s\" duplicated.' ),\n\t\t\t\tnewPattern.title.raw\n\t\t\t),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'patterns-create',\n\t\t\t}\n\t\t);\n\n\t\tonSuccess?.( { pattern: newPattern } );\n\t}\n\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\tonSuccess={ handleOnSuccess }\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,OAAO,QAAQ,iBAAiB;AAC7C,SAASL,KAAK,IAAIM,YAAY,QAAQ,oBAAoB;;AAE1D;AACA;AACA;AACA,OAAOC,kBAAkB,MAAM,wBAAwB;AACvD,SAASC,kBAAkB,EAAEC,aAAa,QAAQ,cAAc;AAEhE,SAASC,aAAaA,CAAEC,OAAO,EAAEC,UAAU,EAAG;EAC7C;EACA,IAAKD,OAAO,CAACE,IAAI,KAAKJ,aAAa,CAACK,IAAI,EAAG;IAC1C,OAAOF,UAAU,CAACG,IAAI,EACnBC,MAAM,CAAIC,QAAQ,IACnBN,OAAO,CAACC,UAAU,CAACM,QAAQ,CAAED,QAAQ,CAACE,IAAK,CAC5C,CAAC,CACAC,GAAG,CAAIH,QAAQ,IAAMA,QAAQ,CAACI,KAAM,CAAC;EACxC;EAEA,OAAOT,UAAU,CAACE,IAAI,EACnBE,MAAM,CAAIC,QAAQ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ACxBsC,UAAU,CAACH,KAAK,CAACC,GAClB,CAAC,EACD;MACC3B,IAAI,EAAE,UAAU;MAChBU,EAAE,EAAE;IACL,CACD,CAAC;IAEDG,SAAS,GAAI;MAAEf,OAAO,EAAE+B;IAAW,CAAE,CAAC;EACvC;EAEA,OACCC,aAAA,CAACpC,kBAAkB;IAClBqC,UAAU,EAAGxC,EAAE,CAAE,mBAAoB,CAAG;IACxCyC,YAAY,EAAGzC,EAAE,CAAE,WAAY,CAAG;IAClCqB,OAAO,EAAGA,OAAS;IACnBqB,OAAO,EAAGrB,OAAS;IACnBC,SAAS,EAAGe,eAAiB;IAAA,GACxBV;EAAe,CACpB,CAAC;AAEJ"}
|
|
@@ -13,10 +13,12 @@ export default function PatternsMenuItems({
|
|
|
13
13
|
rootClientId
|
|
14
14
|
}) {
|
|
15
15
|
return createElement(BlockSettingsMenuControls, null, ({
|
|
16
|
-
selectedClientIds
|
|
16
|
+
selectedClientIds,
|
|
17
|
+
onClose
|
|
17
18
|
}) => createElement(Fragment, null, createElement(PatternConvertButton, {
|
|
18
19
|
clientIds: selectedClientIds,
|
|
19
|
-
rootClientId: rootClientId
|
|
20
|
+
rootClientId: rootClientId,
|
|
21
|
+
closeBlockSettingsMenu: onClose
|
|
20
22
|
}), selectedClientIds.length === 1 && createElement(PatternsManageButton, {
|
|
21
23
|
clientId: selectedClientIds[0]
|
|
22
24
|
})));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BlockSettingsMenuControls","PatternConvertButton","PatternsManageButton","PatternsMenuItems","rootClientId","createElement","selectedClientIds","Fragment","clientIds","length","clientId"],"sources":["@wordpress/patterns/src/components/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { BlockSettingsMenuControls } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport PatternConvertButton from './pattern-convert-button';\nimport PatternsManageButton from './patterns-manage-button';\n\nexport default function PatternsMenuItems( { rootClientId } ) {\n\treturn (\n\t\t<BlockSettingsMenuControls>\n\t\t\t{ ( { selectedClientIds } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<PatternConvertButton\n\t\t\t\t\t\tclientIds={ selectedClientIds }\n\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t/>\n\t\t\t\t\t{ selectedClientIds.length === 1 && (\n\t\t\t\t\t\t<PatternsManageButton\n\t\t\t\t\t\t\tclientId={ selectedClientIds[ 0 ] }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\t\t</BlockSettingsMenuControls>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,yBAAyB,QAAQ,yBAAyB;;AAEnE;AACA;AACA;AACA,OAAOC,oBAAoB,MAAM,0BAA0B;AAC3D,OAAOC,oBAAoB,MAAM,0BAA0B;AAE3D,eAAe,SAASC,iBAAiBA,CAAE;EAAEC;AAAa,CAAC,EAAG;EAC7D,OACCC,aAAA,CAACL,yBAAyB,QACvB,CAAE;IAAEM;
|
|
1
|
+
{"version":3,"names":["BlockSettingsMenuControls","PatternConvertButton","PatternsManageButton","PatternsMenuItems","rootClientId","createElement","selectedClientIds","onClose","Fragment","clientIds","closeBlockSettingsMenu","length","clientId"],"sources":["@wordpress/patterns/src/components/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { BlockSettingsMenuControls } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport PatternConvertButton from './pattern-convert-button';\nimport PatternsManageButton from './patterns-manage-button';\n\nexport default function PatternsMenuItems( { rootClientId } ) {\n\treturn (\n\t\t<BlockSettingsMenuControls>\n\t\t\t{ ( { selectedClientIds, onClose } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<PatternConvertButton\n\t\t\t\t\t\tclientIds={ selectedClientIds }\n\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\tcloseBlockSettingsMenu={ onClose }\n\t\t\t\t\t/>\n\t\t\t\t\t{ selectedClientIds.length === 1 && (\n\t\t\t\t\t\t<PatternsManageButton\n\t\t\t\t\t\t\tclientId={ selectedClientIds[ 0 ] }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\t\t</BlockSettingsMenuControls>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,yBAAyB,QAAQ,yBAAyB;;AAEnE;AACA;AACA;AACA,OAAOC,oBAAoB,MAAM,0BAA0B;AAC3D,OAAOC,oBAAoB,MAAM,0BAA0B;AAE3D,eAAe,SAASC,iBAAiBA,CAAE;EAAEC;AAAa,CAAC,EAAG;EAC7D,OACCC,aAAA,CAACL,yBAAyB,QACvB,CAAE;IAAEM,iBAAiB;IAAEC;EAAQ,CAAC,KACjCF,aAAA,CAAAG,QAAA,QACCH,aAAA,CAACJ,oBAAoB;IACpBQ,SAAS,EAAGH,iBAAmB;IAC/BF,YAAY,EAAGA,YAAc;IAC7BM,sBAAsB,EAAGH;EAAS,CAClC,CAAC,EACAD,iBAAiB,CAACK,MAAM,KAAK,CAAC,IAC/BN,aAAA,CAACH,oBAAoB;IACpBU,QAAQ,EAAGN,iBAAiB,CAAE,CAAC;EAAI,CACnC,CAED,CAEuB,CAAC;AAE9B"}
|
|
@@ -22,14 +22,16 @@ import { PATTERN_SYNC_TYPES } from '../constants';
|
|
|
22
22
|
/**
|
|
23
23
|
* Menu control to convert block(s) to a pattern block.
|
|
24
24
|
*
|
|
25
|
-
* @param {Object} props
|
|
26
|
-
* @param {string[]} props.clientIds
|
|
27
|
-
* @param {string} props.rootClientId
|
|
25
|
+
* @param {Object} props Component props.
|
|
26
|
+
* @param {string[]} props.clientIds Client ids of selected blocks.
|
|
27
|
+
* @param {string} props.rootClientId ID of the currently selected top-level block.
|
|
28
|
+
* @param {()=>void} props.closeBlockSettingsMenu Callback to close the block settings menu dropdown.
|
|
28
29
|
* @return {import('react').ComponentType} The menu control or null.
|
|
29
30
|
*/
|
|
30
31
|
export default function PatternConvertButton({
|
|
31
32
|
clientIds,
|
|
32
|
-
rootClientId
|
|
33
|
+
rootClientId,
|
|
34
|
+
closeBlockSettingsMenu
|
|
33
35
|
}) {
|
|
34
36
|
const {
|
|
35
37
|
createSuccessNotice
|
|
@@ -87,6 +89,7 @@ export default function PatternConvertButton({
|
|
|
87
89
|
});
|
|
88
90
|
replaceBlocks(clientIds, newBlock);
|
|
89
91
|
setEditingPattern(newBlock.clientId, true);
|
|
92
|
+
closeBlockSettingsMenu();
|
|
90
93
|
}
|
|
91
94
|
createSuccessNotice(pattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced ? sprintf(
|
|
92
95
|
// translators: %s: the name the user has given to the pattern.
|
|
@@ -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","PatternConvertButton","clientIds","rootClientId","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","createElement","Fragment","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
|
|
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","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","createElement","Fragment","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!! 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":";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;AACA,eAAe,SAASC,oBAAoBA,CAAE;EAC7CC,SAAS;EACT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AAE,UAAU;MAChBJ,EAAE,EAAE;IACL,CACD,CAAC;IACD3B,cAAc,CAAE,KAAM,CAAC;EACxB,CAAC;EACD,OACCgC,aAAA,CAAAC,QAAA,QACCD,aAAA,CAACpD,QAAQ;IACRsD,IAAI,EAAGrD,MAAQ;IACfsD,OAAO,EAAGA,CAAA,KAAMnC,cAAc,CAAE,IAAK,CAAG;IACxC,iBAAgBD,WAAa;IAC7B,iBAAc;EAAQ,GAEpBd,EAAE,CAAE,gBAAiB,CACd,CAAC,EACTc,WAAW,IACZiC,aAAA,CAAC3C,kBAAkB;IAClB+C,OAAO,EAAGf,UAAY;IACtBgB,SAAS,EAAKd,OAAO,IAAM;MAC1BD,aAAa,CAAEC,OAAQ,CAAC;IACzB,CAAG;IACHe,OAAO,EAAGA,CAAA,KAAM;MACftC,cAAc,CAAE,KAAM,CAAC;IACxB,CAAG;IACHuC,OAAO,EAAGA,CAAA,KAAM;MACfvC,cAAc,CAAE,KAAM,CAAC;IACxB;EAAG,CACH,CAED,CAAC;AAEL"}
|
|
@@ -21,7 +21,6 @@ function PatternsManageButton({
|
|
|
21
21
|
const {
|
|
22
22
|
canRemove,
|
|
23
23
|
isVisible,
|
|
24
|
-
innerBlockCount,
|
|
25
24
|
managePatternsUrl
|
|
26
25
|
} = useSelect(select => {
|
|
27
26
|
const {
|
|
@@ -58,11 +57,11 @@ function PatternsManageButton({
|
|
|
58
57
|
if (!isVisible) {
|
|
59
58
|
return null;
|
|
60
59
|
}
|
|
61
|
-
return createElement(Fragment, null, createElement(MenuItem, {
|
|
62
|
-
href: managePatternsUrl
|
|
63
|
-
}, __('Manage patterns')), canRemove && createElement(MenuItem, {
|
|
60
|
+
return createElement(Fragment, null, canRemove && createElement(MenuItem, {
|
|
64
61
|
onClick: () => convertSyncedPatternToStatic(clientId)
|
|
65
|
-
},
|
|
62
|
+
}, __('Detach')), createElement(MenuItem, {
|
|
63
|
+
href: managePatternsUrl
|
|
64
|
+
}, __('Manage patterns')));
|
|
66
65
|
}
|
|
67
66
|
export default PatternsManageButton;
|
|
68
67
|
//# sourceMappingURL=patterns-manage-button.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["MenuItem","__","isReusableBlock","useSelect","useDispatch","store","blockEditorStore","addQueryArgs","coreStore","patternsStore","unlock","PatternsManageButton","clientId","canRemove","isVisible","
|
|
1
|
+
{"version":3,"names":["MenuItem","__","isReusableBlock","useSelect","useDispatch","store","blockEditorStore","addQueryArgs","coreStore","patternsStore","unlock","PatternsManageButton","clientId","canRemove","isVisible","managePatternsUrl","select","getBlock","canRemoveBlock","getBlockCount","getSettings","canUser","reusableBlock","isBlockTheme","__unstableIsBlockBasedTheme","attributes","ref","innerBlockCount","path","post_type","convertSyncedPatternToStatic","createElement","Fragment","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, getSettings } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst reusableBlock = getBlock( clientId );\n\t\t\tconst isBlockTheme = getSettings().__unstableIsBlockBasedTheme;\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\t'update',\n\t\t\t\t\t\t'blocks',\n\t\t\t\t\t\treusableBlock.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:\n\t\t\t\t\tisBlockTheme && canUser( 'read', 'templates' )\n\t\t\t\t\t\t? addQueryArgs( 'site-editor.php', {\n\t\t\t\t\t\t\t\tpath: '/patterns',\n\t\t\t\t\t\t } )\n\t\t\t\t\t\t: addQueryArgs( 'edit.php', {\n\t\t\t\t\t\t\t\tpost_type: 'wp_block',\n\t\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,S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c,CAC5B,CAAC;EAED,IAAK,CAAEK,SAAS,EAAG;IAClB,OAAO,IAAI;EACZ;EAEA,OACCiB,aAAA,CAAAC,QAAA,QACGnB,SAAS,IACVkB,aAAA,CAAC/B,QAAQ;IACRiC,OAAO,EAAGA,CAAA,KAAMH,4BAA4B,CAAElB,QAAS;EAAG,GAExDX,EAAE,CAAE,QAAS,CACN,CACV,EACD8B,aAAA,CAAC/B,QAAQ;IAACkC,IAAI,EAAGnB;EAAmB,GACjCd,EAAE,CAAE,iBAAkB,CACf,CACT,CAAC;AAEL;AAEA,eAAeU,oBAAoB"}
|
|
@@ -4,7 +4,7 @@ export const PATTERN_TYPES = {
|
|
|
4
4
|
};
|
|
5
5
|
export const PATTERN_DEFAULT_CATEGORY = 'all-patterns';
|
|
6
6
|
export const PATTERN_USER_CATEGORY = 'my-patterns';
|
|
7
|
-
export const
|
|
7
|
+
export const EXCLUDED_PATTERN_SOURCES = ['core', 'pattern-directory/core', 'pattern-directory/featured'];
|
|
8
8
|
export const PATTERN_SYNC_TYPES = {
|
|
9
9
|
full: 'fully',
|
|
10
10
|
unsynced: 'unsynced'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PATTERN_TYPES","theme","user","PATTERN_DEFAULT_CATEGORY","PATTERN_USER_CATEGORY","
|
|
1
|
+
{"version":3,"names":["PATTERN_TYPES","theme","user","PATTERN_DEFAULT_CATEGORY","PATTERN_USER_CATEGORY","EXCLUDED_PATTERN_SOURCES","PATTERN_SYNC_TYPES","full","unsynced"],"sources":["@wordpress/patterns/src/constants.js"],"sourcesContent":["export const PATTERN_TYPES = {\n\ttheme: 'pattern',\n\tuser: 'wp_block',\n};\n\nexport const PATTERN_DEFAULT_CATEGORY = 'all-patterns';\nexport const PATTERN_USER_CATEGORY = 'my-patterns';\nexport const EXCLUDED_PATTERN_SOURCES = [\n\t'core',\n\t'pattern-directory/core',\n\t'pattern-directory/featured',\n];\nexport const PATTERN_SYNC_TYPES = {\n\tfull: 'fully',\n\tunsynced: 'unsynced',\n};\n"],"mappings":"AAAA,OAAO,MAAMA,aAAa,GAAG;EAC5BC,KAAK,EAAE,SAAS;EAChBC,IAAI,EAAE;AACP,CAAC;AAED,OAAO,MAAMC,wBAAwB,GAAG,cAAc;AACtD,OAAO,MAAMC,qBAAqB,GAAG,aAAa;AAClD,OAAO,MAAMC,wBAAwB,GAAG,CACvC,MAAM,EACN,wBAAwB,EACxB,4BAA4B,CAC5B;AACD,OAAO,MAAMC,kBAAkB,GAAG;EACjCC,IAAI,EAAE,OAAO;EACbC,QAAQ,EAAE;AACX,CAAC"}
|
|
@@ -7,7 +7,7 @@ import DuplicatePatternModal from './components/duplicate-pattern-modal';
|
|
|
7
7
|
import RenamePatternModal from './components/rename-pattern-modal';
|
|
8
8
|
import PatternsMenuItems from './components';
|
|
9
9
|
import RenamePatternCategoryModal from './components/rename-pattern-category-modal';
|
|
10
|
-
import { PATTERN_TYPES, PATTERN_DEFAULT_CATEGORY, PATTERN_USER_CATEGORY,
|
|
10
|
+
import { PATTERN_TYPES, PATTERN_DEFAULT_CATEGORY, PATTERN_USER_CATEGORY, EXCLUDED_PATTERN_SOURCES, PATTERN_SYNC_TYPES } from './constants';
|
|
11
11
|
export const privateApis = {};
|
|
12
12
|
lock(privateApis, {
|
|
13
13
|
CreatePatternModal,
|
|
@@ -18,7 +18,7 @@ lock(privateApis, {
|
|
|
18
18
|
PATTERN_TYPES,
|
|
19
19
|
PATTERN_DEFAULT_CATEGORY,
|
|
20
20
|
PATTERN_USER_CATEGORY,
|
|
21
|
-
|
|
21
|
+
EXCLUDED_PATTERN_SOURCES,
|
|
22
22
|
PATTERN_SYNC_TYPES
|
|
23
23
|
});
|
|
24
24
|
//# sourceMappingURL=private-apis.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["lock","CreatePatternModal","DuplicatePatternModal","RenamePatternModal","PatternsMenuItems","RenamePatternCategoryModal","PATTERN_TYPES","PATTERN_DEFAULT_CATEGORY","PATTERN_USER_CATEGORY","
|
|
1
|
+
{"version":3,"names":["lock","CreatePatternModal","DuplicatePatternModal","RenamePatternModal","PatternsMenuItems","RenamePatternCategoryModal","PATTERN_TYPES","PATTERN_DEFAULT_CATEGORY","PATTERN_USER_CATEGORY","EXCLUDED_PATTERN_SOURCES","PATTERN_SYNC_TYPES","privateApis"],"sources":["@wordpress/patterns/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { lock } from './lock-unlock';\nimport CreatePatternModal from './components/create-pattern-modal';\nimport DuplicatePatternModal from './components/duplicate-pattern-modal';\nimport RenamePatternModal from './components/rename-pattern-modal';\nimport PatternsMenuItems from './components';\nimport RenamePatternCategoryModal from './components/rename-pattern-category-modal';\nimport {\n\tPATTERN_TYPES,\n\tPATTERN_DEFAULT_CATEGORY,\n\tPATTERN_USER_CATEGORY,\n\tEXCLUDED_PATTERN_SOURCES,\n\tPATTERN_SYNC_TYPES,\n} from './constants';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tCreatePatternModal,\n\tDuplicatePatternModal,\n\tRenamePatternModal,\n\tPatternsMenuItems,\n\tRenamePatternCategoryModal,\n\tPATTERN_TYPES,\n\tPATTERN_DEFAULT_CATEGORY,\n\tPATTERN_USER_CATEGORY,\n\tEXCLUDED_PATTERN_SOURCES,\n\tPATTERN_SYNC_TYPES,\n} );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAI,QAAQ,eAAe;AACpC,OAAOC,kBAAkB,MAAM,mCAAmC;AAClE,OAAOC,qBAAqB,MAAM,sCAAsC;AACxE,OAAOC,kBAAkB,MAAM,mCAAmC;AAClE,OAAOC,iBAAiB,MAAM,cAAc;AAC5C,OAAOC,0BAA0B,MAAM,4CAA4C;AACnF,SACCC,aAAa,EACbC,wBAAwB,EACxBC,qBAAqB,EACrBC,wBAAwB,EACxBC,kBAAkB,QACZ,aAAa;AAEpB,OAAO,MAAMC,WAAW,GAAG,CAAC,CAAC;AAC7BX,IAAI,CAAEW,WAAW,EAAE;EAClBV,kBAAkB;EAClBC,qBAAqB;EACrBC,kBAAkB;EAClBC,iBAAiB;EACjBC,0BAA0B;EAC1BC,aAAa;EACbC,wBAAwB;EACxBC,qBAAqB;EACrBC,wBAAwB;EACxBC;AACD,CAAE,CAAC"}
|
|
@@ -110,27 +110,24 @@
|
|
|
110
110
|
width: 350px;
|
|
111
111
|
}
|
|
112
112
|
.patterns-menu-items__convert-modal .patterns-menu-items__convert-modal-categories {
|
|
113
|
-
width: 100%;
|
|
114
113
|
position: relative;
|
|
115
|
-
min-height: 40px;
|
|
116
114
|
}
|
|
117
|
-
.patterns-menu-items__convert-modal .components-form-token-field__suggestions-list {
|
|
115
|
+
.patterns-menu-items__convert-modal .components-form-token-field__suggestions-list:not(:empty) {
|
|
118
116
|
position: absolute;
|
|
117
|
+
border: 1px solid var(--wp-admin-theme-color);
|
|
118
|
+
border-bottom-right-radius: 2px;
|
|
119
|
+
border-bottom-left-radius: 2px;
|
|
120
|
+
box-shadow: 0 0 0.5px 0.5px var(--wp-admin-theme-color);
|
|
119
121
|
box-sizing: border-box;
|
|
120
122
|
z-index: 1;
|
|
121
123
|
background-color: #fff;
|
|
122
124
|
width: calc(100% + 2px);
|
|
123
125
|
right: -1px;
|
|
124
126
|
min-width: initial;
|
|
125
|
-
|
|
126
|
-
border-top: none;
|
|
127
|
-
box-shadow: 0 0 0 0.5px var(--wp-admin-theme-color);
|
|
128
|
-
border-bottom-right-radius: 2px;
|
|
129
|
-
border-bottom-left-radius: 2px;
|
|
127
|
+
max-height: 96px;
|
|
130
128
|
}
|
|
131
129
|
|
|
132
130
|
.patterns-create-modal__name-input input[type=text] {
|
|
133
|
-
min-height: 40px;
|
|
134
131
|
margin: 0;
|
|
135
132
|
}
|
|
136
133
|
|
package/build-style/style.css
CHANGED
|
@@ -110,27 +110,24 @@
|
|
|
110
110
|
width: 350px;
|
|
111
111
|
}
|
|
112
112
|
.patterns-menu-items__convert-modal .patterns-menu-items__convert-modal-categories {
|
|
113
|
-
width: 100%;
|
|
114
113
|
position: relative;
|
|
115
|
-
min-height: 40px;
|
|
116
114
|
}
|
|
117
|
-
.patterns-menu-items__convert-modal .components-form-token-field__suggestions-list {
|
|
115
|
+
.patterns-menu-items__convert-modal .components-form-token-field__suggestions-list:not(:empty) {
|
|
118
116
|
position: absolute;
|
|
117
|
+
border: 1px solid var(--wp-admin-theme-color);
|
|
118
|
+
border-bottom-left-radius: 2px;
|
|
119
|
+
border-bottom-right-radius: 2px;
|
|
120
|
+
box-shadow: 0 0 0.5px 0.5px var(--wp-admin-theme-color);
|
|
119
121
|
box-sizing: border-box;
|
|
120
122
|
z-index: 1;
|
|
121
123
|
background-color: #fff;
|
|
122
124
|
width: calc(100% + 2px);
|
|
123
125
|
left: -1px;
|
|
124
126
|
min-width: initial;
|
|
125
|
-
|
|
126
|
-
border-top: none;
|
|
127
|
-
box-shadow: 0 0 0 0.5px var(--wp-admin-theme-color);
|
|
128
|
-
border-bottom-left-radius: 2px;
|
|
129
|
-
border-bottom-right-radius: 2px;
|
|
127
|
+
max-height: 96px;
|
|
130
128
|
}
|
|
131
129
|
|
|
132
130
|
.patterns-create-modal__name-input input[type=text] {
|
|
133
|
-
min-height: 40px;
|
|
134
131
|
margin: 0;
|
|
135
132
|
}
|
|
136
133
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/patterns",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Management of user pattern editing.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -31,20 +31,20 @@
|
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/runtime": "^7.16.0",
|
|
34
|
-
"@wordpress/a11y": "^3.
|
|
35
|
-
"@wordpress/block-editor": "^12.
|
|
36
|
-
"@wordpress/blocks": "^12.
|
|
37
|
-
"@wordpress/components": "^25.
|
|
38
|
-
"@wordpress/compose": "^6.
|
|
39
|
-
"@wordpress/core-data": "^6.
|
|
40
|
-
"@wordpress/data": "^9.
|
|
41
|
-
"@wordpress/element": "^5.
|
|
42
|
-
"@wordpress/html-entities": "^3.
|
|
43
|
-
"@wordpress/i18n": "^4.
|
|
44
|
-
"@wordpress/icons": "^9.
|
|
45
|
-
"@wordpress/notices": "^4.
|
|
46
|
-
"@wordpress/private-apis": "^0.
|
|
47
|
-
"@wordpress/url": "^3.
|
|
34
|
+
"@wordpress/a11y": "^3.47.0",
|
|
35
|
+
"@wordpress/block-editor": "^12.15.0",
|
|
36
|
+
"@wordpress/blocks": "^12.24.0",
|
|
37
|
+
"@wordpress/components": "^25.13.0",
|
|
38
|
+
"@wordpress/compose": "^6.24.0",
|
|
39
|
+
"@wordpress/core-data": "^6.24.0",
|
|
40
|
+
"@wordpress/data": "^9.17.0",
|
|
41
|
+
"@wordpress/element": "^5.24.0",
|
|
42
|
+
"@wordpress/html-entities": "^3.47.0",
|
|
43
|
+
"@wordpress/i18n": "^4.47.0",
|
|
44
|
+
"@wordpress/icons": "^9.38.0",
|
|
45
|
+
"@wordpress/notices": "^4.15.0",
|
|
46
|
+
"@wordpress/private-apis": "^0.29.0",
|
|
47
|
+
"@wordpress/url": "^3.48.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"react": "^18.0.0",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "d98dff8ea96f29cfea045bf964269f46f040d539"
|
|
57
57
|
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
__experimentalVStack as VStack,
|
|
10
10
|
ToggleControl,
|
|
11
11
|
} from '@wordpress/components';
|
|
12
|
-
import { __ } from '@wordpress/i18n';
|
|
12
|
+
import { __, _x } from '@wordpress/i18n';
|
|
13
13
|
import { useState, useMemo } from '@wordpress/element';
|
|
14
14
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
15
15
|
import { store as noticesStore } from '@wordpress/notices';
|
|
@@ -166,12 +166,13 @@ export default function CreatePatternModal( {
|
|
|
166
166
|
>
|
|
167
167
|
<VStack spacing="5">
|
|
168
168
|
<TextControl
|
|
169
|
-
__nextHasNoMarginBottom
|
|
170
169
|
label={ __( 'Name' ) }
|
|
171
170
|
value={ title }
|
|
172
171
|
onChange={ setTitle }
|
|
173
172
|
placeholder={ __( 'My pattern' ) }
|
|
174
173
|
className="patterns-create-modal__name-input"
|
|
174
|
+
__nextHasNoMarginBottom
|
|
175
|
+
__next40pxDefaultSize
|
|
175
176
|
/>
|
|
176
177
|
<CategorySelector
|
|
177
178
|
categoryTerms={ categoryTerms }
|
|
@@ -179,9 +180,12 @@ export default function CreatePatternModal( {
|
|
|
179
180
|
categoryMap={ categoryMap }
|
|
180
181
|
/>
|
|
181
182
|
<ToggleControl
|
|
182
|
-
label={
|
|
183
|
+
label={ _x(
|
|
184
|
+
'Synced',
|
|
185
|
+
'Option that makes an individual pattern synchronized'
|
|
186
|
+
) }
|
|
183
187
|
help={ __(
|
|
184
|
-
'
|
|
188
|
+
'Sync this pattern across multiple locations.'
|
|
185
189
|
) }
|
|
186
190
|
checked={ syncType === PATTERN_SYNC_TYPES.full }
|
|
187
191
|
onChange={ () => {
|
|
@@ -194,6 +198,7 @@ export default function CreatePatternModal( {
|
|
|
194
198
|
/>
|
|
195
199
|
<HStack justify="right">
|
|
196
200
|
<Button
|
|
201
|
+
__next40pxDefaultSize
|
|
197
202
|
variant="tertiary"
|
|
198
203
|
onClick={ () => {
|
|
199
204
|
onClose();
|
|
@@ -204,6 +209,7 @@ export default function CreatePatternModal( {
|
|
|
204
209
|
</Button>
|
|
205
210
|
|
|
206
211
|
<Button
|
|
212
|
+
__next40pxDefaultSize
|
|
207
213
|
variant="primary"
|
|
208
214
|
type="submit"
|
|
209
215
|
aria-disabled={ ! title || isSaving }
|
|
@@ -10,11 +10,11 @@ import { store as noticesStore } from '@wordpress/notices';
|
|
|
10
10
|
* Internal dependencies
|
|
11
11
|
*/
|
|
12
12
|
import CreatePatternModal from './create-pattern-modal';
|
|
13
|
-
import { PATTERN_SYNC_TYPES } from '../constants';
|
|
13
|
+
import { PATTERN_SYNC_TYPES, PATTERN_TYPES } from '../constants';
|
|
14
14
|
|
|
15
15
|
function getTermLabels( pattern, categories ) {
|
|
16
|
-
// Theme patterns
|
|
17
|
-
if (
|
|
16
|
+
// Theme patterns rely on core pattern categories.
|
|
17
|
+
if ( pattern.type !== PATTERN_TYPES.user ) {
|
|
18
18
|
return categories.core
|
|
19
19
|
?.filter( ( category ) =>
|
|
20
20
|
pattern.categories.includes( category.name )
|
|
@@ -52,9 +52,10 @@ export default function DuplicatePatternModal( {
|
|
|
52
52
|
const duplicatedProps = {
|
|
53
53
|
content: pattern.content,
|
|
54
54
|
defaultCategories: getTermLabels( pattern, categories ),
|
|
55
|
-
defaultSyncType:
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
defaultSyncType:
|
|
56
|
+
pattern.type !== PATTERN_TYPES.user // Theme patterns are unsynced by default.
|
|
57
|
+
? PATTERN_SYNC_TYPES.unsynced
|
|
58
|
+
: pattern.wp_pattern_sync_status || PATTERN_SYNC_TYPES.full,
|
|
58
59
|
defaultTitle: sprintf(
|
|
59
60
|
/* translators: %s: Existing pattern title */
|
|
60
61
|
__( '%s (Copy)' ),
|
package/src/components/index.js
CHANGED
|
@@ -12,11 +12,12 @@ import PatternsManageButton from './patterns-manage-button';
|
|
|
12
12
|
export default function PatternsMenuItems( { rootClientId } ) {
|
|
13
13
|
return (
|
|
14
14
|
<BlockSettingsMenuControls>
|
|
15
|
-
{ ( { selectedClientIds } ) => (
|
|
15
|
+
{ ( { selectedClientIds, onClose } ) => (
|
|
16
16
|
<>
|
|
17
17
|
<PatternConvertButton
|
|
18
18
|
clientIds={ selectedClientIds }
|
|
19
19
|
rootClientId={ rootClientId }
|
|
20
|
+
closeBlockSettingsMenu={ onClose }
|
|
20
21
|
/>
|
|
21
22
|
{ selectedClientIds.length === 1 && (
|
|
22
23
|
<PatternsManageButton
|
|
@@ -26,12 +26,17 @@ import { PATTERN_SYNC_TYPES } from '../constants';
|
|
|
26
26
|
/**
|
|
27
27
|
* Menu control to convert block(s) to a pattern block.
|
|
28
28
|
*
|
|
29
|
-
* @param {Object} props
|
|
30
|
-
* @param {string[]} props.clientIds
|
|
31
|
-
* @param {string} props.rootClientId
|
|
29
|
+
* @param {Object} props Component props.
|
|
30
|
+
* @param {string[]} props.clientIds Client ids of selected blocks.
|
|
31
|
+
* @param {string} props.rootClientId ID of the currently selected top-level block.
|
|
32
|
+
* @param {()=>void} props.closeBlockSettingsMenu Callback to close the block settings menu dropdown.
|
|
32
33
|
* @return {import('react').ComponentType} The menu control or null.
|
|
33
34
|
*/
|
|
34
|
-
export default function PatternConvertButton( {
|
|
35
|
+
export default function PatternConvertButton( {
|
|
36
|
+
clientIds,
|
|
37
|
+
rootClientId,
|
|
38
|
+
closeBlockSettingsMenu,
|
|
39
|
+
} ) {
|
|
35
40
|
const { createSuccessNotice } = useDispatch( noticesStore );
|
|
36
41
|
const { replaceBlocks } = useDispatch( blockEditorStore );
|
|
37
42
|
// Ignore reason: false positive of the lint rule.
|
|
@@ -104,6 +109,7 @@ export default function PatternConvertButton( { clientIds, rootClientId } ) {
|
|
|
104
109
|
|
|
105
110
|
replaceBlocks( clientIds, newBlock );
|
|
106
111
|
setEditingPattern( newBlock.clientId, true );
|
|
112
|
+
closeBlockSettingsMenu();
|
|
107
113
|
}
|
|
108
114
|
|
|
109
115
|
createSuccessNotice(
|