@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 6.58 kB
Source Map (JSON)
{"version":3,"file":"menu-inspector-controls.mjs","names":["blockEditorPrivateApis","blockEditorStore","WCSpinner"],"sources":["../../../src/navigation/edit/menu-inspector-controls.jsx"],"sourcesContent":["import {\n\tprivateApis as blockEditorPrivateApis,\n\tInspectorControls,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { PanelBody, Spinner as WCSpinner } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useContext } from '@wordpress/element';\nimport NavigationMenuSelector from './navigation-menu-selector';\nimport { unlock } from '../../lock-unlock';\nimport DeletedNavigationWarning from './deleted-navigation-warning';\nimport useNavigationMenu from '../use-navigation-menu';\nimport LeafMoreMenu from './leaf-more-menu';\nimport { NavigationLinkUI } from './navigation-link-ui';\nimport NavigationListViewHeader from './navigation-list-view-header';\n\nconst actionLabel =\n\t/* translators: %s: The name of a menu. */ __( \"Switch to '%s'\" );\nconst {\n\tPrivateListView,\n\tPrivateBlockContext,\n\tuseListViewPanelState,\n\tuseBlockDisplayTitle,\n} = unlock( blockEditorPrivateApis );\n\nconst MainContent = ( {\n\tclientId,\n\tcurrentMenuId,\n\tisLoading,\n\tisNavigationMenuMissing,\n\tonCreateNew,\n\texpandRevision,\n} ) => {\n\tconst hasChildren = useSelect(\n\t\t( select ) => {\n\t\t\treturn !! select( blockEditorStore ).getBlockCount( clientId );\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { openListViewContentPanel } = unlock(\n\t\tuseDispatch( blockEditorStore )\n\t);\n\n\tconst { navigationMenu } = useNavigationMenu( currentMenuId );\n\n\tif ( currentMenuId && isNavigationMenuMissing ) {\n\t\treturn (\n\t\t\t<DeletedNavigationWarning onCreateNew={ onCreateNew } isNotice />\n\t\t);\n\t}\n\n\tif ( isLoading ) {\n\t\treturn <WCSpinner />;\n\t}\n\n\tconst description = navigationMenu\n\t\t? sprintf(\n\t\t\t\t/* translators: %s: The name of a menu. */\n\t\t\t\t__( 'Structure for Navigation Menu: %s' ),\n\t\t\t\tnavigationMenu?.title || __( 'Untitled menu' )\n\t\t\t)\n\t\t: __(\n\t\t\t\t'You have not yet created any menus. Displaying a list of your Pages'\n\t\t\t);\n\n\treturn (\n\t\t<div className=\"wp-block-navigation__menu-inspector-controls\">\n\t\t\t{ ! hasChildren && (\n\t\t\t\t<p className=\"wp-block-navigation__menu-inspector-controls__empty-message\">\n\t\t\t\t\t{ __( 'This Navigation Menu is empty.' ) }\n\t\t\t\t</p>\n\t\t\t) }\n\t\t\t<PrivateListView\n\t\t\t\tkey={ `${ clientId }-${ expandRevision }` }\n\t\t\t\trootClientId={ clientId }\n\t\t\t\tisExpanded\n\t\t\t\tdescription={ description }\n\t\t\t\tshowAppender\n\t\t\t\tblockSettingsMenu={ LeafMoreMenu }\n\t\t\t\tadditionalBlockContent={ NavigationLinkUI }\n\t\t\t\tonSelect={ openListViewContentPanel }\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nconst MenuInspectorControls = ( props ) => {\n\tconst {\n\t\tclientId,\n\t\tcurrentMenuId = null,\n\t\tonCreateNew,\n\t\tonSelectClassicMenu,\n\t\tonSelectNavigationMenu,\n\t\tisManageMenusButtonDisabled,\n\t\tblockEditingMode,\n\t} = props;\n\n\tconst { isSelectionWithinCurrentSection } =\n\t\tuseContext( PrivateBlockContext );\n\n\tconst blockTitle = useBlockDisplayTitle( {\n\t\tclientId,\n\t\tcontext: 'list-view',\n\t} );\n\n\t// Only make panel collapsible in contentOnly mode\n\tconst showBlockTitle = isSelectionWithinCurrentSection;\n\n\tconst { isOpened, expandRevision, handleToggle } =\n\t\tuseListViewPanelState( clientId );\n\n\tif ( ! showBlockTitle ) {\n\t\treturn (\n\t\t\t<InspectorControls group=\"list\">\n\t\t\t\t<PanelBody title={ null }>\n\t\t\t\t\t<NavigationListViewHeader\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tblockEditingMode={ blockEditingMode }\n\t\t\t\t\t\tcurrentMenuId={ currentMenuId }\n\t\t\t\t\t\tonSelectClassicMenu={ onSelectClassicMenu }\n\t\t\t\t\t\tonSelectNavigationMenu={ onSelectNavigationMenu }\n\t\t\t\t\t\tonCreateNew={ onCreateNew }\n\t\t\t\t\t\tisManageMenusButtonDisabled={\n\t\t\t\t\t\t\tisManageMenusButtonDisabled\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<MainContent\n\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\texpandRevision={ expandRevision }\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t);\n\t}\n\n\t// ContentOnly mode: use collapsible PanelBody\n\treturn (\n\t\t<InspectorControls group=\"list\">\n\t\t\t<PanelBody\n\t\t\t\ttitle={ blockTitle }\n\t\t\t\topened={ isOpened }\n\t\t\t\tonToggle={ handleToggle }\n\t\t\t>\n\t\t\t\t{ blockEditingMode === 'default' && (\n\t\t\t\t\t<NavigationMenuSelector\n\t\t\t\t\t\tcurrentMenuId={ currentMenuId }\n\t\t\t\t\t\tonSelectClassicMenu={ onSelectClassicMenu }\n\t\t\t\t\t\tonSelectNavigationMenu={ onSelectNavigationMenu }\n\t\t\t\t\t\tonCreateNew={ onCreateNew }\n\t\t\t\t\t\tactionLabel={ actionLabel }\n\t\t\t\t\t\tisManageMenusButtonDisabled={\n\t\t\t\t\t\t\tisManageMenusButtonDisabled\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t<MainContent { ...props } expandRevision={ expandRevision } />\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n};\n\nexport default MenuInspectorControls;\n"],"mappings":";;;;;;;;;;;;;;AAiBA,MAAM,cACsC,GAAI,gBAAiB;AACjE,MAAM,EACL,iBACA,qBACA,uBACA,yBACG,OAAQA,WAAuB;AAEnC,MAAM,eAAgB,EACrB,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