@lvce-editor/explorer-view 1.18.0 → 1.19.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,54 @@ 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
+ const create = (id, uri, x, y, width, height, args, parentUid) => {
1304
+ const state = {
1305
+ uid: id,
1306
+ parentUid,
1307
+ root: '',
1308
+ items: [],
1309
+ focusedIndex: -1,
1310
+ focused: false,
1311
+ hoverIndex: -1,
1312
+ x,
1313
+ y,
1314
+ width,
1315
+ height,
1316
+ deltaY: 0,
1317
+ minLineY: 0,
1318
+ maxLineY: 0,
1319
+ pathSeparator: Slash,
1320
+ version: 0,
1321
+ editingIndex: -1,
1322
+ itemHeight: ListItem,
1323
+ dropTargets: [],
1324
+ excluded: [],
1325
+ editingValue: '',
1326
+ editingType: None$5,
1327
+ editingIcon: '',
1328
+ fileIconCache: Object.create(null),
1329
+ useChevrons: false,
1330
+ icons: []
1331
+ };
1332
+ set(state.uid, state, state);
1333
+ return state;
1334
+ };
1335
+
1286
1336
  const isSymbolicLink = dirent => {
1287
1337
  return dirent.type === Symlink;
1288
1338
  };
@@ -1474,7 +1524,9 @@ const expandAll = async state => {
1474
1524
  return state;
1475
1525
  }
1476
1526
  const dirent = items[focusedIndex];
1477
- const depth = dirent.depth;
1527
+ const {
1528
+ depth
1529
+ } = dirent;
1478
1530
  const newDirents = [...items];
1479
1531
  // TODO fetch child dirents in parallel
