vue-dnd-sortable 0.1.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 +15 -0
- package/dist/activator.d.ts +22 -0
- package/dist/collision.d.ts +13 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/provider.vue.d.ts +26 -0
- package/dist/composables.d.ts +10 -0
- package/dist/context.d.ts +21 -0
- package/dist/helpers.d.ts +3 -0
- package/dist/index.d.ts +4 -0
- package/dist/sortable.d.ts +7 -0
- package/dist/types.d.ts +6 -0
- package/dist/utilities/context.d.ts +1 -0
- package/dist/utilities/index.d.ts +3 -0
- package/dist/utilities/rects.d.ts +3 -0
- package/dist/vue-dnd.es.js +268 -0
- package/dist/vue-dnd.umd.js +1 -0
- package/package.json +42 -0
package/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
import type { Coords } from './types';
|
2
|
+
interface ActivatorOptions {
|
3
|
+
element: HTMLElement;
|
4
|
+
onStart?: (coords: Coords) => void;
|
5
|
+
onMove?: (coords: Coords) => void;
|
6
|
+
onEnd?: (e: PointerEvent) => void;
|
7
|
+
}
|
8
|
+
export declare class Activator {
|
9
|
+
private document;
|
10
|
+
private listeners;
|
11
|
+
private documentListeners;
|
12
|
+
private options;
|
13
|
+
private windowListeners;
|
14
|
+
constructor(options: ActivatorOptions);
|
15
|
+
private deactivate;
|
16
|
+
private activate;
|
17
|
+
private handleStart;
|
18
|
+
private handleMove;
|
19
|
+
private handleEnd;
|
20
|
+
private clearSelection;
|
21
|
+
}
|
22
|
+
export {};
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import type { UniqueIdentifier } from './types';
|
2
|
+
import type { DomRectMap } from './utilities';
|
3
|
+
interface CollisionResult {
|
4
|
+
id: UniqueIdentifier;
|
5
|
+
value: number;
|
6
|
+
}
|
7
|
+
export type CollisionDetector = (options: {
|
8
|
+
rect: DOMRect;
|
9
|
+
rects: DomRectMap;
|
10
|
+
}) => CollisionResult[];
|
11
|
+
export declare const rectangleIntersection: CollisionDetector;
|
12
|
+
export declare const closestToCenter: CollisionDetector;
|
13
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default as DndProvider } from './provider.vue';
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import type { CollisionDetector } from '../collision';
|
2
|
+
import type { DndEndEvent } from '../context';
|
3
|
+
import type { UniqueIdentifier } from '../types';
|
4
|
+
interface Props {
|
5
|
+
items: UniqueIdentifier[];
|
6
|
+
collision?: CollisionDetector;
|
7
|
+
axis?: 'x' | 'y';
|
8
|
+
}
|
9
|
+
declare var __VLS_1: {};
|
10
|
+
type __VLS_Slots = {} & {
|
11
|
+
default?: (props: typeof __VLS_1) => any;
|
12
|
+
};
|
13
|
+
declare const __VLS_component: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
14
|
+
end: (event: DndEndEvent) => any;
|
15
|
+
}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{
|
16
|
+
onEnd?: ((event: DndEndEvent) => any) | undefined;
|
17
|
+
}>, {
|
18
|
+
collision: CollisionDetector;
|
19
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
20
|
+
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
21
|
+
export default _default;
|
22
|
+
type __VLS_WithSlots<T, S> = T & {
|
23
|
+
new (): {
|
24
|
+
$slots: S;
|
25
|
+
};
|
26
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { MaybeRefOrGetter } from 'vue';
|
2
|
+
import type { UniqueIdentifier } from './types';
|
3
|
+
export interface SortableOptions {
|
4
|
+
id: UniqueIdentifier;
|
5
|
+
element: MaybeRefOrGetter<HTMLElement | null>;
|
6
|
+
handleElement?: MaybeRefOrGetter<HTMLElement | null>;
|
7
|
+
}
|
8
|
+
export declare function useSortable(options: SortableOptions): {
|
9
|
+
isDragging: import("vue").ComputedRef<boolean>;
|
10
|
+
};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import type { ComputedRef, Ref } from 'vue';
|
2
|
+
import type { Coords, Nullable, UniqueIdentifier } from './types';
|
3
|
+
import type { DomRectMap } from './utilities/rects';
|
4
|
+
interface DndContext {
|
5
|
+
elements: Ref<Map<UniqueIdentifier, HTMLElement>>;
|
6
|
+
rects: Ref<DomRectMap>;
|
7
|
+
items: ComputedRef<UniqueIdentifier[]>;
|
8
|
+
translate: Ref<Coords | null>;
|
9
|
+
active: Ref<UniqueIdentifier | null>;
|
10
|
+
over: Ref<UniqueIdentifier | null>;
|
11
|
+
sortedRects: Ref<DOMRect[]>;
|
12
|
+
activeIndex: ComputedRef<number | null>;
|
13
|
+
overIndex: ComputedRef<number | null>;
|
14
|
+
activate: (id: UniqueIdentifier, handle: Nullable<HTMLElement>) => void;
|
15
|
+
}
|
16
|
+
export interface DndEndEvent {
|
17
|
+
active: UniqueIdentifier;
|
18
|
+
over: UniqueIdentifier | null;
|
19
|
+
}
|
20
|
+
export declare const injectDndContext: <T extends DndContext | null | undefined = DndContext>(fallback?: T | undefined) => T extends null ? DndContext | null : DndContext, provideDndContext: (contextValue: DndContext) => DndContext;
|
21
|
+
export {};
|
package/dist/index.d.ts
ADDED
package/dist/types.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export declare function createContext<TContextValue>(componentName: string): readonly [<T extends TContextValue | null | undefined = TContextValue>(fallback?: T) => T extends null ? TContextValue | null : TContextValue, (contextValue: TContextValue) => TContextValue];
|
@@ -0,0 +1,268 @@
|
|
1
|
+
import { inject as R, provide as A, defineComponent as C, ref as w, computed as f, watch as S, renderSlot as b, onMounted as D, toValue as E, onUnmounted as O } from "vue";
|
2
|
+
function _(s, e) {
|
3
|
+
return e.value - s.value;
|
4
|
+
}
|
5
|
+
function $(s, e) {
|
6
|
+
return s.value - e.value;
|
7
|
+
}
|
8
|
+
const G = ({ rect: s, rects: e }) => {
|
9
|
+
function i(t, n) {
|
10
|
+
const o = Math.max(t.x, n.x), u = Math.min(t.x + t.width, n.x + n.width), c = Math.max(t.y, n.y), v = Math.min(t.y + t.height, n.y + n.height), m = u - o, x = v - c;
|
11
|
+
if (o < u && c < v) {
|
12
|
+
const p = m * x, g = t.width * t.height, y = n.width * n.height, L = p / (g + y - p);
|
13
|
+
return Number(L.toFixed(4));
|
14
|
+
}
|
15
|
+
return 0;
|
16
|
+
}
|
17
|
+
const r = [];
|
18
|
+
for (const [t, n] of e)
|
19
|
+
r.push({
|
20
|
+
id: t,
|
21
|
+
value: i(s, n)
|
22
|
+
});
|
23
|
+
return r.sort(_);
|
24
|
+
}, j = ({ rect: s, rects: e }) => {
|
25
|
+
function i(n, o) {
|
26
|
+
return Math.sqrt((n.x - o.x) ** 2 + (n.y - o.y) ** 2);
|
27
|
+
}
|
28
|
+
function r(n) {
|
29
|
+
return {
|
30
|
+
x: n.x + n.width / 2,
|
31
|
+
y: n.y + n.height / 2
|
32
|
+
};
|
33
|
+
}
|
34
|
+
const t = [];
|
35
|
+
for (const [n, o] of e)
|
36
|
+
t.push({
|
37
|
+
id: n,
|
38
|
+
value: i(r(o), r(s))
|
39
|
+
});
|
40
|
+
return t.sort($);
|
41
|
+
};
|
42
|
+
class M {
|
43
|
+
listeners = [];
|
44
|
+
element;
|
45
|
+
constructor(e) {
|
46
|
+
this.element = e;
|
47
|
+
}
|
48
|
+
add(e, i) {
|
49
|
+
this.element.addEventListener(e, i), this.listeners.push([e, i]);
|
50
|
+
}
|
51
|
+
removeAll() {
|
52
|
+
this.listeners.forEach((e) => {
|
53
|
+
this.element.removeEventListener(...e);
|
54
|
+
});
|
55
|
+
}
|
56
|
+
}
|
57
|
+
class z {
|
58
|
+
document;
|
59
|
+
listeners;
|
60
|
+
documentListeners;
|
61
|
+
options;
|
62
|
+
windowListeners;
|
63
|
+
constructor(e) {
|
64
|
+
const { element: i } = e;
|
65
|
+
this.options = e, this.document = i.ownerDocument, this.listeners = new M(i), this.documentListeners = new M(this.document), this.windowListeners = new M(this.document?.defaultView ?? window), this.handleStart = this.handleStart.bind(this), this.handleMove = this.handleMove.bind(this), this.handleEnd = this.handleEnd.bind(this), this.deactivate();
|
66
|
+
}
|
67
|
+
deactivate() {
|
68
|
+
this.listeners.removeAll(), this.documentListeners.removeAll(), this.windowListeners.removeAll(), this.listeners.add("pointerdown", this.handleStart);
|
69
|
+
}
|
70
|
+
activate() {
|
71
|
+
this.windowListeners.add("selectionchange", this.clearSelection), this.windowListeners.add("resize", this.handleEnd), this.windowListeners.add("visibilitychange", this.handleEnd), this.windowListeners.add("dragstart", (e) => e.preventDefault()), this.windowListeners.add("contextmenu", (e) => e.preventDefault()), this.documentListeners.add("pointermove", this.handleMove), this.documentListeners.add("pointerup", this.handleEnd);
|
72
|
+
}
|
73
|
+
handleStart(e) {
|
74
|
+
e.button === 0 && (this.options.onStart?.({
|
75
|
+
x: e.clientX,
|
76
|
+
y: e.clientY
|
77
|
+
}), this.activate());
|
78
|
+
}
|
79
|
+
handleMove(e) {
|
80
|
+
this.options.onMove?.({
|
81
|
+
x: e.clientX,
|
82
|
+
y: e.clientY
|
83
|
+
}), this.clearSelection();
|
84
|
+
}
|
85
|
+
handleEnd(e) {
|
86
|
+
this.options.onEnd?.(e), this.deactivate();
|
87
|
+
}
|
88
|
+
clearSelection() {
|
89
|
+
this.document?.getSelection()?.removeAllRanges();
|
90
|
+
}
|
91
|
+
}
|
92
|
+
function B(s) {
|
93
|
+
const e = Symbol(
|
94
|
+
`${s}Context`
|
95
|
+
);
|
96
|
+
return [i, r];
|
97
|
+
function i(t) {
|
98
|
+
const n = R(e, t);
|
99
|
+
if (n || n === null) return n;
|
100
|
+
throw new Error(
|
101
|
+
`Injection \`${e.toString()}\` not found. Component must be used within \`${s}\``
|
102
|
+
);
|
103
|
+
}
|
104
|
+
function r(t) {
|
105
|
+
return A(e, t), t;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
function F(s, e) {
|
109
|
+
return s.reduce((i, r) => {
|
110
|
+
const t = e.get(r);
|
111
|
+
return t && i.push(t), i;
|
112
|
+
}, []);
|
113
|
+
}
|
114
|
+
function I(s) {
|
115
|
+
return s !== null && s >= 0;
|
116
|
+
}
|
117
|
+
const [T, V] = B("DndContext");
|
118
|
+
function X(s) {
|
119
|
+
const {
|
120
|
+
rects: e,
|
121
|
+
activeIndex: i,
|
122
|
+
overIndex: r,
|
123
|
+
index: t
|
124
|
+
} = s, n = e[i];
|
125
|
+
if (!n)
|
126
|
+
return null;
|
127
|
+
if (t === i) {
|
128
|
+
const u = e[r];
|
129
|
+
return u ? {
|
130
|
+
x: 0,
|
131
|
+
y: i > r ? n.top - u.top : u.top - n.top
|
132
|
+
} : null;
|
133
|
+
}
|
134
|
+
const o = Y(e, t, i);
|
135
|
+
return t > i && t <= r ? {
|
136
|
+
x: 0,
|
137
|
+
y: -n.height - o
|
138
|
+
} : t < i && t >= r ? {
|
139
|
+
x: 0,
|
140
|
+
y: n.height - o
|
141
|
+
} : {
|
142
|
+
x: 0,
|
143
|
+
y: 0
|
144
|
+
};
|
145
|
+
}
|
146
|
+
function Y(s, e, i) {
|
147
|
+
const r = s[e], t = s[e - 1], n = s[e + 1];
|
148
|
+
return !r || !t && !n ? 0 : i < e ? t ? r.top - (t.top + t.height) : n ? n.top - (r.top + r.height) : 0 : n ? r.top - (n.top - n.height) : t ? t.top - (r.top + r.height) : 0;
|
149
|
+
}
|
150
|
+
const K = /* @__PURE__ */ C({
|
151
|
+
__name: "provider",
|
152
|
+
props: {
|
153
|
+
items: {},
|
154
|
+
collision: { type: Function, default: j },
|
155
|
+
axis: {}
|
156
|
+
},
|
157
|
+
emits: ["end"],
|
158
|
+
setup(s, { emit: e }) {
|
159
|
+
const i = s, r = e, t = w(/* @__PURE__ */ new Map()), n = w(/* @__PURE__ */ new Map()), o = w(null), u = w(null), c = w({
|
160
|
+
start: null,
|
161
|
+
current: { x: 0, y: 0 }
|
162
|
+
}), v = f(() => c.value.start ? {
|
163
|
+
x: i.axis === "y" ? 0 : c.value.current.x - c.value.start.x,
|
164
|
+
y: i.axis === "x" ? 0 : c.value.current.y - c.value.start.y
|
165
|
+
} : null), m = f(() => o.value ? i.items.indexOf(o.value) : null), x = f(() => u.value ? i.items.indexOf(u.value) : null), p = f(() => F(i.items, n.value));
|
166
|
+
function g() {
|
167
|
+
for (const [l, a] of t.value)
|
168
|
+
n.value.set(l, a.getBoundingClientRect());
|
169
|
+
}
|
170
|
+
function y() {
|
171
|
+
if (!o.value)
|
172
|
+
return null;
|
173
|
+
const l = n.value.get(o.value), a = l && v.value ? {
|
174
|
+
...l,
|
175
|
+
width: l.width,
|
176
|
+
height: l.height,
|
177
|
+
x: l.x + v.value?.x,
|
178
|
+
y: l.y + v.value?.y
|
179
|
+
} : null;
|
180
|
+
return a ? i.collision({
|
181
|
+
rect: a,
|
182
|
+
rects: n.value
|
183
|
+
})[0]?.id ?? null : null;
|
184
|
+
}
|
185
|
+
function L(l, a) {
|
186
|
+
const d = t.value.get(l);
|
187
|
+
if (d)
|
188
|
+
return new z({
|
189
|
+
element: a ?? d,
|
190
|
+
onStart(h) {
|
191
|
+
g(), c.value.start = h;
|
192
|
+
},
|
193
|
+
onMove(h) {
|
194
|
+
c.value.start && (o.value || (o.value = l), c.value.current.x = h.x, c.value.current.y = h.y, u.value = y());
|
195
|
+
},
|
196
|
+
onEnd() {
|
197
|
+
o.value && r("end", {
|
198
|
+
active: o.value,
|
199
|
+
over: u.value
|
200
|
+
}), o.value = null, u.value = null, c.value.start = null;
|
201
|
+
}
|
202
|
+
});
|
203
|
+
}
|
204
|
+
return S(t, g, { deep: !0 }), S([o, u], ([l]) => {
|
205
|
+
if (!l) {
|
206
|
+
for (const [d, h] of t.value)
|
207
|
+
h.style.transition = "", h.style.position = "", h.style.zIndex = "", h.style.transform = "";
|
208
|
+
return;
|
209
|
+
}
|
210
|
+
const a = t.value.get(l);
|
211
|
+
if (a) {
|
212
|
+
a.style.position = "relative", a.style.zIndex = "1";
|
213
|
+
for (const [d, h] of t.value)
|
214
|
+
d !== l && (h.style.transition = "0.2s transform");
|
215
|
+
}
|
216
|
+
}), S(v, () => {
|
217
|
+
if (!(!I(m.value) || !I(x.value)) && !(!o.value || !v.value))
|
218
|
+
for (const [l, a] of t.value) {
|
219
|
+
let d = null;
|
220
|
+
l === o.value ? d = v.value : d = X({
|
221
|
+
activeIndex: m.value,
|
222
|
+
overIndex: x.value,
|
223
|
+
rects: p.value,
|
224
|
+
index: i.items.indexOf(l)
|
225
|
+
}), d && (a.style.transform = `translate(${d.x}px, ${d.y}px)`);
|
226
|
+
}
|
227
|
+
}), V({
|
228
|
+
rects: n,
|
229
|
+
activate: L,
|
230
|
+
elements: t,
|
231
|
+
translate: v,
|
232
|
+
active: o,
|
233
|
+
over: u,
|
234
|
+
activeIndex: m,
|
235
|
+
overIndex: x,
|
236
|
+
items: f(() => i.items),
|
237
|
+
sortedRects: p
|
238
|
+
}), (l, a) => b(l.$slots, "default");
|
239
|
+
}
|
240
|
+
});
|
241
|
+
function N(s) {
|
242
|
+
const { active: e, elements: i, activate: r } = T(), { id: t, element: n, handleElement: o } = s;
|
243
|
+
return D(() => {
|
244
|
+
const c = E(n);
|
245
|
+
c && (i.value.set(t, c), r(t, E(o)));
|
246
|
+
}), O(() => {
|
247
|
+
i.value.delete(t);
|
248
|
+
}), {
|
249
|
+
isDragging: f(() => e.value === t)
|
250
|
+
};
|
251
|
+
}
|
252
|
+
function P(s, e) {
|
253
|
+
const { active: i, over: r } = e;
|
254
|
+
if (!r)
|
255
|
+
return s;
|
256
|
+
const t = s.indexOf(i), n = s.indexOf(r);
|
257
|
+
if (t === n)
|
258
|
+
return s;
|
259
|
+
const o = s.slice(), u = o.splice(t, 1)[0];
|
260
|
+
return u && o.splice(n, 0, u), o;
|
261
|
+
}
|
262
|
+
export {
|
263
|
+
K as DndProvider,
|
264
|
+
P as arrayMove,
|
265
|
+
j as closestToCenter,
|
266
|
+
G as rectangleIntersection,
|
267
|
+
N as useSortable
|
268
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
(function(h,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],l):(h=typeof globalThis<"u"?globalThis:h||self,l(h.VueDnD={},h.Vue))})(this,function(h,l){"use strict";function I(o,e){return e.value-o.value}function b(o,e){return o.value-e.value}const C=({rect:o,rects:e})=>{function i(t,n){const s=Math.max(t.x,n.x),u=Math.min(t.x+t.width,n.x+n.width),a=Math.max(t.y,n.y),m=Math.min(t.y+t.height,n.y+n.height),p=u-s,x=m-a;if(s<u&&a<m){const w=p*x,y=t.width*t.height,S=n.width*n.height,L=w/(y+S-w);return Number(L.toFixed(4))}return 0}const r=[];for(const[t,n]of e)r.push({id:t,value:i(o,n)});return r.sort(I)},M=({rect:o,rects:e})=>{function i(n,s){return Math.sqrt((n.x-s.x)**2+(n.y-s.y)**2)}function r(n){return{x:n.x+n.width/2,y:n.y+n.height/2}}const t=[];for(const[n,s]of e)t.push({id:n,value:i(r(s),r(o))});return t.sort(b)};class g{listeners=[];element;constructor(e){this.element=e}add(e,i){this.element.addEventListener(e,i),this.listeners.push([e,i])}removeAll(){this.listeners.forEach(e=>{this.element.removeEventListener(...e)})}}class R{document;listeners;documentListeners;options;windowListeners;constructor(e){const{element:i}=e;this.options=e,this.document=i.ownerDocument,this.listeners=new g(i),this.documentListeners=new g(this.document),this.windowListeners=new g(this.document?.defaultView??window),this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.deactivate()}deactivate(){this.listeners.removeAll(),this.documentListeners.removeAll(),this.windowListeners.removeAll(),this.listeners.add("pointerdown",this.handleStart)}activate(){this.windowListeners.add("selectionchange",this.clearSelection),this.windowListeners.add("resize",this.handleEnd),this.windowListeners.add("visibilitychange",this.handleEnd),this.windowListeners.add("dragstart",e=>e.preventDefault()),this.windowListeners.add("contextmenu",e=>e.preventDefault()),this.documentListeners.add("pointermove",this.handleMove),this.documentListeners.add("pointerup",this.handleEnd)}handleStart(e){e.button===0&&(this.options.onStart?.({x:e.clientX,y:e.clientY}),this.activate())}handleMove(e){this.options.onMove?.({x:e.clientX,y:e.clientY}),this.clearSelection()}handleEnd(e){this.options.onEnd?.(e),this.deactivate()}clearSelection(){this.document?.getSelection()?.removeAllRanges()}}function A(o){const e=Symbol(`${o}Context`);return[i,r];function i(t){const n=l.inject(e,t);if(n||n===null)return n;throw new Error(`Injection \`${e.toString()}\` not found. Component must be used within \`${o}\``)}function r(t){return l.provide(e,t),t}}function D(o,e){return o.reduce((i,r)=>{const t=e.get(r);return t&&i.push(t),i},[])}function E(o){return o!==null&&o>=0}const[j,O]=A("DndContext");function T(o){const{rects:e,activeIndex:i,overIndex:r,index:t}=o,n=e[i];if(!n)return null;if(t===i){const u=e[r];return u?{x:0,y:i>r?n.top-u.top:u.top-n.top}:null}const s=_(e,t,i);return t>i&&t<=r?{x:0,y:-n.height-s}:t<i&&t>=r?{x:0,y:n.height-s}:{x:0,y:0}}function _(o,e,i){const r=o[e],t=o[e-1],n=o[e+1];return!r||!t&&!n?0:i<e?t?r.top-(t.top+t.height):n?n.top-(r.top+r.height):0:n?r.top-(n.top-n.height):t?t.top-(r.top+r.height):0}const $=l.defineComponent({__name:"provider",props:{items:{},collision:{type:Function,default:M},axis:{}},emits:["end"],setup(o,{emit:e}){const i=o,r=e,t=l.ref(new Map),n=l.ref(new Map),s=l.ref(null),u=l.ref(null),a=l.ref({start:null,current:{x:0,y:0}}),m=l.computed(()=>a.value.start?{x:i.axis==="y"?0:a.value.current.x-a.value.start.x,y:i.axis==="x"?0:a.value.current.y-a.value.start.y}:null),p=l.computed(()=>s.value?i.items.indexOf(s.value):null),x=l.computed(()=>u.value?i.items.indexOf(u.value):null),w=l.computed(()=>D(i.items,n.value));function y(){for(const[c,d]of t.value)n.value.set(c,d.getBoundingClientRect())}function S(){if(!s.value)return null;const c=n.value.get(s.value),d=c&&m.value?{...c,width:c.width,height:c.height,x:c.x+m.value?.x,y:c.y+m.value?.y}:null;return d?i.collision({rect:d,rects:n.value})[0]?.id??null:null}function L(c,d){const f=t.value.get(c);if(f)return new R({element:d??f,onStart(v){y(),a.value.start=v},onMove(v){a.value.start&&(s.value||(s.value=c),a.value.current.x=v.x,a.value.current.y=v.y,u.value=S())},onEnd(){s.value&&r("end",{active:s.value,over:u.value}),s.value=null,u.value=null,a.value.start=null}})}return l.watch(t,y,{deep:!0}),l.watch([s,u],([c])=>{if(!c){for(const[f,v]of t.value)v.style.transition="",v.style.position="",v.style.zIndex="",v.style.transform="";return}const d=t.value.get(c);if(d){d.style.position="relative",d.style.zIndex="1";for(const[f,v]of t.value)f!==c&&(v.style.transition="0.2s transform")}}),l.watch(m,()=>{if(!(!E(p.value)||!E(x.value))&&!(!s.value||!m.value))for(const[c,d]of t.value){let f=null;c===s.value?f=m.value:f=T({activeIndex:p.value,overIndex:x.value,rects:w.value,index:i.items.indexOf(c)}),f&&(d.style.transform=`translate(${f.x}px, ${f.y}px)`)}}),O({rects:n,activate:L,elements:t,translate:m,active:s,over:u,activeIndex:p,overIndex:x,items:l.computed(()=>i.items),sortedRects:w}),(c,d)=>l.renderSlot(c.$slots,"default")}});function V(o){const{active:e,elements:i,activate:r}=j(),{id:t,element:n,handleElement:s}=o;return l.onMounted(()=>{const a=l.toValue(n);a&&(i.value.set(t,a),r(t,l.toValue(s)))}),l.onUnmounted(()=>{i.value.delete(t)}),{isDragging:l.computed(()=>e.value===t)}}function z(o,e){const{active:i,over:r}=e;if(!r)return o;const t=o.indexOf(i),n=o.indexOf(r);if(t===n)return o;const s=o.slice(),u=s.splice(t,1)[0];return u&&s.splice(n,0,u),s}h.DndProvider=$,h.arrayMove=z,h.closestToCenter=M,h.rectangleIntersection=C,h.useSortable=V,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
{
|
2
|
+
"name": "vue-dnd-sortable",
|
3
|
+
"version": "0.1.0",
|
4
|
+
"description": "Simple sortable for vue",
|
5
|
+
"type": "module",
|
6
|
+
"main": "dist/vue-dnd.umd.js",
|
7
|
+
"module": "dist/vue-dnd.es.js",
|
8
|
+
"types": "dist/index.d.ts",
|
9
|
+
"exports": {
|
10
|
+
"import": "./dist/vue-dnd.es.js",
|
11
|
+
"require": "./dist/vue-dnd.umd.js",
|
12
|
+
"types": "./dist/index.d.ts"
|
13
|
+
},
|
14
|
+
"files": [
|
15
|
+
"dist"
|
16
|
+
],
|
17
|
+
"scripts": {
|
18
|
+
"build": "vue-tsc --declaration --emitDeclarationOnly && vite build"
|
19
|
+
},
|
20
|
+
"devDependencies": {
|
21
|
+
"@types/bun": "latest",
|
22
|
+
"@vitejs/plugin-vue": "^6.0.0",
|
23
|
+
"vite": "^7.0.0",
|
24
|
+
"vue-tsc": "^2.2.10"
|
25
|
+
},
|
26
|
+
"peerDependencies": {
|
27
|
+
"typescript": "^5.8.3"
|
28
|
+
},
|
29
|
+
"dependencies": {
|
30
|
+
"vue": "^3.5.17"
|
31
|
+
},
|
32
|
+
"keywords": [
|
33
|
+
"vue",
|
34
|
+
"dnd",
|
35
|
+
"drag",
|
36
|
+
"drop",
|
37
|
+
"sortable",
|
38
|
+
"component"
|
39
|
+
],
|
40
|
+
"author": "Hodame <hodame04@gmail.com>",
|
41
|
+
"license": "MIT"
|
42
|
+
}
|