@wordpress/patterns 1.3.6 → 1.4.1
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 +33 -17
- package/build/components/category-selector.js.map +1 -1
- package/build/components/create-pattern-modal.js +15 -54
- package/build/components/create-pattern-modal.js.map +1 -1
- package/build/components/index.js +4 -4
- package/build/components/index.js.map +1 -1
- package/build/components/pattern-convert-button.js +5 -4
- package/build/components/pattern-convert-button.js.map +1 -1
- package/build/components/patterns-manage-button.js +3 -3
- package/build/components/patterns-manage-button.js.map +1 -1
- package/build/lock-unlock.js +1 -1
- package/build/lock-unlock.js.map +1 -1
- package/build-module/components/category-selector.js +32 -17
- package/build-module/components/category-selector.js.map +1 -1
- package/build-module/components/create-pattern-modal.js +7 -47
- package/build-module/components/create-pattern-modal.js.map +1 -1
- package/build-module/components/index.js +1 -1
- package/build-module/components/pattern-convert-button.js +2 -2
- package/build-module/components/pattern-convert-button.js.map +1 -1
- package/build-module/components/patterns-manage-button.js +1 -1
- package/build-module/lock-unlock.js +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-style/style-rtl.css +3 -23
- package/build-style/style.css +3 -23
- package/package.json +17 -16
- package/src/components/category-selector.js +42 -28
- package/src/components/create-pattern-modal.js +4 -47
- package/src/components/pattern-convert-button.js +1 -1
- package/src/components/style.scss +2 -28
- package/src/lock-unlock.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","useMemo","useState","FormTokenField","
|
|
1
|
+
{"version":3,"names":["__","useMemo","useState","FormTokenField","useSelect","store","coreStore","useDebounce","decodeEntities","unescapeString","arg","EMPTY_ARRAY","MAX_TERMS_SUGGESTIONS","DEFAULT_QUERY","per_page","_fields","context","CATEGORY_SLUG","CategorySelector","values","onChange","search","setSearch","debouncedSearch","searchResults","select","getEntityRecords","suggestions","map","term","name","handleChange","termNames","uniqueTerms","reduce","terms","newTerm","some","toLowerCase","push","createElement","Fragment","className","value","onInputChange","maxSuggestions","label","tokenizeOnBlur"],"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 { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDebounce } from '@wordpress/compose';\nimport { decodeEntities } from '@wordpress/html-entities';\n\nconst unescapeString = ( arg ) => {\n\treturn decodeEntities( arg );\n};\n\nconst EMPTY_ARRAY = [];\nconst MAX_TERMS_SUGGESTIONS = 20;\nconst DEFAULT_QUERY = {\n\tper_page: MAX_TERMS_SUGGESTIONS,\n\t_fields: 'id,name',\n\tcontext: 'view',\n};\nexport const CATEGORY_SLUG = 'wp_pattern_category';\n\nexport default function CategorySelector( { values, onChange } ) {\n\tconst [ search, setSearch ] = useState( '' );\n\tconst debouncedSearch = useDebounce( setSearch, 500 );\n\n\tconst { searchResults } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\n\t\t\treturn {\n\t\t\t\tsearchResults: !! search\n\t\t\t\t\t? getEntityRecords( 'taxonomy', CATEGORY_SLUG, {\n\t\t\t\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\t\t\t\tsearch,\n\t\t\t\t\t } )\n\t\t\t\t\t: EMPTY_ARRAY,\n\t\t\t};\n\t\t},\n\t\t[ search ]\n\t);\n\n\tconst suggestions = useMemo( () => {\n\t\treturn ( searchResults ?? [] ).map( ( term ) =>\n\t\t\tunescapeString( term.name )\n\t\t);\n\t}, [ searchResults ] );\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<>\n\t\t\t<FormTokenField\n\t\t\t\tclassName=\"patterns-menu-items__convert-modal-categories\"\n\t\t\t\tvalue={ values }\n\t\t\t\tsuggestions={ suggestions }\n\t\t\t\tonChange={ handleChange }\n\t\t\t\tonInputChange={ debouncedSearch }\n\t\t\t\tmaxSuggestions={ MAX_TERMS_SUGGESTIONS }\n\t\t\t\tlabel={ __( 'Categories' ) }\n\t\t\t\ttokenizeOnBlur={ true }\n\t\t\t/>\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,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,WAAW,QAAQ,oBAAoB;AAChD,SAASC,cAAc,QAAQ,0BAA0B;AAEzD,MAAMC,cAAc,GAAKC,GAAG,IAAM;EACjC,OAAOF,cAAc,CAAEE,GAAI,CAAC;AAC7B,CAAC;AAED,MAAMC,WAAW,GAAG,EAAE;AACtB,MAAMC,qBAAqB,GAAG,EAAE;AAChC,MAAMC,aAAa,GAAG;EACrBC,QAAQ,EAAEF,qBAAqB;EAC/BG,OAAO,EAAE,SAAS;EAClBC,OAAO,EAAE;AACV,CAAC;AACD,OAAO,MAAMC,aAAa,GAAG,qBAAqB;AAElD,eAAe,SAASC,gBAAgBA,CAAE;EAAEC,MAAM;EAAEC;AAAS,CAAC,EAAG;EAChE,MAAM,CAAEC,MAAM,EAAEC,SAAS,CAAE,GAAGpB,QAAQ,CAAE,EAAG,CAAC;EAC5C,MAAMqB,eAAe,GAAGhB,WAAW,CAAEe,SAAS,EAAE,GAAI,CAAC;EAErD,MAAM;IAAEE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EAAG;EAAM,CACvB,CACA,CAAC;AAEL"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { createElement } from "
|
|
1
|
+
import { createElement } from "react";
|
|
2
2
|
/**
|
|
3
3
|
* WordPress dependencies
|
|
4
4
|
*/
|
|
5
5
|
import { Modal, Button, TextControl, __experimentalHStack as HStack, __experimentalVStack as VStack, ToggleControl } from '@wordpress/components';
|
|
6
6
|
import { __ } from '@wordpress/i18n';
|
|
7
|
-
import { useState
|
|
8
|
-
import { useDispatch
|
|
7
|
+
import { useState } from '@wordpress/element';
|
|
8
|
+
import { useDispatch } from '@wordpress/data';
|
|
9
9
|
import { store as noticesStore } from '@wordpress/notices';
|
|
10
10
|
import { store as coreStore } from '@wordpress/core-data';
|
|
11
11
|
|
|
@@ -41,38 +41,6 @@ export default function CreatePatternModal({
|
|
|
41
41
|
const {
|
|
42
42
|
createErrorNotice
|
|
43
43
|
} = useDispatch(noticesStore);
|
|
44
|
-
const {
|
|
45
|
-
corePatternCategories,
|
|
46
|
-
userPatternCategories
|
|
47
|
-
} = useSelect(select => {
|
|
48
|
-
const {
|
|
49
|
-
getUserPatternCategories,
|
|
50
|
-
getBlockPatternCategories
|
|
51
|
-
} = select(coreStore);
|
|
52
|
-
return {
|
|
53
|
-
corePatternCategories: getBlockPatternCategories(),
|
|
54
|
-
userPatternCategories: getUserPatternCategories()
|
|
55
|
-
};
|
|
56
|
-
});
|
|
57
|
-
const categoryMap = useMemo(() => {
|
|
58
|
-
// Merge the user and core pattern categories and remove any duplicates.
|
|
59
|
-
const uniqueCategories = new Map();
|
|
60
|
-
[...userPatternCategories, ...corePatternCategories].forEach(category => {
|
|
61
|
-
if (!uniqueCategories.has(category.label) &&
|
|
62
|
-
// There are two core categories with `Post` label so explicitly remove the one with
|
|
63
|
-
// the `query` slug to avoid any confusion.
|
|
64
|
-
category.name !== 'query') {
|
|
65
|
-
// We need to store the name separately as this is used as the slug in the
|
|
66
|
-
// taxonomy and may vary from the label.
|
|
67
|
-
uniqueCategories.set(category.label, {
|
|
68
|
-
label: category.label,
|
|
69
|
-
value: category.label,
|
|
70
|
-
name: category.name
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
return uniqueCategories;
|
|
75
|
-
}, [userPatternCategories, corePatternCategories]);
|
|
76
44
|
async function onCreate(patternTitle, sync) {
|
|
77
45
|
if (!title || isSaving) {
|
|
78
46
|
return;
|
|
@@ -104,16 +72,9 @@ export default function CreatePatternModal({
|
|
|
104
72
|
*/
|
|
105
73
|
async function findOrCreateTerm(term) {
|
|
106
74
|
try {
|
|
107
|
-
|
|
108
|
-
// the core `Headers` category uses the singular `header` as the slug.
|
|
109
|
-
const existingTerm = categoryMap.get(term);
|
|
110
|
-
const termData = existingTerm ? {
|
|
111
|
-
name: existingTerm.label,
|
|
112
|
-
slug: existingTerm.name
|
|
113
|
-
} : {
|
|
75
|
+
const newTerm = await saveEntityRecord('taxonomy', CATEGORY_SLUG, {
|
|
114
76
|
name: term
|
|
115
|
-
}
|
|
116
|
-
const newTerm = await saveEntityRecord('taxonomy', CATEGORY_SLUG, termData, {
|
|
77
|
+
}, {
|
|
117
78
|
throwOnError: true
|
|
118
79
|
});
|
|
119
80
|
invalidateResolution('getUserPatternCategories');
|
|
@@ -147,9 +108,8 @@ export default function CreatePatternModal({
|
|
|
147
108
|
placeholder: __('My pattern'),
|
|
148
109
|
className: "patterns-create-modal__name-input"
|
|
149
110
|
}), createElement(CategorySelector, {
|
|
150
|
-
|
|
151
|
-
onChange: setCategoryTerms
|
|
152
|
-
categoryMap: categoryMap
|
|
111
|
+
values: categoryTerms,
|
|
112
|
+
onChange: setCategoryTerms
|
|
153
113
|
}), createElement(ToggleControl, {
|
|
154
114
|
label: __('Synced'),
|
|
155
115
|
help: __('Editing the pattern will update it anywhere it is used.'),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Modal","Button","TextControl","__experimentalHStack","HStack","__experimentalVStack","VStack","ToggleControl","__","useState","useMemo","useDispatch","useSelect","store","noticesStore","coreStore","PATTERN_DEFAULT_CATEGORY","PATTERN_SYNC_TYPES","patternsStore","CategorySelector","CATEGORY_SLUG","unlock","CreatePatternModal","onSuccess","onError","content","onClose","className","syncType","setSyncType","full","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 { __ } 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\tonSuccess,\n\tonError,\n\tcontent,\n\tonClose,\n\tclassName = 'patterns-menu-items__convert-modal',\n} ) {\n\tconst [ syncType, setSyncType ] = useState( PATTERN_SYNC_TYPES.full );\n\tconst [ categoryTerms, setCategoryTerms ] = useState( [] );\n\tconst [ title, setTitle ] = useState( '' );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\tconst { createPattern } = unlock( useDispatch( patternsStore ) );\n\tconst { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\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: 'convert-to-pattern-error',\n\t\t\t} );\n\t\t\tonError();\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t\tsetCategoryTerms( [] );\n\t\t\tsetTitle( '' );\n\t\t}\n\t}\n\n\t/**\n\t * @param {string} term\n\t * @return {Promise<number>} The pattern category id.\n\t */\n\tasync function findOrCreateTerm( term ) {\n\t\ttry {\n\t\t\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={ __( 'Create pattern' ) }\n\t\t\tonRequestClose={ () => {\n\t\t\t\tonClose();\n\t\t\t\tsetTitle( '' );\n\t\t\t} }\n\t\t\toverlayClassName={ className }\n\t\t>\n\t\t\t<form\n\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tonCreate( title, syncType );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\tplaceholder={ __( 'My pattern' ) }\n\t\t\t\t\t\tclassName=\"patterns-create-modal__name-input\"\n\t\t\t\t\t/>\n\t\t\t\t\t<CategorySelector\n\t\t\t\t\t\tcategoryTerms={ categoryTerms }\n\t\t\t\t\t\tonChange={ setCategoryTerms }\n\t\t\t\t\t\tcategoryMap={ categoryMap }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Synced' ) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Editing the pattern will update it anywhere it is used.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ syncType === PATTERN_SYNC_TYPES.full }\n\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\tsyncType === PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t\t\t? PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t\t\t\t\t\t: PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t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GA,CAAA,KAAM;MAChB7D,WAAW,CACVD,QAAQ,KAAKX,kBAAkB,CAACa,IAAI,GACjCb,kBAAkB,CAAC6E,QAAQ,GAC3B7E,kBAAkB,CAACa,IACvB,CAAC;IACF;EAAG,CACH,CAAC,EACFoD,aAAA,CAAC9E,MAAM;IAAC2F,OAAO,EAAC;EAAO,GACtBb,aAAA,CAACjF,MAAM;IACN+F,OAAO,EAAC,UAAU;IAClBC,OAAO,EAAGA,CAAA,KAAM;MACfvE,OAAO,CAAC,CAAC;MACTQ,QAAQ,CAAE,EAAG,CAAC;IACf;EAAG,GAED1B,EAAE,CAAE,QAAS,CACR,CAAC,EAET0E,aAAA,CAACjF,MAAM;IACN+F,OAAO,EAAC,SAAS;IACjB1B,IAAI,EAAC,QAAQ;IACb,iBAAgB,CAAErC,KAAK,IAAIE,QAAU;IACrC+D,MAAM,EAAG/D;EAAU,GAEjB3B,EAAE,CAAE,QAAS,CACR,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
1
|
+
{"version":3,"names":["Modal","Button","TextControl","__experimentalHStack","HStack","__experimentalVStack","VStack","ToggleControl","__","useState","useDispatch","store","noticesStore","coreStore","PATTERN_DEFAULT_CATEGORY","PATTERN_SYNC_TYPES","patternsStore","CategorySelector","CATEGORY_SLUG","unlock","CreatePatternModal","onSuccess","onError","content","onClose","className","syncType","setSyncType","full","categoryTerms","setCategoryTerms","title","setTitle","isSaving","setIsSaving","createPattern","saveEntityRecord","invalidateResolution","createErrorNotice","onCreate","patternTitle","sync","categories","Promise","all","map","termName","findOrCreateTerm","newPattern","pattern","categoryId","error","message","type","id","term","newTerm","name","throwOnError","code","data","term_id","createElement","onRequestClose","overlayClassName","onSubmit","event","preventDefault","spacing","__nextHasNoMarginBottom","label","value","onChange","placeholder","values","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 { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_DEFAULT_CATEGORY, PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CategorySelector, { CATEGORY_SLUG } from './category-selector';\nimport { unlock } from '../lock-unlock';\n\nexport default function CreatePatternModal( {\n\tonSuccess,\n\tonError,\n\tcontent,\n\tonClose,\n\tclassName = 'patterns-menu-items__convert-modal',\n} ) {\n\tconst [ syncType, setSyncType ] = useState( PATTERN_SYNC_TYPES.full );\n\tconst [ categoryTerms, setCategoryTerms ] = useState( [] );\n\tconst [ title, setTitle ] = useState( '' );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\tconst { createPattern } = unlock( useDispatch( patternsStore ) );\n\tconst { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tasync function onCreate( patternTitle, sync ) {\n\t\tif ( ! title || isSaving ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSaving( true );\n\t\t\tconst categories = await Promise.all(\n\t\t\t\tcategoryTerms.map( ( termName ) =>\n\t\t\t\t\tfindOrCreateTerm( termName )\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tconst newPattern = await createPattern(\n\t\t\t\tpatternTitle,\n\t\t\t\tsync,\n\t\t\t\ttypeof content === 'function' ? content() : content,\n\t\t\t\tcategories\n\t\t\t);\n\t\t\tonSuccess( {\n\t\t\t\tpattern: newPattern,\n\t\t\t\tcategoryId: PATTERN_DEFAULT_CATEGORY,\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'convert-to-pattern-error',\n\t\t\t} );\n\t\t\tonError();\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t\tsetCategoryTerms( [] );\n\t\t\tsetTitle( '' );\n\t\t}\n\t}\n\n\t/**\n\t * @param {string} term\n\t * @return {Promise<number>} The pattern category id.\n\t */\n\tasync function findOrCreateTerm( term ) {\n\t\ttry {\n\t\t\tconst newTerm = await saveEntityRecord(\n\t\t\t\t'taxonomy',\n\t\t\t\tCATEGORY_SLUG,\n\t\t\t\t{ name: term },\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tinvalidateResolution( 'getUserPatternCategories' );\n\t\t\treturn newTerm.id;\n\t\t} catch ( error ) {\n\t\t\tif ( error.code !== 'term_exists' ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn error.data.term_id;\n\t\t}\n\t}\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Create pattern' ) }\n\t\t\tonRequestClose={ () => {\n\t\t\t\tonClose();\n\t\t\t\tsetTitle( '' );\n\t\t\t} }\n\t\t\toverlayClassName={ className }\n\t\t>\n\t\t\t<form\n\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tonCreate( title, syncType );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\tplaceholder={ __( 'My pattern' ) }\n\t\t\t\t\t\tclassName=\"patterns-create-modal__name-input\"\n\t\t\t\t\t/>\n\t\t\t\t\t<CategorySelector\n\t\t\t\t\t\tvalues={ categoryTerms }\n\t\t\t\t\t\tonChange={ setCategoryTerms }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Synced' ) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Editing the pattern will update it anywhere it is used.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ syncType === PATTERN_SYNC_TYPES.full }\n\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\tsyncType === PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t\t\t? PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t\t\t\t\t\t: PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\taria-disabled={ ! title || isSaving }\n\t\t\t\t\t\t\tisBusy={ isSaving }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t</Modal>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SACCA,KAAK,EACLC,MAAM,EACNC,WAAW,EACXC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,EAC9BC,aAAa,QACP,uBAAuB;AAC9B,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,QAAQ,oBAAo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,MAAM;IACN8E,OAAO,EAAC,SAAS;IACjB1B,IAAI,EAAC,QAAQ;IACb,iBAAgB,CAAEtB,KAAK,IAAIE,QAAU;IACrCgD,MAAM,EAAGhD;EAAU,GAEjBzB,EAAE,CAAE,QAAS,CACR,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createElement, Fragment } from "
|
|
1
|
+
import { createElement, Fragment } from "react";
|
|
2
2
|
/**
|
|
3
3
|
* WordPress dependencies
|
|
4
4
|
*/
|
|
@@ -25,7 +25,7 @@ import { PATTERN_SYNC_TYPES } from '../constants';
|
|
|
25
25
|
* @param {Object} props Component props.
|
|
26
26
|
* @param {string[]} props.clientIds Client ids of selected blocks.
|
|
27
27
|
* @param {string} props.rootClientId ID of the currently selected top-level block.
|
|
28
|
-
* @return {import('
|
|
28
|
+
* @return {import('react').ComponentType} The menu control or null.
|
|
29
29
|
*/
|
|
30
30
|
export default function PatternConvertButton({
|
|
31
31
|
clientIds,
|
|
@@ -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 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 * @return {import('
|
|
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 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 * @return {import('react').ComponentType} The menu control or null.\n */\nexport default function PatternConvertButton( { clientIds, rootClientId } ) {\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}\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,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ACD3C,OAAO;IACP;IACAD,EAAE,CAAE,4BAA6B,CAAC,EAClCqC,OAAO,CAACM,KAAK,CAACC,GACd,CAAC,EACJ;MACCC,IAAI,EAAE,UAAU;MAChBJ,EAAE,EAAE;IACL,CACD,CAAC;IACD3B,cAAc,CAAE,KAAM,CAAC;EACxB,CAAC;EACD,OACCgC,aAAA,CAAAC,QAAA,QACCD,aAAA,CAACnD,QAAQ;IACRqD,IAAI,EAAGpD,MAAQ;IACfqD,OAAO,EAAGA,CAAA,KAAMnC,cAAc,CAAE,IAAK,CAAG;IACxC,iBAAgBD,WAAa;IAC7B,iBAAc;EAAQ,GAEpBb,EAAE,CAAE,gBAAiB,CACd,CAAC,EACTa,WAAW,IACZiC,aAAA,CAAC1C,kBAAkB;IAClB8C,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"}
|
|
@@ -5,5 +5,5 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri
|
|
|
5
5
|
export const {
|
|
6
6
|
lock,
|
|
7
7
|
unlock
|
|
8
|
-
} = __dangerousOptInToUnstableAPIsOnlyForCoreModules('I know using unstable features means my
|
|
8
|
+
} = __dangerousOptInToUnstableAPIsOnlyForCoreModules('I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', '@wordpress/patterns');
|
|
9
9
|
//# sourceMappingURL=lock-unlock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__dangerousOptInToUnstableAPIsOnlyForCoreModules","lock","unlock"],"sources":["@wordpress/patterns/src/lock-unlock.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I know using unstable features means my
|
|
1
|
+
{"version":3,"names":["__dangerousOptInToUnstableAPIsOnlyForCoreModules","lock","unlock"],"sources":["@wordpress/patterns/src/lock-unlock.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.',\n\t\t'@wordpress/patterns'\n\t);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gDAAgD,QAAQ,yBAAyB;AAC1F,OAAO,MAAM;EAAEC,IAAI;EAAEC;AAAO,CAAC,GAC5BF,gDAAgD,CAC/C,8GAA8G,EAC9G,qBACD,CAAC"}
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
--wp-block-synced-color: #7a00df;
|
|
98
98
|
--wp-block-synced-color--rgb: 122, 0, 223;
|
|
99
99
|
}
|
|
100
|
-
@media (min-resolution: 192dpi) {
|
|
100
|
+
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
|
|
101
101
|
:root {
|
|
102
102
|
--wp-admin-border-width-focus: 1.5px;
|
|
103
103
|
}
|
|
@@ -106,30 +106,10 @@
|
|
|
106
106
|
.patterns-menu-items__convert-modal {
|
|
107
107
|
z-index: 1000001;
|
|
108
108
|
}
|
|
109
|
-
.patterns-menu-items__convert-modal [role=dialog] > [role=document] {
|
|
110
|
-
width: 350px;
|
|
111
|
-
}
|
|
112
109
|
.patterns-menu-items__convert-modal .patterns-menu-items__convert-modal-categories {
|
|
113
|
-
width:
|
|
114
|
-
position: relative;
|
|
115
|
-
min-height: 40px;
|
|
116
|
-
}
|
|
117
|
-
.patterns-menu-items__convert-modal .components-form-token-field__suggestions-list {
|
|
118
|
-
position: absolute;
|
|
119
|
-
box-sizing: border-box;
|
|
120
|
-
z-index: 1;
|
|
121
|
-
background-color: #fff;
|
|
122
|
-
width: calc(100% + 2px);
|
|
123
|
-
right: -1px;
|
|
124
|
-
min-width: initial;
|
|
125
|
-
border: 1px solid var(--wp-admin-theme-color);
|
|
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;
|
|
110
|
+
max-width: 300px;
|
|
130
111
|
}
|
|
131
112
|
|
|
132
113
|
.patterns-create-modal__name-input input[type=text] {
|
|
133
|
-
min-height:
|
|
134
|
-
margin: 0;
|
|
114
|
+
min-height: 34px;
|
|
135
115
|
}
|
package/build-style/style.css
CHANGED
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
--wp-block-synced-color: #7a00df;
|
|
98
98
|
--wp-block-synced-color--rgb: 122, 0, 223;
|
|
99
99
|
}
|
|
100
|
-
@media (min-resolution: 192dpi) {
|
|
100
|
+
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
|
|
101
101
|
:root {
|
|
102
102
|
--wp-admin-border-width-focus: 1.5px;
|
|
103
103
|
}
|
|
@@ -106,30 +106,10 @@
|
|
|
106
106
|
.patterns-menu-items__convert-modal {
|
|
107
107
|
z-index: 1000001;
|
|
108
108
|
}
|
|
109
|
-
.patterns-menu-items__convert-modal [role=dialog] > [role=document] {
|
|
110
|
-
width: 350px;
|
|
111
|
-
}
|
|
112
109
|
.patterns-menu-items__convert-modal .patterns-menu-items__convert-modal-categories {
|
|
113
|
-
width:
|
|
114
|
-
position: relative;
|
|
115
|
-
min-height: 40px;
|
|
116
|
-
}
|
|
117
|
-
.patterns-menu-items__convert-modal .components-form-token-field__suggestions-list {
|
|
118
|
-
position: absolute;
|
|
119
|
-
box-sizing: border-box;
|
|
120
|
-
z-index: 1;
|
|
121
|
-
background-color: #fff;
|
|
122
|
-
width: calc(100% + 2px);
|
|
123
|
-
left: -1px;
|
|
124
|
-
min-width: initial;
|
|
125
|
-
border: 1px solid var(--wp-admin-theme-color);
|
|
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;
|
|
110
|
+
max-width: 300px;
|
|
130
111
|
}
|
|
131
112
|
|
|
132
113
|
.patterns-create-modal__name-input input[type=text] {
|
|
133
|
-
min-height:
|
|
134
|
-
margin: 0;
|
|
114
|
+
min-height: 34px;
|
|
135
115
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/patterns",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Management of user pattern editing.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"url": "https://github.com/WordPress/gutenberg/issues"
|
|
20
20
|
},
|
|
21
21
|
"engines": {
|
|
22
|
-
"node": ">=16.0.0"
|
|
22
|
+
"node": ">=16.0.0",
|
|
23
|
+
"npm": ">=8 <9"
|
|
23
24
|
},
|
|
24
25
|
"main": "build/index.js",
|
|
25
26
|
"module": "build-module/index.js",
|
|
@@ -31,19 +32,19 @@
|
|
|
31
32
|
],
|
|
32
33
|
"dependencies": {
|
|
33
34
|
"@babel/runtime": "^7.16.0",
|
|
34
|
-
"@wordpress/block-editor": "^12.
|
|
35
|
-
"@wordpress/blocks": "^12.
|
|
36
|
-
"@wordpress/components": "^25.
|
|
37
|
-
"@wordpress/compose": "^6.
|
|
38
|
-
"@wordpress/core-data": "^6.
|
|
39
|
-
"@wordpress/data": "^9.
|
|
40
|
-
"@wordpress/element": "^5.
|
|
41
|
-
"@wordpress/html-entities": "^3.
|
|
42
|
-
"@wordpress/i18n": "^4.
|
|
43
|
-
"@wordpress/icons": "^9.
|
|
44
|
-
"@wordpress/notices": "^4.
|
|
45
|
-
"@wordpress/private-apis": "^0.
|
|
46
|
-
"@wordpress/url": "^3.
|
|
35
|
+
"@wordpress/block-editor": "^12.11.1",
|
|
36
|
+
"@wordpress/blocks": "^12.20.1",
|
|
37
|
+
"@wordpress/components": "^25.9.1",
|
|
38
|
+
"@wordpress/compose": "^6.20.0",
|
|
39
|
+
"@wordpress/core-data": "^6.20.1",
|
|
40
|
+
"@wordpress/data": "^9.13.1",
|
|
41
|
+
"@wordpress/element": "^5.20.0",
|
|
42
|
+
"@wordpress/html-entities": "^3.43.0",
|
|
43
|
+
"@wordpress/i18n": "^4.43.0",
|
|
44
|
+
"@wordpress/icons": "^9.34.0",
|
|
45
|
+
"@wordpress/notices": "^4.11.1",
|
|
46
|
+
"@wordpress/private-apis": "^0.25.0",
|
|
47
|
+
"@wordpress/url": "^3.44.0"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
50
|
"react": "^18.0.0",
|
|
@@ -52,5 +53,5 @@
|
|
|
52
53
|
"publishConfig": {
|
|
53
54
|
"access": "public"
|
|
54
55
|
},
|
|
55
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "e17f760ed0dc11cce78157d7c2f2086b1b3c09d8"
|
|
56
57
|
}
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
5
|
import { useMemo, useState } from '@wordpress/element';
|
|
6
6
|
import { FormTokenField } from '@wordpress/components';
|
|
7
|
+
import { useSelect } from '@wordpress/data';
|
|
8
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
7
9
|
import { useDebounce } from '@wordpress/compose';
|
|
8
10
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
9
11
|
|
|
@@ -11,29 +13,40 @@ const unescapeString = ( arg ) => {
|
|
|
11
13
|
return decodeEntities( arg );
|
|
12
14
|
};
|
|
13
15
|
|
|
16
|
+
const EMPTY_ARRAY = [];
|
|
17
|
+
const MAX_TERMS_SUGGESTIONS = 20;
|
|
18
|
+
const DEFAULT_QUERY = {
|
|
19
|
+
per_page: MAX_TERMS_SUGGESTIONS,
|
|
20
|
+
_fields: 'id,name',
|
|
21
|
+
context: 'view',
|
|
22
|
+
};
|
|
14
23
|
export const CATEGORY_SLUG = 'wp_pattern_category';
|
|
15
24
|
|
|
16
|
-
export default function CategorySelector( {
|
|
17
|
-
categoryTerms,
|
|
18
|
-
onChange,
|
|
19
|
-
categoryMap,
|
|
20
|
-
} ) {
|
|
25
|
+
export default function CategorySelector( { values, onChange } ) {
|
|
21
26
|
const [ search, setSearch ] = useState( '' );
|
|
22
27
|
const debouncedSearch = useDebounce( setSearch, 500 );
|
|
23
28
|
|
|
29
|
+
const { searchResults } = useSelect(
|
|
30
|
+
( select ) => {
|
|
31
|
+
const { getEntityRecords } = select( coreStore );
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
searchResults: !! search
|
|
35
|
+
? getEntityRecords( 'taxonomy', CATEGORY_SLUG, {
|
|
36
|
+
...DEFAULT_QUERY,
|
|
37
|
+
search,
|
|
38
|
+
} )
|
|
39
|
+
: EMPTY_ARRAY,
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
[ search ]
|
|
43
|
+
);
|
|
44
|
+
|
|
24
45
|
const suggestions = useMemo( () => {
|
|
25
|
-
return
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return category
|
|
30
|
-
.toLowerCase()
|
|
31
|
-
.includes( search.toLowerCase() );
|
|
32
|
-
}
|
|
33
|
-
return true;
|
|
34
|
-
} )
|
|
35
|
-
.sort( ( a, b ) => a.localeCompare( b ) );
|
|
36
|
-
}, [ search, categoryMap ] );
|
|
46
|
+
return ( searchResults ?? [] ).map( ( term ) =>
|
|
47
|
+
unescapeString( term.name )
|
|
48
|
+
);
|
|
49
|
+
}, [ searchResults ] );
|
|
37
50
|
|
|
38
51
|
function handleChange( termNames ) {
|
|
39
52
|
const uniqueTerms = termNames.reduce( ( terms, newTerm ) => {
|
|
@@ -51,16 +64,17 @@ export default function CategorySelector( {
|
|
|
51
64
|
}
|
|
52
65
|
|
|
53
66
|
return (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
<>
|
|
68
|
+
<FormTokenField
|
|
69
|
+
className="patterns-menu-items__convert-modal-categories"
|
|
70
|
+
value={ values }
|
|
71
|
+
suggestions={ suggestions }
|
|
72
|
+
onChange={ handleChange }
|
|
73
|
+
onInputChange={ debouncedSearch }
|
|
74
|
+
maxSuggestions={ MAX_TERMS_SUGGESTIONS }
|
|
75
|
+
label={ __( 'Categories' ) }
|
|
76
|
+
tokenizeOnBlur={ true }
|
|
77
|
+
/>
|
|
78
|
+
</>
|
|
65
79
|
);
|
|
66
80
|
}
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
ToggleControl,
|
|
11
11
|
} from '@wordpress/components';
|
|
12
12
|
import { __ } from '@wordpress/i18n';
|
|
13
|
-
import { useState
|
|
14
|
-
import { useDispatch
|
|
13
|
+
import { useState } from '@wordpress/element';
|
|
14
|
+
import { useDispatch } from '@wordpress/data';
|
|
15
15
|
import { store as noticesStore } from '@wordpress/notices';
|
|
16
16
|
import { store as coreStore } from '@wordpress/core-data';
|
|
17
17
|
|
|
@@ -42,42 +42,6 @@ export default function CreatePatternModal( {
|
|
|
42
42
|
const { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );
|
|
43
43
|
const { createErrorNotice } = useDispatch( noticesStore );
|
|
44
44
|
|
|
45
|
-
const { corePatternCategories, userPatternCategories } = useSelect(
|
|
46
|
-
( select ) => {
|
|
47
|
-
const { getUserPatternCategories, getBlockPatternCategories } =
|
|
48
|
-
select( coreStore );
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
corePatternCategories: getBlockPatternCategories(),
|
|
52
|
-
userPatternCategories: getUserPatternCategories(),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
const categoryMap = useMemo( () => {
|
|
58
|
-
// Merge the user and core pattern categories and remove any duplicates.
|
|
59
|
-
const uniqueCategories = new Map();
|
|
60
|
-
[ ...userPatternCategories, ...corePatternCategories ].forEach(
|
|
61
|
-
( category ) => {
|
|
62
|
-
if (
|
|
63
|
-
! uniqueCategories.has( category.label ) &&
|
|
64
|
-
// There are two core categories with `Post` label so explicitly remove the one with
|
|
65
|
-
// the `query` slug to avoid any confusion.
|
|
66
|
-
category.name !== 'query'
|
|
67
|
-
) {
|
|
68
|
-
// We need to store the name separately as this is used as the slug in the
|
|
69
|
-
// taxonomy and may vary from the label.
|
|
70
|
-
uniqueCategories.set( category.label, {
|
|
71
|
-
label: category.label,
|
|
72
|
-
value: category.label,
|
|
73
|
-
name: category.name,
|
|
74
|
-
} );
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
);
|
|
78
|
-
return uniqueCategories;
|
|
79
|
-
}, [ userPatternCategories, corePatternCategories ] );
|
|
80
|
-
|
|
81
45
|
async function onCreate( patternTitle, sync ) {
|
|
82
46
|
if ( ! title || isSaving ) {
|
|
83
47
|
return;
|
|
@@ -120,16 +84,10 @@ export default function CreatePatternModal( {
|
|
|
120
84
|
*/
|
|
121
85
|
async function findOrCreateTerm( term ) {
|
|
122
86
|
try {
|
|
123
|
-
// We need to match any existing term to the correct slug to prevent duplicates, eg.
|
|
124
|
-
// the core `Headers` category uses the singular `header` as the slug.
|
|
125
|
-
const existingTerm = categoryMap.get( term );
|
|
126
|
-
const termData = existingTerm
|
|
127
|
-
? { name: existingTerm.label, slug: existingTerm.name }
|
|
128
|
-
: { name: term };
|
|
129
87
|
const newTerm = await saveEntityRecord(
|
|
130
88
|
'taxonomy',
|
|
131
89
|
CATEGORY_SLUG,
|
|
132
|
-
|
|
90
|
+
{ name: term },
|
|
133
91
|
{ throwOnError: true }
|
|
134
92
|
);
|
|
135
93
|
invalidateResolution( 'getUserPatternCategories' );
|
|
@@ -168,9 +126,8 @@ export default function CreatePatternModal( {
|
|
|
168
126
|
className="patterns-create-modal__name-input"
|
|
169
127
|
/>
|
|
170
128
|
<CategorySelector
|
|
171
|
-
|
|
129
|
+
values={ categoryTerms }
|
|
172
130
|
onChange={ setCategoryTerms }
|
|
173
|
-
categoryMap={ categoryMap }
|
|
174
131
|
/>
|
|
175
132
|
<ToggleControl
|
|
176
133
|
label={ __( 'Synced' ) }
|
|
@@ -29,7 +29,7 @@ import { PATTERN_SYNC_TYPES } from '../constants';
|
|
|
29
29
|
* @param {Object} props Component props.
|
|
30
30
|
* @param {string[]} props.clientIds Client ids of selected blocks.
|
|
31
31
|
* @param {string} props.rootClientId ID of the currently selected top-level block.
|
|
32
|
-
* @return {import('
|
|
32
|
+
* @return {import('react').ComponentType} The menu control or null.
|
|
33
33
|
*/
|
|
34
34
|
export default function PatternConvertButton( { clientIds, rootClientId } ) {
|
|
35
35
|
const { createSuccessNotice } = useDispatch( noticesStore );
|
|
@@ -1,36 +1,10 @@
|
|
|
1
1
|
.patterns-menu-items__convert-modal {
|
|
2
2
|
z-index: z-index(".patterns-menu-items__convert-modal");
|
|
3
|
-
|
|
4
|
-
// Fix the modal width to prevent added categories from stretching the modal.
|
|
5
|
-
[role="dialog"] > [role="document"] {
|
|
6
|
-
width: 350px;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
3
|
.patterns-menu-items__convert-modal-categories {
|
|
10
|
-
width:
|
|
11
|
-
position: relative;
|
|
12
|
-
min-height: 40px;
|
|
13
|
-
}
|
|
14
|
-
.components-form-token-field__suggestions-list {
|
|
15
|
-
position: absolute;
|
|
16
|
-
box-sizing: border-box;
|
|
17
|
-
z-index: 1;
|
|
18
|
-
background-color: $white;
|
|
19
|
-
// Account for the border width of the token field.
|
|
20
|
-
width: calc(100% + 2px);
|
|
21
|
-
left: -1px;
|
|
22
|
-
min-width: initial;
|
|
23
|
-
border: 1px solid var(--wp-admin-theme-color);
|
|
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;
|
|
4
|
+
max-width: 300px;
|
|
28
5
|
}
|
|
29
6
|
}
|
|
30
7
|
|
|
31
8
|
.patterns-create-modal__name-input input[type="text"] {
|
|
32
|
-
|
|
33
|
-
min-height: 40px;
|
|
34
|
-
// Override the default 1px margin-x.
|
|
35
|
-
margin: 0;
|
|
9
|
+
min-height: 34px;
|
|
36
10
|
}
|