@lvce-editor/explorer-view 2.6.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', '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'];
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
  };
@@ -2562,16 +2580,15 @@ const handleCopy = async state => {
2562
2580
  };
2563
2581
 
2564
2582
  const handleDragLeave = state => {
2565
- const {
2566
- dropTargets
2567
- } = state;
2568
- if (dropTargets.length === 0) {
2569
- return state;
2570
- }
2571
- return {
2572
- ...state,
2573
- dropTargets: []
2574
- };
2583
+ return state;
2584
+ // const { dropTargets } = state
2585
+ // if (dropTargets.length === 0) {
2586
+ // return state
2587
+ // }
2588
+ // return {
2589
+ // ...state,
2590
+ // dropTargets: [],
2591
+ // }
2575
2592
  };
2576
2593
 
2577
2594
  const canBeDroppedInto = dirent => {
@@ -2807,22 +2824,8 @@ const getFileOperationsElectron = async (root, paths, fileHandles) => {
2807
2824
  return operations;
2808
2825
  };
2809
2826
 
2810
- const getFilePathElectron = async file => {
2811
- return invoke('FileSystemHandle.getFilePathElectron', file);
2812
- };
2813
-
2814
- const getFilepath = async file => {
2815
- return getFilePathElectron(file);
2816
- };
2817
- const getFilePaths = async files => {
2818
- const promises = files.map(getFilepath);
2819
- const paths = await Promise.all(promises);
2820
- return paths;
2821
- };
2822
-
2823
2827
  // TODO copy files in parallel
2824
- const copyFilesElectron = async (root, pathSeparator, fileHandles, files) => {
2825
- const paths = await getFilePaths(files);
2828
+ const copyFilesElectron = async (root, pathSeparator, fileHandles, files, paths) => {
2826
2829
  const operations = await getFileOperationsElectron(root, paths, fileHandles);
2827
2830
  await applyFileOperations(operations);
2828
2831
  };
@@ -2838,13 +2841,13 @@ const getMergedDirents$1 = async (root, pathSeparator, dirents) => {
2838
2841
  const mergedDirents = mergeDirents(dirents, childDirents);
2839
2842
  return mergedDirents;
2840
2843
  };
2841
- const handleDrop$1 = async (state, fileHandles, files) => {
2844
+ const handleDrop$1 = async (state, fileHandles, files, paths) => {
2842
2845
  const {
2843
2846
  root,
2844
2847
  pathSeparator,
2845
2848
  items
2846
2849
  } = state;
2847
- await copyFilesElectron(root, pathSeparator, fileHandles, files);
2850
+ await copyFilesElectron(root, pathSeparator, fileHandles, files, paths);
2848
2851
  const mergedDirents = await getMergedDirents$1(root, pathSeparator, items);
2849
2852
  return {
2850
2853
  ...state,
@@ -2861,10 +2864,10 @@ const getModule = isElectron => {
2861
2864
  }
2862
2865
  return handleDrop$2;
2863
2866
  };
2864
- const handleDropRoot = async (state, fileHandles, files) => {
2867
+ const handleDropRoot = async (state, fileHandles, files, paths) => {
2865
2868
  const isElectron = state.platform === Electron;
2866
2869
  const fn = getModule(isElectron);
2867
- return fn(state, fileHandles, files);
2870
+ return fn(state, fileHandles, files, paths);
2868
2871
  };
2869
2872
 
2870
2873
  const getEndIndex = (items, index, dirent) => {
@@ -2884,7 +2887,7 @@ const getMergedDirents = (items, index, dirent, childDirents) => {
2884
2887
  }, ...childDirents, ...items.slice(endIndex)];
2885
2888
  return mergedDirents;
2886
2889
  };
2887
- const handleDropIntoFolder = async (state, dirent, index, fileHandles, files) => {
2890
+ const handleDropIntoFolder = async (state, dirent, index, fileHandles, files, paths) => {
2888
2891
  const {
2889
2892
  pathSeparator,
2890
2893
  items
@@ -2906,18 +2909,18 @@ const handleDropIntoFolder = async (state, dirent, index, fileHandles, files) =>
2906
2909
  dropTargets: []
2907
2910
  };
2908
2911
  };
2909
- const handleDropIntoFile = (state, dirent, index, fileHandles, files) => {
2912
+ const handleDropIntoFile = (state, dirent, index, fileHandles, files, paths) => {
2910
2913
  const {
2911
2914
  items
2912
2915
  } = state;
2913
2916
  const parentIndex = getParentStartIndex(items, index);
2914
2917
  if (parentIndex === -1) {
2915
- return handleDropRoot(state, fileHandles, files);
2918
+ return handleDropRoot(state, fileHandles, files, paths);
2916
2919
  }
2917
2920
  // @ts-ignore
2918
2921
  return handleDropIndex(parentIndex);
2919
2922
  };
2920
- const handleDropIndex = async (state, fileHandles, files, index) => {
2923
+ const handleDropIndex = async (state, fileHandles, files, paths, index) => {
2921
2924
  const {
2922
2925
  items
2923
2926
  } = state;
@@ -2930,7 +2933,7 @@ const handleDropIndex = async (state, fileHandles, files, index) => {
2930
2933
  case DirectoryExpanded:
2931
2934
  return handleDropIntoFolder(state, dirent, index, fileHandles);
2932
2935
  case File:
2933
- return handleDropIntoFile(state, dirent, index, fileHandles, files);
2936
+ return handleDropIntoFile(state, dirent, index, fileHandles, files, paths);
2934
2937
  default:
2935
2938
  return state;
2936
2939
  }
@@ -2950,24 +2953,37 @@ const getFileHandles = async fileIds => {
2950
2953
  return files;
2951
2954
  };
2952
2955
 
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
+
2953
2972
  const handleDrop = async (state, x, y, fileIds, fileList) => {
2954
2973
  try {
2955
2974
  // @ts-ignore
2956
2975
  const files = [...fileList];
2957
2976
  const fileHandles = await getFileHandles(fileIds);
2977
+ const paths = await getFilePaths(files, state.platform);
2958
2978
  const index = getIndexFromPosition(state, x, y);
2959
2979
  const fn = getDropHandler(index);
2960
- const result = await fn(state, fileHandles, files, index);
2980
+ const result = await fn(state, fileHandles, files, paths, index);
2961
2981
  return result;
2962
2982
  } catch (error) {
2963
2983
  throw new VError(error, 'Failed to drop files');
2964
2984
  }
2965
2985
  };
2966
2986
 
2967
- const setFocus = key => {
2968
- return invoke('Focus.setFocus', key);
2969
- };
2970
-
2971
2987
  const handleFocus = async state => {
2972
2988
  await setFocus(FocusExplorer);
2973
2989
  return state;
@@ -4296,6 +4312,7 @@ const wrapCommand = fn => {
4296
4312
  };
4297
4313
 
4298
4314
  const commandMap = {
4315
+ 'Explorer.getMenuEntries2': getMenuEntries2,
4299
4316
  'Explorer.acceptEdit': wrapCommand(acceptEdit),
4300
4317
  'Explorer.cancelEdit': wrapCommand(cancelEdit),
4301
4318
  'Explorer.collapseAll': wrapCommand(collapseAll$1),
@@ -4314,9 +4331,11 @@ const commandMap = {
4314
4331
  'Explorer.handleBlur': wrapCommand(handleBlur),
4315
4332
  'Explorer.handleClick': wrapCommand(handleClick),
4316
4333
  'Explorer.handleClickAt': wrapCommand(handleClickAt),
4334
+ 'Explorer.handleClickCurrent': wrapCommand(handleClickCurrent),
4317
4335
  'Explorer.handleClickCurrentButKeepFocus': wrapCommand(handleClickCurrentButKeepFocus),
4318
4336
  'Explorer.handleClickOpenFolder': wrapCommand(handleClickOpenFolder),
4319
4337
  'Explorer.handleContextMenu': wrapCommand(handleContextMenu),
4338
+ 'Explorer.handleContextMenuKeyboard': wrapCommand(handleContextMenuKeyboard),
4320
4339
  'Explorer.handleCopy': wrapCommand(handleCopy),
4321
4340
  'Explorer.handleDragLeave': wrapCommand(handleDragLeave),
4322
4341
  'Explorer.handleDragOver': wrapCommand(handleDragOver),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",