@lvce-editor/explorer-view 1.21.0 → 1.22.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 +171 -115
- 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:
|
|
@@ -3511,71 +3547,54 @@ const renameDirent = state => {
|
|
|
3511
3547
|
};
|
|
3512
3548
|
};
|
|
3513
3549
|
|
|
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];
|
|
3550
|
+
const renderEditingIndex = (oldState, newState) => {
|
|
3551
|
+
return ['focusInput', 'ExplorerInput'];
|
|
3552
|
+
};
|
|
3553
|
+
|
|
3554
|
+
const renderItems = (oldState, newState) => {
|
|
3555
|
+
const visibleDirents = getVisibleExplorerItems(newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex, newState.editingIndex, newState.editingType, newState.editingValue, newState.icons, newState.useChevrons);
|
|
3556
|
+
const isWide = newState.width > 450;
|
|
3557
|
+
const dom = getExplorerVirtualDom(visibleDirents, newState.focusedIndex, newState.root, isWide, newState.focused);
|
|
3558
|
+
return ['Viewlet.setDom2', dom];
|
|
3559
|
+
};
|
|
3560
|
+
|
|
3561
|
+
const getRenderer = diffType => {
|
|
3562
|
+
switch (diffType) {
|
|
3563
|
+
case RenderEditingIndex:
|
|
3564
|
+
return renderEditingIndex;
|
|
3565
|
+
case RenderItems:
|
|
3566
|
+
return renderItems;
|
|
3567
|
+
default:
|
|
3568
|
+
throw new Error('unknown renderer');
|
|
3569
|
+
}
|
|
3570
|
+
};
|
|
3571
|
+
|
|
3572
|
+
const applyRender = (oldState, newState, diffResult) => {
|
|
3573
|
+
const commands = [];
|
|
3574
|
+
for (const item of diffResult) {
|
|
3575
|
+
const fn = getRenderer(item);
|
|
3576
|
+
commands.push(fn(oldState, newState));
|
|
3577
|
+
}
|
|
3578
|
+
return commands;
|
|
3579
|
+
};
|
|
3580
|
+
|
|
3581
|
+
const renderInternal = (oldState, newState) => {
|
|
3582
|
+
const diffResult = diff(oldState, newState);
|
|
3583
|
+
return applyRender(oldState, newState, diffResult);
|
|
3584
|
+
};
|
|
3556
3585
|
const doRender = (uid, _) => {
|
|
3557
3586
|
if (typeof uid === 'number') {
|
|
3558
3587
|
const {
|
|
3559
3588
|
oldState,
|
|
3560
3589
|
newState
|
|
3561
3590
|
} = 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
|
-
}
|
|
3591
|
+
const commands = renderInternal(oldState, newState);
|
|
3568
3592
|
return commands;
|
|
3569
3593
|
}
|
|
3570
3594
|
// deprecated
|
|
3571
3595
|
const oldState = uid;
|
|
3572
3596
|
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
|
-
}
|
|
3597
|
+
const commands = renderInternal(oldState, newState);
|
|
3579
3598
|
return commands;
|
|
3580
3599
|
};
|
|
3581
3600
|
|
|
@@ -3627,6 +3646,41 @@ const renderActions = state => {
|
|
|
3627
3646
|
return dom;
|
|
3628
3647
|
};
|
|
3629
3648
|
|
|
3649
|
+
const renderEventListeners = () => {
|
|
3650
|
+
return [{
|
|
3651
|
+
name: HandleBlur,
|
|
3652
|
+
params: ['handleBlur']
|
|
3653
|
+
}, {
|
|
3654
|
+
name: HandleFocus,
|
|
3655
|
+
params: ['handleFocus', 'event.isTrusted', 'event.target.className']
|
|
3656
|
+
}, {
|
|
3657
|
+
name: HandleBlur,
|
|
3658
|
+
params: ['handleBlur']
|
|
3659
|
+
}, {
|
|
3660
|
+
name: HandleClick,
|
|
3661
|
+
params: ['event.button', 'event.clientX', 'event.clientY'],
|
|
3662
|
+
preventDefault: true
|
|
3663
|
+
}, {
|
|
3664
|
+
name: HandleClickOpenFolder,
|
|
3665
|
+
params: [],
|
|
3666
|
+
preventDefault: true
|
|
3667
|
+
}, {
|
|
3668
|
+
name: HandlePointerDown,
|
|
3669
|
+
params: ['event.button', 'event.clientX', 'event.clientY'],
|
|
3670
|
+
preventDefault: true
|
|
3671
|
+
}, {
|
|
3672
|
+
name: HandleEditingInput,
|
|
3673
|
+
params: ['event.target.value']
|
|
3674
|
+
}, {
|
|
3675
|
+
name: HandleContextMenu,
|
|
3676
|
+
params: ['event.button', 'event.clientX', 'event.clientY']
|
|
3677
|
+
}, {
|
|
3678
|
+
name: HandleWheel,
|
|
3679
|
+
params: ['event.deltaMode', 'event.deltaY'],
|
|
3680
|
+
passive: true
|
|
3681
|
+
}];
|
|
3682
|
+
};
|
|
3683
|
+
|
|
3630
3684
|
const getSavedRoot = (savedState, workspacePath) => {
|
|
3631
3685
|
return workspacePath;
|
|
3632
3686
|
};
|
|
@@ -3957,10 +4011,10 @@ const commandMap = {
|
|
|
3957
4011
|
'Explorer.focusNext': wrapCommand(focusNext),
|
|
3958
4012
|
'Explorer.focusPrevious': wrapCommand(focusPrevious),
|
|
3959
4013
|
'Explorer.getActions': wrapCommand(getActions),
|
|
4014
|
+
'Explorer.getCommandIds': getCommandIds,
|
|
3960
4015
|
'Explorer.getKeyBindings': wrapCommand(getKeyBindings),
|
|
3961
4016
|
'Explorer.getMenuEntries': wrapCommand(getMenuEntries),
|
|
3962
4017
|
'Explorer.getVirtualDom': wrapCommand(getExplorerVirtualDom),
|
|
3963
|
-
'Explorer.getCommandIds': getCommandIds,
|
|
3964
4018
|
'Explorer.getVisibleItems': wrapCommand(getVisibleExplorerItems),
|
|
3965
4019
|
'Explorer.handleArrowLeft': wrapCommand(handleArrowLeft),
|
|
3966
4020
|
'Explorer.handleArrowRight': wrapCommand(handleArrowRight),
|
|
@@ -3996,7 +4050,9 @@ const commandMap = {
|
|
|
3996
4050
|
'Explorer.create': create,
|
|
3997
4051
|
'Explorer.render': doRender,
|
|
3998
4052
|
'Explorer.renderActions': renderActions,
|
|
3999
|
-
'Explorer.saveState': saveState
|
|
4053
|
+
'Explorer.saveState': saveState,
|
|
4054
|
+
'Explorer.renderEventListeners': renderEventListeners,
|
|
4055
|
+
'Explorer.diff': diff
|
|
4000
4056
|
};
|
|
4001
4057
|
|
|
4002
4058
|
const listen = async () => {
|