@lvce-editor/explorer-view 1.23.0 → 1.25.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.
@@ -898,18 +898,6 @@ const compareDirent = (direntA, direntB) => {
898
898
  return compareDirentType(direntA, direntB) || compareDirentName(direntA, direntB);
899
899
  };
900
900
 
901
- const getFileIcon = ({
902
- name
903
- }) => {
904
- return '';
905
- };
906
- const getIcon = dirent => {
907
- return '';
908
- };
909
- const getFolderIcon = dirent => {
910
- return '';
911
- };
912
-
913
901
  // TODO use posInSet and setSize properties to compute more effectively
914
902
  const computeExplorerRenamedDirent = (dirents, index, newName) => {
915
903
  let startIndex = index;
@@ -921,9 +909,7 @@ const computeExplorerRenamedDirent = (dirents, index, newName) => {
921
909
  ...oldDirent,
922
910
  name: newName,
923
911
  path: oldDirent.path.slice(0, -oldDirent.name.length) + newName,
924
- icon: getFileIcon({
925
- name: newName
926
- })
912
+ icon: ''
927
913
  };
928
914
  const {
929
915
  depth
@@ -1111,7 +1097,7 @@ const acceptCreate = async (state, newDirentType, createFn) => {
1111
1097
  type: newDirentType,
1112
1098
  icon: ''
1113
1099
  };
1114
- newDirent.icon = getIcon();
1100
+ newDirent.icon = '';
1115
1101
  let insertIndex = state.focusedIndex;
1116
1102
  let deltaPosInSet = 0;
1117
1103
  let posInSet = 1;
@@ -1441,7 +1427,7 @@ const toDisplayDirents = (pathSeparator, rawDirents, parentDirent, excluded) =>
1441
1427
  type: rawDirent.type,
1442
1428
  path,
1443
1429
  // TODO storing absolute path might be too costly, could also store relative path here
1444
- icon: getIcon()
1430
+ icon: ''
1445
1431
  };
1446
1432
  };
1447
1433
  const result = [];
@@ -1600,15 +1586,6 @@ const expandAll = async state => {
1600
1586
  };
1601
1587
  };
1602
1588
 
