@lvce-editor/explorer-view 2.40.0 → 2.42.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.
@@ -1001,92 +1001,6 @@ const CreateFile = 1;
1001
1001
  const CreateFolder = 2;
1002
1002
  const Rename$1 = 3;
1003
1003
 
1004
- const emptyObject = {};
1005
- const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1006
- const i18nString = (key, placeholders = emptyObject) => {
1007
- if (placeholders === emptyObject) {
1008
- return key;
1009
- }
1010
- const replacer = (match, rest) => {
1011
- return placeholders[rest];
1012
- };
1013
- return key.replaceAll(RE_PLACEHOLDER, replacer);
1014
- };
1015
-
1016
- const CollapseAllFoldersInExplorer = 'Collapse All Folders in Explorer';
1017
- const Copy$1 = 'Copy';
1018
- const CopyPath = 'Copy Path';
1019
- const CopyRelativePath = 'Copy Relative Path';
1020
- const Cut$1 = 'Cut';
1021
- const Delete$1 = 'Delete';
1022
- const FileOrFolderNameMustBeProvider = 'A file or folder name must be provided.';
1023
- const FilesExplorer = 'Files Explorer';
1024
- const NewFile$1 = 'New File...';
1025
- const NewFolder$1 = 'New Folder...';
1026
- const OpenContainingFolder = 'Open Containing Folder';
1027
- const OpenFolder = 'Open folder';
1028
- const OpenInIntegratedTerminal = 'Open in integrated Terminal';
1029
- const Paste = 'Paste';
1030
- const RefreshExplorer = 'Refresh Explorer';
1031
- const Rename = 'Rename';
1032
- const TypeAFileName = 'Type file name. Press Enter to confirm or Escape to cancel.'; // TODO use keybinding
1033
- const YouHaveNotYetOpenedAFolder = 'You have not yet opened a folder';
1034
-
1035
- const newFile$1 = () => {
1036
- return i18nString(NewFile$1);
1037
- };
1038
- const newFolder$1 = () => {
1039
- return i18nString(NewFolder$1);
1040
- };
1041
- const openContainingFolder$1 = () => {
1042
- return i18nString(OpenContainingFolder);
1043
- };
1044
- const openInIntegratedTerminal = () => {
1045
- return i18nString(OpenInIntegratedTerminal);
1046
- };
1047
- const cut = () => {
1048
- return i18nString(Cut$1);
1049
- };
1050
- const copy = () => {
1051
- return i18nString(Copy$1);
1052
- };
1053
- const paste = () => {
1054
- return i18nString(Paste);
1055
- };
1056
- const copyPath$1 = () => {
1057
- return i18nString(CopyPath);
1058
- };
1059
- const copyRelativePath$1 = () => {
1060
- return i18nString(CopyRelativePath);
1061
- };
1062
- const rename = () => {
1063
- return i18nString(Rename);
1064
- };
1065
- const deleteItem = () => {
1066
- return i18nString(Delete$1);
1067
- };
1068
- const refresh$1 = () => {
1069
- return i18nString(RefreshExplorer);
1070
- };
1071
- const collapseAll$1 = () => {
1072
- return i18nString(CollapseAllFoldersInExplorer);
1073
- };
1074
- const filesExplorer = () => {
1075
- return i18nString(FilesExplorer);
1076
- };
1077
- const youHaveNotYetOpenedAFolder = () => {
1078
- return i18nString(YouHaveNotYetOpenedAFolder);
1079
- };
1080
- const openFolder$1 = () => {
1081
- return i18nString(OpenFolder);
1082
- };
1083
- const fileOrFolderNameMustBeProvided = () => {
1084
- return i18nString(FileOrFolderNameMustBeProvider);
1085
- };
1086
- const typeAFileName = () => {
1087
- return i18nString(TypeAFileName);
1088
- };
1089
-
1090
1004
  const List = 1;
1091
1005
  const Input$1 = 2;
1092
1006
 
