import { ID } from "../../types/index.mjs"; import { SortableContext, SortableOptions, SortableTicket, SortableTicketInput } from "../createSortable/index.mjs"; import { MaybeRefOrGetter } from "vue"; //#region src/composables/createKanban/index.d.ts /** * Options accepted by `createKanban`. * * @example * ```ts * import { createKanban } from '@vuetify/v0' * import { shallowRef, toRef } from 'vue' * * const isReadOnly = shallowRef(false) * const kanban = createKanban({ disabled: toRef(() => isReadOnly.value) }) * ``` */ interface KanbanOptions extends Omit { /** * Mutation gate. When truthy, `transfer` and column-level mutations no-op. * * @default false */ disabled?: MaybeRefOrGetter; } /** * Input shape for a column ticket. Parameterized over the per-column inner * ticket type so `accept` is typed against the caller's domain. * * @template ItemZ The inner ticket input type (extends `SortableTicketInput`). * @template V The column's own value type. * * @example * ```ts * import type { KanbanColumnTicketInput, SortableTicketInput } from '@vuetify/v0' * * interface CardTicket extends SortableTicketInput { * value: { title: string } * } * * interface BoardColumn extends KanbanColumnTicketInput { * value: { title: string; color: string } * } * ``` */ interface KanbanColumnTicketInput extends SortableTicketInput { /** * Per-column mutation gate. When truthy, transfers into and out of this * column are blocked, and the column's inner `items` sortable is disabled * (move / swap / reorder no-op). Column-level operations on * `kanban.columns` are unaffected — those are gated by the kanban-level * `disabled`. * * @default false */ disabled?: MaybeRefOrGetter; /** * Predicate veto for incoming transfers. Synchronous boolean return: * `true` accepts; `false` rejects (silent no-op). Async predicates are * rejected at runtime with a warning. * * @param ticket The item being transferred (from the source column). * @param from The source column id. * @param toIndex The target index inside this destination column. * * @example * ```ts * const review = kanban.columns.register({ * value: { title: 'Review' }, * accept: (ticket, from) => from !== archiveColumn.id, * }) * ``` */ accept?: (ticket: SortableTicket, from: ID, toIndex: number) => boolean; } /** * Output ticket returned from `kanban.columns.register`. Extends `SortableTicket` * with the column's own inner sortable on `items`. * * @template ItemZ Inner ticket input type. * @template Z Column input type. * * @example * ```ts * import { createKanban } from '@vuetify/v0' * * const kanban = createKanban() * const todo = kanban.columns.register({ value: { title: 'Todo' } }) * todo.items.register({ value: { title: 'Write spec' } }) * console.log(todo.id, todo.value.title, todo.items.size) * ``` */ type KanbanColumnTicket = KanbanColumnTicketInput> = SortableTicket & { items: SortableContext; }; /** * Payload of the `transfer:ticket` event on the kanban bus. * * @example * ```ts * import { createKanban } from '@vuetify/v0' * * const kanban = createKanban() * * kanban.on('transfer:ticket', ({ ticket, from, to, toIndex }) => { * console.log(ticket.id, from, '→', to, '@', toIndex) * }) * ``` */ interface KanbanTransferPayload { ticket: SortableTicket; from: ID; to: ID; fromIndex: number; toIndex: number; } /** * Listener signature for the kanban-level `transfer:ticket` event. Registry * events (`register:ticket`, `unregister:ticket`, etc.) live on the columns * registry — subscribe via `kanban.columns.on(...)` rather than `kanban.on(...)`. * * @example * ```ts * import { createKanban } from '@vuetify/v0' * * const kanban = createKanban() * * kanban.on('transfer:ticket', ({ ticket, from, to, toIndex }) => { * console.log(ticket.id, from, '→', to, '@', toIndex) * }) * ``` */ type KanbanEventListener = (event: 'transfer:ticket', cb: (data: KanbanTransferPayload) => void) => void; /** * Public context returned by `createKanban`. * * @example * ```ts * import { createKanban } from '@vuetify/v0' * import type { KanbanColumnTicketInput, SortableTicketInput } from '@vuetify/v0' * * interface CardTicket extends SortableTicketInput { * value: { title: string } * } * * interface BoardColumn extends KanbanColumnTicketInput { * value: { title: string } * } * * const kanban = createKanban() * * const [todo, done] = kanban.columns.onboard([ * { value: { title: 'Todo' } }, * { value: { title: 'Done' } }, * ]) * * const card = todo.items.register({ value: { title: 'Write spec' } }) * * kanban.on('transfer:ticket', ({ ticket, from, to, toIndex }) => { * console.log(`${ticket.id}: ${from} → ${to} @ ${toIndex}`) * }) * * kanban.transfer(card.id, done.id, 0) * ``` */ interface KanbanContext = KanbanColumnTicketInput> { /** * Column registry. Use this for column register / unregister / move / swap / reorder. * * @remarks * Unregistering a column disposes its `items` sortable — all of the column's * tickets are dropped and any subscribers attached to `column.items` are * cleared. The internal cleanup runs before consumer-registered * `unregister:ticket` handlers, so you cannot rescue items from inside that * callback. To preserve items, move them before calling `unregister`. * * `columns.dispose` is the board cascade — the same function as * `kanban.dispose()` — not a columns-only wipe. * * @example * ```ts * import { createKanban } from '@vuetify/v0' * * const kanban = createKanban() * const todo = kanban.columns.register({ value: { title: 'Todo' } }) * todo.items.register({ value: { title: 'Write spec' } }) * kanban.columns.move(todo.id, 1) * ``` * * @example * ```ts * // Reflow items into a fallback column before disposing the source column. * for (const item of todo.items.values()) { * trash.items.register({ id: item.id, value: item.value }) * } * todo.unregister() * ``` */ columns: SortableContext>; /** * Move an item across columns. Same-column transfer (where `toColumnId` * matches the item's current column) collapses to `column.items.move` and * does not emit `transfer:ticket`. * * Returns the moved ticket, or `undefined` when gated (kanban / source / destination / * item disabled, destination.accept rejected, unknown id, duplicate destination id). * * @example * ```ts * import { createKanban } from '@vuetify/v0' * * const kanban = createKanban() * const [todo, done] = kanban.columns.onboard([{ value: 'Todo' }, { value: 'Done' }]) * const card = todo.items.register({ value: 'Write spec' }) * * const moved = kanban.transfer(card.id, done.id, 0) * if (moved) console.log('landed at', moved.index) * * // Returns undefined when gated by disabled, accept, or unknown ids: * kanban.transfer(card.id, 'no-such-column', 0) // → undefined * ``` */ transfer: (id: ID, toColumnId: ID, toIndex: number) => SortableTicket | undefined; /** * Subscribe to the kanban-level `transfer:ticket` event, fired after each * successful cross-column move. Registry events (`register:ticket`, * `unregister:ticket`, `move:ticket`) live on the columns registry — use * `kanban.columns.on(...)` for those, or `column.items.on(...)` for * per-column intra-column reorder events. * * @example * ```ts * import { createKanban } from '@vuetify/v0' * * const kanban = createKanban() * * kanban.on('transfer:ticket', ({ ticket, from, to, fromIndex, toIndex }) => { * console.log(ticket.id, from, '→', to, '@', toIndex) * }) * ``` */ on: KanbanEventListener; /** * Unsubscribe from the `transfer:ticket` event. Must be called with the same * callback reference used to subscribe. * * @example * ```ts * import { createKanban } from '@vuetify/v0' * import type { KanbanTransferPayload } from '@vuetify/v0' * * const kanban = createKanban() * * function onTransfer (data: KanbanTransferPayload) { * console.log(data.ticket.id) * } * * kanban.on('transfer:ticket', onTransfer) * // later * kanban.off('transfer:ticket', onTransfer) * ``` */ off: KanbanEventListener; /** * Tear down the entire board: every column's inner `items` sortable, the * internal id → column lookup, the `transfer:ticket` event bus, and the * columns registry itself. `kanban.columns.dispose` is the same function. * Repeatable — a later call after `columns.register` tears down the rebuilt * board the same way. * * @remarks * Registry `dispose()` runs `clear()`, which never emits `unregister:ticket`, * so the per-column cleanup subscribed on that event would not run. This * method walks current columns and disposes each inner sortable first, then * re-binds that cleanup so a rebuilt board still cascades on column * unregister. * * @example * ```ts * import { createKanban } from '@vuetify/v0' * * const kanban = createKanban() * kanban.columns.register({ value: { title: 'Todo' } }) * // later * kanban.dispose() * ``` */ dispose: () => void; } /** * Create a headless two-level sortable orchestrator. * * @param options Kanban options (currently only `disabled`). * @returns A {@link KanbanContext}. * * @example * ```ts * import { createKanban } from '@vuetify/v0' * import type { KanbanColumnTicketInput, SortableTicketInput } from '@vuetify/v0' * * interface CardTicket extends SortableTicketInput { * value: { title: string } * } * * interface BoardColumn extends KanbanColumnTicketInput { * value: { title: string } * } * * const kanban = createKanban() * * const todo = kanban.columns.register({ value: { title: 'Todo' } }) * const review = kanban.columns.register({ * value: { title: 'Review' }, * accept: card => card.value.title.length > 0, * }) * * const spec = todo.items.register({ value: { title: 'Write spec' } }) * kanban.transfer(spec.id, review.id, 0) * ``` */ declare function createKanban = KanbanColumnTicketInput>(_options?: KanbanOptions): KanbanContext; //#endregion export { KanbanColumnTicket, KanbanColumnTicketInput, KanbanContext, KanbanEventListener, KanbanOptions, KanbanTransferPayload, createKanban };