@lvce-editor/explorer-view 2.22.0 → 2.23.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 +120 -25
- package/package.json +1 -1
|
@@ -996,6 +996,8 @@ const Symlink = 9;
|
|
|
996
996
|
const SymLinkFile = 10;
|
|
997
997
|
const SymLinkFolder = 11;
|
|
998
998
|
const Unknown = 12;
|
|
999
|
+
const EditingFile = 13;
|
|
1000
|
+
const EditingFolder = 14;
|
|
999
1001
|
|
|
1000
1002
|
const RendererWorker = 1;
|
|
1001
1003
|
|
|
@@ -1156,7 +1158,7 @@ const getNewDirentsAccept = async (state, newDirentType, createFn) => {
|
|
|
1156
1158
|
newDirent.posInSet = posInSet;
|
|
1157
1159
|
// @ts-ignore
|
|
1158
1160
|
items.splice(insertIndex + 1, 0, newDirent);
|
|
1159
|
-
const newDirents = [...items];
|
|
1161
|
+
const newDirents = [...items].filter(item => item.type !== EditingFile && item.type !== EditingFolder);
|
|
1160
1162
|
return {
|
|
1161
1163
|
dirents: newDirents,
|
|
1162
1164
|
newFocusedIndex: insertIndex + 1
|
|
@@ -1977,6 +1979,16 @@ const focusNext = state => {
|
|
|
1977
1979
|
return focusIndex(state, focusedIndex + 1);
|
|
1978
1980
|
};
|
|
1979
1981
|
|
|
1982
|
+
const focusNone = state => {
|
|
1983
|
+
const {
|
|
1984
|
+
focusedIndex
|
|
1985
|
+
} = state;
|
|
1986
|
+
if (focusedIndex === -1) {
|
|
1987
|
+
return state;
|
|
1988
|
+
}
|
|
1989
|
+
return focusIndex(state, -1);
|
|
1990
|
+
};
|
|
1991
|
+
|
|
1980
1992
|
const focusPrevious = state => {
|
|
1981
1993
|
const {
|
|
1982
1994
|
focusedIndex,
|
|
@@ -1995,7 +2007,7 @@ const focusPrevious = state => {
|
|
|
1995
2007
|
}
|
|
1996
2008
|
};
|
|
1997
2009
|
|
|
1998
|
-
const commandIds = ['acceptEdit', 'cancelEdit', 'collapseAll', 'copyPath', 'copyRelativePath', 'dispose', 'expandAll', 'expandRecursively', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusNone', 'focusPrevious', 'getFocusedDirent', 'getMenuEntries2', 'getMouseActions', 'handleArrowLeft', 'handleArrowLeft', 'handleArrowRight', 'handleArrowRight', 'handleBlur', 'handleClick', 'handleClickAt', 'handleClickCurrent', 'handleClickCurrentButKeepFocus', 'handleClickOpenFolder', 'handleContextMenu', 'handleContextMenuKeyboard', 'handleCopy', 'handleDragLeave', 'handleDragOver', 'handleDrop', 'handleFocus', 'handleIconThemeChange', 'handleLanguagesChanged', 'handleMouseEnter', 'handleMouseLeave', 'handlePaste', 'handlePointerDown', 'handleUpload', 'handleWheel', 'handleWorkspaceChange', 'hotReload', 'newFile', 'newFolder', 'openContainingFolder', 'refresh', '
|
|
2010
|
+
const commandIds = ['acceptEdit', 'cancelEdit', 'collapseAll', 'copyPath', 'copyRelativePath', 'dispose', 'expandAll', 'expandRecursively', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusNone', 'focusPrevious', 'getFocusedDirent', 'getMenuEntries2', 'getMouseActions', 'handleArrowLeft', 'handleArrowLeft', 'handleArrowRight', 'handleArrowRight', 'handleBlur', 'handleClick', 'handleClickAt', 'handleClickCurrent', 'handleClickCurrentButKeepFocus', 'handleClickOpenFolder', 'handleContextMenu', 'handleContextMenuKeyboard', 'handleCopy', 'handleDragLeave', 'handleDragOver', 'handleDrop', 'handleFocus', 'handleIconThemeChange', 'handleInputBlur', 'handleLanguagesChanged', 'handleMouseEnter', 'handleMouseLeave', 'handlePaste', 'handlePointerDown', 'handleUpload', 'handleWheel', 'handleWorkspaceChange', 'hotReload', 'newFile', 'newFolder', 'openContainingFolder', 'refresh', 'removeDirent', 'rename', 'renameDirent', 'renderEventListeners', 'revealItem', 'revealItem', 'scrollDown', 'scrollUp', 'selectAll', 'selectDown', 'selectUp', 'setDeltaY', 'setSelectedIndices', 'updateEditingValue', 'updateIcons'];
|
|
1999
2011
|
|
|
2000
2012
|
const getCommandIds = () => {
|
|
2001
2013
|
return commandIds;
|
|
@@ -2079,7 +2091,7 @@ const getKeyBindings = () => {
|
|
|
2079
2091
|
when: FocusExplorer
|
|
2080
2092
|
}, {
|
|
2081
2093
|
key: F2,
|
|
2082
|
-
command: 'Explorer.
|
|
2094
|
+
command: 'Explorer.renameDirent',
|
|
2083
2095
|
when: FocusExplorer
|
|
2084
2096
|
}, {
|
|
2085
2097
|
key: Escape,
|
|
@@ -3187,6 +3199,10 @@ const handleIconThemeChange = state => {
|
|
|
3187
3199
|
return updateIcons(state);
|
|
3188
3200
|
};
|
|
3189
3201
|
|
|
3202
|
+
const handleInputBlur = state => {
|
|
3203
|
+
return cancelEdit(state);
|
|
3204
|
+
};
|
|
3205
|
+
|
|
3190
3206
|
// TODO add lots of tests for this
|
|
3191
3207
|
const updateRoot = async state1 => {
|
|
3192
3208
|
// @ts-ignore
|
|
@@ -3540,28 +3556,103 @@ const handleWorkspaceChange = async state => {
|
|
|
3540
3556
|
|
|
3541
3557
|
const ExplorerEditBox = FocusExplorerEditBox;
|
|
3542
3558
|
|
|
3559
|
+
const getNewChildDirentsForNewDirent = async (items, depth, parentPath, direntType) => {
|
|
3560
|
+
// Get existing children or query them if they don't exist
|
|
3561
|
+
let existingChildren = items.filter(item => item.depth === depth && item.path.startsWith(parentPath));
|
|
3562
|
+
if (existingChildren.length === 0) {
|
|
3563
|
+
const childDirents = await readDirWithFileTypes(parentPath);
|
|
3564
|
+
existingChildren = childDirents.map((dirent, index) => ({
|
|
3565
|
+
name: dirent.name,
|
|
3566
|
+
type: dirent.type,
|
|
3567
|
+
path: `${parentPath}/${dirent.name}`,
|
|
3568
|
+
depth,
|
|
3569
|
+
selected: false,
|
|
3570
|
+
posInSet: index + 1,
|
|
3571
|
+
setSize: childDirents.length,
|
|
3572
|
+
icon: ''
|
|
3573
|
+
}));
|
|
3574
|
+
}
|
|
3575
|
+
const updatedChildren = existingChildren.map((child, index) => ({
|
|
3576
|
+
...child,
|
|
3577
|
+
posInSet: index + 1,
|
|
3578
|
+
setSize: existingChildren.length + 2
|
|
3579
|
+
}));
|
|
3580
|
+
const newDirent = {
|
|
3581
|
+
name: '',
|
|
3582
|
+
type: direntType,
|
|
3583
|
+
path: '',
|
|
3584
|
+
depth,
|
|
3585
|
+
selected: false,
|
|
3586
|
+
posInSet: updatedChildren.length + 1,
|
|
3587
|
+
setSize: existingChildren.length + 2,
|
|
3588
|
+
icon: ''
|
|
3589
|
+
};
|
|
3590
|
+
const allChildDirents = [...updatedChildren, newDirent];
|
|
3591
|
+
return allChildDirents;
|
|
3592
|
+
};
|
|
3593
|
+
|
|
3594
|
+
const getNewDirentsForNewDirent = async (items, focusedIndex, type) => {
|
|
3595
|
+
const focusedItem = items[focusedIndex];
|
|
3596
|
+
if (!focusedItem) {
|
|
3597
|
+
return items;
|
|
3598
|
+
}
|
|
3599
|
+
const parentPath = focusedItem.path;
|
|
3600
|
+
const depth = focusedItem.depth + 1;
|
|
3601
|
+
const updatedChildren = await getNewChildDirentsForNewDirent(items, depth, parentPath, type);
|
|
3602
|
+
|
|
3603
|
+
// Create new array with updated items
|
|
3604
|
+
const parentIndex = focusedIndex;
|
|
3605
|
+
const itemsBeforeParent = items.slice(0, parentIndex);
|
|
3606
|
+
const itemsAfterChildren = items.slice(parentIndex + updatedChildren.length);
|
|
3607
|
+
const updatedParent = {
|
|
3608
|
+
...items[parentIndex],
|
|
3609
|
+
setSize: (items[parentIndex]?.setSize || 0) + 1
|
|
3610
|
+
};
|
|
3611
|
+
return [...itemsBeforeParent, updatedParent, ...updatedChildren, ...itemsAfterChildren];
|
|
3612
|
+
};
|
|
3613
|
+
|
|
3614
|
+
const getNewDirentType = editingType => {
|
|
3615
|
+
switch (editingType) {
|
|
3616
|
+
case CreateFile:
|
|
3617
|
+
return EditingFile;
|
|
3618
|
+
case CreateFolder:
|
|
3619
|
+
return EditingFolder;
|
|
3620
|
+
default:
|
|
3621
|
+
return File;
|
|
3622
|
+
}
|
|
3623
|
+
};
|
|
3624
|
+
|
|
3543
3625
|
const newDirent = async (state, editingType) => {
|
|
3544
3626
|
// TODO make focus functional instead of side effect
|
|
3545
3627
|
await setFocus(ExplorerEditBox);
|
|
3546
3628
|
// TODO do it like vscode, select position between folders and files
|
|
3547
3629
|
const {
|
|
3548
3630
|
focusedIndex,
|
|
3549
|
-
items
|
|
3631
|
+
items,
|
|
3632
|
+
minLineY,
|
|
3633
|
+
height,
|
|
3634
|
+
itemHeight,
|
|
3635
|
+
fileIconCache
|
|
3550
3636
|
} = state;
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
}
|
|
3637
|
+
const direntType = getNewDirentType(editingType);
|
|
3638
|
+
const newDirents = await getNewDirentsForNewDirent(items, focusedIndex, direntType);
|
|
3639
|
+
const maxLineY = getExplorerMaxLineY(minLineY, height, itemHeight, newDirents.length);
|
|
3640
|
+
const visible = newDirents.slice(minLineY, maxLineY);
|
|
3641
|
+
const {
|
|
3642
|
+
icons,
|
|
3643
|
+
newFileIconCache
|
|
3644
|
+
} = await getFileIcons(visible, fileIconCache);
|
|
3645
|
+
const editingIndex = newDirents.findIndex(item => item.type === EditingFile || item.type === EditingFolder);
|
|
3559
3646
|
return {
|
|
3560
3647
|
...state,
|
|
3561
|
-
|
|
3648
|
+
items: newDirents,
|
|
3649
|
+
editingIndex,
|
|
3562
3650
|
editingType,
|
|
3563
3651
|
editingValue: '',
|
|
3564
|
-
focus: Input$1
|
|
3652
|
+
focus: Input$1,
|
|
3653
|
+
icons,
|
|
3654
|
+
fileIconCache: newFileIconCache,
|
|
3655
|
+
maxLineY
|
|
3565
3656
|
};
|
|
3566
3657
|
};
|
|
3567
3658
|
|
|
@@ -3756,14 +3847,15 @@ const WelcomeMessage = 'WelcomeMessage';
|
|
|
3756
3847
|
const HandleClick = 'handleClick';
|
|
3757
3848
|
const HandleClickOpenFolder = 'handleClickOpenFolder';
|
|
3758
3849
|
const HandleContextMenu = 'handleContextMenu';
|
|
3850
|
+
const HandleDragLeave = 'handleDragLeave';
|
|
3851
|
+
const HandleDragOver = 'handleDragOver';
|
|
3852
|
+
const HandleDrop = 'handleDrop';
|
|
3759
3853
|
const HandleEditingInput = 'handleEditingInput';
|
|
3854
|
+
const HandleInputBlur = 'handleInputBlur';
|
|
3760
3855
|
const HandleListBlur = 'handleListBlur';
|
|
3761
3856
|
const HandleListFocus = 'handleListFocus';
|
|
3762
3857
|
const HandlePointerDown = 'handlePointerDown';
|
|
3763
3858
|
const HandleWheel = 'handleWheel';
|
|
3764
|
-
const HandleDragOver = 'handleDragOver';
|
|
3765
|
-
const HandleDrop = 'handleDrop';
|
|
3766
|
-
const HandleDragLeave = 'handleDragLeave';
|
|
3767
3859
|
|
|
3768
3860
|
const mergeClassNames = (...classNames) => {
|
|
3769
3861
|
return classNames.filter(Boolean).join(' ');
|
|
@@ -3822,6 +3914,7 @@ const getInputDom = hasEditingError => {
|
|
|
3822
3914
|
className: getClassName$2(hasEditingError),
|
|
3823
3915
|
id: 'ExplorerInput',
|
|
3824
3916
|
onInput: HandleEditingInput,
|
|
3917
|
+
onBlur: HandleInputBlur,
|
|
3825
3918
|
childCount: 0,
|
|
3826
3919
|
name: ExplorerInput
|
|
3827
3920
|
}];
|
|
@@ -4193,8 +4286,8 @@ const renderActions = uid => {
|
|
|
4193
4286
|
|
|
4194
4287
|
const renderEventListeners = () => {
|
|
4195
4288
|
return [{
|
|
4196
|
-
name:
|
|
4197
|
-
params: ['
|
|
4289
|
+
name: HandleInputBlur,
|
|
4290
|
+
params: ['handleInputBlur']
|
|
4198
4291
|
}, {
|
|
4199
4292
|
name: HandleListFocus,
|
|
4200
4293
|
params: ['handleFocus', 'event.isTrusted', 'event.target.className']
|
|
@@ -4592,10 +4685,10 @@ const wrapCommand = fn => {
|
|
|
4592
4685
|
};
|
|
4593
4686
|
|
|
4594
4687
|
const commandMap = {
|
|
4595
|
-
'Explorer.getMenuEntries2': getMenuEntries2,
|
|
4596
4688
|
'Explorer.acceptEdit': wrapCommand(acceptEdit),
|
|
4597
4689
|
'Explorer.cancelEdit': wrapCommand(cancelEdit),
|
|
4598
4690
|
'Explorer.collapseAll': wrapCommand(collapseAll),
|
|
4691
|
+
'Explorer.handleInputBlur': wrapCommand(handleInputBlur),
|
|
4599
4692
|
'Explorer.copyPath': wrapCommand(copyPath),
|
|
4600
4693
|
'Explorer.copyRelativePath': wrapCommand(copyRelativePath),
|
|
4601
4694
|
'Explorer.expandAll': wrapCommand(expandAll),
|
|
@@ -4604,21 +4697,20 @@ const commandMap = {
|
|
|
4604
4697
|
'Explorer.focusIndex': wrapCommand(focusIndex),
|
|
4605
4698
|
'Explorer.focusLast': wrapCommand(focusLast),
|
|
4606
4699
|
'Explorer.focusNext': wrapCommand(focusNext),
|
|
4700
|
+
'Explorer.focusNone': wrapCommand(focusNone),
|
|
4607
4701
|
'Explorer.focusPrevious': wrapCommand(focusPrevious),
|
|
4608
4702
|
'Explorer.getCommandIds': getCommandIds,
|
|
4703
|
+
'Explorer.getMenuEntries2': getMenuEntries2,
|
|
4704
|
+
'Explorer.getMouseActions': getMouseActions,
|
|
4609
4705
|
'Explorer.handleArrowLeft': wrapCommand(handleArrowLeft),
|
|
4610
4706
|
'Explorer.handleArrowRight': wrapCommand(handleArrowRight),
|
|
4611
4707
|
'Explorer.handleBlur': wrapCommand(handleBlur),
|
|
4612
|
-
'Explorer.selectUp': wrapCommand(selectUp),
|
|
4613
|
-
'Explorer.selectDown': wrapCommand(selectDown),
|
|
4614
|
-
'Explorer.selectAll': wrapCommand(selectAll),
|
|
4615
4708
|
'Explorer.handleClick': wrapCommand(handleClick),
|
|
4616
4709
|
'Explorer.handleClickAt': wrapCommand(handleClickAt),
|
|
4617
4710
|
'Explorer.handleClickCurrent': wrapCommand(handleClickCurrent),
|
|
4618
4711
|
'Explorer.handleClickCurrentButKeepFocus': wrapCommand(handleClickCurrentButKeepFocus),
|
|
4619
4712
|
'Explorer.handleClickOpenFolder': wrapCommand(handleClickOpenFolder),
|
|
4620
4713
|
'Explorer.handleContextMenu': wrapCommand(handleContextMenu),
|
|
4621
|
-
'Explorer.getMouseActions': getMouseActions,
|
|
4622
4714
|
'Explorer.handleContextMenuKeyboard': wrapCommand(handleContextMenuKeyboard),
|
|
4623
4715
|
'Explorer.handleCopy': wrapCommand(handleCopy),
|
|
4624
4716
|
'Explorer.handleDragLeave': wrapCommand(handleDragLeave),
|
|
@@ -4640,10 +4732,13 @@ const commandMap = {
|
|
|
4640
4732
|
'Explorer.renameDirent': wrapCommand(renameDirent),
|
|
4641
4733
|
'Explorer.restoreState': restoreState,
|
|
4642
4734
|
'Explorer.revealItem': wrapCommand(revealItem),
|
|
4735
|
+
'Explorer.selectAll': wrapCommand(selectAll),
|
|
4736
|
+
'Explorer.selectDown': wrapCommand(selectDown),
|
|
4737
|
+
'Explorer.selectUp': wrapCommand(selectUp),
|
|
4643
4738
|
'Explorer.setDeltaY': wrapCommand(setDeltaY),
|
|
4739
|
+
'Explorer.setSelectedIndices': wrapCommand(setSelectedIndices),
|
|
4644
4740
|
'Explorer.updateEditingValue': wrapCommand(updateEditingValue),
|
|
4645
4741
|
'Explorer.updateIcons': wrapCommand(updateIcons),
|
|
4646
|
-
'Explorer.setSelectedIndices': wrapCommand(setSelectedIndices),
|
|
4647
4742
|
// not wrapped
|
|
4648
4743
|
'Explorer.create2': create2,
|
|
4649
4744
|
'Explorer.diff2': diff2,
|