@lvce-editor/explorer-view 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.
|
@@ -1013,6 +1013,7 @@ const get$1 = id => {
|
|
|
1013
1013
|
|
|
1014
1014
|
const invoke = (method, ...params) => {
|
|
1015
1015
|
const rpc = get$1(RendererWorker);
|
|
1016
|
+
// @ts-ignore
|
|
1016
1017
|
return rpc.invoke(method, ...params);
|
|
1017
1018
|
};
|
|
1018
1019
|
|
|
@@ -1795,6 +1796,13 @@ const focusFirst = state => {
|
|
|
1795
1796
|
const lastIndex = array => {
|
|
1796
1797
|
return array.length - 1;
|
|
1797
1798
|
};
|
|
1799
|
+
const fromAsync = async asyncIterable => {
|
|
1800
|
+
const children = [];
|
|
1801
|
+
for await (const value of asyncIterable) {
|
|
1802
|
+
children.push(value);
|
|
1803
|
+
}
|
|
1804
|
+
return children;
|
|
1805
|
+
};
|
|
1798
1806
|
|
|
1799
1807
|
const focusLast = state => {
|
|
1800
1808
|
const {
|
|
@@ -2616,8 +2624,55 @@ const handleDragOver = (state, x, y) => {
|
|
|
2616
2624
|
};
|
|
2617
2625
|
};
|
|
2618
2626
|
|
|
2627
|
+
const getChildHandles = async fileHandle => {
|
|
2628
|
+
// @ts-ignore
|
|
2629
|
+
const values = fileHandle.values();
|
|
2630
|
+
const children = await fromAsync(values);
|
|
2631
|
+
return children;
|
|
2632
|
+
};
|
|
2633
|
+
|
|
2634
|
+
const getFileHandleText = async fileHandle => {
|
|
2635
|
+
const file = await fileHandle.getFile();
|
|
2636
|
+
const text = await file.text();
|
|
2637
|
+
return text;
|
|
2638
|
+
};
|
|
2639
|
+
|
|
2640
|
+
const isDirectoryHandle = fileHandle => {
|
|
2641
|
+
return fileHandle.kind === 'directory';
|
|
2642
|
+
};
|
|
2643
|
+
|
|
2644
|
+
const isFileHandle = fileHandle => {
|
|
2645
|
+
return fileHandle.kind === 'file';
|
|
2646
|
+
};
|
|
2647
|
+
|
|
2648
|
+
const createUploadTree = async (root, fileHandles) => {
|
|
2649
|
+
const uploadTree = Object.create(null);
|
|
2650
|
+
for (const fileHandle of fileHandles) {
|
|
2651
|
+
const name = fileHandle.name;
|
|
2652
|
+
if (isDirectoryHandle(fileHandle)) {
|
|
2653
|
+
const children = await getChildHandles(fileHandle);
|
|
2654
|
+
const childTree = await createUploadTree(name, children);
|
|
2655
|
+
uploadTree[name] = childTree;
|
|
2656
|
+
} else if (isFileHandle(fileHandle)) {
|
|
2657
|
+
const text = await getFileHandleText(fileHandle);
|
|
2658
|
+
uploadTree[name] = text;
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
return uploadTree;
|
|
2662
|
+
};
|
|
2663
|
+
|
|
2619
2664
|
const uploadFileSystemHandles = async (root, pathSeparator, fileSystemHandles) => {
|
|
2620
|
-
|
|
2665
|
+
const uploadTree = await createUploadTree(root, fileSystemHandles);
|
|
2666
|
+
console.log({
|
|
2667
|
+
uploadTree
|
|
2668
|
+
});
|
|
2669
|
+
|
|
2670
|
+
// TODO
|
|
2671
|
+
// 1. in electron, use webutils.getPathForFile to see if a path is available
|
|
2672
|
+
// 2. else, walk all files and folders recursively and upload all of them (if there are many, show a progress bar)
|
|
2673
|
+
|
|
2674
|
+
// TODO send file system operations to renderer worker
|
|
2675
|
+
return true;
|
|
2621
2676
|
};
|
|
2622
2677
|
|
|
2623
2678
|
const mergeDirents$2 = (oldDirents, newDirents) => {
|
|
@@ -2637,7 +2692,7 @@ const handleDrop$2 = async (state, files) => {
|
|
|
2637
2692
|
pathSeparator,
|
|
2638
2693
|
items
|
|
2639
2694
|
} = state;
|
|
2640
|
-
const handled = await uploadFileSystemHandles();
|
|
2695
|
+
const handled = await uploadFileSystemHandles(root, pathSeparator, files);
|
|
2641
2696
|
if (handled) {
|
|
2642
2697
|
return state;
|
|
2643
2698
|
}
|
|
@@ -2726,8 +2781,9 @@ const handleDropIntoFolder = async (state, dirent, index, files) => {
|
|
|
2726
2781
|
// @ts-ignore
|
|
2727
2782
|
for (const file of files) {
|
|
2728
2783
|
// TODO path basename
|
|
2729
|
-
const baseName = file;
|
|
2784
|
+
const baseName = file.name;
|
|
2730
2785
|
const to = dirent.path + pathSeparator + baseName;
|
|
2786
|
+
// @ts-ignore
|
|
2731
2787
|
await copy$1(file, to);
|
|
2732
2788
|
}
|
|
2733
2789
|
const childDirents = await getChildDirents(pathSeparator, dirent);
|
|
@@ -2777,8 +2833,15 @@ const getDropHandler = index => {
|
|
|
2777
2833
|
return handleDropIndex;
|
|
2778
2834
|
}
|
|
2779
2835
|
};
|
|
2780
|
-
|
|
2836
|
+
|
|
2837
|
+
const getFileHandles = async fileIds => {
|
|
2838
|
+
const files = await invoke('FileSystemHandle.getFileHandles', fileIds);
|
|
2839
|
+
return files;
|
|
2840
|
+
};
|
|
2841
|
+
|
|
2842
|
+
const handleDrop = async (state, x, y, fileIds) => {
|
|
2781
2843
|
try {
|
|
2844
|
+
const files = await getFileHandles(fileIds);
|
|
2782
2845
|
const index = getIndexFromPosition(state, x, y);
|
|
2783
2846
|
const fn = getDropHandler(index);
|
|
2784
2847
|
const result = await fn(state, files, index);
|
|
@@ -3813,7 +3876,7 @@ const renderEventListeners = () => {
|
|
|
3813
3876
|
preventDefault: true
|
|
3814
3877
|
}, {
|
|
3815
3878
|
name: HandleDrop,
|
|
3816
|
-
params: ['handleDrop', 'event.clientX', 'event.clientY', 'event.dataTransfer.
|
|
3879
|
+
params: ['handleDrop', 'event.clientX', 'event.clientY', 'event.dataTransfer.files2'],
|
|
3817
3880
|
preventDefault: true
|
|
3818
3881
|
}];
|
|
3819
3882
|
};
|