@visactor/vtable-plugins 1.22.4-alpha.5 → 1.22.4-alpha.7

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.
Files changed (49) hide show
  1. package/cjs/filter/condition-filter.d.ts +3 -3
  2. package/cjs/filter/condition-filter.js +6 -118
  3. package/cjs/filter/condition-filter.js.map +1 -1
  4. package/cjs/filter/constants.d.ts +7 -0
  5. package/cjs/filter/constants.js +124 -0
  6. package/cjs/filter/constants.js.map +1 -0
  7. package/cjs/filter/filter-state-manager.d.ts +2 -2
  8. package/cjs/filter/filter-state-manager.js +3 -3
  9. package/cjs/filter/filter-state-manager.js.map +1 -1
  10. package/cjs/filter/filter-toolbar.d.ts +4 -4
  11. package/cjs/filter/filter-toolbar.js +18 -11
  12. package/cjs/filter/filter-toolbar.js.map +1 -1
  13. package/cjs/filter/filter.d.ts +1 -0
  14. package/cjs/filter/filter.js +24 -16
  15. package/cjs/filter/filter.js.map +1 -1
  16. package/cjs/filter/types.d.ts +6 -0
  17. package/cjs/filter/types.js.map +1 -1
  18. package/cjs/filter/value-filter.d.ts +1 -0
  19. package/cjs/filter/value-filter.js +3 -0
  20. package/cjs/filter/value-filter.js.map +1 -1
  21. package/cjs/master-detail-plugin/config.js +1 -2
  22. package/cjs/master-detail-plugin/core.js +2 -1
  23. package/cjs/table-export/index.js +1 -1
  24. package/dist/vtable-plugins.js +94 -62
  25. package/dist/vtable-plugins.min.js +1 -1
  26. package/es/filter/condition-filter.d.ts +3 -3
  27. package/es/filter/condition-filter.js +7 -117
  28. package/es/filter/condition-filter.js.map +1 -1
  29. package/es/filter/constants.d.ts +7 -0
  30. package/es/filter/constants.js +120 -0
  31. package/es/filter/constants.js.map +1 -0
  32. package/es/filter/filter-state-manager.d.ts +2 -2
  33. package/es/filter/filter-state-manager.js +3 -3
  34. package/es/filter/filter-state-manager.js.map +1 -1
  35. package/es/filter/filter-toolbar.d.ts +4 -4
  36. package/es/filter/filter-toolbar.js +19 -10
  37. package/es/filter/filter-toolbar.js.map +1 -1
  38. package/es/filter/filter.d.ts +1 -0
  39. package/es/filter/filter.js +24 -15
  40. package/es/filter/filter.js.map +1 -1
  41. package/es/filter/types.d.ts +6 -0
  42. package/es/filter/types.js.map +1 -1
  43. package/es/filter/value-filter.d.ts +1 -0
  44. package/es/filter/value-filter.js +3 -0
  45. package/es/filter/value-filter.js.map +1 -1
  46. package/es/master-detail-plugin/config.js +1 -2
  47. package/es/master-detail-plugin/core.js +2 -1
  48. package/es/table-export/index.js +1 -1
  49. package/package.json +7 -7
@@ -10111,7 +10111,7 @@ ${recordsStr}
10111
10111
  if (this.shouldApplyFilter(action)) {
10112
10112
  this.applyFilters();
10113
10113
  }
10114
- this.notifyListeners();
10114
+ this.notifyListeners(action);
10115
10115
  }
10116
10116
  subscribe(listener) {
10117
10117
  this.listeners.push(listener);
@@ -10119,8 +10119,8 @@ ${recordsStr}
10119
10119
  this.listeners = this.listeners.filter(l => l !== listener);
10120
10120
  };
10121
10121
  }