1603
- const getParentEndIndex = (dirents, index) => {
1604
- const dirent = dirents[index];
1605
- let endIndex = index + 1;
1606
- while (endIndex < dirents.length && dirents[endIndex].depth > dirent.depth) {
1607
- endIndex++;
1608
- }
1609
- return endIndex;
1610
- };
1611
-
1612
1589
  const makeExpanded = dirent => {
1613
1590
  if (dirent.type === Directory) {
1614
1591
  return {
@@ -1619,6 +1596,35 @@ const makeExpanded = dirent => {
1619
1596
  return dirent;
1620
1597
  };
1621
1598
 
1599
+ // TODO this is very inefficient
1600
+ const getChildDirentsRecursively = async (dirent, pathSeparator) => {
1601
+ switch (dirent.type) {
1602
+ case File:
1603
+ return [dirent];
1604
+ case Directory:
1605
+ case DirectoryExpanding:
1606
+ case DirectoryExpanded:
1607
+ const childDirents = await getChildDirents(pathSeparator, dirent);
1608
+ const all = [makeExpanded(dirent)];
1609
+ for (const childDirent of childDirents) {
1610
+ const childAll = await getChildDirentsRecursively(childDirent, pathSeparator);
1611
+ all.push(...childAll);
1612
+ }
1613
+ return all;
1614
+ default:
1615
+ return [];
1616
+ }
1617
+ };
1618
+
1619
+ const getParentEndIndex = (dirents, index) => {
1620
+ const dirent = dirents[index];
1621
+ let endIndex = index + 1;
1622
+ while (endIndex < dirents.length && dirents[endIndex].depth > dirent.depth) {
1623
+ endIndex++;
1624
+ }
1625
+ return endIndex;
1626
+ };
1627
+
1622
1628
  const expandRecursively = async state => {
1623
1629
  const {
1624
1630
  items,
@@ -1637,47 +1643,42 @@ const expandRecursively = async state => {
1637
1643
  if (dirent.type !== Directory && dirent.type !== DirectoryExpanding && dirent.type !== DirectoryExpanded) {
1638
1644
  return state;
1639
1645
  }
1640
- // TODO this is very inefficient
1641
- const getChildDirentsRecursively = async dirent => {
1642
- switch (dirent.type) {
1643
- case File:
1644
- return [dirent];
1645
- case Directory:
1646
- case DirectoryExpanding:
1647
- case DirectoryExpanded:
1648
- const childDirents = await getChildDirents(pathSeparator, dirent);
1649
- const all = [makeExpanded(dirent)];
1650
- for (const childDirent of childDirents) {
1651
- const childAll = await getChildDirentsRecursively(childDirent);
1652
- all.push(...childAll);
1653
- }
1654
- return all;
1655
- default:
1656
- return [];
1657
- }
1658
- };
1659
1646
  // TODO race condition: what if folder is being collapse while it is recursively expanding?
1660
1647
  // TODO race condition: what if folder is being deleted while it is recursively expanding?
1661
1648
  // TODO race condition: what if a new file/folder is created while the folder is recursively expanding?
1662
1649
  // @ts-ignore
1663
- const childDirents = await getChildDirentsRecursively(dirent);
1650
+ const childDirents = await getChildDirentsRecursively(dirent, pathSeparator);
1664
1651
  const startIndex = focusedIndex;
1665
1652
  if (focusedIndex >= 0) {
1666
1653
  const endIndex = getParentEndIndex(items, focusedIndex);
1667
1654
  const newDirents = [...items.slice(0, startIndex), ...childDirents, ...items.slice(endIndex)];
1668
1655
  const maxLineY = getExplorerMaxLineY(minLineY, height, itemHeight, newDirents.length);
1656
+ const visible = newDirents.slice(minLineY, maxLineY);
1657
+ const {
1658
+ icons,
1659
+ newFileIconCache
1660
+ } = await getFileIcons(visible, state.fileIconCache);
1669
1661
  return {
1670
1662
  ...state,
1671
1663
  items: newDirents,
1672
- maxLineY
1664
+ maxLineY,
1665
+ icons,
1666
+ fileIconCache: newFileIconCache
1673
1667
  };
1674
1668
  }
1675
1669
  const newDirents = childDirents.slice(1);
1676
1670
  const maxLineY = getExplorerMaxLineY(minLineY, height, itemHeight, newDirents.length);
1671
+ const visible = newDirents.slice(minLineY, maxLineY);
1672
+ const {
1673
+ icons,
1674
+ newFileIconCache
1675
+ } = await getFileIcons(visible, state.fileIconCache);
1677
1676
  return {
1678
1677
  ...state,
1679
1678
  items: newDirents,
1680
- maxLineY
1679
+ maxLineY,
1680
+ icons,
1681
+ fileIconCache: newFileIconCache
1681
1682
  };
1682
1683
  };
1683
1684
 
@@ -2422,7 +2423,7 @@ const handleClickDirectoryExpanded = async (state, dirent, index, keepFocus) =>
2422
2423
  // @ts-ignore
2423
2424
  dirent.type = Directory;
2424
2425
  // @ts-ignore
2425
- dirent.icon = getIcon();
2426
+ dirent.icon = '';
2426
2427
  const endIndex = getParentEndIndex(state.items, index);
2427
2428
  const removeCount = endIndex - index - 1;
2428
2429
  // TODO race conditions and side effects are everywhere
@@ -2523,7 +2524,7 @@ const handleClickDirectory = async (state, dirent, index, keepFocus) => {
2523
2524
  // @ts-ignore
2524
2525
  dirent.type = DirectoryExpanded;
2525
2526
  // @ts-ignore
2526
- dirent.icon = getIcon();
2527
+ dirent.icon = '';
2527
2528
  const {
2528
2529
  height,
2529
2530
  itemHeight,
@@ -2616,7 +2617,7 @@ const handleClickDirectoryExpanding = async (state, dirent, index, keepFocus) =>
2616
2617
  // @ts-ignore
2617
2618
  dirent.type = Directory;
2618
2619
  // @ts-ignore
2619
- dirent.icon = getIcon();
2620
+ dirent.icon = '';
2620
2621
  return {
2621
2622
  ...state,
2622
2623
  focusedIndex: index,
@@ -3041,15 +3042,27 @@ const handleFocus = async state => {
3041
3042
  const updateIcon = dirent => {
3042
3043
  return {
3043
3044
  ...dirent,
3044
- icon: getIcon()
3045
+ icon: ''
3045
3046
  };
3046
3047
  };
3047
3048
 
3048
- const updateIcons = state => {
3049
+ const updateIcons = async state => {
3049
3050
  const newDirents = state.items.map(updateIcon);
3051
+ const {
3052
+ items,
3053
+ minLineY,
3054
+ maxLineY
3055
+ } = state;
3056
+ const visible = items.slice(minLineY, maxLineY);
3057
+ const {
3058
+ icons,
3059
+ newFileIconCache
3060
+ } = await getFileIcons(visible, Object.create(null));
3050
3061
  return {
3051
3062
  ...state,
3052
- items: newDirents
3063
+ items: newDirents,
3064
+ icons,
3065
+ fileIconCache: newFileIconCache
3053
3066
  };
3054
3067
  };
3055
3068
 
@@ -3283,7 +3296,7 @@ const getSavedChildDirents = (map, path, depth, excluded, pathSeparator) => {
3283
3296
  depth,
3284
3297
  posInSet: i + 1,
3285
3298
  setSize: visibleLength,
3286
- icon: getFolderIcon(),
3299
+ icon: '',
3287
3300
  name,
3288
3301
  path: childPath,
3289
3302
  type: DirectoryExpanded
@@ -3294,7 +3307,7 @@ const getSavedChildDirents = (map, path, depth, excluded, pathSeparator) => {
3294
3307
  depth,
3295
3308
  posInSet: i + 1,
3296
3309
  setSize: visibleLength,
3297
- icon: getIcon(),
3310
+ icon: '',
3298
3311
  name,
3299
3312
  path: childPath,
3300
3313
  type
@@ -3977,9 +3990,7 @@ const terminate = () => {
3977
3990
  };
3978
3991
 
3979
3992
  const updateEditingValue = (state, value) => {
3980
- const editingIcon = getFileIcon({
3981
- name: value
3982
- });
3993
+ const editingIcon = '';
3983
3994
  return {
3984
3995
  ...state,
3985
3996
  editingValue: value,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "1.23.0",
3
+ "version": "1.25.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",