@lvce-editor/explorer-view 2.27.0 → 2.29.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.
@@ -467,7 +467,7 @@ const registerPromise = () => {
467
467
  promise
468
468
  };
469
469
  };
470
- const create$2 = (method, params) => {
470
+ const create$2$1 = (method, params) => {
471
471
  const {
472
472
  id,
473
473
  promise
@@ -759,7 +759,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
759
759
  const {
760
760
  message,
761
761
  promise
762
- } = create$2(method, params);
762
+ } = create$2$1(method, params);
763
763
  if (useSendAndTransfer && ipc.sendAndTransfer) {
764
764
  ipc.sendAndTransfer(message);
765
765
  } else {
@@ -846,7 +846,7 @@ const listen$1 = async (module, options) => {
846
846
  const ipc = module.wrap(rawIpc);
847
847
  return ipc;
848
848
  };
849
- const create$1 = async ({
849
+ const create$2 = async ({
850
850
  commandMap
851
851
  }) => {
852
852
  // TODO create a commandMap per rpc instance
@@ -858,7 +858,7 @@ const create$1 = async ({
858
858
  };
859
859
  const WebWorkerRpcClient = {
860
860
  __proto__: null,
861
- create: create$1
861
+ create: create$2
862
862
  };
863
863
 
864
864
  const None$5 = 0;
@@ -1474,6 +1474,13 @@ const cancelEdit = state => {
1474
1474
  };
1475
1475
  };
1476
1476
 
1477
+ const cancelTypeAhead = state => {
1478
+ return {
1479
+ ...state,
1480
+ focusWord: ''
1481
+ };
1482
+ };
1483
+
1477
1484
  const isTopLevel$1 = dirent => {
1478
1485
  return dirent.depth === 1;
1479
1486
  };
@@ -1539,17 +1546,71 @@ const copyRelativePath = async state => {
1539
1546
  return state;
1540
1547
  };
1541
1548
 
1542
- const states = Object.create(null);
1543
- const get = uid => {
1544
- return states[uid];
1545
- };
1546
- const set = (uid, oldState, newState) => {
1547
- states[uid] = {
1548
- oldState,
1549
- newState
1549
+ const create$1 = () => {
1550
+ const states = Object.create(null);
1551
+ return {
1552
+ get(uid) {
1553
+ return states[uid];
1554
+ },
1555
+ set(uid, oldState, newState) {
1556
+ states[uid] = {
1557
+ oldState,
1558
+ newState
1559
+ };
1560
+ },
1561
+ dispose(uid) {
1562
+ delete states[uid];
1563
+ },
1564
+ getKeys() {
1565
+ return Object.keys(states).map(key => {
1566
+ return Number.parseInt(key);
1567
+ });
1568
+ },
1569
+ clear() {
1570
+ for (const key of Object.keys(states)) {
1571
+ delete states[key];
1572
+ }
1573
+ },
1574
+ wrapCommand(fn) {
1575
+ const wrapped = async (uid, ...args) => {
1576
+ const {
1577
+ newState
1578
+ } = states[uid];
1579
+ const newerState = await fn(newState, ...args);
1580
+ if (newState === newerState) {
1581
+ return;
1582
+ }
1583
+ const latest = states[uid];
1584
+ states[uid] = {
1585
+ oldState: latest.oldState,
1586
+ newState: newerState
1587
+ };
1588
+ };
1589
+ return wrapped;
1590
+ },
1591
+ diff(uid, modules, numbers) {
1592
+ const {
1593
+ oldState,
1594
+ newState
1595
+ } = states[uid];
1596
+ const diffResult = [];
1597
+ for (let i = 0; i < modules.length; i++) {
1598
+ const fn = modules[i];
1599
+ if (!fn(oldState, newState)) {
1600
+ diffResult.push(numbers[i]);
1601
+ }
1602
+ }
1603
+ return diffResult;
1604
+ }
1550
1605
  };
1551
1606
  };
1552
1607
 
1608
+ const {
1609
+ get,
1610
+ set,
1611
+ wrapCommand
1612
+ } = create$1();
1613
+
1553
1614
  const ListItem = 22;
1554
1615
 
1555
1616
  const Slash = '/';
@@ -1590,7 +1651,9 @@ const create2 = (uid, uri, x, y, width, height, args, parentUid, platform = 0) =
1590
1651
  editingSelection: {
1591
1652
  start: 0,
1592
1653
  end: 0
1593
- }
1654
+ },
1655
+ focusWord: '',
1656
+ focusWordTimeout: 800
1594
1657
  };
1595
1658
  set(uid, state, state);
1596
1659
  };
@@ -1631,7 +1694,9 @@ const create = (id, uri, x, y, width, height, args, parentUid, platform = 0) =>
1631
1694
  editingSelection: {
1632
1695
  start: 0,
1633
1696
  end: 0
1634
- }
1697
+ },
1698
+ focusWord: '',
1699
+ focusWordTimeout: 800
1635
1700
  };
1636
1701
  set(state.uid, state, state);
1637
1702
  return state;
@@ -1959,7 +2024,7 @@ const focusIndex = (state, index) => {
1959
2024
  } = state;
1960
2025
  const newItems = items.map((item, i) => ({
1961
2026
  ...item,
1962
- selected: i === index ? true : false
2027
+ selected: i === index ? false : false
1963
2028
  }));
1964
2029
  if (index < minLineY) {
1965
2030
  if (index < 0) {
@@ -2072,7 +2137,7 @@ const focusPrevious = state => {
2072
2137
  }
2073
2138
  };
2074
2139
 
2075
- const commandIds = ['acceptEdit', 'cancelEdit', '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', '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'];
2140
+ const commandIds = ['acceptEdit', 'cancelEdit', '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', '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'];
2076
2141
 
2077
2142
  const getCommandIds = () => {
2078
2143
  return commandIds;
@@ -3295,6 +3360,73 @@ const handleInputClick = state => {
3295
3360
  return state;
3296
3361
  };
3297
3362
 
3363
+ const filterByFocusWord = (items, focusedIndex, focusWord) => {
3364
+ if (items.length === 0) {
3365
+ return -1;
3366
+ }
3367
+ const matches = [];
3368
+ for (let i = 0; i < items.length; i++) {
3369
+ if (items[i].toLowerCase().includes(focusWord)) {
3370
+ matches.push(i);
3371
+ }
3372
+ }
3373
+ if (matches.length === 0) {
3374
+ return -1;
3375
+ }
3376
+
3377
+ // Find the next match after the current focus
3378
+ let nextIndex = matches.findIndex(index => index > focusedIndex);
3379
+ if (nextIndex === -1) {
3380
+ // If no match found after current focus, wrap around to the first match
3381
+ nextIndex = 0;
3382
+ }
3383
+ return matches[nextIndex];
3384
+ };
3385
+
3386
+ const RE_ASCII = /^[a-z]$/;
3387
+ const isAscii = key => {
3388
+ return RE_ASCII.test(key);
3389
+ };
3390
+
3391
+ let timeout;
3392
+ const handleKeyDown = (state, key) => {
3393
+ const {
3394
+ focusWord,
3395
+ items,
3396
+ focusedIndex,
3397
+ focusWordTimeout
3398
+ } = state;
3399
+ if (focusWord && key === '') {
3400
+ return cancelTypeAhead(state);
3401
+ }
3402
+ if (!isAscii(key)) {
3403
+ return state;
3404
+ }
3405
+ const newFocusWord = focusWord + key.toLowerCase();
3406
+ const itemNames = items.map(item => item.name);
3407
+ const matchingIndex = filterByFocusWord(itemNames, focusedIndex, newFocusWord);
3408
+ if (timeout) {
3409
+ clearTimeout(timeout);
3410
+ }
3411
+
3412
+ // @ts-ignore
3413
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
3414
+ timeout = setTimeout(async () => {
3415
+ await invoke('Explorer.cancelTypeAhead');
3416
+ }, focusWordTimeout);
3417
+ if (matchingIndex === -1) {
3418
+ return {
3419
+ ...state,
3420
+ focusWord: newFocusWord
3421
+ };
3422
+ }
3423
+ return {
3424
+ ...state,
3425
+ focusWord: newFocusWord,
3426
+ focusedIndex: matchingIndex
3427
+ };
3428
+ };
3429
+
3298
3430
  // TODO add lots of tests for this
3299
3431
  const updateRoot = async state1 => {
3300
3432
  // @ts-ignore
@@ -3990,6 +4122,7 @@ const HandleInputBlur = 'handleInputBlur';
3990
4122
  const HandleInputClick = 'handleInputClick';
3991
4123
  const HandleListBlur = 'handleListBlur';
3992
4124
  const HandleListFocus = 'handleListFocus';
4125
+ const HandleListKeyDown = 'handleListKeyDown';
3993
4126
  const HandlePointerDown = 'handlePointerDown';
3994
4127
  const HandleWheel = 'handleWheel';
3995
4128
 
@@ -4174,7 +4307,8 @@ const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused
4174
4307
  onDrop: HandleDrop,
4175
4308
  onFocus: HandleListFocus,
4176
4309
  onPointerDown: HandlePointerDown,
4177
- onWheel: HandleWheel
4310
+ onWheel: HandleWheel,
4311
+ onKeyDown: HandleListKeyDown
4178
4312
  }, ...visibleItems.flatMap(getExplorerItemVirtualDom)];
4179
4313
  return dom;
4180
4314
  };
@@ -4440,6 +4574,10 @@ const renderEventListeners = () => {
4440
4574
  return [{
4441
4575
  name: HandleInputBlur,
4442
4576
  params: ['handleInputBlur']
4577
+ }, {
4578
+ name: HandleListKeyDown,
4579
+ params: ['handleKeyDown', 'event.key'],
4580
+ preventDefault: true
4443
4581
  }, {
4444
4582
  name: HandleListFocus,
4445
4583
  params: ['handleFocus', 'event.isTrusted', 'event.target.className']
@@ -4838,23 +4976,10 @@ const updateEditingValue = async (state, value, inputSource = User) => {
4838
4976
  };
4839
4977
  };
4840
4978
 
4841
- const wrapCommand = fn => {
4842
- const wrapped = async (uid, ...args) => {
4843
- const {
4844
- newState
4845
- } = get(uid);
4846
- const newerState = await fn(newState, ...args);
4847
- if (newState === newerState) {
4848
- return;
4849
- }
4850
- const latest = get(uid);
4851
- set(uid, latest.oldState, newerState);
4852
- };
4853
- return wrapped;
4854
- };
4855
-
4856
4979
  const commandMap = {
4857
4980
  'Explorer.acceptEdit': wrapCommand(acceptEdit),
4981
+ 'Explorer.handleKeyDown': wrapCommand(handleKeyDown),
4982
+ 'Explorer.cancelTypeAhead': wrapCommand(cancelTypeAhead),
4858
4983
  'Explorer.cancelEdit': wrapCommand(cancelEdit),
4859
4984
  'Explorer.collapseAll': wrapCommand(collapseAll),
4860
4985
  'Explorer.copyPath': wrapCommand(copyPath),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.27.0",
3
+ "version": "2.29.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",