dce-reactkit 3.5.4 → 3.5.5

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.
@@ -44,6 +44,11 @@ export declare const confirm: (title: string, text: string, opts?: {
44
44
  * @param [errorTitle] title of the error box
45
45
  */
46
46
  export declare const showFatalError: (error: any, errorTitle?: string) => undefined;
47
+ /**
48
+ * Add a handler for when a fatal error occurs
49
+ * @author Gabe Abrams
50
+ */
51
+ export declare const addFatalErrorHandler: (handler: () => void) => void;
47
52
  /**
48
53
  * Show the "session expired" message
49
54
  * @author Gabe Abrams
@@ -0,0 +1,20 @@
1
+ /**
2
+ * A toggle switch that toggles on or off
3
+ * @author Alessandra De Lucas
4
+ * @author Gabe Abrams
5
+ */
6
+ import React from 'react';
7
+ import Variant from '../types/Variant';
8
+ type Props = {
9
+ isOn: boolean;
10
+ /**
11
+ * A handler to call when the switch is toggled
12
+ * @param isOn Updated value for isOn
13
+ */
14
+ onToggle: (isOn: boolean) => void;
15
+ id?: string;
16
+ description: string;
17
+ backgroundVariantWhenOn?: Variant;
18
+ };
19
+ declare const ToggleSwitch: React.FC<Props>;
20
+ export default ToggleSwitch;
@@ -1,4 +1,4 @@
1
- import AppWrapper, { alert, confirm, showFatalError } from './components/AppWrapper';
1
+ import AppWrapper, { alert, confirm, showFatalError, addFatalErrorHandler } from './components/AppWrapper';
2
2
  import LoadingSpinner from './components/LoadingSpinner';
3
3
  import ErrorBox from './components/ErrorBox';
4
4
  import Modal from './components/Modal';
@@ -18,6 +18,7 @@ import IntelliTable from './components/IntelliTable';
18
18
  import CSVDownloadButton from './components/CSVDownloadButton';
19
19
  import DBEntryManagerPanel from './components/DBEntryManagerPanel';
20
20
  import Tooltip from './components/Tooltip';
21
+ import ToggleSwitch from './components/ToggleSwitch';
21
22
  import ErrorWithCode from './errors/ErrorWithCode';
22
23
  import MINUTE_IN_MS from './constants/MINUTE_IN_MS';
23
24
  import HOUR_IN_MS from './constants/HOUR_IN_MS';
@@ -80,4 +81,4 @@ import PickableItem from './components/ItemPicker/types/PickableItem';
80
81
  import DBEntry from './components/DBEntryManagerPanel/types/DBEntry';
81
82
  import DBEntryField from './components/DBEntryManagerPanel/types/DBEntryField';
82
83
  import DBEntryFieldType from './components/DBEntryManagerPanel/types/DBEntryFieldType';
83
- export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, DBEntryManagerPanel, Tooltip, 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, initClient, visitServerEndpoint, logClientEvent, initServer, genRouteHandler, handleError, handleSuccess, initLogCollection, addDBEditorEndpoints, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, IntelliTableColumn, PickableItem, DBEntry, DBEntryField, DBEntryFieldType, ParamType, };
84
+ export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, DBEntryManagerPanel, Tooltip, ToggleSwitch, 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, 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, };
package/dist/esm/index.js CHANGED
@@ -752,10 +752,10 @@ const logClientEvent = (opts) => __awaiter(void 0, void 0, void 0, function* ()
752
752
  * @author Gabe Abrams
753
753
  */
754
754
  /*------------------------------------------------------------------------*/
755
- /* Static Helpers */
755
+ /* --------------------------- Static Helpers --------------------------- */
756
756
  /*------------------------------------------------------------------------*/
757
757
  /*----------------------------------------*/
758
- /* Alert */
758
+ /* ---------------- Alert --------------- */
759
759
  /*----------------------------------------*/
760
760
  // Stored copies of setters
761
761
  let setAlertInfo;
@@ -769,6 +769,7 @@ let onAlertClosed;
769
769
  const alert$1 = (title, text) => __awaiter(void 0, void 0, void 0, function* () {
770
770
  // Fallback if alert not available
771
771
  if (!setAlertInfo) {
772
+ // eslint-disable-next-line no-alert
772
773
  window.alert(`${title}\n\n${text}`);
773
774
  return undefined;
774
775
  }
@@ -786,7 +787,7 @@ const alert$1 = (title, text) => __awaiter(void 0, void 0, void 0, function* ()
786
787
  });
787
788
  });
