import React from "react";
//#region src/modal/modal-context.d.ts
interface ModalRecord
{
readonly id: string;
readonly visible: boolean;
readonly props: P;
readonly resolver?: ModalResolver;
}
interface ModalResolver {
resolve: (value: unknown) => void;
reject: (reason?: unknown) => void;
}
type ModalState = Readonly>;
type ModalComponent = React.ComponentType
;
type Listener = () => void;
interface ModalStore {
getState: () => ModalState;
subscribe: (listener: Listener) => () => void;
register: (id: string, component: ModalComponent) => () => void;
isRegistered: (id: string) => boolean;
getRegisteredComponent: (id: string) => ModalComponent | undefined;
show: (id: string, props?: P) => Promise;
hide: (id: string, result?: unknown) => void;
remove: (id: string) => void;
hideAll: () => void;
}
declare function createModalStore(): ModalStore;
/**
* Process-wide singleton store. Use this — and only this — when you need to
* trigger modals from **outside React** (event handlers attached to globals,
* route guards, error reporters, sagas). `` defaults to this
* store, so calls made via `modalStore.show()` are picked up by the outlet.
*
* Inside React, prefer `useModalActions()` so refactors that change which
* store backs a subtree (e.g. tests, multi-tenant) keep working.
*
* Use `createModalStore()` instead when you need an isolated store —
* unit tests, SSR per-request stores, or independent modal trees.
*/
declare const modalStore: ModalStore;
interface ModalProviderProps {
/**
* Optional store override. Defaults to the package-level `modalStore`
* singleton, which also accepts imperative calls from outside React.
*/
store?: ModalStore;
children: React.ReactNode;
}
declare function ModalProvider({
store,
children
}: ModalProviderProps): React.JSX.Element;
interface ModalRegisterProps {
id: string;
component: ModalComponent;
}
declare function ModalRegister({
id,
component
}: ModalRegisterProps): null;
interface UseModalActionsReturn {
show: (id: string, props?: P) => Promise;
hide: (id: string, result?: unknown) => void;
hideAll: () => void;
register: (id: string, component: ModalComponent) => () => void;
}
interface UseModalReturn {
visible: boolean;
show: () => void;
close: () => void;
toggle: () => void;
}
/**
* Per-id state hook for modals you mount and control yourself
* (the legacy/manual pattern). Re-renders only when this id's visibility flips.
*/
declare function useModal(id: string): UseModalReturn;
/**
* Imperative actions for the surrounding store. Does not subscribe to state —
* calling components do not re-render when modals open/close. Use this to
* trigger modals from inside React components (event handlers, mutations).
*/
declare function useModalActions(): UseModalActionsReturn;
interface UseModalSelfReturn {
/** Stable id of the surrounding registered modal. */
id: string;
/** True between `show()` and `hide()`. Drive the underlying Modal's `visible` prop. */
visible: boolean;
/** Runtime props passed to `show(id, props)`. */
props: P;
/**
* Close the modal and resolve the awaiting `show()` promise with `result`.
* Modal stays mounted while the exit animation runs — call `remove()` in `afterClose`.
*/
hide: (result?: R) => void;
/** Reject the awaiting `show()` promise without resolving. Does not close. */
reject: (reason?: unknown) => void;
/** Hard-remove the record from store; typically wired to `afterClose`. */
remove: () => void;
}
/**
* Read this modal's own state from inside a registered component.
* Throws if used outside an outlet-rendered modal.
*/
declare function useModalSelf
(): UseModalSelfReturn
;
//#endregion
export { ModalComponent, ModalProvider, ModalProviderProps, ModalRecord, ModalRegister, ModalRegisterProps, ModalState, ModalStore, UseModalActionsReturn, UseModalReturn, UseModalSelfReturn, createModalStore, modalStore, useModal, useModalActions, useModalSelf };
//# sourceMappingURL=modal-context.d.ts.map