@havue/drag-and-drop 1.2.0 → 1.2.2

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.
@@ -37,7 +37,7 @@ class DnDManager extends EventBus {
37
37
  }
38
38
  updateDargInfo(type, data) {
39
39
  if (type === void 0 || type === null) {
40
- throw new Error("请传入拖动元素 type");
40
+ throw new Error("Expected to get a drag type, but received ", type);
41
41
  }
42
42
  this.isDragStart = true;
43
43
  this.dragType = type;
@@ -290,10 +290,6 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
290
290
  const { x, y } = params;
291
291
  const startEl = document.elementFromPoint(x, y);
292
292
  if (!props.disabled && dragItemRef.value && dragItemRef.value.contains(startEl)) {
293
- if (immediateDirections.value.includes(ImmediateEnumType.ALL)) {
294
- handleStart(params);
295
- return;
296
- }
297
293
  isDownThis.value = true;
298
294
  downPosition.x = x;
299
295
  downPosition.y = y;
@@ -301,7 +297,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
301
297
  };
302
298
  const onFirstMove = (params, event) => {
303
299
  const { x, y } = params;
304
- const directions = immediateDirections.value.filter((item) => item !== ImmediateEnumType.ALL);
300
+ const directions = immediateDirections.value;
305
301
  if (isDownThis.value && !props.disabled && directions.length) {
306
302
  const distanceH = x - downPosition.x;
307
303
  const distanceHAbs = Math.abs(distanceH);
@@ -311,11 +307,15 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
311
307
  const isMaxH = distanceHAbs === max;
312
308
  const isMaxV = distanceVAbs === max;
313
309
  let isImmediate = false;
314
- if (isMaxH) {
315
- isImmediate = directions.includes(ImmediateEnumType.LEFT) && distanceH < 0 || directions.includes(ImmediateEnumType.RIGHT) && distanceH > 0;
316
- }
317
- if (isMaxV && !isImmediate) {
318
- isImmediate = directions.includes(ImmediateEnumType.TOP) && distanceV < 0 || directions.includes(ImmediateEnumType.BOTTOM) && distanceV > 0;
310
+ if (directions.includes(ImmediateEnumType.ALL)) {
311
+ isImmediate = true;
312
+ } else {
313
+ if (isMaxH) {
314
+ isImmediate = directions.includes(ImmediateEnumType.LEFT) && distanceH < 0 || directions.includes(ImmediateEnumType.RIGHT) && distanceH > 0;
315
+ }
316
+ if (isMaxV && !isImmediate) {
317
+ isImmediate = directions.includes(ImmediateEnumType.TOP) && distanceV < 0 || directions.includes(ImmediateEnumType.BOTTOM) && distanceV > 0;
318
+ }
319
319
  }
320
320
  if (isImmediate) {
321
321
  event.preventDefault();
@@ -334,6 +334,10 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
334
334
  }
335
335
  };
336
336
  const onMove = (params) => {
337
+ if (props.disabled) {
338
+ isDragThis.value = false;
339
+ return;
340
+ }
337
341
  const { point } = params;
338
342
  if (isDragThis.value) {
339
343
  handleMove(point);
@@ -381,28 +385,20 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
381
385
  ref: dragItemRef,
382
386
  class: normalizeClass(["hv-draggable", _ctx.disabled ? "disabled" : ""])
383
387
  }, [
384
- renderSlot(_ctx.$slots, "default", {}, void 0, true),
388
+ renderSlot(_ctx.$slots, "default"),
385
389
  isDragThis.value ? (openBlock(), createElementBlock("div", {
386
390
  key: 0,
387
391
  class: "hv-draggable__clone-item",
388
392
  style: normalizeStyle(cloneNodeStyle.value)
389
393
  }, [
390
394
  renderSlot(_ctx.$slots, "drag-item", {}, () => [
391
- renderSlot(_ctx.$slots, "default", {}, void 0, true)
392
- ], true)
395
+ renderSlot(_ctx.$slots, "default")
396
+ ])
393
397
  ], 4)) : createCommentVNode("", true)
394
398
  ], 2);
395
399
  };
396
400
  }
397
401
  });
