@torq-north/react-tools 1.4.6 → 1.4.8
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/index.cjs +129 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.es.js +129 -50
- package/dist/index.es.js.map +1 -1
- package/dist/src/Core/Api/httpError.d.ts +12 -0
- package/dist/src/Core/Api/index.d.ts +1 -0
- package/dist/src/Form/Utilities/getFieldError.d.ts +3 -0
- package/dist/src/MUI/Components/Error/ErrorOverlay.d.ts +1 -1
- package/package.json +10 -5
package/dist/index.es.js
CHANGED
|
@@ -120,24 +120,90 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
120
120
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
121
121
|
};
|
|
122
122
|
|
|
123
|
-
var Http;
|
|
124
|
-
(function (Http) {
|
|
125
|
-
Http["GET"] = "get";
|
|
126
|
-
Http["POST"] = "post";
|
|
127
|
-
Http["PUT"] = "put";
|
|
128
|
-
Http["PATCH"] = "patch";
|
|
129
|
-
Http["DELETE"] = "delete";
|
|
130
|
-
})(Http || (Http = {}));
|
|
131
123
|
var HTTPError = /** @class */ (function (_super) {
|
|
132
124
|
__extends(HTTPError, _super);
|
|
133
|
-
function HTTPError(message, status) {
|
|
125
|
+
function HTTPError(message, status, violations) {
|
|
126
|
+
if (violations === void 0) { violations = []; }
|
|
127
|
+
var _newTarget = this.constructor;
|
|
134
128
|
var _this = _super.call(this, message) || this;
|
|
129
|
+
// Preserve Error inheritance when consumers use the ES5 build.
|
|
130
|
+
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
131
|
+
_this.name = "HTTPError";
|
|
135
132
|
_this.status = status;
|
|
136
133
|
_this.statusText = message;
|
|
134
|
+
_this.violations = violations;
|
|
137
135
|
return _this;
|
|
138
136
|
}
|
|
139
137
|
return HTTPError;
|
|
140
138
|
}(Error));
|
|
139
|
+
function isJsonResponse(response) {
|
|
140
|
+
var _a;
|
|
141
|
+
var mediaType = (_a = response.headers
|
|
142
|
+
.get("content-type")) === null || _a === void 0 ? void 0 : _a.split(";")[0].trim().toLowerCase();
|
|
143
|
+
return (mediaType === "application/json" ||
|
|
144
|
+
/^application\/[^\s;]+\+json$/.test(mediaType !== null && mediaType !== void 0 ? mediaType : ""));
|
|
145
|
+
}
|
|
146
|
+
function nonEmptyString(value) {
|
|
147
|
+
return typeof value === "string" ? value.trim() || undefined : undefined;
|
|
148
|
+
}
|
|
149
|
+
function asRecord(value) {
|
|
150
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
151
|
+
? value
|
|
152
|
+
: undefined;
|
|
153
|
+
}
|
|
154
|
+
function readViolations(value) {
|
|
155
|
+
if (!Array.isArray(value))
|
|
156
|
+
return [];
|
|
157
|
+
return value.flatMap(function (item) {
|
|
158
|
+
var _a;
|
|
159
|
+
var violation = asRecord(item);
|
|
160
|
+
var title = (_a = nonEmptyString(violation === null || violation === void 0 ? void 0 : violation.title)) !== null && _a !== void 0 ? _a : nonEmptyString(violation === null || violation === void 0 ? void 0 : violation.message);
|
|
161
|
+
return typeof (violation === null || violation === void 0 ? void 0 : violation.propertyPath) === "string" && title
|
|
162
|
+
? [{ propertyPath: violation.propertyPath, title: title }]
|
|
163
|
+
: [];
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function readHttpError(response) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
168
|
+
var payload, _a, violations, message;
|
|
169
|
+
var _c, _d, _e, _f, _g;
|
|
170
|
+
return __generator(this, function (_h) {
|
|
171
|
+
switch (_h.label) {
|
|
172
|
+
case 0:
|
|
173
|
+
if (!isJsonResponse(response)) return [3 /*break*/, 4];
|
|
174
|
+
_h.label = 1;
|
|
175
|
+
case 1:
|
|
176
|
+
_h.trys.push([1, 3, , 4]);
|
|
177
|
+
_a = asRecord;
|
|
178
|
+
return [4 /*yield*/, response.json()];
|
|
179
|
+
case 2:
|
|
180
|
+
payload = _a.apply(void 0, [_h.sent()]);
|
|
181
|
+
return [3 /*break*/, 4];
|
|
182
|
+
case 3:
|
|
183
|
+
_h.sent();
|
|
184
|
+
return [3 /*break*/, 4];
|
|
185
|
+
case 4:
|
|
186
|
+
violations = readViolations(payload === null || payload === void 0 ? void 0 : payload.violations);
|
|
187
|
+
message = (_g = (_f = (_e = (_d = (_c = nonEmptyString(payload === null || payload === void 0 ? void 0 : payload.message)) !== null && _c !== void 0 ? _c : nonEmptyString(payload === null || payload === void 0 ? void 0 : payload.detail)) !== null && _d !== void 0 ? _d : (violations.length
|
|
188
|
+
? violations.map(function (_a) {
|
|
189
|
+
var title = _a.title;
|
|
190
|
+
return title;
|
|
191
|
+
}).join("; ")
|
|
192
|
+
: undefined)) !== null && _e !== void 0 ? _e : nonEmptyString(payload === null || payload === void 0 ? void 0 : payload.title)) !== null && _f !== void 0 ? _f : nonEmptyString(response.statusText)) !== null && _g !== void 0 ? _g : "Request failed (HTTP ".concat(response.status, ")");
|
|
193
|
+
return [2 /*return*/, new HTTPError(message, response.status, violations)];
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
var Http;
|
|
200
|
+
(function (Http) {
|
|
201
|
+
Http["GET"] = "get";
|
|
202
|
+
Http["POST"] = "post";
|
|
203
|
+
Http["PUT"] = "put";
|
|
204
|
+
Http["PATCH"] = "patch";
|
|
205
|
+
Http["DELETE"] = "delete";
|
|
206
|
+
})(Http || (Http = {}));
|
|
141
207
|
var sendGet = function (url, params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
142
208
|
var fetchUrl, response;
|
|
143
209
|
return __generator(this, function (_a) {
|
|
@@ -223,33 +289,17 @@ var sendDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
|
|
|
223
289
|
}); };
|
|
224
290
|
function checkResponse(response) {
|
|
225
291
|
return __awaiter(this, void 0, void 0, function () {
|
|
226
|
-
var exception, message;
|
|
227
292
|
return __generator(this, function (_a) {
|
|
228
293
|
switch (_a.label) {
|
|
229
294
|
case 0:
|
|
230
|
-
if (!!response.ok) return [3 /*break*/,
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
return [4 /*yield*/, response.json()];
|
|
235
|
-
case 1:
|
|
236
|
-
exception = _a.sent();
|
|
237
|
-
_a.label = 2;
|
|
238
|
-
case 2:
|
|
239
|
-
message = (exception && exception.message) || response.statusText;
|
|
240
|
-
throw new HTTPError(message, response.status);
|
|
241
|
-
case 3: return [2 /*return*/];
|
|
295
|
+
if (!!response.ok) return [3 /*break*/, 2];
|
|
296
|
+
return [4 /*yield*/, readHttpError(response)];
|
|
297
|
+
case 1: throw _a.sent();
|
|
298
|
+
case 2: return [2 /*return*/];
|
|
242
299
|
}
|
|
243
300
|
});
|
|
244
301
|
});
|
|
245
302
|
}
|
|
246
|
-
function isJson(response) {
|
|
247
|
-
var contentType = response.headers.get("content-type");
|
|
248
|
-
if (!contentType) {
|
|
249
|
-
return false;
|
|
250
|
-
}
|
|
251
|
-
return contentType.indexOf("application/json") >= 0;
|
|
252
|
-
}
|
|
253
303
|
var authLoginUrl = "/auth/login";
|
|
254
304
|
var authRedirectEnabled = false;
|
|
255
305
|
function enableAuthRedirect(loginUrl) {
|
|
@@ -275,7 +325,7 @@ function process$1(response) {
|
|
|
275
325
|
return [4 /*yield*/, checkResponse(response)];
|
|
276
326
|
case 1:
|
|
277
327
|
_a.sent();
|
|
278
|
-
if (
|
|
328
|
+
if (isJsonResponse(response)) {
|
|
279
329
|
return [2 /*return*/, response.json()];
|
|
280
330
|
}
|
|
281
331
|
return [2 /*return*/, null];
|
|
@@ -381,6 +431,13 @@ function usePartialSetterState(initial) {
|
|
|
381
431
|
return [params, updateParams];
|
|
382
432
|
}
|
|
383
433
|
|
|
434
|
+
/** Hide rejected values' submission errors after the user edits the field. */
|
|
435
|
+
function getFieldError(meta) {
|
|
436
|
+
if (!meta.touched && !meta.submitFailed)
|
|
437
|
+
return undefined;
|
|
438
|
+
return (meta.error || (!meta.dirtySinceLastSubmit ? meta.submitError : undefined));
|
|
439
|
+
}
|
|
440
|
+
|
|
384
441
|
function FieldWrapper(_a) {
|
|
385
442
|
var icon = _a.icon, children = _a.children, showSpace = _a.showSpace;
|
|
386
443
|
return (jsxs(Stack, { direction: "row", alignItems: "center", children: [(icon || showSpace) && (jsx(Box, { minWidth: 32, color: "primary.main", mt: 2, mx: 1, children: icon })), children] }));
|
|
@@ -404,7 +461,9 @@ function composeValidators() {
|
|
|
404
461
|
}
|
|
405
462
|
|
|
406
463
|
var isRequired = function (value) {
|
|
407
|
-
return value ?
|
|
464
|
+
return (Array.isArray(value) ? value.length > 0 : value != null && value !== "")
|
|
465
|
+
? undefined
|
|
466
|
+
: "This field is required";
|
|
408
467
|
};
|
|
409
468
|
|
|
410
469
|
function TextFormField(_a) {
|
|
@@ -417,7 +476,7 @@ function TextFormField(_a) {
|
|
|
417
476
|
var mergedSlotProps = __assign(__assign({}, textFieldSlotProps), { input: typeof inputSlotProp === "function"
|
|
418
477
|
? function (ownerState) { return (__assign(__assign({}, input), inputSlotProp(ownerState))); }
|
|
419
478
|
: __assign(__assign({}, input), inputSlotProp) });
|
|
420
|
-
return (jsx(FieldWrapper, { icon: icon, showSpace: showSpace, children: jsx(TextField, __assign({ fullWidth: true, label: label, required: required, multiline: multiline, disabled: disabled, placeholder: placeholder, error: meta
|
|
479
|
+
return (jsx(FieldWrapper, { icon: icon, showSpace: showSpace, children: jsx(TextField, __assign({ fullWidth: true, label: label, required: required, multiline: multiline, disabled: disabled, placeholder: placeholder, error: getFieldError(meta), helperText: getFieldError(meta) || helperText, slotProps: mergedSlotProps }, remainingTextFieldProps)) }));
|
|
421
480
|
}
|
|
422
481
|
|
|
423
482
|
function isGroup(o) {
|
|
@@ -480,14 +539,25 @@ function SelectFormField(_a) {
|
|
|
480
539
|
var _a;
|
|
481
540
|
setIsFocused(false);
|
|
482
541
|
(_a = inputSlotProps === null || inputSlotProps === void 0 ? void 0 : inputSlotProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(inputSlotProps, event);
|
|
483
|
-
} }), select: __assign(__assign({}, textFieldSlotProps === null || textFieldSlotProps === void 0 ? void 0 : textFieldSlotProps.select), (
|
|
542
|
+
} }), select: __assign(__assign(__assign({}, textFieldSlotProps === null || textFieldSlotProps === void 0 ? void 0 : textFieldSlotProps.select), { onClose: function (e) {
|
|
543
|
+
var _a, _b;
|
|
544
|
+
typeof (textFieldSlotProps === null || textFieldSlotProps === void 0 ? void 0 : textFieldSlotProps.select) === "function"
|
|
545
|
+
? undefined
|
|
546
|
+
: (_b = (_a = textFieldSlotProps === null || textFieldSlotProps === void 0 ? void 0 : textFieldSlotProps.select) === null || _a === void 0 ? void 0 : _a.onClose) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
547
|
+
//When opening a select and then moving the mouse away, the input does not register as
|
|
548
|
+
// being unhovered. We can fudge this by setting the hover state to false when the options
|
|
549
|
+
// menu is closed. If the mouse is still over the input when the menu is closed, the hover state
|
|
550
|
+
// will be set to true automatically by the onMouseEnter event handler (and the focus state is
|
|
551
|
+
// always true the whole time so the clear button won't flicker)
|
|
552
|
+
setIsMousedOver(false);
|
|
553
|
+
} }), (hasEndAdornment && {
|
|
484
554
|
endAdornment: (jsxs(Stack, { direction: "row", spacing: 1, pr: 2, children: [isClearable &&
|
|
485
555
|
(isMousedOver || isFocused) &&
|
|
486
556
|
value != null &&
|
|
487
557
|
value != "" && (jsx(IconButton, { size: "small", onClick: function () { return onChange(undefined); }, tabIndex: -1, children: jsx(CloseIcon, { fontSize: "small" }) })), inputSlotProps === null || inputSlotProps === void 0 ? void 0 : inputSlotProps.endAdornment] })),
|
|
488
558
|
})) });
|
|
489
559
|
var renderedOptions = useMemo(function () { return renderSelectOptions(options); }, [options]);
|
|
490
|
-
return (jsx(FieldWrapper, { icon: icon, showSpace: showSpace, children: jsxs(TextField, __assign({ onMouseEnter: function () { return setIsMousedOver(true); }, onMouseLeave: function () { return setIsMousedOver(false); }, fullWidth: true, select: true, label: label, required: required, disabled: disabled, error: meta
|
|
560
|
+
return (jsx(FieldWrapper, { icon: icon, showSpace: showSpace, children: jsxs(TextField, __assign({ onMouseEnter: function () { return setIsMousedOver(true); }, onMouseLeave: function () { return setIsMousedOver(false); }, fullWidth: true, select: true, label: label, required: required, disabled: disabled, error: getFieldError(meta), helperText: getFieldError(meta) || helperText, value: value ? value : [], onChange: onChange, slotProps: mergedSlotProps }, remainingTextFieldProps, { children: [renderedOptions, !options && jsx(MenuItem, {})] })) }));
|
|
491
561
|
}
|
|
492
562
|
|
|
493
563
|
function findTextFor(value, options) {
|
|
@@ -531,12 +601,23 @@ function MultiSelectFormField(_a) {
|
|
|
531
601
|
var _a;
|
|
532
602
|
setIsFocused(false);
|
|
533
603
|
(_a = inputSlotProps === null || inputSlotProps === void 0 ? void 0 : inputSlotProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(inputSlotProps, event);
|
|
534
|
-
} }), select: __assign(__assign({}, textFieldSlotProps === null || textFieldSlotProps === void 0 ? void 0 : textFieldSlotProps.select), {
|
|
604
|
+
} }), select: __assign(__assign({}, textFieldSlotProps === null || textFieldSlotProps === void 0 ? void 0 : textFieldSlotProps.select), { onClose: function (e) {
|
|
605
|
+
var _a, _b;
|
|
606
|
+
typeof (textFieldSlotProps === null || textFieldSlotProps === void 0 ? void 0 : textFieldSlotProps.select) === "function"
|
|
607
|
+
? undefined
|
|
608
|
+
: (_b = (_a = textFieldSlotProps === null || textFieldSlotProps === void 0 ? void 0 : textFieldSlotProps.select) === null || _a === void 0 ? void 0 : _a.onClose) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
609
|
+
//When opening a select and then moving the mouse away, the input does not register as
|
|
610
|
+
// being unhovered. We can fudge this by setting the hover state to false when the options
|
|
611
|
+
// menu is closed. If the mouse is still over the input when the menu is closed, the hover state
|
|
612
|
+
// will be set to true automatically by the onMouseEnter event handler (and the focus state is
|
|
613
|
+
// always true the whole time so the clear button won't flicker)
|
|
614
|
+
setIsMousedOver(false);
|
|
615
|
+
}, endAdornment: (jsxs(Stack, { direction: "row", spacing: 1, pr: 2, children: [isClearable && (isMousedOver || isFocused) && (value === null || value === void 0 ? void 0 : value.length) > 0 && (jsx(IconButton, { size: "small", onClick: function () { return onChange([]); }, tabIndex: -1, children: jsx(CloseIcon, { fontSize: "small" }) })), inputSlotProps === null || inputSlotProps === void 0 ? void 0 : inputSlotProps.endAdornment] })), multiple: true, renderValue: function (selected) { return (jsx(Stack, { direction: "row", spacing: 1, flexWrap: "wrap", children: selected.map(function (s, index) {
|
|
535
616
|
var _a;
|
|
536
617
|
return (jsxs(React.Fragment, { children: [index > 0 && ", ", (_a = findTextFor(s, options)) !== null && _a !== void 0 ? _a : "Unknown"] }, s));
|
|
537
618
|
}) })); } }) });
|
|
538
619
|
var renderedOptions = useMemo(function () { return renderCheckboxSelectOptions(options, value); }, [options, value]);
|
|
539
|
-
return (jsx(FieldWrapper, { icon: icon, showSpace: showSpace, children: jsxs(TextField, __assign({ onMouseEnter: function () { return setIsMousedOver(true); }, onMouseLeave: function () { return setIsMousedOver(false); }, fullWidth: true, select: true, label: label, required: required, disabled: disabled, error: meta
|
|
620
|
+
return (jsx(FieldWrapper, { icon: icon, showSpace: showSpace, children: jsxs(TextField, __assign({ onMouseEnter: function () { return setIsMousedOver(true); }, onMouseLeave: function () { return setIsMousedOver(false); }, fullWidth: true, select: true, label: label, required: required, disabled: disabled, error: getFieldError(meta), helperText: getFieldError(meta) || helperText, value: value ? value : [], onChange: onChange, slotProps: mergedSlotProps }, remainingTextFieldProps, { children: [renderedOptions, !options && jsx(MenuItem, {})] })) }));
|
|
540
621
|
}
|
|
541
622
|
|
|
542
623
|
var mustBeChecked = function (v) {
|
|
@@ -548,7 +629,7 @@ var CheckboxFormField = function (_a) {
|
|
|
548
629
|
var _c = useField(name, __assign({ type: "checkbox", validate: mustBeTrue
|
|
549
630
|
? composeValidators.apply(void 0, __spreadArray(__spreadArray([], validators, false), [mustBeChecked], false)) : composeValidators.apply(void 0, validators) }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.field)), input = _c.input, meta = _c.meta;
|
|
550
631
|
var checkboxProps = __assign(__assign(__assign({}, input), { disabled: disabled }), slotProps === null || slotProps === void 0 ? void 0 : slotProps.checkbox);
|
|
551
|
-
return (jsxs(FieldWrapper, { icon: icon, showSpace: showSpace, children: [jsx(FormControlLabel, { control: jsx(FormGroup, { children: jsx(Checkbox, __assign({}, checkboxProps)) }), label: label, disabled: disabled }), ((meta
|
|
632
|
+
return (jsxs(FieldWrapper, { icon: icon, showSpace: showSpace, children: [jsx(FormControlLabel, { control: jsx(FormGroup, { children: jsx(Checkbox, __assign({}, checkboxProps)) }), label: label, disabled: disabled }), (getFieldError(meta) || helperText) && (jsx(FormHelperText, { disabled: disabled, error: getFieldError(meta) || forceError, sx: { marginTop: 0, marginLeft: 2 }, children: getFieldError(meta) || helperText }))] }));
|
|
552
633
|
};
|
|
553
634
|
|
|
554
635
|
var DateFormField = function (_a) {
|
|
@@ -557,7 +638,7 @@ var DateFormField = function (_a) {
|
|
|
557
638
|
var _e = useField(name, __assign({ format: format, validate: required
|
|
558
639
|
? composeValidators.apply(void 0, __spreadArray(__spreadArray([], validators, false), [isRequired], false)) : composeValidators.apply(void 0, validators) }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.field)), input = _e.input, meta = _e.meta;
|
|
559
640
|
var _f = ((_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.datePicker) !== null && _b !== void 0 ? _b : {}), datePickerSlotProps = _f.slotProps, remainingDatePickerProps = __rest(_f, ["slotProps"]);
|
|
560
|
-
var mergedSlotProps = __assign(__assign({}, datePickerSlotProps), { textField: __assign({ fullWidth: true, required: required, color: meta
|
|
641
|
+
var mergedSlotProps = __assign(__assign({}, datePickerSlotProps), { textField: __assign({ fullWidth: true, required: required, color: getFieldError(meta) ? "error" : undefined, error: getFieldError(meta), helperText: getFieldError(meta) || helperText, onFocus: input.onFocus, onBlur: input.onBlur }, datePickerSlotProps === null || datePickerSlotProps === void 0 ? void 0 : datePickerSlotProps.textField) });
|
|
561
642
|
return (jsx(FieldWrapper, { icon: icon, showSpace: showSpace, children: jsx(DatePicker, __assign({ label: label, disabled: disabled, views: ["year", "month", "day"], value: input.value ? dayjs(input.value) : null, onOpen: input.onFocus, onClose: input.onBlur, onChange: function (value) {
|
|
562
643
|
return input.onChange(formatAsDate ? value === null || value === void 0 ? void 0 : value.format("YYYY-MM-DD") : value === null || value === void 0 ? void 0 : value.toJSON());
|
|
563
644
|
}, slotProps: mergedSlotProps }, remainingDatePickerProps)) }));
|
|
@@ -569,7 +650,7 @@ var DateTimeFormField = function (_a) {
|
|
|
569
650
|
var _d = useField(name, __assign({ format: format, validate: required
|
|
570
651
|
? composeValidators.apply(void 0, __spreadArray(__spreadArray([], validators, false), [isRequired], false)) : composeValidators.apply(void 0, validators) }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.field)), input = _d.input, meta = _d.meta;
|
|
571
652
|
var _e = ((_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.dateTimePicker) !== null && _b !== void 0 ? _b : {}), dateTimePickerSlotProps = _e.slotProps, remainingDateTimePickerProps = __rest(_e, ["slotProps"]);
|
|
572
|
-
var mergedSlotProps = __assign(__assign({}, dateTimePickerSlotProps), { textField: __assign({ fullWidth: true, required: required, color: meta
|
|
653
|
+
var mergedSlotProps = __assign(__assign({}, dateTimePickerSlotProps), { textField: __assign({ fullWidth: true, required: required, color: getFieldError(meta) ? "error" : undefined, error: getFieldError(meta), helperText: getFieldError(meta) || helperText, onFocus: input.onFocus, onBlur: input.onBlur }, dateTimePickerSlotProps === null || dateTimePickerSlotProps === void 0 ? void 0 : dateTimePickerSlotProps.textField) });
|
|
573
654
|
return (jsx(FieldWrapper, { icon: icon, showSpace: showSpace, children: jsx(DateTimePicker, __assign({ label: label, disabled: disabled, value: input.value ? dayjs(input.value) : null, onOpen: input.onFocus, onClose: input.onBlur, onChange: function (value) { return input.onChange(value === null || value === void 0 ? void 0 : value.toJSON()); }, slotProps: mergedSlotProps }, remainingDateTimePickerProps)) }));
|
|
574
655
|
};
|
|
575
656
|
|
|
@@ -581,15 +662,16 @@ var RadioOption = function (props) {
|
|
|
581
662
|
|
|
582
663
|
var RadioFormField = function (_a) {
|
|
583
664
|
var name = _a.name, label = _a.label, options = _a.options, required = _a.required, disabled = _a.disabled, vertical = _a.vertical, icon = _a.icon, showSpace = _a.showSpace, slotProps = _a.slotProps, helperText = _a.helperText, forceError = _a.forceError, _b = _a.validators, validators = _b === void 0 ? [] : _b;
|
|
584
|
-
var
|
|
585
|
-
? composeValidators.apply(void 0, __spreadArray(__spreadArray([], validators, false), [isRequired], false)) : composeValidators.apply(void 0, validators) }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.field)).meta
|
|
665
|
+
var meta = useField(name, __assign({ validate: required
|
|
666
|
+
? composeValidators.apply(void 0, __spreadArray(__spreadArray([], validators, false), [isRequired], false)) : composeValidators.apply(void 0, validators) }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.field)).meta;
|
|
667
|
+
var error = getFieldError(meta);
|
|
586
668
|
return (jsx(FieldWrapper, { icon: icon, showSpace: showSpace, children: jsxs(FormControl, { required: required, children: [label && (jsx(FormLabel, { id: "".concat(name, "-radio-buttons-group-label"), disabled: disabled, children: label })), jsx(RadioGroup, { "aria-labelledby": "".concat(name, "-radio-buttons-group-label"), row: !vertical, children: options.map(function (o) {
|
|
587
669
|
var _a;
|
|
588
670
|
return (jsx(FormControlLabel, { label: typeof o === "string" ? o : ((_a = o.text) !== null && _a !== void 0 ? _a : o.value), disabled: disabled, control: jsx(Field, __assign({ name: name, value: typeof o === "string" ? o : o.value, type: "radio", render: function (_a) {
|
|
589
671
|
var input = _a.input, meta = _a.meta;
|
|
590
672
|
return (jsx(RadioOption, { input: input, meta: meta, disabled: disabled, required: required, radioProps: slotProps === null || slotProps === void 0 ? void 0 : slotProps.radio }));
|
|
591
673
|
} }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.radioField)) }, typeof o === "string" ? o : o.value));
|
|
592
|
-
}) }), (
|
|
674
|
+
}) }), (error || helperText) && (jsx(FormHelperText, { error: error != null || forceError, sx: { marginTop: 0 }, children: error || helperText }))] }) }));
|
|
593
675
|
};
|
|
594
676
|
|
|
595
677
|
var ErrorMessage = function (_a) {
|
|
@@ -600,20 +682,17 @@ var ErrorMessage = function (_a) {
|
|
|
600
682
|
var ErrorOverlay = function (_a) {
|
|
601
683
|
var _b, _c, _d, _e;
|
|
602
684
|
var children = _a.children, show = _a.show, offset = _a.offset, message = _a.message;
|
|
603
|
-
return (jsxs(Box, { position: "relative", children: [children, jsx(Stack, { position: "absolute", top: -7 + ((_b = offset === null || offset === void 0 ? void 0 : offset.top) !== null && _b !== void 0 ? _b : 0), left: -7 + ((_c = offset === null || offset === void 0 ? void 0 : offset.left) !== null && _c !== void 0 ? _c : 0), right: -7 + ((_d = offset === null || offset === void 0 ? void 0 : offset.right) !== null && _d !== void 0 ? _d : 0), bottom: -7 + ((_e = offset === null || offset === void 0 ? void 0 : offset.bottom) !== null && _e !== void 0 ? _e : 0), zIndex: 1, borderRadius: 2, justifyContent: "center", alignItems: "center", sx: function (theme) { return ({
|
|
685
|
+
return (jsxs(Box, { position: "relative", children: [children, show && (jsx(Stack, { position: "absolute", top: -7 + ((_b = offset === null || offset === void 0 ? void 0 : offset.top) !== null && _b !== void 0 ? _b : 0), left: -7 + ((_c = offset === null || offset === void 0 ? void 0 : offset.left) !== null && _c !== void 0 ? _c : 0), right: -7 + ((_d = offset === null || offset === void 0 ? void 0 : offset.right) !== null && _d !== void 0 ? _d : 0), bottom: -7 + ((_e = offset === null || offset === void 0 ? void 0 : offset.bottom) !== null && _e !== void 0 ? _e : 0), zIndex: 1, borderRadius: 2, justifyContent: "center", alignItems: "center", sx: function (theme) { return ({
|
|
604
686
|
bgcolor: alpha(theme.palette.background.paper, 0.6),
|
|
605
|
-
transition: "0.2s",
|
|
606
|
-
opacity: show ? 1 : 0,
|
|
607
687
|
backdropFilter: "blur(7px)",
|
|
608
|
-
pointerEvents: show ? undefined : "none",
|
|
609
688
|
}); }, children: jsx(Box, { borderRadius: 2, p: 1, sx: function (theme) { return ({
|
|
610
689
|
bgcolor: alpha(theme.palette.background.paper, 0.6),
|
|
611
|
-
}); }, children: jsx(ErrorMessage, { message: message }) }) })] }));
|
|
690
|
+
}); }, children: jsx(ErrorMessage, { message: message }) }) }))] }));
|
|
612
691
|
};
|
|
613
692
|
|
|
614
693
|
var ErrorNotification = function (_a) {
|
|
615
694
|
var open = _a.open, message = _a.message, onClose = _a.onClose;
|
|
616
|
-
return (jsx(Snackbar, { open: open, autoHideDuration: 6000, onClose: onClose, children: jsx(Alert, { onClose: onClose, severity: "error", sx: { width: "100%" }, elevation: 6, variant: "filled", children: message
|
|
695
|
+
return (jsx(Snackbar, { open: open, autoHideDuration: 6000, onClose: onClose, children: jsx(Alert, { onClose: onClose, severity: "error", sx: { width: "100%" }, elevation: 6, variant: "filled", children: (message === null || message === void 0 ? void 0 : message.trim()) || "An error has occurred" }) }));
|
|
617
696
|
};
|
|
618
697
|
|
|
619
698
|
var DropIndicator = styled(Box, {
|
|
@@ -4761,7 +4840,7 @@ function FileEditorField(_a) {
|
|
|
4761
4840
|
var name = _a.name, label = _a.label, icon = _a.icon, showSpace = _a.showSpace, multiple = _a.multiple, disabled = _a.disabled, helperText = _a.helperText, placeholder = _a.placeholder, required = _a.required, slotProps = _a.slotProps, accept = _a.accept, maxFiles = _a.maxFiles, maxSize = _a.maxSize, minSize = _a.minSize, forceError = _a.forceError, _b = _a.validators, validators = _b === void 0 ? [] : _b;
|
|
4762
4841
|
var _c = useField(name, __assign({ validate: required
|
|
4763
4842
|
? composeValidators.apply(void 0, __spreadArray(__spreadArray([], validators, false), [isFileRequired], false)) : composeValidators.apply(void 0, validators) }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.field)), input = _c.input, meta = _c.meta;
|
|
4764
|
-
return (jsx(FieldWrapper, { icon: icon, showSpace: showSpace, children: jsxs(FormControl, { fullWidth: true, children: [label && (jsx(FormLabel, { disabled: disabled, error: meta
|
|
4843
|
+
return (jsx(FieldWrapper, { icon: icon, showSpace: showSpace, children: jsxs(FormControl, { fullWidth: true, children: [label && (jsx(FormLabel, { disabled: disabled, error: getFieldError(meta), children: label })), jsx(FileEditor, { value: input.value, onChange: input.onChange, multiple: multiple, disabled: disabled, accept: accept, maxFiles: maxFiles, maxSize: maxSize, minSize: minSize, placeholder: placeholder }), jsx(FormHelperText, { error: getFieldError(meta) || forceError, children: getFieldError(meta) || helperText })] }) }));
|
|
4765
4844
|
}
|
|
4766
4845
|
|
|
4767
4846
|
function asInteger(value) {
|
|
@@ -5042,5 +5121,5 @@ function TabSet(_a) {
|
|
|
5042
5121
|
}) }) }), jsx(Panel, __assign({}, actualTab === null || actualTab === void 0 ? void 0 : actualTab.PanelProps, { children: actualTab === null || actualTab === void 0 ? void 0 : actualTab.content }))] }));
|
|
5043
5122
|
}
|
|
5044
5123
|
|
|
5045
|
-
export { CheckboxFormField, CloseableDialog, ConfirmCancel, DateFormField, DateTimeFormField, EMAIL_REGEX, EditableBlock, ErrorMessage, ErrorNotification, ErrorOverlay, ExtendedPagination, ExtendedTable, FieldWrapper, FileDisplay, FileDropper, FileEditor, FileEditorField, LabeledValue, LoaderButton, MultiSelectFormField, POSTAL_CODE_REGEX, Panel, RadioFormField, SelectFormField, TabSet, TextFormField, asInteger, asPhoneNumber, enableAuthRedirect, isEmail, isPostalCode, sendDelete, sendFormDataPost, sendGet, sendPost, sendPut, useAsyncData, useAsyncDataCallback, useDebounce, useDebounceEffect, useFileEditor, usePartialSetterState };
|
|
5124
|
+
export { CheckboxFormField, CloseableDialog, ConfirmCancel, DateFormField, DateTimeFormField, EMAIL_REGEX, EditableBlock, ErrorMessage, ErrorNotification, ErrorOverlay, ExtendedPagination, ExtendedTable, FieldWrapper, FileDisplay, FileDropper, FileEditor, FileEditorField, HTTPError, LabeledValue, LoaderButton, MultiSelectFormField, POSTAL_CODE_REGEX, Panel, RadioFormField, SelectFormField, TabSet, TextFormField, asInteger, asPhoneNumber, enableAuthRedirect, isEmail, isPostalCode, sendDelete, sendFormDataPost, sendGet, sendPost, sendPut, useAsyncData, useAsyncDataCallback, useDebounce, useDebounceEffect, useFileEditor, usePartialSetterState };
|
|
5046
5125
|
//# sourceMappingURL=index.es.js.map
|