@lvce-editor/explorer-view 2.42.0 → 2.44.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$3 = (id, fn) => {
434
+ const set$2 = (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$3(id, resolve);
453
+ set$2(id, resolve);
454
454
  return {
455
455
  id,
456
456
  promise
@@ -761,7 +761,7 @@ const send = (transport, method, ...params) => {
761
761
  const message = create$4(method, params);
762
762
  transport.send(message);
763
763
  };
764
- const invoke$1 = (ipc, method, ...params) => {
764
+ const invoke$2 = (ipc, method, ...params) => {
765
765
  return invokeHelper(ipc, method, params, false);
766
766
  };
767
767
  const invokeAndTransfer = (ipc, method, ...params) => {
@@ -794,7 +794,7 @@ const createRpc = ipc => {
794
794
  send(ipc, method, ...params);
795
795
  },
796
796
  invoke(method, ...params) {
797
- return invoke$1(ipc, method, ...params);
797
+ return invoke$2(ipc, method, ...params);
798
798
  },
799
799
  invokeAndTransfer(method, ...params) {
800
800
  return invokeAndTransfer(ipc, method, ...params);
@@ -851,7 +851,7 @@ const WebWorkerRpcClient = {
851
851
  };
852
852
 
853
853
  const rpcs = Object.create(null);
854
- const set$7 = (id, rpc) => {
854
+ const set$9 = (id, rpc) => {
855
855
  rpcs[id] = rpc;
856
856
  };
857
857
  const get$1 = id => {
@@ -875,26 +875,30 @@ const create$2 = rpcId => {
875
875
  return rpc.invokeAndTransfer(method, ...params);
876
876
  },
877
877
  set(rpc) {
878
- set$7(rpcId, rpc);
878
+ set$9(rpcId, rpc);
879
879
  }
880
880
  };
881
881
  };
882
882
  const RendererWorker$1 = 1;
883
883
  const {
884
- invoke: invoke$2,
885
- set: set$2
884
+ invoke: invoke$4,
885
+ set: set$4
886
886
  } = create$2(RendererWorker$1);
887
887
  const RendererWorker = {
888
888
  __proto__: null,
889
- invoke: invoke$2,
890
- set: set$2
889
+ invoke: invoke$4,
890
+ set: set$4
891
891
  };
892
892
 
893
893
  const {
894
- invoke,
894
+ invoke: invoke$1,
895
895
  set: set$1
896
896
  } = RendererWorker;
897
897
 
898
+ const invoke = async (method, ...params) => {
899
+ return invoke$1(method, ...params);
900
+ };
901
+
898
902
  const remove = async dirent => {
899
903
  return invoke('FileSystem.remove', dirent);
900
904
  };
@@ -1077,7 +1081,7 @@ const requestFileIcons = async requests => {
1077
1081
  return [];
1078
1082
  }
1079
1083
  const simpleRequests = requests.map(toSimpleIconRequest);
1080
- const icons = await invoke('IconTheme.getIcons', simpleRequests);
1084
+ const icons = await invoke$1('IconTheme.getIcons', simpleRequests);
1081
1085
  return icons;
1082
1086
  };
1083
1087
 
@@ -1516,12 +1520,22 @@ const acceptCreateFolder = async state => {
1516
1520
  return acceptCreate(state, Directory, mkdir);
1517
1521
  };
1518
1522
 
1519
- const computeExplorerRenamedDirentUpdate = async (root, parentPath, parentDepth) => {
1520
- const children = await getChildDirents('/', parentPath, parentDepth, []);
1521
- const relativeDirname = parentPath.slice(root.length);
1522
- return {
1523
- [relativeDirname]: children
1524
- };
1523
+ const computeExplorerRenamedDirentUpdate = (root, parentPath, oldUri, children, tree, newUri) => {
1524
+ const rootLength = root.length;
1525
+ const relativeDirname = parentPath.slice(rootLength);
1526
+ const relativeOldPath = oldUri.slice(rootLength);
1527
+ const relativeNewUri = newUri.slice(rootLength);
1528
+ const update = Object.create(null);
1529
+ update[relativeDirname] = children;
1530
+ const oldItems = tree[relativeOldPath] || [];
1531
+ update[relativeNewUri] = oldItems;
1532
+ for (const [key, value] of Object.entries(tree)) {
1533
+ if (key.startsWith(`${relativeOldPath}/`)) {
1534
+ const newKey = `${relativeNewUri}` + key.slice(relativeOldPath.length);
1535
+ update[newKey] = value;
1536
+ }
1537
+ }
1538
+ return update;
1525
1539
  };
1526
1540
 
1527
1541
  const createNewDirentsRename = async (renamedDirent, editingValue, pathSeparator) => {
@@ -1569,10 +1583,12 @@ const acceptRename = async state => {
1569
1583
  if (!successful) {
1570
1584
  return state;
1571
1585
  }
1572
- const dirname = dirname2(renamedDirent.path);
1586
+ const oldUri = renamedDirent.path;
1587
+ const dirname = dirname2(oldUri);
1573
1588
  const newUri = join2(dirname, editingValue);
1574
- const update = await computeExplorerRenamedDirentUpdate(root, dirname, renamedDirent.depth - 1);
1589
+ const children = await getChildDirents('/', dirname, renamedDirent.depth - 1, []);
1575
1590
  const tree = createTree(items, root);
1591
+ const update = computeExplorerRenamedDirentUpdate(root, dirname, oldUri, children, tree, newUri);
1576
1592
  const newTree = updateTree2(tree, update);
1577
1593
  const newDirents = treeToArray(newTree, root);
1578
1594
  const newFocusedIndex = getIndex(newDirents, newUri);
@@ -1707,14 +1723,27 @@ const toCollapsedDirent = dirent => {
1707
1723
  return dirent;
1708
1724
  };
1709
1725
 
1710
- const collapseAll = state => {
1726
+ const collapseAll = async state => {
1711
1727
  const {
1728
+ minLineY,
1729
+ height,
1730
+ itemHeight,
1731
+ fileIconCache,
1712
1732
  items
1713
1733
  } = state;
1714
1734
  const newDirents = items.filter(isTopLevel).map(toCollapsedDirent);
1735
+ const dirents = newDirents;
1736
+ const maxLineY = getExplorerMaxLineY(minLineY, height, itemHeight, dirents.length);
1737
+ const visible = dirents.slice(minLineY, maxLineY);
1738
+ const {
1739
+ icons,
1740
+ newFileIconCache
1741
+ } = await getFileIcons(visible, fileIconCache);
1715
1742
  return {
1716
1743
  ...state,
1717
- items: newDirents
1744
+ items: newDirents,
1745
+ icons,
1746
+ fileIconCache: newFileIconCache
1718
1747
  };
1719
1748
  };
1720
1749
 
@@ -1738,13 +1767,13 @@ const copyPath = async state => {
1738
1767
  };
1739
1768
 
1740
1769
  const writeText = async text => {
1741
- await invoke('ClipBoard.writeText', /* text */text);
1770
+ await invoke$1('ClipBoard.writeText', /* text */text);
1742
1771
  };
1743
1772
  const readNativeFiles = async () => {
1744
- return invoke('ClipBoard.readNativeFiles');
1773
+ return invoke$1('ClipBoard.readNativeFiles');
1745
1774
  };
1746
1775
  const writeNativeFiles = async (type, files) => {
1747
- return invoke('ClipBoard.writeNativeFiles', type, files);
1776
+ return invoke$1('ClipBoard.writeNativeFiles', type, files);
1748
1777
  };
1749
1778
 
1750
1779
  const copyRelativePath = async state => {
@@ -2250,7 +2279,7 @@ const focusPrevious = state => {
2250
2279
  }
2251
2280
  };
2252
2281
 
2253
- const commandIds = ['acceptEdit', 'cancelEdit', 'collapseAll', 'copyPath', 'copyRelativePath', 'dispose', 'expandAll', 'expandRecursively', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusNone', 'handleInputKeyDown', 'focusPrevious', 'getFocusedDirent', 'getMenuEntries2', 'getMouseActions', 'handleArrowLeft', 'handleArrowLeft', 'handleArrowRight', 'handleArrowRight', 'handleBlur', 'handleClick', 'handleClickAt', 'handleClickCurrent', 'handleClickCurrentButKeepFocus', 'handleClickOpenFolder', 'handleContextMenu', 'handleContextMenuKeyboard', 'handleCopy', 'handleDragLeave', 'handleDragOver', 'handleDrop', 'handleFocus', 'handleIconThemeChange', 'handleInputBlur', 'handleInputClick', 'handleLanguagesChanged', 'handleMouseEnter', 'handleMouseLeave', 'handlePaste', 'handlePointerDown', 'handleUpload', 'handleWheel', 'handleWorkspaceChange', 'hotReload', 'newFile', 'newFolder', 'openContainingFolder', 'refresh', 'removeDirent', 'rename', 'renameDirent', 'renderEventListeners', 'revealItem', 'revealItem', 'scrollDown', 'scrollUp', 'selectAll', 'selectDown', 'selectUp', 'setDeltaY', 'setSelectedIndices', 'cancelTypeAhead', 'updateEditingValue', 'handleKeyDown', 'updateIcons'];
2282
+ const commandIds = ['acceptEdit', 'cancelEdit', 'cancelTypeAhead', 'collapseAll', 'copyPath', 'copyRelativePath', 'dispose', 'expandAll', 'expandRecursively', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusNone', 'focusPrevious', 'getFocusedDirent', 'getMenuEntries2', 'getMouseActions', 'handleArrowLeft', 'handleArrowLeft', 'handleArrowRight', 'handleArrowRight', 'handleBlur', 'handleClick', 'handleClickAt', 'handleClickCurrent', 'handleClickCurrentButKeepFocus', 'handleClickOpenFolder', 'handleContextMenu', 'handleContextMenuKeyboard', 'handleCopy', 'handleDragLeave', 'handleDragOver', 'handleDrop', 'handleFocus', 'handleIconThemeChange', 'handleInputBlur', 'handleInputClick', 'handleInputKeyDown', 'handleKeyDown', 'handleLanguagesChanged', 'handleMouseEnter', 'handleMouseLeave', 'handlePaste', 'handlePointerDown', 'handleUpload', 'handleWheel', 'handleWorkspaceChange', 'hotReload', 'newFile', 'newFolder', 'openContainingFolder', 'refresh', 'removeDirent', 'rename', 'renameDirent', 'renderEventListeners', 'revealItem', 'revealItem', 'scrollDown', 'scrollUp', 'selectAll', 'selectDown', 'selectUp', 'setDeltaY', 'setSelectedIndices', 'updateEditingValue', 'updateIcons'];
2254
2283
 
2255
2284
  const getCommandIds = () => {
2256
2285
  return commandIds;
@@ -2627,7 +2656,7 @@ const handleArrowRightDirectoryExpanded = (state, dirent) => {
2627
2656
  };
2628
2657
 
2629
2658
  const setFocus = key => {
2630
- return invoke('Focus.setFocus', key);
2659
+ return invoke$1('Focus.setFocus', key);
2631
2660
  };
2632
2661
 
2633
2662
  const handleClickDirectory = async (state, dirent, index, keepFocus) => {
@@ -2676,7 +2705,7 @@ const handleClickDirectory = async (state, dirent, index, keepFocus) => {
2676
2705
  };
2677
2706
 
2678
2707
  const openUri = async (uri, focus) => {
2679
- await invoke(/* Main.openAbsolutePath */'Main.openUri', /* absolutePath */uri, /* focus */focus);
2708
+ await invoke$1(/* Main.openAbsolutePath */'Main.openUri', /* absolutePath */uri, /* focus */focus);
2680
2709
  };
2681
2710
 
2682
2711
  const handleClickFile = async (state, dirent, index, keepFocus = false) => {
@@ -2937,7 +2966,7 @@ const handleClickOpenFolder = async state => {
2937
2966
  };
2938
2967
 
2939
2968
  const show = async (x, y, id, ...args) => {
2940
- return invoke('ContextMenu.show', x, y, id, ...args);
2969
+ return invoke$1('ContextMenu.show', x, y, id, ...args);
2941
2970
  };
2942
2971
 
2943
2972
  const Explorer$1 = 4;
@@ -3086,8 +3115,12 @@ const getExpandedDirents = items => {
3086
3115
  const getPathDirentsMap = async allPaths => {
3087
3116
  const pathToDirents = Object.create(null);
3088
3117
  await Promise.all(allPaths.map(async path => {
3089
- const dirents = await readDirWithFileTypes(path);
3090
- pathToDirents[path] = dirents;
3118
+ try {
3119
+ const dirents = await readDirWithFileTypes(path);
3120
+ pathToDirents[path] = dirents;
3121
+ } catch {
3122
+ // ignore
3123
+ }
3091
3124
  }));
3092
3125
  return pathToDirents;
3093
3126
  };
@@ -3443,12 +3476,12 @@ const getFileArray = fileList => {
3443
3476
  };
3444
3477
 
3445
3478
  const getFileHandles = async fileIds => {
3446
- const files = await invoke('FileSystemHandle.getFileHandles', fileIds);
3479
+ const files = await invoke$1('FileSystemHandle.getFileHandles', fileIds);
3447
3480
  return files;
3448
3481
  };
3449
3482
 
3450
3483
  const getFilePathElectron = async file => {
3451
- return invoke('FileSystemHandle.getFilePathElectron', file);
3484
+ return invoke$1('FileSystemHandle.getFilePathElectron', file);
3452
3485
  };
3453
3486
 
3454
3487
  const getFilepath = async file => {
@@ -3575,7 +3608,7 @@ const handleKeyDown = (state, key) => {
3575
3608
  // @ts-ignore
3576
3609
  // eslint-disable-next-line @typescript-eslint/no-misused-promises
3577
3610
  timeout = setTimeout(async () => {
3578
- await invoke('Explorer.cancelTypeAhead');
3611
+ await invoke$1('Explorer.cancelTypeAhead');
3579
3612
  }, focusWordTimeout);
3580
3613
  if (matchingIndex === -1) {
3581
3614
  return {
@@ -3770,11 +3803,11 @@ const handleWheel = (state, deltaMode, deltaY) => {
3770
3803
  };
3771
3804
 
3772
3805
  const getWorkspacePath = () => {
3773
- return invoke('Workspace.getPath');
3806
+ return invoke$1('Workspace.getPath');
3774
3807
  };
3775
3808
 
3776
3809
  const getSettings = async () => {
3777
- const useChevronsRaw = await invoke('Preferences.get', 'explorer.useChevrons');
3810
+ const useChevronsRaw = await invoke$1('Preferences.get', 'explorer.useChevrons');
3778
3811
  const useChevrons = useChevronsRaw === false ? false : true;
3779
3812
  return {
3780
3813
  useChevrons
@@ -4038,6 +4071,18 @@ const getNewDirentType = editingType => {
4038
4071
  }
4039
4072
  };
4040
4073
 
4074
+ const isFolder = direntType => {
4075
+ return direntType === Directory || direntType === DirectoryExpanded || direntType === SymLinkFolder;
4076
+ };
4077
+ const getFittingIndex = (dirents, startIndex) => {
4078
+ for (let i = startIndex; i >= 0; i--) {
4079
+ const dirent = dirents[i];
4080
+ if (isFolder(dirent.type)) {
4081
+ return i;
4082
+ }
4083
+ }
4084
+ return -1;
4085
+ };
4041
4086
  const newDirent = async (state, editingType) => {
4042
4087
  // TODO make focus functional instead of side effect
4043
4088
  await setFocus(ExplorerEditBox);
@@ -4051,8 +4096,9 @@ const newDirent = async (state, editingType) => {
4051
4096
  fileIconCache,
4052
4097
  root
4053
4098
  } = state;
4099
+ const index = getFittingIndex(items, focusedIndex);
4054
4100
  const direntType = getNewDirentType(editingType);
4055
- const newDirents = await getNewDirentsForNewDirent(items, focusedIndex, direntType, root);
4101
+ const newDirents = await getNewDirentsForNewDirent(items, index, direntType, root);
4056
4102
  const maxLineY = getExplorerMaxLineY(minLineY, height, itemHeight, newDirents.length);
4057
4103
  const visible = newDirents.slice(minLineY, maxLineY);
4058
4104
  const {
@@ -4095,7 +4141,7 @@ const getContainingFolder = (root, dirents, focusedIndex, pathSeparator) => {
4095
4141
  };
4096
4142
 
4097
4143
  const openNativeFolder = async path => {
4098
- await invoke('OpenNativeFolder.openNativeFolder', /* path */path);
4144
+ await invoke$1('OpenNativeFolder.openNativeFolder', /* path */path);
4099
4145
  };
4100
4146
 
4101
4147
  const openContainingFolder = async state => {
@@ -4139,10 +4185,17 @@ const removeDirent = async state => {
4139
4185
  return newState;
4140
4186
  };
4141
4187
 
4188
+ const getEditingType = direntType => {
4189
+ if (direntType < DELTA_EDITING) {
4190
+ return direntType + DELTA_EDITING;
4191
+ }
4192
+ return direntType;
4193
+ };
4194
+
4142
4195
  const getNewDirentsForRename = (items, focusedIndex) => {
4143
4196
  const item = items[focusedIndex];
4144
4197
  const newItems = [...items];
4145
- const editingType = item.type === File ? EditingFile : EditingFolder;
4198
+ const editingType = getEditingType(item.type);
4146
4199
  // TODO avoid mutation
4147
4200
  newItems[focusedIndex] = {
4148
4201
  ...item,
@@ -5144,24 +5197,24 @@ const terminate = () => {
5144
5197
 
5145
5198
  const getEditingIcon = async (editingType, value, direntType) => {
5146
5199
  if (editingType === CreateFile) {
5147
- return invoke('IconTheme.getFileIcon', {
5200
+ return invoke$1('IconTheme.getFileIcon', {
5148
5201
  name: value
5149
5202
  });
5150
5203
  }
5151
5204
  if (editingType === Rename$1) {
5152
5205
  if (direntType === File || direntType === EditingFile) {
5153
- return invoke('IconTheme.getFileIcon', {
5206
+ return invoke$1('IconTheme.getFileIcon', {
5154
5207
  name: value
5155
5208
  });
5156
5209
  }
5157
- if (direntType === Directory || direntType === EditingFolder) {
5158
- return invoke('IconTheme.getFolderIcon', {
5210
+ if (direntType === Directory || direntType === EditingFolder || direntType === EditingDirectoryExpanded) {
5211
+ return invoke$1('IconTheme.getFolderIcon', {
5159
5212
  name: value
5160
5213
  });
5161
5214
  }
5162
5215
  }
5163
5216
  if (editingType === CreateFolder) {
5164
- return invoke('IconTheme.getFolderIcon', {
5217
+ return invoke$1('IconTheme.getFolderIcon', {
5165
5218
  name: value
5166
5219
  });
5167
5220
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.42.0",
3
+ "version": "2.44.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",