{"version":3,"names":["createContext","useContext","eraseCompositeListContext","value","NOOP_REGISTER","_source","_node","_metadata","NOOP_UNREGISTER","NOOP_SUBSCRIBE","_fn","NOOP_COMPOSITE_LIST_CONTEXT","register","unregister","subscribeMapChange","elementsRef","CompositeListContext","useCompositeListContext","NOOP_COMPOSITE_ROOT_CONTEXT","highlightedIndex","onHighlightedIndexChange","highlightItemOnHover","relayKeyboardEvent","present","CompositeRootContext","useCompositeRootContext","optional","context","undefined","Error"],"sources":["composite-context.ts"],"sourcesContent":["/**\n * Contexts used by the composite primitives.\n *\n * There are two distinct contexts:\n *\n * - `CompositeListContext` — exposes registration helpers + the shared\n *   `elementsRef` / `labelsRef` plain arrays. `useCompositeListItem` reads\n *   from this context; `CompositeList` provides it.\n * - `CompositeRootContext` — exposes `highlightedIndex()` + its setter so\n *   child items can read/update the focused-item state. This mirrors Base\n *   UI React's `CompositeRootContext`.\n *\n * Solid 2 context providers are \"context-as-provider\" (RFC 02), so a\n * `<CompositeListContext value={...}>{...}</CompositeListContext>` is used at\n * the call sites — there is no `.Provider`.\n */\n\nimport { type Accessor, createContext, useContext } from \"solid-js\";\n\n/**\n * Per-item metadata carried alongside the `Element → metadata` map. `index`\n * is managed by `CompositeList` — consumers supply their own custom fields.\n */\nexport type CompositeMetadata<CustomMetadata> = {\n\tindex?: number | null | undefined;\n} & CustomMetadata;\n\n/**\n * A disposer returned by subscription helpers.\n */\nexport type Disposer = () => void;\n\n/**\n * The notification payload shared through `CompositeListContext.subscribe`.\n * Consumers receive the sorted map on every change.\n */\nexport type CompositeMapListener<Metadata> = (\n\tmap: Map<Element, CompositeMetadata<Metadata> | null>,\n) => void;\n\nexport interface CompositeListContextValue<Metadata> {\n\t/** Register a node + its metadata with the list. `source` is a unique,\n\t * per-item token that lets the list detect stale entries when a consumer\n\t * re-registers with a different node. Token shape is deliberately\n\t * `symbol` so consumers can create one per `useCompositeListItem` call. */\n\tregister: (source: symbol, node: Element, metadata: Metadata) => void;\n\t/** Unregister by `source` token (node may already be detached). */\n\tunregister: (source: symbol) => void;\n\t/** Subscribe to sorted-map changes. */\n\tsubscribeMapChange: (fn: CompositeMapListener<Metadata>) => Disposer;\n\t/**\n\t * Plain array of elements ordered by DOM position. This is a plain\n\t * JavaScript array — NOT a reactive signal — because the root's keyboard\n\t * handler reads it at call time and libraries like floating-ui expect a\n\t * mutable `.current`-shaped list. Subscribe to `subscribeMapChange` for\n\t * ordering updates.\n\t */\n\telementsRef: Array<HTMLElement | null>;\n\t/** Parallel labels array, when the caller opted in by passing `labelsRef`\n\t * on `<CompositeList>`. */\n\tlabelsRef?: Array<string | null> | undefined;\n}\n\n/**\n * Phantom brand carried by the erased context value. The brand exists only\n * in the type system — at runtime the field is absent — so there's no cost\n * beyond TypeScript's assignability check. It prevents arbitrary\n * `CompositeListContextValue<X>` objects from being mistaken for the erased\n * shape: only values produced by `eraseCompositeListContext` (or the frozen\n * no-op default) carry the brand.\n */\ndeclare const erasedMetadataBrand: unique symbol;\n\n/**\n * Erased storage shape for `CompositeListContext`. `Metadata` is fixed to\n * `unknown` so the shape is concrete and the context can hold a single\n * monomorphic type. Providers erase via `eraseCompositeListContext`;\n * consumers reify via `useCompositeListContext<Metadata>()`. Both ends\n * preserve the brand so the erasure can't be bypassed with a plain cast.\n */\nexport type ErasedCompositeListContextValue =\n\tCompositeListContextValue<unknown> & {\n\t\treadonly [erasedMetadataBrand]: true;\n\t};\n\n/**\n * Erase the `Metadata` type parameter so a concrete\n * `CompositeListContextValue<Metadata>` can be stored on the shared context.\n * The cast is confined here — the context's `register`/`subscribeMapChange`\n * handlers never actually observe values typed against the wrong `Metadata`\n * because the corresponding `useCompositeListContext<Metadata>()` reader on\n * the other side re-projects them to the same concrete type before the\n * caller sees them.\n */\nexport function eraseCompositeListContext<Metadata>(\n\tvalue: CompositeListContextValue<Metadata>,\n): ErasedCompositeListContextValue {\n\treturn value as ErasedCompositeListContextValue;\n}\n\nconst NOOP_REGISTER = (\n\t_source: symbol,\n\t_node: Element,\n\t_metadata: unknown,\n): void => {};\nconst NOOP_UNREGISTER = (_source: symbol): void => {};\nconst NOOP_SUBSCRIBE = (_fn: CompositeMapListener<unknown>): Disposer => {\n\treturn () => {};\n};\n\n/**\n * Default value used when `useCompositeListItem` is rendered outside of a\n * `<CompositeList>`. Keeping the shape complete (rather than `undefined`)\n * lets tier-2 consumers (like `RadioGroup`'s items) call the hook\n * unconditionally and simply behave as \"unregistered\" when the wrapper is\n * absent.\n */\nconst NOOP_COMPOSITE_LIST_CONTEXT: ErasedCompositeListContextValue =\n\teraseCompositeListContext({\n\t\tregister: NOOP_REGISTER,\n\t\tunregister: NOOP_UNREGISTER,\n\t\tsubscribeMapChange: NOOP_SUBSCRIBE,\n\t\telementsRef: [],\n\t});\n\n/**\n * The context stores the erased shape. `<CompositeList>` passes its concrete\n * `CompositeListContextValue<Metadata>` through `eraseCompositeListContext`;\n * consumers pull the branded value back out through\n * `useCompositeListContext<Metadata>()` which reifies `Metadata` at the call\n * site.\n */\nexport const CompositeListContext =\n\tcreateContext<ErasedCompositeListContextValue>(NOOP_COMPOSITE_LIST_CONTEXT);\n\n/**\n * Read the nearest `CompositeListContext`. Returns the no-op default when\n * there is no provider, so callers don't have to handle `undefined`. The\n * single cast here is the only place `Metadata` is re-reified from the\n * erased storage shape.\n */\nexport function useCompositeListContext<\n\tMetadata,\n>(): CompositeListContextValue<Metadata> {\n\treturn useContext(\n\t\tCompositeListContext,\n\t) as CompositeListContextValue<Metadata>;\n}\n\nexport interface CompositeRootContextValue {\n\t/** Current highlighted index. */\n\thighlightedIndex: Accessor<number>;\n\t/** Setter matching React Base UI's signature exactly. */\n\tonHighlightedIndexChange: (\n\t\tindex: number,\n\t\tshouldScrollIntoView?: boolean,\n\t) => void;\n\t/** If `true`, hovering an item moves focus to it. */\n\thighlightItemOnHover: Accessor<boolean>;\n\t/**\n\t * Forwards an external keyboard event into the composite's `onKeyDown`\n\t * handler. Useful when the triggering element is rendered outside the\n\t * composite tree (e.g. menubar with detached triggers).\n\t */\n\trelayKeyboardEvent: (event: KeyboardEvent) => void;\n\t/** `true` only when provided by a real `<Composite.Root>`. */\n\treadonly present: boolean;\n}\n\n/**\n * No-op sentinel for when no `<Composite.Root>` ancestor exists. Solid 2's\n * `useContext` throws `ContextNotFoundError` when the default is literal\n * `undefined` — even inside an owner — so we always supply a sentinel and\n * let consumers branch on `.present`.\n */\nconst NOOP_COMPOSITE_ROOT_CONTEXT: CompositeRootContextValue = {\n\thighlightedIndex: () => -1,\n\tonHighlightedIndexChange: () => {},\n\thighlightItemOnHover: () => false,\n\trelayKeyboardEvent: () => {},\n\tpresent: false,\n};\n\nexport const CompositeRootContext = createContext<CompositeRootContextValue>(\n\tNOOP_COMPOSITE_ROOT_CONTEXT,\n);\n\n/**\n * Read the composite root context. Returns `undefined` in the `optional: true`\n * form when no real `<Composite.Root>` is an ancestor; otherwise throws.\n */\nexport function useCompositeRootContext(\n\toptional: true,\n): CompositeRootContextValue | undefined;\nexport function useCompositeRootContext(\n\toptional?: false,\n): CompositeRootContextValue;\nexport function useCompositeRootContext(\n\toptional = false,\n): CompositeRootContextValue | undefined {\n\tconst context = useContext(CompositeRootContext);\n\tif (!context.present) {\n\t\tif (optional) return undefined;\n\t\tthrow new Error(\n\t\t\t\"Base UI: CompositeRootContext is missing. Composite parts must be placed within <Composite.Root>.\",\n\t\t);\n\t}\n\treturn context;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAwBA,aAAa,EAAEC,UAAU,QAAQ,UAAU;;AAEnE;AACA;AACA;AACA;;AAKA;AACA;AACA;;AAGA;AACA;AACA;AACA;;AA4BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,yBAAyBA,CACxCC,KAA0C,EACR;EA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