{"version":3,"names":["createChangeEventDetails","REASONS","PopupTriggerMap","MenuStore","_setOpen","_open","constructor","context","triggerElements","attachSetOpen","fn","setOpenMirror","next","setOpen","details","isOpen","MenuHandle","store","open","triggerId","triggerElement","getById","Error","imperativeAction","undefined","close","createMenuHandle"],"sources":["menu-store.ts"],"sourcesContent":["/**\n * `MenuStore` + `MenuHandle` — thin Solid 2 port of Base UI React's\n * `MenuStore` / `MenuHandle` (`packages/react/src/menu/store/MenuStore.ts` +\n * `MenuHandle.ts`), mirroring the popover pattern already shipped\n * (`src/popover/store/popover-store.ts`).\n *\n * The React source threads a full store + selector pair through every\n * sub-part. The Solid `<Menu.Root>` uses its local signal-accessor context\n * (same shape as `<Select.Root>`); this store only carries the minimal\n * surface the imperative handle + multi-trigger registry need:\n *\n *  - A `PopupTriggerMap` so `<Menu.Trigger id=\"...\">` can register and\n *    `MenuHandle.open(id)` can resolve the correct trigger.\n *  - A `setOpen` slot that `<Menu.Root>` binds during setup via\n *    {@link attachSetOpen}.\n *  - An `open` mirror so `handle.isOpen` returns synchronously.\n */\n\nimport {\n\tcreateChangeEventDetails,\n\tREASONS,\n} from \"../../internals/change-event-details\";\nimport { PopupTriggerMap } from \"../../internals/floating-ui/popup-trigger-map\";\nimport type {\n\tMenuRootChangeEventDetails,\n\tMenuRootChangeEventReason,\n} from \"../root/menu-root-context\";\n\n/**\n * Writer signature for `setOpen`. Matches the Solid root's internal\n * `setOpen(next, details)` callback.\n */\nexport type MenuStoreSetOpen = (\n\tnext: boolean,\n\tdetails: MenuRootChangeEventDetails,\n) => void;\n\n/**\n * Minimal store shape consumed by the handle + imperative callers.\n */\nexport class MenuStore<_Payload = unknown> {\n\t/**\n\t * Registry of triggers keyed by id. `<Menu.Trigger id={...}>` adds\n\t * itself here on mount, and `MenuHandle.open(id)` looks it up.\n\t */\n\tpublic readonly context: { triggerElements: PopupTriggerMap };\n\n\t/**\n\t * Internal setOpen slot. `<Menu.Root>` binds this during setup via\n\t * {@link attachSetOpen}; clears on teardown.\n\t */\n\tprivate _setOpen: MenuStoreSetOpen | null = null;\n\n\t/**\n\t * Last-seen reactive open flag. Used by `MenuHandle.isOpen` so the\n\t * caller can read synchronously without needing a subscription hook.\n\t */\n\tprivate _open = false;\n\n\tconstructor() {\n\t\tthis.context = {\n\t\t\ttriggerElements: new PopupTriggerMap(),\n\t\t};\n\t}\n\n\t/**\n\t * Bind the root's `setOpen` writer.\n\t *\n\t * @internal\n\t */\n\tattachSetOpen(fn: MenuStoreSetOpen | null): void {\n\t\tthis._setOpen = fn;\n\t}\n\n\t/**\n\t * Mirror the root's current open flag. Called by `<Menu.Root>`'s effect\n\t * so `handle.isOpen` returns the latest value synchronously.\n\t *\n\t * @internal\n\t */\n\tsetOpenMirror(next: boolean): void {\n\t\tthis._open = next;\n\t}\n\n\t/**\n\t * Imperative open-state writer. No-op when no root is bound.\n\t */\n\tsetOpen(next: boolean, details: MenuRootChangeEventDetails): void {\n\t\tthis._setOpen?.(next, details);\n\t}\n\n\t/**\n\t * Synchronous snapshot of the current open state.\n\t */\n\tget isOpen(): boolean {\n\t\treturn this._open;\n\t}\n}\n\n/**\n * `MenuHandle` — imperative surface + detached-trigger association.\n * Matches React's `MenuHandle` 1:1 on the public methods.\n */\nexport class MenuHandle<Payload = unknown> {\n\t/** @internal */\n\tpublic readonly store: MenuStore<Payload>;\n\n\tconstructor() {\n\t\tthis.store = new MenuStore<Payload>();\n\t}\n\n\t/**\n\t * Opens the menu and associates it with the trigger with the given id.\n\t * Throws if no trigger with that id is registered.\n\t */\n\topen(triggerId: string): void {\n\t\tconst triggerElement = this.store.context.triggerElements.getById(\n\t\t\ttriggerId,\n\t\t) as HTMLElement | undefined;\n\n\t\tif (!triggerElement) {\n\t\t\tthrow new Error(\n\t\t\t\t`Base UI: MenuHandle.open: No trigger found with id \"${triggerId}\".`,\n\t\t\t);\n\t\t}\n\n\t\tthis.store.setOpen(\n\t\t\ttrue,\n\t\t\tcreateChangeEventDetails<MenuRootChangeEventReason>(\n\t\t\t\tREASONS.imperativeAction as MenuRootChangeEventReason,\n\t\t\t\tundefined,\n\t\t\t\ttriggerElement,\n\t\t\t) as MenuRootChangeEventDetails,\n\t\t);\n\t}\n\n\t/** Closes the menu. */\n\tclose(): void {\n\t\tthis.store.setOpen(\n\t\t\tfalse,\n\t\t\tcreateChangeEventDetails<MenuRootChangeEventReason>(\n\t\t\t\tREASONS.imperativeAction as MenuRootChangeEventReason,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t) as MenuRootChangeEventDetails,\n\t\t);\n\t}\n\n\t/** Whether the menu is currently open. Synchronous. */\n\tget isOpen(): boolean {\n\t\treturn this.store.isOpen;\n\t}\n}\n\n/**\n * Factory for `MenuHandle` — matches React's `createMenuHandle()`.\n */\nexport function createMenuHandle<Payload = unknown>(): MenuHandle<Payload> {\n\treturn new MenuHandle<Payload>();\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SACCA,wBAAwB,EACxBC,OAAO,QACD,sCAAsC;AAC7C,SAASC,eAAe,QAAQ,+CAA+C;;AAM/E;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA,OAAO,MAAMC,SAAS,CAAqB;EAC1C;AACD;AACA;AACA;;EAGC;AACD;AACA;AACA;EACSC,QAAQ,GAA4B,IAAI;;EAEhD;AACD;AACA;AACA;EACSC,KAAK,GAAG,KAAK;EAErBC,WAAWA,CAAA,EAAG;IACb,IAAI,CAACC,OAAO,GAAG;MACdC,eAAe,EAAE,IAAIN,eAAe,CAAC;IACtC,CAAC;EACF;;EAEA;AACD;AACA;AACA;AACA;EACCO,aAAaA,CAACC,EAA2B,EAAQ;IAChD,IAAI,CAACN,QAAQ,GAAGM,EAAE;EACnB;;EAEA;AACD;AACA;AACA;AACA;AACA;EACCC,aAAaA,CAACC,IAAa,EAAQ;IAClC,IAAI,CAACP,KAAK,GAAGO,IAAI;EAClB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