@pyreon/dnd 0.50.0 → 0.52.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 +32 -22
- package/lib/index.js +297 -134
- package/lib/index.js.map +1 -1
- package/lib/types/index.d.ts +88 -41
- package/native/kotlin/com/pyreon/runtime/PyreonSortable.kt +198 -0
- package/native/kotlin/com/pyreon/runtime/PyreonSortableModifier.kt +59 -0
- package/native/swift/PyreonSortable.swift +256 -0
- package/package.json +33 -16
- package/lib/analysis/index.js.html +0 -5406
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["__pkgName","__pkgVersion"],"sources":["../package.json","../src/use-drag-monitor.ts","../src/use-draggable.ts","../src/use-droppable.ts","../src/use-file-drop.ts","../src/use-sortable.ts","../src/index.ts"],"sourcesContent":["","import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter'\nimport { batch, isServer, 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 (isServer) return { isDragging: () => false, dragData: () => null }\n\n const isDragging = signal(false)\n const dragData = signal<DragData | null>(null)\n\n /* v8 ignore next 4 — opt-in canMonitor predicate; both arms structurally exercised but counted as one */\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 // batch() so subscribers to isDragging + dragData get notified once,\n // not twice. Drag events fire frequently; doubling subscriber work\n // per event compounds visibly on UIs with many drag-monitor consumers.\n batch(() => {\n isDragging.set(true)\n dragData.set(source.data as DragData)\n })\n options?.onDragStart?.(source.data as DragData)\n },\n onDrop: ({ source, location }) => {\n batch(() => {\n isDragging.set(false)\n dragData.set(null)\n })\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 { centerUnderPointer } from '@atlaskit/pragmatic-drag-and-drop/element/center-under-pointer'\nimport { pointerOutsideOfPreview } from '@atlaskit/pragmatic-drag-and-drop/element/pointer-outside-of-preview'\nimport { preserveOffsetOnSource } from '@atlaskit/pragmatic-drag-and-drop/element/preserve-offset-on-source'\nimport { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview'\nimport { isServer, onCleanup, signal } from '@pyreon/reactivity'\nimport type { DragData, DragPreviewOptions, UseDraggableOptions, UseDraggableResult } from './types'\n\n/**\n * Resolve a preview `offset` preset to pdnd's `GetOffsetFn`. Split out so\n * the ternary chain is directly unit-testable; `undefined` keeps the\n * browser default (top-left of the preview under the pointer).\n */\nfunction resolvePreviewOffset(\n offset: DragPreviewOptions['offset'],\n source: { element: HTMLElement },\n input: Parameters<typeof preserveOffsetOnSource>[0]['input'],\n): ReturnType<typeof pointerOutsideOfPreview> | undefined {\n if (offset === 'pointer-outside') return pointerOutsideOfPreview({ x: '16px', y: '8px' })\n if (offset === 'center') return centerUnderPointer\n if (offset === 'preserve-offset') {\n return preserveOffsetOnSource({ element: source.element, input })\n }\n return undefined\n}\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 (isServer) return { isDragging: () => false }\n\n const isDragging = signal(false)\n let cleanup: (() => void) | undefined\n let disposed = false\n\n function setup() {\n // The hook may have unmounted before this deferred (queueMicrotask) setup\n // ran. onCleanup fired with `cleanup` still undefined (a no-op), so a\n // registration created here would never be torn down — bail instead.\n /* v8 ignore next — defensive disposed-during-setup guard; tested implicitly via lifecycle */\n if (disposed) return\n // Defensive re-setup teardown: `setup` is scheduled exactly once\n // (`queueMicrotask(setup)`) and never re-invoked, so `cleanup` is always\n // undefined here — this branch never fires in the current single-shot\n // design. Kept so a future re-setup trigger (element-change re-registration)\n // can't leak a double registration.\n /* v8 ignore next — defensive re-setup teardown; unreachable with single-shot queueMicrotask */\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 const preview = options.preview\n cleanup = draggable({\n element: el,\n ...(handle ? { dragHandle: handle } : {}),\n // Custom native drag preview — thin pass-through to pdnd's\n // setCustomNativeDragPreview + offset presets. Only wired when the\n // consumer opts in, so the default path is byte-identical.\n ...(preview\n ? {\n onGenerateDragPreview: ({\n nativeSetDragImage,\n source,\n location,\n }: {\n nativeSetDragImage: Parameters<\n typeof setCustomNativeDragPreview\n >[0]['nativeSetDragImage']\n source: { element: HTMLElement }\n location: {\n initial: { input: Parameters<typeof preserveOffsetOnSource>[0]['input'] }\n }\n }) => {\n const getOffset = resolvePreviewOffset(preview.offset, source, location.initial.input)\n setCustomNativeDragPreview({\n render: ({ container }) => preview.render(container),\n nativeSetDragImage,\n ...(getOffset ? { getOffset } : {}),\n })\n },\n }\n : {}),\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 disposed = true\n if (cleanup) cleanup()\n })\n\n return { isDragging }\n}\n","import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter'\nimport {\n attachClosestEdge,\n type Edge,\n extractClosestEdge,\n} from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge'\nimport { batch, isServer, onCleanup, signal } from '@pyreon/reactivity'\nimport type { DragData, DropEdge, 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, overEdge } = useDroppable({\n * element: () => zoneEl,\n * onDrop: (data) => handleDrop(data),\n * canDrop: (data) => data.type === \"card\",\n * edges: [\"top\", \"bottom\"], // opt-in closest-edge detection\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 (isServer) return { isOver: () => false, overEdge: () => null }\n\n const isOver = signal(false)\n const overEdge = signal<DropEdge | null>(null)\n let cleanup: (() => void) | undefined\n let disposed = false\n\n function setup() {\n // Unmounted before this deferred setup ran — don't register a target that\n // onCleanup (already fired with `cleanup` undefined) can never tear down.\n /* v8 ignore next — defensive disposed-during-setup guard */\n if (disposed) return\n // Defensive re-setup teardown: `setup` runs exactly once\n // (`queueMicrotask(setup)`, never re-invoked), so `cleanup` is always\n // undefined here — this branch never fires in the current single-shot\n // design. Kept so a future re-setup trigger can't leak a double target.\n /* v8 ignore next — defensive re-setup teardown; unreachable with single-shot queueMicrotask */\n if (cleanup) cleanup()\n\n const el = options.element()\n if (!el) return\n\n const edges = options.edges\n\n const resolveData = (): DragData => {\n if (!options.data) return {}\n return typeof options.data === 'function' ? (options.data as () => T)() : options.data\n }\n\n cleanup = dropTargetForElements({\n element: el,\n getData: ({ input, element }) => {\n const data = resolveData()\n // Opt-in closest-edge detection — wraps the target data with\n // pdnd hitbox metadata so extractClosestEdge can read the live\n // edge on enter/drag.\n if (edges && edges.length > 0) {\n return attachClosestEdge(data, { input, element, allowedEdges: edges as Edge[] })\n }\n return data\n },\n // pdnd stickiness — keep \"held\" drop-target status while the\n // pointer crosses gaps between targets. Pass-through of getIsSticky.\n ...(options.sticky ? { getIsSticky: () => true } : {}),\n canDrop: ({ source }) => {\n if (!options.canDrop) return true\n return options.canDrop(source.data as DragData)\n },\n onDragEnter: ({ source, self }) => {\n // batch — isOver + overEdge settle in ONE notify pass for\n // subscribers reading both (matches useSortable's batching).\n batch(() => {\n isOver.set(true)\n if (edges) overEdge.set(extractClosestEdge(self.data) as DropEdge | null)\n })\n options.onDragEnter?.(source.data as DragData)\n },\n // Live edge tracking while the pointer moves over the target —\n // only meaningful (and only wired) when edges are configured.\n ...(edges && edges.length > 0\n ? {\n onDrag: ({ self }: { self: { data: Record<string | symbol, unknown> } }) => {\n overEdge.set(extractClosestEdge(self.data) as DropEdge | null)\n },\n }\n : {}),\n onDragLeave: () => {\n batch(() => {\n isOver.set(false)\n overEdge.set(null)\n })\n options.onDragLeave?.()\n },\n onDrop: ({ source }) => {\n batch(() => {\n isOver.set(false)\n overEdge.set(null)\n })\n options.onDrop?.(source.data as DragData)\n },\n })\n }\n\n queueMicrotask(setup)\n\n onCleanup(() => {\n disposed = true\n if (cleanup) cleanup()\n })\n\n return { isOver, overEdge }\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 { batch, isServer, 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 (isServer) return { isOver: () => false, isDraggingFiles: () => false }\n\n const isOver = signal(false)\n const isDraggingFiles = signal(false)\n let cleanup: (() => void) | undefined\n let disposed = false\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 // Unmounted before this deferred setup ran — don't register a drop target\n // that onCleanup (already fired with `cleanup` undefined) can never remove.\n /* v8 ignore next — defensive disposed-during-setup guard */\n if (disposed) return\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 // batch() so onDrop subscribers don't get notified twice\n // (isOver + isDraggingFiles) per file-drop event.\n batch(() => {\n isOver.set(false)\n isDraggingFiles.set(false)\n })\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 disposed = true\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 { announce } from '@pyreon/a11y'\nimport { batch, createSelector, isServer, 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'\nconst SORT_GROUP = '__pyreon_sortable_group'\nconst SORT_PAYLOAD = '__pyreon_sortable_payload'\n\n// Same sr-only recipe as @pyreon/a11y's live regions — inline (not a CSS\n// class) so the instructions node needs zero stylesheet wiring.\nconst SR_ONLY =\n 'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0'\n\nlet _sortableCounter = 0\n\n// Module-level registry of live sortable instances — used to dispatch\n// cross-list drop notifications from the destination back to the source\n// (W18). Keyed by sortableId.\nconst _sortableRegistry = new Map<\n string,\n {\n groupId: string | undefined\n onCrossListDrop: ((item: unknown) => void) | undefined\n }\n>()\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 * - Optional cross-list `groupId` for Trello/Notion/Linear board layouts\n * (W18) — share the same `groupId` between two\n * sortable instances and items can be dragged between them. The\n * source's `onCrossListDrop(item)` removes; the destination's\n * `onCrossListReceive(item, index)` inserts.\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, isActive, isOverKey, overEdge } = useSortable({\n * items,\n * by: (item) => item.id,\n * onReorder: (newItems) => items.set(newItems),\n * label: (item) => item.name, // screen-reader announcements\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={isActive(item.id) ? \"dragging\" : \"\"}\n * style={isOverKey(item.id) ? `border-${overEdge()}: 2px solid blue` : \"\"}\n * >\n * {item.name}\n * </li>\n * )}\n * </For>\n * </ul>\n * ```\n *\n * Prefer `isActive(key)` / `isOverKey(key)` over `activeId() === key` /\n * `overId() === key` in row templates — the equality read subscribes EVERY\n * row to the id signal (O(N) notifies per change); the selectors notify\n * only the two affected rows (O(2), `createSelector` semantics).\n */\nexport function useSortable<T>(options: UseSortableOptions<T>): UseSortableResult {\n if (isServer) {\n const noop = (_el: HTMLElement | null) => {}\n return {\n containerRef: noop,\n itemRef: () => noop,\n itemHandleRef: () => noop,\n activeId: () => null,\n overId: () => null,\n overEdge: () => null,\n isActive: () => false,\n isOverKey: () => false,\n }\n }\n\n const sortableId = `sortable-${++_sortableCounter}`\n const instructionsId = `${sortableId}-instructions`\n const activeId = signal<string | number | null>(null)\n const overId = signal<string | number | null>(null)\n const overEdge = signal<DropEdge | null>(null)\n // createSelector-backed per-key predicates (the krausest select-row\n // pattern): `activeId() === key` in a row template subscribes EVERY row\n // to activeId (O(N) notifies per change); the selector notifies only\n // the two affected keys (deselected + newly selected) — O(2).\n const isActiveSelector = createSelector<string | number | null>(activeId)\n const isOverSelector = createSelector<string | number | null>(overId)\n const axis = options.axis ?? 'vertical'\n const groupId = options.groupId\n\n /** Resolve the announcement label for an item: `label(item)` else the key. */\n function labelOf(item: T | undefined, key: string | number): string {\n if (item !== undefined && options.label) return options.label(item)\n return String(key)\n }\n\n /** Resolve the announcement label for a key by looking the item up. */\n function labelFor(key: string | number): string {\n const item = options.items().find((i) => options.by(i) === key)\n return labelOf(item, key)\n }\n\n // Register so siblings in the same group can call our onCrossListDrop\n // when they receive one of our items.\n _sortableRegistry.set(sortableId, {\n groupId,\n onCrossListDrop: options.onCrossListDrop as ((item: unknown) => void) | undefined,\n })\n\n // Container-level pdnd teardown (auto-scroll + reorder drop-target + the\n // keydown listener). A SINGLE disposer, replaced on re-register and cleared\n // on unmount — symmetric with the per-item map below. A collapsible board\n // whose `<ul ref={containerRef}>` sits behind a `<Show>` (with the hook in\n // the parent) re-fires `containerRef` on every toggle; without disposal each\n // toggle leaked the auto-scroll + drop-target + keydown listener on the now-\n // detached element (the container sibling of the F3 per-item leak).\n let containerCleanup: (() => void) | undefined\n // Per-item pdnd cleanups, keyed by sort key. Disposed individually on\n // item unmount / re-register so a churning list doesn't accumulate\n // dead registrations for the sortable's whole lifetime.\n const itemCleanups = new Map<string | number, () => 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 /* v8 ignore next — defensive null/equal id guards */\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 /* v8 ignore next — defensive findIndex-not-found guards; ids come from active drag */\n if (dragIndex === -1 || dropIndex === -1) return\n\n const reordered = [...currentItems]\n const [moved] = reordered.splice(dragIndex, 1)\n /* v8 ignore next — defensive splice fallback; dragIndex was just verified */\n if (!moved) return\n\n // Determine insert position based on closest edge\n /* v8 ignore next 7 — ternary combinatorics; structurally exercised in browser e2e but not unit-coverable per arm */\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 // Screen-reader announcement — position is 1-based for humans.\n announce(`Dropped ${labelOf(moved, dragId)} at position ${insertAt + 1} of ${reordered.length}`)\n }\n\n /** Announce a cross-list receive on THIS (destination) sortable. */\n function announceCrossListReceive(item: T, insertAt: number) {\n // `items()` reflects the post-insert length when the consumer commits\n // synchronously inside onCrossListReceive (the documented shape); the\n // max() keeps the count honest if the commit is deferred.\n const count = Math.max(options.items().length, insertAt + 1)\n const key = options.by(item)\n announce(\n `Dropped ${labelOf(item, key)} at position ${insertAt + 1} of ${count} in the receiving list`,\n )\n }\n\n /** Returns true when `source` belongs to this sortable or to a sibling\n * in the same `groupId`. */\n function acceptsSource(source: { data: Record<string, unknown> }): boolean {\n if (source.data[SORT_ID] === sortableId) return true\n if (groupId && source.data[SORT_GROUP] === groupId) return true\n return false\n }\n\n function containerRef(el: HTMLElement | null) {\n // Dispose the prior container registration on BOTH unmount (el === null,\n // fired by Pyreon's runtime) AND re-register (a new container element) so\n // a toggled/re-mounted container can't leak its auto-scroll + drop-target +\n // keydown listener. Symmetric with the per-item disposal below (F3).\n if (containerCleanup) {\n containerCleanup()\n containerCleanup = undefined\n }\n if (!el) return\n\n const containerCleanups: (() => void)[] = []\n\n // Visually-hidden keyboard instructions, referenced by every item via\n // aria-describedby (the dnd-kit pattern — screen-reader users land on\n // an item and hear how to reorder it). Created once per container\n // mount, removed with the container registration.\n const instructions = document.createElement('div')\n instructions.id = instructionsId\n instructions.setAttribute('data-pyreon-sortable-instructions', '')\n instructions.style.cssText = SR_ONLY\n instructions.textContent = 'Press Alt plus arrow keys to reorder'\n el.appendChild(instructions)\n containerCleanups.push(() => instructions.remove())\n\n // Auto-scroll when dragging near container edges\n containerCleanups.push(\n autoScrollForElements({\n element: el,\n canScroll: ({ source }) => acceptsSource(source),\n }),\n )\n\n // Container is a drop target for reorder finalization OR for\n // appending a cross-list item at the end of this column.\n containerCleanups.push(\n dropTargetForElements({\n element: el,\n getData: () => ({ [SORT_ID]: sortableId, [SORT_GROUP]: groupId }),\n canDrop: ({ source }) => acceptsSource(source),\n onDrop: ({ source }) => {\n // Item-level dropTarget for cross-list drops marks the source\n // data as handled — container skips so we don't insert twice.\n const handled = (source.data as Record<string, unknown>).__pyreon_sortable_handled\n if (source.data[SORT_ID] === sortableId) {\n // Same-list drop on container edge → reorder finalization.\n performReorder()\n } else if (\n !handled &&\n groupId &&\n source.data[SORT_GROUP] === groupId &&\n options.onCrossListReceive\n ) {\n // Cross-list drop on the container itself (not on an item) →\n // append to the end of this column.\n const item = source.data[SORT_PAYLOAD] as T\n const sourceSortableId = source.data[SORT_ID] as string\n const targetIndex = options.items().length\n options.onCrossListReceive(item, targetIndex)\n const sourceInstance = _sortableRegistry.get(sourceSortableId)\n sourceInstance?.onCrossListDrop?.(item)\n announceCrossListReceive(item, targetIndex)\n }\n // batch() the 3-signal reset so subscribers reading any of\n // activeId/overId/overEdge get notified once per drop, not\n // three times. Fires on every container-level drop.\n batch(() => {\n activeId.set(null)\n overId.set(null)\n overEdge.set(null)\n })\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 /* v8 ignore next — defensive findIndex guard; focusedKey is from active item */\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 // Screen-reader announcement for the keyboard path (1-based).\n announce(\n `Moved ${labelOf(temp, focusedKey)} to position ${targetIndex + 1} of ${currentItems.length}`,\n )\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 containerCleanups.push(() => el.removeEventListener('keydown', keyHandler))\n\n containerCleanup = () => {\n for (const fn of containerCleanups) fn()\n }\n }\n\n // Live item elements + registered drag handles, keyed by sort key.\n // `itemEls` lets the handle registrar re-register an already-mounted\n // item when its handle arrives (child refs fire AFTER the parent's,\n // so the handle is never available at itemRef time).\n const itemEls = new Map<string | number, HTMLElement>()\n const itemHandles = new Map<string | number, HTMLElement>()\n\n function itemRef(key: string | number): (el: HTMLElement | null) => void {\n return (el: HTMLElement | null) => {\n // Per-key disposal. The ref fires with the element on mount and\n // with `null` on unmount. The old code pushed every registration\n // onto the shared `cleanups[]` and made the null branch a pure\n // no-op — so for a `<For>`-rendered sortable (the documented usage:\n // todo list / kanban) every removed item's pdnd `draggable` /\n // `dropTargetForElements` registration (and its pointer/drag\n // listeners on the now-detached node) leaked until the WHOLE\n // sortable unmounted. Dispose the prior registration for this key\n // on BOTH unmount (el === null) and re-registration (same key,\n // new element) so the live set tracks live items, not all-ever.\n const prev = itemCleanups.get(key)\n if (prev) {\n prev()\n itemCleanups.delete(key)\n }\n if (!el) {\n itemEls.delete(key)\n return\n }\n itemEls.set(key, el)\n registerItem(key, el)\n }\n }\n\n /**\n * OPTIONAL drag-handle registrar mirroring `itemRef`. When a handle is\n * (un)registered for an already-mounted item, the item's pdnd\n * registration is torn down and re-created so `dragHandle` takes\n * effect — pdnd captures the handle at registration time.\n */\n function itemHandleRef(key: string | number): (el: HTMLElement | null) => void {\n return (el: HTMLElement | null) => {\n if (el) itemHandles.set(key, el)\n else itemHandles.delete(key)\n const itemEl = itemEls.get(key)\n if (!itemEl) return\n // itemEls and itemCleanups are set together (itemRef → registerItem),\n // so a live itemEl implies a live cleanup — dispose it before the\n // re-registration below replaces it.\n /* v8 ignore next — defensive optional call; a live itemEl implies a live cleanup */\n itemCleanups.get(key)?.()\n itemCleanups.delete(key)\n registerItem(key, itemEl)\n }\n }\n\n function registerItem(key: string | number, 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 // Link the container's visually-hidden keyboard instructions so a\n // screen-reader user focusing the item hears how to reorder it.\n // A consumer-supplied aria-describedby wins.\n if (!el.hasAttribute('aria-describedby')) {\n el.setAttribute('aria-describedby', instructionsId)\n }\n\n const allowedEdges: Edge[] = axis === 'vertical' ? ['top', 'bottom'] : ['left', 'right']\n const handle = itemHandles.get(key)\n\n const cleanup = combine(\n draggable({\n element: el,\n // Per-item drag handle (pdnd dragHandle) — drag initiation is\n // scoped to the registered handle element when one exists.\n ...(handle ? { dragHandle: handle } : {}),\n getInitialData: () => {\n const currentItems = options.items()\n const item = currentItems.find((i) => options.by(i) === key)\n return {\n [SORT_KEY]: key,\n [SORT_ID]: sortableId,\n [SORT_GROUP]: groupId,\n // Carry the actual item value when groupId is set so a\n // sibling sortable's onDrop can receive it without a\n // separate registry lookup. Plain reference (pdnd doesn't\n // serialize) — safe within a single document.\n [SORT_PAYLOAD]: groupId ? item : undefined,\n }\n },\n onDragStart: () => {\n activeId.set(key)\n announce(`Picked up ${labelFor(key)}`)\n },\n onDrop: () => {\n queueMicrotask(() => {\n // batch() — same 3-signal reset shape as the container\n // onDrop above. Per-item drops fire this branch.\n batch(() => {\n activeId.set(null)\n overId.set(null)\n overEdge.set(null)\n })\n })\n },\n }),\n dropTargetForElements({\n element: el,\n getData: ({ input, element }) =>\n attachClosestEdge(\n { [SORT_KEY]: key, [SORT_ID]: sortableId, [SORT_GROUP]: groupId },\n { input, element, allowedEdges },\n ),\n canDrop: ({ source }) => acceptsSource(source),\n onDragEnter: ({ self }) => {\n // batch — overId + overEdge settle in ONE notify pass (same\n // shape as every other multi-signal write in this hook).\n batch(() => {\n overId.set(key)\n overEdge.set(extractClosestEdge(self.data) as DropEdge | null)\n })\n },\n onDrag: ({ self }) => {\n overEdge.set(extractClosestEdge(self.data) as DropEdge | null)\n },\n onDragLeave: () => {\n if (overId.peek() === key) {\n batch(() => {\n overId.set(null)\n overEdge.set(null)\n })\n }\n },\n onDrop: ({ source, self }) => {\n // Same-list drops are handled by the container's onDrop via\n // performReorder. Item-level onDrop fires for cross-list\n // shapes — insert at THIS item's index, then propagate to\n // the source to remove.\n if (source.data[SORT_ID] === sortableId) return\n if (!groupId || source.data[SORT_GROUP] !== groupId || !options.onCrossListReceive) {\n return\n }\n const item = source.data[SORT_PAYLOAD] as T\n const edge = extractClosestEdge(self.data) as DropEdge | null\n const currentItems = options.items()\n const targetIndex = currentItems.findIndex((i) => options.by(i) === key)\n /* v8 ignore next — defensive findIndex guard */\n if (targetIndex === -1) return\n /* v8 ignore next 4 — ternary combinatorics */\n const insertAt =\n edge === 'bottom' || edge === 'right' ? targetIndex + 1 : Math.max(0, targetIndex)\n options.onCrossListReceive(item, insertAt)\n const sourceSortableId = source.data[SORT_ID] as string\n const sourceInstance = _sortableRegistry.get(sourceSortableId)\n sourceInstance?.onCrossListDrop?.(item)\n announceCrossListReceive(item, insertAt)\n // Mark so the container's onDrop (which also fires) skips\n // re-inserting at the end of the list.\n ;(source.data as Record<string, unknown>).__pyreon_sortable_handled = true\n },\n }),\n )\n\n itemCleanups.set(key, cleanup)\n }\n\n onCleanup(() => {\n // Drain the live container registration (idempotent — containerRef(null)\n // may already have cleared it) plus every per-item registration.\n if (containerCleanup) {\n containerCleanup()\n containerCleanup = undefined\n }\n for (const cleanup of itemCleanups.values()) cleanup()\n itemCleanups.clear()\n itemEls.clear()\n itemHandles.clear()\n _sortableRegistry.delete(sortableId)\n // Selectors own a source-tracking effect + per-key buckets — release\n // them with the sortable (keys are unbounded across list churn).\n isActiveSelector.dispose()\n isOverSelector.dispose()\n // batch() the final 3-signal reset so any subscriber that survives\n // the dispose order (unusual but possible — e.g. an external store\n // holding refs) sees one notify, not three.\n batch(() => {\n activeId.set(null)\n overId.set(null)\n overEdge.set(null)\n })\n })\n\n return {\n containerRef,\n itemRef,\n itemHandleRef,\n activeId,\n overId,\n overEdge,\n isActive: (key: string | number) => isActiveSelector(key),\n isOverKey: (key: string | number) => isOverSelector(key),\n }\n}\n","import { name as __pkgName, version as __pkgVersion } from '../package.json' with { type: 'json' }\nimport { registerSingleton } from '@pyreon/reactivity'\n\n// Singleton sentinel — fail-loud detection of duplicate @pyreon/dnd\n// instances in the same heap. See @pyreon/reactivity/singleton-sentinel for\n// full rationale. Hardcoded version is acceptable here — it's a diagnostic\n// aid, not a load-bearing identity check.\nregisterSingleton(__pkgName, __pkgVersion, import.meta.url)\n\nexport type {\n DragData,\n DragPreviewOptions,\n DropEdge,\n DropLocation,\n UseDraggableOptions,\n UseDraggableResult,\n UseDroppableOptions,\n UseDroppableResult,\n UseSortableOptions,\n UseSortableResult,\n} from './types'\n\nexport type { UseDragMonitorOptions, UseDragMonitorResult } from './use-drag-monitor'\nexport { useDragMonitor } from './use-drag-monitor'\n\nexport { useDraggable } from './use-draggable'\nexport { useDroppable } from './use-droppable'\nexport type { UseFileDropOptions, UseFileDropResult } from './use-file-drop'\nexport { useFileDrop } from './use-file-drop'\nexport { useSortable } from './use-sortable'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACuCA,SAAgB,eAAe,SAAuD;CACpF,IAAI,UAAU,OAAO;EAAE,kBAAkB;EAAO,gBAAgB;CAAK;CAErE,MAAM,aAAa,OAAO,KAAK;CAC/B,MAAM,WAAW,OAAwB,IAAI;;CAG7C,MAAM,eAAe,SAAS,cACzB,EAAE,aACD,QAAQ,aAAa,OAAO,IAAgB,KAAK,OACnD;CAwBJ,UAtBgB,mBAAmB;EACjC,GAAI,eAAe,EAAE,YAAY,aAAa,IAAI,CAAC;EACnD,cAAc,EAAE,aAAa;GAI3B,YAAY;IACV,WAAW,IAAI,IAAI;IACnB,SAAS,IAAI,OAAO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;EACA,WAAW,QAAyB,iBAAiB,GAAG;EACxD,YAAY,QAAyB,eAAe,GAAG;CACzD;AACF;;;;AC/gBA,kBAAkBA,MAAWC,SAAc,OAAO,KAAK,GAAG"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["__pkgName","__pkgVersion"],"sources":["../package.json","../src/use-drag-monitor.ts","../src/element-binding.ts","../src/use-draggable.ts","../src/use-droppable.ts","../src/use-file-drop.ts","../src/use-sortable.ts","../src/index.ts"],"sourcesContent":["","import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element-adapter'\nimport { batch, isServer, 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 (isServer) return { isDragging: () => false, dragData: () => null }\n\n const isDragging = signal(false)\n const dragData = signal<DragData | null>(null)\n\n /* v8 ignore next 4 — opt-in canMonitor predicate; both arms structurally exercised but counted as one */\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 // batch() so subscribers to isDragging + dragData get notified once,\n // not twice. Drag events fire frequently; doubling subscriber work\n // per event compounds visibly on UIs with many drag-monitor consumers.\n batch(() => {\n isDragging.set(true)\n dragData.set(source.data as DragData)\n })\n options?.onDragStart?.(source.data as DragData)\n },\n onDrop: ({ source, location }) => {\n batch(() => {\n isDragging.set(false)\n dragData.set(null)\n })\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 { effect, onCleanup, untrack } from '@pyreon/reactivity'\n\nexport interface ElementBinding {\n /** Ref callback: registers the element, moves the registration on a swap, disposes on `null`. */\n ref: (el: HTMLElement | null) => void\n}\n\n/**\n * Bind a pdnd registration to an element that may mount LATER or be SWAPPED.\n *\n * The hooks used to read `options.element()` exactly once, on a microtask\n * after the hook ran. An element that mounted after that (behind `<Show>`, a\n * lazy branch, a data-dependent render) was never registered, and a swapped\n * element kept the registration on the detached old node — both silently.\n *\n * Two ways in, both re-resolving:\n * - `ref` — attach it as the element's `ref`; every (el | null) call moves\n * the registration, so mount order no longer matters.\n * - the `element` getter — still resolved on a microtask (so a plain\n * `let el` assigned by a ref is populated), but inside an effect, so a\n * getter that reads a SIGNAL re-registers when that signal changes. A\n * getter still `null` at that point (and no ref) gets a dev warning naming\n * the fix, instead of a drop zone that never works.\n *\n * Cleanup contract: identity-based — one live registration, disposed on\n * re-register, on `ref(null)`, and when the owning scope is cleaned up.\n */\nexport function bindElement(\n hookName: string,\n getter: (() => HTMLElement | null) | undefined,\n register: (el: HTMLElement) => () => void,\n): ElementBinding {\n let current: HTMLElement | null = null\n let cleanup: (() => void) | undefined\n let disposed = false\n let refUsed = false\n let stopGetter: (() => void) | undefined\n\n const attach = (el: HTMLElement | null): void => {\n if (disposed || el === current) return\n if (cleanup) {\n cleanup()\n cleanup = undefined\n }\n current = el\n if (el) cleanup = register(el)\n }\n\n const ref = (el: HTMLElement | null): void => {\n if (el) refUsed = true\n attach(el)\n }\n\n if (getter) {\n // Defer to the next microtask so a ref-assigned `let` is populated.\n queueMicrotask(() => {\n // Unmounted before the deferred setup ran — nothing to register.\n if (disposed || refUsed) return\n let first = true\n const e = effect(() => {\n const el = getter()\n untrack(() => {\n if (first && !el && !refUsed && process.env.NODE_ENV !== 'production') {\n console.warn(\n `[Pyreon] ${hookName}: element() returned null when the deferred setup ran, so nothing was registered. If the element mounts later (behind <Show>, a lazy branch), attach the returned \\`ref\\` to it instead (<div ref={ref}>), or read the element from a signal so the getter re-resolves.`,\n )\n }\n first = false\n // The ref wins once it has supplied an element.\n if (!refUsed) attach(el)\n })\n })\n stopGetter = () => e.dispose()\n })\n }\n\n onCleanup(() => {\n disposed = true\n stopGetter?.()\n if (cleanup) cleanup()\n cleanup = undefined\n current = null\n })\n\n return { ref }\n}\n","import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element-adapter'\nimport { centerUnderPointer } from '@atlaskit/pragmatic-drag-and-drop/utils/center-under-pointer'\nimport { pointerOutsideOfPreview } from '@atlaskit/pragmatic-drag-and-drop/utils/pointer-outside-of-preview'\nimport { preserveOffsetOnSource } from '@atlaskit/pragmatic-drag-and-drop/utils/preserve-offset-on-source'\nimport { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/utils/set-custom-native-drag-preview'\nimport { isServer, signal } from '@pyreon/reactivity'\nimport { bindElement } from './element-binding'\nimport type { DragData, DragPreviewOptions, UseDraggableOptions, UseDraggableResult } from './types'\n\n/**\n * Resolve a preview `offset` preset to pdnd's `GetOffsetFn`. Split out so\n * the ternary chain is directly unit-testable; `undefined` keeps the\n * browser default (top-left of the preview under the pointer).\n */\nfunction resolvePreviewOffset(\n offset: DragPreviewOptions['offset'],\n source: { element: HTMLElement },\n input: Parameters<typeof preserveOffsetOnSource>[0]['input'],\n): ReturnType<typeof pointerOutsideOfPreview> | undefined {\n if (offset === 'pointer-outside') return pointerOutsideOfPreview({ x: '16px', y: '8px' })\n if (offset === 'center') return centerUnderPointer\n if (offset === 'preserve-offset') {\n return preserveOffsetOnSource({ element: source.element, input })\n }\n return undefined\n}\n\n/**\n * Make an element draggable with signal-driven state.\n *\n * Attach the returned `ref` to the element (works for elements that mount\n * later or get swapped), or pass an `element` getter.\n *\n * @example\n * ```tsx\n * const { ref, isDragging } = useDraggable({\n * data: { id: card.id, type: \"card\" },\n * })\n *\n * <div ref={ref} 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 (isServer) return { isDragging: () => false, ref: () => {} }\n\n const isDragging = signal(false)\n\n const resolveData = () =>\n typeof options.data === 'function' ? (options.data as () => T)() : options.data\n\n function register(el: HTMLElement): () => void {\n const handle = options.handle?.()\n const preview = options.preview\n return draggable({\n element: el,\n ...(handle ? { dragHandle: handle } : {}),\n // Custom native drag preview — thin pass-through to pdnd's\n // setCustomNativeDragPreview + offset presets. Only wired when the\n // consumer opts in, so the default path is byte-identical.\n ...(preview\n ? {\n onGenerateDragPreview: ({\n nativeSetDragImage,\n source,\n location,\n }: {\n nativeSetDragImage: Parameters<\n typeof setCustomNativeDragPreview\n >[0]['nativeSetDragImage']\n source: { element: HTMLElement }\n location: {\n initial: { input: Parameters<typeof preserveOffsetOnSource>[0]['input'] }\n }\n }) => {\n const getOffset = resolvePreviewOffset(preview.offset, source, location.initial.input)\n setCustomNativeDragPreview({\n render: ({ container }) => preview.render(container),\n nativeSetDragImage,\n ...(getOffset ? { getOffset } : {}),\n })\n },\n }\n : {}),\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 const { ref } = bindElement('useDraggable', options.element, register)\n\n return { isDragging, ref }\n}\n","import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/element-adapter'\nimport {\n attachClosestEdge,\n type Edge,\n extractClosestEdge,\n} from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge'\nimport { batch, isServer, signal } from '@pyreon/reactivity'\nimport { bindElement } from './element-binding'\nimport type {\n DragData,\n DropEdge,\n DropLocation,\n UseDroppableOptions,\n UseDroppableResult,\n} from './types'\n\n/**\n * Make an element a drop target with signal-driven state.\n *\n * Attach the returned `ref` to the element (works for elements that mount\n * later or get swapped), or pass an `element` getter.\n *\n * @example\n * ```tsx\n * const { ref, isOver, overEdge } = useDroppable({\n * onDrop: (data, { edge }) => handleDrop(data, edge),\n * canDrop: (data) => data.type === \"card\",\n * edges: [\"top\", \"bottom\"], // opt-in closest-edge detection\n * })\n *\n * <div ref={ref} class={isOver() ? \"bg-blue-50\" : \"\"}>\n * Drop here\n * </div>\n * ```\n */\nexport function useDroppable<T extends DragData = DragData, TSource extends DragData = DragData>(\n options: UseDroppableOptions<T, TSource>,\n): UseDroppableResult {\n if (isServer) return { isOver: () => false, overEdge: () => null, ref: () => {} }\n\n const isOver = signal(false)\n const overEdge = signal<DropEdge | null>(null)\n const edges = options.edges\n const hasEdges = !!edges && edges.length > 0\n\n const resolveData = (): DragData => {\n if (!options.data) return {}\n return typeof options.data === 'function' ? (options.data as () => T)() : options.data\n }\n\n function register(el: HTMLElement): () => void {\n return dropTargetForElements({\n element: el,\n getData: ({ input, element }) => {\n const data = resolveData()\n // Opt-in closest-edge detection — wraps the target data with\n // pdnd hitbox metadata so extractClosestEdge can read the live\n // edge on enter/drag.\n if (hasEdges) {\n return attachClosestEdge(data, { input, element, allowedEdges: edges as Edge[] })\n }\n return data\n },\n // pdnd stickiness — keep \"held\" drop-target status while the\n // pointer crosses gaps between targets. Pass-through of getIsSticky.\n ...(options.sticky ? { getIsSticky: () => true } : {}),\n canDrop: ({ source }) => {\n if (!options.canDrop) return true\n return options.canDrop(source.data as TSource)\n },\n onDragEnter: ({ source, self }) => {\n // batch — isOver + overEdge settle in ONE notify pass for\n // subscribers reading both (matches useSortable's batching).\n batch(() => {\n isOver.set(true)\n if (hasEdges) overEdge.set(extractClosestEdge(self.data) as DropEdge | null)\n })\n options.onDragEnter?.(source.data as TSource)\n },\n // Live edge tracking while the pointer moves over the target —\n // only meaningful (and only wired) when edges are configured.\n ...(hasEdges\n ? {\n onDrag: ({ self }: { self: { data: Record<string | symbol, unknown> } }) => {\n overEdge.set(extractClosestEdge(self.data) as DropEdge | null)\n },\n }\n : {}),\n onDragLeave: () => {\n batch(() => {\n isOver.set(false)\n overEdge.set(null)\n })\n options.onDragLeave?.()\n },\n onDrop: ({ source, self }) => {\n // Capture WHERE the drop landed before the reset below clears the\n // signal — `onDrop` used to receive only the source, so the edge a\n // consumer needs to insert above/below was already gone.\n const location: DropLocation = {\n edge: hasEdges\n ? ((extractClosestEdge(self.data) as DropEdge | null) ?? overEdge.peek())\n : null,\n data: resolveData(),\n }\n batch(() => {\n isOver.set(false)\n overEdge.set(null)\n })\n options.onDrop?.(source.data as TSource, location)\n },\n })\n }\n\n const { ref } = bindElement('useDroppable', options.element, register)\n\n return { isOver, overEdge, ref }\n}\n","import { dropTargetForExternal } from '@atlaskit/pragmatic-drag-and-drop/adapter/drop-target-for-external'\nimport { monitorForExternal } from '@atlaskit/pragmatic-drag-and-drop/adapter/monitor-for-external'\nimport { containsFiles } from '@atlaskit/pragmatic-drag-and-drop/utils/contains-files'\nimport { getFiles } from '@atlaskit/pragmatic-drag-and-drop/utils/get-files'\nimport { batch, isServer, signal } from '@pyreon/reactivity'\nimport { bindElement } from './element-binding'\n\n/** Why a dropped file was not delivered to `onDrop`. */\nexport type FileRejectReason = 'accept' | 'maxFiles'\n\nexport interface UseFileDropOptions {\n /**\n * Element getter for the drop zone. Optional — attach the returned `ref`\n * instead for an element that mounts later or may be swapped. A getter that\n * reads a signal re-registers when the signal changes.\n */\n element?: () => HTMLElement | null\n /** Called when files are dropped (only the accepted ones). */\n onDrop: (files: File[]) => void\n /**\n * Called with the dropped files that were NOT delivered, and why: `'accept'`\n * (type / extension not in `accept`) or `'maxFiles'` (over the limit). Fired\n * once per reason per drop. Without it a rejected drop is silent.\n */\n onReject?: (rejected: File[], reason: FileRejectReason) => void\n /**\n * Filter accepted file types — MIME types (`\"image/png\"`), MIME wildcards\n * (`\"image/*\"`), extensions (`\".pdf\"`), or `\"*\"` / `\"*\\/*\"` for any file.\n */\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 /** Ref callback for the drop zone — see `UseFileDropOptions.element`. */\n ref: (el: HTMLElement | null) => void\n}\n\nfunction matchesAccept(file: File, accept: string[]): boolean {\n return accept.some((pattern) => {\n if (pattern === '*' || pattern === '*/*') return true\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/**\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 * const { ref, isOver, isDraggingFiles } = useFileDrop({\n * accept: [\"image/*\", \".pdf\"],\n * maxFiles: 5,\n * onDrop: (files) => upload(files),\n * onReject: (files, reason) => toast(`${files.length} file(s) rejected: ${reason}`),\n * })\n *\n * <div\n * ref={ref}\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 (isServer) return { isOver: () => false, isDraggingFiles: () => false, ref: () => {} }\n\n const isOver = signal(false)\n const isDraggingFiles = signal(false)\n\n function register(el: HTMLElement): () => void {\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 // batch() so onDrop subscribers don't get notified twice\n // (isOver + isDraggingFiles) per file-drop event.\n batch(() => {\n isOver.set(false)\n isDraggingFiles.set(false)\n })\n\n let files = getFiles({ source })\n\n // Filter by accept\n const accept = options.accept\n if (accept && accept.length > 0) {\n const rejected = files.filter((f) => !matchesAccept(f, accept))\n if (rejected.length > 0) {\n files = files.filter((f) => matchesAccept(f, accept))\n options.onReject?.(rejected, 'accept')\n }\n }\n\n // Limit count\n if (options.maxFiles && files.length > options.maxFiles) {\n options.onReject?.(files.slice(options.maxFiles), '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 return () => {\n for (const fn of cleanups) fn()\n }\n }\n\n const { ref } = bindElement('useFileDrop', options.element, register)\n\n return { isOver, isDraggingFiles, ref }\n}\n","import { combine } from '@atlaskit/pragmatic-drag-and-drop/utils/combine'\nimport { draggable, dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/adapter/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 { announce } from '@pyreon/a11y'\nimport { batch, createSelector, isServer, 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'\nconst SORT_GROUP = '__pyreon_sortable_group'\nconst SORT_PAYLOAD = '__pyreon_sortable_payload'\n\n// Same sr-only recipe as @pyreon/a11y's live regions — inline (not a CSS\n// class) so the instructions node needs zero stylesheet wiring.\nconst SR_ONLY =\n 'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0'\n\nlet _sortableCounter = 0\n\n// Visually-hidden keyboard instructions live in ONE shared host on\n// document.body — NOT inside the consumer's container. Appending a <div> into\n// the container put an invalid child inside a <ul>/<ol> AND broke `<For>`'s\n// owns-parent bulk clear (its markers were no longer the container's first\n// child, so every clear fell back to the per-node walk). Cleanup contract:\n// each sortable removes its OWN node by identity; the host is removed when its\n// last node goes (refcount = host.childElementCount).\nconst INSTRUCTIONS =\n 'To reorder, press Space or Enter to pick up an item, use the arrow keys to move it, then Space or Enter to drop it, or Escape to cancel. Alt plus an arrow key moves an item directly.'\nlet _instructionsHost: HTMLElement | null = null\n\nfunction mountInstructions(id: string): () => void {\n /* v8 ignore next — callers run client-side only (containerRef is a DOM ref) */\n if (isServer) return () => {}\n if (!_instructionsHost || !_instructionsHost.isConnected) {\n _instructionsHost = document.createElement('div')\n _instructionsHost.setAttribute('data-pyreon-sortable-instructions-host', '')\n _instructionsHost.style.cssText = SR_ONLY\n document.body.appendChild(_instructionsHost)\n }\n const host = _instructionsHost\n const node = document.createElement('div')\n node.id = id\n node.setAttribute('data-pyreon-sortable-instructions', '')\n node.textContent = INSTRUCTIONS\n host.appendChild(node)\n return () => {\n node.remove()\n if (host.childElementCount === 0) {\n host.remove()\n if (_instructionsHost === host) _instructionsHost = null\n }\n }\n}\n\n// Module-level registry of live sortable instances — used to dispatch\n// cross-list drop notifications from the destination back to the source\n// (W18). Keyed by sortableId.\nconst _sortableRegistry = new Map<\n string,\n {\n groupId: string | undefined\n onCrossListDrop: ((item: unknown) => void) | undefined\n }\n>()\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: Space/Enter picks an item up, arrows move it,\n * Space/Enter drops, Escape cancels (restores the original position);\n * Alt+Arrow moves directly. Every step is announced to screen readers.\n * - Optional cross-list `groupId` for Trello/Notion/Linear board layouts\n * (W18) — share the same `groupId` between two\n * sortable instances and items can be dragged between them. The\n * source's `onCrossListDrop(item)` removes; the destination's\n * `onCrossListReceive(item, index)` inserts.\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, isActive, isOverKey, overEdge } = useSortable({\n * items,\n * by: (item) => item.id,\n * onReorder: (newItems) => items.set(newItems),\n * label: (item) => item.name, // screen-reader announcements\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={isActive(item.id) ? \"dragging\" : \"\"}\n * style={isOverKey(item.id) ? `border-${overEdge()}: 2px solid blue` : \"\"}\n * >\n * {item.name}\n * </li>\n * )}\n * </For>\n * </ul>\n * ```\n *\n * Prefer `isActive(key)` / `isOverKey(key)` over `activeId() === key` /\n * `overId() === key` in row templates — the equality read subscribes EVERY\n * row to the id signal (O(N) notifies per change); the selectors notify\n * only the two affected rows (O(2), `createSelector` semantics).\n */\nexport function useSortable<T>(options: UseSortableOptions<T>): UseSortableResult {\n if (isServer) {\n const noop = (_el: HTMLElement | null) => {}\n return {\n containerRef: noop,\n itemRef: () => noop,\n itemHandleRef: () => noop,\n activeId: () => null,\n overId: () => null,\n overEdge: () => null,\n isActive: () => false,\n isOverKey: () => false,\n }\n }\n\n const sortableId = `sortable-${++_sortableCounter}`\n const instructionsId = `${sortableId}-instructions`\n const activeId = signal<string | number | null>(null)\n const overId = signal<string | number | null>(null)\n const overEdge = signal<DropEdge | null>(null)\n // createSelector-backed per-key predicates (the krausest select-row\n // pattern): `activeId() === key` in a row template subscribes EVERY row\n // to activeId (O(N) notifies per change); the selector notifies only\n // the two affected keys (deselected + newly selected) — O(2).\n const isActiveSelector = createSelector<string | number | null>(activeId)\n const isOverSelector = createSelector<string | number | null>(overId)\n const axis = options.axis ?? 'vertical'\n const groupId = options.groupId\n const isDisabled = (): boolean => {\n const d = options.disabled\n return typeof d === 'function' ? d() : !!d\n }\n\n /** Resolve the announcement label for an item: `label(item)` else the key. */\n function labelOf(item: T | undefined, key: string | number): string {\n if (item !== undefined && options.label) return options.label(item)\n return String(key)\n }\n\n /** Resolve the announcement label for a key by looking the item up. */\n function labelFor(key: string | number): string {\n const item = options.items().find((i) => options.by(i) === key || String(options.by(i)) === key)\n return labelOf(item, key)\n }\n\n // Register so siblings in the same group can call our onCrossListDrop\n // when they receive one of our items.\n _sortableRegistry.set(sortableId, {\n groupId,\n onCrossListDrop: options.onCrossListDrop as ((item: unknown) => void) | undefined,\n })\n\n // Container-level pdnd teardown (auto-scroll + reorder drop-target + the\n // keydown listener). A SINGLE disposer, replaced on re-register and cleared\n // on unmount — symmetric with the per-item map below. A collapsible board\n // whose `<ul ref={containerRef}>` sits behind a `<Show>` (with the hook in\n // the parent) re-fires `containerRef` on every toggle; without disposal each\n // toggle leaked the auto-scroll + drop-target + keydown listener on the now-\n // detached element (the container sibling of the F3 per-item leak).\n let containerCleanup: (() => void) | undefined\n // Per-item pdnd cleanups, keyed by sort key. Disposed individually on\n // item unmount / re-register so a churning list doesn't accumulate\n // dead registrations for the sortable's whole lifetime.\n const itemCleanups = new Map<string | number, () => 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 /* v8 ignore next — defensive null/equal id guards */\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 /* v8 ignore next — defensive findIndex-not-found guards; ids come from active drag */\n if (dragIndex === -1 || dropIndex === -1) return\n\n const reordered = [...currentItems]\n const [moved] = reordered.splice(dragIndex, 1)\n /* v8 ignore next — defensive splice fallback; dragIndex was just verified */\n if (!moved) return\n\n // Determine insert position based on closest edge\n /* v8 ignore next 7 — ternary combinatorics; structurally exercised in browser e2e but not unit-coverable per arm */\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 // Screen-reader announcement — position is 1-based for humans.\n announce(`Dropped ${labelOf(moved, dragId)} at position ${insertAt + 1} of ${reordered.length}`)\n }\n\n /** Announce a cross-list receive on THIS (destination) sortable. */\n function announceCrossListReceive(item: T, insertAt: number) {\n // `items()` reflects the post-insert length when the consumer commits\n // synchronously inside onCrossListReceive (the documented shape); the\n // max() keeps the count honest if the commit is deferred.\n const count = Math.max(options.items().length, insertAt + 1)\n const key = options.by(item)\n announce(\n `Dropped ${labelOf(item, key)} at position ${insertAt + 1} of ${count} in the receiving list`,\n )\n }\n\n /** Returns true when `source` belongs to this sortable or to a sibling\n * in the same `groupId`. */\n function acceptsSource(source: { data: Record<string, unknown> }): boolean {\n if (source.data[SORT_ID] === sortableId) return true\n if (groupId && source.data[SORT_GROUP] === groupId) return true\n return false\n }\n\n function containerRef(el: HTMLElement | null) {\n // Dispose the prior container registration on BOTH unmount (el === null,\n // fired by Pyreon's runtime) AND re-register (a new container element) so\n // a toggled/re-mounted container can't leak its auto-scroll + drop-target +\n // keydown listener. Symmetric with the per-item disposal below (F3).\n if (containerCleanup) {\n containerCleanup()\n containerCleanup = undefined\n }\n if (!el) return\n\n const containerCleanups: (() => void)[] = []\n\n // Visually-hidden keyboard instructions, referenced by every item via\n // aria-describedby (the dnd-kit pattern — screen-reader users land on\n // an item and hear how to reorder it). Lives in a shared host OUTSIDE\n // the container (see mountInstructions), removed with the container\n // registration.\n containerCleanups.push(mountInstructions(instructionsId))\n\n // A non-list container gets `role=\"list\"` so its `listitem` children are\n // valid; a <ul>/<ol> (implicit list) or a consumer-set role is left alone.\n if (!el.hasAttribute('role') && el.tagName !== 'UL' && el.tagName !== 'OL') {\n el.setAttribute('role', 'list')\n containerCleanups.push(() => {\n if (el.getAttribute('role') === 'list') el.removeAttribute('role')\n })\n }\n\n // Auto-scroll when dragging near container edges\n containerCleanups.push(\n autoScrollForElements({\n element: el,\n canScroll: ({ source }) => acceptsSource(source),\n }),\n )\n\n // Container is a drop target for reorder finalization OR for\n // appending a cross-list item at the end of this column.\n containerCleanups.push(\n dropTargetForElements({\n element: el,\n getData: () => ({ [SORT_ID]: sortableId, [SORT_GROUP]: groupId }),\n canDrop: ({ source }) => acceptsSource(source),\n onDrop: ({ source }) => {\n // Item-level dropTarget for cross-list drops marks the source\n // data as handled — container skips so we don't insert twice.\n const handled = (source.data as Record<string, unknown>).__pyreon_sortable_handled\n if (source.data[SORT_ID] === sortableId) {\n // Same-list drop on container edge → reorder finalization.\n performReorder()\n } else if (\n !handled &&\n groupId &&\n source.data[SORT_GROUP] === groupId &&\n options.onCrossListReceive\n ) {\n // Cross-list drop on the container itself (not on an item) →\n // append to the end of this column.\n const item = source.data[SORT_PAYLOAD] as T\n const sourceSortableId = source.data[SORT_ID] as string\n const targetIndex = options.items().length\n options.onCrossListReceive(item, targetIndex)\n const sourceInstance = _sortableRegistry.get(sourceSortableId)\n sourceInstance?.onCrossListDrop?.(item)\n announceCrossListReceive(item, targetIndex)\n }\n // batch() the 3-signal reset so subscribers reading any of\n // activeId/overId/overEdge get notified once per drop, not\n // three times. Fires on every container-level drop.\n batch(() => {\n activeId.set(null)\n overId.set(null)\n overEdge.set(null)\n })\n },\n }),\n )\n\n // ── Keyboard reordering ────────────────────────────────────────────\n // Pickup mode (WAI-ARIA / dnd-kit model): Space or Enter on a focused\n // item picks it up, the axis arrows move it one slot per press, Space or\n // Enter drops it, Escape cancels and restores the original index. The\n // Alt+Arrow direct move is kept. Every step is announced.\n let picked: { key: string; origin: number } | null = null\n let focusFrame = 0\n\n const indexOf = (key: string): number =>\n options.items().findIndex((item) => String(options.by(item)) === key)\n\n const restoreFocus = (key: string) => {\n if (focusFrame) cancelAnimationFrame(focusFrame)\n focusFrame = requestAnimationFrame(() => {\n focusFrame = 0\n const items = el.querySelectorAll('[data-pyreon-sort-key]')\n for (const item of items) {\n if ((item as HTMLElement).dataset.pyreonSortKey === key) {\n ;(item as HTMLElement).focus()\n break\n }\n }\n })\n }\n\n /** Move the item with `key` from its index to `to`; returns false when out of range. */\n const moveTo = (key: string, to: number): boolean => {\n const currentItems = options.items()\n const from = indexOf(key)\n /* v8 ignore next — defensive findIndex guard; the key comes from a live item */\n if (from === -1) return false\n if (to < 0 || to >= currentItems.length || to === from) return false\n const reordered = [...currentItems]\n const [moved] = reordered.splice(from, 1)\n reordered.splice(to, 0, moved as T)\n options.onReorder(reordered)\n restoreFocus(key)\n return true\n }\n\n const endPickup = () => {\n picked = null\n activeId.set(null)\n }\n\n const keyHandler = (e: KeyboardEvent) => {\n const focused = document.activeElement as HTMLElement | null\n if (!focused || !el.contains(focused)) return\n const focusedKey = focused.dataset.pyreonSortKey\n if (!focusedKey) return\n\n const isSpaceOrEnter = e.key === ' ' || e.key === 'Enter'\n const isUp = axis === 'vertical' ? e.key === 'ArrowUp' : e.key === 'ArrowLeft'\n const isDown = axis === 'vertical' ? e.key === 'ArrowDown' : e.key === 'ArrowRight'\n\n if (picked) {\n if (isUp || isDown) {\n e.preventDefault()\n const from = indexOf(picked.key)\n const to = isUp ? from - 1 : from + 1\n if (moveTo(picked.key, to)) {\n announce(\n `Moved ${labelFor(picked.key)} to position ${to + 1} of ${options.items().length}`,\n )\n }\n return\n }\n if (isSpaceOrEnter) {\n e.preventDefault()\n const key = picked.key\n endPickup()\n announce(\n `Dropped ${labelFor(key)} at position ${indexOf(key) + 1} of ${options.items().length}`,\n )\n return\n }\n if (e.key === 'Escape') {\n e.preventDefault()\n const { key, origin } = picked\n moveTo(key, origin)\n endPickup()\n announce(\n `Reorder cancelled. ${labelFor(key)} returned to position ${origin + 1} of ${options.items().length}`,\n )\n }\n return\n }\n\n if (isDisabled()) return\n\n // Pickup starts only from the ITEM's own keystroke: a button / input\n // inside an item keeps its native Space / Enter behaviour.\n if (\n isSpaceOrEnter &&\n e.target === focused &&\n !e.altKey &&\n !e.ctrlKey &&\n !e.metaKey &&\n !e.shiftKey\n ) {\n e.preventDefault()\n const origin = indexOf(focusedKey)\n /* v8 ignore next — defensive findIndex guard; the key comes from a live item */\n if (origin === -1) return\n picked = { key: focusedKey, origin }\n // Real key type (number keys stay numbers) so isActive(key) matches.\n activeId.set(options.by(options.items()[origin] as T))\n announce(\n `Picked up ${labelFor(focusedKey)}. Current position ${origin + 1} of ${options.items().length}. Use the arrow keys to move, Space or Enter to drop, Escape to cancel.`,\n )\n return\n }\n\n if (!e.altKey || (!isUp && !isDown)) return\n e.preventDefault()\n const from = indexOf(focusedKey)\n const to = isUp ? from - 1 : from + 1\n if (moveTo(focusedKey, to)) {\n // Screen-reader announcement for the keyboard path (1-based).\n announce(`Moved ${labelFor(focusedKey)} to position ${to + 1} of ${options.items().length}`)\n }\n }\n\n el.addEventListener('keydown', keyHandler)\n containerCleanups.push(() => el.removeEventListener('keydown', keyHandler))\n // A pending focus-restore frame must not run against a torn-down list.\n containerCleanups.push(() => {\n if (focusFrame) cancelAnimationFrame(focusFrame)\n focusFrame = 0\n if (picked) endPickup()\n })\n\n containerCleanup = () => {\n for (const fn of containerCleanups) fn()\n }\n }\n\n // Live item elements + registered drag handles, keyed by sort key.\n // `itemEls` lets the handle registrar re-register an already-mounted\n // item when its handle arrives (child refs fire AFTER the parent's,\n // so the handle is never available at itemRef time).\n const itemEls = new Map<string | number, HTMLElement>()\n const itemHandles = new Map<string | number, HTMLElement>()\n\n function itemRef(key: string | number): (el: HTMLElement | null) => void {\n // The element THIS ref callback registered. A keyed re-render mounts the\n // replacement row (same key) BEFORE the old row's ref(null) fires; when\n // this callback registered an element that is no longer the live one for\n // the key, its null is stale and must not tear down the live row's\n // registration. (A callback that never registered anything — an\n // imperative `itemRef(key)(null)` — still disposes the key.)\n let mine: HTMLElement | null = null\n return (el: HTMLElement | null) => {\n if (!el) {\n const stale = mine !== null && itemEls.get(key) !== mine\n mine = null\n if (stale) return\n }\n // Per-key disposal. The ref fires with the element on mount and\n // with `null` on unmount. The old code pushed every registration\n // onto the shared `cleanups[]` and made the null branch a pure\n // no-op — so for a `<For>`-rendered sortable (the documented usage:\n // todo list / kanban) every removed item's pdnd `draggable` /\n // `dropTargetForElements` registration (and its pointer/drag\n // listeners on the now-detached node) leaked until the WHOLE\n // sortable unmounted. Dispose the prior registration for this key\n // on BOTH unmount (el === null) and re-registration (same key,\n // new element) so the live set tracks live items, not all-ever.\n const prev = itemCleanups.get(key)\n if (prev) {\n prev()\n itemCleanups.delete(key)\n }\n if (!el) {\n itemEls.delete(key)\n return\n }\n mine = el\n itemEls.set(key, el)\n registerItem(key, el)\n }\n }\n\n /**\n * OPTIONAL drag-handle registrar mirroring `itemRef`. When a handle is\n * (un)registered for an already-mounted item, the item's pdnd\n * registration is torn down and re-created so `dragHandle` takes\n * effect — pdnd captures the handle at registration time.\n */\n function itemHandleRef(key: string | number): (el: HTMLElement | null) => void {\n // Same ownership rule as itemRef: a stale handle's null must not drop a\n // replacement row's handle.\n let mine: HTMLElement | null = null\n return (el: HTMLElement | null) => {\n if (el) {\n mine = el\n itemHandles.set(key, el)\n } else {\n const stale = mine !== null && itemHandles.get(key) !== mine\n mine = null\n if (stale) return\n itemHandles.delete(key)\n }\n const itemEl = itemEls.get(key)\n if (!itemEl) return\n // itemEls and itemCleanups are set together (itemRef → registerItem),\n // so a live itemEl implies a live cleanup — dispose it before the\n // re-registration below replaces it.\n /* v8 ignore next — defensive optional call; a live itemEl implies a live cleanup */\n itemCleanups.get(key)?.()\n itemCleanups.delete(key)\n registerItem(key, itemEl)\n }\n }\n\n function registerItem(key: string | number, el: HTMLElement) {\n el.dataset.pyreonSortKey = String(key)\n if (!el.hasAttribute('tabindex')) el.setAttribute('tabindex', '0')\n // A consumer-supplied role (option, row, treeitem, …) wins.\n if (!el.hasAttribute('role')) el.setAttribute('role', 'listitem')\n el.setAttribute('aria-roledescription', 'sortable item')\n // Link the container's visually-hidden keyboard instructions so a\n // screen-reader user focusing the item hears how to reorder it.\n // A consumer-supplied aria-describedby wins.\n if (!el.hasAttribute('aria-describedby')) {\n el.setAttribute('aria-describedby', instructionsId)\n }\n\n const allowedEdges: Edge[] = axis === 'vertical' ? ['top', 'bottom'] : ['left', 'right']\n const handle = itemHandles.get(key)\n\n const cleanup = combine(\n draggable({\n element: el,\n // Per-item drag handle (pdnd dragHandle) — drag initiation is\n // scoped to the registered handle element when one exists.\n ...(handle ? { dragHandle: handle } : {}),\n canDrag: () => !isDisabled(),\n getInitialData: () => {\n const currentItems = options.items()\n const item = currentItems.find((i) => options.by(i) === key)\n return {\n [SORT_KEY]: key,\n [SORT_ID]: sortableId,\n [SORT_GROUP]: groupId,\n // Carry the actual item value when groupId is set so a\n // sibling sortable's onDrop can receive it without a\n // separate registry lookup. Plain reference (pdnd doesn't\n // serialize) — safe within a single document.\n [SORT_PAYLOAD]: groupId ? item : undefined,\n }\n },\n onDragStart: () => {\n activeId.set(key)\n announce(`Picked up ${labelFor(key)}`)\n },\n onDrop: () => {\n queueMicrotask(() => {\n // batch() — same 3-signal reset shape as the container\n // onDrop above. Per-item drops fire this branch.\n batch(() => {\n activeId.set(null)\n overId.set(null)\n overEdge.set(null)\n })\n })\n },\n }),\n dropTargetForElements({\n element: el,\n getData: ({ input, element }) =>\n attachClosestEdge(\n { [SORT_KEY]: key, [SORT_ID]: sortableId, [SORT_GROUP]: groupId },\n { input, element, allowedEdges },\n ),\n canDrop: ({ source }) => acceptsSource(source),\n onDragEnter: ({ self }) => {\n // batch — overId + overEdge settle in ONE notify pass (same\n // shape as every other multi-signal write in this hook).\n batch(() => {\n overId.set(key)\n overEdge.set(extractClosestEdge(self.data) as DropEdge | null)\n })\n },\n onDrag: ({ self }) => {\n overEdge.set(extractClosestEdge(self.data) as DropEdge | null)\n },\n onDragLeave: () => {\n if (overId.peek() === key) {\n batch(() => {\n overId.set(null)\n overEdge.set(null)\n })\n }\n },\n onDrop: ({ source, self }) => {\n // Same-list drops are handled by the container's onDrop via\n // performReorder. Item-level onDrop fires for cross-list\n // shapes — insert at THIS item's index, then propagate to\n // the source to remove.\n if (source.data[SORT_ID] === sortableId) return\n if (!groupId || source.data[SORT_GROUP] !== groupId || !options.onCrossListReceive) {\n return\n }\n const item = source.data[SORT_PAYLOAD] as T\n const edge = extractClosestEdge(self.data) as DropEdge | null\n const currentItems = options.items()\n const targetIndex = currentItems.findIndex((i) => options.by(i) === key)\n /* v8 ignore next — defensive findIndex guard */\n if (targetIndex === -1) return\n /* v8 ignore next 4 — ternary combinatorics */\n const insertAt =\n edge === 'bottom' || edge === 'right' ? targetIndex + 1 : Math.max(0, targetIndex)\n options.onCrossListReceive(item, insertAt)\n const sourceSortableId = source.data[SORT_ID] as string\n const sourceInstance = _sortableRegistry.get(sourceSortableId)\n sourceInstance?.onCrossListDrop?.(item)\n announceCrossListReceive(item, insertAt)\n // Mark so the container's onDrop (which also fires) skips\n // re-inserting at the end of the list.\n ;(source.data as Record<string, unknown>).__pyreon_sortable_handled = true\n },\n }),\n )\n\n itemCleanups.set(key, cleanup)\n }\n\n onCleanup(() => {\n // Drain the live container registration (idempotent — containerRef(null)\n // may already have cleared it) plus every per-item registration.\n if (containerCleanup) {\n containerCleanup()\n containerCleanup = undefined\n }\n for (const cleanup of itemCleanups.values()) cleanup()\n itemCleanups.clear()\n itemEls.clear()\n itemHandles.clear()\n _sortableRegistry.delete(sortableId)\n // Selectors own a source-tracking effect + per-key buckets — release\n // them with the sortable (keys are unbounded across list churn).\n isActiveSelector.dispose()\n isOverSelector.dispose()\n // batch() the final 3-signal reset so any subscriber that survives\n // the dispose order (unusual but possible — e.g. an external store\n // holding refs) sees one notify, not three.\n batch(() => {\n activeId.set(null)\n overId.set(null)\n overEdge.set(null)\n })\n })\n\n return {\n containerRef,\n itemRef,\n itemHandleRef,\n activeId,\n overId,\n overEdge,\n isActive: (key: string | number) => isActiveSelector(key),\n isOverKey: (key: string | number) => isOverSelector(key),\n }\n}\n","import { name as __pkgName, version as __pkgVersion } from '../package.json' with { type: 'json' }\nimport { registerSingleton } from '@pyreon/reactivity'\n\n// Singleton sentinel — fail-loud detection of duplicate @pyreon/dnd\n// instances in the same heap. See @pyreon/reactivity/singleton-sentinel for\n// full rationale. Hardcoded version is acceptable here — it's a diagnostic\n// aid, not a load-bearing identity check.\nregisterSingleton(__pkgName, __pkgVersion, import.meta.url)\n\nexport type {\n DragData,\n DragPreviewOptions,\n DropEdge,\n DropLocation,\n UseDraggableOptions,\n UseDraggableResult,\n UseDroppableOptions,\n UseDroppableResult,\n UseSortableOptions,\n UseSortableResult,\n} from './types'\n\nexport type { UseDragMonitorOptions, UseDragMonitorResult } from './use-drag-monitor'\nexport { useDragMonitor } from './use-drag-monitor'\n\nexport { useDraggable } from './use-draggable'\nexport { useDroppable } from './use-droppable'\nexport type { FileRejectReason, UseFileDropOptions, UseFileDropResult } from './use-file-drop'\nexport { useFileDrop } from './use-file-drop'\nexport { useSortable } from './use-sortable'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACuCA,SAAgB,eAAe,SAAuD;CACpF,IAAI,UAAU,OA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KAAK,MAAM,WAAW,aAAa,OAAO,GAAG,QAAQ;EACrD,aAAa,MAAM;EACnB,QAAQ,MAAM;EACd,YAAY,MAAM;EAClB,kBAAkB,OAAO,UAAU;EAGnC,iBAAiB,QAAQ;EACzB,eAAe,QAAQ;EAIvB,YAAY;GACV,SAAS,IAAI,IAAI;GACjB,OAAO,IAAI,IAAI;GACf,SAAS,IAAI,IAAI;EACnB,CAAC;CACH,CAAC;CAED,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA,WAAW,QAAyB,iBAAiB,GAAG;EACxD,YAAY,QAAyB,eAAe,GAAG;CACzD;AACF;;;;ACxqBA,kBAAkBA,MAAWC,SAAc,YAAY,GAAG"}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -35,8 +35,14 @@ interface DragPreviewOptions {
|
|
|
35
35
|
offset?: 'pointer-outside' | 'center' | 'preserve-offset';
|
|
36
36
|
}
|
|
37
37
|
interface UseDraggableOptions<T extends DragData = DragData> {
|
|
38
|
-
/**
|
|
39
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Element getter for the draggable element. Optional — attach the result's
|
|
40
|
+
* `ref` instead for an element that mounts later or may be swapped. Resolved
|
|
41
|
+
* on a microtask after the hook runs; a getter that reads a SIGNAL
|
|
42
|
+
* re-registers when the signal changes. A getter still returning `null` at
|
|
43
|
+
* that point (with no `ref` attached) warns in dev.
|
|
44
|
+
*/
|
|
45
|
+
element?: () => HTMLElement | null;
|
|
40
46
|
/** Data to transfer on drag. Can be a function for dynamic data. */
|
|
41
47
|
data: T | (() => T);
|
|
42
48
|
/** Optional drag handle element (subset of the draggable). */
|
|
@@ -57,20 +63,37 @@ interface UseDraggableOptions<T extends DragData = DragData> {
|
|
|
57
63
|
interface UseDraggableResult {
|
|
58
64
|
/** Whether this element is currently being dragged. */
|
|
59
65
|
isDragging: () => boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Ref callback for the draggable element: registers on mount, moves the
|
|
68
|
+
* registration when the element is swapped, disposes on `null`.
|
|
69
|
+
*/
|
|
70
|
+
ref: (el: HTMLElement | null) => void;
|
|
60
71
|
}
|
|
61
|
-
interface UseDroppableOptions<T extends DragData = DragData> {
|
|
62
|
-
/**
|
|
63
|
-
|
|
64
|
-
|
|
72
|
+
interface UseDroppableOptions<T extends DragData = DragData, TSource extends DragData = DragData> {
|
|
73
|
+
/**
|
|
74
|
+
* Element getter for the drop target. Optional — attach the result's `ref`
|
|
75
|
+
* instead for an element that mounts later or may be swapped (same
|
|
76
|
+
* semantics as `UseDraggableOptions.element`).
|
|
77
|
+
*/
|
|
78
|
+
element?: () => HTMLElement | null;
|
|
79
|
+
/** Data to attach to the drop target (`T`). */
|
|
65
80
|
data?: T | (() => T);
|
|
66
|
-
/**
|
|
67
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Filter what can be dropped. Return false to reject. Receives the DRAG
|
|
83
|
+
* SOURCE's data — type it with the second generic, `TSource`.
|
|
84
|
+
*/
|
|
85
|
+
canDrop?: (sourceData: TSource) => boolean;
|
|
68
86
|
/** Called when a draggable enters this target. */
|
|
69
|
-
onDragEnter?: (sourceData:
|
|
87
|
+
onDragEnter?: (sourceData: TSource) => void;
|
|
70
88
|
/** Called when a draggable leaves this target. */
|
|
71
89
|
onDragLeave?: () => void;
|
|
72
|
-
/**
|
|
73
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Called when an item is dropped on this target, with the source's data and
|
|
92
|
+
* WHERE it landed: `edge` (the closest configured edge, `null` without
|
|
93
|
+
* `edges`) and `data` (this target's own data). Both are captured before the
|
|
94
|
+
* `isOver` / `overEdge` signals reset.
|
|
95
|
+
*/
|
|
96
|
+
onDrop?: (sourceData: TSource, location: DropLocation) => void;
|
|
74
97
|
/**
|
|
75
98
|
* Opt into closest-edge detection (pdnd hitbox `attachClosestEdge` /
|
|
76
99
|
* `extractClosestEdge`). Pass the edges you care about (e.g.
|
|
@@ -94,6 +117,8 @@ interface UseDroppableResult {
|
|
|
94
117
|
* otherwise. Always `null` unless the `edges` option is set.
|
|
95
118
|
*/
|
|
96
119
|
overEdge: () => DropEdge | null;
|
|
120
|
+
/** Ref callback for the drop target — see `UseDroppableOptions.element`. */
|
|
121
|
+
ref: (el: HTMLElement | null) => void;
|
|
97
122
|
}
|
|
98
123
|
interface UseSortableOptions<T> {
|
|
99
124
|
/** Reactive list of items to sort. */
|
|
@@ -138,13 +163,18 @@ interface UseSortableOptions<T> {
|
|
|
138
163
|
* your keys are opaque ids.
|
|
139
164
|
*/
|
|
140
165
|
label?: (item: T) => string;
|
|
166
|
+
/**
|
|
167
|
+
* Disable reordering (pointer drag AND keyboard). Reactive when a function.
|
|
168
|
+
*/
|
|
169
|
+
disabled?: boolean | (() => boolean);
|
|
141
170
|
}
|
|
142
171
|
interface UseSortableResult {
|
|
143
172
|
/**
|
|
144
173
|
* Attach to the scroll container. Pyreon's runtime invokes refs with
|
|
145
|
-
* `T | null
|
|
146
|
-
*
|
|
147
|
-
*
|
|
174
|
+
* `T | null`: an element (re)registers the container (auto-scroll, the
|
|
175
|
+
* container drop target, the keyboard handler, `role="list"` on a non-list
|
|
176
|
+
* element), and `null` DISPOSES that registration — so a container behind
|
|
177
|
+
* `<Show>` can toggle without leaking.
|
|
148
178
|
*/
|
|
149
179
|
containerRef: (el: HTMLElement | null) => void;
|
|
150
180
|
/**
|
|
@@ -218,57 +248,72 @@ interface UseDragMonitorResult {
|
|
|
218
248
|
* </Show>
|
|
219
249
|
* ```
|
|
220
250
|
*/
|
|
221
|
-
declare function useDragMonitor(options?: UseDragMonitorOptions): UseDragMonitorResult;
|
|
251
|
+
export declare function useDragMonitor(options?: UseDragMonitorOptions): UseDragMonitorResult;
|
|
222
252
|
//#endregion
|
|
223
253
|
//#region src/use-draggable.d.ts
|
|
224
254
|
/**
|
|
225
255
|
* Make an element draggable with signal-driven state.
|
|
226
256
|
*
|
|
257
|
+
* Attach the returned `ref` to the element (works for elements that mount
|
|
258
|
+
* later or get swapped), or pass an `element` getter.
|
|
259
|
+
*
|
|
227
260
|
* @example
|
|
228
261
|
* ```tsx
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
* const { isDragging } = useDraggable({
|
|
232
|
-
* element: () => cardEl,
|
|
262
|
+
* const { ref, isDragging } = useDraggable({
|
|
233
263
|
* data: { id: card.id, type: "card" },
|
|
234
264
|
* })
|
|
235
265
|
*
|
|
236
|
-
* <div ref={
|
|
266
|
+
* <div ref={ref} class={isDragging() ? "opacity-50" : ""}>
|
|
237
267
|
* {card.title}
|
|
238
268
|
* </div>
|
|
239
269
|
* ```
|
|
240
270
|
*/
|
|
241
|
-
declare function useDraggable<T extends DragData = DragData>(options: UseDraggableOptions<T>): UseDraggableResult;
|
|
271
|
+
export declare function useDraggable<T extends DragData = DragData>(options: UseDraggableOptions<T>): UseDraggableResult;
|
|
242
272
|
//#endregion
|
|
243
273
|
//#region src/use-droppable.d.ts
|
|
244
274
|
/**
|
|
245
275
|
* Make an element a drop target with signal-driven state.
|
|
246
276
|
*
|
|
277
|
+
* Attach the returned `ref` to the element (works for elements that mount
|
|
278
|
+
* later or get swapped), or pass an `element` getter.
|
|
279
|
+
*
|
|
247
280
|
* @example
|
|
248
281
|
* ```tsx
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
* const { isOver, overEdge } = useDroppable({
|
|
252
|
-
* element: () => zoneEl,
|
|
253
|
-
* onDrop: (data) => handleDrop(data),
|
|
282
|
+
* const { ref, isOver, overEdge } = useDroppable({
|
|
283
|
+
* onDrop: (data, { edge }) => handleDrop(data, edge),
|
|
254
284
|
* canDrop: (data) => data.type === "card",
|
|
255
285
|
* edges: ["top", "bottom"], // opt-in closest-edge detection
|
|
256
286
|
* })
|
|
257
287
|
*
|
|
258
|
-
* <div ref={
|
|
288
|
+
* <div ref={ref} class={isOver() ? "bg-blue-50" : ""}>
|
|
259
289
|
* Drop here
|
|
260
290
|
* </div>
|
|
261
291
|
* ```
|
|
262
292
|
*/
|
|
263
|
-
declare function useDroppable<T extends DragData = DragData>(options: UseDroppableOptions<T>): UseDroppableResult;
|
|
293
|
+
export declare function useDroppable<T extends DragData = DragData, TSource extends DragData = DragData>(options: UseDroppableOptions<T, TSource>): UseDroppableResult;
|
|
264
294
|
//#endregion
|
|
265
295
|
//#region src/use-file-drop.d.ts
|
|
296
|
+
/** Why a dropped file was not delivered to `onDrop`. */
|
|
297
|
+
type FileRejectReason = 'accept' | 'maxFiles';
|
|
266
298
|
interface UseFileDropOptions {
|
|
267
|
-
/**
|
|
268
|
-
|
|
269
|
-
|
|
299
|
+
/**
|
|
300
|
+
* Element getter for the drop zone. Optional — attach the returned `ref`
|
|
301
|
+
* instead for an element that mounts later or may be swapped. A getter that
|
|
302
|
+
* reads a signal re-registers when the signal changes.
|
|
303
|
+
*/
|
|
304
|
+
element?: () => HTMLElement | null;
|
|
305
|
+
/** Called when files are dropped (only the accepted ones). */
|
|
270
306
|
onDrop: (files: File[]) => void;
|
|
271
|
-
/**
|
|
307
|
+
/**
|
|
308
|
+
* Called with the dropped files that were NOT delivered, and why: `'accept'`
|
|
309
|
+
* (type / extension not in `accept`) or `'maxFiles'` (over the limit). Fired
|
|
310
|
+
* once per reason per drop. Without it a rejected drop is silent.
|
|
311
|
+
*/
|
|
312
|
+
onReject?: (rejected: File[], reason: FileRejectReason) => void;
|
|
313
|
+
/**
|
|
314
|
+
* Filter accepted file types — MIME types (`"image/png"`), MIME wildcards
|
|
315
|
+
* (`"image/*"`), extensions (`".pdf"`), or `"*"` / `"*\/*"` for any file.
|
|
316
|
+
*/
|
|
272
317
|
accept?: string[];
|
|
273
318
|
/** Maximum number of files. */
|
|
274
319
|
maxFiles?: number;
|
|
@@ -280,6 +325,8 @@ interface UseFileDropResult {
|
|
|
280
325
|
isOver: () => boolean;
|
|
281
326
|
/** Whether files are being dragged anywhere on the page. */
|
|
282
327
|
isDraggingFiles: () => boolean;
|
|
328
|
+
/** Ref callback for the drop zone — see `UseFileDropOptions.element`. */
|
|
329
|
+
ref: (el: HTMLElement | null) => void;
|
|
283
330
|
}
|
|
284
331
|
/**
|
|
285
332
|
* File drop zone with signal-driven state.
|
|
@@ -287,24 +334,22 @@ interface UseFileDropResult {
|
|
|
287
334
|
*
|
|
288
335
|
* @example
|
|
289
336
|
* ```tsx
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
* const { isOver, isDraggingFiles } = useFileDrop({
|
|
293
|
-
* element: () => dropZone,
|
|
337
|
+
* const { ref, isOver, isDraggingFiles } = useFileDrop({
|
|
294
338
|
* accept: ["image/*", ".pdf"],
|
|
295
339
|
* maxFiles: 5,
|
|
296
340
|
* onDrop: (files) => upload(files),
|
|
341
|
+
* onReject: (files, reason) => toast(`${files.length} file(s) rejected: ${reason}`),
|
|
297
342
|
* })
|
|
298
343
|
*
|
|
299
344
|
* <div
|
|
300
|
-
* ref={
|
|
345
|
+
* ref={ref}
|
|
301
346
|
* class={isOver() ? "drop-active" : isDraggingFiles() ? "drop-ready" : ""}
|
|
302
347
|
* >
|
|
303
348
|
* Drop files here
|
|
304
349
|
* </div>
|
|
305
350
|
* ```
|
|
306
351
|
*/
|
|
307
|
-
declare function useFileDrop(options: UseFileDropOptions): UseFileDropResult;
|
|
352
|
+
export declare function useFileDrop(options: UseFileDropOptions): UseFileDropResult;
|
|
308
353
|
//#endregion
|
|
309
354
|
//#region src/use-sortable.d.ts
|
|
310
355
|
/**
|
|
@@ -315,7 +360,9 @@ declare function useFileDrop(options: UseFileDropOptions): UseFileDropResult;
|
|
|
315
360
|
* - Auto-scroll when dragging near container edges
|
|
316
361
|
* - Closest-edge detection (drop above/below or left/right)
|
|
317
362
|
* - Axis constraint (vertical/horizontal)
|
|
318
|
-
* - Keyboard reordering
|
|
363
|
+
* - Keyboard reordering: Space/Enter picks an item up, arrows move it,
|
|
364
|
+
* Space/Enter drops, Escape cancels (restores the original position);
|
|
365
|
+
* Alt+Arrow moves directly. Every step is announced to screen readers.
|
|
319
366
|
* - Optional cross-list `groupId` for Trello/Notion/Linear board layouts
|
|
320
367
|
* (W18) — share the same `groupId` between two
|
|
321
368
|
* sortable instances and items can be dragged between them. The
|
|
@@ -357,6 +404,6 @@ declare function useFileDrop(options: UseFileDropOptions): UseFileDropResult;
|
|
|
357
404
|
* row to the id signal (O(N) notifies per change); the selectors notify
|
|
358
405
|
* only the two affected rows (O(2), `createSelector` semantics).
|
|
359
406
|
*/
|
|
360
|
-
declare function useSortable<T>(options: UseSortableOptions<T>): UseSortableResult;
|
|
407
|
+
export declare function useSortable<T>(options: UseSortableOptions<T>): UseSortableResult;
|
|
361
408
|
//#endregion
|
|
362
|
-
export {
|
|
409
|
+
export type { DragData, DragPreviewOptions, DropEdge, DropLocation, FileRejectReason, UseDragMonitorOptions, UseDragMonitorResult, UseDraggableOptions, UseDraggableResult, UseDroppableOptions, UseDroppableResult, UseFileDropOptions, UseFileDropResult, UseSortableOptions, UseSortableResult };
|