@lvce-editor/explorer-view 2.13.0 → 2.15.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.
@@ -981,6 +981,10 @@ const getMissingIconRequests = (dirents, fileIconCache) => {
981
981
  return missingRequests;
982
982
  };
983
983
 
984
+ const getPath = dirent => {
985
+ return dirent.path;
986
+ };
987
+
984
988
  const BlockDevice = 1;
985
989
  const CharacterDevice = 2;
986
990
  const Directory = 3;
@@ -1037,7 +1041,7 @@ const getFileIcons = async (dirents, fileIconCache) => {
1037
1041
  const missingRequests = getMissingIconRequests(dirents, fileIconCache);
1038
1042
  const newIcons = await requestFileIcons(missingRequests);
1039
1043
  const newFileIconCache = updateIconCache(fileIconCache, missingRequests, newIcons);
1040
- const paths = dirents.map(dirent => dirent.path);
1044
+ const paths = dirents.map(getPath);
1041
1045
  const icons = getIconsCached(paths, newFileIconCache);
1042
1046
  return {
1043
1047
  icons,
@@ -1448,6 +1452,10 @@ const getFocusedDirent$1 = state => {
1448
1452
  };
1449
1453
 
1450
1454
  const copyPath = async state => {
1455
+ const dirent = getFocusedDirent$1(state);
1456
+ if (!dirent) {
1457
+ return state;
1458
+ }
1451
1459
  // await Command.execute(RendererWorkerCommandType.ClipBoardWriteText, /* text */ path)
1452
1460
  return state;
1453
1461
  };
@@ -1464,6 +1472,9 @@ const writeNativeFiles = async (type, files) => {
1464
1472
 
1465
1473
  const copyRelativePath = async state => {
1466
1474
  const dirent = getFocusedDirent$1(state);
1475
+ if (!dirent) {
1476
+ return state;
1477
+ }
1467
1478
  const relativePath = dirent.path.slice(1);
1468
1479
  // TODO handle error
1469
1480
  await writeText(relativePath);
@@ -1561,49 +1572,27 @@ const create = (id, uri, x, y, width, height, args, parentUid, platform = 0) =>
1561
1572
  };
1562
1573
 
1563
1574
  const RenderItems = 4;
1564
- const RenderEditingIndex = 5;
1565
1575
  const RenderFocus = 6;
1566
1576
 
1567
- const diffType$2 = RenderEditingIndex;
1568
- const isEqual$3 = (oldState, newState) => {
1569
- return oldState.editingIndex === newState.editingIndex && oldState.editingType === newState.editingType;
1570
- };
1571
-
1572
- const DiffEditingIndex = {
1573
- __proto__: null,
1574
- diffType: diffType$2,
1575
- isEqual: isEqual$3
1576
- };
1577
-
1578
1577
  const diffType$1 = RenderFocus;
1579
1578
  const isEqual$2 = (oldState, newState) => {
1580
1579
  return oldState.focused === newState.focused && oldState.focus === newState.focus;
1581
1580
  };
1582
1581
 
1583
- const DiffFocus = {
1584
- __proto__: null,
1585
- diffType: diffType$1,
1586
- isEqual: isEqual$2
1587
- };
1588
-
1589
1582
  const diffType = RenderItems;
1590
1583
  const isEqual$1 = (oldState, newState) => {
1591
1584
  return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.focusedIndex === newState.focusedIndex && oldState.editingIndex === newState.editingIndex && oldState.editingType === newState.editingType && oldState.editingValue === newState.editingValue && oldState.editingErrorMessage === newState.editingErrorMessage && oldState.width === newState.width && oldState.focused === newState.focused && oldState.dropTargets === newState.dropTargets;
1592
1585
  };
1593
1586
 
1594
- const DiffItems = {
1595
- __proto__: null,
1596
- diffType,
1597
- isEqual: isEqual$1
1598
- };
1599
-
1600
- const modules = [DiffItems, DiffEditingIndex, DiffFocus];
1587
+ const modules = [isEqual$1, isEqual$2];
1588
+ const numbers = [diffType, diffType$1];
1601
1589
 
1602
1590
  const diff = (oldState, newState) => {
1603
1591
  const diffResult = [];
1604
- for (const module of modules) {
1605
- if (!module.isEqual(oldState, newState)) {
1606
- diffResult.push(module.diffType);
1592
+ for (let i = 0; i < modules.length; i++) {
1593
+ const fn = modules[i];
1594
+ if (!fn(oldState, newState)) {
1595
+ diffResult.push(numbers[i]);
1607
1596
  }
1608
1597
  }
1609
1598
  return diffResult;
@@ -2598,12 +2587,14 @@ const handleContextMenuMouseAt = async (state, x, y) => {
2598
2587
  number(x);
2599
2588
  number(y);
2600
2589
  const focusedIndex = getIndexFromPosition(state, x, y);
2601
- await show(x, y, Explorer$1);
2602
- return {
2590
+ const newState = {
2603
2591
  ...state,
2604
2592
  focusedIndex,
2605
2593
  focused: false
2606
2594
  };
2595
+ set(state.uid, state, newState);
2596
+ await show(x, y, Explorer$1);
2597
+ return state;
2607
2598
  };
2608
2599
 
2609
2600
  const getContextMenuHandler = button => {
@@ -3072,15 +3063,7 @@ const handleFocus = async state => {
3072
3063
  return state;
3073
3064
  };
3074
3065
 
3075
- const updateIcon = dirent => {
3076
- return {
3077
- ...dirent,
3078
- icon: ''
3079
- };
3080
- };
3081
-
3082
3066
  const updateIcons = async state => {
3083
- const newDirents = state.items.map(updateIcon);
3084
3067
  const {
3085
3068
  items,
3086
3069
  minLineY,
@@ -3093,7 +3076,6 @@ const updateIcons = async state => {
3093
3076
  } = await getFileIcons(visible, Object.create(null));
3094
3077
  return {
3095
3078
  ...state,
3096
- items: newDirents,
3097
3079
  icons,
3098
3080
  fileIconCache: newFileIconCache
3099
3081
  };
@@ -3206,7 +3188,8 @@ const handlePointerDown = (state, button, x, y) => {
3206
3188
  return {
3207
3189
  ...state,
3208
3190
  focused: true,
3209
- focusedIndex: -1
3191
+ focusedIndex: -1,
3192
+ focus: List
3210
3193
  };
3211
3194
  }
3212
3195
  return state;
@@ -3489,7 +3472,7 @@ const newFolder = state => {
3489
3472
  return newDirent(state, CreateFolder);
3490
3473
  };
3491
3474
 
3492
- const getContaingingFolder = (root, dirents, focusedIndex, pathSeparator) => {
3475
+ const getContainingFolder = (root, dirents, focusedIndex, pathSeparator) => {
3493
3476
  if (focusedIndex < 0) {
3494
3477
  return root;
3495
3478
  }
@@ -3499,13 +3482,18 @@ const getContaingingFolder = (root, dirents, focusedIndex, pathSeparator) => {
3499
3482
  const path = `${direntParentPath}`;
3500
3483
  return path;
3501
3484
  };
3485
+
3486
+ const openNativeFolder = async path => {
3487
+ await invoke('OpenNativeFolder.openNativeFolder', /* path */path);
3488
+ };
3489
+
3502
3490
  const openContainingFolder = async state => {
3503
3491
  const {
3504
3492
  focusedIndex,
3505
3493
  root,
3506
3494
  items} = state;
3507
- const path = getContaingingFolder(root, items, focusedIndex);
3508
- await invoke('OpenNativeFolder.openNativeFolder', /* path */path);
3495
+ const path = getContainingFolder(root, items, focusedIndex);
3496
+ await openNativeFolder(path);
3509
3497
  return state;
3510
3498
  };
3511
3499
 
@@ -3515,6 +3503,9 @@ const removeDirent = async state => {
3515
3503
  return state;
3516
3504
  }
3517
3505
  const dirent = getFocusedDirent$1(state);
3506
+ if (!dirent) {
3507
+ return state;
3508
+ }
3518
3509
  const absolutePath = dirent.path;
3519
3510
  try {
3520
3511
  // TODO handle error
@@ -3587,16 +3578,20 @@ const renameDirent = state => {
3587
3578
  };
3588
3579
  };
3589
3580
 
3590
- const renderEditingIndex = (oldState, newState) => {
3591
- return ['focusInput', 'ExplorerInput'];
3592
- };
3593
-
3594
3581
  const ExplorerInput = 'ExplorerInput';
3595
3582
 
3583
+ const User = 1;
3584
+
3596
3585
  const renderFocus = (oldState, newState) => {
3586
+ if (newState.inputSource === User) {
3587
+ return [];
3588
+ }
3597
3589
  if (newState.focus === Input$1) {
3598
3590
  return ['Viewlet.focusElementByName', ExplorerInput];
3599
3591
  }
3592
+ if (newState.focus === List) {
3593
+ return ['Viewlet.focusSelector', '.ListItems'];
3594
+ }
3600
3595
  // TODO
3601
3596
  // 1. when focused, focus the outer list element
3602
3597
  // 2. when focused, set focus context in renderer worker
@@ -3619,6 +3614,7 @@ const Explorer = 'Explorer';
3619
3614
  const ExplorerDropTarget = 'DropTarget';
3620
3615
  const FileIcon = 'FileIcon';
3621
3616
  const FocusOutline = 'FocusOutline';
3617
+ const ListItems = 'ListItems';
3622
3618
  const IconButton = 'IconButton';
3623
3619
  const InputBox = 'InputBox';
3624
3620
  const InputValidationError = 'InputValidationError';
@@ -3796,14 +3792,20 @@ const getActiveDescendant = focusedIndex => {
3796
3792
  const getClassName = (focused, focusedIndex, dropTarget) => {
3797
3793
  const extraClass1 = focused && focusedIndex === -1 ? FocusOutline : Empty;
3798
3794
  const extraClass2 = dropTarget === dropTargetFull ? ExplorerDropTarget : Empty;
3799
- const className = mergeClassNames(Viewlet, Explorer, extraClass1, extraClass2);
3795
+ const className = mergeClassNames(ListItems, extraClass1, extraClass2);
3800
3796
  return className;
3801
3797
  };
3798
+ const parentNode = {
3799
+ type: Div,
3800
+ childCount: 1,
3801
+ className: mergeClassNames(Viewlet, Explorer),
3802
+ role: 'none'
3803
+ };
3802
3804
  const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused, dropTargets) => {
3803
3805
  if (!root) {
3804
3806
  return getExplorerWelcomeVirtualDom(isWide);
3805
3807
  }
3806
- const dom = [{
3808
+ const dom = [parentNode, {
3807
3809
  type: Div,
3808
3810
  className: getClassName(focused, focusedIndex, dropTargets),
3809
3811
  tabIndex: 0,
@@ -3932,8 +3934,6 @@ const renderItems = (oldState, newState) => {
3932
3934
 
3933
3935
  const getRenderer = diffType => {
3934
3936
  switch (diffType) {
3935
- case RenderEditingIndex:
3936
- return renderEditingIndex;
3937
3937
  case RenderItems:
3938
3938
  return renderItems;
3939
3939
  case RenderFocus:
@@ -4159,6 +4159,18 @@ const getPathParts = (root, uri, pathSeparator) => {
4159
4159
  return parts;
4160
4160
  };
4161
4161
 
4162
+ const getPathPartsToReveal = (root, pathParts, dirents) => {
4163
+ for (let i = 0; i < pathParts.length; i++) {
4164
+ const pathPart = pathParts[i];
4165
+ const index = getIndex(dirents, pathPart.path);
4166
+ if (index === -1) {
4167
+ continue;
4168
+ }
4169
+ return pathParts.slice(i);
4170
+ }
4171
+ return pathParts;
4172
+ };
4173
+
4162
4174
  const isTopLevel = dirent => {
4163
4175
  return dirent.depth === 1;
4164
4176
  };
@@ -4166,23 +4178,22 @@ const orderDirents = dirents => {
4166
4178
  if (dirents.length === 0) {
4167
4179
  return dirents;
4168
4180
  }
4169
- // const parentMap = Object.create(null)
4170
- // for(const dirent of dirents){
4171
- // const parentPath = dirent.slice(0, dirent.lastIndexOf('/'))
4172
- // parentMap[parentPath]||=[]
4173
- // parentMap[parentPath].push(dirent)
4174
- // }
4175
- const withDeepChildren = parent => {
4181
+ const withDeepChildren = (parent, processed) => {
4182
+ if (processed.has(parent.path)) {
4183
+ return [];
4184
+ }
4185
+ processed.add(parent.path);
4176
4186
  const children = [];
4177
4187
  for (const dirent of dirents) {
4178
4188
  if (dirent.depth === parent.depth + 1 && dirent.path.startsWith(parent.path)) {
4179
- children.push(dirent, ...withDeepChildren(dirent));
4189
+ children.push(...withDeepChildren(dirent, processed));
4180
4190
  }
4181
4191
  }
4182
4192
  return [parent, ...children];
4183
4193
  };
4184
4194
  const topLevelDirents = dirents.filter(isTopLevel);
4185
- const ordered = topLevelDirents.flatMap(withDeepChildren);
4195
+ const processed = new Set();
4196
+ const ordered = topLevelDirents.flatMap(dirent => withDeepChildren(dirent, processed));
4186
4197
  return ordered;
4187
4198
  };
4188
4199
 
@@ -4208,17 +4219,6 @@ const scrollInto = (index, minLineY, maxLineY) => {
4208
4219
  };
4209
4220
  };
4210
4221
 
4211
- const getPathPartsToReveal = (root, pathParts, dirents) => {
4212
- for (let i = 0; i < pathParts.length; i++) {
4213
- const pathPart = pathParts[i];
4214
- const index = getIndex(dirents, pathPart.uri);
4215
- if (index === -1) {
4216
- continue;
4217
- }
4218
- return pathParts.slice(i);
4219
- }
4220
- return pathParts;
4221
- };
4222
4222
  const getPathPartChildren = async pathPart => {
4223
4223
  const children = await getChildDirents(pathPart.pathSeparator, pathPart);
4224
4224
  return children;
@@ -4355,10 +4355,6 @@ const revealItem = async (state, uri) => {
4355
4355
  return revealItemVisible(state, index);
4356
4356
  };
4357
4357
 
4358
- const getPath = dirent => {
4359
- return dirent.path;
4360
- };
4361
-
4362
4358
  const isExpandedDirectory = dirent => {
4363
4359
  return dirent.type === DirectoryExpanded;
4364
4360
  };
@@ -4390,8 +4386,6 @@ const terminate = () => {
4390
4386
  globalThis.close();
4391
4387
  };
4392
4388
 
4393
- const User = 1;
4394
-
4395
4389
  const updateEditingValue = (state, value, inputSource = User) => {
4396
4390
  const editingIcon = '';
4397
4391
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.13.0",
3
+ "version": "2.15.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",