jaguar-form 1.0.5 → 1.0.7

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 (55) hide show
  1. package/README.md +29 -2
  2. package/dist/Cascader-iWlk7VJR.js +226 -0
  3. package/dist/Select-CoEW4UIq.js +422 -0
  4. package/dist/TreeSelect-BWksr9iW.js +350 -0
  5. package/dist/{compound-BhkceJal.js → compound-BW6G7E_-.js} +95 -84
  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-B-BSf2n1.js +599 -0
  11. package/dist/form.js +2 -2
  12. package/dist/{icons-D79FYcGF.js → icons-BwE05e0C.js} +1 -1
  13. package/dist/{image-upload-BstB2jRd.js → image-upload-D9oPG0Eh.js} +252 -183
  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-Ch4x2nwn.js → inputs-DpZdLaoP.js} +233 -130
  18. package/dist/{useSelection-BUBndjzo.js → lazy-tree-C9l9lzQw.js} +117 -19
  19. package/dist/pickers-Bci1y8cc.js +634 -0
  20. package/dist/select.js +3 -1
  21. package/dist/{selection-9NP9MXSn.js → selection-DCIzhR5q.js} +28 -21
  22. package/dist/{slider-C2T2wII7.js → slider-AM0Egz9P.js} +1 -1
  23. package/dist/slider.js +1 -1
  24. package/dist/store-CFSQW-Fv.js +622 -0
  25. package/dist/style.css +1 -1
  26. package/dist/tree-select.js +1 -1
  27. package/dist/types/components/compound/ControlGroup.d.ts +5 -2
  28. package/dist/types/components/compound/index.d.ts +10 -1
  29. package/dist/types/components/extended-inputs.d.ts +4 -0
  30. package/dist/types/components/image-upload/ManagedImageUpload.d.ts +2 -2
  31. package/dist/types/components/image-upload/index.d.ts +3 -2
  32. package/dist/types/components/image-upload/usePreparation.d.ts +7 -0
  33. package/dist/types/components/image-upload/validation.d.ts +16 -0
  34. package/dist/types/components/inputs.d.ts +19 -4
  35. package/dist/types/components/select/Cascader.d.ts +13 -0
  36. package/dist/types/components/select/types.d.ts +6 -0
  37. package/dist/types/components/select/useRemoteOptions.d.ts +8 -1
  38. package/dist/types/components/select.d.ts +2 -0
  39. package/dist/types/config/index.d.ts +3 -0
  40. package/dist/types/entries/input.d.ts +2 -2
  41. package/dist/types/entries/select.d.ts +2 -0
  42. package/dist/types/form/index.d.ts +54 -10
  43. package/dist/types/form/store.d.ts +12 -1
  44. package/dist/types/primitives/Control.d.ts +3 -1
  45. package/dist/types/types.d.ts +1 -0
  46. package/dist/types/utils/cascader.d.ts +12 -0
  47. package/dist/types/utils/decimal.d.ts +18 -0
  48. package/dist/types/utils/remote-options.d.ts +2 -1
  49. package/dist/{useControllable-Dhp7tTjy.js → useControllable-QDX_UWRh.js} +6 -1
  50. package/package.json +1 -1
  51. package/dist/Select-DiEHlcyU.js +0 -376
  52. package/dist/TreeSelect-1jpd43zZ.js +0 -439
  53. package/dist/form-CnRp3fRw.js +0 -457
  54. package/dist/pickers-D-ymAf_p.js +0 -630
  55. package/dist/store-BvcQ7xcl.js +0 -509
@@ -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-Dhp7tTjy.js";
3
- import { t as l } from "./icons-D79FYcGF.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,117 +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
- if (!N) {
307
- D.dispose();
308
- for (let e of T.current) c.onRemove?.(e);
309
- }
310
- let r = n.accepted.map((e) => ({
311
- uid: `${g}-${++C}`,
312
- name: e.name,
313
- file: e,
314
- status: c.mode === "mixed" ? "local" : "uploading",
315
- progress: 0
316
- }));
317
- if (E.current([...t, ...r]), c.mode === "upload") for (let e of r) D.start(e, c.upload);
318
- }, V = (e) => {
319
- if (L) return;
320
- let t = T.current.find((t) => t.uid === e);
321
- t && c.onRemove?.(t), D.abort(e), E.current(T.current.filter((t) => t.uid !== e)), k([]);
322
- }, te = (e) => {
323
- 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 ? {
324
379
  ...t,
325
380
  status: "ready",
326
381
  progress: 0
327
382
  } : t)));
