@carbonorm/carbonreact 3.6.2 → 4.0.1
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 +1 -1
- package/dist/CarbonReact.d.ts +17 -8
- package/dist/components/Alert/Alert.d.ts +5 -1
- package/dist/components/Errors/BackendThrowable.d.ts +4 -1
- package/dist/components/WebSocket/CarbonWebSocket.d.ts +3 -1
- package/dist/hoc/KeysMatching.d.ts +1 -1
- package/dist/hoc/SubsetMatching.d.ts +4 -0
- package/dist/hoc/deleteRestfulObjectArrays.d.ts +17 -3
- package/dist/hoc/updateRestfulObjectArrays.d.ts +25 -11
- package/dist/index.cjs.js +156 -169
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +157 -170
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/CarbonReact.tsx +36 -21
- package/src/components/Alert/Alert.tsx +32 -29
- package/src/components/Errors/BackendThrowable.tsx +11 -8
- package/src/components/WebSocket/CarbonWebSocket.tsx +21 -15
- package/src/hoc/KeysMatching.ts +4 -2
- package/src/hoc/SubsetMatching.ts +6 -0
- package/src/hoc/deleteRestfulObjectArrays.tsx +51 -52
- package/src/hoc/updateRestfulObjectArrays.tsx +97 -97
- package/src/index.ts +1 -0
- package/src/variables/C6.tsx +1 -1
- package/dist/variables/C6.d.ts +0 -842
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ ideally once it has mounted it never gets unmounted. In application where this i
|
|
|
48
48
|
application even if the component is unmounted. The behavior of accessing or updating state while the component is
|
|
49
49
|
unknown (undefined) and should be avoided. The example below shows a simple implementation of CarbonReact. Our user
|
|
50
50
|
defined component is in `CarbonORM` which is written to extend the `CarbonReact` class. Your implementation must also
|
|
51
|
-
extend `CarbonORM
|
|
51
|
+
extend `CarbonReact`. The name `CarbonORM` is arbitrary and can be changed to your application's name.
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
[index.tsx](https://github.com/CarbonORM/CarbonORM.dev/blob/www/src/index.tsx)
|
package/dist/CarbonReact.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ import { Component, Context, ReactElement, ReactNode } from 'react';
|
|
|
2
2
|
import 'react-toastify/dist/ReactToastify.min.css';
|
|
3
3
|
import { iRestfulObjectArrayTypes } from "variables/C6";
|
|
4
4
|
import { iCarbonWebSocketProps } from "./components/WebSocket/CarbonWebSocket";
|
|
5
|
+
import { iUpdateRestfulObjectArrays } from "./hoc/updateRestfulObjectArrays";
|
|
6
|
+
import { iDeleteRestfulObjectArrays } from "./hoc/deleteRestfulObjectArrays";
|
|
7
|
+
export type tStatefulApiData<T extends {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
} = {}> = T[] | undefined | null;
|
|
5
10
|
export interface iCarbonReactState {
|
|
6
11
|
alertsWaiting: any[];
|
|
7
12
|
websocketEvents: MessageEvent[];
|
|
@@ -12,18 +17,22 @@ export interface iCarbonReactState {
|
|
|
12
17
|
export declare const initialRequiredCarbonORMState: iCarbonReactState;
|
|
13
18
|
export declare const initialCarbonReactState: iCarbonReactState & iRestfulObjectArrayTypes;
|
|
14
19
|
export declare function isJsonString(str: string): boolean;
|
|
15
|
-
declare abstract class CarbonReact<P = {}, S
|
|
20
|
+
declare abstract class CarbonReact<P = {}, S extends {
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
} = {}> extends Component<{
|
|
16
23
|
children?: ReactNode | ReactNode[];
|
|
17
24
|
instanceId?: string;
|
|
18
|
-
websocket?: iCarbonWebSocketProps | boolean;
|
|
25
|
+
websocket?: Omit<iCarbonWebSocketProps, "instance"> | boolean;
|
|
19
26
|
} & P, S & iCarbonReactState> {
|
|
20
27
|
context: Context<S & iCarbonReactState>;
|
|
21
|
-
protected static instance: CarbonReact
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
protected:
|
|
28
|
+
protected static instance: CarbonReact;
|
|
29
|
+
protected target: typeof CarbonReact;
|
|
30
|
+
protected updateRestfulObjectArrays: <ObjectType extends {
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
} = {}>(rest: Omit<iUpdateRestfulObjectArrays<ObjectType, S, P>, "instance">) => void;
|
|
33
|
+
protected deleteRestfulObjectArrays: <ObjectType extends {
|
|
34
|
+
[key: string]: any;
|
|
35
|
+
} = {}>(rest: Omit<iDeleteRestfulObjectArrays<ObjectType, S, P>, "instance">) => void;
|
|
27
36
|
static lastLocation: string;
|
|
28
37
|
static whyDidYouRender: boolean;
|
|
29
38
|
protected constructor(props: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import CarbonReact from "CarbonReact";
|
|
1
2
|
import { ReactNode } from "react";
|
|
2
3
|
export interface iAlertButtonOptions {
|
|
3
4
|
text: string;
|
|
@@ -8,6 +9,7 @@ export interface iAlertButtonOptions {
|
|
|
8
9
|
export interface iAlert {
|
|
9
10
|
title: string;
|
|
10
11
|
text: string;
|
|
12
|
+
instance: CarbonReact;
|
|
11
13
|
component?: ReactNode;
|
|
12
14
|
icon?: "warning" | "error" | "success" | "info" | "question" | null;
|
|
13
15
|
buttons?: (iAlertButtonOptions)[] | undefined;
|
|
@@ -21,4 +23,6 @@ export interface iAlert {
|
|
|
21
23
|
};
|
|
22
24
|
}
|
|
23
25
|
export declare function addAlert(props: iAlert): void;
|
|
24
|
-
export default function Alert(
|
|
26
|
+
export default function Alert({ instance }: {
|
|
27
|
+
instance: CarbonReact;
|
|
28
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import CarbonReact from "CarbonReact";
|
|
1
2
|
import { tC6Tables, tC6RestApi } from "@carbonorm/carbonnode";
|
|
2
3
|
export interface iCarbonWebSocketProps {
|
|
3
4
|
url?: string;
|
|
4
5
|
timeoutSeconds?: number;
|
|
5
6
|
heartbeatSeconds?: number;
|
|
7
|
+
instance: CarbonReact;
|
|
6
8
|
TABLES?: tC6Tables;
|
|
7
9
|
WsLiveUpdates?: tC6RestApi;
|
|
8
10
|
}
|
|
@@ -10,5 +12,5 @@ export interface iCarbonWebSocketProps {
|
|
|
10
12
|
* @function connect
|
|
11
13
|
* This function establishes a connection with the websocket and also ensures constant reconnection if connection closes
|
|
12
14
|
**/
|
|
13
|
-
export declare function initiateWebsocket(
|
|
15
|
+
export declare function initiateWebsocket(props: iCarbonWebSocketProps): void;
|
|
14
16
|
export default function (props: iCarbonWebSocketProps): null;
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import CarbonReact from "CarbonReact";
|
|
2
|
-
import { tRestfulObjectArrayValues, tStatefulApiData } from "variables/C6";
|
|
1
|
+
import CarbonReact, { tStatefulApiData } from "CarbonReact";
|
|
3
2
|
import { KeysMatching } from "./KeysMatching";
|
|
4
|
-
export
|
|
3
|
+
export interface iDeleteRestfulObjectArrays<ObjectType extends {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
} = {}, S extends {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
} = CarbonReact['state'], P = CarbonReact['props']> {
|
|
8
|
+
instance: CarbonReact<P, S>;
|
|
9
|
+
dataOrCallback: ObjectType[] | ((state: Readonly<S>, props: Readonly<P>) => ObjectType[] | null);
|
|
10
|
+
stateKey: KeysMatching<S, tStatefulApiData<ObjectType>>;
|
|
11
|
+
uniqueObjectId: keyof ObjectType | (keyof ObjectType)[];
|
|
12
|
+
callback?: () => void;
|
|
13
|
+
}
|
|
14
|
+
export default function deleteRestfulObjectArrays<ObjectType extends {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
} = {}, S extends {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
} = CarbonReact['state'], P = CarbonReact['props']>({ instance, dataOrCallback, stateKey, uniqueObjectId, callback }: iDeleteRestfulObjectArrays<ObjectType, S, P>): void;
|
|
@@ -1,19 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import CarbonReact from "CarbonReact";
|
|
1
|
+
import CarbonReact, { tStatefulApiData } from "CarbonReact";
|
|
3
2
|
import { KeysMatching } from "./KeysMatching";
|
|
4
3
|
export declare enum eUpdateInsertMethod {
|
|
5
4
|
REPLACE = 0,
|
|
6
5
|
FIRST = 1,
|
|
7
6
|
LAST = 2
|
|
8
7
|
}
|
|
8
|
+
export interface iUpdateRestfulObjectArrays<ObjectType extends {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
} = {}, S extends {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
} = CarbonReact['state'], P = CarbonReact['props']> {
|
|
13
|
+
instance: CarbonReact<P, S>;
|
|
14
|
+
dataOrCallback: ObjectType[] | ((state: Readonly<S>, props: Readonly<P>) => ObjectType[] | null);
|
|
15
|
+
stateKey: KeysMatching<S, tStatefulApiData<ObjectType>>;
|
|
16
|
+
uniqueObjectId: keyof ObjectType | (keyof ObjectType)[];
|
|
17
|
+
insertUpdateOrder?: eUpdateInsertMethod;
|
|
18
|
+
callback?: () => void;
|
|
19
|
+
}
|
|
9
20
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @param dataOrCallback
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @param insertUpdateOrder
|
|
16
|
-
* @param callback -
|
|
17
|
-
* parameter of setState.
|
|
21
|
+
* Updates or inserts objects in a stateful array, merging new data with existing objects.
|
|
22
|
+
* @param instance - The React component instance.
|
|
23
|
+
* @param dataOrCallback - Array of objects or a callback function returning an array of objects.
|
|
24
|
+
* @param stateKey - The key in the state where the data array is stored.
|
|
25
|
+
* @param uniqueObjectId - The unique identifier(s) for objects, typically the primary key of the table.
|
|
26
|
+
* @param insertUpdateOrder - The order in which new data should be inserted/updated.
|
|
27
|
+
* @param callback - Optional callback function to run after state update.
|
|
18
28
|
*/
|
|
19
|
-
export default function updateRestfulObjectArrays<ObjectType
|
|
29
|
+
export default function updateRestfulObjectArrays<ObjectType extends {
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
} = {}, S extends {
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
} = CarbonReact['state'], P = CarbonReact['props']>({ instance, dataOrCallback, stateKey, uniqueObjectId, insertUpdateOrder, callback, }: iUpdateRestfulObjectArrays<ObjectType, S, P>): void;
|