@tedi-design-system/react 19.1.2-rc.4 → 19.2.0-rc.2

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 (46) hide show
  1. package/bundle-stats.html +1 -1
  2. package/external/hoist-non-react-statics/external/react-is/cjs/react-is.development.cjs.js +1 -1
  3. package/external/hoist-non-react-statics/external/react-is/cjs/react-is.development.es.js +1 -1
  4. package/external/hoist-non-react-statics/external/react-is/cjs/react-is.production.min.cjs.js +1 -1
  5. package/external/hoist-non-react-statics/external/react-is/cjs/react-is.production.min.es.js +1 -1
  6. package/external/hoist-non-react-statics/external/react-is/index.cjs.js +1 -1
  7. package/external/hoist-non-react-statics/external/react-is/index.es.js +1 -1
  8. package/external/prop-types/external/react-is/cjs/react-is.development.cjs.js +1 -1
  9. package/external/prop-types/external/react-is/cjs/react-is.development.es.js +1 -1
  10. package/external/prop-types/external/react-is/cjs/react-is.production.min.cjs.js +1 -1
  11. package/external/prop-types/external/react-is/cjs/react-is.production.min.es.js +1 -1
  12. package/external/prop-types/external/react-is/index.cjs.js +1 -1
  13. package/external/prop-types/external/react-is/index.es.js +1 -1
  14. package/index.css +1 -1
  15. package/package.json +1 -1
  16. package/src/tedi/components/form/file-dropzone/file-dropzone.cjs.js +1 -1
  17. package/src/tedi/components/form/file-dropzone/file-dropzone.d.ts +10 -3
  18. package/src/tedi/components/form/file-dropzone/file-dropzone.es.js +103 -100
  19. package/src/tedi/components/form/file-dropzone/file-dropzone.module.scss.cjs.js +1 -1
  20. package/src/tedi/components/form/file-dropzone/file-dropzone.module.scss.es.js +5 -4
  21. package/src/tedi/components/form/multi-value-field/multi-value-field.cjs.js +1 -1
  22. package/src/tedi/components/form/multi-value-field/multi-value-field.d.ts +6 -0
  23. package/src/tedi/components/form/multi-value-field/multi-value-field.es.js +126 -117
  24. package/src/tedi/components/form/multi-value-field/multi-value-field.module.scss.cjs.js +1 -1
  25. package/src/tedi/components/form/multi-value-field/multi-value-field.module.scss.es.js +2 -0
  26. package/src/tedi/components/form/select/components/select-clear-indicator.cjs.js +1 -1
  27. package/src/tedi/components/form/select/components/select-clear-indicator.es.js +21 -10
  28. package/src/tedi/components/form/select/select.cjs.js +1 -1
  29. package/src/tedi/components/form/select/select.d.ts +6 -0
  30. package/src/tedi/components/form/select/select.es.js +173 -171
  31. package/src/tedi/components/form/select/select.module.scss.cjs.js +1 -1
  32. package/src/tedi/components/form/select/select.module.scss.es.js +2 -1
  33. package/src/tedi/components/form/textarea/textarea.d.ts +1 -1
  34. package/src/tedi/components/form/textfield/textfield.cjs.js +1 -1
  35. package/src/tedi/components/form/textfield/textfield.d.ts +6 -0
  36. package/src/tedi/components/form/textfield/textfield.es.js +86 -84
  37. package/src/tedi/components/form/textfield/textfield.module.scss.cjs.js +1 -1
  38. package/src/tedi/components/form/textfield/textfield.module.scss.es.js +2 -0
  39. package/src/tedi/helpers/hooks/use-file-upload.cjs.js +1 -1
  40. package/src/tedi/helpers/hooks/use-file-upload.d.ts +8 -0
  41. package/src/tedi/helpers/hooks/use-file-upload.es.js +102 -79
  42. package/src/tedi/providers/label-provider/labels-map.cjs.js +1 -1
  43. package/src/tedi/providers/label-provider/labels-map.d.ts +7 -0
  44. package/src/tedi/providers/label-provider/labels-map.es.js +19 -12
  45. package/tedi.cjs.js +1 -1
  46. package/tedi.es.js +46 -45
@@ -1,162 +1,164 @@
1
1
  import { jsx as n, jsxs as S } from "react/jsx-runtime";
2
2
  import _ from "../../../../../external/classnames/index.es.js";
3
- import y, { forwardRef as _e, useMemo as b, useCallback as B } from "react";
3
+ import y, { forwardRef as be, useMemo as b, useCallback as w } from "react";
4
4
  import { Icon as D } from "../../base/icon/icon.es.js";
5
- import { ClosingButton as be } from "../../buttons/closing-button/closing-button.es.js";
6
- import { Separator as Ie } from "../../misc/separator/separator.es.js";
5
+ import { ClosingButton as Ie } from "../../buttons/closing-button/closing-button.es.js";
6
+ import { Separator as ge } from "../../misc/separator/separator.es.js";
7
7
  import { FeedbackText as U } from "../feedback-text/feedback-text.es.js";
