@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
package/CHANGELOG.md
CHANGED
|
@@ -5,9 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.CATEGORY_SLUG = void 0;
|
|
7
7
|
exports.default = CategorySelector;
|
|
8
|
-
var
|
|
8
|
+
var _react = require("react");
|
|
9
9
|
var _i18n = require("@wordpress/i18n");
|
|
10
|
+
var _element = require("@wordpress/element");
|
|
10
11
|
var _components = require("@wordpress/components");
|
|
12
|
+
var _data = require("@wordpress/data");
|
|
13
|
+
var _coreData = require("@wordpress/core-data");
|
|
11
14
|
var _compose = require("@wordpress/compose");
|
|
12
15
|
var _htmlEntities = require("@wordpress/html-entities");
|
|
13
16
|
/**
|
|
@@ -17,23 +20,37 @@ var _htmlEntities = require("@wordpress/html-entities");
|
|
|
17
20
|
const unescapeString = arg => {
|
|
18
21
|
return (0, _htmlEntities.decodeEntities)(arg);
|
|
19
22
|
};
|
|
23
|
+
const EMPTY_ARRAY = [];
|
|
24
|
+
const MAX_TERMS_SUGGESTIONS = 20;
|
|
25
|
+
const DEFAULT_QUERY = {
|
|
26
|
+
per_page: MAX_TERMS_SUGGESTIONS,
|
|
27
|
+
_fields: 'id,name',
|
|
28
|
+
context: 'view'
|
|
29
|
+
};
|
|
20
30
|
const CATEGORY_SLUG = 'wp_pattern_category';
|
|
21
31
|
exports.CATEGORY_SLUG = CATEGORY_SLUG;
|
|
22
32
|
function CategorySelector({
|
|
23
|
-
|
|
24
|
-
onChange
|
|
25
|
-
categoryMap
|
|
33
|
+
values,
|
|
34
|
+
onChange
|
|
26
35
|
}) {
|
|
27
36
|
const [search, setSearch] = (0, _element.useState)('');
|
|
28
37
|
const debouncedSearch = (0, _compose.useDebounce)(setSearch, 500);
|
|
38
|
+
const {
|
|
39
|
+
searchResults
|
|
40
|
+
} = (0, _data.useSelect)(select => {
|
|
41
|
+
const {
|
|
42
|
+
getEntityRecords
|
|
43
|
+
} = select(_coreData.store);
|
|
44
|
+
return {
|
|
45
|
+
searchResults: !!search ? getEntityRecords('taxonomy', CATEGORY_SLUG, {
|
|
46
|
+
...DEFAULT_QUERY,
|
|
47
|
+
search
|
|
48
|
+
}) : EMPTY_ARRAY
|
|
49
|
+
};
|
|
50
|
+
}, [search]);
|
|
29
51
|
const suggestions = (0, _element.useMemo)(() => {
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
return category.toLowerCase().includes(search.toLowerCase());
|
|
33
|
-
}
|
|
34
|
-
return true;
|
|
35
|
-
}).sort((a, b) => a.localeCompare(b));
|
|
36
|
-
}, [search, categoryMap]);
|
|
52
|
+
return (searchResults !== null && searchResults !== void 0 ? searchResults : []).map(term => unescapeString(term.name));
|
|
53
|
+
}, [searchResults]);
|
|
37
54
|
function handleChange(termNames) {
|
|
38
55
|
const uniqueTerms = termNames.reduce((terms, newTerm) => {
|
|
39
56
|
if (!terms.some(term => term.toLowerCase() === newTerm.toLowerCase())) {
|
|
@@ -43,16 +60,15 @@ function CategorySelector({
|
|
|
43
60
|
}, []);
|
|
44
61
|
onChange(uniqueTerms);
|
|
45
62
|
}
|
|
46
|
-
return (0,
|
|
63
|
+
return (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)(_components.FormTokenField, {
|
|
47
64
|
className: "patterns-menu-items__convert-modal-categories",
|
|
48
|
-
value:
|
|
65
|
+
value: values,
|
|
49
66
|
suggestions: suggestions,
|
|
50
67
|
onChange: handleChange,
|
|
51
68
|
onInputChange: debouncedSearch,
|
|
69
|
+
maxSuggestions: MAX_TERMS_SUGGESTIONS,
|
|
52
70
|
label: (0, _i18n.__)('Categories'),
|
|
53
|
-
tokenizeOnBlur: true
|
|
54
|
-
|
|
55
|
-
__next40pxDefaultSize: true
|
|
56
|
-
});
|
|
71
|
+
tokenizeOnBlur: true
|
|
72
|
+
}));
|
|
57
73
|
}
|
|
58
74
|
//# sourceMappingURL=category-selector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_i18n","require","_element","_components","_data","_coreData","_compose","_htmlEntities","unescapeString","arg","decodeEntities","EMPTY_ARRAY","MAX_TERMS_SUGGESTIONS","DEFAULT_QUERY","per_page","_fields","context","CATEGORY_SLUG","exports","CategorySelector","values","onChange","search","setSearch","useState","debouncedSearch","useDebounce","searchResults","useSelect","select","getEntityRecords","coreStore","suggestions","useMemo","map","term","name","handleChange","termNames","uniqueTerms","reduce","terms","newTerm","some","toLowerCase","push","_react","createElement","Fragment","FormTokenField","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":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAN,OAAA;AATA;AACA;AACA;;AASA,MAAMO,cAAc,GAAKC,GAAG,IAAM;EACjC,OAAO,IAAAC,4BAAc,EAAED,GAAI,CAAC;AAC7B,CAAC;AAED,MAAME,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;AACM,MAAMC,aAAa,GAAG,qBAAqB;AAACC,OAAA,CAAAD,aAAA,GAAAA,aAAA;AAEpC,SAASE,gBAAgBA,CAAE;EAAEC,MAAM;EAAEC;AAAS,CAAC,EAAG;EAChE,MAAM,CAAEC,MAAM,EAAEC,SAAS,CAAE,GAAG,IAAAC,iBAAQ,EAAE,EAAG,CAAC;EAC5C,MAAMC,eAAe,GAAG,IAAAC,oBAAW,EAAEH,SAAS,EAAE,GAAI,CAAC;EAErD,MAAM;IAAEI;EAAc,CAAC,GAAG,IAAAC,eAAS,EAChCC,M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,QAAE,EAAE,YAAa,CAAG;IAC5BC,cAAc,EAAG;EAAM,CACvB,CACA,CAAC;AAEL"}
|
|
@@ -4,9 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = CreatePatternModal;
|
|
7
|
-
var
|
|
7
|
+
var _react = require("react");
|
|
8
8
|
var _components = require("@wordpress/components");
|
|
9
9
|
var _i18n = require("@wordpress/i18n");
|
|
10
|
+
var _element = require("@wordpress/element");
|
|
10
11
|
var _data = require("@wordpress/data");
|
|
11
12
|
var _notices = require("@wordpress/notices");
|
|
12
13
|
var _coreData = require("@wordpress/core-data");
|
|
@@ -49,38 +50,6 @@ function CreatePatternModal({
|
|
|
49
50
|
const {
|
|
50
51
|
createErrorNotice
|
|
51
52
|
} = (0, _data.useDispatch)(_notices.store);
|
|
52
|
-
const {
|
|
53
|
-
corePatternCategories,
|
|
54
|
-
userPatternCategories
|
|
55
|
-
} = (0, _data.useSelect)(select => {
|
|
56
|
-
const {
|
|
57
|
-
getUserPatternCategories,
|
|
58
|
-
getBlockPatternCategories
|
|
59
|
-
} = select(_coreData.store);
|
|
60
|
-
return {
|
|
61
|
-
corePatternCategories: getBlockPatternCategories(),
|
|
62
|
-
userPatternCategories: getUserPatternCategories()
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
const categoryMap = (0, _element.useMemo)(() => {
|
|
66
|
-
// Merge the user and core pattern categories and remove any duplicates.
|
|
67
|
-
const uniqueCategories = new Map();
|
|
68
|
-
[...userPatternCategories, ...corePatternCategories].forEach(category => {
|
|
69
|
-
if (!uniqueCategories.has(category.label) &&
|
|
70
|
-
// There are two core categories with `Post` label so explicitly remove the one with
|
|
71
|
-
// the `query` slug to avoid any confusion.
|
|
72
|
-
category.name !== 'query') {
|
|
73
|
-
// We need to store the name separately as this is used as the slug in the
|
|
74
|
-
// taxonomy and may vary from the label.
|
|
75
|
-
uniqueCategories.set(category.label, {
|
|
76
|
-
label: category.label,
|
|
77
|
-
value: category.label,
|
|
78
|
-
name: category.name
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
return uniqueCategories;
|
|
83
|
-
}, [userPatternCategories, corePatternCategories]);
|
|
84
53
|
async function onCreate(patternTitle, sync) {
|
|
85
54
|
if (!title || isSaving) {
|
|
86
55
|
return;
|
|
@@ -112,16 +81,9 @@ function CreatePatternModal({
|
|
|
112
81
|
*/
|
|
113
82
|
async function findOrCreateTerm(term) {
|
|
114
83
|
try {
|
|
115
|
-
|
|
116
|
-
// the core `Headers` category uses the singular `header` as the slug.
|
|
117
|
-
const existingTerm = categoryMap.get(term);
|
|
118
|
-
const termData = existingTerm ? {
|
|
119
|
-
name: existingTerm.label,
|
|
120
|
-
slug: existingTerm.name
|
|
121
|
-
} : {
|
|
84
|
+
const newTerm = await saveEntityRecord('taxonomy', _categorySelector.CATEGORY_SLUG, {
|
|
122
85
|
name: term
|
|
123
|
-
}
|
|
124
|
-
const newTerm = await saveEntityRecord('taxonomy', _categorySelector.CATEGORY_SLUG, termData, {
|
|
86
|
+
}, {
|
|
125
87
|
throwOnError: true
|
|
126
88
|
});
|
|
127
89
|
invalidateResolution('getUserPatternCategories');
|
|
@@ -133,47 +95,46 @@ function CreatePatternModal({
|
|
|
133
95
|
return error.data.term_id;
|
|
134
96
|
}
|
|
135
97
|
}
|
|
136
|
-
return (0,
|
|
98
|
+
return (0, _react.createElement)(_components.Modal, {
|
|
137
99
|
title: (0, _i18n.__)('Create pattern'),
|
|
138
100
|
onRequestClose: () => {
|
|
139
101
|
onClose();
|
|
140
102
|
setTitle('');
|
|
141
103
|
},
|
|
142
104
|
overlayClassName: className
|
|
143
|
-
}, (0,
|
|
105
|
+
}, (0, _react.createElement)("form", {
|
|
144
106
|
onSubmit: event => {
|
|
145
107
|
event.preventDefault();
|
|
146
108
|
onCreate(title, syncType);
|
|
147
109
|
}
|
|
148
|
-
}, (0,
|
|
110
|
+
}, (0, _react.createElement)(_components.__experimentalVStack, {
|
|
149
111
|
spacing: "5"
|
|
150
|
-
}, (0,
|
|
112
|
+
}, (0, _react.createElement)(_components.TextControl, {
|
|
151
113
|
__nextHasNoMarginBottom: true,
|
|
152
114
|
label: (0, _i18n.__)('Name'),
|
|
153
115
|
value: title,
|
|
154
116
|
onChange: setTitle,
|
|
155
117
|
placeholder: (0, _i18n.__)('My pattern'),
|
|
156
118
|
className: "patterns-create-modal__name-input"
|
|
157
|
-
}), (0,
|
|
158
|
-
|
|
159
|
-
onChange: setCategoryTerms
|
|
160
|
-
|
|
161
|
-
}), (0, _element.createElement)(_components.ToggleControl, {
|
|
119
|
+
}), (0, _react.createElement)(_categorySelector.default, {
|
|
120
|
+
values: categoryTerms,
|
|
121
|
+
onChange: setCategoryTerms
|
|
122
|
+
}), (0, _react.createElement)(_components.ToggleControl, {
|
|
162
123
|
label: (0, _i18n.__)('Synced'),
|
|
163
124
|
help: (0, _i18n.__)('Editing the pattern will update it anywhere it is used.'),
|
|
164
125
|
checked: syncType === _constants.PATTERN_SYNC_TYPES.full,
|
|
165
126
|
onChange: () => {
|
|
166
127
|
setSyncType(syncType === _constants.PATTERN_SYNC_TYPES.full ? _constants.PATTERN_SYNC_TYPES.unsynced : _constants.PATTERN_SYNC_TYPES.full);
|
|
167
128
|
}
|
|
168
|
-
}), (0,
|
|
129
|
+
}), (0, _react.createElement)(_components.__experimentalHStack, {
|
|
169
130
|
justify: "right"
|
|
170
|
-
}, (0,
|
|
131
|
+
}, (0, _react.createElement)(_components.Button, {
|
|
171
132
|
variant: "tertiary",
|
|
172
133
|
onClick: () => {
|
|
173
134
|
onClose();
|
|
174
135
|
setTitle('');
|
|
175
136
|
}
|
|
176
|
-
}, (0, _i18n.__)('Cancel')), (0,
|
|
137
|
+
}, (0, _i18n.__)('Cancel')), (0, _react.createElement)(_components.Button, {
|
|
177
138
|
variant: "primary",
|
|
178
139
|
type: "submit",
|
|
179
140
|
"aria-disabled": !title || isSaving,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_components","_i18n","_data","_notices","_coreData","_constants","_store","_categorySelector","_interopRequireWildcard","_lockUnlock","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","CreatePatternModal","onSuccess","onError","content","onClose","className","syncType","setSyncType","useState","PATTERN_SYNC_TYPES","full","categoryTerms","setCategoryTerms","title","setTitle","isSaving","setIsSaving","createPattern","unlock","useDispatch","patternsStore","saveEntityRecord","invalidateResolution","coreStore","createErrorNotice","noticesStore","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","createElement","Modal","__","onRequestClose","overlayClassName","onSubmit","event","preventDefault","__experimentalVStack","spacing","TextControl","__nextHasNoMarginBottom","onChange","placeholder","ToggleControl","help","checked","unsynced","__experimentalHStack","justify","Button","variant","onClick","isBusy"],"sources":["@wordpress/patterns/src/components/create-pattern-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tModal,\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tToggleControl,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState, useMemo } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_DEFAULT_CATEGORY, PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CategorySelector, { CATEGORY_SLUG } from './category-selector';\nimport { unlock } from '../lock-unlock';\n\nexport default function CreatePatternModal( {\n\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\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":";;;;;;AAYA,IAAAA,QAAA,GAAAC,OAAA;AATA,IAAAC,WAAA,GAAAD,OAAA;AAQA,IAAAE,KAAA,GAAAF,OAAA;AAEA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AAKA,IAAAM,UAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,iBAAA,GAAAC,uBAAA,CAAAT,OAAA;AACA,IAAAU,WAAA,GAAAV,OAAA;AAAwC,SAAAW,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAH,wBAAAO,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA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AsG,aAAA,EAACpG,WAAA,CAAAkH,aAAa;IACb5C,KAAK,EAAG,IAAAgC,QAAE,EAAE,QAAS,CAAG;IACxBa,IAAI,EAAG,IAAAb,QAAE,EACR,yDACD,CAAG;IACHc,OAAO,EAAG9E,QAAQ,KAAKG,6BAAkB,CAACC,IAAM;IAChDsE,QAAQ,EAAGA,CAAA,KAAM;MAChBzE,WAAW,CACVD,QAAQ,KAAKG,6BAAkB,CAACC,IAAI,GACjCD,6BAAkB,CAAC4E,QAAQ,GAC3B5E,6BAAkB,CAACC,IACvB,CAAC;IACF;EAAG,CACH,CAAC,EACF,IAAA5C,QAAA,CAAAsG,aAAA,EAACpG,WAAA,CAAAsH,oBAAM;IAACC,OAAO,EAAC;EAAO,GACtB,IAAAzH,QAAA,CAAAsG,aAAA,EAACpG,WAAA,CAAAwH,MAAM;IACNC,OAAO,EAAC,UAAU;IAClBC,OAAO,EAAGA,CAAA,KAAM;MACftF,OAAO,CAAC,CAAC;MACTU,QAAQ,CAAE,EAAG,CAAC;IACf;EAAG,GAED,IAAAwD,QAAE,EAAE,QAAS,CACR,CAAC,EAET,IAAAxG,QAAA,CAAAsG,aAAA,EAACpG,WAAA,CAAAwH,MAAM;IACNC,OAAO,EAAC,SAAS;IACjBjC,IAAI,EAAC,QAAQ;IACb,iBAAgB,CAAE3C,KAAK,IAAIE,QAAU;IACrC4E,MAAM,EAAG5E;EAAU,GAEjB,IAAAuD,QAAE,EAAE,QAAS,CACR,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_element","_data","_notices","_coreData","_constants","_store","_categorySelector","_interopRequireWildcard","_lockUnlock","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","CreatePatternModal","onSuccess","onError","content","onClose","className","syncType","setSyncType","useState","PATTERN_SYNC_TYPES","full","categoryTerms","setCategoryTerms","title","setTitle","isSaving","setIsSaving","createPattern","unlock","useDispatch","patternsStore","saveEntityRecord","invalidateResolution","coreStore","createErrorNotice","noticesStore","onCreate","patternTitle","sync","categories","Promise","all","map","termName","findOrCreateTerm","newPattern","pattern","categoryId","PATTERN_DEFAULT_CATEGORY","error","message","type","id","term","newTerm","CATEGORY_SLUG","name","throwOnError","code","data","term_id","_react","createElement","Modal","__","onRequestClose","overlayClassName","onSubmit","event","preventDefault","__experimentalVStack","spacing","TextControl","__nextHasNoMarginBottom","label","value","onChange","placeholder","values","ToggleControl","help","checked","unsynced","__experimentalHStack","justify","Button","variant","onClick","isBusy"],"sources":["@wordpress/patterns/src/components/create-pattern-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tModal,\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n\tToggleControl,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_DEFAULT_CATEGORY, PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport CategorySelector, { CATEGORY_SLUG } from './category-selector';\nimport { unlock } from '../lock-unlock';\n\nexport default function CreatePatternModal( {\n\tonSuccess,\n\tonError,\n\tcontent,\n\tonClose,\n\tclassName = 'patterns-menu-items__convert-modal',\n} ) {\n\tconst [ syncType, setSyncType ] = useState( PATTERN_SYNC_TYPES.full );\n\tconst [ categoryTerms, setCategoryTerms ] = useState( [] );\n\tconst [ title, setTitle ] = useState( '' );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\tconst { createPattern } = unlock( useDispatch( patternsStore ) );\n\tconst { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tasync function onCreate( patternTitle, sync ) {\n\t\tif ( ! title || isSaving ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSaving( true );\n\t\t\tconst categories = await Promise.all(\n\t\t\t\tcategoryTerms.map( ( termName ) =>\n\t\t\t\t\tfindOrCreateTerm( termName )\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tconst newPattern = await createPattern(\n\t\t\t\tpatternTitle,\n\t\t\t\tsync,\n\t\t\t\ttypeof content === 'function' ? content() : content,\n\t\t\t\tcategories\n\t\t\t);\n\t\t\tonSuccess( {\n\t\t\t\tpattern: newPattern,\n\t\t\t\tcategoryId: PATTERN_DEFAULT_CATEGORY,\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tcreateErrorNotice( error.message, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'convert-to-pattern-error',\n\t\t\t} );\n\t\t\tonError();\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t\tsetCategoryTerms( [] );\n\t\t\tsetTitle( '' );\n\t\t}\n\t}\n\n\t/**\n\t * @param {string} term\n\t * @return {Promise<number>} The pattern category id.\n\t */\n\tasync function findOrCreateTerm( term ) {\n\t\ttry {\n\t\t\tconst newTerm = await saveEntityRecord(\n\t\t\t\t'taxonomy',\n\t\t\t\tCATEGORY_SLUG,\n\t\t\t\t{ name: term },\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tinvalidateResolution( 'getUserPatternCategories' );\n\t\t\treturn newTerm.id;\n\t\t} catch ( error ) {\n\t\t\tif ( error.code !== 'term_exists' ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\treturn error.data.term_id;\n\t\t}\n\t}\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Create pattern' ) }\n\t\t\tonRequestClose={ () => {\n\t\t\t\tonClose();\n\t\t\t\tsetTitle( '' );\n\t\t\t} }\n\t\t\toverlayClassName={ className }\n\t\t>\n\t\t\t<form\n\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tonCreate( title, syncType );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\tplaceholder={ __( 'My pattern' ) }\n\t\t\t\t\t\tclassName=\"patterns-create-modal__name-input\"\n\t\t\t\t\t/>\n\t\t\t\t\t<CategorySelector\n\t\t\t\t\t\tvalues={ categoryTerms }\n\t\t\t\t\t\tonChange={ setCategoryTerms }\n\t\t\t\t\t/>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Synced' ) }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Editing the pattern will update it anywhere it is used.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tchecked={ syncType === PATTERN_SYNC_TYPES.full }\n\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\tsetSyncType(\n\t\t\t\t\t\t\t\tsyncType === PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t\t\t? PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t\t\t\t\t\t: PATTERN_SYNC_TYPES.full\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</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,6BAAkB,CAACC,IAAM;IAChDwD,QAAQ,EAAGA,CAAA,KAAM;MAChB3D,WAAW,CACVD,QAAQ,KAAKG,6BAAkB,CAACC,IAAI,GACjCD,6BAAkB,CAAC+D,QAAQ,GAC3B/D,6BAAkB,CAACC,IACvB,CAAC;IACF;EAAG,CACH,CAAC,EACF,IAAAyC,MAAA,CAAAC,aAAA,EAACtF,WAAA,CAAA2G,oBAAM;IAACC,OAAO,EAAC;EAAO,GACtB,IAAAvB,MAAA,CAAAC,aAAA,EAACtF,WAAA,CAAA6G,MAAM;IACNC,OAAO,EAAC,UAAU;IAClBC,OAAO,EAAGA,CAAA,KAAM;MACfzE,OAAO,CAAC,CAAC;MACTU,QAAQ,CAAE,EAAG,CAAC;IACf;EAAG,GAED,IAAAwC,QAAE,EAAE,QAAS,CACR,CAAC,EAET,IAAAH,MAAA,CAAAC,aAAA,EAACtF,WAAA,CAAA6G,MAAM;IACNC,OAAO,EAAC,SAAS;IACjBnC,IAAI,EAAC,QAAQ;IACb,iBAAgB,CAAE5B,KAAK,IAAIE,QAAU;IACrC+D,MAAM,EAAG/D;EAAU,GAEjB,IAAAuC,QAAE,EAAE,QAAS,CACR,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = PatternsMenuItems;
|
|
8
|
-
var
|
|
8
|
+
var _react = require("react");
|
|
9
9
|
var _blockEditor = require("@wordpress/block-editor");
|
|
10
10
|
var _patternConvertButton = _interopRequireDefault(require("./pattern-convert-button"));
|
|
11
11
|
var _patternsManageButton = _interopRequireDefault(require("./patterns-manage-button"));
|
|
@@ -20,12 +20,12 @@ var _patternsManageButton = _interopRequireDefault(require("./patterns-manage-bu
|
|
|
20
20
|
function PatternsMenuItems({
|
|
21
21
|
rootClientId
|
|
22
22
|
}) {
|
|
23
|
-
return (0,
|
|
23
|
+
return (0, _react.createElement)(_blockEditor.BlockSettingsMenuControls, null, ({
|
|
24
24
|
selectedClientIds
|
|
25
|
-
}) => (0,
|
|
25
|
+
}) => (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)(_patternConvertButton.default, {
|
|
26
26
|
clientIds: selectedClientIds,
|
|
27
27
|
rootClientId: rootClientId
|
|
28
|
-
}), selectedClientIds.length === 1 && (0,
|
|
28
|
+
}), selectedClientIds.length === 1 && (0, _react.createElement)(_patternsManageButton.default, {
|
|
29
29
|
clientId: selectedClientIds[0]
|
|
30
30
|
})));
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_blockEditor","require","_patternConvertButton","_interopRequireDefault","_patternsManageButton","PatternsMenuItems","rootClientId","
|
|
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;EAAkB,CAAC,KACxB,IAAAH,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAI,QAAA,QACC,IAAAJ,MAAA,CAAAC,aAAA,EAACN,qBAAA,CAAAU,OAAoB;IACpBC,SAAS,EAAGH,iBAAmB;IAC/BJ,YAAY,EAAGA;EAAc,CAC7B,CAAC,EACAI,iBAAiB,CAACI,MAAM,KAAK,CAAC,IAC/B,IAAAP,MAAA,CAAAC,aAAA,EAACJ,qBAAA,CAAAQ,OAAoB;IACpBG,QAAQ,EAAGL,iBAAiB,CAAE,CAAC;EAAI,CACnC,CAED,CAEuB,CAAC;AAE9B"}
|
|
@@ -5,9 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = PatternConvertButton;
|
|
8
|
-
var
|
|
8
|
+
var _react = require("react");
|
|
9
9
|
var _blocks = require("@wordpress/blocks");
|
|
10
10
|
var _blockEditor = require("@wordpress/block-editor");
|
|
11
|
+
var _element = require("@wordpress/element");
|
|
11
12
|
var _components = require("@wordpress/components");
|
|
12
13
|
var _icons = require("@wordpress/icons");
|
|
13
14
|
var _data = require("@wordpress/data");
|
|
@@ -32,7 +33,7 @@ var _constants = require("../constants");
|
|
|
32
33
|
* @param {Object} props Component props.
|
|
33
34
|
* @param {string[]} props.clientIds Client ids of selected blocks.
|
|
34
35
|
* @param {string} props.rootClientId ID of the currently selected top-level block.
|
|
35
|
-
* @return {import('
|
|
36
|
+
* @return {import('react').ComponentType} The menu control or null.
|
|
36
37
|
*/
|
|
37
38
|
function PatternConvertButton({
|
|
38
39
|
clientIds,
|
|
@@ -105,12 +106,12 @@ function PatternConvertButton({
|
|
|
105
106
|
});
|
|
106
107
|
setIsModalOpen(false);
|
|
107
108
|
};
|
|
108
|
-
return (0,
|
|
109
|
+
return (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)(_components.MenuItem, {
|
|
109
110
|
icon: _icons.symbol,
|
|
110
111
|
onClick: () => setIsModalOpen(true),
|
|
111
112
|
"aria-expanded": isModalOpen,
|
|
112
113
|
"aria-haspopup": "dialog"
|
|
113
|
-
}, (0, _i18n.__)('Create pattern')), isModalOpen && (0,
|
|
114
|
+
}, (0, _i18n.__)('Create pattern')), isModalOpen && (0, _react.createElement)(_createPatternModal.default, {
|
|
114
115
|
content: getContent,
|
|
115
116
|
onSuccess: pattern => {
|
|
116
117
|
handleSuccess(pattern);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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 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":";;;;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AAMA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AACA,IAAAQ,QAAA,GAAAR,OAAA;AAIA,IAAAS,MAAA,GAAAT,OAAA;AACA,IAAAU,mBAAA,GAAAC,sBAA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ACC,QAAQ,GAC3D,IAAAK,aAAO;IACP;IACA,IAAAC,QAAE,EAAE,8BAA+B,CAAC,EACpCT,OAAO,CAACU,KAAK,CAACC,GACd,CAAC,GACD,IAAAH,aAAO;IACP;IACA,IAAAC,QAAE,EAAE,4BAA6B,CAAC,EAClCT,OAAO,CAACU,KAAK,CAACC,GACd,CAAC,EACJ;MACCC,IAAI,EAAE,UAAU;MAChBN,EAAE,EAAE;IACL,CACD,CAAC;IACDpC,cAAc,CAAE,KAAM,CAAC;EACxB,CAAC;EACD,OACC,IAAA2C,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAE,QAAA,QACC,IAAAF,MAAA,CAAAC,aAAA,EAACnE,WAAA,CAAAqE,QAAQ;IACRC,IAAI,EAAGC,aAAQ;IACfC,OAAO,EAAGA,CAAA,KAAMjD,cAAc,CAAE,IAAK,CAAG;IACxC,iBAAgBD,WAAa;IAC7B,iBAAc;EAAQ,GAEpB,IAAAwC,QAAE,EAAE,gBAAiB,CACd,CAAC,EACTxC,WAAW,IACZ,IAAA4C,MAAA,CAAAC,aAAA,EAAC5D,mBAAA,CAAAkE,OAAkB;IAClBC,OAAO,EAAGzB,UAAY;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"}
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _react = require("react");
|
|
8
8
|
var _components = require("@wordpress/components");
|
|
9
9
|
var _i18n = require("@wordpress/i18n");
|
|
10
10
|
var _blocks = require("@wordpress/blocks");
|
|
@@ -65,9 +65,9 @@ function PatternsManageButton({
|
|
|
65
65
|
if (!isVisible) {
|
|
66
66
|
return null;
|
|
67
67
|
}
|
|
68
|
-
return (0,
|
|
68
|
+
return (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)(_components.MenuItem, {
|
|
69
69
|
href: managePatternsUrl
|
|
70
|
-
}, (0, _i18n.__)('Manage patterns')), canRemove && (0,
|
|
70
|
+
}, (0, _i18n.__)('Manage patterns')), canRemove && (0, _react.createElement)(_components.MenuItem, {
|
|
71
71
|
onClick: () => convertSyncedPatternToStatic(clientId)
|
|
72
72
|
}, innerBlockCount > 1 ? (0, _i18n.__)('Detach patterns') : (0, _i18n.__)('Detach pattern')));
|
|
73
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_i18n","_blocks","_data","_blockEditor","_url","_coreData","_store","_lockUnlock","PatternsManageButton","clientId","canRemove","isVisible","innerBlockCount","managePatternsUrl","useSelect","select","getBlock","canRemoveBlock","getBlockCount","getSettings","blockEditorStore","canUser","coreStore","reusableBlock","isBlockTheme","__unstableIsBlockBasedTheme","isReusableBlock","attributes","ref","addQueryArgs","path","post_type","convertSyncedPatternToStatic","unlock","useDispatch","patternsStore","
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_blocks","_data","_blockEditor","_url","_coreData","_store","_lockUnlock","PatternsManageButton","clientId","canRemove","isVisible","innerBlockCount","managePatternsUrl","useSelect","select","getBlock","canRemoveBlock","getBlockCount","getSettings","blockEditorStore","canUser","coreStore","reusableBlock","isBlockTheme","__unstableIsBlockBasedTheme","isReusableBlock","attributes","ref","addQueryArgs","path","post_type","convertSyncedPatternToStatic","unlock","useDispatch","patternsStore","_react","createElement","Fragment","MenuItem","href","__","onClick","_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, innerBlockCount, managePatternsUrl } =\n\t\tuseSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst { getBlock, canRemoveBlock, getBlockCount, getSettings } =\n\t\t\t\t\tselect( blockEditorStore );\n\t\t\t\tconst { canUser } = select( coreStore );\n\t\t\t\tconst reusableBlock = getBlock( clientId );\n\t\t\t\tconst isBlockTheme = getSettings().__unstableIsBlockBasedTheme;\n\n\t\t\t\treturn {\n\t\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\t\tisVisible:\n\t\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t\t!! canUser(\n\t\t\t\t\t\t\t'update',\n\t\t\t\t\t\t\t'blocks',\n\t\t\t\t\t\t\treusableBlock.attributes.ref\n\t\t\t\t\t\t),\n\t\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t\t// The site editor and templates both check whether the user\n\t\t\t\t\t// has edit_theme_options capabilities. We can leverage that here\n\t\t\t\t\t// and omit the manage patterns link if the user can't access it.\n\t\t\t\t\tmanagePatternsUrl:\n\t\t\t\t\t\tisBlockTheme && canUser( 'read', 'templates' )\n\t\t\t\t\t\t\t? addQueryArgs( 'site-editor.php', {\n\t\t\t\t\t\t\t\t\tpath: '/patterns',\n\t\t\t\t\t\t\t } )\n\t\t\t\t\t\t\t: addQueryArgs( 'edit.php', {\n\t\t\t\t\t\t\t\t\tpost_type: 'wp_block',\n\t\t\t\t\t\t\t } ),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ clientId ]\n\t\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<MenuItem href={ managePatternsUrl }>\n\t\t\t\t{ __( 'Manage patterns' ) }\n\t\t\t</MenuItem>\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{ innerBlockCount > 1\n\t\t\t\t\t\t? __( 'Detach patterns' )\n\t\t\t\t\t\t: __( 'Detach pattern' ) }\n\t\t\t\t</MenuItem>\n\t\t\t) }\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,eAAe;IAAEC;EAAkB,CAAC,GACjE,IAAAC,eAAS,EACNC,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,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,IAAAA,QAAE,EAAE,gBAAiB,CACf,CAEV,CAAC;AAEL;AAAC,IAAAE,QAAA,GAEcnC,oBAAoB;AAAAoC,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
package/build/lock-unlock.js
CHANGED
|
@@ -12,7 +12,7 @@ var _privateApis = require("@wordpress/private-apis");
|
|
|
12
12
|
const {
|
|
13
13
|
lock,
|
|
14
14
|
unlock
|
|
15
|
-
} = (0, _privateApis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I know using unstable features means my
|
|
15
|
+
} = (0, _privateApis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', '@wordpress/patterns');
|
|
16
16
|
exports.unlock = unlock;
|
|
17
17
|
exports.lock = lock;
|
|
18
18
|
//# sourceMappingURL=lock-unlock.js.map
|
package/build/lock-unlock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_privateApis","require","lock","unlock","__dangerousOptInToUnstableAPIsOnlyForCoreModules","exports"],"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":["_privateApis","require","lock","unlock","__dangerousOptInToUnstableAPIsOnlyForCoreModules","exports"],"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":";;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAEO,MAAM;EAAEC,IAAI;EAAEC;AAAO,CAAC,GAC5B,IAAAC,6DAAgD,EAC/C,8GAA8G,EAC9G,qBACD,CAAC;AAACC,OAAA,CAAAF,MAAA,GAAAA,MAAA;AAAAE,OAAA,CAAAH,IAAA,GAAAA,IAAA"}
|
|
@@ -1,31 +1,47 @@
|
|
|
1
|
-
import { createElement } from "
|
|
1
|
+
import { createElement, Fragment } from "react";
|
|
2
2
|
/**
|
|
3
3
|
* WordPress dependencies
|
|
4
4
|
*/
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
6
|
import { useMemo, useState } from '@wordpress/element';
|
|
7
7
|
import { FormTokenField } from '@wordpress/components';
|
|
8
|
+
import { useSelect } from '@wordpress/data';
|
|
9
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
8
10
|
import { useDebounce } from '@wordpress/compose';
|
|
9
11
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
10
12
|
const unescapeString = arg => {
|
|
11
13
|
return decodeEntities(arg);
|
|
12
14
|
};
|
|
15
|
+
const EMPTY_ARRAY = [];
|
|
16
|
+
const MAX_TERMS_SUGGESTIONS = 20;
|
|
17
|
+
const DEFAULT_QUERY = {
|
|
18
|
+
per_page: MAX_TERMS_SUGGESTIONS,
|
|
19
|
+
_fields: 'id,name',
|
|
20
|
+
context: 'view'
|
|
21
|
+
};
|
|
13
22
|
export const CATEGORY_SLUG = 'wp_pattern_category';
|
|
14
23
|
export default function CategorySelector({
|
|
15
|
-
|
|
16
|
-
onChange
|
|
17
|
-
categoryMap
|
|
24
|
+
values,
|
|
25
|
+
onChange
|
|
18
26
|
}) {
|
|
19
27
|
const [search, setSearch] = useState('');
|
|
20
28
|
const debouncedSearch = useDebounce(setSearch, 500);
|
|
29
|
+
const {
|
|
30
|
+
searchResults
|
|
31
|
+
} = useSelect(select => {
|
|
32
|
+
const {
|
|
33
|
+
getEntityRecords
|
|
34
|
+
} = select(coreStore);
|
|
35
|
+
return {
|
|
36
|
+
searchResults: !!search ? getEntityRecords('taxonomy', CATEGORY_SLUG, {
|
|
37
|
+
...DEFAULT_QUERY,
|
|
38
|
+
search
|
|
39
|
+
}) : EMPTY_ARRAY
|
|
40
|
+
};
|
|
41
|
+
}, [search]);
|
|
21
42
|
const suggestions = useMemo(() => {
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
return category.toLowerCase().includes(search.toLowerCase());
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
27
|
-
}).sort((a, b) => a.localeCompare(b));
|
|
28
|
-
}, [search, categoryMap]);
|
|
43
|
+
return (searchResults !== null && searchResults !== void 0 ? searchResults : []).map(term => unescapeString(term.name));
|
|
44
|
+
}, [searchResults]);
|
|
29
45
|
function handleChange(termNames) {
|
|
30
46
|
const uniqueTerms = termNames.reduce((terms, newTerm) => {
|
|
31
47
|
if (!terms.some(term => term.toLowerCase() === newTerm.toLowerCase())) {
|
|
@@ -35,16 +51,15 @@ export default function CategorySelector({
|
|
|
35
51
|
}, []);
|
|
36
52
|
onChange(uniqueTerms);
|
|
37
53
|
}
|
|
38
|
-
return createElement(FormTokenField, {
|
|
54
|
+
return createElement(Fragment, null, createElement(FormTokenField, {
|
|
39
55
|
className: "patterns-menu-items__convert-modal-categories",
|
|
40
|
-
value:
|
|
56
|
+
value: values,
|
|
41
57
|
suggestions: suggestions,
|
|
42
58
|
onChange: handleChange,
|
|
43
59
|
onInputChange: debouncedSearch,
|
|
60
|
+
maxSuggestions: MAX_TERMS_SUGGESTIONS,
|
|
44
61
|
label: __('Categories'),
|
|
45
|
-
tokenizeOnBlur: true
|
|
46
|
-
|
|
47
|
-
__next40pxDefaultSize: true
|
|
48
|
-
});
|
|
62
|
+
tokenizeOnBlur: true
|
|
63
|
+
}));
|
|
49
64
|
}
|
|
50
65
|
//# sourceMappingURL=category-selector.js.map
|