@lvce-editor/settings-view 1.21.0 → 2.0.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/settingsViewWorkerMain.js +156 -58
- package/package.json +1 -1
|
@@ -921,6 +921,33 @@ const terminate = () => {
|
|
|
921
921
|
globalThis.close();
|
|
922
922
|
};
|
|
923
923
|
|
|
924
|
+
const computeScrollBar = (height, totalItemCount, itemHeight, scrollOffset, scrollBarMinHeight) => {
|
|
925
|
+
const totalHeight = totalItemCount * itemHeight;
|
|
926
|
+
const scrollable = Math.max(0, totalHeight - height);
|
|
927
|
+
const thumbTrack = Math.max(0, height);
|
|
928
|
+
const thumbHeight = totalHeight > 0 ? Math.max(scrollBarMinHeight, Math.floor(height / Math.max(totalHeight, 1) * height)) : height;
|
|
929
|
+
const thumbMaxTop = Math.max(0, thumbTrack - thumbHeight);
|
|
930
|
+
const thumbTop = scrollable > 0 ? Math.min(thumbMaxTop, Math.floor(scrollOffset / scrollable * thumbMaxTop)) : 0;
|
|
931
|
+
return {
|
|
932
|
+
thumbHeight,
|
|
933
|
+
thumbTop
|
|
934
|
+
};
|
|
935
|
+
};
|
|
936
|
+
|
|
937
|
+
const computeVisibleItems = (items, height, scrollOffset, itemHeight) => {
|
|
938
|
+
const safeItemHeight = itemHeight <= 0 ? 1 : itemHeight;
|
|
939
|
+
const totalItems = items.length;
|
|
940
|
+
const minLineY = Math.max(0, Math.floor(scrollOffset / safeItemHeight));
|
|
941
|
+
const itemsPerViewport = Math.max(1, Math.ceil(height / safeItemHeight));
|
|
942
|
+
const maxLineY = Math.min(totalItems, minLineY + itemsPerViewport);
|
|
943
|
+
const visibleItems = items.slice(minLineY, maxLineY);
|
|
944
|
+
return {
|
|
945
|
+
visibleItems,
|
|
946
|
+
minLineY,
|
|
947
|
+
maxLineY
|
|
948
|
+
};
|
|
949
|
+
};
|
|
950
|
+
|
|
924
951
|
const filterBySearch = (items, searchValue) => {
|
|
925
952
|
if (!searchValue || !searchValue.trim()) {
|
|
926
953
|
return items;
|
|
@@ -979,17 +1006,37 @@ const clear$1 = state => {
|
|
|
979
1006
|
items,
|
|
980
1007
|
tabs,
|
|
981
1008
|
modifiedSettings,
|
|
982
|
-
preferences
|
|
1009
|
+
preferences,
|
|
1010
|
+
height,
|
|
1011
|
+
itemHeight,
|
|
1012
|
+
scrollBarMinHeight
|
|
983
1013
|
} = state;
|
|
984
1014
|
const newSearchValue = '';
|
|
985
1015
|
const filteredItems = getFilteredItems(items, tabs, newSearchValue, modifiedSettings, preferences);
|
|
1016
|
+
const nextScrollOffset = 0;
|
|
1017
|
+
const {
|
|
1018
|
+
visibleItems,
|
|
1019
|
+
minLineY,
|
|
1020
|
+
maxLineY
|
|
1021
|
+
} = computeVisibleItems(filteredItems, height, nextScrollOffset, itemHeight);
|
|
1022
|
+
const {
|
|
1023
|
+
thumbHeight,
|
|
1024
|
+
thumbTop
|
|
1025
|
+
} = computeScrollBar(height, filteredItems.length, itemHeight, nextScrollOffset, scrollBarMinHeight);
|
|
986
1026
|
return {
|
|
987
1027
|
...state,
|
|
988
1028
|
filteredItems,
|
|
1029
|
+
visibleItems,
|
|
1030
|
+
minLineY,
|
|
1031
|
+
maxLineY,
|
|
1032
|
+
deltaY: 0,
|
|
1033
|
+
scrollOffset: nextScrollOffset,
|
|
989
1034
|
focus: FocusSettingsInput,
|
|
990
1035
|
focusSource: Script,
|
|
991
1036
|
inputSource: Script,
|
|
992
|
-
searchValue: newSearchValue
|
|
1037
|
+
searchValue: newSearchValue,
|
|
1038
|
+
scrollBarThumbHeight: thumbHeight,
|
|
1039
|
+
scrollBarThumbTop: thumbTop
|
|
993
1040
|
};
|
|
994
1041
|
};
|
|
995
1042
|
|
|
@@ -1055,11 +1102,11 @@ const isEqual$3 = (oldState, newState) => {
|
|
|
1055
1102
|
};
|
|
1056
1103
|
|
|
1057
1104
|
const isEqual$2 = (oldState, newState) => {
|
|
1058
|
-
return
|
|
1105
|
+
return true;
|
|
1059
1106
|
};
|
|
1060
1107
|
|
|
1061
1108
|
const isEqual$1 = (oldState, newState) => {
|
|
1062
|
-
return oldState.filteredItems === newState.filteredItems;
|
|
1109
|
+
return oldState.filteredItems === newState.filteredItems && oldState.visibleItems === newState.visibleItems;
|
|
1063
1110
|
};
|
|
1064
1111
|
|
|
1065
1112
|
const RenderItems = 1;
|
|
@@ -1203,14 +1250,34 @@ const handleClickTab = (state, name) => {
|
|
|
1203
1250
|
tabs,
|
|
1204
1251
|
searchValue,
|
|
1205
1252
|
modifiedSettings,
|
|
1206
|
-
preferences
|
|
1253
|
+
preferences,
|
|
1254
|
+
height,
|
|
1255
|
+
itemHeight,
|
|
1256
|
+
scrollOffset
|
|
1207
1257
|
} = state;
|
|
1208
1258
|
const updatedTabs = getUpdatedTabs(tabs, name);
|
|
1209
1259
|
const filteredItems = getFilteredItems(items, updatedTabs, searchValue, modifiedSettings, preferences);
|
|
1260
|
+
const {
|
|
1261
|
+
visibleItems,
|
|
1262
|
+
minLineY,
|
|
1263
|
+
maxLineY
|
|
1264
|
+
} = computeVisibleItems(filteredItems, height, scrollOffset, itemHeight);
|
|
1265
|
+
const {
|
|
1266
|
+
scrollBarMinHeight
|
|
1267
|
+
} = state;
|
|
1268
|
+
const {
|
|
1269
|
+
thumbHeight,
|
|
1270
|
+
thumbTop
|
|
1271
|
+
} = computeScrollBar(height, filteredItems.length, itemHeight, scrollOffset, scrollBarMinHeight);
|
|
1210
1272
|
return {
|
|
1211
1273
|
...state,
|
|
1212
1274
|
tabs: updatedTabs,
|
|
1213
|
-
filteredItems
|
|
1275
|
+
filteredItems,
|
|
1276
|
+
visibleItems,
|
|
1277
|
+
minLineY,
|
|
1278
|
+
maxLineY,
|
|
1279
|
+
scrollBarThumbHeight: thumbHeight,
|
|
1280
|
+
scrollBarThumbTop: thumbTop
|
|
1214
1281
|
};
|
|
1215
1282
|
};
|
|
1216
1283
|
|
|
@@ -1281,9 +1348,25 @@ const handleInput = (state, value, inputSource = User) => {
|
|
|
1281
1348
|
tabs,
|
|
1282
1349
|
history,
|
|
1283
1350
|
modifiedSettings,
|
|
1284
|
-
preferences
|
|
1351
|
+
preferences,
|
|
1352
|
+
height,
|
|
1353
|
+
itemHeight
|
|
1285
1354
|
} = state;
|
|
1286
1355
|
const filteredItems = getFilteredItems(items, tabs, value, modifiedSettings, preferences);
|
|
1356
|
+
// Reset scroll when filter value changes so the user sees results from the top
|
|
1357
|
+
const nextScrollOffset = 0;
|
|
1358
|
+
const {
|
|
1359
|
+
visibleItems,
|
|
1360
|
+
minLineY,
|
|
1361
|
+
maxLineY
|
|
1362
|
+
} = computeVisibleItems(filteredItems, height, nextScrollOffset, itemHeight);
|
|
1363
|
+
const {
|
|
1364
|
+
scrollBarMinHeight
|
|
1365
|
+
} = state;
|
|
1366
|
+
const {
|
|
1367
|
+
thumbHeight,
|
|
1368
|
+
thumbTop
|
|
1369
|
+
} = computeScrollBar(height, filteredItems.length, itemHeight, nextScrollOffset, scrollBarMinHeight);
|
|
1287
1370
|
const {
|
|
1288
1371
|
newHistory,
|
|
1289
1372
|
newHistoryIndex
|
|
@@ -1292,9 +1375,16 @@ const handleInput = (state, value, inputSource = User) => {
|
|
|
1292
1375
|
...state,
|
|
1293
1376
|
searchValue: value,
|
|
1294
1377
|
filteredItems,
|
|
1378
|
+
visibleItems,
|
|
1379
|
+
minLineY,
|
|
1380
|
+
maxLineY,
|
|
1381
|
+
deltaY: 0,
|
|
1382
|
+
scrollOffset: nextScrollOffset,
|
|
1295
1383
|
history: newHistory,
|
|
1296
1384
|
historyIndex: newHistoryIndex,
|
|
1297
|
-
inputSource
|
|
1385
|
+
inputSource,
|
|
1386
|
+
scrollBarThumbHeight: thumbHeight,
|
|
1387
|
+
scrollBarThumbTop: thumbTop
|
|
1298
1388
|
};
|
|
1299
1389
|
};
|
|
1300
1390
|
|
|
@@ -1408,33 +1498,6 @@ const clamp = (value, min, max) => {
|
|
|
1408
1498
|
return value;
|
|
1409
1499
|
};
|
|
1410
1500
|
|
|
1411
|
-
const computeScrollBar = (height, totalItemCount, itemHeight, scrollOffset, scrollBarMinHeight) => {
|
|
1412
|
-
const totalHeight = totalItemCount * itemHeight;
|
|
1413
|
-
const scrollable = Math.max(0, totalHeight - height);
|
|
1414
|
-
const thumbTrack = Math.max(0, height);
|
|
1415
|
-
const thumbHeight = totalHeight > 0 ? Math.max(scrollBarMinHeight, Math.floor(height / Math.max(totalHeight, 1) * height)) : height;
|
|
1416
|
-
const thumbMaxTop = Math.max(0, thumbTrack - thumbHeight);
|
|
1417
|
-
const thumbTop = scrollable > 0 ? Math.min(thumbMaxTop, Math.floor(scrollOffset / scrollable * thumbMaxTop)) : 0;
|
|
1418
|
-
return {
|
|
1419
|
-
thumbHeight,
|
|
1420
|
-
thumbTop
|
|
1421
|
-
};
|
|
1422
|
-
};
|
|
1423
|
-
|
|
1424
|
-
const computeVisibleItems = (items, height, scrollOffset, itemHeight) => {
|
|
1425
|
-
const safeItemHeight = itemHeight <= 0 ? 1 : itemHeight;
|
|
1426
|
-
const totalItems = items.length;
|
|
1427
|
-
const minLineY = Math.max(0, Math.floor(scrollOffset / safeItemHeight));
|
|
1428
|
-
const itemsPerViewport = Math.max(1, Math.ceil(height / safeItemHeight));
|
|
1429
|
-
const maxLineY = Math.min(totalItems, minLineY + itemsPerViewport);
|
|
1430
|
-
const visibleItems = items.slice(minLineY, maxLineY);
|
|
1431
|
-
return {
|
|
1432
|
-
visibleItems,
|
|
1433
|
-
minLineY,
|
|
1434
|
-
maxLineY
|
|
1435
|
-
};
|
|
1436
|
-
};
|
|
1437
|
-
|
|
1438
1501
|
const handleWheel = (state, eventDeltaY, inputSource = User) => {
|
|
1439
1502
|
const {
|
|
1440
1503
|
deltaY: deltaY,
|
|
@@ -1446,8 +1509,11 @@ const handleWheel = (state, eventDeltaY, inputSource = User) => {
|
|
|
1446
1509
|
const stepLimit = itemCount === 0 ? 10 : Number.POSITIVE_INFINITY;
|
|
1447
1510
|
const limitedEventDelta = Math.max(-stepLimit, Math.min(stepLimit, eventDeltaY));
|
|
1448
1511
|
const total = deltaY + limitedEventDelta;
|
|
1449
|
-
|
|
1450
|
-
|
|
1512
|
+
// Prevent scrolling beyond the available content height. If content is smaller
|
|
1513
|
+
// than the viewport, the maximum scroll is zero.
|
|
1514
|
+
const totalContentHeight = itemCount * itemHeight;
|
|
1515
|
+
const maxScrollable = Math.max(0, totalContentHeight - height);
|
|
1516
|
+
const clampedDeltaY = clamp(total, 0, maxScrollable);
|
|
1451
1517
|
const scrollOffset = clampedDeltaY;
|
|
1452
1518
|
const {
|
|
1453
1519
|
visibleItems,
|
|
@@ -4147,8 +4213,12 @@ const SettingsItem = 'SettingsItem';
|
|
|
4147
4213
|
const SettingsItemCheckBox = 'SettingsItemCheckBox';
|
|
4148
4214
|
const SettingsItemHeading = 'SettingsItemHeading';
|
|
4149
4215
|
const SettingsItems = 'SettingsItems';
|
|
4216
|
+
const SettingsItemWrapper = 'SettingsItemWrapper';
|
|
4150
4217
|
const SettingsMain = 'SettingsMain';
|
|
4151
4218
|
const SettingsNoResults = 'SettingsNoResults';
|
|
4219
|
+
const SettingsScrollBar = 'ScrollBar';
|
|
4220
|
+
const SettingsScrollBarSmall = 'ScrollBarSmall';
|
|
4221
|
+
const SettingsScrollBarThumb = 'ScrollBarThumb';
|
|
4152
4222
|
const SettingsSearchInput = 'SettingsSearchInput';
|
|
4153
4223
|
const SettingsSideBar = 'SettingsSideBar';
|
|
4154
4224
|
const SettingsTabs = 'SettingsTabs';
|
|
@@ -4173,7 +4243,6 @@ const HandleClickTab = 'handleClickTab';
|
|
|
4173
4243
|
const HandleInput = 'handleInput';
|
|
4174
4244
|
const HandleSettingInput = 'handleSettingInput';
|
|
4175
4245
|
const HandleSettingChecked = 'handleSettingChecked';
|
|
4176
|
-
const HandleScroll = 'handleScroll';
|
|
4177
4246
|
const HandleWheel = 'handleWheel';
|
|
4178
4247
|
const HandleSettingSelect = 'handleSettingSelect';
|
|
4179
4248
|
const HandleInputFocus = 'handleInputFocus';
|
|
@@ -4237,6 +4306,29 @@ const getSettingsHeaderDom = (filteredSettingsCount, hasSearchValue) => {
|
|
|
4237
4306
|
}, ...getSettingsInputDom(), ...getSettingsInputBadgeDom(filteredSettingsCount, hasSearchValue), ...getSettingsInputButtonsDom(hasSearchValue)];
|
|
4238
4307
|
};
|
|
4239
4308
|
|
|
4309
|
+
const getContentHeadingDom = headerText => {
|
|
4310
|
+
return [{
|
|
4311
|
+
type: VirtualDomElements.H1,
|
|
4312
|
+
className: SettingsContentHeading,
|
|
4313
|
+
childCount: 1
|
|
4314
|
+
}, text(headerText)];
|
|
4315
|
+
};
|
|
4316
|
+
|
|
4317
|
+
const parentNode$1 = {
|
|
4318
|
+
type: VirtualDomElements.Div,
|
|
4319
|
+
className: mergeClassNames(SettingsScrollBar, SettingsScrollBarSmall),
|
|
4320
|
+
childCount: 1
|
|
4321
|
+
};
|
|
4322
|
+
const getScrollBarDom = (thumbHeight, thumbTop) => {
|
|
4323
|
+
return [parentNode$1, {
|
|
4324
|
+
type: VirtualDomElements.Div,
|
|
4325
|
+
className: SettingsScrollBarThumb,
|
|
4326
|
+
childCount: 0,
|
|
4327
|
+
height: `${thumbHeight}px`,
|
|
4328
|
+
top: `${thumbTop}px`
|
|
4329
|
+
}];
|
|
4330
|
+
};
|
|
4331
|
+
|
|
4240
4332
|
const getErrorMessageDom = errorMessage => {
|
|
4241
4333
|
if (!errorMessage) {
|
|
4242
4334
|
return [];
|
|
@@ -4543,19 +4635,19 @@ const getSettingsItemsDom = (items, searchValue) => {
|
|
|
4543
4635
|
}, ...items.flatMap(getItemVirtualDom)];
|
|
4544
4636
|
};
|
|
4545
4637
|
|
|
4546
|
-
const getSettingsContentDom = (
|
|
4638
|
+
const getSettingsContentDom = (visibleItems, tabs, searchValue, thumbHeight, thumbTop) => {
|
|
4547
4639
|
const selectedTab = tabs.find(tab => tab.selected);
|
|
4548
4640
|
const headerText = selectedTab ? selectedTab.label : settingsContent();
|
|
4549
4641
|
return [{
|
|
4550
4642
|
type: VirtualDomElements.Div,
|
|
4551
4643
|
className: SettingsContent,
|
|
4552
4644
|
childCount: 2,
|
|
4553
|
-
|
|
4554
|
-
}, {
|
|
4555
|
-
type: VirtualDomElements.
|
|
4556
|
-
className:
|
|
4557
|
-
childCount:
|
|
4558
|
-
},
|
|
4645
|
+
onWheel: HandleWheel
|
|
4646
|
+
}, ...getContentHeadingDom(headerText), {
|
|
4647
|
+
type: VirtualDomElements.Div,
|
|
4648
|
+
className: SettingsItemWrapper,
|
|
4649
|
+
childCount: 2
|
|
4650
|
+
}, ...getSettingsItemsDom(visibleItems, searchValue), ...getScrollBarDom(thumbHeight, thumbTop)];
|
|
4559
4651
|
};
|
|
4560
4652
|
|
|
4561
4653
|
const getTabClassName = tab => {
|
|
@@ -4593,27 +4685,31 @@ const getSettingsSideBarDom = tabs => {
|
|
|
4593
4685
|
}, ...getSettingsTabsDom(tabs)];
|
|
4594
4686
|
};
|
|
4595
4687
|
|
|
4596
|
-
const getSettingsMainDom = (tabs,
|
|
4688
|
+
const getSettingsMainDom = (tabs, visibleItems, totalItemCount, searchValue, thumbHeight, thumbTop) => {
|
|
4597
4689
|
return [{
|
|
4598
4690
|
type: VirtualDomElements.Div,
|
|
4599
4691
|
className: SettingsMain,
|
|
4600
4692
|
childCount: 2
|
|
4601
|
-
}, ...getSettingsSideBarDom(tabs), ...getSettingsContentDom(
|
|
4693
|
+
}, ...getSettingsSideBarDom(tabs), ...getSettingsContentDom(visibleItems, tabs, searchValue, thumbHeight, thumbTop)];
|
|
4602
4694
|
};
|
|
4603
4695
|
|
|
4696
|
+
const parentNode = {
|
|
4697
|
+
type: VirtualDomElements.Div,
|
|
4698
|
+
childCount: 2,
|
|
4699
|
+
className: mergeClassNames(Viewlet, Settings)
|
|
4700
|
+
};
|
|
4604
4701
|
const getSettingsDom = state => {
|
|
4605
4702
|
const {
|
|
4606
4703
|
tabs,
|
|
4607
4704
|
filteredItems,
|
|
4608
|
-
|
|
4705
|
+
visibleItems,
|
|
4706
|
+
searchValue,
|
|
4707
|
+
scrollBarThumbHeight,
|
|
4708
|
+
scrollBarThumbTop
|
|
4609
4709
|
} = state;
|
|
4610
4710
|
const hasSearchValue = searchValue.trim().length > 0;
|
|
4611
4711
|
const filteredItemsCount = filteredItems.length;
|
|
4612
|
-
return [
|
|
4613
|
-
type: VirtualDomElements.Div,
|
|
4614
|
-
childCount: 2,
|
|
4615
|
-
className: mergeClassNames(Viewlet, Settings)
|
|
4616
|
-
}, ...getSettingsHeaderDom(filteredItemsCount, hasSearchValue), ...getSettingsMainDom(tabs, filteredItems, searchValue)];
|
|
4712
|
+
return [parentNode, ...getSettingsHeaderDom(filteredItemsCount, hasSearchValue), ...getSettingsMainDom(tabs, visibleItems, filteredItemsCount, searchValue, scrollBarThumbHeight, scrollBarThumbTop)];
|
|
4617
4713
|
};
|
|
4618
4714
|
|
|
4619
4715
|
const renderItems = (oldState, newState) => {
|
|
@@ -4715,11 +4811,13 @@ const renderEventListeners = () => {
|
|
|
4715
4811
|
}, {
|
|
4716
4812
|
name: HandleSettingChecked,
|
|
4717
4813
|
params: ['handleSettingChecked', 'event.target.name', 'event.target.value']
|
|
4718
|
-
},
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4814
|
+
},
|
|
4815
|
+
// {
|
|
4816
|
+
// name: DomEventListenerFunctions.HandleScroll,
|
|
4817
|
+
// params: ['handleScroll', 'event.target.scrollTop'],
|
|
4818
|
+
// passive: true,
|
|
4819
|
+
// },
|
|
4820
|
+
{
|
|
4723
4821
|
name: HandleWheel,
|
|
4724
4822
|
params: ['handleWheel', 'event.deltaY'],
|
|
4725
4823
|
passive: true
|