@lvce-editor/explorer-view 6.3.0 → 6.5.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 {
@@ -4186,8 +4204,12 @@ const handleIconThemeChange = state => {
4186
4204
  const handleInputBlur = async state => {
4187
4205
  const {
4188
4206
  editingErrorMessage,
4207
+ editingIndex,
4189
4208
  editingValue
4190
4209
  } = state;
4210
+ if (editingIndex === -1) {
4211
+ return state;
4212
+ }
4191
4213
  if (editingErrorMessage || !editingValue) {
4192
4214
  return cancelEditInternal(state, false);
4193
4215
  }
@@ -5084,6 +5106,12 @@ const getLabelDom = (isEditing, name, isDimmed) => {
5084
5106
  return [label, text(name)];
5085
5107
  };
5086
5108
 
5109
+ const getTitle = path => {
5110
+ if (path.startsWith('file://')) {
5111
+ return path.slice('file://'.length);
5112
+ }
5113
+ return path;
5114
+ };
5087
5115
  const getExplorerItemVirtualDom = item => {
5088
5116
  const {
5089
5117
  ariaExpanded,
@@ -5116,7 +5144,7 @@ const getExplorerItemVirtualDom = item => {
5116
5144
  draggable: true,
5117
5145
  id,
5118
5146
  role: TreeItem,
5119
- title: path,
5147
+ title: getTitle(path),
5120
5148
  type: Div
5121
5149
  }, ...chevronDom, getFileIconVirtualDom(icon), ...getInputDom(isEditing, hasEditingError), ...getLabelDom(isEditing, name, isCut || isIgnored)];
5122
5150
  };
@@ -5167,13 +5195,26 @@ const getParentNode$1 = childCount => {
5167
5195
  type: Div
5168
5196
  };
5169
5197
  };
5170
- const getLoadErrorVirtualDom = loadErrorMessage => {
5198
+ const getLoadErrorVirtualDom = (loadErrorMessage, isWide, showOpenAnotherFolderButton) => {
5199
+ const childCount = showOpenAnotherFolderButton ? 2 : 1;
5171
5200
  const errorDom = [{
5172
- childCount: 1,
5201
+ childCount,
5202
+ className: Welcome,
5173
5203
  type: Div
5204
+ }, {
5205
+ childCount: 1,
5206
+ className: WelcomeMessage,
5207
+ type: P
5174
5208
  }, text(loadErrorMessage)];
5209
+ const buttonDom = showOpenAnotherFolderButton ? [{
5210
+ childCount: 1,
5211
+ className: mergeClassNames(Button$2, ButtonPrimary, isWide ? ButtonWide : ButtonNarrow),
5212
+ name: OpenFolder,
5213
+ onClick: HandleClickOpenFolder,
5214
+ type: Button$1
5215
+ }, text(openAnotherFolder())] : [];
5175
5216
  const parentNode = getParentNode$1(1);
5176
- return [parentNode, ...errorDom];
5217
+ return [parentNode, ...errorDom, ...buttonDom];
5177
5218
  };
5178
5219
 
5179
5220
  const getScrollBarVirtualDom = scrollBarHeight => {
@@ -5210,12 +5251,12 @@ const getChildCount = (scrollBarDomLength, errorDomLength) => {
5210
5251
  }
5211
5252
  return childCount;
5212
5253
  };
5213
- const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused, dropTargets, height, contentHeight, editingErrorMessage, loadErrorMessage) => {
5254
+ const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused, dropTargets, height, contentHeight, editingErrorMessage, loadErrorMessage, showOpenAnotherFolderButton) => {
5214
5255
  if (!root) {
5215
5256
  return getExplorerWelcomeVirtualDom(isWide, dropTargets);
5216
5257
  }
5217
5258
  if (loadErrorMessage) {
5218
- return getLoadErrorVirtualDom(loadErrorMessage);
5259
+ return getLoadErrorVirtualDom(loadErrorMessage, isWide, showOpenAnotherFolderButton);
5219
5260
  }
5220
5261
  const scrollBarHeight = getScrollBarSize(height, contentHeight, 20);
5221
5262
  const scrollBarDom = getScrollBarVirtualDom(scrollBarHeight);
@@ -5226,14 +5267,26 @@ const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused
5226
5267
  return dom;
5227
5268
  };
5228
5269
 
5270
+ const getMissingFolderMessage = root => {
5271
+ if (root) {
5272
+ return `Could not open "${root}" because the folder does not exist. It may have been moved or deleted.`;
5273
+ }
5274
+ return 'Could not open folder because the folder does not exist. It may have been moved or deleted.';
5275
+ };
5229
5276
  const getLoadErrorMessage = state => {
5230
5277
  if (state.hasError) {
5278
+ if (state.errorCode === 'ENOENT') {
5279
+ return getMissingFolderMessage(state.root);
5280
+ }
5231
5281
  const code = state.errorCode ? ` (error code: ${state.errorCode})` : '';
5232
5282
  const reason = state.errorMessage || 'an unexpected error occurred';
5233
5283
  return `Could not open folder due to ${reason}${code}.`;
5234
5284
  }
5235
5285
  return '';
5236
5286
  };
5287
+ const shouldShowOpenAnotherFolderButton = state => {
5288
+ return state.hasError && state.errorCode === 'ENOENT';
5289
+ };
5237
5290
 
5238
5291
  const renderItems = (oldState, newState) => {
5239
5292
  const {
@@ -5252,10 +5305,11 @@ const renderItems = (oldState, newState) => {
5252
5305
  const isWide = width > 450;
5253
5306
  const contentHeight = items.length * itemHeight;
5254
5307
  const loadErrorMessage = getLoadErrorMessage(newState);
5308
+ const showOpenAnotherFolderButton = shouldShowOpenAnotherFolderButton(newState);
5255
5309
  if (initial) {
5256
5310
  return [SetDom2, newState.uid, []];
5257
5311
  }
5258
- const dom = getExplorerVirtualDom(visibleDirents, focusedIndex, root, isWide, focused, dropTargets, height, contentHeight, editingErrorMessage, loadErrorMessage);
5312
+ const dom = getExplorerVirtualDom(visibleDirents, focusedIndex, root, isWide, focused, dropTargets, height, contentHeight, editingErrorMessage, loadErrorMessage, showOpenAnotherFolderButton);
5259
5313
  return [SetDom2, newState.uid, dom];
5260
5314
  };
5261
5315
 
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.5.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",