@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
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { iAPI } from "@carbonorm/carbonnode";
|
|
2
|
+
interface iWHERE {
|
|
3
|
+
[key: string]: any | iWHERE;
|
|
4
|
+
}
|
|
5
|
+
export interface iGetStatefulObjectWithWhere {
|
|
6
|
+
WHERE: iWHERE | iWHERE[];
|
|
7
|
+
}
|
|
8
|
+
declare const _default: ({ request }: {
|
|
9
|
+
request: iAPI<any> & iWHERE;
|
|
10
|
+
}) => void;
|
|
11
|
+
export default _default;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { tC6Tables } from "@carbonorm/carbonnode";
|
|
2
|
+
export interface iCarbonWebSocketProps {
|
|
3
|
+
url?: string;
|
|
4
|
+
timeoutSeconds?: number;
|
|
5
|
+
heartbeatSeconds?: number;
|
|
6
|
+
TABLES?: tC6Tables;
|
|
7
|
+
}
|
|
2
8
|
/**
|
|
3
9
|
* @function connect
|
|
4
10
|
* This function establishes a connection with the websocket and also ensures constant reconnection if connection closes
|
|
5
11
|
**/
|
|
6
|
-
export declare function initiateWebsocket({ TABLES }?:
|
|
7
|
-
|
|
8
|
-
}): void;
|
|
9
|
-
export default function (): null;
|
|
12
|
+
export declare function initiateWebsocket({ TABLES, url, timeoutSeconds, heartbeatSeconds }?: iCarbonWebSocketProps): void;
|
|
13
|
+
export default function (props: iCarbonWebSocketProps): null;
|
package/dist/index.cjs.js
CHANGED
|
@@ -4049,7 +4049,7 @@ const useEffectOnce = (effect) => {
|
|
|
4049
4049
|
* @function connect
|
|
4050
4050
|
* This function establishes a connection with the websocket and also ensures constant reconnection if connection closes
|
|
4051
4051
|
**/
|
|
4052
|
-
function initiateWebsocket({ TABLES = undefined } = {}) {
|
|
4052
|
+
function initiateWebsocket({ TABLES = undefined, url = 'ws://localhost:8080/ws', timeoutSeconds = 250, heartbeatSeconds = 60 } = {}) {
|
|
4053
4053
|
const { websocket } = CarbonReact.instance.state;
|
|
4054
4054
|
if (!("WebSocket" in window)) {
|
|
4055
4055
|
// todo - store that this has been shown in the state
|
|
@@ -4063,13 +4063,13 @@ function initiateWebsocket({ TABLES = undefined } = {}) {
|
|
|
4063
4063
|
return;
|
|
4064
4064
|
}
|
|
4065
4065
|
let connectInterval;
|
|
4066
|
-
const connection = new WebSocket(
|
|
4067
|
-
console.log("Connecting websocket url",
|
|
4066
|
+
const connection = new WebSocket(url);
|
|
4067
|
+
console.log("Connecting websocket url", url);
|
|
4068
4068
|
CarbonReact.instance.setState({
|
|
4069
4069
|
websocket: connection
|
|
4070
4070
|
}, () => {
|
|
4071
4071
|
connection.onopen = () => {
|
|
4072
|
-
console.log('WebSocket Client Connected To :: ' +
|
|
4072
|
+
console.log('WebSocket Client Connected To :: ' + url);
|
|
4073
4073
|
clearTimeout(connectInterval); // clear Interval on open of websocket connection
|
|
4074
4074
|
function heartbeat() {
|
|
4075
4075
|
const { websocket } = CarbonReact.instance.state;
|
|
@@ -4078,7 +4078,7 @@ function initiateWebsocket({ TABLES = undefined } = {}) {
|
|
|
4078
4078
|
if (websocket.readyState !== 1)
|
|
4079
4079
|
return;
|
|
4080
4080
|
websocket.send("ping");
|
|
4081
|
-
setTimeout(heartbeat,
|
|
4081
|
+
setTimeout(heartbeat, heartbeatSeconds * 1000);
|
|
4082
4082
|
}
|
|
4083
4083
|
heartbeat();
|
|
4084
4084
|
};
|
|
@@ -4088,7 +4088,7 @@ function initiateWebsocket({ TABLES = undefined } = {}) {
|
|
|
4088
4088
|
websocketEvents: prevState.websocketEvents.concat(message),
|
|
4089
4089
|
websocketData: prevState.websocketData.concat(parsedData), // JSON.parse no good - base64?
|
|
4090
4090
|
}));
|
|
4091
|
-
console.
|
|
4091
|
+
console.info('todo - going to impl TABLES', TABLES);
|
|
4092
4092
|
/*if (undefined !== TABLES) {
|
|
4093
4093
|
|
|
4094
4094
|
TABLES.
|
|
@@ -4102,8 +4102,8 @@ function initiateWebsocket({ TABLES = undefined } = {}) {
|
|
|
4102
4102
|
let reason;
|
|
4103
4103
|
console.log(`Socket is closed.`, event.reason, event);
|
|
4104
4104
|
const retry = () => {
|
|
4105
|
-
const retrySeconds = Math.min(5000, (
|
|
4106
|
-
|
|
4105
|
+
const retrySeconds = Math.min(5000, (timeoutSeconds + timeoutSeconds) * 1000);
|
|
4106
|
+
timeoutSeconds = retrySeconds;
|
|
4107
4107
|
console.log(`WebSocket reconnect will be attempted in ${retrySeconds} second(s).`);
|
|
4108
4108
|
connectInterval = setTimeout(() => initiateWebsocket(), retrySeconds);
|
|
4109
4109
|
};
|
|
@@ -4162,9 +4162,9 @@ function initiateWebsocket({ TABLES = undefined } = {}) {
|
|
|
4162
4162
|
});
|
|
4163
4163
|
});
|
|
4164
4164
|
}
|
|
4165
|
-
function CarbonWebSocket () {
|
|
4165
|
+
function CarbonWebSocket (props) {
|
|
4166
4166
|
useEffectOnce(() => {
|
|
4167
|
-
initiateWebsocket();
|
|
4167
|
+
initiateWebsocket(props);
|
|
4168
4168
|
});
|
|
4169
4169
|
return null;
|
|
4170
4170
|
}
|
|
@@ -4242,6 +4242,20 @@ const CarbonReact = class extends react.Component {
|
|
|
4242
4242
|
}
|
|
4243
4243
|
};
|
|
4244
4244
|
|
|
4245
|
+
var getStatefulObjectWithWhere = ({ request }) => {
|
|
4246
|
+
};
|
|
4247
|
+
|
|
4248
|
+
function watchInputElementChangeEvent(event, cb, timeoutMs = 3000) {
|
|
4249
|
+
const target = event.target;
|
|
4250
|
+
const value = target.value;
|
|
4251
|
+
event.target.style.color = "orange";
|
|
4252
|
+
carbonnode.timeout(() => value === ((() => target.value)()), async () => {
|
|
4253
|
+
const callbackResult = await cb(event);
|
|
4254
|
+
console.log('User provided input callbackResult passed to WatchInputElementChangeEvent (will cause green or red) value (' + value + ')', callbackResult);
|
|
4255
|
+
target.style.color = false === callbackResult ? "red" : "green";
|
|
4256
|
+
}, timeoutMs);
|
|
4257
|
+
}
|
|
4258
|
+
|
|
4245
4259
|
function AccessDenied({ children }) {
|
|
4246
4260
|
return (jsxRuntime_1("div", { children: jsxRuntime_1("div", { className: classes.notfound, children: jsxRuntime_2("div", { className: classes.notfound_404, children: [jsxRuntime_1("h3", { children: "Oops! Access not granted" }), children, jsxRuntime_2("h1", { style: {
|
|
4247
4261
|
position: "absolute",
|
|
@@ -4664,6 +4678,7 @@ exports.documentation = documentation;
|
|
|
4664
4678
|
exports.feature_group_references = feature_group_references;
|
|
4665
4679
|
exports.features = features;
|
|
4666
4680
|
exports.getRootStyleValue = getRootStyleValue;
|
|
4681
|
+
exports.getStatefulObjectWithWhere = getStatefulObjectWithWhere;
|
|
4667
4682
|
exports.getStyles = getStyles;
|
|
4668
4683
|
exports.group_references = group_references;
|
|
4669
4684
|
exports.groups = groups;
|
|
@@ -4698,6 +4713,7 @@ exports.user_sessions = user_sessions;
|
|
|
4698
4713
|
exports.user_tasks = user_tasks;
|
|
4699
4714
|
exports.users = users;
|
|
4700
4715
|
exports.validSQL = ValidSQL;
|
|
4716
|
+
exports.watchInputElementChangeEvent = watchInputElementChangeEvent;
|
|
4701
4717
|
exports.windowDimensions = useWindowDimensions;
|
|
4702
4718
|
exports.wp_commentmeta = wp_commentmeta;
|
|
4703
4719
|
exports.wp_comments = wp_comments;
|