@lvce-editor/explorer-view 2.46.0 → 2.48.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 +96 -83
- package/package.json +1 -1
|
@@ -431,7 +431,7 @@ const create$4 = (method, params) => {
|
|
|
431
431
|
};
|
|
432
432
|
};
|
|
433
433
|
const callbacks = Object.create(null);
|
|
434
|
-
const set$
|
|
434
|
+
const set$3 = (id, fn) => {
|
|
435
435
|
callbacks[id] = fn;
|
|
436
436
|
};
|
|
437
437
|
const get$2 = id => {
|
|
@@ -450,7 +450,7 @@ const registerPromise = () => {
|
|
|
450
450
|
resolve,
|
|
451
451
|
promise
|
|
452
452
|
} = Promise.withResolvers();
|
|
453
|
-
set$
|
|
453
|
+
set$3(id, resolve);
|
|
454
454
|
return {
|
|
455
455
|
id,
|
|
456
456
|
promise
|
|
@@ -779,7 +779,7 @@ const send = (transport, method, ...params) => {
|
|
|
779
779
|
const message = create$4(method, params);
|
|
780
780
|
transport.send(message);
|
|
781
781
|
};
|
|
782
|
-
const invoke$
|
|
782
|
+
const invoke$3 = (ipc, method, ...params) => {
|
|
783
783
|
return invokeHelper(ipc, method, params, false);
|
|
784
784
|
};
|
|
785
785
|
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
@@ -812,7 +812,7 @@ const createRpc = ipc => {
|
|
|
812
812
|
send(ipc, method, ...params);
|
|
813
813
|
},
|
|
814
814
|
invoke(method, ...params) {
|
|
815
|
-
return invoke$
|
|
815
|
+
return invoke$3(ipc, method, ...params);
|
|
816
816
|
},
|
|
817
817
|
invokeAndTransfer(method, ...params) {
|
|
818
818
|
return invokeAndTransfer(ipc, method, ...params);
|
|
@@ -868,8 +868,13 @@ const WebWorkerRpcClient = {
|
|
|
868
868
|
create: create$3
|
|
869
869
|
};
|
|
870
870
|
|
|
871
|
+
const CreateFolder$1 = 'createFolder'; // TODO use number
|
|
872
|
+
const CreateFile$1 = 'createFile'; // TODO use number
|
|
873
|
+
const Copy$2 = 'copy'; // TODO use number
|
|
874
|
+
const Rename$2 = 'rename'; // TODO use number
|
|
875
|
+
|
|
871
876
|
const rpcs = Object.create(null);
|
|
872
|
-
const set$
|
|
877
|
+
const set$b = (id, rpc) => {
|
|
873
878
|
rpcs[id] = rpc;
|
|
874
879
|
};
|
|
875
880
|
const get$1 = id => {
|
|
@@ -893,19 +898,19 @@ const create$2 = rpcId => {
|
|
|
893
898
|
return rpc.invokeAndTransfer(method, ...params);
|
|
894
899
|
},
|
|
895
900
|
set(rpc) {
|
|
896
|
-
set$
|
|
901
|
+
set$b(rpcId, rpc);
|
|
897
902
|
}
|
|
898
903
|
};
|
|
899
904
|
};
|
|
900
905
|
const RendererWorker$1 = 1;
|
|
901
906
|
const {
|
|
902
|
-
invoke: invoke$
|
|
903
|
-
set: set$
|
|
907
|
+
invoke: invoke$2,
|
|
908
|
+
set: set$2
|
|
904
909
|
} = create$2(RendererWorker$1);
|
|
905
910
|
const RendererWorker = {
|
|
906
911
|
__proto__: null,
|
|
907
|
-
invoke: invoke$
|
|
908
|
-
set: set$
|
|
912
|
+
invoke: invoke$2,
|
|
913
|
+
set: set$2
|
|
909
914
|
};
|
|
910
915
|
|
|
911
916
|
const {
|
|
@@ -932,9 +937,6 @@ const getRealPath = async path => {
|
|
|
932
937
|
const stat = async dirent => {
|
|
933
938
|
return invoke('FileSystem.stat', dirent);
|
|
934
939
|
};
|
|
935
|
-
const createFile = async uri => {
|
|
936
|
-
return invoke('FileSystem.writeFile', uri, '');
|
|
937
|
-
};
|
|
938
940
|
const writeFile = async (uri, content) => {
|
|
939
941
|
return invoke('FileSystem.writeFile', uri, content);
|
|
940
942
|
};
|
|
@@ -948,20 +950,29 @@ const copy$1 = async (oldUri, newUri) => {
|
|
|
948
950
|
return invoke('FileSystem.copy', oldUri, newUri);
|
|
949
951
|
};
|
|
950
952
|
|
|
951
|
-
const
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
953
|
+
const applyOperation = operation => {
|
|
954
|
+
if (operation.type === CreateFolder$1) {
|
|
955
|
+
return mkdir(operation.path);
|
|
956
|
+
}
|
|
957
|
+
if (operation.type === Copy$2) {
|
|
958
|
+
return copy$1(operation.from || '', operation.path);
|
|
959
|
+
}
|
|
960
|
+
if (operation.type === Rename$2) {
|
|
961
|
+
return rename$1(operation.from || '', operation.path);
|
|
962
|
+
}
|
|
963
|
+
return writeFile(operation.path, operation.text);
|
|
964
|
+
};
|
|
965
|
+
|
|
966
|
+
const applyFileOperations = async operations => {
|
|
967
|
+
try {
|
|
968
|
+
// TODO run operations in parallel if possible
|
|
969
|
+
for (const operation of operations) {
|
|
970
|
+
await applyOperation(operation);
|
|
964
971
|
}
|
|
972
|
+
return '';
|
|
973
|
+
} catch (error) {
|
|
974
|
+
console.error(new VError(error, `Failed to apply file operations`));
|
|
975
|
+
return `${error}`;
|
|
965
976
|
}
|
|
966
977
|
};
|
|
967
978
|
|
|
@@ -988,21 +999,6 @@ const join2 = (path, childPath) => {
|
|
|
988
999
|
return `${path}/${childPath}`;
|
|
989
1000
|
};
|
|
990
1001
|
|
|
991
|
-
const createNewDirentsAccept = async (newFileName, pathSeparator, absolutePath, root, createFn) => {
|
|
992
|
-
try {
|
|
993
|
-
// Create parent directories if they don't exist
|
|
994
|
-
if (newFileName.includes(pathSeparator)) {
|
|
995
|
-
const parentPath = dirname(pathSeparator, absolutePath);
|
|
996
|
-
await createNestedPath(root, parentPath, pathSeparator);
|
|
997
|
-
}
|
|
998
|
-
await createFn(absolutePath);
|
|
999
|
-
return '';
|
|
1000
|
-
} catch (error) {
|
|
1001
|
-
console.error(new VError(error, `Failed to create file`));
|
|
1002
|
-
return `${error}`;
|
|
1003
|
-
}
|
|
1004
|
-
};
|
|
1005
|
-
|
|
1006
1002
|
const createTree = (items, root) => {
|
|
1007
1003
|
const tree = Object.create(null);
|
|
1008
1004
|
const rootLength = root.length;
|
|
@@ -1130,6 +1126,39 @@ const getFileIcons = async (dirents, fileIconCache) => {
|
|
|
1130
1126
|
};
|
|
1131
1127
|
};
|
|
1132
1128
|
|
|
1129
|
+
const getFileOperationsNestedPath = (path, root, pathSeparator) => {
|
|
1130
|
+
const parts = path.slice(root.length).split(pathSeparator);
|
|
1131
|
+
const operations = [];
|
|
1132
|
+
let currentPath = '';
|
|
1133
|
+
for (const part of parts) {
|
|
1134
|
+
if (!part) continue;
|
|
1135
|
+
currentPath = currentPath ? `${currentPath}${pathSeparator}${part}` : part;
|
|
1136
|
+
operations.push({
|
|
1137
|
+
type: CreateFolder$1,
|
|
1138
|
+
path: `${root}${currentPath}`
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
return operations;
|
|
1142
|
+
};
|
|
1143
|
+
const getFileOperationsCreate = (newFileName, newDirentType, pathSeparator, absolutePath, root) => {
|
|
1144
|
+
const operations = [];
|
|
1145
|
+
const parentPath = dirname(pathSeparator, absolutePath);
|
|
1146
|
+
operations.push(...getFileOperationsNestedPath(parentPath, root, pathSeparator));
|
|
1147
|
+
if (newDirentType === File) {
|
|
1148
|
+
operations.push({
|
|
1149
|
+
type: CreateFile$1,
|
|
1150
|
+
path: absolutePath,
|
|
1151
|
+
text: ''
|
|
1152
|
+
});
|
|
1153
|
+
} else if (newDirentType === Directory) {
|
|
1154
|
+
operations.push({
|
|
1155
|
+
type: CreateFolder$1,
|
|
1156
|
+
path: absolutePath
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
return operations;
|
|
1160
|
+
};
|
|
1161
|
+
|
|
1133
1162
|
const getIndex = (dirents, uri) => {
|
|
1134
1163
|
for (let i = 0; i < dirents.length; i++) {
|
|
1135
1164
|
const dirent = dirents[i];
|
|
@@ -1477,7 +1506,7 @@ const validateFileName2 = name => {
|
|
|
1477
1506
|
return '';
|
|
1478
1507
|
};
|
|
1479
1508
|
|
|
1480
|
-
const acceptCreate = async (state, newDirentType
|
|
1509
|
+
const acceptCreate = async (state, newDirentType) => {
|
|
1481
1510
|
const {
|
|
1482
1511
|
editingValue,
|
|
1483
1512
|
minLineY,
|
|
@@ -1499,7 +1528,8 @@ const acceptCreate = async (state, newDirentType, createFn) => {
|
|
|
1499
1528
|
}
|
|
1500
1529
|
const parentFolder = getParentFolder(items, focusedIndex, root);
|
|
1501
1530
|
const absolutePath = join2(parentFolder, newFileName);
|
|
1502
|
-
const
|
|
1531
|
+
const operations = getFileOperationsCreate(editingValue, newDirentType, pathSeparator, absolutePath, root);
|
|
1532
|
+
const createErrorMessage = await applyFileOperations(operations);
|
|
1503
1533
|
if (createErrorMessage) {
|
|
1504
1534
|
return {
|
|
1505
1535
|
...state,
|
|
@@ -1534,11 +1564,11 @@ const acceptCreate = async (state, newDirentType, createFn) => {
|
|
|
1534
1564
|
};
|
|
1535
1565
|
|
|
1536
1566
|
const acceptCreateFile = async state => {
|
|
1537
|
-
return acceptCreate(state, File
|
|
1567
|
+
return acceptCreate(state, File);
|
|
1538
1568
|
};
|
|
1539
1569
|
|
|
1540
1570
|
const acceptCreateFolder = async state => {
|
|
1541
|
-
return acceptCreate(state, Directory
|
|
1571
|
+
return acceptCreate(state, Directory);
|
|
1542
1572
|
};
|
|
1543
1573
|
|
|
1544
1574
|
const computeExplorerRenamedDirentUpdate = (root, parentPath, oldUri, children, tree, newUri) => {
|
|
@@ -1559,18 +1589,16 @@ const computeExplorerRenamedDirentUpdate = (root, parentPath, oldUri, children,
|
|
|
1559
1589
|
return update;
|
|
1560
1590
|
};
|
|
1561
1591
|
|
|
1562
|
-
const
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
}
|
|
1573
|
-
return true;
|
|
1592
|
+
const getFileOperationsRename = (oldAbsolutePath, newFileName) => {
|
|
1593
|
+
const operations = [];
|
|
1594
|
+
const oldParentPath = dirname2(oldAbsolutePath);
|
|
1595
|
+
const newAbsolutePath = join2(oldParentPath, newFileName);
|
|
1596
|
+
operations.push({
|
|
1597
|
+
type: Rename$2,
|
|
1598
|
+
path: newAbsolutePath,
|
|
1599
|
+
from: oldAbsolutePath
|
|
1600
|
+
});
|
|
1601
|
+
return operations;
|
|
1574
1602
|
};
|
|
1575
1603
|
|
|
1576
1604
|
const updateTree2 = (tree, update) => {
|
|
@@ -1600,9 +1628,13 @@ const acceptRename = async state => {
|
|
|
1600
1628
|
};
|
|
1601
1629
|
}
|
|
1602
1630
|
const renamedDirent = items[editingIndex];
|
|
1603
|
-
const
|
|
1604
|
-
|
|
1605
|
-
|
|
1631
|
+
const operations = getFileOperationsRename(renamedDirent.path, editingValue);
|
|
1632
|
+
const renameErrorMessage = await applyFileOperations(operations);
|
|
1633
|
+
if (renameErrorMessage) {
|
|
1634
|
+
return {
|
|
1635
|
+
...state,
|
|
1636
|
+
editingErrorMessage: renameErrorMessage
|
|
1637
|
+
};
|
|
1606
1638
|
}
|
|
1607
1639
|
const oldUri = renamedDirent.path;
|
|
1608
1640
|
const dirname = dirname2(oldUri);
|
|
@@ -3227,23 +3259,6 @@ const refresh = async state => {
|
|
|
3227
3259
|
};
|
|
3228
3260
|
};
|
|
3229
3261
|
|
|
3230
|
-
const applyOperation = operation => {
|
|
3231
|
-
if (operation.type === 'createFolder') {
|
|
3232
|
-
return mkdir(operation.path);
|
|
3233
|
-
}
|
|
3234
|
-
if (operation.type === 'copy') {
|
|
3235
|
-
return copy$1(operation.from || '', operation.path);
|
|
3236
|
-
}
|
|
3237
|
-
return writeFile(operation.path, operation.text);
|
|
3238
|
-
};
|
|
3239
|
-
|
|
3240
|
-
const applyFileOperations = async operations => {
|
|
3241
|
-
// TODO run operations in parallel if possible
|
|
3242
|
-
for (const operation of operations) {
|
|
3243
|
-
await applyOperation(operation);
|
|
3244
|
-
}
|
|
3245
|
-
};
|
|
3246
|
-
|
|
3247
3262
|
const getChildHandles = async fileHandle => {
|
|
3248
3263
|
// @ts-ignore
|
|
3249
3264
|
const values = fileHandle.values();
|
|
@@ -3290,14 +3305,13 @@ const getFileOperations = (root, uploadTree) => {
|
|
|
3290
3305
|
const fullPath = currentPath ? join2(currentPath, path) : path;
|
|
3291
3306
|
if (typeof value === 'object') {
|
|
3292
3307
|
operations.push({
|
|
3293
|
-
type:
|
|
3294
|
-
path: join2(root, fullPath)
|
|
3295
|
-
text: ''
|
|
3308
|
+
type: CreateFolder$1,
|
|
3309
|
+
path: join2(root, fullPath)
|
|
3296
3310
|
});
|
|
3297
3311
|
processTree(value, fullPath);
|
|
3298
3312
|
} else if (typeof value === 'string') {
|
|
3299
3313
|
operations.push({
|
|
3300
|
-
type:
|
|
3314
|
+
type: CreateFile$1,
|
|
3301
3315
|
path: join2(root, fullPath),
|
|
3302
3316
|
text: value
|
|
3303
3317
|
});
|
|
@@ -3362,7 +3376,6 @@ const getFileOperationsElectron = async (root, paths, fileHandles) => {
|
|
|
3362
3376
|
operations.push({
|
|
3363
3377
|
type: 'copy',
|
|
3364
3378
|
path: join2(root, name),
|
|
3365
|
-
text: '',
|
|
3366
3379
|
from: path
|
|
3367
3380
|
});
|
|
3368
3381
|
}
|
|
@@ -5174,7 +5187,7 @@ const selectDown = state => {
|
|
|
5174
5187
|
}
|
|
5175
5188
|
const newItems = items.map((item, i) => ({
|
|
5176
5189
|
...item,
|
|
5177
|
-
selected: i === targetIndex + 1 ? true : item.selected
|
|
5190
|
+
selected: i === targetIndex + 1 ? true : item.selected || i === focusedIndex
|
|
5178
5191
|
}));
|
|
5179
5192
|
return {
|
|
5180
5193
|
...state,
|