@octane-xplat/dnd-kit 0.0.1 → 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 +21 -0
- package/README.md +306 -2
- package/dist/native/components.js +275 -0
- package/dist/native/controller.js +236 -0
- package/dist/native/geometry.js +18 -0
- package/dist/native/index.js +4 -0
- package/dist/native/octane-client-build.json +8 -0
- package/dist/native/sort.js +11 -0
- package/dist/web/components.js +215 -0
- package/dist/web/controller.js +236 -0
- package/dist/web/geometry.web.js +16 -0
- package/dist/web/index.js +4 -0
- package/dist/web/octane-client-build.json +8 -0
- package/dist/web/sort.js +11 -0
- package/examples/sortable.macos.tsx +128 -0
- package/examples/sortable.tsx +22 -0
- package/package.json +83 -3
- package/src/abort.macos.ts +7 -0
- package/src/components.tsx +262 -0
- package/src/components.web.test.tsx +118 -0
- package/src/controller.mobile.test.ts +176 -0
- package/src/controller.ts +301 -0
- package/src/geometry.macos.test.ts +34 -0
- package/src/geometry.macos.ts +32 -0
- package/src/geometry.ts +18 -0
- package/src/geometry.web.ts +14 -0
- package/src/index.macos.ts +23 -0
- package/src/index.ts +21 -0
- package/src/index.web.ts +21 -0
- package/src/props.ts +83 -0
- package/src/sort.ts +19 -0
- package/types/generated/.tsrx-typegen-manifest.json +11 -0
- package/types/generated/components.d.ts +13 -0
- package/types/generated/controller.d.ts +32 -0
- package/types/generated/geometry.web.d.ts +3 -0
- package/types/generated/index.d.ts +5 -0
- package/types/generated/props.d.ts +84 -0
- package/types/generated/sort.d.ts +2 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { measure } from "./geometry.js";
|
|
2
|
+
import { DragDropManager, Draggable, Droppable, Sensor } from "@dnd-kit/abstract";
|
|
3
|
+
import { defaultCollisionDetection } from "@dnd-kit/collision";
|
|
4
|
+
import { batch, effect, signal, untracked } from "@dnd-kit/state";
|
|
5
|
+
//#region src/controller.ts
|
|
6
|
+
var PanDraggable = class extends Draggable {
|
|
7
|
+
onPan;
|
|
8
|
+
};
|
|
9
|
+
/** Xplat View supplies normalized pan input; the abstract core owns the drag lifecycle. */
|
|
10
|
+
var PanSensor = class extends Sensor {
|
|
11
|
+
bind(input) {
|
|
12
|
+
const source = input;
|
|
13
|
+
let origin = null;
|
|
14
|
+
let bound = true;
|
|
15
|
+
let base = {
|
|
16
|
+
x: 0,
|
|
17
|
+
y: 0
|
|
18
|
+
};
|
|
19
|
+
let queue = Promise.resolve();
|
|
20
|
+
const handle = async (event) => {
|
|
21
|
+
const manager = this.manager;
|
|
22
|
+
if (!bound) return;
|
|
23
|
+
if (event.state === "began") {
|
|
24
|
+
if (source.disabled || !manager.dragOperation.status.idle) return;
|
|
25
|
+
origin = measure(manager.draggableNodes.get(source.id));
|
|
26
|
+
if (!origin) return;
|
|
27
|
+
base = {
|
|
28
|
+
x: event.dx,
|
|
29
|
+
y: event.dy
|
|
30
|
+
};
|
|
31
|
+
manager.scrollShift$.value = {
|
|
32
|
+
x: 0,
|
|
33
|
+
y: 0
|
|
34
|
+
};
|
|
35
|
+
manager.actions.start({
|
|
36
|
+
source,
|
|
37
|
+
coordinates: origin.center
|
|
38
|
+
});
|
|
39
|
+
manager.dragOperation.shape = origin;
|
|
40
|
+
manager.refresh();
|
|
41
|
+
await manager.renderer.rendering;
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (!origin || manager.dragOperation.source?.id !== source.id || !manager.dragOperation.status.dragging) return;
|
|
45
|
+
const x = event.dx - base.x;
|
|
46
|
+
const y = event.dy - base.y;
|
|
47
|
+
manager.actions.move({ to: {
|
|
48
|
+
x: origin.center.x + x,
|
|
49
|
+
y: origin.center.y + y
|
|
50
|
+
} });
|
|
51
|
+
await Promise.resolve();
|
|
52
|
+
manager.dragOperation.shape = origin.translate(x, y);
|
|
53
|
+
manager.refresh();
|
|
54
|
+
if (event.state === "ended" || event.state === "cancelled") {
|
|
55
|
+
manager.actions.stop({ canceled: event.state === "cancelled" });
|
|
56
|
+
origin = null;
|
|
57
|
+
} else manager.startAutoScroll();
|
|
58
|
+
};
|
|
59
|
+
source.onPan = (event) => {
|
|
60
|
+
queue = queue.then(() => handle(event)).catch((error) => {
|
|
61
|
+
origin = null;
|
|
62
|
+
this.manager.cancel();
|
|
63
|
+
console.error("[dnd-kit] pan failed", error);
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
return () => {
|
|
67
|
+
bound = false;
|
|
68
|
+
source.onPan = void 0;
|
|
69
|
+
origin = null;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/** One controller per DndContext; no global registry or cross-root context assumptions. */
|
|
74
|
+
var DndController = class extends DragDropManager {
|
|
75
|
+
options = {};
|
|
76
|
+
draggableNodes = /* @__PURE__ */ new Map();
|
|
77
|
+
droppableNodes = /* @__PURE__ */ new Map();
|
|
78
|
+
scrollShift$ = signal({
|
|
79
|
+
x: 0,
|
|
80
|
+
y: 0
|
|
81
|
+
});
|
|
82
|
+
listeners = /* @__PURE__ */ new Set();
|
|
83
|
+
snapshot = {
|
|
84
|
+
active: null,
|
|
85
|
+
over: null,
|
|
86
|
+
transform: {
|
|
87
|
+
x: 0,
|
|
88
|
+
y: 0
|
|
89
|
+
},
|
|
90
|
+
isDragging: false
|
|
91
|
+
};
|
|
92
|
+
dispose;
|
|
93
|
+
scrollTimer;
|
|
94
|
+
destroyed = false;
|
|
95
|
+
constructor() {
|
|
96
|
+
super({ sensors: [PanSensor] });
|
|
97
|
+
this.dispose = effect(() => {
|
|
98
|
+
const operation = this.dragOperation;
|
|
99
|
+
const active = operation.source;
|
|
100
|
+
const over = operation.target;
|
|
101
|
+
const transform = operation.transform;
|
|
102
|
+
const isDragging = operation.status.dragging;
|
|
103
|
+
this.snapshot = {
|
|
104
|
+
active: active && !operation.status.idle ? {
|
|
105
|
+
id: active.id,
|
|
106
|
+
data: active.data
|
|
107
|
+
} : null,
|
|
108
|
+
over: over && !operation.status.idle ? {
|
|
109
|
+
id: over.id,
|
|
110
|
+
data: over.data
|
|
111
|
+
} : null,
|
|
112
|
+
transform: {
|
|
113
|
+
x: operation.status.idle ? 0 : transform.x + this.scrollShift$.value.x,
|
|
114
|
+
y: operation.status.idle ? 0 : transform.y + this.scrollShift$.value.y
|
|
115
|
+
},
|
|
116
|
+
isDragging
|
|
117
|
+
};
|
|
118
|
+
untracked(() => {
|
|
119
|
+
for (const listener of this.listeners) listener();
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
const event = (canceled = false) => {
|
|
123
|
+
const operation = this.dragOperation;
|
|
124
|
+
return {
|
|
125
|
+
active: operation.source ? {
|
|
126
|
+
id: operation.source.id,
|
|
127
|
+
data: operation.source.data
|
|
128
|
+
} : null,
|
|
129
|
+
over: operation.target ? {
|
|
130
|
+
id: operation.target.id,
|
|
131
|
+
data: operation.target.data
|
|
132
|
+
} : null,
|
|
133
|
+
transform: { ...operation.transform },
|
|
134
|
+
isDragging: operation.status.dragging,
|
|
135
|
+
canceled
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
this.monitor.addEventListener("dragstart", () => this.options.onDragStart?.(event()));
|
|
139
|
+
this.monitor.addEventListener("dragover", () => this.options.onDragOver?.(event()));
|
|
140
|
+
this.monitor.addEventListener("dragmove", () => queueMicrotask(() => queueMicrotask(() => {
|
|
141
|
+
if (!this.destroyed && this.dragOperation.status.dragging) this.options.onDragMove?.(event());
|
|
142
|
+
})));
|
|
143
|
+
this.monitor.addEventListener("dragend", ({ canceled }) => {
|
|
144
|
+
this.stopAutoScroll();
|
|
145
|
+
if (canceled) this.options.onDragCancel?.(event(true));
|
|
146
|
+
else this.options.onDragEnd?.(event());
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
getSnapshot = () => this.snapshot;
|
|
150
|
+
subscribe = (listener) => {
|
|
151
|
+
this.listeners.add(listener);
|
|
152
|
+
return () => {
|
|
153
|
+
this.listeners.delete(listener);
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
registerDraggable(options) {
|
|
157
|
+
if (this.registry.draggables.has(options.id)) throw new Error(`Duplicate draggable id: ${options.id}`);
|
|
158
|
+
const source = new PanDraggable({
|
|
159
|
+
...options,
|
|
160
|
+
register: false,
|
|
161
|
+
effects: () => [() => this.registry.sensors.get(PanSensor).bind(source)]
|
|
162
|
+
}, this);
|
|
163
|
+
source.register();
|
|
164
|
+
return source;
|
|
165
|
+
}
|
|
166
|
+
registerDroppable(options) {
|
|
167
|
+
if (this.registry.droppables.has(options.id)) throw new Error(`Duplicate droppable id: ${options.id}`);
|
|
168
|
+
const target = new Droppable({
|
|
169
|
+
...options,
|
|
170
|
+
register: false,
|
|
171
|
+
accept: options.accept ? (source) => options.accept({
|
|
172
|
+
id: source.id,
|
|
173
|
+
data: source.data
|
|
174
|
+
}) : void 0,
|
|
175
|
+
collisionDetector: (input) => input.dragOperation.source?.id === input.droppable.id ? null : (this.options.collisionDetection ?? defaultCollisionDetection)(input)
|
|
176
|
+
}, this);
|
|
177
|
+
target.register();
|
|
178
|
+
return target;
|
|
179
|
+
}
|
|
180
|
+
refresh() {
|
|
181
|
+
batch(() => {
|
|
182
|
+
for (const droppable of this.registry.droppables) droppable.shape = measure(this.droppableNodes.get(droppable.id)) ?? void 0;
|
|
183
|
+
});
|
|
184
|
+
this.collisionObserver.forceUpdate();
|
|
185
|
+
}
|
|
186
|
+
cancel() {
|
|
187
|
+
this.stopAutoScroll();
|
|
188
|
+
this.actions.stop({ canceled: true });
|
|
189
|
+
}
|
|
190
|
+
startAutoScroll() {
|
|
191
|
+
if (this.scrollTimer || !this.options.autoScroll) return;
|
|
192
|
+
this.scrollTimer = setInterval(() => {
|
|
193
|
+
const scroll = this.options.autoScroll;
|
|
194
|
+
if (!scroll || !this.dragOperation.status.dragging) {
|
|
195
|
+
this.stopAutoScroll();
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const bounds = scroll.bounds();
|
|
199
|
+
if (!bounds) return;
|
|
200
|
+
const horizontal = scroll.axis === "x";
|
|
201
|
+
const start = horizontal ? bounds.x : bounds.y;
|
|
202
|
+
const size = horizontal ? bounds.width : bounds.height;
|
|
203
|
+
const point = horizontal ? this.dragOperation.position.current.x : this.dragOperation.position.current.y;
|
|
204
|
+
const threshold = Math.min(scroll.threshold ?? 40, size / 2);
|
|
205
|
+
if (threshold <= 0 || point < start || point > start + size) return;
|
|
206
|
+
const strength = point < start + threshold ? -(1 - (point - start) / threshold) : point > start + size - threshold ? 1 - (start + size - point) / threshold : 0;
|
|
207
|
+
const next = Math.max(0, Math.min(scroll.maxOffset(), scroll.offsetRef.current + strength * (scroll.speed ?? 12)));
|
|
208
|
+
if (next !== scroll.offsetRef.current) {
|
|
209
|
+
const before = scroll.offsetRef.current;
|
|
210
|
+
scroll.scrollTo(next);
|
|
211
|
+
const delta = scroll.offsetRef.current - before;
|
|
212
|
+
const shift = this.scrollShift$.peek();
|
|
213
|
+
this.scrollShift$.value = {
|
|
214
|
+
x: shift.x + (horizontal ? delta : 0),
|
|
215
|
+
y: shift.y + (horizontal ? 0 : delta)
|
|
216
|
+
};
|
|
217
|
+
this.refresh();
|
|
218
|
+
}
|
|
219
|
+
}, 16);
|
|
220
|
+
}
|
|
221
|
+
stopAutoScroll() {
|
|
222
|
+
if (this.scrollTimer) clearInterval(this.scrollTimer);
|
|
223
|
+
this.scrollTimer = void 0;
|
|
224
|
+
}
|
|
225
|
+
disposeController() {
|
|
226
|
+
this.destroyed = true;
|
|
227
|
+
this.cancel();
|
|
228
|
+
this.dispose();
|
|
229
|
+
this.listeners.clear();
|
|
230
|
+
this.draggableNodes.clear();
|
|
231
|
+
this.droppableNodes.clear();
|
|
232
|
+
this.destroy();
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
//#endregion
|
|
236
|
+
export { DndController };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Rectangle } from "@dnd-kit/geometry";
|
|
2
|
+
//#region src/geometry.ts
|
|
3
|
+
/** NativeScript screen coordinates and dimensions are in DIPs. */
|
|
4
|
+
function measure(element) {
|
|
5
|
+
if (!element || element.isLoaded === false) return null;
|
|
6
|
+
const point = element.getLocationOnScreen?.();
|
|
7
|
+
const size = element.getActualSize?.();
|
|
8
|
+
return point && size && size.width > 0 && size.height > 0 ? new Rectangle(point.x, point.y, size.width, size.height) : null;
|
|
9
|
+
}
|
|
10
|
+
function dragStyle(x, y) {
|
|
11
|
+
return {
|
|
12
|
+
translateX: x,
|
|
13
|
+
translateY: y,
|
|
14
|
+
zIndex: x || y ? 1 : 0
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { dragStyle, measure };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { arrayMove } from "./sort.js";
|
|
2
|
+
import { DndContext, SortableContext, SortableList, useDndContext, useDraggable, useDroppable, useSortable } from "./components.js";
|
|
3
|
+
import { closestCenter, closestCorners, defaultCollisionDetection, pointerIntersection, shapeIntersection } from "@dnd-kit/collision";
|
|
4
|
+
export { DndContext, SortableContext, SortableList, arrayMove, closestCenter, closestCorners, defaultCollisionDetection, pointerIntersection, shapeIntersection, useDndContext, useDraggable, useDroppable, useSortable };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/sort.ts
|
|
2
|
+
/** Return a new order. Invalid indices leave the order unchanged. */
|
|
3
|
+
function arrayMove(items, from, to) {
|
|
4
|
+
const result = [...items];
|
|
5
|
+
if (!Number.isInteger(from) || !Number.isInteger(to) || from < 0 || to < 0 || from >= items.length || to >= items.length || from === to) return result;
|
|
6
|
+
const [item] = result.splice(from, 1);
|
|
7
|
+
result.splice(to, 0, item);
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { arrayMove };
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { dragStyle } from "./geometry.web.js";
|
|
2
|
+
import { DndController } from "./controller.js";
|
|
3
|
+
import { arrayMove } from "./sort.js";
|
|
4
|
+
import { createContext, createScopedElement, createScopedValue, hookSlots, useContext, useEffect, useRef, useSyncExternalStore, withSlot } from "octane";
|
|
5
|
+
import { createElementFromConfig, deferRecord, isRenderCall, memoPublish, memoSlot, memoTake0, memoTake2, memoTake3 } from "octane/internal/client";
|
|
6
|
+
import { View, useMeasure } from "@octane-xplat/ui";
|
|
7
|
+
//#region src/components.tsx
|
|
8
|
+
var _hs$ = /* @__PURE__ */ hookSlots(27);
|
|
9
|
+
var _h$0 = /* @__PURE__ */ Symbol(_hs$);
|
|
10
|
+
var _h$1 = /* @__PURE__ */ Symbol(_hs$ + 1);
|
|
11
|
+
var _h$2 = /* @__PURE__ */ Symbol(_hs$ + 2);
|
|
12
|
+
var _h$3 = /* @__PURE__ */ Symbol(_hs$ + 3);
|
|
13
|
+
var _h$4 = /* @__PURE__ */ Symbol(_hs$ + 4);
|
|
14
|
+
var _h$5 = /* @__PURE__ */ Symbol(_hs$ + 5);
|
|
15
|
+
var _h$6 = /* @__PURE__ */ Symbol(_hs$ + 6);
|
|
16
|
+
var _h$7 = /* @__PURE__ */ Symbol(_hs$ + 7);
|
|
17
|
+
var _h$8 = /* @__PURE__ */ Symbol(_hs$ + 8);
|
|
18
|
+
var _h$9 = /* @__PURE__ */ Symbol(_hs$ + 9);
|
|
19
|
+
var _h$10 = /* @__PURE__ */ Symbol(_hs$ + 10);
|
|
20
|
+
var _h$11 = /* @__PURE__ */ Symbol(_hs$ + 11);
|
|
21
|
+
var _h$12 = /* @__PURE__ */ Symbol(_hs$ + 12);
|
|
22
|
+
var _h$13 = /* @__PURE__ */ Symbol(_hs$ + 13);
|
|
23
|
+
var _h$14 = /* @__PURE__ */ Symbol(_hs$ + 14);
|
|
24
|
+
var _h$15 = /* @__PURE__ */ Symbol(_hs$ + 15);
|
|
25
|
+
var _h$16 = /* @__PURE__ */ Symbol(_hs$ + 16);
|
|
26
|
+
var _h$17 = /* @__PURE__ */ Symbol(_hs$ + 17);
|
|
27
|
+
var _h$18 = /* @__PURE__ */ Symbol(_hs$ + 18);
|
|
28
|
+
var _h$19 = /* @__PURE__ */ Symbol(_hs$ + 19);
|
|
29
|
+
var _h$20 = /* @__PURE__ */ Symbol(_hs$ + 20);
|
|
30
|
+
var _h$21 = /* @__PURE__ */ Symbol(_hs$ + 21);
|
|
31
|
+
var _h$22 = /* @__PURE__ */ Symbol(_hs$ + 22);
|
|
32
|
+
function SortableContext$record(props) {
|
|
33
|
+
return createScopedElement(SortContextProvider, { value: props.items }, () => props.children, "c:a77cf23e");
|
|
34
|
+
}
|
|
35
|
+
var _h$23 = /* @__PURE__ */ Symbol(_hs$ + 23);
|
|
36
|
+
var _h$24 = /* @__PURE__ */ Symbol(_hs$ + 24);
|
|
37
|
+
var _h$25 = /* @__PURE__ */ Symbol(_hs$ + 25);
|
|
38
|
+
var _h$26 = /* @__PURE__ */ Symbol(_hs$ + 26);
|
|
39
|
+
function SortableRow$record(props, sortable) {
|
|
40
|
+
return createScopedElement(View, {
|
|
41
|
+
ref: sortable.ref,
|
|
42
|
+
onPan: sortable.onPan,
|
|
43
|
+
style: sortable.style
|
|
44
|
+
}, () => props.list.renderItem(props.id, props.index), "c:8c6475d9");
|
|
45
|
+
}
|
|
46
|
+
function SortableList$record(dnd, items, onReorder, props, viewProps) {
|
|
47
|
+
return createScopedElement(DndContext, {
|
|
48
|
+
...dnd,
|
|
49
|
+
onDragEnd: (event) => {
|
|
50
|
+
if (event.active && event.over) {
|
|
51
|
+
const from = items.findIndex((id) => id === event.active.id);
|
|
52
|
+
const to = items.findIndex((id) => id === event.over.id);
|
|
53
|
+
if (from >= 0 && to >= 0 && from !== to) onReorder(arrayMove(items, from, to), event);
|
|
54
|
+
}
|
|
55
|
+
dnd?.onDragEnd?.(event);
|
|
56
|
+
}
|
|
57
|
+
}, () => createScopedValue(() => createScopedElement(SortableContext, { items }, () => createScopedValue(() => createScopedElement(View, { ...viewProps }, () => items.map((id, index) => createElementFromConfig("c:77195ea5", SortableRow, {
|
|
58
|
+
key: id,
|
|
59
|
+
id,
|
|
60
|
+
index,
|
|
61
|
+
list: props
|
|
62
|
+
})), "c:f6688f5f")), "c:75c97215")), "c:ad5a2f41");
|
|
63
|
+
}
|
|
64
|
+
var Context = /* @__PURE__ */ createContext(null);
|
|
65
|
+
var ContextProvider = Context;
|
|
66
|
+
var SortContext = /* @__PURE__ */ createContext(null);
|
|
67
|
+
var SortContextProvider = SortContext;
|
|
68
|
+
function DndContext(props) {
|
|
69
|
+
const ref = useRef(null, _h$0);
|
|
70
|
+
if (!ref.current) ref.current = new DndController();
|
|
71
|
+
const controller = ref.current;
|
|
72
|
+
controller.options = props;
|
|
73
|
+
useEffect(() => () => controller.disposeController(), [controller], _h$1);
|
|
74
|
+
return createScopedElement(ContextProvider, { value: controller }, () => props.children, "c:2162dbab");
|
|
75
|
+
}
|
|
76
|
+
function useController() {
|
|
77
|
+
const controller = useContext(Context);
|
|
78
|
+
if (!controller) throw new Error("Drag and drop hooks require DndContext");
|
|
79
|
+
return controller;
|
|
80
|
+
}
|
|
81
|
+
function useDndContext() {
|
|
82
|
+
const controller = withSlot(_h$2, useController);
|
|
83
|
+
return useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot, _h$3);
|
|
84
|
+
}
|
|
85
|
+
function useDraggable(options) {
|
|
86
|
+
let __hks, __hkd0, __hkd1, __hkd2, __hke, __hks$, __hke$;
|
|
87
|
+
const controller = withSlot(_h$4, useController);
|
|
88
|
+
const snapshot = withSlot(_h$5, useDndContext);
|
|
89
|
+
const entity = useRef(null, _h$6);
|
|
90
|
+
const node = useRef(null, _h$7);
|
|
91
|
+
const latest = useRef(options, _h$8);
|
|
92
|
+
latest.current = options;
|
|
93
|
+
const measurement = withSlot(_h$9, useMeasure);
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
const registered = controller.registerDraggable(latest.current);
|
|
96
|
+
entity.current = registered;
|
|
97
|
+
if (node.current) controller.draggableNodes.set(options.id, node.current);
|
|
98
|
+
return () => {
|
|
99
|
+
if (controller.getSnapshot().active?.id === options.id) controller.cancel();
|
|
100
|
+
registered.destroy();
|
|
101
|
+
entity.current = null;
|
|
102
|
+
controller.draggableNodes.delete(options.id);
|
|
103
|
+
};
|
|
104
|
+
}, [controller, options.id], _h$10);
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (!entity.current) return;
|
|
107
|
+
entity.current.data = options.data ?? {};
|
|
108
|
+
entity.current.disabled = options.disabled ?? false;
|
|
109
|
+
if (options.disabled && controller.getSnapshot().active?.id === options.id) controller.cancel();
|
|
110
|
+
}, [
|
|
111
|
+
controller,
|
|
112
|
+
options.id,
|
|
113
|
+
options.data,
|
|
114
|
+
options.disabled
|
|
115
|
+
], _h$11);
|
|
116
|
+
const ref = (__hkd0 = controller, __hkd1 = options.id, __hkd2 = measurement.ref, __hks = memoSlot(_h$12, "useCallback"), __hke = memoTake3(__hks, __hkd0, __hkd1, __hkd2), __hke === null ? memoPublish(__hks, (element) => {
|
|
117
|
+
node.current = element;
|
|
118
|
+
measurement.ref(element);
|
|
119
|
+
if (element) controller.draggableNodes.set(options.id, element);
|
|
120
|
+
else controller.draggableNodes.delete(options.id);
|
|
121
|
+
}, __hkd0, __hkd1, __hkd2) : __hke.value);
|
|
122
|
+
const onPan = (__hks$ = memoSlot(_h$13, "useCallback"), __hke$ = memoTake0(__hks$), __hke$ === null ? memoPublish(__hks$, (event) => entity.current?.onPan?.(event)) : __hke$.value);
|
|
123
|
+
const isDragging = snapshot.isDragging && snapshot.active?.id === options.id;
|
|
124
|
+
const transform = isDragging ? snapshot.transform : {
|
|
125
|
+
x: 0,
|
|
126
|
+
y: 0
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
ref,
|
|
130
|
+
onPan,
|
|
131
|
+
isDragging,
|
|
132
|
+
transform,
|
|
133
|
+
style: dragStyle(transform.x, transform.y)
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function useDroppable(options) {
|
|
137
|
+
let __hks$2, __hkd0$, __hkd1$, __hkd2$, __hke$2;
|
|
138
|
+
const controller = withSlot(_h$14, useController);
|
|
139
|
+
const snapshot = withSlot(_h$15, useDndContext);
|
|
140
|
+
const entity = useRef(null, _h$16);
|
|
141
|
+
const node = useRef(null, _h$17);
|
|
142
|
+
const latest = useRef(options, _h$18);
|
|
143
|
+
latest.current = options;
|
|
144
|
+
const measurement = withSlot(_h$19, useMeasure);
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
const registered = controller.registerDroppable(latest.current);
|
|
147
|
+
entity.current = registered;
|
|
148
|
+
if (node.current) controller.droppableNodes.set(options.id, node.current);
|
|
149
|
+
controller.refresh();
|
|
150
|
+
return () => {
|
|
151
|
+
registered.destroy();
|
|
152
|
+
entity.current = null;
|
|
153
|
+
controller.droppableNodes.delete(options.id);
|
|
154
|
+
controller.refresh();
|
|
155
|
+
};
|
|
156
|
+
}, [controller, options.id], _h$20);
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
if (!entity.current) return;
|
|
159
|
+
entity.current.data = options.data ?? {};
|
|
160
|
+
entity.current.disabled = options.disabled ?? false;
|
|
161
|
+
entity.current.accept = options.accept ? (source) => options.accept({
|
|
162
|
+
id: source.id,
|
|
163
|
+
data: source.data
|
|
164
|
+
}) : void 0;
|
|
165
|
+
controller.refresh();
|
|
166
|
+
}, [
|
|
167
|
+
controller,
|
|
168
|
+
options.data,
|
|
169
|
+
options.disabled,
|
|
170
|
+
options.accept,
|
|
171
|
+
controller.options.collisionDetection,
|
|
172
|
+
measurement.bounds
|
|
173
|
+
], _h$21);
|
|
174
|
+
return {
|
|
175
|
+
ref: (__hkd0$ = controller, __hkd1$ = options.id, __hkd2$ = measurement.ref, __hks$2 = memoSlot(_h$22, "useCallback"), __hke$2 = memoTake3(__hks$2, __hkd0$, __hkd1$, __hkd2$), __hke$2 === null ? memoPublish(__hks$2, (element) => {
|
|
176
|
+
node.current = element;
|
|
177
|
+
measurement.ref(element);
|
|
178
|
+
if (element) controller.droppableNodes.set(options.id, element);
|
|
179
|
+
else controller.droppableNodes.delete(options.id);
|
|
180
|
+
}, __hkd0$, __hkd1$, __hkd2$) : __hke$2.value),
|
|
181
|
+
isOver: snapshot.isDragging && snapshot.over?.id === options.id
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function SortableContext(props, __renderScope = void 0) {
|
|
185
|
+
if (new Set(props.items).size !== props.items.length) throw new Error("SortableContext requires unique item ids");
|
|
186
|
+
return isRenderCall(__renderScope) ? SortableContext$record(props) : deferRecord(SortableContext$record, props);
|
|
187
|
+
}
|
|
188
|
+
function useSortable(options) {
|
|
189
|
+
let __hks$3, __hkd0$2, __hkd1$2, __hke$3;
|
|
190
|
+
if (!useContext(SortContext)?.includes(options.id)) throw new Error("useSortable requires membership in SortableContext");
|
|
191
|
+
const drag = withSlot(_h$23, useDraggable, options);
|
|
192
|
+
const drop = withSlot(_h$24, useDroppable, options);
|
|
193
|
+
const ref = (__hkd0$2 = drag.ref, __hkd1$2 = drop.ref, __hks$3 = memoSlot(_h$25, "useCallback"), __hke$3 = memoTake2(__hks$3, __hkd0$2, __hkd1$2), __hke$3 === null ? memoPublish(__hks$3, (element) => {
|
|
194
|
+
drag.ref(element);
|
|
195
|
+
drop.ref(element);
|
|
196
|
+
}, __hkd0$2, __hkd1$2) : __hke$3.value);
|
|
197
|
+
return {
|
|
198
|
+
...drag,
|
|
199
|
+
ref,
|
|
200
|
+
isOver: drop.isOver
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function SortableRow(props, __renderScope$ = void 0) {
|
|
204
|
+
const sortable = withSlot(_h$26, useSortable, {
|
|
205
|
+
id: props.id,
|
|
206
|
+
disabled: props.list.disabled
|
|
207
|
+
});
|
|
208
|
+
return isRenderCall(__renderScope$) ? SortableRow$record(props, sortable) : deferRecord(SortableRow$record, props, sortable);
|
|
209
|
+
}
|
|
210
|
+
function SortableList(props, __renderScope$2 = void 0) {
|
|
211
|
+
const { items, renderItem: _renderItem, onReorder, disabled: _disabled, dnd, ...viewProps } = props;
|
|
212
|
+
return isRenderCall(__renderScope$2) ? SortableList$record(dnd, items, onReorder, props, viewProps) : deferRecord(SortableList$record, dnd, items, onReorder, props, viewProps);
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
export { DndContext, SortableContext, SortableList, useDndContext, useDraggable, useDroppable, useSortable };
|