@carbonorm/carbonreact 4.0.3 → 4.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.
@@ -17,19 +17,17 @@ export interface iCarbonReactState {
17
17
  export declare const initialRequiredCarbonORMState: iCarbonReactState;
18
18
  export declare const initialCarbonReactState: iCarbonReactState & iRestfulObjectArrayTypes;
19
19
  export declare function isJsonString(str: string): boolean;
20
- declare abstract class CarbonReact<P = {}, S extends {
21
- [key: string]: any;
22
- } = typeof initialCarbonReactState> extends Component<{
20
+ declare abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactState> extends Component<{
23
21
  children?: ReactNode | ReactNode[];
24
22
  instanceId?: string;
25
- websocket?: Omit<iCarbonWebSocketProps, "instance"> | boolean;
23
+ websocket?: Omit<iCarbonWebSocketProps<P, S>, "instance"> | false;
26
24
  } & P, S> {
27
25
  private static persistentStateMap;
28
- context: Context<S>;
26
+ context: Context<S & iCarbonReactState>;
29
27
  protected target: typeof CarbonReact;
30
- protected static _instance: CarbonReact;
31
- static get instance(): CarbonReact;
32
- static set instance(instance: CarbonReact);
28
+ protected static _instance: typeof this;
29
+ static get instance(): typeof this;
30
+ static set instance(instance: typeof this);
33
31
  protected updateRestfulObjectArrays: <ObjectType extends {
34
32
  [key: string]: any;
35
33
  } = {}>(rest: Omit<iUpdateRestfulObjectArrays<ObjectType, S, P>, "instance">) => void;
@@ -41,7 +39,7 @@ declare abstract class CarbonReact<P = {}, S extends {
41
39
  protected constructor(props: {
42
40
  children?: ReactNode | ReactNode[];
43
41
  shouldStatePersist?: boolean | undefined;
44
- websocket?: boolean | iCarbonWebSocketProps | undefined;
42
+ websocket?: boolean | iCarbonWebSocketProps<P, S> | undefined;
45
43
  } & P);
46
44
  shouldComponentUpdate(nextProps: Readonly<P>, nextState: Readonly<S>, _nextContext: any): boolean;
47
45
  componentDidUpdate(_prevProps: Readonly<P>, _prevState: Readonly<S>, _snapshot?: any): void;
@@ -1,4 +1,4 @@
1
- import CarbonReact from "CarbonReact";
1
+ import CarbonReact, { iCarbonReactState } from "CarbonReact";
2
2
  import { ReactNode } from "react";
3
3
  export interface iAlertButtonOptions {
4
4
  text: string;
@@ -6,10 +6,10 @@ export interface iAlertButtonOptions {
6
6
  className?: string;
7
7
  color: "default" | "primary" | "secondary" | "inherit" | "danger" | "info" | "success" | "warning" | undefined;
8
8
  }
9
- export interface iAlert {
9
+ export interface iAlert<P, S> {
10
10
  title: string;
11
11
  text: string;
12
- instance: CarbonReact;
12
+ instance: CarbonReact<P, S>;
13
13
  component?: ReactNode;
14
14
  icon?: "warning" | "error" | "success" | "info" | "question" | null;
15
15
  buttons?: (iAlertButtonOptions)[] | undefined;
@@ -22,7 +22,7 @@ export interface iAlert {
22
22
  [key: string]: any;
23
23
  };
24
24
  }
25
- export declare function addAlert(props: iAlert): void;
26
- export default function Alert({ instance }: {
27
- instance: CarbonReact;
25
+ export declare function addAlert<P, S extends Partial<iCarbonReactState>>(props: iAlert<P, S>): void;
26
+ export default function Alert<P, S extends Partial<iCarbonReactState>>({ instance }: {
27
+ instance: CarbonReact<P, S>;
28
28
  }): import("react/jsx-runtime").JSX.Element | null;
@@ -1,6 +1,6 @@
1
- import CarbonReact from "../../CarbonReact";
1
+ import CarbonReact, { iCarbonReactState } from "../../CarbonReact";
2
2
  import { ReactElement } from "react";
3
- declare const _default: (props: {
4
- instance: CarbonReact;
3
+ declare const _default: <P, S extends Partial<iCarbonReactState>>(props: {
4
+ instance: CarbonReact<P, S>;
5
5
  }) => ReactElement;
6
6
  export default _default;
@@ -1,10 +1,10 @@
1
- import CarbonReact from "CarbonReact";
1
+ import CarbonReact, { iCarbonReactState } from "CarbonReact";
2
2
  import { tC6Tables, tC6RestApi } from "@carbonorm/carbonnode";
3
- export interface iCarbonWebSocketProps {
3
+ export interface iCarbonWebSocketProps<P, S> {
4
4
  url?: string;
5
5
  timeoutSeconds?: number;
6
6
  heartbeatSeconds?: number;
7
- instance: CarbonReact;
7
+ instance: CarbonReact<P, S>;
8
8
  TABLES?: tC6Tables;
9
9
  WsLiveUpdates?: tC6RestApi;
10
10
  }
@@ -12,5 +12,5 @@ export interface iCarbonWebSocketProps {
12
12
  * @function connect
13
13
  * This function establishes a connection with the websocket and also ensures constant reconnection if connection closes
14
14
  **/
15
- export declare function initiateWebsocket(props: iCarbonWebSocketProps): void;
16
- export default function (props: iCarbonWebSocketProps): null;
15
+ export declare function initiateWebsocket<P, S extends Partial<iCarbonReactState>>(props: iCarbonWebSocketProps<P, S>): void;
16
+ export default function <P, S extends Partial<iCarbonReactState>>(props: iCarbonWebSocketProps<P, S>): null;
@@ -2,9 +2,7 @@ import CarbonReact, { tStatefulApiData } from "CarbonReact";
2
2
  import { KeysMatching } from "./KeysMatching";
3
3
  export interface iDeleteRestfulObjectArrays<ObjectType extends {
4
4
  [key: string]: any;
5
- } = {}, S extends {
6
- [key: string]: any;
7
- } = CarbonReact['state'], P = CarbonReact['props']> {
5
+ } = {}, S = CarbonReact['state'], P = CarbonReact['props']> {
8
6
  instance: CarbonReact<P, S>;
9
7
  dataOrCallback: ObjectType[] | ((state: Readonly<S>, props: Readonly<P>) => ObjectType[] | null);
10
8
  stateKey: KeysMatching<S, tStatefulApiData<ObjectType>>;
@@ -13,6 +11,4 @@ export interface iDeleteRestfulObjectArrays<ObjectType extends {
13
11
  }
14
12
  export default function deleteRestfulObjectArrays<ObjectType extends {
15
13
  [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;
14
+ } = {}, S = CarbonReact['state'], P = CarbonReact['props']>({ instance, dataOrCallback, stateKey, uniqueObjectId, callback }: iDeleteRestfulObjectArrays<ObjectType, S, P>): void;
@@ -1,4 +1,4 @@
1
- import CarbonReact, { tStatefulApiData } from "CarbonReact";
1
+ import CarbonReact, { iCarbonReactState, tStatefulApiData } from "CarbonReact";
2
2
  import { KeysMatching } from "./KeysMatching";
3
3
  export declare enum eUpdateInsertMethod {
4
4
  REPLACE = 0,
@@ -7,9 +7,7 @@ export declare enum eUpdateInsertMethod {
7
7
  }
8
8
  export interface iUpdateRestfulObjectArrays<ObjectType extends {
9
9
  [key: string]: any;
10
- } = {}, S extends {
11
- [key: string]: any;
12
- } = CarbonReact['state'], P = CarbonReact['props']> {
10
+ } = {}, S extends CarbonReact['state'] = CarbonReact['state'], P = CarbonReact['props']> {
13
11
  instance: CarbonReact<P, S>;
14
12
  dataOrCallback: ObjectType[] | ((state: Readonly<S>, props: Readonly<P>) => ObjectType[] | null);
15
13
  stateKey: KeysMatching<S, tStatefulApiData<ObjectType>>;
@@ -28,6 +26,4 @@ export interface iUpdateRestfulObjectArrays<ObjectType extends {
28
26
  */
29
27
  export default function updateRestfulObjectArrays<ObjectType extends {
30
28
  [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;
29
+ } = {}, S extends iCarbonReactState = CarbonReact['state'], P = CarbonReact['props']>({ instance, dataOrCallback, stateKey, uniqueObjectId, insertUpdateOrder, callback, }: iUpdateRestfulObjectArrays<ObjectType, S, P>): void;
package/dist/index.cjs.js CHANGED
@@ -4366,8 +4366,7 @@ class CarbonReact extends react.Component {
4366
4366
  target;
4367
4367
  static _instance;
4368
4368
  static get instance() {
4369
- // Here `this` refers to the calling class in static context
4370
- return this._instance;
4369
+ return this;
4371
4370
  }
4372
4371
  static set instance(instance) {
4373
4372
  this._instance = instance;
@@ -4435,11 +4434,11 @@ class CarbonReact extends react.Component {
4435
4434
  console.log('%c color (' + colorHex + ')', 'color: ' + colorHex);
4436
4435
  const nest = jsxRuntime_1(Nest, { position: 'fixed', backgroundColor: '', color: hexToRgb(colorHex), count: 100 });
4437
4436
  if (this.state.backendThrowable.length > 0) {
4438
- return jsxRuntime_2(jsxRuntime_3, { children: [nest, jsxRuntime_1(BackendThrowable, { instance: CarbonReact.instance })] });
4437
+ return jsxRuntime_2(jsxRuntime_3, { children: [nest, jsxRuntime_1(BackendThrowable, { instance: this })] });
4439
4438
  }
4440
4439
  const Context = this.context.Provider;
4441
4440
  return jsxRuntime_2(jsxRuntime_3, { children: [jsxRuntime_1(GlobalHistory, {}), this.props.websocket &&
4442
- jsxRuntime_1(CarbonWebSocket, { ...(true === this.props.websocket ? {} : this.props.websocket), instance: CarbonReact.instance }), jsxRuntime_1(Context, { value: this.state, children: this.props.children }), jsxRuntime_1(reactToastify.ToastContainer, {})] });
4441
+ jsxRuntime_1(CarbonWebSocket, { ...(false !== this.props.websocket ? this.props.websocket : {}), instance: this }), jsxRuntime_1(Context, { value: this.state, children: this.props.children }), jsxRuntime_1(reactToastify.ToastContainer, {})] });
4443
4442
  }
4444
4443
  }
4445
4444