@visactor/vtable-search 1.19.6 → 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.
@@ -1,11 +1,13 @@
1
1
  import type * as VTable from '@visactor/vtable';
2
+ import type { 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.queryResult.length > 0 && 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(!0), 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);
@@ -56,7 +98,7 @@ class SearchComponent {
56
98
  });
57
99
  }
58
100
  }
59
- return this.updateCellStyle(), this.callback && this.callback({
101
+ return this.updateCellStyle(!0), this.callback && this.callback({
60
102
  queryStr: this.queryStr,
61
103
  results: this.queryResult
62
104
  }, this.table), this.autoJump ? this.next() : {
@@ -65,10 +107,19 @@ 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++) {
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++) {
72
123
  const {col: col, row: row, range: range} = this.queryResult[i];
73
124
  range ? this.table.arrangeCustomCellStyle({
74
125
  range: range
@@ -77,30 +128,64 @@ class SearchComponent {
77
128
  row: row
78
129
  }, highlight ? "__search_component_highlight" : null);
79
130
  }
80
- }
131
+ } else (null === (_a = this.queryResult) || void 0 === _a ? void 0 : _a.length) && this.queryResult.forEach((({range: range}) => {
132
+ range && this.table.arrangeCustomCellStyle({
133
+ range: range
134
+ }, "");
135
+ }));
81
136
  }
82
137
  next() {
83
138
  if (!this.queryResult.length) return {
84
139
  index: 0,
85
140
  results: this.queryResult
86
141
  };
87
- if (-1 !== this.currentIndex) {
142
+ if (this.isTree) {
143
+ if (-1 !== this.currentIndex) {
144
+ const {range: range, indexNumber: indexNumber} = this.queryResult[this.currentIndex];
145
+ if (range) {
146
+ let i = 0;
147
+ for (;this.table.isHeader(0, i); ) i++;
148
+ const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
149
+ range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
150
+ range: range
151
+ }, "__search_component_highlight");
152
+ }
153
+ }
154
+ this.currentIndex++, this.currentIndex >= this.queryResult.length && (this.currentIndex = 0);
155
+ const {range: range, indexNumber: indexNumber} = this.queryResult[this.currentIndex];
156
+ if (this.jumpToCell({
157
+ IndexNumber: indexNumber
158
+ }), range) {
159
+ let i = 0;
160
+ for (;this.table.isHeader(0, i); ) i++;
161
+ const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
162
+ range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
163
+ range: range
164
+ }, "__search_component_focuse");
165
+ }
166
+ } else {
167
+ if (-1 !== this.currentIndex) {
168
+ const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
169
+ range ? this.table.arrangeCustomCellStyle({
170
+ range: range
171
+ }, "__search_component_highlight") : this.table.arrangeCustomCellStyle({
172
+ col: col,
173
+ row: row
174
+ }, "__search_component_highlight");
175
+ }
176
+ this.currentIndex++, this.currentIndex >= this.queryResult.length && (this.currentIndex = 0);
88
177
  const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
89
178
  range ? this.table.arrangeCustomCellStyle({
90
179
  range: range
91
- }, "__search_component_highlight") : this.table.arrangeCustomCellStyle({
180
+ }, "__search_component_focuse") : this.table.arrangeCustomCellStyle({
181
+ col: col,
182
+ row: row
183
+ }, "__search_component_focuse"), this.jumpToCell({
92
184
  col: col,
93
185
  row: row
94
- }, "__search_component_highlight");
186
+ });
95
187
  }
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), {
188
+ return {
104
189
  index: this.currentIndex,
105
190
  results: this.queryResult
106
191
  };
@@ -110,33 +195,79 @@ class SearchComponent {
110
195
  index: 0,
111
196
  results: this.queryResult
112
197
  };
113
- if (-1 !== this.currentIndex) {
198
+ if (this.isTree) {
199
+ if (-1 !== this.currentIndex) {
200
+ const {range: range, indexNumber: indexNumber} = this.queryResult[this.currentIndex];
201
+ if (range) {
202
+ let i = 0;
203
+ for (;this.table.isHeader(0, i); ) i++;
204
+ const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
205
+ range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
206
+ range: range
207
+ }, "__search_component_highlight");
208
+ }
209
+ }
210
+ this.currentIndex--, this.currentIndex < 0 && (this.currentIndex = this.queryResult.length - 1);
211
+ const {range: range, indexNumber: indexNumber} = this.queryResult[this.currentIndex];
212
+ if (this.jumpToCell({
213
+ IndexNumber: indexNumber
214
+ }), range) {
215
+ let i = 0;
216
+ for (;this.table.isHeader(0, i); ) i++;
217
+ const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
218
+ range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
219
+ range: range
220
+ }, "__search_component_focuse");
221
+ }
222
+ } else {
223
+ if (-1 !== this.currentIndex) {
224
+ const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
225
+ range ? this.table.arrangeCustomCellStyle({
226
+ range: range
227
+ }, "__search_component_highlight") : this.table.arrangeCustomCellStyle({
228
+ col: col,
229
+ row: row
230
+ }, "__search_component_highlight");
231
+ }
232
+ this.currentIndex--, this.currentIndex < 0 && (this.currentIndex = this.queryResult.length - 1);
114
233
  const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
115
234
  range ? this.table.arrangeCustomCellStyle({
116
235
  range: range
117
- }, "__search_component_highlight") : this.table.arrangeCustomCellStyle({
236
+ }, "__search_component_focuse") : this.table.arrangeCustomCellStyle({
118
237
  col: col,
119
238
  row: row
120
- }, "__search_component_highlight");
239
+ }, "__search_component_focuse"), this.jumpToCell({
240
+ col: col,
241
+ row: row
242
+ });
121
243
  }
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), {
244
+ return {
130
245
  index: this.currentIndex,
131
246
  results: this.queryResult
132
247
  };
133
248
  }
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
- });
249
+ jumpToCell(params) {
250
+ if (this.isTree) {
251
+ const {IndexNumber: IndexNumber} = params, indexNumbers = [ ...IndexNumber ], tmp = [ ...indexNumbers ];
252
+ let tmpNumber = 0, i = 0;
253
+ for (;tmpNumber < tmp.length - 1; ) {
254
+ tmpNumber++;
255
+ const indexNumber = indexNumbers.slice(0, tmpNumber);
256
+ for (;this.table.isHeader(0, i); ) i++;
257
+ const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
258
+ "expand" !== this.table.getHierarchyState(this.treeIndex, row) && this.table.toggleHierarchyState(this.treeIndex, row);
259
+ }
260
+ this.table.scrollToRow(this.getBodyRowIndexByRecordIndex(indexNumbers) + i, this.scrollOption);
261
+ } else {
262
+ const {col: col, row: row} = params, {rowStart: rowStart, rowEnd: rowEnd} = this.table.getBodyVisibleRowRange(), {colStart: colStart, colEnd: colEnd} = this.table.getBodyVisibleColRange();
263
+ (row <= rowStart || row >= rowEnd || col <= colStart || col >= colEnd) && this.table.scrollToCell({
264
+ col: col,
265
+ row: row
266
+ });
267
+ }
268
+ }
269
+ getBodyRowIndexByRecordIndex(index) {
270
+ return Array.isArray(index) && 1 === index.length && (index = index[0]), this.table.dataSource.getTableIndex(index);
140
271
  }
141
272
  clear() {
142
273
  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,CA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,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,sBAAsB,EAAE,CAAC;QACjE,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,IAAI,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;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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;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"]}