@visactor/vtable-search 1.19.6 → 1.19.7

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.
@@ -1,11 +1,13 @@
1
1
  import type * as VTable from '@visactor/vtable';
2
+ import { ITableAnimationOption } from '@visactor/vtable/src/ts-types';
2
3
  type IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;
3
4
  export type QueryResult = {
4
5
  queryStr: string;
5
6
  results: {
6
- col: number;
7
- row: number;
8
- value: string;
7
+ col?: number;
8
+ row?: number;
9
+ value?: string;
10
+ indexNumber?: number[];
9
11
  }[];
10
12
  };
11
13
  export type SearchComponentOption = {
@@ -19,6 +21,11 @@ export type SearchComponentOption = {
19
21
  row: number;
20
22
  table: IVTable;
21
23
  }) => boolean;
24
+ treeQueryMethod?: (queryStr: string, node: any, fieldsToSearch?: string[], option?: {
25
+ table: IVTable;
26
+ }) => boolean;
27
+ fieldsToSearch?: string[];
28
+ scrollOption: ITableAnimationOption;
22
29
  callback?: (queryResult: QueryResult, table: IVTable) => void;
23
30
  };
24
31
  export declare class SearchComponent {
@@ -32,45 +39,61 @@ export declare class SearchComponent {
32
39
  row: number;
33
40
  table: IVTable;
34
41
  }) => boolean;
42
+ treeQueryMethod: (queryStr: string, node: any, fieldsToSearch?: string[], option?: {
43
+ table: IVTable;
44
+ }) => boolean;
45
+ fieldsToSearch: string[];
35
46
  callback?: (queryResult: QueryResult, table: IVTable) => void;
36
47
  queryStr: string;
37
48
  queryResult: {
38
- col: number;
39
- row: number;
49
+ col?: number;
50
+ row?: number;
40
51
  range?: VTable.TYPES.CellRange;
41
- value: string;
52
+ value?: string;
53
+ indexNumber?: number[];
42
54
  }[];
43
55
  currentIndex: number;
56
+ isTree: boolean;
57
+ treeIndex: number;
58
+ scrollOption: ITableAnimationOption;
44
59
  constructor(option: SearchComponentOption);
45
60
  search(str: string): {
46
61
  index: number;
47
62
  results: {
48
- col: number;
49
- row: number;
63
+ col?: number;
64
+ row?: number;
50
65
  range?: VTable.TYPES.CellRange;
51
- value: string;
66
+ value?: string;
67
+ indexNumber?: number[];
52
68
  }[];
53
69
  };
54
70
  updateCellStyle(highlight?: boolean): void;
55
71
  next(): {
56
72
  index: number;
57
73
  results: {
58
- col: number;
59
- row: number;
74
+ col?: number;
75
+ row?: number;
60
76
  range?: VTable.TYPES.CellRange;
61
- value: string;
77
+ value?: string;
78
+ indexNumber?: number[];
62
79
  }[];
63
80
  };
64
81
  prev(): {
65
82
  index: number;
66
83
  results: {
67
- col: number;
68
- row: number;
84
+ col?: number;
85
+ row?: number;
69
86
  range?: VTable.TYPES.CellRange;
70
- value: string;
87
+ value?: string;
88
+ indexNumber?: number[];
71
89
  }[];
72
90
  };
73
- jumpToCell(col: number, row: number): void;
91
+ jumpToCell(params: {
92
+ col?: number;
93
+ row?: number;
94
+ IndexNumber?: number[];
95
+ }): void;
96
+ getBodyRowIndexByRecordIndex(index: number | number[]): number;
74
97
  clear(): void;
75
98
  }
76
99
  export {};
@@ -14,13 +14,23 @@ function defalultQueryMethod(queryStr, value) {
14
14
  return (0, vutils_1.isValid)(queryStr) && (0, vutils_1.isValid)(value) && value.toString().includes(queryStr);
15
15
  }
16
16
 
