@lvce-editor/explorer-view 2.4.0 → 2.5.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.
@@ -2010,7 +2010,7 @@ const rename = () => {
2010
2010
  const deleteItem = () => {
2011
2011
  return i18nString(Delete);
2012
2012
  };
2013
- const refresh = () => {
2013
+ const refresh$1 = () => {
2014
2014
  return i18nString(RefreshExplorer);
2015
2015
  };
2016
2016
  const collapseAll = () => {
@@ -2624,6 +2624,49 @@ const handleDragOver = (state, x, y) => {
2624
2624
  };
2625
2625
  };
2626
2626
 
2627
+ const getTopLevelDirents = (root, pathSeparator, excluded) => {
2628
+ if (!root) {
2629
+ return [];
2630
+ }
2631
+ return getChildDirents(pathSeparator, {
2632
+ depth: 0,
2633
+ path: root,
2634
+ type: Directory
2635
+ }, excluded);
2636
+ };
2637
+
2638
+ const mergeDirents$2 = (oldDirents, newDirents) => {
2639
+ const merged = [];
2640
+ for (const newDirent of newDirents) {
2641
+ merged.push(newDirent);
2642
+ }
2643
+ return merged;
2644
+ };
2645
+
2646
+ // TODO add lots of tests for this
2647
+ const refresh = async state1 => {
2648
+ const topLevelDirents = await getTopLevelDirents(state1.root, state1.pathSeparator, []);
2649
+ const newDirents = mergeDirents$2(state1.items, topLevelDirents);
2650
+ const state3 = {
2651
+ ...state1,
2652
+ items: newDirents
2653
+ };
2654
+ return state3;
2655
+ };
2656
+
2657
+ const applyOperation = operation => {
2658
+ if (operation.type === 'createFolder') {
2659
+ return mkdir(operation.path);
2660
+ }
2661
+ return writeFile(operation.path, operation.text);
2662
+ };
2663
+ const applyFileOperations = async operations => {
2664
+ // TODO run operations in parallel if possible
2665
+ for (const operation of operations) {
2666
+ await applyOperation(operation);
2667
+ }
2668
+ };
2669
+
2627
2670
  const getChildHandles = async fileHandle => {
2628
2671
  // @ts-ignore
2629
2672
  const values = fileHandle.values();
@@ -2661,11 +2704,35 @@ const createUploadTree = async (root, fileHandles) => {
2661
2704
  return uploadTree;
2662
2705
  };
2663
2706
 
2707
+ const getFileOperations = (root, uploadTree) => {
2708
+ const operations = [];
2709
+ const processTree = (tree, currentPath) => {
2710
+ for (const [path, value] of Object.entries(tree)) {
2711
+ const fullPath = currentPath ? `${currentPath}/${path}` : path;
2712
+ if (typeof value === 'object') {
2713
+ operations.push({
2714
+ type: 'createFolder',
2715
+ path: `${root}/${fullPath}`,
2716
+ text: ''
2717
+ });
2718
+ processTree(value, fullPath);
2719
+ } else if (typeof value === 'string') {
2720
+ operations.push({
2721
+ type: 'createFile',
2722
+ path: `${root}/${fullPath}`,
2723
+ text: value
2724
+ });
2725
+ }
2726
+ }
2727
+ };
2728
+ processTree(uploadTree, '');
2729
+ return operations;
2730
+ };
2731
+
2664
2732
  const uploadFileSystemHandles = async (root, pathSeparator, fileSystemHandles) => {
2665
2733
  const uploadTree = await createUploadTree(root, fileSystemHandles);
2666
- console.log({
2667
- uploadTree
2668
- });
2734
+ const fileOperations = getFileOperations(root, uploadTree);
2735
+ await applyFileOperations(fileOperations);
2669
2736
 
2670
2737
  // TODO
2671
2738
  // 1. in electron, use webutils.getPathForFile to see if a path is available
@@ -2675,7 +2742,7 @@ const uploadFileSystemHandles = async (root, pathSeparator, fileSystemHandles) =
2675
2742
  return true;
2676
2743
  };
2677
2744
 
2678
- const mergeDirents$2 = (oldDirents, newDirents) => {
2745
+ const mergeDirents$1 = (oldDirents, newDirents) => {
2679
2746
  return newDirents;
2680
2747
  };
2681
2748
  const getMergedDirents$2 = async (root, pathSeparator, dirents) => {
@@ -2683,7 +2750,7 @@ const getMergedDirents$2 = async (root, pathSeparator, dirents) => {
2683
2750
  path: root,
2684
2751
  depth: 0
2685
2752
  });
2686
- const mergedDirents = mergeDirents$2(dirents, childDirents);
2753
+ const mergedDirents = mergeDirents$1(dirents, childDirents);
2687
2754
  return mergedDirents;
2688
2755
  };
2689
2756
  const handleDrop$2 = async (state, files) => {
@@ -2694,7 +2761,8 @@ const handleDrop$2 = async (state, files) => {
2694
2761
  } = state;
2695
2762
  const handled = await uploadFileSystemHandles(root, pathSeparator, files);
2696
2763
  if (handled) {
2697
- return state;
2764
+ const updated = await refresh(state);
2765
+ return updated;
2698
2766
  }
2699
2767
  const mergedDirents = await getMergedDirents$2(root, pathSeparator, items);
2700
2768
  return {
@@ -2708,7 +2776,7 @@ const getFilePathElectron = async file => {
2708
2776
  return invoke('GetFilePathElectron.getFilePathElectron', file);
2709
2777
  };
2710
2778
 
2711
- const mergeDirents$1 = (oldDirents, newDirents) => {
2779
+ const mergeDirents = (oldDirents, newDirents) => {
2712
2780
  return newDirents;
2713
2781
  };
2714
2782
 
@@ -2726,7 +2794,7 @@ const getMergedDirents$1 = async (root, pathSeparator, dirents) => {
2726
2794
  path: root,
2727
2795
  depth: 0
2728
2796
  });
2729
- const mergedDirents = mergeDirents$1(dirents, childDirents);
2797
+ const mergedDirents = mergeDirents(dirents, childDirents);
2730
2798
  return mergedDirents;
2731
2799
  };
2732
2800
  const handleDrop$1 = async (state, files) => {
@@ -2891,25 +2959,6 @@ const handleIconThemeChange = state => {
2891
2959
  return updateIcons(state);
2892
2960
  };
2893
2961
 
2894
- const getTopLevelDirents = (root, pathSeparator, excluded) => {
2895
- if (!root) {
2896
- return [];
2897
- }
2898
- return getChildDirents(pathSeparator, {
2899
- depth: 0,
2900
- path: root,
2901
- type: Directory
2902
- }, excluded);
2903
- };
2904
-
2905
- const mergeDirents = (oldDirents, newDirents) => {
2906
- const merged = [];
2907
- for (const newDirent of newDirents) {
2908
- merged.push(newDirent);
2909
- }
2910
- return merged;
2911
- };
2912
-
2913
2962
  // TODO add lots of tests for this
2914
2963
  const updateRoot = async state1 => {
2915
2964
  // @ts-ignore
@@ -2918,13 +2967,13 @@ const updateRoot = async state1 => {
2918
2967
  }
2919
2968
  // const file = nativeFiles.files[0]
2920
2969
  // @ts-ignore
2921
- const topLevelDirents = await getTopLevelDirents(state1.root, state1.pathSeparator);
2970
+ const topLevelDirents = await getTopLevelDirents(state1.root, state1.pathSeparator, []);
2922
2971
  // const state2 = Viewlet.getState('Explorer')
2923
2972
  // // TODO what if root changes while reading directories?
2924
2973
  // if (state2.disposed || state2.root !== state1.root) {
2925
2974
  // return state2
2926
2975
  // }
2927
- const newDirents = mergeDirents(state1.items, topLevelDirents);
2976
+ const newDirents = mergeDirents$2(state1.items, topLevelDirents);
2928
2977
  const state3 = {
2929
2978
  ...state1,
2930
2979
  items: newDirents
@@ -3775,7 +3824,7 @@ const getActions = root => {
3775
3824
  command: 'newFolder'
3776
3825
  }, {
3777
3826
  type: Button,
3778
- id: refresh(),
3827
+ id: refresh$1(),
3779
3828
  icon: Refresh,
3780
3829
  command: 'refresh'
3781
3830
  }, {
@@ -4232,6 +4281,7 @@ const commandMap = {
4232
4281
  'Explorer.newFile': wrapCommand(newFile),
4233
4282
  'Explorer.newFolder': wrapCommand(newFolder),
4234
4283
  'Explorer.openContainingFolder': wrapCommand(openContainingFolder),
4284
+ 'Explorer.refresh': wrapCommand(refresh),
4235
4285
  'Explorer.removeDirent': wrapCommand(removeDirent),
4236
4286
  'Explorer.renameDirent': wrapCommand(renameDirent),
4237
4287
  'Explorer.restoreState': restoreState,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",