@lvce-editor/explorer-view 1.6.0 → 1.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.
@@ -2213,36 +2213,11 @@ const handleBlur = state => {
2213
2213
  };
2214
2214
  };
2215
2215
 
2216
- // TODO viewlet should only have create and refresh functions
2217
- // every thing else can be in a separate module <viewlet>.lazy.js
2218
- // and <viewlet>.ipc.js
2219
-
2220
- // viewlet: creating | refreshing | done | disposed
2221
- // TODO recycle viewlets (maybe)
2222
-
2223
- // TODO instead of root string, there should be a root dirent
2224
-
2225
- // TODO rename dirents to items, then can use virtual list component directly
2226
-
2227
- // TODO support multiselection and removing multiple dirents
2228
-
2229
- // TODO use posInSet and setSize properties to compute more effectively
2230
-
2231
- // TODO much shared logic with newFolder
2232
-
2233
- const handleClickFile$1 = async (state, dirent, index, keepFocus = false) => {
2234
- // await Command.execute(/* Main.openAbsolutePath */ 'Main.openUri', /* absolutePath */ dirent.path, /* focus */ !keepFocus)
2235
- return {
2236
- ...state,
2237
- focusedIndex: index,
2238
- focused: keepFocus
2239
- };
2240
- };
2241
- const handleClickDirectory$1 = async (state, dirent, index, keepFocus) => {
2216
+ const handleClickDirectory = async (state, dirent, index, keepFocus) => {
2242
2217
  dirent.type = DirectoryExpanding;
2243
2218
  // TODO handle error
2244
2219
  const dirents = await getChildDirents(state.pathSeparator, dirent);
2245
- const state2 = {};
2220
+ const state2 = state;
2246
2221
  if (!state2) {
2247
2222
  return state;
2248
2223
  }
@@ -2271,15 +2246,7 @@ const handleClickDirectory$1 = async (state, dirent, index, keepFocus) => {
2271
2246
  maxLineY
2272
2247
  };
2273
2248
  };
2274
- const handleClickDirectoryExpanding = (state, dirent, index, keepFocus) => {
2275
- dirent.type = Directory;
2276
- dirent.icon = getIcon();
2277
- return {
2278
- ...state,
2279
- focusedIndex: index,
2280
- focused: keepFocus
2281
- };
2282
- };
2249
+
2283
2250
  const handleClickDirectoryExpanded$1 = (state, dirent, index, keepFocus) => {
2284
2251
  const {
2285
2252
  minLineY,
@@ -2316,6 +2283,26 @@ const handleClickDirectoryExpanded$1 = (state, dirent, index, keepFocus) => {
2316
2283
  focused: keepFocus
2317
2284
  };
2318
2285
  };
2286
+
2287
+ const handleClickDirectoryExpanding = (state, dirent, index, keepFocus) => {
2288
+ dirent.type = Directory;
2289
+ dirent.icon = getIcon();
2290
+ return {
2291
+ ...state,
2292
+ focusedIndex: index,
2293
+ focused: keepFocus
2294
+ };
2295
+ };
2296
+
2297
+ const handleClickFile$1 = async (state, dirent, index, keepFocus = false) => {
2298
+ // await Command.execute(/* Main.openAbsolutePath */ 'Main.openUri', /* absolutePath */ dirent.path, /* focus */ !keepFocus)
2299
+ return {
2300
+ ...state,
2301
+ focusedIndex: index,
2302
+ focused: keepFocus
2303
+ };
2304
+ };
2305
+
2319
2306
  const handleClickSymLink$1 = async (state, dirent, index) => {
2320
2307
  const realPath = await getRealPath(dirent.path);
2321
2308
  const type = await stat(realPath);
@@ -2326,6 +2313,24 @@ const handleClickSymLink$1 = async (state, dirent, index) => {
2326
2313
  throw new Error(`unsupported file type ${type}`);
2327
2314
  }
2328
2315
  };
2316
+
2317
+ // TODO viewlet should only have create and refresh functions
2318
+ // every thing else can be in a separate module <viewlet>.lazy.js
2319
+ // and <viewlet>.ipc.js
2320
+
2321
+ // viewlet: creating | refreshing | done | disposed
2322
+ // TODO recycle viewlets (maybe)
2323
+
2324
+ // TODO instead of root string, there should be a root dirent
2325
+
2326
+ // TODO rename dirents to items, then can use virtual list component directly
2327
+
2328
+ // TODO support multiselection and removing multiple dirents
2329
+
2330
+ // TODO use posInSet and setSize properties to compute more effectively
2331
+
2332
+ // TODO much shared logic with newFolder
2333
+
2329
2334
  const getClickFn = direntType => {
2330
2335
  switch (direntType) {
2331
2336
  case File:
@@ -2333,7 +2338,7 @@ const getClickFn = direntType => {
2333
2338
  return handleClickFile$1;
2334
2339
  case Directory:
2335
2340
  case SymLinkFolder:
2336
- return handleClickDirectory$1;
2341
+ return handleClickDirectory;
2337
2342
  case DirectoryExpanding:
2338
2343
  return handleClickDirectoryExpanding;
2339
2344
  case DirectoryExpanded:
@@ -2367,40 +2372,6 @@ const getIndexFromPosition = (state, eventX, eventY) => {
2367
2372
  return index;
2368
2373
  };
2369
2374
 
2370
- const handleClickDirectory = async (state, dirent, index, keepFocus) => {
2371
- dirent.type = DirectoryExpanding;
2372
- // TODO handle error
2373
- const dirents = await getChildDirents(state.pathSeparator, dirent);
2374
- const state2 = state;
2375
- if (!state2) {
2376
- return state;
2377
- }
2378
- // TODO use Viewlet.getState here and check if it exists
2379
- const newIndex = state2.items.indexOf(dirent);
2380
- // TODO if viewlet is disposed or root has changed, return
2381
- if (newIndex === -1) {
2382
- return state;
2383
- }
2384
- const newDirents = [...state2.items];
2385
- newDirents.splice(newIndex + 1, 0, ...dirents);
2386
- dirent.type = DirectoryExpanded;
2387
- dirent.icon = getIcon();
2388
- const {
2389
- height,
2390
- itemHeight,
2391
- minLineY
2392
- } = state2;
2393
- // TODO when focused index has changed while expanding, don't update it
2394
- const maxLineY = getExplorerMaxLineY(minLineY, height, itemHeight, newDirents.length);
2395
- return {
2396
- ...state,
2397
- items: newDirents,
2398
- focusedIndex: newIndex,
2399
- focused: keepFocus,
2400
- maxLineY
2401
- };
2402
- };
2403
-
2404
2375
  const getParentStartIndex = (dirents, index) => {
2405
2376
  const dirent = dirents[index];
2406
2377
  let startIndex = index - 1;
@@ -2422,21 +2393,21 @@ const LeftClick = 0;
2422
2393
 
2423
2394
  // TODO instead of root string, there should be a root dirent
2424
2395
 
2425
- const updateIcon = dirent => {
2396
+ const updateIcon$1 = dirent => {
2426
2397
  return {
2427
2398
  ...dirent,
2428
2399
  icon: getIcon()
2429
2400
  };
2430
2401
  };
2431
- const updateIcons = state => {
2432
- const newDirents = state.items.map(updateIcon);
2402
+ const updateIcons$1 = state => {
2403
+ const newDirents = state.items.map(updateIcon$1);
2433
2404
  return {
2434
2405
  ...state,
2435
2406
  items: newDirents
2436
2407
  };
2437
2408
  };
2438
2409
  const handleIconThemeChange = state => {
2439
- return updateIcons(state);
2410
+ return updateIcons$1(state);
2440
2411
  };
2441
2412
 
2442
2413
  // TODO rename dirents to items, then can use virtual list component directly
@@ -2985,8 +2956,7 @@ const None = 'none';
2985
2956
  const Copy = 'copy';
2986
2957
  const Cut = 'cut';
2987
2958
 
2988
- const handlePaste = async state => {
2989
- const nativeFiles = await readNativeFiles();
2959
+ const getPasteHandler = type => {
2990
2960
  // TODO detect cut/paste event, not sure if that is possible
2991
2961
  // TODO check that pasted folder is not a parent folder of opened folder
2992
2962
  // TODO support pasting multiple paths
@@ -2999,18 +2969,36 @@ const handlePaste = async state => {
2999
2969
  // TODO but what if a file is currently selected? Then maybe the parent folder
3000
2970
  // TODO but will it work if the folder is a symlink?
3001
2971
  // TODO handle error gracefully when copy fails
3002
- switch (nativeFiles.type) {
2972
+ switch (type) {
3003
2973
  case None:
3004
- return handlePasteNone(state);
2974
+ return handlePasteNone;
3005
2975
  case Copy:
3006
- return handlePasteCopy(state, nativeFiles);
2976
+ return handlePasteCopy;
3007
2977
  case Cut:
3008
- return handlePasteCut(state, nativeFiles);
2978
+ return handlePasteCut;
3009
2979
  default:
3010
- throw new Error(`unexpected native paste type: ${nativeFiles.type}`);
2980
+ throw new Error(`unexpected native paste type: ${type}`);
3011
2981
  }
3012
2982
  };
3013
2983
 
2984
+ const handlePaste = async state => {
2985
+ const nativeFiles = await readNativeFiles();
2986
+ // TODO detect cut/paste event, not sure if that is possible
2987
+ // TODO check that pasted folder is not a parent folder of opened folder
2988
+ // TODO support pasting multiple paths
2989
+ // TODO what happens when pasting multiple paths, but some of them error?
2990
+ // how many error messages should be shown? Should the operation be undone?
2991
+ // TODO what if it is a large folder and takes a long time to copy? Should show progress
2992
+ // TODO what if there is a permission error? Probably should show a modal to ask for permission
2993
+ // TODO if error is EEXISTS, just rename the copy (e.g. file-copy-1.txt, file-copy-2.txt)
2994
+ // TODO actual target should be selected folder
2995
+ // TODO but what if a file is currently selected? Then maybe the parent folder
2996
+ // TODO but will it work if the folder is a symlink?
2997
+ // TODO handle error gracefully when copy fails
2998
+ const fn = getPasteHandler(nativeFiles.type);
2999
+ return fn(state, nativeFiles);
3000
+ };
3001
+
3014
3002
  const handlePointerDown = (state, button, x, y) => {
3015
3003
  const index = getIndexFromPosition(state, x, y);
3016
3004
  if (button === LeftClick && index === -1) {
@@ -3042,15 +3030,15 @@ const handleUpload = async (state, dirents) => {
3042
3030
  }
3043
3031
  };
3044
3032
 
3033
+ const getWorkspacePath = () => {
3034
+ return invoke('Workspace.getPath');
3035
+ };
3036
+
3045
3037
  const EmptyString = '';
3046
3038
 
3047
3039
  const Fulfilled = 'fulfilled';
3048
3040
  const Rejected = 'rejected';
3049
3041
 
3050
- const getWorkspacePath = () => {
3051
- return invoke('Workspace.getPath');
3052
- };
3053
-
3054
3042
  // TODO viewlet should only have create and refresh functions
3055
3043
  // every thing else can be in a separate module <viewlet>.lazy.js
3056
3044
  // and <viewlet>.ipc.js
@@ -3196,6 +3184,16 @@ const loadContent = async (state, savedState) => {
3196
3184
  };
3197
3185
  };
3198
3186
 
3187
+ const handleWorkspaceChange = async state => {
3188
+ const newRoot = await getWorkspacePath();
3189
+ const state1 = {
3190
+ ...state,
3191
+ root: newRoot
3192
+ };
3193
+ const newState = await loadContent(state1, undefined);
3194
+ return newState;
3195
+ };
3196
+
3199
3197
  const ExplorerEditBox = FocusExplorerEditBox;
3200
3198
 
3201
3199
  const setFocus = key => {
@@ -3215,7 +3213,7 @@ const newDirent = async (state, editingType) => {
3215
3213
  if (dirent.type === Directory) {
3216
3214
  // TODO handle error
3217
3215
  // @ts-ignore
3218
- await undefined(state, dirent, focusedIndex);
3216
+ await handleClickDirectory(state, dirent);
3219
3217
  }
3220
3218
  }
3221
3219
  return {
@@ -3377,6 +3375,7 @@ const renderActions = state => {
3377
3375
  const getSavedRoot = (savedState, workspacePath) => {
3378
3376
  return workspacePath;
3379
3377
  };
3378
+
3380
3379
  const restoreState = savedState => {
3381
3380
  if (!savedState) {
3382
3381
  return {
@@ -3401,6 +3400,21 @@ const restoreState = savedState => {
3401
3400
  };
3402
3401
  };
3403
3402
 
3403
+ const updateIcon = dirent => {
3404
+ return {
3405
+ ...dirent,
3406
+ icon: getIcon()
3407
+ };
3408
+ };
3409
+
3410
+ const updateIcons = state => {
3411
+ const newDirents = state.items.map(updateIcon);
3412
+ return {
3413
+ ...state,
3414
+ items: newDirents
3415
+ };
3416
+ };
3417
+
3404
3418
  const getIndex = (dirents, uri) => {
3405
3419
  for (let i = 0; i < dirents.length; i++) {
3406
3420
  const dirent = dirents[i];
@@ -3717,6 +3731,7 @@ const commandMap = {
3717
3731
  'Explorer.handlePointerDown': handlePointerDown,
3718
3732
  'Explorer.handleUpload': handleUpload,
3719
3733
  'Explorer.handleWheel': handleWheel,
3734
+ 'Explorer.handleWorkspaceChange': handleWorkspaceChange,
3720
3735
  'Explorer.loadContent': loadContent,
3721
3736
  'Explorer.newFile': newFile,
3722
3737
  'Explorer.newFolder': newFolder,
@@ -3728,7 +3743,8 @@ const commandMap = {
3728
3743
  'Explorer.revealItem': revealItem,
3729
3744
  'Explorer.saveState': saveState,
3730
3745
  'Explorer.setDeltaY': setDeltaY,
3731
- 'Explorer.updateEditingValue': updateEditingValue
3746
+ 'Explorer.updateEditingValue': updateEditingValue,
3747
+ 'Explorer.updateIcons': updateIcons
3732
3748
  };
3733
3749
 
3734
3750
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "Explorer Worker",
5
5
  "main": "dist/explorerViewWorkerMain.js",
6
6
  "type": "module",