import { ID } from "../../types/index.mjs"; import { ContextTrinity } from "../createTrinity/index.mjs"; import { SelectionContext, SelectionContextOptions, SelectionOptions, SelectionTicket, SelectionTicketInput } from "../createSelection/index.mjs"; import { ComputedRef, MaybeRefOrGetter, Reactive, Ref } from "vue"; //#region src/composables/createGroup/index.d.ts /** * Input type for group tickets. * Extend this interface to add custom properties. */ interface GroupTicketInput extends SelectionTicketInput { /** Whether the ticket should start in mixed/indeterminate state */ indeterminate?: MaybeRefOrGetter; } /** * Output type for group tickets. * Includes all input properties plus selection and tri-state methods. */ type GroupTicket = SelectionTicket & { /** Whether the ticket is in a mixed/indeterminate state */ isMixed: Readonly>; /** Set self to mixed/indeterminate state */ mix: () => void; /** Clear mixed/indeterminate state from self */ unmix: () => void; }; /** * Context returned by createGroup. * * @template Z The input ticket type. * @template E The output ticket type. */ interface GroupContext = GroupTicket> extends Omit, 'register' | 'onboard' | 'select' | 'unselect' | 'toggle'> { selectedIndexes: ComputedRef>; /** Select one or more Tickets by ID */ select: (ids: ID | ID[]) => void; /** Unselect one or more Tickets by ID */ unselect: (ids: ID | ID[]) => void; /** Toggle one or more Tickets ON and OFF by ID */ toggle: (ids: ID | ID[]) => void; /** Set of mixed/indeterminate ticket IDs */ mixedIds: Reactive>; /** Set of mixed/indeterminate ticket instances */ mixedItems: ComputedRef>; /** Set one or more Tickets to mixed/indeterminate state by ID */ mix: (ids: ID | ID[]) => void; /** Clear mixed/indeterminate state from one or more Tickets by ID */ unmix: (ids: ID | ID[]) => void; /** Check if a ticket is in mixed/indeterminate state by ID */ mixed: (id: ID) => boolean; /** Whether no items are currently selected */ isNoneSelected: Readonly>; /** Whether all selectable (non-disabled) items are selected */ isAllSelected: ComputedRef; /** Whether some but not all selectable items are selected */ isMixed: ComputedRef; /** Select all selectable (non-disabled) items */ selectAll: () => void; /** Unselect all items (respects mandatory option) */ unselectAll: () => void; /** Toggle between all selected and none selected */ toggleAll: () => void; /** Register a new ticket (accepts input type, returns output type) */ register: (ticket?: Partial) => E; /** Onboard multiple tickets at once */ onboard: (registrations: Partial[]) => E[]; } interface GroupOptions extends SelectionOptions {} interface GroupContextOptions extends SelectionContextOptions {} /** * Creates a new group instance with batch selection and tri-state support. * * Extends `createSelection` to support selecting, unselecting, and toggling multiple items * at once by passing an array of IDs. Adds tri-state (mixed/indeterminate) support for * checkbox trees and similar use cases. * * @param options The options for the group instance. * @template Z The type of the group ticket. * @template E The type of the group context. * @returns A new group instance with batch selection and tri-state support. * * @remarks * **Key Differences from `createSelection`:** * - `select()` accepts `ID | ID[]` for batch operations * - `unselect()` accepts `ID | ID[]` for batch operations * - `toggle()` accepts `ID | ID[]` for batch operations * - Adds `selectedIndexes` computed Set for getting selected item indexes * - Adds tri-state support via `mix()`, `unmix()`, `mixed()`, `mixedIds`, `mixedItems` * - Perfect for checkbox trees, multi-select dropdowns, and bulk operations * * **Tri-State Support:** * - Items can be in one of three states: selected, mixed (indeterminate), or unselected * - `mix(id)` sets item to mixed state (clears selected if set) * - `unmix(id)` clears mixed state * - `select(id)` clears mixed state before selecting * - `toggle(id)` on a mixed item selects it (resolves the indeterminate state positively) * - Mixed state works on disabled items (it's a computed state, not user action) * * **Batch Operations:** * - Single ID: `group.select('item-1')` * - Array of IDs: `group.select(['item-1', 'item-2', 'item-3'])` * - Uses `toArray()` utility internally to normalize input * - Disabled items are automatically skipped in select operations * - Non-existent IDs are silently ignored * * **Inheritance Chain:** * `createRegistry` → `createSelection` → `createGroup` * * **Used By:** * - `createFeatures` for feature flag management with multiple selections * * @see https://0.vuetifyjs.com/composables/selection/create-group * * @example * ```ts * import { createGroup } from '@vuetify/v0' * * const checkboxes = createGroup() * * checkboxes.onboard([ * { id: 'option-a', value: 'Option A' }, * { id: 'option-b', value: 'Option B' }, * { id: 'option-c', value: 'Option C' }, * ]) * * // Select multiple items at once * checkboxes.select(['option-a', 'option-c']) * * console.log(checkboxes.selectedIds) // Set { 'option-a', 'option-c' } * console.log(Array.from(checkboxes.selectedIndexes.value)) // [0, 2] * * // Set item to mixed/indeterminate state * checkboxes.mix('option-a') * console.log(checkboxes.mixedIds) // Set { 'option-a' } * console.log(checkboxes.selectedIds) // Set { 'option-c' } (option-a removed) * * // Toggle a mixed item selects it * checkboxes.toggle('option-a') * console.log(checkboxes.selectedIds) // Set { 'option-a', 'option-c' } * console.log(checkboxes.mixedIds) // Set {} (cleared) * ``` */ declare function createGroup = GroupTicket, R extends GroupContext = GroupContext>(_options?: GroupOptions): R; /** * Creates a new group context. * * @param options The options for the group context. * @template Z The input ticket type. * @template E The output ticket type. * @template R The context type. * @returns A new group context. * * @see https://0.vuetifyjs.com/composables/selection/create-group * * @example * ```ts * import { createGroupContext } from '@vuetify/v0' * * // With default namespace 'v0:group' * export const [useMyGroup, provideMyGroup, myGroup] = createGroupContext() * * // Or with custom namespace * export const [useMyGroup, provideMyGroup, myGroup] = createGroupContext({ namespace: 'my-group' }) * * // In a parent component: * provideMyGroup() * * // In a child component: * const group = useMyGroup() * ``` */ declare function createGroupContext = GroupTicket, R extends GroupContext = GroupContext>(_options?: GroupContextOptions): ContextTrinity; /** * Returns the current group instance. * * @param namespace The namespace for the group context. Defaults to `'v0:group'`. * @template Z The input ticket type. * @template E The output ticket type. * @template R The context type. * @returns The current group instance. * * @see https://0.vuetifyjs.com/composables/selection/create-group * * @example * ```vue * * * * ``` */ declare function useGroup = GroupTicket, R extends GroupContext = GroupContext>(namespace?: string): R; //#endregion export { GroupContext, GroupContextOptions, GroupOptions, GroupTicket, GroupTicketInput, createGroup, createGroupContext, useGroup };