@carbonorm/carbonreact 4.0.25 → 6.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 +45 -12
- package/dist/components/Alert/Alert.d.ts +1 -1
- package/dist/components/Errors/BackendThrowable.d.ts +1 -1
- package/dist/components/WebSocket/CarbonWebSocket.d.ts +1 -1
- package/dist/{CarbonReact.d.ts → core/CarbonReact.d.ts} +4 -4
- package/dist/env/getEnv.d.ts +1 -0
- package/dist/env/isProduction.d.ts +2 -0
- package/dist/index.cjs +3436 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.cjs.css → index.css} +5102 -5102
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +41 -44
- package/dist/index.esm.css +5101 -5101
- package/dist/index.esm.css.map +1 -1
- package/dist/index.esm.js +719 -1228
- package/dist/index.esm.js.map +1 -1
- package/dist/{variables → schema}/C6.d.ts +1 -1
- package/dist/{hoc → state}/deleteRestfulObjectArrays.d.ts +2 -2
- package/dist/{hoc → state}/updateRestfulObjectArrays.d.ts +2 -2
- package/dist/{hoc → styles}/getStyles.d.ts +1 -1
- package/package.json +17 -6
- package/src/components/Alert/Alert.tsx +4 -5
- package/src/components/Errors/BackendThrowable.tsx +2 -2
- package/src/components/Loading/Loading.tsx +1 -2
- package/src/components/Popup/Popup.tsx +1 -2
- package/src/components/WebSocket/CarbonWebSocket.tsx +86 -72
- package/src/{CarbonReact.tsx → core/CarbonReact.tsx} +18 -24
- package/src/{hoc → dom}/isEdgeBrowser.tsx +4 -2
- package/src/{hoc → dom}/setCookies.tsx +1 -1
- package/src/env/getEnv.ts +29 -0
- package/src/env/isProduction.tsx +6 -0
- package/src/{api/hoc → hooks}/useEffectOnce.tsx +2 -2
- package/src/{hoc → hooks}/windowDimensions.tsx +9 -1
- package/src/index.ts +41 -44
- package/src/{variables → schema}/C6.tsx +1 -2
- package/src/{hoc → state}/deleteRestfulObjectArrays.tsx +2 -2
- package/src/{hoc → state}/updateRestfulObjectArrays.tsx +3 -3
- package/src/{hoc → styles}/getStyles.tsx +6 -2
- package/src/{hoc → testing}/setupTests.tsx +18 -14
- package/dist/components/Nest/Nest.d.ts +0 -49
- package/dist/hoc/setUrl.d.ts +0 -1
- package/dist/index.cjs.css.map +0 -1
- package/dist/index.cjs.js +0 -3946
- package/dist/index.cjs.js.map +0 -1
- package/dist/variables/isProduction.d.ts +0 -2
- package/src/components/Nest/Nest.tsx +0 -241
- package/src/hoc/setUrl.tsx +0 -38
- package/src/variables/isProduction.tsx +0 -5
- /package/dist/api/{hoc/getStatefulObjectWithWhere.d.ts → getStatefulObjectWithWhere.d.ts} +0 -0
- /package/dist/{hoc → dom}/isEdgeBrowser.d.ts +0 -0
- /package/dist/{hoc → dom}/scrollIntoView.d.ts +0 -0
- /package/dist/{hoc → dom}/setCookies.d.ts +0 -0
- /package/dist/{hoc → dom}/uploadImage.d.ts +0 -0
- /package/dist/{api/hoc → dom}/watchInputElementChangeEvent.d.ts +0 -0
- /package/dist/{api/hoc → hooks}/useEffectOnce.d.ts +0 -0
- /package/dist/{hoc → hooks}/windowDimensions.d.ts +0 -0
- /package/dist/{hoc → routing}/GlobalHistory.d.ts +0 -0
- /package/dist/{hoc → testing}/addValidSQL.d.ts +0 -0
- /package/dist/{hoc → testing}/setupTests.d.ts +0 -0
- /package/dist/{hoc → testing}/validSQL.d.ts +0 -0
- /package/dist/{hoc → types}/KeysMatching.d.ts +0 -0
- /package/dist/{hoc → types}/SubsetMatching.d.ts +0 -0
- /package/dist/{hoc → utils}/changed.d.ts +0 -0
- /package/dist/{hoc → utils}/hexToRgb.d.ts +0 -0
- /package/dist/{hoc → utils}/parseMultipleJson.d.ts +0 -0
- /package/src/api/{hoc/getStatefulObjectWithWhere.tsx → getStatefulObjectWithWhere.tsx} +0 -0
- /package/src/{hoc → dom}/scrollIntoView.tsx +0 -0
- /package/src/{hoc → dom}/uploadImage.tsx +0 -0
- /package/src/{api/hoc → dom}/watchInputElementChangeEvent.tsx +0 -0
- /package/src/{hoc → routing}/GlobalHistory.tsx +0 -0
- /package/src/{variables → styles}/bootstrap.module.css +0 -0
- /package/src/{variables → styles}/bootstrap.module.css.d.ts +0 -0
- /package/src/{variables → styles}/bootstrap.module.css.json +0 -0
- /package/src/{variables → styles}/bootstrap.module.css.map +0 -0
- /package/src/{variables → styles}/bootstrap.module.scss +0 -0
- /package/src/{variables → styles}/bootstrap.module.scss.d.ts +0 -0
- /package/src/{hoc → testing}/addValidSQL.tsx +0 -0
- /package/src/{hoc → testing}/validSQL.tsx +0 -0
- /package/src/{hoc → types}/KeysMatching.ts +0 -0
- /package/src/{hoc → types}/SubsetMatching.ts +0 -0
- /package/src/{hoc → utils}/changed.tsx +0 -0
- /package/src/{hoc → utils}/hexToRgb.tsx +0 -0
- /package/src/{hoc → utils}/parseMultipleJson.tsx +0 -0
package/README.md
CHANGED
|
@@ -23,21 +23,26 @@ npm install @carbonorm/carbonreact
|
|
|
23
23
|
|
|
24
24
|
## Generate Models
|
|
25
25
|
|
|
26
|
-
The command below
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
below are the defaults.
|
|
26
|
+
The command below generates a single `C6.ts` file containing your tables, types, and REST bindings. Keep the output in
|
|
27
|
+
version control and import from it on both server and client. All arguments are optional. If you do not provide them the
|
|
28
|
+
defaults will be used. The example arguments below are the defaults.
|
|
30
29
|
|
|
31
30
|
```bash
|
|
32
|
-
npx generateRestBindings --user root --pass password --host 127.0.0.1 --port 3306 --dbname carbonPHP --prefix carbon_ --output /
|
|
31
|
+
npx generateRestBindings --user root --pass password --host 127.0.0.1 --port 3306 --dbname carbonPHP --prefix carbon_ --output ./shared/rest/C6.ts
|
|
33
32
|
```
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
[this command](https://github.com/CarbonORM/CarbonNode/blob/main/scripts/generateRestBindings.ts) in
|
|
37
|
-
[this repository](git@github.com:CarbonORM/CarbonNode.git). We use [Handlebars templates](https://mustache.github.io/)
|
|
38
|
-
to generate the code.
|
|
34
|
+
The generated file exports `C6`, `GLOBAL_REST_PARAMETERS`, and per-table bindings (e.g. `Users`):
|
|
39
35
|
|
|
40
|
-
|
|
36
|
+
```typescript
|
|
37
|
+
import { C6, GLOBAL_REST_PARAMETERS, Users } from "./shared/rest/C6";
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
You can view the generator source in
|
|
41
|
+
[CarbonNode](https://github.com/CarbonORM/CarbonNode/blob/main/scripts/generateRestBindings.ts). We use
|
|
42
|
+
[Handlebars templates](https://mustache.github.io/) to generate the code.
|
|
43
|
+
|
|
44
|
+
For more information on CarbonNode and the generations please see the
|
|
45
|
+
[CarbonNode](https://github.com/CarbonORM/CarbonNode).
|
|
41
46
|
|
|
42
47
|
|
|
43
48
|
## QuickStart Implementation
|
|
@@ -61,7 +66,11 @@ const container = document.getElementById('root');
|
|
|
61
66
|
|
|
62
67
|
const root = createRoot(container!);
|
|
63
68
|
|
|
64
|
-
root.render(
|
|
69
|
+
root.render(
|
|
70
|
+
<React.StrictMode>
|
|
71
|
+
<CarbonORM />
|
|
72
|
+
</React.StrictMode>
|
|
73
|
+
);
|
|
65
74
|
```
|
|
66
75
|
|
|
67
76
|
CarbonReact should be loaded as soon as the page loads. There are plans to allow other alerting systems to be used, but
|
|
@@ -129,7 +138,6 @@ export default class CarbonORM extends CarbonReact<{ browserRouter?: boolean },
|
|
|
129
138
|
}
|
|
130
139
|
|
|
131
140
|
return reactRouterContext(<>
|
|
132
|
-
<CarbonWebSocket url={'ws://localhost:8888/ws'}/>
|
|
133
141
|
<Routes>
|
|
134
142
|
<Route path={UI + "*"}>
|
|
135
143
|
<Route path={MATERIAL_DASHBOARD + "*"} element={ppr(Dashboard, {})}>
|
|
@@ -188,6 +196,31 @@ export default class CarbonORM extends CarbonReact<{ browserRouter?: boolean },
|
|
|
188
196
|
}
|
|
189
197
|
```
|
|
190
198
|
|
|
199
|
+
## Websocket Updates (Optional)
|
|
200
|
+
|
|
201
|
+
Backend: broadcast the payload generated by CarbonNode on every write (POST/PUT/DELETE).
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
import { GLOBAL_REST_PARAMETERS } from "./shared/rest/C6";
|
|
205
|
+
|
|
206
|
+
GLOBAL_REST_PARAMETERS.websocketBroadcast = (payload) => {
|
|
207
|
+
wsServer.broadcast(JSON.stringify(payload));
|
|
208
|
+
};
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Frontend: pass `C6` into CarbonReact so the websocket client can normalize updates and only apply them when the row is
|
|
212
|
+
already in local state. Debug logs only appear when `VERBOSE` is enabled.
|
|
213
|
+
|
|
214
|
+
```typescript jsx
|
|
215
|
+
import { C6 } from "./shared/rest/C6";
|
|
216
|
+
|
|
217
|
+
root.render(
|
|
218
|
+
<React.StrictMode>
|
|
219
|
+
<CarbonORM websocket={{ C6, url: "ws://localhost:8888/carbonorm/websocket" }} />
|
|
220
|
+
</React.StrictMode>
|
|
221
|
+
);
|
|
222
|
+
```
|
|
223
|
+
|
|
191
224
|
|
|
192
225
|
Our testing tool [Jest](https://www.npmjs.com/package/jest) requires [React Router Dom](https://www.npmjs.com/package/react-router-dom)
|
|
193
226
|
to be in `MemoryRouter` mode. This is because Jest does not have a DOM and therefore cannot render the `HashRouter` or
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import CarbonReact, { iCarbonReactState } from "
|
|
1
|
+
import CarbonReact, { iCarbonReactState } from "core/CarbonReact";
|
|
2
2
|
import { ReactElement } from "react";
|
|
3
3
|
declare const _default: <P, S extends iCarbonReactState>(props: {
|
|
4
4
|
instance: CarbonReact<P, S>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import CarbonReact, { iCarbonReactState } from "CarbonReact";
|
|
1
|
+
import CarbonReact, { iCarbonReactState } from "core/CarbonReact";
|
|
2
2
|
import { iC6Object } from "@carbonorm/carbonnode";
|
|
3
3
|
export interface iCarbonWebSocketProps<P, S extends iCarbonReactState> {
|
|
4
4
|
url?: string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Component, Context, ReactElement, ReactNode } from 'react';
|
|
2
2
|
import 'react-toastify/dist/ReactToastify.css';
|
|
3
|
-
import { iRestfulObjectArrayTypes } from "
|
|
4
|
-
import { iCarbonWebSocketProps } from "
|
|
5
|
-
import { iUpdateRestfulObjectArrays } from "
|
|
6
|
-
import { iDeleteRestfulObjectArrays } from "
|
|
3
|
+
import { iRestfulObjectArrayTypes } from "schema/C6";
|
|
4
|
+
import { iCarbonWebSocketProps } from "components/WebSocket/CarbonWebSocket";
|
|
5
|
+
import { iUpdateRestfulObjectArrays } from "state/updateRestfulObjectArrays";
|
|
6
|
+
import { iDeleteRestfulObjectArrays } from "state/deleteRestfulObjectArrays";
|
|
7
7
|
export type tStatefulApiData<T extends {
|
|
8
8
|
[key: string]: any;
|
|
9
9
|
} = {}> = T[] | undefined | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getEnv<T = string>(key: string, fallback?: T): T;
|