import { Effect, Option, Schema as S } from 'effect'; import * as Command from 'foldkit/command'; import { type ChildAttribute, type Html } from 'foldkit/html'; import * as Update from 'foldkit/update'; /** Schema for the dialog component's state, tracking its unique ID, open/closed status, animation support, and animation lifecycle phase. */ export declare const Model: S.Struct<{ readonly id: S.String; readonly isOpen: S.Boolean; readonly isAnimated: S.Boolean; readonly animation: S.Struct<{ readonly id: S.String; readonly isShowing: S.Boolean; readonly transitionState: S.Literals; }>; readonly maybeFocusSelector: S.Option; }>; export type Model = typeof Model.Type; /** Union of all messages the dialog component can produce. */ export declare const Message: import("foldkit/message").MessageUnion<{ readonly RequestedOpen: {}; readonly RequestedClose: {}; readonly CompletedShowDialog: {}; readonly CompletedCloseDialog: {}; readonly Unmounted: {}; readonly CompletedReleaseDialogResources: {}; readonly GotAnimationMessage: { readonly message: import("foldkit/message").MessageUnion<{ readonly Showed: {}; readonly Hid: {}; readonly CompletedWaitForPaint: {}; readonly EndedAnimation: {}; }>; }; }>; export type RequestedOpen = typeof Message.RequestedOpen.Type; export type RequestedClose = typeof Message.RequestedClose.Type; export type CompletedShowDialog = typeof Message.CompletedShowDialog.Type; export type CompletedCloseDialog = typeof Message.CompletedCloseDialog.Type; export type Unmounted = typeof Message.Unmounted.Type; export type CompletedReleaseDialogResources = typeof Message.CompletedReleaseDialogResources.Type; export type Message = typeof Message.Type; /** Union of out-messages the dialog component can produce. */ export declare const OutMessage: import("foldkit/message").MessageUnion<{ readonly Opened: {}; readonly Closed: {}; }>; export type Opened = typeof OutMessage.Opened.Type; export type Closed = typeof OutMessage.Closed.Type; export type OutMessage = typeof OutMessage.Type; /** Configuration for creating a dialog model with `init`. The `id` must be * non-empty and unique within the document: it keys the dialog element, its * ARIA references, and the framework's per-dialog resource cleanup, so a * duplicate or empty id breaks cleanup accounting. * * The dialog derives framework-managed ids from this `id`: `-dialog-title`, * `-dialog-description`, and `-panel` (the animation panel). Spread * `RenderInfo`'s `title` / `description` onto your heading and description * elements rather than constructing those ids yourself. */ export type InitConfig = Readonly<{ id: string; isOpen?: boolean; isAnimated?: boolean; /** CSS selector for the element that receives focus when the dialog opens. * A selector-based override of the `initialFocus` RenderInfo marker, for the * cases a spread-on marker cannot express: an element whose id you do not * own, or a descendant selector. Takes precedence over `initialFocus`. With * neither set, focus falls to the first focusable element. */ focusSelector?: string; }>; /** Creates an initial dialog model from a config. Defaults to closed and non-animated. */ export declare const init: (config: InitConfig) => Model; /** Data attribute the dialog places on the `initialFocus` RenderInfo group and * focuses on open. */ export declare const initialFocusMarkerAttribute = "foldkit-dialog-initial-focus"; /** Selector for {@link initialFocusMarkerAttribute}, focused against the open * dialog when no `focusSelector` is configured. */ export declare const initialFocusMarkerSelector = "[data-foldkit-dialog-initial-focus]"; type UpdateReturn = Update.ReturnWithOutMessage; /** Locks page scroll and opens the native dialog element through * `Dom.showDialog`, which calls `show()` (not native `showModal()`) so other * high-z-index overlays stay interactive. It layers the dialog with a high * z-index, traps focus, and dispatches a `cancel` event on Esc. The Dialog * component supplies its own backdrop. */ export declare const ShowDialog: Command.CommandDefinitionWithArgs<"ShowDialog", { id: S.String; focusSelector: S.String; }, Effect.Effect<{ readonly _tag: "CompletedShowDialog"; }, never, never>>; /** Calls `close()` on the native dialog element and unlocks page scroll. */ export declare const CloseDialog: Command.CommandDefinitionWithArgs<"CloseDialog", { id: S.String; }, Effect.Effect<{ readonly _tag: "CompletedCloseDialog"; }, never, never>>; /** Releases the framework hygiene the dialog holds while open (scroll lock, * focus trap, return focus, stack entry) when the element unmounts without a * purposeful close. Idempotent: a no-op if the dialog already released its * resources through `CloseDialog`. */ export declare const ReleaseDialogResources: Command.CommandDefinitionWithArgs<"ReleaseDialogResources", { id: S.String; }, Effect.Effect<{ readonly _tag: "CompletedReleaseDialogResources"; }, never, never>>; /** Processes a Dialog Message and returns the next Model and optional Commands. */ export declare const update: (model: Model, message: Message) => Readonly<{ model: { readonly id: string; readonly isOpen: boolean; readonly isAnimated: boolean; readonly animation: { readonly id: string; readonly isShowing: boolean; readonly transitionState: "Idle" | "EnterStart" | "EnterAnimating" | "LeaveStart" | "LeaveAnimating"; }; readonly maybeFocusSelector: Option.Option; }; commands?: Update.Commands<{ readonly _tag: "RequestedOpen"; } | { readonly _tag: "RequestedClose"; } | { readonly _tag: "CompletedShowDialog"; } | { readonly _tag: "CompletedCloseDialog"; } | { readonly _tag: "Unmounted"; } | { readonly _tag: "CompletedReleaseDialogResources"; } | { readonly _tag: "GotAnimationMessage"; readonly message: { readonly _tag: "Showed"; } | { readonly _tag: "Hid"; } | { readonly _tag: "CompletedWaitForPaint"; } | { readonly _tag: "EndedAnimation"; }; }, never>; outMessage?: { readonly _tag: "Opened"; } | { readonly _tag: "Closed"; }; }>; /** Programmatically opens the dialog. */ export declare const open: (model: Model) => UpdateReturn; /** Programmatically closes the dialog. */ export declare const close: (model: Model) => UpdateReturn; /** Returns the framework-managed id the dialog's `aria-labelledby` points at, * the `-dialog-title` suffix on `model.id`. * * The primary path is spreading `RenderInfo`'s `title` onto your heading * (`h.h2([...title], [...])`), which carries this id for you. Reach for this * helper only when you need the id as a value outside `toView`: a Command that * calls `getElementById`, a cross-element `aria-describedby`, or a test. Do not * hand-roll the id string. */ export declare const titleId: (model: Model) => string; /** Returns the framework-managed id the dialog's `aria-describedby` points at, * the `-dialog-description` suffix on `model.id`. * * The primary path is spreading `RenderInfo`'s `description` onto your * description element (`h.p([...description], [...])`), which carries this id * for you. Reach for this helper only when you need the id as a value outside * `toView`: a Command that calls `getElementById`, a cross-element * `aria-describedby`, or a test. Do not hand-roll the id string. */ export declare const descriptionId: (model: Model) => string; /** Render-time payload published to the consumer's `toView`. * * - `dialog`: attributes for the native `` element. Carries * the id, ARIA labelling, `open` prop, positioning style, the * `OnCancel` handler that wires Escape to `RequestedClose`, and an * `OnUnmount` backstop that releases framework hygiene (scroll lock, * focus trap, return focus) if the element is removed from the DOM * while still open, such as navigating away from a route-keyed subtree. * The consumer MUST render an `h.dialog(...)` element so the framework * can open and close it, and so the unmount backstop can fire. * - `backdrop`: attributes for the backdrop element. Includes the * Animation data attributes and the `OnClick` handler that closes * the dialog on outside-click (suppressed while a leave animation * is in progress). * - `panel`: attributes for the panel element. Includes the panel id * (`${model.id}-panel`) and the Animation data attributes. * - `title`: attributes for the accessible-name heading. Carries the * framework-managed id the dialog's `aria-labelledby` points at. Spread * onto your heading element (`h.h2([...title], [...])`) so labelling * wires up without hand-rolling the id. * - `description`: attributes for the description element. Carries the * framework-managed id the dialog's `aria-describedby` points at. Spread * onto your description element (`h.p([...description], [...])`). * - `initialFocus`: attributes for the element that should receive focus when * the dialog opens. Spread onto that element (`h.input([...initialFocus])`). * A configured `focusSelector` (see `init`) takes precedence, and focus * falls back to the default when no element carries the group. * - `closeButton`: attributes for an in-panel close control such as a Cancel * or dismiss button. Carries the `OnClick` handler that closes the * dialog (suppressed while a leave animation is in progress). Spread * onto your own button so a plain close needs no parent message. Sets * `type="button"` so that a close control inside a `form` element in the * panel closes without also submitting the form. Spread a later `h.Type` * to override it. * - `isVisible`: derived from `isOpen` and the Animation * `transitionState`. The consumer renders backdrop + panel only * while this is true. */ export type RenderInfo = Readonly<{ dialog: ReadonlyArray; backdrop: ReadonlyArray; panel: ReadonlyArray; title: ReadonlyArray; description: ReadonlyArray; initialFocus: ReadonlyArray; closeButton: ReadonlyArray; isVisible: boolean; }>; /** Per-render view inputs passed to `view` via `h.submodel`'s `viewInputs` field. */ export type ViewInputs = Readonly<{ toView: (render: RenderInfo) => Html; }>; /** Renders a headless dialog component backed by the native `` * element. `ShowDialog` opens it through `Dom.showDialog`, which uses `show()` * (not native `showModal()`) with a high z-index, a focus trap, a * component-supplied backdrop, and a `cancel` event dispatched on Esc. */ export declare const view: import("foldkit/submodel").View<{ readonly id: string; readonly isOpen: boolean; readonly isAnimated: boolean; readonly animation: { readonly id: string; readonly isShowing: boolean; readonly transitionState: "Idle" | "EnterStart" | "EnterAnimating" | "LeaveStart" | "LeaveAnimating"; }; readonly maybeFocusSelector: Option.Option; }, { readonly _tag: "RequestedOpen"; } | { readonly _tag: "RequestedClose"; } | { readonly _tag: "CompletedShowDialog"; } | { readonly _tag: "CompletedCloseDialog"; } | { readonly _tag: "Unmounted"; } | { readonly _tag: "CompletedReleaseDialogResources"; } | { readonly _tag: "GotAnimationMessage"; readonly message: { readonly _tag: "Showed"; } | { readonly _tag: "Hid"; } | { readonly _tag: "CompletedWaitForPaint"; } | { readonly _tag: "EndedAnimation"; }; }, Readonly<{ toView: (render: RenderInfo) => Html; }>>; export {}; //# sourceMappingURL=index.d.ts.map