@lvce-editor/explorer-view 2.1.0 → 2.3.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 +119 -43
- package/package.json +1 -1
|
@@ -1288,7 +1288,41 @@ const ListItem = 22;
|
|
|
1288
1288
|
const Slash = '/';
|
|
1289
1289
|
|
|
1290
1290
|
// TODO parentUid might ot be needed
|
|
1291
|
-
const
|
|
1291
|
+
const create2 = (uid, uri, x, y, width, height, args, parentUid, platform = 0) => {
|
|
1292
|
+
const state = {
|
|
1293
|
+
uid,
|
|
1294
|
+
parentUid,
|
|
1295
|
+
root: '',
|
|
1296
|
+
items: [],
|
|
1297
|
+
focusedIndex: -1,
|
|
1298
|
+
focused: false,
|
|
1299
|
+
hoverIndex: -1,
|
|
1300
|
+
x,
|
|
1301
|
+
y,
|
|
1302
|
+
width,
|
|
1303
|
+
height,
|
|
1304
|
+
deltaY: 0,
|
|
1305
|
+
minLineY: 0,
|
|
1306
|
+
maxLineY: 0,
|
|
1307
|
+
pathSeparator: Slash,
|
|
1308
|
+
version: 0,
|
|
1309
|
+
editingIndex: -1,
|
|
1310
|
+
itemHeight: ListItem,
|
|
1311
|
+
dropTargets: [],
|
|
1312
|
+
excluded: [],
|
|
1313
|
+
editingValue: '',
|
|
1314
|
+
editingType: None$5,
|
|
1315
|
+
editingIcon: '',
|
|
1316
|
+
fileIconCache: Object.create(null),
|
|
1317
|
+
useChevrons: false,
|
|
1318
|
+
icons: [],
|
|
1319
|
+
platform
|
|
1320
|
+
};
|
|
1321
|
+
set(uid, state, state);
|
|
1322
|
+
};
|
|
1323
|
+
|
|
1324
|
+
// TODO parentUid might ot be needed
|
|
1325
|
+
const create = (id, uri, x, y, width, height, args, parentUid, platform = 0) => {
|
|
1292
1326
|
const state = {
|
|
1293
1327
|
uid: id,
|
|
1294
1328
|
parentUid,
|
|
@@ -1315,7 +1349,8 @@ const create = (id, uri, x, y, width, height, args, parentUid) => {
|
|
|
1315
1349
|
editingIcon: '',
|
|
1316
1350
|
fileIconCache: Object.create(null),
|
|
1317
1351
|
useChevrons: false,
|
|
1318
|
-
icons: []
|
|
1352
|
+
icons: [],
|
|
1353
|
+
platform
|
|
1319
1354
|
};
|
|
1320
1355
|
set(state.uid, state, state);
|
|
1321
1356
|
return state;
|
|
@@ -1349,7 +1384,7 @@ const DiffFocus = {
|
|
|
1349
1384
|
|
|
1350
1385
|
const diffType = RenderItems;
|
|
1351
1386
|
const isEqual$1 = (oldState, newState) => {
|
|
1352
|
-
return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.focusedIndex === newState.focusedIndex && oldState.editingIndex === newState.editingIndex && oldState.editingType === newState.editingType && oldState.editingValue === newState.editingValue && oldState.width === newState.width && oldState.focused === newState.focused;
|
|
1387
|
+
return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.focusedIndex === newState.focusedIndex && oldState.editingIndex === newState.editingIndex && oldState.editingType === newState.editingType && oldState.editingValue === newState.editingValue && oldState.width === newState.width && oldState.focused === newState.focused && oldState.dropTargets === newState.dropTargets;
|
|
1353
1388
|
};
|
|
1354
1389
|
|
|
1355
1390
|
const DiffItems = {
|
|
@@ -1802,7 +1837,7 @@ const focusPrevious = state => {
|
|
|
1802
1837
|
}
|
|
1803
1838
|
};
|
|
1804
1839
|
|
|
1805
|
-
const commandIds = ['acceptEdit', 'cancelEdit', 'collapseAll', 'copyPath', 'copyRelativePath', 'expandAll', 'expandRecursively', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusNone', 'focusPrevious', 'getFocusedDirent', 'handleArrowLeft', 'handleArrowLeft', 'handleArrowRight', 'handleArrowRight', 'handleBlur', 'handleClick', 'handleClickAt', 'handleClickCurrent', 'handleClickCurrentButKeepFocus', 'handleClickOpenFolder', 'handleContextMenu', 'handleCopy', 'handleDragOver', 'handleDrop', 'handleFocus', 'handleIconThemeChange', 'handleLanguagesChanged', 'handleMouseEnter', 'handleMouseLeave', 'handlePaste', 'handlePointerDown', 'handleUpload', 'handleWheel', 'handleWorkspaceChange', 'hotReload', 'newFile', 'newFolder', 'openContainingFolder', 'refresh', 'refresh', '
|
|
1840
|
+
const commandIds = ['acceptEdit', 'cancelEdit', 'collapseAll', 'copyPath', 'copyRelativePath', 'expandAll', 'expandRecursively', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusNone', 'focusPrevious', 'getFocusedDirent', 'handleArrowLeft', 'handleArrowLeft', 'handleArrowRight', 'handleArrowRight', 'handleBlur', 'handleClick', 'handleClickAt', 'handleClickCurrent', 'handleClickCurrentButKeepFocus', 'handleClickOpenFolder', 'handleContextMenu', 'handleCopy', 'handleDragOver', 'handleDrop', 'handleFocus', 'handleIconThemeChange', 'handleLanguagesChanged', 'handleMouseEnter', 'handleMouseLeave', 'handlePaste', 'handlePointerDown', 'handleUpload', 'handleWheel', 'handleWorkspaceChange', 'hotReload', 'newFile', 'newFolder', 'openContainingFolder', 'refresh', 'refresh', 'revealItem', 'removeDirent', 'rename', 'renameDirent', 'revealItem', 'scrollDown', 'scrollUp', 'setDeltaY', 'renderEventListeners', 'updateEditingValue', 'updateIcons'];
|
|
1806
1841
|
|
|
1807
1842
|
const getCommandIds = () => {
|
|
1808
1843
|
return commandIds;
|
|
@@ -2532,13 +2567,15 @@ const canBeDroppedInto = dirent => {
|
|
|
2532
2567
|
}
|
|
2533
2568
|
};
|
|
2534
2569
|
|
|
2570
|
+
const dropTargetFull = [-1];
|
|
2571
|
+
|
|
2535
2572
|
const getNewDropTargets = (state, x, y) => {
|
|
2536
2573
|
const {
|
|
2537
2574
|
items
|
|
2538
2575
|
} = state;
|
|
2539
2576
|
const index = getIndexFromPosition(state, x, y);
|
|
2540
2577
|
if (index === -1) {
|
|
2541
|
-
return
|
|
2578
|
+
return dropTargetFull;
|
|
2542
2579
|
}
|
|
2543
2580
|
const item = items[index];
|
|
2544
2581
|
if (!canBeDroppedInto(item)) {
|
|
@@ -2660,7 +2697,7 @@ const getModule = isElectron => {
|
|
|
2660
2697
|
};
|
|
2661
2698
|
const handleDropRoot = async (state, files) => {
|
|
2662
2699
|
// @ts-ignore
|
|
2663
|
-
const fn =
|
|
2700
|
+
const fn = getModule(state.isElectron);
|
|
2664
2701
|
return fn(state, files);
|
|
2665
2702
|
};
|
|
2666
2703
|
|
|
@@ -2686,6 +2723,7 @@ const handleDropIntoFolder = async (state, dirent, index, files) => {
|
|
|
2686
2723
|
pathSeparator,
|
|
2687
2724
|
items
|
|
2688
2725
|
} = state;
|
|
2726
|
+
// @ts-ignore
|
|
2689
2727
|
for (const file of files) {
|
|
2690
2728
|
// TODO path basename
|
|
2691
2729
|
const baseName = file;
|
|
@@ -2712,7 +2750,7 @@ const handleDropIntoFile = (state, dirent, index, files) => {
|
|
|
2712
2750
|
// @ts-ignore
|
|
2713
2751
|
return handleDropIndex(parentIndex);
|
|
2714
2752
|
};
|
|
2715
|
-
const handleDropIndex = async (state,
|
|
2753
|
+
const handleDropIndex = async (state, files, index) => {
|
|
2716
2754
|
const {
|
|
2717
2755
|
items
|
|
2718
2756
|
} = state;
|
|
@@ -2731,15 +2769,20 @@ const handleDropIndex = async (state, index, files) => {
|
|
|
2731
2769
|
}
|
|
2732
2770
|
};
|
|
2733
2771
|
|
|
2772
|
+
const getDropHandler = index => {
|
|
2773
|
+
switch (index) {
|
|
2774
|
+
case -1:
|
|
2775
|
+
return handleDropRoot;
|
|
2776
|
+
default:
|
|
2777
|
+
return handleDropIndex;
|
|
2778
|
+
}
|
|
2779
|
+
};
|
|
2734
2780
|
const handleDrop = async (state, x, y, files) => {
|
|
2735
2781
|
try {
|
|
2736
2782
|
const index = getIndexFromPosition(state, x, y);
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
default:
|
|
2741
|
-
return await handleDropIndex(state, index, files);
|
|
2742
|
-
}
|
|
2783
|
+
const fn = getDropHandler(index);
|
|
2784
|
+
const result = await fn(state, files, index);
|
|
2785
|
+
return result;
|
|
2743
2786
|
} catch (error) {
|
|
2744
2787
|
throw new VError(error, 'Failed to drop files');
|
|
2745
2788
|
}
|
|
@@ -2806,6 +2849,7 @@ const mergeDirents = (oldDirents, newDirents) => {
|
|
|
2806
2849
|
|
|
2807
2850
|
// TODO add lots of tests for this
|
|
2808
2851
|
const updateRoot = async state1 => {
|
|
2852
|
+
// @ts-ignore
|
|
2809
2853
|
if (state1.disposed) {
|
|
2810
2854
|
return state1;
|
|
2811
2855
|
}
|
|
@@ -3095,15 +3139,18 @@ const getExcluded = () => {
|
|
|
3095
3139
|
}
|
|
3096
3140
|
return excluded;
|
|
3097
3141
|
};
|
|
3098
|
-
const getSavedRoot
|
|
3142
|
+
const getSavedRoot = (savedState, workspacePath) => {
|
|
3099
3143
|
return workspacePath;
|
|
3100
3144
|
};
|
|
3101
3145
|
const loadContent = async (state, savedState) => {
|
|
3146
|
+
const {
|
|
3147
|
+
fileIconCache
|
|
3148
|
+
} = state;
|
|
3102
3149
|
const {
|
|
3103
3150
|
useChevrons
|
|
3104
3151
|
} = await getSettings();
|
|
3105
3152
|
const workspacePath = await getWorkspacePath();
|
|
3106
|
-
const root = getSavedRoot
|
|
3153
|
+
const root = getSavedRoot(savedState, workspacePath);
|
|
3107
3154
|
// TODO path separator could be restored from saved state
|
|
3108
3155
|
const pathSeparator = await getPathSeparator(root); // TODO only load path separator once
|
|
3109
3156
|
const excluded = getExcluded();
|
|
@@ -3124,7 +3171,7 @@ const loadContent = async (state, savedState) => {
|
|
|
3124
3171
|
const {
|
|
3125
3172
|
icons,
|
|
3126
3173
|
newFileIconCache
|
|
3127
|
-
} = await getFileIcons(restoredDirents,
|
|
3174
|
+
} = await getFileIcons(restoredDirents, fileIconCache);
|
|
3128
3175
|
return {
|
|
3129
3176
|
...state,
|
|
3130
3177
|
root,
|
|
@@ -3306,6 +3353,8 @@ const ButtonPrimary = 'ButtonPrimary';
|
|
|
3306
3353
|
const ButtonWide = 'ButtonWide';
|
|
3307
3354
|
const Chevron = 'Chevron';
|
|
3308
3355
|
const Explorer = 'Explorer';
|
|
3356
|
+
const Empty = '';
|
|
3357
|
+
const ExplorerDropTarget = 'DropTarget';
|
|
3309
3358
|
const FileIcon = 'FileIcon';
|
|
3310
3359
|
const FocusOutline = 'FocusOutline';
|
|
3311
3360
|
const IconButton = 'IconButton';
|
|
@@ -3339,6 +3388,8 @@ const HandleListBlur = 'handleListBlur';
|
|
|
3339
3388
|
const HandleListFocus = 'handleListFocus';
|
|
3340
3389
|
const HandlePointerDown = 'handlePointerDown';
|
|
3341
3390
|
const HandleWheel = 'handleWheel';
|
|
3391
|
+
const HandleDragOver = 'handleDragOver';
|
|
3392
|
+
const HandleDrop = 'handleDrop';
|
|
3342
3393
|
|
|
3343
3394
|
const mergeClassNames = (...classNames) => {
|
|
3344
3395
|
return classNames.filter(Boolean).join(' ');
|
|
@@ -3469,25 +3520,32 @@ const getActiveDescendant = focusedIndex => {
|
|
|
3469
3520
|
}
|
|
3470
3521
|
return undefined;
|
|
3471
3522
|
};
|
|
3472
|
-
const
|
|
3523
|
+
const getClassName = (focused, focusedIndex, dropTarget) => {
|
|
3524
|
+
const extraClass1 = focused && focusedIndex === -1 ? FocusOutline : Empty;
|
|
3525
|
+
const extraClass2 = dropTarget === dropTargetFull ? ExplorerDropTarget : Empty;
|
|
3526
|
+
const className = mergeClassNames(Viewlet, Explorer, extraClass1, extraClass2);
|
|
3527
|
+
return className;
|
|
3528
|
+
};
|
|
3529
|
+
const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused, dropTargets) => {
|
|
3473
3530
|
if (!root) {
|
|
3474
3531
|
return getExplorerWelcomeVirtualDom(isWide);
|
|
3475
3532
|
}
|
|
3476
|
-
const extraClass = focused && focusedIndex === -1 ? FocusOutline : '';
|
|
3477
3533
|
const dom = [{
|
|
3478
3534
|
type: Div,
|
|
3479
|
-
className:
|
|
3535
|
+
className: getClassName(focused, focusedIndex, dropTargets),
|
|
3480
3536
|
tabIndex: 0,
|
|
3481
3537
|
role: Tree,
|
|
3482
3538
|
ariaLabel: filesExplorer(),
|
|
3483
3539
|
childCount: visibleItems.length,
|
|
3484
3540
|
ariaActiveDescendant: getActiveDescendant(focusedIndex),
|
|
3485
|
-
onFocus: HandleListFocus,
|
|
3486
3541
|
onBlur: HandleListBlur,
|
|
3542
|
+
onClick: HandleClick,
|
|
3487
3543
|
onContextMenu: HandleContextMenu,
|
|
3544
|
+
onDragOver: HandleDragOver,
|
|
3545
|
+
onDrop: HandleDrop,
|
|
3546
|
+
onFocus: HandleListFocus,
|
|
3488
3547
|
onPointerDown: HandlePointerDown,
|
|
3489
|
-
onWheel: HandleWheel
|
|
3490
|
-
onClick: HandleClick
|
|
3548
|
+
onWheel: HandleWheel
|
|
3491
3549
|
}, ...visibleItems.flatMap(getExplorerItemVirtualDom)];
|
|
3492
3550
|
return dom;
|
|
3493
3551
|
};
|
|
@@ -3545,7 +3603,7 @@ const getTreeItemIndentWithChevron = (depth, chevron) => {
|
|
|
3545
3603
|
};
|
|
3546
3604
|
|
|
3547
3605
|
const ariaExpandedValues = [undefined, 'true', 'false'];
|
|
3548
|
-
const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editingIndex, editingType, editingValue, icons, useChevrons) => {
|
|
3606
|
+
const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editingIndex, editingType, editingValue, icons, useChevrons, dropTargets) => {
|
|
3549
3607
|
const visible = [];
|
|
3550
3608
|
const indentFn = useChevrons ? getTreeItemIndentWithChevron : getTreeItemIndent;
|
|
3551
3609
|
let iconIndex = 0;
|
|
@@ -3556,7 +3614,7 @@ const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editin
|
|
|
3556
3614
|
const indent = indentFn(item.depth, chevron);
|
|
3557
3615
|
const isFocused = i === focusedIndex;
|
|
3558
3616
|
const id = isFocused ? 'TreeItemActive' : undefined;
|
|
3559
|
-
const className = isFocused ? TreeItem
|
|
3617
|
+
const className = isFocused ? mergeClassNames(TreeItem, TreeItemActive) : TreeItem;
|
|
3560
3618
|
const expanded = getExpandedType(item.type);
|
|
3561
3619
|
const ariaExpanded = ariaExpandedValues[expanded];
|
|
3562
3620
|
visible.push({
|
|
@@ -3592,7 +3650,7 @@ const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editin
|
|
|
3592
3650
|
const renderItems = (oldState, newState) => {
|
|
3593
3651
|
const visibleDirents = getVisibleExplorerItems(newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex, newState.editingIndex, newState.editingType, newState.editingValue, newState.icons, newState.useChevrons);
|
|
3594
3652
|
const isWide = newState.width > 450;
|
|
3595
|
-
const dom = getExplorerVirtualDom(visibleDirents, newState.focusedIndex, newState.root, isWide, newState.focused);
|
|
3653
|
+
const dom = getExplorerVirtualDom(visibleDirents, newState.focusedIndex, newState.root, isWide, newState.focused, newState.dropTargets);
|
|
3596
3654
|
return ['Viewlet.setDom2', dom];
|
|
3597
3655
|
};
|
|
3598
3656
|
|
|
@@ -3749,31 +3807,47 @@ const renderEventListeners = () => {
|
|
|
3749
3807
|
name: HandleWheel,
|
|
3750
3808
|
params: ['handleWheel', 'event.deltaMode', 'event.deltaY'],
|
|
3751
3809
|
passive: true
|
|
3810
|
+
}, {
|
|
3811
|
+
name: HandleDragOver,
|
|
3812
|
+
params: ['handleDragOver', 'event.clientX', 'event.clientY'],
|
|
3813
|
+
preventDefault: true
|
|
3814
|
+
}, {
|
|
3815
|
+
name: HandleDrop,
|
|
3816
|
+
params: ['handleDrop', 'event.clientX', 'event.clientY', 'event.dataTransfer.files'],
|
|
3817
|
+
preventDefault: true
|
|
3752
3818
|
}];
|
|
3753
3819
|
};
|
|
3754
3820
|
|
|
3755
|
-
const
|
|
3756
|
-
|
|
3821
|
+
const getSavedMinLineY = savedState => {
|
|
3822
|
+
if (savedState && typeof savedState === 'object' && 'minLineY' in savedState && typeof savedState.minLineY === 'number') {
|
|
3823
|
+
return savedState.minLineY;
|
|
3824
|
+
}
|
|
3825
|
+
return 0;
|
|
3826
|
+
};
|
|
3827
|
+
const getSavedDeltaY = savedState => {
|
|
3828
|
+
if (savedState && typeof savedState === 'object' && 'deltaY' in savedState && typeof savedState.deltaY === 'number') {
|
|
3829
|
+
return savedState.deltaY;
|
|
3830
|
+
}
|
|
3831
|
+
return 0;
|
|
3832
|
+
};
|
|
3833
|
+
const getSavedWorkspacePath = savedState => {
|
|
3834
|
+
if (savedState && typeof savedState === 'object' && 'workspacePath' in savedState && typeof savedState.workspacePath === 'string') {
|
|
3835
|
+
return savedState.workspacePath;
|
|
3836
|
+
}
|
|
3837
|
+
return '';
|
|
3757
3838
|
};
|
|
3758
|
-
|
|
3759
3839
|
const restoreState = savedState => {
|
|
3760
3840
|
if (!savedState) {
|
|
3761
3841
|
return {
|
|
3842
|
+
root: '',
|
|
3762
3843
|
minLineY: 0,
|
|
3763
3844
|
deltaY: 0
|
|
3764
3845
|
};
|
|
3765
3846
|
}
|
|
3766
|
-
const root =
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
minLineY = savedState.minLineY;
|
|
3770
|
-
}
|
|
3771
|
-
let deltaY = 0;
|
|
3772
|
-
if (savedState && typeof savedState.deltaY === 'number') {
|
|
3773
|
-
deltaY = savedState.deltaY;
|
|
3774
|
-
}
|
|
3847
|
+
const root = getSavedWorkspacePath(savedState);
|
|
3848
|
+
const minLineY = getSavedMinLineY(savedState);
|
|
3849
|
+
const deltaY = getSavedDeltaY(savedState);
|
|
3775
3850
|
return {
|
|
3776
|
-
...savedState,
|
|
3777
3851
|
root,
|
|
3778
3852
|
minLineY,
|
|
3779
3853
|
deltaY
|
|
@@ -3866,8 +3940,8 @@ const getPathPartsToReveal = (root, pathParts, dirents) => {
|
|
|
3866
3940
|
}
|
|
3867
3941
|
return pathParts;
|
|
3868
3942
|
};
|
|
3869
|
-
const getPathPartChildren = pathPart => {
|
|
3870
|
-
const children = getChildDirents(pathPart.pathSeparator, pathPart);
|
|
3943
|
+
const getPathPartChildren = async pathPart => {
|
|
3944
|
+
const children = await getChildDirents(pathPart.pathSeparator, pathPart);
|
|
3871
3945
|
return children;
|
|
3872
3946
|
};
|
|
3873
3947
|
const mergeVisibleWithHiddenItems = (visibleItems, hiddenItems) => {
|
|
@@ -4097,13 +4171,13 @@ const commandMap = {
|
|
|
4097
4171
|
'Explorer.openContainingFolder': wrapCommand(openContainingFolder),
|
|
4098
4172
|
'Explorer.removeDirent': wrapCommand(removeDirent),
|
|
4099
4173
|
'Explorer.renameDirent': wrapCommand(renameDirent),
|
|
4100
|
-
'Explorer.restoreState':
|
|
4174
|
+
'Explorer.restoreState': restoreState,
|
|
4101
4175
|
'Explorer.revealItem': wrapCommand(revealItem),
|
|
4102
4176
|
'Explorer.setDeltaY': wrapCommand(setDeltaY),
|
|
4103
4177
|
'Explorer.updateEditingValue': wrapCommand(updateEditingValue),
|
|
4104
4178
|
'Explorer.updateIcons': wrapCommand(updateIcons),
|
|
4105
4179
|
// not wrapped
|
|
4106
|
-
'Explorer.
|
|
4180
|
+
'Explorer.create2': create2,
|
|
4107
4181
|
'Explorer.diff2': diff2,
|
|
4108
4182
|
'Explorer.getKeyBindings': getKeyBindings,
|
|
4109
4183
|
'Explorer.getMenuEntries': getMenuEntries,
|
|
@@ -4111,7 +4185,9 @@ const commandMap = {
|
|
|
4111
4185
|
'Explorer.renderActions2': renderActions,
|
|
4112
4186
|
'Explorer.renderEventListeners': renderEventListeners,
|
|
4113
4187
|
'Explorer.saveState': saveState,
|
|
4114
|
-
'Explorer.terminate': terminate
|
|
4188
|
+
'Explorer.terminate': terminate,
|
|
4189
|
+
// deprecated
|
|
4190
|
+
'Explorer.create': create
|
|
4115
4191
|
};
|
|
4116
4192
|
|
|
4117
4193
|
const listen = async () => {
|