@vielzeug/dnd 26.10.0 → 26.10.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"drop-zone.js","names":[],"sources":["../src/drop-zone.ts"],"sourcesContent":["import { warn } from './_dev.js';\nimport { createDisposable, resolveDisabled } from './_shared.js';\nimport { DndError } from './errors.js';\nimport type { Disposable } from './types.js';\n\n// ─── Accept matching ─────────────────────────────────────────────────────────\n\n/**\n * Test whether a `File` matches an accept pattern list.\n *\n * Each pattern can be:\n * - A MIME type: `'image/png'`\n * - A MIME wildcard: `'image/*'`\n * - A file extension: `'.pdf'`\n *\n * An empty list accepts everything.\n */\nexport function matchesAccept(file: File, accept: readonly string[]): boolean {\n if (!accept.length) return true;\n\n return accept.some((pattern) => {\n const p = pattern.trim().toLowerCase();\n const type = file.type.toLowerCase();\n\n if (!p) return false;\n if (p.startsWith('.')) return file.name.toLowerCase().endsWith(p);\n if (p.endsWith('/*')) return type.startsWith(p.slice(0, -1));\n\n return type === p;\n });\n}\n\n// ─── Types ────────────────────────────────────────────────────────────────────\n\nexport interface DropZoneOptions {\n /**\n * Accepted file types. Each entry may be:\n * - A MIME type: 'image/png'\n * - A MIME wildcard: 'image/*'\n * - A file extension: '.pdf'\n *\n * When empty the zone accepts everything.\n */\n accept?: readonly string[];\n /**\n * When `true`, all drag events are ignored and hover state does not change.\n *\n * Note: a disabled zone does not call `preventDefault` on drag or paste events,\n * so underlying elements (such as text editors) will still receive them.\n */\n disabled?: boolean;\n /**\n * The `dropEffect` to set on `dataTransfer` during `dragover`.\n * @default 'copy'\n */\n dropEffect?: DataTransfer['dropEffect'];\n /** The element to attach drag listeners to. */\n element: HTMLElement;\n /**\n * Maximum number of files accepted per drop. Files beyond this limit are\n * treated as rejected and forwarded to `onDropRejected`.\n *\n * When omitted there is no limit.\n */\n maxFiles?: number;\n /** Called when files are dropped or pasted (when `paste: true` and `onPaste` is omitted). Receives accepted files only. */\n onDrop?: (files: File[]) => void;\n /**\n * Called when dropped or pasted files are rejected by the `accept` filter, `maxFiles` limit, or `onValidate`.\n */\n onDropRejected?: (files: File[]) => void;\n /**\n * Called whenever hover state toggles.\n * Use this for drag-over styling.\n */\n onHoverChange?: (hovered: boolean) => void;\n /**\n * Called when files are pasted via the clipboard. Falls back to `onDrop` when omitted.\n * Only active when `paste: true`.\n */\n onPaste?: (files: File[]) => void;\n /**\n * Optional async file gating. Called after type/extension filtering, before `onDrop`.\n * Return (or resolve) `false` to move all type-accepted files to `onDropRejected`.\n *\n * Only receives type-accepted files (after `accept` and `maxFiles` filtering).\n * Files already rejected by the `accept` filter are forwarded to `onDropRejected`\n * unconditionally and are not passed to this function.\n *\n * While validation is in progress `zone.validating` is `true` and `onValidatingChange`\n * is called with `true`.\n *\n * @example\n * ```ts\n * onValidate: async (files, { signal }) => {\n * const ok = await checkServerQuota(files, { signal });\n * return ok;\n * }\n * ```\n */\n onValidate?: (files: File[], context: DropValidationContext) => boolean | Promise<boolean>;\n /**\n * Called whenever the async validation state changes.\n * Use this to drive loading spinners.\n *\n * @example\n * ```ts\n * onValidatingChange: (v) => { spinnerEl.hidden = !v; }\n * ```\n */\n onValidatingChange?: (validating: boolean) => void;\n /**\n * When `true`, a `paste` event listener is added to the drop-zone element. Pasted files run\n * through the same `accept`, `maxFiles`, and `onValidate` pipeline as dropped files.\n * @default false\n */\n paste?: boolean;\n}\n\nexport interface DropValidationContext {\n /** Aborts when the zone is disposed. Pass this to validation requests. */\n readonly signal: AbortSignal;\n}\n\nexport interface DropZone extends Disposable {\n /** Whether the pointer is currently dragging over the zone. */\n readonly hovered: boolean;\n /** `true` while an `onValidate` promise is pending. */\n readonly validating: boolean;\n}\n\n// ─── Internal helpers ─────────────────────────────────────────────────────────\n\n/**\n * DataTransferItem does not expose file names, so extension patterns (for example\n * `.pdf`) cannot be validated during drag-over. We treat these as a permissive\n * pre-check and perform exact filtering in `handleDrop` when `File` objects exist.\n */\nfunction itemsMatchAccept(items: DataTransferItemList, accept: string[]): boolean {\n if (!accept.length) return true;\n\n return Array.from(items).some(\n (item) =>\n item.kind === 'file' &&\n accept.some((pattern) => {\n const p = pattern.trim();\n\n if (p.endsWith('/*')) return item.type.startsWith(p.slice(0, -1));\n\n if (p.startsWith('.')) return true; // extension cannot be checked from DataTransferItem\n\n return item.type === p;\n }),\n );\n}\n\n/**\n * Filter `files` through `accept` patterns and `maxFiles` limit.\n * Returns accepted and rejected arrays.\n */\nfunction applyFileFilters(\n files: File[],\n accept: string[],\n maxFiles: number | undefined,\n): { accepted: File[]; rejected: File[] } {\n const accepted: File[] = [];\n const rejected: File[] = [];\n\n for (const f of files) {\n (matchesAccept(f, accept) ? accepted : rejected).push(f);\n }\n\n if (maxFiles !== undefined && accepted.length > maxFiles) {\n rejected.push(...accepted.splice(maxFiles));\n }\n\n return { accepted, rejected };\n}\n\n// ─── createDropZone ───────────────────────────────────────────────────────────\n\nfunction normalizeAccept(patterns: readonly string[]): string[] {\n return patterns.map((pattern) => {\n const normalized = pattern.trim().toLowerCase();\n const extension = /^\\.[a-z0-9][a-z0-9._+-]*$/.test(normalized);\n const mime = /^[a-z0-9!#$&^_.+-]+\\/(?:\\*|[a-z0-9!#$&^_.+-]+)$/.test(normalized);\n\n if (!extension && !mime) throw new DndError(`Invalid accept pattern: \"${pattern}\"`);\n return normalized;\n });\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/**\n * Attach drag-and-drop behaviour to a DOM element.\n *\n * Accepts files and provides hover state management with configurable MIME/extension filtering.\n * Calls `onDrop` only for accepted files and `onDropRejected` for filtered files.\n *\n * @example\n * ```ts\n * import { createDropZone } from '@vielzeug/dnd';\n *\n * using zone = createDropZone({\n * element: dropZoneEl,\n * accept: ['image/*', '.pdf'],\n * maxFiles: 5,\n * onDrop: (files) => { console.log('Dropped:', files); },\n * onHoverChange: (hovered) => {\n * dropZoneEl.classList.toggle('drag-over', hovered);\n * },\n * });\n * ```\n */\nexport function createDropZone(options: DropZoneOptions): DropZone {\n const accept = normalizeAccept(options.accept ?? []);\n if (options.maxFiles !== undefined && (!Number.isSafeInteger(options.maxFiles) || options.maxFiles < 0)) {\n throw new DndError('maxFiles must be a non-negative safe integer');\n }\n\n const { dropEffect = 'copy', element, maxFiles, onDrop, onDropRejected, onHoverChange, onValidatingChange } = options;\n\n let dragCounter = 0;\n // Whether the *current* drag's payload passes the accept filter.\n // Determined on the first dragenter and held for the duration of the drag.\n let dragAccepted = false;\n let validating = false;\n const validationControllers = new Set<AbortController>();\n\n const setValidating = (next: boolean): void => {\n if (validating === next) return;\n\n validating = next;\n notify('onValidatingChange', onValidatingChange, next);\n };\n\n const updateCounter = (next: number): void => {\n const wasHovered = dragCounter > 0 && dragAccepted;\n\n dragCounter = Math.max(0, next);\n\n // Reset acceptance state when the drag fully leaves so the next drag starts clean.\n if (dragCounter === 0) dragAccepted = false;\n\n const hovered = dragCounter > 0 && dragAccepted;\n\n if (hovered !== wasHovered) notify('onHoverChange', onHoverChange, hovered);\n };\n\n const resetCounter = (): void => {\n updateCounter(0);\n };\n\n const disposable = createDisposable(() => {\n for (const controller of validationControllers) controller.abort();\n\n validationControllers.clear();\n setValidating(false);\n resetCounter();\n });\n\n // Settle the final accepted/rejected split and fire callbacks.\n const settle = (acceptedFiles: File[], rejectedFiles: File[]): void => {\n if (acceptedFiles.length > 0) notify('onDrop', onDrop, [...acceptedFiles]);\n if (rejectedFiles.length > 0) notify('onDropRejected', onDropRejected, [...rejectedFiles]);\n };\n\n // Settle for paste events (which may use onPaste instead of onDrop).\n const settleForPaste = (acceptedFiles: File[], rejectedFiles: File[]): void => {\n if (acceptedFiles.length > 0) {\n if (options.onPaste) {\n notify('onPaste', options.onPaste, [...acceptedFiles]);\n } else {\n notify('onDrop', onDrop, [...acceptedFiles]);\n }\n }\n\n if (rejectedFiles.length > 0) notify('onDropRejected', onDropRejected, [...rejectedFiles]);\n };\n\n // Run accept/maxFiles filter, then async onValidate, then settle.\n const dispatchWithValidation = (rawFiles: File[], settleFn: (accepted: File[], rejected: File[]) => void): void => {\n const { accepted, rejected: rej } = applyFileFilters(rawFiles, accept, maxFiles);\n const onValidate = options.onValidate;\n const validationController = onValidate && accepted.length > 0 ? new AbortController() : null;\n\n if (validationController) {\n validationControllers.add(validationController);\n setValidating(true);\n }\n\n const finishValidation = (): void => {\n if (!validationController) return;\n\n validationControllers.delete(validationController);\n\n if (!disposable.disposed) setValidating(validationControllers.size > 0);\n };\n\n let validation: boolean | Promise<boolean>;\n\n try {\n validation =\n validationController && onValidate ? onValidate([...accepted], { signal: validationController.signal }) : true;\n } catch (error) {\n validation = Promise.reject(error);\n }\n\n void Promise.resolve(validation).then(\n (valid) => {\n finishValidation();\n\n if (disposable.disposed) return;\n\n if (valid === true) {\n settleFn(accepted, rej);\n } else {\n settleFn([], [...rej, ...accepted]);\n }\n },\n () => {\n finishValidation();\n\n if (disposable.disposed) return;\n\n settleFn([], [...rej, ...accepted]);\n },\n );\n };\n\n const handleDragEnter = (e: DragEvent): void => {\n if (resolveDisabled(options.disabled)) return;\n\n e.preventDefault();\n\n // Evaluate the filter once per drag (on first entry) — the payload is\n // constant for the lifetime of a drag operation.\n if (dragCounter === 0) {\n const items = e.dataTransfer?.items;\n\n dragAccepted = !accept.length || !items?.length || itemsMatchAccept(items, accept);\n }\n\n if (!dragAccepted && e.dataTransfer) {\n e.dataTransfer.dropEffect = 'none';\n }\n\n // Always increment so every dragenter is paired with its dragleave,\n // regardless of acceptance. This prevents counter under-runs.\n updateCounter(dragCounter + 1);\n };\n\n const handleDragOver = (e: DragEvent): void => {\n if (resolveDisabled(options.disabled)) return;\n\n e.preventDefault();\n\n if (e.dataTransfer) e.dataTransfer.dropEffect = dragAccepted ? dropEffect : 'none';\n };\n\n const handleDragLeave = (_e: DragEvent): void => {\n // Always decrement to balance the paired dragenter — disabling after enter\n // must not leave the counter permanently incremented.\n updateCounter(dragCounter - 1);\n };\n\n const handleDrop = (e: DragEvent): void => {\n // Reset counter first (idempotent at 0) so hover never sticks even when disabled.\n resetCounter();\n\n if (resolveDisabled(options.disabled)) return;\n\n e.preventDefault();\n\n const raw = e.dataTransfer?.files;\n\n if (!raw) return;\n\n dispatchWithValidation(Array.from(raw), settle);\n };\n\n const handlePaste = (e: ClipboardEvent): void => {\n if (resolveDisabled(options.disabled)) return;\n\n const clipFiles = e.clipboardData?.files;\n\n if (!clipFiles?.length) return;\n\n e.preventDefault();\n dispatchWithValidation(Array.from(clipFiles), settleForPaste);\n };\n\n element.addEventListener('dragenter', handleDragEnter, { signal: disposable.disposalSignal });\n element.addEventListener('dragover', handleDragOver, { signal: disposable.disposalSignal });\n element.addEventListener('dragleave', handleDragLeave, { signal: disposable.disposalSignal });\n element.addEventListener('drop', handleDrop, { signal: disposable.disposalSignal });\n\n if (options.paste) element.addEventListener('paste', handlePaste, { signal: disposable.disposalSignal });\n\n // These global listeners catch drags that end outside the zone.\n // The window 'drop' also fires for in-zone drops, but resetCounter() is idempotent at counter=0.\n window.addEventListener('dragend', resetCounter, { signal: disposable.disposalSignal });\n window.addEventListener('drop', resetCounter, { signal: disposable.disposalSignal });\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 hovered() {\n return dragCounter > 0 && dragAccepted;\n },\n [Symbol.dispose]: disposable[Symbol.dispose],\n get validating() {\n return validating;\n },\n };\n}\n"],"mappings":"8HAiBA,SAAgB,cAAc,EAAY,EAAoC,CAG5E,MAFA,CAAK,EAAO,QAEL,EAAO,KAAM,GAAY,CAC9B,IAAM,EAAI,EAAQ,KAAK,CAAC,CAAC,YAAY,EAC/B,EAAO,EAAK,KAAK,YAAY,EAMnC,OAJK,EACD,EAAE,WAAW,GAAG,EAAU,EAAK,K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,IAAM,EAAM,EAAE,cAAc,MAEvB,GAEL,uBAAuB,MAAM,KAAK,CAAG,EAAG,MAAM,CAChD,EAEM,YAAe,GAA4B,CAC/C,GAAI,EAAgB,EAAQ,QAAQ,EAAG,OAEvC,IAAM,EAAY,EAAE,eAAe,MAE9B,GAAW,SAEhB,EAAE,eAAe,EACjB,uBAAuB,MAAM,KAAK,CAAS,EAAG,cAAc,EAC9D,EAcA,OAZA,EAAQ,iBAAiB,YAAa,gBAAiB,CAAE,OAAQ,EAAW,cAAe,CAAC,EAC5F,EAAQ,iBAAiB,WAAY,eAAgB,CAAE,OAAQ,EAAW,cAAe,CAAC,EAC1F,EAAQ,iBAAiB,YAAa,gBAAiB,CAAE,OAAQ,EAAW,cAAe,CAAC,EAC5F,EAAQ,iBAAiB,OAAQ,WAAY,CAAE,OAAQ,EAAW,cAAe,CAAC,EAE9E,EAAQ,OAAO,EAAQ,iBAAiB,QAAS,YAAa,CAAE,OAAQ,EAAW,cAAe,CAAC,EAIvG,OAAO,iBAAiB,UAAW,aAAc,CAAE,OAAQ,EAAW,cAAe,CAAC,EACtF,OAAO,iBAAiB,OAAQ,aAAc,CAAE,OAAQ,EAAW,cAAe,CAAC,EAE5E,CACL,IAAI,gBAAiB,CACnB,OAAO,EAAW,cACpB,EACA,QAAS,EAAW,QACpB,IAAI,UAAW,CACb,OAAO,EAAW,QACpB,EACA,IAAI,SAAU,CACZ,OAAO,EAAc,GAAK,CAC5B,GACC,OAAO,SAAU,EAAW,OAAO,SACpC,IAAI,YAAa,CACf,OAAO,CACT,CACF,CACF"}
1
+ {"version":3,"file":"drop-zone.js","names":[],"sources":["../src/drop-zone.ts"],"sourcesContent":["import { warn } from './_dev.js';\nimport { createDisposable, resolveDisabled } from './_shared.js';\nimport { DndError } from './errors.js';\nimport type { Disposable } from './types.js';\n\n// ─── Accept matching ─────────────────────────────────────────────────────────\n\n/**\n * Test whether a `File` matches an accept pattern list.\n *\n * Each pattern can be:\n * - A MIME type: `'image/png'`\n * - A MIME wildcard: `'image/*'`\n * - A file extension: `'.pdf'`\n *\n * An empty list accepts everything.\n */\nexport function matchesAccept(file: File, accept: readonly string[]): boolean {\n if (!accept.length) return true;\n\n return accept.some((pattern) => {\n const p = pattern.trim().toLowerCase();\n const type = file.type.toLowerCase();\n\n if (!p) return false;\n if (p.startsWith('.')) return file.name.toLowerCase().endsWith(p);\n if (p.endsWith('/*')) return type.startsWith(p.slice(0, -1));\n\n return type === p;\n });\n}\n\n// ─── Types ────────────────────────────────────────────────────────────────────\n\nexport interface DropZoneOptions {\n /**\n * Accepted file types. Each entry may be:\n * - A MIME type: 'image/png'\n * - A MIME wildcard: 'image/*'\n * - A file extension: '.pdf'\n *\n * When empty the zone accepts everything.\n */\n accept?: readonly string[];\n /**\n * When `true`, all drag events are ignored and hover state does not change.\n *\n * Note: a disabled zone does not call `preventDefault` on drag or paste events,\n * so underlying elements (such as text editors) will still receive them.\n */\n disabled?: boolean;\n /**\n * The `dropEffect` to set on `dataTransfer` during `dragover`.\n * @default 'copy'\n */\n dropEffect?: DataTransfer['dropEffect'];\n /** The element to attach drag listeners to. */\n element: HTMLElement;\n /**\n * Maximum number of files accepted per drop. Files beyond this limit are\n * treated as rejected and forwarded to `onDropRejected`.\n *\n * When omitted there is no limit.\n */\n maxFiles?: number;\n /** Called when files are dropped or pasted (when `paste: true` and `onPaste` is omitted). Receives accepted files only. */\n onDrop?: (files: File[]) => void;\n /**\n * Called when dropped or pasted files are rejected by the `accept` filter, `maxFiles` limit, or `onValidate`.\n */\n onDropRejected?: (files: File[]) => void;\n /**\n * Called whenever hover state toggles.\n * Use this for drag-over styling.\n */\n onHoverChange?: (hovered: boolean) => void;\n /**\n * Called when files are pasted via the clipboard. Falls back to `onDrop` when omitted.\n * Only active when `paste: true`.\n */\n onPaste?: (files: File[]) => void;\n /**\n * Optional async file gating. Called after type/extension filtering, before `onDrop`.\n * Return (or resolve) `false` to move all type-accepted files to `onDropRejected`.\n *\n * Only receives type-accepted files (after `accept` and `maxFiles` filtering).\n * Files already rejected by the `accept` filter are forwarded to `onDropRejected`\n * unconditionally and are not passed to this function.\n *\n * While validation is in progress `zone.validating` is `true` and `onValidatingChange`\n * is called with `true`.\n *\n * @example\n * ```ts\n * onValidate: async (files, { signal }) => {\n * const ok = await checkServerQuota(files, { signal });\n * return ok;\n * }\n * ```\n */\n onValidate?: (files: File[], context: DropValidationContext) => boolean | Promise<boolean>;\n /**\n * Called whenever the async validation state changes.\n * Use this to drive loading spinners.\n *\n * @example\n * ```ts\n * onValidatingChange: (v) => { spinnerEl.hidden = !v; }\n * ```\n */\n onValidatingChange?: (validating: boolean) => void;\n /**\n * When `true`, a `paste` event listener is added to the drop-zone element. Pasted files run\n * through the same `accept`, `maxFiles`, and `onValidate` pipeline as dropped files.\n * @default false\n */\n paste?: boolean;\n}\n\nexport interface DropValidationContext {\n /** Aborts when the zone is disposed. Pass this to validation requests. */\n readonly signal: AbortSignal;\n}\n\nexport interface DropZone extends Disposable {\n /** Whether the pointer is currently dragging over the zone. */\n readonly hovered: boolean;\n /** `true` while an `onValidate` promise is pending. */\n readonly validating: boolean;\n}\n\n// ─── Internal helpers ─────────────────────────────────────────────────────────\n\n/**\n * DataTransferItem does not expose file names, so extension patterns (for example\n * `.pdf`) cannot be validated during drag-over. We treat these as a permissive\n * pre-check and perform exact filtering in `handleDrop` when `File` objects exist.\n */\nfunction itemsMatchAccept(items: DataTransferItemList, accept: string[]): boolean {\n if (!accept.length) return true;\n\n return Array.from(items).some(\n (item) =>\n item.kind === 'file' &&\n accept.some((pattern) => {\n const p = pattern.trim();\n\n if (p.endsWith('/*')) return item.type.startsWith(p.slice(0, -1));\n\n if (p.startsWith('.')) return true; // extension cannot be checked from DataTransferItem\n\n return item.type === p;\n }),\n );\n}\n\n/**\n * Filter `files` through `accept` patterns and `maxFiles` limit.\n * Returns accepted and rejected arrays.\n */\nfunction applyFileFilters(\n files: File[],\n accept: string[],\n maxFiles: number | undefined,\n): { accepted: File[]; rejected: File[] } {\n const accepted: File[] = [];\n const rejected: File[] = [];\n\n for (const f of files) {\n (matchesAccept(f, accept) ? accepted : rejected).push(f);\n }\n\n if (maxFiles !== undefined && accepted.length > maxFiles) {\n rejected.push(...accepted.splice(maxFiles));\n }\n\n return { accepted, rejected };\n}\n\n// ─── createDropZone ───────────────────────────────────────────────────────────\n\nfunction normalizeAccept(patterns: readonly string[]): string[] {\n return patterns.map((pattern) => {\n const normalized = pattern.trim().toLowerCase();\n const extension = /^\\.[a-z0-9][a-z0-9._+-]*$/.test(normalized);\n const mime = /^[a-z0-9!#$&^_.+-]+\\/(?:\\*|[a-z0-9!#$&^_.+-]+)$/.test(normalized);\n\n if (!extension && !mime) throw new DndError(`Invalid accept pattern: \"${pattern}\"`);\n return normalized;\n });\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/**\n * Attach drag-and-drop behaviour to a DOM element.\n *\n * Accepts files and provides hover state management with configurable MIME/extension filtering.\n * Calls `onDrop` only for accepted files and `onDropRejected` for filtered files.\n *\n * @example\n * ```ts\n * import { createDropZone } from '@vielzeug/dnd';\n *\n * using zone = createDropZone({\n * element: dropZoneEl,\n * accept: ['image/*', '.pdf'],\n * maxFiles: 5,\n * onDrop: (files) => { console.log('Dropped:', files); },\n * onHoverChange: (hovered) => {\n * dropZoneEl.classList.toggle('drag-over', hovered);\n * },\n * });\n * ```\n */\nexport function createDropZone(options: DropZoneOptions): DropZone {\n const accept = normalizeAccept(options.accept ?? []);\n if (options.maxFiles !== undefined && (!Number.isSafeInteger(options.maxFiles) || options.maxFiles < 0)) {\n throw new DndError('maxFiles must be a non-negative safe integer');\n }\n\n const { dropEffect = 'copy', element, maxFiles, onDrop, onDropRejected, onHoverChange, onValidatingChange } = options;\n\n let dragCounter = 0;\n // Whether the *current* drag's payload passes the accept filter.\n // Determined on the first dragenter and held for the duration of the drag.\n let dragAccepted = false;\n let validating = false;\n const validationControllers = new Set<AbortController>();\n\n const setValidating = (next: boolean): void => {\n if (validating === next) return;\n\n validating = next;\n notify('onValidatingChange', onValidatingChange, next);\n };\n\n const updateCounter = (next: number): void => {\n const wasHovered = dragCounter > 0 && dragAccepted;\n\n dragCounter = Math.max(0, next);\n\n // Reset acceptance state when the drag fully leaves so the next drag starts clean.\n if (dragCounter === 0) dragAccepted = false;\n\n const hovered = dragCounter > 0 && dragAccepted;\n\n if (hovered !== wasHovered) notify('onHoverChange', onHoverChange, hovered);\n };\n\n const resetCounter = (): void => {\n updateCounter(0);\n };\n\n const disposable = createDisposable(() => {\n for (const controller of validationControllers) controller.abort();\n\n validationControllers.clear();\n setValidating(false);\n resetCounter();\n });\n\n // Settle the final accepted/rejected split and fire callbacks.\n const settle = (acceptedFiles: File[], rejectedFiles: File[]): void => {\n if (acceptedFiles.length > 0) notify('onDrop', onDrop, [...acceptedFiles]);\n if (rejectedFiles.length > 0) notify('onDropRejected', onDropRejected, [...rejectedFiles]);\n };\n\n // Settle for paste events (which may use onPaste instead of onDrop).\n const settleForPaste = (acceptedFiles: File[], rejectedFiles: File[]): void => {\n if (acceptedFiles.length > 0) {\n if (options.onPaste) {\n notify('onPaste', options.onPaste, [...acceptedFiles]);\n } else {\n notify('onDrop', onDrop, [...acceptedFiles]);\n }\n }\n\n if (rejectedFiles.length > 0) notify('onDropRejected', onDropRejected, [...rejectedFiles]);\n };\n\n // Run accept/maxFiles filter, then async onValidate, then settle.\n const dispatchWithValidation = (rawFiles: File[], settleFn: (accepted: File[], rejected: File[]) => void): void => {\n const { accepted, rejected: rej } = applyFileFilters(rawFiles, accept, maxFiles);\n const onValidate = options.onValidate;\n const validationController = onValidate && accepted.length > 0 ? new AbortController() : null;\n\n if (validationController) {\n validationControllers.add(validationController);\n setValidating(true);\n }\n\n const finishValidation = (): void => {\n if (!validationController) return;\n\n validationControllers.delete(validationController);\n\n if (!disposable.disposed) setValidating(validationControllers.size > 0);\n };\n\n let validation: boolean | Promise<boolean>;\n\n try {\n validation =\n validationController && onValidate ? onValidate([...accepted], { signal: validationController.signal }) : true;\n } catch (error) {\n validation = Promise.reject(error);\n }\n\n void Promise.resolve(validation).then(\n (valid) => {\n finishValidation();\n\n if (disposable.disposed) return;\n\n if (valid === true) {\n settleFn(accepted, rej);\n } else {\n settleFn([], [...rej, ...accepted]);\n }\n },\n () => {\n finishValidation();\n\n if (disposable.disposed) return;\n\n settleFn([], [...rej, ...accepted]);\n },\n );\n };\n\n const handleDragEnter = (e: DragEvent): void => {\n if (resolveDisabled(options.disabled)) return;\n\n e.preventDefault();\n\n // Evaluate the filter once per drag (on first entry): the payload is\n // constant for the lifetime of a drag operation.\n if (dragCounter === 0) {\n const items = e.dataTransfer?.items;\n\n dragAccepted = !accept.length || !items?.length || itemsMatchAccept(items, accept);\n }\n\n if (!dragAccepted && e.dataTransfer) {\n e.dataTransfer.dropEffect = 'none';\n }\n\n // Always increment so every dragenter is paired with its dragleave,\n // regardless of acceptance. This prevents counter under-runs.\n updateCounter(dragCounter + 1);\n };\n\n const handleDragOver = (e: DragEvent): void => {\n if (resolveDisabled(options.disabled)) return;\n\n e.preventDefault();\n\n if (e.dataTransfer) e.dataTransfer.dropEffect = dragAccepted ? dropEffect : 'none';\n };\n\n const handleDragLeave = (_e: DragEvent): void => {\n // Always decrement to balance the paired dragenter: disabling after enter\n // must not leave the counter permanently incremented.\n updateCounter(dragCounter - 1);\n };\n\n const handleDrop = (e: DragEvent): void => {\n // Reset counter first (idempotent at 0) so hover never sticks even when disabled.\n resetCounter();\n\n if (resolveDisabled(options.disabled)) return;\n\n e.preventDefault();\n\n const raw = e.dataTransfer?.files;\n\n if (!raw) return;\n\n dispatchWithValidation(Array.from(raw), settle);\n };\n\n const handlePaste = (e: ClipboardEvent): void => {\n if (resolveDisabled(options.disabled)) return;\n\n const clipFiles = e.clipboardData?.files;\n\n if (!clipFiles?.length) return;\n\n e.preventDefault();\n dispatchWithValidation(Array.from(clipFiles), settleForPaste);\n };\n\n element.addEventListener('dragenter', handleDragEnter, { signal: disposable.disposalSignal });\n element.addEventListener('dragover', handleDragOver, { signal: disposable.disposalSignal });\n element.addEventListener('dragleave', handleDragLeave, { signal: disposable.disposalSignal });\n element.addEventListener('drop', handleDrop, { signal: disposable.disposalSignal });\n\n if (options.paste) element.addEventListener('paste', handlePaste, { signal: disposable.disposalSignal });\n\n // These global listeners catch drags that end outside the zone.\n // The window 'drop' also fires for in-zone drops, but resetCounter() is idempotent at counter=0.\n window.addEventListener('dragend', resetCounter, { signal: disposable.disposalSignal });\n window.addEventListener('drop', resetCounter, { signal: disposable.disposalSignal });\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 hovered() {\n return dragCounter > 0 && dragAccepted;\n },\n [Symbol.dispose]: disposable[Symbol.dispose],\n get validating() {\n return validating;\n },\n };\n}\n"],"mappings":"8HAiBA,SAAgB,cAAc,EAAY,EAAoC,CAG5E,MAFA,CAAK,EAAO,QAEL,EAAO,KAAM,GAAY,CAC9B,IAAM,EAAI,EAAQ,KAAK,CAAC,CAAC,YAAY,EAC/B,EAAO,EAAK,KAAK,YAAY,EAMnC,OAJK,EACD,EAAE,WAAW,GAAG,EAAU,EAAK,KAAK,YAAY,CAAC,CAAC,SAAS,CAAC,EAC5D,EAAE,SAAS,IAAI,EAAU,EAAK,WAAW,EAAE,MAAM,EAAG,EAAE,CAAC,EAEpD,IAAS,EAJD,EAKjB,CAAC,CACH,CA4GA,SAAS,iBAAiB,EAA6B,EAA2B,CAGhF,MAFA,CAAK,EAAO,QAEL,MAAM,KAAK,CAAK,CAAC,CAAC,KACtB,GACC,EAAK,OAAS,QACd,EAAO,KAAM,GAAY,CACvB,IAAM,EAAI,EAAQ,KAAK,EAMvB,OAJI,EAAE,SAAS,IAAI,EAAU,EAAK,KAAK,WAAW,EAAE,MA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AW,cAAe,CAAC,EAC1F,EAAQ,iBAAiB,YAAa,gBAAiB,CAAE,OAAQ,EAAW,cAAe,CAAC,EAC5F,EAAQ,iBAAiB,OAAQ,WAAY,CAAE,OAAQ,EAAW,cAAe,CAAC,EAE9E,EAAQ,OAAO,EAAQ,iBAAiB,QAAS,YAAa,CAAE,OAAQ,EAAW,cAAe,CAAC,EAIvG,OAAO,iBAAiB,UAAW,aAAc,CAAE,OAAQ,EAAW,cAAe,CAAC,EACtF,OAAO,iBAAiB,OAAQ,aAAc,CAAE,OAAQ,EAAW,cAAe,CAAC,EAE5E,CACL,IAAI,gBAAiB,CACnB,OAAO,EAAW,cACpB,EACA,QAAS,EAAW,QACpB,IAAI,UAAW,CACb,OAAO,EAAW,QACpB,EACA,IAAI,SAAU,CACZ,OAAO,EAAc,GAAK,CAC5B,GACC,OAAO,SAAU,EAAW,OAAO,SACpC,IAAI,YAAa,CACf,OAAO,CACT,CACF,CACF"}
package/dist/errors.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var DndError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},DndScopeError=class extends DndError{constructor(e=`Invalid scope — use createSortableScope() to create scopes.`){super(e)}};exports.DndError=DndError,exports.DndScopeError=DndScopeError;
1
+ var DndError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},DndScopeError=class extends DndError{constructor(e=`Invalid scope: use createSortableScope() to create scopes.`){super(e)}};exports.DndError=DndError,exports.DndScopeError=DndScopeError;
2
2
  //# sourceMappingURL=errors.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all dnd errors. Use `instanceof DndError` to catch any dnd-originated error. */\nexport class DndError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a sortable action is called with an invalid scope not created by `createSortableScope()`. */\nexport class DndScopeError extends DndError {\n constructor(message = 'Invalid scope — use createSortableScope() to create scopes.') {\n super(message);\n }\n}\n"],"mappings":"AACA,IAAa,SAAb,cAA8B,KAAM,CAClC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,cAAb,cAAmC,QAAS,CAC1C,YAAY,EAAU,8DAA+D,CACnF,MAAM,CAAO,CACf,CACF"}
