@wordpress/block-library
Version:
Block library for the WordPress editor.
125 lines (124 loc) • 6.27 kB
JavaScript
;
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 _wordpress_block_editor = require("@wordpress/block-editor");
let _wordpress_components = require("@wordpress/components");
let _wordpress_data = require("@wordpress/data");
let _wordpress_i18n = require("@wordpress/i18n");
let _wordpress_element = require("@wordpress/element");
let __navigation_menu_selector_jsx = require("./navigation-menu-selector.cjs");
__navigation_menu_selector_jsx = __toESM(__navigation_menu_selector_jsx);
let ______lock_unlock_ts = require("../../lock-unlock.cjs");
let __deleted_navigation_warning_jsx = require("./deleted-navigation-warning.cjs");
__deleted_navigation_warning_jsx = __toESM(__deleted_navigation_warning_jsx);
let ___use_navigation_menu_js = require("../use-navigation-menu.cjs");
___use_navigation_menu_js = __toESM(___use_navigation_menu_js);
let __leaf_more_menu_jsx = require("./leaf-more-menu.cjs");
__leaf_more_menu_jsx = __toESM(__leaf_more_menu_jsx);
let __navigation_link_ui_jsx = require("./navigation-link-ui.cjs");
let __navigation_list_view_header_jsx = require("./navigation-list-view-header.cjs");
__navigation_list_view_header_jsx = __toESM(__navigation_list_view_header_jsx);
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/navigation/edit/menu-inspector-controls.jsx
const actionLabel = (0, _wordpress_i18n.__)("Switch to '%s'");
const { PrivateListView, PrivateBlockContext, useListViewPanelState, useBlockDisplayTitle } = (0, ______lock_unlock_ts.unlock)(_wordpress_block_editor.privateApis);
const MainContent = ({ clientId, currentMenuId, isLoading, isNavigationMenuMissing, onCreateNew, expandRevision }) => {
const hasChildren = (0, _wordpress_data.useSelect)((select) => {
return !!select(_wordpress_block_editor.store).getBlockCount(clientId);
}, [clientId]);
const { openListViewContentPanel } = (0, ______lock_unlock_ts.unlock)((0, _wordpress_data.useDispatch)(_wordpress_block_editor.store));
const { navigationMenu } = (0, ___use_navigation_menu_js.default)(currentMenuId);
if (currentMenuId && isNavigationMenuMissing) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__deleted_navigation_warning_jsx.default, {
onCreateNew,
isNotice: true
});
if (isLoading) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Spinner, {});
const description = navigationMenu ? (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Structure for Navigation Menu: %s"), navigationMenu?.title || (0, _wordpress_i18n.__)("Untitled menu")) : (0, _wordpress_i18n.__)("You have not yet created any menus. Displaying a list of your Pages");
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
className: "wp-block-navigation__menu-inspector-controls",
children: [!hasChildren && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
className: "wp-block-navigation__menu-inspector-controls__empty-message",
children: (0, _wordpress_i18n.__)("This Navigation Menu is empty.")
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PrivateListView, {
rootClientId: clientId,
isExpanded: true,
description,
showAppender: true,
blockSettingsMenu: __leaf_more_menu_jsx.default,
additionalBlockContent: __navigation_link_ui_jsx.NavigationLinkUI,
onSelect: openListViewContentPanel
}, `${clientId}-${expandRevision}`)]
});
};
const MenuInspectorControls = (props) => {
const { clientId, currentMenuId = null, onCreateNew, onSelectClassicMenu, onSelectNavigationMenu, isManageMenusButtonDisabled, blockEditingMode } = props;
const { isSelectionWithinCurrentSection } = (0, _wordpress_element.useContext)(PrivateBlockContext);
const blockTitle = useBlockDisplayTitle({
clientId,
context: "list-view"
});
const showBlockTitle = isSelectionWithinCurrentSection;
const { isOpened, expandRevision, handleToggle } = useListViewPanelState(clientId);
if (!showBlockTitle) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.InspectorControls, {
group: "list",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.PanelBody, {
title: null,
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__navigation_list_view_header_jsx.default, {
clientId,
blockEditingMode,
currentMenuId,
onSelectClassicMenu,
onSelectNavigationMenu,
onCreateNew,
isManageMenusButtonDisabled
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MainContent, {
...props,
expandRevision
})]
})
});
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.InspectorControls, {
group: "list",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.PanelBody, {
title: blockTitle,
opened: isOpened,
onToggle: handleToggle,
children: [blockEditingMode === "default" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__navigation_menu_selector_jsx.default, {
currentMenuId,
onSelectClassicMenu,
onSelectNavigationMenu,
onCreateNew,
actionLabel,
isManageMenusButtonDisabled
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MainContent, {
...props,
expandRevision
})]
})
});
};
exports.default = MenuInspectorControls;
//# sourceMappingURL=menu-inspector-controls.cjs.map