@lvce-editor/explorer-view 2.5.0 → 2.7.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.
@@ -1317,7 +1317,8 @@ const create2 = (uid, uri, x, y, width, height, args, parentUid, platform = 0) =
1317
1317
  fileIconCache: Object.create(null),
1318
1318
  useChevrons: false,
1319
1319
  icons: [],
1320
- platform
1320
+ platform,
1321
+ focus: 0
1321
1322
  };
1322
1323
  set(uid, state, state);
1323
1324
  };
@@ -1351,7 +1352,8 @@ const create = (id, uri, x, y, width, height, args, parentUid, platform = 0) =>
1351
1352
  fileIconCache: Object.create(null),
1352
1353
  useChevrons: false,
1353
1354
  icons: [],
1354
- platform
1355
+ platform,
1356
+ focus: 0
1355
1357
  };
1356
1358
  set(state.uid, state, state);
1357
1359
  return state;
@@ -1845,7 +1847,7 @@ const focusPrevious = state => {
1845
1847
  }
1846
1848
  };
1847
1849
 
1848
- const commandIds = ['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', 'revealItem', 'removeDirent', 'rename', 'renameDirent', 'revealItem', 'scrollDown', 'scrollUp', 'setDeltaY', 'renderEventListeners', 'updateEditingValue', 'updateIcons'];
1850
+ const commandIds = ['getMenuEntries2', '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', 'handleContextMenuKeyboard', 'handleCopy', 'handleDragLeave', 'handleDragOver', 'handleDrop', 'handleFocus', 'handleIconThemeChange', 'handleLanguagesChanged', 'handleMouseEnter', 'handleMouseLeave', 'handlePaste', 'handlePointerDown', 'handleUpload', 'handleWheel', 'handleWorkspaceChange', 'hotReload', 'newFile', 'newFolder', 'openContainingFolder', 'refresh', 'refresh', 'removeDirent', 'rename', 'renameDirent', 'renderEventListeners', 'revealItem', 'revealItem', 'scrollDown', 'scrollUp', 'setDeltaY', 'updateEditingValue', 'updateIcons'];
1849
1851
 
1850
1852
  const getCommandIds = () => {
1851
1853
  return commandIds;
@@ -2141,6 +2143,13 @@ const getMenuEntries = state => {
2141
2143
  }
2142
2144
  };
2143
2145
 