398
- const _export_sfc = (sfc, props) => {
399
- const target = sfc.__vccOpts || sfc;
400
- for (const [key, val] of props) {
401
- target[key] = val;
402
- }
403
- return target;
404
- };
405
- const Draggable = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-dc35c291"]]);
406
402
  const _sfc_main = /* @__PURE__ */ defineComponent({
407
403
  ...{
408
404
  name: "HvDroppable"
@@ -445,6 +441,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
445
441
  }
446
442
  const onMove = (params) => {
447
443
  if (props.disabled) {
444
+ isEntered.value = false;
448
445
  return;
449
446
  }
450
447
  const { type, data, point } = params;
@@ -464,13 +461,11 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
464
461
  }
465
462
  };
466
463
  const onEnd = ({ type, point, data }) => {
467
- if (props.disabled) {
468
- return;
469
- }
470
- if (dropAreaRef.value && acceptDragTypeList.value.includes(type) && isEntered.value) {
464
+ if (!props.disabled && dropAreaRef.value && acceptDragTypeList.value.includes(type) && isEntered.value) {
471
465
  const { position } = getPositionInArea(point);
472
466
  emits("drop", type, position, data);
473
467
  }
468
+ isEntered.value = false;
474
469
  };
475
470
  onMounted(() => {
476
471
  DnDManagerInstance.on("move", onMove);
@@ -491,9 +486,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
491
486
  };
492
487
  }
493
488
  });
494
- const HvDraggable = withInstall(Draggable);
489
+ const HvDraggable = withInstall(_sfc_main$1);
495
490
  const HvDroppable = withInstall(_sfc_main);
496
491
  export {
492
+ DnDManagerInstance,
497
493
  HvDraggable,
498
494
  HvDroppable
499
495
  };
@@ -38,7 +38,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
38
38
  }
39
39
  updateDargInfo(type, data) {
40
40
  if (type === void 0 || type === null) {
41
- throw new Error("请传入拖动元素 type");
41
+ throw new Error("Expected to get a drag type, but received ", type);
42
42
  }
43
43
  this.isDragStart = true;
44
44
  this.dragType = type;
@@ -291,10 +291,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
291
291
  const { x, y } = params;
292
292
  const startEl = document.elementFromPoint(x, y);
293
293
  if (!props.disabled && dragItemRef.value && dragItemRef.value.contains(startEl)) {
294
- if (immediateDirections.value.includes(ImmediateEnumType.ALL)) {
295
- handleStart(params);
296
- return;
297
- }
298
294
  isDownThis.value = true;
299
295
  downPosition.x = x;
300
296
  downPosition.y = y;
@@ -302,7 +298,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
302
298
  };
303
299
  const onFirstMove = (params, event) => {
304
300
  const { x, y } = params;
305
- const directions = immediateDirections.value.filter((item) => item !== ImmediateEnumType.ALL);
301
+ const directions = immediateDirections.value;
306
302
  if (isDownThis.value && !props.disabled && directions.length) {
307
303
  const distanceH = x - downPosition.x;
308
304
  const distanceHAbs = Math.abs(distanceH);
@@ -312,11 +308,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
312
308
  const isMaxH = distanceHAbs === max;
313
309
  const isMaxV = distanceVAbs === max;
314
310
  let isImmediate = false;
315
- if (isMaxH) {
316
- isImmediate = directions.includes(ImmediateEnumType.LEFT) && distanceH < 0 || directions.includes(ImmediateEnumType.RIGHT) && distanceH > 0;
317
- }
318
- if (isMaxV && !isImmediate) {
319
- isImmediate = directions.includes(ImmediateEnumType.TOP) && distanceV < 0 || directions.includes(ImmediateEnumType.BOTTOM) && distanceV > 0;
311
+ if (directions.includes(ImmediateEnumType.ALL)) {
312
+ isImmediate = true;
313
+ } else {
314
+ if (isMaxH) {
315
+ isImmediate = directions.includes(ImmediateEnumType.LEFT) && distanceH < 0 || directions.includes(ImmediateEnumType.RIGHT) && distanceH > 0;
316
+ }
317
+ if (isMaxV && !isImmediate) {
318
+ isImmediate = directions.includes(ImmediateEnumType.TOP) && distanceV < 0 || directions.includes(ImmediateEnumType.BOTTOM) && distanceV > 0;
319
+ }
320
320
  }
321
321
  if (isImmediate) {
322
322
  event.preventDefault();
@@ -335,6 +335,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
335
335
  }
336
336
  };
337
337
  const onMove = (params) => {
338
+ if (props.disabled) {
339
+ isDragThis.value = false;
340
+ return;
341
+ }
338
342
  const { point } = params;
339
343
  if (isDragThis.value) {
340
344
  handleMove(point);
@@ -382,28 +386,20 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
382
386
  ref: dragItemRef,
383
387
  class: vue.normalizeClass(["hv-draggable", _ctx.disabled ? "disabled" : ""])
384
388
  }, [
385
- vue.renderSlot(_ctx.$slots, "default", {}, void 0, true),
389
+ vue.renderSlot(_ctx.$slots, "default"),
386
390
  isDragThis.value ? (vue.openBlock(), vue.createElementBlock("div", {
387
391
  key: 0,
388
392
  class: "hv-draggable__clone-item",
389
393
  style: vue.normalizeStyle(cloneNodeStyle.value)
390
394
  }, [
391
395
  vue.renderSlot(_ctx.$slots, "drag-item", {}, () => [
392
- vue.renderSlot(_ctx.$slots, "default", {}, void 0, true)
393
- ], true)
396
+ vue.renderSlot(_ctx.$slots, "default")
397
+ ])
394
398
  ], 4)) : vue.createCommentVNode("", true)
395
399
  ], 2);
396
400
  };