@@ -1194,6 +1108,16 @@ const getFileIcons = async (dirents, fileIconCache) => {
1194
1108
  };
1195
1109
  };
1196
1110
 
1111
+ const getIndex = (dirents, uri) => {
1112
+ for (let i = 0; i < dirents.length; i++) {
1113
+ const dirent = dirents[i];
1114
+ if (dirent.path === uri) {
1115
+ return i;
1116
+ }
1117
+ }
1118
+ return -1;
1119
+ };
1120
+
1197
1121
  const getParentFolder = (dirents, index, root) => {
1198
1122
  if (index < 0) {
1199
1123
  return root;
@@ -1407,35 +1331,130 @@ const mergeTrees = (a, b) => {
1407
1331
  };
1408
1332
  };
1409
1333
 
1334
+ const treeToArrayInternal = (map, root, items, path, depth) => {
1335
+ const children = map[path];
1336
+ if (!children) {
1337
+ return;
1338
+ }
1339
+ const count = children.length;
1340
+ for (let i = 0; i < count; i++) {
1341
+ const child = children[i];
1342
+ const childPath = join2(path, child.name);
1343
+ const absolutePath = `${root}${childPath}`;
1344
+ items.push({
1345
+ depth,
1346
+ posInSet: i + 1,
1347
+ setSize: count,
1348
+ icon: '',
1349
+ path: absolutePath,
1350
+ selected: false,
1351
+ name: child.name,
1352
+ type: child.type
1353
+ });
1354
+ treeToArrayInternal(map, root, items, childPath, depth + 1);
1355
+ }
1356
+ };
1357
+
1410
1358
  const treeToArray = (map, root) => {
1411
1359
  const items = [];
1412
- const processChildren = (path, depth) => {
1413
- const children = map[path];
1414
- if (!children) {
1415
- return;
1416
- }
1417
- const count = children.length;
1418
- for (let i = 0; i < count; i++) {
1419
- const child = children[i];
1420
- const childPath = join2(path, child.name);
1421
- const absolutePath = `${root}${childPath}`;
1422
- items.push({
1423
- depth,
1424
- posInSet: i + 1,
1425
- setSize: count,
1426
- icon: '',
1427
- path: absolutePath,
1428
- selected: false,
1429
- name: child.name,
1430
- type: child.type
1431
- });
1432
- processChildren(childPath, depth + 1);
1433
- }
1434
- };
1435
- processChildren('', 0);
1360
+ treeToArrayInternal(map, root, items, '', 1);
1436
1361
  return items;
1437
1362
  };
1438
1363
 
1364
+ const emptyObject = {};
1365
+ const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
1366
+ const i18nString = (key, placeholders = emptyObject) => {
1367
+ if (placeholders === emptyObject) {
1368
+ return key;
1369
+ }
1370
+ const replacer = (match, rest) => {
1371
+ return placeholders[rest];
1372
+ };
1373
+ return key.replaceAll(RE_PLACEHOLDER, replacer);
1374
+ };
1375
+
1376
+ const CollapseAllFoldersInExplorer = 'Collapse All Folders in Explorer';
1377
+ const Copy$1 = 'Copy';
1378
+ const CopyPath = 'Copy Path';
1379
+ const CopyRelativePath = 'Copy Relative Path';
1380
+ const Cut$1 = 'Cut';
1381
+ const Delete$1 = 'Delete';
1382
+ const FileOrFolderNameMustBeProvider = 'A file or folder name must be provided.';
1383
+ const FilesExplorer = 'Files Explorer';
1384
+ const NewFile$1 = 'New File...';
1385
+ const NewFolder$1 = 'New Folder...';
1386
+ const OpenContainingFolder = 'Open Containing Folder';
1387
+ const OpenFolder = 'Open folder';
1388
+ const OpenInIntegratedTerminal = 'Open in integrated Terminal';
1389
+ const Paste = 'Paste';
1390
+ const RefreshExplorer = 'Refresh Explorer';
1391
+ const Rename = 'Rename';
1392
+ const TypeAFileName = 'Type file name. Press Enter to confirm or Escape to cancel.'; // TODO use keybinding
1393
+ const YouHaveNotYetOpenedAFolder = 'You have not yet opened a folder';
1394
+
1395
+ const newFile$1 = () => {
1396
+ return i18nString(NewFile$1);
1397
+ };
1398
+ const newFolder$1 = () => {
1399
+ return i18nString(NewFolder$1);
1400
+ };
1401
+ const openContainingFolder$1 = () => {
1402
+ return i18nString(OpenContainingFolder);
1403
+ };
1404
+ const openInIntegratedTerminal = () => {
1405
+ return i18nString(OpenInIntegratedTerminal);
1406
+ };
1407
+ const cut = () => {
1408
+ return i18nString(Cut$1);
1409
+ };
1410
+ const copy = () => {
1411
+ return i18nString(Copy$1);
1412
+ };
1413
+ const paste = () => {
1414
+ return i18nString(Paste);
1415
+ };
1416
+ const copyPath$1 = () => {
1417
+ return i18nString(CopyPath);
1418
+ };
1419
+ const copyRelativePath$1 = () => {
1420
+ return i18nString(CopyRelativePath);
1421
+ };
1422
+ const rename = () => {
1423
+ return i18nString(Rename);
1424
+ };
1425
+ const deleteItem = () => {
1426
+ return i18nString(Delete$1);
1427
+ };
1428
+ const refresh$1 = () => {
1429
+ return i18nString(RefreshExplorer);
1430
+ };
1431
+ const collapseAll$1 = () => {
1432
+ return i18nString(CollapseAllFoldersInExplorer);
1433
+ };
1434
+ const filesExplorer = () => {
1435
+ return i18nString(FilesExplorer);
1436
+ };
1437
+ const youHaveNotYetOpenedAFolder = () => {
1438
+ return i18nString(YouHaveNotYetOpenedAFolder);
1439
+ };
1440
+ const openFolder$1 = () => {
1441
+ return i18nString(OpenFolder);
1442
+ };
1443
+ const fileOrFolderNameMustBeProvided = () => {
1444
+ return i18nString(FileOrFolderNameMustBeProvider);
1445
+ };
1446
+ const typeAFileName = () => {
1447
+ return i18nString(TypeAFileName);
1448
+ };
1449
+
1450
+ const validateFileName2 = name => {
1451
+ if (!name) {
1452
+ const editingErrorMessage = fileOrFolderNameMustBeProvided();
1453
+ return editingErrorMessage;
1454
+ }
1455
+ return '';
1456
+ };
1457
+
1439
1458
  const acceptCreate = async (state, newDirentType, createFn) => {
1440
1459
  const {
1441
1460
  editingValue,
@@ -1449,11 +1468,8 @@ const acceptCreate = async (state, newDirentType, createFn) => {
1449
1468
  items
1450
1469
  } = state;
1451
1470
  const newFileName = editingValue;
1452
- if (!newFileName) {
1453
- // TODO show error message that file name must not be empty
1454
- // below input box
1455
- // await ErrorHandling.showErrorDialog(new Error('file name must not be empty'))
1456
- const editingErrorMessage = fileOrFolderNameMustBeProvided();
1471
+ const editingErrorMessage = validateFileName2(newFileName);
1472
+ if (editingErrorMessage) {
1457
1473
  return {
1458
1474
  ...state,
1459
1475
  editingErrorMessage
@@ -1472,7 +1488,7 @@ const acceptCreate = async (state, newDirentType, createFn) => {
1472
1488
  const merged = mergeTrees(tree, childTree);
1473
1489
  const newItems = treeToArray(merged, root);
1474
1490
  const dirents = newItems;
1475
- const newFocusedIndex = newItems.findIndex(dirent => dirent.path === absolutePath);
1491
+ const newFocusedIndex = getIndex(newItems, absolutePath);
1476
1492
  const maxLineY = getExplorerMaxLineY(minLineY, height, itemHeight, dirents.length);
1477
1493
  const visible = dirents.slice(minLineY, maxLineY);
1478
1494
  const {
@@ -1522,16 +1538,6 @@ const createNewDirentsRename = async (renamedDirent, editingValue, pathSeparator
1522
1538
  return true;
1523
1539
  };
1524
1540
 
1525
- const getIndex = (dirents, uri) => {
1526
- for (let i = 0; i < dirents.length; i++) {
1527
- const dirent = dirents[i];
1528
- if (dirent.path === uri) {
1529
- return i;
1530
- }
1531
- }
1532
- return -1;
1533
- };
1534
-
1535
1541
  const updateTree2 = (tree, update) => {
1536
1542
  const updatedTree = {
1537
1543
  ...tree,
@@ -1551,6 +1557,13 @@ const acceptRename = async state => {
1551
1557
  itemHeight,
1552
1558
  fileIconCache
1553
1559
  } = state;
1560
+ const editingErrorMessage = validateFileName2(editingValue);
1561
+ if (editingErrorMessage) {
1562
+ return {
1563
+ ...state,
1564
+ editingErrorMessage
1565
+ };
1566
+ }
1554
1567
  const renamedDirent = items[editingIndex];
1555
1568
  const successful = await createNewDirentsRename(renamedDirent, editingValue);
1556
1569
  if (!successful) {
@@ -1580,7 +1593,9 @@ const acceptRename = async state => {
1580
1593
  focus: List,
1581
1594
  items: newDirents,
1582
1595
  icons,
1583
- fileIconCache: newFileIconCache
1596
+ fileIconCache: newFileIconCache,
1597
+ editingSelectionEnd: 0,
1598
+ editingSelectionStart: 0
1584
1599
  };
1585
1600
  };
1586
1601
 
@@ -1655,7 +1670,9 @@ const cancelEditRename = (state, keepFocus) => {
1655
1670
  editingValue: '',
1656
1671
  editingType: None$5,
1657
1672
  editingErrorMessage: '',
1658
- focus: List
1673
+ focus: List,
1674
+ editingSelectionStart: 0,
1675
+ editingSelectionEnd: 0
1659
1676
  };
1660
1677
  };
1661
1678
 
@@ -1843,10 +1860,8 @@ const create2 = (uid, uri, x, y, width, height, args, parentUid, platform = 0) =
1843
1860
  focus: 0,
1844
1861
  editingErrorMessage: '',
1845
1862
  inputSource: 0,
1846
- editingSelection: {
1847
- start: 0,
1848
- end: 0
1849
- },
1863
+ editingSelectionEnd: 0,
1864
+ editingSelectionStart: 0,
1850
1865
  focusWord: '',
1851
1866
  focusWordTimeout: 800,
1852
1867
  finalDeltaY: 0,
@@ -1890,10 +1905,8 @@ const create = (id, uri, x, y, width, height, args, parentUid, platform = 0) =>
1890
1905
  focus: 0,
1891
1906
  editingErrorMessage: '',
1892
1907
  inputSource: 0,
1893
- editingSelection: {
1894
- start: 0,
1895
- end: 0
1896
- },
1908
+ editingSelectionStart: 0,
1909
+ editingSelectionEnd: 0,
1897
1910
  focusWord: '',
1898
1911
  focusWordTimeout: 800,
1899
1912
  finalDeltaY: 0,
@@ -1923,7 +1936,7 @@ const isEqual$3 = (oldState, newState) => {
1923
1936
 
1924
1937
  const diffType$1 = RenderSelection;
1925
1938
  const isEqual$2 = (oldState, newState) => {
1926
- return oldState.editingSelection.start === newState.editingSelection.start && oldState.editingSelection.end === newState.editingSelection.end;
1939
+ return oldState.editingSelectionStart === newState.editingSelectionStart && oldState.editingSelectionEnd === newState.editingSelectionEnd;
1927
1940
  };
1928
1941
 
1929
1942
  const diffType = RenderValue;
@@ -4130,6 +4143,7 @@ const getNewDirentsForRename = (items, focusedIndex) => {
4130
4143
  const item = items[focusedIndex];
4131
4144
  const newItems = [...items];
4132
4145
  const editingType = item.type === File ? EditingFile : EditingFolder;
4146
+ // TODO avoid mutation
4133
4147
  newItems[focusedIndex] = {
4134
4148
  ...item,
4135
4149
  type: editingType
@@ -4137,6 +4151,20 @@ const getNewDirentsForRename = (items, focusedIndex) => {
4137
4151
  return newItems;
4138
4152
  };
4139
4153
 
4154
+ const getRenameSelectionRange = name => {
4155
+ const dotIndex = name.lastIndexOf('.');
4156
+ if (dotIndex === -1) {
4157
+ return {
4158
+ start: 0,
4159
+ end: name.length
4160
+ };
4161
+ }
4162
+ return {
4163
+ start: 0,
4164
+ end: dotIndex
4165
+ };
4166
+ };
4167
+
4140
4168
  const User = 1;
4141
4169
  const Script = 2;
4142
4170
 
@@ -4152,6 +4180,10 @@ const renameDirent = state => {
4152
4180
  }
4153
4181
  const item = items[focusedIndex];
4154
4182
  const newItems = getNewDirentsForRename(items, focusedIndex);
4183
+ const {
4184
+ start,
4185
+ end
4186
+ } = getRenameSelectionRange(item.name);
4155
4187
  return {
4156
4188
  ...state,
4157
4189
  items: newItems,
@@ -4159,21 +4191,24 @@ const renameDirent = state => {
4159
4191
  editingType: Rename$1,
4160
4192
  editingValue: item.name,
4161
4193
  editingIcon: icons[focusedIndex - minLineY],
4162
- editingSelection: {
4163
- start: 0,
4164
- end: item.name.length
4165
- },
4194
+ editingSelectionStart: start,
4195
+ editingSelectionEnd: end,
4166
4196
  focus: Input$1,
4167
4197
  inputSource: Script
4168
4198
  };
4169
4199
  };
4170
4200
 
4201
+ const ExplorerInput = 'ExplorerInput';
4202
+
4171
4203
  const renderEditingSelection = (oldState, newState) => {
4172
- return ['Viewlet.setSelection', newState.editingSelection];
4204
+ const {
4205
+ editingSelectionStart,
4206
+ editingSelectionEnd,
4207
+ uid
4208
+ } = newState;
4209
+ return ['Viewlet.setSelectionByName', uid, ExplorerInput, editingSelectionStart, editingSelectionEnd];
4173
4210
  };
4174
4211
 
4175
- const ExplorerInput = 'ExplorerInput';
4176
-
4177
4212
  const renderFocus$1 = (oldState, newState) => {
4178
4213
  if (newState.inputSource === User) {
4179
4214
  return [];
@@ -4681,10 +4716,6 @@ const getRenderer = diffType => {
4681
4716
  const applyRender = (oldState, newState, diffResult) => {
4682
4717
  const commands = [];
4683
4718
  for (const item of diffResult) {
4684
- if (item === RenderSelection) {
4685
- // TODO support this in the future
4686
- continue;
4687
- }
4688
4719
  const fn = getRenderer(item);
4689
4720
  const result = fn(oldState, newState);
4690
4721
  if (result.length > 0) {
@@ -5144,10 +5175,12 @@ const updateEditingValue = async (state, value, inputSource = User) => {
5144
5175
  editingIndex
5145
5176
  } = state;
5146
5177
  const editingIcon = await getEditingIcon(editingType, value, items[editingIndex]?.type);
5178
+ const editingErrorMessage = validateFileName2(value);
5147
5179
  return {
5148
5180
  ...state,
5149
5181
  editingValue: value,
5150
- editingIcon
5182
+ editingIcon,
5183
+ editingErrorMessage
5151
5184
  };
5152
5185
  };
5153
5186
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.40.0",
3
+ "version": "2.42.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",