jaguar-form 1.0.4 → 1.0.6

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.
Files changed (64) hide show
  1. package/README.md +38 -2
  2. package/dist/Cascader-ZIkXvvC3.js +226 -0
  3. package/dist/Select-BIBk_TT6.js +415 -0
  4. package/dist/TreeSelect-BQCyCCqa.js +350 -0
  5. package/dist/{compound-D4_6P0d_.js → compound-BX_PoTK5.js} +100 -88
  6. package/dist/compound.js +1 -1
  7. package/dist/core.js +1 -1
  8. package/dist/date-time.js +1 -1
  9. package/dist/demo-plant.svg +1 -0
  10. package/dist/form-CSfUExUT.js +599 -0
  11. package/dist/form.js +3 -3
  12. package/dist/{icons-BI3fdIey.js → icons-BwE05e0C.js} +1 -1
  13. package/dist/{image-upload-VtUlQgzJ.js → image-upload-D9oPG0Eh.js} +252 -179
  14. package/dist/image-upload.js +1 -1
  15. package/dist/index.js +15 -14
  16. package/dist/input.js +1 -1
  17. package/dist/inputs-Dx3xOy9q.js +718 -0
  18. package/dist/{useSelection-C0OEFZUE.js → lazy-tree-NCX3ntYm.js} +96 -4
  19. package/dist/locale/load.js +7 -3
  20. package/dist/pickers-Bci1y8cc.js +634 -0
  21. package/dist/select.js +3 -1
  22. package/dist/selection-DCIzhR5q.js +197 -0
  23. package/dist/{slider-CNwkLMmo.js → slider-AM0Egz9P.js} +1 -1
  24. package/dist/slider.js +1 -1
  25. package/dist/store-CFSQW-Fv.js +622 -0
  26. package/dist/style.css +1 -1
  27. package/dist/tree-select.js +1 -1
  28. package/dist/types/components/compound/ControlGroup.d.ts +5 -2
  29. package/dist/types/components/compound/index.d.ts +10 -1
  30. package/dist/types/components/extended-inputs.d.ts +34 -0
  31. package/dist/types/components/image-upload/ManagedImageUpload.d.ts +11 -4
  32. package/dist/types/components/image-upload/index.d.ts +3 -2
  33. package/dist/types/components/image-upload/upload.d.ts +1 -1
  34. package/dist/types/components/image-upload/usePreparation.d.ts +7 -0
  35. package/dist/types/components/image-upload/validation.d.ts +16 -0
  36. package/dist/types/components/inputs.d.ts +42 -4
  37. package/dist/types/components/select/Cascader.d.ts +13 -0
  38. package/dist/types/components/select/types.d.ts +10 -1
  39. package/dist/types/components/select/useRemoteOptions.d.ts +18 -0
  40. package/dist/types/components/select.d.ts +3 -0
  41. package/dist/types/config/index.d.ts +3 -0
  42. package/dist/types/entries/input.d.ts +5 -2
  43. package/dist/types/entries/select.d.ts +3 -0
  44. package/dist/types/form/adapter.d.ts +1 -0
  45. package/dist/types/form/index.d.ts +85 -10
  46. package/dist/types/form/store.d.ts +21 -1
  47. package/dist/types/locale/load.d.ts +2 -1
  48. package/dist/types/primitives/Control.d.ts +3 -1
  49. package/dist/types/primitives/Popup.d.ts +1 -0
  50. package/dist/types/types.d.ts +1 -0
  51. package/dist/types/utils/cascader.d.ts +12 -0
  52. package/dist/types/utils/decimal.d.ts +22 -0
  53. package/dist/types/utils/remote-options.d.ts +24 -0
  54. package/dist/useControllable-QDX_UWRh.js +102 -0
  55. package/package.json +1 -1
  56. package/dist/Control-B36bu6zQ.js +0 -47
  57. package/dist/Select-BG2H-YnK.js +0 -252
  58. package/dist/TreeSelect-CkPtMg-g.js +0 -440
  59. package/dist/form-DTI0Sqsy.js +0 -413
  60. package/dist/inputs-BOP8Ryne.js +0 -403
  61. package/dist/pickers-C9QTR2XN.js +0 -631
  62. package/dist/selection-CIEa1uce.js +0 -146
  63. package/dist/store-DOn9K-EA.js +0 -491
  64. package/dist/useControllable-Zax42z2F.js +0 -87
@@ -1,6 +1,6 @@
1
1
  import { useEffect as e, useId as t, useLayoutEffect as n, useRef as r, useState as i } from "react";
2
- import { a, i as o, s, t as c } from "./useControllable-Zax42z2F.js";
3
- import { t as l } from "./icons-BI3fdIey.js";
2
+ import { a, i as o, s, t as c } from "./useControllable-QDX_UWRh.js";
3
+ import { t as l } from "./icons-BwE05e0C.js";
4
4
  import { jsx as u, jsxs as d } from "react/jsx-runtime";
5
5
  // src/components/image-upload/validation.ts
6
6
  var f = "image/jpeg,image/png,image/webp";
@@ -28,9 +28,21 @@ function h(e, t, n) {
28
28
  let r = [...e];
29
29
  return r.splice(n, 0, r.splice(t, 1)[0]), r;
30
30
  }
