dce-reactkit 3.3.1 → 3.3.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/cjs/index.js +20 -32
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/client/initClient.d.ts +1 -10
- package/dist/cjs/types/components/AppWrapper.d.ts +1 -0
- package/dist/esm/index.js +20 -32
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/client/initClient.d.ts +1 -10
- package/dist/esm/types/components/AppWrapper.d.ts +1 -0
- package/dist/index.d.ts +1 -2
- package/package.json +1 -1
- package/src/client/initClient.tsx +18 -44
- package/src/components/AppWrapper.tsx +4 -2
- package/src/helpers/visitServerEndpoint.tsx +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -544,12 +544,14 @@ var LogLevel;
|
|
|
544
544
|
})(LogLevel || (LogLevel = {}));
|
|
545
545
|
var LogLevel$1 = LogLevel;
|
|
546
546
|
|
|
547
|
-
// Import other components
|
|
548
547
|
/*----------------------------------------*/
|
|
549
548
|
/* ---- Static Variables and Getters ---- */
|
|
550
549
|
/*----------------------------------------*/
|
|
551
550
|
/* ----------- Initialized ---------- */
|
|
552
|
-
let
|
|
551
|
+
let onInitialized;
|
|
552
|
+
let initialized = new Promise((resolve) => {
|
|
553
|
+
onInitialized = resolve;
|
|
554
|
+
});
|
|
553
555
|
/* ---------- Send Request ---------- */
|
|
554
556
|
let storedSendRequest;
|
|
555
557
|
/**
|
|
@@ -557,9 +559,18 @@ let storedSendRequest;
|
|
|
557
559
|
* @author Gabe Abrams
|
|
558
560
|
* @returns sendRequest function
|
|
559
561
|
*/
|
|
560
|
-
const getSendRequest = () => {
|
|
562
|
+
const getSendRequest = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
563
|
+
// Wait for initialization or timeout
|
|
564
|
+
let timedOut = false;
|
|
565
|
+
yield Promise.all([
|
|
566
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
567
|
+
yield waitMs(1000);
|
|
568
|
+
timedOut = true;
|
|
569
|
+
}))(),
|
|
570
|
+
initialized,
|
|
571
|
+
]);
|
|
561
572
|
// Error if no send request function
|
|
562
|
-
if (
|
|
573
|
+
if (timedOut) {
|
|
563
574
|
showFatalError(new ErrorWithCode('Could not send a request because the request needed to be sent before dce-reactkit was properly initialized. Perhaps dce-reactkit was not initialized with initClient.', ReactKitErrorCode$1.NoCACCLSendRequestFunction));
|
|
564
575
|
// Return dummy function that never resolves
|
|
565
576
|
return (() => {
|
|
@@ -568,23 +579,7 @@ const getSendRequest = () => {
|
|
|
568
579
|
}
|
|
569
580
|
// Return
|
|
570
581
|
return storedSendRequest;
|
|
571
|
-
};
|
|
572
|
-
/* ------------ Dark Mode ----------- */
|
|
573
|
-
let dark;
|
|
574
|
-
/**
|
|
575
|
-
* Get the current dark/light theme
|
|
576
|
-
* @author Gabe Abrams
|
|
577
|
-
* @returns true if the app has a dark theme
|
|
578
|
-
*/
|
|
579
|
-
const darkModeIsOn = () => {
|
|
580
|
-
// Error if not set up yet
|
|
581
|
-
if (!initialized) {
|
|
582
|
-
showFatalError(new ErrorWithCode('Could not check theme color because dce-reactkit was properly initialized. Perhaps dce-reactkit was not initialized with initClient.', ReactKitErrorCode$1.ThemeCheckedBeforeReactKitReady));
|
|
583
|
-
return false;
|
|
584
|
-
}
|
|
585
|
-
// Return
|
|
586
|
-
return !!dark;
|
|
587
|
-
};
|
|
582
|
+
});
|
|
588
583
|
/* ----- Session Expired Message ---- */
|
|
589
584
|
let sessionExpiredMessage;
|
|
590
585
|
/**
|
|
@@ -593,11 +588,6 @@ let sessionExpiredMessage;
|
|
|
593
588
|
* @returns session expired message
|
|
594
589
|
*/
|
|
595
590
|
const getSessionExpiredMessage = () => {
|
|
596
|
-
// Error if not set up yet
|
|
597
|
-
if (!initialized) {
|
|
598
|
-
showFatalError(new ErrorWithCode('Could not get the session expired message because dce-reactkit was properly initialized. Perhaps dce-reactkit was not initialized with initClient.', ReactKitErrorCode$1.SessionExpiredMessageGottenBeforeReactKitReady));
|
|
599
|
-
return '';
|
|
600
|
-
}
|
|
601
591
|
// Return
|
|
602
592
|
return (sessionExpiredMessage !== null && sessionExpiredMessage !== void 0 ? sessionExpiredMessage : 'Your session has expired. Please go back to Canvas and start over.');
|
|
603
593
|
};
|
|
@@ -609,16 +599,14 @@ const getSessionExpiredMessage = () => {
|
|
|
609
599
|
* @author Gabe Abrams
|
|
610
600
|
* @param opts object containing all arguments
|
|
611
601
|
* @param opts.sendRequest caccl send request functions
|
|
612
|
-
* @param [opts.dark] if true, the app is a dark-themed app
|
|
613
602
|
* @param [opts.sessionExpiredMessage] a custom session expired message
|
|
614
603
|
*/
|
|
615
604
|
const initClient = (opts) => {
|
|
616
605
|
// Store values
|
|
617
606
|
storedSendRequest = opts.sendRequest;
|
|
618
|
-
dark = !!opts.dark;
|
|
619
607
|
sessionExpiredMessage = opts.sessionExpiredMessage;
|
|
620
608
|
// Mark as initialized
|
|
621
|
-
|
|
609
|
+
onInitialized(null);
|
|
622
610
|
};
|
|
623
611
|
|
|
624
612
|
// Keep track of whether or not session expiry has already been handled
|
|
@@ -692,7 +680,7 @@ const visitServerEndpoint = (opts) => __awaiter(void 0, void 0, void 0, function
|
|
|
692
680
|
throw new ErrorWithCode(stubResponse.errorMessage, stubResponse.errorCode);
|
|
693
681
|
}
|
|
694
682
|
// Send the request
|
|
695
|
-
const sendRequest = getSendRequest();
|
|
683
|
+
const sendRequest = yield getSendRequest();
|
|
696
684
|
const response = yield sendRequest({
|
|
697
685
|
path: opts.path,
|
|
698
686
|
method: (_c = opts.method) !== null && _c !== void 0 ? _c : 'GET',
|
|
@@ -903,7 +891,7 @@ const AppWrapper = (props) => {
|
|
|
903
891
|
/* Setup */
|
|
904
892
|
/*------------------------------------------------------------------------*/
|
|
905
893
|
/* -------------- Props ------------- */
|
|
906
|
-
const { children, } = props;
|
|
894
|
+
const { children, dark, } = props;
|
|
907
895
|
/* -------------- State ------------- */
|
|
908
896
|
// Fatal error
|
|
909
897
|
const [fatalErrorMessage, setFatalErrorMessageInner,] = React.useState();
|
|
@@ -964,7 +952,7 @@ const AppWrapper = (props) => {
|
|
|
964
952
|
width: '100vw',
|
|
965
953
|
minHeight: '100vh',
|
|
966
954
|
paddingTop: '2rem',
|
|
967
|
-
backgroundColor: (
|
|
955
|
+
backgroundColor: (dark
|
|
968
956
|
? '#222'
|
|
969
957
|
: '#fff'),
|
|
970
958
|
} },
|