UNPKG

@wordpress/block-library

Version:
88 lines (87 loc) • 4.72 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); // \0rolldown/runtime.js var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { key = keys[i]; if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: ((k) => from[k]).bind(null, key), enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); let clsx = require("clsx"); clsx = __toESM(clsx); let _wordpress_block_editor = require("@wordpress/block-editor"); let _wordpress_data = require("@wordpress/data"); let _wordpress_core_data = require("@wordpress/core-data"); let _wordpress_dom = require("@wordpress/dom"); let ___navigation_link_icons_jsx = require("../navigation-link/icons.cjs"); let ___navigation_edit_utils_js = require("../navigation/edit/utils.cjs"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/block-library/src/page-list-item/edit.jsx function useFrontPageId() { return (0, _wordpress_data.useSelect)((select) => { if (!select(_wordpress_core_data.store).canUser("read", { kind: "root", name: "site" })) return; const site = select(_wordpress_core_data.store).getEntityRecord("root", "site"); return site?.show_on_front === "page" && site?.page_on_front; }, []); } function PageListItemEdit({ context, attributes }) { const { id, label, link, hasChildren, title } = attributes; const isNavigationChild = "showSubmenuIcon" in context; const frontPageId = useFrontPageId(); const submenuVisibility = context.submenuVisibility; const openOnClick = submenuVisibility === "click"; const innerBlocksColors = (0, ___navigation_edit_utils_js.getColors)(context, true); const navigationChildBlockProps = (0, ___navigation_edit_utils_js.getNavigationChildBlockProps)(innerBlocksColors); const blockProps = (0, _wordpress_block_editor.useBlockProps)(navigationChildBlockProps, { className: "wp-block-pages-list__item" }); const innerBlocksProps = (0, _wordpress_block_editor.useInnerBlocksProps)(blockProps); return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", { className: (0, clsx.default)("wp-block-pages-list__item", { "has-child": hasChildren, "wp-block-navigation-item": isNavigationChild, "open-on-click": openOnClick, "open-always": submenuVisibility === "always", "open-on-hover-click": submenuVisibility === "hover" && context.showSubmenuIcon, "menu-item-home": id === frontPageId }), children: [hasChildren && openOnClick ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", { type: "button", className: "wp-block-navigation-item__content wp-block-navigation-submenu__toggle", "aria-expanded": "false", dangerouslySetInnerHTML: { __html: (0, _wordpress_dom.safeHTML)(label) } }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "wp-block-page-list__submenu-icon wp-block-navigation__submenu-icon", children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___navigation_link_icons_jsx.ItemSubmenuIcon, {}) })] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", { className: (0, clsx.default)("wp-block-pages-list__item__link", { "wp-block-navigation-item__content": isNavigationChild }), href: link, dangerouslySetInnerHTML: { __html: (0, _wordpress_dom.safeHTML)(title) } }), hasChildren && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [!openOnClick && context.showSubmenuIcon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", { className: "wp-block-navigation-item__content wp-block-navigation-submenu__toggle wp-block-page-list__submenu-icon wp-block-navigation__submenu-icon", "aria-expanded": "false", type: "button", children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___navigation_link_icons_jsx.ItemSubmenuIcon, {}) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", { ...innerBlocksProps })] })] }, id); } exports.default = PageListItemEdit; //# sourceMappingURL=edit.cjs.map