@lvce-editor/explorer-view 6.3.0 → 6.4.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.
@@ -936,6 +936,7 @@ const FileCannotStartWithBackSlash = 'A file or folder name cannot start with a
936
936
  const FilesExplorer = 'Files Explorer';
937
937
  const NewFile$2 = 'New File...';
938
938
  const NewFolder$2 = 'New Folder...';
939
+ const OpenAnotherFolder = 'Open another folder';
939
940
  const OpenContainingFolder = 'Open Containing Folder';
940
941
  const OpenFolder$1 = 'Open folder';
941
942
  const OpenInIntegratedTerminal = 'Open in integrated Terminal';
@@ -998,6 +999,9 @@ const youHaveNotYetOpenedAFolder = () => {
998
999
  const openFolder$1 = () => {
999
1000
  return i18nString(OpenFolder$1);
1000
1001
  };
1002
+ const openAnotherFolder = () => {
1003
+ return i18nString(OpenAnotherFolder);
1004
+ };
1001
1005
  const fileOrFolderNameMustBeProvided = () => {
1002
1006
  return i18nString(FileOrFolderNameMustBeProvider);
1003
1007
  };
@@ -1207,7 +1211,7 @@ const acceptEdit = async state => {
1207
1211
  };
1208
1212
 
1209
1213
  const getFocusedIndexCancel = (items, editingIndex) => {
1210
- const newFocusedIndex = editingIndex > items.length ? items.length - 1 : editingIndex;
1214
+ const newFocusedIndex = editingIndex >= items.length ? items.length - 1 : editingIndex;
1211
1215
  return newFocusedIndex;
1212
1216
  };
1213
1217
 
@@ -1346,12 +1350,25 @@ const writeNativeFiles = async (type, files) => {
1346
1350
  return invoke$2('ClipBoard.writeNativeFiles', type, files);
1347
1351
  };
1348
1352
 
1353
+ const getRelativePath = (root, pathSeparator, path) => {
1354
+ if (root && path.startsWith(root)) {
1355
+ const relativePath = path.slice(root.length);
1356
+ if (relativePath.startsWith(pathSeparator)) {
1357
+ return relativePath.slice(pathSeparator.length);
1358
+ }
1359
+ return relativePath;
1360
+ }
1361
+ if (path.startsWith(pathSeparator)) {
1362
+ return path.slice(pathSeparator.length);
1363
+ }
1364
+ return path;
1365
+ };
1349
1366
  const copyRelativePath = async state => {
1350
1367
  const dirent = getFocusedDirent$1(state);
1351
1368
  if (!dirent) {
1352
1369
  return state;
1353
1370
  }
1354
- const relativePath = dirent.path.slice(1);
1371
+ const relativePath = getRelativePath(state.root, state.pathSeparator, dirent.path);
1355
1372
  // TODO handle error
1356
1373
  await writeText(relativePath);
1357
1374
  return state;
@@ -2834,6 +2851,19 @@ const NewFolder$1 = 'NewFolder';
2834
2851
  const OpenFolder = 'OpenFolder';
2835
2852
  const Refresh$1 = 'Refresh';
2836
2853
 
2854
+ const isFolder = direntType => {
2855
+ return direntType === Directory || direntType === DirectoryExpanded || direntType === SymLinkFolder;
2856
+ };
2857
+ const getFittingIndex = (dirents, startIndex) => {
2858
+ for (let i = startIndex; i >= 0; i--) {
2859
+ const dirent = dirents[i];
2860
+ if (dirent && isFolder(dirent.type)) {
2861
+ return i;
2862
+ }
2863
+ }
2864
+ return -1;
2865
+ };
2866
+
2837
2867
  const getNewChildDirentsForNewDirent = async (items, depth, parentPath, direntType) => {
2838
2868
  // Get existing children or query them if they don't exist
2839
2869
  let existingChildren = items.filter(item => item.depth === depth && item.path.startsWith(parentPath));
@@ -2921,18 +2951,6 @@ const getNewDirentType = editingType => {
2921
2951
  }
2922
2952
  };
2923
2953
 
2924
- const isFolder = direntType => {
2925
- return direntType === Directory || direntType === DirectoryExpanded || direntType === SymLinkFolder;
2926
- };
2927
- const getFittingIndex = (dirents, startIndex) => {
2928
- for (let i = startIndex; i >= 0; i--) {
2929
- const dirent = dirents[i];
2930
- if (isFolder(dirent.type)) {
2931
- return i;
2932
- }
2933
- }
2934
- return -1;
2935
- };
2936
2954
  const newDirent = async (state, editingType) => {
2937
2955
  // TODO do it like vscode, select position between folders and files
2938
2956
  const {
@@ -5084,6 +5102,12 @@ const getLabelDom = (isEditing, name, isDimmed) => {
5084
5102
  return [label, text(name)];
5085
5103
  };
5086
5104
 
5105
+ const getTitle = path => {
5106
+ if (path.startsWith('file://')) {
5107
+ return path.slice('file://'.length);
5108
+ }
5109
+ return path;
5110
+ };
5087
5111
  const getExplorerItemVirtualDom = item => {
5088
5112
  const {
5089
5113
  ariaExpanded,
@@ -5116,7 +5140,7 @@ const getExplorerItemVirtualDom = item => {
5116
5140
  draggable: true,
5117
5141
  id,
5118
5142
  role: TreeItem,
5119
- title: path,
5143
+ title: getTitle(path),
5120
5144
  type: Div
5121
5145
  }, ...chevronDom, getFileIconVirtualDom(icon), ...getInputDom(isEditing, hasEditingError), ...getLabelDom(isEditing, name, isCut || isIgnored)];
5122
5146
  };
@@ -5167,13 +5191,26 @@ const getParentNode$1 = childCount => {
5167
5191
  type: Div
5168
5192
  };
5169
5193
  };
5170
- const getLoadErrorVirtualDom = loadErrorMessage => {
5194
+ const getLoadErrorVirtualDom = (loadErrorMessage, isWide, showOpenAnotherFolderButton) => {
5195
+ const childCount = showOpenAnotherFolderButton ? 2 : 1;
5171
5196
  const errorDom = [{
5172
- childCount: 1,
5197
+ childCount,
5198
+ className: Welcome,
5173
5199
  type: Div
5200
+ }, {
5201
+ childCount: 1,
5202
+ className: WelcomeMessage,
5203
+ type: P
5174
5204
  }, text(loadErrorMessage)];
5205
+ const buttonDom = showOpenAnotherFolderButton ? [{
5206
+ childCount: 1,
5207
+ className: mergeClassNames(Button$2, ButtonPrimary, isWide ? ButtonWide : ButtonNarrow),
5208
+ name: OpenFolder,
5209
+ onClick: HandleClickOpenFolder,
5210
+ type: Button$1
5211
+ }, text(openAnotherFolder())] : [];
5175
5212
  const parentNode = getParentNode$1(1);
5176
- return [parentNode, ...errorDom];
5213
+ return [parentNode, ...errorDom, ...buttonDom];
5177
5214
  };
5178
5215
 
5179
5216
  const getScrollBarVirtualDom = scrollBarHeight => {
@@ -5210,12 +5247,12 @@ const getChildCount = (scrollBarDomLength, errorDomLength) => {
5210
5247
  }
5211
5248
  return childCount;
5212
5249
  };
5213
- const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused, dropTargets, height, contentHeight, editingErrorMessage, loadErrorMessage) => {
5250
+ const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused, dropTargets, height, contentHeight, editingErrorMessage, loadErrorMessage, showOpenAnotherFolderButton) => {
5214
5251
  if (!root) {
5215
5252
  return getExplorerWelcomeVirtualDom(isWide, dropTargets);
5216
5253
  }
5217
5254
  if (loadErrorMessage) {
5218
- return getLoadErrorVirtualDom(loadErrorMessage);
5255
+ return getLoadErrorVirtualDom(loadErrorMessage, isWide, showOpenAnotherFolderButton);
5219
5256
  }
5220
5257
  const scrollBarHeight = getScrollBarSize(height, contentHeight, 20);
5221
5258
  const scrollBarDom = getScrollBarVirtualDom(scrollBarHeight);
@@ -5226,14 +5263,26 @@ const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused
5226
5263
  return dom;
5227
5264
  };
5228
5265
 
5266
+ const getMissingFolderMessage = root => {
5267
+ if (root) {
5268
+ return `Could not open "${root}" because the folder does not exist. It may have been moved or deleted.`;
5269
+ }
5270
+ return 'Could not open folder because the folder does not exist. It may have been moved or deleted.';
5271
+ };
5229
5272
  const getLoadErrorMessage = state => {
5230
5273
  if (state.hasError) {
5274
+ if (state.errorCode === 'ENOENT') {
5275
+ return getMissingFolderMessage(state.root);
5276
+ }
5231
5277
  const code = state.errorCode ? ` (error code: ${state.errorCode})` : '';
5232
5278
  const reason = state.errorMessage || 'an unexpected error occurred';
5233
5279
  return `Could not open folder due to ${reason}${code}.`;
5234
5280
  }
5235
5281
  return '';
5236
5282
  };
5283
+ const shouldShowOpenAnotherFolderButton = state => {
5284
+ return state.hasError && state.errorCode === 'ENOENT';
5285
+ };
5237
5286
 
5238
5287
  const renderItems = (oldState, newState) => {
5239
5288
  const {
@@ -5252,10 +5301,11 @@ const renderItems = (oldState, newState) => {
5252
5301
  const isWide = width > 450;
5253
5302
  const contentHeight = items.length * itemHeight;
5254
5303
  const loadErrorMessage = getLoadErrorMessage(newState);
5304
+ const showOpenAnotherFolderButton = shouldShowOpenAnotherFolderButton(newState);
5255
5305
  if (initial) {
5256
5306
  return [SetDom2, newState.uid, []];
5257
5307
  }
5258
- const dom = getExplorerVirtualDom(visibleDirents, focusedIndex, root, isWide, focused, dropTargets, height, contentHeight, editingErrorMessage, loadErrorMessage);
5308
+ const dom = getExplorerVirtualDom(visibleDirents, focusedIndex, root, isWide, focused, dropTargets, height, contentHeight, editingErrorMessage, loadErrorMessage, showOpenAnotherFolderButton);
5259
5309
  return [SetDom2, newState.uid, dom];
5260
5310
  };
5261
5311
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "6.3.0",
3
+ "version": "6.4.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",