@visactor/vtable-search 1.16.0-alpha.0 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,6 +37,7 @@ export declare class SearchComponent {
37
37
  queryResult: {
38
38
  col: number;
39
39
  row: number;
40
+ range?: VTable.TYPES.CellRange;
40
41
  value: string;
41
42
  }[];
42
43
  currentIndex: number;
@@ -46,6 +47,7 @@ export declare class SearchComponent {
46
47
  results: {
47
48
  col: number;
48
49
  row: number;
50
+ range?: VTable.TYPES.CellRange;
49
51
  value: string;
50
52
  }[];
51
53
  };
@@ -55,6 +57,7 @@ export declare class SearchComponent {
55
57
  results: {
56
58
  col: number;
57
59
  row: number;
60
+ range?: VTable.TYPES.CellRange;
58
61
  value: string;
59
62
  }[];
60
63
  };
@@ -63,6 +66,7 @@ export declare class SearchComponent {
63
66
  results: {
64
67
  col: number;
65
68
  row: number;
69
+ range?: VTable.TYPES.CellRange;
66
70
  value: string;
67
71
  }[];
68
72
  };
@@ -31,15 +31,30 @@ class SearchComponent {
31
31
  for (let row = 0; row < this.table.rowCount; row++) for (let col = 0; col < this.table.colCount; col++) {
32
32
  if (this.skipHeader && this.table.isHeader(col, row)) continue;
33
33
  const value = this.table.getCellValue(col, row);
34
- this.queryMethod(this.queryStr, value, {
34
+ if (this.queryMethod(this.queryStr, value, {
35
35
  col: col,
36
36
  row: row,
37
37
  table: this.table
38
- }) && this.queryResult.push({
39
- col: col,
40
- row: row,
41
- value: value
42
- });
38
+ })) {
39
+ const mergeCell = this.table.getCellRange(col, row);
40
+ if (mergeCell.start.col !== mergeCell.end.col || mergeCell.start.row !== mergeCell.end.row) {
41
+ let isIn = !1;
42
+ for (let i = this.queryResult.length - 1; i >= 0; i--) if (this.queryResult[i].col === mergeCell.start.col && this.queryResult[i].row === mergeCell.start.row) {
43
+ isIn = !0;
44
+ break;
45
+ }
46
+ isIn || this.queryResult.push({
47
+ col: mergeCell.start.col,
48
+ row: mergeCell.start.row,
49
+ range: mergeCell,
50
+ value: value
51
+ });
52
+ } else this.queryResult.push({
53
+ col: col,
54
+ row: row,
55
+ value: value
56
+ });
57
+ }
43
58
  }
44
59
  return this.updateCellStyle(), this.callback && this.callback({
45
60
  queryStr: this.queryStr,
@@ -54,8 +69,10 @@ class SearchComponent {
54
69
  this.table.hasCustomCellStyle("__search_component_highlight") || this.table.registerCustomCellStyle("__search_component_highlight", this.highlightCellStyle),
55
70
  this.table.hasCustomCellStyle("__search_component_focuse") || this.table.registerCustomCellStyle("__search_component_focuse", this.focuseHighlightCellStyle);
56
71
  for (let i = 0; i < this.queryResult.length; i++) {
57
- const {col: col, row: row} = this.queryResult[i];
58
- this.table.arrangeCustomCellStyle({
72
+ const {col: col, row: row, range: range} = this.queryResult[i];
73
+ range ? this.table.arrangeCustomCellStyle({
74
+ range: range
75
+ }, highlight ? "__search_component_highlight" : null) : this.table.arrangeCustomCellStyle({
59
76
  col: col,
60
77
  row: row
61
78
  }, highlight ? "__search_component_highlight" : null);
@@ -67,12 +84,20 @@ class SearchComponent {
67
84
  index: 0,
68
85
  results: this.queryResult
69
86
  };
70
- -1 !== this.currentIndex && this.table.arrangeCustomCellStyle({
71
- col: this.queryResult[this.currentIndex].col,
72
- row: this.queryResult[this.currentIndex].row
73
- }, "__search_component_highlight"), this.currentIndex++, this.currentIndex >= this.queryResult.length && (this.currentIndex = 0);
74
- const {col: col, row: row} = this.queryResult[this.currentIndex];
75
- return this.table.arrangeCustomCellStyle({
87
+ if (-1 !== this.currentIndex) {
88
+ const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
89
+ range ? this.table.arrangeCustomCellStyle({
90
+ range: range
91
+ }, "__search_component_highlight") : this.table.arrangeCustomCellStyle({
92
+ col: col,
93
+ row: row
94
+ }, "__search_component_highlight");
95
+ }
96
+ this.currentIndex++, this.currentIndex >= this.queryResult.length && (this.currentIndex = 0);
97
+ const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
98
+ return range ? this.table.arrangeCustomCellStyle({
99
+ range: range
100
+ }, "__search_component_focuse") : this.table.arrangeCustomCellStyle({
76
101
  col: col,
77
102
  row: row
78
103
  }, "__search_component_focuse"), this.jumpToCell(col, row), {
@@ -85,12 +110,20 @@ class SearchComponent {
85
110
  index: 0,
86
111
  results: this.queryResult
87
112
  };
88
- -1 !== this.currentIndex && this.table.arrangeCustomCellStyle({
89
- col: this.queryResult[this.currentIndex].col,
90
- row: this.queryResult[this.currentIndex].row
91
- }, "__search_component_highlight"), this.currentIndex--, this.currentIndex < 0 && (this.currentIndex = this.queryResult.length - 1);
92
- const {col: col, row: row} = this.queryResult[this.currentIndex];
93
- return this.table.arrangeCustomCellStyle({
113
+ if (-1 !== this.currentIndex) {
114
+ const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
115
+ range ? this.table.arrangeCustomCellStyle({
116
+ range: range
117
+ }, "__search_component_highlight") : this.table.arrangeCustomCellStyle({
118
+ col: col,
119
+ row: row
120
+ }, "__search_component_highlight");
121
+ }
122
+ this.currentIndex--, this.currentIndex < 0 && (this.currentIndex = this.queryResult.length - 1);
123
+ const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
124
+ return range ? this.table.arrangeCustomCellStyle({
125
+ range: range
126
+ }, "__search_component_focuse") : this.table.arrangeCustomCellStyle({
94
127
  col: col,
95
128
  row: row
96
129
  }, "__search_component_focuse"), this.jumpToCell(col, row), {
@@ -1 +1 @@
1
- {"version":3,"sources":["search-component/search-component.ts"],"names":[],"mappings":";;;AACA,6CAA2C;AAuB3C,MAAM,0BAA0B,GAAoC;IAClE,OAAO,EAAE,wBAAwB;CAClC,CAAC;AAEF,MAAM,+BAA+B,GAAoC;IACvE,OAAO,EAAE,wBAAwB;CAClC,CAAC;AAEF,SAAS,mBAAmB,CAAC,QAAgB,EAAE,KAAa;IAC1D,OAAO,IAAA,gBAAO,EAAC,QAAQ,CAAC,IAAI,IAAA,gBAAO,EAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QA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AM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,sBAAsB,EAAE,CAAC;QACjE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,sBAAsB,EAAE,CAAC;QACjE,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,IAAI,MAAM,EAAE;YACxE,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;SACvC;IACH,CAAC;IAED,KAAK;QAEH,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;IACzB,CAAC;CACF;AApLD,0CAoLC","file":"search-component.js","sourcesContent":["import type * as VTable from '@visactor/vtable';\nimport { isValid } from '@visactor/vutils';\n\ntype IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;\n\nexport type QueryResult = {\n queryStr: string;\n results: {\n col: number;\n row: number;\n value: string;\n }[];\n};\n\nexport type SearchComponentOption = {\n table: IVTable;\n autoJump?: boolean;\n skipHeader?: boolean;\n highlightCellStyle?: VTable.TYPES.CellStyle;\n focuseHighlightCellStyle?: VTable.TYPES.CellStyle;\n queryMethod?: (queryStr: string, value: string, option?: { col: number; row: number; table: IVTable }) => boolean;\n callback?: (queryResult: QueryResult, table: IVTable) => void;\n};\n\nconst defalutHightlightCellStyle: Partial<VTable.TYPES.CellStyle> = {\n bgColor: 'rgba(255, 255, 0, 0.2)'\n};\n\nconst defalutFocusHightlightCellStyle: Partial<VTable.TYPES.CellStyle> = {\n bgColor: 'rgba(255, 155, 0, 0.2)'\n};\n\nfunction defalultQueryMethod(queryStr: string, value: string) {\n return isValid(queryStr) && isValid(value) && value.toString().includes(queryStr);\n}\n\nexport class SearchComponent {\n table: IVTable;\n skipHeader: boolean;\n autoJump: boolean;\n highlightCellStyle: Partial<VTable.TYPES.CellStyle>;\n focuseHighlightCellStyle: Partial<VTable.TYPES.CellStyle>;\n queryMethod: (queryStr: string, value: string, option: { col: number; row: number; table: IVTable }) => boolean;\n callback?: (queryResult: QueryResult, table: IVTable) => void;\n\n queryStr: string;\n queryResult: {\n col: number;\n row: number;\n value: string;\n }[];\n currentIndex: number;\n\n constructor(option: SearchComponentOption) {\n this.table = option.table;\n this.autoJump = option.autoJump || false;\n this.skipHeader = option.skipHeader || false;\n this.highlightCellStyle = option.highlightCellStyle || defalutHightlightCellStyle;\n this.focuseHighlightCellStyle = option.focuseHighlightCellStyle || defalutFocusHightlightCellStyle;\n this.queryMethod = option.queryMethod || defalultQueryMethod;\n this.callback = option.callback;\n\n this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle as any);\n this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle as any);\n }\n\n search(str: string) {\n this.clear();\n this.queryStr = str;\n\n if (!str) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n\n for (let row = 0; row < this.table.rowCount; row++) {\n for (let col = 0; col < this.table.colCount; col++) {\n if (this.skipHeader && this.table.isHeader(col, row)) {\n continue;\n }\n const value = this.table.getCellValue(col, row);\n if (this.queryMethod(this.queryStr, value, { col, row, table: this.table })) {\n 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 updateCellStyle(highlight: boolean = true) {\n if (!this.queryResult) {\n return;\n }\n if (!this.table.hasCustomCellStyle('__search_component_highlight')) {\n this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle as any);\n }\n if (!this.table.hasCustomCellStyle('__search_component_focuse')) {\n this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle as any);\n }\n for (let i = 0; i < this.queryResult.length; i++) {\n const { col, row } = this.queryResult[i];\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n highlight ? '__search_component_highlight' : null\n );\n }\n }\n\n next() {\n if (!this.queryResult.length) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n if (this.currentIndex !== -1) {\n // reset last focus\n this.table.arrangeCustomCellStyle(\n {\n col: this.queryResult[this.currentIndex].col,\n row: this.queryResult[this.currentIndex].row\n },\n '__search_component_highlight'\n );\n }\n this.currentIndex++;\n if (this.currentIndex >= this.queryResult.length) {\n this.currentIndex = 0;\n }\n const { col, row } = this.queryResult[this.currentIndex];\n this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');\n\n this.jumpToCell(col, row);\n\n return {\n index: this.currentIndex,\n results: this.queryResult\n };\n }\n\n prev() {\n if (!this.queryResult.length) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n if (this.currentIndex !== -1) {\n // reset last focus\n this.table.arrangeCustomCellStyle(\n {\n col: this.queryResult[this.currentIndex].col,\n row: this.queryResult[this.currentIndex].row\n },\n '__search_component_highlight'\n );\n }\n this.currentIndex--;\n if (this.currentIndex < 0) {\n this.currentIndex = this.queryResult.length - 1;\n }\n const { col, row } = this.queryResult[this.currentIndex];\n this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');\n\n this.jumpToCell(col, row);\n\n return {\n index: this.currentIndex,\n results: this.queryResult\n };\n }\n\n jumpToCell(col: number, row: number) {\n // if focus cell out of screen, jump to cell\n const { rowStart, rowEnd } = this.table.getBodyVisibleRowRange();\n const { colStart, colEnd } = this.table.getBodyVisibleColRange();\n if (row <= rowStart || row >= rowEnd || col <= colStart || col >= colEnd) {\n this.table.scrollToCell({ col, row });\n }\n }\n\n clear() {\n // reset highlight cell style\n this.updateCellStyle(null);\n this.queryStr = '';\n this.queryResult = [];\n this.current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AAG,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;IACzB,CAAC;CACF;AA9QD,0CA8QC","file":"search-component.js","sourcesContent":["import type * as VTable from '@visactor/vtable';\nimport { isValid } from '@visactor/vutils';\n\ntype IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;\n\nexport type QueryResult = {\n queryStr: string;\n results: {\n col: number;\n row: number;\n value: string;\n }[];\n};\n\nexport type SearchComponentOption = {\n table: IVTable;\n autoJump?: boolean;\n skipHeader?: boolean;\n highlightCellStyle?: VTable.TYPES.CellStyle;\n focuseHighlightCellStyle?: VTable.TYPES.CellStyle;\n queryMethod?: (queryStr: string, value: string, option?: { col: number; row: number; table: IVTable }) => boolean;\n callback?: (queryResult: QueryResult, table: IVTable) => void;\n};\n\nconst defalutHightlightCellStyle: Partial<VTable.TYPES.CellStyle> = {\n bgColor: 'rgba(255, 255, 0, 0.2)'\n};\n\nconst defalutFocusHightlightCellStyle: Partial<VTable.TYPES.CellStyle> = {\n bgColor: 'rgba(255, 155, 0, 0.2)'\n};\n\nfunction defalultQueryMethod(queryStr: string, value: string) {\n return isValid(queryStr) && isValid(value) && value.toString().includes(queryStr);\n}\n\nexport class SearchComponent {\n table: IVTable;\n skipHeader: boolean;\n autoJump: boolean;\n highlightCellStyle: Partial<VTable.TYPES.CellStyle>;\n focuseHighlightCellStyle: Partial<VTable.TYPES.CellStyle>;\n queryMethod: (queryStr: string, value: string, option: { col: number; row: number; table: IVTable }) => boolean;\n callback?: (queryResult: QueryResult, table: IVTable) => void;\n\n queryStr: string;\n queryResult: {\n col: number;\n row: number;\n range?: VTable.TYPES.CellRange;\n value: string;\n }[];\n currentIndex: number;\n\n constructor(option: SearchComponentOption) {\n this.table = option.table;\n this.autoJump = option.autoJump || false;\n this.skipHeader = option.skipHeader || false;\n this.highlightCellStyle = option.highlightCellStyle || defalutHightlightCellStyle;\n this.focuseHighlightCellStyle = option.focuseHighlightCellStyle || defalutFocusHightlightCellStyle;\n this.queryMethod = option.queryMethod || defalultQueryMethod;\n this.callback = option.callback;\n\n this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle as any);\n this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle as any);\n }\n\n search(str: string) {\n this.clear();\n this.queryStr = str;\n\n if (!str) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n\n for (let row = 0; row < this.table.rowCount; row++) {\n for (let col = 0; col < this.table.colCount; col++) {\n if (this.skipHeader && this.table.isHeader(col, row)) {\n continue;\n }\n const value = this.table.getCellValue(col, row);\n if (this.queryMethod(this.queryStr, value, { col, row, table: this.table })) {\n // deal merge cell\n const mergeCell = this.table.getCellRange(col, row);\n if (mergeCell.start.col !== mergeCell.end.col || mergeCell.start.row !== mergeCell.end.row) {\n // find is cell already in queryResult\n let isIn = false;\n for (let i = this.queryResult.length - 1; i >= 0; i--) {\n if (this.queryResult[i].col === mergeCell.start.col && this.queryResult[i].row === mergeCell.start.row) {\n isIn = true;\n break;\n }\n }\n if (!isIn) {\n this.queryResult.push({\n col: mergeCell.start.col,\n row: mergeCell.start.row,\n range: mergeCell,\n value\n });\n }\n } else {\n this.queryResult.push({\n col,\n row,\n value\n });\n }\n }\n }\n }\n\n this.updateCellStyle();\n\n if (this.callback) {\n this.callback(\n {\n queryStr: this.queryStr,\n results: this.queryResult\n },\n this.table\n );\n }\n\n if (this.autoJump) {\n return this.next();\n }\n return {\n index: 0,\n results: this.queryResult\n };\n }\n\n updateCellStyle(highlight: boolean = true) {\n if (!this.queryResult) {\n return;\n }\n if (!this.table.hasCustomCellStyle('__search_component_highlight')) {\n this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle as any);\n }\n if (!this.table.hasCustomCellStyle('__search_component_focuse')) {\n this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle as any);\n }\n for (let i = 0; i < this.queryResult.length; i++) {\n const { col, row, range } = this.queryResult[i];\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n highlight ? '__search_component_highlight' : null\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n highlight ? '__search_component_highlight' : null\n );\n }\n }\n }\n\n next() {\n if (!this.queryResult.length) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n if (this.currentIndex !== -1) {\n // reset last focus\n const { col, row, range } = this.queryResult[this.currentIndex];\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_highlight'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n '__search_component_highlight'\n );\n }\n }\n this.currentIndex++;\n if (this.currentIndex >= this.queryResult.length) {\n this.currentIndex = 0;\n }\n const { col, row, range } = this.queryResult[this.currentIndex];\n // this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_focuse'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n '__search_component_focuse'\n );\n }\n\n this.jumpToCell(col, row);\n\n return {\n index: this.currentIndex,\n results: this.queryResult\n };\n }\n\n prev() {\n if (!this.queryResult.length) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n if (this.currentIndex !== -1) {\n // reset last focus\n // this.table.arrangeCustomCellStyle(\n // {\n // col: this.queryResult[this.currentIndex].col,\n // row: this.queryResult[this.currentIndex].row\n // },\n // '__search_component_highlight'\n // );\n const { col, row, range } = this.queryResult[this.currentIndex];\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_highlight'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n '__search_component_highlight'\n );\n }\n }\n this.currentIndex--;\n if (this.currentIndex < 0) {\n this.currentIndex = this.queryResult.length - 1;\n }\n const { col, row, range } = this.queryResult[this.currentIndex];\n // this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_focuse'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n '__search_component_focuse'\n );\n }\n\n this.jumpToCell(col, row);\n\n return {\n index: this.currentIndex,\n results: this.queryResult\n };\n }\n\n jumpToCell(col: number, row: number) {\n // if focus cell out of screen, jump to cell\n const { rowStart, rowEnd } = this.table.getBodyVisibleRowRange();\n const { colStart, colEnd } = this.table.getBodyVisibleColRange();\n if (row <= rowStart || row >= rowEnd || col <= colStart || col >= colEnd) {\n this.table.scrollToCell({ col, row });\n }\n }\n\n clear() {\n // reset highlight cell style\n this.updateCellStyle(null);\n this.queryStr = '';\n this.queryResult = [];\n this.currentIndex = -1;\n }\n}\n"]}
@@ -54,11 +54,31 @@
54
54
  }
55
55
  const value = this.table.getCellValue(col, row);
56
56
  if (this.queryMethod(this.queryStr, value, { col, row, table: this.table })) {
57
- this.queryResult.push({
58
- col,
59
- row,
60
- value
61
- });
57
+ const mergeCell = this.table.getCellRange(col, row);
58
+ if (mergeCell.start.col !== mergeCell.end.col || mergeCell.start.row !== mergeCell.end.row) {
59
+ let isIn = false;
60
+ for (let i = this.queryResult.length - 1; i >= 0; i--) {
61
+ if (this.queryResult[i].col === mergeCell.start.col && this.queryResult[i].row === mergeCell.start.row) {
62
+ isIn = true;
63
+ break;
64
+ }
65
+ }
66
+ if (!isIn) {
67
+ this.queryResult.push({
68
+ col: mergeCell.start.col,
69
+ row: mergeCell.start.row,
70
+ range: mergeCell,
71
+ value
72
+ });
73
+ }
74
+ }
75
+ else {
76
+ this.queryResult.push({
77
+ col,
78
+ row,
79
+ value
80
+ });
81
+ }
62
82
  }
63
83
  }
64
84
  }
@@ -88,11 +108,18 @@
88
108
  this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle);
89
109
  }
90
110
  for (let i = 0; i < this.queryResult.length; i++) {
91
- const { col, row } = this.queryResult[i];
92
- this.table.arrangeCustomCellStyle({
93
- col,
94
- row
95
- }, highlight ? '__search_component_highlight' : null);
111
+ const { col, row, range } = this.queryResult[i];
112
+ if (range) {
113
+ this.table.arrangeCustomCellStyle({
114
+ range
115
+ }, highlight ? '__search_component_highlight' : null);
116
+ }
117
+ else {
118
+ this.table.arrangeCustomCellStyle({
119
+ col,
120
+ row
121
+ }, highlight ? '__search_component_highlight' : null);
122
+ }
96
123
  }
97
124
  }
98
125
  next() {
@@ -103,17 +130,35 @@
103
130
  };
104
131
  }
105
132
  if (this.currentIndex !== -1) {
106
- this.table.arrangeCustomCellStyle({
107
- col: this.queryResult[this.currentIndex].col,
108
- row: this.queryResult[this.currentIndex].row
109
- }, '__search_component_highlight');
133
+ const { col, row, range } = this.queryResult[this.currentIndex];
134
+ if (range) {
135
+ this.table.arrangeCustomCellStyle({
136
+ range
137
+ }, '__search_component_highlight');
138
+ }
139
+ else {
140
+ this.table.arrangeCustomCellStyle({
141
+ col,
142
+ row
143
+ }, '__search_component_highlight');
144
+ }
110
145
  }
111
146
  this.currentIndex++;
112
147
  if (this.currentIndex >= this.queryResult.length) {
113
148
  this.currentIndex = 0;
114
149
  }
115
- const { col, row } = this.queryResult[this.currentIndex];
116
- this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');
150
+ const { col, row, range } = this.queryResult[this.currentIndex];
151
+ if (range) {
152
+ this.table.arrangeCustomCellStyle({
153
+ range
154
+ }, '__search_component_focuse');
155
+ }
156
+ else {
157
+ this.table.arrangeCustomCellStyle({
158
+ col,
159
+ row
160
+ }, '__search_component_focuse');
161
+ }
117
162
  this.jumpToCell(col, row);
118
163
  return {
119
164
  index: this.currentIndex,
@@ -128,17 +173,35 @@
128
173
  };
129
174
  }
130
175
  if (this.currentIndex !== -1) {
131
- this.table.arrangeCustomCellStyle({
132
- col: this.queryResult[this.currentIndex].col,
133
- row: this.queryResult[this.currentIndex].row
134
- }, '__search_component_highlight');
176
+ const { col, row, range } = this.queryResult[this.currentIndex];
177
+ if (range) {
178
+ this.table.arrangeCustomCellStyle({
179
+ range
180
+ }, '__search_component_highlight');
181
+ }
182
+ else {
183
+ this.table.arrangeCustomCellStyle({
184
+ col,
185
+ row
186
+ }, '__search_component_highlight');
187
+ }
135
188
  }
136
189
  this.currentIndex--;
137
190
  if (this.currentIndex < 0) {
138
191
  this.currentIndex = this.queryResult.length - 1;
139
192
  }
140
- const { col, row } = this.queryResult[this.currentIndex];
141
- this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');
193
+ const { col, row, range } = this.queryResult[this.currentIndex];
194
+ if (range) {
195
+ this.table.arrangeCustomCellStyle({
196
+ range
197
+ }, '__search_component_focuse');
198
+ }
199
+ else {
200
+ this.table.arrangeCustomCellStyle({
201
+ col,
202
+ row
203
+ }, '__search_component_focuse');
204
+ }
142
205
  this.jumpToCell(col, row);
143
206
  return {
144
207
  index: this.currentIndex,
@@ -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 l={bgColor:"rgba(255, 255, 0, 0.2)"},s={bgColor:"rgba(255, 155, 0, 0.2)"};function r(e,l){return t(e)&&t(l)&&l.toString().includes(e)}e.SearchComponent=class{table;skipHeader;autoJump;highlightCellStyle;focuseHighlightCellStyle;queryMethod;callback;queryStr;queryResult;currentIndex;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||s,this.queryMethod=e.queryMethod||r,this.callback=e.callback,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};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 l=this.table.getCellValue(t,e);this.queryMethod(this.queryStr,l,{col:t,row:e,table:this.table})&&this.queryResult.push({col:t,row:e,value:l})}return this.updateCellStyle(),this.callback&&this.callback({queryStr:this.queryStr,results:this.queryResult},this.table),this.autoJump?this.next():{index:0,results:this.queryResult}}updateCellStyle(e=!0){if(this.queryResult){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);for(let t=0;t<this.queryResult.length;t++){const{col:l,row:s}=this.queryResult[t];this.table.arrangeCustomCellStyle({col:l,row:s},e?"__search_component_highlight":null)}}}next(){if(!this.queryResult.length)return{index:0,results:this.queryResult};-1!==this.currentIndex&&this.table.arrangeCustomCellStyle({col:this.queryResult[this.currentIndex].col,row:this.queryResult[this.currentIndex].row},"__search_component_highlight"),this.currentIndex++,this.currentIndex>=this.queryResult.length&&(this.currentIndex=0);const{col:e,row:t}=this.queryResult[this.currentIndex];return this.table.arrangeCustomCellStyle({col:e,row:t},"__search_component_focuse"),this.jumpToCell(e,t),{index:this.currentIndex,results:this.queryResult}}prev(){if(!this.queryResult.length)return{index:0,results:this.queryResult};-1!==this.currentIndex&&this.table.arrangeCustomCellStyle({col:this.queryResult[this.currentIndex].col,row:this.queryResult[this.currentIndex].row},"__search_component_highlight"),this.currentIndex--,this.currentIndex<0&&(this.currentIndex=this.queryResult.length-1);const{col:e,row:t}=this.queryResult[this.currentIndex];return this.table.arrangeCustomCellStyle({col:e,row:t},"__search_component_focuse"),this.jumpToCell(e,t),{index:this.currentIndex,results:this.queryResult}}jumpToCell(e,t){const{rowStart:l,rowEnd:s}=this.table.getBodyVisibleRowRange(),{colStart:r,colEnd:i}=this.table.getBodyVisibleColRange();(t<=l||t>=s||e<=r||e>=i)&&this.table.scrollToCell({col:e,row:t})}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 l={bgColor:"rgba(255, 255, 0, 0.2)"},s={bgColor:"rgba(255, 155, 0, 0.2)"};function r(e,l){return t(e)&&t(l)&&l.toString().includes(e)}e.SearchComponent=class{table;skipHeader;autoJump;highlightCellStyle;focuseHighlightCellStyle;queryMethod;callback;queryStr;queryResult;currentIndex;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||s,this.queryMethod=e.queryMethod||r,this.callback=e.callback,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};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 l=this.table.getCellValue(t,e);if(this.queryMethod(this.queryStr,l,{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:l})}else this.queryResult.push({col:t,row:e,value:l})}}return this.updateCellStyle(),this.callback&&this.callback({queryStr:this.queryStr,results:this.queryResult},this.table),this.autoJump?this.next():{index:0,results:this.queryResult}}updateCellStyle(e=!0){if(this.queryResult){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);for(let t=0;t<this.queryResult.length;t++){const{col:l,row:s,range:r}=this.queryResult[t];r?this.table.arrangeCustomCellStyle({range:r},e?"__search_component_highlight":null):this.table.arrangeCustomCellStyle({col:l,row:s},e?"__search_component_highlight":null)}}}next(){if(!this.queryResult.length)return{index:0,results:this.queryResult};if(-1!==this.currentIndex){const{col:e,row:t,range:l}=this.queryResult[this.currentIndex];l?this.table.arrangeCustomCellStyle({range:l},"__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:l}=this.queryResult[this.currentIndex];return l?this.table.arrangeCustomCellStyle({range:l},"__search_component_focuse"):this.table.arrangeCustomCellStyle({col:e,row:t},"__search_component_focuse"),this.jumpToCell(e,t),{index:this.currentIndex,results:this.queryResult}}prev(){if(!this.queryResult.length)return{index:0,results:this.queryResult};if(-1!==this.currentIndex){const{col:e,row:t,range:l}=this.queryResult[this.currentIndex];l?this.table.arrangeCustomCellStyle({range:l},"__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:l}=this.queryResult[this.currentIndex];return l?this.table.arrangeCustomCellStyle({range:l},"__search_component_focuse"):this.table.arrangeCustomCellStyle({col:e,row:t},"__search_component_focuse"),this.jumpToCell(e,t),{index:this.currentIndex,results:this.queryResult}}jumpToCell(e,t){const{rowStart:l,rowEnd:s}=this.table.getBodyVisibleRowRange(),{colStart:r,colEnd:h}=this.table.getBodyVisibleColRange();(t<=l||t>=s||e<=r||e>=h)&&this.table.scrollToCell({col:e,row:t})}clear(){this.updateCellStyle(null),this.queryStr="",this.queryResult=[],this.currentIndex=-1}}}));
@@ -37,6 +37,7 @@ export declare class SearchComponent {
37
37
  queryResult: {
38
38
  col: number;
39
39
  row: number;
40
+ range?: VTable.TYPES.CellRange;
40
41
  value: string;
41
42
  }[];
42
43
  currentIndex: number;
@@ -46,6 +47,7 @@ export declare class SearchComponent {
46
47
  results: {
47
48
  col: number;
48
49
  row: number;
50
+ range?: VTable.TYPES.CellRange;
49
51
  value: string;
50
52
  }[];
51
53
  };
@@ -55,6 +57,7 @@ export declare class SearchComponent {
55
57
  results: {
56
58
  col: number;
57
59
  row: number;
60
+ range?: VTable.TYPES.CellRange;
58
61
  value: string;
59
62
  }[];
60
63
  };
@@ -63,6 +66,7 @@ export declare class SearchComponent {
63
66
  results: {
64
67
  col: number;
65
68
  row: number;
69
+ range?: VTable.TYPES.CellRange;
66
70
  value: string;
67
71
  }[];
68
72
  };
@@ -27,15 +27,30 @@ export class SearchComponent {
27
27
  for (let row = 0; row < this.table.rowCount; row++) for (let col = 0; col < this.table.colCount; col++) {
28
28
  if (this.skipHeader && this.table.isHeader(col, row)) continue;
29
29
  const value = this.table.getCellValue(col, row);
30
- this.queryMethod(this.queryStr, value, {
30
+ if (this.queryMethod(this.queryStr, value, {
31
31
  col: col,
32
32
  row: row,
33
33
  table: this.table
34
- }) && this.queryResult.push({
35
- col: col,
36
- row: row,
37
- value: value
38
- });
34
+ })) {
35
+ const mergeCell = this.table.getCellRange(col, row);
36
+ if (mergeCell.start.col !== mergeCell.end.col || mergeCell.start.row !== mergeCell.end.row) {
37
+ let isIn = !1;
38
+ for (let i = this.queryResult.length - 1; i >= 0; i--) if (this.queryResult[i].col === mergeCell.start.col && this.queryResult[i].row === mergeCell.start.row) {
39
+ isIn = !0;
40
+ break;
41
+ }
42
+ isIn || this.queryResult.push({
43
+ col: mergeCell.start.col,
44
+ row: mergeCell.start.row,
45
+ range: mergeCell,
46
+ value: value
47
+ });
48
+ } else this.queryResult.push({
49
+ col: col,
50
+ row: row,
51
+ value: value
52
+ });
53
+ }
39
54
  }
40
55
  return this.updateCellStyle(), this.callback && this.callback({
41
56
  queryStr: this.queryStr,
@@ -50,8 +65,10 @@ export class SearchComponent {
50
65
  this.table.hasCustomCellStyle("__search_component_highlight") || this.table.registerCustomCellStyle("__search_component_highlight", this.highlightCellStyle),
51
66
  this.table.hasCustomCellStyle("__search_component_focuse") || this.table.registerCustomCellStyle("__search_component_focuse", this.focuseHighlightCellStyle);
52
67
  for (let i = 0; i < this.queryResult.length; i++) {
53
- const {col: col, row: row} = this.queryResult[i];
54
- this.table.arrangeCustomCellStyle({
68
+ const {col: col, row: row, range: range} = this.queryResult[i];
69
+ range ? this.table.arrangeCustomCellStyle({
70
+ range: range
71
+ }, highlight ? "__search_component_highlight" : null) : this.table.arrangeCustomCellStyle({
55
72
  col: col,
56
73
  row: row
57
74
  }, highlight ? "__search_component_highlight" : null);
@@ -63,12 +80,20 @@ export class SearchComponent {
63
80
  index: 0,
64
81
  results: this.queryResult
65
82
  };
66
- -1 !== this.currentIndex && this.table.arrangeCustomCellStyle({
67
- col: this.queryResult[this.currentIndex].col,
68
- row: this.queryResult[this.currentIndex].row
69
- }, "__search_component_highlight"), this.currentIndex++, this.currentIndex >= this.queryResult.length && (this.currentIndex = 0);
70
- const {col: col, row: row} = this.queryResult[this.currentIndex];
71
- return this.table.arrangeCustomCellStyle({
83
+ if (-1 !== this.currentIndex) {
84
+ const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
85
+ range ? this.table.arrangeCustomCellStyle({
86
+ range: range
87
+ }, "__search_component_highlight") : this.table.arrangeCustomCellStyle({
88
+ col: col,
89
+ row: row
90
+ }, "__search_component_highlight");
91
+ }
92
+ this.currentIndex++, this.currentIndex >= this.queryResult.length && (this.currentIndex = 0);
93
+ const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
94
+ return range ? this.table.arrangeCustomCellStyle({
95
+ range: range
96
+ }, "__search_component_focuse") : this.table.arrangeCustomCellStyle({
72
97
  col: col,
73
98
  row: row
74
99
  }, "__search_component_focuse"), this.jumpToCell(col, row), {
@@ -81,12 +106,20 @@ export class SearchComponent {
81
106
  index: 0,
82
107
  results: this.queryResult
83
108
  };
84
- -1 !== this.currentIndex && this.table.arrangeCustomCellStyle({
85
- col: this.queryResult[this.currentIndex].col,
86
- row: this.queryResult[this.currentIndex].row
87
- }, "__search_component_highlight"), this.currentIndex--, this.currentIndex < 0 && (this.currentIndex = this.queryResult.length - 1);
88
- const {col: col, row: row} = this.queryResult[this.currentIndex];
89
- return this.table.arrangeCustomCellStyle({
109
+ if (-1 !== this.currentIndex) {
110
+ const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
111
+ range ? this.table.arrangeCustomCellStyle({
112
+ range: range
113
+ }, "__search_component_highlight") : this.table.arrangeCustomCellStyle({
114
+ col: col,
115
+ row: row
116
+ }, "__search_component_highlight");
117
+ }
118
+ this.currentIndex--, this.currentIndex < 0 && (this.currentIndex = this.queryResult.length - 1);
119
+ const {col: col, row: row, range: range} = this.queryResult[this.currentIndex];
120
+ return range ? this.table.arrangeCustomCellStyle({
121
+ range: range
122
+ }, "__search_component_focuse") : this.table.arrangeCustomCellStyle({
90
123
  col: col,
91
124
  row: row
92
125
  }, "__search_component_focuse"), this.jumpToCell(col, row), {
@@ -1 +1 @@
1
- {"version":3,"sources":["search-component/search-component.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAuB3C,MAAM,0BAA0B,GAAoC;IAClE,OAAO,EAAE,wBAAwB;CAClC,CAAC;AAEF,MAAM,+BAA+B,GAAoC;IACvE,OAAO,EAAE,wBAAwB;CAClC,CAAC;AAEF,SAAS,mBAAmB,CAAC,QAAgB,EAAE,KAAa;IAC1D,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACpF,CAAC;AAED,MAAM,OAAO,eAAe;IAiB1B,YAAY,MAA6B;QACvC,IAAI,CAAC,K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C,KAAK,CAAC,sBAAsB,EAAE,CAAC;QACjE,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG,IAAI,MAAM,EAAE;YACxE,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;SACvC;IACH,CAAC;IAED,KAAK;QAEH,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;IACzB,CAAC;CACF","file":"search-component.js","sourcesContent":["import type * as VTable from '@visactor/vtable';\nimport { isValid } from '@visactor/vutils';\n\ntype IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;\n\nexport type QueryResult = {\n queryStr: string;\n results: {\n col: number;\n row: number;\n value: string;\n }[];\n};\n\nexport type SearchComponentOption = {\n table: IVTable;\n autoJump?: boolean;\n skipHeader?: boolean;\n highlightCellStyle?: VTable.TYPES.CellStyle;\n focuseHighlightCellStyle?: VTable.TYPES.CellStyle;\n queryMethod?: (queryStr: string, value: string, option?: { col: number; row: number; table: IVTable }) => boolean;\n callback?: (queryResult: QueryResult, table: IVTable) => void;\n};\n\nconst defalutHightlightCellStyle: Partial<VTable.TYPES.CellStyle> = {\n bgColor: 'rgba(255, 255, 0, 0.2)'\n};\n\nconst defalutFocusHightlightCellStyle: Partial<VTable.TYPES.CellStyle> = {\n bgColor: 'rgba(255, 155, 0, 0.2)'\n};\n\nfunction defalultQueryMethod(queryStr: string, value: string) {\n return isValid(queryStr) && isValid(value) && value.toString().includes(queryStr);\n}\n\nexport class SearchComponent {\n table: IVTable;\n skipHeader: boolean;\n autoJump: boolean;\n highlightCellStyle: Partial<VTable.TYPES.CellStyle>;\n focuseHighlightCellStyle: Partial<VTable.TYPES.CellStyle>;\n queryMethod: (queryStr: string, value: string, option: { col: number; row: number; table: IVTable }) => boolean;\n callback?: (queryResult: QueryResult, table: IVTable) => void;\n\n queryStr: string;\n queryResult: {\n col: number;\n row: number;\n value: string;\n }[];\n currentIndex: number;\n\n constructor(option: SearchComponentOption) {\n this.table = option.table;\n this.autoJump = option.autoJump || false;\n this.skipHeader = option.skipHeader || false;\n this.highlightCellStyle = option.highlightCellStyle || defalutHightlightCellStyle;\n this.focuseHighlightCellStyle = option.focuseHighlightCellStyle || defalutFocusHightlightCellStyle;\n this.queryMethod = option.queryMethod || defalultQueryMethod;\n this.callback = option.callback;\n\n this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle as any);\n this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle as any);\n }\n\n search(str: string) {\n this.clear();\n this.queryStr = str;\n\n if (!str) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n\n for (let row = 0; row < this.table.rowCount; row++) {\n for (let col = 0; col < this.table.colCount; col++) {\n if (this.skipHeader && this.table.isHeader(col, row)) {\n continue;\n }\n const value = this.table.getCellValue(col, row);\n if (this.queryMethod(this.queryStr, value, { col, row, table: this.table })) {\n 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 updateCellStyle(highlight: boolean = true) {\n if (!this.queryResult) {\n return;\n }\n if (!this.table.hasCustomCellStyle('__search_component_highlight')) {\n this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle as any);\n }\n if (!this.table.hasCustomCellStyle('__search_component_focuse')) {\n this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle as any);\n }\n for (let i = 0; i < this.queryResult.length; i++) {\n const { col, row } = this.queryResult[i];\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n highlight ? '__search_component_highlight' : null\n );\n }\n }\n\n next() {\n if (!this.queryResult.length) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n if (this.currentIndex !== -1) {\n // reset last focus\n this.table.arrangeCustomCellStyle(\n {\n col: this.queryResult[this.currentIndex].col,\n row: this.queryResult[this.currentIndex].row\n },\n '__search_component_highlight'\n );\n }\n this.currentIndex++;\n if (this.currentIndex >= this.queryResult.length) {\n this.currentIndex = 0;\n }\n const { col, row } = this.queryResult[this.currentIndex];\n this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');\n\n this.jumpToCell(col, row);\n\n return {\n index: this.currentIndex,\n results: this.queryResult\n };\n }\n\n prev() {\n if (!this.queryResult.length) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n if (this.currentIndex !== -1) {\n // reset last focus\n this.table.arrangeCustomCellStyle(\n {\n col: this.queryResult[this.currentIndex].col,\n row: this.queryResult[this.currentIndex].row\n },\n '__search_component_highlight'\n );\n }\n this.currentIndex--;\n if (this.currentIndex < 0) {\n this.currentIndex = this.queryResult.length - 1;\n }\n const { col, row } = this.queryResult[this.currentIndex];\n this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');\n\n this.jumpToCell(col, row);\n\n return {\n index: this.currentIndex,\n results: this.queryResult\n };\n }\n\n jumpToCell(col: number, row: number) {\n // if focus cell out of screen, jump to cell\n const { rowStart, rowEnd } = this.table.getBodyVisibleRowRange();\n const { colStart, colEnd } = this.table.getBodyVisibleColRange();\n if (row <= rowStart || row >= rowEnd || col <= colStart || col >= colEnd) {\n this.table.scrollToCell({ col, row });\n }\n }\n\n clear() {\n // reset highlight cell style\n this.updateCellStyle(null);\n this.queryStr = '';\n this.queryResult = [];\n this.currentIndex = -1;\n }\n}\n"]}
1
+ {"version":3,"sources":["search-component/search-component.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAuB3C,MAAM,0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Table from '@visactor/vtable';\nimport { isValid } from '@visactor/vutils';\n\ntype IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;\n\nexport type QueryResult = {\n queryStr: string;\n results: {\n col: number;\n row: number;\n value: string;\n }[];\n};\n\nexport type SearchComponentOption = {\n table: IVTable;\n autoJump?: boolean;\n skipHeader?: boolean;\n highlightCellStyle?: VTable.TYPES.CellStyle;\n focuseHighlightCellStyle?: VTable.TYPES.CellStyle;\n queryMethod?: (queryStr: string, value: string, option?: { col: number; row: number; table: IVTable }) => boolean;\n callback?: (queryResult: QueryResult, table: IVTable) => void;\n};\n\nconst defalutHightlightCellStyle: Partial<VTable.TYPES.CellStyle> = {\n bgColor: 'rgba(255, 255, 0, 0.2)'\n};\n\nconst defalutFocusHightlightCellStyle: Partial<VTable.TYPES.CellStyle> = {\n bgColor: 'rgba(255, 155, 0, 0.2)'\n};\n\nfunction defalultQueryMethod(queryStr: string, value: string) {\n return isValid(queryStr) && isValid(value) && value.toString().includes(queryStr);\n}\n\nexport class SearchComponent {\n table: IVTable;\n skipHeader: boolean;\n autoJump: boolean;\n highlightCellStyle: Partial<VTable.TYPES.CellStyle>;\n focuseHighlightCellStyle: Partial<VTable.TYPES.CellStyle>;\n queryMethod: (queryStr: string, value: string, option: { col: number; row: number; table: IVTable }) => boolean;\n callback?: (queryResult: QueryResult, table: IVTable) => void;\n\n queryStr: string;\n queryResult: {\n col: number;\n row: number;\n range?: VTable.TYPES.CellRange;\n value: string;\n }[];\n currentIndex: number;\n\n constructor(option: SearchComponentOption) {\n this.table = option.table;\n this.autoJump = option.autoJump || false;\n this.skipHeader = option.skipHeader || false;\n this.highlightCellStyle = option.highlightCellStyle || defalutHightlightCellStyle;\n this.focuseHighlightCellStyle = option.focuseHighlightCellStyle || defalutFocusHightlightCellStyle;\n this.queryMethod = option.queryMethod || defalultQueryMethod;\n this.callback = option.callback;\n\n this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle as any);\n this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle as any);\n }\n\n search(str: string) {\n this.clear();\n this.queryStr = str;\n\n if (!str) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n\n for (let row = 0; row < this.table.rowCount; row++) {\n for (let col = 0; col < this.table.colCount; col++) {\n if (this.skipHeader && this.table.isHeader(col, row)) {\n continue;\n }\n const value = this.table.getCellValue(col, row);\n if (this.queryMethod(this.queryStr, value, { col, row, table: this.table })) {\n // deal merge cell\n const mergeCell = this.table.getCellRange(col, row);\n if (mergeCell.start.col !== mergeCell.end.col || mergeCell.start.row !== mergeCell.end.row) {\n // find is cell already in queryResult\n let isIn = false;\n for (let i = this.queryResult.length - 1; i >= 0; i--) {\n if (this.queryResult[i].col === mergeCell.start.col && this.queryResult[i].row === mergeCell.start.row) {\n isIn = true;\n break;\n }\n }\n if (!isIn) {\n this.queryResult.push({\n col: mergeCell.start.col,\n row: mergeCell.start.row,\n range: mergeCell,\n value\n });\n }\n } else {\n this.queryResult.push({\n col,\n row,\n value\n });\n }\n }\n }\n }\n\n this.updateCellStyle();\n\n if (this.callback) {\n this.callback(\n {\n queryStr: this.queryStr,\n results: this.queryResult\n },\n this.table\n );\n }\n\n if (this.autoJump) {\n return this.next();\n }\n return {\n index: 0,\n results: this.queryResult\n };\n }\n\n updateCellStyle(highlight: boolean = true) {\n if (!this.queryResult) {\n return;\n }\n if (!this.table.hasCustomCellStyle('__search_component_highlight')) {\n this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle as any);\n }\n if (!this.table.hasCustomCellStyle('__search_component_focuse')) {\n this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle as any);\n }\n for (let i = 0; i < this.queryResult.length; i++) {\n const { col, row, range } = this.queryResult[i];\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n highlight ? '__search_component_highlight' : null\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n highlight ? '__search_component_highlight' : null\n );\n }\n }\n }\n\n next() {\n if (!this.queryResult.length) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n if (this.currentIndex !== -1) {\n // reset last focus\n const { col, row, range } = this.queryResult[this.currentIndex];\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_highlight'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n '__search_component_highlight'\n );\n }\n }\n this.currentIndex++;\n if (this.currentIndex >= this.queryResult.length) {\n this.currentIndex = 0;\n }\n const { col, row, range } = this.queryResult[this.currentIndex];\n // this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_focuse'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n '__search_component_focuse'\n );\n }\n\n this.jumpToCell(col, row);\n\n return {\n index: this.currentIndex,\n results: this.queryResult\n };\n }\n\n prev() {\n if (!this.queryResult.length) {\n return {\n index: 0,\n results: this.queryResult\n };\n }\n if (this.currentIndex !== -1) {\n // reset last focus\n // this.table.arrangeCustomCellStyle(\n // {\n // col: this.queryResult[this.currentIndex].col,\n // row: this.queryResult[this.currentIndex].row\n // },\n // '__search_component_highlight'\n // );\n const { col, row, range } = this.queryResult[this.currentIndex];\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_highlight'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n '__search_component_highlight'\n );\n }\n }\n this.currentIndex--;\n if (this.currentIndex < 0) {\n this.currentIndex = this.queryResult.length - 1;\n }\n const { col, row, range } = this.queryResult[this.currentIndex];\n // this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');\n if (range) {\n this.table.arrangeCustomCellStyle(\n {\n range\n },\n '__search_component_focuse'\n );\n } else {\n this.table.arrangeCustomCellStyle(\n {\n col,\n row\n },\n '__search_component_focuse'\n );\n }\n\n this.jumpToCell(col, row);\n\n return {\n index: this.currentIndex,\n results: this.queryResult\n };\n }\n\n jumpToCell(col: number, row: number) {\n // if focus cell out of screen, jump to cell\n const { rowStart, rowEnd } = this.table.getBodyVisibleRowRange();\n const { colStart, colEnd } = this.table.getBodyVisibleColRange();\n if (row <= rowStart || row >= rowEnd || col <= colStart || col >= colEnd) {\n this.table.scrollToCell({ col, row });\n }\n }\n\n clear() {\n // reset highlight cell style\n this.updateCellStyle(null);\n this.queryStr = '';\n this.queryResult = [];\n this.currentIndex = -1;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visactor/vtable-search",
3
- "version": "1.16.0-alpha.0",
3
+ "version": "1.16.0",
4
4
  "description": "The search util of VTable",
5
5
  "author": {
6
6
  "name": "VisActor",
@@ -30,8 +30,8 @@
30
30
  "access": "public"
31
31
  },
32
32
  "dependencies": {
33
- "@visactor/vtable": "1.16.0-alpha.0",
34
- "@visactor/vutils": "~0.19.1"
33
+ "@visactor/vutils": "~0.19.1",
34
+ "@visactor/vtable": "1.16.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@visactor/vchart": "1.13.3-alpha.2",
@@ -75,8 +75,8 @@
75
75
  "axios": "^1.4.0",
76
76
  "@types/react-is": "^17.0.3",
77
77
  "rollup-plugin-node-resolve": "5.2.0",
78
- "@internal/eslint-config": "0.0.1",
79
78
  "@internal/bundler": "0.0.1",
79
+ "@internal/eslint-config": "0.0.1",
80
80
  "@internal/ts-config": "0.0.1"
81
81
  },
82
82
  "scripts": {