@vielzeug/dnd 2.2.0 → 26.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +5 -21
  2. package/dist/_dev.cjs +1 -1
  3. package/dist/_dev.cjs.map +1 -1
  4. package/dist/_dev.js +1 -5
  5. package/dist/_dev.js.map +1 -1
  6. package/dist/_shared.cjs +1 -1
  7. package/dist/_shared.cjs.map +1 -1
  8. package/dist/_shared.d.ts +1 -1
  9. package/dist/_shared.d.ts.map +1 -1
  10. package/dist/_shared.js +1 -22
  11. package/dist/_shared.js.map +1 -1
  12. package/dist/_touch.cjs +1 -1
  13. package/dist/_touch.cjs.map +1 -1
  14. package/dist/_touch.d.ts +8 -3
  15. package/dist/_touch.d.ts.map +1 -1
  16. package/dist/_touch.js +1 -167
  17. package/dist/_touch.js.map +1 -1
  18. package/dist/dnd.cjs +1 -1
  19. package/dist/dnd.cjs.map +1 -1
  20. package/dist/dnd.iife.js +1 -1
  21. package/dist/dnd.iife.js.map +1 -1
  22. package/dist/dnd.js +1 -1
  23. package/dist/dnd.js.map +1 -1
  24. package/dist/drop-zone.cjs +1 -1
  25. package/dist/drop-zone.cjs.map +1 -1
  26. package/dist/drop-zone.d.ts +4 -4
  27. package/dist/drop-zone.d.ts.map +1 -1
  28. package/dist/drop-zone.js +1 -97
  29. package/dist/drop-zone.js.map +1 -1
  30. package/dist/drop.cjs +1 -0
  31. package/dist/drop.d.ts +4 -0
  32. package/dist/drop.d.ts.map +1 -0
  33. package/dist/drop.js +1 -0
  34. package/dist/errors.cjs +1 -1
  35. package/dist/errors.cjs.map +1 -1
  36. package/dist/errors.d.ts +1 -1
  37. package/dist/errors.d.ts.map +1 -1
  38. package/dist/errors.js +1 -13
  39. package/dist/errors.js.map +1 -1
  40. package/dist/index.cjs +1 -1
  41. package/dist/index.d.ts +4 -4
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +1 -4
  44. package/dist/sortable.cjs +1 -1
  45. package/dist/sortable.cjs.map +1 -1
  46. package/dist/sortable.d.ts +40 -66
  47. package/dist/sortable.d.ts.map +1 -1
  48. package/dist/sortable.js +1 -353
  49. package/dist/sortable.js.map +1 -1
  50. package/package.json +34 -9
