@lvce-editor/explorer-view 6.10.0 → 6.13.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.
@@ -189,7 +189,7 @@ class AssertionError extends Error {
189
189
  const Object$1 = 1;
190
190
  const Number$1 = 2;
191
191
  const Array$1 = 3;
192
- const String = 4;
192
+ const String$1 = 4;
193
193
  const Boolean$1 = 5;
194
194
  const Function = 6;
195
195
  const Null = 7;
@@ -201,7 +201,7 @@ const getType = value => {
201
201
  case 'function':
202
202
  return Function;
203
203
  case 'string':
204
- return String;
204
+ return String$1;
205
205
  case 'object':
206
206
  if (value === null) {
207
207
  return Null;
@@ -236,7 +236,7 @@ const array = value => {
236
236
  };
237
237
  const string = value => {
238
238
  const type = getType(value);
239
- if (type !== String) {
239
+ if (type !== String$1) {
240
240
  throw new AssertionError('expected value to be of type string');
241
241
  }
242
242
  };
@@ -1436,8 +1436,8 @@ const applyFileOperations = async operations => {
1436
1436
  }
1437
1437
  return '';
1438
1438
  } catch (error) {
1439
- console.error(new VError(error, `Failed to apply file operations`));
1440
- return `${error}`;
1439
+ console.error(new VError(error, 'Failed to apply file operations'));
1440
+ return String(error);
1441
1441
  }
1442
1442
  };
1443
1443
 
@@ -1717,12 +1717,7 @@ const toDisplayDirent = (parentPath, parentDepth, rawDirentType, rawDirentName,
1717
1717
  const toDisplayDirents = (pathSeparator, rawDirents, parentDirentPath, parentDirentDepth, excluded, expanded = false) => {
1718
1718
  rawDirents = sortExplorerItems(rawDirents);
1719
1719
  const result = [];
1720
- const visibleItems = rawDirents.filter(item => {
1721
- if (excluded.includes(item.name)) {
1722
- return false;
1723
- }
1724
- return true;
1725
- });
1720
+ const visibleItems = rawDirents.filter(item => !excluded.includes(item.name));
1726
1721
  const count = visibleItems.length;
1727
1722
  for (let i = 0; i < visibleItems.length; i++) {
1728
1723
  const rawDirent = visibleItems[i];
@@ -1986,7 +1981,7 @@ const validateFileName2 = (name, siblingFileNames = []) => {
1986
1981
  }
1987
1982
 
1988
1983
  // Disallow reserved directory names
1989
- if (name === '.' || name === '..' || name === '...') {
1984
+ if (['.', '..', '...'].includes(name)) {
1990
1985
  return theNameIsNotValid();
1991
1986
  }
1992
1987
 
@@ -2070,7 +2065,7 @@ const computeExplorerRenamedDirentUpdate = (root, parentPath, oldUri, children,
2070
2065
  update[relativeNewUri] = oldItems;
2071
2066
  for (const [key, value] of Object.entries(tree)) {
2072
2067
  if (key.startsWith(`${relativeOldPath}/`)) {
2073
- const newKey = `${relativeNewUri}` + key.slice(relativeOldPath.length);
2068
+ const newKey = relativeNewUri + key.slice(relativeOldPath.length);
2074
2069
  update[newKey] = value;
2075
2070
  }
2076
2071
  }
@@ -2389,7 +2384,7 @@ const getPaths = items => {
2389
2384
  };
2390
2385
 
2391
2386
  const getSimpleIconRequestType = direntType => {
2392
- if (direntType === Directory || direntType === DirectoryExpanded || direntType === EditingDirectoryExpanded || direntType === EditingFolder) {
2387
+ if ([Directory, DirectoryExpanded, EditingDirectoryExpanded, EditingFolder].includes(direntType)) {
2393
2388
  return 2;
2394
2389
  }
2395
2390
  return 1;
@@ -2630,12 +2625,12 @@ const getChildrenWithCount = (nodes, startIndex, childCount) => {
2630
2625
  };
2631
2626
 
2632
2627
  const compareNodes = (oldNode, newNode) => {
2633
- const patches = [];
2634
2628
  // Check if node type changed - return null to signal incompatible nodes
2635
2629
  // (caller should handle this with a Replace operation)
2636
2630
  if (oldNode.type !== newNode.type) {
2637
2631
  return null;
2638
2632
  }
2633
+ const patches = [];
2639
2634
  // Handle reference nodes - special handling for uid changes
2640
2635
  if (oldNode.type === Reference) {
2641
2636
  if (oldNode.uid !== newNode.uid) {
@@ -2671,7 +2666,7 @@ const compareNodes = (oldNode, newNode) => {
2671
2666
  }
2672
2667
  // Check for removed attributes
2673
2668
  for (const key of oldKeys) {
2674
- if (!(key in newNode)) {
2669
+ if (!Object.hasOwn(newNode, key)) {
2675
2670
  patches.push({
2676
2671
  type: RemoveAttribute,
2677
2672
  key
@@ -2689,11 +2684,78 @@ const treeToArray = node => {
2689
2684
  return result;
2690
2685
  };
2691
2686
 
2687
+ const navigateToChild = (patches, currentChildIndex, index) => {
2688
+ if (currentChildIndex === -1) {
2689
+ patches.push({
2690
+ type: NavigateChild,
2691
+ index
2692
+ });
2693
+ return index;
2694
+ }
2695
+ if (currentChildIndex !== index) {
2696
+ patches.push({
2697
+ type: NavigateSibling,
2698
+ index
2699
+ });
2700
+ }
2701
+ return index;
2702
+ };
2703
+ const navigateToParent = (patches, currentChildIndex) => {
2704
+ if (currentChildIndex >= 0) {
2705
+ patches.push({
2706
+ type: NavigateParent
2707
+ });
2708
+ }
2709
+ return -1;
2710
+ };
2711
+ const addTree = (newNode, patches) => {
2712
+ patches.push({
2713
+ type: Add,
2714
+ nodes: treeToArray(newNode)
2715
+ });
2716
+ };
2717
+ const replaceTree = (newNode, patches) => {
2718
+ patches.push({
2719
+ type: Replace,
2720
+ nodes: treeToArray(newNode)
2721
+ });
2722
+ };
2723
+ const diffExistingChild = (oldNode, newNode, patches, currentChildIndex, index) => {
2724
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
2725
+ if (nodePatches === null) {
2726
+ const nextChildIndex = navigateToChild(patches, currentChildIndex, index);
2727
+ replaceTree(newNode, patches);
2728
+ return nextChildIndex;
2729
+ }
2730
+ const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
2731
+ if (nodePatches.length === 0 && !hasChildrenToCompare) {
2732
+ return currentChildIndex;
2733
+ }
2734
+ const nextChildIndex = navigateToChild(patches, currentChildIndex, index);
2735
+ if (nodePatches.length > 0) {
2736
+ patches.push(...nodePatches);
2737
+ }
2738
+ if (hasChildrenToCompare) {
2739
+ diffChildren(oldNode.children, newNode.children, patches);
2740
+ }
2741
+ return nextChildIndex;
2742
+ };
2743
+ const diffRootNode = (oldNode, newNode, patches) => {
2744
+ const nodePatches = compareNodes(oldNode.node, newNode.node);
2745
+ if (nodePatches === null) {
2746
+ replaceTree(newNode, patches);
2747
+ return;
2748
+ }
2749
+ if (nodePatches.length > 0) {
2750
+ patches.push(...nodePatches);
2751
+ }
2752
+ if (oldNode.children.length > 0 || newNode.children.length > 0) {
2753
+ diffChildren(oldNode.children, newNode.children, patches);
2754
+ }
2755
+ };
2692
2756
  const diffChildren = (oldChildren, newChildren, patches) => {
2693
2757
  const maxLength = Math.max(oldChildren.length, newChildren.length);
2694
- // Track where we are: -1 means at parent, >= 0 means at child index
2695
2758
  let currentChildIndex = -1;
2696
- // Collect indices of children to remove (we'll add these patches at the end in reverse order)
2697
2759
  const indicesToRemove = [];
2698
2760
  for (let i = 0; i < maxLength; i++) {
2699
2761
  const oldNode = oldChildren[i];
@@ -2702,88 +2764,17 @@ const diffChildren = (oldChildren, newChildren, patches) => {
2702
2764
  continue;
2703
2765
  }
2704
2766
  if (!oldNode) {
2705
- // Add new node - we should be at the parent
2706
- if (currentChildIndex >= 0) {
2707
- // Navigate back to parent
2708
- patches.push({
2709
- type: NavigateParent
2710
- });
2711
- currentChildIndex = -1;
2712
- }
2713
- // Flatten the entire subtree so renderInternal can handle it
2714
- const flatNodes = treeToArray(newNode);
2715
- patches.push({
2716
- type: Add,
2717
- nodes: flatNodes
2718
- });
2719
- } else if (newNode) {
2720
- // Compare nodes to see if we need any patches
2721
- const nodePatches = compareNodes(oldNode.node, newNode.node);
2722
- // If nodePatches is null, the node types are incompatible - need to replace
2723
- if (nodePatches === null) {
2724
- // Navigate to this child
2725
- if (currentChildIndex === -1) {
2726
- patches.push({
2727
- type: NavigateChild,
2728
- index: i
2729
- });
2730
- currentChildIndex = i;
2731
- } else if (currentChildIndex !== i) {
2732
- patches.push({
2733
- type: NavigateSibling,
2734
- index: i
2735
- });
2736
- currentChildIndex = i;
2737
- }
2738
- // Replace the entire subtree
2739
- const flatNodes = treeToArray(newNode);
2740
- patches.push({
2741
- type: Replace,
2742
- nodes: flatNodes
2743
- });
2744
- // After replace, we're at the new element (same position)
2745
- continue;
2746
- }
2747
- // Check if we need to recurse into children
2748
- const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
2749
- // Only navigate to this element if we need to do something
2750
- if (nodePatches.length > 0 || hasChildrenToCompare) {
2751
- // Navigate to this child if not already there
2752
- if (currentChildIndex === -1) {
2753
- patches.push({
2754
- type: NavigateChild,
2755
- index: i
2756
- });
2757
- currentChildIndex = i;
2758
- } else if (currentChildIndex !== i) {
2759
- patches.push({
2760
- type: NavigateSibling,
2761
- index: i
2762
- });
2763
- currentChildIndex = i;
2764
- }
2765
- // Apply node patches (these apply to the current element, not children)
2766
- if (nodePatches.length > 0) {
2767
- patches.push(...nodePatches);
2768
- }
2769
- // Compare children recursively
2770
- if (hasChildrenToCompare) {
2771
- diffChildren(oldNode.children, newNode.children, patches);
2772
- }
2773
- }
2774
- } else {
2775
- // Remove old node - collect the index for later removal
2767
+ currentChildIndex = navigateToParent(patches, currentChildIndex);
2768
+ addTree(newNode, patches);
2769
+ continue;
2770
+ }
2771
+ if (!newNode) {
2776
2772
  indicesToRemove.push(i);
2773
+ continue;
2777
2774
  }
2775
+ currentChildIndex = diffExistingChild(oldNode, newNode, patches, currentChildIndex, i);
2778
2776
  }
2779
- // Navigate back to parent if we ended at a child
2780
- if (currentChildIndex >= 0) {
2781
- patches.push({
2782
- type: NavigateParent
2783
- });
2784
- }
2785
- // Add remove patches in reverse order (highest index first)
2786
- // This ensures indices remain valid as we remove
2777
+ navigateToParent(patches, currentChildIndex);
2787
2778
  for (let j = indicesToRemove.length - 1; j >= 0; j--) {
2788
2779
  patches.push({
2789
2780
  type: RemoveChild,
@@ -2792,33 +2783,11 @@ const diffChildren = (oldChildren, newChildren, patches) => {
2792
2783
  }
2793
2784
  };
2794
2785
  const diffTrees = (oldTree, newTree, patches, path) => {
2795
- // At the root level (path.length === 0), we're already AT the element
2796
- // So we compare the root node directly, then compare its children
2797
2786
  if (path.length === 0 && oldTree.length === 1 && newTree.length === 1) {
2798
- const oldNode = oldTree[0];
2799
- const newNode = newTree[0];
2800
- // Compare root nodes
2801
- const nodePatches = compareNodes(oldNode.node, newNode.node);
2802
- // If nodePatches is null, the root node types are incompatible - need to replace
2803
- if (nodePatches === null) {
2804
- const flatNodes = treeToArray(newNode);
2805
- patches.push({
2806
- type: Replace,
2807
- nodes: flatNodes
2808
- });
2809
- return;
2810
- }
2811
- if (nodePatches.length > 0) {
2812
- patches.push(...nodePatches);
2813
- }
2814
- // Compare children
2815
- if (oldNode.children.length > 0 || newNode.children.length > 0) {
2816
- diffChildren(oldNode.children, newNode.children, patches);
2817
- }
2818
- } else {
2819
- // Non-root level or multiple root elements - use the regular comparison
2820
- diffChildren(oldTree, newTree, patches);
2787
+ diffRootNode(oldTree[0], newTree[0], patches);
2788
+ return;
2821
2789
  }
2790
+ diffChildren(oldTree, newTree, patches);
2822
2791
  };
2823
2792
 
2824
2793
  const removeTrailingNavigationPatches = patches => {
@@ -2897,6 +2866,12 @@ const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editin
2897
2866
  for (let i = minLineY; i < Math.min(maxLineY, items.length); i++) {
2898
2867
  const item = items[i];
2899
2868
  let chevron = getChevronType(item.type, useChevrons);
2869
+ const isEditing = i === editingIndex;
2870
+ let icon = icons[iconIndex++];
2871
+ if (isEditing) {
2872
+ icon = editingIcon;
2873
+ chevron = getEditingChevron(item.type);
2874
+ }
2900
2875
  const isFocused = i === focusedIndex;
2901
2876
  const id = isFocused ? 'TreeItemActive' : undefined;
2902
2877
  const isSelected = item.selected;
@@ -2908,12 +2883,6 @@ const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editin
2908
2883
  const className = getTreeItemClassName(isSelected, isFocused, isDropping, useChevrons, indent, decoration);
2909
2884
  const expanded = getExpandedType(item.type);
2910
2885
  const ariaExpanded = ariaExpandedValues[expanded];
2911
- const isEditing = i === editingIndex;
2912
- let icon = icons[iconIndex++];
2913
- if (isEditing) {
2914
- icon = editingIcon;
2915
- chevron = getEditingChevron(item.type);
2916
- }
2917
2886
  visible.push({
2918
2887
  ...item,
2919
2888
  ariaExpanded,
@@ -3850,7 +3819,7 @@ const OpenFolder = 'OpenFolder';
3850
3819
  const Refresh$1 = 'Refresh';
3851
3820
 
3852
3821
  const isFolder = direntType => {
3853
- return direntType === Directory || direntType === DirectoryExpanded || direntType === SymLinkFolder;
3822
+ return [Directory, DirectoryExpanded, SymLinkFolder].includes(direntType);
3854
3823
  };
3855
3824
  const getFittingIndex = (dirents, startIndex) => {
3856
3825
  for (let i = startIndex; i >= 0; i--) {
@@ -4287,12 +4256,7 @@ const handleClickAt = async (state, defaultPrevented, button, ctrlKey, shiftKey,
4287
4256
  }
4288
4257
  const index = getIndexFromPosition(state, eventX, eventY);
4289
4258
  if (index === -1 || index >= state.items.length) {
4290
- return {
4291
- ...state,
4292
- focused: true,
4293
- focusedIndex: -1
4294
- // TODO mark all items as not selected
4295
- };
4259
+ return focusIndex(state, -1);
4296
4260
  }
4297
4261
  if (shiftKey) {
4298
4262
  return handleClickAtRangeSelection(state, index);
@@ -4396,6 +4360,7 @@ const handleCopy = async state => {
4396
4360
  await writeNativeFiles('copy', files);
4397
4361
  return {
4398
4362
  ...state,
4363
+ cutItems: [],
4399
4364
  pasteShouldMove: false
4400
4365
  };
4401
4366
  };
@@ -4884,11 +4849,7 @@ const getDroppedName = item => {
4884
4849
  return item.name;
4885
4850
  };
4886
4851
  const getFileSystemHandlesNormalized = fileSystemHandles => {
4887
- const normalized = [];
4888
- for (const item of fileSystemHandles) {
4889
- normalized.push(getFileSystemHandle(item));
4890
- }
4891
- return normalized;
4852
+ return Array.from(fileSystemHandles, getFileSystemHandle);
4892
4853
  };
4893
4854
  const uploadFileSystemHandles = async (root, pathSeparator, fileSystemHandles) => {
4894
4855
  if (fileSystemHandles.length === 0) {
@@ -5186,6 +5147,9 @@ const handleEscape = async state => {
5186
5147
  };
5187
5148
 
5188
5149
  const handleFocus = async state => {
5150
+ if (state.editingIndex !== -1) {
5151
+ return state;
5152
+ }
5189
5153
  return {
5190
5154
  ...state,
5191
5155
  focus: List
@@ -5265,7 +5229,7 @@ const isAscii = key => {
5265
5229
  return RE_ASCII.test(key);
5266
5230
  };
5267
5231
 
5268
- let timeout;
5232
+ const typeAheadTimeout = {};
5269
5233
  const handleKeyDown = (state, key) => {
5270
5234
  const {
5271
5235
  focusedIndex,
@@ -5282,10 +5246,10 @@ const handleKeyDown = (state, key) => {
5282
5246
  const newFocusWord = focusWord + key.toLowerCase();
5283
5247
  const itemNames = items.map(item => item.name);
5284
5248
  const matchingIndex = filterByFocusWord(itemNames, focusedIndex, newFocusWord);
5285
- if (timeout) {
5286
- clearTimeout(timeout);
5249
+ if (typeAheadTimeout.value) {
5250
+ clearTimeout(typeAheadTimeout.value);
5287
5251
  }
5288
- timeout = setTimeout(async () => {
5252
+ typeAheadTimeout.value = setTimeout(async () => {
5289
5253
  await invoke$2('Explorer.cancelTypeAhead');
5290
5254
  }, focusWordTimeout);
5291
5255
  if (matchingIndex === -1) {
@@ -5674,7 +5638,7 @@ const getContainingFolder = (root, dirents, focusedIndex, pathSeparator) => {
5674
5638
  const dirent = dirents[focusedIndex];
5675
5639
  const direntPath = dirent.path;
5676
5640
  const direntParentPath = direntPath.slice(0, -(dirent.name.length + 1));
5677
- const path = `${direntParentPath}`;
5641
+ const path = direntParentPath;
5678
5642
  return path;
5679
5643
  };
5680
5644
 
@@ -5900,7 +5864,7 @@ const getDragLabel = urls => {
5900
5864
  if (urls.length === 1) {
5901
5865
  return getBaseName('/', urls[0]);
5902
5866
  }
5903
- return `${urls.length}`;
5867
+ return String(urls.length);
5904
5868
  };
5905
5869
 
5906
5870
  const toUri = path => {
@@ -6716,6 +6680,8 @@ const saveState = state => {
6716
6680
  };
6717
6681
  };
6718
6682
 
6683
+ // TODO select all should only select all items in the current folder
6684
+ // and when calling it next item, expand selection to its parent folder
6719
6685
  const selectAll = state => {
6720
6686
  const {
6721
6687
  items
@@ -6817,7 +6783,7 @@ const getEditingIcon = async (editingType, value, direntType) => {
6817
6783
  name: value
6818
6784
  });
6819
6785
  }
6820
- if (direntType === Directory || direntType === EditingFolder || direntType === EditingDirectoryExpanded) {
6786
+ if (direntType !== undefined && [Directory, EditingFolder, EditingDirectoryExpanded].includes(direntType)) {
6821
6787
  return invoke$2('IconTheme.getFolderIcon', {
6822
6788
  name: value
6823
6789
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "6.10.0",
3
+ "version": "6.13.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",