@carbonorm/carbonreact 2.0.1 → 2.0.3
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 +6 -6
- package/dist/hoc/deleteRestfulObjectArrays.d.ts +2 -2
- package/dist/hoc/updateRestfulObjectArrays.d.ts +2 -2
- package/dist/hoc/uploadImage.d.ts +1 -1
- package/dist/index.cjs.js +68 -26
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +68 -26
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -1
- package/src/CarbonReact.tsx +7 -7
- package/src/hoc/deleteRestfulObjectArrays.tsx +2 -2
- package/src/hoc/updateRestfulObjectArrays.tsx +3 -3
- package/src/hoc/uploadImage.tsx +68 -23
package/dist/CarbonReact.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
2
|
import 'react-toastify/dist/ReactToastify.min.css';
|
|
3
3
|
import { iRestfulObjectArrayTypes } from "variables/C6";
|
|
4
|
-
export interface
|
|
4
|
+
export interface iCarbonReactState {
|
|
5
5
|
alertsWaiting: any[];
|
|
6
6
|
websocketEvents: MessageEvent[];
|
|
7
7
|
websocketData: any[];
|
|
8
8
|
websocket?: WebSocket;
|
|
9
9
|
backendThrowable: any[];
|
|
10
10
|
}
|
|
11
|
-
export declare const initialRequiredCarbonORMState:
|
|
12
|
-
export declare const
|
|
11
|
+
export declare const initialRequiredCarbonORMState: iCarbonReactState;
|
|
12
|
+
export declare const initialCarbonReactState: iCarbonReactState;
|
|
13
13
|
export default class CarbonReact<P = {}, S = {}> extends React.Component<{
|
|
14
14
|
children?: ReactNode | ReactNode[];
|
|
15
|
-
} & P, (iRestfulObjectArrayTypes | S) &
|
|
15
|
+
} & P, (iRestfulObjectArrayTypes | S) & iCarbonReactState> {
|
|
16
16
|
static instance: CarbonReact;
|
|
17
17
|
static lastLocation: string;
|
|
18
18
|
static whyDidYouRender: boolean;
|
|
19
19
|
constructor(props: any);
|
|
20
20
|
websocketTimeout: number;
|
|
21
|
-
shouldComponentUpdate(nextProps: Readonly<any>, nextState: Readonly<
|
|
22
|
-
componentDidUpdate(_prevProps: Readonly<any>, _prevState: Readonly<
|
|
21
|
+
shouldComponentUpdate(nextProps: Readonly<any>, nextState: Readonly<iCarbonReactState>, _nextContext: any): boolean;
|
|
22
|
+
componentDidUpdate(_prevProps: Readonly<any>, _prevState: Readonly<iCarbonReactState>, _snapshot?: any): void;
|
|
23
23
|
render(): import("react/jsx-runtime").JSX.Element;
|
|
24
24
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { iCarbonReactState } from "CarbonReact";
|
|
2
2
|
import { iRestfulObjectArrayTypes, tRestfulObjectValues } from "variables/C6";
|
|
3
|
-
export default function deleteRestfulObjectArrays<ObjectType = tRestfulObjectValues, ObjectArrayTypes = iRestfulObjectArrayTypes>(dataOrCallback: ((prev: Readonly<
|
|
3
|
+
export default function deleteRestfulObjectArrays<ObjectType = tRestfulObjectValues, ObjectArrayTypes = iRestfulObjectArrayTypes>(dataOrCallback: ((prev: Readonly<iCarbonReactState>) => ObjectType[]) | ObjectType[], stateKey: keyof ObjectArrayTypes, uniqueObjectId: keyof ObjectType, callback?: () => void): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { iCarbonReactState } from "CarbonReact";
|
|
2
2
|
import { iRestfulObjectArrayTypes, tRestfulObjectValues } from "variables/C6";
|
|
3
3
|
export declare enum eUpdateInsertMethod {
|
|
4
4
|
REPLACE = 0,
|
|
@@ -15,4 +15,4 @@ export declare enum eUpdateInsertMethod {
|
|
|
15
15
|
* @param callback - if you want to do something with the updated state, you can pass a callback here. Run as the second
|
|
16
16
|
* parameter of setState.
|
|
17
17
|
*/
|
|
18
|
-
export default function
|
|
18
|
+
export default function updateRestfulObjectArrays<ObjectType = tRestfulObjectValues, ObjectArrayTypes = iRestfulObjectArrayTypes>(dataOrCallback: ((prev: Readonly<iCarbonReactState>) => ObjectType[]) | ObjectType[], stateKey: keyof ObjectArrayTypes, uniqueObjectId: keyof ObjectType, insertUpdateOrder?: eUpdateInsertMethod, callback?: () => void): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ChangeEvent } from "react";
|
|
2
2
|
export declare function toDataURL(src: string, fileType: string, callback: (dataUriEncoded: string) => void): Promise<void>;
|
|
3
|
-
export declare function uploadImageChange(event: ChangeEvent<HTMLInputElement>, uploadCallback: (
|
|
3
|
+
export declare function uploadImageChange(event: ChangeEvent<HTMLInputElement>, uploadCallback: (dataUriBase64: string) => void): Promise<void>;
|
|
4
4
|
export default function uploadImage(uploadCallback: (dataUriBase64: string) => void): () => void;
|
package/dist/index.cjs.js
CHANGED
|
@@ -2781,13 +2781,13 @@ var initialRequiredCarbonORMState = {
|
|
|
2781
2781
|
websocketData: [],
|
|
2782
2782
|
websocketEvents: [],
|
|
2783
2783
|
};
|
|
2784
|
-
var
|
|
2784
|
+
var initialCarbonReactState = __assign(__assign({}, initialRequiredCarbonORMState), initialRestfulObjectsState);
|
|
2785
2785
|
var CarbonReact = /** @class */ (function (_super) {
|
|
2786
2786
|
__extends(CarbonReact, _super);
|
|
2787
2787
|
function CarbonReact(props) {
|
|
2788
2788
|
var _this = _super.call(this, props) || this;
|
|
2789
2789
|
_this.websocketTimeout = 5000;
|
|
2790
|
-
_this.state =
|
|
2790
|
+
_this.state = initialCarbonReactState;
|
|
2791
2791
|
CarbonReact.instance = _this;
|
|
2792
2792
|
// This should only ever be done here, when the full state is being trashed.
|
|
2793
2793
|
carbonnode.clearCache({
|
|
@@ -3438,7 +3438,7 @@ exports.eUpdateInsertMethod = void 0;
|
|
|
3438
3438
|
* @param callback - if you want to do something with the updated state, you can pass a callback here. Run as the second
|
|
3439
3439
|
* parameter of setState.
|
|
3440
3440
|
*/
|
|
3441
|
-
function
|
|
3441
|
+
function updateRestfulObjectArrays(dataOrCallback, stateKey, uniqueObjectId, insertUpdateOrder, callback) {
|
|
3442
3442
|
if (insertUpdateOrder === void 0) { insertUpdateOrder = exports.eUpdateInsertMethod.LAST; }
|
|
3443
3443
|
var bootstrap = CarbonReact.instance;
|
|
3444
3444
|
return bootstrap.setState(function (previousBootstrapState) {
|
|
@@ -3501,35 +3501,77 @@ function toDataURL(src, fileType, callback) {
|
|
|
3501
3501
|
});
|
|
3502
3502
|
}
|
|
3503
3503
|
function uploadImageChange(event, uploadCallback) {
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
var fileExtension = file.name.split('.').pop();
|
|
3512
|
-
// check file extension is valid data uri
|
|
3513
|
-
if (fileExtension !== 'jpg' && fileExtension !== 'jpeg' && fileExtension !== 'png' && fileExtension !== 'gif') {
|
|
3514
|
-
reactToastify.toast.error('Please upload a valid image file type (jpg, jpeg, png, gif).');
|
|
3515
|
-
return;
|
|
3516
|
-
}
|
|
3517
|
-
// @link https://github.com/palantir/tslint/issues/4653
|
|
3518
|
-
// @link https://github.com/Microsoft/TypeScript/issues/13376#issuecomment-273289748
|
|
3519
|
-
void toDataURL(URL.createObjectURL(file), file.type, uploadCallback);
|
|
3504
|
+
var _a, _b;
|
|
3505
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3506
|
+
var _this = this;
|
|
3507
|
+
return __generator(this, function (_c) {
|
|
3508
|
+
if (event.target.files === null || undefined === ((_b = (_a = event.target) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b[0])) {
|
|
3509
|
+
reactToastify.toast.error('Please upload a valid image file type (jpg, jpeg, png, gif, heic).');
|
|
3510
|
+
return [2 /*return*/];
|
|
3520
3511
|
}
|
|
3512
|
+
Object.keys(event.target.files).forEach(function (index) {
|
|
3513
|
+
(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3514
|
+
var file, fileExtension, isHeic;
|
|
3515
|
+
var _a;
|
|
3516
|
+
return __generator(this, function (_b) {
|
|
3517
|
+
switch (_b.label) {
|
|
3518
|
+
case 0:
|
|
3519
|
+
file = (_a = event.target.files) === null || _a === void 0 ? void 0 : _a[index];
|
|
3520
|
+
// loop through all files and create data url then post to postPost
|
|
3521
|
+
if (false === file.type.match('image.*')) {
|
|
3522
|
+
reactToastify.toast.error('Please upload a valid image file type (jpg, jpeg, png, gif, heic). (E_IMAGE_*<>' + file.type + ')');
|
|
3523
|
+
return [2 /*return*/];
|
|
3524
|
+
}
|
|
3525
|
+
fileExtension = file.name.split('.').pop();
|
|
3526
|
+
// check file extension is valid data uri
|
|
3527
|
+
if (fileExtension !== 'jpg'
|
|
3528
|
+
&& fileExtension !== 'jpeg'
|
|
3529
|
+
&& fileExtension !== 'heic'
|
|
3530
|
+
&& fileExtension !== 'png'
|
|
3531
|
+
&& fileExtension !== 'gif') {
|
|
3532
|
+
reactToastify.toast.error('Please upload a valid image file type (jpg, jpeg, png, gif, heic). (E_IMAGE_EXT)');
|
|
3533
|
+
return [2 /*return*/];
|
|
3534
|
+
}
|
|
3535
|
+
isHeic = fileExtension === 'heic';
|
|
3536
|
+
if (!isHeic) return [3 /*break*/, 2];
|
|
3537
|
+
return [4 /*yield*/, React.lazy(function () { return require("heic2any"); })];
|
|
3538
|
+
case 1:
|
|
3539
|
+
// todo - this should be code split and lazy loaded, but doesn't work
|
|
3540
|
+
// look up code splitting, it could be an issue with rewired
|
|
3541
|
+
file = (_b.sent())({
|
|
3542
|
+
blob: file,
|
|
3543
|
+
toType: "image/webp",
|
|
3544
|
+
quality: 1.0, // 0.5 cuts the quality and size by half
|
|
3545
|
+
});
|
|
3546
|
+
_b.label = 2;
|
|
3547
|
+
case 2:
|
|
3548
|
+
// @link https://github.com/palantir/tslint/issues/4653
|
|
3549
|
+
// @link https://github.com/Microsoft/TypeScript/issues/13376#issuecomment-273289748
|
|
3550
|
+
void toDataURL(URL.createObjectURL(file), 'image/webp', uploadCallback);
|
|
3551
|
+
return [2 /*return*/];
|
|
3552
|
+
}
|
|
3553
|
+
});
|
|
3554
|
+
}); })();
|
|
3555
|
+
});
|
|
3556
|
+
return [2 /*return*/];
|
|
3521
3557
|
});
|
|
3522
|
-
}
|
|
3558
|
+
});
|
|
3523
3559
|
}
|
|
3524
3560
|
// dataUriEncoded is the base64 encoded string which is posted in column post_content
|
|
3525
3561
|
function uploadImage(uploadCallback) {
|
|
3526
3562
|
return function () {
|
|
3527
3563
|
var input = document.createElement('input');
|
|
3528
3564
|
input.type = 'file';
|
|
3529
|
-
input.accept = 'image
|
|
3530
|
-
input.
|
|
3531
|
-
|
|
3532
|
-
|
|
3565
|
+
input.accept = 'image/*, .heic';
|
|
3566
|
+
input.style.display = 'none';
|
|
3567
|
+
// the element must be appended to the document to work on safari
|
|
3568
|
+
// @link https://stackoverflow.com/questions/47664777/javascript-file-input-onchange-not-working-ios-safari-only
|
|
3569
|
+
document.body.appendChild(input);
|
|
3570
|
+
// safari also requires addEventListener rather than .onChange
|
|
3571
|
+
input.addEventListener('change', function (e) {
|
|
3572
|
+
console.log('upload image event', e);
|
|
3573
|
+
void uploadImageChange(e, uploadCallback);
|
|
3574
|
+
});
|
|
3533
3575
|
input.click();
|
|
3534
3576
|
};
|
|
3535
3577
|
}
|
|
@@ -3583,7 +3625,7 @@ exports.group_references = group_references;
|
|
|
3583
3625
|
exports.groups = groups;
|
|
3584
3626
|
exports.hexToRgb = hexToRgb;
|
|
3585
3627
|
exports.history_logs = history_logs;
|
|
3586
|
-
exports.
|
|
3628
|
+
exports.initialCarbonReactState = initialCarbonReactState;
|
|
3587
3629
|
exports.initialRequiredCarbonORMState = initialRequiredCarbonORMState;
|
|
3588
3630
|
exports.initialRestfulObjectsState = initialRestfulObjectsState;
|
|
3589
3631
|
exports.isEdgeBrowser = isEdgeBrowser;
|
|
@@ -3598,7 +3640,7 @@ exports.scrollIntoView = ScrollIntoViewDirective;
|
|
|
3598
3640
|
exports.setCookies = setCookies;
|
|
3599
3641
|
exports.setUrl = setUrl;
|
|
3600
3642
|
exports.toDataURL = toDataURL;
|
|
3601
|
-
exports.updateRestfulObjectArrays =
|
|
3643
|
+
exports.updateRestfulObjectArrays = updateRestfulObjectArrays;
|
|
3602
3644
|
exports.uploadImage = uploadImage;
|
|
3603
3645
|
exports.uploadImageChange = uploadImageChange;
|
|
3604
3646
|
exports.user_followers = user_followers;
|