UNPKG

@wordpress/block-library

Version:
112 lines (110 loc) 4.8 kB
"use strict"; 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 __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/block-library/src/navigation/edit/inner-blocks.js var inner_blocks_exports = {}; __export(inner_blocks_exports, { default: () => NavigationInnerBlocks }); module.exports = __toCommonJS(inner_blocks_exports); var import_core_data = require("@wordpress/core-data"); var import_block_editor = require("@wordpress/block-editor"); var import_data = require("@wordpress/data"); var import_element = require("@wordpress/element"); var import_placeholder_preview = __toESM(require("./placeholder/placeholder-preview")); var import_constants = require("../constants"); var import_jsx_runtime = require("react/jsx-runtime"); function NavigationInnerBlocks({ clientId, hasCustomPlaceholder, orientation, templateLock }) { const { isImmediateParentOfSelectedBlock, selectedBlockHasChildren, isSelected, hasSelectedDescendant } = (0, import_data.useSelect)( (select) => { const { getBlockCount, hasSelectedInnerBlock, getSelectedBlockClientId } = select(import_block_editor.store); const selectedBlockId = getSelectedBlockClientId(); return { isImmediateParentOfSelectedBlock: hasSelectedInnerBlock( clientId, false ), selectedBlockHasChildren: !!getBlockCount(selectedBlockId), hasSelectedDescendant: hasSelectedInnerBlock(clientId, true), // This prop is already available but computing it here ensures it's // fresh compared to isImmediateParentOfSelectedBlock. isSelected: selectedBlockId === clientId }; }, [clientId] ); const [blocks, onInput, onChange] = (0, import_core_data.useEntityBlockEditor)( "postType", "wp_navigation" ); const parentOrChildHasSelection = isSelected || isImmediateParentOfSelectedBlock && !selectedBlockHasChildren; const placeholder = (0, import_element.useMemo)(() => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_placeholder_preview.default, {}), []); const hasMenuItems = !!blocks?.length; const showPlaceholder = !hasCustomPlaceholder && !hasMenuItems && !isSelected; const innerBlocksProps = (0, import_block_editor.useInnerBlocksProps)( { className: "wp-block-navigation__container" }, { value: blocks, onInput, onChange, prioritizedInserterBlocks: import_constants.PRIORITIZED_INSERTER_BLOCKS, defaultBlock: import_constants.DEFAULT_BLOCK, directInsert: true, orientation, templateLock, // As an exception to other blocks which feature nesting, show // the block appender even when a child block is selected. // This should be a temporary fix, to be replaced by improvements to // the sibling inserter. // See https://github.com/WordPress/gutenberg/issues/37572. renderAppender: isSelected || isImmediateParentOfSelectedBlock && !selectedBlockHasChildren || hasSelectedDescendant || // Show the appender while dragging to allow inserting element between item and the appender. parentOrChildHasSelection ? import_block_editor.InnerBlocks.ButtonBlockAppender : false, placeholder: showPlaceholder ? placeholder : void 0, __experimentalCaptureToolbars: true, __unstableDisableLayoutClassNames: true } ); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ...innerBlocksProps }); } //# sourceMappingURL=inner-blocks.js.map