@lvce-editor/explorer-view 1.21.0 → 1.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 +180 -117
- package/package.json +1 -1
|
@@ -1332,6 +1332,43 @@ const create = (id, uri, x, y, width, height, args, parentUid) => {
|
|
|
1332
1332
|
return state;
|
|
1333
1333
|
};
|
|
1334
1334
|
|
|
1335
|
+
const RenderItems = 4;
|
|
1336
|
+
const RenderEditingIndex = 5;
|
|
1337
|
+
|
|
1338
|
+
const diffType$1 = RenderEditingIndex;
|
|
1339
|
+
const isEqual$2 = (oldState, newState) => {
|
|
1340
|
+
return oldState.editingIndex === newState.editingIndex && oldState.editingType === newState.editingType;
|
|
1341
|
+
};
|
|
1342
|
+
|
|
1343
|
+
const DiffEditingIndex = {
|
|
1344
|
+
__proto__: null,
|
|
1345
|
+
diffType: diffType$1,
|
|
1346
|
+
isEqual: isEqual$2
|
|
1347
|
+
};
|
|
1348
|
+
|
|
1349
|
+
const diffType = RenderItems;
|
|
1350
|
+
const isEqual$1 = (oldState, newState) => {
|
|
1351
|
+
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;
|
|
1352
|
+
};
|
|
1353
|
+
|
|
1354
|
+
const DiffItems = {
|
|
1355
|
+
__proto__: null,
|
|
1356
|
+
diffType,
|
|
1357
|
+
isEqual: isEqual$1
|
|
1358
|
+
};
|
|
1359
|
+
|
|
1360
|
+
const modules = [DiffItems, DiffEditingIndex];
|
|
1361
|
+
|
|
1362
|
+
const diff = (oldState, newState) => {
|
|
1363
|
+
const diffResult = [];
|
|
1364
|
+
for (const module of modules) {
|
|
1365
|
+
if (!module.isEqual(oldState, newState)) {
|
|
1366
|
+
diffResult.push(module.diffType);
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
return diffResult;
|
|
1370
|
+
};
|
|
1371
|
+
|
|
1335
1372
|
const isSymbolicLink = dirent => {
|
|
1336
1373
|
return dirent.type === Symlink;
|
|
1337
1374
|
};
|
|
@@ -1895,7 +1932,7 @@ const WelcomeMessage = 'WelcomeMessage';
|
|
|
1895
1932
|
|
|
1896
1933
|
const HandleBlur = 'handleBlur';
|
|
1897
1934
|
const HandleClick = 'handleClick';
|
|
1898
|
-
const
|
|
1935
|
+
const HandleClickOpenFolder = 'handleClickOpenFolder';
|
|
1899
1936
|
const HandleContextMenu = 'handleContextMenu';
|
|
1900
1937
|
const HandleEditingInput = 'handleEditingInput';
|
|
1901
1938
|
const HandleFocus = 'handleFocus';
|
|
@@ -2022,7 +2059,7 @@ const getExplorerWelcomeVirtualDom = isWide => {
|
|
|
2022
2059
|
type: Button,
|
|
2023
2060
|
className: mergeClassNames(Button$1, ButtonPrimary, isWide ? ButtonWide : ButtonNarrow),
|
|
2024
2061
|
childCount: 1,
|
|
2025
|
-
onClick:
|
|
2062
|
+
onClick: HandleClickOpenFolder
|
|
2026
2063
|
}, text(openFolder$1())];
|
|
2027
2064
|
};
|
|
2028
2065
|
|
|
@@ -2375,6 +2412,60 @@ const focusParentFolder = state => {
|
|
|
2375
2412
|
return focusIndex(state, parentStartIndex);
|
|
2376
2413
|
};
|
|
2377
2414
|
|
|
2415
|
+
const handleClickDirectoryExpanded = async (state, dirent, index, keepFocus) => {
|
|
2416
|
+
const {
|
|
2417
|
+
minLineY,
|
|
2418
|
+
maxLineY,
|
|
2419
|
+
itemHeight,
|
|
2420
|
+
fileIconCache
|
|
2421
|
+
} = state;
|
|
2422
|
+
// @ts-ignore
|
|
2423
|
+
dirent.type = Directory;
|
|
2424
|
+
// @ts-ignore
|
|
2425
|
+
dirent.icon = getIcon();
|
|
2426
|
+
const endIndex = getParentEndIndex(state.items, index);
|
|
2427
|
+
const removeCount = endIndex - index - 1;
|
|
2428
|
+
// TODO race conditions and side effects are everywhere
|
|
2429
|
+
const newDirents = [...state.items];
|
|
2430
|
+
newDirents.splice(index + 1, removeCount);
|
|
2431
|
+
const newTotal = newDirents.length;
|
|
2432
|
+
if (newTotal < maxLineY) {
|
|
2433
|
+
const visibleItems = Math.min(maxLineY - minLineY, newTotal);
|
|
2434
|
+
const newMaxLineY = Math.min(maxLineY, newTotal);
|
|
2435
|
+
const newMinLineY = newMaxLineY - visibleItems;
|
|
2436
|
+
const deltaY = newMinLineY * itemHeight;
|
|
2437
|
+
const parts = newDirents.slice(minLineY, maxLineY);
|
|
2438
|
+
const {
|
|
2439
|
+
icons,
|
|
2440
|
+
newFileIconCache
|
|
2441
|
+
} = await getFileIcons(parts, fileIconCache);
|
|
2442
|
+
return {
|
|
2443
|
+
...state,
|
|
2444
|
+
items: newDirents,
|
|
2445
|
+
icons,
|
|
2446
|
+
fileIconCache: newFileIconCache,
|
|
2447
|
+
focusedIndex: index,
|
|
2448
|
+
focused: keepFocus,
|
|
2449
|
+
minLineY: newMinLineY,
|
|
2450
|
+
maxLineY: newMaxLineY,
|
|
2451
|
+
deltaY
|
|
2452
|
+
};
|
|
2453
|
+
}
|
|
2454
|
+
const parts = newDirents.slice(state.minLineY, state.maxLineY);
|
|
2455
|
+
const {
|
|
2456
|
+
icons,
|
|
2457
|
+
newFileIconCache
|
|
2458
|
+
} = await getFileIcons(parts, fileIconCache);
|
|
2459
|
+
return {
|
|
2460
|
+
...state,
|
|
2461
|
+
items: newDirents,
|
|
2462
|
+
icons,
|
|
2463
|
+
fileIconCache: newFileIconCache,
|
|
2464
|
+
focusedIndex: index,
|
|
2465
|
+
focused: keepFocus
|
|
2466
|
+
};
|
|
2467
|
+
};
|
|
2468
|
+
|
|
2378
2469
|
const handleArrowLeft = state => {
|
|
2379
2470
|
const {
|
|
2380
2471
|
items,
|
|
@@ -2390,8 +2481,7 @@ const handleArrowLeft = state => {
|
|
|
2390
2481
|
case SymLinkFile:
|
|
2391
2482
|
return focusParentFolder(state);
|
|
2392
2483
|
case DirectoryExpanded:
|
|
2393
|
-
|
|
2394
|
-
return handleClickDirectoryExpanded(state, dirent, focusedIndex);
|
|
2484
|
+
return handleClickDirectoryExpanded(state, dirent, focusedIndex, true);
|
|
2395
2485
|
default:
|
|
2396
2486
|
// TODO handle expanding directory and cancel file system call to read child dirents
|
|
2397
2487
|
return state;
|
|
@@ -2522,60 +2612,6 @@ const handleBlur = state => {
|
|
|
2522
2612
|
};
|
|
2523
2613
|
};
|
|
2524
2614
|
|
|
2525
|
-
const handleClickDirectoryExpanded$1 = async (state, dirent, index, keepFocus) => {
|
|
2526
|
-
const {
|
|
2527
|
-
minLineY,
|
|
2528
|
-
maxLineY,
|
|
2529
|
-
itemHeight,
|
|
2530
|
-
fileIconCache
|
|
2531
|
-
} = state;
|
|
2532
|
-
// @ts-ignore
|
|
2533
|
-
dirent.type = Directory;
|
|
2534
|
-
// @ts-ignore
|
|
2535
|
-
dirent.icon = getIcon();
|
|
2536
|
-
const endIndex = getParentEndIndex(state.items, index);
|
|
2537
|
-
const removeCount = endIndex - index - 1;
|
|
2538
|
-
// TODO race conditions and side effects are everywhere
|
|
2539
|
-
const newDirents = [...state.items];
|
|
2540
|
-
newDirents.splice(index + 1, removeCount);
|
|
2541
|
-
const newTotal = newDirents.length;
|
|
2542
|
-
if (newTotal < maxLineY) {
|
|
2543
|
-
const visibleItems = Math.min(maxLineY - minLineY, newTotal);
|
|
2544
|
-
const newMaxLineY = Math.min(maxLineY, newTotal);
|
|
2545
|
-
const newMinLineY = newMaxLineY - visibleItems;
|
|
2546
|
-
const deltaY = newMinLineY * itemHeight;
|
|
2547
|
-
const parts = newDirents.slice(minLineY, maxLineY);
|
|
2548
|
-
const {
|
|
2549
|
-
icons,
|
|
2550
|
-
newFileIconCache
|
|
2551
|
-
} = await getFileIcons(parts, fileIconCache);
|
|
2552
|
-
return {
|
|
2553
|
-
...state,
|
|
2554
|
-
items: newDirents,
|
|
2555
|
-
icons,
|
|
2556
|
-
fileIconCache: newFileIconCache,
|
|
2557
|
-
focusedIndex: index,
|
|
2558
|
-
focused: keepFocus,
|
|
2559
|
-
minLineY: newMinLineY,
|
|
2560
|
-
maxLineY: newMaxLineY,
|
|
2561
|
-
deltaY
|
|
2562
|
-
};
|
|
2563
|
-
}
|
|
2564
|
-
const parts = newDirents.slice(state.minLineY, state.maxLineY);
|
|
2565
|
-
const {
|
|
2566
|
-
icons,
|
|
2567
|
-
newFileIconCache
|
|
2568
|
-
} = await getFileIcons(parts, fileIconCache);
|
|
2569
|
-
return {
|
|
2570
|
-
...state,
|
|
2571
|
-
items: newDirents,
|
|
2572
|
-
icons,
|
|
2573
|
-
fileIconCache: newFileIconCache,
|
|
2574
|
-
focusedIndex: index,
|
|
2575
|
-
focused: keepFocus
|
|
2576
|
-
};
|
|
2577
|
-
};
|
|
2578
|
-
|
|
2579
2615
|
const handleClickDirectoryExpanding = async (state, dirent, index, keepFocus) => {
|
|
2580
2616
|
// @ts-ignore
|
|
2581
2617
|
dirent.type = Directory;
|
|
@@ -2616,7 +2652,7 @@ const getClickFn = direntType => {
|
|
|
2616
2652
|
case DirectoryExpanding:
|
|
2617
2653
|
return handleClickDirectoryExpanding;
|
|
2618
2654
|
case DirectoryExpanded:
|
|
2619
|
-
return handleClickDirectoryExpanded
|
|
2655
|
+
return handleClickDirectoryExpanded;
|
|
2620
2656
|
case Symlink:
|
|
2621
2657
|
return handleClickSymLink;
|
|
2622
2658
|
case CharacterDevice:
|
|
@@ -3167,7 +3203,7 @@ const handleUpload = async (state, dirents) => {
|
|
|
3167
3203
|
}
|
|
3168
3204
|
};
|
|
3169
3205
|
|
|
3170
|
-
const setDeltaY = (state, deltaY) => {
|
|
3206
|
+
const setDeltaY = async (state, deltaY) => {
|
|
3171
3207
|
const {
|
|
3172
3208
|
itemHeight,
|
|
3173
3209
|
height,
|
|
@@ -3183,11 +3219,18 @@ const setDeltaY = (state, deltaY) => {
|
|
|
3183
3219
|
}
|
|
3184
3220
|
const minLineY = Math.round(deltaY / itemHeight);
|
|
3185
3221
|
const maxLineY = minLineY + Math.round(height / itemHeight);
|
|
3222
|
+
const visible = items.slice(minLineY, maxLineY);
|
|
3223
|
+
const {
|
|
3224
|
+
icons,
|
|
3225
|
+
newFileIconCache
|
|
3226
|
+
} = await getFileIcons(visible, state.fileIconCache);
|
|
3186
3227
|
return {
|
|
3187
3228
|
...state,
|
|
3188
3229
|
deltaY,
|
|
3189
3230
|
minLineY,
|
|
3190
|
-
maxLineY
|
|
3231
|
+
maxLineY,
|
|
3232
|
+
icons,
|
|
3233
|
+
fileIconCache: newFileIconCache
|
|
3191
3234
|
};
|
|
3192
3235
|
};
|
|
3193
3236
|
|
|
@@ -3511,71 +3554,54 @@ const renameDirent = state => {
|
|
|
3511
3554
|
};
|
|
3512
3555
|
};
|
|
3513
3556
|
|
|
3514
|
-
const
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
return oldState.editingIndex === newState.editingIndex && oldState.editingType === newState.editingType;
|
|
3550
|
-
},
|
|
3551
|
-
apply(oldState, newState) {
|
|
3552
|
-
return ['focusInput', 'ExplorerInput'];
|
|
3553
|
-
}
|
|
3554
|
-
};
|
|
3555
|
-
const render = [renderItems, renderEditingIndex];
|
|
3557
|
+
const renderEditingIndex = (oldState, newState) => {
|
|
3558
|
+
return ['focusInput', 'ExplorerInput'];
|
|
3559
|
+
};
|
|
3560
|
+
|
|
3561
|
+
const renderItems = (oldState, newState) => {
|
|
3562
|
+
const visibleDirents = getVisibleExplorerItems(newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex, newState.editingIndex, newState.editingType, newState.editingValue, newState.icons, newState.useChevrons);
|
|
3563
|
+
const isWide = newState.width > 450;
|
|
3564
|
+
const dom = getExplorerVirtualDom(visibleDirents, newState.focusedIndex, newState.root, isWide, newState.focused);
|
|
3565
|
+
return ['Viewlet.setDom2', dom];
|
|
3566
|
+
};
|
|
3567
|
+
|
|
3568
|
+
const getRenderer = diffType => {
|
|
3569
|
+
switch (diffType) {
|
|
3570
|
+
case RenderEditingIndex:
|
|
3571
|
+
return renderEditingIndex;
|
|
3572
|
+
case RenderItems:
|
|
3573
|
+
return renderItems;
|
|
3574
|
+
default:
|
|
3575
|
+
throw new Error('unknown renderer');
|
|
3576
|
+
}
|
|
3577
|
+
};
|
|
3578
|
+
|
|
3579
|
+
const applyRender = (oldState, newState, diffResult) => {
|
|
3580
|
+
const commands = [];
|
|
3581
|
+
for (const item of diffResult) {
|
|
3582
|
+
const fn = getRenderer(item);
|
|
3583
|
+
commands.push(fn(oldState, newState));
|
|
3584
|
+
}
|
|
3585
|
+
return commands;
|
|
3586
|
+
};
|
|
3587
|
+
|
|
3588
|
+
const renderInternal = (oldState, newState) => {
|
|
3589
|
+
const diffResult = diff(oldState, newState);
|
|
3590
|
+
return applyRender(oldState, newState, diffResult);
|
|
3591
|
+
};
|
|
3556
3592
|
const doRender = (uid, _) => {
|
|
3557
3593
|
if (typeof uid === 'number') {
|
|
3558
3594
|
const {
|
|
3559
3595
|
oldState,
|
|
3560
3596
|
newState
|
|
3561
3597
|
} = get(uid);
|
|
3562
|
-
const commands =
|
|
3563
|
-
for (const fn of render) {
|
|
3564
|
-
if (!fn.isEqual(oldState, newState)) {
|
|
3565
|
-
commands.push(fn.apply(oldState, newState));
|
|
3566
|
-
}
|
|
3567
|
-
}
|
|
3598
|
+
const commands = renderInternal(oldState, newState);
|
|
3568
3599
|
return commands;
|
|
3569
3600
|
}
|
|
3570
3601
|
// deprecated
|
|
3571
3602
|
const oldState = uid;
|
|
3572
3603
|
const newState = _;
|
|
3573
|
-
const commands =
|
|
3574
|
-
for (const fn of render) {
|
|
3575
|
-
if (!fn.isEqual(oldState, newState)) {
|
|
3576
|
-
commands.push(fn.apply(oldState, newState));
|
|
3577
|
-
}
|
|
3578
|
-
}
|
|
3604
|
+
const commands = renderInternal(oldState, newState);
|
|
3579
3605
|
return commands;
|
|
3580
3606
|
};
|
|
3581
3607
|
|
|
@@ -3627,6 +3653,41 @@ const renderActions = state => {
|
|
|
3627
3653
|
return dom;
|
|
3628
3654
|
};
|
|
3629
3655
|
|
|
3656
|
+
const renderEventListeners = () => {
|
|
3657
|
+
return [{
|
|
3658
|
+
name: HandleBlur,
|
|
3659
|
+
params: ['handleBlur']
|
|
3660
|
+
}, {
|
|
3661
|
+
name: HandleFocus,
|
|
3662
|
+
params: ['handleFocus', 'event.isTrusted', 'event.target.className']
|
|
3663
|
+
}, {
|
|
3664
|
+
name: HandleBlur,
|
|
3665
|
+
params: ['handleBlur']
|
|
3666
|
+
}, {
|
|
3667
|
+
name: HandleClick,
|
|
3668
|
+
params: ['event.button', 'event.clientX', 'event.clientY'],
|
|
3669
|
+
preventDefault: true
|
|
3670
|
+
}, {
|
|
3671
|
+
name: HandleClickOpenFolder,
|
|
3672
|
+
params: [],
|
|
3673
|
+
preventDefault: true
|
|
3674
|
+
}, {
|
|
3675
|
+
name: HandlePointerDown,
|
|
3676
|
+
params: ['event.button', 'event.clientX', 'event.clientY'],
|
|
3677
|
+
preventDefault: true
|
|
3678
|
+
}, {
|
|
3679
|
+
name: HandleEditingInput,
|
|
3680
|
+
params: ['event.target.value']
|
|
3681
|
+
}, {
|
|
3682
|
+
name: HandleContextMenu,
|
|
3683
|
+
params: ['event.button', 'event.clientX', 'event.clientY']
|
|
3684
|
+
}, {
|
|
3685
|
+
name: HandleWheel,
|
|
3686
|
+
params: ['event.deltaMode', 'event.deltaY'],
|
|
3687
|
+
passive: true
|
|
3688
|
+
}];
|
|
3689
|
+
};
|
|
3690
|
+
|
|
3630
3691
|
const getSavedRoot = (savedState, workspacePath) => {
|
|
3631
3692
|
return workspacePath;
|
|
3632
3693
|
};
|
|
@@ -3957,10 +4018,10 @@ const commandMap = {
|
|
|
3957
4018
|
'Explorer.focusNext': wrapCommand(focusNext),
|
|
3958
4019
|
'Explorer.focusPrevious': wrapCommand(focusPrevious),
|
|
3959
4020
|
'Explorer.getActions': wrapCommand(getActions),
|
|
4021
|
+
'Explorer.getCommandIds': getCommandIds,
|
|
3960
4022
|
'Explorer.getKeyBindings': wrapCommand(getKeyBindings),
|
|
3961
4023
|
'Explorer.getMenuEntries': wrapCommand(getMenuEntries),
|
|
3962
4024
|
'Explorer.getVirtualDom': wrapCommand(getExplorerVirtualDom),
|
|
3963
|
-
'Explorer.getCommandIds': getCommandIds,
|
|
3964
4025
|
'Explorer.getVisibleItems': wrapCommand(getVisibleExplorerItems),
|
|
3965
4026
|
'Explorer.handleArrowLeft': wrapCommand(handleArrowLeft),
|
|
3966
4027
|
'Explorer.handleArrowRight': wrapCommand(handleArrowRight),
|
|
@@ -3996,7 +4057,9 @@ const commandMap = {
|
|
|
3996
4057
|
'Explorer.create': create,
|
|
3997
4058
|
'Explorer.render': doRender,
|
|
3998
4059
|
'Explorer.renderActions': renderActions,
|
|
3999
|
-
'Explorer.saveState': saveState
|
|
4060
|
+
'Explorer.saveState': saveState,
|
|
4061
|
+
'Explorer.renderEventListeners': renderEventListeners,
|
|
4062
|
+
'Explorer.diff': diff
|
|
4000
4063
|
};
|
|
4001
4064
|
|
|
4002
4065
|
const listen = async () => {
|