@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.
- package/bundle-stats.html +1 -1
- package/external/hoist-non-react-statics/external/react-is/cjs/react-is.development.cjs.js +1 -1
- package/external/hoist-non-react-statics/external/react-is/cjs/react-is.development.es.js +1 -1
- package/external/hoist-non-react-statics/external/react-is/cjs/react-is.production.min.cjs.js +1 -1
- package/external/hoist-non-react-statics/external/react-is/cjs/react-is.production.min.es.js +1 -1
- package/external/hoist-non-react-statics/external/react-is/index.cjs.js +1 -1
- package/external/hoist-non-react-statics/external/react-is/index.es.js +1 -1
- package/external/prop-types/external/react-is/cjs/react-is.development.cjs.js +1 -1
- package/external/prop-types/external/react-is/cjs/react-is.development.es.js +1 -1
- package/external/prop-types/external/react-is/cjs/react-is.production.min.cjs.js +1 -1
- package/external/prop-types/external/react-is/cjs/react-is.production.min.es.js +1 -1
- package/external/prop-types/external/react-is/index.cjs.js +1 -1
- package/external/prop-types/external/react-is/index.es.js +1 -1
- package/index.css +1 -1
- package/package.json +1 -1
- package/src/tedi/components/form/file-dropzone/file-dropzone.cjs.js +1 -1
- package/src/tedi/components/form/file-dropzone/file-dropzone.d.ts +10 -3
- package/src/tedi/components/form/file-dropzone/file-dropzone.es.js +103 -100
- package/src/tedi/components/form/file-dropzone/file-dropzone.module.scss.cjs.js +1 -1
- package/src/tedi/components/form/file-dropzone/file-dropzone.module.scss.es.js +5 -4
- package/src/tedi/components/form/multi-value-field/multi-value-field.cjs.js +1 -1
- package/src/tedi/components/form/multi-value-field/multi-value-field.d.ts +6 -0
- package/src/tedi/components/form/multi-value-field/multi-value-field.es.js +126 -117
- package/src/tedi/components/form/multi-value-field/multi-value-field.module.scss.cjs.js +1 -1
- package/src/tedi/components/form/multi-value-field/multi-value-field.module.scss.es.js +2 -0
- package/src/tedi/components/form/select/components/select-clear-indicator.cjs.js +1 -1
- package/src/tedi/components/form/select/components/select-clear-indicator.es.js +21 -10
- package/src/tedi/components/form/select/select.cjs.js +1 -1
- package/src/tedi/components/form/select/select.d.ts +6 -0
- package/src/tedi/components/form/select/select.es.js +173 -171
- package/src/tedi/components/form/select/select.module.scss.cjs.js +1 -1
- package/src/tedi/components/form/select/select.module.scss.es.js +2 -1
- package/src/tedi/components/form/textarea/textarea.d.ts +1 -1
- package/src/tedi/components/form/textfield/textfield.cjs.js +1 -1
- package/src/tedi/components/form/textfield/textfield.d.ts +6 -0
- package/src/tedi/components/form/textfield/textfield.es.js +86 -84
- package/src/tedi/components/form/textfield/textfield.module.scss.cjs.js +1 -1
- package/src/tedi/components/form/textfield/textfield.module.scss.es.js +2 -0
- package/src/tedi/helpers/hooks/use-file-upload.cjs.js +1 -1
- package/src/tedi/helpers/hooks/use-file-upload.d.ts +8 -0
- package/src/tedi/helpers/hooks/use-file-upload.es.js +102 -79
- package/src/tedi/providers/label-provider/labels-map.cjs.js +1 -1
- package/src/tedi/providers/label-provider/labels-map.d.ts +7 -0
- package/src/tedi/providers/label-provider/labels-map.es.js +19 -12
- package/tedi.cjs.js +1 -1
- 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
|
|
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
|
|
6
|
-
import { Separator as
|
|
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
|
|
9
|
-
import { FormLabel as
|
|
10
|
-
import { useOptionalInputGroup as
|
|
11
|
-
import
|
|
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
|
|
14
|
-
const
|
|
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 =
|
|
17
|
+
}, Be = be((I, J) => {
|
|
18
18
|
var M;
|
|
19
19
|
const { getCurrentBreakpointProps: Q } = ke(I.defaultServerBreakpoint), {
|
|
20
|
-
id:
|
|
20
|
+
id: ze,
|
|
21
21
|
label: g,
|
|
22
22
|
className: W,
|
|
23
23
|
inputClassName: X,
|
|
24
24
|
disabled: d,
|
|
25
|
-
required:
|
|
25
|
+
required: B,
|
|
26
26
|
hideLabel: z,
|
|
27
|
-
invalid:
|
|
27
|
+
invalid: f,
|
|
28
28
|
readOnly: F,
|
|
29
29
|
icon: i,
|
|
30
|
-
onIconClick:
|
|
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
|
-
|
|
36
|
+
showClearOnInteraction: G,
|
|
37
|
+
onClear: v,
|
|
37
38
|
onChange: o,
|
|
38
|
-
onChangeEvent:
|
|
39
|
-
onKeyUp:
|
|
40
|
-
onKeyDown:
|
|
41
|
-
onKeyPress:
|
|
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:
|
|
46
|
-
onClick:
|
|
46
|
+
onBlur: C,
|
|
47
|
+
onClick: ie,
|
|
47
48
|
helper: e,
|
|
48
49
|
input: a,
|
|
49
|
-
name:
|
|
50
|
-
isTextArea:
|
|
51
|
-
startSlot:
|
|
52
|
-
endSlot:
|
|
53
|
-
...
|
|
54
|
-
} = Q(I) || {}, { getLabel: L } =
|
|
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
|
|
58
|
+
return T.current;
|
|
58
59
|
},
|
|
59
60
|
get inner() {
|
|
60
|
-
return
|
|
61
|
+
return O.current;
|
|
61
62
|
}
|
|
62
63
|
}));
|
|
63
|
-
const V = b(() => Array.isArray(e) ?
|
|
64
|
-
(
|
|
65
|
-
h ||
|
|
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 =
|
|
69
|
-
h ||
|
|
70
|
-
}, [h, o,
|
|
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
|
|
73
|
-
size: s === "large" ? 24 : s === "small" ? !!
|
|
74
|
-
className:
|
|
75
|
-
}, q = typeof i == "string" ? { ...
|
|
76
|
-
return
|
|
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: _(
|
|
82
|
-
onClick: d ? void 0 :
|
|
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:
|
|
87
|
-
}, [i, s,
|
|
88
|
-
|
|
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:
|
|
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:
|
|
95
|
+
className: r["tedi-textfield__clear-button"]
|
|
95
96
|
}
|
|
96
|
-
) : null, [
|
|
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
|
-
|
|
99
|
+
c && i && /* @__PURE__ */ n(ge, { color: "primary", axis: "vertical", className: r["tedi-textfield__separator"] }),
|
|
99
100
|
i && H()
|
|
100
|
-
] }), [
|
|
101
|
-
|
|
101
|
+
] }), [c, i, K, H]), ve = /* @__PURE__ */ n(
|
|
102
|
+
Ne,
|
|
102
103
|
{
|
|
103
104
|
...a,
|
|
104
105
|
id: u,
|
|
105
|
-
name:
|
|
106
|
+
name: le,
|
|
106
107
|
value: P,
|
|
107
108
|
defaultValue: $,
|
|
108
|
-
onChange:
|
|
109
|
-
onChangeEvent:
|
|
109
|
+
onChange: ye,
|
|
110
|
+
onChangeEvent: ee,
|
|
110
111
|
disabled: d,
|
|
111
112
|
readOnly: F || (a == null ? void 0 : a.readOnly),
|
|
112
|
-
required:
|
|
113
|
+
required: B,
|
|
113
114
|
invalid: V,
|
|
114
115
|
placeholder: Y,
|
|
115
|
-
className: _(
|
|
116
|
-
[
|
|
116
|
+
className: _(r["tedi-textfield__input"], X, {
|
|
117
|
+
[r["tedi-textfield__input--hidden-arrows"]]: Z
|
|
117
118
|
}),
|
|
118
|
-
onFocus: (
|
|
119
|
+
onFocus: (t) => {
|
|
119
120
|
var l;
|
|
120
|
-
(l = a == null ? void 0 : a.onFocus) == null || l.call(a,
|
|
121
|
+
(l = a == null ? void 0 : a.onFocus) == null || l.call(a, t), A == null || A(t);
|
|
121
122
|
},
|
|
122
|
-
onBlur: (
|
|
123
|
+
onBlur: (t) => {
|
|
123
124
|
var l;
|
|
124
|
-
(l = a == null ? void 0 : a.onBlur) == null || l.call(a,
|
|
125
|
+
(l = a == null ? void 0 : a.onBlur) == null || l.call(a, t), C == null || C(t);
|
|
125
126
|
},
|
|
126
|
-
isTextArea:
|
|
127
|
-
"aria-describedby": !e || Array.isArray(e) && e.length === 0 ? void 0 : Array.isArray(e) ? e.map((
|
|
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:
|
|
130
|
+
ref: T
|
|
130
131
|
}
|
|
131
|
-
),
|
|
132
|
-
|
|
133
|
-
{ [
|
|
134
|
-
{ [
|
|
135
|
-
{ [
|
|
136
|
-
{ [
|
|
137
|
-
{ [
|
|
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
|
-
),
|
|
140
|
-
return /* @__PURE__ */ S("div", { "data-name": "textfield", ...
|
|
141
|
-
!
|
|
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:
|
|
146
|
-
onKeyDown:
|
|
147
|
-
onKeyUp:
|
|
148
|
-
onKeyPress:
|
|
149
|
-
onClick:
|
|
150
|
-
ref:
|
|
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
|
-
|
|
155
|
+
ve,
|
|
156
|
+
oe,
|
|
157
|
+
(R || i) && xe
|
|
156
158
|
]
|
|
157
159
|
}
|
|
158
160
|
),
|
|
159
|
-
|
|
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
|
|
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
|
|
2
|
-
import { useLabels as
|
|
3
|
-
const
|
|
4
|
-
if (
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
10
|
-
},
|
|
11
|
-
const { getLabel:
|
|
12
|
-
accept:
|
|
13
|
-
maxSize:
|
|
14
|
-
multiple:
|
|
15
|
-
validateIndividually:
|
|
16
|
-
defaultFiles:
|
|
17
|
-
onChange:
|
|
18
|
-
onDelete:
|
|
19
|
-
files:
|
|
20
|
-
announcementTimeout:
|
|
21
|
-
showRestrictions:
|
|
22
|
-
} =
|
|
23
|
-
|
|
24
|
-
|
|
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
|
|
27
|
-
(
|
|
28
|
-
!
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
},
|
|
32
|
-
},
|
|
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
|
-
[
|
|
35
|
-
),
|
|
36
|
-
var
|
|
37
|
-
if (!
|
|
38
|
-
const
|
|
39
|
-
return
|
|
40
|
-
},
|
|
41
|
-
const
|
|
42
|
-
(
|
|
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(
|
|
46
|
-
const
|
|
47
|
-
return
|
|
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:
|
|
52
|
-
uploadErrorHelper:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
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(
|
|
63
|
-
id:
|
|
71
|
+
return Object.assign($, {
|
|
72
|
+
id: q(),
|
|
64
73
|
isLoading: !1,
|
|
65
|
-
isValid:
|
|
74
|
+
isValid: u && j
|
|
66
75
|
});
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
|
78
|
-
if (
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
} else
|
|
82
|
-
|
|
83
|
-
|
|
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: (
|
|
87
|
-
const
|
|
88
|
-
|
|
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
|
|
92
|
-
return
|
|
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:
|
|
95
|
-
announcement:
|
|
116
|
+
fileInputRef: h,
|
|
117
|
+
announcement: U
|
|
96
118
|
};
|
|
97
119
|
};
|
|
98
120
|
export {
|
|
99
|
-
|
|
121
|
+
K as formatFileSize,
|
|
122
|
+
ee as useFileUpload
|
|
100
123
|
};
|