@carbonorm/carbonreact 4.0.16 → 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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbonorm/carbonreact",
3
3
  "license": "MIT",
4
- "version": "4.0.16",
4
+ "version": "4.0.17",
5
5
  "browser": "dist/index.umd.js",
6
6
  "module": "dist/index.esm.js",
7
7
  "main": "dist/index.cjs.js",
@@ -1,15 +1,16 @@
1
1
  import changed from "hoc/changed";
2
- import { GlobalHistory } from "hoc/GlobalHistory";
2
+ import {GlobalHistory} from "hoc/GlobalHistory";
3
3
  import hexToRgb from "hoc/hexToRgb";
4
- import { Component, Context, createContext, ReactElement, ReactNode } from 'react';
5
- import { ToastContainer } from 'react-toastify';
4
+ import {Component, Context, createContext, ReactElement, ReactNode} from 'react';
5
+ import {ToastContainer} from 'react-toastify';
6
6
  import 'react-toastify/dist/ReactToastify.min.css';
7
7
  import BackendThrowable from 'components/Errors/BackendThrowable';
8
8
  import Nest from 'components/Nest/Nest';
9
- import { initialRestfulObjectsState, iRestfulObjectArrayTypes } from "variables/C6";
10
- import CarbonWebSocket, { iCarbonWebSocketProps } from "./components/WebSocket/CarbonWebSocket";
11
- import updateRestfulObjectArrays, { iUpdateRestfulObjectArrays } from "./hoc/updateRestfulObjectArrays";
12
- import deleteRestfulObjectArrays, { iDeleteRestfulObjectArrays } from "./hoc/deleteRestfulObjectArrays";
9
+ import {initialRestfulObjectsState, iRestfulObjectArrayTypes} from "variables/C6";
10
+ import CarbonWebSocket, {iCarbonWebSocketProps} from "./components/WebSocket/CarbonWebSocket";
11
+ import updateRestfulObjectArrays, {iUpdateRestfulObjectArrays} from "./hoc/updateRestfulObjectArrays";
12
+ import deleteRestfulObjectArrays, {iDeleteRestfulObjectArrays} from "./hoc/deleteRestfulObjectArrays";
13
+ import {BrowserRouter, HashRouter, MemoryRouter, Routes} from "react-router-dom";
13
14
 
14
15
  export type tStatefulApiData<T extends { [key: string]: any } = {}> = T[] | undefined | null;
15
16
 
@@ -44,10 +45,17 @@ export function isJsonString(str: string) {
44
45
  return true;
45
46
  }
46
47
 
48
+ export enum eRouterType {
49
+ BrowserRouter,
50
+ HashRouter,
51
+ MemoryRouter,
52
+ }
53
+
47
54
  abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactState> extends Component<{
48
55
  children?: ReactNode | ReactNode[],
49
56
  instanceId?: string,
50
57
  persistentState?: boolean,
58
+ routerType?: eRouterType,
51
59
  websocket?: Omit<iCarbonWebSocketProps<P, S>, "instance"> | false
52
60
  } & P, S> {
53
61
 
@@ -159,6 +167,19 @@ abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactSta
159
167
  }
160
168
  }
161
169
 
170
+ reactRouterContext(children: ReactElement) {
171
+ switch (this.props.routerType) {
172
+ case eRouterType.BrowserRouter:
173
+ return <BrowserRouter>{children}</BrowserRouter>
174
+ case eRouterType.MemoryRouter:
175
+ return <MemoryRouter initialEntries={['/']}>{children}</MemoryRouter>
176
+ case eRouterType.HashRouter:
177
+ return <HashRouter>{children}</HashRouter>
178
+ default:
179
+ throw new Error('Invalid routerType');
180
+ }
181
+ }
182
+
162
183
  render(): ReactElement {
163
184
  console.log('CarbonORM TSX RENDER');
164
185
 
@@ -166,27 +187,28 @@ abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactSta
166
187
 
167
188
  console.log('%c color (' + colorHex + ')', 'color: ' + colorHex);
168
189
 
169
- const nest = <Nest position={'fixed'} backgroundColor={''} color={hexToRgb(colorHex)} count={100} />;
190
+ const nest = <Nest position={'fixed'} backgroundColor={''} color={hexToRgb(colorHex)} count={100}/>;
170
191
 
171
192
  if (this.state.backendThrowable.length > 0) {
172
193
  return <>
173
194
  {nest}
174
- <BackendThrowable instance={this} />
195
+ <BackendThrowable instance={this}/>
175
196
  </>;
176
197
  }
177
198
 
199
+ this.context = createContext(this.state)
178
200
  const Context = this.context.Provider;
179
201
 
180
- return <>
181
- <GlobalHistory />
202
+ return this.reactRouterContext(<Routes>
203
+ <GlobalHistory/>
182
204
  {this.props.websocket &&
183
205
  <CarbonWebSocket<P, S> {...(false !== this.props.websocket ? this.props.websocket : {})}
184
- instance={this} />}
206
+ instance={this}/>}
185
207
  <Context value={this.state}>
186
208
  {this.props.children}
187
209
  </Context>
188
- <ToastContainer />
189
- </>;
210
+ <ToastContainer/>
211
+ </Routes>);
190
212
  }
191
213
  }
192
214