dce-reactkit 3.5.11 → 3.5.12

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 CHANGED
@@ -319,7 +319,7 @@ const ModalButtonTypeToLabelAndVariant = {
319
319
  /*------------------------------------------------------------------------*/
320
320
  /* Style */
321
321
  /*------------------------------------------------------------------------*/
322
- const style$a = `
322
+ const style$b = `
323
323
  .Modal-backdrop {
324
324
  position: fixed;
325
325
  top: 0;
@@ -493,7 +493,7 @@ const Modal = (props) => {
493
493
  left: 0,
494
494
  right: 0,
495
495
  } },
496
- React__default["default"].createElement("style", null, style$a),
496
+ React__default["default"].createElement("style", null, style$b),
497
497
  React__default["default"].createElement("div", { className: `Modal-backdrop ${backdropAnimationClass}`, style: {
498
498
  zIndex: 5000000003,
499
499
  }, onClick: () => __awaiter(void 0, void 0, void 0, function* () {
@@ -781,6 +781,39 @@ const logClientEvent = (opts) => __awaiter(void 0, void 0, void 0, function* ()
781
781
  /* --------------------------- Static Helpers --------------------------- */
782
782
  /*------------------------------------------------------------------------*/
783
783
  /*----------------------------------------*/
784
+ /* ----------- Redirect/Leave ----------- */
785
+ /*----------------------------------------*/
786
+ // Stored copy of setter for url to leave to
787
+ let setURLToLeaveTo;
788
+ /**
789
+ * Redirect to a new page
790
+ * @author Gabe Abrams
791
+ * @param url the url to redirect to
792
+ * @param destination the destination of the redirect, for example "YouTube"
793
+ * and will be used in the following text: `Redirecting to ${destination}...`
794
+ */
795
+ const leaveToURL = (url, destination) => __awaiter(void 0, void 0, void 0, function* () {
796
+ if (setURLToLeaveTo) {
797
+ // Beautiful redirect
798
+ setURLToLeaveTo({ url, destination });
799
+ }
800
+ else {
801
+ // Overwrite page in a janky way
802
+ window.document.body.innerHTML = `
803
+ <div>
804
+ <h1>
805
+ Redirecting to ${destination}...
806
+ </h1>
807
+ <p>
808
+ If you are not redirected in 5 seconds, please <a href="${url}">click here</a>.
809
+ </p>
810
+ </div>
811
+ `;
812
+ }
813
+ // Redirect to location
814
+ window.location.href = url;
815
+ });
816
+ /*----------------------------------------*/
784
817
  /* ---------------- Alert --------------- */
785
818
  /*----------------------------------------*/
786
819
  // Stored copies of setters
@@ -917,6 +950,30 @@ const addFatalErrorHandler = (handler) => {
917
950
  fatalErrorHandlers.push(handler);
918
951
  };
919
952
  /*------------------------------------------------------------------------*/
953
+ /* -------------------------------- Style ------------------------------- */
954
+ /*------------------------------------------------------------------------*/
955
+ const style$a = `
956
+ .AppWrapper-leave-to-url-notice {
957
+ opacity: 0;
958
+
959
+ animation-name: AppWrapper-leave-to-url-notice-appear;
960
+ animation-duration: 0.5s;
961
+ animation-delay: 1s;
962
+ animation-fill-mode: both;
963
+ animation-timing-function: ease-out;
964
+ animation-iteration-count: 1;
965
+ }
966
+
967
+ @keyframes AppWrapper-leave-to-url-notice-appear {
968
+ 0% {
969
+ opacity: 0;
970
+ }
971
+ 100% {
972
+ opacity: 1;
973
+ }
974
+ }
975
+ `;
976
+ /*------------------------------------------------------------------------*/
920
977
  /* ------------------------------ Component ----------------------------- */
921
978
  /*------------------------------------------------------------------------*/
922
979
  const AppWrapper = (props) => {
@@ -926,6 +983,9 @@ const AppWrapper = (props) => {
926
983
  /* -------------- Props ------------- */
927
984
  const { children, dark, } = props;
928
985
  /* -------------- State ------------- */
986
+ // Leave to URL
987
+ const [urlToLeaveTo, setURLToLeaveToInner,] = React.useState();
988
+ setURLToLeaveTo = setURLToLeaveToInner;
929
989
  // Fatal error
930
990
  const [fatalErrorMessage, setFatalErrorMessageInner,] = React.useState();
931
991
  setFatalErrorMessage = setFatalErrorMessageInner;
@@ -973,8 +1033,27 @@ const AppWrapper = (props) => {
973
1033
  /*----------------------------------------*/
974
1034
  // Body that will be filled with the current view
975
1035
  let body;
1036
+ /* ---------- Leave to URL ---------- */
1037
+ if (!body && urlToLeaveTo) {
1038
+ // Destructure url info
1039
+ const { url, destination, } = urlToLeaveTo;
1040
+ // Show pretty redirect screen
1041
+ body = (React__default["default"].createElement("div", { className: "AppWrapper-leave-to-url-container p-5 text-center" },
1042
+ React__default["default"].createElement("div", { className: "AppWrapper-leave-to-url-notice d-inline-block" },
1043
+ React__default["default"].createElement("h3", { className: "text-start m-0" },
1044
+ "Redirecting to",
1045
+ ' ',
1046
+ destination,
1047
+ "..."),
1048
+ React__default["default"].createElement("div", { className: "text-start" },
1049
+ "If you are not automatically redirected in 5 seconds, please",
1050
+ ' ',
1051
+ React__default["default"].createElement("a", { href: url, "aria-label": `Click here to leave to ${destination}` }, "click here"),
1052
+ "."))));
1053
+ }
976
1054
  /* ----------- Fatal Error ---------- */
977
- if (fatalErrorMessage || fatalErrorCode || sessionHasExpired) {
1055
+ if (!body
1056
+ && (fatalErrorMessage || fatalErrorCode || sessionHasExpired)) {
978
1057
  // Re-encapsulate in an error
979
1058
  const error = (sessionHasExpired
980
1059
  ? new ErrorWithCode(getSessionExpiredMessage(), ReactKitErrorCode$1.SessionExpired)
@@ -1001,6 +1080,7 @@ const AppWrapper = (props) => {
1001
1080
  /* Main UI */
1002
1081
  /*----------------------------------------*/
1003
1082
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
1083
+ React__default["default"].createElement("style", null, style$a),
1004
1084
  modal,
1005
1085
  body));
1006
1086
  };
@@ -42935,6 +43015,7 @@ exports.initClient = initClient;
42935
43015
  exports.initLogCollection = initLogCollection;
42936
43016
  exports.initServer = initServer;
42937
43017
  exports.isMobileOrTablet = isMobileOrTablet;
43018
+ exports.leaveToURL = leaveToURL;
42938
43019
  exports.logClientEvent = logClientEvent;
42939
43020
  exports.onlyKeepLetters = onlyKeepLetters;
42940
43021
  exports.padDecimalZeros = padDecimalZeros;