[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  /******/ (() => { // webpackBootstrap
   2  /******/     "use strict";
   3  /******/     // The require scope
   4  /******/     var __webpack_require__ = {};
   5  /******/     
   6  /************************************************************************/
   7  /******/     /* webpack/runtime/define property getters */
   8  /******/     (() => {
   9  /******/         // define getter functions for harmony exports
  10  /******/         __webpack_require__.d = (exports, definition) => {
  11  /******/             for(var key in definition) {
  12  /******/                 if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  13  /******/                     Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  14  /******/                 }
  15  /******/             }
  16  /******/         };
  17  /******/     })();
  18  /******/     
  19  /******/     /* webpack/runtime/hasOwnProperty shorthand */
  20  /******/     (() => {
  21  /******/         __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  22  /******/     })();
  23  /******/     
  24  /******/     /* webpack/runtime/make namespace object */
  25  /******/     (() => {
  26  /******/         // define __esModule on exports
  27  /******/         __webpack_require__.r = (exports) => {
  28  /******/             if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  29  /******/                 Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  30  /******/             }
  31  /******/             Object.defineProperty(exports, '__esModule', { value: true });
  32  /******/         };
  33  /******/     })();
  34  /******/     
  35  /************************************************************************/
  36  var __webpack_exports__ = {};
  37  // ESM COMPAT FLAG
  38  __webpack_require__.r(__webpack_exports__);
  39  
  40  // EXPORTS
  41  __webpack_require__.d(__webpack_exports__, {
  42    privateApis: () => (/* reexport */ privateApis)
  43  });
  44  
  45  ;// external ["wp","commands"]
  46  const external_wp_commands_namespaceObject = window["wp"]["commands"];
  47  ;// external ["wp","i18n"]
  48  const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
  49  ;// external ["wp","primitives"]
  50  const external_wp_primitives_namespaceObject = window["wp"]["primitives"];
  51  ;// external "ReactJSXRuntime"
  52  const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"];
  53  ;// ./node_modules/@wordpress/icons/build-module/library/plus.js
  54  /**
  55   * WordPress dependencies
  56   */
  57  
  58  
  59  const plus = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
  60    xmlns: "http://www.w3.org/2000/svg",
  61    viewBox: "0 0 24 24",
  62    children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
  63      d: "M11 12.5V17.5H12.5V12.5H17.5V11H12.5V6H11V11H6V12.5H11Z"
  64    })
  65  });
  66  /* harmony default export */ const library_plus = (plus);
  67  
  68  ;// external ["wp","url"]
  69  const external_wp_url_namespaceObject = window["wp"]["url"];
  70  ;// external ["wp","coreData"]
  71  const external_wp_coreData_namespaceObject = window["wp"]["coreData"];
  72  ;// external ["wp","data"]
  73  const external_wp_data_namespaceObject = window["wp"]["data"];
  74  ;// external ["wp","element"]
  75  const external_wp_element_namespaceObject = window["wp"]["element"];
  76  ;// external ["wp","notices"]
  77  const external_wp_notices_namespaceObject = window["wp"]["notices"];
  78  ;// external ["wp","router"]
  79  const external_wp_router_namespaceObject = window["wp"]["router"];
  80  ;// external ["wp","privateApis"]
  81  const external_wp_privateApis_namespaceObject = window["wp"]["privateApis"];
  82  ;// ./node_modules/@wordpress/core-commands/build-module/lock-unlock.js
  83  /**
  84   * WordPress dependencies
  85   */
  86  
  87  const {
  88    lock,
  89    unlock
  90  } = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/core-commands');
  91  
  92  ;// ./node_modules/@wordpress/core-commands/build-module/admin-navigation-commands.js
  93  /**
  94   * WordPress dependencies
  95   */
  96  
  97  
  98  
  99  
 100  
 101  
 102  
 103  
 104  
 105  
 106  /**
 107   * Internal dependencies
 108   */
 109  
 110  const {
 111    useHistory
 112  } = unlock(external_wp_router_namespaceObject.privateApis);
 113  function useAddNewPageCommand() {
 114    const isSiteEditor = (0,external_wp_url_namespaceObject.getPath)(window.location.href)?.includes('site-editor.php');
 115    const history = useHistory();
 116    const isBlockBasedTheme = (0,external_wp_data_namespaceObject.useSelect)(select => {
 117      return select(external_wp_coreData_namespaceObject.store).getCurrentTheme()?.is_block_theme;
 118    }, []);
 119    const {
 120      saveEntityRecord
 121    } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_coreData_namespaceObject.store);
 122    const {
 123      createErrorNotice
 124    } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store);
 125    const createPageEntity = (0,external_wp_element_namespaceObject.useCallback)(async ({
 126      close
 127    }) => {
 128      try {
 129        const page = await saveEntityRecord('postType', 'page', {
 130          status: 'draft'
 131        }, {
 132          throwOnError: true
 133        });
 134        if (page?.id) {
 135          history.push({
 136            postId: page.id,
 137            postType: 'page',
 138            canvas: 'edit'
 139          });
 140        }
 141      } catch (error) {
 142        const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : (0,external_wp_i18n_namespaceObject.__)('An error occurred while creating the item.');
 143        createErrorNotice(errorMessage, {
 144          type: 'snackbar'
 145        });
 146      } finally {
 147        close();
 148      }
 149    }, [createErrorNotice, history, saveEntityRecord]);
 150    const commands = (0,external_wp_element_namespaceObject.useMemo)(() => {
 151      const addNewPage = isSiteEditor && isBlockBasedTheme ? createPageEntity : () => document.location.href = 'post-new.php?post_type=page';
 152      return [{
 153        name: 'core/add-new-page',
 154        label: (0,external_wp_i18n_namespaceObject.__)('Add new page'),
 155        icon: library_plus,
 156        callback: addNewPage
 157      }];
 158    }, [createPageEntity, isSiteEditor, isBlockBasedTheme]);
 159    return {
 160      isLoading: false,
 161      commands
 162    };
 163  }
 164  function useAdminNavigationCommands() {
 165    (0,external_wp_commands_namespaceObject.useCommand)({
 166      name: 'core/add-new-post',
 167      label: (0,external_wp_i18n_namespaceObject.__)('Add new post'),
 168      icon: library_plus,
 169      callback: () => {
 170        document.location.href = 'post-new.php';
 171      }
 172    });
 173    (0,external_wp_commands_namespaceObject.useCommandLoader)({
 174      name: 'core/add-new-page',
 175      hook: useAddNewPageCommand
 176    });
 177  }
 178  
 179  ;// ./node_modules/@wordpress/icons/build-module/library/post.js
 180  /**
 181   * WordPress dependencies
 182   */
 183  
 184  
 185  const post = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
 186    xmlns: "http://www.w3.org/2000/svg",
 187    viewBox: "0 0 24 24",
 188    children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
 189      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"
 190    })
 191  });
 192  /* harmony default export */ const library_post = (post);
 193  
 194  ;// ./node_modules/@wordpress/icons/build-module/library/page.js
 195  /**
 196   * WordPress dependencies
 197   */
 198  
 199  
 200  
 201  const page = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_primitives_namespaceObject.SVG, {
 202    xmlns: "http://www.w3.org/2000/svg",
 203    viewBox: "0 0 24 24",
 204    children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
 205      d: "M15.5 7.5h-7V9h7V7.5Zm-7 3.5h7v1.5h-7V11Zm7 3.5h-7V16h7v-1.5Z"
 206    }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
 207      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"
 208    })]
 209  });
 210  /* harmony default export */ const library_page = (page);
 211  
 212  ;// ./node_modules/@wordpress/icons/build-module/library/layout.js
 213  /**
 214   * WordPress dependencies
 215   */
 216  
 217  
 218  const layout = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
 219    xmlns: "http://www.w3.org/2000/svg",
 220    viewBox: "0 0 24 24",
 221    children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
 222      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"
 223    })
 224  });
 225  /* harmony default export */ const library_layout = (layout);
 226  
 227  ;// ./node_modules/@wordpress/icons/build-module/library/symbol-filled.js
 228  /**
 229   * WordPress dependencies
 230   */
 231  
 232  
 233  const symbolFilled = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
 234    xmlns: "http://www.w3.org/2000/svg",
 235    viewBox: "0 0 24 24",
 236    children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
 237      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"
 238    })
 239  });
 240  /* harmony default export */ const symbol_filled = (symbolFilled);
 241  
 242  ;// ./node_modules/@wordpress/icons/build-module/library/navigation.js
 243  /**
 244   * WordPress dependencies
 245   */
 246  
 247  
 248  const navigation = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
 249    viewBox: "0 0 24 24",
 250    xmlns: "http://www.w3.org/2000/svg",
 251    children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
 252      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"
 253    })
 254  });
 255  /* harmony default export */ const library_navigation = (navigation);
 256  
 257  ;// ./node_modules/@wordpress/icons/build-module/library/styles.js
 258  /**
 259   * WordPress dependencies
 260   */
 261  
 262  
 263  const styles = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
 264    viewBox: "0 0 24 24",
 265    xmlns: "http://www.w3.org/2000/svg",
 266    children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
 267      fillRule: "evenodd",
 268      clipRule: "evenodd",
 269      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"
 270    })
 271  });
 272  /* harmony default export */ const library_styles = (styles);
 273  
 274  ;// ./node_modules/@wordpress/icons/build-module/library/symbol.js
 275  /**
 276   * WordPress dependencies
 277   */
 278  
 279  
 280  const symbol = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
 281    xmlns: "http://www.w3.org/2000/svg",
 282    viewBox: "0 0 24 24",
 283    children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
 284      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"
 285    })
 286  });
 287  /* harmony default export */ const library_symbol = (symbol);
 288  
 289  ;// external ["wp","compose"]
 290  const external_wp_compose_namespaceObject = window["wp"]["compose"];
 291  ;// external ["wp","htmlEntities"]
 292  const external_wp_htmlEntities_namespaceObject = window["wp"]["htmlEntities"];
 293  ;// ./node_modules/@wordpress/core-commands/build-module/utils/order-entity-records-by-search.js
 294  function orderEntityRecordsBySearch(records = [], search = '') {
 295    if (!Array.isArray(records) || !records.length) {
 296      return [];
 297    }
 298    if (!search) {
 299      return records;
 300    }
 301    const priority = [];
 302    const nonPriority = [];
 303    for (let i = 0; i < records.length; i++) {
 304      const record = records[i];
 305      if (record?.title?.raw?.toLowerCase()?.includes(search?.toLowerCase())) {
 306        priority.push(record);
 307      } else {
 308        nonPriority.push(record);
 309      }
 310    }
 311    return priority.concat(nonPriority);
 312  }
 313  
 314  ;// ./node_modules/@wordpress/core-commands/build-module/site-editor-navigation-commands.js
 315  /**
 316   * WordPress dependencies
 317   */
 318  
 319  
 320  
 321  
 322  
 323  
 324  
 325  
 326  
 327  
 328  
 329  /**
 330   * Internal dependencies
 331   */
 332  
 333  
 334  const {
 335    useHistory: site_editor_navigation_commands_useHistory
 336  } = unlock(external_wp_router_namespaceObject.privateApis);
 337  const icons = {
 338    post: library_post,
 339    page: library_page,
 340    wp_template: library_layout,
 341    wp_template_part: symbol_filled
 342  };
 343  function useDebouncedValue(value) {
 344    const [debouncedValue, setDebouncedValue] = (0,external_wp_element_namespaceObject.useState)('');
 345    const debounced = (0,external_wp_compose_namespaceObject.useDebounce)(setDebouncedValue, 250);
 346    (0,external_wp_element_namespaceObject.useEffect)(() => {
 347      debounced(value);
 348      return () => debounced.cancel();
 349    }, [debounced, value]);
 350    return debouncedValue;
 351  }
 352  const getNavigationCommandLoaderPerPostType = postType => function useNavigationCommandLoader({
 353    search
 354  }) {
 355    const history = site_editor_navigation_commands_useHistory();
 356    const {
 357      isBlockBasedTheme,
 358      canCreateTemplate
 359    } = (0,external_wp_data_namespaceObject.useSelect)(select => {
 360      return {
 361        isBlockBasedTheme: select(external_wp_coreData_namespaceObject.store).getCurrentTheme()?.is_block_theme,
 362        canCreateTemplate: select(external_wp_coreData_namespaceObject.store).canUser('create', {
 363          kind: 'postType',
 364          name: 'wp_template'
 365        })
 366      };
 367    }, []);
 368    const delayedSearch = useDebouncedValue(search);
 369    const {
 370      records,
 371      isLoading
 372    } = (0,external_wp_data_namespaceObject.useSelect)(select => {
 373      if (!delayedSearch) {
 374        return {
 375          isLoading: false
 376        };
 377      }
 378      const query = {
 379        search: delayedSearch,
 380        per_page: 10,
 381        orderby: 'relevance',
 382        status: ['publish', 'future', 'draft', 'pending', 'private']
 383      };
 384      return {
 385        records: select(external_wp_coreData_namespaceObject.store).getEntityRecords('postType', postType, query),
 386        isLoading: !select(external_wp_coreData_namespaceObject.store).hasFinishedResolution('getEntityRecords', ['postType', postType, query])
 387      };
 388    }, [delayedSearch]);
 389    const commands = (0,external_wp_element_namespaceObject.useMemo)(() => {
 390      return (records !== null && records !== void 0 ? records : []).map(record => {
 391        const command = {
 392          name: postType + '-' + record.id,
 393          searchLabel: record.title?.rendered + ' ' + record.id,
 394          label: record.title?.rendered ? (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(record.title?.rendered) : (0,external_wp_i18n_namespaceObject.__)('(no title)'),
 395          icon: icons[postType]
 396        };
 397        if (!canCreateTemplate || postType === 'post' || postType === 'page' && !isBlockBasedTheme) {
 398          return {
 399            ...command,
 400            callback: ({
 401              close
 402            }) => {
 403              const args = {
 404                post: record.id,
 405                action: 'edit'
 406              };
 407              const targetUrl = (0,external_wp_url_namespaceObject.addQueryArgs)('post.php', args);
 408              document.location = targetUrl;
 409              close();
 410            }
 411          };
 412        }
 413        const isSiteEditor = (0,external_wp_url_namespaceObject.getPath)(window.location.href)?.includes('site-editor.php');
 414        return {
 415          ...command,
 416          callback: ({
 417            close
 418          }) => {
 419            const args = {
 420              postType,
 421              postId: record.id,
 422              canvas: 'edit'
 423            };
 424            const targetUrl = (0,external_wp_url_namespaceObject.addQueryArgs)('site-editor.php', args);
 425            if (isSiteEditor) {
 426              history.push(args);
 427            } else {
 428              document.location = targetUrl;
 429            }
 430            close();
 431          }
 432        };
 433      });
 434    }, [canCreateTemplate, records, isBlockBasedTheme, history]);
 435    return {
 436      commands,
 437      isLoading
 438    };
 439  };
 440  const getNavigationCommandLoaderPerTemplate = templateType => function useNavigationCommandLoader({
 441    search
 442  }) {
 443    const history = site_editor_navigation_commands_useHistory();
 444    const {
 445      isBlockBasedTheme,
 446      canCreateTemplate
 447    } = (0,external_wp_data_namespaceObject.useSelect)(select => {
 448      return {
 449        isBlockBasedTheme: select(external_wp_coreData_namespaceObject.store).getCurrentTheme()?.is_block_theme,
 450        canCreateTemplate: select(external_wp_coreData_namespaceObject.store).canUser('create', {
 451          kind: 'postType',
 452          name: templateType
 453        })
 454      };
 455    }, []);
 456    const {
 457      records,
 458      isLoading
 459    } = (0,external_wp_data_namespaceObject.useSelect)(select => {
 460      const {
 461        getEntityRecords
 462      } = select(external_wp_coreData_namespaceObject.store);
 463      const query = {
 464        per_page: -1
 465      };
 466      return {
 467        records: getEntityRecords('postType', templateType, query),
 468        isLoading: !select(external_wp_coreData_namespaceObject.store).hasFinishedResolution('getEntityRecords', ['postType', templateType, query])
 469      };
 470    }, []);
 471  
 472    /*
 473     * wp_template and wp_template_part endpoints do not support per_page or orderby parameters.
 474     * We need to sort the results based on the search query to avoid removing relevant
 475     * records below using .slice().
 476     */
 477    const orderedRecords = (0,external_wp_element_namespaceObject.useMemo)(() => {
 478      return orderEntityRecordsBySearch(records, search).slice(0, 10);
 479    }, [records, search]);
 480    const commands = (0,external_wp_element_namespaceObject.useMemo)(() => {
 481      if (!canCreateTemplate || !isBlockBasedTheme && !templateType === 'wp_template_part') {
 482        return [];
 483      }
 484      const isSiteEditor = (0,external_wp_url_namespaceObject.getPath)(window.location.href)?.includes('site-editor.php');
 485      const result = [];
 486      result.push(...orderedRecords.map(record => {
 487        return {
 488          name: templateType + '-' + record.id,
 489          searchLabel: record.title?.rendered + ' ' + record.id,
 490          label: record.title?.rendered ? record.title?.rendered : (0,external_wp_i18n_namespaceObject.__)('(no title)'),
 491          icon: icons[templateType],
 492          callback: ({
 493            close
 494          }) => {
 495            const args = {
 496              postType: templateType,
 497              postId: record.id,
 498              canvas: 'edit'
 499            };
 500            const targetUrl = (0,external_wp_url_namespaceObject.addQueryArgs)('site-editor.php', args);
 501            if (isSiteEditor) {
 502              history.push(args);
 503            } else {
 504              document.location = targetUrl;
 505            }
 506            close();
 507          }
 508        };
 509      }));
 510      if (orderedRecords?.length > 0 && templateType === 'wp_template_part') {
 511        result.push({
 512          name: 'core/edit-site/open-template-parts',
 513          label: (0,external_wp_i18n_namespaceObject.__)('Template parts'),
 514          icon: symbol_filled,
 515          callback: ({
 516            close
 517          }) => {
 518            const args = {
 519              postType: 'wp_template_part',
 520              categoryId: 'all-parts'
 521            };
 522            const targetUrl = (0,external_wp_url_namespaceObject.addQueryArgs)('site-editor.php', args);
 523            if (isSiteEditor) {
 524              history.push(args);
 525            } else {
 526              document.location = targetUrl;
 527            }
 528            close();
 529          }
 530        });
 531      }
 532      return result;
 533    }, [canCreateTemplate, isBlockBasedTheme, orderedRecords, history]);
 534    return {
 535      commands,
 536      isLoading
 537    };
 538  };
 539  const usePageNavigationCommandLoader = getNavigationCommandLoaderPerPostType('page');
 540  const usePostNavigationCommandLoader = getNavigationCommandLoaderPerPostType('post');
 541  const useTemplateNavigationCommandLoader = getNavigationCommandLoaderPerTemplate('wp_template');
 542  const useTemplatePartNavigationCommandLoader = getNavigationCommandLoaderPerTemplate('wp_template_part');
 543  function useSiteEditorBasicNavigationCommands() {
 544    const history = site_editor_navigation_commands_useHistory();
 545    const isSiteEditor = (0,external_wp_url_namespaceObject.getPath)(window.location.href)?.includes('site-editor.php');
 546    const {
 547      isBlockBasedTheme,
 548      canCreateTemplate
 549    } = (0,external_wp_data_namespaceObject.useSelect)(select => {
 550      return {
 551        isBlockBasedTheme: select(external_wp_coreData_namespaceObject.store).getCurrentTheme()?.is_block_theme,
 552        canCreateTemplate: select(external_wp_coreData_namespaceObject.store).canUser('create', {
 553          kind: 'postType',
 554          name: 'wp_template'
 555        })
 556      };
 557    }, []);
 558    const commands = (0,external_wp_element_namespaceObject.useMemo)(() => {
 559      const result = [];
 560      if (canCreateTemplate && isBlockBasedTheme) {
 561        result.push({
 562          name: 'core/edit-site/open-navigation',
 563          label: (0,external_wp_i18n_namespaceObject.__)('Navigation'),
 564          icon: library_navigation,
 565          callback: ({
 566            close
 567          }) => {
 568            const args = {
 569              postType: 'wp_navigation'
 570            };
 571            const targetUrl = (0,external_wp_url_namespaceObject.addQueryArgs)('site-editor.php', args);
 572            if (isSiteEditor) {
 573              history.push(args);
 574            } else {
 575              document.location = targetUrl;
 576            }
 577            close();
 578          }
 579        });
 580        result.push({
 581          name: 'core/edit-site/open-styles',
 582          label: (0,external_wp_i18n_namespaceObject.__)('Styles'),
 583          icon: library_styles,
 584          callback: ({
 585            close
 586          }) => {
 587            const args = {
 588              path: '/wp_global_styles'
 589            };
 590            const targetUrl = (0,external_wp_url_namespaceObject.addQueryArgs)('site-editor.php', args);
 591            if (isSiteEditor) {
 592              history.push(args);
 593            } else {
 594              document.location = targetUrl;
 595            }
 596            close();
 597          }
 598        });
 599        result.push({
 600          name: 'core/edit-site/open-pages',
 601          label: (0,external_wp_i18n_namespaceObject.__)('Pages'),
 602          icon: library_page,
 603          callback: ({
 604            close
 605          }) => {
 606            const args = {
 607              postType: 'page'
 608            };
 609            const targetUrl = (0,external_wp_url_namespaceObject.addQueryArgs)('site-editor.php', args);
 610            if (isSiteEditor) {
 611              history.push(args);
 612            } else {
 613              document.location = targetUrl;
 614            }
 615            close();
 616          }
 617        });
 618        result.push({
 619          name: 'core/edit-site/open-templates',
 620          label: (0,external_wp_i18n_namespaceObject.__)('Templates'),
 621          icon: library_layout,
 622          callback: ({
 623            close
 624          }) => {
 625            const args = {
 626              postType: 'wp_template'
 627            };
 628            const targetUrl = (0,external_wp_url_namespaceObject.addQueryArgs)('site-editor.php', args);
 629            if (isSiteEditor) {
 630              history.push(args);
 631            } else {
 632              document.location = targetUrl;
 633            }
 634            close();
 635          }
 636        });
 637      }
 638      result.push({
 639        name: 'core/edit-site/open-patterns',
 640        label: (0,external_wp_i18n_namespaceObject.__)('Patterns'),
 641        icon: library_symbol,
 642        callback: ({
 643          close
 644        }) => {
 645          if (canCreateTemplate) {
 646            const args = {
 647              postType: 'wp_block'
 648            };
 649            const targetUrl = (0,external_wp_url_namespaceObject.addQueryArgs)('site-editor.php', args);
 650            if (isSiteEditor) {
 651              history.push(args);
 652            } else {
 653              document.location = targetUrl;
 654            }
 655            close();
 656          } else {
 657            // If a user cannot access the site editor
 658            document.location.href = 'edit.php?post_type=wp_block';
 659          }
 660        }
 661      });
 662      return result;
 663    }, [history, isSiteEditor, canCreateTemplate, isBlockBasedTheme]);
 664    return {
 665      commands,
 666      isLoading: false
 667    };
 668  }
 669  function useSiteEditorNavigationCommands() {
 670    (0,external_wp_commands_namespaceObject.useCommandLoader)({
 671      name: 'core/edit-site/navigate-pages',
 672      hook: usePageNavigationCommandLoader
 673    });
 674    (0,external_wp_commands_namespaceObject.useCommandLoader)({
 675      name: 'core/edit-site/navigate-posts',
 676      hook: usePostNavigationCommandLoader
 677    });
 678    (0,external_wp_commands_namespaceObject.useCommandLoader)({
 679      name: 'core/edit-site/navigate-templates',
 680      hook: useTemplateNavigationCommandLoader
 681    });
 682    (0,external_wp_commands_namespaceObject.useCommandLoader)({
 683      name: 'core/edit-site/navigate-template-parts',
 684      hook: useTemplatePartNavigationCommandLoader
 685    });
 686    (0,external_wp_commands_namespaceObject.useCommandLoader)({
 687      name: 'core/edit-site/basic-navigation',
 688      hook: useSiteEditorBasicNavigationCommands,
 689      context: 'site-editor'
 690    });
 691  }
 692  
 693  ;// ./node_modules/@wordpress/core-commands/build-module/private-apis.js
 694  /**
 695   * Internal dependencies
 696   */
 697  
 698  
 699  
 700  function useCommands() {
 701    useAdminNavigationCommands();
 702    useSiteEditorNavigationCommands();
 703  }
 704  const privateApis = {};
 705  lock(privateApis, {
 706    useCommands
 707  });
 708  
 709  ;// ./node_modules/@wordpress/core-commands/build-module/index.js
 710  
 711  
 712  (window.wp = window.wp || {}).coreCommands = __webpack_exports__;
 713  /******/ })()
 714  ;


Generated : Sun Dec 22 08:20:01 2024 Cross-referenced by PHPXref