@hpcc-js/dgrid2 0.0.0 → 2.2.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/LICENSE +43 -0
- package/README.md +5 -5
- package/dist/index.es6.js +422 -311
- package/dist/index.es6.js.map +1 -1
- package/dist/index.js +421 -310
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/package.json +63 -62
- package/src/__package__.ts +3 -3
- package/src/hooks.ts +12 -0
- package/src/index.ts +2 -2
- package/src/reactTable.tsx +161 -0
- package/src/table.css +9 -9
- package/src/table.md +57 -57
- package/src/table.ts +92 -0
- package/types/__package__.d.ts +3 -3
- package/types/__package__.d.ts.map +1 -1
- package/types/hooks.d.ts +3 -0
- package/types/hooks.d.ts.map +1 -0
- package/types/index.d.ts +2 -2
- package/types/reactTable.d.ts +12 -0
- package/types/reactTable.d.ts.map +1 -0
- package/types/table.d.ts +32 -19
- package/types/table.d.ts.map +1 -1
- package/types-3.4/__package__.d.ts +2 -2
- package/types-3.4/hooks.d.ts +6 -0
- package/types-3.4/reactTable.d.ts +12 -0
- package/types-3.4/table.d.ts +20 -7
- package/src/table.tsx +0 -165
- package/src/test.ts +0 -41
- package/types/test.d.ts +0 -6
- package/types/test.d.ts.map +0 -1
- package/types-3.4/test.d.ts +0 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const PKG_NAME = "@hpcc-js/dgrid2";
|
|
2
|
-
export declare const PKG_VERSION = "
|
|
3
|
-
export declare const BUILD_VERSION = "2.
|
|
2
|
+
export declare const PKG_VERSION = "2.2.0";
|
|
3
|
+
export declare const BUILD_VERSION = "2.103.2";
|
|
4
4
|
//# sourceMappingURL=__package__.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Table } from "./table";
|
|
3
|
+
export declare type QuerySortItem = {
|
|
4
|
+
attribute: string;
|
|
5
|
+
descending: boolean;
|
|
6
|
+
};
|
|
7
|
+
export interface ReactTableProps {
|
|
8
|
+
table: Table;
|
|
9
|
+
sort?: QuerySortItem;
|
|
10
|
+
}
|
|
11
|
+
export declare const ReactTable: React.FunctionComponent<ReactTableProps>;
|
|
12
|
+
//# sourceMappingURL=reactTable.d.ts.map
|
package/types-3.4/table.d.ts
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
import { HTMLWidget, publish } from "@hpcc-js/common";
|
|
2
2
|
import "../src/table.css";
|
|
3
|
-
export declare type
|
|
4
|
-
attribute: string;
|
|
5
|
-
descending: boolean;
|
|
6
|
-
};
|
|
3
|
+
export declare type ColumnType = "boolean" | "number" | "string" | "time";
|
|
7
4
|
export declare class Table extends HTMLWidget {
|
|
8
5
|
protected _div: any;
|
|
9
6
|
constructor();
|
|
7
|
+
noDataMessage: publish<this, string>;
|
|
10
8
|
darkMode: publish<this, boolean>;
|
|
11
9
|
multiSelect: publish<this, boolean>;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
columnTypes: publish<this, {
|
|
11
|
+
[column: string]: ColumnType;
|
|
12
|
+
}>;
|
|
13
|
+
columnPatterns: publish<this, {
|
|
14
|
+
[column: string]: string;
|
|
15
|
+
}>;
|
|
16
|
+
columnFormats: publish<this, {
|
|
17
|
+
[column: string]: string;
|
|
18
|
+
}>;
|
|
19
|
+
columnType(column: string): ColumnType;
|
|
20
|
+
columnType(column: string, type: ColumnType): this;
|
|
21
|
+
columnPattern(column: string): string;
|
|
22
|
+
columnPattern(column: string, pattern: string): this;
|
|
23
|
+
columnFormat(column: string): string;
|
|
24
|
+
columnFormat(column: string, format: string): this;
|
|
25
|
+
private _prevRow;
|
|
26
|
+
private _prevColumn;
|
|
27
|
+
onRowClickCallback(row: any, column: any): void;
|
|
15
28
|
enter(domNode: any, element: any): void;
|
|
16
29
|
update(domNode: any, element: any): void;
|
|
17
30
|
exit(domNode: any, element: any): void;
|
package/src/table.tsx
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
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
|
-
}
|
package/types/test.d.ts
DELETED
package/types/test.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|