{"version":3,"file":"roving-tab-index-item.cjs","names":["forwardRef","useRef","useRovingTabIndexContext"],"sources":["../../src/tree-grid/roving-tab-index-item.tsx"],"sourcesContent":["import { useRef, forwardRef } from '@wordpress/element';\nimport { useRovingTabIndexContext } from './roving-tab-index-context';\nimport type { RovingTabIndexItemProps } from './types';\n\nexport const RovingTabIndexItem = forwardRef(\n\tfunction UnforwardedRovingTabIndexItem(\n\t\t{ children, as: Component, ...props }: RovingTabIndexItemProps,\n\t\tforwardedRef: React.ForwardedRef< any >\n\t) {\n\t\tconst localRef = useRef< any >( null );\n\t\tconst ref = forwardedRef || localRef;\n\t\tconst context = useRovingTabIndexContext();\n\t\tif ( ! context ) {\n\t\t\tthrow new Error(\n\t\t\t\t'TreeGridItem can only be rendered inside a TreeGrid component.'\n\t\t\t);\n\t\t}\n\t\tconst { lastFocusedElement, setLastFocusedElement } = context;\n\t\tlet tabIndex;\n\n\t\tif ( lastFocusedElement ) {\n\t\t\ttabIndex =\n\t\t\t\tlastFocusedElement ===\n\t\t\t\t// TODO: The original implementation simply used `ref.current` here, assuming\n\t\t\t\t// that a forwarded ref would always be an object, which is not necessarily true.\n\t\t\t\t// This workaround maintains the original runtime behavior in a type-safe way,\n\t\t\t\t// but should be revisited.\n\t\t\t\t( 'current' in ref ? ref.current : undefined )\n\t\t\t\t\t? 0\n\t\t\t\t\t: -1;\n\t\t}\n\n\t\tconst onFocus: React.FocusEventHandler< HTMLElement > = ( event ) =>\n\t\t\tsetLastFocusedElement?.( event.target );\n\t\tconst allProps = { ref, tabIndex, onFocus, ...props };\n\n\t\tif ( typeof children === 'function' ) {\n\t\t\treturn children( allProps );\n\t\t}\n\n\t\tif ( ! Component ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn <Component { ...allProps }>{ children }</Component>;\n\t}\n);\nRovingTabIndexItem.displayName = 'RovingTabIndexItem';\n\nexport default RovingTabIndexItem;\n"],"mappings":";;;;;;;;;AAIA,MAAa,sBAAA,GAAqBA,mBAAAA,WAAAA,CACjC,SAAS,8BACR,EAAE,UAAU,IAAI,WAAW,GAAG,SAC9B,cACC;CACD,MAAM,YAAA,GAAWC,mBAAAA,OAAAA,CAAe,IAAK;CACrC,MAAM,MAAM,gBAAgB;CAC5B,MAAM,WAAA,GAAUC,8BAAAA,yBAAAA,CAAyB;CACzC,IAAK,CAAE,SACN,MAAM,IAAI,MACT,gEACD;CAED,MAAM,EAAE,oBAAoB,0BAA0B;CACtD,IAAI;CAEJ,IAAK,oBACJ,WACC,wBAKE,aAAa,MAAM,IAAI,UAAU,KAAA,KAChC,IACA;CAGL,MAAM,WAAoD,UACzD,wBAAyB,MAAM,MAAO;CACvC,MAAM,WAAW;EAAE;EAAK;EAAU;EAAS,GAAG;CAAM;CAEpD,IAAK,OAAO,aAAa,YACxB,OAAO,SAAU,QAAS;CAG3B,IAAK,CAAE,WACN,OAAO;CAGR,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,WAAD;EAAW,GAAK;EAAa;CAAqB,CAAA;AAC1D,CACD;AACA,mBAAmB,cAAc"}