@lvce-editor/virtual-dom 2.5.0 → 2.7.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/index.js CHANGED
@@ -577,6 +577,38 @@ const addFileHandle = fileHandle => {
577
577
  return add(promise);
578
578
  };
579
579
 
580
+ const setDragImage = (dataTransfer, label) => {
581
+ const dragImage = document.createElement('div');
582
+ dragImage.className = 'DragImage';
583
+ dragImage.textContent = label;
584
+ document.body.append(dragImage);
585
+ dataTransfer.setDragImage(dragImage, -10, -10);
586
+ const handleTimeOut = () => {
587
+ dragImage.remove();
588
+ };
589
+ setTimeout(handleTimeOut, 0);
590
+ };
591
+
592
+ const applyDragInfoMaybe = event => {
593
+ const {
594
+ target,
595
+ dataTransfer
596
+ } = event;
597
+ if (dataTransfer) {
598
+ const uid = getComponentUid(target);
599
+ const dragInfo = getDragInfo(uid);
600
+ if (!dragInfo) {
601
+ return;
602
+ }
603
+ for (const item of dragInfo) {
604
+ dataTransfer.setData(item.type, item.data);
605
+ }
606
+ if (dragInfo.label) {
607
+ setDragImage(dataTransfer, dragInfo.label);
608
+ }
609
+ }
610
+ };
611
+
580
612
  let ignore = false;
581
613
  const startIgnore = () => {
582
614
  ignore = true;
@@ -676,16 +708,6 @@ const preventEventsMaybe = (info, event) => {
676
708
  if (info.stopPropagation) {
677
709
  event.stopPropagation();
678
710
  }
679
- if (event.dataTransfer) {
680
- const uid = getComponentUid(event.target);
681
- const dragInfo = getDragInfo(uid);
682
- if (!dragInfo) {
683
- return;
684
- }
685
- for (const item of info.dragInfo) {
686
- event.dataTransfer.setData(item.type, item.data);
687
- }
688
- }
689
711
  };
690
712
 
691
713
  const createFn = info => {
@@ -696,6 +718,7 @@ const createFn = info => {
696
718
  const uid = getComponentUidFromEvent(event);
697
719
  const args = getEventListenerArgs(info.params, event);
698
720
  preventEventsMaybe(info, event);
721
+ applyDragInfoMaybe(event);
699
722
  if (args.length === 0) {
700
723
  return;
701
724
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/virtual-dom",
3
- "version": "2.5.0",
3
+ "version": "2.7.0",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "keywords": [],
@@ -0,0 +1,20 @@
1
+ import { getComponentUid } from '../ComponentUid/ComponentUid.ts'
2
+ import { getDragInfo } from '../DragInfo/DragInfo.ts'
3
+ import { setDragImage } from '../SetDragImage/SetDragImage.ts'
4
+
5
+ export const applyDragInfoMaybe = (event: any): void => {
6
+ const { target, dataTransfer } = event
7
+ if (dataTransfer) {
8
+ const uid = getComponentUid(target)
9
+ const dragInfo = getDragInfo(uid)
10
+ if (!dragInfo) {
11
+ return
12
+ }
13
+ for (const item of dragInfo) {
14
+ dataTransfer.setData(item.type, item.data)
15
+ }
16
+ if (dragInfo.label) {
17
+ setDragImage(dataTransfer, dragInfo.label)
18
+ }
19
+ }
20
+ }
@@ -1,3 +1,4 @@
1
+ import { applyDragInfoMaybe } from '../ApplyDragInfoMaybe/ApplyDragInfoMaybe.ts'
1
2
  import * as ComponentUid from '../ComponentUid/ComponentUid.ts'
2
3
  import * as EventState from '../EventState/EventState.ts'
3
4
  import * as GetEventListenerArgs from '../GetEventListenerArgs/GetEventListenerArgs.ts'
@@ -13,6 +14,7 @@ export const createFn = (info): any => {
13
14
  const uid = ComponentUid.getComponentUidFromEvent(event)
14
15
  const args = GetEventListenerArgs.getEventListenerArgs(info.params, event)
15
16
  preventEventsMaybe(info, event)
17
+ applyDragInfoMaybe(event)
16
18
  if (args.length === 0) {
17
19
  return
18
20
  }
@@ -1,5 +1,3 @@
1
- import { getComponentUid } from '../ComponentUid/ComponentUid.ts'
2
- import { getDragInfo } from '../DragInfo/DragInfo.ts'
3
1
  import { isInputElement } from '../IsInputElement/IsInputElement.ts'
4
2
 
5
3
  export const preventEventsMaybe = (info: any, event: any): void => {
@@ -13,14 +11,4 @@ export const preventEventsMaybe = (info: any, event: any): void => {
13
11
  if (info.stopPropagation) {
14
12
  event.stopPropagation()
15
13
  }
16
- if (event.dataTransfer) {
17
- const uid = getComponentUid(event.target)
18
- const dragInfo = getDragInfo(uid)
19
- if (!dragInfo) {
20
- return
21
- }
22
- for (const item of info.dragInfo) {
23
- event.dataTransfer.setData(item.type, item.data)
24
- }
25
- }
26
14
  }
@@ -0,0 +1,14 @@
1
+ export const setDragImage = (
2
+ dataTransfer: DataTransfer,
3
+ label: string,
4
+ ): void => {
5
+ const dragImage = document.createElement('div')
6
+ dragImage.className = 'DragImage'
7
+ dragImage.textContent = label
8
+ document.body.append(dragImage)
9
+ dataTransfer.setDragImage(dragImage, -10, -10)
10
+ const handleTimeOut = (): void => {
11
+ dragImage.remove()
12
+ }
13
+ setTimeout(handleTimeOut, 0)
14
+ }