mimir-ui-kit 1.63.0 → 1.64.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as x, jsx as p, Fragment as k } from "react/jsx-runtime";
|
|
2
2
|
import { c as q } from "../../index-DIxK0V-G.js";
|
|
3
3
|
import { forwardRef as G, useState as H, useEffect as J, useMemo as K } from "react";
|
|
4
|
-
import { imageTypes as g } from "./constants.js";
|
|
5
4
|
import "../Button/Button.js";
|
|
6
5
|
import { EButtonVariantDefault as Q } from "../Button/constants.js";
|
|
7
6
|
import { ListFiles as W } from "../ListFiles/ListFiles.js";
|
|
8
7
|
import { EFileItemVariant as X } from "../ListFiles/constants.js";
|
|
9
8
|
import { ListPhotos as Y } from "../ListPhotos/ListPhotos.js";
|
|
10
9
|
import { Uploader as Z } from "../Uploader/Uploader.js";
|
|
11
|
-
import '../../assets/UploaderPhotos.css';const
|
|
10
|
+
import '../../assets/UploaderPhotos.css';const g = {
|
|
12
11
|
"upload-file-wrapper": "_upload-file-wrapper_1a115_2"
|
|
13
|
-
},
|
|
14
|
-
(r,
|
|
12
|
+
}, y = (r, d) => "file" in r && r.file instanceof File ? d.includes(r.file.type) : "type" in r && typeof r.type == "string" ? d.includes(r.type) : !1, le = G(
|
|
13
|
+
(r, d) => {
|
|
15
14
|
const {
|
|
16
15
|
type: s,
|
|
17
|
-
filesType:
|
|
18
|
-
arrayName:
|
|
19
|
-
maxSize:
|
|
20
|
-
onChange:
|
|
21
|
-
value:
|
|
22
|
-
maxFiles:
|
|
23
|
-
titleUploader:
|
|
24
|
-
buttonText:
|
|
25
|
-
showOnlyUploadButton:
|
|
26
|
-
uploadButtonVariant:
|
|
27
|
-
buttonSize:
|
|
28
|
-
buttonClassName:
|
|
29
|
-
variantListFiles:
|
|
30
|
-
onMaxFilesExceeded:
|
|
31
|
-
onMaxSizeExceeded:
|
|
32
|
-
onInvalidFileType:
|
|
33
|
-
loadImage:
|
|
34
|
-
isDownloadingImage:
|
|
35
|
-
dataTestIdReactMap:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
16
|
+
filesType: a,
|
|
17
|
+
arrayName: z,
|
|
18
|
+
maxSize: P,
|
|
19
|
+
onChange: l,
|
|
20
|
+
value: f,
|
|
21
|
+
maxFiles: m,
|
|
22
|
+
titleUploader: U,
|
|
23
|
+
buttonText: b = "Выберите файлы",
|
|
24
|
+
showOnlyUploadButton: v = !1,
|
|
25
|
+
uploadButtonVariant: D = Q.SecondaryAsphalt,
|
|
26
|
+
buttonSize: E = "m",
|
|
27
|
+
buttonClassName: S,
|
|
28
|
+
variantListFiles: V = X.white,
|
|
29
|
+
onMaxFilesExceeded: L,
|
|
30
|
+
onMaxSizeExceeded: N,
|
|
31
|
+
onInvalidFileType: B,
|
|
32
|
+
loadImage: _,
|
|
33
|
+
isDownloadingImage: j,
|
|
34
|
+
dataTestIdReactMap: t,
|
|
35
|
+
accept: A
|
|
36
|
+
} = r, [n, u] = H(
|
|
37
|
+
f || []
|
|
38
|
+
), F = !!m && n.length >= m;
|
|
39
39
|
J(() => {
|
|
40
|
-
|
|
41
|
-
}, [
|
|
42
|
-
const C = (
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
f && u(f);
|
|
41
|
+
}, [f]);
|
|
42
|
+
const C = (i) => {
|
|
43
|
+
const o = i.value.map((e) => y(e.file, a) ? new Promise((c) => {
|
|
44
|
+
const h = new FileReader();
|
|
45
|
+
h.onload = () => {
|
|
46
|
+
c({
|
|
47
47
|
id: e.id,
|
|
48
|
-
url:
|
|
48
|
+
url: h.result,
|
|
49
49
|
type: e.file.type,
|
|
50
50
|
name: e.file.name,
|
|
51
51
|
size: e.file.size
|
|
52
52
|
});
|
|
53
|
-
},
|
|
53
|
+
}, h.readAsDataURL(e.file);
|
|
54
54
|
}) : Promise.resolve({
|
|
55
55
|
id: e.id,
|
|
56
56
|
url: "",
|
|
@@ -58,63 +58,64 @@ import '../../assets/UploaderPhotos.css';const w = {
|
|
|
58
58
|
name: e.file.name,
|
|
59
59
|
type: e.file.type
|
|
60
60
|
}));
|
|
61
|
-
Promise.all(
|
|
62
|
-
|
|
61
|
+
Promise.all(o).then((e) => {
|
|
62
|
+
u((c) => [...c, ...e]), l == null || l({ type: "add", data: i.value });
|
|
63
63
|
});
|
|
64
|
-
},
|
|
65
|
-
|
|
64
|
+
}, w = (i) => {
|
|
65
|
+
u((o) => o.filter((e) => e.id !== i)), l == null || l({ type: "delete", data: i });
|
|
66
66
|
}, { photos: I, files: O } = K(() => {
|
|
67
|
-
const
|
|
68
|
-
return s === "all" ? { files:
|
|
69
|
-
}, [a, s]);
|
|
70
|
-
return /* @__PURE__ */
|
|
67
|
+
const i = () => n.filter((e) => !y(e, a)), o = () => n.filter((e) => y(e, a));
|
|
68
|
+
return s === "all" ? { files: i(), photos: o() } : s === "files" ? { photos: [], files: i() } : s === "photos" ? { files: [], photos: o() } : { files: [], photos: [] };
|
|
69
|
+
}, [n, a, s]);
|
|
70
|
+
return /* @__PURE__ */ x(
|
|
71
71
|
"div",
|
|
72
72
|
{
|
|
73
73
|
"data-testid": "universal-uploader",
|
|
74
|
-
"data-testid-react":
|
|
74
|
+
"data-testid-react": t == null ? void 0 : t.wrapper,
|
|
75
75
|
className: q(
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
g["upload-file-wrapper"],
|
|
77
|
+
F && g.disabled
|
|
78
78
|
),
|
|
79
79
|
children: [
|
|
80
|
-
/* @__PURE__ */
|
|
80
|
+
/* @__PURE__ */ p(
|
|
81
81
|
Z,
|
|
82
82
|
{
|
|
83
|
-
dataTestIdReactMap: { wrapper:
|
|
84
|
-
filesType:
|
|
85
|
-
arrayName:
|
|
86
|
-
maxSize:
|
|
83
|
+
dataTestIdReactMap: { wrapper: t == null ? void 0 : t.uploader },
|
|
84
|
+
filesType: a,
|
|
85
|
+
arrayName: z,
|
|
86
|
+
maxSize: P,
|
|
87
87
|
onChangeValue: C,
|
|
88
|
-
ref:
|
|
89
|
-
maxFiles:
|
|
90
|
-
isDisabled:
|
|
91
|
-
titleUploader:
|
|
92
|
-
showOnlyUploadButton:
|
|
93
|
-
buttonText:
|
|
94
|
-
uploadButtonVariant:
|
|
95
|
-
buttonSize:
|
|
96
|
-
buttonClassName:
|
|
97
|
-
onMaxFilesExceeded:
|
|
98
|
-
onMaxSizeExceeded:
|
|
99
|
-
onInvalidFileType:
|
|
88
|
+
ref: d,
|
|
89
|
+
maxFiles: m && m - n.length,
|
|
90
|
+
isDisabled: F,
|
|
91
|
+
titleUploader: U,
|
|
92
|
+
showOnlyUploadButton: v,
|
|
93
|
+
buttonText: b,
|
|
94
|
+
uploadButtonVariant: D,
|
|
95
|
+
buttonSize: E,
|
|
96
|
+
buttonClassName: S,
|
|
97
|
+
onMaxFilesExceeded: L,
|
|
98
|
+
onMaxSizeExceeded: N,
|
|
99
|
+
onInvalidFileType: B,
|
|
100
|
+
accept: A
|
|
100
101
|
}
|
|
101
102
|
),
|
|
102
|
-
!
|
|
103
|
-
(s === "files" || s === "all") && /* @__PURE__ */
|
|
103
|
+
!v && /* @__PURE__ */ x(k, { children: [
|
|
104
|
+
(s === "files" || s === "all") && /* @__PURE__ */ p("div", { "data-testid-react": t == null ? void 0 : t.listFiles, children: /* @__PURE__ */ p(
|
|
104
105
|
W,
|
|
105
106
|
{
|
|
106
107
|
value: O,
|
|
107
|
-
onChange: (
|
|
108
|
-
variant:
|
|
108
|
+
onChange: (i) => w(i.deleteId),
|
|
109
|
+
variant: V
|
|
109
110
|
}
|
|
110
111
|
) }),
|
|
111
|
-
(s === "photos" || s === "all") && /* @__PURE__ */
|
|
112
|
+
(s === "photos" || s === "all") && /* @__PURE__ */ p("div", { "data-testid-react": t == null ? void 0 : t.listPhotos, children: /* @__PURE__ */ p(
|
|
112
113
|
Y,
|
|
113
114
|
{
|
|
114
115
|
value: I,
|
|
115
|
-
onChange: (
|
|
116
|
-
loadImage:
|
|
117
|
-
isDownloadingImage:
|
|
116
|
+
onChange: (i) => w(i.deleteId),
|
|
117
|
+
loadImage: _,
|
|
118
|
+
isDownloadingImage: j
|
|
118
119
|
}
|
|
119
120
|
) })
|
|
120
121
|
] })
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
import { imageTypesArr } from './constants';
|
|
3
2
|
import { TDataTestIdReactMap } from '../../types';
|
|
4
3
|
import { EButtonSize } from '../Button';
|
|
5
4
|
import { TButtonDefaultFormProps } from '../Button/types';
|
|
@@ -9,7 +8,7 @@ export type TUploader = {
|
|
|
9
8
|
* Массив разрешенных типов файлов для настройки валидации
|
|
10
9
|
* 'jpeg' | 'jpg' | 'png' | 'tiff' | 'gif' | 'heic' | 'doc' | 'xls' | 'pdf' | 'docx' | 'txt' | 'xlsx'
|
|
11
10
|
*/
|
|
12
|
-
filesType:
|
|
11
|
+
filesType: string[];
|
|
13
12
|
/**
|
|
14
13
|
* Наименование передаваемого массива файлов
|
|
15
14
|
*/
|
|
@@ -70,6 +69,7 @@ export type TUploader = {
|
|
|
70
69
|
* Объект, для передачи в компонент и его элементы data-testid-react, для автоматизированного тестирования
|
|
71
70
|
*/
|
|
72
71
|
dataTestIdReactMap?: TDataTestIdReactMap<'wrapper' | 'input' | 'label' | 'button' | 'buttonIcon' | 'title' | 'description'>;
|
|
72
|
+
accept?: Record<string, string>;
|
|
73
73
|
};
|
|
74
74
|
export type TUploadValue = {
|
|
75
75
|
value: TFileItem[];
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { jsxs as r, jsx as l, Fragment as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { Icon as
|
|
4
|
-
import { Button as
|
|
5
|
-
import { EButtonVariantDefault as
|
|
6
|
-
import '../../assets/Uploader.css';const
|
|
1
|
+
import { jsxs as r, jsx as l, Fragment as L } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as G, useRef as O, useId as I } from "react";
|
|
3
|
+
import { Icon as P } from "../../icons/Icon.js";
|
|
4
|
+
import { Button as X } from "../Button/Button.js";
|
|
5
|
+
import { EButtonVariantDefault as Y } from "../Button/constants.js";
|
|
6
|
+
import '../../assets/Uploader.css';const m = {
|
|
7
7
|
"upload-file-wrapper": "_upload-file-wrapper_bplvw_2",
|
|
8
8
|
"upload-text": "_upload-text_bplvw_25",
|
|
9
9
|
"upload-file-input": "_upload-file-input_bplvw_35"
|
|
10
|
-
},
|
|
10
|
+
}, $ = {
|
|
11
11
|
jpeg: "image/jpeg",
|
|
12
12
|
jpg: "image/jpg",
|
|
13
13
|
png: "image/png",
|
|
@@ -21,50 +21,52 @@ import '../../assets/Uploader.css';const f = {
|
|
|
21
21
|
xls: "application/excel",
|
|
22
22
|
txt: "text/plain",
|
|
23
23
|
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
24
|
-
},
|
|
25
|
-
"jpeg",
|
|
26
|
-
"jpg",
|
|
27
|
-
"png",
|
|
28
|
-
"tiff",
|
|
29
|
-
"gif",
|
|
30
|
-
"heic"
|
|
31
|
-
], K = () => {
|
|
24
|
+
}, q = ["jpeg", "jpg", "png", "tiff", "gif", "heic"], H = () => {
|
|
32
25
|
let n = 0;
|
|
33
26
|
return () => (n = (n + 1) % Number.MAX_SAFE_INTEGER, n);
|
|
34
|
-
},
|
|
35
|
-
(n,
|
|
27
|
+
}, J = H(), R = G(
|
|
28
|
+
(n, v) => {
|
|
36
29
|
const {
|
|
37
|
-
filesType:
|
|
38
|
-
onChangeValue:
|
|
39
|
-
arrayName:
|
|
40
|
-
maxSize:
|
|
41
|
-
maxFiles:
|
|
42
|
-
isDisabled:
|
|
30
|
+
filesType: a = q,
|
|
31
|
+
onChangeValue: y,
|
|
32
|
+
arrayName: j,
|
|
33
|
+
maxSize: u = 15,
|
|
34
|
+
maxFiles: p,
|
|
35
|
+
isDisabled: f,
|
|
43
36
|
titleUploader: d = "Или перетащите сюда",
|
|
44
|
-
buttonText:
|
|
45
|
-
showOnlyUploadButton:
|
|
46
|
-
uploadButtonVariant:
|
|
47
|
-
buttonSize:
|
|
48
|
-
buttonClassName:
|
|
37
|
+
buttonText: N = "Выберите файлы",
|
|
38
|
+
showOnlyUploadButton: E = !1,
|
|
39
|
+
uploadButtonVariant: S = Y.SecondaryAsphalt,
|
|
40
|
+
buttonSize: F = "m",
|
|
41
|
+
buttonClassName: z,
|
|
49
42
|
onMaxFilesExceeded: s,
|
|
50
43
|
onMaxSizeExceeded: g,
|
|
51
44
|
onInvalidFileType: x,
|
|
52
|
-
dataTestIdReactMap: e
|
|
53
|
-
|
|
45
|
+
dataTestIdReactMap: e,
|
|
46
|
+
accept: U = $
|
|
47
|
+
} = n, b = O(null), h = I(), A = (i) => {
|
|
54
48
|
var o;
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
if (i.type) return i.type;
|
|
50
|
+
switch ((o = i.name.split(".").pop()) == null ? void 0 : o.toLowerCase()) {
|
|
51
|
+
case "heic":
|
|
52
|
+
return "image/heic";
|
|
53
|
+
case "msg":
|
|
54
|
+
return "application/vnd.ms-outlook";
|
|
55
|
+
default:
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
}, B = (i) => {
|
|
57
59
|
var c;
|
|
58
60
|
if (i.target.files && i.target.files[0]) {
|
|
59
61
|
const o = Array.from(i.target.files);
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
const k =
|
|
63
|
-
return !w && x && x(t.name), !
|
|
64
|
-
}).slice(0,
|
|
65
|
-
|
|
62
|
+
p && o.length > p && (s == null || s());
|
|
63
|
+
const V = o.filter((t) => {
|
|
64
|
+
const k = A(t), w = a.map((D) => U[D]).includes(k), _ = t.size / 1024 ** 2 <= u;
|
|
65
|
+
return !w && x && x(t.name), !_ && g && g(t.name), w && _;
|
|
66
|
+
}).slice(0, p).map((t) => ({ file: t, id: J() }));
|
|
67
|
+
y({ arrayName: j, value: V }), (c = i.target) != null && c.value && (i.target.value = "");
|
|
66
68
|
}
|
|
67
|
-
},
|
|
69
|
+
}, C = () => {
|
|
68
70
|
var i;
|
|
69
71
|
(i = b.current) == null || i.click();
|
|
70
72
|
};
|
|
@@ -72,23 +74,23 @@ import '../../assets/Uploader.css';const f = {
|
|
|
72
74
|
"div",
|
|
73
75
|
{
|
|
74
76
|
"data-testid-react": e == null ? void 0 : e.wrapper,
|
|
75
|
-
className:
|
|
76
|
-
ref:
|
|
77
|
+
className: m["upload-file-wrapper"],
|
|
78
|
+
ref: v,
|
|
77
79
|
children: [
|
|
78
80
|
/* @__PURE__ */ l(
|
|
79
81
|
"input",
|
|
80
82
|
{
|
|
81
83
|
"data-testid-react": e == null ? void 0 : e.input,
|
|
82
84
|
type: "file",
|
|
83
|
-
className:
|
|
85
|
+
className: m["upload-file-input"],
|
|
84
86
|
"aria-label": "Upload",
|
|
85
87
|
name: "image[]",
|
|
86
88
|
multiple: !0,
|
|
87
|
-
onChange:
|
|
89
|
+
onChange: B,
|
|
88
90
|
title: "",
|
|
89
91
|
id: h,
|
|
90
|
-
accept:
|
|
91
|
-
disabled:
|
|
92
|
+
accept: a.map((i) => `.${i}`).join(", "),
|
|
93
|
+
disabled: f
|
|
92
94
|
}
|
|
93
95
|
),
|
|
94
96
|
/* @__PURE__ */ r(
|
|
@@ -99,35 +101,35 @@ import '../../assets/Uploader.css';const f = {
|
|
|
99
101
|
ref: b,
|
|
100
102
|
children: [
|
|
101
103
|
/* @__PURE__ */ l(
|
|
102
|
-
|
|
104
|
+
X,
|
|
103
105
|
{
|
|
104
106
|
dataTestIdReactMap: {
|
|
105
107
|
button: e == null ? void 0 : e.button,
|
|
106
108
|
isIconButton: e == null ? void 0 : e.buttonIcon
|
|
107
109
|
},
|
|
108
|
-
size:
|
|
109
|
-
variant:
|
|
110
|
-
leftIcon: /* @__PURE__ */ l(
|
|
111
|
-
onClick:
|
|
112
|
-
disabled:
|
|
113
|
-
className:
|
|
114
|
-
children:
|
|
110
|
+
size: F,
|
|
111
|
+
variant: S,
|
|
112
|
+
leftIcon: /* @__PURE__ */ l(P, { iconName: "UnionIcon16px" }),
|
|
113
|
+
onClick: C,
|
|
114
|
+
disabled: f,
|
|
115
|
+
className: z,
|
|
116
|
+
children: N
|
|
115
117
|
}
|
|
116
118
|
),
|
|
117
|
-
!
|
|
119
|
+
!E && /* @__PURE__ */ r(L, { children: [
|
|
118
120
|
d && /* @__PURE__ */ l("b", { "data-testid-react": e == null ? void 0 : e.title, children: d }),
|
|
119
121
|
/* @__PURE__ */ r(
|
|
120
122
|
"span",
|
|
121
123
|
{
|
|
122
124
|
"data-testid-react": e == null ? void 0 : e.description,
|
|
123
|
-
className:
|
|
125
|
+
className: m["upload-text"],
|
|
124
126
|
children: [
|
|
125
127
|
"Максимальный размер одного файла – ",
|
|
126
|
-
|
|
128
|
+
u,
|
|
127
129
|
" Мб",
|
|
128
130
|
/* @__PURE__ */ l("br", {}),
|
|
129
131
|
"Загрузить можно файлы следующих форматов: ",
|
|
130
|
-
|
|
132
|
+
a.join(", ")
|
|
131
133
|
]
|
|
132
134
|
}
|
|
133
135
|
)
|
|
@@ -141,5 +143,5 @@ import '../../assets/Uploader.css';const f = {
|
|
|
141
143
|
}
|
|
142
144
|
);
|
|
143
145
|
export {
|
|
144
|
-
|
|
146
|
+
R as Uploader
|
|
145
147
|
};
|