@visactor/vtable-plugins 1.22.5 → 1.22.6-alpha.0
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/excel-edit-cell-keyboard.js +19 -16
- package/cjs/excel-edit-cell-keyboard.js.map +1 -1
- package/cjs/filter/filter-state-manager.d.ts +2 -2
- package/cjs/filter/filter-state-manager.js +3 -3
- package/cjs/filter/filter-state-manager.js.map +1 -1
- package/cjs/filter/filter-toolbar.js +1 -1
- package/cjs/filter/filter-toolbar.js.map +1 -1
- package/cjs/filter/filter.js +4 -3
- package/cjs/filter/filter.js.map +1 -1
- package/cjs/filter/types.d.ts +1 -0
- package/cjs/filter/types.js.map +1 -1
- package/cjs/filter/value-filter.d.ts +1 -0
- package/cjs/filter/value-filter.js +3 -0
- package/cjs/filter/value-filter.js.map +1 -1
- package/cjs/master-detail-plugin/config.js +2 -1
- package/cjs/master-detail-plugin/core.js +1 -2
- package/dist/vtable-plugins.js +25 -17
- package/dist/vtable-plugins.min.js +3 -3
- package/es/excel-edit-cell-keyboard.js +19 -16
- package/es/excel-edit-cell-keyboard.js.map +1 -1
- package/es/filter/filter-state-manager.d.ts +2 -2
- package/es/filter/filter-state-manager.js +3 -3
- package/es/filter/filter-state-manager.js.map +1 -1
- package/es/filter/filter-toolbar.js +1 -1
- package/es/filter/filter-toolbar.js.map +1 -1
- package/es/filter/filter.js +4 -3
- package/es/filter/filter.js.map +1 -1
- package/es/filter/types.d.ts +1 -0
- package/es/filter/types.js.map +1 -1
- package/es/filter/value-filter.d.ts +1 -0
- package/es/filter/value-filter.js +3 -0
- package/es/filter/value-filter.js.map +1 -1
- package/es/master-detail-plugin/config.js +2 -1
- package/es/master-detail-plugin/core.js +1 -2
- package/package.json +8 -8
|
@@ -31,25 +31,28 @@ class ExcelEditCellKeyboardPlugin {
|
|
|
31
31
|
document.addEventListener("keydown", this.handleKeyDown.bind(this), !0);
|
|
32
32
|
}
|
|
33
33
|
handleKeyDown(event) {
|
|
34
|
-
if (this.table.editorManager && this.isExcelShortcutKey(event))
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
34
|
+
if (this.table.editorManager && this.isExcelShortcutKey(event)) {
|
|
35
|
+
const eventKey = event.key.toLowerCase();
|
|
36
|
+
if (this.table.editorManager.editingEditor && "keydown" === this.table.editorManager.beginTriggerEditCellMode) {
|
|
37
|
+
const {col: col, row: row} = this.table.editorManager.editCell;
|
|
38
|
+
this.table.editorManager.completeEdit(), this.table.getElement().focus(), event.shiftKey || event.ctrlKey || event.metaKey || (eventKey === ExcelEditCellKeyboardResponse.ENTER ? this.table.selectCell(col, row + 1) : eventKey === ExcelEditCellKeyboardResponse.TAB ? this.table.selectCell(col + 1, row) : eventKey === ExcelEditCellKeyboardResponse.ARROW_LEFT ? this.table.selectCell(col - 1, row) : eventKey === ExcelEditCellKeyboardResponse.ARROW_RIGHT ? this.table.selectCell(col + 1, row) : eventKey === ExcelEditCellKeyboardResponse.ARROW_DOWN ? this.table.selectCell(col, row + 1) : eventKey === ExcelEditCellKeyboardResponse.ARROW_UP && this.table.selectCell(col, row - 1),
|
|
39
|
+
event.stopPropagation(), event.preventDefault());
|
|
40
|
+
} else {
|
|
41
|
+
const {col: col, row: row} = this.table.stateManager.select.cellPos;
|
|
42
|
+
if (!this.table.editorManager.editingEditor || eventKey !== ExcelEditCellKeyboardResponse.ENTER && eventKey !== ExcelEditCellKeyboardResponse.TAB) {
|
|
43
|
+
if (!this.table.editorManager.editingEditor && (eventKey === ExcelEditCellKeyboardResponse.DELETE || eventKey === ExcelEditCellKeyboardResponse.BACKSPACE)) {
|
|
44
|
+
const selectCells = this.table.getSelectedCellInfos();
|
|
45
|
+
(null == selectCells ? void 0 : selectCells.length) > 0 && deleteSelectRange(selectCells, this.table),
|
|
46
|
+
event.stopPropagation(), event.preventDefault();
|
|
47
|
+
}
|
|
48
|
+
} else this.table.editorManager.completeEdit(), this.table.getElement().focus(),
|
|
49
|
+
eventKey === ExcelEditCellKeyboardResponse.ENTER ? this.table.selectCell(col, row + 1) : eventKey === ExcelEditCellKeyboardResponse.TAB && this.table.selectCell(col + 1, row),
|
|
50
|
+
event.stopPropagation(), event.preventDefault();
|
|
51
|
+
}
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
54
|
isExcelShortcutKey(event) {
|
|
52
|
-
return this.responseKeyboard.includes(event.key);
|
|
55
|
+
return this.responseKeyboard.includes(event.key.toLowerCase());
|
|
53
56
|
}
|
|
54
57
|
setResponseKeyboard(responseKeyboard) {
|
|
55
58
|
this.responseKeyboard = responseKeyboard;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/excel-edit-cell-keyboard.ts"],"names":[],"mappings":";;;AACA,6CAAoD;AAGpD,IAAY,6BASX;AATD,WAAY,6BAA6B;IACvC,gDAAe,CAAA;IACf,4CAAW,CAAA;IACX,yDAAwB,CAAA;IACxB,2DAA0B,CAAA;IAC1B,yDAAwB,CAAA;IACxB,qDAAoB,CAAA;IACpB,kDAAiB,CAAA;IACjB,wDAAuB,CAAA;AACzB,CAAC,EATW,6BAA6B,GAA7B,qCAA6B,KAA7B,qCAA6B,QASxC;AASD,MAAa,2BAA2B;IAOtC,YAAY,aAAmD;;QAN/D,OAAE,GAAG,0BAA0B,CAAC;QAChC,SAAI,GAAG,0BAA0B,CAAC;QAClC,YAAO,GAAG,CAAC,yBAAgB,CAAC,WAAW,CAAC,CAAC;QAKvC,IAAI,CAAC,EAAE,GAAG,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,EAAE,mCAAI,IAAI,CAAC,EAAE,CAAC;QACvC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,gBAAgB,GAAG,MAAA,aAAa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AAgB,GAAG,gBAAgB,CAAC;IAC3C,CAAC;IACD,sBAAsB,CAAC,gBAAiD;QACtE,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/F,CAAC;IACD,mBAAmB,CAAC,gBAAiD;QACnE,IAAI,CAAC,gBAAgB,GAAG,CAAC,GAAG,IAAI,CAAC,gBAAgB,EAAE,GAAG,gBAAgB,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO;QACL,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;IACpE,CAAC;CACF;AAxHD,kEAwHC;AAED,SAAS,iBAAiB,CAAC,WAA+B,EAAE,aAAwB;IAClF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC9C,aAAa,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;SACjF;KACF;AACH,CAAC","file":"excel-edit-cell-keyboard.js","sourcesContent":["import type { ListTable, BaseTableAPI, TYPES, pluginsDefinition } from '@visactor/vtable';\nimport { TABLE_EVENT_TYPE } from '@visactor/vtable';\nimport type { TableEvents } from '@visactor/vtable/src/core/TABLE_EVENT_TYPE';\nimport type { EventArg } from './types';\nexport enum ExcelEditCellKeyboardResponse {\n ENTER = 'enter',\n TAB = 'tab',\n ARROW_LEFT = 'arrowLeft',\n ARROW_RIGHT = 'arrowRight',\n ARROW_DOWN = 'arrowDown',\n ARROW_UP = 'arrowUp',\n DELETE = 'delete',\n BACKSPACE = 'backspace'\n}\n//备用 插件配置项 目前感觉都走默认逻辑就行\nexport type IExcelEditCellKeyboardPluginOptions = {\n id?: string;\n responseKeyboard?: ExcelEditCellKeyboardResponse[];\n // 是否响应删除\n // enableDeleteKey?: boolean;\n};\n\nexport class ExcelEditCellKeyboardPlugin implements pluginsDefinition.IVTablePlugin {\n id = `excel-edit-cell-keyboard`;\n name = 'Excel Edit Cell Keyboard';\n runTime = [TABLE_EVENT_TYPE.INITIALIZED];\n table: ListTable;\n pluginOptions: IExcelEditCellKeyboardPluginOptions;\n responseKeyboard: ExcelEditCellKeyboardResponse[];\n constructor(pluginOptions?: IExcelEditCellKeyboardPluginOptions) {\n this.id = pluginOptions?.id ?? this.id;\n this.pluginOptions = pluginOptions;\n this.responseKeyboard = pluginOptions?.responseKeyboard ?? [\n ExcelEditCellKeyboardResponse.ENTER,\n ExcelEditCellKeyboardResponse.TAB,\n ExcelEditCellKeyboardResponse.ARROW_LEFT,\n ExcelEditCellKeyboardResponse.ARROW_RIGHT,\n ExcelEditCellKeyboardResponse.ARROW_DOWN,\n ExcelEditCellKeyboardResponse.ARROW_UP,\n ExcelEditCellKeyboardResponse.DELETE,\n ExcelEditCellKeyboardResponse.BACKSPACE\n ];\n\n this.bindEvent();\n }\n run(...args: [EventArg, TableEvents[keyof TableEvents] | TableEvents[keyof TableEvents][], BaseTableAPI]) {\n const table: BaseTableAPI = args[2];\n this.table = table as ListTable;\n }\n\n bindEvent() {\n //监听document全局的keydown事件 捕获阶段监听 可以及时阻止事件传播和默认行为\n document.addEventListener('keydown', this.handleKeyDown.bind(this), true);\n // this.table.on('selected_cell', () => {\n // this.updateHighlight();\n // });\n\n // this.table.on('selected_clear', () => {\n // this.clearHighlight();\n // });\n\n // this.table.on('mousemove_table', () => {\n // if (this.table.stateManager.select.selecting) {\n // this.updateHighlight();\n // }\n // });\n }\n handleKeyDown(event: KeyboardEvent) {\n if (this.table.editorManager && this.isExcelShortcutKey(event)) {\n //判断是键盘触发编辑单元格的情况下,那么在编辑状态中切换方向需要选中下一个继续编辑\n if (this.table.editorManager.editingEditor && this.table.editorManager.beginTriggerEditCellMode === 'keydown') {\n const { col, row } = this.table.editorManager.editCell;\n this.table.editorManager.completeEdit();\n this.table.getElement().focus();\n if (!event.shiftKey && !event.ctrlKey && !event.metaKey) {\n //有这些配合键,则不进行选中下一个单元格的行为 执行vtable内部逻辑\n if (event.key === ExcelEditCellKeyboardResponse.ENTER) {\n this.table.selectCell(col, row + 1);\n } else if (event.key === ExcelEditCellKeyboardResponse.TAB) {\n this.table.selectCell(col + 1, row);\n } else if (event.key === ExcelEditCellKeyboardResponse.ARROW_LEFT) {\n this.table.selectCell(col - 1, row);\n } else if (event.key === ExcelEditCellKeyboardResponse.ARROW_RIGHT) {\n this.table.selectCell(col + 1, row);\n } else if (event.key === ExcelEditCellKeyboardResponse.ARROW_DOWN) {\n this.table.selectCell(col, row + 1);\n } else if (event.key === ExcelEditCellKeyboardResponse.ARROW_UP) {\n this.table.selectCell(col, row - 1);\n }\n // 阻止事件传播和默认行为\n event.stopPropagation();\n event.preventDefault();\n }\n } else {\n const { col, row } = this.table.stateManager.select.cellPos;\n if (\n this.table.editorManager.editingEditor &&\n (event.key === ExcelEditCellKeyboardResponse.ENTER || event.key === ExcelEditCellKeyboardResponse.TAB)\n ) {\n this.table.editorManager.completeEdit();\n this.table.getElement().focus();\n if (event.key === ExcelEditCellKeyboardResponse.ENTER) {\n this.table.selectCell(col, row + 1);\n } else if (event.key === ExcelEditCellKeyboardResponse.TAB) {\n this.table.selectCell(col + 1, row);\n }\n // 阻止事件传播和默认行为\n event.stopPropagation();\n event.preventDefault();\n } else if (\n !this.table.editorManager.editingEditor &&\n (event.key === ExcelEditCellKeyboardResponse.DELETE || event.key === ExcelEditCellKeyboardResponse.BACKSPACE)\n ) {\n //响应删除键,删除\n const selectCells = this.table.getSelectedCellInfos();\n if (selectCells?.length > 0) {\n // 如果选中的是范围,则删除范围内的所有单元格\n deleteSelectRange(selectCells, this.table);\n }\n // 阻止事件传播和默认行为\n event.stopPropagation();\n event.preventDefault();\n }\n }\n }\n }\n // 判断event的keyCode是否是excel的快捷键\n isExcelShortcutKey(event: KeyboardEvent) {\n return this.responseKeyboard.includes(event.key as ExcelEditCellKeyboardResponse);\n }\n setResponseKeyboard(responseKeyboard: ExcelEditCellKeyboardResponse[]) {\n this.responseKeyboard = responseKeyboard;\n }\n deleteResponseKeyboard(responseKeyboard: ExcelEditCellKeyboardResponse[]) {\n this.responseKeyboard = this.responseKeyboard.filter(key => !responseKeyboard.includes(key));\n }\n addResponseKeyboard(responseKeyboard: ExcelEditCellKeyboardResponse[]) {\n this.responseKeyboard = [...this.responseKeyboard, ...responseKeyboard];\n }\n release() {\n document.removeEventListener('keydown', this.handleKeyDown, true);\n }\n}\n//将选中单元格的值设置为空\nfunction deleteSelectRange(selectCells: TYPES.CellInfo[][], tableInstance: ListTable) {\n for (let i = 0; i < selectCells.length; i++) {\n for (let j = 0; j < selectCells[i].length; j++) {\n tableInstance.changeCellValue(selectCells[i][j].col, selectCells[i][j].row, '');\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/excel-edit-cell-keyboard.ts"],"names":[],"mappings":";;;AACA,6CAAoD;AAGpD,IAAY,6BASX;AATD,WAAY,6BAA6B;IACvC,gDAAe,CAAA;IACf,4CAAW,CAAA;IACX,yDAAwB,CAAA;IACxB,2DAA0B,CAAA;IAC1B,yDAAwB,CAAA;IACxB,qDAAoB,CAAA;IACpB,kDAAiB,CAAA;IACjB,wDAAuB,CAAA;AACzB,CAAC,EATW,6BAA6B,GAA7B,qCAA6B,KAA7B,qCAA6B,QASxC;AASD,MAAa,2BAA2B;IAOtC,YAAY,aAAmD;;QAN/D,OAAE,GAAG,0BAA0B,CAAC;QAChC,SAAI,GAAG,0BAA0B,CAAC;QAClC,YAAO,GAAG,C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LE_EVENT_TYPE } from '@visactor/vtable';\nimport type { TableEvents } from '@visactor/vtable/src/core/TABLE_EVENT_TYPE';\nimport type { EventArg } from './types';\nexport enum ExcelEditCellKeyboardResponse {\n ENTER = 'enter',\n TAB = 'tab',\n ARROW_LEFT = 'arrowLeft',\n ARROW_RIGHT = 'arrowRight',\n ARROW_DOWN = 'arrowDown',\n ARROW_UP = 'arrowUp',\n DELETE = 'delete',\n BACKSPACE = 'backspace'\n}\n//备用 插件配置项 目前感觉都走默认逻辑就行\nexport type IExcelEditCellKeyboardPluginOptions = {\n id?: string;\n responseKeyboard?: ExcelEditCellKeyboardResponse[];\n // 是否响应删除\n // enableDeleteKey?: boolean;\n};\n\nexport class ExcelEditCellKeyboardPlugin implements pluginsDefinition.IVTablePlugin {\n id = `excel-edit-cell-keyboard`;\n name = 'Excel Edit Cell Keyboard';\n runTime = [TABLE_EVENT_TYPE.INITIALIZED];\n table: ListTable;\n pluginOptions: IExcelEditCellKeyboardPluginOptions;\n responseKeyboard: ExcelEditCellKeyboardResponse[];\n constructor(pluginOptions?: IExcelEditCellKeyboardPluginOptions) {\n this.id = pluginOptions?.id ?? this.id;\n this.pluginOptions = pluginOptions;\n this.responseKeyboard = pluginOptions?.responseKeyboard ?? [\n ExcelEditCellKeyboardResponse.ENTER,\n ExcelEditCellKeyboardResponse.TAB,\n ExcelEditCellKeyboardResponse.ARROW_LEFT,\n ExcelEditCellKeyboardResponse.ARROW_RIGHT,\n ExcelEditCellKeyboardResponse.ARROW_DOWN,\n ExcelEditCellKeyboardResponse.ARROW_UP,\n ExcelEditCellKeyboardResponse.DELETE,\n ExcelEditCellKeyboardResponse.BACKSPACE\n ];\n\n this.bindEvent();\n }\n run(...args: [EventArg, TableEvents[keyof TableEvents] | TableEvents[keyof TableEvents][], BaseTableAPI]) {\n const table: BaseTableAPI = args[2];\n this.table = table as ListTable;\n }\n\n bindEvent() {\n //监听document全局的keydown事件 捕获阶段监听 可以及时阻止事件传播和默认行为\n document.addEventListener('keydown', this.handleKeyDown.bind(this), true);\n // this.table.on('selected_cell', () => {\n // this.updateHighlight();\n // });\n\n // this.table.on('selected_clear', () => {\n // this.clearHighlight();\n // });\n\n // this.table.on('mousemove_table', () => {\n // if (this.table.stateManager.select.selecting) {\n // this.updateHighlight();\n // }\n // });\n }\n handleKeyDown(event: KeyboardEvent) {\n if (this.table.editorManager && this.isExcelShortcutKey(event)) {\n const eventKey = event.key.toLowerCase() as ExcelEditCellKeyboardResponse;\n //判断是键盘触发编辑单元格的情况下,那么在编辑状态中切换方向需要选中下一个继续编辑\n if (this.table.editorManager.editingEditor && this.table.editorManager.beginTriggerEditCellMode === 'keydown') {\n const { col, row } = this.table.editorManager.editCell;\n this.table.editorManager.completeEdit();\n this.table.getElement().focus();\n if (!event.shiftKey && !event.ctrlKey && !event.metaKey) {\n //有这些配合键,则不进行选中下一个单元格的行为 执行vtable内部逻辑\n if (eventKey === ExcelEditCellKeyboardResponse.ENTER) {\n this.table.selectCell(col, row + 1);\n } else if (eventKey === ExcelEditCellKeyboardResponse.TAB) {\n this.table.selectCell(col + 1, row);\n } else if (eventKey === ExcelEditCellKeyboardResponse.ARROW_LEFT) {\n this.table.selectCell(col - 1, row);\n } else if (eventKey === ExcelEditCellKeyboardResponse.ARROW_RIGHT) {\n this.table.selectCell(col + 1, row);\n } else if (eventKey === ExcelEditCellKeyboardResponse.ARROW_DOWN) {\n this.table.selectCell(col, row + 1);\n } else if (eventKey === ExcelEditCellKeyboardResponse.ARROW_UP) {\n this.table.selectCell(col, row - 1);\n }\n // 阻止事件传播和默认行为\n event.stopPropagation();\n event.preventDefault();\n }\n } else {\n const { col, row } = this.table.stateManager.select.cellPos;\n if (\n this.table.editorManager.editingEditor &&\n (eventKey === ExcelEditCellKeyboardResponse.ENTER || eventKey === ExcelEditCellKeyboardResponse.TAB)\n ) {\n this.table.editorManager.completeEdit();\n this.table.getElement().focus();\n if (eventKey === ExcelEditCellKeyboardResponse.ENTER) {\n this.table.selectCell(col, row + 1);\n } else if (eventKey === ExcelEditCellKeyboardResponse.TAB) {\n this.table.selectCell(col + 1, row);\n }\n // 阻止事件传播和默认行为\n event.stopPropagation();\n event.preventDefault();\n } else if (\n !this.table.editorManager.editingEditor &&\n (eventKey === ExcelEditCellKeyboardResponse.DELETE || eventKey === ExcelEditCellKeyboardResponse.BACKSPACE)\n ) {\n //响应删除键,删除\n const selectCells = this.table.getSelectedCellInfos();\n if (selectCells?.length > 0) {\n // 如果选中的是范围,则删除范围内的所有单元格\n deleteSelectRange(selectCells, this.table);\n }\n // 阻止事件传播和默认行为\n event.stopPropagation();\n event.preventDefault();\n }\n }\n }\n }\n // 判断event的keyCode是否是excel的快捷键\n isExcelShortcutKey(event: KeyboardEvent) {\n return this.responseKeyboard.includes(event.key.toLowerCase() as ExcelEditCellKeyboardResponse);\n }\n setResponseKeyboard(responseKeyboard: ExcelEditCellKeyboardResponse[]) {\n this.responseKeyboard = responseKeyboard;\n }\n deleteResponseKeyboard(responseKeyboard: ExcelEditCellKeyboardResponse[]) {\n this.responseKeyboard = this.responseKeyboard.filter(key => !responseKeyboard.includes(key));\n }\n addResponseKeyboard(responseKeyboard: ExcelEditCellKeyboardResponse[]) {\n this.responseKeyboard = [...this.responseKeyboard, ...responseKeyboard];\n }\n release() {\n document.removeEventListener('keydown', this.handleKeyDown, true);\n }\n}\n//将选中单元格的值设置为空\nfunction deleteSelectRange(selectCells: TYPES.CellInfo[][], tableInstance: ListTable) {\n for (let i = 0; i < selectCells.length; i++) {\n for (let j = 0; j < selectCells[i].length; j++) {\n tableInstance.changeCellValue(selectCells[i][j].col, selectCells[i][j].row, '');\n }\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ListTable, PivotTable } from '@visactor/vtable';
|
|
2
|
-
import type { FilterState, FilterAction, FilterConfig } from './types';
|
|
2
|
+
import type { FilterState, FilterAction, FilterConfig, FilterListener } from './types';
|
|
3
3
|
import type { FilterEngine } from './filter-engine';
|
|
4
4
|
export declare class FilterStateManager {
|
|
5
5
|
private state;
|
|
@@ -12,7 +12,7 @@ export declare class FilterStateManager {
|
|
|
12
12
|
getAllFilterStates(): FilterState;
|
|
13
13
|
reapplyCurrentFilters(): void;
|
|
14
14
|
dispatch(action: FilterAction): void;
|
|
15
|
-
subscribe(listener:
|
|
15
|
+
subscribe(listener: FilterListener): () => void;
|
|
16
16
|
private notifyListeners;
|
|
17
17
|
private reduce;
|
|
18
18
|
private applyFilters;
|
|
@@ -29,15 +29,15 @@ class FilterStateManager {
|
|
|
29
29
|
}
|
|
30
30
|
dispatch(action) {
|
|
31
31
|
this.state = this.reduce(this.state, action), this.shouldApplyFilter(action) && this.applyFilters(),
|
|
32
|
-
this.notifyListeners();
|
|
32
|
+
this.notifyListeners(action);
|
|
33
33
|
}
|
|
34
34
|
subscribe(listener) {
|
|
35
35
|
return this.listeners.push(listener), () => {
|
|
36
36
|
this.listeners = this.listeners.filter((l => l !== listener));
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
-
notifyListeners() {
|
|
40
|
-
this.listeners.forEach((listener => listener(this.state)));
|
|
39
|
+
notifyListeners(action) {
|
|
40
|
+
this.listeners.forEach((listener => listener(this.state, action)));
|
|
41
41
|
}
|
|
42
42
|
reduce(state, action) {
|
|
43
43
|
const {type: type, payload: payload} = action, newFilter = new Map(state.filters);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/filter/filter-state-manager.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"sources":["../src/filter/filter-state-manager.ts"],"names":[],"mappings":";;;AAEA,mCAA2C;AAM3C,MAAa,kBAAkB;IAO7B,YAAY,KAA6B,EAAE,MAAoB;QAJvD,cAAS,GAA0B,EAAE,CAAC;QAK5C,IAAI,CAAC,KAAK,GAAG;YACX,OAAO,EAAE,IAAI,GAAG,EAAE;SACnB,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG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;gBACjC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,gDAAO,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAK,OAAO,KAAE,MAAM,EAAE,IAAI,IAAG,CAAC;gBAC5F,MAAM;SACT;QAED,uCAAY,KAAK,KAAE,OAAO,EAAE,SAAS,IAAG;IAC1C,CAAC;IAEO,YAAY;QAClB,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;IAEO,iBAAiB,CAAC,MAAoB;QAC5C,MAAM,kBAAkB,GAAG;YACzB,wBAAgB,CAAC,aAAa;YAC9B,wBAAgB,CAAC,aAAa;YAC9B,wBAAgB,CAAC,cAAc;YAC/B,wBAAgB,CAAC,iBAAiB;YAClC,wBAAgB,CAAC,aAAa;SAC/B,CAAC;QACF,OAAO,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,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 { FilterState, FilterAction, FilterConfig, FilterListener } from './types';\nimport { FilterActionType } from './types';\nimport type { FilterEngine } from './filter-engine';\n\n/**\n * 筛选状态管理器,用于管理筛选状态\n */\nexport class FilterStateManager {\n private state: FilterState;\n private engine: FilterEngine;\n private listeners: Array<FilterListener> = [];\n\n private table: ListTable | PivotTable;\n\n constructor(table: ListTable | PivotTable, engine: FilterEngine) {\n this.state = {\n filters: new Map()\n };\n this.engine = engine;\n this.table = table;\n }\n\n getFilterState(fieldId?: string | number): FilterConfig {\n return this.state.filters.get(fieldId);\n }\n\n /**\n * 获取所有激活的筛选字段\n */\n getActiveFilterFields(): (string | number)[] {\n const activeFields: (string | number)[] = [];\n this.state.filters.forEach((config, field) => {\n if (config.enable) {\n activeFields.push(field);\n }\n });\n return activeFields;\n }\n\n /**\n * 获取所有筛选状态\n */\n getAllFilterStates(): FilterState {\n return this.state;\n }\n\n /**\n * 公共方法:重新应用当前所有激活的筛选状态\n * 用于在表格配置更新后恢复筛选显示\n */\n reapplyCurrentFilters(): void {\n const activeFields = this.getActiveFilterFields();\n if (activeFields.length > 0) {\n this.applyFilters();\n }\n }\n\n dispatch(action: FilterAction) {\n this.state = this.reduce(this.state, action);\n if (this.shouldApplyFilter(action)) {\n this.applyFilters();\n }\n this.notifyListeners(action);\n }\n\n subscribe(listener: FilterListener): () => void {\n this.listeners.push(listener);\n return () => {\n this.listeners = this.listeners.filter(l => l !== listener);\n };\n }\n\n private notifyListeners(action: FilterAction): void {\n this.listeners.forEach(listener => listener(this.state, action));\n }\n\n private reduce(state: FilterState, action: FilterAction): FilterState {\n const { type, payload } = action;\n const newFilter = new Map(state.filters);\n switch (type) {\n case FilterActionType.ADD_FILTER:\n newFilter.set(payload.field, payload);\n break;\n case FilterActionType.REMOVE_FILTER:\n newFilter.delete(payload.field);\n break;\n case FilterActionType.UPDATE_FILTER:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), ...payload });\n break;\n case FilterActionType.ENABLE_FILTER:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), enable: true });\n break;\n case FilterActionType.DISABLE_FILTER:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), enable: false });\n break;\n case FilterActionType.CLEAR_ALL_FILTERS:\n newFilter.clear();\n break;\n case FilterActionType.APPLY_FILTERS:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), ...payload, enable: true });\n break;\n }\n\n return { ...state, filters: newFilter };\n }\n\n private applyFilters() {\n this.engine.applyFilter(this.state, this.table);\n }\n\n private shouldApplyFilter(action: FilterAction) {\n const shouldApplyActions = [\n FilterActionType.REMOVE_FILTER,\n FilterActionType.ENABLE_FILTER,\n FilterActionType.DISABLE_FILTER,\n FilterActionType.CLEAR_ALL_FILTERS,\n FilterActionType.APPLY_FILTERS\n ];\n return shouldApplyActions.includes(action.type) || action.payload.enable;\n }\n}\n"]}
|
|
@@ -85,7 +85,7 @@ class FilterToolbar {
|
|
|
85
85
|
this.filterMenu.style.left = `${left}px`, this.filterMenu.style.top = `${top}px`;
|
|
86
86
|
}
|
|
87
87
|
show(col, row, filterModes) {
|
|
88
|
-
this.filterModes = filterModes, this.filterModes.includes("byValue") ? this.filterModes.includes("byCondition") || (this.filterTabByCondition.style.display = "none",
|
|
88
|
+
this.valueFilter.clearSearchInputValue(), this.filterModes = filterModes, this.filterModes.includes("byValue") ? this.filterModes.includes("byCondition") || (this.filterTabByCondition.style.display = "none",
|
|
89
89
|
this.onTabSwitch("byValue")) : (this.filterTabByValue.style.display = "none", this.onTabSwitch("byCondition")),
|
|
90
90
|
this.adjustMenuPosition(col, row), this.filterMenu.style.display = "block";
|
|
91
91
|
const field = this.table.internalProps.layoutMap.getHeaderField(col, row);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/filter/filter-toolbar.ts"],"names":[],"mappings":";;;AAEA,iDAA6C;AAC7C,yDAAqD;AACrD,qCAAqD;AAMrD,MAAa,aAAa;IAoBxB,YAAY,KAA6B,EAAE,kBAAsC;QAjBjF,gBAAW,GAAuB,IAAI,CAAC;QACvC,oBAAe,GAA2B,IAAI,CAAC;QAC/C,cAAS,GAA8B,SAAS,CAAC;QACjD,cAAS,GAAY,KAAK,CAAC;QAC3B,kBAAa,GAA2B,IAAI,CAAC;QAC7C,gBAAW,GAAiB,EAAE,CAAC;QAa7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC7C,IAAI,CAAC,WAAW,GAAG,IAAI,0BAAW,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACxE,IAAI,CAAC,eAAe,GAAG,IAAI,kCAAe,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,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AClC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;QAExC,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,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"]}
|
|
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;QAChD,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC;QACrB,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;YACxB,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;SAC7B;aAAM;YACL,IAAI,CAAC,eAAe,CAAC,I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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;AAlPD,sCAkPC","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.valueFilter.clearSearchInputValue();\n this.filterModes = filterModes;\n if (!this.filterModes.includes('byValue')) {\n this.filterTabByValue.style.display = 'none';\n this.onTabSwitch('byCondition');\n } else if (!this.filterModes.includes('byCondition')) {\n this.filterTabByCondition.style.display = 'none';\n this.onTabSwitch('byValue');\n }\n\n this.adjustMenuPosition(col, row);\n this.filterMenu.style.display = 'block';\n\n const field = this.table.internalProps.layoutMap.getHeaderField(col, row) as string | number;\n this.updateSelectedField(field);\n\n // 根据当前筛选配置自动选择正确的筛选标签页\n const currentFilter = this.filterStateManager.getFilterState(field);\n if (currentFilter && currentFilter.type === 'byCondition') {\n this.onTabSwitch('byCondition');\n } else {\n this.onTabSwitch('byValue');\n }\n\n // 确保在事件冒泡完成后才设置 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"]}
|
package/cjs/filter/filter.js
CHANGED
|
@@ -36,10 +36,11 @@ class FilterPlugin {
|
|
|
36
36
|
this.filterStateManager = new filter_state_manager_1.FilterStateManager(this.table, this.filterEngine),
|
|
37
37
|
this.filterToolbar = new filter_toolbar_1.FilterToolbar(this.table, this.filterStateManager),
|
|
38
38
|
this.columns = eventArgs.options.columns, this.filterToolbar.render(document.body),
|
|
39
|
-
this.updateFilterIcons(this.columns), this.filterStateManager.subscribe((() => {
|
|
40
|
-
|
|
39
|
+
this.updateFilterIcons(this.columns), this.filterStateManager.subscribe(((_, action) => {
|
|
40
|
+
(null == action ? void 0 : action.type) !== types_1.FilterActionType.ADD_FILTER && (this.updateFilterIcons(this.columns),
|
|
41
|
+
this.table.updateColumns(this.columns, {
|
|
41
42
|
clearRowHeightCache: !1
|
|
42
|
-
});
|
|
43
|
+
}));
|
|
43
44
|
})); else if (runtime === vtable_1.TABLE_EVENT_TYPE.BEFORE_UPDATE_OPTION) this.pluginOptions = Object.assign(Object.assign({}, this.pluginOptions), eventArgs.options.plugins.find((plugin => plugin.id === this.id)).pluginOptions),
|
|
44
45
|
this.columns = eventArgs.options.columns, this.handleOptionUpdate(eventArgs.options); else if (runtime === vtable_1.TABLE_EVENT_TYPE.ICON_CLICK && "filter-icon" === eventArgs.name || "filtering-icon" === eventArgs.name) {
|
|
45
46
|
if (3 === (null === (_a = eventArgs.event) || void 0 === _a ? void 0 : _a.which) || 2 === (null === (_b = eventArgs.event) || void 0 === _b ? void 0 : _b.button) || 2 == (2 & (null === (_c = eventArgs.event) || void 0 === _c ? void 0 : _c.buttons))) return;
|
package/cjs/filter/filter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/filter/filter.ts"],"names":[],"mappings":";;;AAAA,6CAA2D;AAC3D,mDAA+C;AAC/C,iEAA4D;AAC5D,qDAAiD;AAEjD,mCAA2C;AAc3C,MAAa,YAAY;IAmBvB,YAAY,aA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,CAAC,KAAK;wBACnB,IAAI,EAAE,MAAM,CAAC,IAAI;wBACjB,MAAM,EAAE,MAAM,CAAC,MAAM;wBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;wBACzB,SAAS,EAAE,MAAM,CAAC,SAAS;wBAC3B,MAAM,EAAE,IAAI;qBACb;iBACF,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAC/B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC5B,CAAC;CACF;AAzSD,oCAySC","file":"filter.js","sourcesContent":["import { TABLE_EVENT_TYPE, TYPES } from '@visactor/vtable';\nimport { FilterEngine } from './filter-engine';\nimport { FilterStateManager } from './filter-state-manager';\nimport { FilterToolbar } from './filter-toolbar';\nimport type { FilterOptions, FilterConfig, FilterState } from './types';\nimport { FilterActionType } from './types';\nimport type {\n ListTableConstructorOptions,\n pluginsDefinition,\n ListTable,\n PivotTable,\n BaseTableAPI,\n ColumnDefine,\n ColumnsDefine\n} from '@visactor/vtable';\n\n/**\n * 筛选插件,负责初始化筛选引擎、状态管理器和工具栏\n */\nexport class FilterPlugin implements pluginsDefinition.IVTablePlugin {\n id = `filter`;\n name = 'Filter';\n runTime = [\n TABLE_EVENT_TYPE.BEFORE_INIT,\n TABLE_EVENT_TYPE.BEFORE_UPDATE_OPTION,\n TABLE_EVENT_TYPE.ICON_CLICK,\n TABLE_EVENT_TYPE.SCROLL\n ];\n\n pluginOptions: FilterOptions;\n\n table: ListTable | PivotTable;\n columns: ColumnsDefine;\n\n filterEngine: FilterEngine;\n filterStateManager: FilterStateManager;\n filterToolbar: FilterToolbar;\n\n constructor(pluginOptions: FilterOptions) {\n this.id = pluginOptions?.id ?? this.id;\n this.pluginOptions = pluginOptions;\n this.pluginOptions.filterIcon = pluginOptions.filterIcon ?? {\n name: 'filter-icon',\n type: 'svg',\n width: 12,\n height: 12,\n positionType: TYPES.IconPosition.right,\n cursor: 'pointer',\n svg: '<svg t=\"1752821809070\" class=\"icon\" viewBox=\"0 0 1664 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"12092\" width=\"200\" height=\"200\"><path d=\"M89.6 179.2A89.6 89.6 0 0 1 89.6 0h1408a89.6 89.6 0 0 1 0 179.2H89.6z m256 384a89.6 89.6 0 0 1 0-179.2h896a89.6 89.6 0 0 1 0 179.2h-896z m256 384a89.6 89.6 0 0 1 0-179.2h384a89.6 89.6 0 0 1 0 179.2h-384z\" fill=\"#93a2b9\" p-id=\"12093\"></path></svg>'\n };\n this.pluginOptions.filteringIcon = pluginOptions.filteringIcon ?? {\n name: 'filtering-icon',\n type: 'svg',\n width: 12,\n height: 12,\n positionType: TYPES.IconPosition.right,\n cursor: 'pointer',\n svg: '<svg t=\"1752821771292\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"11926\" width=\"200\" height=\"200\"><path d=\"M971.614323 53.05548L655.77935 412.054233C635.196622 435.434613 623.906096 465.509377 623.906096 496.583302v495.384307c0 28.975686-35.570152 43.063864-55.353551 21.781723l-159.865852-171.256294c-5.495389-5.895053-8.59279-13.688514-8.592789-21.781722V496.583302c0-31.073925-11.290526-61.148688-31.873254-84.429153L52.385677 53.05548C34.200936 32.472751 48.888611 0 76.365554 0h871.268892c27.476943 0 42.164618 32.472751 23.979877 53.05548z\" fill=\"#416eff\" p-id=\"11927\"></path></svg>'\n };\n if (!this.pluginOptions.filterModes || !this.pluginOptions.filterModes.length) {\n this.pluginOptions.filterModes = ['byValue', 'byCondition'];\n }\n }\n\n run(...args: any[]) {\n const eventArgs = args[0];\n const runtime = args[1];\n const table: BaseTableAPI = args[2];\n this.table = table as ListTable | PivotTable;\n\n if (runtime === TABLE_EVENT_TYPE.BEFORE_INIT) {\n this.filterEngine = new FilterEngine();\n this.filterStateManager = new FilterStateManager(this.table, this.filterEngine);\n this.filterToolbar = new FilterToolbar(this.table, this.filterStateManager);\n this.columns = eventArgs.options.columns;\n\n this.filterToolbar.render(document.body);\n this.updateFilterIcons(this.columns);\n this.filterStateManager.subscribe(() => {\n this.updateFilterIcons(this.columns);\n (this.table as ListTable).updateColumns(this.columns, {\n clearRowHeightCache: false\n });\n });\n } else if (runtime === TABLE_EVENT_TYPE.BEFORE_UPDATE_OPTION) {\n this.pluginOptions = {\n ...this.pluginOptions,\n ...(eventArgs.options.plugins as FilterPlugin[]).find(plugin => plugin.id === this.id).pluginOptions\n };\n this.columns = eventArgs.options.columns;\n this.handleOptionUpdate(eventArgs.options);\n } else if (\n (runtime === TABLE_EVENT_TYPE.ICON_CLICK && eventArgs.name === 'filter-icon') ||\n eventArgs.name === 'filtering-icon'\n ) {\n const isRightClick =\n eventArgs.event?.which === 3 || eventArgs.event?.button === 2 || (eventArgs.event?.buttons & 2) === 2;\n // 如果是右键点击,直接返回不处理\n if (isRightClick) {\n return;\n }\n\n const col = eventArgs.col;\n const row = eventArgs.row;\n if (this.filterToolbar.isVisible) {\n this.filterToolbar.hide();\n } else {\n this.filterToolbar.show(col, row, this.pluginOptions.filterModes);\n }\n } else if (runtime === TABLE_EVENT_TYPE.SCROLL) {\n if (eventArgs.scrollDirection === 'horizontal') {\n this.filterToolbar.adjustMenuPosition();\n }\n }\n }\n\n update() {\n if (this.filterStateManager) {\n this.reapplyActiveFilters();\n }\n }\n\n /**\n * 处理选项更新事件\n */\n private handleOptionUpdate(options: ListTableConstructorOptions): void {\n const currentActiveFields = this.filterStateManager ? this.filterStateManager.getActiveFilterFields() : [];\n\n // 验证筛选状态一致性\n if (this.filterStateManager && currentActiveFields.length > 0) {\n this.validateFilterStatesAfterUpdate(options, currentActiveFields);\n }\n\n // 更新筛选图标\n this.updateFilterIcons(options.columns);\n }\n\n /**\n * 重新应用所有激活的筛选状态\n * 在 updateOption 后调用,因为 updateOption 会全量更新表格\n */\n private reapplyActiveFilters(): void {\n this.filterStateManager.reapplyCurrentFilters();\n }\n\n /**\n * 验证更新后的筛选状态一致性\n */\n private validateFilterStatesAfterUpdate(\n options: ListTableConstructorOptions,\n activeFields: (string | number)[]\n ): void {\n const columns = options.columns;\n const fieldsToRemove: (string | number)[] = [];\n\n activeFields.forEach(field => {\n const column = columns.find(col => col.field === field);\n\n // 检查该列是否仍然应该启用筛选\n if (!column || !this.shouldEnableFilterForColumn(field, column)) {\n fieldsToRemove.push(field);\n }\n });\n\n // 清除不再有效的筛选状态\n fieldsToRemove.forEach(field => {\n this.filterStateManager.dispatch({\n type: FilterActionType.REMOVE_FILTER,\n payload: { field }\n });\n });\n }\n\n /**\n * 更新所有列的筛选图标状态\n * 根据列的筛选启用状态,添加或移除筛选图标\n */\n private updateFilterIcons(columns: ColumnsDefine = []) {\n const filterIcon = this.pluginOptions.filterIcon;\n const filteringIcon = this.pluginOptions.filteringIcon;\n\n const isIconEqual = (a, b) =>\n a === b || (a && b && typeof a === 'object' && typeof b === 'object' && a.name === b.name);\n\n const toIconList = icons => (icons ? (Array.isArray(icons) ? icons : [icons]) : []);\n\n const compactIcons = list => (list.length === 0 ? undefined : list.length === 1 ? list[0] : list);\n\n columns.forEach(column => {\n const shouldShow = this.shouldEnableFilterForColumn(column.field, column);\n const isFiltering = !!this.filterStateManager.getFilterState(column.field)?.enable;\n let icons = toIconList(column.headerIcon);\n\n if (shouldShow) {\n if (isFiltering) {\n if (!icons.some(icon => isIconEqual(icon, filteringIcon))) {\n icons = icons.filter(icon => !isIconEqual(icon, filterIcon));\n icons.push(filteringIcon);\n }\n } else {\n if (!icons.some(icon => isIconEqual(icon, filterIcon))) {\n icons = icons.filter(icon => !isIconEqual(icon, filteringIcon));\n icons.push(filterIcon);\n }\n }\n } else {\n icons = icons.filter(icon => !isIconEqual(icon, filterIcon));\n }\n\n column.headerIcon = compactIcons(icons);\n });\n }\n\n /**\n * 判断指定列是否应该启用筛选功能\n */\n shouldEnableFilterForColumn(field: number | string, column: ColumnDefine): boolean {\n // 如果是空白列,不适用筛选\n if (!column.title) {\n return false;\n }\n\n // 首先检查列级别的 filter 属性(最高优先级)\n const columnWithFilter = column as any;\n if (columnWithFilter.filter !== undefined) {\n return !!columnWithFilter.filter;\n }\n\n // 如果有自定义的启用钩子函数,使用钩子函数的结果\n if (this.pluginOptions.enableFilter) {\n return this.pluginOptions.enableFilter(field, column);\n }\n\n // 如果没有钩子函数,使用默认启用配置\n if (this.pluginOptions.defaultEnabled !== undefined) {\n return this.pluginOptions.defaultEnabled;\n }\n\n // 默认情况,所有列都启用筛选\n return true;\n }\n\n /**\n * 获取当前的筛选状态\n * 用于保存配置时获取筛选状态\n */\n getFilterState(): any {\n if (!this.filterStateManager) {\n return null;\n }\n\n const state = this.filterStateManager.getAllFilterStates();\n const serializedState: Record<string | number, any> = {};\n\n // 将 Map 转换为普通对象以便序列化\n state.filters.forEach((config: FilterConfig, field: string | number) => {\n serializedState[field] = {\n enable: config.enable,\n field: config.field,\n type: config.type,\n values: config.values,\n operator: config.operator,\n condition: config.condition\n };\n });\n\n return {\n filters: serializedState\n };\n }\n\n /**\n * 设置筛选状态\n * 用于从保存的配置中恢复筛选状态\n */\n setFilterState(filterState?: FilterState): void {\n if (!this.filterStateManager) {\n console.warn('setFilterState: 状态管理器未初始化');\n return;\n }\n\n // 清除当前所有筛选\n this.filterStateManager.dispatch({\n type: FilterActionType.CLEAR_ALL_FILTERS,\n payload: {}\n });\n\n // 若传入参数为空,则重置筛选状态\n if (!filterState || !filterState.filters) {\n return;\n }\n\n // 恢复每个筛选配置\n Object.entries(filterState.filters).forEach(([, config]: [string, any]) => {\n if (config.enable) {\n this.filterStateManager.dispatch({\n type: FilterActionType.ADD_FILTER,\n payload: {\n field: config.field,\n type: config.type,\n values: config.values,\n operator: config.operator,\n condition: config.condition,\n enable: true\n }\n });\n }\n });\n }\n\n release() {\n this.table = null;\n this.filterEngine = null;\n this.filterStateManager = null;\n this.filterToolbar = null;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/filter/filter.ts"],"names":[],"mappings":";;;AAAA,6CAA2D;AAC3D,mDAA+C;AAC/C,iEAA4D;AAC5D,qDAAiD;AAEjD,mCAA2C;AAc3C,MAAa,YAAY;IAmBvB,YAAY,aAA4B;;QAlBxC,OAAE,GAAG,QAAQ,CAAC;QACd,SAAI,GAAG,QAAQ,CAAC;QAChB,YAAO,GAAG;YACR,yBAAgB,CAAC,WAAW;YAC5B,yBAAgB,CAAC,oBAAoB;YACrC,yBAAgB,CAAC,UAAU;YAC3B,yBAAgB,CAAC,MAAM;SACxB,CAAC;QAYA,IAAI,CAAC,EAAE,GAAG,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,EAAE,mCAAI,IAAI,CAAC,EAAE,CAAC;QACvC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,aAAa,CAAC,UAAU,GAAG,MAAA,aAAa,CAAC,UAAU,mCAAI;YAC1D,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE,KAAK;YACX,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,EAAE;YACV,YAAY,EAAE,cAAK,CAAC,YAAY,CAAC,KAAK;YACtC,MAAM,EAAE,SAAS;YACjB,GAAG,EAAE,oZAAoZ;SAC1Z,CAAC;QACF,IAAI,CAAC,aAAa,CAAC,aAAa,GAAG,MAAA,aAAa,CAAC,aAAa,mCAAI;YAChE,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,KAAK;YACX,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,EAAE;YACV,YAAY,EAAE,cAAK,CAAC,YAAY,CAAC,KAAK;YACtC,MAAM,EAAE,SAAS;YACjB,GAAG,EAAE,+nBAA+nB;SACroB,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC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AE;SACZ,CAAC,CAAC;QAGH,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE;YACxC,OAAO;SACR;QAGD,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAgB,EAAE,EAAE;YACxE,IAAI,MAAM,CAAC,MAAM,EAAE;gBACjB,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC;oBAC/B,IAAI,EAAE,wBAAgB,CAAC,UAAU;oBACjC,OAAO,EAAE;wBACP,KAAK,EAAE,MAAM,CAAC,KAAK;wBACnB,IAAI,EAAE,MAAM,CAAC,IAAI;wBACjB,MAAM,EAAE,MAAM,CAAC,MAAM;wBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;wBACzB,SAAS,EAAE,MAAM,CAAC,SAAS;wBAC3B,MAAM,EAAE,IAAI;qBACb;iBACF,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;QAC/B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC5B,CAAC;CACF;AA7SD,oCA6SC","file":"filter.js","sourcesContent":["import { TABLE_EVENT_TYPE, TYPES } from '@visactor/vtable';\nimport { FilterEngine } from './filter-engine';\nimport { FilterStateManager } from './filter-state-manager';\nimport { FilterToolbar } from './filter-toolbar';\nimport type { FilterOptions, FilterConfig, FilterState, FilterAction } from './types';\nimport { FilterActionType } from './types';\nimport type {\n ListTableConstructorOptions,\n pluginsDefinition,\n ListTable,\n PivotTable,\n BaseTableAPI,\n ColumnDefine,\n ColumnsDefine\n} from '@visactor/vtable';\n\n/**\n * 筛选插件,负责初始化筛选引擎、状态管理器和工具栏\n */\nexport class FilterPlugin implements pluginsDefinition.IVTablePlugin {\n id = `filter`;\n name = 'Filter';\n runTime = [\n TABLE_EVENT_TYPE.BEFORE_INIT,\n TABLE_EVENT_TYPE.BEFORE_UPDATE_OPTION,\n TABLE_EVENT_TYPE.ICON_CLICK,\n TABLE_EVENT_TYPE.SCROLL\n ];\n\n pluginOptions: FilterOptions;\n\n table: ListTable | PivotTable;\n columns: ColumnsDefine;\n\n filterEngine: FilterEngine;\n filterStateManager: FilterStateManager;\n filterToolbar: FilterToolbar;\n\n constructor(pluginOptions: FilterOptions) {\n this.id = pluginOptions?.id ?? this.id;\n this.pluginOptions = pluginOptions;\n this.pluginOptions.filterIcon = pluginOptions.filterIcon ?? {\n name: 'filter-icon',\n type: 'svg',\n width: 12,\n height: 12,\n positionType: TYPES.IconPosition.right,\n cursor: 'pointer',\n svg: '<svg t=\"1752821809070\" class=\"icon\" viewBox=\"0 0 1664 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"12092\" width=\"200\" height=\"200\"><path d=\"M89.6 179.2A89.6 89.6 0 0 1 89.6 0h1408a89.6 89.6 0 0 1 0 179.2H89.6z m256 384a89.6 89.6 0 0 1 0-179.2h896a89.6 89.6 0 0 1 0 179.2h-896z m256 384a89.6 89.6 0 0 1 0-179.2h384a89.6 89.6 0 0 1 0 179.2h-384z\" fill=\"#93a2b9\" p-id=\"12093\"></path></svg>'\n };\n this.pluginOptions.filteringIcon = pluginOptions.filteringIcon ?? {\n name: 'filtering-icon',\n type: 'svg',\n width: 12,\n height: 12,\n positionType: TYPES.IconPosition.right,\n cursor: 'pointer',\n svg: '<svg t=\"1752821771292\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"11926\" width=\"200\" height=\"200\"><path d=\"M971.614323 53.05548L655.77935 412.054233C635.196622 435.434613 623.906096 465.509377 623.906096 496.583302v495.384307c0 28.975686-35.570152 43.063864-55.353551 21.781723l-159.865852-171.256294c-5.495389-5.895053-8.59279-13.688514-8.592789-21.781722V496.583302c0-31.073925-11.290526-61.148688-31.873254-84.429153L52.385677 53.05548C34.200936 32.472751 48.888611 0 76.365554 0h871.268892c27.476943 0 42.164618 32.472751 23.979877 53.05548z\" fill=\"#416eff\" p-id=\"11927\"></path></svg>'\n };\n if (!this.pluginOptions.filterModes || !this.pluginOptions.filterModes.length) {\n this.pluginOptions.filterModes = ['byValue', 'byCondition'];\n }\n }\n\n run(...args: any[]) {\n const eventArgs = args[0];\n const runtime = args[1];\n const table: BaseTableAPI = args[2];\n this.table = table as ListTable | PivotTable;\n\n if (runtime === TABLE_EVENT_TYPE.BEFORE_INIT) {\n this.filterEngine = new FilterEngine();\n this.filterStateManager = new FilterStateManager(this.table, this.filterEngine);\n this.filterToolbar = new FilterToolbar(this.table, this.filterStateManager);\n this.columns = eventArgs.options.columns;\n\n this.filterToolbar.render(document.body);\n this.updateFilterIcons(this.columns);\n this.filterStateManager.subscribe((_: FilterState, action?: FilterAction) => {\n // 新增筛选配置时,不需要更新筛选图标以及表格\n if (action?.type === FilterActionType.ADD_FILTER) {\n return;\n }\n this.updateFilterIcons(this.columns);\n (this.table as ListTable).updateColumns(this.columns, {\n clearRowHeightCache: false\n });\n });\n } else if (runtime === TABLE_EVENT_TYPE.BEFORE_UPDATE_OPTION) {\n this.pluginOptions = {\n ...this.pluginOptions,\n ...(eventArgs.options.plugins as FilterPlugin[]).find(plugin => plugin.id === this.id).pluginOptions\n };\n this.columns = eventArgs.options.columns;\n this.handleOptionUpdate(eventArgs.options);\n } else if (\n (runtime === TABLE_EVENT_TYPE.ICON_CLICK && eventArgs.name === 'filter-icon') ||\n eventArgs.name === 'filtering-icon'\n ) {\n const isRightClick =\n eventArgs.event?.which === 3 || eventArgs.event?.button === 2 || (eventArgs.event?.buttons & 2) === 2;\n // 如果是右键点击,直接返回不处理\n if (isRightClick) {\n return;\n }\n\n const col = eventArgs.col;\n const row = eventArgs.row;\n if (this.filterToolbar.isVisible) {\n this.filterToolbar.hide();\n } else {\n this.filterToolbar.show(col, row, this.pluginOptions.filterModes);\n }\n } else if (runtime === TABLE_EVENT_TYPE.SCROLL) {\n if (eventArgs.scrollDirection === 'horizontal') {\n this.filterToolbar.adjustMenuPosition();\n }\n }\n }\n\n update() {\n if (this.filterStateManager) {\n this.reapplyActiveFilters();\n }\n }\n\n /**\n * 处理选项更新事件\n */\n private handleOptionUpdate(options: ListTableConstructorOptions): void {\n const currentActiveFields = this.filterStateManager ? this.filterStateManager.getActiveFilterFields() : [];\n\n // 验证筛选状态一致性\n if (this.filterStateManager && currentActiveFields.length > 0) {\n this.validateFilterStatesAfterUpdate(options, currentActiveFields);\n }\n\n // 更新筛选图标\n this.updateFilterIcons(options.columns);\n }\n\n /**\n * 重新应用所有激活的筛选状态\n * 在 updateOption 后调用,因为 updateOption 会全量更新表格\n */\n private reapplyActiveFilters(): void {\n this.filterStateManager.reapplyCurrentFilters();\n }\n\n /**\n * 验证更新后的筛选状态一致性\n */\n private validateFilterStatesAfterUpdate(\n options: ListTableConstructorOptions,\n activeFields: (string | number)[]\n ): void {\n const columns = options.columns;\n const fieldsToRemove: (string | number)[] = [];\n\n activeFields.forEach(field => {\n const column = columns.find(col => col.field === field);\n\n // 检查该列是否仍然应该启用筛选\n if (!column || !this.shouldEnableFilterForColumn(field, column)) {\n fieldsToRemove.push(field);\n }\n });\n\n // 清除不再有效的筛选状态\n fieldsToRemove.forEach(field => {\n this.filterStateManager.dispatch({\n type: FilterActionType.REMOVE_FILTER,\n payload: { field }\n });\n });\n }\n\n /**\n * 更新所有列的筛选图标状态\n * 根据列的筛选启用状态,添加或移除筛选图标\n */\n private updateFilterIcons(columns: ColumnsDefine = []) {\n const filterIcon = this.pluginOptions.filterIcon;\n const filteringIcon = this.pluginOptions.filteringIcon;\n\n const isIconEqual = (a: any, b: any) =>\n a === b || (a && b && typeof a === 'object' && typeof b === 'object' && a.name === b.name);\n\n const toIconList = (icons: any) => (icons ? (Array.isArray(icons) ? icons : [icons]) : []);\n\n const compactIcons = (list: any[]) => (list.length === 0 ? undefined : list.length === 1 ? list[0] : list);\n\n columns.forEach(column => {\n const shouldShow = this.shouldEnableFilterForColumn(column.field as string | number, column);\n const isFiltering = !!this.filterStateManager.getFilterState(column.field as string | number)?.enable;\n let icons = toIconList(column.headerIcon);\n\n if (shouldShow) {\n if (isFiltering) {\n if (!icons.some(icon => isIconEqual(icon, filteringIcon))) {\n icons = icons.filter(icon => !isIconEqual(icon, filterIcon));\n icons.push(filteringIcon);\n }\n } else {\n if (!icons.some(icon => isIconEqual(icon, filterIcon))) {\n icons = icons.filter(icon => !isIconEqual(icon, filteringIcon));\n icons.push(filterIcon);\n }\n }\n } else {\n icons = icons.filter(icon => !isIconEqual(icon, filterIcon));\n }\n\n column.headerIcon = compactIcons(icons);\n });\n }\n\n /**\n * 判断指定列是否应该启用筛选功能\n */\n shouldEnableFilterForColumn(field: number | string, column: ColumnDefine): boolean {\n // 如果是空白列,不适用筛选\n if (!column.title) {\n return false;\n }\n\n // 首先检查列级别的 filter 属性(最高优先级)\n const columnWithFilter = column as any;\n if (columnWithFilter.filter !== undefined) {\n return !!columnWithFilter.filter;\n }\n\n // 如果有自定义的启用钩子函数,使用钩子函数的结果\n if (this.pluginOptions.enableFilter) {\n return this.pluginOptions.enableFilter(field, column);\n }\n\n // 如果没有钩子函数,使用默认启用配置\n if (this.pluginOptions.defaultEnabled !== undefined) {\n return this.pluginOptions.defaultEnabled;\n }\n\n // 默认情况,所有列都启用筛选\n return true;\n }\n\n /**\n * 获取当前的筛选状态\n * 用于保存配置时获取筛选状态\n */\n getFilterState(): any {\n if (!this.filterStateManager) {\n return null;\n }\n\n const state = this.filterStateManager.getAllFilterStates();\n const serializedState: Record<string | number, any> = {};\n\n // 将 Map 转换为普通对象以便序列化\n state.filters.forEach((config: FilterConfig, field: string | number) => {\n serializedState[field] = {\n enable: config.enable,\n field: config.field,\n type: config.type,\n values: config.values,\n operator: config.operator,\n condition: config.condition\n };\n });\n\n return {\n filters: serializedState\n };\n }\n\n /**\n * 设置筛选状态\n * 用于从保存的配置中恢复筛选状态\n */\n setFilterState(filterState?: FilterState): void {\n if (!this.filterStateManager) {\n console.warn('setFilterState: 状态管理器未初始化');\n return;\n }\n\n // 清除当前所有筛选\n this.filterStateManager.dispatch({\n type: FilterActionType.CLEAR_ALL_FILTERS,\n payload: {}\n });\n\n // 若传入参数为空,则重置筛选状态\n if (!filterState || !filterState.filters) {\n return;\n }\n\n // 恢复每个筛选配置\n Object.entries(filterState.filters).forEach(([, config]: [string, any]) => {\n if (config.enable) {\n this.filterStateManager.dispatch({\n type: FilterActionType.ADD_FILTER,\n payload: {\n field: config.field,\n type: config.type,\n values: config.values,\n operator: config.operator,\n condition: config.condition,\n enable: true\n }\n });\n }\n });\n }\n\n release() {\n this.table = null;\n this.filterEngine = null;\n this.filterStateManager = null;\n this.filterToolbar = null;\n }\n}\n"]}
|
package/cjs/filter/types.d.ts
CHANGED
package/cjs/filter/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/filter/types.ts"],"names":[],"mappings":";;;AAiCA,IAAY,gBAQX;AARD,WAAY,gBAAgB;IAC1B,mEAAU,CAAA;IACV,yEAAa,CAAA;IACb,yEAAa,CAAA;IACb,yEAAa,CAAA;IACb,2EAAc,CAAA;IACd,iFAAiB,CAAA;IACjB,yEAAa,CAAA;AACf,CAAC,EARW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAQ3B;AA2CD,IAAY,sBAOX;AAPD,WAAY,sBAAsB;IAChC,qCAAW,CAAA;IACX,uCAAa,CAAA;IACb,2CAAiB,CAAA;IACjB,yCAAe,CAAA;IACf,+CAAqB,CAAA;IACrB,yCAAe,CAAA;AACjB,CAAC,EAPW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAOjC","file":"types.js","sourcesContent":["import type { TYPES } from '@visactor/vtable';\n\nexport interface FilterOptions {\n /** 筛选器 ID,用于唯一标识筛选器 */\n id?: string;\n /** 筛选器图标 */\n filterIcon?: TYPES.ColumnIconOption;\n /** 筛选器激活图标 */\n filteringIcon?: TYPES.ColumnIconOption;\n /** 筛选功能启用钩子函数,返回指定列是否启用筛选功能 */\n enableFilter?: (field: number | string, column: TYPES.ColumnDefine) => boolean;\n /** 默认是否启用筛选(当 enableFilter 未定义时使用) */\n defaultEnabled?: boolean;\n /** 是否展示按条件筛选,按值筛选 UI */\n filterModes?: FilterMode[];\n}\n\nexport type FilterMode = 'byValue' | 'byCondition';\n\nexport interface FilterState {\n filters: Map<string | number, FilterConfig>;\n // activeFilters: string[]; // 激活的筛选器的 ID 列表\n}\n\nexport interface FilterConfig {\n enable: boolean; // 是否启用筛选\n field: string | number; // 对应表格列,同时作为筛选配置的唯一标识\n type: 'byValue' | 'byCondition'; // 筛选类型\n values?: any[]; // 按值筛选时的值列表\n operator?: FilterOperator; // 按条件筛选时的操作符\n condition?: any; // 按条件筛选时的具体条件\n}\n\nexport enum FilterActionType {\n ADD_FILTER,\n REMOVE_FILTER,\n UPDATE_FILTER,\n ENABLE_FILTER,\n DISABLE_FILTER,\n CLEAR_ALL_FILTERS,\n APPLY_FILTERS\n}\n\nexport interface FilterAction {\n type: FilterActionType;\n payload: any;\n}\n\nexport interface ValueFilterOptionDom {\n id: string;\n originalValue: any;\n itemContainer: HTMLDivElement;\n checkbox: HTMLInputElement;\n countSpan: HTMLSpanElement;\n}\n\nexport type FilterOperator =\n // 通用\n | 'equals'\n | 'notEquals'\n // 数值\n | 'greaterThan'\n | 'lessThan'\n | 'greaterThanOrEqual'\n | 'lessThanOrEqual'\n | 'between'\n | 'notBetween'\n // 文本\n | 'contains'\n | 'notContains'\n | 'startsWith'\n | 'notStartsWith'\n | 'endsWith'\n | 'notEndsWith'\n // 复选框 | 单选框\n | 'isChecked'\n | 'isUnchecked';\n\nexport interface OperatorOption {\n value: FilterOperator;\n label: string;\n category: FilterOperatorCategory;\n}\n\nexport enum FilterOperatorCategory {\n ALL = 'all',\n TEXT = 'text',\n NUMBER = 'number',\n COLOR = 'color',\n CHECKBOX = 'checkbox',\n RADIO = 'radio'\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/filter/types.ts"],"names":[],"mappings":";;;AAiCA,IAAY,gBAQX;AARD,WAAY,gBAAgB;IAC1B,mEAAU,CAAA;IACV,yEAAa,CAAA;IACb,yEAAa,CAAA;IACb,yEAAa,CAAA;IACb,2EAAc,CAAA;IACd,iFAAiB,CAAA;IACjB,yEAAa,CAAA;AACf,CAAC,EARW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAQ3B;AA2CD,IAAY,sBAOX;AAPD,WAAY,sBAAsB;IAChC,qCAAW,CAAA;IACX,uCAAa,CAAA;IACb,2CAAiB,CAAA;IACjB,yCAAe,CAAA;IACf,+CAAqB,CAAA;IACrB,yCAAe,CAAA;AACjB,CAAC,EAPW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAOjC","file":"types.js","sourcesContent":["import type { TYPES } from '@visactor/vtable';\n\nexport interface FilterOptions {\n /** 筛选器 ID,用于唯一标识筛选器 */\n id?: string;\n /** 筛选器图标 */\n filterIcon?: TYPES.ColumnIconOption;\n /** 筛选器激活图标 */\n filteringIcon?: TYPES.ColumnIconOption;\n /** 筛选功能启用钩子函数,返回指定列是否启用筛选功能 */\n enableFilter?: (field: number | string, column: TYPES.ColumnDefine) => boolean;\n /** 默认是否启用筛选(当 enableFilter 未定义时使用) */\n defaultEnabled?: boolean;\n /** 是否展示按条件筛选,按值筛选 UI */\n filterModes?: FilterMode[];\n}\n\nexport type FilterMode = 'byValue' | 'byCondition';\n\nexport interface FilterState {\n filters: Map<string | number, FilterConfig>;\n // activeFilters: string[]; // 激活的筛选器的 ID 列表\n}\n\nexport interface FilterConfig {\n enable: boolean; // 是否启用筛选\n field: string | number; // 对应表格列,同时作为筛选配置的唯一标识\n type: 'byValue' | 'byCondition'; // 筛选类型\n values?: any[]; // 按值筛选时的值列表\n operator?: FilterOperator; // 按条件筛选时的操作符\n condition?: any; // 按条件筛选时的具体条件\n}\n\nexport enum FilterActionType {\n ADD_FILTER,\n REMOVE_FILTER,\n UPDATE_FILTER,\n ENABLE_FILTER,\n DISABLE_FILTER,\n CLEAR_ALL_FILTERS,\n APPLY_FILTERS\n}\n\nexport interface FilterAction {\n type: FilterActionType;\n payload: any;\n}\n\nexport interface ValueFilterOptionDom {\n id: string;\n originalValue: any;\n itemContainer: HTMLDivElement;\n checkbox: HTMLInputElement;\n countSpan: HTMLSpanElement;\n}\n\nexport type FilterOperator =\n // 通用\n | 'equals'\n | 'notEquals'\n // 数值\n | 'greaterThan'\n | 'lessThan'\n | 'greaterThanOrEqual'\n | 'lessThanOrEqual'\n | 'between'\n | 'notBetween'\n // 文本\n | 'contains'\n | 'notContains'\n | 'startsWith'\n | 'notStartsWith'\n | 'endsWith'\n | 'notEndsWith'\n // 复选框 | 单选框\n | 'isChecked'\n | 'isUnchecked';\n\nexport interface OperatorOption {\n value: FilterOperator;\n label: string;\n category: FilterOperatorCategory;\n}\n\nexport enum FilterOperatorCategory {\n ALL = 'all',\n TEXT = 'text',\n NUMBER = 'number',\n COLOR = 'color',\n CHECKBOX = 'checkbox',\n RADIO = 'radio'\n}\n\nexport type FilterListener = (state: FilterState, action?: FilterAction) => void;\n"]}
|