PluginProbe
Gutenberg / 22.5.1
Gutenberg v22.5.1
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 12.6.0 All 403 releases
gutenberg / build / scripts / core-commands / index.js

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

734 lines 28.5 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.mjs
119 var index_exports = {};
120 __export(index_exports, {
121 initializeCommandPalette: () => initializeCommandPalette,
122 privateApis: () => privateApis
123 });
124 var import_element3 = __toESM(require_element(), 1);
125 var import_router2 = __toESM(require_router(), 1);
126 var import_commands3 = __toESM(require_commands(), 1);
127
128 // packages/core-commands/build-module/admin-navigation-commands.mjs
129 var import_commands = __toESM(require_commands(), 1);
130 var import_i18n = __toESM(require_i18n(), 1);
131
132 // packages/icons/build-module/library/brush.mjs
133 var import_primitives = __toESM(require_primitives(), 1);
134 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
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.mjs
138 var import_primitives2 = __toESM(require_primitives(), 1);
139 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
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.mjs
143 var import_primitives3 = __toESM(require_primitives(), 1);
144 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
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.mjs
148 var import_primitives4 = __toESM(require_primitives(), 1);
149 var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
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.mjs
153 var import_primitives5 = __toESM(require_primitives(), 1);
154 var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
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.mjs
161 var import_primitives6 = __toESM(require_primitives(), 1);
162 var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
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.mjs
166 var import_primitives7 = __toESM(require_primitives(), 1);
167 var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
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.mjs
178 var import_primitives8 = __toESM(require_primitives(), 1);
179 var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1);
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.mjs
183 var import_primitives9 = __toESM(require_primitives(), 1);
184 var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
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.mjs
188 var import_element = __toESM(require_element(), 1);
189 var import_core_data = __toESM(require_core_data(), 1);
190 var import_data = __toESM(require_data(), 1);
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.mjs
246 var import_commands2 = __toESM(require_commands(), 1);
247 var import_i18n2 = __toESM(require_i18n(), 1);
248 var import_element2 = __toESM(require_element(), 1);
249 var import_data2 = __toESM(require_data(), 1);
250 var import_core_data2 = __toESM(require_core_data(), 1);
251 var import_router = __toESM(require_router(), 1);
252 var import_url = __toESM(require_url(), 1);
253 var import_compose = __toESM(require_compose(), 1);
254 var import_html_entities = __toESM(require_html_entities(), 1);
255
256 // packages/core-commands/build-module/lock-unlock.mjs
257 var import_private_apis = __toESM(require_private_apis(), 1);
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.mjs
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.mjs
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 ROUTE_MAPPING = {
302 "/template": "/templates",
303 "/pattern": "/patterns"
304 };
305 function getSiteEditorPage() {
306 return window.__experimentalExtensibleSiteEditor ? "admin.php?page=site-editor-v2" : "site-editor.php";
307 }
308 function mapRoute(path) {
309 if (!window.__experimentalExtensibleSiteEditor) {
310 return path;
311 }
312 for (const [oldPath, newPath] of Object.entries(ROUTE_MAPPING)) {
313 if (path === oldPath || path.startsWith(oldPath + "?")) {
314 if (path.includes("postType=wp_template_part")) {
315 return "/template-parts";
316 }
317 return path.replace(oldPath, newPath);
318 }
319 }
320 return path;
321 }
322 function isInSiteEditor() {
323 const path = (0, import_url.getPath)(window.location.href);
324 return path?.includes("site-editor.php") || path?.includes("page=site-editor-v2");
325 }
326 var getNavigationCommandLoaderPerPostType = (postType) => function useNavigationCommandLoader({ search }) {
327 const history = useHistory();
328 const { isBlockBasedTheme, canCreateTemplate } = (0, import_data2.useSelect)(
329 (select) => {
330 return {
331 isBlockBasedTheme: select(import_core_data2.store).getCurrentTheme()?.is_block_theme,
332 canCreateTemplate: select(import_core_data2.store).canUser("create", {
333 kind: "postType",
334 name: "wp_template"
335 })
336 };
337 },
338 []
339 );
340 const delayedSearch = useDebouncedValue(search);
341 const { records, isLoading } = (0, import_data2.useSelect)(
342 (select) => {
343 if (!delayedSearch) {
344 return {
345 isLoading: false
346 };
347 }
348 const query = {
349 search: delayedSearch,
350 per_page: 10,
351 orderby: "relevance",
352 status: [
353 "publish",
354 "future",
355 "draft",
356 "pending",
357 "private"
358 ]
359 };
360 return {
361 records: select(import_core_data2.store).getEntityRecords(
362 "postType",
363 postType,
364 query
365 ),
366 isLoading: !select(import_core_data2.store).hasFinishedResolution(
367 "getEntityRecords",
368 ["postType", postType, query]
369 )
370 };
371 },
372 [delayedSearch]
373 );
374 const commands = (0, import_element2.useMemo)(() => {
375 return (records ?? []).map((record) => {
376 const command = {
377 name: postType + "-" + record.id,
378 searchLabel: record.title?.rendered + " " + record.id,
379 label: record.title?.rendered ? (0, import_html_entities.decodeEntities)(record.title?.rendered) : (0, import_i18n2.__)("(no title)"),
380 icon: icons[postType]
381 };
382 if (!canCreateTemplate || postType === "post" || postType === "page" && !isBlockBasedTheme) {
383 return {
384 ...command,
385 callback: ({ close }) => {
386 const args = {
387 post: record.id,
388 action: "edit"
389 };
390 const targetUrl = (0, import_url.addQueryArgs)("post.php", args);
391 document.location = targetUrl;
392 close();
393 }
394 };
395 }
396 const isSiteEditor = isInSiteEditor();
397 return {
398 ...command,
399 callback: ({ close }) => {
400 if (isSiteEditor) {
401 history.navigate(
402 `/${postType}/${record.id}?canvas=edit`
403 );
404 } else {
405 document.location = (0, import_url.addQueryArgs)(
406 getSiteEditorPage(),
407 {
408 p: `/${postType}/${record.id}`,
409 canvas: "edit"
410 }
411 );
412 }
413 close();
414 }
415 };
416 });
417 }, [canCreateTemplate, records, isBlockBasedTheme, history]);
418 return {
419 commands,
420 isLoading
421 };
422 };
423 var getNavigationCommandLoaderPerTemplate = (templateType) => function useNavigationCommandLoader({ search }) {
424 const history = useHistory();
425 const { isBlockBasedTheme, canCreateTemplate } = (0, import_data2.useSelect)(
426 (select) => {
427 return {
428 isBlockBasedTheme: select(import_core_data2.store).getCurrentTheme()?.is_block_theme,
429 canCreateTemplate: select(import_core_data2.store).canUser("create", {
430 kind: "postType",
431 name: templateType
432 })
433 };
434 },
435 []
436 );
437 const { records, isLoading } = (0, import_data2.useSelect)((select) => {
438 const { getEntityRecords } = select(import_core_data2.store);
439 const query = { per_page: -1 };
440 return {
441 records: getEntityRecords("postType", templateType, query),
442 isLoading: !select(import_core_data2.store).hasFinishedResolution(
443 "getEntityRecords",
444 ["postType", templateType, query]
445 )
446 };
447 }, []);
448 const orderedRecords = (0, import_element2.useMemo)(() => {
449 return orderEntityRecordsBySearch(records, search).slice(0, 10);
450 }, [records, search]);
451 const commands = (0, import_element2.useMemo)(() => {
452 if (!canCreateTemplate || !isBlockBasedTheme && !templateType === "wp_template_part") {
453 return [];
454 }
455 const isSiteEditor = (0, import_url.getPath)(window.location.href)?.includes(
456 "site-editor.php"
457 );
458 const result = [];
459 result.push(
460 ...orderedRecords.map((record) => {
461 return {
462 name: templateType + "-" + record.id,
463 searchLabel: record.title?.rendered + " " + record.id,
464 label: record.title?.rendered ? record.title?.rendered : (0, import_i18n2.__)("(no title)"),
465 icon: icons[templateType],
466 callback: ({ close }) => {
467 if (isSiteEditor) {
468 history.navigate(
469 `/${templateType}/${record.id}?canvas=edit`
470 );
471 } else {
472 document.location = (0, import_url.addQueryArgs)(
473 getSiteEditorPage(),
474 {
475 p: `/${templateType}/${record.id}`,
476 canvas: "edit"
477 }
478 );
479 }
480 close();
481 }
482 };
483 })
484 );
485 if (orderedRecords?.length > 0 && templateType === "wp_template_part") {
486 result.push({
487 name: "core/edit-site/open-template-parts",
488 label: (0, import_i18n2.__)("Go to: Template parts"),
489 icon: symbol_filled_default,
490 callback: ({ close }) => {
491 if (isSiteEditor) {
492 history.navigate(
493 mapRoute(
494 "/pattern?postType=wp_template_part&categoryId=all-parts"
495 )
496 );
497 } else {
498 document.location = (0, import_url.addQueryArgs)(
499 getSiteEditorPage(),
500 {
501 p: mapRoute("/pattern"),
502 postType: "wp_template_part",
503 categoryId: "all-parts"
504 }
505 );
506 }
507 close();
508 }
509 });
510 }
511 return result;
512 }, [canCreateTemplate, isBlockBasedTheme, orderedRecords, history]);
513 return {
514 commands,
515 isLoading
516 };
517 };
518 var getSiteEditorBasicNavigationCommands = () => function useSiteEditorBasicNavigationCommands() {
519 const history = useHistory();
520 const isSiteEditor = isInSiteEditor();
521 const { isBlockBasedTheme, canCreateTemplate, canCreatePatterns } = (0, import_data2.useSelect)((select) => {
522 return {
523 isBlockBasedTheme: select(import_core_data2.store).getCurrentTheme()?.is_block_theme,
524 canCreateTemplate: select(import_core_data2.store).canUser("create", {
525 kind: "postType",
526 name: "wp_template"
527 }),
528 canCreatePatterns: select(import_core_data2.store).canUser("create", {
529 kind: "postType",
530 name: "wp_block"
531 })
532 };
533 }, []);
534 const commands = (0, import_element2.useMemo)(() => {
535 const result = [];
536 if (canCreateTemplate && isBlockBasedTheme) {
537 result.push({
538 name: "core/edit-site/open-styles",
539 label: (0, import_i18n2.__)("Go to: Styles"),
540 icon: styles_default,
541 callback: ({ close }) => {
542 if (isSiteEditor) {
543 history.navigate("/styles");
544 } else {
545 document.location = (0, import_url.addQueryArgs)(
546 getSiteEditorPage(),
547 {
548 p: "/styles"
549 }
550 );
551 }
552 close();
553 }
554 });
555 result.push({
556 name: "core/edit-site/open-navigation",
557 label: (0, import_i18n2.__)("Go to: Navigation"),
558 icon: navigation_default,
559 callback: ({ close }) => {
560 if (isSiteEditor) {
561 history.navigate("/navigation");
562 } else {
563 document.location = (0, import_url.addQueryArgs)(
564 getSiteEditorPage(),
565 {
566 p: "/navigation"
567 }
568 );
569 }
570 close();
571 }
572 });
573 result.push({
574 name: "core/edit-site/open-templates",
575 label: (0, import_i18n2.__)("Go to: Templates"),
576 icon: layout_default,
577 callback: ({ close }) => {
578 if (isSiteEditor) {
579 history.navigate(mapRoute("/template"));
580 } else {
581 document.location = (0, import_url.addQueryArgs)(
582 getSiteEditorPage(),
583 {
584 p: mapRoute("/template")
585 }
586 );
587 }
588 close();
589 }
590 });
591 }
592 if (canCreatePatterns) {
593 result.push({
594 name: "core/edit-site/open-patterns",
595 label: (0, import_i18n2.__)("Go to: Patterns"),
596 icon: symbol_default,
597 callback: ({ close }) => {
598 if (canCreateTemplate) {
599 if (isSiteEditor) {
600 history.navigate(mapRoute("/pattern"));
601 } else {
602 document.location = (0, import_url.addQueryArgs)(
603 getSiteEditorPage(),
604 {
605 p: mapRoute("/pattern")
606 }
607 );
608 }
609 close();
610 } else {
611 document.location.href = "edit.php?post_type=wp_block";
612 }
613 }
614 });
615 }
616 return result;
617 }, [
618 history,
619 isSiteEditor,
620 canCreateTemplate,
621 canCreatePatterns,
622 isBlockBasedTheme
623 ]);
624 return {
625 commands,
626 isLoading: false
627 };
628 };
629 var getGlobalStylesOpenCssCommands = () => function useGlobalStylesOpenCssCommands() {
630 const history = useHistory();
631 const isSiteEditor = isInSiteEditor();
632 const { canEditCSS } = (0, import_data2.useSelect)((select) => {
633 const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } = select(import_core_data2.store);
634 const globalStylesId = __experimentalGetCurrentGlobalStylesId();
635 const globalStyles = globalStylesId ? getEntityRecord("root", "globalStyles", globalStylesId) : void 0;
636 return {
637 canEditCSS: !!globalStyles?._links?.["wp:action-edit-css"]
638 };
639 }, []);
640 const commands = (0, import_element2.useMemo)(() => {
641 if (!canEditCSS) {
642 return [];
643 }
644 return [
645 {
646 name: "core/open-styles-css",
647 label: (0, import_i18n2.__)("Open custom CSS"),
648 icon: brush_default,
649 callback: ({ close }) => {
650 close();
651 if (isSiteEditor) {
652 history.navigate("/styles?section=/css");
653 } else {
654 document.location = (0, import_url.addQueryArgs)(
655 getSiteEditorPage(),
656 {
657 p: "/styles",
658 section: "/css"
659 }
660 );
661 }
662 }
663 }
664 ];
665 }, [history, canEditCSS, isSiteEditor]);
666 return {
667 isLoading: false,
668 commands
669 };
670 };
671 function useSiteEditorNavigationCommands(isNetworkAdmin) {
672 (0, import_commands2.useCommandLoader)({
673 name: "core/edit-site/navigate-pages",
674 hook: getNavigationCommandLoaderPerPostType("page"),
675 disabled: isNetworkAdmin
676 });
677 (0, import_commands2.useCommandLoader)({
678 name: "core/edit-site/navigate-posts",
679 hook: getNavigationCommandLoaderPerPostType("post"),
680 disabled: isNetworkAdmin
681 });
682 (0, import_commands2.useCommandLoader)({
683 name: "core/edit-site/navigate-templates",
684 hook: getNavigationCommandLoaderPerTemplate("wp_template"),
685 disabled: isNetworkAdmin
686 });
687 (0, import_commands2.useCommandLoader)({
688 name: "core/edit-site/navigate-template-parts",
689 hook: getNavigationCommandLoaderPerTemplate("wp_template_part"),
690 disabled: isNetworkAdmin
691 });
692 (0, import_commands2.useCommandLoader)({
693 name: "core/edit-site/basic-navigation",
694 hook: getSiteEditorBasicNavigationCommands(),
695 context: "site-editor",
696 disabled: isNetworkAdmin
697 });
698 (0, import_commands2.useCommandLoader)({
699 name: "core/edit-site/global-styles-css",
700 hook: getGlobalStylesOpenCssCommands(),
701 disabled: isNetworkAdmin
702 });
703 }
704
705 // packages/core-commands/build-module/private-apis.mjs
706 function useCommands2() {
707 useAdminNavigationCommands();
708 useSiteEditorNavigationCommands();
709 }
710 var privateApis = {};
711 lock(privateApis, {
712 useCommands: useCommands2
713 });
714
715 // packages/core-commands/build-module/index.mjs
716 var import_jsx_runtime10 = __toESM(require_jsx_runtime(), 1);
717 var { RouterProvider } = unlock(import_router2.privateApis);
718 function CommandPalette({ settings }) {
719 const { menu_commands: menuCommands, is_network_admin: isNetworkAdmin } = settings;
720 useAdminNavigationCommands(menuCommands);
721 useSiteEditorNavigationCommands(isNetworkAdmin);
722 return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(RouterProvider, { pathArg: "p", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_commands3.CommandMenu, {}) });
723 }
724 function initializeCommandPalette(settings) {
725 const root = document.createElement("div");
726 document.body.appendChild(root);
727 (0, import_element3.createRoot)(root).render(
728 /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_element3.StrictMode, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CommandPalette, { settings }) })
729 );
730 }
731 return __toCommonJS(index_exports);
732 })();
733 //# sourceMappingURL=index.js.map
734