17
+ function defalultTreeQueryMethod(queryStr, node, fieldsToSearch) {
18
+ if (!(0, vutils_1.isValid)(queryStr)) return !1;
19
+ return (Array.isArray(fieldsToSearch) && fieldsToSearch.length > 0 ? fieldsToSearch : Object.keys(node)).some((field => (0,
20
+ vutils_1.isValid)(null == node ? void 0 : node[field]) && node[field].toString().includes(queryStr)));
21
+ }
22
+
17
23
  class SearchComponent {
18
24
  constructor(option) {
19
25
  this.table = option.table, this.autoJump = option.autoJump || !1, this.skipHeader = option.skipHeader || !1,
20
26
  this.highlightCellStyle = option.highlightCellStyle || defalutHightlightCellStyle,
21
27
  this.focuseHighlightCellStyle = option.focuseHighlightCellStyle || defalutFocusHightlightCellStyle,
22
- this.queryMethod = option.queryMethod || defalultQueryMethod, this.callback = option.callback,
23
- this.table.registerCustomCellStyle("__search_component_highlight", this.highlightCellStyle),
28
+ this.queryMethod = option.queryMethod || defalultQueryMethod, this.treeQueryMethod = option.treeQueryMethod || defalultTreeQueryMethod,
29
+ this.fieldsToSearch = option.fieldsToSearch || [], this.isTree = !1, this.treeIndex = 0,
30
+ this.callback = option.callback, this.scrollOption = option.scrollOption || {
31
+ duration: 900,
32
+ easing: "quartIn"
33
+ }, this.table.registerCustomCellStyle("__search_component_highlight", this.highlightCellStyle),
24
34
  this.table.registerCustomCellStyle("__search_component_focuse", this.focuseHighlightCellStyle);
25
35
  }
26
36
  search(str) {
@@ -28,6 +38,38 @@ class SearchComponent {
28
38
  index: 0,
29
39
  results: this.queryResult
30
40
  };
41
+ if (this.isTree = this.table.options.columns.some((item => item.tree)), this.treeIndex = this.isTree ? this.table.options.columns.findIndex((item => item.tree)) : 0,
42
+ this.isTree) {
43
+ const colEnd = this.table.colCount, walk = (nodes, path) => {
44
+ nodes.forEach(((item, idx) => {
45
+ const currentPath = [ ...path, idx ];
46
+ this.treeQueryMethod(this.queryStr, item, this.fieldsToSearch, {
47
+ table: this.table
48
+ }) && this.queryResult.push({
49
+ indexNumber: currentPath,
50
+ range: {
51
+ start: {
52
+ row: null,
53
+ col: 0
54
+ },
55
+ end: {
56
+ row: null,
57
+ col: colEnd
58
+ }
59
+ }
60
+ }), item.children && Array.isArray(item.children) && item.children.length > 0 && walk(item.children, currentPath);
61
+ }));
62
+ };
63
+ return walk(this.table.records, []), this.jumpToCell({
64
+ IndexNumber: this.queryResult[0].indexNumber
65
+ }), this.callback && this.callback({
66
+ queryStr: this.queryStr,
67
+ results: this.queryResult
68
+ }, this.table), this.updateCellStyle(), this.currentIndex = 0, {
69
+ index: 0,
70
+ results: this.queryResult
71
+ };
72
+ }
31
73
  for (let row = 0; row < this.table.rowCount; row++) for (let col = 0; col < this.table.colCount; col++) {
32
74
  if (this.skipHeader && this.table.isHeader(col, row)) continue;
33
75
  const value = this.table.getCellValue(col, row);
@@ -65,18 +107,24 @@ class SearchComponent {
65
107
  };
66
108
  }
67
109
  updateCellStyle(highlight = !0) {
68
- if (this.queryResult) {
69
- this.table.hasCustomCellStyle("__search_component_highlight") || this.table.registerCustomCellStyle("__search_component_highlight", this.highlightCellStyle),
70
- this.table.hasCustomCellStyle("__search_component_focuse") || this.table.registerCustomCellStyle("__search_component_focuse", this.focuseHighlightCellStyle);
71
- for (let i = 0; i < this.queryResult.length; i++) {
72
- const {col: col, row: row, range: range} = this.queryResult[i];
73
- range ? this.table.arrangeCustomCellStyle({
74
- range: range
75
- }, highlight ? "__search_component_highlight" : null) : this.table.arrangeCustomCellStyle({
76
- col: col,
77
- row: row
78
- }, highlight ? "__search_component_highlight" : null);
79
- }
110
+ if (this.queryResult) if (this.table.hasCustomCellStyle("__search_component_highlight") || this.table.registerCustomCellStyle("__search_component_highlight", this.highlightCellStyle),
111
+ this.table.hasCustomCellStyle("__search_component_focuse") || this.table.registerCustomCellStyle("__search_component_focuse", this.focuseHighlightCellStyle),
112
+ this.isTree) {
113
+ const {range: range, indexNumber: indexNumber} = this.queryResult[0];
114
+ let i = 0;
115
+ for (;this.table.isHeader(0, i); ) i++;
116
+ let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
117
+ range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
118
+ range: range
119
+ }, highlight ? "__search_component_focuse" : null);
120
+ } else for (let i = 0; i < this.queryResult.length; i++) {
121
+ const {col: col, row: row, range: range} = this.queryResult[i];
122
+ range ? this.table.arrangeCustomCellStyle({
123
+ range: range
124
+ }, highlight ? "__search_component_highlight" : null) : this.table.arrangeCustomCellStyle({
125
+ col: col,
126
+ row: row
127
+ }, highlight ? "__search_component_highlight" : null);
80
128
  }
81
129
  }
82
130
  next() {
@@ -84,23 +132,53 @@ class SearchComponent {
84
132
  index: 0,
85
133
  results: this.queryResult
86
134
  };
87
- if (-1 !== this.currentIndex) {
135
+ if (this.isTree) {
136
+ if (-1 !== this.currentIndex) {
137
+ const {range: range, indexNumber: indexNumber} = this.queryResult[this.currentIndex];
138
+ if (range) {
139
+ let i = 0;
140
+ for (;this.table.isHeader(0, i); ) i++;
141
+ let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
142
+ range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
143
+ range: range
144
+ }, "__search_component_highlight");
145
+ }
146
+ }
147
+ this.currentIndex++, this.currentIndex >= this.queryResult.length && (this.currentIndex = 0);
148
+ const {range: range, indexNumber: indexNumber} = this.queryResult[this.currentIndex];
149
+ if (this.jumpToCell({
150
+ IndexNumber: indexNumber
151
+ }), range) {
152
+ let i = 0;
153
+ for (;this.table.isHeader(0, i); ) i++;
154
+ let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
155
+ range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
156
+ range: range
157
+ }, "__search_component_focuse");
158
+ }
159
+ } else {
160
+ if (-1 !== this.currentIndex) {
161
+ const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
162
+ range ? this.table.arrangeCustomCellStyle({
163
+ range: range
164
+ }, "__search_component_highlight") : this.table.arrangeCustomCellStyle({
165
+ col: col,
166
+ row: row
167
+ }, "__search_component_highlight");
168
+ }
169
+ this.currentIndex++, this.currentIndex >= this.queryResult.length && (this.currentIndex = 0);
88
170
  const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
89
171
  range ? this.table.arrangeCustomCellStyle({
90
172
  range: range
91
- }, "__search_component_highlight") : this.table.arrangeCustomCellStyle({
173
+ }, "__search_component_focuse") : this.table.arrangeCustomCellStyle({
92
174
  col: col,
93
175
  row: row
94
- }, "__search_component_highlight");
176
+ }, "__search_component_focuse"), this.jumpToCell({
177
+ col: col,
178
+ row: row
179
+ });
95
180
  }
