@lvce-editor/explorer-view 5.25.0 → 5.27.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/README.md +9 -0
- package/dist/explorerViewWorkerMain.js +109 -58
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2260,21 +2260,6 @@ const copyRelativePath = async state => {
|
|
|
2260
2260
|
return state;
|
|
2261
2261
|
};
|
|
2262
2262
|
|
|
2263
|
-
// TODO optimize this function to return the minimum number
|
|
2264
|
-
// of visible items needed, e.g. when not scrolled 5 items with
|
|
2265
|
-
// 20px fill 100px but when scrolled 6 items are needed
|
|
2266
|
-
const getNumberOfVisibleItems = (listHeight, itemHeight) => {
|
|
2267
|
-
if (listHeight <= 0 || itemHeight <= 0) {
|
|
2268
|
-
return 0;
|
|
2269
|
-
}
|
|
2270
|
-
return Math.ceil(listHeight / itemHeight) + 1;
|
|
2271
|
-
};
|
|
2272
|
-
|
|
2273
|
-
const getExplorerMaxLineY = (minLineY, height, itemHeight, direntsLength) => {
|
|
2274
|
-
const maxLineY = minLineY + Math.min(getNumberOfVisibleItems(height, itemHeight), direntsLength);
|
|
2275
|
-
return maxLineY;
|
|
2276
|
-
};
|
|
2277
|
-
|
|
2278
2263
|
const getIconsCached = (dirents, fileIconCache) => {
|
|
2279
2264
|
return dirents.map(dirent => fileIconCache[dirent]);
|
|
2280
2265
|
};
|
|
@@ -2359,6 +2344,21 @@ const getFileIcons = async (dirents, fileIconCache) => {
|
|
|
2359
2344
|
};
|
|
2360
2345
|
};
|
|
2361
2346
|
|
|
2347
|
+
// TODO optimize this function to return the minimum number
|
|
2348
|
+
// of visible items needed, e.g. when not scrolled 5 items with
|
|
2349
|
+
// 20px fill 100px but when scrolled 6 items are needed
|
|
2350
|
+
const getNumberOfVisibleItems = (listHeight, itemHeight) => {
|
|
2351
|
+
if (listHeight <= 0 || itemHeight <= 0) {
|
|
2352
|
+
return 0;
|
|
2353
|
+
}
|
|
2354
|
+
return Math.ceil(listHeight / itemHeight) + 1;
|
|
2355
|
+
};
|
|
2356
|
+
|
|
2357
|
+
const getExplorerMaxLineY = (minLineY, height, itemHeight, direntsLength) => {
|
|
2358
|
+
const maxLineY = minLineY + Math.min(getNumberOfVisibleItems(height, itemHeight), direntsLength);
|
|
2359
|
+
return maxLineY;
|
|
2360
|
+
};
|
|
2361
|
+
|
|
2362
2362
|
const None$4 = 0;
|
|
2363
2363
|
const Right = 1;
|
|
2364
2364
|
const Down = 2;
|
|
@@ -2457,13 +2457,6 @@ const mergeClassNames = (...classNames) => {
|
|
|
2457
2457
|
return classNames.filter(Boolean).join(' ');
|
|
2458
2458
|
};
|
|
2459
2459
|
|
|
2460
|
-
const px = value => {
|
|
2461
|
-
return `${value}px`;
|
|
2462
|
-
};
|
|
2463
|
-
const position = (x, y) => {
|
|
2464
|
-
return `${x}px ${y}px`;
|
|
2465
|
-
};
|
|
2466
|
-
|
|
2467
2460
|
const text = data => {
|
|
2468
2461
|
return {
|
|
2469
2462
|
childCount: 0,
|
|
@@ -2884,7 +2877,7 @@ const wrapListItemCommand = fn => {
|
|
|
2884
2877
|
const intermediate = get(id);
|
|
2885
2878
|
set(id, intermediate.oldState, updatedState);
|
|
2886
2879
|
const maxLineY = getExplorerMaxLineY(minLineY, height, itemHeight, items.length);
|
|
2887
|
-
if (items === intermediate.newState.items && minLineY === intermediate.newState.minLineY && editingIcon === intermediate.newState.editingIcon && cutItems === intermediate.newState.cutItems && editingErrorMessage === intermediate.newState.editingErrorMessage && dropTargets === intermediate.newState.dropTargets && fileIconCache === intermediate.newState.fileIconCache && decorations === intermediate.newState.decorations) {
|
|
2880
|
+
if (items === intermediate.newState.items && minLineY === intermediate.newState.minLineY && height === intermediate.newState.height && itemHeight === intermediate.newState.itemHeight && editingIcon === intermediate.newState.editingIcon && cutItems === intermediate.newState.cutItems && editingErrorMessage === intermediate.newState.editingErrorMessage && dropTargets === intermediate.newState.dropTargets && fileIconCache === intermediate.newState.fileIconCache && decorations === intermediate.newState.decorations) {
|
|
2888
2881
|
return;
|
|
2889
2882
|
}
|
|
2890
2883
|
const visible = items.slice(minLineY, maxLineY);
|
|
@@ -2981,7 +2974,7 @@ const isEqual$6 = (oldState, newState) => {
|
|
|
2981
2974
|
// TODO compute css more optimized
|
|
2982
2975
|
// maybe only when items change, and even then not
|
|
2983
2976
|
// always, but only when it affects the css
|
|
2984
|
-
return oldState.editingErrorMessage === newState.editingErrorMessage && oldState.errorMessageLeft === newState.errorMessageLeft && oldState.errorMessageTop === newState.errorMessageTop && oldState.maxIndent === newState.maxIndent && oldState.scrollBarActive === newState.scrollBarActive && oldState.scrollBarHeight === newState.scrollBarHeight && oldState.visibleExplorerItems === newState.visibleExplorerItems && oldState.width === newState.width;
|
|
2977
|
+
return oldState.deltaY === newState.deltaY && oldState.editingErrorMessage === newState.editingErrorMessage && oldState.errorMessageLeft === newState.errorMessageLeft && oldState.errorMessageTop === newState.errorMessageTop && oldState.maxIndent === newState.maxIndent && oldState.scrollBarActive === newState.scrollBarActive && oldState.scrollBarHeight === newState.scrollBarHeight && oldState.visibleExplorerItems === newState.visibleExplorerItems && oldState.width === newState.width;
|
|
2985
2978
|
};
|
|
2986
2979
|
|
|
2987
2980
|
const isEqual$5 = (oldState, newState) => {
|
|
@@ -4354,6 +4347,9 @@ const getNewDropTargets = (state, index) => {
|
|
|
4354
4347
|
return dropTargetFull;
|
|
4355
4348
|
}
|
|
4356
4349
|
const item = items[index];
|
|
4350
|
+
if (!item) {
|
|
4351
|
+
return dropTargetFull;
|
|
4352
|
+
}
|
|
4357
4353
|
if (!canBeDroppedInto(item)) {
|
|
4358
4354
|
const startIndex = getParentStartIndex(items, index);
|
|
4359
4355
|
const endIndex = getParentEndIndex(items, index);
|
|
@@ -5067,6 +5063,48 @@ const handlePointerDown = (state, button, x, y) => {
|
|
|
5067
5063
|
return state;
|
|
5068
5064
|
};
|
|
5069
5065
|
|
|
5066
|
+
const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
|
|
5067
|
+
if (size >= contentSize) {
|
|
5068
|
+
return 0;
|
|
5069
|
+
}
|
|
5070
|
+
return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
|
|
5071
|
+
};
|
|
5072
|
+
|
|
5073
|
+
const handleResize = (state, dimensions) => {
|
|
5074
|
+
const {
|
|
5075
|
+
height: rawHeight,
|
|
5076
|
+
width: rawWidth
|
|
5077
|
+
} = dimensions;
|
|
5078
|
+
if (!Number.isFinite(rawHeight) || !Number.isFinite(rawWidth)) {
|
|
5079
|
+
return state;
|
|
5080
|
+
}
|
|
5081
|
+
const height = Math.max(0, rawHeight);
|
|
5082
|
+
const width = Math.max(0, rawWidth);
|
|
5083
|
+
const {
|
|
5084
|
+
deltaY,
|
|
5085
|
+
itemHeight,
|
|
5086
|
+
items
|
|
5087
|
+
} = state;
|
|
5088
|
+
const contentHeight = items.length * itemHeight;
|
|
5089
|
+
const maxDeltaY = Math.max(contentHeight - height, 0);
|
|
5090
|
+
const newDeltaY = Math.min(Math.max(deltaY, 0), maxDeltaY);
|
|
5091
|
+
const minLineY = Math.round(newDeltaY / itemHeight);
|
|
5092
|
+
const maxLineY = getExplorerMaxLineY(minLineY, height, itemHeight, items.length);
|
|
5093
|
+
const scrollBarHeight = getScrollBarSize(height, contentHeight, 20);
|
|
5094
|
+
if (state.height === height && state.width === width && state.deltaY === newDeltaY && state.minLineY === minLineY && state.maxLineY === maxLineY && state.scrollBarHeight === scrollBarHeight) {
|
|
5095
|
+
return state;
|
|
5096
|
+
}
|
|
5097
|
+
return {
|
|
5098
|
+
...state,
|
|
5099
|
+
deltaY: newDeltaY,
|
|
5100
|
+
height,
|
|
5101
|
+
maxLineY,
|
|
5102
|
+
minLineY,
|
|
5103
|
+
scrollBarHeight,
|
|
5104
|
+
width
|
|
5105
|
+
};
|
|
5106
|
+
};
|
|
5107
|
+
|
|
5070
5108
|
const handleUpload = async (state, dirents) => {
|
|
5071
5109
|
const {
|
|
5072
5110
|
pathSeparator,
|
|
@@ -5087,6 +5125,9 @@ const handleUpload = async (state, dirents) => {
|
|
|
5087
5125
|
};
|
|
5088
5126
|
|
|
5089
5127
|
const setDeltaY = async (state, deltaY) => {
|
|
5128
|
+
if (!Number.isFinite(deltaY)) {
|
|
5129
|
+
return state;
|
|
5130
|
+
}
|
|
5090
5131
|
const {
|
|
5091
5132
|
height,
|
|
5092
5133
|
itemHeight,
|
|
@@ -5429,14 +5470,11 @@ const getEditingType = direntType => {
|
|
|
5429
5470
|
|
|
5430
5471
|
const getNewDirentsForRename = (items, focusedIndex) => {
|
|
5431
5472
|
const item = items[focusedIndex];
|
|
5432
|
-
const newItems = [...items];
|
|
5433
5473
|
const editingType = getEditingType(item.type);
|
|
5434
|
-
|
|
5435
|
-
newItems[focusedIndex] = {
|
|
5474
|
+
return [...items.slice(0, focusedIndex), {
|
|
5436
5475
|
...item,
|
|
5437
5476
|
type: editingType
|
|
5438
|
-
};
|
|
5439
|
-
return newItems;
|
|
5477
|
+
}, ...items.slice(focusedIndex + 1)];
|
|
5440
5478
|
};
|
|
5441
5479
|
|
|
5442
5480
|
const getRenameSelectionRange = name => {
|
|
@@ -5491,12 +5529,18 @@ const getIndentRule = indent => {
|
|
|
5491
5529
|
padding-left: ${indent}px;
|
|
5492
5530
|
}`;
|
|
5493
5531
|
};
|
|
5494
|
-
|
|
5532
|
+
|
|
5533
|
+
const getCss = (scrollBarHeight, scrollBarTop, uniqueIndents, errorMessageLeft, errorMessageTop, errorMessageWidth) => {
|
|
5495
5534
|
const rules = [`.Explorer {
|
|
5496
5535
|
--ScrollBarThumbHeight: ${scrollBarHeight}px;
|
|
5536
|
+
--ScrollBarThumbTop: ${scrollBarTop}px;
|
|
5497
5537
|
--ErrorMessageTop: ${errorMessageTop}px;
|
|
5498
5538
|
--ErrorMessageLeft: ${errorMessageLeft}px;
|
|
5499
5539
|
--ErrorMessageWidth: ${errorMessageWidth}px;
|
|
5540
|
+
}
|
|
5541
|
+
.Explorer .ScrollBarThumb {
|
|
5542
|
+
height: var(--ScrollBarThumbHeight);
|
|
5543
|
+
translate: 0px var(--ScrollBarThumbTop);
|
|
5500
5544
|
}`, ...uniqueIndents.map(getIndentRule)];
|
|
5501
5545
|
const css = rules.join('\n');
|
|
5502
5546
|
return css;
|
|
@@ -5513,6 +5557,17 @@ const getErrorMessagePosition = (itemHeight, focusedIndex, minLineY, depth, inde
|
|
|
5513
5557
|
};
|
|
5514
5558
|
};
|
|
5515
5559
|
|
|
5560
|
+
const getScrollBarTop = (height, contentHeight, scrollTop) => {
|
|
5561
|
+
if (contentHeight <= 0 || !Number.isFinite(contentHeight)) {
|
|
5562
|
+
return 0;
|
|
5563
|
+
}
|
|
5564
|
+
const scrollBarTop = Math.round(scrollTop / contentHeight * height);
|
|
5565
|
+
if (!Number.isFinite(scrollBarTop)) {
|
|
5566
|
+
return 0;
|
|
5567
|
+
}
|
|
5568
|
+
return scrollBarTop;
|
|
5569
|
+
};
|
|
5570
|
+
|
|
5516
5571
|
const getUnique = items => {
|
|
5517
5572
|
const seens = [];
|
|
5518
5573
|
for (const item of items) {
|
|
@@ -5523,9 +5578,18 @@ const getUnique = items => {
|
|
|
5523
5578
|
return seens;
|
|
5524
5579
|
};
|
|
5525
5580
|
|
|
5581
|
+
const getIndent = item => item.indent;
|
|
5582
|
+
const getUniqueIndents = items => {
|
|
5583
|
+
const indents = items.map(getIndent);
|
|
5584
|
+
const uniqueIndents = getUnique(indents);
|
|
5585
|
+
return uniqueIndents;
|
|
5586
|
+
};
|
|
5587
|
+
|
|
5526
5588
|
const renderCss = (oldState, newState) => {
|
|
5527
5589
|
const {
|
|
5590
|
+
deltaY,
|
|
5528
5591
|
focusedIndex,
|
|
5592
|
+
height,
|
|
5529
5593
|
itemHeight,
|
|
5530
5594
|
items,
|
|
5531
5595
|
minLineY,
|
|
@@ -5534,8 +5598,9 @@ const renderCss = (oldState, newState) => {
|
|
|
5534
5598
|
visibleExplorerItems,
|
|
5535
5599
|
width
|
|
5536
5600
|
} = newState;
|
|
5537
|
-
const
|
|
5538
|
-
const
|
|
5601
|
+
const uniqueIndents = getUniqueIndents(visibleExplorerItems);
|
|
5602
|
+
const contentHeight = items.length * itemHeight;
|
|
5603
|
+
const scrollBarTop = getScrollBarTop(height, contentHeight, deltaY);
|
|
5539
5604
|
const indent = 8;
|
|
5540
5605
|
const padding = 10;
|
|
5541
5606
|
const fileIconWidth = 16;
|
|
@@ -5547,7 +5612,7 @@ const renderCss = (oldState, newState) => {
|
|
|
5547
5612
|
left,
|
|
5548
5613
|
top
|
|
5549
5614
|
} = getErrorMessagePosition(itemHeight, focusedIndex, minLineY, depth, indent, fileIconWidth, padding + defaultPaddingLeft + chevronSpace, width);
|
|
5550
|
-
const css = getCss(scrollBarHeight, uniqueIndents, left, top, errorMessageWidth);
|
|
5615
|
+
const css = getCss(scrollBarHeight, scrollBarTop, uniqueIndents, left, top, errorMessageWidth);
|
|
5551
5616
|
return [SetCss, uid, css];
|
|
5552
5617
|
};
|
|
5553
5618
|
|
|
@@ -5617,11 +5682,14 @@ const renderFocus = (oldState, newState) => {
|
|
|
5617
5682
|
};
|
|
5618
5683
|
|
|
5619
5684
|
const renderFocusContext = (oldState, newState) => {
|
|
5685
|
+
const {
|
|
5686
|
+
uid
|
|
5687
|
+
} = newState;
|
|
5620
5688
|
if (newState.focus === Input$1) {
|
|
5621
|
-
return [SetFocusContext,
|
|
5689
|
+
return [SetFocusContext, uid, FocusExplorerEditBox];
|
|
5622
5690
|
}
|
|
5623
5691
|
if (newState.focus === List) {
|
|
5624
|
-
return [SetFocusContext,
|
|
5692
|
+
return [SetFocusContext, uid, FocusExplorer];
|
|
5625
5693
|
}
|
|
5626
5694
|
return [];
|
|
5627
5695
|
};
|
|
@@ -5839,25 +5907,11 @@ const getListItemsVirtualDom = (visibleItems, focusedIndex, focused, dropTargets
|
|
|
5839
5907
|
return dom;
|
|
5840
5908
|
};
|
|
5841
5909
|
|
|
5842
|
-
const
|
|
5843
|
-
if (size >= contentSize) {
|
|
5844
|
-
return 0;
|
|
5845
|
-
}
|
|
5846
|
-
return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
|
|
5847
|
-
};
|
|
5848
|
-
|
|
5849
|
-
const getScrollBarTop = (height, contentHeight, scrollTop) => {
|
|
5850
|
-
const scrollBarTop = Math.round(scrollTop / contentHeight * height);
|
|
5851
|
-
return scrollBarTop;
|
|
5852
|
-
};
|
|
5853
|
-
|
|
5854
|
-
const getScrollBarVirtualDom = (scrollBarHeight, scrollBarTop) => {
|
|
5910
|
+
const getScrollBarVirtualDom = scrollBarHeight => {
|
|
5855
5911
|
const shouldShowScrollbar = scrollBarHeight > 0;
|
|
5856
5912
|
if (!shouldShowScrollbar) {
|
|
5857
5913
|
return [];
|
|
5858
5914
|
}
|
|
5859
|
-
const heightString = px(scrollBarHeight);
|
|
5860
|
-
const translateString = position(0, scrollBarTop);
|
|
5861
5915
|
return [{
|
|
5862
5916
|
childCount: 1,
|
|
5863
5917
|
className: mergeClassNames(ScrollBar, ScrollBarSmall),
|
|
@@ -5865,8 +5919,6 @@ const getScrollBarVirtualDom = (scrollBarHeight, scrollBarTop) => {
|
|
|
5865
5919
|
}, {
|
|
5866
5920
|
childCount: 0,
|
|
5867
5921
|
className: ScrollBarThumb,
|
|
5868
|
-
height: heightString,
|
|
5869
|
-
translate: translateString,
|
|
5870
5922
|
type: Div
|
|
5871
5923
|
}];
|
|
5872
5924
|
};
|
|
@@ -5881,13 +5933,12 @@ const getChildCount = (scrollBarDomLength, errorDomLength) => {
|
|
|
5881
5933
|
}
|
|
5882
5934
|
return childCount;
|
|
5883
5935
|
};
|
|
5884
|
-
const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused, dropTargets, height, contentHeight,
|
|
5936
|
+
const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused, dropTargets, height, contentHeight, errorMessage) => {
|
|
5885
5937
|
if (!root) {
|
|
5886
5938
|
return getExplorerWelcomeVirtualDom(isWide);
|
|
5887
5939
|
}
|
|
5888
5940
|
const scrollBarHeight = getScrollBarSize(height, contentHeight, 20);
|
|
5889
|
-
const
|
|
5890
|
-
const scrollBarDom = getScrollBarVirtualDom(scrollBarHeight, scrollBarTop);
|
|
5941
|
+
const scrollBarDom = getScrollBarVirtualDom(scrollBarHeight);
|
|
5891
5942
|
const errorDom = getErrorMessageDom(errorMessage);
|
|
5892
5943
|
const childCount = getChildCount(scrollBarDom.length, errorDom.length);
|
|
5893
5944
|
const parentNode = {
|
|
@@ -5902,7 +5953,6 @@ const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused
|
|
|
5902
5953
|
|
|
5903
5954
|
const renderItems = (oldState, newState) => {
|
|
5904
5955
|
const {
|
|
5905
|
-
deltaY,
|
|
5906
5956
|
dropTargets,
|
|
5907
5957
|
editingErrorMessage,
|
|
5908
5958
|
focused,
|
|
@@ -5916,8 +5966,8 @@ const renderItems = (oldState, newState) => {
|
|
|
5916
5966
|
const visibleDirents = newState.visibleExplorerItems;
|
|
5917
5967
|
const isWide = width > 450;
|
|
5918
5968
|
const contentHeight = items.length * itemHeight;
|
|
5919
|
-
const dom = getExplorerVirtualDom(visibleDirents, focusedIndex, root, isWide, focused, dropTargets, height, contentHeight,
|
|
5920
|
-
return [SetDom2, dom];
|
|
5969
|
+
const dom = getExplorerVirtualDom(visibleDirents, focusedIndex, root, isWide, focused, dropTargets, height, contentHeight, editingErrorMessage);
|
|
5970
|
+
return [SetDom2, newState.uid, dom];
|
|
5921
5971
|
};
|
|
5922
5972
|
|
|
5923
5973
|
const renderIncremental = (oldState, newState) => {
|
|
@@ -6475,6 +6525,7 @@ const commandMap = {
|
|
|
6475
6525
|
'Explorer.handleKeyDown': wrapListItemCommand(handleKeyDown),
|
|
6476
6526
|
'Explorer.handlePaste': wrapListItemCommand(handlePaste),
|
|
6477
6527
|
'Explorer.handlePointerDown': wrapListItemCommand(handlePointerDown),
|
|
6528
|
+
'Explorer.handleResize': wrapListItemCommand(handleResize),
|
|
6478
6529
|
'Explorer.handleUpload': wrapListItemCommand(handleUpload),
|
|
6479
6530
|
'Explorer.handleWheel': wrapListItemCommand(handleWheel),
|
|
6480
6531
|
'Explorer.handleWorkspaceChange': wrapListItemCommand(handleWorkspaceChange),
|