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.
@@ -9,6 +9,14 @@ type Props = {
9
9
  children: React.ReactNode;
10
10
  dark?: boolean;
11
11
  };
12
+ /**
13
+ * Redirect to a new page
14
+ * @author Gabe Abrams
15
+ * @param url the url to redirect to
16
+ * @param destination the destination of the redirect, for example "YouTube"
17
+ * and will be used in the following text: `Redirecting to ${destination}...`
18
+ */
19
+ export declare const leaveToURL: (url: string, destination: string) => Promise<void>;
12
20
  /**
13
21
  * Show an alert modal with an "Okay" button
14
22
  * @author Gabe Abrams
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Get the current part of day (morning, evening, etc.)
3
3
  * @author Gabe Abrams
4
+ * @returns the part of day (morning, evening, etc.)
4
5
  */
5
6
  declare const getPartOfDay: () => string;
6
7
  export default getPartOfDay;
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ /**
3
+ * Given some text, make the links clickable
4
+ * @author Gabe Abrams
5
+ * @param text the text to process
6
+ * @param [opts] options to customize behavior
7
+ * @param [opts.newTab] if true, links will open in a new tab
8
+ * @param [opts.preventPropagation] if true, clicks to link will prevent default
9
+ * and propagation
10
+ * @returns the processed text
11
+ */
12
+ declare const makeLinksClickable: (text: string, opts?: {
13
+ newTab?: boolean;
14
+ preventPropagation?: boolean;
15
+ }) => React.ReactNode;
16
+ export default makeLinksClickable;
@@ -1,4 +1,4 @@
1
- import AppWrapper, { alert, confirm, showFatalError, addFatalErrorHandler } from './components/AppWrapper';
1
+ import AppWrapper, { alert, confirm, showFatalError, addFatalErrorHandler, leaveToURL } from './components/AppWrapper';
2
2
  import LoadingSpinner from './components/LoadingSpinner';
3
3
  import ErrorBox from './components/ErrorBox';
4
4
  import Modal from './components/Modal';
@@ -65,6 +65,7 @@ import validateEmail from './helpers/validators/validateEmail';
65
65
  import validatePhoneNumber from './helpers/validators/validatePhoneNumber';
66
66
  import validateString from './helpers/validators/validateString';
67
67
  import idify from './helpers/idify';
68
+ import makeLinksClickable from './helpers/makeLinksClickable';
68
69
  import ModalButtonType from './types/ModalButtonType';
69
70
  import ModalSize from './types/ModalSize';
70
71
  import ModalType from './types/ModalType';
@@ -83,4 +84,4 @@ import PickableItem from './components/ItemPicker/types/PickableItem';
83
84
  import DBEntry from './components/DBEntryManagerPanel/types/DBEntry';
84
85
  import DBEntryField from './components/DBEntryManagerPanel/types/DBEntryField';
85
86
  import DBEntryFieldType from './components/DBEntryManagerPanel/types/DBEntryFieldType';