96
- this.currentIndex++, this.currentIndex >= this.queryResult.length && (this.currentIndex = 0);
97
- const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
98
- return range ? this.table.arrangeCustomCellStyle({
99
- range: range
100
- }, "__search_component_focuse") : this.table.arrangeCustomCellStyle({
101
- col: col,
102
- row: row
103
- }, "__search_component_focuse"), this.jumpToCell(col, row), {
181
+ return {
104
182
  index: this.currentIndex,
105
183
  results: this.queryResult
106
184
  };
@@ -110,33 +188,79 @@ class SearchComponent {
110
188
  index: 0,
111
189
  results: this.queryResult
112
190
  };
113
- if (-1 !== this.currentIndex) {
191
+ if (this.isTree) {
192
+ if (-1 !== this.currentIndex) {
193
+ const {range: range, indexNumber: indexNumber} = this.queryResult[this.currentIndex];
194
+ if (range) {
195
+ let i = 0;
196
+ for (;this.table.isHeader(0, i); ) i++;
197
+ let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
198
+ range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
199
+ range: range
200
+ }, "__search_component_highlight");
201
+ }
202
+ }
203
+ this.currentIndex--, this.currentIndex < 0 && (this.currentIndex = this.queryResult.length - 1);
204
+ const {range: range, indexNumber: indexNumber} = this.queryResult[this.currentIndex];
205
+ if (this.jumpToCell({
206
+ IndexNumber: indexNumber
207
+ }), range) {
208
+ let i = 0;
209
+ for (;this.table.isHeader(0, i); ) i++;
210
+ let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
211
+ range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
212
+ range: range
213
+ }, "__search_component_focuse");
214
+ }
215
+ } else {
216
+ if (-1 !== this.currentIndex) {
217
+ const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
218
+ range ? this.table.arrangeCustomCellStyle({
219
+ range: range
220
+ }, "__search_component_highlight") : this.table.arrangeCustomCellStyle({
221
+ col: col,
222
+ row: row
223
+ }, "__search_component_highlight");
224
+ }
225
+ this.currentIndex--, this.currentIndex < 0 && (this.currentIndex = this.queryResult.length - 1);
114
226
  const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
115
227
  range ? this.table.arrangeCustomCellStyle({
116
228
  range: range
117
- }, "__search_component_highlight") : this.table.arrangeCustomCellStyle({
229
+ }, "__search_component_focuse") : this.table.arrangeCustomCellStyle({
118
230
  col: col,
119
231
  row: row
120
- }, "__search_component_highlight");
232
+ }, "__search_component_focuse"), this.jumpToCell({
233
+ col: col,
234
+ row: row
235
+ });
121
236
  }
