{"version":3,"names":["createContext","createMemo","useContext","createPopupCore","readOption","SNAPSHOT_KEYS","snapshotKeys","DialogContext","useDialog","optional","ctx","Error","createDialog","options","core","open","disabled","onOpenChange","modal","name","disablePointerDismissal","Boolean","api","setOpen","toggle","Provider","props","children","DIALOG_SNAPSHOT_KEYS"],"sources":["create-dialog.tsx"],"sourcesContent":["import type { JSX } from \"@solidjs/web\";\nimport { type Accessor, createContext, createMemo, useContext } from \"solid-js\";\nimport { createPopupCore } from \"../internals/create-popup-core\";\nimport { type MaybeAccessor, readOption } from \"../internals/maybe-accessor\";\nimport {\n\tSNAPSHOT_KEYS,\n\ttype Snapshottable,\n\tsnapshotKeys,\n} from \"../internals/observability/snapshot\";\n\n/**\n * Why the dialog's open state changed.\n *\n * - `\"trigger-press\"` — trigger was clicked or keyboard-activated.\n * - `\"escape-key\"` — Escape dismissed the dialog.\n * - `\"outside-press\"` — pointer pressed outside (when enabled).\n * - `\"close-button\"` — `<Dialog.Close>` was pressed.\n * - `\"imperative\"` — `d.setOpen()` called programmatically.\n */\nexport type DialogChangeReason =\n\t| \"trigger-press\"\n\t| \"escape-key\"\n\t| \"outside-press\"\n\t| \"close-button\"\n\t| \"imperative\";\n\nimport type { DialogModalKind } from \"./dialog-root-context\";\n\nexport type { DialogModalKind };\n\n/**\n * Options for {@link createDialog}.\n */\nexport interface CreateDialogOptions {\n\t/**\n\t * Open state. Consumer-owned signal.\n\t */\n\topen: MaybeAccessor<boolean>;\n\t/**\n\t * Whether interaction is suppressed.\n\t * @default false\n\t */\n\tdisabled?: MaybeAccessor<boolean>;\n\t/**\n\t * Modal surface kind.\n\t * @default true\n\t */\n\tmodal?: MaybeAccessor<DialogModalKind>;\n\t/**\n\t * When true, outside-press dismissal is disabled.\n\t * @default false\n\t */\n\tdisablePointerDismissal?: MaybeAccessor<boolean>;\n\t/**\n\t * Pre-change callback fired via `runWithOwner(null, ...)`.\n\t */\n\tonOpenChange?: (\n\t\topen: boolean,\n\t\tevent: Event,\n\t\treason: DialogChangeReason,\n\t) => void;\n}\n\n/**\n * Public API returned by {@link createDialog}.\n */\nexport interface DialogApi {\n\t/** Reactive accessor for the current open state. */\n\topen: Accessor<boolean>;\n\t/** Whether interaction is suppressed. */\n\tdisabled: Accessor<boolean>;\n\t/** Modal surface kind. */\n\tmodal: Accessor<DialogModalKind>;\n\t/** Whether outside-press dismissal is disabled. */\n\tdisablePointerDismissal: Accessor<boolean>;\n\n\t/** Imperative open setter. */\n\tsetOpen: (next: boolean, event?: Event, reason?: DialogChangeReason) => void;\n\t/** Flip open (no-op when disabled). */\n\ttoggle: (event?: Event, reason?: DialogChangeReason) => void;\n\n\t/** Context provider. */\n\tProvider: (props: { children: JSX.Element }) => JSX.Element;\n}\n\nconst DialogContext = createContext<DialogApi | null>(null);\n\n/**\n * Read the nearest {@link DialogApi}. Throws unless `optional` is true.\n */\nexport function useDialog(): DialogApi;\nexport function useDialog(optional: true): DialogApi | null;\nexport function useDialog(optional?: boolean): DialogApi | null {\n\tconst ctx = useContext(DialogContext);\n\tif (ctx == null && !optional) {\n\t\tthrow new Error(\n\t\t\t\"Base UI: useDialog() must be called inside a <d.Provider>.\",\n\t\t);\n\t}\n\treturn ctx;\n}\n\n/**\n * Headless primitive for a dialog compound. Modal by default. Configurable\n * outside-press dismissal. DOM machinery lives in `<Dialog.Root>`.\n */\nexport function createDialog(options: CreateDialogOptions): DialogApi {\n\tconst core = createPopupCore<DialogChangeReason>({\n\t\topen: options.open,\n\t\tdisabled: options.disabled,\n\t\tonOpenChange: options.onOpenChange,\n\t});\n\n\tconst modal = createMemo<DialogModalKind>(\n\t\t() => readOption(options.modal) ?? true,\n\t\t{ name: \"dialog.modal\" },\n\t);\n\n\tconst disablePointerDismissal = createMemo<boolean>(\n\t\t() => Boolean(readOption(options.disablePointerDismissal)),\n\t\t{ name: \"dialog.disablePointerDismissal\" },\n\t);\n\n\tconst api: DialogApi = {\n\t\topen: core.open,\n\t\tdisabled: core.disabled,\n\t\tmodal,\n\t\tdisablePointerDismissal,\n\t\tsetOpen: core.setOpen,\n\t\ttoggle: core.toggle,\n\t\tProvider: (props) => (\n\t\t\t<DialogContext value={api}>{props.children}</DialogContext>\n\t\t),\n\t};\n\n\t(api as DialogApi & Snapshottable)[SNAPSHOT_KEYS] = DIALOG_SNAPSHOT_KEYS;\n\n\treturn api;\n}\n\nconst DIALOG_SNAPSHOT_KEYS = snapshotKeys<DialogApi>(\n\t\"open\",\n\t\"disabled\",\n\t\"modal\",\n\t\"disablePointerDismissal\",\n);\n"],"mappings":"AACA,SAAwBA,aAAa,EAAEC,UAAU,EAAEC,UAAU,QAAQ,UAAU;AAC/E,SAASC,eAAe,QAAQ,gCAAgC;AAChE,SAA6BC,UAAU,QAAQ,6BAA6B;AAC5E,SACCC,aAAa,EAEbC,YAAY,QACN,qCAAqC;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA;AACA;AACA;;AA+BA;AACA;AACA;;AAoBA,MAAMC,aAAa,GAAGP,aAAa,CAAmB,IAAI,CAAC;;AAE3D;AACA;AACA;;AAGA,OAAO,SAASQ,SAASA,CAACC,QAAkB,EAAoB;EAC/D,MAAMC,GAAG,GAAGR,UAAU,CAACK,aAAa,CAAC;EACrC,IAAIG,GAAG,IAAI,IAAI,IAAI,CAACD,QAAQ,EAAE;IAC7B,MAAM,IAAIE,KAAK,CACd,4DACD,CAAC;EACF;EACA,OAAOD,GAAG;AACX;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASE,YAAYA,CAACC,OAA4B,EAAa;EACrE,MAAMC,IAAI,GAAGX,eAAe,CAAqB;IAChDY,IAAI,EAAEF,OAAO,CAACE,IAAI;IAClBC,QAAQ,EAAEH,OAAO,CAACG,QAAQ;IAC1BC,YAAY,EAAEJ,OAAO,CAACI;EACvB,CAAC,CAAC;EAEF,MAAMC,KAAK,GAAGjB,UAAU,CACvB,MAAMG,UAAU,CAACS,OAAO,CAACK,KAAK,CAAC,IAAI,IAAI,EACvC;IAA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