86
- export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, DBEntryManagerPanel, Tooltip, ToggleSwitch, AutoscrollToBottomContainer, alert, confirm, showFatalError, ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, DynamicWord, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, stubServerEndpoint, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, canReviewLogs, isMobileOrTablet, extractProp, compareArraysByProp, genCommaList, validateEmail, validatePhoneNumber, validateString, getLocalTimeInfo, idify, initClient, visitServerEndpoint, logClientEvent, addFatalErrorHandler, initServer, genRouteHandler, handleError, handleSuccess, initLogCollection, addDBEditorEndpoints, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, IntelliTableColumn, PickableItem, DBEntry, DBEntryField, DBEntryFieldType, ParamType, };
87
+ export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, DBEntryManagerPanel, Tooltip, ToggleSwitch, AutoscrollToBottomContainer, alert, confirm, showFatalError, ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, DynamicWord, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, stubServerEndpoint, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, canReviewLogs, isMobileOrTablet, extractProp, compareArraysByProp, genCommaList, validateEmail, validatePhoneNumber, validateString, getLocalTimeInfo, idify, makeLinksClickable, initClient, visitServerEndpoint, logClientEvent, addFatalErrorHandler, leaveToURL, initServer, genRouteHandler, handleError, handleSuccess, initLogCollection, addDBEditorEndpoints, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, IntelliTableColumn, PickableItem, DBEntry, DBEntryField, DBEntryFieldType, ParamType, };
package/dist/esm/index.js CHANGED
@@ -293,7 +293,7 @@ const ModalButtonTypeToLabelAndVariant = {
293
293
  /*------------------------------------------------------------------------*/
294
294
  /* Style */
295
295
  /*------------------------------------------------------------------------*/
296
- const style$a = `
296
+ const style$b = `
297
297
  .Modal-backdrop {
298
298
  position: fixed;
299
299
  top: 0;
@@ -467,7 +467,7 @@ const Modal = (props) => {
467
467
  left: 0,
468
468
  right: 0,
469
469
  } },
470
- React__default.createElement("style", null, style$a),
470
+ React__default.createElement("style", null, style$b),
471
471
  React__default.createElement("div", { className: `Modal-backdrop ${backdropAnimationClass}`, style: {
472
472
  zIndex: 5000000003,
473
473
  }, onClick: () => __awaiter(void 0, void 0, void 0, function* () {
@@ -755,6 +755,39 @@ const logClientEvent = (opts) => __awaiter(void 0, void 0, void 0, function* ()
755
755
  /* --------------------------- Static Helpers --------------------------- */
756
756
  /*------------------------------------------------------------------------*/
757
757
  /*----------------------------------------*/
758
+ /* ----------- Redirect/Leave ----------- */
759
+ /*----------------------------------------*/
760
+ // Stored copy of setter for url to leave to
761
+ let setURLToLeaveTo;
762
+ /**
763
+ * Redirect to a new page
764
+ * @author Gabe Abrams
765
+ * @param url the url to redirect to
766
+ * @param destination the destination of the redirect, for example "YouTube"
767
+ * and will be used in the following text: `Redirecting to ${destination}...`
768
+ */
769
+ const leaveToURL = (url, destination) => __awaiter(void 0, void 0, void 0, function* () {
770
+ if (setURLToLeaveTo) {
771
+ // Beautiful redirect
772
+ setURLToLeaveTo({ url, destination });
773
+ }
774
+ else {
775
+ // Overwrite page in a janky way
776
+ window.document.body.innerHTML = `
777
+ <div>
778
+ <h1>
779
+ Redirecting to ${destination}...
780
+ </h1>
781
+ <p>
782
+ If you are not redirected in 5 seconds, please <a href="${url}">click here</a>.
783
+ </p>
784
+ </div>
785
+ `;
786
+ }
787
+ // Redirect to location
788
+ window.location.href = url;
789
+ });
790
+ /*----------------------------------------*/
758
791
  /* ---------------- Alert --------------- */
759
792
  /*----------------------------------------*/
760
793
  // Stored copies of setters
@@ -891,6 +924,30 @@ const addFatalErrorHandler = (handler) => {
891
924
  fatalErrorHandlers.push(handler);
892
925
  };
893
926
  /*------------------------------------------------------------------------*/
927
+ /* -------------------------------- Style ------------------------------- */
928
+ /*------------------------------------------------------------------------*/
929
+ const style$a = `
930
+ .AppWrapper-leave-to-url-notice {
931
+ opacity: 0;
932
+
933
+ animation-name: AppWrapper-leave-to-url-notice-appear;
934
+ animation-duration: 0.5s;
935
+ animation-delay: 1s;
936
+ animation-fill-mode: both;
937
+ animation-timing-function: ease-out;
938
+ animation-iteration-count: 1;
939
+ }
940
+
941
+ @keyframes AppWrapper-leave-to-url-notice-appear {
942
+ 0% {
943
+ opacity: 0;
944
+ }
945
+ 100% {
946
+ opacity: 1;
947
+ }
948
+ }
949
+ `;
950
+ /*------------------------------------------------------------------------*/
894
951
  /* ------------------------------ Component ----------------------------- */
895
952
  /*------------------------------------------------------------------------*/
896
953
  const AppWrapper = (props) => {
@@ -900,6 +957,9 @@ const AppWrapper = (props) => {
900
957
  /* -------------- Props ------------- */
901
958
  const { children, dark, } = props;
902
959
  /* -------------- State ------------- */
960
+ // Leave to URL
961
+ const [urlToLeaveTo, setURLToLeaveToInner,] = useState();
962
+ setURLToLeaveTo = setURLToLeaveToInner;
903
963
  // Fatal error
904
964
  const [fatalErrorMessage, setFatalErrorMessageInner,] = useState();
905
965
  setFatalErrorMessage = setFatalErrorMessageInner;
@@ -947,8 +1007,27 @@ const AppWrapper = (props) => {
947
1007
  /*----------------------------------------*/
948
1008
  // Body that will be filled with the current view
949
1009
  let body;
1010
+ /* ---------- Leave to URL ---------- */
1011
+ if (!body && urlToLeaveTo) {
1012
+ // Destructure url info
1013
+ const { url, destination, } = urlToLeaveTo;
1014
+ // Show pretty redirect screen
1015
+ body = (React__default.createElement("div", { className: "AppWrapper-leave-to-url-container p-5 text-center" },
1016
+ React__default.createElement("div", { className: "AppWrapper-leave-to-url-notice d-inline-block" },
1017
+ React__default.createElement("h3", { className: "text-start m-0" },
1018
+ "Redirecting to",
1019
+ ' ',
1020
+ destination,
1021
+ "..."),
1022
+ React__default.createElement("div", { className: "text-start" },
1023
+ "If you are not automatically redirected in 5 seconds, please",
1024
+ ' ',
1025
+ React__default.createElement("a", { href: url, "aria-label": `Click here to leave to ${destination}` }, "click here"),
1026
+ "."))));
1027
+ }
950
1028
  /* ----------- Fatal Error ---------- */
951
- if (fatalErrorMessage || fatalErrorCode || sessionHasExpired) {
1029
+ if (!body
1030
+ && (fatalErrorMessage || fatalErrorCode || sessionHasExpired)) {
952
1031
  // Re-encapsulate in an error
953
1032
  const error = (sessionHasExpired
954
1033
  ? new ErrorWithCode(getSessionExpiredMessage(), ReactKitErrorCode$1.SessionExpired)
@@ -975,6 +1054,7 @@ const AppWrapper = (props) => {
975
1054
  /* Main UI */
976
1055
  /*----------------------------------------*/
977
1056
  return (React__default.createElement(React__default.Fragment, null,
1057
+ React__default.createElement("style", null, style$a),
978
1058
  modal,
979
1059
  body));
980
1060
  };
@@ -42258,11 +42338,12 @@ const startMinWait = (minWaitMs) => {
42258
42338
  /**
42259
42339
  * Get the current part of day (morning, evening, etc.)
42260
42340
  * @author Gabe Abrams
42341
+ * @returns the part of day (morning, evening, etc.)
42261
42342
  */
42262
42343
  const getPartOfDay = () => {
42263
42344
  // Setup the post-it time of day
42264
42345
  let partOfDay = 'day';
42265
- let hours = new Date().getHours();
42346
+ const hours = new Date().getHours();
42266
42347
  if (hours < 12) {
42267
42348
  partOfDay = 'morning';
42268
42349
  }
@@ -42826,6 +42907,64 @@ const validateString = (input, opts) => {
42826
42907
  });
42827
42908
  };
42828
42909
 
42910
+ // Import React
42911
+ // Regular express that matches urls
42912
+ const urlRegex = /(https?:\/\/)?([a-z0-9-]+\.)+[a-z0-9]{2,6}(:[0-9]{1,5})?(\/\S*)?/g;
42913
+ /**
42914
+ * Given some text, make the links clickable
42915
+ * @author Gabe Abrams
42916
+ * @param text the text to process
42917
+ * @param [opts] options to customize behavior
42918
+ * @param [opts.newTab] if true, links will open in a new tab
42919
+ * @param [opts.preventPropagation] if true, clicks to link will prevent default
42920
+ * and propagation
42921
+ * @returns the processed text
42922
+ */
42923
+ const makeLinksClickable = (text, opts) => {
42924
+ // Search text for links
42925
+ let matches = urlRegex.exec(text);
42926
+ // If no matches, just return the text
42927
+ if (!matches) {
42928
+ return text;
42929
+ }
42930
+ // Check if using new tab
42931
+ const newTab = opts === null || opts === void 0 ? void 0 : opts.newTab;
42932
+ // Next element key
42933
+ let nextKey = 0;
42934
+ // Process each link
42935
+ const elements = [];
42936
+ let lastIndex = 0;
42937
+ while (matches) {
42938
+ // Get the link
42939
+ const link = matches[0];
42940
+ // Get the index of the link
42941
+ const { index } = matches;
42942
+ // Add the text before the link
42943
+ elements.push(React__default.createElement("span", { key: nextKey += 1 }, text.substring(lastIndex, index)));
42944
+ // Add the link
42945
+ elements.push(React__default.createElement("a", { key: nextKey += 1, href: link, target: newTab ? '_blank' : undefined, rel: newTab ? 'noopener noreferrer' : undefined, style: {
42946
+ textDecoration: 'underline',
42947
+ }, onClick: (e) => {
42948
+ // Prevent default and propagation if requested
42949
+ if (opts === null || opts === void 0 ? void 0 : opts.preventPropagation) {
42950
+ e.preventDefault();
42951
+ e.stopPropagation();
42952
+ }
42953
+ } }, link));
42954
+ // Update the last index
42955
+ lastIndex = index + link.length;
42956
+ // Get the next match
42957
+ matches = urlRegex.exec(text);
42958
+ }
42959
+ // Add the last bit of text
42960
+ const remainingText = text.substring(lastIndex);
42961
+ if (remainingText && remainingText.length > 0) {
42962
+ elements.push(React__default.createElement("span", { key: nextKey += 1 }, remainingText));
42963
+ }
42964
+ // Return the elements
42965
+ return elements;
42966
+ };
42967
+
42829
42968
  /**
42830
42969
  * Days of the week
42831
42970
  * @author Gabe Abrams
@@ -42842,5 +42981,5 @@ var DayOfWeek;
42842
42981
  })(DayOfWeek || (DayOfWeek = {}));
42843
42982
  var DayOfWeek$1 = DayOfWeek;
42844
42983
 
42845
- export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntryFieldType$1 as DBEntryFieldType, DBEntryManagerPanel, DayOfWeek$1 as DayOfWeek, Drawer, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, ItemPicker, LoadingSpinner, LogAction$1 as LogAction, LogBuiltInMetadata, LogReviewer, LogSource$1 as LogSource, LogType$1 as LogType, MINUTE_IN_MS, Modal, ModalButtonType$1 as ModalButtonType, ModalSize$1 as ModalSize, ModalType$1 as ModalType, ParamType$1 as ParamType, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode$1 as ReactKitErrorCode, SimpleDateChooser, TabBox, ToggleSwitch, Tooltip, Variant$1 as Variant, abbreviate, addDBEditorEndpoints, addFatalErrorHandler, alert$1 as alert, avg, canReviewLogs, ceilToNumDecimals, compareArraysByProp, confirm, extractProp, floorToNumDecimals, forceNumIntoBounds, genCSV, genCommaList, genRouteHandler, getHumanReadableDate, getLocalTimeInfo, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, idify, initClient, initLogCollection, initServer, isMobileOrTablet, logClientEvent, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, roundToNumDecimals, showFatalError, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, validateEmail, validatePhoneNumber, validateString, visitServerEndpoint, waitMs };
42984
+ export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntryFieldType$1 as DBEntryFieldType, DBEntryManagerPanel, DayOfWeek$1 as DayOfWeek, Drawer, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, ItemPicker, LoadingSpinner, LogAction$1 as LogAction, LogBuiltInMetadata, LogReviewer, LogSource$1 as LogSource, LogType$1 as LogType, MINUTE_IN_MS, Modal, ModalButtonType$1 as ModalButtonType, ModalSize$1 as ModalSize, ModalType$1 as ModalType, ParamType$1 as ParamType, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode$1 as ReactKitErrorCode, SimpleDateChooser, TabBox, ToggleSwitch, Tooltip, Variant$1 as Variant, abbreviate, addDBEditorEndpoints, addFatalErrorHandler, alert$1 as alert, avg, canReviewLogs, ceilToNumDecimals, compareArraysByProp, confirm, extractProp, floorToNumDecimals, forceNumIntoBounds, genCSV, genCommaList, genRouteHandler, getHumanReadableDate, getLocalTimeInfo, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, idify, initClient, initLogCollection, initServer, isMobileOrTablet, leaveToURL, logClientEvent, makeLinksClickable, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, roundToNumDecimals, showFatalError, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, validateEmail, validatePhoneNumber, validateString, visitServerEndpoint, waitMs };
42846
42985
  //# sourceMappingURL=index.js.map