@lvce-editor/explorer-view 2.45.0 → 2.47.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.
@@ -431,7 +431,7 @@ const create$4 = (method, params) => {
431
431
  };
432
432
  };
433
433
  const callbacks = Object.create(null);
434
- const set$2 = (id, fn) => {
434
+ const set$3 = (id, fn) => {
435
435
  callbacks[id] = fn;
436
436
  };
437
437
  const get$2 = id => {
@@ -450,7 +450,7 @@ const registerPromise = () => {
450
450
  resolve,
451
451
  promise
452
452
  } = Promise.withResolvers();
453
- set$2(id, resolve);
453
+ set$3(id, resolve);
454
454
  return {
455
455
  id,
456
456
  promise
@@ -523,6 +523,16 @@ const constructError = (message, type, name) => {
523
523
  }
524
524
  return new ErrorConstructor(message);
525
525
  };
526
+ const joinLines = lines => {
527
+ return lines.join(NewLine);
528
+ };
529
+ const splitLines = lines => {
530
+ return lines.split(NewLine);
531
+ };
532
+ const getCurrentStack = () => {
533
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(2));
534
+ return currentStack;
535
+ };
526
536
  const getNewLineIndex = (string, startIndex = undefined) => {
527
537
  return string.indexOf(NewLine, startIndex);
528
538
  };
@@ -533,19 +543,16 @@ const getParentStack = error => {
533
543
  }
534
544
  return parentStack;
535
545
  };
536
- const joinLines = lines => {
537
- return lines.join(NewLine);
538
- };
539
546
  const MethodNotFound = -32601;
540
547
  const Custom = -32001;
