import { ID } from "../../types/index.mjs"; import { ContextTrinity } from "../createTrinity/index.mjs"; import { RegistryContext, RegistryOptions, RegistryTicket, RegistryTicketInput } from "../createRegistry/index.mjs"; //#region src/composables/createQueue/index.d.ts /** * Input type for queue tickets - what users provide to register(). * Extend this interface to add custom properties. * * @template V The type of the ticket value. */ interface QueueTicketInput extends RegistryTicketInput { /** * Timeout in milliseconds * * @remarks * - If `undefined`: Uses the default timeout from queue options (default: 3000ms) * - If `-1`: Ticket persists indefinitely until manually dismissed * - If a number: Ticket will be automatically removed after the specified milliseconds */ timeout?: number; } /** * Output type for queue tickets - what users receive from get(). * Includes all input properties plus queue state and methods. * * @template Z The input ticket type that extends QueueTicketInput. */ type QueueTicket = RegistryTicket & Z & { /** * Timeout in milliseconds (resolved from input or default) */ timeout?: number; /** * Whether the timeout is currently paused * * @remarks * - Set to `true` when the ticket is not the first in the queue or when manually paused * - When `true`, the timeout does not progress * - Automatically managed by the queue system */ isPaused: boolean; /** * Convenience method to dismiss this ticket from the queue * * @remarks * Equivalent to calling `queue.unregister(ticket.id)` */ dismiss: () => void; }; /** * Context for managing queue collections with timeout support. * * @template Z The input ticket type. * @template E The output ticket type. */ interface QueueContext = QueueTicket> extends Omit, 'register' | 'unregister' | 'offboard'> { /** * Register a new ticket in the queue (accepts input type, returns output type) * * @param ticket The partial ticket data to register * @remarks * - If no ID is provided, a unique ID will be generated automatically * - If no timeout is provided, uses the default timeout from queue options (3000ms) * - First ticket in queue starts its timeout immediately * - Subsequent tickets are paused until they become first in queue * - Each ticket receives a `dismiss()` method for convenience * * @see https://0.vuetifyjs.com/composables/registration/create-queue * * @example * ```ts * import { useQueue } from '@vuetify/v0' * * const queue = useQueue() * * // Register with default timeout (3000ms) * const ticket1 = queue.register({ value: 'First' }) * * // Register with custom timeout * const ticket2 = queue.register({ value: 'Second', timeout: 5000 }) * * // Register persistent ticket (must be manually dismissed) * const ticket3 = queue.register({ value: 'Persistent', timeout: -1 }) * ``` */ register: (ticket?: Partial) => E; /** * Unregister a ticket from the queue * * @param id The ID of the ticket to unregister. If not provided, the first ticket in the queue will be unregistered. * @remarks * - Removes the ticket from the queue and clears its timeout * - If the removed ticket was first in queue, automatically resumes the next ticket * - Returns the unregistered ticket or `undefined` if not found * * @see https://0.vuetifyjs.com/composables/registration/create-queue * * @example * ```ts * import { useQueue } from '@vuetify/v0' * * const queue = useQueue() * * const ticket1 = queue.register({ value: 'First' }) * const ticket2 = queue.register({ value: 'Second' }) * * // Unregister specific ticket * queue.unregister(ticket2.id) * * // Unregister first ticket in queue * const removed = queue.unregister() * console.log(removed?.value) // 'First' * ``` */ unregister: (id?: ID) => E | undefined; /** * Pause the timeout of the first ticket in the queue * * @remarks * - Pauses the timeout for the first ticket if it exists and is not already paused * - Returns the paused ticket or `undefined` if no pausable ticket exists * - The timeout will not progress while paused * * @see https://0.vuetifyjs.com/composables/registration/create-queue * * @example * ```ts * import { useQueue } from '@vuetify/v0' * * const queue = useQueue({ timeout: 5000 }) * * const ticket = queue.register({ value: 'Pausable ticket' }) * * // Pause the first ticket's timeout * const paused = queue.pause() * * console.log(paused?.isPaused) // true * ``` */ pause: () => E | undefined; /** * Resume the timeout of the first paused ticket in the queue * * @remarks * - Resumes the timeout for the first ticket if it exists, is at index 0, and is currently paused * - Returns the resumed ticket or `undefined` if no resumable ticket exists * - The timeout will continue from its full duration (not from where it was paused) * * @see https://0.vuetifyjs.com/composables/registration/create-queue * * @example * ```ts * import { useQueue } from '@vuetify/v0' * * const queue = useQueue({ timeout: 5000 }) * * const ticket = queue.register({ value: 'Ticket' }) * queue.pause() * * // Later, resume the paused ticket * const resumed = queue.resume() * * console.log(resumed?.isPaused) // false * ``` */ resume: () => E | undefined; /** * Clear the entire queue * * @remarks * - Removes all tickets from the queue * - Clears all active timeouts * - Resets the queue to an empty state * * @see https://0.vuetifyjs.com/composables/registration/create-queue * * @example * ```ts * import { useQueue } from '@vuetify/v0' * * const queue = useQueue() * * queue.register({ value: 'First' }) * queue.register({ value: 'Second' }) * * console.log(queue.size) // 2 * * queue.clear() * * console.log(queue.size) // 0 * ``` */ clear: () => void; /** * Dispose of the queue and clean up resources * * @remarks * - Clears all tickets and timeouts * - Removes all event listeners * - Should be called when the queue is no longer needed * - Automatically called on scope disposal * * @see https://0.vuetifyjs.com/composables/registration/create-queue * * @example * ```ts * import { onScopeDispose } from 'vue' * import { useQueue } from '@vuetify/v0' * * const queue = useQueue() * * queue.register({ value: 'Ticket' }) * * onScopeDispose(() => { * queue.dispose() * }) * ``` */ dispose: () => void; /** * Batch unregister tickets from the queue */ offboard: (ids: ID[]) => void; } interface QueueOptions extends RegistryOptions { /** * Default timeout in milliseconds for tickets without explicit timeout * * @default 3000 * @remarks * - Applied to tickets that don't specify their own timeout * - Can be overridden per ticket during registration */ timeout?: number; } interface QueueContextOptions extends QueueOptions { namespace?: string; } /** * Creates a new queue instance * * @param options The options for the queue instance * @returns A new queue instance * * @see https://0.vuetifyjs.com/composables/registration/create-queue * * @example * ```ts * import { createQueue } from '@vuetify/v0' * * const queue = createQueue() * * // Register an ticket with default timeout (3000ms) * const ticket1 = queue.register({ value: 'Ticket 1' }) * * // Register an ticket with custom timeout * const ticket2 = queue.register({ value: 'Ticket 2', timeout: 5000 }) * * // Register a persistent ticket that must be manually dismissed * const ticket3 = queue.register({ value: 'Ticket 3', timeout: -1 }) * * // Dismiss an ticket using the convenience method * ticket3.dismiss() * * console.log(queue.size) // 2 * ``` */ declare function createQueue(_options?: QueueOptions): QueueContext; /** * Creates a new queue context. * * @param options The options for the queue context. * @returns A new queue context. * * @see https://0.vuetifyjs.com/composables/registration/create-queue * * @example * ```ts * import { createQueueContext } from '@vuetify/v0' * * export const [useQueue, provideQueue, context] = createQueueContext({ * timeout: 5000, * }) * ``` */ declare function createQueueContext(_options?: QueueContextOptions): ContextTrinity; /** * Returns the current queue instance. * * @param namespace The namespace for the queue context. Defaults to `'v0:queue'`. * @returns The current queue instance. * * @see https://0.vuetifyjs.com/composables/registration/create-queue * * @example * ```vue * * ``` */ declare function useQueue(namespace?: string): QueueContext; //#endregion export { QueueContext, QueueContextOptions, QueueOptions, QueueTicket, QueueTicketInput, createQueue, createQueueContext, useQueue };