@wordpress/patterns 1.9.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/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 +39 -29
- package/build/components/partial-syncing-controls.js.map +1 -1
- package/build/private-apis.js +6 -2
- 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 +39 -29
- package/build-module/components/partial-syncing-controls.js.map +1 -1
- package/build-module/private-apis.js +4 -2
- package/build-module/private-apis.js.map +1 -1
- package/package.json +16 -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 +57 -45
- package/src/private-apis.js +10 -2
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,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AAKA,IAAAM,UAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,iBAAA,GAAAC,uBAAA,CAAAT,OAAA;AACA,IAAAU,WAAA,GAAAV,OAAA;AAAwC,SAAAW,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAH,wBAAAO,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAA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
|
+
{"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={ isSaving }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ confirmLabel }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t</form>\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,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AAKA,IAAAM,UAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,iBAAA,GAAAC,uBAAA,CAAAT,OAAA;AACA,IAAAU,WAAA,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AAQ,EAAGA,CAAA,KAAM;MAChBjE,WAAW,CACVD,QAAQ,KAAKH,6BAAkB,CAACC,IAAI,GACjCD,6BAAkB,CAAC6E,QAAQ,GAC3B7E,6BAAkB,CAACC,IACvB,CAAC;IACF;EAAG,CACH,CAAC,EACF,IAAAf,MAAA,CAAAC,aAAA,EAACxC,WAAA,CAAAmI,oBAAM;IAACC,OAAO,EAAC;EAAO,GACtB,IAAA7F,MAAA,CAAAC,aAAA,EAACxC,WAAA,CAAAqI,MAAM;IACNR,qBAAqB;IACrBS,OAAO,EAAC,UAAU;IAClBC,OAAO,EAAGA,CAAA,KAAM;MACf3F,OAAO,CAAC,CAAC;MACTiB,QAAQ,CAAE,EAAG,CAAC;IACf;EAAG,GAED,IAAAxB,QAAE,EAAE,QAAS,CACR,CAAC,EAET,IAAAE,MAAA,CAAAC,aAAA,EAACxC,WAAA,CAAAqI,MAAM;IACNR,qBAAqB;IACrBS,OAAO,EAAC,SAAS;IACjB9B,IAAI,EAAC,QAAQ;IACb,iBAAgB,CAAE9D,KAAK,IAAIoB,QAAU;IACrC0E,MAAM,EAAG1E;EAAU,GAEjBf,YACK,CACD,CACD,CACH,CAAC;AAET"}
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(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;;AAMA;AACA;AACA;;AAIA,SAASO,aAAaA,CAAEC,OAAO,EAAEC,UAAU,EAAG;EAC7C;EACA,IAAKD,OAAO,CAACE,IAAI,KAAKC,wBAAa,CAACC,IAAI,EAAG;IAC1C,OAAOH,UAAU,CAACI,IAAI,EACnBC,MAAM,CAAIC,QAAQ,IACnBP,OAAO,CAACC,UAAU,CAACO,QAAQ,CAAED,QAAQ,CAACE,IAAK,CAC5C,CAAC,CACAC,GAAG,CAAIH,QAAQ,IAAMA,QAAQ,CAACI,KAAM,CAAC;EACxC;EAEA,OAAOV,UAAU,CAACG,IAAI,EACnBE,MAAM,CAAIC,QAAQ,IACnBP,OAAO,CAACY,mBAAmB,CAACJ,QAAQ,CAAED,QAAQ,CAACM,EAAG,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AChBW,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"}
|
|
@@ -28,47 +28,58 @@ function PartialSyncingControls({
|
|
|
28
28
|
setAttributes
|
|
29
29
|
}) {
|
|
30
30
|
const syncedAttributes = _constants.PARTIAL_SYNCING_SUPPORTED_BLOCKS[name];
|
|
31
|
-
|
|
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
|
+
};
|
|
32
42
|
if (!isChecked) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
...attributes.connections?.attributes,
|
|
37
|
-
[attributeName]: undefined
|
|
43
|
+
for (const attributeName of Object.keys(syncedAttributes)) {
|
|
44
|
+
if (updatedBindings[attributeName]?.source?.name === 'pattern_attributes') {
|
|
45
|
+
delete updatedBindings[attributeName];
|
|
38
46
|
}
|
|
39
|
-
};
|
|
40
|
-
if (Object.keys(updatedConnections.attributes).length === 1) {
|
|
41
|
-
updatedConnections.attributes = undefined;
|
|
42
47
|
}
|
|
43
|
-
if (Object.keys(
|
|
44
|
-
|
|
48
|
+
if (!Object.keys(updatedBindings).length) {
|
|
49
|
+
updatedBindings = undefined;
|
|
45
50
|
}
|
|
46
51
|
setAttributes({
|
|
47
|
-
|
|
52
|
+
metadata: {
|
|
53
|
+
...attributes.metadata,
|
|
54
|
+
bindings: updatedBindings
|
|
55
|
+
}
|
|
48
56
|
});
|
|
49
57
|
return;
|
|
50
58
|
}
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
59
|
+
for (const attributeName of Object.keys(syncedAttributes)) {
|
|
60
|
+
if (!updatedBindings[attributeName]) {
|
|
61
|
+
updatedBindings[attributeName] = {
|
|
62
|
+
source: {
|
|
63
|
+
name: 'pattern_attributes'
|
|
64
|
+
}
|
|
65
|
+
};
|
|
58
66
|
}
|
|
59
|
-
}
|
|
67
|
+
}
|
|
60
68
|
if (typeof attributes.metadata?.id === 'string') {
|
|
61
69
|
setAttributes({
|
|
62
|
-
|
|
70
|
+
metadata: {
|
|
71
|
+
...attributes.metadata,
|
|
72
|
+
bindings: updatedBindings
|
|
73
|
+
}
|
|
63
74
|
});
|
|
64
75
|
return;
|
|
65
76
|
}
|
|
66
77
|
const id = (0, _nanoid.nanoid)(6);
|
|
67
78
|
setAttributes({
|
|
68
|
-
connections: updatedConnections,
|
|
69
79
|
metadata: {
|
|
70
80
|
...attributes.metadata,
|
|
71
|
-
id
|
|
81
|
+
id,
|
|
82
|
+
bindings: updatedBindings
|
|
72
83
|
}
|
|
73
84
|
});
|
|
74
85
|
}
|
|
@@ -76,15 +87,14 @@ function PartialSyncingControls({
|
|
|
76
87
|
group: "advanced"
|
|
77
88
|
}, (0, _react.createElement)(_components.BaseControl, {
|
|
78
89
|
__nextHasNoMarginBottom: true
|
|
79
|
-
}, (0, _react.createElement)(_components.BaseControl.VisualLabel, null, (0, _i18n.__)('
|
|
80
|
-
key: attributeName,
|
|
90
|
+
}, (0, _react.createElement)(_components.BaseControl.VisualLabel, null, (0, _i18n.__)('Pattern overrides')), (0, _react.createElement)(_components.CheckboxControl, {
|
|
81
91
|
__nextHasNoMarginBottom: true,
|
|
82
|
-
label:
|
|
83
|
-
checked:
|
|
92
|
+
label: (0, _i18n.__)('Allow instance overrides'),
|
|
93
|
+
checked: attributeSources.some(source => source === 'pattern_attributes'),
|
|
84
94
|
onChange: isChecked => {
|
|
85
|
-
|
|
95
|
+
updateBindings(isChecked);
|
|
86
96
|
}
|
|
87
|
-
})))
|
|
97
|
+
})));
|
|
88
98
|
}
|
|
89
99
|
var _default = PartialSyncingControls;
|
|
90
100
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_nanoid","require","_blockEditor","_components","_i18n","_constants","PartialSyncingControls","name","attributes","setAttributes","syncedAttributes","PARTIAL_SYNCING_SUPPORTED_BLOCKS","
|
|
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,GAAAC,OAAA;AAKA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,UAAA,GAAAJ,OAAA;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;;AAGA,SAASK,sBAAsBA,CAAE;EAAEC,IAAI;EAAEC,UAAU;EAAEC;AAAc,CAAC,EAAG;EACtE,MAAMC,gBAAgB,GAAGC,2CAAgC,CAAEJ,IAAI,CAAE;EACjE,MAAMK,gBAAgB,GAAGC,MAAM,CAACC,IAAI,CAAEJ,gBAAiB,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,GAAGT,UAAU,CAACS,QAAQ;UACtBC,QAAQ,EAAEM;QACX;MACD,CAAE,CAAC;MACH;IACD;IAEA,MAAMG,EAAE,GAAG,IAAAC,cAAM,EAAE,CAAE,CAAC;IACtBnB,aAAa,CAAE;MACdQ,QAAQ,EAAE;QACT,GAAGT,UAAU,CAACS,QAAQ;QACtBU,EAAE;QACFT,QAAQ,EAAEM;MACX;IACD,CAAE,CAAC;EACJ;EAEA,OACC,IAAAK,MAAA,CAAAC,aAAA,EAAC5B,YAAA,CAAA6B,iBAAiB;IAACC,KAAK,EAAC;EAAU,GAClC,IAAAH,MAAA,CAAAC,aAAA,EAAC3B,WAAA,CAAA8B,WAAW;IAACC,uBAAuB;EAAA,GACnC,IAAAL,MAAA,CAAAC,aAAA,EAAC3B,WAAA,CAAA8B,WAAW,CAACE,WAAW,QACrB,IAAAC,QAAE,EAAE,mBAAoB,CACF,CAAC,EAC1B,IAAAP,MAAA,CAAAC,aAAA,EAAC3B,WAAA,CAAAkC,eAAe;IACfH,uBAAuB;IACvBI,KAAK,EAAG,IAAAF,QAAE,EAAE,0BAA2B,CAAG;IAC1CG,OAAO,EAAG3B,gBAAgB,CAAC4B,IAAI,CAC5BrB,MAAM,IAAMA,MAAM,KAAK,oBAC1B,CAAG;IACHsB,QAAQ,EAAKlB,SAAS,IAAM;MAC3BD,cAAc,CAAEC,SAAU,CAAC;IAC5B;EAAG,CACH,CACW,CACK,CAAC;AAEtB;AAAC,IAAAmB,QAAA,GAEcpC,sBAAsB;AAAAqC,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
package/build/private-apis.js
CHANGED
|
@@ -6,13 +6,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.privateApis = void 0;
|
|
8
8
|
var _lockUnlock = require("./lock-unlock");
|
|
9
|
-
var _createPatternModal =
|
|
10
|
-
var _duplicatePatternModal =
|
|
9
|
+
var _createPatternModal = _interopRequireWildcard(require("./components/create-pattern-modal"));
|
|
10
|
+
var _duplicatePatternModal = _interopRequireWildcard(require("./components/duplicate-pattern-modal"));
|
|
11
11
|
var _renamePatternModal = _interopRequireDefault(require("./components/rename-pattern-modal"));
|
|
12
12
|
var _components = _interopRequireDefault(require("./components"));
|
|
13
13
|
var _renamePatternCategoryModal = _interopRequireDefault(require("./components/rename-pattern-category-modal"));
|
|
14
14
|
var _partialSyncingControls = _interopRequireDefault(require("./components/partial-syncing-controls"));
|
|
15
15
|
var _constants = require("./constants");
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
16
18
|
/**
|
|
17
19
|
* Internal dependencies
|
|
18
20
|
*/
|
|
@@ -21,7 +23,9 @@ const privateApis = {};
|
|
|
21
23
|
exports.privateApis = privateApis;
|
|
22
24
|
(0, _lockUnlock.lock)(privateApis, {
|
|
23
25
|
CreatePatternModal: _createPatternModal.default,
|
|
26
|
+
CreatePatternModalContents: _createPatternModal.CreatePatternModalContents,
|
|
24
27
|
DuplicatePatternModal: _duplicatePatternModal.default,
|
|
28
|
+
useDuplicatePatternProps: _duplicatePatternModal.useDuplicatePatternProps,
|
|
25
29
|
RenamePatternModal: _renamePatternModal.default,
|
|
26
30
|
PatternsMenuItems: _components.default,
|
|
27
31
|
RenamePatternCategoryModal: _renamePatternCategoryModal.default,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_lockUnlock","require","_createPatternModal","
|
|
1
|
+
{"version":3,"names":["_lockUnlock","require","_createPatternModal","_interopRequireWildcard","_duplicatePatternModal","_renamePatternModal","_interopRequireDefault","_components","_renamePatternCategoryModal","_partialSyncingControls","_constants","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","privateApis","exports","lock","CreatePatternModal","CreatePatternModalContents","DuplicatePatternModal","useDuplicatePatternProps","RenamePatternModal","PatternsMenuItems","RenamePatternCategoryModal","PartialSyncingControls","PATTERN_TYPES","PATTERN_DEFAULT_CATEGORY","PATTERN_USER_CATEGORY","EXCLUDED_PATTERN_SOURCES","PATTERN_SYNC_TYPES","PARTIAL_SYNCING_SUPPORTED_BLOCKS"],"sources":["@wordpress/patterns/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { lock } from './lock-unlock';\nimport {\n\tdefault as CreatePatternModal,\n\tCreatePatternModalContents,\n} from './components/create-pattern-modal';\nimport {\n\tdefault as DuplicatePatternModal,\n\tuseDuplicatePatternProps,\n} from './components/duplicate-pattern-modal';\nimport RenamePatternModal from './components/rename-pattern-modal';\nimport PatternsMenuItems from './components';\nimport RenamePatternCategoryModal from './components/rename-pattern-category-modal';\nimport PartialSyncingControls from './components/partial-syncing-controls';\nimport {\n\tPATTERN_TYPES,\n\tPATTERN_DEFAULT_CATEGORY,\n\tPATTERN_USER_CATEGORY,\n\tEXCLUDED_PATTERN_SOURCES,\n\tPATTERN_SYNC_TYPES,\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n} from './constants';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tCreatePatternModal,\n\tCreatePatternModalContents,\n\tDuplicatePatternModal,\n\tuseDuplicatePatternProps,\n\tRenamePatternModal,\n\tPatternsMenuItems,\n\tRenamePatternCategoryModal,\n\tPartialSyncingControls,\n\tPATTERN_TYPES,\n\tPATTERN_DEFAULT_CATEGORY,\n\tPATTERN_USER_CATEGORY,\n\tEXCLUDED_PATTERN_SOURCES,\n\tPATTERN_SYNC_TYPES,\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n} );\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAC,uBAAA,CAAAF,OAAA;AAIA,IAAAG,sBAAA,GAAAD,uBAAA,CAAAF,OAAA;AAIA,IAAAI,mBAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,WAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,2BAAA,GAAAF,sBAAA,CAAAL,OAAA;AACA,IAAAQ,uBAAA,GAAAH,sBAAA,CAAAL,OAAA;AACA,IAAAS,UAAA,GAAAT,OAAA;AAOqB,SAAAU,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAT,wBAAAa,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA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ternsStore } from '../store';
|
|
|
21
21
|
import CategorySelector, { CATEGORY_SLUG } from './category-selector';
|
|
22
22
|
import { unlock } from '../lock-unlock';
|
|
23
23
|
export default function CreatePatternModal({
|
|
24
|
+
className = 'patterns-menu-items__convert-modal',
|
|
25
|
+
modalTitle = __('Create pattern'),
|
|
26
|
+
...restProps
|
|
27
|
+
}) {
|
|
28
|
+
return createElement(Modal, {
|
|
29
|
+
title: modalTitle,
|
|
30
|
+
onRequestClose: restProps.onClose,
|
|
31
|
+
overlayClassName: className
|
|
32
|
+
}, createElement(CreatePatternModalContents, {
|
|
33
|
+
...restProps
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
export function CreatePatternModalContents({
|
|
24
37
|
confirmLabel = __('Create'),
|
|
25
38
|
defaultCategories = [],
|
|
26
|
-
className = 'patterns-menu-items__convert-modal',
|
|
27
39
|
content,
|
|
28
|
-
modalTitle = __('Create pattern'),
|
|
29
40
|
onClose,
|
|
30
41
|
onError,
|
|
31
42
|
onSuccess,
|
|
@@ -62,16 +73,20 @@ export default function CreatePatternModal({
|
|
|
62
73
|
const categoryMap = useMemo(() => {
|
|
63
74
|
// Merge the user and core pattern categories and remove any duplicates.
|
|
64
75
|
const uniqueCategories = new Map();
|
|
65
|
-
|
|
66
|
-
|
|
76
|
+
userPatternCategories.forEach(category => {
|
|
77
|
+
uniqueCategories.set(category.label.toLowerCase(), {
|
|
78
|
+
label: category.label,
|
|
79
|
+
name: category.name,
|
|
80
|
+
id: category.id
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
corePatternCategories.forEach(category => {
|
|
84
|
+
if (!uniqueCategories.has(category.label.toLowerCase()) &&
|
|
67
85
|
// There are two core categories with `Post` label so explicitly remove the one with
|
|
68
86
|
// the `query` slug to avoid any confusion.
|
|
69
87
|
category.name !== 'query') {
|
|
70
|
-
|
|
71
|
-
// taxonomy and may vary from the label.
|
|
72
|
-
uniqueCategories.set(category.label, {
|
|
88
|
+
uniqueCategories.set(category.label.toLowerCase(), {
|
|
73
89
|
label: category.label,
|
|
74
|
-
value: category.label,
|
|
75
90
|
name: category.name
|
|
76
91
|
});
|
|
77
92
|
}
|
|
@@ -109,9 +124,13 @@ export default function CreatePatternModal({
|
|
|
109
124
|
*/
|
|
110
125
|
async function findOrCreateTerm(term) {
|
|
111
126
|
try {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
127
|
+
const existingTerm = categoryMap.get(term.toLowerCase());
|
|
128
|
+
if (existingTerm && existingTerm.id) {
|
|
129
|
+
return existingTerm.id;
|
|
130
|
+
}
|
|
131
|
+
// If we have an existing core category we need to match the new user category to the
|
|
132
|
+
// correct slug rather than autogenerating it to prevent duplicates, eg. the core `Headers`
|
|
133
|
+
// category uses the singular `header` as the slug.
|
|
115
134
|
const termData = existingTerm ? {
|
|
116
135
|
name: existingTerm.label,
|
|
117
136
|
slug: existingTerm.name
|
|
@@ -130,14 +149,7 @@ export default function CreatePatternModal({
|
|
|
130
149
|
return error.data.term_id;
|
|
131
150
|
}
|
|
132
151
|
}
|
|
133
|
-
return createElement(
|
|
134
|
-
title: modalTitle,
|
|
135
|
-
onRequestClose: () => {
|
|
136
|
-
onClose();
|
|
137
|
-
setTitle('');
|
|
138
|
-
},
|
|
139
|
-
overlayClassName: className
|
|
140
|
-
}, createElement("form", {
|
|
152
|
+
return createElement("form", {
|
|
141
153
|
onSubmit: event => {
|
|
142
154
|
event.preventDefault();
|
|
143
155
|
onCreate(title, syncType);
|
|
@@ -178,6 +190,6 @@ export default function CreatePatternModal({
|
|
|
178
190
|
type: "submit",
|
|
179
191
|
"aria-disabled": !title || isSaving,
|
|
180
192
|
isBusy: isSaving
|
|
181
|
-
}, confirmLabel))))
|
|
193
|
+
}, confirmLabel))));
|
|
182
194
|
}
|
|
183
195
|
//# sourceMappingURL=create-pattern-modal.js.map
|