@carbonorm/carbonreact 4.0.24 → 5.0.4

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 CHANGED
@@ -23,21 +23,26 @@ npm install @carbonorm/carbonreact
23
23
 
24
24
  ## Generate Models
25
25
 
26
- The command below will generate the models for the database. The models will be generated in the output directory. We do
27
- recommend you keep this folder separate from other work. It is also best to track the output directory in your version
28
- control system. All arguments are optional. If you do not provide them the defaults will be used. The example arguments
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 /src/api/rest
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
- You can view the [code generated](https://github.com/CarbonORM/CarbonORM.dev/blob/www/src/api/rest/Users.tsx) by
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
- For more information on CarbonNode and the generations please see the [CarbonNode](https://github.com/CarbonORM/CarbonNode).
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(<React.StrictMode><CarbonORM /></React.StrictMode>);
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
@@ -0,0 +1,9 @@
1
+ import { ReactNode } from 'react';
2
+ interface OutsideClickHandlerProps {
3
+ onOutsideClick: () => any;
4
+ children: ReactNode;
5
+ disabled?: boolean;
6
+ useCapture?: boolean;
7
+ }
8
+ export default function OutsideClickHandler({ onOutsideClick, children, disabled, useCapture }: OutsideClickHandlerProps): import("react/jsx-runtime").JSX.Element;
9
+ export {};