@wordpress/patterns 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/category-selector.js +2 -1
- package/build/components/category-selector.js.map +1 -1
- package/build/components/create-pattern-modal.js +6 -3
- package/build/components/create-pattern-modal.js.map +1 -1
- package/build/components/duplicate-pattern-modal.js +3 -3
- package/build/components/duplicate-pattern-modal.js.map +1 -1
- package/build/components/index.js +4 -2
- package/build/components/index.js.map +1 -1
- package/build/components/pattern-convert-button.js +7 -4
- package/build/components/pattern-convert-button.js.map +1 -1
- package/build/components/patterns-manage-button.js +1 -2
- package/build/components/patterns-manage-button.js.map +1 -1
- package/build-module/components/category-selector.js +2 -1
- package/build-module/components/category-selector.js.map +1 -1
- package/build-module/components/create-pattern-modal.js +6 -3
- package/build-module/components/create-pattern-modal.js.map +1 -1
- package/build-module/components/duplicate-pattern-modal.js +4 -4
- package/build-module/components/duplicate-pattern-modal.js.map +1 -1
- package/build-module/components/index.js +4 -2
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/pattern-convert-button.js +7 -4
- package/build-module/components/pattern-convert-button.js.map +1 -1
- package/build-module/components/patterns-manage-button.js +1 -2
- package/build-module/components/patterns-manage-button.js.map +1 -1
- package/build-style/style-rtl.css +6 -9
- package/build-style/style.css +6 -9
- package/package.json +16 -16
- package/src/components/category-selector.js +1 -0
- package/src/components/create-pattern-modal.js +5 -2
- package/src/components/duplicate-pattern-modal.js +7 -6
- package/src/components/index.js +2 -1
- package/src/components/pattern-convert-button.js +10 -4
- package/src/components/patterns-manage-button.js +34 -37
- package/src/components/style.scss +9 -14
package/CHANGELOG.md
CHANGED
|
@@ -53,7 +53,8 @@ function CategorySelector({
|
|
|
53
53
|
label: (0, _i18n.__)('Categories'),
|
|
54
54
|
tokenizeOnBlur: true,
|
|
55
55
|
__experimentalExpandOnFocus: true,
|
|
56
|
-
__next40pxDefaultSize: true
|
|
56
|
+
__next40pxDefaultSize: true,
|
|
57
|
+
__nextHasNoMarginBottom: true
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
60
|
//# sourceMappingURL=category-selector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_element","_components","_compose","_htmlEntities","unescapeString","arg","decodeEntities","CATEGORY_SLUG","exports","CategorySelector","categoryTerms","onChange","categoryMap","search","setSearch","useState","debouncedSearch","useDebounce","suggestions","useMemo","Array","from","values","map","category","label","filter","toLowerCase","includes","sort","a","b","localeCompare","handleChange","termNames","uniqueTerms","reduce","terms","newTerm","some","term","push","_react","createElement","FormTokenField","className","value","onInputChange","__","tokenizeOnBlur","__experimentalExpandOnFocus","__next40pxDefaultSize"],"sources":["@wordpress/patterns/src/components/category-selector.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useMemo, useState } from '@wordpress/element';\nimport { FormTokenField } from '@wordpress/components';\nimport { useDebounce } from '@wordpress/compose';\nimport { decodeEntities } from '@wordpress/html-entities';\n\nconst unescapeString = ( arg ) => {\n\treturn decodeEntities( arg );\n};\n\nexport const CATEGORY_SLUG = 'wp_pattern_category';\n\nexport default function CategorySelector( {\n\tcategoryTerms,\n\tonChange,\n\tcategoryMap,\n} ) {\n\tconst [ search, setSearch ] = useState( '' );\n\tconst debouncedSearch = useDebounce( setSearch, 500 );\n\n\tconst suggestions = useMemo( () => {\n\t\treturn Array.from( categoryMap.values() )\n\t\t\t.map( ( category ) => unescapeString( category.label ) )\n\t\t\t.filter( ( category ) => {\n\t\t\t\tif ( search !== '' ) {\n\t\t\t\t\treturn category\n\t\t\t\t\t\t.toLowerCase()\n\t\t\t\t\t\t.includes( search.toLowerCase() );\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t} )\n\t\t\t.sort( ( a, b ) => a.localeCompare( b ) );\n\t}, [ search, categoryMap ] );\n\n\tfunction handleChange( termNames ) {\n\t\tconst uniqueTerms = termNames.reduce( ( terms, newTerm ) => {\n\t\t\tif (\n\t\t\t\t! terms.some(\n\t\t\t\t\t( term ) => term.toLowerCase() === newTerm.toLowerCase()\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tterms.push( newTerm );\n\t\t\t}\n\t\t\treturn terms;\n\t\t}, [] );\n\n\t\tonChange( uniqueTerms );\n\t}\n\n\treturn (\n\t\t<FormTokenField\n\t\t\tclassName=\"patterns-menu-items__convert-modal-categories\"\n\t\t\tvalue={ categoryTerms }\n\t\t\tsuggestions={ suggestions }\n\t\t\tonChange={ handleChange }\n\t\t\tonInputChange={ debouncedSearch }\n\t\t\tlabel={ __( 'Categories' ) }\n\t\t\ttokenizeOnBlur\n\t\t\t__experimentalExpandOnFocus\n\t\t\t__next40pxDefaultSize\n\t\t/>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,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,
|
|
1
|
+
{"version":3,"names":["_i18n","require","_element","_components","_compose","_htmlEntities","unescapeString","arg","decodeEntities","CATEGORY_SLUG","exports","CategorySelector","categoryTerms","onChange","categoryMap","search","setSearch","useState","debouncedSearch","useDebounce","suggestions","useMemo","Array","from","values","map","category","label","filter","toLowerCase","includes","sort","a","b","localeCompare","handleChange","termNames","uniqueTerms","reduce","terms","newTerm","some","term","push","_react","createElement","FormTokenField","className","value","onInputChange","__","tokenizeOnBlur","__experimentalExpandOnFocus","__next40pxDefaultSize","__nextHasNoMarginBottom"],"sources":["@wordpress/patterns/src/components/category-selector.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useMemo, useState } from '@wordpress/element';\nimport { FormTokenField } from '@wordpress/components';\nimport { useDebounce } from '@wordpress/compose';\nimport { decodeEntities } from '@wordpress/html-entities';\n\nconst unescapeString = ( arg ) => {\n\treturn decodeEntities( arg );\n};\n\nexport const CATEGORY_SLUG = 'wp_pattern_category';\n\nexport default function CategorySelector( {\n\tcategoryTerms,\n\tonChange,\n\tcategoryMap,\n} ) {\n\tconst [ search, setSearch ] = useState( '' );\n\tconst debouncedSearch = useDebounce( setSearch, 500 );\n\n\tconst suggestions = useMemo( () => {\n\t\treturn Array.from( categoryMap.values() )\n\t\t\t.map( ( category ) => unescapeString( category.label ) )\n\t\t\t.filter( ( category ) => {\n\t\t\t\tif ( search !== '' ) {\n\t\t\t\t\treturn category\n\t\t\t\t\t\t.toLowerCase()\n\t\t\t\t\t\t.includes( search.toLowerCase() );\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t} )\n\t\t\t.sort( ( a, b ) => a.localeCompare( b ) );\n\t}, [ search, categoryMap ] );\n\n\tfunction handleChange( termNames ) {\n\t\tconst uniqueTerms = termNames.reduce( ( terms, newTerm ) => {\n\t\t\tif (\n\t\t\t\t! terms.some(\n\t\t\t\t\t( term ) => term.toLowerCase() === newTerm.toLowerCase()\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tterms.push( newTerm );\n\t\t\t}\n\t\t\treturn terms;\n\t\t}, [] );\n\n\t\tonChange( uniqueTerms );\n\t}\n\n\treturn (\n\t\t<FormTokenField\n\t\t\tclassName=\"patterns-menu-items__convert-modal-categories\"\n\t\t\tvalue={ categoryTerms }\n\t\t\tsuggestions={ suggestions }\n\t\t\tonChange={ handleChange }\n\t\t\tonInputChange={ debouncedSearch }\n\t\t\tlabel={ __( 'Categories' ) }\n\t\t\ttokenizeOnBlur\n\t\t\t__experimentalExpandOnFocus\n\t\t\t__next40pxDefaultSize\n\t\t\t__nextHasNoMarginBottom\n\t\t/>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AAPA;AACA;AACA;;AAOA,MAAMK,cAAc,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;IACrBC,uBAAuB;EAAA,CACvB,CAAC;AAEJ"}
|
|
@@ -154,19 +154,20 @@ function CreatePatternModal({
|
|
|
154
154
|
}, (0, _react.createElement)(_components.__experimentalVStack, {
|
|
155
155
|
spacing: "5"
|
|
156
156
|
}, (0, _react.createElement)(_components.TextControl, {
|
|
157
|
-
__nextHasNoMarginBottom: true,
|
|
158
157
|
label: (0, _i18n.__)('Name'),
|
|
159
158
|
value: title,
|
|
160
159
|
onChange: setTitle,
|
|
161
160
|
placeholder: (0, _i18n.__)('My pattern'),
|
|
162
|
-
className: "patterns-create-modal__name-input"
|
|
161
|
+
className: "patterns-create-modal__name-input",
|
|
162
|
+
__nextHasNoMarginBottom: true,
|
|
163
|
+
__next40pxDefaultSize: true
|
|
163
164
|
}), (0, _react.createElement)(_categorySelector.default, {
|
|
164
165
|
categoryTerms: categoryTerms,
|
|
165
166
|
onChange: setCategoryTerms,
|
|
166
167
|
categoryMap: categoryMap
|
|
167
168
|
}), (0, _react.createElement)(_components.ToggleControl, {
|
|
168
169
|
label: (0, _i18n._x)('Synced', 'Option that makes an individual pattern synchronized'),
|
|
169
|
-
help: (0, _i18n.__)('
|
|
170
|
+
help: (0, _i18n.__)('Sync this pattern across multiple locations.'),
|
|
170
171
|
checked: syncType === _constants.PATTERN_SYNC_TYPES.full,
|
|
171
172
|
onChange: () => {
|
|
172
173
|
setSyncType(syncType === _constants.PATTERN_SYNC_TYPES.full ? _constants.PATTERN_SYNC_TYPES.unsynced : _constants.PATTERN_SYNC_TYPES.full);
|
|
@@ -174,12 +175,14 @@ function CreatePatternModal({
|
|
|
174
175
|
}), (0, _react.createElement)(_components.__experimentalHStack, {
|
|
175
176
|
justify: "right"
|
|
176
177
|
}, (0, _react.createElement)(_components.Button, {
|
|
178
|
+
__next40pxDefaultSize: true,
|
|
177
179
|
variant: "tertiary",
|
|
178
180
|
onClick: () => {
|
|
179
181
|
onClose();
|
|
180
182
|
setTitle('');
|
|
181
183
|
}
|
|
182
184
|
}, (0, _i18n.__)('Cancel')), (0, _react.createElement)(_components.Button, {
|
|
185
|
+
__next40pxDefaultSize: true,
|
|
183
186
|
variant: "primary",
|
|
184
187
|
type: "submit",
|
|
185
188
|
"aria-disabled": !title || isSaving,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_i18n","_element","_data","_notices","_coreData","_constants","_store","_categorySelector","_interopRequireWildcard","_lockUnlock","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","CreatePatternModal","confirmLabel","__","defaultCategories","className","content","modalTitle","onClose","onError","onSuccess","defaultSyncType","PATTERN_SYNC_TYPES","full","defaultTitle","syncType","setSyncType","useState","categoryTerms","setCategoryTerms","title","setTitle","isSaving","setIsSaving","createPattern","unlock","useDispatch","patternsStore","saveEntityRecord","invalidateResolution","coreStore","createErrorNotice","noticesStore","corePatternCategories","userPatternCategories","useSelect","select","getUserPatternCategories","getBlockPatternCategories","categoryMap","useMemo","uniqueCategories","Map","forEach","category","label","name","value","onCreate","patternTitle","sync","categories","Promise","all","map","termName","findOrCreateTerm","newPattern","pattern","categoryId","PATTERN_DEFAULT_CATEGORY","error","message","type","id","term","existingTerm","termData","slug","newTerm","CATEGORY_SLUG","throwOnError","code","data","term_id","_react","createElement","Modal","onRequestClose","overlayClassName","onSubmit","event","preventDefault","__experimentalVStack","spacing","TextControl","__nextHasNoMarginBottom","onChange","placeholder","ToggleControl","_x","help","checked","unsynced","__experimentalHStack","justify","Button","variant","onClick","isBusy"],"sources":["@wordpress/patterns/src/components/create-pattern-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tModal,\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tToggleControl,\n} from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport { useState, useMemo } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_DEFAULT_CATEGORY, PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CategorySelector, { CATEGORY_SLUG } from './category-selector';\nimport { unlock } from '../lock-unlock';\n\nexport default function CreatePatternModal( {\n\tconfirmLabel = __( 'Create' ),\n\tdefaultCategories = [],\n\tclassName = 'patterns-menu-items__convert-modal',\n\tcontent,\n\tmodalTitle = __( 'Create pattern' ),\n\tonClose,\n\tonError,\n\tonSuccess,\n\tdefaultSyncType = PATTERN_SYNC_TYPES.full,\n\tdefaultTitle = '',\n} ) {\n\tconst [ syncType, setSyncType ] = useState( defaultSyncType );\n\tconst [ categoryTerms, setCategoryTerms ] = useState( defaultCategories );\n\tconst [ title, setTitle ] = useState( defaultTitle );\n\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\tconst { createPattern } = unlock( useDispatch( patternsStore ) );\n\tconst { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tconst { corePatternCategories, userPatternCategories } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getUserPatternCategories, getBlockPatternCategories } =\n\t\t\t\tselect( coreStore );\n\n\t\t\treturn {\n\t\t\t\tcorePatternCategories: getBlockPatternCategories(),\n\t\t\t\tuserPatternCategories: getUserPatternCategories(),\n\t\t\t};\n\t\t}\n\t);\n\n\tconst categoryMap = useMemo( () => {\n\t\t// Merge the user and core pattern categories and remove any duplicates.\n\t\tconst uniqueCategories = new Map();\n\t\t[ ...userPatternCategories, ...corePatternCategories ].forEach(\n\t\t\t( category ) => {\n\t\t\t\tif (\n\t\t\t\t\t! uniqueCategories.has( category.label ) &&\n\t\t\t\t\t// There are two core categories with `Post` label so explicitly remove the one with\n\t\t\t\t\t// the `query` slug to avoid any confusion.\n\t\t\t\t\tcategory.name !== 'query'\n\t\t\t\t) {\n\t\t\t\t\t// We need to store the name separately as this is used as the slug in the\n\t\t\t\t\t// taxonomy and may vary from the label.\n\t\t\t\t\tuniqueCategories.set( category.label, {\n\t\t\t\t\t\tlabel: category.label,\n\t\t\t\t\t\tvalue: category.label,\n\t\t\t\t\t\tname: category.name,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t\treturn uniqueCategories;\n\t}, [ userPatternCategories, corePatternCategories ] );\n\n\tasync function onCreate( patternTitle, sync ) {\n\t\tif ( ! title || isSaving ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSaving( true );\n\t\t\tconst categories = await Promise.all(\n\t\t\t\tcategoryTerms.map( ( termName ) =>\n\t\t\t\t\tfindOrCreateTerm( termName )\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tconst newPattern = await createPattern(\n\t\t\t\tpatternTitle,\n\t\t\t\tsync,\n\t\t\t\ttypeof content === 'function' ? content() : content,\n\t\t\t\tcategories\n\t\t\t);\n\t\t\tonSuccess( {\n\t\t\t\tpattern: newPattern,\n\t\t\t\tcategoryId: PATTERN_DEFAULT_CATEGORY,\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-create',\n\t\t\t} );\n\t\t\tonError?.();\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t\tsetCategoryTerms( [] );\n\t\t\tsetTitle( '' );\n\t\t}\n\t}\n\n\t/**\n\t * @param {string} term\n\t * @return {Promise<number>} The pattern category id.\n\t */\n\tasync function findOrCreateTerm( term ) {\n\t\ttry {\n\t\t\t// We need to match any existing term to the correct slug to prevent duplicates, eg.\n\t\t\t// the core `Headers` category uses the singular `header` as the slug.\n\t\t\tconst existingTerm = categoryMap.get( term );\n\t\t\tconst termData = existingTerm\n\t\t\t\t? { name: existingTerm.label, slug: existingTerm.name }\n\t\t\t\t: { name: term };\n\t\t\tconst newTerm = await saveEntityRecord(\n\t\t\t\t'taxonomy',\n\t\t\t\tCATEGORY_SLUG,\n\t\t\t\ttermData,\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tinvalidateResolution( 'getUserPatternCategories' );\n\t\t\treturn newTerm.id;\n\t\t} catch ( error ) {\n\t\t\tif ( error.code !== 'term_exists' ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn error.data.term_id;\n\t\t}\n\t}\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle }\n\t\t\tonRequestClose={ () => {\n\t\t\t\tonClose();\n\t\t\t\tsetTitle( '' );\n\t\t\t} }\n\t\t\toverlayClassName={ className }\n\t\t>\n\t\t\t<form\n\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tonCreate( title, syncType );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\tplaceholder={ __( 'My pattern' ) }\n\t\t\t\t\t\tclassName=\"patterns-create-modal__name-input\"\n\t\t\t\t\t/>\n\t\t\t\t\t<CategorySelector\n\t\t\t\t\t\tcategoryTerms={ categoryTerms }\n\t\t\t\t\t\tonChange={ setCategoryTerms }\n\t\t\t\t\t\tcategoryMap={ categoryMap }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t\t'Synced',\n\t\t\t\t\t\t\t'Option that makes an individual pattern synchronized'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Editing the pattern will update it anywhere it is used.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ syncType === PATTERN_SYNC_TYPES.full }\n\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\tsyncType === PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t\t\t? PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t\t\t\t\t\t: PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\taria-disabled={ ! title || isSaving }\n\t\t\t\t\t\t\tisBusy={ isSaving }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ 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,WAA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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","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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,CAAAC,aAAA,EAAC7G,WAAA,CAAAkI,MAAM;IACNR,qBAAqB;IACrBS,OAAO,EAAC,SAAS;IACjBnC,IAAI,EAAC,QAAQ;IACb,iBAAgB,CAAE3C,KAAK,IAAIE,QAAU;IACrC8E,MAAM,EAAG9E;EAAU,GAEjBpB,YACK,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
@@ -21,8 +21,8 @@ var _constants = require("../constants");
|
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
function getTermLabels(pattern, categories) {
|
|
24
|
-
// Theme patterns
|
|
25
|
-
if (
|
|
24
|
+
// Theme patterns rely on core pattern categories.
|
|
25
|
+
if (pattern.type !== _constants.PATTERN_TYPES.user) {
|
|
26
26
|
return categories.core?.filter(category => pattern.categories.includes(category.name)).map(category => category.label);
|
|
27
27
|
}
|
|
28
28
|
return categories.user?.filter(category => pattern.wp_pattern_category.includes(category.id)).map(category => category.label);
|
|
@@ -51,7 +51,7 @@ function DuplicatePatternModal({
|
|
|
51
51
|
const duplicatedProps = {
|
|
52
52
|
content: pattern.content,
|
|
53
53
|
defaultCategories: getTermLabels(pattern, categories),
|
|
54
|
-
defaultSyncType:
|
|
54
|
+
defaultSyncType: pattern.type !== _constants.PATTERN_TYPES.user // Theme patterns are unsynced by default.
|
|
55
55
|
? _constants.PATTERN_SYNC_TYPES.unsynced : pattern.wp_pattern_sync_status || _constants.PATTERN_SYNC_TYPES.full,
|
|
56
56
|
defaultTitle: (0, _i18n.sprintf)( /* translators: %s: Existing pattern title */
|
|
57
57
|
(0, _i18n.__)('%s (Copy)'), typeof pattern.title === 'string' ? pattern.title : pattern.title.raw)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_coreData","require","_data","_i18n","_notices","_createPatternModal","_interopRequireDefault","_constants","getTermLabels","pattern","categories","
|
|
1
|
+
{"version":3,"names":["_coreData","require","_data","_i18n","_notices","_createPatternModal","_interopRequireDefault","_constants","getTermLabels","pattern","categories","type","PATTERN_TYPES","user","core","filter","category","includes","name","map","label","wp_pattern_category","id","DuplicatePatternModal","onClose","onSuccess","createSuccessNotice","useDispatch","noticesStore","useSelect","select","getUserPatternCategories","getBlockPatternCategories","coreStore","duplicatedProps","content","defaultCategories","defaultSyncType","PATTERN_SYNC_TYPES","unsynced","wp_pattern_sync_status","full","defaultTitle","sprintf","__","title","raw","handleOnSuccess","newPattern","_react","createElement","default","modalTitle","confirmLabel","onError"],"sources":["@wordpress/patterns/src/components/duplicate-pattern-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport CreatePatternModal from './create-pattern-modal';\nimport { PATTERN_SYNC_TYPES, PATTERN_TYPES } from '../constants';\n\nfunction getTermLabels( pattern, categories ) {\n\t// Theme patterns rely on core pattern categories.\n\tif ( pattern.type !== PATTERN_TYPES.user ) {\n\t\treturn categories.core\n\t\t\t?.filter( ( category ) =>\n\t\t\t\tpattern.categories.includes( category.name )\n\t\t\t)\n\t\t\t.map( ( category ) => category.label );\n\t}\n\n\treturn categories.user\n\t\t?.filter( ( category ) =>\n\t\t\tpattern.wp_pattern_category.includes( category.id )\n\t\t)\n\t\t.map( ( category ) => category.label );\n}\n\nexport default function DuplicatePatternModal( {\n\tpattern,\n\tonClose,\n\tonSuccess,\n} ) {\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst categories = useSelect( ( select ) => {\n\t\tconst { getUserPatternCategories, getBlockPatternCategories } =\n\t\t\tselect( coreStore );\n\n\t\treturn {\n\t\t\tcore: getBlockPatternCategories(),\n\t\t\tuser: getUserPatternCategories(),\n\t\t};\n\t} );\n\n\tif ( ! pattern ) {\n\t\treturn null;\n\t}\n\n\tconst duplicatedProps = {\n\t\tcontent: pattern.content,\n\t\tdefaultCategories: getTermLabels( pattern, categories ),\n\t\tdefaultSyncType:\n\t\t\tpattern.type !== PATTERN_TYPES.user // Theme patterns are unsynced by default.\n\t\t\t\t? PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t: pattern.wp_pattern_sync_status || PATTERN_SYNC_TYPES.full,\n\t\tdefaultTitle: sprintf(\n\t\t\t/* translators: %s: Existing pattern title */\n\t\t\t__( '%s (Copy)' ),\n\t\t\ttypeof pattern.title === 'string'\n\t\t\t\t? pattern.title\n\t\t\t\t: pattern.title.raw\n\t\t),\n\t};\n\n\tfunction handleOnSuccess( { pattern: newPattern } ) {\n\t\tcreateSuccessNotice(\n\t\t\tsprintf(\n\t\t\t\t// translators: %s: The new pattern's title e.g. 'Call to action (copy)'.\n\t\t\t\t__( '\"%s\" duplicated.' ),\n\t\t\t\tnewPattern.title.raw\n\t\t\t),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'patterns-create',\n\t\t\t}\n\t\t);\n\n\t\tonSuccess?.( { pattern: newPattern } );\n\t}\n\n\treturn (\n\t\t<CreatePatternModal\n\t\t\tmodalTitle={ __( 'Duplicate pattern' ) }\n\t\t\tconfirmLabel={ __( 'Duplicate' ) }\n\t\t\tonClose={ onClose }\n\t\t\tonError={ onClose }\n\t\t\tonSuccess={ handleOnSuccess }\n\t\t\t{ ...duplicatedProps }\n\t\t/>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAKA,IAAAI,mBAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AAZA;AACA;AACA;;AAMA;AACA;AACA;;AAIA,SAASO,aAAaA,CAAEC,OAAO,EAAEC,UAAU,EAAG;EAC7C;EACA,IAAKD,OAAO,CAACE,IAAI,KAAKC,wBAAa,CAACC,IAAI,EAAG;IAC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AAE,WAAY,CAAC,EACjB,OAAOnC,OAAO,CAACoC,KAAK,KAAK,QAAQ,GAC9BpC,OAAO,CAACoC,KAAK,GACbpC,OAAO,CAACoC,KAAK,CAACC,GAClB;EACD,CAAC;EAED,SAASC,eAAeA,CAAE;IAAEtC,OAAO,EAAEuC;EAAW,CAAC,EAAG;IACnDtB,mBAAmB,CAClB,IAAAiB,aAAO;IACN;IACA,IAAAC,QAAE,EAAE,kBAAmB,CAAC,EACxBI,UAAU,CAACH,KAAK,CAACC,GAClB,CAAC,EACD;MACCnC,IAAI,EAAE,UAAU;MAChBW,EAAE,EAAE;IACL,CACD,CAAC;IAEDG,SAAS,GAAI;MAAEhB,OAAO,EAAEuC;IAAW,CAAE,CAAC;EACvC;EAEA,OACC,IAAAC,MAAA,CAAAC,aAAA,EAAC7C,mBAAA,CAAA8C,OAAkB;IAClBC,UAAU,EAAG,IAAAR,QAAE,EAAE,mBAAoB,CAAG;IACxCS,YAAY,EAAG,IAAAT,QAAE,EAAE,WAAY,CAAG;IAClCpB,OAAO,EAAGA,OAAS;IACnB8B,OAAO,EAAG9B,OAAS;IACnBC,SAAS,EAAGsB,eAAiB;IAAA,GACxBb;EAAe,CACpB,CAAC;AAEJ"}
|
|
@@ -21,10 +21,12 @@ function PatternsMenuItems({
|
|
|
21
21
|
rootClientId
|
|
22
22
|
}) {
|
|
23
23
|
return (0, _react.createElement)(_blockEditor.BlockSettingsMenuControls, null, ({
|
|
24
|
-
selectedClientIds
|
|
24
|
+
selectedClientIds,
|
|
25
|
+
onClose
|
|
25
26
|
}) => (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)(_patternConvertButton.default, {
|
|
26
27
|
clientIds: selectedClientIds,
|
|
27
|
-
rootClientId: rootClientId
|
|
28
|
+
rootClientId: rootClientId,
|
|
29
|
+
closeBlockSettingsMenu: onClose
|
|
28
30
|
}), selectedClientIds.length === 1 && (0, _react.createElement)(_patternsManageButton.default, {
|
|
29
31
|
clientId: selectedClientIds[0]
|
|
30
32
|
})));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_blockEditor","require","_patternConvertButton","_interopRequireDefault","_patternsManageButton","PatternsMenuItems","rootClientId","_react","createElement","BlockSettingsMenuControls","selectedClientIds","Fragment","default","clientIds","length","clientId"],"sources":["@wordpress/patterns/src/components/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { BlockSettingsMenuControls } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport PatternConvertButton from './pattern-convert-button';\nimport PatternsManageButton from './patterns-manage-button';\n\nexport default function PatternsMenuItems( { rootClientId } ) {\n\treturn (\n\t\t<BlockSettingsMenuControls>\n\t\t\t{ ( { selectedClientIds } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<PatternConvertButton\n\t\t\t\t\t\tclientIds={ selectedClientIds }\n\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t/>\n\t\t\t\t\t{ selectedClientIds.length === 1 && (\n\t\t\t\t\t\t<PatternsManageButton\n\t\t\t\t\t\t\tclientId={ selectedClientIds[ 0 ] }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\t\t</BlockSettingsMenuControls>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAKA,IAAAC,qBAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAD,sBAAA,CAAAF,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIe,SAASI,iBAAiBA,CAAE;EAAEC;AAAa,CAAC,EAAG;EAC7D,OACC,IAAAC,MAAA,CAAAC,aAAA,EAACR,YAAA,CAAAS,yBAAyB,QACvB,CAAE;IAAEC;
|
|
1
|
+
{"version":3,"names":["_blockEditor","require","_patternConvertButton","_interopRequireDefault","_patternsManageButton","PatternsMenuItems","rootClientId","_react","createElement","BlockSettingsMenuControls","selectedClientIds","onClose","Fragment","default","clientIds","closeBlockSettingsMenu","length","clientId"],"sources":["@wordpress/patterns/src/components/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { BlockSettingsMenuControls } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport PatternConvertButton from './pattern-convert-button';\nimport PatternsManageButton from './patterns-manage-button';\n\nexport default function PatternsMenuItems( { rootClientId } ) {\n\treturn (\n\t\t<BlockSettingsMenuControls>\n\t\t\t{ ( { selectedClientIds, onClose } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<PatternConvertButton\n\t\t\t\t\t\tclientIds={ selectedClientIds }\n\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\tcloseBlockSettingsMenu={ onClose }\n\t\t\t\t\t/>\n\t\t\t\t\t{ selectedClientIds.length === 1 && (\n\t\t\t\t\t\t<PatternsManageButton\n\t\t\t\t\t\t\tclientId={ selectedClientIds[ 0 ] }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\t\t</BlockSettingsMenuControls>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAKA,IAAAC,qBAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAD,sBAAA,CAAAF,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIe,SAASI,iBAAiBA,CAAE;EAAEC;AAAa,CAAC,EAAG;EAC7D,OACC,IAAAC,MAAA,CAAAC,aAAA,EAACR,YAAA,CAAAS,yBAAyB,QACvB,CAAE;IAAEC,iBAAiB;IAAEC;EAAQ,CAAC,KACjC,IAAAJ,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAK,QAAA,QACC,IAAAL,MAAA,CAAAC,aAAA,EAACN,qBAAA,CAAAW,OAAoB;IACpBC,SAAS,EAAGJ,iBAAmB;IAC/BJ,YAAY,EAAGA,YAAc;IAC7BS,sBAAsB,EAAGJ;EAAS,CAClC,CAAC,EACAD,iBAAiB,CAACM,MAAM,KAAK,CAAC,IAC/B,IAAAT,MAAA,CAAAC,aAAA,EAACJ,qBAAA,CAAAS,OAAoB;IACpBI,QAAQ,EAAGP,iBAAiB,CAAE,CAAC;EAAI,CACnC,CAED,CAEuB,CAAC;AAE9B"}
|
|
@@ -30,14 +30,16 @@ var _constants = require("../constants");
|
|
|
30
30
|
/**
|
|
31
31
|
* Menu control to convert block(s) to a pattern block.
|
|
32
32
|
*
|
|
33
|
-
* @param {Object} props
|
|
34
|
-
* @param {string[]} props.clientIds
|
|
35
|
-
* @param {string} props.rootClientId
|
|
33
|
+
* @param {Object} props Component props.
|
|
34
|
+
* @param {string[]} props.clientIds Client ids of selected blocks.
|
|
35
|
+
* @param {string} props.rootClientId ID of the currently selected top-level block.
|
|
36
|
+
* @param {()=>void} props.closeBlockSettingsMenu Callback to close the block settings menu dropdown.
|
|
36
37
|
* @return {import('react').ComponentType} The menu control or null.
|
|
37
38
|
*/
|
|
38
39
|
function PatternConvertButton({
|
|
39
40
|
clientIds,
|
|
40
|
-
rootClientId
|
|
41
|
+
rootClientId,
|
|
42
|
+
closeBlockSettingsMenu
|
|
41
43
|
}) {
|
|
42
44
|
const {
|
|
43
45
|
createSuccessNotice
|
|
@@ -95,6 +97,7 @@ function PatternConvertButton({
|
|
|
95
97
|
});
|
|
96
98
|
replaceBlocks(clientIds, newBlock);
|
|
97
99
|
setEditingPattern(newBlock.clientId, true);
|
|
100
|
+
closeBlockSettingsMenu();
|
|
98
101
|
}
|
|
99
102
|
createSuccessNotice(pattern.wp_pattern_sync_status === _constants.PATTERN_SYNC_TYPES.unsynced ? (0, _i18n.sprintf)(
|
|
100
103
|
// translators: %s: the name the user has given to the pattern.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_blocks","require","_blockEditor","_element","_components","_icons","_data","_coreData","_i18n","_notices","_store","_createPatternModal","_interopRequireDefault","_lockUnlock","_constants","PatternConvertButton","clientIds","rootClientId","createSuccessNotice","useDispatch","noticesStore","replaceBlocks","blockEditorStore","setEditingPattern","unlock","patternsStore","isModalOpen","setIsModalOpen","useState","canConvert","useSelect","select","_getBlocksByClientId","canUser","coreStore","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","rootId","length","undefined","blocks","isReusable","isReusableBlock","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","hasBlockSupport","name","getContent","useCallback","serialize","handleSuccess","pattern","wp_pattern_sync_status","PATTERN_SYNC_TYPES","unsynced","newBlock","createBlock","id","clientId","sprintf","__","title","raw","type","_react","createElement","Fragment","MenuItem","icon","symbol","onClick","default","content","onSuccess","onError","onClose"],"sources":["@wordpress/patterns/src/components/pattern-convert-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\thasBlockSupport,\n\tisReusableBlock,\n\tcreateBlock,\n\tserialize,\n} from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useState, useCallback } from '@wordpress/element';\nimport { MenuItem } from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CreatePatternModal from './create-pattern-modal';\nimport { unlock } from '../lock-unlock';\nimport { PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Menu control to convert block(s) to a pattern block.\n *\n * @param {Object} props
|
|
1
|
+
{"version":3,"names":["_blocks","require","_blockEditor","_element","_components","_icons","_data","_coreData","_i18n","_notices","_store","_createPatternModal","_interopRequireDefault","_lockUnlock","_constants","PatternConvertButton","clientIds","rootClientId","closeBlockSettingsMenu","createSuccessNotice","useDispatch","noticesStore","replaceBlocks","blockEditorStore","setEditingPattern","unlock","patternsStore","isModalOpen","setIsModalOpen","useState","canConvert","useSelect","select","_getBlocksByClientId","canUser","coreStore","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","rootId","length","undefined","blocks","isReusable","isReusableBlock","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","hasBlockSupport","name","getContent","useCallback","serialize","handleSuccess","pattern","wp_pattern_sync_status","PATTERN_SYNC_TYPES","unsynced","newBlock","createBlock","id","clientId","sprintf","__","title","raw","type","_react","createElement","Fragment","MenuItem","icon","symbol","onClick","default","content","onSuccess","onError","onClose"],"sources":["@wordpress/patterns/src/components/pattern-convert-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\thasBlockSupport,\n\tisReusableBlock,\n\tcreateBlock,\n\tserialize,\n} from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useState, useCallback } from '@wordpress/element';\nimport { MenuItem } from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CreatePatternModal from './create-pattern-modal';\nimport { unlock } from '../lock-unlock';\nimport { PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Menu control to convert block(s) to a pattern block.\n *\n * @param {Object} props Component props.\n * @param {string[]} props.clientIds Client ids of selected blocks.\n * @param {string} props.rootClientId ID of the currently selected top-level block.\n * @param {()=>void} props.closeBlockSettingsMenu Callback to close the block settings menu dropdown.\n * @return {import('react').ComponentType} The menu control or null.\n */\nexport default function PatternConvertButton( {\n\tclientIds,\n\trootClientId,\n\tcloseBlockSettingsMenu,\n} ) {\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst { replaceBlocks } = useDispatch( blockEditorStore );\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { setEditingPattern } = unlock( useDispatch( patternsStore ) );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst canConvert = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst {\n\t\t\t\tgetBlocksByClientId,\n\t\t\t\tcanInsertBlockType,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst rootId =\n\t\t\t\trootClientId ||\n\t\t\t\t( clientIds.length > 0\n\t\t\t\t\t? getBlockRootClientId( clientIds[ 0 ] )\n\t\t\t\t\t: undefined );\n\n\t\t\tconst blocks = getBlocksByClientId( clientIds ) ?? [];\n\n\t\t\tconst isReusable =\n\t\t\t\tblocks.length === 1 &&\n\t\t\t\tblocks[ 0 ] &&\n\t\t\t\tisReusableBlock( blocks[ 0 ] ) &&\n\t\t\t\t!! select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_block',\n\t\t\t\t\tblocks[ 0 ].attributes.ref\n\t\t\t\t);\n\n\t\t\tconst _canConvert =\n\t\t\t\t// Hide when this is already a synced pattern.\n\t\t\t\t! isReusable &&\n\t\t\t\t// Hide when patterns are disabled.\n\t\t\t\tcanInsertBlockType( 'core/block', rootId ) &&\n\t\t\t\tblocks.every(\n\t\t\t\t\t( block ) =>\n\t\t\t\t\t\t// Guard against the case where a regular block has *just* been converted.\n\t\t\t\t\t\t!! block &&\n\t\t\t\t\t\t// Hide on invalid blocks.\n\t\t\t\t\t\tblock.isValid &&\n\t\t\t\t\t\t// Hide when block doesn't support being made into a pattern.\n\t\t\t\t\t\thasBlockSupport( block.name, 'reusable', true )\n\t\t\t\t) &&\n\t\t\t\t// Hide when current doesn't have permission to do that.\n\t\t\t\t!! canUser( 'create', 'blocks' );\n\n\t\t\treturn _canConvert;\n\t\t},\n\t\t[ clientIds, rootClientId ]\n\t);\n\tconst { getBlocksByClientId } = useSelect( blockEditorStore );\n\tconst getContent = useCallback(\n\t\t() => serialize( getBlocksByClientId( clientIds ) ),\n\t\t[ getBlocksByClientId, clientIds ]\n\t);\n\n\tif ( ! canConvert ) {\n\t\treturn null;\n\t}\n\n\tconst handleSuccess = ( { pattern } ) => {\n\t\tif ( pattern.wp_pattern_sync_status !== PATTERN_SYNC_TYPES.unsynced ) {\n\t\t\tconst newBlock = createBlock( 'core/block', {\n\t\t\t\tref: pattern.id,\n\t\t\t} );\n\n\t\t\treplaceBlocks( clientIds, newBlock );\n\t\t\tsetEditingPattern( newBlock.clientId, true );\n\t\t\tcloseBlockSettingsMenu();\n\t\t}\n\n\t\tcreateSuccessNotice(\n\t\t\tpattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Unsynced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Synced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t ),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'convert-to-pattern-success',\n\t\t\t}\n\t\t);\n\t\tsetIsModalOpen( false );\n\t};\n\treturn (\n\t\t<>\n\t\t\t<MenuItem\n\t\t\t\ticon={ symbol }\n\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\taria-expanded={ isModalOpen }\n\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t>\n\t\t\t\t{ __( 'Create pattern' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<CreatePatternModal\n\t\t\t\t\tcontent={ getContent }\n\t\t\t\t\tonSuccess={ ( pattern ) => {\n\t\t\t\t\t\thandleSuccess( pattern );\n\t\t\t\t\t} }\n\t\t\t\t\tonError={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonClose={ () => {\n\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AY;IACtB0B,SAAS,EAAKtB,OAAO,IAAM;MAC1BD,aAAa,CAAEC,OAAQ,CAAC;IACzB,CAAG;IACHuB,OAAO,EAAGA,CAAA,KAAM;MACfrD,cAAc,CAAE,KAAM,CAAC;IACxB,CAAG;IACHsD,OAAO,EAAGA,CAAA,KAAM;MACftD,cAAc,CAAE,KAAM,CAAC;IACxB;EAAG,CACH,CAED,CAAC;AAEL"}
|
|
@@ -28,7 +28,6 @@ function PatternsManageButton({
|
|
|
28
28
|
const {
|
|
29
29
|
canRemove,
|
|
30
30
|
isVisible,
|
|
31
|
-
innerBlockCount,
|
|
32
31
|
managePatternsUrl
|
|
33
32
|
} = (0, _data.useSelect)(select => {
|
|
34
33
|
const {
|
|
@@ -67,7 +66,7 @@ function PatternsManageButton({
|
|
|
67
66
|
}
|
|
68
67
|
return (0, _react.createElement)(_react.Fragment, null, canRemove && (0, _react.createElement)(_components.MenuItem, {
|
|
69
68
|
onClick: () => convertSyncedPatternToStatic(clientId)
|
|
70
|
-
},
|
|
69
|
+
}, (0, _i18n.__)('Detach')), (0, _react.createElement)(_components.MenuItem, {
|
|
71
70
|
href: managePatternsUrl
|
|
72
71
|
}, (0, _i18n.__)('Manage patterns')));
|
|
73
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_i18n","_blocks","_data","_blockEditor","_url","_coreData","_store","_lockUnlock","PatternsManageButton","clientId","canRemove","isVisible","
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_blocks","_data","_blockEditor","_url","_coreData","_store","_lockUnlock","PatternsManageButton","clientId","canRemove","isVisible","managePatternsUrl","useSelect","select","getBlock","canRemoveBlock","getBlockCount","getSettings","blockEditorStore","canUser","coreStore","reusableBlock","isBlockTheme","__unstableIsBlockBasedTheme","isReusableBlock","attributes","ref","innerBlockCount","addQueryArgs","path","post_type","convertSyncedPatternToStatic","unlock","useDispatch","patternsStore","_react","createElement","Fragment","MenuItem","onClick","__","href","_default","exports","default"],"sources":["@wordpress/patterns/src/components/patterns-manage-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nfunction PatternsManageButton( { clientId } ) {\n\tconst { canRemove, isVisible, managePatternsUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, canRemoveBlock, getBlockCount, getSettings } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst reusableBlock = getBlock( clientId );\n\t\t\tconst isBlockTheme = getSettings().__unstableIsBlockBasedTheme;\n\n\t\t\treturn {\n\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\tisVisible:\n\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t!! canUser(\n\t\t\t\t\t\t'update',\n\t\t\t\t\t\t'blocks',\n\t\t\t\t\t\treusableBlock.attributes.ref\n\t\t\t\t\t),\n\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t// The site editor and templates both check whether the user\n\t\t\t\t// has edit_theme_options capabilities. We can leverage that here\n\t\t\t\t// and omit the manage patterns link if the user can't access it.\n\t\t\t\tmanagePatternsUrl:\n\t\t\t\t\tisBlockTheme && canUser( 'read', 'templates' )\n\t\t\t\t\t\t? addQueryArgs( 'site-editor.php', {\n\t\t\t\t\t\t\t\tpath: '/patterns',\n\t\t\t\t\t\t } )\n\t\t\t\t\t\t: addQueryArgs( 'edit.php', {\n\t\t\t\t\t\t\t\tpost_type: 'wp_block',\n\t\t\t\t\t\t } ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { convertSyncedPatternToStatic } = unlock(\n\t\tuseDispatch( patternsStore )\n\t);\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ canRemove && (\n\t\t\t\t<MenuItem\n\t\t\t\t\tonClick={ () => convertSyncedPatternToStatic( clientId ) }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Detach' ) }\n\t\t\t\t</MenuItem>\n\t\t\t) }\n\t\t\t<MenuItem href={ managePatternsUrl }>\n\t\t\t\t{ __( 'Manage patterns' ) }\n\t\t\t</MenuItem>\n\t\t</>\n\t);\n}\n\nexport default PatternsManageButton;\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,IAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,WAAA,GAAAR,OAAA;AAfA;AACA;AACA;;AASA;AACA;AACA;;AAIA,SAASS,oBAAoBA,CAAE;EAAEC;AAAS,CAAC,EAAG;EAC7C,MAAM;IAAEC,SAAS;IAAEC,SAAS;IAAEC;EAAkB,CAAC,GAAG,IAAAC,eAAS,EAC1DC,MAAM,IAAM;IACb,MAAM;MAAEC,QAAQ;MAAEC,cAAc;MAAEC,aAAa;MAAEC;IAAY,CAAC,GAC7DJ,MAAM,CAAEK,kBAAiB,CAAC;IAC3B,MAAM;MAAEC;IAAQ,CAAC,GAAGN,MAAM,CAAEO,eAAU,CAAC;IACvC,MAAMC,aAAa,GAAGP,QAAQ,CAAEN,QAAS,CAAC;IAC1C,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AF,QAAA"}
|
|
@@ -44,7 +44,8 @@ export default function CategorySelector({
|
|
|
44
44
|
label: __('Categories'),
|
|
45
45
|
tokenizeOnBlur: true,
|
|
46
46
|
__experimentalExpandOnFocus: true,
|
|
47
|
-
__next40pxDefaultSize: true
|
|
47
|
+
__next40pxDefaultSize: true,
|
|
48
|
+
__nextHasNoMarginBottom: true
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
51
|
//# sourceMappingURL=category-selector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","useMemo","useState","FormTokenField","useDebounce","decodeEntities","unescapeString","arg","CATEGORY_SLUG","CategorySelector","categoryTerms","onChange","categoryMap","search","setSearch","debouncedSearch","suggestions","Array","from","values","map","category","label","filter","toLowerCase","includes","sort","a","b","localeCompare","handleChange","termNames","uniqueTerms","reduce","terms","newTerm","some","term","push","createElement","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":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,OAAO,EAAEC,QAAQ,QAAQ,oBAAoB;AACtD,SAASC,cAAc,QAAQ,uBAAuB;AACtD,SAASC,WAAW,QAAQ,oBAAoB;AAChD,SAASC,cAAc,QAAQ,0BAA0B;AAEzD,MAAMC,cAAc,GAAKC,GAAG,IAAM;EACjC,OAAOF,cAAc,CAAEE,GAAI,CAAC;AAC7B,CAAC;AAED,OAAO,MAAMC,aAAa,GAAG,qBAAqB;AAElD,eAAe,SAASC,gBAAgBA,CAAE;EACzCC,aAAa;EACbC,QAAQ;EACRC;AACD,CAAC,EAAG;EACH,MAAM,CAAEC,MAAM,EAAEC,SAAS,CAAE,GAAGZ,QAAQ,CAAE,EAAG,CAAC;EAC5C,MAAMa,eAAe,GAAGX,WAAW,CAAEU,SAAS,EAAE,GAAI,CAAC;EAErD,MAAME,WAAW,GAAGf,O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","useMemo","useState","FormTokenField","useDebounce","decodeEntities","unescapeString","arg","CATEGORY_SLUG","CategorySelector","categoryTerms","onChange","categoryMap","search","setSearch","debouncedSearch","suggestions","Array","from","values","map","category","label","filter","toLowerCase","includes","sort","a","b","localeCompare","handleChange","termNames","uniqueTerms","reduce","terms","newTerm","some","term","push","createElement","className","value","onInputChange","tokenizeOnBlur","__experimentalExpandOnFocus","__next40pxDefaultSize","__nextHasNoMarginBottom"],"sources":["@wordpress/patterns/src/components/category-selector.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useMemo, useState } from '@wordpress/element';\nimport { FormTokenField } from '@wordpress/components';\nimport { useDebounce } from '@wordpress/compose';\nimport { decodeEntities } from '@wordpress/html-entities';\n\nconst unescapeString = ( arg ) => {\n\treturn decodeEntities( arg );\n};\n\nexport const CATEGORY_SLUG = 'wp_pattern_category';\n\nexport default function CategorySelector( {\n\tcategoryTerms,\n\tonChange,\n\tcategoryMap,\n} ) {\n\tconst [ search, setSearch ] = useState( '' );\n\tconst debouncedSearch = useDebounce( setSearch, 500 );\n\n\tconst suggestions = useMemo( () => {\n\t\treturn Array.from( categoryMap.values() )\n\t\t\t.map( ( category ) => unescapeString( category.label ) )\n\t\t\t.filter( ( category ) => {\n\t\t\t\tif ( search !== '' ) {\n\t\t\t\t\treturn category\n\t\t\t\t\t\t.toLowerCase()\n\t\t\t\t\t\t.includes( search.toLowerCase() );\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t} )\n\t\t\t.sort( ( a, b ) => a.localeCompare( b ) );\n\t}, [ search, categoryMap ] );\n\n\tfunction handleChange( termNames ) {\n\t\tconst uniqueTerms = termNames.reduce( ( terms, newTerm ) => {\n\t\t\tif (\n\t\t\t\t! terms.some(\n\t\t\t\t\t( term ) => term.toLowerCase() === newTerm.toLowerCase()\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tterms.push( newTerm );\n\t\t\t}\n\t\t\treturn terms;\n\t\t}, [] );\n\n\t\tonChange( uniqueTerms );\n\t}\n\n\treturn (\n\t\t<FormTokenField\n\t\t\tclassName=\"patterns-menu-items__convert-modal-categories\"\n\t\t\tvalue={ categoryTerms }\n\t\t\tsuggestions={ suggestions }\n\t\t\tonChange={ handleChange }\n\t\t\tonInputChange={ debouncedSearch }\n\t\t\tlabel={ __( 'Categories' ) }\n\t\t\ttokenizeOnBlur\n\t\t\t__experimentalExpandOnFocus\n\t\t\t__next40pxDefaultSize\n\t\t\t__nextHasNoMarginBottom\n\t\t/>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,OAAO,EAAEC,QAAQ,QAAQ,oBAAoB;AACtD,SAASC,cAAc,QAAQ,uBAAuB;AACtD,SAASC,WAAW,QAAQ,oBAAoB;AAChD,SAASC,cAAc,QAAQ,0BAA0B;AAEzD,MAAMC,cAAc,GAAKC,GAAG,IAAM;EACjC,OAAOF,cAAc,CAAEE,GAAI,CAAC;AAC7B,CAAC;AAED,OAAO,MAAMC,aAAa,GAAG,qBAAqB;AAElD,eAAe,SAASC,gBAAgBA,CAAE;EACzCC,aAAa;EACbC,QAAQ;EACRC;AACD,CAAC,EAAG;EACH,MAAM,CAAEC,MAAM,EAAEC,SAAS,CAAE,GAAGZ,QAAQ,CAAE,EAAG,CAAC;EAC5C,MAAMa,eAAe,GAAGX,WAAW,CAAEU,SAAS,EAAE,GAAI,CAAC;EAErD,MAAME,WAAW,GAAGf,OAAO,CAAE,MAAM;IAClC,OAAOgB,KAAK,CAACC,IAAI,CAAEN,WAAW,CAACO,MAAM,CAAC,CAAE,CAAC,CACvCC,GAAG,CAAIC,QAAQ,IAAMf,cAAc,CAAEe,QAAQ,CAACC,KAAM,CAAE,CAAC,CACvDC,MAAM,CAAIF,QAAQ,IAAM;MACxB,IAAKR,MAAM,KAAK,EAAE,EAAG;QACpB,OAAOQ,QAAQ,CACbG,WAAW,CAAC,CAAC,CACbC,QAAQ,CAAEZ,MAAM,CAACW,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,CAAEf,MAAM,EAAED,WAAW,CAAG,CAAC;EAE5B,SAASkB,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;IAEPvB,QAAQ,CAAEqB,WAAY,CAAC;EACxB;EAEA,OACCO,aAAA,CAACpC,cAAc;IACdqC,SAAS,EAAC,+CAA+C;IACzDC,KAAK,EAAG/B,aAAe;IACvBM,WAAW,EAAGA,WAAa;IAC3BL,QAAQ,EAAGmB,YAAc;IACzBY,aAAa,EAAG3B,eAAiB;IACjCO,KAAK,EAAGtB,EAAE,CAAE,YAAa,CAAG;IAC5B2C,cAAc;IACdC,2BAA2B;IAC3BC,qBAAqB;IACrBC,uBAAuB;EAAA,CACvB,CAAC;AAEJ"}
|
|
@@ -145,19 +145,20 @@ export default function CreatePatternModal({
|
|
|
145
145
|
}, createElement(VStack, {
|
|
146
146
|
spacing: "5"
|
|
147
147
|
}, createElement(TextControl, {
|
|
148
|
-
__nextHasNoMarginBottom: true,
|
|
149
148
|
label: __('Name'),
|
|
150
149
|
value: title,
|
|
151
150
|
onChange: setTitle,
|
|
152
151
|
placeholder: __('My pattern'),
|
|
153
|
-
className: "patterns-create-modal__name-input"
|
|
152
|
+
className: "patterns-create-modal__name-input",
|
|
153
|
+
__nextHasNoMarginBottom: true,
|
|
154
|
+
__next40pxDefaultSize: true
|
|
154
155
|
}), createElement(CategorySelector, {
|
|
155
156
|
categoryTerms: categoryTerms,
|
|
156
157
|
onChange: setCategoryTerms,
|
|
157
158
|
categoryMap: categoryMap
|
|
158
159
|
}), createElement(ToggleControl, {
|
|
159
160
|
label: _x('Synced', 'Option that makes an individual pattern synchronized'),
|
|
160
|
-
help: __('
|
|
161
|
+
help: __('Sync this pattern across multiple locations.'),
|
|
161
162
|
checked: syncType === PATTERN_SYNC_TYPES.full,
|
|
162
163
|
onChange: () => {
|
|
163
164
|
setSyncType(syncType === PATTERN_SYNC_TYPES.full ? PATTERN_SYNC_TYPES.unsynced : PATTERN_SYNC_TYPES.full);
|
|
@@ -165,12 +166,14 @@ export default function CreatePatternModal({
|
|
|
165
166
|
}), createElement(HStack, {
|
|
166
167
|
justify: "right"
|
|
167
168
|
}, createElement(Button, {
|
|
169
|
+
__next40pxDefaultSize: true,
|
|
168
170
|
variant: "tertiary",
|
|
169
171
|
onClick: () => {
|
|
170
172
|
onClose();
|
|
171
173
|
setTitle('');
|
|
172
174
|
}
|
|
173
175
|
}, __('Cancel')), createElement(Button, {
|
|
176
|
+
__next40pxDefaultSize: true,
|
|
174
177
|
variant: "primary",
|
|
175
178
|
type: "submit",
|
|
176
179
|
"aria-disabled": !title || isSaving,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Modal","Button","TextControl","__experimentalHStack","HStack","__experimentalVStack","VStack","ToggleControl","__","_x","useState","useMemo","useDispatch","useSelect","store","noticesStore","coreStore","PATTERN_DEFAULT_CATEGORY","PATTERN_SYNC_TYPES","patternsStore","CategorySelector","CATEGORY_SLUG","unlock","CreatePatternModal","confirmLabel","defaultCategories","className","content","modalTitle","onClose","onError","onSuccess","defaultSyncType","full","defaultTitle","syncType","setSyncType","categoryTerms","setCategoryTerms","title","setTitle","isSaving","setIsSaving","createPattern","saveEntityRecord","invalidateResolution","createErrorNotice","corePatternCategories","userPatternCategories","select","getUserPatternCategories","getBlockPatternCategories","categoryMap","uniqueCategories","Map","forEach","category","has","label","name","set","value","onCreate","patternTitle","sync","categories","Promise","all","map","termName","findOrCreateTerm","newPattern","pattern","categoryId","error","message","type","id","term","existingTerm","get","termData","slug","newTerm","throwOnError","code","data","term_id","createElement","onRequestClose","overlayClassName","onSubmit","event","preventDefault","spacing","__nextHasNoMarginBottom","onChange","placeholder","help","checked","unsynced","justify","variant","onClick","isBusy"],"sources":["@wordpress/patterns/src/components/create-pattern-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tModal,\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tToggleControl,\n} from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport { useState, useMemo } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_DEFAULT_CATEGORY, PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CategorySelector, { CATEGORY_SLUG } from './category-selector';\nimport { unlock } from '../lock-unlock';\n\nexport default function CreatePatternModal( {\n\tconfirmLabel = __( 'Create' ),\n\tdefaultCategories = [],\n\tclassName = 'patterns-menu-items__convert-modal',\n\tcontent,\n\tmodalTitle = __( 'Create pattern' ),\n\tonClose,\n\tonError,\n\tonSuccess,\n\tdefaultSyncType = PATTERN_SYNC_TYPES.full,\n\tdefaultTitle = '',\n} ) {\n\tconst [ syncType, setSyncType ] = useState( defaultSyncType );\n\tconst [ categoryTerms, setCategoryTerms ] = useState( defaultCategories );\n\tconst [ title, setTitle ] = useState( defaultTitle );\n\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\tconst { createPattern } = unlock( useDispatch( patternsStore ) );\n\tconst { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tconst { corePatternCategories, userPatternCategories } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getUserPatternCategories, getBlockPatternCategories } =\n\t\t\t\tselect( coreStore );\n\n\t\t\treturn {\n\t\t\t\tcorePatternCategories: getBlockPatternCategories(),\n\t\t\t\tuserPatternCategories: getUserPatternCategories(),\n\t\t\t};\n\t\t}\n\t);\n\n\tconst categoryMap = useMemo( () => {\n\t\t// Merge the user and core pattern categories and remove any duplicates.\n\t\tconst uniqueCategories = new Map();\n\t\t[ ...userPatternCategories, ...corePatternCategories ].forEach(\n\t\t\t( category ) => {\n\t\t\t\tif (\n\t\t\t\t\t! uniqueCategories.has( category.label ) &&\n\t\t\t\t\t// There are two core categories with `Post` label so explicitly remove the one with\n\t\t\t\t\t// the `query` slug to avoid any confusion.\n\t\t\t\t\tcategory.name !== 'query'\n\t\t\t\t) {\n\t\t\t\t\t// We need to store the name separately as this is used as the slug in the\n\t\t\t\t\t// taxonomy and may vary from the label.\n\t\t\t\t\tuniqueCategories.set( category.label, {\n\t\t\t\t\t\tlabel: category.label,\n\t\t\t\t\t\tvalue: category.label,\n\t\t\t\t\t\tname: category.name,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t\treturn uniqueCategories;\n\t}, [ userPatternCategories, corePatternCategories ] );\n\n\tasync function onCreate( patternTitle, sync ) {\n\t\tif ( ! title || isSaving ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSaving( true );\n\t\t\tconst categories = await Promise.all(\n\t\t\t\tcategoryTerms.map( ( termName ) =>\n\t\t\t\t\tfindOrCreateTerm( termName )\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tconst newPattern = await createPattern(\n\t\t\t\tpatternTitle,\n\t\t\t\tsync,\n\t\t\t\ttypeof content === 'function' ? content() : content,\n\t\t\t\tcategories\n\t\t\t);\n\t\t\tonSuccess( {\n\t\t\t\tpattern: newPattern,\n\t\t\t\tcategoryId: PATTERN_DEFAULT_CATEGORY,\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-create',\n\t\t\t} );\n\t\t\tonError?.();\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t\tsetCategoryTerms( [] );\n\t\t\tsetTitle( '' );\n\t\t}\n\t}\n\n\t/**\n\t * @param {string} term\n\t * @return {Promise<number>} The pattern category id.\n\t */\n\tasync function findOrCreateTerm( term ) {\n\t\ttry {\n\t\t\t// We need to match any existing term to the correct slug to prevent duplicates, eg.\n\t\t\t// the core `Headers` category uses the singular `header` as the slug.\n\t\t\tconst existingTerm = categoryMap.get( term );\n\t\t\tconst termData = existingTerm\n\t\t\t\t? { name: existingTerm.label, slug: existingTerm.name }\n\t\t\t\t: { name: term };\n\t\t\tconst newTerm = await saveEntityRecord(\n\t\t\t\t'taxonomy',\n\t\t\t\tCATEGORY_SLUG,\n\t\t\t\ttermData,\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tinvalidateResolution( 'getUserPatternCategories' );\n\t\t\treturn newTerm.id;\n\t\t} catch ( error ) {\n\t\t\tif ( error.code !== 'term_exists' ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn error.data.term_id;\n\t\t}\n\t}\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle }\n\t\t\tonRequestClose={ () => {\n\t\t\t\tonClose();\n\t\t\t\tsetTitle( '' );\n\t\t\t} }\n\t\t\toverlayClassName={ className }\n\t\t>\n\t\t\t<form\n\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tonCreate( title, syncType );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\tplaceholder={ __( 'My pattern' ) }\n\t\t\t\t\t\tclassName=\"patterns-create-modal__name-input\"\n\t\t\t\t\t/>\n\t\t\t\t\t<CategorySelector\n\t\t\t\t\t\tcategoryTerms={ categoryTerms }\n\t\t\t\t\t\tonChange={ setCategoryTerms }\n\t\t\t\t\t\tcategoryMap={ categoryMap }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t\t'Synced',\n\t\t\t\t\t\t\t'Option that makes an individual pattern synchronized'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Editing the pattern will update it anywhere it is used.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ syncType === PATTERN_SYNC_TYPES.full }\n\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\tsyncType === PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t\t\t? PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t\t\t\t\t\t: PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"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D,EAAE,CACT,QAAQ,EACR,sDACD,CAAG;IACHyF,IAAI,EAAG1F,EAAE,CACR,yDACD,CAAG;IACH2F,OAAO,EAAGhE,QAAQ,KAAKjB,kBAAkB,CAACe,IAAM;IAChD+D,QAAQ,EAAGA,CAAA,KAAM;MAChB5D,WAAW,CACVD,QAAQ,KAAKjB,kBAAkB,CAACe,IAAI,GACjCf,kBAAkB,CAACkF,QAAQ,GAC3BlF,kBAAkB,CAACe,IACvB,CAAC;IACF;EAAG,CACH,CAAC,EACFuD,aAAA,CAACpF,MAAM;IAACiG,OAAO,EAAC;EAAO,GACtBb,aAAA,CAACvF,MAAM;IACNqG,OAAO,EAAC,UAAU;IAClBC,OAAO,EAAGA,CAAA,KAAM;MACf1E,OAAO,CAAC,CAAC;MACTW,QAAQ,CAAE,EAAG,CAAC;IACf;EAAG,GAEDhC,EAAE,CAAE,QAAS,CACR,CAAC,EAETgF,aAAA,CAACvF,MAAM;IACNqG,OAAO,EAAC,SAAS;IACjB1B,IAAI,EAAC,QAAQ;IACb,iBAAgB,CAAErC,KAAK,IAAIE,QAAU;IACrC+D,MAAM,EAAG/D;EAAU,GAEjBjB,YACK,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
1
|
+
{"version":3,"names":["Modal","Button","TextControl","__experimentalHStack","HStack","__experimentalVStack","VStack","ToggleControl","__","_x","useState","useMemo","useDispatch","useSelect","store","noticesStore","coreStore","PATTERN_DEFAULT_CATEGORY","PATTERN_SYNC_TYPES","patternsStore","CategorySelector","CATEGORY_SLUG","unlock","CreatePatternModal","confirmLabel","defaultCategories","className","content","modalTitle","onClose","onError","onSuccess","defaultSyncType","full","defaultTitle","syncType","setSyncType","categoryTerms","setCategoryTerms","title","setTitle","isSaving","setIsSaving","createPattern","saveEntityRecord","invalidateResolution","createErrorNotice","corePatternCategories","userPatternCategories","select","getUserPatternCategories","getBlockPatternCategories","categoryMap","uniqueCategories","Map","forEach","category","has","label","name","set","value","onCreate","patternTitle","sync","categories","Promise","all","map","termName","findOrCreateTerm","newPattern","pattern","categoryId","error","message","type","id","term","existingTerm","get","termData","slug","newTerm","throwOnError","code","data","term_id","createElement","onRequestClose","overlayClassName","onSubmit","event","preventDefault","spacing","onChange","placeholder","__nextHasNoMarginBottom","__next40pxDefaultSize","help","checked","unsynced","justify","variant","onClick","isBusy"],"sources":["@wordpress/patterns/src/components/create-pattern-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tModal,\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tToggleControl,\n} from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\nimport { useState, useMemo } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_DEFAULT_CATEGORY, PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CategorySelector, { CATEGORY_SLUG } from './category-selector';\nimport { unlock } from '../lock-unlock';\n\nexport default function CreatePatternModal( {\n\tconfirmLabel = __( 'Create' ),\n\tdefaultCategories = [],\n\tclassName = 'patterns-menu-items__convert-modal',\n\tcontent,\n\tmodalTitle = __( 'Create pattern' ),\n\tonClose,\n\tonError,\n\tonSuccess,\n\tdefaultSyncType = PATTERN_SYNC_TYPES.full,\n\tdefaultTitle = '',\n} ) {\n\tconst [ syncType, setSyncType ] = useState( defaultSyncType );\n\tconst [ categoryTerms, setCategoryTerms ] = useState( defaultCategories );\n\tconst [ title, setTitle ] = useState( defaultTitle );\n\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\tconst { createPattern } = unlock( useDispatch( patternsStore ) );\n\tconst { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tconst { corePatternCategories, userPatternCategories } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getUserPatternCategories, getBlockPatternCategories } =\n\t\t\t\tselect( coreStore );\n\n\t\t\treturn {\n\t\t\t\tcorePatternCategories: getBlockPatternCategories(),\n\t\t\t\tuserPatternCategories: getUserPatternCategories(),\n\t\t\t};\n\t\t}\n\t);\n\n\tconst categoryMap = useMemo( () => {\n\t\t// Merge the user and core pattern categories and remove any duplicates.\n\t\tconst uniqueCategories = new Map();\n\t\t[ ...userPatternCategories, ...corePatternCategories ].forEach(\n\t\t\t( category ) => {\n\t\t\t\tif (\n\t\t\t\t\t! uniqueCategories.has( category.label ) &&\n\t\t\t\t\t// There are two core categories with `Post` label so explicitly remove the one with\n\t\t\t\t\t// the `query` slug to avoid any confusion.\n\t\t\t\t\tcategory.name !== 'query'\n\t\t\t\t) {\n\t\t\t\t\t// We need to store the name separately as this is used as the slug in the\n\t\t\t\t\t// taxonomy and may vary from the label.\n\t\t\t\t\tuniqueCategories.set( category.label, {\n\t\t\t\t\t\tlabel: category.label,\n\t\t\t\t\t\tvalue: category.label,\n\t\t\t\t\t\tname: category.name,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t\treturn uniqueCategories;\n\t}, [ userPatternCategories, corePatternCategories ] );\n\n\tasync function onCreate( patternTitle, sync ) {\n\t\tif ( ! title || isSaving ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSaving( true );\n\t\t\tconst categories = await Promise.all(\n\t\t\t\tcategoryTerms.map( ( termName ) =>\n\t\t\t\t\tfindOrCreateTerm( termName )\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tconst newPattern = await createPattern(\n\t\t\t\tpatternTitle,\n\t\t\t\tsync,\n\t\t\t\ttypeof content === 'function' ? content() : content,\n\t\t\t\tcategories\n\t\t\t);\n\t\t\tonSuccess( {\n\t\t\t\tpattern: newPattern,\n\t\t\t\tcategoryId: PATTERN_DEFAULT_CATEGORY,\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'pattern-create',\n\t\t\t} );\n\t\t\tonError?.();\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t\tsetCategoryTerms( [] );\n\t\t\tsetTitle( '' );\n\t\t}\n\t}\n\n\t/**\n\t * @param {string} term\n\t * @return {Promise<number>} The pattern category id.\n\t */\n\tasync function findOrCreateTerm( term ) {\n\t\ttry {\n\t\t\t// We need to match any existing term to the correct slug to prevent duplicates, eg.\n\t\t\t// the core `Headers` category uses the singular `header` as the slug.\n\t\t\tconst existingTerm = categoryMap.get( term );\n\t\t\tconst termData = existingTerm\n\t\t\t\t? { name: existingTerm.label, slug: existingTerm.name }\n\t\t\t\t: { name: term };\n\t\t\tconst newTerm = await saveEntityRecord(\n\t\t\t\t'taxonomy',\n\t\t\t\tCATEGORY_SLUG,\n\t\t\t\ttermData,\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tinvalidateResolution( 'getUserPatternCategories' );\n\t\t\treturn newTerm.id;\n\t\t} catch ( error ) {\n\t\t\tif ( error.code !== 'term_exists' ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn error.data.term_id;\n\t\t}\n\t}\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle }\n\t\t\tonRequestClose={ () => {\n\t\t\t\tonClose();\n\t\t\t\tsetTitle( '' );\n\t\t\t} }\n\t\t\toverlayClassName={ className }\n\t\t>\n\t\t\t<form\n\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tonCreate( title, syncType );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\tplaceholder={ __( 'My pattern' ) }\n\t\t\t\t\t\tclassName=\"patterns-create-modal__name-input\"\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t/>\n\t\t\t\t\t<CategorySelector\n\t\t\t\t\t\tcategoryTerms={ categoryTerms }\n\t\t\t\t\t\tonChange={ setCategoryTerms }\n\t\t\t\t\t\tcategoryMap={ categoryMap }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t\t'Synced',\n\t\t\t\t\t\t\t'Option that makes an individual pattern synchronized'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Sync this pattern across multiple locations.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ syncType === PATTERN_SYNC_TYPES.full }\n\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\tsyncType === PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t\t\t? PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t\t\t\t\t\t: PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\taria-disabled={ ! title || isSa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QAAQ,EACR,sDACD,CAAG;IACH0F,IAAI,EAAG3F,EAAE,CACR,8CACD,CAAG;IACH4F,OAAO,EAAGjE,QAAQ,KAAKjB,kBAAkB,CAACe,IAAM;IAChD8D,QAAQ,EAAGA,CAAA,KAAM;MAChB3D,WAAW,CACVD,QAAQ,KAAKjB,kBAAkB,CAACe,IAAI,GACjCf,kBAAkB,CAACmF,QAAQ,GAC3BnF,kBAAkB,CAACe,IACvB,CAAC;IACF;EAAG,CACH,CAAC,EACFuD,aAAA,CAACpF,MAAM;IAACkG,OAAO,EAAC;EAAO,GACtBd,aAAA,CAACvF,MAAM;IACNiG,qBAAqB;IACrBK,OAAO,EAAC,UAAU;IAClBC,OAAO,EAAGA,CAAA,KAAM;MACf3E,OAAO,CAAC,CAAC;MACTW,QAAQ,CAAE,EAAG,CAAC;IACf;EAAG,GAEDhC,EAAE,CAAE,QAAS,CACR,CAAC,EAETgF,aAAA,CAACvF,MAAM;IACNiG,qBAAqB;IACrBK,OAAO,EAAC,SAAS;IACjB3B,IAAI,EAAC,QAAQ;IACb,iBAAgB,CAAErC,KAAK,IAAIE,QAAU;IACrCgE,MAAM,EAAGhE;EAAU,GAEjBjB,YACK,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
@@ -11,10 +11,10 @@ import { store as noticesStore } from '@wordpress/notices';
|
|
|
11
11
|
* Internal dependencies
|
|
12
12
|
*/
|
|
13
13
|
import CreatePatternModal from './create-pattern-modal';
|
|
14
|
-
import { PATTERN_SYNC_TYPES } from '../constants';
|
|
14
|
+
import { PATTERN_SYNC_TYPES, PATTERN_TYPES } from '../constants';
|
|
15
15
|
function getTermLabels(pattern, categories) {
|
|
16
|
-
// Theme patterns
|
|
17
|
-
if (
|
|
16
|
+
// Theme patterns rely on core pattern categories.
|
|
17
|
+
if (pattern.type !== PATTERN_TYPES.user) {
|
|
18
18
|
return categories.core?.filter(category => pattern.categories.includes(category.name)).map(category => category.label);
|
|
19
19
|
}
|
|
20
20
|
return categories.user?.filter(category => pattern.wp_pattern_category.includes(category.id)).map(category => category.label);
|
|
@@ -43,7 +43,7 @@ export default function DuplicatePatternModal({
|
|
|
43
43
|
const duplicatedProps = {
|
|
44
44
|
content: pattern.content,
|
|
45
45
|
defaultCategories: getTermLabels(pattern, categories),
|
|
46
|
-
defaultSyncType:
|
|
46
|
+
defaultSyncType: pattern.type !== PATTERN_TYPES.user // Theme patterns are unsynced by default.
|
|
47
47
|
? PATTERN_SYNC_TYPES.unsynced : pattern.wp_pattern_sync_status || PATTERN_SYNC_TYPES.full,
|
|
48
48
|
defaultTitle: sprintf( /* translators: %s: Existing pattern title */
|
|
49
49
|
__('%s (Copy)'), typeof pattern.title === 'string' ? pattern.title : pattern.title.raw)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["store","coreStore","useDispatch","useSelect","__","sprintf","noticesStore","CreatePatternModal","PATTERN_SYNC_TYPES","getTermLabels","pattern","categories","
|
|
1
|
+
{"version":3,"names":["store","coreStore","useDispatch","useSelect","__","sprintf","noticesStore","CreatePatternModal","PATTERN_SYNC_TYPES","PATTERN_TYPES","getTermLabels","pattern","categories","type","user","core","filter","category","includes","name","map","label","wp_pattern_category","id","DuplicatePatternModal","onClose","onSuccess","createSuccessNotice","select","getUserPatternCategories","getBlockPatternCategories","duplicatedProps","content","defaultCategories","defaultSyncType","unsynced","wp_pattern_sync_status","full","defaultTitle","title","raw","handleOnSuccess","newPattern","createElement","modalTitle","confirmLabel","onError"],"sources":["@wordpress/patterns/src/components/duplicate-pattern-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport CreatePatternModal from './create-pattern-modal';\nimport { PATTERN_SYNC_TYPES, PATTERN_TYPES } from '../constants';\n\nfunction getTermLabels( pattern, categories ) {\n\t// Theme patterns rely on core pattern categories.\n\tif ( pattern.type !== PATTERN_TYPES.user ) {\n\t\treturn categories.core\n\t\t\t?.filter( ( category ) =>\n\t\t\t\tpattern.categories.includes( category.name )\n\t\t\t)\n\t\t\t.map( ( category ) => category.label );\n\t}\n\n\treturn categories.user\n\t\t?.filter( ( category ) =>\n\t\t\tpattern.wp_pattern_category.includes( category.id )\n\t\t)\n\t\t.map( ( category ) => category.label );\n}\n\nexport default function DuplicatePatternModal( {\n\tpattern,\n\tonClose,\n\tonSuccess,\n} ) {\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst categories = useSelect( ( select ) => {\n\t\tconst { getUserPatternCategories, getBlockPatternCategories } =\n\t\t\tselect( coreStore );\n\n\t\treturn {\n\t\t\tcore: getBlockPatternCategories(),\n\t\t\tuser: getUserPatternCategories(),\n\t\t};\n\t} );\n\n\tif ( ! pattern ) {\n\t\treturn null;\n\t}\n\n\tconst duplicatedProps = {\n\t\tcontent: pattern.content,\n\t\tdefaultCategories: getTermLabels( pattern, categories ),\n\t\tdefaultSyncType:\n\t\t\tpattern.type !== PATTERN_TYPES.user // Theme patterns are unsynced by default.\n\t\t\t\t? PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t: pattern.wp_pattern_sync_status || PATTERN_SYNC_TYPES.full,\n\t\tdefaultTitle: sprintf(\n\t\t\t/* translators: %s: Existing pattern title */\n\t\t\t__( '%s (Copy)' ),\n\t\t\ttypeof pattern.title === 'string'\n\t\t\t\t? pattern.title\n\t\t\t\t: pattern.title.raw\n\t\t),\n\t};\n\n\tfunction handleOnSuccess( { pattern: newPattern } ) {\n\t\tcreateSuccessNotice(\n\t\t\tsprintf(\n\t\t\t\t// translators: %s: The new pattern's title e.g. 'Call to action (copy)'.\n\t\t\t\t__( '\"%s\" duplicated.' ),\n\t\t\t\tnewPattern.title.raw\n\t\t\t),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'patterns-create',\n\t\t\t}\n\t\t);\n\n\t\tonSuccess?.( { pattern: newPattern } );\n\t}\n\n\treturn (\n\t\t<CreatePatternModal\n\t\t\tmodalTitle={ __( 'Duplicate pattern' ) }\n\t\t\tconfirmLabel={ __( 'Duplicate' ) }\n\t\t\tonClose={ onClose }\n\t\t\tonError={ onClose }\n\t\t\tonSuccess={ handleOnSuccess }\n\t\t\t{ ...duplicatedProps }\n\t\t/>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASL,KAAK,IAAIM,YAAY,QAAQ,oBAAoB;;AAE1D;AACA;AACA;AACA,OAAOC,kBAAkB,MAAM,wBAAwB;AACvD,SAASC,kBAAkB,EAAEC,aAAa,QAAQ,cAAc;AAEhE,SAASC,aAAaA,CAAEC,OAAO,EAAEC,UAAU,EAAG;EAC7C;EACA,IAAKD,OAAO,CAACE,IAAI,KAAKJ,aAAa,CAACK,IAAI,EAAG;IAC1C,OAAOF,UAAU,CAACG,IAAI,EACnBC,MAAM,CAAIC,QAAQ,IACnBN,OAAO,CAACC,UAAU,CAACM,QAAQ,CAAED,QAAQ,CAACE,IAAK,CAC5C,CAAC,CACAC,GAAG,CAAIH,QAAQ,IAAMA,QAAQ,CAACI,KAAM,CAAC;EACxC;EAEA,OAAOT,UAAU,CAACE,IAAI,EACnBE,MAAM,CAAIC,QAAQ,IACnBN,OAAO,CAACW,mBAAmB,CAACJ,QAAQ,CAAED,QAAQ,CAACM,EAAG,CACnD,CAAC,CACAH,GAAG,CAAIH,QAAQ,IAAMA,QAAQ,CAACI,KAAM,CAAC;AACxC;AAEA,eAAe,SAASG,qBAAqBA,CAAE;EAC9Cb,OAAO;EACPc,OAAO;EACPC;AACD,CAAC,EAAG;EACH,MAAM;IAAEC;EAAoB,CAAC,GAAGzB,WAAW,CAA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EAAE,CAAE,WAAY,CAAG;IAClCqB,OAAO,EAAGA,OAAS;IACnBqB,OAAO,EAAGrB,OAAS;IACnBC,SAAS,EAAGe,eAAiB;IAAA,GACxBV;EAAe,CACpB,CAAC;AAEJ"}
|
|
@@ -13,10 +13,12 @@ export default function PatternsMenuItems({
|
|
|
13
13
|
rootClientId
|
|
14
14
|
}) {
|
|
15
15
|
return createElement(BlockSettingsMenuControls, null, ({
|
|
16
|
-
selectedClientIds
|
|
16
|
+
selectedClientIds,
|
|
17
|
+
onClose
|
|
17
18
|
}) => createElement(Fragment, null, createElement(PatternConvertButton, {
|
|
18
19
|
clientIds: selectedClientIds,
|
|
19
|
-
rootClientId: rootClientId
|
|
20
|
+
rootClientId: rootClientId,
|
|
21
|
+
closeBlockSettingsMenu: onClose
|
|
20
22
|
}), selectedClientIds.length === 1 && createElement(PatternsManageButton, {
|
|
21
23
|
clientId: selectedClientIds[0]
|
|
22
24
|
})));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BlockSettingsMenuControls","PatternConvertButton","PatternsManageButton","PatternsMenuItems","rootClientId","createElement","selectedClientIds","Fragment","clientIds","length","clientId"],"sources":["@wordpress/patterns/src/components/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { BlockSettingsMenuControls } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport PatternConvertButton from './pattern-convert-button';\nimport PatternsManageButton from './patterns-manage-button';\n\nexport default function PatternsMenuItems( { rootClientId } ) {\n\treturn (\n\t\t<BlockSettingsMenuControls>\n\t\t\t{ ( { selectedClientIds } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<PatternConvertButton\n\t\t\t\t\t\tclientIds={ selectedClientIds }\n\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t/>\n\t\t\t\t\t{ selectedClientIds.length === 1 && (\n\t\t\t\t\t\t<PatternsManageButton\n\t\t\t\t\t\t\tclientId={ selectedClientIds[ 0 ] }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\t\t</BlockSettingsMenuControls>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,yBAAyB,QAAQ,yBAAyB;;AAEnE;AACA;AACA;AACA,OAAOC,oBAAoB,MAAM,0BAA0B;AAC3D,OAAOC,oBAAoB,MAAM,0BAA0B;AAE3D,eAAe,SAASC,iBAAiBA,CAAE;EAAEC;AAAa,CAAC,EAAG;EAC7D,OACCC,aAAA,CAACL,yBAAyB,QACvB,CAAE;IAAEM;
|
|
1
|
+
{"version":3,"names":["BlockSettingsMenuControls","PatternConvertButton","PatternsManageButton","PatternsMenuItems","rootClientId","createElement","selectedClientIds","onClose","Fragment","clientIds","closeBlockSettingsMenu","length","clientId"],"sources":["@wordpress/patterns/src/components/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { BlockSettingsMenuControls } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport PatternConvertButton from './pattern-convert-button';\nimport PatternsManageButton from './patterns-manage-button';\n\nexport default function PatternsMenuItems( { rootClientId } ) {\n\treturn (\n\t\t<BlockSettingsMenuControls>\n\t\t\t{ ( { selectedClientIds, onClose } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<PatternConvertButton\n\t\t\t\t\t\tclientIds={ selectedClientIds }\n\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\tcloseBlockSettingsMenu={ onClose }\n\t\t\t\t\t/>\n\t\t\t\t\t{ selectedClientIds.length === 1 && (\n\t\t\t\t\t\t<PatternsManageButton\n\t\t\t\t\t\t\tclientId={ selectedClientIds[ 0 ] }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\t\t</BlockSettingsMenuControls>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,yBAAyB,QAAQ,yBAAyB;;AAEnE;AACA;AACA;AACA,OAAOC,oBAAoB,MAAM,0BAA0B;AAC3D,OAAOC,oBAAoB,MAAM,0BAA0B;AAE3D,eAAe,SAASC,iBAAiBA,CAAE;EAAEC;AAAa,CAAC,EAAG;EAC7D,OACCC,aAAA,CAACL,yBAAyB,QACvB,CAAE;IAAEM,iBAAiB;IAAEC;EAAQ,CAAC,KACjCF,aAAA,CAAAG,QAAA,QACCH,aAAA,CAACJ,oBAAoB;IACpBQ,SAAS,EAAGH,iBAAmB;IAC/BF,YAAY,EAAGA,YAAc;IAC7BM,sBAAsB,EAAGH;EAAS,CAClC,CAAC,EACAD,iBAAiB,CAACK,MAAM,KAAK,CAAC,IAC/BN,aAAA,CAACH,oBAAoB;IACpBU,QAAQ,EAAGN,iBAAiB,CAAE,CAAC;EAAI,CACnC,CAED,CAEuB,CAAC;AAE9B"}
|
|
@@ -22,14 +22,16 @@ import { PATTERN_SYNC_TYPES } from '../constants';
|
|
|
22
22
|
/**
|
|
23
23
|
* Menu control to convert block(s) to a pattern block.
|
|
24
24
|
*
|
|
25
|
-
* @param {Object} props
|
|
26
|
-
* @param {string[]} props.clientIds
|
|
27
|
-
* @param {string} props.rootClientId
|
|
25
|
+
* @param {Object} props Component props.
|
|
26
|
+
* @param {string[]} props.clientIds Client ids of selected blocks.
|
|
27
|
+
* @param {string} props.rootClientId ID of the currently selected top-level block.
|
|
28
|
+
* @param {()=>void} props.closeBlockSettingsMenu Callback to close the block settings menu dropdown.
|
|
28
29
|
* @return {import('react').ComponentType} The menu control or null.
|
|
29
30
|
*/
|
|
30
31
|
export default function PatternConvertButton({
|
|
31
32
|
clientIds,
|
|
32
|
-
rootClientId
|
|
33
|
+
rootClientId,
|
|
34
|
+
closeBlockSettingsMenu
|
|
33
35
|
}) {
|
|
34
36
|
const {
|
|
35
37
|
createSuccessNotice
|
|
@@ -87,6 +89,7 @@ export default function PatternConvertButton({
|
|
|
87
89
|
});
|
|
88
90
|
replaceBlocks(clientIds, newBlock);
|
|
89
91
|
setEditingPattern(newBlock.clientId, true);
|
|
92
|
+
closeBlockSettingsMenu();
|
|
90
93
|
}
|
|
91
94
|
createSuccessNotice(pattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced ? sprintf(
|
|
92
95
|
// translators: %s: the name the user has given to the pattern.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["hasBlockSupport","isReusableBlock","createBlock","serialize","store","blockEditorStore","useState","useCallback","MenuItem","symbol","useSelect","useDispatch","coreStore","__","sprintf","noticesStore","patternsStore","CreatePatternModal","unlock","PATTERN_SYNC_TYPES","PatternConvertButton","clientIds","rootClientId","createSuccessNotice","replaceBlocks","setEditingPattern","isModalOpen","setIsModalOpen","canConvert","select","_getBlocksByClientId","canUser","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","rootId","length","undefined","blocks","isReusable","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","name","getContent","handleSuccess","pattern","wp_pattern_sync_status","unsynced","newBlock","id","clientId","title","raw","type","createElement","Fragment","icon","onClick","content","onSuccess","onError","onClose"],"sources":["@wordpress/patterns/src/components/pattern-convert-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\thasBlockSupport,\n\tisReusableBlock,\n\tcreateBlock,\n\tserialize,\n} from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useState, useCallback } from '@wordpress/element';\nimport { MenuItem } from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CreatePatternModal from './create-pattern-modal';\nimport { unlock } from '../lock-unlock';\nimport { PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Menu control to convert block(s) to a pattern block.\n *\n * @param {Object} props
|
|
1
|
+
{"version":3,"names":["hasBlockSupport","isReusableBlock","createBlock","serialize","store","blockEditorStore","useState","useCallback","MenuItem","symbol","useSelect","useDispatch","coreStore","__","sprintf","noticesStore","patternsStore","CreatePatternModal","unlock","PATTERN_SYNC_TYPES","PatternConvertButton","clientIds","rootClientId","closeBlockSettingsMenu","createSuccessNotice","replaceBlocks","setEditingPattern","isModalOpen","setIsModalOpen","canConvert","select","_getBlocksByClientId","canUser","getBlocksByClientId","canInsertBlockType","getBlockRootClientId","rootId","length","undefined","blocks","isReusable","getEntityRecord","attributes","ref","_canConvert","every","block","isValid","name","getContent","handleSuccess","pattern","wp_pattern_sync_status","unsynced","newBlock","id","clientId","title","raw","type","createElement","Fragment","icon","onClick","content","onSuccess","onError","onClose"],"sources":["@wordpress/patterns/src/components/pattern-convert-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\thasBlockSupport,\n\tisReusableBlock,\n\tcreateBlock,\n\tserialize,\n} from '@wordpress/blocks';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useState, useCallback } from '@wordpress/element';\nimport { MenuItem } from '@wordpress/components';\nimport { symbol } from '@wordpress/icons';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CreatePatternModal from './create-pattern-modal';\nimport { unlock } from '../lock-unlock';\nimport { PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Menu control to convert block(s) to a pattern block.\n *\n * @param {Object} props Component props.\n * @param {string[]} props.clientIds Client ids of selected blocks.\n * @param {string} props.rootClientId ID of the currently selected top-level block.\n * @param {()=>void} props.closeBlockSettingsMenu Callback to close the block settings menu dropdown.\n * @return {import('react').ComponentType} The menu control or null.\n */\nexport default function PatternConvertButton( {\n\tclientIds,\n\trootClientId,\n\tcloseBlockSettingsMenu,\n} ) {\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst { replaceBlocks } = useDispatch( blockEditorStore );\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { setEditingPattern } = unlock( useDispatch( patternsStore ) );\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst canConvert = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst {\n\t\t\t\tgetBlocksByClientId,\n\t\t\t\tcanInsertBlockType,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst rootId =\n\t\t\t\trootClientId ||\n\t\t\t\t( clientIds.length > 0\n\t\t\t\t\t? getBlockRootClientId( clientIds[ 0 ] )\n\t\t\t\t\t: undefined );\n\n\t\t\tconst blocks = getBlocksByClientId( clientIds ) ?? [];\n\n\t\t\tconst isReusable =\n\t\t\t\tblocks.length === 1 &&\n\t\t\t\tblocks[ 0 ] &&\n\t\t\t\tisReusableBlock( blocks[ 0 ] ) &&\n\t\t\t\t!! select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_block',\n\t\t\t\t\tblocks[ 0 ].attributes.ref\n\t\t\t\t);\n\n\t\t\tconst _canConvert =\n\t\t\t\t// Hide when this is already a synced pattern.\n\t\t\t\t! isReusable &&\n\t\t\t\t// Hide when patterns are disabled.\n\t\t\t\tcanInsertBlockType( 'core/block', rootId ) &&\n\t\t\t\tblocks.every(\n\t\t\t\t\t( block ) =>\n\t\t\t\t\t\t// Guard against the case where a regular block has *just* been converted.\n\t\t\t\t\t\t!! block &&\n\t\t\t\t\t\t// Hide on invalid blocks.\n\t\t\t\t\t\tblock.isValid &&\n\t\t\t\t\t\t// Hide when block doesn't support being made into a pattern.\n\t\t\t\t\t\thasBlockSupport( block.name, 'reusable', true )\n\t\t\t\t) &&\n\t\t\t\t// Hide when current doesn't have permission to do that.\n\t\t\t\t!! canUser( 'create', 'blocks' );\n\n\t\t\treturn _canConvert;\n\t\t},\n\t\t[ clientIds, rootClientId ]\n\t);\n\tconst { getBlocksByClientId } = useSelect( blockEditorStore );\n\tconst getContent = useCallback(\n\t\t() => serialize( getBlocksByClientId( clientIds ) ),\n\t\t[ getBlocksByClientId, clientIds ]\n\t);\n\n\tif ( ! canConvert ) {\n\t\treturn null;\n\t}\n\n\tconst handleSuccess = ( { pattern } ) => {\n\t\tif ( pattern.wp_pattern_sync_status !== PATTERN_SYNC_TYPES.unsynced ) {\n\t\t\tconst newBlock = createBlock( 'core/block', {\n\t\t\t\tref: pattern.id,\n\t\t\t} );\n\n\t\t\treplaceBlocks( clientIds, newBlock );\n\t\t\tsetEditingPattern( newBlock.clientId, true );\n\t\t\tcloseBlockSettingsMenu();\n\t\t}\n\n\t\tcreateSuccessNotice(\n\t\t\tpattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Unsynced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t// translators: %s: the name the user has given to the pattern.\n\t\t\t\t\t\t__( 'Synced pattern created: %s' ),\n\t\t\t\t\t\tpattern.title.raw\n\t\t\t\t ),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'convert-to-pattern-success',\n\t\t\t}\n\t\t);\n\t\tsetIsModalOpen( false );\n\t};\n\treturn (\n\t\t<>\n\t\t\t<MenuItem\n\t\t\t\ticon={ symbol }\n\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\taria-expanded={ isModalOpen }\n\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t>\n\t\t\t\t{ __( 'Create pattern' ) }\n\t\t\t</MenuItem>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<CreatePatternModal\n\t\t\t\t\tcontent={ getContent }\n\t\t\t\t\tonSuccess={ ( pattern ) => {\n\t\t\t\t\t\thandleSuccess( pattern );\n\t\t\t\t\t} }\n\t\t\t\t\tonError={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SACCA,eAAe,EACfC,eAAe,EACfC,WAAW,EACXC,SAAS,QACH,mBAAmB;AAC1B,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,QAAQ,EAAEC,WAAW,QAAQ,oBAAoB;AAC1D,SAASC,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,MAAM,QAAQ,kBAAkB;AACzC,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASP,KAAK,IAAIQ,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASV,KAAK,IAAIW,YAAY,QAAQ,oBAAoB;AAC1D;AACA;AACA;AACA,SAASX,KAAK,IAAIY,aAAa,QAAQ,UAAU;AACjD,OAAOC,kBAAkB,MAAM,wBAAwB;AACvD,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,kBAAkB,QAAQ,cAAc;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,oBAAoBA,CAAE;EAC7CC,SAAS;EACTC,YAAY;EACZC;AACD,CAAC,EAAG;EACH,MAAM;IAAEC;EAAoB,CAAC,GAAGb,WAAW,CAAEI,YAAa,CAAC;EAC3D,MAAM;IAAEU;EAAc,CAAC,GAAGd,WAAW,CAAEN,gBAAiB,CAAC;EACzD;EACA;EACA,MAAM;IAAEqB;EAAkB,CAAC,GAAGR,MAAM,CAAEP,WAAW,CAAEK,aAAc,CAAE,CAAC;EACpE,MAAM,CAAEW,WA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GAEpBd,EAAE,CAAE,gBAAiB,CACd,CAAC,EACTc,WAAW,IACZiC,aAAA,CAAC3C,kBAAkB;IAClB+C,OAAO,EAAGf,UAAY;IACtBgB,SAAS,EAAKd,OAAO,IAAM;MAC1BD,aAAa,CAAEC,OAAQ,CAAC;IACzB,CAAG;IACHe,OAAO,EAAGA,CAAA,KAAM;MACftC,cAAc,CAAE,KAAM,CAAC;IACxB,CAAG;IACHuC,OAAO,EAAGA,CAAA,KAAM;MACfvC,cAAc,CAAE,KAAM,CAAC;IACxB;EAAG,CACH,CAED,CAAC;AAEL"}
|
|
@@ -21,7 +21,6 @@ function PatternsManageButton({
|
|
|
21
21
|
const {
|
|
22
22
|
canRemove,
|
|
23
23
|
isVisible,
|
|
24
|
-
innerBlockCount,
|
|
25
24
|
managePatternsUrl
|
|
26
25
|
} = useSelect(select => {
|
|
27
26
|
const {
|
|
@@ -60,7 +59,7 @@ function PatternsManageButton({
|
|
|
60
59
|
}
|
|
61
60
|
return createElement(Fragment, null, canRemove && createElement(MenuItem, {
|
|
62
61
|
onClick: () => convertSyncedPatternToStatic(clientId)
|
|
63
|
-
},
|
|
62
|
+
}, __('Detach')), createElement(MenuItem, {
|
|
64
63
|
href: managePatternsUrl
|
|
65
64
|
}, __('Manage patterns')));
|
|
66
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["MenuItem","__","isReusableBlock","useSelect","useDispatch","store","blockEditorStore","addQueryArgs","coreStore","patternsStore","unlock","PatternsManageButton","clientId","canRemove","isVisible","
|
|
1
|
+
{"version":3,"names":["MenuItem","__","isReusableBlock","useSelect","useDispatch","store","blockEditorStore","addQueryArgs","coreStore","patternsStore","unlock","PatternsManageButton","clientId","canRemove","isVisible","managePatternsUrl","select","getBlock","canRemoveBlock","getBlockCount","getSettings","canUser","reusableBlock","isBlockTheme","__unstableIsBlockBasedTheme","attributes","ref","innerBlockCount","path","post_type","convertSyncedPatternToStatic","createElement","Fragment","onClick","href"],"sources":["@wordpress/patterns/src/components/patterns-manage-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nfunction PatternsManageButton( { clientId } ) {\n\tconst { canRemove, isVisible, managePatternsUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, canRemoveBlock, getBlockCount, getSettings } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst reusableBlock = getBlock( clientId );\n\t\t\tconst isBlockTheme = getSettings().__unstableIsBlockBasedTheme;\n\n\t\t\treturn {\n\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\tisVisible:\n\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t!! canUser(\n\t\t\t\t\t\t'update',\n\t\t\t\t\t\t'blocks',\n\t\t\t\t\t\treusableBlock.attributes.ref\n\t\t\t\t\t),\n\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t// The site editor and templates both check whether the user\n\t\t\t\t// has edit_theme_options capabilities. We can leverage that here\n\t\t\t\t// and omit the manage patterns link if the user can't access it.\n\t\t\t\tmanagePatternsUrl:\n\t\t\t\t\tisBlockTheme && canUser( 'read', 'templates' )\n\t\t\t\t\t\t? addQueryArgs( 'site-editor.php', {\n\t\t\t\t\t\t\t\tpath: '/patterns',\n\t\t\t\t\t\t } )\n\t\t\t\t\t\t: addQueryArgs( 'edit.php', {\n\t\t\t\t\t\t\t\tpost_type: 'wp_block',\n\t\t\t\t\t\t } ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { convertSyncedPatternToStatic } = unlock(\n\t\tuseDispatch( patternsStore )\n\t);\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ canRemove && (\n\t\t\t\t<MenuItem\n\t\t\t\t\tonClick={ () => convertSyncedPatternToStatic( clientId ) }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Detach' ) }\n\t\t\t\t</MenuItem>\n\t\t\t) }\n\t\t\t<MenuItem href={ managePatternsUrl }>\n\t\t\t\t{ __( 'Manage patterns' ) }\n\t\t\t</MenuItem>\n\t\t</>\n\t);\n}\n\nexport default PatternsManageButton;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SAASF,KAAK,IAAIG,SAAS,QAAQ,sBAAsB;;AAEzD;AACA;AACA;AACA,SAASH,KAAK,IAAII,aAAa,QAAQ,UAAU;AACjD,SAASC,MAAM,QAAQ,gBAAgB;AAEvC,SAASC,oBAAoBA,CAAE;EAAEC;AAAS,CAAC,EAAG;EAC7C,MAAM;IAAEC,SAAS;IAAEC,SAAS;IAAEC;EAAkB,CAAC,GAAGZ,SAAS,CAC1Da,MAAM,IAAM;IACb,MAAM;MAAEC,QAAQ;MAAEC,cAAc;MAAEC,aAAa;MAAEC;IAAY,CAAC,GAC7DJ,MAAM,CAAEV,gBAAiB,CAAC;IAC3B,MAAM;MAAEe;IAAQ,CAAC,GAAGL,MAAM,CAAER,SAAU,CAAC;IACvC,MAAMc,aAAa,GAAGL,QAAQ,CAAEL,QAAS,CAAC;IAC1C,MAAMW,YAAY,GAAGH,WAAW,CAAC,CAAC,CAACI,2BAA2B;IAE9D,OAAO;MACNX,SAAS,EAAEK,cAAc,CAAEN,QAAS,CAAC;MACrCE,SAAS,EACR,CAAC,CAAEQ,aAAa,IAChBpB,eAAe,CAAEoB,aAAc,CAAC,IAChC,CAAC,CAAED,OAAO,CACT,QAAQ,EACR,QAAQ,EACRC,aAAa,CAACG,UAAU,CAACC,GAC1B,CAAC;MACFC,eAAe,EAAER,aAAa,CAAEP,QAAS,CAAC;MAC1C;MACA;MACA;MACAG,iBAAiB,EAChBQ,YAAY,IAAIF,OAAO,CAAE,MAAM,EAAE,WAAY,CAAC,GAC3Cd,YAAY,CAAE,iBAAiB,EAAE;QACjCqB,IAAI,EAAE;MACN,CAAE,CAAC,GACHrB,YAAY,CAAE,UAAU,EAAE;QAC1BsB,SAAS,EAAE;MACX,CAAE;IACP,CAAC;EACF,CAAC,EACD,CAAEjB,QAAQ,CACX,CAAC;;EAED;EACA;EACA,MAAM;IAAEkB;EAA6B,CAAC,GAAGpB,MAAM,CAC9CN,WAAW,CAAEK,aAAc,CAC5B,CAAC;EAED,IAAK,CAAEK,SAAS,EAAG;IAClB,OAAO,IAAI;EACZ;EAEA,OACCiB,aAAA,CAAAC,QAAA,QACGnB,SAAS,IACVkB,aAAA,CAAC/B,QAAQ;IACRiC,OAAO,EAAGA,CAAA,KAAMH,4BAA4B,CAAElB,QAAS;EAAG,GAExDX,EAAE,CAAE,QAAS,CACN,CACV,EACD8B,aAAA,CAAC/B,QAAQ;IAACkC,IAAI,EAAGnB;EAAmB,GACjCd,EAAE,CAAE,iBAAkB,CACf,CACT,CAAC;AAEL;AAEA,eAAeU,oBAAoB"}
|
|
@@ -110,27 +110,24 @@
|
|
|
110
110
|
width: 350px;
|
|
111
111
|
}
|
|
112
112
|
.patterns-menu-items__convert-modal .patterns-menu-items__convert-modal-categories {
|
|
113
|
-
width: 100%;
|
|
114
113
|
position: relative;
|
|
115
|
-
min-height: 40px;
|
|
116
114
|
}
|
|
117
|
-
.patterns-menu-items__convert-modal .components-form-token-field__suggestions-list {
|
|
115
|
+
.patterns-menu-items__convert-modal .components-form-token-field__suggestions-list:not(:empty) {
|
|
118
116
|
position: absolute;
|
|
117
|
+
border: 1px solid var(--wp-admin-theme-color);
|
|
118
|
+
border-bottom-right-radius: 2px;
|
|
119
|
+
border-bottom-left-radius: 2px;
|
|
120
|
+
box-shadow: 0 0 0.5px 0.5px var(--wp-admin-theme-color);
|
|
119
121
|
box-sizing: border-box;
|
|
120
122
|
z-index: 1;
|
|
121
123
|
background-color: #fff;
|
|
122
124
|
width: calc(100% + 2px);
|
|
123
125
|
right: -1px;
|
|
124
126
|
min-width: initial;
|
|
125
|
-
|
|
126
|
-
border-top: none;
|
|
127
|
-
box-shadow: 0 0 0 0.5px var(--wp-admin-theme-color);
|
|
128
|
-
border-bottom-right-radius: 2px;
|
|
129
|
-
border-bottom-left-radius: 2px;
|
|
127
|
+
max-height: 96px;
|
|
130
128
|
}
|
|
131
129
|
|
|
132
130
|
.patterns-create-modal__name-input input[type=text] {
|
|
133
|
-
min-height: 40px;
|
|
134
131
|
margin: 0;
|
|
135
132
|
}
|
|
136
133
|
|
package/build-style/style.css
CHANGED
|
@@ -110,27 +110,24 @@
|
|
|
110
110
|
width: 350px;
|
|
111
111
|
}
|
|
112
112
|
.patterns-menu-items__convert-modal .patterns-menu-items__convert-modal-categories {
|
|
113
|
-
width: 100%;
|
|
114
113
|
position: relative;
|
|
115
|
-
min-height: 40px;
|
|
116
114
|
}
|
|
117
|
-
.patterns-menu-items__convert-modal .components-form-token-field__suggestions-list {
|
|
115
|
+
.patterns-menu-items__convert-modal .components-form-token-field__suggestions-list:not(:empty) {
|
|
118
116
|
position: absolute;
|
|
117
|
+
border: 1px solid var(--wp-admin-theme-color);
|
|
118
|
+
border-bottom-left-radius: 2px;
|
|
119
|
+
border-bottom-right-radius: 2px;
|
|
120
|
+
box-shadow: 0 0 0.5px 0.5px var(--wp-admin-theme-color);
|
|
119
121
|
box-sizing: border-box;
|
|
120
122
|
z-index: 1;
|
|
121
123
|
background-color: #fff;
|
|
122
124
|
width: calc(100% + 2px);
|
|
123
125
|
left: -1px;
|
|
124
126
|
min-width: initial;
|
|
125
|
-
|
|
126
|
-
border-top: none;
|
|
127
|
-
box-shadow: 0 0 0 0.5px var(--wp-admin-theme-color);
|
|
128
|
-
border-bottom-left-radius: 2px;
|
|
129
|
-
border-bottom-right-radius: 2px;
|
|
127
|
+
max-height: 96px;
|
|
130
128
|
}
|
|
131
129
|
|
|
132
130
|
.patterns-create-modal__name-input input[type=text] {
|
|
133
|
-
min-height: 40px;
|
|
134
131
|
margin: 0;
|
|
135
132
|
}
|
|
136
133
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/patterns",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Management of user pattern editing.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -31,20 +31,20 @@
|
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/runtime": "^7.16.0",
|
|
34
|
-
"@wordpress/a11y": "^3.
|
|
35
|
-
"@wordpress/block-editor": "^12.
|
|
36
|
-
"@wordpress/blocks": "^12.
|
|
37
|
-
"@wordpress/components": "^25.
|
|
38
|
-
"@wordpress/compose": "^6.
|
|
39
|
-
"@wordpress/core-data": "^6.
|
|
40
|
-
"@wordpress/data": "^9.
|
|
41
|
-
"@wordpress/element": "^5.
|
|
42
|
-
"@wordpress/html-entities": "^3.
|
|
43
|
-
"@wordpress/i18n": "^4.
|
|
44
|
-
"@wordpress/icons": "^9.
|
|
45
|
-
"@wordpress/notices": "^4.
|
|
46
|
-
"@wordpress/private-apis": "^0.
|
|
47
|
-
"@wordpress/url": "^3.
|
|
34
|
+
"@wordpress/a11y": "^3.47.0",
|
|
35
|
+
"@wordpress/block-editor": "^12.15.0",
|
|
36
|
+
"@wordpress/blocks": "^12.24.0",
|
|
37
|
+
"@wordpress/components": "^25.13.0",
|
|
38
|
+
"@wordpress/compose": "^6.24.0",
|
|
39
|
+
"@wordpress/core-data": "^6.24.0",
|
|
40
|
+
"@wordpress/data": "^9.17.0",
|
|
41
|
+
"@wordpress/element": "^5.24.0",
|
|
42
|
+
"@wordpress/html-entities": "^3.47.0",
|
|
43
|
+
"@wordpress/i18n": "^4.47.0",
|
|
44
|
+
"@wordpress/icons": "^9.38.0",
|
|
45
|
+
"@wordpress/notices": "^4.15.0",
|
|
46
|
+
"@wordpress/private-apis": "^0.29.0",
|
|
47
|
+
"@wordpress/url": "^3.48.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"react": "^18.0.0",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "d98dff8ea96f29cfea045bf964269f46f040d539"
|
|
57
57
|
}
|
|
@@ -166,12 +166,13 @@ export default function CreatePatternModal( {
|
|
|
166
166
|
>
|
|
167
167
|
<VStack spacing="5">
|
|
168
168
|
<TextControl
|
|
169
|
-
__nextHasNoMarginBottom
|
|
170
169
|
label={ __( 'Name' ) }
|
|
171
170
|
value={ title }
|
|
172
171
|
onChange={ setTitle }
|
|
173
172
|
placeholder={ __( 'My pattern' ) }
|
|
174
173
|
className="patterns-create-modal__name-input"
|
|
174
|
+
__nextHasNoMarginBottom
|
|
175
|
+
__next40pxDefaultSize
|
|
175
176
|
/>
|
|
176
177
|
<CategorySelector
|
|
177
178
|
categoryTerms={ categoryTerms }
|
|
@@ -184,7 +185,7 @@ export default function CreatePatternModal( {
|
|
|
184
185
|
'Option that makes an individual pattern synchronized'
|
|
185
186
|
) }
|
|
186
187
|
help={ __(
|
|
187
|
-
'
|
|
188
|
+
'Sync this pattern across multiple locations.'
|
|
188
189
|
) }
|
|
189
190
|
checked={ syncType === PATTERN_SYNC_TYPES.full }
|
|
190
191
|
onChange={ () => {
|
|
@@ -197,6 +198,7 @@ export default function CreatePatternModal( {
|
|
|
197
198
|
/>
|
|
198
199
|
<HStack justify="right">
|
|
199
200
|
<Button
|
|
201
|
+
__next40pxDefaultSize
|
|
200
202
|
variant="tertiary"
|
|
201
203
|
onClick={ () => {
|
|
202
204
|
onClose();
|
|
@@ -207,6 +209,7 @@ export default function CreatePatternModal( {
|
|
|
207
209
|
</Button>
|
|
208
210
|
|
|
209
211
|
<Button
|
|
212
|
+
__next40pxDefaultSize
|
|
210
213
|
variant="primary"
|
|
211
214
|
type="submit"
|
|
212
215
|
aria-disabled={ ! title || isSaving }
|
|
@@ -10,11 +10,11 @@ import { store as noticesStore } from '@wordpress/notices';
|
|
|
10
10
|
* Internal dependencies
|
|
11
11
|
*/
|
|
12
12
|
import CreatePatternModal from './create-pattern-modal';
|
|
13
|
-
import { PATTERN_SYNC_TYPES } from '../constants';
|
|
13
|
+
import { PATTERN_SYNC_TYPES, PATTERN_TYPES } from '../constants';
|
|
14
14
|
|
|
15
15
|
function getTermLabels( pattern, categories ) {
|
|
16
|
-
// Theme patterns
|
|
17
|
-
if (
|
|
16
|
+
// Theme patterns rely on core pattern categories.
|
|
17
|
+
if ( pattern.type !== PATTERN_TYPES.user ) {
|
|
18
18
|
return categories.core
|
|
19
19
|
?.filter( ( category ) =>
|
|
20
20
|
pattern.categories.includes( category.name )
|
|
@@ -52,9 +52,10 @@ export default function DuplicatePatternModal( {
|
|
|
52
52
|
const duplicatedProps = {
|
|
53
53
|
content: pattern.content,
|
|
54
54
|
defaultCategories: getTermLabels( pattern, categories ),
|
|
55
|
-
defaultSyncType:
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
defaultSyncType:
|
|
56
|
+
pattern.type !== PATTERN_TYPES.user // Theme patterns are unsynced by default.
|
|
57
|
+
? PATTERN_SYNC_TYPES.unsynced
|
|
58
|
+
: pattern.wp_pattern_sync_status || PATTERN_SYNC_TYPES.full,
|
|
58
59
|
defaultTitle: sprintf(
|
|
59
60
|
/* translators: %s: Existing pattern title */
|
|
60
61
|
__( '%s (Copy)' ),
|
package/src/components/index.js
CHANGED
|
@@ -12,11 +12,12 @@ import PatternsManageButton from './patterns-manage-button';
|
|
|
12
12
|
export default function PatternsMenuItems( { rootClientId } ) {
|
|
13
13
|
return (
|
|
14
14
|
<BlockSettingsMenuControls>
|
|
15
|
-
{ ( { selectedClientIds } ) => (
|
|
15
|
+
{ ( { selectedClientIds, onClose } ) => (
|
|
16
16
|
<>
|
|
17
17
|
<PatternConvertButton
|
|
18
18
|
clientIds={ selectedClientIds }
|
|
19
19
|
rootClientId={ rootClientId }
|
|
20
|
+
closeBlockSettingsMenu={ onClose }
|
|
20
21
|
/>
|
|
21
22
|
{ selectedClientIds.length === 1 && (
|
|
22
23
|
<PatternsManageButton
|
|
@@ -26,12 +26,17 @@ import { PATTERN_SYNC_TYPES } from '../constants';
|
|
|
26
26
|
/**
|
|
27
27
|
* Menu control to convert block(s) to a pattern block.
|
|
28
28
|
*
|
|
29
|
-
* @param {Object} props
|
|
30
|
-
* @param {string[]} props.clientIds
|
|
31
|
-
* @param {string} props.rootClientId
|
|
29
|
+
* @param {Object} props Component props.
|
|
30
|
+
* @param {string[]} props.clientIds Client ids of selected blocks.
|
|
31
|
+
* @param {string} props.rootClientId ID of the currently selected top-level block.
|
|
32
|
+
* @param {()=>void} props.closeBlockSettingsMenu Callback to close the block settings menu dropdown.
|
|
32
33
|
* @return {import('react').ComponentType} The menu control or null.
|
|
33
34
|
*/
|
|
34
|
-
export default function PatternConvertButton( {
|
|
35
|
+
export default function PatternConvertButton( {
|
|
36
|
+
clientIds,
|
|
37
|
+
rootClientId,
|
|
38
|
+
closeBlockSettingsMenu,
|
|
39
|
+
} ) {
|
|
35
40
|
const { createSuccessNotice } = useDispatch( noticesStore );
|
|
36
41
|
const { replaceBlocks } = useDispatch( blockEditorStore );
|
|
37
42
|
// Ignore reason: false positive of the lint rule.
|
|
@@ -104,6 +109,7 @@ export default function PatternConvertButton( { clientIds, rootClientId } ) {
|
|
|
104
109
|
|
|
105
110
|
replaceBlocks( clientIds, newBlock );
|
|
106
111
|
setEditingPattern( newBlock.clientId, true );
|
|
112
|
+
closeBlockSettingsMenu();
|
|
107
113
|
}
|
|
108
114
|
|
|
109
115
|
createSuccessNotice(
|
|
@@ -16,41 +16,40 @@ import { store as patternsStore } from '../store';
|
|
|
16
16
|
import { unlock } from '../lock-unlock';
|
|
17
17
|
|
|
18
18
|
function PatternsManageButton( { clientId } ) {
|
|
19
|
-
const { canRemove, isVisible,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const isBlockTheme = getSettings().__unstableIsBlockBasedTheme;
|
|
19
|
+
const { canRemove, isVisible, managePatternsUrl } = useSelect(
|
|
20
|
+
( select ) => {
|
|
21
|
+
const { getBlock, canRemoveBlock, getBlockCount, getSettings } =
|
|
22
|
+
select( blockEditorStore );
|
|
23
|
+
const { canUser } = select( coreStore );
|
|
24
|
+
const reusableBlock = getBlock( clientId );
|
|
25
|
+
const isBlockTheme = getSettings().__unstableIsBlockBasedTheme;
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
27
|
+
return {
|
|
28
|
+
canRemove: canRemoveBlock( clientId ),
|
|
29
|
+
isVisible:
|
|
30
|
+
!! reusableBlock &&
|
|
31
|
+
isReusableBlock( reusableBlock ) &&
|
|
32
|
+
!! canUser(
|
|
33
|
+
'update',
|
|
34
|
+
'blocks',
|
|
35
|
+
reusableBlock.attributes.ref
|
|
36
|
+
),
|
|
37
|
+
innerBlockCount: getBlockCount( clientId ),
|
|
38
|
+
// The site editor and templates both check whether the user
|
|
39
|
+
// has edit_theme_options capabilities. We can leverage that here
|
|
40
|
+
// and omit the manage patterns link if the user can't access it.
|
|
41
|
+
managePatternsUrl:
|
|
42
|
+
isBlockTheme && canUser( 'read', 'templates' )
|
|
43
|
+
? addQueryArgs( 'site-editor.php', {
|
|
44
|
+
path: '/patterns',
|
|
45
|
+
} )
|
|
46
|
+
: addQueryArgs( 'edit.php', {
|
|
47
|
+
post_type: 'wp_block',
|
|
48
|
+
} ),
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
[ clientId ]
|
|
52
|
+
);
|
|
54
53
|
|
|
55
54
|
// Ignore reason: false positive of the lint rule.
|
|
56
55
|
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
|
|
@@ -68,9 +67,7 @@ function PatternsManageButton( { clientId } ) {
|
|
|
68
67
|
<MenuItem
|
|
69
68
|
onClick={ () => convertSyncedPatternToStatic( clientId ) }
|
|
70
69
|
>
|
|
71
|
-
{
|
|
72
|
-
? __( 'Detach patterns' )
|
|
73
|
-
: __( 'Detach pattern' ) }
|
|
70
|
+
{ __( 'Detach' ) }
|
|
74
71
|
</MenuItem>
|
|
75
72
|
) }
|
|
76
73
|
<MenuItem href={ managePatternsUrl }>
|
|
@@ -7,32 +7,27 @@
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
.patterns-menu-items__convert-modal-categories {
|
|
10
|
-
width: 100%;
|
|
11
10
|
position: relative;
|
|
12
|
-
min-height: 40px;
|
|
13
11
|
}
|
|
14
|
-
|
|
12
|
+
|
|
13
|
+
.components-form-token-field__suggestions-list:not(:empty) {
|
|
15
14
|
position: absolute;
|
|
15
|
+
border: $border-width solid var(--wp-admin-theme-color);
|
|
16
|
+
border-bottom-left-radius: $radius-block-ui;
|
|
17
|
+
border-bottom-right-radius: $radius-block-ui;
|
|
18
|
+
box-shadow: 0 0 0.5px 0.5px var(--wp-admin-theme-color);
|
|
16
19
|
box-sizing: border-box;
|
|
17
20
|
z-index: 1;
|
|
18
21
|
background-color: $white;
|
|
19
|
-
// Account for the border width of the token field.
|
|
20
|
-
width: calc(100% + 2px);
|
|
22
|
+
width: calc(100% + 2px); // Account for the border width of the token field.
|
|
21
23
|
left: -1px;
|
|
22
24
|
min-width: initial;
|
|
23
|
-
|
|
24
|
-
border-top: none;
|
|
25
|
-
box-shadow: 0 0 0 0.5px var(--wp-admin-theme-color);
|
|
26
|
-
border-bottom-left-radius: 2px;
|
|
27
|
-
border-bottom-right-radius: 2px;
|
|
25
|
+
max-height: $grid-unit-60 * 2; // Adjust to not cover the save button, showing three items.
|
|
28
26
|
}
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
.patterns-create-modal__name-input input[type="text"] {
|
|
32
|
-
//
|
|
33
|
-
min-height: 40px;
|
|
34
|
-
// Override the default 1px margin-x.
|
|
35
|
-
margin: 0;
|
|
30
|
+
margin: 0; // Override the default 1px margin-x.
|
|
36
31
|
}
|
|
37
32
|
|
|
38
33
|
.patterns-rename-pattern-category-modal__validation-message {
|