UNPKG

@wordpress/block-library

Version:
145 lines (142 loc) 5.6 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _blockEditor = require("@wordpress/block-editor"); var _components = require("@wordpress/components"); var _data = require("@wordpress/data"); var _i18n = require("@wordpress/i18n"); var _navigationMenuSelector = _interopRequireDefault(require("./navigation-menu-selector")); var _lockUnlock = require("../../lock-unlock"); var _deletedNavigationWarning = _interopRequireDefault(require("./deleted-navigation-warning")); var _useNavigationMenu = _interopRequireDefault(require("../use-navigation-menu")); var _leafMoreMenu = _interopRequireDefault(require("./leaf-more-menu")); var _updateAttributes = require("../../navigation-link/update-attributes"); var _linkUi = require("../../navigation-link/link-ui"); var _jsxRuntime = require("react/jsx-runtime"); /** * WordPress dependencies */ /** * Internal dependencies */ const actionLabel = /* translators: %s: The name of a menu. */(0, _i18n.__)("Switch to '%s'"); const BLOCKS_WITH_LINK_UI_SUPPORT = ['core/navigation-link', 'core/navigation-submenu']; const { PrivateListView } = (0, _lockUnlock.unlock)(_blockEditor.privateApis); function AdditionalBlockContent({ block, insertedBlock, setInsertedBlock }) { const { updateBlockAttributes } = (0, _data.useDispatch)(_blockEditor.store); const supportsLinkControls = BLOCKS_WITH_LINK_UI_SUPPORT?.includes(insertedBlock?.name); const blockWasJustInserted = insertedBlock?.clientId === block.clientId; const showLinkControls = supportsLinkControls && blockWasJustInserted; if (!showLinkControls) { return null; } const setInsertedBlockAttributes = _insertedBlockClientId => _updatedAttributes => { if (!_insertedBlockClientId) { return; } updateBlockAttributes(_insertedBlockClientId, _updatedAttributes); }; return /*#__PURE__*/(0, _jsxRuntime.jsx)(_linkUi.LinkUI, { clientId: insertedBlock?.clientId, link: insertedBlock?.attributes, onClose: () => { setInsertedBlock(null); }, onChange: updatedValue => { (0, _updateAttributes.updateAttributes)(updatedValue, setInsertedBlockAttributes(insertedBlock?.clientId), insertedBlock?.attributes); setInsertedBlock(null); }, onCancel: () => { setInsertedBlock(null); } }); } const MainContent = ({ clientId, currentMenuId, isLoading, isNavigationMenuMissing, onCreateNew }) => { const hasChildren = (0, _data.useSelect)(select => { return !!select(_blockEditor.store).getBlockCount(clientId); }, [clientId]); const { navigationMenu } = (0, _useNavigationMenu.default)(currentMenuId); if (currentMenuId && isNavigationMenuMissing) { return /*#__PURE__*/(0, _jsxRuntime.jsx)(_deletedNavigationWarning.default, { onCreateNew: onCreateNew, isNotice: true }); } if (isLoading) { return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Spinner, {}); } const description = navigationMenu ? (0, _i18n.sprintf)(/* translators: %s: The name of a menu. */ (0, _i18n.__)('Structure for Navigation Menu: %s'), navigationMenu?.title || (0, _i18n.__)('Untitled menu')) : (0, _i18n.__)('You have not yet created any menus. Displaying a list of your Pages'); return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", { className: "wp-block-navigation__menu-inspector-controls", children: [!hasChildren && /*#__PURE__*/(0, _jsxRuntime.jsx)("p", { className: "wp-block-navigation__menu-inspector-controls__empty-message", children: (0, _i18n.__)('This Navigation Menu is empty.') }), /*#__PURE__*/(0, _jsxRuntime.jsx)(PrivateListView, { rootClientId: clientId, isExpanded: true, description: description, showAppender: true, blockSettingsMenu: _leafMoreMenu.default, additionalBlockContent: AdditionalBlockContent })] }); }; const MenuInspectorControls = props => { const { createNavigationMenuIsSuccess, createNavigationMenuIsError, currentMenuId = null, onCreateNew, onSelectClassicMenu, onSelectNavigationMenu, isManageMenusButtonDisabled, blockEditingMode } = props; return /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.InspectorControls, { group: "list", children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.PanelBody, { title: null, children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, { className: "wp-block-navigation-off-canvas-editor__header", children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalHeading, { className: "wp-block-navigation-off-canvas-editor__title", level: 2, children: (0, _i18n.__)('Menu') }), blockEditingMode === 'default' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_navigationMenuSelector.default, { currentMenuId: currentMenuId, onSelectClassicMenu: onSelectClassicMenu, onSelectNavigationMenu: onSelectNavigationMenu, onCreateNew: onCreateNew, createNavigationMenuIsSuccess: createNavigationMenuIsSuccess, createNavigationMenuIsError: createNavigationMenuIsError, actionLabel: actionLabel, isManageMenusButtonDisabled: isManageMenusButtonDisabled })] }), /*#__PURE__*/(0, _jsxRuntime.jsx)(MainContent, { ...props })] }) }); }; var _default = exports.default = MenuInspectorControls; //# sourceMappingURL=menu-inspector-controls.js.map