@wordpress/components
Version:
UI components for WordPress.
1 lines • 27.9 kB
Source Map (JSON)
{"version":3,"file":"hook.mjs","names":["styles"],"sources":["../../../../style-runtime/src/index.ts","../../../src/tools-panel/style.module.scss","../../../src/tools-panel/tools-panel/hook.ts"],"sourcesContent":["type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n","import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"2b5d59eda1\", \"._6c1192219f33c902__tools-panel{border-top:1px solid #ddd;margin-top:-1px;padding:16px}.cd15a9c80fb6cbd4__tools-panel-with-inner-wrapper>div:not(:first-of-type){column-gap:var(--wpds-dimension-gap-lg,16px);display:grid;grid-column:1/-1;grid-template-columns:repeat(2,minmax(0,1fr));row-gap:var(--wpds-dimension-gap-lg,16px)}.e58228332b88343f__tools-panel-hidden-inner-wrapper>div:not(:first-of-type){display:none}._00ef83981f008ed1__tools-panel-header{gap:8px;grid-column:1/-1}._00ef83981f008ed1__tools-panel-header .components-dropdown-menu{line-height:0;margin:-4px 0}._00ef83981f008ed1__tools-panel-header._00ef83981f008ed1__tools-panel-header._00ef83981f008ed1__tools-panel-header._00ef83981f008ed1__tools-panel-header .components-dropdown-menu__toggle{min-width:24px;padding:0}._07c5a099c6314de5__tools-panel-heading._07c5a099c6314de5__tools-panel-heading{font-size:inherit;line-height:normal;margin:0}._900a3554bc5023e1__tools-panel-item{grid-column:1/-1}._900a3554bc5023e1__tools-panel-item>div,._900a3554bc5023e1__tools-panel-item>fieldset{margin-bottom:0;max-width:100%;padding-bottom:0}._900a3554bc5023e1__tools-panel-item .components-base-control__help,._900a3554bc5023e1__tools-panel-item._900a3554bc5023e1__tools-panel-item .components-base-control,._900a3554bc5023e1__tools-panel-item._900a3554bc5023e1__tools-panel-item .components-base-control .components-base-control__field:last-child{margin-bottom:0}._175ccc0d8111dddf__tools-panel-item-placeholder{display:none}._4193bdc190e9fde6__dropdown-menu{min-width:200px}.d094cd83a4e22156__reset-label{color:var(--wp-components-color-accent-darker-10,var(--wp-admin-theme-color-darker-10,#2145e6));font-size:var(--wpds-typography-font-size-xs,11px);font-weight:var(--wpds-typography-font-weight-emphasis,600);line-height:1.4;margin-inline-start:12px;text-transform:uppercase}._3de4c27602641134__default-controls-item{color:#1e1e1e}._3de4c27602641134__default-controls-item:focus .d094cd83a4e22156__reset-label{color:inherit}._3de4c27602641134__default-controls-item._3de4c27602641134__default-controls-item[aria-disabled=true]{color:#757575;opacity:1}._3de4c27602641134__default-controls-item._3de4c27602641134__default-controls-item[aria-disabled=true]:hover{color:#757575}._3de4c27602641134__default-controls-item._3de4c27602641134__default-controls-item[aria-disabled=true] .d094cd83a4e22156__reset-label{opacity:.3}\");\n}\nexport default {\"tools-panel\":\"_6c1192219f33c902__tools-panel\",\"tools-panel-with-inner-wrapper\":\"cd15a9c80fb6cbd4__tools-panel-with-inner-wrapper\",\"tools-panel-hidden-inner-wrapper\":\"e58228332b88343f__tools-panel-hidden-inner-wrapper\",\"tools-panel-header\":\"_00ef83981f008ed1__tools-panel-header\",\"tools-panel-heading\":\"_07c5a099c6314de5__tools-panel-heading\",\"tools-panel-item\":\"_900a3554bc5023e1__tools-panel-item\",\"tools-panel-item-placeholder\":\"_175ccc0d8111dddf__tools-panel-item-placeholder\",\"dropdown-menu\":\"_4193bdc190e9fde6__dropdown-menu\",\"reset-label\":\"d094cd83a4e22156__reset-label\",\"default-controls-item\":\"_3de4c27602641134__default-controls-item\"};\n","import clsx from 'clsx';\nimport {\n\tuseCallback,\n\tuseEffect,\n\tuseMemo,\n\tuseReducer,\n\tuseState,\n} from '@wordpress/element';\nimport styles from '../style.module.scss';\nimport type { WordPressComponentProps } from '../../context';\nimport { useContextSystem } from '../../context';\nimport type {\n\tRegisteredToolsPanelItem,\n\tToolsPanelMenuItemKey,\n\tToolsPanelMenuItems,\n\tToolsPanelProps,\n\tResetAllFilter,\n} from '../types';\n\ntype PanelItemsState = {\n\tpanelItems: RegisteredToolsPanelItem[];\n\tmenuItemOrder: string[];\n\t/**\n\t * Menu state that can't be read back off the items: an optional item the\n\t * user has shown, or a default item flagged as customized. Anything absent\n\t * here falls back to whether the item currently holds a value.\n\t */\n\tmenuItemValues: Record< string, boolean >;\n};\n\ntype PanelItemsAction =\n\t| { type: 'REGISTER_PANEL'; item: RegisteredToolsPanelItem }\n\t| {\n\t\t\ttype: 'UNREGISTER_PANEL';\n\t\t\tlabel: string;\n\t\t\titem?: RegisteredToolsPanelItem;\n\t }\n\t| { type: 'UPDATE_VALUE'; label: string; value: boolean }\n\t| { type: 'TOGGLE_VALUE'; label: string }\n\t| { type: 'RESET_ALL' };\n\nfunction emptyState(): PanelItemsState {\n\treturn { panelItems: [], menuItemOrder: [], menuItemValues: {} };\n}\n\n// An item is always shown while it has a value. `defaultShown` only opts an\n// optional item in when it has none.\nconst getSeedValue = ( item: RegisteredToolsPanelItem ) =>\n\titem.hasValue() || ( ! item.isShownByDefault && !! item.defaultShown );\n\nconst getMenuGroup = (\n\titem: RegisteredToolsPanelItem\n): ToolsPanelMenuItemKey => ( item.isShownByDefault ? 'default' : 'optional' );\n\nfunction panelItemsReducer(\n\tpanelItems: RegisteredToolsPanelItem[],\n\taction: PanelItemsAction\n) {\n\tswitch ( action.type ) {\n\t\tcase 'REGISTER_PANEL': {\n\t\t\t// An existing registration is replaced rather than appended, so\n\t\t\t// that an item moving between the default and optional groups\n\t\t\t// doesn't end up in the list twice.\n\t\t\tconst existingIndex = panelItems.findIndex(\n\t\t\t\t( item ) => item.label === action.item.label\n\t\t\t);\n\n\t\t\tconst newItems = [ ...panelItems ];\n\t\t\tif ( existingIndex !== -1 ) {\n\t\t\t\tnewItems.splice( existingIndex, 1 );\n\t\t\t}\n\t\t\tnewItems.push( action.item );\n\t\t\treturn newItems;\n\t\t}\n\t\tcase 'UNREGISTER_PANEL': {\n\t\t\tconst index = panelItems.findIndex(\n\t\t\t\t( item ) => item.label === action.label\n\t\t\t);\n\t\t\tif ( index === -1 ) {\n\t\t\t\treturn panelItems;\n\t\t\t}\n\t\t\t// A replacement may already hold this label, in which case this is\n\t\t\t// a late cleanup for a registration that is no longer current.\n\t\t\tif ( action.item && panelItems[ index ] !== action.item ) {\n\t\t\t\treturn panelItems;\n\t\t\t}\n\t\t\tconst newItems = [ ...panelItems ];\n\t\t\tnewItems.splice( index, 1 );\n\t\t\treturn newItems;\n\t\t}\n\t\tdefault:\n\t\t\treturn panelItems;\n\t}\n}\n\nfunction menuItemOrderReducer(\n\tmenuItemOrder: string[],\n\taction: PanelItemsAction\n) {\n\tswitch ( action.type ) {\n\t\tcase 'REGISTER_PANEL': {\n\t\t\t// Append-only: an item that unregisters and comes back keeps its\n\t\t\t// original place in the menu.\n\t\t\tif ( menuItemOrder.includes( action.item.label ) ) {\n\t\t\t\treturn menuItemOrder;\n\t\t\t}\n\t\t\treturn [ ...menuItemOrder, action.item.label ];\n\t\t}\n\t\tdefault:\n\t\t\treturn menuItemOrder;\n\t}\n}\n\nfunction menuItemValuesReducer(\n\tstate: PanelItemsState,\n\taction: PanelItemsAction\n) {\n\tconst values = state.menuItemValues;\n\n\tswitch ( action.type ) {\n\t\tcase 'REGISTER_PANEL': {\n\t\t\t// A new registration starts from its own value rather than\n\t\t\t// inheriting what an item it replaces recorded under the same\n\t\t\t// label. Clearing here rather than on deregistration covers both\n\t\t\t// orderings, since the two are not guaranteed to arrive in one.\n\t\t\t// Relies on re-registering also re-reporting the value.\n\t\t\tif ( ! values.hasOwnProperty( action.item.label ) ) {\n\t\t\t\treturn values;\n\t\t\t}\n\t\t\tconst { [ action.item.label ]: unusedValue, ...rest } = values;\n\t\t\treturn rest;\n\t\t}\n\t\tcase 'UPDATE_VALUE': {\n\t\t\tif ( values[ action.label ] === action.value ) {\n\t\t\t\treturn values;\n\t\t\t}\n\t\t\treturn { ...values, [ action.label ]: action.value };\n\t\t}\n\t\tcase 'TOGGLE_VALUE': {\n\t\t\tconst item = state.panelItems.find(\n\t\t\t\t( { label } ) => label === action.label\n\t\t\t);\n\t\t\tif ( ! item ) {\n\t\t\t\treturn values;\n\t\t\t}\n\t\t\tconst current = values[ action.label ] ?? getSeedValue( item );\n\t\t\treturn { ...values, [ action.label ]: ! current };\n\t\t}\n\t\tcase 'RESET_ALL': {\n\t\t\t// Optional items are set to false so they hide right away.\n\t\t\t// Default items are left alone: a reset can leave a value in\n\t\t\t// place, since `onDeselect` and `resetAllFilter` are optional and\n\t\t\t// `resetAll` need not cover every attribute. Each item reports its\n\t\t\t// value again if the reset changed it.\n\t\t\tconst hidden = state.panelItems.filter(\n\t\t\t\t( item ) =>\n\t\t\t\t\t! item.isShownByDefault && values[ item.label ] !== false\n\t\t\t);\n\n\t\t\tif ( ! hidden.length ) {\n\t\t\t\treturn values;\n\t\t\t}\n\n\t\t\tconst next = { ...values };\n\t\t\thidden.forEach( ( { label } ) => {\n\t\t\t\tnext[ label ] = false;\n\t\t\t} );\n\t\t\treturn next;\n\t\t}\n\t\tdefault:\n\t\t\treturn values;\n\t}\n}\n\nfunction panelReducer( state: PanelItemsState, action: PanelItemsAction ) {\n\tconst panelItems = panelItemsReducer( state.panelItems, action );\n\tconst menuItemOrder = menuItemOrderReducer( state.menuItemOrder, action );\n\tconst menuItemValues = menuItemValuesReducer(\n\t\t{ ...state, panelItems },\n\t\taction\n\t);\n\n\t// Items dispatch far more often than they change anything. Holding onto\n\t// the existing state lets React skip the render.\n\tif (\n\t\tpanelItems === state.panelItems &&\n\t\tmenuItemOrder === state.menuItemOrder &&\n\t\tmenuItemValues === state.menuItemValues\n\t) {\n\t\treturn state;\n\t}\n\n\treturn { panelItems, menuItemOrder, menuItemValues };\n}\n\nfunction resetAllFiltersReducer(\n\tfilters: ResetAllFilter[],\n\taction: { type: 'REGISTER' | 'UNREGISTER'; filter: ResetAllFilter }\n) {\n\tswitch ( action.type ) {\n\t\tcase 'REGISTER':\n\t\t\treturn [ ...filters, action.filter ];\n\t\tcase 'UNREGISTER':\n\t\t\treturn filters.filter( ( f ) => f !== action.filter );\n\t\tdefault:\n\t\t\treturn filters;\n\t}\n}\n\nconst isMenuItemTypeEmpty = (\n\tobj: ToolsPanelMenuItems[ ToolsPanelMenuItemKey ]\n) => Object.keys( obj ).length === 0;\n\nexport function useToolsPanel(\n\tprops: WordPressComponentProps< ToolsPanelProps, 'div' >\n) {\n\tconst {\n\t\tclassName,\n\t\theadingLevel = 2,\n\t\tresetAll,\n\t\tpanelId,\n\t\thasInnerWrapper = false,\n\t\tshouldRenderPlaceholderItems = false,\n\t\t__experimentalFirstVisibleItemClass,\n\t\t__experimentalLastVisibleItemClass,\n\t\t...otherProps\n\t} = useContextSystem( props, 'ToolsPanel' );\n\n\t// Marks the render that follows a reset so items can tell a reset apart\n\t// from the user switching them off. Clearing it from an effect rather than\n\t// as each control updates keeps the whole reset within one pass; otherwise\n\t// later controls see it already cleared and reset themselves again from\n\t// stale data.\n\tconst [ isResetting, setIsResetting ] = useState( false );\n\n\tuseEffect( () => {\n\t\tif ( isResetting ) {\n\t\t\tsetIsResetting( false );\n\t\t}\n\t}, [ isResetting ] );\n\n\tconst [ { panelItems, menuItemOrder, menuItemValues }, panelDispatch ] =\n\t\tuseReducer( panelReducer, undefined, emptyState );\n\n\t// Reset all filters registered against the context directly, by consumers\n\t// that aren't themselves a panel item. Items supply theirs when they\n\t// register.\n\tconst [ externalResetAllFilters, dispatchResetAllFilters ] = useReducer(\n\t\tresetAllFiltersReducer,\n\t\t[]\n\t);\n\n\tconst registerPanelItem = useCallback(\n\t\t( item: RegisteredToolsPanelItem ) => {\n\t\t\tpanelDispatch( { type: 'REGISTER_PANEL', item } );\n\t\t},\n\t\t[]\n\t);\n\n\tconst deregisterPanelItem = useCallback(\n\t\t( label: string, item?: RegisteredToolsPanelItem ) => {\n\t\t\tpanelDispatch( { type: 'UNREGISTER_PANEL', label, item } );\n\t\t},\n\t\t[]\n\t);\n\n\tconst registerResetAllFilter = useCallback( ( filter: ResetAllFilter ) => {\n\t\tdispatchResetAllFilters( { type: 'REGISTER', filter } );\n\t}, [] );\n\n\tconst deregisterResetAllFilter = useCallback(\n\t\t( filter: ResetAllFilter ) => {\n\t\t\tdispatchResetAllFilters( { type: 'UNREGISTER', filter } );\n\t\t},\n\t\t[]\n\t);\n\n\t// Argument order is unchanged from before this hook derived the menu; only\n\t// the group argument is gone, since it follows from `isShownByDefault`.\n\tconst flagItemCustomization = useCallback(\n\t\t( value: boolean, label: string ) => {\n\t\t\tpanelDispatch( { type: 'UPDATE_VALUE', label, value } );\n\t\t},\n\t\t[]\n\t);\n\n\t// Derived during render so the panel can never paint a half-built menu.\n\t// See: https://github.com/WordPress/gutenberg/pull/65564\n\tconst menuItems = useMemo( () => {\n\t\tconst result: ToolsPanelMenuItems = { default: {}, optional: {} };\n\t\tconst byLabel = new Map(\n\t\t\tpanelItems.map( ( item ) => [ item.label, item ] )\n\t\t);\n\n\t\t// `menuItemOrder` holds every registered label, so it alone drives\n\t\t// the menu.\n\t\tmenuItemOrder.forEach( ( label ) => {\n\t\t\tconst item = byLabel.get( label );\n\t\t\tif ( ! item ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresult[ getMenuGroup( item ) ][ label ] =\n\t\t\t\tmenuItemValues[ label ] ?? getSeedValue( item );\n\t\t} );\n\n\t\treturn result;\n\t}, [ panelItems, menuItemOrder, menuItemValues ] );\n\n\t// Drives the plus icon and the empty panel styling.\n\tconst areAllOptionalControlsHidden = useMemo( () => {\n\t\treturn (\n\t\t\tisMenuItemTypeEmpty( menuItems.default ) &&\n\t\t\t! isMenuItemTypeEmpty( menuItems.optional ) &&\n\t\t\tObject.values( menuItems.optional ).every(\n\t\t\t\t( isSelected ) => ! isSelected\n\t\t\t)\n\t\t);\n\t}, [ menuItems ] );\n\n\tconst classes = clsx(\n\t\tstyles[ 'tools-panel' ],\n\t\thasInnerWrapper && styles[ 'tools-panel-with-inner-wrapper' ],\n\t\tareAllOptionalControlsHidden &&\n\t\t\tstyles[ 'tools-panel-hidden-inner-wrapper' ],\n\t\tclassName\n\t);\n\n\t// `onShownChange` is invoked from here rather than in response to the\n\t// resulting state change, so that it only ever reports an explicit menu\n\t// action by the user.\n\tconst toggleItem = useCallback(\n\t\t( label: string ) => {\n\t\t\tconst currentItem = panelItems.find(\n\t\t\t\t( item ) => item.label === label\n\t\t\t);\n\n\t\t\tif ( ! currentItem ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tpanelDispatch( { type: 'TOGGLE_VALUE', label } );\n\n\t\t\t// Default items stay visible when toggled off, which resets them\n\t\t\t// instead of hiding them. Only optional items have a show or hide\n\t\t\t// transition to report.\n\t\t\tif ( currentItem.isShownByDefault ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tcurrentItem.onShownChange?.( ! menuItems.optional[ label ] );\n\t\t},\n\t\t[ menuItems, panelItems ]\n\t);\n\n\tconst resetAllFilters = useMemo( () => {\n\t\tconst itemFilters = panelItems\n\t\t\t.map( ( item ) => item.resetAllFilter )\n\t\t\t.filter( ( filter ): filter is ResetAllFilter => !! filter );\n\n\t\treturn [ ...itemFilters, ...externalResetAllFilters ];\n\t}, [ panelItems, externalResetAllFilters ] );\n\n\tconst resetAllItems = useCallback( () => {\n\t\tif ( typeof resetAll === 'function' ) {\n\t\t\tsetIsResetting( true );\n\t\t\tresetAll( resetAllFilters );\n\t\t}\n\n\t\tpanelDispatch( { type: 'RESET_ALL' } );\n\t}, [ resetAllFilters, resetAll ] );\n\n\t// Lets `ItemGroup` style the visible ends of the panel when hidden\n\t// placeholder items sit among the children.\n\tconst getFirstVisibleItemLabel = ( items: RegisteredToolsPanelItem[] ) => {\n\t\tconst optionalItems = menuItems.optional || {};\n\t\tconst firstItem = items.find(\n\t\t\t( item ) => item.isShownByDefault || optionalItems[ item.label ]\n\t\t);\n\n\t\treturn firstItem?.label;\n\t};\n\n\tconst firstDisplayedItem = getFirstVisibleItemLabel( panelItems );\n\tconst lastDisplayedItem = getFirstVisibleItemLabel(\n\t\t[ ...panelItems ].reverse()\n\t);\n\n\tconst hasMenuItems = panelItems.length > 0;\n\n\tconst panelContext = useMemo(\n\t\t() => ( {\n\t\t\tareAllOptionalControlsHidden,\n\t\t\tderegisterPanelItem,\n\t\t\tderegisterResetAllFilter,\n\t\t\tfirstDisplayedItem,\n\t\t\tflagItemCustomization,\n\t\t\thasMenuItems,\n\t\t\tisResetting,\n\t\t\tlastDisplayedItem,\n\t\t\tmenuItems,\n\t\t\tpanelId,\n\t\t\tregisterPanelItem,\n\t\t\tregisterResetAllFilter,\n\t\t\tshouldRenderPlaceholderItems,\n\t\t\t__experimentalFirstVisibleItemClass,\n\t\t\t__experimentalLastVisibleItemClass,\n\t\t} ),\n\t\t[\n\t\t\tareAllOptionalControlsHidden,\n\t\t\tderegisterPanelItem,\n\t\t\tderegisterResetAllFilter,\n\t\t\tfirstDisplayedItem,\n\t\t\tflagItemCustomization,\n\t\t\tisResetting,\n\t\t\tlastDisplayedItem,\n\t\t\tmenuItems,\n\t\t\tpanelId,\n\t\t\thasMenuItems,\n\t\t\tregisterResetAllFilter,\n\t\t\tregisterPanelItem,\n\t\t\tshouldRenderPlaceholderItems,\n\t\t\t__experimentalFirstVisibleItemClass,\n\t\t\t__experimentalLastVisibleItemClass,\n\t\t]\n\t);\n\n\treturn {\n\t\t...otherProps,\n\t\theadingLevel,\n\t\tpanelContext,\n\t\tresetAllItems,\n\t\ttoggleItem,\n\t\tclassName: classes,\n\t};\n}\n"],"mappings":";;;;AAUA,MAAM,uBAAuB;;;;;;;;;AAU7B,SAAS,aAAa;CACrB,MAAM,cAAc;CAEpB,IAAK,YAAY,kBAChB,OAAO,YAAY;CAGpB,YAAY,mBAAmB;EAC9B,2BAAW,IAAI,IAAI;EACnB,wBAAQ,IAAI,IAAI;EAChB,gCAAgB,IAAI,QA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