@lvce-editor/explorer-view 2.23.0 → 2.24.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 +102 -39
- package/package.json +1 -1
|
@@ -985,6 +985,8 @@ const getPath = dirent => {
|
|
|
985
985
|
return dirent.path;
|
|
986
986
|
};
|
|
987
987
|
|
|
988
|
+
const DELTA_EDITING = 100;
|
|
989
|
+
|
|
988
990
|
const BlockDevice = 1;
|
|
989
991
|
const CharacterDevice = 2;
|
|
990
992
|
const Directory = 3;
|
|
@@ -996,8 +998,8 @@ const Symlink = 9;
|
|
|
996
998
|
const SymLinkFile = 10;
|
|
997
999
|
const SymLinkFolder = 11;
|
|
998
1000
|
const Unknown = 12;
|
|
999
|
-
const EditingFile =
|
|
1000
|
-
const EditingFolder =
|
|
1001
|
+
const EditingFile = File + DELTA_EDITING;
|
|
1002
|
+
const EditingFolder = Directory + DELTA_EDITING;
|
|
1001
1003
|
|
|
1002
1004
|
const RendererWorker = 1;
|
|
1003
1005
|
|
|
@@ -1015,12 +1017,20 @@ const invoke = (method, ...params) => {
|
|
|
1015
1017
|
return rpc.invoke(method, ...params);
|
|
1016
1018
|
};
|
|
1017
1019
|
|
|
1020
|
+
const getFileIcon = async name => {
|
|
1021
|
+
return invoke('IconTheme.getFileIcon', {
|
|
1022
|
+
name
|
|
1023
|
+
});
|
|
1024
|
+
};
|
|
1025
|
+
|
|
1026
|
+
const getFolderIcon = async name => {
|
|
1027
|
+
return invoke('IconTheme.getFolderIcon', {
|
|
1028
|
+
name
|
|
1029
|
+
});
|
|
1030
|
+
};
|
|
1031
|
+
|
|
1018
1032
|
const requestFileIcons = async requests => {
|
|
1019
|
-
const promises = requests.map(request => request.type === File ?
|
|
1020
|
-
name: request.name
|
|
1021
|
-
}) : invoke('IconTheme.getFolderIcon', {
|
|
1022
|
-
name: request.name
|
|
1023
|
-
}));
|
|
1033
|
+
const promises = requests.map(request => request.type === File ? getFileIcon(request.name) : getFolderIcon(request.name));
|
|
1024
1034
|
return Promise.all(promises);
|
|
1025
1035
|
};
|
|
1026
1036
|
|
|
@@ -1408,12 +1418,41 @@ const acceptEdit = async state => {
|
|
|
1408
1418
|
}
|
|
1409
1419
|
};
|
|
1410
1420
|
|
|
1421
|
+
const getNewDirentsForCancelRename = (items, editingIndex) => {
|
|
1422
|
+
const item = items[editingIndex];
|
|
1423
|
+
const newItems = [...items];
|
|
1424
|
+
newItems[editingIndex] = {
|
|
1425
|
+
...item,
|
|
1426
|
+
type: item.type - DELTA_EDITING
|
|
1427
|
+
};
|
|
1428
|
+
return newItems;
|
|
1429
|
+
};
|
|
1430
|
+
|
|
1431
|
+
const isNormalItem = item => {
|
|
1432
|
+
return item.type !== EditingFile && item.type !== EditingFolder;
|
|
1433
|
+
};
|
|
1411
1434
|
const cancelEdit = state => {
|
|
1412
1435
|
const {
|
|
1413
|
-
editingIndex
|
|
1436
|
+
editingIndex,
|
|
1437
|
+
editingType
|
|
1414
1438
|
} = state;
|
|
1439
|
+
if (editingType === Rename$1) {
|
|
1440
|
+
const newItems = getNewDirentsForCancelRename(state.items, editingIndex);
|
|
1441
|
+
return {
|
|
1442
|
+
...state,
|
|
1443
|
+
items: newItems,
|
|
1444
|
+
focusedIndex: editingIndex,
|
|
1445
|
+
focused: true,
|
|
1446
|
+
editingIndex: -1,
|
|
1447
|
+
editingValue: '',
|
|
1448
|
+
editingType: None$5,
|
|
1449
|
+
focus: List
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
const filteredItems = state.items.filter(isNormalItem);
|
|
1415
1453
|
return {
|
|
1416
1454
|
...state,
|
|
1455
|
+
items: filteredItems,
|
|
1417
1456
|
focusedIndex: editingIndex,
|
|
1418
1457
|
focused: true,
|
|
1419
1458
|
editingIndex: -1,
|
|
@@ -3580,7 +3619,7 @@ const getNewChildDirentsForNewDirent = async (items, depth, parentPath, direntTy
|
|
|
3580
3619
|
const newDirent = {
|
|
3581
3620
|
name: '',
|
|
3582
3621
|
type: direntType,
|
|
3583
|
-
path:
|
|
3622
|
+
path: parentPath,
|
|
3584
3623
|
depth,
|
|
3585
3624
|
selected: false,
|
|
3586
3625
|
posInSet: updatedChildren.length + 1,
|
|
@@ -3591,7 +3630,20 @@ const getNewChildDirentsForNewDirent = async (items, depth, parentPath, direntTy
|
|
|
3591
3630
|
return allChildDirents;
|
|
3592
3631
|
};
|
|
3593
3632
|
|
|
3594
|
-
const getNewDirentsForNewDirent = async (items, focusedIndex, type) => {
|
|
3633
|
+
const getNewDirentsForNewDirent = async (items, focusedIndex, type, root) => {
|
|
3634
|
+
if (items.length === 0 || focusedIndex === -1) {
|
|
3635
|
+
const newDirent = {
|
|
3636
|
+
name: '',
|
|
3637
|
+
type,
|
|
3638
|
+
path: root,
|
|
3639
|
+
depth: 0,
|
|
3640
|
+
selected: false,
|
|
3641
|
+
posInSet: 1,
|
|
3642
|
+
setSize: 1,
|
|
3643
|
+
icon: ''
|
|
3644
|
+
};
|
|
3645
|
+
return [...items, newDirent];
|
|
3646
|
+
}
|
|
3595
3647
|
const focusedItem = items[focusedIndex];
|
|
3596
3648
|
if (!focusedItem) {
|
|
3597
3649
|
return items;
|
|
@@ -3632,10 +3684,11 @@ const newDirent = async (state, editingType) => {
|
|
|
3632
3684
|
minLineY,
|
|
3633
3685
|
height,
|
|
3634
3686
|
itemHeight,
|
|
3635
|
-
fileIconCache
|
|
3687
|
+
fileIconCache,
|
|
3688
|
+
root
|
|
3636
3689
|
} = state;
|
|
3637
3690
|
const direntType = getNewDirentType(editingType);
|
|
3638
|
-
const newDirents = await getNewDirentsForNewDirent(items, focusedIndex, direntType);
|
|
3691
|
+
const newDirents = await getNewDirentsForNewDirent(items, focusedIndex, direntType, root);
|
|
3639
3692
|
const maxLineY = getExplorerMaxLineY(minLineY, height, itemHeight, newDirents.length);
|
|
3640
3693
|
const visible = newDirents.slice(minLineY, maxLineY);
|
|
3641
3694
|
const {
|
|
@@ -3649,6 +3702,7 @@ const newDirent = async (state, editingType) => {
|
|
|
3649
3702
|
editingIndex,
|
|
3650
3703
|
editingType,
|
|
3651
3704
|
editingValue: '',
|
|
3705
|
+
focusedIndex: editingIndex,
|
|
3652
3706
|
focus: Input$1,
|
|
3653
3707
|
icons,
|
|
3654
3708
|
fileIconCache: newFileIconCache,
|
|
@@ -3756,6 +3810,17 @@ const removeDirent = async state => {
|
|
|
3756
3810
|
};
|
|
3757
3811
|
};
|
|
3758
3812
|
|
|
3813
|
+
const getNewDirentsForRename = (items, focusedIndex) => {
|
|
3814
|
+
const item = items[focusedIndex];
|
|
3815
|
+
const newItems = [...items];
|
|
3816
|
+
const editingType = item.type === File ? EditingFile : EditingFolder;
|
|
3817
|
+
newItems[focusedIndex] = {
|
|
3818
|
+
...item,
|
|
3819
|
+
type: editingType
|
|
3820
|
+
};
|
|
3821
|
+
return newItems;
|
|
3822
|
+
};
|
|
3823
|
+
|
|
3759
3824
|
const User = 1;
|
|
3760
3825
|
const Script = 2;
|
|
3761
3826
|
|
|
@@ -3764,9 +3829,14 @@ const renameDirent = state => {
|
|
|
3764
3829
|
focusedIndex,
|
|
3765
3830
|
items
|
|
3766
3831
|
} = state;
|
|
3832
|
+
if (items.length === 0) {
|
|
3833
|
+
return state;
|
|
3834
|
+
}
|
|
3767
3835
|
const item = items[focusedIndex];
|
|
3836
|
+
const newItems = getNewDirentsForRename(items, focusedIndex);
|
|
3768
3837
|
return {
|
|
3769
3838
|
...state,
|
|
3839
|
+
items: newItems,
|
|
3770
3840
|
editingIndex: focusedIndex,
|
|
3771
3841
|
editingType: Rename$1,
|
|
3772
3842
|
editingValue: item.name,
|
|
@@ -4095,13 +4165,12 @@ const getClassName = (isSelected, isFocused) => {
|
|
|
4095
4165
|
}
|
|
4096
4166
|
return TreeItem;
|
|
4097
4167
|
};
|
|
4098
|
-
const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editingIndex, editingType, editingValue, editingErrorMessage, icons, useChevrons, dropTargets) => {
|
|
4168
|
+
const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editingIndex, editingType, editingValue, editingErrorMessage, icons, useChevrons, dropTargets, editingIcon) => {
|
|
4099
4169
|
const visible = [];
|
|
4100
4170
|
const indentFn = useChevrons ? getTreeItemIndentWithChevron : getTreeItemIndent;
|
|
4101
4171
|
let iconIndex = 0;
|
|
4102
4172
|
for (let i = minLineY; i < Math.min(maxLineY, items.length); i++) {
|
|
4103
4173
|
const item = items[i];
|
|
4104
|
-
const icon = icons[iconIndex++];
|
|
4105
4174
|
const chevron = getChevronType(item.type, useChevrons);
|
|
4106
4175
|
const indent = indentFn(item.depth, chevron);
|
|
4107
4176
|
const isFocused = i === focusedIndex;
|
|
@@ -4110,12 +4179,17 @@ const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editin
|
|
|
4110
4179
|
const className = getClassName(isSelected, isFocused);
|
|
4111
4180
|
const expanded = getExpandedType(item.type);
|
|
4112
4181
|
const ariaExpanded = ariaExpandedValues[expanded];
|
|
4113
|
-
|
|
4114
|
-
|
|
4182
|
+
const isEditing = i === editingIndex;
|
|
4183
|
+
let icon = icons[iconIndex++];
|
|
4184
|
+
if (isEditing) {
|
|
4185
|
+
icon = editingIcon;
|
|
4186
|
+
}
|
|
4115
4187
|
visible.push({
|
|
4116
4188
|
...item,
|
|
4117
|
-
|
|
4118
|
-
|
|
4189
|
+
posInSet: item.posInSet ?? i + 1,
|
|
4190
|
+
setSize: item.setSize ?? items.length,
|
|
4191
|
+
isEditing: isEditing,
|
|
4192
|
+
hasEditingError: isEditing && Boolean(editingErrorMessage),
|
|
4119
4193
|
icon,
|
|
4120
4194
|
indent,
|
|
4121
4195
|
ariaExpanded,
|
|
@@ -4124,29 +4198,11 @@ const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editin
|
|
|
4124
4198
|
className
|
|
4125
4199
|
});
|
|
4126
4200
|
}
|
|
4127
|
-
if (editingType !== None$5 && editingIndex === -1) {
|
|
4128
|
-
visible.push({
|
|
4129
|
-
depth: 3,
|
|
4130
|
-
posInSet: 1,
|
|
4131
|
-
setSize: 1,
|
|
4132
|
-
icon: '',
|
|
4133
|
-
name: 'new',
|
|
4134
|
-
path: '/test/new',
|
|
4135
|
-
isEditing: true,
|
|
4136
|
-
hasEditingError: Boolean(editingErrorMessage),
|
|
4137
|
-
indent: '',
|
|
4138
|
-
ariaExpanded: undefined,
|
|
4139
|
-
chevron: 0,
|
|
4140
|
-
id: undefined,
|
|
4141
|
-
className: TreeItem,
|
|
4142
|
-
selected: false
|
|
4143
|
-
});
|
|
4144
|
-
}
|
|
4145
4201
|
return visible;
|
|
4146
4202
|
};
|
|
4147
4203
|
|
|
4148
4204
|
const renderItems = (oldState, newState) => {
|
|
4149
|
-
const visibleDirents = getVisibleExplorerItems(newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex, newState.editingIndex, newState.editingType, newState.editingValue, newState.editingErrorMessage, newState.icons, newState.useChevrons);
|
|
4205
|
+
const visibleDirents = getVisibleExplorerItems(newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex, newState.editingIndex, newState.editingType, newState.editingValue, newState.editingErrorMessage, newState.icons, newState.useChevrons, newState.dropTargets, newState.editingIcon);
|
|
4150
4206
|
const isWide = newState.width > 450;
|
|
4151
4207
|
const dom = getExplorerVirtualDom(visibleDirents, newState.focusedIndex, newState.root, isWide, newState.focused, newState.dropTargets);
|
|
4152
4208
|
return ['Viewlet.setDom2', dom];
|
|
@@ -4648,18 +4704,25 @@ const terminate = () => {
|
|
|
4648
4704
|
};
|
|
4649
4705
|
|
|
4650
4706
|
const getEditingIcon = async (editingType, value) => {
|
|
4651
|
-
if (editingType ===
|
|
4707
|
+
if (editingType === CreateFile) {
|
|
4708
|
+
return invoke('IconTheme.getFileIcon', {
|
|
4709
|
+
name: value
|
|
4710
|
+
});
|
|
4711
|
+
}
|
|
4712
|
+
// TODO need renamefile and renamefolder type
|
|
4713
|
+
if (editingType === Rename$1) {
|
|
4652
4714
|
return invoke('IconTheme.getFileIcon', {
|
|
4653
4715
|
name: value
|
|
4654
4716
|
});
|
|
4655
4717
|
}
|
|
4656
|
-
if (editingType ===
|
|
4718
|
+
if (editingType === CreateFolder) {
|
|
4657
4719
|
return invoke('IconTheme.getFolderIcon', {
|
|
4658
4720
|
name: value
|
|
4659
4721
|
});
|
|
4660
4722
|
}
|
|
4661
4723
|
return '';
|
|
4662
4724
|
};
|
|
4725
|
+
|
|
4663
4726
|
const updateEditingValue = async (state, value, inputSource = User) => {
|
|
4664
4727
|
const editingIcon = await getEditingIcon(state.editingType, value);
|
|
4665
4728
|
return {
|