@carbonorm/carbonreact 4.0.25 → 6.0.0

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.
Files changed (83) hide show
  1. package/README.md +45 -12
  2. package/dist/components/Alert/Alert.d.ts +1 -1
  3. package/dist/components/Errors/BackendThrowable.d.ts +1 -1
  4. package/dist/components/WebSocket/CarbonWebSocket.d.ts +1 -1
  5. package/dist/{CarbonReact.d.ts → core/CarbonReact.d.ts} +4 -4
  6. package/dist/env/getEnv.d.ts +1 -0
  7. package/dist/env/isProduction.d.ts +2 -0
  8. package/dist/index.cjs +3436 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/{index.cjs.css → index.css} +5102 -5102
  11. package/dist/index.css.map +1 -0
  12. package/dist/index.d.ts +41 -44
  13. package/dist/index.esm.css +5101 -5101
  14. package/dist/index.esm.css.map +1 -1
  15. package/dist/index.esm.js +719 -1228
  16. package/dist/index.esm.js.map +1 -1
  17. package/dist/{variables → schema}/C6.d.ts +1 -1
  18. package/dist/{hoc → state}/deleteRestfulObjectArrays.d.ts +2 -2
  19. package/dist/{hoc → state}/updateRestfulObjectArrays.d.ts +2 -2
  20. package/dist/{hoc → styles}/getStyles.d.ts +1 -1
  21. package/package.json +17 -6
  22. package/src/components/Alert/Alert.tsx +4 -5
  23. package/src/components/Errors/BackendThrowable.tsx +2 -2
  24. package/src/components/Loading/Loading.tsx +1 -2
  25. package/src/components/Popup/Popup.tsx +1 -2
  26. package/src/components/WebSocket/CarbonWebSocket.tsx +86 -72
  27. package/src/{CarbonReact.tsx → core/CarbonReact.tsx} +18 -24
  28. package/src/{hoc → dom}/isEdgeBrowser.tsx +4 -2
  29. package/src/{hoc → dom}/setCookies.tsx +1 -1
  30. package/src/env/getEnv.ts +29 -0
  31. package/src/env/isProduction.tsx +6 -0
  32. package/src/{api/hoc → hooks}/useEffectOnce.tsx +2 -2
  33. package/src/{hoc → hooks}/windowDimensions.tsx +9 -1
  34. package/src/index.ts +41 -44
  35. package/src/{variables → schema}/C6.tsx +1 -2
  36. package/src/{hoc → state}/deleteRestfulObjectArrays.tsx +2 -2
  37. package/src/{hoc → state}/updateRestfulObjectArrays.tsx +3 -3
  38. package/src/{hoc → styles}/getStyles.tsx +6 -2
  39. package/src/{hoc → testing}/setupTests.tsx +18 -14
  40. package/dist/components/Nest/Nest.d.ts +0 -49
  41. package/dist/hoc/setUrl.d.ts +0 -1
  42. package/dist/index.cjs.css.map +0 -1
  43. package/dist/index.cjs.js +0 -3946
  44. package/dist/index.cjs.js.map +0 -1
  45. package/dist/variables/isProduction.d.ts +0 -2
  46. package/src/components/Nest/Nest.tsx +0 -241
  47. package/src/hoc/setUrl.tsx +0 -38
  48. package/src/variables/isProduction.tsx +0 -5
  49. /package/dist/api/{hoc/getStatefulObjectWithWhere.d.ts → getStatefulObjectWithWhere.d.ts} +0 -0
  50. /package/dist/{hoc → dom}/isEdgeBrowser.d.ts +0 -0
  51. /package/dist/{hoc → dom}/scrollIntoView.d.ts +0 -0
  52. /package/dist/{hoc → dom}/setCookies.d.ts +0 -0
  53. /package/dist/{hoc → dom}/uploadImage.d.ts +0 -0
  54. /package/dist/{api/hoc → dom}/watchInputElementChangeEvent.d.ts +0 -0
  55. /package/dist/{api/hoc → hooks}/useEffectOnce.d.ts +0 -0
  56. /package/dist/{hoc → hooks}/windowDimensions.d.ts +0 -0
  57. /package/dist/{hoc → routing}/GlobalHistory.d.ts +0 -0
  58. /package/dist/{hoc → testing}/addValidSQL.d.ts +0 -0
  59. /package/dist/{hoc → testing}/setupTests.d.ts +0 -0
  60. /package/dist/{hoc → testing}/validSQL.d.ts +0 -0
  61. /package/dist/{hoc → types}/KeysMatching.d.ts +0 -0
  62. /package/dist/{hoc → types}/SubsetMatching.d.ts +0 -0
  63. /package/dist/{hoc → utils}/changed.d.ts +0 -0
  64. /package/dist/{hoc → utils}/hexToRgb.d.ts +0 -0
  65. /package/dist/{hoc → utils}/parseMultipleJson.d.ts +0 -0
  66. /package/src/api/{hoc/getStatefulObjectWithWhere.tsx → getStatefulObjectWithWhere.tsx} +0 -0
  67. /package/src/{hoc → dom}/scrollIntoView.tsx +0 -0
  68. /package/src/{hoc → dom}/uploadImage.tsx +0 -0
  69. /package/src/{api/hoc → dom}/watchInputElementChangeEvent.tsx +0 -0
  70. /package/src/{hoc → routing}/GlobalHistory.tsx +0 -0
  71. /package/src/{variables → styles}/bootstrap.module.css +0 -0
  72. /package/src/{variables → styles}/bootstrap.module.css.d.ts +0 -0
  73. /package/src/{variables → styles}/bootstrap.module.css.json +0 -0
  74. /package/src/{variables → styles}/bootstrap.module.css.map +0 -0
  75. /package/src/{variables → styles}/bootstrap.module.scss +0 -0
  76. /package/src/{variables → styles}/bootstrap.module.scss.d.ts +0 -0
  77. /package/src/{hoc → testing}/addValidSQL.tsx +0 -0
  78. /package/src/{hoc → testing}/validSQL.tsx +0 -0
  79. /package/src/{hoc → types}/KeysMatching.ts +0 -0
  80. /package/src/{hoc → types}/SubsetMatching.ts +0 -0
  81. /package/src/{hoc → utils}/changed.tsx +0 -0
  82. /package/src/{hoc → utils}/hexToRgb.tsx +0 -0
  83. /package/src/{hoc → utils}/parseMultipleJson.tsx +0 -0
