@visactor/vtable-search 0.23.2 → 0.23.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/search-component/search-component.js +2 -2
- package/cjs/search-component/search-component.js.map +1 -1
- package/dist/vtable-export.js +4 -1
- package/dist/vtable-export.min.js +1 -1
- package/es/search-component/search-component.js +3 -1
- package/es/search-component/search-component.js.map +1 -1
- package/package.json +4 -4
|
@@ -4,14 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
}), exports.SearchComponent = void 0;
|
|
6
6
|
|
|
7
|
-
const defalutHightlightCellStyle = {
|
|
7
|
+
const vutils_1 = require("@visactor/vutils"), defalutHightlightCellStyle = {
|
|
8
8
|
bgColor: "rgba(255, 255, 0, 0.2)"
|
|
9
9
|
}, defalutFocusHightlightCellStyle = {
|
|
10
10
|
bgColor: "rgba(255, 155, 0, 0.2)"
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
function defalultQueryMethod(queryStr, value) {
|
|
14
|
-
return value.toString().includes(queryStr);
|
|
14
|
+
return (0, vutils_1.isValid)(queryStr) && (0, vutils_1.isValid)(value) && value.toString().includes(queryStr);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
class SearchComponent {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["search-component/search-component.ts"],"names":[],"mappings":";;;AAuBA,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,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC7C,CAAC;AAED,MAAa,eAAe;IAiB1B,YAAY,MAA6B;QACvC,IAAI,CAAC,KAAK,GAAG,MA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,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;IACzB,CAAC;CACF;AA9KD,0CA8KC","file":"search-component.js","sourcesContent":["import type * as VTable from '@visactor/vtable';\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 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 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,6CAA2C;AAuB3C,MAAM,0BAA0B,GAAoC;IAClE,OAAO,EAAE,wBAAwB;CAClC,CAAC;AAEF,MAAM,+BAA+B,GAAoC;IACvE,OAAO,EAAE,wBAAwB;CAClC,CAAC;AAEF,SAAS,mBAAmB,CAAC,QAAgB,EAAE,KAAa;IAC1D,OAAO,IAAA,gBAAO,EAAC,QAAQ,CAAC,IAAI,IAAA,gBAAO,EAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACpF,CAAC;AAED,MAAa,eAAe;IAiB1B,YAAY,MAA6B;QACvC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,KAAK,CAAC;QACzC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,KAAK,CAAC;QAC7C,IAAI,CAAC,kBAAkB,GAAG,MAAM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AAC,YAAY,GAAG,CAAC,EAAE;YACzB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC;SACjD;QACD,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACzD,IAAI,CAAC,KAAK,CAAC,sBAAsB,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,2BAA2B,CAAC,CAAC;QAE7E,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAE1B,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,YAAY;YACxB,OAAO,EAAE,IAAI,CAAC,WAAW;SAC1B,CAAC;IACJ,CAAC;IAED,UAAU,CAAC,GAAW,EAAE,GAAW;QAEjC,MAAM,EAAE,QAAQ,EAAE,MAAM,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;AA9KD,0CA8KC","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 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"]}
|
package/dist/vtable-export.js
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.VTable = global.VTable || {}, global.VTable.export = {})));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
+
const isValid = value => null != value;
|
|
8
|
+
var isValid$1 = isValid;
|
|
9
|
+
|
|
7
10
|
const defalutHightlightCellStyle = {
|
|
8
11
|
bgColor: 'rgba(255, 255, 0, 0.2)'
|
|
9
12
|
};
|
|
@@ -11,7 +14,7 @@
|
|
|
11
14
|
bgColor: 'rgba(255, 155, 0, 0.2)'
|
|
12
15
|
};
|
|
13
16
|
function defalultQueryMethod(queryStr, value) {
|
|
14
|
-
return value.toString().includes(queryStr);
|
|
17
|
+
return isValid$1(queryStr) && isValid$1(value) && value.toString().includes(queryStr);
|
|
15
18
|
}
|
|
16
19
|
class SearchComponent {
|
|
17
20
|
table;
|
|
@@ -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";
|
|
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)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,3 +1,5 @@
|
|
|
1
|
+
import { isValid } from "@visactor/vutils";
|
|
2
|
+
|
|
1
3
|
const defalutHightlightCellStyle = {
|
|
2
4
|
bgColor: "rgba(255, 255, 0, 0.2)"
|
|
3
5
|
}, defalutFocusHightlightCellStyle = {
|
|
@@ -5,7 +7,7 @@ const defalutHightlightCellStyle = {
|
|
|
5
7
|
};
|
|
6
8
|
|
|
7
9
|
function defalultQueryMethod(queryStr, value) {
|
|
8
|
-
return value.toString().includes(queryStr);
|
|
10
|
+
return isValid(queryStr) && isValid(value) && value.toString().includes(queryStr);
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
export class SearchComponent {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["search-component/search-component.ts"],"names":[],"mappings":"AAuBA,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,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AAE,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';\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 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 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,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,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1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AAC;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 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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visactor/vtable-search",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.4",
|
|
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.18.1",
|
|
34
|
-
"@visactor/vtable": "0.23.
|
|
34
|
+
"@visactor/vtable": "0.23.4"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@visactor/vchart": "1.10.0",
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
"@types/react-is": "^17.0.3",
|
|
77
77
|
"rollup-plugin-node-resolve": "5.2.0",
|
|
78
78
|
"@internal/bundler": "0.0.1",
|
|
79
|
-
"@internal/
|
|
80
|
-
"@internal/
|
|
79
|
+
"@internal/ts-config": "0.0.1",
|
|
80
|
+
"@internal/eslint-config": "0.0.1"
|
|
81
81
|
},
|
|
82
82
|
"scripts": {
|
|
83
83
|
"start": "vite ./demo",
|