@lvce-editor/explorer-view 7.0.0 → 7.3.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.
@@ -1276,6 +1276,7 @@ const DeltaMode = 'event.deltaMode';
1276
1276
  const DeltaY = 'event.deltaY';
1277
1277
  const EventTargetClassName = 'event.target.className';
1278
1278
  const IsTrusted = 'event.isTrusted';
1279
+ const Key = 'event.key';
1279
1280
  const ShiftKey = 'event.shiftKey';
1280
1281
  const TargetName = 'event.target.name';
1281
1282
  const TargetValue = 'event.target.value';
@@ -1395,6 +1396,9 @@ const readDirWithFileTypes = async uri => {
1395
1396
  const getPathSeparator$1 = async root => {
1396
1397
  return invoke('FileSystem.getPathSeparator', root);
1397
1398
  };
1399
+ const isReadonly = async root => {
1400
+ return invoke('FileSystem.isReadonly', root);
1401
+ };
1398
1402
  const getRealPath = async path => {
1399
1403
  return invoke('FileSystem.getRealPath', path);
1400
1404
  };
@@ -2073,22 +2077,32 @@ const acceptCreateFolder = async state => {
2073
2077
  return acceptCreate(state, Directory);
2074
2078
  };
2075
2079
 
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 => {
2080
+ const getUpdatedChildren = (children, oldItems, newUri) => {
2081
+ const setSize = children.length;
2082
+ return children.toSorted(compareDirent).map((child, index) => {
2084
2083
  if (oldItems.length > 0 && child.path === newUri && child.type === Directory) {
2085
2084
  return {
2086
2085
  ...child,
2086
+ posInSet: index + 1,
2087
+ setSize,
2087
2088
  type: DirectoryExpanded
2088
2089
  };
2089
2090
  }
2090
- return child;
2091
+ return {
2092
+ ...child,
2093
+ posInSet: index + 1,
2094
+ setSize
2095
+ };
2091
2096
  });
2097
+ };
2098
+ const computeExplorerRenamedDirentUpdate = (root, parentPath, oldUri, children, tree, newUri) => {
2099
+ const rootLength = root.length;
2100
+ const relativeDirname = parentPath.slice(rootLength);
2101
+ const relativeOldPath = oldUri.slice(rootLength);
2102
+ const relativeNewUri = newUri.slice(rootLength);
2103
+ const update = Object.create(null);
2104
+ const oldItems = tree[relativeOldPath] || [];
2105
+ update[relativeDirname] = getUpdatedChildren(children, oldItems, newUri);
2092
2106
  update[relativeNewUri] = oldItems;
2093
2107
  for (const [key, value] of Object.entries(tree)) {
2094
2108
  if (!key.startsWith(`${relativeOldPath}/`)) {
@@ -2381,21 +2395,40 @@ const copyRelativePath = async state => {
2381
2395
  return state;
2382
2396
  };
2383
2397
 
2398
+ const getIconCacheKey = (path, type) => {
2399
+ switch (type) {
2400
+ case DirectoryExpanded:
2401
+ case DirectoryExpanding:
2402
+ case EditingDirectoryExpanded:
2403
+ return `${path}#expanded`;
2404
+ default:
2405
+ return path;
2406
+ }
2407
+ };
2408
+
2384
2409
  const getIconsCached = (dirents, fileIconCache) => {
2385
- return dirents.map(dirent => fileIconCache[dirent]);
2410
+ return dirents.map(dirent => {
2411
+ const cacheKey = getIconCacheKey(dirent.path, dirent.type);
2412
+ return fileIconCache[cacheKey];
2413
+ });
2386
2414
  };
2387
2415
 
2388
2416
  const getMissingDirents = (dirents, fileIconCache) => {
2389
2417
  const missingDirents = [];
2390
2418
  for (const dirent of dirents) {
2391
- if (!(dirent.path in fileIconCache)) {
2419
+ const cacheKey = getIconCacheKey(dirent.path, dirent.type);
2420
+ if (!(cacheKey in fileIconCache)) {
2392
2421
  missingDirents.push(dirent);
2393
2422
  }
2394
2423
  }
2395
2424
  return missingDirents;
2396
2425
  };
2397
2426
  const toIconRequest = dirent => {
2427
+ const cacheKey = getIconCacheKey(dirent.path, dirent.type);
2398
2428
  return {
2429
+ ...(cacheKey !== dirent.path && {
2430
+ expanded: true
2431
+ }),
2399
2432
  name: dirent.name,
2400
2433
  path: dirent.path,
2401
2434
  type: dirent.type
@@ -2407,14 +2440,6 @@ const getMissingIconRequests = (dirents, fileIconCache) => {
2407
2440
  return iconRequests;
2408
2441
  };
2409
2442
 
2410
- const getPath = item => {
2411
- return item.path;
2412
- };
2413
-
2414
- const getPaths = items => {
2415
- return items.map(getPath);
2416
- };
2417
-
2418
2443
  const getSimpleIconRequestType = direntType => {
2419
2444
  if ([Directory, DirectoryExpanded, EditingDirectoryExpanded, EditingFolder].includes(direntType)) {
2420
2445
  return 2;
@@ -2424,6 +2449,9 @@ const getSimpleIconRequestType = direntType => {
2424
2449
 
2425
2450
  const toSimpleIconRequest = request => {
2426
2451
  return {
2452
+ ...(request.expanded && {
2453
+ expanded: true
2454
+ }),
2427
2455
  name: request.name,
2428
2456
  type: getSimpleIconRequestType(request.type)
2429
2457
  };
@@ -2448,7 +2476,8 @@ const updateIconCache = (iconCache, missingRequests, newIcons) => {
2448
2476
  for (let i = 0; i < missingRequests.length; i++) {
2449
2477
  const request = missingRequests[i];
2450
2478
  const icon = newIcons[i];
2451
- newFileIconCache[request.path] = icon;
2479
+ const cacheKey = getIconCacheKey(request.path, request.type);
2480
+ newFileIconCache[cacheKey] = icon;
2452
2481
  }
2453
2482
  return newFileIconCache;
2454
2483
  };
@@ -2457,8 +2486,7 @@ const getFileIcons = async (dirents, fileIconCache) => {
2457
2486
  const missingRequests = getMissingIconRequests(dirents, fileIconCache);
2458
2487
  const newIcons = await requestFileIcons(missingRequests);
2459
2488
  const newFileIconCache = updateIconCache(fileIconCache, missingRequests, newIcons);
2460
- const paths = getPaths(dirents);
2461
- const icons = getIconsCached(paths, newFileIconCache);
2489
+ const icons = getIconsCached(dirents, newFileIconCache);
2462
2490
  return {
2463
2491
  icons,
2464
2492
  newFileIconCache
@@ -3043,6 +3071,7 @@ const create = (id, uri, x, y, width, height, args, parentUid, platform = 0, ass
3043
3071
  initial: true,
3044
3072
  inputSource: 0,
3045
3073
  isPointerDown: false,
3074
+ isReadonly: false,
3046
3075
  itemHeight: ListItem,
3047
3076
  items: [],
3048
3077
  maxIndent: 0,
@@ -3483,6 +3512,7 @@ const getKeyBindings = () => {
3483
3512
 
3484
3513
  const Separator = 1;
3485
3514
  const None$2 = 0;
3515
+ const Disabled = 5;
3486
3516
  const RestoreFocus = 6;
3487
3517
 
3488
3518
  const menuEntrySeparator = {
@@ -3564,6 +3594,10 @@ const menuEntryRename = {
3564
3594
  id: 'rename',
3565
3595
  label: rename()
3566
3596
  };
3597
+ const menuEntryRenameDisabled = {
3598
+ ...menuEntryRename,
3599
+ flags: Disabled
3600
+ };
3567
3601
  const menuEntryDelete = {
3568
3602
  command: 'Explorer.removeDirent',
3569
3603
  flags: None$2,
@@ -3576,7 +3610,6 @@ const menuEntryRemoveFolderFromWorkspace = {
3576
3610
  id: 'removeFolderFromWorkspace',
3577
3611
  label: removeFolderFromWorkspace()
3578
3612
  };
3579
- const ALL_ENTRIES = [menuEntryNewFile, menuEntryNewFolder, menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, menuEntryRename, menuEntryDelete];
3580
3613
 
3581
3614
  // TODO there are two possible ways of getting the focused dirent of explorer
3582
3615
  // 1. directly access state of explorer (bad because it directly accesses state of another component)
@@ -3587,17 +3620,23 @@ const getFocusedDirent = explorerState => {
3587
3620
  }
3588
3621
  return explorerState.items[explorerState.focusedIndex];
3589
3622
  };
3590
- const getMenuEntriesDirectory = () => {
3591
- return ALL_ENTRIES;
3623
+ const getMenuEntryRename = state => {
3624
+ if (state.isReadonly) {
3625
+ return menuEntryRenameDisabled;
3626
+ }
3627
+ return menuEntryRename;
3628
+ };
3629
+ const getMenuEntriesDirectory = state => {
3630
+ return [menuEntryNewFile, menuEntryNewFolder, menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, getMenuEntryRename(state), menuEntryDelete];
3592
3631
  };
3593
- const getMenuEntriesFile = () => {
3594
- return [menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, menuEntrySelectForCompare, menuEntrySeparator, menuEntryRename, menuEntryDelete];
3632
+ const getMenuEntriesFile = state => {
3633
+ return [menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, menuEntrySelectForCompare, menuEntrySeparator, getMenuEntryRename(state), menuEntryDelete];
3595
3634
  };
3596
- const getMenuEntriesFileCompareWithSelected = () => {
3597
- return [menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, menuEntryCompareWithSelected, menuEntrySeparator, menuEntryRename, menuEntryDelete];
3635
+ const getMenuEntriesFileCompareWithSelected = state => {
3636
+ return [menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryCut, menuEntryCopy, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath, menuEntrySeparator, menuEntryCompareWithSelected, menuEntrySeparator, getMenuEntryRename(state), menuEntryDelete];
3598
3637
  };
3599
- const getMenuEntriesDefault = () => {
3600
- return ALL_ENTRIES;
3638
+ const getMenuEntriesDefault = state => {
3639
+ return getMenuEntriesDirectory(state);
3601
3640
  };
3602
3641
  const getMenuEntriesRoot = root => {
3603
3642
  const entries = [menuEntryNewFile, menuEntryNewFolder, menuEntryOpenContainingFolder, menuEntryOpenInIntegratedTerminal, menuEntrySeparator, menuEntryPaste, menuEntrySeparator, menuEntryCopyPath, menuEntryCopyRelativePath];
@@ -3613,14 +3652,14 @@ const getMenuEntries = state => {
3613
3652
  }
3614
3653
  switch (focusedDirent.type) {
3615
3654
  case Directory:
3616
- return getMenuEntriesDirectory();
3655
+ return getMenuEntriesDirectory(state);
3617
3656
  case File:
3618
3657
  if (state.compareSourceUri && state.compareSourceUri !== focusedDirent.path) {
3619
- return getMenuEntriesFileCompareWithSelected();
3658
+ return getMenuEntriesFileCompareWithSelected(state);
3620
3659
  }
3621
- return getMenuEntriesFile();
3660
+ return getMenuEntriesFile(state);
3622
3661
  default:
3623
- return getMenuEntriesDefault();
3662
+ return getMenuEntriesDefault(state);
3624
3663
  }
3625
3664
  };
3626
3665
 
@@ -3657,6 +3696,18 @@ const getMouseActions = () => {
3657
3696
  }];
3658
3697
  };
3659
3698
 
3699
+ const getTitle$1 = state => {
3700
+ const {
3701
+ pathSeparator,
3702
+ root
3703
+ } = state;
3704
+ if (!root) {
3705
+ return 'Explorer';
3706
+ }
3707
+ const normalizedRoot = root.endsWith(pathSeparator) && root !== pathSeparator ? root.slice(0, -pathSeparator.length) : root;
3708
+ return getBaseName(pathSeparator, normalizedRoot) || normalizedRoot;
3709
+ };
3710
+
3660
3711
  const getParentStartIndex = (dirents, index) => {
3661
3712
  const dirent = dirents[index];
3662
3713
  let startIndex = index - 1;
@@ -4011,6 +4062,14 @@ const getPathDirentsMap = async allPaths => {
4011
4062
  return pathToDirents;
4012
4063
  };
4013
4064
 
4065
+ const getPath = item => {
4066
+ return item.path;
4067
+ };
4068
+
4069
+ const getPaths = items => {
4070
+ return items.map(getPath);
4071
+ };
4072
+
4014
4073
  const restoreDirentType = (rawDirentType, path, expandedPaths) => {
4015
4074
  if (rawDirentType === Directory && expandedPaths.includes(path)) {
4016
4075
  return DirectoryExpanded;
@@ -4773,7 +4832,9 @@ const loadContent = async (state, savedState) => {
4773
4832
  const root = getSavedRoot(savedState, workspacePath);
4774
4833
  try {
4775
4834
  // TODO path separator could be restored from saved state
4776
- const pathSeparator = await getPathSeparator(root); // TODO only load path separator once
4835
+ const [pathSeparator, isReadonly$1] = await Promise.all([getPathSeparator(root),
4836
+ // TODO only load path separator once
4837
+ isReadonly(root)]);
4777
4838
  const excluded = getExcluded();
4778
4839
  const restoredDirents = await restoreExpandedState(savedState, root, pathSeparator, excluded);
4779
4840
  const rawDeltaY = getRestoredDeltaY(savedState);
@@ -4792,6 +4853,7 @@ const loadContent = async (state, savedState) => {
4792
4853
  excluded,
4793
4854
  hasError: false,
4794
4855
  initial: false,
4856
+ isReadonly: isReadonly$1,
4795
4857
  items: restoredDirents,
4796
4858
  maxIndent: 10,
4797
4859
  minLineY,
@@ -4809,6 +4871,7 @@ const loadContent = async (state, savedState) => {
4809
4871
  errorMessage,
4810
4872
  hasError: true,
4811
4873
  initial: false,
4874
+ isReadonly: false,
4812
4875
  items: [],
4813
4876
  root,
4814
4877
  useChevrons
@@ -5251,7 +5314,7 @@ const filterByFocusWord = (items, focusedIndex, focusWord) => {
5251
5314
  }
5252
5315
  const matches = [];
5253
5316
  for (let i = 0; i < items.length; i++) {
5254
- if (items[i].toLowerCase().includes(focusWord)) {
5317
+ if (items[i].toLowerCase().startsWith(focusWord)) {
5255
5318
  matches.push(i);
5256
5319
  }
5257
5320
  }
@@ -5268,19 +5331,22 @@ const filterByFocusWord = (items, focusedIndex, focusWord) => {
5268
5331
  return matches[nextIndex];
5269
5332
  };
5270
5333
 
5271
- const RE_ASCII = /^[a-z]$/;
5334
+ const RE_ASCII = /^[a-z]$/i;
5272
5335
  const isAscii = key => {
5273
5336
  return RE_ASCII.test(key);
5274
5337
  };
5275
5338
 
5276
5339
  const typeAheadTimeout = {};
5277
- const handleKeyDown = (state, key) => {
5340
+ const handleKeyDown = (state, defaultPrevented, key) => {
5278
5341
  const {
5279
5342
  focusedIndex,
5280
5343
  focusWord,
5281
5344
  focusWordTimeout,
5282
5345
  items
5283
5346
  } = state;
5347
+ if (defaultPrevented) {
5348
+ return state;
5349
+ }
5284
5350
  if (focusWord && key === '') {
5285
5351
  return cancelTypeAhead(state);
5286
5352
  }
@@ -6018,6 +6084,7 @@ const HandleDrop = 6;
6018
6084
  const HandleEditingInput = 7;
6019
6085
  const HandleInputBlur = 8;
6020
6086
  const HandleInputClick = 9;
6087
+ const HandleKeyDown = 21;
6021
6088
  const HandleListBlur = 11;
6022
6089
  const HandleListFocus = 12;
6023
6090
  const HandlePointerDown = 14;
@@ -6499,6 +6566,9 @@ const renderEventListeners = () => {
6499
6566
  }, {
6500
6567
  name: HandleListBlur,
6501
6568
  params: ['handleBlur']
6569
+ }, {
6570
+ name: HandleKeyDown,
6571
+ params: ['handleKeyDown', DefaultPrevented, Key]
6502
6572
  }, {
6503
6573
  name: HandleClick,
6504
6574
  params: ['handleClickAt', DefaultPrevented, Button$3, CtrlKey, ShiftKey, ClientX, ClientY],
@@ -6900,6 +6970,7 @@ const commandMap = {
6900
6970
  'Explorer.getMenuEntries': getMenuEntries,
6901
6971
  'Explorer.getMenuEntries2': wrapGetter(getMenuEntries2),
6902
6972
  'Explorer.getMouseActions': getMouseActions,
6973
+ 'Explorer.getTitle': wrapGetter(getTitle$1),
6903
6974
  'Explorer.handleArrowLeft': wrapListItemCommand(handleArrowLeft),
6904
6975
  'Explorer.handleArrowRight': wrapListItemCommand(handleArrowRight),
6905
6976
  'Explorer.handleBlur': wrapListItemCommand(handleBlur),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "7.0.0",
3
+ "version": "7.3.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",