@lvce-editor/explorer-view 6.16.0 → 7.2.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.
@@ -1395,6 +1395,9 @@ const readDirWithFileTypes = async uri => {
1395
1395
  const getPathSeparator$1 = async root => {
1396
1396
  return invoke('FileSystem.getPathSeparator', root);
1397
1397
  };
1398
+ const isReadonly = async root => {
1399
+ return invoke('FileSystem.isReadonly', root);
1400
+ };
1398
1401
  const getRealPath = async path => {
1399
1402
  return invoke('FileSystem.getRealPath', path);
1400
1403
  };
@@ -2073,22 +2076,32 @@ const acceptCreateFolder = async state => {
2073
2076
  return acceptCreate(state, Directory);
2074
2077
  };
2075
2078
 
2076
- const computeExplorerRenamedDirentUpdate = (root, parentPath, oldUri, children, tree, newUri) => {
2077
- const rootLength = root.length;
2078
- const relativeDirname = parentPath.slice(rootLength);
2079
- const relativeOldPath = oldUri.slice(rootLength);
2080
- const relativeNewUri = newUri.slice(rootLength);
2081
- const update = Object.create(null);
2082
- const oldItems = tree[relativeOldPath] || [];
2083
- update[relativeDirname] = children.map(child => {
2079
+ const getUpdatedChildren = (children, oldItems, newUri) => {
2080
+ const setSize = children.length;
2081
+ return children.toSorted(compareDirent).map((child, index) => {
2084
2082
  if (oldItems.length > 0 && child.path === newUri && child.type === Directory) {
2085
2083
  return {
2086
2084
  ...child,
2085
+ posInSet: index + 1,
2086
+ setSize,
2087
2087
  type: DirectoryExpanded
2088
2088
  };
2089
2089
  }
2090
- return child;
2090
+ return {
2091
+ ...child,
2092
+ posInSet: index + 1,
2093
+ setSize
2094
+ };
2091
2095
  });
2096
+ };
2097
+ const computeExplorerRenamedDirentUpdate = (root, parentPath, oldUri, children, tree, newUri) => {
2098
+ const rootLength = root.length;
2099
+ const relativeDirname = parentPath.slice(rootLength);
2100
+ const relativeOldPath = oldUri.slice(rootLength);
2101
+ const relativeNewUri = newUri.slice(rootLength);
2102
+ const update = Object.create(null);
2103
+ const oldItems = tree[relativeOldPath] || [];
2104
+ update[relativeDirname] = getUpdatedChildren(children, oldItems, newUri);
2092
2105
  update[relativeNewUri] = oldItems;
2093
2106
  for (const [key, value] of Object.entries(tree)) {
2094
2107
  if (!key.startsWith(`${relativeOldPath}/`)) {
@@ -2381,21 +2394,40 @@ const copyRelativePath = async state => {
2381
2394
  return state;
2382
2395
  };
2383
2396
 
2397
+ const getIconCacheKey = (path, type) => {
2398
+ switch (type) {
2399
+ case DirectoryExpanded:
2400
+ case DirectoryExpanding:
2401
+ case EditingDirectoryExpanded:
2402
+ return `${path}#expanded`;
2403
+ default:
2404
+ return path;
2405
+ }
2406
+ };
2407
+
2384
2408
  const getIconsCached = (dirents, fileIconCache) => {
2385
- return dirents.map(dirent => fileIconCache[dirent]);
2409
+ return dirents.map(dirent => {
2410
+ const cacheKey = getIconCacheKey(dirent.path, dirent.type);
2411
+ return fileIconCache[cacheKey];
2412
+ });
2386
2413
  };
2387
2414
 
2388
2415
  const getMissingDirents = (dirents, fileIconCache) => {
2389
2416
  const missingDirents = [];
2390
2417
  for (const dirent of dirents) {
2391
- if (!(dirent.path in fileIconCache)) {
2418
+ const cacheKey = getIconCacheKey(dirent.path, dirent.type);
2419
+ if (!(cacheKey in fileIconCache)) {
2392
2420
  missingDirents.push(dirent);
2393
2421
  }
2394
2422
  }
2395
2423
  return missingDirents;
2396
2424
  };
2397
2425
  const toIconRequest = dirent => {
2426
+ const cacheKey = getIconCacheKey(dirent.path, dirent.type);
2398
2427
  return {
2428
+ ...(cacheKey !== dirent.path && {
2429
+ expanded: true
2430
+ }),
2399
2431
  name: dirent.name,
2400
2432
  path: dirent.path,
2401
2433
  type: dirent.type
@@ -2407,14 +2439,6 @@ const getMissingIconRequests = (dirents, fileIconCache) => {
2407
2439
  return iconRequests;
2408
2440
  };
2409
2441
 
2410
- const getPath = item => {
2411
- return item.path;
2412
- };
2413
-
2414
- const getPaths = items => {
2415
- return items.map(getPath);
2416
- };
2417
-
2418
2442
  const getSimpleIconRequestType = direntType => {
2419
2443
  if ([Directory, DirectoryExpanded, EditingDirectoryExpanded, EditingFolder].includes(direntType)) {
2420
2444
  return 2;
@@ -2424,6 +2448,9 @@ const getSimpleIconRequestType = direntType => {
2424
2448
 
2425
2449
  const toSimpleIconRequest = request => {
2426
2450
  return {
2451
+ ...(request.expanded && {
2452
+ expanded: true
2453
+ }),
2427
2454
  name: request.name,
2428
2455
  type: getSimpleIconRequestType(request.type)
2429
2456
  };
@@ -2448,7 +2475,8 @@ const updateIconCache = (iconCache, missingRequests, newIcons) => {
2448
2475
  for (let i = 0; i < missingRequests.length; i++) {
2449
2476
  const request = missingRequests[i];
2450
2477
  const icon = newIcons[i];
2451
- newFileIconCache[request.path] = icon;
2478
+ const cacheKey = getIconCacheKey(request.path, request.type);
2479
+ newFileIconCache[cacheKey] = icon;
2452
2480
  }
2453
2481
  return newFileIconCache;
2454
2482
  };
@@ -2457,8 +2485,7 @@ const getFileIcons = async (dirents, fileIconCache) => {
2457
2485
  const missingRequests = getMissingIconRequests(dirents, fileIconCache);
2458
2486
  const newIcons = await requestFileIcons(missingRequests);
2459
2487
  const newFileIconCache = updateIconCache(fileIconCache, missingRequests, newIcons);
2460
- const paths = getPaths(dirents);
2461
- const icons = getIconsCached(paths, newFileIconCache);
2488
+ const icons = getIconsCached(dirents, newFileIconCache);
2462
2489
  return {
2463
2490
  icons,
2464
2491
  newFileIconCache
@@ -3043,6 +3070,7 @@ const create = (id, uri, x, y, width, height, args, parentUid, platform = 0, ass
3043
3070
  initial: true,
3044
3071
  inputSource: 0,
3045
3072
  isPointerDown: false,
3073
+ isReadonly: false,
3046
3074
  itemHeight: ListItem,
3047
3075
  items: [],
3048
3076
  maxIndent: 0,
@@ -3483,6 +3511,7 @@ const getKeyBindings = () => {
3483
3511
 
3484
3512
  const Separator = 1;
3485
3513
  const None$2 = 0;
3514
+ const Disabled = 5;
3486
3515
  const RestoreFocus = 6;
3487
3516
 
3488
3517
  const menuEntrySeparator = {
@@ -3564,6 +3593,10 @@ const menuEntryRename = {
3564
3593
  id: 'rename',
3565
3594
  label: rename()
3566
3595
  };
3596
+ const menuEntryRenameDisabled = {
3597
+ ...menuEntryRename,
3598
+ flags: Disabled
3599
+ };
3567
3600
  const menuEntryDelete = {
3568
3601
  command: 'Explorer.removeDirent',
3569
3602
  flags: None$2,
@@ -3576,7 +3609,6 @@ const menuEntryRemoveFolderFromWorkspace = {
3576
3609
  id: 'removeFolderFromWorkspace',
3577
3610
  label: removeFolderFromWorkspace()
3578
3611
  };
3579
- const ALL_ENTRIES = [menuEntryNewFile, menuEntryNewFolder, menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, menuEntryRename, menuEntryDelete];
3580
3612
 
3581
3613
  // TODO there are two possible ways of getting the focused dirent of explorer
3582
3614
  // 1. directly access state of explorer (bad because it directly accesses state of another component)
@@ -3587,17 +3619,23 @@ const getFocusedDirent = explorerState => {
3587
3619
  }
3588
3620
  return explorerState.items[explorerState.focusedIndex];
3589
3621
  };
3590
- const getMenuEntriesDirectory = () => {
3591
- return ALL_ENTRIES;
3622
+ const getMenuEntryRename = state => {
3623
+ if (state.isReadonly) {
3624
+ return menuEntryRenameDisabled;
3625
+ }
3626
+ return menuEntryRename;
3627
+ };
3628
+ const getMenuEntriesDirectory = state => {
3629
+ return [menuEntryNewFile, menuEntryNewFolder, menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, getMenuEntryRename(state), menuEntryDelete];
3592
3630
  };
3593
- const getMenuEntriesFile = () => {
3594
- return [menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, menuEntrySelectForCompare, menuEntrySeparator, menuEntryRename, menuEntryDelete];
3631
+ const getMenuEntriesFile = state => {
3632
+ return [menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, menuEntrySelectForCompare, menuEntrySeparator, getMenuEntryRename(state), menuEntryDelete];
3595
3633
  };
3596
- const getMenuEntriesFileCompareWithSelected = () => {
3597
- return [menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, menuEntryCompareWithSelected, menuEntrySeparator, menuEntryRename, menuEntryDelete];
3634
+ const getMenuEntriesFileCompareWithSelected = state => {
3635
+ return [menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, menuEntryCompareWithSelected, menuEntrySeparator, getMenuEntryRename(state), menuEntryDelete];
3598
3636
  };
3599
- const getMenuEntriesDefault = () => {
3600
- return ALL_ENTRIES;
3637
+ const getMenuEntriesDefault = state => {
3638
+ return getMenuEntriesDirectory(state);
3601
3639
  };
3602
3640
  const getMenuEntriesRoot = root => {
3603
3641
  const entries = [menuEntryNewFile, menuEntryNewFolder, menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath];
@@ -3613,14 +3651,14 @@ const getMenuEntries = state => {
3613
3651
  }
3614
3652
  switch (focusedDirent.type) {
3615
3653
  case Directory:
3616
- return getMenuEntriesDirectory();
3654
+ return getMenuEntriesDirectory(state);
3617
3655
  case File:
3618
3656
  if (state.compareSourceUri && state.compareSourceUri !== focusedDirent.path) {
3619
- return getMenuEntriesFileCompareWithSelected();
3657
+ return getMenuEntriesFileCompareWithSelected(state);
3620
3658
  }
3621
- return getMenuEntriesFile();
3659
+ return getMenuEntriesFile(state);
3622
3660
  default:
3623
- return getMenuEntriesDefault();
3661
+ return getMenuEntriesDefault(state);
3624
3662
  }
3625
3663
  };
3626
3664
 
@@ -4011,6 +4049,14 @@ const getPathDirentsMap = async allPaths => {
4011
4049
  return pathToDirents;
4012
4050
  };
4013
4051
 
4052
+ const getPath = item => {
4053
+ return item.path;
4054
+ };
4055
+
4056
+ const getPaths = items => {
4057
+ return items.map(getPath);
4058
+ };
4059
+
4014
4060
  const restoreDirentType = (rawDirentType, path, expandedPaths) => {
4015
4061
  if (rawDirentType === Directory && expandedPaths.includes(path)) {
4016
4062
  return DirectoryExpanded;
@@ -4773,7 +4819,9 @@ const loadContent = async (state, savedState) => {
4773
4819
  const root = getSavedRoot(savedState, workspacePath);
4774
4820
  try {
4775
4821
  // TODO path separator could be restored from saved state
4776
- const pathSeparator = await getPathSeparator(root); // TODO only load path separator once
4822
+ const [pathSeparator, isReadonly$1] = await Promise.all([getPathSeparator(root),
4823
+ // TODO only load path separator once
4824
+ isReadonly(root)]);
4777
4825
  const excluded = getExcluded();
4778
4826
  const restoredDirents = await restoreExpandedState(savedState, root, pathSeparator, excluded);
4779
4827
  const rawDeltaY = getRestoredDeltaY(savedState);
@@ -4792,6 +4840,7 @@ const loadContent = async (state, savedState) => {
4792
4840
  excluded,
4793
4841
  hasError: false,
4794
4842
  initial: false,
4843
+ isReadonly: isReadonly$1,
4795
4844
  items: restoredDirents,
4796
4845
  maxIndent: 10,
4797
4846
  minLineY,
@@ -4809,6 +4858,7 @@ const loadContent = async (state, savedState) => {
4809
4858
  errorMessage,
4810
4859
  hasError: true,
4811
4860
  initial: false,
4861
+ isReadonly: false,
4812
4862
  items: [],
4813
4863
  root,
4814
4864
  useChevrons
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "6.16.0",
3
+ "version": "7.2.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",