@sps-woodland/file-upload 7.17.9 → 8.0.0
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.cjs.js +5 -4
- package/lib/index.es.js +91 -91
- package/package.json +14 -13
package/lib/index.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const de=require("react"),w=require("@sps-woodland/core"),p=require("@spscommerce/utils"),V=require("@sps-woodland/buttons");function ue(t){if(t&&t.__esModule)return t;const l=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const o=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(l,a,o.get?o:{enumerable:!0,get:()=>t[a]})}}return l.default=t,Object.freeze(l)}const e=ue(de),z={"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"],DOCX:["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],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"],PPT:["application/vnd.ms-powerpoint"],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"],XLS:["application/vnd.ms-excel"],XLSX:["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],XML:["application/xml"],XUL:["application/vnd.mozilla.xul+xml"],ZIP:["application/zip"]};function fe(t,l,a){return l in t?Object.defineProperty(t,l,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[l]=a,t}function R(t,l){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);l&&(o=o.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),a.push.apply(a,o)}return a}function W(t){for(var l=1;l<arguments.length;l++){var a=arguments[l]!=null?arguments[l]:{};l%2?R(Object(a),!0).forEach(function(o){fe(t,o,a[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):R(Object(a)).forEach(function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(a,o))})}return t}var me=(t,l,a)=>{for(var o of Object.keys(t)){var n;if(t[o]!==((n=l[o])!==null&&n!==void 0?n:a[o]))return!1}return!0},j=t=>l=>{var a=t.defaultClassName,o=W(W({},t.defaultVariants),l);for(var n in o){var v,g=(v=o[n])!==null&&v!==void 0?v:t.defaultVariants[n];if(g!=null){var c=g;typeof c=="boolean"&&(c=c===!0?"true":"false");var d=t.variantClassNames[n][c];d&&(a+=" "+d)}}for(var[x,C]of t.compoundVariants)me(x,o,t.defaultVariants)&&(a+=" "+C);return a},he="rh07jwm",k="rh07jwn",ve="rh07jwl",we=j({defaultClassName:"rh07jw0",variantClassNames:{active:{true:"rh07jw1",false:"rh07jw2"},mini:{true:"rh07jw3",false:"rh07jw4"},error:{true:"rh07jw5",false:"rh07jw6"},shown:{true:"rh07jw7",false:"rh07jw8"}},defaultVariants:{active:!1,mini:!1,error:!1,shown:!0},compoundVariants:[]}),ge="rh07jwq",Fe=j({defaultClassName:"rh07jw9",variantClassNames:{constrainContentWidth:{true:"rh07jwa",false:"rh07jwb"}},defaultVariants:{constrainContentWidth:!1},compoundVariants:[]}),xe="rh07jwp",be="rh07jwr",ye=j({defaultClassName:"rh07jwd",variantClassNames:{mini:{true:"rh07jwe",false:"rh07jwf"},error:{true:"rh07jwg",false:"rh07jwh"}},defaultVariants:{mini:!1,error:!1},compoundVariants:[]}),L="rh07jwc",Se="rh07jwo",Ee=j({defaultClassName:"rh07jwi",variantClassNames:{mini:{true:"rh07jwj",false:"rh07jwk"}},defaultVariants:{mini:!1},compoundVariants:[]});function N({constrainContentWidth:t,description:l,multiple:a=!1,dismissable:o,processing:n,mini:v,downloadLabel:g,acceptExtensions:c,maxSize:d,customRequirement:x,onSelection:C,onDismiss:P,download:M,shown:b,className:X,children:Ce,...G}){const y=e.useRef(new Set),[_,A]=e.useState(b),[Oe,q]=e.useState([]),[Z,H]=e.useState(""),[B,J]=e.useState(),[K,S]=e.useState(!1),[F,E]=e.useState(!1),[O,I]=e.useState([]),[Y,Q]=e.useState(""),{t:h}=e.useContext(w.I18nContext),D=h(a?"design-system:fileUpload.instructions_plural":"design-system:fileUpload.instructions").split("|"),$=l||(a?"Files":"File"),u=e.useRef(null);e.useEffect(()=>{b&&A(b)},[b]),e.useEffect(()=>{d&&te(d)},[d]),e.useEffect(()=>{c&&ie(c)},[c]);function ee(){o&&(A(!1),P&&P())}function te(i){try{J(p.parseFileSize(i))}catch{throw new Error(`Could not parse "${i}" as a file size.`)}}function ie(i){const f=(Array.isArray(i)?i:i.trim().split(/\s?,\s?/)).map(m=>m.replace(/^\./,"")),r=f.map(m=>`.${m}`.toLowerCase());Q(r.map((m,U)=>U>0&&U===r.length-1?`or ${m}`:m).join(r.length>2?", ":" ")),y.current.clear();for(const m of f){const U=Object.keys(z).includes(m.toUpperCase())?z[m.toUpperCase()]:[];for(const pe of U)y.current.add(pe)}H(r.concat(Array.from(y.current)).join(","))}function T(i){I([]);let s=[];const f=Array.from(i);for(const r of f)r===null?s.push("Not a file"):(c&&!y.current.has(r.type)&&s.push(r.name),d&&B&&r.size>B&&s.indexOf(r.name)===-1&&s.push(r.name));s.length?(E(!0),u.current&&u.current.value&&(u.current.value="")):(q(f),C(f)),I(s)}function ae(i){i.preventDefault(),E(!1),u.current&&u.current.click()}function oe(){M&&M()}function le(i){i.stopPropagation(),T(i.target.files||[]),u.current&&u.current.value&&(u.current.value="")}function ne(i){i.preventDefault(),i.stopPropagation(),S(!0),E(!1)}function se(i){i.preventDefault(),S(!0),E(!1)}function re(i){i.preventDefault(),S(!1)}function ce(i){i.preventDefault(),i.stopPropagation(),S(!1),i.dataTransfer.items?T(Array.from(i.dataTransfer.items).map(s=>s.getAsFile())):T(i.dataTransfer.files)}return e.createElement("div",{onDrop:ce,onDragOver:ne,onDragLeave:re,onDragEnter:se,className:w.cl(we({active:K,mini:v,error:F,shown:_}),X),...G},e.createElement("div",{className:w.cl(Fe({constrainContentWidth:t}))},n?e.createElement("div",null,e.createElement(w.Spinner,{size:"md","aria-hidden":"true"}),e.createElement("div",{className:L},h("design-system:fileUpload.processing"))):e.createElement("div",null,e.createElement(w.Icon,{className:ye({mini:v,error:F}),icon:F?"exclamation-circle":"upload-cloud","aria-hidden":"true"}),e.createElement("div",{className:Ee({mini:v})},F?e.createElement("div",null,h(O.length>1?"design-system:fileUpload.cancelled_plural":"design-system:fileUpload.cancelled")):e.createElement("div",null,h("design-system:fileUpload.title",{description:$}))),F?e.createElement("div",{className:ve},new Set(O.map((i,s)=>{const f=Math.floor(i.length/2);return e.createElement("div",{className:he,key:i},e.createElement("span",{className:k},i.substr(0,f)),e.createElement("div",{className:k},e.createElement("span",null,i.substr(f))),s<O.length-1?",":"")}))):e.createElement("span",null),e.createElement("div",{className:L},e.createElement("div",null,e.createElement("span",null,D[0]),e.createElement("a",{href:"",onClick:ae},D[1]),e.createElement("span",null,D[2]))),e.createElement("div",{className:Se},c?e.createElement("span",null,"("," ",h("design-system:fileUpload.acceptedTypes",{fileTypes:Y})," ",")"):"",d?e.createElement("span",null,"( ",h("design-system:fileUpload.maximumSize",{size:d})," )"):"",x?e.createElement("span",null," ",x," "):""),g&&e.createElement("div",{className:xe},e.createElement(V.Button,{kind:"link",icon:"download-cloud",onClick:oe},g)))),o&&!n&&e.createElement("div",{className:ge},e.createElement(V.Button,{kind:"icon",icon:"x",title:h("design-system:fileUpload.close"),onClick:ee})),e.createElement("form",{className:be},e.createElement("input",{ref:u,type:"file",accept:Z||"*/*",multiple:a||void 0,onChange:le})))}w.Metadata.set(N,{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"}}});const Ue={components:[N],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:p.code`
|
|
2
2
|
import { FileUpload } from "@sps-woodland/file-upload";
|
|
3
3
|
|
|
4
4
|
function Component() {
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
}
|
|
72
72
|
`}}},dismissable:{label:"Dismissable",description:"With this option, the file upload component can be dismissed by the user. If the user does dismiss it, you can show it again programmatically if you need to.",examples:{basic:{react:p.code`
|
|
73
73
|
import { FileUpload } from "@sps-woodland/file-upload";
|
|
74
|
+
import { Button } from "@sps-woodland/buttons";
|
|
74
75
|
|
|
75
76
|
function Component() {
|
|
76
77
|
const [showFileUpload, setShowFileUpload] = React.useState(true);
|
|
@@ -91,9 +92,9 @@
|
|
|
91
92
|
shown={showFileUpload}
|
|
92
93
|
/>
|
|
93
94
|
{!showFileUpload && (
|
|
94
|
-
<
|
|
95
|
+
<Button onClick={() => setShowFileUpload(true)}>
|
|
95
96
|
Reset
|
|
96
|
-
</
|
|
97
|
+
</Button>
|
|
97
98
|
)}
|
|
98
99
|
</>
|
|
99
100
|
)
|
|
@@ -152,4 +153,4 @@
|
|
|
152
153
|
</div>
|
|
153
154
|
)
|
|
154
155
|
}
|
|
155
|
-
`}}}}},je={"File Upload":
|
|
156
|
+
`}}}}},je={"File Upload":Ue};exports.FileUpload=N;exports.MANIFEST=je;
|
package/lib/index.es.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as e from "react";
|
|
2
|
-
import { Metadata as
|
|
3
|
-
import { parseFileSize as
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
const L = {
|
|
2
|
+
import { Metadata as de, I18nContext as fe, cl as B, Spinner as ue, Icon as me } from "@sps-woodland/core";
|
|
3
|
+
import { parseFileSize as he, code as m } from "@spscommerce/utils";
|
|
4
|
+
import { Button as I } from "@sps-woodland/buttons";
|
|
5
|
+
const V = {
|
|
7
6
|
"7Z": ["application/x-7z-compressed"],
|
|
8
7
|
AAC: ["audio/aac"],
|
|
9
8
|
ABW: ["application/x-abiword"],
|
|
@@ -79,7 +78,7 @@ const L = {
|
|
|
79
78
|
XUL: ["application/vnd.mozilla.xul+xml"],
|
|
80
79
|
ZIP: ["application/zip"]
|
|
81
80
|
};
|
|
82
|
-
function
|
|
81
|
+
function ve(i, o, a) {
|
|
83
82
|
return o in i ? Object.defineProperty(i, o, {
|
|
84
83
|
value: a,
|
|
85
84
|
enumerable: !0,
|
|
@@ -87,7 +86,7 @@ function ge(i, o, a) {
|
|
|
87
86
|
writable: !0
|
|
88
87
|
}) : i[o] = a, i;
|
|
89
88
|
}
|
|
90
|
-
function
|
|
89
|
+
function W(i, o) {
|
|
91
90
|
var a = Object.keys(i);
|
|
92
91
|
if (Object.getOwnPropertySymbols) {
|
|
93
92
|
var l = Object.getOwnPropertySymbols(i);
|
|
@@ -97,18 +96,18 @@ function z(i, o) {
|
|
|
97
96
|
}
|
|
98
97
|
return a;
|
|
99
98
|
}
|
|
100
|
-
function
|
|
99
|
+
function z(i) {
|
|
101
100
|
for (var o = 1; o < arguments.length; o++) {
|
|
102
101
|
var a = arguments[o] != null ? arguments[o] : {};
|
|
103
|
-
o % 2 ?
|
|
104
|
-
|
|
105
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(i, Object.getOwnPropertyDescriptors(a)) :
|
|
102
|
+
o % 2 ? W(Object(a), !0).forEach(function(l) {
|
|
103
|
+
ve(i, l, a[l]);
|
|
104
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(i, Object.getOwnPropertyDescriptors(a)) : W(Object(a)).forEach(function(l) {
|
|
106
105
|
Object.defineProperty(i, l, Object.getOwnPropertyDescriptor(a, l));
|
|
107
106
|
});
|
|
108
107
|
}
|
|
109
108
|
return i;
|
|
110
109
|
}
|
|
111
|
-
var
|
|
110
|
+
var we = (i, o, a) => {
|
|
112
111
|
for (var l of Object.keys(i)) {
|
|
113
112
|
var n;
|
|
114
113
|
if (i[l] !== ((n = o[l]) !== null && n !== void 0 ? n : a[l]))
|
|
@@ -116,7 +115,7 @@ var Fe = (i, o, a) => {
|
|
|
116
115
|
}
|
|
117
116
|
return !0;
|
|
118
117
|
}, U = (i) => (o) => {
|
|
119
|
-
var a = i.defaultClassName, l =
|
|
118
|
+
var a = i.defaultClassName, l = z(z({}, i.defaultVariants), o);
|
|
120
119
|
for (var n in l) {
|
|
121
120
|
var v, w = (v = l[n]) !== null && v !== void 0 ? v : i.defaultVariants[n];
|
|
122
121
|
if (w != null) {
|
|
@@ -127,10 +126,10 @@ var Fe = (i, o, a) => {
|
|
|
127
126
|
}
|
|
128
127
|
}
|
|
129
128
|
for (var [F, C] of i.compoundVariants)
|
|
130
|
-
|
|
129
|
+
we(F, l, i.defaultVariants) && (a += " " + C);
|
|
131
130
|
return a;
|
|
132
|
-
},
|
|
133
|
-
function
|
|
131
|
+
}, ge = "rh07jwm", R = "rh07jwn", Fe = "rh07jwl", xe = U({ defaultClassName: "rh07jw0", variantClassNames: { active: { true: "rh07jw1", false: "rh07jw2" }, mini: { true: "rh07jw3", false: "rh07jw4" }, error: { true: "rh07jw5", false: "rh07jw6" }, shown: { true: "rh07jw7", false: "rh07jw8" } }, defaultVariants: { active: !1, mini: !1, error: !1, shown: !0 }, compoundVariants: [] }), ye = "rh07jwq", be = U({ defaultClassName: "rh07jw9", variantClassNames: { constrainContentWidth: { true: "rh07jwa", false: "rh07jwb" } }, defaultVariants: { constrainContentWidth: !1 }, compoundVariants: [] }), Ee = "rh07jwp", Se = "rh07jwr", Ue = U({ defaultClassName: "rh07jwd", variantClassNames: { mini: { true: "rh07jwe", false: "rh07jwf" }, error: { true: "rh07jwg", false: "rh07jwh" } }, defaultVariants: { mini: !1, error: !1 }, compoundVariants: [] }), L = "rh07jwc", Ce = "rh07jwo", je = U({ defaultClassName: "rh07jwi", variantClassNames: { mini: { true: "rh07jwj", false: "rh07jwk" } }, defaultVariants: { mini: !1 }, compoundVariants: [] });
|
|
132
|
+
function k({
|
|
134
133
|
constrainContentWidth: i,
|
|
135
134
|
description: o,
|
|
136
135
|
multiple: a = !1,
|
|
@@ -142,42 +141,42 @@ function G({
|
|
|
142
141
|
maxSize: c,
|
|
143
142
|
customRequirement: F,
|
|
144
143
|
onSelection: C,
|
|
145
|
-
onDismiss:
|
|
146
|
-
download:
|
|
144
|
+
onDismiss: T,
|
|
145
|
+
download: N,
|
|
147
146
|
shown: x,
|
|
148
|
-
className:
|
|
149
|
-
children:
|
|
150
|
-
...
|
|
147
|
+
className: X,
|
|
148
|
+
children: De,
|
|
149
|
+
...G
|
|
151
150
|
}) {
|
|
152
|
-
const y = e.useRef(/* @__PURE__ */ new Set()), [
|
|
151
|
+
const y = e.useRef(/* @__PURE__ */ new Set()), [Z, P] = e.useState(x), [Te, q] = e.useState([]), [H, J] = e.useState(""), [A, K] = e.useState(), [_, b] = e.useState(!1), [g, E] = e.useState(!1), [j, M] = e.useState([]), [Y, Q] = e.useState(""), { t: h } = e.useContext(fe), O = h(a ? "design-system:fileUpload.instructions_plural" : "design-system:fileUpload.instructions").split("|"), $ = o || (a ? "Files" : "File"), d = e.useRef(null);
|
|
153
152
|
e.useEffect(() => {
|
|
154
153
|
x && P(x);
|
|
155
154
|
}, [x]), e.useEffect(() => {
|
|
156
|
-
c &&
|
|
155
|
+
c && te(c);
|
|
157
156
|
}, [c]), e.useEffect(() => {
|
|
158
|
-
p &&
|
|
157
|
+
p && ie(p);
|
|
159
158
|
}, [p]);
|
|
160
|
-
function
|
|
161
|
-
l && (P(!1),
|
|
159
|
+
function ee() {
|
|
160
|
+
l && (P(!1), T && T());
|
|
162
161
|
}
|
|
163
|
-
function
|
|
162
|
+
function te(t) {
|
|
164
163
|
try {
|
|
165
|
-
|
|
164
|
+
K(he(t));
|
|
166
165
|
} catch {
|
|
167
166
|
throw new Error(`Could not parse "${t}" as a file size.`);
|
|
168
167
|
}
|
|
169
168
|
}
|
|
170
|
-
function
|
|
169
|
+
function ie(t) {
|
|
171
170
|
const f = (Array.isArray(t) ? t : t.trim().split(/\s?,\s?/)).map((u) => u.replace(/^\./, "")), r = f.map((u) => `.${u}`.toLowerCase());
|
|
172
|
-
|
|
173
|
-
r.map((u,
|
|
171
|
+
Q(
|
|
172
|
+
r.map((u, S) => S > 0 && S === r.length - 1 ? `or ${u}` : u).join(r.length > 2 ? ", " : " ")
|
|
174
173
|
), y.current.clear();
|
|
175
174
|
for (const u of f) {
|
|
176
|
-
const
|
|
177
|
-
for (const
|
|
178
|
-
y.current.add(
|
|
175
|
+
const S = Object.keys(V).includes(u.toUpperCase()) ? V[u.toUpperCase()] : [];
|
|
176
|
+
for (const ce of S)
|
|
177
|
+
y.current.add(ce);
|
|
179
178
|
}
|
|
180
|
-
|
|
179
|
+
J(r.concat(Array.from(y.current)).join(","));
|
|
181
180
|
}
|
|
182
181
|
function D(t) {
|
|
183
182
|
M([]);
|
|
@@ -185,102 +184,102 @@ function G({
|
|
|
185
184
|
const f = Array.from(t);
|
|
186
185
|
for (const r of f)
|
|
187
186
|
r === null ? s.push("Not a file") : (p && !y.current.has(r.type) && s.push(r.name), c && A && r.size > A && s.indexOf(r.name) === -1 && s.push(r.name));
|
|
188
|
-
s.length ? (
|
|
187
|
+
s.length ? (E(!0), d.current && d.current.value && (d.current.value = "")) : (q(f), C(f)), M(s);
|
|
188
|
+
}
|
|
189
|
+
function ae(t) {
|
|
190
|
+
t.preventDefault(), E(!1), d.current && d.current.click();
|
|
191
|
+
}
|
|
192
|
+
function le() {
|
|
193
|
+
N && N();
|
|
189
194
|
}
|
|
190
195
|
function oe(t) {
|
|
191
|
-
t.
|
|
196
|
+
t.stopPropagation(), D(t.target.files || []), d.current && d.current.value && (d.current.value = "");
|
|
192
197
|
}
|
|
193
|
-
function ne() {
|
|
194
|
-
|
|
198
|
+
function ne(t) {
|
|
199
|
+
t.preventDefault(), t.stopPropagation(), b(!0), E(!1);
|
|
195
200
|
}
|
|
196
201
|
function se(t) {
|
|
197
|
-
t.
|
|
202
|
+
t.preventDefault(), b(!0), E(!1);
|
|
198
203
|
}
|
|
199
204
|
function re(t) {
|
|
200
|
-
t.preventDefault(),
|
|
205
|
+
t.preventDefault(), b(!1);
|
|
201
206
|
}
|
|
202
207
|
function pe(t) {
|
|
203
|
-
t.preventDefault(),
|
|
204
|
-
}
|
|
205
|
-
function ce(t) {
|
|
206
|
-
t.preventDefault(), S(!1);
|
|
207
|
-
}
|
|
208
|
-
function de(t) {
|
|
209
|
-
t.preventDefault(), t.stopPropagation(), S(!1), t.dataTransfer.items ? D(
|
|
208
|
+
t.preventDefault(), t.stopPropagation(), b(!1), t.dataTransfer.items ? D(
|
|
210
209
|
Array.from(t.dataTransfer.items).map(
|
|
211
210
|
(s) => s.getAsFile()
|
|
212
211
|
)
|
|
213
212
|
) : D(t.dataTransfer.files);
|
|
214
213
|
}
|
|
215
214
|
return /* @__PURE__ */ e.createElement("div", {
|
|
216
|
-
onDrop:
|
|
217
|
-
onDragOver:
|
|
218
|
-
onDragLeave:
|
|
219
|
-
onDragEnter:
|
|
220
|
-
className:
|
|
221
|
-
...
|
|
215
|
+
onDrop: pe,
|
|
216
|
+
onDragOver: ne,
|
|
217
|
+
onDragLeave: re,
|
|
218
|
+
onDragEnter: se,
|
|
219
|
+
className: B(xe({ active: _, mini: v, error: g, shown: Z }), X),
|
|
220
|
+
...G
|
|
222
221
|
}, /* @__PURE__ */ e.createElement("div", {
|
|
223
|
-
className:
|
|
224
|
-
}, n ? /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(
|
|
222
|
+
className: B(be({ constrainContentWidth: i }))
|
|
223
|
+
}, n ? /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(ue, {
|
|
225
224
|
size: "md",
|
|
226
225
|
"aria-hidden": "true"
|
|
227
226
|
}), /* @__PURE__ */ e.createElement("div", {
|
|
228
|
-
className:
|
|
229
|
-
}, h("design-system:fileUpload.processing"))) : /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(
|
|
230
|
-
className:
|
|
227
|
+
className: L
|
|
228
|
+
}, h("design-system:fileUpload.processing"))) : /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(me, {
|
|
229
|
+
className: Ue({ mini: v, error: g }),
|
|
231
230
|
icon: g ? "exclamation-circle" : "upload-cloud",
|
|
232
231
|
"aria-hidden": "true"
|
|
233
232
|
}), /* @__PURE__ */ e.createElement("div", {
|
|
234
|
-
className:
|
|
233
|
+
className: je({ mini: v })
|
|
235
234
|
}, g ? /* @__PURE__ */ e.createElement("div", null, h(
|
|
236
235
|
j.length > 1 ? "design-system:fileUpload.cancelled_plural" : "design-system:fileUpload.cancelled"
|
|
237
|
-
)) : /* @__PURE__ */ e.createElement("div", null, h("design-system:fileUpload.title", { description:
|
|
238
|
-
className:
|
|
236
|
+
)) : /* @__PURE__ */ e.createElement("div", null, h("design-system:fileUpload.title", { description: $ }))), g ? /* @__PURE__ */ e.createElement("div", {
|
|
237
|
+
className: Fe
|
|
239
238
|
}, new Set(
|
|
240
239
|
j.map((t, s) => {
|
|
241
240
|
const f = Math.floor(t.length / 2);
|
|
242
241
|
return /* @__PURE__ */ e.createElement("div", {
|
|
243
|
-
className:
|
|
242
|
+
className: ge,
|
|
244
243
|
key: t
|
|
245
244
|
}, /* @__PURE__ */ e.createElement("span", {
|
|
246
|
-
className:
|
|
245
|
+
className: R
|
|
247
246
|
}, t.substr(0, f)), /* @__PURE__ */ e.createElement("div", {
|
|
248
|
-
className:
|
|
247
|
+
className: R
|
|
249
248
|
}, /* @__PURE__ */ e.createElement("span", null, t.substr(f))), s < j.length - 1 ? "," : "");
|
|
250
249
|
})
|
|
251
250
|
)) : /* @__PURE__ */ e.createElement("span", null), /* @__PURE__ */ e.createElement("div", {
|
|
252
|
-
className:
|
|
251
|
+
className: L
|
|
253
252
|
}, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("span", null, O[0]), /* @__PURE__ */ e.createElement("a", {
|
|
254
253
|
href: "",
|
|
255
|
-
onClick:
|
|
254
|
+
onClick: ae
|
|
256
255
|
}, O[1]), /* @__PURE__ */ e.createElement("span", null, O[2]))), /* @__PURE__ */ e.createElement("div", {
|
|
257
|
-
className:
|
|
256
|
+
className: Ce
|
|
258
257
|
}, p ? /* @__PURE__ */ e.createElement("span", null, "(", " ", h("design-system:fileUpload.acceptedTypes", {
|
|
259
|
-
fileTypes:
|
|
258
|
+
fileTypes: Y
|
|
260
259
|
}), " ", ")") : "", c ? /* @__PURE__ */ e.createElement("span", null, "( ", h("design-system:fileUpload.maximumSize", { size: c }), " )") : "", F ? /* @__PURE__ */ e.createElement("span", null, " ", F, " ") : ""), w && /* @__PURE__ */ e.createElement("div", {
|
|
261
|
-
className:
|
|
262
|
-
}, /* @__PURE__ */ e.createElement(
|
|
263
|
-
kind:
|
|
264
|
-
icon:
|
|
265
|
-
onClick:
|
|
260
|
+
className: Ee
|
|
261
|
+
}, /* @__PURE__ */ e.createElement(I, {
|
|
262
|
+
kind: "link",
|
|
263
|
+
icon: "download-cloud",
|
|
264
|
+
onClick: le
|
|
266
265
|
}, w)))), l && !n && /* @__PURE__ */ e.createElement("div", {
|
|
267
|
-
className:
|
|
268
|
-
}, /* @__PURE__ */ e.createElement(
|
|
269
|
-
kind:
|
|
270
|
-
icon:
|
|
266
|
+
className: ye
|
|
267
|
+
}, /* @__PURE__ */ e.createElement(I, {
|
|
268
|
+
kind: "icon",
|
|
269
|
+
icon: "x",
|
|
271
270
|
title: h("design-system:fileUpload.close"),
|
|
272
|
-
onClick:
|
|
271
|
+
onClick: ee
|
|
273
272
|
})), /* @__PURE__ */ e.createElement("form", {
|
|
274
|
-
className:
|
|
273
|
+
className: Se
|
|
275
274
|
}, /* @__PURE__ */ e.createElement("input", {
|
|
276
275
|
ref: d,
|
|
277
276
|
type: "file",
|
|
278
|
-
accept:
|
|
277
|
+
accept: H || "*/*",
|
|
279
278
|
multiple: a || void 0,
|
|
280
|
-
onChange:
|
|
279
|
+
onChange: oe
|
|
281
280
|
})));
|
|
282
281
|
}
|
|
283
|
-
|
|
282
|
+
de.set(k, {
|
|
284
283
|
name: "FileUpload",
|
|
285
284
|
props: {
|
|
286
285
|
constrainContentWidth: { type: "boolean" },
|
|
@@ -297,8 +296,8 @@ ue.set(G, {
|
|
|
297
296
|
download: { type: "() => void" }
|
|
298
297
|
}
|
|
299
298
|
});
|
|
300
|
-
const
|
|
301
|
-
components: [
|
|
299
|
+
const Oe = {
|
|
300
|
+
components: [k],
|
|
302
301
|
examples: {
|
|
303
302
|
basic: {
|
|
304
303
|
label: "Basic File Upload",
|
|
@@ -410,6 +409,7 @@ const Ne = {
|
|
|
410
409
|
basic: {
|
|
411
410
|
react: m`
|
|
412
411
|
import { FileUpload } from "@sps-woodland/file-upload";
|
|
412
|
+
import { Button } from "@sps-woodland/buttons";
|
|
413
413
|
|
|
414
414
|
function Component() {
|
|
415
415
|
const [showFileUpload, setShowFileUpload] = React.useState(true);
|
|
@@ -430,9 +430,9 @@ const Ne = {
|
|
|
430
430
|
shown={showFileUpload}
|
|
431
431
|
/>
|
|
432
432
|
{!showFileUpload && (
|
|
433
|
-
<
|
|
433
|
+
<Button onClick={() => setShowFileUpload(true)}>
|
|
434
434
|
Reset
|
|
435
|
-
</
|
|
435
|
+
</Button>
|
|
436
436
|
)}
|
|
437
437
|
</>
|
|
438
438
|
)
|
|
@@ -523,10 +523,10 @@ const Ne = {
|
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
|
-
},
|
|
527
|
-
"File Upload":
|
|
526
|
+
}, Me = {
|
|
527
|
+
"File Upload": Oe
|
|
528
528
|
};
|
|
529
529
|
export {
|
|
530
|
-
|
|
531
|
-
|
|
530
|
+
k as FileUpload,
|
|
531
|
+
Me as MANIFEST
|
|
532
532
|
};
|
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": "
|
|
4
|
+
"version": "8.0.0",
|
|
5
5
|
"author": "SPS Commerce",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"repository": "https://github.com/SPSCommerce/woodland/tree/main/packages/@sps-woodland/file-upload",
|
|
@@ -26,28 +26,29 @@
|
|
|
26
26
|
"access": "public"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@spscommerce/ds-illustrations": "6.37.3",
|
|
30
29
|
"@spscommerce/utils": "^6.12.1",
|
|
30
|
+
"@spscommerce/ds-illustrations": "^6.12.1",
|
|
31
31
|
"react": "^16.14.0",
|
|
32
32
|
"react-dom": "^16.14.0",
|
|
33
|
-
"@sps-woodland/core": "
|
|
34
|
-
"@sps-woodland/tokens": "
|
|
35
|
-
"@
|
|
36
|
-
"@spscommerce/ds-react": "
|
|
37
|
-
"@spscommerce/ds-shared": "
|
|
33
|
+
"@sps-woodland/core": "8.0.0",
|
|
34
|
+
"@sps-woodland/tokens": "8.0.0",
|
|
35
|
+
"@sps-woodland/buttons": "8.0.0",
|
|
36
|
+
"@spscommerce/ds-react": "8.0.0",
|
|
37
|
+
"@spscommerce/ds-shared": "8.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@spscommerce/ds-illustrations": "6.37.3",
|
|
41
40
|
"@spscommerce/utils": "^6.12.1",
|
|
41
|
+
"@spscommerce/ds-illustrations": "^6.12.1",
|
|
42
42
|
"@vanilla-extract/css": "^1.9.3",
|
|
43
43
|
"@vanilla-extract/recipes": "^0.2.5",
|
|
44
44
|
"react": "^16.14.0",
|
|
45
45
|
"react-dom": "^16.14.0",
|
|
46
|
-
"@sps-woodland/core": "
|
|
47
|
-
"@sps-woodland/tokens": "
|
|
48
|
-
"@
|
|
49
|
-
"@spscommerce/ds-react": "
|
|
50
|
-
"@spscommerce/ds-shared": "
|
|
46
|
+
"@sps-woodland/core": "8.0.0",
|
|
47
|
+
"@sps-woodland/tokens": "8.0.0",
|
|
48
|
+
"@sps-woodland/buttons": "8.0.0",
|
|
49
|
+
"@spscommerce/ds-react": "8.0.0",
|
|
50
|
+
"@spscommerce/ds-shared": "8.0.0",
|
|
51
|
+
"@spscommerce/ds-colors": "8.0.0"
|
|
51
52
|
},
|
|
52
53
|
"scripts": {
|
|
53
54
|
"build": "pnpm run build:js && pnpm run build:types",
|