{"version":3,"file":"fill.cjs","names":["useContext","SlotFillContext","useRef","useObservableValue","createPortal","StyleProvider"],"sources":["../../src/slot-fill/fill.tsx"],"sourcesContent":["import { useObservableValue } from '@wordpress/compose';\nimport {\n\tuseContext,\n\tuseLayoutEffect,\n\tuseRef,\n\tcreatePortal,\n} from '@wordpress/element';\nimport SlotFillContext from './context';\nimport type { FillComponentProps } from './types';\nimport StyleProvider from '../style-provider';\n\nexport default function Fill( { name, children }: FillComponentProps ) {\n\tconst registry = useContext( SlotFillContext );\n\tconst instanceRef = useRef( {} );\n\tconst childrenRef = useRef( children );\n\n\tuseLayoutEffect( () => {\n\t\tchildrenRef.current = children;\n\t}, [ children ] );\n\n\tuseLayoutEffect( () => {\n\t\tconst instance = instanceRef.current;\n\t\tregistry.registerFill( name, {\n\t\t\tinstance,\n\t\t\tchildren: childrenRef.current,\n\t\t} );\n\t\treturn () => registry.unregisterFill( name, instance );\n\t}, [ registry, name ] );\n\n\tuseLayoutEffect( () => {\n\t\tregistry.updateFill( name, {\n\t\t\tinstance: instanceRef.current,\n\t\t\tchildren,\n\t\t} );\n\t}, [ registry, name, children ] );\n\n\tconst slot = useObservableValue( registry.slots, name );\n\n\tif ( ! slot ) {\n\t\treturn null;\n\t}\n\n\tif ( slot.type === 'children' ) {\n\t\treturn null;\n\t}\n\n\tconst portalEl = slot.ref.current;\n\tif ( ! portalEl ) {\n\t\treturn null;\n\t}\n\n\tconst wrappedChildren =\n\t\ttypeof children === 'function'\n\t\t\t? children( slot.fillProps ?? {} )\n\t\t\t: children;\n\n\t// When using a `Fill`, the `children` will be rendered in the document of the\n\t// `Slot`. Wrap the children in a `StyleProvider` so CSS Module styles target\n\t// that document/iframe instead of the document containing the `Fill`.\n\treturn createPortal(\n\t\t<StyleProvider document={ portalEl.ownerDocument }>\n\t\t\t{ wrappedChildren }\n\t\t</StyleProvider>,\n\t\tportalEl\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,SAAwB,KAAM,EAAE,MAAM,YAAiC;CACtE,MAAM,YAAA,GAAWA,mBAAAA,WAAAA,CAAYC,aAAAA,OAAgB;CAC7C,MAAM,eAAA,GAAcC,mBAAAA,OAAAA,CAAQ,CAAC,CAAE;CAC/B,MAAM,eAAA,GAAcA,mBAAAA,OAAAA,CAAQ,QAAS;CAErC,CAAA,GAAA,mBAAA,gBAAA,OAAuB;EACtB,YAAY,UAAU;CACvB,GAAG,CAAE,QAAS,CAAE;CAEhB,CAAA,GAAA,mBAAA,gBAAA,OAAuB;EACtB,MAAM,WAAW,YAAY;EAC7B,SAAS,aAAc,MAAM;GAC5B;GACA,UAAU,YAAY;EACvB,CAAE;EACF,aAAa,SAAS,eAAgB,MAAM,QAAS;CACtD,GAAG,CAAE,UAAU,IAAK,CAAE;CAEtB,CAAA,GAAA,mBAAA,gBAAA,OAAuB;EACtB,SAAS,WAAY,MAAM;GAC1B,UAAU,YAAY;GACtB;EACD,CAAE;CACH,GAAG;EAAE;EAAU;EAAM;CAAS,CAAE;CAEhC,MAAM,QAAA,GAAOC,mBAAAA,mBAAAA,CAAoB,SAAS,OAAO,IAAK;CAEtD,IAAK,CAAE,MACN,OAAO;CAGR,IAAK,KAAK,SAAS,YAClB,OAAO;CAGR,MAAM,WAAW,KAAK,IAAI;CAC1B,IAAK,CAAE,UACN,OAAO;CAGR,MAAM,kBACL,OAAO,aAAa,aACjB,SAAU,KAAK,aAAa,CAAC,CAAE,IAC/B;CAKJ,QAAA,GAAOC,mBAAAA,aAAAA,CACN,iBAAA,GAAA,kBAAA,IAAA,CAACC,4BAAAA,SAAD;EAAe,UAAW,SAAS;EAChC,UAAA;CACY,CAAA,GACf,QACD;AACD"}