@torq-north/react-tools 1.1.1 → 1.3.0

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.es.js CHANGED
@@ -558,9 +558,9 @@ var isRequired = function (value) {
558
558
  function TextFormField(_a) {
559
559
  var _b;
560
560
  var name = _a.name, label = _a.label, required = _a.required, multiline = _a.multiline, disabled = _a.disabled, placeholder = _a.placeholder, slotProps = _a.slotProps, helperText = _a.helperText, icon = _a.icon, showSpace = _a.showSpace, format = _a.format, _c = _a.validators, validators = _c === void 0 ? [] : _c;
561
- var _d = useField(name, __assign(__assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.field), { format: format, validate: required
562
- ? composeValidators.apply(void 0, __spreadArray(__spreadArray([], validators, false), [isRequired], false)) : composeValidators.apply(void 0, validators) })), input = _d.input, meta = _d.meta;
563
- var textFieldProps = deepmerge((_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.textField) !== null && _b !== void 0 ? _b : {}, {
561
+ var _d = useField(name, __assign({ format: format, validate: required
562
+ ? 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;
563
+ var textFieldProps = deepmerge({
564
564
  fullWidth: true,
565
565
  label: label,
566
566
  required: required,
@@ -570,7 +570,7 @@ function TextFormField(_a) {
570
570
  error: meta.touched && meta.error,
571
571
  helperText: (meta.touched && meta.error) || helperText,
572
572
  slotProps: { input: input },
573
- });
573
+ }, (_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.textField) !== null && _b !== void 0 ? _b : {});
574
574
  return (jsx(FieldWrapper, { icon: icon, showSpace: showSpace, children: jsx(TextField, __assign({}, textFieldProps)) }));
575
575
  }
576
576
 
@@ -616,9 +616,9 @@ function render(option, showCheckbox, isSelected) {
616
616
  function SelectFormField(_a) {
617
617
  var _b, _c;
618
618
  var name = _a.name, label = _a.label, required = _a.required, disabled = _a.disabled, helperText = _a.helperText, slotProps = _a.slotProps, isClearable = _a.isClearable, options = _a.options, icon = _a.icon, showSpace = _a.showSpace, format = _a.format, _d = _a.validators, validators = _d === void 0 ? [] : _d;
619
- var _e = useField(name, __assign(__assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.field), { format: format, validate: required
620
- ? composeValidators.apply(void 0, __spreadArray(__spreadArray([], validators, false), [isRequired], false)) : composeValidators.apply(void 0, validators) })), _f = _e.input, value = _f.value, onChange = _f.onChange, otherInputProps = __rest(_f, ["value", "onChange"]), meta = _e.meta;
621
- var textFieldProps = deepmerge((_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.textField) !== null && _b !== void 0 ? _b : {}, {
619
+ var _e = useField(name, __assign({ format: format, validate: required
620
+ ? composeValidators.apply(void 0, __spreadArray(__spreadArray([], validators, false), [isRequired], false)) : composeValidators.apply(void 0, validators) }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.field)), _f = _e.input, value = _f.value, onChange = _f.onChange, otherInputProps = __rest(_f, ["value", "onChange"]), meta = _e.meta;
621
+ var textFieldProps = deepmerge({
622
622
  fullWidth: true,
623
623
  select: true,
624
624
  label: label,
@@ -631,10 +631,10 @@ function SelectFormField(_a) {
631
631
  slotProps: {
632
632
  input: otherInputProps,
633
633
  select: {
634
- endAdornment: isClearable ? (jsx(Box, { pr: 2, children: jsx(IconButton, { size: (_c = slotProps === null || slotProps === void 0 ? void 0 : slotProps.textField) === null || _c === void 0 ? void 0 : _c.size, onClick: function () { return onChange(undefined); }, children: jsx(CloseIcon, { fontSize: "inherit" }) }) })) : undefined,
634
+ endAdornment: isClearable ? (jsx(Box, { pr: 2, children: jsx(IconButton, { size: (_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.textField) === null || _b === void 0 ? void 0 : _b.size, onClick: function () { return onChange(undefined); }, children: jsx(CloseIcon, { fontSize: "inherit" }) }) })) : undefined,
635
635
  },
636
636
  },
637
- });
637
+ }, (_c = slotProps === null || slotProps === void 0 ? void 0 : slotProps.textField) !== null && _c !== void 0 ? _c : {});
638
638
  var renderedOptions = useMemo(function () { return renderSelectOptions(options); }, [options]);
639
639
  return (jsx(FieldWrapper, { icon: icon, showSpace: showSpace, children: jsxs(TextField, __assign({}, textFieldProps, { children: [renderedOptions, !options && jsx(MenuItem, {})] })) }));
640
640
  }
@@ -661,9 +661,9 @@ function findTextFor(value, options) {
661
661
  function MultiSelectFormField(_a) {
662
662
  var _b, _c;
663
663
  var name = _a.name, label = _a.label, required = _a.required, disabled = _a.disabled, helperText = _a.helperText, slotProps = _a.slotProps, isClearable = _a.isClearable, options = _a.options, icon = _a.icon, showSpace = _a.showSpace, format = _a.format, _d = _a.validators, validators = _d === void 0 ? [] : _d;
664
- var _e = useField(name, __assign(__assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.field), { format: format, validate: required
665
- ? composeValidators.apply(void 0, __spreadArray(__spreadArray([], validators, false), [isRequired], false)) : composeValidators.apply(void 0, validators) })), _f = _e.input, value = _f.value, onChange = _f.onChange, otherInputProps = __rest(_f, ["value", "onChange"]), meta = _e.meta;
666
- var textFieldProps = deepmerge((_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.textField) !== null && _b !== void 0 ? _b : {}, {
664
+ var _e = useField(name, __assign({ format: format, validate: required
665
+ ? composeValidators.apply(void 0, __spreadArray(__spreadArray([], validators, false), [isRequired], false)) : composeValidators.apply(void 0, validators) }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.field)), _f = _e.input, value = _f.value, onChange = _f.onChange, otherInputProps = __rest(_f, ["value", "onChange"]), meta = _e.meta;
666
+ var textFieldProps = deepmerge({
667
667
  fullWidth: true,
668
668
  select: true,
669
669
  label: label,
@@ -676,12 +676,12 @@ function MultiSelectFormField(_a) {
676
676
  slotProps: {
677
677
  input: otherInputProps,
678
678
  select: {
679
- endAdornment: isClearable ? (jsx(Box, { pr: 2, children: jsx(IconButton, { size: (_c = slotProps === null || slotProps === void 0 ? void 0 : slotProps.textField) === null || _c === void 0 ? void 0 : _c.size, onClick: function () { return onChange([]); }, children: jsx(CloseIcon, { fontSize: "inherit" }) }) })) : undefined,
679
+ endAdornment: isClearable ? (jsx(Box, { pr: 2, children: jsx(IconButton, { size: (_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.textField) === null || _b === void 0 ? void 0 : _b.size, onClick: function () { return onChange([]); }, children: jsx(CloseIcon, { fontSize: "inherit" }) }) })) : undefined,
680
680
  multiple: true,
681
681
  renderValue: function (selected) { return (jsx(Box, { whiteSpace: "normal", children: selected.map(function (s) { return findTextFor(s, options); }).join(", ") })); },
682
682
  },
683
683
  },
684
- });
684
+ }, (_c = slotProps === null || slotProps === void 0 ? void 0 : slotProps.textField) !== null && _c !== void 0 ? _c : {});
685
685
  var renderedOptions = useMemo(function () { return renderCheckboxSelectOptions(options, value); }, [options, value]);
686
686
  return (jsx(FieldWrapper, { icon: icon, showSpace: showSpace, children: jsxs(TextField, __assign({}, textFieldProps, { children: [renderedOptions, !options && jsx(MenuItem, {})] })) }));
687
687
  }
@@ -692,19 +692,19 @@ var mustBeChecked = function (v) {
692
692
 
693
693
  var CheckboxFormField = function (_a) {
694
694
  var _b;
695
- var name = _a.name, label = _a.label, mustBeTrue = _a.mustBeTrue, disabled = _a.disabled, helperText = _a.helperText, slotProps = _a.slotProps, icon = _a.icon, showSpace = _a.showSpace, _c = _a.validators, validators = _c === void 0 ? [] : _c;
695
+ var name = _a.name, label = _a.label, mustBeTrue = _a.mustBeTrue, disabled = _a.disabled, helperText = _a.helperText, slotProps = _a.slotProps, icon = _a.icon, showSpace = _a.showSpace, _c = _a.validators, validators = _c === void 0 ? [] : _c, forceError = _a.forceError;
696
696
  var _d = useField(name, __assign({ type: "checkbox", validate: mustBeTrue
697
697
  ? 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 = _d.input, meta = _d.meta;
698
- var checkboxProps = deepmerge((_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.checkbox) !== null && _b !== void 0 ? _b : {}, __assign(__assign({}, input), { disabled: disabled }));
699
- return (jsxs(FieldWrapper, { icon: icon, showSpace: showSpace, children: [jsx(FormControlLabel, { control: jsx(FormGroup, { children: jsx(Checkbox, __assign({}, checkboxProps)) }), label: label, disabled: disabled }), ((meta.touched && meta.error) || helperText) && (jsx(FormHelperText, { disabled: disabled, error: meta.touched && meta.error, sx: { marginTop: 0, marginLeft: 2 }, children: meta.error || helperText }))] }));
698
+ var checkboxProps = deepmerge(__assign(__assign({}, input), { disabled: disabled }), (_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.checkbox) !== null && _b !== void 0 ? _b : {});
699
+ return (jsxs(FieldWrapper, { icon: icon, showSpace: showSpace, children: [jsx(FormControlLabel, { control: jsx(FormGroup, { children: jsx(Checkbox, __assign({}, checkboxProps)) }), label: label, disabled: disabled }), ((meta.touched && meta.error) || helperText) && (jsx(FormHelperText, { disabled: disabled, error: (meta.touched && meta.error) || forceError, sx: { marginTop: 0, marginLeft: 2 }, children: meta.error || helperText }))] }));
700
700
  };
701
701
 
702
702
  var DateFormField = function (_a) {
703
703
  var _b;
704
704
  var name = _a.name, label = _a.label, required = _a.required, icon = _a.icon, showSpace = _a.showSpace, slotProps = _a.slotProps, disabled = _a.disabled, helperText = _a.helperText, format = _a.format, _c = _a.validators, validators = _c === void 0 ? [] : _c;
705
- var _d = useField(name, __assign(__assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.field), { format: format, validate: required
706
- ? composeValidators.apply(void 0, __spreadArray(__spreadArray([], validators, false), [isRequired], false)) : composeValidators.apply(void 0, validators) })), input = _d.input, meta = _d.meta;
707
- var datePickerProps = deepmerge((_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.datePicker) !== null && _b !== void 0 ? _b : {}, {
705
+ var _d = useField(name, __assign({ format: format, validate: required
706
+ ? 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;
707
+ var datePickerProps = deepmerge({
708
708
  label: label,
709
709
  disabled: disabled,
710
710
  views: ["year", "month", "day"],
@@ -719,16 +719,16 @@ var DateFormField = function (_a) {
719
719
  onBlur: input.onBlur,
720
720
  },
721
721
  },
722
- });
722
+ }, (_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.datePicker) !== null && _b !== void 0 ? _b : {});
723
723
  return (jsx(FieldWrapper, { icon: icon, showSpace: showSpace, children: jsx(DatePicker, __assign({ value: input.value ? dayjs(input.value) : null, onChange: function (value) { return input.onChange(value === null || value === void 0 ? void 0 : value.toJSON()); } }, datePickerProps)) }));
724
724
  };
725
725
 
726
726
  var DateTimeFormField = function (_a) {
727
727
  var _b;
728
728
  var name = _a.name, label = _a.label, required = _a.required, icon = _a.icon, showSpace = _a.showSpace, slotProps = _a.slotProps, disabled = _a.disabled, helperText = _a.helperText, format = _a.format, _c = _a.validators, validators = _c === void 0 ? [] : _c;
729
- var _d = useField(name, __assign(__assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.field), { format: format, validate: required
730
- ? composeValidators.apply(void 0, __spreadArray(__spreadArray([], validators, false), [isRequired], false)) : composeValidators.apply(void 0, validators) })), input = _d.input, meta = _d.meta;
731
- var dateTimeProps = deepmerge((_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.dateTimePicker) !== null && _b !== void 0 ? _b : {}, {
729
+ var _d = useField(name, __assign({ format: format, validate: required
730
+ ? 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;
731
+ var dateTimeProps = deepmerge({
732
732
  label: label,
733
733
  disabled: disabled,
734
734
  views: ["year", "month", "day"],
@@ -743,7 +743,7 @@ var DateTimeFormField = function (_a) {
743
743
  onBlur: input.onBlur,
744
744
  },
745
745
  },
746
- });
746
+ }, (_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.dateTimePicker) !== null && _b !== void 0 ? _b : {});
747
747
  return (jsx(FieldWrapper, { icon: icon, showSpace: showSpace, children: jsx(DateTimePicker, __assign({ value: input.value ? dayjs(input.value) : null, onChange: function (value) { return input.onChange(value === null || value === void 0 ? void 0 : value.toJSON()); } }, dateTimeProps)) }));
748
748
  };
749
749
 
@@ -754,16 +754,16 @@ var RadioOption = function (props) {
754
754
  };
755
755
 
756
756
  var RadioFormField = function (_a) {
757
- 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, _b = _a.validators, validators = _b === void 0 ? [] : _b;
758
- var _c = useField(name, __assign(__assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.field), { validate: required
759
- ? composeValidators.apply(void 0, __spreadArray(__spreadArray([], validators, false), [isRequired], false)) : composeValidators.apply(void 0, validators) })).meta, error = _c.error, visited = _c.visited;
757
+ 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;
758
+ var _c = useField(name, __assign({ validate: required
759
+ ? 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, error = _c.error, visited = _c.visited;
760
760
  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) {
761
761
  var _a, _b;
762
- 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" }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.radioField, { render: function (_a) {
762
+ 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) {
763
763
  var input = _a.input, meta = _a.meta;
764
764
  return (jsx(RadioOption, { input: input, meta: meta, disabled: disabled, required: required, radioProps: slotProps === null || slotProps === void 0 ? void 0 : slotProps.radio }));
765
- } })) }, typeof o === "string" ? o : ((_b = o.text) !== null && _b !== void 0 ? _b : o.value)));
766
- }) }), (((visited || disabled) && error) || helperText) && (jsx(FormHelperText, { error: error != null, sx: { marginTop: 0 }, children: error || helperText }))] }) }));
765
+ } }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.radioField)) }, typeof o === "string" ? o : ((_b = o.text) !== null && _b !== void 0 ? _b : o.value)));
766
+ }) }), (((visited || disabled) && error) || helperText) && (jsx(FormHelperText, { error: error != null || forceError, sx: { marginTop: 0 }, children: error || helperText }))] }) }));
767
767
  };