122
- this.currentIndex--, this.currentIndex < 0 && (this.currentIndex = this.queryResult.length - 1);
123
- const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
124
- return range ? this.table.arrangeCustomCellStyle({
125
- range: range
126
- }, "__search_component_focuse") : this.table.arrangeCustomCellStyle({
127
- col: col,
128
- row: row
129
- }, "__search_component_focuse"), this.jumpToCell(col, row), {
237
+ return {
130
238
  index: this.currentIndex,
131
239
  results: this.queryResult
132
240
  };
133
241
  }
134
- jumpToCell(col, row) {
135
- const {rowStart: rowStart, rowEnd: rowEnd} = this.table.getBodyVisibleRowRange(), {colStart: colStart, colEnd: colEnd} = this.table.getBodyVisibleColRange();
136
- (row <= rowStart || row >= rowEnd || col <= colStart || col >= colEnd) && this.table.scrollToCell({
137
- col: col,
138
- row: row
139
- });
242
+ jumpToCell(params) {
243
+ if (this.isTree) {
244
+ const {IndexNumber: IndexNumber} = params;
245
+ let indexNumbers = [ ...IndexNumber ], tmp = [ ...indexNumbers ], tmpNumber = 0, i = 0;
246
+ for (;tmpNumber < tmp.length - 1; ) {
247
+ tmpNumber++;
248
+ let indexNumber = indexNumbers.slice(0, tmpNumber);
249
+ for (;this.table.isHeader(0, i); ) i++;
250
+ let row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
251
+ "expand" !== this.table.getHierarchyState(this.treeIndex, row) && this.table.toggleHierarchyState(this.treeIndex, row);
252
+ }
253
+ this.table.scrollToRow(this.getBodyRowIndexByRecordIndex(indexNumbers) + i, this.scrollOption);
254
+ } else {
255
+ const {col: col, row: row} = params, {rowStart: rowStart, rowEnd: rowEnd} = this.table.getBodyVisibleRowRange(), {colStart: colStart, colEnd: colEnd} = this.table.getBodyVisibleColRange();
256
+ (row <= rowStart || row >= rowEnd || col <= colStart || col >= colEnd) && this.table.scrollToCell({
257
+ col: col,
258
+ row: row
259
+ });
260
+ }
261
+ }
262
+ getBodyRowIndexByRecordIndex(index) {
263
+ return Array.isArray(index) && 1 === index.length && (index = index[0]), this.table.dataSource.getTableIndex(index);
140
264
  }
141
265
  clear() {
142
266
  this.updateCellStyle(null), this.queryStr = "", this.queryResult = [], this.currentIndex = -1;
@@ -1 +1 @@
1
- {"version":3,"sources":["search-component/search-component.ts"],"names":[],"mappings":";;;AACA,6CAA2C;AAuB3C,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;AAED,MAAa,eAAe;IAkB1B,YAAY,MAA6B;QACvC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,KAAK,CAAC;QACzC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,KAAK,CAAC;QAC7C,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,IAAI,0BAA0B,CAAC;QAClF,IAAI,CAAC,wBAAwB,GAAG,MAAM,CAAC,wBAAwB,IAAI,+BAA+B,CAAC;QACnG,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,IAAI,mBAAmB,CAAC;QAC7D,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAEhC,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC,8BAA8B,EAA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MAAM,EAAE;YACxE,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;SACvC;IACH,CAAC;IAED,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;AA9QD,0CA8QC","file":"search-component.js","sourcesContent":["import type * as VTable from '@visactor/vtable';\nimport { isValid } from '@visactor/vutils';\n\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 }[];\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 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}\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 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 }[];\n currentIndex: number;\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.callback = option.callback;\n\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\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\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 updateCellStyle(highlight: boolean = true) {\n if (!this.queryResult) {\n return;\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 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 next() {\n if (!this.queryResult.length) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n if (this.currentIndex !== -1) {\n // reset last focus\n const { col, row, range } = this.queryResult[this.currentIndex];\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 // 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 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 if (this.currentIndex !== -1) {\n // reset last focus\n // this.table.arrangeCustomCellStyle(\n // {\n // col: this.queryResult[this.currentIndex].col,\n // row: this.queryResult[this.currentIndex].row\n // },\n // '__search_component_highlight'\n // );\n const { col, row, range } = this.queryResult[this.currentIndex];\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 < 0) {\n this.currentIndex = this.queryResult.length - 1;\n }\n const { col, row, range } = this.queryResult[this.currentIndex];\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 return {\n index: this.currentIndex,\n results: this.queryResult\n };\n }\n\n jumpToCell(col: number, row: number) {\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 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;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,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;QAAE,OAAO,KAAK,CAAC;IAGr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AAS,EACd,GAAG,CACJ,CAAC;iBACH;aACF;YACD,IAAI,CAAC,KAAK,CAAC,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;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"]}