@lvce-editor/explorer-view 1.4.0 → 1.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/README.md +2 -0
- package/dist/explorerViewWorkerMain.js +161 -42
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -847,6 +847,9 @@ const getFileIcon = ({
|
|
|
847
847
|
const getIcon = dirent => {
|
|
848
848
|
return '';
|
|
849
849
|
};
|
|
850
|
+
const getFolderIcon = dirent => {
|
|
851
|
+
return '';
|
|
852
|
+
};
|
|
850
853
|
|
|
851
854
|
// TODO use posInSet and setSize properties to compute more effectively
|
|
852
855
|
const computeExplorerRenamedDirent = (dirents, index, newName) => {
|
|
@@ -948,15 +951,45 @@ const CreateFile = 1;
|
|
|
948
951
|
const CreateFolder = 2;
|
|
949
952
|
const Rename = 3;
|
|
950
953
|
|
|
951
|
-
const
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
const
|
|
955
|
-
const
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
const
|
|
954
|
+
const state = {
|
|
955
|
+
rpc: undefined
|
|
956
|
+
};
|
|
957
|
+
const invoke = (method, ...params) => {
|
|
958
|
+
const rpc = state.rpc;
|
|
959
|
+
// @ts-ignore
|
|
960
|
+
return rpc.invoke(method, ...params);
|
|
961
|
+
};
|
|
962
|
+
const setRpc = rpc => {
|
|
963
|
+
state.rpc = rpc;
|
|
964
|
+
};
|
|
965
|
+
|
|
966
|
+
const remove = async dirent => {
|
|
967
|
+
return invoke('FileSystem.remove', dirent);
|
|
968
|
+
};
|
|
969
|
+
const readDirWithFileTypes = async uri => {
|
|
970
|
+
return invoke('FileSystem.readDirWithFileTypes', uri);
|
|
971
|
+
};
|
|
972
|
+
const getPathSeparator$1 = async root => {
|
|
973
|
+
return invoke('FileSystem.getPathSeparator', root);
|
|
974
|
+
};
|
|
975
|
+
const getRealPath = async path => {
|
|
976
|
+
return invoke('FileSystem.getRealPath', path);
|
|
977
|
+
};
|
|
978
|
+
const stat = async dirent => {
|
|
979
|
+
return invoke('FileSystem.stat', dirent);
|
|
980
|
+
};
|
|
981
|
+
const createFile = async uri => {
|
|
982
|
+
return invoke('FileSystem.createFile', uri);
|
|
983
|
+
};
|
|
984
|
+
const mkdir = async uri => {
|
|
985
|
+
return invoke('FileSystem.mkdir', uri);
|
|
986
|
+
};
|
|
987
|
+
const rename$1 = async (oldUri, newUri) => {
|
|
988
|
+
return invoke('FileSystem.rename', oldUri, newUri);
|
|
989
|
+
};
|
|
990
|
+
const copy$1 = async (oldUri, newUri) => {
|
|
991
|
+
return invoke('FileSystem.copy', oldUri, newUri);
|
|
992
|
+
};
|
|
960
993
|
|
|
961
994
|
const dirname = (pathSeparator, path) => {
|
|
962
995
|
const index = path.lastIndexOf(pathSeparator);
|
|
@@ -1121,18 +1154,6 @@ const copyPath$1 = async state => {
|
|
|
1121
1154
|
return state;
|
|
1122
1155
|
};
|
|
1123
1156
|
|
|
1124
|
-
const state = {
|
|
1125
|
-
rpc: undefined
|
|
1126
|
-
};
|
|
1127
|
-
const invoke = (method, ...params) => {
|
|
1128
|
-
const rpc = state.rpc;
|
|
1129
|
-
// @ts-ignore
|
|
1130
|
-
return rpc.invoke(method, ...params);
|
|
1131
|
-
};
|
|
1132
|
-
const setRpc = rpc => {
|
|
1133
|
-
state.rpc = rpc;
|
|
1134
|
-
};
|
|
1135
|
-
|
|
1136
1157
|
const writeText = async text => {
|
|
1137
1158
|
await invoke('ClipBoard.writeText', /* text */text);
|
|
1138
1159
|
};
|
|
@@ -1292,7 +1313,7 @@ const hasSymbolicLinks = rawDirents => {
|
|
|
1292
1313
|
return rawDirents.some(isSymbolicLink);
|
|
1293
1314
|
};
|
|
1294
1315
|
const getChildDirentsRaw = async uri => {
|
|
1295
|
-
const rawDirents = await readDirWithFileTypes();
|
|
1316
|
+
const rawDirents = await readDirWithFileTypes(uri);
|
|
1296
1317
|
array(rawDirents);
|
|
1297
1318
|
if (hasSymbolicLinks(rawDirents)) {
|
|
1298
1319
|
return resolveSymbolicLinks(uri, rawDirents);
|
|
@@ -2208,8 +2229,8 @@ const handleClickDirectoryExpanded$1 = (state, dirent, index, keepFocus) => {
|
|
|
2208
2229
|
};
|
|
2209
2230
|
};
|
|
2210
2231
|
const handleClickSymLink$1 = async (state, dirent, index) => {
|
|
2211
|
-
await getRealPath();
|
|
2212
|
-
const type = await stat();
|
|
2232
|
+
const realPath = await getRealPath(dirent.path);
|
|
2233
|
+
const type = await stat(realPath);
|
|
2213
2234
|
switch (type) {
|
|
2214
2235
|
case File:
|
|
2215
2236
|
return handleClickFile$1(state, dirent, index);
|
|
@@ -2522,8 +2543,8 @@ const handleClickCurrentButKeepFocus = state => {
|
|
|
2522
2543
|
// export const handleBlur=()=>{}
|
|
2523
2544
|
|
|
2524
2545
|
const handleClickSymLink = async (state, dirent, index) => {
|
|
2525
|
-
await getRealPath();
|
|
2526
|
-
const type = await stat();
|
|
2546
|
+
const realPath = await getRealPath(dirent.path);
|
|
2547
|
+
const type = await stat(realPath);
|
|
2527
2548
|
switch (type) {
|
|
2528
2549
|
case File:
|
|
2529
2550
|
return handleClickFile(state, dirent, index);
|
|
@@ -2661,10 +2682,10 @@ const mergeDirents$2 = (oldDirents, newDirents) => {
|
|
|
2661
2682
|
// TODO copy files in parallel
|
|
2662
2683
|
const copyFilesElectron = async (root, pathSeparator, files) => {
|
|
2663
2684
|
for (const file of files) {
|
|
2664
|
-
await getFilePathElectron(file);
|
|
2685
|
+
const from = await getFilePathElectron(file);
|
|
2665
2686
|
// const from = file.path
|
|
2666
|
-
join(pathSeparator, root, file.name);
|
|
2667
|
-
await copy$1();
|
|
2687
|
+
const to = join(pathSeparator, root, file.name);
|
|
2688
|
+
await copy$1(from, to);
|
|
2668
2689
|
}
|
|
2669
2690
|
};
|
|
2670
2691
|
const getMergedDirents$2 = async (root, pathSeparator, dirents) => {
|
|
@@ -2757,7 +2778,10 @@ const handleDropIntoFolder = async (state, dirent, index, files) => {
|
|
|
2757
2778
|
items
|
|
2758
2779
|
} = state;
|
|
2759
2780
|
for (const file of files) {
|
|
2760
|
-
|
|
2781
|
+
// TODO path basename
|
|
2782
|
+
const baseName = file;
|
|
2783
|
+
const to = dirent.path + pathSeparator + baseName;
|
|
2784
|
+
await copy$1(file, to);
|
|
2761
2785
|
}
|
|
2762
2786
|
const childDirents = await getChildDirents(pathSeparator, dirent);
|
|
2763
2787
|
const mergedDirents = getMergedDirents(items, index, dirent, childDirents);
|
|
@@ -2915,8 +2939,8 @@ const handlePasteCopy = async (state, nativeFiles) => {
|
|
|
2915
2939
|
// TODO handle pasting files into hardlink
|
|
2916
2940
|
// TODO what if folder is big and it takes a long time
|
|
2917
2941
|
for (const source of nativeFiles.files) {
|
|
2918
|
-
join(state.pathSeperator, state.root, getBaseName(state.pathSeparator, source));
|
|
2919
|
-
await copy$1();
|
|
2942
|
+
const target = join(state.pathSeperator, state.root, getBaseName(state.pathSeparator, source));
|
|
2943
|
+
await copy$1(source, target);
|
|
2920
2944
|
}
|
|
2921
2945
|
// TODO only update folder at which level it changed
|
|
2922
2946
|
return updateRoot(state);
|
|
@@ -2924,8 +2948,8 @@ const handlePasteCopy = async (state, nativeFiles) => {
|
|
|
2924
2948
|
|
|
2925
2949
|
const handlePasteCut = async (state, nativeFiles) => {
|
|
2926
2950
|
for (const source of nativeFiles.files) {
|
|
2927
|
-
`${state.root}${state.pathSeparator}${getBaseName(state.pathSeparator, source)}`;
|
|
2928
|
-
await rename$1();
|
|
2951
|
+
const target = `${state.root}${state.pathSeparator}${getBaseName(state.pathSeparator, source)}`;
|
|
2952
|
+
await rename$1(source, target);
|
|
2929
2953
|
}
|
|
2930
2954
|
return state;
|
|
2931
2955
|
};
|
|
@@ -2977,6 +3001,15 @@ const handlePointerDown = (state, button, x, y) => {
|
|
|
2977
3001
|
return state;
|
|
2978
3002
|
};
|
|
2979
3003
|
|
|
3004
|
+
const EmptyString = '';
|
|
3005
|
+
|
|
3006
|
+
const Fulfilled = 'fulfilled';
|
|
3007
|
+
const Rejected = 'rejected';
|
|
3008
|
+
|
|
3009
|
+
const getWorkspacePath = () => {
|
|
3010
|
+
return invoke('Workspace.getPath');
|
|
3011
|
+
};
|
|
3012
|
+
|
|
2980
3013
|
// TODO viewlet should only have create and refresh functions
|
|
2981
3014
|
// every thing else can be in a separate module <viewlet>.lazy.js
|
|
2982
3015
|
// and <viewlet>.ipc.js
|
|
@@ -2987,12 +3020,95 @@ const handlePointerDown = (state, button, x, y) => {
|
|
|
2987
3020
|
// TODO instead of root string, there should be a root dirent
|
|
2988
3021
|
|
|
2989
3022
|
const getPathSeparator = root => {
|
|
2990
|
-
return getPathSeparator$1();
|
|
3023
|
+
return getPathSeparator$1(root);
|
|
3024
|
+
};
|
|
3025
|
+
const getSavedChildDirents = (map, path, depth, excluded, pathSeparator) => {
|
|
3026
|
+
const children = map[path];
|
|
3027
|
+
if (!children) {
|
|
3028
|
+
return [];
|
|
3029
|
+
}
|
|
3030
|
+
const dirents = [];
|
|
3031
|
+
sortExplorerItems(children);
|
|
3032
|
+
const visible = [];
|
|
3033
|
+
const displayRoot = path.endsWith(pathSeparator) ? path : path + pathSeparator;
|
|
3034
|
+
for (const child of children) {
|
|
3035
|
+
if (excluded.includes(child.name)) {
|
|
3036
|
+
continue;
|
|
3037
|
+
}
|
|
3038
|
+
visible.push(child);
|
|
3039
|
+
}
|
|
3040
|
+
const visibleLength = visible.length;
|
|
3041
|
+
for (let i = 0; i < visibleLength; i++) {
|
|
3042
|
+
const child = visible[i];
|
|
3043
|
+
const {
|
|
3044
|
+
name,
|
|
3045
|
+
type
|
|
3046
|
+
} = child;
|
|
3047
|
+
const childPath = displayRoot + name;
|
|
3048
|
+
if ((child.type === Directory || child.type === SymLinkFolder) && childPath in map) {
|
|
3049
|
+
dirents.push({
|
|
3050
|
+
depth,
|
|
3051
|
+
posInSet: i + 1,
|
|
3052
|
+
setSize: visibleLength,
|
|
3053
|
+
icon: getFolderIcon(),
|
|
3054
|
+
name,
|
|
3055
|
+
path: childPath,
|
|
3056
|
+
type: DirectoryExpanded
|
|
3057
|
+
});
|
|
3058
|
+
dirents.push(...getSavedChildDirents(map, childPath, depth + 1, excluded, pathSeparator));
|
|
3059
|
+
} else {
|
|
3060
|
+
dirents.push({
|
|
3061
|
+
depth,
|
|
3062
|
+
posInSet: i + 1,
|
|
3063
|
+
setSize: visibleLength,
|
|
3064
|
+
icon: getIcon(),
|
|
3065
|
+
name,
|
|
3066
|
+
path: childPath,
|
|
3067
|
+
type
|
|
3068
|
+
});
|
|
3069
|
+
}
|
|
3070
|
+
}
|
|
3071
|
+
return dirents;
|
|
3072
|
+
};
|
|
3073
|
+
const createDirents = (root, expandedDirentPaths, expandedDirentChildren, excluded, pathSeparator) => {
|
|
3074
|
+
const dirents = [];
|
|
3075
|
+
const map = Object.create(null);
|
|
3076
|
+
for (let i = 0; i < expandedDirentPaths.length; i++) {
|
|
3077
|
+
const path = expandedDirentPaths[i];
|
|
3078
|
+
const children = expandedDirentChildren[i];
|
|
3079
|
+
if (children.status === Fulfilled) {
|
|
3080
|
+
map[path] = children.value;
|
|
3081
|
+
}
|
|
3082
|
+
}
|
|
3083
|
+
dirents.push(...getSavedChildDirents(map, root, 1, excluded, pathSeparator));
|
|
3084
|
+
return dirents;
|
|
3085
|
+
};
|
|
3086
|
+
const getSavedExpandedPaths = (savedState, root) => {
|
|
3087
|
+
if (savedState && savedState.root !== root) {
|
|
3088
|
+
return [];
|
|
3089
|
+
}
|
|
3090
|
+
if (savedState && savedState.expandedPaths && Array.isArray(savedState.expandedPaths)) {
|
|
3091
|
+
return savedState.expandedPaths;
|
|
3092
|
+
}
|
|
3093
|
+
return [];
|
|
2991
3094
|
};
|
|
2992
3095
|
const restoreExpandedState = async (savedState, root, pathSeparator, excluded) => {
|
|
2993
|
-
|
|
3096
|
+
// TODO read all opened folders in parallel
|
|
3097
|
+
// ignore ENOENT errors
|
|
3098
|
+
// ignore ENOTDIR errors
|
|
3099
|
+
// merge all dirents
|
|
3100
|
+
// restore scroll location
|
|
3101
|
+
const expandedPaths = getSavedExpandedPaths(savedState, root);
|
|
3102
|
+
if (root === EmptyString) {
|
|
2994
3103
|
return [];
|
|
2995
3104
|
}
|
|
3105
|
+
const expandedDirentPaths = [root, ...expandedPaths];
|
|
3106
|
+
const expandedDirentChildren = await Promise.allSettled(expandedDirentPaths.map(getChildDirentsRaw));
|
|
3107
|
+
if (expandedDirentChildren[0].status === Rejected) {
|
|
3108
|
+
throw expandedDirentChildren[0].reason;
|
|
3109
|
+
}
|
|
3110
|
+
const dirents = createDirents(root, expandedDirentPaths, expandedDirentChildren, excluded, pathSeparator);
|
|
3111
|
+
return dirents;
|
|
2996
3112
|
};
|
|
2997
3113
|
const getExcluded = () => {
|
|
2998
3114
|
const excludedObject = {};
|
|
@@ -3008,11 +3124,12 @@ const getSavedRoot$1 = (savedState, workspacePath) => {
|
|
|
3008
3124
|
return workspacePath;
|
|
3009
3125
|
};
|
|
3010
3126
|
const loadContent = async (state, savedState) => {
|
|
3011
|
-
const
|
|
3127
|
+
const workspacePath = await getWorkspacePath();
|
|
3128
|
+
const root = getSavedRoot$1(savedState, workspacePath);
|
|
3012
3129
|
// TODO path separator could be restored from saved state
|
|
3013
|
-
const pathSeparator = await getPathSeparator(); // TODO only load path separator once
|
|
3130
|
+
const pathSeparator = await getPathSeparator(root); // TODO only load path separator once
|
|
3014
3131
|
const excluded = getExcluded();
|
|
3015
|
-
const restoredDirents = await restoreExpandedState();
|
|
3132
|
+
const restoredDirents = await restoreExpandedState(savedState, root, pathSeparator, excluded);
|
|
3016
3133
|
const {
|
|
3017
3134
|
itemHeight,
|
|
3018
3135
|
height
|
|
@@ -3309,12 +3426,14 @@ const revealItem = async (state, uri) => {
|
|
|
3309
3426
|
return revealItemVisible(state, index);
|
|
3310
3427
|
};
|
|
3311
3428
|
|
|
3312
|
-
const isExpandedDirectory = dirent => {
|
|
3313
|
-
return dirent.type === DirectoryExpanded;
|
|
3314
|
-
};
|
|
3315
3429
|
const getPath = dirent => {
|
|
3316
3430
|
return dirent.path;
|
|
3317
3431
|
};
|
|
3432
|
+
|
|
3433
|
+
const isExpandedDirectory = dirent => {
|
|
3434
|
+
return dirent.type === DirectoryExpanded;
|
|
3435
|
+
};
|
|
3436
|
+
|
|
3318
3437
|
const saveState = state => {
|
|
3319
3438
|
const {
|
|
3320
3439
|
items,
|