@visactor/vtable-search 1.19.7 → 1.19.8
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/search-component/search-component.d.ts +2 -2
- package/cjs/search-component/search-component.js +36 -29
- package/cjs/search-component/search-component.js.map +1 -1
- package/dist/vtable-export.js +68 -61
- package/dist/vtable-export.min.js +1 -1
- package/es/search-component/search-component.d.ts +2 -2
- package/es/search-component/search-component.js +36 -29
- package/es/search-component/search-component.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as VTable from '@visactor/vtable';
|
|
2
|
-
import { ITableAnimationOption } from '@visactor/vtable/src/ts-types';
|
|
2
|
+
import type { ITableAnimationOption } from '@visactor/vtable/src/ts-types';
|
|
3
3
|
type IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;
|
|
4
4
|
export type QueryResult = {
|
|
5
5
|
queryStr: string;
|
|
@@ -25,7 +25,7 @@ export type SearchComponentOption = {
|
|
|
25
25
|
table: IVTable;
|
|
26
26
|
}) => boolean;
|
|
27
27
|
fieldsToSearch?: string[];
|
|
28
|
-
scrollOption
|
|
28
|
+
scrollOption?: ITableAnimationOption;
|
|
29
29
|
callback?: (queryResult: QueryResult, table: IVTable) => void;
|
|
30
30
|
};
|
|
31
31
|
export declare class SearchComponent {
|
|
@@ -60,12 +60,12 @@ class SearchComponent {
|
|
|
60
60
|
}), item.children && Array.isArray(item.children) && item.children.length > 0 && walk(item.children, currentPath);
|
|
61
61
|
}));
|
|
62
62
|
};
|
|
63
|
-
return walk(this.table.records, []), this.jumpToCell({
|
|
63
|
+
return walk(this.table.records, []), this.queryResult.length > 0 && this.jumpToCell({
|
|
64
64
|
IndexNumber: this.queryResult[0].indexNumber
|
|
65
65
|
}), this.callback && this.callback({
|
|
66
66
|
queryStr: this.queryStr,
|
|
67
67
|
results: this.queryResult
|
|
68
|
-
}, this.table), this.updateCellStyle(), this.currentIndex = 0, {
|
|
68
|
+
}, this.table), this.updateCellStyle(!0), this.currentIndex = 0, {
|
|
69
69
|
index: 0,
|
|
70
70
|
results: this.queryResult
|
|
71
71
|
};
|
|
@@ -98,7 +98,7 @@ class SearchComponent {
|
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
return this.updateCellStyle(), this.callback && this.callback({
|
|
101
|
+
return this.updateCellStyle(!0), this.callback && this.callback({
|
|
102
102
|
queryStr: this.queryStr,
|
|
103
103
|
results: this.queryResult
|
|
104
104
|
}, this.table), this.autoJump ? this.next() : {
|
|
@@ -107,25 +107,32 @@ class SearchComponent {
|
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
updateCellStyle(highlight = !0) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
110
|
+
var _a;
|
|
111
|
+
if (null != highlight) {
|
|
112
|
+
if (this.queryResult) if (this.table.hasCustomCellStyle("__search_component_highlight") || this.table.registerCustomCellStyle("__search_component_highlight", this.highlightCellStyle),
|
|
113
|
+
this.table.hasCustomCellStyle("__search_component_focuse") || this.table.registerCustomCellStyle("__search_component_focuse", this.focuseHighlightCellStyle),
|
|
114
|
+
this.isTree) {
|
|
115
|
+
const {range: range, indexNumber: indexNumber} = this.queryResult[0];
|
|
116
|
+
let i = 0;
|
|
117
|
+
for (;this.table.isHeader(0, i); ) i++;
|
|
118
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
119
|
+
range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
|
|
120
|
+
range: range
|
|
121
|
+
}, highlight ? "__search_component_focuse" : null);
|
|
122
|
+
} else for (let i = 0; i < this.queryResult.length; i++) {
|
|
123
|
+
const {col: col, row: row, range: range} = this.queryResult[i];
|
|
124
|
+
range ? this.table.arrangeCustomCellStyle({
|
|
125
|
+
range: range
|
|
126
|
+
}, highlight ? "__search_component_highlight" : null) : this.table.arrangeCustomCellStyle({
|
|
127
|
+
col: col,
|
|
128
|
+
row: row
|
|
129
|
+
}, highlight ? "__search_component_highlight" : null);
|
|
130
|
+
}
|
|
131
|
+
} else (null === (_a = this.queryResult) || void 0 === _a ? void 0 : _a.length) && this.queryResult.forEach((({range: range}) => {
|
|
132
|
+
range && this.table.arrangeCustomCellStyle({
|
|
123
133
|
range: range
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
row: row
|
|
127
|
-
}, highlight ? "__search_component_highlight" : null);
|
|
128
|
-
}
|
|
134
|
+
}, "");
|
|
135
|
+
}));
|
|
129
136
|
}
|
|
130
137
|
next() {
|
|
131
138
|
if (!this.queryResult.length) return {
|
|
@@ -138,7 +145,7 @@ class SearchComponent {
|
|
|
138
145
|
if (range) {
|
|
139
146
|
let i = 0;
|
|
140
147
|
for (;this.table.isHeader(0, i); ) i++;
|
|
141
|
-
|
|
148
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
142
149
|
range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
|
|
143
150
|
range: range
|
|
144
151
|
}, "__search_component_highlight");
|
|
@@ -151,7 +158,7 @@ class SearchComponent {
|
|
|
151
158
|
}), range) {
|
|
152
159
|
let i = 0;
|
|
153
160
|
for (;this.table.isHeader(0, i); ) i++;
|
|
154
|
-
|
|
161
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
155
162
|
range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
|
|
156
163
|
range: range
|
|
157
164
|
}, "__search_component_focuse");
|
|
@@ -194,7 +201,7 @@ class SearchComponent {
|
|
|
194
201
|
if (range) {
|
|
195
202
|
let i = 0;
|
|
196
203
|
for (;this.table.isHeader(0, i); ) i++;
|
|
197
|
-
|
|
204
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
198
205
|
range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
|
|
199
206
|
range: range
|
|
200
207
|
}, "__search_component_highlight");
|
|
@@ -207,7 +214,7 @@ class SearchComponent {
|
|
|
207
214
|
}), range) {
|
|
208
215
|
let i = 0;
|
|
209
216
|
for (;this.table.isHeader(0, i); ) i++;
|
|
210
|
-
|
|
217
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
211
218
|
range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
|
|
212
219
|
range: range
|
|
213
220
|
}, "__search_component_focuse");
|
|
@@ -241,13 +248,13 @@ class SearchComponent {
|
|
|
241
248
|
}
|
|
242
249
|
jumpToCell(params) {
|
|
243
250
|
if (this.isTree) {
|
|
244
|
-
const {IndexNumber: IndexNumber} = params;
|
|
245
|
-
let
|
|
251
|
+
const {IndexNumber: IndexNumber} = params, indexNumbers = [ ...IndexNumber ], tmp = [ ...indexNumbers ];
|
|
252
|
+
let tmpNumber = 0, i = 0;
|
|
246
253
|
for (;tmpNumber < tmp.length - 1; ) {
|
|
247
254
|
tmpNumber++;
|
|
248
|
-
|
|
255
|
+
const indexNumber = indexNumbers.slice(0, tmpNumber);
|
|
249
256
|
for (;this.table.isHeader(0, i); ) i++;
|
|
250
|
-
|
|
257
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
251
258
|
"expand" !== this.table.getHierarchyState(this.treeIndex, row) && this.table.toggleHierarchyState(this.treeIndex, row);
|
|
252
259
|
}
|
|
253
260
|
this.table.scrollToRow(this.getBodyRowIndexByRecordIndex(indexNumbers) + i, this.scrollOption);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["search-component/search-component.ts"],"names":[],"mappings":";;;AAGA,6CAA2C;AA6B3C,MAAM,0BAA0B,GAAoC;IAClE,OAAO,EAAE,wBAAwB;CAClC,CAAC;AAEF,MAAM,+BAA+B,GAAoC;IACvE,OAAO,EAAE,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,aAAa,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;IACD,KAAK;QAEH,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;IACzB,CAAC;CACF;AArfD,0CAqfC","file":"search-component.js","sourcesContent":["import type * as VTable from '@visactor/vtable';\nimport { ITableAnimationOption } from '@visactor/vtable/src/ts-types';\nimport { EasingType } from '@visactor/vtable/src/vrender';\nimport { isValid } from '@visactor/vutils';\ntype IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;\n\nexport type QueryResult = {\n queryStr: string;\n results: {\n col?: number;\n row?: number;\n value?: string;\n indexNumber?: number[];\n\n }[];\n};\n\nexport type SearchComponentOption = {\n table: IVTable;\n autoJump?: boolean;\n skipHeader?: boolean;\n highlightCellStyle?: VTable.TYPES.CellStyle;\n focuseHighlightCellStyle?: VTable.TYPES.CellStyle;\n queryMethod?: (queryStr: string, value: string, option?: { col: number; row: number; table: IVTable }) => boolean;\n treeQueryMethod?: (queryStr: string, node: any, fieldsToSearch?: string[], option?: { table: IVTable }) => boolean;\n fieldsToSearch?: string[];\n scrollOption: ITableAnimationOption;\n\n\n callback?: (queryResult: QueryResult, table: IVTable) => void;\n};\n\nconst defalutHightlightCellStyle: Partial<VTable.TYPES.CellStyle> = {\n bgColor: 'rgba(255, 255, 0, 0.2)'\n};\n\nconst defalutFocusHightlightCellStyle: Partial<VTable.TYPES.CellStyle> = {\n bgColor: 'rgba(255, 155, 0, 0.2)'\n};\n\nfunction defalultQueryMethod(queryStr: string, value: string) {\n return isValid(queryStr) && isValid(value) && value.toString().includes(queryStr);\n}\nfunction defalultTreeQueryMethod(queryStr: string, node: any, fieldsToSearch?: string[]) {\n if (!isValid(queryStr)) return false;\n\n // 如果没有传 fieldsToSearch,则用 node 的全部 key\n const searchFields = (Array.isArray(fieldsToSearch) && fieldsToSearch.length > 0)\n ? fieldsToSearch\n : Object.keys(node);\n\n return searchFields.some(field =>\n isValid(node?.[field]) &&\n node[field].toString().includes(queryStr)\n );\n}\nexport class SearchComponent {\n table: IVTable;\n skipHeader: boolean;\n autoJump: boolean;\n highlightCellStyle: Partial<VTable.TYPES.CellStyle>;\n focuseHighlightCellStyle: Partial<VTable.TYPES.CellStyle>;\n queryMethod: (queryStr: string, value: string, option: { col: number; row: number; table: IVTable }) => boolean;\n treeQueryMethod: (queryStr: string, node: any, fieldsToSearch?: string[], option?: { table: IVTable }) => boolean;\n fieldsToSearch: string[];\n\n\n callback?: (queryResult: QueryResult, table: IVTable) => void;\n\n queryStr: string;\n queryResult: {\n col?: number;\n row?: number;\n range?: VTable.TYPES.CellRange;\n value?: string;\n indexNumber?: number[];\n }[];\n\n currentIndex: number;\n isTree: boolean;\n treeIndex: number;\n scrollOption: ITableAnimationOption;\n\n constructor(option: SearchComponentOption) {\n this.table = option.table;\n this.autoJump = option.autoJump || false;\n this.skipHeader = option.skipHeader || false;\n this.highlightCellStyle = option.highlightCellStyle || defalutHightlightCellStyle;\n this.focuseHighlightCellStyle = option.focuseHighlightCellStyle || defalutFocusHightlightCellStyle;\n this.queryMethod = option.queryMethod || defalultQueryMethod;\n this.treeQueryMethod = option.treeQueryMethod || defalultTreeQueryMethod;\n this.fieldsToSearch = option.fieldsToSearch || [];\n this.isTree = false\n this.treeIndex = 0\n this.callback = option.callback;\n this.scrollOption = option.scrollOption || { duration: 900, easing: 'quartIn' as EasingType } as ITableAnimationOption\n this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle as any);\n this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle as any);\n }\n\n search(str: string) {\n this.clear();\n this.queryStr = str;\n\n if (!str) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n this.isTree = this.table.options.columns.some((item: any) => item.tree)\n this.treeIndex = this.isTree\n ? this.table.options.columns.findIndex((item: any) => item.tree)\n : 0;\n if (this.isTree) {\n // 如果传入单一节点也能处理\n const colEnd = this.table.colCount;\n const walk = (nodes: any[], path: number[]) => {\n nodes.forEach((item: any, idx: number) => {\n const currentPath = [...path, idx]; // 当前节点的完整路径\n\n // 保持你的 treeQueryMethod 调用方式(this 上下文来自定义环境)\n if (this.treeQueryMethod(this.queryStr, item, this.fieldsToSearch, { table: this.table })) {\n this.queryResult.push({\n indexNumber: currentPath,\n range: {\n start: { row: null, col: 0 },\n end: { row: null, col: colEnd }\n }\n\n });\n }\n\n if (item.children && Array.isArray(item.children) && item.children.length > 0) {\n walk(item.children, currentPath);\n }\n });\n };\n\n walk(this.table.records, []);\n\n this.jumpToCell({ IndexNumber: this.queryResult[0].indexNumber });\n\n\n if (this.callback) {\n this.callback(\n {\n queryStr: this.queryStr,\n results: this.queryResult\n },\n this.table\n );\n }\n this.updateCellStyle();\n\n // if (this.autoJump) {\n // return this.next();\n // }\n this.currentIndex = 0;\n\n return {\n index: 0,\n results: this.queryResult\n };\n } else {\n for (let row = 0; row < this.table.rowCount; row++) {\n for (let col = 0; col < this.table.colCount; col++) {\n if (this.skipHeader && this.table.isHeader(col, row)) {\n continue;\n }\n const value = this.table.getCellValue(col, row);\n if (this.queryMethod(this.queryStr, value, { col, row, table: this.table })) {\n // deal merge cell\n const mergeCell = this.table.getCellRange(col, row);\n if (mergeCell.start.col !== mergeCell.end.col || mergeCell.start.row !== mergeCell.end.row) {\n // find is cell already in queryResult\n let isIn = false;\n for (let i = this.queryResult.length - 1; i >= 0; i--) {\n if (this.queryResult[i].col === mergeCell.start.col && this.queryResult[i].row === mergeCell.start.row) {\n isIn = true;\n break;\n }\n }\n if (!isIn) {\n this.queryResult.push({\n col: mergeCell.start.col,\n row: mergeCell.start.row,\n range: mergeCell,\n value\n });\n }\n } else {\n this.queryResult.push({\n col,\n row,\n value\n });\n }\n }\n }\n }\n this.updateCellStyle();\n\n if (this.callback) {\n this.callback(\n {\n queryStr: this.queryStr,\n results: this.queryResult\n },\n this.table\n );\n }\n\n if (this.autoJump) {\n return this.next();\n }\n return {\n index: 0,\n results: this.queryResult\n };\n }\n\n\n\n\n\n\n }\n\n updateCellStyle(highlight: boolean = true) {\n if (!this.queryResult) {\n return;\n }\n\n if (!this.table.hasCustomCellStyle('__search_component_highlight')) {\n this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle as any);\n }\n if (!this.table.hasCustomCellStyle('__search_component_focuse')) {\n this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle as any);\n }\n if (this.isTree) {\n const { range, indexNumber } = this.queryResult[0];\n\n let i = 0;\n\n // 如果是表头就往下偏移\n while (this.table.isHeader(0, i)) {\n i++;\n }\n let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row\n range.end.row = row\n\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n highlight ? '__search_component_focuse' : null\n );\n\n } else {\n for (let i = 0; i < this.queryResult.length; i++) {\n\n const { col, row, range } = this.queryResult[i];\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n highlight ? '__search_component_highlight' : null\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n highlight ? '__search_component_highlight' : null\n );\n }\n }\n }\n\n }\n\n next() {\n if (!this.queryResult.length) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n if (this.isTree) {\n\n if (this.currentIndex !== -1) {\n const { range, indexNumber } = this.queryResult[this.currentIndex];\n\n\n if (range) {\n let i = 0;\n\n // 如果是表头就往下偏移\n while (this.table.isHeader(0, i)) {\n i++;\n }\n let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row\n range.end.row = row\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_highlight'\n );\n }\n }\n\n this.currentIndex++;\n if (this.currentIndex >= this.queryResult.length) {\n this.currentIndex = 0;\n }\n const { range, indexNumber } = this.queryResult[this.currentIndex];\n this.jumpToCell({ IndexNumber: indexNumber });\n\n if (range) {\n let i = 0;\n\n // 如果是表头就往下偏移\n while (this.table.isHeader(0, i)) {\n i++;\n }\n let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row\n range.end.row = row\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_focuse'\n );\n }\n\n } else {\n\n if (this.currentIndex !== -1) {\n const { col, row, range } = this.queryResult[this.currentIndex];\n\n // reset last focus\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_highlight'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n '__search_component_highlight'\n );\n }\n }\n this.currentIndex++;\n if (this.currentIndex >= this.queryResult.length) {\n this.currentIndex = 0;\n }\n const { col, row, range } = this.queryResult[this.currentIndex];\n\n // this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_focuse'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n '__search_component_focuse'\n );\n }\n\n this.jumpToCell({ col, row });\n }\n\n\n\n return {\n index: this.currentIndex,\n results: this.queryResult\n };\n }\n\n prev() {\n if (!this.queryResult.length) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n\n if (this.isTree) {\n // 先取消当前高亮\n if (this.currentIndex !== -1) {\n const { range, indexNumber } = this.queryResult[this.currentIndex];\n if (range) {\n let i = 0;\n while (this.table.isHeader(0, i)) {\n i++;\n }\n let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row;\n range.end.row = row;\n this.table.arrangeCustomCellStyle(\n { range },\n '__search_component_highlight'\n );\n }\n }\n\n // 索引向前\n this.currentIndex--;\n if (this.currentIndex < 0) {\n this.currentIndex = this.queryResult.length - 1;\n }\n\n // 焦点样式\n const { range, indexNumber } = this.queryResult[this.currentIndex];\n this.jumpToCell({ IndexNumber: indexNumber });\n\n if (range) {\n let i = 0;\n while (this.table.isHeader(0, i)) {\n i++;\n }\n let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row;\n range.end.row = row;\n this.table.arrangeCustomCellStyle(\n { range },\n '__search_component_focuse'\n );\n }\n\n } else {\n // 普通表格处理\n if (this.currentIndex !== -1) {\n const { col, row, range } = this.queryResult[this.currentIndex];\n if (range) {\n this.table.arrangeCustomCellStyle(\n { range },\n '__search_component_highlight'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n { col, row },\n '__search_component_highlight'\n );\n }\n }\n\n this.currentIndex--;\n if (this.currentIndex < 0) {\n this.currentIndex = this.queryResult.length - 1;\n }\n\n const { col, row, range } = this.queryResult[this.currentIndex];\n if (range) {\n this.table.arrangeCustomCellStyle(\n { range },\n '__search_component_focuse'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n { col, row },\n '__search_component_focuse'\n );\n }\n\n this.jumpToCell({ col, row });\n }\n\n return {\n index: this.currentIndex,\n results: this.queryResult\n };\n }\n\n\n jumpToCell(params: { col?: number; row?: number, IndexNumber?: number[] }) {\n\n if (this.isTree) {\n const { IndexNumber } = params\n let indexNumbers = [...IndexNumber]\n\n let tmp = [...indexNumbers]\n let tmpNumber = 0\n let i = 0;\n\n while (tmpNumber < tmp.length - 1) {\n tmpNumber++\n let indexNumber = indexNumbers.slice(0, tmpNumber)\n\n // 如果是表头就往下偏移\n while (this.table.isHeader(0, i)) {\n i++;\n }\n let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n\n const hierarchyState = this.table.getHierarchyState(\n this.treeIndex,\n row\n );\n\n if (hierarchyState !== 'expand') {\n\n this.table.toggleHierarchyState(\n this.treeIndex,\n row\n );\n }\n }\n this.table.scrollToRow(this.getBodyRowIndexByRecordIndex(indexNumbers) + i, this.scrollOption)\n\n\n } else {\n const { col, row } = params;\n // if focus cell out of screen, jump to cell\n const { rowStart, rowEnd } = this.table.getBodyVisibleRowRange();\n const { colStart, colEnd } = this.table.getBodyVisibleColRange();\n if (row <= rowStart || row >= rowEnd || col <= colStart || col >= colEnd) {\n this.table.scrollToCell({ col, row });\n }\n }\n\n\n }\n getBodyRowIndexByRecordIndex(index: number | number[]): number {\n if (Array.isArray(index) && index.length === 1) {\n index = index[0];\n }\n return this.table.dataSource.getTableIndex(index);\n }\n clear() {\n // reset highlight cell style\n this.updateCellStyle(null);\n this.queryStr = '';\n this.queryResult = [];\n this.currentIndex = -1;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["search-component/search-component.ts"],"names":[],"mappings":";;;AAGA,6CAA2C;AA0B3C,MAAM,0BAA0B,GAAoC;IAClE,OAAO,EAAE,wBAAwB;CAClC,CAAC;AAEF,MAAM,+BAA+B,GAAoC;IACvE,OAAO,EAAE,wBAAwB;CAClC,CAAC;AAEF,SAAS,mBAAmB,CAAC,QAAgB,EAAE,KAAa;IAC1D,OAAO,IAAA,gBAAO,EAAC,QAAQ,CAAC,IAAI,IAAA,gBAAO,EAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACpF,CAAC;AACD,SAAS,uBAAuB,CAAC,QAAgB,EAAE,IAAS,EAAE,cAAyB;IACrF,IAAI,CAAC,IAAA,gBAAO,EAAC,QAAQ,CAAC,EAAE;QACtB,OAAO,KAAK,CAAC;KACd;IAGD,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAErH,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,IAAA,gBAAO,EAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAG,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,QA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,EAAE,GAAG,CAAC,CAAC;iBACtD;aACF;YACD,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,4BAA4B,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;SAChG;aAAM;YACL,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;YAE5B,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,sBAAsB,EAAE,CAAC;YACjE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,sBAAsB,EAAE,CAAC;YACjE,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,IAAI,MAAM,EAAE;gBACxE,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;aACvC;SACF;IACH,CAAC;IACD,4BAA4B,CAAC,KAAwB;QACnD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YAC9C,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;SAClB;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;IACD,KAAK;QAEH,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;IACzB,CAAC;CACF;AA/cD,0CA+cC","file":"search-component.js","sourcesContent":["import type * as VTable from '@visactor/vtable';\nimport type { ITableAnimationOption } from '@visactor/vtable/src/ts-types';\nimport type { EasingType } from '@visactor/vtable/src/vrender';\nimport { isValid } from '@visactor/vutils';\ntype IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;\n\nexport type QueryResult = {\n queryStr: string;\n results: {\n col?: number;\n row?: number;\n value?: string;\n indexNumber?: number[];\n }[];\n};\n\nexport type SearchComponentOption = {\n table: IVTable;\n autoJump?: boolean;\n skipHeader?: boolean;\n highlightCellStyle?: VTable.TYPES.CellStyle;\n focuseHighlightCellStyle?: VTable.TYPES.CellStyle;\n queryMethod?: (queryStr: string, value: string, option?: { col: number; row: number; table: IVTable }) => boolean;\n treeQueryMethod?: (queryStr: string, node: any, fieldsToSearch?: string[], option?: { table: IVTable }) => boolean;\n fieldsToSearch?: string[];\n scrollOption?: ITableAnimationOption;\n callback?: (queryResult: QueryResult, table: IVTable) => void;\n};\n\nconst defalutHightlightCellStyle: Partial<VTable.TYPES.CellStyle> = {\n bgColor: 'rgba(255, 255, 0, 0.2)'\n};\n\nconst defalutFocusHightlightCellStyle: Partial<VTable.TYPES.CellStyle> = {\n bgColor: 'rgba(255, 155, 0, 0.2)'\n};\n\nfunction defalultQueryMethod(queryStr: string, value: string) {\n return isValid(queryStr) && isValid(value) && value.toString().includes(queryStr);\n}\nfunction defalultTreeQueryMethod(queryStr: string, node: any, fieldsToSearch?: string[]) {\n if (!isValid(queryStr)) {\n return false;\n }\n\n // 如果没有传 fieldsToSearch,则用 node 的全部 key\n const searchFields = Array.isArray(fieldsToSearch) && fieldsToSearch.length > 0 ? fieldsToSearch : Object.keys(node);\n\n return searchFields.some(field => isValid(node?.[field]) && node[field].toString().includes(queryStr));\n}\nexport class SearchComponent {\n table: IVTable;\n skipHeader: boolean;\n autoJump: boolean;\n highlightCellStyle: Partial<VTable.TYPES.CellStyle>;\n focuseHighlightCellStyle: Partial<VTable.TYPES.CellStyle>;\n queryMethod: (queryStr: string, value: string, option: { col: number; row: number; table: IVTable }) => boolean;\n treeQueryMethod: (queryStr: string, node: any, fieldsToSearch?: string[], option?: { table: IVTable }) => boolean;\n fieldsToSearch: string[];\n\n callback?: (queryResult: QueryResult, table: IVTable) => void;\n\n queryStr: string;\n queryResult: {\n col?: number;\n row?: number;\n range?: VTable.TYPES.CellRange;\n value?: string;\n indexNumber?: number[];\n }[];\n\n currentIndex: number;\n isTree: boolean;\n treeIndex: number;\n scrollOption: ITableAnimationOption;\n\n constructor(option: SearchComponentOption) {\n this.table = option.table;\n this.autoJump = option.autoJump || false;\n this.skipHeader = option.skipHeader || false;\n this.highlightCellStyle = option.highlightCellStyle || defalutHightlightCellStyle;\n this.focuseHighlightCellStyle = option.focuseHighlightCellStyle || defalutFocusHightlightCellStyle;\n this.queryMethod = option.queryMethod || defalultQueryMethod;\n this.treeQueryMethod = option.treeQueryMethod || defalultTreeQueryMethod;\n this.fieldsToSearch = option.fieldsToSearch || [];\n this.isTree = false;\n this.treeIndex = 0;\n this.callback = option.callback;\n this.scrollOption =\n option.scrollOption || ({ duration: 900, easing: 'quartIn' as EasingType } as ITableAnimationOption);\n this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle as any);\n this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle as any);\n }\n\n search(str: string) {\n this.clear();\n this.queryStr = str;\n\n if (!str) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n this.isTree = this.table.options.columns.some((item: any) => item.tree);\n this.treeIndex = this.isTree ? this.table.options.columns.findIndex((item: any) => item.tree) : 0;\n if (this.isTree) {\n // 如果传入单一节点也能处理\n const colEnd = this.table.colCount;\n const walk = (nodes: any[], path: number[]) => {\n nodes.forEach((item: any, idx: number) => {\n const currentPath = [...path, idx]; // 当前节点的完整路径\n\n // 保持你的 treeQueryMethod 调用方式(this 上下文来自定义环境)\n if (this.treeQueryMethod(this.queryStr, item, this.fieldsToSearch, { table: this.table })) {\n this.queryResult.push({\n indexNumber: currentPath,\n range: {\n start: { row: null, col: 0 },\n end: { row: null, col: colEnd }\n }\n });\n }\n\n if (item.children && Array.isArray(item.children) && item.children.length > 0) {\n walk(item.children, currentPath);\n }\n });\n };\n\n walk(this.table.records, []);\n if (this.queryResult.length > 0) {\n this.jumpToCell({ IndexNumber: this.queryResult[0].indexNumber });\n }\n\n if (this.callback) {\n this.callback(\n {\n queryStr: this.queryStr,\n results: this.queryResult\n },\n this.table\n );\n }\n this.updateCellStyle(true);\n\n // if (this.autoJump) {\n // return this.next();\n // }\n this.currentIndex = 0;\n\n return {\n index: 0,\n results: this.queryResult\n };\n }\n for (let row = 0; row < this.table.rowCount; row++) {\n for (let col = 0; col < this.table.colCount; col++) {\n if (this.skipHeader && this.table.isHeader(col, row)) {\n continue;\n }\n const value = this.table.getCellValue(col, row);\n if (this.queryMethod(this.queryStr, value, { col, row, table: this.table })) {\n // deal merge cell\n const mergeCell = this.table.getCellRange(col, row);\n if (mergeCell.start.col !== mergeCell.end.col || mergeCell.start.row !== mergeCell.end.row) {\n // find is cell already in queryResult\n let isIn = false;\n for (let i = this.queryResult.length - 1; i >= 0; i--) {\n if (this.queryResult[i].col === mergeCell.start.col && this.queryResult[i].row === mergeCell.start.row) {\n isIn = true;\n break;\n }\n }\n if (!isIn) {\n this.queryResult.push({\n col: mergeCell.start.col,\n row: mergeCell.start.row,\n range: mergeCell,\n value\n });\n }\n } else {\n this.queryResult.push({\n col,\n row,\n value\n });\n }\n }\n }\n }\n this.updateCellStyle(true);\n\n if (this.callback) {\n this.callback(\n {\n queryStr: this.queryStr,\n results: this.queryResult\n },\n this.table\n );\n }\n\n if (this.autoJump) {\n return this.next();\n }\n return {\n index: 0,\n results: this.queryResult\n };\n }\n\n updateCellStyle(highlight: boolean = true) {\n if (highlight == null) {\n if (this.queryResult?.length) {\n this.queryResult.forEach(({ range }) => {\n if (range) {\n this.table.arrangeCustomCellStyle(\n { range },\n '' // 或者 null,看API是否允许\n );\n }\n });\n }\n return;\n }\n if (!this.queryResult) {\n return;\n }\n\n if (!this.table.hasCustomCellStyle('__search_component_highlight')) {\n this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle as any);\n }\n if (!this.table.hasCustomCellStyle('__search_component_focuse')) {\n this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle as any);\n }\n if (this.isTree) {\n const { range, indexNumber } = this.queryResult[0];\n\n let i = 0;\n\n // 如果是表头就往下偏移\n while (this.table.isHeader(0, i)) {\n i++;\n }\n const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row;\n range.end.row = row;\n\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n highlight ? '__search_component_focuse' : null\n );\n } else {\n for (let i = 0; i < this.queryResult.length; i++) {\n const { col, row, range } = this.queryResult[i];\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n highlight ? '__search_component_highlight' : null\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n highlight ? '__search_component_highlight' : null\n );\n }\n }\n }\n }\n\n next() {\n if (!this.queryResult.length) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n if (this.isTree) {\n if (this.currentIndex !== -1) {\n const { range, indexNumber } = this.queryResult[this.currentIndex];\n\n if (range) {\n let i = 0;\n\n // 如果是表头就往下偏移\n while (this.table.isHeader(0, i)) {\n i++;\n }\n const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row;\n range.end.row = row;\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_highlight'\n );\n }\n }\n\n this.currentIndex++;\n if (this.currentIndex >= this.queryResult.length) {\n this.currentIndex = 0;\n }\n const { range, indexNumber } = this.queryResult[this.currentIndex];\n this.jumpToCell({ IndexNumber: indexNumber });\n\n if (range) {\n let i = 0;\n\n // 如果是表头就往下偏移\n while (this.table.isHeader(0, i)) {\n i++;\n }\n const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row;\n range.end.row = row;\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_focuse'\n );\n }\n } else {\n if (this.currentIndex !== -1) {\n const { col, row, range } = this.queryResult[this.currentIndex];\n\n // reset last focus\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_highlight'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n '__search_component_highlight'\n );\n }\n }\n this.currentIndex++;\n if (this.currentIndex >= this.queryResult.length) {\n this.currentIndex = 0;\n }\n const { col, row, range } = this.queryResult[this.currentIndex];\n\n // this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_focuse'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n '__search_component_focuse'\n );\n }\n\n this.jumpToCell({ col, row });\n }\n\n return {\n index: this.currentIndex,\n results: this.queryResult\n };\n }\n\n prev() {\n if (!this.queryResult.length) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n\n if (this.isTree) {\n // 先取消当前高亮\n if (this.currentIndex !== -1) {\n const { range, indexNumber } = this.queryResult[this.currentIndex];\n if (range) {\n let i = 0;\n while (this.table.isHeader(0, i)) {\n i++;\n }\n const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row;\n range.end.row = row;\n this.table.arrangeCustomCellStyle({ range }, '__search_component_highlight');\n }\n }\n\n // 索引向前\n this.currentIndex--;\n if (this.currentIndex < 0) {\n this.currentIndex = this.queryResult.length - 1;\n }\n\n // 焦点样式\n const { range, indexNumber } = this.queryResult[this.currentIndex];\n this.jumpToCell({ IndexNumber: indexNumber });\n\n if (range) {\n let i = 0;\n while (this.table.isHeader(0, i)) {\n i++;\n }\n const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row;\n range.end.row = row;\n this.table.arrangeCustomCellStyle({ range }, '__search_component_focuse');\n }\n } else {\n // 普通表格处理\n if (this.currentIndex !== -1) {\n const { col, row, range } = this.queryResult[this.currentIndex];\n if (range) {\n this.table.arrangeCustomCellStyle({ range }, '__search_component_highlight');\n } else {\n this.table.arrangeCustomCellStyle({ col, row }, '__search_component_highlight');\n }\n }\n\n this.currentIndex--;\n if (this.currentIndex < 0) {\n this.currentIndex = this.queryResult.length - 1;\n }\n\n const { col, row, range } = this.queryResult[this.currentIndex];\n if (range) {\n this.table.arrangeCustomCellStyle({ range }, '__search_component_focuse');\n } else {\n this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');\n }\n\n this.jumpToCell({ col, row });\n }\n\n return {\n index: this.currentIndex,\n results: this.queryResult\n };\n }\n\n jumpToCell(params: { col?: number; row?: number; IndexNumber?: number[] }) {\n if (this.isTree) {\n const { IndexNumber } = params;\n const indexNumbers = [...IndexNumber];\n\n const tmp = [...indexNumbers];\n let tmpNumber = 0;\n let i = 0;\n\n while (tmpNumber < tmp.length - 1) {\n tmpNumber++;\n const indexNumber = indexNumbers.slice(0, tmpNumber);\n\n // 如果是表头就往下偏移\n while (this.table.isHeader(0, i)) {\n i++;\n }\n const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n\n const hierarchyState = this.table.getHierarchyState(this.treeIndex, row);\n\n if (hierarchyState !== 'expand') {\n this.table.toggleHierarchyState(this.treeIndex, row);\n }\n }\n this.table.scrollToRow(this.getBodyRowIndexByRecordIndex(indexNumbers) + i, this.scrollOption);\n } else {\n const { col, row } = params;\n // if focus cell out of screen, jump to cell\n const { rowStart, rowEnd } = this.table.getBodyVisibleRowRange();\n const { colStart, colEnd } = this.table.getBodyVisibleColRange();\n if (row <= rowStart || row >= rowEnd || col <= colStart || col >= colEnd) {\n this.table.scrollToCell({ col, row });\n }\n }\n }\n getBodyRowIndexByRecordIndex(index: number | number[]): number {\n if (Array.isArray(index) && index.length === 1) {\n index = index[0];\n }\n return this.table.dataSource.getTableIndex(index);\n }\n clear() {\n // reset highlight cell style\n this.updateCellStyle(null);\n this.queryStr = '';\n this.queryResult = [];\n this.currentIndex = -1;\n }\n}\n"]}
|
package/dist/vtable-export.js
CHANGED
|
@@ -17,13 +17,11 @@
|
|
|
17
17
|
return isValid$1(queryStr) && isValid$1(value) && value.toString().includes(queryStr);
|
|
18
18
|
}
|
|
19
19
|
function defalultTreeQueryMethod(queryStr, node, fieldsToSearch) {
|
|
20
|
-
if (!isValid$1(queryStr))
|
|
20
|
+
if (!isValid$1(queryStr)) {
|
|
21
21
|
return false;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return searchFields.some(field => isValid$1(node?.[field]) &&
|
|
26
|
-
node[field].toString().includes(queryStr));
|
|
22
|
+
}
|
|
23
|
+
const searchFields = Array.isArray(fieldsToSearch) && fieldsToSearch.length > 0 ? fieldsToSearch : Object.keys(node);
|
|
24
|
+
return searchFields.some(field => isValid$1(node?.[field]) && node[field].toString().includes(queryStr));
|
|
27
25
|
}
|
|
28
26
|
class SearchComponent {
|
|
29
27
|
table;
|
|
@@ -53,7 +51,8 @@
|
|
|
53
51
|
this.isTree = false;
|
|
54
52
|
this.treeIndex = 0;
|
|
55
53
|
this.callback = option.callback;
|
|
56
|
-
this.scrollOption =
|
|
54
|
+
this.scrollOption =
|
|
55
|
+
option.scrollOption || { duration: 900, easing: 'quartIn' };
|
|
57
56
|
this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle);
|
|
58
57
|
this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle);
|
|
59
58
|
}
|
|
@@ -67,9 +66,7 @@
|
|
|
67
66
|
};
|
|
68
67
|
}
|
|
69
68
|
this.isTree = this.table.options.columns.some((item) => item.tree);
|
|
70
|
-
this.treeIndex = this.isTree
|
|
71
|
-
? this.table.options.columns.findIndex((item) => item.tree)
|
|
72
|
-
: 0;
|
|
69
|
+
this.treeIndex = this.isTree ? this.table.options.columns.findIndex((item) => item.tree) : 0;
|
|
73
70
|
if (this.isTree) {
|
|
74
71
|
const colEnd = this.table.colCount;
|
|
75
72
|
const walk = (nodes, path) => {
|
|
@@ -90,73 +87,83 @@
|
|
|
90
87
|
});
|
|
91
88
|
};
|
|
92
89
|
walk(this.table.records, []);
|
|
93
|
-
|
|
90
|
+
if (this.queryResult.length > 0) {
|
|
91
|
+
this.jumpToCell({ IndexNumber: this.queryResult[0].indexNumber });
|
|
92
|
+
}
|
|
94
93
|
if (this.callback) {
|
|
95
94
|
this.callback({
|
|
96
95
|
queryStr: this.queryStr,
|
|
97
96
|
results: this.queryResult
|
|
98
97
|
}, this.table);
|
|
99
98
|
}
|
|
100
|
-
this.updateCellStyle();
|
|
99
|
+
this.updateCellStyle(true);
|
|
101
100
|
this.currentIndex = 0;
|
|
102
101
|
return {
|
|
103
102
|
index: 0,
|
|
104
103
|
results: this.queryResult
|
|
105
104
|
};
|
|
106
105
|
}
|
|
107
|
-
|
|
108
|
-
for (let
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
if (!isIn) {
|
|
125
|
-
this.queryResult.push({
|
|
126
|
-
col: mergeCell.start.col,
|
|
127
|
-
row: mergeCell.start.row,
|
|
128
|
-
range: mergeCell,
|
|
129
|
-
value
|
|
130
|
-
});
|
|
106
|
+
for (let row = 0; row < this.table.rowCount; row++) {
|
|
107
|
+
for (let col = 0; col < this.table.colCount; col++) {
|
|
108
|
+
if (this.skipHeader && this.table.isHeader(col, row)) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const value = this.table.getCellValue(col, row);
|
|
112
|
+
if (this.queryMethod(this.queryStr, value, { col, row, table: this.table })) {
|
|
113
|
+
const mergeCell = this.table.getCellRange(col, row);
|
|
114
|
+
if (mergeCell.start.col !== mergeCell.end.col || mergeCell.start.row !== mergeCell.end.row) {
|
|
115
|
+
let isIn = false;
|
|
116
|
+
for (let i = this.queryResult.length - 1; i >= 0; i--) {
|
|
117
|
+
if (this.queryResult[i].col === mergeCell.start.col && this.queryResult[i].row === mergeCell.start.row) {
|
|
118
|
+
isIn = true;
|
|
119
|
+
break;
|
|
131
120
|
}
|
|
132
121
|
}
|
|
133
|
-
|
|
122
|
+
if (!isIn) {
|
|
134
123
|
this.queryResult.push({
|
|
135
|
-
col,
|
|
136
|
-
row,
|
|
124
|
+
col: mergeCell.start.col,
|
|
125
|
+
row: mergeCell.start.row,
|
|
126
|
+
range: mergeCell,
|
|
137
127
|
value
|
|
138
128
|
});
|
|
139
129
|
}
|
|
140
130
|
}
|
|
131
|
+
else {
|
|
132
|
+
this.queryResult.push({
|
|
133
|
+
col,
|
|
134
|
+
row,
|
|
135
|
+
value
|
|
136
|
+
});
|
|
137
|
+
}
|
|
141
138
|
}
|
|
142
139
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}, this.table);
|
|
149
|
-
}
|
|
150
|
-
if (this.autoJump) {
|
|
151
|
-
return this.next();
|
|
152
|
-
}
|
|
153
|
-
return {
|
|
154
|
-
index: 0,
|
|
140
|
+
}
|
|
141
|
+
this.updateCellStyle(true);
|
|
142
|
+
if (this.callback) {
|
|
143
|
+
this.callback({
|
|
144
|
+
queryStr: this.queryStr,
|
|
155
145
|
results: this.queryResult
|
|
156
|
-
};
|
|
146
|
+
}, this.table);
|
|
147
|
+
}
|
|
148
|
+
if (this.autoJump) {
|
|
149
|
+
return this.next();
|
|
157
150
|
}
|
|
151
|
+
return {
|
|
152
|
+
index: 0,
|
|
153
|
+
results: this.queryResult
|
|
154
|
+
};
|
|
158
155
|
}
|
|
159
156
|
updateCellStyle(highlight = true) {
|
|
157
|
+
if (highlight == null) {
|
|
158
|
+
if (this.queryResult?.length) {
|
|
159
|
+
this.queryResult.forEach(({ range }) => {
|
|
160
|
+
if (range) {
|
|
161
|
+
this.table.arrangeCustomCellStyle({ range }, '');
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
160
167
|
if (!this.queryResult) {
|
|
161
168
|
return;
|
|
162
169
|
}
|
|
@@ -172,7 +179,7 @@
|
|
|
172
179
|
while (this.table.isHeader(0, i)) {
|
|
173
180
|
i++;
|
|
174
181
|
}
|
|
175
|
-
|
|
182
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
176
183
|
range.start.row = row;
|
|
177
184
|
range.end.row = row;
|
|
178
185
|
this.table.arrangeCustomCellStyle({
|
|
@@ -211,7 +218,7 @@
|
|
|
211
218
|
while (this.table.isHeader(0, i)) {
|
|
212
219
|
i++;
|
|
213
220
|
}
|
|
214
|
-
|
|
221
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
215
222
|
range.start.row = row;
|
|
216
223
|
range.end.row = row;
|
|
217
224
|
this.table.arrangeCustomCellStyle({
|
|
@@ -230,7 +237,7 @@
|
|
|
230
237
|
while (this.table.isHeader(0, i)) {
|
|
231
238
|
i++;
|
|
232
239
|
}
|
|
233
|
-
|
|
240
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
234
241
|
range.start.row = row;
|
|
235
242
|
range.end.row = row;
|
|
236
243
|
this.table.arrangeCustomCellStyle({
|
|
@@ -291,7 +298,7 @@
|
|
|
291
298
|
while (this.table.isHeader(0, i)) {
|
|
292
299
|
i++;
|
|
293
300
|
}
|
|
294
|
-
|
|
301
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
295
302
|
range.start.row = row;
|
|
296
303
|
range.end.row = row;
|
|
297
304
|
this.table.arrangeCustomCellStyle({ range }, '__search_component_highlight');
|
|
@@ -308,7 +315,7 @@
|
|
|
308
315
|
while (this.table.isHeader(0, i)) {
|
|
309
316
|
i++;
|
|
310
317
|
}
|
|
311
|
-
|
|
318
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
312
319
|
range.start.row = row;
|
|
313
320
|
range.end.row = row;
|
|
314
321
|
this.table.arrangeCustomCellStyle({ range }, '__search_component_focuse');
|
|
@@ -345,17 +352,17 @@
|
|
|
345
352
|
jumpToCell(params) {
|
|
346
353
|
if (this.isTree) {
|
|
347
354
|
const { IndexNumber } = params;
|
|
348
|
-
|
|
349
|
-
|
|
355
|
+
const indexNumbers = [...IndexNumber];
|
|
356
|
+
const tmp = [...indexNumbers];
|
|
350
357
|
let tmpNumber = 0;
|
|
351
358
|
let i = 0;
|
|
352
359
|
while (tmpNumber < tmp.length - 1) {
|
|
353
360
|
tmpNumber++;
|
|
354
|
-
|
|
361
|
+
const indexNumber = indexNumbers.slice(0, tmpNumber);
|
|
355
362
|
while (this.table.isHeader(0, i)) {
|
|
356
363
|
i++;
|
|
357
364
|
}
|
|
358
|
-
|
|
365
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
359
366
|
const hierarchyState = this.table.getHierarchyState(this.treeIndex, row);
|
|
360
367
|
if (hierarchyState !== 'expand') {
|
|
361
368
|
this.table.toggleHierarchyState(this.treeIndex, row);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).VTable=e.VTable||{},e.VTable.export={}))}(this,(function(e){"use strict";var t=e=>null!=e;const r={bgColor:"rgba(255, 255, 0, 0.2)"},s={bgColor:"rgba(255, 155, 0, 0.2)"};function l(e,r){return t(e)&&t(r)&&r.toString().includes(e)}function i(e,r,s){if(!t(e))return!1;return(Array.isArray(s)&&s.length>0?s:Object.keys(r)).some((s=>t(r?.[s])&&r[s].toString().includes(e)))}e.SearchComponent=class{table;skipHeader;autoJump;highlightCellStyle;focuseHighlightCellStyle;queryMethod;treeQueryMethod;fieldsToSearch;callback;queryStr;queryResult;currentIndex;isTree;treeIndex;scrollOption;constructor(e){this.table=e.table,this.autoJump=e.autoJump||!1,this.skipHeader=e.skipHeader||!1,this.highlightCellStyle=e.highlightCellStyle||r,this.focuseHighlightCellStyle=e.focuseHighlightCellStyle||s,this.queryMethod=e.queryMethod||l,this.treeQueryMethod=e.treeQueryMethod||i,this.fieldsToSearch=e.fieldsToSearch||[],this.isTree=!1,this.treeIndex=0,this.callback=e.callback,this.scrollOption=e.scrollOption||{duration:900,easing:"quartIn"},this.table.registerCustomCellStyle("__search_component_highlight",this.highlightCellStyle),this.table.registerCustomCellStyle("__search_component_focuse",this.focuseHighlightCellStyle)}search(e){if(this.clear(),this.queryStr=e,!e)return{index:0,results:this.queryResult};if(this.isTree=this.table.options.columns.some((e=>e.tree)),this.treeIndex=this.isTree?this.table.options.columns.findIndex((e=>e.tree)):0,this.isTree){const e=this.table.colCount,t=(r,s)=>{r.forEach(((r,l)=>{const i=[...s,l];this.treeQueryMethod(this.queryStr,r,this.fieldsToSearch,{table:this.table})&&this.queryResult.push({indexNumber:i,range:{start:{row:null,col:0},end:{row:null,col:e}}}),r.children&&Array.isArray(r.children)&&r.children.length>0&&t(r.children,i)}))};return t(this.table.records,[]),this.jumpToCell({IndexNumber:this.queryResult[0].indexNumber}),this.callback&&this.callback({queryStr:this.queryStr,results:this.queryResult},this.table),this.updateCellStyle(),this.currentIndex=0,{index:0,results:this.queryResult}}for(let e=0;e<this.table.rowCount;e++)for(let t=0;t<this.table.colCount;t++){if(this.skipHeader&&this.table.isHeader(t,e))continue;const r=this.table.getCellValue(t,e);if(this.queryMethod(this.queryStr,r,{col:t,row:e,table:this.table})){const s=this.table.getCellRange(t,e);if(s.start.col!==s.end.col||s.start.row!==s.end.row){let e=!1;for(let t=this.queryResult.length-1;t>=0;t--)if(this.queryResult[t].col===s.start.col&&this.queryResult[t].row===s.start.row){e=!0;break}e||this.queryResult.push({col:s.start.col,row:s.start.row,range:s,value:r})}else this.queryResult.push({col:t,row:e,value:r})}}return this.updateCellStyle(),this.callback&&this.callback({queryStr:this.queryStr,results:this.queryResult},this.table),this.autoJump?this.next():{index:0,results:this.queryResult}}updateCellStyle(e=!0){if(this.queryResult)if(this.table.hasCustomCellStyle("__search_component_highlight")||this.table.registerCustomCellStyle("__search_component_highlight",this.highlightCellStyle),this.table.hasCustomCellStyle("__search_component_focuse")||this.table.registerCustomCellStyle("__search_component_focuse",this.focuseHighlightCellStyle),this.isTree){const{range:t,indexNumber:r}=this.queryResult[0];let s=0;for(;this.table.isHeader(0,s);)s++;
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).VTable=e.VTable||{},e.VTable.export={}))}(this,(function(e){"use strict";var t=e=>null!=e;const r={bgColor:"rgba(255, 255, 0, 0.2)"},s={bgColor:"rgba(255, 155, 0, 0.2)"};function l(e,r){return t(e)&&t(r)&&r.toString().includes(e)}function i(e,r,s){if(!t(e))return!1;return(Array.isArray(s)&&s.length>0?s:Object.keys(r)).some((s=>t(r?.[s])&&r[s].toString().includes(e)))}e.SearchComponent=class{table;skipHeader;autoJump;highlightCellStyle;focuseHighlightCellStyle;queryMethod;treeQueryMethod;fieldsToSearch;callback;queryStr;queryResult;currentIndex;isTree;treeIndex;scrollOption;constructor(e){this.table=e.table,this.autoJump=e.autoJump||!1,this.skipHeader=e.skipHeader||!1,this.highlightCellStyle=e.highlightCellStyle||r,this.focuseHighlightCellStyle=e.focuseHighlightCellStyle||s,this.queryMethod=e.queryMethod||l,this.treeQueryMethod=e.treeQueryMethod||i,this.fieldsToSearch=e.fieldsToSearch||[],this.isTree=!1,this.treeIndex=0,this.callback=e.callback,this.scrollOption=e.scrollOption||{duration:900,easing:"quartIn"},this.table.registerCustomCellStyle("__search_component_highlight",this.highlightCellStyle),this.table.registerCustomCellStyle("__search_component_focuse",this.focuseHighlightCellStyle)}search(e){if(this.clear(),this.queryStr=e,!e)return{index:0,results:this.queryResult};if(this.isTree=this.table.options.columns.some((e=>e.tree)),this.treeIndex=this.isTree?this.table.options.columns.findIndex((e=>e.tree)):0,this.isTree){const e=this.table.colCount,t=(r,s)=>{r.forEach(((r,l)=>{const i=[...s,l];this.treeQueryMethod(this.queryStr,r,this.fieldsToSearch,{table:this.table})&&this.queryResult.push({indexNumber:i,range:{start:{row:null,col:0},end:{row:null,col:e}}}),r.children&&Array.isArray(r.children)&&r.children.length>0&&t(r.children,i)}))};return t(this.table.records,[]),this.queryResult.length>0&&this.jumpToCell({IndexNumber:this.queryResult[0].indexNumber}),this.callback&&this.callback({queryStr:this.queryStr,results:this.queryResult},this.table),this.updateCellStyle(!0),this.currentIndex=0,{index:0,results:this.queryResult}}for(let e=0;e<this.table.rowCount;e++)for(let t=0;t<this.table.colCount;t++){if(this.skipHeader&&this.table.isHeader(t,e))continue;const r=this.table.getCellValue(t,e);if(this.queryMethod(this.queryStr,r,{col:t,row:e,table:this.table})){const s=this.table.getCellRange(t,e);if(s.start.col!==s.end.col||s.start.row!==s.end.row){let e=!1;for(let t=this.queryResult.length-1;t>=0;t--)if(this.queryResult[t].col===s.start.col&&this.queryResult[t].row===s.start.row){e=!0;break}e||this.queryResult.push({col:s.start.col,row:s.start.row,range:s,value:r})}else this.queryResult.push({col:t,row:e,value:r})}}return this.updateCellStyle(!0),this.callback&&this.callback({queryStr:this.queryStr,results:this.queryResult},this.table),this.autoJump?this.next():{index:0,results:this.queryResult}}updateCellStyle(e=!0){if(null!=e){if(this.queryResult)if(this.table.hasCustomCellStyle("__search_component_highlight")||this.table.registerCustomCellStyle("__search_component_highlight",this.highlightCellStyle),this.table.hasCustomCellStyle("__search_component_focuse")||this.table.registerCustomCellStyle("__search_component_focuse",this.focuseHighlightCellStyle),this.isTree){const{range:t,indexNumber:r}=this.queryResult[0];let s=0;for(;this.table.isHeader(0,s);)s++;const l=this.getBodyRowIndexByRecordIndex(r)+s;t.start.row=l,t.end.row=l,this.table.arrangeCustomCellStyle({range:t},e?"__search_component_focuse":null)}else for(let t=0;t<this.queryResult.length;t++){const{col:r,row:s,range:l}=this.queryResult[t];l?this.table.arrangeCustomCellStyle({range:l},e?"__search_component_highlight":null):this.table.arrangeCustomCellStyle({col:r,row:s},e?"__search_component_highlight":null)}}else this.queryResult?.length&&this.queryResult.forEach((({range:e})=>{e&&this.table.arrangeCustomCellStyle({range:e},"")}))}next(){if(!this.queryResult.length)return{index:0,results:this.queryResult};if(this.isTree){if(-1!==this.currentIndex){const{range:e,indexNumber:t}=this.queryResult[this.currentIndex];if(e){let r=0;for(;this.table.isHeader(0,r);)r++;const s=this.getBodyRowIndexByRecordIndex(t)+r;e.start.row=s,e.end.row=s,this.table.arrangeCustomCellStyle({range:e},"__search_component_highlight")}}this.currentIndex++,this.currentIndex>=this.queryResult.length&&(this.currentIndex=0);const{range:e,indexNumber:t}=this.queryResult[this.currentIndex];if(this.jumpToCell({IndexNumber:t}),e){let r=0;for(;this.table.isHeader(0,r);)r++;const s=this.getBodyRowIndexByRecordIndex(t)+r;e.start.row=s,e.end.row=s,this.table.arrangeCustomCellStyle({range:e},"__search_component_focuse")}}else{if(-1!==this.currentIndex){const{col:e,row:t,range:r}=this.queryResult[this.currentIndex];r?this.table.arrangeCustomCellStyle({range:r},"__search_component_highlight"):this.table.arrangeCustomCellStyle({col:e,row:t},"__search_component_highlight")}this.currentIndex++,this.currentIndex>=this.queryResult.length&&(this.currentIndex=0);const{col:e,row:t,range:r}=this.queryResult[this.currentIndex];r?this.table.arrangeCustomCellStyle({range:r},"__search_component_focuse"):this.table.arrangeCustomCellStyle({col:e,row:t},"__search_component_focuse"),this.jumpToCell({col:e,row:t})}return{index:this.currentIndex,results:this.queryResult}}prev(){if(!this.queryResult.length)return{index:0,results:this.queryResult};if(this.isTree){if(-1!==this.currentIndex){const{range:e,indexNumber:t}=this.queryResult[this.currentIndex];if(e){let r=0;for(;this.table.isHeader(0,r);)r++;const s=this.getBodyRowIndexByRecordIndex(t)+r;e.start.row=s,e.end.row=s,this.table.arrangeCustomCellStyle({range:e},"__search_component_highlight")}}this.currentIndex--,this.currentIndex<0&&(this.currentIndex=this.queryResult.length-1);const{range:e,indexNumber:t}=this.queryResult[this.currentIndex];if(this.jumpToCell({IndexNumber:t}),e){let r=0;for(;this.table.isHeader(0,r);)r++;const s=this.getBodyRowIndexByRecordIndex(t)+r;e.start.row=s,e.end.row=s,this.table.arrangeCustomCellStyle({range:e},"__search_component_focuse")}}else{if(-1!==this.currentIndex){const{col:e,row:t,range:r}=this.queryResult[this.currentIndex];r?this.table.arrangeCustomCellStyle({range:r},"__search_component_highlight"):this.table.arrangeCustomCellStyle({col:e,row:t},"__search_component_highlight")}this.currentIndex--,this.currentIndex<0&&(this.currentIndex=this.queryResult.length-1);const{col:e,row:t,range:r}=this.queryResult[this.currentIndex];r?this.table.arrangeCustomCellStyle({range:r},"__search_component_focuse"):this.table.arrangeCustomCellStyle({col:e,row:t},"__search_component_focuse"),this.jumpToCell({col:e,row:t})}return{index:this.currentIndex,results:this.queryResult}}jumpToCell(e){if(this.isTree){const{IndexNumber:t}=e,r=[...t],s=[...r];let l=0,i=0;for(;l<s.length-1;){l++;const e=r.slice(0,l);for(;this.table.isHeader(0,i);)i++;const t=this.getBodyRowIndexByRecordIndex(e)+i;"expand"!==this.table.getHierarchyState(this.treeIndex,t)&&this.table.toggleHierarchyState(this.treeIndex,t)}this.table.scrollToRow(this.getBodyRowIndexByRecordIndex(r)+i,this.scrollOption)}else{const{col:t,row:r}=e,{rowStart:s,rowEnd:l}=this.table.getBodyVisibleRowRange(),{colStart:i,colEnd:n}=this.table.getBodyVisibleColRange();(r<=s||r>=l||t<=i||t>=n)&&this.table.scrollToCell({col:t,row:r})}}getBodyRowIndexByRecordIndex(e){return Array.isArray(e)&&1===e.length&&(e=e[0]),this.table.dataSource.getTableIndex(e)}clear(){this.updateCellStyle(null),this.queryStr="",this.queryResult=[],this.currentIndex=-1}}}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as VTable from '@visactor/vtable';
|
|
2
|
-
import { ITableAnimationOption } from '@visactor/vtable/src/ts-types';
|
|
2
|
+
import type { ITableAnimationOption } from '@visactor/vtable/src/ts-types';
|
|
3
3
|
type IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;
|
|
4
4
|
export type QueryResult = {
|
|
5
5
|
queryStr: string;
|
|
@@ -25,7 +25,7 @@ export type SearchComponentOption = {
|
|
|
25
25
|
table: IVTable;
|
|
26
26
|
}) => boolean;
|
|
27
27
|
fieldsToSearch?: string[];
|
|
28
|
-
scrollOption
|
|
28
|
+
scrollOption?: ITableAnimationOption;
|
|
29
29
|
callback?: (queryResult: QueryResult, table: IVTable) => void;
|
|
30
30
|
};
|
|
31
31
|
export declare class SearchComponent {
|
|
@@ -55,12 +55,12 @@ export class SearchComponent {
|
|
|
55
55
|
}), item.children && Array.isArray(item.children) && item.children.length > 0 && walk(item.children, currentPath);
|
|
56
56
|
}));
|
|
57
57
|
};
|
|
58
|
-
return walk(this.table.records, []), this.jumpToCell({
|
|
58
|
+
return walk(this.table.records, []), this.queryResult.length > 0 && this.jumpToCell({
|
|
59
59
|
IndexNumber: this.queryResult[0].indexNumber
|
|
60
60
|
}), this.callback && this.callback({
|
|
61
61
|
queryStr: this.queryStr,
|
|
62
62
|
results: this.queryResult
|
|
63
|
-
}, this.table), this.updateCellStyle(), this.currentIndex = 0, {
|
|
63
|
+
}, this.table), this.updateCellStyle(!0), this.currentIndex = 0, {
|
|
64
64
|
index: 0,
|
|
65
65
|
results: this.queryResult
|
|
66
66
|
};
|
|
@@ -93,7 +93,7 @@ export class SearchComponent {
|
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
return this.updateCellStyle(), this.callback && this.callback({
|
|
96
|
+
return this.updateCellStyle(!0), this.callback && this.callback({
|
|
97
97
|
queryStr: this.queryStr,
|
|
98
98
|
results: this.queryResult
|
|
99
99
|
}, this.table), this.autoJump ? this.next() : {
|
|
@@ -102,25 +102,32 @@ export class SearchComponent {
|
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
updateCellStyle(highlight = !0) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
105
|
+
var _a;
|
|
106
|
+
if (null != highlight) {
|
|
107
|
+
if (this.queryResult) if (this.table.hasCustomCellStyle("__search_component_highlight") || this.table.registerCustomCellStyle("__search_component_highlight", this.highlightCellStyle),
|
|
108
|
+
this.table.hasCustomCellStyle("__search_component_focuse") || this.table.registerCustomCellStyle("__search_component_focuse", this.focuseHighlightCellStyle),
|
|
109
|
+
this.isTree) {
|
|
110
|
+
const {range: range, indexNumber: indexNumber} = this.queryResult[0];
|
|
111
|
+
let i = 0;
|
|
112
|
+
for (;this.table.isHeader(0, i); ) i++;
|
|
113
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
114
|
+
range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
|
|
115
|
+
range: range
|
|
116
|
+
}, highlight ? "__search_component_focuse" : null);
|
|
117
|
+
} else for (let i = 0; i < this.queryResult.length; i++) {
|
|
118
|
+
const {col: col, row: row, range: range} = this.queryResult[i];
|
|
119
|
+
range ? this.table.arrangeCustomCellStyle({
|
|
120
|
+
range: range
|
|
121
|
+
}, highlight ? "__search_component_highlight" : null) : this.table.arrangeCustomCellStyle({
|
|
122
|
+
col: col,
|
|
123
|
+
row: row
|
|
124
|
+
}, highlight ? "__search_component_highlight" : null);
|
|
125
|
+
}
|
|
126
|
+
} else (null === (_a = this.queryResult) || void 0 === _a ? void 0 : _a.length) && this.queryResult.forEach((({range: range}) => {
|
|
127
|
+
range && this.table.arrangeCustomCellStyle({
|
|
118
128
|
range: range
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
row: row
|
|
122
|
-
}, highlight ? "__search_component_highlight" : null);
|
|
123
|
-
}
|
|
129
|
+
}, "");
|
|
130
|
+
}));
|
|
124
131
|
}
|
|
125
132
|
next() {
|
|
126
133
|
if (!this.queryResult.length) return {
|
|
@@ -133,7 +140,7 @@ export class SearchComponent {
|
|
|
133
140
|
if (range) {
|
|
134
141
|
let i = 0;
|
|
135
142
|
for (;this.table.isHeader(0, i); ) i++;
|
|
136
|
-
|
|
143
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
137
144
|
range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
|
|
138
145
|
range: range
|
|
139
146
|
}, "__search_component_highlight");
|
|
@@ -146,7 +153,7 @@ export class SearchComponent {
|
|
|
146
153
|
}), range) {
|
|
147
154
|
let i = 0;
|
|
148
155
|
for (;this.table.isHeader(0, i); ) i++;
|
|
149
|
-
|
|
156
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
150
157
|
range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
|
|
151
158
|
range: range
|
|
152
159
|
}, "__search_component_focuse");
|
|
@@ -189,7 +196,7 @@ export class SearchComponent {
|
|
|
189
196
|
if (range) {
|
|
190
197
|
let i = 0;
|
|
191
198
|
for (;this.table.isHeader(0, i); ) i++;
|
|
192
|
-
|
|
199
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
193
200
|
range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
|
|
194
201
|
range: range
|
|
195
202
|
}, "__search_component_highlight");
|
|
@@ -202,7 +209,7 @@ export class SearchComponent {
|
|
|
202
209
|
}), range) {
|
|
203
210
|
let i = 0;
|
|
204
211
|
for (;this.table.isHeader(0, i); ) i++;
|
|
205
|
-
|
|
212
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
206
213
|
range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
|
|
207
214
|
range: range
|
|
208
215
|
}, "__search_component_focuse");
|
|
@@ -236,13 +243,13 @@ export class SearchComponent {
|
|
|
236
243
|
}
|
|
237
244
|
jumpToCell(params) {
|
|
238
245
|
if (this.isTree) {
|
|
239
|
-
const {IndexNumber: IndexNumber} = params;
|
|
240
|
-
let
|
|
246
|
+
const {IndexNumber: IndexNumber} = params, indexNumbers = [ ...IndexNumber ], tmp = [ ...indexNumbers ];
|
|
247
|
+
let tmpNumber = 0, i = 0;
|
|
241
248
|
for (;tmpNumber < tmp.length - 1; ) {
|
|
242
249
|
tmpNumber++;
|
|
243
|
-
|
|
250
|
+
const indexNumber = indexNumbers.slice(0, tmpNumber);
|
|
244
251
|
for (;this.table.isHeader(0, i); ) i++;
|
|
245
|
-
|
|
252
|
+
const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
|
|
246
253
|
"expand" !== this.table.getHierarchyState(this.treeIndex, row) && this.table.toggleHierarchyState(this.treeIndex, row);
|
|
247
254
|
}
|
|
248
255
|
this.table.scrollToRow(this.getBodyRowIndexByRecordIndex(indexNumbers) + i, this.scrollOption);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["search-component/search-component.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AA6B3C,MAAM,0BAA0B,GAAoC;IAClE,OAAO,EAAE,wBAAwB;CAClC,CAAC;AAEF,MAAM,+BAA+B,GAAoC;IACvE,OAAO,EAAE,wBAAwB;CAClC,CAAC;AAEF,SAAS,mBAAmB,CAAC,QAAgB,EAAE,KAAa;IAC1D,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACpF,CAAC;AACD,SAAS,uBAAuB,CAAC,QAAgB,EAAE,IAAS,EAAE,cAAyB;IACrF,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;QAAE,OAAO,KAAK,CAAC;IAGrC,MAAM,YAAY,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,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AC,WAAW,CAAC,IAAI,CAAC,4BAA4B,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;SAG/F;aAAM;YACL,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;YAE5B,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,sBAAsB,EAAE,CAAC;YACjE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,sBAAsB,EAAE,CAAC;YACjE,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,IAAI,MAAM,EAAE;gBACxE,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;aACvC;SACF;IAGH,CAAC;IACD,4BAA4B,CAAC,KAAwB;QACnD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YAC9C,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;SAClB;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;IACD,KAAK;QAEH,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;IACzB,CAAC;CACF","file":"search-component.js","sourcesContent":["import type * as VTable from '@visactor/vtable';\nimport { ITableAnimationOption } from '@visactor/vtable/src/ts-types';\nimport { EasingType } from '@visactor/vtable/src/vrender';\nimport { isValid } from '@visactor/vutils';\ntype IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;\n\nexport type QueryResult = {\n queryStr: string;\n results: {\n col?: number;\n row?: number;\n value?: string;\n indexNumber?: number[];\n\n }[];\n};\n\nexport type SearchComponentOption = {\n table: IVTable;\n autoJump?: boolean;\n skipHeader?: boolean;\n highlightCellStyle?: VTable.TYPES.CellStyle;\n focuseHighlightCellStyle?: VTable.TYPES.CellStyle;\n queryMethod?: (queryStr: string, value: string, option?: { col: number; row: number; table: IVTable }) => boolean;\n treeQueryMethod?: (queryStr: string, node: any, fieldsToSearch?: string[], option?: { table: IVTable }) => boolean;\n fieldsToSearch?: string[];\n scrollOption: ITableAnimationOption;\n\n\n callback?: (queryResult: QueryResult, table: IVTable) => void;\n};\n\nconst defalutHightlightCellStyle: Partial<VTable.TYPES.CellStyle> = {\n bgColor: 'rgba(255, 255, 0, 0.2)'\n};\n\nconst defalutFocusHightlightCellStyle: Partial<VTable.TYPES.CellStyle> = {\n bgColor: 'rgba(255, 155, 0, 0.2)'\n};\n\nfunction defalultQueryMethod(queryStr: string, value: string) {\n return isValid(queryStr) && isValid(value) && value.toString().includes(queryStr);\n}\nfunction defalultTreeQueryMethod(queryStr: string, node: any, fieldsToSearch?: string[]) {\n if (!isValid(queryStr)) return false;\n\n // 如果没有传 fieldsToSearch,则用 node 的全部 key\n const searchFields = (Array.isArray(fieldsToSearch) && fieldsToSearch.length > 0)\n ? fieldsToSearch\n : Object.keys(node);\n\n return searchFields.some(field =>\n isValid(node?.[field]) &&\n node[field].toString().includes(queryStr)\n );\n}\nexport class SearchComponent {\n table: IVTable;\n skipHeader: boolean;\n autoJump: boolean;\n highlightCellStyle: Partial<VTable.TYPES.CellStyle>;\n focuseHighlightCellStyle: Partial<VTable.TYPES.CellStyle>;\n queryMethod: (queryStr: string, value: string, option: { col: number; row: number; table: IVTable }) => boolean;\n treeQueryMethod: (queryStr: string, node: any, fieldsToSearch?: string[], option?: { table: IVTable }) => boolean;\n fieldsToSearch: string[];\n\n\n callback?: (queryResult: QueryResult, table: IVTable) => void;\n\n queryStr: string;\n queryResult: {\n col?: number;\n row?: number;\n range?: VTable.TYPES.CellRange;\n value?: string;\n indexNumber?: number[];\n }[];\n\n currentIndex: number;\n isTree: boolean;\n treeIndex: number;\n scrollOption: ITableAnimationOption;\n\n constructor(option: SearchComponentOption) {\n this.table = option.table;\n this.autoJump = option.autoJump || false;\n this.skipHeader = option.skipHeader || false;\n this.highlightCellStyle = option.highlightCellStyle || defalutHightlightCellStyle;\n this.focuseHighlightCellStyle = option.focuseHighlightCellStyle || defalutFocusHightlightCellStyle;\n this.queryMethod = option.queryMethod || defalultQueryMethod;\n this.treeQueryMethod = option.treeQueryMethod || defalultTreeQueryMethod;\n this.fieldsToSearch = option.fieldsToSearch || [];\n this.isTree = false\n this.treeIndex = 0\n this.callback = option.callback;\n this.scrollOption = option.scrollOption || { duration: 900, easing: 'quartIn' as EasingType } as ITableAnimationOption\n this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle as any);\n this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle as any);\n }\n\n search(str: string) {\n this.clear();\n this.queryStr = str;\n\n if (!str) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n this.isTree = this.table.options.columns.some((item: any) => item.tree)\n this.treeIndex = this.isTree\n ? this.table.options.columns.findIndex((item: any) => item.tree)\n : 0;\n if (this.isTree) {\n // 如果传入单一节点也能处理\n const colEnd = this.table.colCount;\n const walk = (nodes: any[], path: number[]) => {\n nodes.forEach((item: any, idx: number) => {\n const currentPath = [...path, idx]; // 当前节点的完整路径\n\n // 保持你的 treeQueryMethod 调用方式(this 上下文来自定义环境)\n if (this.treeQueryMethod(this.queryStr, item, this.fieldsToSearch, { table: this.table })) {\n this.queryResult.push({\n indexNumber: currentPath,\n range: {\n start: { row: null, col: 0 },\n end: { row: null, col: colEnd }\n }\n\n });\n }\n\n if (item.children && Array.isArray(item.children) && item.children.length > 0) {\n walk(item.children, currentPath);\n }\n });\n };\n\n walk(this.table.records, []);\n\n this.jumpToCell({ IndexNumber: this.queryResult[0].indexNumber });\n\n\n if (this.callback) {\n this.callback(\n {\n queryStr: this.queryStr,\n results: this.queryResult\n },\n this.table\n );\n }\n this.updateCellStyle();\n\n // if (this.autoJump) {\n // return this.next();\n // }\n this.currentIndex = 0;\n\n return {\n index: 0,\n results: this.queryResult\n };\n } else {\n for (let row = 0; row < this.table.rowCount; row++) {\n for (let col = 0; col < this.table.colCount; col++) {\n if (this.skipHeader && this.table.isHeader(col, row)) {\n continue;\n }\n const value = this.table.getCellValue(col, row);\n if (this.queryMethod(this.queryStr, value, { col, row, table: this.table })) {\n // deal merge cell\n const mergeCell = this.table.getCellRange(col, row);\n if (mergeCell.start.col !== mergeCell.end.col || mergeCell.start.row !== mergeCell.end.row) {\n // find is cell already in queryResult\n let isIn = false;\n for (let i = this.queryResult.length - 1; i >= 0; i--) {\n if (this.queryResult[i].col === mergeCell.start.col && this.queryResult[i].row === mergeCell.start.row) {\n isIn = true;\n break;\n }\n }\n if (!isIn) {\n this.queryResult.push({\n col: mergeCell.start.col,\n row: mergeCell.start.row,\n range: mergeCell,\n value\n });\n }\n } else {\n this.queryResult.push({\n col,\n row,\n value\n });\n }\n }\n }\n }\n this.updateCellStyle();\n\n if (this.callback) {\n this.callback(\n {\n queryStr: this.queryStr,\n results: this.queryResult\n },\n this.table\n );\n }\n\n if (this.autoJump) {\n return this.next();\n }\n return {\n index: 0,\n results: this.queryResult\n };\n }\n\n\n\n\n\n\n }\n\n updateCellStyle(highlight: boolean = true) {\n if (!this.queryResult) {\n return;\n }\n\n if (!this.table.hasCustomCellStyle('__search_component_highlight')) {\n this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle as any);\n }\n if (!this.table.hasCustomCellStyle('__search_component_focuse')) {\n this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle as any);\n }\n if (this.isTree) {\n const { range, indexNumber } = this.queryResult[0];\n\n let i = 0;\n\n // 如果是表头就往下偏移\n while (this.table.isHeader(0, i)) {\n i++;\n }\n let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row\n range.end.row = row\n\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n highlight ? '__search_component_focuse' : null\n );\n\n } else {\n for (let i = 0; i < this.queryResult.length; i++) {\n\n const { col, row, range } = this.queryResult[i];\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n highlight ? '__search_component_highlight' : null\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n highlight ? '__search_component_highlight' : null\n );\n }\n }\n }\n\n }\n\n next() {\n if (!this.queryResult.length) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n if (this.isTree) {\n\n if (this.currentIndex !== -1) {\n const { range, indexNumber } = this.queryResult[this.currentIndex];\n\n\n if (range) {\n let i = 0;\n\n // 如果是表头就往下偏移\n while (this.table.isHeader(0, i)) {\n i++;\n }\n let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row\n range.end.row = row\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_highlight'\n );\n }\n }\n\n this.currentIndex++;\n if (this.currentIndex >= this.queryResult.length) {\n this.currentIndex = 0;\n }\n const { range, indexNumber } = this.queryResult[this.currentIndex];\n this.jumpToCell({ IndexNumber: indexNumber });\n\n if (range) {\n let i = 0;\n\n // 如果是表头就往下偏移\n while (this.table.isHeader(0, i)) {\n i++;\n }\n let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row\n range.end.row = row\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_focuse'\n );\n }\n\n } else {\n\n if (this.currentIndex !== -1) {\n const { col, row, range } = this.queryResult[this.currentIndex];\n\n // reset last focus\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_highlight'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n '__search_component_highlight'\n );\n }\n }\n this.currentIndex++;\n if (this.currentIndex >= this.queryResult.length) {\n this.currentIndex = 0;\n }\n const { col, row, range } = this.queryResult[this.currentIndex];\n\n // this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_focuse'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n '__search_component_focuse'\n );\n }\n\n this.jumpToCell({ col, row });\n }\n\n\n\n return {\n index: this.currentIndex,\n results: this.queryResult\n };\n }\n\n prev() {\n if (!this.queryResult.length) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n\n if (this.isTree) {\n // 先取消当前高亮\n if (this.currentIndex !== -1) {\n const { range, indexNumber } = this.queryResult[this.currentIndex];\n if (range) {\n let i = 0;\n while (this.table.isHeader(0, i)) {\n i++;\n }\n let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row;\n range.end.row = row;\n this.table.arrangeCustomCellStyle(\n { range },\n '__search_component_highlight'\n );\n }\n }\n\n // 索引向前\n this.currentIndex--;\n if (this.currentIndex < 0) {\n this.currentIndex = this.queryResult.length - 1;\n }\n\n // 焦点样式\n const { range, indexNumber } = this.queryResult[this.currentIndex];\n this.jumpToCell({ IndexNumber: indexNumber });\n\n if (range) {\n let i = 0;\n while (this.table.isHeader(0, i)) {\n i++;\n }\n let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row;\n range.end.row = row;\n this.table.arrangeCustomCellStyle(\n { range },\n '__search_component_focuse'\n );\n }\n\n } else {\n // 普通表格处理\n if (this.currentIndex !== -1) {\n const { col, row, range } = this.queryResult[this.currentIndex];\n if (range) {\n this.table.arrangeCustomCellStyle(\n { range },\n '__search_component_highlight'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n { col, row },\n '__search_component_highlight'\n );\n }\n }\n\n this.currentIndex--;\n if (this.currentIndex < 0) {\n this.currentIndex = this.queryResult.length - 1;\n }\n\n const { col, row, range } = this.queryResult[this.currentIndex];\n if (range) {\n this.table.arrangeCustomCellStyle(\n { range },\n '__search_component_focuse'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n { col, row },\n '__search_component_focuse'\n );\n }\n\n this.jumpToCell({ col, row });\n }\n\n return {\n index: this.currentIndex,\n results: this.queryResult\n };\n }\n\n\n jumpToCell(params: { col?: number; row?: number, IndexNumber?: number[] }) {\n\n if (this.isTree) {\n const { IndexNumber } = params\n let indexNumbers = [...IndexNumber]\n\n let tmp = [...indexNumbers]\n let tmpNumber = 0\n let i = 0;\n\n while (tmpNumber < tmp.length - 1) {\n tmpNumber++\n let indexNumber = indexNumbers.slice(0, tmpNumber)\n\n // 如果是表头就往下偏移\n while (this.table.isHeader(0, i)) {\n i++;\n }\n let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n\n const hierarchyState = this.table.getHierarchyState(\n this.treeIndex,\n row\n );\n\n if (hierarchyState !== 'expand') {\n\n this.table.toggleHierarchyState(\n this.treeIndex,\n row\n );\n }\n }\n this.table.scrollToRow(this.getBodyRowIndexByRecordIndex(indexNumbers) + i, this.scrollOption)\n\n\n } else {\n const { col, row } = params;\n // if focus cell out of screen, jump to cell\n const { rowStart, rowEnd } = this.table.getBodyVisibleRowRange();\n const { colStart, colEnd } = this.table.getBodyVisibleColRange();\n if (row <= rowStart || row >= rowEnd || col <= colStart || col >= colEnd) {\n this.table.scrollToCell({ col, row });\n }\n }\n\n\n }\n getBodyRowIndexByRecordIndex(index: number | number[]): number {\n if (Array.isArray(index) && index.length === 1) {\n index = index[0];\n }\n return this.table.dataSource.getTableIndex(index);\n }\n clear() {\n // reset highlight cell style\n this.updateCellStyle(null);\n this.queryStr = '';\n this.queryResult = [];\n this.currentIndex = -1;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["search-component/search-component.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AA0B3C,MAAM,0BAA0B,GAAoC;IAClE,OAAO,EAAE,wBAAwB;C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,GAAG,IAAI,QAAQ,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,IAAI,MAAM,EAAE;gBACxE,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;aACvC;SACF;IACH,CAAC;IACD,4BAA4B,CAAC,KAAwB;QACnD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YAC9C,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;SAClB;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;IACD,KAAK;QAEH,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;IACzB,CAAC;CACF","file":"search-component.js","sourcesContent":["import type * as VTable from '@visactor/vtable';\nimport type { ITableAnimationOption } from '@visactor/vtable/src/ts-types';\nimport type { EasingType } from '@visactor/vtable/src/vrender';\nimport { isValid } from '@visactor/vutils';\ntype IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;\n\nexport type QueryResult = {\n queryStr: string;\n results: {\n col?: number;\n row?: number;\n value?: string;\n indexNumber?: number[];\n }[];\n};\n\nexport type SearchComponentOption = {\n table: IVTable;\n autoJump?: boolean;\n skipHeader?: boolean;\n highlightCellStyle?: VTable.TYPES.CellStyle;\n focuseHighlightCellStyle?: VTable.TYPES.CellStyle;\n queryMethod?: (queryStr: string, value: string, option?: { col: number; row: number; table: IVTable }) => boolean;\n treeQueryMethod?: (queryStr: string, node: any, fieldsToSearch?: string[], option?: { table: IVTable }) => boolean;\n fieldsToSearch?: string[];\n scrollOption?: ITableAnimationOption;\n callback?: (queryResult: QueryResult, table: IVTable) => void;\n};\n\nconst defalutHightlightCellStyle: Partial<VTable.TYPES.CellStyle> = {\n bgColor: 'rgba(255, 255, 0, 0.2)'\n};\n\nconst defalutFocusHightlightCellStyle: Partial<VTable.TYPES.CellStyle> = {\n bgColor: 'rgba(255, 155, 0, 0.2)'\n};\n\nfunction defalultQueryMethod(queryStr: string, value: string) {\n return isValid(queryStr) && isValid(value) && value.toString().includes(queryStr);\n}\nfunction defalultTreeQueryMethod(queryStr: string, node: any, fieldsToSearch?: string[]) {\n if (!isValid(queryStr)) {\n return false;\n }\n\n // 如果没有传 fieldsToSearch,则用 node 的全部 key\n const searchFields = Array.isArray(fieldsToSearch) && fieldsToSearch.length > 0 ? fieldsToSearch : Object.keys(node);\n\n return searchFields.some(field => isValid(node?.[field]) && node[field].toString().includes(queryStr));\n}\nexport class SearchComponent {\n table: IVTable;\n skipHeader: boolean;\n autoJump: boolean;\n highlightCellStyle: Partial<VTable.TYPES.CellStyle>;\n focuseHighlightCellStyle: Partial<VTable.TYPES.CellStyle>;\n queryMethod: (queryStr: string, value: string, option: { col: number; row: number; table: IVTable }) => boolean;\n treeQueryMethod: (queryStr: string, node: any, fieldsToSearch?: string[], option?: { table: IVTable }) => boolean;\n fieldsToSearch: string[];\n\n callback?: (queryResult: QueryResult, table: IVTable) => void;\n\n queryStr: string;\n queryResult: {\n col?: number;\n row?: number;\n range?: VTable.TYPES.CellRange;\n value?: string;\n indexNumber?: number[];\n }[];\n\n currentIndex: number;\n isTree: boolean;\n treeIndex: number;\n scrollOption: ITableAnimationOption;\n\n constructor(option: SearchComponentOption) {\n this.table = option.table;\n this.autoJump = option.autoJump || false;\n this.skipHeader = option.skipHeader || false;\n this.highlightCellStyle = option.highlightCellStyle || defalutHightlightCellStyle;\n this.focuseHighlightCellStyle = option.focuseHighlightCellStyle || defalutFocusHightlightCellStyle;\n this.queryMethod = option.queryMethod || defalultQueryMethod;\n this.treeQueryMethod = option.treeQueryMethod || defalultTreeQueryMethod;\n this.fieldsToSearch = option.fieldsToSearch || [];\n this.isTree = false;\n this.treeIndex = 0;\n this.callback = option.callback;\n this.scrollOption =\n option.scrollOption || ({ duration: 900, easing: 'quartIn' as EasingType } as ITableAnimationOption);\n this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle as any);\n this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle as any);\n }\n\n search(str: string) {\n this.clear();\n this.queryStr = str;\n\n if (!str) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n this.isTree = this.table.options.columns.some((item: any) => item.tree);\n this.treeIndex = this.isTree ? this.table.options.columns.findIndex((item: any) => item.tree) : 0;\n if (this.isTree) {\n // 如果传入单一节点也能处理\n const colEnd = this.table.colCount;\n const walk = (nodes: any[], path: number[]) => {\n nodes.forEach((item: any, idx: number) => {\n const currentPath = [...path, idx]; // 当前节点的完整路径\n\n // 保持你的 treeQueryMethod 调用方式(this 上下文来自定义环境)\n if (this.treeQueryMethod(this.queryStr, item, this.fieldsToSearch, { table: this.table })) {\n this.queryResult.push({\n indexNumber: currentPath,\n range: {\n start: { row: null, col: 0 },\n end: { row: null, col: colEnd }\n }\n });\n }\n\n if (item.children && Array.isArray(item.children) && item.children.length > 0) {\n walk(item.children, currentPath);\n }\n });\n };\n\n walk(this.table.records, []);\n if (this.queryResult.length > 0) {\n this.jumpToCell({ IndexNumber: this.queryResult[0].indexNumber });\n }\n\n if (this.callback) {\n this.callback(\n {\n queryStr: this.queryStr,\n results: this.queryResult\n },\n this.table\n );\n }\n this.updateCellStyle(true);\n\n // if (this.autoJump) {\n // return this.next();\n // }\n this.currentIndex = 0;\n\n return {\n index: 0,\n results: this.queryResult\n };\n }\n for (let row = 0; row < this.table.rowCount; row++) {\n for (let col = 0; col < this.table.colCount; col++) {\n if (this.skipHeader && this.table.isHeader(col, row)) {\n continue;\n }\n const value = this.table.getCellValue(col, row);\n if (this.queryMethod(this.queryStr, value, { col, row, table: this.table })) {\n // deal merge cell\n const mergeCell = this.table.getCellRange(col, row);\n if (mergeCell.start.col !== mergeCell.end.col || mergeCell.start.row !== mergeCell.end.row) {\n // find is cell already in queryResult\n let isIn = false;\n for (let i = this.queryResult.length - 1; i >= 0; i--) {\n if (this.queryResult[i].col === mergeCell.start.col && this.queryResult[i].row === mergeCell.start.row) {\n isIn = true;\n break;\n }\n }\n if (!isIn) {\n this.queryResult.push({\n col: mergeCell.start.col,\n row: mergeCell.start.row,\n range: mergeCell,\n value\n });\n }\n } else {\n this.queryResult.push({\n col,\n row,\n value\n });\n }\n }\n }\n }\n this.updateCellStyle(true);\n\n if (this.callback) {\n this.callback(\n {\n queryStr: this.queryStr,\n results: this.queryResult\n },\n this.table\n );\n }\n\n if (this.autoJump) {\n return this.next();\n }\n return {\n index: 0,\n results: this.queryResult\n };\n }\n\n updateCellStyle(highlight: boolean = true) {\n if (highlight == null) {\n if (this.queryResult?.length) {\n this.queryResult.forEach(({ range }) => {\n if (range) {\n this.table.arrangeCustomCellStyle(\n { range },\n '' // 或者 null,看API是否允许\n );\n }\n });\n }\n return;\n }\n if (!this.queryResult) {\n return;\n }\n\n if (!this.table.hasCustomCellStyle('__search_component_highlight')) {\n this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle as any);\n }\n if (!this.table.hasCustomCellStyle('__search_component_focuse')) {\n this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle as any);\n }\n if (this.isTree) {\n const { range, indexNumber } = this.queryResult[0];\n\n let i = 0;\n\n // 如果是表头就往下偏移\n while (this.table.isHeader(0, i)) {\n i++;\n }\n const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row;\n range.end.row = row;\n\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n highlight ? '__search_component_focuse' : null\n );\n } else {\n for (let i = 0; i < this.queryResult.length; i++) {\n const { col, row, range } = this.queryResult[i];\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n highlight ? '__search_component_highlight' : null\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n highlight ? '__search_component_highlight' : null\n );\n }\n }\n }\n }\n\n next() {\n if (!this.queryResult.length) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n if (this.isTree) {\n if (this.currentIndex !== -1) {\n const { range, indexNumber } = this.queryResult[this.currentIndex];\n\n if (range) {\n let i = 0;\n\n // 如果是表头就往下偏移\n while (this.table.isHeader(0, i)) {\n i++;\n }\n const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row;\n range.end.row = row;\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_highlight'\n );\n }\n }\n\n this.currentIndex++;\n if (this.currentIndex >= this.queryResult.length) {\n this.currentIndex = 0;\n }\n const { range, indexNumber } = this.queryResult[this.currentIndex];\n this.jumpToCell({ IndexNumber: indexNumber });\n\n if (range) {\n let i = 0;\n\n // 如果是表头就往下偏移\n while (this.table.isHeader(0, i)) {\n i++;\n }\n const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row;\n range.end.row = row;\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_focuse'\n );\n }\n } else {\n if (this.currentIndex !== -1) {\n const { col, row, range } = this.queryResult[this.currentIndex];\n\n // reset last focus\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_highlight'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n '__search_component_highlight'\n );\n }\n }\n this.currentIndex++;\n if (this.currentIndex >= this.queryResult.length) {\n this.currentIndex = 0;\n }\n const { col, row, range } = this.queryResult[this.currentIndex];\n\n // this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_focuse'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n '__search_component_focuse'\n );\n }\n\n this.jumpToCell({ col, row });\n }\n\n return {\n index: this.currentIndex,\n results: this.queryResult\n };\n }\n\n prev() {\n if (!this.queryResult.length) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n\n if (this.isTree) {\n // 先取消当前高亮\n if (this.currentIndex !== -1) {\n const { range, indexNumber } = this.queryResult[this.currentIndex];\n if (range) {\n let i = 0;\n while (this.table.isHeader(0, i)) {\n i++;\n }\n const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row;\n range.end.row = row;\n this.table.arrangeCustomCellStyle({ range }, '__search_component_highlight');\n }\n }\n\n // 索引向前\n this.currentIndex--;\n if (this.currentIndex < 0) {\n this.currentIndex = this.queryResult.length - 1;\n }\n\n // 焦点样式\n const { range, indexNumber } = this.queryResult[this.currentIndex];\n this.jumpToCell({ IndexNumber: indexNumber });\n\n if (range) {\n let i = 0;\n while (this.table.isHeader(0, i)) {\n i++;\n }\n const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n range.start.row = row;\n range.end.row = row;\n this.table.arrangeCustomCellStyle({ range }, '__search_component_focuse');\n }\n } else {\n // 普通表格处理\n if (this.currentIndex !== -1) {\n const { col, row, range } = this.queryResult[this.currentIndex];\n if (range) {\n this.table.arrangeCustomCellStyle({ range }, '__search_component_highlight');\n } else {\n this.table.arrangeCustomCellStyle({ col, row }, '__search_component_highlight');\n }\n }\n\n this.currentIndex--;\n if (this.currentIndex < 0) {\n this.currentIndex = this.queryResult.length - 1;\n }\n\n const { col, row, range } = this.queryResult[this.currentIndex];\n if (range) {\n this.table.arrangeCustomCellStyle({ range }, '__search_component_focuse');\n } else {\n this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');\n }\n\n this.jumpToCell({ col, row });\n }\n\n return {\n index: this.currentIndex,\n results: this.queryResult\n };\n }\n\n jumpToCell(params: { col?: number; row?: number; IndexNumber?: number[] }) {\n if (this.isTree) {\n const { IndexNumber } = params;\n const indexNumbers = [...IndexNumber];\n\n const tmp = [...indexNumbers];\n let tmpNumber = 0;\n let i = 0;\n\n while (tmpNumber < tmp.length - 1) {\n tmpNumber++;\n const indexNumber = indexNumbers.slice(0, tmpNumber);\n\n // 如果是表头就往下偏移\n while (this.table.isHeader(0, i)) {\n i++;\n }\n const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;\n\n const hierarchyState = this.table.getHierarchyState(this.treeIndex, row);\n\n if (hierarchyState !== 'expand') {\n this.table.toggleHierarchyState(this.treeIndex, row);\n }\n }\n this.table.scrollToRow(this.getBodyRowIndexByRecordIndex(indexNumbers) + i, this.scrollOption);\n } else {\n const { col, row } = params;\n // if focus cell out of screen, jump to cell\n const { rowStart, rowEnd } = this.table.getBodyVisibleRowRange();\n const { colStart, colEnd } = this.table.getBodyVisibleColRange();\n if (row <= rowStart || row >= rowEnd || col <= colStart || col >= colEnd) {\n this.table.scrollToCell({ col, row });\n }\n }\n }\n getBodyRowIndexByRecordIndex(index: number | number[]): number {\n if (Array.isArray(index) && index.length === 1) {\n index = index[0];\n }\n return this.table.dataSource.getTableIndex(index);\n }\n clear() {\n // reset highlight cell style\n this.updateCellStyle(null);\n this.queryStr = '';\n this.queryResult = [];\n this.currentIndex = -1;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visactor/vtable-search",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.8",
|
|
4
4
|
"description": "The search util of VTable",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "VisActor",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@visactor/vutils": "~0.19.1",
|
|
34
|
-
"@visactor/vtable": "1.19.
|
|
34
|
+
"@visactor/vtable": "1.19.8"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@visactor/vchart": "2.0.2",
|
|
@@ -75,8 +75,8 @@
|
|
|
75
75
|
"axios": "^1.4.0",
|
|
76
76
|
"@types/react-is": "^17.0.3",
|
|
77
77
|
"rollup-plugin-node-resolve": "5.2.0",
|
|
78
|
-
"@internal/bundler": "0.0.1",
|
|
79
78
|
"@internal/ts-config": "0.0.1",
|
|
79
|
+
"@internal/bundler": "0.0.1",
|
|
80
80
|
"@internal/eslint-config": "0.0.1"
|
|
81
81
|
},
|
|
82
82
|
"scripts": {
|