@hpcc-js/dgrid2 3.1.1 → 3.2.1

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/package.json CHANGED
@@ -1,28 +1,29 @@
1
1
  {
2
2
  "name": "@hpcc-js/dgrid2",
3
- "version": "3.1.1",
3
+ "version": "3.2.1",
4
4
  "description": "hpcc-js - DGrid2",
5
5
  "type": "module",
6
+ "main": "./dist/index.umd.cjs",
7
+ "module": "./dist/index.js",
6
8
  "exports": {
7
9
  ".": {
8
10
  "types": "./types/index.d.ts",
9
- "default": "./dist/index.js"
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.umd.cjs"
10
13
  },
11
14
  "./dist/*": "./dist/*"
12
15
  },
13
- "module": "./dist/index.js",
14
- "browser": "./dist/index.js",
16
+ "browser": "./dist/index.umd.cjs",
15
17
  "types": "./types/index.d.ts",
16
18
  "files": [
17
19
  "dist/*",
18
20
  "src/*",
19
- "types/*",
20
- "font-awesome/**/*"
21
+ "types/*"
21
22
  ],
22
23
  "scripts": {
23
24
  "clean": "rimraf --glob lib* types dist *.tsbuildinfo .turbo",
24
- "bundle": "node esbuild.js",
25
- "bundle-watch": "npm run bundle -- --development --watch",
25
+ "bundle": "vite build",
26
+ "bundle-watch": "vite --port 5507",
26
27
  "gen-types": "tsc --project tsconfig.json",
27
28
  "gen-types-watch": "npm run gen-types -- --watch",
28
29
  "build": "run-p gen-types bundle",
@@ -36,13 +37,20 @@
36
37
  "update-major": "npx --yes npm-check-updates -u"
37
38
  },
38
39
  "dependencies": {
39
- "@hpcc-js/common": "^3.2.0",
40
- "@hpcc-js/util": "^3.2.0"
40
+ "@hpcc-js/common": "^3.3.1",
41
+ "@hpcc-js/util": "^3.3.1"
42
+ },
43
+ "peerDependencies": {
44
+ "react": "^18.0.0",
45
+ "react-dom": "^18.0.0"
41
46
  },
42
47
  "devDependencies": {
43
- "@hpcc-js/esbuild-plugins": "^1.3.0",
44
- "@hpcc-js/preact-shim": "^3.0.0",
45
- "react-data-grid": "7.0.0-beta.47"
48
+ "@hpcc-js/esbuild-plugins": "^1.4.1",
49
+ "@types/react": "^18.0.0",
50
+ "@types/react-dom": "^18.0.0",
51
+ "@vitejs/plugin-react": "4.3.4",
52
+ "react-data-grid": "7.0.0-beta.47",
53
+ "vite-plugin-html": "3.2.2"
46
54
  },
47
55
  "repository": {
48
56
  "type": "git",
@@ -55,5 +63,5 @@
55
63
  "url": "https://github.com/hpcc-systems/Visualization/issues"
56
64
  },
57
65
  "homepage": "https://github.com/hpcc-systems/Visualization",
58
- "gitHead": "b4f63e027feea45ebdfc578ef9c85d107bd97322"
66
+ "gitHead": "521692e7cfd01c274d5cfff0c54e79d1686d3dd6"
59
67
  }
package/src/hooks.ts CHANGED
@@ -1,10 +1,8 @@
1
+ import React from "react";
1
2
  import { Widget } from "@hpcc-js/common";
2
- import * as React from "react";
3
3
 
