dce-reactkit 3.5.10 → 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
  };
@@ -40851,7 +40931,7 @@ const AutoscrollToBottomContainer = (props) => {
40851
40931
  // Initialize refs
40852
40932
  const lastItemIds = React.useRef([]);
40853
40933
  const container = React.useRef(null);
40854
- const wasScrolledToBottomBeforeItemsUpdate = React.useRef(true);
40934
+ const wasLastScrolledToBottom = React.useRef(true);
40855
40935
  /*------------------------------------------------------------------------*/
40856
40936
  /* ------------------------- Component Functions ------------------------ */
40857
40937
  /*------------------------------------------------------------------------*/
@@ -40874,7 +40954,10 @@ const AutoscrollToBottomContainer = (props) => {
40874
40954
  const rootFontSizePx = Number.parseInt(getComputedStyle(document.documentElement).fontSize, 10);
40875
40955
  const distanceToBottomRems = Math.abs((scrollTop + clientHeight - scrollHeight) / rootFontSizePx);
40876
40956
  // Figure out if we're scrolled to the bottom
40877
- return (distanceToBottomRems < SCROLLED_TO_BOTTOM_THRESHOLD_REMS);
40957
+ const atBottom = (distanceToBottomRems < SCROLLED_TO_BOTTOM_THRESHOLD_REMS);
40958
+ // Remember if we scrolled to the bottom
40959
+ wasLastScrolledToBottom.current = atBottom;
40960
+ return atBottom;
40878
40961
  };
40879
40962
  /**
40880
40963
  * Scroll the user to the bottom of the container
@@ -40890,7 +40973,10 @@ const AutoscrollToBottomContainer = (props) => {
40890
40973
  type: ActionType.HideJumpToBottomButton,
40891
40974
  });
40892
40975
  // Scroll to bottom
40893
- container.current.scrollTop = container.current.scrollHeight;
40976
+ container.current.scrollTop = (container.current.scrollHeight
40977
+ - container.current.clientHeight);
40978
+ // Remember that we scrolled to the bottom
40979
+ wasLastScrolledToBottom.current = true;
40894
40980
  };
40895
40981
  /*----------------------------------------*/
40896
40982
  /* -------------- Handlers -------------- */
@@ -40904,8 +40990,9 @@ const AutoscrollToBottomContainer = (props) => {
40904
40990
  if (!container.current) {
40905
40991
  return;
40906
40992
  }
40907
- // If scrolled to bottom, hide the button
40993
+ // If scrolled to bottom, hide the button and remember position
40908
40994
  if (isScrolledToBottom()) {
40995
+ // Hide button
40909
40996
  dispatch({
40910
40997
  type: ActionType.HideJumpToBottomButton,
40911
40998
  });
@@ -40930,17 +41017,19 @@ const AutoscrollToBottomContainer = (props) => {
40930
41017
  // Check if new content appeared
40931
41018
  const currentItemIds = getItemIds(items);
40932
41019
  // Check if new content appeared at bottom
40933
- const newContentAppeared = (currentItemIds.length > 0
40934
- && lastItemIds.current
40935
- && lastItemIds.current.length > 0
40936
- && (currentItemIds[currentItemIds.length - 1]
40937
- !== lastItemIds.current[lastItemIds.current.length - 1]));
41020
+ const newContentAppeared = (
41021
+ // There are items
41022
+ currentItemIds.length > 0
41023
+ // The last item is new
41024
+ && !lastItemIds.current.includes(currentItemIds[currentItemIds.length - 1]));
41025
+ // Update last item ids
41026
+ lastItemIds.current = currentItemIds;
40938
41027
  // Do nothing if no new content
40939
41028
  if (!newContentAppeared) {
40940
41029
  return;
40941
41030
  }
40942
41031
  // Check if used to be scrolled to the bottom
40943
- if (wasScrolledToBottomBeforeItemsUpdate.current) {
41032
+ if (wasLastScrolledToBottom.current) {
40944
41033
  // Was scrolled to the bottom! Autoscroll.
40945
41034
  scrollToBottom();
40946
41035
  }
@@ -40950,12 +41039,6 @@ const AutoscrollToBottomContainer = (props) => {
40950
41039
  type: ActionType.ShowJumpToBottomButton,
40951
41040
  });
40952
41041
  }
40953
- // Update last item ids
40954
- lastItemIds.current = currentItemIds;
40955
- // Remember if we were scrolled to the bottom before the update
40956
- return () => {
40957
- wasScrolledToBottomBeforeItemsUpdate.current = isScrolledToBottom();
40958
- };
40959
41042
  }, [items]);
40960
41043
  /*------------------------------------------------------------------------*/
40961
41044
  /* ------------------------------- Render ------------------------------- */
@@ -42932,6 +43015,7 @@ exports.initClient = initClient;
42932
43015
  exports.initLogCollection = initLogCollection;
42933
43016
  exports.initServer = initServer;
42934
43017
  exports.isMobileOrTablet = isMobileOrTablet;
43018
+ exports.leaveToURL = leaveToURL;
42935
43019
  exports.logClientEvent = logClientEvent;
42936
43020
  exports.onlyKeepLetters = onlyKeepLetters;
42937
43021
  exports.padDecimalZeros = padDecimalZeros;