@lvce-editor/virtual-dom 2.3.0 → 2.4.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.d.ts
CHANGED
|
@@ -50,6 +50,9 @@ export declare const applyPatch: ($Element: Node, patches: readonly Patch[]) =>
|
|
|
50
50
|
export declare const setComponentUid: ($Element: any, uid: any) => void;
|
|
51
51
|
export declare const getComponentUid: ($Element: any) => number;
|
|
52
52
|
export declare const getComponentUidFromEvent: (event: any) => number;
|
|
53
|
+
export declare const setDragInfo: (id: string | number, data: any) => void;
|
|
54
|
+
export declare const getDragInfo: (id: string | number) => any;
|
|
55
|
+
export declare const removeDragInfo: (id: string | number) => void;
|
|
53
56
|
export declare const getFileHandles: (ids: readonly number[]) => Promise<readonly FileSystemHandle[]>;
|
|
54
57
|
export declare const addFileHandle: (fileHandle: FileSystemHandle) => number;
|
|
55
58
|
export declare const setIpc: (value: any) => void;
|
package/dist/index.js
CHANGED
|
@@ -540,6 +540,17 @@ const applyPatch = ($Element, patches) => {
|
|
|
540
540
|
}
|
|
541
541
|
};
|
|
542
542
|
|
|
543
|
+
const dragInfos = Object.create(null);
|
|
544
|
+
const setDragInfo = (id, data) => {
|
|
545
|
+
dragInfos[id] = data;
|
|
546
|
+
};
|
|
547
|
+
const getDragInfo = id => {
|
|
548
|
+
return dragInfos[id];
|
|
549
|
+
};
|
|
550
|
+
const removeDragInfo = id => {
|
|
551
|
+
delete dragInfos[id];
|
|
552
|
+
};
|
|
553
|
+
|
|
543
554
|
let id = 0;
|
|
544
555
|
const create = () => {
|
|
545
556
|
return ++id;
|
|
@@ -653,6 +664,17 @@ const getEventListenerArgs = (params, event) => {
|
|
|
653
664
|
const isInputElement = element => {
|
|
654
665
|
return element instanceof HTMLInputElement;
|
|
655
666
|
};
|
|
667
|
+
const getDragTargetIndex = target => {
|
|
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
|
+
};
|
|
656
678
|
const preventEventsMaybe = (info, event) => {
|
|
657
679
|
if (info.preventDefault === 2) {
|
|
658
680
|
if (!isInputElement(event.target)) {
|
|
@@ -664,6 +686,17 @@ const preventEventsMaybe = (info, event) => {
|
|
|
664
686
|
if (info.stopPropagation) {
|
|
665
687
|
event.stopPropagation();
|
|
666
688
|
}
|
|
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
|
+
}
|
|
667
700
|
};
|
|
668
701
|
|
|
669
702
|
const createFn = info => {
|
|
@@ -813,4 +846,4 @@ const rememberFocus = ($Viewlet, dom, eventMap, uid = 0) => {
|
|
|
813
846
|
return $Viewlet;
|
|
814
847
|
};
|
|
815
848
|
|
|
816
|
-
export { addFileHandle, applyPatch, getComponentUid, getComponentUidFromEvent, getFileHandles, registerEventListeners, rememberFocus, render, renderInto, setComponentUid, setIpc };
|
|
849
|
+
export { addFileHandle, applyPatch, getComponentUid, getComponentUidFromEvent, getDragInfo, getFileHandles, registerEventListeners, rememberFocus, removeDragInfo, render, renderInto, setComponentUid, setDragInfo, setIpc };
|
package/package.json
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const dragInfos = Object.create(null)
|
|
2
|
+
|
|
3
|
+
export const setDragInfo = (id: string | number, data: any): void => {
|
|
4
|
+
dragInfos[id] = data
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const getDragInfo = (id: string | number): any => {
|
|
8
|
+
return dragInfos[id]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const removeDragInfo = (id: string | number): void => {
|
|
12
|
+
delete dragInfos[id]
|
|
13
|
+
}
|
package/src/parts/Main/Main.ts
CHANGED
|
@@ -4,6 +4,11 @@ export {
|
|
|
4
4
|
getComponentUidFromEvent,
|
|
5
5
|
setComponentUid,
|
|
6
6
|
} from '../ComponentUid/ComponentUid.ts'
|
|
7
|
+
export {
|
|
8
|
+
getDragInfo,
|
|
9
|
+
removeDragInfo,
|
|
10
|
+
setDragInfo,
|
|
11
|
+
} from '../DragInfo/DragInfo.ts'
|
|
7
12
|
export { addFileHandle, getFileHandles } from '../FileHandles/FileHandles.ts'
|
|
8
13
|
export { setIpc } from '../IpcState/IpcState.ts'
|
|
9
14
|
export { registerEventListeners } from '../RegisterEventListeners/RegisterEventListeners.ts'
|
|
@@ -2,6 +2,18 @@ const isInputElement = (element: HTMLElement): boolean => {
|
|
|
2
2
|
return element instanceof HTMLInputElement
|
|
3
3
|
}
|
|
4
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
|
+
}
|
|
16
|
+
|
|
5
17
|
export const preventEventsMaybe = (info: any, event: any): void => {
|
|
6
18
|
if (info.preventDefault === 2) {
|
|
7
19
|
if (!isInputElement(event.target)) {
|
|
@@ -13,4 +25,15 @@ export const preventEventsMaybe = (info: any, event: any): void => {
|
|
|
13
25
|
if (info.stopPropagation) {
|
|
14
26
|
event.stopPropagation()
|
|
15
27
|
}
|
|
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
|
+
}
|
|
16
39
|
}
|