@wordpress/components
Version:
UI components for WordPress.
8 lines (7 loc) • 1.66 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/slot-fill/bubbles-virtually/use-slot-fills.ts"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useContext, useMemo, useSyncExternalStore } from '@wordpress/element';\n/**\n * Internal dependencies\n */\nimport SlotFillContext from '../context';\nfunction useObservableValueWithSelector(map, name, selector) {\n const subscribe = useMemo(() => listener => map.subscribe(name, listener), [map, name]);\n const getValue = () => selector(map.get(name));\n return useSyncExternalStore(subscribe, getValue, getValue);\n}\nfunction getLength(array) {\n return array?.length;\n}\nexport default function useSlotFills(name) {\n const registry = useContext(SlotFillContext);\n const length = useObservableValueWithSelector(registry.fills, name, getLength);\n // callers expect an opaque array with length `length`, so create that array\n const fills = useMemo(() => {\n return length !== undefined ? Array.from({\n length\n }) : undefined;\n }, [length]);\n return fills;\n}"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA0D;AAI1D,qBAA4B;AAC5B,SAAS,+BAA+B,KAAK,MAAM,UAAU;AAC3D,QAAM,gBAAY,wBAAQ,MAAM,cAAY,IAAI,UAAU,MAAM,QAAQ,GAAG,CAAC,KAAK,IAAI,CAAC;AACtF,QAAM,WAAW,MAAM,SAAS,IAAI,IAAI,IAAI,CAAC;AAC7C,aAAO,qCAAqB,WAAW,UAAU,QAAQ;AAC3D;AACA,SAAS,UAAU,OAAO;AACxB,SAAO,OAAO;AAChB;AACe,SAAR,aAA8B,MAAM;AACzC,QAAM,eAAW,2BAAW,eAAAA,OAAe;AAC3C,QAAM,SAAS,+BAA+B,SAAS,OAAO,MAAM,SAAS;AAE7E,QAAM,YAAQ,wBAAQ,MAAM;AAC1B,WAAO,WAAW,SAAY,MAAM,KAAK;AAAA,MACvC;AAAA,IACF,CAAC,IAAI;AAAA,EACP,GAAG,CAAC,MAAM,CAAC;AACX,SAAO;AACT;",
"names": ["SlotFillContext"]
}