@itcase/forms 1.0.66 → 1.0.68
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/itcase-forms.cjs.js +266 -280
- package/dist/itcase-forms.esm.js +266 -280
- package/package.json +23 -23
package/dist/itcase-forms.cjs.js
CHANGED
|
@@ -17,9 +17,9 @@ var Choice = require('@itcase/ui/components/Choice');
|
|
|
17
17
|
var Code = require('@itcase/ui/components/Code');
|
|
18
18
|
var DatePicker = require('@itcase/ui/components/DatePicker');
|
|
19
19
|
var axios = require('axios');
|
|
20
|
-
var reactDropzone = require('react-dropzone');
|
|
21
20
|
var fileSelector = require('file-selector');
|
|
22
21
|
var castArray = require('lodash/castArray');
|
|
22
|
+
var reactDropzone = require('react-dropzone');
|
|
23
23
|
var common = require('@itcase/common');
|
|
24
24
|
var Loader = require('@itcase/ui/components/Loader');
|
|
25
25
|
var Title = require('@itcase/ui/components/Title');
|
|
@@ -896,160 +896,106 @@ DatePickerField.propTypes = {
|
|
|
896
896
|
onChange: PropTypes__default.default.func
|
|
897
897
|
};
|
|
898
898
|
|
|
899
|
-
|
|
900
|
-
try {
|
|
901
|
-
const response = await axios__default.default({
|
|
902
|
-
url,
|
|
903
|
-
responseType: 'blob'
|
|
904
|
-
});
|
|
905
|
-
const blobObject = response.data;
|
|
906
|
-
const dirtyFilename = response.headers['content-disposition']?.split('filename=')[1];
|
|
907
|
-
// Remove double quotes
|
|
908
|
-
let filename = dirtyFilename?.substring(1).slice(0, -1);
|
|
909
|
-
if (!filename) {
|
|
910
|
-
const typeParts = blobObject.type.split('/');
|
|
911
|
-
const fileType = typeParts[typeParts.length - 1];
|
|
912
|
-
filename = `${new Date().getTime()}.${fileType}`;
|
|
913
|
-
}
|
|
914
|
-
return new File([blobObject], filename, {
|
|
915
|
-
type: blobObject.type
|
|
916
|
-
});
|
|
917
|
-
} catch (error) {
|
|
918
|
-
console.log('error: ', error);
|
|
919
|
-
return null;
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
async function convertToFiles(inputValue, isPreviews) {
|
|
923
|
-
const newFiles = [];
|
|
924
|
-
for await (const value of castArray__default.default(inputValue)) {
|
|
925
|
-
let newFile = null;
|
|
926
|
-
|
|
927
|
-
// Download image by url and save as File instance
|
|
928
|
-
const isURL = typeof value === 'string' && value.includes('/');
|
|
929
|
-
if (value.image || isURL) {
|
|
930
|
-
newFile = await getFileByURL(value.image || value);
|
|
931
|
-
if (newFile) {
|
|
932
|
-
setFileDataURL(newFile);
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
// Convert dataURL to File instance
|
|
937
|
-
if (value.dataURL) {
|
|
938
|
-
newFile = common.createFileFromDataURL(value.name || value.path, value.dataURL);
|
|
939
|
-
newFile.dataURL = value.dataURL;
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
// Save new File to state
|
|
943
|
-
if (newFile) {
|
|
944
|
-
newFile.id = value.id;
|
|
945
|
-
if (isPreviews) {
|
|
946
|
-
newFile.preview = URL.createObjectURL(newFile);
|
|
947
|
-
}
|
|
948
|
-
newFiles.push(newFile);
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
// else if (value) {
|
|
952
|
-
// newFiles.push({
|
|
953
|
-
// name: value,
|
|
954
|
-
// error: 'File is unavailable',
|
|
955
|
-
// })
|
|
956
|
-
// }
|
|
957
|
-
}
|
|
958
|
-
return newFiles;
|
|
959
|
-
}
|
|
960
|
-
function setFileDataURL(file, resolve) {
|
|
961
|
-
resolve = resolve || (() => {});
|
|
962
|
-
// Init reader and save his file
|
|
963
|
-
const reader = new FileReader();
|
|
964
|
-
reader._readedFile = file;
|
|
899
|
+
/* globals File, FileReader, URL, console */
|
|
965
900
|
|
|
966
|
-
// Set handlers
|
|
967
|
-
reader.onabort = () => resolve();
|
|
968
|
-
reader.onerror = () => resolve();
|
|
969
|
-
reader.onload = event => {
|
|
970
|
-
event.target._readedFile.dataURL = reader.result;
|
|
971
|
-
resolve();
|
|
972
|
-
};
|
|
973
|
-
// Run reader
|
|
974
|
-
if (file instanceof File) {
|
|
975
|
-
reader.readAsDataURL(file);
|
|
976
|
-
} else {
|
|
977
|
-
resolve();
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
901
|
const FileInputDropzone = /*#__PURE__*/React__default.default.memo(function FileInputDropzone(props) {
|
|
981
902
|
const {
|
|
982
|
-
|
|
983
|
-
size,
|
|
903
|
+
isPreviews,
|
|
984
904
|
className,
|
|
905
|
+
dropzoneProps = {},
|
|
906
|
+
errorMessageTextColor,
|
|
907
|
+
errorMessageTextSize,
|
|
908
|
+
errorMessageTextWeight,
|
|
985
909
|
fileErrorText,
|
|
986
|
-
|
|
987
|
-
removeThumbTextSize,
|
|
988
|
-
removeThumbTextColor,
|
|
989
|
-
removeThumbTextWeight,
|
|
990
|
-
thumbNameTextSize,
|
|
991
|
-
thumbNameTextColor,
|
|
992
|
-
removeThumbTextHoverColor,
|
|
993
|
-
thumbNameTextWrap,
|
|
994
|
-
thumbNameTextWeight,
|
|
995
|
-
hintTitleTextColor,
|
|
996
|
-
hintTitleTextWrap,
|
|
997
|
-
thumbColumn,
|
|
998
|
-
hintTitleTextWeight,
|
|
999
|
-
hintDescriptionTextSize,
|
|
910
|
+
hintDescription,
|
|
1000
911
|
hintDescriptionTextColor,
|
|
1001
|
-
|
|
912
|
+
hintDescriptionTextSize,
|
|
1002
913
|
hintDescriptionTextWeight,
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
914
|
+
hintDescriptionTextWrap,
|
|
915
|
+
hintTitle,
|
|
916
|
+
hintTitleTextColor,
|
|
917
|
+
hintTitleTextSize,
|
|
918
|
+
hintTitleTextWeight,
|
|
919
|
+
hintTitleTextWrap,
|
|
920
|
+
inputName,
|
|
1006
921
|
inputValue,
|
|
1007
922
|
maxFiles,
|
|
1008
923
|
maxSize,
|
|
1009
924
|
removeThumbText,
|
|
1010
|
-
|
|
1011
|
-
|
|
925
|
+
removeThumbTextColor,
|
|
926
|
+
removeThumbTextHoverColor,
|
|
927
|
+
removeThumbTextSize,
|
|
928
|
+
removeThumbTextWeight,
|
|
1012
929
|
showFilename,
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
930
|
+
size,
|
|
931
|
+
thumbColumn,
|
|
932
|
+
thumbNameTextColor,
|
|
933
|
+
thumbNameTextSize,
|
|
934
|
+
thumbNameTextWeight,
|
|
935
|
+
thumbNameTextWrap,
|
|
1016
936
|
onAddFiles,
|
|
1017
937
|
onDeleteFile
|
|
1018
938
|
} = props;
|
|
1019
|
-
const [fileError, setFileError] = React.useState('');
|
|
1020
|
-
const [fileIsLoading, setFileIsLoading] = React.useState(false);
|
|
1021
|
-
// State with instances of "File" type
|
|
1022
|
-
const [files, setFiles] = React.useState(inputValue ? castArray__default.default(inputValue) : []);
|
|
1023
939
|
|
|
1024
|
-
//
|
|
940
|
+
// TODO: delete react-final-form things out of here?
|
|
1025
941
|
const {
|
|
1026
942
|
change
|
|
1027
943
|
} = reactFinalForm.useForm();
|
|
944
|
+
const [fileError, setFileError] = React.useState('');
|
|
945
|
+
const [fileIsLoading, setFileIsLoading] = React.useState(false);
|
|
946
|
+
const filesList = React.useMemo(() => inputValue ? castArray__default.default(inputValue) : [], [inputValue]);
|
|
1028
947
|
const changeFormState = React.useCallback(newFiles => {
|
|
1029
948
|
// If max files in dropzone is 1 - return file as it self, else as array of files
|
|
1030
949
|
// ps: for old projects compatibility
|
|
1031
950
|
const toSave = dropzoneProps.maxFiles == 1 ? newFiles[0] : newFiles;
|
|
1032
951
|
change(inputName, toSave);
|
|
1033
952
|
return toSave;
|
|
1034
|
-
},
|
|
953
|
+
},
|
|
954
|
+
// If "inputName" will be changes, then it should be a different field
|
|
955
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
956
|
+
[dropzoneProps, change]);
|
|
957
|
+
|
|
958
|
+
//
|
|
959
|
+
const convertFiledValueAndSaveAsFiles = React.useCallback(async newInputValue => {
|
|
960
|
+
setFileIsLoading(true);
|
|
961
|
+
const newFiles = await convertToFiles(newInputValue, isPreviews);
|
|
962
|
+
changeFormState(newFiles);
|
|
963
|
+
setFileIsLoading(false);
|
|
964
|
+
return newFiles;
|
|
965
|
+
}, [isPreviews, changeFormState]);
|
|
966
|
+
|
|
967
|
+
// Delete file from dropzone
|
|
968
|
+
const removeFile = React.useCallback((event, index) => {
|
|
969
|
+
event.stopPropagation();
|
|
970
|
+
event.preventDefault();
|
|
971
|
+
const newFiles = [...filesList];
|
|
972
|
+
newFiles.splice(index, 1);
|
|
973
|
+
if (onDeleteFile) {
|
|
974
|
+
onDeleteFile(filesList[index], inputName);
|
|
975
|
+
}
|
|
976
|
+
changeFormState(newFiles);
|
|
977
|
+
},
|
|
978
|
+
// If "inputName" will be changes, then it should be a different field
|
|
979
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
980
|
+
[filesList, changeFormState, onDeleteFile]);
|
|
1035
981
|
|
|
1036
982
|
// Create dropzone options
|
|
1037
983
|
const {
|
|
1038
|
-
|
|
1039
|
-
|
|
984
|
+
getInputProps,
|
|
985
|
+
getRootProps
|
|
1040
986
|
} = reactDropzone.useDropzone({
|
|
987
|
+
maxFiles: maxFiles || 5,
|
|
1041
988
|
maxSize: maxSize || 10485760,
|
|
1042
989
|
// 10mb
|
|
1043
|
-
maxFiles: maxFiles || 5,
|
|
1044
990
|
// accept: { 'image/*': [] },
|
|
1045
991
|
...dropzoneProps,
|
|
1046
992
|
getFilesFromEvent: async event => {
|
|
1047
993
|
const result = await fileSelector.fromEvent(event);
|
|
1048
994
|
const newFiles = result.filter(item => item instanceof File);
|
|
1049
995
|
// Add exists and new files to accepted(or rejected)
|
|
1050
|
-
return [...
|
|
996
|
+
return [...filesList, ...newFiles];
|
|
1051
997
|
},
|
|
1052
|
-
onDropAccepted:
|
|
998
|
+
onDropAccepted: acceptedFiles => {
|
|
1053
999
|
// If dropped files has accepted and we need a previews
|
|
1054
1000
|
if (isPreviews) {
|
|
1055
1001
|
// Add preview to every file
|
|
@@ -1060,7 +1006,7 @@ const FileInputDropzone = /*#__PURE__*/React__default.default.memo(function File
|
|
|
1060
1006
|
});
|
|
1061
1007
|
}
|
|
1062
1008
|
// Save to form data (including empty when files are not valid)
|
|
1063
|
-
|
|
1009
|
+
const filesToSave = changeFormState(acceptedFiles);
|
|
1064
1010
|
setFileError('');
|
|
1065
1011
|
|
|
1066
1012
|
// Save DataURL for all files
|
|
@@ -1069,65 +1015,38 @@ const FileInputDropzone = /*#__PURE__*/React__default.default.memo(function File
|
|
|
1069
1015
|
});
|
|
1070
1016
|
// Save files to form values
|
|
1071
1017
|
Promise.all(readerPromisesList).then(() => {
|
|
1072
|
-
const filesToSave = changeFormState(acceptedFiles);
|
|
1073
1018
|
if (onAddFiles) {
|
|
1074
1019
|
onAddFiles(filesToSave, inputName);
|
|
1075
1020
|
}
|
|
1076
1021
|
});
|
|
1077
1022
|
},
|
|
1078
|
-
onDropRejected:
|
|
1023
|
+
onDropRejected: rejectedFiles => {
|
|
1079
1024
|
// If dropped files has rejected
|
|
1080
1025
|
if (rejectedFiles.length) {
|
|
1081
|
-
|
|
1026
|
+
let fileErrorMessage = 'Ошибка при добавлении файла';
|
|
1027
|
+
const firstFileErrorItem = rejectedFiles[0].errors[0];
|
|
1028
|
+
if (firstFileErrorItem) {
|
|
1029
|
+
if (firstFileErrorItem.code === reactDropzone.ErrorCode.TooManyFiles) {
|
|
1030
|
+
fileErrorMessage = `Максимальное количество файлов: ${maxFiles}`;
|
|
1031
|
+
} else {
|
|
1032
|
+
fileErrorMessage = firstFileErrorItem.message;
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1082
1035
|
// Show error
|
|
1083
|
-
setFileError(
|
|
1036
|
+
setFileError(fileErrorMessage);
|
|
1084
1037
|
} else {
|
|
1085
1038
|
// Else clean error
|
|
1086
1039
|
setFileError('');
|
|
1087
1040
|
}
|
|
1088
1041
|
}
|
|
1089
1042
|
});
|
|
1090
|
-
|
|
1091
|
-
// Delete file from dropzone
|
|
1092
|
-
const removeFile = React.useCallback((event, index) => {
|
|
1093
|
-
event.stopPropagation();
|
|
1094
|
-
event.preventDefault();
|
|
1095
|
-
const newFiles = [...files];
|
|
1096
|
-
newFiles.splice(index, 1);
|
|
1097
|
-
if (onDeleteFile) {
|
|
1098
|
-
onDeleteFile(files[index], inputName);
|
|
1099
|
-
}
|
|
1100
|
-
changeFormState(newFiles);
|
|
1101
|
-
}, [files, changeFormState, onDeleteFile]);
|
|
1102
|
-
|
|
1103
|
-
//
|
|
1104
|
-
const convertFiledValueAndSaveAsFiles = React.useCallback(async newInputValue => {
|
|
1105
|
-
setFileIsLoading(true);
|
|
1106
|
-
const newFiles = await convertToFiles(newInputValue, isPreviews);
|
|
1107
|
-
setFileIsLoading(false);
|
|
1108
|
-
setFiles(newFiles);
|
|
1109
|
-
return newFiles;
|
|
1110
|
-
}, [isPreviews]);
|
|
1111
1043
|
React.useEffect(() => {
|
|
1112
1044
|
// First time convert value to Files and save to local and form state
|
|
1113
|
-
convertFiledValueAndSaveAsFiles(inputValue)
|
|
1114
|
-
}, []); // eslint-disable-line
|
|
1115
|
-
|
|
1116
|
-
React.useEffect(() => {
|
|
1117
|
-
// Everytime convert value to Files and save to local state
|
|
1118
|
-
if (!inputValue) {
|
|
1119
|
-
setFiles([]);
|
|
1120
|
-
} else {
|
|
1121
|
-
convertFiledValueAndSaveAsFiles(inputValue);
|
|
1122
|
-
}
|
|
1123
|
-
// only "inputValue"
|
|
1124
|
-
}, [inputValue]); // eslint-disable-line
|
|
1125
|
-
|
|
1126
|
-
React.useEffect(() => {
|
|
1045
|
+
convertFiledValueAndSaveAsFiles(inputValue);
|
|
1127
1046
|
// Make sure to revoke the data uris to avoid memory leaks, will run on unmount
|
|
1128
|
-
return () =>
|
|
1129
|
-
|
|
1130
|
-
|
|
1047
|
+
return () => filesList.forEach(file => URL.revokeObjectURL(file?.preview));
|
|
1048
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1049
|
+
}, []);
|
|
1131
1050
|
const fillClass = useDeviceTargetClass.useDeviceTargetClass(props, {
|
|
1132
1051
|
prefix: 'fill_',
|
|
1133
1052
|
propsKey: 'fill'
|
|
@@ -1182,9 +1101,9 @@ const FileInputDropzone = /*#__PURE__*/React__default.default.memo(function File
|
|
|
1182
1101
|
name: inputName
|
|
1183
1102
|
})), /*#__PURE__*/React__default.default.createElement("div", {
|
|
1184
1103
|
className: clsx__default.default('form-dropzone__dropzone-wrapper', thumbColumn && `form-dropzone__dropzone-wrapper_column_${thumbColumn}`, fillClass, fillHoverClass, borderWidthClass, borderColorClass, borderColorHoverClass, borderTypeClass)
|
|
1185
|
-
},
|
|
1104
|
+
}, filesList.map((file, index) => /*#__PURE__*/React__default.default.createElement("aside", {
|
|
1186
1105
|
className: clsx__default.default('form-dropzone__thumb', fillClass, thumbDirectionClass, thumbBorderWidthClass, thumbBorderColorClass, thumbBorderColorHoverClass, thumbBorderTypeClass),
|
|
1187
|
-
key:
|
|
1106
|
+
key: file.id || `${file.name}_${index}`
|
|
1188
1107
|
}, isPreviews && !file.error && /*#__PURE__*/React__default.default.createElement("div", {
|
|
1189
1108
|
className: "form-dropzone__thumb-image"
|
|
1190
1109
|
}, /*#__PURE__*/React__default.default.createElement("img", {
|
|
@@ -1197,140 +1116,213 @@ const FileInputDropzone = /*#__PURE__*/React__default.default.memo(function File
|
|
|
1197
1116
|
})), file.error && /*#__PURE__*/React__default.default.createElement("div", null, /*#__PURE__*/React__default.default.createElement(Text.Text, {
|
|
1198
1117
|
size: thumbNameTextSize,
|
|
1199
1118
|
textColor: thumbNameTextColor,
|
|
1200
|
-
|
|
1201
|
-
|
|
1119
|
+
textWeight: thumbNameTextWeight,
|
|
1120
|
+
textWrap: thumbNameTextWrap
|
|
1202
1121
|
}, fileErrorText || file.error)), showFilename && /*#__PURE__*/React__default.default.createElement("div", {
|
|
1203
1122
|
className: "form-dropzone__thumb-name"
|
|
1204
1123
|
}, /*#__PURE__*/React__default.default.createElement(Text.Text, {
|
|
1124
|
+
className: "form-dropzone__thumb-name-inner",
|
|
1205
1125
|
size: thumbNameTextSize,
|
|
1206
1126
|
textColor: thumbNameTextColor,
|
|
1207
|
-
textWrap: thumbNameTextWrap,
|
|
1208
1127
|
textWeight: thumbNameTextWeight,
|
|
1209
|
-
|
|
1128
|
+
textWrap: thumbNameTextWrap
|
|
1210
1129
|
}, file.name)), fileIsLoading && /*#__PURE__*/React__default.default.createElement("div", {
|
|
1211
1130
|
className: "form-dropzone__thumb-loader"
|
|
1212
1131
|
}, /*#__PURE__*/React__default.default.createElement(Loader.Loader, {
|
|
1213
|
-
|
|
1132
|
+
width: "fill",
|
|
1214
1133
|
height: "fill",
|
|
1134
|
+
fill: "surfacePrimary",
|
|
1215
1135
|
itemFill: "surfaceItemAccent",
|
|
1216
|
-
set: "simple"
|
|
1217
|
-
width: "fill"
|
|
1136
|
+
set: "simple"
|
|
1218
1137
|
})), /*#__PURE__*/React__default.default.createElement("div", {
|
|
1219
1138
|
className: "form-dropzone__thumb-remove",
|
|
1220
|
-
onClick: event => removeFile(event,
|
|
1139
|
+
onClick: event => removeFile(event, index)
|
|
1221
1140
|
}, /*#__PURE__*/React__default.default.createElement(Text.Text, {
|
|
1141
|
+
className: "form-dropzone__thumb-remove-text",
|
|
1222
1142
|
size: removeThumbTextSize,
|
|
1223
1143
|
textColor: removeThumbTextColor,
|
|
1224
|
-
textWeight: removeThumbTextWeight,
|
|
1225
1144
|
textColorHover: removeThumbTextHoverColor,
|
|
1226
|
-
|
|
1227
|
-
}, removeThumbText || '
|
|
1145
|
+
textWeight: removeThumbTextWeight
|
|
1146
|
+
}, removeThumbText || 'Удалить')))), !filesList.length ? /*#__PURE__*/React__default.default.createElement("div", {
|
|
1228
1147
|
className: "form-dropzone__hint"
|
|
1229
1148
|
}, /*#__PURE__*/React__default.default.createElement(Text.Text, {
|
|
1149
|
+
className: "form-dropzone__hint-title",
|
|
1230
1150
|
size: hintTitleTextSize,
|
|
1231
1151
|
textColor: hintTitleTextColor,
|
|
1232
|
-
textWrap: hintTitleTextWrap,
|
|
1233
1152
|
textWeight: hintTitleTextWeight,
|
|
1234
|
-
|
|
1153
|
+
textWrap: hintTitleTextWrap
|
|
1235
1154
|
}, hintTitle || 'Select a file or drag in form'), /*#__PURE__*/React__default.default.createElement(Text.Text, {
|
|
1155
|
+
className: "form-dropzone__hint-text",
|
|
1236
1156
|
size: hintDescriptionTextSize,
|
|
1237
1157
|
textColor: hintDescriptionTextColor,
|
|
1238
|
-
textWrap: hintDescriptionTextWrap,
|
|
1239
1158
|
textWeight: hintDescriptionTextWeight,
|
|
1240
|
-
|
|
1159
|
+
textWrap: hintDescriptionTextWrap
|
|
1241
1160
|
}, hintDescription)) : /*#__PURE__*/React__default.default.createElement("div", {
|
|
1242
1161
|
className: "form-dropzone__hint form-dropzone__hint_type_add-more"
|
|
1243
1162
|
}, /*#__PURE__*/React__default.default.createElement(Text.Text, {
|
|
1163
|
+
className: "form-dropzone__hint-title",
|
|
1244
1164
|
size: hintTitleTextSize,
|
|
1245
1165
|
textColor: hintTitleTextColor,
|
|
1246
|
-
textWrap: hintTitleTextWrap,
|
|
1247
1166
|
textWeight: hintTitleTextWeight,
|
|
1248
|
-
|
|
1167
|
+
textWrap: hintTitleTextWrap
|
|
1249
1168
|
}, hintTitle || 'Select a file or drag in form'), /*#__PURE__*/React__default.default.createElement(Text.Text, {
|
|
1169
|
+
className: "form-dropzone__hint-text",
|
|
1250
1170
|
size: hintDescriptionTextSize,
|
|
1251
1171
|
textColor: hintDescriptionTextColor,
|
|
1252
|
-
textWrap: hintDescriptionTextWrap,
|
|
1253
1172
|
textWeight: hintDescriptionTextWeight,
|
|
1254
|
-
|
|
1173
|
+
textWrap: hintDescriptionTextWrap
|
|
1255
1174
|
}, hintDescription)))), fileError && /*#__PURE__*/React__default.default.createElement("div", {
|
|
1256
1175
|
className: "form-field__message"
|
|
1257
1176
|
}, /*#__PURE__*/React__default.default.createElement(Text.Text, {
|
|
1258
1177
|
className: "form-field__message-item form-field__message-item_type_message",
|
|
1259
1178
|
size: errorMessageTextSize,
|
|
1260
|
-
|
|
1261
|
-
|
|
1179
|
+
textColor: errorMessageTextColor,
|
|
1180
|
+
textWeight: errorMessageTextWeight
|
|
1262
1181
|
}, fileError)));
|
|
1263
1182
|
});
|
|
1264
1183
|
FileInputDropzone.propTypes = {
|
|
1184
|
+
isPreviews: PropTypes__default.default.bool,
|
|
1265
1185
|
dropzoneProps: PropTypes__default.default.object,
|
|
1266
1186
|
hintDescription: PropTypes__default.default.string,
|
|
1267
1187
|
hintTitle: PropTypes__default.default.string,
|
|
1268
1188
|
inputName: PropTypes__default.default.string,
|
|
1269
1189
|
inputValue: PropTypes__default.default.any,
|
|
1270
|
-
isPreviews: PropTypes__default.default.bool,
|
|
1271
|
-
showFilename: PropTypes__default.default.bool,
|
|
1272
|
-
loadingText: PropTypes__default.default.string,
|
|
1273
1190
|
metaError: PropTypes__default.default.string,
|
|
1274
1191
|
metaTouched: PropTypes__default.default.bool,
|
|
1275
1192
|
removeThumbText: PropTypes__default.default.string,
|
|
1193
|
+
showFilename: PropTypes__default.default.bool,
|
|
1276
1194
|
onAddFiles: PropTypes__default.default.func,
|
|
1277
1195
|
onDeleteFile: PropTypes__default.default.func
|
|
1278
1196
|
};
|
|
1197
|
+
async function getFileByURL(url) {
|
|
1198
|
+
try {
|
|
1199
|
+
const response = await axios__default.default({
|
|
1200
|
+
url: url,
|
|
1201
|
+
responseType: 'blob'
|
|
1202
|
+
});
|
|
1203
|
+
const blobObject = response.data;
|
|
1204
|
+
const dirtyFilename = response.headers['content-disposition']?.split('filename=')[1];
|
|
1205
|
+
// Remove double quotes
|
|
1206
|
+
let filename = dirtyFilename?.substring(1).slice(0, -1);
|
|
1207
|
+
if (!filename) {
|
|
1208
|
+
const typeParts = blobObject.type.split('/');
|
|
1209
|
+
const fileType = typeParts[typeParts.length - 1];
|
|
1210
|
+
filename = `${new Date().getTime()}.${fileType}`;
|
|
1211
|
+
}
|
|
1212
|
+
return new File([blobObject], filename, {
|
|
1213
|
+
type: blobObject.type
|
|
1214
|
+
});
|
|
1215
|
+
} catch (error) {
|
|
1216
|
+
console.log('error: ', error);
|
|
1217
|
+
return null;
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
async function convertToFiles(inputValue, isPreviews) {
|
|
1221
|
+
const newFiles = [];
|
|
1222
|
+
for (const value of castArray__default.default(inputValue)) {
|
|
1223
|
+
let newFile = null;
|
|
1224
|
+
|
|
1225
|
+
// Download image by url and save as File instance
|
|
1226
|
+
const isURL = typeof value === 'string' && value.includes('/');
|
|
1227
|
+
if (value.image || isURL) {
|
|
1228
|
+
newFile = await getFileByURL(value.image || value);
|
|
1229
|
+
if (newFile) {
|
|
1230
|
+
setFileDataURL(newFile);
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
// Convert dataURL to File instance
|
|
1235
|
+
if (value.dataURL) {
|
|
1236
|
+
newFile = common.createFileFromDataURL(value.name || value.path, value.dataURL);
|
|
1237
|
+
newFile.dataURL = value.dataURL;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
// Save new File to state
|
|
1241
|
+
if (newFile) {
|
|
1242
|
+
newFile.id = value.id;
|
|
1243
|
+
if (isPreviews) {
|
|
1244
|
+
newFile.preview = URL.createObjectURL(newFile);
|
|
1245
|
+
}
|
|
1246
|
+
newFiles.push(newFile);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
return newFiles;
|
|
1250
|
+
}
|
|
1251
|
+
function setFileDataURL(file, resolve) {
|
|
1252
|
+
resolve = resolve || (() => {});
|
|
1253
|
+
// Init reader and save his file
|
|
1254
|
+
const reader = new FileReader();
|
|
1255
|
+
reader._readedFile = file;
|
|
1256
|
+
|
|
1257
|
+
// Set handlers
|
|
1258
|
+
reader.onabort = () => resolve();
|
|
1259
|
+
reader.onerror = () => resolve();
|
|
1260
|
+
reader.onload = event => {
|
|
1261
|
+
event.target._readedFile.dataURL = reader.result;
|
|
1262
|
+
resolve();
|
|
1263
|
+
};
|
|
1264
|
+
// Run reader
|
|
1265
|
+
if (file instanceof File) {
|
|
1266
|
+
reader.readAsDataURL(file);
|
|
1267
|
+
} else {
|
|
1268
|
+
resolve();
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1279
1271
|
|
|
1280
1272
|
const FileInput = /*#__PURE__*/React__default.default.memo(function FileInput(props) {
|
|
1281
1273
|
const {
|
|
1282
|
-
|
|
1283
|
-
shape,
|
|
1284
|
-
size,
|
|
1274
|
+
width,
|
|
1285
1275
|
borderWidth,
|
|
1276
|
+
isPreviews,
|
|
1277
|
+
isRequired,
|
|
1286
1278
|
borderColorHover,
|
|
1287
1279
|
borderType,
|
|
1288
|
-
label,
|
|
1289
|
-
thumbBorderWidth,
|
|
1290
|
-
thumbBorderColor,
|
|
1291
|
-
thumbBorderColorHover,
|
|
1292
|
-
thumbBorderType,
|
|
1293
|
-
removeThumbTextHoverColor,
|
|
1294
|
-
labelTextColor,
|
|
1295
|
-
fill,
|
|
1296
|
-
fillHover,
|
|
1297
1280
|
className,
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
thumbNameTextWeight,
|
|
1303
|
-
removeThumbTextSize,
|
|
1304
|
-
removeThumbTextColor,
|
|
1305
|
-
removeThumbTextWeight,
|
|
1306
|
-
hintTitle,
|
|
1307
|
-
errorMessageTextSize,
|
|
1281
|
+
classNameGroupItem,
|
|
1282
|
+
dropzoneProps,
|
|
1283
|
+
errorMessageTextColor = 'errorTextPrimary',
|
|
1284
|
+
errorMessageTextSize = 's',
|
|
1308
1285
|
errorMessageTextWeight,
|
|
1309
|
-
errorMessageTextColor,
|
|
1310
1286
|
fieldProps,
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
hintDescriptionTextSize,
|
|
1287
|
+
fileErrorText,
|
|
1288
|
+
fill,
|
|
1289
|
+
fillHover,
|
|
1290
|
+
hintDescription,
|
|
1316
1291
|
hintDescriptionTextColor,
|
|
1317
|
-
|
|
1292
|
+
hintDescriptionTextSize,
|
|
1318
1293
|
hintDescriptionTextWeight,
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1294
|
+
hintDescriptionTextWrap,
|
|
1295
|
+
hintTitle,
|
|
1296
|
+
hintTitleTextColor,
|
|
1297
|
+
hintTitleTextSize,
|
|
1298
|
+
hintTitleTextWeight,
|
|
1299
|
+
hintTitleTextWrap,
|
|
1300
|
+
label,
|
|
1301
|
+
labelTextColor,
|
|
1325
1302
|
maxFiles,
|
|
1326
1303
|
maxSize,
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1304
|
+
name,
|
|
1305
|
+
removeThumbText,
|
|
1306
|
+
removeThumbTextColor,
|
|
1307
|
+
removeThumbTextHoverColor,
|
|
1308
|
+
removeThumbTextSize,
|
|
1309
|
+
removeThumbTextWeight,
|
|
1310
|
+
shape,
|
|
1311
|
+
showFilename,
|
|
1312
|
+
showMessage,
|
|
1313
|
+
size,
|
|
1314
|
+
thumbBorderColor,
|
|
1315
|
+
thumbBorderColorHover,
|
|
1316
|
+
thumbBorderType,
|
|
1317
|
+
thumbBorderWidth,
|
|
1318
|
+
thumbColumn = 1,
|
|
1319
|
+
thumbDirection = 'vertical',
|
|
1320
|
+
thumbNameTextColor,
|
|
1321
|
+
thumbNameTextSize,
|
|
1322
|
+
thumbNameTextWeight,
|
|
1323
|
+
thumbNameTextWrap,
|
|
1330
1324
|
onAddFiles,
|
|
1331
|
-
onDeleteFile
|
|
1332
|
-
classNameGroupItem,
|
|
1333
|
-
width
|
|
1325
|
+
onDeleteFile
|
|
1334
1326
|
} = props;
|
|
1335
1327
|
return /*#__PURE__*/React__default.default.createElement(reactFinalForm.Field, {
|
|
1336
1328
|
name: name
|
|
@@ -1356,8 +1348,8 @@ const FileInput = /*#__PURE__*/React__default.default.memo(function FileInput(pr
|
|
|
1356
1348
|
meta: meta
|
|
1357
1349
|
});
|
|
1358
1350
|
const updatedInputProps = useValidationAppearanceInputProps({
|
|
1359
|
-
|
|
1360
|
-
|
|
1351
|
+
inputProps: props,
|
|
1352
|
+
validationStateKey: isErrorState ? errorKey : 'success'
|
|
1361
1353
|
});
|
|
1362
1354
|
|
|
1363
1355
|
/** TODO:
|
|
@@ -1365,82 +1357,77 @@ const FileInput = /*#__PURE__*/React__default.default.memo(function FileInput(pr
|
|
|
1365
1357
|
*/
|
|
1366
1358
|
return /*#__PURE__*/React__default.default.createElement(FieldWrapper, Object.assign({
|
|
1367
1359
|
className: clsx__default.default('form-field_type_dropzone', 'form__item_type_dropzone', classNameGroupItem),
|
|
1360
|
+
width: width,
|
|
1361
|
+
labelTextColor: labelTextColor,
|
|
1362
|
+
errorKey: errorKey,
|
|
1363
|
+
errorMessage: errorMessage,
|
|
1368
1364
|
fieldClassName: "form-dropzone",
|
|
1369
1365
|
inputName: input.name,
|
|
1370
1366
|
inputValue: input.value,
|
|
1371
|
-
isRequired: isRequired,
|
|
1372
1367
|
label: label,
|
|
1373
|
-
labelTextColor: labelTextColor,
|
|
1374
1368
|
metaActive: meta.active,
|
|
1375
1369
|
metaError: meta.error,
|
|
1376
1370
|
metaTouched: meta.touched,
|
|
1377
1371
|
showMessage: showMessage,
|
|
1378
|
-
width: width,
|
|
1379
1372
|
isErrorState: isErrorState,
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
errorMessage: errorMessage
|
|
1373
|
+
isRequired: isRequired,
|
|
1374
|
+
isValidState: isValidState
|
|
1383
1375
|
}, fieldProps), /*#__PURE__*/React__default.default.createElement(FileInputDropzone, {
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1376
|
+
className: className,
|
|
1377
|
+
fill: fill,
|
|
1378
|
+
fillHover: fillHover,
|
|
1387
1379
|
borderWidth: borderWidth,
|
|
1388
1380
|
borderColor: updatedInputProps.borderColor,
|
|
1389
1381
|
borderColorHover: borderColorHover,
|
|
1390
1382
|
borderType: borderType,
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1383
|
+
dropzoneProps: dropzoneProps,
|
|
1384
|
+
errorMessageTextColor: errorMessageTextColor,
|
|
1385
|
+
errorMessageTextSize: errorMessageTextSize,
|
|
1386
|
+
errorMessageWeight: errorMessageTextWeight,
|
|
1395
1387
|
fileErrorText: fileErrorText,
|
|
1396
|
-
|
|
1397
|
-
|
|
1388
|
+
hintDescription: hintDescription,
|
|
1389
|
+
hintDescriptionTextColor: hintDescriptionTextColor,
|
|
1390
|
+
hintDescriptionTextSize: hintDescriptionTextSize,
|
|
1391
|
+
hintDescriptionTextWeight: hintDescriptionTextWeight,
|
|
1392
|
+
hintDescriptionTextWrap: hintDescriptionTextWrap,
|
|
1393
|
+
hintTitle: hintTitle,
|
|
1394
|
+
hintTitleTextColor: hintTitleTextColor,
|
|
1395
|
+
hintTitleTextSize: hintTitleTextSize,
|
|
1396
|
+
hintTitleTextWeight: hintTitleTextWeight,
|
|
1397
|
+
hintTitleTextWrap: hintTitleTextWrap,
|
|
1398
|
+
inputName: input.name,
|
|
1399
|
+
inputValue: input.value,
|
|
1398
1400
|
maxFiles: maxFiles,
|
|
1399
1401
|
maxSize: maxSize,
|
|
1402
|
+
metaError: meta.error,
|
|
1403
|
+
metaTouched: meta.touched,
|
|
1404
|
+
removeThumbText: removeThumbText,
|
|
1405
|
+
removeThumbTextColor: removeThumbTextColor,
|
|
1400
1406
|
removeThumbTextHoverColor: removeThumbTextHoverColor,
|
|
1401
|
-
|
|
1402
|
-
|
|
1407
|
+
removeThumbTextSize: removeThumbTextSize,
|
|
1408
|
+
removeThumbTextWeight: removeThumbTextWeight,
|
|
1409
|
+
shape: shape,
|
|
1410
|
+
showFilename: showFilename,
|
|
1411
|
+
size: size,
|
|
1412
|
+
thumbBorderColor: thumbBorderColor,
|
|
1413
|
+
thumbBorderColorHover: thumbBorderColorHover,
|
|
1414
|
+
thumbBorderType: thumbBorderType,
|
|
1415
|
+
thumbBorderWidth: thumbBorderWidth,
|
|
1403
1416
|
thumbColumn: thumbColumn,
|
|
1404
1417
|
thumbDirection: thumbDirection,
|
|
1405
|
-
inputName: input.name,
|
|
1406
|
-
inputValue: input.value,
|
|
1407
|
-
thumbNameTextSize: thumbNameTextSize,
|
|
1408
1418
|
thumbNameTextColor: thumbNameTextColor,
|
|
1409
|
-
|
|
1419
|
+
thumbNameTextSize: thumbNameTextSize,
|
|
1410
1420
|
thumbNameTextWeight: thumbNameTextWeight,
|
|
1411
|
-
|
|
1412
|
-
hintTitleTextColor: hintTitleTextColor,
|
|
1413
|
-
hintTitleTextWrap: hintTitleTextWrap,
|
|
1414
|
-
hintTitleTextWeight: hintTitleTextWeight,
|
|
1415
|
-
removeThumbTextSize: removeThumbTextSize,
|
|
1416
|
-
removeThumbTextColor: removeThumbTextColor,
|
|
1417
|
-
removeThumbTextWeight: removeThumbTextWeight,
|
|
1418
|
-
hintDescriptionTextSize: hintDescriptionTextSize,
|
|
1419
|
-
hintDescriptionTextColor: hintDescriptionTextColor,
|
|
1420
|
-
hintDescriptionTextWrap: hintDescriptionTextWrap,
|
|
1421
|
-
hintDescriptionTextWeight: hintDescriptionTextWeight,
|
|
1422
|
-
errorMessageTextSize: errorMessageTextSize,
|
|
1423
|
-
errorMessageWeight: errorMessageTextWeight,
|
|
1424
|
-
errorMessageTextColor: errorMessageTextColor,
|
|
1421
|
+
thumbNameTextWrap: thumbNameTextWrap,
|
|
1425
1422
|
isPreviews: isPreviews,
|
|
1426
|
-
shape: shape,
|
|
1427
|
-
showFilename: showFilename,
|
|
1428
|
-
metaError: meta.error,
|
|
1429
|
-
metaTouched: meta.touched,
|
|
1430
|
-
removeThumbText: removeThumbText,
|
|
1431
1423
|
onAddFiles: onAddFiles,
|
|
1432
1424
|
onDeleteFile: onDeleteFile
|
|
1433
1425
|
}));
|
|
1434
1426
|
});
|
|
1435
1427
|
});
|
|
1436
|
-
FileInput.defaultProps = {
|
|
1437
|
-
errorMessageTextSize: 's',
|
|
1438
|
-
errorMessageTextColor: 'errorTextPrimary',
|
|
1439
|
-
thumbColumn: 1,
|
|
1440
|
-
thumbDirection: 'vertical'
|
|
1441
|
-
};
|
|
1442
1428
|
FileInput.propTypes = {
|
|
1443
|
-
|
|
1429
|
+
isPreviews: PropTypes__default.default.bool,
|
|
1430
|
+
isRequired: PropTypes__default.default.bool,
|
|
1444
1431
|
className: PropTypes__default.default.string,
|
|
1445
1432
|
classNameGroupItem: PropTypes__default.default.string,
|
|
1446
1433
|
classNameInput: PropTypes__default.default.string,
|
|
@@ -1449,11 +1436,10 @@ FileInput.propTypes = {
|
|
|
1449
1436
|
hintDescription: PropTypes__default.default.string,
|
|
1450
1437
|
hintTitle: PropTypes__default.default.string,
|
|
1451
1438
|
inputClass: PropTypes__default.default.string,
|
|
1452
|
-
isPreviews: PropTypes__default.default.bool,
|
|
1453
|
-
isRequired: PropTypes__default.default.bool,
|
|
1454
|
-
showFilename: PropTypes__default.default.bool,
|
|
1455
1439
|
label: PropTypes__default.default.any,
|
|
1440
|
+
name: PropTypes__default.default.string.isRequired,
|
|
1456
1441
|
removeThumbText: PropTypes__default.default.string,
|
|
1442
|
+
showFilename: PropTypes__default.default.bool,
|
|
1457
1443
|
onAddFiles: PropTypes__default.default.func,
|
|
1458
1444
|
onDeleteFile: PropTypes__default.default.func
|
|
1459
1445
|
};
|
|
@@ -2866,7 +2852,7 @@ const FinalForm = /*#__PURE__*/React__default.default.forwardRef(function FinalF
|
|
|
2866
2852
|
values: true
|
|
2867
2853
|
},
|
|
2868
2854
|
onChange: onChangeFormValues
|
|
2869
|
-
}), Boolean(Object.keys(config).length) && /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, renderFieldsWrapper(
|
|
2855
|
+
}), Boolean(Object.keys(config).length) && /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, renderFieldsWrapper(/*#__PURE__*/React__default.default.createElement(Group$1.Group, {
|
|
2870
2856
|
className: "form__wrapper",
|
|
2871
2857
|
direction: "vertical",
|
|
2872
2858
|
gap: fieldsGap || groupGap,
|