@lvce-editor/explorer-view 5.8.0 → 5.10.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.
- package/dist/explorerViewWorkerMain.js +262 -227
- package/package.json +1 -1
|
@@ -1059,6 +1059,7 @@ const DeltaY = 'event.deltaY';
|
|
|
1059
1059
|
const EventTargetClassName = 'event.target.className';
|
|
1060
1060
|
const IsTrusted = 'event.isTrusted';
|
|
1061
1061
|
const ShiftKey = 'event.shiftKey';
|
|
1062
|
+
const TargetName = 'event.target.name';
|
|
1062
1063
|
const TargetValue = 'event.target.value';
|
|
1063
1064
|
|
|
1064
1065
|
const Enter = 3;
|
|
@@ -1839,8 +1840,8 @@ const FileOrFolderAlreadyExists = 'A file or folder **{PH1}** already exists at
|
|
|
1839
1840
|
const FileOrFolderNameMustBeProvider = 'A file or folder name must be provided.';
|
|
1840
1841
|
const FileCannotStartWithBackSlash = 'A file or folder name cannot start with a backslash.';
|
|
1841
1842
|
const FilesExplorer = 'Files Explorer';
|
|
1842
|
-
const NewFile$
|
|
1843
|
-
const NewFolder$
|
|
1843
|
+
const NewFile$2 = 'New File...';
|
|
1844
|
+
const NewFolder$2 = 'New Folder...';
|
|
1844
1845
|
const OpenContainingFolder = 'Open Containing Folder';
|
|
1845
1846
|
const OpenFolder$1 = 'Open folder';
|
|
1846
1847
|
const OpenInIntegratedTerminal = 'Open in integrated Terminal';
|
|
@@ -1852,10 +1853,10 @@ const TypeAFileName = 'Type file name. Press Enter to confirm or Escape to cance
|
|
|
1852
1853
|
const YouHaveNotYetOpenedAFolder = 'You have not yet opened a folder';
|
|
1853
1854
|
|
|
1854
1855
|
const newFile$1 = () => {
|
|
1855
|
-
return i18nString(NewFile$
|
|
1856
|
+
return i18nString(NewFile$2);
|
|
1856
1857
|
};
|
|
1857
1858
|
const newFolder$1 = () => {
|
|
1858
|
-
return i18nString(NewFolder$
|
|
1859
|
+
return i18nString(NewFolder$2);
|
|
1859
1860
|
};
|
|
1860
1861
|
const openContainingFolder$1 = () => {
|
|
1861
1862
|
return i18nString(OpenContainingFolder);
|
|
@@ -3438,6 +3439,239 @@ const handleBlur = async state => {
|
|
|
3438
3439
|
};
|
|
3439
3440
|
};
|
|
3440
3441
|
|
|
3442
|
+
const CollapseAll$1 = 'CollapseAll';
|
|
3443
|
+
const ExplorerInput = 'ExplorerInput';
|
|
3444
|
+
const NewFile$1 = 'NewFile';
|
|
3445
|
+
const NewFolder$1 = 'NewFolder';
|
|
3446
|
+
const OpenFolder = 'OpenFolder';
|
|
3447
|
+
const Refresh$1 = 'Refresh';
|
|
3448
|
+
|
|
3449
|
+
const getNewChildDirentsForNewDirent = async (items, depth, parentPath, direntType) => {
|
|
3450
|
+
// Get existing children or query them if they don't exist
|
|
3451
|
+
let existingChildren = items.filter(item => item.depth === depth && item.path.startsWith(parentPath));
|
|
3452
|
+
if (existingChildren.length === 0) {
|
|
3453
|
+
const childDirents = await readDirWithFileTypes(parentPath);
|
|
3454
|
+
existingChildren = childDirents.map((dirent, index) => ({
|
|
3455
|
+
depth,
|
|
3456
|
+
icon: '',
|
|
3457
|
+
name: dirent.name,
|
|
3458
|
+
path: join2(parentPath, dirent.name),
|
|
3459
|
+
posInSet: index + 1,
|
|
3460
|
+
selected: false,
|
|
3461
|
+
setSize: childDirents.length,
|
|
3462
|
+
type: dirent.type
|
|
3463
|
+
}));
|
|
3464
|
+
}
|
|
3465
|
+
const updatedChildren = existingChildren.map((child, index) => ({
|
|
3466
|
+
...child,
|
|
3467
|
+
posInSet: index + 1,
|
|
3468
|
+
setSize: existingChildren.length + 2
|
|
3469
|
+
}));
|
|
3470
|
+
const newDirent = {
|
|
3471
|
+
depth,
|
|
3472
|
+
icon: '',
|
|
3473
|
+
name: '',
|
|
3474
|
+
path: parentPath,
|
|
3475
|
+
posInSet: updatedChildren.length + 1,
|
|
3476
|
+
selected: false,
|
|
3477
|
+
setSize: existingChildren.length + 2,
|
|
3478
|
+
type: direntType
|
|
3479
|
+
};
|
|
3480
|
+
const allChildDirents = [...updatedChildren, newDirent];
|
|
3481
|
+
return allChildDirents;
|
|
3482
|
+
};
|
|
3483
|
+
|
|
3484
|
+
const getNewDirentsForNewDirent = async (items, focusedIndex, type, root) => {
|
|
3485
|
+
if (items.length === 0 || focusedIndex === -1) {
|
|
3486
|
+
const newDirent = {
|
|
3487
|
+
depth: 0,
|
|
3488
|
+
icon: '',
|
|
3489
|
+
name: '',
|
|
3490
|
+
path: root,
|
|
3491
|
+
posInSet: 1,
|
|
3492
|
+
selected: false,
|
|
3493
|
+
setSize: 1,
|
|
3494
|
+
type
|
|
3495
|
+
};
|
|
3496
|
+
return [...items, newDirent];
|
|
3497
|
+
}
|
|
3498
|
+
const focusedItem = items[focusedIndex];
|
|
3499
|
+
if (!focusedItem) {
|
|
3500
|
+
return items;
|
|
3501
|
+
}
|
|
3502
|
+
const parentPath = focusedItem.path;
|
|
3503
|
+
const depth = focusedItem.depth + 1;
|
|
3504
|
+
const updatedChildren = await getNewChildDirentsForNewDirent(items, depth, parentPath, type);
|
|
3505
|
+
|
|
3506
|
+
// Create new array with updated items
|
|
3507
|
+
const parentIndex = focusedIndex;
|
|
3508
|
+
const itemsBeforeParent = items.slice(0, parentIndex);
|
|
3509
|
+
const itemsAfterChildren = items.slice(parentIndex + updatedChildren.length);
|
|
3510
|
+
const updatedParent = {
|
|
3511
|
+
...items[parentIndex],
|
|
3512
|
+
setSize: (items[parentIndex]?.setSize || 0) + 1
|
|
3513
|
+
};
|
|
3514
|
+
return [...itemsBeforeParent, updatedParent, ...updatedChildren, ...itemsAfterChildren];
|
|
3515
|
+
};
|
|
3516
|
+
|
|
3517
|
+
const getNewDirentType = editingType => {
|
|
3518
|
+
switch (editingType) {
|
|
3519
|
+
case CreateFile:
|
|
3520
|
+
return EditingFile;
|
|
3521
|
+
case CreateFolder:
|
|
3522
|
+
return EditingFolder;
|
|
3523
|
+
default:
|
|
3524
|
+
return File;
|
|
3525
|
+
}
|
|
3526
|
+
};
|
|
3527
|
+
|
|
3528
|
+
const isFolder = direntType => {
|
|
3529
|
+
return direntType === Directory || direntType === DirectoryExpanded || direntType === SymLinkFolder;
|
|
3530
|
+
};
|
|
3531
|
+
const getFittingIndex = (dirents, startIndex) => {
|
|
3532
|
+
for (let i = startIndex; i >= 0; i--) {
|
|
3533
|
+
const dirent = dirents[i];
|
|
3534
|
+
if (isFolder(dirent.type)) {
|
|
3535
|
+
return i;
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
return -1;
|
|
3539
|
+
};
|
|
3540
|
+
const newDirent = async (state, editingType) => {
|
|
3541
|
+
// TODO do it like vscode, select position between folders and files
|
|
3542
|
+
const {
|
|
3543
|
+
focusedIndex,
|
|
3544
|
+
items,
|
|
3545
|
+
root
|
|
3546
|
+
} = state;
|
|
3547
|
+
const index = getFittingIndex(items, focusedIndex);
|
|
3548
|
+
const direntType = getNewDirentType(editingType);
|
|
3549
|
+
const newDirents = await getNewDirentsForNewDirent(items, index, direntType, root);
|
|
3550
|
+
const editingIndex = newDirents.findIndex(item => item.type === EditingFile || item.type === EditingFolder);
|
|
3551
|
+
return {
|
|
3552
|
+
...state,
|
|
3553
|
+
editingIndex,
|
|
3554
|
+
editingType,
|
|
3555
|
+
editingValue: '',
|
|
3556
|
+
focus: Input$1,
|
|
3557
|
+
focusedIndex: editingIndex,
|
|
3558
|
+
items: newDirents
|
|
3559
|
+
};
|
|
3560
|
+
};
|
|
3561
|
+
|
|
3562
|
+
// TODO much shared logic with newFolder
|
|
3563
|
+
const newFile = state => {
|
|
3564
|
+
return newDirent(state, CreateFile);
|
|
3565
|
+
};
|
|
3566
|
+
|
|
3567
|
+
const newFolder = state => {
|
|
3568
|
+
return newDirent(state, CreateFolder);
|
|
3569
|
+
};
|
|
3570
|
+
|
|
3571
|
+
const isExpanded = item => {
|
|
3572
|
+
return item.type === DirectoryExpanded || item.type === DirectoryExpanding;
|
|
3573
|
+
};
|
|
3574
|
+
|
|
3575
|
+
const getExpandedDirents = items => {
|
|
3576
|
+
return items.filter(isExpanded);
|
|
3577
|
+
};
|
|
3578
|
+
|
|
3579
|
+
const getPathDirentsMap = async allPaths => {
|
|
3580
|
+
const pathToDirents = Object.create(null);
|
|
3581
|
+
await Promise.all(allPaths.map(async path => {
|
|
3582
|
+
try {
|
|
3583
|
+
const dirents = await readDirWithFileTypes(path);
|
|
3584
|
+
pathToDirents[path] = dirents;
|
|
3585
|
+
} catch {
|
|
3586
|
+
// ignore
|
|
3587
|
+
}
|
|
3588
|
+
}));
|
|
3589
|
+
return pathToDirents;
|
|
3590
|
+
};
|
|
3591
|
+
|
|
3592
|
+
const restoreDirentType = (rawDirentType, path, expandedPaths) => {
|
|
3593
|
+
if (rawDirentType === Directory && expandedPaths.includes(path)) {
|
|
3594
|
+
return DirectoryExpanded;
|
|
3595
|
+
}
|
|
3596
|
+
return rawDirentType;
|
|
3597
|
+
};
|
|
3598
|
+
|
|
3599
|
+
const getProtoMapInternal = (root, pathToDirents, expandedPaths, depth) => {
|
|
3600
|
+
if (!(root in pathToDirents)) {
|
|
3601
|
+
return [];
|
|
3602
|
+
}
|
|
3603
|
+
const items = pathToDirents[root] || [];
|
|
3604
|
+
const protoMap = [];
|
|
3605
|
+
for (let i = 0; i < items.length; i++) {
|
|
3606
|
+
const item = items[i];
|
|
3607
|
+
const path = join2(root, item.name);
|
|
3608
|
+
const displayDirent = {
|
|
3609
|
+
depth,
|
|
3610
|
+
icon: '',
|
|
3611
|
+
name: item.name,
|
|
3612
|
+
path,
|
|
3613
|
+
posInSet: i + 1,
|
|
3614
|
+
selected: false,
|
|
3615
|
+
setSize: items.length,
|
|
3616
|
+
type: restoreDirentType(item.type, path, expandedPaths)
|
|
3617
|
+
};
|
|
3618
|
+
const children = getProtoMapInternal(path, pathToDirents, expandedPaths, depth + 1);
|
|
3619
|
+
protoMap.push(displayDirent, ...children);
|
|
3620
|
+
}
|
|
3621
|
+
return protoMap;
|
|
3622
|
+
};
|
|
3623
|
+
|
|
3624
|
+
const getProtoMap = (root, pathToDirents, expandedPaths) => {
|
|
3625
|
+
return getProtoMapInternal(root, pathToDirents, expandedPaths, 1);
|
|
3626
|
+
};
|
|
3627
|
+
|
|
3628
|
+
const sortPathDirentsMap = map => {
|
|
3629
|
+
const sortedMap = Object.create(null);
|
|
3630
|
+
for (const [key, value] of Object.entries(map)) {
|
|
3631
|
+
const sorted = sortExplorerItems(value);
|
|
3632
|
+
sortedMap[key] = sorted;
|
|
3633
|
+
}
|
|
3634
|
+
return sortedMap;
|
|
3635
|
+
};
|
|
3636
|
+
|
|
3637
|
+
const refresh = async state => {
|
|
3638
|
+
const {
|
|
3639
|
+
focusedIndex,
|
|
3640
|
+
items,
|
|
3641
|
+
root
|
|
3642
|
+
} = state;
|
|
3643
|
+
const expandedDirents = getExpandedDirents(items);
|
|
3644
|
+
const expandedPaths = getPaths(expandedDirents);
|
|
3645
|
+
const allPaths = [root, ...expandedPaths];
|
|
3646
|
+
const pathToDirents = await getPathDirentsMap(allPaths);
|
|
3647
|
+
const sortedPathDirents = sortPathDirentsMap(pathToDirents);
|
|
3648
|
+
const newItems = getProtoMap(root, sortedPathDirents, expandedPaths);
|
|
3649
|
+
let newFocusedIndex = focusedIndex;
|
|
3650
|
+
if (focusedIndex >= newItems.length) {
|
|
3651
|
+
newFocusedIndex = newItems.length - 1;
|
|
3652
|
+
}
|
|
3653
|
+
return {
|
|
3654
|
+
...state,
|
|
3655
|
+
focusedIndex: newFocusedIndex,
|
|
3656
|
+
items: newItems
|
|
3657
|
+
};
|
|
3658
|
+
};
|
|
3659
|
+
|
|
3660
|
+
const handleButtonClick = async (state, name) => {
|
|
3661
|
+
switch (name) {
|
|
3662
|
+
case CollapseAll$1:
|
|
3663
|
+
return collapseAll(state);
|
|
3664
|
+
case NewFile$1:
|
|
3665
|
+
return newFile(state);
|
|
3666
|
+
case NewFolder$1:
|
|
3667
|
+
return newFolder(state);
|
|
3668
|
+
case Refresh$1:
|
|
3669
|
+
return refresh(state);
|
|
3670
|
+
default:
|
|
3671
|
+
return state;
|
|
3672
|
+
}
|
|
3673
|
+
};
|
|
3674
|
+
|
|
3441
3675
|
class ExplorerError extends Error {
|
|
3442
3676
|
constructor(message) {
|
|
3443
3677
|
super(message);
|
|
@@ -3528,13 +3762,12 @@ const resetEditing = {
|
|
|
3528
3762
|
|
|
3529
3763
|
const handleClick = async (state, index, keepFocus = false) => {
|
|
3530
3764
|
const {
|
|
3531
|
-
items
|
|
3532
|
-
minLineY
|
|
3765
|
+
items
|
|
3533
3766
|
} = state;
|
|
3534
3767
|
if (index === -1) {
|
|
3535
3768
|
return focusIndex(state, -1);
|
|
3536
3769
|
}
|
|
3537
|
-
const actualIndex = index
|
|
3770
|
+
const actualIndex = index;
|
|
3538
3771
|
const dirent = items[actualIndex];
|
|
3539
3772
|
if (!dirent) {
|
|
3540
3773
|
console.warn(`[explorer] dirent at index ${actualIndex} not found`, state);
|
|
@@ -3563,6 +3796,7 @@ const getIndexFromPosition = (state, eventX, eventY) => {
|
|
|
3563
3796
|
const {
|
|
3564
3797
|
itemHeight,
|
|
3565
3798
|
items,
|
|
3799
|
+
minLineY,
|
|
3566
3800
|
y
|
|
3567
3801
|
} = state;
|
|
3568
3802
|
const index = Math.floor((eventY - y) / itemHeight);
|
|
@@ -3572,7 +3806,7 @@ const getIndexFromPosition = (state, eventX, eventY) => {
|
|
|
3572
3806
|
if (index >= items.length) {
|
|
3573
3807
|
return -1;
|
|
3574
3808
|
}
|
|
3575
|
-
return index;
|
|
3809
|
+
return index + minLineY;
|
|
3576
3810
|
};
|
|
3577
3811
|
|
|
3578
3812
|
/**
|
|
@@ -3636,7 +3870,7 @@ const handleClickAt = async (state, defaultPrevented, button, ctrlKey, shiftKey,
|
|
|
3636
3870
|
return state;
|
|
3637
3871
|
}
|
|
3638
3872
|
const index = getIndexFromPosition(state, eventX, eventY);
|
|
3639
|
-
if (index === -1) {
|
|
3873
|
+
if (index === -1 || index >= state.items.length) {
|
|
3640
3874
|
return {
|
|
3641
3875
|
...state,
|
|
3642
3876
|
focused: true,
|
|
@@ -3866,95 +4100,6 @@ const handleDragStart = state => {
|
|
|
3866
4100
|
return state;
|
|
3867
4101
|
};
|
|
3868
4102
|
|
|
3869
|
-
const isExpanded = item => {
|
|
3870
|
-
return item.type === DirectoryExpanded || item.type === DirectoryExpanding;
|
|
3871
|
-
};
|
|
3872
|
-
|
|
3873
|
-
const getExpandedDirents = items => {
|
|
3874
|
-
return items.filter(isExpanded);
|
|
3875
|
-
};
|
|
3876
|
-
|
|
3877
|
-
const getPathDirentsMap = async allPaths => {
|
|
3878
|
-
const pathToDirents = Object.create(null);
|
|
3879
|
-
await Promise.all(allPaths.map(async path => {
|
|
3880
|
-
try {
|
|
3881
|
-
const dirents = await readDirWithFileTypes(path);
|
|
3882
|
-
pathToDirents[path] = dirents;
|
|
3883
|
-
} catch {
|
|
3884
|
-
// ignore
|
|
3885
|
-
}
|
|
3886
|
-
}));
|
|
3887
|
-
return pathToDirents;
|
|
3888
|
-
};
|
|
3889
|
-
|
|
3890
|
-
const restoreDirentType = (rawDirentType, path, expandedPaths) => {
|
|
3891
|
-
if (rawDirentType === Directory && expandedPaths.includes(path)) {
|
|
3892
|
-
return DirectoryExpanded;
|
|
3893
|
-
}
|
|
3894
|
-
return rawDirentType;
|
|
3895
|
-
};
|
|
3896
|
-
|
|
3897
|
-
const getProtoMapInternal = (root, pathToDirents, expandedPaths, depth) => {
|
|
3898
|
-
if (!(root in pathToDirents)) {
|
|
3899
|
-
return [];
|
|
3900
|
-
}
|
|
3901
|
-
const items = pathToDirents[root] || [];
|
|
3902
|
-
const protoMap = [];
|
|
3903
|
-
for (let i = 0; i < items.length; i++) {
|
|
3904
|
-
const item = items[i];
|
|
3905
|
-
const path = join2(root, item.name);
|
|
3906
|
-
const displayDirent = {
|
|
3907
|
-
depth,
|
|
3908
|
-
icon: '',
|
|
3909
|
-
name: item.name,
|
|
3910
|
-
path,
|
|
3911
|
-
posInSet: i + 1,
|
|
3912
|
-
selected: false,
|
|
3913
|
-
setSize: items.length,
|
|
3914
|
-
type: restoreDirentType(item.type, path, expandedPaths)
|
|
3915
|
-
};
|
|
3916
|
-
const children = getProtoMapInternal(path, pathToDirents, expandedPaths, depth + 1);
|
|
3917
|
-
protoMap.push(displayDirent, ...children);
|
|
3918
|
-
}
|
|
3919
|
-
return protoMap;
|
|
3920
|
-
};
|
|
3921
|
-
|
|
3922
|
-
const getProtoMap = (root, pathToDirents, expandedPaths) => {
|
|
3923
|
-
return getProtoMapInternal(root, pathToDirents, expandedPaths, 1);
|
|
3924
|
-
};
|
|
3925
|
-
|
|
3926
|
-
const sortPathDirentsMap = map => {
|
|
3927
|
-
const sortedMap = Object.create(null);
|
|
3928
|
-
for (const [key, value] of Object.entries(map)) {
|
|
3929
|
-
const sorted = sortExplorerItems(value);
|
|
3930
|
-
sortedMap[key] = sorted;
|
|
3931
|
-
}
|
|
3932
|
-
return sortedMap;
|
|
3933
|
-
};
|
|
3934
|
-
|
|
3935
|
-
const refresh = async state => {
|
|
3936
|
-
const {
|
|
3937
|
-
focusedIndex,
|
|
3938
|
-
items,
|
|
3939
|
-
root
|
|
3940
|
-
} = state;
|
|
3941
|
-
const expandedDirents = getExpandedDirents(items);
|
|
3942
|
-
const expandedPaths = getPaths(expandedDirents);
|
|
3943
|
-
const allPaths = [root, ...expandedPaths];
|
|
3944
|
-
const pathToDirents = await getPathDirentsMap(allPaths);
|
|
3945
|
-
const sortedPathDirents = sortPathDirentsMap(pathToDirents);
|
|
3946
|
-
const newItems = getProtoMap(root, sortedPathDirents, expandedPaths);
|
|
3947
|
-
let newFocusedIndex = focusedIndex;
|
|
3948
|
-
if (focusedIndex >= newItems.length) {
|
|
3949
|
-
newFocusedIndex = newItems.length - 1;
|
|
3950
|
-
}
|
|
3951
|
-
return {
|
|
3952
|
-
...state,
|
|
3953
|
-
focusedIndex: newFocusedIndex,
|
|
3954
|
-
items: newItems
|
|
3955
|
-
};
|
|
3956
|
-
};
|
|
3957
|
-
|
|
3958
4103
|
const getChildHandles = async fileHandle => {
|
|
3959
4104
|
// @ts-ignore
|
|
3960
4105
|
const values = fileHandle.values();
|
|
@@ -4959,128 +5104,6 @@ const initialize = async () => {
|
|
|
4959
5104
|
await Promise.all([initializeFileSystemWorker(), initializeIconThemeWorker(), initializeSourceControlWorker()]);
|
|
4960
5105
|
};
|
|
4961
5106
|
|
|
4962
|
-
const getNewChildDirentsForNewDirent = async (items, depth, parentPath, direntType) => {
|
|
4963
|
-
// Get existing children or query them if they don't exist
|
|
4964
|
-
let existingChildren = items.filter(item => item.depth === depth && item.path.startsWith(parentPath));
|
|
4965
|
-
if (existingChildren.length === 0) {
|
|
4966
|
-
const childDirents = await readDirWithFileTypes(parentPath);
|
|
4967
|
-
existingChildren = childDirents.map((dirent, index) => ({
|
|
4968
|
-
depth,
|
|
4969
|
-
icon: '',
|
|
4970
|
-
name: dirent.name,
|
|
4971
|
-
path: join2(parentPath, dirent.name),
|
|
4972
|
-
posInSet: index + 1,
|
|
4973
|
-
selected: false,
|
|
4974
|
-
setSize: childDirents.length,
|
|
4975
|
-
type: dirent.type
|
|
4976
|
-
}));
|
|
4977
|
-
}
|
|
4978
|
-
const updatedChildren = existingChildren.map((child, index) => ({
|
|
4979
|
-
...child,
|
|
4980
|
-
posInSet: index + 1,
|
|
4981
|
-
setSize: existingChildren.length + 2
|
|
4982
|
-
}));
|
|
4983
|
-
const newDirent = {
|
|
4984
|
-
depth,
|
|
4985
|
-
icon: '',
|
|
4986
|
-
name: '',
|
|
4987
|
-
path: parentPath,
|
|
4988
|
-
posInSet: updatedChildren.length + 1,
|
|
4989
|
-
selected: false,
|
|
4990
|
-
setSize: existingChildren.length + 2,
|
|
4991
|
-
type: direntType
|
|
4992
|
-
};
|
|
4993
|
-
const allChildDirents = [...updatedChildren, newDirent];
|
|
4994
|
-
return allChildDirents;
|
|
4995
|
-
};
|
|
4996
|
-
|
|
4997
|
-
const getNewDirentsForNewDirent = async (items, focusedIndex, type, root) => {
|
|
4998
|
-
if (items.length === 0 || focusedIndex === -1) {
|
|
4999
|
-
const newDirent = {
|
|
5000
|
-
depth: 0,
|
|
5001
|
-
icon: '',
|
|
5002
|
-
name: '',
|
|
5003
|
-
path: root,
|
|
5004
|
-
posInSet: 1,
|
|
5005
|
-
selected: false,
|
|
5006
|
-
setSize: 1,
|
|
5007
|
-
type
|
|
5008
|
-
};
|
|
5009
|
-
return [...items, newDirent];
|
|
5010
|
-
}
|
|
5011
|
-
const focusedItem = items[focusedIndex];
|
|
5012
|
-
if (!focusedItem) {
|
|
5013
|
-
return items;
|
|
5014
|
-
}
|
|
5015
|
-
const parentPath = focusedItem.path;
|
|
5016
|
-
const depth = focusedItem.depth + 1;
|
|
5017
|
-
const updatedChildren = await getNewChildDirentsForNewDirent(items, depth, parentPath, type);
|
|
5018
|
-
|
|
5019
|
-
// Create new array with updated items
|
|
5020
|
-
const parentIndex = focusedIndex;
|
|
5021
|
-
const itemsBeforeParent = items.slice(0, parentIndex);
|
|
5022
|
-
const itemsAfterChildren = items.slice(parentIndex + updatedChildren.length);
|
|
5023
|
-
const updatedParent = {
|
|
5024
|
-
...items[parentIndex],
|
|
5025
|
-
setSize: (items[parentIndex]?.setSize || 0) + 1
|
|
5026
|
-
};
|
|
5027
|
-
return [...itemsBeforeParent, updatedParent, ...updatedChildren, ...itemsAfterChildren];
|
|
5028
|
-
};
|
|
5029
|
-
|
|
5030
|
-
const getNewDirentType = editingType => {
|
|
5031
|
-
switch (editingType) {
|
|
5032
|
-
case CreateFile:
|
|
5033
|
-
return EditingFile;
|
|
5034
|
-
case CreateFolder:
|
|
5035
|
-
return EditingFolder;
|
|
5036
|
-
default:
|
|
5037
|
-
return File;
|
|
5038
|
-
}
|
|
5039
|
-
};
|
|
5040
|
-
|
|
5041
|
-
const isFolder = direntType => {
|
|
5042
|
-
return direntType === Directory || direntType === DirectoryExpanded || direntType === SymLinkFolder;
|
|
5043
|
-
};
|
|
5044
|
-
const getFittingIndex = (dirents, startIndex) => {
|
|
5045
|
-
for (let i = startIndex; i >= 0; i--) {
|
|
5046
|
-
const dirent = dirents[i];
|
|
5047
|
-
if (isFolder(dirent.type)) {
|
|
5048
|
-
return i;
|
|
5049
|
-
}
|
|
5050
|
-
}
|
|
5051
|
-
return -1;
|
|
5052
|
-
};
|
|
5053
|
-
const newDirent = async (state, editingType) => {
|
|
5054
|
-
// TODO do it like vscode, select position between folders and files
|
|
5055
|
-
const {
|
|
5056
|
-
focusedIndex,
|
|
5057
|
-
items,
|
|
5058
|
-
root
|
|
5059
|
-
} = state;
|
|
5060
|
-
const index = getFittingIndex(items, focusedIndex);
|
|
5061
|
-
const direntType = getNewDirentType(editingType);
|
|
5062
|
-
const newDirents = await getNewDirentsForNewDirent(items, index, direntType, root);
|
|
5063
|
-
const editingIndex = newDirents.findIndex(item => item.type === EditingFile || item.type === EditingFolder);
|
|
5064
|
-
return {
|
|
5065
|
-
...state,
|
|
5066
|
-
editingIndex,
|
|
5067
|
-
editingType,
|
|
5068
|
-
editingValue: '',
|
|
5069
|
-
focus: Input$1,
|
|
5070
|
-
focusedIndex: editingIndex,
|
|
5071
|
-
items: newDirents
|
|
5072
|
-
};
|
|
5073
|
-
};
|
|
5074
|
-
|
|
5075
|
-
// TODO much shared logic with newFolder
|
|
5076
|
-
const newFile = state => {
|
|
5077
|
-
return newDirent(state, CreateFile);
|
|
5078
|
-
};
|
|
5079
|
-
|
|
5080
|
-
const newFolder = state => {
|
|
5081
|
-
return newDirent(state, CreateFolder);
|
|
5082
|
-
};
|
|
5083
|
-
|
|
5084
5107
|
const getContainingFolder = (root, dirents, focusedIndex, pathSeparator) => {
|
|
5085
5108
|
if (focusedIndex < 0) {
|
|
5086
5109
|
return root;
|
|
@@ -5325,9 +5348,6 @@ const renderDragData = (oldState, newState) => {
|
|
|
5325
5348
|
return ['Viewlet.setDragData', newState.uid, dragData];
|
|
5326
5349
|
};
|
|
5327
5350
|
|
|
5328
|
-
const ExplorerInput = 'ExplorerInput';
|
|
5329
|
-
const OpenFolder = 'OpenFolder';
|
|
5330
|
-
|
|
5331
5351
|
const renderEditingSelection = (oldState, newState) => {
|
|
5332
5352
|
const {
|
|
5333
5353
|
editingSelectionEnd,
|
|
@@ -5385,11 +5405,14 @@ const getErrorMessageDom = errorMessage => {
|
|
|
5385
5405
|
}, text(errorMessage)];
|
|
5386
5406
|
};
|
|
5387
5407
|
|
|
5408
|
+
const HandleButtonClick = 18;
|
|
5388
5409
|
const HandleClick = 1;
|
|
5389
5410
|
const HandleClickOpenFolder = 2;
|
|
5390
5411
|
const HandleContextMenu = 3;
|
|
5412
|
+
const HandleDragEnd = 19;
|
|
5391
5413
|
const HandleDragLeave = 4;
|
|
5392
5414
|
const HandleDragOver = 5;
|
|
5415
|
+
const HandleDragStart = 17;
|
|
5393
5416
|
const HandleDrop = 6;
|
|
5394
5417
|
const HandleEditingInput = 7;
|
|
5395
5418
|
const HandleInputBlur = 8;
|
|
@@ -5398,7 +5421,6 @@ const HandleListBlur = 11;
|
|
|
5398
5421
|
const HandleListFocus = 12;
|
|
5399
5422
|
const HandlePointerDown = 14;
|
|
5400
5423
|
const HandleWheel = 15;
|
|
5401
|
-
const HandleDragStart = 17;
|
|
5402
5424
|
|
|
5403
5425
|
const getExplorerWelcomeVirtualDom = isWide => {
|
|
5404
5426
|
return [{
|
|
@@ -5556,6 +5578,7 @@ const getListItemsVirtualDom = (visibleItems, focusedIndex, focused, dropTargets
|
|
|
5556
5578
|
onBlur: HandleListBlur,
|
|
5557
5579
|
onClick: HandleClick,
|
|
5558
5580
|
onContextMenu: HandleContextMenu,
|
|
5581
|
+
onDragEnd: HandleDragEnd,
|
|
5559
5582
|
onDragLeave: HandleDragLeave,
|
|
5560
5583
|
onDragOver: HandleDragOver,
|
|
5561
5584
|
onDragStart: HandleDragStart,
|
|
@@ -5720,21 +5743,25 @@ const getActions = root => {
|
|
|
5720
5743
|
command: 'newFile',
|
|
5721
5744
|
icon: NewFile,
|
|
5722
5745
|
id: newFile$1(),
|
|
5746
|
+
name: NewFile$1,
|
|
5723
5747
|
type: Button
|
|
5724
5748
|
}, {
|
|
5725
5749
|
command: 'newFolder',
|
|
5726
5750
|
icon: NewFolder,
|
|
5727
5751
|
id: newFolder$1(),
|
|
5752
|
+
name: NewFolder$1,
|
|
5728
5753
|
type: Button
|
|
5729
5754
|
}, {
|
|
5730
5755
|
command: 'refresh',
|
|
5731
5756
|
icon: Refresh,
|
|
5732
5757
|
id: refresh$1(),
|
|
5758
|
+
name: Refresh$1,
|
|
5733
5759
|
type: Button
|
|
5734
5760
|
}, {
|
|
5735
5761
|
command: 'collapseAll',
|
|
5736
5762
|
icon: CollapseAll,
|
|
5737
5763
|
id: collapseAll$1(),
|
|
5764
|
+
name: CollapseAll$1,
|
|
5738
5765
|
type: Button
|
|
5739
5766
|
}];
|
|
5740
5767
|
};
|
|
@@ -5750,14 +5777,14 @@ const getIconVirtualDom = (icon, type = Div) => {
|
|
|
5750
5777
|
|
|
5751
5778
|
const getActionButtonVirtualDom = action => {
|
|
5752
5779
|
const {
|
|
5753
|
-
command,
|
|
5754
5780
|
icon,
|
|
5755
|
-
id
|
|
5781
|
+
id,
|
|
5782
|
+
name
|
|
5756
5783
|
} = action;
|
|
5757
5784
|
return [{
|
|
5758
5785
|
childCount: 1,
|
|
5759
5786
|
className: IconButton,
|
|
5760
|
-
|
|
5787
|
+
name,
|
|
5761
5788
|
title: id,
|
|
5762
5789
|
type: Button$1
|
|
5763
5790
|
}, getIconVirtualDom(icon || '')];
|
|
@@ -5776,6 +5803,7 @@ const getActionsVirtualDom = actions => {
|
|
|
5776
5803
|
return [{
|
|
5777
5804
|
childCount: actions.length,
|
|
5778
5805
|
className: Actions,
|
|
5806
|
+
onClick: HandleButtonClick,
|
|
5779
5807
|
role: ToolBar,
|
|
5780
5808
|
type: Div
|
|
5781
5809
|
}, ...actions.flatMap(getActionVirtualDom)];
|
|
@@ -5837,6 +5865,12 @@ const renderEventListeners = () => {
|
|
|
5837
5865
|
}, {
|
|
5838
5866
|
name: HandleDragLeave,
|
|
5839
5867
|
params: ['handleDragLeave']
|
|
5868
|
+
}, {
|
|
5869
|
+
name: HandleButtonClick,
|
|
5870
|
+
params: ['handleButtonClick', TargetName]
|
|
5871
|
+
}, {
|
|
5872
|
+
name: HandleDragEnd,
|
|
5873
|
+
params: ['handleDragEnd']
|
|
5840
5874
|
}, {
|
|
5841
5875
|
// @ts-ignore
|
|
5842
5876
|
dragEffect: 'copyMove',
|
|
@@ -6157,6 +6191,7 @@ const commandMap = {
|
|
|
6157
6191
|
'Explorer.handleArrowLeft': wrapListItemCommand(handleArrowLeft),
|
|
6158
6192
|
'Explorer.handleArrowRight': wrapListItemCommand(handleArrowRight),
|
|
6159
6193
|
'Explorer.handleBlur': wrapListItemCommand(handleBlur),
|
|
6194
|
+
'Explorer.handleButtonClick': wrapListItemCommand(handleButtonClick),
|
|
6160
6195
|
'Explorer.handleClick': wrapListItemCommand(handleClick),
|
|
6161
6196
|
'Explorer.handleClickAt': wrapListItemCommand(handleClickAt),
|
|
6162
6197
|
'Explorer.handleClickCurrent': wrapListItemCommand(handleClickCurrent),
|