@@ -1 +1 @@
1
- {"version":3,"file":"sortable.cjs","names":[],"sources":["../src/sortable.ts"],"sourcesContent":["import { warn } from './_dev';\nimport { createDisposable, resolveDisabled } from './_shared';\nimport { createScopeTouchController, type ScopeTouchController, type TouchInputOptions } from './_touch';\nimport { DndScopeError } from './errors';\nimport type { Disposable } from './types';\n\n// ─── Branded scope ────────────────────────────────────────────────────────────\n\nconst SCOPE_BRAND = Symbol('SortableScope');\n\nexport interface SortableScope extends Disposable {\n /** `true` while any sortable in this scope is actively dragging. */\n readonly isDragging: boolean;\n /**\n * Calls the revert function registered for the most recent cross-container move.\n * A no-op when no move registered a revert function.\n */\n revert(): void;\n readonly [SCOPE_BRAND]: true;\n}\n\n// ─── Types ────────────────────────────────────────────────────────────────────\n\nexport interface AutoScrollOptions {\n /** Scroll the sortable container while dragging near its edges. @default true */\n container?: boolean;\n /** Distance in pixels from an edge that triggers auto-scroll. @default 32 */\n edgeThreshold?: number;\n /** Pixels scrolled per dragover frame while near an edge. @default 18 */\n speed?: number;\n /** Scroll the viewport while dragging near the window edges. @default false */\n viewport?: boolean;\n}\n\n/**\n * Passed to `onReorder` after every successful reorder (drag or keyboard).\n */\nexport interface ReorderEvent {\n /** The new ordered list of item keys after the reorder. */\n ids: string[];\n /**\n * Register a revert function that will be called when `sortable.revert()` is invoked.\n * Useful for rolling back optimistic UI updates on server error.\n * Only the most recent `setRevert` registration is retained — a new reorder overwrites it.\n *\n * @example\n * ```ts\n * onReorder: ({ ids, setRevert }) => {\n * const prev = order;\n * setOrder(ids);\n * setRevert(() => setOrder(prev));\n * },\n * ```\n */\n setRevert(fn: () => void): void;\n}\n\n/** A single committed move between two containers in the same sortable scope. */\nexport interface SortableMoveEvent {\n /** Stable identity of the moved item. */\n readonly itemId: string;\n /** Registers a rollback for the most recent scope move. */\n setRevert(fn: () => void): void;\n /** Source container before the move. */\n readonly source: HTMLElement;\n /** Ordered source item IDs after the move. */\n readonly sourceIds: string[];\n /** Target container after the move. */\n readonly target: HTMLElement;\n /** Ordered target item IDs after the move. */\n readonly targetIds: string[];\n}\n\n/**\n * Structured accessibility/observability event for sortable interactions.\n *\n * Drag: `pickup` on dragstart, `drop` on commit, `cancel` on cancel.\n * Keyboard: `move` on each successful arrow/Home/End reorder (direct-commit model).\n *\n * Wire a consumer-side announcer to provide screen-reader feedback:\n * ```ts\n * createSortable({\n * onInteraction(event) {\n * announce(formatSortableEvent(event));\n * },\n * });\n * ```\n */\nexport type SortableInteractionEvent =\n | { readonly index: number; readonly itemId: string; readonly total: number; readonly type: 'pickup' }\n | {\n readonly index: number;\n readonly itemId: string;\n readonly previousIndex: number;\n readonly total: number;\n readonly type: 'move';\n }\n | { readonly index: number; readonly itemId: string; readonly total: number; readonly type: 'drop' }\n | { readonly index: number; readonly itemId: string; readonly total: number; readonly type: 'cancel' };\n\nexport interface SortableScopeOptions {\n /**\n * Called exactly once for every successful cross-container move.\n * Local reorders continue to use each sortable's `onReorder` callback.\n */\n onMove?: (event: SortableMoveEvent) => void;\n /**\n * Enables touch input for sortable items registered to this scope.\n * The controller ignores unrelated document draggables.\n */\n touch?: boolean | TouchInputOptions;\n}\n\nexport type SortableTouchOptions = TouchInputOptions;\n\nexport interface SortableOptions {\n /** Auto-scrolls the container (and viewport) near edges while dragging. @default true */\n autoScroll?: boolean | AutoScrollOptions;\n /** Sorting axis used to compute insertion position. @default 'vertical' */\n axis?: 'vertical' | 'horizontal';\n /**\n * When `true`, drag interactions are ignored.\n *\n * Note: if `disabled` transitions to `true` while a drag is in progress the\n * drag is treated as a cancellation — the item snaps back to its original\n * position rather than committing the last placeholder location.\n */\n disabled?: boolean;\n /** Optional custom drag preview element. */\n dragImage?: HTMLElement | ((id: string, item: HTMLElement, event: DragEvent) => HTMLElement | null | undefined);\n /**\n * Hotspot offset `[x, y]` passed to `setDragImage`.\n * Controls which point of the preview image follows the cursor.\n * @default [0, 0]\n */\n dragImageOffset?: [number, number];\n /** Container element whose direct-child items are sortable. */\n element: HTMLElement;\n /**\n * Returns the identity key for a given item element.\n * This separates the \"what is this item?\" concern (yours) from the \"which children\n * are sortable?\" concern (ours — marked with `data-dnd-item`).\n *\n * @example\n * ```ts\n * getKey: (el) => el.dataset.taskId!\n * ```\n */\n getKey: (element: HTMLElement) => string;\n /**\n * Selector for the drag handle inside each item.\n * When omitted the whole item is the handle.\n */\n handle?: string;\n /**\n * Enables keyboard-based reordering using arrow keys plus Home/End.\n * @default true\n */\n keyboard?: boolean;\n /**\n * Called just before a successful drag commit with the before and after order snapshots.\n * Use this hook to set up FLIP animations — the source items are still in their\n * pre-commit positions at the time of the call.\n *\n * @example\n * ```ts\n * onBeforeReorder: (from, to) => {\n * // record element positions here, then animate after the next microtask\n * }\n * ```\n */\n onBeforeReorder?: (from: string[], to: string[]) => void;\n /** Called when a drag ends (whether dropped or cancelled). */\n onDragEnd?: (id: string, event: DragEvent) => void;\n /** Called when the user starts dragging an item. */\n onDragStart?: (id: string, event: DragEvent) => void;\n /**\n * Structured accessibility event for pickup/move/drop/cancel — wire to a consumer-side\n * announcer for screen-reader feedback. See {@link SortableInteractionEvent}.\n */\n onInteraction?: (event: SortableInteractionEvent) => void;\n /**\n * Called with a {@link ReorderEvent} after a successful reorder, only when the order changed.\n *\n * @example\n * ```ts\n * onReorder: ({ ids, setRevert }) => {\n * const prev = order;\n * setOrder(ids);\n * setRevert(() => setOrder(prev));\n * },\n * ```\n */\n onReorder?: (event: ReorderEvent) => void;\n /** CSS class applied to the placeholder element. @default 'dnd-placeholder' */\n placeholderClass?: string;\n /** Shared scope for connected sortable containers. Containers only exchange items within the same scope. */\n scope?: SortableScope;\n}\n\nexport interface Sortable extends Disposable {\n readonly isDragging: boolean;\n /**\n * Calls the revert function registered via `setRevert` in the last `onReorder` invocation (if any) and clears it.\n * A no-op when no revert function was registered or has already been consumed.\n *\n * Works for both drag-based and keyboard-based reorders.\n * Note: only the most recent reorder can be reverted; a new reorder overwrites the stored function.\n *\n * @example\n * ```ts\n * onReorder: ({ ids, setRevert }) => {\n * const prev = order;\n * setOrder(ids);\n * setRevert(() => setOrder(prev));\n * },\n * // later, on server error:\n * sortable.revert();\n * ```\n */\n revert(): void;\n /**\n * Re-reads the container's children and reapplies `draggable`, ARIA roles,\n * and handle attributes. Call this after programmatically adding, removing,\n * or replacing items — e.g. after a framework render that replaces DOM nodes.\n *\n * Not needed when items are only reordered via drag or keyboard.\n */\n sync(): void;\n}\n\n// ─── Internal types ───────────────────────────────────────────────────────────\n\ninterface ResolvedAutoScrollOptions {\n container: boolean;\n edgeThreshold: number;\n speed: number;\n viewport: boolean;\n}\n\n/** Per-container closure passed into shared session functions. */\ninterface ContainerHandle {\n commitReorder: (orderedIds: string[]) => void;\n readonly element: HTMLElement;\n getOrderedIds: () => string[];\n isDisabled: () => boolean;\n notifyBeforeReorder: (from: string[], to: string[]) => void;\n notifyDragEnd: (id: string, event: DragEvent) => void;\n notifyDragStart: (id: string, event: DragEvent) => void;\n notifyInteraction: (event: SortableInteractionEvent) => void;\n resolveTouchTarget: (target: Element) => HTMLElement | null;\n}\n\n/**\n * Encapsulates all mutable state for a single in-progress drag operation.\n * Created at dragstart, destroyed on dragend/cancel.\n */\ninterface DragSession {\n draggedEl: HTMLElement;\n draggedId: string;\n /** rAF handle for the deferred element-hide; null once fired or cancelled. */\n hideFrame: number | null;\n /**\n * Order snapshots captured lazily: snapshot is taken the first time a handle\n * becomes the active target (and always for the source at drag start).\n */\n initialOrders: Map<ContainerHandle, string[]>;\n originalDisplay: string;\n originalNextSibling: ChildNode | null;\n originalParent: HTMLElement;\n placeholder: HTMLElement;\n source: ContainerHandle;\n target: ContainerHandle | null;\n}\n\ninterface SortableScopeState {\n active: DragSession | null;\n commitMove: (event: Omit<SortableMoveEvent, 'setRevert'>) => void;\n /** All sortables registered in this scope, kept for scope.dispose(). */\n disposables: Set<() => void>;\n handles: Set<ContainerHandle>;\n lastRevert: (() => void) | null;\n touch: ScopeTouchController | null;\n}\n\ninterface ManagedElementState {\n dataDndHandle: string | null;\n dataDndItem: string | null;\n draggable: string | null;\n role: string | null;\n tabIndex: string | null;\n touchAction: string;\n}\n\ninterface TouchDragEvent extends DragEvent {\n readonly __dndTouch?: boolean;\n readonly __dndTouchPreview?: boolean;\n}\n\n// ─── Internal constants ───────────────────────────────────────────────────────\n\nconst HANDLE_ATTR = 'data-dnd-handle';\nconst ITEM_ATTR = 'data-dnd-item';\nconst sortableScopeStates = new WeakMap<SortableScope, SortableScopeState>();\nconst DEFAULT_AUTO_SCROLL: ResolvedAutoScrollOptions = {\n container: true,\n edgeThreshold: 32,\n speed: 18,\n viewport: false,\n};\n\n// ─── Scope helpers ────────────────────────────────────────────────────────────\n\nfunction getSortableScopeState(scope: SortableScope): SortableScopeState {\n const state = sortableScopeStates.get(scope);\n\n if (!state) throw new DndScopeError();\n\n return state;\n}\n\n// ─── Option resolution ────────────────────────────────────────────────────────\n\nfunction resolveAutoScrollOptions(\n autoScroll: boolean | AutoScrollOptions | undefined,\n): ResolvedAutoScrollOptions | null {\n if (autoScroll === false) return null;\n\n if (autoScroll === true || autoScroll === undefined) return DEFAULT_AUTO_SCROLL;\n\n return {\n container: autoScroll.container ?? true,\n edgeThreshold: autoScroll.edgeThreshold ?? 32,\n speed: autoScroll.speed ?? 18,\n viewport: autoScroll.viewport ?? false,\n };\n}\n\n// ─── DOM helpers ──────────────────────────────────────────────────────────────\n\nfunction hasOrderChanged(before: string[], after: string[]): boolean {\n return after.length !== before.length || after.some((id, index) => id !== before[index]);\n}\n\nfunction isTouchDragEvent(event: DragEvent): event is TouchDragEvent {\n return (event as TouchDragEvent).__dndTouch === true;\n}\n\n// ─── Drag session helpers ─────────────────────────────────────────────────────\n\nfunction scheduleHide(session: DragSession): void {\n if (typeof requestAnimationFrame !== 'function') return;\n\n session.hideFrame = requestAnimationFrame(() => {\n session.hideFrame = null;\n session.draggedEl.style.display = 'none';\n });\n}\n\nfunction cancelHide(session: DragSession): void {\n if (session.hideFrame !== null) {\n cancelAnimationFrame(session.hideFrame);\n session.hideFrame = null;\n }\n}\n\nfunction restoreSessionElement(session: DragSession): void {\n cancelHide(session);\n session.draggedEl.style.display = session.originalDisplay;\n session.draggedEl.removeAttribute('data-dragging');\n}\n\n/**\n * Snapshot a handle's current order if not already recorded.\n * Called the first time a handle becomes an active target so we only capture\n * lists that actually participate in the drag.\n */\nfunction snapshotOrder(session: DragSession, handle: ContainerHandle): void {\n if (!session.initialOrders.has(handle)) {\n session.initialOrders.set(handle, handle.getOrderedIds());\n }\n}\n\n// ─── Session commit / cancel ──────────────────────────────────────────────────\n\nfunction cancelSession(scopeState: SortableScopeState, event: DragEvent): void {\n const session = scopeState.active;\n\n if (!session) return;\n\n restoreSessionElement(session);\n session.originalParent.insertBefore(session.draggedEl, session.originalNextSibling);\n session.placeholder.remove();\n scopeState.active = null;\n\n session.source.notifyDragEnd(session.draggedId, event);\n session.source.notifyInteraction({\n index: session.source.getOrderedIds().indexOf(session.draggedId),\n itemId: session.draggedId,\n total: session.source.getOrderedIds().length,\n type: 'cancel',\n });\n}\n\nfunction commitSession(scopeState: SortableScopeState, event: DragEvent): void {\n const session = scopeState.active;\n\n if (!session) return;\n\n const targetHandle = session.target;\n const targetElement = session.placeholder.parentElement;\n\n restoreSessionElement(session);\n\n if (targetHandle && scopeState.handles.has(targetHandle) && targetElement) {\n targetElement.insertBefore(session.draggedEl, session.placeholder);\n } else {\n session.originalParent.insertBefore(session.draggedEl, session.originalNextSibling);\n }\n\n session.placeholder.remove();\n scopeState.active = null;\n\n session.source.notifyDragEnd(session.draggedId, event);\n\n const changes: Array<{ after: string[]; before: string[]; handle: ContainerHandle }> = [];\n\n for (const [handle, before] of session.initialOrders) {\n if (!scopeState.handles.has(handle)) continue;\n\n const afterOrder = handle.getOrderedIds();\n\n if (hasOrderChanged(before, afterOrder)) {\n changes.push({ after: afterOrder, before, handle });\n }\n }\n\n for (const { after, before, handle } of changes) {\n handle.notifyBeforeReorder(before, after);\n }\n\n if (targetHandle && targetHandle !== session.source) {\n const sourceChange = changes.find((change) => change.handle === session.source);\n const targetChange = changes.find((change) => change.handle === targetHandle);\n\n if (sourceChange && targetChange) {\n scopeState.commitMove({\n itemId: session.draggedId,\n source: session.source.element,\n sourceIds: sourceChange.after,\n target: targetHandle.element,\n targetIds: targetChange.after,\n });\n\n const dropIndex = targetChange.after.indexOf(session.draggedId);\n const dropTotal = targetChange.after.length;\n\n // Emit from both source and target so a consumer wiring onInteraction on\n // either container receives the drop event.\n session.source.notifyInteraction({ index: dropIndex, itemId: session.draggedId, total: dropTotal, type: 'drop' });\n targetHandle.notifyInteraction({ index: dropIndex, itemId: session.draggedId, total: dropTotal, type: 'drop' });\n }\n\n return;\n }\n\n for (const { after, handle } of changes) {\n handle.commitReorder(after);\n }\n\n // Same-container — emit drop even when the order didn't change (user picked up\n // and dropped at the same position). The interaction completed; silence would\n // leave screen-reader users without confirmation.\n const sourceChange = changes.find((change) => change.handle === session.source);\n const finalOrder = sourceChange ? sourceChange.after : session.source.getOrderedIds();\n const finalIndex = finalOrder.indexOf(session.draggedId);\n\n session.source.notifyInteraction({\n index: finalIndex,\n itemId: session.draggedId,\n total: finalOrder.length,\n type: 'drop',\n });\n}\n\nfunction finishSession(scopeState: SortableScopeState, event: DragEvent, forceCancel: boolean): void {\n if (!scopeState.active) return;\n\n const { active } = scopeState;\n\n // If source or target became disabled during the drag, treat as cancellation.\n if (\n forceCancel ||\n !event.dataTransfer ||\n event.dataTransfer.dropEffect === 'none' ||\n !active.target ||\n !scopeState.handles.has(active.target) ||\n active.source.isDisabled() ||\n active.target.isDisabled()\n ) {\n cancelSession(scopeState, event);\n } else {\n commitSession(scopeState, event);\n }\n}\n\nfunction maybeAutoScroll(\n event: DragEvent,\n container: HTMLElement,\n axis: 'vertical' | 'horizontal',\n options: ResolvedAutoScrollOptions | null,\n): void {\n if (!options) return;\n\n const { container: scrollContainer, edgeThreshold: threshold, speed, viewport } = options;\n const rect = container.getBoundingClientRect();\n\n if (axis === 'vertical') {\n if (scrollContainer && event.clientY < rect.top + threshold) {\n container.scrollTop -= speed;\n } else if (scrollContainer && event.clientY > rect.bottom - threshold) {\n container.scrollTop += speed;\n }\n\n if (viewport && event.clientY < threshold) {\n window.scrollBy({ left: 0, top: -speed });\n } else if (viewport && event.clientY > window.innerHeight - threshold) {\n window.scrollBy({ left: 0, top: speed });\n }\n\n return;\n }\n\n if (scrollContainer && event.clientX < rect.left + threshold) {\n container.scrollLeft -= speed;\n } else if (scrollContainer && event.clientX > rect.right - threshold) {\n container.scrollLeft += speed;\n }\n\n if (viewport && event.clientX < threshold) {\n window.scrollBy({ left: -speed, top: 0 });\n } else if (viewport && event.clientX > window.innerWidth - threshold) {\n window.scrollBy({ left: speed, top: 0 });\n }\n}\n\n// ─── Keyboard reorder ─────────────────────────────────────────────────────────\n\nfunction applyKeyboardReorder(\n item: HTMLElement,\n element: HTMLElement,\n getItems: () => HTMLElement[],\n getOrderedIds: () => string[],\n key: string,\n axis: 'vertical' | 'horizontal',\n): string[] | null {\n const items = getItems();\n const currentIndex = items.indexOf(item);\n\n if (currentIndex < 0) return null;\n\n const isForward = axis === 'vertical' ? key === 'ArrowDown' : key === 'ArrowRight';\n const isBackward = axis === 'vertical' ? key === 'ArrowUp' : key === 'ArrowLeft';\n let targetIndex: number;\n\n if (isForward) {\n targetIndex = Math.min(items.length - 1, currentIndex + 1);\n } else if (isBackward) {\n targetIndex = Math.max(0, currentIndex - 1);\n } else if (key === 'Home') {\n targetIndex = 0;\n } else if (key === 'End') {\n targetIndex = items.length - 1;\n } else {\n return null;\n }\n\n // Already at the boundary — return null so the caller does not call preventDefault\n // and the browser can handle the key (e.g. scrolling the page).\n if (targetIndex === currentIndex) return null;\n\n const targetItem = items[targetIndex];\n\n if (!targetItem) return null;\n\n element.insertBefore(item, targetIndex > currentIndex ? targetItem.nextSibling : targetItem);\n item.focus();\n\n return getOrderedIds();\n}\n\n// ─── createSortableScope ──────────────────────────────────────────────────────\n\n/**\n * Create a shared scope for connected sortable containers.\n *\n * Items can be dragged between all sortables that share the same scope.\n * The scope exposes `isDragging` and `dispose()` — calling `dispose()` tears down\n * all member sortables at once.\n *\n * @example\n * ```ts\n * const scope = createSortableScope();\n * const left = createSortable({ element: leftEl, scope, getKey, onReorder });\n * const right = createSortable({ element: rightEl, scope, getKey, onReorder });\n *\n * // Tear down everything at once:\n * scope.dispose();\n * ```\n */\nexport function createSortableScope(options: SortableScopeOptions = {}): SortableScope {\n const state: SortableScopeState = {\n active: null,\n commitMove(event): void {\n options.onMove?.({\n ...event,\n setRevert(fn): void {\n state.lastRevert = fn;\n },\n });\n },\n disposables: new Set(),\n handles: new Set(),\n lastRevert: null,\n touch: null,\n };\n const disposable = createDisposable(() => {\n state.touch?.dispose();\n\n // Dispose all registered sortables (each dispose() call is idempotent)\n for (const disposeFn of state.disposables) {\n disposeFn();\n }\n });\n\n const scope = {\n get disposalSignal() {\n return disposable.disposalSignal;\n },\n dispose: disposable.dispose,\n get disposed() {\n return disposable.disposed;\n },\n get isDragging() {\n return state.active !== null;\n },\n revert() {\n state.lastRevert?.();\n state.lastRevert = null;\n },\n [SCOPE_BRAND]: true as const,\n [Symbol.dispose]: disposable[Symbol.dispose],\n } as SortableScope;\n\n sortableScopeStates.set(scope, state);\n\n if (options.touch) {\n state.touch = createScopeTouchController(options.touch === true ? {} : options.touch, (target) => {\n for (const handle of state.handles) {\n const dragTarget = handle.resolveTouchTarget(target);\n\n if (dragTarget) return dragTarget;\n }\n\n return null;\n });\n }\n\n return scope;\n}\n\n// ─── createSortable ───────────────────────────────────────────────────────────\n\n/**\n * Makes a list of items sortable via native HTML drag interactions.\n *\n * Provide `getKey` to map each item element to a stable string identity.\n * `createSortable` marks qualifying children with `data-dnd-item` and sets\n * `draggable=\"true\"` automatically.\n *\n * Style the drop indicator by targeting `.dnd-placeholder` in your CSS.\n * Supports keyboard reordering (arrow keys, Home/End) and auto-scrolling near edges.\n *\n * @example\n * ```ts\n * import { createSortable } from '@vielzeug/dnd';\n *\n * using sortable = createSortable({\n * element: listEl,\n * getKey: (el) => el.dataset.id!,\n * onReorder: ({ ids, setRevert }) => {\n * const prev = order;\n * setOrder(ids);\n * setRevert(() => setOrder(prev));\n * },\n * });\n * ```\n */\nexport function createSortable(options: SortableOptions): Sortable {\n const {\n autoScroll = true,\n axis = 'vertical',\n element,\n getKey,\n handle,\n keyboard = true,\n placeholderClass = 'dnd-placeholder',\n scope = createSortableScope(),\n } = options;\n const autoScrollOptions = resolveAutoScrollOptions(autoScroll);\n const scopeState = getSortableScopeState(scope);\n\n if (handle !== undefined && handle.trim() === '') {\n warn(\n 'handle option is an empty string — no handle elements will be found. Provide a valid CSS selector or omit the option.',\n );\n }\n\n const getItems = (): HTMLElement[] =>\n Array.from(element.children).filter((c) => (c as HTMLElement).hasAttribute(ITEM_ATTR)) as HTMLElement[];\n\n const getOrderedIds = (): string[] => getItems().map((el) => getKey(el));\n const managedElements = new Map<HTMLElement, ManagedElementState>();\n const originalContainerRole = element.getAttribute('role');\n\n const rememberElement = (managedElement: HTMLElement): ManagedElementState => {\n const existing = managedElements.get(managedElement);\n\n if (existing) return existing;\n\n const state: ManagedElementState = {\n dataDndHandle: managedElement.getAttribute(HANDLE_ATTR),\n dataDndItem: managedElement.getAttribute(ITEM_ATTR),\n draggable: managedElement.getAttribute('draggable'),\n role: managedElement.getAttribute('role'),\n tabIndex: managedElement.getAttribute('tabindex'),\n touchAction: managedElement.style.touchAction,\n };\n\n managedElements.set(managedElement, state);\n\n return state;\n };\n\n const restoreAttribute = (managedElement: HTMLElement, name: string, value: string | null): void => {\n if (value === null) {\n managedElement.removeAttribute(name);\n } else {\n managedElement.setAttribute(name, value);\n }\n };\n\n const syncItems = (): void => {\n getItems().forEach((el) => {\n const itemState = rememberElement(el);\n\n if (itemState.role === null) el.setAttribute('role', 'listitem');\n\n if (itemState.tabIndex === null) el.tabIndex = 0;\n\n if (handle) {\n el.querySelectorAll<HTMLElement>(handle).forEach((handleEl) => {\n rememberElement(handleEl);\n handleEl.setAttribute(HANDLE_ATTR, '');\n handleEl.setAttribute('draggable', 'true');\n handleEl.style.touchAction = 'none';\n });\n } else {\n el.setAttribute('draggable', 'true');\n // A native mouse drag has no competing gesture to arbitrate; touch does. Without this,\n // a mobile browser can decide the very first bit of finger movement is a page\n // scroll/pan — a decision it makes independently of, and before, this library's own\n // touch-shim threshold/`preventDefault()` logic ever runs — and hand the rest of the\n // gesture to native scrolling. Once that happens the item never receives the\n // `dragover` sequence needed to update the drop target, so the session ends up\n // committing back to wherever it started: indistinguishable from the drop \"reverting\".\n // `touch-action: none` opts the element out of every default touch gesture from\n // `touchstart` onward, leaving the whole interaction to this library's own JS.\n el.style.touchAction = 'none';\n }\n });\n };\n\n const markItems = (): void => {\n const seenKeys = new Set<string>();\n\n // Mark all children that have a key as sortable items\n Array.from(element.children).forEach((child) => {\n const el = child as HTMLElement;\n\n try {\n const key = getKey(el);\n\n if (key) {\n rememberElement(el);\n\n if (seenKeys.has(key)) {\n warn(\n `getKey returned the duplicate key \"${key}\" for two sibling items — onReorder's ids and applyReorder may become inconsistent. Ensure getKey returns a unique value per item.`,\n );\n } else {\n seenKeys.add(key);\n }\n\n el.setAttribute(ITEM_ATTR, '');\n }\n } catch (err) {\n warn(\n `getKey threw for a child element — the item will not be sortable. Check your getKey implementation. ${String(err)}`,\n );\n }\n });\n\n syncItems();\n };\n\n const cleanupItems = (): void => {\n for (const [managedElement, state] of managedElements) {\n restoreAttribute(managedElement, HANDLE_ATTR, state.dataDndHandle);\n restoreAttribute(managedElement, ITEM_ATTR, state.dataDndItem);\n restoreAttribute(managedElement, 'draggable', state.draggable);\n restoreAttribute(managedElement, 'role', state.role);\n restoreAttribute(managedElement, 'tabindex', state.tabIndex);\n managedElement.style.touchAction = state.touchAction;\n }\n\n managedElements.clear();\n };\n\n const createPlaceholder = (source: HTMLElement): HTMLElement => {\n const p = document.createElement('div');\n\n p.className = placeholderClass;\n p.setAttribute('aria-hidden', 'true');\n\n if (axis === 'horizontal') {\n p.style.width = `${source.offsetWidth}px`;\n } else {\n p.style.height = `${source.offsetHeight}px`;\n }\n\n return p;\n };\n\n let lastRevert: (() => void) | null = null;\n\n const handle_: ContainerHandle = {\n commitReorder: (orderedIds) => {\n if (!options.onReorder) return;\n\n const event: ReorderEvent = {\n ids: orderedIds,\n setRevert(fn) {\n lastRevert = fn;\n },\n };\n\n options.onReorder(event);\n },\n element,\n getOrderedIds,\n isDisabled: () => resolveDisabled(options.disabled),\n notifyBeforeReorder: (from, to) => options.onBeforeReorder?.(from, to),\n notifyDragEnd: (id, event) => options.onDragEnd?.(id, event),\n notifyDragStart: (id, event) => options.onDragStart?.(id, event),\n notifyInteraction: (event) => options.onInteraction?.(event),\n resolveTouchTarget: (target) => {\n if (resolveDisabled(options.disabled) || !element.contains(target)) return null;\n\n const item = target.closest<HTMLElement>(`[${ITEM_ATTR}]`);\n\n if (!item || !element.contains(item)) return null;\n\n if (!handle) return item;\n\n const handleTarget = target.closest<HTMLElement>(handle);\n\n return handleTarget && item.contains(handleTarget) ? handleTarget : null;\n },\n };\n\n scopeState.handles.add(handle_);\n\n const handleDragStart = (e: DragEvent): void => {\n if (scopeState.active) return;\n\n if (handle_.isDisabled()) return;\n\n const target = e.target as HTMLElement;\n const item = target.closest<HTMLElement>(`[${ITEM_ATTR}]`);\n\n if (!item) return;\n\n if (handle && !target.closest(handle)) return;\n\n const originalParent = item.parentElement;\n\n if (!originalParent) return;\n\n const placeholder = createPlaceholder(item);\n const originalNextSibling = item.nextSibling;\n const activeId = getKey(item);\n\n // Snapshot only the source handle at drag start; targets are snapshotted lazily.\n const initialOrders = new Map<ContainerHandle, string[]>();\n\n initialOrders.set(handle_, handle_.getOrderedIds());\n item.setAttribute('data-dragging', '');\n originalParent.insertBefore(placeholder, originalNextSibling);\n\n const session: DragSession = {\n draggedEl: item,\n draggedId: activeId,\n hideFrame: null,\n initialOrders,\n originalDisplay: item.style.display,\n originalNextSibling,\n originalParent,\n placeholder,\n source: handle_,\n target: handle_,\n };\n\n if (!isTouchDragEvent(e) || e.__dndTouchPreview) scheduleHide(session);\n\n scopeState.active = session;\n\n if (e.dataTransfer) {\n e.dataTransfer.effectAllowed = 'move';\n e.dataTransfer.setData('text/plain', activeId);\n\n if (options.dragImage) {\n const preview =\n typeof options.dragImage === 'function' ? options.dragImage(activeId, item, e) : options.dragImage;\n const [offsetX, offsetY] = options.dragImageOffset ?? [0, 0];\n\n if (preview) e.dataTransfer.setDragImage(preview, offsetX, offsetY);\n }\n }\n\n handle_.notifyDragStart(session.draggedId, e);\n handle_.notifyInteraction({\n index: handle_.getOrderedIds().indexOf(activeId),\n itemId: activeId,\n total: handle_.getOrderedIds().length,\n type: 'pickup',\n });\n };\n\n const handleDragOver = (e: DragEvent): void => {\n const session = scopeState.active;\n\n if (!session) return;\n\n if (session.source.isDisabled() || handle_.isDisabled()) return;\n\n e.preventDefault();\n maybeAutoScroll(e, element, axis, autoScrollOptions);\n\n // Lazily snapshot this handle's order the first time it becomes a target.\n snapshotOrder(session, handle_);\n\n const { draggedEl, placeholder } = session;\n const target = (e.target as HTMLElement).closest<HTMLElement>(`[${ITEM_ATTR}]`);\n\n if (!target) {\n // Only append placeholder when it isn't already inside this container.\n // Moving it to the end on every over-empty-space event causes the\n // placeholder to oscillate between positions as the cursor moves.\n if (placeholder.parentElement !== element) {\n element.appendChild(placeholder);\n }\n\n session.target = handle_;\n\n return;\n }\n\n if (target === draggedEl || target === placeholder) return;\n\n const rect = target.getBoundingClientRect();\n const insertAfter =\n axis === 'vertical' ? e.clientY >= rect.top + rect.height / 2 : e.clientX >= rect.left + rect.width / 2;\n\n element.insertBefore(placeholder, insertAfter ? target.nextSibling : target);\n session.target = handle_;\n };\n\n const handleDrop = (e: DragEvent): void => {\n const session = scopeState.active;\n\n if (!session) return;\n\n if (session.source.isDisabled() || handle_.isDisabled()) return;\n\n e.preventDefault();\n // Record the drop target; the actual commit happens in handleDragEnd where\n // dataTransfer.dropEffect tells us whether the browser accepted the operation.\n session.target = handle_;\n };\n\n const handleDragEnd = (e: DragEvent): void => {\n if (scopeState.active?.source !== handle_) return;\n\n finishSession(scopeState, e, false);\n };\n\n const handleKeydown = (e: KeyboardEvent): void => {\n if (!keyboard || handle_.isDisabled()) return;\n\n const tagName = (e.target as HTMLElement | null)?.tagName;\n\n if (tagName === 'INPUT' || tagName === 'TEXTAREA' || tagName === 'SELECT') return;\n\n const item = (e.target as HTMLElement).closest<HTMLElement>(`[${ITEM_ATTR}]`);\n\n if (!item || !element.contains(item)) return;\n\n const prevOrder = getOrderedIds();\n const activeId = getKey(item);\n const prevIndex = prevOrder.indexOf(activeId);\n const newOrder = applyKeyboardReorder(item, element, getItems, getOrderedIds, e.key, axis);\n\n // null means unrecognized key or boundary — let the browser handle it (e.g. page scroll)\n if (newOrder === null) return;\n\n e.preventDefault();\n handle_.notifyBeforeReorder(prevOrder, newOrder);\n handle_.commitReorder(newOrder);\n handle_.notifyInteraction({\n index: newOrder.indexOf(activeId),\n itemId: activeId,\n previousIndex: prevIndex,\n total: newOrder.length,\n type: 'move',\n });\n };\n\n markItems();\n\n const disposable = createDisposable(() => {\n scopeState.disposables.delete(disposable.dispose);\n\n if (scopeState.active && (scopeState.active.source === handle_ || scopeState.active.target === handle_)) {\n finishSession(scopeState, new Event('dragend') as DragEvent, true);\n }\n\n scopeState.handles.delete(handle_);\n restoreAttribute(element, 'role', originalContainerRole);\n cleanupItems();\n });\n\n if (originalContainerRole === null) element.setAttribute('role', 'list');\n\n element.addEventListener('dragstart', handleDragStart, { signal: disposable.disposalSignal });\n element.addEventListener('dragover', handleDragOver, { signal: disposable.disposalSignal });\n element.addEventListener('drop', handleDrop, { signal: disposable.disposalSignal });\n element.addEventListener('dragend', handleDragEnd, { signal: disposable.disposalSignal });\n element.addEventListener('keydown', handleKeydown, { signal: disposable.disposalSignal });\n\n // Register with scope so scope.dispose() can tear this down\n scopeState.disposables.add(disposable.dispose);\n\n return {\n get disposalSignal() {\n return disposable.disposalSignal;\n },\n dispose: disposable.dispose,\n get disposed() {\n return disposable.disposed;\n },\n get isDragging() {\n return scopeState.active?.source === handle_;\n },\n revert: () => {\n lastRevert?.();\n lastRevert = null;\n },\n [Symbol.dispose]: disposable[Symbol.dispose],\n sync: () => {\n markItems();\n },\n };\n}\n\n// ─── applyReorder ─────────────────────────────────────────────────────────────\n\n/**\n * Applies a sorted key array to a backing data array.\n * Unknown keys are ignored; items not present in `ids` are appended in original order.\n */\nexport function applyReorder<T>(items: T[], ids: string[], getKey: (item: T) => string): T[] {\n const byId = new Map(items.map((item) => [getKey(item), item] as const));\n const ordered: T[] = [];\n\n for (const id of ids) {\n if (!byId.has(id)) continue;\n\n const item = byId.get(id) as T;\n\n ordered.push(item);\n byId.delete(id);\n }\n\n for (const item of byId.values()) ordered.push(item);\n\n return ordered;\n}\n"],"mappings":"iHAQA,IAAM,EAAc,OAAO,eAAe,EAqSpC,EAAc,kBACd,EAAY,gBACZ,EAAsB,IAAI,QAC1B,EAAiD,CACrD,UAAW,GACX,cAAe,GACf,MAAO,GACP,SAAU,EACZ,EAIA,SAAS,EAAsB,EAA0C,CACvE,IAAM,EAAQ,EAAoB,IAAI,CAAK,EAE3C,GAAI,CAAC,EAAO,MAAM,IAAI,EAAA,cAEtB,OAAO,CACT,CAIA,SAAS,EACP,EACkC,CAKlC,OAJI,IAAe,GAAc,KAE7B,IAAe,IAAQ,IAAe,IAAA,GAAkB,EAErD,CACL,UAAW,EAAW,WAAa,GACnC,cAAe,EAAW,eAAiB,GAC3C,MAAO,EAAW,OAAS,GAC3B,SAAU,EAAW,UAAY,EACnC,CACF,CAIA,SAAS,EAAgB,EAAkB,EAA0B,CACnE,OAAO,EAAM,SAAW,EAAO,QAAU,EAAM,MAAM,EAAI,IAAU,IAAO,EAAO,E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qB,EACvD,EAAa,CACf,CAAC,EAaD,OAXI,IAA0B,MAAM,EAAQ,aAAa,OAAQ,MAAM,EAEvE,EAAQ,iBAAiB,YAAa,EAAiB,CAAE,OAAQ,EAAW,cAAe,CAAC,EAC5F,EAAQ,iBAAiB,WAAY,EAAgB,CAAE,OAAQ,EAAW,cAAe,CAAC,EAC1F,EAAQ,iBAAiB,OAAQ,EAAY,CAAE,OAAQ,EAAW,cAAe,CAAC,EAClF,EAAQ,iBAAiB,UAAW,EAAe,CAAE,OAAQ,EAAW,cAAe,CAAC,EACxF,EAAQ,iBAAiB,UAAW,EAAe,CAAE,OAAQ,EAAW,cAAe,CAAC,EAGxF,EAAW,YAAY,IAAI,EAAW,OAAO,EAEtC,CACL,IAAI,gBAAiB,CACnB,OAAO,EAAW,cACpB,EACA,QAAS,EAAW,QACpB,IAAI,UAAW,CACb,OAAO,EAAW,QACpB,EACA,IAAI,YAAa,CACf,OAAO,EAAW,QAAQ,SAAW,CACvC,EACA,WAAc,CACZ,IAAa,EACb,EAAa,IACf,GACC,OAAO,SAAU,EAAW,OAAO,SACpC,SAAY,CACV,EAAU,CACZ,CACF,CACF,CAQA,SAAgB,EAAgB,EAAY,EAAe,EAAkC,CAC3F,IAAM,EAAO,IAAI,IAAI,EAAM,IAAK,GAAS,CAAC,EAAO,CAAI,EAAG,CAAI,CAAU,CAAC,EACjE,EAAe,CAAC,EAEtB,IAAK,IAAM,KAAM,EAAK,CACpB,GAAI,CAAC,EAAK,IAAI,CAAE,EAAG,SAEnB,IAAM,EAAO,EAAK,IAAI,CAAE,EAExB,EAAQ,KAAK,CAAI,EACjB,EAAK,OAAO,CAAE,CAChB,CAEA,IAAK,IAAM,KAAQ,EAAK,OAAO,EAAG,EAAQ,KAAK,CAAI,EAEnD,OAAO,CACT"}
1
+ {"version":3,"file":"sortable.cjs","names":[],"sources":["../src/sortable.ts"],"sourcesContent":["import { matchKey } from '@vielzeug/keymap';\n\nimport { warn } from './_dev.js';\nimport { createDisposable, resolveDisabled } from './_shared.js';\nimport { createScopeTouchController, type ScopeTouchController, type TouchInputOptions } from './_touch.js';\nimport { DndError, DndScopeError } from './errors.js';\nimport type { Disposable } from './types.js';\n\n// ─── Branded scope ────────────────────────────────────────────────────────────\n\nconst SCOPE_BRAND = Symbol('SortableScope');\n\nexport interface SortableScope extends Disposable {\n /** `true` while any sortable in this scope is actively dragging. */\n readonly isDragging: boolean;\n readonly [SCOPE_BRAND]: true;\n}\n\n// ─── Types ────────────────────────────────────────────────────────────────────\n\nexport interface AutoScrollOptions {\n /** Scroll the sortable container while dragging near its edges. @default true */\n container?: boolean;\n /** Distance in pixels from an edge that triggers auto-scroll. @default 32 */\n edgeThreshold?: number;\n /** Pixels scrolled per dragover frame while near an edge. @default 18 */\n speed?: number;\n /** Scroll the viewport while dragging near the window edges. @default false */\n viewport?: boolean;\n}\n\n/**\n * Passed to `onReorder` after every successful reorder (drag or keyboard).\n * Application history owns rollback — use `before`/`after`/`item` to record\n * an undo entry.\n */\nexport interface ReorderEvent {\n /** Item keys after the reorder. */\n after: readonly string[];\n /** Item keys before the reorder. */\n before: readonly string[];\n /** Stable identity of the moved item. */\n item: string;\n}\n\n/** A single committed move between two containers in the same sortable scope. */\nexport interface SortableMoveEvent {\n /** Stable identity of the moved item. */\n readonly itemId: string;\n /** Source container before the move. */\n readonly source: HTMLElement;\n /** Ordered source item IDs before the move. */\n readonly sourceBeforeIds: readonly string[];\n /** Ordered source item IDs after the move. */\n readonly sourceIds: readonly string[];\n /** Target container after the move. */\n readonly target: HTMLElement;\n /** Ordered target item IDs before the move. */\n readonly targetBeforeIds: readonly string[];\n /** Ordered target item IDs after the move. */\n readonly targetIds: readonly string[];\n}\n\n/**\n * Structured accessibility/observability event for sortable interactions.\n *\n * Drag: `pickup` on dragstart, `drop` on commit, `cancel` on cancel.\n * Keyboard: `move` on each successful arrow/Home/End reorder (direct-commit model).\n *\n * Wire a consumer-side announcer to provide screen-reader feedback:\n * ```ts\n * createSortable({\n * onInteraction(event) {\n * announce(formatSortableEvent(event));\n * },\n * });\n * ```\n */\nexport type SortableInteractionEvent =\n | { readonly index: number; readonly itemId: string; readonly total: number; readonly type: 'pickup' }\n | {\n readonly index: number;\n readonly itemId: string;\n readonly previousIndex: number;\n readonly total: number;\n readonly type: 'move';\n }\n | { readonly index: number; readonly itemId: string; readonly total: number; readonly type: 'drop' }\n | { readonly index: number; readonly itemId: string; readonly total: number; readonly type: 'cancel' };\n\nexport interface SortableScopeOptions {\n /**\n * Called exactly once for every successful cross-container move.\n * Local reorders continue to use each sortable's `onReorder` callback.\n */\n onMove?: (event: SortableMoveEvent) => void;\n /**\n * Enables touch input for sortable items registered to this scope.\n * The controller ignores unrelated document draggables.\n */\n touch?: boolean | TouchInputOptions;\n}\n\nexport type SortableTouchOptions = TouchInputOptions;\n\nexport interface SortableOptions {\n /** Auto-scrolls the container (and viewport) near edges while dragging. @default true */\n autoScroll?: boolean | AutoScrollOptions;\n /** Sorting axis used to compute insertion position. @default 'vertical' */\n axis?: 'vertical' | 'horizontal';\n /**\n * When `true`, drag interactions are ignored.\n *\n * Note: if `disabled` transitions to `true` while a drag is in progress the\n * drag is treated as a cancellation — the item snaps back to its original\n * position rather than committing the last placeholder location.\n */\n disabled?: boolean;\n /** Optional custom drag preview element. */\n dragImage?: HTMLElement | ((id: string, item: HTMLElement, event: DragEvent) => HTMLElement | null | undefined);\n /**\n * Hotspot offset `[x, y]` passed to `setDragImage`.\n * Controls which point of the preview image follows the cursor.\n * @default [0, 0]\n */\n dragImageOffset?: [number, number];\n /** Container element whose direct-child items are sortable. */\n element: HTMLElement;\n /**\n * Returns the identity key for a given item element.\n * This separates the \"what is this item?\" concern (yours) from the \"which children\n * are sortable?\" concern (ours — marked with `data-dnd-item`).\n *\n * @example\n * ```ts\n * getKey: (el) => el.dataset.taskId!\n * ```\n */\n getKey: (element: HTMLElement) => string;\n /**\n * Selector for the drag handle inside each item.\n * When omitted the whole item is the handle.\n */\n handle?: string;\n /**\n * Returns the current sortable item elements. When omitted the sortable\n * scans the container's direct children. Provide this for explicit item\n * ownership — e.g. when items are managed by a framework render loop.\n */\n items?: () => readonly HTMLElement[];\n /**\n * Enables keyboard-based reordering using arrow keys plus Home/End.\n * @default true\n */\n keyboard?: boolean;\n /**\n * Called just before a successful drag commit with the before and after order snapshots.\n * Use this hook to set up FLIP animations — the source items are still in their\n * pre-commit positions at the time of the call.\n *\n * @example\n * ```ts\n * onBeforeReorder: (from, to) => {\n * // record element positions here, then animate after the next microtask\n * }\n * ```\n */\n onBeforeReorder?: (from: readonly string[], to: readonly string[]) => void;\n /** Called when a drag ends (whether dropped or cancelled). */\n onDragEnd?: (id: string, event: DragEvent) => void;\n /** Called when the user starts dragging an item. */\n onDragStart?: (id: string, event: DragEvent) => void;\n /**\n * Structured accessibility event for pickup/move/drop/cancel — wire to a consumer-side\n * announcer for screen-reader feedback. See {@link SortableInteractionEvent}.\n */\n onInteraction?: (event: SortableInteractionEvent) => void;\n /**\n * Called with a {@link ReorderEvent} after a successful reorder, only when the order changed.\n * The event carries `before`, `after`, and `item` so application history can own rollback.\n *\n * @example\n * ```ts\n * onReorder: ({ before, after, item }) => {\n * history.push({ revert: () => setOrder(before) });\n * setOrder(after);\n * },\n * ```\n */\n onReorder?: (event: ReorderEvent) => void;\n /** CSS class applied to the placeholder element. @default 'dnd-placeholder' */\n placeholderClass?: string;\n /** Shared scope for connected sortable containers. Containers only exchange items within the same scope. */\n scope?: SortableScope;\n}\n\nexport interface Sortable extends Disposable {\n readonly isDragging: boolean;\n /**\n * Re-reads items from the `items` provider (or the container's direct children)\n * and reapplies `draggable`, ARIA roles, and handle attributes. Call this after\n * programmatically adding, removing, or replacing items — e.g. after a framework\n * render that replaces DOM nodes.\n *\n * Not needed when items are only reordered via drag or keyboard.\n */\n refresh(): void;\n}\n\n// ─── Internal types ───────────────────────────────────────────────────────────\n\ninterface ResolvedAutoScrollOptions {\n container: boolean;\n edgeThreshold: number;\n speed: number;\n viewport: boolean;\n}\n\n/** Per-container closure passed into shared session functions. */\ninterface ContainerHandle {\n commitReorder: (event: { after: readonly string[]; before: readonly string[]; item: string }) => void;\n readonly element: HTMLElement;\n getOrderedIds: () => string[];\n getOrderedItems: () => HTMLElement[];\n isDisabled: () => boolean;\n notifyBeforeReorder: (from: readonly string[], to: readonly string[]) => void;\n notifyDragEnd: (id: string, event: DragEvent) => void;\n notifyDragStart: (id: string, event: DragEvent) => void;\n notifyInteraction: (event: SortableInteractionEvent) => void;\n resolveTouchTarget: (target: Element) => HTMLElement | null;\n}\n\n/**\n * Encapsulates all mutable state for a single in-progress drag operation.\n * Created at dragstart, destroyed on dragend/cancel.\n */\ninterface DragSession {\n draggedEl: HTMLElement;\n draggedId: string;\n /** rAF handle for the deferred element-hide; null once fired or cancelled. */\n hideFrame: number | null;\n /**\n * Order snapshots captured lazily: snapshot is taken the first time a handle\n * becomes the active target (and always for the source at drag start).\n */\n initialOrders: Map<ContainerHandle, string[]>;\n originalDisplay: string;\n originalNextSibling: ChildNode | null;\n originalParent: HTMLElement;\n placeholder: HTMLElement;\n source: ContainerHandle;\n target: ContainerHandle | null;\n}\n\ninterface SortableScopeState {\n active: DragSession | null;\n commitMove: (event: SortableMoveEvent) => void;\n /** All sortables registered in this scope, kept for scope.dispose(). */\n disposables: Set<() => void>;\n handles: Set<ContainerHandle>;\n touch: ScopeTouchController | null;\n}\n\ninterface ManagedElementState {\n dataDndHandle: string | null;\n dataDndItem: string | null;\n draggable: string | null;\n role: string | null;\n tabIndex: string | null;\n touchAction: string;\n}\n\ninterface TouchDragEvent extends DragEvent {\n readonly __dndTouch?: boolean;\n readonly __dndTouchPreview?: boolean;\n}\n\n// ─── Internal constants ───────────────────────────────────────────────────────\n\nconst HANDLE_ATTR = 'data-dnd-handle';\nconst ITEM_ATTR = 'data-dnd-item';\nconst sortableScopeStates = new WeakMap<SortableScope, SortableScopeState>();\nconst DEFAULT_AUTO_SCROLL: ResolvedAutoScrollOptions = {\n container: true,\n edgeThreshold: 32,\n speed: 18,\n viewport: false,\n};\n\n// ─── Scope helpers ────────────────────────────────────────────────────────────\n\nfunction getSortableScopeState(scope: SortableScope): SortableScopeState {\n const state = sortableScopeStates.get(scope);\n\n if (!state) throw new DndScopeError();\n if (scope.disposed) throw new DndScopeError('Cannot register a sortable with a disposed scope.');\n\n return state;\n}\n\n// ─── Option resolution ────────────────────────────────────────────────────────\n\nfunction resolveAutoScrollOptions(\n autoScroll: boolean | AutoScrollOptions | undefined,\n): ResolvedAutoScrollOptions | null {\n if (autoScroll === false) return null;\n\n if (autoScroll === true || autoScroll === undefined) return DEFAULT_AUTO_SCROLL;\n if (\n !Number.isFinite(autoScroll.edgeThreshold ?? 32) ||\n (autoScroll.edgeThreshold ?? 32) < 0 ||\n !Number.isFinite(autoScroll.speed ?? 18) ||\n (autoScroll.speed ?? 18) <= 0\n ) {\n throw new DndError('Auto-scroll edgeThreshold must be non-negative and speed must be positive');\n }\n\n return {\n container: autoScroll.container ?? true,\n edgeThreshold: autoScroll.edgeThreshold ?? 32,\n speed: autoScroll.speed ?? 18,\n viewport: autoScroll.viewport ?? false,\n };\n}\n\n// ─── DOM helpers ──────────────────────────────────────────────────────────────\n\nfunction hasOrderChanged(before: string[], after: string[]): boolean {\n return after.length !== before.length || after.some((id, index) => id !== before[index]);\n}\n\nfunction isTouchDragEvent(event: DragEvent): event is TouchDragEvent {\n return (event as TouchDragEvent).__dndTouch === true;\n}\n\nfunction immutableIds(ids: readonly string[]): readonly string[] {\n return Object.freeze([...ids]);\n}\n\nfunction notify<Args extends unknown[]>(\n name: string,\n callback: ((...args: Args) => void) | undefined,\n ...args: Args\n): void {\n if (!callback) return;\n try {\n callback(...args);\n } catch {\n warn(`${name} callback failed; Dnd continued without interrupting internal state.`);\n }\n}\n\n// ─── Drag session helpers ─────────────────────────────────────────────────────\n\nfunction scheduleHide(session: DragSession): void {\n if (typeof requestAnimationFrame !== 'function') return;\n\n session.hideFrame = requestAnimationFrame(() => {\n session.hideFrame = null;\n session.draggedEl.style.display = 'none';\n });\n}\n\nfunction cancelHide(session: DragSession): void {\n if (session.hideFrame !== null) {\n cancelAnimationFrame(session.hideFrame);\n session.hideFrame = null;\n }\n}\n\nfunction restoreSessionElement(session: DragSession): void {\n cancelHide(session);\n session.draggedEl.style.display = session.originalDisplay;\n session.draggedEl.removeAttribute('data-dragging');\n}\n\n/**\n * Snapshot a handle's current order if not already recorded.\n * Called the first time a handle becomes an active target so we only capture\n * lists that actually participate in the drag.\n */\nfunction snapshotOrder(session: DragSession, handle: ContainerHandle): void {\n if (!session.initialOrders.has(handle)) {\n session.initialOrders.set(handle, handle.getOrderedIds());\n }\n}\n\nfunction projectedChanges(session: DragSession): Array<{ after: string[]; before: string[]; handle: ContainerHandle }> {\n const target = session.target;\n\n return [...session.initialOrders].flatMap(([handle, before]) => {\n const after = before.filter((id) => id !== session.draggedId);\n\n if (handle === target && session.placeholder.parentElement === handle.element) {\n const children = [...handle.element.children];\n const placeholderIndex = children.indexOf(session.placeholder);\n const insertionIndex = handle\n .getOrderedItems()\n .filter((item) => item !== session.draggedEl && children.indexOf(item) < placeholderIndex).length;\n after.splice(insertionIndex, 0, session.draggedId);\n }\n\n return hasOrderChanged(before, after) ? [{ after, before, handle }] : [];\n });\n}\n\n// ─── Session commit / cancel ──────────────────────────────────────────────────\n\nfunction cancelSession(scopeState: SortableScopeState, event: DragEvent): void {\n const session = scopeState.active;\n\n if (!session) return;\n\n restoreSessionElement(session);\n session.originalParent.insertBefore(\n session.draggedEl,\n session.originalNextSibling?.parentNode === session.originalParent ? session.originalNextSibling : null,\n );\n session.placeholder.remove();\n scopeState.active = null;\n\n session.source.notifyDragEnd(session.draggedId, event);\n session.source.notifyInteraction({\n index: session.source.getOrderedIds().indexOf(session.draggedId),\n itemId: session.draggedId,\n total: session.source.getOrderedIds().length,\n type: 'cancel',\n });\n}\n\nfunction commitSession(scopeState: SortableScopeState, event: DragEvent): void {\n const session = scopeState.active;\n\n if (!session) return;\n\n const targetHandle = session.target;\n const targetElement = session.placeholder.parentElement;\n const projected = projectedChanges(session);\n\n for (const { after, before, handle } of projected) {\n handle.notifyBeforeReorder(immutableIds(before), immutableIds(after));\n }\n\n restoreSessionElement(session);\n\n if (targetHandle && scopeState.handles.has(targetHandle) && targetElement) {\n targetElement.insertBefore(session.draggedEl, session.placeholder);\n } else {\n session.originalParent.insertBefore(\n session.draggedEl,\n session.originalNextSibling?.parentNode === session.originalParent ? session.originalNextSibling : null,\n );\n }\n\n session.placeholder.remove();\n scopeState.active = null;\n\n session.source.notifyDragEnd(session.draggedId, event);\n\n const changes: Array<{ after: readonly string[]; before: readonly string[]; handle: ContainerHandle }> = [];\n\n for (const [handle, before] of session.initialOrders) {\n if (!scopeState.handles.has(handle)) continue;\n\n const afterOrder = handle.getOrderedIds();\n\n if (hasOrderChanged(before, afterOrder)) {\n changes.push({ after: afterOrder, before, handle });\n }\n }\n\n if (targetHandle && targetHandle !== session.source) {\n const sourceChange = changes.find((change) => change.handle === session.source);\n const targetChange = changes.find((change) => change.handle === targetHandle);\n\n if (sourceChange && targetChange) {\n scopeState.commitMove({\n itemId: session.draggedId,\n source: session.source.element,\n sourceBeforeIds: sourceChange.before,\n sourceIds: sourceChange.after,\n target: targetHandle.element,\n targetBeforeIds: targetChange.before,\n targetIds: targetChange.after,\n });\n\n const dropIndex = targetChange.after.indexOf(session.draggedId);\n const dropTotal = targetChange.after.length;\n\n // Emit from both source and target so a consumer wiring onInteraction on\n // either container receives the drop event.\n session.source.notifyInteraction({ index: dropIndex, itemId: session.draggedId, total: dropTotal, type: 'drop' });\n targetHandle.notifyInteraction({ index: dropIndex, itemId: session.draggedId, total: dropTotal, type: 'drop' });\n }\n\n return;\n }\n\n for (const { after, before, handle } of changes) {\n handle.commitReorder({ after, before, item: session.draggedId });\n }\n\n // Same-container — emit drop even when the order didn't change (user picked up\n // and dropped at the same position). The interaction completed; silence would\n // leave screen-reader users without confirmation.\n const sourceChange = changes.find((change) => change.handle === session.source);\n const finalOrder = sourceChange ? sourceChange.after : session.source.getOrderedIds();\n const finalIndex = finalOrder.indexOf(session.draggedId);\n\n session.source.notifyInteraction({\n index: finalIndex,\n itemId: session.draggedId,\n total: finalOrder.length,\n type: 'drop',\n });\n}\n\nfunction finishSession(scopeState: SortableScopeState, event: DragEvent, forceCancel: boolean): void {\n if (!scopeState.active) return;\n\n const { active } = scopeState;\n\n // If source or target became disabled during the drag, treat as cancellation.\n if (\n forceCancel ||\n !event.dataTransfer ||\n event.dataTransfer.dropEffect === 'none' ||\n !active.target ||\n !scopeState.handles.has(active.target) ||\n active.source.isDisabled() ||\n active.target.isDisabled()\n ) {\n cancelSession(scopeState, event);\n } else {\n commitSession(scopeState, event);\n }\n}\n\nfunction maybeAutoScroll(\n event: DragEvent,\n container: HTMLElement,\n axis: 'vertical' | 'horizontal',\n options: ResolvedAutoScrollOptions | null,\n): void {\n if (!options) return;\n\n const { container: scrollContainer, edgeThreshold: threshold, speed, viewport } = options;\n const rect = container.getBoundingClientRect();\n\n if (axis === 'vertical') {\n if (scrollContainer && event.clientY < rect.top + threshold) {\n container.scrollTop -= speed;\n } else if (scrollContainer && event.clientY > rect.bottom - threshold) {\n container.scrollTop += speed;\n }\n\n if (viewport && event.clientY < threshold) {\n window.scrollBy({ left: 0, top: -speed });\n } else if (viewport && event.clientY > window.innerHeight - threshold) {\n window.scrollBy({ left: 0, top: speed });\n }\n\n return;\n }\n\n if (scrollContainer && event.clientX < rect.left + threshold) {\n container.scrollLeft -= speed;\n } else if (scrollContainer && event.clientX > rect.right - threshold) {\n container.scrollLeft += speed;\n }\n\n if (viewport && event.clientX < threshold) {\n window.scrollBy({ left: -speed, top: 0 });\n } else if (viewport && event.clientX > window.innerWidth - threshold) {\n window.scrollBy({ left: speed, top: 0 });\n }\n}\n\n// ─── Keyboard reorder ─────────────────────────────────────────────────────────\n\nfunction keyboardTargetIndex(\n items: HTMLElement[],\n item: HTMLElement,\n event: KeyboardEvent,\n axis: 'vertical' | 'horizontal',\n): number | null {\n const currentIndex = items.indexOf(item);\n\n if (currentIndex < 0) return null;\n\n const forwardKey = axis === 'vertical' ? 'ArrowDown' : 'ArrowRight';\n const backwardKey = axis === 'vertical' ? 'ArrowUp' : 'ArrowLeft';\n const isForward = matchKey(event, forwardKey);\n const isBackward = matchKey(event, backwardKey);\n let targetIndex: number;\n\n if (isForward) targetIndex = Math.min(items.length - 1, currentIndex + 1);\n else if (isBackward) targetIndex = Math.max(0, currentIndex - 1);\n else if (matchKey(event, 'Home')) targetIndex = 0;\n else if (matchKey(event, 'End')) targetIndex = items.length - 1;\n else return null;\n\n // Already at the boundary — return null so the caller does not call preventDefault\n // and the browser can handle the key (e.g. scrolling the page).\n return targetIndex === currentIndex ? null : targetIndex;\n}\n\n// ─── createSortableScope ──────────────────────────────────────────────────────\n\n/**\n * Create a shared scope for connected sortable containers.\n *\n * Items can be dragged between all sortables that share the same scope.\n *\n * @example\n * ```ts\n * const scope = createSortableScope();\n * const left = createSortable({ element: leftEl, scope, getKey, onReorder });\n * const right = createSortable({ element: rightEl, scope, getKey, onReorder });\n *\n * // Tear down everything at once:\n * scope.dispose();\n * ```\n */\nexport function createSortableScope(options: SortableScopeOptions = {}): SortableScope {\n const state: SortableScopeState = {\n active: null,\n commitMove(event): void {\n notify(\n 'onMove',\n options.onMove,\n Object.freeze({\n ...event,\n sourceBeforeIds: immutableIds(event.sourceBeforeIds),\n sourceIds: immutableIds(event.sourceIds),\n targetBeforeIds: immutableIds(event.targetBeforeIds),\n targetIds: immutableIds(event.targetIds),\n }),\n );\n },\n disposables: new Set(),\n handles: new Set(),\n touch: null,\n };\n const disposable = createDisposable(() => {\n state.touch?.dispose();\n\n // Dispose all registered sortables (each dispose() call is idempotent)\n for (const disposeFn of [...state.disposables]) {\n disposeFn();\n }\n state.disposables.clear();\n state.handles.clear();\n });\n\n const scope = {\n get disposalSignal() {\n return disposable.disposalSignal;\n },\n dispose: disposable.dispose,\n get disposed() {\n return disposable.disposed;\n },\n get isDragging() {\n return state.active !== null;\n },\n [SCOPE_BRAND]: true as const,\n [Symbol.dispose]: disposable[Symbol.dispose],\n } as SortableScope;\n\n sortableScopeStates.set(scope, state);\n\n if (options.touch) {\n state.touch = createScopeTouchController(options.touch === true ? {} : options.touch, (target) => {\n if (state.active) return null;\n for (const handle of state.handles) {\n const dragTarget = handle.resolveTouchTarget(target);\n\n if (dragTarget) return dragTarget;\n }\n\n return null;\n });\n }\n\n return scope;\n}\n\n// ─── createSortable ───────────────────────────────────────────────────────────\n\n/**\n * Makes a list of items sortable via native HTML drag interactions.\n *\n * Provide `getKey` to map each item element to a stable string identity.\n * `createSortable` marks qualifying children with `data-dnd-item` and sets\n * `draggable=\"true\"` automatically.\n *\n * Style the drop indicator by targeting `.dnd-placeholder` in your CSS.\n * Supports keyboard reordering (arrow keys, Home/End) and auto-scrolling near edges.\n *\n * @example\n * ```ts\n * import { createSortable } from '@vielzeug/dnd/sortable';\n *\n * using sortable = createSortable({\n * element: listEl,\n * getKey: (el) => el.dataset.id!,\n * onReorder: ({ before, after }) => {\n * history.push({ revert: () => setOrder(before) });\n * setOrder(after);\n * },\n * });\n * ```\n */\nexport function createSortable(options: SortableOptions): Sortable {\n const {\n autoScroll = true,\n axis = 'vertical',\n element,\n getKey,\n handle,\n keyboard = true,\n placeholderClass = 'dnd-placeholder',\n scope = createSortableScope(),\n } = options;\n if (axis !== 'vertical' && axis !== 'horizontal') throw new DndError('axis must be \"vertical\" or \"horizontal\"');\n const handleSelector = handle?.trim() || null;\n\n if (handle !== undefined && !handleSelector) {\n warn(\n 'handle option is an empty string — no handle elements will be found. Provide a valid CSS selector or omit the option.',\n );\n } else if (handleSelector) {\n try {\n element.querySelector(handleSelector);\n } catch (error) {\n throw new DndError(`Invalid handle selector: \"${handle}\"`, { cause: error });\n }\n }\n\n const autoScrollOptions = resolveAutoScrollOptions(autoScroll);\n const scopeState = getSortableScopeState(scope);\n if ([...scopeState.handles].some((registered) => registered.element === element)) {\n throw new DndError('A sortable is already registered for this element in the selected scope.');\n }\n const getItems = (): HTMLElement[] =>\n (options.items ? options.items() : (Array.from(element.children) as HTMLElement[])).filter(\n (item) => item.parentElement === element && item.hasAttribute(ITEM_ATTR),\n );\n\n const getOrderedIds = (): string[] => getItems().map((el) => getKey(el));\n const managedElements = new Map<HTMLElement, ManagedElementState>();\n const originalContainerRole = element.getAttribute('role');\n\n const rememberElement = (managedElement: HTMLElement): ManagedElementState => {\n const existing = managedElements.get(managedElement);\n\n if (existing) return existing;\n\n const state: ManagedElementState = {\n dataDndHandle: managedElement.getAttribute(HANDLE_ATTR),\n dataDndItem: managedElement.getAttribute(ITEM_ATTR),\n draggable: managedElement.getAttribute('draggable'),\n role: managedElement.getAttribute('role'),\n tabIndex: managedElement.getAttribute('tabindex'),\n touchAction: managedElement.style.touchAction,\n };\n\n managedElements.set(managedElement, state);\n\n return state;\n };\n\n const restoreAttribute = (managedElement: HTMLElement, name: string, value: string | null): void => {\n if (value === null) {\n managedElement.removeAttribute(name);\n } else {\n managedElement.setAttribute(name, value);\n }\n };\n\n const syncItems = (items = getItems()): void => {\n items.forEach((el) => {\n const itemState = rememberElement(el);\n\n if (itemState.role === null) el.setAttribute('role', 'listitem');\n\n if (itemState.tabIndex === null) el.tabIndex = 0;\n\n if (handle !== undefined) {\n handleSelector &&\n el.querySelectorAll<HTMLElement>(handleSelector).forEach((handleEl) => {\n rememberElement(handleEl);\n handleEl.setAttribute(HANDLE_ATTR, '');\n handleEl.setAttribute('draggable', 'true');\n if (scopeState.touch) handleEl.style.touchAction = 'none';\n });\n } else {\n el.setAttribute('draggable', 'true');\n // A native mouse drag has no competing gesture to arbitrate; touch does. Without this,\n // a mobile browser can decide the very first bit of finger movement is a page\n // scroll/pan — a decision it makes independently of, and before, this library's own\n // Gesture activation-distance/`preventDefault()` logic ever runs — and hand the rest of the\n // gesture to native scrolling. Once that happens the item never receives the\n // `dragover` sequence needed to update the drop target, so the session ends up\n // committing back to wherever it started: indistinguishable from the drop \"reverting\".\n // `touch-action: none` opts the element out of every default touch gesture from\n // `pointerdown` onward, leaving the whole interaction to this library's own JS.\n if (scopeState.touch) el.style.touchAction = 'none';\n }\n });\n };\n\n const markItems = (): void => {\n const seenKeys = new Set<string>();\n\n // When an explicit items provider is given, use it directly; otherwise scan\n // the container's direct children for elements that have a key.\n const provided = options.items ? options.items() : (Array.from(element.children) as HTMLElement[]);\n const candidates = provided.filter((item) => item instanceof HTMLElement && item.parentElement === element);\n const keyed: HTMLElement[] = [];\n\n if (candidates.length !== provided.length) {\n warn('items returned an element that is not a direct child of the sortable container; it was ignored.');\n }\n\n for (const el of candidates) {\n try {\n const key = getKey(el);\n\n if (key) {\n if (seenKeys.has(key)) {\n warn(\n `getKey returned the duplicate key \"${key}\" for two sibling items — the duplicate item was excluded. Ensure getKey returns a unique value per item.`,\n );\n continue;\n }\n\n seenKeys.add(key);\n keyed.push(el);\n }\n } catch (err) {\n warn(\n `getKey threw for a child element — the item will not be sortable. Check your getKey implementation. ${String(err)}`,\n );\n }\n }\n\n cleanupItems();\n for (const el of keyed) {\n rememberElement(el);\n el.setAttribute(ITEM_ATTR, '');\n }\n syncItems(keyed);\n };\n\n const cleanupItems = (): void => {\n for (const [managedElement, state] of managedElements) {\n restoreAttribute(managedElement, HANDLE_ATTR, state.dataDndHandle);\n restoreAttribute(managedElement, ITEM_ATTR, state.dataDndItem);\n restoreAttribute(managedElement, 'draggable', state.draggable);\n restoreAttribute(managedElement, 'role', state.role);\n restoreAttribute(managedElement, 'tabindex', state.tabIndex);\n managedElement.style.touchAction = state.touchAction;\n }\n\n managedElements.clear();\n };\n\n const createPlaceholder = (source: HTMLElement): HTMLElement => {\n const p = document.createElement('div');\n\n p.className = placeholderClass;\n p.setAttribute('aria-hidden', 'true');\n\n if (axis === 'horizontal') {\n p.style.width = `${source.offsetWidth}px`;\n } else {\n p.style.height = `${source.offsetHeight}px`;\n }\n\n return p;\n };\n\n const handle_: ContainerHandle = {\n commitReorder: (event) =>\n notify(\n 'onReorder',\n options.onReorder,\n Object.freeze({ after: immutableIds(event.after), before: immutableIds(event.before), item: event.item }),\n ),\n element,\n getOrderedIds,\n getOrderedItems: getItems,\n isDisabled: () => resolveDisabled(options.disabled),\n notifyBeforeReorder: (from, to) => notify('onBeforeReorder', options.onBeforeReorder, from, to),\n notifyDragEnd: (id, event) => notify('onDragEnd', options.onDragEnd, id, event),\n notifyDragStart: (id, event) => notify('onDragStart', options.onDragStart, id, event),\n notifyInteraction: (event) => notify('onInteraction', options.onInteraction, Object.freeze(event)),\n resolveTouchTarget: (target) => {\n if (resolveDisabled(options.disabled) || !element.contains(target)) return null;\n\n const item = target.closest<HTMLElement>(`[${ITEM_ATTR}]`);\n\n if (!item || !getItems().includes(item)) return null;\n\n if (handle === undefined) return item;\n if (!handleSelector) return null;\n\n const handleTarget = target.closest<HTMLElement>(handleSelector);\n\n return handleTarget && item.contains(handleTarget) ? handleTarget : null;\n },\n };\n\n const handleDragStart = (e: DragEvent): void => {\n if (scopeState.active) return;\n\n if (handle_.isDisabled()) return;\n\n const target = e.target as HTMLElement;\n const item = target.closest<HTMLElement>(`[${ITEM_ATTR}]`);\n\n if (!item || !getItems().includes(item)) return;\n\n if (handle !== undefined) {\n const handleTarget = handleSelector ? target.closest(handleSelector) : null;\n if (!handleTarget || !item.contains(handleTarget)) return;\n }\n\n const originalParent = item.parentElement;\n\n if (!originalParent) return;\n\n const placeholder = createPlaceholder(item);\n const originalNextSibling = item.nextSibling;\n const activeId = getKey(item);\n\n // Snapshot only the source handle at drag start; targets are snapshotted lazily.\n const initialOrders = new Map<ContainerHandle, string[]>();\n\n initialOrders.set(handle_, handle_.getOrderedIds());\n item.setAttribute('data-dragging', '');\n originalParent.insertBefore(placeholder, originalNextSibling);\n\n const session: DragSession = {\n draggedEl: item,\n draggedId: activeId,\n hideFrame: null,\n initialOrders,\n originalDisplay: item.style.display,\n originalNextSibling,\n originalParent,\n placeholder,\n source: handle_,\n target: handle_,\n };\n\n if (!isTouchDragEvent(e) || e.__dndTouchPreview) scheduleHide(session);\n\n scopeState.active = session;\n\n if (e.dataTransfer) {\n try {\n e.dataTransfer.effectAllowed = 'move';\n e.dataTransfer.setData('text/plain', activeId);\n\n if (options.dragImage) {\n const preview =\n typeof options.dragImage === 'function' ? options.dragImage(activeId, item, e) : options.dragImage;\n const [offsetX, offsetY] = options.dragImageOffset ?? [0, 0];\n\n if (preview) e.dataTransfer.setDragImage(preview, offsetX, offsetY);\n }\n } catch (error) {\n warn(`drag preview setup failed: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n handle_.notifyDragStart(session.draggedId, e);\n handle_.notifyInteraction({\n index: handle_.getOrderedIds().indexOf(activeId),\n itemId: activeId,\n total: handle_.getOrderedIds().length,\n type: 'pickup',\n });\n };\n\n const handleDragOver = (e: DragEvent): void => {\n const session = scopeState.active;\n\n if (!session) return;\n\n if (session.source.isDisabled() || handle_.isDisabled()) return;\n\n e.preventDefault();\n maybeAutoScroll(e, element, axis, autoScrollOptions);\n\n // Lazily snapshot this handle's order the first time it becomes a target.\n snapshotOrder(session, handle_);\n\n const { draggedEl, placeholder } = session;\n const target = (e.target as HTMLElement).closest<HTMLElement>(`[${ITEM_ATTR}]`);\n\n if (target && !getItems().includes(target)) return;\n\n if (!target) {\n // Only append placeholder when it isn't already inside this container.\n // Moving it to the end on every over-empty-space event causes the\n // placeholder to oscillate between positions as the cursor moves.\n if (placeholder.parentElement !== element) {\n element.appendChild(placeholder);\n }\n\n session.target = handle_;\n\n return;\n }\n\n if (target === draggedEl || target === placeholder) return;\n\n const rect = target.getBoundingClientRect();\n const insertAfter =\n axis === 'vertical' ? e.clientY >= rect.top + rect.height / 2 : e.clientX >= rect.left + rect.width / 2;\n\n element.insertBefore(placeholder, insertAfter ? target.nextSibling : target);\n session.target = handle_;\n };\n\n const handleDrop = (e: DragEvent): void => {\n const session = scopeState.active;\n\n if (!session) return;\n\n if (session.source.isDisabled() || handle_.isDisabled()) return;\n\n e.preventDefault();\n // Record the drop target; the actual commit happens in handleDragEnd where\n // dataTransfer.dropEffect tells us whether the browser accepted the operation.\n session.target = handle_;\n };\n\n const handleDragEnd = (e: DragEvent): void => {\n if (scopeState.active?.source !== handle_) return;\n\n finishSession(scopeState, e, false);\n };\n\n const handleKeydown = (e: KeyboardEvent): void => {\n if (!keyboard || handle_.isDisabled()) return;\n\n const eventTarget = e.target as HTMLElement | null;\n const item = eventTarget?.closest<HTMLElement>(`[${ITEM_ATTR}]`);\n\n if (!eventTarget || !item || !getItems().includes(item)) return;\n\n const interactive = eventTarget.closest<HTMLElement>(\n 'input, textarea, select, button, a[href], [contenteditable]:not([contenteditable=\"false\"]), [role=\"button\"], [role=\"link\"]',\n );\n const keyboardHandle = handleSelector ? eventTarget.closest<HTMLElement>(handleSelector) : null;\n\n if (interactive && (!keyboardHandle || !item.contains(keyboardHandle))) return;\n\n const items = getItems();\n const prevIndex = items.indexOf(item);\n const targetIndex = keyboardTargetIndex(items, item, e, axis);\n\n // null means unrecognized key or boundary — let the browser handle it (e.g. page scroll)\n if (targetIndex === null) return;\n\n const targetItem = items[targetIndex];\n if (!targetItem) return;\n\n const prevOrder = items.map(getKey);\n const reorderedItems = [...items];\n reorderedItems.splice(prevIndex, 1);\n reorderedItems.splice(targetIndex, 0, item);\n const newOrder = reorderedItems.map(getKey);\n const activeId = getKey(item);\n\n e.preventDefault();\n handle_.notifyBeforeReorder(immutableIds(prevOrder), immutableIds(newOrder));\n element.insertBefore(item, targetIndex > prevIndex ? targetItem.nextSibling : targetItem);\n item.focus();\n handle_.commitReorder({ after: newOrder, before: prevOrder, item: activeId });\n handle_.notifyInteraction({\n index: targetIndex,\n itemId: activeId,\n previousIndex: prevIndex,\n total: newOrder.length,\n type: 'move',\n });\n };\n\n markItems();\n\n let stopTouch: (() => void) | undefined;\n const disposable = createDisposable(() => {\n scopeState.disposables.delete(disposable.dispose);\n\n if (\n scopeState.active &&\n (scopeState.active.source === handle_ || scopeState.active.target === handle_) &&\n !scopeState.touch?.cancel()\n ) {\n finishSession(scopeState, new Event('dragend') as DragEvent, true);\n }\n\n stopTouch?.();\n scopeState.handles.delete(handle_);\n restoreAttribute(element, 'role', originalContainerRole);\n cleanupItems();\n });\n\n scopeState.handles.add(handle_);\n stopTouch = scopeState.touch?.register(element);\n\n if (originalContainerRole === null) element.setAttribute('role', 'list');\n\n element.addEventListener('dragstart', handleDragStart, { signal: disposable.disposalSignal });\n element.addEventListener('dragover', handleDragOver, { signal: disposable.disposalSignal });\n element.addEventListener('drop', handleDrop, { signal: disposable.disposalSignal });\n element.addEventListener('dragend', handleDragEnd, { signal: disposable.disposalSignal });\n element.addEventListener('keydown', handleKeydown, { signal: disposable.disposalSignal });\n\n // Register with scope so scope.dispose() can tear this down\n scopeState.disposables.add(disposable.dispose);\n\n return {\n get disposalSignal() {\n return disposable.disposalSignal;\n },\n dispose: disposable.dispose,\n get disposed() {\n return disposable.disposed;\n },\n get isDragging() {\n return scopeState.active?.source === handle_;\n },\n [Symbol.dispose]: disposable[Symbol.dispose],\n refresh: () => {\n markItems();\n },\n };\n}\n\n// ─── applyReorder ─────────────────────────────────────────────────────────────\n\n/**\n * Applies a sorted key array to a backing data array.\n * Unknown keys are ignored; omitted items are appended and duplicate backing keys throw `DndError`.\n */\nexport function applyReorder<T>(items: readonly T[], ids: readonly string[], getKey: (item: T) => string): T[] {\n const byId = new Map<string, T>();\n\n for (const item of items) {\n const id = getKey(item);\n if (byId.has(id)) throw new DndError(`Duplicate item key: \"${id}\"`);\n byId.set(id, item);\n }\n const ordered: T[] = [];\n\n for (const id of ids) {\n if (!byId.has(id)) continue;\n\n const item = byId.get(id) as T;\n\n ordered.push(item);\n byId.delete(id);\n }\n\n for (const item of byId.values()) ordered.push(item);\n\n return ordered;\n}\n\nexport { DndError, DndScopeError } from './errors.js';\nexport type { Disposable } from './types.js';\n"],"mappings":"gNAUA,IAAM,EAAc,OAAO,eAAe,EA6QpC,EAAc,kBACd,EAAY,gBACZ,EAAsB,IAAI,QAC1B,EAAiD,CACrD,UAAW,GAC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AiB,WAAY,eAAgB,CAAE,OAAQ,EAAW,cAAe,CAAC,EAC1F,EAAQ,iBAAiB,OAAQ,WAAY,CAAE,OAAQ,EAAW,cAAe,CAAC,EAClF,EAAQ,iBAAiB,UAAW,cAAe,CAAE,OAAQ,EAAW,cAAe,CAAC,EACxF,EAAQ,iBAAiB,UAAW,cAAe,CAAE,OAAQ,EAAW,cAAe,CAAC,EAGxF,EAAW,YAAY,IAAI,EAAW,OAAO,EAEtC,CACL,IAAI,gBAAiB,CACnB,OAAO,EAAW,cACpB,EACA,QAAS,EAAW,QACpB,IAAI,UAAW,CACb,OAAO,EAAW,QACpB,EACA,IAAI,YAAa,CACf,OAAO,EAAW,QAAQ,SAAW,CACvC,GACC,OAAO,SAAU,EAAW,OAAO,SACpC,YAAe,CACb,UAAU,CACZ,CACF,CACF,CAQA,SAAgB,aAAgB,EAAqB,EAAwB,EAAkC,CAC7G,IAAM,EAAO,IAAI,IAEjB,IAAK,IAAM,KAAQ,EAAO,CACxB,IAAM,EAAK,EAAO,CAAI,EACtB,GAAI,EAAK,IAAI,CAAE,EAAG,MAAM,IAAI,EAAA,SAAS,wBAAwB,EAAG,EAAE,EAClE,EAAK,IAAI,EAAI,CAAI,CACnB,CACA,IAAM,EAAe,CAAC,EAEtB,IAAK,IAAM,KAAM,EAAK,CACpB,GAAI,CAAC,EAAK,IAAI,CAAE,EAAG,SAEnB,IAAM,EAAO,EAAK,IAAI,CAAE,EAExB,EAAQ,KAAK,CAAI,EACjB,EAAK,OAAO,CAAE,CAChB,CAEA,IAAK,IAAM,KAAQ,EAAK,OAAO,EAAG,EAAQ,KAAK,CAAI,EAEnD,OAAO,CACT"}
@@ -1,14 +1,9 @@
1
- import { type TouchInputOptions } from './_touch';
2
- import type { Disposable } from './types';
1
+ import { type TouchInputOptions } from './_touch.js';
2
+ import type { Disposable } from './types.js';
3
3
  declare const SCOPE_BRAND: unique symbol;
