@visactor/vtable-search 1.20.1 → 1.20.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -67,6 +67,7 @@ export declare class SearchComponent {
67
67
  indexNumber?: number[];
68
68
  }[];
69
69
  };
70
+ arrangeCustomCellStyle(resultItem: (typeof this.queryResult)[number], highlight?: boolean, customStyleId?: string): void;
70
71
  updateCellStyle(highlight?: boolean): void;
71
72
  next(): {
72
73
  index: number;
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  }), exports.SearchComponent = void 0;
6
6
 
7
- const vutils_1 = require("@visactor/vutils"), defalutHightlightCellStyle = {
7
+ const vutils_1 = require("@visactor/vutils"), HighlightStyleId = "__search_component_highlight", FocuseHighlightStyleId = "__search_component_focuse", defalutHightlightCellStyle = {
8
8
  bgColor: "rgba(255, 255, 0, 0.2)"
9
9
  }, defalutFocusHightlightCellStyle = {
10
10
  bgColor: "rgba(255, 155, 0, 0.2)"
@@ -30,8 +30,8 @@ class SearchComponent {
30
30
  this.callback = option.callback, this.scrollOption = option.scrollOption || {
31
31
  duration: 900,
32
32
  easing: "quartIn"
33
- }, this.table.registerCustomCellStyle("__search_component_highlight", this.highlightCellStyle),
34
- this.table.registerCustomCellStyle("__search_component_focuse", this.focuseHighlightCellStyle);
33
+ }, this.table.registerCustomCellStyle(HighlightStyleId, this.highlightCellStyle),
34
+ this.table.registerCustomCellStyle(FocuseHighlightStyleId, this.focuseHighlightCellStyle);
35
35
  }
36
36
  search(str) {
37
37
  if (this.clear(), this.queryStr = str, !str) return {
@@ -65,7 +65,7 @@ class SearchComponent {
65
65
  }), this.callback && this.callback({
66
66
  queryStr: this.queryStr,
67
67
  results: this.queryResult
68
- }, this.table), this.updateCellStyle(!0), this.currentIndex = 0, {
68
+ }, this.table), this.updateCellStyle(), 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(!0), this.callback && this.callback({
101
+ return this.updateCellStyle(), this.callback && this.callback({
102
102
  queryStr: this.queryStr,
103
103
  results: this.queryResult
104
104
  }, this.table), this.autoJump ? this.next() : {
@@ -106,32 +106,30 @@ class SearchComponent {
106
106
  results: this.queryResult
107
107
  };
108
108
  }
109
+ arrangeCustomCellStyle(resultItem, highlight = !0, customStyleId = HighlightStyleId) {
110
+ const {col: col, row: row, range: range} = resultItem;
111
+ this.table.arrangeCustomCellStyle(range ? {
112
+ range: range
113
+ } : {
114
+ row: row,
115
+ col: col
116
+ }, highlight ? customStyleId : null);
117
+ }
109
118
  updateCellStyle(highlight = !0) {
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),
119
+ if (highlight) {
120
+ if (this.queryResult) if (this.table.hasCustomCellStyle(HighlightStyleId) || this.table.registerCustomCellStyle(HighlightStyleId, this.highlightCellStyle),
121
+ this.table.hasCustomCellStyle(FocuseHighlightStyleId) || this.table.registerCustomCellStyle(FocuseHighlightStyleId, this.focuseHighlightCellStyle),
114
122
  this.isTree) {
115
123
  const {range: range, indexNumber: indexNumber} = this.queryResult[0];
116
124
  let i = 0;
117
125
  for (;this.table.isHeader(0, i); ) i++;
118
126
  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({
127
+ range.start.row = row, range.end.row = row, this.arrangeCustomCellStyle({
125
128
  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({
133
- range: range
134
- }, "");
129
+ }, highlight, FocuseHighlightStyleId);
130
+ } else for (let i = 0; i < this.queryResult.length; i++) this.arrangeCustomCellStyle(this.queryResult[i], highlight);
131
+ } else (this.queryResult || []).forEach((resultItem => {
132
+ this.arrangeCustomCellStyle(resultItem, highlight);
135
133
  }));
136
134
  }
137
135
  next() {
@@ -146,9 +144,9 @@ class SearchComponent {
146
144
  let i = 0;
147
145
  for (;this.table.isHeader(0, i); ) i++;
148
146
  const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
149
- range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
147
+ range.start.row = row, range.end.row = row, this.arrangeCustomCellStyle({
150
148
  range: range
151
- }, "__search_component_highlight");
149
+ });
152
150
  }
153
151
  }
154
152
  this.currentIndex++, this.currentIndex >= this.queryResult.length && (this.currentIndex = 0);
@@ -159,28 +157,16 @@ class SearchComponent {
159
157
  let i = 0;
160
158
  for (;this.table.isHeader(0, i); ) i++;
161
159
  const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
162
- range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
160
+ range.start.row = row, range.end.row = row, this.arrangeCustomCellStyle({
163
161
  range: range
164
- }, "__search_component_focuse");
162
+ }, !0, FocuseHighlightStyleId);
165
163
  }
