@carbonorm/carbonreact 2.0.3 → 3.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/dist/CarbonReact.d.ts +49 -14
- package/dist/hoc/deleteRestfulObjectArrays.d.ts +2 -3
- package/dist/hoc/setUrl.d.ts +1 -1
- package/dist/hoc/updateRestfulObjectArrays.d.ts +2 -3
- package/dist/index.cjs.js +105 -398
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.esm.js +102 -392
- package/dist/index.esm.js.map +1 -1
- package/dist/variables/C6.d.ts +1 -3
- package/package.json +3 -3
- package/src/CarbonReact.tsx +9 -10
- package/src/hoc/deleteRestfulObjectArrays.tsx +20 -9
- package/src/hoc/setUrl.tsx +3 -14
- package/src/hoc/updateRestfulObjectArrays.tsx +19 -10
- package/src/index.ts +0 -2
- package/src/variables/C6.tsx +1 -6
- package/dist/hoc/axiosInstance.d.ts +0 -5
- package/src/hoc/axiosInstance.tsx +0 -494
package/dist/variables/C6.d.ts
CHANGED
|
@@ -471,7 +471,5 @@ export interface iRestfulObjectArrayTypes {
|
|
|
471
471
|
users: tStatefulApiData<iUsers>;
|
|
472
472
|
}
|
|
473
473
|
export declare const initialRestfulObjectsState: iRestfulObjectArrayTypes;
|
|
474
|
-
export type
|
|
475
|
-
export type tRestfulObjectArrayValues = iRestfulObjectArrayTypes[tRestfulObjectArrayKeys];
|
|
476
|
-
export type tRestfulObjectValues = tRestfulObjectArrayValues[number];
|
|
474
|
+
export type tRestfulObjectArrayValues = iRestfulObjectArrayTypes[keyof iRestfulObjectArrayTypes];
|
|
477
475
|
export {};
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbonorm/carbonreact",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"module": "dist/index.esm.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@carbonorm/carbonnode": "^1.0.
|
|
9
|
+
"@carbonorm/carbonnode": "^1.0.12",
|
|
10
10
|
"@fortawesome/fontawesome-svg-core": "^6.4.0",
|
|
11
11
|
"@fortawesome/free-solid-svg-icons": "^6.4.0",
|
|
12
12
|
"@fortawesome/react-fontawesome": "^0.2.0",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@rollup/plugin-node-resolve": "^7.0.0",
|
|
34
34
|
"@rollup/plugin-typescript": "^11.1.2",
|
|
35
35
|
"@types/ms": "^0.7.31",
|
|
36
|
-
"@types/node": "^18.
|
|
36
|
+
"@types/node": "^18.17.14",
|
|
37
37
|
"@types/react": "^18.0.32",
|
|
38
38
|
"@types/react-dom": "^18.0.11",
|
|
39
39
|
"@types/styled-components": "5.1.24",
|
package/src/CarbonReact.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import {clearCache} from "@carbonorm/carbonnode";
|
|
|
2
2
|
import changed from "hoc/changed";
|
|
3
3
|
import {GlobalHistory} from "hoc/GlobalHistory";
|
|
4
4
|
import hexToRgb from "hoc/hexToRgb";
|
|
5
|
-
import
|
|
5
|
+
import {Component, ReactNode} from 'react';
|
|
6
6
|
import {BrowserRouter} from 'react-router-dom';
|
|
7
7
|
import {ToastContainer} from 'react-toastify';
|
|
8
8
|
import 'react-toastify/dist/ReactToastify.min.css';
|
|
@@ -28,16 +28,18 @@ export const initialRequiredCarbonORMState: iCarbonReactState = {
|
|
|
28
28
|
websocketEvents: [],
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export const initialCarbonReactState: iCarbonReactState = {
|
|
31
|
+
export const initialCarbonReactState: iCarbonReactState & iRestfulObjectArrayTypes = {
|
|
32
32
|
...initialRequiredCarbonORMState,
|
|
33
33
|
...initialRestfulObjectsState,
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
const CarbonReact= class <P = {}, S = {}> extends Component<{
|
|
37
37
|
children?: ReactNode | ReactNode[],
|
|
38
|
-
} & P,
|
|
38
|
+
} & P, S & iCarbonReactState> {
|
|
39
39
|
|
|
40
|
-
static instance:
|
|
40
|
+
static instance: Component<{
|
|
41
|
+
children?: ReactNode | ReactNode[],
|
|
42
|
+
} & any, any & iCarbonReactState>;
|
|
41
43
|
|
|
42
44
|
static lastLocation = window.location.pathname;
|
|
43
45
|
|
|
@@ -49,16 +51,13 @@ export default class CarbonReact<P = {}, S = {}> extends React.Component<{
|
|
|
49
51
|
|
|
50
52
|
super(props);
|
|
51
53
|
|
|
52
|
-
this.state = initialCarbonReactState as unknown as
|
|
53
|
-
|
|
54
|
-
CarbonReact.instance = this;
|
|
54
|
+
this.state = initialCarbonReactState as unknown as S & iCarbonReactState;
|
|
55
55
|
|
|
56
56
|
// This should only ever be done here, when the full state is being trashed.
|
|
57
57
|
clearCache({
|
|
58
58
|
ignoreWarning: true
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
|
|
62
61
|
/** We can think of our app as having one state; this state.
|
|
63
62
|
* Long-term, I'd like us to store this state to local storage and only load updates on reload...
|
|
64
63
|
* Class based components are far easier to manage state in local storage and pass state down to children.
|
|
@@ -122,4 +121,4 @@ export default class CarbonReact<P = {}, S = {}> extends React.Component<{
|
|
|
122
121
|
|
|
123
122
|
}
|
|
124
123
|
|
|
125
|
-
|
|
124
|
+
export default CarbonReact;
|
|
@@ -1,23 +1,34 @@
|
|
|
1
|
-
import CarbonReact
|
|
2
|
-
import {
|
|
1
|
+
import CarbonReact from "CarbonReact";
|
|
2
|
+
import {tRestfulObjectArrayValues, tStatefulApiData} from "variables/C6";
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
//ObjectType, UniqueIdType extends keyof ObjectType
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
// @link https://www.typescriptlang.org/docs/handbook/2/mapped-types.html
|
|
7
|
+
export default function deleteRestfulObjectArrays<ObjectType = tRestfulObjectArrayValues, S = {}, P = {}>
|
|
8
|
+
(dataOrCallback: ObjectType[] | (<K extends keyof S>(
|
|
9
|
+
state: ((prevState: Readonly<S>, props: Readonly<P>) => (Pick<S, K> | S | null)) | (Pick<S, K> | S | null),
|
|
10
|
+
callback?: () => void
|
|
11
|
+
) => ObjectType[]),
|
|
12
|
+
stateKey: S[keyof S] extends tStatefulApiData<ObjectType> ? keyof S : never,
|
|
9
13
|
uniqueObjectId: keyof ObjectType,
|
|
10
14
|
callback?: () => void): void {
|
|
11
15
|
|
|
12
|
-
return CarbonReact.instance.setState((previousBootstrapState )
|
|
16
|
+
return CarbonReact.instance.setState((previousBootstrapState, props) => {
|
|
13
17
|
|
|
14
|
-
let newOrReplacementData: ObjectType[]
|
|
18
|
+
let newOrReplacementData: ObjectType[] = [];
|
|
19
|
+
|
|
20
|
+
if (dataOrCallback instanceof Array) {
|
|
21
|
+
newOrReplacementData = dataOrCallback
|
|
22
|
+
} else if (dataOrCallback instanceof Function) {
|
|
23
|
+
newOrReplacementData = dataOrCallback(previousBootstrapState, props);
|
|
24
|
+
} else {
|
|
25
|
+
throw Error('The dataOrCallback parameter was not an array or function')
|
|
26
|
+
}
|
|
15
27
|
|
|
16
|
-
// @ts-ignore
|
|
17
28
|
const previousStateProperty = previousBootstrapState[stateKey];
|
|
18
29
|
|
|
19
30
|
return {
|
|
20
|
-
[stateKey]:
|
|
31
|
+
[stateKey]: [
|
|
21
32
|
...previousStateProperty?.filter(item => false === (newOrReplacementData?.find(value => value[uniqueObjectId] === item[uniqueObjectId]) || false)) || []
|
|
22
33
|
] as ObjectType[]
|
|
23
34
|
}
|
package/src/hoc/setUrl.tsx
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
// @link https://www.benmvp.com/blog/mocking-window-location-methods-jest-jsdom/
|
|
2
|
-
import axiosInstance from "
|
|
2
|
+
import {axiosInstance} from "@carbonorm/carbonnode";
|
|
3
3
|
|
|
4
|
-
export default function setUrl() {
|
|
5
|
-
|
|
6
|
-
const isGitHubActions = process.env.REACT_APP_TEST_REMOTE === 'true'
|
|
7
|
-
|
|
8
|
-
const host = ( isGitHubActions ? process.env.REACT_APP_REMOTE_SUBDOMAIN : process.env.REACT_APP_LOCAL_SUBDOMAIN ) + '.example.com' + (isGitHubActions ? '' : ':8080')
|
|
9
|
-
|
|
10
|
-
console.log("test host:: ", host, isGitHubActions)
|
|
11
|
-
|
|
12
|
-
/*Object.defineProperty(global, 'window', {
|
|
13
|
-
writable: true,
|
|
14
|
-
value: Object.create(window)
|
|
15
|
-
});*/
|
|
4
|
+
export default function setUrl(host: string = 'www.example.com', https: boolean = false) {
|
|
16
5
|
|
|
17
6
|
if (!global.structuredClone){
|
|
18
7
|
|
|
@@ -24,7 +13,7 @@ export default function setUrl() {
|
|
|
24
13
|
}
|
|
25
14
|
|
|
26
15
|
// noinspection HttpUrlsUsage
|
|
27
|
-
axiosInstance.defaults.baseURL = 'http' + (
|
|
16
|
+
axiosInstance.defaults.baseURL = 'http' + (https ? 's' : '') + '://' + host + '/';
|
|
28
17
|
|
|
29
18
|
Object.defineProperty(global.window, 'location', {
|
|
30
19
|
writable: true,
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
} from "CarbonReact";
|
|
4
|
-
import {iRestfulObjectArrayTypes, tRestfulObjectValues} from "variables/C6";
|
|
1
|
+
import {tRestfulObjectArrayValues, tStatefulApiData} from "variables/C6";
|
|
2
|
+
import CarbonReact from "CarbonReact";
|
|
5
3
|
|
|
6
4
|
|
|
7
5
|
export enum eUpdateInsertMethod {
|
|
@@ -20,18 +18,29 @@ export enum eUpdateInsertMethod {
|
|
|
20
18
|
* @param callback - if you want to do something with the updated state, you can pass a callback here. Run as the second
|
|
21
19
|
* parameter of setState.
|
|
22
20
|
*/
|
|
23
|
-
export default function updateRestfulObjectArrays<ObjectType =
|
|
24
|
-
(dataOrCallback:
|
|
25
|
-
|
|
21
|
+
export default function updateRestfulObjectArrays<ObjectType = tRestfulObjectArrayValues, S = {}, P = {}>
|
|
22
|
+
(dataOrCallback: ObjectType[] | (<K extends keyof S>(
|
|
23
|
+
state: ((prevState: Readonly<S>, props: Readonly<P>) => (Pick<S, K> | S | null)) | (Pick<S, K> | S | null),
|
|
24
|
+
callback?: () => void
|
|
25
|
+
) => ObjectType[]),
|
|
26
|
+
stateKey: S[keyof S] extends ObjectType ? keyof S : never,
|
|
26
27
|
uniqueObjectId: keyof ObjectType,
|
|
27
28
|
insertUpdateOrder: eUpdateInsertMethod = eUpdateInsertMethod.LAST,
|
|
28
29
|
callback?: () => void): void {
|
|
29
30
|
|
|
30
|
-
const bootstrap
|
|
31
|
+
const bootstrap = CarbonReact.instance;
|
|
31
32
|
|
|
32
|
-
return bootstrap.setState((previousBootstrapState): {} => {
|
|
33
|
+
return bootstrap.setState((previousBootstrapState, props): {} => {
|
|
33
34
|
|
|
34
|
-
let newOrReplacementData: ObjectType[]
|
|
35
|
+
let newOrReplacementData: ObjectType[] = [];
|
|
36
|
+
|
|
37
|
+
if (dataOrCallback instanceof Array) {
|
|
38
|
+
newOrReplacementData = dataOrCallback
|
|
39
|
+
} else if (dataOrCallback instanceof Function) {
|
|
40
|
+
newOrReplacementData = dataOrCallback(previousBootstrapState, props);
|
|
41
|
+
} else {
|
|
42
|
+
throw Error('The dataOrCallback parameter was not an array or function')
|
|
43
|
+
}
|
|
35
44
|
|
|
36
45
|
// @ts-ignore
|
|
37
46
|
const previousStateProperty = previousBootstrapState[stateKey];
|
package/src/index.ts
CHANGED
|
@@ -23,8 +23,6 @@ export * from "./components/Popup/Popup";
|
|
|
23
23
|
export * from "./hoc/GlobalHistory";
|
|
24
24
|
export { default as addValidSQL } from "./hoc/addValidSQL";
|
|
25
25
|
export * from "./hoc/addValidSQL";
|
|
26
|
-
export { default as axiosInstance } from "./hoc/axiosInstance";
|
|
27
|
-
export * from "./hoc/axiosInstance";
|
|
28
26
|
export { default as changed } from "./hoc/changed";
|
|
29
27
|
export * from "./hoc/changed";
|
|
30
28
|
export { default as deleteRestfulObjectArrays } from "./hoc/deleteRestfulObjectArrays";
|
package/src/variables/C6.tsx
CHANGED
|
@@ -1824,12 +1824,7 @@ export const initialRestfulObjectsState: iRestfulObjectArrayTypes = {
|
|
|
1824
1824
|
users: undefined,
|
|
1825
1825
|
};
|
|
1826
1826
|
|
|
1827
|
-
export type
|
|
1828
|
-
|
|
1829
|
-
export type tRestfulObjectArrayValues = iRestfulObjectArrayTypes[tRestfulObjectArrayKeys];
|
|
1830
|
-
|
|
1831
|
-
// @ts-ignore
|
|
1832
|
-
export type tRestfulObjectValues = tRestfulObjectArrayValues[number];
|
|
1827
|
+
export type tRestfulObjectArrayValues = iRestfulObjectArrayTypes[keyof iRestfulObjectArrayTypes];
|
|
1833
1828
|
|
|
1834
1829
|
|
|
1835
1830
|
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance, AxiosResponse } from "axios";
|
|
2
|
-
export declare function HandleResponseCodes(data: any): void;
|
|
3
|
-
export declare function setCookies(cookies: string[], req?: AxiosResponse | undefined): void;
|
|
4
|
-
declare const axiosInstance: AxiosInstance;
|
|
5
|
-
export default axiosInstance;
|