328
- }, 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 = {
329
388
  type: f("imageType"),
330
- size: f("imageSize", { max: F }),
389
+ size: f("imageSize", { max: L }),
331
390
  count: f("imageCount")
332
391
  };
333
392
  return /* @__PURE__ */ d("div", {
334
393
  role: "group",
335
- id: R ? g : void 0,
336
- tabIndex: R && !c.disabled ? 0 : void 0,
394
+ id: H || c.readOnly ? v : void 0,
395
+ tabIndex: H && !c.disabled ? 0 : void 0,
337
396
  className: s("rfe-image-upload", c.className),
338
397
  style: c.style,
339
398
  "data-size": c.size ?? p.size,
340
- "data-status": U ? "error" : c.status ?? "default",
399
+ "data-status": q ? "error" : c.status ?? "default",
341
400
  "data-disabled": c.disabled || void 0,
342
- "data-dragging": A || void 0,
343
- "aria-label": c["aria-label"] ?? H,
344
- "aria-describedby": c["aria-describedby"],
345
- "aria-invalid": U || void 0,
346
- "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,
347
406
  onBlur: (e) => {
348
407
  e.currentTarget.contains(e.relatedTarget) || c.onBlur?.();
349
408
  },
350
409
  onDragOver: (e) => {
351
- 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));
352
411
  },
353
412
  onDragLeave: (e) => {
354
- e.relatedTarget instanceof Node && e.currentTarget.contains(e.relatedTarget) || j(!1);
413
+ e.relatedTarget instanceof Node && e.currentTarget.contains(e.relatedTarget) || M(!1);
355
414
  },
356
415
  onDrop: (e) => {
357
- 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)));
358
417
  },
359
418
  children: [
360
419
  /* @__PURE__ */ d("div", {
361
420
  className: "rfe-image-grid",
362
421
  children: [
363
- w.map((e, t) => /* @__PURE__ */ u(ee, {
422
+ D.map((e, t) => /* @__PURE__ */ u(ee, {
364
423
  item: e,
365
- sortProps: z.enabled ? z.row(t) : void 0,
366
- sortActions: z.enabled ? /* @__PURE__ */ u(v, {
424
+ sortProps: U.enabled ? U.row(t) : void 0,
425
+ sortActions: U.enabled ? /* @__PURE__ */ u(b, {
367
426
  index: t,
368
- count: w.length,
427
+ count: D.length,
369
428
  name: e.name,
370
- onMove: z.move,
371
- onDragStart: (e) => z.dragStart(t, e),
372
- onDragEnd: z.reset
429
+ onMove: U.move,
430
+ onDragStart: (e) => U.dragStart(t, e),
431
+ onDragEnd: U.reset
373
432
  }) : void 0,
374
- blocked: L,
375
- preview: c.preview !== !1 && !c.disabled,
433
+ blocked: V,
434
+ preview: (c.previewable ?? c.preview ?? !0) && !c.disabled,
376
435
  icons: c.icons,
377
- onRemove: () => V(e.uid),
378
- onCancel: () => te(e.uid),
436
+ onRemove: () => ae(e.uid),
437
+ onCancel: () => G(e.uid),
379
438
  onRetry: () => {
380
- c.mode === "upload" && !L && !D.has(e.uid) && D.start(e, c.upload);
439
+ c.mode === "upload" && !V && !A.has(e.uid) && A.start(e, c.upload);
381
440
  }
382
441
  }, e.uid)),
383
- !R && /* @__PURE__ */ d("button", {
442
+ !H && !c.readOnly && /* @__PURE__ */ d("button", {
384
443
  type: "button",
385
- id: g,
444
+ id: v,
386
445
  className: "rfe-image-add",
387
- disabled: L,
388
- "aria-label": c["aria-label"] ?? H,
389
- "aria-describedby": c["aria-describedby"],
390
- "aria-invalid": U || void 0,
391
- 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(),
392
451
  children: [
393
452
  /* @__PURE__ */ u("span", {
394
453
  className: "rfe-image-add-icon",
@@ -397,51 +456,53 @@ function w(c) {
397
456
  source: c.icons?.add
398
457
  })
399
458
  }),
400
- /* @__PURE__ */ u("span", { children: H }),
459
+ /* @__PURE__ */ u("span", { children: K }),
401
460
  c.dragDrop !== !1 && /* @__PURE__ */ u("small", { children: f("dropImage") })
402
461
  ]
403
462
  }),
404
463
  /* @__PURE__ */ u("input", {
405
- ref: M,
464
+ ref: N,
406
465
  type: "file",
407
466
  name: c.name,
408
- accept: I,
409
- multiple: N,
410
- disabled: L || R,
467
+ accept: re,
468
+ multiple: !I && P,
469
+ disabled: V || H,
411
470
  hidden: !0,
412
471
  onChange: (e) => {
413
- B(Array.from(e.currentTarget.files ?? [])), e.currentTarget.value = "";
472
+ W(Array.from(e.currentTarget.files ?? [])), e.currentTarget.value = "";
414
473
  }
415
474
  })
416
475
  ]
417
476
  }),
418
477
  /* @__PURE__ */ d("div", {
419
478
  className: "rfe-image-meta",
420
- children: [/* @__PURE__ */ u("span", { children: f("imageHint", { max: F }) }), /* @__PURE__ */ d("span", { children: [
421
- 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,
422
482
  " / ",
423
- P
483
+ F
424
484
  ] })]
425
485
  }),
426
- !!O.length && /* @__PURE__ */ u("div", {
486
+ !!j.length && /* @__PURE__ */ u("div", {
427
487
  className: "rfe-image-rejected",
488
+ id: `${v}-rejected`,
428
489
  role: "alert",
429
- 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: [
430
491
  e.name,
431
492
  ": ",
432
- W[t]
493
+ oe[t]
433
494
  ] }, n))
434
495
  })
435
496
  ]
436
497
  });
437
498
  }
438
499
  // src/components/image-upload/index.tsx
439
- var T = [], E = /* @__PURE__ */ new WeakMap(), D = 0;
440
- function O(e) {
441
- let t = E.get(e);
442
- 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;
443
504
  }
444
- 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 }) {
445
506
  let { t: m } = a(), [h, g] = i(""), [_, v] = i(!1), y = r(null);
446
507
  return e(() => {
447
508
  let e = URL.createObjectURL(t);
@@ -511,132 +572,140 @@ function k({ file: t, onRemove: n, preview: o, removeIcon: s, previewIcon: c, so
511
572
  ]
512
573
  });
513
574
  }
514
- 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 }) {
515
- 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) => {
516
- if (Y || !e.length) return;
517
- let t = m(A ? G : [], e, {
518
- maxCount: J,
519
- maxSize: F,
520
- 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);
521
591
  });
