@lvce-editor/explorer-view 2.34.0 → 2.35.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.
@@ -1397,7 +1397,7 @@ const acceptRename = async state => {
1397
1397
  // TODO this does not work with rename of nested file
1398
1398
  const oldAbsolutePath = renamedDirent.path;
1399
1399
  const oldParentPath = dirname(pathSeparator, oldAbsolutePath);
1400
- const newAbsolutePath = [oldParentPath, editingValue].join(pathSeparator);
1400
+ const newAbsolutePath = join2(oldParentPath, editingValue);
1401
1401
  await rename(oldAbsolutePath, newAbsolutePath);
1402
1402
  } catch (error) {
1403
1403
  console.error(new VError(error, `Failed to rename file`));
@@ -1407,9 +1407,6 @@ const acceptRename = async state => {
1407
1407
  newDirents,
1408
1408
  focusedIndex
1409
1409
  } = computeExplorerRenamedDirent(items, editingIndex, editingValue);
1410
- // TODO move focused index
1411
- // @ts-ignore
1412
- state.items = newDirents;
1413
1410
  return {
1414
1411
  ...state,
1415
1412
  editingIndex: -1,
@@ -1418,7 +1415,8 @@ const acceptRename = async state => {
1418
1415
  editingIcon: '',
1419
1416
  focusedIndex,
1420
1417
  focused: true,
1421
- focus: List
1418
+ focus: List,
1419
+ items: newDirents
1422
1420
  };
1423
1421
  };
1424
1422
 
@@ -1438,6 +1436,28 @@ const acceptEdit = async state => {
1438
1436
  }
1439
1437
  };
1440
1438
 
