@itcase/forms 1.0.67 → 1.0.69
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 +271 -282
- package/dist/itcase-forms.esm.js +271 -282
- package/package.json +1 -1
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,214 @@ 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
|
+
filename = url.split('/').at(-1);
|
|
1209
|
+
// const typeParts = blobObject.type.split('/')
|
|
1210
|
+
// const fileType = typeParts[typeParts.length - 1]
|
|
1211
|
+
// filename = `${new Date().getTime()}.${fileType}`
|
|
1212
|
+
}
|
|
1213
|
+
return new File([blobObject], filename, {
|
|
1214
|
+
type: blobObject.type
|
|
1215
|
+
});
|
|
1216
|
+
} catch (error) {
|
|
1217
|
+
console.log('error: ', error);
|
|
1218
|
+
return null;
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
async function convertToFiles(inputValue, isPreviews) {
|
|
1222
|
+
const newFiles = [];
|
|
1223
|
+
for (const value of castArray__default.default(inputValue)) {
|
|
1224
|
+
let newFile = null;
|
|
1225
|
+
|
|
1226
|
+
// Download image by url and save as File instance
|
|
1227
|
+
const isURL = typeof value === 'string' && value.includes('/');
|
|
1228
|
+
if (value.image || isURL) {
|
|
1229
|
+
newFile = await getFileByURL(value.image || value);
|
|
1230
|
+
if (newFile) {
|
|
1231
|
+
setFileDataURL(newFile);
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
// Convert dataURL to File instance
|
|
1236
|
+
if (value.dataURL) {
|
|
1237
|
+
newFile = common.createFileFromDataURL(value.name || value.path, value.dataURL);
|
|
1238
|
+
newFile.dataURL = value.dataURL;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
// Save new File to state
|
|
1242
|
+
if (newFile) {
|
|
1243
|
+
newFile.id = value.id;
|
|
1244
|
+
if (isPreviews) {
|
|
1245
|
+
newFile.preview = URL.createObjectURL(newFile);
|
|
1246
|
+
}
|
|
1247
|
+
newFiles.push(newFile);
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
return newFiles;
|
|
1251
|
+
}
|
|
1252
|
+
function setFileDataURL(file, resolve) {
|
|
1253
|
+
resolve = resolve || (() => {});
|
|
1254
|
+
// Init reader and save his file
|
|
1255
|
+
const reader = new FileReader();
|
|
1256
|
+
reader._readedFile = file;
|
|
1257
|
+
|
|
1258
|
+
// Set handlers
|
|
1259
|
+
reader.onabort = () => resolve();
|
|
1260
|
+
reader.onerror = () => resolve();
|
|
1261
|
+
reader.onload = event => {
|
|
1262
|
+
event.target._readedFile.dataURL = reader.result;
|
|
1263
|
+
resolve();
|
|
1264
|
+
};
|
|
1265
|
+
// Run reader
|
|
1266
|
+
if (file instanceof File) {
|
|
1267
|
+
reader.readAsDataURL(file);
|
|
1268
|
+
} else {
|
|
1269
|
+
resolve();
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1279
1272
|
|
|
1280
1273
|
const FileInput = /*#__PURE__*/React__default.default.memo(function FileInput(props) {
|
|
1281
1274
|
const {
|
|
1282
|
-
|
|
1283
|
-
shape,
|
|
1284
|
-
size,
|
|
1275
|
+
width,
|
|
1285
1276
|
borderWidth,
|
|
1277
|
+
isPreviews,
|
|
1278
|
+
isRequired,
|
|
1286
1279
|
borderColorHover,
|
|
1287
1280
|
borderType,
|
|
1288
|
-
label,
|
|
1289
|
-
thumbBorderWidth,
|
|
1290
|
-
thumbBorderColor,
|
|
1291
|
-
thumbBorderColorHover,
|
|
1292
|
-
thumbBorderType,
|
|
1293
|
-
removeThumbTextHoverColor,
|
|
1294
|
-
labelTextColor,
|
|
1295
|
-
fill,
|
|
1296
|
-
fillHover,
|
|
1297
1281
|
className,
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
thumbNameTextWeight,
|
|
1303
|
-
removeThumbTextSize,
|
|
1304
|
-
removeThumbTextColor,
|
|
1305
|
-
removeThumbTextWeight,
|
|
1306
|
-
hintTitle,
|
|
1307
|
-
errorMessageTextSize,
|
|
1282
|
+
classNameGroupItem,
|
|
1283
|
+
dropzoneProps,
|
|
1284
|
+
errorMessageTextColor = 'errorTextPrimary',
|
|
1285
|
+
errorMessageTextSize = 's',
|
|
1308
1286
|
errorMessageTextWeight,
|
|
1309
|
-
errorMessageTextColor,
|
|
1310
1287
|
fieldProps,
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
hintDescriptionTextSize,
|
|
1288
|
+
fileErrorText,
|
|
1289
|
+
fill,
|
|
1290
|
+
fillHover,
|
|
1291
|
+
hintDescription,
|
|
1316
1292
|
hintDescriptionTextColor,
|
|
1317
|
-
|
|
1293
|
+
hintDescriptionTextSize,
|
|
1318
1294
|
hintDescriptionTextWeight,
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1295
|
+
hintDescriptionTextWrap,
|
|
1296
|
+
hintTitle,
|
|
1297
|
+
hintTitleTextColor,
|
|
1298
|
+
hintTitleTextSize,
|
|
1299
|
+
hintTitleTextWeight,
|
|
1300
|
+
hintTitleTextWrap,
|
|
1301
|
+
label,
|
|
1302
|
+
labelTextColor,
|
|
1325
1303
|
maxFiles,
|
|
1326
1304
|
maxSize,
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1305
|
+
name,
|
|
1306
|
+
removeThumbText,
|
|
1307
|
+
removeThumbTextColor,
|
|
1308
|
+
removeThumbTextHoverColor,
|
|
1309
|
+
removeThumbTextSize,
|
|
1310
|
+
removeThumbTextWeight,
|
|
1311
|
+
shape,
|
|
1312
|
+
showFilename,
|
|
1313
|
+
showMessage,
|
|
1314
|
+
size,
|
|
1315
|
+
thumbBorderColor,
|
|
1316
|
+
thumbBorderColorHover,
|
|
1317
|
+
thumbBorderType,
|
|
1318
|
+
thumbBorderWidth,
|
|
1319
|
+
thumbColumn = 1,
|
|
1320
|
+
thumbDirection = 'vertical',
|
|
1321
|
+
thumbNameTextColor,
|
|
1322
|
+
thumbNameTextSize,
|
|
1323
|
+
thumbNameTextWeight,
|
|
1324
|
+
thumbNameTextWrap,
|
|
1330
1325
|
onAddFiles,
|
|
1331
|
-
onDeleteFile
|
|
1332
|
-
classNameGroupItem,
|
|
1333
|
-
width
|
|
1326
|
+
onDeleteFile
|
|
1334
1327
|
} = props;
|
|
1335
1328
|
return /*#__PURE__*/React__default.default.createElement(reactFinalForm.Field, {
|
|
1336
1329
|
name: name
|
|
@@ -1356,8 +1349,8 @@ const FileInput = /*#__PURE__*/React__default.default.memo(function FileInput(pr
|
|
|
1356
1349
|
meta: meta
|
|
1357
1350
|
});
|
|
1358
1351
|
const updatedInputProps = useValidationAppearanceInputProps({
|
|
1359
|
-
|
|
1360
|
-
|
|
1352
|
+
inputProps: props,
|
|
1353
|
+
validationStateKey: isErrorState ? errorKey : 'success'
|
|
1361
1354
|
});
|
|
1362
1355
|
|
|
1363
1356
|
/** TODO:
|
|
@@ -1365,82 +1358,77 @@ const FileInput = /*#__PURE__*/React__default.default.memo(function FileInput(pr
|
|
|
1365
1358
|
*/
|
|
1366
1359
|
return /*#__PURE__*/React__default.default.createElement(FieldWrapper, Object.assign({
|
|
1367
1360
|
className: clsx__default.default('form-field_type_dropzone', 'form__item_type_dropzone', classNameGroupItem),
|
|
1361
|
+
width: width,
|
|
1362
|
+
labelTextColor: labelTextColor,
|
|
1363
|
+
errorKey: errorKey,
|
|
1364
|
+
errorMessage: errorMessage,
|
|
1368
1365
|
fieldClassName: "form-dropzone",
|
|
1369
1366
|
inputName: input.name,
|
|
1370
1367
|
inputValue: input.value,
|
|
1371
|
-
isRequired: isRequired,
|
|
1372
1368
|
label: label,
|
|
1373
|
-
labelTextColor: labelTextColor,
|
|
1374
1369
|
metaActive: meta.active,
|
|
1375
1370
|
metaError: meta.error,
|
|
1376
1371
|
metaTouched: meta.touched,
|
|
1377
1372
|
showMessage: showMessage,
|
|
1378
|
-
width: width,
|
|
1379
1373
|
isErrorState: isErrorState,
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
errorMessage: errorMessage
|
|
1374
|
+
isRequired: isRequired,
|
|
1375
|
+
isValidState: isValidState
|
|
1383
1376
|
}, fieldProps), /*#__PURE__*/React__default.default.createElement(FileInputDropzone, {
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1377
|
+
className: className,
|
|
1378
|
+
fill: fill,
|
|
1379
|
+
fillHover: fillHover,
|
|
1387
1380
|
borderWidth: borderWidth,
|
|
1388
1381
|
borderColor: updatedInputProps.borderColor,
|
|
1389
1382
|
borderColorHover: borderColorHover,
|
|
1390
1383
|
borderType: borderType,
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1384
|
+
dropzoneProps: dropzoneProps,
|
|
1385
|
+
errorMessageTextColor: errorMessageTextColor,
|
|
1386
|
+
errorMessageTextSize: errorMessageTextSize,
|
|
1387
|
+
errorMessageWeight: errorMessageTextWeight,
|
|
1395
1388
|
fileErrorText: fileErrorText,
|
|
1396
|
-
|
|
1397
|
-
|
|
1389
|
+
hintDescription: hintDescription,
|
|
1390
|
+
hintDescriptionTextColor: hintDescriptionTextColor,
|
|
1391
|
+
hintDescriptionTextSize: hintDescriptionTextSize,
|
|
1392
|
+
hintDescriptionTextWeight: hintDescriptionTextWeight,
|
|
1393
|
+
hintDescriptionTextWrap: hintDescriptionTextWrap,
|
|
1394
|
+
hintTitle: hintTitle,
|
|
1395
|
+
hintTitleTextColor: hintTitleTextColor,
|
|
1396
|
+
hintTitleTextSize: hintTitleTextSize,
|
|
1397
|
+
hintTitleTextWeight: hintTitleTextWeight,
|
|
1398
|
+
hintTitleTextWrap: hintTitleTextWrap,
|
|
1399
|
+
inputName: input.name,
|
|
1400
|
+
inputValue: input.value,
|
|
1398
1401
|
maxFiles: maxFiles,
|
|
1399
1402
|
maxSize: maxSize,
|
|
1403
|
+
metaError: meta.error,
|
|
1404
|
+
metaTouched: meta.touched,
|
|
1405
|
+
removeThumbText: removeThumbText,
|
|
1406
|
+
removeThumbTextColor: removeThumbTextColor,
|
|
1400
1407
|
removeThumbTextHoverColor: removeThumbTextHoverColor,
|
|
1401
|
-
|
|
1402
|
-
|
|
1408
|
+
removeThumbTextSize: removeThumbTextSize,
|
|
1409
|
+
removeThumbTextWeight: removeThumbTextWeight,
|
|
1410
|
+
shape: shape,
|
|
1411
|
+
showFilename: showFilename,
|
|
1412
|
+
size: size,
|
|
1413
|
+
thumbBorderColor: thumbBorderColor,
|
|
1414
|
+
thumbBorderColorHover: thumbBorderColorHover,
|
|
1415
|
+
thumbBorderType: thumbBorderType,
|
|
1416
|
+
thumbBorderWidth: thumbBorderWidth,
|
|
1403
1417
|
thumbColumn: thumbColumn,
|
|
1404
1418
|
thumbDirection: thumbDirection,
|
|
1405
|
-
inputName: input.name,
|
|
1406
|
-
inputValue: input.value,
|
|
1407
|
-
thumbNameTextSize: thumbNameTextSize,
|
|
1408
1419
|
thumbNameTextColor: thumbNameTextColor,
|
|
1409
|
-
|
|
1420
|
+
thumbNameTextSize: thumbNameTextSize,
|
|
1410
1421
|
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,
|
|
1422
|
+
thumbNameTextWrap: thumbNameTextWrap,
|
|
1425
1423
|
isPreviews: isPreviews,
|
|
1426
|
-
shape: shape,
|
|
1427
|
-
showFilename: showFilename,
|
|
1428
|
-
metaError: meta.error,
|
|
1429
|
-
metaTouched: meta.touched,
|
|
1430
|
-
removeThumbText: removeThumbText,
|
|
1431
1424
|
onAddFiles: onAddFiles,
|
|
1432
1425
|
onDeleteFile: onDeleteFile
|
|
1433
1426
|
}));
|
|
1434
1427
|
});
|
|
1435
1428
|
});
|
|
1436
|
-
FileInput.defaultProps = {
|
|
1437
|
-
errorMessageTextSize: 's',
|
|
1438
|
-
errorMessageTextColor: 'errorTextPrimary',
|
|
1439
|
-
thumbColumn: 1,
|
|
1440
|
-
thumbDirection: 'vertical'
|
|
1441
|
-
};
|
|
1442
1429
|
FileInput.propTypes = {
|
|
1443
|
-
|
|
1430
|
+
isPreviews: PropTypes__default.default.bool,
|
|
1431
|
+
isRequired: PropTypes__default.default.bool,
|
|
1444
1432
|
className: PropTypes__default.default.string,
|
|
1445
1433
|
classNameGroupItem: PropTypes__default.default.string,
|
|
1446
1434
|
classNameInput: PropTypes__default.default.string,
|
|
@@ -1449,11 +1437,10 @@ FileInput.propTypes = {
|
|
|
1449
1437
|
hintDescription: PropTypes__default.default.string,
|
|
1450
1438
|
hintTitle: PropTypes__default.default.string,
|
|
1451
1439
|
inputClass: PropTypes__default.default.string,
|
|
1452
|
-
isPreviews: PropTypes__default.default.bool,
|
|
1453
|
-
isRequired: PropTypes__default.default.bool,
|
|
1454
|
-
showFilename: PropTypes__default.default.bool,
|
|
1455
1440
|
label: PropTypes__default.default.any,
|
|
1441
|
+
name: PropTypes__default.default.string.isRequired,
|
|
1456
1442
|
removeThumbText: PropTypes__default.default.string,
|
|
1443
|
+
showFilename: PropTypes__default.default.bool,
|
|
1457
1444
|
onAddFiles: PropTypes__default.default.func,
|
|
1458
1445
|
onDeleteFile: PropTypes__default.default.func
|
|
1459
1446
|
};
|
|
@@ -2015,10 +2002,11 @@ function getDefaultValue(options, selectValue) {
|
|
|
2015
2002
|
}
|
|
2016
2003
|
const SelectField = /*#__PURE__*/React__default.default.memo(function SelectField(props) {
|
|
2017
2004
|
const {
|
|
2018
|
-
classNameGroupItem,
|
|
2019
|
-
fieldProps,
|
|
2020
2005
|
isDisabled,
|
|
2021
2006
|
isRequired,
|
|
2007
|
+
classNameGroupItem,
|
|
2008
|
+
fieldProps,
|
|
2009
|
+
initialValue,
|
|
2022
2010
|
name,
|
|
2023
2011
|
options,
|
|
2024
2012
|
selectProps,
|
|
@@ -2028,7 +2016,8 @@ const SelectField = /*#__PURE__*/React__default.default.memo(function SelectFiel
|
|
|
2028
2016
|
onInputChange
|
|
2029
2017
|
} = props;
|
|
2030
2018
|
return /*#__PURE__*/React__default.default.createElement(reactFinalForm.Field, {
|
|
2031
|
-
name: name
|
|
2019
|
+
name: name,
|
|
2020
|
+
initialValue: initialValue
|
|
2032
2021
|
}, function Render({
|
|
2033
2022
|
input,
|
|
2034
2023
|
meta
|