{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/action-item/index.tsx"],"sourcesContent":["import { MenuGroup, MenuItem, Slot, Fill } from '@wordpress/components';\nimport { Children } from '@wordpress/element';\nimport type { ActionItemProps, ActionItemSlotProps } from './types';\n\nfunction ActionItemSlot( {\n\tname,\n\tas: Component = MenuGroup,\n\tfillProps = {},\n\tchildren,\n\t...props\n}: ActionItemSlotProps ) {\n\treturn (\n\t\t<Slot name={ name } fillProps={ fillProps }>\n\t\t\t{ ( fills ) => {\n\t\t\t\t// Each fill renders an array of its own, so flatten them into a\n\t\t\t\t// single list before handing them over.\n\t\t\t\tconst items = Children.toArray( fills );\n\n\t\t\t\tif ( ! items.length ) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tif ( typeof children === 'function' ) {\n\t\t\t\t\treturn children( items );\n\t\t\t\t}\n\n\t\t\t\treturn <Component { ...props }>{ items }</Component>;\n\t\t\t} }\n\t\t</Slot>\n\t);\n}\n\nfunction ActionItem( { name, as, onClick, ...props }: ActionItemProps ) {\n\treturn (\n\t\t<Fill name={ name }>\n\t\t\t{ ( { as: slotAs = MenuItem, onClick: slotOnClick } ) => {\n\t\t\t\t// The slot provides the component to render the item with, so\n\t\t\t\t// that it fits the menu it ends up in, and an onClick handler,\n\t\t\t\t// for example one that closes that menu. The `as` prop\n\t\t\t\t// replaces the component. The `onClick` prop does not replace\n\t\t\t\t// the handler: both run.\n\t\t\t\tconst Component = as ?? slotAs;\n\t\t\t\tconst handlers = [ onClick, slotOnClick ].filter( Boolean );\n\n\t\t\t\treturn (\n\t\t\t\t\t<Component\n\t\t\t\t\t\tonClick={\n\t\t\t\t\t\t\thandlers.length\n\t\t\t\t\t\t\t\t? ( ...args: unknown[] ) =>\n\t\t\t\t\t\t\t\t\t\thandlers.forEach( ( handler ) =>\n\t\t\t\t\t\t\t\t\t\t\thandler( ...args )\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} }\n\t\t</Fill>\n\t);\n}\n\nActionItem.Slot = ActionItemSlot;\n\nexport default ActionItem;\n"],"mappings":";;;;AAIA,SAAS,eAAgB,EACxB,MACA,IAAI,YAAY,WAChB,YAAY,CAAC,GACb,UACA,GAAG,SACqB;CACxB,OACC,oBAAC,MAAD;EAAa;EAAmB;EAC3B,WAAA,UAAW;GAGd,MAAM,QAAQ,SAAS,QAAS,KAAM;GAEtC,IAAK,CAAE,MAAM,QACZ,OAAO;GAGR,IAAK,OAAO,aAAa,YACxB,OAAO,SAAU,KAAM;GAGxB,OAAO,oBAAC,WAAD;IAAW,GAAK;IAAU,UAAA;GAAkB,CAAA;EACpD;CACK,CAAA;AAER;AAEA,SAAS,WAAY,EAAE,MAAM,IAAI,SAAS,GAAG,SAA2B;CACvE,OACC,oBAAC,MAAD;EAAa;EACR,WAAA,EAAE,IAAI,SAAS,UAAU,SAAS,kBAAmB;GAMxD,MAAM,YAAY,MAAM;GACxB,MAAM,WAAW,CAAE,SAAS,WAAY,CAAC,CAAC,OAAQ,OAAQ;GAE1D,OACC,oBAAC,WAAD;IACC,SACC,SAAS,UACJ,GAAG,SACL,SAAS,SAAW,YACnB,QAAS,GAAG,IAAK,CAClB,IACA,KAAA;IAEJ,GAAK;GACL,CAAA;EAEH;CACK,CAAA;AAER;AAEA,WAAW,OAAO"}