@lvce-editor/explorer-view 2.46.0 → 2.47.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.
@@ -431,7 +431,7 @@ const create$4 = (method, params) => {
431
431
  };
432
432
  };
433
433
  const callbacks = Object.create(null);
434
- const set$2 = (id, fn) => {
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$2(id, resolve);
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$2 = (ipc, method, ...params) => {
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$2(ipc, method, ...params);
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$a = (id, rpc) => {
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$a(rpcId, rpc);
901
+ set$b(rpcId, rpc);
897
902
  }
898
903
  };
899
904
  };
900
905
  const RendererWorker$1 = 1;
901
906
  const {
902
- invoke: invoke$5,
903
- set: set$5
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$5,
908
- set: set$5
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 createNestedPath = async (root, path, pathSeparator) => {
952
- const parts = path.slice(root.length).split(pathSeparator);
953
- let currentPath = '';
954
- for (const part of parts) {
955
- if (!part) continue;
956
- currentPath = currentPath ? `${currentPath}${pathSeparator}${part}` : part;
957
- try {
958
- await mkdir(`${root}${currentPath}`);
959
- } catch (error) {
960
- // Ignore error if directory already exists
961
- if (!(error instanceof Error && error.message.includes('already exists'))) {
962
- throw error;
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,41 @@ 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
+ text: ''
1140
+ });
1141
+ }
1142
+ return operations;
1143
+ };
1144
+ const getFileOperationsCreate = (newFileName, newDirentType, pathSeparator, absolutePath, root) => {
1145
+ const operations = [];
1146
+ const parentPath = dirname(pathSeparator, absolutePath);
1147
+ operations.push(...getFileOperationsNestedPath(parentPath, root, pathSeparator));
1148
+ if (newDirentType === File) {
1149
+ operations.push({
1150
+ type: CreateFile$1,
1151
+ path: absolutePath,
1152
+ text: ''
1153
+ });
1154
+ } else if (newDirentType === Directory) {
1155
+ operations.push({
1156
+ type: CreateFolder$1,
1157
+ path: absolutePath,
1158
+ text: ''
1159
+ });
1160
+ }
1161
+ return operations;
1162
+ };
1163
+
1133
1164
  const getIndex = (dirents, uri) => {
1134
1165
  for (let i = 0; i < dirents.length; i++) {
1135
1166
  const dirent = dirents[i];
@@ -1499,7 +1530,8 @@ const acceptCreate = async (state, newDirentType, createFn) => {
1499
1530
  }
1500
1531
  const parentFolder = getParentFolder(items, focusedIndex, root);
1501
1532
  const absolutePath = join2(parentFolder, newFileName);
1502
- const createErrorMessage = await createNewDirentsAccept(newFileName, pathSeparator, absolutePath, root, createFn);
1533
+ const operations = getFileOperationsCreate(editingValue, newDirentType, pathSeparator, absolutePath, root);
1534
+ const createErrorMessage = await applyFileOperations(operations);
1503
1535
  if (createErrorMessage) {
1504
1536
  return {
1505
1537
  ...state,
@@ -1534,11 +1566,11 @@ const acceptCreate = async (state, newDirentType, createFn) => {
1534
1566
  };
1535
1567
 
1536
1568
  const acceptCreateFile = async state => {
1537
- return acceptCreate(state, File, createFile);
1569
+ return acceptCreate(state, File);
1538
1570
  };
1539
1571
 
1540
1572
  const acceptCreateFolder = async state => {
1541
- return acceptCreate(state, Directory, mkdir);
1573
+ return acceptCreate(state, Directory);
1542
1574
  };
1543
1575
 
1544
1576
  const computeExplorerRenamedDirentUpdate = (root, parentPath, oldUri, children, tree, newUri) => {
@@ -1568,9 +1600,9 @@ const createNewDirentsRename = async (renamedDirent, editingValue, pathSeparator
1568
1600
  await rename$1(oldAbsolutePath, newAbsolutePath);
1569
1601
  } catch (error) {
1570
1602
  console.error(new VError(error, `Failed to rename file`));
1571
- return false;
1603
+ return `${error}`;
1572
1604
  }
1573
- return true;
1605
+ return '';
1574
1606
  };
1575
1607
 
1576
1608
  const updateTree2 = (tree, update) => {
@@ -1600,9 +1632,12 @@ const acceptRename = async state => {
1600
1632
  };
1601
1633
  }
1602
1634
  const renamedDirent = items[editingIndex];
1603
- const successful = await createNewDirentsRename(renamedDirent, editingValue);
1604
- if (!successful) {
1605
- return state;
1635
+ const renameErrorMessage = await createNewDirentsRename(renamedDirent, editingValue);
1636
+ if (renameErrorMessage) {
1637
+ return {
1638
+ ...state,
1639
+ editingErrorMessage: renameErrorMessage
1640
+ };
1606
1641
  }
1607
1642
  const oldUri = renamedDirent.path;
1608
1643
  const dirname = dirname2(oldUri);
@@ -3227,23 +3262,6 @@ const refresh = async state => {
3227
3262
  };
3228
3263
  };
3229
3264
 
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
3265
  const getChildHandles = async fileHandle => {
3248
3266
  // @ts-ignore
3249
3267
  const values = fileHandle.values();
@@ -3290,14 +3308,14 @@ const getFileOperations = (root, uploadTree) => {
3290
3308
  const fullPath = currentPath ? join2(currentPath, path) : path;
3291
3309
  if (typeof value === 'object') {
3292
3310
  operations.push({
3293
- type: 'createFolder',
3311
+ type: CreateFolder$1,
3294
3312
  path: join2(root, fullPath),
3295
3313
  text: ''
3296
3314
  });
3297
3315
  processTree(value, fullPath);
3298
3316
  } else if (typeof value === 'string') {
3299
3317
  operations.push({
3300
- type: 'createFile',
3318
+ type: CreateFile$1,
3301
3319
  path: join2(root, fullPath),
3302
3320
  text: value
3303
3321
  });
@@ -5174,7 +5192,7 @@ const selectDown = state => {
5174
5192
  }
5175
5193
  const newItems = items.map((item, i) => ({
5176
5194
  ...item,
5177
- selected: i === targetIndex + 1 ? true : item.selected
5195
+ selected: i === targetIndex + 1 ? true : item.selected || i === focusedIndex
5178
5196
  }));
5179
5197
  return {
5180
5198
  ...state,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.46.0",
3
+ "version": "2.47.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",