1
+ {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all dnd errors. Use `instanceof DndError` to catch any dnd-originated error. */\nexport class DndError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a sortable action is called with an invalid scope not created by `createSortableScope()`. */\nexport class DndScopeError extends DndError {\n constructor(message = 'Invalid scope: use createSortableScope() to create scopes.') {\n super(message);\n }\n}\n"],"mappings":"AACA,IAAa,SAAb,cAA8B,KAAM,CAClC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,cAAb,cAAmC,QAAS,CAC1C,YAAY,EAAU,6DAA8D,CAClF,MAAM,CAAO,CACf,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,qBAAa,QAAS,SAAQ,KAAK;gBACrB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAKjD;AAED,4GAA4G;AAC5G,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,OAAO,SAAgE;CAGpF"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,qBAAa,QAAS,SAAQ,KAAK;gBACrB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAKjD;AAED,4GAA4G;AAC5G,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,OAAO,SAA+D;CAGnF"}
package/dist/errors.js CHANGED
@@ -1,2 +1,2 @@
1
- var DndError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},DndScopeError=class extends DndError{constructor(e=`Invalid scope — use createSortableScope() to create scopes.`){super(e)}};export{DndError,DndScopeError};
1
+ var DndError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},DndScopeError=class extends DndError{constructor(e=`Invalid scope: use createSortableScope() to create scopes.`){super(e)}};export{DndError,DndScopeError};
2
2
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all dnd errors. Use `instanceof DndError` to catch any dnd-originated error. */\nexport class DndError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a sortable action is called with an invalid scope not created by `createSortableScope()`. */\nexport class DndScopeError extends DndError {\n constructor(message = 'Invalid scope — use createSortableScope() to create scopes.') {\n super(message);\n }\n}\n"],"mappings":"AACA,IAAa,SAAb,cAA8B,KAAM,CAClC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,cAAb,cAAmC,QAAS,CAC1C,YAAY,EAAU,8DAA+D,CACnF,MAAM,CAAO,CACf,CACF"}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all dnd errors. Use `instanceof DndError` to catch any dnd-originated error. */\nexport class DndError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a sortable action is called with an invalid scope not created by `createSortableScope()`. */\nexport class DndScopeError extends DndError {\n constructor(message = 'Invalid scope: use createSortableScope() to create scopes.') {\n super(message);\n }\n}\n"],"mappings":"AACA,IAAa,SAAb,cAA8B,KAAM,CAClC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,cAAb,cAAmC,QAAS,CAC1C,YAAY,EAAU,6DAA8D,CAClF,MAAM,CAAO,CACf,CACF"}
@@ -1 +1 @@
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,GACX,cAAe,GACf,MAAO,GACP,SAAU,EACZ,EAIA,SAAS,sBAAsB,EAA0C,CACvE,IAAM,EAAQ,EAAoB,IAAI,CAAK,EAE3C,GAAI,CAAC,EAAO,MAAM,IAAI,EAAA,cACtB,GAAI,EAAM,SAAU,MAAM,IAAI,EAAA,cAAc,mDAAmD,EAE/F,OAAO,CACT,CAIA,SAAS,yBACP,EACkC,CAClC,GAAI,IAAe,GAAO,OAAO,KAEjC,GAAI,IAAe,IAAQ,IAAe,IAAA,GAAW,OAAO,EAC5D,GACE,CAAC,OAAO,SAAS,EAAW,eAAiB,EAAE,IAC9C,EAAW,eAAiB,IAAM,GACnC,CAAC,OAAO,SAAS,EAAW,OAAS,EAAE,IACtC,EAAW,OAAS,KAAO,EAE5B,MAAM,IAAI,EAAA,SAAS,2EAA2E,EAGhG,MAAO,CACL,UAAW,EAAW,WAAa,GACnC,cAAe,EAAW,eAAiB,GAC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O,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
+ {"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,GACX,cAAe,GACf,MAAO,GACP,SAAU,EACZ,EAIA,SAAS,sBAAsB,EAA0C,CACvE,IAAM,EAAQ,EAAoB,IAAI,CAAK,EAE3C,GAAI,CAAC,EAAO,MAAM,IAAI,EAAA,cACtB,GAAI,EAAM,SAAU,MAAM,IAAI,EAAA,cAAc,mDAAmD,EAE/F,OAAO,CACT,CAIA,SAAS,yBACP,EACkC,CAClC,GAAI,IAAe,GAAO,OAAO,KAEjC,GAAI,IAAe,IAAQ,IAAe,IAAA,GAAW,OAAO,EAC5D,GACE,CAAC,OAAO,SAAS,EAAW,eAAiB,EAAE,IAC9C,EAAW,eAAiB,IAAM,GACnC,CAAC,OAAO,SAAS,EAAW,OAAS,EAAE,IACtC,EAAW,OAAS,KAAO,EAE5B,MAAM,IAAI,EAAA,SAAS,2EAA2E,EAGhG,MAAO,CACL,UAAW,EAAW,WAAa,GACnC,cAAe,EAAW,eAAiB,GAC3C,MAAO,EAAW,OAAS,GAC3B,SAAU,EAAW,UAAY,EACnC,CACF,CAIA,SAAS,gBAAgB,EAA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,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"}
@@ -18,7 +18,7 @@ export interface AutoScrollOptions {
18
18
  }
