@visactor/vtable-plugins 1.22.7 → 1.22.8-alpha.13

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 (69) hide show
  1. package/cjs/excel-edit-cell-keyboard.js +1 -0
  2. package/cjs/excel-edit-cell-keyboard.js.map +1 -1
  3. package/cjs/filter/condition-filter.d.ts +13 -2
  4. package/cjs/filter/condition-filter.js +69 -172
  5. package/cjs/filter/condition-filter.js.map +1 -1
  6. package/cjs/filter/constant.d.ts +7 -0
  7. package/cjs/filter/constant.js +124 -0
  8. package/cjs/filter/constant.js.map +1 -0
  9. package/cjs/filter/filter-engine.d.ts +3 -1
  10. package/cjs/filter/filter-engine.js +6 -4
  11. package/cjs/filter/filter-engine.js.map +1 -1
  12. package/cjs/filter/filter-state-manager.js +8 -2
  13. package/cjs/filter/filter-state-manager.js.map +1 -1
  14. package/cjs/filter/filter-toolbar.d.ts +9 -4
  15. package/cjs/filter/filter-toolbar.js +44 -27
  16. package/cjs/filter/filter-toolbar.js.map +1 -1
  17. package/cjs/filter/filter.d.ts +2 -0
  18. package/cjs/filter/filter.js +29 -15
  19. package/cjs/filter/filter.js.map +1 -1
  20. package/cjs/filter/styles.js +1 -1
  21. package/cjs/filter/styles.js.map +1 -1
  22. package/cjs/filter/types.d.ts +35 -0
  23. package/cjs/filter/types.js.map +1 -1
  24. package/cjs/filter/value-filter.d.ts +10 -2
  25. package/cjs/filter/value-filter.js +115 -57
  26. package/cjs/filter/value-filter.js.map +1 -1
  27. package/cjs/focus-highlight.js +1 -1
  28. package/cjs/focus-highlight.js.map +1 -1
  29. package/cjs/master-detail-plugin/checkbox.js +0 -1
  30. package/cjs/master-detail-plugin/config.js +2 -1
  31. package/cjs/master-detail-plugin/utils.js +1 -1
  32. package/cjs/table-series-number.js +1 -0
  33. package/cjs/table-series-number.js.map +1 -1
  34. package/dist/vtable-plugins.js +9839 -168
  35. package/dist/vtable-plugins.min.js +3 -3
  36. package/es/excel-edit-cell-keyboard.js +1 -0
  37. package/es/excel-edit-cell-keyboard.js.map +1 -1
  38. package/es/filter/condition-filter.d.ts +13 -2
  39. package/es/filter/condition-filter.js +67 -168
  40. package/es/filter/condition-filter.js.map +1 -1
  41. package/es/filter/constant.d.ts +7 -0
  42. package/es/filter/constant.js +120 -0
  43. package/es/filter/constant.js.map +1 -0
  44. package/es/filter/filter-engine.d.ts +3 -1
  45. package/es/filter/filter-engine.js +6 -4
  46. package/es/filter/filter-engine.js.map +1 -1
  47. package/es/filter/filter-state-manager.js +8 -2
  48. package/es/filter/filter-state-manager.js.map +1 -1
  49. package/es/filter/filter-toolbar.d.ts +9 -4
  50. package/es/filter/filter-toolbar.js +44 -24
  51. package/es/filter/filter-toolbar.js.map +1 -1
  52. package/es/filter/filter.d.ts +2 -0
  53. package/es/filter/filter.js +36 -16
  54. package/es/filter/filter.js.map +1 -1
  55. package/es/filter/styles.js +1 -1
  56. package/es/filter/styles.js.map +1 -1
  57. package/es/filter/types.d.ts +35 -0
  58. package/es/filter/types.js.map +1 -1
  59. package/es/filter/value-filter.d.ts +10 -2
  60. package/es/filter/value-filter.js +112 -54
  61. package/es/filter/value-filter.js.map +1 -1
  62. package/es/focus-highlight.js +1 -1
  63. package/es/focus-highlight.js.map +1 -1
  64. package/es/master-detail-plugin/checkbox.js +1 -2
  65. package/es/master-detail-plugin/config.js +2 -1
  66. package/es/master-detail-plugin/utils.js +1 -1
  67. package/es/table-series-number.js +1 -0
  68. package/es/table-series-number.js.map +1 -1
  69. package/package.json +7 -7
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.operators = exports.categories = void 0;
6
+
7
+ const types_1 = require("./types");
8
+
9
+ exports.categories = [ {
10
+ value: types_1.FilterOperatorCategory.ALL,
11
+ label: "全部"
12
+ }, {
13
+ value: types_1.FilterOperatorCategory.TEXT,
14
+ label: "文本"
15
+ }, {
16
+ value: types_1.FilterOperatorCategory.NUMBER,
17
+ label: "数值"
18
+ }, {
19
+ value: types_1.FilterOperatorCategory.COLOR,
20
+ label: "颜色"
21
+ }, {
22
+ value: types_1.FilterOperatorCategory.CHECKBOX,
23
+ label: "复选框"
24
+ }, {
25
+ value: types_1.FilterOperatorCategory.RADIO,
26
+ label: "单选框"
27
+ } ], exports.operators = [ {
28
+ value: "equals",
29
+ label: "等于",
30
+ category: types_1.FilterOperatorCategory.ALL
31
+ }, {
32
+ value: "notEquals",
33
+ label: "不等于",
34
+ category: types_1.FilterOperatorCategory.ALL
35
+ }, {
36
+ value: "equals",
37
+ label: "等于",
38
+ category: types_1.FilterOperatorCategory.NUMBER
39
+ }, {
40
+ value: "notEquals",
41
+ label: "不等于",
42
+ category: types_1.FilterOperatorCategory.NUMBER
43
+ }, {
44
+ value: "greaterThan",
45
+ label: "大于",
46
+ category: types_1.FilterOperatorCategory.NUMBER
47
+ }, {
48
+ value: "lessThan",
49
+ label: "小于",
50
+ category: types_1.FilterOperatorCategory.NUMBER
51
+ }, {
52
+ value: "greaterThanOrEqual",
53
+ label: "大于等于",
54
+ category: types_1.FilterOperatorCategory.NUMBER
55
+ }, {
56
+ value: "lessThanOrEqual",
57
+ label: "小于等于",
58
+ category: types_1.FilterOperatorCategory.NUMBER
59
+ }, {
60
+ value: "between",
61
+ label: "介于",
62
+ category: types_1.FilterOperatorCategory.NUMBER
63
+ }, {
64
+ value: "notBetween",
65
+ label: "不介于",
66
+ category: types_1.FilterOperatorCategory.NUMBER
67
+ }, {
68
+ value: "equals",
69
+ label: "等于",
70
+ category: types_1.FilterOperatorCategory.TEXT
71
+ }, {
72
+ value: "notEquals",
73
+ label: "不等于",
74
+ category: types_1.FilterOperatorCategory.TEXT
75
+ }, {
76
+ value: "contains",
77
+ label: "包含",
78
+ category: types_1.FilterOperatorCategory.TEXT
79
+ }, {
80
+ value: "notContains",
81
+ label: "不包含",
82
+ category: types_1.FilterOperatorCategory.TEXT
83
+ }, {
84
+ value: "startsWith",
85
+ label: "开头是",
86
+ category: types_1.FilterOperatorCategory.TEXT
87
+ }, {
88
+ value: "notStartsWith",
89
+ label: "开头不是",
90
+ category: types_1.FilterOperatorCategory.TEXT
91
+ }, {
92
+ value: "endsWith",
93
+ label: "结尾是",
94
+ category: types_1.FilterOperatorCategory.TEXT
95
+ }, {
96
+ value: "notEndsWith",
97
+ label: "结尾不是",
98
+ category: types_1.FilterOperatorCategory.TEXT
99
+ }, {
100
+ value: "equals",
101
+ label: "等于",
102
+ category: types_1.FilterOperatorCategory.COLOR
103
+ }, {
104
+ value: "notEquals",
105
+ label: "不等于",
106
+ category: types_1.FilterOperatorCategory.COLOR
107
+ }, {
108
+ value: "isChecked",
109
+ label: "已选中",
110
+ category: types_1.FilterOperatorCategory.CHECKBOX
111
+ }, {
112
+ value: "isUnchecked",
113
+ label: "未选中",
114
+ category: types_1.FilterOperatorCategory.CHECKBOX
115
+ }, {
116
+ value: "isChecked",
117
+ label: "已选中",
118
+ category: types_1.FilterOperatorCategory.RADIO
119
+ }, {
120
+ value: "isUnchecked",
121
+ label: "未选中",
122
+ category: types_1.FilterOperatorCategory.RADIO
123
+ } ];
124
+ //# sourceMappingURL=constant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/filter/constant.ts"],"names":[],"mappings":";;;AACA,mCAAiD;AAGpC,QAAA,UAAU,GAAG;IACxB,EAAE,KAAK,EAAE,8BAAsB,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE;IAClD,EAAE,KAAK,EAAE,8BAAsB,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;IACnD,EAAE,KAAK,EAAE,8BAAsB,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE;IACrD,EAAE,KAAK,EAAE,8BAAsB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE;IACpD,EAAE,KAAK,EAAE,8BAAsB,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE;IACxD,EAAE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,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,8BAAsB,CAAC,KAAK,EAAE;CAC/E,CAAC","file":"constant.js","sourcesContent":["import type { OperatorOption } from './types';\nimport { FilterOperatorCategory } from './types';\n\n// 分类下拉选项\nexport const categories = [\n { value: FilterOperatorCategory.ALL, label: '全部' },\n { value: FilterOperatorCategory.TEXT, label: '文本' },\n { value: FilterOperatorCategory.NUMBER, label: '数值' },\n { value: FilterOperatorCategory.COLOR, label: '颜色' },\n { value: FilterOperatorCategory.CHECKBOX, label: '复选框' },\n { value: FilterOperatorCategory.RADIO, label: '单选框' }\n];\n\n// 按分类组织的操作符选项\nexport const operators: OperatorOption[] = [\n // 通用操作符 (全部分类中显示)\n { value: 'equals', label: '等于', category: FilterOperatorCategory.ALL },\n { value: 'notEquals', label: '不等于', category: FilterOperatorCategory.ALL },\n\n // 数值操作符\n { value: 'equals', label: '等于', category: FilterOperatorCategory.NUMBER },\n { value: 'notEquals', label: '不等于', category: FilterOperatorCategory.NUMBER },\n { value: 'greaterThan', label: '大于', category: FilterOperatorCategory.NUMBER },\n { value: 'lessThan', label: '小于', category: FilterOperatorCategory.NUMBER },\n { value: 'greaterThanOrEqual', label: '大于等于', category: FilterOperatorCategory.NUMBER },\n { value: 'lessThanOrEqual', label: '小于等于', category: FilterOperatorCategory.NUMBER },\n { value: 'between', label: '介于', category: FilterOperatorCategory.NUMBER },\n { value: 'notBetween', label: '不介于', category: FilterOperatorCategory.NUMBER },\n\n // 文本操作符\n { value: 'equals', label: '等于', category: FilterOperatorCategory.TEXT },\n { value: 'notEquals', label: '不等于', category: FilterOperatorCategory.TEXT },\n { value: 'contains', label: '包含', category: FilterOperatorCategory.TEXT },\n { value: 'notContains', label: '不包含', category: FilterOperatorCategory.TEXT },\n { value: 'startsWith', label: '开头是', category: FilterOperatorCategory.TEXT },\n { value: 'notStartsWith', label: '开头不是', category: FilterOperatorCategory.TEXT },\n { value: 'endsWith', label: '结尾是', category: FilterOperatorCategory.TEXT },\n { value: 'notEndsWith', label: '结尾不是', category: FilterOperatorCategory.TEXT },\n\n // 颜色操作符\n { value: 'equals', label: '等于', category: FilterOperatorCategory.COLOR },\n { value: 'notEquals', label: '不等于', category: FilterOperatorCategory.COLOR },\n\n // 复选框操作符\n { value: 'isChecked', label: '已选中', category: FilterOperatorCategory.CHECKBOX },\n { value: 'isUnchecked', label: '未选中', category: FilterOperatorCategory.CHECKBOX },\n\n // 单选框操作符\n { value: 'isChecked', label: '已选中', category: FilterOperatorCategory.RADIO },\n { value: 'isUnchecked', label: '未选中', category: FilterOperatorCategory.RADIO }\n];\n"]}
@@ -1,10 +1,12 @@
1
1
  import type { ListTable, PivotTable, TYPES } from '@visactor/vtable';