788
789
  /*----------------------------------------*/
789
- /* Confirm */
790
+ /* --------------- Confirm -------------- */
790
791
  /*----------------------------------------*/
791
792
  // Stored copies of setters
792
793
  let setConfirmInfo;
@@ -809,6 +810,7 @@ let onConfirmClosed;
809
810
  const confirm = (title, text, opts) => __awaiter(void 0, void 0, void 0, function* () {
810
811
  // Fallback if confirm is not available
811
812
  if (!setConfirmInfo) {
813
+ // eslint-disable-next-line no-alert
812
814
  return window.confirm(`${title}\n\n${text}`);
813
815
  }
814
816
  // Return promise that resolves with result of confirmation
@@ -826,12 +828,14 @@ const confirm = (title, text, opts) => __awaiter(void 0, void 0, void 0, functio
826
828
  });
827
829
  });
828
830
  /*----------------------------------------*/
829
- /* Fatal Error */
831
+ /* ------------- Fatal Error ------------ */
830
832
  /*----------------------------------------*/
831
833
  // Stored copies of setters
832
834
  let setFatalErrorMessage;
833
835
  let setFatalErrorCode;
834
836
  let setFatalErrorTitle;
837
+ // Fatal error listeners
838
+ const fatalErrorHandlers = [];
835
839
  /**
836
840
  * Show a fatal error message
837
841
  * @author Gabe Abrams
@@ -847,6 +851,15 @@ const showFatalError = (error, errorTitle = 'An Error Occurred') => {
847
851
  const code = (typeof error === 'string'
848
852
  ? ReactKitErrorCode$1.NoCode
849
853
  : String((_b = error.code) !== null && _b !== void 0 ? _b : ReactKitErrorCode$1.NoCode));
854
+ // Call all fatal error listeners
855
+ try {
856
+ fatalErrorHandlers.forEach((handler) => {
857
+ handler();
858
+ });
859
+ }
860
+ catch (err) {
861
+ // Ignore listener errors
862
+ }
850
863
  // Add log
851
864
  logClientEvent({
852
865
  context: LogBuiltInMetadata.Context.ClientFatalError,
@@ -870,12 +883,19 @@ const showFatalError = (error, errorTitle = 'An Error Occurred') => {
870
883
  setFatalErrorTitle(errorTitle);
871
884
  return undefined;
872
885
  };
886
+ /**
887
+ * Add a handler for when a fatal error occurs
888
+ * @author Gabe Abrams
889
+ */
890
+ const addFatalErrorHandler = (handler) => {
891
+ fatalErrorHandlers.push(handler);
892
+ };
873
893
  /*------------------------------------------------------------------------*/
874
- /* Component */
894
+ /* ------------------------------ Component ----------------------------- */
875
895
  /*------------------------------------------------------------------------*/
876
896
  const AppWrapper = (props) => {
877
897
  /*------------------------------------------------------------------------*/
878
- /* Setup */
898
+ /* -------------------------------- Setup ------------------------------- */
879
899
  /*------------------------------------------------------------------------*/
880
900
  /* -------------- Props ------------- */
881
901
  const { children, dark, } = props;
@@ -896,10 +916,10 @@ const AppWrapper = (props) => {
896
916
  // Session expired
897
917
  const [sessionHasExpired, setSessionHasExpiredInner,] = useState(false);
898
918
  /*------------------------------------------------------------------------*/
899
- /* Render */
919
+ /* ------------------------------- Render ------------------------------- */
900
920
  /*------------------------------------------------------------------------*/
901
921
  /*----------------------------------------*/
902
- /* Modal */
922
+ /* ---------------- Modal --------------- */
903
923
  /*----------------------------------------*/
904
924
  // Modal that may be defined
905
925
  let modal;
@@ -923,7 +943,7 @@ const AppWrapper = (props) => {
923
943
  }, dontAllowBackdropExit: true }, confirmInfo.text));
