@carbonorm/carbonreact 4.0.15 → 4.0.17

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,14 +17,19 @@ 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
+ export declare enum eRouterType {
21
+ BrowserRouter = 0,
22
+ HashRouter = 1,
23
+ MemoryRouter = 2
24
+ }
20
25
  declare abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactState> extends Component<{
21
26
  children?: ReactNode | ReactNode[];
22
27
  instanceId?: string;
23
28
  persistentState?: boolean;
29
+ routerType?: eRouterType;
24
30
  websocket?: Omit<iCarbonWebSocketProps<P, S>, "instance"> | false;
25
31
  } & P, S> {
26
32
  private static allInstances;
27
- private static activeInstances;
28
33
  context: Context<S & iCarbonReactState>;
29
34
  protected target: typeof CarbonReact;
30
35
  protected static _instance: ThisType<CarbonReact<any, any>>;
@@ -47,9 +52,9 @@ declare abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbon
47
52
  } & P);
48
53
  private static generateIdentifier;
49
54
  private generateIdentifier;
50
- componentWillUnmount(): void;
51
55
  shouldComponentUpdate(nextProps: Readonly<P>, nextState: Readonly<S>, _nextContext: any): boolean;
52
56
  componentDidUpdate(_prevProps: Readonly<P>, _prevState: Readonly<S>, _snapshot?: any): void;
57
+ reactRouterContext(children: ReactElement): import("react/jsx-runtime").JSX.Element;
53
58
  render(): ReactElement;
54
59
  }
55
60
  export default CarbonReact;
package/dist/index.cjs.js CHANGED
@@ -4371,17 +4371,22 @@ function isJsonString(str) {
4371
4371
  }
4372
4372
  return true;
4373
4373
  }
4374
+ exports.eRouterType = void 0;
4375
+ (function (eRouterType) {
4376
+ eRouterType[eRouterType["BrowserRouter"] = 0] = "BrowserRouter";
4377
+ eRouterType[eRouterType["HashRouter"] = 1] = "HashRouter";
4378
+ eRouterType[eRouterType["MemoryRouter"] = 2] = "MemoryRouter";
4379
+ })(exports.eRouterType || (exports.eRouterType = {}));
4374
4380
  class CarbonReact extends react.Component {
4375
4381
  static allInstances = new Map();
4376
- static activeInstances = new Map();
4377
4382
  context = react.createContext(this.state);
4378
4383
  target;
4379
4384
  static _instance;
4380
4385
  static getInstance(instanceId) {
4381
4386
  const identifier = this.generateIdentifier(instanceId);
4382
4387
  if (undefined !== instanceId) {
4383
- if (CarbonReact.activeInstances.has(identifier)) {
4384
- return CarbonReact.activeInstances.get(identifier);
4388
+ if (CarbonReact.allInstances.has(identifier)) {
4389
+ return CarbonReact.allInstances.get(identifier);
4385
4390
  }
4386
4391
  throw new Error(`No instance has been instantiated yet for class (${this.name}) with instanceId (${instanceId})`);
4387
4392
  }
@@ -4409,11 +4414,6 @@ class CarbonReact extends react.Component {
4409
4414
  constructor(props) {
4410
4415
  super(props);
4411
4416
  const identifier = this.generateIdentifier();
4412
- if (CarbonReact.activeInstances.has(identifier)) {
4413
- throw new Error(`${identifier} instance already exists in the DOM! Each instance should have a unique instanceId.`);
4414
- }
4415
- // Register the new instance
4416
- CarbonReact.activeInstances.set(identifier, this);
4417
4417
  if (props.persistentState && CarbonReact.allInstances.has(identifier)) {
4418
4418
  // Reuse the state from the existing instance
4419
4419
  this.state = CarbonReact.allInstances.get(identifier).state;
@@ -4436,10 +4436,6 @@ class CarbonReact extends react.Component {
4436
4436
  const className = this.constructor.name;
4437
4437
  return this.props.instanceId ? `${className}-${this.props.instanceId}` : className;
4438
4438
  }
4439
- componentWillUnmount() {
4440
- const identifier = this.generateIdentifier();
4441
- CarbonReact.activeInstances.delete(identifier);
4442
- }
4443
4439
  shouldComponentUpdate(nextProps, nextState, _nextContext) {
4444
4440
  changed(this.constructor.name + ' (C6Api)', 'props', this.props, nextProps);
4445
4441
  changed(this.constructor.name + ' (C6Api)', 'state', this.state, nextState);
@@ -4455,6 +4451,18 @@ class CarbonReact extends react.Component {
4455
4451
  }
4456
4452
  }
4457
4453
  }
4454
+ reactRouterContext(children) {
4455
+ switch (this.props.routerType) {
4456
+ case exports.eRouterType.BrowserRouter:
4457
+ return jsxRuntime_1(reactRouterDom.BrowserRouter, { children: children });
4458
+ case exports.eRouterType.MemoryRouter:
4459
+ return jsxRuntime_1(reactRouterDom.MemoryRouter, { initialEntries: ['/'], children: children });
4460
+ case exports.eRouterType.HashRouter:
4461
+ return jsxRuntime_1(reactRouterDom.HashRouter, { children: children });
4462
+ default:
4463
+ throw new Error('Invalid routerType');
4464
+ }
4465
+ }
4458
4466
  render() {
4459
4467
  console.log('CarbonORM TSX RENDER');
4460
4468
  const colorHex = '#' + Math.random().toString(16).slice(-6);
@@ -4463,9 +4471,10 @@ class CarbonReact extends react.Component {
4463
4471
  if (this.state.backendThrowable.length > 0) {
4464
4472
  return jsxRuntime_2(jsxRuntime_3, { children: [nest, jsxRuntime_1(BackendThrowable, { instance: this })] });
4465
4473
  }
4474
+ this.context = react.createContext(this.state);
4466
4475
  const Context = this.context.Provider;
4467
- return jsxRuntime_2(jsxRuntime_3, { children: [jsxRuntime_1(GlobalHistory, {}), this.props.websocket &&
4468
- 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, {})] });
4476
+ return this.reactRouterContext(jsxRuntime_2(reactRouterDom.Routes, { children: [jsxRuntime_1(GlobalHistory, {}), this.props.websocket &&
4477
+ 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, {})] }));
4469
4478
  }
4470
4479
  }
4471
4480