@carbonorm/carbonreact 3.4.2 → 3.4.5
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/dist/api/hoc/getStatefulObjectWithWhere.d.ts +11 -0
- package/dist/api/hoc/watchInputElementChangeEvent.d.ts +2 -0
- package/dist/components/WebSocket/CarbonWebSocket.d.ts +8 -4
- package/dist/index.cjs.js +26 -10
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.js +26 -12
- package/dist/index.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/api/hoc/getStatefulObjectWithWhere.tsx +17 -0
- package/src/api/hoc/watchInputElementChangeEvent.tsx +24 -0
- package/src/components/WebSocket/CarbonWebSocket.tsx +22 -11
- package/src/index.ts +4 -0
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbonorm/carbonreact",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.5",
|
|
4
4
|
"browser": "dist/index.umd.js",
|
|
5
5
|
"module": "dist/index.esm.js",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@carbonorm/carbonnode": "^1.2.
|
|
10
|
+
"@carbonorm/carbonnode": "^1.2.14",
|
|
11
11
|
"@fortawesome/fontawesome-svg-core": "^6.4.0",
|
|
12
12
|
"@fortawesome/free-solid-svg-icons": "^6.4.0",
|
|
13
13
|
"@fortawesome/react-fontawesome": "^0.2.0",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"scripts": {
|
|
71
71
|
"prepublishOnly": "npm run build",
|
|
72
72
|
"c6": "wget https://raw.githubusercontent.com/RichardTMiles/CarbonPHP/lts/view/C6.tsx -O src/variables/C6.tsx",
|
|
73
|
-
"build": "rm -rf ./dist/ && npm run build:css && npm run build:index && rollup -c && npm run build:compileValidSQL",
|
|
73
|
+
"build": "rm -rf ./dist/ ./src/api/rest/ && npm run build:css && npm run build:index && rollup -c && npm run build:compileValidSQL",
|
|
74
74
|
"dev": "rollup -c -w",
|
|
75
75
|
"test": "node test/test.js",
|
|
76
76
|
"pretest": "npm run build",
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {iAPI} from "@carbonorm/carbonnode";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
interface iWHERE {
|
|
5
|
+
[key: string]: any|iWHERE
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface iGetStatefulObjectWithWhere {
|
|
9
|
+
WHERE: iWHERE | iWHERE[]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default ({request}: { request: iAPI<any> & iWHERE }) => {
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {ChangeEvent} from "react";
|
|
2
|
+
import {timeout} from "@carbonorm/carbonnode";
|
|
3
|
+
|
|
4
|
+
export default function watchInputElementChangeEvent(event: ChangeEvent<HTMLInputElement>, cb: (event: ChangeEvent<HTMLInputElement>) => (Promise<boolean> | boolean), timeoutMs: number = 3000) {
|
|
5
|
+
|
|
6
|
+
const target = event.target;
|
|
7
|
+
|
|
8
|
+
const value = target.value;
|
|
9
|
+
|
|
10
|
+
event.target.style.color = "orange";
|
|
11
|
+
|
|
12
|
+
timeout(() => value === ((() => target.value)()),
|
|
13
|
+
async () => {
|
|
14
|
+
|
|
15
|
+
const callbackResult = await cb(event);
|
|
16
|
+
|
|
17
|
+
console.log('User provided input callbackResult passed to WatchInputElementChangeEvent (will cause green or red) value (' + value + ')', callbackResult)
|
|
18
|
+
|
|
19
|
+
target.style.color = false === callbackResult ? "red" : "green"
|
|
20
|
+
|
|
21
|
+
},
|
|
22
|
+
timeoutMs)
|
|
23
|
+
|
|
24
|
+
}
|
|
@@ -4,11 +4,22 @@ import {useEffectOnce} from "../../api/hoc/useEffectOnce";
|
|
|
4
4
|
import {tC6Tables} from "@carbonorm/carbonnode";
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
export interface iCarbonWebSocketProps {
|
|
8
|
+
url?: string,
|
|
9
|
+
timeoutSeconds?: number,
|
|
10
|
+
heartbeatSeconds?: number,
|
|
11
|
+
TABLES?: tC6Tables
|
|
12
|
+
}
|
|
13
|
+
|
|
7
14
|
/**
|
|
8
15
|
* @function connect
|
|
9
16
|
* This function establishes a connection with the websocket and also ensures constant reconnection if connection closes
|
|
10
17
|
**/
|
|
11
|
-
export function initiateWebsocket({TABLES = undefined
|
|
18
|
+
export function initiateWebsocket({TABLES = undefined,
|
|
19
|
+
url = 'ws://localhost:8080/ws',
|
|
20
|
+
timeoutSeconds = 250,
|
|
21
|
+
heartbeatSeconds = 60
|
|
22
|
+
}: iCarbonWebSocketProps = {}) {
|
|
12
23
|
|
|
13
24
|
const {websocket} = CarbonReact.instance.state;
|
|
14
25
|
|
|
@@ -32,9 +43,9 @@ export function initiateWebsocket({TABLES = undefined}: {TABLES?: tC6Tables} = {
|
|
|
32
43
|
|
|
33
44
|
let connectInterval;
|
|
34
45
|
|
|
35
|
-
const connection = new WebSocket(
|
|
46
|
+
const connection = new WebSocket(url);
|
|
36
47
|
|
|
37
|
-
console.log("Connecting websocket url",
|
|
48
|
+
console.log("Connecting websocket url", url);
|
|
38
49
|
|
|
39
50
|
CarbonReact.instance.setState({
|
|
40
51
|
websocket: connection
|
|
@@ -42,7 +53,7 @@ export function initiateWebsocket({TABLES = undefined}: {TABLES?: tC6Tables} = {
|
|
|
42
53
|
|
|
43
54
|
connection.onopen = () => {
|
|
44
55
|
|
|
45
|
-
console.log('WebSocket Client Connected To :: ' +
|
|
56
|
+
console.log('WebSocket Client Connected To :: ' + url);
|
|
46
57
|
|
|
47
58
|
clearTimeout(connectInterval); // clear Interval on open of websocket connection
|
|
48
59
|
|
|
@@ -56,7 +67,7 @@ export function initiateWebsocket({TABLES = undefined}: {TABLES?: tC6Tables} = {
|
|
|
56
67
|
|
|
57
68
|
websocket.send("ping");
|
|
58
69
|
|
|
59
|
-
setTimeout(heartbeat,
|
|
70
|
+
setTimeout(heartbeat, heartbeatSeconds * 1000);
|
|
60
71
|
|
|
61
72
|
}
|
|
62
73
|
|
|
@@ -64,7 +75,7 @@ export function initiateWebsocket({TABLES = undefined}: {TABLES?: tC6Tables} = {
|
|
|
64
75
|
|
|
65
76
|
};
|
|
66
77
|
|
|
67
|
-
connection.onmessage = (message: MessageEvent<string>
|
|
78
|
+
connection.onmessage = (message: MessageEvent<string>) => {
|
|
68
79
|
|
|
69
80
|
const parsedData = isJsonString(message?.data) ? JSON.parse(message?.data) : message?.data;
|
|
70
81
|
|
|
@@ -73,7 +84,7 @@ export function initiateWebsocket({TABLES = undefined}: {TABLES?: tC6Tables} = {
|
|
|
73
84
|
websocketData: prevState.websocketData.concat(parsedData), // JSON.parse no good - base64?
|
|
74
85
|
}));
|
|
75
86
|
|
|
76
|
-
console.
|
|
87
|
+
console.info('todo - going to impl TABLES', TABLES)
|
|
77
88
|
|
|
78
89
|
/*if (undefined !== TABLES) {
|
|
79
90
|
|
|
@@ -97,9 +108,9 @@ export function initiateWebsocket({TABLES = undefined}: {TABLES?: tC6Tables} = {
|
|
|
97
108
|
|
|
98
109
|
const retry = () => {
|
|
99
110
|
|
|
100
|
-
const retrySeconds = Math.min(5000, (
|
|
111
|
+
const retrySeconds = Math.min(5000, (timeoutSeconds + timeoutSeconds) * 1000)
|
|
101
112
|
|
|
102
|
-
|
|
113
|
+
timeoutSeconds = retrySeconds;
|
|
103
114
|
|
|
104
115
|
console.log(`WebSocket reconnect will be attempted in ${retrySeconds} second(s).`)
|
|
105
116
|
|
|
@@ -168,11 +179,11 @@ export function initiateWebsocket({TABLES = undefined}: {TABLES?: tC6Tables} = {
|
|
|
168
179
|
|
|
169
180
|
}
|
|
170
181
|
|
|
171
|
-
export default function () {
|
|
182
|
+
export default function (props: iCarbonWebSocketProps) {
|
|
172
183
|
|
|
173
184
|
useEffectOnce(() => {
|
|
174
185
|
|
|
175
|
-
initiateWebsocket()
|
|
186
|
+
initiateWebsocket(props)
|
|
176
187
|
|
|
177
188
|
})
|
|
178
189
|
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
export { default as CarbonReact } from "./CarbonReact";
|
|
6
6
|
export * from "./CarbonReact";
|
|
7
|
+
export { default as getStatefulObjectWithWhere } from "./api/hoc/getStatefulObjectWithWhere";
|
|
8
|
+
export * from "./api/hoc/getStatefulObjectWithWhere";
|
|
7
9
|
export * from "./api/hoc/useEffectOnce";
|
|
10
|
+
export { default as watchInputElementChangeEvent } from "./api/hoc/watchInputElementChangeEvent";
|
|
11
|
+
export * from "./api/hoc/watchInputElementChangeEvent";
|
|
8
12
|
export { default as Alert } from "./components/Alert/Alert";
|
|
9
13
|
export * from "./components/Alert/Alert";
|
|
10
14
|
export { default as AccessDenied } from "./components/Errors/AccessDenied";
|