@sps-woodland/file-upload 8.52.2 → 8.53.1
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/lib/index.js +109 -106
- package/lib/index.umd.cjs +2 -2
- package/lib/style.css +1 -1
- package/package.json +18 -16
package/lib/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as e from "react";
|
|
2
|
-
import { Metadata as
|
|
3
|
-
import { parseFileSize as
|
|
4
|
-
import { Button as
|
|
5
|
-
import { GENERAL_ERROR_LARGE as
|
|
6
|
-
import { useWoodlandLanguage as
|
|
7
|
-
const
|
|
2
|
+
import { Metadata as we, cl as W, Spinner as ge } from "@sps-woodland/core";
|
|
3
|
+
import { parseFileSize as Fe, code as _ } from "@spscommerce/utils";
|
|
4
|
+
import { Button as z } from "@sps-woodland/buttons";
|
|
5
|
+
import { GENERAL_ERROR_LARGE as Ee, UPLOAD_LARGE as xe } from "@sps-woodland/illustrations";
|
|
6
|
+
import { useWoodlandLanguage as be } from "@spscommerce/i18n";
|
|
7
|
+
const G = {
|
|
8
8
|
"7Z": ["application/x-7z-compressed"],
|
|
9
9
|
AAC: ["audio/aac"],
|
|
10
10
|
ABW: ["application/x-abiword"],
|
|
@@ -108,7 +108,7 @@ const W = {
|
|
|
108
108
|
XUL: ["application/vnd.mozilla.xul+xml"],
|
|
109
109
|
ZIP: ["application/zip"]
|
|
110
110
|
};
|
|
111
|
-
function
|
|
111
|
+
function ye(o, i, l) {
|
|
112
112
|
return i in o ? Object.defineProperty(o, i, {
|
|
113
113
|
value: l,
|
|
114
114
|
enumerable: !0,
|
|
@@ -116,7 +116,7 @@ function be(o, i, l) {
|
|
|
116
116
|
writable: !0
|
|
117
117
|
}) : o[i] = l, o;
|
|
118
118
|
}
|
|
119
|
-
function
|
|
119
|
+
function Z(o, i) {
|
|
120
120
|
var l = Object.keys(o);
|
|
121
121
|
if (Object.getOwnPropertySymbols) {
|
|
122
122
|
var t = Object.getOwnPropertySymbols(o);
|
|
@@ -126,30 +126,30 @@ function z(o, i) {
|
|
|
126
126
|
}
|
|
127
127
|
return l;
|
|
128
128
|
}
|
|
129
|
-
function
|
|
129
|
+
function $(o) {
|
|
130
130
|
for (var i = 1; i < arguments.length; i++) {
|
|
131
131
|
var l = arguments[i] != null ? arguments[i] : {};
|
|
132
|
-
i % 2 ?
|
|
133
|
-
|
|
134
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(o, Object.getOwnPropertyDescriptors(l)) :
|
|
132
|
+
i % 2 ? Z(Object(l), !0).forEach(function(t) {
|
|
133
|
+
ye(o, t, l[t]);
|
|
134
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(o, Object.getOwnPropertyDescriptors(l)) : Z(Object(l)).forEach(function(t) {
|
|
135
135
|
Object.defineProperty(o, t, Object.getOwnPropertyDescriptor(l, t));
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
138
|
return o;
|
|
139
139
|
}
|
|
140
|
-
var
|
|
140
|
+
var Se = (o, i, l) => {
|
|
141
141
|
for (var t of Object.keys(o)) {
|
|
142
142
|
var r;
|
|
143
143
|
if (o[t] !== ((r = i[t]) !== null && r !== void 0 ? r : l[t]))
|
|
144
144
|
return !1;
|
|
145
145
|
}
|
|
146
146
|
return !0;
|
|
147
|
-
},
|
|
148
|
-
var l = o.defaultClassName, t =
|
|
147
|
+
}, T = (o) => (i) => {
|
|
148
|
+
var l = o.defaultClassName, t = $($({}, o.defaultVariants), i);
|
|
149
149
|
for (var r in t) {
|
|
150
|
-
var m,
|
|
151
|
-
if (
|
|
152
|
-
var p =
|
|
150
|
+
var m, F = (m = t[r]) !== null && m !== void 0 ? m : o.defaultVariants[r];
|
|
151
|
+
if (F != null) {
|
|
152
|
+
var p = F;
|
|
153
153
|
typeof p == "boolean" && (p = p === !0 ? "true" : "false");
|
|
154
154
|
var s = (
|
|
155
155
|
// @ts-expect-error
|
|
@@ -158,164 +158,167 @@ var ye = (o, i, l) => {
|
|
|
158
158
|
s && (l += " " + s);
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
|
-
for (var [
|
|
162
|
-
|
|
161
|
+
for (var [y, D] of o.compoundVariants)
|
|
162
|
+
Se(y, t, o.defaultVariants) && (l += " " + D);
|
|
163
163
|
return l;
|
|
164
|
-
}, Ue =
|
|
165
|
-
function
|
|
164
|
+
}, Ue = T({ defaultClassName: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw0", variantClassNames: { active: { true: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw1", false: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw2" }, mini: { true: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw3", false: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw4" }, error: { true: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw5", false: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw6" }, shown: { true: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw7", false: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw8" }, disabled: { true: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw9", false: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwa" } }, defaultVariants: { active: !1, mini: !1, error: !1, shown: !0, disabled: !1 }, compoundVariants: [] }), Ce = T({ defaultClassName: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwb", variantClassNames: { constrainContentWidth: { true: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwc", false: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwd" }, disabled: { true: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwe", false: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwf" } }, defaultVariants: { constrainContentWidth: !1, disabled: !1 }, compoundVariants: [] }), q = "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwg", je = T({ defaultClassName: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwh", variantClassNames: { mini: { true: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwi", false: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwj" }, error: { true: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwk", false: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwl" }, disabled: { true: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwm", false: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwn" } }, defaultVariants: { mini: !1, error: !1, disabled: !1 }, compoundVariants: [] }), ke = T({ defaultClassName: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwo", variantClassNames: { mini: { true: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwp", false: "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwq" } }, defaultVariants: { mini: !1 }, compoundVariants: [] }), Te = "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwr", De = "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jws", H = "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwt", J = "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwu", Oe = "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwv", Pe = "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jww", Le = "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwx", Me = "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwy", Ne = "pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwz";
|
|
165
|
+
function K({ list: o }) {
|
|
166
166
|
return /* @__PURE__ */ e.createElement(e.Fragment, null, o.map((i, l) => {
|
|
167
167
|
const t = Math.floor(i.length / 2);
|
|
168
|
-
return /* @__PURE__ */ e.createElement("div", { className: De, key: i }, /* @__PURE__ */ e.createElement("span", { className:
|
|
168
|
+
return /* @__PURE__ */ e.createElement("div", { className: De, key: i }, /* @__PURE__ */ e.createElement("span", { className: H }, i.substring(0, t)), /* @__PURE__ */ e.createElement("div", { className: H }, /* @__PURE__ */ e.createElement("span", null, i.substring(t))), l < o.length - 1 ? "," : "");
|
|
169
169
|
}));
|
|
170
170
|
}
|
|
171
|
-
function
|
|
171
|
+
function Y({
|
|
172
172
|
constrainContentWidth: o,
|
|
173
173
|
description: i,
|
|
174
174
|
multiple: l = !1,
|
|
175
175
|
dismissable: t,
|
|
176
176
|
processing: r,
|
|
177
177
|
mini: m,
|
|
178
|
-
downloadLabel:
|
|
178
|
+
downloadLabel: F,
|
|
179
179
|
acceptExtensions: p,
|
|
180
180
|
maxSize: s,
|
|
181
|
-
customRequirement:
|
|
182
|
-
onSelection:
|
|
183
|
-
onDismiss:
|
|
184
|
-
download:
|
|
185
|
-
shown:
|
|
186
|
-
className:
|
|
181
|
+
customRequirement: y,
|
|
182
|
+
onSelection: D,
|
|
183
|
+
onDismiss: L,
|
|
184
|
+
download: M,
|
|
185
|
+
shown: S,
|
|
186
|
+
className: Q,
|
|
187
187
|
disabled: d,
|
|
188
|
-
children:
|
|
189
|
-
...
|
|
188
|
+
children: Ve,
|
|
189
|
+
...ee
|
|
190
190
|
}) {
|
|
191
|
-
const U = e.useRef(/* @__PURE__ */ new Set()), [
|
|
191
|
+
const U = e.useRef(/* @__PURE__ */ new Set()), O = e.useRef(/* @__PURE__ */ new Set()), [oe, N] = e.useState(S), [Be, ae] = e.useState([]), [le, te] = e.useState(""), [A, ie] = e.useState(), [ne, C] = e.useState(!1), [E, j] = e.useState(!1), [h, V] = e.useState([]), [v, B] = e.useState([]), [x, se] = e.useState(""), R = e.useMemo(() => (/* @__PURE__ */ new Set([...h, ...v])).size, [h, v]), { t: c } = be(), k = (l ? c("fileUpload.instructions.other", {
|
|
192
192
|
defaultValue: "Drag and drop your files here or |browse for files| on your desktop."
|
|
193
193
|
}) : c("fileUpload.instructions.one", {
|
|
194
194
|
defaultValue: "Drag and drop your file here or |browse for a file| on your desktop."
|
|
195
|
-
})).split("|"),
|
|
195
|
+
})).split("|"), X = i || (l ? "Files" : "File"), f = e.useRef(null);
|
|
196
196
|
e.useEffect(() => {
|
|
197
|
-
|
|
198
|
-
}, [
|
|
199
|
-
s &&
|
|
197
|
+
S && N(S);
|
|
198
|
+
}, [S]), e.useEffect(() => {
|
|
199
|
+
s && pe(s);
|
|
200
200
|
}, [s]), e.useEffect(() => {
|
|
201
|
-
p &&
|
|
201
|
+
p && de(p);
|
|
202
202
|
}, [p]);
|
|
203
|
-
function
|
|
204
|
-
t && (
|
|
203
|
+
function re() {
|
|
204
|
+
t && (N(!1), L && L());
|
|
205
205
|
}
|
|
206
|
-
function
|
|
206
|
+
function pe(a) {
|
|
207
207
|
try {
|
|
208
|
-
|
|
208
|
+
ie(Fe(a));
|
|
209
209
|
} catch {
|
|
210
210
|
throw new Error(`Could not parse "${a}" as a file size.`);
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
|
-
function
|
|
213
|
+
function de(a) {
|
|
214
214
|
const w = (Array.isArray(a) ? a : a.trim().split(/\s?,\s?/)).map((n) => n.replace(/^\./, "")), u = w.map((n) => `.${n}`.toLowerCase());
|
|
215
|
-
|
|
216
|
-
u.map((n,
|
|
217
|
-
), U.current.clear();
|
|
215
|
+
se(
|
|
216
|
+
u.map((n, g) => g > 0 && g === u.length - 1 ? `or ${n}` : n).join(u.length > 2 ? ", " : " ")
|
|
217
|
+
), U.current.clear(), O.current.clear();
|
|
218
218
|
for (const n of w) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
219
|
+
O.current.add(n.toLowerCase());
|
|
220
|
+
const g = Object.keys(G).includes(n.toUpperCase()) ? G[n.toUpperCase()] : [];
|
|
221
|
+
for (const P of g)
|
|
222
|
+
U.current.add(P);
|
|
222
223
|
}
|
|
223
|
-
|
|
224
|
+
te(u.concat(Array.from(U.current)).join(","));
|
|
224
225
|
}
|
|
225
|
-
function
|
|
226
|
-
|
|
227
|
-
let
|
|
226
|
+
function I(a) {
|
|
227
|
+
V([]), B([]);
|
|
228
|
+
let b = [], w = [];
|
|
228
229
|
const u = a ? Array.from(a) : [];
|
|
229
|
-
for (const n of u)
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
a.preventDefault(), j(!1), f.current && f.current.click();
|
|
235
|
-
}
|
|
236
|
-
function de() {
|
|
237
|
-
P && P();
|
|
230
|
+
for (const n of u) {
|
|
231
|
+
const g = n.name.split(".").pop()?.toLowerCase() ?? "", P = n.type ? U.current.has(n.type) : O.current.has(g);
|
|
232
|
+
p && !P && w.push(n.name), s && A && n.size > A && b.push(n.name);
|
|
233
|
+
}
|
|
234
|
+
b.length || w.length ? (j(!0), f.current && f.current.value && (f.current.value = "")) : (ae(u), D(u)), V(b), B(w);
|
|
238
235
|
}
|
|
239
236
|
function ce(a) {
|
|
240
|
-
a.
|
|
237
|
+
a.preventDefault(), j(!1), f.current && f.current.click();
|
|
241
238
|
}
|
|
242
|
-
function _e(
|
|
243
|
-
|
|
239
|
+
function _e() {
|
|
240
|
+
M && M();
|
|
244
241
|
}
|
|
245
242
|
function fe(a) {
|
|
246
|
-
a.
|
|
243
|
+
a.stopPropagation(), I(a.target.files), f.current && f.current.value && (f.current.value = "");
|
|
247
244
|
}
|
|
248
245
|
function ue(a) {
|
|
249
|
-
a.preventDefault(),
|
|
246
|
+
a.preventDefault(), a.stopPropagation(), C(!0), j(!1);
|
|
250
247
|
}
|
|
251
248
|
function me(a) {
|
|
252
|
-
a.preventDefault(),
|
|
249
|
+
a.preventDefault(), C(!0), j(!1);
|
|
250
|
+
}
|
|
251
|
+
function he(a) {
|
|
252
|
+
a.preventDefault(), C(!1);
|
|
253
|
+
}
|
|
254
|
+
function ve(a) {
|
|
255
|
+
a.preventDefault(), a.stopPropagation(), C(!1), a.dataTransfer.files && I(a.dataTransfer.files);
|
|
253
256
|
}
|
|
254
257
|
return /* @__PURE__ */ e.createElement(
|
|
255
258
|
"div",
|
|
256
259
|
{
|
|
257
260
|
onDrop: d ? () => {
|
|
258
|
-
} :
|
|
261
|
+
} : ve,
|
|
259
262
|
onDragOver: d ? () => {
|
|
260
|
-
} : _e,
|
|
261
|
-
onDragLeave: d ? () => {
|
|
262
263
|
} : ue,
|
|
264
|
+
onDragLeave: d ? () => {
|
|
265
|
+
} : he,
|
|
263
266
|
onDragEnter: d ? () => {
|
|
264
|
-
} :
|
|
265
|
-
className:
|
|
266
|
-
...
|
|
267
|
+
} : me,
|
|
268
|
+
className: W(Ue({ active: ne, mini: m, error: E, shown: oe, disabled: d }), Q),
|
|
269
|
+
...ee
|
|
267
270
|
},
|
|
268
|
-
/* @__PURE__ */ e.createElement("div", { className:
|
|
271
|
+
/* @__PURE__ */ e.createElement("div", { className: W(Ce({ constrainContentWidth: o, disabled: d })) }, r ? /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(ge, { size: "md", "aria-hidden": "true" }), /* @__PURE__ */ e.createElement("div", { className: q }, c("fileUpload.processing", { defaultValue: "Processing Upload..." }))) : /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { className: je({ mini: m, error: E, disabled: d }), "aria-hidden": "true" }, /* @__PURE__ */ e.createElement(
|
|
269
272
|
"img",
|
|
270
273
|
{
|
|
271
|
-
className:
|
|
272
|
-
src:
|
|
274
|
+
className: Ne,
|
|
275
|
+
src: E ? Ee : xe,
|
|
273
276
|
alt: "Upload Icon"
|
|
274
277
|
}
|
|
275
|
-
)), /* @__PURE__ */ e.createElement("div", { className:
|
|
276
|
-
|
|
278
|
+
)), /* @__PURE__ */ e.createElement("div", { className: ke({ mini: m }) }, E ? /* @__PURE__ */ e.createElement("div", null, c(
|
|
279
|
+
R > 1 ? "fileUpload.cancelled.other" : "fileUpload.cancelled.one",
|
|
277
280
|
{
|
|
278
|
-
defaultValue:
|
|
281
|
+
defaultValue: R > 1 ? "File Upload(s) Failed" : "File Upload Failed"
|
|
279
282
|
}
|
|
280
283
|
)) : /* @__PURE__ */ e.createElement("div", null, c("fileUpload.title", {
|
|
281
|
-
description:
|
|
282
|
-
defaultValue: `Upload your ${
|
|
283
|
-
}))),
|
|
284
|
+
description: X,
|
|
285
|
+
defaultValue: `Upload your ${X}`
|
|
286
|
+
}))), E ? /* @__PURE__ */ e.createElement("div", { className: Te }, h.length > 0 && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(K, { list: h }), /* @__PURE__ */ e.createElement("div", { className: J }, c(
|
|
284
287
|
h.length === 1 ? "fileUpload.error.tooLarge.one" : "fileUpload.error.tooLarge.other",
|
|
285
288
|
{
|
|
286
289
|
size: s,
|
|
287
290
|
defaultValue: h.length === 1 ? `Selected file is larger than the size limit of ${s}.` : `Selected files are larger than the size limit of ${s}.`
|
|
288
291
|
}
|
|
289
|
-
))), v.length > 0 && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(
|
|
292
|
+
))), v.length > 0 && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(K, { list: v }), /* @__PURE__ */ e.createElement("div", { className: J }, c(
|
|
290
293
|
v.length === 1 ? "fileUpload.error.wrongType.one" : "fileUpload.error.wrongType.other",
|
|
291
294
|
{
|
|
292
|
-
fileTypes:
|
|
293
|
-
defaultValue: v.length === 1 ? `Selected file is not an accepted file type: ${
|
|
295
|
+
fileTypes: x,
|
|
296
|
+
defaultValue: v.length === 1 ? `Selected file is not an accepted file type: ${x}.` : `Selected files are not accepted file types: ${x}.`
|
|
294
297
|
}
|
|
295
|
-
)))) : /* @__PURE__ */ e.createElement("span", null), /* @__PURE__ */ e.createElement("div", { className:
|
|
296
|
-
fileTypes:
|
|
297
|
-
defaultValue: `${
|
|
298
|
+
)))) : /* @__PURE__ */ e.createElement("span", null), /* @__PURE__ */ e.createElement("div", { className: q }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("span", null, k[0]), d ? /* @__PURE__ */ e.createElement("u", null, k[1]) : /* @__PURE__ */ e.createElement("a", { href: "", onClick: ce }, k[1]), /* @__PURE__ */ e.createElement("span", null, k[2]))), /* @__PURE__ */ e.createElement("div", { className: Oe }, p ? /* @__PURE__ */ e.createElement("span", null, "(", " ", c("fileUpload.acceptedTypes", {
|
|
299
|
+
fileTypes: x,
|
|
300
|
+
defaultValue: `${x} format accepted`
|
|
298
301
|
}), " ", ")") : "", s ? /* @__PURE__ */ e.createElement("span", null, "(", " ", c("fileUpload.maximumSize", {
|
|
299
302
|
size: s,
|
|
300
303
|
defaultValue: `${s} maximum`
|
|
301
|
-
}), " ", ")") : "",
|
|
302
|
-
|
|
304
|
+
}), " ", ")") : "", y ? /* @__PURE__ */ e.createElement("span", null, " ", y, " ") : ""), F && /* @__PURE__ */ e.createElement("div", { className: Pe }, /* @__PURE__ */ e.createElement(
|
|
305
|
+
z,
|
|
303
306
|
{
|
|
304
307
|
disabled: d,
|
|
305
308
|
kind: "link",
|
|
306
309
|
icon: "download-cloud",
|
|
307
|
-
onClick:
|
|
310
|
+
onClick: _e
|
|
308
311
|
},
|
|
309
|
-
|
|
312
|
+
F
|
|
310
313
|
)))),
|
|
311
|
-
t && !r && /* @__PURE__ */ e.createElement("div", { className:
|
|
312
|
-
|
|
314
|
+
t && !r && /* @__PURE__ */ e.createElement("div", { className: Le }, /* @__PURE__ */ e.createElement(
|
|
315
|
+
z,
|
|
313
316
|
{
|
|
314
317
|
disabled: d,
|
|
315
318
|
kind: "icon",
|
|
316
319
|
icon: "x",
|
|
317
320
|
title: c("fileUpload.close", { defaultValue: "Close" }),
|
|
318
|
-
onClick:
|
|
321
|
+
onClick: re
|
|
319
322
|
}
|
|
320
323
|
)),
|
|
321
324
|
/* @__PURE__ */ e.createElement("form", { className: Me }, /* @__PURE__ */ e.createElement(
|
|
@@ -323,14 +326,14 @@ function J({
|
|
|
323
326
|
{
|
|
324
327
|
ref: f,
|
|
325
328
|
type: "file",
|
|
326
|
-
accept:
|
|
329
|
+
accept: le || "*/*",
|
|
327
330
|
multiple: l || void 0,
|
|
328
|
-
onChange:
|
|
331
|
+
onChange: fe
|
|
329
332
|
}
|
|
330
333
|
))
|
|
331
334
|
);
|
|
332
335
|
}
|
|
333
|
-
|
|
336
|
+
we.set(Y, {
|
|
334
337
|
name: "FileUpload",
|
|
335
338
|
props: {
|
|
336
339
|
constrainContentWidth: { type: "boolean" },
|
|
@@ -348,8 +351,8 @@ ve.set(J, {
|
|
|
348
351
|
disabled: { type: "boolean" }
|
|
349
352
|
}
|
|
350
353
|
});
|
|
351
|
-
const
|
|
352
|
-
components: [
|
|
354
|
+
const Ae = {
|
|
355
|
+
components: [Y],
|
|
353
356
|
examples: {
|
|
354
357
|
basic: {
|
|
355
358
|
label: "Basic File Upload",
|
|
@@ -602,10 +605,10 @@ const Ne = {
|
|
|
602
605
|
}
|
|
603
606
|
}
|
|
604
607
|
}
|
|
605
|
-
},
|
|
606
|
-
"File Upload":
|
|
608
|
+
}, Ge = {
|
|
609
|
+
"File Upload": Ae
|
|
607
610
|
};
|
|
608
611
|
export {
|
|
609
|
-
|
|
610
|
-
|
|
612
|
+
Y as FileUpload,
|
|
613
|
+
Ge as MANIFEST
|
|
611
614
|
};
|
package/lib/index.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(s,F){typeof exports=="object"&&typeof module<"u"?F(exports,require("react"),require("@sps-woodland/core"),require("@spscommerce/utils"),require("@sps-woodland/buttons"),require("@sps-woodland/illustrations"),require("@spscommerce/i18n")):typeof define=="function"&&define.amd?define(["exports","react","@sps-woodland/core","@spscommerce/utils","@sps-woodland/buttons","@sps-woodland/illustrations","@spscommerce/i18n"],F):(s=typeof globalThis<"u"?globalThis:s||self,F(s.FileUpload={},s.React,s.core,s.utils,s.buttons,s.illustrations,s.i18n))})(this,(function(s,F,S,d,L,A,ee){"use strict";function oe(o){const l=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const a in o)if(a!=="default"){const t=Object.getOwnPropertyDescriptor(o,a);Object.defineProperty(l,a,t.get?t:{enumerable:!0,get:()=>o[a]})}}return l.default=o,Object.freeze(l)}const e=oe(F),V={"7Z":["application/x-7z-compressed"],AAC:["audio/aac"],ABW:["application/x-abiword"],ARC:["application/octet-stream"],AVI:["video/x-msvideo"],AZW:["application/vnd.amazon.ebook"],BIN:["application/octet-stream"],BMP:["image/bmp"],BZ:["application/x-bzip"],BZ2:["application/x-bzip2"],CER:["application/pkix-cert","application/x-x509-ca-cert"],CSH:["application/x-csh"],CSS:["text/css"],CSV:["text/csv","application/vnd.ms-excel"],DOC:["application/msword"],DOT:["application/msword"],DOCX:["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],DOTX:["application/vnd.openxmlformats-officedocument.wordprocessingml.template"],DOCM:["application/vnd.ms-word.document.macroEnabled.12"],DOTM:["application/vnd.ms-word.template.macroEnabled.12"],EDI:["application/edi-x12","application/edifact"],EML:["application/octet-stream","message/rfc822","multipart/mixed","message/rfc5322","message/rfc6532"],EOT:["application/vnd.ms-fontobject"],EPUB:["application/epub+zip"],ES:["application/ecmascript"],FLV:["video/x-flv"],GIF:["image/gif"],GZ:["application/x-gzip"],HTM:["text/html"],HTML:["text/html"],ICO:["image/x-icon"],ICS:["text/calendar"],JAR:["application/java-archive"],JPEG:["image/jpeg"],JPG:["image/jpeg"],JS:["application/javascript"],JSON:["application/json"],M3U:["audio/x-mpequrl"],MID:["audio/midi"],MIDI:["audio/midi"],MOV:["video/quicktime"],MP3:["audio/mpeg3"],MP4:["video/mp4"],MPEG:["video/mpeg"],MPKG:["application/vnd.apple.installer+xml"],ODP:["application/vnd.oasis.opendocument.presentation"],ODS:["application/vnd.oasis.opendocument.spreadsheet"],ODT:["application/vnd.oasis.opendocument.text"],OGA:["audio/ogg"],OGV:["video/ogg"],OGX:["application/ogg"],OTF:["font/otf"],PNG:["image/png"],PDF:["application/pdf"],POT:["application/vnd.ms-powerpoint"],POTM:["application/vnd.ms-powerpoint.template.macroEnabled.12"],POTX:["application/vnd.openxmlformats-officedocument.presentationml.template"],PPA:["application/vnd.ms-powerpoint"],PPAM:["application/vnd.ms-powerpoint.addin.macroEnabled.12"],PPS:["application/vnd.ms-powerpoint"],PPSM:["application/vnd.ms-powerpoint.slideshow.macroEnabled.12"],PPT:["application/vnd.ms-powerpoint"],PPTM:["application/vnd.ms-powerpoint.presentation.macroEnabled.12"],PPSX:["application/vnd.openxmlformats-officedocument.presentationml.slideshow"],PPTX:["application/vnd.openxmlformats-officedocument.presentationml.presentation"],RAR:["application/x-rar-compressed"],RTF:["application/rtf"],SH:["application/x-sh"],SVG:["image/svg+xml"],SWF:["application/x-shockwave-flash"],TAR:["application/x-tar"],TIF:["image/tiff"],TIFF:["image/tiff"],TS:["application/typescript"],TTF:["font/ttf"],TXT:["text/plain"],VSD:["application/vnd.visio"],WAV:["audio/wav"],WEBA:["audio/webm"],WEBM:["video/webm"],WEBP:["image/webp"],WOFF:["font/woff"],WOFF2:["font/woff2"],XHTML:["application/xhtml+xml"],XLA:["application/vnd.ms-excel"],XLS:["application/vnd.ms-excel"],XLSB:["application/vnd.ms-excel.sheet.binary.macroEnabled.12"],XLT:["application/vnd.ms-excel"],XLAM:["application/vnd.ms-excel.addin.macroEnabled.12"],XLSM:["application/vnd.ms-excel.sheet.macroEnabled.12"],XLSX:["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],XLTM:["application/vnd.ms-excel.template.macroEnabled.12"],XLTX:["application/vnd.openxmlformats-officedocument.spreadsheetml.template"],XML:["application/xml"],XUL:["application/vnd.mozilla.xul+xml"],ZIP:["application/zip"]};function ae(o,l,a){return l in o?Object.defineProperty(o,l,{value:a,enumerable:!0,configurable:!0,writable:!0}):o[l]=a,o}function B(o,l){var a=Object.keys(o);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(o);l&&(t=t.filter(function(p){return Object.getOwnPropertyDescriptor(o,p).enumerable})),a.push.apply(a,t)}return a}function I(o){for(var l=1;l<arguments.length;l++){var a=arguments[l]!=null?arguments[l]:{};l%2?B(Object(a),!0).forEach(function(t){ae(o,t,a[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(a)):B(Object(a)).forEach(function(t){Object.defineProperty(o,t,Object.getOwnPropertyDescriptor(a,t))})}return o}var le=(o,l,a)=>{for(var t of Object.keys(o)){var p;if(o[t]!==((p=l[t])!==null&&p!==void 0?p:a[t]))return!1}return!0},U=o=>l=>{var a=o.defaultClassName,t=I(I({},o.defaultVariants),l);for(var p in t){var h,E=(h=t[p])!==null&&h!==void 0?h:o.defaultVariants[p];if(E!=null){var c=E;typeof c=="boolean"&&(c=c===!0?"true":"false");var r=o.variantClassNames[p][c];r&&(a+=" "+r)}}for(var[j,N]of o.compoundVariants)le(j,t,o.defaultVariants)&&(a+=" "+N);return a},te=U({defaultClassName:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jw0",variantClassNames:{active:{true:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jw1",false:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jw2"},mini:{true:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jw3",false:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jw4"},error:{true:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jw5",false:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jw6"},shown:{true:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jw7",false:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jw8"},disabled:{true:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jw9",false:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwa"}},defaultVariants:{active:!1,mini:!1,error:!1,shown:!0,disabled:!1},compoundVariants:[]}),ie=U({defaultClassName:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwb",variantClassNames:{constrainContentWidth:{true:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwc",false:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwd"},disabled:{true:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwe",false:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwf"}},defaultVariants:{constrainContentWidth:!1,disabled:!1},compoundVariants:[]}),R="pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwg",ne=U({defaultClassName:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwh",variantClassNames:{mini:{true:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwi",false:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwj"},error:{true:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwk",false:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwl"},disabled:{true:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwm",false:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwn"}},defaultVariants:{mini:!1,error:!1,disabled:!1},compoundVariants:[]}),se=U({defaultClassName:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwo",variantClassNames:{mini:{true:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwp",false:"pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwq"}},defaultVariants:{mini:!1},compoundVariants:[]}),re="pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwr",pe="pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jws",X="pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwt",W="pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwu",de="pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwv",ce="pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jww",fe="pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwx",_e="pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwy",ue="pkg_sps-woodland_file-upload__version_8_52_2__hash_rh07jwz";function z({list:o}){return e.createElement(e.Fragment,null,o.map((l,a)=>{const t=Math.floor(l.length/2);return e.createElement("div",{className:pe,key:l},e.createElement("span",{className:X},l.substring(0,t)),e.createElement("div",{className:X},e.createElement("span",null,l.substring(t))),a<o.length-1?",":"")}))}function M({constrainContentWidth:o,description:l,multiple:a=!1,dismissable:t,processing:p,mini:h,downloadLabel:E,acceptExtensions:c,maxSize:r,customRequirement:j,onSelection:N,onDismiss:G,download:q,shown:O,className:he,disabled:f,children:Ae,...ve}){const T=e.useRef(new Set),[we,Z]=e.useState(O),[Ve,ge]=e.useState([]),[Fe,Ee]=e.useState(""),[$,be]=e.useState(),[xe,C]=e.useState(!1),[b,k]=e.useState(!1),[v,H]=e.useState([]),[w,J]=e.useState([]),[x,ye]=e.useState(""),K=e.useMemo(()=>new Set([...v,...w]).size,[v,w]),{t:_}=ee.useWoodlandLanguage(),D=(a?_("fileUpload.instructions.other",{defaultValue:"Drag and drop your files here or |browse for files| on your desktop."}):_("fileUpload.instructions.one",{defaultValue:"Drag and drop your file here or |browse for a file| on your desktop."})).split("|"),Y=l||(a?"Files":"File"),u=e.useRef(null);e.useEffect(()=>{O&&Z(O)},[O]),e.useEffect(()=>{r&&Ue(r)},[r]),e.useEffect(()=>{c&&je(c)},[c]);function Se(){t&&(Z(!1),G&&G())}function Ue(i){try{be(d.parseFileSize(i))}catch{throw new Error(`Could not parse "${i}" as a file size.`)}}function je(i){const g=(Array.isArray(i)?i:i.trim().split(/\s?,\s?/)).map(n=>n.replace(/^\./,"")),m=g.map(n=>`.${n}`.toLowerCase());ye(m.map((n,P)=>P>0&&P===m.length-1?`or ${n}`:n).join(m.length>2?", ":" ")),T.current.clear();for(const n of g){const P=Object.keys(V).includes(n.toUpperCase())?V[n.toUpperCase()]:[];for(const Ne of P)T.current.add(Ne)}Ee(m.concat(Array.from(T.current)).join(","))}function Q(i){H([]),J([]);let y=[],g=[];const m=i?Array.from(i):[];for(const n of m)c&&!T.current.has(n.type)&&g.push(n.name),r&&$&&n.size>$&&y.push(n.name);y.length||g.length?(k(!0),u.current&&u.current.value&&(u.current.value="")):(ge(m),N(m)),H(y),J(g)}function Oe(i){i.preventDefault(),k(!1),u.current&&u.current.click()}function Te(){q&&q()}function Ce(i){i.stopPropagation(),Q(i.target.files),u.current&&u.current.value&&(u.current.value="")}function ke(i){i.preventDefault(),i.stopPropagation(),C(!0),k(!1)}function De(i){i.preventDefault(),C(!0),k(!1)}function Pe(i){i.preventDefault(),C(!1)}function Me(i){i.preventDefault(),i.stopPropagation(),C(!1),i.dataTransfer.files&&Q(i.dataTransfer.files)}return e.createElement("div",{onDrop:f?()=>{}:Me,onDragOver:f?()=>{}:ke,onDragLeave:f?()=>{}:Pe,onDragEnter:f?()=>{}:De,className:S.cl(te({active:xe,mini:h,error:b,shown:we,disabled:f}),he),...ve},e.createElement("div",{className:S.cl(ie({constrainContentWidth:o,disabled:f}))},p?e.createElement("div",null,e.createElement(S.Spinner,{size:"md","aria-hidden":"true"}),e.createElement("div",{className:R},_("fileUpload.processing",{defaultValue:"Processing Upload..."}))):e.createElement("div",null,e.createElement("div",{className:ne({mini:h,error:b,disabled:f}),"aria-hidden":"true"},e.createElement("img",{className:ue,src:b?A.GENERAL_ERROR_LARGE:A.UPLOAD_LARGE,alt:"Upload Icon"})),e.createElement("div",{className:se({mini:h})},b?e.createElement("div",null,_(K>1?"fileUpload.cancelled.other":"fileUpload.cancelled.one",{defaultValue:K>1?"File Upload(s) Failed":"File Upload Failed"})):e.createElement("div",null,_("fileUpload.title",{description:Y,defaultValue:`Upload your ${Y}`}))),b?e.createElement("div",{className:re},v.length>0&&e.createElement(e.Fragment,null,e.createElement(z,{list:v}),e.createElement("div",{className:W},_(v.length===1?"fileUpload.error.tooLarge.one":"fileUpload.error.tooLarge.other",{size:r,defaultValue:v.length===1?`Selected file is larger than the size limit of ${r}.`:`Selected files are larger than the size limit of ${r}.`}))),w.length>0&&e.createElement(e.Fragment,null,e.createElement(z,{list:w}),e.createElement("div",{className:W},_(w.length===1?"fileUpload.error.wrongType.one":"fileUpload.error.wrongType.other",{fileTypes:x,defaultValue:w.length===1?`Selected file is not an accepted file type: ${x}.`:`Selected files are not accepted file types: ${x}.`})))):e.createElement("span",null),e.createElement("div",{className:R},e.createElement("div",null,e.createElement("span",null,D[0]),f?e.createElement("u",null,D[1]):e.createElement("a",{href:"",onClick:Oe},D[1]),e.createElement("span",null,D[2]))),e.createElement("div",{className:de},c?e.createElement("span",null,"("," ",_("fileUpload.acceptedTypes",{fileTypes:x,defaultValue:`${x} format accepted`})," ",")"):"",r?e.createElement("span",null,"("," ",_("fileUpload.maximumSize",{size:r,defaultValue:`${r} maximum`})," ",")"):"",j?e.createElement("span",null," ",j," "):""),E&&e.createElement("div",{className:ce},e.createElement(L.Button,{disabled:f,kind:"link",icon:"download-cloud",onClick:Te},E)))),t&&!p&&e.createElement("div",{className:fe},e.createElement(L.Button,{disabled:f,kind:"icon",icon:"x",title:_("fileUpload.close",{defaultValue:"Close"}),onClick:Se})),e.createElement("form",{className:_e},e.createElement("input",{ref:u,type:"file",accept:Fe||"*/*",multiple:a||void 0,onChange:Ce})))}S.Metadata.set(M,{name:"FileUpload",props:{constrainContentWidth:{type:"boolean"},description:{type:"string"},multiple:{type:"boolean"},dismissable:{type:"boolean"},mini:{type:"boolean"},downloadLabel:{type:"string"},acceptExtensions:{type:"string[] | string"},maxSize:{type:"string"},customRequirement:{type:"string"},onSelection:{type:"(files: File[]) => void",required:!0},dismissal:{type:"() => void"},download:{type:"() => void"},disabled:{type:"boolean"}}});const me={"File Upload":{components:[M],examples:{basic:{label:"Basic File Upload",description:"Simply allow the user to drag-and-drop or select a single file or multiple files at once.",examples:{basic:{description:"Single file upload",react:d.code`
|
|
1
|
+
(function(s,E){typeof exports=="object"&&typeof module<"u"?E(exports,require("react"),require("@sps-woodland/core"),require("@spscommerce/utils"),require("@sps-woodland/buttons"),require("@sps-woodland/illustrations"),require("@spscommerce/i18n")):typeof define=="function"&&define.amd?define(["exports","react","@sps-woodland/core","@spscommerce/utils","@sps-woodland/buttons","@sps-woodland/illustrations","@spscommerce/i18n"],E):(s=typeof globalThis<"u"?globalThis:s||self,E(s.FileUpload={},s.React,s.core,s.utils,s.buttons,s.illustrations,s.i18n))})(this,(function(s,E,U,d,V,B,ae){"use strict";function le(o){const l=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const a in o)if(a!=="default"){const t=Object.getOwnPropertyDescriptor(o,a);Object.defineProperty(l,a,t.get?t:{enumerable:!0,get:()=>o[a]})}}return l.default=o,Object.freeze(l)}const e=le(E),R={"7Z":["application/x-7z-compressed"],AAC:["audio/aac"],ABW:["application/x-abiword"],ARC:["application/octet-stream"],AVI:["video/x-msvideo"],AZW:["application/vnd.amazon.ebook"],BIN:["application/octet-stream"],BMP:["image/bmp"],BZ:["application/x-bzip"],BZ2:["application/x-bzip2"],CER:["application/pkix-cert","application/x-x509-ca-cert"],CSH:["application/x-csh"],CSS:["text/css"],CSV:["text/csv","application/vnd.ms-excel"],DOC:["application/msword"],DOT:["application/msword"],DOCX:["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],DOTX:["application/vnd.openxmlformats-officedocument.wordprocessingml.template"],DOCM:["application/vnd.ms-word.document.macroEnabled.12"],DOTM:["application/vnd.ms-word.template.macroEnabled.12"],EDI:["application/edi-x12","application/edifact"],EML:["application/octet-stream","message/rfc822","multipart/mixed","message/rfc5322","message/rfc6532"],EOT:["application/vnd.ms-fontobject"],EPUB:["application/epub+zip"],ES:["application/ecmascript"],FLV:["video/x-flv"],GIF:["image/gif"],GZ:["application/x-gzip"],HTM:["text/html"],HTML:["text/html"],ICO:["image/x-icon"],ICS:["text/calendar"],JAR:["application/java-archive"],JPEG:["image/jpeg"],JPG:["image/jpeg"],JS:["application/javascript"],JSON:["application/json"],M3U:["audio/x-mpequrl"],MID:["audio/midi"],MIDI:["audio/midi"],MOV:["video/quicktime"],MP3:["audio/mpeg3"],MP4:["video/mp4"],MPEG:["video/mpeg"],MPKG:["application/vnd.apple.installer+xml"],ODP:["application/vnd.oasis.opendocument.presentation"],ODS:["application/vnd.oasis.opendocument.spreadsheet"],ODT:["application/vnd.oasis.opendocument.text"],OGA:["audio/ogg"],OGV:["video/ogg"],OGX:["application/ogg"],OTF:["font/otf"],PNG:["image/png"],PDF:["application/pdf"],POT:["application/vnd.ms-powerpoint"],POTM:["application/vnd.ms-powerpoint.template.macroEnabled.12"],POTX:["application/vnd.openxmlformats-officedocument.presentationml.template"],PPA:["application/vnd.ms-powerpoint"],PPAM:["application/vnd.ms-powerpoint.addin.macroEnabled.12"],PPS:["application/vnd.ms-powerpoint"],PPSM:["application/vnd.ms-powerpoint.slideshow.macroEnabled.12"],PPT:["application/vnd.ms-powerpoint"],PPTM:["application/vnd.ms-powerpoint.presentation.macroEnabled.12"],PPSX:["application/vnd.openxmlformats-officedocument.presentationml.slideshow"],PPTX:["application/vnd.openxmlformats-officedocument.presentationml.presentation"],RAR:["application/x-rar-compressed"],RTF:["application/rtf"],SH:["application/x-sh"],SVG:["image/svg+xml"],SWF:["application/x-shockwave-flash"],TAR:["application/x-tar"],TIF:["image/tiff"],TIFF:["image/tiff"],TS:["application/typescript"],TTF:["font/ttf"],TXT:["text/plain"],VSD:["application/vnd.visio"],WAV:["audio/wav"],WEBA:["audio/webm"],WEBM:["video/webm"],WEBP:["image/webp"],WOFF:["font/woff"],WOFF2:["font/woff2"],XHTML:["application/xhtml+xml"],XLA:["application/vnd.ms-excel"],XLS:["application/vnd.ms-excel"],XLSB:["application/vnd.ms-excel.sheet.binary.macroEnabled.12"],XLT:["application/vnd.ms-excel"],XLAM:["application/vnd.ms-excel.addin.macroEnabled.12"],XLSM:["application/vnd.ms-excel.sheet.macroEnabled.12"],XLSX:["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],XLTM:["application/vnd.ms-excel.template.macroEnabled.12"],XLTX:["application/vnd.openxmlformats-officedocument.spreadsheetml.template"],XML:["application/xml"],XUL:["application/vnd.mozilla.xul+xml"],ZIP:["application/zip"]};function te(o,l,a){return l in o?Object.defineProperty(o,l,{value:a,enumerable:!0,configurable:!0,writable:!0}):o[l]=a,o}function I(o,l){var a=Object.keys(o);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(o);l&&(t=t.filter(function(p){return Object.getOwnPropertyDescriptor(o,p).enumerable})),a.push.apply(a,t)}return a}function X(o){for(var l=1;l<arguments.length;l++){var a=arguments[l]!=null?arguments[l]:{};l%2?I(Object(a),!0).forEach(function(t){te(o,t,a[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(a)):I(Object(a)).forEach(function(t){Object.defineProperty(o,t,Object.getOwnPropertyDescriptor(a,t))})}return o}var ie=(o,l,a)=>{for(var t of Object.keys(o)){var p;if(o[t]!==((p=l[t])!==null&&p!==void 0?p:a[t]))return!1}return!0},j=o=>l=>{var a=o.defaultClassName,t=X(X({},o.defaultVariants),l);for(var p in t){var h,b=(h=t[p])!==null&&h!==void 0?h:o.defaultVariants[p];if(b!=null){var c=b;typeof c=="boolean"&&(c=c===!0?"true":"false");var r=o.variantClassNames[p][c];r&&(a+=" "+r)}}for(var[C,L]of o.compoundVariants)ie(C,t,o.defaultVariants)&&(a+=" "+L);return a},ne=j({defaultClassName:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw0",variantClassNames:{active:{true:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw1",false:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw2"},mini:{true:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw3",false:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw4"},error:{true:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw5",false:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw6"},shown:{true:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw7",false:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw8"},disabled:{true:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw9",false:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwa"}},defaultVariants:{active:!1,mini:!1,error:!1,shown:!0,disabled:!1},compoundVariants:[]}),se=j({defaultClassName:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwb",variantClassNames:{constrainContentWidth:{true:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwc",false:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwd"},disabled:{true:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwe",false:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwf"}},defaultVariants:{constrainContentWidth:!1,disabled:!1},compoundVariants:[]}),W="pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwg",re=j({defaultClassName:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwh",variantClassNames:{mini:{true:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwi",false:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwj"},error:{true:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwk",false:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwl"},disabled:{true:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwm",false:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwn"}},defaultVariants:{mini:!1,error:!1,disabled:!1},compoundVariants:[]}),pe=j({defaultClassName:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwo",variantClassNames:{mini:{true:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwp",false:"pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwq"}},defaultVariants:{mini:!1},compoundVariants:[]}),de="pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwr",ce="pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jws",z="pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwt",G="pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwu",fe="pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwv",_e="pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jww",ue="pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwx",me="pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwy",he="pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwz";function q({list:o}){return e.createElement(e.Fragment,null,o.map((l,a)=>{const t=Math.floor(l.length/2);return e.createElement("div",{className:ce,key:l},e.createElement("span",{className:z},l.substring(0,t)),e.createElement("div",{className:z},e.createElement("span",null,l.substring(t))),a<o.length-1?",":"")}))}function M({constrainContentWidth:o,description:l,multiple:a=!1,dismissable:t,processing:p,mini:h,downloadLabel:b,acceptExtensions:c,maxSize:r,customRequirement:C,onSelection:L,onDismiss:Z,download:$,shown:O,className:we,disabled:f,children:Ve,...ge}){const T=e.useRef(new Set),N=e.useRef(new Set),[Fe,H]=e.useState(O),[Be,Ee]=e.useState([]),[be,xe]=e.useState(""),[J,ye]=e.useState(),[Se,k]=e.useState(!1),[x,D]=e.useState(!1),[v,K]=e.useState([]),[w,Y]=e.useState([]),[y,Ue]=e.useState(""),Q=e.useMemo(()=>new Set([...v,...w]).size,[v,w]),{t:_}=ae.useWoodlandLanguage(),P=(a?_("fileUpload.instructions.other",{defaultValue:"Drag and drop your files here or |browse for files| on your desktop."}):_("fileUpload.instructions.one",{defaultValue:"Drag and drop your file here or |browse for a file| on your desktop."})).split("|"),ee=l||(a?"Files":"File"),u=e.useRef(null);e.useEffect(()=>{O&&H(O)},[O]),e.useEffect(()=>{r&&Ce(r)},[r]),e.useEffect(()=>{c&&Oe(c)},[c]);function je(){t&&(H(!1),Z&&Z())}function Ce(i){try{ye(d.parseFileSize(i))}catch{throw new Error(`Could not parse "${i}" as a file size.`)}}function Oe(i){const g=(Array.isArray(i)?i:i.trim().split(/\s?,\s?/)).map(n=>n.replace(/^\./,"")),m=g.map(n=>`.${n}`.toLowerCase());Ue(m.map((n,F)=>F>0&&F===m.length-1?`or ${n}`:n).join(m.length>2?", ":" ")),T.current.clear(),N.current.clear();for(const n of g){N.current.add(n.toLowerCase());const F=Object.keys(R).includes(n.toUpperCase())?R[n.toUpperCase()]:[];for(const A of F)T.current.add(A)}xe(m.concat(Array.from(T.current)).join(","))}function oe(i){K([]),Y([]);let S=[],g=[];const m=i?Array.from(i):[];for(const n of m){const F=n.name.split(".").pop()?.toLowerCase()??"",A=n.type?T.current.has(n.type):N.current.has(F);c&&!A&&g.push(n.name),r&&J&&n.size>J&&S.push(n.name)}S.length||g.length?(D(!0),u.current&&u.current.value&&(u.current.value="")):(Ee(m),L(m)),K(S),Y(g)}function Te(i){i.preventDefault(),D(!1),u.current&&u.current.click()}function ke(){$&&$()}function De(i){i.stopPropagation(),oe(i.target.files),u.current&&u.current.value&&(u.current.value="")}function Pe(i){i.preventDefault(),i.stopPropagation(),k(!0),D(!1)}function Me(i){i.preventDefault(),k(!0),D(!1)}function Le(i){i.preventDefault(),k(!1)}function Ne(i){i.preventDefault(),i.stopPropagation(),k(!1),i.dataTransfer.files&&oe(i.dataTransfer.files)}return e.createElement("div",{onDrop:f?()=>{}:Ne,onDragOver:f?()=>{}:Pe,onDragLeave:f?()=>{}:Le,onDragEnter:f?()=>{}:Me,className:U.cl(ne({active:Se,mini:h,error:x,shown:Fe,disabled:f}),we),...ge},e.createElement("div",{className:U.cl(se({constrainContentWidth:o,disabled:f}))},p?e.createElement("div",null,e.createElement(U.Spinner,{size:"md","aria-hidden":"true"}),e.createElement("div",{className:W},_("fileUpload.processing",{defaultValue:"Processing Upload..."}))):e.createElement("div",null,e.createElement("div",{className:re({mini:h,error:x,disabled:f}),"aria-hidden":"true"},e.createElement("img",{className:he,src:x?B.GENERAL_ERROR_LARGE:B.UPLOAD_LARGE,alt:"Upload Icon"})),e.createElement("div",{className:pe({mini:h})},x?e.createElement("div",null,_(Q>1?"fileUpload.cancelled.other":"fileUpload.cancelled.one",{defaultValue:Q>1?"File Upload(s) Failed":"File Upload Failed"})):e.createElement("div",null,_("fileUpload.title",{description:ee,defaultValue:`Upload your ${ee}`}))),x?e.createElement("div",{className:de},v.length>0&&e.createElement(e.Fragment,null,e.createElement(q,{list:v}),e.createElement("div",{className:G},_(v.length===1?"fileUpload.error.tooLarge.one":"fileUpload.error.tooLarge.other",{size:r,defaultValue:v.length===1?`Selected file is larger than the size limit of ${r}.`:`Selected files are larger than the size limit of ${r}.`}))),w.length>0&&e.createElement(e.Fragment,null,e.createElement(q,{list:w}),e.createElement("div",{className:G},_(w.length===1?"fileUpload.error.wrongType.one":"fileUpload.error.wrongType.other",{fileTypes:y,defaultValue:w.length===1?`Selected file is not an accepted file type: ${y}.`:`Selected files are not accepted file types: ${y}.`})))):e.createElement("span",null),e.createElement("div",{className:W},e.createElement("div",null,e.createElement("span",null,P[0]),f?e.createElement("u",null,P[1]):e.createElement("a",{href:"",onClick:Te},P[1]),e.createElement("span",null,P[2]))),e.createElement("div",{className:fe},c?e.createElement("span",null,"("," ",_("fileUpload.acceptedTypes",{fileTypes:y,defaultValue:`${y} format accepted`})," ",")"):"",r?e.createElement("span",null,"("," ",_("fileUpload.maximumSize",{size:r,defaultValue:`${r} maximum`})," ",")"):"",C?e.createElement("span",null," ",C," "):""),b&&e.createElement("div",{className:_e},e.createElement(V.Button,{disabled:f,kind:"link",icon:"download-cloud",onClick:ke},b)))),t&&!p&&e.createElement("div",{className:ue},e.createElement(V.Button,{disabled:f,kind:"icon",icon:"x",title:_("fileUpload.close",{defaultValue:"Close"}),onClick:je})),e.createElement("form",{className:me},e.createElement("input",{ref:u,type:"file",accept:be||"*/*",multiple:a||void 0,onChange:De})))}U.Metadata.set(M,{name:"FileUpload",props:{constrainContentWidth:{type:"boolean"},description:{type:"string"},multiple:{type:"boolean"},dismissable:{type:"boolean"},mini:{type:"boolean"},downloadLabel:{type:"string"},acceptExtensions:{type:"string[] | string"},maxSize:{type:"string"},customRequirement:{type:"string"},onSelection:{type:"(files: File[]) => void",required:!0},dismissal:{type:"() => void"},download:{type:"() => void"},disabled:{type:"boolean"}}});const ve={"File Upload":{components:[M],examples:{basic:{label:"Basic File Upload",description:"Simply allow the user to drag-and-drop or select a single file or multiple files at once.",examples:{basic:{description:"Single file upload",react:d.code`
|
|
2
2
|
import { FileUpload } from "@sps-woodland/file-upload";
|
|
3
3
|
|
|
4
4
|
function Component() {
|
|
@@ -170,4 +170,4 @@
|
|
|
170
170
|
onSelection={selectFile} />
|
|
171
171
|
)
|
|
172
172
|
}
|
|
173
|
-
`}}}}}};s.FileUpload=M,s.MANIFEST=
|
|
173
|
+
`}}}}}};s.FileUpload=M,s.MANIFEST=ve,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|
package/lib/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.pkg_sps-woodland_file-
|
|
1
|
+
.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw0{border-width:.0625rem;border-style:dashed;border-radius:.25rem;display:block;padding:1rem;position:relative}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw1{background-color:#f4ecf2;border-color:#91467f;border-style:solid}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw3{padding:1rem}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw5{border-color:#de002e}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw8{display:none}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jw9{border-color:#d2d4d4}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwb{color:#4b5356;margin:0 auto;text-align:center}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwc{width:50%}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwe{color:#717779}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwg{font-size:.75rem;line-height:1.25rem}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwh{color:#717779;display:block;margin-bottom:1rem}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwi{font-size:1.5rem;line-height:1.5rem}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwj{font-size:3rem;line-height:3rem}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwk{color:#de002e}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwm{opacity:.5}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwo{font-weight:600;margin-bottom:.25rem}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwp{font-size:1rem;line-height:1.25rem}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwq{font-size:1.125rem;line-height:1.25rem}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwr{font-size:.875rem;font-weight:600;line-height:1.25rem}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jws{display:flex;justify-content:center;white-space:nowrap}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwt{max-width:50%;overflow:hidden}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwt:first-child{text-overflow:ellipsis}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwt:last-child{float:right}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwu{font-weight:400}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwv{font-size:.75rem;line-height:1.125rem;margin-top:.25rem}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwv>span+span{margin-left:.125rem}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jww{margin-top:1rem}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwx{position:absolute;right:.5rem;top:.5rem}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwy{display:none}.pkg_sps-woodland_file-upload__version_8_53_1__hash_rh07jwz{height:3rem}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sps-woodland/file-upload",
|
|
3
3
|
"description": "SPS Woodland Design System file upload component",
|
|
4
|
-
"version": "8.
|
|
4
|
+
"version": "8.53.1",
|
|
5
5
|
"author": "SPS Commerce",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"repository": "https://github.com/SPSCommerce/woodland/tree/main/packages/@sps-woodland/file-upload",
|
|
@@ -30,29 +30,31 @@
|
|
|
30
30
|
"@spscommerce/utils": "^7.0.0 || ^8.0.0 || ^9.0.0",
|
|
31
31
|
"react": "^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
32
32
|
"react-dom": "^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
33
|
-
"@sps-woodland/buttons": "8.
|
|
34
|
-
"@sps-woodland/core": "8.
|
|
35
|
-
"@sps-woodland/illustrations": "8.
|
|
36
|
-
"@sps-woodland/tokens": "8.
|
|
37
|
-
"@spscommerce/ds-react": "8.
|
|
38
|
-
"@spscommerce/ds-shared": "8.
|
|
39
|
-
"@spscommerce/i18n": "8.
|
|
33
|
+
"@sps-woodland/buttons": "8.53.1",
|
|
34
|
+
"@sps-woodland/core": "8.53.1",
|
|
35
|
+
"@sps-woodland/illustrations": "8.53.1",
|
|
36
|
+
"@sps-woodland/tokens": "8.53.1",
|
|
37
|
+
"@spscommerce/ds-react": "8.53.1",
|
|
38
|
+
"@spscommerce/ds-shared": "8.53.1",
|
|
39
|
+
"@spscommerce/i18n": "8.53.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@spscommerce/ds-illustrations": "6.12.1",
|
|
43
43
|
"@spscommerce/utils": "9.0.3",
|
|
44
|
+
"@testing-library/jest-dom": "^5.16.5",
|
|
45
|
+
"@testing-library/react": "12.1.5",
|
|
44
46
|
"@vanilla-extract/css": "1.17.4",
|
|
45
47
|
"@vanilla-extract/recipes": "0.2.5",
|
|
46
48
|
"react": "16.14.0",
|
|
47
49
|
"react-dom": "16.14.0",
|
|
48
|
-
"@sps-woodland/buttons": "8.
|
|
49
|
-
"@sps-woodland/core": "8.
|
|
50
|
-
"@sps-woodland/illustrations": "8.
|
|
51
|
-
"@sps-woodland/tokens": "8.
|
|
52
|
-
"@spscommerce/ds-colors": "8.
|
|
53
|
-
"@spscommerce/ds-react": "8.
|
|
54
|
-
"@spscommerce/ds-shared": "8.
|
|
55
|
-
"@spscommerce/i18n": "8.
|
|
50
|
+
"@sps-woodland/buttons": "8.53.1",
|
|
51
|
+
"@sps-woodland/core": "8.53.1",
|
|
52
|
+
"@sps-woodland/illustrations": "8.53.1",
|
|
53
|
+
"@sps-woodland/tokens": "8.53.1",
|
|
54
|
+
"@spscommerce/ds-colors": "8.53.1",
|
|
55
|
+
"@spscommerce/ds-react": "8.53.1",
|
|
56
|
+
"@spscommerce/ds-shared": "8.53.1",
|
|
57
|
+
"@spscommerce/i18n": "8.53.1"
|
|
56
58
|
},
|
|
57
59
|
"scripts": {
|
|
58
60
|
"build": "pnpm run build:js && pnpm run build:types",
|