166
164
  } 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
- }
165
+ -1 !== this.currentIndex && this.arrangeCustomCellStyle(this.queryResult[this.currentIndex]),
176
166
  this.currentIndex++, this.currentIndex >= this.queryResult.length && (this.currentIndex = 0);
177
- const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
178
- range ? this.table.arrangeCustomCellStyle({
179
- range: range
180
- }, "__search_component_focuse") : this.table.arrangeCustomCellStyle({
181
- col: col,
182
- row: row
183
- }, "__search_component_focuse"), this.jumpToCell({
167
+ const {col: col, row: row} = this.queryResult[this.currentIndex];
168
+ this.arrangeCustomCellStyle(this.queryResult[this.currentIndex], !0, FocuseHighlightStyleId),
169
+ this.jumpToCell({
184
170
  col: col,
185
171
  row: row
186
172
  });
@@ -202,9 +188,9 @@ class SearchComponent {
202
188
  let i = 0;
203
189
  for (;this.table.isHeader(0, i); ) i++;
204
190
  const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
205
- range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
191
+ range.start.row = row, range.end.row = row, this.arrangeCustomCellStyle({
206
192
  range: range
207
- }, "__search_component_highlight");
193
+ });
208
194
  }
209
195
  }
210
196
  this.currentIndex--, this.currentIndex < 0 && (this.currentIndex = this.queryResult.length - 1);
@@ -215,28 +201,16 @@ class SearchComponent {
215
201
  let i = 0;
216
202
  for (;this.table.isHeader(0, i); ) i++;
217
203
  const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
218
- range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
204
+ range.start.row = row, range.end.row = row, this.arrangeCustomCellStyle({
219
205
  range: range
220
- }, "__search_component_focuse");
206
+ }, !0, FocuseHighlightStyleId);
221
207
  }
222
208
  } 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
- }
209
+ -1 !== this.currentIndex && this.arrangeCustomCellStyle(this.queryResult[this.currentIndex]),
232
210
  this.currentIndex--, this.currentIndex < 0 && (this.currentIndex = this.queryResult.length - 1);
