@visactor/vtable-plugins 1.22.7-alpha.1 → 1.22.7-alpha.11
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.
- package/cjs/auto-fill/date-tools.js +2 -1
- package/cjs/contextmenu/index.js +1 -2
- package/cjs/filter/condition-filter.d.ts +4 -3
- package/cjs/filter/condition-filter.js +42 -41
- package/cjs/filter/condition-filter.js.map +1 -1
- package/cjs/filter/{constants.js → constant.js} +1 -1
- package/cjs/filter/constant.js.map +1 -0
- package/cjs/filter/filter-engine.d.ts +3 -1
- package/cjs/filter/filter-engine.js +5 -3
- package/cjs/filter/filter-engine.js.map +1 -1
- package/cjs/filter/filter-state-manager.d.ts +0 -14
- package/cjs/filter/filter-state-manager.js +9 -37
- package/cjs/filter/filter-state-manager.js.map +1 -1
- package/cjs/filter/filter-toolbar.d.ts +4 -3
- package/cjs/filter/filter-toolbar.js +35 -39
- package/cjs/filter/filter-toolbar.js.map +1 -1
- package/cjs/filter/filter.js +12 -14
- package/cjs/filter/filter.js.map +1 -1
- package/cjs/filter/styles.d.ts +124 -2
- package/cjs/filter/styles.js +1 -1
- package/cjs/filter/styles.js.map +1 -1
- package/cjs/filter/types.d.ts +8 -6
- package/cjs/filter/types.js.map +1 -1
- package/cjs/filter/value-filter.d.ts +14 -14
- package/cjs/filter/value-filter.js +140 -222
- package/cjs/filter/value-filter.js.map +1 -1
- package/cjs/gantt-export-image.js.map +1 -1
- package/cjs/master-detail-plugin/checkbox.js +1 -0
- package/cjs/master-detail-plugin/config.js.map +1 -1
- package/cjs/master-detail-plugin/types.js +1 -1
- package/cjs/table-export/index.js +1 -2
- package/dist/vtable-plugins.js +346 -471
- package/dist/vtable-plugins.min.js +2 -2
- package/es/auto-fill/date-tools.js +2 -1
- package/es/contextmenu/index.js +1 -2
- package/es/filter/condition-filter.d.ts +4 -3
- package/es/filter/condition-filter.js +42 -41
- package/es/filter/condition-filter.js.map +1 -1
- package/es/filter/{constants.js → constant.js} +1 -1
- package/es/filter/constant.js.map +1 -0
- package/es/filter/filter-engine.d.ts +3 -1
- package/es/filter/filter-engine.js +5 -3
- package/es/filter/filter-engine.js.map +1 -1
- package/es/filter/filter-state-manager.d.ts +0 -14
- package/es/filter/filter-state-manager.js +9 -37
- package/es/filter/filter-state-manager.js.map +1 -1
- package/es/filter/filter-toolbar.d.ts +4 -3
- package/es/filter/filter-toolbar.js +38 -42
- package/es/filter/filter-toolbar.js.map +1 -1
- package/es/filter/filter.js +14 -15
- package/es/filter/filter.js.map +1 -1
- package/es/filter/styles.d.ts +124 -2
- package/es/filter/styles.js +1 -1
- package/es/filter/styles.js.map +1 -1
- package/es/filter/types.d.ts +8 -6
- package/es/filter/types.js.map +1 -1
- package/es/filter/value-filter.d.ts +14 -14
- package/es/filter/value-filter.js +140 -222
- package/es/filter/value-filter.js.map +1 -1
- package/es/gantt-export-image.js.map +1 -1
- package/es/master-detail-plugin/checkbox.js +2 -1
- package/es/master-detail-plugin/config.js.map +1 -1
- package/es/master-detail-plugin/types.js +1 -1
- package/es/table-export/index.js +1 -2
- package/package.json +6 -6
- package/cjs/filter/constants.js.map +0 -1
- package/es/filter/constants.js.map +0 -1
- /package/cjs/filter/{constants.d.ts → constant.d.ts} +0 -0
- /package/es/filter/{constants.d.ts → constant.d.ts} +0 -0
|
@@ -33,4 +33,5 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
33
33
|
value: !0
|
|
34
34
|
}), exports.format = exports.parse = exports.addDays = exports.differenceInDays = exports.isValid = void 0,
|
|
35
35
|
exports.isValid = isValid, exports.differenceInDays = differenceInDays, exports.addDays = addDays,
|
|
36
|
-
exports.parse = parse, exports.format = format;
|
|
36
|
+
exports.parse = parse, exports.format = format;
|
|
37
|
+
//# sourceMappingURL=date-tools.js.map
|
package/cjs/contextmenu/index.js
CHANGED
|
@@ -18,5 +18,4 @@ var __createBinding = this && this.__createBinding || (Object.create ? function(
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", {
|
|
19
19
|
value: !0
|
|
20
20
|
}), __exportStar(require("./menu-manager"), exports), __exportStar(require("./styles"), exports),
|
|
21
|
-
__exportStar(require("./types"), exports);
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ListTable, PivotTable } from '@visactor/vtable';
|
|
2
2
|
import type { FilterStateManager } from './filter-state-manager';
|
|
3
|
-
import type {
|
|
3
|
+
import type { FilterOptions, FilterStyles, OperatorOption } from './types';
|
|
4
4
|
export declare class ConditionFilter {
|
|
5
5
|
private table;
|
|
6
6
|
private filterStateManager;
|
|
7
|
+
private pluginOptions;
|
|
8
|
+
private filterToolBarHide;
|
|
7
9
|
private styles;
|
|
8
10
|
private filterByConditionPanel;
|
|
9
11
|
private conditionContainer;
|
|
@@ -20,7 +22,7 @@ export declare class ConditionFilter {
|
|
|
20
22
|
private currentCategory;
|
|
21
23
|
private categories;
|
|
22
24
|
protected operators: OperatorOption[];
|
|
23
|
-
constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager, pluginOptions: FilterOptions);
|
|
25
|
+
constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager, pluginOptions: FilterOptions, filterToolBarHide: () => void);
|
|
24
26
|
setSelectedField(fieldId: string | number): void;
|
|
25
27
|
private updateOperatorOptions;
|
|
26
28
|
private handleCategoryChange;
|
|
@@ -32,7 +34,6 @@ export declare class ConditionFilter {
|
|
|
32
34
|
applyFilter(fieldId?: string | number): void;
|
|
33
35
|
clearFilter(fieldId: string | number): void;
|
|
34
36
|
render(container: HTMLElement): void;
|
|
35
|
-
updatePluginOptions(filterOptions: FilterOptions): void;
|
|
36
37
|
updateStyles(styles: FilterStyles): void;
|
|
37
38
|
private bindEvents;
|
|
38
39
|
show(): void;
|
|
@@ -4,13 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
}), exports.ConditionFilter = void 0;
|
|
6
6
|
|
|
7
|
-
const styles_1 = require("./styles"), types_1 = require("./types"),
|
|
7
|
+
const styles_1 = require("./styles"), types_1 = require("./types"), constant_1 = require("./constant");
|
|
8
8
|
|
|
9
9
|
class ConditionFilter {
|
|
10
|
-
constructor(table, filterStateManager, pluginOptions) {
|
|
10
|
+
constructor(table, filterStateManager, pluginOptions, filterToolBarHide) {
|
|
11
11
|
this.currentCategory = types_1.FilterOperatorCategory.ALL, this.categories = [],
|
|
12
|
-
this.operators = [], this.table = table, this.
|
|
13
|
-
this.
|
|
12
|
+
this.operators = [], this.table = table, this.filterStateManager = filterStateManager,
|
|
13
|
+
this.pluginOptions = pluginOptions, this.styles = pluginOptions.styles || {}, this.categories = pluginOptions.conditionCategories,
|
|
14
|
+
this.operators = constant_1.operators, this.filterToolBarHide = filterToolBarHide;
|
|
14
15
|
}
|
|
15
16
|
setSelectedField(fieldId) {
|
|
16
17
|
this.selectedField = fieldId, this.updateOperatorOptions(), this.loadCurrentFilterState();
|
|
@@ -34,10 +35,11 @@ class ConditionFilter {
|
|
|
34
35
|
this.syncUIState());
|
|
35
36
|
}
|
|
36
37
|
loadCurrentFilterState() {
|
|
37
|
-
|
|
38
|
-
filter
|
|
39
|
-
|
|
40
|
-
this.
|
|
38
|
+
var _a, _b, _c, _d;
|
|
39
|
+
const filter = this.filterStateManager.getFilterState(this.selectedField), syncFilterItemsState = null === (_b = null === (_a = this.pluginOptions) || void 0 === _a ? void 0 : _a.syncFilterItemsState) || void 0 === _b || _b;
|
|
40
|
+
filter && "byCondition" === filter.type || !syncFilterItemsState ? (this.operatorSelect && (this.operatorSelect.value = null !== (_c = null == filter ? void 0 : filter.operator) && void 0 !== _c ? _c : constant_1.operators[0].value),
|
|
41
|
+
this.valueInput && (Array.isArray(null == filter ? void 0 : filter.condition) ? (this.valueInput.value = String(filter.condition[0]),
|
|
42
|
+
this.valueInputMax && (this.valueInputMax.value = String(filter.condition[1]))) : (this.valueInput.value = String(null !== (_d = null == filter ? void 0 : filter.condition) && void 0 !== _d ? _d : ""),
|
|
41
43
|
this.valueInputMax && (this.valueInputMax.value = ""))), this.syncUIState()) : this.reset();
|
|
42
44
|
}
|
|
43
45
|
reset() {
|
|
@@ -60,33 +62,35 @@ class ConditionFilter {
|
|
|
60
62
|
return "between" === operator || "notBetween" === operator;
|
|
61
63
|
}
|
|
62
64
|
applyFilter(fieldId = this.selectedField) {
|
|
63
|
-
var _a, _b;
|
|
65
|
+
var _a, _b, _c, _d;
|
|
64
66
|
if (!this.operatorSelect || !this.valueInput) return;
|
|
65
67
|
const operator = null === (_a = this.operatorSelect) || void 0 === _a ? void 0 : _a.value;
|
|
66
68
|
let conditionValue = null === (_b = this.valueInput) || void 0 === _b ? void 0 : _b.value;
|
|
67
|
-
if (this.currentCategory
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
conditionValue = [ minValue, maxValue ];
|
|
69
|
+
if (this.currentCategory === types_1.FilterOperatorCategory.NUMBER && (conditionValue = parseFloat(conditionValue),
|
|
70
|
+
isNaN(conditionValue))) return;
|
|
71
|
+
if (this.isRangeOperator(operator)) {
|
|
72
|
+
const minValue = conditionValue;
|
|
73
|
+
let maxValue = this.valueInputMax.value.trim();
|
|
74
|
+
if (this.currentCategory === types_1.FilterOperatorCategory.NUMBER) {
|
|
75
|
+
const numMaxValue = parseFloat(maxValue);
|
|
76
|
+
if (isNaN(numMaxValue)) return;
|
|
77
|
+
maxValue = numMaxValue;
|
|
78
78
|
}
|
|
79
|
-
conditionValue
|
|
80
|
-
type: types_1.FilterActionType.APPLY_FILTERS,
|
|
81
|
-
payload: {
|
|
82
|
-
field: fieldId,
|
|
83
|
-
type: "byCondition",
|
|
84
|
-
operator: operator,
|
|
85
|
-
condition: conditionValue,
|
|
86
|
-
enable: !0
|
|
87
|
-
}
|
|
88
|
-
}), this.hide()) : this.clearFilter(fieldId);
|
|
79
|
+
conditionValue = [ minValue, maxValue ];
|
|
89
80
|
}
|
|
81
|
+
if (!conditionValue && !1 !== conditionValue && 0 !== conditionValue && !this.isBooleanOperator(operator)) return void this.clearFilter(fieldId);
|
|
82
|
+
const syncFilterItemsState = null === (_d = null === (_c = this.pluginOptions) || void 0 === _c ? void 0 : _c.syncFilterItemsState) || void 0 === _d || _d;
|
|
83
|
+
this.filterStateManager.dispatch({
|
|
84
|
+
type: types_1.FilterActionType.APPLY_FILTERS,
|
|
85
|
+
payload: {
|
|
86
|
+
field: fieldId,
|
|
87
|
+
type: "byCondition",
|
|
88
|
+
operator: operator,
|
|
89
|
+
condition: conditionValue,
|
|
90
|
+
enable: !0,
|
|
91
|
+
shouldKeepUnrelatedState: !syncFilterItemsState
|
|
92
|
+
}
|
|
93
|
+
});
|
|
90
94
|
}
|
|
91
95
|
clearFilter(fieldId) {
|
|
92
96
|
this.filterStateManager.dispatch({
|
|
@@ -97,28 +101,29 @@ class ConditionFilter {
|
|
|
97
101
|
}), this.hide();
|
|
98
102
|
}
|
|
99
103
|
render(container) {
|
|
100
|
-
|
|
104
|
+
const filterStyles = this.styles;
|
|
105
|
+
this.filterByConditionPanel = document.createElement("div"), (0, styles_1.applyStyles)(this.filterByConditionPanel, filterStyles.filterPanel),
|
|
101
106
|
this.conditionContainer = document.createElement("div"), (0, styles_1.applyStyles)(this.conditionContainer, this.styles.conditionContainer),
|
|
102
107
|
this.categoryLabel = (0, styles_1.createElement)("label", {}, [ "筛选类型:" ]), (0,
|
|
103
108
|
styles_1.applyStyles)(this.categoryLabel, this.styles.formLabel), this.categorySelect = (0,
|
|
104
|
-
styles_1.createElement)("select"), (0, styles_1.applyStyles)(this.categorySelect,
|
|
109
|
+
styles_1.createElement)("select"), (0, styles_1.applyStyles)(this.categorySelect, filterStyles.operatorSelect),
|
|
105
110
|
this.categories.forEach((category => {
|
|
106
111
|
const option = document.createElement("option");
|
|
107
112
|
option.value = category.value, option.textContent = category.label, this.categorySelect.appendChild(option);
|
|
108
113
|
})), this.operatorLabel = (0, styles_1.createElement)("label", {}, [ "筛选条件:" ]),
|
|
109
114
|
(0, styles_1.applyStyles)(this.operatorLabel, this.styles.formLabel), this.operatorSelect = (0,
|
|
110
|
-
styles_1.createElement)("select"), (0, styles_1.applyStyles)(this.operatorSelect,
|
|
115
|
+
styles_1.createElement)("select"), (0, styles_1.applyStyles)(this.operatorSelect, filterStyles.operatorSelect),
|
|
111
116
|
this.valueLabel = (0, styles_1.createElement)("label", {}, [ "筛选值:" ]), (0, styles_1.applyStyles)(this.valueLabel, this.styles.formLabel),
|
|
112
117
|
this.rangeInputContainer = (0, styles_1.createElement)("div"), (0, styles_1.applyStyles)(this.rangeInputContainer, this.styles.rangeInputContainer),
|
|
113
118
|
this.valueInput = (0, styles_1.createElement)("input", {
|
|
114
119
|
type: "text",
|
|
115
120
|
placeholder: "请输入筛选值"
|
|
116
|
-
}), (0, styles_1.applyStyles)(this.valueInput,
|
|
121
|
+
}), (0, styles_1.applyStyles)(this.valueInput, filterStyles.searchInput), this.andLabel = (0,
|
|
117
122
|
styles_1.createElement)("span", {}, [ "和" ]), (0, styles_1.applyStyles)(this.andLabel, this.styles.addLabel),
|
|
118
123
|
this.andLabel.style.display = "none", this.valueInputMax = (0, styles_1.createElement)("input", {
|
|
119
124
|
type: "text",
|
|
120
125
|
placeholder: "最大值"
|
|
121
|
-
}), (0, styles_1.applyStyles)(this.valueInputMax,
|
|
126
|
+
}), (0, styles_1.applyStyles)(this.valueInputMax, filterStyles.searchInput), this.valueInputMax.style.display = "none",
|
|
122
127
|
this.rangeInputContainer.appendChild(this.valueInput), this.rangeInputContainer.appendChild(this.andLabel),
|
|
123
128
|
this.rangeInputContainer.appendChild(this.valueInputMax), this.conditionContainer.appendChild(this.categoryLabel),
|
|
124
129
|
this.conditionContainer.appendChild(this.categorySelect), this.conditionContainer.appendChild(this.operatorLabel),
|
|
@@ -127,10 +132,6 @@ class ConditionFilter {
|
|
|
127
132
|
container.appendChild(this.filterByConditionPanel), this.hide(), this.updateOperatorOptions(),
|
|
128
133
|
this.bindEvents();
|
|
129
134
|
}
|
|
130
|
-
updatePluginOptions(filterOptions) {
|
|
131
|
-
this.styles = filterOptions.styles, this.categories = filterOptions.conditionCategories,
|
|
132
|
-
this.updateStyles(filterOptions.styles);
|
|
133
|
-
}
|
|
134
135
|
updateStyles(styles) {
|
|
135
136
|
(0, styles_1.applyStyles)(this.filterByConditionPanel, styles.filterPanel), (0,
|
|
136
137
|
styles_1.applyStyles)(this.conditionContainer, styles.conditionContainer), (0, styles_1.applyStyles)(this.categoryLabel, styles.formLabel),
|
|
@@ -142,9 +143,9 @@ class ConditionFilter {
|
|
|
142
143
|
}
|
|
143
144
|
bindEvents() {
|
|
144
145
|
this.valueInput.addEventListener("keypress", (event => {
|
|
145
|
-
"Enter" === event.key && this.applyFilter();
|
|
146
|
+
"Enter" === event.key && (this.applyFilter(), this.filterToolBarHide());
|
|
146
147
|
})), this.valueInputMax.addEventListener("keypress", (event => {
|
|
147
|
-
"Enter" === event.key && this.applyFilter();
|
|
148
|
+
"Enter" === event.key && (this.applyFilter(), this.filterToolBarHide());
|
|
148
149
|
})), this.categorySelect.addEventListener("change", (() => {
|
|
149
150
|
this.handleCategoryChange();
|
|
150
151
|
})), this.operatorSelect.addEventListener("change", (() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/filter/condition-filter.ts"],"names":[],"mappings":";;;AAEA,qCAAsD;AAQtD,mCAAmE;AACnE,2CAAwC;AAKxC,MAAa,eAAe;IAuB1B,YAAY,KAA6B,EAAE,kBAAsC,EAAE,aAA4B;QALvG,oBAAe,GAA2B,8BAAsB,CAAC,GAAG,CAAC;QAErE,eAAU,GAAmC,EAAE,CAAC;QAC9C,cAAS,GAAqB,EAAE,CAAC;QAGzC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,MAAM,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AAsB,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;SACpD;IACH,CAAC;CACF;AAtbD,0CAsbC","file":"condition-filter.js","sourcesContent":["import type { ListTable, PivotTable } from '@visactor/vtable';\nimport type { FilterStateManager } from './filter-state-manager';\nimport { applyStyles, createElement } from './styles';\nimport type {\n FilterOperator,\n OperatorOption,\n FilterStyles,\n FilterOperatorCategoryOption,\n FilterOptions\n} from './types';\nimport { FilterActionType, FilterOperatorCategory } from './types';\nimport { operators } from './constants';\n\n/**\n * 按条件筛选组件\n */\nexport class ConditionFilter {\n private table: ListTable | PivotTable;\n private filterStateManager: FilterStateManager;\n private styles: FilterStyles;\n\n private filterByConditionPanel: HTMLElement;\n private conditionContainer: HTMLElement;\n private categoryLabel: HTMLElement;\n private selectedField: string | number;\n private operatorSelect: HTMLSelectElement;\n private valueInput: HTMLInputElement;\n private andLabel: HTMLElement;\n private valueInputMax: HTMLInputElement;\n private categorySelect: HTMLSelectElement;\n private operatorLabel: HTMLElement;\n private rangeInputContainer: HTMLElement;\n private valueLabel: HTMLElement;\n\n private currentCategory: FilterOperatorCategory = FilterOperatorCategory.ALL;\n\n private categories: FilterOperatorCategoryOption[] = [];\n protected operators: OperatorOption[] = [];\n\n constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager, pluginOptions: FilterOptions) {\n this.table = table;\n this.styles = pluginOptions.styles;\n this.filterStateManager = filterStateManager;\n this.categories = pluginOptions.conditionCategories;\n this.operators = operators;\n }\n\n setSelectedField(fieldId: string | number): void {\n this.selectedField = fieldId;\n this.updateOperatorOptions();\n this.loadCurrentFilterState();\n }\n\n /**\n * 更新操作符下拉选项\n */\n private updateOperatorOptions(): void {\n if (!this.operatorSelect) {\n return;\n }\n this.operatorSelect.innerHTML = '';\n let filteredOperators: OperatorOption[];\n\n if (this.currentCategory === FilterOperatorCategory.ALL) {\n // 当选择\"全部\"时,收集所有配置的分类中, 不重复的操作符\n const uniqueOperators = new Map<string, OperatorOption>();\n this.operators\n .filter(op => this.categories.map(cat => cat.value).includes(op.category))\n .forEach(op => {\n if (!uniqueOperators.has(op.value)) {\n uniqueOperators.set(op.value, op);\n }\n });\n filteredOperators = Array.from(uniqueOperators.values());\n } else {\n // 其他类别正常筛选\n filteredOperators = this.operators.filter(op => op.category === this.currentCategory);\n }\n\n // 添加新选项\n filteredOperators.forEach(op => {\n const option = document.createElement('option');\n option.value = op.value;\n option.textContent = op.label;\n this.operatorSelect.appendChild(option);\n });\n }\n\n private handleCategoryChange(): void {\n if (!this.categorySelect) {\n return;\n }\n\n this.currentCategory = this.categorySelect.value as FilterOperatorCategory;\n this.updateOperatorOptions();\n\n // 分类切换后也需要同步UI状态\n this.syncUIState();\n }\n\n /**\n * 加载当前的筛选状态\n */\n private loadCurrentFilterState(): void {\n const filter = this.filterStateManager.getFilterState(this.selectedField);\n\n if (filter && filter.type === 'byCondition') {\n // 设置操作符\n if (filter.operator && this.operatorSelect) {\n this.operatorSelect.value = filter.operator;\n }\n\n // 设置条件值\n if (filter.condition !== undefined && this.valueInput) {\n if (Array.isArray(filter.condition)) {\n this.valueInput.value = String(filter.condition[0]);\n if (this.valueInputMax) {\n this.valueInputMax.value = String(filter.condition[1]);\n }\n } else {\n this.valueInput.value = String(filter.condition);\n if (this.valueInputMax) {\n this.valueInputMax.value = '';\n }\n }\n }\n\n // 同步UI状态:根据当前操作符显示/隐藏范围输入框\n this.syncUIState();\n } else {\n // 重置为默认值\n this.reset();\n }\n }\n\n /**\n * 重置筛选条件到默认状态\n */\n reset(): void {\n // 重置操作符选择\n if (this.operatorSelect) {\n this.operatorSelect.selectedIndex = 0;\n }\n\n // 重置所有输入框\n if (this.valueInput) {\n this.valueInput.value = '';\n this.valueInput.placeholder = '请输入筛选值';\n }\n\n if (this.valueInputMax) {\n this.valueInputMax.value = '';\n }\n\n // 重置分类选择\n this.currentCategory = FilterOperatorCategory.ALL;\n if (this.categorySelect) {\n this.categorySelect.value = FilterOperatorCategory.ALL;\n }\n\n // 更新操作符选项\n this.updateOperatorOptions();\n\n // 同步UI状态\n this.syncUIState();\n }\n\n /**\n * 同步UI状态:根据当前选择的操作符调整UI显示\n */\n private syncUIState(): void {\n if (!this.operatorSelect || !this.valueInput) {\n return;\n }\n\n const selectedOperator = this.operatorSelect.value as FilterOperator;\n const andLabel = this.valueInput.nextElementSibling as HTMLElement;\n\n if (this.isRangeOperator(selectedOperator)) {\n // 显示范围输入相关UI\n this.valueInput.placeholder = '最小值';\n if (this.valueInputMax) {\n this.valueInputMax.style.display = 'inline-block';\n }\n if (andLabel) {\n andLabel.style.display = 'inline-block';\n }\n } else {\n // 隐藏范围输入相关UI\n this.valueInput.placeholder = '请输入筛选值';\n if (this.valueInputMax) {\n this.valueInputMax.style.display = 'none';\n }\n if (andLabel) {\n andLabel.style.display = 'none';\n }\n }\n }\n\n private isBooleanOperator(operator: FilterOperator): boolean {\n const booleanCondition = ['isChecked', 'isUnchecked'];\n return booleanCondition.includes(operator);\n }\n\n private isRangeOperator(operator: FilterOperator): boolean {\n return operator === 'between' || operator === 'notBetween';\n }\n\n /**\n * 应用筛选条件\n */\n applyFilter(fieldId: string | number = this.selectedField): void {\n if (!this.operatorSelect || !this.valueInput) {\n return;\n }\n\n const operator = this.operatorSelect?.value as FilterOperator;\n let conditionValue: any = this.valueInput?.value;\n\n // 根据所选操作符和分类尝试转换输入值\n if (this.currentCategory === FilterOperatorCategory.NUMBER) {\n conditionValue = parseFloat(conditionValue);\n if (isNaN(conditionValue)) {\n console.warn('请输入有效的数字');\n return;\n }\n }\n\n // 处理范围操作符的双值输入\n if (this.isRangeOperator(operator)) {\n const minValue = conditionValue;\n let maxValue: string | number = this.valueInputMax.value.trim();\n\n // 尝试将最大值也转换为数字\n if (this.currentCategory === FilterOperatorCategory.NUMBER) {\n const numMaxValue = parseFloat(maxValue);\n if (!isNaN(numMaxValue)) {\n maxValue = numMaxValue;\n } else {\n console.warn('请输入有效的最大值');\n return;\n }\n }\n\n // 使用数组形式传递范围值\n conditionValue = [minValue, maxValue];\n }\n\n if (!conditionValue && conditionValue !== false && conditionValue !== 0 && !this.isBooleanOperator(operator)) {\n this.clearFilter(fieldId);\n return;\n }\n\n // TODO:处理单元格颜色和字体颜色的筛选\n\n this.filterStateManager.dispatch({\n type: FilterActionType.APPLY_FILTERS,\n payload: {\n field: fieldId,\n type: 'byCondition',\n operator,\n condition: conditionValue,\n enable: true\n }\n });\n\n this.hide();\n }\n\n /**\n * 清除筛选\n */\n clearFilter(fieldId: string | number): void {\n this.filterStateManager.dispatch({\n type: FilterActionType.REMOVE_FILTER,\n payload: {\n field: fieldId\n }\n });\n\n this.hide();\n }\n\n /**\n * 渲染条件筛选面板\n */\n render(container: HTMLElement): void {\n // 按条件筛选面板\n this.filterByConditionPanel = document.createElement('div');\n applyStyles(this.filterByConditionPanel, this.styles.filterPanel);\n\n // 条件选择区域\n this.conditionContainer = document.createElement('div');\n applyStyles(this.conditionContainer, this.styles.conditionContainer);\n\n // 分类选择下拉框\n this.categoryLabel = createElement('label', {}, ['筛选类型:']);\n applyStyles(this.categoryLabel, this.styles.formLabel);\n\n this.categorySelect = createElement('select') as HTMLSelectElement;\n applyStyles(this.categorySelect, this.styles.operatorSelect);\n\n // 添加分类选项\n this.categories.forEach(category => {\n const option = document.createElement('option');\n option.value = category.value;\n option.textContent = category.label;\n this.categorySelect.appendChild(option);\n });\n\n // 操作符选择下拉框\n this.operatorLabel = createElement('label', {}, ['筛选条件:']);\n applyStyles(this.operatorLabel, this.styles.formLabel);\n\n this.operatorSelect = createElement('select') as HTMLSelectElement;\n applyStyles(this.operatorSelect, this.styles.operatorSelect);\n\n // 条件值输入框\n this.valueLabel = createElement('label', {}, ['筛选值:']);\n applyStyles(this.valueLabel, this.styles.formLabel);\n\n // 一个容器来包装两个输入框和\"和\"字\n this.rangeInputContainer = createElement('div');\n applyStyles(this.rangeInputContainer, this.styles.rangeInputContainer);\n\n this.valueInput = createElement('input', {\n type: 'text',\n placeholder: '请输入筛选值'\n }) as HTMLInputElement;\n applyStyles(this.valueInput, this.styles.searchInput);\n\n // \"和\"字标签\n this.andLabel = createElement('span', {}, ['和']);\n applyStyles(this.andLabel, this.styles.addLabel);\n this.andLabel.style.display = 'none'; // 默认隐藏\n\n // 范围筛选的最大值输入框\n this.valueInputMax = createElement('input', {\n type: 'text',\n placeholder: '最大值'\n }) as HTMLInputElement;\n applyStyles(this.valueInputMax, this.styles.searchInput);\n this.valueInputMax.style.display = 'none'; // 默认隐藏\n\n // 将输入框和\"和\"字添加到容器中\n this.rangeInputContainer.appendChild(this.valueInput);\n this.rangeInputContainer.appendChild(this.andLabel);\n this.rangeInputContainer.appendChild(this.valueInputMax);\n\n // 将元素添加到容器中\n this.conditionContainer.appendChild(this.categoryLabel);\n this.conditionContainer.appendChild(this.categorySelect);\n this.conditionContainer.appendChild(this.operatorLabel);\n this.conditionContainer.appendChild(this.operatorSelect);\n this.conditionContainer.appendChild(this.valueLabel);\n this.conditionContainer.appendChild(this.rangeInputContainer);\n\n this.filterByConditionPanel.appendChild(this.conditionContainer);\n container.appendChild(this.filterByConditionPanel);\n\n // 默认隐藏\n this.hide();\n\n // 初始化操作符选项\n this.updateOperatorOptions();\n this.bindEvents();\n }\n\n /**\n * 更新插件选项\n * @param filterOptions 筛选选项\n */\n updatePluginOptions(filterOptions: FilterOptions): void {\n this.styles = filterOptions.styles;\n this.categories = filterOptions.conditionCategories;\n this.updateStyles(filterOptions.styles);\n }\n\n /**\n * 更新样式\n * @param styles 筛选样式\n */\n updateStyles(styles: FilterStyles) {\n applyStyles(this.filterByConditionPanel, styles.filterPanel);\n applyStyles(this.conditionContainer, styles.conditionContainer);\n applyStyles(this.categoryLabel, styles.formLabel);\n applyStyles(this.categorySelect, styles.operatorSelect);\n applyStyles(this.operatorLabel, styles.formLabel);\n applyStyles(this.operatorSelect, styles.operatorSelect);\n applyStyles(this.valueLabel, styles.formLabel);\n applyStyles(this.rangeInputContainer, styles.rangeInputContainer);\n applyStyles(this.valueInput, styles.searchInput);\n applyStyles(this.andLabel, styles.addLabel);\n applyStyles(this.valueInputMax, styles.searchInput);\n }\n\n /**\n * 绑定事件\n */\n private bindEvents(): void {\n // 输入框回车事件\n this.valueInput.addEventListener('keypress', event => {\n if (event.key === 'Enter') {\n this.applyFilter();\n }\n });\n\n // 最大值输入框回车事件\n this.valueInputMax.addEventListener('keypress', event => {\n if (event.key === 'Enter') {\n this.applyFilter();\n }\n });\n\n // 分类切换事件\n this.categorySelect.addEventListener('change', () => {\n this.handleCategoryChange();\n });\n\n // 操作符切换事件\n this.operatorSelect.addEventListener('change', () => {\n const selectedOperator = this.operatorSelect.value as FilterOperator;\n const andLabel = this.valueInput.nextElementSibling as HTMLElement;\n\n if (this.isRangeOperator(selectedOperator)) {\n this.valueInput.placeholder = '最小值';\n this.valueInputMax.style.display = 'inline-block';\n andLabel.style.display = 'inline-block';\n } else {\n this.valueInput.placeholder = '请输入筛选值';\n this.valueInputMax.style.display = 'none';\n andLabel.style.display = 'none';\n }\n });\n }\n\n /**\n * 显示筛选面板\n */\n show(): void {\n if (this.filterByConditionPanel) {\n this.filterByConditionPanel.style.display = 'block';\n this.loadCurrentFilterState();\n }\n }\n\n /**\n * 隐藏筛选面板\n */\n hide(): void {\n if (this.filterByConditionPanel) {\n this.filterByConditionPanel.style.display = 'none';\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/filter/condition-filter.ts"],"names":[],"mappings":";;;AAEA,qCAAoE;AAQpE,mCAAmE;AACnE,yCAAuC;AAKvC,MAAa,eAAe;IA0B1B,YACE,KAA6B,EAC7B,kBAAsC,EACtC,aAA4B,EAC5B,iBAA6B;QATvB,oBAAe,GAA2B,8BAAsB,CAAC,GAAG,CAAC;QAErE,eAAU,GAAmC,EAAE,CAAC;QAC9C,cAAS,GAAqB,EAAE,CAAC;QAQzC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC7C,IAAI,CAAC,aAA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,IAAI;QACF,IAAI,IAAI,CAAC,sBAAsB,EAAE;YAC/B,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;YACpD,IAAI,CAAC,sBAAsB,EAAE,CAAC;SAC/B;IACH,CAAC;IAKD,IAAI;QACF,IAAI,IAAI,CAAC,sBAAsB,EAAE;YAC/B,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;SACpD;IACH,CAAC;CACF;AAtbD,0CAsbC","file":"condition-filter.js","sourcesContent":["import type { ListTable, PivotTable } from '@visactor/vtable';\nimport type { FilterStateManager } from './filter-state-manager';\nimport { applyStyles, filterStyles, createElement } from './styles';\nimport type {\n FilterOperator,\n FilterOperatorCategoryOption,\n FilterOptions,\n FilterStyles,\n OperatorOption\n} from './types';\nimport { FilterActionType, FilterOperatorCategory } from './types';\nimport { operators } from './constant';\n\n/**\n * 按条件筛选组件\n */\nexport class ConditionFilter {\n private table: ListTable | PivotTable;\n private filterStateManager: FilterStateManager;\n private pluginOptions: FilterOptions;\n private filterToolBarHide: () => void;\n\n private styles: Record<any, any>;\n\n private filterByConditionPanel: HTMLElement;\n private conditionContainer: HTMLElement;\n private categoryLabel: HTMLElement;\n private selectedField: string | number;\n private operatorSelect: HTMLSelectElement;\n private valueInput: HTMLInputElement;\n private andLabel: HTMLElement;\n private valueInputMax: HTMLInputElement;\n private categorySelect: HTMLSelectElement;\n private operatorLabel: HTMLElement;\n private rangeInputContainer: HTMLElement;\n private valueLabel: HTMLElement;\n\n private currentCategory: FilterOperatorCategory = FilterOperatorCategory.ALL;\n\n private categories: FilterOperatorCategoryOption[] = [];\n protected operators: OperatorOption[] = [];\n\n constructor(\n table: ListTable | PivotTable,\n filterStateManager: FilterStateManager,\n pluginOptions: FilterOptions,\n filterToolBarHide: () => void\n ) {\n this.table = table;\n this.filterStateManager = filterStateManager;\n this.pluginOptions = pluginOptions;\n this.styles = pluginOptions.styles || {};\n this.categories = pluginOptions.conditionCategories;\n this.operators = operators;\n this.filterToolBarHide = filterToolBarHide;\n }\n\n setSelectedField(fieldId: string | number): void {\n this.selectedField = fieldId;\n this.updateOperatorOptions();\n this.loadCurrentFilterState();\n }\n\n /**\n * 更新操作符下拉选项\n */\n private updateOperatorOptions(): void {\n if (!this.operatorSelect) {\n return;\n }\n this.operatorSelect.innerHTML = '';\n let filteredOperators: OperatorOption[];\n\n if (this.currentCategory === FilterOperatorCategory.ALL) {\n // 当选择\"全部\"时,收集所有配置的分类中, 不重复的操作符\n const uniqueOperators = new Map<string, OperatorOption>();\n this.operators\n .filter(op => this.categories.map(cat => cat.value).includes(op.category))\n .forEach(op => {\n if (!uniqueOperators.has(op.value)) {\n uniqueOperators.set(op.value, op);\n }\n });\n filteredOperators = Array.from(uniqueOperators.values());\n } else {\n // 其他类别正常筛选\n filteredOperators = this.operators.filter(op => op.category === this.currentCategory);\n }\n\n // 添加新选项\n filteredOperators.forEach(op => {\n const option = document.createElement('option');\n option.value = op.value;\n option.textContent = op.label;\n this.operatorSelect.appendChild(option);\n });\n }\n\n private handleCategoryChange(): void {\n if (!this.categorySelect) {\n return;\n }\n\n this.currentCategory = this.categorySelect.value as FilterOperatorCategory;\n this.updateOperatorOptions();\n\n // 分类切换后也需要同步UI状态\n this.syncUIState();\n }\n\n /**\n * 加载当前的筛选状态\n */\n private loadCurrentFilterState(): void {\n const filter = this.filterStateManager.getFilterState(this.selectedField);\n const syncFilterItemsState = this.pluginOptions?.syncFilterItemsState ?? true;\n\n // 不联动的场景下, 用户的配置始终会被展示出来\n if ((filter && filter.type === 'byCondition') || !syncFilterItemsState) {\n // 设置操作符\n if (this.operatorSelect) {\n this.operatorSelect.value = filter?.operator ?? operators[0].value;\n }\n\n // 设置条件值\n if (this.valueInput) {\n if (Array.isArray(filter?.condition)) {\n this.valueInput.value = String(filter.condition[0]);\n if (this.valueInputMax) {\n this.valueInputMax.value = String(filter.condition[1]);\n }\n } else {\n this.valueInput.value = String(filter?.condition ?? '');\n if (this.valueInputMax) {\n this.valueInputMax.value = '';\n }\n }\n }\n\n // 同步UI状态:根据当前操作符显示/隐藏范围输入框\n this.syncUIState();\n } else {\n // 重置为默认值\n this.reset();\n }\n }\n\n /**\n * 重置筛选条件到默认状态\n */\n reset(): void {\n // 重置操作符选择\n if (this.operatorSelect) {\n this.operatorSelect.selectedIndex = 0;\n }\n\n // 重置所有输入框\n if (this.valueInput) {\n this.valueInput.value = '';\n this.valueInput.placeholder = '请输入筛选值';\n }\n\n if (this.valueInputMax) {\n this.valueInputMax.value = '';\n }\n\n // 重置分类选择\n this.currentCategory = FilterOperatorCategory.ALL;\n if (this.categorySelect) {\n this.categorySelect.value = FilterOperatorCategory.ALL;\n }\n\n // 更新操作符选项\n this.updateOperatorOptions();\n\n // 同步UI状态\n this.syncUIState();\n }\n\n /**\n * 同步UI状态:根据当前选择的操作符调整UI显示\n */\n private syncUIState(): void {\n if (!this.operatorSelect || !this.valueInput) {\n return;\n }\n\n const selectedOperator = this.operatorSelect.value as FilterOperator;\n const andLabel = this.valueInput.nextElementSibling as HTMLElement;\n\n if (this.isRangeOperator(selectedOperator)) {\n // 显示范围输入相关UI\n this.valueInput.placeholder = '最小值';\n if (this.valueInputMax) {\n this.valueInputMax.style.display = 'inline-block';\n }\n if (andLabel) {\n andLabel.style.display = 'inline-block';\n }\n } else {\n // 隐藏范围输入相关UI\n this.valueInput.placeholder = '请输入筛选值';\n if (this.valueInputMax) {\n this.valueInputMax.style.display = 'none';\n }\n if (andLabel) {\n andLabel.style.display = 'none';\n }\n }\n }\n\n private isBooleanOperator(operator: FilterOperator): boolean {\n const booleanCondition = ['isChecked', 'isUnchecked'];\n return booleanCondition.includes(operator);\n }\n\n private isRangeOperator(operator: FilterOperator): boolean {\n return operator === 'between' || operator === 'notBetween';\n }\n\n /**\n * 应用筛选条件\n */\n applyFilter(fieldId: string | number = this.selectedField): void {\n if (!this.operatorSelect || !this.valueInput) {\n return;\n }\n\n const operator = this.operatorSelect?.value as FilterOperator;\n let conditionValue: any = this.valueInput?.value;\n\n // 根据所选操作符和分类尝试转换输入值\n if (this.currentCategory === FilterOperatorCategory.NUMBER) {\n conditionValue = parseFloat(conditionValue);\n if (isNaN(conditionValue)) {\n console.warn('请输入有效的数字');\n return;\n }\n }\n\n // 处理范围操作符的双值输入\n if (this.isRangeOperator(operator)) {\n const minValue = conditionValue;\n let maxValue: string | number = this.valueInputMax.value.trim();\n\n // 尝试将最大值也转换为数字\n if (this.currentCategory === FilterOperatorCategory.NUMBER) {\n const numMaxValue = parseFloat(maxValue);\n if (!isNaN(numMaxValue)) {\n maxValue = numMaxValue;\n } else {\n console.warn('请输入有效的最大值');\n return;\n }\n }\n\n // 使用数组形式传递范围值\n conditionValue = [minValue, maxValue];\n }\n\n if (!conditionValue && conditionValue !== false && conditionValue !== 0 && !this.isBooleanOperator(operator)) {\n this.clearFilter(fieldId);\n return;\n }\n\n // TODO:处理单元格颜色和字体颜色的筛选\n const syncFilterItemsState = this.pluginOptions?.syncFilterItemsState ?? true;\n this.filterStateManager.dispatch({\n type: FilterActionType.APPLY_FILTERS,\n payload: {\n field: fieldId,\n type: 'byCondition',\n operator,\n condition: conditionValue,\n enable: true,\n shouldKeepUnrelatedState: !syncFilterItemsState\n }\n });\n }\n\n /**\n * 清除筛选\n */\n clearFilter(fieldId: string | number): void {\n this.filterStateManager.dispatch({\n type: FilterActionType.REMOVE_FILTER,\n payload: {\n field: fieldId\n }\n });\n\n this.hide();\n }\n\n /**\n * 渲染条件筛选面板\n */\n render(container: HTMLElement): void {\n const filterStyles = this.styles;\n // 按条件筛选面板\n this.filterByConditionPanel = document.createElement('div');\n applyStyles(this.filterByConditionPanel, filterStyles.filterPanel);\n\n // 条件选择区域\n this.conditionContainer = document.createElement('div');\n applyStyles(this.conditionContainer, this.styles.conditionContainer);\n\n // 分类选择下拉框\n this.categoryLabel = createElement('label', {}, ['筛选类型:']);\n applyStyles(this.categoryLabel, this.styles.formLabel);\n\n this.categorySelect = createElement('select') as HTMLSelectElement;\n applyStyles(this.categorySelect, filterStyles.operatorSelect);\n\n // 添加分类选项\n this.categories.forEach(category => {\n const option = document.createElement('option');\n option.value = category.value;\n option.textContent = category.label;\n this.categorySelect.appendChild(option);\n });\n\n // 操作符选择下拉框\n this.operatorLabel = createElement('label', {}, ['筛选条件:']);\n applyStyles(this.operatorLabel, this.styles.formLabel);\n\n this.operatorSelect = createElement('select') as HTMLSelectElement;\n applyStyles(this.operatorSelect, filterStyles.operatorSelect);\n\n // 条件值输入框\n this.valueLabel = createElement('label', {}, ['筛选值:']);\n applyStyles(this.valueLabel, this.styles.formLabel);\n\n // 一个容器来包装两个输入框和\"和\"字\n this.rangeInputContainer = createElement('div');\n applyStyles(this.rangeInputContainer, this.styles.rangeInputContainer);\n\n this.valueInput = createElement('input', {\n type: 'text',\n placeholder: '请输入筛选值'\n }) as HTMLInputElement;\n applyStyles(this.valueInput, filterStyles.searchInput);\n\n // \"和\"字标签\n this.andLabel = createElement('span', {}, ['和']);\n applyStyles(this.andLabel, this.styles.addLabel);\n this.andLabel.style.display = 'none'; // 默认隐藏\n\n // 范围筛选的最大值输入框\n this.valueInputMax = createElement('input', {\n type: 'text',\n placeholder: '最大值'\n }) as HTMLInputElement;\n applyStyles(this.valueInputMax, filterStyles.searchInput);\n this.valueInputMax.style.display = 'none'; // 默认隐藏\n\n // 将输入框和\"和\"字添加到容器中\n this.rangeInputContainer.appendChild(this.valueInput);\n this.rangeInputContainer.appendChild(this.andLabel);\n this.rangeInputContainer.appendChild(this.valueInputMax);\n\n // 将元素添加到容器中\n this.conditionContainer.appendChild(this.categoryLabel);\n this.conditionContainer.appendChild(this.categorySelect);\n this.conditionContainer.appendChild(this.operatorLabel);\n this.conditionContainer.appendChild(this.operatorSelect);\n this.conditionContainer.appendChild(this.valueLabel);\n this.conditionContainer.appendChild(this.rangeInputContainer);\n\n this.filterByConditionPanel.appendChild(this.conditionContainer);\n container.appendChild(this.filterByConditionPanel);\n\n // 默认隐藏\n this.hide();\n\n // 初始化操作符选项\n this.updateOperatorOptions();\n this.bindEvents();\n }\n\n updateStyles(styles: FilterStyles) {\n applyStyles(this.filterByConditionPanel, styles.filterPanel);\n applyStyles(this.conditionContainer, styles.conditionContainer);\n applyStyles(this.categoryLabel, styles.formLabel);\n applyStyles(this.categorySelect, styles.operatorSelect);\n applyStyles(this.operatorLabel, styles.formLabel);\n applyStyles(this.operatorSelect, styles.operatorSelect);\n applyStyles(this.valueLabel, styles.formLabel);\n applyStyles(this.rangeInputContainer, styles.rangeInputContainer);\n applyStyles(this.valueInput, styles.searchInput);\n applyStyles(this.andLabel, styles.addLabel);\n applyStyles(this.valueInputMax, styles.searchInput);\n }\n\n /**\n * 绑定事件\n */\n private bindEvents(): void {\n // 输入框回车事件\n this.valueInput.addEventListener('keypress', event => {\n if (event.key === 'Enter') {\n this.applyFilter();\n this.filterToolBarHide();\n }\n });\n\n // 最大值输入框回车事件\n this.valueInputMax.addEventListener('keypress', event => {\n if (event.key === 'Enter') {\n this.applyFilter();\n this.filterToolBarHide();\n }\n });\n\n // 分类切换事件\n this.categorySelect.addEventListener('change', () => {\n this.handleCategoryChange();\n });\n\n // 操作符切换事件\n this.operatorSelect.addEventListener('change', () => {\n const selectedOperator = this.operatorSelect.value as FilterOperator;\n const andLabel = this.valueInput.nextElementSibling as HTMLElement;\n\n if (this.isRangeOperator(selectedOperator)) {\n this.valueInput.placeholder = '最小值';\n this.valueInputMax.style.display = 'inline-block';\n andLabel.style.display = 'inline-block';\n } else {\n this.valueInput.placeholder = '请输入筛选值';\n this.valueInputMax.style.display = 'none';\n andLabel.style.display = 'none';\n }\n });\n }\n\n /**\n * 显示筛选面板\n */\n show(): void {\n if (this.filterByConditionPanel) {\n this.filterByConditionPanel.style.display = 'block';\n this.loadCurrentFilterState();\n }\n }\n\n /**\n * 隐藏筛选面板\n */\n hide(): void {\n if (this.filterByConditionPanel) {\n this.filterByConditionPanel.style.display = 'none';\n }\n }\n}\n"]}
|
|
@@ -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,IAAI,EAAE,QAAQ,EAAE,8BAAsB,CAAC,KAAK,EAAE;IACxE,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,8BAAsB,CAAC,KAAK,EAAE;IAG5E,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,8BAAsB,CAAC,QAAQ,EAAE;IAC/E,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,8BAAsB,CAAC,QAAQ,EAAE;IAGjF,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,8BAAsB,CAAC,KAAK,EAAE;IAC5E,EAAE,KAAK,EAAE,aAAa,EAAE,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) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/filter/filter-engine.ts"],"names":[],"mappings":";;;AAMA,MAAa,YAAY;
|
|
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;;QA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AAI,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;AAzID,oCAyIC","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 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"]}
|
|
@@ -6,7 +6,6 @@ export declare class FilterStateManager {
|
|
|
6
6
|
private engine;
|
|
7
7
|
private listeners;
|
|
8
8
|
private table;
|
|
9
|
-
private filterMenuStates;
|
|
10
9
|
constructor(table: ListTable | PivotTable, engine: FilterEngine);
|
|
11
10
|
getFilterState(fieldId?: string | number): FilterConfig;
|
|
12
11
|
getActiveFilterFields(): (string | number)[];
|
|
@@ -18,17 +17,4 @@ export declare class FilterStateManager {
|
|
|
18
17
|
private reduce;
|
|
19
18
|
private applyFilters;
|
|
20
19
|
private shouldApplyFilter;
|
|
21
|
-
initializeFilterMenuState(fieldId: string | number, candidateValues: Array<{
|
|
22
|
-
value: any;
|
|
23
|
-
count: number;
|
|
24
|
-
rawValue: any;
|
|
25
|
-
}>, displayToRawMap: Map<any, any>): void;
|
|
26
|
-
getStableCandidateValues(fieldId: string | number): Array<{
|
|
27
|
-
value: any;
|
|
28
|
-
count: number;
|
|
29
|
-
rawValue: any;
|
|
30
|
-
}>;
|
|
31
|
-
updateSearchKeyword(fieldId: string | number, keyword: string): void;
|
|
32
|
-
getVisibleSelectedValues(fieldId: string | number): Set<any>;
|
|
33
|
-
getCurrentSearchKeyword(fieldId: string | number): string;
|
|
34
20
|
}
|
|
@@ -8,7 +8,7 @@ const types_1 = require("./types");
|
|
|
8
8
|
|
|
9
9
|
class FilterStateManager {
|
|
10
10
|
constructor(table, engine) {
|
|
11
|
-
this.listeners = [], this.
|
|
11
|
+
this.listeners = [], this.state = {
|
|
12
12
|
filters: new Map
|
|
13
13
|
}, this.engine = engine, this.table = table;
|
|
14
14
|
}
|
|
@@ -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.
|
|
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:
|
|
@@ -85,40 +91,6 @@ class FilterStateManager {
|
|
|
85
91
|
shouldApplyFilter(action) {
|
|
86
92
|
return [ types_1.FilterActionType.REMOVE_FILTER, types_1.FilterActionType.ENABLE_FILTER, types_1.FilterActionType.DISABLE_FILTER, types_1.FilterActionType.CLEAR_ALL_FILTERS, types_1.FilterActionType.APPLY_FILTERS ].includes(action.type);
|
|
87
93
|
}
|
|
88
|
-
initializeFilterMenuState(fieldId, candidateValues, displayToRawMap) {
|
|
89
|
-
this.filterMenuStates.set(fieldId, {
|
|
90
|
-
stableCandidateValues: candidateValues,
|
|
91
|
-
currentSearchKeyword: "",
|
|
92
|
-
displayToRawMap: displayToRawMap
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
getStableCandidateValues(fieldId) {
|
|
96
|
-
var _a;
|
|
97
|
-
return (null === (_a = this.filterMenuStates.get(fieldId)) || void 0 === _a ? void 0 : _a.stableCandidateValues) || [];
|
|
98
|
-
}
|
|
99
|
-
updateSearchKeyword(fieldId, keyword) {
|
|
100
|
-
const menuState = this.filterMenuStates.get(fieldId);
|
|
101
|
-
menuState && (menuState.currentSearchKeyword = keyword);
|
|
102
|
-
}
|
|
103
|
-
getVisibleSelectedValues(fieldId) {
|
|
104
|
-
const menuState = this.filterMenuStates.get(fieldId), filter = this.getFilterState(fieldId);
|
|
105
|
-
if (!menuState || !(null == filter ? void 0 : filter.values)) return new Set;
|
|
106
|
-
const allSelectedValues = new Set(filter.values), filterKeywords = menuState.currentSearchKeyword.toUpperCase().split(" ").filter((s => s));
|
|
107
|
-
if (0 === filterKeywords.length) return allSelectedValues;
|
|
108
|
-
const visibleSelected = new Set;
|
|
109
|
-
for (const candidate of menuState.stableCandidateValues) {
|
|
110
|
-
const displayValue = candidate.value, txtValue = String(displayValue).toUpperCase(), match = filterKeywords.some((keyword => txtValue.includes(keyword)));
|
|
111
|
-
if (match) {
|
|
112
|
-
const rawValue = menuState.displayToRawMap ? menuState.displayToRawMap.get(displayValue) : displayValue;
|
|
113
|
-
allSelectedValues.has(rawValue) && visibleSelected.add(rawValue);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return visibleSelected;
|
|
117
|
-
}
|
|
118
|
-
getCurrentSearchKeyword(fieldId) {
|
|
119
|
-
var _a;
|
|
120
|
-
return (null === (_a = this.filterMenuStates.get(fieldId)) || void 0 === _a ? void 0 : _a.currentSearchKeyword) || "";
|
|
121
|
-
}
|
|
122
94
|
}
|
|
123
95
|
|
|
124
96
|
exports.FilterStateManager = FilterStateManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/filter/filter-state-manager.ts"],"names":[],"mappings":";;;AAEA,mCAA2C;AAM3C,MAAa,kBAAkB;IAoB7B,YAAY,KAA6B,EAAE,MAAoB;QAjBvD,cAAS,GAA0B,EAAE,CAAC;QAKtC,qBA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AAM,QAAQ,GAAG,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;gBACxG,IAAI,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;oBACnC,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;iBAC/B;aACF;SACF;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;IAKD,uBAAuB,CAAC,OAAwB;;QAC9C,OAAO,CAAA,MAAA,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,0CAAE,oBAAoB,KAAI,EAAE,CAAC;IACxE,CAAC;CACF;AAlND,gDAkNC","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 // 筛选菜单相关的状态\n private filterMenuStates: Map<\n string | number,\n {\n // 筛选菜单打开时固定的候选值列表\n stableCandidateValues: Array<{ value: any; count: number; rawValue: any }>;\n // 当前搜索关键词\n currentSearchKeyword: string;\n // 显示值到原始值的映射\n displayToRawMap: Map<any, any>;\n }\n > = new Map();\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 /**\n * 初始化筛选菜单状态(当筛选菜单打开时调用)\n */\n initializeFilterMenuState(\n fieldId: string | number,\n candidateValues: Array<{ value: any; count: number; rawValue: any }>,\n displayToRawMap: Map<any, any>\n ): void {\n this.filterMenuStates.set(fieldId, {\n stableCandidateValues: candidateValues,\n currentSearchKeyword: '',\n displayToRawMap: displayToRawMap\n });\n }\n\n /**\n * 获取筛选菜单的稳定候选值列表\n */\n getStableCandidateValues(fieldId: string | number): Array<{ value: any; count: number; rawValue: any }> {\n return this.filterMenuStates.get(fieldId)?.stableCandidateValues || [];\n }\n\n /**\n * 更新搜索关键词\n */\n updateSearchKeyword(fieldId: string | number, keyword: string): void {\n const menuState = this.filterMenuStates.get(fieldId);\n if (!menuState) {\n return;\n }\n\n menuState.currentSearchKeyword = keyword;\n }\n\n /**\n * 获取当前可见的选中值(根据搜索关键词从筛选状态中筛选)\n */\n getVisibleSelectedValues(fieldId: string | number): Set<any> {\n const menuState = this.filterMenuStates.get(fieldId);\n const filter = this.getFilterState(fieldId);\n if (!menuState || !filter?.values) {\n return new Set();\n }\n\n const allSelectedValues = new Set(filter.values);\n const keyword = menuState.currentSearchKeyword;\n const filterKeywords = keyword\n .toUpperCase()\n .split(' ')\n .filter(s => s);\n\n // 如果没有搜索关键词,返回所有被选中的值\n if (filterKeywords.length === 0) {\n return allSelectedValues;\n }\n\n // 根据搜索关键词筛选出可见的选中值\n const visibleSelected = new Set<any>();\n for (const candidate of menuState.stableCandidateValues) {\n const displayValue = candidate.value;\n const txtValue = String(displayValue).toUpperCase();\n\n // 检查是否匹配搜索关键词\n const match = filterKeywords.some(keyword => txtValue.includes(keyword));\n\n if (match) {\n // 如果可见,检查是否被选中\n const rawValue = menuState.displayToRawMap ? menuState.displayToRawMap.get(displayValue) : displayValue;\n if (allSelectedValues.has(rawValue)) {\n visibleSelected.add(rawValue);\n }\n }\n }\n\n return visibleSelected;\n }\n\n /**\n * 获取当前搜索关键词\n */\n getCurrentSearchKeyword(fieldId: string | number): string {\n return this.filterMenuStates.get(fieldId)?.currentSearchKeyword || '';\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,MAAoB;QAC3B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC7C,IAAI,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE;YAClC,IAAI,CAA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,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"]}
|
|
@@ -6,7 +6,7 @@ import type { FilterMode, FilterOptions, FilterStyles } from './types';
|
|
|
6
6
|
export declare class FilterToolbar {
|
|
7
7
|
table: ListTable | PivotTable;
|
|
8
8
|
filterStateManager: FilterStateManager;
|
|
9
|
-
|
|
9
|
+
pluginOptions: FilterOptions;
|
|
10
10
|
valueFilter: ValueFilter | null;
|
|
11
11
|
conditionFilter: ConditionFilter | null;
|
|
12
12
|
activeTab: 'byValue' | 'byCondition';
|
|
@@ -24,8 +24,8 @@ export declare class FilterToolbar {
|
|
|
24
24
|
private clearFilterOptionLink;
|
|
25
25
|
private cancelFilterButton;
|
|
26
26
|
private applyFilterButton;
|
|
27
|
+
private activeType;
|
|
27
28
|
constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager, pluginOptions: FilterOptions);
|
|
28
|
-
updatePluginOptions(pluginOptions: FilterOptions): void;
|
|
29
29
|
private onTabSwitch;
|
|
30
30
|
private updateSelectedField;
|
|
31
31
|
private applyFilter;
|
|
@@ -36,5 +36,6 @@ export declare class FilterToolbar {
|
|
|
36
36
|
attachEventListeners(): void;
|
|
37
37
|
adjustMenuPosition(col?: number | null, row?: number | null, providedLeft?: number | null, providedTop?: number | null): void;
|
|
38
38
|
show(col: number, row: number, filterModes: FilterMode[]): void;
|
|
39
|
-
hide(currentCol
|
|
39
|
+
hide: (currentCol?: number, currentRow?: number) => void;
|
|
40
|
+
destroy(): void;
|
|
40
41
|
}
|