522
- ne(t.rejected), t.rejected.length && R?.(t.rejected), (A ? t.accepted.length !== G.length : t.accepted.length > 0) && W(t.accepted);
523
- }, oe = {
524
- type: V("imageType"),
525
- size: V("imageSize", { max: F }),
526
- count: V("imageCount")
527
- }, Q = !A && G.length ? V("replaceImage") : V("addImage"), $ = C === "error" || z["aria-invalid"], se = [
528
- z["aria-describedby"],
529
- `${H}-hint`,
530
- 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
531
600
  ].filter(Boolean).join(" ");
532
601
  return /* @__PURE__ */ d("div", {
533
- id: X ? H : void 0,
534
- tabIndex: X && !b ? 0 : void 0,
602
+ id: Q || T ? q : void 0,
603
+ tabIndex: Q && !w ? 0 : void 0,
535
604
  role: "group",
536
- "aria-label": z["aria-label"] ?? Q,
537
- "aria-describedby": se,
538
- "aria-invalid": $ || void 0,
539
- className: s("rfe-image-upload", E),
540
- style: D,
541
- "data-size": ee ?? B.size,
542
- "data-variant": w ?? B.variant,
543
- "data-status": $ ? "error" : C ?? "default",
544
- "data-disabled": b || void 0,
545
- "data-readonly": x || void 0,
546
- "data-dragging": re && !Y || void 0,
547
- "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,
548
617
  onBlur: (e) => {
549
- e.currentTarget.contains(e.relatedTarget) || y?.();
618
+ e.currentTarget.contains(e.relatedTarget) || C?.();
550
619
  },
551
620
  onDragOver: (e) => {
552
- 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));
553
622
  },
554
623
  onDragLeave: (e) => {
555
- e.relatedTarget instanceof Node && e.currentTarget.contains(e.relatedTarget) || q(!1);
624
+ e.relatedTarget instanceof Node && e.currentTarget.contains(e.relatedTarget) || ue(!1);
556
625
  },
