import { Extensible } from "../../types/index.mjs"; import { ContextTrinity } from "../createTrinity/index.mjs"; import { SelectionContext, SelectionOptions, SelectionTicket, SelectionTicketInput } from "../createSelection/index.mjs"; import { Plugin } from "../createPlugin/index.mjs"; import { ComputedRef, MaybeRefOrGetter, Ref } from "vue"; //#region src/composables/useStack/index.d.ts /** * Input type for stack tickets - what users provide to register(). */ interface StackTicketInput extends SelectionTicketInput { /** * Callback invoked when the overlay should be dismissed * * @remarks Called by `ticket.dismiss()` or when scrim is clicked. * Typically sets isActive to false. */ onDismiss?: () => void; /** * Whether this overlay blocks scrim dismissal * * @default false * @remarks When true, clicking the scrim will not dismiss this overlay. * Use for critical dialogs requiring explicit user action. */ blocking?: MaybeRefOrGetter; /** * Whether this overlay should be backed by a scrim/backdrop * * @default true * @remarks When false, the overlay still participates in z-index stacking * but `Scrim` skips rendering a backdrop for it. Use for non-modal overlays * (snackbars, toasts, tooltips) that need layering without dimming. */ scrim?: MaybeRefOrGetter; /** * The overlay's DOM element. * * @remarks When set, the stack can expose this element as a top-layer teleport * target via {@link StackContext.topElement}. Native modal dialogs pass their * `` element so non-modal overlays (snackbars) can teleport into them. * * @example * ```ts * stack.register({ el: () => dialogRef.value?.element }) * ``` */ el?: MaybeRefOrGetter; } /** * Output type for stack tickets - what users receive from register(). */ type StackTicket = SelectionTicket & { /** * Callback invoked when the overlay should be dismissed */ onDismiss?: () => void; /** * Whether this overlay blocks scrim dismissal */ blocking: Readonly>; /** * Whether this overlay is backed by a scrim/backdrop */ scrim: Readonly>; /** The overlay's DOM element, if provided at registration. */ el?: MaybeRefOrGetter; /** * The calculated z-index for this overlay * * @remarks Automatically calculated based on selection order. * First selected overlay gets baseZIndex, each subsequent adds increment. */ zIndex: ComputedRef; /** * Whether this overlay is the topmost in the global stack * * @remarks Useful for determining which overlay should handle * global keyboard events (e.g., Escape key). */ globalTop: ComputedRef; /** * Dismiss this overlay * * @remarks If blocking is false, calls onDismiss callback and unselects. * If blocking is true, does nothing. */ dismiss: () => void; }; /** * Context returned by createStack. */ interface StackContext = StackTicket> extends Omit, 'register'> { /** * Whether any overlays are selected (active) * * @remarks Reactive boolean for conditional scrim rendering. */ isActive: Readonly>; /** * The topmost selected overlay ticket * * @remarks Access to the current top overlay for inspection. */ top: Readonly>; /** * Z-index for the scrim (one below top overlay) * * @remarks Position scrim behind the topmost overlay but above all others. */ scrimZIndex: Readonly>; /** * Whether the topmost overlay blocks scrim clicks * * @remarks When true, the topmost overlay has `blocking: true` * and scrim clicks should be ignored. */ isBlocking: Readonly>; /** * App-wide default teleport target, as set via `createStackPlugin({ default: … })`. * Portal reads this when no per-component `to` prop is given. */ default: Readonly | HTMLElement | undefined>>; /** * Element of the topmost selected modal overlay that has a resolvable DOM * element (a top-layer ``), or `null`. * * @remarks Overlays that must appear above a modal (snackbars, tooltips) * teleport into this element so they share its top-layer context and remain * interactive. Non-modal (`scrim: false`) tickets are never returned, so a * non-modal overlay never resolves to itself. * * **One-tick window.** When a modal mounts already-open (`modelValue=true`), * the ticket's `select()` fires synchronously in the `immediate: true` watch * before the content ref resolves, so `topElement` is `null` for one tick. * Consumers that read `topElement` reactively (e.g. `Portal` resolving its * teleport target) see the correct element on the next tick after the * modal's DOM node mounts. * * @example * ```ts * const to = toRef(() => stack.topElement.value ?? 'body') * ``` */ topElement: Readonly>; /** * Register an overlay ticket * * @param input Partial ticket data * @returns Stack ticket with z-index and top tracking * * @remarks When called within component setup, the ticket is automatically * unregistered when the component unmounts. */ register: (input?: Partial) => E; } interface StackOptions extends SelectionOptions { /** * Base z-index when stack is empty * * @default 2000 * @remarks First overlay receives this z-index. */ baseZIndex?: number; /** * Z-index increment between overlays * * @default 10 * @remarks Gap between overlay z-indexes allows room for * overlay-internal elements (dropdowns, tooltips within dialogs). */ increment?: number; /** * App-wide default teleport target for all Portals. * * @remarks When set, every Portal that has no explicit `to` prop inherits * this target. A per-component `to` prop always takes precedence. * `'top-layer'` resolves to the topmost open modal element (a ``), * falling back to `'body'` when no modal is active. * * @example * ```ts * app.use(createStackPlugin({ default: 'top-layer' })) * ``` */ default?: Extensible<'top-layer'> | HTMLElement; } interface StackContextOptions extends StackOptions { namespace?: string; } interface StackPluginOptions extends StackContextOptions { /** When true, this plugin appears in the Vue DevTools v0 inspector. @default false */ devtools?: boolean; } /** * Creates a new stack instance for managing overlay z-indexes. * * @param options Configuration options * @returns Stack context with registry methods and scrim helpers * * @see https://0.vuetifyjs.com/composables/plugins/use-stack * * @example * ```ts * import { createStack } from '@vuetify/v0' * * const stack = createStack({ baseZIndex: 1000 }) * * const ticket = stack.register({ * onDismiss: () => console.log('dismissed'), * blocking: false, * }) * * ticket.select() // Activate overlay * console.log(ticket.zIndex.value) // 1000 * * ticket.unselect() // Deactivate overlay * ``` */ declare function createStack(_options?: StackOptions): StackContext; /** * Creates a stack context trinity for provide/inject usage. * * @param options Configuration options including namespace * @returns Trinity of [useStackContext, provideStackContext, context] * * @see https://0.vuetifyjs.com/composables/plugins/use-stack * * @example * ```ts * import { createStackContext } from '@vuetify/v0' * * const [useMyStack, provideMyStack, myStack] = createStackContext({ * namespace: 'my:stack', * baseZIndex: 3000, * }) * * // In parent component: * provideMyStack() * * // In child component: * const stack = useMyStack() * ``` */ declare function createStackContext(_options?: StackContextOptions): ContextTrinity; /** * Creates a Vue plugin to provide stack context at app level. * * @param options Configuration options * @returns Vue plugin instance * * @see https://0.vuetifyjs.com/composables/plugins/use-stack * * @example * ```ts * import { createApp } from 'vue' * import { createStackPlugin } from '@vuetify/v0' * * const app = createApp(App) * app.use(createStackPlugin({ baseZIndex: 2000 })) * app.mount('#app') * ``` */ declare function createStackPlugin(_options?: StackPluginOptions): Plugin; /** * Returns the current stack context. * * @param namespace The namespace for the stack context. Defaults to 'v0:stack'. * @returns The stack context instance * * @remarks Falls back to an internal shared instance if no provider exists. * For SSR safety, use createStackPlugin to provide isolated context per app. * * Tickets registered within component setup are automatically unregistered * when the component is unmounted. * * @see https://0.vuetifyjs.com/composables/plugins/use-stack * * @example * ```vue * * * * ``` */ declare function useStack(namespace?: string): StackContext; //#endregion export { StackContext, StackContextOptions, StackOptions, StackPluginOptions, StackTicket, StackTicketInput, createStack, createStackContext, createStackPlugin, useStack };