@mezzanine-ui/react 0.10.2 → 0.10.3
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.
|
@@ -22,6 +22,10 @@ export interface UploadPictureWallBaseProps extends Omit<NativeElementPropsWitho
|
|
|
22
22
|
* @default false
|
|
23
23
|
*/
|
|
24
24
|
disabled?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* maximum file lengths
|
|
27
|
+
*/
|
|
28
|
+
maxLength?: number;
|
|
25
29
|
/**
|
|
26
30
|
* Whether the input which is multiple.
|
|
27
31
|
* @default true
|
|
@@ -9,7 +9,7 @@ import UploadPictureWallItem from './UploadPictureWallItem.js';
|
|
|
9
9
|
import cx from 'clsx';
|
|
10
10
|
|
|
11
11
|
const UploadPictureWall = forwardRef(function UploadPictureWall(props, ref) {
|
|
12
|
-
const { accept = 'image/*', className, controllerRef, defaultValues, disabled = false, multiple = true, onChange, onDelete, onError, onMultiUpload, onUpload, onUploadSuccess, parallel = false, style, } = props;
|
|
12
|
+
const { accept = 'image/*', className, controllerRef, defaultValues, disabled = false, maxLength, multiple = true, onChange, onDelete, onError, onMultiUpload, onUpload, onUploadSuccess, parallel = false, style, } = props;
|
|
13
13
|
const [uploadPictureImageLoaders, setUploadPictureImageLoader] = useState(defaultValues ? compact(defaultValues).map((value) => new ImageUploader(undefined, value)) : []);
|
|
14
14
|
const [needUploadImageLoaders, setNeedUploadImageLoaders] = useState([]);
|
|
15
15
|
const [needUploadImageLoaderSets, setNeedUploadImageLoaderSets] = useState([]);
|
|
@@ -24,8 +24,8 @@ const UploadPictureWall = forwardRef(function UploadPictureWall(props, ref) {
|
|
|
24
24
|
}
|
|
25
25
|
}, [onChange, prevValues, values]);
|
|
26
26
|
useEffect(() => {
|
|
27
|
-
if (prevNeedUploadImageLoadersLength > needUploadImageLoaders.length
|
|
28
|
-
prevNeedUploadImageLoaderSetsLength > needUploadImageLoaderSets.length) {
|
|
27
|
+
if (prevNeedUploadImageLoadersLength > needUploadImageLoaders.length
|
|
28
|
+
|| prevNeedUploadImageLoaderSetsLength > needUploadImageLoaderSets.length) {
|
|
29
29
|
setValues(compact(uploadPictureImageLoaders.map((loader) => loader.getUrl())));
|
|
30
30
|
}
|
|
31
31
|
}, [
|
|
@@ -99,7 +99,9 @@ const UploadPictureWall = forwardRef(function UploadPictureWall(props, ref) {
|
|
|
99
99
|
}, [needUploadImageLoaders, onError, onUpload, onUploadSuccess]);
|
|
100
100
|
const onImagesUpload = useCallback((files) => {
|
|
101
101
|
if (files.length) {
|
|
102
|
-
const imageLoaders = files
|
|
102
|
+
const imageLoaders = files
|
|
103
|
+
.map((file) => new ImageUploader(file))
|
|
104
|
+
.slice(0, Math.max(0, (maxLength !== null && maxLength !== void 0 ? maxLength : 999999) - loaderList.length));
|
|
103
105
|
setUploadPictureImageLoader((ups) => [...ups, ...imageLoaders]);
|
|
104
106
|
if (onMultiUpload) {
|
|
105
107
|
const uploadFiles = imageLoaders.map((loader) => loader.getFile());
|
|
@@ -134,7 +136,7 @@ const UploadPictureWall = forwardRef(function UploadPictureWall(props, ref) {
|
|
|
134
136
|
}
|
|
135
137
|
}
|
|
136
138
|
}
|
|
137
|
-
}, [onError, onMultiUpload, onUpload, onUploadSuccess, parallel]);
|
|
139
|
+
}, [onError, onMultiUpload, onUpload, onUploadSuccess, parallel, maxLength, loaderList]);
|
|
138
140
|
const onImageDelete = useCallback((uid) => {
|
|
139
141
|
setUploadPictureImageLoader((ups) => ups.filter((up) => up.getUid() !== uid));
|
|
140
142
|
setNeedUploadImageLoaders((nUps) => nUps.filter((nUp) => nUp.getUid() !== uid));
|
|
@@ -148,7 +150,7 @@ const UploadPictureWall = forwardRef(function UploadPictureWall(props, ref) {
|
|
|
148
150
|
useImperativeHandle(controllerRef, () => ({
|
|
149
151
|
getAllData: () => uploadPictureImageLoaders.map((loader) => loader.getAll()),
|
|
150
152
|
}));
|
|
151
|
-
return (jsxs("div", { ref: ref, className: cx(uploadPictureWallClasses.host, className), style: style, children: [loaderList.map((up) => (jsx(UploadPictureWallItem, { accept: accept, disabled: disabled, imageLoader: up, multiple: multiple, onDelete: () => onImageDelete(up.getUid()) }, up.getUid()))), jsx(UploadPictureWallItem, { accept: accept, disabled: disabled, imageLoader: new ImageUploader(), multiple: multiple, onUpload: onImagesUpload })] }));
|
|
153
|
+
return (jsxs("div", { ref: ref, className: cx(uploadPictureWallClasses.host, className), style: style, children: [loaderList.map((up) => (jsx(UploadPictureWallItem, { accept: accept, disabled: disabled, imageLoader: up, multiple: multiple, onDelete: () => onImageDelete(up.getUid()) }, up.getUid()))), maxLength && loaderList.length >= maxLength ? null : (jsx(UploadPictureWallItem, { accept: accept, disabled: disabled, imageLoader: new ImageUploader(), multiple: multiple, onUpload: onImagesUpload }))] }));
|
|
152
154
|
});
|
|
153
155
|
var UploadPictureWall$1 = UploadPictureWall;
|
|
154
156
|
|