233
- const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
234
- range ? this.table.arrangeCustomCellStyle({
235
- range: range
236
- }, "__search_component_focuse") : this.table.arrangeCustomCellStyle({
237
- col: col,
238
- row: row
239
- }, "__search_component_focuse"), this.jumpToCell({
211
+ const {col: col, row: row} = this.queryResult[this.currentIndex];
212
+ this.arrangeCustomCellStyle(this.queryResult[this.currentIndex], !0, FocuseHighlightStyleId),
213
+ this.jumpToCell({
240
214
  col: col,
241
215
  row: row
242
216
  });
@@ -270,7 +244,7 @@ class SearchComponent {
270
244
  return Array.isArray(index) && 1 === index.length && (index = index[0]), this.table.dataSource.getTableIndex(index);
271
245
  }
272
246
  clear() {
273
- this.updateCellStyle(null), this.queryStr = "", this.queryResult = [], this.currentIndex = -1;
247
+ this.updateCellStyle(!1), this.queryStr = "", this.queryResult = [], this.currentIndex = -1;
274
248
  }
275
249
  }
276
250
 
@@ -1 +1 @@
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,GAA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a,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"]}
1
+ {"version":3,"sources":["search-component/search-component.ts"],"names":[],"mappings":";;;AAGA,6CAA2C;AA0B3C,MAAM,gBAAgB,GAAG,8BAA8B,CAAC;AACxD,MAAM,sBAAsB,GAAG,2BAA2B,CAAC;AAE3D,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,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IACpD,CAAC;IACD,KAAK;QAEH,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;IACzB,CAAC;CACF;AAjaD,0CAiaC","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 HighlightStyleId = '__search_component_highlight';\nconst FocuseHighlightStyleId = '__search_component_focuse';\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(HighlightStyleId, this.highlightCellStyle as any);\n this.table.registerCustomCellStyle(FocuseHighlightStyleId, 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();\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();\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 * @description: 为查询结果项设置自定义单元格样式\n * @param {(typeof this.queryResult)[number]} resultItem 查询结果项\n * @param {boolean} highlight 是否高亮\n * @param {string} customStyleId 自定义样式ID\n */\n arrangeCustomCellStyle(\n resultItem: (typeof this.queryResult)[number],\n highlight: boolean = true,\n customStyleId: string = HighlightStyleId\n ) {\n const { col, row, range } = resultItem;\n this.table.arrangeCustomCellStyle(\n range\n ? { range }\n : {\n row,\n col\n },\n highlight ? customStyleId : null\n );\n }\n\n updateCellStyle(highlight: boolean = true) {\n if (!highlight) {\n (this.queryResult || []).forEach(resultItem => {\n this.arrangeCustomCellStyle(resultItem, highlight);\n });\n return;\n }\n if (!this.queryResult) {\n return;\n }\n\n if (!this.table.hasCustomCellStyle(HighlightStyleId)) {\n this.table.registerCustomCellStyle(HighlightStyleId, this.highlightCellStyle as any);\n }\n if (!this.table.hasCustomCellStyle(FocuseHighlightStyleId)) {\n this.table.registerCustomCellStyle(FocuseHighlightStyleId, 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.arrangeCustomCellStyle(\n {\n range\n },\n highlight,\n FocuseHighlightStyleId\n );\n } else {\n for (let i = 0; i < this.queryResult.length; i++) {\n this.arrangeCustomCellStyle(this.queryResult[i], highlight);\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.arrangeCustomCellStyle({ range });\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.arrangeCustomCellStyle(\n {\n range\n },\n true,\n FocuseHighlightStyleId\n );\n }\n } else {\n if (this.currentIndex !== -1) {\n // reset last focus\n this.arrangeCustomCellStyle(this.queryResult[this.currentIndex]);\n }\n this.currentIndex++;\n if (this.currentIndex >= this.queryResult.length) {\n this.currentIndex = 0;\n }\n const { col, row } = this.queryResult[this.currentIndex];\n\n this.arrangeCustomCellStyle(this.queryResult[this.currentIndex], true, FocuseHighlightStyleId);\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.arrangeCustomCellStyle({ range });\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.arrangeCustomCellStyle({ range }, true, FocuseHighlightStyleId);\n }\n } else {\n // 普通表格处理\n if (this.currentIndex !== -1) {\n this.arrangeCustomCellStyle(this.queryResult[this.currentIndex]);\n }\n\n this.currentIndex--;\n if (this.currentIndex < 0) {\n this.currentIndex = this.queryResult.length - 1;\n }\n\n const { col, row } = this.queryResult[this.currentIndex];\n this.arrangeCustomCellStyle(this.queryResult[this.currentIndex], true, FocuseHighlightStyleId);\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(false);\n this.queryStr = '';\n this.queryResult = [];\n this.currentIndex = -1;\n }\n}\n"]}
@@ -7,6 +7,8 @@
7
7
  const isValid = value => null != value;
8
8
  var isValid$1 = isValid;
9
9
 
10
+ const HighlightStyleId = '__search_component_highlight';
11
+ const FocuseHighlightStyleId = '__search_component_focuse';
10
12
  const defalutHightlightCellStyle = {
11
13
  bgColor: 'rgba(255, 255, 0, 0.2)'
12
14
  };
@@ -53,8 +55,8 @@
53
55
  this.callback = option.callback;
54
56
  this.scrollOption =
55
57
  option.scrollOption || { duration: 900, easing: 'quartIn' };
56
- this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle);
57
- this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle);
58
+ this.table.registerCustomCellStyle(HighlightStyleId, this.highlightCellStyle);
59
+ this.table.registerCustomCellStyle(FocuseHighlightStyleId, this.focuseHighlightCellStyle);
58
60
  }
59
61
  search(str) {
60
62
  this.clear();
@@ -96,7 +98,7 @@
96
98
  results: this.queryResult
97
99
  }, this.table);
98
100
  }
99
- this.updateCellStyle(true);
101
+ this.updateCellStyle();
100
102
  this.currentIndex = 0;
101
103
  return {
102
104
  index: 0,
@@ -138,7 +140,7 @@
138
140
  }
139
141
  }
140
142
  }
