@lvce-editor/explorer-view 2.3.0 → 2.5.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/explorerViewWorkerMain.js +146 -33
- package/package.json +1 -1
|
@@ -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 {
|
|
@@ -2002,7 +2010,7 @@ const rename = () => {
|
|
|
2002
2010
|
const deleteItem = () => {
|
|
2003
2011
|
return i18nString(Delete);
|
|
2004
2012
|
};
|
|
2005
|
-
const refresh = () => {
|
|
2013
|
+
const refresh$1 = () => {
|
|
2006
2014
|
return i18nString(RefreshExplorer);
|
|
2007
2015
|
};
|
|
2008
2016
|
const collapseAll = () => {
|
|
@@ -2616,11 +2624,125 @@ const handleDragOver = (state, x, y) => {
|
|
|
2616
2624
|
};
|
|
2617
2625
|
};
|
|
2618
2626
|
|
|
2619
|
-
const
|
|
2620
|
-
|
|
2627
|
+
const getTopLevelDirents = (root, pathSeparator, excluded) => {
|
|
2628
|
+
if (!root) {
|
|
2629
|
+
return [];
|
|
2630
|
+
}
|
|
2631
|
+
return getChildDirents(pathSeparator, {
|
|
2632
|
+
depth: 0,
|
|
2633
|
+
path: root,
|
|
2634
|
+
type: Directory
|
|
2635
|
+
}, excluded);
|
|
2621
2636
|
};
|
|
2622
2637
|
|
|
2623
2638
|
const mergeDirents$2 = (oldDirents, newDirents) => {
|
|
2639
|
+
const merged = [];
|
|
2640
|
+
for (const newDirent of newDirents) {
|
|
2641
|
+
merged.push(newDirent);
|
|
2642
|
+
}
|
|
2643
|
+
return merged;
|
|
2644
|
+
};
|
|
2645
|
+
|
|
2646
|
+
// TODO add lots of tests for this
|
|
2647
|
+
const refresh = async state1 => {
|
|
2648
|
+
const topLevelDirents = await getTopLevelDirents(state1.root, state1.pathSeparator, []);
|
|
2649
|
+
const newDirents = mergeDirents$2(state1.items, topLevelDirents);
|
|
2650
|
+
const state3 = {
|
|
2651
|
+
...state1,
|
|
2652
|
+
items: newDirents
|
|
2653
|
+
};
|
|
2654
|
+
return state3;
|
|
2655
|
+
};
|
|
2656
|
+
|
|
2657
|
+
const applyOperation = operation => {
|
|
2658
|
+
if (operation.type === 'createFolder') {
|
|
2659
|
+
return mkdir(operation.path);
|
|
2660
|
+
}
|
|
2661
|
+
return writeFile(operation.path, operation.text);
|
|
2662
|
+
};
|
|
2663
|
+
const applyFileOperations = async operations => {
|
|
2664
|
+
// TODO run operations in parallel if possible
|
|
2665
|
+
for (const operation of operations) {
|
|
2666
|
+
await applyOperation(operation);
|
|
2667
|
+
}
|
|
2668
|
+
};
|
|
2669
|
+
|
|
2670
|
+
const getChildHandles = async fileHandle => {
|
|
2671
|
+
// @ts-ignore
|
|
2672
|
+
const values = fileHandle.values();
|
|
2673
|
+
const children = await fromAsync(values);
|
|
2674
|
+
return children;
|
|
2675
|
+
};
|
|
2676
|
+
|
|
2677
|
+
const getFileHandleText = async fileHandle => {
|
|
2678
|
+
const file = await fileHandle.getFile();
|
|
2679
|
+
const text = await file.text();
|
|
2680
|
+
return text;
|
|
2681
|
+
};
|
|
2682
|
+
|
|
2683
|
+
const isDirectoryHandle = fileHandle => {
|
|
2684
|
+
return fileHandle.kind === 'directory';
|
|
2685
|
+
};
|
|
2686
|
+
|
|
2687
|
+
const isFileHandle = fileHandle => {
|
|
2688
|
+
return fileHandle.kind === 'file';
|
|
2689
|
+
};
|
|
2690
|
+
|
|
2691
|
+
const createUploadTree = async (root, fileHandles) => {
|
|
2692
|
+
const uploadTree = Object.create(null);
|
|
2693
|
+
for (const fileHandle of fileHandles) {
|
|
2694
|
+
const name = fileHandle.name;
|
|
2695
|
+
if (isDirectoryHandle(fileHandle)) {
|
|
2696
|
+
const children = await getChildHandles(fileHandle);
|
|
2697
|
+
const childTree = await createUploadTree(name, children);
|
|
2698
|
+
uploadTree[name] = childTree;
|
|
2699
|
+
} else if (isFileHandle(fileHandle)) {
|
|
2700
|
+
const text = await getFileHandleText(fileHandle);
|
|
2701
|
+
uploadTree[name] = text;
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
return uploadTree;
|
|
2705
|
+
};
|
|
2706
|
+
|
|
2707
|
+
const getFileOperations = (root, uploadTree) => {
|
|
2708
|
+
const operations = [];
|
|
2709
|
+
const processTree = (tree, currentPath) => {
|
|
2710
|
+
for (const [path, value] of Object.entries(tree)) {
|
|
2711
|
+
const fullPath = currentPath ? `${currentPath}/${path}` : path;
|
|
2712
|
+
if (typeof value === 'object') {
|
|
2713
|
+
operations.push({
|
|
2714
|
+
type: 'createFolder',
|
|
2715
|
+
path: `${root}/${fullPath}`,
|
|
2716
|
+
text: ''
|
|
2717
|
+
});
|
|
2718
|
+
processTree(value, fullPath);
|
|
2719
|
+
} else if (typeof value === 'string') {
|
|
2720
|
+
operations.push({
|
|
2721
|
+
type: 'createFile',
|
|
2722
|
+
path: `${root}/${fullPath}`,
|
|
2723
|
+
text: value
|
|
2724
|
+
});
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
};
|
|
2728
|
+
processTree(uploadTree, '');
|
|
2729
|
+
return operations;
|
|
2730
|
+
};
|
|
2731
|
+
|
|
2732
|
+
const uploadFileSystemHandles = async (root, pathSeparator, fileSystemHandles) => {
|
|
2733
|
+
const uploadTree = await createUploadTree(root, fileSystemHandles);
|
|
2734
|
+
const fileOperations = getFileOperations(root, uploadTree);
|
|
2735
|
+
await applyFileOperations(fileOperations);
|
|
2736
|
+
|
|
2737
|
+
// TODO
|
|
2738
|
+
// 1. in electron, use webutils.getPathForFile to see if a path is available
|
|
2739
|
+
// 2. else, walk all files and folders recursively and upload all of them (if there are many, show a progress bar)
|
|
2740
|
+
|
|
2741
|
+
// TODO send file system operations to renderer worker
|
|
2742
|
+
return true;
|
|
2743
|
+
};
|
|
2744
|
+
|
|
2745
|
+
const mergeDirents$1 = (oldDirents, newDirents) => {
|
|
2624
2746
|
return newDirents;
|
|
2625
2747
|
};
|
|
2626
2748
|
const getMergedDirents$2 = async (root, pathSeparator, dirents) => {
|
|
@@ -2628,7 +2750,7 @@ const getMergedDirents$2 = async (root, pathSeparator, dirents) => {
|
|
|
2628
2750
|
path: root,
|
|
2629
2751
|
depth: 0
|
|
2630
2752
|
});
|
|
2631
|
-
const mergedDirents = mergeDirents$
|
|
2753
|
+
const mergedDirents = mergeDirents$1(dirents, childDirents);
|
|
2632
2754
|
return mergedDirents;
|
|
2633
2755
|
};
|
|
2634
2756
|
const handleDrop$2 = async (state, files) => {
|
|
@@ -2637,9 +2759,10 @@ const handleDrop$2 = async (state, files) => {
|
|
|
2637
2759
|
pathSeparator,
|
|
2638
2760
|
items
|
|
2639
2761
|
} = state;
|
|
2640
|
-
const handled = await uploadFileSystemHandles();
|
|
2762
|
+
const handled = await uploadFileSystemHandles(root, pathSeparator, files);
|
|
2641
2763
|
if (handled) {
|
|
2642
|
-
|
|
2764
|
+
const updated = await refresh(state);
|
|
2765
|
+
return updated;
|
|
2643
2766
|
}
|
|
2644
2767
|
const mergedDirents = await getMergedDirents$2(root, pathSeparator, items);
|
|
2645
2768
|
return {
|
|
@@ -2653,7 +2776,7 @@ const getFilePathElectron = async file => {
|
|
|
2653
2776
|
return invoke('GetFilePathElectron.getFilePathElectron', file);
|
|
2654
2777
|
};
|
|
2655
2778
|
|
|
2656
|
-
const mergeDirents
|
|
2779
|
+
const mergeDirents = (oldDirents, newDirents) => {
|
|
2657
2780
|
return newDirents;
|
|
2658
2781
|
};
|
|
2659
2782
|
|
|
@@ -2671,7 +2794,7 @@ const getMergedDirents$1 = async (root, pathSeparator, dirents) => {
|
|
|
2671
2794
|
path: root,
|
|
2672
2795
|
depth: 0
|
|
2673
2796
|
});
|
|
2674
|
-
const mergedDirents = mergeDirents
|
|
2797
|
+
const mergedDirents = mergeDirents(dirents, childDirents);
|
|
2675
2798
|
return mergedDirents;
|
|
2676
2799
|
};
|
|
2677
2800
|
const handleDrop$1 = async (state, files) => {
|
|
@@ -2726,8 +2849,9 @@ const handleDropIntoFolder = async (state, dirent, index, files) => {
|
|
|
2726
2849
|
// @ts-ignore
|
|
2727
2850
|
for (const file of files) {
|
|
2728
2851
|
// TODO path basename
|
|
2729
|
-
const baseName = file;
|
|
2852
|
+
const baseName = file.name;
|
|
2730
2853
|
const to = dirent.path + pathSeparator + baseName;
|
|
2854
|
+
// @ts-ignore
|
|
2731
2855
|
await copy$1(file, to);
|
|
2732
2856
|
}
|
|
2733
2857
|
const childDirents = await getChildDirents(pathSeparator, dirent);
|
|
@@ -2777,8 +2901,15 @@ const getDropHandler = index => {
|
|
|
2777
2901
|
return handleDropIndex;
|
|
2778
2902
|
}
|
|
2779
2903
|
};
|
|
2780
|
-
|
|
2904
|
+
|
|
2905
|
+
const getFileHandles = async fileIds => {
|
|
2906
|
+
const files = await invoke('FileSystemHandle.getFileHandles', fileIds);
|
|
2907
|
+
return files;
|
|
2908
|
+
};
|
|
2909
|
+
|
|
2910
|
+
const handleDrop = async (state, x, y, fileIds) => {
|
|
2781
2911
|
try {
|
|
2912
|
+
const files = await getFileHandles(fileIds);
|
|
2782
2913
|
const index = getIndexFromPosition(state, x, y);
|
|
2783
2914
|
const fn = getDropHandler(index);
|
|
2784
2915
|
const result = await fn(state, files, index);
|
|
@@ -2828,25 +2959,6 @@ const handleIconThemeChange = state => {
|
|
|
2828
2959
|
return updateIcons(state);
|
|
2829
2960
|
};
|
|
2830
2961
|
|
|
2831
|
-
const getTopLevelDirents = (root, pathSeparator, excluded) => {
|
|
2832
|
-
if (!root) {
|
|
2833
|
-
return [];
|
|
2834
|
-
}
|
|
2835
|
-
return getChildDirents(pathSeparator, {
|
|
2836
|
-
depth: 0,
|
|
2837
|
-
path: root,
|
|
2838
|
-
type: Directory
|
|
2839
|
-
}, excluded);
|
|
2840
|
-
};
|
|
2841
|
-
|
|
2842
|
-
const mergeDirents = (oldDirents, newDirents) => {
|
|
2843
|
-
const merged = [];
|
|
2844
|
-
for (const newDirent of newDirents) {
|
|
2845
|
-
merged.push(newDirent);
|
|
2846
|
-
}
|
|
2847
|
-
return merged;
|
|
2848
|
-
};
|
|
2849
|
-
|
|
2850
2962
|
// TODO add lots of tests for this
|
|
2851
2963
|
const updateRoot = async state1 => {
|
|
2852
2964
|
// @ts-ignore
|
|
@@ -2855,13 +2967,13 @@ const updateRoot = async state1 => {
|
|
|
2855
2967
|
}
|
|
2856
2968
|
// const file = nativeFiles.files[0]
|
|
2857
2969
|
// @ts-ignore
|
|
2858
|
-
const topLevelDirents = await getTopLevelDirents(state1.root, state1.pathSeparator);
|
|
2970
|
+
const topLevelDirents = await getTopLevelDirents(state1.root, state1.pathSeparator, []);
|
|
2859
2971
|
// const state2 = Viewlet.getState('Explorer')
|
|
2860
2972
|
// // TODO what if root changes while reading directories?
|
|
2861
2973
|
// if (state2.disposed || state2.root !== state1.root) {
|
|
2862
2974
|
// return state2
|
|
2863
2975
|
// }
|
|
2864
|
-
const newDirents = mergeDirents(state1.items, topLevelDirents);
|
|
2976
|
+
const newDirents = mergeDirents$2(state1.items, topLevelDirents);
|
|
2865
2977
|
const state3 = {
|
|
2866
2978
|
...state1,
|
|
2867
2979
|
items: newDirents
|
|
@@ -3712,7 +3824,7 @@ const getActions = root => {
|
|
|
3712
3824
|
command: 'newFolder'
|
|
3713
3825
|
}, {
|
|
3714
3826
|
type: Button,
|
|
3715
|
-
id: refresh(),
|
|
3827
|
+
id: refresh$1(),
|
|
3716
3828
|
icon: Refresh,
|
|
3717
3829
|
command: 'refresh'
|
|
3718
3830
|
}, {
|
|
@@ -3813,7 +3925,7 @@ const renderEventListeners = () => {
|
|
|
3813
3925
|
preventDefault: true
|
|
3814
3926
|
}, {
|
|
3815
3927
|
name: HandleDrop,
|
|
3816
|
-
params: ['handleDrop', 'event.clientX', 'event.clientY', 'event.dataTransfer.
|
|
3928
|
+
params: ['handleDrop', 'event.clientX', 'event.clientY', 'event.dataTransfer.files2'],
|
|
3817
3929
|
preventDefault: true
|
|
3818
3930
|
}];
|
|
3819
3931
|
};
|
|
@@ -4169,6 +4281,7 @@ const commandMap = {
|
|
|
4169
4281
|
'Explorer.newFile': wrapCommand(newFile),
|
|
4170
4282
|
'Explorer.newFolder': wrapCommand(newFolder),
|
|
4171
4283
|
'Explorer.openContainingFolder': wrapCommand(openContainingFolder),
|
|
4284
|
+
'Explorer.refresh': wrapCommand(refresh),
|
|
4172
4285
|
'Explorer.removeDirent': wrapCommand(removeDirent),
|
|
4173
4286
|
'Explorer.renameDirent': wrapCommand(renameDirent),
|
|
4174
4287
|
'Explorer.restoreState': restoreState,
|