PluginProbe
Gutenberg / trunk
Gutenberg vtrunk
24.1.0 24.0.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 All 404 releases
gutenberg / build / scripts / core-commands / index.js

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

719 lines 26.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function() {
2 var wp;
3 (wp ||= {}).coreCommands = (() => {
4 var __create = Object.create;
5 var __defProp = Object.defineProperty;
6 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7 var __getOwnPropNames = Object.getOwnPropertyNames;
8 var __getProtoOf = Object.getPrototypeOf;
9 var __hasOwnProp = Object.prototype.hasOwnProperty;
10 var __commonJS = (cb, mod) => function __require() {
11 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12 };
13 var __export = (target, all) => {
14 for (var name in all)
15 __defProp(target, name, { get: all[name], enumerable: true });
16 };
17 var __copyProps = (to, from, except, desc) => {
18 if (from && typeof from === "object" || typeof from === "function") {
19 for (let key of __getOwnPropNames(from))
20 if (!__hasOwnProp.call(to, key) && key !== except)
21 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22 }
23 return to;
24 };
25 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26 // If the importer is in node compatibility mode or this is not an ESM
27 // file that has been converted to a CommonJS file using a Babel-
28 // compatible transform (i.e. "__esModule" has not been set), then set
29 // "default" to the CommonJS "module.exports" for node compatibility.
30 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31 mod
32 ));
33 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
35 // package-external:@wordpress/element
36 var require_element = __commonJS({
37 "package-external:@wordpress/element"(exports, module) {
38 module.exports = window.wp.element;
39 }
40 });
41
42 // package-external:@wordpress/router
43 var require_router = __commonJS({
44 "package-external:@wordpress/router"(exports, module) {
45 module.exports = window.wp.router;
46 }
47 });
48
49 // package-external:@wordpress/commands
50 var require_commands = __commonJS({
51 "package-external:@wordpress/commands"(exports, module) {
52 module.exports = window.wp.commands;
53 }
54 });
55
56 // package-external:@wordpress/i18n
57 var require_i18n = __commonJS({
58 "package-external:@wordpress/i18n"(exports, module) {
59 module.exports = window.wp.i18n;
60 }
61 });
62
63 // package-external:@wordpress/primitives
64 var require_primitives = __commonJS({
65 "package-external:@wordpress/primitives"(exports, module) {
66 module.exports = window.wp.primitives;
67 }
68 });
69
70 // vendor-external:react/jsx-runtime
71 var require_jsx_runtime = __commonJS({
72 "vendor-external:react/jsx-runtime"(exports, module) {
73 module.exports = window.ReactJSXRuntime;
74 }
75 });
76
77 // package-external:@wordpress/core-data
78 var require_core_data = __commonJS({
79 "package-external:@wordpress/core-data"(exports, module) {
80 module.exports = window.wp.coreData;
81 }
82 });
83
84 // package-external:@wordpress/data
85 var require_data = __commonJS({
86 "package-external:@wordpress/data"(exports, module) {
87 module.exports = window.wp.data;
88 }
89 });
90
91 // package-external:@wordpress/url
92 var require_url = __commonJS({
93 "package-external:@wordpress/url"(exports, module) {
94 module.exports = window.wp.url;
95 }
96 });
97
98 // package-external:@wordpress/compose
99 var require_compose = __commonJS({
100 "package-external:@wordpress/compose"(exports, module) {
101 module.exports = window.wp.compose;
102 }
103 });
104
105 // package-external:@wordpress/html-entities
106 var require_html_entities = __commonJS({
107 "package-external:@wordpress/html-entities"(exports, module) {
108 module.exports = window.wp.htmlEntities;
109 }
110 });
111
112 // package-external:@wordpress/private-apis
113 var require_private_apis = __commonJS({
114 "package-external:@wordpress/private-apis"(exports, module) {
115 module.exports = window.wp.privateApis;
116 }
117 });
118
119 // packages/core-commands/build-module/index.mjs
120 var index_exports = {};
121 __export(index_exports, {
122 initializeCommandPalette: () => initializeCommandPalette,
123 privateApis: () => privateApis
124 });
125 var import_element3 = __toESM(require_element(), 1);
126 var import_router2 = __toESM(require_router(), 1);
127 var import_commands3 = __toESM(require_commands(), 1);
128
129 // packages/core-commands/build-module/admin-navigation-commands.mjs
130 var import_commands = __toESM(require_commands(), 1);
131 var import_i18n = __toESM(require_i18n(), 1);
132
133 // packages/icons/build-module/library/external.mjs
134 var import_primitives = __toESM(require_primitives(), 1);
135 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
136 var external_default = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", style: { fill: "none" }, stroke: "currentColor", strokeWidth: "1.5", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.Path, { d: "M9.5 6.25H6.5C5.80964 6.25 5.25 6.80964 5.25 7.5V17.5C5.25 18.1904 5.80964 18.75 6.5 18.75H16.5C17.1904 18.75 17.75 18.1904 17.75 17.5V14.5M11.5 12.5L18.75 5.25M12.5 5.25H18.75V11.5", vectorEffect: "non-scaling-stroke" }) });
137
138 // packages/icons/build-module/library/layout.mjs
139 var import_primitives2 = __toESM(require_primitives(), 1);
140 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
141 var layout_default = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", style: { fill: "none" }, stroke: "currentColor", strokeWidth: "1.5", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.Path, { d: "M9.75 19.25H18C18.6904 19.25 19.25 18.6904 19.25 18V9.75M9.75 19.25H6C5.30964 19.25 4.75 18.6904 4.75 18V9.75M9.75 19.25V9.75M19.25 9.75V6C19.25 5.30964 18.6904 4.75 18 4.75H6C5.30964 4.75 4.75 5.30964 4.75 6V9.75M19.25 9.75H9.75M9.75 9.75H4.75", vectorEffect: "non-scaling-stroke" }) });
142
143 // packages/icons/build-module/library/page.mjs
144 var import_primitives3 = __toESM(require_primitives(), 1);
145 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
146 var page_default = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", style: { fill: "none" }, stroke: "currentColor", strokeWidth: "1.5", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.Path, { d: "M8.5 8.25H15.5M8.5 11.75H15.5M8.5 15.25H15.5M18.25 18V6C18.25 5.30964 17.6904 4.75 17 4.75H7C6.30964 4.75 5.75 5.30964 5.75 6L5.75 18C5.75 18.6904 6.30964 19.25 7 19.25H17C17.6904 19.25 18.25 18.6904 18.25 18Z", vectorEffect: "non-scaling-stroke" }) });
147
148 // packages/icons/build-module/library/post.mjs
149 var import_primitives4 = __toESM(require_primitives(), 1);
150 var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
151 var post_default = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", style: { fill: "none" }, stroke: "currentColor", strokeWidth: "1.5", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.Path, { d: "M4.76776 11.5178L7.76777 8.51776M4 15H20M4 19H13M6 6.74999L9.53554 10.2855C10.1688 9.65226 10.3913 8.76379 10.2031 7.95118L12.5178 6.26776L10.0178 3.76776L8.33435 6.08246C7.52174 5.89422 6.63327 6.11673 6 6.74999Z", vectorEffect: "non-scaling-stroke" }) });
152
153 // packages/icons/build-module/library/symbol-filled.mjs
154 var import_primitives5 = __toESM(require_primitives(), 1);
155 var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
156 var symbol_filled_default = /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_primitives5.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", style: { fill: "none" }, stroke: "currentColor", strokeWidth: "1.5", children: [
157 /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives5.Path, { d: "M15.2071 6.20711L20.2929 11.2929C20.6834 11.6834 20.6834 12.3166 20.2929 12.7071L15.2071 17.7929C14.8166 18.1834 14.1834 18.1834 13.7929 17.7929L8.70711 12.7071C8.31658 12.3166 8.31658 11.6834 8.70711 11.2929L13.7929 6.20711C14.1834 5.81658 14.8166 5.81658 15.2071 6.20711Z", fill: "currentColor", vectorEffect: "non-scaling-stroke" }),
158 /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives5.Path, { d: "M9.5 5.5L3.70711 11.2929C3.31658 11.6834 3.31658 12.3166 3.70711 12.7071L9.5 18.5", vectorEffect: "non-scaling-stroke" })
159 ] });
160
161 // packages/core-commands/build-module/admin-navigation-commands.mjs
162 var import_element = __toESM(require_element(), 1);
163 var import_core_data = __toESM(require_core_data(), 1);
164 var import_data = __toESM(require_data(), 1);
165 var getViewSiteCommand = () => function useViewSiteCommand() {
166 const homeUrl = (0, import_data.useSelect)((select) => {
167 return select(import_core_data.store).getEntityRecord(
168 "root",
169 "__unstableBase"
170 )?.home;
171 }, []);
172 const commands = (0, import_element.useMemo)(() => {
173 if (!homeUrl) {
174 return [];
175 }
176 return [
177 {
178 name: "core/view-site",
179 label: (0, import_i18n.__)("View site"),
180 icon: external_default,
181 category: "view",
182 callback: ({ close }) => {
183 close();
184 window.open(homeUrl, "_blank");
185 }
186 }
187 ];
188 }, [homeUrl]);
189 return {
190 isLoading: false,
191 commands
192 };
193 };
194 function useAdminNavigationCommands(menuCommands) {
195 const commands = (0, import_element.useMemo)(() => {
196 return (menuCommands ?? []).map((menuCommand) => {
197 const label = (0, import_i18n.sprintf)(
198 /* translators: %s: menu label */
199 (0, import_i18n.__)("Go to: %s"),
200 menuCommand.label
201 );
202 return {
203 name: menuCommand.name,
204 label,
205 searchLabel: label,
206 category: "view",
207 callback: ({ close }) => {
208 document.location = menuCommand.url;
209 close();
210 }
211 };
212 });
213 }, [menuCommands]);
214 (0, import_commands.useCommands)(commands);
215 (0, import_commands.useCommandLoader)({
216 name: "core/view-site",
217 hook: getViewSiteCommand()
218 });
219 }
220
221 // packages/core-commands/build-module/site-editor-navigation-commands.mjs
222 var import_commands2 = __toESM(require_commands(), 1);
223 var import_i18n2 = __toESM(require_i18n(), 1);
224 var import_element2 = __toESM(require_element(), 1);
225 var import_data2 = __toESM(require_data(), 1);
226 var import_core_data2 = __toESM(require_core_data(), 1);
227 var import_router = __toESM(require_router(), 1);
228 var import_url = __toESM(require_url(), 1);
229 var import_compose = __toESM(require_compose(), 1);
230 var import_html_entities = __toESM(require_html_entities(), 1);
231
232 // packages/core-commands/build-module/lock-unlock.mjs
233 var import_private_apis = __toESM(require_private_apis(), 1);
234 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
235 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
236 "@wordpress/core-commands"
237 );
238
239 // packages/core-commands/build-module/utils/order-entity-records-by-search.mjs
240 function orderEntityRecordsBySearch(records = [], search = "") {
241 if (!Array.isArray(records) || !records.length) {
242 return [];
243 }
244 if (!search) {
245 return records;
246 }
247 const priority = [];
248 const nonPriority = [];
249 for (let i = 0; i < records.length; i++) {
250 const record = records[i];
251 if (record?.title?.raw?.toLowerCase()?.includes(search?.toLowerCase())) {
252 priority.push(record);
253 } else {
254 nonPriority.push(record);
255 }
256 }
257 return priority.concat(nonPriority);
258 }
259
260 // packages/core-commands/build-module/site-editor-navigation-commands.mjs
261 var { useHistory } = unlock(import_router.privateApis);
262 var icons = {
263 post: post_default,
264 page: page_default,
265 wp_template: layout_default,
266 wp_template_part: symbol_filled_default
267 };
268 function useDebouncedValue(value) {
269 const [debouncedValue, setDebouncedValue] = (0, import_element2.useState)("");
270 const debounced = (0, import_compose.useDebounce)(setDebouncedValue, 250);
271 (0, import_element2.useEffect)(() => {
272 debounced(value);
273 return () => debounced.cancel();
274 }, [debounced, value]);
275 return debouncedValue;
276 }
277 var ROUTE_MAPPING = {
278 "/template": "/templates",
279 "/pattern": "/patterns"
280 };
281 function getSiteEditorPage() {
282 return window.__experimentalExtensibleSiteEditor ? "admin.php?page=site-editor-v2" : "site-editor.php";
283 }
284 function mapRoute(path) {
285 if (!window.__experimentalExtensibleSiteEditor) {
286 return path;
287 }
288 for (const [oldPath, newPath] of Object.entries(ROUTE_MAPPING)) {
289 if (path === oldPath || path.startsWith(oldPath + "?")) {
290 if (path.includes("postType=wp_template_part")) {
291 return "/template-parts";
292 }
293 return path.replace(oldPath, newPath);
294 }
295 }
296 return path;
297 }
298 function isInSiteEditor() {
299 const path = (0, import_url.getPath)(window.location.href);
300 return path?.includes("site-editor.php") || path?.includes("page=site-editor-v2");
301 }
302 var getNavigationCommandLoaderPerPostType = (postType) => function useNavigationCommandLoader({ search }) {
303 const history = useHistory();
304 const { isBlockBasedTheme, canCreateTemplate } = (0, import_data2.useSelect)(
305 (select) => {
306 return {
307 isBlockBasedTheme: select(import_core_data2.store).getCurrentTheme()?.is_block_theme,
308 canCreateTemplate: select(import_core_data2.store).canUser("create", {
309 kind: "postType",
310 name: "wp_template"
311 })
312 };
313 },
314 []
315 );
316 const delayedSearch = useDebouncedValue(search);
317 const { records, isLoading } = (0, import_data2.useSelect)(
318 (select) => {
319 if (!delayedSearch) {
320 return {
321 isLoading: false
322 };
323 }
324 const query = {
325 search: delayedSearch,
326 per_page: 10,
327 orderby: "relevance",
328 status: [
329 "publish",
330 "future",
331 "draft",
332 "pending",
333 "private"
334 ]
335 };
336 return {
337 records: select(import_core_data2.store).getEntityRecords(
338 "postType",
339 postType,
340 query
341 ),
342 isLoading: !select(import_core_data2.store).hasFinishedResolution(
343 "getEntityRecords",
344 ["postType", postType, query]
345 )
346 };
347 },
348 [delayedSearch]
349 );
350 const commands = (0, import_element2.useMemo)(() => {
351 return (records ?? []).map((record) => {
352 const command = {
353 name: postType + "-" + record.id,
354 searchLabel: record.title?.rendered + " " + record.id,
355 label: record.title?.rendered ? (0, import_html_entities.decodeEntities)(record.title?.rendered) : (0, import_i18n2.__)("(no title)"),
356 icon: icons[postType],
357 category: "edit"
358 };
359 if (!canCreateTemplate || postType === "post" || postType === "page" && !isBlockBasedTheme) {
360 return {
361 ...command,
362 callback: ({ close }) => {
363 const args = {
364 post: record.id,
365 action: "edit"
366 };
367 const targetUrl = (0, import_url.addQueryArgs)("post.php", args);
368 document.location = targetUrl;
369 close();
370 }
371 };
372 }
373 const isSiteEditor = isInSiteEditor();
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 getSiteEditorPage(),
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 category: "edit",
444 callback: ({ close }) => {
445 if (isSiteEditor) {
446 history.navigate(
447 `/${templateType}/${record.id}?canvas=edit`
448 );
449 } else {
450 document.location = (0, import_url.addQueryArgs)(
451 getSiteEditorPage(),
452 {
453 p: `/${templateType}/${record.id}`,
454 canvas: "edit"
455 }
456 );
457 }
458 close();
459 }
460 };
461 })
462 );
463 if (orderedRecords?.length > 0 && templateType === "wp_template_part") {
464 result.push({
465 name: "core/edit-site/open-template-parts",
466 label: (0, import_i18n2.__)("Go to: Template parts"),
467 category: "view",
468 callback: ({ close }) => {
469 if (isSiteEditor) {
470 history.navigate(
471 mapRoute(
472 "/pattern?postType=wp_template_part&categoryId=all-parts"
473 )
474 );
475 } else {
476 document.location = (0, import_url.addQueryArgs)(
477 getSiteEditorPage(),
478 {
479 p: mapRoute("/pattern"),
480 postType: "wp_template_part",
481 categoryId: "all-parts"
482 }
483 );
484 }
485 close();
486 }
487 });
488 }
489 return result;
490 }, [canCreateTemplate, isBlockBasedTheme, orderedRecords, history]);
491 return {
492 commands,
493 isLoading
494 };
495 };
496 var getSiteEditorBasicNavigationCommands = () => function useSiteEditorBasicNavigationCommands() {
497 const history = useHistory();
498 const isSiteEditor = isInSiteEditor();
499 const { isBlockBasedTheme, canCreateTemplate, canCreatePatterns } = (0, import_data2.useSelect)((select) => {
500 return {
501 isBlockBasedTheme: select(import_core_data2.store).getCurrentTheme()?.is_block_theme,
502 canCreateTemplate: select(import_core_data2.store).canUser("create", {
503 kind: "postType",
504 name: "wp_template"
505 }),
506 canCreatePatterns: select(import_core_data2.store).canUser("create", {
507 kind: "postType",
508 name: "wp_block"
509 })
510 };
511 }, []);
512 const commands = (0, import_element2.useMemo)(() => {
513 const result = [];
514 if (canCreateTemplate && isBlockBasedTheme) {
515 result.push({
516 name: "core/edit-site/open-styles",
517 label: (0, import_i18n2.__)("Go to: Styles"),
518 category: "view",
519 callback: ({ close }) => {
520 if (isSiteEditor) {
521 history.navigate("/styles");
522 } else {
523 document.location = (0, import_url.addQueryArgs)(
524 getSiteEditorPage(),
525 {
526 p: "/styles"
527 }
528 );
529 }
530 close();
531 }
532 });
533 result.push({
534 name: "core/edit-site/open-navigation",
535 label: (0, import_i18n2.__)("Go to: Navigation"),
536 category: "view",
537 callback: ({ close }) => {
538 if (isSiteEditor) {
539 history.navigate("/navigation");
540 } else {
541 document.location = (0, import_url.addQueryArgs)(
542 getSiteEditorPage(),
543 {
544 p: "/navigation"
545 }
546 );
547 }
548 close();
549 }
550 });
551 result.push({
552 name: "core/edit-site/open-templates",
553 label: (0, import_i18n2.__)("Go to: Templates"),
554 category: "view",
555 callback: ({ close }) => {
556 if (isSiteEditor) {
557 history.navigate(mapRoute("/template"));
558 } else {
559 document.location = (0, import_url.addQueryArgs)(
560 getSiteEditorPage(),
561 {
562 p: mapRoute("/template")
563 }
564 );
565 }
566 close();
567 }
568 });
569 }
570 if (canCreatePatterns) {
571 result.push({
572 name: "core/edit-site/open-patterns",
573 label: (0, import_i18n2.__)("Go to: Patterns"),
574 category: "view",
575 callback: ({ close }) => {
576 if (canCreateTemplate) {
577 if (isSiteEditor) {
578 history.navigate(mapRoute("/pattern"));
579 } else {
580 document.location = (0, import_url.addQueryArgs)(
581 getSiteEditorPage(),
582 {
583 p: mapRoute("/pattern")
584 }
585 );
586 }
587 close();
588 } else {
589 document.location.href = "edit.php?post_type=wp_block";
590 }
591 }
592 });
593 }
594 return result;
595 }, [
596 history,
597 isSiteEditor,
598 canCreateTemplate,
599 canCreatePatterns,
600 isBlockBasedTheme
601 ]);
602 return {
603 commands,
604 isLoading: false
605 };
606 };
607 var getGlobalStylesOpenCssCommands = () => function useGlobalStylesOpenCssCommands() {
608 const history = useHistory();
609 const isSiteEditor = isInSiteEditor();
610 const { canEditCSS, isBlockBasedTheme } = (0, import_data2.useSelect)((select) => {
611 const {
612 getEntityRecord,
613 __experimentalGetCurrentGlobalStylesId,
614 getCurrentTheme
615 } = select(import_core_data2.store);
616 const globalStylesId = __experimentalGetCurrentGlobalStylesId();
617 const globalStyles = globalStylesId ? getEntityRecord("root", "globalStyles", globalStylesId) : void 0;
618 return {
619 canEditCSS: !!globalStyles?._links?.["wp:action-edit-css"],
620 isBlockBasedTheme: getCurrentTheme()?.is_block_theme
621 };
622 }, []);
623 const commands = (0, import_element2.useMemo)(() => {
624 if (!canEditCSS || !isBlockBasedTheme) {
625 return [];
626 }
627 return [
628 {
629 name: "core/open-styles-css",
630 label: (0, import_i18n2.__)("Open custom CSS"),
631 category: "view",
632 callback: ({ close }) => {
633 close();
634 if (isSiteEditor) {
635 history.navigate("/styles?section=/css");
636 } else {
637 document.location = (0, import_url.addQueryArgs)(
638 getSiteEditorPage(),
639 {
640 p: "/styles",
641 section: "/css"
642 }
643 );
644 }
645 }
646 }
647 ];
648 }, [history, canEditCSS, isSiteEditor, isBlockBasedTheme]);
649 return {
650 isLoading: false,
651 commands
652 };
653 };
654 function useSiteEditorNavigationCommands(isNetworkAdmin) {
655 (0, import_commands2.useCommandLoader)({
656 name: "core/edit-site/navigate-pages",
657 hook: getNavigationCommandLoaderPerPostType("page"),
658 disabled: isNetworkAdmin
659 });
660 (0, import_commands2.useCommandLoader)({
661 name: "core/edit-site/navigate-posts",
662 hook: getNavigationCommandLoaderPerPostType("post"),
663 disabled: isNetworkAdmin
664 });
665 (0, import_commands2.useCommandLoader)({
666 name: "core/edit-site/navigate-templates",
667 hook: getNavigationCommandLoaderPerTemplate("wp_template"),
668 disabled: isNetworkAdmin
669 });
670 (0, import_commands2.useCommandLoader)({
671 name: "core/edit-site/navigate-template-parts",
672 hook: getNavigationCommandLoaderPerTemplate("wp_template_part"),
673 disabled: isNetworkAdmin
674 });
675 (0, import_commands2.useCommandLoader)({
676 name: "core/edit-site/basic-navigation",
677 hook: getSiteEditorBasicNavigationCommands(),
678 context: "site-editor",
679 disabled: isNetworkAdmin
680 });
681 (0, import_commands2.useCommandLoader)({
682 name: "core/edit-site/global-styles-css",
683 hook: getGlobalStylesOpenCssCommands(),
684 disabled: isNetworkAdmin
685 });
686 }
687
688 // packages/core-commands/build-module/private-apis.mjs
689 function useCommands2() {
690 useAdminNavigationCommands();
691 useSiteEditorNavigationCommands();
692 }
693 var privateApis = {};
694 lock(privateApis, {
695 useCommands: useCommands2
696 });
697
698 // packages/core-commands/build-module/index.mjs
699 var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
700 var { RouterProvider } = unlock(import_router2.privateApis);
701 function CommandPalette({ settings }) {
702 const { menu_commands: menuCommands, is_network_admin: isNetworkAdmin } = settings;
703 useAdminNavigationCommands(menuCommands);
704 useSiteEditorNavigationCommands(isNetworkAdmin);
705 return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(RouterProvider, { pathArg: "p", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_commands3.CommandMenu, {}) });
706 }
707 function initializeCommandPalette(settings) {
708 const root = document.createElement("div");
709 document.body.appendChild(root);
710 (0, import_element3.createRoot)(root).render(
711 /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_element3.StrictMode, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CommandPalette, { settings }) })
712 );
713 }
714 return __toCommonJS(index_exports);
715 })();
716 (window.wp ||= {}).coreCommands = wp.coreCommands;
717 })();
718 //# sourceMappingURL=index.js.map
719