2
- import type { FilterState } from './types';
2
+ import type { FilterState, FilterOptions } from './types';
3
3
  export declare class FilterEngine {
4
4
  filterFuncRule: (TYPES.FilterFuncRule & {
5
5
  fieldId?: string;
6
6
  })[];
7
7
  filterValueRule: TYPES.FilterValueRule[];
8
+ private pluginOptions;
9
+ constructor(filterPluginOptions: FilterOptions);
8
10
  applyFilter(state: FilterState, table: ListTable | PivotTable): void;
9
11
  private createFilterFunction;
10
12
  private compareValues;
@@ -5,10 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  }), exports.FilterEngine = void 0;
6
6
 
7
7
  class FilterEngine {
8
- constructor() {
9
- this.filterFuncRule = [], this.filterValueRule = [];
8
+ constructor(filterPluginOptions) {
9
+ this.filterFuncRule = [], this.filterValueRule = [], this.pluginOptions = filterPluginOptions;
10
10
  }
11
11
  applyFilter(state, table) {
12
+ var _a;
12
13
  const {filters: filters} = state;
13
14
  this.filterFuncRule = [], this.filterValueRule = [], filters.forEach(((filter, field) => {
14
15
  if (filter.enable) if ("byValue" === filter.type) this.filterValueRule.push({
@@ -22,7 +23,8 @@ class FilterEngine {
22
23
  });
23
24
  }
24
25
  })), table.updateFilterRules([ ...this.filterFuncRule, ...this.filterValueRule ], {
25
- clearRowHeightCache: !1
26
+ clearRowHeightCache: !1,
27
+ onFilterRecordsEnd: null === (_a = this.pluginOptions) || void 0 === _a ? void 0 : _a.onFilterRecordsEnd
26
28
  });
27
29
  }
28
30
  createFilterFunction(filter) {
@@ -88,7 +90,7 @@ class FilterEngine {
88
90
  if ("number" == typeof value && "number" == typeof condition) return value === condition ? 0 : value > condition ? 1 : -1;
89
91
  if ("boolean" == typeof value && "boolean" == typeof condition) return value === condition ? 0 : -1;
90
92
  const valueStr = String(value).toLowerCase(), conditionStr = String(condition).toLowerCase();
91
- return valueStr === conditionStr ? 0 : valueStr > conditionStr ? 1 : -1;
93
+ return isNaN(Number(valueStr)) || isNaN(Number(conditionStr)) ? valueStr === conditionStr ? 0 : valueStr > conditionStr ? 1 : -1 : Number(valueStr) === Number(conditionStr) ? 0 : Number(valueStr) > Number(conditionStr) ? 1 : -1;
92
94
  }
93
95
  clearAllFilter(table) {
94
96
  this.filterFuncRule = [], this.filterValueRule = [], table.updateFilterRules([]);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/filter/filter-engine.ts"],"names":[],"mappings":";;;AAMA,MAAa,YAAY;IAAzB;QACE,mBAAc,GAAoD,EAAE,CAAC;QACrE,oBAAe,GAA4B,EAAE,CAAC;IAgIhD,CAAC;IA9HC,WAAW,CAAC,KAAkB,EAAE,KAA6B;QAC3D,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;QAC1B,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAE1B,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YAChC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;gBAClB,OAAO;aACR;YAED,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE;gBAC7B,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;oBACxB,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;oBAC/B,cAAc,EAAE,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,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7C,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;QACrD,OAAO,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED,cAAc,CAAC,KAA6B;QAC1C,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAC1B,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC;IAED,WAAW,CAAC,KAA6B,EAAE,OAAwB;QACjE,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,KAAK,OAAO,CAAC,CAAC;QACvF,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC;QAEnF,KAAK,CAAC,iBAAiB,CAAC,CAAC,GAAG,IAAI,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;IAC7E,CAAC;CACF;AAlID,oCAkIC","file":"filter-engine.js","sourcesContent":["import type { ListTable, PivotTable, TYPES } from '@visactor/vtable';\nimport type { FilterState, FilterOperator, FilterConfig } from './types';\n\n/**\n * 筛选引擎,用于进行实际的筛选操作\n */\nexport class FilterEngine {\n filterFuncRule: (TYPES.FilterFuncRule & { fieldId?: string })[] = [];\n filterValueRule: TYPES.FilterValueRule[] = [];\n\n applyFilter(state: FilterState, table: ListTable | PivotTable) {\n const { filters } = state;\n this.filterFuncRule = [];\n this.filterValueRule = [];\n\n filters.forEach((filter, field) => {\n if (!filter.enable) {\n return;\n }\n\n if (filter.type === 'byValue') {\n this.filterValueRule.push({\n filterKey: String(filter.field),\n filteredValues: filter.values\n });\n } else if (filter.type === 'byCondition') {\n // 为条件筛选生成过滤函数\n const filterFunc = this.createFilterFunction(filter);\n this.filterFuncRule.push({\n filterFunc,\n fieldId: String(filter.field)\n });\n }\n });\n\n table.updateFilterRules([...this.filterFuncRule, ...this.filterValueRule], {\n clearRowHeightCache: false\n });\n }\n\n /**\n * 根据筛选配置创建筛选函数\n */\n private createFilterFunction(filter: FilterConfig): (record: any) => boolean {\n const { field, operator, condition } = filter;\n\n // 如果没有操作符或条件,返回一个总是通过的函数\n if (!operator || condition === undefined) {\n return () => true;\n }\n\n return (record: any) => {\n const value = record[field];\n\n if (value === null || value === undefined) {\n return false;\n }\n\n // 根据操作符生成对应的比较逻辑\n switch (operator) {\n case 'equals':\n return this.compareValues(value, condition) === 0;\n case 'notEquals':\n return this.compareValues(value, condition) !== 0;\n case 'greaterThan':\n return this.compareValues(value, condition) > 0;\n case 'lessThan':\n return this.compareValues(value, condition) < 0;\n case 'greaterThanOrEqual':\n return this.compareValues(value, condition) >= 0;\n case 'lessThanOrEqual':\n return this.compareValues(value, condition) <= 0;\n case 'between':\n // 范围条件需要是数组形式 [min, max]\n if (Array.isArray(condition) && condition.length === 2) {\n return this.compareValues(value, condition[0]) >= 0 && this.compareValues(value, condition[1]) <= 0;\n }\n return true;\n case 'notBetween':\n // 范围条件需要是数组形式 [min, max]\n if (Array.isArray(condition) && condition.length === 2) {\n return this.compareValues(value, condition[0]) < 0 || this.compareValues(value, condition[1]) > 0;\n }\n return true;\n case 'contains':\n return String(value).toLowerCase().includes(String(condition).toLowerCase());\n case 'notContains':\n return !String(value).toLowerCase().includes(String(condition).toLowerCase());\n case 'startsWith':\n return String(value).toLowerCase().startsWith(String(condition).toLowerCase());\n case 'notStartsWith':\n return !String(value).toLowerCase().startsWith(String(condition).toLowerCase());\n case 'endsWith':\n return String(value).toLowerCase().endsWith(String(condition).toLowerCase());\n case 'notEndsWith':\n return !String(value).toLowerCase().endsWith(String(condition).toLowerCase());\n case 'isChecked':\n return Boolean(value) === true;\n case 'isUnchecked':\n return Boolean(value) === false;\n default:\n return true;\n }\n };\n }\n\n /**\n * 比较两个值\n * 返回: -1 (value < condition), 0 (value === condition), 1 (value > condition)\n */\n private compareValues(value: any, condition: any): number {\n if (typeof value === 'number' && typeof condition === 'number') {\n return value === condition ? 0 : value > condition ? 1 : -1;\n }\n\n if (typeof value === 'boolean' && typeof condition === 'boolean') {\n return value === condition ? 0 : -1;\n }\n\n const valueStr = String(value).toLowerCase();\n const conditionStr = String(condition).toLowerCase();\n return valueStr === conditionStr ? 0 : valueStr > conditionStr ? 1 : -1;\n }\n\n clearAllFilter(table: ListTable | PivotTable) {\n this.filterFuncRule = [];\n this.filterValueRule = [];\n table.updateFilterRules([]);\n }\n\n clearFilter(table: ListTable | PivotTable, fieldId: string | number) {\n this.filterValueRule = this.filterValueRule.filter(rule => rule.filterKey !== fieldId);\n this.filterFuncRule = this.filterFuncRule.filter(rule => rule.fieldId !== fieldId);\n\n table.updateFilterRules([...this.filterFuncRule, ...this.filterValueRule]);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/filter/filter-engine.ts"],"names":[],"mappings":";;;AAMA,MAAa,YAAY;IAMvB,YAAY,mBAAkC;QAL9C,mBAAc,GAAoD,EAAE,CAAC;QACrE,oBAAe,GAA4B,EAAE,CAAC;QAK5C,IAAI,CAAC,aAAa,GAAG,mBAAmB,CAAC;IAC3C,CAAC;IAED,WAAW,CAAC,KAAkB,EAAE,KAA6B;;QAC3D,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;QAC1B,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAE1B,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YACh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CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,KAAK,OAAO,CAAC,CAAC;QACvF,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC;QAEnF,KAAK,CAAC,iBAAiB,CAAC,CAAC,GAAG,IAAI,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;IAC7E,CAAC;CACF;AA/ID,oCA+IC","file":"filter-engine.js","sourcesContent":["import type { ListTable, PivotTable, TYPES } from '@visactor/vtable';\nimport type { FilterState, FilterConfig, FilterOptions } from './types';\n\n/**\n * 筛选引擎,用于进行实际的筛选操作\n */\nexport class FilterEngine {\n filterFuncRule: (TYPES.FilterFuncRule & { fieldId?: string })[] = [];\n filterValueRule: TYPES.FilterValueRule[] = [];\n\n private pluginOptions: FilterOptions;\n\n constructor(filterPluginOptions: FilterOptions) {\n this.pluginOptions = filterPluginOptions;\n }\n\n applyFilter(state: FilterState, table: ListTable | PivotTable) {\n const { filters } = state;\n this.filterFuncRule = [];\n this.filterValueRule = [];\n\n filters.forEach((filter, field) => {\n if (!filter.enable) {\n return;\n }\n\n if (filter.type === 'byValue') {\n this.filterValueRule.push({\n filterKey: String(filter.field),\n filteredValues: filter.values\n });\n } else if (filter.type === 'byCondition') {\n // 为条件筛选生成过滤函数\n const filterFunc = this.createFilterFunction(filter);\n this.filterFuncRule.push({\n filterFunc,\n fieldId: String(filter.field)\n });\n }\n });\n\n table.updateFilterRules([...this.filterFuncRule, ...this.filterValueRule], {\n clearRowHeightCache: false,\n onFilterRecordsEnd: this.pluginOptions?.onFilterRecordsEnd\n });\n }\n\n /**\n * 根据筛选配置创建筛选函数\n */\n private createFilterFunction(filter: FilterConfig): (record: any) => boolean {\n const { field, operator, condition } = filter;\n\n // 如果没有操作符或条件,返回一个总是通过的函数\n if (!operator || condition === undefined) {\n return () => true;\n }\n\n return (record: any) => {\n const value = record[field];\n\n if (value === null || value === undefined) {\n return false;\n }\n\n // 根据操作符生成对应的比较逻辑\n switch (operator) {\n case 'equals':\n return this.compareValues(value, condition) === 0;\n case 'notEquals':\n return this.compareValues(value, condition) !== 0;\n case 'greaterThan':\n return this.compareValues(value, condition) > 0;\n case 'lessThan':\n return this.compareValues(value, condition) < 0;\n case 'greaterThanOrEqual':\n return this.compareValues(value, condition) >= 0;\n case 'lessThanOrEqual':\n return this.compareValues(value, condition) <= 0;\n case 'between':\n // 范围条件需要是数组形式 [min, max]\n if (Array.isArray(condition) && condition.length === 2) {\n return this.compareValues(value, condition[0]) >= 0 && this.compareValues(value, condition[1]) <= 0;\n }\n return true;\n case 'notBetween':\n // 范围条件需要是数组形式 [min, max]\n if (Array.isArray(condition) && condition.length === 2) {\n return this.compareValues(value, condition[0]) < 0 || this.compareValues(value, condition[1]) > 0;\n }\n return true;\n case 'contains':\n return String(value).toLowerCase().includes(String(condition).toLowerCase());\n case 'notContains':\n return !String(value).toLowerCase().includes(String(condition).toLowerCase());\n case 'startsWith':\n return String(value).toLowerCase().startsWith(String(condition).toLowerCase());\n case 'notStartsWith':\n return !String(value).toLowerCase().startsWith(String(condition).toLowerCase());\n case 'endsWith':\n return String(value).toLowerCase().endsWith(String(condition).toLowerCase());\n case 'notEndsWith':\n return !String(value).toLowerCase().endsWith(String(condition).toLowerCase());\n case 'isChecked':\n return Boolean(value) === true;\n case 'isUnchecked':\n return Boolean(value) === false;\n default:\n return true;\n }\n };\n }\n\n /**\n * 比较两个值\n * 返回: -1 (value < condition), 0 (value === condition), 1 (value > condition)\n */\n private compareValues(value: any, condition: any): number {\n if (typeof value === 'number' && typeof condition === 'number') {\n return value === condition ? 0 : value > condition ? 1 : -1;\n }\n\n if (typeof value === 'boolean' && typeof condition === 'boolean') {\n return value === condition ? 0 : -1;\n }\n\n // 进入字符串比较\n const valueStr = String(value).toLowerCase();\n const conditionStr = String(condition).toLowerCase();\n\n // 如果两个字符串都能正确转换成数字, 则仍然按数字比较\n if (!isNaN(Number(valueStr)) && !isNaN(Number(conditionStr))) {\n return Number(valueStr) === Number(conditionStr) ? 0 : Number(valueStr) > Number(conditionStr) ? 1 : -1;\n }\n return valueStr === conditionStr ? 0 : valueStr > conditionStr ? 1 : -1;\n }\n\n clearAllFilter(table: ListTable | PivotTable) {\n this.filterFuncRule = [];\n this.filterValueRule = [];\n table.updateFilterRules([]);\n }\n\n clearFilter(table: ListTable | PivotTable, fieldId: string | number) {\n this.filterValueRule = this.filterValueRule.filter(rule => rule.filterKey !== fieldId);\n this.filterFuncRule = this.filterFuncRule.filter(rule => rule.fieldId !== fieldId);\n\n table.updateFilterRules([...this.filterFuncRule, ...this.filterValueRule]);\n }\n}\n"]}
@@ -43,11 +43,17 @@ class FilterStateManager {
43
43
  const {type: type, payload: payload} = action, newFilter = new Map(state.filters);
44
44
  switch (type) {
45
45
  case types_1.FilterActionType.ADD_FILTER:
46
- newFilter.set(payload.field, payload);
46
+ payload.shouldKeepUnrelatedState ? newFilter.set(payload.field, Object.assign(Object.assign({}, newFilter.get(payload.field)), payload)) : newFilter.set(payload.field, payload);
47
47
  break;
48
48
 
49
49
  case types_1.FilterActionType.REMOVE_FILTER:
50
- newFilter.delete(payload.field);
50
+ payload.shouldKeepUnrelatedState && "byValue" === payload.type ? (delete newFilter.get(payload.field).values,
51
+ newFilter.set(payload.field, Object.assign(Object.assign({}, newFilter.get(payload.field)), {
52
+ enable: !1
53
+ }))) : payload.shouldKeepUnrelatedState && "byCondition" === payload.type ? (delete newFilter.get(payload.field).condition,
54
+ delete newFilter.get(payload.field).operator, newFilter.set(payload.field, Object.assign(Object.assign({}, newFilter.get(payload.field)), {
55
+ enable: !1
56
+ }))) : newFilter.delete(payload.field);
51
57
  break;
52
58
 
53
59
  case types_1.FilterActionType.UPDATE_FILTER:
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/filter/filter-state-manager.ts"],"names":[],"mappings":";;;AAEA,mCAA2C;AAM3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CAAC,KAAK,kCAAO,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,KAAE,MAAM,EAAE,KAAK,IAAG,CAAC;gBACjF,MAAM;YACR,KAAK,wBAAgB,CAAC,iBAAiB;gBACrC,SAAS,CAAC,KAAK,EAAE,CAAC;gBAClB,MAAM;YACR,KAAK,wBAAgB,CAAC,aAAa;gBACjC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,gDAAO,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAK,OAAO,KAAE,MAAM,EAAE,IAAI,IAAG,CAAC;gBAC5F,MAAM;SACT;QAED,uCAAY,KAAK,KAAE,OAAO,EAAE,SAAS,IAAG;IAC1C,CAAC;IAEO,YAAY;QAClB,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;IAEO,iBAAiB,CAAC,MAAoB;QAC5C,MAAM,kBAAkB,GAAG;YACzB,wBAAgB,CAAC,aAAa;YAC9B,wBAAgB,CAAC,aAAa;YAC9B,wBAAgB,CAAC,cAAc;YAC/B,wBAAgB,CAAC,iBAAiB;YAClC,wBAAgB,CAAC,aAAa;SAC/B,CAAC;QACF,OAAO,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;CACF;AAjHD,gDAiHC","file":"filter-state-manager.js","sourcesContent":["import type { ListTable, PivotTable } from '@visactor/vtable';\nimport type { FilterState, FilterAction, FilterConfig, FilterListener } from './types';\nimport { FilterActionType } from './types';\nimport type { FilterEngine } from './filter-engine';\n\n/**\n * 筛选状态管理器,用于管理筛选状态\n */\nexport class FilterStateManager {\n private state: FilterState;\n private engine: FilterEngine;\n private listeners: Array<FilterListener> = [];\n\n private table: ListTable | PivotTable;\n\n constructor(table: ListTable | PivotTable, engine: FilterEngine) {\n this.state = {\n filters: new Map()\n };\n this.engine = engine;\n this.table = table;\n }\n\n getFilterState(fieldId?: string | number): FilterConfig {\n return this.state.filters.get(fieldId);\n }\n\n /**\n * 获取所有激活的筛选字段\n */\n getActiveFilterFields(): (string | number)[] {\n const activeFields: (string | number)[] = [];\n this.state.filters.forEach((config, field) => {\n if (config.enable) {\n activeFields.push(field);\n }\n });\n return activeFields;\n }\n\n /**\n * 获取所有筛选状态\n */\n getAllFilterStates(): FilterState {\n return this.state;\n }\n\n /**\n * 公共方法:重新应用当前所有激活的筛选状态\n * 用于在表格配置更新后恢复筛选显示\n */\n reapplyCurrentFilters(): void {\n const activeFields = this.getActiveFilterFields();\n if (activeFields.length > 0) {\n this.applyFilters();\n }\n }\n\n dispatch(action: FilterAction) {\n this.state = this.reduce(this.state, action);\n if (this.shouldApplyFilter(action)) {\n this.applyFilters();\n }\n this.notifyListeners(action);\n }\n\n subscribe(listener: FilterListener): () => void {\n this.listeners.push(listener);\n return () => {\n this.listeners = this.listeners.filter(l => l !== listener);\n };\n }\n\n private notifyListeners(action: FilterAction): void {\n this.listeners.forEach(listener => listener(this.state, action));\n }\n\n private reduce(state: FilterState, action: FilterAction): FilterState {\n const { type, payload } = action;\n const newFilter = new Map(state.filters);\n switch (type) {\n case FilterActionType.ADD_FILTER:\n newFilter.set(payload.field, payload);\n break;\n case FilterActionType.REMOVE_FILTER:\n newFilter.delete(payload.field);\n break;\n case FilterActionType.UPDATE_FILTER:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), ...payload });\n break;\n case FilterActionType.ENABLE_FILTER:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), enable: true });\n break;\n case FilterActionType.DISABLE_FILTER:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), enable: false });\n break;\n case FilterActionType.CLEAR_ALL_FILTERS:\n newFilter.clear();\n break;\n case FilterActionType.APPLY_FILTERS:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), ...payload, enable: true });\n break;\n }\n\n return { ...state, filters: newFilter };\n }\n\n private applyFilters() {\n this.engine.applyFilter(this.state, this.table);\n }\n\n private shouldApplyFilter(action: FilterAction) {\n const shouldApplyActions = [\n FilterActionType.REMOVE_FILTER,\n FilterActionType.ENABLE_FILTER,\n FilterActionType.DISABLE_FILTER,\n FilterActionType.CLEAR_ALL_FILTERS,\n FilterActionType.APPLY_FILTERS\n ];\n return shouldApplyActions.includes(action.type);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/filter/filter-state-manager.ts"],"names":[],"mappings":";;;AAEA,mCAA2C;AAM3C,MAAa,kBAAkB;IAO7B,YAAY,KAA6B,EAAE,MAAoB;QAJvD,cAAS,GAA0B,EAAE,CAAC;QAK5C,IAAI,CAAC,KAAK,GAAG;YACX,OAAO,EAAE,IAAI,GAAG,EAAE;SACnB,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,cAAc,CAAC,OAAyB;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAKD,qBAAqB;QACnB,MAAM,YAAY,GAAwB,EAAE,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YAC3C,IAAI,MAAM,CAAC,MAAM,EAAE;gBACjB,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aAC1B;QACH,CAAC,CAAC,CAAC;QACH,OAAO,YAAY,CAAC;IACtB,CAAC;IAKD,kBAAkB;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAMD,qBAAqB;QACnB,MAAM,YAAY,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAClD,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;YAC3B,IAAI,CAAC,YAAY,EAAE,CAAC;SACrB;IACH,CAAC;IAED,QAAQ,CAAC,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AAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,KAAE,MAAM,EAAE,KAAK,IAAG,CAAC;gBACjF,MAAM;YACR,KAAK,wBAAgB,CAAC,iBAAiB;gBACrC,SAAS,CAAC,KAAK,EAAE,CAAC;gBAClB,MAAM;YACR,KAAK,wBAAgB,CAAC,aAAa;gBACjC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,gDAAO,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAK,OAAO,KAAE,MAAM,EAAE,IAAI,IAAG,CAAC;gBAC5F,MAAM;SACT;QAED,uCAAY,KAAK,KAAE,OAAO,EAAE,SAAS,IAAG;IAC1C,CAAC;IAEO,YAAY;QAClB,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;IAEO,iBAAiB,CAAC,MAAoB;QAC5C,MAAM,kBAAkB,GAAG;YACzB,wBAAgB,CAAC,aAAa;YAC9B,wBAAgB,CAAC,aAAa;YAC9B,wBAAgB,CAAC,cAAc;YAC/B,wBAAgB,CAAC,iBAAiB;YAClC,wBAAgB,CAAC,aAAa;SAC/B,CAAC;QACF,OAAO,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;CACF;AA/HD,gDA+HC","file":"filter-state-manager.js","sourcesContent":["import type { ListTable, PivotTable } from '@visactor/vtable';\nimport type { FilterState, FilterAction, FilterConfig, FilterListener } from './types';\nimport { FilterActionType } from './types';\nimport type { FilterEngine } from './filter-engine';\n\n/**\n * 筛选状态管理器,用于管理筛选状态\n */\nexport class FilterStateManager {\n private state: FilterState;\n private engine: FilterEngine;\n private listeners: Array<FilterListener> = [];\n\n private table: ListTable | PivotTable;\n\n constructor(table: ListTable | PivotTable, engine: FilterEngine) {\n this.state = {\n filters: new Map()\n };\n this.engine = engine;\n this.table = table;\n }\n\n getFilterState(fieldId?: string | number): FilterConfig {\n return this.state.filters.get(fieldId);\n }\n\n /**\n * 获取所有激活的筛选字段\n */\n getActiveFilterFields(): (string | number)[] {\n const activeFields: (string | number)[] = [];\n this.state.filters.forEach((config, field) => {\n if (config.enable) {\n activeFields.push(field);\n }\n });\n return activeFields;\n }\n\n /**\n * 获取所有筛选状态\n */\n getAllFilterStates(): FilterState {\n return this.state;\n }\n\n /**\n * 公共方法:重新应用当前所有激活的筛选状态\n * 用于在表格配置更新后恢复筛选显示\n */\n reapplyCurrentFilters(): void {\n const activeFields = this.getActiveFilterFields();\n if (activeFields.length > 0) {\n this.applyFilters();\n }\n }\n\n dispatch(action: FilterAction) {\n this.state = this.reduce(this.state, action);\n if (this.shouldApplyFilter(action)) {\n this.applyFilters();\n }\n this.notifyListeners(action);\n }\n\n subscribe(listener: FilterListener): () => void {\n this.listeners.push(listener);\n return () => {\n this.listeners = this.listeners.filter(l => l !== listener);\n };\n }\n\n private notifyListeners(action: FilterAction): void {\n this.listeners.forEach(listener => listener(this.state, action));\n }\n\n private reduce(state: FilterState, action: FilterAction): FilterState {\n const { type, payload } = action;\n const newFilter = new Map(state.filters);\n switch (type) {\n case FilterActionType.ADD_FILTER:\n if (payload.shouldKeepUnrelatedState) {\n newFilter.set(payload.field, { ...newFilter.get(payload.field), ...payload });\n } else {\n newFilter.set(payload.field, payload);\n }\n break;\n case FilterActionType.REMOVE_FILTER:\n if (payload.shouldKeepUnrelatedState && payload.type === 'byValue') {\n delete newFilter.get(payload.field).values;\n newFilter.set(payload.field, { ...newFilter.get(payload.field), enable: false });\n } else if (payload.shouldKeepUnrelatedState && payload.type === 'byCondition') {\n delete newFilter.get(payload.field).condition;\n delete newFilter.get(payload.field).operator;\n newFilter.set(payload.field, { ...newFilter.get(payload.field), enable: false });\n } else {\n newFilter.delete(payload.field);\n }\n\n break;\n case FilterActionType.UPDATE_FILTER:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), ...payload });\n break;\n case FilterActionType.ENABLE_FILTER:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), enable: true });\n break;\n case FilterActionType.DISABLE_FILTER:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), enable: false });\n break;\n case FilterActionType.CLEAR_ALL_FILTERS:\n newFilter.clear();\n break;\n case FilterActionType.APPLY_FILTERS:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), ...payload, enable: true });\n break;\n }\n\n return { ...state, filters: newFilter };\n }\n\n private applyFilters() {\n this.engine.applyFilter(this.state, this.table);\n }\n\n private shouldApplyFilter(action: FilterAction) {\n const shouldApplyActions = [\n FilterActionType.REMOVE_FILTER,\n FilterActionType.ENABLE_FILTER,\n FilterActionType.DISABLE_FILTER,\n FilterActionType.CLEAR_ALL_FILTERS,\n FilterActionType.APPLY_FILTERS\n ];\n return shouldApplyActions.includes(action.type);\n }\n}\n"]}
@@ -1,11 +1,12 @@
1
- import type { ListTable, PivotTable } from '@visactor/vtable';
1
+ import { type ListTable, type PivotTable } from '@visactor/vtable';
2
2
  import type { FilterStateManager } from './filter-state-manager';
