@lvce-editor/settings-view 1.12.0 → 1.14.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.
@@ -991,19 +991,24 @@ const create$1 = (id, uri, x, y, width, height) => {
991
991
  scrollOffset: 0,
992
992
  filteredItemsCount: 0,
993
993
  history: [],
994
+ historyIndex: -1,
994
995
  modifiedSettings: {}
995
996
  };
996
997
  set$1(id, state, state);
997
998
  };
998
999
 
999
- const isEqual$3 = (oldState, newState) => {
1000
+ const isEqual$4 = (oldState, newState) => {
1000
1001
  return oldState.focus === newState.focus;
1001
1002
  };
1002
1003
 
1003
- const isEqual$2 = (oldState, newState) => {
1004
+ const isEqual$3 = (oldState, newState) => {
1004
1005
  return oldState.filteredItems === newState.filteredItems;
1005
1006
  };
1006
1007
 
1008
+ const isEqual$2 = (oldState, newState) => {
1009
+ return newState.inputSource === User || oldState.scrollOffset === newState.scrollOffset;
1010
+ };
1011
+
1007
1012
  const isEqual$1 = (oldState, newState) => {
1008
1013
  return oldState.filteredItems === newState.filteredItems;
1009
1014
  };
@@ -1012,13 +1017,14 @@ const RenderItems = 1;
1012
1017
  const RenderFocus = 2;
1013
1018
  const RenderValue = 3;
1014
1019
  const RenderSettingValues = 10;
1020
+ const RenderScrollOffset = 11;
1015
1021
 
1016
1022
  const isEqual = (oldState, newState) => {
1017
1023
  return newState.inputSource === User || oldState.searchValue === newState.searchValue;
1018
1024
  };
1019
1025
 
1020
- const modules = [isEqual$3, isEqual$2, isEqual, isEqual$1];
1021
- const numbers = [RenderFocus, RenderItems, RenderValue, RenderSettingValues];
1026
+ const modules = [isEqual$4, isEqual$3, isEqual, isEqual$1, isEqual$2];
1027
+ const numbers = [RenderFocus, RenderItems, RenderValue, RenderSettingValues, RenderScrollOffset];
1022
1028
 
1023
1029
  const diff = (oldState, newState) => {
1024
1030
  const diffResult = [];
@@ -1080,43 +1086,104 @@ const handleClickTab = (state, name) => {
1080
1086
  };
1081
1087
  };
1082
1088
 
1089
+ const addToHistory = (history, value) => {
1090
+ let newHistory = history;
1091
+ let newHistoryIndex = -1;
1092
+ if (value && value.trim() && !history.includes(value)) {
1093
+ newHistory = [...history, value];
1094
+ newHistoryIndex = newHistory.length - 1;
1095
+ } else if (value && value.trim()) {
1096
+ // If value already exists in history, find its index
1097
+ newHistoryIndex = history.indexOf(value);
1098
+ }
1099
+ return {
1100
+ newHistory,
1101
+ newHistoryIndex
1102
+ };
1103
+ };
1104
+
1083
1105
  const handleInput = (state, value, inputSource = User) => {
1084
1106
  const {
1085
1107
  items,
1086
1108
  tabs,
1087
- preferences
1109
+ preferences,
1110
+ history
1088
1111
  } = state;
1089
1112
  const filteredItems = getFilteredItems(items, tabs, value, preferences);
1113
+ const {
1114
+ newHistory,
1115
+ newHistoryIndex
1116
+ } = addToHistory(history, value);
1090
1117
  return {
1091
1118
  ...state,
1092
1119
  searchValue: value,
1093
1120
  filteredItems,
1121
+ history: newHistory,
1122
+ historyIndex: newHistoryIndex,
1094
1123
  inputSource
1095
1124
  };
1096
1125
  };
1097
1126
 
1098
- const handleSettingChecked = (state, name, value) => {
1099
- // TODO update value
1127
+ const handleScroll = (state, scrollTop, inputSource = User) => {
1100
1128
  return {
1101
- ...state
1129
+ ...state,
1130
+ scrollOffset: scrollTop,
1131
+ inputSource
1102
1132
  };
1103
1133
  };
1104
1134
 
1105
- const handleSettingInput = (state, name, value, inputSource = User) => {
1106
- // TODO update value
1135
+ const getNewFilteredItems = (oldModifiedSetings, newModifiedSettings, items, tabs, searchValue, oldFilteredItems) => {
1136
+ if (oldModifiedSetings === newModifiedSettings) {
1137
+ return oldFilteredItems;
1138
+ }
1139
+ return getFilteredItems(items, tabs, searchValue, newModifiedSettings);
1140
+ };
1141
+
1142
+ const getNewModifiedSettings = (modifiedSettings, name) => {
1143
+ if (name in modifiedSettings) {
1144
+ return modifiedSettings;
1145
+ }
1107
1146
  return {
1108
- ...state,
1109
- inputSource
1147
+ ...modifiedSettings,
1148
+ [name]: true
1110
1149
  };
1111
1150
  };
1112
1151
 
1113
- const handleSettingSelect = (state, name, value) => {
1114
- // TODO update value
1152
+ const handleSettingUpdate = (state, name, value, inputSource) => {
1153
+ const {
1154
+ modifiedSettings,
1155
+ items,
1156
+ tabs,
1157
+ searchValue,
1158
+ preferences,
1159
+ filteredItems
1160
+ } = state;
1161
+ const newModifiedSettings = getNewModifiedSettings(modifiedSettings, name);
1162
+ const newPreferences = {
1163
+ ...preferences,
1164
+ [name]: value
1165
+ };
1166
+ const newFilteredItems = getNewFilteredItems(modifiedSettings, newModifiedSettings, items, tabs, searchValue, filteredItems);
1115
1167
  return {
1116
- ...state
1168
+ ...state,
1169
+ inputSource,
1170
+ filteredItems: newFilteredItems,
1171
+ preferences: newPreferences
1117
1172
  };
1118
1173
  };
1119
1174
 
1175
+ const handleSettingChecked = (state, name, value, source = User) => {
1176
+ return handleSettingUpdate(state, name, value, source);
1177
+ };
1178
+
1179
+ const handleSettingInput = (state, name, value, inputSource = User) => {
1180
+ return handleSettingUpdate(state, name, value, inputSource);
1181
+ };
1182
+
1183
+ const handleSettingSelect = (state, name, value, source = User) => {
1184
+ return handleSettingUpdate(state, name, value, source);
1185
+ };
1186
+
1120
1187
  const initialize = async () => {
1121
1188
  // TODO
1122
1189
  };
@@ -3203,6 +3270,12 @@ const getSavedTabId = savedState => {
3203
3270
  }
3204
3271
  return '';
3205
3272
  };
3273
+ const getSavedScrollOffset = savedState => {
3274
+ if (savedState && typeof savedState === 'object' && 'scrollOffset' in savedState && typeof savedState.scrollOffset === 'number') {
3275
+ return savedState.scrollOffset;
3276
+ }
3277
+ return 0;
3278
+ };
3206
3279
  const restoreState = savedState => {
3207
3280
  if (!savedState) {
3208
3281
  return {
@@ -3210,7 +3283,8 @@ const restoreState = savedState => {
3210
3283
  minLineY: 0,
3211
3284
  deltaY: 0,
3212
3285
  tabId: '',
3213
- searchValue: ''
3286
+ searchValue: '',
3287
+ scrollOffset: 0
3214
3288
  };
3215
3289
  }
3216
3290
  const root = getSavedWorkspacePath(savedState);
@@ -3218,12 +3292,14 @@ const restoreState = savedState => {
3218
3292
  const deltaY = getSavedDeltaY(savedState);
3219
3293
  const tabId = getSavedTabId(savedState);
3220
3294
  const searchValue = getSavedSearchValue(savedState);
3295
+ const scrollOffset = getSavedScrollOffset(savedState);
3221
3296
  return {
3222
3297
  root,
3223
3298
  minLineY,
3224
3299
  deltaY,
3225
3300
  tabId,
3226
- searchValue
3301
+ searchValue,
3302
+ scrollOffset
3227
3303
  };
3228
3304
  };
3229
3305
 
@@ -3237,7 +3313,8 @@ const getModifiedSettings = preferences => {
3237
3313
  const loadContent = async (state, savedState) => {
3238
3314
  const {
3239
3315
  searchValue,
3240
- tabId
3316
+ tabId,
3317
+ scrollOffset
3241
3318
  } = restoreState(savedState);
3242
3319
  const tabs = getTabs();
3243
3320
  const newTabs = getUpdatedTabs(tabs, tabId);
@@ -3252,6 +3329,7 @@ const loadContent = async (state, savedState) => {
3252
3329
  items,
3253
3330
  modifiedSettings,
3254
3331
  preferences,
3332
+ scrollOffset,
3255
3333
  searchValue,
3256
3334
  tabs: newTabs
3257
3335
  };
@@ -3306,31 +3384,31 @@ const text = data => {
3306
3384
  const {
3307
3385
  Viewlet
3308
3386
  } = ClassNames;
3309
- const Settings = 'Settings';
3310
- const SettingsInputWrapper = 'SettingsInputWrapper';
3311
- const InputBox = 'InputBox';
3312
- const SettingsSearchInput = 'SettingsSearchInput';
3387
+ const Badge = 'Badge';
3313
3388
  const Button = 'Button';
3314
- const InputButton = 'InputButton';
3315
- const SearchFieldButton = 'SearchFieldButton';
3389
+ const CheckBox = 'CheckBox';
3316
3390
  const Disabled = 'Disabled';
3391
+ const InputBox = 'InputBox';
3392
+ const InputButton = 'InputButton';
3317
3393
  const MaskIcon = 'MaskIcon';
3318
3394
  const MaskIconClearAll = 'MaskIconClearAll';
3319
- const SettingsItem = 'SettingsItem';
3320
- const SettingsItemCheckBox = 'SettingsItemCheckBox';
3321
- const CheckBox = 'CheckBox';
3395
+ const SearchFieldButton = 'SearchFieldButton';
3322
3396
  const Select = 'Select';
3323
- const SettingsItems = 'SettingsItems';
3324
- const SettingsNoResults = 'SettingsNoResults';
3325
- const SettingsMain = 'SettingsMain';
3397
+ const Settings = 'Settings';
3326
3398
  const SettingsContent = 'SettingsContent';
3327
3399
  const SettingsContentHeading = 'SettingsContentHeading';
3328
3400
  const SettingsHeader = 'SettingsHeader';
3401
+ const SettingsInputWrapper = 'SettingsInputWrapper';
3402
+ const SettingsItem = 'SettingsItem';
3403
+ const SettingsItemCheckBox = 'SettingsItemCheckBox';
3404
+ const SettingsItems = 'SettingsItems';
3405
+ const SettingsMain = 'SettingsMain';
3406
+ const SettingsNoResults = 'SettingsNoResults';
3407
+ const SettingsSearchInput = 'SettingsSearchInput';
3329
3408
  const SettingsSideBar = 'SettingsSideBar';
3330
3409
  const SettingsTabs = 'SettingsTabs';
3331
3410
  const Tab = 'Tab';
3332
3411
  const TabSelected = 'TabSelected';
3333
- const Badge = 'Badge';
3334
3412
 
3335
3413
  const getSettingsInputBadgeDom = (filteredSettingsCount, hasSearchValue) => {
3336
3414
  if (!hasSearchValue) {
@@ -3350,6 +3428,7 @@ const HandleClickTab = 'handleClickTab';
3350
3428
  const HandleInput = 'handleInput';
3351
3429
  const HandleSettingInput = 'handleSettingInput';
3352
3430
  const HandleSettingChecked = 'handleSettingChecked';
3431
+ const HandleScroll = 'handleScroll';
3353
3432
  const HandleSettingSelect = 'handleSettingSelect';
3354
3433
 
3355
3434
  const getButtonClassName = hasSearchValue => {
@@ -3411,14 +3490,17 @@ const getItemCheckBoxVirtualDom = item => {
3411
3490
  const {
3412
3491
  heading,
3413
3492
  description,
3414
- id
3493
+ id,
3494
+ modified
3415
3495
  } = item;
3496
+ const isModified = modified || false;
3416
3497
  const domId = getInputId(id);
3417
3498
  return [{
3418
3499
  type: VirtualDomElements.Div,
3419
3500
  className: SettingsItem,
3420
3501
  childCount: 3,
3421
- role: 'group'
3502
+ role: 'group',
3503
+ 'data-modified': isModified
3422
3504
  }, {
3423
3505
  type: VirtualDomElements.H3,
3424
3506
  childCount: 1
@@ -3441,27 +3523,38 @@ const getItemCheckBoxVirtualDom = item => {
3441
3523
  }, text(description)];
3442
3524
  };
3443
3525
 
3526
+ const getItemHeadingDom = heading => {
3527
+ return [{
3528
+ type: VirtualDomElements.H3,
3529
+ childCount: 1
3530
+ }, text(heading)];
3531
+ };
3532
+
3533
+ const getItemLabelDom = (domId, label) => {
3534
+ return [{
3535
+ type: VirtualDomElements.Label,
3536
+ htmlFor: domId,
3537
+ childCount: 1,
3538
+ className: 'Label'
3539
+ }, text(label)];
3540
+ };
3541
+
3444
3542
  const getItemNumberVirtualDom = item => {
3445
3543
  const {
3446
3544
  heading,
3447
3545
  description,
3448
- id
3546
+ id,
3547
+ modified
3449
3548
  } = item;
3450
3549
  const domId = getInputId(id);
3550
+ const isModified = modified || false;
3451
3551
  return [{
3452
3552
  type: VirtualDomElements.Div,
3453
3553
  className: SettingsItem,
3454
3554
  childCount: 3,
3455
- role: 'group'
3456
- }, {
3457
- type: VirtualDomElements.H3,
3458
- childCount: 1
3459
- }, text(heading), {
3460
- type: VirtualDomElements.Label,
3461
- htmlFor: domId,
3462
- childCount: 1,
3463
- className: 'Label'
3464
- }, text(description), {
3555
+ role: 'group',
3556
+ 'data-modified': isModified
3557
+ }, ...getItemHeadingDom(heading), ...getItemLabelDom(domId, description), {
3465
3558
  type: VirtualDomElements.Input,
3466
3559
  className: InputBox,
3467
3560
  inputType: 'number',
@@ -3492,22 +3585,18 @@ const getItemSelectVirtualDom = item => {
3492
3585
  id
3493
3586
  } = item;
3494
3587
  const options = item.options || [];
3588
+ const domId = getInputId(id);
3495
3589
  return [{
3496
3590
  type: VirtualDomElements.Div,
3497
3591
  className: SettingsItem,
3498
3592
  childCount: 3,
3499
3593
  role: 'group'
3500
- }, {
3501
- type: VirtualDomElements.H3,
3502
- childCount: 1
3503
- }, text(heading), {
3504
- type: VirtualDomElements.P,
3505
- childCount: 1
3506
- }, text(description), {
3594
+ }, ...getItemHeadingDom(heading), ...getItemLabelDom(domId, description), {
3507
3595
  type: VirtualDomElements.Select,
3508
3596
  className: Select,
3509
3597
  childCount: options.length,
3510
- name: id
3598
+ name: id,
3599
+ onChange: HandleSettingSelect
3511
3600
  }, ...options.flatMap(getOptionDom)];
3512
3601
  };
3513
3602
 
@@ -3593,7 +3682,8 @@ const getSettingsContentDom = (items, tabs, searchValue) => {
3593
3682
  return [{
3594
3683
  type: VirtualDomElements.Div,
3595
3684
  className: SettingsContent,
3596
- childCount: 2
3685
+ childCount: 2,
3686
+ onScroll: HandleScroll
3597
3687
  }, {
3598
3688
  type: VirtualDomElements.H1,
3599
3689
  className: SettingsContentHeading,
@@ -3664,6 +3754,16 @@ const renderItems = (oldState, newState) => {
3664
3754
  return ['Viewlet.setDom2', newState.id, dom];
3665
3755
  };
3666
3756
 
3757
+ const renderScrollOffset = (oldState, newState) => {
3758
+ const {
3759
+ id,
3760
+ scrollOffset
3761
+ } = newState;
3762
+ const selector = '.SettingsContent';
3763
+ const property = 'scrollTop';
3764
+ return ['Viewlet.setProperty', id, selector, property, scrollOffset];
3765
+ };
3766
+
3667
3767
  const renderSettingValues = (oldState, newState) => {
3668
3768
  const {
3669
3769
  filteredItems,
@@ -3694,6 +3794,8 @@ const getRenderer = diffType => {
3694
3794
  return renderValue;
3695
3795
  case RenderSettingValues:
3696
3796
  return renderSettingValues;
3797
+ case RenderScrollOffset:
3798
+ return renderScrollOffset;
3697
3799
  default:
3698
3800
  throw new Error('unknown renderer');
3699
3801
  }
@@ -3738,6 +3840,10 @@ const renderEventListeners = () => {
3738
3840
  }, {
3739
3841
  name: HandleSettingChecked,
3740
3842
  params: ['handleSettingChecked', 'event.target.name', 'event.target.value']
3843
+ }, {
3844
+ name: HandleScroll,
3845
+ params: ['handleScroll', 'event.target.scrollTop'],
3846
+ passive: true
3741
3847
  }, {
3742
3848
  name: HandleSettingSelect,
3743
3849
  params: ['handleSettingSelect', 'event.target.name', 'event.target.value']
@@ -3747,7 +3853,8 @@ const renderEventListeners = () => {
3747
3853
  const saveState = state => {
3748
3854
  const {
3749
3855
  tabs,
3750
- searchValue
3856
+ searchValue,
3857
+ scrollOffset
3751
3858
  } = state;
3752
3859
  const selectedTab = getSelectedTabId(tabs);
3753
3860
  return {
@@ -3757,15 +3864,69 @@ const saveState = state => {
3757
3864
  maxLineY: 0,
3758
3865
  deltaY: 0,
3759
3866
  searchValue,
3760
- selectedTab
3867
+ selectedTab,
3868
+ scrollOffset
3869
+ };
3870
+ };
3871
+
3872
+ const useNextSearchValue = state => {
3873
+ const {
3874
+ history,
3875
+ historyIndex,
3876
+ items,
3877
+ tabs,
3878
+ preferences
3879
+ } = state;
3880
+ if (history.length === 0 || historyIndex >= history.length - 1) {
3881
+ return state;
3882
+ }
3883
+ const newHistoryIndex = historyIndex + 1;
3884
+ const newSearchValue = history[newHistoryIndex];
3885
+ const filteredItems = getFilteredItems(items, tabs, newSearchValue, preferences);
3886
+ return {
3887
+ ...state,
3888
+ searchValue: newSearchValue,
3889
+ historyIndex: newHistoryIndex,
3890
+ filteredItems,
3891
+ inputSource: Script
3892
+ };
3893
+ };
3894
+
3895
+ const usePreviousSearchValue = state => {
3896
+ const {
3897
+ history,
3898
+ historyIndex,
3899
+ items,
3900
+ tabs,
3901
+ preferences
3902
+ } = state;
3903
+ if (history.length === 0 || historyIndex <= 0) {
3904
+ return state;
3905
+ }
3906
+ const newHistoryIndex = historyIndex - 1;
3907
+ const newSearchValue = history[newHistoryIndex];
3908
+ const filteredItems = getFilteredItems(items, tabs, newSearchValue, preferences);
3909
+ return {
3910
+ ...state,
3911
+ searchValue: newSearchValue,
3912
+ historyIndex: newHistoryIndex,
3913
+ filteredItems,
3914
+ inputSource: Script
3761
3915
  };
3762
3916
  };
3763
3917
 
3764
3918
  const commandMap = {
3765
3919
  'Initialize.initialize': initialize,
3920
+ 'Settings.clear': wrapCommand(clear$1),
3766
3921
  'Settings.create': create$1,
3767
3922
  'Settings.diff2': diff2,
3768
3923
  'Settings.getCommandIds': getCommandIds,
3924
+ 'Settings.handleClickTab': wrapCommand(handleClickTab),
3925
+ 'Settings.handleInput': wrapCommand(handleInput),
3926
+ 'Settings.handleScroll': wrapCommand(handleScroll),
3927
+ 'Settings.handleSettingChecked': wrapCommand(handleSettingChecked),
3928
+ 'Settings.handleSettingInput': wrapCommand(handleSettingInput),
3929
+ 'Settings.handleSettingSelect': wrapCommand(handleSettingSelect),
3769
3930
  'Settings.loadContent': wrapCommand(loadContent),
3770
3931
  'Settings.render2': render2,
3771
3932
  'Settings.renderActions': renderActions,
@@ -3773,12 +3934,8 @@ const commandMap = {
3773
3934
  'Settings.restoreState': restoreState,
3774
3935
  'Settings.saveState': wrapGetter(saveState),
3775
3936
  'Settings.terminate': terminate,
3776
- 'Settings.handleClickTab': wrapCommand(handleClickTab),
3777
- 'Settings.clear': wrapCommand(clear$1),
3778
- 'Settings.handleInput': wrapCommand(handleInput),
3779
- 'Settings.handleSettingInput': wrapCommand(handleSettingInput),
3780
- 'Settings.handleSettingChecked': wrapCommand(handleSettingChecked),
3781
- 'Settings.handleSettingSelect': wrapCommand(handleSettingSelect)
3937
+ 'Settings.useNextSearchValue': wrapCommand(useNextSearchValue),
3938
+ 'Settings.usePreviousSearchValue': wrapCommand(usePreviousSearchValue)
3782
3939
  };
3783
3940
 
3784
3941
  const rpcs = Object.create(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/settings-view",
3
- "version": "1.12.0",
3
+ "version": "1.14.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",