@lvce-editor/explorer-view 1.27.0 → 1.28.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.
@@ -809,6 +809,9 @@ const createRpc = ipc => {
809
809
  },
810
810
  invokeAndTransfer(method, ...params) {
811
811
  return invokeAndTransfer(ipc, method, ...params);
812
+ },
813
+ async dispose() {
814
+ await ipc?.dispose();
812
815
  }
813
816
  };
814
817
  return rpc;
@@ -1320,13 +1323,25 @@ const create = (id, uri, x, y, width, height, args, parentUid) => {
1320
1323
 
1321
1324
  const RenderItems = 4;
1322
1325
  const RenderEditingIndex = 5;
1326
+ const RenderFocus = 6;
1323
1327
 
1324
- const diffType$1 = RenderEditingIndex;
1325
- const isEqual$2 = (oldState, newState) => {
1328
+ const diffType$2 = RenderEditingIndex;
1329
+ const isEqual$3 = (oldState, newState) => {
1326
1330
  return oldState.editingIndex === newState.editingIndex && oldState.editingType === newState.editingType;
1327
1331
  };
1328
1332
 
1329
1333
  const DiffEditingIndex = {
1334
+ __proto__: null,
1335
+ diffType: diffType$2,
1336
+ isEqual: isEqual$3
1337
+ };
1338
+
1339
+ const diffType$1 = RenderFocus;
1340
+ const isEqual$2 = (oldState, newState) => {
1341
+ return oldState.focused === newState.focused;
1342
+ };
1343
+
1344
+ const DiffFocus = {
1330
1345
  __proto__: null,
1331
1346
  diffType: diffType$1,
1332
1347
  isEqual: isEqual$2
@@ -1343,7 +1358,7 @@ const DiffItems = {
1343
1358
  isEqual: isEqual$1
1344
1359
  };
1345
1360
 
1346
- const modules = [DiffItems, DiffEditingIndex];
1361
+ const modules = [DiffItems, DiffEditingIndex, DiffFocus];
1347
1362
 
1348
1363
  const diff = (oldState, newState) => {
1349
1364
  const diffResult = [];
@@ -1355,6 +1370,15 @@ const diff = (oldState, newState) => {
1355
1370
  return diffResult;
1356
1371
  };
1357
1372
 
1373
+ const diff2 = uid => {
1374
+ const {
1375
+ oldState,
1376
+ newState
1377
+ } = get(uid);
1378
+ const result = diff(oldState, newState);
1379
+ return result;
1380
+ };
1381
+
1358
1382
  const isSymbolicLink = dirent => {
1359
1383
  return dirent.type === Symlink;
1360
1384
  };
@@ -1411,11 +1435,11 @@ const resolveSymbolicLinks = async (uri, rawDirents) => {
1411
1435
  };
1412
1436
 
1413
1437
  const sortExplorerItems = rawDirents => {
1414
- rawDirents.sort(compareDirent);
1438
+ return rawDirents.toSorted(compareDirent);
1415
1439
  };
1416
1440
 
1417
1441
  const toDisplayDirents = (pathSeparator, rawDirents, parentDirent, excluded) => {
1418
- sortExplorerItems(rawDirents);
1442
+ rawDirents = sortExplorerItems(rawDirents);
1419
1443
  // TODO figure out whether this uses too much memory (name,path -> redundant, depth could be computed on demand)
1420
1444
  const toDisplayDirent = (rawDirent, index) => {
1421
1445
  const path = [parentDirent.path, rawDirent.name].join(pathSeparator);
@@ -1481,7 +1505,7 @@ const getExplorerMaxLineY = (minLineY, height, itemHeight, direntsLength) => {
1481
1505
  };
1482
1506
 
1483
1507
  const getIconsCached = (dirents, fileIconCache) => {
1484
- return dirents.map(dirent => fileIconCache[dirent.path]);
1508
+ return dirents.map(dirent => fileIconCache[dirent]);
1485
1509
  };
1486
1510
 
1487
1511
  const getMissingIconRequests = (dirents, fileIconCache) => {
@@ -1526,7 +1550,8 @@ const getFileIcons = async (dirents, fileIconCache) => {
1526
1550
  const missingRequests = getMissingIconRequests(dirents, fileIconCache);
1527
1551
  const newIcons = await requestFileIcons(missingRequests);
1528
1552
  const newFileIconCache = updateIconCache(fileIconCache, missingRequests, newIcons);
1529
- const icons = getIconsCached(dirents, newFileIconCache);
1553
+ const paths = dirents.map(dirent => dirent.path);
1554
+ const icons = getIconsCached(paths, newFileIconCache);
1530
1555
  return {
1531
1556
  icons,
1532
1557
  newFileIconCache
@@ -1932,31 +1957,42 @@ const WelcomeMessage = 'WelcomeMessage';
1932
1957
  // only numbers are compared. it could also make rendering faster,
1933
1958
  // since less data is transferred to renderer process
1934
1959
 
1935
- const HandleBlur = 'handleBlur';
1936
1960
  const HandleClick = 'handleClick';
1937
1961
  const HandleClickOpenFolder = 'handleClickOpenFolder';
1938
1962
  const HandleContextMenu = 'handleContextMenu';
1939
1963
  const HandleEditingInput = 'handleEditingInput';
1940
- const HandleFocus = 'handleFocus';
1964
+ const HandleListBlur = 'handleListBlur';
1965
+ const HandleListFocus = 'handleListFocus';
1941
1966
  const HandlePointerDown = 'handlePointerDown';
1942
1967
  const HandleWheel = 'handleWheel';
1943
1968
 
1969
+ const mergeClassNames = (...classNames) => {
1970
+ return classNames.filter(Boolean).join(' ');
1971
+ };
1972
+ const Text = 12;
1973
+ const text = data => {
1974
+ return {
1975
+ type: Text,
1976
+ text: data,
1977
+ childCount: 0
1978
+ };
1979
+ };
1980
+
1944
1981
  const Button = 1;
1945
1982
  const Div = 4;
1946
1983
  const Input = 6;
1947
- const Text = 12;
1948
1984
  const Img = 17;
1949
1985
  const P = 50;
1950
1986
 
1951
1987
  const chevronDownVirtualDom = {
1952
1988
  type: Div,
1953
- className: `${Chevron} ${MaskIconChevronDown}`,
1989
+ className: mergeClassNames(Chevron, MaskIconChevronDown),
1954
1990
  childCount: 0
1955
1991
  };
1956
1992
 
1957
1993
  const chevronRightVirtualDom = {
1958
1994
  type: Div,
1959
- className: `${Chevron} ${MaskIconChevronRight}`,
1995
+ className: mergeClassNames(Chevron, MaskIconChevronRight),
1960
1996
  childCount: 0
1961
1997
  };
1962
1998
 
@@ -1975,15 +2011,7 @@ const getFileIconVirtualDom = icon => {
1975
2011
  };
1976
2012
  };
1977
2013
 
1978
- const ExplorerInput = 'ExploreerInput';
1979
-
1980
- const text = data => {
1981
- return {
1982
- type: Text,
1983
- text: data,
1984
- childCount: 0
1985
- };
1986
- };
2014
+ const ExplorerInput = 'ExplorerInput';
1987
2015
 
1988
2016
  const label = {
1989
2017
  type: Div,
@@ -2039,10 +2067,6 @@ const getExplorerItemVirtualDom = item => {
2039
2067
  return dom;
2040
2068
  };
2041
2069
 
2042
- const mergeClassNames = (...classNames) => {
2043
- return classNames.filter(Boolean).join(' ');
2044
- };
2045
-
2046
2070
  const getExplorerWelcomeVirtualDom = isWide => {
2047
2071
  return [{
2048
2072
  type: Div,
@@ -2084,8 +2108,8 @@ const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused
2084
2108
  ariaLabel: filesExplorer(),
2085
2109
  childCount: visibleItems.length,
2086
2110
  ariaActiveDescendant: getActiveDescendant(focusedIndex),
2087
- onFocus: HandleFocus,
2088
- onBlur: HandleBlur,
2111
+ onFocus: HandleListFocus,
2112
+ onBlur: HandleListBlur,
2089
2113
  onContextMenu: HandleContextMenu,
2090
2114
  onPointerDown: HandlePointerDown,
2091
2115
  onWheel: HandleWheel,
@@ -2620,6 +2644,13 @@ const handleBlur = state => {
2620
2644
  };
2621
2645
  };
2622
2646
 
2647
+ class ExplorerError extends Error {
2648
+ constructor(message) {
2649
+ super(message);
2650
+ this.name = 'ExplorerError';
2651
+ }
2652
+ }
2653
+
2623
2654
  const handleClickDirectoryExpanding = async (state, dirent, index, keepFocus) => {
2624
2655
  // @ts-ignore
2625
2656
  dirent.type = Directory;
@@ -2664,13 +2695,13 @@ const getClickFn = direntType => {
2664
2695
  case Symlink:
2665
2696
  return handleClickSymLink;
2666
2697
  case CharacterDevice:
2667
- throw new Error('Cannot open character device files');
2698
+ throw new ExplorerError('Cannot open character device files');
2668
2699
  case BlockDevice:
2669
- throw new Error('Cannot open block device files');
2700
+ throw new ExplorerError('Cannot open block device files');
2670
2701
  case Socket:
2671
- throw new Error('Cannot open socket files');
2702
+ throw new ExplorerError('Cannot open socket files');
2672
2703
  default:
2673
- throw new Error(`unsupported dirent type ${direntType}`);
2704
+ throw new ExplorerError(`unsupported dirent type ${direntType}`);
2674
2705
  }
2675
2706
  };
2676
2707
 
@@ -2786,15 +2817,21 @@ const handleContextMenuMouseAt = async (state, x, y) => {
2786
2817
  };
2787
2818
  };
2788
2819
 
2789
- const handleContextMenu = (state, button, x, y) => {
2820
+ const getContextMenuHandler = button => {
2790
2821
  switch (button) {
2791
2822
  case Keyboard:
2792
- return handleContextMenuKeyboard(state);
2823
+ return handleContextMenuKeyboard;
2793
2824
  default:
2794
- return handleContextMenuMouseAt(state, x, y);
2825
+ return handleContextMenuMouseAt;
2795
2826
  }
2796
2827
  };
2797
2828
 
2829
+ const handleContextMenu = async (state, button, x, y) => {
2830
+ const fn = getContextMenuHandler(button);
2831
+ const newState = await fn(state, x, y);
2832
+ return newState;
2833
+ };
2834
+
2798
2835
  const handleCopy = async state => {
2799
2836
  // TODO handle multiple files
2800
2837
  // TODO if not file is selected, what happens?
@@ -3272,16 +3309,13 @@ const getSettings = async () => {
3272
3309
 
3273
3310
  const EmptyString = '';
3274
3311
 
3275
- const Fulfilled = 'fulfilled';
3276
- const Rejected = 'rejected';
3277
-
3278
3312
  const getSavedChildDirents = (map, path, depth, excluded, pathSeparator) => {
3279
- const children = map[path];
3313
+ let children = map[path];
3280
3314
  if (!children) {
3281
3315
  return [];
3282
3316
  }
3283
3317
  const dirents = [];
3284
- sortExplorerItems(children);
3318
+ children = sortExplorerItems(children);
3285
3319
  const visible = [];
3286
3320
  const displayRoot = path.endsWith(pathSeparator) ? path : path + pathSeparator;
3287
3321
  for (const child of children) {
@@ -3323,6 +3357,10 @@ const getSavedChildDirents = (map, path, depth, excluded, pathSeparator) => {
3323
3357
  }
3324
3358
  return dirents;
3325
3359
  };
3360
+
3361
+ const Fulfilled = 'fulfilled';
3362
+ const Rejected = 'rejected';
3363
+
3326
3364
  const createDirents = (root, expandedDirentPaths, expandedDirentChildren, excluded, pathSeparator) => {
3327
3365
  const dirents = [];
3328
3366
  const map = Object.create(null);
@@ -3578,6 +3616,13 @@ const renderEditingIndex = (oldState, newState) => {
3578
3616
  return ['focusInput', 'ExplorerInput'];
3579
3617
  };
3580
3618
 
3619
+ const renderFocus = (oldState, newState) => {
3620
+ // TODO
3621
+ // 1. when focused, focus the outer list element
3622
+ // 2. when focused, set focus context in renderer worker
3623
+ return [];
3624
+ };
3625
+
3581
3626
  const renderItems = (oldState, newState) => {
3582
3627
  const visibleDirents = getVisibleExplorerItems(newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex, newState.editingIndex, newState.editingType, newState.editingValue, newState.icons, newState.useChevrons);
3583
3628
  const isWide = newState.width > 450;
@@ -3591,6 +3636,8 @@ const getRenderer = diffType => {
3591
3636
  return renderEditingIndex;
3592
3637
  case RenderItems:
3593
3638
  return renderItems;
3639
+ case RenderFocus:
3640
+ return renderFocus;
3594
3641
  default:
3595
3642
  throw new Error('unknown renderer');
3596
3643
  }
@@ -3600,11 +3647,24 @@ const applyRender = (oldState, newState, diffResult) => {
3600
3647
  const commands = [];
3601
3648
  for (const item of diffResult) {
3602
3649
  const fn = getRenderer(item);
3603
- commands.push(fn(oldState, newState));
3650
+ const result = fn(oldState, newState);
3651
+ if (result.length > 0) {
3652
+ commands.push(result);
3653
+ }
3604
3654
  }
3605
3655
  return commands;
3606
3656
  };
3607
3657
 
3658
+ const render2 = (uid, diffResult) => {
3659
+ const {
3660
+ oldState,
3661
+ newState
3662
+ } = get(uid);
3663
+ set(uid, newState, newState);
3664
+ const commands = applyRender(oldState, newState, diffResult);
3665
+ return commands;
3666
+ };
3667
+
3608
3668
  const renderInternal = (oldState, newState) => {
3609
3669
  const diffResult = diff(oldState, newState);
3610
3670
  return applyRender(oldState, newState, diffResult);
@@ -3667,6 +3727,15 @@ const getActionsVirtualDom = actions => {
3667
3727
  }, ...actions.flatMap(getActionVirtualDom)];
3668
3728
  };
3669
3729
 
3730
+ const renderActions$1 = uid => {
3731
+ const {
3732
+ newState
3733
+ } = get(uid);
3734
+ const actions = getActions(newState.root);
3735
+ const dom = getActionsVirtualDom(actions);
3736
+ return dom;
3737
+ };
3738
+
3670
3739
  const renderActions = state => {
3671
3740
  const actions = getActions(state.root);
3672
3741
  const dom = getActionsVirtualDom(actions);
@@ -3675,13 +3744,13 @@ const renderActions = state => {
3675
3744
 
3676
3745
  const renderEventListeners = () => {
3677
3746
  return [{
3678
- name: HandleBlur,
3747
+ name: HandleListBlur,
3679
3748
  params: ['handleBlur']
3680
3749
  }, {
3681
- name: HandleFocus,
3750
+ name: HandleListFocus,
3682
3751
  params: ['handleFocus', 'event.isTrusted', 'event.target.className']
3683
3752
  }, {
3684
- name: HandleBlur,
3753
+ name: HandleListBlur,
3685
3754
  params: ['handleBlur']
3686
3755
  }, {
3687
3756
  name: HandleClick,
@@ -3700,7 +3769,8 @@ const renderEventListeners = () => {
3700
3769
  params: ['handleEditingInput', 'event.target.value']
3701
3770
  }, {
3702
3771
  name: HandleContextMenu,
3703
- params: ['handleContextMenu', 'event.button', 'event.clientX', 'event.clientY']
3772
+ params: ['handleContextMenu', 'event.button', 'event.clientX', 'event.clientY'],
3773
+ preventDefault: true
3704
3774
  }, {
3705
3775
  name: HandleWheel,
3706
3776
  params: ['handleWheel', 'event.deltaMode', 'event.deltaY'],
@@ -4068,10 +4138,14 @@ const commandMap = {
4068
4138
  'Explorer.updateIcons': wrapCommand(updateIcons),
4069
4139
  // not wrapped
4070
4140
  'Explorer.create': create,
4071
- 'Explorer.render': doRender,
4072
- 'Explorer.renderActions': renderActions,
4073
- 'Explorer.saveState': saveState,
4141
+ 'Explorer.diff2': diff2,
4142
+ 'Explorer.render2': render2,
4143
+ 'Explorer.renderActions2': renderActions$1,
4074
4144
  'Explorer.renderEventListeners': renderEventListeners,
4145
+ 'Explorer.saveState': saveState,
4146
+ // deprecated
4147
+ 'Explorer.renderActions': renderActions,
4148
+ 'Explorer.render': doRender,
4075
4149
  'Explorer.diff': diff
4076
4150
  };
4077
4151
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "1.27.0",
3
+ "version": "1.28.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",