@visactor/vtable-plugins 1.22.7-alpha.7 → 1.22.7-alpha.9

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.
@@ -10117,10 +10117,26 @@ ${recordsStr}
10117
10117
  const newFilter = new Map(state.filters);
10118
10118
  switch (type) {
10119
10119
  case exports.FilterActionType.ADD_FILTER:
10120
- newFilter.set(payload.field, payload);
10120
+ if (payload.shouldKeepUnrelatedState) {
10121
+ newFilter.set(payload.field, { ...newFilter.get(payload.field), ...payload });
10122
+ }
10123
+ else {
10124
+ newFilter.set(payload.field, payload);
10125
+ }
10121
10126
  break;
10122
10127
  case exports.FilterActionType.REMOVE_FILTER:
10123
- newFilter.delete(payload.field);
10128
+ if (payload.shouldKeepUnrelatedState && payload.type === 'byValue') {
10129
+ delete newFilter.get(payload.field).values;
10130
+ newFilter.set(payload.field, { ...newFilter.get(payload.field), enable: false });
10131
+ }
10132
+ else if (payload.shouldKeepUnrelatedState && payload.type === 'byCondition') {
10133
+ delete newFilter.get(payload.field).condition;
10134
+ delete newFilter.get(payload.field).operator;
10135
+ newFilter.set(payload.field, { ...newFilter.get(payload.field), enable: false });
10136
+ }
10137
+ else {
10138
+ newFilter.delete(payload.field);
10139
+ }
10124
10140
  break;
10125
10141
  case exports.FilterActionType.UPDATE_FILTER:
10126
10142
  newFilter.set(payload.field, { ...newFilter.get(payload.field), ...payload });
@@ -10381,42 +10397,6 @@ ${recordsStr}
10381
10397
  this.candidateKeys.set(fieldId, countMap);
10382
10398
  this.toUnformattedCache.set(fieldId, toUnformatted);
10383
10399
  }
10384
- syncRulesAndCandidateKeys() {
10385
- const currentRecords = this.table.internalProps.dataSource.records;
10386
- const filteredFields = this.filterStateManager.getActiveFilterFields();
10387
- currentRecords.forEach(record => {
10388
- filteredFields.forEach(candidateField => {
10389
- const formatFn = this.getFormatFnCache(candidateField);
10390
- if (isValid$2(record)) {
10391
- const originalValue = record[candidateField];
10392
- const formattedValue = formatFn(record);
10393
- const lastToUnformatted = this.toUnformattedCache.get(candidateField) || new Map();
10394
- if (!lastToUnformatted.has(formattedValue) &&
10395
- this.filterStateManager.getFilterState(candidateField)?.values?.length > 0) {
10396
- this.filterStateManager.getFilterState(candidateField).values.push(originalValue);
10397
- this.selectedKeys.get(candidateField).add(originalValue);
10398
- }
10399
- }
10400
- });
10401
- });
10402
- }
10403
- syncSelectedKeys() {
10404
- const currentRecords = this.table.internalProps.dataSource.records;
10405
- const filteredFields = this.filterStateManager.getActiveFilterFields();
10406
- currentRecords.forEach(record => {
10407
- filteredFields.forEach(candidateField => {
10408
- if (isValid$2(record)) {
10409
- const originalValue = record[candidateField];
10410
- if (this.filterStateManager.getFilterState(candidateField)?.type === 'byCondition') {
10411
- if (!this.selectedKeys.get(candidateField)) {
10412
- this.selectedKeys.set(candidateField, new Set());
10413
- }
10414
- this.selectedKeys.get(candidateField).add(originalValue);
10415
- }
10416
- }
10417
- });
10418
- });
10419
- }
10420
10400
  collectCandidateKeysForFilteredColumn(candidateField) {
10421
10401
  const syncFilterItemsState = this.pluginOptions?.syncFilterItemsState ?? true;
10422
10402
  const filteredFields = this.filterStateManager.getActiveFilterFields().filter(field => field !== candidateField);
@@ -10485,7 +10465,7 @@ ${recordsStr}
10485
10465
  if (isHasFilteredState && isValueFilter) {
10486
10466
  return;
10487
10467
  }
10488
- let selectedValues = new Set();
10468
+ const selectedValues = new Set();
10489
10469
  const originalValues = new Set();
10490
10470
  const originalRecords = this.table.internalProps.records;
10491
10471
  originalRecords.forEach(record => {
@@ -10501,23 +10481,41 @@ ${recordsStr}
10501
10481
  selectedValues.add(record[fieldId]);
10502
10482
  }
10503
10483
  });
