@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 4.84 kB
Source Map (JSON)
{"version":3,"file":"inner-blocks.cjs","names":["useSelect","blockEditorStore","useEntityBlockEditor","useMemo","PlaceholderPreview","InnerBlocks","useInnerBlocksProps","PRIORITIZED_INSERTER_BLOCKS","DEFAULT_BLOCK"],"sources":["../../../src/navigation/edit/inner-blocks.jsx"],"sourcesContent":["import { useEntityBlockEditor } from '@wordpress/core-data';\nimport {\n\tuseInnerBlocksProps,\n\tInnerBlocks,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\nimport PlaceholderPreview from './placeholder/placeholder-preview';\nimport { DEFAULT_BLOCK, PRIORITIZED_INSERTER_BLOCKS } from '../constants';\n\nexport default function NavigationInnerBlocks( {\n\tclientId,\n\thasCustomPlaceholder,\n\torientation,\n\ttemplateLock,\n} ) {\n\tconst {\n\t\tisImmediateParentOfSelectedBlock,\n\t\tselectedBlockHasChildren,\n\t\tisSelected,\n\t\thasSelectedDescendant,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockCount,\n\t\t\t\thasSelectedInnerBlock,\n\t\t\t\tgetSelectedBlockClientId,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst selectedBlockId = getSelectedBlockClientId();\n\n\t\t\treturn {\n\t\t\t\tisImmediateParentOfSelectedBlock: hasSelectedInnerBlock(\n\t\t\t\t\tclientId,\n\t\t\t\t\tfalse\n\t\t\t\t),\n\t\t\t\tselectedBlockHasChildren: !! getBlockCount( selectedBlockId ),\n\t\t\t\thasSelectedDescendant: hasSelectedInnerBlock( clientId, true ),\n\n\t\t\t\t// This prop is already available but computing it here ensures it's\n\t\t\t\t// fresh compared to isImmediateParentOfSelectedBlock.\n\t\t\t\tisSelected: selectedBlockId === clientId,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst [ blocks, onInput, onChange ] = useEntityBlockEditor(\n\t\t'postType',\n\t\t'wp_navigation'\n\t);\n\n\t// When the block is selected itself or has a top level item selected that\n\t// doesn't itself have children, show the standard appender. Else show no\n\t// appender.\n\tconst parentOrChildHasSelection =\n\t\tisSelected ||\n\t\t( isImmediateParentOfSelectedBlock && ! selectedBlockHasChildren );\n\n\tconst placeholder = useMemo( () => <PlaceholderPreview />, [] );\n\n\tconst hasMenuItems = !! blocks?.length;\n\n\t// If there is a `ref` attribute pointing to a `wp_navigation` but\n\t// that menu has no **items** (i.e. empty) then show a placeholder.\n\t// The block must also be selected else the placeholder will display\n\t// alongside the appender.\n\tconst showPlaceholder =\n\t\t! hasCustomPlaceholder && ! hasMenuItems && ! isSelected;\n\n\t// When the block is selected but has no items yet, show the button\n\t// appender. Otherwise, show the dropdown appender.\n\t// As an exception to other blocks which feature nesting, the appender stays\n\t// visible even when a child block (or a submenu item) is selected.\n\t// See https://github.com/WordPress/gutenberg/issues/37572.\n\tlet renderAppender = false;\n\tif ( isSelected && ! hasMenuItems ) {\n\t\trenderAppender = InnerBlocks.ButtonBlockAppender;\n\t} else if ( parentOrChildHasSelection || hasSelectedDescendant ) {\n\t\trenderAppender = InnerBlocks.DefaultBlockAppender;\n\t}\n\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{\n\t\t\tclassName: 'wp-block-navigation__container',\n\t\t},\n\t\t{\n\t\t\tvalue: blocks,\n\t\t\tonInput,\n\t\t\tonChange,\n\t\t\tprioritizedInserterBlocks: PRIORITIZED_INSERTER_BLOCKS,\n\t\t\tdefaultBlock: DEFAULT_BLOCK,\n\t\t\tdirectInsert: true,\n\t\t\torientation,\n\t\t\ttemplateLock,\n\t\t\trenderAppender,\n\t\t\tplaceholder: showPlaceholder ? placeholder : undefined,\n\t\t\t__experimentalCaptureToolbars: true,\n\t\t\t__unstableDisableLayoutClassNames: true,\n\t\t}\n\t);\n\n\treturn <div { ...innerBlocksProps } />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;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