3
3
  import { ValueFilter } from './value-filter';
4
4
  import { ConditionFilter } from './condition-filter';
5
- import type { FilterMode } from './types';
5
+ import type { FilterMode, FilterOptions, FilterStyles } from './types';
6
6
  export declare class FilterToolbar {
7
7
  table: ListTable | PivotTable;
8
8
  filterStateManager: FilterStateManager;
9
+ pluginOptions: FilterOptions;
9
10
  valueFilter: ValueFilter | null;
10
11
  conditionFilter: ConditionFilter | null;
11
12
  activeTab: 'byValue' | 'byCondition';
@@ -13,23 +14,27 @@ export declare class FilterToolbar {
13
14
  selectedField: string | number | null;
14
15
  filterModes: FilterMode[];
15
16
  private filterMenu;
17
+ private filterTabsContainer;
16
18
  private filterMenuWidth;
17
19
  private currentCol?;
18
20
  private currentRow?;
19
21
  private filterTabByValue;
20
22
  private filterTabByCondition;
23
+ private footerContainer;
21
24
  private clearFilterOptionLink;
22
25
  private cancelFilterButton;
23
26
  private applyFilterButton;
24
- constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager);
27
+ constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager, pluginOptions: FilterOptions);
25
28
  private onTabSwitch;
