import type { OverlayCloseReason, OverlayId, OverlayOpenOptions, OverlayRenderer, OverlayUpdate } from "./overlay-context.js"; import type { Mode } from "@tooee/commands"; /** * An overlay stack entry as tracked by the store. `prevMode` is the host mode * captured at open time (mode itself stays outside this package — see the * shell's OverlayProvider, which owns all mode side effects). */ export interface OverlayRecord { id: OverlayId; render: OverlayRenderer; payload: TPayload; options: OverlayOpenOptions; prevMode: Mode; } export interface OverlayStoreContext { stack: readonly OverlayRecord[]; } /** * Emitted when a record leaves the stack (close, closeTop, or same-id * replacement). Lifecycle side effects (onClose callbacks, mode restoration, * sequence-reset bridges) are performed by the adapter subscribed via * `store.on("closed", ...)`; transitions stay pure. */ export interface OverlayClosedEmit { record: OverlayRecord; reason: OverlayCloseReason; /** * Legacy mode restoration decision, computed in the transition (it needs * stack state): `record.prevMode` when the record is non-ownCommands, * `restoreMode !== false`, AND it was the topmost non-ownCommands entry * (closing a buried legacy overlay must not clobber the mode set by the one * above it — R-04); otherwise null. Same-id replacement displacement never * restores (the successor takes over). */ restoreModeTo: Mode | null; } /** * Event payload map, passed explicitly as a `createStore` generic * (@xstate/store v4 removed the `emits` config; event/emitted types come from * generics or `schemas`). Both maps here are deliberately CLOSED — no index * signatures — so unknown `store.trigger.*` / `store.send` / `store.on` / * `enqueue.emit.*` event names are compile errors (pinned by * `overlay-store.typecheck.ts`). The v4 `schemas.emitted` alternative was * evaluated and rejected: it gives the same strictness while adding runtime * schema objects this store does not need. */ export interface OverlayOpenedEvent { record: OverlayRecord; } /** * `next` is a discriminated `OverlayUpdate`, not `unknown | ((prev) => unknown)`: * the old union collapsed to `unknown`, so the transition had to guess with * `typeof next === "function"` and could not store a function-valued payload. * The caller now states which it means. */ export interface OverlayUpdatedEvent { id: OverlayId; next: OverlayUpdate; } export interface OverlayClosedEvent { id: OverlayId; reason: OverlayCloseReason; } export interface OverlayClosedTopEvent { reason: OverlayCloseReason; } /** * The two payload MAPS below must stay type aliases. XState v4 constrains them * with `EventPayloadMap = Record`, and only an * object-literal type alias gets TypeScript's implicit index signature — an * `interface` is rejected by that constraint. The only way to make an interface * satisfy it is to add an index signature, which would OPEN the map and destroy * the closed-event-name guarantee pinned by `overlay-store.typecheck.ts`. The * payload types themselves are interfaces (above), which is where the rule's * intent actually applies. */ export type OverlayStoreEvents = { opened: OverlayOpenedEvent; updated: OverlayUpdatedEvent; closed: OverlayClosedEvent; closedTop: OverlayClosedTopEvent; }; export declare const createOverlayStore: () => import("@xstate/store").Store; export type OverlayStore = ReturnType; export declare const selectStack: (ctx: OverlayStoreContext) => readonly OverlayRecord[]; export declare const selectTop: (ctx: OverlayStoreContext) => OverlayRecord | null; export declare const selectHasOverlay: (ctx: OverlayStoreContext) => boolean; export declare const selectIsOpen: (ctx: OverlayStoreContext, id: OverlayId) => boolean; /** Fresh array; prefer selectStack identity + memo in render paths. */ export declare const selectStackIds: (ctx: OverlayStoreContext) => readonly OverlayId[]; //# sourceMappingURL=overlay-store.d.ts.map