@lvce-editor/virtual-dom 2.4.0 → 2.6.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 +34 -22
- package/package.json +1 -1
- package/src/parts/ApplyDragInfoMaybe/ApplyDragInfoMaybe.ts +20 -0
- package/src/parts/CreateEventListenerFunction/CreateEventListenerFunction.ts +2 -0
- package/src/parts/IsInputElement/IsInputElement.ts +3 -0
- package/src/parts/PreventEventsMaybe/PreventEventsMaybe.ts +1 -26
- package/src/parts/SetDragImage/SetDragImage.ts +14 -0
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;
|
|
@@ -664,17 +696,7 @@ const getEventListenerArgs = (params, event) => {
|
|
|
664
696
|
const isInputElement = element => {
|
|
665
697
|
return element instanceof HTMLInputElement;
|
|
666
698
|
};
|
|
667
|
-
|
|
668
|
-
if (target.dataset.index) {
|
|
669
|
-
return Number.parseInt(target.dataset.index);
|
|
670
|
-
}
|
|
671
|
-
const parentNode = target.closest('[data-index]');
|
|
672
|
-
if (!parentNode) {
|
|
673
|
-
return -1;
|
|
674
|
-
}
|
|
675
|
-
// @ts-ignore
|
|
676
|
-
return Number.parseInt(parentNode.dataset.index);
|
|
677
|
-
};
|
|
699
|
+
|
|
678
700
|
const preventEventsMaybe = (info, event) => {
|
|
679
701
|
if (info.preventDefault === 2) {
|
|
680
702
|
if (!isInputElement(event.target)) {
|
|
@@ -686,17 +708,6 @@ const preventEventsMaybe = (info, event) => {
|
|
|
686
708
|
if (info.stopPropagation) {
|
|
687
709
|
event.stopPropagation();
|
|
688
710
|
}
|
|
689
|
-
if (event.dataTransfer) {
|
|
690
|
-
const index = getDragTargetIndex(event.target);
|
|
691
|
-
if (info.dragInfo) {
|
|
692
|
-
for (const item of info.dragInfo) {
|
|
693
|
-
event.dataTransfer.setData(item.type, item.data + index);
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
if (info.dragEffect) {
|
|
697
|
-
event.dataTransfer.effectAllowed = info.dragEffect;
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
711
|
};
|
|
701
712
|
|
|
702
713
|
const createFn = info => {
|
|
@@ -707,6 +718,7 @@ const createFn = info => {
|
|
|
707
718
|
const uid = getComponentUidFromEvent(event);
|
|
708
719
|
const args = getEventListenerArgs(info.params, event);
|
|
709
720
|
preventEventsMaybe(info, event);
|
|
721
|
+
applyDragInfoMaybe(event);
|
|
710
722
|
if (args.length === 0) {
|
|
711
723
|
return;
|
|
712
724
|
}
|
package/package.json
CHANGED
|
@@ -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,18 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
return element instanceof HTMLInputElement
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
const getDragTargetIndex = (target: HTMLElement): number => {
|
|
6
|
-
if (target.dataset.index) {
|
|
7
|
-
return Number.parseInt(target.dataset.index)
|
|
8
|
-
}
|
|
9
|
-
const parentNode = target.closest('[data-index]')
|
|
10
|
-
if (!parentNode) {
|
|
11
|
-
return -1
|
|
12
|
-
}
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
return Number.parseInt(parentNode.dataset.index)
|
|
15
|
-
}
|
|
1
|
+
import { isInputElement } from '../IsInputElement/IsInputElement.ts'
|
|
16
2
|
|
|
17
3
|
export const preventEventsMaybe = (info: any, event: any): void => {
|
|
18
4
|
if (info.preventDefault === 2) {
|
|
@@ -25,15 +11,4 @@ export const preventEventsMaybe = (info: any, event: any): void => {
|
|
|
25
11
|
if (info.stopPropagation) {
|
|
26
12
|
event.stopPropagation()
|
|
27
13
|
}
|
|
28
|
-
if (event.dataTransfer) {
|
|
29
|
-
const index = getDragTargetIndex(event.target)
|
|
30
|
-
if (info.dragInfo) {
|
|
31
|
-
for (const item of info.dragInfo) {
|
|
32
|
-
event.dataTransfer.setData(item.type, item.data + index)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (info.dragEffect) {
|
|
36
|
-
event.dataTransfer.effectAllowed = info.dragEffect
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
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
|
+
}
|