import { RefObject } from 'react'; /** * ASMA-8471 — native Back closes the top ui-core overlay through its own close path. * * This module owns ONLY the overlay side of the contract: a LIFO registry of open overlays plus the * arbitration that decides which one a Back press (or a native dialog `cancel`/`close`) acts on. It * never touches browser history — no `pushState`, `back()` or `go()` — that lives in * `asma-core-helpers`' `getHistory()` adapter (PR #51, ASMA-8476), published at * `window.__ASMA__SHELL__.overlayBack = { v, enabled, register }`. When that adapter is live (`v === * 1` and `register` is a function) this module registers ONE long-lived closer with it as soon as the * stack goes from empty to non-empty, and unregisters it once the stack drains back to empty — see * {@link registerOverlayBackCloser}. When the adapter is absent, or on a version this module doesn't * speak, it runs registry-only and never touches `window.__ASMA__SHELL__` at all. * * **Window-scoped, not module-scoped** — same reasoning as `useTopLayer.hook.ts`'s * `__asmaOpenModalDialogRegistry__`: a normal (non-`KERNEL_EXTERNAL`) build instantiates this module * once per micro-frontend bundle, so a module-level array would give every bundle its own stack and * "close only the top" would silently become "close only MY top" — and TWO bundles would each try to * register their own adapter closer. `document.defaultView` (or `rawWindow` under the `asma-micro-app` * sandbox) is the one object every bundle in the page shares, so the adapter registration state lives * there too. */ export declare const OVERLAY_BACK_REGISTRY_VERSION = 1; /** Returns nothing: no latch, a repeated Back repeats the dismissal. Returns a Promise: the entry * latches until it settles, and Back on a latched top does nothing (see `requestCloseTopOverlayBack`). */ export type OverlayBackRequestClose = (event?: Event) => false | void | Promise; interface OverlayBackEntry { requestClose: OverlayBackRequestClose; pending: boolean; owner: Element | null; parentOwner: Element | null; ownerRef?: RefObject; parentOwnerRef?: RefObject; } interface OverlayBackAdapterState { /** The adapter's own unregister for our one long-lived closer, once `register()` has been called. */ unregister: (() => void) | null; } interface OverlayBackRegistry { version: number; entries: OverlayBackEntry[]; adapter: OverlayBackAdapterState; } /** The `asma-core-helpers` contract (PR #51, ASMA-8476): `register` hands it the current top's close * function and gets back that registration's unregister. Absent, or `v` other than `1`, means no * history adapter is live. */ interface OverlayBackAdapter { v?: number; enabled?: boolean; pendingNavigation?: boolean; register?: (requestClose: OverlayBackRequestClose) => () => void; continuePendingNavigation?: () => void; failOpenPendingNavigation?: () => void; } declare global { interface Window { rawWindow?: Window; __asmaOverlayBackRegistry__?: OverlayBackRegistry; __ASMA__SHELL__?: { overlayBack?: OverlayBackAdapter; }; } } /** * Push a LIFO entry onto the overlay-back stack. The returned unregister must run when the overlay * stops being eligible to receive Back (closes, or is no longer the active layer) — see * {@link useBackCloses} for the React lifecycle wrapper every consumer actually uses. */ export declare function registerOverlayBackCloser(requestClose: OverlayBackRequestClose, owner?: Element | null, parentOwner?: Element | null, ownerRef?: RefObject, parentOwnerRef?: RefObject): () => void; /** * Declares "overlays rendered below me in the React tree are nested inside me", which is what makes * one Back press close the inner one first (BACK-2). * * Needed because an overlay is usually portalled out of its parent's DOM subtree, so DOM * containment cannot carry the relationship — only the React tree still knows it. Wrap your * surface's children in ``, passing the same * ref you gave {@link useBackCloses} as `ownerRef`. Every ui-core overlay already does this; an app * wiring up an overlay of its own should too, otherwise a ui-core overlay opened inside it is * ordered by registration time alone and Back may close the outer surface first. */ export declare const OverlayBackOwnerContext: import('react').Context | undefined>; /** * Act on the topmost registered overlay, honouring the close contract's latch: a top entry whose * previous `requestClose` returned a Promise that hasn't settled yet is skipped entirely (one * documented dead press), never passed through to the next entry down — BACK-2 is "one press closes * one layer", not "closes the nearest dismissible one". Known limitation, by design: there is no * timeout, so a Promise that never settles keeps Back dead on that surface, and holds a route change * the history adapter deferred behind it, until the surface unmounts. * * `StyledDialog`'s native `cancel`/`close` arbitration calls this directly, and it is exactly what the * one closer registered with the history adapter (`asma-core-helpers`, a separate package) delegates * to on an owned traversal. */ export declare function requestCloseTopOverlayBack(event?: Event): false | void | Promise; /** Number of overlays currently registered. */ export declare function getOverlayBackStackSize(): number; /** `true` when a live `asma-core-helpers` history adapter (PAT-002) has published `overlayBack.v === 1`. */ export declare function hasOverlayBackAdapter(): boolean; /** The host kill switch: off means no history adapter, so pickers fall back to their legacy history path. */ export declare function isOverlayBackEnabled(): boolean; /** * Register a surface onto the overlay-back stack while `active`, so native Back closes it through its * own `requestClose` — see {@link requestCloseTopOverlayBack} for the arbitration. This hook never * installs a `popstate`/history listener of its own, with or without a live adapter — that would race * `asma-core-helpers`' own listener (CON-002/CON-009) and duplicate work the adapter already owns. The * adapter registration itself (see {@link registerOverlayBackCloser}) is driven purely by the stack's * empty/non-empty transitions, not by this hook. * * Pass `ownerRef` wherever the surface has a stable root element: it is what places the entry * relative to a nested child (`isOwnedBy`) and to an open native modal * ({@link isCoveredByOpenModalDialog}). */ export interface UseBackClosesOptions { /** * Register while `true`, unregister while `false` — normally the surface's own "is showing" * state. Keep it off for a state that is visible but not dismissable as an overlay (a minimized * panel), so Back reaches whatever is behind it instead. */ active: boolean; /** * The surface's existing close path — the same function its ✕ or Escape already calls. Never a * synthetic key event. Return nothing for a plain dismissal; return a Promise to latch the * surface while an async close runs (Back does nothing until it settles); return `false` to * refuse this press, which is also how a surface that must survive navigation opts out of the * adapter's deferred route change. */ requestClose: OverlayBackRequestClose; /** * The surface's own root element — the one that is actually painted on top. Pass it wherever * there is one. It is what lets Back order this surface against an overlay nested inside it and * against an open native modal ``; without it the entry is ordered by registration * time alone. For a surface promoted into the top layer via the Popover API, this must be the * element carrying the `popover` attribute, not a wrapper around it. */ ownerRef?: RefObject; } export declare function useBackCloses({ active, requestClose, ownerRef }: UseBackClosesOptions): void; export {};