{"version":3,"names":["createChangeEventDetails","REASONS","PopupTriggerMap","DialogStore","_setOpen","_setPayload","_open","constructor","context","triggerElements","attachSetOpen","fn","attachSetPayload","setOpenMirror","next","setOpen","details","setPayload","payload","isOpen","DialogHandle","store","open","triggerId","triggerElement","getById","undefined","process","env","NODE_ENV","console","warn","imperativeAction","preventUnmountOnClose","openWithPayload","close","createDialogHandle"],"sources":["dialog-store.ts"],"sourcesContent":["/**\n * `DialogStore` — thin Solid 2 port of Base UI React's `DialogStore`\n * (`packages/react/src/dialog/store/DialogStore.ts`).\n *\n * Mirrors `PopoverStore` from the popover compound: the actual state\n * machine lives on `<Dialog.Root>`'s local signals (open / mount /\n * transition status / interactions). This store is a thin imperative-API\n * wrapper that exposes:\n *\n * - a `PopupTriggerMap` so `<Dialog.Trigger id=\"...\">` can register\n *   itself and `DialogHandle.open(id)` can resolve the trigger element.\n * - `setOpen(next, details)` — the writer `<Dialog.Root>` binds via\n *   `attachSetOpen` during setup. The handle's `open()` / `close()` /\n *   `openWithPayload()` all route through this.\n * - `setPayload(payload)` — same deal, for the payload slot.\n * - Synchronous `isOpen` read for imperative callers who don't want to\n *   subscribe to reactivity.\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\tDialogRootChangeEventDetails,\n\tDialogRootChangeEventReason,\n} from \"../dialog-root-context\";\n\nexport type DialogStoreSetOpen = (\n\tnext: boolean,\n\tdetails: DialogRootChangeEventDetails,\n) => void;\n\nexport type DialogStoreSetPayload<Payload> = (\n\tpayload: Payload | undefined,\n) => void;\n\n/**\n * Internal store shape for `<Dialog.Root>`. Public surface via\n * `DialogHandle` is stable; everything else is `@internal`.\n */\nexport class DialogStore<_Payload = unknown> {\n\t/**\n\t * Trigger registry. `<Dialog.Trigger id=\"...\">` adds itself on mount;\n\t * `DialogHandle.open(id)` looks up the element to seed the change\n\t * details' `trigger` slot.\n\t */\n\tpublic readonly context: { triggerElements: PopupTriggerMap };\n\n\tprivate _setOpen: DialogStoreSetOpen | null = null;\n\tprivate _setPayload: DialogStoreSetPayload<_Payload> | null = null;\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/** @internal */\n\tattachSetOpen(fn: DialogStoreSetOpen | null): void {\n\t\tthis._setOpen = fn;\n\t}\n\n\t/** @internal */\n\tattachSetPayload(fn: DialogStoreSetPayload<_Payload> | null): void {\n\t\tthis._setPayload = fn;\n\t}\n\n\t/** @internal */\n\tsetOpenMirror(next: boolean): void {\n\t\tthis._open = next;\n\t}\n\n\t/**\n\t * Imperative open-state writer. If the root is not currently mounted\n\t * (handle was constructed but never used inside a live `<Dialog.Root>`),\n\t * this is a no-op.\n\t */\n\tsetOpen(next: boolean, details: DialogRootChangeEventDetails): void {\n\t\tthis._setOpen?.(next, details);\n\t}\n\n\t/** Imperative payload writer. No-op when no root is bound. */\n\tsetPayload(payload: _Payload | undefined): void {\n\t\tthis._setPayload?.(payload);\n\t}\n\n\t/** Synchronous snapshot — does NOT subscribe to Solid's reactive graph. */\n\tget isOpen(): boolean {\n\t\treturn this._open;\n\t}\n}\n\n/**\n * `DialogHandle` — imperative + cross-tree trigger-association surface.\n *\n * Matches Base UI React's `DialogHandle` on the public method surface\n * (`open(triggerId)` / `openWithPayload(payload)` / `close()` / `isOpen`)\n * and carries an internal store that `<Dialog.Root handle={...}>` adopts.\n *\n * Usage:\n *\n * ```ts\n * const handle = Dialog.createHandle<MyPayload>();\n *\n * // ... inside the component\n * <Dialog.Root handle={handle}>\n *   <Dialog.Trigger id=\"t1\" handle={handle}>Open</Dialog.Trigger>\n *   {/* ... *\\/}\n * </Dialog.Root>\n *\n * // Later, from outside:\n * handle.open(\"t1\");\n * handle.openWithPayload({ title: \"Hello\" });\n * handle.close();\n * ```\n */\nexport class DialogHandle<Payload = unknown> {\n\t/** @internal */\n\tpublic readonly store: DialogStore<Payload>;\n\n\tconstructor(store?: DialogStore<Payload>) {\n\t\tthis.store = store ?? new DialogStore<Payload>();\n\t}\n\n\t/**\n\t * Opens the dialog. If `triggerId` is provided and a trigger with\n\t * that id is registered, the dialog is associated with it (focus\n\t * returns there on close; `aria-labelledby` / positioning downstream\n\t * anchors against it). A missing `triggerId` still opens the dialog\n\t * but skips the association.\n\t */\n\topen(triggerId: string | null): void {\n\t\tconst triggerElement =\n\t\t\ttriggerId !== null\n\t\t\t\t? (this.store.context.triggerElements.getById(triggerId) as\n\t\t\t\t\t\t| HTMLElement\n\t\t\t\t\t\t| undefined)\n\t\t\t\t: undefined;\n\n\t\tif (process.env.NODE_ENV !== \"production\") {\n\t\t\tif (triggerId !== null && !triggerElement) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Base UI: DialogHandle.open: No trigger found with id \"${triggerId}\". The dialog will open, but the trigger will not be associated with the dialog.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tthis.store.setOpen(\n\t\t\ttrue,\n\t\t\tcreateChangeEventDetails<\n\t\t\t\tDialogRootChangeEventReason,\n\t\t\t\t{ preventUnmountOnClose: () => void }\n\t\t\t>(\n\t\t\t\tREASONS.imperativeAction as DialogRootChangeEventReason,\n\t\t\t\tundefined,\n\t\t\t\ttriggerElement,\n\t\t\t\t{ preventUnmountOnClose: () => {} },\n\t\t\t) as DialogRootChangeEventDetails,\n\t\t);\n\t}\n\n\t/**\n\t * Opens the dialog and sets the payload. Does NOT associate the\n\t * dialog with any trigger — the render-function children receive\n\t * `{ payload }` but there's no anchor element.\n\t */\n\topenWithPayload(payload: Payload): void {\n\t\tthis.store.setPayload(payload);\n\t\tthis.store.setOpen(\n\t\t\ttrue,\n\t\t\tcreateChangeEventDetails<\n\t\t\t\tDialogRootChangeEventReason,\n\t\t\t\t{ preventUnmountOnClose: () => void }\n\t\t\t>(\n\t\t\t\tREASONS.imperativeAction as DialogRootChangeEventReason,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t{ preventUnmountOnClose: () => {} },\n\t\t\t) as DialogRootChangeEventDetails,\n\t\t);\n\t}\n\n\t/**\n\t * Closes the dialog.\n\t */\n\tclose(): void {\n\t\tthis.store.setOpen(\n\t\t\tfalse,\n\t\t\tcreateChangeEventDetails<\n\t\t\t\tDialogRootChangeEventReason,\n\t\t\t\t{ preventUnmountOnClose: () => void }\n\t\t\t>(\n\t\t\t\tREASONS.imperativeAction as DialogRootChangeEventReason,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t{ preventUnmountOnClose: () => {} },\n\t\t\t) as DialogRootChangeEventDetails,\n\t\t);\n\t}\n\n\t/** Synchronous snapshot of the open state. */\n\tget isOpen(): boolean {\n\t\treturn this.store.isOpen;\n\t}\n}\n\n/** Factory for `DialogHandle` — matches React's `createDialogHandle()`. */\nexport function createDialogHandle<Payload = unknown>(): DialogHandle<Payload> {\n\treturn new DialogHandle<Payload>();\n}\n"],"mappings":"AAAA;AACA;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;AAe/E;AACA;AACA;AACA;AACA,OAAO,MAAMC,WAAW,CAAqB;EAC5C;AACD;AACA;AACA;AACA;;EAGSC,QAAQ,GAA8B,IAAI;EAC1CC,WAAW,GAA2C,IAAI;EAC1DC,KAAK,GAAG,KAAK;EAErBC,WAAWA,CAAA,EAAG;IACb,IAAI,CAACC,OAAO,GAAG;MACdC,eAAe,EAAE,IAAIP,eAAe,CAAC;IACtC,CAAC;EACF;;EAEA;EACAQ,aAAaA,CAACC,EAA6B,EAAQ;IAClD,IAAI,CAACP,QAAQ,GAAGO,EAAE;EACnB;;EAEA;EACAC,gBAAgBA,CAACD,EAA0C,EAAQ;IAClE,IAAI,CAACN,WAAW,G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