141
- this.updateCellStyle(true);
143
+ this.updateCellStyle();
142
144
  if (this.callback) {
143
145
  this.callback({
144
146
  queryStr: this.queryStr,
@@ -153,25 +155,30 @@
153
155
  results: this.queryResult
154
156
  };
155
157
  }
158
+ arrangeCustomCellStyle(resultItem, highlight = true, customStyleId = HighlightStyleId) {
159
+ const { col, row, range } = resultItem;
160
+ this.table.arrangeCustomCellStyle(range
161
+ ? { range }
162
+ : {
163
+ row,
164
+ col
165
+ }, highlight ? customStyleId : null);
166
+ }
156
167
  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
- }
168
+ if (!highlight) {
169
+ (this.queryResult || []).forEach(resultItem => {
170
+ this.arrangeCustomCellStyle(resultItem, highlight);
171
+ });
165
172
  return;
166
173
  }
167
174
  if (!this.queryResult) {
168
175
  return;
169
176
  }
170
- if (!this.table.hasCustomCellStyle('__search_component_highlight')) {
171
- this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle);
177
+ if (!this.table.hasCustomCellStyle(HighlightStyleId)) {
178
+ this.table.registerCustomCellStyle(HighlightStyleId, this.highlightCellStyle);
172
179
  }
173
- if (!this.table.hasCustomCellStyle('__search_component_focuse')) {
174
- this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle);
180
+ if (!this.table.hasCustomCellStyle(FocuseHighlightStyleId)) {
181
+ this.table.registerCustomCellStyle(FocuseHighlightStyleId, this.focuseHighlightCellStyle);
175
182
  }
176
183
  if (this.isTree) {
177
184
  const { range, indexNumber } = this.queryResult[0];
@@ -182,24 +189,13 @@
182
189
  const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
183
190
  range.start.row = row;
184
191
  range.end.row = row;
185
- this.table.arrangeCustomCellStyle({
192
+ this.arrangeCustomCellStyle({
186
193
  range
187
- }, highlight ? '__search_component_focuse' : null);
194
+ }, highlight, FocuseHighlightStyleId);
188
195
  }
189
196
  else {
190
197
  for (let i = 0; i < this.queryResult.length; i++) {
191
- const { col, row, range } = this.queryResult[i];
192
- if (range) {
193
- this.table.arrangeCustomCellStyle({
194
- range
195
- }, highlight ? '__search_component_highlight' : null);
196
- }
197
- else {
198
- this.table.arrangeCustomCellStyle({
199
- col,
200
- row
201
- }, highlight ? '__search_component_highlight' : null);
202
- }
198
+ this.arrangeCustomCellStyle(this.queryResult[i], highlight);
203
199
  }
204
200
  }
205
201
  }
@@ -221,9 +217,7 @@
221
217
  const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
222
218
  range.start.row = row;
223
219
  range.end.row = row;
224
- this.table.arrangeCustomCellStyle({
225
- range
226
- }, '__search_component_highlight');
220
+ this.arrangeCustomCellStyle({ range });
227
221
  }
228
222
  }
229
223
  this.currentIndex++;
@@ -240,42 +234,21 @@
240
234
  const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
241
235
  range.start.row = row;
242
236
  range.end.row = row;
243
- this.table.arrangeCustomCellStyle({
237
+ this.arrangeCustomCellStyle({
244
238
  range
245
- }, '__search_component_focuse');
239
+ }, true, FocuseHighlightStyleId);
246
240
  }
247
241
  }
248
242
  else {
249
243
  if (this.currentIndex !== -1) {
250
- const { col, row, range } = this.queryResult[this.currentIndex];
251
- if (range) {
252
- this.table.arrangeCustomCellStyle({
253
- range
254
- }, '__search_component_highlight');
255
- }
256
- else {
257
- this.table.arrangeCustomCellStyle({
258
- col,
259
- row
260
- }, '__search_component_highlight');
261
- }
244
+ this.arrangeCustomCellStyle(this.queryResult[this.currentIndex]);
262
245
  }
263
246
  this.currentIndex++;
264
247
  if (this.currentIndex >= this.queryResult.length) {
265
248
  this.currentIndex = 0;
266
249
  }
267
- const { col, row, range } = this.queryResult[this.currentIndex];
268
- if (range) {
269
- this.table.arrangeCustomCellStyle({
270
- range
271
- }, '__search_component_focuse');
272
- }
273
- else {
274
- this.table.arrangeCustomCellStyle({
275
- col,
276
- row
277
- }, '__search_component_focuse');
278
- }
250
+ const { col, row } = this.queryResult[this.currentIndex];
251
+ this.arrangeCustomCellStyle(this.queryResult[this.currentIndex], true, FocuseHighlightStyleId);
279
252
  this.jumpToCell({ col, row });
280
253
  }
281
254
  return {
@@ -301,7 +274,7 @@
301
274
  const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
302
275
  range.start.row = row;
303
276
  range.end.row = row;
304
- this.table.arrangeCustomCellStyle({ range }, '__search_component_highlight');
277
+ this.arrangeCustomCellStyle({ range });
305
278
  }