19
19
  /**
20
20
  * Passed to `onReorder` after every successful reorder (drag or keyboard).
21
- * Application history owns rollback — use `before`/`after`/`item` to record
21
+ * Application history owns rollback: use `before`/`after`/`item` to record
22
22
  * an undo entry.
23
23
  */
24
24
  export interface ReorderEvent {
@@ -105,7 +105,7 @@ export interface SortableOptions {
105
105
  * When `true`, drag interactions are ignored.
106
106
  *
107
107
  * Note: if `disabled` transitions to `true` while a drag is in progress the
108
- * drag is treated as a cancellation — the item snaps back to its original
108
+ * drag is treated as a cancellation: the item snaps back to its original
109
109
  * position rather than committing the last placeholder location.
110
110
  */
111
111
  disabled?: boolean;
@@ -122,7 +122,7 @@ export interface SortableOptions {
122
122
  /**
123
123
  * Returns the identity key for a given item element.
124
124
  * This separates the "what is this item?" concern (yours) from the "which children
125
- * are sortable?" concern (ours — marked with `data-dnd-item`).
125
+ * are sortable?" concern (ours: marked with `data-dnd-item`).
126
126
  *
127
127
  * @example
128
128
  * ```ts
@@ -138,7 +138,7 @@ export interface SortableOptions {
138
138
  /**
139
139
  * Returns the current sortable item elements. When omitted the sortable
140
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.
141
+ * ownership: e.g. when items are managed by a framework render loop.
142
142
  */
143
143
  items?: () => readonly HTMLElement[];
144
144
  /**
@@ -148,7 +148,7 @@ export interface SortableOptions {
148
148
  keyboard?: boolean;
149
149
  /**
150
150
  * Called just before a successful drag commit with the before and after order snapshots.
151
- * Use this hook to set up FLIP animations — the source items are still in their
151
+ * Use this hook to set up FLIP animations: the source items are still in their
152
152
  * pre-commit positions at the time of the call.
153
153
  *
154
154
  * @example
@@ -164,7 +164,7 @@ export interface SortableOptions {
164
164
  /** Called when the user starts dragging an item. */
165
165
  onDragStart?: (id: string, event: DragEvent) => void;
166
166
  /**
167
- * Structured accessibility event for pickup/move/drop/cancel — wire to a consumer-side
167
+ * Structured accessibility event for pickup/move/drop/cancel: wire to a consumer-side
168
168
  * announcer for screen-reader feedback. See {@link SortableInteractionEvent}.
169
169
  */
170
170
  onInteraction?: (event: SortableInteractionEvent) => void;
@@ -191,7 +191,7 @@ export interface Sortable extends Disposable {
191
191
  /**
192
192
  * Re-reads items from the `items` provider (or the container's direct children)
193
193
  * and reapplies `draggable`, ARIA roles, and handle attributes. Call this after
194
- * programmatically adding, removing, or replacing items — e.g. after a framework
194
+ * programmatically adding, removing, or replacing items: e.g. after a framework
195
195
  * render that replaces DOM nodes.
196
196
  *
197
197
  * Not needed when items are only reordered via drag or keyboard.