@torq-north/react-tools 1.2.0 → 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 +94 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.es.js +93 -83
- package/dist/index.es.js.map +1 -1
- package/dist/src/Form/Components/FileEditorField/FileEditorField.d.ts +1 -5
- package/dist/src/Form/Components/FileEditorField/useFileEditorField.d.ts +4 -38
- package/dist/src/Form/Components/FileEditorField.d.ts +13 -0
- package/dist/src/Form/Utilities/isFileRequired.d.ts +3 -0
- package/dist/src/MUI/Components/FileEditor/DropIndicator.d.ts +9 -0
- package/dist/src/MUI/Components/FileEditor/FileEditor.d.ts +8 -0
- package/dist/src/MUI/Components/FileEditor/index.d.ts +4 -0
- package/dist/src/MUI/Components/FileEditor/useFileEditor.d.ts +17 -0
- package/dist/src/index.d.ts +1 -0
- package/package.json +3 -2
package/dist/index.es.js
CHANGED
|
@@ -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
|
|
4799
|
-
var
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
var
|
|
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
|
|
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
|
-
|
|
4866
|
+
onChange((values !== null && values !== void 0 ? values : []).concat(acceptedFiles));
|
|
4813
4867
|
}
|
|
4814
4868
|
else {
|
|
4815
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
4843
|
-
}, [multiple,
|
|
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
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
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
|
|
4908
|
-
|
|
4909
|
-
|
|
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
|
-
|
|
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, forceError = _a.forceError;
|
|
4917
|
-
var
|
|
4918
|
-
|
|
4919
|
-
|
|
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) || forceError, 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
|