@lvce-editor/explorer-view 1.18.0 → 1.20.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.
@@ -442,10 +442,10 @@ const create$4 = (method, params) => {
442
442
  };
443
443
  };
444
444
  const callbacks = Object.create(null);
445
- const set$1 = (id, fn) => {
445
+ const set$2 = (id, fn) => {
446
446
  callbacks[id] = fn;
447
447
  };
448
- const get$1 = id => {
448
+ const get$2 = id => {
449
449
  return callbacks[id];
450
450
  };
451
451
  const remove$1 = id => {
@@ -461,7 +461,7 @@ const registerPromise = () => {
461
461
  resolve,
462
462
  promise
463
463
  } = Promise.withResolvers();
464
- set$1(id, resolve);
464
+ set$2(id, resolve);
465
465
  return {
466
466
  id,
467
467
  promise
@@ -618,7 +618,7 @@ const warn = (...args) => {
618
618
  console.warn(...args);
619
619
  };
620
620
  const resolve = (id, response) => {
621
- const fn = get$1(id);
621
+ const fn = get$2(id);
622
622
  if (!fn) {
623
623
  console.log(response);
624
624
  warn(`callback ${id} may already be disposed`);
@@ -657,7 +657,7 @@ const getErrorProperty = (error, prettyError) => {
657
657
  }
658
658
  };
659
659
  };
660
- const create$1 = (message, error) => {
660
+ const create$1$1 = (message, error) => {
661
661
  return {
662
662
  jsonrpc: Two,
663
663
  id: message.id,
@@ -668,7 +668,7 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
668
668
  const prettyError = preparePrettyError(error);
669
669
  logError(error, prettyError);
670
670
  const errorProperty = getErrorProperty(error, prettyError);
671
- return create$1(message, errorProperty);
671
+ return create$1$1(message, errorProperty);
672
672
  };
673
673
  const create$5 = (message, result) => {
674
674
  return {
@@ -843,7 +843,7 @@ const listen$1 = async (module, options) => {
843
843
  const ipc = module.wrap(rawIpc);
844
844
  return ipc;
845
845
  };
846
- const create = async ({
846
+ const create$1 = async ({
847
847
  commandMap
848
848
  }) => {
849
849
  // TODO create a commandMap per rpc instance
@@ -855,7 +855,7 @@ const create = async ({
855
855
  };
856
856
  const WebWorkerRpcClient = {
857
857
  __proto__: null,
858
- create
858
+ create: create$1
859
859
  };
860
860
 
861
861
  const RE_CHARACTERS = /^[a-zA-Z.-]+$/;
@@ -925,7 +925,9 @@ const computeExplorerRenamedDirent = (dirents, index, newName) => {
925
925
  name: newName
926
926
  })
927
927
  };
928
- const depth = newDirent.depth;
928
+ const {
929
+ depth
930
+ } = newDirent;
929
931
  // TODO
930
932
  for (; startIndex >= 0; startIndex--) {
931
933
  const dirent = dirents[startIndex];
@@ -1013,15 +1015,15 @@ const Rename$1 = 3;
1013
1015
  const RendererWorker = 1;
1014
1016
 
1015
1017
  const rpcs = Object.create(null);
1016
- const set = (id, rpc) => {
1018
+ const set$1 = (id, rpc) => {
1017
1019
  rpcs[id] = rpc;
1018
1020
  };
1019
- const get = id => {
1021
+ const get$1 = id => {
1020
1022
  return rpcs[id];
1021
1023
  };
1022
1024
 
1023
1025
  const invoke = (method, ...params) => {
1024
- const rpc = get(RendererWorker);
1026
+ const rpc = get$1(RendererWorker);
1025
1027
  return rpc.invoke(method, ...params);
1026
1028
  };
1027
1029
 
@@ -1093,7 +1095,7 @@ const acceptCreate = async (state, newDirentType, createFn) => {
1093
1095
  // TODO better handle error
1094
1096
  try {
1095
1097
  await createFn(absolutePath);
1096
- } catch (error) {
1098
+ } catch {
1097
1099
  // TODO display error
1098
1100
  return state;
1099
1101
  }
@@ -1173,7 +1175,7 @@ const acceptRename = async state => {
1173
1175
  const oldParentPath = dirname(pathSeparator, oldAbsolutePath);
1174
1176
  const newAbsolutePath = [oldParentPath, editingValue].join(pathSeparator);
1175
1177
  await rename$1(oldAbsolutePath, newAbsolutePath);
1176
- } catch (error) {
1178
+ } catch {
1177
1179
  // TODO
1178
1180
  // await ErrorHandling.showErrorDialog(error)
1179
1181
  return state;
@@ -1283,6 +1285,55 @@ const copyRelativePath$1 = async state => {
1283
1285
  return state;
1284
1286
  };
1285
1287
 
1288
+ const states = Object.create(null);
1289
+ const get = uid => {
1290
+ return states[uid];
1291
+ };
1292
+ const set = (uid, oldState, newState) => {
1293
+ states[uid] = {
1294
+ oldState,
1295
+ newState
1296
+ };
1297
+ };
1298
+
1299
+ const ListItem = 22;
1300
+
1301
+ const Slash = '/';
1302
+
1303
+ // TODO parentUid might ot be needed
1304
+ const create = (id, uri, x, y, width, height, args, parentUid) => {
1305
+ const state = {
1306
+ uid: id,
1307
+ parentUid,
1308
+ root: '',
1309
+ items: [],
1310
+ focusedIndex: -1,
1311
+ focused: false,
1312
+ hoverIndex: -1,
1313
+ x,
1314
+ y,
1315
+ width,
1316
+ height,
1317
+ deltaY: 0,
1318
+ minLineY: 0,
1319
+ maxLineY: 0,
1320
+ pathSeparator: Slash,
1321
+ version: 0,
1322
+ editingIndex: -1,
1323
+ itemHeight: ListItem,
1324
+ dropTargets: [],
1325
+ excluded: [],
1326
+ editingValue: '',
1327
+ editingType: None$5,
1328
+ editingIcon: '',
1329
+ fileIconCache: Object.create(null),
1330
+ useChevrons: false,
1331
+ icons: []
1332
+ };
1333
+ set(state.uid, state, state);
1334
+ return state;
1335
+ };
1336
+
1286
1337
  const isSymbolicLink = dirent => {
1287
1338
  return dirent.type === Symlink;
1288
1339
  };
@@ -1474,7 +1525,9 @@ const expandAll = async state => {
1474
1525
  return state;
1475
1526
  }
1476
1527
  const dirent = items[focusedIndex];
1477
- const depth = dirent.depth;
1528
+ const {
1529
+ depth
1530
+ } = dirent;
1478
1531
  const newDirents = [...items];
1479
1532
  // TODO fetch child dirents in parallel
1480
1533
  for (const dirent of newDirents) {
@@ -1825,6 +1878,18 @@ const Viewlet = 'Viewlet';
1825
1878
  const Welcome = 'Welcome';
1826
1879
  const WelcomeMessage = 'WelcomeMessage';
1827
1880
 
1881
+ // TODO add option to make classnames numeric
1882
+ // once at start, send all classnames to renderer process
1883
+ // then, components uses numeric classname
1884
+ // when a component uses multiple classnames, it is a new number
1885
+ // representing the concatenated strings for example
1886
+ // 0 = 'Button'
1887
+ // 1 = 'IconButton'
1888
+ // 2 = 'Button IconButton'
1889
+ // it could make dom diffing faster, since for classname,
1890
+ // only numbers are compared. it could also make rendering faster,
1891
+ // since less data is transferred to renderer process
1892
+
1828
1893
  const HandleBlur = 'handleBlur';
1829
1894
  const HandleClick = 'handleClick';
1830
1895
  const handleClickOpenFolder$1 = 'handleClickOpenFolder';
@@ -2807,7 +2872,9 @@ const isEqual = (a, b) => {
2807
2872
  if (a.length !== b.length) {
2808
2873
  return false;
2809
2874
  }
2810
- const length = a.length;
2875
+ const {
2876
+ length
2877
+ } = a;
2811
2878
  for (let i = 0; i < length; i++) {
2812
2879
  if (a[i] !== b[i]) {
2813
2880
  return false;
@@ -3176,23 +3243,19 @@ const getWorkspacePath = () => {
3176
3243
  return invoke('Workspace.getPath');
3177
3244
  };
3178
3245
 
3246
+ const getSettings = async () => {
3247
+ const useChevronsRaw = await invoke('Preferences.get', 'explorer.useChevrons');
3248
+ const useChevrons = useChevronsRaw === false ? false : true;
3249
+ return {
3250
+ useChevrons
3251
+ };
3252
+ };
3253
+
3179
3254
  const EmptyString = '';
3180
3255
 
3181
3256
  const Fulfilled = 'fulfilled';
3182
3257
  const Rejected = 'rejected';
3183
3258
 
3184
- // TODO viewlet should only have create and refresh functions
3185
- // every thing else can be in a separate module <viewlet>.lazy.js
3186
- // and <viewlet>.ipc.js
3187
-
3188
- // viewlet: creating | refreshing | done | disposed
3189
- // TODO recycle viewlets (maybe)
3190
-
3191
- // TODO instead of root string, there should be a root dirent
3192
-
3193
- const getPathSeparator = root => {
3194
- return getPathSeparator$1(root);
3195
- };
3196
3259
  const getSavedChildDirents = (map, path, depth, excluded, pathSeparator) => {
3197
3260
  const children = map[path];
3198
3261
  if (!children) {
@@ -3281,6 +3344,19 @@ const restoreExpandedState = async (savedState, root, pathSeparator, excluded) =
3281
3344
  const dirents = createDirents(root, expandedDirentPaths, expandedDirentChildren, excluded, pathSeparator);
3282
3345
  return dirents;
3283
3346
  };
3347
+
3348
+ // TODO viewlet should only have create and refresh functions
3349
+ // every thing else can be in a separate module <viewlet>.lazy.js
3350
+ // and <viewlet>.ipc.js
3351
+
3352
+ // viewlet: creating | refreshing | done | disposed
3353
+ // TODO recycle viewlets (maybe)
3354
+
3355
+ // TODO instead of root string, there should be a root dirent
3356
+
3357
+ const getPathSeparator = root => {
3358
+ return getPathSeparator$1(root);
3359
+ };
3284
3360
  const getExcluded = () => {
3285
3361
  const excludedObject = {};
3286
3362
  const excluded = [];
@@ -3295,8 +3371,9 @@ const getSavedRoot$1 = (savedState, workspacePath) => {
3295
3371
  return workspacePath;
3296
3372
  };
3297
3373
  const loadContent = async (state, savedState) => {
3298
- const useChevronsRaw = await invoke('Preferences.get', 'explorer.useChevrons');
3299
- const useChevrons = Boolean(useChevronsRaw);
3374
+ const {
3375
+ useChevrons
3376
+ } = await getSettings();
3300
3377
  const workspacePath = await getWorkspacePath();
3301
3378
  const root = getSavedRoot$1(savedState, workspacePath);
3302
3379
  // TODO path separator could be restored from saved state
@@ -3412,7 +3489,7 @@ const removeDirent = async state => {
3412
3489
  try {
3413
3490
  // TODO handle error
3414
3491
  await remove(absolutePath);
3415
- } catch (error) {
3492
+ } catch {
3416
3493
  // TODO vscode shows error as alert (no stacktrace) and retry button
3417
3494
  // maybe should show alert as well, but where to put stacktrace?
3418
3495
  // on web should probably show notification (dialog)
@@ -3482,7 +3559,7 @@ const renameDirent = state => {
3482
3559
 
3483
3560
  const renderItems = {
3484
3561
  isEqual(oldState, newState) {
3485
- return JSON.stringify(oldState.items) === JSON.stringify(newState.items) && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.focusedIndex === newState.focusedIndex && oldState.editingIndex === newState.editingIndex && oldState.editingType === newState.editingType && oldState.editingValue === newState.editingValue && oldState.width === newState.width && oldState.focused === newState.focused;
3562
+ return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.focusedIndex === newState.focusedIndex && oldState.editingIndex === newState.editingIndex && oldState.editingType === newState.editingType && oldState.editingValue === newState.editingValue && oldState.width === newState.width && oldState.focused === newState.focused;
3486
3563
  },
3487
3564
  apply(oldState, newState) {
3488
3565
  const visibleDirents = getVisibleExplorerItems(newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex, newState.editingIndex, newState.editingType, newState.editingValue, newState.icons, newState.useChevrons);
@@ -3522,7 +3599,23 @@ const renderEditingIndex = {
3522
3599
  }
3523
3600
  };
3524
3601
  const render = [renderItems, renderEditingIndex];
3525
- const doRender = (oldState, newState) => {
3602
+ const doRender = (uid, _) => {
3603
+ if (typeof uid === 'number') {
3604
+ const {
3605
+ oldState,
3606
+ newState
3607
+ } = get(uid);
3608
+ const commands = [];
3609
+ for (const fn of render) {
3610
+ if (!fn.isEqual(oldState, newState)) {
3611
+ commands.push(fn.apply(oldState, newState));
3612
+ }
3613
+ }
3614
+ return commands;
3615
+ }
3616
+ // deprecated
3617
+ const oldState = uid;
3618
+ const newState = _;
3526
3619
  const commands = [];
3527
3620
  for (const fn of render) {
3528
3621
  if (!fn.isEqual(oldState, newState)) {
@@ -3838,14 +3931,22 @@ const isExpandedDirectory = dirent => {
3838
3931
  return dirent.type === DirectoryExpanded;
3839
3932
  };
3840
3933
 
3841
- const saveState = state => {
3934
+ const saveState = uid => {
3935
+ let newState;
3936
+ if (typeof uid === 'number') {
3937
+ const value = get(uid);
3938
+ newState = value.newState;
3939
+ } else {
3940
+ // deprecated
3941
+ newState = uid;
3942
+ }
3842
3943
  const {
3843
3944
  items,
3844
3945
  root,
3845
3946
  deltaY,
3846
3947
  minLineY,
3847
3948
  maxLineY
3848
- } = state;
3949
+ } = newState;
3849
3950
  const expandedPaths = items.filter(isExpandedDirectory).map(getPath);
3850
3951
  return {
3851
3952
  expandedPaths,
@@ -3895,64 +3996,83 @@ const updateEditingValue = (state, value) => {
3895
3996
  };
3896
3997
  };
3897
3998
 
3999
+ const wrapCommand = fn => {
4000
+ const wrapped = async (uid, ...args) => {
4001
+ if (typeof uid === 'number') {
4002
+ const {
4003
+ newState
4004
+ } = get(uid);
4005
+ const newerState = await fn(newState, ...args);
4006
+ set(uid, newState, newerState);
4007
+ } else {
4008
+ // deprecated
4009
+ const newerState = await fn(uid, ...args);
4010
+ return newerState;
4011
+ }
4012
+ };
4013
+ return wrapped;
4014
+ };
4015
+
3898
4016
  const commandMap = {
3899
- 'Explorer.acceptEdit': acceptEdit,
3900
- 'Explorer.cancelEdit': cancelEdit,
3901
- 'Explorer.collapseAll': collapseAll$1,
3902
- 'Explorer.copyPath': copyPath$1,
3903
- 'Explorer.copyRelativePath': copyRelativePath$1,
3904
- 'Explorer.expandAll': expandAll,
3905
- 'Explorer.expandRecursively': expandRecursively,
3906
- 'Explorer.focusFirst': focusFirst,
3907
- 'Explorer.focusIndex': focusIndex,
3908
- 'Explorer.focusLast': focusLast,
3909
- 'Explorer.focusNext': focusNext,
3910
- 'Explorer.focusPrevious': focusPrevious,
3911
- 'Explorer.getActions': getActions,
3912
- 'Explorer.getKeyBindings': getKeyBindings,
3913
- 'Explorer.getMenuEntries': getMenuEntries,
3914
- 'Explorer.getVirtualDom': getExplorerVirtualDom,
3915
- 'Explorer.getVisibleItems': getVisibleExplorerItems,
3916
- 'Explorer.handleArrowLeft': handleArrowLeft,
3917
- 'Explorer.handleArrowRight': handleArrowRight,
3918
- 'Explorer.handleBlur': handleBlur,
3919
- 'Explorer.handleClick': handleClick,
3920
- 'Explorer.handleClickAt': handleClickAt,
3921
- 'Explorer.handleClickCurrentButKeepFocus': handleClickCurrentButKeepFocus,
3922
- 'Explorer.handleClickOpenFolder': handleClickOpenFolder,
3923
- 'Explorer.handleContextMenu': handleContextMenu,
3924
- 'Explorer.handleCopy': handleCopy,
3925
- 'Explorer.handleDragOver': handleDragOver,
3926
- 'Explorer.handleDrop': handleDrop,
3927
- 'Explorer.handleFocus': handleFocus,
3928
- 'Explorer.handleIconThemeChange': handleIconThemeChange,
3929
- 'Explorer.handlePaste': handlePaste,
3930
- 'Explorer.handlePointerDown': handlePointerDown,
3931
- 'Explorer.handleUpload': handleUpload,
3932
- 'Explorer.handleWheel': handleWheel,
3933
- 'Explorer.handleWorkspaceChange': handleWorkspaceChange,
3934
- 'Explorer.loadContent': loadContent,
3935
- 'Explorer.newFile': newFile,
3936
- 'Explorer.newFolder': newFolder,
3937
- 'Explorer.openContainingFolder': openContainingFolder,
3938
- 'Explorer.removeDirent': removeDirent,
3939
- 'Explorer.renameDirent': renameDirent,
4017
+ 'Explorer.acceptEdit': wrapCommand(acceptEdit),
4018
+ 'Explorer.cancelEdit': wrapCommand(cancelEdit),
4019
+ 'Explorer.collapseAll': wrapCommand(collapseAll$1),
4020
+ 'Explorer.copyPath': wrapCommand(copyPath$1),
4021
+ 'Explorer.copyRelativePath': wrapCommand(copyRelativePath$1),
4022
+ 'Explorer.expandAll': wrapCommand(expandAll),
4023
+ 'Explorer.expandRecursively': wrapCommand(expandRecursively),
4024
+ 'Explorer.focusFirst': wrapCommand(focusFirst),
4025
+ 'Explorer.focusIndex': wrapCommand(focusIndex),
4026
+ 'Explorer.focusLast': wrapCommand(focusLast),
4027
+ 'Explorer.focusNext': wrapCommand(focusNext),
4028
+ 'Explorer.focusPrevious': wrapCommand(focusPrevious),
4029
+ 'Explorer.getActions': wrapCommand(getActions),
4030
+ 'Explorer.getKeyBindings': wrapCommand(getKeyBindings),
4031
+ 'Explorer.getMenuEntries': wrapCommand(getMenuEntries),
4032
+ 'Explorer.getVirtualDom': wrapCommand(getExplorerVirtualDom),
4033
+ 'Explorer.getVisibleItems': wrapCommand(getVisibleExplorerItems),
4034
+ 'Explorer.handleArrowLeft': wrapCommand(handleArrowLeft),
4035
+ 'Explorer.handleArrowRight': wrapCommand(handleArrowRight),
4036
+ 'Explorer.handleBlur': wrapCommand(handleBlur),
4037
+ 'Explorer.handleClick': wrapCommand(handleClick),
4038
+ 'Explorer.handleClickAt': wrapCommand(handleClickAt),
4039
+ 'Explorer.handleClickCurrentButKeepFocus': wrapCommand(handleClickCurrentButKeepFocus),
4040
+ 'Explorer.handleClickOpenFolder': wrapCommand(handleClickOpenFolder),
4041
+ 'Explorer.handleContextMenu': wrapCommand(handleContextMenu),
4042
+ 'Explorer.handleCopy': wrapCommand(handleCopy),
4043
+ 'Explorer.handleDragOver': wrapCommand(handleDragOver),
4044
+ 'Explorer.handleDrop': wrapCommand(handleDrop),
4045
+ 'Explorer.handleFocus': wrapCommand(handleFocus),
4046
+ 'Explorer.handleIconThemeChange': wrapCommand(handleIconThemeChange),
4047
+ 'Explorer.handlePaste': wrapCommand(handlePaste),
4048
+ 'Explorer.handlePointerDown': wrapCommand(handlePointerDown),
4049
+ 'Explorer.handleUpload': wrapCommand(handleUpload),
4050
+ 'Explorer.handleWheel': wrapCommand(handleWheel),
4051
+ 'Explorer.handleWorkspaceChange': wrapCommand(handleWorkspaceChange),
4052
+ 'Explorer.loadContent': wrapCommand(loadContent),
4053
+ 'Explorer.newFile': wrapCommand(newFile),
4054
+ 'Explorer.newFolder': wrapCommand(newFolder),
4055
+ 'Explorer.openContainingFolder': wrapCommand(openContainingFolder),
4056
+ 'Explorer.removeDirent': wrapCommand(removeDirent),
4057
+ 'Explorer.renameDirent': wrapCommand(renameDirent),
4058
+ 'Explorer.restoreState': wrapCommand(restoreState),
4059
+ 'Explorer.revealItem': wrapCommand(revealItem),
4060
+ 'Explorer.setDeltaY': wrapCommand(setDeltaY),
4061
+ 'Explorer.terminate': wrapCommand(terminate),
4062
+ 'Explorer.updateEditingValue': wrapCommand(updateEditingValue),
4063
+ 'Explorer.updateIcons': wrapCommand(updateIcons),
4064
+ // not wrapped
4065
+ 'Explorer.create': create,
3940
4066
  'Explorer.render': doRender,
3941
4067
  'Explorer.renderActions': renderActions,
3942
- 'Explorer.restoreState': restoreState,
3943
- 'Explorer.revealItem': revealItem,
3944
- 'Explorer.saveState': saveState,
3945
- 'Explorer.setDeltaY': setDeltaY,
3946
- 'Explorer.terminate': terminate,
3947
- 'Explorer.updateEditingValue': updateEditingValue,
3948
- 'Explorer.updateIcons': updateIcons
4068
+ 'Explorer.saveState': saveState
3949
4069
  };
3950
4070
 
3951
4071
  const listen = async () => {
3952
4072
  const rpc = await WebWorkerRpcClient.create({
3953
4073
  commandMap: commandMap
3954
4074
  });
3955
- set(RendererWorker, rpc);
4075
+ set$1(RendererWorker, rpc);
3956
4076
  };
3957
4077
 
3958
4078
  const main = async () => {
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "1.18.0",
3
+ "version": "1.20.0",
4
4
  "description": "Explorer Worker",
5
- "main": "dist/explorerViewWorkerMain.js",
6
- "type": "module",
7
5
  "keywords": [],
8
- "author": "Lvce Editor",
9
- "license": "MIT",
10
6
  "repository": {
11
7
  "type": "git",
12
8
  "url": "git+https://github.com/lvce-editor/explorer-view.git"
13
- }
9
+ },
10
+ "license": "MIT",
11
+ "author": "Lvce Editor",
12
+ "type": "module",
13
+ "main": "dist/explorerViewWorkerMain.js"
14
14
  }