@havue/drag-and-drop 1.1.1 → 1.2.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/dist/drag-and-drop.mjs
CHANGED
|
@@ -2,8 +2,8 @@ import './style.css';
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
import { defineComponent, ref, reactive, computed, createElementBlock, openBlock, normalizeClass, renderSlot, createCommentVNode, normalizeStyle } from "vue";
|
|
6
|
-
import { EventBus
|
|
5
|
+
import { defineComponent, ref, reactive, computed, onMounted, onBeforeUnmount, createElementBlock, openBlock, normalizeClass, renderSlot, createCommentVNode, normalizeStyle } from "vue";
|
|
6
|
+
import { EventBus } from "@havue/shared";
|
|
7
7
|
const withInstall = (main, extra) => {
|
|
8
8
|
main.install = (app) => {
|
|
9
9
|
for (const comp of [main, ...Object.values({})]) {
|
|
@@ -15,22 +15,20 @@ const withInstall = (main, extra) => {
|
|
|
15
15
|
class DnDManager extends EventBus {
|
|
16
16
|
constructor() {
|
|
17
17
|
super();
|
|
18
|
-
/** 是否开始拖动 */
|
|
18
|
+
/** 是否开始拖动 | Whether to start dragging */
|
|
19
19
|
__publicField(this, "isDragStart", false);
|
|
20
|
-
/** 拖动元素类型 */
|
|
20
|
+
/** 拖动元素类型 | Drag type */
|
|
21
21
|
__publicField(this, "dragType");
|
|
22
|
-
/** Draggable
|
|
23
|
-
* 供Droppable使用
|
|
24
|
-
*/
|
|
22
|
+
/** Draggable传递的数据,供Droppable使用 | Draggable passes data for use by Droppable */
|
|
25
23
|
__publicField(this, "dragData");
|
|
26
24
|
__publicField(this, "isSendFirstMovePos", false);
|
|
27
|
-
/**
|
|
25
|
+
/** 长按一定时间才触发 onStart | Press and hold for a certain amount of time to trigger onStart */
|
|
28
26
|
__publicField(this, "touchStartPressTime", 300);
|
|
29
|
-
/**
|
|
27
|
+
/** 点击触发时的时间 | The time at which the click is triggered */
|
|
30
28
|
__publicField(this, "touchStartTime", 0);
|
|
31
|
-
/**
|
|
29
|
+
/** 点击触发的位置 | The position where the click event is triggered */
|
|
32
30
|
__publicField(this, "touchStartPosition", { x: 0, y: 0 });
|
|
33
|
-
/** onMove最后位置 */
|
|
31
|
+
/** onMove最后位置 | onMove last position */
|
|
34
32
|
__publicField(this, "lastMovePoint", { x: 0, y: 0 });
|
|
35
33
|
__publicField(this, "emitTouchStartTimer");
|
|
36
34
|
__publicField(this, "destroy", () => {
|
|
@@ -48,14 +46,14 @@ class DnDManager extends EventBus {
|
|
|
48
46
|
this.emitTouchStartTimer = void 0;
|
|
49
47
|
}
|
|
50
48
|
/**
|
|
51
|
-
* 通知 Draggable 开始点击
|
|
49
|
+
* 通知 Draggable 开始点击 | Tell Draggable to start clicking
|
|
52
50
|
* @param point
|
|
53
51
|
*/
|
|
54
52
|
onDown(point) {
|
|
55
53
|
this.emit("down", point);
|
|
56
54
|
}
|
|
57
55
|
/**
|
|
58
|
-
*
|
|
56
|
+
* 第一次移动时,通知 Draggable | On the first move, notify Draggable
|
|
59
57
|
* @param point
|
|
60
58
|
*/
|
|
61
59
|
onFirstMove(point, e) {
|
|
@@ -66,7 +64,7 @@ class DnDManager extends EventBus {
|
|
|
66
64
|
this.emit("first-move", point, e);
|
|
67
65
|
}
|
|
68
66
|
/**
|
|
69
|
-
* 通知 Draggable 拖拽开始
|
|
67
|
+
* 通知 Draggable 拖拽开始 | Notify Draggable to begin the drag
|
|
70
68
|
* @param point
|
|
71
69
|
*/
|
|
72
70
|
onStart(point) {
|
|
@@ -76,7 +74,7 @@ class DnDManager extends EventBus {
|
|
|
76
74
|
this.emit("start", point);
|
|
77
75
|
}
|
|
78
76
|
/**
|
|
79
|
-
* 通知 Draggable 移动
|
|
77
|
+
* 通知 Draggable 移动 | Notify Draggable to move
|
|
80
78
|
* @param point
|
|
81
79
|
* @returns
|
|
82
80
|
*/
|
|
@@ -92,7 +90,7 @@ class DnDManager extends EventBus {
|
|
|
92
90
|
});
|
|
93
91
|
}
|
|
94
92
|
/**
|
|
95
|
-
* 结束拖拽
|
|
93
|
+
* 结束拖拽 | Ending drag
|
|
96
94
|
* @returns
|
|
97
95
|
*/
|
|
98
96
|
onEnd() {
|
|
@@ -217,15 +215,12 @@ class DnDManager extends EventBus {
|
|
|
217
215
|
const onMouseDown = this.onMouseDown.bind(this);
|
|
218
216
|
const onMouseMove = this.onMouseMove.bind(this);
|
|
219
217
|
const onMouseUp = this.onMouseUp.bind(this);
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
document.body.addEventListener("mousemove", onMouseMove);
|
|
227
|
-
document.body.addEventListener("mouseup", onMouseUp);
|
|
228
|
-
}
|
|
218
|
+
document.body.addEventListener("touchstart", onTouchStart, { passive: false });
|
|
219
|
+
document.body.addEventListener("touchmove", onTouchMove, { passive: false });
|
|
220
|
+
document.body.addEventListener("touchend", onTouchEnd, { passive: false });
|
|
221
|
+
document.body.addEventListener("mousedown", onMouseDown);
|
|
222
|
+
document.body.addEventListener("mousemove", onMouseMove);
|
|
223
|
+
document.body.addEventListener("mouseup", onMouseUp);
|
|
229
224
|
this.destroy = () => {
|
|
230
225
|
document.body.removeEventListener("touchstart", onTouchStart);
|
|
231
226
|
document.body.removeEventListener("touchmove", onTouchMove);
|
|
@@ -291,7 +286,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
291
286
|
transform: `translate(${cloneNodePosition.x}px, ${cloneNodePosition.y}px) translate(-50%, -50%)`
|
|
292
287
|
};
|
|
293
288
|
});
|
|
294
|
-
|
|
289
|
+
const onDown = (params) => {
|
|
295
290
|
const { x, y } = params;
|
|
296
291
|
const startEl = document.elementFromPoint(x, y);
|
|
297
292
|
if (!props.disabled && dragItemRef.value && dragItemRef.value.contains(startEl)) {
|
|
@@ -303,8 +298,8 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
303
298
|
downPosition.x = x;
|
|
304
299
|
downPosition.y = y;
|
|
305
300
|
}
|
|
306
|
-
}
|
|
307
|
-
|
|
301
|
+
};
|
|
302
|
+
const onFirstMove = (params, event) => {
|
|
308
303
|
const { x, y } = params;
|
|
309
304
|
const directions = immediateDirections.value.filter((item) => item !== ImmediateEnumType.ALL);
|
|
310
305
|
if (isDownThis.value && !props.disabled && directions.length) {
|
|
@@ -330,21 +325,21 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
330
325
|
return;
|
|
331
326
|
}
|
|
332
327
|
}
|
|
333
|
-
}
|
|
334
|
-
|
|
328
|
+
};
|
|
329
|
+
const onStart = (params) => {
|
|
335
330
|
const { x, y } = params;
|
|
336
331
|
const startEl = document.elementFromPoint(x, y);
|
|
337
332
|
if (!props.disabled && dragItemRef.value && dragItemRef.value.contains(startEl)) {
|
|
338
333
|
handleStart(params);
|
|
339
334
|
}
|
|
340
|
-
}
|
|
341
|
-
|
|
335
|
+
};
|
|
336
|
+
const onMove = (params) => {
|
|
342
337
|
const { point } = params;
|
|
343
338
|
if (isDragThis.value) {
|
|
344
339
|
handleMove(point);
|
|
345
340
|
}
|
|
346
|
-
}
|
|
347
|
-
|
|
341
|
+
};
|
|
342
|
+
const onEnd = () => {
|
|
348
343
|
isDownThis.value = false;
|
|
349
344
|
isDragThis.value = false;
|
|
350
345
|
Object.assign(downPosition, {
|
|
@@ -355,7 +350,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
355
350
|
x: 0,
|
|
356
351
|
y: 0
|
|
357
352
|
});
|
|
358
|
-
}
|
|
353
|
+
};
|
|
359
354
|
function handleStart(point) {
|
|
360
355
|
isDragThis.value = true;
|
|
361
356
|
cloneNodePosition.x = point.x;
|
|
@@ -366,6 +361,20 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
366
361
|
cloneNodePosition.x = point.x;
|
|
367
362
|
cloneNodePosition.y = point.y;
|
|
368
363
|
}
|
|
364
|
+
onMounted(() => {
|
|
365
|
+
DnDManagerInstance.on("down", onDown);
|
|
366
|
+
DnDManagerInstance.on("first-move", onFirstMove);
|
|
367
|
+
DnDManagerInstance.on("start", onStart);
|
|
368
|
+
DnDManagerInstance.on("move", onMove);
|
|
369
|
+
DnDManagerInstance.on("end", onEnd);
|
|
370
|
+
});
|
|
371
|
+
onBeforeUnmount(() => {
|
|
372
|
+
DnDManagerInstance.off("down", onDown);
|
|
373
|
+
DnDManagerInstance.off("first-move", onFirstMove);
|
|
374
|
+
DnDManagerInstance.off("start", onStart);
|
|
375
|
+
DnDManagerInstance.off("move", onMove);
|
|
376
|
+
DnDManagerInstance.off("end", onEnd);
|
|
377
|
+
});
|
|
369
378
|
return (_ctx, _cache) => {
|
|
370
379
|
return openBlock(), createElementBlock("div", {
|
|
371
380
|
ref_key: "dragItemRef",
|
|
@@ -378,7 +387,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
378
387
|
class: "hv-draggable__clone-item",
|
|
379
388
|
style: normalizeStyle(cloneNodeStyle.value)
|
|
380
389
|
}, [
|
|
381
|
-
renderSlot(_ctx.$slots, "
|
|
390
|
+
renderSlot(_ctx.$slots, "drag-item", {}, () => [
|
|
382
391
|
renderSlot(_ctx.$slots, "default", {}, void 0, true)
|
|
383
392
|
], true)
|
|
384
393
|
], 4)) : createCommentVNode("", true)
|
|
@@ -393,14 +402,15 @@ const _export_sfc = (sfc, props) => {
|
|
|
393
402
|
}
|
|
394
403
|
return target;
|
|
395
404
|
};
|
|
396
|
-
const Draggable = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-
|
|
405
|
+
const Draggable = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-dc35c291"]]);
|
|
397
406
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
398
407
|
...{
|
|
399
408
|
name: "HvDroppable"
|
|
400
409
|
},
|
|
401
410
|
__name: "Droppable",
|
|
402
411
|
props: {
|
|
403
|
-
acceptDragType: {}
|
|
412
|
+
acceptDragType: {},
|
|
413
|
+
disabled: { type: Boolean }
|
|
404
414
|
},
|
|
405
415
|
emits: ["enter", "move", "drop", "leave"],
|
|
406
416
|
setup(__props, { emit: __emit }) {
|
|
@@ -433,7 +443,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
433
443
|
}
|
|
434
444
|
};
|
|
435
445
|
}
|
|
436
|
-
|
|
446
|
+
const onMove = (params) => {
|
|
447
|
+
if (props.disabled) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
437
450
|
const { type, data, point } = params;
|
|
438
451
|
if (dropAreaRef.value && acceptDragTypeList.value.includes(type)) {
|
|
439
452
|
const { isInArea, position } = getPositionInArea(point);
|
|
@@ -449,12 +462,23 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
449
462
|
emits("leave", type, data);
|
|
450
463
|
}
|
|
451
464
|
}
|
|
452
|
-
}
|
|
453
|
-
|
|
465
|
+
};
|
|
466
|
+
const onEnd = ({ type, point, data }) => {
|
|
467
|
+
if (props.disabled) {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
454
470
|
if (dropAreaRef.value && acceptDragTypeList.value.includes(type) && isEntered.value) {
|
|
455
471
|
const { position } = getPositionInArea(point);
|
|
456
472
|
emits("drop", type, position, data);
|
|
457
473
|
}
|
|
474
|
+
};
|
|
475
|
+
onMounted(() => {
|
|
476
|
+
DnDManagerInstance.on("move", onMove);
|
|
477
|
+
DnDManagerInstance.on("end", onEnd);
|
|
478
|
+
});
|
|
479
|
+
onBeforeUnmount(() => {
|
|
480
|
+
DnDManagerInstance.off("move", onMove);
|
|
481
|
+
DnDManagerInstance.off("end", onEnd);
|
|
458
482
|
});
|
|
459
483
|
return (_ctx, _cache) => {
|
|
460
484
|
return openBlock(), createElementBlock("div", {
|
|
@@ -16,22 +16,20 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
16
16
|
class DnDManager extends shared.EventBus {
|
|
17
17
|
constructor() {
|
|
18
18
|
super();
|
|
19
|
-
/** 是否开始拖动 */
|
|
19
|
+
/** 是否开始拖动 | Whether to start dragging */
|
|
20
20
|
__publicField(this, "isDragStart", false);
|
|
21
|
-
/** 拖动元素类型 */
|
|
21
|
+
/** 拖动元素类型 | Drag type */
|
|
22
22
|
__publicField(this, "dragType");
|
|
23
|
-
/** Draggable
|
|
24
|
-
* 供Droppable使用
|
|
25
|
-
*/
|
|
23
|
+
/** Draggable传递的数据,供Droppable使用 | Draggable passes data for use by Droppable */
|
|
26
24
|
__publicField(this, "dragData");
|
|
27
25
|
__publicField(this, "isSendFirstMovePos", false);
|
|
28
|
-
/**
|
|
26
|
+
/** 长按一定时间才触发 onStart | Press and hold for a certain amount of time to trigger onStart */
|
|
29
27
|
__publicField(this, "touchStartPressTime", 300);
|
|
30
|
-
/**
|
|
28
|
+
/** 点击触发时的时间 | The time at which the click is triggered */
|
|
31
29
|
__publicField(this, "touchStartTime", 0);
|
|
32
|
-
/**
|
|
30
|
+
/** 点击触发的位置 | The position where the click event is triggered */
|
|
33
31
|
__publicField(this, "touchStartPosition", { x: 0, y: 0 });
|
|
34
|
-
/** onMove最后位置 */
|
|
32
|
+
/** onMove最后位置 | onMove last position */
|
|
35
33
|
__publicField(this, "lastMovePoint", { x: 0, y: 0 });
|
|
36
34
|
__publicField(this, "emitTouchStartTimer");
|
|
37
35
|
__publicField(this, "destroy", () => {
|
|
@@ -49,14 +47,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
49
47
|
this.emitTouchStartTimer = void 0;
|
|
50
48
|
}
|
|
51
49
|
/**
|
|
52
|
-
* 通知 Draggable 开始点击
|
|
50
|
+
* 通知 Draggable 开始点击 | Tell Draggable to start clicking
|
|
53
51
|
* @param point
|
|
54
52
|
*/
|
|
55
53
|
onDown(point) {
|
|
56
54
|
this.emit("down", point);
|
|
57
55
|
}
|
|
58
56
|
/**
|
|
59
|
-
*
|
|
57
|
+
* 第一次移动时,通知 Draggable | On the first move, notify Draggable
|
|
60
58
|
* @param point
|
|
61
59
|
*/
|
|
62
60
|
onFirstMove(point, e) {
|
|
@@ -67,7 +65,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
67
65
|
this.emit("first-move", point, e);
|
|
68
66
|
}
|
|
69
67
|
/**
|
|
70
|
-
* 通知 Draggable 拖拽开始
|
|
68
|
+
* 通知 Draggable 拖拽开始 | Notify Draggable to begin the drag
|
|
71
69
|
* @param point
|
|
72
70
|
*/
|
|
73
71
|
onStart(point) {
|
|
@@ -77,7 +75,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
77
75
|
this.emit("start", point);
|
|
78
76
|
}
|
|
79
77
|
/**
|
|
80
|
-
* 通知 Draggable 移动
|
|
78
|
+
* 通知 Draggable 移动 | Notify Draggable to move
|
|
81
79
|
* @param point
|
|
82
80
|
* @returns
|
|
83
81
|
*/
|
|
@@ -93,7 +91,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
93
91
|
});
|
|
94
92
|
}
|
|
95
93
|
/**
|
|
96
|
-
* 结束拖拽
|
|
94
|
+
* 结束拖拽 | Ending drag
|
|
97
95
|
* @returns
|
|
98
96
|
*/
|
|
99
97
|
onEnd() {
|
|
@@ -218,15 +216,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
218
216
|
const onMouseDown = this.onMouseDown.bind(this);
|
|
219
217
|
const onMouseMove = this.onMouseMove.bind(this);
|
|
220
218
|
const onMouseUp = this.onMouseUp.bind(this);
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
document.body.addEventListener("mousemove", onMouseMove);
|
|
228
|
-
document.body.addEventListener("mouseup", onMouseUp);
|
|
229
|
-
}
|
|
219
|
+
document.body.addEventListener("touchstart", onTouchStart, { passive: false });
|
|
220
|
+
document.body.addEventListener("touchmove", onTouchMove, { passive: false });
|
|
221
|
+
document.body.addEventListener("touchend", onTouchEnd, { passive: false });
|
|
222
|
+
document.body.addEventListener("mousedown", onMouseDown);
|
|
223
|
+
document.body.addEventListener("mousemove", onMouseMove);
|
|
224
|
+
document.body.addEventListener("mouseup", onMouseUp);
|
|
230
225
|
this.destroy = () => {
|
|
231
226
|
document.body.removeEventListener("touchstart", onTouchStart);
|
|
232
227
|
document.body.removeEventListener("touchmove", onTouchMove);
|
|
@@ -292,7 +287,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
292
287
|
transform: `translate(${cloneNodePosition.x}px, ${cloneNodePosition.y}px) translate(-50%, -50%)`
|
|
293
288
|
};
|
|
294
289
|
});
|
|
295
|
-
|
|
290
|
+
const onDown = (params) => {
|
|
296
291
|
const { x, y } = params;
|
|
297
292
|
const startEl = document.elementFromPoint(x, y);
|
|
298
293
|
if (!props.disabled && dragItemRef.value && dragItemRef.value.contains(startEl)) {
|
|
@@ -304,8 +299,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
304
299
|
downPosition.x = x;
|
|
305
300
|
downPosition.y = y;
|
|
306
301
|
}
|
|
307
|
-
}
|
|
308
|
-
|
|
302
|
+
};
|
|
303
|
+
const onFirstMove = (params, event) => {
|
|
309
304
|
const { x, y } = params;
|
|
310
305
|
const directions = immediateDirections.value.filter((item) => item !== ImmediateEnumType.ALL);
|
|
311
306
|
if (isDownThis.value && !props.disabled && directions.length) {
|
|
@@ -331,21 +326,21 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
331
326
|
return;
|
|
332
327
|
}
|
|
333
328
|
}
|
|
334
|
-
}
|
|
335
|
-
|
|
329
|
+
};
|
|
330
|
+
const onStart = (params) => {
|
|
336
331
|
const { x, y } = params;
|
|
337
332
|
const startEl = document.elementFromPoint(x, y);
|
|
338
333
|
if (!props.disabled && dragItemRef.value && dragItemRef.value.contains(startEl)) {
|
|
339
334
|
handleStart(params);
|
|
340
335
|
}
|
|
341
|
-
}
|
|
342
|
-
|
|
336
|
+
};
|
|
337
|
+
const onMove = (params) => {
|
|
343
338
|
const { point } = params;
|
|
344
339
|
if (isDragThis.value) {
|
|
345
340
|
handleMove(point);
|
|
346
341
|
}
|
|
347
|
-
}
|
|
348
|
-
|
|
342
|
+
};
|
|
343
|
+
const onEnd = () => {
|
|
349
344
|
isDownThis.value = false;
|
|
350
345
|
isDragThis.value = false;
|
|
351
346
|
Object.assign(downPosition, {
|
|
@@ -356,7 +351,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
356
351
|
x: 0,
|
|
357
352
|
y: 0
|
|
358
353
|
});
|
|
359
|
-
}
|
|
354
|
+
};
|
|
360
355
|
function handleStart(point) {
|
|
361
356
|
isDragThis.value = true;
|
|
362
357
|
cloneNodePosition.x = point.x;
|
|
@@ -367,6 +362,20 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
367
362
|
cloneNodePosition.x = point.x;
|
|
368
363
|
cloneNodePosition.y = point.y;
|
|
369
364
|
}
|
|
365
|
+
vue.onMounted(() => {
|
|
366
|
+
DnDManagerInstance.on("down", onDown);
|
|
367
|
+
DnDManagerInstance.on("first-move", onFirstMove);
|
|
368
|
+
DnDManagerInstance.on("start", onStart);
|
|
369
|
+
DnDManagerInstance.on("move", onMove);
|
|
370
|
+
DnDManagerInstance.on("end", onEnd);
|
|
371
|
+
});
|
|
372
|
+
vue.onBeforeUnmount(() => {
|
|
373
|
+
DnDManagerInstance.off("down", onDown);
|
|
374
|
+
DnDManagerInstance.off("first-move", onFirstMove);
|
|
375
|
+
DnDManagerInstance.off("start", onStart);
|
|
376
|
+
DnDManagerInstance.off("move", onMove);
|
|
377
|
+
DnDManagerInstance.off("end", onEnd);
|
|
378
|
+
});
|
|
370
379
|
return (_ctx, _cache) => {
|
|
371
380
|
return vue.openBlock(), vue.createElementBlock("div", {
|
|
372
381
|
ref_key: "dragItemRef",
|
|
@@ -379,7 +388,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
379
388
|
class: "hv-draggable__clone-item",
|
|
380
389
|
style: vue.normalizeStyle(cloneNodeStyle.value)
|
|
381
390
|
}, [
|
|
382
|
-
vue.renderSlot(_ctx.$slots, "
|
|
391
|
+
vue.renderSlot(_ctx.$slots, "drag-item", {}, () => [
|
|
383
392
|
vue.renderSlot(_ctx.$slots, "default", {}, void 0, true)
|
|
384
393
|
], true)
|
|
385
394
|
], 4)) : vue.createCommentVNode("", true)
|
|
@@ -394,14 +403,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
394
403
|
}
|
|
395
404
|
return target;
|
|
396
405
|
};
|
|
397
|
-
const Draggable = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-
|
|
406
|
+
const Draggable = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-dc35c291"]]);
|
|
398
407
|
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
|
|
399
408
|
...{
|
|
400
409
|
name: "HvDroppable"
|
|
401
410
|
},
|
|
402
411
|
__name: "Droppable",
|
|
403
412
|
props: {
|
|
404
|
-
acceptDragType: {}
|
|
413
|
+
acceptDragType: {},
|
|
414
|
+
disabled: { type: Boolean }
|
|
405
415
|
},
|
|
406
416
|
emits: ["enter", "move", "drop", "leave"],
|
|
407
417
|
setup(__props, { emit: __emit }) {
|
|
@@ -434,7 +444,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
434
444
|
}
|
|
435
445
|
};
|
|
436
446
|
}
|
|
437
|
-
|
|
447
|
+
const onMove = (params) => {
|
|
448
|
+
if (props.disabled) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
438
451
|
const { type, data, point } = params;
|
|
439
452
|
if (dropAreaRef.value && acceptDragTypeList.value.includes(type)) {
|
|
440
453
|
const { isInArea, position } = getPositionInArea(point);
|
|
@@ -450,12 +463,23 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
450
463
|
emits("leave", type, data);
|
|
451
464
|
}
|
|
452
465
|
}
|
|
453
|
-
}
|
|
454
|
-
|
|
466
|
+
};
|
|
467
|
+
const onEnd = ({ type, point, data }) => {
|
|
468
|
+
if (props.disabled) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
455
471
|
if (dropAreaRef.value && acceptDragTypeList.value.includes(type) && isEntered.value) {
|
|
456
472
|
const { position } = getPositionInArea(point);
|
|
457
473
|
emits("drop", type, position, data);
|
|
458
474
|
}
|
|
475
|
+
};
|
|
476
|
+
vue.onMounted(() => {
|
|
477
|
+
DnDManagerInstance.on("move", onMove);
|
|
478
|
+
DnDManagerInstance.on("end", onEnd);
|
|
479
|
+
});
|
|
480
|
+
vue.onBeforeUnmount(() => {
|
|
481
|
+
DnDManagerInstance.off("move", onMove);
|
|
482
|
+
DnDManagerInstance.off("end", onEnd);
|
|
459
483
|
});
|
|
460
484
|
return (_ctx, _cache) => {
|
|
461
485
|
return vue.openBlock(), vue.createElementBlock("div", {
|
package/dist/style.css
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
.hv-draggable[data-v-
|
|
1
|
+
.hv-draggable[data-v-dc35c291] {
|
|
2
2
|
width: fit-content;
|
|
3
3
|
cursor: grab;
|
|
4
4
|
}
|
|
5
|
-
.hv-draggable.disabled[data-v-
|
|
5
|
+
.hv-draggable.disabled[data-v-dc35c291] {
|
|
6
6
|
cursor: not-allowed;
|
|
7
7
|
}
|
|
8
|
-
.hv-draggable__clone-item[data-v-
|
|
8
|
+
.hv-draggable__clone-item[data-v-dc35c291] {
|
|
9
9
|
position: fixed;
|
|
10
10
|
top: 0;
|
|
11
11
|
left: 0;
|
|
@@ -14,7 +14,7 @@ type __VLS_Props = {
|
|
|
14
14
|
data?: any;
|
|
15
15
|
};
|
|
16
16
|
declare const dragItemRef: import("vue").Ref<HTMLElement | undefined, HTMLElement | undefined>;
|
|
17
|
-
/** 是否开始拖动 */
|
|
17
|
+
/** 是否开始拖动 | Whether to start dragging */
|
|
18
18
|
declare const isDragThis: import("vue").Ref<boolean, boolean>;
|
|
19
19
|
declare const cloneNodeStyle: import("vue").ComputedRef<{
|
|
20
20
|
transform: string;
|
|
@@ -24,7 +24,7 @@ declare var __VLS_1: {}, __VLS_3: {}, __VLS_5: {};
|
|
|
24
24
|
type __VLS_Slots = __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.$slots> & {
|
|
25
25
|
default?: (props: typeof __VLS_1) => any;
|
|
26
26
|
} & {
|
|
27
|
-
'
|
|
27
|
+
'drag-item'?: (props: typeof __VLS_3) => any;
|
|
28
28
|
} & {
|
|
29
29
|
default?: (props: typeof __VLS_5) => any;
|
|
30
30
|
}>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { DragAndDropDragType, DragAndDropPoint } from './manager';
|
|
2
2
|
type __VLS_Props = {
|
|
3
3
|
acceptDragType: DragAndDropDragType | Array<DragAndDropDragType>;
|
|
4
|
+
disabled?: boolean;
|
|
4
5
|
};
|
|
5
6
|
declare const dropAreaRef: import("vue").Ref<HTMLElement | undefined, HTMLElement | undefined>;
|
|
6
7
|
declare const __VLS_ctx: InstanceType<__VLS_PickNotAny<typeof __VLS_self, new () => {}>>;
|
|
@@ -4,7 +4,7 @@ export type DragAndDropPoint = {
|
|
|
4
4
|
y: number;
|
|
5
5
|
};
|
|
6
6
|
export type DragAndDropDragType = string | number | symbol;
|
|
7
|
-
type
|
|
7
|
+
export type DnDManagerEvents = {
|
|
8
8
|
down: (p: DragAndDropPoint) => void;
|
|
9
9
|
'first-move': (p: DragAndDropPoint, e: MouseEvent | TouchEvent) => void;
|
|
10
10
|
start: (p: DragAndDropPoint) => void;
|
|
@@ -19,51 +19,49 @@ type Events = {
|
|
|
19
19
|
point: DragAndDropPoint;
|
|
20
20
|
}) => void;
|
|
21
21
|
};
|
|
22
|
-
export declare class DnDManager extends EventBus<
|
|
23
|
-
/** 是否开始拖动 */
|
|
22
|
+
export declare class DnDManager extends EventBus<DnDManagerEvents> {
|
|
23
|
+
/** 是否开始拖动 | Whether to start dragging */
|
|
24
24
|
isDragStart: boolean;
|
|
25
|
-
/** 拖动元素类型 */
|
|
25
|
+
/** 拖动元素类型 | Drag type */
|
|
26
26
|
dragType: DragAndDropDragType | undefined;
|
|
27
|
-
/** Draggable
|
|
28
|
-
* 供Droppable使用
|
|
29
|
-
*/
|
|
27
|
+
/** Draggable传递的数据,供Droppable使用 | Draggable passes data for use by Droppable */
|
|
30
28
|
dragData: any;
|
|
31
29
|
private isSendFirstMovePos;
|
|
32
|
-
/**
|
|
30
|
+
/** 长按一定时间才触发 onStart | Press and hold for a certain amount of time to trigger onStart */
|
|
33
31
|
private touchStartPressTime;
|
|
34
|
-
/**
|
|
32
|
+
/** 点击触发时的时间 | The time at which the click is triggered */
|
|
35
33
|
private touchStartTime;
|
|
36
|
-
/**
|
|
34
|
+
/** 点击触发的位置 | The position where the click event is triggered */
|
|
37
35
|
private touchStartPosition;
|
|
38
|
-
/** onMove最后位置 */
|
|
36
|
+
/** onMove最后位置 | onMove last position */
|
|
39
37
|
private lastMovePoint;
|
|
40
38
|
private emitTouchStartTimer;
|
|
41
39
|
private destroy;
|
|
42
40
|
constructor();
|
|
43
41
|
updateDargInfo(type: Exclude<DragAndDropDragType, undefined>, data: any): void;
|
|
44
42
|
/**
|
|
45
|
-
* 通知 Draggable 开始点击
|
|
43
|
+
* 通知 Draggable 开始点击 | Tell Draggable to start clicking
|
|
46
44
|
* @param point
|
|
47
45
|
*/
|
|
48
46
|
private onDown;
|
|
49
47
|
/**
|
|
50
|
-
*
|
|
48
|
+
* 第一次移动时,通知 Draggable | On the first move, notify Draggable
|
|
51
49
|
* @param point
|
|
52
50
|
*/
|
|
53
51
|
private onFirstMove;
|
|
54
52
|
/**
|
|
55
|
-
* 通知 Draggable 拖拽开始
|
|
53
|
+
* 通知 Draggable 拖拽开始 | Notify Draggable to begin the drag
|
|
56
54
|
* @param point
|
|
57
55
|
*/
|
|
58
56
|
private onStart;
|
|
59
57
|
/**
|
|
60
|
-
* 通知 Draggable 移动
|
|
58
|
+
* 通知 Draggable 移动 | Notify Draggable to move
|
|
61
59
|
* @param point
|
|
62
60
|
* @returns
|
|
63
61
|
*/
|
|
64
62
|
private onMove;
|
|
65
63
|
/**
|
|
66
|
-
* 结束拖拽
|
|
64
|
+
* 结束拖拽 | Ending drag
|
|
67
65
|
* @returns
|
|
68
66
|
*/
|
|
69
67
|
private onEnd;
|
|
@@ -78,4 +76,3 @@ export declare class DnDManager extends EventBus<Events> {
|
|
|
78
76
|
destroyed(): void;
|
|
79
77
|
}
|
|
80
78
|
export declare const DnDManagerInstance: DnDManager;
|
|
81
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@havue/drag-and-drop",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Drag and drop components for Vue3",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"havue",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"url": "git+https://github.com/HappyPedestrian/havue.git"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@havue/shared": "^1.
|
|
19
|
+
"@havue/shared": "^1.2.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"vue": "^3.3.0"
|