PluginProbe
Gutenberg / 22.3.0
Gutenberg v22.3.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / scripts / core-commands / index.js

index.js in Gutenberg 22.3.0, at build/scripts/core-commands/index.js

713 lines 27.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var wp;
2 (wp ||= {}).coreCommands = (() => {
3 var __create = Object.create;
4 var __defProp = Object.defineProperty;
5 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6 var __getOwnPropNames = Object.getOwnPropertyNames;
7 var __getProtoOf = Object.getPrototypeOf;
8 var __hasOwnProp = Object.prototype.hasOwnProperty;
9 var __commonJS = (cb, mod) => function __require() {
10 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11 };
12 var __export = (target, all) => {
13 for (var name in all)
14 __defProp(target, name, { get: all[name], enumerable: true });
15 };
16 var __copyProps = (to, from, except, desc) => {
17 if (from && typeof from === "object" || typeof from === "function") {
18 for (let key of __getOwnPropNames(from))
19 if (!__hasOwnProp.call(to, key) && key !== except)
20 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21 }
22 return to;
23 };
24 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25 // If the importer is in node compatibility mode or this is not an ESM
26 // file that has been converted to a CommonJS file using a Babel-
27 // compatible transform (i.e. "__esModule" has not been set), then set
28 // "default" to the CommonJS "module.exports" for node compatibility.
29 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30 mod
31 ));
32 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
34 // package-external:@wordpress/element
35 var require_element = __commonJS({
36 "package-external:@wordpress/element"(exports, module) {
37 module.exports = window.wp.element;
38 }
39 });
40
41 // package-external:@wordpress/router
42 var require_router = __commonJS({
43 "package-external:@wordpress/router"(exports, module) {
44 module.exports = window.wp.router;
45 }
46 });
47
48 // package-external:@wordpress/commands
49 var require_commands = __commonJS({
50 "package-external:@wordpress/commands"(exports, module) {
51 module.exports = window.wp.commands;
52 }
53 });
54
55 // package-external:@wordpress/i18n
56 var require_i18n = __commonJS({
57 "package-external:@wordpress/i18n"(exports, module) {
58 module.exports = window.wp.i18n;
59 }
60 });
61
62 // package-external:@wordpress/primitives
63 var require_primitives = __commonJS({
64 "package-external:@wordpress/primitives"(exports, module) {
65 module.exports = window.wp.primitives;
66 }
67 });
68
69 // vendor-external:react/jsx-runtime
70 var require_jsx_runtime = __commonJS({
71 "vendor-external:react/jsx-runtime"(exports, module) {
72 module.exports = window.ReactJSXRuntime;
73 }
74 });
75
76 // package-external:@wordpress/core-data
77 var require_core_data = __commonJS({
78 "package-external:@wordpress/core-data"(exports, module) {
79 module.exports = window.wp.coreData;
80 }
81 });
82
83 // package-external:@wordpress/data
84 var require_data = __commonJS({
85 "package-external:@wordpress/data"(exports, module) {
86 module.exports = window.wp.data;
87 }
88 });
89
90 // package-external:@wordpress/url
91 var require_url = __commonJS({
92 "package-external:@wordpress/url"(exports, module) {
93 module.exports = window.wp.url;
94 }
95 });
96
97 // package-external:@wordpress/compose
98 var require_compose = __commonJS({
99 "package-external:@wordpress/compose"(exports, module) {
100 module.exports = window.wp.compose;
101 }
102 });
103
104 // package-external:@wordpress/html-entities
105 var require_html_entities = __commonJS({
106 "package-external:@wordpress/html-entities"(exports, module) {
107 module.exports = window.wp.htmlEntities;
108 }
109 });
110
111 // package-external:@wordpress/private-apis
112 var require_private_apis = __commonJS({
113 "package-external:@wordpress/private-apis"(exports, module) {
114 module.exports = window.wp.privateApis;
115 }
116 });
117
118 // packages/core-commands/build-module/index.js
119 var index_exports = {};
120 __export(index_exports, {
121 initializeCommandPalette: () => initializeCommandPalette,
122 privateApis: () => privateApis
123 });
124 var import_element3 = __toESM(require_element());
125 var import_router2 = __toESM(require_router());
126 var import_commands3 = __toESM(require_commands());
127
128 // packages/core-commands/build-module/admin-navigation-commands.js
129 var import_commands = __toESM(require_commands());
130 var import_i18n = __toESM(require_i18n());
131
132 // packages/icons/build-module/library/brush.js
133 var import_primitives = __toESM(require_primitives());
134 var import_jsx_runtime = __toESM(require_jsx_runtime());
135 var brush_default = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.Path, { d: "M4 20h8v-1.5H4V20zM18.9 3.5c-.6-.6-1.5-.6-2.1 0l-7.2 7.2c-.4-.1-.7 0-1.1.1-.5.2-1.5.7-1.9 2.2-.4 1.7-.8 2.2-1.1 2.7-.1.1-.2.3-.3.4l-.6 1.1H6c2 0 3.4-.4 4.7-1.4.8-.6 1.2-1.4 1.3-2.3 0-.3 0-.5-.1-.7L19 5.7c.5-.6.5-1.6-.1-2.2zM9.7 14.7c-.7.5-1.5.8-2.4 1 .2-.5.5-1.2.8-2.3.2-.6.4-1 .8-1.1.5-.1 1 .1 1.3.3.2.2.3.5.2.8 0 .3-.1.9-.7 1.3z" }) });
136
137 // packages/icons/build-module/library/external.js
138 var import_primitives2 = __toESM(require_primitives());
139 var import_jsx_runtime2 = __toESM(require_jsx_runtime());
140 var external_default = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.Path, { d: "M19.5 4.5h-7V6h4.44l-5.97 5.97 1.06 1.06L18 7.06v4.44h1.5v-7Zm-13 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-3H17v3a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h3V5.5h-3Z" }) });
141
142 // packages/icons/build-module/library/layout.js
143 var import_primitives3 = __toESM(require_primitives());
144 var import_jsx_runtime3 = __toESM(require_jsx_runtime());
145 var layout_default = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.Path, { d: "M18 5.5H6a.5.5 0 00-.5.5v3h13V6a.5.5 0 00-.5-.5zm.5 5H10v8h8a.5.5 0 00.5-.5v-7.5zm-10 0h-3V18a.5.5 0 00.5.5h2.5v-8zM6 4h12a2 2 0 012 2v12a2 2 0 01-2 2H6a2 2 0 01-2-2V6a2 2 0 012-2z" }) });
146
147 // packages/icons/build-module/library/navigation.js
148 var import_primitives4 = __toESM(require_primitives());
149 var import_jsx_runtime4 = __toESM(require_jsx_runtime());
150 var navigation_default = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.Path, { d: "M12 4c-4.4 0-8 3.6-8 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zm0 14.5c-3.6 0-6.5-2.9-6.5-6.5S8.4 5.5 12 5.5s6.5 2.9 6.5 6.5-2.9 6.5-6.5 6.5zM9 16l4.5-3L15 8.4l-4.5 3L9 16z" }) });
151
152 // packages/icons/build-module/library/page.js
153 var import_primitives5 = __toESM(require_primitives());
154 var import_jsx_runtime5 = __toESM(require_jsx_runtime());
155 var page_default = /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_primitives5.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: [
156 /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives5.Path, { d: "M15.5 7.5h-7V9h7V7.5Zm-7 3.5h7v1.5h-7V11Zm7 3.5h-7V16h7v-1.5Z" }),
157 /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives5.Path, { d: "M17 4H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2ZM7 5.5h10a.5.5 0 0 1 .5.5v12a.5.5 0 0 1-.5.5H7a.5.5 0 0 1-.5-.5V6a.5.5 0 0 1 .5-.5Z" })
158 ] });
159
160 // packages/icons/build-module/library/post.js
161 var import_primitives6 = __toESM(require_primitives());
162 var import_jsx_runtime6 = __toESM(require_jsx_runtime());
163 var post_default = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_primitives6.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_primitives6.Path, { d: "m7.3 9.7 1.4 1.4c.2-.2.3-.3.4-.5 0 0 0-.1.1-.1.3-.5.4-1.1.3-1.6L12 7 9 4 7.2 6.5c-.6-.1-1.1 0-1.6.3 0 0-.1 0-.1.1-.3.1-.4.2-.6.4l1.4 1.4L4 11v1h1l2.3-2.3zM4 20h9v-1.5H4V20zm0-5.5V16h16v-1.5H4z" }) });
164
165 // packages/icons/build-module/library/styles.js
166 var import_primitives7 = __toESM(require_primitives());
167 var import_jsx_runtime7 = __toESM(require_jsx_runtime());
168 var styles_default = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_primitives7.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
169 import_primitives7.Path,
170 {
171 fillRule: "evenodd",
172 clipRule: "evenodd",
173 d: "M20 12a8 8 0 1 1-16 0 8 8 0 0 1 16 0Zm-1.5 0a6.5 6.5 0 0 1-6.5 6.5v-13a6.5 6.5 0 0 1 6.5 6.5Z"
174 }
175 ) });
176
177 // packages/icons/build-module/library/symbol-filled.js
178 var import_primitives8 = __toESM(require_primitives());
179 var import_jsx_runtime8 = __toESM(require_jsx_runtime());
180 var symbol_filled_default = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_primitives8.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_primitives8.Path, { d: "M21.3 10.8l-5.6-5.6c-.7-.7-1.8-.7-2.5 0l-5.6 5.6c-.7.7-.7 1.8 0 2.5l5.6 5.6c.3.3.8.5 1.2.5s.9-.2 1.2-.5l5.6-5.6c.8-.7.8-1.9.1-2.5zm-17.6 1L10 5.5l-1-1-6.3 6.3c-.7.7-.7 1.8 0 2.5L9 19.5l1.1-1.1-6.3-6.3c-.2 0-.2-.2-.1-.3z" }) });
181
182 // packages/icons/build-module/library/symbol.js
183 var import_primitives9 = __toESM(require_primitives());
184 var import_jsx_runtime9 = __toESM(require_jsx_runtime());
185 var symbol_default = /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_primitives9.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_primitives9.Path, { d: "M21.3 10.8l-5.6-5.6c-.7-.7-1.8-.7-2.5 0l-5.6 5.6c-.7.7-.7 1.8 0 2.5l5.6 5.6c.3.3.8.5 1.2.5s.9-.2 1.2-.5l5.6-5.6c.8-.7.8-1.9.1-2.5zm-1 1.4l-5.6 5.6c-.1.1-.3.1-.4 0l-5.6-5.6c-.1-.1-.1-.3 0-.4l5.6-5.6s.1-.1.2-.1.1 0 .2.1l5.6 5.6c.1.1.1.3 0 .4zm-16.6-.4L10 5.5l-1-1-6.3 6.3c-.7.7-.7 1.8 0 2.5L9 19.5l1.1-1.1-6.3-6.3c-.2 0-.2-.2-.1-.3z" }) });
186
187 // packages/core-commands/build-module/admin-navigation-commands.js
188 var import_element = __toESM(require_element());
189 var import_core_data = __toESM(require_core_data());
190 var import_data = __toESM(require_data());
191 var getViewSiteCommand = () => function useViewSiteCommand() {
192 const homeUrl = (0, import_data.useSelect)((select) => {
193 return select(import_core_data.store).getEntityRecord(
194 "root",
195 "__unstableBase"
196 )?.home;
197 }, []);
198 const commands = (0, import_element.useMemo)(() => {
199 if (!homeUrl) {
200 return [];
201 }
202 return [
203 {
204 name: "core/view-site",
205 label: (0, import_i18n.__)("View site"),
206 icon: external_default,
207 callback: ({ close }) => {
208 close();
209 window.open(homeUrl, "_blank");
210 }
211 }
212 ];
213 }, [homeUrl]);
214 return {
215 isLoading: false,
216 commands
217 };
218 };
219 function useAdminNavigationCommands(menuCommands) {
220 const commands = (0, import_element.useMemo)(() => {
221 return (menuCommands ?? []).map((menuCommand) => {
222 const label = (0, import_i18n.sprintf)(
223 /* translators: %s: menu label */
224 (0, import_i18n.__)("Go to: %s"),
225 menuCommand.label
226 );
227 return {
228 name: menuCommand.name,
229 label,
230 searchLabel: label,
231 callback: ({ close }) => {
232 document.location = menuCommand.url;
233 close();
234 }
235 };
236 });
237 }, [menuCommands]);
238 (0, import_commands.useCommands)(commands);
239 (0, import_commands.useCommandLoader)({
240 name: "core/view-site",
241 hook: getViewSiteCommand()
242 });
243 }
244
245 // packages/core-commands/build-module/site-editor-navigation-commands.js
246 var import_commands2 = __toESM(require_commands());
247 var import_i18n2 = __toESM(require_i18n());
248 var import_element2 = __toESM(require_element());
249 var import_data2 = __toESM(require_data());
250 var import_core_data2 = __toESM(require_core_data());
251 var import_router = __toESM(require_router());
252 var import_url = __toESM(require_url());
253 var import_compose = __toESM(require_compose());
254 var import_html_entities = __toESM(require_html_entities());
255
256 // packages/core-commands/build-module/lock-unlock.js
257 var import_private_apis = __toESM(require_private_apis());
258 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
259 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
260 "@wordpress/core-commands"
261 );
262
263 // packages/core-commands/build-module/utils/order-entity-records-by-search.js
264 function orderEntityRecordsBySearch(records = [], search = "") {
265 if (!Array.isArray(records) || !records.length) {
266 return [];
267 }
268 if (!search) {
269 return records;
270 }
271 const priority = [];
272 const nonPriority = [];
273 for (let i = 0; i < records.length; i++) {
274 const record = records[i];
275 if (record?.title?.raw?.toLowerCase()?.includes(search?.toLowerCase())) {
276 priority.push(record);
277 } else {
278 nonPriority.push(record);
279 }
280 }
281 return priority.concat(nonPriority);
282 }
283
284 // packages/core-commands/build-module/site-editor-navigation-commands.js
285 var { useHistory } = unlock(import_router.privateApis);
286 var icons = {
287 post: post_default,
288 page: page_default,
289 wp_template: layout_default,
290 wp_template_part: symbol_filled_default
291 };
292 function useDebouncedValue(value) {
293 const [debouncedValue, setDebouncedValue] = (0, import_element2.useState)("");
294 const debounced = (0, import_compose.useDebounce)(setDebouncedValue, 250);
295 (0, import_element2.useEffect)(() => {
296 debounced(value);
297 return () => debounced.cancel();
298 }, [debounced, value]);
299 return debouncedValue;
300 }
301 var getNavigationCommandLoaderPerPostType = (postType) => function useNavigationCommandLoader({ search }) {
302 const history = useHistory();
303 const { isBlockBasedTheme, canCreateTemplate } = (0, import_data2.useSelect)(
304 (select) => {
305 return {
306 isBlockBasedTheme: select(import_core_data2.store).getCurrentTheme()?.is_block_theme,
307 canCreateTemplate: select(import_core_data2.store).canUser("create", {
308 kind: "postType",
309 name: "wp_template"
310 })
311 };
312 },
313 []
314 );
315 const delayedSearch = useDebouncedValue(search);
316 const { records, isLoading } = (0, import_data2.useSelect)(
317 (select) => {
318 if (!delayedSearch) {
319 return {
320 isLoading: false
321 };
322 }
323 const query = {
324 search: delayedSearch,
325 per_page: 10,
326 orderby: "relevance",
327 status: [
328 "publish",
329 "future",
330 "draft",
331 "pending",
332 "private"
333 ]
334 };
335 return {
336 records: select(import_core_data2.store).getEntityRecords(
337 "postType",
338 postType,
339 query
340 ),
341 isLoading: !select(import_core_data2.store).hasFinishedResolution(
342 "getEntityRecords",
343 ["postType", postType, query]
344 )
345 };
346 },
347 [delayedSearch]
348 );
349 const commands = (0, import_element2.useMemo)(() => {
350 return (records ?? []).map((record) => {
351 const command = {
352 name: postType + "-" + record.id,
353 searchLabel: record.title?.rendered + " " + record.id,
354 label: record.title?.rendered ? (0, import_html_entities.decodeEntities)(record.title?.rendered) : (0, import_i18n2.__)("(no title)"),
355 icon: icons[postType]
356 };
357 if (!canCreateTemplate || postType === "post" || postType === "page" && !isBlockBasedTheme) {
358 return {
359 ...command,
360 callback: ({ close }) => {
361 const args = {
362 post: record.id,
363 action: "edit"
364 };
365 const targetUrl = (0, import_url.addQueryArgs)("post.php", args);
366 document.location = targetUrl;
367 close();
368 }
369 };
370 }
371 const isSiteEditor = (0, import_url.getPath)(window.location.href)?.includes(
372 "site-editor.php"
373 );
374 return {
375 ...command,
376 callback: ({ close }) => {
377 if (isSiteEditor) {
378 history.navigate(
379 `/${postType}/${record.id}?canvas=edit`
380 );
381 } else {
382 document.location = (0, import_url.addQueryArgs)(
383 "site-editor.php",
384 {
385 p: `/${postType}/${record.id}`,
386 canvas: "edit"
387 }
388 );
389 }
390 close();
391 }
392 };
393 });
394 }, [canCreateTemplate, records, isBlockBasedTheme, history]);
395 return {
396 commands,
397 isLoading
398 };
399 };
400 var getNavigationCommandLoaderPerTemplate = (templateType) => function useNavigationCommandLoader({ search }) {
401 const history = useHistory();
402 const { isBlockBasedTheme, canCreateTemplate } = (0, import_data2.useSelect)(
403 (select) => {
404 return {
405 isBlockBasedTheme: select(import_core_data2.store).getCurrentTheme()?.is_block_theme,
406 canCreateTemplate: select(import_core_data2.store).canUser("create", {
407 kind: "postType",
408 name: templateType
409 })
410 };
411 },
412 []
413 );
414 const { records, isLoading } = (0, import_data2.useSelect)((select) => {
415 const { getEntityRecords } = select(import_core_data2.store);
416 const query = { per_page: -1 };
417 return {
418 records: getEntityRecords("postType", templateType, query),
419 isLoading: !select(import_core_data2.store).hasFinishedResolution(
420 "getEntityRecords",
421 ["postType", templateType, query]
422 )
423 };
424 }, []);
425 const orderedRecords = (0, import_element2.useMemo)(() => {
426 return orderEntityRecordsBySearch(records, search).slice(0, 10);
427 }, [records, search]);
428 const commands = (0, import_element2.useMemo)(() => {
429 if (!canCreateTemplate || !isBlockBasedTheme && !templateType === "wp_template_part") {
430 return [];
431 }
432 const isSiteEditor = (0, import_url.getPath)(window.location.href)?.includes(
433 "site-editor.php"
434 );
435 const result = [];
436 result.push(
437 ...orderedRecords.map((record) => {
438 return {
439 name: templateType + "-" + record.id,
440 searchLabel: record.title?.rendered + " " + record.id,
441 label: record.title?.rendered ? record.title?.rendered : (0, import_i18n2.__)("(no title)"),
442 icon: icons[templateType],
443 callback: ({ close }) => {
444 if (isSiteEditor) {
445 history.navigate(
446 `/${templateType}/${record.id}?canvas=edit`
447 );
448 } else {
449 document.location = (0, import_url.addQueryArgs)(
450 "site-editor.php",
451 {
452 p: `/${templateType}/${record.id}`,
453 canvas: "edit"
454 }
455 );
456 }
457 close();
458 }
459 };
460 })
461 );
462 if (orderedRecords?.length > 0 && templateType === "wp_template_part") {
463 result.push({
464 name: "core/edit-site/open-template-parts",
465 label: (0, import_i18n2.__)("Go to: Template parts"),
466 icon: symbol_filled_default,
467 callback: ({ close }) => {
468 if (isSiteEditor) {
469 history.navigate(
470 "/pattern?postType=wp_template_part&categoryId=all-parts"
471 );
472 } else {
473 document.location = (0, import_url.addQueryArgs)(
474 "site-editor.php",
475 {
476 p: "/pattern",
477 postType: "wp_template_part",
478 categoryId: "all-parts"
479 }
480 );
481 }
482 close();
483 }
484 });
485 }
486 return result;
487 }, [canCreateTemplate, isBlockBasedTheme, orderedRecords, history]);
488 return {
489 commands,
490 isLoading
491 };
492 };
493 var getSiteEditorBasicNavigationCommands = () => function useSiteEditorBasicNavigationCommands() {
494 const history = useHistory();
495 const isSiteEditor = (0, import_url.getPath)(window.location.href)?.includes(
496 "site-editor.php"
497 );
498 const { isBlockBasedTheme, canCreateTemplate, canCreatePatterns } = (0, import_data2.useSelect)((select) => {
499 return {
500 isBlockBasedTheme: select(import_core_data2.store).getCurrentTheme()?.is_block_theme,
501 canCreateTemplate: select(import_core_data2.store).canUser("create", {
502 kind: "postType",
503 name: "wp_template"
504 }),
505 canCreatePatterns: select(import_core_data2.store).canUser("create", {
506 kind: "postType",
507 name: "wp_block"
508 })
509 };
510 }, []);
511 const commands = (0, import_element2.useMemo)(() => {
512 const result = [];
513 if (canCreateTemplate && isBlockBasedTheme) {
514 result.push({
515 name: "core/edit-site/open-styles",
516 label: (0, import_i18n2.__)("Go to: Styles"),
517 icon: styles_default,
518 callback: ({ close }) => {
519 if (isSiteEditor) {
520 history.navigate("/styles");
521 } else {
522 document.location = (0, import_url.addQueryArgs)(
523 "site-editor.php",
524 {
525 p: "/styles"
526 }
527 );
528 }
529 close();
530 }
531 });
532 result.push({
533 name: "core/edit-site/open-navigation",
534 label: (0, import_i18n2.__)("Go to: Navigation"),
535 icon: navigation_default,
536 callback: ({ close }) => {
537 if (isSiteEditor) {
538 history.navigate("/navigation");
539 } else {
540 document.location = (0, import_url.addQueryArgs)(
541 "site-editor.php",
542 {
543 p: "/navigation"
544 }
545 );
546 }
547 close();
548 }
549 });
550 result.push({
551 name: "core/edit-site/open-templates",
552 label: (0, import_i18n2.__)("Go to: Templates"),
553 icon: layout_default,
554 callback: ({ close }) => {
555 if (isSiteEditor) {
556 history.navigate("/template");
557 } else {
558 document.location = (0, import_url.addQueryArgs)(
559 "site-editor.php",
560 {
561 p: "/template"
562 }
563 );
564 }
565 close();
566 }
567 });
568 }
569 if (canCreatePatterns) {
570 result.push({
571 name: "core/edit-site/open-patterns",
572 label: (0, import_i18n2.__)("Go to: Patterns"),
573 icon: symbol_default,
574 callback: ({ close }) => {
575 if (canCreateTemplate) {
576 if (isSiteEditor) {
577 history.navigate("/pattern");
578 } else {
579 document.location = (0, import_url.addQueryArgs)(
580 "site-editor.php",
581 {
582 p: "/pattern"
583 }
584 );
585 }
586 close();
587 } else {
588 document.location.href = "edit.php?post_type=wp_block";
589 }
590 }
591 });
592 }
593 return result;
594 }, [
595 history,
596 isSiteEditor,
597 canCreateTemplate,
598 canCreatePatterns,
599 isBlockBasedTheme
600 ]);
601 return {
602 commands,
603 isLoading: false
604 };
605 };
606 var getGlobalStylesOpenCssCommands = () => function useGlobalStylesOpenCssCommands() {
607 const history = useHistory();
608 const isSiteEditor = (0, import_url.getPath)(window.location.href)?.includes(
609 "site-editor.php"
610 );
611 const { canEditCSS } = (0, import_data2.useSelect)((select) => {
612 const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } = select(import_core_data2.store);
613 const globalStylesId = __experimentalGetCurrentGlobalStylesId();
614 const globalStyles = globalStylesId ? getEntityRecord("root", "globalStyles", globalStylesId) : void 0;
615 return {
616 canEditCSS: !!globalStyles?._links?.["wp:action-edit-css"]
617 };
618 }, []);
619 const commands = (0, import_element2.useMemo)(() => {
620 if (!canEditCSS) {
621 return [];
622 }
623 return [
624 {
625 name: "core/open-styles-css",
626 label: (0, import_i18n2.__)("Open custom CSS"),
627 icon: brush_default,
628 callback: ({ close }) => {
629 close();
630 if (isSiteEditor) {
631 history.navigate("/styles?section=/css");
632 } else {
633 document.location = (0, import_url.addQueryArgs)(
634 "site-editor.php",
635 {
636 p: "/styles",
637 section: "/css"
638 }
639 );
640 }
641 }
642 }
643 ];
644 }, [history, canEditCSS, isSiteEditor]);
645 return {
646 isLoading: false,
647 commands
648 };
649 };
650 function useSiteEditorNavigationCommands(isNetworkAdmin) {
651 (0, import_commands2.useCommandLoader)({
652 name: "core/edit-site/navigate-pages",
653 hook: getNavigationCommandLoaderPerPostType("page"),
654 disabled: isNetworkAdmin
655 });
656 (0, import_commands2.useCommandLoader)({
657 name: "core/edit-site/navigate-posts",
658 hook: getNavigationCommandLoaderPerPostType("post"),
659 disabled: isNetworkAdmin
660 });
661 (0, import_commands2.useCommandLoader)({
662 name: "core/edit-site/navigate-templates",
663 hook: getNavigationCommandLoaderPerTemplate("wp_template"),
664 disabled: isNetworkAdmin
665 });
666 (0, import_commands2.useCommandLoader)({
667 name: "core/edit-site/navigate-template-parts",
668 hook: getNavigationCommandLoaderPerTemplate("wp_template_part"),
669 disabled: isNetworkAdmin
670 });
671 (0, import_commands2.useCommandLoader)({
672 name: "core/edit-site/basic-navigation",
673 hook: getSiteEditorBasicNavigationCommands(),
674 context: "site-editor",
675 disabled: isNetworkAdmin
676 });
677 (0, import_commands2.useCommandLoader)({
678 name: "core/edit-site/global-styles-css",
679 hook: getGlobalStylesOpenCssCommands(),
680 disabled: isNetworkAdmin
681 });
682 }
683
684 // packages/core-commands/build-module/private-apis.js
685 function useCommands2() {
686 useAdminNavigationCommands();
687 useSiteEditorNavigationCommands();
688 }
689 var privateApis = {};
690 lock(privateApis, {
691 useCommands: useCommands2
692 });
693
694 // packages/core-commands/build-module/index.js
695 var import_jsx_runtime10 = __toESM(require_jsx_runtime());
696 var { RouterProvider } = unlock(import_router2.privateApis);
697 function CommandPalette({ settings }) {
698 const { menu_commands: menuCommands, is_network_admin: isNetworkAdmin } = settings;
699 useAdminNavigationCommands(menuCommands);
700 useSiteEditorNavigationCommands(isNetworkAdmin);
701 return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(RouterProvider, { pathArg: "p", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_commands3.CommandMenu, {}) });
702 }
703 function initializeCommandPalette(settings) {
704 const root = document.createElement("div");
705 document.body.appendChild(root);
706 (0, import_element3.createRoot)(root).render(
707 /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_element3.StrictMode, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CommandPalette, { settings }) })
708 );
709 }
710 return __toCommonJS(index_exports);
711 })();
712 //# sourceMappingURL=index.js.map
713