10484
+ const hasFiltered = !arrayEqual(Array.from(originalValues), Array.from(selectedValues));
10485
+ if (hasFiltered) {
10486
+ this.selectedKeys.set(fieldId, selectedValues);
10487
+ this.filterStateManager.dispatch({
10488
+ type: exports.FilterActionType.ADD_FILTER,
10489
+ payload: {
10490
+ field: fieldId,
10491
+ type: 'byValue',
10492
+ values: Array.from(selectedValues),
10493
+ enable: true
10494
+ }
10495
+ });
10496
+ }
10504
10497
  }
10505
10498
  else {
10506
- const selectedFromRules = this.filterStateManager.getFilterState(fieldId)?.values || originalValues;
10507
- selectedValues = new Set(selectedFromRules);
10508
- }
10509
- this.selectedKeys.set(fieldId, selectedValues);
10510
- const hasFiltered = !arrayEqual(Array.from(originalValues), Array.from(selectedValues));
10511
- if (hasFiltered) {
10512
- this.filterStateManager.dispatch({
10513
- type: exports.FilterActionType.ADD_FILTER,
10514
- payload: {
10515
- field: fieldId,
10516
- type: 'byValue',
10517
- values: Array.from(selectedValues),
10518
- enable: true
10499
+ const selectedRules = this.filterStateManager.getFilterState(fieldId)?.values;
10500
+ if (selectedRules) {
10501
+ const hasFiltered = !arrayEqual(Array.from(originalValues), selectedRules);
10502
+ if (hasFiltered) {
10503
+ this.selectedKeys.set(fieldId, new Set(selectedRules));
10504
+ this.filterStateManager.dispatch({
10505
+ type: exports.FilterActionType.ADD_FILTER,
10506
+ payload: {
10507
+ field: fieldId,
10508
+ type: 'byValue',
10509
+ values: selectedRules,
10510
+ enable: true,
10511
+ shouldKeepUnrelatedState: true
10512
+ }
10513
+ });
10519
10514
  }
10520
- });
10515
+ }
10516
+ else {
10517
+ this.selectedKeys.set(fieldId, originalValues);
10518
+ }
10521
10519
  }
10522
10520
  }