26
29
  private updateSelectedField;
27
30
  private applyFilter;
28
31
  private clearFilter;
29
32
  private updateClearFilterButtonState;
30
33
  render(container: HTMLElement): void;
34
+ updateStyles(styles: FilterStyles): void;
31
35
  attachEventListeners(): void;
32
36
  adjustMenuPosition(col?: number | null, row?: number | null, providedLeft?: number | null, providedTop?: number | null): void;
33
37
  show(col: number, row: number, filterModes: FilterMode[]): void;
34
- hide(): void;
38
+ hide: (currentCol?: number, currentRow?: number) => void;
39
+ destroy(): void;
35
40
  }
@@ -4,15 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  }), exports.FilterToolbar = void 0;
6
6
 
7
- const value_filter_1 = require("./value-filter"), condition_filter_1 = require("./condition-filter"), styles_1 = require("./styles");
7
+ const vtable_1 = require("@visactor/vtable"), value_filter_1 = require("./value-filter"), condition_filter_1 = require("./condition-filter"), styles_1 = require("./styles");
8
8
 
9
9
  class FilterToolbar {
10
- constructor(table, filterStateManager) {
10
+ constructor(table, filterStateManager, pluginOptions) {
11
11
  this.valueFilter = null, this.conditionFilter = null, this.activeTab = "byValue",
12
- this.isVisible = !1, this.selectedField = null, this.filterModes = [], this.table = table,
13
- this.filterStateManager = filterStateManager, this.valueFilter = new value_filter_1.ValueFilter(this.table, this.filterStateManager),
14
- this.conditionFilter = new condition_filter_1.ConditionFilter(this.table, this.filterStateManager),
15
- this.filterMenuWidth = 300, this.filterStateManager.subscribe((state => {
12
+ this.isVisible = !1, this.selectedField = null, this.filterModes = [], this.hide = (currentCol, currentRow) => {
13
+ this.filterMenu.style.display = "none", this.isVisible = !1, this.table.fireListeners(vtable_1.TABLE_EVENT_TYPE.FILTER_MENU_HIDE, {
14
+ col: null != currentCol ? currentCol : this.currentCol,
15
+ row: null != currentRow ? currentRow : this.currentRow
16
+ });
17
+ }, this.table = table, this.filterStateManager = filterStateManager, this.valueFilter = new value_filter_1.ValueFilter(this.table, this.filterStateManager, pluginOptions),
18
+ this.conditionFilter = new condition_filter_1.ConditionFilter(this.table, this.filterStateManager, pluginOptions, this.hide),
19
+ this.pluginOptions = pluginOptions, this.filterMenuWidth = 300, this.filterStateManager.subscribe((state => {
16
20
  this.isVisible && null !== this.selectedField && this.updateClearFilterButtonState(this.selectedField);
17
21
  }));
18
22
  }
@@ -42,29 +46,38 @@ class FilterToolbar {
42
46
  this.clearFilterOptionLink.style.cursor = hasActiveFilter ? "pointer" : "not-allowed";
43
47
  }
44
48
  render(container) {
45
- this.filterMenu = document.createElement("div"), (0, styles_1.applyStyles)(this.filterMenu, styles_1.filterStyles.filterMenu),
46
- this.filterMenu.style.width = `${this.filterMenuWidth}px`;
47
- const filterTabsContainer = document.createElement("div");
48
- (0, styles_1.applyStyles)(filterTabsContainer, styles_1.filterStyles.tabsContainer),
49
+ const filterStyles = this.pluginOptions.styles || {};
50
+ this.filterMenu = document.createElement("div"), this.filterMenu.classList.add("vtable-filter-menu"),
51
+ (0, styles_1.applyStyles)(this.filterMenu, filterStyles.filterMenu), this.filterMenu.style.width = `${this.filterMenuWidth}px`,
52
+ this.filterTabsContainer = document.createElement("div"), (0, styles_1.applyStyles)(this.filterTabsContainer, filterStyles.tabsContainer),
49
53
  this.filterTabByValue = document.createElement("button"), this.filterTabByValue.innerText = "按值筛选",
50
- (0, styles_1.applyStyles)(this.filterTabByValue, styles_1.filterStyles.tabStyle(!0)),
51
- this.filterTabByCondition = document.createElement("button"), this.filterTabByCondition.innerText = "按条件筛选",
52
- (0, styles_1.applyStyles)(this.filterTabByCondition, styles_1.filterStyles.tabStyle(!1)),
53
- filterTabsContainer.append(this.filterTabByValue, this.filterTabByCondition);
54
- const footerContainer = document.createElement("div");
55
- (0, styles_1.applyStyles)(footerContainer, styles_1.filterStyles.footerContainer),
54
+ (0, styles_1.applyStyles)(this.filterTabByValue, filterStyles.tabStyle(!0)), this.filterTabByCondition = document.createElement("button"),
55
+ this.filterTabByCondition.innerText = "按条件筛选", (0, styles_1.applyStyles)(this.filterTabByCondition, filterStyles.tabStyle(!1)),
56
+ this.filterTabsContainer.append(this.filterTabByValue, this.filterTabByCondition),
57
+ this.footerContainer = document.createElement("div"), (0, styles_1.applyStyles)(this.footerContainer, filterStyles.footerContainer),
56
58
  this.clearFilterOptionLink = document.createElement("a"), this.clearFilterOptionLink.href = "#",
57
- this.clearFilterOptionLink.innerText = "清除筛选", (0, styles_1.applyStyles)(this.clearFilterOptionLink, styles_1.filterStyles.clearLink);
59
+ this.clearFilterOptionLink.innerText = "清除筛选", (0, styles_1.applyStyles)(this.clearFilterOptionLink, filterStyles.clearLink);
58
60
  const footerButtons = document.createElement("div");
59
61
  this.cancelFilterButton = document.createElement("button"), this.cancelFilterButton.innerText = "取消",
60
- (0, styles_1.applyStyles)(this.cancelFilterButton, styles_1.filterStyles.footerButton(!1)),
62
+ (0, styles_1.applyStyles)(this.cancelFilterButton, filterStyles.footerButton(!1)),
61
63
  this.applyFilterButton = document.createElement("button"), this.applyFilterButton.innerText = "确认",
62
- (0, styles_1.applyStyles)(this.applyFilterButton, styles_1.filterStyles.footerButton(!0)),
63
- footerButtons.append(this.cancelFilterButton, this.applyFilterButton), footerContainer.append(this.clearFilterOptionLink, footerButtons),
64
- this.filterMenu.append(filterTabsContainer), this.valueFilter.render(this.filterMenu),
65
- this.conditionFilter.render(this.filterMenu), this.filterMenu.append(footerContainer),
64
+ (0, styles_1.applyStyles)(this.applyFilterButton, filterStyles.footerButton(!0)),
65
+ footerButtons.append(this.cancelFilterButton, this.applyFilterButton), this.footerContainer.append(this.clearFilterOptionLink, footerButtons),
66
+ this.filterMenu.append(this.filterTabsContainer), this.valueFilter.render(this.filterMenu),
67
+ this.conditionFilter.render(this.filterMenu), this.filterMenu.append(this.footerContainer),
66
68
  container.appendChild(this.filterMenu), this.attachEventListeners();
67
69
  }
70
+ updateStyles(styles) {
71
+ var _a;
72
+ const realDisplay = (null !== (_a = this.filterMenu.style.display) && void 0 !== _a ? _a : styles.filterMenu.display) || "none";
73
+ (0, styles_1.applyStyles)(this.filterMenu, Object.assign(Object.assign({}, styles.filterMenu), {
74
+ display: realDisplay
75
+ })), (0, styles_1.applyStyles)(this.filterTabsContainer, styles.tabsContainer),
76
+ (0, styles_1.applyStyles)(this.filterTabByValue, styles.tabStyle(!0)), (0, styles_1.applyStyles)(this.footerContainer, styles.footerContainer),
77
+ (0, styles_1.applyStyles)(this.clearFilterOptionLink, styles.clearLink), (0, styles_1.applyStyles)(this.cancelFilterButton, styles.footerButton(!1)),
78
+ (0, styles_1.applyStyles)(this.applyFilterButton, styles.footerButton(!0)), this.valueFilter.updateStyles(styles),
79
+ this.conditionFilter.updateStyles(styles);
80
+ }
68
81
  attachEventListeners() {
69
82
  this.filterTabByValue.addEventListener("click", (() => {
70
83
  this.onTabSwitch("byValue");
@@ -87,9 +100,10 @@ class FilterToolbar {
87
100
  if ("number" != typeof effectiveCol || "number" != typeof effectiveRow) return;
88
101
  this.currentCol = effectiveCol, this.currentRow = effectiveRow;
89
102
  let left = 0, top = 0;
90
- const canvasBounds = this.table.canvas.getBoundingClientRect(), cell = this.table.getCellRelativeRect(effectiveCol, effectiveRow);
103
+ const canvasBounds = this.table.canvas.getBoundingClientRect(), cell = this.table.getCellRelativeRect(effectiveCol, effectiveRow), filterMenuWidth = this.filterMenuWidth;
91
104
  cell.right < this.filterMenuWidth ? (left = cell.left + canvasBounds.left, top = cell.bottom + canvasBounds.top) : (left = cell.right + canvasBounds.left - this.filterMenuWidth,
92
- top = cell.bottom + canvasBounds.top), this.filterMenu.style.display = this.isVisible ? "block" : "none",
105
+ top = cell.bottom + canvasBounds.top), left = Math.max(0, Math.min(window.innerWidth - filterMenuWidth, left)),
106
+ top = Math.max(0, Math.min(window.innerHeight - 380, top)), this.filterMenu.style.display = this.isVisible ? "block" : "none",
93
107
  this.filterMenu.style.left = `${left}px`, this.filterMenu.style.top = `${top}px`;
94
108
  }
95
109
  show(col, row, filterModes) {
@@ -101,11 +115,14 @@ class FilterToolbar {
101
115
  const currentFilter = this.filterStateManager.getFilterState(field);
102
116
  currentFilter && "byCondition" === currentFilter.type ? this.onTabSwitch("byCondition") : this.onTabSwitch("byValue"),
103
117
  this.updateClearFilterButtonState(field), setTimeout((() => {
104
- this.isVisible = !0;
118
+ this.isVisible = !0, this.table.fireListeners(vtable_1.TABLE_EVENT_TYPE.FILTER_MENU_SHOW, {
119
+ col: col,
120
+ row: row
121
+ });
105
122
  }), 0);
106
123
  }
107
- hide() {
108
- this.filterMenu.style.display = "none", this.isVisible = !1;
124
+ destroy() {
125
+ this.valueFilter.destroy(), this.filterMenu.remove();
109
126
  }
110
127
  }
111
128
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/filter/filter-toolbar.ts"],"names":[],"mappings":";;;AAEA,iDAA6C;AAC7C,yDAAqD;AACrD,qCAAqD;AAMrD,MAAa,aAAa;IAoBxB,YAAY,KAA6B,EAAE,kBAAsC;QAjBjF,gBAAW,GAAuB,IAAI,CAAC;QACvC,oBAAe,GAA2B,IAAI,CAAC;QAC/C,cAAS,GAA8B,SAAS,CAAC;QACjD,cAAS,GAAY,KAAK,CAAC;QAC3B,kBAAa,GAA2B,IAAI,CAAC;QAC7C,gBAAW,GAAiB,EAAE,CAAC;QAa7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC7C,IAAI,CAAC,WAAW,GAAG,IAAI,0BAAW,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACxE,IAAI,CAAC,eAAe,GAAG,IAAI,kCAAe,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAEhF,IAAI,CAAC,eAAe,GAAG,GAAG,CAAC;QAG3B,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,KAAK,CAA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C,CAAC;SAC7B;QAGD,IAAI,CAAC,4BAA4B,CAAC,KAAK,CAAC,CAAC;QAGzC,UAAU,CAAC,GAAG,EAAE;YACd,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACxB,CAAC,EAAE,CAAC,CAAC,CAAC;IACR,CAAC;IAED,IAAI;QACF,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;QACvC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IACzB,CAAC;CACF;AAzQD,sCAyQC","file":"filter-toolbar.js","sourcesContent":["import type { ListTable, PivotTable } from '@visactor/vtable';\nimport type { FilterStateManager } from './filter-state-manager';\nimport { ValueFilter } from './value-filter';\nimport { ConditionFilter } from './condition-filter';\nimport { applyStyles, filterStyles } from './styles';\nimport type { FilterMode } from './types';\n\n/**\n * 筛选工具栏,管理按值和按条件筛选组件\n */\nexport class FilterToolbar {\n table: ListTable | PivotTable;\n filterStateManager: FilterStateManager;\n valueFilter: ValueFilter | null = null;\n conditionFilter: ConditionFilter | null = null;\n activeTab: 'byValue' | 'byCondition' = 'byValue';\n isVisible: boolean = false;\n selectedField: string | number | null = null;\n filterModes: FilterMode[] = [];\n\n private filterMenu: HTMLElement;\n private filterMenuWidth: number;\n private currentCol?: number | null;\n private currentRow?: number | null;\n private filterTabByValue: HTMLButtonElement;\n private filterTabByCondition: HTMLButtonElement;\n private clearFilterOptionLink: HTMLAnchorElement;\n private cancelFilterButton: HTMLButtonElement;\n private applyFilterButton: HTMLButtonElement;\n\n constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager) {\n this.table = table;\n this.filterStateManager = filterStateManager;\n this.valueFilter = new ValueFilter(this.table, this.filterStateManager);\n this.conditionFilter = new ConditionFilter(this.table, this.filterStateManager);\n\n this.filterMenuWidth = 300; // 待优化,可能需要自适应内容的宽度\n\n // 监听筛选状态变化,更新清除筛选按钮状态\n this.filterStateManager.subscribe(state => {\n if (this.isVisible && this.selectedField !== null) {\n this.updateClearFilterButtonState(this.selectedField);\n }\n });\n }\n\n private onTabSwitch(tab: 'byValue' | 'byCondition'): void {\n this.activeTab = tab;\n if (tab === 'byValue') {\n this.valueFilter.show();\n this.conditionFilter.hide();\n } else {\n this.conditionFilter.show();\n this.valueFilter.hide();\n }\n\n const isValueTab = tab === 'byValue';\n applyStyles(this.filterTabByValue, filterStyles.tabStyle(isValueTab));\n applyStyles(this.filterTabByCondition, filterStyles.tabStyle(!isValueTab));\n }\n\n private updateSelectedField(field: string | number): void {\n this.selectedField = field;\n // 通知筛选组件更新选中字段\n if (this.valueFilter) {\n this.valueFilter.setSelectedField(field);\n }\n if (this.conditionFilter) {\n this.conditionFilter.setSelectedField(field);\n }\n }\n\n private applyFilter(field: string | number): void {\n if (this.activeTab === 'byValue') {\n this.valueFilter.applyFilter(field);\n } else if (this.activeTab === 'byCondition') {\n this.conditionFilter.applyFilter(field);\n }\n this.hide();\n }\n\n private clearFilter(field: string | number): void {\n if (this.valueFilter) {\n this.valueFilter.clearFilter(field);\n }\n if (this.conditionFilter) {\n this.conditionFilter.clearFilter(field);\n }\n this.hide();\n }\n\n /**\n * 更新清除筛选按钮的状态\n */\n private updateClearFilterButtonState(field: string | number): void {\n const currentFilter = this.filterStateManager.getFilterState(field);\n const hasActiveFilter = currentFilter && currentFilter.enable;\n\n this.clearFilterOptionLink.style.display = 'inline';\n this.clearFilterOptionLink.style.opacity = hasActiveFilter ? '1' : '0.5';\n this.clearFilterOptionLink.style.pointerEvents = hasActiveFilter ? 'auto' : 'none';\n this.clearFilterOptionLink.style.cursor = hasActiveFilter ? 'pointer' : 'not-allowed';\n }\n\n render(container: HTMLElement): void {\n // === 主容器 ===\n this.filterMenu = document.createElement('div');\n applyStyles(this.filterMenu, filterStyles.filterMenu);\n this.filterMenu.style.width = `${this.filterMenuWidth}px`;\n\n // === 筛选 Tab ===\n const filterTabsContainer = document.createElement('div');\n applyStyles(filterTabsContainer, filterStyles.tabsContainer);\n\n this.filterTabByValue = document.createElement('button');\n this.filterTabByValue.innerText = '按值筛选';\n applyStyles(this.filterTabByValue, filterStyles.tabStyle(true));\n\n this.filterTabByCondition = document.createElement('button');\n this.filterTabByCondition.innerText = '按条件筛选';\n applyStyles(this.filterTabByCondition, filterStyles.tabStyle(false));\n\n filterTabsContainer.append(this.filterTabByValue, this.filterTabByCondition);\n\n // === 页脚(清除、取消、确定 筛选按钮) ===\n const footerContainer = document.createElement('div');\n applyStyles(footerContainer, filterStyles.footerContainer);\n\n this.clearFilterOptionLink = document.createElement('a');\n this.clearFilterOptionLink.href = '#';\n this.clearFilterOptionLink.innerText = '清除筛选';\n applyStyles(this.clearFilterOptionLink, filterStyles.clearLink);\n\n const footerButtons = document.createElement('div');\n this.cancelFilterButton = document.createElement('button');\n this.cancelFilterButton.innerText = '取消';\n applyStyles(this.cancelFilterButton, filterStyles.footerButton(false));\n\n this.applyFilterButton = document.createElement('button');\n this.applyFilterButton.innerText = '确认';\n applyStyles(this.applyFilterButton, filterStyles.footerButton(true));\n\n footerButtons.append(this.cancelFilterButton, this.applyFilterButton);\n footerContainer.append(this.clearFilterOptionLink, footerButtons);\n\n // --- 筛选器头部 Tab ---\n this.filterMenu.append(filterTabsContainer);\n\n // --- 筛选器内容 ---\n this.valueFilter.render(this.filterMenu);\n this.conditionFilter.render(this.filterMenu);\n\n // --- 筛选器页脚 ---\n this.filterMenu.append(footerContainer);\n\n container.appendChild(this.filterMenu); // 将筛选器添加到 DOM 中\n this.attachEventListeners();\n }\n\n attachEventListeners() {\n // 按值筛选/按条件筛选的事件监听\n this.filterTabByValue.addEventListener('click', () => {\n this.onTabSwitch('byValue');\n });\n\n this.filterTabByCondition.addEventListener('click', () => {\n this.onTabSwitch('byCondition');\n });\n\n this.cancelFilterButton.addEventListener('click', () => this.hide());\n\n this.clearFilterOptionLink.addEventListener('click', e => {\n e.preventDefault();\n this.clearFilter(this.selectedField);\n });\n\n this.applyFilterButton.addEventListener('click', () => {\n this.applyFilter(this.selectedField);\n });\n\n // 点击空白处整个筛选菜单可消失\n document.addEventListener('click', () => {\n if (this.isVisible) {\n this.hide();\n }\n });\n\n this.filterMenu.addEventListener('click', e => {\n e.stopPropagation();\n });\n }\n\n adjustMenuPosition(\n col?: number | null,\n row?: number | null,\n providedLeft?: number | null,\n providedTop?: number | null\n ) {\n if (typeof providedLeft === 'number' && typeof providedTop === 'number') {\n this.filterMenu.style.display = this.isVisible ? 'block' : 'none';\n this.filterMenu.style.left = `${providedLeft}px`;\n this.filterMenu.style.top = `${providedTop}px`;\n return;\n }\n\n // 明晰的参数 > 记忆的数字\n const effectiveCol = typeof col === 'number' ? col : this.currentCol;\n const effectiveRow = typeof row === 'number' ? row : this.currentRow;\n\n if (typeof effectiveCol !== 'number' || typeof effectiveRow !== 'number') {\n return;\n }\n\n this.currentCol = effectiveCol;\n this.currentRow = effectiveRow;\n\n let left: number = 0;\n let top: number = 0;\n\n const canvasBounds = this.table.canvas.getBoundingClientRect();\n const cell = this.table.getCellRelativeRect(effectiveCol, effectiveRow);\n\n if (cell.right < this.filterMenuWidth) {\n // 无法把筛选菜单完整地显示在左侧,那么显示在右侧\n left = cell.left + canvasBounds.left;\n top = cell.bottom + canvasBounds.top;\n } else {\n // 筛选菜单默认显示在左侧\n left = cell.right + canvasBounds.left - this.filterMenuWidth;\n top = cell.bottom + canvasBounds.top;\n }\n\n this.filterMenu.style.display = this.isVisible ? 'block' : 'none';\n this.filterMenu.style.left = `${left}px`;\n this.filterMenu.style.top = `${top}px`;\n }\n\n show(col: number, row: number, filterModes: FilterMode[]): void {\n this.valueFilter.clearSearchInputValue();\n this.filterModes = filterModes;\n if (!this.filterModes.includes('byValue')) {\n this.filterTabByValue.style.display = 'none';\n this.onTabSwitch('byCondition');\n } else if (!this.filterModes.includes('byCondition')) {\n this.filterTabByCondition.style.display = 'none';\n this.onTabSwitch('byValue');\n }\n\n this.adjustMenuPosition(col, row);\n this.filterMenu.style.display = 'block';\n\n const field = this.table.internalProps.layoutMap.getHeaderField(col, row) as string | number;\n this.updateSelectedField(field);\n\n // 根据当前筛选配置自动选择正确的筛选标签页\n const currentFilter = this.filterStateManager.getFilterState(field);\n if (currentFilter && currentFilter.type === 'byCondition') {\n this.onTabSwitch('byCondition');\n } else {\n this.onTabSwitch('byValue');\n }\n\n // 更新清除筛选按钮状态\n this.updateClearFilterButtonState(field);\n\n // 确保在事件冒泡完成后才设置 isVisible 为 true\n setTimeout(() => {\n this.isVisible = true;\n }, 0);\n }\n\n hide(): void {\n this.filterMenu.style.display = 'none';\n this.isVisible = false;\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/filter/filter-toolbar.ts"],"names":[],"mappings":";;;AAAA,6CAAqF;AAErF,iDAA6C;AAC7C,yDAAqD;AACrD,qCAAqD;AAMrD,MAAa,aAAa;IAuBxB,YAAY,KAA6B,EAAE,kBAAsC,EAAE,aAA4B;QAnB/G,gBAAW,GAAuB,IAAI,CAAC;QACvC,oBAAe,GAA2B,IAAI,CAAC;QAC/C,cAAS,GAA8B,SAAS,CAAC;QACjD,cAAS,GAAY,KAAK,CAAC;QAC3B,kBAAa,GAA2B,IAAI,CAAC;QAC7C,gBAAW,GAAiB,EAAE,CAAC;QA4R/B,SAAI,GAAG,CAAC,UAAmB,EAAE,UAAmB,EAAQ,EAAE;YACxD,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;YACvC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;YACvB,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,yBAAgB,CAAC,gBAAgB,EAAE;gBAC1D,GAAG,EAAE,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,IAAI,CAAC,UAAU;gBAClC,GAAG,EAAE,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,IAAI,CAAC,UAAU;aACnC,CAAC,CAAC;QACL,CAAC,CAAC;QApRA,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB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E, type ListTable, type PivotTable } from '@visactor/vtable';\nimport type { FilterStateManager } from './filter-state-manager';\nimport { ValueFilter } from './value-filter';\nimport { ConditionFilter } from './condition-filter';\nimport { applyStyles, filterStyles } from './styles';\nimport type { FilterMode, FilterOptions, FilterStyles } from './types';\n\n/**\n * 筛选工具栏,管理按值和按条件筛选组件\n */\nexport class FilterToolbar {\n table: ListTable | PivotTable;\n filterStateManager: FilterStateManager;\n pluginOptions: FilterOptions;\n valueFilter: ValueFilter | null = null;\n conditionFilter: ConditionFilter | null = null;\n activeTab: 'byValue' | 'byCondition' = 'byValue';\n isVisible: boolean = false;\n selectedField: string | number | null = null;\n filterModes: FilterMode[] = [];\n\n private filterMenu: HTMLElement;\n private filterTabsContainer: HTMLElement;\n private filterMenuWidth: number;\n private currentCol?: number | null;\n private currentRow?: number | null;\n private filterTabByValue: HTMLButtonElement;\n private filterTabByCondition: HTMLButtonElement;\n private footerContainer: HTMLElement;\n private clearFilterOptionLink: HTMLAnchorElement;\n private cancelFilterButton: HTMLButtonElement;\n private applyFilterButton: HTMLButtonElement;\n\n constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager, pluginOptions: FilterOptions) {\n this.table = table;\n this.filterStateManager = filterStateManager;\n this.valueFilter = new ValueFilter(this.table, this.filterStateManager, pluginOptions);\n this.conditionFilter = new ConditionFilter(this.table, this.filterStateManager, pluginOptions, this.hide);\n this.pluginOptions = pluginOptions;\n\n this.filterMenuWidth = 300; // 待优化,可能需要自适应内容的宽度\n\n // 监听筛选状态变化,更新清除筛选按钮状态\n this.filterStateManager.subscribe(state => {\n if (this.isVisible && this.selectedField !== null) {\n this.updateClearFilterButtonState(this.selectedField);\n }\n });\n }\n\n private onTabSwitch(tab: 'byValue' | 'byCondition'): void {\n this.activeTab = tab;\n if (tab === 'byValue') {\n this.valueFilter.show();\n this.conditionFilter.hide();\n } else {\n this.conditionFilter.show();\n this.valueFilter.hide();\n }\n\n const isValueTab = tab === 'byValue';\n applyStyles(this.filterTabByValue, filterStyles.tabStyle(isValueTab));\n applyStyles(this.filterTabByCondition, filterStyles.tabStyle(!isValueTab));\n }\n\n private updateSelectedField(field: string | number): void {\n this.selectedField = field;\n // 通知筛选组件更新选中字段\n if (this.valueFilter) {\n this.valueFilter.setSelectedField(field);\n }\n if (this.conditionFilter) {\n this.conditionFilter.setSelectedField(field);\n }\n }\n\n private applyFilter(field: string | number): void {\n if (this.activeTab === 'byValue') {\n this.valueFilter.applyFilter(field);\n } else if (this.activeTab === 'byCondition') {\n this.conditionFilter.applyFilter(field);\n }\n this.hide();\n }\n\n private clearFilter(field: string | number): void {\n if (this.valueFilter) {\n this.valueFilter.clearFilter(field);\n }\n if (this.conditionFilter) {\n this.conditionFilter.clearFilter(field);\n }\n this.hide();\n }\n\n /**\n * 更新清除筛选按钮的状态\n */\n private updateClearFilterButtonState(field: string | number): void {\n const currentFilter = this.filterStateManager.getFilterState(field);\n const hasActiveFilter = currentFilter && currentFilter.enable;\n\n this.clearFilterOptionLink.style.display = 'inline';\n this.clearFilterOptionLink.style.opacity = hasActiveFilter ? '1' : '0.5';\n this.clearFilterOptionLink.style.pointerEvents = hasActiveFilter ? 'auto' : 'none';\n this.clearFilterOptionLink.style.cursor = hasActiveFilter ? 'pointer' : 'not-allowed';\n }\n\n render(container: HTMLElement): void {\n const filterStyles = this.pluginOptions.styles || {};\n // === 主容器 ===\n this.filterMenu = document.createElement('div');\n this.filterMenu.classList.add('vtable-filter-menu');\n applyStyles(this.filterMenu, filterStyles.filterMenu);\n this.filterMenu.style.width = `${this.filterMenuWidth}px`;\n\n // === 筛选 Tab ===\n this.filterTabsContainer = document.createElement('div');\n applyStyles(this.filterTabsContainer, filterStyles.tabsContainer);\n\n this.filterTabByValue = document.createElement('button');\n this.filterTabByValue.innerText = '按值筛选';\n applyStyles(this.filterTabByValue, filterStyles.tabStyle(true));\n\n this.filterTabByCondition = document.createElement('button');\n this.filterTabByCondition.innerText = '按条件筛选';\n applyStyles(this.filterTabByCondition, filterStyles.tabStyle(false));\n\n this.filterTabsContainer.append(this.filterTabByValue, this.filterTabByCondition);\n\n // === 页脚(清除、取消、确定 筛选按钮) ===\n this.footerContainer = document.createElement('div');\n applyStyles(this.footerContainer, filterStyles.footerContainer);\n\n this.clearFilterOptionLink = document.createElement('a');\n this.clearFilterOptionLink.href = '#';\n this.clearFilterOptionLink.innerText = '清除筛选';\n applyStyles(this.clearFilterOptionLink, filterStyles.clearLink);\n\n const footerButtons = document.createElement('div');\n this.cancelFilterButton = document.createElement('button');\n this.cancelFilterButton.innerText = '取消';\n applyStyles(this.cancelFilterButton, filterStyles.footerButton(false));\n\n this.applyFilterButton = document.createElement('button');\n this.applyFilterButton.innerText = '确认';\n applyStyles(this.applyFilterButton, filterStyles.footerButton(true));\n\n footerButtons.append(this.cancelFilterButton, this.applyFilterButton);\n this.footerContainer.append(this.clearFilterOptionLink, footerButtons);\n\n // --- 筛选器头部 Tab ---\n this.filterMenu.append(this.filterTabsContainer);\n\n // --- 筛选器内容 ---\n this.valueFilter.render(this.filterMenu);\n this.conditionFilter.render(this.filterMenu);\n\n // --- 筛选器页脚 ---\n this.filterMenu.append(this.footerContainer);\n\n container.appendChild(this.filterMenu); // 将筛选器添加到 DOM 中\n this.attachEventListeners();\n }\n\n updateStyles(styles: FilterStyles) {\n const realDisplay = (this.filterMenu.style.display ?? styles.filterMenu.display) || 'none';\n applyStyles(this.filterMenu, { ...styles.filterMenu, display: realDisplay });\n applyStyles(this.filterTabsContainer, styles.tabsContainer);\n applyStyles(this.filterTabByValue, styles.tabStyle(true));\n applyStyles(this.footerContainer, styles.footerContainer);\n applyStyles(this.clearFilterOptionLink, styles.clearLink);\n applyStyles(this.cancelFilterButton, styles.footerButton(false));\n applyStyles(this.applyFilterButton, styles.footerButton(true));\n this.valueFilter.updateStyles(styles);\n this.conditionFilter.updateStyles(styles);\n }\n\n attachEventListeners() {\n // 按值筛选/按条件筛选的事件监听\n this.filterTabByValue.addEventListener('click', () => {\n this.onTabSwitch('byValue');\n });\n\n this.filterTabByCondition.addEventListener('click', () => {\n this.onTabSwitch('byCondition');\n });\n\n this.cancelFilterButton.addEventListener('click', () => this.hide());\n\n this.clearFilterOptionLink.addEventListener('click', e => {\n e.preventDefault();\n this.clearFilter(this.selectedField);\n });\n\n this.applyFilterButton.addEventListener('click', () => {\n this.applyFilter(this.selectedField);\n });\n\n // 点击空白处整个筛选菜单可消失\n document.addEventListener('click', () => {\n if (this.isVisible) {\n this.hide();\n }\n });\n\n this.filterMenu.addEventListener('click', e => {\n e.stopPropagation();\n });\n }\n\n adjustMenuPosition(\n col?: number | null,\n row?: number | null,\n providedLeft?: number | null,\n providedTop?: number | null\n ) {\n if (typeof providedLeft === 'number' && typeof providedTop === 'number') {\n this.filterMenu.style.display = this.isVisible ? 'block' : 'none';\n this.filterMenu.style.left = `${providedLeft}px`;\n this.filterMenu.style.top = `${providedTop}px`;\n return;\n }\n\n // 明晰的参数 > 记忆的数字\n const effectiveCol = typeof col === 'number' ? col : this.currentCol;\n const effectiveRow = typeof row === 'number' ? row : this.currentRow;\n\n if (typeof effectiveCol !== 'number' || typeof effectiveRow !== 'number') {\n return;\n }\n\n this.currentCol = effectiveCol;\n this.currentRow = effectiveRow;\n\n let left: number = 0;\n let top: number = 0;\n\n const canvasBounds = this.table.canvas.getBoundingClientRect();\n const cell = this.table.getCellRelativeRect(effectiveCol, effectiveRow);\n\n const filterMenuWidth = this.filterMenuWidth;\n // 最高高度预估值\n // TODO: 需要获取精确高度\n const filterMenuHeight = 380;\n\n if (cell.right < this.filterMenuWidth) {\n // 无法把筛选菜单完整地显示在左侧,那么显示在右侧\n left = cell.left + canvasBounds.left;\n top = cell.bottom + canvasBounds.top;\n } else {\n // 筛选菜单默认显示在左侧\n left = cell.right + canvasBounds.left - this.filterMenuWidth;\n top = cell.bottom + canvasBounds.top;\n }\n\n // 确保筛选菜单不会超出窗口边界\n left = Math.max(0, Math.min(window.innerWidth - filterMenuWidth, left));\n top = Math.max(0, Math.min(window.innerHeight - filterMenuHeight, top));\n\n this.filterMenu.style.display = this.isVisible ? 'block' : 'none';\n this.filterMenu.style.left = `${left}px`;\n this.filterMenu.style.top = `${top}px`;\n }\n\n show(col: number, row: number, filterModes: FilterMode[]): void {\n this.valueFilter.clearSearchInputValue();\n this.filterModes = filterModes;\n if (!this.filterModes.includes('byValue')) {\n this.filterTabByValue.style.display = 'none';\n this.onTabSwitch('byCondition');\n } else if (!this.filterModes.includes('byCondition')) {\n this.filterTabByCondition.style.display = 'none';\n this.onTabSwitch('byValue');\n }\n\n this.adjustMenuPosition(col, row);\n this.filterMenu.style.display = 'block';\n\n const field = this.table.internalProps.layoutMap.getHeaderField(col, row) as string | number;\n this.updateSelectedField(field);\n\n // 根据当前筛选配置自动选择正确的筛选标签页\n const currentFilter = this.filterStateManager.getFilterState(field);\n if (currentFilter && currentFilter.type === 'byCondition') {\n this.onTabSwitch('byCondition');\n } else {\n this.onTabSwitch('byValue');\n }\n\n // 更新清除筛选按钮状态\n this.updateClearFilterButtonState(field);\n\n // 确保在事件冒泡完成后才设置 isVisible 为 true\n setTimeout(() => {\n this.isVisible = true;\n this.table.fireListeners(TABLE_EVENT_TYPE.FILTER_MENU_SHOW, {\n col: col,\n row: row\n });\n }, 0);\n }\n\n hide = (currentCol?: number, currentRow?: number): void => {\n this.filterMenu.style.display = 'none';\n this.isVisible = false;\n this.table.fireListeners(TABLE_EVENT_TYPE.FILTER_MENU_HIDE, {\n col: currentCol ?? this.currentCol,\n row: currentRow ?? this.currentRow\n });\n };\n\n destroy() {\n this.valueFilter.destroy();\n this.filterMenu.remove();\n }\n}\n"]}
@@ -14,7 +14,9 @@ export declare class FilterPlugin implements pluginsDefinition.IVTablePlugin {
14
14
  filterStateManager: FilterStateManager;
15
15
  filterToolbar: FilterToolbar;
16
16
  constructor(pluginOptions: FilterOptions);
17
+ initFilterPlugin(eventArgs: any): void;
17
18
  run(...args: any[]): void;
19
+ updatePluginOptions(pluginOptions: FilterOptions): void;
18
20
  update(): void;
19
21
  syncFilterWithTableData(field?: string | number): void;
20
22
  private handleOptionUpdate;