@hpcc-js/dgrid2 3.2.0 → 3.2.2

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@hpcc-js/dgrid2",
3
- "version": "3.2.0",
3
+ "version": "3.2.2",
4
4
  "description": "hpcc-js - DGrid2",
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.cjs",
@@ -37,14 +37,18 @@
37
37
  "update-major": "npx --yes npm-check-updates -u"
38
38
  },
39
39
  "dependencies": {
40
- "@hpcc-js/common": "^3.3.0",
41
- "@hpcc-js/util": "^3.3.0"
40
+ "@hpcc-js/common": "^3.3.2",
41
+ "@hpcc-js/util": "^3.3.2"
42
42
  },
43
43
  "devDependencies": {
44
- "@hpcc-js/esbuild-plugins": "^1.4.0",
45
- "@preact/preset-vite": "2.9.2",
46
- "preact": "10.25.0",
47
- "react-data-grid": "7.0.0-beta.47"
44
+ "@hpcc-js/esbuild-plugins": "^1.4.2",
45
+ "@types/react": "19.1.0",
46
+ "@types/react-dom": "19.1.0",
47
+ "@vitejs/plugin-react": "4.3.4",
48
+ "react": "19.1.0",
49
+ "react-data-grid": "7.0.0-beta.51",
50
+ "react-dom": "19.1.0",
51
+ "vite-plugin-html": "3.2.2"
48
52
  },
49
53
  "repository": {
50
54
  "type": "git",
@@ -57,5 +61,5 @@
57
61
  "url": "https://github.com/hpcc-systems/Visualization/issues"
58
62
  },
59
63
  "homepage": "https://github.com/hpcc-systems/Visualization",
60
- "gitHead": "145a4d4c8189c70f08e9804e63959d6dd398bd9f"
64
+ "gitHead": "c54b3bd37ed839305001ba47f2657a1f8eb8628a"
61
65
  }
@@ -0,0 +1,56 @@
1
+ import React, { Component, ErrorInfo, ReactNode } from "react";
2
+
3
+ interface Props {
4
+ children: ReactNode;
5
+ fallback?: ReactNode;
6
+ }
7
+
8
+ interface State {
9
+ hasError: boolean;
10
+ error: Error | null;
11
+ }
12
+
13
+ export class ErrorBoundary extends Component<Props, State> {
14
+ public state: State = {
15
+ hasError: false,
16
+ error: null
17
+ };
18
+
19
+ public static getDerivedStateFromError(error: Error): State {
20
+ return { hasError: true, error };
21
+ }
22
+
23
+ public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
24
+ console.error("Error caught by boundary:", error);
25
+ console.error("Component stack:", errorInfo.componentStack);
26
+ }
27
+
28
+ private handleReset = () => {
29
+ this.setState({ hasError: false, error: null });
30
+ };
31
+
32
+ public render() {
33
+ if (this.state.hasError) {
34
+ if (this.props.fallback) {
35
+ return this.props.fallback;
36
+ }
37
+
38
+ return (
39
+ <div className="min-h-[200px] flex items-center justify-center p-8 bg-red-50 rounded-lg border border-red-100">
40
+ <div className="text-center">
41
+ <h2 className="text-xl font-semibold text-red-700 mb-2">Something went wrong</h2>
42
+ <p className="text-red-600">{this.state.error?.message}</p>
43
+ <button
44
+ onClick={this.handleReset}
45
+ className="mt-4 px-4 py-2 bg-red-600 text-white rounded-md hover:bg-red-700 transition-colors"
46
+ >
47
+ Try again
48
+ </button>
49
+ </div>
50
+ </div>
51
+ );
52
+ }
53
+
54
+ return this.props.children;
55
+ }
56
+ }
package/src/hooks.ts CHANGED
@@ -1,4 +1,4 @@
1
- import React from "preact/compat";
1
+ import React from "react";
2
2
  import { Widget } from "@hpcc-js/common";
3
3
 