1480
1532
  for (const dirent of newDirents) {
@@ -1825,6 +1877,18 @@ const Viewlet = 'Viewlet';
1825
1877
  const Welcome = 'Welcome';
1826
1878
  const WelcomeMessage = 'WelcomeMessage';
1827
1879
 
1880
+ // TODO add option to make classnames numeric
1881
+ // once at start, send all classnames to renderer process
1882
+ // then, components uses numeric classname
1883
+ // when a component uses multiple classnames, it is a new number
1884
+ // representing the concatenated strings for example
1885
+ // 0 = 'Button'
1886
+ // 1 = 'IconButton'
1887
+ // 2 = 'Button IconButton'
1888
+ // it could make dom diffing faster, since for classname,
1889
+ // only numbers are compared. it could also make rendering faster,
1890
+ // since less data is transferred to renderer process
1891
+
1828
1892
  const HandleBlur = 'handleBlur';
1829
1893
  const HandleClick = 'handleClick';
1830
1894
  const handleClickOpenFolder$1 = 'handleClickOpenFolder';
@@ -2807,7 +2871,9 @@ const isEqual = (a, b) => {
2807
2871
  if (a.length !== b.length) {
2808
2872
  return false;
2809
2873
  }
2810
- const length = a.length;
2874
+ const {
2875
+ length
2876
+ } = a;
2811
2877
  for (let i = 0; i < length; i++) {
2812
2878
  if (a[i] !== b[i]) {
2813
2879
  return false;
@@ -3412,7 +3478,7 @@ const removeDirent = async state => {
3412
3478
  try {
3413
3479
  // TODO handle error
3414
3480
  await remove(absolutePath);
3415
- } catch (error) {
3481
+ } catch {
3416
3482
  // TODO vscode shows error as alert (no stacktrace) and retry button
3417
3483
  // maybe should show alert as well, but where to put stacktrace?
3418
3484
  // on web should probably show notification (dialog)
@@ -3482,7 +3548,7 @@ const renameDirent = state => {
3482
3548
 
3483
3549
  const renderItems = {
3484
3550
  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;
3551
+ 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
3552
  },
3487
3553
  apply(oldState, newState) {
3488
3554
  const visibleDirents = getVisibleExplorerItems(newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex, newState.editingIndex, newState.editingType, newState.editingValue, newState.icons, newState.useChevrons);
@@ -3522,7 +3588,23 @@ const renderEditingIndex = {
3522
3588
  }
3523
3589
  };
3524
3590
  const render = [renderItems, renderEditingIndex];
3525
- const doRender = (oldState, newState) => {
3591
+ const doRender = (uid, _) => {
3592
+ if (typeof uid === 'number') {
3593
+ const {
3594
+ oldState,
3595
+ newState
3596
+ } = get(uid);
3597
+ const commands = [];
3598
+ for (const fn of render) {
3599
+ if (!fn.isEqual(oldState, newState)) {
3600
+ commands.push(fn.apply(oldState, newState));
3601
+ }
3602
+ }
3603
+ return commands;
3604
+ }
3605
+ // deprecated
3606
+ const oldState = uid;
3607
+ const newState = _;
3526
3608
  const commands = [];
3527
3609
  for (const fn of render) {
3528
3610
  if (!fn.isEqual(oldState, newState)) {
@@ -3838,14 +3920,22 @@ const isExpandedDirectory = dirent => {
3838
3920
  return dirent.type === DirectoryExpanded;
3839
3921
  };
3840
3922
 
3841
- const saveState = state => {
3923
+ const saveState = uid => {
3924
+ let newState;
3925
+ if (typeof uid === 'number') {
3926
+ const value = get(uid);
3927
+ newState = value.newState;
3928
+ } else {
3929
+ // deprecated
3930
+ newState = uid;
3931
+ }
3842
3932
  const {
3843
3933
  items,
3844
3934
  root,
3845
3935
  deltaY,
3846
3936
  minLineY,
3847
3937
  maxLineY
3848
- } = state;
3938
+ } = newState;
3849
3939
  const expandedPaths = items.filter(isExpandedDirectory).map(getPath);
3850
3940
  return {
3851
3941
  expandedPaths,
@@ -3895,64 +3985,83 @@ const updateEditingValue = (state, value) => {
3895
3985
  };
3896
3986
  };
3897
3987
 
3988
+ const wrapCommand = fn => {
3989
+ const wrapped = async (uid, ...args) => {
3990
+ if (typeof uid === 'number') {
3991
+ const {
3992
+ newState
3993
+ } = get(uid);
3994
+ const newerState = await fn(newState, ...args);
3995
+ set(uid, newState, newerState);
3996
+ } else {
3997
+ // deprecated
3998
+ const newerState = await fn(uid, ...args);
3999
+ return newerState;
4000
+ }
4001
+ };
4002
+ return wrapped;
4003
+ };
4004
+
3898
4005
  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,
4006
+ 'Explorer.acceptEdit': wrapCommand(acceptEdit),
4007
+ 'Explorer.cancelEdit': wrapCommand(cancelEdit),
4008
+ 'Explorer.collapseAll': wrapCommand(collapseAll$1),
4009
+ 'Explorer.copyPath': wrapCommand(copyPath$1),
4010
+ 'Explorer.copyRelativePath': wrapCommand(copyRelativePath$1),
4011
+ 'Explorer.expandAll': wrapCommand(expandAll),
4012
+ 'Explorer.expandRecursively': wrapCommand(expandRecursively),
4013
+ 'Explorer.focusFirst': wrapCommand(focusFirst),
4014
+ 'Explorer.focusIndex': wrapCommand(focusIndex),
4015
+ 'Explorer.focusLast': wrapCommand(focusLast),
4016
+ 'Explorer.focusNext': wrapCommand(focusNext),
4017
+ 'Explorer.focusPrevious': wrapCommand(focusPrevious),
4018
+ 'Explorer.getActions': wrapCommand(getActions),
4019
+ 'Explorer.getKeyBindings': wrapCommand(getKeyBindings),
4020
+ 'Explorer.getMenuEntries': wrapCommand(getMenuEntries),
4021
+ 'Explorer.getVirtualDom': wrapCommand(getExplorerVirtualDom),
4022
+ 'Explorer.getVisibleItems': wrapCommand(getVisibleExplorerItems),
4023
+ 'Explorer.handleArrowLeft': wrapCommand(handleArrowLeft),
4024
+ 'Explorer.handleArrowRight': wrapCommand(handleArrowRight),
4025
+ 'Explorer.handleBlur': wrapCommand(handleBlur),
4026
+ 'Explorer.handleClick': wrapCommand(handleClick),
4027
+ 'Explorer.handleClickAt': wrapCommand(handleClickAt),
4028
+ 'Explorer.handleClickCurrentButKeepFocus': wrapCommand(handleClickCurrentButKeepFocus),
4029
+ 'Explorer.handleClickOpenFolder': wrapCommand(handleClickOpenFolder),
4030
+ 'Explorer.handleContextMenu': wrapCommand(handleContextMenu),
4031
+ 'Explorer.handleCopy': wrapCommand(handleCopy),
4032
+ 'Explorer.handleDragOver': wrapCommand(handleDragOver),
4033
+ 'Explorer.handleDrop': wrapCommand(handleDrop),
4034
+ 'Explorer.handleFocus': wrapCommand(handleFocus),
4035
+ 'Explorer.handleIconThemeChange': wrapCommand(handleIconThemeChange),
4036
+ 'Explorer.handlePaste': wrapCommand(handlePaste),
4037
+ 'Explorer.handlePointerDown': wrapCommand(handlePointerDown),
4038
+ 'Explorer.handleUpload': wrapCommand(handleUpload),
4039
+ 'Explorer.handleWheel': wrapCommand(handleWheel),
4040
+ 'Explorer.handleWorkspaceChange': wrapCommand(handleWorkspaceChange),
4041
+ 'Explorer.loadContent': wrapCommand(loadContent),
4042
+ 'Explorer.newFile': wrapCommand(newFile),
4043
+ 'Explorer.newFolder': wrapCommand(newFolder),
4044
+ 'Explorer.openContainingFolder': wrapCommand(openContainingFolder),
4045
+ 'Explorer.removeDirent': wrapCommand(removeDirent),
4046
+ 'Explorer.renameDirent': wrapCommand(renameDirent),
4047
+ 'Explorer.restoreState': wrapCommand(restoreState),
4048
+ 'Explorer.revealItem': wrapCommand(revealItem),
4049
+ 'Explorer.setDeltaY': wrapCommand(setDeltaY),
4050
+ 'Explorer.terminate': wrapCommand(terminate),
4051
+ 'Explorer.updateEditingValue': wrapCommand(updateEditingValue),
4052
+ 'Explorer.updateIcons': wrapCommand(updateIcons),
4053
+ // not wrapped
4054
+ 'Explorer.create': create,
3940
4055
  'Explorer.render': doRender,
3941
4056
  '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
4057
+ 'Explorer.saveState': saveState
3949
4058
  };
3950
4059
 
3951
4060
  const listen = async () => {
3952
4061
  const rpc = await WebWorkerRpcClient.create({
3953
4062
  commandMap: commandMap
3954
4063
  });
3955
- set(RendererWorker, rpc);
4064
+ set$1(RendererWorker, rpc);
3956
4065
  };
3957
4066
 
3958
4067
  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.19.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
  }