@lvce-editor/explorer-view 1.20.0 → 1.21.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.
@@ -779,12 +779,12 @@ const invokeAndTransfer = (ipc, method, ...params) => {
779
779
  return invokeHelper(ipc, method, params, true);
780
780
  };
781
781
 
782
- const commands = Object.create(null);
782
+ const commands$1 = Object.create(null);
783
783
  const register = commandMap => {
784
- Object.assign(commands, commandMap);
784
+ Object.assign(commands$1, commandMap);
785
785
  };
786
786
  const getCommand = key => {
787
- return commands[key];
787
+ return commands$1[key];
788
788
  };
789
789
  const execute = (command, ...args) => {
790
790
  const fn = getCommand(command);
@@ -1100,9 +1100,7 @@ const acceptCreate = async (state, newDirentType, createFn) => {
1100
1100
  return state;
1101
1101
  }
1102
1102
  const parentDirent = focusedIndex >= 0 ? state.items[focusedIndex] : {
1103
- depth: 0,
1104
- path: state.root
1105
- };
1103
+ depth: 0};
1106
1104
  const depth = parentDirent.depth + 1;
1107
1105
  const newDirent = {
1108
1106
  path: absolutePath,
@@ -1853,6 +1851,11 @@ const getActions = root => {
1853
1851
  }];
1854
1852
  };
1855
1853
 
1854
+ const commands = ['acceptEdit', 'cancelEdit', 'collapseAll', 'copyPath', 'copyRelativePath', 'expandAll', 'expandRecursively', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusNone', 'focusPrevious', 'getFocusedDirent', 'handleArrowLeft', 'handleArrowLeft', 'handleArrowRight', 'handleArrowRight', 'handleBlur', 'handleClick', 'handleClickAt', 'handleClickCurrent', 'handleClickCurrentButKeepFocus', 'handleClickOpenFolder', 'handleContextMenu', 'handleCopy', 'handleDragOver', 'handleDrop', 'handleFocus', 'handleIconThemeChange', 'handleLanguagesChanged', 'handleMouseEnter', 'handleMouseLeave', 'handlePaste', 'handlePointerDown', 'handleUpload', 'handleWheel', 'handleWorkspaceChange', 'hotReload', 'newFile', 'newFolder', 'openContainingFolder', 'refresh', 'refresh', 'relealItem', 'removeDirent', 'rename', 'renameDirent', 'revealItem', 'scrollDown', 'scrollUp', 'setDeltaY', 'updateEditingValue', 'updateIcons'];
1855
+ const getCommandIds = () => {
1856
+ return commands;
1857
+ };
1858
+
1856
1859
  const None$4 = 'none';
1857
1860
  const ToolBar = 'toolbar';
1858
1861
  const Tree = 'tree';
@@ -2355,19 +2358,59 @@ const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editin
2355
2358
  return visible;
2356
2359
  };
2357
2360
 