1439
+ const isNormalItem = item => {
1440
+ return item.type !== EditingFile && item.type !== EditingFolder;
1441
+ };
1442
+
1443
+ const cancelEditCreate = (state, keepFocus) => {
1444
+ const {
1445
+ editingIndex,
1446
+ items
1447
+ } = state;
1448
+ const filteredItems = items.filter(isNormalItem);
1449
+ return {
1450
+ ...state,
1451
+ items: filteredItems,
1452
+ focusedIndex: editingIndex,
1453
+ focused: keepFocus,
1454
+ editingIndex: -1,
1455
+ editingValue: '',
1456
+ editingType: None$5,
1457
+ focus: List
1458
+ };
1459
+ };
1460
+
1441
1461
  const normalizeDirentType = direntType => {
1442
1462
  if (direntType > DELTA_EDITING) {
1443
1463
  return direntType - DELTA_EDITING;
@@ -1455,33 +1475,17 @@ const getNewDirentsForCancelRename = (items, editingIndex) => {
1455
1475
  return newItems;
1456
1476
  };
1457
1477
 
1458
- const isNormalItem = item => {
1459
- return item.type !== EditingFile && item.type !== EditingFolder;
1460
- };
1461
- const cancelEdit = state => {
1478
+ const cancelEditRename = (state, keepFocus) => {
1462
1479
  const {
1463
1480
  editingIndex,
1464
- editingType
1481
+ items
1465
1482
  } = state;
1466
- if (editingType === Rename$1) {
1467
- const newItems = getNewDirentsForCancelRename(state.items, editingIndex);
1468
- return {
1469
- ...state,
1470
- items: newItems,
1471
- focusedIndex: editingIndex,
1472
- focused: true,
1473
- editingIndex: -1,
1474
- editingValue: '',
1475
- editingType: None$5,
1476
- focus: List
1477
- };
1478
- }
1479
- const filteredItems = state.items.filter(isNormalItem);
1483
+ const newItems = getNewDirentsForCancelRename(items, editingIndex);
1480
1484
  return {
1481
1485
  ...state,
1482
- items: filteredItems,
1486
+ items: newItems,
1483
1487
  focusedIndex: editingIndex,
1484
- focused: true,
1488
+ focused: keepFocus,
1485
1489
  editingIndex: -1,
1486
1490
  editingValue: '',
1487
1491
  editingType: None$5,
@@ -1489,6 +1493,20 @@ const cancelEdit = state => {
1489
1493
  };
1490
1494
  };
1491
1495
 
1496
+ const cancelEditInternal = (state, keepFocus) => {
1497
+ const {
1498
+ editingType
1499
+ } = state;
1500
+ if (editingType === Rename$1) {
1501
+ return cancelEditRename(state, keepFocus);
1502
+ }
1503
+ return cancelEditCreate(state, keepFocus);
1504
+ };
1505
+
1506
+ const cancelEdit = state => {
1507
+ return cancelEditInternal(state, true);
1508
+ };
1509
+
1492
1510
  const cancelTypeAhead = state => {
1493
1511
  return {
1494
1512
  ...state,
@@ -2645,15 +2663,9 @@ const handleArrowRight = async state => {
2645
2663
  }
2646
2664
  };
2647
2665
 
2648
- const handleBlur = state => {
2666
+ const handleBlur = async state => {
2649
2667
  // TODO when blur event occurs because of context menu, focused index should stay the same
2650
2668
  // but focus outline should be removed
2651
- const {
2652
- editingType
2653
- } = state;
2654
- if (editingType !== None$5) {
2655
- return state;
2656
- }
2657
2669
  return {
2658
2670
  ...state,
2659
2671
  focused: false
@@ -3436,8 +3448,15 @@ const handleIconThemeChange = state => {
3436
3448
  return updateIcons(state);
3437
3449
  };
3438
3450
 
3439
- const handleInputBlur = state => {
3440
- return cancelEdit(state);
3451
+ const handleInputBlur = async state => {
3452
+ const {
3453
+ editingErrorMessage,
3454
+ editingValue
3455
+ } = state;
3456
+ if (editingErrorMessage || !editingValue) {
3457
+ return cancelEditInternal(state, false);
3458
+ }
3459
+ return acceptEdit(state);
3441
3460
  };
3442
3461
 
3443
3462
  const handleInputClick = state => {
@@ -4193,7 +4212,6 @@ const HandleInputBlur = 'handleInputBlur';
4193
4212
  const HandleInputClick = 'handleInputClick';
4194
4213
  const HandleListBlur = 'handleListBlur';
4195
4214
  const HandleListFocus = 'handleListFocus';
4196
- const HandleListKeyDown = 'handleListKeyDown';
4197
4215
  const HandlePointerDown = 'handlePointerDown';
4198
4216
  const HandleWheel = 'handleWheel';
4199
4217
 
@@ -4380,8 +4398,8 @@ const getListItemsVirtualDom = (visibleItems, focusedIndex, focused, dropTargets
4380
4398
  onDrop: HandleDrop,
4381
4399
  onFocus: HandleListFocus,
4382
4400
  onPointerDown: HandlePointerDown,
4383
- onWheel: HandleWheel,
4384
- onKeyDown: HandleListKeyDown
4401
+ onWheel: HandleWheel
4402
+ // onKeyDown: DomEventListenerFunctions.HandleListKeyDown,
4385
4403
  }, ...visibleItems.flatMap(getExplorerItemVirtualDom)];
4386
4404
  return dom;
4387
4405
  };
@@ -5093,7 +5111,12 @@ const getEditingIcon = async (editingType, value, direntType) => {
5093
5111
  };
5094
5112
 
5095
5113
  const updateEditingValue = async (state, value, inputSource = User) => {
5096
- const editingIcon = await getEditingIcon(state.editingType, value, state.items[state.editingIndex]?.type);
5114
+ const {
5115
+ editingType,
5116
+ items,
5117
+ editingIndex
5118
+ } = state;
5119
+ const editingIcon = await getEditingIcon(editingType, value, items[editingIndex]?.type);
5097
5120
  return {
5098
5121
  ...state,
5099
5122
  editingValue: value,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.34.0",
3
+ "version": "2.35.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",