541
- const splitLines = lines => {
542
- return lines.split(NewLine);
543
- };
544
548
  const restoreJsonRpcError = error => {
549
+ const currentStack = getCurrentStack();
545
550
  if (error && error instanceof Error) {
551
+ if (typeof error.stack === 'string') {
552
+ error.stack = error.stack + NewLine + currentStack;
553
+ }
546
554
  return error;
547
555
  }
548
- const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
549
556
  if (error && error.code && error.code === MethodNotFound) {
550
557
  const restoredError = new JsonRpcError(error.message);
551
558
  const parentStack = getParentStack(error);
@@ -626,6 +633,17 @@ const getErrorType = prettyError => {
626
633
  }
627
634
  return undefined;
628
635
  };
636
+ const isAlreadyStack = line => {
637
+ return line.trim().startsWith('at ');
638
+ };
639
+ const getStack = prettyError => {
640
+ const stackString = prettyError.stack || '';
641
+ const newLineIndex = stackString.indexOf('\n');
642
+ if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
643
+ return stackString.slice(newLineIndex + 1);
644
+ }
645
+ return stackString;
646
+ };
629
647
  const getErrorProperty = (error, prettyError) => {
630
648
  if (error && error.code === E_COMMAND_NOT_FOUND) {
631
649
  return {
@@ -638,7 +656,7 @@ const getErrorProperty = (error, prettyError) => {
638
656
  code: Custom,
639
657
  message: prettyError.message,
640
658
  data: {
641
- stack: prettyError.stack,
659
+ stack: getStack(prettyError),
642
660
  codeFrame: prettyError.codeFrame,
643
661
  type: getErrorType(prettyError),
644
662
  code: prettyError.code,
@@ -761,7 +779,7 @@ const send = (transport, method, ...params) => {
761
779
  const message = create$4(method, params);
762
780
  transport.send(message);
763
781
  };
764
- const invoke$2 = (ipc, method, ...params) => {
782
+ const invoke$3 = (ipc, method, ...params) => {
765
783
  return invokeHelper(ipc, method, params, false);
766
784
  };
767
785
  const invokeAndTransfer = (ipc, method, ...params) => {
@@ -794,7 +812,7 @@ const createRpc = ipc => {
794
812
  send(ipc, method, ...params);
795
813
  },
796
814
  invoke(method, ...params) {
797
- return invoke$2(ipc, method, ...params);
815
+ return invoke$3(ipc, method, ...params);
798
816
  },
799
817
  invokeAndTransfer(method, ...params) {
800
818
  return invokeAndTransfer(ipc, method, ...params);
@@ -850,8 +868,13 @@ const WebWorkerRpcClient = {
850
868
  create: create$3
851
869
  };
852
870
 
871
+ const CreateFolder$1 = 'createFolder'; // TODO use number
872
+ const CreateFile$1 = 'createFile'; // TODO use number
873
+ const Copy$2 = 'copy'; // TODO use number
874
+ const Rename$2 = 'rename'; // TODO use number
875
+
853
876
  const rpcs = Object.create(null);
854
- const set$9 = (id, rpc) => {
877
+ const set$b = (id, rpc) => {
855
878
  rpcs[id] = rpc;
856
879
  };
857
880
  const get$1 = id => {
@@ -875,19 +898,19 @@ const create$2 = rpcId => {
875
898
  return rpc.invokeAndTransfer(method, ...params);
876
899
  },
877
900
  set(rpc) {
878
- set$9(rpcId, rpc);
901
+ set$b(rpcId, rpc);
879
902
  }
880
903
  };
881
904
  };
882
905
  const RendererWorker$1 = 1;
883
906
  const {
884
- invoke: invoke$4,
885
- set: set$4
907
+ invoke: invoke$2,
908
+ set: set$2
886
909
  } = create$2(RendererWorker$1);
887
910
  const RendererWorker = {
888
911
  __proto__: null,
889
- invoke: invoke$4,
890
- set: set$4
912
+ invoke: invoke$2,
913
+ set: set$2
891
914
  };
892
915
 
893
916
  const {
@@ -914,9 +937,6 @@ const getRealPath = async path => {
914
937
  const stat = async dirent => {
915
938
  return invoke('FileSystem.stat', dirent);
916
939
  };
917
- const createFile = async uri => {
918
- return invoke('FileSystem.writeFile', uri, '');
919
- };
920
940
  const writeFile = async (uri, content) => {
921
941
  return invoke('FileSystem.writeFile', uri, content);
922
942
  };
@@ -930,20 +950,29 @@ const copy$1 = async (oldUri, newUri) => {
930
950
  return invoke('FileSystem.copy', oldUri, newUri);
931
951
  };
932
952
 
933
- const createNestedPath = async (root, path, pathSeparator) => {
934
- const parts = path.slice(root.length).split(pathSeparator);
935
- let currentPath = '';
936
- for (const part of parts) {
937
- if (!part) continue;
938
- currentPath = currentPath ? `${currentPath}${pathSeparator}${part}` : part;
939
- try {
940
- await mkdir(`${root}${currentPath}`);
941
- } catch (error) {
942
- // Ignore error if directory already exists
943
- if (!(error instanceof Error && error.message.includes('already exists'))) {
944
- throw error;
945
- }
953
+ const applyOperation = operation => {
954
+ if (operation.type === CreateFolder$1) {
955
+ return mkdir(operation.path);
956
+ }
957
+ if (operation.type === Copy$2) {
958
+ return copy$1(operation.from || '', operation.path);
959
+ }
960
+ if (operation.type === Rename$2) {
961
+ return rename$1(operation.from || '', operation.path);
962
+ }
963
+ return writeFile(operation.path, operation.text);
964
+ };
965
+
966
+ const applyFileOperations = async operations => {
967
+ try {
968
+ // TODO run operations in parallel if possible
969
+ for (const operation of operations) {
970
+ await applyOperation(operation);
946
971
  }
972
+ return '';
973
+ } catch (error) {
974
+ console.error(new VError(error, `Failed to apply file operations`));
975
+ return `${error}`;
947
976
  }
948
977
  };
949
978
 
@@ -970,21 +999,6 @@ const join2 = (path, childPath) => {
970
999
  return `${path}/${childPath}`;
971
1000
  };
972
1001
 
973
- const createNewDirentsAccept = async (newFileName, pathSeparator, absolutePath, root, createFn) => {
974
- try {
975
- // Create parent directories if they don't exist
976
- if (newFileName.includes(pathSeparator)) {
977
- const parentPath = dirname(pathSeparator, absolutePath);
978
- await createNestedPath(root, parentPath, pathSeparator);
979
- }
980
- await createFn(absolutePath);
981
- return '';
982
- } catch (error) {
983
- console.error(new VError(error, `Failed to create file`));
984
- return `${error}`;
985
- }
986
- };
987
-
988
1002
  const createTree = (items, root) => {
989
1003
  const tree = Object.create(null);
990
1004
  const rootLength = root.length;
@@ -1112,6 +1126,41 @@ const getFileIcons = async (dirents, fileIconCache) => {
1112
1126
  };
1113
1127
  };
1114
1128
 
1129
+ const getFileOperationsNestedPath = (path, root, pathSeparator) => {
1130
+ const parts = path.slice(root.length).split(pathSeparator);
1131
+ const operations = [];
1132
+ let currentPath = '';
1133
+ for (const part of parts) {
1134
+ if (!part) continue;
1135
+ currentPath = currentPath ? `${currentPath}${pathSeparator}${part}` : part;
1136
+ operations.push({
1137
+ type: CreateFolder$1,
1138
+ path: `${root}${currentPath}`,
1139
+ text: ''
1140
+ });
1141
+ }
1142
+ return operations;
1143
+ };
1144
+ const getFileOperationsCreate = (newFileName, newDirentType, pathSeparator, absolutePath, root) => {
1145
+ const operations = [];
1146
+ const parentPath = dirname(pathSeparator, absolutePath);
1147
+ operations.push(...getFileOperationsNestedPath(parentPath, root, pathSeparator));
1148
+ if (newDirentType === File) {
1149
+ operations.push({
1150
+ type: CreateFile$1,
1151
+ path: absolutePath,
1152
+ text: ''
1153
+ });
1154
+ } else if (newDirentType === Directory) {
1155
+ operations.push({
1156
+ type: CreateFolder$1,
1157
+ path: absolutePath,
1158
+ text: ''
1159
+ });
1160
+ }
1161
+ return operations;
1162
+ };
1163
+
1115
1164
  const getIndex = (dirents, uri) => {
1116
1165
  for (let i = 0; i < dirents.length; i++) {
1117
1166
  const dirent = dirents[i];
@@ -1481,7 +1530,8 @@ const acceptCreate = async (state, newDirentType, createFn) => {
1481
1530
  }
1482
1531
  const parentFolder = getParentFolder(items, focusedIndex, root);
1483
1532
  const absolutePath = join2(parentFolder, newFileName);
1484
- const createErrorMessage = await createNewDirentsAccept(newFileName, pathSeparator, absolutePath, root, createFn);
1533
+ const operations = getFileOperationsCreate(editingValue, newDirentType, pathSeparator, absolutePath, root);
1534
+ const createErrorMessage = await applyFileOperations(operations);
1485
1535
  if (createErrorMessage) {
1486
1536
  return {
1487
1537
  ...state,
@@ -1516,11 +1566,11 @@ const acceptCreate = async (state, newDirentType, createFn) => {
1516
1566
  };
1517
1567
 
1518
1568
  const acceptCreateFile = async state => {
1519
- return acceptCreate(state, File, createFile);
1569
+ return acceptCreate(state, File);
1520
1570
  };
1521
1571
 
1522
1572
  const acceptCreateFolder = async state => {
1523
- return acceptCreate(state, Directory, mkdir);
1573
+ return acceptCreate(state, Directory);
1524
1574
  };
1525
1575
 
1526
1576
  const computeExplorerRenamedDirentUpdate = (root, parentPath, oldUri, children, tree, newUri) => {
@@ -1550,9 +1600,9 @@ const createNewDirentsRename = async (renamedDirent, editingValue, pathSeparator
1550
1600
  await rename$1(oldAbsolutePath, newAbsolutePath);
1551
1601
  } catch (error) {
1552
1602
  console.error(new VError(error, `Failed to rename file`));
1553
- return false;
1603
+ return `${error}`;
1554
1604
  }
1555
- return true;
1605
+ return '';
1556
1606
  };
1557
1607
 
1558
1608
  const updateTree2 = (tree, update) => {
@@ -1582,9 +1632,12 @@ const acceptRename = async state => {
1582
1632
  };
1583
1633
  }
1584
1634
  const renamedDirent = items[editingIndex];
1585
- const successful = await createNewDirentsRename(renamedDirent, editingValue);
1586
- if (!successful) {
1587
- return state;
1635
+ const renameErrorMessage = await createNewDirentsRename(renamedDirent, editingValue);
1636
+ if (renameErrorMessage) {
1637
+ return {
1638
+ ...state,
1639
+ editingErrorMessage: renameErrorMessage
1640
+ };
1588
1641
  }
1589
1642
  const oldUri = renamedDirent.path;
1590
1643
  const dirname = dirname2(oldUri);
@@ -3209,23 +3262,6 @@ const refresh = async state => {
3209
3262
  };
3210
3263
  };
3211
3264
 
3212
- const applyOperation = operation => {
3213
- if (operation.type === 'createFolder') {
3214
- return mkdir(operation.path);
3215
- }
3216
- if (operation.type === 'copy') {
3217
- return copy$1(operation.from || '', operation.path);
3218
- }
3219
- return writeFile(operation.path, operation.text);
3220
- };
3221
-
3222
- const applyFileOperations = async operations => {
3223
- // TODO run operations in parallel if possible
3224
- for (const operation of operations) {
3225
- await applyOperation(operation);
3226
- }
3227
- };
3228
-
3229
3265
  const getChildHandles = async fileHandle => {
3230
3266
  // @ts-ignore
3231
3267
  const values = fileHandle.values();
@@ -3272,14 +3308,14 @@ const getFileOperations = (root, uploadTree) => {
3272
3308
  const fullPath = currentPath ? join2(currentPath, path) : path;
3273
3309
  if (typeof value === 'object') {
3274
3310
  operations.push({
3275
- type: 'createFolder',
3311
+ type: CreateFolder$1,
3276
3312
  path: join2(root, fullPath),
3277
3313
  text: ''
3278
3314
  });
3279
3315
  processTree(value, fullPath);
3280
3316
  } else if (typeof value === 'string') {
3281
3317
  operations.push({
3282
- type: 'createFile',
3318
+ type: CreateFile$1,
3283
3319
  path: join2(root, fullPath),
3284
3320
  text: value
3285
3321
  });
@@ -4300,6 +4336,11 @@ const getErrorMessagePosition = (itemHeight, focusedIndex, minLineY, depth, inde
4300
4336
  };
4301
4337
  };
4302
4338
 
4339
+ const None$2 = 'none';
4340
+ const ToolBar = 'toolbar';
4341
+ const Tree = 'tree';
4342
+ const TreeItem$1 = 'treeitem';
4343
+
4303
4344
  const Actions = 'Actions';
4304
4345
  const Button$2 = 'Button';
4305
4346
  const ButtonNarrow = 'ButtonNarrow';
@@ -4322,7 +4363,7 @@ const MaskIconChevronRight = 'MaskIconChevronRight';
4322
4363
  const ScrollBar = 'ScrollBar';
4323
4364
  const ScrollBarSmall = 'ScrollBarSmall';
4324
4365
  const ScrollBarThumb = 'ScrollBarThumb';
4325
- const TreeItem$1 = 'TreeItem';
4366
+ const TreeItem = 'TreeItem';
4326
4367
  const TreeItemActive = 'TreeItemActive';
4327
4368
  const Viewlet = 'Viewlet';
4328
4369
  const Welcome = 'Welcome';
@@ -4413,11 +4454,6 @@ const getExplorerWelcomeVirtualDom = isWide => {
4413
4454
  }, text(openFolder$1())];
4414
4455
  };
4415
4456
 
4416
- const None$2 = 'none';
4417
- const ToolBar = 'toolbar';
4418
- const Tree = 'tree';
4419
- const TreeItem = 'treeitem';
4420
-
4421
4457
  const chevronDownVirtualDom = {
4422
4458
  type: Div,
4423
4459
  className: mergeClassNames(Chevron, MaskIconChevronDown),
@@ -4505,7 +4541,7 @@ const getExplorerItemVirtualDom = item => {
4505
4541
  const chevronDom = getChevronVirtualDom(chevron);
4506
4542
  return [{
4507
4543
  type: Div,
4508
- role: TreeItem,
4544
+ role: TreeItem$1,
4509
4545
  className,
4510
4546
  draggable: true,
4511
4547
  title: path,
@@ -4563,6 +4599,11 @@ const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
4563
4599
  return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
4564
4600
  };
4565
4601
 
4602
+ const getScrollBarTop = (height, contentHeight, scrollTop) => {
4603
+ const scrollBarTop = Math.round(scrollTop / contentHeight * height);
4604
+ return scrollBarTop;
4605
+ };
4606
+
4566
4607
  const getScrollBarVirtualDom = (scrollBarHeight, scrollBarTop) => {
4567
4608
  const shouldShowScrollbar = scrollBarHeight > 0;
4568
4609
  if (!shouldShowScrollbar) {
@@ -4598,7 +4639,7 @@ const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused
4598
4639
  return getExplorerWelcomeVirtualDom(isWide);
4599
4640
  }
4600
4641
  const scrollBarHeight = getScrollBarSize(height, contentHeight, 20);
4601
- const scrollBarTop = Math.round(scrollTop / contentHeight * height);
4642
+ const scrollBarTop = getScrollBarTop(height, contentHeight, scrollTop);
4602
4643
  const scrollBarDom = getScrollBarVirtualDom(scrollBarHeight, scrollBarTop);
4603
4644
  const errorDom = getErrorMessageDom(errorMessage, errorMessageLeft, errorMessageTop);
4604
4645
  const childCount = getChildCount(scrollBarDom.length, errorDom.length);
@@ -4606,7 +4647,7 @@ const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused
4606
4647
  type: Div,
4607
4648
  childCount,
4608
4649
  className: mergeClassNames(Viewlet, Explorer),
4609
- role: 'none'
4650
+ role: None$2
4610
4651
  };
4611
4652
  const dom = [parentNode, ...getListItemsVirtualDom(visibleItems, focusedIndex, focused, dropTargets), ...scrollBarDom, ...errorDom];
4612
4653
  return dom;
@@ -4647,8 +4688,8 @@ const getExpandedType = type => {
4647
4688
  }
4648
4689
  };
4649
4690
 
4650
- const focused = mergeClassNames(TreeItem$1, TreeItemActive);
4651
- const selected = mergeClassNames(TreeItem$1, TreeItemActive);
4691
+ const focused = mergeClassNames(TreeItem, TreeItemActive);
4692
+ const selected = mergeClassNames(TreeItem, TreeItemActive);
4652
4693
  const getTreeItemClassName = (isSelected, isFocused) => {
4653
4694
  if (isFocused) {
4654
4695
  return focused;
@@ -4656,7 +4697,7 @@ const getTreeItemClassName = (isSelected, isFocused) => {
4656
4697
  if (isSelected) {
4657
4698
  return selected;
4658
4699
  }
4659
- return TreeItem$1;
4700
+ return TreeItem;
4660
4701
  };
4661
4702
 
4662
4703
  const defaultIndent$1 = 1;
@@ -5151,7 +5192,7 @@ const selectDown = state => {
5151
5192
  }
5152
5193
  const newItems = items.map((item, i) => ({
5153
5194
  ...item,
5154
- selected: i === targetIndex + 1 ? true : item.selected
5195
+ selected: i === targetIndex + 1 ? true : item.selected || i === focusedIndex
5155
5196
  }));
5156
5197
  return {
5157
5198
  ...state,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.45.0",
3
+ "version": "2.47.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",