@lvce-editor/settings-view 1.20.0 → 1.21.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.
@@ -477,7 +477,8 @@ const splitLines = lines => {
477
477
  return lines.split(NewLine);
478
478
  };
479
479
  const getCurrentStack = () => {
480
- const currentStack = joinLines(splitLines(new Error().stack || '').slice(2));
480
+ const stackLinesToSkip = 3;
481
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
481
482
  return currentStack;
482
483
  };
483
484
  const getNewLineIndex = (string, startIndex = undefined) => {
@@ -748,6 +749,12 @@ const invokeAndTransfer = (ipc, method, ...params) => {
748
749
  return invokeHelper(ipc, method, params, true);
749
750
  };
750
751
 
752
+ class CommandNotFoundError extends Error {
753
+ constructor(command) {
754
+ super(`Command not found ${command}`);
755
+ this.name = 'CommandNotFoundError';
756
+ }
757
+ }
751
758
  const commands = Object.create(null);
752
759
  const register = commandMap => {
753
760
  Object.assign(commands, commandMap);
@@ -758,7 +765,7 @@ const getCommand = key => {
758
765
  const execute = (command, ...args) => {
759
766
  const fn = getCommand(command);
760
767
  if (!fn) {
761
- throw new Error(`command not found ${command}`);
768
+ throw new CommandNotFoundError(command);
762
769
  }
763
770
  return fn(...args);
764
771
  };
@@ -933,6 +940,7 @@ const filterByTab = (items, tabs) => {
933
940
  const isItemModified = (item, preferences) => {
934
941
  return item.id in preferences;
935
942
  };
943
+
936
944
  const validateSettings = (items, modifiedSettings, preferences) => {
937
945
  return items.map(item => {
938
946
  const value = preferences[item.id] ?? item.value;
@@ -1013,6 +1021,8 @@ const create$1 = (id, uri, x, y, width, height) => {
1013
1021
  y,
1014
1022
  width,
1015
1023
  height,
1024
+ deltaY: 0,
1025
+ itemHeight: 100,
1016
1026
  tabs: [],
1017
1027
  items: [],
1018
1028
  searchValue: '',
@@ -1020,11 +1030,18 @@ const create$1 = (id, uri, x, y, width, height) => {
1020
1030
  preferences: {},
1021
1031
  inputSource: 0,
1022
1032
  scrollOffset: 0,
1033
+ minLineY: 0,
1034
+ maxLineY: 0,
1035
+ visibleItems: [],
1023
1036
  filteredItemsCount: 0,
1024
1037
  history: [],
1025
1038
  historyIndex: -1,
1026
1039
  modifiedSettings: {},
1027
- focusSource: 0
1040
+ focusSource: 0,
1041
+ scrollBarMinHeight: 0,
1042
+ scrollBarThumbHeight: 0,
1043
+ scrollBarThumbTop: 0,
1044
+ highlightsEnabled: false
1028
1045
  };
1029
1046
  set$1(id, state, state);
1030
1047
  };
@@ -1034,7 +1051,7 @@ const isEqual$4 = (oldState, newState) => {
1034
1051
  };
1035
1052
 
1036
1053
  const isEqual$3 = (oldState, newState) => {
1037
- return oldState.filteredItems === newState.filteredItems;
1054
+ return oldState.filteredItems === newState.filteredItems && oldState.deltaY === newState.deltaY;
1038
1055
  };
1039
1056
 
1040
1057
  const isEqual$2 = (oldState, newState) => {
@@ -1117,7 +1134,7 @@ const P = 50;
1117
1134
  const Ul = 60;
1118
1135
  const Select$1 = 63;
1119
1136
  const Option = 64;
1120
- const Label = 66;
1137
+ const Label$1 = 66;
1121
1138
  const VirtualDomElements = {
1122
1139
  __proto__: null,
1123
1140
  Aside,
@@ -1126,7 +1143,7 @@ const VirtualDomElements = {
1126
1143
  H1,
1127
1144
  H3,
1128
1145
  Input,
1129
- Label,
1146
+ Label: Label$1,
1130
1147
  Option,
1131
1148
  P,
1132
1149
  Select: Select$1,
@@ -1375,6 +1392,88 @@ const handleSettingSelect = (state, name, value, source = User) => {
1375
1392
  return handleSettingUpdate(state, name, value, source);
1376
1393
  };
1377
1394
 
1395
+ const clamp = (value, min, max) => {
1396
+ if (Number.isNaN(value)) {
1397
+ return min;
1398
+ }
1399
+ if (max < min) {
1400
+ return min;
1401
+ }
1402
+ if (value < min) {
1403
+ return min;
1404
+ }
1405
+ if (value > max) {
1406
+ return max;
1407
+ }
1408
+ return value;
1409
+ };
1410
+
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
+ const handleWheel = (state, eventDeltaY, inputSource = User) => {
1439
+ const {
1440
+ deltaY: deltaY,
1441
+ filteredItems,
1442
+ height,
1443
+ itemHeight = 1
1444
+ } = state;
1445
+ const itemCount = filteredItems.length;
1446
+ const stepLimit = itemCount === 0 ? 10 : Number.POSITIVE_INFINITY;
1447
+ const limitedEventDelta = Math.max(-stepLimit, Math.min(stepLimit, eventDeltaY));
1448
+ const total = deltaY + limitedEventDelta;
1449
+ const max = itemCount === 0 ? Number.POSITIVE_INFINITY : Math.max(0, itemCount * itemHeight);
1450
+ const clampedDeltaY = clamp(total, 0, max);
1451
+ const scrollOffset = clampedDeltaY;
1452
+ const {
1453
+ visibleItems,
1454
+ minLineY,
1455
+ maxLineY
1456
+ } = computeVisibleItems(filteredItems, height, scrollOffset, itemHeight);
1457
+ const {
1458
+ scrollBarMinHeight
1459
+ } = state;
1460
+ const {
1461
+ thumbHeight,
1462
+ thumbTop
1463
+ } = computeScrollBar(height, filteredItems.length, itemHeight, scrollOffset, scrollBarMinHeight);
1464
+ return {
1465
+ ...state,
1466
+ deltaY: clampedDeltaY,
1467
+ scrollOffset,
1468
+ visibleItems,
1469
+ minLineY,
1470
+ maxLineY,
1471
+ inputSource,
1472
+ scrollBarThumbHeight: thumbHeight,
1473
+ scrollBarThumbTop: thumbTop
1474
+ };
1475
+ };
1476
+
1378
1477
  const initialize = async () => {
1379
1478
  // TODO
1380
1479
  };
@@ -1475,7 +1574,7 @@ const sendMessagePortToEditorWorker = async (port, rpcId) => {
1475
1574
  await invokeAndTransfer$3('SendMessagePortToExtensionHostWorker.sendMessagePortToEditorWorker', port, command, rpcId);
1476
1575
  };
1477
1576
  const sendMessagePortToErrorWorker = async (port, rpcId) => {
1478
- const command = 'HandleMessagePort.handleMessagePort';
1577
+ const command = 'Errors.handleMessagePort';
1479
1578
  // @ts-ignore
1480
1579
  await invokeAndTransfer$3('SendMessagePortToExtensionHostWorker.sendMessagePortToErrorWorker', port, command, rpcId);
1481
1580
  };
@@ -1674,6 +1773,14 @@ const getAllPreferences = async () => {
1674
1773
  // @ts-ignore
1675
1774
  return invoke$3('Preferences.getAll');
1676
1775
  };
1776
+ const showSaveFilePicker = async () => {
1777
+ // @ts-ignore
1778
+ return invoke$3('FilePicker.showSaveFilePicker');
1779
+ };
1780
+ const getLogsDir = async () => {
1781
+ // @ts-ignore
1782
+ return invoke$3('PlatformPaths.getLogsDir');
1783
+ };
1677
1784
  const RendererWorker = {
1678
1785
  __proto__: null,
1679
1786
  activateByEvent,
@@ -1699,6 +1806,7 @@ const RendererWorker = {
1699
1806
  getFolderSize,
1700
1807
  getIcons,
1701
1808
  getKeyBindings,
1809
+ getLogsDir,
1702
1810
  getMarkdownDom,
1703
1811
  getNodeVersion,
1704
1812
  getPreference,
@@ -1745,6 +1853,7 @@ const RendererWorker = {
1745
1853
  showContextMenu,
1746
1854
  showErrorDialog,
1747
1855
  showMessageBox,
1856
+ showSaveFilePicker,
1748
1857
  uninstallExtension,
1749
1858
  unregisterWebViewInterceptor,
1750
1859
  writeClipBoardImage,
@@ -3966,9 +4075,28 @@ const loadContent = async (state, savedState) => {
3966
4075
  const preferences = await getPreferences();
3967
4076
  const modifiedSettings = getModifiedSettings(preferences);
3968
4077
  const filteredItems = getFilteredItems(items, newTabs, searchValue, modifiedSettings, preferences);
4078
+ const {
4079
+ height,
4080
+ itemHeight
4081
+ } = state;
4082
+ const {
4083
+ visibleItems,
4084
+ minLineY,
4085
+ maxLineY
4086
+ } = computeVisibleItems(filteredItems, height, scrollOffset, itemHeight);
4087
+ const {
4088
+ scrollBarMinHeight
4089
+ } = state;
4090
+ const {
4091
+ thumbHeight,
4092
+ thumbTop
4093
+ } = computeScrollBar(height, filteredItems.length, itemHeight, scrollOffset, scrollBarMinHeight);
3969
4094
  return {
3970
4095
  ...state,
3971
4096
  filteredItems,
4097
+ visibleItems,
4098
+ minLineY,
4099
+ maxLineY,
3972
4100
  inputSource: Script,
3973
4101
  items,
3974
4102
  modifiedSettings,
@@ -3977,7 +4105,9 @@ const loadContent = async (state, savedState) => {
3977
4105
  searchValue,
3978
4106
  tabs: newTabs,
3979
4107
  history,
3980
- historyIndex
4108
+ historyIndex,
4109
+ scrollBarThumbHeight: thumbHeight,
4110
+ scrollBarThumbTop: thumbTop
3981
4111
  };
3982
4112
  };
3983
4113
 
@@ -4002,6 +4132,7 @@ const CheckBox = 'CheckBox';
4002
4132
  const ErrorMessage = 'ErrorMessage';
4003
4133
  const InputBox = 'InputBox';
4004
4134
  const InputBoxError = 'InputBoxError';
4135
+ const Label = 'Label';
4005
4136
  const MaskIcon = 'MaskIcon';
4006
4137
  const MaskIconClearAll = 'MaskIconClearAll';
4007
4138
  const ModifiedIndicator = 'ModifiedIndicator';
@@ -4014,6 +4145,7 @@ const SettingsHeader = 'SettingsHeader';
4014
4145
  const SettingsInputWrapper = 'SettingsInputWrapper';
4015
4146
  const SettingsItem = 'SettingsItem';
4016
4147
  const SettingsItemCheckBox = 'SettingsItemCheckBox';
4148
+ const SettingsItemHeading = 'SettingsItemHeading';
4017
4149
  const SettingsItems = 'SettingsItems';
4018
4150
  const SettingsMain = 'SettingsMain';
4019
4151
  const SettingsNoResults = 'SettingsNoResults';
@@ -4042,6 +4174,7 @@ const HandleInput = 'handleInput';
4042
4174
  const HandleSettingInput = 'handleSettingInput';
4043
4175
  const HandleSettingChecked = 'handleSettingChecked';
4044
4176
  const HandleScroll = 'handleScroll';
4177
+ const HandleWheel = 'handleWheel';
4045
4178
  const HandleSettingSelect = 'handleSettingSelect';
4046
4179
  const HandleInputFocus = 'handleInputFocus';
4047
4180
 
@@ -4077,6 +4210,10 @@ const getSettingsInputDom = () => {
4077
4210
  type: VirtualDomElements.Input,
4078
4211
  className: mergeClassNames(InputBox, SettingsSearchInput, 'MultilineInputBox'),
4079
4212
  placeholder,
4213
+ autocomplete: 'off',
4214
+ autocorrect: 'off',
4215
+ autocapitalize: 'off',
4216
+ spellcheck: false,
4080
4217
  childCount: 0,
4081
4218
  name: SettingsSearch,
4082
4219
  onInput: HandleInput,
@@ -4115,6 +4252,24 @@ const getInputId = id => {
4115
4252
  return id.replaceAll('.', '\\.');
4116
4253
  };
4117
4254
 
4255
+ const parent = {
4256
+ type: VirtualDomElements.H3,
4257
+ className: SettingsItemHeading,
4258
+ childCount: 1
4259
+ };
4260
+ const getItemHeadingDom = heading => {
4261
+ return [parent, text(heading)];
4262
+ };
4263
+
4264
+ const getItemLabelDom = (domId, label) => {
4265
+ return [{
4266
+ type: VirtualDomElements.Label,
4267
+ htmlFor: domId,
4268
+ childCount: 1,
4269
+ className: Label
4270
+ }, text(label)];
4271
+ };
4272
+
4118
4273
  const getItemCheckBoxVirtualDom = item => {
4119
4274
  const {
4120
4275
  heading,
@@ -4130,13 +4285,10 @@ const getItemCheckBoxVirtualDom = item => {
4130
4285
  return [{
4131
4286
  type: VirtualDomElements.Div,
4132
4287
  className: SettingsItem,
4133
- childCount: 3 + errorChildCount,
4288
+ childCount: 2 + errorChildCount,
4134
4289
  role: AriaRoles.Group,
4135
4290
  'data-modified': modified
4136
- }, {
4137
- type: VirtualDomElements.H3,
4138
- childCount: 1
4139
- }, text(heading), {
4291
+ }, ...getItemHeadingDom(heading), {
4140
4292
  type: VirtualDomElements.Div,
4141
4293
  className: SettingsItemCheckBox,
4142
4294
  childCount: 2
@@ -4148,28 +4300,7 @@ const getItemCheckBoxVirtualDom = item => {
4148
4300
  inputType: 'checkbox',
4149
4301
  name: id,
4150
4302
  onChange: HandleSettingChecked
4151
- }, {
4152
- type: VirtualDomElements.Label,
4153
- childCount: 1,
4154
- htmlFor: domId
4155
- }, text(description), ...getErrorMessageDom(errorMessage)];
4156
- };
4157
-
4158
- const parent = {
4159
- type: VirtualDomElements.H3,
4160
- childCount: 1
4161
- };
4162
- const getItemHeadingDom = heading => {
4163
- return [parent, text(heading)];
4164
- };
4165
-
4166
- const getItemLabelDom = (domId, label) => {
4167
- return [{
4168
- type: VirtualDomElements.Label,
4169
- htmlFor: domId,
4170
- childCount: 1,
4171
- className: 'Label'
4172
- }, text(label)];
4303
+ }, ...getItemLabelDom(domId, description), ...getErrorMessageDom(errorMessage)];
4173
4304
  };
4174
4305
 
4175
4306
  const getItemColorVirtualDom = item => {
@@ -4306,6 +4437,7 @@ const getItemStringVirtualDom = item => {
4306
4437
  hasError,
4307
4438
  errorMessage
4308
4439
  } = item;
4440
+ const domId = getInputId(id);
4309
4441
  const inputClassName = hasError ? `${InputBox} ${InputBoxError}` : InputBox;
4310
4442
  const errorChildCount = hasError ? 1 : 0;
4311
4443
  return [{
@@ -4313,18 +4445,13 @@ const getItemStringVirtualDom = item => {
4313
4445
  className: SettingsItem,
4314
4446
  childCount: 3 + errorChildCount,
4315
4447
  role: AriaRoles.Group
4316
- }, {
4317
- type: VirtualDomElements.H3,
4318
- childCount: 1
4319
- }, text(heading), {
4320
- type: VirtualDomElements.P,
4321
- childCount: 1
4322
- }, text(description), {
4448
+ }, ...getItemHeadingDom(heading), ...getItemLabelDom(domId, description), {
4323
4449
  type: VirtualDomElements.Input,
4324
4450
  className: inputClassName,
4325
4451
  inputType: 'text',
4326
4452
  placeholder: stringValue(),
4327
4453
  childCount: 0,
4454
+ id: domId,
4328
4455
  name: id,
4329
4456
  onInput: HandleSettingInput
4330
4457
  }, ...getErrorMessageDom(errorMessage)];
@@ -4369,26 +4496,28 @@ const getItemUrlVirtualDom = item => {
4369
4496
  }, ...getErrorMessageDom(errorMessage)];
4370
4497
  };
4371
4498
 
4372
- const getItemVirtualDom = item => {
4373
- if (item.type === Number$1) {
4374
- return getItemNumberVirtualDom(item);
4375
- }
4376
- if (item.type === Boolean$1) {
4377
- return getItemCheckBoxVirtualDom(item);
4378
- }
4379
- if (item.type === String) {
4380
- return getItemStringVirtualDom(item);
4381
- }
4382
- if (item.type === Enum) {
4383
- return getItemSelectVirtualDom(item);
4384
- }
4385
- if (item.type === Color) {
4386
- return getItemColorVirtualDom(item);
4387
- }
4388
- if (item.type === Url) {
4389
- return getItemUrlVirtualDom(item);
4499
+ const getItemRender = type => {
4500
+ switch (type) {
4501
+ case Number$1:
4502
+ return getItemNumberVirtualDom;
4503
+ case Boolean$1:
4504
+ return getItemCheckBoxVirtualDom;
4505
+ case String:
4506
+ return getItemStringVirtualDom;
4507
+ case Enum:
4508
+ return getItemSelectVirtualDom;
4509
+ case Color:
4510
+ return getItemColorVirtualDom;
4511
+ case Url:
4512
+ return getItemUrlVirtualDom;
4513
+ default:
4514
+ return getItemUnknownVirtualDom;
4390
4515
  }
4391
- return getItemUnknownVirtualDom();
4516
+ };
4517
+
4518
+ const getItemVirtualDom = item => {
4519
+ const fn = getItemRender(item.type);
4520
+ return fn(item);
4392
4521
  };
4393
4522
 
4394
4523
  const getSettingsNoResultsDom = searchValue => {
@@ -4590,6 +4719,10 @@ const renderEventListeners = () => {
4590
4719
  name: HandleScroll,
4591
4720
  params: ['handleScroll', 'event.target.scrollTop'],
4592
4721
  passive: true
4722
+ }, {
4723
+ name: HandleWheel,
4724
+ params: ['handleWheel', 'event.deltaY'],
4725
+ passive: true
4593
4726
  }, {
4594
4727
  name: HandleSettingSelect,
4595
4728
  params: ['handleSettingSelect', 'event.target.name', 'event.target.value']
@@ -4682,6 +4815,7 @@ const commandMap = {
4682
4815
  'Settings.handleInputBlur': wrapCommand(handleInputBlur),
4683
4816
  'Settings.handleInput': wrapCommand(handleInput),
4684
4817
  'Settings.handleScroll': wrapCommand(handleScroll),
4818
+ 'Settings.handleWheel': wrapCommand(handleWheel),
4685
4819
  'Settings.handleSettingChecked': wrapCommand(handleSettingChecked),
4686
4820
  'Settings.handleSettingInput': wrapCommand(handleSettingInput),
4687
4821
  'Settings.handleInputFocus': wrapCommand(handleInputFocus),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/settings-view",
3
- "version": "1.20.0",
3
+ "version": "1.21.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",