dce-reactkit 3.9.3 → 3.9.4-beta-prompt.1
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 +109 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/AppWrapper.d.ts +24 -0
- package/dist/cjs/types/index.d.ts +2 -2
- package/dist/cjs/types/types/ModalType.d.ts +1 -0
- package/dist/esm/index.js +109 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/AppWrapper.d.ts +24 -0
- package/dist/esm/types/index.d.ts +2 -2
- package/dist/esm/types/types/ModalType.d.ts +1 -0
- package/dist/index.d.ts +26 -1
- package/package.json +1 -1
- package/src/components/AppWrapper.tsx +216 -0
- package/src/components/Modal/index.tsx +3 -0
- package/src/index.ts +2 -0
- package/src/types/ModalType.tsx +1 -0
|
@@ -44,6 +44,30 @@ export declare const confirm: (title: string, text: string, opts?: {
|
|
|
44
44
|
cancelButtonText?: string;
|
|
45
45
|
cancelButtonVariant?: Variant;
|
|
46
46
|
}) => Promise<boolean>;
|
|
47
|
+
/**
|
|
48
|
+
* Show a prompt modal asking the user for input
|
|
49
|
+
* @author Yuen Ler Chow
|
|
50
|
+
* @param title the title text to display at the top of the prompt
|
|
51
|
+
* @param text the text to display in the prompt
|
|
52
|
+
* @param [opts={}] additional options for the prompt dialog
|
|
53
|
+
* @param [opts.placeholder] the placeholder text for the input field
|
|
54
|
+
* @param [opts.defaultText] the default text for the input field
|
|
55
|
+
* @param [opts.confirmButtonText=Okay] the text of the confirm button
|
|
56
|
+
* @param [opts.confirmButtonVariant=Variant.Dark] the variant of the confirm button
|
|
57
|
+
* @param [opts.cancelButtonText=Cancel] the text of the cancel button
|
|
58
|
+
* @param [opts.cancelButtonVariant=Variant.Secondary] the variant of the cancel button
|
|
59
|
+
* @returns Promise that resolves with the input string or null if canceled
|
|
60
|
+
*/
|
|
61
|
+
export declare const prompt: (title: string, text: string, currentInputFieldText: string, opts?: {
|
|
62
|
+
placeholder?: string | undefined;
|
|
63
|
+
defaultText?: string | undefined;
|
|
64
|
+
confirmButtonText?: string | undefined;
|
|
65
|
+
confirmButtonVariant?: Variant | undefined;
|
|
66
|
+
cancelButtonText?: string | undefined;
|
|
67
|
+
cancelButtonVariant?: Variant | undefined;
|
|
68
|
+
minNumChars?: number | undefined;
|
|
69
|
+
findValidationError?: ((text: string) => string | undefined) | undefined;
|
|
70
|
+
} | undefined) => Promise<string | null>;
|
|
47
71
|
/**
|
|
48
72
|
* Show a fatal error message
|
|
49
73
|
* @author Gabe Abrams
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import AppWrapper, { alert, confirm, showFatalError, addFatalErrorHandler, leaveToURL } from './components/AppWrapper';
|
|
1
|
+
import AppWrapper, { alert, prompt, 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';
|
|
@@ -99,4 +99,4 @@ import PickableItem from './components/ItemPicker/types/PickableItem';
|
|
|
99
99
|
import DBEntry from './components/DBEntryManagerPanel/types/DBEntry';
|
|
100
100
|
import DBEntryField from './components/DBEntryManagerPanel/types/DBEntryField';
|
|
101
101
|
import DBEntryFieldType from './components/DBEntryManagerPanel/types/DBEntryFieldType';
|
|
102
|
-
export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, DBEntryManagerPanel, Tooltip, ToggleSwitch, AutoscrollToBottomContainer, MultiSwitch, Dropdown, 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, prefixWithAOrAn, everyAsync, filterAsync, forEachAsync, mapAsync, someAsync, capitalize, shuffleArray, initClient, visitServerEndpoint, logClientEvent, addFatalErrorHandler, leaveToURL, combineClassNames, useForceRender, setClientEventMetadataPopulator, initServer, genRouteHandler, handleError, handleSuccess, initLogCollection, addDBEditorEndpoints, visitEndpointOnAnotherServer, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, LogFunction, IntelliTableColumn, DropdownItemType, PickableItem, DBEntry, DBEntryField, DBEntryFieldType, ParamType, };
|
|
102
|
+
export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, DBEntryManagerPanel, Tooltip, ToggleSwitch, AutoscrollToBottomContainer, MultiSwitch, Dropdown, alert, prompt, 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, prefixWithAOrAn, everyAsync, filterAsync, forEachAsync, mapAsync, someAsync, capitalize, shuffleArray, initClient, visitServerEndpoint, logClientEvent, addFatalErrorHandler, leaveToURL, combineClassNames, useForceRender, setClientEventMetadataPopulator, initServer, genRouteHandler, handleError, handleSuccess, initLogCollection, addDBEditorEndpoints, visitEndpointOnAnotherServer, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, LogFunction, IntelliTableColumn, DropdownItemType, PickableItem, DBEntry, DBEntryField, DBEntryFieldType, ParamType, };
|
package/dist/esm/index.js
CHANGED
|
@@ -158,6 +158,7 @@ var ModalButtonType$1 = ModalButtonType;
|
|
|
158
158
|
var ModalType;
|
|
159
159
|
(function (ModalType) {
|
|
160
160
|
ModalType["Okay"] = "okay";
|
|
161
|
+
ModalType["Cancel"] = "cancel";
|
|
161
162
|
ModalType["OkayCancel"] = "okay-cancel";
|
|
162
163
|
ModalType["YesNo"] = "yes-no";
|
|
163
164
|
ModalType["YesNoCancel"] = "yes-no-cancel";
|
|
@@ -312,6 +313,9 @@ const modalTypeToModalButtonTypes = {
|
|
|
312
313
|
[ModalType$1.Okay]: [
|
|
313
314
|
ModalButtonType$1.Okay,
|
|
314
315
|
],
|
|
316
|
+
[ModalType$1.Cancel]: [
|
|
317
|
+
ModalButtonType$1.Cancel,
|
|
318
|
+
],
|
|
315
319
|
[ModalType$1.OkayCancel]: [
|
|
316
320
|
ModalButtonType$1.Okay,
|
|
317
321
|
ModalButtonType$1.Cancel,
|
|
@@ -1052,6 +1056,73 @@ const confirm = (title, text, opts) => __awaiter(void 0, void 0, void 0, functio
|
|
|
1052
1056
|
});
|
|
1053
1057
|
});
|
|
1054
1058
|
/*----------------------------------------*/
|
|
1059
|
+
/* --------------- Prompt -------------- */
|
|
1060
|
+
/*----------------------------------------*/
|
|
1061
|
+
// Stored copies of setters
|
|
1062
|
+
let setPromptInfo;
|
|
1063
|
+
// Function to call when prompt is closed
|
|
1064
|
+
let onPromptClosed;
|
|
1065
|
+
/**
|
|
1066
|
+
* Show a prompt modal asking the user for input
|
|
1067
|
+
* @author Yuen Ler Chow
|
|
1068
|
+
* @param title the title text to display at the top of the prompt
|
|
1069
|
+
* @param text the text to display in the prompt
|
|
1070
|
+
* @param [opts={}] additional options for the prompt dialog
|
|
1071
|
+
* @param [opts.placeholder] the placeholder text for the input field
|
|
1072
|
+
* @param [opts.defaultText] the default text for the input field
|
|
1073
|
+
* @param [opts.confirmButtonText=Okay] the text of the confirm button
|
|
1074
|
+
* @param [opts.confirmButtonVariant=Variant.Dark] the variant of the confirm button
|
|
1075
|
+
* @param [opts.cancelButtonText=Cancel] the text of the cancel button
|
|
1076
|
+
* @param [opts.cancelButtonVariant=Variant.Secondary] the variant of the cancel button
|
|
1077
|
+
* @returns Promise that resolves with the input string or null if canceled
|
|
1078
|
+
*/
|
|
1079
|
+
const prompt = (title, text, currentInputFieldText, opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1080
|
+
var _a;
|
|
1081
|
+
// Wait for helper to exist
|
|
1082
|
+
yield waitForHelper(() => {
|
|
1083
|
+
return !!setPromptInfo;
|
|
1084
|
+
});
|
|
1085
|
+
// Fallback if prompt is not available
|
|
1086
|
+
if (!setPromptInfo) {
|
|
1087
|
+
const resultPassesValidation = false;
|
|
1088
|
+
while (!resultPassesValidation) {
|
|
1089
|
+
// eslint-disable-next-line no-alert
|
|
1090
|
+
const result = window.prompt(`${title}\n\n${text}`, (_a = opts === null || opts === void 0 ? void 0 : opts.defaultText) !== null && _a !== void 0 ? _a : '');
|
|
1091
|
+
if (result === null) {
|
|
1092
|
+
return null;
|
|
1093
|
+
}
|
|
1094
|
+
// Validate min num chars
|
|
1095
|
+
const minNumCharsValidationError = (((opts === null || opts === void 0 ? void 0 : opts.minNumChars) && result.length < opts.minNumChars)
|
|
1096
|
+
? `Please enter at least ${opts.minNumChars} characters.`
|
|
1097
|
+
: undefined);
|
|
1098
|
+
// Run custom validation
|
|
1099
|
+
const customValidationError = ((opts === null || opts === void 0 ? void 0 : opts.findValidationError)
|
|
1100
|
+
&& opts.findValidationError(result));
|
|
1101
|
+
// Show validation issue
|
|
1102
|
+
if (minNumCharsValidationError || customValidationError) {
|
|
1103
|
+
alert('Invalid Input', `${minNumCharsValidationError !== null && minNumCharsValidationError !== void 0 ? minNumCharsValidationError : ''} ${customValidationError !== null && customValidationError !== void 0 ? customValidationError : ''}`);
|
|
1104
|
+
}
|
|
1105
|
+
else {
|
|
1106
|
+
return result;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
// Return promise that resolves with result of prompt
|
|
1111
|
+
return new Promise((resolve) => {
|
|
1112
|
+
// Setup handler
|
|
1113
|
+
onPromptClosed = (result) => {
|
|
1114
|
+
resolve(result);
|
|
1115
|
+
};
|
|
1116
|
+
// Show the prompt
|
|
1117
|
+
setPromptInfo({
|
|
1118
|
+
title,
|
|
1119
|
+
text,
|
|
1120
|
+
currentInputFieldText,
|
|
1121
|
+
opts: (opts !== null && opts !== void 0 ? opts : {}),
|
|
1122
|
+
});
|
|
1123
|
+
});
|
|
1124
|
+
});
|
|
1125
|
+
/*----------------------------------------*/
|
|
1055
1126
|
/* ------------- Fatal Error ------------ */
|
|
1056
1127
|
/*----------------------------------------*/
|
|
1057
1128
|
// Stored copies of setters
|
|
@@ -1067,14 +1138,14 @@ const fatalErrorHandlers = [];
|
|
|
1067
1138
|
* @param [errorTitle] title of the error box
|
|
1068
1139
|
*/
|
|
1069
1140
|
const showFatalError = (error, errorTitle = 'An Error Occurred') => __awaiter(void 0, void 0, void 0, function* () {
|
|
1070
|
-
var
|
|
1141
|
+
var _b, _c;
|
|
1071
1142
|
// Determine message and code
|
|
1072
1143
|
const message = (typeof error === 'string'
|
|
1073
1144
|
? error.trim()
|
|
1074
|
-
: String((
|
|
1145
|
+
: String((_b = error.message) !== null && _b !== void 0 ? _b : 'An unknown error occurred.'));
|
|
1075
1146
|
const code = (typeof error === 'string'
|
|
1076
1147
|
? ReactKitErrorCode$1.NoCode
|
|
1077
|
-
: String((
|
|
1148
|
+
: String((_c = error.code) !== null && _c !== void 0 ? _c : ReactKitErrorCode$1.NoCode));
|
|
1078
1149
|
// Call all fatal error listeners
|
|
1079
1150
|
try {
|
|
1080
1151
|
fatalErrorHandlers.forEach((handler) => {
|
|
@@ -1201,6 +1272,9 @@ const AppWrapper = (props) => {
|
|
|
1201
1272
|
// Confirm
|
|
1202
1273
|
const [confirmInfo, setConfirmInfoInner,] = useState(undefined);
|
|
1203
1274
|
setConfirmInfo = setConfirmInfoInner;
|
|
1275
|
+
// Prompt
|
|
1276
|
+
const [promptInfo, setPromptInfoInner] = useState(undefined);
|
|
1277
|
+
setPromptInfo = setPromptInfoInner;
|
|
1204
1278
|
// Session expired
|
|
1205
1279
|
const [sessionHasExpired, setSessionHasExpiredInner,] = useState(false);
|
|
1206
1280
|
setSessionHasExpired = setSessionHasExpiredInner;
|
|
@@ -1231,6 +1305,37 @@ const AppWrapper = (props) => {
|
|
|
1231
1305
|
}
|
|
1232
1306
|
}, onTopOfOtherModals: true, dontAllowBackdropExit: true }, confirmInfo.text));
|
|
1233
1307
|
}
|
|
1308
|
+
/* ------------- Prompt ------------ */
|
|
1309
|
+
if (promptInfo) {
|
|
1310
|
+
// Run min char validation
|
|
1311
|
+
const minNumCharsValidationError = ((promptInfo.opts.minNumChars
|
|
1312
|
+
&& promptInfo.currentInputFieldText.length < promptInfo.opts.minNumChars)
|
|
1313
|
+
? `Please enter at least ${promptInfo.opts.minNumChars} characters.`
|
|
1314
|
+
: undefined);
|
|
1315
|
+
// Run custom validation
|
|
1316
|
+
const customValidationError = (promptInfo.opts.findValidationError
|
|
1317
|
+
&& promptInfo.opts.findValidationError(promptInfo.currentInputFieldText));
|
|
1318
|
+
modal = (React__default.createElement(Modal, { key: `prompt-${promptInfo.title}-${promptInfo.text}`, title: promptInfo.title,
|
|
1319
|
+
// Don't show ok button if there is a validation error
|
|
1320
|
+
type: ((customValidationError || minNumCharsValidationError)
|
|
1321
|
+
? ModalType$1.Cancel
|
|
1322
|
+
: ModalType$1.OkayCancel), okayLabel: promptInfo.opts.confirmButtonText, okayVariant: promptInfo.opts.confirmButtonVariant, cancelLabel: promptInfo.opts.cancelButtonText, cancelVariant: promptInfo.opts.cancelButtonVariant, onClose: (buttonType) => {
|
|
1323
|
+
const result = (buttonType === ModalButtonType$1.Okay
|
|
1324
|
+
? promptInfo.currentInputFieldText
|
|
1325
|
+
: null);
|
|
1326
|
+
setPromptInfo(undefined);
|
|
1327
|
+
if (onPromptClosed) {
|
|
1328
|
+
onPromptClosed(result);
|
|
1329
|
+
}
|
|
1330
|
+
}, onTopOfOtherModals: true, dontAllowBackdropExit: true },
|
|
1331
|
+
React__default.createElement("div", { className: "d-flex flex-column align-items-center" },
|
|
1332
|
+
React__default.createElement("p", null, promptInfo.text),
|
|
1333
|
+
React__default.createElement("input", { type: "text", placeholder: promptInfo.opts.placeholder, value: promptInfo.currentInputFieldText, onChange: (e) => {
|
|
1334
|
+
return setPromptInfo(Object.assign(Object.assign({}, promptInfo), { currentInputFieldText: e.target.value }));
|
|
1335
|
+
} }),
|
|
1336
|
+
minNumCharsValidationError && (React__default.createElement("div", { className: "text-danger bg-danger bg-opacity-25 p-2 m-1 rounded" }, minNumCharsValidationError)),
|
|
1337
|
+
customValidationError && (React__default.createElement("div", { className: "text-danger bg-danger bg-opacity-25 p-2 m-1 rounded" }, customValidationError)))));
|
|
1338
|
+
}
|
|
1234
1339
|
/* ------ Custom Modal Portals ------ */
|
|
1235
1340
|
// Custom modal portals
|
|
1236
1341
|
const customModalPortals = [];
|
|
@@ -16209,5 +16314,5 @@ var DayOfWeek;
|
|
|
16209
16314
|
})(DayOfWeek || (DayOfWeek = {}));
|
|
16210
16315
|
var DayOfWeek$1 = DayOfWeek;
|
|
16211
16316
|
|
|
16212
|
-
export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntryFieldType$1 as DBEntryFieldType, DBEntryManagerPanel, DayOfWeek$1 as DayOfWeek, Drawer, Dropdown, DropdownItemType$1 as DropdownItemType, 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, MultiSwitch, ParamType$1 as ParamType, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode$1 as ReactKitErrorCode, SimpleDateChooser, TabBox, ToggleSwitch, Tooltip, Variant$1 as Variant, abbreviate, addDBEditorEndpoints, addFatalErrorHandler, alert, avg, canReviewLogs, capitalize, ceilToNumDecimals, combineClassNames, compareArraysByProp, confirm, everyAsync, extractProp, filterAsync, floorToNumDecimals, forEachAsync, forceNumIntoBounds, genCSV, genCommaList, genRouteHandler, getHumanReadableDate, getLocalTimeInfo, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, idify, initClient, initLogCollection, initServer, isMobileOrTablet, leaveToURL, logClientEvent, makeLinksClickable, mapAsync, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, prefixWithAOrAn, roundToNumDecimals, setClientEventMetadataPopulator, showFatalError, shuffleArray, someAsync, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, useForceRender, validateEmail, validatePhoneNumber, validateString, visitEndpointOnAnotherServer, visitServerEndpoint, waitMs };
|
|
16317
|
+
export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntryFieldType$1 as DBEntryFieldType, DBEntryManagerPanel, DayOfWeek$1 as DayOfWeek, Drawer, Dropdown, DropdownItemType$1 as DropdownItemType, 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, MultiSwitch, ParamType$1 as ParamType, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode$1 as ReactKitErrorCode, SimpleDateChooser, TabBox, ToggleSwitch, Tooltip, Variant$1 as Variant, abbreviate, addDBEditorEndpoints, addFatalErrorHandler, alert, avg, canReviewLogs, capitalize, ceilToNumDecimals, combineClassNames, compareArraysByProp, confirm, everyAsync, extractProp, filterAsync, floorToNumDecimals, forEachAsync, forceNumIntoBounds, genCSV, genCommaList, genRouteHandler, getHumanReadableDate, getLocalTimeInfo, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, idify, initClient, initLogCollection, initServer, isMobileOrTablet, leaveToURL, logClientEvent, makeLinksClickable, mapAsync, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, prefixWithAOrAn, prompt, roundToNumDecimals, setClientEventMetadataPopulator, showFatalError, shuffleArray, someAsync, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, useForceRender, validateEmail, validatePhoneNumber, validateString, visitEndpointOnAnotherServer, visitServerEndpoint, waitMs };
|
|
16213
16318
|
//# sourceMappingURL=index.js.map
|