@pyreon/dnd 0.11.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present Vit Bokisch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # @pyreon/dnd
2
+
3
+ Signal-driven drag and drop for the Pyreon framework. Wraps [@atlaskit/pragmatic-drag-and-drop](https://github.com/atlassian/pragmatic-drag-and-drop) with reactive signal state.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ bun add @pyreon/dnd
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - 5 hooks covering all drag-and-drop use cases
14
+ - Signal-driven state (isDragging, isOver, activeId, etc.)
15
+ - Auto-scroll when dragging near container edges
16
+ - Closest-edge detection for precise drop indicators
17
+ - Keyboard accessibility (Alt+Arrow to reorder)
18
+ - File drop with MIME type and count filtering
19
+ - Global drag monitoring for overlays and analytics
20
+
21
+ ## Hooks
22
+
23
+ ### useDraggable
24
+
25
+ Make an element draggable with reactive state.
26
+
27
+ ```tsx
28
+ const { isDragging } = useDraggable({
29
+ element: () => cardEl,
30
+ data: { id: card.id, type: "card" },
31
+ handle: () => handleEl, // optional drag handle
32
+ disabled: () => locked(), // reactive disable
33
+ })
34
+
35
+ <div ref={(el) => cardEl = el} class={isDragging() ? "opacity-50" : ""}>
36
+ <div ref={(el) => handleEl = el}>⠿</div>
37
+ {card.title}
38
+ </div>
39
+ ```
40
+
41
+ ### useDroppable
42
+
43
+ Make an element a drop target with filtering.
44
+
45
+ ```tsx
46
+ const { isOver } = useDroppable({
47
+ element: () => zoneEl,
48
+ canDrop: (data) => data.type === "card",
49
+ onDrop: (data) => addCard(data.id),
50
+ onDragEnter: () => highlight(),
51
+ onDragLeave: () => unhighlight(),
52
+ })
53
+
54
+ <div ref={(el) => zoneEl = el} class={isOver() ? "bg-blue-50" : ""}>
55
+ Drop here
56
+ </div>
57
+ ```
58
+
59
+ ### useSortable
60
+
61
+ Full-featured sortable list with edge detection and keyboard support.
62
+
63
+ ```tsx
64
+ const { containerRef, itemRef, activeId, overId, overEdge } = useSortable({
65
+ items: columns,
66
+ by: (col) => col.id,
67
+ onReorder: (newItems) => columns.set(newItems),
68
+ axis: "vertical", // or "horizontal"
69
+ })
70
+
71
+ <ul ref={containerRef}>
72
+ <For each={columns()} by={c => c.id}>
73
+ {col => (
74
+ <li
75
+ ref={itemRef(col.id)}
76
+ class={activeId() === col.id ? "dragging" : ""}
77
+ style={overId() === col.id && overEdge() === "top" ? "border-top: 2px solid blue" : ""}
78
+ >
79
+ {col.name}
80
+ </li>
81
+ )}
82
+ </For>
83
+ </ul>
84
+ ```
85
+
86
+ Features:
87
+ - Auto-scroll when dragging near container edges
88
+ - `overEdge` signal shows "top"/"bottom" (vertical) or "left"/"right" (horizontal)
89
+ - Keyboard reordering with Alt+Arrow keys
90
+ - Accessible: `role="listitem"`, `aria-roledescription`, `tabindex`
91
+
92
+ ### useFileDrop
93
+
94
+ Native file drag-and-drop with filtering.
95
+
96
+ ```tsx
97
+ const { isOver, isDraggingFiles } = useFileDrop({
98
+ element: () => dropZone,
99
+ accept: ["image/*", ".pdf"],
100
+ maxFiles: 5,
101
+ onDrop: (files) => upload(files),
102
+ disabled: () => uploading(),
103
+ })
104
+
105
+ <div
106
+ ref={(el) => dropZone = el}
107
+ class={isOver() ? "drop-active" : isDraggingFiles() ? "drop-ready" : ""}
108
+ >
109
+ {isDraggingFiles() ? "Drop files here" : "Drag files to upload"}
110
+ </div>
111
+ ```
112
+
113
+ ### useDragMonitor
114
+
115
+ Global drag state tracking for overlays and coordination.
116
+
117
+ ```tsx
118
+ const { isDragging, dragData } = useDragMonitor({
119
+ canMonitor: (data) => data.type === "card",
120
+ onDragStart: (data) => showOverlay(),
121
+ onDrop: (source, target) => logAnalytics(source, target),
122
+ })
123
+
124
+ <Show when={isDragging()}>
125
+ <div class="global-drag-overlay">
126
+ Dragging: {() => dragData()?.name}
127
+ </div>
128
+ </Show>
129
+ ```
130
+
131
+ ## License
132
+
133
+ MIT