@hai-dev/ui-kit 1.1.4 → 1.1.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.
@@ -1,61 +1,62 @@
1
- import { jsxs as Ro, Fragment as yo, jsx as _ } from "react/jsx-runtime";
1
+ import { jsxs as yo, Fragment as Io, jsx as _ } from "react/jsx-runtime";
2
2
  import { useState as i, useRef as w } from "react";
3
- import { D as Io } from "../../index-BiffjjQq.js";
4
- import { c as Fo } from "../../index-B2JRaoNz.js";
3
+ import { D as Fo } from "../../index-BiffjjQq.js";
4
+ import { c as No } from "../../index-B2JRaoNz.js";
5
5
  import { localizedText as Mo } from "./locale.js";
6
- import { EN_LOCALE as No } from "../../constants.js";
7
- import { DEFAULT_MIN_DIMENSION as bo, DEFAULT_ASPECT_RATIO as Ho, DEFAULT_TIMEOUT as Vo, DEFAULT_FILE_MAX_SIZE as ko, FULL_PROGRESS_VALUE as J, PHOTO_LOADING_DELAY as jo, RESET_DATA_DELAY as m } from "./constants.js";
8
- import { UploadDialog as zo } from "./components/upload-dialog/upload-dialog.js";
9
- import { UploadButton as Wo } from "./components/upload-button/upload-button.js";
10
- import { ErrorUploadDialog as Bo } from "./components/error-upload-dialog/error-upload-dialog.js";
11
- import { isVideo as K } from "./utils/is-video.js";
12
- import { validatePhotoFile as Q } from "./utils/validate-photo-file.js";
13
- import { readPhoto as $ } from "./utils/read-photo.js";
14
- import { getPhotoCrop as Go } from "./utils/get-photo-crop.js";
15
- import { getCroppedSource as Yo } from "./utils/get-cropped-source.js";
16
- import { getDefaultCroppedPhoto as oo } from "./utils/get-default-cropped-photo.js";
17
- import '../../assets/photo-crop-uploader.css';const Xo = "_photoCropCanvas_1i4lr_1", Zo = {
18
- photoCropCanvas: Xo
6
+ import { EN_LOCALE as bo } from "../../constants.js";
7
+ import { DEFAULT_MIN_DIMENSION as Ho, DEFAULT_ASPECT_RATIO as Vo, DEFAULT_TIMEOUT as ko, DEFAULT_FILE_MAX_SIZE as jo, FULL_PROGRESS_VALUE as K, PHOTO_LOADING_DELAY as zo, RESET_DATA_DELAY as m } from "./constants.js";
8
+ import { UploadDialog as Wo } from "./components/upload-dialog/upload-dialog.js";
9
+ import { UploadButton as Bo } from "./components/upload-button/upload-button.js";
10
+ import { ErrorUploadDialog as Go } from "./components/error-upload-dialog/error-upload-dialog.js";
11
+ import { isVideo as Q } from "./utils/is-video.js";
12
+ import { validatePhotoFile as $ } from "./utils/validate-photo-file.js";
13
+ import { readPhoto as oo } from "./utils/read-photo.js";
14
+ import { getPhotoCrop as Yo } from "./utils/get-photo-crop.js";
15
+ import { getCroppedSource as Xo } from "./utils/get-cropped-source.js";
16
+ import { getDefaultCroppedPhoto as eo } from "./utils/get-default-cropped-photo.js";
17
+ import '../../assets/photo-crop-uploader.css';const Zo = "_photoCropCanvas_1i4lr_1", qo = {
18
+ photoCropCanvas: Zo
19
19
  };
20
- function he(a) {
20
+ function me(a) {
21
21
  const {
22
- buttonClassname: eo = "",
23
- onStartUpload: ro = () => {
22
+ buttonClassname: ro = "",
23
+ onStartUpload: to = () => {
24
24
  },
25
- onEndUpload: to = () => {
25
+ onEndUpload: so = () => {
26
26
  },
27
27
  onError: no = () => {
28
28
  },
29
- onStartCrop: so = () => {
29
+ onStartCrop: ao = () => {
30
30
  },
31
- onDragOver: ao = () => {
31
+ onDragOver: io = () => {
32
32
  },
33
- onDragLeave: io = () => {
33
+ onDragLeave: co = () => {
34
34
  },
35
- onDragDrop: co = () => {
35
+ onDragDrop: lo = () => {
36
36
  },
37
- showErrorPopup: lo = !1,
38
- minDimension: c = bo,
39
- aspectRatio: C = Ho,
40
- locale: n = No,
41
- timeout: M = Vo,
42
- fileMaxSize: N = ko,
37
+ showErrorPopup: po = !1,
38
+ minDimension: c = Ho,
39
+ aspectRatio: C = Vo,
40
+ locale: s = bo,
41
+ timeout: N = ko,
42
+ fileMaxSize: M = jo,
43
43
  allowedExtensions: U,
44
44
  allowedMimeTypes: b,
45
- circular: po,
46
- width: uo,
47
- keepSelection: fo,
48
- uploadButton: ho,
45
+ circular: uo,
46
+ width: fo,
47
+ keepSelection: ho,
48
+ uploadButton: mo,
49
49
  multiple: g = !1,
50
50
  fromSources: H,
51
51
  withVideoUploaded: A = !1,
52
- returnCropParams: mo = !1,
53
- ...Co
54
- } = a, {
55
- onEndCrop: qo,
56
- onClose: Jo,
52
+ returnCropParams: Co = !1,
53
+ dialogClassname: V,
57
54
  ...go
58
- } = Co, [Eo, E] = i(!1), [P, D] = i([]), [x, v] = i([]), f = w([]), h = w([]), [p, V] = i(0), k = w(null), j = w(null), [l, O] = i(!1), [Po, z] = i(0), [W, B] = i(""), [Do, S] = i([]), [So, G] = i(!1), Lo = Eo || l && g, To = () => {
55
+ } = a, {
56
+ onEndCrop: Jo,
57
+ onClose: Ko,
58
+ ...Eo
59
+ } = go, [Po, E] = i(!1), [P, D] = i([]), [x, v] = i([]), f = w([]), h = w([]), [p, k] = i(0), j = w(null), z = w(null), [l, O] = i(!1), [Do, W] = i(0), [B, G] = i(""), [So, S] = i([]), [Lo, Y] = i(!1), To = Po || l && g, _o = () => {
59
60
  S([]);
60
61
  }, R = (o = []) => {
61
62
  l || (a.returnCropParams === !0 && a.onClose?.(
@@ -73,70 +74,70 @@ function he(a) {
73
74
  ), E(!1), setTimeout(() => S([]), m), setTimeout(() => D([]), m), setTimeout(() => {
74
75
  f.current = [], h.current = [];
75
76
  }, m));
76
- }, Y = () => {
77
+ }, X = () => {
77
78
  l || (a.returnCropParams === !0 ? R([]) : y([]));
78
- }, _o = () => {
79
- G(!1);
79
+ }, wo = () => {
80
+ Y(!1);
80
81
  }, L = (o, r = o, e = []) => {
81
- to(o), B(""), D(o), v(Array(o.length)), V(0), E(!0), f.current = r, h.current = e, o.length || Y();
82
+ so(o), G(""), D(o), v(Array(o.length)), k(0), E(!0), f.current = r, h.current = e, o.length || X();
82
83
  }, I = (o) => {
83
- o instanceof Error && (console.warn(o.message), no(o), B(o.message), G(!0), D([]), E(!1), f.current = [], h.current = []);
84
- }, wo = async (o) => {
84
+ o instanceof Error && (console.warn(o.message), no(o), G(o.message), Y(!0), D([]), E(!1), f.current = [], h.current = []);
85
+ }, Uo = async (o) => {
85
86
  const { files: r } = o.target;
86
87
  if (r?.length && !l)
87
88
  try {
88
- if (O(!0), ro(), g) {
89
- const e = Array.from(r), t = J / e.length, T = [], u = [], Z = [], F = [];
89
+ if (O(!0), to(), g) {
90
+ const e = Array.from(r), t = K / e.length, T = [], u = [], q = [], F = [];
90
91
  for (const d of e) {
91
- const Oo = K(d);
92
+ const Ro = Q(d);
92
93
  try {
93
- if (A && Oo) {
94
- const s = URL.createObjectURL(d);
95
- Z.push(u.length), u.push(s);
94
+ if (A && Ro) {
95
+ const n = URL.createObjectURL(d);
96
+ q.push(u.length), u.push(n);
96
97
  } else {
97
- Q(
98
+ $(
98
99
  d,
99
100
  {
100
- maxSize: N,
101
+ maxSize: M,
101
102
  allowedExtensions: U,
102
103
  allowedMimeTypes: b
103
104
  },
104
- n
105
+ s
105
106
  );
106
- const s = await $(
107
+ const n = await oo(
107
108
  d,
108
109
  c,
109
- n,
110
- M
110
+ s,
111
+ N
111
112
  );
112
- T.push(s), u.push(s);
113
+ T.push(n), u.push(n);
113
114
  }
114
- } catch (s) {
115
- let q = "";
116
- s instanceof Error && (q = s.message), F.push({
115
+ } catch (n) {
116
+ let J = "";
117
+ n instanceof Error && (J = n.message), F.push({
117
118
  photoName: d.name,
118
- errorMessage: q
119
+ errorMessage: J
119
120
  });
120
121
  }
121
- z(
122
- (s) => Math.min(J, s + t)
123
- ), await new Promise((s) => setTimeout(s, 0));
122
+ W(
123
+ (n) => Math.min(K, n + t)
124
+ ), await new Promise((n) => setTimeout(n, 0));
124
125
  }
125
126
  if (H?.length)
126
127
  throw new Error(F[0]?.errorMessage);
127
- S(F), L(T, u, Z);
128
+ S(F), L(T, u, q);
128
129
  } else {
129
130
  const e = r[0];
130
- if (A && K(e)) {
131
+ if (A && Q(e)) {
131
132
  const t = URL.createObjectURL(e);
132
133
  L([], [t], [0]);
133
134
  } else {
134
- Q(
135
+ $(
135
136
  e,
136
- { maxSize: N, allowedExtensions: U, allowedMimeTypes: b },
137
- n
137
+ { maxSize: M, allowedExtensions: U, allowedMimeTypes: b },
138
+ s
138
139
  );
139
- const t = await $(e, c, n, M);
140
+ const t = await oo(e, c, s, N);
140
141
  L([t]);
141
142
  }
142
143
  }
@@ -144,35 +145,35 @@ function he(a) {
144
145
  I(e);
145
146
  } finally {
146
147
  g ? setTimeout(() => {
147
- o.target.value = "", z(0), O(!1);
148
- }, jo) : (o.target.value = "", O(!1));
148
+ o.target.value = "", W(0), O(!1);
149
+ }, zo) : (o.target.value = "", O(!1));
149
150
  }
150
- }, Uo = (o) => {
151
- const { width: r, height: e } = o.currentTarget, t = Go(r, e, c, C);
151
+ }, Ao = (o) => {
152
+ const { width: r, height: e } = o.currentTarget, t = Yo(r, e, c, C);
152
153
  v((T) => {
153
154
  const u = [...T];
154
155
  return u[p] = t, u;
155
156
  });
156
- }, Ao = (o, r) => {
157
+ }, xo = (o, r) => {
157
158
  v((e) => {
158
159
  const t = [...e];
159
160
  return t[p] = r, t;
160
161
  });
161
- }, X = () => {
162
- const o = j.current, r = k.current;
162
+ }, Z = () => {
163
+ const o = z.current, r = j.current;
163
164
  if (o && r && x)
164
165
  try {
165
166
  const e = x[p];
166
167
  if (!e) return !1;
167
- if (so(), a.returnCropParams === !0) {
168
- const t = Io(e, r.naturalWidth, r.naturalHeight);
168
+ if (ao(), a.returnCropParams === !0) {
169
+ const t = Fo(e, r.naturalWidth, r.naturalHeight);
169
170
  a.onEndCrop?.(t), p >= P.length - 1 && R();
170
171
  } else {
171
- const t = Yo(
172
+ const t = Xo(
172
173
  r,
173
174
  o,
174
175
  e,
175
- n
176
+ s
176
177
  );
177
178
  a.onEndCrop?.(t), p >= P.length - 1 && y();
178
179
  }
@@ -182,19 +183,19 @@ function he(a) {
182
183
  }
183
184
  else
184
185
  return !1;
185
- }, xo = () => {
186
- X() && V((r) => r + 1);
187
- }, vo = async () => {
186
+ }, vo = () => {
187
+ Z() && k((r) => r + 1);
188
+ }, Oo = async () => {
188
189
  const o = P.slice(p);
189
190
  try {
190
- if (mo) {
191
+ if (Co) {
191
192
  const r = await Promise.all(
192
193
  o.map(
193
- (e) => oo(
194
+ (e) => eo(
194
195
  e,
195
196
  c,
196
197
  C,
197
- n,
198
+ s,
198
199
  !0
199
200
  )
200
201
  )
@@ -203,11 +204,11 @@ function he(a) {
203
204
  } else {
204
205
  const r = await Promise.all(
205
206
  o.map(
206
- (e) => oo(
207
+ (e) => eo(
207
208
  e,
208
209
  c,
209
210
  C,
210
- n,
211
+ s,
211
212
  !1
212
213
  )
213
214
  )
@@ -218,75 +219,77 @@ function he(a) {
218
219
  I(r);
219
220
  }
220
221
  };
221
- return /* @__PURE__ */ Ro(yo, { children: [
222
+ return /* @__PURE__ */ yo(Io, { children: [
222
223
  /* @__PURE__ */ _(
223
- Wo,
224
+ Bo,
224
225
  {
225
- onChange: wo,
226
+ onChange: Uo,
226
227
  onPhotoDataLoaded: L,
227
- buttonClassname: eo,
228
+ buttonClassname: ro,
228
229
  disabled: l,
229
230
  buttonDisabled: l,
230
- locale: n,
231
- width: uo,
231
+ locale: s,
232
+ width: fo,
232
233
  allowedExtensions: U,
233
- onDragDrop: co,
234
- onDragLeave: io,
235
- onDragOver: ao,
236
- button: ho,
234
+ onDragDrop: lo,
235
+ onDragLeave: co,
236
+ onDragOver: io,
237
+ button: mo,
237
238
  multiple: g,
238
239
  fromSources: H,
239
240
  withVideoUploaded: A,
240
- ...go,
241
- children: Mo[n].upload
241
+ ...Eo,
242
+ children: Mo[s].upload
242
243
  }
243
244
  ),
244
245
  /* @__PURE__ */ _(
245
- zo,
246
+ Wo,
246
247
  {
247
- open: Lo,
248
+ open: To,
249
+ className: V,
248
250
  photoSourceLoading: l,
249
- loadingValue: Po,
250
- errors: Do,
251
+ loadingValue: Do,
252
+ errors: So,
251
253
  photoCrops: x,
252
254
  photoSources: P,
253
- onNextPhoto: xo,
254
- onSkipCrop: vo,
255
- onClearErrors: To,
256
- photoError: W,
257
- onCloseDialogHandler: Y,
258
- onCropChange: Ao,
259
- onPhotoCrop: X,
260
- onPhotoLoad: Uo,
261
- imageRef: k,
255
+ onNextPhoto: vo,
256
+ onSkipCrop: Oo,
257
+ onClearErrors: _o,
258
+ photoError: B,
259
+ onCloseDialogHandler: X,
260
+ onCropChange: xo,
261
+ onPhotoCrop: Z,
262
+ onPhotoLoad: Ao,
263
+ imageRef: j,
262
264
  minDimension: c,
263
265
  aspectRatio: C,
264
- locale: n,
265
- circular: po,
266
- keepSelection: fo,
266
+ locale: s,
267
+ circular: uo,
268
+ keepSelection: ho,
267
269
  photoIndex: p
268
270
  }
269
271
  ),
270
272
  /* @__PURE__ */ _(
271
- Bo,
273
+ Go,
272
274
  {
273
- open: lo && So,
274
- photoError: W,
275
- onCloseErrorDialog: _o,
276
- locale: n
275
+ className: V,
276
+ open: po && Lo,
277
+ photoError: B,
278
+ onCloseErrorDialog: wo,
279
+ locale: s
277
280
  }
278
281
  ),
279
282
  /* @__PURE__ */ _(
280
283
  "canvas",
281
284
  {
282
- className: Fo(Zo.photoCropCanvas),
285
+ className: No(qo.photoCropCanvas),
283
286
  width: c,
284
287
  height: c,
285
- ref: j
288
+ ref: z
286
289
  }
287
290
  )
288
291
  ] });
289
292
  }
290
293
  export {
291
- he as PhotoCropUploader
294
+ me as PhotoCropUploader
292
295
  };
@@ -49,6 +49,7 @@ export type PhotoCropUploaderCustomProps = {
49
49
  uploadButton?: ReactNode;
50
50
  fromSources?: PhotoDataUrl[];
51
51
  withVideoUploaded?: boolean;
52
+ dialogClassname?: string;
52
53
  };
53
54
  export type PhotoCropUploaderProps = PhotoCropUploaderCustomProps & CropProps & InputHTMLAttributes<HTMLInputElement>;
54
55
  export type PhotoCropUploaderLocaleText = Record<Locale, Record<string, string>>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hai-dev/ui-kit",
3
3
  "private": false,
4
- "version": "1.1.4",
4
+ "version": "1.1.5",
5
5
  "license": "UNLICENSED",
6
6
  "author": {
7
7
  "name": "Vladislav Knitrunov",