Skip to content

Commit 7cf5627

Browse files
authored
Merge pull request #294 from sylwit/feature/react18
Feature/react18
2 parents 2746e90 + 29b8416 commit 7cf5627

26 files changed

+12035
-41804
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Require: `NodeJS`
5353
```
5454
$ npm install --legacy-peer-deps install dependencies for development.
5555
$ export NODE_OPTIONS=--openssl-legacy-provider to work with Node 18+
56+
$ export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true to work with ARM if you haven't chromium installed
5657
$ npm run dev Launch DEV mode (with hot reload).
5758
$ npm run build Make a build.
5859

__tests__/ui/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { Component } from 'react';
2-
import { render } from 'react-dom';
3-
2+
import { createRoot } from 'react-dom/client';
43
import '../../src/styles.css';
54
import { ReactTabulator } from '../../lib';
65

@@ -45,4 +44,6 @@ class Demo extends Component {
4544
}
4645
}
4746

48-
render(<Demo />, document.querySelector('#app'));
47+
const rootElement = document.querySelector('#app');
48+
const root = createRoot(rootElement);
49+
root.render(<Demo />);

demo/src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react';
2-
import { render } from 'react-dom';
2+
import { createRoot } from 'react-dom/client';
33
import './styles.css';
44

55
import '../../styles.css'; // required styles
@@ -21,4 +21,9 @@ class Demo extends Component {
2121
}
2222
}
2323

24-
render(<Demo />, document.querySelector('#demo'));
24+
// Get the root element from the DOM
25+
const rootElement = document.querySelector('#demo');
26+
27+
// Create a root and render your app
28+
const root = createRoot(rootElement);
29+
root.render(<Demo />);

lib/ConfigUtils.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
1414
function verb(n) { return function (v) { return step([n, v]); }; }
1515
function step(op) {
1616
if (f) throw new TypeError("Generator is already executing.");
17-
while (_) try {
17+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
1818
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1919
if (y = 0, t) op = [op[0] & 2, t.value];
2020
switch (op[0]) {
@@ -37,15 +37,19 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
3737
};
3838
exports.__esModule = true;
3939
exports.propsToOptions = void 0;
40-
var Es6Promise = require("es6-promise"); // without this, 'yarn build' will complain about Promise.
41-
var react_dom_1 = require("react-dom");
40+
var client_1 = require("react-dom/client");
4241
// .prettierignore (to keep relevant props together)
4342
var NOOPS = function () { };
4443
function syncRender(comp, el) {
45-
return new Es6Promise.Promise(function (resolve, reject) {
46-
react_dom_1.render(comp, el, function () {
47-
resolve(el);
48-
});
44+
return new Promise(function (resolve, reject) {
45+
try {
46+
var root = (0, client_1.createRoot)(el);
47+
root.render(comp);
48+
resolve(el); // Resolve immediately after rendering
49+
}
50+
catch (error) {
51+
reject(error);
52+
}
4953
});
5054
}
5155
// get callbacks from props (default: NOOP) to set them to Tabulator options later.

lib/React15Tabulator.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ export default class extends React.Component<IProps, Partial<IState>> {
1414
componentWillUnmount(): void;
1515
componentWillReceiveProps(props: IProps): void;
1616
pickValidHTMLProps: () => void;
17-
render(): JSX.Element;
17+
render(): React.JSX.Element;
1818
}
1919
export {};

lib/React15Tabulator.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
4040
function verb(n) { return function (v) { return step([n, v]); }; }
4141
function step(op) {
4242
if (f) throw new TypeError("Generator is already executing.");
43-
while (_) try {
43+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
4444
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
4545
if (y = 0, t) op = [op[0] & 2, t.value];
4646
switch (op[0]) {
@@ -79,12 +79,12 @@ var default_1 = /** @class */ (function (_super) {
7979
};
8080
_this.ref = null;
8181
_this.htmlProps = null;
82-
_this.mainId = "tabulator-" + +new Date() + "-" + Math.floor(Math.random() * 9999999); // random id
82+
_this.mainId = "tabulator-".concat(+new Date(), "-").concat(Math.floor(Math.random() * 9999999)); // random id
8383
_this.table = null; // will be set once Tabulator instantiated
8484
_this.pickValidHTMLProps = function () {
8585
// run once
8686
if (!_this.htmlProps) {
87-
_this.htmlProps = pick_react_known_prop_1.pickHTMLProps(_this.props); // pick valid html props
87+
_this.htmlProps = (0, pick_react_known_prop_1.pickHTMLProps)(_this.props); // pick valid html props
8888
delete _this.htmlProps['data']; // don't render data & columns as attributes
8989
delete _this.htmlProps['columns'];
9090
}
@@ -100,15 +100,14 @@ var default_1 = /** @class */ (function (_super) {
100100
domEle = ReactDOM.findDOMNode(this.ref);
101101
that = this;
102102
_a = this.props, columns = _a.columns, data = _a.data, options = _a.options;
103-
return [4 /*yield*/, ConfigUtils_1.propsToOptions(this.props)];
103+
return [4 /*yield*/, (0, ConfigUtils_1.propsToOptions)(this.props)];
104104
case 1:
105105
propOptions = _b.sent();
106106
new tabulator_tables_1.Tabulator(domEle, __assign(__assign(__assign(__assign({ columns: columns }, propOptions), { layout: 'fitColumns', // fit columns to width of table (optional)
107107
tableBuilding: function () {
108108
that.table = this; // keep table instance
109109
that.props.tableBuilding ? that.props.tableBuilding() : '';
110-
},
111-
dataLoaded: function () {
110+
}, dataLoaded: function () {
112111
that.props.dataLoaded ? that.props.dataLoaded() : '';
113112
}, invalidOptionWarnings: false }), options), { data: data }));
114113
// await table.setData(data);
@@ -127,13 +126,13 @@ var default_1 = /** @class */ (function (_super) {
127126
// this is for React 15.x only
128127
default_1.prototype.componentWillReceiveProps = function (props) {
129128
var _this = this;
130-
if (!Utils_1.isSameArray(this.state.data, props.data)) {
129+
if (!(0, Utils_1.isSameArray)(this.state.data, props.data)) {
131130
// console.log('- data changed');
132131
this.setState({ data: props.data }, function () {
133132
_this.table && _this.table.setData(_this.state.data);
134133
});
135134
}
136-
if (!Utils_1.isSameArray(this.state.columns, props.columns)) {
135+
if (!(0, Utils_1.isSameArray)(this.state.columns, props.columns)) {
137136
// console.log('- columns changed');
138137
this.setState({ columns: props.columns }, function () {
139138
_this.table && _this.table.setColumns(_this.state.columns);

lib/ReactTabulator.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference types="react" />
1+
import * as React from 'react';
22
import { Tabulator as TabulatorTypes } from './types/TabulatorTypes';
33
export interface ReactTabulatorOptions extends TabulatorTypes.Options {
44
[k: string]: any;
@@ -12,5 +12,5 @@ export interface ReactTabulatorProps {
1212
onRef?: (ref: any) => void;
1313
[k: string]: any;
1414
}
15-
declare const ReactTabulator: (props: ReactTabulatorProps) => JSX.Element;
15+
declare const ReactTabulator: (props: ReactTabulatorProps) => React.JSX.Element;
1616
export default ReactTabulator;

lib/ReactTabulator.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
2525
function verb(n) { return function (v) { return step([n, v]); }; }
2626
function step(op) {
2727
if (f) throw new TypeError("Generator is already executing.");
28-
while (_) try {
28+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
2929
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
3030
if (y = 0, t) op = [op[0] & 2, t.value];
3131
switch (op[0]) {
@@ -48,7 +48,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
4848
};
4949
exports.__esModule = true;
5050
var React = require("react");
51-
var ReactDOM = require("react-dom");
5251
var pick_react_known_prop_1 = require("pick-react-known-prop");
5352
var ConfigUtils_1 = require("./ConfigUtils");
5453
/* tslint:disable-next-line */
@@ -58,9 +57,9 @@ var tabulator_tables_1 = require("tabulator-tables");
5857
var ReactTabulator = function (props) {
5958
var ref = React.useRef();
6059
var instanceRef = React.useRef();
61-
var _a = React.useState("tabulator-" + +new Date() + "-" + Math.floor(Math.random() * 9999999)), mainId = _a[0], setMainId = _a[1];
60+
var _a = React.useState("tabulator-".concat(+new Date(), "-").concat(Math.floor(Math.random() * 9999999))), mainId = _a[0], setMainId = _a[1];
6261
var htmlProps;
63-
htmlProps = pick_react_known_prop_1.pickHTMLProps(props); // pick valid html props
62+
htmlProps = (0, pick_react_known_prop_1.pickHTMLProps)(props); // pick valid html props
6463
delete htmlProps['data']; // don't render data & columns as attributes
6564
delete htmlProps['columns'];
6665
var initTabulator = function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -69,9 +68,9 @@ var ReactTabulator = function (props) {
6968
return __generator(this, function (_b) {
7069
switch (_b.label) {
7170
case 0:
72-
domEle = ReactDOM.findDOMNode(ref.current);
71+
domEle = ref.current;
7372
columns = props.columns, data = props.data, options = props.options;
74-
return [4 /*yield*/, ConfigUtils_1.propsToOptions(props)];
73+
return [4 /*yield*/, (0, ConfigUtils_1.propsToOptions)(props)];
7574
case 1:
7675
propOptions = _b.sent();
7776
if (data) {
@@ -93,11 +92,17 @@ var ReactTabulator = function (props) {
9392
React.useEffect(function () {
9493
// console.log('useEffect - onmount');
9594
initTabulator();
95+
// Cleanup function to destroy Tabulator instance on unmount
96+
return function () {
97+
if (instanceRef.current) {
98+
instanceRef.current.destroy();
99+
}
100+
};
96101
}, []);
97102
React.useEffect(function () {
98103
// console.log('useEffect - props.data changed');
99-
if (instanceRef && instanceRef.current) {
100-
initTabulator(); // re-init table
104+
if (instanceRef === null || instanceRef === void 0 ? void 0 : instanceRef.current) {
105+
initTabulator();
101106
}
102107
}, [props.data]);
103108
return React.createElement("div", __assign({ ref: ref, "data-instance": mainId }, htmlProps, { className: props.className }));

lib/ReactTabulatorExample.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
/// <reference types="react" />
2-
declare const _default: () => JSX.Element;
1+
import * as React from 'react';
2+
declare const _default: () => React.JSX.Element;
33
export default _default;

lib/ReactTabulatorExample.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var columns = [
2222
{ title: 'Date Of Birth', field: 'dob', sorter: 'date' },
2323
{ title: 'Rating', field: 'rating', hozAlign: 'center', formatter: 'star' },
2424
{ title: 'Passed?', field: 'passed', hozAlign: 'center', formatter: 'tickCross' },
25-
{ title: 'Custom', field: 'custom', hozAlign: 'center', editor: 'input', formatter: Utils_1.reactFormatter(React.createElement(SimpleButton, null)) }
25+
{ title: 'Custom', field: 'custom', hozAlign: 'center', editor: 'input', formatter: (0, Utils_1.reactFormatter)(React.createElement(SimpleButton, null)) }
2626
];
2727
var data = [
2828
{ id: 1, name: 'Oli Bob', age: '12', color: 'red', dob: '01/01/1980', rating: 5, passed: true, pets: ['cat', 'dog'] },

0 commit comments

Comments
 (0)