@wordpress/patterns 1.8.0 → 1.9.1-next.79a6196f.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/LICENSE.md +1 -1
- package/build/components/create-pattern-modal.js +33 -20
- package/build/components/create-pattern-modal.js.map +1 -1
- package/build/components/duplicate-pattern-modal.js +29 -17
- package/build/components/duplicate-pattern-modal.js.map +1 -1
- package/build/components/partial-syncing-controls.js +101 -0
- package/build/components/partial-syncing-controls.js.map +1 -0
- 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 +10 -3
- package/build/private-apis.js.map +1 -1
- package/build-module/components/create-pattern-modal.js +32 -20
- package/build-module/components/create-pattern-modal.js.map +1 -1
- package/build-module/components/duplicate-pattern-modal.js +28 -17
- package/build-module/components/duplicate-pattern-modal.js.map +1 -1
- package/build-module/components/partial-syncing-controls.js +93 -0
- package/build-module/components/partial-syncing-controls.js.map +1 -0
- 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 +9 -4
- package/build-module/private-apis.js.map +1 -1
- package/package.json +17 -16
- package/src/components/create-pattern-modal.js +100 -89
- package/src/components/duplicate-pattern-modal.js +26 -24
- package/src/components/partial-syncing-controls.js +110 -0
- package/src/components/rename-pattern-category-modal.js +7 -1
- package/src/components/rename-pattern-modal.js +11 -2
- package/src/constants.js +10 -0
- package/src/private-apis.js +14 -2
package/CHANGELOG.md
CHANGED
package/LICENSE.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.CreatePatternModalContents = CreatePatternModalContents;
|
|
6
7
|
exports.default = CreatePatternModal;
|
|
7
8
|
var _react = require("react");
|
|
8
9
|
var _components = require("@wordpress/components");
|
|
@@ -30,11 +31,22 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
30
31
|
*/
|
|
31
32
|
|
|
32
33
|
function CreatePatternModal({
|
|
34
|
+
className = 'patterns-menu-items__convert-modal',
|
|
35
|
+
modalTitle = (0, _i18n.__)('Create pattern'),
|
|
36
|
+
...restProps
|
|
37
|
+
}) {
|
|
38
|
+
return (0, _react.createElement)(_components.Modal, {
|
|
39
|
+
title: modalTitle,
|
|
40
|
+
onRequestClose: restProps.onClose,
|
|
41
|
+
overlayClassName: className
|
|
42
|
+
}, (0, _react.createElement)(CreatePatternModalContents, {
|
|
43
|
+
...restProps
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
function CreatePatternModalContents({
|
|
33
47
|
confirmLabel = (0, _i18n.__)('Create'),
|
|
34
48
|
defaultCategories = [],
|
|
35
|
-
className = 'patterns-menu-items__convert-modal',
|
|
36
49
|
content,
|
|
37
|
-
modalTitle = (0, _i18n.__)('Create pattern'),
|
|
38
50
|
onClose,
|
|
39
51
|
onError,
|
|
40
52
|
onSuccess,
|
|
@@ -71,16 +83,20 @@ function CreatePatternModal({
|
|
|
71
83
|
const categoryMap = (0, _element.useMemo)(() => {
|
|
72
84
|
// Merge the user and core pattern categories and remove any duplicates.
|
|
73
85
|
const uniqueCategories = new Map();
|
|
74
|
-
|
|
75
|
-
|
|
86
|
+
userPatternCategories.forEach(category => {
|
|
87
|
+
uniqueCategories.set(category.label.toLowerCase(), {
|
|
88
|
+
label: category.label,
|
|
89
|
+
name: category.name,
|
|
90
|
+
id: category.id
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
corePatternCategories.forEach(category => {
|
|
94
|
+
if (!uniqueCategories.has(category.label.toLowerCase()) &&
|
|
76
95
|
// There are two core categories with `Post` label so explicitly remove the one with
|
|
77
96
|
// the `query` slug to avoid any confusion.
|
|
78
97
|
category.name !== 'query') {
|
|
79
|
-
|
|
80
|
-
// taxonomy and may vary from the label.
|
|
81
|
-
uniqueCategories.set(category.label, {
|
|
98
|
+
uniqueCategories.set(category.label.toLowerCase(), {
|
|
82
99
|
label: category.label,
|
|
83
|
-
value: category.label,
|
|
84
100
|
name: category.name
|
|
85
101
|
});
|
|
86
102
|
}
|
|
@@ -118,9 +134,13 @@ function CreatePatternModal({
|
|
|
118
134
|
*/
|
|
119
135
|
async function findOrCreateTerm(term) {
|
|
120
136
|
try {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
137
|
+
const existingTerm = categoryMap.get(term.toLowerCase());
|
|
138
|
+
if (existingTerm && existingTerm.id) {
|
|
139
|
+
return existingTerm.id;
|
|
140
|
+
}
|
|
141
|
+
// If we have an existing core category we need to match the new user category to the
|
|
142
|
+
// correct slug rather than autogenerating it to prevent duplicates, eg. the core `Headers`
|
|
143
|
+
// category uses the singular `header` as the slug.
|
|
124
144
|
const termData = existingTerm ? {
|
|
125
145
|
name: existingTerm.label,
|
|
126
146
|
slug: existingTerm.name
|
|
@@ -139,14 +159,7 @@ function CreatePatternModal({
|
|
|
139
159
|
return error.data.term_id;
|
|
140
160
|
}
|
|
141
161
|
}
|
|
142
|
-
return (0, _react.createElement)(
|
|
143
|
-
title: modalTitle,
|
|
144
|
-
onRequestClose: () => {
|
|
145
|
-
onClose();
|
|
146
|
-
setTitle('');
|
|
147
|
-
},
|
|
148
|
-
overlayClassName: className
|
|
149
|
-
}, (0, _react.createElement)("form", {
|
|
162
|
+
return (0, _react.createElement)("form", {
|
|
150
163
|
onSubmit: event => {
|
|
151
164
|
event.preventDefault();
|
|
152
165
|
onCreate(title, syncType);
|
|
@@ -187,6 +200,6 @@ function CreatePatternModal({
|
|
|
187
200
|
type: "submit",
|
|
188
201
|
"aria-disabled": !title || isSaving,
|
|
189
202
|
isBusy: isSaving
|
|
190
|
-
}, confirmLabel))))
|
|
203
|
+
}, confirmLabel))));
|
|
191
204
|
}
|
|
192
205
|
//# sourceMappingURL=create-pattern-modal.js.map
|
|
@@ -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","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__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":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAQA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GA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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"}
|
|
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","className","modalTitle","__","restProps","_react","createElement","Modal","title","onRequestClose","onClose","overlayClassName","CreatePatternModalContents","confirmLabel","defaultCategories","content","onError","onSuccess","defaultSyncType","PATTERN_SYNC_TYPES","full","defaultTitle","syncType","setSyncType","useState","categoryTerms","setCategoryTerms","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","toLowerCase","name","id","onCreate","patternTitle","sync","categories","Promise","all","map","termName","findOrCreateTerm","newPattern","pattern","categoryId","PATTERN_DEFAULT_CATEGORY","error","message","type","term","existingTerm","termData","slug","newTerm","CATEGORY_SLUG","throwOnError","code","data","term_id","onSubmit","event","preventDefault","__experimentalVStack","spacing","TextControl","value","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\tclassName = 'patterns-menu-items__convert-modal',\n\tmodalTitle = __( 'Create pattern' ),\n\t...restProps\n} ) {\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle }\n\t\t\tonRequestClose={ restProps.onClose }\n\t\t\toverlayClassName={ className }\n\t\t>\n\t\t\t<CreatePatternModalContents { ...restProps } />\n\t\t</Modal>\n\t);\n}\n\nexport function CreatePatternModalContents( {\n\tconfirmLabel = __( 'Create' ),\n\tdefaultCategories = [],\n\tcontent,\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\tuserPatternCategories.forEach( ( category ) => {\n\t\t\tuniqueCategories.set( category.label.toLowerCase(), {\n\t\t\t\tlabel: category.label,\n\t\t\t\tname: category.name,\n\t\t\t\tid: category.id,\n\t\t\t} );\n\t\t} );\n\n\t\tcorePatternCategories.forEach( ( category ) => {\n\t\t\tif (\n\t\t\t\t! uniqueCategories.has( category.label.toLowerCase() ) &&\n\t\t\t\t// There are two core categories with `Post` label so explicitly remove the one with\n\t\t\t\t// the `query` slug to avoid any confusion.\n\t\t\t\tcategory.name !== 'query'\n\t\t\t) {\n\t\t\t\tuniqueCategories.set( category.label.toLowerCase(), {\n\t\t\t\t\tlabel: category.label,\n\t\t\t\t\tname: category.name,\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\tconst existingTerm = categoryMap.get( term.toLowerCase() );\n\t\t\tif ( existingTerm && existingTerm.id ) {\n\t\t\t\treturn existingTerm.id;\n\t\t\t}\n\t\t\t// If we have an existing core category we need to match the new user category to the\n\t\t\t// correct slug rather than autogenerating it to prevent duplicates, eg. the core `Headers`\n\t\t\t// category uses the singular `header` as the slug.\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\treturn (\n\t\t<form\n\t\t\tonSubmit={ ( event ) => {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tonCreate( title, syncType );\n\t\t\t} }\n\t\t>\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<TextControl\n\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\tvalue={ title }\n\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\tplaceholder={ __( 'My pattern' ) }\n\t\t\t\t\tclassName=\"patterns-create-modal__name-input\"\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t/>\n\t\t\t\t<CategorySelector\n\t\t\t\t\tcategoryTerms={ categoryTerms }\n\t\t\t\t\tonChange={ setCategoryTerms }\n\t\t\t\t\tcategoryMap={ categoryMap }\n\t\t\t\t/>\n\t\t\t\t<ToggleControl\n\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t'Synced',\n\t\t\t\t\t\t'Option that makes an individual pattern synchronized'\n\t\t\t\t\t) }\n\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t'Sync this pattern across multiple locations.'\n\t\t\t\t\t) }\n\t\t\t\t\tchecked={ syncType === PATTERN_SYNC_TYPES.full }\n\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\tsyncType === PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t\t? PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t\t\t\t\t: PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t);\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\taria-disabled={ ! title || isSaving }\n\t\t\t\t\t\tisBusy={ isS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ty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = DuplicatePatternModal;
|
|
8
|
+
exports.useDuplicatePatternProps = useDuplicatePatternProps;
|
|
8
9
|
var _react = require("react");
|
|
9
10
|
var _coreData = require("@wordpress/core-data");
|
|
10
11
|
var _data = require("@wordpress/data");
|
|
@@ -27,9 +28,8 @@ function getTermLabels(pattern, categories) {
|
|
|
27
28
|
}
|
|
28
29
|
return categories.user?.filter(category => pattern.wp_pattern_category.includes(category.id)).map(category => category.label);
|
|
29
30
|
}
|
|
30
|
-
function
|
|
31
|
+
function useDuplicatePatternProps({
|
|
31
32
|
pattern,
|
|
32
|
-
onClose,
|
|
33
33
|
onSuccess
|
|
34
34
|
}) {
|
|
35
35
|
const {
|
|
@@ -48,33 +48,45 @@ function DuplicatePatternModal({
|
|
|
48
48
|
if (!pattern) {
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
return {
|
|
52
52
|
content: pattern.content,
|
|
53
53
|
defaultCategories: getTermLabels(pattern, categories),
|
|
54
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
|
-
(0, _i18n.__)('%s (Copy)'), typeof pattern.title === 'string' ? pattern.title : pattern.title.raw)
|
|
58
|
-
|
|
59
|
-
function handleOnSuccess({
|
|
60
|
-
pattern: newPattern
|
|
61
|
-
}) {
|
|
62
|
-
createSuccessNotice((0, _i18n.sprintf)(
|
|
63
|
-
// translators: %s: The new pattern's title e.g. 'Call to action (copy)'.
|
|
64
|
-
(0, _i18n.__)('"%s" duplicated.'), newPattern.title.raw), {
|
|
65
|
-
type: 'snackbar',
|
|
66
|
-
id: 'patterns-create'
|
|
67
|
-
});
|
|
68
|
-
onSuccess?.({
|
|
57
|
+
(0, _i18n.__)('%s (Copy)'), typeof pattern.title === 'string' ? pattern.title : pattern.title.raw),
|
|
58
|
+
onSuccess: ({
|
|
69
59
|
pattern: newPattern
|
|
70
|
-
})
|
|
60
|
+
}) => {
|
|
61
|
+
createSuccessNotice((0, _i18n.sprintf)(
|
|
62
|
+
// translators: %s: The new pattern's title e.g. 'Call to action (copy)'.
|
|
63
|
+
(0, _i18n.__)('"%s" duplicated.'), newPattern.title.raw), {
|
|
64
|
+
type: 'snackbar',
|
|
65
|
+
id: 'patterns-create'
|
|
66
|
+
});
|
|
67
|
+
onSuccess?.({
|
|
68
|
+
pattern: newPattern
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function DuplicatePatternModal({
|
|
74
|
+
pattern,
|
|
75
|
+
onClose,
|
|
76
|
+
onSuccess
|
|
77
|
+
}) {
|
|
78
|
+
const duplicatedProps = useDuplicatePatternProps({
|
|
79
|
+
pattern,
|
|
80
|
+
onSuccess
|
|
81
|
+
});
|
|
82
|
+
if (!pattern) {
|
|
83
|
+
return null;
|
|
71
84
|
}
|
|
72
85
|
return (0, _react.createElement)(_createPatternModal.default, {
|
|
73
86
|
modalTitle: (0, _i18n.__)('Duplicate pattern'),
|
|
74
87
|
confirmLabel: (0, _i18n.__)('Duplicate'),
|
|
75
88
|
onClose: onClose,
|
|
76
89
|
onError: onClose,
|
|
77
|
-
onSuccess: handleOnSuccess,
|
|
78
90
|
...duplicatedProps
|
|
79
91
|
});
|
|
80
92
|
}
|
|
@@ -1 +1 @@
|
|
|
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","
|
|
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","useDuplicatePatternProps","onSuccess","createSuccessNotice","useDispatch","noticesStore","useSelect","select","getUserPatternCategories","getBlockPatternCategories","coreStore","content","defaultCategories","defaultSyncType","PATTERN_SYNC_TYPES","unsynced","wp_pattern_sync_status","full","defaultTitle","sprintf","__","title","raw","newPattern","DuplicatePatternModal","onClose","duplicatedProps","_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 function useDuplicatePatternProps( { pattern, onSuccess } ) {\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst categories = useSelect( ( select ) => {\n\t\tconst { getUserPatternCategories, getBlockPatternCategories } =\n\t\t\tselect( coreStore );\n\n\t\treturn {\n\t\t\tcore: getBlockPatternCategories(),\n\t\t\tuser: getUserPatternCategories(),\n\t\t};\n\t} );\n\tif ( ! pattern ) {\n\t\treturn null;\n\t}\n\treturn {\n\t\tcontent: pattern.content,\n\t\tdefaultCategories: getTermLabels( pattern, categories ),\n\t\tdefaultSyncType:\n\t\t\tpattern.type !== PATTERN_TYPES.user // Theme patterns are unsynced by default.\n\t\t\t\t? PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t: pattern.wp_pattern_sync_status || PATTERN_SYNC_TYPES.full,\n\t\tdefaultTitle: sprintf(\n\t\t\t/* translators: %s: Existing pattern title */\n\t\t\t__( '%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\tonSuccess: ( { pattern: newPattern } ) => {\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: The new pattern's title e.g. 'Call to action (copy)'.\n\t\t\t\t\t__( '\"%s\" duplicated.' ),\n\t\t\t\t\tnewPattern.title.raw\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'patterns-create',\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tonSuccess?.( { pattern: newPattern } );\n\t\t},\n\t};\n}\n\nexport default function DuplicatePatternModal( {\n\tpattern,\n\tonClose,\n\tonSuccess,\n} ) {\n\tconst duplicatedProps = useDuplicatePatternProps( { pattern, onSuccess } );\n\tif ( ! pattern ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<CreatePatternModal\n\t\t\tmodalTitle={ __( 'Duplicate pattern' ) }\n\t\t\tconfirmLabel={ __( 'Duplicate' ) }\n\t\t\tonClose={ onClose }\n\t\t\tonError={ onClose }\n\t\t\t{ ...duplicatedProps }\n\t\t/>\n\t);\n}\n"],"mappings":";;;;;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAKA,IAAAI,mBAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AAZA;AACA;AACA;;AAM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O,CAAC6B,sBAAsB,IAAIF,6BAAkB,CAACG,IAAI;IAC7DC,YAAY,EAAE,IAAAC,aAAO,GACpB;IACA,IAAAC,QAAE,EAAE,WAAY,CAAC,EACjB,OAAOjC,OAAO,CAACkC,KAAK,KAAK,QAAQ,GAC9BlC,OAAO,CAACkC,KAAK,GACblC,OAAO,CAACkC,KAAK,CAACC,GAClB,CAAC;IACDpB,SAAS,EAAEA,CAAE;MAAEf,OAAO,EAAEoC;IAAW,CAAC,KAAM;MACzCpB,mBAAmB,CAClB,IAAAgB,aAAO;MACN;MACA,IAAAC,QAAE,EAAE,kBAAmB,CAAC,EACxBG,UAAU,CAACF,KAAK,CAACC,GAClB,CAAC,EACD;QACCjC,IAAI,EAAE,UAAU;QAChBW,EAAE,EAAE;MACL,CACD,CAAC;MAEDE,SAAS,GAAI;QAAEf,OAAO,EAAEoC;MAAW,CAAE,CAAC;IACvC;EACD,CAAC;AACF;AAEe,SAASC,qBAAqBA,CAAE;EAC9CrC,OAAO;EACPsC,OAAO;EACPvB;AACD,CAAC,EAAG;EACH,MAAMwB,eAAe,GAAGzB,wBAAwB,CAAE;IAAEd,OAAO;IAAEe;EAAU,CAAE,CAAC;EAC1E,IAAK,CAAEf,OAAO,EAAG;IAChB,OAAO,IAAI;EACZ;EACA,OACC,IAAAwC,MAAA,CAAAC,aAAA,EAAC7C,mBAAA,CAAA8C,OAAkB;IAClBC,UAAU,EAAG,IAAAV,QAAE,EAAE,mBAAoB,CAAG;IACxCW,YAAY,EAAG,IAAAX,QAAE,EAAE,WAAY,CAAG;IAClCK,OAAO,EAAGA,OAAS;IACnBO,OAAO,EAAGP,OAAS;IAAA,GACdC;EAAe,CACpB,CAAC;AAEJ"}
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
const attributeSources = Object.keys(syncedAttributes).map(attributeName => attributes.metadata?.bindings?.[attributeName]?.source?.name);
|
|
32
|
+
const isConnectedToOtherSources = attributeSources.every(source => source && source !== 'pattern_attributes');
|
|
33
|
+
|
|
34
|
+
// Render nothing if all supported attributes are connected to other sources.
|
|
35
|
+
if (isConnectedToOtherSources) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
function updateBindings(isChecked) {
|
|
39
|
+
let updatedBindings = {
|
|
40
|
+
...attributes?.metadata?.bindings
|
|
41
|
+
};
|
|
42
|
+
if (!isChecked) {
|
|
43
|
+
for (const attributeName of Object.keys(syncedAttributes)) {
|
|
44
|
+
if (updatedBindings[attributeName]?.source?.name === 'pattern_attributes') {
|
|
45
|
+
delete updatedBindings[attributeName];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (!Object.keys(updatedBindings).length) {
|
|
49
|
+
updatedBindings = undefined;
|
|
50
|
+
}
|
|
51
|
+
setAttributes({
|
|
52
|
+
metadata: {
|
|
53
|
+
...attributes.metadata,
|
|
54
|
+
bindings: updatedBindings
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
for (const attributeName of Object.keys(syncedAttributes)) {
|
|
60
|
+
if (!updatedBindings[attributeName]) {
|
|
61
|
+
updatedBindings[attributeName] = {
|
|
62
|
+
source: {
|
|
63
|
+
name: 'pattern_attributes'
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (typeof attributes.metadata?.id === 'string') {
|
|
69
|
+
setAttributes({
|
|
70
|
+
metadata: {
|
|
71
|
+
...attributes.metadata,
|
|
72
|
+
bindings: updatedBindings
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const id = (0, _nanoid.nanoid)(6);
|
|
78
|
+
setAttributes({
|
|
79
|
+
metadata: {
|
|
80
|
+
...attributes.metadata,
|
|
81
|
+
id,
|
|
82
|
+
bindings: updatedBindings
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return (0, _react.createElement)(_blockEditor.InspectorControls, {
|
|
87
|
+
group: "advanced"
|
|
88
|
+
}, (0, _react.createElement)(_components.BaseControl, {
|
|
89
|
+
__nextHasNoMarginBottom: true
|
|
90
|
+
}, (0, _react.createElement)(_components.BaseControl.VisualLabel, null, (0, _i18n.__)('Pattern overrides')), (0, _react.createElement)(_components.CheckboxControl, {
|
|
91
|
+
__nextHasNoMarginBottom: true,
|
|
92
|
+
label: (0, _i18n.__)('Allow instance overrides'),
|
|
93
|
+
checked: attributeSources.some(source => source === 'pattern_attributes'),
|
|
94
|
+
onChange: isChecked => {
|
|
95
|
+
updateBindings(isChecked);
|
|
96
|
+
}
|
|
97
|
+
})));
|
|
98
|
+
}
|
|
99
|
+
var _default = PartialSyncingControls;
|
|
100
|
+
exports.default = _default;
|
|
101
|
+
//# 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","attributeSources","Object","keys","map","attributeName","metadata","bindings","source","isConnectedToOtherSources","every","updateBindings","isChecked","updatedBindings","length","undefined","id","nanoid","_react","createElement","InspectorControls","group","BaseControl","__nextHasNoMarginBottom","VisualLabel","__","CheckboxControl","label","checked","some","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\tconst attributeSources = Object.keys( syncedAttributes ).map(\n\t\t( attributeName ) =>\n\t\t\tattributes.metadata?.bindings?.[ attributeName ]?.source?.name\n\t);\n\tconst isConnectedToOtherSources = attributeSources.every(\n\t\t( source ) => source && source !== 'pattern_attributes'\n\t);\n\n\t// Render nothing if all supported attributes are connected to other sources.\n\tif ( isConnectedToOtherSources ) {\n\t\treturn null;\n\t}\n\n\tfunction updateBindings( isChecked ) {\n\t\tlet updatedBindings = {\n\t\t\t...attributes?.metadata?.bindings,\n\t\t};\n\n\t\tif ( ! isChecked ) {\n\t\t\tfor ( const attributeName of Object.keys( syncedAttributes ) ) {\n\t\t\t\tif (\n\t\t\t\t\tupdatedBindings[ attributeName ]?.source?.name ===\n\t\t\t\t\t'pattern_attributes'\n\t\t\t\t) {\n\t\t\t\t\tdelete updatedBindings[ attributeName ];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( ! Object.keys( updatedBindings ).length ) {\n\t\t\t\tupdatedBindings = undefined;\n\t\t\t}\n\t\t\tsetAttributes( {\n\t\t\t\tmetadata: {\n\t\t\t\t\t...attributes.metadata,\n\t\t\t\t\tbindings: updatedBindings,\n\t\t\t\t},\n\t\t\t} );\n\t\t\treturn;\n\t\t}\n\n\t\tfor ( const attributeName of Object.keys( syncedAttributes ) ) {\n\t\t\tif ( ! updatedBindings[ attributeName ] ) {\n\t\t\t\tupdatedBindings[ attributeName ] = {\n\t\t\t\t\tsource: {\n\t\t\t\t\t\tname: 'pattern_attributes',\n\t\t\t\t\t},\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( {\n\t\t\t\tmetadata: {\n\t\t\t\t\t...attributes.metadata,\n\t\t\t\t\tbindings: updatedBindings,\n\t\t\t\t},\n\t\t\t} );\n\t\t\treturn;\n\t\t}\n\n\t\tconst id = nanoid( 6 );\n\t\tsetAttributes( {\n\t\t\tmetadata: {\n\t\t\t\t...attributes.metadata,\n\t\t\t\tid,\n\t\t\t\tbindings: updatedBindings,\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{ __( 'Pattern overrides' ) }\n\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t<CheckboxControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Allow instance overrides' ) }\n\t\t\t\t\tchecked={ attributeSources.some(\n\t\t\t\t\t\t( source ) => source === 'pattern_attributes'\n\t\t\t\t\t) }\n\t\t\t\t\tonChange={ ( isChecked ) => {\n\t\t\t\t\t\tupdateBindings( isChecked );\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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CAAEC,SAAU,CAAC;IAC5B;EAAG,CACH,CACW,CACK,CAAC;AAEtB;AAAC,IAAAmB,QAAA,GAEcpC,sBAAsB;AAAAqC,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;AAOA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;A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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,aAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,Q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O,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'))))));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_coreData","_data","_element","_htmlEntities","_i18n","_notices","RenamePatternModal","onClose","onError","onSuccess","pattern","props","originalName","decodeEntities","title","name","setName","useState","isSaving","setIsSaving","editEntityRecord","__experimentalSaveSpecifiedEntityEdits","saveSpecifiedEntityEdits","useDispatch","coreStore","createSuccessNotice","createErrorNotice","noticesStore","onRename","event","preventDefault","type","id","savedRecord","throwOnError","__","error","errorMessage","message","code","onRequestClose","_react","createElement","Modal","onSubmit","__experimentalVStack","spacing","TextControl","__nextHasNoMarginBottom","label","value","onChange","required","__experimentalHStack","justify","Button","variant","onClick"],"sources":["@wordpress/patterns/src/components/rename-pattern-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tModal,\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 { useState } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\nexport default function RenamePatternModal( {\n\tonClose,\n\tonError,\n\tonSuccess,\n\tpattern,\n\t...props\n} ) {\n\tconst originalName = decodeEntities( pattern.title );\n\tconst [ name, setName ] = useState( originalName );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\n\tconst {\n\t\teditEntityRecord,\n\t\t__experimentalSaveSpecifiedEntityEdits: saveSpecifiedEntityEdits,\n\t} = useDispatch( coreStore );\n\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tconst onRename = async ( event ) => {\n\t\tevent.preventDefault();\n\n\t\tif ( ! name || name === pattern.title || isSaving ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait editEntityRecord( 'postType', pattern.type, pattern.id, {\n\t\t\t\ttitle: name,\n\t\t\t} );\n\n\t\t\tsetIsSaving( true );\n\t\t\tsetName( '' );\n\t\t\tonClose?.();\n\n\t\t\tconst savedRecord = await saveSpecifiedEntityEdits(\n\t\t\t\t'postType',\n\t\t\t\tpattern.type,\n\t\t\t\tpattern.id,\n\t\t\t\t[ 'title' ],\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\tonSuccess?.( savedRecord );\n\n\t\t\tcreateSuccessNotice( __( 'Pattern renamed' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-update',\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tonError?.();\n\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while renaming the pattern.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-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 title={ __( 'Rename' ) } { ...props } onRequestClose={ onClose }>\n\t\t\t<form onSubmit={ onRename }>\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={ name }\n\t\t\t\t\t\tonChange={ setName }\n\t\t\t\t\t\trequired\n\t\t\t\t\t/>\n\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button
|
|
1
|
+
{"version":3,"names":["_components","require","_coreData","_data","_element","_htmlEntities","_i18n","_notices","RenamePatternModal","onClose","onError","onSuccess","pattern","props","originalName","decodeEntities","title","name","setName","useState","isSaving","setIsSaving","editEntityRecord","__experimentalSaveSpecifiedEntityEdits","saveSpecifiedEntityEdits","useDispatch","coreStore","createSuccessNotice","createErrorNotice","noticesStore","onRename","event","preventDefault","type","id","savedRecord","throwOnError","__","error","errorMessage","message","code","onRequestClose","_react","createElement","Modal","onSubmit","__experimentalVStack","spacing","TextControl","__nextHasNoMarginBottom","__next40pxDefaultSize","label","value","onChange","required","__experimentalHStack","justify","Button","variant","onClick"],"sources":["@wordpress/patterns/src/components/rename-pattern-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tModal,\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 { useState } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\nexport default function RenamePatternModal( {\n\tonClose,\n\tonError,\n\tonSuccess,\n\tpattern,\n\t...props\n} ) {\n\tconst originalName = decodeEntities( pattern.title );\n\tconst [ name, setName ] = useState( originalName );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\n\tconst {\n\t\teditEntityRecord,\n\t\t__experimentalSaveSpecifiedEntityEdits: saveSpecifiedEntityEdits,\n\t} = useDispatch( coreStore );\n\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tconst onRename = async ( event ) => {\n\t\tevent.preventDefault();\n\n\t\tif ( ! name || name === pattern.title || isSaving ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait editEntityRecord( 'postType', pattern.type, pattern.id, {\n\t\t\t\ttitle: name,\n\t\t\t} );\n\n\t\t\tsetIsSaving( true );\n\t\t\tsetName( '' );\n\t\t\tonClose?.();\n\n\t\t\tconst savedRecord = await saveSpecifiedEntityEdits(\n\t\t\t\t'postType',\n\t\t\t\tpattern.type,\n\t\t\t\tpattern.id,\n\t\t\t\t[ 'title' ],\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\tonSuccess?.( savedRecord );\n\n\t\t\tcreateSuccessNotice( __( 'Pattern renamed' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-update',\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tonError?.();\n\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while renaming the pattern.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-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 title={ __( 'Rename' ) } { ...props } onRequestClose={ onClose }>\n\t\t\t<form onSubmit={ onRename }>\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\t__next40pxDefaultSize\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ name }\n\t\t\t\t\t\tonChange={ setName }\n\t\t\t\t\t\trequired\n\t\t\t\t\t/>\n\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\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>\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,IA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,EAAE,MAAO,CAAG;IACtBgB,KAAK,EAAGpC,IAAM;IACdqC,QAAQ,EAAGpC,OAAS;IACpBqC,QAAQ;EAAA,CACR,CAAC,EAEF,IAAAZ,MAAA,CAAAC,aAAA,EAAC5C,WAAA,CAAAwD,oBAAM;IAACC,OAAO,EAAC;EAAO,GACtB,IAAAd,MAAA,CAAAC,aAAA,EAAC5C,WAAA,CAAA0D,MAAM;IACNP,qBAAqB;IACrBQ,OAAO,EAAC,UAAU;IAClBC,OAAO,EAAGlB;EAAgB,GAExB,IAAAL,QAAE,EAAE,QAAS,CACR,CAAC,EAET,IAAAM,MAAA,CAAAC,aAAA,EAAC5C,WAAA,CAAA0D,MAAM;IACNP,qBAAqB;IACrBQ,OAAO,EAAC,SAAS;IACjB1B,IAAI,EAAC;EAAQ,GAEX,IAAAI,QAAE,EAAE,MAAO,CACN,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
package/build/constants.js
CHANGED
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.PATTERN_USER_CATEGORY = exports.PATTERN_TYPES = exports.PATTERN_SYNC_TYPES = exports.PATTERN_DEFAULT_CATEGORY = exports.EXCLUDED_PATTERN_SOURCES = void 0;
|
|
6
|
+
exports.PATTERN_USER_CATEGORY = exports.PATTERN_TYPES = exports.PATTERN_SYNC_TYPES = exports.PATTERN_DEFAULT_CATEGORY = exports.PARTIAL_SYNCING_SUPPORTED_BLOCKS = exports.EXCLUDED_PATTERN_SOURCES = void 0;
|
|
7
|
+
var _i18n = require("@wordpress/i18n");
|
|
8
|
+
/**
|
|
9
|
+
* WordPress dependencies
|
|
10
|
+
*/
|
|
11
|
+
|
|
7
12
|
const PATTERN_TYPES = {
|
|
8
13
|
theme: 'pattern',
|
|
9
14
|
user: 'wp_block'
|
|
@@ -19,5 +24,13 @@ const PATTERN_SYNC_TYPES = {
|
|
|
19
24
|
full: 'fully',
|
|
20
25
|
unsynced: 'unsynced'
|
|
21
26
|
};
|
|
27
|
+
|
|
28
|
+
// TODO: This should not be hardcoded. Maybe there should be a config and/or an UI.
|
|
22
29
|
exports.PATTERN_SYNC_TYPES = PATTERN_SYNC_TYPES;
|
|
30
|
+
const PARTIAL_SYNCING_SUPPORTED_BLOCKS = {
|
|
31
|
+
'core/paragraph': {
|
|
32
|
+
content: (0, _i18n.__)('Content')
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.PARTIAL_SYNCING_SUPPORTED_BLOCKS = PARTIAL_SYNCING_SUPPORTED_BLOCKS;
|
|
23
36
|
//# sourceMappingURL=constants.js.map
|
package/build/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PATTERN_TYPES","theme","user","exports","PATTERN_DEFAULT_CATEGORY","PATTERN_USER_CATEGORY","EXCLUDED_PATTERN_SOURCES","PATTERN_SYNC_TYPES","full","unsynced"],"sources":["@wordpress/patterns/src/constants.js"],"sourcesContent":["
|
|
1
|
+
{"version":3,"names":["_i18n","require","PATTERN_TYPES","theme","user","exports","PATTERN_DEFAULT_CATEGORY","PATTERN_USER_CATEGORY","EXCLUDED_PATTERN_SOURCES","PATTERN_SYNC_TYPES","full","unsynced","PARTIAL_SYNCING_SUPPORTED_BLOCKS","content","__"],"sources":["@wordpress/patterns/src/constants.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\nexport 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\n// TODO: This should not be hardcoded. Maybe there should be a config and/or an UI.\nexport const PARTIAL_SYNCING_SUPPORTED_BLOCKS = {\n\t'core/paragraph': { content: __( 'Content' ) },\n};\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGO,MAAMC,aAAa,GAAG;EAC5BC,KAAK,EAAE,SAAS;EAChBC,IAAI,EAAE;AACP,CAAC;AAACC,OAAA,CAAAH,aAAA,GAAAA,aAAA;AAEK,MAAMI,wBAAwB,GAAG,cAAc;AAACD,OAAA,CAAAC,wBAAA,GAAAA,wBAAA;AAChD,MAAMC,qBAAqB,GAAG,aAAa;AAACF,OAAA,CAAAE,qBAAA,GAAAA,qBAAA;AAC5C,MAAMC,wBAAwB,GAAG,CACvC,MAAM,EACN,wBAAwB,EACxB,4BAA4B,CAC5B;AAACH,OAAA,CAAAG,wBAAA,GAAAA,wBAAA;AACK,MAAMC,kBAAkB,GAAG;EACjCC,IAAI,EAAE,OAAO;EACbC,QAAQ,EAAE;AACX,CAAC;;AAED;AAAAN,OAAA,CAAAI,kBAAA,GAAAA,kBAAA;AACO,MAAMG,gCAAgC,GAAG;EAC/C,gBAAgB,EAAE;IAAEC,OAAO,EAAE,IAAAC,QAAE,EAAE,SAAU;EAAE;AAC9C,CAAC;AAACT,OAAA,CAAAO,gCAAA,GAAAA,gCAAA"}
|