306
279
  }
307
280
  this.currentIndex--;
@@ -318,30 +291,19 @@
318
291
  const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
319
292
  range.start.row = row;
320
293
  range.end.row = row;
321
- this.table.arrangeCustomCellStyle({ range }, '__search_component_focuse');
294
+ this.arrangeCustomCellStyle({ range }, true, FocuseHighlightStyleId);
322
295
  }
323
296
  }
324
297
  else {
325
298
  if (this.currentIndex !== -1) {
326
- const { col, row, range } = this.queryResult[this.currentIndex];
327
- if (range) {
328
- this.table.arrangeCustomCellStyle({ range }, '__search_component_highlight');
329
- }
330
- else {
331
- this.table.arrangeCustomCellStyle({ col, row }, '__search_component_highlight');
332
- }
299
+ this.arrangeCustomCellStyle(this.queryResult[this.currentIndex]);
333
300
  }
334
301
  this.currentIndex--;
335
302
  if (this.currentIndex < 0) {
336
303
  this.currentIndex = this.queryResult.length - 1;
337
304
  }
338
- const { col, row, range } = this.queryResult[this.currentIndex];
339
- if (range) {
340
- this.table.arrangeCustomCellStyle({ range }, '__search_component_focuse');
341
- }
342
- else {
343
- this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');
344
- }
305
+ const { col, row } = this.queryResult[this.currentIndex];
306
+ this.arrangeCustomCellStyle(this.queryResult[this.currentIndex], true, FocuseHighlightStyleId);
345
307
  this.jumpToCell({ col, row });
346
308
  }
347
309
  return {
@@ -386,7 +348,7 @@
386
348
  return this.table.dataSource.getTableIndex(index);
387
349
  }
388
350
  clear() {
389
- this.updateCellStyle(null);
351
+ this.updateCellStyle(false);
390
352
  this.queryStr = '';
391
353
  this.queryResult = [];
392
354
  this.currentIndex = -1;
@@ -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.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
+ !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="__search_component_highlight",s="__search_component_focuse",l={bgColor:"rgba(255, 255, 0, 0.2)"},i={bgColor:"rgba(255, 155, 0, 0.2)"};function h(e,r){return t(e)&&t(r)&&r.toString().includes(e)}function n(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||l,this.focuseHighlightCellStyle=e.focuseHighlightCellStyle||i,this.queryMethod=e.queryMethod||h,this.treeQueryMethod=e.treeQueryMethod||n,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(r,this.highlightCellStyle),this.table.registerCustomCellStyle(s,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(),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}}arrangeCustomCellStyle(e,t=!0,s=r){const{col:l,row:i,range:h}=e;this.table.arrangeCustomCellStyle(h?{range:h}:{row:i,col:l},t?s:null)}updateCellStyle(e=!0){if(e){if(this.queryResult)if(this.table.hasCustomCellStyle(r)||this.table.registerCustomCellStyle(r,this.highlightCellStyle),this.table.hasCustomCellStyle(s)||this.table.registerCustomCellStyle(s,this.focuseHighlightCellStyle),this.isTree){const{range:t,indexNumber:r}=this.queryResult[0];let l=0;for(;this.table.isHeader(0,l);)l++;const i=this.getBodyRowIndexByRecordIndex(r)+l;t.start.row=i,t.end.row=i,this.arrangeCustomCellStyle({range:t},e,s)}else for(let t=0;t<this.queryResult.length;t++)this.arrangeCustomCellStyle(this.queryResult[t],e)}else(this.queryResult||[]).forEach((t=>{this.arrangeCustomCellStyle(t,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.arrangeCustomCellStyle({range:e})}}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 l=this.getBodyRowIndexByRecordIndex(t)+r;e.start.row=l,e.end.row=l,this.arrangeCustomCellStyle({range:e},!0,s)}}else{-1!==this.currentIndex&&this.arrangeCustomCellStyle(this.queryResult[this.currentIndex]),this.currentIndex++,this.currentIndex>=this.queryResult.length&&(this.currentIndex=0);const{col:e,row:t}=this.queryResult[this.currentIndex];this.arrangeCustomCellStyle(this.queryResult[this.currentIndex],!0,s),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.arrangeCustomCellStyle({range:e})}}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 l=this.getBodyRowIndexByRecordIndex(t)+r;e.start.row=l,e.end.row=l,this.arrangeCustomCellStyle({range:e},!0,s)}}else{-1!==this.currentIndex&&this.arrangeCustomCellStyle(this.queryResult[this.currentIndex]),this.currentIndex--,this.currentIndex<0&&(this.currentIndex=this.queryResult.length-1);const{col:e,row:t}=this.queryResult[this.currentIndex];this.arrangeCustomCellStyle(this.queryResult[this.currentIndex],!0,s),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:h}=this.table.getBodyVisibleColRange();(r<=s||r>=l||t<=i||t>=h)&&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(!1),this.queryStr="",this.queryResult=[],this.currentIndex=-1}}}));
@@ -67,6 +67,7 @@ export declare class SearchComponent {
67
67
  indexNumber?: number[];
68
68
  }[];