397
401
  }
398
402
  });
399
- const _export_sfc = (sfc, props) => {
400
- const target = sfc.__vccOpts || sfc;
401
- for (const [key, val] of props) {
402
- target[key] = val;
403
- }
404
- return target;
405
- };
406
- const Draggable = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-dc35c291"]]);
407
403
  const _sfc_main = /* @__PURE__ */ vue.defineComponent({
408
404
  ...{
409
405
  name: "HvDroppable"
@@ -446,6 +442,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
446
442
  }
447
443
  const onMove = (params) => {
448
444
  if (props.disabled) {
445
+ isEntered.value = false;
449
446
  return;
450
447
  }
451
448
  const { type, data, point } = params;
@@ -465,13 +462,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
465
462
  }
466
463
  };
467
464
  const onEnd = ({ type, point, data }) => {
468
- if (props.disabled) {
469
- return;
470
- }
471
- if (dropAreaRef.value && acceptDragTypeList.value.includes(type) && isEntered.value) {
465
+ if (!props.disabled && dropAreaRef.value && acceptDragTypeList.value.includes(type) && isEntered.value) {
472
466
  const { position } = getPositionInArea(point);
473
467
  emits("drop", type, position, data);
474
468
  }
469
+ isEntered.value = false;
475
470
  };
476
471
  vue.onMounted(() => {
477
472
  DnDManagerInstance.on("move", onMove);
@@ -492,8 +487,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
492
487
  };
493
488
  }
494
489
  });
495
- const HvDraggable = withInstall(Draggable);
490
+ const HvDraggable = withInstall(_sfc_main$1);
496
491
  const HvDroppable = withInstall(_sfc_main);
492
+ exports2.DnDManagerInstance = DnDManagerInstance;
497
493
  exports2.HvDraggable = HvDraggable;
498
494
  exports2.HvDroppable = HvDroppable;
499
495
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
package/dist/style.css CHANGED
@@ -1,11 +1,11 @@
1
- .hv-draggable[data-v-dc35c291] {
1
+ .hv-draggable {
2
2
  width: fit-content;
3
3
  cursor: grab;
4
4
  }
5
- .hv-draggable.disabled[data-v-dc35c291] {
5
+ .hv-draggable.disabled {
6
6
  cursor: not-allowed;
7
7
  }
8
- .hv-draggable__clone-item[data-v-dc35c291] {
8
+ .hv-draggable__clone-item {
9
9
  position: fixed;
10
10
  top: 0;
11
11
  left: 0;
@@ -1,6 +1,8 @@
1
1
  import type { SFCWithInstall } from '@havue/utils';
2
2
  import Draggable from './Draggable.vue';
3
3
  import Droppable from './Droppable.vue';
4
+ import { DnDManagerInstance } from './manager';
4
5
  export declare const HvDraggable: SFCWithInstall<typeof Draggable>;
5
6
  export declare const HvDroppable: SFCWithInstall<typeof Droppable>;
6
- export type { DragAndDropPoint, DragAndDropDragType, DnDManager } from './manager';
7
+ export type { DragAndDropPoint, DragAndDropDragType, DnDManager, DnDManagerEvents } from './manager';
8
+ export { DnDManagerInstance };
@@ -21,11 +21,11 @@ export type DnDManagerEvents = {
21
21
  };
22
22
  export declare class DnDManager extends EventBus<DnDManagerEvents> {
23
23
  /** 是否开始拖动 | Whether to start dragging */
24
- isDragStart: boolean;
24
+ private isDragStart;
25
25
  /** 拖动元素类型 | Drag type */
26
- dragType: DragAndDropDragType | undefined;
26
+ private dragType;
27
27
  /** Draggable传递的数据,供Droppable使用 | Draggable passes data for use by Droppable */
28
- dragData: any;
28
+ private dragData;
29
29
  private isSendFirstMovePos;
30
30
  /** 长按一定时间才触发 onStart | Press and hold for a certain amount of time to trigger onStart */
31
31
  private touchStartPressTime;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@havue/drag-and-drop",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
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.2.0"
19
+ "@havue/shared": "^1.2.2"
20
20
  },
21
21
  "devDependencies": {
22
22
  "vue": "^3.3.0"