@lvce-editor/explorer-view 2.55.0 → 2.56.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.
@@ -995,6 +995,23 @@ const applyFileOperations = async operations => {
995
995
  }
996
996
  };
997
997
 
998
+ const DELTA_EDITING = 100;
999
+
1000
+ const BlockDevice = 1;
1001
+ const CharacterDevice = 2;
1002
+ const Directory = 3;
1003
+ const DirectoryExpanded = 4;
1004
+ const DirectoryExpanding = 5;
1005
+ const File = 7;
1006
+ const Socket = 8;
1007
+ const Symlink = 9;
1008
+ const SymLinkFile = 10;
1009
+ const SymLinkFolder = 11;
1010
+ const Unknown = 12;
1011
+ const EditingFile = File + DELTA_EDITING;
1012
+ const EditingFolder = Directory + DELTA_EDITING;
1013
+ const EditingDirectoryExpanded = DirectoryExpanded + DELTA_EDITING;
1014
+
998
1015
  const dirname = (pathSeparator, path) => {
999
1016
  const index = path.lastIndexOf(pathSeparator);
1000
1017
  if (index === -1) {
@@ -1015,16 +1032,32 @@ const join2 = (path, childPath) => {
1015
1032
  return `${path}/${childPath}`;
1016
1033
  };
1017
1034
 
1035
+ const getActualType = (type, expanded) => {
1036
+ const actualType = type === Directory && expanded ? DirectoryExpanded : type;
1037
+ return actualType;
1038
+ };
1018
1039
  const createTree = (items, root) => {
1019
1040
  const tree = Object.create(null);
1020
1041
  const rootLength = root.length;
1021
- for (const item of items) {
1042
+ const paths = items.map(item => {
1022
1043
  const relativePath = item.path.slice(rootLength);
1023
1044
  const dirname = dirname2(relativePath);
1045
+ return dirname;
1046
+ });
1047
+ for (const item of items) {
1048
+ const {
1049
+ type,
1050
+ name,
1051
+ path
1052
+ } = item;
1053
+ const relativePath = path.slice(rootLength);
1054
+ const dirname = dirname2(relativePath);
1055
+ const isExpanded = paths.includes(relativePath);
1056
+ const actualType = getActualType(type, isExpanded);
1024
1057
  tree[dirname] ||= [];
1025
1058
  tree[dirname].push({
1026
- name: item.name,
1027
- type: item.type
1059
+ name,
1060
+ type: actualType
1028
1061
  });
1029
1062
  }
1030
1063
  return tree;
@@ -1076,23 +1109,6 @@ const getPaths = items => {
1076
1109
  return items.map(getPath);
1077
1110
  };
1078
1111
 
1079
- const DELTA_EDITING = 100;
1080
-
1081
- const BlockDevice = 1;
1082
- const CharacterDevice = 2;
1083
- const Directory = 3;
1084
- const DirectoryExpanded = 4;
1085
- const DirectoryExpanding = 5;
1086
- const File = 7;
1087
- const Socket = 8;
1088
- const Symlink = 9;
1089
- const SymLinkFile = 10;
1090
- const SymLinkFolder = 11;
1091
- const Unknown = 12;
1092
- const EditingFile = File + DELTA_EDITING;
1093
- const EditingFolder = Directory + DELTA_EDITING;
1094
- const EditingDirectoryExpanded = DirectoryExpanded + DELTA_EDITING;
1095
-
1096
1112
  const getSimpleIconRequestType = direntType => {
1097
1113
  if (direntType === Directory || direntType === DirectoryExpanded || direntType === EditingDirectoryExpanded || direntType === EditingFolder) {
1098
1114
  return 2;
@@ -1197,13 +1213,14 @@ const getPathParts = (root, uri, pathSeparator) => {
1197
1213
  const parts = [];
1198
1214
  let index = root.length - 1;
1199
1215
  let depth = 0;
1200
- while ((index = uri.indexOf('/', index + 1)) !== -1) {
1216
+ while ((index = uri.indexOf(pathSeparator, index + 1)) !== -1) {
1201
1217
  const partUri = uri.slice(0, index);
1202
1218
  parts.push({
1203
1219
  path: partUri,
1204
1220
  depth: depth++,
1205
1221
  root,
1206
- pathSeparator
1222
+ pathSeparator,
1223
+ expanded: true
1207
1224
  });
1208
1225
  }
1209
1226
  return parts;
@@ -1310,14 +1327,14 @@ const sortExplorerItems = rawDirents => {
1310
1327
  };
1311
1328
 
1312
1329
  // TODO figure out whether this uses too much memory (name,path -> redundant, depth could be computed on demand)
1313
- const toDisplayDirent = (parentPath, parentDepth, rawDirent, index, length) => {
1314
- const path = join2(parentPath, rawDirent.name);
1330
+ const toDisplayDirent = (parentPath, parentDepth, rawDirentType, rawDirentName, index, length) => {
1331
+ const path = join2(parentPath, rawDirentName);
1315
1332
  return {
1316
- name: rawDirent.name,
1333
+ name: rawDirentName,
1317
1334
  posInSet: index + 1,
1318
1335
  setSize: length,
1319
1336
  depth: parentDepth + 1,
1320
- type: rawDirent.type,
1337
+ type: rawDirentType,
1321
1338
  path,
1322
1339
  // TODO storing absolute path might be too costly, could also store relative path here
1323
1340
  icon: '',
@@ -1325,7 +1342,7 @@ const toDisplayDirent = (parentPath, parentDepth, rawDirent, index, length) => {
1325
1342
  };
1326
1343
  };
1327
1344
 
1328
- const toDisplayDirents = (pathSeparator, rawDirents, parentDirentPath, parentDirentDepth, excluded) => {
1345
+ const toDisplayDirents = (pathSeparator, rawDirents, parentDirentPath, parentDirentDepth, excluded, expanded = false) => {
1329
1346
  rawDirents = sortExplorerItems(rawDirents);
1330
1347
  const result = [];
1331
1348
  const visibleItems = rawDirents.filter(item => {
@@ -1337,7 +1354,7 @@ const toDisplayDirents = (pathSeparator, rawDirents, parentDirentPath, parentDir
1337
1354
  const count = visibleItems.length;
1338
1355
  for (let i = 0; i < visibleItems.length; i++) {
1339
1356
  const rawDirent = visibleItems[i];
1340
- result.push(toDisplayDirent(parentDirentPath, parentDirentDepth, rawDirent, i, count));
1357
+ result.push(toDisplayDirent(parentDirentPath, parentDirentDepth, rawDirent.type, rawDirent.name, i, count));
1341
1358
  }
1342
1359
  return result;
1343
1360
  };
@@ -1448,6 +1465,7 @@ const CopyPath = 'Copy Path';
1448
1465
  const CopyRelativePath = 'Copy Relative Path';
1449
1466
  const Cut$1 = 'Cut';
1450
1467
  const Delete$1 = 'Delete';
1468
+ const FileNameCannotStartWithSlash = 'A file or folder name cannot start with a slash.';
1451
1469
  const FileOrFolderNameMustBeProvider = 'A file or folder name must be provided.';
1452
1470
  const FilesExplorer = 'Files Explorer';
1453
1471
  const NewFile$1 = 'New File...';
@@ -1512,6 +1530,9 @@ const openFolder$1 = () => {
1512
1530
  const fileOrFolderNameMustBeProvided = () => {
1513
1531
  return i18nString(FileOrFolderNameMustBeProvider);
1514
1532
  };
1533
+ const fileCannotStartWithSlash = () => {
1534
+ return i18nString(FileNameCannotStartWithSlash);
1535
+ };
1515
1536
  const typeAFileName = () => {
1516
1537
  return i18nString(TypeAFileName);
1517
1538
  };
@@ -1521,6 +1542,9 @@ const validateFileName2 = name => {
1521
1542
  const editingErrorMessage = fileOrFolderNameMustBeProvided();
1522
1543
  return editingErrorMessage;
1523
1544
  }
1545
+ if (name.startsWith('/')) {
1546
+ return fileCannotStartWithSlash();
1547
+ }
1524
1548
  return '';
1525
1549
  };
1526
1550
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.55.0",
3
+ "version": "2.56.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",