@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/index.js ADDED
@@ -0,0 +1,377 @@
1
+ // src/core/context/DragDropProvider.ts
2
+ import {
3
+ defaultPreset
4
+ } from "@dnd-kit/dom";
5
+ import { DragDropManager } from "@dnd-kit/dom";
6
+ import {
7
+ computed,
8
+ defineComponent,
9
+ onUnmounted,
10
+ onWatcherCleanup,
11
+ shallowRef,
12
+ watch as watch2,
13
+ watchEffect
14
+ } from "vue";
15
+
16
+ // src/core/context/renderer.ts
17
+ import { nextTick, ref, watch } from "vue";
18
+ function useRenderer() {
19
+ const transitionCount = ref(0);
20
+ const rendering = ref(null);
21
+ let resolver = null;
22
+ watch(
23
+ transitionCount,
24
+ () => {
25
+ resolver?.();
26
+ rendering.value = null;
27
+ },
28
+ {
29
+ flush: "post"
30
+ }
31
+ );
32
+ const renderer = {
33
+ get rendering() {
34
+ return rendering.value ?? Promise.resolve();
35
+ }
36
+ };
37
+ function trackRendering(callback) {
38
+ if (!rendering.value) {
39
+ rendering.value = new Promise((resolve) => {
40
+ resolver = resolve;
41
+ });
42
+ }
43
+ callback();
44
+ nextTick(() => {
45
+ transitionCount.value++;
46
+ });
47
+ }
48
+ return {
49
+ renderer,
50
+ trackRendering
51
+ };
52
+ }
53
+
54
+ // src/utilities/context.ts
55
+ import { inject, provide } from "vue";
56
+ function createContext(componentName) {
57
+ const injectionKey = Symbol(
58
+ `${componentName}Context`
59
+ );
60
+ return [injectContext, provideContext];
61
+ function injectContext(fallback) {
62
+ const context = inject(injectionKey, fallback);
63
+ if (context) return context;
64
+ if (context === null) return context;
65
+ throw new Error(
66
+ `Injection \`${injectionKey.toString()}\` not found. Component must be used within \`${componentName}\``
67
+ );
68
+ }
69
+ function provideContext(contextValue) {
70
+ provide(injectionKey, contextValue);
71
+ return contextValue;
72
+ }
73
+ }
74
+
75
+ // src/utilities/element.ts
76
+ import { toValue } from "vue";
77
+ function unrefElement(elRef) {
78
+ const plain = toValue(elRef);
79
+ return plain?.$el ?? plain ?? void 0;
80
+ }
81
+
82
+ // src/utilities/ref.ts
83
+ import { toValue as toValue2 } from "vue";
84
+ function toValueDeep(input) {
85
+ return Object.fromEntries(
86
+ Object.entries(input).map(([key, value]) => [key, toValue2(value)])
87
+ );
88
+ }
89
+
90
+ // src/core/context/context.ts
91
+ var [injectDragDropContext, provideDragDropContext] = createContext("DragDropProvider");
92
+
93
+ // src/core/context/DragDropProvider.ts
94
+ var DragDropProvider_default = /* @__PURE__ */ defineComponent({
95
+ props: [
96
+ "manager",
97
+ "plugins",
98
+ "sensors",
99
+ "modifiers"
100
+ ],
101
+ emits: [
102
+ "beforeDragStart",
103
+ "collision",
104
+ "dragStart",
105
+ "dragMove",
106
+ "dragOver",
107
+ "dragEnd"
108
+ ],
109
+ setup(props, { emit, slots }) {
110
+ const { renderer, trackRendering } = useRenderer();
111
+ const manager = shallowRef(props.manager ?? new DragDropManager(props));
112
+ watch2(
113
+ [() => props.manager],
114
+ () => {
115
+ const _manager = props.manager ?? new DragDropManager(props);
116
+ const cleanupFns = [];
117
+ _manager.renderer = renderer;
118
+ cleanupFns.push(
119
+ _manager.monitor.addEventListener(
120
+ "beforedragstart",
121
+ (event, manager2) => trackRendering(() => emit("beforeDragStart", event, manager2))
122
+ )
123
+ );
124
+ cleanupFns.push(
125
+ _manager.monitor.addEventListener(
126
+ "dragstart",
127
+ (event, manager2) => emit("dragStart", event, manager2)
128
+ )
129
+ );
130
+ cleanupFns.push(
131
+ _manager.monitor.addEventListener(
132
+ "dragover",
133
+ (event, manager2) => trackRendering(() => emit("dragOver", event, manager2))
134
+ )
135
+ );
136
+ cleanupFns.push(
137
+ _manager.monitor.addEventListener(
138
+ "dragmove",
139
+ (event, manager2) => trackRendering(() => emit("dragMove", event, manager2))
140
+ )
141
+ );
142
+ cleanupFns.push(
143
+ _manager.monitor.addEventListener(
144
+ "dragend",
145
+ (event, manager2) => trackRendering(() => emit("dragEnd", event, manager2))
146
+ )
147
+ );
148
+ cleanupFns.push(
149
+ _manager.monitor.addEventListener(
150
+ "collision",
151
+ (event, manager2) => emit("collision", event, manager2)
152
+ )
153
+ );
154
+ manager.value = _manager;
155
+ onWatcherCleanup(() => cleanupFns.forEach((fn) => fn()));
156
+ },
157
+ {
158
+ immediate: true
159
+ }
160
+ );
161
+ watchEffect(() => {
162
+ manager.value.plugins = props.plugins ?? defaultPreset.plugins;
163
+ manager.value.sensors = props.sensors ?? defaultPreset.sensors;
164
+ manager.value.modifiers = props.modifiers ?? defaultPreset.modifiers;
165
+ });
166
+ provideDragDropContext(computed(() => manager.value));
167
+ onUnmounted(() => {
168
+ if (!props.manager) {
169
+ manager.value.destroy();
170
+ }
171
+ });
172
+ return () => slots.default?.();
173
+ }
174
+ });
175
+
176
+ // src/core/draggable/useDraggable.ts
177
+ import { Draggable } from "@dnd-kit/dom";
178
+
179
+ // src/composables/useDeepSignal.ts
180
+ import { effect, untracked } from "@dnd-kit/state";
181
+ import { computed as computed2, onWatcherCleanup as onWatcherCleanup2, ref as ref2, toValue as toValue3, watchEffect as watchEffect2 } from "vue";
182
+ function useDeepSignal(target) {
183
+ const tracked = /* @__PURE__ */ new Map();
184
+ const dirty = ref2(0);
185
+ watchEffect2(() => {
186
+ const _target = toValue3(target);
187
+ if (!_target) {
188
+ tracked.clear();
189
+ return;
190
+ }
191
+ onWatcherCleanup2(
192
+ effect(() => {
193
+ let stale = false;
194
+ for (const entry of tracked) {
195
+ const [key] = entry;
196
+ const value = untracked(() => entry[1]);
197
+ const latestValue = _target[key];
198
+ if (value !== latestValue) {
199
+ stale = true;
200
+ tracked.set(key, latestValue);
201
+ }
202
+ }
203
+ if (stale) {
204
+ dirty.value++;
205
+ }
206
+ })
207
+ );
208
+ });
209
+ return computed2(() => {
210
+ const _target = toValue3(target);
211
+ void dirty.value;
212
+ return _target ? new Proxy(_target, {
213
+ get(target2, key) {
214
+ const value = target2[key];
215
+ tracked.set(key, value);
216
+ return value;
217
+ }
218
+ }) : _target;
219
+ });
220
+ }
221
+
222
+ // src/core/draggable/useDraggable.ts
223
+ import { computed as computed4, shallowReadonly, toValue as toValue4, watchEffect as watchEffect4 } from "vue";
224
+
225
+ // src/core/hooks/useInstance.ts
226
+ import { computed as computed3, onWatcherCleanup as onWatcherCleanup3, shallowRef as shallowRef2, watchEffect as watchEffect3 } from "vue";
227
+
228
+ // src/core/hooks/useDragDropManager.ts
229
+ function useDragDropManager() {
230
+ return injectDragDropContext();
231
+ }
232
+
233
+ // src/core/hooks/useInstance.ts
234
+ function useInstance(initializer) {
235
+ const manager = useDragDropManager();
236
+ const instance = shallowRef2(initializer(manager.value));
237
+ watchEffect3(() => {
238
+ instance.value.manager = manager.value;
239
+ onWatcherCleanup3(instance.value.register());
240
+ });
241
+ return computed3(() => instance.value);
242
+ }
243
+
244
+ // src/core/draggable/useDraggable.ts
245
+ function useDraggable(input) {
246
+ const draggable = useInstance(
247
+ (manager) => new Draggable(
248
+ {
249
+ ...toValueDeep(input),
250
+ register: false,
251
+ element: unrefElement(input.element) ?? void 0,
252
+ handle: unrefElement(input.handle) ?? void 0
253
+ },
254
+ manager
255
+ )
256
+ );
257
+ const trackedDraggable = useDeepSignal(draggable);
258
+ watchEffect4(() => {
259
+ draggable.value.element = unrefElement(input.element) ?? void 0;
260
+ draggable.value.handle = unrefElement(input.handle) ?? void 0;
261
+ draggable.value.id = toValue4(input.id);
262
+ draggable.value.disabled = toValue4(input.disabled) ?? false;
263
+ draggable.value.feedback = toValue4(input.feedback) ?? "default";
264
+ draggable.value.alignment = toValue4(input.alignment);
265
+ draggable.value.modifiers = toValue4(input.modifiers);
266
+ draggable.value.sensors = toValue4(input.sensors);
267
+ if (toValue4(input.data)) {
268
+ draggable.value.data = toValue4(input.data);
269
+ }
270
+ });
271
+ return {
272
+ draggable: shallowReadonly(draggable),
273
+ isDragging: computed4(() => trackedDraggable.value.isDragging),
274
+ isDropping: computed4(() => trackedDraggable.value.isDropping),
275
+ isDragSource: computed4(() => trackedDraggable.value.isDragSource)
276
+ };
277
+ }
278
+
279
+ // src/core/droppable/useDroppable.ts
280
+ import { Droppable } from "@dnd-kit/dom";
281
+ import { computed as computed5, shallowReadonly as shallowReadonly2, toValue as toValue5, watchEffect as watchEffect5 } from "vue";
282
+ function useDroppable(input) {
283
+ const droppable = useInstance(
284
+ (manager) => new Droppable(
285
+ {
286
+ ...toValueDeep(input),
287
+ register: false,
288
+ element: unrefElement(input.element) ?? void 0
289
+ },
290
+ manager
291
+ )
292
+ );
293
+ const trackedDroppable = useDeepSignal(droppable);
294
+ watchEffect5(() => {
295
+ droppable.value.element = unrefElement(input.element) ?? void 0;
296
+ droppable.value.id = toValue5(input.id);
297
+ droppable.value.accept = toValue5(input.accept);
298
+ droppable.value.type = toValue5(input.type);
299
+ droppable.value.disabled = toValue5(input.disabled) ?? false;
300
+ if (toValue5(input.collisionDetector)) {
301
+ droppable.value.collisionDetector = toValue5(input.collisionDetector);
302
+ }
303
+ if (toValue5(input.data)) {
304
+ droppable.value.data = toValue5(input.data);
305
+ }
306
+ });
307
+ return {
308
+ droppable: shallowReadonly2(droppable),
309
+ isDropTarget: computed5(() => trackedDroppable.value.isDropTarget)
310
+ };
311
+ }
312
+
313
+ // src/core/hooks/useDragDropMonitor.ts
314
+ import { onWatcherCleanup as onWatcherCleanup4, watchEffect as watchEffect6 } from "vue";
315
+ function useDragDropMonitor(handlers) {
316
+ const manager = useDragDropManager();
317
+ watchEffect6(() => {
318
+ if (!manager) {
319
+ if (process.env.NODE_ENV !== "production") {
320
+ console.warn(
321
+ "useDragDropMonitor composable was called outside of a DragDropProvider. Make sure your app is wrapped in a DragDropProvider component."
322
+ );
323
+ }
324
+ return;
325
+ }
326
+ const cleanupFns = Object.entries(handlers).reduce(
327
+ (acc, [handlerName, handler]) => {
328
+ if (handler) {
329
+ const eventName = handlerName.replace(/^on/, "").toLowerCase();
330
+ const unsubscribe = manager.value.monitor.addEventListener(
331
+ eventName,
332
+ handler
333
+ );
334
+ acc.push(unsubscribe);
335
+ }
336
+ return acc;
337
+ },
338
+ []
339
+ );
340
+ onWatcherCleanup4(() => cleanupFns.forEach((cleanup) => cleanup()));
341
+ });
342
+ }
343
+
344
+ // src/core/hooks/useDragOperation.ts
345
+ import { computed as computed6 } from "vue";
346
+ function useDragOperation() {
347
+ const manager = useDragDropManager();
348
+ const trackedDragOperation = useDeepSignal(
349
+ computed6(() => manager.value.dragOperation)
350
+ );
351
+ return {
352
+ get source() {
353
+ return trackedDragOperation.value.source;
354
+ },
355
+ get target() {
356
+ return trackedDragOperation.value.target;
357
+ },
358
+ get status() {
359
+ return trackedDragOperation.value.status;
360
+ }
361
+ };
362
+ }
363
+
364
+ // src/core/index.ts
365
+ import { KeyboardSensor, PointerSensor } from "@dnd-kit/dom";
366
+ export {
367
+ DragDropProvider_default as DragDropProvider,
368
+ KeyboardSensor,
369
+ PointerSensor,
370
+ useDragDropManager,
371
+ useDragDropMonitor,
372
+ useDragOperation,
373
+ useDraggable,
374
+ useDroppable,
375
+ useInstance
376
+ };
377
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@dnd-kit/vue",
3
+ "version": "0.2.3",
4
+ "main": "./index.cjs",
5
+ "module": "./index.js",
6
+ "type": "module",
7
+ "types": "./index.d.ts",
8
+ "sideEffects": false,
9
+ "license": "MIT",
10
+ "files": [
11
+ "LICENSE",
12
+ "README.md",
13
+ "index.js",
14
+ "index.d.ts",
15
+ "index.cjs",
16
+ "composables.js",
17
+ "composables.d.ts",
18
+ "composables.cjs",
19
+ "sortable.js",
20
+ "sortable.d.ts",
21
+ "sortable.cjs",
22
+ "utilities.js",
23
+ "utilities.d.ts",
24
+ "utilities.cjs"
25
+ ],
26
+ "exports": {
27
+ ".": {
28
+ "types": "./index.d.ts",
29
+ "import": "./index.js",
30
+ "require": "./index.cjs"
31
+ },
32
+ "./composables": {
33
+ "types": "./composables.d.ts",
34
+ "import": "./composables.js",
35
+ "require": "./composables.cjs"
36
+ },
37
+ "./sortable": {
38
+ "types": "./sortable.d.ts",
39
+ "import": "./sortable.js",
40
+ "require": "./sortable.cjs"
41
+ },
42
+ "./utilities": {
43
+ "types": "./utilities.d.ts",
44
+ "import": "./utilities.js",
45
+ "require": "./utilities.cjs"
46
+ }
47
+ },
48
+ "scripts": {
49
+ "build": "bun build:utilities && bun build:composables && bun build:core && bun build:sortable",
50
+ "build:core": "tsup src/core/index.ts",
51
+ "build:composables": "tsup --entry.composables src/composables/index.ts",
52
+ "build:sortable": "tsup --entry.sortable src/sortable/index.ts",
53
+ "build:utilities": "tsup --entry.utilities src/utilities/index.ts",
54
+ "dev": "bun build:utilities --watch & bun build:composables --watch & bun build:core --watch & bun build:sortable --watch",
55
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
56
+ },
57
+ "dependencies": {
58
+ "@dnd-kit/abstract": "^0.2.3",
59
+ "@dnd-kit/dom": "^0.2.3",
60
+ "@dnd-kit/state": "^0.2.3",
61
+ "tslib": "^2.6.2"
62
+ },
63
+ "peerDependencies": {
64
+ "vue": "^3.5.0"
65
+ },
66
+ "devDependencies": {
67
+ "tsup": "8.3.0",
68
+ "typescript": "^5.5.2",
69
+ "vue": "^3.5.0"
70
+ },
71
+ "publishConfig": {
72
+ "access": "public"
73
+ },
74
+ "repository": {
75
+ "type": "git",
76
+ "url": "https://github.com/clauderic/dnd-kit"
77
+ }
78
+ }
package/sortable.cjs ADDED
@@ -0,0 +1,112 @@
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/sortable/index.ts
21
+ var sortable_exports = {};
22
+ __export(sortable_exports, {
23
+ isSortable: () => import_sortable2.isSortable,
24
+ useSortable: () => useSortable
25
+ });
26
+ module.exports = __toCommonJS(sortable_exports);
27
+
28
+ // src/sortable/useSortable.ts
29
+ var import_sortable = require("@dnd-kit/dom/sortable");
30
+ var import_state = require("@dnd-kit/state");
31
+ var import_composables = require("@dnd-kit/vue/composables");
32
+ var import_utilities = require("@dnd-kit/vue/utilities");
33
+ var import_vue = require("@dnd-kit/vue");
34
+ var import_vue2 = require("vue");
35
+ function useSortable(input) {
36
+ const transition = (0, import_vue2.computed)(() => ({
37
+ ...import_sortable.defaultSortableTransition,
38
+ ...(0, import_vue2.toValue)(input.transition)
39
+ }));
40
+ const sortable = (0, import_vue.useInstance)((manager) => {
41
+ const _input = (0, import_utilities.toValueDeep)(input);
42
+ return new import_sortable.Sortable(
43
+ {
44
+ ..._input,
45
+ register: false,
46
+ transition: transition.value,
47
+ element: (0, import_utilities.unrefElement)(input.element),
48
+ handle: (0, import_utilities.unrefElement)(input.handle),
49
+ target: (0, import_utilities.unrefElement)(input.target)
50
+ },
51
+ manager
52
+ );
53
+ });
54
+ const trackedSortable = (0, import_composables.useDeepSignal)(sortable);
55
+ (0, import_vue2.watchEffect)(() => {
56
+ sortable.value.element = (0, import_utilities.unrefElement)(input.element);
57
+ sortable.value.handle = (0, import_utilities.unrefElement)(input.handle);
58
+ if ((0, import_utilities.unrefElement)(input.source)) {
59
+ sortable.value.source = (0, import_utilities.unrefElement)(input.source);
60
+ }
61
+ if ((0, import_utilities.unrefElement)(input.target)) {
62
+ sortable.value.target = (0, import_utilities.unrefElement)(input.target);
63
+ }
64
+ sortable.value.id = (0, import_vue2.toValue)(input.id);
65
+ sortable.value.disabled = (0, import_vue2.toValue)(input.disabled) ?? false;
66
+ sortable.value.feedback = (0, import_vue2.toValue)(input.feedback) ?? "default";
67
+ sortable.value.alignment = (0, import_vue2.toValue)(input.alignment);
68
+ sortable.value.modifiers = (0, import_vue2.toValue)(input.modifiers);
69
+ sortable.value.sensors = (0, import_vue2.toValue)(input.sensors);
70
+ sortable.value.accept = (0, import_vue2.toValue)(input.accept);
71
+ sortable.value.type = (0, import_vue2.toValue)(input.type);
72
+ sortable.value.collisionPriority = (0, import_vue2.toValue)(input.collisionPriority);
73
+ sortable.value.transition = transition.value;
74
+ if ((0, import_vue2.toValue)(input.data)) {
75
+ sortable.value.data = (0, import_vue2.toValue)(input.data);
76
+ }
77
+ });
78
+ (0, import_vue2.watch)(
79
+ [() => (0, import_vue2.toValue)(input.group), () => (0, import_vue2.toValue)(input.index)],
80
+ () => {
81
+ (0, import_state.batch)(() => {
82
+ sortable.value.group = (0, import_vue2.toValue)(input.group);
83
+ sortable.value.index = (0, import_vue2.toValue)(input.index);
84
+ });
85
+ },
86
+ { flush: "sync" }
87
+ );
88
+ (0, import_vue2.watch)(
89
+ () => (0, import_vue2.toValue)(input.index),
90
+ () => {
91
+ if (sortable.value.manager?.dragOperation.status.idle && sortable.value.transition?.idle) {
92
+ sortable.value.refreshShape();
93
+ }
94
+ }
95
+ );
96
+ return {
97
+ sortable: (0, import_vue2.shallowReadonly)(sortable),
98
+ isDragging: (0, import_vue2.computed)(() => trackedSortable.value.isDragging),
99
+ isDropping: (0, import_vue2.computed)(() => trackedSortable.value.isDropping),
100
+ isDragSource: (0, import_vue2.computed)(() => trackedSortable.value.isDragSource),
101
+ isDropTarget: (0, import_vue2.computed)(() => trackedSortable.value.isDropTarget)
102
+ };
103
+ }
104
+
105
+ // src/sortable/index.ts
106
+ var import_sortable2 = require("@dnd-kit/dom/sortable");
107
+ // Annotate the CommonJS export names for ESM import in node:
108
+ 0 && (module.exports = {
109
+ isSortable,
110
+ useSortable
111
+ });
112
+ //# sourceMappingURL=sortable.cjs.map
package/sortable.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import * as vue from 'vue';
2
+ import { MaybeRefOrGetter, ComponentPublicInstance } from 'vue';
3
+ import { Data } from '@dnd-kit/abstract';
4
+ import { SortableInput } from '@dnd-kit/dom/sortable';
5
+ export { isSortable } from '@dnd-kit/dom/sortable';
6
+
7
+ type MaybeRefsOrGetters<T> = {
8
+ [K in keyof T]: MaybeRefOrGetter<T[K]>;
9
+ };
10
+ type MaybeElement = HTMLElement | ComponentPublicInstance | undefined | null;
11
+
12
+ interface UseSortableInput<T extends Data = Data> extends MaybeRefsOrGetters<Omit<SortableInput<T>, 'handle' | 'element' | 'source' | 'target'>> {
13
+ handle?: MaybeRefOrGetter<MaybeElement>;
14
+ element?: MaybeRefOrGetter<MaybeElement>;
15
+ source?: MaybeRefOrGetter<MaybeElement>;
16
+ target?: MaybeRefOrGetter<MaybeElement>;
17
+ }
18
+ declare function useSortable<T extends Data = Data>(input: UseSortableInput<T>): {
19
+ sortable: Readonly<vue.ComputedRef<any>>;
20
+ isDragging: vue.ComputedRef<any>;
21
+ isDropping: vue.ComputedRef<any>;
22
+ isDragSource: vue.ComputedRef<any>;
23
+ isDropTarget: vue.ComputedRef<any>;
24
+ };
25
+
26
+ export { type UseSortableInput, useSortable };
package/sortable.js ADDED
@@ -0,0 +1,90 @@
1
+ // src/sortable/useSortable.ts
2
+ import { defaultSortableTransition, Sortable } from "@dnd-kit/dom/sortable";
3
+ import { batch } from "@dnd-kit/state";
4
+ import { useDeepSignal } from "@dnd-kit/vue/composables";
5
+ import { toValueDeep, unrefElement } from "@dnd-kit/vue/utilities";
6
+ import { useInstance } from "@dnd-kit/vue";
7
+ import {
8
+ computed,
9
+ shallowReadonly,
10
+ toValue,
11
+ watch,
12
+ watchEffect
13
+ } from "vue";
14
+ function useSortable(input) {
15
+ const transition = computed(() => ({
16
+ ...defaultSortableTransition,
17
+ ...toValue(input.transition)
18
+ }));
19
+ const sortable = useInstance((manager) => {
20
+ const _input = toValueDeep(input);
21
+ return new Sortable(
22
+ {
23
+ ..._input,
24
+ register: false,
25
+ transition: transition.value,
26
+ element: unrefElement(input.element),
27
+ handle: unrefElement(input.handle),
28
+ target: unrefElement(input.target)
29
+ },
30
+ manager
31
+ );
32
+ });
33
+ const trackedSortable = useDeepSignal(sortable);
34
+ watchEffect(() => {
35
+ sortable.value.element = unrefElement(input.element);
36
+ sortable.value.handle = unrefElement(input.handle);
37
+ if (unrefElement(input.source)) {
38
+ sortable.value.source = unrefElement(input.source);
39
+ }
40
+ if (unrefElement(input.target)) {
41
+ sortable.value.target = unrefElement(input.target);
42
+ }
43
+ sortable.value.id = toValue(input.id);
44
+ sortable.value.disabled = toValue(input.disabled) ?? false;
45
+ sortable.value.feedback = toValue(input.feedback) ?? "default";
46
+ sortable.value.alignment = toValue(input.alignment);
47
+ sortable.value.modifiers = toValue(input.modifiers);
48
+ sortable.value.sensors = toValue(input.sensors);
49
+ sortable.value.accept = toValue(input.accept);
50
+ sortable.value.type = toValue(input.type);
51
+ sortable.value.collisionPriority = toValue(input.collisionPriority);
52
+ sortable.value.transition = transition.value;
53
+ if (toValue(input.data)) {
54
+ sortable.value.data = toValue(input.data);
55
+ }
56
+ });
57
+ watch(
58
+ [() => toValue(input.group), () => toValue(input.index)],
59
+ () => {
60
+ batch(() => {
61
+ sortable.value.group = toValue(input.group);
62
+ sortable.value.index = toValue(input.index);
63
+ });
64
+ },
65
+ { flush: "sync" }
66
+ );
67
+ watch(
68
+ () => toValue(input.index),
69
+ () => {
70
+ if (sortable.value.manager?.dragOperation.status.idle && sortable.value.transition?.idle) {
71
+ sortable.value.refreshShape();
72
+ }
73
+ }
74
+ );
75
+ return {
76
+ sortable: shallowReadonly(sortable),
77
+ isDragging: computed(() => trackedSortable.value.isDragging),
78
+ isDropping: computed(() => trackedSortable.value.isDropping),
79
+ isDragSource: computed(() => trackedSortable.value.isDragSource),
80
+ isDropTarget: computed(() => trackedSortable.value.isDropTarget)
81
+ };
82
+ }
83
+
84
+ // src/sortable/index.ts
85
+ import { isSortable } from "@dnd-kit/dom/sortable";
86
+ export {
87
+ isSortable,
88
+ useSortable
89
+ };
90
+ //# sourceMappingURL=sortable.js.map