dce-reactkit 3.5.11 → 3.5.13

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
  };
@@ -42284,11 +42364,12 @@ const startMinWait = (minWaitMs) => {
42284
42364
  /**
42285
42365
  * Get the current part of day (morning, evening, etc.)
42286
42366
  * @author Gabe Abrams
42367
+ * @returns the part of day (morning, evening, etc.)
42287
42368
  */
42288
42369
  const getPartOfDay = () => {
42289
42370
  // Setup the post-it time of day
42290
42371
  let partOfDay = 'day';
42291
- let hours = new Date().getHours();
42372
+ const hours = new Date().getHours();
42292
42373
  if (hours < 12) {
42293
42374
  partOfDay = 'morning';
42294
42375
  }
@@ -42852,6 +42933,64 @@ const validateString = (input, opts) => {
42852
42933
  });
42853
42934
  };
42854
42935
 
42936
+ // Import React
42937
+ // Regular express that matches urls
42938
+ const urlRegex = /(https?:\/\/)?([a-z0-9-]+\.)+[a-z0-9]{2,6}(:[0-9]{1,5})?(\/\S*)?/g;
42939
+ /**
42940
+ * Given some text, make the links clickable
42941
+ * @author Gabe Abrams
42942
+ * @param text the text to process
42943
+ * @param [opts] options to customize behavior
42944
+ * @param [opts.newTab] if true, links will open in a new tab
42945
+ * @param [opts.preventPropagation] if true, clicks to link will prevent default
42946
+ * and propagation
42947
+ * @returns the processed text
42948
+ */
42949
+ const makeLinksClickable = (text, opts) => {
42950
+ // Search text for links
42951
+ let matches = urlRegex.exec(text);
42952
+ // If no matches, just return the text
42953
+ if (!matches) {
42954
+ return text;
42955
+ }
42956
+ // Check if using new tab
42957
+ const newTab = opts === null || opts === void 0 ? void 0 : opts.newTab;
42958
+ // Next element key
42959
+ let nextKey = 0;
42960
+ // Process each link
42961
+ const elements = [];
42962
+ let lastIndex = 0;
42963
+ while (matches) {
42964
+ // Get the link
42965
+ const link = matches[0];
42966
+ // Get the index of the link
42967
+ const { index } = matches;
42968
+ // Add the text before the link
42969
+ elements.push(React__default["default"].createElement("span", { key: nextKey += 1 }, text.substring(lastIndex, index)));
42970
+ // Add the link
42971
+ elements.push(React__default["default"].createElement("a", { key: nextKey += 1, href: link, target: newTab ? '_blank' : undefined, rel: newTab ? 'noopener noreferrer' : undefined, style: {
42972
+ textDecoration: 'underline',
42973
+ }, onClick: (e) => {
42974
+ // Prevent default and propagation if requested
42975
+ if (opts === null || opts === void 0 ? void 0 : opts.preventPropagation) {
42976
+ e.preventDefault();
42977
+ e.stopPropagation();
42978
+ }
42979
+ } }, link));
42980
+ // Update the last index
42981
+ lastIndex = index + link.length;
42982
+ // Get the next match
42983
+ matches = urlRegex.exec(text);
42984
+ }
42985
+ // Add the last bit of text
42986
+ const remainingText = text.substring(lastIndex);
42987
+ if (remainingText && remainingText.length > 0) {
42988
+ elements.push(React__default["default"].createElement("span", { key: nextKey += 1 }, remainingText));
42989
+ }
42990
+ // Return the elements
42991
+ return elements;
42992
+ };
42993
+
42855
42994
  /**
42856
42995
  * Days of the week
42857
42996
  * @author Gabe Abrams
@@ -42935,7 +43074,9 @@ exports.initClient = initClient;
42935
43074
  exports.initLogCollection = initLogCollection;
42936
43075
  exports.initServer = initServer;
42937
43076
  exports.isMobileOrTablet = isMobileOrTablet;
43077
+ exports.leaveToURL = leaveToURL;
42938
43078
  exports.logClientEvent = logClientEvent;
43079
+ exports.makeLinksClickable = makeLinksClickable;
42939
43080
  exports.onlyKeepLetters = onlyKeepLetters;
42940
43081
  exports.padDecimalZeros = padDecimalZeros;
42941
43082
  exports.padZerosLeft = padZerosLeft;