8
- import { Field as ge } from "../field/field.es.js";
9
- import { FormLabel as Ne } from "../form-label/form-label.es.js";
10
- import { useOptionalInputGroup as Ae } from "../input-group/input-group.es.js";
11
- import t from "./textfield.module.scss.es.js";
8
+ import { Field as Ne } from "../field/field.es.js";
9
+ import { FormLabel as Ae } from "../form-label/form-label.es.js";
10
+ import { useOptionalInputGroup as Ce } from "../input-group/input-group.es.js";
11
+ import r from "./textfield.module.scss.es.js";
12
12
  import { useBreakpointProps as ke } from "../../../helpers/hooks/use-breakpoint-props.es.js";
13
- import { useLabels as Ce } from "../../../providers/label-provider/use-labels.es.js";
14
- const Se = {
13
+ import { useLabels as Se } from "../../../providers/label-provider/use-labels.es.js";
14
+ const we = {
15
15
  large: 24,
16
16
  default: 18
17
- }, Be = _e((I, J) => {
17
+ }, Be = be((I, J) => {
18
18
  var M;
19
19
  const { getCurrentBreakpointProps: Q } = ke(I.defaultServerBreakpoint), {
20
- id: we,
20
+ id: ze,
21
21
  label: g,
22
22
  className: W,
23
23
  inputClassName: X,
24
24
  disabled: d,
25
- required: w,
25
+ required: B,
26
26
  hideLabel: z,
27
- invalid: c,
27
+ invalid: f,
28
28
  readOnly: F,
29
29
  icon: i,
30
- onIconClick: v,
30
+ onIconClick: x,
31
31
  iconButtonProps: p,
32
32
  size: s = "default",
33
33
  placeholder: Y,
34
34
  isArrowsHidden: Z = !0,
35
35
  isClearable: R,
36
- onClear: x,
36
+ showClearOnInteraction: G,
37
+ onClear: v,
37
38
  onChange: o,
38
- onChangeEvent: G,
39
- onKeyUp: ee,
40
- onKeyDown: re,
41
- onKeyPress: te,
39
+ onChangeEvent: ee,
40
+ onKeyUp: re,
41
+ onKeyDown: te,
42
+ onKeyPress: ae,
42
43
  defaultValue: $,
43
44
  value: N,
44
45
  onFocus: A,
45
- onBlur: k,
46
- onClick: ae,
46
+ onBlur: C,
47
+ onClick: ie,
47
48
  helper: e,
48
49
  input: a,
49
- name: ie,
50
- isTextArea: le,
51
- startSlot: ne,
52
- endSlot: se,
53
- ...oe
54
- } = Q(I) || {}, { getLabel: L } = Ce(), T = y.useRef(null), E = y.useRef(null), [de, O] = y.useState(N ?? $ ?? ""), P = N ?? de, f = !!(R && P && !F), m = (M = Ae) == null ? void 0 : M(), ce = y.useId(), fe = m == null ? void 0 : m.hasExternalLabel, u = I.id ?? (m == null ? void 0 : m.inputId) ?? ce;
50
+ name: le,
51
+ isTextArea: ne,
52
+ startSlot: se,
53
+ endSlot: oe,
54
+ ...de
55
+ } = Q(I) || {}, { getLabel: L } = Se(), O = y.useRef(null), T = y.useRef(null), [ce, E] = y.useState(N ?? $ ?? ""), P = N ?? ce, c = !!(R && P && !F), m = (M = Ce) == null ? void 0 : M(), fe = y.useId(), me = m == null ? void 0 : m.hasExternalLabel, u = I.id ?? (m == null ? void 0 : m.inputId) ?? fe;
55
56
  y.useImperativeHandle(J, () => ({
56
57
  get input() {
57
- return E.current;
58
+ return T.current;
58
59
  },
59
60
  get inner() {
60
- return T.current;
61
+ return O.current;
61
62
  }
62
63
  }));
63
- const V = b(() => Array.isArray(e) ? c || e.some((r) => r.type === "error") : c || (e == null ? void 0 : e.type) === "error", [c, e]), me = b(() => !e || Array.isArray(e) && e.length === 0 ? !1 : Array.isArray(e) ? !c && e.every((r) => r.type === "valid") : !c && e.type === "valid", [c, e]), ue = s === "large" ? "default" : s, h = N !== void 0, pe = B(
64
- (r) => {
65
- h || O(r), o == null || o(r);
64
+ const V = b(() => Array.isArray(e) ? f || e.some((t) => t.type === "error") : f || (e == null ? void 0 : e.type) === "error", [f, e]), ue = b(() => !e || Array.isArray(e) && e.length === 0 ? !1 : Array.isArray(e) ? !f && e.every((t) => t.type === "valid") : !f && e.type === "valid", [f, e]), pe = s === "large" ? "default" : s, h = N !== void 0, ye = w(
65
+ (t) => {
66
+ h || E(t), o == null || o(t);
66
67
  },
67
68
  [h, o]
68
- ), j = B(() => {
69
- h || O(""), o == null || o(""), x == null || x();
70
- }, [h, o, x]), H = B(() => {
69
+ ), j = w(() => {
70
+ h || E(""), o == null || o(""), v == null || v();
71
+ }, [h, o, v]), H = w(() => {
71
72
  if (!i) return null;
72
- const C = {
73
- size: s === "large" ? 24 : s === "small" ? !!v ? 18 : 16 : 18,
74
- className: t["tedi-textfield__icon"]
75
- }, q = typeof i == "string" ? { ...C, name: i } : { ...C, ...i, className: _(C.className, i.className) };
76
- return v ? /* @__PURE__ */ n(
73
+ const k = {
74
+ size: s === "large" ? 24 : s === "small" ? !!x ? 18 : 16 : 18,
75
+ className: r["tedi-textfield__icon"]
76
+ }, q = typeof i == "string" ? { ...k, name: i } : { ...k, ...i, className: _(k.className, i.className) };
77
+ return x ? /* @__PURE__ */ n(
77
78
  "button",
78
79
  {
79
80
  type: "button",
80
81
  ...p,
81
- className: _(t["tedi-textfield__icon-wrapper"], p == null ? void 0 : p.className),
82
- onClick: d ? void 0 : v,
82
+ className: _(r["tedi-textfield__icon-wrapper"], p == null ? void 0 : p.className),
83
+ onClick: d ? void 0 : x,
83
84
  disabled: d,
84
85
  children: /* @__PURE__ */ n(D, { ...q })
85
86
  }
86
- ) : /* @__PURE__ */ n("div", { className: t["tedi-textfield__icon-wrapper"], "aria-hidden": "true", children: /* @__PURE__ */ n(D, { ...q }) });
87
- }, [i, s, v, p, d]), K = b(() => f ? /* @__PURE__ */ n(
88
- be,
87
+ ) : /* @__PURE__ */ n("div", { className: r["tedi-textfield__icon-wrapper"], "aria-hidden": "true", children: /* @__PURE__ */ n(D, { ...q }) });
88
+ }, [i, s, x, p, d]), K = b(() => c ? /* @__PURE__ */ n(
89
+ Ie,
89
90
  {
90
- iconSize: Se[s === "large" ? "large" : "default"],
91
+ iconSize: we[s === "large" ? "large" : "default"],
91
92
  onClick: d ? void 0 : j,
92
93
  disabled: d,
93
94
  title: L("clear"),
94
- className: t["tedi-textfield__clear-button"]
95
+ className: r["tedi-textfield__clear-button"]
95
96
  }
96
- ) : null, [f, s, d, j, L]), ye = b(() => !f && !i ? null : /* @__PURE__ */ S("div", { className: t["tedi-textfield__right-area"], children: [
97
+ ) : null, [c, s, d, j, L]), xe = b(() => !c && !i ? null : /* @__PURE__ */ S("div", { className: r["tedi-textfield__right-area"], children: [
97
98
  K,
98
- f && i && /* @__PURE__ */ n(Ie, { color: "primary", axis: "vertical", className: t["tedi-textfield__separator"] }),
99
+ c && i && /* @__PURE__ */ n(ge, { color: "primary", axis: "vertical", className: r["tedi-textfield__separator"] }),
99
100
  i && H()
100
- ] }), [f, i, K, H]), ve = /* @__PURE__ */ n(
101
- ge,
101
+ ] }), [c, i, K, H]), ve = /* @__PURE__ */ n(
102
+ Ne,
102
103
  {
103
104
  ...a,
104
105
  id: u,
105
- name: ie,
106
+ name: le,
106
107
  value: P,
107
108
  defaultValue: $,
108
- onChange: pe,
109
- onChangeEvent: G,
109
+ onChange: ye,
110
+ onChangeEvent: ee,
110
111
  disabled: d,
111
112
  readOnly: F || (a == null ? void 0 : a.readOnly),
112
- required: w,
113
+ required: B,
113
114
  invalid: V,
114
115
  placeholder: Y,
115
- className: _(t["tedi-textfield__input"], X, {
116
- [t["tedi-textfield__input--hidden-arrows"]]: Z
116
+ className: _(r["tedi-textfield__input"], X, {
117
+ [r["tedi-textfield__input--hidden-arrows"]]: Z
117
118
  }),
118
- onFocus: (r) => {
119
+ onFocus: (t) => {
119
120
  var l;
120
- (l = a == null ? void 0 : a.onFocus) == null || l.call(a, r), A == null || A(r);
121
+ (l = a == null ? void 0 : a.onFocus) == null || l.call(a, t), A == null || A(t);
121
122
  },
122
- onBlur: (r) => {
123
+ onBlur: (t) => {
123
124
  var l;
124
- (l = a == null ? void 0 : a.onBlur) == null || l.call(a, r), k == null || k(r);
125
+ (l = a == null ? void 0 : a.onBlur) == null || l.call(a, t), C == null || C(t);
125
126
  },
126
- isTextArea: le,
127
- "aria-describedby": !e || Array.isArray(e) && e.length === 0 ? void 0 : Array.isArray(e) ? e.map((r, l) => `${u}-helper-${l}`).join(" ") : `${u}-helper`,
127
+ isTextArea: ne,
128
+ "aria-describedby": !e || Array.isArray(e) && e.length === 0 ? void 0 : Array.isArray(e) ? e.map((t, l) => `${u}-helper-${l}`).join(" ") : `${u}-helper`,
128
129
  "aria-label": z && typeof g == "string" ? g : void 0,
129
- ref: E
130
+ ref: T
130
131
  }
131
- ), xe = _(
132
- t["tedi-textfield"],
133
- { [t[`tedi-textfield--${s}`]]: s },
134
- { [t["tedi-textfield--with-icon"]]: i },
135
- { [t["tedi-textfield--invalid"]]: V },
136
- { [t["tedi-textfield--valid"]]: me },
137
- { [t["tedi-textfield--clearable"]]: f },
132
+ ), he = _(
133
+ r["tedi-textfield"],
134
+ { [r[`tedi-textfield--${s}`]]: s },
135
+ { [r["tedi-textfield--with-icon"]]: i },
136
+ { [r["tedi-textfield--invalid"]]: V },
137
+ { [r["tedi-textfield--valid"]]: ue },
138
+ { [r["tedi-textfield--clearable"]]: c },
139
+ { [r["tedi-textfield--clear-on-interaction"]]: c && G },
138
140
  W
139
- ), he = () => !e || Array.isArray(e) && e.length === 0 ? null : /* @__PURE__ */ n("div", { className: t["tedi-textfield__feedback-wrapper"], children: Array.isArray(e) ? e.map((r, l) => /* @__PURE__ */ n(U, { ...r, id: `${u}-helper-${l}` }, l)) : /* @__PURE__ */ n(U, { ...e, id: `${u}-helper` }) });
140
- return /* @__PURE__ */ S("div", { "data-name": "textfield", ...oe, className: xe, children: [
141
- !fe && /* @__PURE__ */ n(Ne, { id: u, label: g, required: w, hideLabel: z, size: ue }),
141
+ ), _e = () => !e || Array.isArray(e) && e.length === 0 ? null : /* @__PURE__ */ n("div", { className: r["tedi-textfield__feedback-wrapper"], children: Array.isArray(e) ? e.map((t, l) => /* @__PURE__ */ n(U, { ...t, id: `${u}-helper-${l}` }, l)) : /* @__PURE__ */ n(U, { ...e, id: `${u}-helper` }) });
142
+ return /* @__PURE__ */ S("div", { "data-name": "textfield", ...de, className: he, children: [
143
+ !me && /* @__PURE__ */ n(Ae, { id: u, label: g, required: B, hideLabel: z, size: pe }),
142
144
  /* @__PURE__ */ S(
143
145
  "div",
144
146
  {
145
- className: t["tedi-textfield__inner"],
146
- onKeyDown: re,
147
- onKeyUp: ee,
148
- onKeyPress: te,
149
- onClick: ae,
150
- ref: T,
147
+ className: r["tedi-textfield__inner"],
148
+ onKeyDown: te,
149
+ onKeyUp: re,
150
+ onKeyPress: ae,
151
+ onClick: ie,
152
+ ref: O,
151
153
  children: [
152
- ne,
153
- ve,
154
154
  se,
155
- (R || i) && ye
155
+ ve,
156
+ oe,
157
+ (R || i) && xe
156
158
  ]
157
159
  }
158
160
  ),
159
- he()
161
+ _e()
160
162
  ] });
161
163
  });
162
164
  Be.displayName = "TextField";
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e={"tedi-textfield":"tedi-textfield-376bbeed","tedi-textfield__inner":"tedi-textfield__inner-98791cdd","tedi-textfield__input":"tedi-textfield__input-ade0f9a6","tedi-textfield--invalid":"tedi-textfield--invalid-290ce18d","tedi-textfield--valid":"tedi-textfield--valid-273af8c0","tedi-textfield--clearable":"tedi-textfield--clearable-f47f0508","tedi-textfield--with-icon":"tedi-textfield--with-icon-db2c6f01","tedi-textfield--small":"tedi-textfield--small-4ffcc517","tedi-textfield--large":"tedi-textfield--large-0e4d788c","tedi-textfield__right-area":"tedi-textfield__right-area-6ac81c6b","tedi-textfield__icon-wrapper":"tedi-textfield__icon-wrapper-4935814e","tedi-textfield--inline":"tedi-textfield--inline-7ed55c4e","tedi-textfield__icon":"tedi-textfield__icon-05d4adc8","tedi-textfield__feedback-wrapper":"tedi-textfield__feedback-wrapper-9d47f9c6","tedi-textfield__separator":"tedi-textfield__separator-63d1ba14"};exports.default=e;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e={"tedi-textfield":"tedi-textfield-376bbeed","tedi-textfield__inner":"tedi-textfield__inner-98791cdd","tedi-textfield__input":"tedi-textfield__input-ade0f9a6","tedi-textfield--invalid":"tedi-textfield--invalid-290ce18d","tedi-textfield--valid":"tedi-textfield--valid-273af8c0","tedi-textfield--clearable":"tedi-textfield--clearable-f47f0508","tedi-textfield--with-icon":"tedi-textfield--with-icon-db2c6f01","tedi-textfield--small":"tedi-textfield--small-4ffcc517","tedi-textfield--large":"tedi-textfield--large-0e4d788c","tedi-textfield__right-area":"tedi-textfield__right-area-6ac81c6b","tedi-textfield--clear-on-interaction":"tedi-textfield--clear-on-interaction-155ed896","tedi-textfield__clear-button":"tedi-textfield__clear-button-edbbffef","tedi-textfield__icon-wrapper":"tedi-textfield__icon-wrapper-4935814e","tedi-textfield--inline":"tedi-textfield--inline-7ed55c4e","tedi-textfield__icon":"tedi-textfield__icon-05d4adc8","tedi-textfield__feedback-wrapper":"tedi-textfield__feedback-wrapper-9d47f9c6","tedi-textfield__separator":"tedi-textfield__separator-63d1ba14"};exports.default=e;
@@ -9,6 +9,8 @@ const e = {
9
9
  "tedi-textfield--small": "tedi-textfield--small-4ffcc517",
10
10
  "tedi-textfield--large": "tedi-textfield--large-0e4d788c",
11
11
  "tedi-textfield__right-area": "tedi-textfield__right-area-6ac81c6b",
12
+ "tedi-textfield--clear-on-interaction": "tedi-textfield--clear-on-interaction-155ed896",
13
+ "tedi-textfield__clear-button": "tedi-textfield__clear-button-edbbffef",
12
14
  "tedi-textfield__icon-wrapper": "tedi-textfield__icon-wrapper-4935814e",
13
15
  "tedi-textfield--inline": "tedi-textfield--inline-7ed55c4e",
14
16
  "tedi-textfield__icon": "tedi-textfield__icon-05d4adc8",
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react"),_=require("../../providers/label-provider/use-labels.cjs.js"),q=({accept:F,maxSize:o},f)=>{if(!F&&!o)return;const p=[F&&`${f("file-upload.accept")} ${F.replaceAll(",",", ")}`,o&&`${f("file-upload.max-size")} ${o}MB`].filter(Boolean).join(". ");return p.length?{text:p}:void 0},B=()=>`${Date.now()}-${Math.random().toString(36).slice(2)}`,k=100,P=F=>{const{getLabel:o}=_.useLabels(),{accept:f,maxSize:p,multiple:$=!1,validateIndividually:b=!1,defaultFiles:H=[],onChange:l,onDelete:m,files:x,announcementTimeout:M=5e3,showRestrictions:L=!0}=F,g=x!==void 0,[A,j]=u.useState(H),c=g?x:A,C=L?q({accept:f,maxSize:p},o):void 0,[N,h]=u.useState(void 0),V=N??C,[z,w]=u.useState(""),y=u.useRef(!0),v=u.useRef(),T=u.useRef();u.useEffect(()=>()=>{y.current=!1,v.current&&clearTimeout(v.current),T.current&&clearTimeout(T.current)},[]);const E=u.useCallback(e=>{!e||!y.current||(w(""),v.current&&clearTimeout(v.current),T.current&&clearTimeout(T.current),v.current=setTimeout(()=>{y.current&&(w(e),T.current=setTimeout(()=>{y.current&&w("")},M))},k))},[M]),a=u.useRef(null),I=e=>{var i;if(!f)return!0;const s=f.split(",").map(d=>d.trim().toLowerCase()),n=e.name.includes(".")?`.${(i=e.name.split(".").pop())==null?void 0:i.toLowerCase()}`:"",r=e.type.toLowerCase();return s.includes(n)||s.includes(r)},O=e=>{const s=e.reduce((n,{type:r,file:i})=>(n[r].push(i.name),n),{extension:[],size:[]});return Object.entries(s).filter(([n,r])=>r.length).map(([n,r])=>{const i=r.map(d=>`'${d}'`).join(", ");return o(`file-upload.${n}-rejected`,i)}).join(". ")};return{innerFiles:c,uploadErrorHelper:V,onFileChange:e=>{if(e.target.files){const s=Array.from(e.target.files),n=[],r=s.map(t=>{const R=I(t),S=!p||t.size<=p*1024**2;R||n.push({type:"extension",file:t}),S||n.push({type:"size",file:t});const U=new File([t],t.name,{type:t.type,lastModified:t.lastModified});return Object.assign(U,{id:B(),isLoading:!1,isValid:R&&S})});let i;if(!$)i=r.length>0&&r[0].isValid?[r[0]]:c;else if(b)i=[...c,...r];else{const t=r.filter(R=>R.isValid);i=t.length>0?[...c,...t]:c}const d=i.filter(t=>!c.includes(t)).length;if(d>0&&!g&&j(i),l==null||l(i),n.length){const t=O(n);h({type:"error",text:t}),E(t)}else h(void 0),d>0&&E(o("file-upload.success-added",d.toString()));e.target.value="",a.current&&(a.current.value="")}},onFileRemove:e=>{const s=c.filter(n=>n!==e);g||j(s),m==null||m(e),l==null||l(s),s.length===0&&h(void 0),E(o("file-upload.removed",e.name??"")),a.current&&(a.current.value="")},handleClear:()=>{const e=[...c];return e.forEach(s=>m==null?void 0:m(s)),g||j([]),l==null||l([]),h(void 0),E(o("file-upload.cleared")),a.current&&(a.current.value=""),e},fileInputRef:a,announcement:z}};exports.useFileUpload=P;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react"),W=require("../../providers/label-provider/use-labels.cjs.js"),C=s=>{if(s<1024)return`${s} B`;const n=["KB","MB","GB","TB"];let c=s/1024,d=0;for(;c>=1024&&d<n.length-1;)c/=1024,d+=1;return`${Math.round(c*10)/10} ${n[d]}`},G=({accept:s,maxSize:n},c)=>{if(!s&&!n)return;const d=[s&&`${c("file-upload.accept")} ${s.replaceAll(",",", ")}`,n&&`${c("file-upload.max-size")} ${C(n*1024**2)}`].filter(Boolean).join(". ");return d.length?{text:d}:void 0},K=()=>`${Date.now()}-${Math.random().toString(36).slice(2)}`,z=(s,n)=>s.name===n.name&&s.size===n.size&&s.lastModified===n.lastModified,P=100,Y=s=>{const{getLabel:n}=W.useLabels(),{accept:c,maxSize:d,multiple:A=!1,validateIndividually:I=!1,defaultFiles:N=[],onChange:f,onDelete:h,files:B,announcementTimeout:H=5e3,showRestrictions:b=!0}=s,$=B!==void 0,[O,x]=p.useState(N),u=$?B:O,L=b?G({accept:c,maxSize:d},n):void 0,[V,E]=p.useState(void 0),U=V??L,[_,R]=p.useState(""),M=p.useRef(!0),v=p.useRef(),T=p.useRef();p.useEffect(()=>()=>{M.current=!1,v.current&&clearTimeout(v.current),T.current&&clearTimeout(T.current)},[]);const j=p.useCallback(t=>{!t||!M.current||(R(""),v.current&&clearTimeout(v.current),T.current&&clearTimeout(T.current),v.current=setTimeout(()=>{M.current&&(R(t),T.current=setTimeout(()=>{M.current&&R("")},H))},P))},[H]),F=p.useRef(null),k=t=>{var m;if(!c)return!0;const l=c.split(",").map(o=>o.trim().toLowerCase()),r=t.name.includes(".")?`.${(m=t.name.split(".").pop())==null?void 0:m.toLowerCase()}`:"",i=t.type.toLowerCase();return l.some(o=>o==="*"||o==="*/*"?!0:o.endsWith("/*")?i.startsWith(o.slice(0,-1)):o===r||o===i)},q=t=>{const l=t.reduce((r,{type:i,file:m})=>(r[i].push(m.name),r),{extension:[],size:[]});return Object.entries(l).filter(([r,i])=>i.length).map(([r,i])=>{const m=i.map(o=>`'${o}'`).join(", ");return n(`file-upload.${r}-rejected`,m)}).join(". ")};return{innerFiles:u,uploadErrorHelper:U,errorHelper:V,restrictionsHint:L,onFileChange:t=>{if(t.target.files){const l=Array.from(t.target.files),r=[],i=l.map(e=>{const a=k(e),w=!d||e.size<=d*1024**2;a||r.push({type:"extension",file:e}),w||r.push({type:"size",file:e});const S=new File([e],e.name,{type:e.type,lastModified:e.lastModified});return Object.assign(S,{id:K(),isLoading:!1,isValid:a&&w})}),m=e=>e.filter((a,w)=>!u.some(S=>z(S,a))&&e.findIndex(S=>z(S,a))===w),o=A?Array.from(new Set(i.filter(e=>u.some(a=>z(a,e))).map(e=>e.name??""))):[];let g;if(!A)g=i.length>0&&i[0].isValid?[i[0]]:u;else if(I){const e=m(i);g=e.length>0?[...u,...e]:u}else{const e=m(i.filter(a=>a.isValid));g=e.length>0?[...u,...e]:u}const y=g.filter(e=>!u.includes(e)).length;if(y>0&&!$&&x(g),f==null||f(g),r.length){const e=q(r);E({type:"error",text:e}),j(e)}else{E(void 0);const e=[y>0&&n("file-upload.success-added",y.toString()),o.length&&n("file-upload.duplicates-skipped",o.map(a=>`'${a}'`).join(", "))].filter(Boolean);e.length&&j(e.join(". "))}t.target.value="",F.current&&(F.current.value="")}},onFileRemove:t=>{const l=u.filter(r=>r!==t);$||x(l),h==null||h(t),f==null||f(l),(l.length===0||t.isValid===!1&&!l.some(r=>r.isValid===!1))&&E(void 0),j(n("file-upload.removed",t.name??"")),F.current&&(F.current.value="")},handleClear:()=>{const t=[...u];return t.forEach(l=>h==null?void 0:h(l)),$||x([]),f==null||f([]),E(void 0),j(n("file-upload.cleared")),F.current&&(F.current.value=""),t},fileInputRef:F,announcement:_}};exports.formatFileSize=C;exports.useFileUpload=Y;
@@ -76,9 +76,17 @@ export interface UseFileUploadProps {
76
76
  */
77
77
  showRestrictions?: boolean;
78
78
  }
79
+ /**
80
+ * Formats a byte count into a readable size (`512 KB`, `2.5 MB`, …). Uses 1024-based
81
+ * units to stay consistent with the size validation (`maxSize * 1024 ** 2`), and rolls
82
+ * sub-1-unit values down so `0.5 MB` reads as `512 KB` rather than `0.5MB` (#888).
83
+ */
84
+ export declare const formatFileSize: (bytes: number) => string;
79
85
  export declare const useFileUpload: (props: UseFileUploadProps) => {
80
86
  innerFiles: FileUploadFile[];
81
87
  uploadErrorHelper: FeedbackTextProps | undefined;
88
+ errorHelper: FeedbackTextProps | undefined;
89
+ restrictionsHint: FeedbackTextProps | undefined;
82
90
  onFileChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
83
91
  onFileRemove: (file: FileUploadFile) => void;
84
92
  handleClear: () => FileUploadFile[];
@@ -1,100 +1,123 @@
1
- import c, { useEffect as U } from "react";
2
- import { useLabels as B } from "../../providers/label-provider/use-labels.es.js";
3
- const k = ({ accept: F, maxSize: o }, f) => {
4
- if (!F && !o) return;
5
- const p = [
6
- F && `${f("file-upload.accept")} ${F.replaceAll(",", ", ")}`,
7
- o && `${f("file-upload.max-size")} ${o}MB`
1
+ import p, { useEffect as b } from "react";
2
+ import { useLabels as G } from "../../providers/label-provider/use-labels.es.js";
3
+ const K = (s) => {
4
+ if (s < 1024) return `${s} B`;
5
+ const n = ["KB", "MB", "GB", "TB"];
6
+ let c = s / 1024, d = 0;
7
+ for (; c >= 1024 && d < n.length - 1; )
8
+ c /= 1024, d += 1;
9
+ return `${Math.round(c * 10) / 10} ${n[d]}`;
10
+ }, Y = ({ accept: s, maxSize: n }, c) => {
11
+ if (!s && !n) return;
12
+ const d = [
13
+ s && `${c("file-upload.accept")} ${s.replaceAll(",", ", ")}`,
14
+ n && `${c("file-upload.max-size")} ${K(n * 1024 ** 2)}`
8
15
  ].filter(Boolean).join(". ");
9
- return p.length ? { text: p } : void 0;
10
- }, Y = () => `${Date.now()}-${Math.random().toString(36).slice(2)}`, q = 100, Q = (F) => {
11
- const { getLabel: o } = B(), {
12
- accept: f,
13
- maxSize: p,
14
- multiple: H = !1,
15
- validateIndividually: S = !1,
16
- defaultFiles: A = [],
17
- onChange: l,
18
- onDelete: m,
19
- files: $,
20
- announcementTimeout: j = 5e3,
21
- showRestrictions: C = !0
22
- } = F, h = $ !== void 0, [L, R] = c.useState(A), u = h ? $ : L, N = C ? k({ accept: f, maxSize: p }, o) : void 0, [V, g] = c.useState(void 0), _ = V ?? N, [b, w] = c.useState(""), y = c.useRef(!0), v = c.useRef(), T = c.useRef();
23
- U(() => () => {
24
- y.current = !1, v.current && clearTimeout(v.current), T.current && clearTimeout(T.current);
16
+ return d.length ? { text: d } : void 0;
17
+ }, q = () => `${Date.now()}-${Math.random().toString(36).slice(2)}`, A = (s, n) => s.name === n.name && s.size === n.size && s.lastModified === n.lastModified, D = 100, ee = (s) => {
18
+ const { getLabel: n } = G(), {
19
+ accept: c,
20
+ maxSize: d,
21
+ multiple: B = !1,
22
+ validateIndividually: I = !1,
23
+ defaultFiles: L = [],
24
+ onChange: f,
25
+ onDelete: F,
26
+ files: H,
27
+ announcementTimeout: V = 5e3,
28
+ showRestrictions: N = !0
29
+ } = s, x = H !== void 0, [_, R] = p.useState(L), a = x ? H : _, y = N ? Y({ accept: c, maxSize: d }, n) : void 0, [C, E] = p.useState(void 0), O = C ?? y, [U, S] = p.useState(""), w = p.useRef(!0), v = p.useRef(), T = p.useRef();
30
+ b(() => () => {
31
+ w.current = !1, v.current && clearTimeout(v.current), T.current && clearTimeout(T.current);
25
32
  }, []);
26
- const E = c.useCallback(
27
- (e) => {
28
- !e || !y.current || (w(""), v.current && clearTimeout(v.current), T.current && clearTimeout(T.current), v.current = setTimeout(() => {
29
- y.current && (w(e), T.current = setTimeout(() => {
30
- y.current && w("");
31
- }, j));
32
- }, q));
33
+ const M = p.useCallback(
34
+ (t) => {
35
+ !t || !w.current || (S(""), v.current && clearTimeout(v.current), T.current && clearTimeout(T.current), v.current = setTimeout(() => {
36
+ w.current && (S(t), T.current = setTimeout(() => {
37
+ w.current && S("");
38
+ }, V));
39
+ }, D));
33
40
  },
34
- [j]
35
- ), a = c.useRef(null), z = (e) => {
36
- var i;
37
- if (!f) return !0;
38
- const s = f.split(",").map((d) => d.trim().toLowerCase()), n = e.name.includes(".") ? `.${(i = e.name.split(".").pop()) == null ? void 0 : i.toLowerCase()}` : "", r = e.type.toLowerCase();
39
- return s.includes(n) || s.includes(r);
40
- }, I = (e) => {
41
- const s = e.reduce(
42
- (n, { type: r, file: i }) => (n[r].push(i.name), n),
41
+ [V]
42
+ ), h = p.useRef(null), k = (t) => {
43
+ var m;
44
+ if (!c) return !0;
45
+ const l = c.split(",").map((o) => o.trim().toLowerCase()), r = t.name.includes(".") ? `.${(m = t.name.split(".").pop()) == null ? void 0 : m.toLowerCase()}` : "", i = t.type.toLowerCase();
46
+ return l.some((o) => o === "*" || o === "*/*" ? !0 : o.endsWith("/*") ? i.startsWith(o.slice(0, -1)) : o === r || o === i);
47
+ }, W = (t) => {
48
+ const l = t.reduce(
49
+ (r, { type: i, file: m }) => (r[i].push(m.name), r),
43
50
  { extension: [], size: [] }
44
51
  );
45
- return Object.entries(s).filter(([n, r]) => r.length).map(([n, r]) => {
46
- const i = r.map((d) => `'${d}'`).join(", ");
47
- return o(`file-upload.${n}-rejected`, i);
52
+ return Object.entries(l).filter(([r, i]) => i.length).map(([r, i]) => {
53
+ const m = i.map((o) => `'${o}'`).join(", ");
54
+ return n(`file-upload.${r}-rejected`, m);
48
55
  }).join(". ");
49
56
  };
50
57
  return {
51
- innerFiles: u,
52
- uploadErrorHelper: _,
53
- onFileChange: (e) => {
54
- if (e.target.files) {
55
- const s = Array.from(e.target.files), n = [], r = s.map((t) => {
56
- const x = z(t), M = !p || t.size <= p * 1024 ** 2;
57
- x || n.push({ type: "extension", file: t }), M || n.push({ type: "size", file: t });
58
- const O = new File([t], t.name, {
59
- type: t.type,
60
- lastModified: t.lastModified
58
+ innerFiles: a,
59
+ uploadErrorHelper: O,
60
+ errorHelper: C,
61
+ restrictionsHint: y,
62
+ onFileChange: (t) => {
63
+ if (t.target.files) {
64
+ const l = Array.from(t.target.files), r = [], i = l.map((e) => {
65
+ const u = k(e), j = !d || e.size <= d * 1024 ** 2;
66
+ u || r.push({ type: "extension", file: e }), j || r.push({ type: "size", file: e });
67
+ const $ = new File([e], e.name, {
68
+ type: e.type,
69
+ lastModified: e.lastModified
61
70
  });
62
- return Object.assign(O, {
63
- id: Y(),
71
+ return Object.assign($, {
72
+ id: q(),
64
73
  isLoading: !1,
65
- isValid: x && M
74
+ isValid: u && j
66
75
  });
67
- });
68
- let i;
69
- if (!H)
70
- i = r.length > 0 && r[0].isValid ? [r[0]] : u;
71
- else if (S)
72
- i = [...u, ...r];
73
- else {
74
- const t = r.filter((x) => x.isValid);
75
- i = t.length > 0 ? [...u, ...t] : u;
76
+ }), m = (e) => e.filter(
77
+ (u, j) => !a.some(($) => A($, u)) && e.findIndex(($) => A($, u)) === j
78
+ ), o = B ? Array.from(
79
+ new Set(
80
+ i.filter((e) => a.some((u) => A(u, e))).map((e) => e.name ?? "")
81
+ )
82
+ ) : [];
83
+ let g;
84
+ if (!B)
85
+ g = i.length > 0 && i[0].isValid ? [i[0]] : a;
86
+ else if (I) {
87
+ const e = m(i);
88
+ g = e.length > 0 ? [...a, ...e] : a;
89
+ } else {
90
+ const e = m(i.filter((u) => u.isValid));
91
+ g = e.length > 0 ? [...a, ...e] : a;
76
92
  }
77
- const d = i.filter((t) => !u.includes(t)).length;
78
- if (d > 0 && !h && R(i), l == null || l(i), n.length) {
79
- const t = I(n);
80
- g({ type: "error", text: t }), E(t);
81
- } else
82
- g(void 0), d > 0 && E(o("file-upload.success-added", d.toString()));
83
- e.target.value = "", a.current && (a.current.value = "");
93
+ const z = g.filter((e) => !a.includes(e)).length;
94
+ if (z > 0 && !x && R(g), f == null || f(g), r.length) {
95
+ const e = W(r);
96
+ E({ type: "error", text: e }), M(e);
97
+ } else {
98
+ E(void 0);
99
+ const e = [
100
+ z > 0 && n("file-upload.success-added", z.toString()),
101
+ o.length && n("file-upload.duplicates-skipped", o.map((u) => `'${u}'`).join(", "))
102
+ ].filter(Boolean);
103
+ e.length && M(e.join(". "));
104
+ }
105
+ t.target.value = "", h.current && (h.current.value = "");
84
106
  }
85
107
  },
86
- onFileRemove: (e) => {
87
- const s = u.filter((n) => n !== e);
88
- h || R(s), m == null || m(e), l == null || l(s), s.length === 0 && g(void 0), E(o("file-upload.removed", e.name ?? "")), a.current && (a.current.value = "");
108
+ onFileRemove: (t) => {
109
+ const l = a.filter((r) => r !== t);
110
+ x || R(l), F == null || F(t), f == null || f(l), (l.length === 0 || t.isValid === !1 && !l.some((r) => r.isValid === !1)) && E(void 0), M(n("file-upload.removed", t.name ?? "")), h.current && (h.current.value = "");
89
111
  },
90
112
  handleClear: () => {
91
- const e = [...u];
92
- return e.forEach((s) => m == null ? void 0 : m(s)), h || R([]), l == null || l([]), g(void 0), E(o("file-upload.cleared")), a.current && (a.current.value = ""), e;
113
+ const t = [...a];
114
+ return t.forEach((l) => F == null ? void 0 : F(l)), x || R([]), f == null || f([]), E(void 0), M(n("file-upload.cleared")), h.current && (h.current.value = ""), t;
93
115
  },
94
- fileInputRef: a,
95
- announcement: b
116
+ fileInputRef: h,
117
+ announcement: U
96
118
  };
97
119
  };
98
120
  export {
99
- Q as useFileUpload
121
+ K as formatFileSize,
122
+ ee as useFileUpload
100
123
  };