@pisell/materials 6.0.3 → 6.0.5
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/build/lowcode/assets-daily.json +11 -11
- package/build/lowcode/assets-dev.json +2 -2
- package/build/lowcode/assets-prod.json +11 -11
- package/build/lowcode/meta.js +1 -1
- package/build/lowcode/render/default/view.js +3 -3
- package/build/lowcode/view.js +3 -3
- package/es/components/dataSourceComponents/fields/Input.Phone/WithMode.js +11 -9
- package/es/components/dataSourceComponents/fields/Upload/BaseUpload.js +68 -28
- package/es/components/dataSourceComponents/fields/Upload/utils.d.ts +1 -0
- package/es/components/dataSourceComponents/fields/Upload/utils.js +24 -0
- package/es/components/select/index.js +1 -1
- package/lib/components/dataSourceComponents/fields/Input.Phone/WithMode.js +8 -14
- package/lib/components/dataSourceComponents/fields/Upload/BaseUpload.js +134 -77
- package/lib/components/dataSourceComponents/fields/Upload/utils.d.ts +1 -0
- package/lib/components/dataSourceComponents/fields/Upload/utils.js +24 -2
- package/lib/components/select/index.js +1 -1
- package/package.json +3 -3
|
@@ -109,15 +109,17 @@ var PhoneInput = function PhoneInput(_ref) {
|
|
|
109
109
|
},
|
|
110
110
|
onBlur: handleBlur,
|
|
111
111
|
popupMatchSelectWidth: false,
|
|
112
|
-
optionLabelProp: "
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
112
|
+
optionLabelProp: "inputValue",
|
|
113
|
+
optionFilterProp: "label",
|
|
114
|
+
showSearch: true,
|
|
115
|
+
options: countries.map(function (country) {
|
|
116
|
+
return {
|
|
117
|
+
value: country.code,
|
|
118
|
+
label: "".concat(translationOriginal(country.name), " (").concat(country.prefix, ")"),
|
|
119
|
+
inputValue: country.prefix
|
|
120
|
+
};
|
|
121
|
+
})
|
|
122
|
+
}), /*#__PURE__*/React.createElement(Input, _extends({}, props, {
|
|
121
123
|
status: status,
|
|
122
124
|
type: "tel",
|
|
123
125
|
value: phoneNumber,
|
|
@@ -22,7 +22,7 @@ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefine
|
|
|
22
22
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
23
23
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
24
24
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
25
|
-
import React, { useState, useMemo, useCallback, useEffect } from 'react';
|
|
25
|
+
import React, { useState, useMemo, useCallback, useEffect, useRef } from 'react';
|
|
26
26
|
import { PlusOutlined } from '@ant-design/icons';
|
|
27
27
|
import { Upload, Image } from 'antd';
|
|
28
28
|
import { useDebounceFn, useMemoizedFn } from 'ahooks';
|
|
@@ -34,7 +34,7 @@ import PisellUpload from "../../../pisellUpload";
|
|
|
34
34
|
import useEngineContext from "../../../../hooks/useEngineContext";
|
|
35
35
|
import { getText } from "../../../../locales";
|
|
36
36
|
import { DEFAULT_MAX_COUNT, SUPPORTED_LANGUAGES } from "./constants";
|
|
37
|
-
import { getPointSuffix, checkFileCount, getFileType, getMediaMetadata, getFileMetadataParams, getDefaultFileList, createMultilingualData, createMultilingualFileList } from "./utils";
|
|
37
|
+
import { getPointSuffix, checkFileCount, getFileType, getMediaMetadata, getFileMetadataParams, getDefaultFileList, createMultilingualData, createMultilingualFileList, isValueEqual } from "./utils";
|
|
38
38
|
import fallback from "./fallback.png";
|
|
39
39
|
import "./index.less";
|
|
40
40
|
var BaseUpload = function BaseUpload(props) {
|
|
@@ -77,6 +77,10 @@ var BaseUpload = function BaseUpload(props) {
|
|
|
77
77
|
_useState12 = _slicedToArray(_useState11, 2),
|
|
78
78
|
errorImageMap = _useState12[0],
|
|
79
79
|
setErrorImageMap = _useState12[1];
|
|
80
|
+
var fileListRef = useRef([]);
|
|
81
|
+
useEffect(function () {
|
|
82
|
+
fileListRef.current = fileList;
|
|
83
|
+
}, [fileList]);
|
|
80
84
|
var _useEngineContext = useEngineContext(),
|
|
81
85
|
appHelper = _useEngineContext.appHelper;
|
|
82
86
|
var _appHelper$constants = appHelper === null || appHelper === void 0 ? void 0 : appHelper.constants,
|
|
@@ -117,7 +121,7 @@ var BaseUpload = function BaseUpload(props) {
|
|
|
117
121
|
_context.next = 5;
|
|
118
122
|
break;
|
|
119
123
|
}
|
|
120
|
-
return _context.abrupt("return",
|
|
124
|
+
return _context.abrupt("return", '');
|
|
121
125
|
case 5:
|
|
122
126
|
_context.prev = 5;
|
|
123
127
|
_context.next = 8;
|
|
@@ -149,13 +153,36 @@ var BaseUpload = function BaseUpload(props) {
|
|
|
149
153
|
};
|
|
150
154
|
}(), [errorImageMap]);
|
|
151
155
|
useEffect(function () {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
// 只在 value 变化且不是由内部 onChange 触发时才更新 fileList
|
|
157
|
+
var currentValue = getValueFromFileList(fileListRef.current);
|
|
158
|
+
if (!fileListRef.current.length || !isValueEqual(value, currentValue)) {
|
|
159
|
+
var newFileList = getDefaultFileList(value, {
|
|
160
|
+
enableMultilingual: !!enableMultilingual,
|
|
161
|
+
multiple: !!multiple
|
|
162
|
+
});
|
|
163
|
+
setFileList(newFileList);
|
|
164
|
+
setErrorImageMap({});
|
|
165
|
+
}
|
|
158
166
|
}, [value, enableMultilingual, multiple]);
|
|
167
|
+
var getValueFromFileList = function getValueFromFileList(fileList) {
|
|
168
|
+
if (!fileList.length) return multiple ? [] : '';
|
|
169
|
+
if (enableMultilingual) {
|
|
170
|
+
var multilingualValues = fileList.filter(function (file) {
|
|
171
|
+
return file.status === 'done';
|
|
172
|
+
}).map(function (file) {
|
|
173
|
+
var _file$response2, _file$response2$data;
|
|
174
|
+
return file.multilingual || createMultilingualData(((_file$response2 = file.response) === null || _file$response2 === void 0 ? void 0 : (_file$response2$data = _file$response2.data) === null || _file$response2$data === void 0 ? void 0 : _file$response2$data.url) || file.url || '');
|
|
175
|
+
});
|
|
176
|
+
return multiple ? multilingualValues : multilingualValues[0];
|
|
177
|
+
}
|
|
178
|
+
var urls = fileList.filter(function (file) {
|
|
179
|
+
return file.status === 'done';
|
|
180
|
+
}).map(function (file) {
|
|
181
|
+
var _file$response3, _file$response3$data;
|
|
182
|
+
return ((_file$response3 = file.response) === null || _file$response3 === void 0 ? void 0 : (_file$response3$data = _file$response3.data) === null || _file$response3$data === void 0 ? void 0 : _file$response3$data.url) || file.url || '';
|
|
183
|
+
});
|
|
184
|
+
return multiple ? urls : urls[0] || '';
|
|
185
|
+
};
|
|
159
186
|
var calcMaxCount = useMemo(function () {
|
|
160
187
|
return multiple ? maxCount || DEFAULT_MAX_COUNT : 1;
|
|
161
188
|
}, [maxCount, multiple]);
|
|
@@ -184,55 +211,68 @@ var BaseUpload = function BaseUpload(props) {
|
|
|
184
211
|
}, {
|
|
185
212
|
wait: 500
|
|
186
213
|
});
|
|
214
|
+
var fileDoneSetMultilingualFileList = useMemoizedFn(function () {
|
|
215
|
+
setFileList(function (prev) {
|
|
216
|
+
return prev.map(function (item) {
|
|
217
|
+
var _item$response, _item$response$data, _item$response2, _item$response2$data;
|
|
218
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
219
|
+
multilingualFileList: item.multilingualFileList || createMultilingualFileList(((_item$response = item.response) === null || _item$response === void 0 ? void 0 : (_item$response$data = _item$response.data) === null || _item$response$data === void 0 ? void 0 : _item$response$data.url) || item.url || ''),
|
|
220
|
+
multilingual: item.multilingual || createMultilingualData(((_item$response2 = item.response) === null || _item$response2 === void 0 ? void 0 : (_item$response2$data = _item$response2.data) === null || _item$response2$data === void 0 ? void 0 : _item$response2$data.url) || item.url || '')
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
});
|
|
187
225
|
var handleChange = useCallback(function (_ref2) {
|
|
188
|
-
var _file$
|
|
226
|
+
var _file$response4, _file$response7, _file$response8;
|
|
189
227
|
var file = _ref2.file,
|
|
190
228
|
newFileList = _ref2.fileList;
|
|
191
229
|
var updatedFileList = newFileList.map(function (item) {
|
|
192
|
-
var _item$
|
|
230
|
+
var _item$response3;
|
|
193
231
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
194
|
-
status: item.status === 'done' && item.response && !((_item$
|
|
232
|
+
status: item.status === 'done' && item.response && !((_item$response3 = item.response) !== null && _item$response3 !== void 0 && _item$response3.status) ? 'error' : item.status
|
|
195
233
|
});
|
|
196
234
|
});
|
|
197
235
|
setFileList(updatedFileList);
|
|
198
|
-
if (file.status === 'done' && (_file$
|
|
236
|
+
if (file.status === 'done' && (_file$response4 = file.response) !== null && _file$response4 !== void 0 && _file$response4.status) {
|
|
199
237
|
if (multiple) {
|
|
200
238
|
if (enableMultilingual) {
|
|
201
239
|
var multilingualUrls = updatedFileList.filter(function (item) {
|
|
202
240
|
return item.status === 'done';
|
|
203
241
|
}).map(function (item) {
|
|
204
|
-
var _item$
|
|
205
|
-
return item.multilingual || createMultilingualData(((_item$
|
|
242
|
+
var _item$response4, _item$response4$data;
|
|
243
|
+
return item.multilingual || createMultilingualData(((_item$response4 = item.response) === null || _item$response4 === void 0 ? void 0 : (_item$response4$data = _item$response4.data) === null || _item$response4$data === void 0 ? void 0 : _item$response4$data.url) || item.url || '');
|
|
206
244
|
});
|
|
245
|
+
fileDoneSetMultilingualFileList();
|
|
207
246
|
onChange === null || onChange === void 0 ? void 0 : onChange(multilingualUrls);
|
|
208
247
|
} else {
|
|
209
248
|
var urls = updatedFileList.filter(function (item) {
|
|
210
249
|
return item.status === 'done';
|
|
211
250
|
}).map(function (item) {
|
|
212
|
-
var _item$
|
|
213
|
-
return ((_item$
|
|
251
|
+
var _item$response5, _item$response5$data;
|
|
252
|
+
return ((_item$response5 = item.response) === null || _item$response5 === void 0 ? void 0 : (_item$response5$data = _item$response5.data) === null || _item$response5$data === void 0 ? void 0 : _item$response5$data.url) || item.url || '';
|
|
214
253
|
});
|
|
215
254
|
onChange === null || onChange === void 0 ? void 0 : onChange(urls);
|
|
216
255
|
}
|
|
217
256
|
} else {
|
|
218
257
|
if (enableMultilingual) {
|
|
219
|
-
var _file$
|
|
220
|
-
var multilingualData = createMultilingualData(((_file$
|
|
258
|
+
var _file$response5, _file$response5$data;
|
|
259
|
+
var multilingualData = createMultilingualData(((_file$response5 = file.response) === null || _file$response5 === void 0 ? void 0 : (_file$response5$data = _file$response5.data) === null || _file$response5$data === void 0 ? void 0 : _file$response5$data.url) || '');
|
|
260
|
+
fileDoneSetMultilingualFileList();
|
|
221
261
|
onChange === null || onChange === void 0 ? void 0 : onChange(multilingualData);
|
|
222
262
|
} else {
|
|
223
|
-
var _file$
|
|
224
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(((_file$
|
|
263
|
+
var _file$response6, _file$response6$data;
|
|
264
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(((_file$response6 = file.response) === null || _file$response6 === void 0 ? void 0 : (_file$response6$data = _file$response6.data) === null || _file$response6$data === void 0 ? void 0 : _file$response6$data.url) || '');
|
|
225
265
|
}
|
|
226
266
|
}
|
|
227
|
-
} else if (file.status === 'error' || isBoolean((_file$
|
|
267
|
+
} else if (file.status === 'error' || isBoolean((_file$response7 = file.response) === null || _file$response7 === void 0 ? void 0 : _file$response7.status) && ((_file$response8 = file.response) === null || _file$response8 === void 0 ? void 0 : _file$response8.status) === false) {
|
|
228
268
|
PisellToast({
|
|
229
269
|
content: getText('pisell-upload-error')(file.name)
|
|
230
270
|
});
|
|
231
271
|
}
|
|
232
272
|
}, [multiple, enableMultilingual, onChange]);
|
|
233
273
|
var handlePreview = useCallback(function (file) {
|
|
234
|
-
var _file$
|
|
235
|
-
setPreviewImage(file.url || ((_file$
|
|
274
|
+
var _file$response9, _file$response9$data;
|
|
275
|
+
setPreviewImage(file.url || ((_file$response9 = file.response) === null || _file$response9 === void 0 ? void 0 : (_file$response9$data = _file$response9.data) === null || _file$response9$data === void 0 ? void 0 : _file$response9$data.url) || '');
|
|
236
276
|
setPreviewOpen(true);
|
|
237
277
|
}, []);
|
|
238
278
|
var handleEditMultilingual = useCallback(function (file) {
|
|
@@ -254,8 +294,8 @@ var BaseUpload = function BaseUpload(props) {
|
|
|
254
294
|
onChange === null || onChange === void 0 ? void 0 : onChange(multilingualUrls);
|
|
255
295
|
} else {
|
|
256
296
|
var urls = val.map(function (item) {
|
|
257
|
-
var _item$
|
|
258
|
-
return ((_item$
|
|
297
|
+
var _item$response6, _item$response6$data;
|
|
298
|
+
return ((_item$response6 = item.response) === null || _item$response6 === void 0 ? void 0 : (_item$response6$data = _item$response6.data) === null || _item$response6$data === void 0 ? void 0 : _item$response6$data.url) || item.url || '';
|
|
259
299
|
});
|
|
260
300
|
onChange === null || onChange === void 0 ? void 0 : onChange(urls);
|
|
261
301
|
}
|
|
@@ -287,9 +327,9 @@ var BaseUpload = function BaseUpload(props) {
|
|
|
287
327
|
if (!prev) return null;
|
|
288
328
|
var newFile = _objectSpread({}, prev);
|
|
289
329
|
newFile.multilingualFileList[lang] = info.fileList.map(function (item) {
|
|
290
|
-
var _item$
|
|
330
|
+
var _item$response7;
|
|
291
331
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
292
|
-
status: item.status === 'done' && !((_item$
|
|
332
|
+
status: item.status === 'done' && !((_item$response7 = item.response) !== null && _item$response7 !== void 0 && _item$response7.status) ? 'error' : item.status
|
|
293
333
|
});
|
|
294
334
|
});
|
|
295
335
|
if (info.file.status === 'done') {
|
|
@@ -14,3 +14,4 @@ export declare const getDefaultFileList: (value: UploadValue | undefined, option
|
|
|
14
14
|
export declare const getFileMetadataParams: (file: RcFile & {
|
|
15
15
|
metadata?: MediaMetadata;
|
|
16
16
|
}) => Record<string, any>;
|
|
17
|
+
export declare const isValueEqual: (value: any, fileListValue: any) => boolean;
|
|
@@ -259,4 +259,28 @@ export var getFileMetadataParams = function getFileMetadataParams(file) {
|
|
|
259
259
|
}
|
|
260
260
|
});
|
|
261
261
|
return metadataParams;
|
|
262
|
+
};
|
|
263
|
+
export var isValueEqual = function isValueEqual(value, fileListValue) {
|
|
264
|
+
// 处理空值情况
|
|
265
|
+
if (!value && !fileListValue) return true;
|
|
266
|
+
if (!value || !fileListValue) return false;
|
|
267
|
+
|
|
268
|
+
// 数组情况
|
|
269
|
+
if (Array.isArray(value) && Array.isArray(fileListValue)) {
|
|
270
|
+
if (value.length !== fileListValue.length) return false;
|
|
271
|
+
return value.every(function (v, i) {
|
|
272
|
+
if (_typeof(v) === 'object') {
|
|
273
|
+
return JSON.stringify(v) === JSON.stringify(fileListValue[i]);
|
|
274
|
+
}
|
|
275
|
+
return v === fileListValue[i];
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// 对象情况(多语言单文件)
|
|
280
|
+
if (_typeof(value) === 'object' && _typeof(fileListValue) === 'object') {
|
|
281
|
+
return JSON.stringify(value) === JSON.stringify(fileListValue);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// 字符串情况(单文件)
|
|
285
|
+
return value === fileListValue;
|
|
262
286
|
};
|
|
@@ -41,7 +41,7 @@ var SelectBase = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
41
41
|
setSearchValue = _useState2[1];
|
|
42
42
|
var filteredOptions = useMemo(function () {
|
|
43
43
|
if (!searchValue) return options;
|
|
44
|
-
return options.filter(function (option) {
|
|
44
|
+
return (options || []).filter(function (option) {
|
|
45
45
|
var _option$optionFilterP;
|
|
46
46
|
var optionValue = ((_option$optionFilterP = option[optionFilterProp]) === null || _option$optionFilterP === void 0 ? void 0 : _option$optionFilterP.toString().toLowerCase()) || '';
|
|
47
47
|
return optionValue.includes(searchValue.toLowerCase());
|
|
@@ -111,21 +111,15 @@ var PhoneInput = ({ value: propsValue, onChange, isVerification, ...props }) =>
|
|
|
111
111
|
style: { width: "90px" },
|
|
112
112
|
onBlur: handleBlur,
|
|
113
113
|
popupMatchSelectWidth: false,
|
|
114
|
-
optionLabelProp: "
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
Option,
|
|
119
|
-
{
|
|
120
|
-
key: country.code,
|
|
114
|
+
optionLabelProp: "inputValue",
|
|
115
|
+
optionFilterProp: "label",
|
|
116
|
+
showSearch: true,
|
|
117
|
+
options: countries.map((country) => ({
|
|
121
118
|
value: country.code,
|
|
122
|
-
label: country.prefix
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
country.prefix,
|
|
127
|
-
")"
|
|
128
|
-
))
|
|
119
|
+
label: `${translationOriginal(country.name)} (${country.prefix})`,
|
|
120
|
+
inputValue: country.prefix
|
|
121
|
+
}))
|
|
122
|
+
}
|
|
129
123
|
), /* @__PURE__ */ import_react.default.createElement(
|
|
130
124
|
import_antd.Input,
|
|
131
125
|
{
|
|
@@ -70,7 +70,13 @@ var BaseUpload = (props) => {
|
|
|
70
70
|
const [previewOpen, setPreviewOpen] = (0, import_react.useState)(false);
|
|
71
71
|
const [open, setOpen] = (0, import_react.useState)(false);
|
|
72
72
|
const [editMultilingualFile, setEditMultilingualFile] = (0, import_react.useState)(null);
|
|
73
|
-
const [errorImageMap, setErrorImageMap] = (0, import_react.useState)(
|
|
73
|
+
const [errorImageMap, setErrorImageMap] = (0, import_react.useState)(
|
|
74
|
+
{}
|
|
75
|
+
);
|
|
76
|
+
const fileListRef = (0, import_react.useRef)([]);
|
|
77
|
+
(0, import_react.useEffect)(() => {
|
|
78
|
+
fileListRef.current = fileList;
|
|
79
|
+
}, [fileList]);
|
|
74
80
|
const { appHelper } = (0, import_useEngineContext.default)();
|
|
75
81
|
const { mediaUploadUrl, getHeaders } = appHelper == null ? void 0 : appHelper.constants;
|
|
76
82
|
const handleImageError = (0, import_react.useCallback)((file) => {
|
|
@@ -87,36 +93,60 @@ var BaseUpload = (props) => {
|
|
|
87
93
|
img.src = url;
|
|
88
94
|
});
|
|
89
95
|
}, []);
|
|
90
|
-
const getItemUrl = (0, import_react.useCallback)(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
const url = file.url || ((_b = (_a = file.response) == null ? void 0 : _a.data) == null ? void 0 : _b.url) || "";
|
|
96
|
-
if (!url)
|
|
97
|
-
return "";
|
|
98
|
-
try {
|
|
99
|
-
const isValid = await checkImageUrl(url);
|
|
100
|
-
if (!isValid) {
|
|
101
|
-
setErrorImageMap((prev) => ({
|
|
102
|
-
...prev,
|
|
103
|
-
[file.uid]: true
|
|
104
|
-
}));
|
|
96
|
+
const getItemUrl = (0, import_react.useCallback)(
|
|
97
|
+
async (file) => {
|
|
98
|
+
var _a, _b;
|
|
99
|
+
if (errorImageMap[file.uid]) {
|
|
105
100
|
return import_fallback.default;
|
|
106
101
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
102
|
+
const url = file.url || ((_b = (_a = file.response) == null ? void 0 : _a.data) == null ? void 0 : _b.url) || "";
|
|
103
|
+
if (!url)
|
|
104
|
+
return "";
|
|
105
|
+
try {
|
|
106
|
+
const isValid = await checkImageUrl(url);
|
|
107
|
+
if (!isValid) {
|
|
108
|
+
setErrorImageMap((prev) => ({
|
|
109
|
+
...prev,
|
|
110
|
+
[file.uid]: true
|
|
111
|
+
}));
|
|
112
|
+
return import_fallback.default;
|
|
113
|
+
}
|
|
114
|
+
return url;
|
|
115
|
+
} catch (error) {
|
|
116
|
+
return import_fallback.default;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
[errorImageMap]
|
|
120
|
+
);
|
|
112
121
|
(0, import_react.useEffect)(() => {
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
const currentValue = getValueFromFileList(fileListRef.current);
|
|
123
|
+
if (!fileListRef.current.length || !(0, import_utils2.isValueEqual)(value, currentValue)) {
|
|
124
|
+
const newFileList = (0, import_utils2.getDefaultFileList)(value, {
|
|
125
|
+
enableMultilingual: !!enableMultilingual,
|
|
126
|
+
multiple: !!multiple
|
|
127
|
+
});
|
|
128
|
+
setFileList(newFileList);
|
|
129
|
+
setErrorImageMap({});
|
|
130
|
+
}
|
|
119
131
|
}, [value, enableMultilingual, multiple]);
|
|
132
|
+
const getValueFromFileList = (fileList2) => {
|
|
133
|
+
if (!fileList2.length)
|
|
134
|
+
return multiple ? [] : "";
|
|
135
|
+
if (enableMultilingual) {
|
|
136
|
+
const multilingualValues = fileList2.filter((file) => file.status === "done").map(
|
|
137
|
+
(file) => {
|
|
138
|
+
var _a, _b;
|
|
139
|
+
return file.multilingual || (0, import_utils2.createMultilingualData)(((_b = (_a = file.response) == null ? void 0 : _a.data) == null ? void 0 : _b.url) || file.url || "");
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
return multiple ? multilingualValues : multilingualValues[0];
|
|
143
|
+
}
|
|
144
|
+
const urls = fileList2.filter((file) => file.status === "done").map((file) => {
|
|
145
|
+
var _a, _b;
|
|
146
|
+
return ((_b = (_a = file.response) == null ? void 0 : _a.data) == null ? void 0 : _b.url) || file.url || "";
|
|
147
|
+
});
|
|
148
|
+
return multiple ? urls : urls[0] || "";
|
|
149
|
+
};
|
|
120
150
|
const calcMaxCount = (0, import_react.useMemo)(
|
|
121
151
|
() => multiple ? maxCount || import_constants.DEFAULT_MAX_COUNT : 1,
|
|
122
152
|
[maxCount, multiple]
|
|
@@ -140,6 +170,22 @@ var BaseUpload = (props) => {
|
|
|
140
170
|
(msg) => (0, import_pisellToast.default)({ content: msg }),
|
|
141
171
|
{ wait: 500 }
|
|
142
172
|
);
|
|
173
|
+
const fileDoneSetMultilingualFileList = (0, import_ahooks.useMemoizedFn)(() => {
|
|
174
|
+
setFileList((prev) => {
|
|
175
|
+
return prev.map((item) => {
|
|
176
|
+
var _a, _b, _c, _d;
|
|
177
|
+
return {
|
|
178
|
+
...item,
|
|
179
|
+
multilingualFileList: item.multilingualFileList || (0, import_utils2.createMultilingualFileList)(
|
|
180
|
+
((_b = (_a = item.response) == null ? void 0 : _a.data) == null ? void 0 : _b.url) || item.url || ""
|
|
181
|
+
),
|
|
182
|
+
multilingual: item.multilingual || (0, import_utils2.createMultilingualData)(
|
|
183
|
+
((_d = (_c = item.response) == null ? void 0 : _c.data) == null ? void 0 : _d.url) || item.url || ""
|
|
184
|
+
)
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
});
|
|
143
189
|
const handleChange = (0, import_react.useCallback)(
|
|
144
190
|
({ file, fileList: newFileList }) => {
|
|
145
191
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -156,10 +202,15 @@ var BaseUpload = (props) => {
|
|
|
156
202
|
if (enableMultilingual) {
|
|
157
203
|
const multilingualUrls = updatedFileList.filter(
|
|
158
204
|
(item) => item.status === "done"
|
|
159
|
-
).map(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
205
|
+
).map(
|
|
206
|
+
(item) => {
|
|
207
|
+
var _a2, _b2;
|
|
208
|
+
return item.multilingual || (0, import_utils2.createMultilingualData)(
|
|
209
|
+
((_b2 = (_a2 = item.response) == null ? void 0 : _a2.data) == null ? void 0 : _b2.url) || item.url || ""
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
);
|
|
213
|
+
fileDoneSetMultilingualFileList();
|
|
163
214
|
onChange == null ? void 0 : onChange(multilingualUrls);
|
|
164
215
|
} else {
|
|
165
216
|
const urls = updatedFileList.filter((item) => item.status === "done").map((item) => {
|
|
@@ -170,7 +221,10 @@ var BaseUpload = (props) => {
|
|
|
170
221
|
}
|
|
171
222
|
} else {
|
|
172
223
|
if (enableMultilingual) {
|
|
173
|
-
const multilingualData = (0, import_utils2.createMultilingualData)(
|
|
224
|
+
const multilingualData = (0, import_utils2.createMultilingualData)(
|
|
225
|
+
((_c = (_b = file.response) == null ? void 0 : _b.data) == null ? void 0 : _c.url) || ""
|
|
226
|
+
);
|
|
227
|
+
fileDoneSetMultilingualFileList();
|
|
174
228
|
onChange == null ? void 0 : onChange(multilingualData);
|
|
175
229
|
} else {
|
|
176
230
|
onChange == null ? void 0 : onChange(((_e = (_d = file.response) == null ? void 0 : _d.data) == null ? void 0 : _e.url) || "");
|
|
@@ -378,31 +432,36 @@ var BaseUpload = (props) => {
|
|
|
378
432
|
),
|
|
379
433
|
[restProps.disabled, handleGlobeIconClick]
|
|
380
434
|
);
|
|
381
|
-
const itemRender = (0, import_ahooks.useMemoizedFn)(
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
435
|
+
const itemRender = (0, import_ahooks.useMemoizedFn)(
|
|
436
|
+
(originNode, file) => {
|
|
437
|
+
const [itemUrl, setItemUrl] = (0, import_react.useState)("");
|
|
438
|
+
(0, import_react.useEffect)(() => {
|
|
439
|
+
getItemUrl(file).then(setItemUrl);
|
|
440
|
+
}, [file]);
|
|
441
|
+
const newNode = import_react.default.cloneElement(originNode, {
|
|
442
|
+
children: import_react.default.Children.map(originNode.props.children, (child) => {
|
|
443
|
+
if ((child == null ? void 0 : child.type) === "a") {
|
|
444
|
+
return import_react.default.cloneElement(child, {
|
|
445
|
+
children: import_react.default.Children.map(
|
|
446
|
+
child.props.children,
|
|
447
|
+
(grandChild) => {
|
|
448
|
+
if ((grandChild == null ? void 0 : grandChild.type) === "img") {
|
|
449
|
+
return import_react.default.cloneElement(grandChild, {
|
|
450
|
+
src: itemUrl,
|
|
451
|
+
onError: () => handleImageError(file)
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
return grandChild;
|
|
455
|
+
}
|
|
456
|
+
)
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
return child;
|
|
460
|
+
})
|
|
461
|
+
});
|
|
462
|
+
return newNode;
|
|
463
|
+
}
|
|
464
|
+
);
|
|
406
465
|
const uploadProps = {
|
|
407
466
|
...restProps,
|
|
408
467
|
multiple,
|
|
@@ -472,27 +531,25 @@ var BaseUpload = (props) => {
|
|
|
472
531
|
onCancel: handleEditMultilingualCancel,
|
|
473
532
|
onOk: handleEditMultilingualOk
|
|
474
533
|
},
|
|
475
|
-
/* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-upload-multilingual-container" }, import_constants.SUPPORTED_LANGUAGES.map(
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
showDownloadIcon: false
|
|
486
|
-
},
|
|
487
|
-
fileList: ((_a = editMultilingualFile == null ? void 0 : editMultilingualFile.multilingualFileList) == null ? void 0 : _a[lang]) || [],
|
|
488
|
-
onRemove: (file) => handleEditMultilingualRemove(file, lang),
|
|
489
|
-
onChange: (info) => handleEditMultilingualChange(info, lang),
|
|
490
|
-
multiple: false
|
|
534
|
+
/* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-upload-multilingual-container" }, import_constants.SUPPORTED_LANGUAGES.map((lang) => {
|
|
535
|
+
var _a, _b, _c;
|
|
536
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { key: lang, className: "pisell-upload-multilingual-item" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-upload-multilingual-item-title" }, (0, import_locales.getText)(`pisell-upload-multilingual-item-title-${lang}`)), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-upload-multilingual-item-content" }, /* @__PURE__ */ import_react.default.createElement(
|
|
537
|
+
import_pisellUpload.default,
|
|
538
|
+
{
|
|
539
|
+
...uploadProps,
|
|
540
|
+
showUploadList: {
|
|
541
|
+
showRemoveIcon: true,
|
|
542
|
+
showPreviewIcon: true,
|
|
543
|
+
showDownloadIcon: false
|
|
491
544
|
},
|
|
492
|
-
((
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
545
|
+
fileList: ((_a = editMultilingualFile == null ? void 0 : editMultilingualFile.multilingualFileList) == null ? void 0 : _a[lang]) || [],
|
|
546
|
+
onRemove: (file) => handleEditMultilingualRemove(file, lang),
|
|
547
|
+
onChange: (info) => handleEditMultilingualChange(info, lang),
|
|
548
|
+
multiple: false
|
|
549
|
+
},
|
|
550
|
+
((_c = (_b = editMultilingualFile == null ? void 0 : editMultilingualFile.multilingualFileList) == null ? void 0 : _b[lang]) == null ? void 0 : _c.length) ? null : renderUploadButton(false)
|
|
551
|
+
)));
|
|
552
|
+
}))
|
|
496
553
|
), previewImage && /* @__PURE__ */ import_react.default.createElement(
|
|
497
554
|
import_antd.Image,
|
|
498
555
|
{
|
|
@@ -14,3 +14,4 @@ export declare const getDefaultFileList: (value: UploadValue | undefined, option
|
|
|
14
14
|
export declare const getFileMetadataParams: (file: RcFile & {
|
|
15
15
|
metadata?: MediaMetadata;
|
|
16
16
|
}) => Record<string, any>;
|
|
17
|
+
export declare const isValueEqual: (value: any, fileListValue: any) => boolean;
|
|
@@ -30,7 +30,8 @@ __export(utils_exports, {
|
|
|
30
30
|
getFileType: () => getFileType,
|
|
31
31
|
getMediaMetadata: () => getMediaMetadata,
|
|
32
32
|
getPointSuffix: () => getPointSuffix,
|
|
33
|
-
getSuffix: () => getSuffix
|
|
33
|
+
getSuffix: () => getSuffix,
|
|
34
|
+
isValueEqual: () => isValueEqual
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(utils_exports);
|
|
36
37
|
var import_utils = require("@pisell/utils");
|
|
@@ -236,6 +237,26 @@ var getFileMetadataParams = (file) => {
|
|
|
236
237
|
});
|
|
237
238
|
return metadataParams;
|
|
238
239
|
};
|
|
240
|
+
var isValueEqual = (value, fileListValue) => {
|
|
241
|
+
if (!value && !fileListValue)
|
|
242
|
+
return true;
|
|
243
|
+
if (!value || !fileListValue)
|
|
244
|
+
return false;
|
|
245
|
+
if (Array.isArray(value) && Array.isArray(fileListValue)) {
|
|
246
|
+
if (value.length !== fileListValue.length)
|
|
247
|
+
return false;
|
|
248
|
+
return value.every((v, i) => {
|
|
249
|
+
if (typeof v === "object") {
|
|
250
|
+
return JSON.stringify(v) === JSON.stringify(fileListValue[i]);
|
|
251
|
+
}
|
|
252
|
+
return v === fileListValue[i];
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
if (typeof value === "object" && typeof fileListValue === "object") {
|
|
256
|
+
return JSON.stringify(value) === JSON.stringify(fileListValue);
|
|
257
|
+
}
|
|
258
|
+
return value === fileListValue;
|
|
259
|
+
};
|
|
239
260
|
// Annotate the CommonJS export names for ESM import in node:
|
|
240
261
|
0 && (module.exports = {
|
|
241
262
|
checkFileCount,
|
|
@@ -249,5 +270,6 @@ var getFileMetadataParams = (file) => {
|
|
|
249
270
|
getFileType,
|
|
250
271
|
getMediaMetadata,
|
|
251
272
|
getPointSuffix,
|
|
252
|
-
getSuffix
|
|
273
|
+
getSuffix,
|
|
274
|
+
isValueEqual
|
|
253
275
|
});
|
|
@@ -63,7 +63,7 @@ var SelectBase = (0, import_react.forwardRef)((props, ref) => {
|
|
|
63
63
|
const filteredOptions = (0, import_react.useMemo)(() => {
|
|
64
64
|
if (!searchValue)
|
|
65
65
|
return options;
|
|
66
|
-
return options.filter(
|
|
66
|
+
return (options || []).filter(
|
|
67
67
|
(option) => {
|
|
68
68
|
var _a;
|
|
69
69
|
const optionValue = ((_a = option[optionFilterProp]) == null ? void 0 : _a.toString().toLowerCase()) || "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pisell/materials",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.5",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"module": "./es/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -65,9 +65,9 @@
|
|
|
65
65
|
"react-virtualized-auto-sizer": "^1.0.20",
|
|
66
66
|
"crypto-js": "^4.2.0",
|
|
67
67
|
"@zxing/library": "0.21.2",
|
|
68
|
-
"@pisell/
|
|
68
|
+
"@pisell/utils": "1.0.42",
|
|
69
69
|
"@pisell/icon": "0.0.11",
|
|
70
|
-
"@pisell/
|
|
70
|
+
"@pisell/date-picker": "1.0.100"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"react": "^18.0.0",
|