@@ -1,11 +1,11 @@
1
1
  import classNames from "classnames";
2
- import CarbonReact, {iCarbonReactState} from "CarbonReact";
2
+ import CarbonReact, {iCarbonReactState} from "core/CarbonReact";
3
3
  import {ReactNode} from "react";
4
4
  import Popup from "components/Popup/Popup";
5
- import getStyles from "hoc/getStyles";
5
+ import getStyles from "styles/getStyles";
6
6
  import {faClose} from "@fortawesome/free-solid-svg-icons";
7
7
  import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
8
- import isProduction from "variables/isProduction";
8
+ import isProduction from "env/isProduction";
9
9
 
10
10
  // 'digBtnBlue': string;
11
11
  // 'digBtnGreen': string;
@@ -56,7 +56,7 @@ export default function Alert<P, S extends iCarbonReactState>({instance}: { inst
56
56
  color: 'danger',
57
57
  }];
58
58
 
59
- const hideExpandInformation = isProduction
59
+ const hideExpandInformation = isProduction()
60
60
 
61
61
  if (false === hideExpandInformation) {
62
62
  buttons.push({
@@ -205,4 +205,3 @@ export default function Alert<P, S extends iCarbonReactState>({instance}: { inst
205
205
  </Popup>
206
206
 
207
207
  }
208
-
@@ -1,6 +1,6 @@
1
1
  import styles from './style.module.scss';
2
2
  import OutsideClickHandler from '../OutsideClickHandler/OutsideClickHandler';
3
- import CarbonReact, {iCarbonReactState} from "../../CarbonReact";
3
+ import CarbonReact, {iCarbonReactState} from "core/CarbonReact";
4
4
  import {ReactElement} from "react";
5
5
 
6
6
  export default <P,S extends iCarbonReactState>(props: {
@@ -43,4 +43,4 @@ export default <P,S extends iCarbonReactState>(props: {
43
43
  </OutsideClickHandler>
44
44
  </div>;
45
45
 
46
- }
46
+ }
@@ -1,5 +1,5 @@
1
1
  import classNames from "classnames";
2
- import getStyles, {getRootStyleValue} from "hoc/getStyles";
2
+ import getStyles, {getRootStyleValue} from "styles/getStyles";
3
3
  import {ReactNode} from "react";
4
4
  import Skeleton, {SkeletonTheme} from "react-loading-skeleton";
5
5
 
@@ -34,4 +34,3 @@ export default function Loading(props: iLoading) {
34
34
  </div>;
35
35
 
36
36
  }
37
-
@@ -1,6 +1,6 @@
1
1
  import classNames from "classnames";
2
2
  import OutsideClickHandler from '../OutsideClickHandler/OutsideClickHandler';
3
- import getStyles from "hoc/getStyles";
3
+ import getStyles from "styles/getStyles";
4
4
  import {PropsWithChildren, ReactElement} from "react";
5
5
 
6
6
 
@@ -43,4 +43,3 @@ export default function Popup({
43
43
  </div>
44
44
 
45
45
  }
46
-
@@ -1,7 +1,7 @@
1
- import CarbonReact, {iCarbonReactState, isJsonString, tStatefulApiData} from "CarbonReact";
1
+ import CarbonReact, {iCarbonReactState, isJsonString, tStatefulApiData} from "core/CarbonReact";
2
2
  import {addAlert} from "../Alert/Alert";
3
- import {useEffectOnce} from "../../api/hoc/useEffectOnce";
4
- import {iC6Object} from "@carbonorm/carbonnode";
3
+ import {useEffectOnce} from "hooks/useEffectOnce";
4
+ import {iC6Object, isVerbose} from "@carbonorm/carbonnode";
5
5
 
6
6
 
7
7
  export interface iCarbonWebSocketProps<P, S extends iCarbonReactState> {
@@ -20,17 +20,25 @@ export function initiateWebsocket<P, S extends iCarbonReactState>(props: iCarbon
20
20
 
21
21
  let {
22
22
  instance,
23
- url = 'ws' + (window.location.protocol === 'https:' ? 's' : '') + '://' + window.location.host + '/carbonorm/websocket',
23
+ url,
24
24
  timeoutSeconds = 250,
25
25
  heartbeatSeconds = 60,
26
26
  C6
27
27
  } = props;
28
28
 
29
+ if (typeof window === "undefined") {
30
+ return;
31
+ }
32
+
33
+ if (!url) {
34
+ url = 'ws' + (window.location.protocol === 'https:' ? 's' : '') + '://' + window.location.host + '/carbonorm/websocket';
35
+ }
36
+
29
37
  const {
30
38
  TABLES = undefined,
31
- IMPORT = undefined,
32
39
  } = C6 ?? {};
33
40
 
41
+ const verbose = isVerbose();
34
42
 
35
43
  const {websocket} = instance.state;
36
44
 
@@ -47,6 +55,7 @@ export function initiateWebsocket<P, S extends iCarbonReactState>(props: iCarbon
47
55
 
48
56
  }
49
57
 
58
+
50
59
  if (false === (undefined === websocket || null === websocket)) {
51
60
 
52
61
  return;
@@ -67,21 +76,14 @@ export function initiateWebsocket<P, S extends iCarbonReactState>(props: iCarbon
67
76
  connection.onopen = () => {
68
77
 
69
78
  console.log('WebSocket Client Connected To :: ' + url);
70
-
71
79
  clearTimeout(connectInterval); // clear Interval on open of websocket connection
72
80
 
73
81
  function heartbeat() {
74
-
75
82
  const {websocket} = instance.state;
76
-
77
83
  if (!websocket) return;
78
-
79
84
  if (websocket.readyState !== 1) return;
80
-
81
85
  websocket.send("ping");
82
-
83
86
  setTimeout(heartbeat, heartbeatSeconds * 1000);
84
-
85
87
  }
86
88
 
87
89
  heartbeat();
@@ -103,7 +105,9 @@ export function initiateWebsocket<P, S extends iCarbonReactState>(props: iCarbon
103
105
 
104
106
  if (undefined === TABLES) {
105
107
 
106
- console.log('WebSocket updates without the TABLES property passed will not automatically update the state.')
108
+ if (verbose) {
109
+ console.log('WebSocket updates without the TABLES property passed will not automatically update the state.');
110
+ }
107
111
 
108
112
  return;
109
113
 
@@ -113,7 +117,7 @@ export function initiateWebsocket<P, S extends iCarbonReactState>(props: iCarbon
113
117
 
114
118
  const TABLE_NAME: string = parsedData?.REST?.TABLE_NAME;
115
119
 
116
- const TABLE_PREFIX: string = parsedData?.REST?.TABLE_PREFIX;
120
+ const TABLE_PREFIX: string = parsedData?.REST?.TABLE_PREFIX ?? '';
117
121
 
118
122
  const METHOD: string = parsedData?.REST?.METHOD;
119
123
 
@@ -125,15 +129,21 @@ export function initiateWebsocket<P, S extends iCarbonReactState>(props: iCarbon
125
129
 
126
130
  if (null === REQUEST_PRIMARY_KEY) {
127
131
 
128
- console.log('WebSocket updates without a primary key are not yet supported.')
132
+ if (verbose) {
133
+ console.log('WebSocket updates without a primary key are not yet supported.');
134
+ }
129
135
 
130
136
  return;
131
137
 
132
138
  }
133
139
 
134
- console.log('todo - going to impl REST', TABLE_NAME, METHOD, REQUEST_PRIMARY_KEY, parsedData?.REST)
140
+ if (verbose) {
141
+ console.log('todo - going to impl REST', TABLE_NAME, METHOD, REQUEST_PRIMARY_KEY, parsedData?.REST);
142
+ }
135
143
 
136
- const TABLE_NAME_SHORT = TABLE_NAME.substring(TABLE_PREFIX.length);
144
+ const TABLE_NAME_SHORT = TABLE_NAME.startsWith(TABLE_PREFIX)
145
+ ? TABLE_NAME.substring(TABLE_PREFIX.length)
146
+ : TABLE_NAME;
137
147
 
138
148
  const currentCache: tStatefulApiData<{ [key: string]: any }> = instance.state[TABLE_NAME_SHORT]
139
149
 
@@ -143,77 +153,81 @@ export function initiateWebsocket<P, S extends iCarbonReactState>(props: iCarbon
143
153
 
144
154
  if (null === c6Table) {
145
155
 
146
- console.error('WebSocket update could not find (' + TABLE_NAME_SHORT + ') in the TABLES property passed.', TABLES)
156
+ if (verbose) {
157
+ console.error('WebSocket update could not find (' + TABLE_NAME_SHORT + ') in the TABLES property passed.', TABLES);
158
+ }
147
159
 
148
160
  return;
149
161
 
150
162
  }
151
163
 
152
- const primaryKeyKeys = Object.keys(REQUEST_PRIMARY_KEY)
153
-
154
- // todo - which direction should we filter
155
- const elementsToUpdate = currentCache?.filter((row: any) => {
156
-
157
- for (const element of primaryKeyKeys) {
158
-
159
- // remove the table name from the column name
160
- const column = element.split('.')[1]
161
-
162
- console.log('column', column, REQUEST_PRIMARY_KEY[element], row[column])
163
-
164
- if (REQUEST_PRIMARY_KEY[element] !== row[column]) {
165
-
166
- return false
164
+ const columns = c6Table.COLUMNS as Record<string, string>;
165
+ const validColumns = new Set(Object.values(columns));
167
166
 
167
+ const normalizeRecord = (record: { [key: string]: any } | null | undefined) => {
168
+ const normalized: { [key: string]: any } = {};
169
+ for (const [key, value] of Object.entries(record ?? {})) {
170
+ const shortKey = columns[key] ?? (key.includes('.') ? key.split('.').pop()! : key);
171
+ if (validColumns.has(shortKey)) {
172
+ normalized[shortKey] = value;
168
173
  }
169
-
170
174
  }
175
+ return normalized;
176
+ };
171
177
 
172
- return true
173
-
174
- }) ?? []
175
-
176
- console.log('elementsToUpdate', elementsToUpdate)
178
+ const normalizedPrimaryKey = normalizeRecord(REQUEST_PRIMARY_KEY);
179
+ const primaryKeyKeys = Object.keys(normalizedPrimaryKey);
177
180
 
178
- if (elementsToUpdate.length === 0) {
179
- console.error('Could not find any elements to update in the cache.', elementsToUpdate, primaryKeyKeys, REQUEST_PRIMARY_KEY, currentCache)
181
+ if (primaryKeyKeys.length === 0) {
182
+ if (verbose) {
183
+ console.error('WebSocket update could not map primary keys for', TABLE_NAME_SHORT, REQUEST_PRIMARY_KEY);
184
+ }
180
185
  return;
181
186
  }
182
187
 
183
- const updatedElements = elementsToUpdate.map((row: any) => {
188
+ // todo - which direction should we filter
189
+ const elementsToUpdate = currentCache?.filter((row: any) =>
190
+ primaryKeyKeys.every((key) => normalizedPrimaryKey[key] === row[key])
191
+ ) ?? []
184
192
 
185
- return {
186
- ...row,
187
- ...REQUEST
188
- }
193
+ if (verbose) {
194
+ console.log('elementsToUpdate', elementsToUpdate);
195
+ }
189
196
 
190
- })
191
-
192
- updatedElements.forEach(async (row: any) => {
193
-
194
- const RestRequests = await IMPORT?.(TABLE_NAME_SHORT)
195
-
196
- const {
197
- postState,
198
- deleteState,
199
- putState,
200
- } = RestRequests;
201
-
202
- switch (METHOD) {
203
- case 'POST':
204
- postState({}, row)
205
- break;
206
- case 'DELETE':
207
- deleteState({}, row)
208
- break;
209
- case 'PUT':
210
- putState({}, row)
211
- break;
212
- default:
213
- console.error('Method not supported', METHOD)
197
+ if (elementsToUpdate.length === 0) {
198
+ if (verbose) {
199
+ console.error('Could not find any elements to update in the cache.', elementsToUpdate, primaryKeyKeys, REQUEST_PRIMARY_KEY, currentCache);
214
200
  }
201
+ return;
202
+ }
215
203
 
216
- })
204
+ const normalizedRequest = normalizeRecord(REQUEST);
205
+ const updatedElements = elementsToUpdate.map((row: any) => ({
206
+ ...row,
207
+ ...normalizedRequest,
208
+ }));
209
+
210
+ switch (METHOD) {
211
+ case 'POST':
212
+ case 'PUT':
213
+ instance.updateRestfulObjectArrays({
214
+ dataOrCallback: updatedElements,
215
+ stateKey: TABLE_NAME_SHORT as any,
216
+ uniqueObjectId: c6Table.PRIMARY_SHORT as any,
217
+ });
218
+ break;
219
+ case 'DELETE':
220
+ instance.deleteRestfulObjectArrays({
221
+ dataOrCallback: elementsToUpdate,
222
+ stateKey: TABLE_NAME_SHORT as any,
223
+ uniqueObjectId: c6Table.PRIMARY_SHORT as any,
224
+ });
225
+ break;
226
+ default:
227
+ if (verbose) {
228
+ console.error('Method not supported', METHOD);
229
+ }
230
+ }
217
231
 
218
232
  }
219
233
 
@@ -315,4 +329,4 @@ export default function <P, S extends iCarbonReactState>(props: iCarbonWebSocket
315
329
 
316
330
  return null
317
331
 
318
- }
332
+ }
@@ -1,15 +1,13 @@
1
- import changed from "hoc/changed";
2
- import {GlobalHistory} from "hoc/GlobalHistory";
3
- import hexToRgb from "hoc/hexToRgb";
1
+ import changed from "utils/changed";
2
+ import {GlobalHistory} from "routing/GlobalHistory";
4
3
  import {Component, Context, createContext, ReactElement, ReactNode} from 'react';
5
4
  import {ToastContainer} from 'react-toastify';
6
5
  import 'react-toastify/dist/ReactToastify.css';
7
6
  import BackendThrowable from 'components/Errors/BackendThrowable';
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";
7
+ import {initialRestfulObjectsState, iRestfulObjectArrayTypes} from "schema/C6";
8
+ import CarbonWebSocket, {iCarbonWebSocketProps} from "components/WebSocket/CarbonWebSocket";
9
+ import updateRestfulObjectArrays, {iUpdateRestfulObjectArrays} from "state/updateRestfulObjectArrays";
10
+ import deleteRestfulObjectArrays, {iDeleteRestfulObjectArrays} from "state/deleteRestfulObjectArrays";
13
11
  import {BrowserRouter, HashRouter, MemoryRouter} from "react-router-dom";
14
12
 
15
13
  export type tStatefulApiData<T extends { [key: string]: any } = {}> = T[] | undefined | null;
@@ -51,6 +49,8 @@ export enum eRouterType {
51
49
  MemoryRouter,
52
50
  }
53
51
 
52
+ const canUseDom = () => typeof window !== "undefined" && typeof document !== "undefined";
53
+
54
54
  abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactState> extends Component<{
55
55
  children?: ReactNode | ReactNode[],
56
56
  instanceId?: string,
@@ -105,7 +105,7 @@ abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactSta
105
105
  ...rest
106
106
  });
107
107
 
108
- static lastLocation = window.location.pathname;
108
+ static lastLocation = typeof window === "undefined" ? "" : window.location.pathname;
109
109
 
110
110
  static whyDidYouRender = true;
111
111
 
@@ -157,10 +157,10 @@ abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactSta
157
157
  }
158
158
 
159
159
  componentDidUpdate(_prevProps: Readonly<P>, _prevState: Readonly<S>, _snapshot?: any) {
160
- if (CarbonReact.lastLocation !== location.pathname) {
160
+ if (typeof location !== "undefined" && CarbonReact.lastLocation !== location.pathname) {
161
161
  CarbonReact.lastLocation = location.pathname;
162
162
  const websocket = this.state.websocket;
163
- if (websocket?.readyState === WebSocket.OPEN) {
163
+ if (typeof WebSocket !== "undefined" && websocket?.readyState === WebSocket.OPEN) {
164
164
  websocket.send(location.pathname);
165
165
  console.log(location.pathname);
166
166
  }
@@ -168,7 +168,8 @@ abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactSta
168
168
  }
169
169
 
170
170
  reactRouterContext(children: ReactElement) {
171
- switch (this.props.routerType ?? eRouterType.BrowserRouter) {
171
+ const routerType = this.props.routerType ?? (canUseDom() ? eRouterType.BrowserRouter : eRouterType.MemoryRouter);
172
+ switch (routerType) {
172
173
  case eRouterType.BrowserRouter:
173
174
  return <BrowserRouter>{children}</BrowserRouter>
174
175
  case eRouterType.MemoryRouter:
@@ -183,31 +184,24 @@ abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactSta
183
184
  render(): ReactElement {
184
185
  console.log('CarbonORM TSX RENDER');
185
186
 
186
- const colorHex = '#' + Math.random().toString(16).slice(-6);
187
-
188
- console.log('%c color (' + colorHex + ')', 'color: ' + colorHex);
189
-
190
- const nest = <Nest position={'fixed'} backgroundColor={''} color={hexToRgb(colorHex)} count={100}/>;
187
+ const canUseDomNow = canUseDom();
191
188
 
192
189
  if (this.state.backendThrowable.length > 0) {
193
- return <>
194
- {nest}
195
- <BackendThrowable instance={this}/>
196
- </>;
190
+ return <BackendThrowable instance={this}/>;
197
191
  }
198
192
 
199
193
  this.context = createContext(this.state)
200
194
  const Context = this.context.Provider;
201
195
 
202
196
  return this.reactRouterContext(<>
203
- <GlobalHistory/>
204
- {this.props.websocket &&
197
+ {canUseDomNow && <GlobalHistory/>}
198
+ {canUseDomNow && this.props.websocket &&
205
199
  <CarbonWebSocket<P, S> {...(false !== this.props.websocket ? this.props.websocket : {})}
206
200
  instance={this}/>}
207
201
  <Context value={this.state}>
208
202
  {this.props.children}
209
203
  </Context>
210
- <ToastContainer/>
204
+ {canUseDomNow && <ToastContainer/>}
211
205
  </>);
212
206
  }
213
207
  }
@@ -3,5 +3,7 @@
3
3
  // Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) \
4
4
  // Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.26
5
5
 
6
- const isEdgeBrowser = window.navigator.userAgent.indexOf("Edg") > -1
7
- export default isEdgeBrowser
6
+ const isEdgeBrowser = typeof window !== "undefined"
7
+ && typeof window.navigator !== "undefined"
8
+ && window.navigator.userAgent.indexOf("Edg") > -1
9
+ export default isEdgeBrowser
@@ -11,7 +11,7 @@ export default function setCookies(cookies: string[], req: AxiosResponse | undef
11
11
  .replace("HttpOnly", "")
12
12
  .replace("secure", "");
13
13
 
14
- if (document === undefined || document === null) {
14
+ if (typeof document === "undefined" || document === null) {
15
15
 
16
16
  const getStackTrace = function () {
17
17
  let obj: any = {};
@@ -0,0 +1,29 @@
1
+ function getProcessEnv(key: string): string | undefined {
2
+ // works in node + most polyfills
3
+ return typeof process !== "undefined" ? process.env?.[key] : undefined;
4
+ }
5
+
6
+ function getViteEnv(key: string): string | undefined {
7
+ // IMPORTANT:
8
+ // this file must be ESM-compatible in any environment where it's executed
9
+ // because import.meta may not even parse in CJS contexts
10
+ // @ts-ignore
11
+ return typeof import.meta !== "undefined" ? import.meta.env?.[key] : undefined;
12
+ }
13
+
14
+ export function getEnv<T = string>(key: string, fallback?: T): T {
15
+ // Prefer process.env in SSR/node (secrets, runtime config)
16
+ const proc = getProcessEnv(key);
17
+ if (proc !== undefined) return proc as T;
18
+
19
+ // Vite client / build-time vars
20
+ try {
21
+ const vite = getViteEnv(key);
22
+ if (vite !== undefined) return vite as T;
23
+ } catch {
24
+ // ignore
25
+ }
26
+
27
+ if (fallback !== undefined) return fallback;
28
+ throw new Error(`Missing required environment variable: ${key}`);
29
+ }
@@ -0,0 +1,6 @@
1
+ import {getEnv} from "./getEnv";
2
+
3
+ // @ts-ignore
4
+ const isProduction = () => getEnv("NODE_ENV", "") === "production"
5
+
6
+ export default isProduction
@@ -3,7 +3,7 @@ import { useEffect, useRef, useState } from 'react';
3
3
  // @link https://dev.to/ag-grid/react-18-avoiding-use-effect-getting-called-twice-4i9e
4
4
  export const useEffectOnce = (effect: () => void | (() => void)) => {
5
5
  const effectFn = useRef<() => void | (() => void)>(effect);
6
- const destroyFn = useRef<void | (() => void)>();
6
+ const destroyFn = useRef<void | (() => void)>(undefined);
7
7
  const effectCalled = useRef(false);
8
8
  const rendered = useRef(false);
9
9
  const [, setVal] = useState<number>(0);
@@ -30,4 +30,4 @@ export const useEffectOnce = (effect: () => void | (() => void)) => {
30
30
  }
31
31
  };
32
32
  }, []);
33
- }
33
+ }
@@ -1,6 +1,10 @@
1
1
  import { useState, useEffect } from 'react';
2
2
 
3
3
  function getWindowDimensions() {
4
+ if (typeof window === "undefined") {
5
+ return { width: 0, height: 0 };
6
+ }
7
+
4
8
  const { innerWidth: width, innerHeight: height } = window;
5
9
  return {
6
10
  width,
@@ -12,6 +16,10 @@ export default function useWindowDimensions() {
12
16
  const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions());
13
17
 
14
18
  useEffect(() => {
19
+ if (typeof window === "undefined") {
20
+ return;
21
+ }
22
+
15
23
  function handleResize() {
16
24
  setWindowDimensions(getWindowDimensions());
17
25
  }
@@ -21,4 +29,4 @@ export default function useWindowDimensions() {
21
29
  }, []);
22
30
 
23
31
  return windowDimensions;
24
- }
32
+ }
package/src/index.ts CHANGED
@@ -2,13 +2,8 @@
2
2
  * @file Automatically generated by barrelsby.
3
3
  */
4
4
 
5
- export { default as CarbonReact } from "./CarbonReact";
6
- export * from "./CarbonReact";
7
- export { default as getStatefulObjectWithWhere } from "./api/hoc/getStatefulObjectWithWhere";
8
- export * from "./api/hoc/getStatefulObjectWithWhere";
9
- export * from "./api/hoc/useEffectOnce";
10
- export { default as watchInputElementChangeEvent } from "./api/hoc/watchInputElementChangeEvent";
11
- export * from "./api/hoc/watchInputElementChangeEvent";
5
+ export { default as getStatefulObjectWithWhere } from "./api/getStatefulObjectWithWhere";
6
+ export * from "./api/getStatefulObjectWithWhere";
12
7
  export { default as Alert } from "./components/Alert/Alert";
13
8
  export * from "./components/Alert/Alert";
14
9
  export { default as AccessDenied } from "./components/Errors/AccessDenied";
@@ -21,46 +16,48 @@ export { default as PageNotFound } from "./components/Errors/PageNotFound";
21
16
  export * from "./components/Errors/PageNotFound";
22
17
  export { default as Loading } from "./components/Loading/Loading";
23
18
  export * from "./components/Loading/Loading";
24
- export { default as Nest } from "./components/Nest/Nest";
25
- export * from "./components/Nest/Nest";
26
19
  export { default as OutsideClickHandler } from "./components/OutsideClickHandler/OutsideClickHandler";
27
20
  export * from "./components/OutsideClickHandler/OutsideClickHandler";
28
21
  export { default as Popup } from "./components/Popup/Popup";
29
22
  export * from "./components/Popup/Popup";
30
23
  export { default as CarbonWebSocket } from "./components/WebSocket/CarbonWebSocket";
31
24
  export * from "./components/WebSocket/CarbonWebSocket";
32
- export * from "./hoc/GlobalHistory";
33
- export * from "./hoc/KeysMatching";
34
- export * from "./hoc/SubsetMatching";
35
- export { default as addValidSQL } from "./hoc/addValidSQL";
36
- export * from "./hoc/addValidSQL";
37
- export { default as changed } from "./hoc/changed";
38
- export * from "./hoc/changed";
39
- export { default as deleteRestfulObjectArrays } from "./hoc/deleteRestfulObjectArrays";
40
- export * from "./hoc/deleteRestfulObjectArrays";
41
- export { default as getStyles } from "./hoc/getStyles";
42
- export * from "./hoc/getStyles";
43
- export { default as hexToRgb } from "./hoc/hexToRgb";
44
- export * from "./hoc/hexToRgb";
45
- export { default as isEdgeBrowser } from "./hoc/isEdgeBrowser";
46
- export * from "./hoc/isEdgeBrowser";
47
- export * from "./hoc/parseMultipleJson";
48
- export { default as scrollIntoView } from "./hoc/scrollIntoView";
49
- export * from "./hoc/scrollIntoView";
50
- export { default as setCookies } from "./hoc/setCookies";
51
- export * from "./hoc/setCookies";
52
- export { default as setUrl } from "./hoc/setUrl";
53
- export * from "./hoc/setUrl";
54
- export { default as setupTests } from "./hoc/setupTests";
55
- export * from "./hoc/setupTests";
56
- export { default as updateRestfulObjectArrays } from "./hoc/updateRestfulObjectArrays";
57
- export * from "./hoc/updateRestfulObjectArrays";
58
- export { default as uploadImage } from "./hoc/uploadImage";
59
- export * from "./hoc/uploadImage";
60
- export { default as validSQL } from "./hoc/validSQL";
61
- export * from "./hoc/validSQL";
62
- export { default as windowDimensions } from "./hoc/windowDimensions";
63
- export * from "./hoc/windowDimensions";
64
- export * from "./variables/C6";
65
- export { default as isProduction } from "./variables/isProduction";
66
- export * from "./variables/isProduction";
25
+ export { default as CarbonReact } from "./core/CarbonReact";
26
+ export * from "./core/CarbonReact";
27
+ export { default as isEdgeBrowser } from "./dom/isEdgeBrowser";
28
+ export * from "./dom/isEdgeBrowser";
29
+ export { default as scrollIntoView } from "./dom/scrollIntoView";
30
+ export * from "./dom/scrollIntoView";
31
+ export { default as setCookies } from "./dom/setCookies";
32
+ export * from "./dom/setCookies";
33
+ export { default as uploadImage } from "./dom/uploadImage";
34
+ export * from "./dom/uploadImage";
35
+ export { default as watchInputElementChangeEvent } from "./dom/watchInputElementChangeEvent";
36
+ export * from "./dom/watchInputElementChangeEvent";
37
+ export * from "./env/getEnv";
38
+ export { default as isProduction } from "./env/isProduction";
39
+ export * from "./env/isProduction";
40
+ export * from "./hooks/useEffectOnce";
41
+ export { default as windowDimensions } from "./hooks/windowDimensions";
42
+ export * from "./hooks/windowDimensions";
43
+ export * from "./routing/GlobalHistory";
44
+ export * from "./schema/C6";
45
+ export { default as deleteRestfulObjectArrays } from "./state/deleteRestfulObjectArrays";
46
+ export * from "./state/deleteRestfulObjectArrays";
47
+ export { default as updateRestfulObjectArrays } from "./state/updateRestfulObjectArrays";
48
+ export * from "./state/updateRestfulObjectArrays";
49
+ export { default as getStyles } from "./styles/getStyles";
50
+ export * from "./styles/getStyles";
51
+ export { default as addValidSQL } from "./testing/addValidSQL";
52
+ export * from "./testing/addValidSQL";
53
+ export { default as setupTests } from "./testing/setupTests";
54
+ export * from "./testing/setupTests";
55
+ export { default as validSQL } from "./testing/validSQL";
56
+ export * from "./testing/validSQL";
57
+ export * from "./types/KeysMatching";
58
+ export * from "./types/SubsetMatching";
59
+ export { default as changed } from "./utils/changed";
60
+ export * from "./utils/changed";
61
+ export { default as hexToRgb } from "./utils/hexToRgb";
62
+ export * from "./utils/hexToRgb";
63
+ export * from "./utils/parseMultipleJson";
@@ -1,4 +1,4 @@
1
- import { tStatefulApiData } from "CarbonReact";
1
+ import { tStatefulApiData } from "core/CarbonReact";
2
2
 
3
3
  export interface stringMap {
4
4
  [key: string]: string;
@@ -3301,4 +3301,3 @@ export const initialRestfulObjectsState: iRestfulObjectArrayTypes = {
3301
3301
 
3302
3302
  export type tRestfulObjectArrayValues = iRestfulObjectArrayTypes[keyof iRestfulObjectArrayTypes];
3303
3303
 
3304
-
@@ -1,5 +1,5 @@
1
- import CarbonReact, { iCarbonReactState, tStatefulApiData } from "CarbonReact";
2
- import { KeysMatching } from "./KeysMatching";
1
+ import CarbonReact, { iCarbonReactState, tStatefulApiData } from "core/CarbonReact";
2
+ import { KeysMatching } from "types/KeysMatching";
3
3
 
4
4
  export interface iDeleteRestfulObjectArrays<
5
5
  ObjectType extends {