10523
10521
  applyFilter(fieldId = this.selectedField) {
@@ -10535,14 +10533,17 @@ ${recordsStr}
10535
10533
  .filter(key => key !== null)
10536
10534
  .flat();
10537
10535
  this.selectedKeys.set(fieldId, new Set(selections));
10538
- if (selections.length >= 0 && selections.length < this.valueFilterOptionList.get(fieldId).length) {
10536
+ const syncFilterItemsState = this.pluginOptions?.syncFilterItemsState ?? true;
10537
+ if ((selections.length >= 0 && selections.length < this.valueFilterOptionList.get(fieldId).length) ||
10538
+ !syncFilterItemsState) {
10539
10539
  this.filterStateManager.dispatch({
10540
10540
  type: exports.FilterActionType.APPLY_FILTERS,
10541
10541
  payload: {
10542
10542
  field: fieldId,
10543
10543
  type: 'byValue',
10544
10544
  values: selections,
10545
- enable: true
10545
+ enable: true,
10546
+ shouldKeepUnrelatedState: !syncFilterItemsState
10546
10547
  }
10547
10548
  });
10548
10549
  }
@@ -10550,7 +10551,8 @@ ${recordsStr}
10550
10551
  this.filterStateManager.dispatch({
10551
10552
  type: exports.FilterActionType.REMOVE_FILTER,
10552
10553
  payload: {
10553
- field: fieldId
10554
+ field: fieldId,
10555
+ type: 'byValue'
10554
10556
  }
10555
10557
  });
10556
10558
  }
@@ -10786,6 +10788,7 @@ ${recordsStr}
10786
10788
  table;
10787
10789
  filterStateManager;
10788
10790
  pluginOptions;
10791
+ filterToolBarHide;
10789
10792
  styles;
10790
10793
  filterByConditionPanel;
10791
10794
  conditionContainer;
@@ -10802,13 +10805,14 @@ ${recordsStr}
10802
10805
  currentCategory = exports.FilterOperatorCategory.ALL;
10803
10806
  categories = [];
10804
10807
  operators = [];
10805
- constructor(table, filterStateManager, pluginOptions) {
10808
+ constructor(table, filterStateManager, pluginOptions, filterToolBarHide) {
10806
10809
  this.table = table;
10807
10810
  this.filterStateManager = filterStateManager;
10808
10811
  this.pluginOptions = pluginOptions;
10809
10812
  this.styles = pluginOptions.styles || {};
10810
10813
  this.categories = pluginOptions.conditionCategories;
10811
10814
  this.operators = operators;
10815
+ this.filterToolBarHide = filterToolBarHide;
10812
10816
  }
10813
10817
  setSelectedField(fieldId) {
10814
10818
  this.selectedField = fieldId;
@@ -10853,19 +10857,19 @@ ${recordsStr}
10853
10857
  loadCurrentFilterState() {
10854
10858
  const filter = this.filterStateManager.getFilterState(this.selectedField);
10855
10859
  const syncFilterItemsState = this.pluginOptions?.syncFilterItemsState ?? true;
10856
- if (filter && (filter.type === 'byCondition' || !syncFilterItemsState)) {
10857
- if (filter.operator && this.operatorSelect) {
10858
- this.operatorSelect.value = filter.operator;
10860
+ if ((filter && filter.type === 'byCondition') || !syncFilterItemsState) {
10861
+ if (this.operatorSelect) {
10862
+ this.operatorSelect.value = filter?.operator ?? operators[0].value;
10859
10863
  }
10860
- if (filter.condition !== undefined && this.valueInput) {
10861
- if (Array.isArray(filter.condition)) {
10864
+ if (this.valueInput) {
10865
+ if (Array.isArray(filter?.condition)) {
10862
10866
  this.valueInput.value = String(filter.condition[0]);
10863
10867
  if (this.valueInputMax) {
10864
10868
  this.valueInputMax.value = String(filter.condition[1]);
10865
10869
  }
10866
10870
  }
10867
10871
  else {
10868
- this.valueInput.value = String(filter.condition);
10872
+ this.valueInput.value = String(filter?.condition ?? '');
10869
10873
  if (this.valueInputMax) {
10870
10874
  this.valueInputMax.value = '';
10871
10875
  }
@@ -10957,6 +10961,7 @@ ${recordsStr}
10957
10961
  this.clearFilter(fieldId);
10958
10962
  return;
10959
10963
  }
10964
+ const syncFilterItemsState = this.pluginOptions?.syncFilterItemsState ?? true;
10960
10965
  this.filterStateManager.dispatch({
10961
10966
  type: exports.FilterActionType.APPLY_FILTERS,
10962
10967
  payload: {
@@ -10964,10 +10969,10 @@ ${recordsStr}
10964
10969
  type: 'byCondition',
10965
10970
  operator,
10966
10971
  condition: conditionValue,
10967
- enable: true
10972
+ enable: true,
10973
+ shouldKeepUnrelatedState: !syncFilterItemsState
10968
10974
  }
10969
10975
  });
10970
- this.hide();
10971
10976
  }
10972
10977
  clearFilter(fieldId) {
10973
10978
  this.filterStateManager.dispatch({
@@ -11048,11 +11053,13 @@ ${recordsStr}
11048
11053
  this.valueInput.addEventListener('keypress', event => {
11049
11054
  if (event.key === 'Enter') {
11050
11055
  this.applyFilter();
11056
+ this.filterToolBarHide();
11051
11057
  }
11052
11058
  });
11053
11059
  this.valueInputMax.addEventListener('keypress', event => {
11054
11060
  if (event.key === 'Enter') {
11055
11061
  this.applyFilter();
11062
+ this.filterToolBarHide();
11056
11063
  }
11057
11064
  });
11058
11065
  this.categorySelect.addEventListener('change', () => {
@@ -11111,7 +11118,7 @@ ${recordsStr}
11111
11118
  this.table = table;
11112
11119
  this.filterStateManager = filterStateManager;
11113
11120
  this.valueFilter = new ValueFilter(this.table, this.filterStateManager, pluginOptions);
11114
- this.conditionFilter = new ConditionFilter(this.table, this.filterStateManager, pluginOptions);
11121
+ this.conditionFilter = new ConditionFilter(this.table, this.filterStateManager, pluginOptions, this.hide);
11115
11122
  this.pluginOptions = pluginOptions;
11116
11123
  this.filterMenuWidth = 300;
11117
11124
  this.filterStateManager.subscribe(state => {
@@ -11150,7 +11157,7 @@ ${recordsStr}
11150
11157
  else if (this.activeTab === 'byCondition') {
11151
11158
  this.conditionFilter.applyFilter(field);
11152
11159
  }
11153
- this.hide(this.currentCol, this.currentRow);
11160
+ this.hide();
11154
11161
  }
11155
11162
  clearFilter(field) {
11156
11163
  if (this.valueFilter) {
@@ -11159,7 +11166,7 @@ ${recordsStr}
11159
11166
  if (this.conditionFilter) {
11160
11167
  this.conditionFilter.clearFilter(field);
11161
11168
  }
11162
- this.hide(this.currentCol, this.currentRow);
11169
+ this.hide();
11163
11170
  }
11164
11171
  updateClearFilterButtonState(field) {
11165
11172
  const currentFilter = this.filterStateManager.getFilterState(field);
@@ -11232,7 +11239,7 @@ ${recordsStr}
11232
11239
  this.filterTabByCondition.addEventListener('click', () => {
11233
11240
  this.onTabSwitch('byCondition');
11234
11241
  });
11235
- this.cancelFilterButton.addEventListener('click', () => this.hide(this.currentCol, this.currentRow));
11242
+ this.cancelFilterButton.addEventListener('click', () => this.hide());
11236
11243
  this.clearFilterOptionLink.addEventListener('click', e => {
11237
11244
  e.preventDefault();
11238
11245
  this.clearFilter(this.selectedField);
@@ -11242,7 +11249,7 @@ ${recordsStr}
11242
11249
  });
11243
11250
  document.addEventListener('click', () => {
11244
11251
  if (this.isVisible) {
11245
- this.hide(this.currentCol, this.currentRow);
11252
+ this.hide();
11246
11253
  }
11247
11254
  });
11248
11255
  this.filterMenu.addEventListener('click', e => {
@@ -11314,14 +11321,14 @@ ${recordsStr}
11314
11321
  });
11315
11322
  }, 0);
11316
11323
  }
11317
- hide(currentCol, currentRow) {
11324
+ hide = (currentCol, currentRow) => {
11318
11325
  this.filterMenu.style.display = 'none';
11319
11326
  this.isVisible = false;
11320
11327
  this.table.fireListeners(VTable.TABLE_EVENT_TYPE.FILTER_MENU_HIDE, {
11321
- col: currentCol,
11322
- row: currentRow
11328
+ col: currentCol ?? this.currentCol,
11329
+ row: currentRow ?? this.currentRow
11323
11330
  });
11324
- }
11331
+ };
11325
11332
  destroy() {
11326
11333
  this.valueFilter.destroy();
11327
11334
  this.filterMenu.remove();