10122
- notifyListeners() {
10123
- this.listeners.forEach(listener => listener(this.state));
10122
+ notifyListeners(action) {
10123
+ this.listeners.forEach(listener => listener(this.state, action));
10124
10124
  }
10125
10125
  reduce(state, action) {
10126
10126
  const { type, payload } = action;
@@ -10831,8 +10831,46 @@ ${recordsStr}
10831
10831
  hide() {
10832
10832
  this.filterByValuePanel.style.display = 'none';
10833
10833
  }
10834
+ clearSearchInputValue() {
10835
+ this.filterByValueSearchInput.value = '';
10836
+ }
10834
10837
  }
10835
10838
 
10839
+ const categories = [
10840
+ { value: exports.FilterOperatorCategory.ALL, label: '全部' },
10841
+ { value: exports.FilterOperatorCategory.TEXT, label: '文本' },
10842
+ { value: exports.FilterOperatorCategory.NUMBER, label: '数值' },
10843
+ { value: exports.FilterOperatorCategory.COLOR, label: '颜色' },
10844
+ { value: exports.FilterOperatorCategory.CHECKBOX, label: '复选框' },
10845
+ { value: exports.FilterOperatorCategory.RADIO, label: '单选框' }
10846
+ ];
10847
+ const operators = [
10848
+ { value: 'equals', label: '等于', category: exports.FilterOperatorCategory.ALL },
10849
+ { value: 'notEquals', label: '不等于', category: exports.FilterOperatorCategory.ALL },
10850
+ { value: 'equals', label: '等于', category: exports.FilterOperatorCategory.NUMBER },
10851
+ { value: 'notEquals', label: '不等于', category: exports.FilterOperatorCategory.NUMBER },
10852
+ { value: 'greaterThan', label: '大于', category: exports.FilterOperatorCategory.NUMBER },
10853
+ { value: 'lessThan', label: '小于', category: exports.FilterOperatorCategory.NUMBER },
10854
+ { value: 'greaterThanOrEqual', label: '大于等于', category: exports.FilterOperatorCategory.NUMBER },
10855
+ { value: 'lessThanOrEqual', label: '小于等于', category: exports.FilterOperatorCategory.NUMBER },
10856
+ { value: 'between', label: '介于', category: exports.FilterOperatorCategory.NUMBER },
10857
+ { value: 'notBetween', label: '不介于', category: exports.FilterOperatorCategory.NUMBER },
10858
+ { value: 'equals', label: '等于', category: exports.FilterOperatorCategory.TEXT },
10859
+ { value: 'notEquals', label: '不等于', category: exports.FilterOperatorCategory.TEXT },
10860
+ { value: 'contains', label: '包含', category: exports.FilterOperatorCategory.TEXT },
10861
+ { value: 'notContains', label: '不包含', category: exports.FilterOperatorCategory.TEXT },
10862
+ { value: 'startsWith', label: '开头是', category: exports.FilterOperatorCategory.TEXT },
10863
+ { value: 'notStartsWith', label: '开头不是', category: exports.FilterOperatorCategory.TEXT },
10864
+ { value: 'endsWith', label: '结尾是', category: exports.FilterOperatorCategory.TEXT },
10865
+ { value: 'notEndsWith', label: '结尾不是', category: exports.FilterOperatorCategory.TEXT },
10866
+ { value: 'equals', label: '等于', category: exports.FilterOperatorCategory.COLOR },
10867
+ { value: 'notEquals', label: '不等于', category: exports.FilterOperatorCategory.COLOR },
10868
+ { value: 'isChecked', label: '已选中', category: exports.FilterOperatorCategory.CHECKBOX },
10869
+ { value: 'isUnchecked', label: '未选中', category: exports.FilterOperatorCategory.CHECKBOX },
10870
+ { value: 'isChecked', label: '已选中', category: exports.FilterOperatorCategory.RADIO },
10871
+ { value: 'isUnchecked', label: '未选中', category: exports.FilterOperatorCategory.RADIO }
10872
+ ];
10873
+
10836
10874
  class ConditionFilter {
10837
10875
  table;
10838
10876
  filterStateManager;
@@ -10844,44 +10882,14 @@ ${recordsStr}
10844
10882
  valueInputMax;
10845
10883
  categorySelect;
10846
10884
  currentCategory = exports.FilterOperatorCategory.ALL;
10847
- operators = [
10848
- { value: 'equals', label: '等于', category: exports.FilterOperatorCategory.ALL },
10849
- { value: 'notEquals', label: '不等于', category: exports.FilterOperatorCategory.ALL },
10850
- { value: 'equals', label: '等于', category: exports.FilterOperatorCategory.NUMBER },
10851
- { value: 'notEquals', label: '不等于', category: exports.FilterOperatorCategory.NUMBER },
10852
- { value: 'greaterThan', label: '大于', category: exports.FilterOperatorCategory.NUMBER },
10853
- { value: 'lessThan', label: '小于', category: exports.FilterOperatorCategory.NUMBER },
10854
- { value: 'greaterThanOrEqual', label: '大于等于', category: exports.FilterOperatorCategory.NUMBER },
10855
- { value: 'lessThanOrEqual', label: '小于等于', category: exports.FilterOperatorCategory.NUMBER },
10856
- { value: 'between', label: '介于', category: exports.FilterOperatorCategory.NUMBER },
10857
- { value: 'notBetween', label: '不介于', category: exports.FilterOperatorCategory.NUMBER },
10858
- { value: 'equals', label: '等于', category: exports.FilterOperatorCategory.TEXT },
10859
- { value: 'notEquals', label: '不等于', category: exports.FilterOperatorCategory.TEXT },
10860
- { value: 'contains', label: '包含', category: exports.FilterOperatorCategory.TEXT },
10861
- { value: 'notContains', label: '不包含', category: exports.FilterOperatorCategory.TEXT },
10862
- { value: 'startsWith', label: '开头是', category: exports.FilterOperatorCategory.TEXT },
10863
- { value: 'notStartsWith', label: '开头不是', category: exports.FilterOperatorCategory.TEXT },
10864
- { value: 'endsWith', label: '结尾是', category: exports.FilterOperatorCategory.TEXT },
10865
- { value: 'notEndsWith', label: '结尾不是', category: exports.FilterOperatorCategory.TEXT },
10866
- { value: 'equals', label: '等于', category: exports.FilterOperatorCategory.COLOR },
10867
- { value: 'notEquals', label: '不等于', category: exports.FilterOperatorCategory.COLOR },
10868
- { value: 'isChecked', label: '已选中', category: exports.FilterOperatorCategory.CHECKBOX },
10869
- { value: 'isUnchecked', label: '未选中', category: exports.FilterOperatorCategory.CHECKBOX },
10870
- { value: 'isChecked', label: '已选中', category: exports.FilterOperatorCategory.RADIO },
10871
- { value: 'isUnchecked', label: '未选中', category: exports.FilterOperatorCategory.RADIO }
10872
- ];
10873
- categories = [
10874
- { value: exports.FilterOperatorCategory.ALL, label: '全部' },
10875
- { value: exports.FilterOperatorCategory.TEXT, label: '文本' },
10876
- { value: exports.FilterOperatorCategory.NUMBER, label: '数值' },
10877
- { value: exports.FilterOperatorCategory.COLOR, label: '颜色' },
10878
- { value: exports.FilterOperatorCategory.CHECKBOX, label: '复选框' },
10879
- { value: exports.FilterOperatorCategory.RADIO, label: '单选框' }
10880
- ];
10881
- constructor(table, filterStateManager, styles) {
10885
+ categories = [];
10886
+ operators = [];
10887
+ constructor(table, filterStateManager, styles, conditionCategories) {
10882
10888
  this.table = table;
10883
10889
  this.styles = styles;
10884
10890
  this.filterStateManager = filterStateManager;
10891
+ this.categories = conditionCategories;
10892
+ this.operators = operators;
10885
10893
  }
10886
10894
  setSelectedField(fieldId) {
10887
10895
  this.selectedField = fieldId;
@@ -10896,7 +10904,9 @@ ${recordsStr}
10896
10904
  let filteredOperators;
10897
10905
  if (this.currentCategory === exports.FilterOperatorCategory.ALL) {
10898
10906
  const uniqueOperators = new Map();
10899
- this.operators.forEach(op => {
10907
+ this.operators
10908
+ .filter(op => this.categories.map(cat => cat.value).includes(op.category))
10909
+ .forEach(op => {
10900
10910
  if (!uniqueOperators.has(op.value)) {
10901
10911
  uniqueOperators.set(op.value, op);
10902
10912
  }
@@ -11161,12 +11171,12 @@ ${recordsStr}
11161
11171
  clearFilterOptionLink;
11162
11172
  cancelFilterButton;
11163
11173
  applyFilterButton;
11164
- constructor(table, filterStateManager, styles) {
11174
+ constructor(table, filterStateManager, styles, conditionCategories) {
11165
11175
  this.table = table;
11166
11176
  this.filterStateManager = filterStateManager;
11167
11177
  this.styles = styles;
11168
11178
  this.valueFilter = new ValueFilter(this.table, this.filterStateManager, this.styles);
11169
- this.conditionFilter = new ConditionFilter(this.table, this.filterStateManager, this.styles);
11179
+ this.conditionFilter = new ConditionFilter(this.table, this.filterStateManager, this.styles, conditionCategories);
11170
11180
  this.filterMenuWidth = 300;
11171
11181
  this.filterStateManager.subscribe(state => {
11172
11182
  if (this.isVisible && this.selectedField !== null) {
@@ -11204,7 +11214,7 @@ ${recordsStr}
11204
11214
  else if (this.activeTab === 'byCondition') {
11205
11215
  this.conditionFilter.applyFilter(field);
11206
11216
  }
11207
- this.hide();
11217
+ this.hide(this.currentCol, this.currentRow);
11208
11218
  }
11209
11219
  clearFilter(field) {
11210
11220
  if (this.valueFilter) {
@@ -11213,7 +11223,7 @@ ${recordsStr}
11213
11223
  if (this.conditionFilter) {
11214
11224
  this.conditionFilter.clearFilter(field);
11215
11225
  }
11216
- this.hide();
11226
+ this.hide(this.currentCol, this.currentRow);
11217
11227
  }
11218
11228
  updateClearFilterButtonState(field) {
11219
11229
  const currentFilter = this.filterStateManager.getFilterState(field);
@@ -11266,7 +11276,7 @@ ${recordsStr}
11266
11276
  this.filterTabByCondition.addEventListener('click', () => {
11267
11277
  this.onTabSwitch('byCondition');
11268
11278
  });
11269
- this.cancelFilterButton.addEventListener('click', () => this.hide());
11279
+ this.cancelFilterButton.addEventListener('click', () => this.hide(this.currentCol, this.currentRow));
11270
11280
  this.clearFilterOptionLink.addEventListener('click', e => {
11271
11281
  e.preventDefault();
11272
11282
  this.clearFilter(this.selectedField);
@@ -11276,7 +11286,7 @@ ${recordsStr}
11276
11286
  });
11277
11287
  document.addEventListener('click', () => {
11278
11288
  if (this.isVisible) {
11279
- this.hide();
11289
+ this.hide(this.currentCol, this.currentRow);
11280
11290
  }
11281
11291
  });
11282
11292
  this.filterMenu.addEventListener('click', e => {
@@ -11314,6 +11324,7 @@ ${recordsStr}
11314
11324
  this.filterMenu.style.top = `${top}px`;
11315
11325
  }
11316
11326
  show(col, row, filterModes) {
11327
+ this.valueFilter.clearSearchInputValue();
11317
11328
  this.filterModes = filterModes;
11318
11329
  if (!this.filterModes.includes('byValue')) {
11319
11330
  this.filterTabByValue.style.display = 'none';
@@ -11337,11 +11348,19 @@ ${recordsStr}
11337
11348
  this.updateClearFilterButtonState(field);
11338
11349
  setTimeout(() => {
11339
11350
  this.isVisible = true;
11351
+ this.table.fireListeners(VTable.TABLE_EVENT_TYPE.FILTER_MENU_SHOW, {
11352
+ col: col,
11353
+ row: row
11354
+ });
11340
11355
  }, 0);
11341
11356
  }
11342
- hide() {
11357
+ hide(currentCol, currentRow) {
11343
11358
  this.filterMenu.style.display = 'none';
11344
11359
  this.isVisible = false;
11360
+ this.table.fireListeners(VTable.TABLE_EVENT_TYPE.FILTER_MENU_HIDE, {
11361
+ col: currentCol,
11362
+ row: currentRow
11363
+ });
11345
11364
  }
11346
11365
  }
11347
11366
 
@@ -20851,6 +20870,24 @@ ${recordsStr}
20851
20870
  this.pluginOptions.filterModes = ['byValue', 'byCondition'];
20852
20871
  }
20853
20872
  this.pluginOptions.styles = lodashExports.merge({}, filterStyles, pluginOptions.styles);
20873
+ this.pluginOptions.conditionCategories = pluginOptions.conditionCategories ?? categories;
20874
+ }
20875
+ initFilterPlugin(eventArgs) {
20876
+ this.filterEngine = new FilterEngine();
20877
+ this.filterStateManager = new FilterStateManager(this.table, this.filterEngine);
20878
+ this.filterToolbar = new FilterToolbar(this.table, this.filterStateManager, this.pluginOptions.styles, this.pluginOptions.conditionCategories);
20879
+ this.columns = eventArgs.options.columns;
20880
+ this.filterToolbar.render(document.body);
20881
+ this.updateFilterIcons(this.columns);
20882
+ this.filterStateManager.subscribe((_, action) => {
20883
+ if (action?.type === exports.FilterActionType.ADD_FILTER) {
20884
+ return;
20885
+ }
20886
+ this.updateFilterIcons(this.columns);
20887
+ this.table.updateColumns(this.columns, {
20888
+ clearRowHeightCache: false
20889
+ });
20890
+ });
20854
20891
  }
20855
20892
  run(...args) {
20856
20893
  const eventArgs = args[0];
@@ -20858,23 +20895,15 @@ ${recordsStr}
20858
20895
  const table = args[2];
20859
20896
  this.table = table;
20860
20897
  if (runtime === VTable.TABLE_EVENT_TYPE.BEFORE_INIT) {
20861
- this.filterEngine = new FilterEngine();
20862
- this.filterStateManager = new FilterStateManager(this.table, this.filterEngine);
20863
- this.filterToolbar = new FilterToolbar(this.table, this.filterStateManager, this.pluginOptions.styles);
20864
- this.columns = eventArgs.options.columns;
20865
- this.filterToolbar.render(document.body);
20866
- this.updateFilterIcons(this.columns);
20867
- this.filterStateManager.subscribe(() => {
20868
- this.updateFilterIcons(this.columns);
20869
- this.table.updateColumns(this.columns, {
20870
- clearRowHeightCache: false
20871
- });
20872
- });
20898
+ this.initFilterPlugin(eventArgs);
20873
20899
  }
20874
20900
  else if (runtime === VTable.TABLE_EVENT_TYPE.BEFORE_UPDATE_OPTION) {
20901
+ if (!this.filterEngine || !this.filterStateManager || !this.filterToolbar) {
20902
+ this.initFilterPlugin(eventArgs);
20903
+ }
20875
20904
  this.pluginOptions = {
20876
20905
  ...this.pluginOptions,
20877
- ...eventArgs.options.plugins.find(plugin => plugin.id === this.id).pluginOptions
20906
+ ...eventArgs.options.plugins?.find(plugin => plugin.id === this.id)?.pluginOptions
20878
20907
  };
20879
20908
  this.columns = eventArgs.options.columns;
20880
20909
  this.handleOptionUpdate(eventArgs.options);
@@ -20888,7 +20917,7 @@ ${recordsStr}
20888
20917
  const col = eventArgs.col;
20889
20918
  const row = eventArgs.row;
20890
20919
  if (this.filterToolbar.isVisible) {
20891
- this.filterToolbar.hide();
20920
+ this.filterToolbar.hide(eventArgs.col, eventArgs.row);
20892
20921
  }
20893
20922
  else {
20894
20923
  this.filterToolbar.show(col, row, this.pluginOptions.filterModes);
@@ -20935,8 +20964,8 @@ ${recordsStr}
20935
20964
  const filterIcon = this.pluginOptions.filterIcon;
20936
20965
  const filteringIcon = this.pluginOptions.filteringIcon;
20937
20966
  const isIconEqual = (a, b) => a === b || (a && b && typeof a === 'object' && typeof b === 'object' && a.name === b.name);
20938
- const toIconList = icons => (icons ? (Array.isArray(icons) ? icons : [icons]) : []);
20939
- const compactIcons = list => (list.length === 0 ? undefined : list.length === 1 ? list[0] : list);
20967
+ const toIconList = (icons) => (icons ? (Array.isArray(icons) ? icons : [icons]) : []);
20968
+ const compactIcons = (list) => (list.length === 0 ? undefined : list.length === 1 ? list[0] : list);
20940
20969
  columns.forEach(column => {
20941
20970
  const shouldShow = this.shouldEnableFilterForColumn(column.field, column);
20942
20971
  const isFiltering = !!this.filterStateManager.getFilterState(column.field)?.enable;
@@ -21025,6 +21054,9 @@ ${recordsStr}
21025
21054
  });
21026
21055
  }
21027
21056
  release() {
21057
+ this.columns.forEach(column => {
21058
+ column.headerIcon = undefined;
21059
+ });
21028
21060
  this.table = null;
21029
21061
  this.filterEngine = null;
21030
21062
  this.filterStateManager = null;