@visactor/vtable-plugins 1.22.4-alpha.1 → 1.22.4-alpha.2

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.
@@ -214,5 +214,4 @@ export const loopSeriesRule = {
214
214
 
215
215
  export function reverseIfNeed(data, reverse) {
216
216
  return reverse ? data.reverse() : data;
217
- }
218
- //# sourceMappingURL=rules.js.map
217
+ }
@@ -126,4 +126,5 @@ export class MenuManager {
126
126
  this.menuContainer = null), null !== this.hideTimeout && (clearTimeout(this.hideTimeout),
127
127
  this.hideTimeout = null), vglobal.removeEventListener("click", this.handleDocumentClick);
128
128
  }
129
- }
129
+ }
130
+ //# sourceMappingURL=menu-manager.js.map
@@ -6,6 +6,7 @@ export declare class FilterStateManager {
6
6
  private engine;
7
7
  private listeners;
8
8
  private table;
9
+ private filterMenuStates;
9
10
  constructor(table: ListTable | PivotTable, engine: FilterEngine);
10
11
  getFilterState(fieldId?: string | number): FilterConfig;
11
12
  getActiveFilterFields(): (string | number)[];
@@ -17,4 +18,17 @@ export declare class FilterStateManager {
17
18
  private reduce;
18
19
  private applyFilters;
19
20
  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;
20
34
  }
@@ -2,7 +2,7 @@ import { FilterActionType } from "./types";
2
2
 
3
3
  export class FilterStateManager {
4
4
  constructor(table, engine) {
5
- this.listeners = [], this.state = {
5
+ this.listeners = [], this.filterMenuStates = new Map, this.state = {
6
6
  filters: new Map
7
7
  }, this.engine = engine, this.table = table;
8
8
  }
@@ -79,5 +79,39 @@ export class FilterStateManager {
79
79
  shouldApplyFilter(action) {
80
80
  return [ FilterActionType.REMOVE_FILTER, FilterActionType.ENABLE_FILTER, FilterActionType.DISABLE_FILTER, FilterActionType.CLEAR_ALL_FILTERS, FilterActionType.APPLY_FILTERS ].includes(action.type) || action.payload.enable;
81
81
  }
82
+ initializeFilterMenuState(fieldId, candidateValues, displayToRawMap) {
83
+ this.filterMenuStates.set(fieldId, {
84
+ stableCandidateValues: candidateValues,
85
+ currentSearchKeyword: "",
86
+ displayToRawMap: displayToRawMap
87
+ });
88
+ }
89
+ getStableCandidateValues(fieldId) {
90
+ var _a;
91
+ return (null === (_a = this.filterMenuStates.get(fieldId)) || void 0 === _a ? void 0 : _a.stableCandidateValues) || [];
92
+ }
93
+ updateSearchKeyword(fieldId, keyword) {
94
+ const menuState = this.filterMenuStates.get(fieldId);
95
+ menuState && (menuState.currentSearchKeyword = keyword);
96
+ }
97
+ getVisibleSelectedValues(fieldId) {
98
+ const menuState = this.filterMenuStates.get(fieldId), filter = this.getFilterState(fieldId);
99
+ if (!menuState || !(null == filter ? void 0 : filter.values)) return new Set;
100
+ const allSelectedValues = new Set(filter.values), filterKeywords = menuState.currentSearchKeyword.toUpperCase().split(" ").filter((s => s));
101
+ if (0 === filterKeywords.length) return allSelectedValues;
102
+ const visibleSelected = new Set;
103
+ for (const candidate of menuState.stableCandidateValues) {
104
+ const displayValue = candidate.value, txtValue = String(displayValue).toUpperCase(), match = filterKeywords.some((keyword => txtValue.includes(keyword)));
105
+ if (match) {
106
+ const rawValue = menuState.displayToRawMap ? menuState.displayToRawMap.get(displayValue) : displayValue;
107
+ allSelectedValues.has(rawValue) && visibleSelected.add(rawValue);
108
+ }
109
+ }
110
+ return visibleSelected;
111
+ }
112
+ getCurrentSearchKeyword(fieldId) {
113
+ var _a;
114
+ return (null === (_a = this.filterMenuStates.get(fieldId)) || void 0 === _a ? void 0 : _a.currentSearchKeyword) || "";
115
+ }
82
116
  }
83
117
  //# sour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,MAAM,EAAE,IAAI,IAAG,CAAC;gBAChF,MAAM;YACR,KAAK,gBAAgB,CAAC,cAAc;gBAClC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,kCAAO,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,KAAE,MAAM,EAAE,KAAK,IAAG,CAAC;gBACjF,MAAM;YACR,KAAK,gBAAgB,CAAC,iBAAiB;gBACrC,SAAS,CAAC,KAAK,EAAE,CAAC;gBAClB,MAAM;YACR,KAAK,gBAAgB,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,gBAAgB,CAAC,aAAa;YAC9B,gBAAgB,CAAC,aAAa;YAC9B,gBAAgB,CAAC,cAAc;YAC/B,gBAAgB,CAAC,iBAAiB;YAClC,gBAAgB,CAAC,aAAa;SAC/B,CAAC;QACF,OAAO,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;IAC3E,CAAC;CACF","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"]}
1
+ {"version":3,"sources":["../src/filter/filter-state-manager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAO3C,MAAM,OAAO,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;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AAM,OAAO,GAAG,SAAS,CAAC,oBAAoB,CAAC;QAC/C,MAAM,cAAc,GAAG,OAAO;aAC3B,WAAW,EAAE;aACb,KAAK,CAAC,GAAG,CAAC;aACV,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAGlB,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE;YAC/B,OAAO,iBAAiB,CAAC;SAC1B;QAGD,MAAM,eAAe,GAAG,IAAI,GAAG,EAAO,CAAC;QACvC,KAAK,MAAM,SAAS,IAAI,SAAS,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","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"]}
@@ -25,6 +25,7 @@ export declare class FilterToolbar {
25
25
  private updateSelectedField;
26
26
  private applyFilter;
27
27
  private clearFilter;
28
+ private updateClearFilterButtonState;
28
29
  render(container: HTMLElement): void;
29
30
  attachEventListeners(): void;
30
31
  show(col: number, row: number, filterModes: FilterMode[]): void;
@@ -10,7 +10,9 @@ export class FilterToolbar {
10
10
  this.isVisible = !1, this.selectedField = null, this.filterModes = [], this.table = table,
11
11
  this.filterStateManager = filterStateManager, this.styles = styles, this.valueFilter = new ValueFilter(this.table, this.filterStateManager, this.styles),
12
12
  this.conditionFilter = new ConditionFilter(this.table, this.filterStateManager, this.styles),
13
- this.filterMenuWidth = 300;
13
+ this.filterMenuWidth = 300, this.filterStateManager.subscribe((state => {
14
+ this.isVisible && null !== this.selectedField && this.updateClearFilterButtonState(this.selectedField);
15
+ }));
14
16
  }
15
17
  onTabSwitch(tab) {
16
18
  this.activeTab = tab, "byValue" === tab ? (this.valueFilter.show(), this.conditionFilter.hide()) : (this.conditionFilter.show(),
@@ -30,6 +32,12 @@ export class FilterToolbar {
30
32
  this.valueFilter && this.valueFilter.clearFilter(field), this.conditionFilter && this.conditionFilter.clearFilter(field),
31
33
  this.hide();
32
34
  }
35
+ updateClearFilterButtonState(field) {
36
+ const currentFilter = this.filterStateManager.getFilterState(field), hasActiveFilter = currentFilter && currentFilter.enable;
37
+ this.clearFilterOptionLink.style.display = "inline", this.clearFilterOptionLink.style.opacity = hasActiveFilter ? "1" : "0.5",
38
+ this.clearFilterOptionLink.style.pointerEvents = hasActiveFilter ? "auto" : "none",
39
+ this.clearFilterOptionLink.style.cursor = hasActiveFilter ? "pointer" : "not-allowed";
40
+ }
33
41
  render(container) {
34
42
  this.filterMenu = document.createElement("div"), applyStyles(this.filterMenu, this.styles.filterMenu),
35
43
  this.filterMenu.style.width = `${this.filterMenuWidth}px`;
@@ -79,7 +87,7 @@ export class FilterToolbar {
79
87
  this.updateSelectedField(field);
80
88
  const currentFilter = this.filterStateManager.getFilterState(field);
81
89
  currentFilter && "byCondition" === currentFilter.type ? this.onTabSwitch("byCondition") : this.onTabSwitch("byValue"),
82
- setTimeout((() => {
90
+ this.updateClearFilterButtonState(field), setTimeout((() => {
83
91
  this.isVisible = !0;
84
92
  }), 0);
85
93
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/filter/filter-toolbar.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAMvC,MAAM,OAAO,aAAa;IAoBxB,YAAY,KAA6B,EAAE,kBAAsC,EAAE,MAAoB;QAfvG,gBAAW,GAAuB,I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ACzD,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","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 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 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 // 确保在事件冒泡完成后才设置 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,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAMvC,MAAM,OAAO,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,I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AAC,GAAG,CAAC;SACtC;QAED,IAAI,CAAC,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","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"]}
@@ -17,7 +17,9 @@ export declare class ValueFilter {
17
17
  private updateUI;
18
18
  setSelectedField(fieldId: string | number): void;
19
19
  collectUniqueColumnValues(fieldId: string | number): void;
20
+ private updateCandidateCounts;
20
21
  private onValueSelect;
22
+ private isValueVisible;
21
23
  private toggleSelectAll;
22
24
  private onSearch;
23
25
  private initFilterStateFromTableData;
@@ -20,107 +20,44 @@ export class ValueFilter {
20
20
  this.selectedField = fieldId, this.collectUniqueColumnValues(fieldId);
21
21
  }
22
22
  collectUniqueColumnValues(fieldId) {
23
- var _a;
24
- const isEnable = null === (_a = this.filterStateManager.getFilterState(fieldId)) || void 0 === _a ? void 0 : _a.enable, displayValueMap = new Map, rawToDisplayMap = new Map, displayToRawMap = new Map;
25
- let targetCol = -1, targetRow = -1;
23
+ if (this.uniqueKeys.has(fieldId)) return;
24
+ const displayToRawMap = new Map;
25
+ let targetCol = -1;
26
26
  for (let col = 0; col < this.table.colCount; col++) {
27
27
  for (let row = this.table.columnHeaderLevelCount; row < this.table.rowCount; row++) if (!this.table.internalProps.layoutMap.isHeader(col, row)) {
28
28
  const bodyInfo = this.table.internalProps.layoutMap.getBody(col, row);
29
29
  if (bodyInfo && bodyInfo.field === fieldId) {
30
- targetCol = col, targetRow = row;
30
+ targetCol = col;
31
31
  break;
32
32
  }
33
33
  }
34
34
  if (-1 !== targetCol) break;
35
35
  }
36
- if (isEnable) {
37
- const records = this.table.internalProps.records, recordsLength = records.length;
38
- for (let i = 0; i < recordsLength; i++) {
39
- let rawValue, displayValue;
40
- if (-1 !== targetCol) {
41
- const row = this.table.columnHeaderLevelCount + i;
42
- rawValue = records[i][fieldId];
43
- const bodyInfo = this.table.internalProps.layoutMap.getBody(targetCol, row);
44
- displayValue = bodyInfo && "fieldFormat" in bodyInfo && bodyInfo.fieldFormat && "function" == typeof bodyInfo.fieldFormat ? bodyInfo.fieldFormat({
45
- [fieldId]: rawValue
46
- }) : rawValue;
47
- }
48
- null != rawValue && (displayValueMap.set(displayValue, (displayValueMap.get(displayValue) || 0) + 1),
49
- rawToDisplayMap.set(rawValue, displayValue), displayToRawMap.set(displayValue, rawValue));
50
- }
51
- } else {
52
- const currentLength = this.table.internalProps.dataSource.length;
53
- for (let i = 0; i < currentLength; i++) {
54
- let rawValue, displayValue;
55
- if (-1 !== targetCol) {
56
- const row = this.table.columnHeaderLevelCount + i;
57
- row < this.table.rowCount && (rawValue = this.table.getCellOriginValue(targetCol, row),
58
- displayValue = this.table.getCellValue(targetCol, row));
59
- } else rawValue = this.table.getFieldData(String(fieldId), -1 !== targetCol ? targetCol : 0, this.table.columnHeaderLevelCount + i),
60
- displayValue = rawValue;
61
- null != rawValue && (displayValueMap.set(displayValue, (displayValueMap.get(displayValue) || 0) + 1),
62
- rawToDisplayMap.set(rawValue, displayValue), displayToRawMap.set(displayValue, rawValue));
63
- }
36
+ const records = this.table.internalProps.records, recordsLength = records.length;
37
+ for (let i = 0; i < recordsLength; i++) {
38
+ let rawValue, displayValue;
39
+ if (-1 !== targetCol) {
40
+ const row = this.table.columnHeaderLevelCount + i;
41
+ rawValue = records[i][fieldId];
42
+ const bodyInfo = this.table.internalProps.layoutMap.getBody(targetCol, row);
43
+ displayValue = bodyInfo && "fieldFormat" in bodyInfo && bodyInfo.fieldFormat && "function" == typeof bodyInfo.fieldFormat ? bodyInfo.fieldFormat({
44
+ [fieldId]: rawValue
45
+ }) : rawValue;
46
+ } else rawValue = records[i][fieldId], displayValue = rawValue;
47
+ null == rawValue || displayToRawMap.has(displayValue) || displayToRawMap.set(displayValue, rawValue);
64
48
  }
65
49
  this.displayToRawValueMap.set(fieldId, displayToRawMap);
66
- const uniqueValues = Array.from(displayValueMap.entries()).map((([displayValue, count]) => ({
50
+ const uniqueValues = Array.from(displayToRawMap.entries()).map((([displayValue, rawValue]) => ({
67
51
  value: displayValue,
68
- count: count,
69
- rawValue: displayToRawMap.get(displayValue)
52
+ count: 0,
53
+ rawValue: rawValue
70
54
  })));
71
55
  this.uniqueKeys.set(fieldId, uniqueValues);
72
56
  }
73
- onValueSelect(fieldId, displayValue, selected) {
74
- const displayToRawMap = this.displayToRawValueMap.get(fieldId), rawValue = displayToRawMap ? displayToRawMap.get(displayValue) : displayValue, filter = this.filterStateManager.getFilterState(fieldId);
75
- if (filter) {
76
- const updatedValues = selected ? [ ...filter.values || [], rawValue ] : (filter.values || []).filter((v => v !== rawValue));
77
- this.filterStateManager.dispatch({
78
- type: FilterActionType.UPDATE_FILTER,
79
- payload: {
80
- field: fieldId,
81
- values: updatedValues
82
- }
83
- });
84
- } else this.filterStateManager.dispatch({
85
- type: FilterActionType.ADD_FILTER,
86
- payload: {
87
- field: fieldId,
88
- type: "byValue",
89
- values: [ rawValue ]
90
- }
91
- });
92
- }
93
- toggleSelectAll(fieldId, selected) {
94
- var _a;
95
- const filter = this.filterStateManager.getFilterState(fieldId), rawValuesToUpdate = selected && (null === (_a = this.uniqueKeys.get(fieldId)) || void 0 === _a ? void 0 : _a.map((item => item.rawValue))) || [];
96
- if (filter) {
97
- const updatedValues = selected ? rawValuesToUpdate : [];
98
- this.filterStateManager.dispatch({
99
- type: FilterActionType.UPDATE_FILTER,
100
- payload: {
101
- field: fieldId,
102
- values: updatedValues
103
- }
104
- });
105
- } else this.filterStateManager.dispatch({
106
- type: FilterActionType.ADD_FILTER,
107
- payload: {
108
- field: fieldId,
109
- type: "byValue",
110
- values: rawValuesToUpdate,
111
- enable: !0
112
- }
113
- });
114
- }
115
- onSearch(fieldId, value) {
116
- const filterKeywords = value.toUpperCase().split(" ").filter((s => s)), items = this.valueFilterOptionList.get(fieldId);
117
- for (const item of items) {
118
- const txtValue = item.id.toUpperCase() || "", match = filterKeywords.some((keyword => txtValue.includes(keyword)));
119
- item.itemContainer.style.display = 0 === filterKeywords.length || match ? "flex" : "none";
120
- }
121
- }
122
- initFilterStateFromTableData(fieldId) {
123
- const filter = this.filterStateManager.getFilterState(fieldId), selectedRawValues = new Set, displayToRawMap = this.displayToRawValueMap.get(fieldId);
57
+ updateCandidateCounts(fieldId) {
58
+ const uniqueValues = this.uniqueKeys.get(fieldId);
59
+ if (!uniqueValues) return;
60
+ const filter = this.filterStateManager.getFilterState(fieldId), dataSource = (null == filter ? void 0 : filter.enable) ? this.table.internalProps.records : this.table.internalProps.dataSource;
124
61
  let targetCol = -1;
125
62
  for (let col = 0; col < this.table.colCount; col++) {
126
63
  for (let row = this.table.columnHeaderLevelCount; row < this.table.rowCount; row++) if (!this.table.internalProps.layoutMap.isHeader(col, row)) {
@@ -132,32 +69,117 @@ export class ValueFilter {
132
69
  }
133
70
  if (-1 !== targetCol) break;
134
71
  }
135
- const currentLength = this.table.internalProps.dataSource.length;
136
- for (let i = 0; i < currentLength; i++) {
137
- let displayValue, rawValue;
72
+ const dataLength = dataSource.length, countMap = new Map;
73
+ for (let i = 0; i < dataLength; i++) {
74
+ let displayValue;
138
75
  if (-1 !== targetCol) {
139
76
  const row = this.table.columnHeaderLevelCount + i;
140
- row < this.table.rowCount && (displayValue = this.table.getCellValue(targetCol, row),
141
- rawValue = displayToRawMap ? displayToRawMap.get(displayValue) : displayValue);
142
- } else displayValue = this.table.getFieldData(String(fieldId), -1 !== targetCol ? targetCol : 0, this.table.columnHeaderLevelCount + i),
143
- rawValue = displayToRawMap ? displayToRawMap.get(displayValue) : displayValue;
144
- null != rawValue && selectedRawValues.add(rawValue);
77
+ row < this.table.rowCount && (displayValue = this.table.getCellValue(targetCol, row));
78
+ } else displayValue = this.table.getFieldData(String(fieldId), -1 !== targetCol ? targetCol : 0, this.table.columnHeaderLevelCount + i);
79
+ null != displayValue && countMap.set(displayValue, (countMap.get(displayValue) || 0) + 1);
145
80
  }
146
- (!filter || !arrayEqual(filter.values, Array.from(selectedRawValues))) && (filter ? this.filterStateManager.dispatch({
81
+ uniqueValues.forEach((item => {
82
+ item.count = countMap.get(item.value) || 0;
83
+ }));
84
+ }
85
+ onValueSelect(fieldId, displayValue, selected) {
86
+ const displayToRawMap = this.displayToRawValueMap.get(fieldId), rawValue = displayToRawMap ? displayToRawMap.get(displayValue) : displayValue, filter = this.filterStateManager.getFilterState(fieldId);
87
+ let updatedValues;
88
+ filter ? (updatedValues = selected ? [ ...filter.values || [], rawValue ] : (filter.values || []).filter((v => v !== rawValue)),
89
+ this.filterStateManager.dispatch({
147
90
  type: FilterActionType.UPDATE_FILTER,
91
+ payload: {
92
+ field: fieldId,
93
+ values: updatedValues
94
+ }
95
+ })) : (updatedValues = selected ? [ rawValue ] : [], this.filterStateManager.dispatch({
96
+ type: FilterActionType.ADD_FILTER,
148
97
  payload: {
149
98
  field: fieldId,
150
99
  type: "byValue",
151
- values: Array.from(selectedRawValues)
100
+ values: updatedValues
101
+ }
102
+ }));
103
+ }
104
+ isValueVisible(displayValue, keyword) {
105
+ if (!keyword) return !0;
106
+ const filterKeywords = keyword.toUpperCase().split(" ").filter((s => s)), txtValue = String(displayValue).toUpperCase();
107
+ return filterKeywords.some((keyword => txtValue.includes(keyword)));
108
+ }
109
+ toggleSelectAll(fieldId, selected) {
110
+ const currentKeyword = this.filterStateManager.getCurrentSearchKeyword(fieldId), stableCandidates = this.filterStateManager.getStableCandidateValues(fieldId), displayToRawMap = this.displayToRawValueMap.get(fieldId), visibleRawValues = stableCandidates.filter((candidate => this.isValueVisible(candidate.value, currentKeyword))).map((candidate => displayToRawMap ? displayToRawMap.get(candidate.value) : candidate.value)), filter = this.filterStateManager.getFilterState(fieldId), currentValues = new Set((null == filter ? void 0 : filter.values) || []);
111
+ let updatedValues;
112
+ updatedValues = selected ? Array.from(new Set([ ...currentValues, ...visibleRawValues ])) : Array.from(currentValues).filter((value => !visibleRawValues.includes(value))),
113
+ filter ? this.filterStateManager.dispatch({
114
+ type: FilterActionType.UPDATE_FILTER,
115
+ payload: {
116
+ field: fieldId,
117
+ values: updatedValues
152
118
  }
153
119
  }) : this.filterStateManager.dispatch({
154
120
  type: FilterActionType.ADD_FILTER,
155
121
  payload: {
156
122
  field: fieldId,
157
123
  type: "byValue",
158
- values: Array.from(selectedRawValues)
124
+ values: updatedValues,
125
+ enable: !0
159
126
  }
160
- }));
127
+ });
128
+ }
129
+ onSearch(fieldId, value) {
130
+ this.filterStateManager.updateSearchKeyword(fieldId, value);
131
+ const items = this.valueFilterOptionList.get(fieldId), filterKeywords = value.toUpperCase().split(" ").filter((s => s));
132
+ for (const item of items) {
133
+ const txtValue = item.id.toUpperCase() || "", match = filterKeywords.some((keyword => txtValue.includes(keyword))), isVisible = 0 === filterKeywords.length || match;
134
+ item.itemContainer.style.display = isVisible ? "flex" : "none";
135
+ }
136
+ }
137
+ initFilterStateFromTableData(fieldId) {
138
+ var _a, _b;
139
+ const filter = this.filterStateManager.getFilterState(fieldId);
140
+ if (null == filter ? void 0 : filter.enable) {
141
+ const selectedRawValues = new Set, displayToRawMap = this.displayToRawValueMap.get(fieldId);
142
+ let targetCol = -1;
143
+ for (let col = 0; col < this.table.colCount; col++) {
144
+ for (let row = this.table.columnHeaderLevelCount; row < this.table.rowCount; row++) if (!this.table.internalProps.layoutMap.isHeader(col, row)) {
145
+ const bodyInfo = this.table.internalProps.layoutMap.getBody(col, row);
146
+ if (bodyInfo && bodyInfo.field === fieldId) {
147
+ targetCol = col;
148
+ break;
149
+ }
150
+ }
151
+ if (-1 !== targetCol) break;
152
+ }
153
+ const currentLength = this.table.internalProps.dataSource.length;
154
+ for (let i = 0; i < currentLength; i++) {
155
+ let displayValue, rawValue;
156
+ if (-1 !== targetCol) {
157
+ const row = this.table.columnHeaderLevelCount + i;
158
+ row < this.table.rowCount && (displayValue = this.table.getCellValue(targetCol, row),
159
+ rawValue = displayToRawMap ? displayToRawMap.get(displayValue) : displayValue);
160
+ } else displayValue = this.table.getFieldData(String(fieldId), -1 !== targetCol ? targetCol : 0, this.table.columnHeaderLevelCount + i),
161
+ rawValue = displayToRawMap ? displayToRawMap.get(displayValue) : displayValue;
162
+ null != rawValue && selectedRawValues.add(rawValue);
163
+ }
164
+ !arrayEqual(filter.values, Array.from(selectedRawValues)) && this.filterStateManager.dispatch({
165
+ type: FilterActionType.UPDATE_FILTER,
166
+ payload: {
167
+ field: fieldId,
168
+ values: Array.from(selectedRawValues)
169
+ }
170
+ });
171
+ } else if (!filter) {
172
+ const availableRawValues = (null === (_b = null === (_a = this.uniqueKeys.get(fieldId)) || void 0 === _a ? void 0 : _a.filter((item => item.count > 0))) || void 0 === _b ? void 0 : _b.map((item => item.rawValue)).filter((v => null != v))) || [];
173
+ this.filterStateManager.dispatch({
174
+ type: FilterActionType.ADD_FILTER,
175
+ payload: {
176
+ field: fieldId,
177
+ type: "byValue",
178
+ values: availableRawValues,
179
+ enable: !1
180
+ }
181
+ });
182
+ }
161
183
  }
162
184
  syncCheckboxesWithFilterState(filter) {
163
185
  if (!filter) return;
@@ -167,7 +189,7 @@ export class ValueFilter {
167
189
  const displayValue = optionDom.originalValue, rawValue = displayToRawMap ? displayToRawMap.get(displayValue) : displayValue;
168
190
  optionDom.checkbox.checked = selectedRawValues.some((v => v === rawValue));
169
191
  const count = (null === (_b = null === (_a = this.uniqueKeys.get(filter.field)) || void 0 === _a ? void 0 : _a.find((key => String(key.value) === optionDom.id))) || void 0 === _b ? void 0 : _b.count) || 0;
170
- optionDom.countSpan.textContent = String(count), optionDom.itemContainer.style.display = 0 === count ? "none" : "flex";
192
+ optionDom.checkbox.disabled = 0 === count;
171
193
  }));
172
194
  }
173
195
  syncSelectAllWithFilterState(filter) {
@@ -180,14 +202,14 @@ export class ValueFilter {
180
202
  this.selectAllCheckbox.indeterminate = !0);
181
203
  }
182
204
  applyFilter(fieldId = this.selectedField) {
183
- var _a, _b;
184
- const selectedKeys = (null === (_a = this.filterStateManager.getFilterState(fieldId)) || void 0 === _a ? void 0 : _a.values) || [];
185
- selectedKeys.length > 0 && selectedKeys.length < (null === (_b = this.uniqueKeys.get(fieldId)) || void 0 === _b ? void 0 : _b.length) ? this.filterStateManager.dispatch({
205
+ var _a;
206
+ const visibleSelectedKeys = Array.from(this.filterStateManager.getVisibleSelectedValues(fieldId));
207
+ visibleSelectedKeys.length > 0 && visibleSelectedKeys.length < (null === (_a = this.uniqueKeys.get(fieldId)) || void 0 === _a ? void 0 : _a.length) ? this.filterStateManager.dispatch({
186
208
  type: FilterActionType.APPLY_FILTERS,
187
209
  payload: {
188
210
  field: fieldId,
189
211
  type: "byValue",
190
- values: selectedKeys,
212
+ values: visibleSelectedKeys,
191
213
  enable: !0
192
214
  }
193
215
  }) : this.filterStateManager.dispatch({
@@ -230,12 +252,12 @@ export class ValueFilter {
230
252
  const selectedRawValues = (null === (_a = this.filterStateManager.getFilterState(field)) || void 0 === _a ? void 0 : _a.values) || [], selectedRawValueSet = new Set(selectedRawValues), itemDomList = [];
231
253
  null === (_b = this.uniqueKeys.get(field)) || void 0 === _b || _b.forEach((({value: value, count: count, rawValue: rawValue}) => {
232
254
  const itemDiv = document.createElement("div");
233
- applyStyles(itemDiv, this.styles.optionItem);
255
+ applyStyles(itemDiv, this.styles.optionItem), itemDiv.style.display = "flex";
234
256
  const label = document.createElement("label");
235
257
  applyStyles(label, this.styles.optionLabel);
236
258
  const checkbox = document.createElement("input");
237
259
  checkbox.type = "checkbox", checkbox.value = String(value), checkbox.checked = selectedRawValueSet.has(rawValue),
238
- applyStyles(checkbox, this.styles.checkbox);
260
+ checkbox.disabled = 0 === count, applyStyles(checkbox, this.styles.checkbox);
239
261
  const countSpan = document.createElement("span");
240
262
  countSpan.textContent = String(count), applyStyles(countSpan, this.styles.countSpan),
241
263
  label.append(checkbox, ` ${value}`), itemDiv.append(label, countSpan), this.filterItemsContainer.appendChild(itemDiv);
@@ -266,7 +288,11 @@ export class ValueFilter {
266
288
  }));
267
289
  }
268
290
  show() {
269
- this.initFilterStateFromTableData(this.selectedField), this.renderFilterOptions(this.selectedField),
291
+ this.collectUniqueColumnValues(this.selectedField), this.updateCandidateCounts(this.selectedField),
292
+ this.initFilterStateFromTableData(this.selectedField);
293
+ const uniqueValues = this.uniqueKeys.get(this.selectedField), displayToRawMap = this.displayToRawValueMap.get(this.selectedField);
294
+ uniqueValues && displayToRawMap && this.filterStateManager.initializeFilterMenuState(this.selectedField, uniqueValues, displayToRawMap),
295
+ this.filterByValueSearchInput && (this.filterByValueSearchInput.value = ""), this.renderFilterOptions(this.selectedField),
270
296
  this.filterByValuePanel.style.display = "block";
271
297
  }
272
298
  hide() {