768
768
 
769
769
  var ErrorMessage = function (_a) {
@@ -815,6 +815,63 @@ var DropIndicator = styled(Box, {
815
815
  });
816
816
  });
817
817
 
818
+ function isAsset(file) {
819
+ return "id" in file;
820
+ }
821
+
822
+ var FileBox = styled(Box)(function (_a) {
823
+ var disableInteraction = _a.disableInteraction, theme = _a.theme;
824
+ var alterFunc = theme.palette.mode === "dark" ? lighten : darken;
825
+ return {
826
+ transition: "0.2s",
827
+ cursor: disableInteraction ? undefined : "pointer",
828
+ "&:hover": disableInteraction
829
+ ? undefined
830
+ : {
831
+ backgroundColor: alterFunc(theme.palette.background.paper, 0.05),
832
+ "&:active": {
833
+ transition: "0s",
834
+ backgroundColor: alterFunc(theme.palette.background.paper, 0.1),
835
+ },
836
+ },
837
+ "&:nth-of-type(odd)": {
838
+ backgroundColor: alterFunc(theme.palette.background.paper, 0.05),
839
+ "&:hover": disableInteraction
840
+ ? undefined
841
+ : {
842
+ backgroundColor: alterFunc(theme.palette.background.paper, 0.1),
843
+ "&:active": {
844
+ backgroundColor: alterFunc(theme.palette.background.paper, 0.15),
845
+ },
846
+ },
847
+ },
848
+ };
849
+ });
850
+
851
+ var UnstyledLink = styled("a")({
852
+ color: "unset",
853
+ textDecoration: "none",
854
+ });
855
+ function IndividualFile(_a) {
856
+ var file = _a.file, disableLink = _a.disableLink, allowDelete = _a.allowDelete, onDelete = _a.onDelete;
857
+ var isImage = isAsset(file)
858
+ ? file.mimeType.startsWith("image")
859
+ : ["png", "jpg", "jpeg", "gif"].some(function (ext) { return file.name.endsWith(ext); });
860
+ var content = (jsxs(Stack, { p: 0.5, direction: "row", justifyContent: "space-between", children: [jsxs(Stack, { direction: "row", gap: 2, alignItems: "center", children: [isImage ? jsx(ImageIcon, {}) : jsx(FileIcon, {}), jsx(Typography, { children: isAsset(file) ? file.fileName : file.name }), file instanceof File && (jsx(Tooltip, { title: "New File", placement: "right", children: jsx(SparkleIcon, { color: "info" }) }))] }), allowDelete && (jsx(IconButton, { color: "error", onClick: function (e) {
861
+ e.stopPropagation();
862
+ onDelete && onDelete(file);
863
+ }, children: jsx(DeleteIcon, {}) }))] }));
864
+ return (jsxs(FileBox, { disableInteraction: disableLink, children: [!disableLink && (jsx(UnstyledLink, { href: isAsset(file) ? file.fullPath : "#", target: "_blank", children: content })), disableLink && content] }));
865
+ }
866
+
867
+ function FileDisplay(_a) {
868
+ var files = _a.files, individualFileProps = __rest(_a, ["files"]);
869
+ if (!Array.isArray(files)) {
870
+ return (jsx(Box, { children: jsx(IndividualFile, __assign({ file: files }, individualFileProps)) }));
871
+ }
872
+ return (jsx(Stack, { children: files.map(function (f) { return (jsx(IndividualFile, __assign({ file: f }, individualFileProps), isAsset(f) ? f.id : f.name)); }) }));
873
+ }
874
+
818
875
  var propTypes = {exports: {}};
