import { ContextTrinity } from "../createTrinity/index.mjs"; import { ModelContext, ModelOptions, ModelTicket, ModelTicketInput } from "../createModel/index.mjs"; import { MaybeRefOrGetter } from "vue"; //#region src/composables/createSelection/index.d.ts /** * Input type for selection tickets - what users provide to register(). * Custom ticket types should extend this interface. * * @template V The type of the ticket value. * * @example * ```ts * interface MyTicket extends SelectionTicketInput { * label: string * disabled?: boolean * metadata?: Record * } * * const selection = createSelection() * selection.register({ label: 'Item 1' }) * ``` */ interface SelectionTicketInput extends ModelTicketInput {} /** * Output type for selection tickets - what users receive from get(). * Includes registry-added methods for self-selection. * * @template Z The input ticket type that extends SelectionTicketInput. * * @remarks * The following properties are automatically added by the registry: * - `disabled` - Defaults to `false` if not provided * - `isSelected` - Reactive boolean indicating selection state * - `select()` - Method to select this ticket * - `unselect()` - Method to unselect this ticket * - `toggle()` - Method to toggle selection state */ type SelectionTicket = ModelTicket & { /** Select self */ select: () => void; /** Unselect self */ unselect: () => void; /** Toggle self on and off */ toggle: () => void; }; /** * Context returned by createSelection. * * @template Z The input ticket type (what users provide to register). * @template E The output ticket type (what users receive from get). Defaults to SelectionTicket. */ interface SelectionContext = SelectionTicket> extends Omit, 'register'> { /** Whether the selection allows multiple selections */ multiple: MaybeRefOrGetter; /** Register a new ticket (accepts input type, returns output type) */ register: (ticket?: Partial) => E; /** Onboard multiple tickets at once */ onboard: (registrations: Partial[]) => E[]; /** Mandate selected ID based on "mandatory" option */ mandate: () => void; /** Seek for the first/last non-disabled ticket */ seek: (direction?: 'first' | 'last', from?: number) => E | undefined; } interface SelectionOptions extends ModelOptions { /** * Controls mandatory selection behavior: * - `false` (default): No mandatory selection enforcement * - `true`: Prevents deselecting the last selected item * - `'force'`: Automatically selects the first non-disabled item on registration */ mandatory?: MaybeRefOrGetter; /** When true, treats the selection as an array */ multiple?: MaybeRefOrGetter; /** * Auto-select tickets on registration * * @default false * @remarks Overrides createModel's default of `true`. When truthy, newly registered * items are automatically selected if not disabled. Respects `multiple` mode. */ enroll?: MaybeRefOrGetter; } interface SelectionContextOptions extends SelectionOptions { namespace?: string; } /** * Creates a new selection instance for managing multiple selected items. * * Extends `createModel` with multi-select, mandatory enforcement, * auto-enrollment, and ticket self-methods. * Supports disabled items, mandatory selection enforcement, and auto-enrollment. * * @param options The options for the selection instance. * @template Z The input ticket type - what users provide to register(). Extend SelectionTicketInput to add custom properties. * @template E The output ticket type - what users receive from get(). Automatically includes selection methods. * @template R The context type. Defaults to SelectionContext. * @returns A new selection instance with selection management methods. * * @remarks * **Key Features:** * - Multi-selection support (unlike `createSingle` which enforces single selection) * - Set-based `selectedIds` tracking for efficient lookups * - Computed `selectedItems` and `selectedValues` for reactive access * - Each ticket gets `isSelected`, `select()`, `unselect()`, and `toggle()` methods * - Disabled items cannot be selected * - Mandatory mode prevents deselecting the last item * - Force mode auto-selects first non-disabled item on registration * - Enroll option auto-selects all non-disabled items on registration * * **Inheritance Chain:** * `createRegistry` → `createModel` → `createSelection` → `createSingle`/`createGroup` → `createStep` * * @see https://0.vuetifyjs.com/composables/selection/create-selection * * @example * ```ts * import { createSelection } from '@vuetify/v0' * * // Basic usage * const selection = createSelection({ mandatory: true }) * * selection.onboard([ * { id: 'item-1', value: 'Item 1' }, * { id: 'item-2', value: 'Item 2', disabled: true }, * { id: 'item-3', value: 'Item 3' }, * ]) * * selection.select('item-1') * selection.select('item-3') * * console.log(selection.selectedIds) // Set { 'item-1', 'item-3' } * console.log(Array.from(selection.selectedValues.value)) // ['Item 1', 'Item 3'] * ``` * * @example * ```ts * // With custom ticket type * interface MyTicket extends SelectionTicketInput { * label: string * icon?: string * } * * const tabs = createSelection() * * tabs.register({ label: 'Home', icon: 'mdi-home' }) * tabs.register({ label: 'Settings' }) * * const ticket = tabs.get('...') * // ticket has: label, icon, isSelected, select(), unselect(), toggle() * ``` */ declare function createSelection = SelectionTicket, R extends SelectionContext = SelectionContext>(_options?: SelectionOptions): R; /** * Creates a new selection context. * * @param options The options for the selection context. * @template Z The input ticket type - what users provide to register(). * @template E The output ticket type - what users receive from get(). * @template R The context type. Defaults to SelectionContext. * @returns A new selection context. * * @see https://0.vuetifyjs.com/composables/selection/create-selection * * @example * ```ts * import { createSelectionContext } from '@vuetify/v0' * * // With default namespace 'v0:selection' * export const [useCheckboxes, provideCheckboxes, checkboxes] = createSelectionContext() * * // Or with custom namespace * export const [useCheckboxes, provideCheckboxes, checkboxes] = createSelectionContext({ namespace: 'checkboxes' }) * * // In a parent component: * provideCheckboxes() * * // In a child component: * const checkboxes = useCheckboxes() * checkboxes.select('checkbox-1') * ``` * * @example * ```ts * // With custom ticket type * interface TabTicket extends SelectionTicketInput { * label: string * icon?: string * } * * export const [useTabs, provideTabs, tabs] = createSelectionContext() * ``` */ declare function createSelectionContext = SelectionTicket, R extends SelectionContext = SelectionContext>(_options?: SelectionContextOptions): ContextTrinity; /** * Returns the current selection instance. * * @param namespace The namespace for the selection context. Defaults to `'v0:selection'`. * @template Z The input ticket type. * @template E The output ticket type. * @template R The context type. * @returns The current selection instance. * * @see https://0.vuetifyjs.com/composables/selection/create-selection * * @example * ```vue * * * * ``` */ declare function useSelection = SelectionTicket, R extends SelectionContext = SelectionContext>(namespace?: string): R; //#endregion export { SelectionContext, SelectionContextOptions, SelectionOptions, SelectionTicket, SelectionTicketInput, createSelection, createSelectionContext, useSelection };