@carbonorm/carbonreact 2.0.0 → 2.0.2
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 +8 -15
- package/dist/hoc/deleteRestfulObjectArrays.d.ts +3 -2
- package/dist/hoc/getStyles.d.ts +3 -3
- package/dist/hoc/updateRestfulObjectArrays.d.ts +3 -2
- package/dist/index.cjs.js +1525 -2650
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.esm.js +1523 -2636
- package/dist/index.esm.js.map +1 -1
- package/dist/variables/C6.d.ts +33 -564
- package/package.json +2 -1
- package/src/CarbonReact.tsx +10 -11
- package/src/hoc/deleteRestfulObjectArrays.tsx +8 -6
- package/src/hoc/updateRestfulObjectArrays.tsx +7 -7
- package/src/hoc/uploadImage.tsx +68 -23
- package/src/index.ts +0 -2
- package/src/variables/C6.tsx +3 -1
- package/dist/components/Errors/Localhost.d.ts +0 -1
package/src/CarbonReact.tsx
CHANGED
|
@@ -8,12 +8,12 @@ import {ToastContainer} from 'react-toastify';
|
|
|
8
8
|
import 'react-toastify/dist/ReactToastify.min.css';
|
|
9
9
|
import BackendThrowable from 'components/Errors/BackendThrowable';
|
|
10
10
|
import Nest from 'components/Nest/Nest';
|
|
11
|
-
import {
|
|
11
|
+
import {initialRestfulObjectsState, iRestfulObjectArrayTypes} from "variables/C6";
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
// our central container, single page application is best with the DigApi
|
|
16
|
-
export interface
|
|
16
|
+
export interface iCarbonReactState {
|
|
17
17
|
alertsWaiting: any[],
|
|
18
18
|
websocketEvents: MessageEvent[],
|
|
19
19
|
websocketData: any[],
|
|
@@ -21,22 +21,21 @@ export interface iCarbonORMState {
|
|
|
21
21
|
backendThrowable: any[],
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export const
|
|
24
|
+
export const initialRequiredCarbonORMState: iCarbonReactState = {
|
|
25
25
|
alertsWaiting: [],
|
|
26
26
|
backendThrowable: [],
|
|
27
27
|
websocketData: [],
|
|
28
28
|
websocketEvents: [],
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export const
|
|
32
|
-
...
|
|
33
|
-
...
|
|
34
|
-
|
|
31
|
+
export const initialCarbonReactState: iCarbonReactState = {
|
|
32
|
+
...initialRequiredCarbonORMState,
|
|
33
|
+
...initialRestfulObjectsState,
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
export default class CarbonReact<P = {}, S = {}> extends React.Component<{
|
|
38
37
|
children?: ReactNode | ReactNode[],
|
|
39
|
-
} & P, ( iRestfulObjectArrayTypes |& S ) &
|
|
38
|
+
} & P, ( iRestfulObjectArrayTypes |& S ) & iCarbonReactState> {
|
|
40
39
|
|
|
41
40
|
static instance: CarbonReact;
|
|
42
41
|
|
|
@@ -50,7 +49,7 @@ export default class CarbonReact<P = {}, S = {}> extends React.Component<{
|
|
|
50
49
|
|
|
51
50
|
super(props);
|
|
52
51
|
|
|
53
|
-
this.state =
|
|
52
|
+
this.state = initialCarbonReactState as unknown as iCarbonReactState & S;
|
|
54
53
|
|
|
55
54
|
CarbonReact.instance = this;
|
|
56
55
|
|
|
@@ -73,7 +72,7 @@ export default class CarbonReact<P = {}, S = {}> extends React.Component<{
|
|
|
73
72
|
|
|
74
73
|
shouldComponentUpdate(
|
|
75
74
|
nextProps: Readonly<any>,
|
|
76
|
-
nextState: Readonly<
|
|
75
|
+
nextState: Readonly<iCarbonReactState>,
|
|
77
76
|
_nextContext: any): boolean {
|
|
78
77
|
|
|
79
78
|
changed(this.constructor.name + ' (DigApi)', 'props', this.props, nextProps);
|
|
@@ -83,7 +82,7 @@ export default class CarbonReact<P = {}, S = {}> extends React.Component<{
|
|
|
83
82
|
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
componentDidUpdate(_prevProps: Readonly<any>, _prevState: Readonly<
|
|
85
|
+
componentDidUpdate(_prevProps: Readonly<any>, _prevState: Readonly<iCarbonReactState>, _snapshot?: any) {
|
|
87
86
|
if (CarbonReact.lastLocation !== location.pathname) {
|
|
88
87
|
CarbonReact.lastLocation = location.pathname;
|
|
89
88
|
const websocket = this.state.websocket;
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import CarbonReact, {
|
|
1
|
+
import CarbonReact, {iCarbonReactState} from "CarbonReact";
|
|
2
|
+
import {iRestfulObjectArrayTypes, tRestfulObjectValues} from "variables/C6";
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
//ObjectType, UniqueIdType extends keyof ObjectType
|
|
5
|
-
export default function deleteRestfulObjectArrays<ObjectType
|
|
6
|
-
(dataOrCallback: ((prev: Readonly<
|
|
7
|
-
stateKey: keyof
|
|
6
|
+
export default function deleteRestfulObjectArrays<ObjectType = tRestfulObjectValues, ObjectArrayTypes = iRestfulObjectArrayTypes>
|
|
7
|
+
(dataOrCallback: ((prev: Readonly<iCarbonReactState>) => ObjectType[]) | ObjectType[],
|
|
8
|
+
stateKey: keyof ObjectArrayTypes,
|
|
8
9
|
uniqueObjectId: keyof ObjectType,
|
|
9
10
|
callback?: () => void): void {
|
|
10
11
|
|
|
11
|
-
return CarbonReact.instance.setState((previousBootstrapState): {} => {
|
|
12
|
+
return CarbonReact.instance.setState((previousBootstrapState ): {} => {
|
|
12
13
|
|
|
13
14
|
let newOrReplacementData: ObjectType[] = dataOrCallback instanceof Function ? dataOrCallback(previousBootstrapState) : dataOrCallback;
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
const previousStateProperty = previousBootstrapState[stateKey];
|
|
16
18
|
|
|
17
19
|
return {
|
|
18
20
|
[stateKey]: null === previousBootstrapState ? null : [
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import CarbonReact, {
|
|
2
|
-
|
|
3
|
-
iRestfulObjectArrayTypes,
|
|
4
|
-
tRestfulObjectValues
|
|
2
|
+
iCarbonReactState
|
|
5
3
|
} from "CarbonReact";
|
|
4
|
+
import {iRestfulObjectArrayTypes, tRestfulObjectValues} from "variables/C6";
|
|
6
5
|
|
|
7
6
|
|
|
8
7
|
export enum eUpdateInsertMethod {
|
|
@@ -21,9 +20,9 @@ export enum eUpdateInsertMethod {
|
|
|
21
20
|
* @param callback - if you want to do something with the updated state, you can pass a callback here. Run as the second
|
|
22
21
|
* parameter of setState.
|
|
23
22
|
*/
|
|
24
|
-
export default function updateRestfulObjectArray<ObjectType
|
|
25
|
-
(dataOrCallback: ((prev: Readonly<
|
|
26
|
-
stateKey: keyof
|
|
23
|
+
export default function updateRestfulObjectArray<ObjectType = tRestfulObjectValues, ObjectArrayTypes = iRestfulObjectArrayTypes>
|
|
24
|
+
(dataOrCallback: ((prev: Readonly<iCarbonReactState>) => ObjectType[]) | ObjectType[],
|
|
25
|
+
stateKey: keyof ObjectArrayTypes,
|
|
27
26
|
uniqueObjectId: keyof ObjectType,
|
|
28
27
|
insertUpdateOrder: eUpdateInsertMethod = eUpdateInsertMethod.LAST,
|
|
29
28
|
callback?: () => void): void {
|
|
@@ -34,7 +33,8 @@ export default function updateRestfulObjectArray<ObjectType extends tRestfulObje
|
|
|
34
33
|
|
|
35
34
|
let newOrReplacementData: ObjectType[] = dataOrCallback instanceof Function ? dataOrCallback(previousBootstrapState) : dataOrCallback;
|
|
36
35
|
|
|
37
|
-
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
const previousStateProperty = previousBootstrapState[stateKey];
|
|
38
38
|
|
|
39
39
|
let updatedData = newOrReplacementData.map(value => {
|
|
40
40
|
return {
|
package/src/hoc/uploadImage.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @link https://stackoverflow.com/questions/6735414/php-data-uri-to-file
|
|
2
2
|
// @link https://www.tutorialspoint.com/convert-image-to-data-uri-with-javascript
|
|
3
|
-
import {ChangeEvent} from "react";
|
|
3
|
+
import {ChangeEvent, lazy} from "react";
|
|
4
4
|
import {toast} from "react-toastify";
|
|
5
5
|
|
|
6
6
|
|
|
@@ -40,40 +40,69 @@ export async function toDataURL(src: string, fileType: string, callback: (dataUr
|
|
|
40
40
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export function uploadImageChange(event: ChangeEvent<HTMLInputElement>,
|
|
44
|
-
uploadCallback: (
|
|
43
|
+
export async function uploadImageChange(event: ChangeEvent<HTMLInputElement>,
|
|
44
|
+
uploadCallback: (dataUriBase64: string) => void) {
|
|
45
45
|
|
|
46
|
-
if (event.target.files
|
|
46
|
+
if (event.target.files === null || undefined === event.target?.files?.[0]) {
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
toast.error('Please upload a valid image file type (jpg, jpeg, png, gif, heic).');
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
return;
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Object.keys(event.target.files).forEach((index) => {
|
|
55
|
+
|
|
56
|
+
(async () => {
|
|
57
|
+
let file = event.target.files?.[index];
|
|
51
58
|
|
|
52
59
|
// loop through all files and create data url then post to postPost
|
|
53
|
-
if (file.type.match('image.*')) {
|
|
60
|
+
if (false === file.type.match('image.*')) {
|
|
54
61
|
|
|
55
|
-
|
|
56
|
-
const fileExtension = file.name.split('.').pop();
|
|
62
|
+
toast.error('Please upload a valid image file type (jpg, jpeg, png, gif, heic). (E_IMAGE_*<>' + file.type + ')');
|
|
57
63
|
|
|
58
|
-
|
|
59
|
-
if (fileExtension !== 'jpg' && fileExtension !== 'jpeg' && fileExtension !== 'png' && fileExtension !== 'gif') {
|
|
64
|
+
return;
|
|
60
65
|
|
|
61
|
-
|
|
66
|
+
}
|
|
62
67
|
|
|
63
|
-
|
|
68
|
+
// get file extension
|
|
69
|
+
const fileExtension = file.name.split('.').pop();
|
|
64
70
|
|
|
65
|
-
|
|
71
|
+
// check file extension is valid data uri
|
|
72
|
+
if (fileExtension !== 'jpg'
|
|
73
|
+
&& fileExtension !== 'jpeg'
|
|
74
|
+
&& fileExtension !== 'heic'
|
|
75
|
+
&& fileExtension !== 'png'
|
|
76
|
+
&& fileExtension !== 'gif') {
|
|
66
77
|
|
|
78
|
+
toast.error('Please upload a valid image file type (jpg, jpeg, png, gif, heic). (E_IMAGE_EXT)');
|
|
67
79
|
|
|
68
|
-
|
|
69
|
-
// @link https://github.com/Microsoft/TypeScript/issues/13376#issuecomment-273289748
|
|
70
|
-
void toDataURL(URL.createObjectURL(file), file.type, uploadCallback);
|
|
80
|
+
return;
|
|
71
81
|
|
|
72
82
|
}
|
|
73
83
|
|
|
74
|
-
|
|
84
|
+
const isHeic = fileExtension === 'heic';
|
|
85
|
+
|
|
86
|
+
if (isHeic) {
|
|
87
|
+
|
|
88
|
+
// todo - this should be code split and lazy loaded, but doesn't work
|
|
89
|
+
// look up code splitting, it could be an issue with rewired
|
|
90
|
+
file = (await lazy(() => require("heic2any")))({
|
|
91
|
+
blob: file,
|
|
92
|
+
toType: "image/webp",
|
|
93
|
+
quality: 1.0, // 0.5 cuts the quality and size by half
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// @link https://github.com/palantir/tslint/issues/4653
|
|
99
|
+
// @link https://github.com/Microsoft/TypeScript/issues/13376#issuecomment-273289748
|
|
100
|
+
void toDataURL(URL.createObjectURL(file), 'image/webp', uploadCallback);
|
|
101
|
+
|
|
102
|
+
})();
|
|
103
|
+
|
|
104
|
+
});
|
|
75
105
|
|
|
76
|
-
}
|
|
77
106
|
|
|
78
107
|
}
|
|
79
108
|
|
|
@@ -81,12 +110,28 @@ uploadCallback: ((imageDataUri: string) => void)) {
|
|
|
81
110
|
// dataUriEncoded is the base64 encoded string which is posted in column post_content
|
|
82
111
|
export default function uploadImage(uploadCallback: (dataUriBase64: string) => void) {
|
|
83
112
|
return () => {
|
|
113
|
+
|
|
84
114
|
const input: HTMLInputElement = document.createElement('input')
|
|
115
|
+
|
|
85
116
|
input.type = 'file'
|
|
86
|
-
|
|
87
|
-
input.
|
|
88
|
-
|
|
89
|
-
|
|
117
|
+
|
|
118
|
+
input.accept = 'image/*, .heic'
|
|
119
|
+
|
|
120
|
+
input.style.display = 'none'
|
|
121
|
+
|
|
122
|
+
// the element must be appended to the document to work on safari
|
|
123
|
+
// @link https://stackoverflow.com/questions/47664777/javascript-file-input-onchange-not-working-ios-safari-only
|
|
124
|
+
document.body.appendChild(input);
|
|
125
|
+
|
|
126
|
+
// safari also requires addEventListener rather than .onChange
|
|
127
|
+
input.addEventListener('change', (e) => {
|
|
128
|
+
|
|
129
|
+
console.log('upload image event', e)
|
|
130
|
+
|
|
131
|
+
void uploadImageChange(e as unknown as ChangeEvent<HTMLInputElement>, uploadCallback)
|
|
132
|
+
|
|
133
|
+
})
|
|
134
|
+
|
|
90
135
|
input.click()
|
|
91
136
|
}
|
|
92
137
|
}
|
package/src/index.ts
CHANGED
|
@@ -12,8 +12,6 @@ export { default as BackendThrowable } from "./components/Errors/BackendThrowabl
|
|
|
12
12
|
export * from "./components/Errors/BackendThrowable";
|
|
13
13
|
export { default as ErrorHttpCode } from "./components/Errors/ErrorHttpCode";
|
|
14
14
|
export * from "./components/Errors/ErrorHttpCode";
|
|
15
|
-
export { default as Localhost } from "./components/Errors/Localhost";
|
|
16
|
-
export * from "./components/Errors/Localhost";
|
|
17
15
|
export { default as PageNotFound } from "./components/Errors/PageNotFound";
|
|
18
16
|
export * from "./components/Errors/PageNotFound";
|
|
19
17
|
export { default as Loading } from "./components/Loading/Loading";
|
package/src/variables/C6.tsx
CHANGED
|
@@ -1802,7 +1802,7 @@ export interface iRestfulObjectArrayTypes {
|
|
|
1802
1802
|
users: tStatefulApiData<iUsers>,
|
|
1803
1803
|
}
|
|
1804
1804
|
|
|
1805
|
-
export const
|
|
1805
|
+
export const initialRestfulObjectsState: iRestfulObjectArrayTypes = {
|
|
1806
1806
|
|
|
1807
1807
|
carbons: undefined,
|
|
1808
1808
|
comments: undefined,
|
|
@@ -1832,3 +1832,5 @@ export type tRestfulObjectArrayValues = iRestfulObjectArrayTypes[tRestfulObjectA
|
|
|
1832
1832
|
export type tRestfulObjectValues = tRestfulObjectArrayValues[number];
|
|
1833
1833
|
|
|
1834
1834
|
|
|
1835
|
+
|
|
1836
|
+
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function Localhost(): import("react/jsx-runtime").JSX.Element;
|