@lvce-editor/explorer-view 2.47.0 → 2.49.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.
@@ -868,10 +868,10 @@ 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
871
+ const CreateFolder$1 = 1;
872
+ const CreateFile$1 = 2;
873
+ const Copy$2 = 3;
874
+ const Rename$2 = 4;
875
875
 
876
876
  const rpcs = Object.create(null);
877
877
  const set$b = (id, rpc) => {
@@ -993,7 +993,7 @@ const getBaseName = (pathSeparator, path) => {
993
993
  return path.slice(path.lastIndexOf(pathSeparator) + 1);
994
994
  };
995
995
  const join2 = (path, childPath) => {
996
- if (path.endsWith('/')) {
996
+ if (path.endsWith('/') || childPath.startsWith('/')) {
997
997
  return `${path}${childPath}`;
998
998
  }
999
999
  return `${path}/${childPath}`;
@@ -1077,16 +1077,17 @@ const EditingFile = File + DELTA_EDITING;
1077
1077
  const EditingFolder = Directory + DELTA_EDITING;
1078
1078
  const EditingDirectoryExpanded = DirectoryExpanded + DELTA_EDITING;
1079
1079
 
1080
- const getSimpleType = direntType => {
1080
+ const getSimpleIconRequestType = direntType => {
1081
1081
  if (direntType === Directory || direntType === DirectoryExpanded || direntType === EditingDirectoryExpanded || direntType === EditingFolder) {
1082
1082
  return 2;
1083
1083
  }
1084
1084
  return 1;
1085
1085
  };
1086
+
1086
1087
  const toSimpleIconRequest = request => {
1087
1088
  return {
1088
1089
  name: request.name,
1089
- type: getSimpleType(request.type)
1090
+ type: getSimpleIconRequestType(request.type)
1090
1091
  };
1091
1092
  };
1092
1093
 
@@ -1132,11 +1133,10 @@ const getFileOperationsNestedPath = (path, root, pathSeparator) => {
1132
1133
  let currentPath = '';
1133
1134
  for (const part of parts) {
1134
1135
  if (!part) continue;
1135
- currentPath = currentPath ? `${currentPath}${pathSeparator}${part}` : part;
1136
+ currentPath = join2(currentPath, part);
1136
1137
  operations.push({
1137
1138
  type: CreateFolder$1,
1138
- path: `${root}${currentPath}`,
1139
- text: ''
1139
+ path: join2(root, currentPath)
1140
1140
  });
1141
1141
  }
1142
1142
  return operations;
@@ -1154,8 +1154,7 @@ const getFileOperationsCreate = (newFileName, newDirentType, pathSeparator, abso
1154
1154
  } else if (newDirentType === Directory) {
1155
1155
  operations.push({
1156
1156
  type: CreateFolder$1,
1157
- path: absolutePath,
1158
- text: ''
1157
+ path: absolutePath
1159
1158
  });
1160
1159
  }
1161
1160
  return operations;
@@ -1393,7 +1392,7 @@ const treeToArrayInternal = (map, root, items, path, depth) => {
1393
1392
  for (let i = 0; i < count; i++) {
1394
1393
  const child = children[i];
1395
1394
  const childPath = join2(path, child.name);
1396
- const absolutePath = `${root}${childPath}`;
1395
+ const absolutePath = join2(root, childPath);
1397
1396
  items.push({
1398
1397
  depth,
1399
1398
  posInSet: i + 1,
@@ -1508,7 +1507,7 @@ const validateFileName2 = name => {
1508
1507
  return '';
1509
1508
  };
1510
1509
 
1511
- const acceptCreate = async (state, newDirentType, createFn) => {
1510
+ const acceptCreate = async (state, newDirentType) => {
1512
1511
  const {
1513
1512
  editingValue,
1514
1513
  minLineY,
@@ -1591,18 +1590,16 @@ const computeExplorerRenamedDirentUpdate = (root, parentPath, oldUri, children,
1591
1590
  return update;
1592
1591
  };
1593
1592
 
1594
- const createNewDirentsRename = async (renamedDirent, editingValue, pathSeparator) => {
1595
- try {
1596
- // TODO this does not work with rename of nested file
1597
- const oldAbsolutePath = renamedDirent.path;
1598
- const oldParentPath = dirname2(oldAbsolutePath);
1599
- const newAbsolutePath = join2(oldParentPath, editingValue);
1600
- await rename$1(oldAbsolutePath, newAbsolutePath);
1601
- } catch (error) {
1602
- console.error(new VError(error, `Failed to rename file`));
1603
- return `${error}`;
1604
- }
1605
- return '';
1593
+ const getFileOperationsRename = (oldAbsolutePath, newFileName) => {
1594
+ const operations = [];
1595
+ const oldParentPath = dirname2(oldAbsolutePath);
1596
+ const newAbsolutePath = join2(oldParentPath, newFileName);
1597
+ operations.push({
1598
+ type: Rename$2,
1599
+ path: newAbsolutePath,
1600
+ from: oldAbsolutePath
1601
+ });
1602
+ return operations;
1606
1603
  };
1607
1604
 
1608
1605
  const updateTree2 = (tree, update) => {
@@ -1632,7 +1629,8 @@ const acceptRename = async state => {
1632
1629
  };
1633
1630
  }
1634
1631
  const renamedDirent = items[editingIndex];
1635
- const renameErrorMessage = await createNewDirentsRename(renamedDirent, editingValue);
1632
+ const operations = getFileOperationsRename(renamedDirent.path, editingValue);
1633
+ const renameErrorMessage = await applyFileOperations(operations);
1636
1634
  if (renameErrorMessage) {
1637
1635
  return {
1638
1636
  ...state,
@@ -3309,8 +3307,7 @@ const getFileOperations = (root, uploadTree) => {
3309
3307
  if (typeof value === 'object') {
3310
3308
  operations.push({
3311
3309
  type: CreateFolder$1,
3312
- path: join2(root, fullPath),
3313
- text: ''
3310
+ path: join2(root, fullPath)
3314
3311
  });
3315
3312
  processTree(value, fullPath);
3316
3313
  } else if (typeof value === 'string') {
@@ -3378,9 +3375,8 @@ const getFileOperationsElectron = async (root, paths, fileHandles) => {
3378
3375
  } = fileHandle;
3379
3376
  const path = paths[i];
3380
3377
  operations.push({
3381
- type: 'copy',
3378
+ type: Copy$2,
3382
3379
  path: join2(root, name),
3383
- text: '',
3384
3380
  from: path
3385
3381
  });
3386
3382
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.47.0",
3
+ "version": "2.49.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",