819
876
 
820
877
  var reactIs = {exports: {}};
@@ -4795,24 +4852,21 @@ function arrayify(value) {
4795
4852
  }
4796
4853
  return Array.isArray(value) ? value : [value];
4797
4854
  }
4798
- function useFileEditorField(name, options) {
4799
- var _a = useField(name, __assign(__assign({}, options.fieldProps), { validate: function (v) {
4800
- return options.required && v == null ? "This field is required" : undefined;
4801
- } })), input = _a.input, meta = _a.meta;
4802
- var values = useMemo(function () { return arrayify(input.value); }, [input.value]);
4803
- var _b = useState(false), showError = _b[0], setShowError = _b[1];
4804
- var _c = useState(""), errorMessage = _c[0], setErrorMessage = _c[1];
4805
- var _d = useState(false), dragOverDropzone = _d[0], setDragOverDropzone = _d[1];
4855
+ function useFileEditor(value, onChange, options) {
4856
+ var values = useMemo(function () { return arrayify(value); }, [value]);
4857
+ var _a = useState(false), showError = _a[0], setShowError = _a[1];
4858
+ var _b = useState(""), errorMessage = _b[0], setErrorMessage = _b[1];
4859
+ var _c = useState(false), dragOverDropzone = _c[0], setDragOverDropzone = _c[1];
4806
4860
  var multiple = options.multiple, disabled = options.disabled, otherOptions = __rest(options, ["multiple", "disabled"]);
4807
- var _e = useDropzone(__assign({ multiple: multiple, noClick: multiple || values.length == 0, noKeyboard: multiple, disabled: disabled, onDragEnter: function () { return setDragOverDropzone(true); }, onDragOver: function (e) {
4861
+ var _d = useDropzone(__assign({ multiple: multiple, noClick: multiple || values.length == 0, noKeyboard: multiple, disabled: disabled, onDragEnter: function () { return setDragOverDropzone(true); }, onDragOver: function (e) {
4808
4862
  e.preventDefault();
4809
4863
  e.stopPropagation();
4810
4864
  }, onDragLeave: function () { return setDragOverDropzone(false); }, onDrop: function () { return setDragOverDropzone(false); }, onDropAccepted: function (acceptedFiles) {
4811
4865
  if (multiple) {
4812
- input.onChange((values !== null && values !== void 0 ? values : []).concat(acceptedFiles));
4866
+ onChange((values !== null && values !== void 0 ? values : []).concat(acceptedFiles));
4813
4867
  }
4814
4868
  else {
4815
- input.onChange(acceptedFiles[0]);
4869
+ onChange(acceptedFiles[0]);
4816
4870
  }
4817
4871
  }, onDropRejected: function (fileRejections) {
4818
4872
  setShowError(true);
@@ -4820,17 +4874,13 @@ function useFileEditorField(name, options) {
4820
4874
  setErrorMessage("Multiple files cannot be added to this field");
4821
4875
  }
4822
4876
  else {
4823
- //Other than trying to add multiple files to a single input, the only other errors
4824
- // it could be would be size or type violations. Since those are case by case and kind
4825
- // of hard to cram into a single error message, it's easier to just cover all our bases
4826
- // with one message
4827
4877
  setErrorMessage("Some files were rejected because they do not fit the size restriction or are not the right file type");
4828
4878
  }
4829
- } }, otherOptions)), getRootProps = _e.getRootProps, getInputProps = _e.getInputProps, open = _e.open;
4879
+ } }, otherOptions)), getRootProps = _d.getRootProps, getInputProps = _d.getInputProps, open = _d.open;
4830
4880
  var removeFile = useCallback(function (file) {
4831
4881
  var _a, _b;
4832
4882
  if (!multiple) {
4833
- input.onChange(null);
4883
+ onChange(null);
4834
4884
  return;
4835
4885
  }
4836
4886
  var index = (_a = values === null || values === void 0 ? void 0 : values.findIndex(function (f) { return f === file; })) !== null && _a !== void 0 ? _a : -1;
@@ -4839,8 +4889,8 @@ function useFileEditorField(name, options) {
4839
4889
  }
4840
4890
  var copy = (_b = values === null || values === void 0 ? void 0 : values.slice()) !== null && _b !== void 0 ? _b : [];
4841
4891
  copy.splice(index, 1);
4842
- input.onChange(copy);
4843
- }, [multiple, input.onChange, values]);
4892
+ onChange(copy);
4893
+ }, [multiple, onChange, values]);
4844
4894
  return {
4845
4895
  dragOverDropzone: dragOverDropzone,
4846
4896
  getRootProps: getRootProps,
@@ -4851,77 +4901,37 @@ function useFileEditorField(name, options) {
4851
4901
  showError: showError,
4852
4902
  setShowError: setShowError,
4853
4903
  errorMessage: errorMessage,
4854
- meta: meta,
4855
4904
  };
4856
4905
  }
