/** * Stage 3 port of Base UI React's `FloatingTreeStore` * (`packages/react/src/floating-ui-react/components/FloatingTreeStore.ts`). * * Stores and manages floating elements in a tree structure. Used as the * backing store for the `FloatingTree` component, and consumed by the * `useDismiss` / nested `useHover` paths (Stage 4) to traverse parent / * child relationships. * * Port notes: * - The React source uses a plain mutable `nodesRef: RefObject>` * for the node list. The Solid port keeps the exact same shape — * `MutableRef` — so call sites (`tree.nodesRef.current`) * look identical. This is a ref-like, not a signal: consumers that need * reactivity subscribe to the `events` emitter for `"addnode"` / * `"removenode"` instead. Matches React (the original has no signal-style * subscription either; `FloatingTree` itself is just a context carrier). * - Events are emitted via the same shared `createEventEmitter` utility. */ import type { FloatingEvents, FloatingNodeType, MutableRef } from "../types"; import { createEventEmitter } from "../utils/create-event-emitter"; export class FloatingTreeStore { public readonly nodesRef: MutableRef> = { current: [], }; public readonly events: FloatingEvents = createEventEmitter(); public addNode(node: FloatingNodeType): void { this.nodesRef.current.push(node); } public removeNode(node: FloatingNodeType): void { const index = this.nodesRef.current.indexOf(node); if (index !== -1) { this.nodesRef.current.splice(index, 1); } } }