4
4
  export function useData(widget: Widget): [string[], Array<string | number>[]] {
@@ -1,7 +1,7 @@
1
- import { FunctionComponent } from "preact";
2
- import { useCallback, useEffect, useState } from "preact/hooks";
3
- import DataGrid, { Column, SelectColumn, SortColumn } from "react-data-grid";
1
+ import React, { FunctionComponent, useCallback, useEffect, useState } from "react";
2
+ import { DataGrid, Column, SelectColumn, SortColumn } from "react-data-grid";
4
3
  import { format, timeFormat, timeParse } from "@hpcc-js/common";
4
+ import { ErrorBoundary } from "./ErrorBoundary.tsx";
5
5
  import { useData } from "./hooks.ts";
6
6
  import type { Table } from "./table.ts";
7
7
 
@@ -140,23 +140,24 @@ export const ReactTable: FunctionComponent<ReactTableProps> = ({
140
140
  setRows(items);
141
141
  }, [listColumns, data, sort]);
142
142
 
143
- return <DataGrid
144
- columns={listColumns}
145
- headerRowHeight={24}
146
- rows={rows}
147
- rowKeyGetter={rowKeyGetter}
148
- rowHeight={20}
149
- renderers={{ noRowsFallback: <EmptyRowsRenderer message={table.noDataMessage()} /> as any }}
150
- className={table.darkMode() ? "rdg-dark" : "rdg-light"}
151
- sortColumns={sortColumn ? [sortColumn] : []}
152
- onSortColumnsChange={onSortColumnsChange}
153
- selectedRows={selectedRows}
154
- onSelectedRowsChange={multiSelect ? onSelectedRowsChange : undefined}
155
- onCellClick={multiSelect ? undefined : (args, event) => onCellClick(args.row, args.column)}
156
- aria-describedby={""}
157
- aria-label={""}
158
- aria-labelledby={""}
159
- style={{ height: "100%" }}
160
- />;
143
+ return (
144
+ <ErrorBoundary fallback={<div>Error loading table</div>}>
145
+ <DataGrid
146
+ columns={listColumns}
147
+ headerRowHeight={24}
148
+ rows={rows}
149
+ rowKeyGetter={rowKeyGetter}
150
+ rowHeight={20}
151
+ renderers={{ noRowsFallback: <EmptyRowsRenderer message={table.noDataMessage()} /> as any }}
152
+ className={table.darkMode() ? "rdg-dark" : "rdg-light"}
153
+ sortColumns={sortColumn ? [sortColumn] : []}
154
+ onSortColumnsChange={onSortColumnsChange}
155
+ selectedRows={selectedRows}
156
+ onSelectedRowsChange={multiSelect ? onSelectedRowsChange : undefined}
157
+ onCellClick={multiSelect ? undefined : (args, event) => onCellClick(args.row, args.column)}
158
+ style={{ height: "100%" }}
159
+ />
160
+ </ErrorBoundary>
161
+ );
161
162
  };
162
163
 
package/src/table.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { render, createElement } from "preact";
1
+ import { createElement } from "react";
2
+ import { createRoot } from "react-dom/client";
2
3
  import { HTMLWidget } from "@hpcc-js/common";
3
4
  import { ReactTable } from "./reactTable.tsx";
4
5
 
@@ -9,6 +10,8 @@ export type ColumnType = "boolean" | "number" | "string" | "time";
9
10
  export class Table extends HTMLWidget {
10
11
 
11
12
  protected _div;
13
+ protected _root: any;
14
+ protected _component: any;
12
15
 
13
16
  constructor() {
14
17
  super();
@@ -57,13 +60,15 @@ export class Table extends HTMLWidget {
57
60
  .append("div")
58
61
  .style("display", "grid")
59
62
  ;
63
+ this._root = createRoot(this._div.node(), { identifierPrefix: this.id() });
64
+ this._component = createElement(ReactTable, { table: this });
60
65
  }
61
66
 
62
67
  update(domNode, element) {
63
68
  super.update(domNode, element);
64
69
  this._div.style("width", this.width() + "px");
65
70
  this._div.style("height", this.height() + "px");
66
- render(createElement(ReactTable, { table: this }), this._div.node());
71
+ this._root.render(this._component);
67
72
  }
68
73
 
69
74
  exit(domNode, element) {
@@ -0,0 +1,17 @@
1
+ import React, { Component, ErrorInfo, ReactNode } from "react";
2
+ interface Props {
3
+ children: ReactNode;
4
+ fallback?: ReactNode;
5
+ }
6
+ interface State {
7
+ hasError: boolean;
8
+ error: Error | null;
9
+ }
10
+ export declare class ErrorBoundary extends Component<Props, State> {
11
+ state: State;
12
+ static getDerivedStateFromError(error: Error): State;
13
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
14
+ private handleReset;
15
+ render(): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode>> | React.JSX.Element;
16
+ }
17
+ export {};
@@ -1,4 +1,4 @@
1
- import { FunctionComponent } from "preact";
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 = {
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;