2358
- const handleBlur = state => {
2359
- // TODO when blur event occurs because of context menu, focused index should stay the same
2360
- // but focus outline should be removed
2361
+ const getParentStartIndex = (dirents, index) => {
2362
+ const dirent = dirents[index];
2363
+ let startIndex = index - 1;
2364
+ while (startIndex >= 0 && dirents[startIndex].depth >= dirent.depth) {
2365
+ startIndex--;
2366
+ }
2367
+ return startIndex;
2368
+ };
2369
+
2370
+ const focusParentFolder = state => {
2371
+ const parentStartIndex = getParentStartIndex(state.items, state.focusedIndex);
2372
+ if (parentStartIndex === -1) {
2373
+ return state;
2374
+ }
2375
+ return focusIndex(state, parentStartIndex);
2376
+ };
2377
+
2378
+ const handleArrowLeft = state => {
2361
2379
  const {
2362
- editingType
2380
+ items,
2381
+ focusedIndex
2363
2382
  } = state;
2364
- if (editingType !== None$5) {
2383
+ if (focusedIndex === -1) {
2365
2384
  return state;
2366
2385
  }
2367
- return {
2368
- ...state,
2369
- focused: false
2370
- };
2386
+ const dirent = items[focusedIndex];
2387
+ switch (dirent.type) {
2388
+ case Directory:
2389
+ case File:
2390
+ case SymLinkFile:
2391
+ return focusParentFolder(state);
2392
+ case DirectoryExpanded:
2393
+ // @ts-ignore
2394
+ return handleClickDirectoryExpanded(state, dirent, focusedIndex);
2395
+ default:
2396
+ // TODO handle expanding directory and cancel file system call to read child dirents
2397
+ return state;
2398
+ }
2399
+ };
2400
+
2401
+ const handleArrowRightDirectoryExpanded = (state, dirent) => {
2402
+ const {
2403
+ items,
2404
+ focusedIndex
2405
+ } = state;
2406
+ if (focusedIndex === items.length - 1) {
2407
+ return state;
2408
+ }
2409
+ const nextDirent = items[focusedIndex + 1];
2410
+ if (nextDirent.depth === dirent.depth + 1) {
2411
+ return focusIndex(state, focusedIndex + 1);
2412
+ }
2413
+ return state;
2371
2414
  };
2372
2415
 
2373
2416
  const handleClickDirectory = async (state, dirent, index, keepFocus) => {
@@ -2414,6 +2457,71 @@ const handleClickDirectory = async (state, dirent, index, keepFocus) => {
2414
2457
  };
2415
2458
  };
2416
2459
 
2460
+ const openUri = async (uri, focus) => {
2461
+ await invoke(/* Main.openAbsolutePath */'Main.openUri', /* absolutePath */uri, /* focus */focus);
2462
+ };
2463
+
2464
+ const handleClickFile = async (state, dirent, index, keepFocus = false) => {
2465
+ await openUri(dirent.path, !keepFocus);
2466
+ return {
2467
+ ...state,
2468
+ focusedIndex: index,
2469
+ focused: keepFocus
2470
+ };
2471
+ };
2472
+
2473
+ const handleClickSymLink = async (state, dirent, index) => {
2474
+ const realPath = await getRealPath(dirent.path);
2475
+ const type = await stat(realPath);
2476
+ switch (type) {
2477
+ case File:
2478
+ return handleClickFile(state, dirent, index);
2479
+ default:
2480
+ throw new Error(`unsupported file type ${type}`);
2481
+ }
2482
+ };
2483
+
2484
+ const handleArrowRight = async state => {
2485
+ const {
2486
+ items,
2487
+ focusedIndex
2488
+ } = state;
2489
+ if (focusedIndex === -1) {
2490
+ return state;
2491
+ }
2492
+ const dirent = items[focusedIndex];
2493
+ switch (dirent.type) {
2494
+ case File:
2495
+ case SymLinkFile:
2496
+ return state;
2497
+ case Directory:
2498
+ case SymLinkFolder:
2499
+ // @ts-ignore
2500
+ return handleClickDirectory(state, dirent);
2501
+ case DirectoryExpanded:
2502
+ return handleArrowRightDirectoryExpanded(state, dirent);
2503
+ case Symlink:
2504
+ return handleClickSymLink(state, dirent, focusedIndex);
2505
+ default:
2506
+ throw new Error(`unsupported file type ${dirent.type}`);
2507
+ }
2508
+ };
2509
+
2510
+ const handleBlur = state => {
2511
+ // TODO when blur event occurs because of context menu, focused index should stay the same
2512
+ // but focus outline should be removed
2513
+ const {
2514
+ editingType
2515
+ } = state;
2516
+ if (editingType !== None$5) {
2517
+ return state;
2518
+ }
2519
+ return {
2520
+ ...state,
2521
+ focused: false
2522
+ };
2523
+ };
2524
+
2417
2525
  const handleClickDirectoryExpanded$1 = async (state, dirent, index, keepFocus) => {
2418
2526
  const {
2419
2527
  minLineY,
@@ -2480,30 +2588,6 @@ const handleClickDirectoryExpanding = async (state, dirent, index, keepFocus) =>
2480
2588
  };
2481
2589
  };
2482
2590
 
2483
- const openUri = async (uri, focus) => {
2484
- await invoke(/* Main.openAbsolutePath */'Main.openUri', /* absolutePath */uri, /* focus */focus);
2485
- };
2486
-
2487
- const handleClickFile$1 = async (state, dirent, index, keepFocus = false) => {
2488
- await openUri(dirent.path, !keepFocus);
2489
- return {
2490
- ...state,
2491
- focusedIndex: index,
2492
- focused: keepFocus
2493
- };
2494
- };
2495
-
2496
- const handleClickSymLink$1 = async (state, dirent, index) => {
2497
- const realPath = await getRealPath(dirent.path);
2498
- const type = await stat(realPath);
2499
- switch (type) {
2500
- case File:
2501
- return handleClickFile$1(state, dirent, index);
2502
- default:
2503
- throw new Error(`unsupported file type ${type}`);
2504
- }
2505
- };
2506
-
2507
2591
  // TODO viewlet should only have create and refresh functions
2508
2592
  // every thing else can be in a separate module <viewlet>.lazy.js
2509
2593
  // and <viewlet>.ipc.js
@@ -2525,7 +2609,7 @@ const getClickFn = direntType => {
2525
2609
  switch (direntType) {
2526
2610
  case File:
2527
2611
  case SymLinkFile:
2528
- return handleClickFile$1;
2612
+ return handleClickFile;
2529
2613
  case Directory:
2530
2614
  case SymLinkFolder:
2531
2615
  return handleClickDirectory;
@@ -2534,7 +2618,7 @@ const getClickFn = direntType => {
2534
2618
  case DirectoryExpanded:
2535
2619
  return handleClickDirectoryExpanded$1;
2536
2620
  case Symlink:
2537
- return handleClickSymLink$1;
2621
+ return handleClickSymLink;
2538
2622
  case CharacterDevice:
2539
2623
  throw new Error('Cannot open character device files');
2540
2624
  case BlockDevice:
@@ -2546,34 +2630,6 @@ const getClickFn = direntType => {
2546
2630
  }
2547
2631
  };
2548
2632
 
2549
- const getIndexFromPosition = (state, eventX, eventY) => {
2550
- const {
2551
- y,
2552
- itemHeight,
2553
- items
2554
- } = state;
2555
- const index = Math.floor((eventY - y) / itemHeight);
2556
- if (index < 0) {
2557
- return 0;
2558
- }
2559
- if (index >= items.length) {
2560
- return -1;
2561
- }
2562
- return index;
2563
- };
2564
-
2565
- const getParentStartIndex = (dirents, index) => {
2566
- const dirent = dirents[index];
2567
- let startIndex = index - 1;
2568
- while (startIndex >= 0 && dirents[startIndex].depth >= dirent.depth) {
2569
- startIndex--;
2570
- }
2571
- return startIndex;
2572
- };
2573
-
2574
- const Keyboard = -1;
2575
- const LeftClick = 0;
2576
-
2577
2633
  // TODO viewlet should only have create and refresh functions
2578
2634
  // every thing else can be in a separate module <viewlet>.lazy.js
2579
2635
  // and <viewlet>.ipc.js
@@ -2584,81 +2640,11 @@ const LeftClick = 0;
2584
2640
  // TODO instead of root string, there should be a root dirent
2585
2641
 
2586
2642
  // TODO rename dirents to items, then can use virtual list component directly
2587
- const setDeltaY$1 = (state, deltaY) => {
2588
- const {
2589
- itemHeight,
2590
- height,
2591
- items
2592
- } = state;
2593
- if (deltaY < 0) {
2594
- deltaY = 0;
2595
- } else if (deltaY > items.length * itemHeight - height) {
2596
- deltaY = Math.max(items.length * itemHeight - height, 0);
2597
- }
2598
- if (state.deltaY === deltaY) {
2599
- return state;
2600
- }
2601
- const minLineY = Math.round(deltaY / itemHeight);
2602
- const maxLineY = minLineY + Math.round(height / itemHeight);
2603
- return {
2604
- ...state,
2605
- deltaY,
2606
- minLineY,
2607
- maxLineY
2608
- };
2609
- };
2610
- const handleWheel = (state, deltaMode, deltaY) => {
2611
- return setDeltaY$1(state, state.deltaY + deltaY);
2612
- };
2613
2643
 
2614
2644
  // TODO use posInSet and setSize properties to compute more effectively
2615
2645
 
2616
2646
  // TODO much shared logic with newFolder
2617
2647
 
2618
- const handleClickFile = async (state, dirent, index, keepFocus = false) => {
2619
- // await Command.execute(/* Main.openAbsolutePath */ 'Main.openUri', /* absolutePath */ dirent.path, /* focus */ !keepFocus)
2620
- return {
2621
- ...state,
2622
- focusedIndex: index,
2623
- focused: keepFocus
2624
- };
2625
- };
2626
- const handleClickDirectoryExpanded = (state, dirent, index, keepFocus) => {
2627
- const {
2628
- minLineY,
2629
- maxLineY,
2630
- itemHeight
2631
- } = state;
2632
- dirent.type = Directory;
2633
- dirent.icon = getIcon();
2634
- const endIndex = getParentEndIndex(state.items, index);
2635
- const removeCount = endIndex - index - 1;
2636
- // TODO race conditions and side effects are everywhere
2637
- const newDirents = [...state.items];
2638
- newDirents.splice(index + 1, removeCount);
2639
- const newTotal = newDirents.length;
2640
- if (newTotal < maxLineY) {
2641
- const visibleItems = Math.min(maxLineY - minLineY, newTotal);
2642
- const newMaxLineY = Math.min(maxLineY, newTotal);
2643
- const newMinLineY = newMaxLineY - visibleItems;
2644
- const deltaY = newMinLineY * itemHeight;
2645
- return {
2646
- ...state,
2647
- items: newDirents,
2648
- focusedIndex: index,
2649
- focused: keepFocus,
2650
- minLineY: newMinLineY,
2651
- maxLineY: newMaxLineY,
2652
- deltaY
2653
- };
2654
- }
2655
- return {
2656
- ...state,
2657
- items: newDirents,
2658
- focusedIndex: index,
2659
- focused: keepFocus
2660
- };
2661
- };
2662
2648
  const handleClick = async (state, index, keepFocus = false) => {
2663
2649
  const {
2664
2650
  items,
@@ -2676,102 +2662,44 @@ const handleClick = async (state, index, keepFocus = false) => {
2676
2662
  const clickFn = getClickFn(dirent.type);
2677
2663
  return clickFn(state, dirent, actualIndex, keepFocus);
2678
2664
  };
2679
- const handleClickAt = (state, button, x, y) => {
2680
- if (button !== LeftClick) {
2681
- return state;
2682
- }
2683
- const index = getIndexFromPosition(state, x, y);
2684
- return handleClick(state, index);
2685
- };
2686
- const handleClickCurrentButKeepFocus = state => {
2687
- return handleClick(state, state.focusedIndex - state.minLineY, /* keepFocus */true);
2688
- };
2689
2665
 
2690
2666
  // export const handleBlur=()=>{}
2691
2667
 
2692
- const handleClickSymLink = async (state, dirent, index) => {
2693
- const realPath = await getRealPath(dirent.path);
2694
- const type = await stat(realPath);
2695
- switch (type) {
2696
- case File:
2697
- return handleClickFile(state, dirent, index);
2698
- default:
2699
- throw new Error(`unsupported file type ${type}`);
2700
- }
2701
- };
2702
- const handleArrowRightDirectoryExpanded = (state, dirent) => {
2703
- const {
2704
- items,
2705
- focusedIndex
2706
- } = state;
2707
- if (focusedIndex === items.length - 1) {
2708
- return state;
2709
- }
2710
- const nextDirent = items[focusedIndex + 1];
2711
- if (nextDirent.depth === dirent.depth + 1) {
2712
- return focusIndex(state, focusedIndex + 1);
2713
- }
2714
- return state;
2715
- };
2716
- const handleArrowRight = async state => {
2668
+ // TODO what happens when mouse leave and anther mouse enter event occur?
2669
+ // should update preview instead of closing and reopening
2670
+
2671
+ // TODO maybe just insert items into explorer and refresh whole explorer
2672
+
2673
+ const getIndexFromPosition = (state, eventX, eventY) => {
2717
2674
  const {
2718
- items,
2719
- focusedIndex
2675
+ y,
2676
+ itemHeight,
2677
+ items
2720
2678
  } = state;
2721
- if (focusedIndex === -1) {
2722
- return state;
2723
- }
2724
- const dirent = items[focusedIndex];
2725
- switch (dirent.type) {
2726
- case File:
2727
- case SymLinkFile:
2728
- return state;
2729
- case Directory:
2730
- case SymLinkFolder:
2731
- // @ts-ignore
2732
- return handleClickDirectory(state, dirent);
2733
- case DirectoryExpanded:
2734
- return handleArrowRightDirectoryExpanded(state, dirent);
2735
- case Symlink:
2736
- return handleClickSymLink(state, dirent, focusedIndex);
2737
- default:
2738
- throw new Error(`unsupported file type ${dirent.type}`);
2679
+ const index = Math.floor((eventY - y) / itemHeight);
2680
+ if (index < 0) {
2681
+ return 0;
2739
2682
  }
2740
- };
2741
- const focusParentFolder = state => {
2742
- const parentStartIndex = getParentStartIndex(state.items, state.focusedIndex);
2743
- if (parentStartIndex === -1) {
2744
- return state;
2683
+ if (index >= items.length) {
2684
+ return -1;
2745
2685
  }
2746
- return focusIndex(state, parentStartIndex);
2686
+ return index;
2747
2687
  };
2748
- const handleArrowLeft = state => {
2749
- const {
2750
- items,
2751
- focusedIndex
2752
- } = state;
2753
- if (focusedIndex === -1) {
2688
+
2689
+ const Keyboard = -1;
2690
+ const LeftClick = 0;
2691
+
2692
+ const handleClickAt = (state, button, x, y) => {
2693
+ if (button !== LeftClick) {
2754
2694
  return state;
2755
2695
  }
2756
- const dirent = items[focusedIndex];
2757
- switch (dirent.type) {
2758
- case Directory:
2759
- case File:
2760
- case SymLinkFile:
2761
- return focusParentFolder(state);
2762
- case DirectoryExpanded:
2763
- // @ts-ignore
2764
- return handleClickDirectoryExpanded(state, dirent, focusedIndex);
2765
- default:
2766
- // TODO handle expanding directory and cancel file system call to read child dirents
2767
- return state;
2768
- }
2696
+ const index = getIndexFromPosition(state, x, y);
2697
+ return handleClick(state, index);
2769
2698
  };
2770
2699
 
2771
- // TODO what happens when mouse leave and anther mouse enter event occur?
2772
- // should update preview instead of closing and reopening
2773
-
2774
- // TODO maybe just insert items into explorer and refresh whole explorer
2700
+ const handleClickCurrentButKeepFocus = state => {
2701
+ return handleClick(state, state.focusedIndex - state.minLineY, /* keepFocus */true);
2702
+ };
2775
2703
 
2776
2704
  const openFolder = async () => {
2777
2705
  // TODO
@@ -3239,6 +3167,34 @@ const handleUpload = async (state, dirents) => {
3239
3167
  }
3240
3168
  };
3241
3169
 
3170
+ const setDeltaY = (state, deltaY) => {
3171
+ const {
3172
+ itemHeight,
3173
+ height,
3174
+ items
3175
+ } = state;
3176
+ if (deltaY < 0) {
3177
+ deltaY = 0;
3178
+ } else if (deltaY > items.length * itemHeight - height) {
3179
+ deltaY = Math.max(items.length * itemHeight - height, 0);
3180
+ }
3181
+ if (state.deltaY === deltaY) {
3182
+ return state;
3183
+ }
3184
+ const minLineY = Math.round(deltaY / itemHeight);
3185
+ const maxLineY = minLineY + Math.round(height / itemHeight);
3186
+ return {
3187
+ ...state,
3188
+ deltaY,
3189
+ minLineY,
3190
+ maxLineY
3191
+ };
3192
+ };
3193
+
3194
+ const handleWheel = (state, deltaMode, deltaY) => {
3195
+ return setDeltaY(state, state.deltaY + deltaY);
3196
+ };
3197
+
3242
3198
  const getWorkspacePath = () => {
3243
3199
  return invoke('Workspace.getPath');
3244
3200
  };
@@ -3471,9 +3427,7 @@ const openContainingFolder = async state => {
3471
3427
  const {
3472
3428
  focusedIndex,
3473
3429
  root,
3474
- items,
3475
- pathSeparator
3476
- } = state;
3430
+ items} = state;
3477
3431
  const path = getContaingingFolder(root, items, focusedIndex);
3478
3432
  await invoke('OpenNativeFolder.openNativeFolder', /* path */path);
3479
3433
  return state;
@@ -3957,30 +3911,6 @@ const saveState = uid => {
3957
3911
  };
3958
3912
  };
3959
3913
 
3960
- const setDeltaY = (state, deltaY) => {
3961
- const {
3962
- itemHeight,
3963
- height,
3964
- items
3965
- } = state;
3966
- if (deltaY < 0) {
3967
- deltaY = 0;
3968
- } else if (deltaY > items.length * itemHeight - height) {
3969
- deltaY = Math.max(items.length * itemHeight - height, 0);
3970
- }
3971
- if (state.deltaY === deltaY) {
3972
- return state;
3973
- }
3974
- const minLineY = Math.round(deltaY / itemHeight);
3975
- const maxLineY = minLineY + Math.round(height / itemHeight);
3976
- return {
3977
- ...state,
3978
- deltaY,
3979
- minLineY,
3980
- maxLineY
3981
- };
3982
- };
3983
-
3984
3914
  const terminate = () => {
3985
3915
  globalThis.close();
3986
3916
  };
@@ -4030,6 +3960,7 @@ const commandMap = {
4030
3960
  'Explorer.getKeyBindings': wrapCommand(getKeyBindings),
4031
3961
  'Explorer.getMenuEntries': wrapCommand(getMenuEntries),
4032
3962
  'Explorer.getVirtualDom': wrapCommand(getExplorerVirtualDom),
3963
+ 'Explorer.getCommandIds': getCommandIds,
4033
3964
  'Explorer.getVisibleItems': wrapCommand(getVisibleExplorerItems),
4034
3965
  'Explorer.handleArrowLeft': wrapCommand(handleArrowLeft),
4035
3966
  'Explorer.handleArrowRight': wrapCommand(handleArrowRight),
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "1.20.0",
3
+ "version": "1.21.0",
4
4
  "description": "Explorer Worker",
5
- "keywords": [],
6
5
  "repository": {
7
6
  "type": "git",
8
7
  "url": "git+https://github.com/lvce-editor/explorer-view.git"