924
944
  }
925
945
  /*----------------------------------------*/
926
- /* Views */
946
+ /* ---------------- Views --------------- */
927
947
  /*----------------------------------------*/
928
948
  // Body that will be filled with the current view
929
949
  let body;
@@ -949,7 +969,7 @@ const AppWrapper = (props) => {
949
969
  }
950
970
  /* --------------- App -------------- */
951
971
  if (!body) {
952
- body = (React__default.createElement(React__default.Fragment, null, children));
972
+ body = children;
953
973
  }
954
974
  /*----------------------------------------*/
955
975
  /* Main UI */
@@ -40630,6 +40650,39 @@ const Tooltip = (props) => {
40630
40650
  React__default.createElement("span", { className: "Tooltip-text" }, text))))));
40631
40651
  };
40632
40652
 
40653
+ /**
40654
+ * A toggle switch that toggles on or off
40655
+ * @author Alessandra De Lucas
40656
+ * @author Gabe Abrams
40657
+ */
40658
+ /*------------------------------------------------------------------------*/
40659
+ /* ------------------------------ Component ----------------------------- */
40660
+ /*------------------------------------------------------------------------*/
40661
+ const ToggleSwitch = (props) => {
40662
+ /*------------------------------------------------------------------------*/
40663
+ /* -------------------------------- Setup ------------------------------- */
40664
+ /*------------------------------------------------------------------------*/
40665
+ /* -------------- Props ------------- */
40666
+ // Destructure all props
40667
+ const { isOn, onToggle, id, description, backgroundVariantWhenOn = Variant$1.Info, } = props;
40668
+ /*------------------------------------------------------------------------*/
40669
+ /* ------------------------------- Render ------------------------------- */
40670
+ /*------------------------------------------------------------------------*/
40671
+ /*----------------------------------------*/
40672
+ /* --------------- Main UI -------------- */
40673
+ /*----------------------------------------*/
40674
+ const backgroundVariant = (isOn
40675
+ ? backgroundVariantWhenOn
40676
+ : 'secondary');
40677
+ return (React__default.createElement("button", { id: id, "aria-label": `If on, ${description}. Currently ${isOn ? 'on' : 'off'}. Click to turn ${isOn ? 'off' : 'on'}.`, className: `alert alert-${backgroundVariant} bg-${backgroundVariant} mb-0 rounded-pill d-inline-block pt-0 pb-0 px-3`, onClick: () => {
40678
+ onToggle(!isOn);
40679
+ }, type: "button" },
40680
+ React__default.createElement(FontAwesomeIcon, { icon: faCircle, className: "text-light", style: {
40681
+ transform: `translateX(${isOn ? '' : '-'}0.7rem)`,
40682
+ transition: '0.3s transform ease-in-out',
40683
+ } })));
40684
+ };
40685
+
40633
40686
  /**
40634
40687
  * One minute in ms
40635
40688
  * @author Gabe Abrams
@@ -42509,5 +42562,5 @@ var DayOfWeek;
42509
42562
  })(DayOfWeek || (DayOfWeek = {}));
42510
42563
  var DayOfWeek$1 = DayOfWeek;
42511
42564
 
42512
- export { AppWrapper, 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, Tooltip, Variant$1 as Variant, abbreviate, addDBEditorEndpoints, alert$1 as alert, avg, canReviewLogs, ceilToNumDecimals, compareArraysByProp, confirm, extractProp, floorToNumDecimals, forceNumIntoBounds, genCSV, genCommaList, genRouteHandler, getHumanReadableDate, getLocalTimeInfo, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, initClient, initLogCollection, initServer, isMobileOrTablet, logClientEvent, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, roundToNumDecimals, showFatalError, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, validateEmail, validatePhoneNumber, validateString, visitServerEndpoint, waitMs };
42565
+ export { AppWrapper, 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, initClient, initLogCollection, initServer, isMobileOrTablet, logClientEvent, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, roundToNumDecimals, showFatalError, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, validateEmail, validatePhoneNumber, validateString, visitServerEndpoint, waitMs };
42513
42566
  //# sourceMappingURL=index.js.map