@vielzeug/dnd 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/dnd.cjs +1 -1
- package/dist/dnd.cjs.map +1 -1
- package/dist/dnd.iife.js +1 -1
- package/dist/dnd.iife.js.map +1 -1
- package/dist/dnd.js +1 -1
- package/dist/dnd.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/sortable.cjs +1 -1
- package/dist/sortable.cjs.map +1 -1
- package/dist/sortable.d.ts.map +1 -1
- package/dist/sortable.js +1 -1
- package/dist/sortable.js.map +1 -1
- package/dist/touch.cjs +2 -0
- package/dist/touch.cjs.map +1 -0
- package/dist/touch.d.ts +33 -0
- package/dist/touch.d.ts.map +1 -0
- package/dist/touch.js +79 -0
- package/dist/touch.js.map +1 -0
- package/package.json +3 -3
package/dist/sortable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sortable.js","names":[],"sources":["../src/sortable.ts"],"sourcesContent":["import { warn } from './_dev';\nimport { createDisposable, resolveDisabled } from './_shared';\nimport { DndScopeError } from './errors';\nimport { type Disposable } from './types';\n\n// ─── Branded scope ────────────────────────────────────────────────────────────\n\nconst SCOPE_BRAND = Symbol('SortableScope');\n\nexport interface SortableScope extends Disposable {\n /** `true` while any sortable in this scope is actively dragging. */\n readonly isDragging: boolean;\n readonly [SCOPE_BRAND]: true;\n}\n\n// ─── Types ────────────────────────────────────────────────────────────────────\n\nexport interface AutoScrollOptions {\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 sortable container while dragging near its edges. @default true */\n container?: boolean;\n /** Scroll the viewport while dragging near the window edges. @default false */\n viewport?: boolean;\n}\n\n/**\n * Passed to `onReorder` after every successful reorder (drag or keyboard).\n */\nexport interface ReorderEvent {\n /** The new ordered list of item keys after the reorder. */\n ids: string[];\n /**\n * Register a revert function that will be called when `sortable.revert()` is invoked.\n * Useful for rolling back optimistic UI updates on server error.\n * Only the most recent `setRevert` registration is retained — a new reorder overwrites it.\n *\n * @example\n * ```ts\n * onReorder: ({ ids, setRevert }) => {\n * const prev = order;\n * setOrder(ids);\n * setRevert(() => setOrder(prev));\n * },\n * ```\n */\n setRevert(fn: () => void): void;\n}\n\nexport interface SortableOptions {\n /** Container element whose direct-child items are sortable. */\n element: HTMLElement;\n /** Shared scope for connected sortable containers. Containers only exchange items within the same scope. */\n scope?: SortableScope;\n /**\n * Selector for the drag handle inside each item.\n * When omitted the whole item is the handle.\n */\n handle?: string;\n /**\n * Enables keyboard-based reordering using arrow keys plus Home/End.\n * @default true\n */\n keyboard?: boolean;\n /**\n * 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 /** Sorting axis used to compute insertion position. @default 'vertical' */\n axis?: 'vertical' | 'horizontal';\n /** Auto-scrolls the container (and viewport) near edges while dragging. @default true */\n autoScroll?: boolean | AutoScrollOptions;\n /** Optional custom drag preview element. */\n dragImage?: HTMLElement | ((id: string, item: HTMLElement, event: DragEvent) => HTMLElement | null | undefined);\n /** CSS class applied to the placeholder element. @default 'dnd-placeholder' */\n placeholderClass?: string;\n /**\n * Called with a {@link ReorderEvent} after a successful reorder, only when the order changed.\n *\n * @example\n * ```ts\n * onReorder: ({ ids, setRevert }) => {\n * const prev = order;\n * setOrder(ids);\n * setRevert(() => setOrder(prev));\n * },\n * ```\n */\n onReorder?: (event: ReorderEvent) => void;\n /**\n * Called just before a successful drag commit with the before and after order snapshots.\n * Use this hook to set up FLIP animations — the source items are still in their\n * pre-commit positions at the time of the call.\n *\n * @example\n * ```ts\n * onBeforeReorder: (from, to) => {\n * // record element positions here, then animate after the next microtask\n * }\n * ```\n */\n onBeforeReorder?: (from: string[], to: string[]) => void;\n /**\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 /** Called when the user starts dragging an item. */\n onDragStart?: (id: string, event: DragEvent) => void;\n /** Called when a drag ends (whether dropped or cancelled). */\n onDragEnd?: (id: string, event: DragEvent) => void;\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}\n\nexport interface Sortable extends Disposable {\n readonly isDragging: boolean;\n /**\n * Calls the revert function registered via `setRevert` in the last `onReorder` invocation (if any) and clears it.\n * A no-op when no revert function was registered or has already been consumed.\n *\n * Works for both drag-based and keyboard-based reorders.\n * Note: only the most recent reorder can be reverted; a new reorder overwrites the stored function.\n *\n * @example\n * ```ts\n * onReorder: ({ ids, setRevert }) => {\n * const prev = order;\n * setOrder(ids);\n * setRevert(() => setOrder(prev));\n * },\n * // later, on server error:\n * sortable.revert();\n * ```\n */\n revert(): void;\n /**\n * Re-reads the container's children and reapplies `draggable`, ARIA roles,\n * and handle attributes. Call this after programmatically adding, removing,\n * or replacing items — e.g. after a framework render that replaces DOM nodes.\n *\n * Not needed when items are only reordered via drag or keyboard.\n */\n sync(): void;\n}\n\n// ─── Internal types ───────────────────────────────────────────────────────────\n\ninterface ResolvedAutoScrollOptions {\n container: boolean;\n edgeThreshold: number;\n speed: number;\n viewport: boolean;\n}\n\n/** Per-container closure passed into shared session functions. */\ninterface ContainerHandle {\n getOrderedIds: () => string[];\n isDisabled: () => boolean;\n commitReorder: (orderedIds: string[]) => void;\n notifyBeforeReorder: (from: string[], to: string[]) => void;\n notifyDragEnd: (id: string, event: DragEvent) => void;\n notifyDragStart: (id: string, event: DragEvent) => void;\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 /**\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 /** rAF handle for the deferred element-hide; null once fired or cancelled. */\n hideFrame: number | null;\n}\n\ninterface SortableScopeState {\n active: DragSession | null;\n handles: Set<ContainerHandle>;\n /** All sortables registered in this scope, kept for scope.dispose(). */\n disposables: Set<() => void>;\n}\n\n// ─── Internal constants ───────────────────────────────────────────────────────\n\nconst HANDLE_ATTR = 'data-dnd-handle';\nconst ITEM_ATTR = 'data-dnd-item';\nconst sortableScopeStates = new WeakMap<SortableScope, SortableScopeState>();\nconst DEFAULT_AUTO_SCROLL: ResolvedAutoScrollOptions = {\n container: true,\n edgeThreshold: 32,\n speed: 18,\n viewport: false,\n};\n\n// ─── Scope helpers ────────────────────────────────────────────────────────────\n\nfunction getSortableScopeState(scope: SortableScope): SortableScopeState {\n const state = sortableScopeStates.get(scope);\n\n if (!state) throw new DndScopeError();\n\n return state;\n}\n\n// ─── Option resolution ────────────────────────────────────────────────────────\n\nfunction resolveAutoScrollOptions(\n autoScroll: boolean | AutoScrollOptions | undefined,\n): ResolvedAutoScrollOptions | null {\n if (autoScroll === false) return null;\n\n if (autoScroll === true || autoScroll === undefined) return DEFAULT_AUTO_SCROLL;\n\n return {\n container: autoScroll.container ?? true,\n edgeThreshold: autoScroll.edgeThreshold ?? 32,\n speed: autoScroll.speed ?? 18,\n viewport: autoScroll.viewport ?? false,\n };\n}\n\n// ─── DOM helpers ──────────────────────────────────────────────────────────────\n\nfunction hasOrderChanged(before: string[], after: string[]): boolean {\n return after.length !== before.length || after.some((id, index) => id !== before[index]);\n}\n\nfunction clearHandleAttributes(element: HTMLElement): void {\n element.querySelectorAll<HTMLElement>(`[${HANDLE_ATTR}]`).forEach((handleEl) => {\n handleEl.removeAttribute(HANDLE_ATTR);\n handleEl.removeAttribute('draggable');\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\n// ─── Session commit / cancel ──────────────────────────────────────────────────\n\nfunction cancelSession(scopeState: SortableScopeState, event: DragEvent): void {\n const session = scopeState.active;\n\n if (!session) return;\n\n restoreSessionElement(session);\n session.originalParent.insertBefore(session.draggedEl, session.originalNextSibling);\n session.placeholder.remove();\n scopeState.active = null;\n\n session.source.notifyDragEnd(session.draggedId, event);\n}\n\nfunction commitSession(scopeState: SortableScopeState, event: DragEvent): void {\n const session = scopeState.active;\n\n if (!session) return;\n\n const targetHandle = session.target;\n const targetElement = session.placeholder.parentElement;\n\n restoreSessionElement(session);\n\n if (targetHandle && scopeState.handles.has(targetHandle) && targetElement) {\n targetElement.insertBefore(session.draggedEl, session.placeholder);\n } else {\n session.originalParent.insertBefore(session.draggedEl, session.originalNextSibling);\n }\n\n session.placeholder.remove();\n scopeState.active = null;\n\n session.source.notifyDragEnd(session.draggedId, event);\n\n for (const [handle, beforeOrder] of session.initialOrders) {\n if (!scopeState.handles.has(handle)) continue;\n\n const afterOrder = handle.getOrderedIds();\n\n if (!hasOrderChanged(beforeOrder, afterOrder)) continue;\n\n handle.notifyBeforeReorder(beforeOrder, afterOrder);\n handle.commitReorder(afterOrder);\n }\n}\n\nfunction finishSession(scopeState: SortableScopeState, event: DragEvent, forceCancel: boolean): void {\n if (!scopeState.active) return;\n\n const { active } = scopeState;\n\n // If source or target became disabled during the drag, treat as cancellation.\n if (\n forceCancel ||\n !event.dataTransfer ||\n event.dataTransfer.dropEffect === 'none' ||\n !active.target ||\n !scopeState.handles.has(active.target) ||\n active.source.isDisabled() ||\n active.target.isDisabled()\n ) {\n cancelSession(scopeState, event);\n } else {\n commitSession(scopeState, event);\n }\n}\n\nfunction maybeAutoScroll(\n event: DragEvent,\n container: HTMLElement,\n axis: 'vertical' | 'horizontal',\n options: ResolvedAutoScrollOptions | null,\n): void {\n if (!options) return;\n\n const { container: scrollContainer, edgeThreshold: threshold, speed, viewport } = options;\n const rect = container.getBoundingClientRect();\n\n if (axis === 'vertical') {\n if (scrollContainer && event.clientY < rect.top + threshold) {\n container.scrollTop -= speed;\n } else if (scrollContainer && event.clientY > rect.bottom - threshold) {\n container.scrollTop += speed;\n }\n\n if (viewport && event.clientY < threshold) {\n window.scrollBy({ left: 0, top: -speed });\n } else if (viewport && event.clientY > window.innerHeight - threshold) {\n window.scrollBy({ left: 0, top: speed });\n }\n\n return;\n }\n\n if (scrollContainer && event.clientX < rect.left + threshold) {\n container.scrollLeft -= speed;\n } else if (scrollContainer && event.clientX > rect.right - threshold) {\n container.scrollLeft += speed;\n }\n\n if (viewport && event.clientX < threshold) {\n window.scrollBy({ left: -speed, top: 0 });\n } else if (viewport && event.clientX > window.innerWidth - threshold) {\n window.scrollBy({ left: speed, top: 0 });\n }\n}\n\n// ─── Keyboard reorder ─────────────────────────────────────────────────────────\n\nfunction applyKeyboardReorder(\n item: HTMLElement,\n element: HTMLElement,\n getItems: () => HTMLElement[],\n getOrderedIds: () => string[],\n key: string,\n axis: 'vertical' | 'horizontal',\n): string[] | null {\n const items = getItems();\n const currentIndex = items.indexOf(item);\n\n if (currentIndex < 0) return null;\n\n const isForward = axis === 'vertical' ? key === 'ArrowDown' : key === 'ArrowRight';\n const isBackward = axis === 'vertical' ? key === 'ArrowUp' : key === 'ArrowLeft';\n let targetIndex: number;\n\n if (isForward) {\n targetIndex = Math.min(items.length - 1, currentIndex + 1);\n } else if (isBackward) {\n targetIndex = Math.max(0, currentIndex - 1);\n } else if (key === 'Home') {\n targetIndex = 0;\n } else if (key === 'End') {\n targetIndex = items.length - 1;\n } else {\n return null;\n }\n\n // Already at the boundary — return null so the caller does not call preventDefault\n // and the browser can handle the key (e.g. scrolling the page).\n if (targetIndex === currentIndex) return null;\n\n const targetItem = items[targetIndex];\n\n if (!targetItem) return null;\n\n element.insertBefore(item, targetIndex > currentIndex ? targetItem.nextSibling : targetItem);\n item.focus();\n\n return getOrderedIds();\n}\n\n// ─── createSortableScope ──────────────────────────────────────────────────────\n\n/**\n * Create a shared scope for connected sortable containers.\n *\n * Items can be dragged between all sortables that share the same scope.\n * The scope exposes `isDragging` and `dispose()` — calling `dispose()` tears down\n * all member sortables at once.\n *\n * @example\n * ```ts\n * const scope = createSortableScope();\n * const left = createSortable({ element: leftEl, scope, getKey, onReorder });\n * const right = createSortable({ element: rightEl, scope, getKey, onReorder });\n *\n * // Tear down everything at once:\n * scope.dispose();\n * ```\n */\nexport function createSortableScope(): SortableScope {\n const state: SortableScopeState = { active: null, disposables: new Set(), handles: new Set() };\n const disposable = createDisposable(() => {\n // Dispose all registered sortables (each dispose() call is idempotent)\n for (const disposeFn of state.disposables) {\n disposeFn();\n }\n });\n\n const scope = {\n get disposalSignal() {\n return disposable.disposalSignal;\n },\n dispose: disposable.dispose,\n get disposed() {\n return disposable.disposed;\n },\n get isDragging() {\n return state.active !== null;\n },\n [SCOPE_BRAND]: true as const,\n [Symbol.dispose]: disposable[Symbol.dispose],\n } as SortableScope;\n\n sortableScopeStates.set(scope, state);\n\n return scope;\n}\n\n// ─── createSortable ───────────────────────────────────────────────────────────\n\n/**\n * Makes a list of items sortable via native HTML drag interactions.\n *\n * Provide `getKey` to map each item element to a stable string identity.\n * `createSortable` marks qualifying children with `data-dnd-item` and sets\n * `draggable=\"true\"` automatically.\n *\n * Style the drop indicator by targeting `.dnd-placeholder` in your CSS.\n * Supports keyboard reordering (arrow keys, Home/End) and auto-scrolling near edges.\n *\n * @example\n * ```ts\n * import { createSortable } from '@vielzeug/dnd';\n *\n * using sortable = createSortable({\n * element: listEl,\n * getKey: (el) => el.dataset.id!,\n * onReorder: ({ ids, setRevert }) => {\n * const prev = order;\n * setOrder(ids);\n * setRevert(() => setOrder(prev));\n * },\n * });\n * ```\n */\nexport function createSortable(options: SortableOptions): Sortable {\n const {\n autoScroll = true,\n axis = 'vertical',\n element,\n getKey,\n handle,\n keyboard = true,\n placeholderClass = 'dnd-placeholder',\n scope = createSortableScope(),\n } = options;\n const autoScrollOptions = resolveAutoScrollOptions(autoScroll);\n const scopeState = getSortableScopeState(scope);\n\n if (handle !== undefined && handle.trim() === '') {\n warn(\n 'handle option is an empty string — no handle elements will be found. Provide a valid CSS selector or omit the option.',\n );\n }\n\n const getItems = (): HTMLElement[] =>\n Array.from(element.children).filter((c) => (c as HTMLElement).hasAttribute(ITEM_ATTR)) as HTMLElement[];\n\n const getOrderedIds = (): string[] => getItems().map((el) => getKey(el));\n\n const syncItems = (): void => {\n clearHandleAttributes(element);\n\n getItems().forEach((el) => {\n el.setAttribute('role', 'listitem');\n el.tabIndex = 0;\n\n if (handle) {\n el.removeAttribute('draggable');\n el.querySelectorAll<HTMLElement>(handle).forEach((handleEl) => {\n handleEl.setAttribute(HANDLE_ATTR, '');\n handleEl.setAttribute('draggable', 'true');\n });\n } else {\n el.setAttribute('draggable', 'true');\n }\n });\n };\n\n const markItems = (): void => {\n const seenKeys = new Set<string>();\n\n // Mark all children that have a key as sortable items\n Array.from(element.children).forEach((child) => {\n const el = child as HTMLElement;\n\n try {\n const key = getKey(el);\n\n if (key) {\n if (seenKeys.has(key)) {\n warn(\n `getKey returned the duplicate key \"${key}\" for two sibling items — onReorder's ids and applyReorder may become inconsistent. Ensure getKey returns a unique value per item.`,\n );\n } else {\n seenKeys.add(key);\n }\n\n el.setAttribute(ITEM_ATTR, '');\n }\n } catch (err) {\n warn(\n `getKey threw for a child element — the item will not be sortable. Check your getKey implementation. ${String(err)}`,\n );\n }\n });\n\n syncItems();\n };\n\n const cleanupItems = (): void => {\n clearHandleAttributes(element);\n\n element.querySelectorAll<HTMLElement>(`[${ITEM_ATTR}]`).forEach((item) => {\n item.removeAttribute(ITEM_ATTR);\n item.removeAttribute('draggable');\n item.removeAttribute('role');\n item.removeAttribute('tabindex');\n });\n };\n\n const createPlaceholder = (source: HTMLElement): HTMLElement => {\n const p = document.createElement('div');\n\n p.className = placeholderClass;\n p.setAttribute('aria-hidden', 'true');\n\n if (axis === 'horizontal') {\n p.style.width = `${source.offsetWidth}px`;\n } else {\n p.style.height = `${source.offsetHeight}px`;\n }\n\n return p;\n };\n\n let lastRevert: (() => void) | null = null;\n\n const handle_: ContainerHandle = {\n commitReorder: (orderedIds) => {\n if (!options.onReorder) return;\n\n const event: ReorderEvent = {\n ids: orderedIds,\n setRevert(fn) {\n lastRevert = fn;\n },\n };\n\n options.onReorder(event);\n },\n getOrderedIds,\n isDisabled: () => resolveDisabled(options.disabled),\n notifyBeforeReorder: (from, to) => options.onBeforeReorder?.(from, to),\n notifyDragEnd: (id, event) => options.onDragEnd?.(id, event),\n notifyDragStart: (id, event) => options.onDragStart?.(id, event),\n };\n\n scopeState.handles.add(handle_);\n\n const handleDragStart = (e: DragEvent): void => {\n if (scopeState.active) return;\n\n if (handle_.isDisabled()) return;\n\n const target = e.target as HTMLElement;\n const item = target.closest<HTMLElement>(`[${ITEM_ATTR}]`);\n\n if (!item) return;\n\n if (handle && !target.closest(handle)) return;\n\n const originalParent = item.parentElement;\n\n if (!originalParent) return;\n\n const placeholder = createPlaceholder(item);\n const originalNextSibling = item.nextSibling;\n const activeId = getKey(item);\n\n // Snapshot only the source handle at drag start; targets are snapshotted lazily.\n const initialOrders = new Map<ContainerHandle, string[]>();\n\n initialOrders.set(handle_, handle_.getOrderedIds());\n item.setAttribute('data-dragging', '');\n originalParent.insertBefore(placeholder, originalNextSibling);\n\n const session: DragSession = {\n draggedEl: item,\n draggedId: activeId,\n hideFrame: null,\n initialOrders,\n originalDisplay: item.style.display,\n originalNextSibling,\n originalParent,\n placeholder,\n source: handle_,\n target: handle_,\n };\n\n scheduleHide(session);\n scopeState.active = session;\n\n if (e.dataTransfer) {\n e.dataTransfer.effectAllowed = 'move';\n e.dataTransfer.setData('text/plain', activeId);\n\n if (options.dragImage) {\n const preview =\n typeof options.dragImage === 'function' ? options.dragImage(activeId, item, e) : options.dragImage;\n const [offsetX, offsetY] = options.dragImageOffset ?? [0, 0];\n\n if (preview) e.dataTransfer.setDragImage(preview, offsetX, offsetY);\n }\n }\n\n handle_.notifyDragStart(session.draggedId, e);\n };\n\n const handleDragOver = (e: DragEvent): void => {\n const session = scopeState.active;\n\n if (!session) return;\n\n if (session.source.isDisabled() || handle_.isDisabled()) return;\n\n e.preventDefault();\n maybeAutoScroll(e, element, axis, autoScrollOptions);\n\n // Lazily snapshot this handle's order the first time it becomes a target.\n snapshotOrder(session, handle_);\n\n const { draggedEl, placeholder } = session;\n const target = (e.target as HTMLElement).closest<HTMLElement>(`[${ITEM_ATTR}]`);\n\n if (!target) {\n if (placeholder.parentElement !== element || placeholder.nextSibling !== null) {\n element.appendChild(placeholder);\n }\n\n session.target = handle_;\n\n return;\n }\n\n if (target === draggedEl || target === placeholder) return;\n\n const rect = target.getBoundingClientRect();\n const insertAfter =\n axis === 'vertical' ? e.clientY >= rect.top + rect.height / 2 : e.clientX >= rect.left + rect.width / 2;\n\n element.insertBefore(placeholder, insertAfter ? target.nextSibling : target);\n session.target = handle_;\n };\n\n const handleDrop = (e: DragEvent): void => {\n const session = scopeState.active;\n\n if (!session) return;\n\n if (session.source.isDisabled() || handle_.isDisabled()) return;\n\n e.preventDefault();\n // Record the drop target; the actual commit happens in handleDragEnd where\n // dataTransfer.dropEffect tells us whether the browser accepted the operation.\n session.target = handle_;\n };\n\n const handleDragEnd = (e: DragEvent): void => {\n if (scopeState.active?.source !== handle_) return;\n\n finishSession(scopeState, e, false);\n };\n\n const handleKeydown = (e: KeyboardEvent): void => {\n if (!keyboard || handle_.isDisabled()) return;\n\n const tagName = (e.target as HTMLElement | null)?.tagName;\n\n if (tagName === 'INPUT' || tagName === 'TEXTAREA' || tagName === 'SELECT') return;\n\n const item = (e.target as HTMLElement).closest<HTMLElement>(`[${ITEM_ATTR}]`);\n\n if (!item || !element.contains(item)) return;\n\n const prevOrder = getOrderedIds();\n const newOrder = applyKeyboardReorder(item, element, getItems, getOrderedIds, e.key, axis);\n\n // null means unrecognized key or boundary — let the browser handle it (e.g. page scroll)\n if (newOrder === null) return;\n\n e.preventDefault();\n handle_.notifyBeforeReorder(prevOrder, newOrder);\n handle_.commitReorder(newOrder);\n };\n\n markItems();\n\n const disposable = createDisposable(() => {\n scopeState.disposables.delete(disposable.dispose);\n\n if (scopeState.active && (scopeState.active.source === handle_ || scopeState.active.target === handle_)) {\n finishSession(scopeState, new Event('dragend') as DragEvent, true);\n }\n\n scopeState.handles.delete(handle_);\n element.removeAttribute('role');\n cleanupItems();\n });\n\n element.setAttribute('role', 'list');\n element.addEventListener('dragstart', handleDragStart, { signal: disposable.disposalSignal });\n element.addEventListener('dragover', handleDragOver, { signal: disposable.disposalSignal });\n element.addEventListener('drop', handleDrop, { signal: disposable.disposalSignal });\n element.addEventListener('dragend', handleDragEnd, { signal: disposable.disposalSignal });\n element.addEventListener('keydown', handleKeydown, { signal: disposable.disposalSignal });\n\n // Register with scope so scope.dispose() can tear this down\n scopeState.disposables.add(disposable.dispose);\n\n return {\n get disposalSignal() {\n return disposable.disposalSignal;\n },\n dispose: disposable.dispose,\n get disposed() {\n return disposable.disposed;\n },\n get isDragging() {\n return scopeState.active?.source === handle_;\n },\n revert: () => {\n lastRevert?.();\n lastRevert = null;\n },\n [Symbol.dispose]: disposable[Symbol.dispose],\n sync: () => {\n markItems();\n },\n };\n}\n\n// ─── applyReorder ─────────────────────────────────────────────────────────────\n\n/**\n * Applies a sorted key array to a backing data array.\n * Unknown keys are ignored; items not present in `ids` are appended in original order.\n */\nexport function applyReorder<T>(items: T[], ids: string[], getKey: (item: T) => string): T[] {\n const byId = new Map(items.map((item) => [getKey(item), item] as const));\n const ordered: T[] = [];\n\n for (const id of ids) {\n if (!byId.has(id)) continue;\n\n const item = byId.get(id) as T;\n\n ordered.push(item);\n byId.delete(id);\n }\n\n for (const item of byId.values()) ordered.push(item);\n\n return ordered;\n}\n"],"mappings":";;;;AAOA,IAAM,IAAc,OAAO,eAAe,GA6MpC,IAAc,mBACd,IAAY,iBACZ,oBAAsB,IAAI,QAA2C,GACrE,IAAiD;CACrD,WAAW;CACX,eAAe;CACf,OAAO;CACP,UAAU;AACZ;AAIA,SAAS,EAAsB,GAA0C;CACvE,IAAM,IAAQ,EAAoB,IAAI,CAAK;CAE3C,IAAI,CAAC,GAAO,MAAM,IAAI,EAAc;CAEpC,OAAO;AACT;AAIA,SAAS,EACP,GACkC;CAKlC,OAJI,MAAe,KAAc,OAE7B,MAAe,MAAQ,MAAe,KAAA,IAAkB,IAErD;EACL,WAAW,EAAW,aAAa;EACnC,eAAe,EAAW,iBAAiB;EAC3C,OAAO,EAAW,SAAS;EAC3B,UAAU,EAAW,YAAY;CACnC;AACF;AAIA,SAAS,EAAgB,GAAkB,GAA0B;CACnE,OAAO,EAAM,WAAW,EAAO,UAAU,EAAM,MAAM,GAAI,MAAU,MAAO,EAAO,EAAM;AACzF;AAEA,SAAS,EAAsB,GAA4B;CACzD,EAAQ,iBAA8B,IAAI,EAAY,EAAE,C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,GAGxF,EAAW,YAAY,IAAI,EAAW,OAAO,GAEtC;EACL,IAAI,iBAAiB;GACnB,OAAO,EAAW;EACpB;EACA,SAAS,EAAW;EACpB,IAAI,WAAW;GACb,OAAO,EAAW;EACpB;EACA,IAAI,aAAa;GACf,OAAO,EAAW,QAAQ,WAAW;EACvC;EACA,cAAc;GAEZ,AADA,IAAa,GACb,IAAa;EACf;GACC,OAAO,UAAU,EAAW,OAAO;EACpC,YAAY;GACV,EAAU;EACZ;CACF;AACF;AAQA,SAAgB,EAAgB,GAAY,GAAe,GAAkC;CAC3F,IAAM,IAAO,IAAI,IAAI,EAAM,KAAK,MAAS,CAAC,EAAO,CAAI,GAAG,CAAI,CAAU,CAAC,GACjE,IAAe,CAAC;CAEtB,KAAK,IAAM,KAAM,GAAK;EACpB,IAAI,CAAC,EAAK,IAAI,CAAE,GAAG;EAEnB,IAAM,IAAO,EAAK,IAAI,CAAE;EAGxB,AADA,EAAQ,KAAK,CAAI,GACjB,EAAK,OAAO,CAAE;CAChB;CAEA,KAAK,IAAM,KAAQ,EAAK,OAAO,GAAG,EAAQ,KAAK,CAAI;CAEnD,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"sortable.js","names":[],"sources":["../src/sortable.ts"],"sourcesContent":["import { warn } from './_dev';\nimport { createDisposable, resolveDisabled } from './_shared';\nimport { DndScopeError } from './errors';\nimport { type Disposable } from './types';\n\n// ─── Branded scope ────────────────────────────────────────────────────────────\n\nconst SCOPE_BRAND = Symbol('SortableScope');\n\nexport interface SortableScope extends Disposable {\n /** `true` while any sortable in this scope is actively dragging. */\n readonly isDragging: boolean;\n readonly [SCOPE_BRAND]: true;\n}\n\n// ─── Types ────────────────────────────────────────────────────────────────────\n\nexport interface AutoScrollOptions {\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 sortable container while dragging near its edges. @default true */\n container?: boolean;\n /** Scroll the viewport while dragging near the window edges. @default false */\n viewport?: boolean;\n}\n\n/**\n * Passed to `onReorder` after every successful reorder (drag or keyboard).\n */\nexport interface ReorderEvent {\n /** The new ordered list of item keys after the reorder. */\n ids: string[];\n /**\n * Register a revert function that will be called when `sortable.revert()` is invoked.\n * Useful for rolling back optimistic UI updates on server error.\n * Only the most recent `setRevert` registration is retained — a new reorder overwrites it.\n *\n * @example\n * ```ts\n * onReorder: ({ ids, setRevert }) => {\n * const prev = order;\n * setOrder(ids);\n * setRevert(() => setOrder(prev));\n * },\n * ```\n */\n setRevert(fn: () => void): void;\n}\n\nexport interface SortableOptions {\n /** Container element whose direct-child items are sortable. */\n element: HTMLElement;\n /** Shared scope for connected sortable containers. Containers only exchange items within the same scope. */\n scope?: SortableScope;\n /**\n * Selector for the drag handle inside each item.\n * When omitted the whole item is the handle.\n */\n handle?: string;\n /**\n * Enables keyboard-based reordering using arrow keys plus Home/End.\n * @default true\n */\n keyboard?: boolean;\n /**\n * 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 /** Sorting axis used to compute insertion position. @default 'vertical' */\n axis?: 'vertical' | 'horizontal';\n /** Auto-scrolls the container (and viewport) near edges while dragging. @default true */\n autoScroll?: boolean | AutoScrollOptions;\n /** Optional custom drag preview element. */\n dragImage?: HTMLElement | ((id: string, item: HTMLElement, event: DragEvent) => HTMLElement | null | undefined);\n /** CSS class applied to the placeholder element. @default 'dnd-placeholder' */\n placeholderClass?: string;\n /**\n * Called with a {@link ReorderEvent} after a successful reorder, only when the order changed.\n *\n * @example\n * ```ts\n * onReorder: ({ ids, setRevert }) => {\n * const prev = order;\n * setOrder(ids);\n * setRevert(() => setOrder(prev));\n * },\n * ```\n */\n onReorder?: (event: ReorderEvent) => void;\n /**\n * Called just before a successful drag commit with the before and after order snapshots.\n * Use this hook to set up FLIP animations — the source items are still in their\n * pre-commit positions at the time of the call.\n *\n * @example\n * ```ts\n * onBeforeReorder: (from, to) => {\n * // record element positions here, then animate after the next microtask\n * }\n * ```\n */\n onBeforeReorder?: (from: string[], to: string[]) => void;\n /**\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 /** Called when the user starts dragging an item. */\n onDragStart?: (id: string, event: DragEvent) => void;\n /** Called when a drag ends (whether dropped or cancelled). */\n onDragEnd?: (id: string, event: DragEvent) => void;\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}\n\nexport interface Sortable extends Disposable {\n readonly isDragging: boolean;\n /**\n * Calls the revert function registered via `setRevert` in the last `onReorder` invocation (if any) and clears it.\n * A no-op when no revert function was registered or has already been consumed.\n *\n * Works for both drag-based and keyboard-based reorders.\n * Note: only the most recent reorder can be reverted; a new reorder overwrites the stored function.\n *\n * @example\n * ```ts\n * onReorder: ({ ids, setRevert }) => {\n * const prev = order;\n * setOrder(ids);\n * setRevert(() => setOrder(prev));\n * },\n * // later, on server error:\n * sortable.revert();\n * ```\n */\n revert(): void;\n /**\n * Re-reads the container's children and reapplies `draggable`, ARIA roles,\n * and handle attributes. Call this after programmatically adding, removing,\n * or replacing items — e.g. after a framework render that replaces DOM nodes.\n *\n * Not needed when items are only reordered via drag or keyboard.\n */\n sync(): void;\n}\n\n// ─── Internal types ───────────────────────────────────────────────────────────\n\ninterface ResolvedAutoScrollOptions {\n container: boolean;\n edgeThreshold: number;\n speed: number;\n viewport: boolean;\n}\n\n/** Per-container closure passed into shared session functions. */\ninterface ContainerHandle {\n getOrderedIds: () => string[];\n isDisabled: () => boolean;\n commitReorder: (orderedIds: string[]) => void;\n notifyBeforeReorder: (from: string[], to: string[]) => void;\n notifyDragEnd: (id: string, event: DragEvent) => void;\n notifyDragStart: (id: string, event: DragEvent) => void;\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 /**\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 /** rAF handle for the deferred element-hide; null once fired or cancelled. */\n hideFrame: number | null;\n}\n\ninterface SortableScopeState {\n active: DragSession | null;\n handles: Set<ContainerHandle>;\n /** All sortables registered in this scope, kept for scope.dispose(). */\n disposables: Set<() => void>;\n}\n\n// ─── Internal constants ───────────────────────────────────────────────────────\n\nconst HANDLE_ATTR = 'data-dnd-handle';\nconst ITEM_ATTR = 'data-dnd-item';\nconst sortableScopeStates = new WeakMap<SortableScope, SortableScopeState>();\nconst DEFAULT_AUTO_SCROLL: ResolvedAutoScrollOptions = {\n container: true,\n edgeThreshold: 32,\n speed: 18,\n viewport: false,\n};\n\n// ─── Scope helpers ────────────────────────────────────────────────────────────\n\nfunction getSortableScopeState(scope: SortableScope): SortableScopeState {\n const state = sortableScopeStates.get(scope);\n\n if (!state) throw new DndScopeError();\n\n return state;\n}\n\n// ─── Option resolution ────────────────────────────────────────────────────────\n\nfunction resolveAutoScrollOptions(\n autoScroll: boolean | AutoScrollOptions | undefined,\n): ResolvedAutoScrollOptions | null {\n if (autoScroll === false) return null;\n\n if (autoScroll === true || autoScroll === undefined) return DEFAULT_AUTO_SCROLL;\n\n return {\n container: autoScroll.container ?? true,\n edgeThreshold: autoScroll.edgeThreshold ?? 32,\n speed: autoScroll.speed ?? 18,\n viewport: autoScroll.viewport ?? false,\n };\n}\n\n// ─── DOM helpers ──────────────────────────────────────────────────────────────\n\nfunction hasOrderChanged(before: string[], after: string[]): boolean {\n return after.length !== before.length || after.some((id, index) => id !== before[index]);\n}\n\nfunction clearHandleAttributes(element: HTMLElement): void {\n element.querySelectorAll<HTMLElement>(`[${HANDLE_ATTR}]`).forEach((handleEl) => {\n handleEl.removeAttribute(HANDLE_ATTR);\n handleEl.removeAttribute('draggable');\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\n// ─── Session commit / cancel ──────────────────────────────────────────────────\n\nfunction cancelSession(scopeState: SortableScopeState, event: DragEvent): void {\n const session = scopeState.active;\n\n if (!session) return;\n\n restoreSessionElement(session);\n session.originalParent.insertBefore(session.draggedEl, session.originalNextSibling);\n session.placeholder.remove();\n scopeState.active = null;\n\n session.source.notifyDragEnd(session.draggedId, event);\n}\n\nfunction commitSession(scopeState: SortableScopeState, event: DragEvent): void {\n const session = scopeState.active;\n\n if (!session) return;\n\n const targetHandle = session.target;\n const targetElement = session.placeholder.parentElement;\n\n restoreSessionElement(session);\n\n if (targetHandle && scopeState.handles.has(targetHandle) && targetElement) {\n targetElement.insertBefore(session.draggedEl, session.placeholder);\n } else {\n session.originalParent.insertBefore(session.draggedEl, session.originalNextSibling);\n }\n\n session.placeholder.remove();\n scopeState.active = null;\n\n session.source.notifyDragEnd(session.draggedId, event);\n\n for (const [handle, beforeOrder] of session.initialOrders) {\n if (!scopeState.handles.has(handle)) continue;\n\n const afterOrder = handle.getOrderedIds();\n\n if (!hasOrderChanged(beforeOrder, afterOrder)) continue;\n\n handle.notifyBeforeReorder(beforeOrder, afterOrder);\n handle.commitReorder(afterOrder);\n }\n}\n\nfunction finishSession(scopeState: SortableScopeState, event: DragEvent, forceCancel: boolean): void {\n if (!scopeState.active) return;\n\n const { active } = scopeState;\n\n // If source or target became disabled during the drag, treat as cancellation.\n if (\n forceCancel ||\n !event.dataTransfer ||\n event.dataTransfer.dropEffect === 'none' ||\n !active.target ||\n !scopeState.handles.has(active.target) ||\n active.source.isDisabled() ||\n active.target.isDisabled()\n ) {\n cancelSession(scopeState, event);\n } else {\n commitSession(scopeState, event);\n }\n}\n\nfunction maybeAutoScroll(\n event: DragEvent,\n container: HTMLElement,\n axis: 'vertical' | 'horizontal',\n options: ResolvedAutoScrollOptions | null,\n): void {\n if (!options) return;\n\n const { container: scrollContainer, edgeThreshold: threshold, speed, viewport } = options;\n const rect = container.getBoundingClientRect();\n\n if (axis === 'vertical') {\n if (scrollContainer && event.clientY < rect.top + threshold) {\n container.scrollTop -= speed;\n } else if (scrollContainer && event.clientY > rect.bottom - threshold) {\n container.scrollTop += speed;\n }\n\n if (viewport && event.clientY < threshold) {\n window.scrollBy({ left: 0, top: -speed });\n } else if (viewport && event.clientY > window.innerHeight - threshold) {\n window.scrollBy({ left: 0, top: speed });\n }\n\n return;\n }\n\n if (scrollContainer && event.clientX < rect.left + threshold) {\n container.scrollLeft -= speed;\n } else if (scrollContainer && event.clientX > rect.right - threshold) {\n container.scrollLeft += speed;\n }\n\n if (viewport && event.clientX < threshold) {\n window.scrollBy({ left: -speed, top: 0 });\n } else if (viewport && event.clientX > window.innerWidth - threshold) {\n window.scrollBy({ left: speed, top: 0 });\n }\n}\n\n// ─── Keyboard reorder ─────────────────────────────────────────────────────────\n\nfunction applyKeyboardReorder(\n item: HTMLElement,\n element: HTMLElement,\n getItems: () => HTMLElement[],\n getOrderedIds: () => string[],\n key: string,\n axis: 'vertical' | 'horizontal',\n): string[] | null {\n const items = getItems();\n const currentIndex = items.indexOf(item);\n\n if (currentIndex < 0) return null;\n\n const isForward = axis === 'vertical' ? key === 'ArrowDown' : key === 'ArrowRight';\n const isBackward = axis === 'vertical' ? key === 'ArrowUp' : key === 'ArrowLeft';\n let targetIndex: number;\n\n if (isForward) {\n targetIndex = Math.min(items.length - 1, currentIndex + 1);\n } else if (isBackward) {\n targetIndex = Math.max(0, currentIndex - 1);\n } else if (key === 'Home') {\n targetIndex = 0;\n } else if (key === 'End') {\n targetIndex = items.length - 1;\n } else {\n return null;\n }\n\n // Already at the boundary — return null so the caller does not call preventDefault\n // and the browser can handle the key (e.g. scrolling the page).\n if (targetIndex === currentIndex) return null;\n\n const targetItem = items[targetIndex];\n\n if (!targetItem) return null;\n\n element.insertBefore(item, targetIndex > currentIndex ? targetItem.nextSibling : targetItem);\n item.focus();\n\n return getOrderedIds();\n}\n\n// ─── createSortableScope ──────────────────────────────────────────────────────\n\n/**\n * Create a shared scope for connected sortable containers.\n *\n * Items can be dragged between all sortables that share the same scope.\n * The scope exposes `isDragging` and `dispose()` — calling `dispose()` tears down\n * all member sortables at once.\n *\n * @example\n * ```ts\n * const scope = createSortableScope();\n * const left = createSortable({ element: leftEl, scope, getKey, onReorder });\n * const right = createSortable({ element: rightEl, scope, getKey, onReorder });\n *\n * // Tear down everything at once:\n * scope.dispose();\n * ```\n */\nexport function createSortableScope(): SortableScope {\n const state: SortableScopeState = { active: null, disposables: new Set(), handles: new Set() };\n const disposable = createDisposable(() => {\n // Dispose all registered sortables (each dispose() call is idempotent)\n for (const disposeFn of state.disposables) {\n disposeFn();\n }\n });\n\n const scope = {\n get disposalSignal() {\n return disposable.disposalSignal;\n },\n dispose: disposable.dispose,\n get disposed() {\n return disposable.disposed;\n },\n get isDragging() {\n return state.active !== null;\n },\n [SCOPE_BRAND]: true as const,\n [Symbol.dispose]: disposable[Symbol.dispose],\n } as SortableScope;\n\n sortableScopeStates.set(scope, state);\n\n return scope;\n}\n\n// ─── createSortable ───────────────────────────────────────────────────────────\n\n/**\n * Makes a list of items sortable via native HTML drag interactions.\n *\n * Provide `getKey` to map each item element to a stable string identity.\n * `createSortable` marks qualifying children with `data-dnd-item` and sets\n * `draggable=\"true\"` automatically.\n *\n * Style the drop indicator by targeting `.dnd-placeholder` in your CSS.\n * Supports keyboard reordering (arrow keys, Home/End) and auto-scrolling near edges.\n *\n * @example\n * ```ts\n * import { createSortable } from '@vielzeug/dnd';\n *\n * using sortable = createSortable({\n * element: listEl,\n * getKey: (el) => el.dataset.id!,\n * onReorder: ({ ids, setRevert }) => {\n * const prev = order;\n * setOrder(ids);\n * setRevert(() => setOrder(prev));\n * },\n * });\n * ```\n */\nexport function createSortable(options: SortableOptions): Sortable {\n const {\n autoScroll = true,\n axis = 'vertical',\n element,\n getKey,\n handle,\n keyboard = true,\n placeholderClass = 'dnd-placeholder',\n scope = createSortableScope(),\n } = options;\n const autoScrollOptions = resolveAutoScrollOptions(autoScroll);\n const scopeState = getSortableScopeState(scope);\n\n if (handle !== undefined && handle.trim() === '') {\n warn(\n 'handle option is an empty string — no handle elements will be found. Provide a valid CSS selector or omit the option.',\n );\n }\n\n const getItems = (): HTMLElement[] =>\n Array.from(element.children).filter((c) => (c as HTMLElement).hasAttribute(ITEM_ATTR)) as HTMLElement[];\n\n const getOrderedIds = (): string[] => getItems().map((el) => getKey(el));\n\n const syncItems = (): void => {\n clearHandleAttributes(element);\n\n getItems().forEach((el) => {\n el.setAttribute('role', 'listitem');\n el.tabIndex = 0;\n\n if (handle) {\n el.removeAttribute('draggable');\n el.querySelectorAll<HTMLElement>(handle).forEach((handleEl) => {\n handleEl.setAttribute(HANDLE_ATTR, '');\n handleEl.setAttribute('draggable', 'true');\n });\n } else {\n el.setAttribute('draggable', 'true');\n }\n });\n };\n\n const markItems = (): void => {\n const seenKeys = new Set<string>();\n\n // Mark all children that have a key as sortable items\n Array.from(element.children).forEach((child) => {\n const el = child as HTMLElement;\n\n try {\n const key = getKey(el);\n\n if (key) {\n if (seenKeys.has(key)) {\n warn(\n `getKey returned the duplicate key \"${key}\" for two sibling items — onReorder's ids and applyReorder may become inconsistent. Ensure getKey returns a unique value per item.`,\n );\n } else {\n seenKeys.add(key);\n }\n\n el.setAttribute(ITEM_ATTR, '');\n }\n } catch (err) {\n warn(\n `getKey threw for a child element — the item will not be sortable. Check your getKey implementation. ${String(err)}`,\n );\n }\n });\n\n syncItems();\n };\n\n const cleanupItems = (): void => {\n clearHandleAttributes(element);\n\n element.querySelectorAll<HTMLElement>(`[${ITEM_ATTR}]`).forEach((item) => {\n item.removeAttribute(ITEM_ATTR);\n item.removeAttribute('draggable');\n item.removeAttribute('role');\n item.removeAttribute('tabindex');\n });\n };\n\n const createPlaceholder = (source: HTMLElement): HTMLElement => {\n const p = document.createElement('div');\n\n p.className = placeholderClass;\n p.setAttribute('aria-hidden', 'true');\n\n if (axis === 'horizontal') {\n p.style.width = `${source.offsetWidth}px`;\n } else {\n p.style.height = `${source.offsetHeight}px`;\n }\n\n return p;\n };\n\n let lastRevert: (() => void) | null = null;\n\n const handle_: ContainerHandle = {\n commitReorder: (orderedIds) => {\n if (!options.onReorder) return;\n\n const event: ReorderEvent = {\n ids: orderedIds,\n setRevert(fn) {\n lastRevert = fn;\n },\n };\n\n options.onReorder(event);\n },\n getOrderedIds,\n isDisabled: () => resolveDisabled(options.disabled),\n notifyBeforeReorder: (from, to) => options.onBeforeReorder?.(from, to),\n notifyDragEnd: (id, event) => options.onDragEnd?.(id, event),\n notifyDragStart: (id, event) => options.onDragStart?.(id, event),\n };\n\n scopeState.handles.add(handle_);\n\n const handleDragStart = (e: DragEvent): void => {\n if (scopeState.active) return;\n\n if (handle_.isDisabled()) return;\n\n const target = e.target as HTMLElement;\n const item = target.closest<HTMLElement>(`[${ITEM_ATTR}]`);\n\n if (!item) return;\n\n if (handle && !target.closest(handle)) return;\n\n const originalParent = item.parentElement;\n\n if (!originalParent) return;\n\n const placeholder = createPlaceholder(item);\n const originalNextSibling = item.nextSibling;\n const activeId = getKey(item);\n\n // Snapshot only the source handle at drag start; targets are snapshotted lazily.\n const initialOrders = new Map<ContainerHandle, string[]>();\n\n initialOrders.set(handle_, handle_.getOrderedIds());\n item.setAttribute('data-dragging', '');\n originalParent.insertBefore(placeholder, originalNextSibling);\n\n const session: DragSession = {\n draggedEl: item,\n draggedId: activeId,\n hideFrame: null,\n initialOrders,\n originalDisplay: item.style.display,\n originalNextSibling,\n originalParent,\n placeholder,\n source: handle_,\n target: handle_,\n };\n\n scheduleHide(session);\n scopeState.active = session;\n\n if (e.dataTransfer) {\n e.dataTransfer.effectAllowed = 'move';\n e.dataTransfer.setData('text/plain', activeId);\n\n if (options.dragImage) {\n const preview =\n typeof options.dragImage === 'function' ? options.dragImage(activeId, item, e) : options.dragImage;\n const [offsetX, offsetY] = options.dragImageOffset ?? [0, 0];\n\n if (preview) e.dataTransfer.setDragImage(preview, offsetX, offsetY);\n }\n }\n\n handle_.notifyDragStart(session.draggedId, e);\n };\n\n const handleDragOver = (e: DragEvent): void => {\n const session = scopeState.active;\n\n if (!session) return;\n\n if (session.source.isDisabled() || handle_.isDisabled()) return;\n\n e.preventDefault();\n maybeAutoScroll(e, element, axis, autoScrollOptions);\n\n // Lazily snapshot this handle's order the first time it becomes a target.\n snapshotOrder(session, handle_);\n\n const { draggedEl, placeholder } = session;\n const target = (e.target as HTMLElement).closest<HTMLElement>(`[${ITEM_ATTR}]`);\n\n if (!target) {\n // Only append placeholder when it isn't already inside this container.\n // Moving it to the end on every over-empty-space event causes the\n // placeholder to oscillate between positions as the cursor moves.\n if (placeholder.parentElement !== element) {\n element.appendChild(placeholder);\n }\n\n session.target = handle_;\n\n return;\n }\n\n if (target === draggedEl || target === placeholder) return;\n\n const rect = target.getBoundingClientRect();\n const insertAfter =\n axis === 'vertical' ? e.clientY >= rect.top + rect.height / 2 : e.clientX >= rect.left + rect.width / 2;\n\n element.insertBefore(placeholder, insertAfter ? target.nextSibling : target);\n session.target = handle_;\n };\n\n const handleDrop = (e: DragEvent): void => {\n const session = scopeState.active;\n\n if (!session) return;\n\n if (session.source.isDisabled() || handle_.isDisabled()) return;\n\n e.preventDefault();\n // Record the drop target; the actual commit happens in handleDragEnd where\n // dataTransfer.dropEffect tells us whether the browser accepted the operation.\n session.target = handle_;\n };\n\n const handleDragEnd = (e: DragEvent): void => {\n if (scopeState.active?.source !== handle_) return;\n\n finishSession(scopeState, e, false);\n };\n\n const handleKeydown = (e: KeyboardEvent): void => {\n if (!keyboard || handle_.isDisabled()) return;\n\n const tagName = (e.target as HTMLElement | null)?.tagName;\n\n if (tagName === 'INPUT' || tagName === 'TEXTAREA' || tagName === 'SELECT') return;\n\n const item = (e.target as HTMLElement).closest<HTMLElement>(`[${ITEM_ATTR}]`);\n\n if (!item || !element.contains(item)) return;\n\n const prevOrder = getOrderedIds();\n const newOrder = applyKeyboardReorder(item, element, getItems, getOrderedIds, e.key, axis);\n\n // null means unrecognized key or boundary — let the browser handle it (e.g. page scroll)\n if (newOrder === null) return;\n\n e.preventDefault();\n handle_.notifyBeforeReorder(prevOrder, newOrder);\n handle_.commitReorder(newOrder);\n };\n\n markItems();\n\n const disposable = createDisposable(() => {\n scopeState.disposables.delete(disposable.dispose);\n\n if (scopeState.active && (scopeState.active.source === handle_ || scopeState.active.target === handle_)) {\n finishSession(scopeState, new Event('dragend') as DragEvent, true);\n }\n\n scopeState.handles.delete(handle_);\n element.removeAttribute('role');\n cleanupItems();\n });\n\n element.setAttribute('role', 'list');\n element.addEventListener('dragstart', handleDragStart, { signal: disposable.disposalSignal });\n element.addEventListener('dragover', handleDragOver, { signal: disposable.disposalSignal });\n element.addEventListener('drop', handleDrop, { signal: disposable.disposalSignal });\n element.addEventListener('dragend', handleDragEnd, { signal: disposable.disposalSignal });\n element.addEventListener('keydown', handleKeydown, { signal: disposable.disposalSignal });\n\n // Register with scope so scope.dispose() can tear this down\n scopeState.disposables.add(disposable.dispose);\n\n return {\n get disposalSignal() {\n return disposable.disposalSignal;\n },\n dispose: disposable.dispose,\n get disposed() {\n return disposable.disposed;\n },\n get isDragging() {\n return scopeState.active?.source === handle_;\n },\n revert: () => {\n lastRevert?.();\n lastRevert = null;\n },\n [Symbol.dispose]: disposable[Symbol.dispose],\n sync: () => {\n markItems();\n },\n };\n}\n\n// ─── applyReorder ─────────────────────────────────────────────────────────────\n\n/**\n * Applies a sorted key array to a backing data array.\n * Unknown keys are ignored; items not present in `ids` are appended in original order.\n */\nexport function applyReorder<T>(items: T[], ids: string[], getKey: (item: T) => string): T[] {\n const byId = new Map(items.map((item) => [getKey(item), item] as const));\n const ordered: T[] = [];\n\n for (const id of ids) {\n if (!byId.has(id)) continue;\n\n const item = byId.get(id) as T;\n\n ordered.push(item);\n byId.delete(id);\n }\n\n for (const item of byId.values()) ordered.push(item);\n\n return ordered;\n}\n"],"mappings":";;;;AAOA,IAAM,IAAc,OAAO,eAAe,GA6MpC,IAAc,mBACd,IAAY,iBACZ,oBAAsB,IAAI,QAA2C,GACrE,IAAiD;CACrD,WAAW;CACX,eAAe;CACf,OAAO;CACP,UAAU;AACZ;AAIA,SAAS,EAAsB,GAA0C;CACvE,IAAM,IAAQ,EAAoB,IAAI,CAAK;CAE3C,IAAI,CAAC,GAAO,MAAM,IAAI,EAAc;CAEpC,OAAO;AACT;AAIA,SAAS,EACP,GACkC;CAKlC,OAJI,MAAe,KAAc,OAE7B,MAAe,MAAQ,MAAe,KAAA,IAAkB,IAErD;EACL,WAAW,EAAW,aAAa;EACnC,eAAe,EAAW,iBAAiB;EAC3C,OAAO,EAAW,SAAS;EAC3B,UAAU,EAAW,YAAY;CACnC;AACF;AAIA,SAAS,EAAgB,GAAkB,GAA0B;CACnE,OAAO,EAAM,WAAW,EAAO,UAAU,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EAAE,QAAQ,EAAW,eAAe,CAAC,GACxF,EAAQ,iBAAiB,WAAW,GAAe,EAAE,QAAQ,EAAW,eAAe,CAAC,GAGxF,EAAW,YAAY,IAAI,EAAW,OAAO,GAEtC;EACL,IAAI,iBAAiB;GACnB,OAAO,EAAW;EACpB;EACA,SAAS,EAAW;EACpB,IAAI,WAAW;GACb,OAAO,EAAW;EACpB;EACA,IAAI,aAAa;GACf,OAAO,EAAW,QAAQ,WAAW;EACvC;EACA,cAAc;GAEZ,AADA,IAAa,GACb,IAAa;EACf;GACC,OAAO,UAAU,EAAW,OAAO;EACpC,YAAY;GACV,EAAU;EACZ;CACF;AACF;AAQA,SAAgB,EAAgB,GAAY,GAAe,GAAkC;CAC3F,IAAM,IAAO,IAAI,IAAI,EAAM,KAAK,MAAS,CAAC,EAAO,CAAI,GAAG,CAAI,CAAU,CAAC,GACjE,IAAe,CAAC;CAEtB,KAAK,IAAM,KAAM,GAAK;EACpB,IAAI,CAAC,EAAK,IAAI,CAAE,GAAG;EAEnB,IAAM,IAAO,EAAK,IAAI,CAAE;EAGxB,AADA,EAAQ,KAAK,CAAI,GACjB,EAAK,OAAO,CAAE;CAChB;CAEA,KAAK,IAAM,KAAQ,EAAK,OAAO,GAAG,EAAQ,KAAK,CAAI;CAEnD,OAAO;AACT"}
|
package/dist/touch.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./_shared.cjs");function t(){try{return new DataTransfer}catch{return{dropEffect:`move`,effectAllowed:`move`,getData:()=>``,setData(){},setDragImage(){}}}}function n(n={}){let r=t(),i=null,a=null,o=e.createDisposable(()=>{i=null,a=null});function s(e,t,n,i){let a=new Event(t,{bubbles:!0,cancelable:!0});Object.defineProperty(a,"clientX",{configurable:!0,value:n}),Object.defineProperty(a,"clientY",{configurable:!0,value:i}),Object.defineProperty(a,"dataTransfer",{configurable:!0,value:r}),e.dispatchEvent(a)}return document.addEventListener(`touchstart`,t=>{if(e.resolveDisabled(n.disabled))return;let r=t.touches[0];if(!r)return;let o=document.elementFromPoint(r.clientX,r.clientY)?.closest(n.draggableSelector??`[draggable="true"]`);o&&(i=o,a=o,s(o,`dragstart`,r.clientX,r.clientY),t.preventDefault())},{passive:!1,signal:o.disposalSignal}),document.addEventListener(`touchmove`,e=>{if(!i)return;let t=e.touches[0];if(!t)return;let n=i.style.display;i.style.display=`none`;let r=document.elementFromPoint(t.clientX,t.clientY);i.style.display=n,r&&r!==a&&(a&&s(a,`dragleave`,t.clientX,t.clientY),a=r),r&&s(r,`dragover`,t.clientX,t.clientY),e.preventDefault()},{passive:!1,signal:o.disposalSignal}),document.addEventListener(`touchend`,e=>{if(!i)return;let t=e.changedTouches[0];if(!t)return;let n=i.style.display;i.style.display=`none`;let r=document.elementFromPoint(t.clientX,t.clientY);i.style.display=n,r&&s(r,`drop`,t.clientX,t.clientY),s(i,`dragend`,t.clientX,t.clientY),i=null,a=null},{passive:!0,signal:o.disposalSignal}),document.addEventListener(`touchcancel`,e=>{if(!i)return;let t=e.changedTouches[0];t&&(s(i,`dragend`,t.clientX,t.clientY),i=null,a=null)},{passive:!0,signal:o.disposalSignal}),o}exports.createTouchDragShim=n;
|
|
2
|
+
//# sourceMappingURL=touch.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"touch.cjs","names":[],"sources":["../src/touch.ts"],"sourcesContent":["import { createDisposable, resolveDisabled } from './_shared';\nimport { type Disposable } from './types';\n\nexport interface TouchDragOptions {\n /**\n * Set to `true` (or mutate this same options object's field later) to pause the shim without\n * disposing it — matches `createSortable`'s/`createDropZone`'s own `disabled` option.\n */\n disabled?: boolean;\n /**\n * CSS selector identifying draggable elements. Defaults to `[draggable=\"true\"]` — the exact\n * attribute `createSortable`/`createDropZone`-managed elements already carry, so the default\n * needs no configuration for the common case of bridging touch to an existing sortable/drop zone.\n */\n draggableSelector?: string;\n}\n\nfunction makeDataTransfer(): DataTransfer {\n try {\n return new DataTransfer();\n } catch {\n // Safari < 14 does not expose the DataTransfer constructor.\n return {\n dropEffect: 'move',\n effectAllowed: 'move',\n getData: () => '',\n setData() {},\n setDragImage() {},\n } as unknown as DataTransfer;\n }\n}\n\n/**\n * Bridges touch gestures to the synthetic `DragEvent` sequence `createSortable()`/\n * `createDropZone()` already listen for. HTML5 drag-and-drop has no native touch story —\n * this translates `touchstart`/`touchmove`/`touchend`/`touchcancel` into\n * `dragstart`/`dragover`/`drop`/`dragend` on the same document, so touch devices get\n * sortable/drop-zone behavior for free with no extra wiring at each call site.\n *\n * Listens at the `document` level (matching how `createSortable`/`createDropZone` themselves\n * scope drag detection) — one instance covers the whole page. Dispose to remove all listeners.\n *\n * @example\n * ```ts\n * using touchDrag = createTouchDragShim();\n * // ...later, or via the `using` declaration above:\n * touchDrag.dispose();\n * ```\n */\nexport function createTouchDragShim(options: TouchDragOptions = {}): Disposable {\n const dt = makeDataTransfer();\n\n let dragging: HTMLElement | null = null;\n let lastTarget: Element | null = null;\n\n const disposable = createDisposable(() => {\n dragging = null;\n lastTarget = null;\n });\n\n // Built on a plain `Event` rather than `new DragEvent(...)`: jsdom (and potentially other\n // non-browser DOM implementations) doesn't expose a `DragEvent` constructor at all, and\n // `createSortable`/`createDropZone`'s own handlers only ever read `type`/`clientX`/`clientY`/\n // `dataTransfer` off the event object — they never check `instanceof DragEvent` — so a patched\n // plain `Event` is indistinguishable to them and works everywhere a real `DragEvent` would.\n function dispatch(el: Element, type: string, clientX: number, clientY: number): void {\n const event = new Event(type, { bubbles: true, cancelable: true });\n\n Object.defineProperty(event, 'clientX', { configurable: true, value: clientX });\n Object.defineProperty(event, 'clientY', { configurable: true, value: clientY });\n Object.defineProperty(event, 'dataTransfer', { configurable: true, value: dt });\n el.dispatchEvent(event);\n }\n\n document.addEventListener(\n 'touchstart',\n (e: TouchEvent) => {\n if (resolveDisabled(options.disabled)) return;\n\n const touch = e.touches[0];\n\n if (!touch) return;\n\n const target = document.elementFromPoint(touch.clientX, touch.clientY) as HTMLElement | null;\n const draggable = target?.closest<HTMLElement>(options.draggableSelector ?? '[draggable=\"true\"]');\n\n if (!draggable) return;\n\n dragging = draggable;\n lastTarget = draggable;\n dispatch(draggable, 'dragstart', touch.clientX, touch.clientY);\n // Prevent scroll while dragging.\n e.preventDefault();\n },\n { passive: false, signal: disposable.disposalSignal },\n );\n\n document.addEventListener(\n 'touchmove',\n (e: TouchEvent) => {\n if (!dragging) return;\n\n const touch = e.touches[0];\n\n if (!touch) return;\n\n // Hide the dragged element temporarily so elementFromPoint sees what's beneath it.\n const prevDisplay = dragging.style.display;\n\n dragging.style.display = 'none';\n\n const below = document.elementFromPoint(touch.clientX, touch.clientY);\n\n dragging.style.display = prevDisplay;\n\n if (below && below !== lastTarget) {\n if (lastTarget) dispatch(lastTarget, 'dragleave', touch.clientX, touch.clientY);\n\n lastTarget = below;\n }\n\n if (below) dispatch(below, 'dragover', touch.clientX, touch.clientY);\n\n e.preventDefault();\n },\n { passive: false, signal: disposable.disposalSignal },\n );\n\n document.addEventListener(\n 'touchend',\n (e: TouchEvent) => {\n if (!dragging) return;\n\n const touch = e.changedTouches[0];\n\n if (!touch) return;\n\n const prevDisplay = dragging.style.display;\n\n dragging.style.display = 'none';\n\n const below = document.elementFromPoint(touch.clientX, touch.clientY);\n\n dragging.style.display = prevDisplay;\n\n if (below) dispatch(below, 'drop', touch.clientX, touch.clientY);\n\n dispatch(dragging, 'dragend', touch.clientX, touch.clientY);\n\n dragging = null;\n lastTarget = null;\n },\n { passive: true, signal: disposable.disposalSignal },\n );\n\n document.addEventListener(\n 'touchcancel',\n (e: TouchEvent) => {\n if (!dragging) return;\n\n const touch = e.changedTouches[0];\n\n if (!touch) return;\n\n dispatch(dragging, 'dragend', touch.clientX, touch.clientY);\n dragging = null;\n lastTarget = null;\n },\n { passive: true, signal: disposable.disposalSignal },\n );\n\n return disposable;\n}\n"],"mappings":"iCAiBA,SAAS,GAAiC,CACxC,GAAI,CACF,OAAO,IAAI,YACb,MAAQ,CAEN,MAAO,CAC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,QAAU,EAErB,GAAS,IAAU,IACjB,GAAY,EAAS,EAAY,YAAa,EAAM,QAAS,EAAM,OAAO,EAE9E,EAAa,GAGX,GAAO,EAAS,EAAO,WAAY,EAAM,QAAS,EAAM,OAAO,EAEnE,EAAE,eAAe,CACnB,EACA,CAAE,QAAS,GAAO,OAAQ,EAAW,cAAe,CACtD,EAEA,SAAS,iBACP,WACC,GAAkB,CACjB,GAAI,CAAC,EAAU,OAEf,IAAM,EAAQ,EAAE,eAAe,GAE/B,GAAI,CAAC,EAAO,OAEZ,IAAM,EAAc,EAAS,MAAM,QAEnC,EAAS,MAAM,QAAU,OAEzB,IAAM,EAAQ,SAAS,iBAAiB,EAAM,QAAS,EAAM,OAAO,EAEpE,EAAS,MAAM,QAAU,EAErB,GAAO,EAAS,EAAO,OAAQ,EAAM,QAAS,EAAM,OAAO,EAE/D,EAAS,EAAU,UAAW,EAAM,QAAS,EAAM,OAAO,EAE1D,EAAW,KACX,EAAa,IACf,EACA,CAAE,QAAS,GAAM,OAAQ,EAAW,cAAe,CACrD,EAEA,SAAS,iBACP,cACC,GAAkB,CACjB,GAAI,CAAC,EAAU,OAEf,IAAM,EAAQ,EAAE,eAAe,GAE1B,IAEL,EAAS,EAAU,UAAW,EAAM,QAAS,EAAM,OAAO,EAC1D,EAAW,KACX,EAAa,KACf,EACA,CAAE,QAAS,GAAM,OAAQ,EAAW,cAAe,CACrD,EAEO,CACT"}
|
package/dist/touch.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Disposable } from './types';
|
|
2
|
+
export interface TouchDragOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Set to `true` (or mutate this same options object's field later) to pause the shim without
|
|
5
|
+
* disposing it — matches `createSortable`'s/`createDropZone`'s own `disabled` option.
|
|
6
|
+
*/
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* CSS selector identifying draggable elements. Defaults to `[draggable="true"]` — the exact
|
|
10
|
+
* attribute `createSortable`/`createDropZone`-managed elements already carry, so the default
|
|
11
|
+
* needs no configuration for the common case of bridging touch to an existing sortable/drop zone.
|
|
12
|
+
*/
|
|
13
|
+
draggableSelector?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Bridges touch gestures to the synthetic `DragEvent` sequence `createSortable()`/
|
|
17
|
+
* `createDropZone()` already listen for. HTML5 drag-and-drop has no native touch story —
|
|
18
|
+
* this translates `touchstart`/`touchmove`/`touchend`/`touchcancel` into
|
|
19
|
+
* `dragstart`/`dragover`/`drop`/`dragend` on the same document, so touch devices get
|
|
20
|
+
* sortable/drop-zone behavior for free with no extra wiring at each call site.
|
|
21
|
+
*
|
|
22
|
+
* Listens at the `document` level (matching how `createSortable`/`createDropZone` themselves
|
|
23
|
+
* scope drag detection) — one instance covers the whole page. Dispose to remove all listeners.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* using touchDrag = createTouchDragShim();
|
|
28
|
+
* // ...later, or via the `using` declaration above:
|
|
29
|
+
* touchDrag.dispose();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function createTouchDragShim(options?: TouchDragOptions): Disposable;
|
|
33
|
+
//# sourceMappingURL=touch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"touch.d.ts","sourceRoot":"","sources":["../src/touch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAiBD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,gBAAqB,GAAG,UAAU,CA2H9E"}
|
package/dist/touch.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createDisposable as e, resolveDisabled as t } from "./_shared.js";
|
|
2
|
+
//#region src/touch.ts
|
|
3
|
+
function n() {
|
|
4
|
+
try {
|
|
5
|
+
return new DataTransfer();
|
|
6
|
+
} catch {
|
|
7
|
+
return {
|
|
8
|
+
dropEffect: "move",
|
|
9
|
+
effectAllowed: "move",
|
|
10
|
+
getData: () => "",
|
|
11
|
+
setData() {},
|
|
12
|
+
setDragImage() {}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function r(r = {}) {
|
|
17
|
+
let i = n(), a = null, o = null, s = e(() => {
|
|
18
|
+
a = null, o = null;
|
|
19
|
+
});
|
|
20
|
+
function c(e, t, n, r) {
|
|
21
|
+
let a = new Event(t, {
|
|
22
|
+
bubbles: !0,
|
|
23
|
+
cancelable: !0
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(a, "clientX", {
|
|
26
|
+
configurable: !0,
|
|
27
|
+
value: n
|
|
28
|
+
}), Object.defineProperty(a, "clientY", {
|
|
29
|
+
configurable: !0,
|
|
30
|
+
value: r
|
|
31
|
+
}), Object.defineProperty(a, "dataTransfer", {
|
|
32
|
+
configurable: !0,
|
|
33
|
+
value: i
|
|
34
|
+
}), e.dispatchEvent(a);
|
|
35
|
+
}
|
|
36
|
+
return document.addEventListener("touchstart", (e) => {
|
|
37
|
+
if (t(r.disabled)) return;
|
|
38
|
+
let n = e.touches[0];
|
|
39
|
+
if (!n) return;
|
|
40
|
+
let i = document.elementFromPoint(n.clientX, n.clientY)?.closest(r.draggableSelector ?? "[draggable=\"true\"]");
|
|
41
|
+
i && (a = i, o = i, c(i, "dragstart", n.clientX, n.clientY), e.preventDefault());
|
|
42
|
+
}, {
|
|
43
|
+
passive: !1,
|
|
44
|
+
signal: s.disposalSignal
|
|
45
|
+
}), document.addEventListener("touchmove", (e) => {
|
|
46
|
+
if (!a) return;
|
|
47
|
+
let t = e.touches[0];
|
|
48
|
+
if (!t) return;
|
|
49
|
+
let n = a.style.display;
|
|
50
|
+
a.style.display = "none";
|
|
51
|
+
let r = document.elementFromPoint(t.clientX, t.clientY);
|
|
52
|
+
a.style.display = n, r && r !== o && (o && c(o, "dragleave", t.clientX, t.clientY), o = r), r && c(r, "dragover", t.clientX, t.clientY), e.preventDefault();
|
|
53
|
+
}, {
|
|
54
|
+
passive: !1,
|
|
55
|
+
signal: s.disposalSignal
|
|
56
|
+
}), document.addEventListener("touchend", (e) => {
|
|
57
|
+
if (!a) return;
|
|
58
|
+
let t = e.changedTouches[0];
|
|
59
|
+
if (!t) return;
|
|
60
|
+
let n = a.style.display;
|
|
61
|
+
a.style.display = "none";
|
|
62
|
+
let r = document.elementFromPoint(t.clientX, t.clientY);
|
|
63
|
+
a.style.display = n, r && c(r, "drop", t.clientX, t.clientY), c(a, "dragend", t.clientX, t.clientY), a = null, o = null;
|
|
64
|
+
}, {
|
|
65
|
+
passive: !0,
|
|
66
|
+
signal: s.disposalSignal
|
|
67
|
+
}), document.addEventListener("touchcancel", (e) => {
|
|
68
|
+
if (!a) return;
|
|
69
|
+
let t = e.changedTouches[0];
|
|
70
|
+
t && (c(a, "dragend", t.clientX, t.clientY), a = null, o = null);
|
|
71
|
+
}, {
|
|
72
|
+
passive: !0,
|
|
73
|
+
signal: s.disposalSignal
|
|
74
|
+
}), s;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
export { r as createTouchDragShim };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=touch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"touch.js","names":[],"sources":["../src/touch.ts"],"sourcesContent":["import { createDisposable, resolveDisabled } from './_shared';\nimport { type Disposable } from './types';\n\nexport interface TouchDragOptions {\n /**\n * Set to `true` (or mutate this same options object's field later) to pause the shim without\n * disposing it — matches `createSortable`'s/`createDropZone`'s own `disabled` option.\n */\n disabled?: boolean;\n /**\n * CSS selector identifying draggable elements. Defaults to `[draggable=\"true\"]` — the exact\n * attribute `createSortable`/`createDropZone`-managed elements already carry, so the default\n * needs no configuration for the common case of bridging touch to an existing sortable/drop zone.\n */\n draggableSelector?: string;\n}\n\nfunction makeDataTransfer(): DataTransfer {\n try {\n return new DataTransfer();\n } catch {\n // Safari < 14 does not expose the DataTransfer constructor.\n return {\n dropEffect: 'move',\n effectAllowed: 'move',\n getData: () => '',\n setData() {},\n setDragImage() {},\n } as unknown as DataTransfer;\n }\n}\n\n/**\n * Bridges touch gestures to the synthetic `DragEvent` sequence `createSortable()`/\n * `createDropZone()` already listen for. HTML5 drag-and-drop has no native touch story —\n * this translates `touchstart`/`touchmove`/`touchend`/`touchcancel` into\n * `dragstart`/`dragover`/`drop`/`dragend` on the same document, so touch devices get\n * sortable/drop-zone behavior for free with no extra wiring at each call site.\n *\n * Listens at the `document` level (matching how `createSortable`/`createDropZone` themselves\n * scope drag detection) — one instance covers the whole page. Dispose to remove all listeners.\n *\n * @example\n * ```ts\n * using touchDrag = createTouchDragShim();\n * // ...later, or via the `using` declaration above:\n * touchDrag.dispose();\n * ```\n */\nexport function createTouchDragShim(options: TouchDragOptions = {}): Disposable {\n const dt = makeDataTransfer();\n\n let dragging: HTMLElement | null = null;\n let lastTarget: Element | null = null;\n\n const disposable = createDisposable(() => {\n dragging = null;\n lastTarget = null;\n });\n\n // Built on a plain `Event` rather than `new DragEvent(...)`: jsdom (and potentially other\n // non-browser DOM implementations) doesn't expose a `DragEvent` constructor at all, and\n // `createSortable`/`createDropZone`'s own handlers only ever read `type`/`clientX`/`clientY`/\n // `dataTransfer` off the event object — they never check `instanceof DragEvent` — so a patched\n // plain `Event` is indistinguishable to them and works everywhere a real `DragEvent` would.\n function dispatch(el: Element, type: string, clientX: number, clientY: number): void {\n const event = new Event(type, { bubbles: true, cancelable: true });\n\n Object.defineProperty(event, 'clientX', { configurable: true, value: clientX });\n Object.defineProperty(event, 'clientY', { configurable: true, value: clientY });\n Object.defineProperty(event, 'dataTransfer', { configurable: true, value: dt });\n el.dispatchEvent(event);\n }\n\n document.addEventListener(\n 'touchstart',\n (e: TouchEvent) => {\n if (resolveDisabled(options.disabled)) return;\n\n const touch = e.touches[0];\n\n if (!touch) return;\n\n const target = document.elementFromPoint(touch.clientX, touch.clientY) as HTMLElement | null;\n const draggable = target?.closest<HTMLElement>(options.draggableSelector ?? '[draggable=\"true\"]');\n\n if (!draggable) return;\n\n dragging = draggable;\n lastTarget = draggable;\n dispatch(draggable, 'dragstart', touch.clientX, touch.clientY);\n // Prevent scroll while dragging.\n e.preventDefault();\n },\n { passive: false, signal: disposable.disposalSignal },\n );\n\n document.addEventListener(\n 'touchmove',\n (e: TouchEvent) => {\n if (!dragging) return;\n\n const touch = e.touches[0];\n\n if (!touch) return;\n\n // Hide the dragged element temporarily so elementFromPoint sees what's beneath it.\n const prevDisplay = dragging.style.display;\n\n dragging.style.display = 'none';\n\n const below = document.elementFromPoint(touch.clientX, touch.clientY);\n\n dragging.style.display = prevDisplay;\n\n if (below && below !== lastTarget) {\n if (lastTarget) dispatch(lastTarget, 'dragleave', touch.clientX, touch.clientY);\n\n lastTarget = below;\n }\n\n if (below) dispatch(below, 'dragover', touch.clientX, touch.clientY);\n\n e.preventDefault();\n },\n { passive: false, signal: disposable.disposalSignal },\n );\n\n document.addEventListener(\n 'touchend',\n (e: TouchEvent) => {\n if (!dragging) return;\n\n const touch = e.changedTouches[0];\n\n if (!touch) return;\n\n const prevDisplay = dragging.style.display;\n\n dragging.style.display = 'none';\n\n const below = document.elementFromPoint(touch.clientX, touch.clientY);\n\n dragging.style.display = prevDisplay;\n\n if (below) dispatch(below, 'drop', touch.clientX, touch.clientY);\n\n dispatch(dragging, 'dragend', touch.clientX, touch.clientY);\n\n dragging = null;\n lastTarget = null;\n },\n { passive: true, signal: disposable.disposalSignal },\n );\n\n document.addEventListener(\n 'touchcancel',\n (e: TouchEvent) => {\n if (!dragging) return;\n\n const touch = e.changedTouches[0];\n\n if (!touch) return;\n\n dispatch(dragging, 'dragend', touch.clientX, touch.client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sortable lists, file-drop zones, and MIME-type filtering",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"dependencies": {},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/node": "^26.1.0",
|
|
39
|
-
"typescript": "
|
|
39
|
+
"typescript": "^6.0.3",
|
|
40
40
|
"vite": "^8.1.3",
|
|
41
|
-
"vitest": "^4.1.
|
|
41
|
+
"vitest": "^4.1.10"
|
|
42
42
|
}
|
|
43
43
|
}
|