69
69
  };
70
+ arrangeCustomCellStyle(resultItem: (typeof this.queryResult)[number], highlight?: boolean, customStyleId?: string): void;
70
71
  updateCellStyle(highlight?: boolean): void;
71
72
  next(): {
72
73
  index: number;
@@ -1,6 +1,6 @@
1
1
  import { isValid } from "@visactor/vutils";
2
2
 
3
- const defalutHightlightCellStyle = {
3
+ const HighlightStyleId = "__search_component_highlight", FocuseHighlightStyleId = "__search_component_focuse", defalutHightlightCellStyle = {
4
4
  bgColor: "rgba(255, 255, 0, 0.2)"
5
5
  }, defalutFocusHightlightCellStyle = {
6
6
  bgColor: "rgba(255, 155, 0, 0.2)"
@@ -25,8 +25,8 @@ export class SearchComponent {
25
25
  this.callback = option.callback, this.scrollOption = option.scrollOption || {
26
26
  duration: 900,
27
27
  easing: "quartIn"
28
- }, this.table.registerCustomCellStyle("__search_component_highlight", this.highlightCellStyle),
29
- this.table.registerCustomCellStyle("__search_component_focuse", this.focuseHighlightCellStyle);
28
+ }, this.table.registerCustomCellStyle(HighlightStyleId, this.highlightCellStyle),
29
+ this.table.registerCustomCellStyle(FocuseHighlightStyleId, this.focuseHighlightCellStyle);
30
30
  }
31
31
  search(str) {
32
32
  if (this.clear(), this.queryStr = str, !str) return {
@@ -60,7 +60,7 @@ export class SearchComponent {
60
60
  }), this.callback && this.callback({
61
61
  queryStr: this.queryStr,
62
62
  results: this.queryResult
63
- }, this.table), this.updateCellStyle(!0), this.currentIndex = 0, {
63
+ }, this.table), this.updateCellStyle(), 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(!0), this.callback && this.callback({
96
+ return this.updateCellStyle(), this.callback && this.callback({
97
97
  queryStr: this.queryStr,
98
98
  results: this.queryResult
99
99
  }, this.table), this.autoJump ? this.next() : {
@@ -101,32 +101,30 @@ export class SearchComponent {
101
101
  results: this.queryResult
102
102
  };
103
103
  }
104
+ arrangeCustomCellStyle(resultItem, highlight = !0, customStyleId = HighlightStyleId) {
105
+ const {col: col, row: row, range: range} = resultItem;
106
+ this.table.arrangeCustomCellStyle(range ? {
107
+ range: range
108
+ } : {
109
+ row: row,
110
+ col: col
111
+ }, highlight ? customStyleId : null);
112
+ }
104
113
  updateCellStyle(highlight = !0) {
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),
114
+ if (highlight) {
115
+ if (this.queryResult) if (this.table.hasCustomCellStyle(HighlightStyleId) || this.table.registerCustomCellStyle(HighlightStyleId, this.highlightCellStyle),
116
+ this.table.hasCustomCellStyle(FocuseHighlightStyleId) || this.table.registerCustomCellStyle(FocuseHighlightStyleId, this.focuseHighlightCellStyle),
109
117
  this.isTree) {
110
118
  const {range: range, indexNumber: indexNumber} = this.queryResult[0];
111
119
  let i = 0;
112
120
  for (;this.table.isHeader(0, i); ) i++;
113
121
  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({
122
+ range.start.row = row, range.end.row = row, this.arrangeCustomCellStyle({
120
123
  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({
128
- range: range
129
- }, "");
124
+ }, highlight, FocuseHighlightStyleId);
125
+ } else for (let i = 0; i < this.queryResult.length; i++) this.arrangeCustomCellStyle(this.queryResult[i], highlight);
126
+ } else (this.queryResult || []).forEach((resultItem => {
127
+ this.arrangeCustomCellStyle(resultItem, highlight);
130
128
  }));
131
129
  }
132
130
  next() {
@@ -141,9 +139,9 @@ export class SearchComponent {
141
139
  let i = 0;
142
140
  for (;this.table.isHeader(0, i); ) i++;
143
141
  const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
144
- range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
142
+ range.start.row = row, range.end.row = row, this.arrangeCustomCellStyle({
145
143
  range: range
146
- }, "__search_component_highlight");
144
+ });
147
145
  }
148
146
  }
149
147
  this.currentIndex++, this.currentIndex >= this.queryResult.length && (this.currentIndex = 0);
@@ -154,28 +152,16 @@ export class SearchComponent {
154
152
  let i = 0;
155
153
  for (;this.table.isHeader(0, i); ) i++;
156
154
  const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
157
- range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
155
+ range.start.row = row, range.end.row = row, this.arrangeCustomCellStyle({
158
156
  range: range
159
- }, "__search_component_focuse");
157
+ }, !0, FocuseHighlightStyleId);
160
158
  }
161
159
  } else {
162
- if (-1 !== this.currentIndex) {
163
- const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
164
- range ? this.table.arrangeCustomCellStyle({
165
- range: range
166
- }, "__search_component_highlight") : this.table.arrangeCustomCellStyle({
167
- col: col,
168
- row: row
169
- }, "__search_component_highlight");
170
- }
160
+ -1 !== this.currentIndex && this.arrangeCustomCellStyle(this.queryResult[this.currentIndex]),
171
161
  this.currentIndex++, this.currentIndex >= this.queryResult.length && (this.currentIndex = 0);
172
- const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
173
- range ? this.table.arrangeCustomCellStyle({
174
- range: range
175
- }, "__search_component_focuse") : this.table.arrangeCustomCellStyle({
176
- col: col,
177
- row: row
178
- }, "__search_component_focuse"), this.jumpToCell({
162
+ const {col: col, row: row} = this.queryResult[this.currentIndex];
163
+ this.arrangeCustomCellStyle(this.queryResult[this.currentIndex], !0, FocuseHighlightStyleId),
164
+ this.jumpToCell({
179
165
  col: col,
180
166
  row: row
181
167
  });
@@ -197,9 +183,9 @@ export class SearchComponent {
197
183
  let i = 0;
198
184
  for (;this.table.isHeader(0, i); ) i++;
199
185
  const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
200
- range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
186
+ range.start.row = row, range.end.row = row, this.arrangeCustomCellStyle({
201
187
  range: range
202
- }, "__search_component_highlight");
188
+ });
203
189
  }
204
190
  }