4
4
  export interface SortableScope extends Disposable {
5
5
  /** `true` while any sortable in this scope is actively dragging. */
6
6
  readonly isDragging: boolean;
7
- /**
8
- * Calls the revert function registered for the most recent cross-container move.
9
- * A no-op when no move registered a revert function.
10
- */
11
- revert(): void;
12
7
  readonly [SCOPE_BRAND]: true;
13
8
  }
14
9
  export interface AutoScrollOptions {
@@ -23,40 +18,33 @@ export interface AutoScrollOptions {
23
18
  }
24
19
  /**
25
20
  * Passed to `onReorder` after every successful reorder (drag or keyboard).
21
+ * Application history owns rollback — use `before`/`after`/`item` to record
22
+ * an undo entry.
26
23
  */
27
24
  export interface ReorderEvent {
28
- /** The new ordered list of item keys after the reorder. */
29
- ids: string[];
30
- /**
31
- * Register a revert function that will be called when `sortable.revert()` is invoked.
32
- * Useful for rolling back optimistic UI updates on server error.
33
- * Only the most recent `setRevert` registration is retained — a new reorder overwrites it.
34
- *
35
- * @example
36
- * ```ts
37
- * onReorder: ({ ids, setRevert }) => {
38
- * const prev = order;
39
- * setOrder(ids);
40
- * setRevert(() => setOrder(prev));
41
- * },
42
- * ```
43
- */
44
- setRevert(fn: () => void): void;
25
+ /** Item keys after the reorder. */
26
+ after: readonly string[];
27
+ /** Item keys before the reorder. */
28
+ before: readonly string[];
29
+ /** Stable identity of the moved item. */
30
+ item: string;
45
31
  }
46
32
  /** A single committed move between two containers in the same sortable scope. */
47
33
  export interface SortableMoveEvent {
48
34
  /** Stable identity of the moved item. */
49
35
  readonly itemId: string;
50
- /** Registers a rollback for the most recent scope move. */
51
- setRevert(fn: () => void): void;
52
36
  /** Source container before the move. */
53
37
  readonly source: HTMLElement;
38
+ /** Ordered source item IDs before the move. */
39
+ readonly sourceBeforeIds: readonly string[];
54
40
  /** Ordered source item IDs after the move. */
55
- readonly sourceIds: string[];
41
+ readonly sourceIds: readonly string[];
56
42
  /** Target container after the move. */
57
43
  readonly target: HTMLElement;
44
+ /** Ordered target item IDs before the move. */
45
+ readonly targetBeforeIds: readonly string[];
58
46
  /** Ordered target item IDs after the move. */
59
- readonly targetIds: string[];
47
+ readonly targetIds: readonly string[];
60
48
  }
61
49
  /**
62
50
  * Structured accessibility/observability event for sortable interactions.
@@ -147,6 +135,12 @@ export interface SortableOptions {
147
135
  * When omitted the whole item is the handle.
148
136
  */
149
137
  handle?: string;
138
+ /**
139
+ * Returns the current sortable item elements. When omitted the sortable
140
+ * scans the container's direct children. Provide this for explicit item
141
+ * ownership — e.g. when items are managed by a framework render loop.
142
+ */
143
+ items?: () => readonly HTMLElement[];
150
144
  /**
151
145
  * Enables keyboard-based reordering using arrow keys plus Home/End.
152
146
  * @default true
@@ -164,7 +158,7 @@ export interface SortableOptions {
164
158
  * }
165
159
  * ```
166
160
  */
167
- onBeforeReorder?: (from: string[], to: string[]) => void;
161
+ onBeforeReorder?: (from: readonly string[], to: readonly string[]) => void;
168
162
  /** Called when a drag ends (whether dropped or cancelled). */
169
163
  onDragEnd?: (id: string, event: DragEvent) => void;
170
164
  /** Called when the user starts dragging an item. */
@@ -176,13 +170,13 @@ export interface SortableOptions {
176
170
  onInteraction?: (event: SortableInteractionEvent) => void;
177
171
  /**
178
172
  * Called with a {@link ReorderEvent} after a successful reorder, only when the order changed.
173
+ * The event carries `before`, `after`, and `item` so application history can own rollback.
179
174
  *
180
175
  * @example
181
176
  * ```ts
182
- * onReorder: ({ ids, setRevert }) => {
183
- * const prev = order;
184
- * setOrder(ids);
185
- * setRevert(() => setOrder(prev));
177
+ * onReorder: ({ before, after, item }) => {
178
+ * history.push({ revert: () => setOrder(before) });
179
+ * setOrder(after);
186
180
  * },
187
181
  * ```
188
182
  */
@@ -195,39 +189,19 @@ export interface SortableOptions {
195
189
  export interface Sortable extends Disposable {
196
190
  readonly isDragging: boolean;
197
191
  /**
198
- * Calls the revert function registered via `setRevert` in the last `onReorder` invocation (if any) and clears it.
199
- * A no-op when no revert function was registered or has already been consumed.
200
- *
201
- * Works for both drag-based and keyboard-based reorders.
202
- * Note: only the most recent reorder can be reverted; a new reorder overwrites the stored function.
203
- *
204
- * @example
205
- * ```ts
206
- * onReorder: ({ ids, setRevert }) => {
207
- * const prev = order;
208
- * setOrder(ids);
209
- * setRevert(() => setOrder(prev));
210
- * },
211
- * // later, on server error:
212
- * sortable.revert();
213
- * ```
214
- */
215
- revert(): void;
216
- /**
217
- * Re-reads the container's children and reapplies `draggable`, ARIA roles,
218
- * and handle attributes. Call this after programmatically adding, removing,
219
- * or replacing items — e.g. after a framework render that replaces DOM nodes.
192
+ * Re-reads items from the `items` provider (or the container's direct children)
193
+ * and reapplies `draggable`, ARIA roles, and handle attributes. Call this after
194
+ * programmatically adding, removing, or replacing items — e.g. after a framework
195
+ * render that replaces DOM nodes.
220
196
  *
221
197
  * Not needed when items are only reordered via drag or keyboard.
222
198
  */
223
- sync(): void;
199
+ refresh(): void;
224
200
  }
225
201
  /**
226
202
  * Create a shared scope for connected sortable containers.
227
203
  *
228
204
  * Items can be dragged between all sortables that share the same scope.
229
- * The scope exposes `isDragging` and `dispose()` — calling `dispose()` tears down
230
- * all member sortables at once.
231
205
  *
232
206
  * @example
233
207
  * ```ts
@@ -252,15 +226,14 @@ export declare function createSortableScope(options?: SortableScopeOptions): Sor
252
226
  *
253
227
  * @example
254
228
  * ```ts
255
- * import { createSortable } from '@vielzeug/dnd';
229
+ * import { createSortable } from '@vielzeug/dnd/sortable';
256
230
  *
257
231
  * using sortable = createSortable({
258
232
  * element: listEl,
259
233
  * getKey: (el) => el.dataset.id!,
260
- * onReorder: ({ ids, setRevert }) => {
261
- * const prev = order;
262
- * setOrder(ids);
263
- * setRevert(() => setOrder(prev));
234
+ * onReorder: ({ before, after }) => {
235
+ * history.push({ revert: () => setOrder(before) });
236
+ * setOrder(after);
264
237
  * },
265
238
  * });
266
239
  * ```
@@ -268,8 +241,9 @@ export declare function createSortableScope(options?: SortableScopeOptions): Sor
268
241
  export declare function createSortable(options: SortableOptions): Sortable;
269
242
  /**
270
243
  * Applies a sorted key array to a backing data array.
271
- * Unknown keys are ignored; items not present in `ids` are appended in original order.
244
+ * Unknown keys are ignored; omitted items are appended and duplicate backing keys throw `DndError`.
272
245
  */
273
- export declare function applyReorder<T>(items: T[], ids: string[], getKey: (item: T) => string): T[];
274
- export {};
246
+ export declare function applyReorder<T>(items: readonly T[], ids: readonly string[], getKey: (item: T) => string): T[];
247
+ export { DndError, DndScopeError } from './errors.js';
248
+ export type { Disposable } from './types.js';
275
249
  //# sourceMappingURL=sortable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sortable.d.ts","sourceRoot":"","sources":["../src/sortable.ts"],"names":[],"mappings":"AAEA,OAAO,EAAyD,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAEzG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAI1C,QAAA,MAAM,WAAW,eAA0B,CAAC;AAE5C,MAAM,WAAW,aAAc,SAAQ,UAAU;IAC/C,oEAAoE;IACpE,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B;;;OAGG;IACH,MAAM,IAAI,IAAI,CAAC;IACf,QAAQ,CAAC,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC;CAC9B;AAID,MAAM,WAAW,iBAAiB;IAChC,iFAAiF;IACjF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,6EAA6E;IAC7E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,yEAAyE;IACzE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,2DAA2D;IAC3D,GAAG,EAAE,MAAM,EAAE,CAAC;IACd;;;;;;;;;;;;;OAaG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;CACjC;AAED,iFAAiF;AACjF,MAAM,WAAW,iBAAiB;IAChC,yCAAyC;IACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI,GAA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