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 F, jsx as n, Fragment as k } from "react/jsx-runtime";
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 w = {
10
+ import '../../assets/UploaderPhotos.css';const g = {
12
11
  "upload-file-wrapper": "_upload-file-wrapper_1a115_2"
13
- }, c = (r) => "file" in r && r.file instanceof File ? g.includes(r.file.type) : "type" in r && typeof r.type == "string" ? g.includes(r.type) : !1, le = G(
14
- (r, x) => {
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: z,
18
- arrayName: P,
19
- maxSize: U,
20
- onChange: o,
21
- value: p,
22
- maxFiles: d,
23
- titleUploader: b,
24
- buttonText: D = "Выберите файлы",
25
- showOnlyUploadButton: h = !1,
26
- uploadButtonVariant: E = Q.SecondaryAsphalt,
27
- buttonSize: S = "m",
28
- buttonClassName: V,
29
- variantListFiles: L = X.white,
30
- onMaxFilesExceeded: N,
31
- onMaxSizeExceeded: B,
32
- onInvalidFileType: _,
33
- loadImage: j,
34
- isDownloadingImage: A,
35
- dataTestIdReactMap: i
36
- } = r, [a, m] = H(
37
- p || []
38
- ), y = !!d && a.length >= d;
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
- p && m(p);
41
- }, [p]);
42
- const C = (t) => {
43
- const l = t.value.map((e) => c(e.file) ? new Promise((f) => {
44
- const u = new FileReader();
45
- u.onload = () => {
46
- f({
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: u.result,
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
- }, u.readAsDataURL(e.file);
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(l).then((e) => {
62
- m((f) => [...f, ...e]), o == null || o({ type: "add", data: t.value });
61
+ Promise.all(o).then((e) => {
62
+ u((c) => [...c, ...e]), l == null || l({ type: "add", data: i.value });
63
63
  });
64
- }, v = (t) => {
65
- m((l) => l.filter((e) => e.id !== t)), o == null || o({ type: "delete", data: t });
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 t = () => a.filter((e) => !c(e)), l = () => a.filter(c);
68
- return s === "all" ? { files: t(), photos: l() } : s === "files" ? { photos: [], files: t() } : s === "photos" ? { files: [], photos: l() } : { files: [], photos: [] };
69
- }, [a, s]);
70
- return /* @__PURE__ */ F(
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": i == null ? void 0 : i.wrapper,
74
+ "data-testid-react": t == null ? void 0 : t.wrapper,
75
75
  className: q(
76
- w["upload-file-wrapper"],
77
- y && w.disabled
76
+ g["upload-file-wrapper"],
77
+ F && g.disabled
78
78
  ),
79
79
  children: [
80
- /* @__PURE__ */ n(
80
+ /* @__PURE__ */ p(
81
81
  Z,
82
82
  {
83
- dataTestIdReactMap: { wrapper: i == null ? void 0 : i.uploader },
84
- filesType: z,
85
- arrayName: P,
86
- maxSize: U,
83
+ dataTestIdReactMap: { wrapper: t == null ? void 0 : t.uploader },
84
+ filesType: a,
85
+ arrayName: z,
86
+ maxSize: P,
87
87
  onChangeValue: C,
88
- ref: x,
89
- maxFiles: d && d - a.length,
90
- isDisabled: y,
91
- titleUploader: b,
92
- showOnlyUploadButton: h,
93
- buttonText: D,
94
- uploadButtonVariant: E,
95
- buttonSize: S,
96
- buttonClassName: V,
97
- onMaxFilesExceeded: N,
98
- onMaxSizeExceeded: B,
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
- !h && /* @__PURE__ */ F(k, { children: [
103
- (s === "files" || s === "all") && /* @__PURE__ */ n("div", { "data-testid-react": i == null ? void 0 : i.listFiles, children: /* @__PURE__ */ n(
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: (t) => v(t.deleteId),
108
- variant: L
108
+ onChange: (i) => w(i.deleteId),
109
+ variant: V
109
110
  }
110
111
  ) }),
111
- (s === "photos" || s === "all") && /* @__PURE__ */ n("div", { "data-testid-react": i == null ? void 0 : i.listPhotos, children: /* @__PURE__ */ n(
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: (t) => v(t.deleteId),
116
- loadImage: j,
117
- isDownloadingImage: A
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: imageTypesArr[];
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 G } from "react/jsx-runtime";
2
- import { forwardRef as O, useRef as L, useId as X } from "react";
3
- import { Icon as q } from "../../icons/Icon.js";
4
- import { Button as H } from "../Button/Button.js";
5
- import { EButtonVariantDefault as I } from "../Button/constants.js";
6
- import '../../assets/Uploader.css';const f = {
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
- }, v = {
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
- }, J = [
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
- }, P = K(), T = O(
35
- (n, _) => {
27
+ }, J = H(), R = G(
28
+ (n, v) => {
36
29
  const {
37
- filesType: p = J,
38
- onChangeValue: j,
39
- arrayName: N,
40
- maxSize: m = 15,
41
- maxFiles: a,
42
- isDisabled: u,
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: z = "Выберите файлы",
45
- showOnlyUploadButton: S = !1,
46
- uploadButtonVariant: B = I.SecondaryAsphalt,
47
- buttonSize: C = "m",
48
- buttonClassName: E,
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
- } = n, b = L(null), h = X(), F = (i) => {
45
+ dataTestIdReactMap: e,
46
+ accept: U = $
47
+ } = n, b = O(null), h = I(), A = (i) => {
54
48
  var o;
55
- return i.type ? i.type : ((o = i.name.split(".").pop()) == null ? void 0 : o.toLowerCase()) === "heic" ? "image/heic" : "";
56
- }, U = (i) => {
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
- a && o.length > a && (s == null || s());
61
- const A = o.filter((t) => {
62
- const k = F(t), w = p.map((D) => v[D]).includes(k), y = t.size / 1024 ** 2 <= m;
63
- return !w && x && x(t.name), !y && g && g(t.name), w && y;
64
- }).slice(0, a).map((t) => ({ file: t, id: P() }));
65
- j({ arrayName: N, value: A }), (c = i.target) != null && c.value && (i.target.value = "");
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
- }, V = () => {
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: f["upload-file-wrapper"],
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: f["upload-file-input"],
85
+ className: m["upload-file-input"],
84
86
  "aria-label": "Upload",
85
87
  name: "image[]",
86
88
  multiple: !0,
87
- onChange: U,
89
+ onChange: B,
88
90
  title: "",
89
91
  id: h,
90
- accept: p.map((i) => v[i]).join(),
91
- disabled: u
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
- H,
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: C,
109
- variant: B,
110
- leftIcon: /* @__PURE__ */ l(q, { iconName: "UnionIcon16px" }),
111
- onClick: V,
112
- disabled: u,
113
- className: E,
114
- children: z
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
- !S && /* @__PURE__ */ r(G, { children: [
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: f["upload-text"],
125
+ className: m["upload-text"],
124
126
  children: [
125
127
  "Максимальный размер одного файла – ",
126
- m,
128
+ u,
127
129
  " Мб",
128
130
  /* @__PURE__ */ l("br", {}),
129
131
  "Загрузить можно файлы следующих форматов: ",
130
- p.join(", ")
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
- T as Uploader
146
+ R as Uploader
145
147
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mimir-ui-kit",
3
3
  "private": false,
4
- "version": "1.63.0",
4
+ "version": "1.64.0",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {