@wordpress/patterns 1.7.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +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 +6 -3
- 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/partial-syncing-controls.js +91 -0
- package/build/components/partial-syncing-controls.js.map +1 -0
- 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 +1 -2
- package/build/components/patterns-manage-button.js.map +1 -1
- package/build/components/rename-pattern-category-modal.js +3 -0
- package/build/components/rename-pattern-category-modal.js.map +1 -1
- package/build/components/rename-pattern-modal.js +3 -0
- package/build/components/rename-pattern-modal.js.map +1 -1
- package/build/constants.js +14 -1
- package/build/constants.js.map +1 -1
- package/build/private-apis.js +4 -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 +6 -3
- 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/partial-syncing-controls.js +83 -0
- package/build-module/components/partial-syncing-controls.js.map +1 -0
- 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 +1 -2
- package/build-module/components/patterns-manage-button.js.map +1 -1
- package/build-module/components/rename-pattern-category-modal.js +3 -0
- package/build-module/components/rename-pattern-category-modal.js.map +1 -1
- package/build-module/components/rename-pattern-modal.js +3 -0
- package/build-module/components/rename-pattern-modal.js.map +1 -1
- package/build-module/constants.js +11 -0
- package/build-module/constants.js.map +1 -1
- package/build-module/private-apis.js +5 -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 +17 -16
- package/src/components/category-selector.js +1 -0
- package/src/components/create-pattern-modal.js +5 -2
- package/src/components/duplicate-pattern-modal.js +7 -6
- package/src/components/index.js +2 -1
- package/src/components/partial-syncing-controls.js +98 -0
- package/src/components/pattern-convert-button.js +10 -4
- package/src/components/patterns-manage-button.js +34 -37
- package/src/components/rename-pattern-category-modal.js +7 -1
- package/src/components/rename-pattern-modal.js +11 -2
- package/src/components/style.scss +9 -14
- package/src/constants.js +10 -0
- package/src/private-apis.js +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -53,7 +53,8 @@ function CategorySelector({
|
|
|
53
53
|
label: (0, _i18n.__)('Categories'),
|
|
54
54
|
tokenizeOnBlur: true,
|
|
55
55
|
__experimentalExpandOnFocus: true,
|
|
56
|
-
__next40pxDefaultSize: true
|
|
56
|
+
__next40pxDefaultSize: true,
|
|
57
|
+
__nextHasNoMarginBottom: true
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
60
|
//# sourceMappingURL=category-selector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_element","_components","_compose","_htmlEntities","unescapeString","arg","decodeEntities","CATEGORY_SLUG","exports","CategorySelector","categoryTerms","onChange","categoryMap","search","setSearch","useState","debouncedSearch","useDebounce","suggestions","useMemo","Array","from","values","map","category","label","filter","toLowerCase","includes","sort","a","b","localeCompare","handleChange","termNames","uniqueTerms","reduce","terms","newTerm","some","term","push","_react","createElement","FormTokenField","className","value","onInputChange","__","tokenizeOnBlur","__experimentalExpandOnFocus","__next40pxDefaultSize"],"sources":["@wordpress/patterns/src/components/category-selector.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useMemo, useState } from '@wordpress/element';\nimport { FormTokenField } from '@wordpress/components';\nimport { useDebounce } from '@wordpress/compose';\nimport { decodeEntities } from '@wordpress/html-entities';\n\nconst unescapeString = ( arg ) => {\n\treturn decodeEntities( arg );\n};\n\nexport const CATEGORY_SLUG = 'wp_pattern_category';\n\nexport default function CategorySelector( {\n\tcategoryTerms,\n\tonChange,\n\tcategoryMap,\n} ) {\n\tconst [ search, setSearch ] = useState( '' );\n\tconst debouncedSearch = useDebounce( setSearch, 500 );\n\n\tconst suggestions = useMemo( () => {\n\t\treturn Array.from( categoryMap.values() )\n\t\t\t.map( ( category ) => unescapeString( category.label ) )\n\t\t\t.filter( ( category ) => {\n\t\t\t\tif ( search !== '' ) {\n\t\t\t\t\treturn category\n\t\t\t\t\t\t.toLowerCase()\n\t\t\t\t\t\t.includes( search.toLowerCase() );\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t} )\n\t\t\t.sort( ( a, b ) => a.localeCompare( b ) );\n\t}, [ search, categoryMap ] );\n\n\tfunction handleChange( termNames ) {\n\t\tconst uniqueTerms = termNames.reduce( ( terms, newTerm ) => {\n\t\t\tif (\n\t\t\t\t! terms.some(\n\t\t\t\t\t( term ) => term.toLowerCase() === newTerm.toLowerCase()\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tterms.push( newTerm );\n\t\t\t}\n\t\t\treturn terms;\n\t\t}, [] );\n\n\t\tonChange( uniqueTerms );\n\t}\n\n\treturn (\n\t\t<FormTokenField\n\t\t\tclassName=\"patterns-menu-items__convert-modal-categories\"\n\t\t\tvalue={ categoryTerms }\n\t\t\tsuggestions={ suggestions }\n\t\t\tonChange={ handleChange }\n\t\t\tonInputChange={ debouncedSearch }\n\t\t\tlabel={ __( 'Categories' ) }\n\t\t\ttokenizeOnBlur\n\t\t\t__experimentalExpandOnFocus\n\t\t\t__next40pxDefaultSize\n\t\t/>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA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,KAAK,EAAEC,OAAO,KAAM;MAC3D,IACC,CAAED,KAAK,CAACE,IAAI,CACTC,IAAI,IAAMA,IAAI,CAACb,WAAW,CAAC,CAAC,KAAKW,OAAO,CAACX,WAAW,CAAC,CACxD,CAAC,EACA;QACDU,KAAK,CAACI,IAAI,CAAEH,OAAQ,CAAC;MACtB;MACA,OAAOD,KAAK;IACb,CAAC,EAAE,EAAG,CAAC;IAEP1B,QAAQ,CAAEwB,WAAY,CAAC;EACxB;EAEA,OACC,IAAAO,MAAA,CAAAC,aAAA,EAAC1C,WAAA,CAAA2C,cAAc;IACdC,SAAS,EAAC,+CAA+C;IACzDC,KAAK,EAAGpC,aAAe;IACvBQ,WAAW,EAAGA,WAAa;IAC3BP,QAAQ,EAAGsB,YAAc;IACzBc,aAAa,EAAG/B,eAAiB;IACjCS,KAAK,EAAG,IAAAuB,QAAE,EAAE,YAAa,CAAG;IAC5BC,cAAc;IACdC,2BAA2B;IAC3BC,qBAAqB;EAAA,
|
|
1
|
+
{"version":3,"names":["_i18n","require","_element","_components","_compose","_htmlEntities","unescapeString","arg","decodeEntities","CATEGORY_SLUG","exports","CategorySelector","categoryTerms","onChange","categoryMap","search","setSearch","useState","debouncedSearch","useDebounce","suggestions","useMemo","Array","from","values","map","category","label","filter","toLowerCase","includes","sort","a","b","localeCompare","handleChange","termNames","uniqueTerms","reduce","terms","newTerm","some","term","push","_react","createElement","FormTokenField","className","value","onInputChange","__","tokenizeOnBlur","__experimentalExpandOnFocus","__next40pxDefaultSize","__nextHasNoMarginBottom"],"sources":["@wordpress/patterns/src/components/category-selector.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useMemo, useState } from '@wordpress/element';\nimport { FormTokenField } from '@wordpress/components';\nimport { useDebounce } from '@wordpress/compose';\nimport { decodeEntities } from '@wordpress/html-entities';\n\nconst unescapeString = ( arg ) => {\n\treturn decodeEntities( arg );\n};\n\nexport const CATEGORY_SLUG = 'wp_pattern_category';\n\nexport default function CategorySelector( {\n\tcategoryTerms,\n\tonChange,\n\tcategoryMap,\n} ) {\n\tconst [ search, setSearch ] = useState( '' );\n\tconst debouncedSearch = useDebounce( setSearch, 500 );\n\n\tconst suggestions = useMemo( () => {\n\t\treturn Array.from( categoryMap.values() )\n\t\t\t.map( ( category ) => unescapeString( category.label ) )\n\t\t\t.filter( ( category ) => {\n\t\t\t\tif ( search !== '' ) {\n\t\t\t\t\treturn category\n\t\t\t\t\t\t.toLowerCase()\n\t\t\t\t\t\t.includes( search.toLowerCase() );\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t} )\n\t\t\t.sort( ( a, b ) => a.localeCompare( b ) );\n\t}, [ search, categoryMap ] );\n\n\tfunction handleChange( termNames ) {\n\t\tconst uniqueTerms = termNames.reduce( ( terms, newTerm ) => {\n\t\t\tif (\n\t\t\t\t! terms.some(\n\t\t\t\t\t( term ) => term.toLowerCase() === newTerm.toLowerCase()\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tterms.push( newTerm );\n\t\t\t}\n\t\t\treturn terms;\n\t\t}, [] );\n\n\t\tonChange( uniqueTerms );\n\t}\n\n\treturn (\n\t\t<FormTokenField\n\t\t\tclassName=\"patterns-menu-items__convert-modal-categories\"\n\t\t\tvalue={ categoryTerms }\n\t\t\tsuggestions={ suggestions }\n\t\t\tonChange={ handleChange }\n\t\t\tonInputChange={ debouncedSearch }\n\t\t\tlabel={ __( 'Categories' ) }\n\t\t\ttokenizeOnBlur\n\t\t\t__experimentalExpandOnFocus\n\t\t\t__next40pxDefaultSize\n\t\t\t__nextHasNoMarginBottom\n\t\t/>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AAPA;AACA;AACA;;AAOA,MAAMK,cAAc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I,CAAEH,OAAQ,CAAC;MACtB;MACA,OAAOD,KAAK;IACb,CAAC,EAAE,EAAG,CAAC;IAEP1B,QAAQ,CAAEwB,WAAY,CAAC;EACxB;EAEA,OACC,IAAAO,MAAA,CAAAC,aAAA,EAAC1C,WAAA,CAAA2C,cAAc;IACdC,SAAS,EAAC,+CAA+C;IACzDC,KAAK,EAAGpC,aAAe;IACvBQ,WAAW,EAAGA,WAAa;IAC3BP,QAAQ,EAAGsB,YAAc;IACzBc,aAAa,EAAG/B,eAAiB;IACjCS,KAAK,EAAG,IAAAuB,QAAE,EAAE,YAAa,CAAG;IAC5BC,cAAc;IACdC,2BAA2B;IAC3BC,qBAAqB;IACrBC,uBAAuB;EAAA,CACvB,CAAC;AAEJ"}
|
|
@@ -154,19 +154,20 @@ function CreatePatternModal({
|
|
|
154
154
|
}, (0, _react.createElement)(_components.__experimentalVStack, {
|
|
155
155
|
spacing: "5"
|
|
156
156
|
}, (0, _react.createElement)(_components.TextControl, {
|
|
157
|
-
__nextHasNoMarginBottom: true,
|
|
158
157
|
label: (0, _i18n.__)('Name'),
|
|
159
158
|
value: title,
|
|
160
159
|
onChange: setTitle,
|
|
161
160
|
placeholder: (0, _i18n.__)('My pattern'),
|
|
162
|
-
className: "patterns-create-modal__name-input"
|
|
161
|
+
className: "patterns-create-modal__name-input",
|
|
162
|
+
__nextHasNoMarginBottom: true,
|
|
163
|
+
__next40pxDefaultSize: true
|
|
163
164
|
}), (0, _react.createElement)(_categorySelector.default, {
|
|
164
165
|
categoryTerms: categoryTerms,
|
|
165
166
|
onChange: setCategoryTerms,
|
|
166
167
|
categoryMap: categoryMap
|
|
167
168
|
}), (0, _react.createElement)(_components.ToggleControl, {
|
|
168
169
|
label: (0, _i18n._x)('Synced', 'Option that makes an individual pattern synchronized'),
|
|
169
|
-
help: (0, _i18n.__)('
|
|
170
|
+
help: (0, _i18n.__)('Sync this pattern across multiple locations.'),
|
|
170
171
|
checked: syncType === _constants.PATTERN_SYNC_TYPES.full,
|
|
171
172
|
onChange: () => {
|
|
172
173
|
setSyncType(syncType === _constants.PATTERN_SYNC_TYPES.full ? _constants.PATTERN_SYNC_TYPES.unsynced : _constants.PATTERN_SYNC_TYPES.full);
|
|
@@ -174,12 +175,14 @@ function CreatePatternModal({
|
|
|
174
175
|
}), (0, _react.createElement)(_components.__experimentalHStack, {
|
|
175
176
|
justify: "right"
|
|
176
177
|
}, (0, _react.createElement)(_components.Button, {
|
|
178
|
+
__next40pxDefaultSize: true,
|
|
177
179
|
variant: "tertiary",
|
|
178
180
|
onClick: () => {
|
|
179
181
|
onClose();
|
|
180
182
|
setTitle('');
|
|
181
183
|
}
|
|
182
184
|
}, (0, _i18n.__)('Cancel')), (0, _react.createElement)(_components.Button, {
|
|
185
|
+
__next40pxDefaultSize: true,
|
|
183
186
|
variant: "primary",
|
|
184
187
|
type: "submit",
|
|
185
188
|
"aria-disabled": !title || isSaving,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_i18n","_element","_data","_notices","_coreData","_constants","_store","_categorySelector","_interopRequireWildcard","_lockUnlock","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","CreatePatternModal","confirmLabel","__","defaultCategories","className","content","modalTitle","onClose","onError","onSuccess","defaultSyncType","PATTERN_SYNC_TYPES","full","defaultTitle","syncType","setSyncType","useState","categoryTerms","setCategoryTerms","title","setTitle","isSaving","setIsSaving","createPattern","unlock","useDispatch","patternsStore","saveEntityRecord","invalidateResolution","coreStore","createErrorNotice","noticesStore","corePatternCategories","userPatternCategories","useSelect","select","getUserPatternCategories","getBlockPatternCategories","categoryMap","useMemo","uniqueCategories","Map","forEach","category","label","name","value","onCreate","patternTitle","sync","categories","Promise","all","map","termName","findOrCreateTerm","newPattern","pattern","categoryId","PATTERN_DEFAULT_CATEGORY","error","message","type","id","term","existingTerm","termData","slug","newTerm","CATEGORY_SLUG","throwOnError","code","data","term_id","_react","createElement","Modal","onRequestClose","overlayClassName","onSubmit","event","preventDefault","__experimentalVStack","spacing","TextControl","__nextHasNoMarginBottom","onChange","placeholder","ToggleControl","_x","help","checked","unsynced","__experimentalHStack","justify","Button","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\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={ _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'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{ confir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ACVD,QAAQ,KAAKH,6BAAkB,CAACC,IAAI,GACjCD,6BAAkB,CAACiF,QAAQ,GAC3BjF,6BAAkB,CAACC,IACvB,CAAC;IACF;EAAG,CACH,CAAC,EACF,IAAA8D,MAAA,CAAAC,aAAA,EAAC7G,WAAA,CAAA+H,oBAAM;IAACC,OAAO,EAAC;EAAO,GACtB,IAAApB,MAAA,CAAAC,aAAA,EAAC7G,WAAA,CAAAiI,MAAM;IACNC,OAAO,EAAC,UAAU;IAClBC,OAAO,EAAGA,CAAA,KAAM;MACf1F,OAAO,CAAC,CAAC;MACTa,QAAQ,CAAE,EAAG,CAAC;IACf;EAAG,GAED,IAAAlB,QAAE,EAAE,QAAS,CACR,CAAC,EAET,IAAAwE,MAAA,CAAAC,aAAA,EAAC7G,WAAA,CAAAiI,MAAM;IACNC,OAAO,EAAC,SAAS;IACjBlC,IAAI,EAAC,QAAQ;IACb,iBAAgB,CAAE3C,KAAK,IAAIE,QAAU;IACrC6E,MAAM,EAAG7E;EAAU,GAEjBpB,YACK,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_element","_data","_notices","_coreData","_constants","_store","_categorySelector","_interopRequireWildcard","_lockUnlock","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","CreatePatternModal","confirmLabel","__","defaultCategories","className","content","modalTitle","onClose","onError","onSuccess","defaultSyncType","PATTERN_SYNC_TYPES","full","defaultTitle","syncType","setSyncType","useState","categoryTerms","setCategoryTerms","title","setTitle","isSaving","setIsSaving","createPattern","unlock","useDispatch","patternsStore","saveEntityRecord","invalidateResolution","coreStore","createErrorNotice","noticesStore","corePatternCategories","userPatternCategories","useSelect","select","getUserPatternCategories","getBlockPatternCategories","categoryMap","useMemo","uniqueCategories","Map","forEach","category","label","name","value","onCreate","patternTitle","sync","categories","Promise","all","map","termName","findOrCreateTerm","newPattern","pattern","categoryId","PATTERN_DEFAULT_CATEGORY","error","message","type","id","term","existingTerm","termData","slug","newTerm","CATEGORY_SLUG","throwOnError","code","data","term_id","_react","createElement","Modal","onRequestClose","overlayClassName","onSubmit","event","preventDefault","__experimentalVStack","spacing","TextControl","onChange","placeholder","__nextHasNoMarginBottom","__next40pxDefaultSize","ToggleControl","_x","help","checked","unsynced","__experimentalHStack","justify","Button","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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AAK,EAAG,IAAA8C,QAAE,EACT,QAAQ,EACR,sDACD,CAAG;IACHC,IAAI,EAAG,IAAAzF,QAAE,EACR,8CACD,CAAG;IACH0F,OAAO,EAAG9E,QAAQ,KAAKH,6BAAkB,CAACC,IAAM;IAChDyE,QAAQ,EAAGA,CAAA,KAAM;MAChBtE,WAAW,CACVD,QAAQ,KAAKH,6BAAkB,CAACC,IAAI,GACjCD,6BAAkB,CAACkF,QAAQ,GAC3BlF,6BAAkB,CAACC,IACvB,CAAC;IACF;EAAG,CACH,CAAC,EACF,IAAA8D,MAAA,CAAAC,aAAA,EAAC7G,WAAA,CAAAgI,oBAAM;IAACC,OAAO,EAAC;EAAO,GACtB,IAAArB,MAAA,CAAAC,aAAA,EAAC7G,WAAA,CAAAkI,MAAM;IACNR,qBAAqB;IACrBS,OAAO,EAAC,UAAU;IAClBC,OAAO,EAAGA,CAAA,KAAM;MACf3F,OAAO,CAAC,CAAC;MACTa,QAAQ,CAAE,EAAG,CAAC;IACf;EAAG,GAED,IAAAlB,QAAE,EAAE,QAAS,CACR,CAAC,EAET,IAAAwE,MAAA,CAAAC,aAAA,EAAC7G,WAAA,CAAAkI,MAAM;IACNR,qBAAqB;IACrBS,OAAO,EAAC,SAAS;IACjBnC,IAAI,EAAC,QAAQ;IACb,iBAAgB,CAAE3C,KAAK,IAAIE,QAAU;IACrC8E,MAAM,EAAG9E;EAAU,GAEjBpB,YACK,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
@@ -21,8 +21,8 @@ var _constants = require("../constants");
|
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
function getTermLabels(pattern, categories) {
|
|
24
|
-
// Theme patterns
|
|
25
|
-
if (
|
|
24
|
+
// Theme patterns rely on core pattern categories.
|
|
25
|
+
if (pattern.type !== _constants.PATTERN_TYPES.user) {
|
|
26
26
|
return categories.core?.filter(category => pattern.categories.includes(category.name)).map(category => category.label);
|
|
27
27
|
}
|
|
28
28
|
return categories.user?.filter(category => pattern.wp_pattern_category.includes(category.id)).map(category => category.label);
|
|
@@ -51,7 +51,7 @@ function DuplicatePatternModal({
|
|
|
51
51
|
const duplicatedProps = {
|
|
52
52
|
content: pattern.content,
|
|
53
53
|
defaultCategories: getTermLabels(pattern, categories),
|
|
54
|
-
defaultSyncType:
|
|
54
|
+
defaultSyncType: pattern.type !== _constants.PATTERN_TYPES.user // Theme patterns are unsynced by default.
|
|
55
55
|
? _constants.PATTERN_SYNC_TYPES.unsynced : pattern.wp_pattern_sync_status || _constants.PATTERN_SYNC_TYPES.full,
|
|
56
56
|
defaultTitle: (0, _i18n.sprintf)( /* translators: %s: Existing pattern title */
|
|
57
57
|
(0, _i18n.__)('%s (Copy)'), typeof pattern.title === 'string' ? pattern.title : pattern.title.raw)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_coreData","require","_data","_i18n","_notices","_createPatternModal","_interopRequireDefault","_constants","getTermLabels","pattern","categories","
|
|
1
|
+
{"version":3,"names":["_coreData","require","_data","_i18n","_notices","_createPatternModal","_interopRequireDefault","_constants","getTermLabels","pattern","categories","type","PATTERN_TYPES","user","core","filter","category","includes","name","map","label","wp_pattern_category","id","DuplicatePatternModal","onClose","onSuccess","createSuccessNotice","useDispatch","noticesStore","useSelect","select","getUserPatternCategories","getBlockPatternCategories","coreStore","duplicatedProps","content","defaultCategories","defaultSyncType","PATTERN_SYNC_TYPES","unsynced","wp_pattern_sync_status","full","defaultTitle","sprintf","__","title","raw","handleOnSuccess","newPattern","_react","createElement","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 { __, 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":";;;;;;;;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;AAZA;AACA;AACA;;AAMA;AACA;AACA;;AAIA,SAASO,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,CAACO,QAAQ,CAAED,QAAQ,CAACE,IAAK,CAC5C,CAAC,CACAC,GAAG,CAAIH,QAAQ,IAAMA,QAAQ,CAACI,KAAM,CAAC;EACxC;EAEA,OAAOV,UAAU,CAACG,IAAI,EACnBE,MAAM,CAAIC,QAAQ,IACnBP,OAAO,CAACY,mBAAmB,CAACJ,QAAQ,CAAED,QAAQ,CAACM,EAAG,CACnD,CAAC,CACAH,GAAG,CAAIH,QAAQ,IAAMA,QAAQ,CAACI,KAAM,CAAC;AACxC;AAEe,SAASG,qBAAqBA,CAAE;EAC9Cd,OAAO;EACPe,OAAO;EACPC;AACD,CAAC,EAAG;EACH,MAAM;IAAEC;EAAoB,CAAC,GAAG,IAAAC,iBAAW,EAAEC,cAAa,C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AG,IAAAR,QAAE,EAAE,mBAAoB,CAAG;IACxCS,YAAY,EAAG,IAAAT,QAAE,EAAE,WAAY,CAAG;IAClCpB,OAAO,EAAGA,OAAS;IACnB8B,OAAO,EAAG9B,OAAS;IACnBC,SAAS,EAAGsB,eAAiB;IAAA,GACxBb;EAAe,CACpB,CAAC;AAEJ"}
|
|
@@ -21,10 +21,12 @@ function PatternsMenuItems({
|
|
|
21
21
|
rootClientId
|
|
22
22
|
}) {
|
|
23
23
|
return (0, _react.createElement)(_blockEditor.BlockSettingsMenuControls, null, ({
|
|
24
|
-
selectedClientIds
|
|
24
|
+
selectedClientIds,
|
|
25
|
+
onClose
|
|
25
26
|
}) => (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)(_patternConvertButton.default, {
|
|
26
27
|
clientIds: selectedClientIds,
|
|
27
|
-
rootClientId: rootClientId
|
|
28
|
+
rootClientId: rootClientId,
|
|
29
|
+
closeBlockSettingsMenu: onClose
|
|
28
30
|
}), selectedClientIds.length === 1 && (0, _react.createElement)(_patternsManageButton.default, {
|
|
29
31
|
clientId: selectedClientIds[0]
|
|
30
32
|
})));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_blockEditor","require","_patternConvertButton","_interopRequireDefault","_patternsManageButton","PatternsMenuItems","rootClientId","_react","createElement","BlockSettingsMenuControls","selectedClientIds","Fragment","default","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":";;;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAKA,IAAAC,qBAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAD,sBAAA,CAAAF,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIe,SAASI,iBAAiBA,CAAE;EAAEC;AAAa,CAAC,EAAG;EAC7D,OACC,IAAAC,MAAA,CAAAC,aAAA,EAACR,YAAA,CAAAS,yBAAyB,QACvB,CAAE;IAAEC;
|
|
1
|
+
{"version":3,"names":["_blockEditor","require","_patternConvertButton","_interopRequireDefault","_patternsManageButton","PatternsMenuItems","rootClientId","_react","createElement","BlockSettingsMenuControls","selectedClientIds","onClose","Fragment","default","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":";;;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAKA,IAAAC,qBAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAD,sBAAA,CAAAF,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIe,SAASI,iBAAiBA,CAAE;EAAEC;AAAa,CAAC,EAAG;EAC7D,OACC,IAAAC,MAAA,CAAAC,aAAA,EAACR,YAAA,CAAAS,yBAAyB,QACvB,CAAE;IAAEC,iBAAiB;IAAEC;EAAQ,CAAC,KACjC,IAAAJ,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAK,QAAA,QACC,IAAAL,MAAA,CAAAC,aAAA,EAACN,qBAAA,CAAAW,OAAoB;IACpBC,SAAS,EAAGJ,iBAAmB;IAC/BJ,YAAY,EAAGA,YAAc;IAC7BS,sBAAsB,EAAGJ;EAAS,CAClC,CAAC,EACAD,iBAAiB,CAACM,MAAM,KAAK,CAAC,IAC/B,IAAAT,MAAA,CAAAC,aAAA,EAACJ,qBAAA,CAAAS,OAAoB;IACpBI,QAAQ,EAAGP,iBAAiB,CAAE,CAAC;EAAI,CACnC,CAED,CAEuB,CAAC;AAE9B"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _nanoid = require("nanoid");
|
|
9
|
+
var _blockEditor = require("@wordpress/block-editor");
|
|
10
|
+
var _components = require("@wordpress/components");
|
|
11
|
+
var _i18n = require("@wordpress/i18n");
|
|
12
|
+
var _constants = require("../constants");
|
|
13
|
+
/**
|
|
14
|
+
* External dependencies
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* WordPress dependencies
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Internal dependencies
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
function PartialSyncingControls({
|
|
26
|
+
name,
|
|
27
|
+
attributes,
|
|
28
|
+
setAttributes
|
|
29
|
+
}) {
|
|
30
|
+
const syncedAttributes = _constants.PARTIAL_SYNCING_SUPPORTED_BLOCKS[name];
|
|
31
|
+
function updateConnections(attributeName, isChecked) {
|
|
32
|
+
if (!isChecked) {
|
|
33
|
+
let updatedConnections = {
|
|
34
|
+
...attributes.connections,
|
|
35
|
+
attributes: {
|
|
36
|
+
...attributes.connections?.attributes,
|
|
37
|
+
[attributeName]: undefined
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
if (Object.keys(updatedConnections.attributes).length === 1) {
|
|
41
|
+
updatedConnections.attributes = undefined;
|
|
42
|
+
}
|
|
43
|
+
if (Object.keys(updatedConnections).length === 1 && updateConnections.attributes === undefined) {
|
|
44
|
+
updatedConnections = undefined;
|
|
45
|
+
}
|
|
46
|
+
setAttributes({
|
|
47
|
+
connections: updatedConnections
|
|
48
|
+
});
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const updatedConnections = {
|
|
52
|
+
...attributes.connections,
|
|
53
|
+
attributes: {
|
|
54
|
+
...attributes.connections?.attributes,
|
|
55
|
+
[attributeName]: {
|
|
56
|
+
source: 'pattern_attributes'
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
if (typeof attributes.metadata?.id === 'string') {
|
|
61
|
+
setAttributes({
|
|
62
|
+
connections: updatedConnections
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const id = (0, _nanoid.nanoid)(6);
|
|
67
|
+
setAttributes({
|
|
68
|
+
connections: updatedConnections,
|
|
69
|
+
metadata: {
|
|
70
|
+
...attributes.metadata,
|
|
71
|
+
id
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return (0, _react.createElement)(_blockEditor.InspectorControls, {
|
|
76
|
+
group: "advanced"
|
|
77
|
+
}, (0, _react.createElement)(_components.BaseControl, {
|
|
78
|
+
__nextHasNoMarginBottom: true
|
|
79
|
+
}, (0, _react.createElement)(_components.BaseControl.VisualLabel, null, (0, _i18n.__)('Synced attributes')), Object.entries(syncedAttributes).map(([attributeName, label]) => (0, _react.createElement)(_components.CheckboxControl, {
|
|
80
|
+
key: attributeName,
|
|
81
|
+
__nextHasNoMarginBottom: true,
|
|
82
|
+
label: label,
|
|
83
|
+
checked: attributes.connections?.attributes?.[attributeName]?.source === 'pattern_attributes',
|
|
84
|
+
onChange: isChecked => {
|
|
85
|
+
updateConnections(attributeName, isChecked);
|
|
86
|
+
}
|
|
87
|
+
}))));
|
|
88
|
+
}
|
|
89
|
+
var _default = PartialSyncingControls;
|
|
90
|
+
exports.default = _default;
|
|
91
|
+
//# sourceMappingURL=partial-syncing-controls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_nanoid","require","_blockEditor","_components","_i18n","_constants","PartialSyncingControls","name","attributes","setAttributes","syncedAttributes","PARTIAL_SYNCING_SUPPORTED_BLOCKS","updateConnections","attributeName","isChecked","updatedConnections","connections","undefined","Object","keys","length","source","metadata","id","nanoid","_react","createElement","InspectorControls","group","BaseControl","__nextHasNoMarginBottom","VisualLabel","__","entries","map","label","CheckboxControl","key","checked","onChange","_default","exports","default"],"sources":["@wordpress/patterns/src/components/partial-syncing-controls.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { nanoid } from 'nanoid';\n\n/**\n * WordPress dependencies\n */\nimport { InspectorControls } from '@wordpress/block-editor';\nimport { BaseControl, CheckboxControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { PARTIAL_SYNCING_SUPPORTED_BLOCKS } from '../constants';\n\nfunction PartialSyncingControls( { name, attributes, setAttributes } ) {\n\tconst syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ];\n\n\tfunction updateConnections( attributeName, isChecked ) {\n\t\tif ( ! isChecked ) {\n\t\t\tlet updatedConnections = {\n\t\t\t\t...attributes.connections,\n\t\t\t\tattributes: {\n\t\t\t\t\t...attributes.connections?.attributes,\n\t\t\t\t\t[ attributeName ]: undefined,\n\t\t\t\t},\n\t\t\t};\n\t\t\tif ( Object.keys( updatedConnections.attributes ).length === 1 ) {\n\t\t\t\tupdatedConnections.attributes = undefined;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tObject.keys( updatedConnections ).length === 1 &&\n\t\t\t\tupdateConnections.attributes === undefined\n\t\t\t) {\n\t\t\t\tupdatedConnections = undefined;\n\t\t\t}\n\t\t\tsetAttributes( {\n\t\t\t\tconnections: updatedConnections,\n\t\t\t} );\n\t\t\treturn;\n\t\t}\n\n\t\tconst updatedConnections = {\n\t\t\t...attributes.connections,\n\t\t\tattributes: {\n\t\t\t\t...attributes.connections?.attributes,\n\t\t\t\t[ attributeName ]: {\n\t\t\t\t\tsource: 'pattern_attributes',\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\tif ( typeof attributes.metadata?.id === 'string' ) {\n\t\t\tsetAttributes( { connections: updatedConnections } );\n\t\t\treturn;\n\t\t}\n\n\t\tconst id = nanoid( 6 );\n\t\tsetAttributes( {\n\t\t\tconnections: updatedConnections,\n\t\t\tmetadata: {\n\t\t\t\t...attributes.metadata,\n\t\t\t\tid,\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn (\n\t\t<InspectorControls group=\"advanced\">\n\t\t\t<BaseControl __nextHasNoMarginBottom>\n\t\t\t\t<BaseControl.VisualLabel>\n\t\t\t\t\t{ __( 'Synced attributes' ) }\n\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t{ Object.entries( syncedAttributes ).map(\n\t\t\t\t\t( [ attributeName, label ] ) => (\n\t\t\t\t\t\t<CheckboxControl\n\t\t\t\t\t\t\tkey={ attributeName }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\tlabel={ label }\n\t\t\t\t\t\t\tchecked={\n\t\t\t\t\t\t\t\tattributes.connections?.attributes?.[\n\t\t\t\t\t\t\t\t\tattributeName\n\t\t\t\t\t\t\t\t]?.source === 'pattern_attributes'\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonChange={ ( isChecked ) => {\n\t\t\t\t\t\t\t\tupdateConnections( attributeName, isChecked );\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) }\n\t\t\t</BaseControl>\n\t\t</InspectorControls>\n\t);\n}\n\nexport default PartialSyncingControls;\n"],"mappings":";;;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AAKA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,UAAA,GAAAJ,OAAA;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;;AAGA,SAASK,sBAAsBA,CAAE;EAAEC,IAAI;EAAEC,UAAU;EAAEC;AAAc,CAAC,EAAG;EACtE,MAAMC,gBAAgB,GAAGC,2CAAgC,CAAEJ,IAAI,CAAE;EAEjE,SAASK,iBAAiBA,CAAEC,aAAa,EAAEC,SAAS,EAAG;IACtD,IAAK,CAAEA,SAAS,EAAG;MAClB,IAAIC,kBAAkB,GAAG;QACxB,GAAGP,UAAU,CAACQ,WAAW;QACzBR,UAAU,EAAE;UACX,GAAGA,UAAU,CAACQ,WAAW,EAAER,UAAU;UACrC,CAAEK,aAAa,GAAII;QACpB;MACD,CAAC;MACD,IAAKC,MAAM,CAACC,IAAI,CAAEJ,kBAAkB,CAACP,UAAW,CAAC,CAACY,MAAM,KAAK,CAAC,EAAG;QAChEL,kBAA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e;IACfC,GAAG,EAAGxB,aAAe;IACrBiB,uBAAuB;IACvBK,KAAK,EAAGA,KAAO;IACfG,OAAO,EACN9B,UAAU,CAACQ,WAAW,EAAER,UAAU,GACjCK,aAAa,CACb,EAAEQ,MAAM,KAAK,oBACd;IACDkB,QAAQ,EAAKzB,SAAS,IAAM;MAC3BF,iBAAiB,CAAEC,aAAa,EAAEC,SAAU,CAAC;IAC9C;EAAG,CACH,CAEH,CACY,CACK,CAAC;AAEtB;AAAC,IAAA0B,QAAA,GAEclC,sBAAsB;AAAAmC,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
|
@@ -30,14 +30,16 @@ var _constants = require("../constants");
|
|
|
30
30
|
/**
|
|
31
31
|
* Menu control to convert block(s) to a pattern block.
|
|
32
32
|
*
|
|
33
|
-
* @param {Object} props
|
|
34
|
-
* @param {string[]} props.clientIds
|
|
35
|
-
* @param {string} props.rootClientId
|
|
33
|
+
* @param {Object} props Component props.
|
|
34
|
+
* @param {string[]} props.clientIds Client ids of selected blocks.
|
|
35
|
+
* @param {string} props.rootClientId ID of the currently selected top-level block.
|
|
36
|
+
* @param {()=>void} props.closeBlockSettingsMenu Callback to close the block settings menu dropdown.
|
|
36
37
|
* @return {import('react').ComponentType} The menu control or null.
|
|
37
38
|
*/
|
|
38
39
|
function PatternConvertButton({
|
|
39
40
|
clientIds,
|
|
40
|
-
rootClientId
|
|
41
|
+
rootClientId,
|
|
42
|
+
closeBlockSettingsMenu
|
|
41
43
|
}) {
|
|
42
44
|
const {
|
|
43
45
|
createSuccessNotice
|
|
@@ -95,6 +97,7 @@ function PatternConvertButton({
|
|
|
95
97
|
});
|
|
96
98
|
replaceBlocks(clientIds, newBlock);
|
|
97
99
|
setEditingPattern(newBlock.clientId, true);
|
|
100
|
+
closeBlockSettingsMenu();
|
|
98
101
|
}
|
|
99
102
|
createSuccessNotice(pattern.wp_pattern_sync_status === _constants.PATTERN_SYNC_TYPES.unsynced ? (0, _i18n.sprintf)(
|
|
100
103
|
// translators: %s: the name the user has given to the pattern.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_blocks","require","_blockEditor","_element","_components","_icons","_data","_coreData","_i18n","_notices","_store","_createPatternModal","_interopRequireDefault","_lockUnlock","_constants","PatternConvertButton","clientIds","rootClientId","createSuccessNotice","useDispatch","noticesStore","replaceBlocks","blockEditorStore","setEditingPattern","unlock","patternsStore","isModalOpen","setIsModalOpen","useState","canConvert","useSelect","select","_getBlocksByClientId","canUser","coreStore","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","rootId","length","undefined","blocks","isReusable","isReusableBlock","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","hasBlockSupport","name","getContent","useCallback","serialize","handleSuccess","pattern","wp_pattern_sync_status","PATTERN_SYNC_TYPES","unsynced","newBlock","createBlock","id","clientId","sprintf","__","title","raw","type","_react","createElement","Fragment","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
|
|
1
|
+
{"version":3,"names":["_blocks","require","_blockEditor","_element","_components","_icons","_data","_coreData","_i18n","_notices","_store","_createPatternModal","_interopRequireDefault","_lockUnlock","_constants","PatternConvertButton","clientIds","rootClientId","closeBlockSettingsMenu","createSuccessNotice","useDispatch","noticesStore","replaceBlocks","blockEditorStore","setEditingPattern","unlock","patternsStore","isModalOpen","setIsModalOpen","useState","canConvert","useSelect","select","_getBlocksByClientId","canUser","coreStore","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","rootId","length","undefined","blocks","isReusable","isReusableBlock","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","hasBlockSupport","name","getContent","useCallback","serialize","handleSuccess","pattern","wp_pattern_sync_status","PATTERN_SYNC_TYPES","unsynced","newBlock","createBlock","id","clientId","sprintf","__","title","raw","type","_react","createElement","Fragment","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!! canUser( 'create', 'blocks' );\n\n\t\t\treturn _canConvert;\n\t\t},\n\t\t[ clientIds, rootClientId ]\n\t);\n\tconst { getBlocksByClientId } = useSelect( blockEditorStore );\n\tconst getContent = useCallback(\n\t\t() => serialize( getBlocksByClientId( clientIds ) ),\n\t\t[ getBlocksByClientId, clientIds ]\n\t);\n\n\tif ( ! canConvert ) {\n\t\treturn null;\n\t}\n\n\tconst handleSuccess = ( { pattern } ) => {\n\t\tif ( pattern.wp_pattern_sync_status !== PATTERN_SYNC_TYPES.unsynced ) {\n\t\t\tconst newBlock = createBlock( 'core/block', {\n\t\t\t\tref: pattern.id,\n\t\t\t} );\n\n\t\t\treplaceBlocks( clientIds, newBlock );\n\t\t\tsetEditingPattern( newBlock.clientId, true );\n\t\t\tcloseBlockSettingsMenu();\n\t\t}\n\n\t\tcreateSuccessNotice(\n\t\t\tpattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Unsynced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Synced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t ),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'convert-to-pattern-success',\n\t\t\t}\n\t\t);\n\t\tsetIsModalOpen( false );\n\t};\n\treturn (\n\t\t<>\n\t\t\t<MenuItem\n\t\t\t\ticon={ symbol }\n\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\taria-expanded={ isModalOpen }\n\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t>\n\t\t\t\t{ __( 'Create pattern' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<CreatePatternModal\n\t\t\t\t\tcontent={ getContent }\n\t\t\t\t\tonSuccess={ ( pattern ) => {\n\t\t\t\t\t\thandleSuccess( pattern );\n\t\t\t\t\t} }\n\t\t\t\t\tonError={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AAMA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AACA,IAAAQ,QAAA,GAAAR,OAAA;AAIA,IAAAS,MAAA,GAAAT,OAAA;AACA,IAAAU,mBAAA,GAAAC,sBAAA,CAAAX,OAAA;AACA,IAAAY,WAAA,GAAAZ,OAAA;AACA,IAAAa,UAAA,GAAAb,OAAA;AAvBA;AACA;AACA;;AAeA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASc,oBAAoBA,CAAE;EAC7CC,SAAS;EACTC,YAAY;EACZC;AACD,CAAC,EAAG;EACH,MAAM;IAAEC;EAAoB,CAAC,GAAG,IAAAC,iBAAW,EAAEC,cAAa,CAAC;EAC3D,MAAM;IAAEC;EAAc,CAAC,GAAG,IAAAF,iBAAW,EAAEG,kBAAiB,CAAC;EACzD;EACA;EACA,MAAM;IAAEC;EAAkB,CAAC,GAAG,IAAAC,kBAAM,EAAE,IAAAL,iBAAW,EAAEM,YAAc,CAAE,CAAC;EACpE,MAAM,CAAEC,WAAW,EAAEC,cAAc,CAAE,GAAG,IAAAC,iBAAQ,EAAE,KAAM,CAAC;EACzD,M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ACxC,iBAAgBD,WAAa;IAC7B,iBAAc;EAAQ,GAEpB,IAAAwC,QAAE,EAAE,gBAAiB,CACd,CAAC,EACTxC,WAAW,IACZ,IAAA4C,MAAA,CAAAC,aAAA,EAAC7D,mBAAA,CAAAmE,OAAkB;IAClBC,OAAO,EAAGzB,UAAY;IACtB0B,SAAS,EAAKtB,OAAO,IAAM;MAC1BD,aAAa,CAAEC,OAAQ,CAAC;IACzB,CAAG;IACHuB,OAAO,EAAGA,CAAA,KAAM;MACfrD,cAAc,CAAE,KAAM,CAAC;IACxB,CAAG;IACHsD,OAAO,EAAGA,CAAA,KAAM;MACftD,cAAc,CAAE,KAAM,CAAC;IACxB;EAAG,CACH,CAED,CAAC;AAEL"}
|
|
@@ -28,7 +28,6 @@ function PatternsManageButton({
|
|
|
28
28
|
const {
|
|
29
29
|
canRemove,
|
|
30
30
|
isVisible,
|
|
31
|
-
innerBlockCount,
|
|
32
31
|
managePatternsUrl
|
|
33
32
|
} = (0, _data.useSelect)(select => {
|
|
34
33
|
const {
|
|
@@ -67,7 +66,7 @@ function PatternsManageButton({
|
|
|
67
66
|
}
|
|
68
67
|
return (0, _react.createElement)(_react.Fragment, null, canRemove && (0, _react.createElement)(_components.MenuItem, {
|
|
69
68
|
onClick: () => convertSyncedPatternToStatic(clientId)
|
|
70
|
-
},
|
|
69
|
+
}, (0, _i18n.__)('Detach')), (0, _react.createElement)(_components.MenuItem, {
|
|
71
70
|
href: managePatternsUrl
|
|
72
71
|
}, (0, _i18n.__)('Manage patterns')));
|
|
73
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_i18n","_blocks","_data","_blockEditor","_url","_coreData","_store","_lockUnlock","PatternsManageButton","clientId","canRemove","isVisible","
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_blocks","_data","_blockEditor","_url","_coreData","_store","_lockUnlock","PatternsManageButton","clientId","canRemove","isVisible","managePatternsUrl","useSelect","select","getBlock","canRemoveBlock","getBlockCount","getSettings","blockEditorStore","canUser","coreStore","reusableBlock","isBlockTheme","__unstableIsBlockBasedTheme","isReusableBlock","attributes","ref","innerBlockCount","addQueryArgs","path","post_type","convertSyncedPatternToStatic","unlock","useDispatch","patternsStore","_react","createElement","Fragment","MenuItem","onClick","__","href","_default","exports","default"],"sources":["@wordpress/patterns/src/components/patterns-manage-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nfunction PatternsManageButton( { clientId } ) {\n\tconst { canRemove, isVisible, managePatternsUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, canRemoveBlock, getBlockCount, 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":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,IAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,WAAA,GAAAR,OAAA;AAfA;AACA;AACA;;AASA;AACA;AACA;;AAIA,SAASS,oBAAoBA,CAAE;EAAEC;AAAS,CAAC,EAAG;EAC7C,MAAM;IAAEC,SAAS;IAAEC,SAAS;IAAEC;EAAkB,CAAC,GAAG,IAAAC,eAAS,EAC1DC,MAAM,IAAM;IACb,MAAM;MAAEC,QAAQ;MAAEC,cAAc;MAAE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AAC,aAAA,EAACvC,WAAA,CAAAyC,QAAQ;IAACG,IAAI,EAAG9B;EAAmB,GACjC,IAAA6B,QAAE,EAAE,iBAAkB,CACf,CACT,CAAC;AAEL;AAAC,IAAAE,QAAA,GAEcnC,oBAAoB;AAAAoC,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
|
@@ -122,6 +122,7 @@ function RenamePatternCategoryModal({
|
|
|
122
122
|
}, (0, _react.createElement)(_components.TextControl, {
|
|
123
123
|
ref: textControlRef,
|
|
124
124
|
__nextHasNoMarginBottom: true,
|
|
125
|
+
__next40pxDefaultSize: true,
|
|
125
126
|
label: (0, _i18n.__)('Name'),
|
|
126
127
|
value: name,
|
|
127
128
|
onChange: onChange,
|
|
@@ -133,9 +134,11 @@ function RenamePatternCategoryModal({
|
|
|
133
134
|
}, validationMessage)), (0, _react.createElement)(_components.__experimentalHStack, {
|
|
134
135
|
justify: "right"
|
|
135
136
|
}, (0, _react.createElement)(_components.Button, {
|
|
137
|
+
__next40pxDefaultSize: true,
|
|
136
138
|
variant: "tertiary",
|
|
137
139
|
onClick: onRequestClose
|
|
138
140
|
}, (0, _i18n.__)('Cancel')), (0, _react.createElement)(_components.Button, {
|
|
141
|
+
__next40pxDefaultSize: true,
|
|
139
142
|
variant: "primary",
|
|
140
143
|
type: "submit",
|
|
141
144
|
"aria-disabled": !name || name === category.name || isSaving,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_coreData","_data","_element","_htmlEntities","_i18n","_notices","_a11y","_categorySelector","RenamePatternCategoryModal","category","existingCategories","onClose","onError","onSuccess","props","id","useId","textControlRef","useRef","name","setName","useState","decodeEntities","isSaving","setIsSaving","validationMessage","setValidationMessage","validationMessageId","undefined","saveEntityRecord","invalidateResolution","useDispatch","coreStore","createErrorNotice","createSuccessNotice","noticesStore","onChange","newName","onSave","event","preventDefault","message","__","speak","current","focus","patternCategories","find","existingCategory","label","toLowerCase","savedRecord","CATEGORY_SLUG","slug","type","error","onRequestClose","_react","createElement","Modal","title","onSubmit","__experimentalVStack","spacing","TextControl","ref","__nextHasNoMarginBottom","value","required","className","__experimentalHStack","justify","Button","variant","onClick","isBusy"],"sources":["@wordpress/patterns/src/components/rename-pattern-category-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} from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDispatch } from '@wordpress/data';\nimport { useId, useRef, useState } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport { CATEGORY_SLUG } from './category-selector';\n\nexport default function RenamePatternCategoryModal( {\n\tcategory,\n\texistingCategories,\n\tonClose,\n\tonError,\n\tonSuccess,\n\t...props\n} ) {\n\tconst id = useId();\n\tconst textControlRef = useRef();\n\tconst [ name, setName ] = useState( decodeEntities( category.name ) );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\tconst [ validationMessage, setValidationMessage ] = useState( false );\n\tconst validationMessageId = validationMessage\n\t\t? `patterns-rename-pattern-category-modal__validation-message-${ id }`\n\t\t: undefined;\n\n\tconst { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tconst onChange = ( newName ) => {\n\t\tif ( validationMessage ) {\n\t\t\tsetValidationMessage( undefined );\n\t\t}\n\t\tsetName( newName );\n\t};\n\n\tconst onSave = async ( event ) => {\n\t\tevent.preventDefault();\n\n\t\tif ( isSaving ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! name || name === category.name ) {\n\t\t\tconst message = __( 'Please enter a new name for this category.' );\n\t\t\tspeak( message, 'assertive' );\n\t\t\tsetValidationMessage( message );\n\t\t\ttextControlRef.current?.focus();\n\t\t\treturn;\n\t\t}\n\n\t\t// Check existing categories to avoid creating duplicates.\n\t\tif (\n\t\t\texistingCategories.patternCategories.find( ( existingCategory ) => {\n\t\t\t\t// Compare the id so that the we don't disallow the user changing the case of their current category\n\t\t\t\t// (i.e. renaming 'test' to 'Test').\n\t\t\t\treturn (\n\t\t\t\t\texistingCategory.id !== category.id &&\n\t\t\t\t\texistingCategory.label.toLowerCase() === name.toLowerCase()\n\t\t\t\t);\n\t\t\t} )\n\t\t) {\n\t\t\tconst message = __(\n\t\t\t\t'This category already exists. Please use a different name.'\n\t\t\t);\n\t\t\tspeak( message, 'assertive' );\n\t\t\tsetValidationMessage( message );\n\t\t\ttextControlRef.current?.focus();\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSaving( true );\n\n\t\t\t// User pattern category properties may differ as they can be\n\t\t\t// normalized for use alongside template part areas, core pattern\n\t\t\t// categories etc. As a result we won't just destructure the passed\n\t\t\t// category object.\n\t\t\tconst savedRecord = await saveEntityRecord(\n\t\t\t\t'taxonomy',\n\t\t\t\tCATEGORY_SLUG,\n\t\t\t\t{\n\t\t\t\t\tid: category.id,\n\t\t\t\t\tslug: category.slug,\n\t\t\t\t\tname,\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tinvalidateResolution( 'getUserPatternCategories' );\n\t\t\tonSuccess?.( savedRecord );\n\t\t\tonClose();\n\n\t\t\tcreateSuccessNotice( __( 'Pattern category renamed.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-category-update',\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tonError?.();\n\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-category-update',\n\t\t\t} );\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t\tsetName( '' );\n\t\t}\n\t};\n\n\tconst onRequestClose = () => {\n\t\tonClose();\n\t\tsetName( '' );\n\t};\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Rename' ) }\n\t\t\tonRequestClose={ onRequestClose }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t<form onSubmit={ onSave }>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<VStack spacing=\"2\">\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\tref={ textControlRef }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\tvalue={ name }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\taria-describedby={ validationMessageId }\n\t\t\t\t\t\t\trequired\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ validationMessage && (\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tclassName=\"patterns-rename-pattern-category-modal__validation-message\"\n\t\t\t\t\t\t\t\tid={ validationMessageId }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ validationMessage }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</VStack>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button variant=\"tertiary\" onClick={ onRequestClose }>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\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={\n\t\t\t\t\t\t\t\t! name || name === category.name || isSaving\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tisBusy={ isSaving }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Save' ) }\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":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AA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EAAC,4DAA4D;IACtEtD,EAAE,EAAGY;EAAqB,GAExBF,iBACG,CAEA,CAAC,EACT,IAAAgC,MAAA,CAAAC,aAAA,EAAC5D,WAAA,CAAAwE,oBAAM;IAACC,OAAO,EAAC;EAAO,GACtB,IAAAd,MAAA,CAAAC,aAAA,EAAC5D,WAAA,CAAA0E,MAAM;IAACC,OAAO,EAAC,UAAU;IAACC,OAAO,EAAGlB;EAAgB,GAClD,IAAAd,QAAE,EAAE,QAAS,CACR,CAAC,EACT,IAAAe,MAAA,CAAAC,aAAA,EAAC5D,WAAA,CAAA0E,MAAM;IACNC,OAAO,EAAC,SAAS;IACjBnB,IAAI,EAAC,QAAQ;IACb,iBACC,CAAEnC,IAAI,IAAIA,IAAI,KAAKV,QAAQ,CAACU,IAAI,IAAII,QACpC;IACDoD,MAAM,EAAGpD;EAAU,GAEjB,IAAAmB,QAAE,EAAE,MAAO,CACN,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
1
|
+
{"version":3,"names":["_components","require","_coreData","_data","_element","_htmlEntities","_i18n","_notices","_a11y","_categorySelector","RenamePatternCategoryModal","category","existingCategories","onClose","onError","onSuccess","props","id","useId","textControlRef","useRef","name","setName","useState","decodeEntities","isSaving","setIsSaving","validationMessage","setValidationMessage","validationMessageId","undefined","saveEntityRecord","invalidateResolution","useDispatch","coreStore","createErrorNotice","createSuccessNotice","noticesStore","onChange","newName","onSave","event","preventDefault","message","__","speak","current","focus","patternCategories","find","existingCategory","label","toLowerCase","savedRecord","CATEGORY_SLUG","slug","type","error","onRequestClose","_react","createElement","Modal","title","onSubmit","__experimentalVStack","spacing","TextControl","ref","__nextHasNoMarginBottom","__next40pxDefaultSize","value","required","className","__experimentalHStack","justify","Button","variant","onClick","isBusy"],"sources":["@wordpress/patterns/src/components/rename-pattern-category-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} from '@wordpress/components';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDispatch } from '@wordpress/data';\nimport { useId, useRef, useState } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport { CATEGORY_SLUG } from './category-selector';\n\nexport default function RenamePatternCategoryModal( {\n\tcategory,\n\texistingCategories,\n\tonClose,\n\tonError,\n\tonSuccess,\n\t...props\n} ) {\n\tconst id = useId();\n\tconst textControlRef = useRef();\n\tconst [ name, setName ] = useState( decodeEntities( category.name ) );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\tconst [ validationMessage, setValidationMessage ] = useState( false );\n\tconst validationMessageId = validationMessage\n\t\t? `patterns-rename-pattern-category-modal__validation-message-${ id }`\n\t\t: undefined;\n\n\tconst { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tconst onChange = ( newName ) => {\n\t\tif ( validationMessage ) {\n\t\t\tsetValidationMessage( undefined );\n\t\t}\n\t\tsetName( newName );\n\t};\n\n\tconst onSave = async ( event ) => {\n\t\tevent.preventDefault();\n\n\t\tif ( isSaving ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! name || name === category.name ) {\n\t\t\tconst message = __( 'Please enter a new name for this category.' );\n\t\t\tspeak( message, 'assertive' );\n\t\t\tsetValidationMessage( message );\n\t\t\ttextControlRef.current?.focus();\n\t\t\treturn;\n\t\t}\n\n\t\t// Check existing categories to avoid creating duplicates.\n\t\tif (\n\t\t\texistingCategories.patternCategories.find( ( existingCategory ) => {\n\t\t\t\t// Compare the id so that the we don't disallow the user changing the case of their current category\n\t\t\t\t// (i.e. renaming 'test' to 'Test').\n\t\t\t\treturn (\n\t\t\t\t\texistingCategory.id !== category.id &&\n\t\t\t\t\texistingCategory.label.toLowerCase() === name.toLowerCase()\n\t\t\t\t);\n\t\t\t} )\n\t\t) {\n\t\t\tconst message = __(\n\t\t\t\t'This category already exists. Please use a different name.'\n\t\t\t);\n\t\t\tspeak( message, 'assertive' );\n\t\t\tsetValidationMessage( message );\n\t\t\ttextControlRef.current?.focus();\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSaving( true );\n\n\t\t\t// User pattern category properties may differ as they can be\n\t\t\t// normalized for use alongside template part areas, core pattern\n\t\t\t// categories etc. As a result we won't just destructure the passed\n\t\t\t// category object.\n\t\t\tconst savedRecord = await saveEntityRecord(\n\t\t\t\t'taxonomy',\n\t\t\t\tCATEGORY_SLUG,\n\t\t\t\t{\n\t\t\t\t\tid: category.id,\n\t\t\t\t\tslug: category.slug,\n\t\t\t\t\tname,\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tinvalidateResolution( 'getUserPatternCategories' );\n\t\t\tonSuccess?.( savedRecord );\n\t\t\tonClose();\n\n\t\t\tcreateSuccessNotice( __( 'Pattern category renamed.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-category-update',\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tonError?.();\n\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-category-update',\n\t\t\t} );\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t\tsetName( '' );\n\t\t}\n\t};\n\n\tconst onRequestClose = () => {\n\t\tonClose();\n\t\tsetName( '' );\n\t};\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Rename' ) }\n\t\t\tonRequestClose={ onRequestClose }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t<form onSubmit={ onSave }>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<VStack spacing=\"2\">\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\tref={ textControlRef }\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\tvalue={ name }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\taria-describedby={ validationMessageId }\n\t\t\t\t\t\t\trequired\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ validationMessage && (\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tclassName=\"patterns-rename-pattern-category-modal__validation-message\"\n\t\t\t\t\t\t\t\tid={ validationMessageId }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ validationMessage }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</VStack>\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={ onRequestClose }\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\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={\n\t\t\t\t\t\t\t\t! name || name === category.name || isSaving\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tisBusy={ isSaving }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Save' ) }\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":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAOA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,aA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AAC,aAAA,EAAC5D,WAAA,CAAAyE,oBAAM;IAACC,OAAO,EAAC;EAAO,GACtB,IAAAf,MAAA,CAAAC,aAAA,EAAC5D,WAAA,CAAA2E,MAAM;IACNN,qBAAqB;IACrBO,OAAO,EAAC,UAAU;IAClBC,OAAO,EAAGnB;EAAgB,GAExB,IAAAd,QAAE,EAAE,QAAS,CACR,CAAC,EACT,IAAAe,MAAA,CAAAC,aAAA,EAAC5D,WAAA,CAAA2E,MAAM;IACNN,qBAAqB;IACrBO,OAAO,EAAC,SAAS;IACjBpB,IAAI,EAAC,QAAQ;IACb,iBACC,CAAEnC,IAAI,IAAIA,IAAI,KAAKV,QAAQ,CAACU,IAAI,IAAII,QACpC;IACDqD,MAAM,EAAGrD;EAAU,GAEjB,IAAAmB,QAAE,EAAE,MAAO,CACN,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
@@ -80,6 +80,7 @@ function RenamePatternModal({
|
|
|
80
80
|
spacing: "5"
|
|
81
81
|
}, (0, _react.createElement)(_components.TextControl, {
|
|
82
82
|
__nextHasNoMarginBottom: true,
|
|
83
|
+
__next40pxDefaultSize: true,
|
|
83
84
|
label: (0, _i18n.__)('Name'),
|
|
84
85
|
value: name,
|
|
85
86
|
onChange: setName,
|
|
@@ -87,9 +88,11 @@ function RenamePatternModal({
|
|
|
87
88
|
}), (0, _react.createElement)(_components.__experimentalHStack, {
|
|
88
89
|
justify: "right"
|
|
89
90
|
}, (0, _react.createElement)(_components.Button, {
|
|
91
|
+
__next40pxDefaultSize: true,
|
|
90
92
|
variant: "tertiary",
|
|
91
93
|
onClick: onRequestClose
|
|
92
94
|
}, (0, _i18n.__)('Cancel')), (0, _react.createElement)(_components.Button, {
|
|
95
|
+
__next40pxDefaultSize: true,
|
|
93
96
|
variant: "primary",
|
|
94
97
|
type: "submit"
|
|
95
98
|
}, (0, _i18n.__)('Save'))))));
|