4857
4906
 
4858
- function isAsset(file) {
4859
- return "id" in file;
4860
- }
4861
-
4862
- var FileBox = styled(Box)(function (_a) {
4863
- var disableInteraction = _a.disableInteraction, theme = _a.theme;
4864
- var alterFunc = theme.palette.mode === "dark" ? lighten : darken;
4865
- return {
4866
- transition: "0.2s",
4867
- cursor: disableInteraction ? undefined : "pointer",
4868
- "&:hover": disableInteraction
4869
- ? undefined
4870
- : {
4871
- backgroundColor: alterFunc(theme.palette.background.paper, 0.05),
4872
- "&:active": {
4873
- transition: "0s",
4874
- backgroundColor: alterFunc(theme.palette.background.paper, 0.1),
4875
- },
4876
- },
4877
- "&:nth-of-type(odd)": {
4878
- backgroundColor: alterFunc(theme.palette.background.paper, 0.05),
4879
- "&:hover": disableInteraction
4880
- ? undefined
4881
- : {
4882
- backgroundColor: alterFunc(theme.palette.background.paper, 0.1),
4883
- "&:active": {
4884
- backgroundColor: alterFunc(theme.palette.background.paper, 0.15),
4885
- },
4886
- },
4887
- },
4888
- };
4889
- });
4890
-
4891
- var UnstyledLink = styled("a")({
4892
- color: "unset",
4893
- textDecoration: "none",
4894
- });
4895
- function IndividualFile(_a) {
4896
- var file = _a.file, disableLink = _a.disableLink, allowDelete = _a.allowDelete, onDelete = _a.onDelete;
4897
- var isImage = isAsset(file)
4898
- ? file.mimeType.startsWith("image")
4899
- : ["png", "jpg", "jpeg", "gif"].some(function (ext) { return file.name.endsWith(ext); });
4900
- var content = (jsxs(Stack, { p: 0.5, direction: "row", justifyContent: "space-between", children: [jsxs(Stack, { direction: "row", gap: 2, alignItems: "center", children: [isImage ? jsx(ImageIcon, {}) : jsx(FileIcon, {}), jsx(Typography, { children: isAsset(file) ? file.fileName : file.name }), file instanceof File && (jsx(Tooltip, { title: "New File", placement: "right", children: jsx(SparkleIcon, { color: "info" }) }))] }), allowDelete && (jsx(IconButton, { color: "error", onClick: function (e) {
4901
- e.stopPropagation();
4902
- onDelete && onDelete(file);
4903
- }, children: jsx(DeleteIcon, {}) }))] }));
4904
- return (jsxs(FileBox, { disableInteraction: disableLink, children: [!disableLink && (jsx(UnstyledLink, { href: isAsset(file) ? file.fullPath : "#", target: "_blank", children: content })), disableLink && content] }));
4907
+ function FileEditor(_a) {
4908
+ var value = _a.value, onChange = _a.onChange, multiple = _a.multiple, disabled = _a.disabled, placeholder = _a.placeholder, accept = _a.accept, maxFiles = _a.maxFiles, maxSize = _a.maxSize, minSize = _a.minSize;
4909
+ var _b = useFileEditor(value, onChange, {
4910
+ multiple: multiple,
4911
+ accept: accept,
4912
+ disabled: disabled,
4913
+ maxFiles: maxFiles,
4914
+ maxSize: maxSize,
4915
+ minSize: minSize,
4916
+ }), getInputProps = _b.getInputProps, getRootProps = _b.getRootProps, dragOverDropzone = _b.dragOverDropzone, values = _b.values, removeFile = _b.removeFile, open = _b.open, showError = _b.showError, setShowError = _b.setShowError, errorMessage = _b.errorMessage;
4917
+ return (jsxs(Fragment$1, { children: [jsxs(Box, { sx: { position: "relative" }, children: [jsx("input", __assign({}, getInputProps())), jsx(DropIndicator, __assign({ multiple: multiple, dragOver: dragOverDropzone, disabled: disabled }, getRootProps(), { children: jsxs(Stack, { gap: 1, children: [values.length > 0 && (jsx(Box, { sx: { opacity: disabled ? 0.4 : 1 }, children: jsx(FileDisplay, { files: values !== null && values !== void 0 ? values : [], disableLink: true, allowDelete: !disabled, onDelete: removeFile }) })), (multiple || (values === null || values === void 0 ? void 0 : values.length) == 0) && (jsx(Button, { onClick: open, startIcon: jsx(AddIcon, {}), fullWidth: true, disabled: disabled, children: placeholder !== null && placeholder !== void 0 ? placeholder : "Add File".concat(multiple ? "s" : "") }))] }) })), dragOverDropzone && (jsx(Stack, { position: "absolute", top: 0, bottom: 0, left: 0, right: 0, justifyContent: "center", alignItems: "center", sx: { pointerEvents: "none" }, children: jsx(NoteAddIcon, { sx: { fontSize: 50 } }) }))] }), jsx(ErrorNotification, { open: showError, onClose: function () { return setShowError(false); }, message: errorMessage })] }));
4905
4918
  }
4906
4919
 
4907
- function FileDisplay(_a) {
4908
- var files = _a.files, individualFileProps = __rest(_a, ["files"]);
4909
- if (!Array.isArray(files)) {
4910
- return (jsx(Box, { children: jsx(IndividualFile, __assign({ file: files }, individualFileProps)) }));
4920
+ var isFileRequired = function (value) {
4921
+ if (value == null) {
4922
+ return "This field is required";
4911
4923
  }
4912
- return (jsx(Stack, { children: files.map(function (f) { return (jsx(IndividualFile, __assign({ file: f }, individualFileProps), isAsset(f) ? f.id : f.name)); }) }));
4913
- }
4924
+ if (Array.isArray(value) && value.length === 0) {
4925
+ return "This field is required";
4926
+ }
4927
+ return undefined;
4928
+ };
4914
4929
 
4915
4930
  function FileEditorField(_a) {
4916
- 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;
4917
- var _b = useFileEditorField(name, {
4918
- multiple: multiple,
4919
- accept: accept,
4920
- disabled: disabled,
4921
- required: required,
4922
- fieldProps: slotProps === null || slotProps === void 0 ? void 0 : slotProps.field,
4923
- }), getInputProps = _b.getInputProps, getRootProps = _b.getRootProps, dragOverDropzone = _b.dragOverDropzone, values = _b.values, removeFile = _b.removeFile, open = _b.open, showError = _b.showError, setShowError = _b.setShowError, errorMessage = _b.errorMessage, meta = _b.meta;
4924
- return (jsxs(FieldWrapper, { icon: icon, showSpace: showSpace, children: [jsxs(FormControl, { fullWidth: true, sx: { position: "relative" }, children: [label && (jsx(FormLabel, { disabled: disabled, error: meta.touched && meta.error, children: label })), jsx("input", __assign({}, getInputProps())), jsx(DropIndicator, __assign({ multiple: multiple, dragOver: dragOverDropzone, disabled: disabled }, getRootProps(), { children: jsxs(Stack, { gap: 1, children: [values.length > 0 && (jsx(Box, { sx: { opacity: disabled ? 0.4 : 1 }, children: jsx(FileDisplay, { files: values !== null && values !== void 0 ? values : [], disableLink: true, allowDelete: !disabled, onDelete: removeFile }) })), (multiple || (values === null || values === void 0 ? void 0 : values.length) == 0) && (jsx(Button, { onClick: open, startIcon: jsx(AddIcon, {}), fullWidth: true, disabled: disabled, children: placeholder !== null && placeholder !== void 0 ? placeholder : "Add File".concat(multiple ? "s" : "") }))] }) })), dragOverDropzone && (jsx(Stack, { position: "absolute", top: 0, bottom: 0, left: 0, right: 0, justifyContent: "center", alignItems: "center", sx: { pointerEvents: "none" }, children: jsx(NoteAddIcon, { sx: { fontSize: 50 } }) })), jsx(FormHelperText, { error: meta.touched && meta.error, children: (meta.touched && meta.error) || helperText })] }), jsx(ErrorNotification, { open: showError, onClose: function () { return setShowError(false); }, message: errorMessage })] }));
4931
+ 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;
4932
+ var _c = useField(name, __assign({ validate: required
4933
+ ? 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;
4934
+ return (jsx(FieldWrapper, { icon: icon, showSpace: showSpace, children: jsxs(FormControl, { fullWidth: true, children: [label && (jsx(FormLabel, { disabled: disabled, error: meta.touched && meta.error, 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: (meta.touched && meta.error) || forceError, children: (meta.touched && meta.error) || helperText })] }) }));
4925
4935
  }
4926
4936
 
4927
4937
  function asInteger(value) {
@@ -5202,5 +5212,5 @@ function TabSet(_a) {
5202
5212
  }) }) }), jsx(Panel, __assign({}, actualTab === null || actualTab === void 0 ? void 0 : actualTab.PanelProps, { children: actualTab === null || actualTab === void 0 ? void 0 : actualTab.content }))] }));
5203
5213
  }
5204
5214
 
5205
- export { CheckboxFormField, CloseableDialog, ConfirmCancel, DateFormField, DateTimeFormField, EMAIL_REGEX, EditableBlock, ErrorMessage, ErrorNotification, ErrorOverlay, ExtendedPagination, ExtendedTable, FieldWrapper, FileDisplay, FileDropper, 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, usePartialSetterState };
5215
+ 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 };
5206
5216
  //# sourceMappingURL=index.es.js.map