vue-dnd-sortable 0.1.3 → 0.1.4
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/dist/activator.d.ts +1 -1
- package/dist/components/handle.vue.d.ts +15 -0
- package/dist/components/index.d.ts +3 -1
- package/dist/components/sortable.vue.d.ts +16 -0
- package/dist/composables.d.ts +11 -3
- package/dist/context.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/utilities/index.d.ts +1 -0
- package/dist/utilities/vue.d.ts +7 -0
- package/dist/vue-dnd.es.js +206 -149
- package/dist/vue-dnd.umd.js +1 -1
- package/package.json +1 -1
- /package/dist/components/{provider.vue.d.ts → context.vue.d.ts} +0 -0
package/dist/activator.d.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
as?: string;
|
|
3
|
+
};
|
|
4
|
+
declare var __VLS_6: {};
|
|
5
|
+
type __VLS_Slots = {} & {
|
|
6
|
+
default?: (props: typeof __VLS_6) => any;
|
|
7
|
+
};
|
|
8
|
+
declare const __VLS_component: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
9
|
+
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
|
10
|
+
export default _default;
|
|
11
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
12
|
+
new (): {
|
|
13
|
+
$slots: S;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
as?: string;
|
|
3
|
+
id: number;
|
|
4
|
+
};
|
|
5
|
+
declare var __VLS_7: {};
|
|
6
|
+
type __VLS_Slots = {} & {
|
|
7
|
+
default?: (props: typeof __VLS_7) => any;
|
|
8
|
+
};
|
|
9
|
+
declare const __VLS_component: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
10
|
+
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
|
11
|
+
export default _default;
|
|
12
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
13
|
+
new (): {
|
|
14
|
+
$slots: S;
|
|
15
|
+
};
|
|
16
|
+
};
|
package/dist/composables.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import type { MaybeRefOrGetter } from 'vue';
|
|
2
1
|
import type { UniqueIdentifier } from './types';
|
|
2
|
+
import type { MaybeComputedElementRef } from './utilities';
|
|
3
3
|
export interface SortableOptions {
|
|
4
4
|
id: UniqueIdentifier;
|
|
5
|
-
element:
|
|
6
|
-
|
|
5
|
+
element: MaybeComputedElementRef;
|
|
6
|
+
handle?: MaybeComputedElementRef;
|
|
7
7
|
}
|
|
8
|
+
interface SortableContext {
|
|
9
|
+
setHandleRef: (el: MaybeComputedElementRef) => void;
|
|
10
|
+
}
|
|
11
|
+
declare const injectSortableContext: <T extends SortableContext | null | undefined = SortableContext>(fallback?: T | undefined) => T extends null ? SortableContext | null : SortableContext;
|
|
12
|
+
export { injectSortableContext };
|
|
8
13
|
export declare function useSortable(options: SortableOptions): {
|
|
9
14
|
isDragging: import("vue").ComputedRef<boolean>;
|
|
15
|
+
elementRef: import("vue").Ref<Element | HTMLElement | SVGElement | null | undefined, Element | HTMLElement | SVGElement | null | undefined>;
|
|
16
|
+
setHandleRef: (el: MaybeComputedElementRef) => void;
|
|
10
17
|
};
|
|
18
|
+
export declare function useSetHandleRef(): (el: MaybeComputedElementRef) => void;
|
package/dist/context.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ComputedRef, Ref } from 'vue';
|
|
|
2
2
|
import type { Coords, Nullable, UniqueIdentifier } from './types';
|
|
3
3
|
import type { DomRectMap } from './utilities/rects';
|
|
4
4
|
interface DndContext {
|
|
5
|
-
elements: Ref<Map<UniqueIdentifier,
|
|
5
|
+
elements: Ref<Map<UniqueIdentifier, Element>>;
|
|
6
6
|
rects: Ref<DomRectMap>;
|
|
7
7
|
items: ComputedRef<UniqueIdentifier[]>;
|
|
8
8
|
translate: Ref<Coords | null>;
|
|
@@ -11,7 +11,7 @@ interface DndContext {
|
|
|
11
11
|
sortedRects: Ref<DOMRect[]>;
|
|
12
12
|
activeIndex: ComputedRef<number | null>;
|
|
13
13
|
overIndex: ComputedRef<number | null>;
|
|
14
|
-
activate: (id: UniqueIdentifier, handle: Nullable<
|
|
14
|
+
activate: (id: UniqueIdentifier, handle: Nullable<Element>) => void;
|
|
15
15
|
}
|
|
16
16
|
export interface DndEndEvent {
|
|
17
17
|
active: UniqueIdentifier;
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ComponentPublicInstance, MaybeRef, MaybeRefOrGetter } from 'vue';
|
|
2
|
+
export type VueInstance = ComponentPublicInstance;
|
|
3
|
+
export type MaybeElementRef<T extends MaybeElement = MaybeElement> = MaybeRef<T>;
|
|
4
|
+
export type MaybeComputedElementRef<T extends MaybeElement = MaybeElement> = MaybeRefOrGetter<T>;
|
|
5
|
+
export type MaybeElement = Element | HTMLElement | SVGElement | VueInstance | undefined | null;
|
|
6
|
+
export type UnRefElementReturn<T extends MaybeElement = MaybeElement> = T extends VueInstance ? Exclude<MaybeElement, VueInstance> : T | undefined;
|
|
7
|
+
export declare function unrefElement<T extends MaybeElement>(elRef: MaybeComputedElementRef<T>): UnRefElementReturn<T>;
|
package/dist/vue-dnd.es.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { inject as
|
|
2
|
-
function
|
|
3
|
-
return e.value -
|
|
1
|
+
import { inject as H, provide as B, toValue as z, defineComponent as L, ref as p, computed as y, watch as C, renderSlot as M, onMounted as T, onUnmounted as k, watchEffect as F, createBlock as I, openBlock as A, resolveDynamicComponent as $, unref as V, withCtx as D, useTemplateRef as X } from "vue";
|
|
2
|
+
function Y(o, e) {
|
|
3
|
+
return e.value - o.value;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
return
|
|
5
|
+
function q(o, e) {
|
|
6
|
+
return o.value - e.value;
|
|
7
7
|
}
|
|
8
|
-
const
|
|
9
|
-
function
|
|
10
|
-
const
|
|
11
|
-
if (
|
|
12
|
-
const
|
|
13
|
-
return Number(
|
|
8
|
+
const se = ({ rect: o, rects: e }) => {
|
|
9
|
+
function s(t, n) {
|
|
10
|
+
const l = Math.max(t.x, n.x), r = Math.min(t.x + t.width, n.x + n.width), c = Math.max(t.y, n.y), u = Math.min(t.y + t.height, n.y + n.height), h = r - l, f = u - c;
|
|
11
|
+
if (l < r && c < u) {
|
|
12
|
+
const x = h * f, g = t.width * t.height, S = n.width * n.height, b = x / (g + S - x);
|
|
13
|
+
return Number(b.toFixed(4));
|
|
14
14
|
}
|
|
15
15
|
return 0;
|
|
16
16
|
}
|
|
17
|
-
const
|
|
17
|
+
const i = [];
|
|
18
18
|
for (const [t, n] of e)
|
|
19
|
-
|
|
19
|
+
i.push({
|
|
20
20
|
id: t,
|
|
21
|
-
value:
|
|
21
|
+
value: s(o, n)
|
|
22
22
|
});
|
|
23
|
-
return
|
|
24
|
-
},
|
|
25
|
-
function
|
|
26
|
-
return Math.sqrt((n.x -
|
|
23
|
+
return i.sort(Y);
|
|
24
|
+
}, G = ({ rect: o, rects: e }) => {
|
|
25
|
+
function s(n, l) {
|
|
26
|
+
return Math.sqrt((n.x - l.x) ** 2 + (n.y - l.y) ** 2);
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function i(n) {
|
|
29
29
|
return {
|
|
30
30
|
x: n.x + n.width / 2,
|
|
31
31
|
y: n.y + n.height / 2
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
const t = [];
|
|
35
|
-
for (const [n,
|
|
35
|
+
for (const [n, l] of e)
|
|
36
36
|
t.push({
|
|
37
37
|
id: n,
|
|
38
|
-
value: i(
|
|
38
|
+
value: s(i(l), i(o))
|
|
39
39
|
});
|
|
40
|
-
return t.sort(
|
|
40
|
+
return t.sort(q);
|
|
41
41
|
};
|
|
42
|
-
class
|
|
42
|
+
class _ {
|
|
43
43
|
listeners = [];
|
|
44
44
|
element;
|
|
45
45
|
constructor(e) {
|
|
46
46
|
this.element = e;
|
|
47
47
|
}
|
|
48
|
-
add(e,
|
|
49
|
-
this.element.addEventListener(e,
|
|
48
|
+
add(e, s) {
|
|
49
|
+
this.element.addEventListener(e, s), this.listeners.push([e, s]);
|
|
50
50
|
}
|
|
51
51
|
removeAll() {
|
|
52
52
|
this.listeners.forEach((e) => {
|
|
@@ -54,15 +54,15 @@ class M {
|
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
class
|
|
57
|
+
class K {
|
|
58
58
|
document;
|
|
59
59
|
listeners;
|
|
60
60
|
documentListeners;
|
|
61
61
|
options;
|
|
62
62
|
windowListeners;
|
|
63
63
|
constructor(e) {
|
|
64
|
-
const { element:
|
|
65
|
-
this.options = e, this.document =
|
|
64
|
+
const { element: s } = e;
|
|
65
|
+
this.options = e, this.document = s.ownerDocument, this.listeners = new _(s), this.documentListeners = new _(this.document), this.windowListeners = new _(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
66
|
}
|
|
67
67
|
deactivate() {
|
|
68
68
|
this.listeners.removeAll(), this.documentListeners.removeAll(), this.windowListeners.removeAll(), this.listeners.add("pointerdown", this.handleStart);
|
|
@@ -89,180 +89,237 @@ class z {
|
|
|
89
89
|
this.document?.getSelection()?.removeAllRanges();
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
function
|
|
92
|
+
function j(o) {
|
|
93
93
|
const e = Symbol(
|
|
94
|
-
`${
|
|
94
|
+
`${o}Context`
|
|
95
95
|
);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
function s(t) {
|
|
97
|
+
const n = H(e, t);
|
|
98
|
+
if (n || n === null)
|
|
99
|
+
return n;
|
|
100
100
|
throw new Error(
|
|
101
|
-
`Injection \`${e.toString()}\` not found. Component must be used within \`${
|
|
101
|
+
`Injection \`${e.toString()}\` not found. Component must be used within \`${o}\``
|
|
102
102
|
);
|
|
103
103
|
}
|
|
104
|
-
function
|
|
105
|
-
return
|
|
104
|
+
function i(t) {
|
|
105
|
+
return B(e, t), t;
|
|
106
106
|
}
|
|
107
|
+
return [s, i];
|
|
107
108
|
}
|
|
108
|
-
function
|
|
109
|
-
return
|
|
110
|
-
const t = e.get(
|
|
111
|
-
return t &&
|
|
109
|
+
function N(o, e) {
|
|
110
|
+
return o.reduce((s, i) => {
|
|
111
|
+
const t = e.get(i);
|
|
112
|
+
return t && s.push(t), s;
|
|
112
113
|
}, []);
|
|
113
114
|
}
|
|
114
|
-
function
|
|
115
|
-
|
|
115
|
+
function w(o) {
|
|
116
|
+
const e = z(o);
|
|
117
|
+
return e?.$el ?? e;
|
|
116
118
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
function E(o) {
|
|
120
|
+
return o !== null && o >= 0;
|
|
121
|
+
}
|
|
122
|
+
const [U, J] = j("DndContext");
|
|
123
|
+
function P(o) {
|
|
119
124
|
const {
|
|
120
125
|
rects: e,
|
|
121
|
-
activeIndex:
|
|
122
|
-
overIndex:
|
|
126
|
+
activeIndex: s,
|
|
127
|
+
overIndex: i,
|
|
123
128
|
index: t
|
|
124
|
-
} =
|
|
129
|
+
} = o, n = e[s];
|
|
125
130
|
if (!n)
|
|
126
131
|
return null;
|
|
127
|
-
if (t ===
|
|
128
|
-
const
|
|
129
|
-
return
|
|
132
|
+
if (t === s) {
|
|
133
|
+
const r = e[i];
|
|
134
|
+
return r ? {
|
|
130
135
|
x: 0,
|
|
131
|
-
y:
|
|
136
|
+
y: s > i ? n.top - r.top : r.top - n.top
|
|
132
137
|
} : null;
|
|
133
138
|
}
|
|
134
|
-
const
|
|
135
|
-
return t >
|
|
139
|
+
const l = Q(e, t, s);
|
|
140
|
+
return t > s && t <= i ? {
|
|
136
141
|
x: 0,
|
|
137
|
-
y: -n.height -
|
|
138
|
-
} : t <
|
|
142
|
+
y: -n.height - l
|
|
143
|
+
} : t < s && t >= i ? {
|
|
139
144
|
x: 0,
|
|
140
|
-
y: n.height -
|
|
145
|
+
y: n.height - l
|
|
141
146
|
} : {
|
|
142
147
|
x: 0,
|
|
143
148
|
y: 0
|
|
144
149
|
};
|
|
145
150
|
}
|
|
146
|
-
function
|
|
147
|
-
const
|
|
148
|
-
return !
|
|
151
|
+
function Q(o, e, s) {
|
|
152
|
+
const i = o[e], t = o[e - 1], n = o[e + 1];
|
|
153
|
+
return !i || !t && !n ? 0 : s < e ? t ? i.top - (t.top + t.height) : n ? n.top - (i.top + i.height) : 0 : n ? i.top - (n.top - n.height) : t ? t.top - (i.top + i.height) : 0;
|
|
149
154
|
}
|
|
150
|
-
const
|
|
151
|
-
__name: "
|
|
155
|
+
const oe = /* @__PURE__ */ L({
|
|
156
|
+
__name: "context",
|
|
152
157
|
props: {
|
|
153
158
|
items: {},
|
|
154
|
-
collision: { type: Function, default:
|
|
159
|
+
collision: { type: Function, default: G },
|
|
155
160
|
axis: {}
|
|
156
161
|
},
|
|
157
162
|
emits: ["end"],
|
|
158
|
-
setup(
|
|
159
|
-
const
|
|
163
|
+
setup(o, { emit: e }) {
|
|
164
|
+
const s = o, i = e, t = p(/* @__PURE__ */ new Map()), n = p(/* @__PURE__ */ new Map()), l = p(/* @__PURE__ */ new Map()), r = p(null), c = p(null), u = p({
|
|
160
165
|
start: null,
|
|
161
166
|
current: { x: 0, y: 0 }
|
|
162
|
-
}),
|
|
163
|
-
x:
|
|
164
|
-
y:
|
|
165
|
-
} : null),
|
|
166
|
-
function
|
|
167
|
-
for (const [
|
|
168
|
-
n.value.set(
|
|
167
|
+
}), h = y(() => u.value.start ? {
|
|
168
|
+
x: s.axis === "y" ? 0 : u.value.current.x - u.value.start.x,
|
|
169
|
+
y: s.axis === "x" ? 0 : u.value.current.y - u.value.start.y
|
|
170
|
+
} : null), f = y(() => r.value ? s.items.indexOf(r.value) : null), x = y(() => c.value ? s.items.indexOf(c.value) : null), g = y(() => N(s.items, n.value));
|
|
171
|
+
function S() {
|
|
172
|
+
for (const [a, d] of t.value)
|
|
173
|
+
n.value.set(a, d.getBoundingClientRect());
|
|
169
174
|
}
|
|
170
|
-
function
|
|
171
|
-
if (!
|
|
175
|
+
function b() {
|
|
176
|
+
if (!r.value)
|
|
172
177
|
return null;
|
|
173
|
-
const
|
|
174
|
-
...
|
|
175
|
-
width:
|
|
176
|
-
height:
|
|
177
|
-
x:
|
|
178
|
-
y:
|
|
178
|
+
const a = n.value.get(r.value), d = a && h.value ? {
|
|
179
|
+
...a,
|
|
180
|
+
width: a.width,
|
|
181
|
+
height: a.height,
|
|
182
|
+
x: a.x + h.value?.x,
|
|
183
|
+
y: a.y + h.value?.y
|
|
179
184
|
} : null;
|
|
180
|
-
return
|
|
181
|
-
rect:
|
|
185
|
+
return d ? s.collision({
|
|
186
|
+
rect: d,
|
|
182
187
|
rects: n.value
|
|
183
188
|
})[0]?.id ?? null : null;
|
|
184
189
|
}
|
|
185
|
-
function
|
|
186
|
-
const
|
|
187
|
-
if (
|
|
188
|
-
return
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
}
|
|
190
|
+
function O(a, d) {
|
|
191
|
+
const v = t.value.get(a);
|
|
192
|
+
if (!v)
|
|
193
|
+
return;
|
|
194
|
+
const m = new K({
|
|
195
|
+
element: d ?? v,
|
|
196
|
+
onStart(R) {
|
|
197
|
+
S(), u.value.start = R;
|
|
198
|
+
},
|
|
199
|
+
onMove(R) {
|
|
200
|
+
u.value.start && (r.value || (r.value = a), u.value.current.x = R.x, u.value.current.y = R.y, c.value = b());
|
|
201
|
+
},
|
|
202
|
+
onEnd() {
|
|
203
|
+
r.value && i("end", {
|
|
204
|
+
active: r.value,
|
|
205
|
+
over: c.value
|
|
206
|
+
}), r.value = null, c.value = null, u.value.start = null;
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
l.value.set(a, m);
|
|
203
210
|
}
|
|
204
|
-
return
|
|
205
|
-
if (!
|
|
206
|
-
for (const [
|
|
207
|
-
|
|
211
|
+
return C(t, S, { deep: !0 }), C([r, c], ([a]) => {
|
|
212
|
+
if (!a) {
|
|
213
|
+
for (const [v, m] of t.value)
|
|
214
|
+
m.style.transition = "", m.style.position = "", m.style.zIndex = "", m.style.transform = "";
|
|
208
215
|
return;
|
|
209
216
|
}
|
|
210
|
-
const
|
|
211
|
-
if (
|
|
212
|
-
|
|
213
|
-
for (const [
|
|
214
|
-
|
|
217
|
+
const d = t.value.get(a);
|
|
218
|
+
if (d) {
|
|
219
|
+
d.style.position = "relative", d.style.zIndex = "1";
|
|
220
|
+
for (const [v, m] of t.value)
|
|
221
|
+
v !== a && (m.style.transition = "0.2s transform");
|
|
215
222
|
}
|
|
216
|
-
}),
|
|
217
|
-
if (!(!
|
|
218
|
-
for (const [
|
|
219
|
-
let
|
|
220
|
-
|
|
221
|
-
activeIndex:
|
|
223
|
+
}), C(h, () => {
|
|
224
|
+
if (!(!E(f.value) || !E(x.value)) && !(!r.value || !h.value))
|
|
225
|
+
for (const [a, d] of t.value) {
|
|
226
|
+
let v = null;
|
|
227
|
+
a === r.value ? v = h.value : v = P({
|
|
228
|
+
activeIndex: f.value,
|
|
222
229
|
overIndex: x.value,
|
|
223
|
-
rects:
|
|
224
|
-
index:
|
|
225
|
-
}),
|
|
230
|
+
rects: g.value,
|
|
231
|
+
index: s.items.indexOf(a)
|
|
232
|
+
}), v && (d.style.transform = `translate(${v.x}px, ${v.y}px)`);
|
|
226
233
|
}
|
|
227
|
-
}),
|
|
234
|
+
}), J({
|
|
228
235
|
rects: n,
|
|
229
|
-
activate:
|
|
236
|
+
activate: O,
|
|
230
237
|
elements: t,
|
|
231
|
-
translate:
|
|
232
|
-
active:
|
|
233
|
-
over:
|
|
234
|
-
activeIndex:
|
|
238
|
+
translate: h,
|
|
239
|
+
active: r,
|
|
240
|
+
over: c,
|
|
241
|
+
activeIndex: f,
|
|
235
242
|
overIndex: x,
|
|
236
|
-
items:
|
|
237
|
-
sortedRects:
|
|
238
|
-
}), (
|
|
243
|
+
items: y(() => s.items),
|
|
244
|
+
sortedRects: g
|
|
245
|
+
}), (a, d) => M(a.$slots, "default");
|
|
239
246
|
}
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
247
|
+
}), [
|
|
248
|
+
W,
|
|
249
|
+
Z
|
|
250
|
+
] = j("SortableContext");
|
|
251
|
+
function ee(o) {
|
|
252
|
+
const { active: e, elements: s, activate: i } = U(), { id: t, element: n, handle: l } = o, r = p(w(l)), c = p(w(n));
|
|
253
|
+
T(() => {
|
|
254
|
+
const f = w(n);
|
|
255
|
+
f && s.value.set(t, f);
|
|
256
|
+
}), k(() => {
|
|
257
|
+
s.value.delete(t);
|
|
258
|
+
}), F(() => {
|
|
259
|
+
n && (c.value = w(n)), l && (r.value = w(l)), i(t, r.value);
|
|
260
|
+
});
|
|
261
|
+
const u = y(() => e.value === t), h = (f) => {
|
|
262
|
+
r.value = w(f);
|
|
263
|
+
};
|
|
264
|
+
return Z({
|
|
265
|
+
setHandleRef: h
|
|
248
266
|
}), {
|
|
249
|
-
isDragging:
|
|
267
|
+
isDragging: u,
|
|
268
|
+
elementRef: c,
|
|
269
|
+
setHandleRef: h
|
|
250
270
|
};
|
|
251
271
|
}
|
|
252
|
-
function
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
272
|
+
function te() {
|
|
273
|
+
return W().setHandleRef;
|
|
274
|
+
}
|
|
275
|
+
const ie = /* @__PURE__ */ L({
|
|
276
|
+
__name: "handle",
|
|
277
|
+
props: {
|
|
278
|
+
as: { default: "button" }
|
|
279
|
+
},
|
|
280
|
+
setup(o) {
|
|
281
|
+
const e = te();
|
|
282
|
+
return (s, i) => (A(), I($(s.as), { ref: V(e) }, {
|
|
283
|
+
default: D(() => [
|
|
284
|
+
M(s.$slots, "default")
|
|
285
|
+
]),
|
|
286
|
+
_: 3
|
|
287
|
+
}, 512));
|
|
288
|
+
}
|
|
289
|
+
}), re = /* @__PURE__ */ L({
|
|
290
|
+
__name: "sortable",
|
|
291
|
+
props: {
|
|
292
|
+
as: { default: "div" },
|
|
293
|
+
id: {}
|
|
294
|
+
},
|
|
295
|
+
setup(o) {
|
|
296
|
+
const e = X("el");
|
|
297
|
+
return ee({ id: o.id, element: e }), (s, i) => (A(), I($(s.as), { ref: "el" }, {
|
|
298
|
+
default: D(() => [
|
|
299
|
+
M(s.$slots, "default")
|
|
300
|
+
]),
|
|
301
|
+
_: 3
|
|
302
|
+
}, 512));
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
function le(o, e) {
|
|
306
|
+
const { active: s, over: i } = e;
|
|
307
|
+
if (!i)
|
|
308
|
+
return o;
|
|
309
|
+
const t = o.indexOf(s), n = o.indexOf(i);
|
|
257
310
|
if (t === n)
|
|
258
|
-
return
|
|
259
|
-
const
|
|
260
|
-
return
|
|
311
|
+
return o;
|
|
312
|
+
const l = o.slice(), r = l.splice(t, 1)[0];
|
|
313
|
+
return r && l.splice(n, 0, r), l;
|
|
261
314
|
}
|
|
262
315
|
export {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
316
|
+
oe as SortableContext,
|
|
317
|
+
ie as SortableHandle,
|
|
318
|
+
re as SortableItem,
|
|
319
|
+
le as arrayMove,
|
|
320
|
+
G as closestToCenter,
|
|
321
|
+
W as injectSortableContext,
|
|
322
|
+
se as rectangleIntersection,
|
|
323
|
+
te as useSetHandleRef,
|
|
324
|
+
ee as useSortable
|
|
268
325
|
};
|
package/dist/vue-dnd.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(u,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],i):(u=typeof globalThis<"u"?globalThis:u||self,i(u.VueDnD={},u.Vue))})(this,function(u,i){"use strict";function D(s,e){return e.value-s.value}function $(s,e){return s.value-e.value}const j=({rect:s,rects:e})=>{function o(t,n){const a=Math.max(t.x,n.x),l=Math.min(t.x+t.width,n.x+n.width),f=Math.max(t.y,n.y),d=Math.min(t.y+t.height,n.y+n.height),v=l-a,p=d-f;if(a<l&&f<d){const y=v*p,g=t.width*t.height,S=n.width*n.height,R=y/(g+S-y);return Number(R.toFixed(4))}return 0}const r=[];for(const[t,n]of e)r.push({id:t,value:o(s,n)});return r.sort(D)},M=({rect:s,rects:e})=>{function o(n,a){return Math.sqrt((n.x-a.x)**2+(n.y-a.y)**2)}function r(n){return{x:n.x+n.width/2,y:n.y+n.height/2}}const t=[];for(const[n,a]of e)t.push({id:n,value:o(r(a),r(s))});return t.sort($)};class b{listeners=[];element;constructor(e){this.element=e}add(e,o){this.element.addEventListener(e,o),this.listeners.push([e,o])}removeAll(){this.listeners.forEach(e=>{this.element.removeEventListener(...e)})}}class O{document;listeners;documentListeners;options;windowListeners;constructor(e){const{element:o}=e;this.options=e,this.document=o.ownerDocument,this.listeners=new b(o),this.documentListeners=new b(this.document),this.windowListeners=new b(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 _(s){const e=Symbol(`${s}Context`);function o(t){const n=i.inject(e,t);if(n||n===null)return n;throw new Error(`Injection \`${e.toString()}\` not found. Component must be used within \`${s}\``)}function r(t){return i.provide(e,t),t}return[o,r]}function T(s,e){return s.reduce((o,r)=>{const t=e.get(r);return t&&o.push(t),o},[])}function w(s){const e=i.toValue(s);return e?.$el??e}function L(s){return s!==null&&s>=0}const[B,H]=_("DndContext");function k(s){const{rects:e,activeIndex:o,overIndex:r,index:t}=s,n=e[o];if(!n)return null;if(t===o){const l=e[r];return l?{x:0,y:o>r?n.top-l.top:l.top-n.top}:null}const a=V(e,t,o);return t>o&&t<=r?{x:0,y:-n.height-a}:t<o&&t>=r?{x:0,y:n.height-a}:{x:0,y:0}}function V(s,e,o){const r=s[e],t=s[e-1],n=s[e+1];return!r||!t&&!n?0:o<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 z=i.defineComponent({__name:"context",props:{items:{},collision:{type:Function,default:M},axis:{}},emits:["end"],setup(s,{emit:e}){const o=s,r=e,t=i.ref(new Map),n=i.ref(new Map),a=i.ref(new Map),l=i.ref(null),f=i.ref(null),d=i.ref({start:null,current:{x:0,y:0}}),v=i.computed(()=>d.value.start?{x:o.axis==="y"?0:d.value.current.x-d.value.start.x,y:o.axis==="x"?0:d.value.current.y-d.value.start.y}:null),p=i.computed(()=>l.value?o.items.indexOf(l.value):null),y=i.computed(()=>f.value?o.items.indexOf(f.value):null),g=i.computed(()=>T(o.items,n.value));function S(){for(const[c,h]of t.value)n.value.set(c,h.getBoundingClientRect())}function R(){if(!l.value)return null;const c=n.value.get(l.value),h=c&&v.value?{...c,width:c.width,height:c.height,x:c.x+v.value?.x,y:c.y+v.value?.y}:null;return h?o.collision({rect:h,rects:n.value})[0]?.id??null:null}function G(c,h){const m=t.value.get(c);if(!m)return;const x=new O({element:h??m,onStart(C){S(),d.value.start=C},onMove(C){d.value.start&&(l.value||(l.value=c),d.value.current.x=C.x,d.value.current.y=C.y,f.value=R())},onEnd(){l.value&&r("end",{active:l.value,over:f.value}),l.value=null,f.value=null,d.value.start=null}});a.value.set(c,x)}return i.watch(t,S,{deep:!0}),i.watch([l,f],([c])=>{if(!c){for(const[m,x]of t.value)x.style.transition="",x.style.position="",x.style.zIndex="",x.style.transform="";return}const h=t.value.get(c);if(h){h.style.position="relative",h.style.zIndex="1";for(const[m,x]of t.value)m!==c&&(x.style.transition="0.2s transform")}}),i.watch(v,()=>{if(!(!L(p.value)||!L(y.value))&&!(!l.value||!v.value))for(const[c,h]of t.value){let m=null;c===l.value?m=v.value:m=k({activeIndex:p.value,overIndex:y.value,rects:g.value,index:o.items.indexOf(c)}),m&&(h.style.transform=`translate(${m.x}px, ${m.y}px)`)}}),H({rects:n,activate:G,elements:t,translate:v,active:l,over:f,activeIndex:p,overIndex:y,items:i.computed(()=>o.items),sortedRects:g}),(c,h)=>i.renderSlot(c.$slots,"default")}}),[E,q]=_("SortableContext");function I(s){const{active:e,elements:o,activate:r}=B(),{id:t,element:n,handle:a}=s,l=i.ref(w(a)),f=i.ref(w(n));i.onMounted(()=>{const p=w(n);p&&o.value.set(t,p)}),i.onUnmounted(()=>{o.value.delete(t)}),i.watchEffect(()=>{n&&(f.value=w(n)),a&&(l.value=w(a)),r(t,l.value)});const d=i.computed(()=>e.value===t),v=p=>{l.value=w(p)};return q({setHandleRef:v}),{isDragging:d,elementRef:f,setHandleRef:v}}function A(){return E().setHandleRef}const F=i.defineComponent({__name:"handle",props:{as:{default:"button"}},setup(s){const e=A();return(o,r)=>(i.openBlock(),i.createBlock(i.resolveDynamicComponent(o.as),{ref:i.unref(e)},{default:i.withCtx(()=>[i.renderSlot(o.$slots,"default")]),_:3},512))}}),X=i.defineComponent({__name:"sortable",props:{as:{default:"div"},id:{}},setup(s){const e=i.useTemplateRef("el");return I({id:s.id,element:e}),(o,r)=>(i.openBlock(),i.createBlock(i.resolveDynamicComponent(o.as),{ref:"el"},{default:i.withCtx(()=>[i.renderSlot(o.$slots,"default")]),_:3},512))}});function Y(s,e){const{active:o,over:r}=e;if(!r)return s;const t=s.indexOf(o),n=s.indexOf(r);if(t===n)return s;const a=s.slice(),l=a.splice(t,1)[0];return l&&a.splice(n,0,l),a}u.SortableContext=z,u.SortableHandle=F,u.SortableItem=X,u.arrayMove=Y,u.closestToCenter=M,u.injectSortableContext=E,u.rectangleIntersection=j,u.useSetHandleRef=A,u.useSortable=I,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
File without changes
|