@visactor/vtable-search 0.20.4-alpha.3

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/README.md ADDED
@@ -0,0 +1,97 @@
1
+ <div align="center">
2
+ <a href="" target="_blank">
3
+ <img alt="VisActor Logo" width="200" src="https://github.com/VisActor/.github/blob/main/profile/500_200.svg"/>
4
+ </a>
5
+ </div>
6
+
7
+ <div align="center">
8
+ <h1>VTable-Export</h1>
9
+ </div>
10
+
11
+ <div align="center">
12
+
13
+ VTable is not just a high-performance multidimensional data analysis table, but also a grid artist that creates art between rows and columns.React-VTable is a React wrapper of VTable.
14
+
15
+ [![npm Version](https://img.shields.io/npm/v/@visactor/vtable.svg)](https://www.npmjs.com/package/@visactor/react-vtable)
16
+ [![npm Download](https://img.shields.io/npm/dm/@visactor/vtable.svg)](https://www.npmjs.com/package/@visactor/react-vvtable)
17
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/visactor/vtable/blob/main/LICENSE)
18
+
19
+ </div>
20
+
21
+ # Usage
22
+
23
+ ## Installation
24
+
25
+ [npm package](https://www.npmjs.com/package/@visactor/vtable-export)
26
+
27
+ ```bash
28
+ // npm
29
+ npm install @visactor/vtable-export
30
+
31
+ // yarn
32
+ yarn add @visactor/vtable-export
33
+ ```
34
+
35
+ ## Quick Start
36
+
37
+ ```jsx
38
+ import * as VTable from '@visactor/vtable';
39
+ import { downloadCsv, exportVTableToCsv, downloadExcel, exportVTableToExcel } from '@visactor/vtable-export';
40
+
41
+ const option = {
42
+ header: [
43
+ {
44
+ field: "0",
45
+ caption: "name",
46
+ },
47
+ {
48
+ field: "1",
49
+ caption: "age",
50
+ },
51
+ {
52
+ field: "2",
53
+ caption: "gender",
54
+ },
55
+ {
56
+ field: "3",
57
+ caption: "hobby",
58
+ },
59
+ ],
60
+ records: new Array(1000).fill(["John", 18, "male", "🏀"]),
61
+ };
62
+
63
+ const tableInstance = new VTable.ListTable(option);
64
+
65
+ // donload csv file
66
+ downloadCsv(exportVTableToCsv(tableInstance), 'export-csv');
67
+
68
+ // donload excel file
69
+ downloadExcel(await exportVTableToExcel(tableInstance), 'export-excel');
70
+
71
+ ```
72
+
73
+ ##
74
+
75
+ [More demos and detailed tutorials](https://visactor.io/vtable)
76
+
77
+ # Related Links
78
+
79
+ - [Official website](https://visactor.io/vtable)
80
+
81
+ # Ecosystem
82
+
83
+ | Project | Description |
84
+ | ----------------------------------------------------------- | -------------------------------------------------------------------------------------- |
85
+ | [AI-generated Components](https://visactor.io/ai-vtable) | AI-generated table component. |
86
+
87
+ # Contribution
88
+
89
+ If you would like to contribute, please read the [Code of Conduct ](./CODE_OF_CONDUCT.md) 和 [ Guide](./CONTRIBUTING.zh-CN.md) first。
90
+
91
+ Small streams converge to make great rivers and seas!
92
+
93
+ <a href="https://github.com/visactor/vtable/graphs/contributors"><img src="https://contrib.rocks/image?repo=visactor/vtable" /></a>
94
+
95
+ # License
96
+
97
+ [MIT License](./LICENSE)
package/cjs/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './search-component';
package/cjs/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
4
+ void 0 === k2 && (k2 = k);
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = {
7
+ enumerable: !0,
8
+ get: function() {
9
+ return m[k];
10
+ }
11
+ }), Object.defineProperty(o, k2, desc);
12
+ } : function(o, m, k, k2) {
13
+ void 0 === k2 && (k2 = k), o[k2] = m[k];
14
+ }), __exportStar = this && this.__exportStar || function(m, exports) {
15
+ for (var p in m) "default" === p || Object.prototype.hasOwnProperty.call(exports, p) || __createBinding(exports, m, p);
16
+ };
17
+
18
+ Object.defineProperty(exports, "__esModule", {
19
+ value: !0
20
+ }), __exportStar(require("./search-component"), exports);
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC","file":"index.js","sourcesContent":["export * from './search-component';\n"]}
@@ -0,0 +1 @@
1
+ export * from './search-component';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
4
+ void 0 === k2 && (k2 = k);
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = {
7
+ enumerable: !0,
8
+ get: function() {
9
+ return m[k];
10
+ }
11
+ }), Object.defineProperty(o, k2, desc);
12
+ } : function(o, m, k, k2) {
13
+ void 0 === k2 && (k2 = k), o[k2] = m[k];
14
+ }), __exportStar = this && this.__exportStar || function(m, exports) {
15
+ for (var p in m) "default" === p || Object.prototype.hasOwnProperty.call(exports, p) || __createBinding(exports, m, p);
16
+ };
17
+
18
+ Object.defineProperty(exports, "__esModule", {
19
+ value: !0
20
+ }), __exportStar(require("./search-component"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["search-component/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC","file":"index.js","sourcesContent":["export * from './search-component';\n"]}
@@ -0,0 +1,72 @@
1
+ import type * as VTable from '@visactor/vtable';
2
+ type IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;
3
+ export type QueryResult = {
4
+ queryStr: string;
5
+ results: {
6
+ col: number;
7
+ row: number;
8
+ value: string;
9
+ }[];
10
+ };
11
+ export type SearchComponentOption = {
12
+ table: IVTable;
13
+ autoJump?: boolean;
14
+ skipHeader?: boolean;
15
+ highlightCellStyle?: VTable.TYPES.CellStyle;
16
+ focuseHighlightCellStyle?: VTable.TYPES.CellStyle;
17
+ queryMethod?: (queryStr: string, value: string, option?: {
18
+ col: number;
19
+ row: number;
20
+ table: IVTable;
21
+ }) => boolean;
22
+ callback?: (queryResult: QueryResult, table: IVTable) => void;
23
+ };
24
+ export declare class SearchComponent {
25
+ table: IVTable;
26
+ skipHeader: boolean;
27
+ autoJump: boolean;
28
+ highlightCellStyle: Partial<VTable.TYPES.CellStyle>;
29
+ focuseHighlightCellStyle: Partial<VTable.TYPES.CellStyle>;
30
+ queryMethod: (queryStr: string, value: string, option: {
31
+ col: number;
32
+ row: number;
33
+ table: IVTable;
34
+ }) => boolean;
35
+ callback?: (queryResult: QueryResult, table: IVTable) => void;
36
+ queryStr: string;
37
+ queryResult: {
38
+ col: number;
39
+ row: number;
40
+ value: string;
41
+ }[];
42
+ currentIndex: number;
43
+ constructor(option: SearchComponentOption);
44
+ search(str: string): {
45
+ index: number;
46
+ results: {
47
+ col: number;
48
+ row: number;
49
+ value: string;
50
+ }[];
51
+ };
52
+ updateCellStyle(highlight?: boolean): void;
53
+ next(): {
54
+ index: number;
55
+ results: {
56
+ col: number;
57
+ row: number;
58
+ value: string;
59
+ }[];
60
+ };
61
+ prev(): {
62
+ index: number;
63
+ results: {
64
+ col: number;
65
+ row: number;
66
+ value: string;
67
+ }[];
68
+ };
69
+ jumpToCell(col: number, row: number): void;
70
+ clear(): void;
71
+ }
72
+ export {};
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.SearchComponent = void 0;
6
+
7
+ const defalutHightlightCellStyle = {
8
+ bgColor: "rgba(255, 255, 0, 0.2)"
9
+ }, defalutFocusHightlightCellStyle = {
10
+ bgColor: "rgba(255, 155, 0, 0.2)"
11
+ };
12
+
13
+ function defalultQueryMethod(queryStr, value) {
14
+ return value.toString().includes(queryStr);
15
+ }
16
+
17
+ class SearchComponent {
18
+ constructor(option) {
19
+ this.table = option.table, this.autoJump = option.autoJump || !1, this.skipHeader = option.skipHeader || !1,
20
+ this.highlightCellStyle = option.highlightCellStyle || defalutHightlightCellStyle,
21
+ this.focuseHighlightCellStyle = option.focuseHighlightCellStyle || defalutFocusHightlightCellStyle,
22
+ this.queryMethod = option.queryMethod || defalultQueryMethod, this.callback = option.callback,
23
+ this.table.registerCustomCellStyle("__search_component_highlight", this.highlightCellStyle),
24
+ this.table.registerCustomCellStyle("__search_component_focuse", this.focuseHighlightCellStyle);
25
+ }
26
+ search(str) {
27
+ if (this.clear(), this.queryStr = str, !str) return {
28
+ index: 0,
29
+ results: this.queryResult
30
+ };
31
+ for (let row = 0; row < this.table.rowCount; row++) for (let col = 0; col < this.table.colCount; col++) {
32
+ if (this.skipHeader && this.table.isHeader(col, row)) continue;
33
+ const value = this.table.getCellValue(col, row);
34
+ this.queryMethod(this.queryStr, value, {
35
+ col: col,
36
+ row: row,
37
+ table: this.table
38
+ }) && this.queryResult.push({
39
+ col: col,
40
+ row: row,
41
+ value: value
42
+ });
43
+ }
44
+ return this.updateCellStyle(), this.callback && this.callback({
45
+ queryStr: this.queryStr,
46
+ results: this.queryResult
47
+ }, this.table), this.autoJump ? this.next() : {
48
+ index: 0,
49
+ results: this.queryResult
50
+ };
51
+ }
52
+ updateCellStyle(highlight = !0) {
53
+ if (this.queryResult) for (let i = 0; i < this.queryResult.length; i++) {
54
+ const {col: col, row: row} = this.queryResult[i];
55
+ this.table.arrangeCustomCellStyle({
56
+ col: col,
57
+ row: row
58
+ }, highlight ? "__search_component_highlight" : null);
59
+ }
60
+ }
61
+ next() {
62
+ if (!this.queryResult.length) return {
63
+ index: 0,
64
+ results: this.queryResult
65
+ };
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({
72
+ col: col,
73
+ row: row
74
+ }, "__search_component_focuse"), this.jumpToCell(col, row), {
75
+ index: this.currentIndex,
76
+ results: this.queryResult
77
+ };
78
+ }
79
+ prev() {
80
+ if (!this.queryResult.length) return {
81
+ index: 0,
82
+ results: this.queryResult
83
+ };
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({
90
+ col: col,
91
+ row: row
92
+ }, "__search_component_focuse"), this.jumpToCell(col, row), {
93
+ index: this.currentIndex,
94
+ results: this.queryResult
95
+ };
96
+ }
97
+ jumpToCell(col, row) {
98
+ const {rowStart: rowStart, rowEnd: rowEnd} = this.table.getBodyVisibleRowRange(), {colStart: colStart, colEnd: colEnd} = this.table.getBodyVisibleColRange();
99
+ (row <= rowStart || row >= rowEnd || col <= colStart || col >= colEnd) && this.table.scrollToCell({
100
+ col: col,
101
+ row: row
102
+ });
103
+ }
104
+ clear() {
105
+ this.updateCellStyle(null), this.queryStr = "", this.queryResult = [], this.currentIndex = -1;
106
+ }
107
+ }
108
+
109
+ exports.SearchComponent = SearchComponent;
110
+ //# sourceMappingURL=search-component.js.map
@@ -0,0 +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,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,C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,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"]}
@@ -0,0 +1,156 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.VTable = global.VTable || {}, global.VTable.export = {})));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ const defalutHightlightCellStyle = {
8
+ bgColor: 'rgba(255, 255, 0, 0.2)'
9
+ };
10
+ const defalutFocusHightlightCellStyle = {
11
+ bgColor: 'rgba(255, 155, 0, 0.2)'
12
+ };
13
+ function defalultQueryMethod(queryStr, value) {
14
+ return value.toString().includes(queryStr);
15
+ }
16
+ class SearchComponent {
17
+ table;
18
+ skipHeader;
19
+ autoJump;
20
+ highlightCellStyle;
21
+ focuseHighlightCellStyle;
22
+ queryMethod;
23
+ callback;
24
+ queryStr;
25
+ queryResult;
26
+ currentIndex;
27
+ constructor(option) {
28
+ this.table = option.table;
29
+ this.autoJump = option.autoJump || false;
30
+ this.skipHeader = option.skipHeader || false;
31
+ this.highlightCellStyle = option.highlightCellStyle || defalutHightlightCellStyle;
32
+ this.focuseHighlightCellStyle = option.focuseHighlightCellStyle || defalutFocusHightlightCellStyle;
33
+ this.queryMethod = option.queryMethod || defalultQueryMethod;
34
+ this.callback = option.callback;
35
+ this.table.registerCustomCellStyle('__search_component_highlight', this.highlightCellStyle);
36
+ this.table.registerCustomCellStyle('__search_component_focuse', this.focuseHighlightCellStyle);
37
+ }
38
+ search(str) {
39
+ this.clear();
40
+ this.queryStr = str;
41
+ if (!str) {
42
+ return {
43
+ index: 0,
44
+ results: this.queryResult
45
+ };
46
+ }
47
+ for (let row = 0; row < this.table.rowCount; row++) {
48
+ for (let col = 0; col < this.table.colCount; col++) {
49
+ if (this.skipHeader && this.table.isHeader(col, row)) {
50
+ continue;
51
+ }
52
+ const value = this.table.getCellValue(col, row);
53
+ if (this.queryMethod(this.queryStr, value, { col, row, table: this.table })) {
54
+ this.queryResult.push({
55
+ col,
56
+ row,
57
+ value
58
+ });
59
+ }
60
+ }
61
+ }
62
+ this.updateCellStyle();
63
+ if (this.callback) {
64
+ this.callback({
65
+ queryStr: this.queryStr,
66
+ results: this.queryResult
67
+ }, this.table);
68
+ }
69
+ if (this.autoJump) {
70
+ return this.next();
71
+ }
72
+ return {
73
+ index: 0,
74
+ results: this.queryResult
75
+ };
76
+ }
77
+ updateCellStyle(highlight = true) {
78
+ if (!this.queryResult) {
79
+ return;
80
+ }
81
+ for (let i = 0; i < this.queryResult.length; i++) {
82
+ const { col, row } = this.queryResult[i];
83
+ this.table.arrangeCustomCellStyle({
84
+ col,
85
+ row
86
+ }, highlight ? '__search_component_highlight' : null);
87
+ }
88
+ }
89
+ next() {
90
+ if (!this.queryResult.length) {
91
+ return {
92
+ index: 0,
93
+ results: this.queryResult
94
+ };
95
+ }
96
+ if (this.currentIndex !== -1) {
97
+ this.table.arrangeCustomCellStyle({
98
+ col: this.queryResult[this.currentIndex].col,
99
+ row: this.queryResult[this.currentIndex].row
100
+ }, '__search_component_highlight');
101
+ }
102
+ this.currentIndex++;
103
+ if (this.currentIndex >= this.queryResult.length) {
104
+ this.currentIndex = 0;
105
+ }
106
+ const { col, row } = this.queryResult[this.currentIndex];
107
+ this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');
108
+ this.jumpToCell(col, row);
109
+ return {
110
+ index: this.currentIndex,
111
+ results: this.queryResult
112
+ };
113
+ }
114
+ prev() {
115
+ if (!this.queryResult.length) {
116
+ return {
117
+ index: 0,
118
+ results: this.queryResult
119
+ };
120
+ }
121
+ if (this.currentIndex !== -1) {
122
+ this.table.arrangeCustomCellStyle({
123
+ col: this.queryResult[this.currentIndex].col,
124
+ row: this.queryResult[this.currentIndex].row
125
+ }, '__search_component_highlight');
126
+ }
127
+ this.currentIndex--;
128
+ if (this.currentIndex < 0) {
129
+ this.currentIndex = this.queryResult.length - 1;
130
+ }
131
+ const { col, row } = this.queryResult[this.currentIndex];
132
+ this.table.arrangeCustomCellStyle({ col, row }, '__search_component_focuse');
133
+ this.jumpToCell(col, row);
134
+ return {
135
+ index: this.currentIndex,
136
+ results: this.queryResult
137
+ };
138
+ }
139
+ jumpToCell(col, row) {
140
+ const { rowStart, rowEnd } = this.table.getBodyVisibleRowRange();
141
+ const { colStart, colEnd } = this.table.getBodyVisibleColRange();
142
+ if (row <= rowStart || row >= rowEnd || col <= colStart || col >= colEnd) {
143
+ this.table.scrollToCell({ col, row });
144
+ }
145
+ }
146
+ clear() {
147
+ this.updateCellStyle(null);
148
+ this.queryStr = '';
149
+ this.queryResult = [];
150
+ this.currentIndex = -1;
151
+ }
152
+ }
153
+
154
+ exports.SearchComponent = SearchComponent;
155
+
156
+ }));
@@ -0,0 +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";const t={bgColor:"rgba(255, 255, 0, 0.2)"},l={bgColor:"rgba(255, 155, 0, 0.2)"};function s(e,t){return t.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||t,this.focuseHighlightCellStyle=e.focuseHighlightCellStyle||l,this.queryMethod=e.queryMethod||s,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}}}));
package/es/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './search-component';
package/es/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./search-component";
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC","file":"index.js","sourcesContent":["export * from './search-component';\n"]}
@@ -0,0 +1 @@
1
+ export * from './search-component';
@@ -0,0 +1,2 @@
1
+ export * from "./search-component";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["search-component/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC","file":"index.js","sourcesContent":["export * from './search-component';\n"]}
@@ -0,0 +1,72 @@
1
+ import type * as VTable from '@visactor/vtable';
2
+ type IVTable = VTable.ListTable | VTable.PivotTable | VTable.PivotChart;
3
+ export type QueryResult = {
4
+ queryStr: string;
5
+ results: {
6
+ col: number;
7
+ row: number;
8
+ value: string;
9
+ }[];
10
+ };
11
+ export type SearchComponentOption = {
12
+ table: IVTable;
13
+ autoJump?: boolean;
14
+ skipHeader?: boolean;
15
+ highlightCellStyle?: VTable.TYPES.CellStyle;
16
+ focuseHighlightCellStyle?: VTable.TYPES.CellStyle;
17
+ queryMethod?: (queryStr: string, value: string, option?: {
18
+ col: number;
19
+ row: number;
20
+ table: IVTable;
21
+ }) => boolean;
22
+ callback?: (queryResult: QueryResult, table: IVTable) => void;
23
+ };
24
+ export declare class SearchComponent {
25
+ table: IVTable;
26
+ skipHeader: boolean;
27
+ autoJump: boolean;
28
+ highlightCellStyle: Partial<VTable.TYPES.CellStyle>;
29
+ focuseHighlightCellStyle: Partial<VTable.TYPES.CellStyle>;
30
+ queryMethod: (queryStr: string, value: string, option: {
31
+ col: number;
32
+ row: number;
33
+ table: IVTable;
34
+ }) => boolean;
35
+ callback?: (queryResult: QueryResult, table: IVTable) => void;
36
+ queryStr: string;
37
+ queryResult: {
38
+ col: number;
39
+ row: number;
40
+ value: string;
41
+ }[];
42
+ currentIndex: number;
43
+ constructor(option: SearchComponentOption);
44
+ search(str: string): {
45
+ index: number;
46
+ results: {
47
+ col: number;
48
+ row: number;
49
+ value: string;
50
+ }[];
51
+ };
52
+ updateCellStyle(highlight?: boolean): void;
53
+ next(): {
54
+ index: number;
55
+ results: {
56
+ col: number;
57
+ row: number;
58
+ value: string;
59
+ }[];
60
+ };
61
+ prev(): {
62
+ index: number;
63
+ results: {
64
+ col: number;
65
+ row: number;
66
+ value: string;
67
+ }[];
68
+ };
69
+ jumpToCell(col: number, row: number): void;
70
+ clear(): void;
71
+ }
72
+ export {};
@@ -0,0 +1,102 @@
1
+ const defalutHightlightCellStyle = {
2
+ bgColor: "rgba(255, 255, 0, 0.2)"
3
+ }, defalutFocusHightlightCellStyle = {
4
+ bgColor: "rgba(255, 155, 0, 0.2)"
5
+ };
6
+
7
+ function defalultQueryMethod(queryStr, value) {
8
+ return value.toString().includes(queryStr);
9
+ }
10
+
11
+ export class SearchComponent {
12
+ constructor(option) {
13
+ this.table = option.table, this.autoJump = option.autoJump || !1, this.skipHeader = option.skipHeader || !1,
14
+ this.highlightCellStyle = option.highlightCellStyle || defalutHightlightCellStyle,
15
+ this.focuseHighlightCellStyle = option.focuseHighlightCellStyle || defalutFocusHightlightCellStyle,
16
+ this.queryMethod = option.queryMethod || defalultQueryMethod, this.callback = option.callback,
17
+ this.table.registerCustomCellStyle("__search_component_highlight", this.highlightCellStyle),
18
+ this.table.registerCustomCellStyle("__search_component_focuse", this.focuseHighlightCellStyle);
19
+ }
20
+ search(str) {
21
+ if (this.clear(), this.queryStr = str, !str) return {
22
+ index: 0,
23
+ results: this.queryResult
24
+ };
25
+ for (let row = 0; row < this.table.rowCount; row++) for (let col = 0; col < this.table.colCount; col++) {
26
+ if (this.skipHeader && this.table.isHeader(col, row)) continue;
27
+ const value = this.table.getCellValue(col, row);
28
+ this.queryMethod(this.queryStr, value, {
29
+ col: col,
30
+ row: row,
31
+ table: this.table
32
+ }) && this.queryResult.push({
33
+ col: col,
34
+ row: row,
35
+ value: value
36
+ });
37
+ }
38
+ return this.updateCellStyle(), this.callback && this.callback({
39
+ queryStr: this.queryStr,
40
+ results: this.queryResult
41
+ }, this.table), this.autoJump ? this.next() : {
42
+ index: 0,
43
+ results: this.queryResult
44
+ };
45
+ }
46
+ updateCellStyle(highlight = !0) {
47
+ if (this.queryResult) for (let i = 0; i < this.queryResult.length; i++) {
48
+ const {col: col, row: row} = this.queryResult[i];
49
+ this.table.arrangeCustomCellStyle({
50
+ col: col,
51
+ row: row
52
+ }, highlight ? "__search_component_highlight" : null);
53
+ }
54
+ }
55
+ next() {
56
+ if (!this.queryResult.length) return {
57
+ index: 0,
58
+ results: this.queryResult
59
+ };
60
+ -1 !== this.currentIndex && this.table.arrangeCustomCellStyle({
61
+ col: this.queryResult[this.currentIndex].col,
62
+ row: this.queryResult[this.currentIndex].row
63
+ }, "__search_component_highlight"), this.currentIndex++, this.currentIndex >= this.queryResult.length && (this.currentIndex = 0);
64
+ const {col: col, row: row} = this.queryResult[this.currentIndex];
65
+ return this.table.arrangeCustomCellStyle({
66
+ col: col,
67
+ row: row
68
+ }, "__search_component_focuse"), this.jumpToCell(col, row), {
69
+ index: this.currentIndex,
70
+ results: this.queryResult
71
+ };
72
+ }
73
+ prev() {
74
+ if (!this.queryResult.length) return {
75
+ index: 0,
76
+ results: this.queryResult
77
+ };
78
+ -1 !== this.currentIndex && this.table.arrangeCustomCellStyle({
79
+ col: this.queryResult[this.currentIndex].col,
80
+ row: this.queryResult[this.currentIndex].row
81
+ }, "__search_component_highlight"), this.currentIndex--, this.currentIndex < 0 && (this.currentIndex = this.queryResult.length - 1);
82
+ const {col: col, row: row} = this.queryResult[this.currentIndex];
83
+ return this.table.arrangeCustomCellStyle({
84
+ col: col,
85
+ row: row
86
+ }, "__search_component_focuse"), this.jumpToCell(col, row), {
87
+ index: this.currentIndex,
88
+ results: this.queryResult
89
+ };
90
+ }
91
+ jumpToCell(col, row) {
92
+ const {rowStart: rowStart, rowEnd: rowEnd} = this.table.getBodyVisibleRowRange(), {colStart: colStart, colEnd: colEnd} = this.table.getBodyVisibleColRange();
93
+ (row <= rowStart || row >= rowEnd || col <= colStart || col >= colEnd) && this.table.scrollToCell({
94
+ col: col,
95
+ row: row
96
+ });
97
+ }
98
+ clear() {
99
+ this.updateCellStyle(null), this.queryStr = "", this.queryResult = [], this.currentIndex = -1;
100
+ }
101
+ }
102
+ //# sourceMappingURL=search-component.js.map
@@ -0,0 +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,MAAM,OAAO,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,CA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,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","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"]}
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "name": "@visactor/vtable-search",
3
+ "version": "0.20.4-alpha.3",
4
+ "description": "The search util of VTable",
5
+ "author": {
6
+ "name": "VisActor",
7
+ "url": "https://VisActor.io/"
8
+ },
9
+ "license": "MIT",
10
+ "sideEffects": false,
11
+ "main": "cjs/index.js",
12
+ "module": "es/index.js",
13
+ "types": "es/index.d.ts",
14
+ "files": [
15
+ "cjs",
16
+ "es",
17
+ "dist"
18
+ ],
19
+ "exports": {
20
+ ".": {
21
+ "require": "./cjs/index.js",
22
+ "import": "./es/index.js"
23
+ }
24
+ },
25
+ "unpkg": "latest",
26
+ "unpkgFiles": [
27
+ "dist/vtable-exporter.js"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "dependencies": {
33
+ "@visactor/vtable": "0.20.4-alpha.3",
34
+ "@visactor/vutils": "~0.17.1"
35
+ },
36
+ "devDependencies": {
37
+ "@visactor/vchart": "1.9.1",
38
+ "@rushstack/eslint-patch": "~1.1.4",
39
+ "react": "^18.0.0",
40
+ "react-dom": "^18.0.0",
41
+ "@types/react": "^18.0.0",
42
+ "@types/react-dom": "^18.0.0",
43
+ "@vitejs/plugin-react": "3.1.0",
44
+ "eslint": "~8.18.0",
45
+ "vite": "3.2.6",
46
+ "typescript": "4.9.5",
47
+ "@babel/core": "7.20.12",
48
+ "@babel/preset-env": "7.20.2",
49
+ "@types/chai": "4.2.22",
50
+ "@types/jest": "^26.0.0",
51
+ "@types/mocha": "9.0.0",
52
+ "@types/node": "*",
53
+ "@types/offscreencanvas": "2019.6.4",
54
+ "chai": "4.3.4",
55
+ "jest": "^26.0.0",
56
+ "jest-electron": "^0.1.12",
57
+ "jest-transform-stub": "^2.0.0",
58
+ "magic-string": "^0.25.7",
59
+ "mocha": "9.1.3",
60
+ "postcss": "8.4.21",
61
+ "rimraf": "3.0.2",
62
+ "sass": "1.43.5",
63
+ "ts-jest": "^26.0.0",
64
+ "ts-loader": "9.2.6",
65
+ "ts-node": "10.9.0",
66
+ "tslib": "2.3.1",
67
+ "ttypescript": "1.5.13",
68
+ "typescript-transform-paths": "3.3.1",
69
+ "json-formatter-js": "^2.3.4",
70
+ "inversify": "6.0.1",
71
+ "vite-plugin-markdown": "^2.1.0",
72
+ "markdown-it": "^13.0.0",
73
+ "node-fetch": "2.6.7",
74
+ "form-data": "~4.0.0",
75
+ "axios": "^1.4.0",
76
+ "@types/react-is": "^17.0.3",
77
+ "rollup-plugin-node-resolve": "5.2.0",
78
+ "@internal/bundler": "0.0.1",
79
+ "@internal/eslint-config": "0.0.1",
80
+ "@internal/ts-config": "0.0.1"
81
+ },
82
+ "scripts": {
83
+ "start": "vite ./demo",
84
+ "build": "bundle --clean"
85
+ }
86
+ }