4
4
  export function useData(widget: Widget): [string[], Array<string | number>[]] {
5
- // eslint-disable-next-line react-hooks/exhaustive-deps
6
5
  const columns: string[] = React.useMemo(() => widget.columns(), [widget, widget.dataChecksum()]);
7
- // eslint-disable-next-line react-hooks/exhaustive-deps
8
6
  const data: Array<string | number>[] = React.useMemo(() => widget.data(), [widget, widget.dataChecksum()]);
9
7
 
10
8
  return [columns, data];
@@ -1,4 +1,4 @@
1
- import * as React from "react";
1
+ import React, { FunctionComponent, useCallback, useEffect, useState } from "react";
2
2
  import DataGrid, { Column, SelectColumn, SortColumn } from "react-data-grid";
3
3
  import { format, timeFormat, timeParse } from "@hpcc-js/common";
4
4
  import { useData } from "./hooks.ts";
@@ -23,7 +23,7 @@ interface EmptyRowsRendererProps {
23
23
  message: string
24
24
  }
25
25
 
26
- const EmptyRowsRenderer: React.FunctionComponent<EmptyRowsRendererProps> = ({
26
+ const EmptyRowsRenderer: FunctionComponent<EmptyRowsRendererProps> = ({
27
27
  message
28
28
  }) => {
29
29
 
@@ -43,7 +43,7 @@ export interface ReactTableProps {
43
43
  sort?: QuerySortItem,
44
44
  }
45
45
 
46
- export const ReactTable: React.FunctionComponent<ReactTableProps> = ({
46
+ export const ReactTable: FunctionComponent<ReactTableProps> = ({
47
47
  table,
48
48
  sort
49
49
  }) => {
@@ -53,13 +53,13 @@ export const ReactTable: React.FunctionComponent<ReactTableProps> = ({
53
53
  const columnPatterns = table.columnPatterns();
54
54
  const columnFormats = table.columnFormats();
55
55
 
56
- const [listColumns, setListColumns] = React.useState<ColumnEx<any[]>[]>([]);
57
- const [sortColumn, setSortColumn] = React.useState<SortColumn>();
58
- const [rows, setRows] = React.useState<any[]>([]);
59
- const [selectedRows, setSelectedRows] = React.useState<ReadonlySet<number>>(new Set());
56
+ const [listColumns, setListColumns] = useState<ColumnEx<any[]>[]>([]);
57
+ const [sortColumn, setSortColumn] = useState<SortColumn>();
58
+ const [rows, setRows] = useState<any[]>([]);
59
+ const [selectedRows, setSelectedRows] = useState<ReadonlySet<number>>(new Set());
60
60
 
61
61
  // Columns ---
62
- React.useEffect(() => {
62
+ useEffect(() => {
63
63
  setListColumns([
64
64
  ...multiSelect ? [SelectColumn as ColumnEx<any[]>] : [],
65
65
  ...columns.map((column): ColumnEx<any[]> => {
@@ -94,7 +94,7 @@ export const ReactTable: React.FunctionComponent<ReactTableProps> = ({
94
94
  ]);
95
95
  }, [columnFormats, columnPatterns, columnTypes, columns, multiSelect]);
96
96
 
97
- const onSortColumnsChange = React.useCallback((sortColumns: SortColumn[]) => {
97
+ const onSortColumnsChange = useCallback((sortColumns: SortColumn[]) => {
98
98
  const futureSortColumn = sortColumns.slice(-1)[0];
99
99
  const sorted = futureSortColumn !== undefined;
100
100
  const isSortedDescending: boolean = futureSortColumn?.direction === "DESC";
@@ -102,20 +102,20 @@ export const ReactTable: React.FunctionComponent<ReactTableProps> = ({
102
102
  setRows(copyAndSort(rows, sorted ? futureSortColumn.columnKey : "key", sorted ? isSortedDescending : false));
103
103
  }, [rows]);
104
104
 
105
- const rowKeyGetter = React.useCallback((row: any) => {
105
+ const rowKeyGetter = useCallback((row: any) => {
106
106
  return row.key;
107
107
  }, []);
108
108
 
109
- const onSelectedRowsChange = React.useCallback((selectedRows: Set<any>) => {
109
+ const onSelectedRowsChange = useCallback((selectedRows: Set<any>) => {
110
110
  setSelectedRows(selectedRows);
111
111
  }, []);
112
112
 
113
- const onCellClick = React.useCallback((row, column) => {
113
+ const onCellClick = useCallback((row, column) => {
114
114
  table.onRowClickCallback(row, column.key);
115
115
  }, [table]);
116
116
 
117
117
  // Rows ---
118
- React.useEffect(() => {
118
+ useEffect(() => {
119
119
  let items = data.map((row, index) => {
120
120
  const retVal = {
121
121
  key: index
package/src/table.ts CHANGED
@@ -1,6 +1,6 @@
1
- import * as React from "react";
1
+ import { createElement } from "react";
2
+ import { createRoot } from "react-dom/client";
2
3
  import { HTMLWidget } from "@hpcc-js/common";
3
- import { render, unmountComponentAtNode } from "react-dom";
4
4
  import { ReactTable } from "./reactTable.tsx";
5
5
 
6
6
  import "./table.css";
@@ -10,6 +10,8 @@ export type ColumnType = "boolean" | "number" | "string" | "time";
10
10
  export class Table extends HTMLWidget {
11
11
 
12
12
  protected _div;
13
+ protected _root: any;
14
+ protected _component: any;
13
15
 
14
16
  constructor() {
15
17
  super();
@@ -58,17 +60,18 @@ export class Table extends HTMLWidget {
58
60
  .append("div")
59
61
  .style("display", "grid")
60
62
  ;
63
+ this._root = createRoot(this._div.node(), { identifierPrefix: this.id() });
64
+ this._component = createElement(ReactTable, { table: this });
61
65
  }
62
66
 
63
67
  update(domNode, element) {
64
68
  super.update(domNode, element);
65
69
  this._div.style("width", this.width() + "px");
66
70
  this._div.style("height", this.height() + "px");
67
- render(React.createElement(ReactTable, { table: this }), this._div.node());
71
+ this._root.render(this._component);
68
72
  }
69
73
 
70
74
  exit(domNode, element) {
71
- unmountComponentAtNode(this._div.node());
72
75
  this._div.remove();
73
76
  super.exit(domNode, element);
74
77
  }
@@ -1,4 +1,4 @@
1
- import * as React from "react";
1
+ import { FunctionComponent } from "react";
2
2
  import type { Table } from "./table.ts";
3
3
  import "react-data-grid/lib/styles.css";
4
4
  export type QuerySortItem = {
@@ -9,4 +9,4 @@ export interface ReactTableProps {
9
9
  table: Table;
10
10
  sort?: QuerySortItem;
11
11
  }
12
- export declare const ReactTable: React.FunctionComponent<ReactTableProps>;
12
+ export declare const ReactTable: FunctionComponent<ReactTableProps>;
package/types/table.d.ts CHANGED
@@ -3,6 +3,8 @@ import "./table.css";
3
3
  export type ColumnType = "boolean" | "number" | "string" | "time";
4
4
  export declare class Table extends HTMLWidget {
5
5
  protected _div: any;
6
+ protected _root: any;
7
+ protected _component: any;
6
8
  constructor();
7
9
  columnType(column: string): ColumnType;
8
10
  columnType(column: string, type: ColumnType): this;