@wordpress/patterns 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/category-selector.js +16 -31
- package/build/components/category-selector.js.map +1 -1
- package/build/components/create-pattern-modal.js +59 -14
- package/build/components/create-pattern-modal.js.map +1 -1
- package/build/components/duplicate-pattern-modal.js +81 -0
- package/build/components/duplicate-pattern-modal.js.map +1 -0
- package/build/components/rename-pattern-category-modal.js +106 -0
- package/build/components/rename-pattern-category-modal.js.map +1 -0
- package/build/components/rename-pattern-modal.js +97 -0
- package/build/components/rename-pattern-modal.js.map +1 -0
- package/build/lock-unlock.js +1 -1
- package/build/lock-unlock.js.map +1 -1
- package/build/private-apis.js +6 -0
- package/build/private-apis.js.map +1 -1
- package/build-module/components/category-selector.js +17 -32
- package/build-module/components/category-selector.js.map +1 -1
- package/build-module/components/create-pattern-modal.js +61 -16
- package/build-module/components/create-pattern-modal.js.map +1 -1
- package/build-module/components/duplicate-pattern-modal.js +73 -0
- package/build-module/components/duplicate-pattern-modal.js.map +1 -0
- package/build-module/components/rename-pattern-category-modal.js +99 -0
- package/build-module/components/rename-pattern-category-modal.js.map +1 -0
- package/build-module/components/rename-pattern-modal.js +90 -0
- package/build-module/components/rename-pattern-modal.js.map +1 -0
- package/build-module/lock-unlock.js +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/private-apis.js +6 -0
- package/build-module/private-apis.js.map +1 -1
- package/build-style/style-rtl.css +22 -2
- package/build-style/style.css +22 -2
- package/package.json +16 -17
- package/src/components/category-selector.js +28 -42
- package/src/components/create-pattern-modal.js +63 -14
- package/src/components/duplicate-pattern-modal.js +93 -0
- package/src/components/rename-pattern-category-modal.js +121 -0
- package/src/components/rename-pattern-modal.js +115 -0
- package/src/components/style.scss +28 -2
- package/src/lock-unlock.js +1 -1
- package/src/private-apis.js +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -9,8 +9,6 @@ var _react = require("react");
|
|
|
9
9
|
var _i18n = require("@wordpress/i18n");
|
|
10
10
|
var _element = require("@wordpress/element");
|
|
11
11
|
var _components = require("@wordpress/components");
|
|
12
|
-
var _data = require("@wordpress/data");
|
|
13
|
-
var _coreData = require("@wordpress/core-data");
|
|
14
12
|
var _compose = require("@wordpress/compose");
|
|
15
13
|
var _htmlEntities = require("@wordpress/html-entities");
|
|
16
14
|
/**
|
|
@@ -20,37 +18,23 @@ var _htmlEntities = require("@wordpress/html-entities");
|
|
|
20
18
|
const unescapeString = arg => {
|
|
21
19
|
return (0, _htmlEntities.decodeEntities)(arg);
|
|
22
20
|
};
|
|
23
|
-
const EMPTY_ARRAY = [];
|
|
24
|
-
const MAX_TERMS_SUGGESTIONS = 20;
|
|
25
|
-
const DEFAULT_QUERY = {
|
|
26
|
-
per_page: MAX_TERMS_SUGGESTIONS,
|
|
27
|
-
_fields: 'id,name',
|
|
28
|
-
context: 'view'
|
|
29
|
-
};
|
|
30
21
|
const CATEGORY_SLUG = 'wp_pattern_category';
|
|
31
22
|
exports.CATEGORY_SLUG = CATEGORY_SLUG;
|
|
32
23
|
function CategorySelector({
|
|
33
|
-
|
|
34
|
-
onChange
|
|
24
|
+
categoryTerms,
|
|
25
|
+
onChange,
|
|
26
|
+
categoryMap
|
|
35
27
|
}) {
|
|
36
28
|
const [search, setSearch] = (0, _element.useState)('');
|
|
37
29
|
const debouncedSearch = (0, _compose.useDebounce)(setSearch, 500);
|
|
38
|
-
const {
|
|
39
|
-
searchResults
|
|
40
|
-
} = (0, _data.useSelect)(select => {
|
|
41
|
-
const {
|
|
42
|
-
getEntityRecords
|
|
43
|
-
} = select(_coreData.store);
|
|
44
|
-
return {
|
|
45
|
-
searchResults: !!search ? getEntityRecords('taxonomy', CATEGORY_SLUG, {
|
|
46
|
-
...DEFAULT_QUERY,
|
|
47
|
-
search
|
|
48
|
-
}) : EMPTY_ARRAY
|
|
49
|
-
};
|
|
50
|
-
}, [search]);
|
|
51
30
|
const suggestions = (0, _element.useMemo)(() => {
|
|
52
|
-
return (
|
|
53
|
-
|
|
31
|
+
return Array.from(categoryMap.values()).map(category => unescapeString(category.label)).filter(category => {
|
|
32
|
+
if (search !== '') {
|
|
33
|
+
return category.toLowerCase().includes(search.toLowerCase());
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}).sort((a, b) => a.localeCompare(b));
|
|
37
|
+
}, [search, categoryMap]);
|
|
54
38
|
function handleChange(termNames) {
|
|
55
39
|
const uniqueTerms = termNames.reduce((terms, newTerm) => {
|
|
56
40
|
if (!terms.some(term => term.toLowerCase() === newTerm.toLowerCase())) {
|
|
@@ -60,15 +44,16 @@ function CategorySelector({
|
|
|
60
44
|
}, []);
|
|
61
45
|
onChange(uniqueTerms);
|
|
62
46
|
}
|
|
63
|
-
return (0, _react.createElement)(
|
|
47
|
+
return (0, _react.createElement)(_components.FormTokenField, {
|
|
64
48
|
className: "patterns-menu-items__convert-modal-categories",
|
|
65
|
-
value:
|
|
49
|
+
value: categoryTerms,
|
|
66
50
|
suggestions: suggestions,
|
|
67
51
|
onChange: handleChange,
|
|
68
52
|
onInputChange: debouncedSearch,
|
|
69
|
-
maxSuggestions: MAX_TERMS_SUGGESTIONS,
|
|
70
53
|
label: (0, _i18n.__)('Categories'),
|
|
71
|
-
tokenizeOnBlur: true
|
|
72
|
-
|
|
54
|
+
tokenizeOnBlur: true,
|
|
55
|
+
__experimentalExpandOnFocus: true,
|
|
56
|
+
__next40pxDefaultSize: true
|
|
57
|
+
});
|
|
73
58
|
}
|
|
74
59
|
//# sourceMappingURL=category-selector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_element","_components","
|
|
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,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,GAAKC,GAAG,IAAM;EACjC,OAAO,IAAAC,4BAAc,EAAED,GAAI,CAAC;AAC7B,CAAC;AAEM,MAAME,aAAa,GAAG,qBAAqB;AAACC,OAAA,CAAAD,aAAA,GAAAA,aAAA;AAEpC,SAASE,gBAAgBA,CAAE;EACzCC,aAAa;EACbC,QAAQ;EACRC;AACD,CAAC,EAAG;EACH,MAAM,CAAEC,MAAM,EAAEC,SAAS,CAAE,GAAG,IAAAC,iBAAQ,EAAE,EAAG,CAAC;EAC5C,MAAMC,eAAe,GAAG,IAAAC,oBAAW,EAAEH,SAAS,EAAE,GAAI,CAAC;EAErD,MAAMI,WAAW,GAAG,IAAAC,gBAAO,EAAE,MAAM;IAClC,OAAOC,KAAK,CAACC,IAAI,CAAET,WAAW,CAACU,MAAM,CAAC,CAAE,CAAC,CACvCC,GAAG,CAAIC,QAAQ,IAAMpB,cAAc,CAAEoB,QAAQ,CAACC,KAAM,CAAE,CAAC,CACvDC,MAAM,CAAIF,QAAQ,IAAM;MACxB,IAAKX,MAAM,KAAK,EAAE,EAAG;QACpB,OAAOW,QAAQ,CACbG,WAAW,CAAC,CAAC,CACbC,QAAQ,CAAEf,MAAM,CAACc,WAAW,CAAC,CAAE,CAAC;MACnC;MACA,OAAO,IAAI;IACZ,CAAE,CAAC,CACFE,IAAI,CAAE,CAAEC,CAAC,EAAEC,CAAC,KAAMD,CAAC,CAACE,aAAa,CAAED,CAAE,CAAE,CAAC;EAC3C,CAAC,EAAE,CAAElB,MAAM,EAAED,WAAW,CAAG,CAAC;EAE5B,SAASqB,YAAYA,CAAEC,SAAS,EAAG;IAClC,MAAMC,WAAW,GAAGD,SAAS,CAACE,MAAM,CAAE,CAAEC,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,CACrB,CAAC;AAEJ"}
|
|
@@ -30,15 +30,20 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
function CreatePatternModal({
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
confirmLabel = (0, _i18n.__)('Create'),
|
|
34
|
+
defaultCategories = [],
|
|
35
|
+
className = 'patterns-menu-items__convert-modal',
|
|
35
36
|
content,
|
|
37
|
+
modalTitle = (0, _i18n.__)('Create pattern'),
|
|
36
38
|
onClose,
|
|
37
|
-
|
|
39
|
+
onError,
|
|
40
|
+
onSuccess,
|
|
41
|
+
defaultSyncType = _constants.PATTERN_SYNC_TYPES.full,
|
|
42
|
+
defaultTitle = ''
|
|
38
43
|
}) {
|
|
39
|
-
const [syncType, setSyncType] = (0, _element.useState)(
|
|
40
|
-
const [categoryTerms, setCategoryTerms] = (0, _element.useState)(
|
|
41
|
-
const [title, setTitle] = (0, _element.useState)(
|
|
44
|
+
const [syncType, setSyncType] = (0, _element.useState)(defaultSyncType);
|
|
45
|
+
const [categoryTerms, setCategoryTerms] = (0, _element.useState)(defaultCategories);
|
|
46
|
+
const [title, setTitle] = (0, _element.useState)(defaultTitle);
|
|
42
47
|
const [isSaving, setIsSaving] = (0, _element.useState)(false);
|
|
43
48
|
const {
|
|
44
49
|
createPattern
|
|
@@ -50,6 +55,38 @@ function CreatePatternModal({
|
|
|
50
55
|
const {
|
|
51
56
|
createErrorNotice
|
|
52
57
|
} = (0, _data.useDispatch)(_notices.store);
|
|
58
|
+
const {
|
|
59
|
+
corePatternCategories,
|
|
60
|
+
userPatternCategories
|
|
61
|
+
} = (0, _data.useSelect)(select => {
|
|
62
|
+
const {
|
|
63
|
+
getUserPatternCategories,
|
|
64
|
+
getBlockPatternCategories
|
|
65
|
+
} = select(_coreData.store);
|
|
66
|
+
return {
|
|
67
|
+
corePatternCategories: getBlockPatternCategories(),
|
|
68
|
+
userPatternCategories: getUserPatternCategories()
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
const categoryMap = (0, _element.useMemo)(() => {
|
|
72
|
+
// Merge the user and core pattern categories and remove any duplicates.
|
|
73
|
+
const uniqueCategories = new Map();
|
|
74
|
+
[...userPatternCategories, ...corePatternCategories].forEach(category => {
|
|
75
|
+
if (!uniqueCategories.has(category.label) &&
|
|
76
|
+
// There are two core categories with `Post` label so explicitly remove the one with
|
|
77
|
+
// the `query` slug to avoid any confusion.
|
|
78
|
+
category.name !== 'query') {
|
|
79
|
+
// We need to store the name separately as this is used as the slug in the
|
|
80
|
+
// taxonomy and may vary from the label.
|
|
81
|
+
uniqueCategories.set(category.label, {
|
|
82
|
+
label: category.label,
|
|
83
|
+
value: category.label,
|
|
84
|
+
name: category.name
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return uniqueCategories;
|
|
89
|
+
}, [userPatternCategories, corePatternCategories]);
|
|
53
90
|
async function onCreate(patternTitle, sync) {
|
|
54
91
|
if (!title || isSaving) {
|
|
55
92
|
return;
|
|
@@ -65,9 +102,9 @@ function CreatePatternModal({
|
|
|
65
102
|
} catch (error) {
|
|
66
103
|
createErrorNotice(error.message, {
|
|
67
104
|
type: 'snackbar',
|
|
68
|
-
id: '
|
|
105
|
+
id: 'pattern-create'
|
|
69
106
|
});
|
|
70
|
-
onError();
|
|
107
|
+
onError?.();
|
|
71
108
|
} finally {
|
|
72
109
|
setIsSaving(false);
|
|
73
110
|
setCategoryTerms([]);
|
|
@@ -81,9 +118,16 @@ function CreatePatternModal({
|
|
|
81
118
|
*/
|
|
82
119
|
async function findOrCreateTerm(term) {
|
|
83
120
|
try {
|
|
84
|
-
|
|
121
|
+
// We need to match any existing term to the correct slug to prevent duplicates, eg.
|
|
122
|
+
// the core `Headers` category uses the singular `header` as the slug.
|
|
123
|
+
const existingTerm = categoryMap.get(term);
|
|
124
|
+
const termData = existingTerm ? {
|
|
125
|
+
name: existingTerm.label,
|
|
126
|
+
slug: existingTerm.name
|
|
127
|
+
} : {
|
|
85
128
|
name: term
|
|
86
|
-
}
|
|
129
|
+
};
|
|
130
|
+
const newTerm = await saveEntityRecord('taxonomy', _categorySelector.CATEGORY_SLUG, termData, {
|
|
87
131
|
throwOnError: true
|
|
88
132
|
});
|
|
89
133
|
invalidateResolution('getUserPatternCategories');
|
|
@@ -96,7 +140,7 @@ function CreatePatternModal({
|
|
|
96
140
|
}
|
|
97
141
|
}
|
|
98
142
|
return (0, _react.createElement)(_components.Modal, {
|
|
99
|
-
title:
|
|
143
|
+
title: modalTitle,
|
|
100
144
|
onRequestClose: () => {
|
|
101
145
|
onClose();
|
|
102
146
|
setTitle('');
|
|
@@ -117,8 +161,9 @@ function CreatePatternModal({
|
|
|
117
161
|
placeholder: (0, _i18n.__)('My pattern'),
|
|
118
162
|
className: "patterns-create-modal__name-input"
|
|
119
163
|
}), (0, _react.createElement)(_categorySelector.default, {
|
|
120
|
-
|
|
121
|
-
onChange: setCategoryTerms
|
|
164
|
+
categoryTerms: categoryTerms,
|
|
165
|
+
onChange: setCategoryTerms,
|
|
166
|
+
categoryMap: categoryMap
|
|
122
167
|
}), (0, _react.createElement)(_components.ToggleControl, {
|
|
123
168
|
label: (0, _i18n.__)('Synced'),
|
|
124
169
|
help: (0, _i18n.__)('Editing the pattern will update it anywhere it is used.'),
|
|
@@ -139,6 +184,6 @@ function CreatePatternModal({
|
|
|
139
184
|
type: "submit",
|
|
140
185
|
"aria-disabled": !title || isSaving,
|
|
141
186
|
isBusy: isSaving
|
|
142
|
-
},
|
|
187
|
+
}, confirmLabel)))));
|
|
143
188
|
}
|
|
144
189
|
//# 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","onSuccess","onError","content","onClose","className","syncType","setSyncType","useState","PATTERN_SYNC_TYPES","full","categoryTerms","setCategoryTerms","title","setTitle","isSaving","setIsSaving","createPattern","unlock","useDispatch","patternsStore","saveEntityRecord","invalidateResolution","coreStore","createErrorNotice","noticesStore","onCreate","patternTitle","sync","categories","Promise","all","map","termName","findOrCreateTerm","newPattern","pattern","categoryId","PATTERN_DEFAULT_CATEGORY","error","message","type","id","term","newTerm","CATEGORY_SLUG","name","throwOnError","code","data","term_id","_react","createElement","Modal","__","onRequestClose","overlayClassName","onSubmit","event","preventDefault","__experimentalVStack","spacing","TextControl","__nextHasNoMarginBottom","label","value","onChange","placeholder","values","ToggleControl","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 { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } 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\tonSuccess,\n\tonError,\n\tcontent,\n\tonClose,\n\tclassName = 'patterns-menu-items__convert-modal',\n} ) {\n\tconst [ syncType, setSyncType ] = useState( PATTERN_SYNC_TYPES.full );\n\tconst [ categoryTerms, setCategoryTerms ] = useState( [] );\n\tconst [ title, setTitle ] = useState( '' );\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\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: 'convert-to-pattern-error',\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 newTerm = await saveEntityRecord(\n\t\t\t\t'taxonomy',\n\t\t\t\tCATEGORY_SLUG,\n\t\t\t\t{ name: term },\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={ __( 'Create pattern' ) }\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\tvalues={ categoryTerms }\n\t\t\t\t\t\tonChange={ setCategoryTerms }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Synced' ) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Editing the pattern will update it anywhere it is used.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ syncType === PATTERN_SYNC_TYPES.full }\n\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\tsyncType === PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t\t\t? PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t\t\t\t\t\t: PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\taria-disabled={ ! title || isSaving }\n\t\t\t\t\t\t\tisBusy={ isSaving }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t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AACC,OAAO,EAAC;EAAO,GACtB,IAAAvB,MAAA,CAAAC,aAAA,EAACtF,WAAA,CAAA6G,MAAM;IACNC,OAAO,EAAC,UAAU;IAClBC,OAAO,EAAGA,CAAA,KAAM;MACfzE,OAAO,CAAC,CAAC;MACTU,QAAQ,CAAE,EAAG,CAAC;IACf;EAAG,GAED,IAAAwC,QAAE,EAAE,QAAS,CACR,CAAC,EAET,IAAAH,MAAA,CAAAC,aAAA,EAACtF,WAAA,CAAA6G,MAAM;IACNC,OAAO,EAAC,SAAS;IACjBnC,IAAI,EAAC,QAAQ;IACb,iBAAgB,CAAE5B,KAAK,IAAIE,QAAU;IACrC+D,MAAM,EAAG/D;EAAU,GAEjB,IAAAuC,QAAE,EAAE,QAAS,CACR,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","__nextHasNoMarginBottom","onChange","placeholder","ToggleControl","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 { __ } from '@wordpress/i18n';\nimport { useState, useMemo } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_DEFAULT_CATEGORY, PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CategorySelector, { CATEGORY_SLUG } from './category-selector';\nimport { unlock } from '../lock-unlock';\n\nexport default function CreatePatternModal( {\n\tconfirmLabel = __( 'Create' ),\n\tdefaultCategories = [],\n\tclassName = 'patterns-menu-items__convert-modal',\n\tcontent,\n\tmodalTitle = __( 'Create pattern' ),\n\tonClose,\n\tonError,\n\tonSuccess,\n\tdefaultSyncType = PATTERN_SYNC_TYPES.full,\n\tdefaultTitle = '',\n} ) {\n\tconst [ syncType, setSyncType ] = useState( defaultSyncType );\n\tconst [ categoryTerms, setCategoryTerms ] = useState( defaultCategories );\n\tconst [ title, setTitle ] = useState( defaultTitle );\n\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\tconst { createPattern } = unlock( useDispatch( patternsStore ) );\n\tconst { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tconst { corePatternCategories, userPatternCategories } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getUserPatternCategories, getBlockPatternCategories } =\n\t\t\t\tselect( coreStore );\n\n\t\t\treturn {\n\t\t\t\tcorePatternCategories: getBlockPatternCategories(),\n\t\t\t\tuserPatternCategories: getUserPatternCategories(),\n\t\t\t};\n\t\t}\n\t);\n\n\tconst categoryMap = useMemo( () => {\n\t\t// Merge the user and core pattern categories and remove any duplicates.\n\t\tconst uniqueCategories = new Map();\n\t\t[ ...userPatternCategories, ...corePatternCategories ].forEach(\n\t\t\t( category ) => {\n\t\t\t\tif (\n\t\t\t\t\t! uniqueCategories.has( category.label ) &&\n\t\t\t\t\t// There are two core categories with `Post` label so explicitly remove the one with\n\t\t\t\t\t// the `query` slug to avoid any confusion.\n\t\t\t\t\tcategory.name !== 'query'\n\t\t\t\t) {\n\t\t\t\t\t// We need to store the name separately as this is used as the slug in the\n\t\t\t\t\t// taxonomy and may vary from the label.\n\t\t\t\t\tuniqueCategories.set( category.label, {\n\t\t\t\t\t\tlabel: category.label,\n\t\t\t\t\t\tvalue: category.label,\n\t\t\t\t\t\tname: category.name,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t\treturn uniqueCategories;\n\t}, [ userPatternCategories, corePatternCategories ] );\n\n\tasync function onCreate( patternTitle, sync ) {\n\t\tif ( ! title || isSaving ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSaving( true );\n\t\t\tconst categories = await Promise.all(\n\t\t\t\tcategoryTerms.map( ( termName ) =>\n\t\t\t\t\tfindOrCreateTerm( termName )\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tconst newPattern = await createPattern(\n\t\t\t\tpatternTitle,\n\t\t\t\tsync,\n\t\t\t\ttypeof content === 'function' ? content() : content,\n\t\t\t\tcategories\n\t\t\t);\n\t\t\tonSuccess( {\n\t\t\t\tpattern: newPattern,\n\t\t\t\tcategoryId: PATTERN_DEFAULT_CATEGORY,\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-create',\n\t\t\t} );\n\t\t\tonError?.();\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t\tsetCategoryTerms( [] );\n\t\t\tsetTitle( '' );\n\t\t}\n\t}\n\n\t/**\n\t * @param {string} term\n\t * @return {Promise<number>} The pattern category id.\n\t */\n\tasync function findOrCreateTerm( term ) {\n\t\ttry {\n\t\t\t// We need to match any existing term to the correct slug to prevent duplicates, eg.\n\t\t\t// the core `Headers` category uses the singular `header` as the slug.\n\t\t\tconst existingTerm = categoryMap.get( term );\n\t\t\tconst termData = existingTerm\n\t\t\t\t? { name: existingTerm.label, slug: existingTerm.name }\n\t\t\t\t: { name: term };\n\t\t\tconst newTerm = await saveEntityRecord(\n\t\t\t\t'taxonomy',\n\t\t\t\tCATEGORY_SLUG,\n\t\t\t\ttermData,\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tinvalidateResolution( 'getUserPatternCategories' );\n\t\t\treturn newTerm.id;\n\t\t} catch ( error ) {\n\t\t\tif ( error.code !== 'term_exists' ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn error.data.term_id;\n\t\t}\n\t}\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle }\n\t\t\tonRequestClose={ () => {\n\t\t\t\tonClose();\n\t\t\t\tsetTitle( '' );\n\t\t\t} }\n\t\t\toverlayClassName={ className }\n\t\t>\n\t\t\t<form\n\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tonCreate( title, syncType );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\tplaceholder={ __( 'My pattern' ) }\n\t\t\t\t\t\tclassName=\"patterns-create-modal__name-input\"\n\t\t\t\t\t/>\n\t\t\t\t\t<CategorySelector\n\t\t\t\t\t\tcategoryTerms={ categoryTerms }\n\t\t\t\t\t\tonChange={ setCategoryTerms }\n\t\t\t\t\t\tcategoryMap={ categoryMap }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Synced' ) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Editing the pattern will update it anywhere it is used.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ syncType === PATTERN_SYNC_TYPES.full }\n\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\tsyncType === PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t\t\t? PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t\t\t\t\t\t: PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\taria-disabled={ ! title || isSaving }\n\t\t\t\t\t\t\tisBusy={ isSaving }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ confirmLabel }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t</Modal>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAQA,IAAAC,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AAA8H,oBAAM;IAACC,OAAO,EAAC;EAAO,GACtB,IAAAnB,MAAA,CAAAC,aAAA,EAAC7G,WAAA,CAAAgI,MAAM;IACNC,OAAO,EAAC,UAAU;IAClBC,OAAO,EAAGA,CAAA,KAAM;MACfzF,OAAO,CAAC,CAAC;MACTa,QAAQ,CAAE,EAAG,CAAC;IACf;EAAG,GAED,IAAAlB,QAAE,EAAE,QAAS,CACR,CAAC,EAET,IAAAwE,MAAA,CAAAC,aAAA,EAAC7G,WAAA,CAAAgI,MAAM;IACNC,OAAO,EAAC,SAAS;IACjBjC,IAAI,EAAC,QAAQ;IACb,iBAAgB,CAAE3C,KAAK,IAAIE,QAAU;IACrC4E,MAAM,EAAG5E;EAAU,GAEjBpB,YACK,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = DuplicatePatternModal;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _coreData = require("@wordpress/core-data");
|
|
10
|
+
var _data = require("@wordpress/data");
|
|
11
|
+
var _i18n = require("@wordpress/i18n");
|
|
12
|
+
var _notices = require("@wordpress/notices");
|
|
13
|
+
var _createPatternModal = _interopRequireDefault(require("./create-pattern-modal"));
|
|
14
|
+
var _constants = require("../constants");
|
|
15
|
+
/**
|
|
16
|
+
* WordPress dependencies
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Internal dependencies
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
function getTermLabels(pattern, categories) {
|
|
24
|
+
// Theme patterns don't have an id and rely on core pattern categories.
|
|
25
|
+
if (!pattern.id) {
|
|
26
|
+
return categories.core?.filter(category => pattern.categories.includes(category.name)).map(category => category.label);
|
|
27
|
+
}
|
|
28
|
+
return categories.user?.filter(category => pattern.wp_pattern_category.includes(category.id)).map(category => category.label);
|
|
29
|
+
}
|
|
30
|
+
function DuplicatePatternModal({
|
|
31
|
+
pattern,
|
|
32
|
+
onClose,
|
|
33
|
+
onSuccess
|
|
34
|
+
}) {
|
|
35
|
+
const {
|
|
36
|
+
createSuccessNotice
|
|
37
|
+
} = (0, _data.useDispatch)(_notices.store);
|
|
38
|
+
const categories = (0, _data.useSelect)(select => {
|
|
39
|
+
const {
|
|
40
|
+
getUserPatternCategories,
|
|
41
|
+
getBlockPatternCategories
|
|
42
|
+
} = select(_coreData.store);
|
|
43
|
+
return {
|
|
44
|
+
core: getBlockPatternCategories(),
|
|
45
|
+
user: getUserPatternCategories()
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
if (!pattern) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const duplicatedProps = {
|
|
52
|
+
content: pattern.content,
|
|
53
|
+
defaultCategories: getTermLabels(pattern, categories),
|
|
54
|
+
defaultSyncType: !pattern.id // Theme patterns don't have an ID.
|
|
55
|
+
? _constants.PATTERN_SYNC_TYPES.unsynced : pattern.wp_pattern_sync_status || _constants.PATTERN_SYNC_TYPES.full,
|
|
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?.({
|
|
69
|
+
pattern: newPattern
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return (0, _react.createElement)(_createPatternModal.default, {
|
|
73
|
+
modalTitle: (0, _i18n.__)('Duplicate pattern'),
|
|
74
|
+
confirmLabel: (0, _i18n.__)('Duplicate'),
|
|
75
|
+
onClose: onClose,
|
|
76
|
+
onError: onClose,
|
|
77
|
+
onSuccess: handleOnSuccess,
|
|
78
|
+
...duplicatedProps
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=duplicate-pattern-modal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_coreData","require","_data","_i18n","_notices","_createPatternModal","_interopRequireDefault","_constants","getTermLabels","pattern","categories","id","core","filter","category","includes","name","map","label","user","wp_pattern_category","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","type","_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 } from '../constants';\n\nfunction getTermLabels( pattern, categories ) {\n\t// Theme patterns don't have an id and rely on core pattern categories.\n\tif ( ! pattern.id ) {\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: ! pattern.id // Theme patterns don't have an ID.\n\t\t\t? PATTERN_SYNC_TYPES.unsynced\n\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/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|
|
6
|
+
exports.default = RenamePatternCategoryModal;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _components = require("@wordpress/components");
|
|
9
|
+
var _coreData = require("@wordpress/core-data");
|
|
10
|
+
var _data = require("@wordpress/data");
|
|
11
|
+
var _element = require("@wordpress/element");
|
|
12
|
+
var _htmlEntities = require("@wordpress/html-entities");
|
|
13
|
+
var _i18n = require("@wordpress/i18n");
|
|
14
|
+
var _notices = require("@wordpress/notices");
|
|
15
|
+
var _categorySelector = require("./category-selector");
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal dependencies
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
function RenamePatternCategoryModal({
|
|
25
|
+
category,
|
|
26
|
+
onClose,
|
|
27
|
+
onError,
|
|
28
|
+
onSuccess,
|
|
29
|
+
...props
|
|
30
|
+
}) {
|
|
31
|
+
const [name, setName] = (0, _element.useState)((0, _htmlEntities.decodeEntities)(category.name));
|
|
32
|
+
const [isSaving, setIsSaving] = (0, _element.useState)(false);
|
|
33
|
+
const {
|
|
34
|
+
saveEntityRecord,
|
|
35
|
+
invalidateResolution
|
|
36
|
+
} = (0, _data.useDispatch)(_coreData.store);
|
|
37
|
+
const {
|
|
38
|
+
createErrorNotice,
|
|
39
|
+
createSuccessNotice
|
|
40
|
+
} = (0, _data.useDispatch)(_notices.store);
|
|
41
|
+
const onRename = async event => {
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
if (!name || name === category.name || isSaving) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
setIsSaving(true);
|
|
48
|
+
|
|
49
|
+
// User pattern category properties may differ as they can be
|
|
50
|
+
// normalized for use alongside template part areas, core pattern
|
|
51
|
+
// categories etc. As a result we won't just destructure the passed
|
|
52
|
+
// category object.
|
|
53
|
+
const savedRecord = await saveEntityRecord('taxonomy', _categorySelector.CATEGORY_SLUG, {
|
|
54
|
+
id: category.id,
|
|
55
|
+
slug: category.slug,
|
|
56
|
+
name
|
|
57
|
+
});
|
|
58
|
+
invalidateResolution('getUserPatternCategories');
|
|
59
|
+
onSuccess?.(savedRecord);
|
|
60
|
+
onClose();
|
|
61
|
+
createSuccessNotice((0, _i18n.__)('Pattern category renamed.'), {
|
|
62
|
+
type: 'snackbar',
|
|
63
|
+
id: 'pattern-category-update'
|
|
64
|
+
});
|
|
65
|
+
} catch (error) {
|
|
66
|
+
onError?.();
|
|
67
|
+
createErrorNotice(error.message, {
|
|
68
|
+
type: 'snackbar',
|
|
69
|
+
id: 'pattern-category-update'
|
|
70
|
+
});
|
|
71
|
+
} finally {
|
|
72
|
+
setIsSaving(false);
|
|
73
|
+
setName('');
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const onRequestClose = () => {
|
|
77
|
+
onClose();
|
|
78
|
+
setName('');
|
|
79
|
+
};
|
|
80
|
+
return (0, _react.createElement)(_components.Modal, {
|
|
81
|
+
title: (0, _i18n.__)('Rename'),
|
|
82
|
+
onRequestClose: onRequestClose,
|
|
83
|
+
...props
|
|
84
|
+
}, (0, _react.createElement)("form", {
|
|
85
|
+
onSubmit: onRename
|
|
86
|
+
}, (0, _react.createElement)(_components.__experimentalVStack, {
|
|
87
|
+
spacing: "5"
|
|
88
|
+
}, (0, _react.createElement)(_components.TextControl, {
|
|
89
|
+
__nextHasNoMarginBottom: true,
|
|
90
|
+
label: (0, _i18n.__)('Name'),
|
|
91
|
+
value: name,
|
|
92
|
+
onChange: setName,
|
|
93
|
+
required: true
|
|
94
|
+
}), (0, _react.createElement)(_components.__experimentalHStack, {
|
|
95
|
+
justify: "right"
|
|
96
|
+
}, (0, _react.createElement)(_components.Button, {
|
|
97
|
+
variant: "tertiary",
|
|
98
|
+
onClick: onRequestClose
|
|
99
|
+
}, (0, _i18n.__)('Cancel')), (0, _react.createElement)(_components.Button, {
|
|
100
|
+
variant: "primary",
|
|
101
|
+
type: "submit",
|
|
102
|
+
"aria-disabled": !name || name === category.name || isSaving,
|
|
103
|
+
isBusy: isSaving
|
|
104
|
+
}, (0, _i18n.__)('Save'))))));
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=rename-pattern-category-modal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_components","require","_coreData","_data","_element","_htmlEntities","_i18n","_notices","_categorySelector","RenamePatternCategoryModal","category","onClose","onError","onSuccess","props","name","setName","useState","decodeEntities","isSaving","setIsSaving","saveEntityRecord","invalidateResolution","useDispatch","coreStore","createErrorNotice","createSuccessNotice","noticesStore","onRename","event","preventDefault","savedRecord","CATEGORY_SLUG","id","slug","__","type","error","message","onRequestClose","_react","createElement","Modal","title","onSubmit","__experimentalVStack","spacing","TextControl","__nextHasNoMarginBottom","label","value","onChange","required","__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 { useState } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { CATEGORY_SLUG } from './category-selector';\n\nexport default function RenamePatternCategoryModal( {\n\tcategory,\n\tonClose,\n\tonError,\n\tonSuccess,\n\t...props\n} ) {\n\tconst [ name, setName ] = useState( decodeEntities( category.name ) );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\n\tconst { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );\n\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tconst onRename = async ( event ) => {\n\t\tevent.preventDefault();\n\n\t\tif ( ! name || name === category.name || isSaving ) {\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={ 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\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;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AAKA,IAAAO,iBAAA,GAAAP,OAAA;AApBA;AACA;AACA;;AAeA;AACA;AACA;;AAGe,SAASQ,0BAA0BA,CAAE;EACnDC,QAAQ;EACRC,OAAO;EACPC,OAAO;EACPC,SAAS;EACT,GAAGC;AACJ,CAAC,EAAG;EACH,MAAM,CAAEC,IAAI,EAAEC,OAAO,CAAE,GAAG,IAAAC,iBAAQ,EAAE,IAAAC,4BAAc,EAAER,QAAQ,CAACK,IAAK,CAAE,CAAC;EACrE,MAAM,CAAEI,QAAQ,EAAEC,WAAW,CAAE,GAAG,IAAAH,iBAAQ,EAAE,KAAM,CAAC;EAEnD,MAAM;IAAEI,gBAAgB;IAAEC;EAAqB,CAAC,GAAG,IAAAC,iBAAW,EAAEC,eAAU,CAAC;EAE3E,MAAM;IAAEC,iBAAiB;IAAEC;EAAoB,CAAC,GAC/C,IAAAH,iBAAW,EAAEI,cAAa,CAAC;EAE5B,MAAMC,QAAQ,GAAG,MAAQC,K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AAA,EAACzC,WAAA,CAAA6C,oBAAM;IAACC,OAAO,EAAC;EAAG,GAClB,IAAAN,MAAA,CAAAC,aAAA,EAACzC,WAAA,CAAA+C,WAAW;IACXC,uBAAuB;IACvBC,KAAK,EAAG,IAAAd,QAAE,EAAE,MAAO,CAAG;IACtBe,KAAK,EAAGnC,IAAM;IACdoC,QAAQ,EAAGnC,OAAS;IACpBoC,QAAQ;EAAA,CACR,CAAC,EACF,IAAAZ,MAAA,CAAAC,aAAA,EAACzC,WAAA,CAAAqD,oBAAM;IAACC,OAAO,EAAC;EAAO,GACtB,IAAAd,MAAA,CAAAC,aAAA,EAACzC,WAAA,CAAAuD,MAAM;IAACC,OAAO,EAAC,UAAU;IAACC,OAAO,EAAGlB;EAAgB,GAClD,IAAAJ,QAAE,EAAE,QAAS,CACR,CAAC,EACT,IAAAK,MAAA,CAAAC,aAAA,EAACzC,WAAA,CAAAuD,MAAM;IACNC,OAAO,EAAC,SAAS;IACjBpB,IAAI,EAAC,QAAQ;IACb,iBACC,CAAErB,IAAI,IAAIA,IAAI,KAAKL,QAAQ,CAACK,IAAI,IAAII,QACpC;IACDuC,MAAM,EAAGvC;EAAU,GAEjB,IAAAgB,QAAE,EAAE,MAAO,CACN,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = RenamePatternModal;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _components = require("@wordpress/components");
|
|
9
|
+
var _coreData = require("@wordpress/core-data");
|
|
10
|
+
var _data = require("@wordpress/data");
|
|
11
|
+
var _element = require("@wordpress/element");
|
|
12
|
+
var _htmlEntities = require("@wordpress/html-entities");
|
|
13
|
+
var _i18n = require("@wordpress/i18n");
|
|
14
|
+
var _notices = require("@wordpress/notices");
|
|
15
|
+
/**
|
|
16
|
+
* WordPress dependencies
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
function RenamePatternModal({
|
|
20
|
+
onClose,
|
|
21
|
+
onError,
|
|
22
|
+
onSuccess,
|
|
23
|
+
pattern,
|
|
24
|
+
...props
|
|
25
|
+
}) {
|
|
26
|
+
const originalName = (0, _htmlEntities.decodeEntities)(pattern.title);
|
|
27
|
+
const [name, setName] = (0, _element.useState)(originalName);
|
|
28
|
+
const [isSaving, setIsSaving] = (0, _element.useState)(false);
|
|
29
|
+
const {
|
|
30
|
+
editEntityRecord,
|
|
31
|
+
__experimentalSaveSpecifiedEntityEdits: saveSpecifiedEntityEdits
|
|
32
|
+
} = (0, _data.useDispatch)(_coreData.store);
|
|
33
|
+
const {
|
|
34
|
+
createSuccessNotice,
|
|
35
|
+
createErrorNotice
|
|
36
|
+
} = (0, _data.useDispatch)(_notices.store);
|
|
37
|
+
const onRename = async event => {
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
if (!name || name === pattern.title || isSaving) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
await editEntityRecord('postType', pattern.type, pattern.id, {
|
|
44
|
+
title: name
|
|
45
|
+
});
|
|
46
|
+
setIsSaving(true);
|
|
47
|
+
setName('');
|
|
48
|
+
onClose?.();
|
|
49
|
+
const savedRecord = await saveSpecifiedEntityEdits('postType', pattern.type, pattern.id, ['title'], {
|
|
50
|
+
throwOnError: true
|
|
51
|
+
});
|
|
52
|
+
onSuccess?.(savedRecord);
|
|
53
|
+
createSuccessNotice((0, _i18n.__)('Pattern renamed'), {
|
|
54
|
+
type: 'snackbar',
|
|
55
|
+
id: 'pattern-update'
|
|
56
|
+
});
|
|
57
|
+
} catch (error) {
|
|
58
|
+
onError?.();
|
|
59
|
+
const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : (0, _i18n.__)('An error occurred while renaming the pattern.');
|
|
60
|
+
createErrorNotice(errorMessage, {
|
|
61
|
+
type: 'snackbar',
|
|
62
|
+
id: 'pattern-update'
|
|
63
|
+
});
|
|
64
|
+
} finally {
|
|
65
|
+
setIsSaving(false);
|
|
66
|
+
setName('');
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const onRequestClose = () => {
|
|
70
|
+
onClose?.();
|
|
71
|
+
setName('');
|
|
72
|
+
};
|
|
73
|
+
return (0, _react.createElement)(_components.Modal, {
|
|
74
|
+
title: (0, _i18n.__)('Rename'),
|
|
75
|
+
...props,
|
|
76
|
+
onRequestClose: onClose
|
|
77
|
+
}, (0, _react.createElement)("form", {
|
|
78
|
+
onSubmit: onRename
|
|
79
|
+
}, (0, _react.createElement)(_components.__experimentalVStack, {
|
|
80
|
+
spacing: "5"
|
|
81
|
+
}, (0, _react.createElement)(_components.TextControl, {
|
|
82
|
+
__nextHasNoMarginBottom: true,
|
|
83
|
+
label: (0, _i18n.__)('Name'),
|
|
84
|
+
value: name,
|
|
85
|
+
onChange: setName,
|
|
86
|
+
required: true
|
|
87
|
+
}), (0, _react.createElement)(_components.__experimentalHStack, {
|
|
88
|
+
justify: "right"
|
|
89
|
+
}, (0, _react.createElement)(_components.Button, {
|
|
90
|
+
variant: "tertiary",
|
|
91
|
+
onClick: onRequestClose
|
|
92
|
+
}, (0, _i18n.__)('Cancel')), (0, _react.createElement)(_components.Button, {
|
|
93
|
+
variant: "primary",
|
|
94
|
+
type: "submit"
|
|
95
|
+
}, (0, _i18n.__)('Save'))))));
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=rename-pattern-modal.js.map
|
|
@@ -0,0 +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 variant=\"tertiary\" onClick={ onRequestClose }>\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 variant=\"primary\" type=\"submit\">\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,GAA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