[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/build/routes/navigation-edit/ -> content.js (source)

   1  var __create = Object.create;
   2  var __defProp = Object.defineProperty;
   3  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
   4  var __getOwnPropNames = Object.getOwnPropertyNames;
   5  var __getProtoOf = Object.getPrototypeOf;
   6  var __hasOwnProp = Object.prototype.hasOwnProperty;
   7  var __commonJS = (cb, mod) => function __require() {
   8    return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
   9  };
  10  var __copyProps = (to, from, except, desc) => {
  11    if (from && typeof from === "object" || typeof from === "function") {
  12      for (let key of __getOwnPropNames(from))
  13        if (!__hasOwnProp.call(to, key) && key !== except)
  14          __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15    }
  16    return to;
  17  };
  18  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  19    // If the importer is in node compatibility mode or this is not an ESM
  20    // file that has been converted to a CommonJS file using a Babel-
  21    // compatible transform (i.e. "__esModule" has not been set), then set
  22    // "default" to the CommonJS "module.exports" for node compatibility.
  23    isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  24    mod
  25  ));
  26  
  27  // package-external:@wordpress/i18n
  28  var require_i18n = __commonJS({
  29    "package-external:@wordpress/i18n"(exports, module) {
  30      module.exports = window.wp.i18n;
  31    }
  32  });
  33  
  34  // package-external:@wordpress/components
  35  var require_components = __commonJS({
  36    "package-external:@wordpress/components"(exports, module) {
  37      module.exports = window.wp.components;
  38    }
  39  });
  40  
  41  // vendor-external:react/jsx-runtime
  42  var require_jsx_runtime = __commonJS({
  43    "vendor-external:react/jsx-runtime"(exports, module) {
  44      module.exports = window.ReactJSXRuntime;
  45    }
  46  });
  47  
  48  // package-external:@wordpress/element
  49  var require_element = __commonJS({
  50    "package-external:@wordpress/element"(exports, module) {
  51      module.exports = window.wp.element;
  52    }
  53  });
  54  
  55  // package-external:@wordpress/data
  56  var require_data = __commonJS({
  57    "package-external:@wordpress/data"(exports, module) {
  58      module.exports = window.wp.data;
  59    }
  60  });
  61  
  62  // package-external:@wordpress/core-data
  63  var require_core_data = __commonJS({
  64    "package-external:@wordpress/core-data"(exports, module) {
  65      module.exports = window.wp.coreData;
  66    }
  67  });
  68  
  69  // package-external:@wordpress/html-entities
  70  var require_html_entities = __commonJS({
  71    "package-external:@wordpress/html-entities"(exports, module) {
  72      module.exports = window.wp.htmlEntities;
  73    }
  74  });
  75  
  76  // package-external:@wordpress/block-editor
  77  var require_block_editor = __commonJS({
  78    "package-external:@wordpress/block-editor"(exports, module) {
  79      module.exports = window.wp.blockEditor;
  80    }
  81  });
  82  
  83  // package-external:@wordpress/blocks
  84  var require_blocks = __commonJS({
  85    "package-external:@wordpress/blocks"(exports, module) {
  86      module.exports = window.wp.blocks;
  87    }
  88  });
  89  
  90  // package-external:@wordpress/private-apis
  91  var require_private_apis = __commonJS({
  92    "package-external:@wordpress/private-apis"(exports, module) {
  93      module.exports = window.wp.privateApis;
  94    }
  95  });
  96  
  97  // package-external:@wordpress/primitives
  98  var require_primitives = __commonJS({
  99    "package-external:@wordpress/primitives"(exports, module) {
 100      module.exports = window.wp.primitives;
 101    }
 102  });
 103  
 104  // routes/navigation-edit/stage.tsx
 105  import { useParams } from "@wordpress/route";
 106  
 107  // packages/admin-ui/build-module/breadcrumbs/index.js
 108  var import_i18n = __toESM(require_i18n());
 109  var import_components = __toESM(require_components());
 110  var import_jsx_runtime = __toESM(require_jsx_runtime());
 111  import { Link } from "@wordpress/route";
 112  var BreadcrumbItem = ({
 113    item: { label, to }
 114  }) => {
 115    if (!to) {
 116      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalHeading, { level: 1, truncate: true, children: label }) });
 117    }
 118    return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, { to, children: label }) });
 119  };
 120  var Breadcrumbs = ({ items }) => {
 121    if (!items.length) {
 122      return null;
 123    }
 124    return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("nav", { "aria-label": (0, import_i18n.__)("Breadcrumbs"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
 125      import_components.__experimentalHStack,
 126      {
 127        as: "ul",
 128        className: "admin-ui-breadcrumbs__list",
 129        spacing: 0,
 130        justify: "flex-start",
 131        alignment: "center",
 132        children: items.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BreadcrumbItem, { item }, index))
 133      }
 134    ) });
 135  };
 136  var breadcrumbs_default = Breadcrumbs;
 137  
 138  // node_modules/clsx/dist/clsx.mjs
 139  function r(e) {
 140    var t, f, n = "";
 141    if ("string" == typeof e || "number" == typeof e) n += e;
 142    else if ("object" == typeof e) if (Array.isArray(e)) {
 143      var o = e.length;
 144      for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
 145    } else for (f in e) e[f] && (n && (n += " "), n += f);
 146    return n;
 147  }
 148  function clsx() {
 149    for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
 150    return n;
 151  }
 152  var clsx_default = clsx;
 153  
 154  // packages/admin-ui/build-module/navigable-region/index.js
 155  var import_element = __toESM(require_element());
 156  var import_jsx_runtime2 = __toESM(require_jsx_runtime());
 157  var NavigableRegion = (0, import_element.forwardRef)(
 158    ({ children, className, ariaLabel, as: Tag = "div", ...props }, ref) => {
 159      return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
 160        Tag,
 161        {
 162          ref,
 163          className: clsx_default("admin-ui-navigable-region", className),
 164          "aria-label": ariaLabel,
 165          role: "region",
 166          tabIndex: "-1",
 167          ...props,
 168          children
 169        }
 170      );
 171    }
 172  );
 173  NavigableRegion.displayName = "NavigableRegion";
 174  var navigable_region_default = NavigableRegion;
 175  
 176  // packages/admin-ui/build-module/page/header.js
 177  var import_components3 = __toESM(require_components());
 178  
 179  // packages/admin-ui/build-module/page/sidebar-toggle-slot.js
 180  var import_components2 = __toESM(require_components());
 181  var { Fill: SidebarToggleFill, Slot: SidebarToggleSlot } = (0, import_components2.createSlotFill)("SidebarToggle");
 182  
 183  // packages/admin-ui/build-module/page/header.js
 184  var import_jsx_runtime3 = __toESM(require_jsx_runtime());
 185  function Header({
 186    breadcrumbs,
 187    badges,
 188    title,
 189    subTitle,
 190    actions,
 191    showSidebarToggle = true
 192  }) {
 193    return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_components3.__experimentalVStack, { className: "admin-ui-page__header", as: "header", children: [
 194      /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_components3.__experimentalHStack, { justify: "space-between", spacing: 2, children: [
 195        /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_components3.__experimentalHStack, { spacing: 2, justify: "left", children: [
 196          showSidebarToggle && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
 197            SidebarToggleSlot,
 198            {
 199              bubblesVirtually: true,
 200              className: "admin-ui-page__sidebar-toggle-slot"
 201            }
 202          ),
 203          title && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_components3.__experimentalHeading, { as: "h2", level: 3, weight: 500, truncate: true, children: title }),
 204          breadcrumbs,
 205          badges
 206        ] }),
 207        /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
 208          import_components3.__experimentalHStack,
 209          {
 210            style: { width: "auto", flexShrink: 0 },
 211            spacing: 2,
 212            className: "admin-ui-page__header-actions",
 213            children: actions
 214          }
 215        )
 216      ] }),
 217      subTitle && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "admin-ui-page__header-subtitle", children: subTitle })
 218    ] });
 219  }
 220  
 221  // packages/admin-ui/build-module/page/index.js
 222  var import_jsx_runtime4 = __toESM(require_jsx_runtime());
 223  function Page({
 224    breadcrumbs,
 225    badges,
 226    title,
 227    subTitle,
 228    children,
 229    className,
 230    actions,
 231    hasPadding = false,
 232    showSidebarToggle = true
 233  }) {
 234    const classes = clsx_default("admin-ui-page", className);
 235    return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(navigable_region_default, { className: classes, ariaLabel: title, children: [
 236      (title || breadcrumbs || badges) && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
 237        Header,
 238        {
 239          breadcrumbs,
 240          badges,
 241          title,
 242          subTitle,
 243          actions,
 244          showSidebarToggle
 245        }
 246      ),
 247      hasPadding ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "admin-ui-page__content has-padding", children }) : children
 248    ] });
 249  }
 250  Page.SidebarToggleFill = SidebarToggleFill;
 251  var page_default = Page;
 252  
 253  // routes/navigation-edit/stage.tsx
 254  var import_data3 = __toESM(require_data());
 255  var import_core_data2 = __toESM(require_core_data());
 256  var import_i18n3 = __toESM(require_i18n());
 257  var import_html_entities = __toESM(require_html_entities());
 258  
 259  // routes/navigation-edit/editor/index.tsx
 260  var import_element3 = __toESM(require_element());
 261  var import_block_editor3 = __toESM(require_block_editor());
 262  var import_blocks2 = __toESM(require_blocks());
 263  var import_components5 = __toESM(require_components());
 264  import { useEditorAssets } from "@wordpress/lazy-editor";
 265  
 266  // routes/navigation-edit/editor/style.scss
 267  var css = `.navigation-edit-editor__hidden-blocks {
 268    display: none;
 269  }`;
 270  document.head.appendChild(document.createElement("style")).appendChild(document.createTextNode(css));
 271  
 272  // routes/navigation-edit/editor/content.tsx
 273  var import_block_editor2 = __toESM(require_block_editor());
 274  var import_data2 = __toESM(require_data());
 275  var import_blocks = __toESM(require_blocks());
 276  var import_element2 = __toESM(require_element());
 277  var import_core_data = __toESM(require_core_data());
 278  
 279  // routes/lock-unlock.ts
 280  var import_private_apis = __toESM(require_private_apis());
 281  var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
 282    "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
 283    "@wordpress/routes"
 284  );
 285  
 286  // packages/icons/build-module/library/chevron-down.js
 287  var import_primitives = __toESM(require_primitives());
 288  var import_jsx_runtime5 = __toESM(require_jsx_runtime());
 289  var chevron_down_default = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives.Path, { d: "M17.5 11.6L12 16l-5.5-4.4.9-1.2L12 14l4.5-3.6 1 1.2z" }) });
 290  
 291  // packages/icons/build-module/library/chevron-up.js
 292  var import_primitives2 = __toESM(require_primitives());
 293  var import_jsx_runtime6 = __toESM(require_jsx_runtime());
 294  var chevron_up_default = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_primitives2.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_primitives2.Path, { d: "M6.5 12.4L12 8l5.5 4.4-.9 1.2L12 10l-4.5 3.6-1-1.2z" }) });
 295  
 296  // packages/icons/build-module/library/more-vertical.js
 297  var import_primitives3 = __toESM(require_primitives());
 298  var import_jsx_runtime7 = __toESM(require_jsx_runtime());
 299  var more_vertical_default = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_primitives3.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_primitives3.Path, { d: "M13 19h-2v-2h2v2zm0-6h-2v-2h2v2zm0-6h-2V5h2v2z" }) });
 300  
 301  // routes/navigation-edit/editor/leaf-more-menu.tsx
 302  var import_components4 = __toESM(require_components());
 303  var import_data = __toESM(require_data());
 304  var import_i18n2 = __toESM(require_i18n());
 305  var import_block_editor = __toESM(require_block_editor());
 306  var POPOVER_PROPS = {
 307    className: "block-editor-block-settings-menu__popover",
 308    placement: "bottom-start"
 309  };
 310  function LeafMoreMenu({
 311    block,
 312    ...props
 313  }) {
 314    const { clientId } = block;
 315    const { moveBlocksDown, moveBlocksUp, removeBlocks } = (0, import_data.useDispatch)(import_block_editor.store);
 316    const removeLabel = (0, import_i18n2.sprintf)(
 317      /* translators: %s: block name */
 318      (0, import_i18n2.__)("Remove %s"),
 319      (0, import_block_editor.BlockTitle)({ clientId, maximumLength: 25 })
 320    );
 321    const rootClientId = (0, import_data.useSelect)(
 322      (select) => {
 323        const { getBlockRootClientId } = select(import_block_editor.store);
 324        return getBlockRootClientId(clientId);
 325      },
 326      [clientId]
 327    );
 328    return /* @__PURE__ */ React.createElement(
 329      import_components4.DropdownMenu,
 330      {
 331        icon: more_vertical_default,
 332        label: (0, import_i18n2.__)("Options"),
 333        className: "block-editor-block-settings-menu",
 334        popoverProps: POPOVER_PROPS,
 335        noIcons: true,
 336        ...props
 337      },
 338      ({ onClose }) => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(import_components4.MenuGroup, null, /* @__PURE__ */ React.createElement(
 339        import_components4.MenuItem,
 340        {
 341          icon: chevron_up_default,
 342          onClick: () => {
 343            moveBlocksUp([clientId], rootClientId);
 344            onClose();
 345          }
 346        },
 347        (0, import_i18n2.__)("Move up")
 348      ), /* @__PURE__ */ React.createElement(
 349        import_components4.MenuItem,
 350        {
 351          icon: chevron_down_default,
 352          onClick: () => {
 353            moveBlocksDown([clientId], rootClientId);
 354            onClose();
 355          }
 356        },
 357        (0, import_i18n2.__)("Move down")
 358      )), /* @__PURE__ */ React.createElement(import_components4.MenuGroup, null, /* @__PURE__ */ React.createElement(
 359        import_components4.MenuItem,
 360        {
 361          onClick: () => {
 362            removeBlocks([clientId], false);
 363            onClose();
 364          }
 365        },
 366        removeLabel
 367      )))
 368    );
 369  }
 370  
 371  // routes/navigation-edit/editor/content.tsx
 372  var { PrivateListView } = unlock(import_block_editor2.privateApis);
 373  var MAX_PAGE_COUNT = 100;
 374  var PAGES_QUERY = [
 375    "postType",
 376    "page",
 377    {
 378      per_page: MAX_PAGE_COUNT,
 379      _fields: ["id", "link", "menu_order", "parent", "title", "type"],
 380      // TODO: When https://core.trac.wordpress.org/ticket/39037 REST API support for multiple orderby
 381      // values is resolved, update 'orderby' to [ 'menu_order', 'post_title' ] to provide a consistent
 382      // sort.
 383      orderby: "menu_order",
 384      order: "asc"
 385    }
 386  ];
 387  function NavigationMenuContent({
 388    rootClientId
 389  }) {
 390    const { listViewRootClientId, isLoading } = (0, import_data2.useSelect)(
 391      (select) => {
 392        const {
 393          areInnerBlocksControlled,
 394          getBlockName,
 395          getBlockCount,
 396          getBlockOrder
 397        } = select(import_block_editor2.store);
 398        const { isResolving } = select(import_core_data.store);
 399        const blockClientIds = getBlockOrder(rootClientId);
 400        const hasOnlyPageListBlock = blockClientIds.length === 1 && getBlockName(blockClientIds[0]) === "core/page-list";
 401        const pageListHasBlocks = hasOnlyPageListBlock && getBlockCount(blockClientIds[0]) > 0;
 402        const isLoadingPages = isResolving(
 403          "getEntityRecords",
 404          PAGES_QUERY
 405        );
 406        return {
 407          listViewRootClientId: pageListHasBlocks ? blockClientIds[0] : rootClientId,
 408          // This is a small hack to wait for the navigation block
 409          // to actually load its inner blocks.
 410          isLoading: !areInnerBlocksControlled(rootClientId) || isLoadingPages
 411        };
 412      },
 413      [rootClientId]
 414    );
 415    const { replaceBlock, __unstableMarkNextChangeAsNotPersistent } = (0, import_data2.useDispatch)(import_block_editor2.store);
 416    const offCanvasOnselect = (0, import_element2.useCallback)(
 417      (block) => {
 418        if (block.name === "core/navigation-link" && !block.attributes.url) {
 419          __unstableMarkNextChangeAsNotPersistent();
 420          replaceBlock(
 421            block.clientId,
 422            (0, import_blocks.createBlock)("core/navigation-link", block.attributes)
 423          );
 424        }
 425      },
 426      [__unstableMarkNextChangeAsNotPersistent, replaceBlock]
 427    );
 428    return /* @__PURE__ */ React.createElement(React.Fragment, null, !isLoading && /* @__PURE__ */ React.createElement(
 429      PrivateListView,
 430      {
 431        rootClientId: listViewRootClientId,
 432        onSelect: offCanvasOnselect,
 433        blockSettingsMenu: LeafMoreMenu,
 434        showAppender: false,
 435        isExpanded: true
 436      }
 437    ), /* @__PURE__ */ React.createElement("div", { className: "navigation-edit-editor__hidden-blocks" }, /* @__PURE__ */ React.createElement(import_block_editor2.BlockList, null)));
 438  }
 439  
 440  // routes/navigation-edit/editor/index.tsx
 441  var noop = () => {
 442  };
 443  function NavigationMenuEditor({ id }) {
 444    const { isReady: assetsReady } = useEditorAssets();
 445    const blocks = (0, import_element3.useMemo)(() => {
 446      if (!assetsReady || !id) {
 447        return [];
 448      }
 449      return [(0, import_blocks2.createBlock)("core/navigation", { ref: id })];
 450    }, [assetsReady, id]);
 451    if (!assetsReady || !blocks.length) {
 452      return /* @__PURE__ */ React.createElement(
 453        "div",
 454        {
 455          style: {
 456            display: "flex",
 457            justifyContent: "center",
 458            alignItems: "center",
 459            height: "100vh"
 460          }
 461        },
 462        /* @__PURE__ */ React.createElement(import_components5.Spinner, null)
 463      );
 464    }
 465    return /* @__PURE__ */ React.createElement(
 466      import_block_editor3.BlockEditorProvider,
 467      {
 468        settings: {},
 469        value: blocks,
 470        onChange: noop,
 471        onInput: noop
 472      },
 473      /* @__PURE__ */ React.createElement(NavigationMenuContent, { rootClientId: blocks[0].clientId })
 474    );
 475  }
 476  
 477  // routes/navigation-edit/stage.tsx
 478  var NAVIGATION_POST_TYPE = "wp_navigation";
 479  function NavigationEditStage() {
 480    const { id } = useParams({ from: "/navigation/edit/$id" });
 481    const navigationId = parseInt(id);
 482    const { navigationMenu } = (0, import_data3.useSelect)(
 483      (select) => {
 484        const { getEntityRecord } = select(import_core_data2.store);
 485        return {
 486          navigationMenu: getEntityRecord(
 487            "postType",
 488            NAVIGATION_POST_TYPE,
 489            navigationId
 490          )
 491        };
 492      },
 493      [navigationId]
 494    );
 495    if (!navigationMenu) {
 496      return;
 497    }
 498    const menuTitle = navigationMenu.title?.rendered || navigationMenu.title?.raw || "";
 499    return /* @__PURE__ */ React.createElement(
 500      page_default,
 501      {
 502        breadcrumbs: /* @__PURE__ */ React.createElement(
 503          breadcrumbs_default,
 504          {
 505            items: [
 506              {
 507                label: (0, import_i18n3.__)("Navigation"),
 508                to: "/navigation/list"
 509              },
 510              {
 511                label: (0, import_html_entities.decodeEntities)(menuTitle)
 512              }
 513            ]
 514          }
 515        ),
 516        hasPadding: true
 517      },
 518      /* @__PURE__ */ React.createElement(NavigationMenuEditor, { id: navigationId })
 519    );
 520  }
 521  var stage = NavigationEditStage;
 522  export {
 523    stage
 524  };


Generated : Tue May 5 08:20:14 2026 Cross-referenced by PHPXref