2146
+ const getMenuEntries2 = uid => {
2147
+ const {
2148
+ newState
2149
+ } = get(uid);
2150
+ return getMenuEntries(newState);
2151
+ };
2152
+
2144
2153
  const getParentStartIndex = (dirents, index) => {
2145
2154
  const dirent = dirents[index];
2146
2155
  let startIndex = index - 1;
@@ -2249,6 +2258,10 @@ const handleArrowRightDirectoryExpanded = (state, dirent) => {
2249
2258
  return state;
2250
2259
  };
2251
2260
 
2261
+ const setFocus = key => {
2262
+ return invoke('Focus.setFocus', key);
2263
+ };
2264
+
2252
2265
  const handleClickDirectory = async (state, dirent, index, keepFocus) => {
2253
2266
  // @ts-ignore
2254
2267
  dirent.type = DirectoryExpanding;
@@ -2282,6 +2295,7 @@ const handleClickDirectory = async (state, dirent, index, keepFocus) => {
2282
2295
  icons,
2283
2296
  newFileIconCache
2284
2297
  } = await getFileIcons(parts, state.fileIconCache);
2298
+ await setFocus(FocusExplorer);
2285
2299
  return {
2286
2300
  ...state,
2287
2301
  items: newDirents,
@@ -2486,6 +2500,10 @@ const handleClickAt = (state, button, x, y) => {
2486
2500
  return handleClick(state, index);
2487
2501
  };
2488
2502
 
2503
+ const handleClickCurrent = state => {
2504
+ return handleClick(state, state.focusedIndex - state.minLineY, /* keepFocus */false);
2505
+ };
2506
+
2489
2507
  const handleClickCurrentButKeepFocus = state => {
2490
2508
  return handleClick(state, state.focusedIndex - state.minLineY, /* keepFocus */true);
2491
2509
  };
@@ -2561,6 +2579,18 @@ const handleCopy = async state => {
2561
2579
  return state;
2562
2580
  };
2563
2581
 
2582
+ const handleDragLeave = state => {
2583
+ return state;
2584
+ // const { dropTargets } = state
2585
+ // if (dropTargets.length === 0) {
2586
+ // return state
2587
+ // }
2588
+ // return {
2589
+ // ...state,
2590
+ // dropTargets: [],
2591
+ // }
2592
+ };
2593
+
2564
2594
  const canBeDroppedInto = dirent => {
2565
2595
  if (!dirent) {
2566
2596
  return false;
@@ -2658,6 +2688,9 @@ const applyOperation = operation => {
2658
2688
  if (operation.type === 'createFolder') {
2659
2689
  return mkdir(operation.path);
2660
2690
  }
2691
+ if (operation.type === 'copy') {
2692
+ return copy$1(operation.from || '', operation.path);
2693
+ }
2661
2694
  return writeFile(operation.path, operation.text);
2662
2695
  };
2663
2696
  const applyFileOperations = async operations => {
@@ -2753,16 +2786,19 @@ const getMergedDirents$2 = async (root, pathSeparator, dirents) => {
2753
2786
  const mergedDirents = mergeDirents$1(dirents, childDirents);
2754
2787
  return mergedDirents;
2755
2788
  };
2756
- const handleDrop$2 = async (state, files) => {
2789
+ const handleDrop$2 = async (state, fileHandles, files) => {
2757
2790
  const {
2758
2791
  root,
2759
2792
  pathSeparator,
2760
2793
  items
2761
2794
  } = state;
2762
- const handled = await uploadFileSystemHandles(root, pathSeparator, files);
2795
+ const handled = await uploadFileSystemHandles(root, pathSeparator, fileHandles);
2763
2796
  if (handled) {
2764
2797
  const updated = await refresh(state);
2765
- return updated;
2798
+ return {
2799
+ ...updated,
2800
+ dropTargets: []
2801
+ };
2766
2802
  }
2767
2803
  const mergedDirents = await getMergedDirents$2(root, pathSeparator, items);
2768
2804
  return {
@@ -2772,22 +2808,30 @@ const handleDrop$2 = async (state, files) => {
2772
2808
  };
2773
2809
  };
2774
2810
 
2775
- const getFilePathElectron = async file => {
2776
- return invoke('GetFilePathElectron.getFilePathElectron', file);
2811
+ const getFileOperationsElectron = async (root, paths, fileHandles) => {
2812
+ const operations = [];
2813
+ for (let i = 0; i < paths.length; i++) {
2814
+ const fileHandle = fileHandles[i];
2815
+ const name = fileHandle.name;
2816
+ const path = paths[i];
2817
+ operations.push({
2818
+ type: 'copy',
2819
+ path: `${root}/${name}`,
2820
+ text: '',
2821
+ from: path
2822
+ });
2823
+ }
2824
+ return operations;
2777
2825
  };
2778
2826
 
2779
- const mergeDirents = (oldDirents, newDirents) => {
2780
- return newDirents;
2827
+ // TODO copy files in parallel
2828
+ const copyFilesElectron = async (root, pathSeparator, fileHandles, files, paths) => {
2829
+ const operations = await getFileOperationsElectron(root, paths, fileHandles);
2830
+ await applyFileOperations(operations);
2781
2831
  };
2782
2832
 
2783
- // TODO copy files in parallel
2784
- const copyFilesElectron = async (root, pathSeparator, files) => {
2785
- for (const file of files) {
2786
- const from = await getFilePathElectron(file);
2787
- // const from = file.path
2788
- const to = join(pathSeparator, root, file.name);
2789
- await copy$1(from, to);
2790
- }
2833
+ const mergeDirents = (oldDirents, newDirents) => {
2834
+ return newDirents;
2791
2835
  };
2792
2836
  const getMergedDirents$1 = async (root, pathSeparator, dirents) => {
2793
2837
  const childDirents = await getChildDirents(pathSeparator, {
@@ -2797,13 +2841,13 @@ const getMergedDirents$1 = async (root, pathSeparator, dirents) => {
2797
2841
  const mergedDirents = mergeDirents(dirents, childDirents);
2798
2842
  return mergedDirents;
2799
2843
  };
2800
- const handleDrop$1 = async (state, files) => {
2844
+ const handleDrop$1 = async (state, fileHandles, files, paths) => {
2801
2845
  const {
2802
2846
  root,
2803
2847
  pathSeparator,
2804
2848
  items
2805
2849
  } = state;
2806
- await copyFilesElectron(root, pathSeparator, files);
2850
+ await copyFilesElectron(root, pathSeparator, fileHandles, files, paths);
2807
2851
  const mergedDirents = await getMergedDirents$1(root, pathSeparator, items);
2808
2852
  return {
2809
2853
  ...state,
@@ -2812,16 +2856,18 @@ const handleDrop$1 = async (state, files) => {
2812
2856
  };
2813
2857
  };
2814
2858
 
2859
+ const Electron = 2;
2860
+
2815
2861
  const getModule = isElectron => {
2816
2862
  if (isElectron) {
2817
2863
  return handleDrop$1;
2818
2864
  }
2819
2865
  return handleDrop$2;
2820
2866
  };
2821
- const handleDropRoot = async (state, files) => {
2822
- // @ts-ignore
2823
- const fn = getModule(state.isElectron);
2824
- return fn(state, files);
2867
+ const handleDropRoot = async (state, fileHandles, files, paths) => {
2868
+ const isElectron = state.platform === Electron;
2869
+ const fn = getModule(isElectron);
2870
+ return fn(state, fileHandles, files, paths);
2825
2871
  };
2826
2872
 
2827
2873
  const getEndIndex = (items, index, dirent) => {
@@ -2841,13 +2887,13 @@ const getMergedDirents = (items, index, dirent, childDirents) => {
2841
2887
  }, ...childDirents, ...items.slice(endIndex)];
2842
2888
  return mergedDirents;
2843
2889
  };
2844
- const handleDropIntoFolder = async (state, dirent, index, files) => {
2890
+ const handleDropIntoFolder = async (state, dirent, index, fileHandles, files, paths) => {
2845
2891
  const {
2846
2892
  pathSeparator,
2847
2893
  items
2848
2894
  } = state;
2849
2895
  // @ts-ignore
2850
- for (const file of files) {
2896
+ for (const file of fileHandles) {
2851
2897
  // TODO path basename
2852
2898
  const baseName = file.name;
2853
2899
  const to = dirent.path + pathSeparator + baseName;
@@ -2863,18 +2909,18 @@ const handleDropIntoFolder = async (state, dirent, index, files) => {
2863
2909
  dropTargets: []
2864
2910
  };
2865
2911
  };
2866
- const handleDropIntoFile = (state, dirent, index, files) => {
2912
+ const handleDropIntoFile = (state, dirent, index, fileHandles, files, paths) => {
2867
2913
  const {
2868
2914
  items
2869
2915
  } = state;
2870
2916
  const parentIndex = getParentStartIndex(items, index);
2871
2917
  if (parentIndex === -1) {
2872
- return handleDropRoot(state, files);
2918
+ return handleDropRoot(state, fileHandles, files, paths);
2873
2919
  }
2874
2920
  // @ts-ignore
2875
2921
  return handleDropIndex(parentIndex);
2876
2922
  };
2877
- const handleDropIndex = async (state, files, index) => {
2923
+ const handleDropIndex = async (state, fileHandles, files, paths, index) => {
2878
2924
  const {
2879
2925
  items
2880
2926
  } = state;
@@ -2885,9 +2931,9 @@ const handleDropIndex = async (state, files, index) => {
2885
2931
  switch (dirent.type) {
2886
2932
  case Directory:
2887
2933
  case DirectoryExpanded:
2888
- return handleDropIntoFolder(state, dirent, index, files);
2934
+ return handleDropIntoFolder(state, dirent, index, fileHandles);
2889
2935
  case File:
2890
- return handleDropIntoFile(state, dirent, index, files);
2936
+ return handleDropIntoFile(state, dirent, index, fileHandles, files, paths);
2891
2937
  default:
2892
2938
  return state;
2893
2939
  }
@@ -2907,22 +2953,37 @@ const getFileHandles = async fileIds => {
2907
2953
  return files;
2908
2954
  };
2909
2955
 
2910
- const handleDrop = async (state, x, y, fileIds) => {
2956
+ const getFilePathElectron = async file => {
2957
+ return invoke('FileSystemHandle.getFilePathElectron', file);
2958
+ };
2959
+
2960
+ const getFilepath = async file => {
2961
+ return getFilePathElectron(file);
2962
+ };
2963
+ const getFilePaths = async (files, platform) => {
2964
+ if (platform !== Electron) {
2965
+ return files.map(file => '');
2966
+ }
2967
+ const promises = files.map(getFilepath);
2968
+ const paths = await Promise.all(promises);
2969
+ return paths;
2970
+ };
2971
+
2972
+ const handleDrop = async (state, x, y, fileIds, fileList) => {
2911
2973
  try {
2912
- const files = await getFileHandles(fileIds);
2974
+ // @ts-ignore
2975
+ const files = [...fileList];
2976
+ const fileHandles = await getFileHandles(fileIds);
2977
+ const paths = await getFilePaths(files, state.platform);
2913
2978
  const index = getIndexFromPosition(state, x, y);
2914
2979
  const fn = getDropHandler(index);
2915
- const result = await fn(state, files, index);
2980
+ const result = await fn(state, fileHandles, files, paths, index);
2916
2981
  return result;
2917
2982
  } catch (error) {
2918
2983
  throw new VError(error, 'Failed to drop files');
2919
2984
  }
2920
2985
  };
2921
2986
 
2922
- const setFocus = key => {
2923
- return invoke('Focus.setFocus', key);
2924
- };
2925
-
2926
2987
  const handleFocus = async state => {
2927
2988
  await setFocus(FocusExplorer);
2928
2989
  return state;
@@ -3502,6 +3563,7 @@ const HandlePointerDown = 'handlePointerDown';
3502
3563
  const HandleWheel = 'handleWheel';
3503
3564
  const HandleDragOver = 'handleDragOver';
3504
3565
  const HandleDrop = 'handleDrop';
3566
+ const HandleDragLeave = 'handleDragLeave';
3505
3567
 
3506
3568
  const mergeClassNames = (...classNames) => {
3507
3569
  return classNames.filter(Boolean).join(' ');
@@ -3653,6 +3715,7 @@ const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused
3653
3715
  onBlur: HandleListBlur,
3654
3716
  onClick: HandleClick,
3655
3717
  onContextMenu: HandleContextMenu,
3718
+ onDragLeave: HandleDragLeave,
3656
3719
  onDragOver: HandleDragOver,
3657
3720
  onDrop: HandleDrop,
3658
3721
  onFocus: HandleListFocus,
@@ -3925,8 +3988,11 @@ const renderEventListeners = () => {
3925
3988
  preventDefault: true
3926
3989
  }, {
3927
3990
  name: HandleDrop,
3928
- params: ['handleDrop', 'event.clientX', 'event.clientY', 'event.dataTransfer.files2'],
3991
+ params: ['handleDrop', 'event.clientX', 'event.clientY', 'event.dataTransfer.files2', 'event.dataTransfer.files'],
3929
3992
  preventDefault: true
3993
+ }, {
3994
+ name: HandleDragLeave,
3995
+ params: ['handleDragLeave']
3930
3996
  }];
3931
3997
  };
3932
3998
 
@@ -4246,6 +4312,7 @@ const wrapCommand = fn => {
4246
4312
  };
4247
4313
 
4248
4314
  const commandMap = {
4315
+ 'Explorer.getMenuEntries2': getMenuEntries2,
4249
4316
  'Explorer.acceptEdit': wrapCommand(acceptEdit),
4250
4317
  'Explorer.cancelEdit': wrapCommand(cancelEdit),
4251
4318
  'Explorer.collapseAll': wrapCommand(collapseAll$1),
@@ -4264,10 +4331,13 @@ const commandMap = {
4264
4331
  'Explorer.handleBlur': wrapCommand(handleBlur),
4265
4332
  'Explorer.handleClick': wrapCommand(handleClick),
4266
4333
  'Explorer.handleClickAt': wrapCommand(handleClickAt),
4334
+ 'Explorer.handleClickCurrent': wrapCommand(handleClickCurrent),
4267
4335
  'Explorer.handleClickCurrentButKeepFocus': wrapCommand(handleClickCurrentButKeepFocus),
4268
4336
  'Explorer.handleClickOpenFolder': wrapCommand(handleClickOpenFolder),
4269
4337
  'Explorer.handleContextMenu': wrapCommand(handleContextMenu),
4338
+ 'Explorer.handleContextMenuKeyboard': wrapCommand(handleContextMenuKeyboard),
4270
4339
  'Explorer.handleCopy': wrapCommand(handleCopy),
4340
+ 'Explorer.handleDragLeave': wrapCommand(handleDragLeave),
4271
4341
  'Explorer.handleDragOver': wrapCommand(handleDragOver),
4272
4342
  'Explorer.handleDrop': wrapCommand(handleDrop),
4273
4343
  'Explorer.handleFocus': wrapCommand(handleFocus),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.5.0",
3
+ "version": "2.7.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",