557
626
  onDrop: (e) => {
558
- 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)));
559
628
  },
560
629
  children: [
561
630
  /* @__PURE__ */ d("div", {
562
631
  className: "rfe-image-grid",
563
632
  children: [
564
- G.map((e, t) => /* @__PURE__ */ u(k, {
633
+ Y.map((e, t) => /* @__PURE__ */ u(te, {
565
634
  file: e,
566
- sortProps: Z.enabled ? Z.row(t) : void 0,
567
- sortActions: Z.enabled ? /* @__PURE__ */ u(v, {
635
+ sortProps: $.enabled ? $.row(t) : void 0,
636
+ sortActions: $.enabled ? /* @__PURE__ */ u(b, {
568
637
  index: t,
569
- count: G.length,
638
+ count: Y.length,
570
639
  name: e.name,
571
- onMove: Z.move,
572
- onDragStart: (e) => Z.dragStart(t, e),
573
- onDragEnd: Z.reset
640
+ onMove: $.move,
641
+ onDragStart: (e) => $.dragStart(t, e),
642
+ onDragEnd: $.reset
574
643
  }) : void 0,
575
- preview: M && !b,
576
- removeIcon: L?.remove,
577
- previewIcon: L?.preview,
578
- onRemove: Y ? void 0 : () => {
579
- 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));
580
649
  }
581
- }, `${O(e)}-${G.slice(0, t).filter((t) => t === e).length}`)),
582
- !X && /* @__PURE__ */ d("button", {
583
- id: H,
650
+ }, `${j(e)}-${Y.slice(0, t).filter((t) => t === e).length}`)),
651
+ !Q && !T && /* @__PURE__ */ d("button", {
652
+ id: q,
584
653
  type: "button",
585
654
  className: "rfe-image-add",
586
- disabled: Y,
587
- "aria-label": z["aria-label"] ?? Q,
588
- "aria-describedby": se,
589
- "aria-invalid": $ || void 0,
590
- 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(),
591
660
  children: [
592
661
  /* @__PURE__ */ u("span", {
593
662
  className: "rfe-image-add-icon",
594
663
  children: /* @__PURE__ */ u(l, {
595
- name: S ? "loading" : "imageAdd",
596
- source: S ? void 0 : L?.add
664
+ name: E ? "loading" : "imageAdd",
665
+ source: E ? void 0 : R?.add
597
666
  })
598
667
  }),
599
- /* @__PURE__ */ u("span", { children: S ? V("processing") : Q }),
600
- 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") })
601
670
  ]
602
671
  }),
603
672
  /* @__PURE__ */ u("input", {
604
- ref: ie,
673
+ ref: de,
605
674
  type: "file",
606
- name: n,
607
- accept: I,
608
- multiple: A,
609
- disabled: Y || X,
675
+ name: p,
676
+ accept: re,
677
+ multiple: !fe && M,
678
+ disabled: Z || Q,
610
679
  hidden: !0,
611
680
  onChange: (e) => {
612
- ae(Array.from(e.currentTarget.files ?? [])), e.currentTarget.value = "";
681
+ ge(Array.from(e.currentTarget.files ?? [])), e.currentTarget.value = "";
613
682
  }
614
683
  })
615
684
  ]
616
685
  }),
617
686
  /* @__PURE__ */ d("div", {
618
687
  className: "rfe-image-meta",
619
- id: `${H}-hint`,
620
- children: [/* @__PURE__ */ u("span", { children: V("imageHint", { max: F }) }), /* @__PURE__ */ d("span", { children: [
621
- 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,
622
691
  " / ",
623
- J
692
+ X
624
693
  ] })]
625
694
  }),
626
- !!K.length && /* @__PURE__ */ u("div", {
695
+ !!se.length && /* @__PURE__ */ u("div", {
627
696
  className: "rfe-image-rejected",
628
- id: `${H}-rejected`,
697
+ id: `${q}-rejected`,
629
698
  role: "alert",
630
- 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: [
631
700
  e.name,
632
701
  ":",
633
- oe[t]
702
+ _e[t]
634
703
  ] }, n))
635
704
  })
636
705
  ]
637
706
  });
638
707
  }
639
- function j(e) {
640
- return e.mode === "upload" || e.mode === "mixed" ? /* @__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 });
641
710
  }
642
- 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 };