@pyreon/dnd 0.12.8 → 0.12.10
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/lib/analysis/index.js.html +1 -1
- package/lib/index.js +20 -0
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/src/tests/dnd.test.ts +57 -0
- package/src/tests/integration.test.ts +1662 -0
- package/src/use-drag-monitor.ts +2 -0
- package/src/use-draggable.ts +2 -0
- package/src/use-droppable.ts +2 -0
- package/src/use-file-drop.ts +2 -0
- package/src/use-sortable.ts +11 -0
|
@@ -5386,7 +5386,7 @@ var drawChart = (function (exports) {
|
|
|
5386
5386
|
</script>
|
|
5387
5387
|
<script>
|
|
5388
5388
|
/*<!--*/
|
|
5389
|
-
const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.js","children":[{"name":"src","children":[{"uid":"
|
|
5389
|
+
const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.js","children":[{"name":"src","children":[{"uid":"8a5945b6-1","name":"use-drag-monitor.ts"},{"uid":"8a5945b6-3","name":"use-draggable.ts"},{"uid":"8a5945b6-5","name":"use-droppable.ts"},{"uid":"8a5945b6-7","name":"use-file-drop.ts"},{"uid":"8a5945b6-9","name":"use-sortable.ts"},{"uid":"8a5945b6-11","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"8a5945b6-1":{"renderedLength":1307,"gzipLength":625,"brotliLength":0,"metaUid":"8a5945b6-0"},"8a5945b6-3":{"renderedLength":1312,"gzipLength":600,"brotliLength":0,"metaUid":"8a5945b6-2"},"8a5945b6-5":{"renderedLength":1361,"gzipLength":597,"brotliLength":0,"metaUid":"8a5945b6-4"},"8a5945b6-7":{"renderedLength":2300,"gzipLength":939,"brotliLength":0,"metaUid":"8a5945b6-6"},"8a5945b6-9":{"renderedLength":5878,"gzipLength":2004,"brotliLength":0,"metaUid":"8a5945b6-8"},"8a5945b6-11":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"metaUid":"8a5945b6-10"}},"nodeMetas":{"8a5945b6-0":{"id":"/src/use-drag-monitor.ts","moduleParts":{"index.js":"8a5945b6-1"},"imported":[{"uid":"8a5945b6-12"},{"uid":"8a5945b6-13"}],"importedBy":[{"uid":"8a5945b6-10"}]},"8a5945b6-2":{"id":"/src/use-draggable.ts","moduleParts":{"index.js":"8a5945b6-3"},"imported":[{"uid":"8a5945b6-12"},{"uid":"8a5945b6-13"}],"importedBy":[{"uid":"8a5945b6-10"}]},"8a5945b6-4":{"id":"/src/use-droppable.ts","moduleParts":{"index.js":"8a5945b6-5"},"imported":[{"uid":"8a5945b6-12"},{"uid":"8a5945b6-13"}],"importedBy":[{"uid":"8a5945b6-10"}]},"8a5945b6-6":{"id":"/src/use-file-drop.ts","moduleParts":{"index.js":"8a5945b6-7"},"imported":[{"uid":"8a5945b6-14"},{"uid":"8a5945b6-15"},{"uid":"8a5945b6-13"}],"importedBy":[{"uid":"8a5945b6-10"}]},"8a5945b6-8":{"id":"/src/use-sortable.ts","moduleParts":{"index.js":"8a5945b6-9"},"imported":[{"uid":"8a5945b6-16"},{"uid":"8a5945b6-12"},{"uid":"8a5945b6-17"},{"uid":"8a5945b6-18"},{"uid":"8a5945b6-13"}],"importedBy":[{"uid":"8a5945b6-10"}]},"8a5945b6-10":{"id":"/src/index.ts","moduleParts":{"index.js":"8a5945b6-11"},"imported":[{"uid":"8a5945b6-0"},{"uid":"8a5945b6-2"},{"uid":"8a5945b6-4"},{"uid":"8a5945b6-6"},{"uid":"8a5945b6-8"}],"importedBy":[],"isEntry":true},"8a5945b6-12":{"id":"@atlaskit/pragmatic-drag-and-drop/element/adapter","moduleParts":{},"imported":[],"importedBy":[{"uid":"8a5945b6-0"},{"uid":"8a5945b6-2"},{"uid":"8a5945b6-4"},{"uid":"8a5945b6-8"}]},"8a5945b6-13":{"id":"@pyreon/reactivity","moduleParts":{},"imported":[],"importedBy":[{"uid":"8a5945b6-0"},{"uid":"8a5945b6-2"},{"uid":"8a5945b6-4"},{"uid":"8a5945b6-6"},{"uid":"8a5945b6-8"}]},"8a5945b6-14":{"id":"@atlaskit/pragmatic-drag-and-drop/external/adapter","moduleParts":{},"imported":[],"importedBy":[{"uid":"8a5945b6-6"}]},"8a5945b6-15":{"id":"@atlaskit/pragmatic-drag-and-drop/external/file","moduleParts":{},"imported":[],"importedBy":[{"uid":"8a5945b6-6"}]},"8a5945b6-16":{"id":"@atlaskit/pragmatic-drag-and-drop/combine","moduleParts":{},"imported":[],"importedBy":[{"uid":"8a5945b6-8"}]},"8a5945b6-17":{"id":"@atlaskit/pragmatic-drag-and-drop-auto-scroll/element","moduleParts":{},"imported":[],"importedBy":[{"uid":"8a5945b6-8"}]},"8a5945b6-18":{"id":"@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge","moduleParts":{},"imported":[],"importedBy":[{"uid":"8a5945b6-8"}]}},"env":{"rollup":"4.23.0"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
|
|
5390
5390
|
|
|
5391
5391
|
const run = () => {
|
|
5392
5392
|
const width = window.innerWidth;
|
package/lib/index.js
CHANGED
|
@@ -27,6 +27,10 @@ import { attachClosestEdge, extractClosestEdge } from "@atlaskit/pragmatic-drag-
|
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
29
|
function useDragMonitor(options) {
|
|
30
|
+
if (typeof document === "undefined") return {
|
|
31
|
+
isDragging: () => false,
|
|
32
|
+
dragData: () => null
|
|
33
|
+
};
|
|
30
34
|
const isDragging = signal(false);
|
|
31
35
|
const dragData = signal(null);
|
|
32
36
|
const canMonitorFn = options?.canMonitor ? ({ source }) => options.canMonitor?.(source.data) ?? true : null;
|
|
@@ -70,6 +74,7 @@ function useDragMonitor(options) {
|
|
|
70
74
|
* ```
|
|
71
75
|
*/
|
|
72
76
|
function useDraggable(options) {
|
|
77
|
+
if (typeof document === "undefined") return { isDragging: () => false };
|
|
73
78
|
const isDragging = signal(false);
|
|
74
79
|
let cleanup;
|
|
75
80
|
function setup() {
|
|
@@ -125,6 +130,7 @@ function useDraggable(options) {
|
|
|
125
130
|
* ```
|
|
126
131
|
*/
|
|
127
132
|
function useDroppable(options) {
|
|
133
|
+
if (typeof document === "undefined") return { isOver: () => false };
|
|
128
134
|
const isOver = signal(false);
|
|
129
135
|
let cleanup;
|
|
130
136
|
function setup() {
|
|
@@ -188,6 +194,10 @@ function useDroppable(options) {
|
|
|
188
194
|
* ```
|
|
189
195
|
*/
|
|
190
196
|
function useFileDrop(options) {
|
|
197
|
+
if (typeof document === "undefined") return {
|
|
198
|
+
isOver: () => false,
|
|
199
|
+
isDraggingFiles: () => false
|
|
200
|
+
};
|
|
191
201
|
const isOver = signal(false);
|
|
192
202
|
const isDraggingFiles = signal(false);
|
|
193
203
|
let cleanup;
|
|
@@ -285,6 +295,16 @@ let _sortableCounter = 0;
|
|
|
285
295
|
* ```
|
|
286
296
|
*/
|
|
287
297
|
function useSortable(options) {
|
|
298
|
+
if (typeof document === "undefined") {
|
|
299
|
+
const noop = () => {};
|
|
300
|
+
return {
|
|
301
|
+
containerRef: noop,
|
|
302
|
+
itemRef: () => noop,
|
|
303
|
+
activeId: () => null,
|
|
304
|
+
overId: () => null,
|
|
305
|
+
overEdge: () => null
|
|
306
|
+
};
|
|
307
|
+
}
|
|
288
308
|
const sortableId = `sortable-${++_sortableCounter}`;
|
|
289
309
|
const activeId = signal(null);
|
|
290
310
|
const overId = signal(null);
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/use-drag-monitor.ts","../src/use-draggable.ts","../src/use-droppable.ts","../src/use-file-drop.ts","../src/use-sortable.ts"],"sourcesContent":["import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter'\nimport { onCleanup, signal } from '@pyreon/reactivity'\nimport type { DragData } from './types'\n\nexport interface UseDragMonitorOptions {\n /** Called on any drag start in the page. */\n onDragStart?: (data: DragData) => void\n /** Called on any drop in the page. */\n onDrop?: (sourceData: DragData, targetData: DragData) => void\n /** Filter which drags to monitor. */\n canMonitor?: (data: DragData) => boolean\n}\n\nexport interface UseDragMonitorResult {\n /** Whether any element is currently being dragged. */\n isDragging: () => boolean\n /** Data of the currently dragging element (null if not dragging). */\n dragData: () => DragData | null\n}\n\n/**\n * Monitor all drag operations on the page.\n * Useful for global drag indicators, analytics, or coordination between\n * multiple drag-and-drop areas.\n *\n * @example\n * ```tsx\n * const { isDragging, dragData } = useDragMonitor({\n * canMonitor: (data) => data.type === \"card\",\n * onDrop: (source, target) => logDrop(source, target),\n * })\n *\n * <Show when={isDragging()}>\n * <div class=\"global-drag-overlay\">\n * Dragging: {() => dragData()?.name}\n * </div>\n * </Show>\n * ```\n */\nexport function useDragMonitor(options?: UseDragMonitorOptions): UseDragMonitorResult {\n const isDragging = signal(false)\n const dragData = signal<DragData | null>(null)\n\n const canMonitorFn = options?.canMonitor\n ? ({ source }: { source: { data: Record<string, unknown> } }) =>\n options.canMonitor?.(source.data as DragData) ?? true\n : null\n\n const cleanup = monitorForElements({\n ...(canMonitorFn ? { canMonitor: canMonitorFn } : {}),\n onDragStart: ({ source }) => {\n isDragging.set(true)\n dragData.set(source.data as DragData)\n options?.onDragStart?.(source.data as DragData)\n },\n onDrop: ({ source, location }) => {\n isDragging.set(false)\n dragData.set(null)\n const targetData = location.current.dropTargets[0]?.data ?? {}\n options?.onDrop?.(source.data as DragData, targetData as DragData)\n },\n })\n\n onCleanup(cleanup)\n\n return { isDragging, dragData }\n}\n","import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter'\nimport { onCleanup, signal } from '@pyreon/reactivity'\nimport type { DragData, UseDraggableOptions, UseDraggableResult } from './types'\n\n/**\n * Make an element draggable with signal-driven state.\n *\n * @example\n * ```tsx\n * let cardEl: HTMLElement | null = null\n *\n * const { isDragging } = useDraggable({\n * element: () => cardEl,\n * data: { id: card.id, type: \"card\" },\n * })\n *\n * <div ref={(el) => cardEl = el} class={isDragging() ? \"opacity-50\" : \"\"}>\n * {card.title}\n * </div>\n * ```\n */\nexport function useDraggable<T extends DragData = DragData>(\n options: UseDraggableOptions<T>,\n): UseDraggableResult {\n const isDragging = signal(false)\n let cleanup: (() => void) | undefined\n\n function setup() {\n if (cleanup) cleanup()\n\n const el = options.element()\n if (!el) return\n\n const resolveData = () =>\n typeof options.data === 'function' ? (options.data as () => T)() : options.data\n\n const handle = options.handle?.()\n cleanup = draggable({\n element: el,\n ...(handle ? { dragHandle: handle } : {}),\n getInitialData: resolveData,\n canDrag: () => {\n const disabled = options.disabled\n if (typeof disabled === 'function') return !disabled()\n return !disabled\n },\n onDragStart: () => {\n isDragging.set(true)\n options.onDragStart?.()\n },\n onDrop: () => {\n isDragging.set(false)\n options.onDragEnd?.()\n },\n })\n }\n\n // Defer setup to next microtask so refs are populated\n queueMicrotask(setup)\n\n onCleanup(() => {\n if (cleanup) cleanup()\n })\n\n return { isDragging }\n}\n","import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter'\nimport { onCleanup, signal } from '@pyreon/reactivity'\nimport type { DragData, UseDroppableOptions, UseDroppableResult } from './types'\n\n/**\n * Make an element a drop target with signal-driven state.\n *\n * @example\n * ```tsx\n * let zoneEl: HTMLElement | null = null\n *\n * const { isOver } = useDroppable({\n * element: () => zoneEl,\n * onDrop: (data) => handleDrop(data),\n * canDrop: (data) => data.type === \"card\",\n * })\n *\n * <div ref={(el) => zoneEl = el} class={isOver() ? \"bg-blue-50\" : \"\"}>\n * Drop here\n * </div>\n * ```\n */\nexport function useDroppable<T extends DragData = DragData>(\n options: UseDroppableOptions<T>,\n): UseDroppableResult {\n const isOver = signal(false)\n let cleanup: (() => void) | undefined\n\n function setup() {\n if (cleanup) cleanup()\n\n const el = options.element()\n if (!el) return\n\n cleanup = dropTargetForElements({\n element: el,\n getData: () => {\n if (!options.data) return {}\n return typeof options.data === 'function' ? (options.data as () => T)() : options.data\n },\n canDrop: ({ source }) => {\n if (!options.canDrop) return true\n return options.canDrop(source.data as DragData)\n },\n onDragEnter: ({ source }) => {\n isOver.set(true)\n options.onDragEnter?.(source.data as DragData)\n },\n onDragLeave: () => {\n isOver.set(false)\n options.onDragLeave?.()\n },\n onDrop: ({ source }) => {\n isOver.set(false)\n options.onDrop?.(source.data as DragData)\n },\n })\n }\n\n queueMicrotask(setup)\n\n onCleanup(() => {\n if (cleanup) cleanup()\n })\n\n return { isOver }\n}\n","import {\n dropTargetForExternal,\n monitorForExternal,\n} from '@atlaskit/pragmatic-drag-and-drop/external/adapter'\nimport { containsFiles, getFiles } from '@atlaskit/pragmatic-drag-and-drop/external/file'\nimport { onCleanup, signal } from '@pyreon/reactivity'\n\nexport interface UseFileDropOptions {\n /** Element getter for the drop zone. */\n element: () => HTMLElement | null\n /** Called when files are dropped. */\n onDrop: (files: File[]) => void\n /** Filter accepted file types (e.g. [\"image/*\", \".pdf\"]). */\n accept?: string[]\n /** Maximum number of files. */\n maxFiles?: number\n /** Whether drop is disabled. */\n disabled?: boolean | (() => boolean)\n}\n\nexport interface UseFileDropResult {\n /** Whether files are being dragged over the drop zone. */\n isOver: () => boolean\n /** Whether files are being dragged anywhere on the page. */\n isDraggingFiles: () => boolean\n}\n\n/**\n * File drop zone with signal-driven state.\n * Uses the native file drag events via pragmatic-drag-and-drop.\n *\n * @example\n * ```tsx\n * let dropZone: HTMLElement | null = null\n *\n * const { isOver, isDraggingFiles } = useFileDrop({\n * element: () => dropZone,\n * accept: [\"image/*\", \".pdf\"],\n * maxFiles: 5,\n * onDrop: (files) => upload(files),\n * })\n *\n * <div\n * ref={(el) => dropZone = el}\n * class={isOver() ? \"drop-active\" : isDraggingFiles() ? \"drop-ready\" : \"\"}\n * >\n * Drop files here\n * </div>\n * ```\n */\nexport function useFileDrop(options: UseFileDropOptions): UseFileDropResult {\n const isOver = signal(false)\n const isDraggingFiles = signal(false)\n let cleanup: (() => void) | undefined\n\n function matchesAccept(file: File, accept: string[]): boolean {\n return accept.some((pattern) => {\n if (pattern.startsWith('.')) {\n return file.name.toLowerCase().endsWith(pattern.toLowerCase())\n }\n if (pattern.endsWith('/*')) {\n return file.type.startsWith(pattern.slice(0, -1))\n }\n return file.type === pattern\n })\n }\n\n function setup() {\n if (cleanup) cleanup()\n\n const el = options.element()\n if (!el) return\n\n const cleanups: (() => void)[] = []\n\n // Monitor for file drags anywhere on the page\n cleanups.push(\n monitorForExternal({\n canMonitor: ({ source }) => containsFiles({ source }),\n onDragStart: () => isDraggingFiles.set(true),\n onDrop: () => isDraggingFiles.set(false),\n }),\n )\n\n // Drop target on the specific element\n cleanups.push(\n dropTargetForExternal({\n element: el,\n canDrop: ({ source }) => {\n const disabled = options.disabled\n if (typeof disabled === 'function' ? disabled() : disabled) return false\n return containsFiles({ source })\n },\n onDragEnter: () => isOver.set(true),\n onDragLeave: () => isOver.set(false),\n onDrop: ({ source }) => {\n isOver.set(false)\n isDraggingFiles.set(false)\n\n let files = getFiles({ source })\n\n // Filter by accept\n if (options.accept && options.accept.length > 0) {\n files = files.filter((f) => matchesAccept(f, options.accept as string[]))\n }\n\n // Limit count\n if (options.maxFiles && files.length > options.maxFiles) {\n files = files.slice(0, options.maxFiles)\n }\n\n if (files.length > 0) {\n options.onDrop(files)\n }\n },\n }),\n )\n\n cleanup = () => {\n for (const fn of cleanups) fn()\n }\n }\n\n queueMicrotask(setup)\n\n onCleanup(() => {\n if (cleanup) cleanup()\n })\n\n return { isOver, isDraggingFiles }\n}\n","import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine'\nimport { draggable, dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter'\nimport { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element'\nimport {\n attachClosestEdge,\n type Edge,\n extractClosestEdge,\n} from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge'\nimport { onCleanup, signal } from '@pyreon/reactivity'\nimport type { DropEdge, UseSortableOptions, UseSortableResult } from './types'\n\nconst SORT_KEY = '__pyreon_sortable_key'\nconst SORT_ID = '__pyreon_sortable_id'\n\nlet _sortableCounter = 0\n\n/**\n * Sortable list with signal-driven state, auto-scroll, and edge detection.\n *\n * Features:\n * - Keyed drag items matching `<For by={...}>` pattern\n * - Auto-scroll when dragging near container edges\n * - Closest-edge detection (drop above/below or left/right)\n * - Axis constraint (vertical/horizontal)\n * - Keyboard reordering (Alt+Arrow keys)\n *\n * @example\n * ```tsx\n * const items = signal([\n * { id: \"1\", name: \"Alice\" },\n * { id: \"2\", name: \"Bob\" },\n * { id: \"3\", name: \"Charlie\" },\n * ])\n *\n * const { containerRef, itemRef, activeId, overId, overEdge } = useSortable({\n * items,\n * by: (item) => item.id,\n * onReorder: (newItems) => items.set(newItems),\n * })\n *\n * <ul ref={containerRef}>\n * <For each={items()} by={item => item.id}>\n * {(item) => (\n * <li\n * ref={itemRef(item.id)}\n * class={activeId() === item.id ? \"dragging\" : \"\"}\n * style={overId() === item.id ? `border-${overEdge()}: 2px solid blue` : \"\"}\n * >\n * {item.name}\n * </li>\n * )}\n * </For>\n * </ul>\n * ```\n */\nexport function useSortable<T>(options: UseSortableOptions<T>): UseSortableResult {\n const sortableId = `sortable-${++_sortableCounter}`\n const activeId = signal<string | number | null>(null)\n const overId = signal<string | number | null>(null)\n const overEdge = signal<DropEdge | null>(null)\n const axis = options.axis ?? 'vertical'\n\n const cleanups: (() => void)[] = []\n\n /** Perform the reorder based on current active/over/edge state. */\n function performReorder() {\n const dragId = activeId.peek()\n const dropId = overId.peek()\n const edge = overEdge.peek()\n if (dragId == null || dropId == null || dragId === dropId) return\n\n const currentItems = options.items()\n const dragIndex = currentItems.findIndex((item) => options.by(item) === dragId)\n const dropIndex = currentItems.findIndex((item) => options.by(item) === dropId)\n if (dragIndex === -1 || dropIndex === -1) return\n\n const reordered = [...currentItems]\n const [moved] = reordered.splice(dragIndex, 1)\n if (!moved) return\n\n // Determine insert position based on closest edge\n const rawInsert =\n edge === 'bottom' || edge === 'right'\n ? dropIndex >= dragIndex\n ? dropIndex\n : dropIndex + 1\n : dropIndex <= dragIndex\n ? dropIndex\n : dropIndex - 1\n const insertAt = Math.max(0, Math.min(rawInsert, reordered.length))\n\n reordered.splice(insertAt, 0, moved)\n options.onReorder(reordered)\n }\n\n function containerRef(el: HTMLElement) {\n // Auto-scroll when dragging near container edges\n cleanups.push(\n autoScrollForElements({\n element: el,\n canScroll: ({ source }) => source.data[SORT_ID] === sortableId,\n }),\n )\n\n // Container is a drop target for reorder finalization\n cleanups.push(\n dropTargetForElements({\n element: el,\n getData: () => ({ [SORT_ID]: sortableId }),\n canDrop: ({ source }) => source.data[SORT_ID] === sortableId,\n onDrop: () => {\n performReorder()\n activeId.set(null)\n overId.set(null)\n overEdge.set(null)\n },\n }),\n )\n\n // Keyboard reordering: Alt+Arrow keys\n const keyHandler = (e: KeyboardEvent) => {\n if (!e.altKey) return\n\n const isUp = axis === 'vertical' ? e.key === 'ArrowUp' : e.key === 'ArrowLeft'\n const isDown = axis === 'vertical' ? e.key === 'ArrowDown' : e.key === 'ArrowRight'\n if (!isUp && !isDown) return\n\n const focused = document.activeElement as HTMLElement | null\n if (!focused || !el.contains(focused)) return\n\n const focusedKey = focused.dataset.pyreonSortKey\n if (!focusedKey) return\n\n e.preventDefault()\n\n const currentItems = options.items()\n const currentIndex = currentItems.findIndex((item) => String(options.by(item)) === focusedKey)\n if (currentIndex === -1) return\n\n const targetIndex = isUp ? currentIndex - 1 : currentIndex + 1\n if (targetIndex < 0 || targetIndex >= currentItems.length) return\n\n const reordered = [...currentItems]\n const temp = reordered[currentIndex]\n reordered[currentIndex] = reordered[targetIndex] as T\n reordered[targetIndex] = temp as T\n options.onReorder(reordered)\n\n // Restore focus after DOM update\n requestAnimationFrame(() => {\n const items = el.querySelectorAll('[data-pyreon-sort-key]')\n for (const item of items) {\n if ((item as HTMLElement).dataset.pyreonSortKey === focusedKey) {\n ;(item as HTMLElement).focus()\n break\n }\n }\n })\n }\n\n el.addEventListener('keydown', keyHandler)\n cleanups.push(() => el.removeEventListener('keydown', keyHandler))\n }\n\n function itemRef(key: string | number): (el: HTMLElement) => void {\n return (el: HTMLElement) => {\n el.dataset.pyreonSortKey = String(key)\n if (!el.hasAttribute('tabindex')) el.setAttribute('tabindex', '0')\n el.setAttribute('role', 'listitem')\n el.setAttribute('aria-roledescription', 'sortable item')\n\n const allowedEdges: Edge[] = axis === 'vertical' ? ['top', 'bottom'] : ['left', 'right']\n\n const cleanup = combine(\n draggable({\n element: el,\n getInitialData: () => ({\n [SORT_KEY]: key,\n [SORT_ID]: sortableId,\n }),\n onDragStart: () => activeId.set(key),\n onDrop: () => {\n queueMicrotask(() => {\n activeId.set(null)\n overId.set(null)\n overEdge.set(null)\n })\n },\n }),\n dropTargetForElements({\n element: el,\n getData: ({ input, element }) =>\n attachClosestEdge(\n { [SORT_KEY]: key, [SORT_ID]: sortableId },\n { input, element, allowedEdges },\n ),\n canDrop: ({ source }) => source.data[SORT_ID] === sortableId,\n onDragEnter: ({ self }) => {\n overId.set(key)\n overEdge.set(extractClosestEdge(self.data) as DropEdge | null)\n },\n onDrag: ({ self }) => {\n overEdge.set(extractClosestEdge(self.data) as DropEdge | null)\n },\n onDragLeave: () => {\n if (overId.peek() === key) {\n overId.set(null)\n overEdge.set(null)\n }\n },\n }),\n )\n\n cleanups.push(cleanup)\n }\n }\n\n onCleanup(() => {\n for (const cleanup of cleanups) cleanup()\n cleanups.length = 0\n activeId.set(null)\n overId.set(null)\n overEdge.set(null)\n })\n\n return { containerRef, itemRef, activeId, overId, overEdge }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,eAAe,SAAuD;CACpF,MAAM,aAAa,OAAO,MAAM;CAChC,MAAM,WAAW,OAAwB,KAAK;CAE9C,MAAM,eAAe,SAAS,cACzB,EAAE,aACD,QAAQ,aAAa,OAAO,KAAiB,IAAI,OACnD;AAiBJ,WAfgB,mBAAmB;EACjC,GAAI,eAAe,EAAE,YAAY,cAAc,GAAG,EAAE;EACpD,cAAc,EA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,aAAO,IAAI,KAAK;AAChB,eAAS,IAAI,KAAK;OAClB;;IAEL,CAAC,EACF,sBAAsB;IACpB,SAAS;IACT,UAAU,EAAE,OAAO,cACjB,kBACE;MAAG,WAAW;MAAM,UAAU;KAAY,EAC1C;KAAE;KAAO;KAAS;KAAc,CACjC;IACH,UAAU,EAAE,aAAa,OAAO,KAAK,aAAa;IAClD,cAAc,EAAE,WAAW;AACzB,YAAO,IAAI,IAAI;AACf,cAAS,IAAI,mBAAmB,KAAK,KAAK,CAAoB;;IAEhE,SAAS,EAAE,WAAW;AACpB,cAAS,IAAI,mBAAmB,KAAK,KAAK,CAAoB;;IAEhE,mBAAmB;AACjB,SAAI,OAAO,MAAM,KAAK,KAAK;AACzB,aAAO,IAAI,KAAK;AAChB,eAAS,IAAI,KAAK;;;IAGvB,CAAC,CACH;AAED,YAAS,KAAK,QAAQ;;;AAI1B,iBAAgB;AACd,OAAK,MAAM,WAAW,SAAU,UAAS;AACzC,WAAS,SAAS;AAClB,WAAS,IAAI,KAAK;AAClB,SAAO,IAAI,KAAK;AAChB,WAAS,IAAI,KAAK;GAClB;AAEF,QAAO;EAAE;EAAc;EAAS;EAAU;EAAQ;EAAU"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/use-drag-monitor.ts","../src/use-draggable.ts","../src/use-droppable.ts","../src/use-file-drop.ts","../src/use-sortable.ts"],"sourcesContent":["import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter'\nimport { onCleanup, signal } from '@pyreon/reactivity'\nimport type { DragData } from './types'\n\nexport interface UseDragMonitorOptions {\n /** Called on any drag start in the page. */\n onDragStart?: (data: DragData) => void\n /** Called on any drop in the page. */\n onDrop?: (sourceData: DragData, targetData: DragData) => void\n /** Filter which drags to monitor. */\n canMonitor?: (data: DragData) => boolean\n}\n\nexport interface UseDragMonitorResult {\n /** Whether any element is currently being dragged. */\n isDragging: () => boolean\n /** Data of the currently dragging element (null if not dragging). */\n dragData: () => DragData | null\n}\n\n/**\n * Monitor all drag operations on the page.\n * Useful for global drag indicators, analytics, or coordination between\n * multiple drag-and-drop areas.\n *\n * @example\n * ```tsx\n * const { isDragging, dragData } = useDragMonitor({\n * canMonitor: (data) => data.type === \"card\",\n * onDrop: (source, target) => logDrop(source, target),\n * })\n *\n * <Show when={isDragging()}>\n * <div class=\"global-drag-overlay\">\n * Dragging: {() => dragData()?.name}\n * </div>\n * </Show>\n * ```\n */\nexport function useDragMonitor(options?: UseDragMonitorOptions): UseDragMonitorResult {\n if (typeof document === 'undefined') return { isDragging: () => false, dragData: () => null }\n\n const isDragging = signal(false)\n const dragData = signal<DragData | null>(null)\n\n const canMonitorFn = options?.canMonitor\n ? ({ source }: { source: { data: Record<string, unknown> } }) =>\n options.canMonitor?.(source.data as DragData) ?? true\n : null\n\n const cleanup = monitorForElements({\n ...(canMonitorFn ? { canMonitor: canMonitorFn } : {}),\n onDragStart: ({ source }) => {\n isDragging.set(true)\n dragData.set(source.data as DragData)\n options?.onDragStart?.(source.data as DragData)\n },\n onDrop: ({ source, location }) => {\n isDragging.set(false)\n dragData.set(null)\n const targetData = location.current.dropTargets[0]?.data ?? {}\n options?.onDrop?.(source.data as DragData, targetData as DragData)\n },\n })\n\n onCleanup(cleanup)\n\n return { isDragging, dragData }\n}\n","import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter'\nimport { onCleanup, signal } from '@pyreon/reactivity'\nimport type { DragData, UseDraggableOptions, UseDraggableResult } from './types'\n\n/**\n * Make an element draggable with signal-driven state.\n *\n * @example\n * ```tsx\n * let cardEl: HTMLElement | null = null\n *\n * const { isDragging } = useDraggable({\n * element: () => cardEl,\n * data: { id: card.id, type: \"card\" },\n * })\n *\n * <div ref={(el) => cardEl = el} class={isDragging() ? \"opacity-50\" : \"\"}>\n * {card.title}\n * </div>\n * ```\n */\nexport function useDraggable<T extends DragData = DragData>(\n options: UseDraggableOptions<T>,\n): UseDraggableResult {\n if (typeof document === 'undefined') return { isDragging: () => false }\n\n const isDragging = signal(false)\n let cleanup: (() => void) | undefined\n\n function setup() {\n if (cleanup) cleanup()\n\n const el = options.element()\n if (!el) return\n\n const resolveData = () =>\n typeof options.data === 'function' ? (options.data as () => T)() : options.data\n\n const handle = options.handle?.()\n cleanup = draggable({\n element: el,\n ...(handle ? { dragHandle: handle } : {}),\n getInitialData: resolveData,\n canDrag: () => {\n const disabled = options.disabled\n if (typeof disabled === 'function') return !disabled()\n return !disabled\n },\n onDragStart: () => {\n isDragging.set(true)\n options.onDragStart?.()\n },\n onDrop: () => {\n isDragging.set(false)\n options.onDragEnd?.()\n },\n })\n }\n\n // Defer setup to next microtask so refs are populated\n queueMicrotask(setup)\n\n onCleanup(() => {\n if (cleanup) cleanup()\n })\n\n return { isDragging }\n}\n","import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter'\nimport { onCleanup, signal } from '@pyreon/reactivity'\nimport type { DragData, UseDroppableOptions, UseDroppableResult } from './types'\n\n/**\n * Make an element a drop target with signal-driven state.\n *\n * @example\n * ```tsx\n * let zoneEl: HTMLElement | null = null\n *\n * const { isOver } = useDroppable({\n * element: () => zoneEl,\n * onDrop: (data) => handleDrop(data),\n * canDrop: (data) => data.type === \"card\",\n * })\n *\n * <div ref={(el) => zoneEl = el} class={isOver() ? \"bg-blue-50\" : \"\"}>\n * Drop here\n * </div>\n * ```\n */\nexport function useDroppable<T extends DragData = DragData>(\n options: UseDroppableOptions<T>,\n): UseDroppableResult {\n if (typeof document === 'undefined') return { isOver: () => false }\n\n const isOver = signal(false)\n let cleanup: (() => void) | undefined\n\n function setup() {\n if (cleanup) cleanup()\n\n const el = options.element()\n if (!el) return\n\n cleanup = dropTargetForElements({\n element: el,\n getData: () => {\n if (!options.data) return {}\n return typeof options.data === 'function' ? (options.data as () => T)() : options.data\n },\n canDrop: ({ source }) => {\n if (!options.canDrop) return true\n return options.canDrop(source.data as DragData)\n },\n onDragEnter: ({ source }) => {\n isOver.set(true)\n options.onDragEnter?.(source.data as DragData)\n },\n onDragLeave: () => {\n isOver.set(false)\n options.onDragLeave?.()\n },\n onDrop: ({ source }) => {\n isOver.set(false)\n options.onDrop?.(source.data as DragData)\n },\n })\n }\n\n queueMicrotask(setup)\n\n onCleanup(() => {\n if (cleanup) cleanup()\n })\n\n return { isOver }\n}\n","import {\n dropTargetForExternal,\n monitorForExternal,\n} from '@atlaskit/pragmatic-drag-and-drop/external/adapter'\nimport { containsFiles, getFiles } from '@atlaskit/pragmatic-drag-and-drop/external/file'\nimport { onCleanup, signal } from '@pyreon/reactivity'\n\nexport interface UseFileDropOptions {\n /** Element getter for the drop zone. */\n element: () => HTMLElement | null\n /** Called when files are dropped. */\n onDrop: (files: File[]) => void\n /** Filter accepted file types (e.g. [\"image/*\", \".pdf\"]). */\n accept?: string[]\n /** Maximum number of files. */\n maxFiles?: number\n /** Whether drop is disabled. */\n disabled?: boolean | (() => boolean)\n}\n\nexport interface UseFileDropResult {\n /** Whether files are being dragged over the drop zone. */\n isOver: () => boolean\n /** Whether files are being dragged anywhere on the page. */\n isDraggingFiles: () => boolean\n}\n\n/**\n * File drop zone with signal-driven state.\n * Uses the native file drag events via pragmatic-drag-and-drop.\n *\n * @example\n * ```tsx\n * let dropZone: HTMLElement | null = null\n *\n * const { isOver, isDraggingFiles } = useFileDrop({\n * element: () => dropZone,\n * accept: [\"image/*\", \".pdf\"],\n * maxFiles: 5,\n * onDrop: (files) => upload(files),\n * })\n *\n * <div\n * ref={(el) => dropZone = el}\n * class={isOver() ? \"drop-active\" : isDraggingFiles() ? \"drop-ready\" : \"\"}\n * >\n * Drop files here\n * </div>\n * ```\n */\nexport function useFileDrop(options: UseFileDropOptions): UseFileDropResult {\n if (typeof document === 'undefined') return { isOver: () => false, isDraggingFiles: () => false }\n\n const isOver = signal(false)\n const isDraggingFiles = signal(false)\n let cleanup: (() => void) | undefined\n\n function matchesAccept(file: File, accept: string[]): boolean {\n return accept.some((pattern) => {\n if (pattern.startsWith('.')) {\n return file.name.toLowerCase().endsWith(pattern.toLowerCase())\n }\n if (pattern.endsWith('/*')) {\n return file.type.startsWith(pattern.slice(0, -1))\n }\n return file.type === pattern\n })\n }\n\n function setup() {\n if (cleanup) cleanup()\n\n const el = options.element()\n if (!el) return\n\n const cleanups: (() => void)[] = []\n\n // Monitor for file drags anywhere on the page\n cleanups.push(\n monitorForExternal({\n canMonitor: ({ source }) => containsFiles({ source }),\n onDragStart: () => isDraggingFiles.set(true),\n onDrop: () => isDraggingFiles.set(false),\n }),\n )\n\n // Drop target on the specific element\n cleanups.push(\n dropTargetForExternal({\n element: el,\n canDrop: ({ source }) => {\n const disabled = options.disabled\n if (typeof disabled === 'function' ? disabled() : disabled) return false\n return containsFiles({ source })\n },\n onDragEnter: () => isOver.set(true),\n onDragLeave: () => isOver.set(false),\n onDrop: ({ source }) => {\n isOver.set(false)\n isDraggingFiles.set(false)\n\n let files = getFiles({ source })\n\n // Filter by accept\n if (options.accept && options.accept.length > 0) {\n files = files.filter((f) => matchesAccept(f, options.accept as string[]))\n }\n\n // Limit count\n if (options.maxFiles && files.length > options.maxFiles) {\n files = files.slice(0, options.maxFiles)\n }\n\n if (files.length > 0) {\n options.onDrop(files)\n }\n },\n }),\n )\n\n cleanup = () => {\n for (const fn of cleanups) fn()\n }\n }\n\n queueMicrotask(setup)\n\n onCleanup(() => {\n if (cleanup) cleanup()\n })\n\n return { isOver, isDraggingFiles }\n}\n","import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine'\nimport { draggable, dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter'\nimport { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element'\nimport {\n attachClosestEdge,\n type Edge,\n extractClosestEdge,\n} from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge'\nimport { onCleanup, signal } from '@pyreon/reactivity'\nimport type { DropEdge, UseSortableOptions, UseSortableResult } from './types'\n\nconst SORT_KEY = '__pyreon_sortable_key'\nconst SORT_ID = '__pyreon_sortable_id'\n\nlet _sortableCounter = 0\n\n/**\n * Sortable list with signal-driven state, auto-scroll, and edge detection.\n *\n * Features:\n * - Keyed drag items matching `<For by={...}>` pattern\n * - Auto-scroll when dragging near container edges\n * - Closest-edge detection (drop above/below or left/right)\n * - Axis constraint (vertical/horizontal)\n * - Keyboard reordering (Alt+Arrow keys)\n *\n * @example\n * ```tsx\n * const items = signal([\n * { id: \"1\", name: \"Alice\" },\n * { id: \"2\", name: \"Bob\" },\n * { id: \"3\", name: \"Charlie\" },\n * ])\n *\n * const { containerRef, itemRef, activeId, overId, overEdge } = useSortable({\n * items,\n * by: (item) => item.id,\n * onReorder: (newItems) => items.set(newItems),\n * })\n *\n * <ul ref={containerRef}>\n * <For each={items()} by={item => item.id}>\n * {(item) => (\n * <li\n * ref={itemRef(item.id)}\n * class={activeId() === item.id ? \"dragging\" : \"\"}\n * style={overId() === item.id ? `border-${overEdge()}: 2px solid blue` : \"\"}\n * >\n * {item.name}\n * </li>\n * )}\n * </For>\n * </ul>\n * ```\n */\nexport function useSortable<T>(options: UseSortableOptions<T>): UseSortableResult {\n if (typeof document === 'undefined') {\n const noop = () => {}\n return {\n containerRef: noop as (el: HTMLElement) => void,\n itemRef: () => noop as (el: HTMLElement) => void,\n activeId: () => null,\n overId: () => null,\n overEdge: () => null,\n }\n }\n\n const sortableId = `sortable-${++_sortableCounter}`\n const activeId = signal<string | number | null>(null)\n const overId = signal<string | number | null>(null)\n const overEdge = signal<DropEdge | null>(null)\n const axis = options.axis ?? 'vertical'\n\n const cleanups: (() => void)[] = []\n\n /** Perform the reorder based on current active/over/edge state. */\n function performReorder() {\n const dragId = activeId.peek()\n const dropId = overId.peek()\n const edge = overEdge.peek()\n if (dragId == null || dropId == null || dragId === dropId) return\n\n const currentItems = options.items()\n const dragIndex = currentItems.findIndex((item) => options.by(item) === dragId)\n const dropIndex = currentItems.findIndex((item) => options.by(item) === dropId)\n if (dragIndex === -1 || dropIndex === -1) return\n\n const reordered = [...currentItems]\n const [moved] = reordered.splice(dragIndex, 1)\n if (!moved) return\n\n // Determine insert position based on closest edge\n const rawInsert =\n edge === 'bottom' || edge === 'right'\n ? dropIndex >= dragIndex\n ? dropIndex\n : dropIndex + 1\n : dropIndex <= dragIndex\n ? dropIndex\n : dropIndex - 1\n const insertAt = Math.max(0, Math.min(rawInsert, reordered.length))\n\n reordered.splice(insertAt, 0, moved)\n options.onReorder(reordered)\n }\n\n function containerRef(el: HTMLElement) {\n // Auto-scroll when dragging near container edges\n cleanups.push(\n autoScrollForElements({\n element: el,\n canScroll: ({ source }) => source.data[SORT_ID] === sortableId,\n }),\n )\n\n // Container is a drop target for reorder finalization\n cleanups.push(\n dropTargetForElements({\n element: el,\n getData: () => ({ [SORT_ID]: sortableId }),\n canDrop: ({ source }) => source.data[SORT_ID] === sortableId,\n onDrop: () => {\n performReorder()\n activeId.set(null)\n overId.set(null)\n overEdge.set(null)\n },\n }),\n )\n\n // Keyboard reordering: Alt+Arrow keys\n const keyHandler = (e: KeyboardEvent) => {\n if (!e.altKey) return\n\n const isUp = axis === 'vertical' ? e.key === 'ArrowUp' : e.key === 'ArrowLeft'\n const isDown = axis === 'vertical' ? e.key === 'ArrowDown' : e.key === 'ArrowRight'\n if (!isUp && !isDown) return\n\n const focused = document.activeElement as HTMLElement | null\n if (!focused || !el.contains(focused)) return\n\n const focusedKey = focused.dataset.pyreonSortKey\n if (!focusedKey) return\n\n e.preventDefault()\n\n const currentItems = options.items()\n const currentIndex = currentItems.findIndex((item) => String(options.by(item)) === focusedKey)\n if (currentIndex === -1) return\n\n const targetIndex = isUp ? currentIndex - 1 : currentIndex + 1\n if (targetIndex < 0 || targetIndex >= currentItems.length) return\n\n const reordered = [...currentItems]\n const temp = reordered[currentIndex]\n reordered[currentIndex] = reordered[targetIndex] as T\n reordered[targetIndex] = temp as T\n options.onReorder(reordered)\n\n // Restore focus after DOM update\n requestAnimationFrame(() => {\n const items = el.querySelectorAll('[data-pyreon-sort-key]')\n for (const item of items) {\n if ((item as HTMLElement).dataset.pyreonSortKey === focusedKey) {\n ;(item as HTMLElement).focus()\n break\n }\n }\n })\n }\n\n el.addEventListener('keydown', keyHandler)\n cleanups.push(() => el.removeEventListener('keydown', keyHandler))\n }\n\n function itemRef(key: string | number): (el: HTMLElement) => void {\n return (el: HTMLElement) => {\n el.dataset.pyreonSortKey = String(key)\n if (!el.hasAttribute('tabindex')) el.setAttribute('tabindex', '0')\n el.setAttribute('role', 'listitem')\n el.setAttribute('aria-roledescription', 'sortable item')\n\n const allowedEdges: Edge[] = axis === 'vertical' ? ['top', 'bottom'] : ['left', 'right']\n\n const cleanup = combine(\n draggable({\n element: el,\n getInitialData: () => ({\n [SORT_KEY]: key,\n [SORT_ID]: sortableId,\n }),\n onDragStart: () => activeId.set(key),\n onDrop: () => {\n queueMicrotask(() => {\n activeId.set(null)\n overId.set(null)\n overEdge.set(null)\n })\n },\n }),\n dropTargetForElements({\n element: el,\n getData: ({ input, element }) =>\n attachClosestEdge(\n { [SORT_KEY]: key, [SORT_ID]: sortableId },\n { input, element, allowedEdges },\n ),\n canDrop: ({ source }) => source.data[SORT_ID] === sortableId,\n onDragEnter: ({ self }) => {\n overId.set(key)\n overEdge.set(extractClosestEdge(self.data) as DropEdge | null)\n },\n onDrag: ({ self }) => {\n overEdge.set(extractClosestEdge(self.data) as DropEdge | null)\n },\n onDragLeave: () => {\n if (overId.peek() === key) {\n overId.set(null)\n overEdge.set(null)\n }\n },\n }),\n )\n\n cleanups.push(cleanup)\n }\n }\n\n onCleanup(() => {\n for (const cleanup of cleanups) cleanup()\n cleanups.length = 0\n activeId.set(null)\n overId.set(null)\n overEdge.set(null)\n })\n\n return { containerRef, itemRef, activeId, overId, overEdge }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,eAAe,SAAuD;AACpF,KAAI,OAAO,aAAa,YAAa,QAAO;EAAE,kBAAkB;EAAO,gBAAgB;EAAM;CAE7F,MAAM,aAAa,OAAO,M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AS;EAAU;EAAQ;EAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pyreon/dnd",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.10",
|
|
4
4
|
"description": "Signal-driven drag and drop for Pyreon — wraps @atlaskit/pragmatic-drag-and-drop",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/pyreon/pyreon/issues"
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@pyreon/typescript": "^0.12.
|
|
45
|
+
"@pyreon/typescript": "^0.12.10"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@pyreon/core": "^0.12.
|
|
49
|
-
"@pyreon/reactivity": "^0.12.
|
|
48
|
+
"@pyreon/core": "^0.12.10",
|
|
49
|
+
"@pyreon/reactivity": "^0.12.10"
|
|
50
50
|
}
|
|
51
51
|
}
|
package/src/tests/dnd.test.ts
CHANGED
|
@@ -659,6 +659,63 @@ describe('useDragMonitor canMonitor filter', () => {
|
|
|
659
659
|
})
|
|
660
660
|
})
|
|
661
661
|
|
|
662
|
+
// ─── SSR safety ────────────────────────────────────────────────────────────
|
|
663
|
+
|
|
664
|
+
describe('SSR safety — all hooks return inert results without document', () => {
|
|
665
|
+
let originalDocument: typeof globalThis.document
|
|
666
|
+
|
|
667
|
+
beforeEach(() => {
|
|
668
|
+
originalDocument = globalThis.document
|
|
669
|
+
// @ts-expect-error — simulate SSR by removing document
|
|
670
|
+
delete globalThis.document
|
|
671
|
+
})
|
|
672
|
+
|
|
673
|
+
afterEach(() => {
|
|
674
|
+
globalThis.document = originalDocument
|
|
675
|
+
})
|
|
676
|
+
|
|
677
|
+
it('useDraggable returns inert isDragging', async () => {
|
|
678
|
+
const { useDraggable } = await import('../use-draggable')
|
|
679
|
+
const result = useDraggable({ element: () => null, data: { id: '1' } })
|
|
680
|
+
expect(result.isDragging()).toBe(false)
|
|
681
|
+
})
|
|
682
|
+
|
|
683
|
+
it('useDroppable returns inert isOver', async () => {
|
|
684
|
+
const { useDroppable } = await import('../use-droppable')
|
|
685
|
+
const result = useDroppable({ element: () => null, onDrop: () => {} })
|
|
686
|
+
expect(result.isOver()).toBe(false)
|
|
687
|
+
})
|
|
688
|
+
|
|
689
|
+
it('useSortable returns full inert API', async () => {
|
|
690
|
+
const { useSortable } = await import('../use-sortable')
|
|
691
|
+
const result = useSortable({
|
|
692
|
+
items: () => [{ id: '1' }],
|
|
693
|
+
by: (item: { id: string }) => item.id,
|
|
694
|
+
onReorder: () => {},
|
|
695
|
+
})
|
|
696
|
+
expect(result.activeId()).toBeNull()
|
|
697
|
+
expect(result.overId()).toBeNull()
|
|
698
|
+
expect(result.overEdge()).toBeNull()
|
|
699
|
+
expect(typeof result.containerRef).toBe('function')
|
|
700
|
+
expect(typeof result.itemRef).toBe('function')
|
|
701
|
+
expect(typeof result.itemRef('1')).toBe('function')
|
|
702
|
+
})
|
|
703
|
+
|
|
704
|
+
it('useFileDrop returns inert signals', async () => {
|
|
705
|
+
const { useFileDrop } = await import('../use-file-drop')
|
|
706
|
+
const result = useFileDrop({ element: () => null, onDrop: () => {} })
|
|
707
|
+
expect(result.isOver()).toBe(false)
|
|
708
|
+
expect(result.isDraggingFiles()).toBe(false)
|
|
709
|
+
})
|
|
710
|
+
|
|
711
|
+
it('useDragMonitor returns inert signals', async () => {
|
|
712
|
+
const { useDragMonitor } = await import('../use-drag-monitor')
|
|
713
|
+
const result = useDragMonitor()
|
|
714
|
+
expect(result.isDragging()).toBe(false)
|
|
715
|
+
expect(result.dragData()).toBeNull()
|
|
716
|
+
})
|
|
717
|
+
})
|
|
718
|
+
|
|
662
719
|
// ─── Module exports ─────────────────────────────────────────────────────────
|
|
663
720
|
|
|
664
721
|
describe('module exports', () => {
|