@lvce-editor/explorer-view 2.39.0 → 2.41.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.
@@ -441,11 +441,11 @@ const remove$1 = id => {
441
441
  delete callbacks[id];
442
442
  };
443
443
  let id = 0;
444
- const create$3 = () => {
444
+ const create$3$1 = () => {
445
445
  return ++id;
446
446
  };
447
447
  const registerPromise = () => {
448
- const id = create$3();
448
+ const id = create$3$1();
449
449
  const {
450
450
  resolve,
451
451
  promise
@@ -835,7 +835,7 @@ const listen$1 = async (module, options) => {
835
835
  const ipc = module.wrap(rawIpc);
836
836
  return ipc;
837
837
  };
838
- const create$2 = async ({
838
+ const create$3 = async ({
839
839
  commandMap
840
840
  }) => {
841
841
  // TODO create a commandMap per rpc instance
@@ -847,25 +847,43 @@ const create$2 = async ({
847
847
  };
848
848
  const WebWorkerRpcClient = {
849
849
  __proto__: null,
850
- create: create$2
850
+ create: create$3
851
851
  };
852
852
 
853
853
  const rpcs = Object.create(null);
854
- const set$5 = (id, rpc) => {
854
+ const set$7 = (id, rpc) => {
855
855
  rpcs[id] = rpc;
856
856
  };
857
857
  const get$1 = id => {
858
858
  return rpcs[id];
859
859
  };
860
- const RendererWorker$1 = 1;
861
- const invoke$2 = (method, ...params) => {
862
- const rpc = get$1(RendererWorker$1);
863
- // @ts-ignore
864
- return rpc.invoke(method, ...params);
865
- };
866
- const set$2 = rpc => {
867
- set$5(RendererWorker$1, rpc);
860
+
861
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
862
+
863
+ const create$2 = rpcId => {
864
+ return {
865
+ // @ts-ignore
866
+ invoke(method, ...params) {
867
+ const rpc = get$1(rpcId);
868
+ // @ts-ignore
869
+ return rpc.invoke(method, ...params);
870
+ },
871
+ // @ts-ignore
872
+ invokeAndTransfer(method, ...params) {
873
+ const rpc = get$1(rpcId);
874
+ // @ts-ignore
875
+ return rpc.invokeAndTransfer(method, ...params);
876
+ },
877
+ set(rpc) {
878
+ set$7(rpcId, rpc);
879
+ }
880
+ };
868
881
  };
882
+ const RendererWorker$1 = 1;
883
+ const {
884
+ invoke: invoke$2,
885
+ set: set$2
886
+ } = create$2(RendererWorker$1);
869
887
  const RendererWorker = {
870
888
  __proto__: null,
871
889
  invoke: invoke$2,
@@ -1176,6 +1194,16 @@ const getFileIcons = async (dirents, fileIconCache) => {
1176
1194
  };
1177
1195
  };
1178
1196
 
1197
+ const getIndex = (dirents, uri) => {
1198
+ for (let i = 0; i < dirents.length; i++) {
1199
+ const dirent = dirents[i];
1200
+ if (dirent.path === uri) {
1201
+ return i;
1202
+ }
1203
+ }
1204
+ return -1;
1205
+ };
1206
+
1179
1207
  const getParentFolder = (dirents, index, root) => {
1180
1208
  if (index < 0) {
1181
1209
  return root;
@@ -1291,13 +1319,13 @@ const sortExplorerItems = rawDirents => {
1291
1319
  };
1292
1320
 
1293
1321
  // TODO figure out whether this uses too much memory (name,path -> redundant, depth could be computed on demand)
1294
- const toDisplayDirent = (parentDirent, rawDirent, index, length) => {
1295
- const path = join2(parentDirent.path, rawDirent.name);
1322
+ const toDisplayDirent = (parentPath, parentDepth, rawDirent, index, length) => {
1323
+ const path = join2(parentPath, rawDirent.name);
1296
1324
  return {
1297
1325
  name: rawDirent.name,
1298
1326
  posInSet: index + 1,
1299
1327
  setSize: length,
1300
- depth: parentDirent.depth + 1,
1328
+ depth: parentDepth + 1,
1301
1329
  type: rawDirent.type,
1302
1330
  path,
1303
1331
  // TODO storing absolute path might be too costly, could also store relative path here
@@ -1306,7 +1334,7 @@ const toDisplayDirent = (parentDirent, rawDirent, index, length) => {
1306
1334
  };
1307
1335
  };
1308
1336
 
1309
- const toDisplayDirents = (pathSeparator, rawDirents, parentDirent, excluded) => {
1337
+ const toDisplayDirents = (pathSeparator, rawDirents, parentDirentPath, parentDirentDepth, excluded) => {
1310
1338
  rawDirents = sortExplorerItems(rawDirents);
1311
1339
  const result = [];
1312
1340
  const visibleItems = rawDirents.filter(item => {
@@ -1318,7 +1346,7 @@ const toDisplayDirents = (pathSeparator, rawDirents, parentDirent, excluded) =>
1318
1346
  const count = visibleItems.length;
1319
1347
  for (let i = 0; i < visibleItems.length; i++) {
1320
1348
  const rawDirent = visibleItems[i];
1321
- result.push(toDisplayDirent(parentDirent, rawDirent, i, count));
1349
+ result.push(toDisplayDirent(parentDirentPath, parentDirentDepth, rawDirent, i, count));
1322
1350
  }
1323
1351
  return result;
1324
1352
  };
@@ -1331,18 +1359,16 @@ const getChildDirentsRaw = async uri => {
1331
1359
  }
1332
1360
  return rawDirents;
1333
1361
  };
1334
- const getChildDirents = async (pathSeparator, parentDirent, excluded = []) => {
1362
+ const getChildDirents = async (pathSeparator, parentDirentPath, parentDirentDepth, excluded = []) => {
1335
1363
  string(pathSeparator);
1336
- object(parentDirent);
1337
1364
  // TODO use event/actor based code instead, this is impossible to cancel right now
1338
1365
  // also cancel updating when opening new folder
1339
1366
  // const dispose = state => state.pendingRequests.forEach(cancelRequest)
1340
1367
  // TODO should use FileSystem directly in this case because it is globally available anyway
1341
1368
  // and more typesafe than Command.execute
1342
1369
  // and more performant
1343
- const uri = parentDirent.path;
1344
- const rawDirents = await getChildDirentsRaw(uri);
1345
- const displayDirents = toDisplayDirents(pathSeparator, rawDirents, parentDirent, excluded);
1370
+ const rawDirents = await getChildDirentsRaw(parentDirentPath);
1371
+ const displayDirents = toDisplayDirents(pathSeparator, rawDirents, parentDirentPath, parentDirentDepth, excluded);
1346
1372
  return displayDirents;
1347
1373
  };
1348
1374
 
@@ -1374,7 +1400,7 @@ const orderDirents = dirents => {
1374
1400
  };
1375
1401
 
1376
1402
  const getPathPartChildren = async pathPart => {
1377
- const children = await getChildDirents(pathPart.pathSeparator, pathPart);
1403
+ const children = await getChildDirents(pathPart.pathSeparator, pathPart.path, pathPart.depth);
1378
1404
  return children;
1379
1405
  };
1380
1406
  const getPathPartsChildren = async pathparts => {
@@ -1391,32 +1417,33 @@ const mergeTrees = (a, b) => {
1391
1417
  };
1392
1418
  };
1393
1419
 
1420
+ const treeToArrayInternal = (map, root, items, path, depth) => {
1421
+ const children = map[path];
1422
+ if (!children) {
1423
+ return;
1424
+ }
1425
+ const count = children.length;
1426
+ for (let i = 0; i < count; i++) {
1427
+ const child = children[i];
1428
+ const childPath = join2(path, child.name);
1429
+ const absolutePath = `${root}${childPath}`;
1430
+ items.push({
1431
+ depth,
1432
+ posInSet: i + 1,
1433
+ setSize: count,
1434
+ icon: '',
1435
+ path: absolutePath,
1436
+ selected: false,
1437
+ name: child.name,
1438
+ type: child.type
1439
+ });
1440
+ treeToArrayInternal(map, root, items, childPath, depth + 1);
1441
+ }
1442
+ };
1443
+
1394
1444
  const treeToArray = (map, root) => {
1395
1445
  const items = [];
1396
- const processChildren = (path, depth) => {
1397
- const children = map[path];
1398
- if (!children) {
1399
- return;
1400
- }
1401
- const count = children.length;
1402
- for (let i = 0; i < count; i++) {
1403
- const child = children[i];
1404
- const childPath = join2(path, child.name);
1405
- const absolutePath = `${root}${childPath}`;
1406
- items.push({
1407
- depth,
1408
- posInSet: i + 1,
1409
- setSize: count,
1410
- icon: '',
1411
- path: absolutePath,
1412
- selected: false,
1413
- name: child.name,
1414
- type: child.type
1415
- });
1416
- processChildren(childPath, depth + 1);
1417
- }
1418
- };
1419
- processChildren('', 0);
1446
+ treeToArrayInternal(map, root, items, '', 1);
1420
1447
  return items;
1421
1448
  };
1422
1449
 
@@ -1456,7 +1483,7 @@ const acceptCreate = async (state, newDirentType, createFn) => {
1456
1483
  const merged = mergeTrees(tree, childTree);
1457
1484
  const newItems = treeToArray(merged, root);
1458
1485
  const dirents = newItems;
1459
- const newFocusedIndex = newItems.findIndex(dirent => dirent.path === absolutePath);
1486
+ const newFocusedIndex = getIndex(newItems, absolutePath);
1460
1487
  const maxLineY = getExplorerMaxLineY(minLineY, height, itemHeight, dirents.length);
1461
1488
  const visible = dirents.slice(minLineY, maxLineY);
1462
1489
  const {
@@ -1484,98 +1511,11 @@ const acceptCreateFolder = async state => {
1484
1511
  return acceptCreate(state, Directory, mkdir);
1485
1512
  };
1486
1513
 
1487
- // TODO use posInSet and setSize properties to compute more effectively
1488
- const computeExplorerRenamedDirent = (dirents, index, newName) => {
1489
- let startIndex = index;
1490
- let innerEndIndex = index + 1;
1491
- let insertIndex = -1;
1492
- let posInSet = -1;
1493
- const oldDirent = dirents[index];
1494
- const newDirent = {
1495
- ...oldDirent,
1496
- name: newName,
1497
- path: oldDirent.path.slice(0, -oldDirent.name.length) + newName,
1498
- icon: ''
1499
- };
1500
- const {
1501
- depth
1502
- } = newDirent;
1503
- // TODO
1504
- for (; startIndex >= 0; startIndex--) {
1505
- const dirent = dirents[startIndex];
1506
- if (dirent.depth > depth) {
1507
- continue;
1508
- }
1509
- if (dirent.depth < depth) {
1510
- break;
1511
- }
1512
- if (compareDirent(dirent, newDirent) === 1) {
1513
- insertIndex = startIndex;
1514
- posInSet = dirent.posInSet;
1515
- // dirent.posInSet++
1516
- }
1517
- }
1518
- startIndex++;
1519
- for (; innerEndIndex < dirents.length; innerEndIndex++) {
1520
- const dirent = dirents[innerEndIndex];
1521
- if (dirent.depth <= depth) {
1522
- break;
1523
- }
1524
- dirent.path = newDirent.path + dirent.path.slice(oldDirent.path.length);
1525
- }
1526
- innerEndIndex--;
1527
- let endIndex = innerEndIndex + 1;
1528
- for (; endIndex < dirents.length; endIndex++) {
1529
- const dirent = dirents[endIndex];
1530
- if (dirent.depth > depth) {
1531
- continue;
1532
- }
1533
- if (dirent.depth < depth) {
1534
- break;
1535
- }
1536
- if (insertIndex === -1 && compareDirent(dirent, newDirent) === -1) {
1537
- for (; endIndex < dirents.length; endIndex++) {
1538
- }
1539
- insertIndex = endIndex;
1540
- posInSet = dirent.posInSet + 1;
1541
- }
1542
- }
1543
- endIndex--;
1544
- for (let j = startIndex; j < index; j++) {
1545
- const dirent = dirents[j];
1546
- if (dirent.depth === depth) {
1547
- dirent.posInSet++;
1548
- }
1549
- }
1550
- for (let j = index; j < endIndex; j++) {
1551
- const dirent = dirents[j];
1552
- if (dirent.depth === depth) {
1553
- dirent.posInSet--;
1554
- }
1555
- }
1556
-
1557
- // for (let j = startIndex; j < index; j++) {
1558
- // const dirent = dirents[j]
1559
- // dirent.posInSet++
1560
- // }
1561
-
1562
- if (insertIndex === -1) {
1563
- insertIndex = index;
1564
- return {
1565
- focusedIndex: index,
1566
- newDirents: [...dirents.slice(0, index), newDirent, ...dirents.slice(index + 1)]
1567
- };
1568
- }
1569
- newDirent.posInSet = posInSet;
1570
- const newDirents = [...dirents];
1571
- if (index < insertIndex) {
1572
- insertIndex--;
1573
- }
1574
- newDirents.splice(index, 1);
1575
- newDirents.splice(insertIndex, 0, newDirent);
1514
+ const computeExplorerRenamedDirentUpdate = async (root, parentPath, parentDepth) => {
1515
+ const children = await getChildDirents('/', parentPath, parentDepth, []);
1516
+ const relativeDirname = parentPath.slice(root.length);
1576
1517
  return {
1577
- newDirents,
1578
- focusedIndex: insertIndex
1518
+ [relativeDirname]: children
1579
1519
  };
1580
1520
  };
1581
1521
 
@@ -1593,30 +1533,55 @@ const createNewDirentsRename = async (renamedDirent, editingValue, pathSeparator
1593
1533
  return true;
1594
1534
  };
1595
1535
 
1536
+ const updateTree2 = (tree, update) => {
1537
+ const updatedTree = {
1538
+ ...tree,
1539
+ ...update
1540
+ };
1541
+ return updatedTree;
1542
+ };
1543
+
1596
1544
  const acceptRename = async state => {
1597
1545
  const {
1598
1546
  editingIndex,
1599
1547
  editingValue,
1600
- items} = state;
1548
+ items,
1549
+ root,
1550
+ minLineY,
1551
+ height,
1552
+ itemHeight,
1553
+ fileIconCache
1554
+ } = state;
1601
1555
  const renamedDirent = items[editingIndex];
1602
1556
  const successful = await createNewDirentsRename(renamedDirent, editingValue);
1603
1557
  if (!successful) {
1604
1558
  return state;
1605
1559
  }
1560
+ const dirname = dirname2(renamedDirent.path);
1561
+ const newUri = join2(dirname, editingValue);
1562
+ const update = await computeExplorerRenamedDirentUpdate(root, dirname, renamedDirent.depth - 1);
1563
+ const tree = createTree(items, root);
1564
+ const newTree = updateTree2(tree, update);
1565
+ const newDirents = treeToArray(newTree, root);
1566
+ const newFocusedIndex = getIndex(newDirents, newUri);
1567
+ const maxLineY = getExplorerMaxLineY(minLineY, height, itemHeight, newDirents.length);
1568
+ const visible = newDirents.slice(minLineY, maxLineY);
1606
1569
  const {
1607
- newDirents,
1608
- focusedIndex
1609
- } = computeExplorerRenamedDirent(items, editingIndex, editingValue);
1570
+ icons,
1571
+ newFileIconCache
1572
+ } = await getFileIcons(visible, fileIconCache);
1610
1573
  return {
1611
1574
  ...state,
1612
1575
  editingIndex: -1,
1613
1576
  editingValue: '',
1614
1577
  editingType: None$5,
1615
1578
  editingIcon: '',
1616
- focusedIndex,
1579
+ focusedIndex: newFocusedIndex,
1617
1580
  focused: true,
1618
1581
  focus: List,
1619
- items: newDirents
1582
+ items: newDirents,
1583
+ icons,
1584
+ fileIconCache: newFileIconCache
1620
1585
  };
1621
1586
  };
1622
1587
 
@@ -2019,7 +1984,7 @@ const expandAll = async state => {
2019
1984
  dirent.type = DirectoryExpanding;
2020
1985
  // TODO handle error
2021
1986
  // TODO race condition
2022
- const childDirents = await getChildDirents(pathSeparator, dirent);
1987
+ const childDirents = await getChildDirents(pathSeparator, dirent.path, dirent.depth);
2023
1988
  const newIndex = newDirents.indexOf(dirent);
2024
1989
  if (newIndex === -1) {
2025
1990
  continue;
@@ -2064,7 +2029,7 @@ const getChildDirentsRecursively = async (dirent, pathSeparator) => {
2064
2029
  case Directory:
2065
2030
  case DirectoryExpanding:
2066
2031
  case DirectoryExpanded:
2067
- const childDirents = await getChildDirents(pathSeparator, dirent);
2032
+ const childDirents = await getChildDirents(pathSeparator, dirent.path, dirent.depth);
2068
2033
  const all = [makeExpanded(dirent)];
2069
2034
  for (const childDirent of childDirents) {
2070
2035
  const childAll = await getChildDirentsRecursively(childDirent, pathSeparator);
@@ -2657,7 +2622,7 @@ const handleClickDirectory = async (state, dirent, index, keepFocus) => {
2657
2622
  // @ts-ignore
2658
2623
  dirent.type = DirectoryExpanding;
2659
2624
  // TODO handle error
2660
- const dirents = await getChildDirents(state.pathSeparator, dirent);
2625
+ const dirents = await getChildDirents(state.pathSeparator, dirent.path, dirent.depth);
2661
2626
  const state2 = state;
2662
2627
  if (!state2) {
2663
2628
  return state;
@@ -2919,7 +2884,10 @@ const handleRangeSelection = (state, startIndex, endIndex) => {
2919
2884
  };
2920
2885
 
2921
2886
  const handleClickAtRangeSelection = async (state, index) => {
2922
- const firstSelectedIndex = state.items.findIndex(item => item.selected);
2887
+ const {
2888
+ items
2889
+ } = state;
2890
+ const firstSelectedIndex = items.findIndex(item => item.selected);
2923
2891
  if (firstSelectedIndex === -1) {
2924
2892
  return handleRangeSelection(state, index, index);
2925
2893
  }
@@ -2929,10 +2897,7 @@ const handleClickAtRangeSelection = async (state, index) => {
2929
2897
  };
2930
2898
 
2931
2899
  const handleClickAt = async (state, defaultPrevented, button, ctrlKey, shiftKey, x, y) => {
2932
- if (defaultPrevented) {
2933
- return state;
2934
- }
2935
- if (button !== LeftClick) {
2900
+ if (defaultPrevented || button !== LeftClick) {
2936
2901
  return state;
2937
2902
  }
2938
2903
  const index = getIndexFromPosition(state, x, y);
@@ -3294,10 +3259,7 @@ const mergeDirents$2 = (oldDirents, newDirents) => {
3294
3259
  return newDirents;
3295
3260
  };
3296
3261
  const getMergedDirents$2 = async (root, pathSeparator, dirents) => {
3297
- const childDirents = await getChildDirents(pathSeparator, {
3298
- path: root,
3299
- depth: 0
3300
- });
3262
+ const childDirents = await getChildDirents(pathSeparator, root, 0);
3301
3263
  const mergedDirents = mergeDirents$2(dirents, childDirents);
3302
3264
  return mergedDirents;
3303
3265
  };
@@ -3351,10 +3313,7 @@ const mergeDirents$1 = (oldDirents, newDirents) => {
3351
3313
  return newDirents;
3352
3314
  };
3353
3315
  const getMergedDirents$1 = async (root, pathSeparator, dirents) => {
3354
- const childDirents = await getChildDirents(pathSeparator, {
3355
- path: root,
3356
- depth: 0
3357
- });
3316
+ const childDirents = await getChildDirents(pathSeparator, root, 0);
3358
3317
  const mergedDirents = mergeDirents$1(dirents, childDirents);
3359
3318
  return mergedDirents;
3360
3319
  };
@@ -3417,7 +3376,7 @@ const handleDropIntoFolder = async (state, dirent, index, fileHandles, files, pa
3417
3376
  // @ts-ignore
3418
3377
  await copy$1(file, to);
3419
3378
  }
3420
- const childDirents = await getChildDirents(pathSeparator, dirent);
3379
+ const childDirents = await getChildDirents(pathSeparator, dirent.path, dirent.depth);
3421
3380
  const mergedDirents = getMergedDirents(items, index, dirent, childDirents);
3422
3381
  // TODO update maxlineY
3423
3382
  return {
@@ -3623,11 +3582,7 @@ const getTopLevelDirents = (root, pathSeparator, excluded) => {
3623
3582
  if (!root) {
3624
3583
  return [];
3625
3584
  }
3626
- return getChildDirents(pathSeparator, {
3627
- depth: 0,
3628
- path: root,
3629
- type: Directory
3630
- }, excluded);
3585
+ return getChildDirents(pathSeparator, root, 0, excluded);
3631
3586
  };
3632
3587
 
3633
3588
  const mergeDirents = (oldDirents, newDirents) => {
@@ -4933,16 +4888,6 @@ const restoreState = savedState => {
4933
4888
  };
4934
4889
  };
4935
4890
 
4936
- const getIndex = (dirents, uri) => {
4937
- for (let i = 0; i < dirents.length; i++) {
4938
- const dirent = dirents[i];
4939
- if (dirent.path === uri) {
4940
- return i;
4941
- }
4942
- }
4943
- return -1;
4944
- };
4945
-
4946
4891
  const getPathPartsToReveal = (root, pathParts, dirents) => {
4947
4892
  for (let i = 0; i < pathParts.length; i++) {
4948
4893
  const pathPart = pathParts[i];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.39.0",
3
+ "version": "2.41.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",