205
191
  this.currentIndex--, this.currentIndex < 0 && (this.currentIndex = this.queryResult.length - 1);
@@ -210,28 +196,16 @@ export class SearchComponent {
210
196
  let i = 0;
211
197
  for (;this.table.isHeader(0, i); ) i++;
212
198
  const row = this.getBodyRowIndexByRecordIndex(indexNumber) + i;
213
- range.start.row = row, range.end.row = row, this.table.arrangeCustomCellStyle({
199
+ range.start.row = row, range.end.row = row, this.arrangeCustomCellStyle({
214
200
  range: range
215
- }, "__search_component_focuse");
201
+ }, !0, FocuseHighlightStyleId);
216
202
  }
217
203
  } else {
218
- if (-1 !== this.currentIndex) {
219
- const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
220
- range ? this.table.arrangeCustomCellStyle({
221
- range: range
222
- }, "__search_component_highlight") : this.table.arrangeCustomCellStyle({
223
- col: col,
224
- row: row
225
- }, "__search_component_highlight");
226
- }
204
+ -1 !== this.currentIndex && this.arrangeCustomCellStyle(this.queryResult[this.currentIndex]),
227
205
  this.currentIndex--, this.currentIndex < 0 && (this.currentIndex = this.queryResult.length - 1);
228
- const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
229
- range ? this.table.arrangeCustomCellStyle({
230
- range: range
231
- }, "__search_component_focuse") : this.table.arrangeCustomCellStyle({
232
- col: col,
233
- row: row
234
- }, "__search_component_focuse"), this.jumpToCell({
206
+ const {col: col, row: row} = this.queryResult[this.currentIndex];
207
+ this.arrangeCustomCellStyle(this.queryResult[this.currentIndex], !0, FocuseHighlightStyleId),
208
+ this.jumpToCell({
235
209
  col: col,
236
210
  row: row
237
211
  });
@@ -265,7 +239,7 @@ export class SearchComponent {
265
239
  return Array.isArray(index) && 1 === index.length && (index = index[0]), this.table.dataSource.getTableIndex(index);
266
240
  }
267
241
  clear() {
268
- this.updateCellStyle(null), this.queryStr = "", this.queryResult = [], this.currentIndex = -1;
242
+ this.updateCellStyle(!1), this.queryStr = "", this.queryResult = [], this.currentIndex = -1;
269
243
  }
270
244
  }
271
245
  //# sourceMappingURL=search-component.js.map
@@ -1 +1 @@
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;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,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,OAAO,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAG,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,EAA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BAAoB,CAAC,IAAI,CAAC,SAAS,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","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"]}
1
+ {"version":3,"sources":["search-component/search-component.ts"],"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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,KAAK,CAAC,CAAC;QAC5B,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 HighlightStyleId = '__search_component_highlight';\nconst FocuseHighlightStyleId = '__search_component_focuse';\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(HighlightStyleId, this.highlightCellStyle as any);\n this.table.registerCustomCellStyle(FocuseHighlightStyleId, 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();\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();\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 * @description: 为查询结果项设置自定义单元格样式\n * @param {(typeof this.queryResult)[number]} resultItem 查询结果项\n * @param {boolean} highlight 是否高亮\n * @param {string} customStyleId 自定义样式ID\n */\n arrangeCustomCellStyle(\n resultItem: (typeof this.queryResult)[number],\n highlight: boolean = true,\n customStyleId: string = HighlightStyleId\n ) {\n const { col, row, range } = resultItem;\n this.table.arrangeCustomCellStyle(\n range\n ? { range }\n : {\n row,\n col\n },\n highlight ? customStyleId : null\n );\n }\n\n updateCellStyle(highlight: boolean = true) {\n if (!highlight) {\n (this.queryResult || []).forEach(resultItem => {\n this.arrangeCustomCellStyle(resultItem, highlight);\n });\n return;\n }\n if (!this.queryResult) {\n return;\n }\n\n if (!this.table.hasCustomCellStyle(HighlightStyleId)) {\n this.table.registerCustomCellStyle(HighlightStyleId, this.highlightCellStyle as any);\n }\n if (!this.table.hasCustomCellStyle(FocuseHighlightStyleId)) {\n this.table.registerCustomCellStyle(FocuseHighlightStyleId, 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.arrangeCustomCellStyle(\n {\n range\n },\n highlight,\n FocuseHighlightStyleId\n );\n } else {\n for (let i = 0; i < this.queryResult.length; i++) {\n this.arrangeCustomCellStyle(this.queryResult[i], highlight);\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.arrangeCustomCellStyle({ range });\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.arrangeCustomCellStyle(\n {\n range\n },\n true,\n FocuseHighlightStyleId\n );\n }\n } else {\n if (this.currentIndex !== -1) {\n // reset last focus\n this.arrangeCustomCellStyle(this.queryResult[this.currentIndex]);\n }\n this.currentIndex++;\n if (this.currentIndex >= this.queryResult.length) {\n this.currentIndex = 0;\n }\n const { col, row } = this.queryResult[this.currentIndex];\n\n this.arrangeCustomCellStyle(this.queryResult[this.currentIndex], true, FocuseHighlightStyleId);\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.arrangeCustomCellStyle({ range });\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.arrangeCustomCellStyle({ range }, true, FocuseHighlightStyleId);\n }\n } else {\n // 普通表格处理\n if (this.currentIndex !== -1) {\n this.arrangeCustomCellStyle(this.queryResult[this.currentIndex]);\n }\n\n this.currentIndex--;\n if (this.currentIndex < 0) {\n this.currentIndex = this.queryResult.length - 1;\n }\n\n const { col, row } = this.queryResult[this.currentIndex];\n this.arrangeCustomCellStyle(this.queryResult[this.currentIndex], true, FocuseHighlightStyleId);\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(false);\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.20.1",
3
+ "version": "1.20.2",
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.20.1"
34
+ "@visactor/vtable": "1.20.2"
35
35
  },
36
36
  "devDependencies": {
37
37
  "cross-env": "^7.0.3",
@@ -77,9 +77,9 @@
77
77
  "axios": "^1.4.0",
78
78
  "@types/react-is": "^17.0.3",
79
79
  "rollup-plugin-node-resolve": "5.2.0",
80
- "@internal/bundler": "0.0.1",
80
+ "@internal/eslint-config": "0.0.1",
81
81
  "@internal/ts-config": "0.0.1",
82
- "@internal/eslint-config": "0.0.1"
82
+ "@internal/bundler": "0.0.1"
83
83
  },
84
84
  "scripts": {
85
85
  "start": "vite ./demo",