@visactor/vtable-plugins 1.22.4-alpha.2 → 1.22.4
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/rules.js +2 -1
- package/cjs/contextmenu/menu-manager.js +1 -2
- package/cjs/filter/condition-filter.d.ts +1 -3
- package/cjs/filter/condition-filter.js +20 -20
- package/cjs/filter/condition-filter.js.map +1 -1
- package/cjs/filter/filter-state-manager.d.ts +0 -14
- package/cjs/filter/filter-state-manager.js +1 -35
- package/cjs/filter/filter-state-manager.js.map +1 -1
- package/cjs/filter/filter-toolbar.d.ts +5 -4
- package/cjs/filter/filter-toolbar.js +30 -30
- package/cjs/filter/filter-toolbar.js.map +1 -1
- package/cjs/filter/filter.d.ts +4 -3
- package/cjs/filter/filter.js +15 -19
- package/cjs/filter/filter.js.map +1 -1
- package/cjs/filter/styles.d.ts +124 -2
- package/cjs/filter/styles.js.map +1 -1
- package/cjs/filter/types.d.ts +0 -27
- package/cjs/filter/types.js.map +1 -1
- package/cjs/filter/value-filter.d.ts +1 -5
- package/cjs/filter/value-filter.js +118 -145
- package/cjs/filter/value-filter.js.map +1 -1
- package/cjs/gantt-export-image.d.ts +0 -1
- package/cjs/gantt-export-image.js +2 -10
- package/cjs/gantt-export-image.js.map +1 -1
- package/cjs/master-detail-plugin/config.js +2 -2
- package/cjs/master-detail-plugin/config.js.map +1 -1
- package/cjs/table-export/csv/index.js +1 -1
- package/cjs/table-export/csv/index.js.map +1 -1
- package/dist/vtable-plugins.js +211 -9794
- package/dist/vtable-plugins.min.js +3 -3
- package/es/auto-fill/rules.js +2 -1
- package/es/contextmenu/menu-manager.js +1 -2
- package/es/filter/condition-filter.d.ts +1 -3
- package/es/filter/condition-filter.js +14 -14
- package/es/filter/condition-filter.js.map +1 -1
- package/es/filter/filter-state-manager.d.ts +0 -14
- package/es/filter/filter-state-manager.js +1 -35
- package/es/filter/filter-state-manager.js.map +1 -1
- package/es/filter/filter-toolbar.d.ts +5 -4
- package/es/filter/filter-toolbar.js +28 -29
- package/es/filter/filter-toolbar.js.map +1 -1
- package/es/filter/filter.d.ts +4 -3
- package/es/filter/filter.js +13 -21
- package/es/filter/filter.js.map +1 -1
- package/es/filter/styles.d.ts +124 -2
- package/es/filter/styles.js.map +1 -1
- package/es/filter/types.d.ts +0 -27
- package/es/filter/types.js.map +1 -1
- package/es/filter/value-filter.d.ts +1 -5
- package/es/filter/value-filter.js +118 -145
- package/es/filter/value-filter.js.map +1 -1
- package/es/gantt-export-image.d.ts +0 -1
- package/es/gantt-export-image.js +1 -11
- package/es/gantt-export-image.js.map +1 -1
- package/es/master-detail-plugin/config.js +2 -2
- package/es/master-detail-plugin/config.js.map +1 -1
- package/es/table-export/csv/index.js +1 -1
- package/es/table-export/csv/index.js.map +1 -1
- package/package.json +8 -8
package/cjs/auto-fill/rules.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { ListTable, PivotTable } from '@visactor/vtable';
|
|
2
2
|
import type { FilterStateManager } from './filter-state-manager';
|
|
3
|
-
import type { FilterStyles } from './types';
|
|
4
3
|
export declare class ConditionFilter {
|
|
5
4
|
private table;
|
|
6
5
|
private filterStateManager;
|
|
7
|
-
private styles;
|
|
8
6
|
private filterByConditionPanel;
|
|
9
7
|
private selectedField;
|
|
10
8
|
private operatorSelect;
|
|
@@ -14,7 +12,7 @@ export declare class ConditionFilter {
|
|
|
14
12
|
private currentCategory;
|
|
15
13
|
private operators;
|
|
16
14
|
private categories;
|
|
17
|
-
constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager
|
|
15
|
+
constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager);
|
|
18
16
|
setSelectedField(fieldId: string | number): void;
|
|
19
17
|
private updateOperatorOptions;
|
|
20
18
|
private handleCategoryChange;
|
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
const styles_1 = require("./styles"), types_1 = require("./types");
|
|
8
8
|
|
|
9
9
|
class ConditionFilter {
|
|
10
|
-
constructor(table, filterStateManager
|
|
10
|
+
constructor(table, filterStateManager) {
|
|
11
11
|
this.currentCategory = types_1.FilterOperatorCategory.ALL, this.operators = [ {
|
|
12
12
|
value: "equals",
|
|
13
13
|
label: "等于",
|
|
@@ -122,7 +122,7 @@ class ConditionFilter {
|
|
|
122
122
|
}, {
|
|
123
123
|
value: types_1.FilterOperatorCategory.RADIO,
|
|
124
124
|
label: "单选框"
|
|
125
|
-
} ], this.table = table, this.
|
|
125
|
+
} ], this.table = table, this.filterStateManager = filterStateManager;
|
|
126
126
|
}
|
|
127
127
|
setSelectedField(fieldId) {
|
|
128
128
|
this.selectedField = fieldId, this.updateOperatorOptions(), this.loadCurrentFilterState();
|
|
@@ -209,40 +209,40 @@ class ConditionFilter {
|
|
|
209
209
|
}), this.hide();
|
|
210
210
|
}
|
|
211
211
|
render(container) {
|
|
212
|
-
this.filterByConditionPanel = document.createElement("div"), (0, styles_1.applyStyles)(this.filterByConditionPanel,
|
|
212
|
+
this.filterByConditionPanel = document.createElement("div"), (0, styles_1.applyStyles)(this.filterByConditionPanel, styles_1.filterStyles.filterPanel);
|
|
213
213
|
const conditionContainer = document.createElement("div");
|
|
214
|
-
(0, styles_1.applyStyles)(conditionContainer,
|
|
214
|
+
(0, styles_1.applyStyles)(conditionContainer, styles_1.filterStyles.conditionContainer);
|
|
215
215
|
const categoryLabel = (0, styles_1.createElement)("label", {}, [ "筛选类型:" ]);
|
|
216
|
-
(0, styles_1.applyStyles)(categoryLabel,
|
|
217
|
-
styles_1.createElement)("select"), (0, styles_1.applyStyles)(this.categorySelect,
|
|
216
|
+
(0, styles_1.applyStyles)(categoryLabel, styles_1.filterStyles.formLabel), this.categorySelect = (0,
|
|
217
|
+
styles_1.createElement)("select"), (0, styles_1.applyStyles)(this.categorySelect, styles_1.filterStyles.operatorSelect),
|
|
218
218
|
this.categories.forEach((category => {
|
|
219
219
|
const option = document.createElement("option");
|
|
220
220
|
option.value = category.value, option.textContent = category.label, this.categorySelect.appendChild(option);
|
|
221
221
|
}));
|
|
222
222
|
const operatorLabel = (0, styles_1.createElement)("label", {}, [ "筛选条件:" ]);
|
|
223
|
-
(0, styles_1.applyStyles)(operatorLabel,
|
|
224
|
-
styles_1.createElement)("select"), (0, styles_1.applyStyles)(this.operatorSelect,
|
|
223
|
+
(0, styles_1.applyStyles)(operatorLabel, styles_1.filterStyles.formLabel), this.operatorSelect = (0,
|
|
224
|
+
styles_1.createElement)("select"), (0, styles_1.applyStyles)(this.operatorSelect, styles_1.filterStyles.operatorSelect);
|
|
225
225
|
const valueLabel = (0, styles_1.createElement)("label", {}, [ "筛选值:" ]);
|
|
226
|
-
(0, styles_1.applyStyles)(valueLabel,
|
|
226
|
+
(0, styles_1.applyStyles)(valueLabel, styles_1.filterStyles.formLabel);
|
|
227
227
|
const rangeInputContainer = (0, styles_1.createElement)("div");
|
|
228
|
-
(0, styles_1.applyStyles)(rangeInputContainer,
|
|
228
|
+
(0, styles_1.applyStyles)(rangeInputContainer, styles_1.filterStyles.rangeInputContainer),
|
|
229
229
|
this.valueInput = (0, styles_1.createElement)("input", {
|
|
230
230
|
type: "text",
|
|
231
231
|
placeholder: "请输入筛选值"
|
|
232
|
-
}), (0, styles_1.applyStyles)(this.valueInput,
|
|
232
|
+
}), (0, styles_1.applyStyles)(this.valueInput, styles_1.filterStyles.searchInput);
|
|
233
233
|
const andLabel = (0, styles_1.createElement)("span", {}, [ "和" ]);
|
|
234
|
-
(0, styles_1.applyStyles)(andLabel,
|
|
234
|
+
(0, styles_1.applyStyles)(andLabel, styles_1.filterStyles.addLabel), andLabel.style.display = "none",
|
|
235
235
|
this.valueInputMax = (0, styles_1.createElement)("input", {
|
|
236
236
|
type: "text",
|
|
237
237
|
placeholder: "最大值"
|
|
238
|
-
}), (0, styles_1.applyStyles)(this.valueInputMax,
|
|
239
|
-
|
|
240
|
-
rangeInputContainer.appendChild(
|
|
241
|
-
conditionContainer.appendChild(
|
|
242
|
-
conditionContainer.appendChild(
|
|
243
|
-
conditionContainer.appendChild(
|
|
244
|
-
|
|
245
|
-
this.bindEvents();
|
|
238
|
+
}), (0, styles_1.applyStyles)(this.valueInputMax, styles_1.filterStyles.searchInput),
|
|
239
|
+
this.valueInputMax.style.display = "none", rangeInputContainer.appendChild(this.valueInput),
|
|
240
|
+
rangeInputContainer.appendChild(andLabel), rangeInputContainer.appendChild(this.valueInputMax),
|
|
241
|
+
conditionContainer.appendChild(categoryLabel), conditionContainer.appendChild(this.categorySelect),
|
|
242
|
+
conditionContainer.appendChild(operatorLabel), conditionContainer.appendChild(this.operatorSelect),
|
|
243
|
+
conditionContainer.appendChild(valueLabel), conditionContainer.appendChild(rangeInputContainer),
|
|
244
|
+
this.filterByConditionPanel.appendChild(conditionContainer), container.appendChild(this.filterByConditionPanel),
|
|
245
|
+
this.hide(), this.updateOperatorOptions(), this.bindEvents();
|
|
246
246
|
}
|
|
247
247
|
bindEvents() {
|
|
248
248
|
this.valueInput.addEventListener("keypress", (event => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/filter/condition-filter.ts"],"names":[],"mappings":";;;AAEA,qCAAsD;AAEtD,mCAAmE;AAKnE,MAAa,eAAe;IA8D1B,YAAY,KAA6B,EAAE,kBAAsC,EAAE,MAAoB;QAnD/F,oBAAe,GAA2B,8BAAsB,CAAC,GAAG,CAAC;QAGrE,cAAS,GAAqB;YAEpC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,8BAAsB,CAAC,GAAG,EAAE;YACtE,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,8BAAsB,CAAC,GAAG,EAAE;YAG1E,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,8BAAsB,CAAC,MAAM,EAAE;YACzE,EAAE,KAAK,EAAE,WAAW,EAAE,K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C9B,CAAC,CAAC,CAAC;QAGH,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,EAAE;YAClD,MAAM,gBAAgB,GAAG,IAAI,CAAC,cAAc,CAAC,KAAuB,CAAC;YACrE,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,kBAAiC,CAAC;YAEnE,IAAI,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,EAAE;gBAC1C,IAAI,CAAC,UAAU,CAAC,WAAW,GAAG,KAAK,CAAC;gBACpC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,OAAO,GAAG,cAAc,CAAC;gBAClD,QAAQ,CAAC,KAAK,CAAC,OAAO,GAAG,cAAc,CAAC;aACzC;iBAAM;gBACL,IAAI,CAAC,UAAU,CAAC,WAAW,GAAG,QAAQ,CAAC;gBACvC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;gBAC1C,QAAQ,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;aACjC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAKD,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;AA7bD,0CA6bC","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 { FilterOperator, OperatorOption, FilterStyles } from './types';\nimport { FilterActionType, FilterOperatorCategory } from './types';\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 selectedField: string | number;\n private operatorSelect: HTMLSelectElement;\n private valueInput: HTMLInputElement;\n private valueInputMax: HTMLInputElement;\n private categorySelect: HTMLSelectElement;\n private currentCategory: FilterOperatorCategory = FilterOperatorCategory.ALL;\n\n // 按分类组织的操作符选项\n private 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\n // 分类下拉选项\n private 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 constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager, styles: FilterStyles) {\n this.table = table;\n this.styles = styles;\n this.filterStateManager = filterStateManager;\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.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 const conditionContainer = document.createElement('div');\n applyStyles(conditionContainer, this.styles.conditionContainer);\n\n // 分类选择下拉框\n const categoryLabel = createElement('label', {}, ['筛选类型:']);\n applyStyles(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 const operatorLabel = createElement('label', {}, ['筛选条件:']);\n applyStyles(operatorLabel, this.styles.formLabel);\n\n this.operatorSelect = createElement('select') as HTMLSelectElement;\n applyStyles(this.operatorSelect, this.styles.operatorSelect);\n\n // 条件值输入框\n const valueLabel = createElement('label', {}, ['筛选值:']);\n applyStyles(valueLabel, this.styles.formLabel);\n\n // 一个容器来包装两个输入框和\"和\"字\n const rangeInputContainer = createElement('div');\n applyStyles(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 const andLabel = createElement('span', {}, ['和']);\n applyStyles(andLabel, this.styles.addLabel);\n 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 rangeInputContainer.appendChild(this.valueInput);\n rangeInputContainer.appendChild(andLabel);\n rangeInputContainer.appendChild(this.valueInputMax);\n\n // 将元素添加到容器中\n conditionContainer.appendChild(categoryLabel);\n conditionContainer.appendChild(this.categorySelect);\n conditionContainer.appendChild(operatorLabel);\n conditionContainer.appendChild(this.operatorSelect);\n conditionContainer.appendChild(valueLabel);\n conditionContainer.appendChild(rangeInputContainer);\n\n this.filterByConditionPanel.appendChild(conditionContainer);\n container.appendChild(this.filterByConditionPanel);\n\n // 默认隐藏\n this.hide();\n\n // 初始化操作符选项\n this.updateOperatorOptions();\n this.bindEvents();\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;AAEpE,mCAAmE;AAKnE,MAAa,eAAe;IA4D1B,YAAY,KAA6B,EAAE,kBAAsC;QAnDzE,oBAAe,GAA2B,8BAAsB,CAAC,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,0CA0bC","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 { FilterOperator, OperatorOption } from './types';\nimport { FilterActionType, FilterOperatorCategory } from './types';\n\n/**\n * 按条件筛选组件\n */\nexport class ConditionFilter {\n private table: ListTable | PivotTable;\n private filterStateManager: FilterStateManager;\n private filterByConditionPanel: HTMLElement;\n private selectedField: string | number;\n private operatorSelect: HTMLSelectElement;\n private valueInput: HTMLInputElement;\n private valueInputMax: HTMLInputElement;\n private categorySelect: HTMLSelectElement;\n private currentCategory: FilterOperatorCategory = FilterOperatorCategory.ALL;\n\n // 按分类组织的操作符选项\n private 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\n // 分类下拉选项\n private 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 constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager) {\n this.table = table;\n this.filterStateManager = filterStateManager;\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.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, filterStyles.filterPanel);\n\n // 条件选择区域\n const conditionContainer = document.createElement('div');\n applyStyles(conditionContainer, filterStyles.conditionContainer);\n\n // 分类选择下拉框\n const categoryLabel = createElement('label', {}, ['筛选类型:']);\n applyStyles(categoryLabel, filterStyles.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 const operatorLabel = createElement('label', {}, ['筛选条件:']);\n applyStyles(operatorLabel, filterStyles.formLabel);\n\n this.operatorSelect = createElement('select') as HTMLSelectElement;\n applyStyles(this.operatorSelect, filterStyles.operatorSelect);\n\n // 条件值输入框\n const valueLabel = createElement('label', {}, ['筛选值:']);\n applyStyles(valueLabel, filterStyles.formLabel);\n\n // 一个容器来包装两个输入框和\"和\"字\n const rangeInputContainer = createElement('div');\n applyStyles(rangeInputContainer, filterStyles.rangeInputContainer);\n\n this.valueInput = createElement('input', {\n type: 'text',\n placeholder: '请输入筛选值'\n }) as HTMLInputElement;\n applyStyles(this.valueInput, filterStyles.searchInput);\n\n // \"和\"字标签\n const andLabel = createElement('span', {}, ['和']);\n applyStyles(andLabel, filterStyles.addLabel);\n 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 rangeInputContainer.appendChild(this.valueInput);\n rangeInputContainer.appendChild(andLabel);\n rangeInputContainer.appendChild(this.valueInputMax);\n\n // 将元素添加到容器中\n conditionContainer.appendChild(categoryLabel);\n conditionContainer.appendChild(this.categorySelect);\n conditionContainer.appendChild(operatorLabel);\n conditionContainer.appendChild(this.operatorSelect);\n conditionContainer.appendChild(valueLabel);\n conditionContainer.appendChild(rangeInputContainer);\n\n this.filterByConditionPanel.appendChild(conditionContainer);\n container.appendChild(this.filterByConditionPanel);\n\n // 默认隐藏\n this.hide();\n\n // 初始化操作符选项\n this.updateOperatorOptions();\n this.bindEvents();\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"]}
|
|
@@ -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
|
}
|
|
@@ -85,40 +85,6 @@ class FilterStateManager {
|
|
|
85
85
|
shouldApplyFilter(action) {
|
|
86
86
|
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) || action.payload.enable;
|
|
87
87
|
}
|
|
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
88
|
}
|
|
123
89
|
|
|
124
90
|
exports.FilterStateManager = FilterStateManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/filter/filter-state-manager.ts"],"names":[],"mappings":";;;AAGA,mCAA2C;AAO3C,MAAa,kBAAkB;IAoB7B,YAAY,KAA6B,EAAE,MAAoB;QAjBvD,cAAS,GAAwC,EAAE,CAAC;QAKpD,qBAAgB,GAUpB,IAAI,GAAG,EAAE,CAAC;QAGZ,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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CAAC,qBAAqB,EAAE;YACvD,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC;YACrC,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAAC;YAGpD,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;YAEzE,IAAI,KAAK,EAAE;gBAET,MAAM,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 { ColumnDefine } from '@visactor/vtable/es/ts-types';\nimport type { FilterState, FilterAction, FilterConfig } from './types';\nimport { FilterActionType } from './types';\nimport type { FilterEngine } from './filter-engine';\nimport type { FilterPlugin } from '../filter';\n\n/**\n * 筛选状态管理器,用于管理筛选状态\n */\nexport class FilterStateManager {\n private state: FilterState;\n private engine: FilterEngine;\n private listeners: Array<(state: FilterState) => void> = [];\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();\n }\n\n subscribe(listener: (state: FilterState) => void): () => void {\n this.listeners.push(listener);\n return () => {\n this.listeners = this.listeners.filter(l => l !== listener);\n };\n }\n\n private notifyListeners(): void {\n this.listeners.forEach(listener => listener(this.state));\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) || action.payload.enable;\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":";;;AAGA,mCAA2C;AAO3C,MAAa,kBAAkB;IAO7B,YAAY,KAA6B,EAAE,MAAoB;QAJvD,cAAS,GAAwC,EAAE,CAAC;QAK1D,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,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C,aAAa;SAC/B,CAAC;QACF,OAAO,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;IAC3E,CAAC;CACF;AAjHD,gDAiHC","file":"filter-state-manager.js","sourcesContent":["import type { ListTable, PivotTable } from '@visactor/vtable';\nimport type { ColumnDefine } from '@visactor/vtable/es/ts-types';\nimport type { FilterState, FilterAction, FilterConfig } from './types';\nimport { FilterActionType } from './types';\nimport type { FilterEngine } from './filter-engine';\nimport type { FilterPlugin } from '../filter';\n\n/**\n * 筛选状态管理器,用于管理筛选状态\n */\nexport class FilterStateManager {\n private state: FilterState;\n private engine: FilterEngine;\n private listeners: Array<(state: FilterState) => void> = [];\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();\n }\n\n subscribe(listener: (state: FilterState) => void): () => void {\n this.listeners.push(listener);\n return () => {\n this.listeners = this.listeners.filter(l => l !== listener);\n };\n }\n\n private notifyListeners(): void {\n this.listeners.forEach(listener => listener(this.state));\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) || action.payload.enable;\n }\n}\n"]}
|
|
@@ -2,11 +2,10 @@ import type { ListTable, 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
|
|
5
|
+
import type { FilterMode } from './types';
|
|
6
6
|
export declare class FilterToolbar {
|
|
7
7
|
table: ListTable | PivotTable;
|
|
8
8
|
filterStateManager: FilterStateManager;
|
|
9
|
-
styles: FilterStyles;
|
|
10
9
|
valueFilter: ValueFilter | null;
|
|
11
10
|
conditionFilter: ConditionFilter | null;
|
|
12
11
|
activeTab: 'byValue' | 'byCondition';
|
|
@@ -15,19 +14,21 @@ export declare class FilterToolbar {
|
|
|
15
14
|
filterModes: FilterMode[];
|
|
16
15
|
private filterMenu;
|
|
17
16
|
private filterMenuWidth;
|
|
17
|
+
private currentCol?;
|
|
18
|
+
private currentRow?;
|
|
18
19
|
private filterTabByValue;
|
|
19
20
|
private filterTabByCondition;
|
|
20
21
|
private clearFilterOptionLink;
|
|
21
22
|
private cancelFilterButton;
|
|
22
23
|
private applyFilterButton;
|
|
23
|
-
constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager
|
|
24
|
+
constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager);
|
|
24
25
|
private onTabSwitch;
|
|
25
26
|
private updateSelectedField;
|
|
26
27
|
private applyFilter;
|
|
27
28
|
private clearFilter;
|
|
28
|
-
private updateClearFilterButtonState;
|
|
29
29
|
render(container: HTMLElement): void;
|
|
30
30
|
attachEventListeners(): void;
|
|
31
|
+
adjustMenuPosition(col?: number | null, row?: number | null, providedLeft?: number | null, providedTop?: number | null): void;
|
|
31
32
|
show(col: number, row: number, filterModes: FilterMode[]): void;
|
|
32
33
|
hide(): void;
|
|
33
34
|
}
|
|
@@ -7,21 +7,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
const 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) {
|
|
11
11
|
this.valueFilter = null, this.conditionFilter = null, this.activeTab = "byValue",
|
|
12
12
|
this.isVisible = !1, this.selectedField = null, this.filterModes = [], this.table = table,
|
|
13
|
-
this.filterStateManager = filterStateManager, this.
|
|
14
|
-
this.conditionFilter = new condition_filter_1.ConditionFilter(this.table, this.filterStateManager
|
|
15
|
-
this.filterMenuWidth = 300
|
|
16
|
-
this.isVisible && null !== this.selectedField && this.updateClearFilterButtonState(this.selectedField);
|
|
17
|
-
}));
|
|
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;
|
|
18
16
|
}
|
|
19
17
|
onTabSwitch(tab) {
|
|
20
18
|
this.activeTab = tab, "byValue" === tab ? (this.valueFilter.show(), this.conditionFilter.hide()) : (this.conditionFilter.show(),
|
|
21
19
|
this.valueFilter.hide());
|
|
22
20
|
const isValueTab = "byValue" === tab;
|
|
23
|
-
(0, styles_1.applyStyles)(this.filterTabByValue,
|
|
24
|
-
(0, styles_1.applyStyles)(this.filterTabByCondition,
|
|
21
|
+
(0, styles_1.applyStyles)(this.filterTabByValue, styles_1.filterStyles.tabStyle(isValueTab)),
|
|
22
|
+
(0, styles_1.applyStyles)(this.filterTabByCondition, styles_1.filterStyles.tabStyle(!isValueTab));
|
|
25
23
|
}
|
|
26
24
|
updateSelectedField(field) {
|
|
27
25
|
this.selectedField = field, this.valueFilter && this.valueFilter.setSelectedField(field),
|
|
@@ -35,30 +33,25 @@ class FilterToolbar {
|
|
|
35
33
|
this.valueFilter && this.valueFilter.clearFilter(field), this.conditionFilter && this.conditionFilter.clearFilter(field),
|
|
36
34
|
this.hide();
|
|
37
35
|
}
|
|
38
|
-
updateClearFilterButtonState(field) {
|
|
39
|
-
const currentFilter = this.filterStateManager.getFilterState(field), hasActiveFilter = currentFilter && currentFilter.enable;
|
|
40
|
-
this.clearFilterOptionLink.style.display = "inline", this.clearFilterOptionLink.style.opacity = hasActiveFilter ? "1" : "0.5",
|
|
41
|
-
this.clearFilterOptionLink.style.pointerEvents = hasActiveFilter ? "auto" : "none",
|
|
42
|
-
this.clearFilterOptionLink.style.cursor = hasActiveFilter ? "pointer" : "not-allowed";
|
|
43
|
-
}
|
|
44
36
|
render(container) {
|
|
45
|
-
this.filterMenu = document.createElement("div"), (0, styles_1.applyStyles)(this.filterMenu,
|
|
37
|
+
this.filterMenu = document.createElement("div"), (0, styles_1.applyStyles)(this.filterMenu, styles_1.filterStyles.filterMenu),
|
|
46
38
|
this.filterMenu.style.width = `${this.filterMenuWidth}px`;
|
|
47
39
|
const filterTabsContainer = document.createElement("div");
|
|
48
|
-
(0, styles_1.applyStyles)(filterTabsContainer,
|
|
49
|
-
this.filterTabByValue
|
|
40
|
+
(0, styles_1.applyStyles)(filterTabsContainer, styles_1.filterStyles.tabsContainer),
|
|
41
|
+
this.filterTabByValue = document.createElement("button"), this.filterTabByValue.innerText = "按值筛选",
|
|
42
|
+
(0, styles_1.applyStyles)(this.filterTabByValue, styles_1.filterStyles.tabStyle(!0)),
|
|
50
43
|
this.filterTabByCondition = document.createElement("button"), this.filterTabByCondition.innerText = "按条件筛选",
|
|
51
|
-
(0, styles_1.applyStyles)(this.filterTabByCondition,
|
|
44
|
+
(0, styles_1.applyStyles)(this.filterTabByCondition, styles_1.filterStyles.tabStyle(!1)),
|
|
52
45
|
filterTabsContainer.append(this.filterTabByValue, this.filterTabByCondition);
|
|
53
46
|
const footerContainer = document.createElement("div");
|
|
54
|
-
(0, styles_1.applyStyles)(footerContainer,
|
|
55
|
-
this.clearFilterOptionLink
|
|
56
|
-
(0, styles_1.applyStyles)(this.clearFilterOptionLink,
|
|
47
|
+
(0, styles_1.applyStyles)(footerContainer, styles_1.filterStyles.footerContainer),
|
|
48
|
+
this.clearFilterOptionLink = document.createElement("a"), this.clearFilterOptionLink.href = "#",
|
|
49
|
+
this.clearFilterOptionLink.innerText = "清除筛选", (0, styles_1.applyStyles)(this.clearFilterOptionLink, styles_1.filterStyles.clearLink);
|
|
57
50
|
const footerButtons = document.createElement("div");
|
|
58
51
|
this.cancelFilterButton = document.createElement("button"), this.cancelFilterButton.innerText = "取消",
|
|
59
|
-
(0, styles_1.applyStyles)(this.cancelFilterButton,
|
|
52
|
+
(0, styles_1.applyStyles)(this.cancelFilterButton, styles_1.filterStyles.footerButton(!1)),
|
|
60
53
|
this.applyFilterButton = document.createElement("button"), this.applyFilterButton.innerText = "确认",
|
|
61
|
-
(0, styles_1.applyStyles)(this.applyFilterButton,
|
|
54
|
+
(0, styles_1.applyStyles)(this.applyFilterButton, styles_1.filterStyles.footerButton(!0)),
|
|
62
55
|
footerButtons.append(this.cancelFilterButton, this.applyFilterButton), footerContainer.append(this.clearFilterOptionLink, footerButtons),
|
|
63
56
|
this.filterMenu.append(filterTabsContainer), this.valueFilter.render(this.filterMenu),
|
|
64
57
|
this.conditionFilter.render(this.filterMenu), this.filterMenu.append(footerContainer),
|
|
@@ -79,20 +72,27 @@ class FilterToolbar {
|
|
|
79
72
|
e.stopPropagation();
|
|
80
73
|
}));
|
|
81
74
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
adjustMenuPosition(col, row, providedLeft, providedTop) {
|
|
76
|
+
if ("number" == typeof providedLeft && "number" == typeof providedTop) return this.filterMenu.style.display = this.isVisible ? "block" : "none",
|
|
77
|
+
this.filterMenu.style.left = `${providedLeft}px`, void (this.filterMenu.style.top = `${providedTop}px`);
|
|
78
|
+
const effectiveCol = "number" == typeof col ? col : this.currentCol, effectiveRow = "number" == typeof row ? row : this.currentRow;
|
|
79
|
+
if ("number" != typeof effectiveCol || "number" != typeof effectiveRow) return;
|
|
80
|
+
this.currentCol = effectiveCol, this.currentRow = effectiveRow;
|
|
86
81
|
let left = 0, top = 0;
|
|
87
|
-
const canvasBounds = this.table.canvas.getBoundingClientRect(), cell = this.table.
|
|
82
|
+
const canvasBounds = this.table.canvas.getBoundingClientRect(), cell = this.table.getCellRelativeRect(effectiveCol, effectiveRow);
|
|
88
83
|
cell.right < this.filterMenuWidth ? (left = cell.left + canvasBounds.left, top = cell.bottom + canvasBounds.top) : (left = cell.right + canvasBounds.left - this.filterMenuWidth,
|
|
89
|
-
top = cell.bottom + canvasBounds.top), this.filterMenu.style.display = "block",
|
|
84
|
+
top = cell.bottom + canvasBounds.top), this.filterMenu.style.display = this.isVisible ? "block" : "none",
|
|
90
85
|
this.filterMenu.style.left = `${left}px`, this.filterMenu.style.top = `${top}px`;
|
|
86
|
+
}
|
|
87
|
+
show(col, row, filterModes) {
|
|
88
|
+
this.filterModes = filterModes, this.filterModes.includes("byValue") ? this.filterModes.includes("byCondition") || (this.filterTabByCondition.style.display = "none",
|
|
89
|
+
this.onTabSwitch("byValue")) : (this.filterTabByValue.style.display = "none", this.onTabSwitch("byCondition")),
|
|
90
|
+
this.adjustMenuPosition(col, row), this.filterMenu.style.display = "block";
|
|
91
91
|
const field = this.table.internalProps.layoutMap.getHeaderField(col, row);
|
|
92
92
|
this.updateSelectedField(field);
|
|
93
93
|
const currentFilter = this.filterStateManager.getFilterState(field);
|
|
94
94
|
currentFilter && "byCondition" === currentFilter.type ? this.onTabSwitch("byCondition") : this.onTabSwitch("byValue"),
|
|
95
|
-
|
|
95
|
+
setTimeout((() => {
|
|
96
96
|
this.isVisible = !0;
|
|
97
97
|
}), 0);
|
|
98
98
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/filter/filter-toolbar.ts"],"names":[],"mappings":";;;AAEA,iDAA6C;AAC7C,yDAAqD;AACrD,qCAAuC;AAMvC,MAAa,aAAa;IAoBxB,YAAY,KAA6B,EAAE,kBAAsC,EAAE,MAAoB;QAfvG,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;QAW7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC7C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,IAAI,0BAAW,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,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UAAU,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;QACxC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,IAAI,IAAI,CAAC;QACzC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC;QAEvC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,CAAoB,CAAC;QAC7F,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAGhC,MAAM,aAAa,GAAG,IAAI,CAAC,kBAAkB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QACpE,IAAI,aAAa,IAAI,aAAa,CAAC,IAAI,KAAK,aAAa,EAAE;YACzD,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;SACjC;aAAM;YACL,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,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;AA3OD,sCA2OC","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 } from './styles';\nimport type { FilterMode, FilterStyles } from './types';\n\n/**\n * 筛选工具栏,管理按值和按条件筛选组件\n */\nexport class FilterToolbar {\n table: ListTable | PivotTable;\n filterStateManager: FilterStateManager;\n styles: FilterStyles;\n\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 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, styles: FilterStyles) {\n this.table = table;\n this.filterStateManager = filterStateManager;\n this.styles = styles;\n this.valueFilter = new ValueFilter(this.table, this.filterStateManager, this.styles);\n this.conditionFilter = new ConditionFilter(this.table, this.filterStateManager, this.styles);\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, this.styles.tabStyle(isValueTab));\n applyStyles(this.filterTabByCondition, this.styles.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, this.styles.filterMenu);\n this.filterMenu.style.width = `${this.filterMenuWidth}px`;\n\n // === 筛选 Tab ===\n const filterTabsContainer = document.createElement('div');\n applyStyles(filterTabsContainer, this.styles.tabsContainer);\n\n this.filterTabByValue = document.createElement('button');\n this.filterTabByValue.innerText = '按值筛选';\n applyStyles(this.filterTabByValue, this.styles.tabStyle(true));\n\n this.filterTabByCondition = document.createElement('button');\n this.filterTabByCondition.innerText = '按条件筛选';\n applyStyles(this.filterTabByCondition, this.styles.tabStyle(false));\n\n filterTabsContainer.append(this.filterTabByValue, this.filterTabByCondition);\n\n // === 页脚(清除、取消、确定 筛选按钮) ===\n const footerContainer = document.createElement('div');\n applyStyles(footerContainer, this.styles.footerContainer);\n\n this.clearFilterOptionLink = document.createElement('a');\n this.clearFilterOptionLink.href = '#';\n this.clearFilterOptionLink.innerText = '清除筛选';\n applyStyles(this.clearFilterOptionLink, this.styles.clearLink);\n\n const footerButtons = document.createElement('div');\n this.cancelFilterButton = document.createElement('button');\n this.cancelFilterButton.innerText = '取消';\n applyStyles(this.cancelFilterButton, this.styles.footerButton(false));\n\n this.applyFilterButton = document.createElement('button');\n this.applyFilterButton.innerText = '确认';\n applyStyles(this.applyFilterButton, this.styles.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 show(col: number, row: number, filterModes: FilterMode[]): void {\n this.filterModes = filterModes;\n if (!this.filterModes.includes('byValue')) {\n this.filterTabByValue.style.display = 'none';\n setTimeout(() => this.onTabSwitch('byCondition'), 0);\n } else if (!this.filterModes.includes('byCondition')) {\n this.filterTabByCondition.style.display = 'none';\n setTimeout(() => this.onTabSwitch('byValue'), 0);\n }\n\n let left: number = 0;\n let top: number = 0;\n const canvasBounds = this.table.canvas.getBoundingClientRect();\n const cell = this.table.getMergeCellRect(col, row);\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 = 'block';\n this.filterMenu.style.left = `${left}px`;\n this.filterMenu.style.top = `${top}px`;\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":";;;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;IAC7B,CAAC;IAEO,WAAW,CAAC,GAA8B;Q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AK,CAAC,aAAa,CAAC,SAAS,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,CAAoB,CAAC;QAC7F,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAGhC,MAAM,aAAa,GAAG,IAAI,CAAC,kBAAkB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QACpE,IAAI,aAAa,IAAI,aAAa,CAAC,IAAI,KAAK,aAAa,EAAE;YACzD,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;SACjC;aAAM;YACL,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;SAC7B;QAGD,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;AAjPD,sCAiPC","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 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 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.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 // 确保在事件冒泡完成后才设置 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"]}
|