import type { JSX } from "@solidjs/web"; /** * `` provider + `useCompositeListItem` hook. * * Owns a per-item `Element → metadata` map, observes DOM mutations to * discover re-ordering, and exposes: * 1. a plain-array `elementsRef` (ordered by DOM position) * 2. a `subscribeMapChange` helper so items can learn their index * 3. a `mapTick` signal that bumps whenever `register`/`unregister` fire, * driving the sorted-map memo in a Solid-idiomatic way * * Mirrors `packages/react/src/internals/composite/list/CompositeList.tsx` in * Base UI React. The Solid translation: * * - React's `useState(0)` counter becomes a `createSignal(0)` + a hidden * `latestTick` integer (we write to it from `register`/`unregister` which * are called from unowned event/effect scope; the signal uses * `ownedWrite: true` so we don't trip `SIGNAL_WRITE_IN_OWNED_SCOPE` when an * `onCleanup` removes an item). * - React's `useMemo` becomes `createMemo`. The memo re-reads on `tick` * changes and walks the map in document order. * - React's `useIsoLayoutEffect` calls become split `createRenderEffect`s * (for DOM-level sync) and `createEffect`s (for listener dispatch). * - The sibling-unit `MutationObserver` is hooked up in a render-effect * keyed on the sorted map; when elements are re-ordered in the DOM, the * observer bumps `tick` so consumers re-sort on the next microtask. * * `useCompositeListItem` takes a per-call `source` symbol (created once per * invocation) which is how we identify items across re-registrations — Solid * has no component-instance identity for refs to hang off of, so we use an * explicit token. The returned ref callback registers the element on first * call and unregisters via `onCleanup` when the owning scope disposes. */ import { type Accessor } from "solid-js"; import { type CompositeMapListener } from "./composite-context.js"; export interface CompositeListProps { children: JSX.Element; /** * Plain array that the list keeps in DOM order. Consumers (notably the * composite root) read it inside event handlers, so it is NOT wrapped in * a signal — direct mutation is expected. Passing a pre-allocated array * is supported and matches Base UI React's `elementsRef` ergonomics. */ elementsRef: Array; /** Parallel labels array for typeahead; optional. */ labelsRef?: Array | undefined; /** * Fired whenever the sorted map changes. Runs in an effect, so consumers * can read reactive values inside the callback body without warnings. */ onMapChange?: CompositeMapListener | undefined; } export declare function CompositeList(props: CompositeListProps): JSX.Element; export interface UseCompositeListItemParameters { /** Consumer-supplied metadata carried alongside the index. */ metadata?: Metadata | undefined; /** Label for typeahead (when the root opts into labels). */ label?: string | null | undefined; /** Fallback label source — used when `label` is omitted. */ textRef?: { current: HTMLElement | null; } | undefined; /** * Override the index the item reports (skips registration). Matches the * Base UI React "externalIndex" escape hatch for components that know * their index up front. */ index?: number | undefined; } export interface UseCompositeListItemReturn { /** Stable ref callback. Composes with other refs via Solid's array form. */ ref: (node: HTMLElement | null) => void; /** Accessor returning the item's current index (or `-1` before register). */ index: Accessor; } /** * Register the rendered element with the nearest ``. Returns * a ref callback + an accessor for the item's current index. * * The `source` symbol is created once per call so re-registrations (e.g. the * owner scope re-running) stay identified across element swaps. Cleanup on * scope disposal unregisters automatically. */ export declare function useCompositeListItem(params?: UseCompositeListItemParameters): UseCompositeListItemReturn; //# sourceMappingURL=composite-list.d.ts.map