[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/dist/ -> core-commands.js (source)

   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", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.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" }) });
 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", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.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" }) });
 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.jsxs)(import_primitives3.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", children: [
 147      /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.Path, { d: "M15.5 7.5h-7V9h7V7.5Zm-7 3.5h7v1.5h-7V11Zm7 3.5h-7V16h7v-1.5Z" }),
 148      /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.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" })
 149    ] });
 150  
 151    // packages/icons/build-module/library/post.mjs
 152    var import_primitives4 = __toESM(require_primitives(), 1);
 153    var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
 154    var post_default = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.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" }) });
 155  
 156    // packages/icons/build-module/library/symbol-filled.mjs
 157    var import_primitives5 = __toESM(require_primitives(), 1);
 158    var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
 159    var symbol_filled_default = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives5.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives5.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" }) });
 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  })();


Generated : Sun Sep 13 08:20:28 2026 Cross-referenced by PHPXref