@dnd-kit/vue 0.2.3
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 +17 -0
- package/composables.cjs +73 -0
- package/composables.d.ts +6 -0
- package/composables.js +46 -0
- package/index.cjs +402 -0
- package/index.d.ts +76 -0
- package/index.js +377 -0
- package/package.json +78 -0
- package/sortable.cjs +112 -0
- package/sortable.d.ts +26 -0
- package/sortable.js +90 -0
- package/utilities.cjs +70 -0
- package/utilities.d.ts +15 -0
- package/utilities.js +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @dnd-kit/vue
|
|
2
|
+
|
|
3
|
+
[](https://npm.im/@dnd-kit/vue)
|
|
4
|
+
|
|
5
|
+
The Vue layer for @dnd-kit, built on top of @dnd-kit/dom.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
To get started, install the `@dnd-kit/vue` package via npm or yarn:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm install @dnd-kit/vue
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Visit [docs.dndkit.com](https://docs.dndkit.com) to learn how to get started with @dnd-kit.
|
package/composables.cjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/composables/index.ts
|
|
21
|
+
var composables_exports = {};
|
|
22
|
+
__export(composables_exports, {
|
|
23
|
+
useDeepSignal: () => useDeepSignal
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(composables_exports);
|
|
26
|
+
|
|
27
|
+
// src/composables/useDeepSignal.ts
|
|
28
|
+
var import_state = require("@dnd-kit/state");
|
|
29
|
+
var import_vue = require("vue");
|
|
30
|
+
function useDeepSignal(target) {
|
|
31
|
+
const tracked = /* @__PURE__ */ new Map();
|
|
32
|
+
const dirty = (0, import_vue.ref)(0);
|
|
33
|
+
(0, import_vue.watchEffect)(() => {
|
|
34
|
+
const _target = (0, import_vue.toValue)(target);
|
|
35
|
+
if (!_target) {
|
|
36
|
+
tracked.clear();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
(0, import_vue.onWatcherCleanup)(
|
|
40
|
+
(0, import_state.effect)(() => {
|
|
41
|
+
let stale = false;
|
|
42
|
+
for (const entry of tracked) {
|
|
43
|
+
const [key] = entry;
|
|
44
|
+
const value = (0, import_state.untracked)(() => entry[1]);
|
|
45
|
+
const latestValue = _target[key];
|
|
46
|
+
if (value !== latestValue) {
|
|
47
|
+
stale = true;
|
|
48
|
+
tracked.set(key, latestValue);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (stale) {
|
|
52
|
+
dirty.value++;
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
return (0, import_vue.computed)(() => {
|
|
58
|
+
const _target = (0, import_vue.toValue)(target);
|
|
59
|
+
void dirty.value;
|
|
60
|
+
return _target ? new Proxy(_target, {
|
|
61
|
+
get(target2, key) {
|
|
62
|
+
const value = target2[key];
|
|
63
|
+
tracked.set(key, value);
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
}) : _target;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
+
0 && (module.exports = {
|
|
71
|
+
useDeepSignal
|
|
72
|
+
});
|
|
73
|
+
//# sourceMappingURL=composables.cjs.map
|
package/composables.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MaybeRefOrGetter, ComputedRef } from 'vue';
|
|
2
|
+
|
|
3
|
+
/** Trigger a recompute when reading signal properties of an object. */
|
|
4
|
+
declare function useDeepSignal<T extends object | null | undefined>(target: MaybeRefOrGetter<T>): ComputedRef<T>;
|
|
5
|
+
|
|
6
|
+
export { useDeepSignal };
|
package/composables.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/composables/useDeepSignal.ts
|
|
2
|
+
import { effect, untracked } from "@dnd-kit/state";
|
|
3
|
+
import { computed, onWatcherCleanup, ref, toValue, watchEffect } from "vue";
|
|
4
|
+
function useDeepSignal(target) {
|
|
5
|
+
const tracked = /* @__PURE__ */ new Map();
|
|
6
|
+
const dirty = ref(0);
|
|
7
|
+
watchEffect(() => {
|
|
8
|
+
const _target = toValue(target);
|
|
9
|
+
if (!_target) {
|
|
10
|
+
tracked.clear();
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
onWatcherCleanup(
|
|
14
|
+
effect(() => {
|
|
15
|
+
let stale = false;
|
|
16
|
+
for (const entry of tracked) {
|
|
17
|
+
const [key] = entry;
|
|
18
|
+
const value = untracked(() => entry[1]);
|
|
19
|
+
const latestValue = _target[key];
|
|
20
|
+
if (value !== latestValue) {
|
|
21
|
+
stale = true;
|
|
22
|
+
tracked.set(key, latestValue);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (stale) {
|
|
26
|
+
dirty.value++;
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
return computed(() => {
|
|
32
|
+
const _target = toValue(target);
|
|
33
|
+
void dirty.value;
|
|
34
|
+
return _target ? new Proxy(_target, {
|
|
35
|
+
get(target2, key) {
|
|
36
|
+
const value = target2[key];
|
|
37
|
+
tracked.set(key, value);
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
}) : _target;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
useDeepSignal
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=composables.js.map
|
package/index.cjs
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/core/index.ts
|
|
21
|
+
var core_exports = {};
|
|
22
|
+
__export(core_exports, {
|
|
23
|
+
DragDropProvider: () => DragDropProvider_default,
|
|
24
|
+
KeyboardSensor: () => import_dom5.KeyboardSensor,
|
|
25
|
+
PointerSensor: () => import_dom5.PointerSensor,
|
|
26
|
+
useDragDropManager: () => useDragDropManager,
|
|
27
|
+
useDragDropMonitor: () => useDragDropMonitor,
|
|
28
|
+
useDragOperation: () => useDragOperation,
|
|
29
|
+
useDraggable: () => useDraggable,
|
|
30
|
+
useDroppable: () => useDroppable,
|
|
31
|
+
useInstance: () => useInstance
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(core_exports);
|
|
34
|
+
|
|
35
|
+
// src/core/context/DragDropProvider.ts
|
|
36
|
+
var import_dom = require("@dnd-kit/dom");
|
|
37
|
+
var import_dom2 = require("@dnd-kit/dom");
|
|
38
|
+
var import_vue5 = require("vue");
|
|
39
|
+
|
|
40
|
+
// src/core/context/renderer.ts
|
|
41
|
+
var import_vue = require("vue");
|
|
42
|
+
function useRenderer() {
|
|
43
|
+
const transitionCount = (0, import_vue.ref)(0);
|
|
44
|
+
const rendering = (0, import_vue.ref)(null);
|
|
45
|
+
let resolver = null;
|
|
46
|
+
(0, import_vue.watch)(
|
|
47
|
+
transitionCount,
|
|
48
|
+
() => {
|
|
49
|
+
resolver?.();
|
|
50
|
+
rendering.value = null;
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
flush: "post"
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
const renderer = {
|
|
57
|
+
get rendering() {
|
|
58
|
+
return rendering.value ?? Promise.resolve();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
function trackRendering(callback) {
|
|
62
|
+
if (!rendering.value) {
|
|
63
|
+
rendering.value = new Promise((resolve) => {
|
|
64
|
+
resolver = resolve;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
callback();
|
|
68
|
+
(0, import_vue.nextTick)(() => {
|
|
69
|
+
transitionCount.value++;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
renderer,
|
|
74
|
+
trackRendering
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/utilities/context.ts
|
|
79
|
+
var import_vue2 = require("vue");
|
|
80
|
+
function createContext(componentName) {
|
|
81
|
+
const injectionKey = Symbol(
|
|
82
|
+
`${componentName}Context`
|
|
83
|
+
);
|
|
84
|
+
return [injectContext, provideContext];
|
|
85
|
+
function injectContext(fallback) {
|
|
86
|
+
const context = (0, import_vue2.inject)(injectionKey, fallback);
|
|
87
|
+
if (context) return context;
|
|
88
|
+
if (context === null) return context;
|
|
89
|
+
throw new Error(
|
|
90
|
+
`Injection \`${injectionKey.toString()}\` not found. Component must be used within \`${componentName}\``
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
function provideContext(contextValue) {
|
|
94
|
+
(0, import_vue2.provide)(injectionKey, contextValue);
|
|
95
|
+
return contextValue;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/utilities/element.ts
|
|
100
|
+
var import_vue3 = require("vue");
|
|
101
|
+
function unrefElement(elRef) {
|
|
102
|
+
const plain = (0, import_vue3.toValue)(elRef);
|
|
103
|
+
return plain?.$el ?? plain ?? void 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/utilities/ref.ts
|
|
107
|
+
var import_vue4 = require("vue");
|
|
108
|
+
function toValueDeep(input) {
|
|
109
|
+
return Object.fromEntries(
|
|
110
|
+
Object.entries(input).map(([key, value]) => [key, (0, import_vue4.toValue)(value)])
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/core/context/context.ts
|
|
115
|
+
var [injectDragDropContext, provideDragDropContext] = createContext("DragDropProvider");
|
|
116
|
+
|
|
117
|
+
// src/core/context/DragDropProvider.ts
|
|
118
|
+
var DragDropProvider_default = /* @__PURE__ */ (0, import_vue5.defineComponent)({
|
|
119
|
+
props: [
|
|
120
|
+
"manager",
|
|
121
|
+
"plugins",
|
|
122
|
+
"sensors",
|
|
123
|
+
"modifiers"
|
|
124
|
+
],
|
|
125
|
+
emits: [
|
|
126
|
+
"beforeDragStart",
|
|
127
|
+
"collision",
|
|
128
|
+
"dragStart",
|
|
129
|
+
"dragMove",
|
|
130
|
+
"dragOver",
|
|
131
|
+
"dragEnd"
|
|
132
|
+
],
|
|
133
|
+
setup(props, { emit, slots }) {
|
|
134
|
+
const { renderer, trackRendering } = useRenderer();
|
|
135
|
+
const manager = (0, import_vue5.shallowRef)(props.manager ?? new import_dom2.DragDropManager(props));
|
|
136
|
+
(0, import_vue5.watch)(
|
|
137
|
+
[() => props.manager],
|
|
138
|
+
() => {
|
|
139
|
+
const _manager = props.manager ?? new import_dom2.DragDropManager(props);
|
|
140
|
+
const cleanupFns = [];
|
|
141
|
+
_manager.renderer = renderer;
|
|
142
|
+
cleanupFns.push(
|
|
143
|
+
_manager.monitor.addEventListener(
|
|
144
|
+
"beforedragstart",
|
|
145
|
+
(event, manager2) => trackRendering(() => emit("beforeDragStart", event, manager2))
|
|
146
|
+
)
|
|
147
|
+
);
|
|
148
|
+
cleanupFns.push(
|
|
149
|
+
_manager.monitor.addEventListener(
|
|
150
|
+
"dragstart",
|
|
151
|
+
(event, manager2) => emit("dragStart", event, manager2)
|
|
152
|
+
)
|
|
153
|
+
);
|
|
154
|
+
cleanupFns.push(
|
|
155
|
+
_manager.monitor.addEventListener(
|
|
156
|
+
"dragover",
|
|
157
|
+
(event, manager2) => trackRendering(() => emit("dragOver", event, manager2))
|
|
158
|
+
)
|
|
159
|
+
);
|
|
160
|
+
cleanupFns.push(
|
|
161
|
+
_manager.monitor.addEventListener(
|
|
162
|
+
"dragmove",
|
|
163
|
+
(event, manager2) => trackRendering(() => emit("dragMove", event, manager2))
|
|
164
|
+
)
|
|
165
|
+
);
|
|
166
|
+
cleanupFns.push(
|
|
167
|
+
_manager.monitor.addEventListener(
|
|
168
|
+
"dragend",
|
|
169
|
+
(event, manager2) => trackRendering(() => emit("dragEnd", event, manager2))
|
|
170
|
+
)
|
|
171
|
+
);
|
|
172
|
+
cleanupFns.push(
|
|
173
|
+
_manager.monitor.addEventListener(
|
|
174
|
+
"collision",
|
|
175
|
+
(event, manager2) => emit("collision", event, manager2)
|
|
176
|
+
)
|
|
177
|
+
);
|
|
178
|
+
manager.value = _manager;
|
|
179
|
+
(0, import_vue5.onWatcherCleanup)(() => cleanupFns.forEach((fn) => fn()));
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
immediate: true
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
(0, import_vue5.watchEffect)(() => {
|
|
186
|
+
manager.value.plugins = props.plugins ?? import_dom.defaultPreset.plugins;
|
|
187
|
+
manager.value.sensors = props.sensors ?? import_dom.defaultPreset.sensors;
|
|
188
|
+
manager.value.modifiers = props.modifiers ?? import_dom.defaultPreset.modifiers;
|
|
189
|
+
});
|
|
190
|
+
provideDragDropContext((0, import_vue5.computed)(() => manager.value));
|
|
191
|
+
(0, import_vue5.onUnmounted)(() => {
|
|
192
|
+
if (!props.manager) {
|
|
193
|
+
manager.value.destroy();
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return () => slots.default?.();
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// src/core/draggable/useDraggable.ts
|
|
201
|
+
var import_dom3 = require("@dnd-kit/dom");
|
|
202
|
+
|
|
203
|
+
// src/composables/useDeepSignal.ts
|
|
204
|
+
var import_state = require("@dnd-kit/state");
|
|
205
|
+
var import_vue6 = require("vue");
|
|
206
|
+
function useDeepSignal(target) {
|
|
207
|
+
const tracked = /* @__PURE__ */ new Map();
|
|
208
|
+
const dirty = (0, import_vue6.ref)(0);
|
|
209
|
+
(0, import_vue6.watchEffect)(() => {
|
|
210
|
+
const _target = (0, import_vue6.toValue)(target);
|
|
211
|
+
if (!_target) {
|
|
212
|
+
tracked.clear();
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
(0, import_vue6.onWatcherCleanup)(
|
|
216
|
+
(0, import_state.effect)(() => {
|
|
217
|
+
let stale = false;
|
|
218
|
+
for (const entry of tracked) {
|
|
219
|
+
const [key] = entry;
|
|
220
|
+
const value = (0, import_state.untracked)(() => entry[1]);
|
|
221
|
+
const latestValue = _target[key];
|
|
222
|
+
if (value !== latestValue) {
|
|
223
|
+
stale = true;
|
|
224
|
+
tracked.set(key, latestValue);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (stale) {
|
|
228
|
+
dirty.value++;
|
|
229
|
+
}
|
|
230
|
+
})
|
|
231
|
+
);
|
|
232
|
+
});
|
|
233
|
+
return (0, import_vue6.computed)(() => {
|
|
234
|
+
const _target = (0, import_vue6.toValue)(target);
|
|
235
|
+
void dirty.value;
|
|
236
|
+
return _target ? new Proxy(_target, {
|
|
237
|
+
get(target2, key) {
|
|
238
|
+
const value = target2[key];
|
|
239
|
+
tracked.set(key, value);
|
|
240
|
+
return value;
|
|
241
|
+
}
|
|
242
|
+
}) : _target;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// src/core/draggable/useDraggable.ts
|
|
247
|
+
var import_vue8 = require("vue");
|
|
248
|
+
|
|
249
|
+
// src/core/hooks/useInstance.ts
|
|
250
|
+
var import_vue7 = require("vue");
|
|
251
|
+
|
|
252
|
+
// src/core/hooks/useDragDropManager.ts
|
|
253
|
+
function useDragDropManager() {
|
|
254
|
+
return injectDragDropContext();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// src/core/hooks/useInstance.ts
|
|
258
|
+
function useInstance(initializer) {
|
|
259
|
+
const manager = useDragDropManager();
|
|
260
|
+
const instance = (0, import_vue7.shallowRef)(initializer(manager.value));
|
|
261
|
+
(0, import_vue7.watchEffect)(() => {
|
|
262
|
+
instance.value.manager = manager.value;
|
|
263
|
+
(0, import_vue7.onWatcherCleanup)(instance.value.register());
|
|
264
|
+
});
|
|
265
|
+
return (0, import_vue7.computed)(() => instance.value);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// src/core/draggable/useDraggable.ts
|
|
269
|
+
function useDraggable(input) {
|
|
270
|
+
const draggable = useInstance(
|
|
271
|
+
(manager) => new import_dom3.Draggable(
|
|
272
|
+
{
|
|
273
|
+
...toValueDeep(input),
|
|
274
|
+
register: false,
|
|
275
|
+
element: unrefElement(input.element) ?? void 0,
|
|
276
|
+
handle: unrefElement(input.handle) ?? void 0
|
|
277
|
+
},
|
|
278
|
+
manager
|
|
279
|
+
)
|
|
280
|
+
);
|
|
281
|
+
const trackedDraggable = useDeepSignal(draggable);
|
|
282
|
+
(0, import_vue8.watchEffect)(() => {
|
|
283
|
+
draggable.value.element = unrefElement(input.element) ?? void 0;
|
|
284
|
+
draggable.value.handle = unrefElement(input.handle) ?? void 0;
|
|
285
|
+
draggable.value.id = (0, import_vue8.toValue)(input.id);
|
|
286
|
+
draggable.value.disabled = (0, import_vue8.toValue)(input.disabled) ?? false;
|
|
287
|
+
draggable.value.feedback = (0, import_vue8.toValue)(input.feedback) ?? "default";
|
|
288
|
+
draggable.value.alignment = (0, import_vue8.toValue)(input.alignment);
|
|
289
|
+
draggable.value.modifiers = (0, import_vue8.toValue)(input.modifiers);
|
|
290
|
+
draggable.value.sensors = (0, import_vue8.toValue)(input.sensors);
|
|
291
|
+
if ((0, import_vue8.toValue)(input.data)) {
|
|
292
|
+
draggable.value.data = (0, import_vue8.toValue)(input.data);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
return {
|
|
296
|
+
draggable: (0, import_vue8.shallowReadonly)(draggable),
|
|
297
|
+
isDragging: (0, import_vue8.computed)(() => trackedDraggable.value.isDragging),
|
|
298
|
+
isDropping: (0, import_vue8.computed)(() => trackedDraggable.value.isDropping),
|
|
299
|
+
isDragSource: (0, import_vue8.computed)(() => trackedDraggable.value.isDragSource)
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// src/core/droppable/useDroppable.ts
|
|
304
|
+
var import_dom4 = require("@dnd-kit/dom");
|
|
305
|
+
var import_vue9 = require("vue");
|
|
306
|
+
function useDroppable(input) {
|
|
307
|
+
const droppable = useInstance(
|
|
308
|
+
(manager) => new import_dom4.Droppable(
|
|
309
|
+
{
|
|
310
|
+
...toValueDeep(input),
|
|
311
|
+
register: false,
|
|
312
|
+
element: unrefElement(input.element) ?? void 0
|
|
313
|
+
},
|
|
314
|
+
manager
|
|
315
|
+
)
|
|
316
|
+
);
|
|
317
|
+
const trackedDroppable = useDeepSignal(droppable);
|
|
318
|
+
(0, import_vue9.watchEffect)(() => {
|
|
319
|
+
droppable.value.element = unrefElement(input.element) ?? void 0;
|
|
320
|
+
droppable.value.id = (0, import_vue9.toValue)(input.id);
|
|
321
|
+
droppable.value.accept = (0, import_vue9.toValue)(input.accept);
|
|
322
|
+
droppable.value.type = (0, import_vue9.toValue)(input.type);
|
|
323
|
+
droppable.value.disabled = (0, import_vue9.toValue)(input.disabled) ?? false;
|
|
324
|
+
if ((0, import_vue9.toValue)(input.collisionDetector)) {
|
|
325
|
+
droppable.value.collisionDetector = (0, import_vue9.toValue)(input.collisionDetector);
|
|
326
|
+
}
|
|
327
|
+
if ((0, import_vue9.toValue)(input.data)) {
|
|
328
|
+
droppable.value.data = (0, import_vue9.toValue)(input.data);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
return {
|
|
332
|
+
droppable: (0, import_vue9.shallowReadonly)(droppable),
|
|
333
|
+
isDropTarget: (0, import_vue9.computed)(() => trackedDroppable.value.isDropTarget)
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// src/core/hooks/useDragDropMonitor.ts
|
|
338
|
+
var import_vue10 = require("vue");
|
|
339
|
+
function useDragDropMonitor(handlers) {
|
|
340
|
+
const manager = useDragDropManager();
|
|
341
|
+
(0, import_vue10.watchEffect)(() => {
|
|
342
|
+
if (!manager) {
|
|
343
|
+
if (process.env.NODE_ENV !== "production") {
|
|
344
|
+
console.warn(
|
|
345
|
+
"useDragDropMonitor composable was called outside of a DragDropProvider. Make sure your app is wrapped in a DragDropProvider component."
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
const cleanupFns = Object.entries(handlers).reduce(
|
|
351
|
+
(acc, [handlerName, handler]) => {
|
|
352
|
+
if (handler) {
|
|
353
|
+
const eventName = handlerName.replace(/^on/, "").toLowerCase();
|
|
354
|
+
const unsubscribe = manager.value.monitor.addEventListener(
|
|
355
|
+
eventName,
|
|
356
|
+
handler
|
|
357
|
+
);
|
|
358
|
+
acc.push(unsubscribe);
|
|
359
|
+
}
|
|
360
|
+
return acc;
|
|
361
|
+
},
|
|
362
|
+
[]
|
|
363
|
+
);
|
|
364
|
+
(0, import_vue10.onWatcherCleanup)(() => cleanupFns.forEach((cleanup) => cleanup()));
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// src/core/hooks/useDragOperation.ts
|
|
369
|
+
var import_vue11 = require("vue");
|
|
370
|
+
function useDragOperation() {
|
|
371
|
+
const manager = useDragDropManager();
|
|
372
|
+
const trackedDragOperation = useDeepSignal(
|
|
373
|
+
(0, import_vue11.computed)(() => manager.value.dragOperation)
|
|
374
|
+
);
|
|
375
|
+
return {
|
|
376
|
+
get source() {
|
|
377
|
+
return trackedDragOperation.value.source;
|
|
378
|
+
},
|
|
379
|
+
get target() {
|
|
380
|
+
return trackedDragOperation.value.target;
|
|
381
|
+
},
|
|
382
|
+
get status() {
|
|
383
|
+
return trackedDragOperation.value.status;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// src/core/index.ts
|
|
389
|
+
var import_dom5 = require("@dnd-kit/dom");
|
|
390
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
391
|
+
0 && (module.exports = {
|
|
392
|
+
DragDropProvider,
|
|
393
|
+
KeyboardSensor,
|
|
394
|
+
PointerSensor,
|
|
395
|
+
useDragDropManager,
|
|
396
|
+
useDragDropMonitor,
|
|
397
|
+
useDragOperation,
|
|
398
|
+
useDraggable,
|
|
399
|
+
useDroppable,
|
|
400
|
+
useInstance
|
|
401
|
+
});
|
|
402
|
+
//# sourceMappingURL=index.cjs.map
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { MaybeRefOrGetter, ComponentPublicInstance } from 'vue';
|
|
3
|
+
import * as _dnd_kit_abstract from '@dnd-kit/abstract';
|
|
4
|
+
import { DragDropEvents, Data } from '@dnd-kit/abstract';
|
|
5
|
+
import * as _dnd_kit_dom from '@dnd-kit/dom';
|
|
6
|
+
import { DragDropManagerInput, DragDropManager, Draggable, Droppable, DraggableInput, DroppableInput } from '@dnd-kit/dom';
|
|
7
|
+
export { DragDropManager, KeyboardSensor, PointerSensor } from '@dnd-kit/dom';
|
|
8
|
+
import { CleanupFunction } from '@dnd-kit/state';
|
|
9
|
+
|
|
10
|
+
type NamedTuple<T extends (...args: any) => any> = T extends (...args: infer A) => any ? A : never;
|
|
11
|
+
type ToVueEmits<T extends Record<string, (...args: any) => any>> = {
|
|
12
|
+
[K in keyof T]: NamedTuple<T[K]>;
|
|
13
|
+
};
|
|
14
|
+
type Events$1 = ToVueEmits<DragDropEvents<Draggable, Droppable, DragDropManager>>;
|
|
15
|
+
interface DragDropProviderProps extends DragDropManagerInput {
|
|
16
|
+
manager?: DragDropManager;
|
|
17
|
+
}
|
|
18
|
+
type DragDropProviderEmits = {
|
|
19
|
+
beforeDragStart: Events$1['beforedragstart'];
|
|
20
|
+
collision: Events$1['collision'];
|
|
21
|
+
dragStart: Events$1['dragstart'];
|
|
22
|
+
dragMove: Events$1['dragmove'];
|
|
23
|
+
dragOver: Events$1['dragover'];
|
|
24
|
+
dragEnd: Events$1['dragend'];
|
|
25
|
+
};
|
|
26
|
+
declare const _default: vue.DefineComponent<DragDropProviderProps, {}, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<DragDropProviderProps> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, false, {}, any>;
|
|
27
|
+
|
|
28
|
+
type MaybeRefsOrGetters<T> = {
|
|
29
|
+
[K in keyof T]: MaybeRefOrGetter<T[K]>;
|
|
30
|
+
};
|
|
31
|
+
type MaybeElement = HTMLElement | ComponentPublicInstance | undefined | null;
|
|
32
|
+
|
|
33
|
+
interface UseDraggableInput<T extends Data = Data> extends MaybeRefsOrGetters<Omit<DraggableInput<T>, 'handle' | 'element'>> {
|
|
34
|
+
handle?: MaybeRefOrGetter<MaybeElement>;
|
|
35
|
+
element?: MaybeRefOrGetter<MaybeElement>;
|
|
36
|
+
}
|
|
37
|
+
declare function useDraggable<T extends Data = Data>(input: UseDraggableInput<T>): {
|
|
38
|
+
draggable: Readonly<vue.ComputedRef<any>>;
|
|
39
|
+
isDragging: vue.ComputedRef<any>;
|
|
40
|
+
isDropping: vue.ComputedRef<any>;
|
|
41
|
+
isDragSource: vue.ComputedRef<any>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
interface UseDroppableInput<T extends Data = Data> extends MaybeRefsOrGetters<Omit<DroppableInput<T>, 'element'>> {
|
|
45
|
+
element?: MaybeRefOrGetter<MaybeElement>;
|
|
46
|
+
}
|
|
47
|
+
declare function useDroppable<T extends Data = Data>(input: UseDroppableInput<T>): {
|
|
48
|
+
droppable: Readonly<vue.ComputedRef<any>>;
|
|
49
|
+
isDropTarget: vue.ComputedRef<any>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
declare function useDragDropManager(): vue.ComputedRef<_dnd_kit_dom.DragDropManager<_dnd_kit_abstract.Data, _dnd_kit_dom.Draggable<_dnd_kit_abstract.Data>, _dnd_kit_dom.Droppable<_dnd_kit_abstract.Data>>>;
|
|
53
|
+
|
|
54
|
+
type DragDropEventMap = {
|
|
55
|
+
beforedragstart: 'onBeforeDragStart';
|
|
56
|
+
};
|
|
57
|
+
type EventHandlerName<T extends string> = T extends keyof DragDropEventMap ? DragDropEventMap[T] : T extends `drag${infer Second}${infer Rest}` ? `onDrag${Uppercase<Second>}${Rest}` : `on${Capitalize<T>}`;
|
|
58
|
+
type Events<T extends Data, U extends Draggable<T>, V extends Droppable<T>, W extends DragDropManager<T, U, V>> = DragDropEvents<U, V, W>;
|
|
59
|
+
type EventHandlers<T extends Data = Data, U extends Draggable<T> = Draggable<T>, V extends Droppable<T> = Droppable<T>, W extends DragDropManager<T, U, V> = DragDropManager<T, U, V>> = {
|
|
60
|
+
[K in keyof Events<T, U, V, W> as EventHandlerName<K>]?: Events<T, U, V, W>[K];
|
|
61
|
+
};
|
|
62
|
+
declare function useDragDropMonitor<T extends Data = Data, U extends Draggable<T> = Draggable<T>, V extends Droppable<T> = Droppable<T>, W extends DragDropManager<T, U, V> = DragDropManager<T, U, V>>(handlers: EventHandlers<T, U, V, W>): void;
|
|
63
|
+
|
|
64
|
+
declare function useDragOperation(): {
|
|
65
|
+
readonly source: _dnd_kit_dom.Draggable<_dnd_kit_abstract.Data> | null;
|
|
66
|
+
readonly target: _dnd_kit_dom.Droppable<_dnd_kit_abstract.Data> | null;
|
|
67
|
+
readonly status: _dnd_kit_abstract.DragOperationStatus;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
interface Instance<T extends DragDropManager = DragDropManager> {
|
|
71
|
+
manager: T | undefined;
|
|
72
|
+
register(): CleanupFunction | void;
|
|
73
|
+
}
|
|
74
|
+
declare function useInstance<T extends Instance>(initializer: (manager: DragDropManager | undefined) => T): vue.ComputedRef<any>;
|
|
75
|
+
|
|
76
|
+
export { type EventHandlers as DragDropEventHandlers, _default as DragDropProvider, type DragDropProviderEmits, type DragDropProviderProps, type UseDraggableInput, type UseDroppableInput, useDragDropManager, useDragDropMonitor, useDragOperation, useDraggable, useDroppable, useInstance };
|