@hpcc-js/dgrid2 0.0.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.
- package/README.md +5 -0
- package/dist/index.es6.js +3254 -0
- package/dist/index.es6.js.map +1 -0
- package/dist/index.js +3265 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
- package/src/__package__.ts +3 -0
- package/src/index.ts +2 -0
- package/src/table.css +10 -0
- package/src/table.md +57 -0
- package/src/table.tsx +165 -0
- package/src/test.ts +41 -0
- package/types/__package__.d.ts +4 -0
- package/types/__package__.d.ts.map +1 -0
- package/types/index.d.ts +3 -0
- package/types/index.d.ts.map +1 -0
- package/types/table.d.ts +20 -0
- package/types/table.d.ts.map +1 -0
- package/types/test.d.ts +6 -0
- package/types/test.d.ts.map +1 -0
- package/types-3.4/__package__.d.ts +4 -0
- package/types-3.4/index.d.ts +3 -0
- package/types-3.4/table.d.ts +20 -0
- package/types-3.4/test.d.ts +6 -0
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hpcc-js/dgrid2",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "hpcc-js - DGrid2",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.es6",
|
|
7
|
+
"unpkg": "dist/index.min.js",
|
|
8
|
+
"jsdelivr": "dist/index.min.js",
|
|
9
|
+
"types": "types/index.d.ts",
|
|
10
|
+
"typesVersions": {
|
|
11
|
+
"<3.8": {
|
|
12
|
+
"*": [
|
|
13
|
+
"types-3.4/index.d.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist/*",
|
|
19
|
+
"types/*",
|
|
20
|
+
"types-3.4/*",
|
|
21
|
+
"src/*"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"clean": "rimraf lib* types dist *.tsbuildinfo",
|
|
25
|
+
"compile-es6": "tsc --module es6 --outDir ./lib-es6",
|
|
26
|
+
"compile-es6-watch": "npm run compile-es6 -- -w",
|
|
27
|
+
"compile-umd": "tsc --module umd --outDir ./lib-umd",
|
|
28
|
+
"compile-umd-watch": "npm run compile-umd -- -w",
|
|
29
|
+
"bundle": "rollup -c",
|
|
30
|
+
"bundle-watch": "npm run bundle -- -w",
|
|
31
|
+
"minimize": "terser dist/index.js -c -m --source-map \"content='dist/index.js.map',url='index.min.js.map'\" -o dist/index.min.js",
|
|
32
|
+
"gen-legacy-types": "downlevel-dts ./types ./types-3.4",
|
|
33
|
+
"build": "npm run compile-es6 && npm run bundle",
|
|
34
|
+
"watch": "npm-run-all compile-es6 -p compile-es6-watch bundle-watch",
|
|
35
|
+
"stamp": "node ../../node_modules/@hpcc-js/bundle/src/stamp.js",
|
|
36
|
+
"lint": "eslint src/**/*.ts",
|
|
37
|
+
"docs": "typedoc --options tdoptions.json .",
|
|
38
|
+
"update": "npx npm-check-updates -u -t minor"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@hpcc-js/common": "^2.67.0",
|
|
42
|
+
"@hpcc-js/util": "^2.46.2"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"react-data-grid": "7.0.0-beta.11",
|
|
46
|
+
"@githubocto/flat-ui": "0.14.0",
|
|
47
|
+
"@hpcc-js/bundle": "^2.11.1",
|
|
48
|
+
"preact": "10.7.1",
|
|
49
|
+
"tslib": "2.3.1"
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/hpcc-systems/Visualization.git"
|
|
54
|
+
},
|
|
55
|
+
"author": "Gordon Smith <gordonjsmith@gmail.com>",
|
|
56
|
+
"contributors": [],
|
|
57
|
+
"license": "Apache-2.0",
|
|
58
|
+
"bugs": {
|
|
59
|
+
"url": "https://github.com/hpcc-systems/Visualization/issues"
|
|
60
|
+
},
|
|
61
|
+
"homepage": "https://github.com/hpcc-systems/Visualization"
|
|
62
|
+
}
|
package/src/index.ts
ADDED
package/src/table.css
ADDED
package/src/table.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Table
|
|
2
|
+
|
|
3
|
+
**Class**: `Table`
|
|
4
|
+
|
|
5
|
+
<ClientOnly>
|
|
6
|
+
<hpcc-vitepress style="width:100%;height:600px">
|
|
7
|
+
<div id="placeholder" style="height:400px">
|
|
8
|
+
</div>
|
|
9
|
+
<script type="module">
|
|
10
|
+
import { Table } from "@hpcc-js/dgrid2";
|
|
11
|
+
|
|
12
|
+
new Table()
|
|
13
|
+
.target("placeholder")
|
|
14
|
+
.columns(["Category", "Series-1", "Series-2", "Series-3", "Series-4"])
|
|
15
|
+
.data([
|
|
16
|
+
["A", -25, -23, -25, -22],
|
|
17
|
+
["B", -20, -21, -25, -21],
|
|
18
|
+
["C", -18, -20, -25, -19],
|
|
19
|
+
["D", -17, -17, -25, -18],
|
|
20
|
+
["E", -16, -15, -19, -18],
|
|
21
|
+
["F", -15, -14, -16, -16],
|
|
22
|
+
["G", -12, -10, -14, -15],
|
|
23
|
+
["H", -12, -8, -13, -15],
|
|
24
|
+
["I", -11, -6, -12, -12],
|
|
25
|
+
["J", -11, -6, -8, -12],
|
|
26
|
+
["K", -9, 0, -5, -10],
|
|
27
|
+
["L", -5, 1, -5, -9],
|
|
28
|
+
["M", -5, 2, -4, -8],
|
|
29
|
+
["N", -1, 4, -2, -7],
|
|
30
|
+
["O", 3, 7, 0, -5],
|
|
31
|
+
["P", 3, 8, 0, -3],
|
|
32
|
+
["Q", 4, 8, 7, 0],
|
|
33
|
+
["R", 6, 9, 11, 1],
|
|
34
|
+
["S", 9, 11, 11, 5],
|
|
35
|
+
["T", 10, 20, 12, 6],
|
|
36
|
+
["U", 12, 20, 16, 8],
|
|
37
|
+
["V", 12, 21, 18, 14],
|
|
38
|
+
["W", 14, 21, 18, 18],
|
|
39
|
+
["X", 15, 23, 21, 18],
|
|
40
|
+
["Y", 21, 23, 23, 21],
|
|
41
|
+
["Z", 23, 24, 24, 24]
|
|
42
|
+
])
|
|
43
|
+
.render()
|
|
44
|
+
;
|
|
45
|
+
</script>
|
|
46
|
+
</hpcc-vitepress>
|
|
47
|
+
</ClientOnly>
|
|
48
|
+
|
|
49
|
+
::: tip
|
|
50
|
+
See [Getting Started](../README) for details on how to include @hpcc-js/dgrid2 in your application
|
|
51
|
+
:::
|
|
52
|
+
|
|
53
|
+
## `Table`
|
|
54
|
+
|
|
55
|
+
## Events
|
|
56
|
+
|
|
57
|
+
## Credits
|
package/src/table.tsx
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { HTMLWidget, publish } from "@hpcc-js/common";
|
|
2
|
+
import * as React from "preact/compat";
|
|
3
|
+
import DataGrid, { Column, SelectColumn, SortColumn } from "react-data-grid";
|
|
4
|
+
|
|
5
|
+
import "../src/table.css";
|
|
6
|
+
|
|
7
|
+
export type QuerySortItem = { attribute: string, descending: boolean };
|
|
8
|
+
function copyAndSort<T>(items: T[], attribute: string, descending?: boolean): T[] {
|
|
9
|
+
const key = attribute as keyof T;
|
|
10
|
+
return [...items].sort((a: T, b: T) => {
|
|
11
|
+
if (a[key] < b[key]) {
|
|
12
|
+
return descending ? 1 : -1;
|
|
13
|
+
} else if (a[key] > b[key]) {
|
|
14
|
+
return descending ? -1 : 1;
|
|
15
|
+
}
|
|
16
|
+
return 0;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface ReactTableProps {
|
|
21
|
+
columns: string[];
|
|
22
|
+
data: Array<string | number>[];
|
|
23
|
+
onRowClickCallback: (row: any) => void;
|
|
24
|
+
sort?: QuerySortItem,
|
|
25
|
+
darkMode?: boolean;
|
|
26
|
+
multiSelect?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const ReactTable: React.FunctionComponent<ReactTableProps> = ({
|
|
30
|
+
columns,
|
|
31
|
+
data,
|
|
32
|
+
onRowClickCallback,
|
|
33
|
+
sort,
|
|
34
|
+
darkMode = false,
|
|
35
|
+
multiSelect = false
|
|
36
|
+
}) => {
|
|
37
|
+
const [listColumns, setListColumns] = React.useState<Column<object>[]>([]);
|
|
38
|
+
const [sortColumn, setSortColumn] = React.useState<SortColumn>();
|
|
39
|
+
const [items, setItems] = React.useState<any[]>([]);
|
|
40
|
+
const [selectedRows, setSelectedRows] = React.useState<ReadonlySet<number>>(() => new Set());
|
|
41
|
+
|
|
42
|
+
// Columns ---
|
|
43
|
+
React.useEffect(() => {
|
|
44
|
+
setListColumns([
|
|
45
|
+
...multiSelect ? [SelectColumn] : [],
|
|
46
|
+
...columns.map(column => ({
|
|
47
|
+
key: column,
|
|
48
|
+
name: column,
|
|
49
|
+
resizable: true,
|
|
50
|
+
sortable: true,
|
|
51
|
+
minWidth: 80,
|
|
52
|
+
}))
|
|
53
|
+
]);
|
|
54
|
+
}, [columns, multiSelect]);
|
|
55
|
+
|
|
56
|
+
const onSortColumnsChange = React.useCallback((sortColumns: SortColumn[]) => {
|
|
57
|
+
const futureSortColumn = sortColumns.slice(-1)[0];
|
|
58
|
+
const sorted = futureSortColumn !== undefined;
|
|
59
|
+
const isSortedDescending: boolean = futureSortColumn?.direction === "DESC";
|
|
60
|
+
setSortColumn(futureSortColumn);
|
|
61
|
+
setItems(copyAndSort(items, sorted ? futureSortColumn.columnKey : "key", sorted ? isSortedDescending : false));
|
|
62
|
+
}, [items]);
|
|
63
|
+
|
|
64
|
+
const rowKeyGetter = React.useCallback((row: any) => {
|
|
65
|
+
return row.key;
|
|
66
|
+
}, []);
|
|
67
|
+
|
|
68
|
+
const onSelectedRowsChange = React.useCallback((selectedRows: Set<any>) => {
|
|
69
|
+
setSelectedRows(selectedRows);
|
|
70
|
+
onRowClickCallback(items.filter(row => selectedRows.has(rowKeyGetter(row))));
|
|
71
|
+
}, [items, onRowClickCallback, rowKeyGetter]);
|
|
72
|
+
|
|
73
|
+
const onRowClick = React.useCallback((row, column) => {
|
|
74
|
+
onRowClickCallback(items.filter(item => rowKeyGetter(item) === rowKeyGetter(row)));
|
|
75
|
+
}, [items, onRowClickCallback, rowKeyGetter]);
|
|
76
|
+
|
|
77
|
+
// Rows ---
|
|
78
|
+
React.useEffect(() => {
|
|
79
|
+
let items = data.map((row, index) => {
|
|
80
|
+
const retVal = {
|
|
81
|
+
key: index
|
|
82
|
+
};
|
|
83
|
+
columns.forEach((column, index) => {
|
|
84
|
+
retVal[column] = row[index];
|
|
85
|
+
});
|
|
86
|
+
return retVal;
|
|
87
|
+
});
|
|
88
|
+
if (sort?.attribute) {
|
|
89
|
+
items = copyAndSort(items, sort.attribute, sort.descending);
|
|
90
|
+
}
|
|
91
|
+
setItems(items);
|
|
92
|
+
}, [columns, data, sort]);
|
|
93
|
+
|
|
94
|
+
return <DataGrid
|
|
95
|
+
columns={listColumns}
|
|
96
|
+
headerRowHeight={24}
|
|
97
|
+
rows={items}
|
|
98
|
+
rowKeyGetter={rowKeyGetter}
|
|
99
|
+
rowHeight={20}
|
|
100
|
+
className={darkMode ? "rdg-dark" : "rdg-light"}
|
|
101
|
+
sortColumns={sortColumn ? [sortColumn] : []}
|
|
102
|
+
onSortColumnsChange={onSortColumnsChange}
|
|
103
|
+
selectedRows={selectedRows}
|
|
104
|
+
onSelectedRowsChange={multiSelect ? onSelectedRowsChange : undefined}
|
|
105
|
+
onRowClick={multiSelect ? undefined : onRowClick}
|
|
106
|
+
aria-describedby={""}
|
|
107
|
+
aria-label={""}
|
|
108
|
+
aria-labelledby={""}
|
|
109
|
+
style={{ height: "100%" }}
|
|
110
|
+
/>;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export class Table extends HTMLWidget {
|
|
114
|
+
|
|
115
|
+
protected _div;
|
|
116
|
+
|
|
117
|
+
constructor() {
|
|
118
|
+
super();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@publish(false, "boolean", "Dark Mode")
|
|
122
|
+
darkMode: publish<this, boolean>;
|
|
123
|
+
@publish(false, "boolean", "Multiple Selection")
|
|
124
|
+
multiSelect: publish<this, boolean>;
|
|
125
|
+
|
|
126
|
+
_prevRow;
|
|
127
|
+
_prevColumn;
|
|
128
|
+
private renderTable() {
|
|
129
|
+
return <ReactTable columns={this.columns()} data={this.data()} darkMode={this.darkMode()} onRowClickCallback={(row, column = "") => {
|
|
130
|
+
if (this._prevRow && JSON.stringify(this._prevRow) !== JSON.stringify(row)) {
|
|
131
|
+
this.click(this._prevRow, this._prevColumn ?? "", false);
|
|
132
|
+
}
|
|
133
|
+
if (row) {
|
|
134
|
+
this.click(row, column, true);
|
|
135
|
+
}
|
|
136
|
+
this._prevRow = row;
|
|
137
|
+
this._prevColumn = column;
|
|
138
|
+
}} />;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
enter(domNode, element) {
|
|
142
|
+
super.enter(domNode, element);
|
|
143
|
+
this._div = element
|
|
144
|
+
.append("div")
|
|
145
|
+
;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
update(domNode, element) {
|
|
149
|
+
super.update(domNode, element);
|
|
150
|
+
this._div.style("width", this.width() + "px");
|
|
151
|
+
this._div.style("height", this.height() + "px");
|
|
152
|
+
React.render(this.renderTable(), this._div.node());
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
exit(domNode, element) {
|
|
156
|
+
React.unmountComponentAtNode(this._div.node());
|
|
157
|
+
this._div.remove();
|
|
158
|
+
super.exit(domNode, element);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Events ---
|
|
162
|
+
click(row, col, sel) {
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
Table.prototype._class += " dgrid2_Table";
|
package/src/test.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Table } from "./table";
|
|
2
|
+
|
|
3
|
+
export { Test1 as Test };
|
|
4
|
+
|
|
5
|
+
export class Test1 extends Table {
|
|
6
|
+
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
this
|
|
10
|
+
.columns(["Category", "Series-1", "Series-2", "Series-3", "Series-4"])
|
|
11
|
+
.data([
|
|
12
|
+
["A", -25, -23, -25, -22],
|
|
13
|
+
["B", -20, -21, -25, -21],
|
|
14
|
+
["C", -18, -20, -25, -19],
|
|
15
|
+
["D", -17, -17, -25, -18],
|
|
16
|
+
["E", -16, -15, -19, -18],
|
|
17
|
+
["F", -15, -14, -16, -16],
|
|
18
|
+
["G", -12, -10, -14, -15],
|
|
19
|
+
["H", -12, -8, -13, -15],
|
|
20
|
+
["I", -11, -6, -12, -12],
|
|
21
|
+
["J", -11, -6, -8, -12],
|
|
22
|
+
["K", -9, 0, -5, -10],
|
|
23
|
+
["L", -5, 1, -5, -9],
|
|
24
|
+
["M", -5, 2, -4, -8],
|
|
25
|
+
["N", -1, 4, -2, -7],
|
|
26
|
+
["O", 3, 7, 0, -5],
|
|
27
|
+
["P", 3, 8, 0, -3],
|
|
28
|
+
["Q", 4, 8, 7, 0],
|
|
29
|
+
["R", 6, 9, 11, 1],
|
|
30
|
+
["S", 9, 11, 11, 5],
|
|
31
|
+
["T", 10, 20, 12, 6],
|
|
32
|
+
["U", 12, 20, 16, 8],
|
|
33
|
+
["V", 12, 21, 18, 14],
|
|
34
|
+
["W", 14, 21, 18, 18],
|
|
35
|
+
["X", 15, 23, 21, 18],
|
|
36
|
+
["Y", 21, 23, 23, 21],
|
|
37
|
+
["Z", 23, 24, 24, 24]
|
|
38
|
+
])
|
|
39
|
+
;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"__package__.d.ts","sourceRoot":"","sources":["../src/__package__.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,oBAAoB,CAAC;AAC1C,eAAO,MAAM,WAAW,UAAU,CAAC;AACnC,eAAO,MAAM,aAAa,aAAa,CAAC"}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC"}
|
package/types/table.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HTMLWidget, publish } from "@hpcc-js/common";
|
|
2
|
+
import "../src/table.css";
|
|
3
|
+
export declare type QuerySortItem = {
|
|
4
|
+
attribute: string;
|
|
5
|
+
descending: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare class Table extends HTMLWidget {
|
|
8
|
+
protected _div: any;
|
|
9
|
+
constructor();
|
|
10
|
+
darkMode: publish<this, boolean>;
|
|
11
|
+
multiSelect: publish<this, boolean>;
|
|
12
|
+
_prevRow: any;
|
|
13
|
+
_prevColumn: any;
|
|
14
|
+
private renderTable;
|
|
15
|
+
enter(domNode: any, element: any): void;
|
|
16
|
+
update(domNode: any, element: any): void;
|
|
17
|
+
exit(domNode: any, element: any): void;
|
|
18
|
+
click(row: any, col: any, sel: any): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../src/table.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAItD,OAAO,kBAAkB,CAAC;AAE1B,oBAAY,aAAa,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,CAAC;AA0GvE,qBAAa,KAAM,SAAQ,UAAU;IAEjC,SAAS,CAAC,IAAI,MAAC;;IAOf,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAEjC,WAAW,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAEpC,QAAQ,MAAC;IACT,WAAW,MAAC;IACZ,OAAO,CAAC,WAAW;IAanB,KAAK,CAAC,OAAO,KAAA,EAAE,OAAO,KAAA;IAOtB,MAAM,CAAC,OAAO,KAAA,EAAE,OAAO,KAAA;IAOvB,IAAI,CAAC,OAAO,KAAA,EAAE,OAAO,KAAA;IAOrB,KAAK,CAAC,GAAG,KAAA,EAAE,GAAG,KAAA,EAAE,GAAG,KAAA;CAEtB"}
|
package/types/test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,CAAC;AAEzB,qBAAa,KAAM,SAAQ,KAAK;;CAoC/B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HTMLWidget, publish } from "@hpcc-js/common";
|
|
2
|
+
import "../src/table.css";
|
|
3
|
+
export declare type QuerySortItem = {
|
|
4
|
+
attribute: string;
|
|
5
|
+
descending: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare class Table extends HTMLWidget {
|
|
8
|
+
protected _div: any;
|
|
9
|
+
constructor();
|
|
10
|
+
darkMode: publish<this, boolean>;
|
|
11
|
+
multiSelect: publish<this, boolean>;
|
|
12
|
+
_prevRow: any;
|
|
13
|
+
_prevColumn: any;
|
|
14
|
+
private renderTable;
|
|
15
|
+
enter(domNode: any, element: any): void;
|
|
16
|
+
update(domNode: any, element: any): void;
|
|
17
|
+
exit(domNode: any, element: any): void;
|
|
18
|
+
click(row: any, col: any, sel: any): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=table.d.ts.map
|