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