@lvce-editor/explorer-view 5.27.0 → 6.0.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.
@@ -2920,6 +2920,8 @@ const create = (id, uri, x, y, width, height, args, parentUid, platform = 0, ass
2920
2920
  editingSelectionStart: 0,
2921
2921
  editingType: None$5,
2922
2922
  editingValue: '',
2923
+ errorCode: '',
2924
+ errorMessage: '',
2923
2925
  errorMessageLeft: 0,
2924
2926
  errorMessageTop: 0,
2925
2927
  errorMessageWidth: 0,
@@ -2932,6 +2934,7 @@ const create = (id, uri, x, y, width, height, args, parentUid, platform = 0, ass
2932
2934
  focusWord: '',
2933
2935
  focusWordTimeout: 800,
2934
2936
  handleOffset: 0,
2937
+ hasError: false,
2935
2938
  height,
2936
2939
  hoverIndex: -1,
2937
2940
  icons: [],
@@ -2974,7 +2977,7 @@ const isEqual$6 = (oldState, newState) => {
2974
2977
  // TODO compute css more optimized
2975
2978
  // maybe only when items change, and even then not
2976
2979
  // always, but only when it affects the css
2977
- return oldState.deltaY === newState.deltaY && oldState.editingErrorMessage === newState.editingErrorMessage && oldState.errorMessageLeft === newState.errorMessageLeft && oldState.errorMessageTop === newState.errorMessageTop && oldState.maxIndent === newState.maxIndent && oldState.scrollBarActive === newState.scrollBarActive && oldState.scrollBarHeight === newState.scrollBarHeight && oldState.visibleExplorerItems === newState.visibleExplorerItems && oldState.width === newState.width;
2980
+ return oldState.deltaY === newState.deltaY && oldState.editingErrorMessage === newState.editingErrorMessage && oldState.hasError === newState.hasError && oldState.errorMessage === newState.errorMessage && oldState.errorCode === newState.errorCode && oldState.errorMessageLeft === newState.errorMessageLeft && oldState.errorMessageTop === newState.errorMessageTop && oldState.maxIndent === newState.maxIndent && oldState.scrollBarActive === newState.scrollBarActive && oldState.scrollBarHeight === newState.scrollBarHeight && oldState.visibleExplorerItems === newState.visibleExplorerItems && oldState.width === newState.width;
2978
2981
  };
2979
2982
 
2980
2983
  const isEqual$5 = (oldState, newState) => {
@@ -2986,7 +2989,7 @@ const isEqual$4 = (oldState, newState) => {
2986
2989
  };
2987
2990
 
2988
2991
  const isEqual$3 = (oldState, newState) => {
2989
- 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.editingErrorMessage === newState.editingErrorMessage && oldState.width === newState.width && oldState.focused === newState.focused && oldState.dropTargets === newState.dropTargets && oldState.icons === newState.icons && oldState.cutItems === newState.cutItems && oldState.visibleExplorerItems === newState.visibleExplorerItems;
2992
+ 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.editingErrorMessage === newState.editingErrorMessage && oldState.hasError === newState.hasError && oldState.errorMessage === newState.errorMessage && oldState.errorCode === newState.errorCode && oldState.width === newState.width && oldState.focused === newState.focused && oldState.dropTargets === newState.dropTargets && oldState.icons === newState.icons && oldState.cutItems === newState.cutItems && oldState.visibleExplorerItems === newState.visibleExplorerItems;
2990
2993
  };
2991
2994
 
2992
2995
  const isEqual$2 = (oldState, newState) => {
@@ -5327,6 +5330,36 @@ const getExcluded = () => {
5327
5330
  const getSavedRoot = (savedState, workspacePath) => {
5328
5331
  return workspacePath;
5329
5332
  };
5333
+ const getErrorCode = error => {
5334
+ if (error && typeof error === 'object' && 'code' in error && typeof error.code === 'string') {
5335
+ return error.code;
5336
+ }
5337
+ return '';
5338
+ };
5339
+ const getErrorMessage = error => {
5340
+ if (error instanceof Error) {
5341
+ return error.message;
5342
+ }
5343
+ if (typeof error === 'string') {
5344
+ return error;
5345
+ }
5346
+ return 'Unknown error';
5347
+ };
5348
+ const getFriendlyErrorMessage = (errorMessage, errorCode) => {
5349
+ switch (errorCode) {
5350
+ case 'EACCES':
5351
+ case 'EPERM':
5352
+ return 'permission was denied';
5353
+ case 'EBUSY':
5354
+ return 'the folder is currently in use';
5355
+ case 'ENOENT':
5356
+ return 'the folder does not exist';
5357
+ case 'ENOTDIR':
5358
+ return 'the path is not a folder';
5359
+ default:
5360
+ return errorMessage || 'an unexpected error occurred';
5361
+ }
5362
+ };
5330
5363
  const loadContent = async (state, savedState) => {
5331
5364
  const {
5332
5365
  assetDir,
@@ -5339,34 +5372,53 @@ const loadContent = async (state, savedState) => {
5339
5372
  } = await getSettings();
5340
5373
  const workspacePath = await getWorkspacePath();
5341
5374
  const root = getSavedRoot(savedState, workspacePath);
5342
- // TODO path separator could be restored from saved state
5343
- const pathSeparator = await getPathSeparator(root); // TODO only load path separator once
5344
- const excluded = getExcluded();
5345
- const restoredDirents = await restoreExpandedState(savedState, root, pathSeparator, excluded);
5346
- let minLineY = 0;
5347
- if (savedState && typeof savedState.minLineY === 'number') {
5348
- minLineY = savedState.minLineY;
5349
- }
5350
- let deltaY = 0;
5351
- if (savedState && typeof savedState.deltaY === 'number') {
5352
- deltaY = savedState.deltaY;
5353
- }
5354
- const scheme = getScheme(root);
5355
- const decorations = await getFileDecorations(scheme, root, restoredDirents.filter(item => item.depth === 1).map(item => item.path), sourceControlDecorations, assetDir, platform);
5356
- return {
5357
- ...state,
5358
- confirmDelete,
5359
- decorations,
5360
- deltaY,
5361
- excluded,
5362
- initial: true,
5363
- items: restoredDirents,
5364
- maxIndent: 10,
5365
- minLineY,
5366
- pathSeparator,
5367
- root,
5368
- useChevrons
5369
- };
5375
+ try {
5376
+ // TODO path separator could be restored from saved state
5377
+ const pathSeparator = await getPathSeparator(root); // TODO only load path separator once
5378
+ const excluded = getExcluded();
5379
+ const restoredDirents = await restoreExpandedState(savedState, root, pathSeparator, excluded);
5380
+ let minLineY = 0;
5381
+ if (savedState && typeof savedState.minLineY === 'number') {
5382
+ minLineY = savedState.minLineY;
5383
+ }
5384
+ let deltaY = 0;
5385
+ if (savedState && typeof savedState.deltaY === 'number') {
5386
+ deltaY = savedState.deltaY;
5387
+ }
5388
+ const scheme = getScheme(root);
5389
+ const decorations = await getFileDecorations(scheme, root, restoredDirents.filter(item => item.depth === 1).map(item => item.path), sourceControlDecorations, assetDir, platform);
5390
+ return {
5391
+ ...state,
5392
+ confirmDelete,
5393
+ decorations,
5394
+ deltaY,
5395
+ errorCode: '',
5396
+ errorMessage: '',
5397
+ excluded,
5398
+ hasError: false,
5399
+ initial: true,
5400
+ items: restoredDirents,
5401
+ maxIndent: 10,
5402
+ minLineY,
5403
+ pathSeparator,
5404
+ root,
5405
+ useChevrons
5406
+ };
5407
+ } catch (error) {
5408
+ const errorCode = getErrorCode(error);
5409
+ const errorMessage = getFriendlyErrorMessage(getErrorMessage(error), errorCode);
5410
+ return {
5411
+ ...state,
5412
+ confirmDelete,
5413
+ errorCode,
5414
+ errorMessage,
5415
+ hasError: true,
5416
+ initial: true,
5417
+ items: [],
5418
+ root,
5419
+ useChevrons
5420
+ };
5421
+ }
5370
5422
  };
5371
5423
 
5372
5424
  const handleWorkspaceChange = async state => {
@@ -5593,7 +5645,6 @@ const renderCss = (oldState, newState) => {
5593
5645
  itemHeight,
5594
5646
  items,
5595
5647
  minLineY,
5596
- scrollBarHeight,
5597
5648
  uid,
5598
5649
  visibleExplorerItems,
5599
5650
  width
@@ -5601,6 +5652,7 @@ const renderCss = (oldState, newState) => {
5601
5652
  const uniqueIndents = getUniqueIndents(visibleExplorerItems);
5602
5653
  const contentHeight = items.length * itemHeight;
5603
5654
  const scrollBarTop = getScrollBarTop(height, contentHeight, deltaY);
5655
+ const scrollBarHeight = getScrollBarSize(height, contentHeight, 20);
5604
5656
  const indent = 8;
5605
5657
  const padding = 10;
5606
5658
  const fileIconWidth = 16;
@@ -5907,6 +5959,23 @@ const getListItemsVirtualDom = (visibleItems, focusedIndex, focused, dropTargets
5907
5959
  return dom;
5908
5960
  };
5909
5961
 
5962
+ const getParentNode$1 = childCount => {
5963
+ return {
5964
+ childCount,
5965
+ className: mergeClassNames(Viewlet, Explorer$1),
5966
+ role: None,
5967
+ type: Div
5968
+ };
5969
+ };
5970
+ const getLoadErrorVirtualDom = loadErrorMessage => {
5971
+ const errorDom = [{
5972
+ childCount: 1,
5973
+ type: Div
5974
+ }, text(loadErrorMessage)];
5975
+ const parentNode = getParentNode$1(1);
5976
+ return [parentNode, ...errorDom];
5977
+ };
5978
+
5910
5979
  const getScrollBarVirtualDom = scrollBarHeight => {
5911
5980
  const shouldShowScrollbar = scrollBarHeight > 0;
5912
5981
  if (!shouldShowScrollbar) {
@@ -5923,6 +5992,14 @@ const getScrollBarVirtualDom = scrollBarHeight => {
5923
5992
  }];
5924
5993
  };
5925
5994
 
5995
+ const getParentNode = childCount => {
5996
+ return {
5997
+ childCount,
5998
+ className: mergeClassNames(Viewlet, Explorer$1),
5999
+ role: None,
6000
+ type: Div
6001
+ };
6002
+ };
5926
6003
  const getChildCount = (scrollBarDomLength, errorDomLength) => {
5927
6004
  let childCount = 1;
5928
6005
  if (scrollBarDomLength > 0) {
@@ -5933,24 +6010,31 @@ const getChildCount = (scrollBarDomLength, errorDomLength) => {
5933
6010
  }
5934
6011
  return childCount;
5935
6012
  };
5936
- const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused, dropTargets, height, contentHeight, errorMessage) => {
6013
+ const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused, dropTargets, height, contentHeight, editingErrorMessage, loadErrorMessage) => {
5937
6014
  if (!root) {
5938
6015
  return getExplorerWelcomeVirtualDom(isWide);
5939
6016
  }
6017
+ if (loadErrorMessage) {
6018
+ return getLoadErrorVirtualDom(loadErrorMessage);
6019
+ }
5940
6020
  const scrollBarHeight = getScrollBarSize(height, contentHeight, 20);
5941
6021
  const scrollBarDom = getScrollBarVirtualDom(scrollBarHeight);
5942
- const errorDom = getErrorMessageDom(errorMessage);
6022
+ const errorDom = getErrorMessageDom(editingErrorMessage);
5943
6023
  const childCount = getChildCount(scrollBarDom.length, errorDom.length);
5944
- const parentNode = {
5945
- childCount,
5946
- className: mergeClassNames(Viewlet, Explorer$1),
5947
- role: None,
5948
- type: Div
5949
- };
6024
+ const parentNode = getParentNode(childCount);
5950
6025
  const dom = [parentNode, ...getListItemsVirtualDom(visibleItems, focusedIndex, focused, dropTargets), ...scrollBarDom, ...errorDom];
5951
6026
  return dom;
5952
6027
  };
5953
6028
 
6029
+ const getLoadErrorMessage = state => {
6030
+ if (state.hasError) {
6031
+ const code = state.errorCode ? ` (error code: ${state.errorCode})` : '';
6032
+ const reason = state.errorMessage || 'an unexpected error occurred';
6033
+ return `Could not open folder due to ${reason}${code}.`;
6034
+ }
6035
+ return '';
6036
+ };
6037
+
5954
6038
  const renderItems = (oldState, newState) => {
5955
6039
  const {
5956
6040
  dropTargets,
@@ -5966,7 +6050,8 @@ const renderItems = (oldState, newState) => {
5966
6050
  const visibleDirents = newState.visibleExplorerItems;
5967
6051
  const isWide = width > 450;
5968
6052
  const contentHeight = items.length * itemHeight;
5969
- const dom = getExplorerVirtualDom(visibleDirents, focusedIndex, root, isWide, focused, dropTargets, height, contentHeight, editingErrorMessage);
6053
+ const loadErrorMessage = getLoadErrorMessage(newState);
6054
+ const dom = getExplorerVirtualDom(visibleDirents, focusedIndex, root, isWide, focused, dropTargets, height, contentHeight, editingErrorMessage, loadErrorMessage);
5970
6055
  return [SetDom2, newState.uid, dom];
5971
6056
  };
5972
6057
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "5.27.0",
3
+ "version": "6.0.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",