31
+ function g(e, t, n, r = !1) {
32
+ let i = r && t === 1 && e >= 1;
33
+ return {
34
+ full: e >= t && !i,
35
+ replacing: i,
36
+ remaining: i ? 1 : Math.max(0, t - e)
37
+ };
38
+ }
39
+ function _(e, t = 3) {
40
+ let n = Number.isFinite(t) ? Math.max(0, Math.floor(t)) : 3;
41
+ return e ? n : Math.min(1, n);
42
+ }
31
43
  // src/components/image-upload/sorting.tsx
32
- var g = "application/x-rfe-image-sort";
33
- function _(e, n, a) {
44
+ var v = "application/x-rfe-image-sort";
45
+ function y(e, n, a) {
34
46
  let o = t(), s = r(null), [c, l] = i(null), u = (t, r) => {
35
47
  a && t !== r && t >= 0 && r >= 0 && t < e.length && r < e.length && n(h(e, t, r));
36
48
  }, d = () => {
@@ -41,13 +53,13 @@ function _(e, n, a) {
41
53
  row: (e) => ({
42
54
  "data-sort-over": c === e || void 0,
43
55
  onDragOver: (t) => {
44
- a && s.current !== null && t.dataTransfer.types.includes(g) && (t.preventDefault(), t.stopPropagation(), t.dataTransfer.dropEffect = "move", l(e));
56
+ a && s.current !== null && t.dataTransfer.types.includes(v) && (t.preventDefault(), t.stopPropagation(), t.dataTransfer.dropEffect = "move", l(e));
45
57
  },
46
58
  onDragLeave: (t) => {
47
59
  t.relatedTarget instanceof Node && t.currentTarget.contains(t.relatedTarget) || l((t) => t === e ? null : t);
48
60
  },
49
61
  onDrop: (t) => {
50
- if (s.current === null || t.dataTransfer.getData(g) !== o) return;
62
+ if (s.current === null || t.dataTransfer.getData(v) !== o) return;
51
63
  t.preventDefault(), t.stopPropagation();
52
64
  let n = s.current;
53
65
  d(), u(n, e);
@@ -55,12 +67,12 @@ function _(e, n, a) {
55
67
  }),
56
68
  move: u,
57
69
  dragStart: (e, t) => {
58
- a ? (s.current = e, t.dataTransfer.effectAllowed = "move", t.dataTransfer.setData(g, o), t.dataTransfer.setData("text/plain", o)) : t.preventDefault();
70
+ a ? (s.current = e, t.dataTransfer.effectAllowed = "move", t.dataTransfer.setData(v, o), t.dataTransfer.setData("text/plain", o)) : t.preventDefault();
59
71
  },
60
72
  reset: d
61
73
  };
62
74
  }
63
- function v({ index: e, count: t, name: n, onMove: r, onDragStart: i, onDragEnd: o }) {
75
+ function b({ index: e, count: t, name: n, onMove: r, onDragStart: i, onDragEnd: o }) {
64
76
  let { t: s } = a();
65
77
  return /* @__PURE__ */ d("div", {
66
78
  className: "rfe-image-sort",
@@ -95,8 +107,46 @@ function v({ index: e, count: t, name: n, onMove: r, onDragStart: i, onDragEnd:
95
107
  ]
96
108
  });
97
109
  }
110
+ // src/components/image-upload/usePreparation.ts
111
+ function x(t, n) {
112
+ let a = r(null), [o, s] = i(!1), c = () => {
113
+ a.current?.abort(), a.current = null, s(!1);
114
+ };
115
+ return e(() => () => {
116
+ a.current?.abort(), a.current = null;
117
+ }, []), e(() => {
118
+ n && c();
119
+ }, [n]), {
120
+ busy: o,
121
+ cancel: c,
122
+ prepare: async (e, r) => {
123
+ if (n || a.current) return;
124
+ if (!t.beforeUpload) {
125
+ r(e);
126
+ return;
127
+ }
128
+ let i = new AbortController();
129
+ a.current = i, s(!0);
130
+ try {
131
+ let n = [];
132
+ for (let r of e) {
133
+ if (i.signal.aborted) return;
134
+ try {
135
+ let e = await t.beforeUpload(r, { signal: i.signal });
136
+ e !== !1 && n.push(e);
137
+ } catch (e) {
138
+ i.signal.aborted || t.onPrepareError?.(e, r);
139
+ }
140
+ }
141
+ !i.signal.aborted && a.current === i && r(n);
142
+ } finally {
143
+ a.current === i && (a.current = null, s(!1));
144
+ }
145
+ }
146
+ };
147
+ }
98
148
  // src/components/image-upload/upload.ts
99
- function y(e) {
149
+ function S(e) {
100
150
  if (typeof e != "string" || !e.trim()) return !1;
101
151
  try {
102
152
  return ["http:", "https:"].includes(new URL(e, "https://example.invalid").protocol);
@@ -104,14 +154,14 @@ function y(e) {
104
154
  return !1;
105
155
  }
106
156
  }
107
- var b = { validate: (e) => {
157
+ var C = { validate: (e) => {
108
158
  if (e != null) {
109
159
  if (!Array.isArray(e)) return { code: "invalidType" };
110
160
  if (e.some((e) => e?.status === "uploading" || e?.status === "ready")) return { code: "processing" };
111
- if (e.some((e) => e?.status !== "success" || !y(e.url))) return { code: "validationFailed" };
161
+ if (e.some((e) => e?.status !== "success" || !S(e.url))) return { code: "validationFailed" };
112
162
  }
113
163
  } };
114
- function x(e) {
164
+ function w(e) {
115
165
  let t = /* @__PURE__ */ new Map(), n = (e) => {
116
166
  let n = t.get(e);
117
167
  n && (t.delete(e), n.abort());
@@ -145,7 +195,7 @@ function x(e) {
145
195
  });
146
196
  if (!o()) return !1;
147
197
  let s = typeof n == "string" ? n : n.url;
148
- if (!y(s)) throw Error("Invalid uploaded image URL");
198
+ if (!S(s)) throw Error("Invalid uploaded image URL");
149
199
  return t.delete(r.uid), e(r.uid, {
150
200
  url: s,
151
201
  name: typeof n == "string" ? r.name : n.name ?? r.name,
@@ -164,9 +214,9 @@ function x(e) {
164
214
  };
165
215
  }
166
216
  // src/components/image-upload/ManagedImageUpload.tsx
167
- var S = [], C = 0;
217
+ var T = [], E = 0;
168
218
  function ee({ item: t, blocked: n, preview: o, onRemove: s, onRetry: c, onCancel: f, icons: p, sortActions: m, sortProps: h }) {
169
- let { t: g } = a(), [_, v] = i(""), [b, x] = i(!1), S = r(null);
219
+ let { t: g } = a(), [_, v] = i(""), [y, b] = i(!1), x = r(null);
170
220
  e(() => {
171
221
  if (!t.file) {
172
222
  v("");
@@ -175,8 +225,8 @@ function ee({ item: t, blocked: n, preview: o, onRemove: s, onRetry: c, onCancel
175
225
  let e = URL.createObjectURL(t.file);
176
226
  return v(e), () => URL.revokeObjectURL(e);
177
227
  }, [t.file]);
178
- let C = y(t.url) ? t.url : _;
179
- return e(() => x(!1), [C]), /* @__PURE__ */ d("div", {
228
+ let C = S(t.url) ? t.url : _;
229
+ return e(() => b(!1), [C]), /* @__PURE__ */ d("div", {
180
230
  className: "rfe-image-tile",
181
231
  "data-upload-status": t.status,
182
232
  ...h,
@@ -184,19 +234,19 @@ function ee({ item: t, blocked: n, preview: o, onRemove: s, onRetry: c, onCancel
184
234
  /* @__PURE__ */ d("div", {
185
235
  className: "rfe-image-media",
186
236
  children: [
187
- C && !b ? /* @__PURE__ */ u("img", {
237
+ C && !y ? /* @__PURE__ */ u("img", {
188
238
  src: C,
189
239
  alt: t.name,
190
- onError: () => x(!0)
240
+ onError: () => b(!0)
191
241
  }) : /* @__PURE__ */ u("div", {
192
242
  className: "rfe-image-placeholder",
193
243
  children: /* @__PURE__ */ u(l, { name: "empty" })
194
244
  }),
195
- o && C && !b && /* @__PURE__ */ u("button", {
245
+ o && C && !y && /* @__PURE__ */ u("button", {
196
246
  type: "button",
197
247
  className: "rfe-image-preview",
198
248
  "aria-label": `${g("preview")} ${t.name}`,
199
- onClick: () => S.current?.showModal(),
249
+ onClick: () => x.current?.showModal(),
200
250
  children: /* @__PURE__ */ u(l, {
201
251
  name: "passwordVisible",
202
252
  source: p?.preview
@@ -258,17 +308,17 @@ function ee({ item: t, blocked: n, preview: o, onRemove: s, onRetry: c, onCancel
258
308
  }),
259
309
  m,
260
310
  o && /* @__PURE__ */ d("dialog", {
261
- ref: S,
311
+ ref: x,
262
312
  className: "rfe-image-dialog",
263
313
  "aria-label": t.name,
264
314
  onClick: (e) => {
265
- e.target === e.currentTarget && S.current?.close();
315
+ e.target === e.currentTarget && x.current?.close();
266
316
  },
267
317
  children: [/* @__PURE__ */ u("button", {
268
318
  type: "button",
269
319
  className: "rfe-image-dialog-close",
270
320
  "aria-label": g("closePreview"),
271
- onClick: () => S.current?.close(),
321
+ onClick: () => x.current?.close(),
272
322
  children: /* @__PURE__ */ u(l, { name: "clear" })
273
323
  }), C && /* @__PURE__ */ u("img", {
274
324
  src: C,
@@ -278,113 +328,126 @@ function ee({ item: t, blocked: n, preview: o, onRemove: s, onRetry: c, onCancel
278
328
  ]
279
329
  });
280
330
  }
281
- function w(c) {
282
- let { t: f } = a(), p = o(), h = t(), g = c.id ?? h, [y, b] = i(c.defaultValue ?? S), w = c.value ?? y, T = r(w), E = r(() => {}), [D] = i(() => x((e, t) => {
283
- T.current.some((t) => t.uid === e) && E.current(T.current.map((n) => n.uid === e ? {
331
+ function D(c) {
332
+ let { t: f } = a(), p = o(), h = t(), v = c.id ?? h, [S, C] = i(c.defaultValue ?? T), D = c.value ?? S, O = r(D), k = r(() => {}), [A] = i(() => w((e, t) => {
333
+ O.current.some((t) => t.uid === e) && k.current(O.current.map((n) => n.uid === e ? {
284
334
  ...n,
285
335
  ...t
286
336
  } : n));
287
- })), [O, k] = i([]), [A, j] = i(!1), M = r(null);
337
+ })), [j, te] = i([]), [ne, M] = i(!1), N = r(null);
288
338
  n(() => {
289
- T.current = w, E.current = (e) => {
290
- T.current = e, c.value === void 0 && b(e), c.onChange?.(e);
291
- }, D.retain(new Set(w.filter((e) => e.status === "uploading").map((e) => e.uid)));
339
+ O.current = D, k.current = (e) => {
340
+ O.current = e, c.value === void 0 && C(e), c.onChange?.(e);
341
+ }, A.retain(new Set(D.filter((e) => e.status === "uploading").map((e) => e.uid)));
292
342
  }, [
293
- w,
343
+ D,
294
344
  c.value,
295
345
  c.onChange,
296
- D
297
- ]), e(() => () => D.dispose(), [D]);
298
- let N = c.multiple !== !1, P = N ? Math.max(0, Math.floor(c.maxCount ?? 3)) : 1, F = c.maxSize ?? 5, I = c.accept ?? "image/jpeg,image/png,image/webp", L = !!(c.disabled || c.readOnly || c.loading), R = N && w.length >= P, z = _(w, (e) => E.current(e), !!c.sortable && !L && N && w.length > 1), B = (e) => {
299
- if (L || !e.length) return;
300
- let t = N ? T.current : [], n = m([], e, {
301
- maxCount: Math.max(0, P - t.length),
302
- maxSize: F,
303
- accept: I
346
+ A
347
+ ]), e(() => () => A.dispose(), [A]);
348
+ let P = c.multiple !== !1, F = _(P, c.maxCount), I = F <= 1, L = c.maxSize ?? 5, re = c.accept ?? "image/jpeg,image/png,image/webp", R = !!(c.disabled || c.readOnly || c.loading), z = x(c, R), B = JSON.stringify(D.map((e) => e.uid)), ie = r(B);
349
+ n(() => {
350
+ ie.current !== B && z.cancel(), ie.current = B;
351
+ }, [B]);
352
+ let V = R || z.busy, { full: H } = g(D.length, F, P, c.replaceable), U = y(D, (e) => k.current(e), !!c.sortable && !V && P && D.length > 1), W = (e) => {
353
+ V || H || !e.length || z.prepare(e, (e) => {
354
+ let t = I ? [] : O.current, n = m([], e, {
355
+ maxCount: Math.max(0, F - t.length),
356
+ maxSize: L,
357
+ accept: re
358
+ });
359
+ if (te(n.rejected), n.rejected.length && c.onReject?.(n.rejected), !n.accepted.length) return;
360
+ if (I) {
361
+ A.dispose();
362
+ for (let e of O.current) c.onRemove?.(e);
363
+ }
364
+ let r = n.accepted.map((e) => ({
365
+ uid: `${v}-${++E}`,
366
+ name: e.name,
367
+ file: e,
368
+ status: c.mode === "mixed" ? "local" : "uploading",
369
+ progress: 0
370
+ }));
371
+ if (k.current([...t, ...r]), c.mode === "upload") for (let e of r) A.start(e, c.upload);
304
372
  });
305
- if (k(n.rejected), n.rejected.length && c.onReject?.(n.rejected), !n.accepted.length) return;
306
- N || D.dispose();
307
- let r = n.accepted.map((e) => ({
308
- uid: `${g}-${++C}`,
309
- name: e.name,
310
- file: e,
311
- status: "uploading",
312
- progress: 0
313
- }));
314
- E.current([...t, ...r]);
315
- for (let e of r) D.start(e, c.upload);
316
- }, V = (e) => {
317
- L || (D.abort(e), E.current(T.current.filter((t) => t.uid !== e)), k([]));
318
- }, te = (e) => {
319
- L || (D.abort(e), E.current(T.current.map((t) => t.uid === e ? {
373
+ }, ae = (e) => {
374
+ if (V) return;
375
+ let t = O.current.find((t) => t.uid === e);
376
+ t && c.onRemove?.(t), A.abort(e), k.current(O.current.filter((t) => t.uid !== e)), te([]);
377
+ }, G = (e) => {
378
+ V || (A.abort(e), k.current(O.current.map((t) => t.uid === e ? {
320
379
  ...t,
321
380
  status: "ready",
322
381
  progress: 0
323
382
  } : t)));
324
- }, H = !N && w.length ? f("replaceImage") : f("addImage"), U = c.status === "error" || c["aria-invalid"], W = {
383
+ }, K = I && D.length ? f("replaceImage") : f("addImage"), q = c.status === "error" || c["aria-invalid"], J = [
384
+ c["aria-describedby"],
385
+ `${v}-hint`,
386
+ j.length ? `${v}-rejected` : void 0
387
+ ].filter(Boolean).join(" "), oe = {
325
388
  type: f("imageType"),
326
- size: f("imageSize", { max: F }),
389
+ size: f("imageSize", { max: L }),
327
390
  count: f("imageCount")
328
391
  };
329
392
  return /* @__PURE__ */ d("div", {
330
393
  role: "group",
331
- id: R ? g : void 0,
332
- tabIndex: R && !c.disabled ? 0 : void 0,
394
+ id: H || c.readOnly ? v : void 0,
395
+ tabIndex: H && !c.disabled ? 0 : void 0,
333
396
  className: s("rfe-image-upload", c.className),
334
397
  style: c.style,
335
398
  "data-size": c.size ?? p.size,
336
- "data-status": U ? "error" : c.status ?? "default",
399
+ "data-status": q ? "error" : c.status ?? "default",
337
400
  "data-disabled": c.disabled || void 0,
338
- "data-dragging": A || void 0,
339
- "aria-label": c["aria-label"] ?? H,
340
- "aria-describedby": c["aria-describedby"],
341
- "aria-invalid": U || void 0,
342
- "aria-busy": w.some((e) => e.status === "uploading") || void 0,
401
+ "data-dragging": ne || void 0,
402
+ "aria-label": c["aria-label"] ?? K,
403
+ "aria-describedby": J,
404
+ "aria-invalid": q || void 0,
405
+ "aria-busy": z.busy || D.some((e) => e.status === "uploading") || void 0,
343
406
  onBlur: (e) => {
344
407
  e.currentTarget.contains(e.relatedTarget) || c.onBlur?.();
345
408
  },
346
409
  onDragOver: (e) => {
347
- c.dragDrop !== !1 && e.dataTransfer.types.includes("Files") && (e.preventDefault(), e.dataTransfer.dropEffect = L || R ? "none" : "copy", !L && !R && j(!0));
410
+ c.dragDrop !== !1 && e.dataTransfer.types.includes("Files") && (e.preventDefault(), e.dataTransfer.dropEffect = V || H ? "none" : "copy", !V && !H && M(!0));
348
411
  },
349
412
  onDragLeave: (e) => {
350
- e.relatedTarget instanceof Node && e.currentTarget.contains(e.relatedTarget) || j(!1);
413
+ e.relatedTarget instanceof Node && e.currentTarget.contains(e.relatedTarget) || M(!1);
351
414
  },
352
415
  onDrop: (e) => {
353
- c.dragDrop !== !1 && e.dataTransfer.types.includes("Files") && (e.preventDefault(), j(!1), B(Array.from(e.dataTransfer.files)));
416
+ c.dragDrop !== !1 && e.dataTransfer.types.includes("Files") && (e.preventDefault(), M(!1), W(Array.from(e.dataTransfer.files)));
354
417
  },
355
418
  children: [
356
419
  /* @__PURE__ */ d("div", {
357
420
  className: "rfe-image-grid",
358
421
  children: [
359
- w.map((e, t) => /* @__PURE__ */ u(ee, {
422
+ D.map((e, t) => /* @__PURE__ */ u(ee, {
360
423
  item: e,
361
- sortProps: z.enabled ? z.row(t) : void 0,
362
- sortActions: z.enabled ? /* @__PURE__ */ u(v, {
424
+ sortProps: U.enabled ? U.row(t) : void 0,
425
+ sortActions: U.enabled ? /* @__PURE__ */ u(b, {
363
426
  index: t,
364
- count: w.length,
427
+ count: D.length,
365
428
  name: e.name,
366
- onMove: z.move,
367
- onDragStart: (e) => z.dragStart(t, e),
368
- onDragEnd: z.reset
429
+ onMove: U.move,
430
+ onDragStart: (e) => U.dragStart(t, e),
431
+ onDragEnd: U.reset
369
432
  }) : void 0,
370
- blocked: L,
371
- preview: c.preview !== !1 && !c.disabled,
433
+ blocked: V,
434
+ preview: (c.previewable ?? c.preview ?? !0) && !c.disabled,
372
435
  icons: c.icons,
373
- onRemove: () => V(e.uid),
374
- onCancel: () => te(e.uid),
436
+ onRemove: () => ae(e.uid),
437
+ onCancel: () => G(e.uid),
375
438
  onRetry: () => {
376
- !L && !D.has(e.uid) && D.start(e, c.upload);
439
+ c.mode === "upload" && !V && !A.has(e.uid) && A.start(e, c.upload);
377
440
  }
378
441
  }, e.uid)),
379
- !R && /* @__PURE__ */ d("button", {
442
+ !H && !c.readOnly && /* @__PURE__ */ d("button", {
380
443
  type: "button",
381
- id: g,
444
+ id: v,
382
445
  className: "rfe-image-add",
383
- disabled: L,
384
- "aria-label": c["aria-label"] ?? H,
385
- "aria-describedby": c["aria-describedby"],
386
- "aria-invalid": U || void 0,
387
- onClick: () => M.current?.click(),
446
+ disabled: V,
447
+ "aria-label": c["aria-label"] ?? K,
448
+ "aria-describedby": J,
449
+ "aria-invalid": q || void 0,
450
+ onClick: () => N.current?.click(),
388
451
  children: [
389
452
  /* @__PURE__ */ u("span", {
390
453
  className: "rfe-image-add-icon",
@@ -393,51 +456,53 @@ function w(c) {
393
456
  source: c.icons?.add
394
457
  })
395
458
  }),
396
- /* @__PURE__ */ u("span", { children: H }),
459
+ /* @__PURE__ */ u("span", { children: K }),
397
460
  c.dragDrop !== !1 && /* @__PURE__ */ u("small", { children: f("dropImage") })
398
461
  ]
399
462
  }),
400
463
  /* @__PURE__ */ u("input", {
401
- ref: M,
464
+ ref: N,
402
465
  type: "file",
403
466
  name: c.name,
404
- accept: I,
405
- multiple: N,
406
- disabled: L || R,
467
+ accept: re,
468
+ multiple: !I && P,
469
+ disabled: V || H,
407
470
  hidden: !0,
408
471
  onChange: (e) => {
409
- B(Array.from(e.currentTarget.files ?? [])), e.currentTarget.value = "";
472
+ W(Array.from(e.currentTarget.files ?? [])), e.currentTarget.value = "";
410
473
  }
411
474
  })
412
475
  ]
413
476
  }),
414
477
  /* @__PURE__ */ d("div", {
415
478
  className: "rfe-image-meta",
416
- children: [/* @__PURE__ */ u("span", { children: f("imageHint", { max: F }) }), /* @__PURE__ */ d("span", { children: [
417
- w.length,
479
+ id: `${v}-hint`,
480
+ children: [/* @__PURE__ */ u("span", { children: f("imageHint", { max: L }) }), (c.showCount ?? F > 1) && /* @__PURE__ */ d("span", { children: [
481
+ D.length,
418
482
  " / ",
419
- P
483
+ F
420
484
  ] })]
421
485
  }),
422
- !!O.length && /* @__PURE__ */ u("div", {
486
+ !!j.length && /* @__PURE__ */ u("div", {
423
487
  className: "rfe-image-rejected",
488
+ id: `${v}-rejected`,
424
489
  role: "alert",
425
- children: O.map(({ file: e, reason: t }, n) => /* @__PURE__ */ d("div", { children: [
490
+ children: j.map(({ file: e, reason: t }, n) => /* @__PURE__ */ d("div", { children: [
426
491
  e.name,
427
492
  ": ",
428
- W[t]
493
+ oe[t]
429
494
  ] }, n))
430
495
  })
431
496
  ]
432
497
  });
433
498
  }
434
499
  // src/components/image-upload/index.tsx
435
- var T = [], E = /* @__PURE__ */ new WeakMap(), D = 0;
436
- function O(e) {
437
- let t = E.get(e);
438
- return t === void 0 && (t = ++D, E.set(e, t)), t;
500
+ var O = [], k = /* @__PURE__ */ new WeakMap(), A = 0;
501
+ function j(e) {
502
+ let t = k.get(e);
503
+ return t === void 0 && (t = ++A, k.set(e, t)), t;
439
504
  }
440
- function k({ file: t, onRemove: n, preview: o, removeIcon: s, previewIcon: c, sortActions: f, sortProps: p }) {
505
+ function te({ file: t, onRemove: n, preview: o, removeIcon: s, previewIcon: c, sortActions: f, sortProps: p }) {
441
506
  let { t: m } = a(), [h, g] = i(""), [_, v] = i(!1), y = r(null);
442
507
  return e(() => {
443
508
  let e = URL.createObjectURL(t);
@@ -507,132 +572,140 @@ function k({ file: t, onRemove: n, preview: o, removeIcon: s, previewIcon: c, so
507
572
  ]
508
573
  });
509
574
  }
510
- function A({ id: e, name: n, value: p, defaultValue: h, onChange: g, onBlur: y, disabled: b, readOnly: x, loading: S, status: C, size: ee, variant: w, className: E, style: D, multiple: A = !0, dragDrop: j = !0, preview: M = !0, sortable: N = !1, maxCount: P = 3, maxSize: F = 5, accept: I = f, icons: L, onReject: R, ...z }) {
511
- let B = o(), { t: V } = a(), te = t(), H = e ?? te, [U, W] = c(p, h ?? T, g), G = Array.isArray(U) ? U : T, [K, ne] = i([]), [re, q] = i(!1), ie = r(null), J = A ? Math.max(0, Math.floor(P)) : 1, Y = !!(b || x || S), X = G.length >= J && A, Z = _(G, W, N && !Y && A && G.length > 1), ae = (e) => {
512
- if (Y || !e.length) return;
513
- let t = m(A ? G : [], e, {
514
- maxCount: J,
515
- maxSize: F,
516
- accept: I
575
+ function ne({ id: e, name: p, value: h, defaultValue: v, onChange: S, onBlur: C, disabled: w, readOnly: T, loading: E, status: ee, size: D, variant: k, className: A, style: ne, multiple: M = !0, dragDrop: N = !0, preview: P = !0, sortable: F = !1, maxCount: I = 3, maxSize: L = 5, accept: re = f, icons: R, onReject: z, showCount: B, replaceable: ie = !1, previewable: V, beforeUpload: H, onPrepareError: U, ...W }) {
576
+ let ae = o(), { t: G } = a(), K = t(), q = e ?? K, [J, oe] = c(h, v ?? O, S), Y = Array.isArray(J) ? J : O, [se, ce] = i([]), [le, ue] = i(!1), de = r(null), X = _(M, I), fe = X <= 1, pe = !!(w || T || E), me = x({
577
+ beforeUpload: H,
578
+ onPrepareError: U
579
+ }, pe), he = r(Y);
580
+ n(() => {
581
+ (he.current.length !== Y.length || he.current.some((e, t) => e !== Y[t])) && me.cancel(), he.current = Y;
582
+ }, [Y]);
583
+ let Z = pe || me.busy, { full: Q } = g(Y.length, X, M, ie), $ = y(Y, oe, F && !Z && M && Y.length > 1), ge = (e) => {
584
+ Z || Q || !e.length || me.prepare(e, (e) => {
585
+ let t = m(fe ? [] : Y, e, {
586
+ maxCount: X,
587
+ maxSize: L,
588
+ accept: re
589
+ });
590
+ ce(t.rejected), t.rejected.length && z?.(t.rejected), (fe ? t.accepted.length > 0 : t.accepted.length !== Y.length) && oe(t.accepted);
517
591
  });
518
- ne(t.rejected), t.rejected.length && R?.(t.rejected), (A ? t.accepted.length !== G.length : t.accepted.length > 0) && W(t.accepted);
519
- }, oe = {
520
- type: V("imageType"),
521
- size: V("imageSize", { max: F }),
522
- count: V("imageCount")
523
- }, Q = !A && G.length ? V("replaceImage") : V("addImage"), $ = C === "error" || z["aria-invalid"], se = [
524
- z["aria-describedby"],
525
- `${H}-hint`,
526
- K.length ? `${H}-rejected` : void 0
592
+ }, _e = {
593
+ type: G("imageType"),
594
+ size: G("imageSize", { max: L }),
595
+ count: G("imageCount")
596
+ }, ve = fe && Y.length ? G("replaceImage") : G("addImage"), ye = ee === "error" || W["aria-invalid"], be = [
597
+ W["aria-describedby"],
598
+ `${q}-hint`,
599
+ se.length ? `${q}-rejected` : void 0
527
600
  ].filter(Boolean).join(" ");
528
601
  return /* @__PURE__ */ d("div", {
529
- id: X ? H : void 0,
530
- tabIndex: X && !b ? 0 : void 0,
602
+ id: Q || T ? q : void 0,
603
+ tabIndex: Q && !w ? 0 : void 0,
531
604
  role: "group",
532
- "aria-label": z["aria-label"] ?? Q,
533
- "aria-describedby": se,
534
- "aria-invalid": $ || void 0,
535
- className: s("rfe-image-upload", E),
536
- style: D,
537
- "data-size": ee ?? B.size,
538
- "data-variant": w ?? B.variant,
539
- "data-status": $ ? "error" : C ?? "default",
540
- "data-disabled": b || void 0,
541
- "data-readonly": x || void 0,
542
- "data-dragging": re && !Y || void 0,
543
- "aria-busy": S || void 0,
605
+ "aria-label": W["aria-label"] ?? ve,
606
+ "aria-describedby": be,
607
+ "aria-invalid": ye || void 0,
608
+ className: s("rfe-image-upload", A),
609
+ style: ne,
610
+ "data-size": D ?? ae.size,
611
+ "data-variant": k ?? ae.variant,
612
+ "data-status": ye ? "error" : ee ?? "default",
613
+ "data-disabled": w || void 0,
614
+ "data-readonly": T || void 0,
615
+ "data-dragging": le && !Z || void 0,
616
+ "aria-busy": E || me.busy || void 0,
544
617
  onBlur: (e) => {
545
- e.currentTarget.contains(e.relatedTarget) || y?.();
618
+ e.currentTarget.contains(e.relatedTarget) || C?.();
546
619
  },
547
620
  onDragOver: (e) => {
548
- j && e.dataTransfer.types.includes("Files") && (e.preventDefault(), e.dataTransfer.dropEffect = Y || X ? "none" : "copy", !Y && !X && q(!0));
621
+ N && e.dataTransfer.types.includes("Files") && (e.preventDefault(), e.dataTransfer.dropEffect = Z || Q ? "none" : "copy", !Z && !Q && ue(!0));
549
622
  },
550
623
  onDragLeave: (e) => {
551
- e.relatedTarget instanceof Node && e.currentTarget.contains(e.relatedTarget) || q(!1);
624
+ e.relatedTarget instanceof Node && e.currentTarget.contains(e.relatedTarget) || ue(!1);
552
625
  },
553
626
  onDrop: (e) => {
554
- j && e.dataTransfer.types.includes("Files") && (e.preventDefault(), q(!1), Y || ae(Array.from(e.dataTransfer.files)));
627
+ N && e.dataTransfer.types.includes("Files") && (e.preventDefault(), ue(!1), Z || ge(Array.from(e.dataTransfer.files)));
555
628
  },
556
629
  children: [
557
630
  /* @__PURE__ */ d("div", {
558
631
  className: "rfe-image-grid",
559
632
  children: [
560
- G.map((e, t) => /* @__PURE__ */ u(k, {
633
+ Y.map((e, t) => /* @__PURE__ */ u(te, {
561
634
  file: e,
562
- sortProps: Z.enabled ? Z.row(t) : void 0,
563
- sortActions: Z.enabled ? /* @__PURE__ */ u(v, {
635
+ sortProps: $.enabled ? $.row(t) : void 0,
636
+ sortActions: $.enabled ? /* @__PURE__ */ u(b, {
564
637
  index: t,
565
- count: G.length,
638
+ count: Y.length,
566
639
  name: e.name,
567
- onMove: Z.move,
568
- onDragStart: (e) => Z.dragStart(t, e),
569
- onDragEnd: Z.reset
640
+ onMove: $.move,
641
+ onDragStart: (e) => $.dragStart(t, e),
642
+ onDragEnd: $.reset
570
643
  }) : void 0,
571
- preview: M && !b,
572
- removeIcon: L?.remove,
573
- previewIcon: L?.preview,
574
- onRemove: Y ? void 0 : () => {
575
- ne([]), W(G.filter((e, n) => n !== t));
644
+ preview: (V ?? P) && !w,
645
+ removeIcon: R?.remove,
646
+ previewIcon: R?.preview,
647
+ onRemove: Z ? void 0 : () => {
648
+ ce([]), oe(Y.filter((e, n) => n !== t));
576
649
  }
577
- }, `${O(e)}-${G.slice(0, t).filter((t) => t === e).length}`)),
578
- !X && /* @__PURE__ */ d("button", {
579
- id: H,
650
+ }, `${j(e)}-${Y.slice(0, t).filter((t) => t === e).length}`)),
651
+ !Q && !T && /* @__PURE__ */ d("button", {
652
+ id: q,
580
653
  type: "button",
581
654
  className: "rfe-image-add",
582
- disabled: Y,
583
- "aria-label": z["aria-label"] ?? Q,
584
- "aria-describedby": se,
585
- "aria-invalid": $ || void 0,
586
- onClick: () => ie.current?.click(),
655
+ disabled: Z,
656
+ "aria-label": W["aria-label"] ?? ve,
657
+ "aria-describedby": be,
658
+ "aria-invalid": ye || void 0,
659
+ onClick: () => de.current?.click(),
587
660
  children: [
588
661
  /* @__PURE__ */ u("span", {
589
662
  className: "rfe-image-add-icon",
590
663
  children: /* @__PURE__ */ u(l, {
591
- name: S ? "loading" : "imageAdd",
592
- source: S ? void 0 : L?.add
664
+ name: E ? "loading" : "imageAdd",
665
+ source: E ? void 0 : R?.add
593
666
  })
594
667
  }),
595
- /* @__PURE__ */ u("span", { children: S ? V("processing") : Q }),
596
- j && !S && /* @__PURE__ */ u("small", { children: V("dropImage") })
668
+ /* @__PURE__ */ u("span", { children: E ? G("processing") : ve }),
669
+ N && !E && /* @__PURE__ */ u("small", { children: G("dropImage") })
597
670
  ]
598
671
  }),
599
672
  /* @__PURE__ */ u("input", {
600
- ref: ie,
673
+ ref: de,
601
674
  type: "file",
602
- name: n,
603
- accept: I,
604
- multiple: A,
605
- disabled: Y || X,
675
+ name: p,
676
+ accept: re,
677
+ multiple: !fe && M,
678
+ disabled: Z || Q,
606
679
  hidden: !0,
607
680
  onChange: (e) => {
608
- ae(Array.from(e.currentTarget.files ?? [])), e.currentTarget.value = "";
681
+ ge(Array.from(e.currentTarget.files ?? [])), e.currentTarget.value = "";
609
682
  }
610
683
  })
611
684
  ]
612
685
  }),
613
686
  /* @__PURE__ */ d("div", {
614
687
  className: "rfe-image-meta",
615
- id: `${H}-hint`,
616
- children: [/* @__PURE__ */ u("span", { children: V("imageHint", { max: F }) }), /* @__PURE__ */ d("span", { children: [
617
- G.length,
688
+ id: `${q}-hint`,
689
+ children: [/* @__PURE__ */ u("span", { children: G("imageHint", { max: L }) }), (B ?? X > 1) && /* @__PURE__ */ d("span", { children: [
690
+ Y.length,
618
691
  " / ",
619
- J
692
+ X
620
693
  ] })]
621
694
  }),
622
- !!K.length && /* @__PURE__ */ u("div", {
695
+ !!se.length && /* @__PURE__ */ u("div", {
623
696
  className: "rfe-image-rejected",
624
- id: `${H}-rejected`,
697
+ id: `${q}-rejected`,
625
698
  role: "alert",
626
- children: K.map(({ file: e, reason: t }, n) => /* @__PURE__ */ d("div", { children: [
699
+ children: se.map(({ file: e, reason: t }, n) => /* @__PURE__ */ d("div", { children: [
627
700
  e.name,
628
701
  ":",
629
- oe[t]
702
+ _e[t]
630
703
  ] }, n))
631
704
  })
632
705
  ]
633
706
  });
634
707
  }
635
- function j(e) {
636
- return e.mode === "upload" ? /* @__PURE__ */ u(w, { ...e }) : /* @__PURE__ */ u(A, { ...e });
708
+ function M(e) {
709
+ return e.mode === "upload" || e.mode === "mixed" ? /* @__PURE__ */ u(D, { ...e }) : /* @__PURE__ */ u(ne, { ...e });
637
710
  }
638
- export { b as i, x as n, y as r, j as t };
711
+ export { C as i, w as n, S as r, M as t };