@blakesteve/roster 5.5.0 → 5.7.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.
Files changed (47) hide show
  1. package/README.md +183 -2
  2. package/dist/components/atoms/LoadingDots/LoadingDots.cjs +1 -0
  3. package/dist/components/atoms/LoadingDots/LoadingDots.d.ts +20 -0
  4. package/dist/components/atoms/LoadingDots/LoadingDots.js +43 -0
  5. package/dist/components/atoms/Progress/Progress.cjs +1 -0
  6. package/dist/components/atoms/Progress/Progress.d.ts +61 -0
  7. package/dist/components/atoms/Progress/Progress.js +106 -0
  8. package/dist/components/atoms/Progress/progress-values.cjs +1 -0
  9. package/dist/components/atoms/Progress/progress-values.d.ts +26 -0
  10. package/dist/components/atoms/Progress/progress-values.js +12 -0
  11. package/dist/components/atoms/Skeleton/Skeleton.cjs +1 -0
  12. package/dist/components/atoms/Skeleton/Skeleton.d.ts +79 -0
  13. package/dist/components/atoms/Skeleton/Skeleton.js +80 -0
  14. package/dist/components/atoms/Stat/Stat.cjs +1 -1
  15. package/dist/components/atoms/Stat/Stat.js +19 -19
  16. package/dist/components/atoms/Stat/stat-variants.cjs +1 -1
  17. package/dist/components/atoms/Stat/stat-variants.d.ts +1 -0
  18. package/dist/components/atoms/Stat/stat-variants.js +5 -4
  19. package/dist/components/molecules/FileUpload/FileUpload.cjs +1 -1
  20. package/dist/components/molecules/FileUpload/FileUpload.js +120 -141
  21. package/dist/components/molecules/Pagination/Pagination.cjs +1 -0
  22. package/dist/components/molecules/Pagination/Pagination.d.ts +116 -0
  23. package/dist/components/molecules/Pagination/Pagination.js +247 -0
  24. package/dist/components/molecules/Pagination/page-items.cjs +1 -0
  25. package/dist/components/molecules/Pagination/page-items.d.ts +13 -0
  26. package/dist/components/molecules/Pagination/page-items.js +11 -0
  27. package/dist/components/molecules/ProgressField/ProgressField.cjs +1 -0
  28. package/dist/components/molecules/ProgressField/ProgressField.d.ts +23 -0
  29. package/dist/components/molecules/ProgressField/ProgressField.js +32 -0
  30. package/dist/components/molecules/SkeletonPresets/SkeletonPresets.cjs +1 -0
  31. package/dist/components/molecules/SkeletonPresets/SkeletonPresets.d.ts +55 -0
  32. package/dist/components/molecules/SkeletonPresets/SkeletonPresets.js +45 -0
  33. package/dist/components/molecules/StepProgress/StepProgress.cjs +1 -0
  34. package/dist/components/molecules/StepProgress/StepProgress.d.ts +36 -0
  35. package/dist/components/molecules/StepProgress/StepProgress.js +89 -0
  36. package/dist/components/organisms/DataTable/DataTable.cjs +1 -1
  37. package/dist/components/organisms/DataTable/DataTable.d.ts +8 -1
  38. package/dist/components/organisms/DataTable/DataTable.js +61 -98
  39. package/dist/components/organisms/Dialog/Dialog.d.ts +1 -1
  40. package/dist/index.d.ts +7 -0
  41. package/dist/meta.json +3 -3
  42. package/dist/node_modules/@fortawesome/free-solid-svg-icons/index.cjs +1 -1
  43. package/dist/node_modules/@fortawesome/free-solid-svg-icons/index.js +30 -50
  44. package/dist/roster.cjs +1 -1
  45. package/dist/roster.css +1 -1
  46. package/dist/roster.js +178 -159
  47. package/package.json +1 -1
@@ -0,0 +1,80 @@
1
+ "use client";
2
+ import { jsx as s, jsxs as p, Fragment as g } from "react/jsx-runtime";
3
+ import { useState as y, useEffect as S } from "react";
4
+ import { cn as a } from "../../../lib/utils.js";
5
+ const f = {
6
+ sm: "rst:text-xs",
7
+ md: "rst:text-sm",
8
+ lg: "rst:text-base",
9
+ inherit: ""
10
+ }, k = {
11
+ xs: "rst:h-6 rst:w-6",
12
+ sm: "rst:h-8 rst:w-8",
13
+ md: "rst:h-10 rst:w-10",
14
+ lg: "rst:h-12 rst:w-12",
15
+ xl: "rst:h-16 rst:w-16"
16
+ }, x = {
17
+ sm: "rst:rounded-sm",
18
+ md: "rst:rounded-md",
19
+ lg: "rst:rounded-lg",
20
+ xl: "rst:rounded-xl",
21
+ full: "rst:rounded-full"
22
+ }, h = "rst:animate-skeleton rst:forced-colors:outline-solid rst:forced-colors:outline-1";
23
+ function E({ shape: t = "line", size: r, lines: d = 1, width: e, height: u, radius: c, className: o }) {
24
+ if (t === "circle") {
25
+ const l = r && r in k ? r : "md";
26
+ return /* @__PURE__ */ s(
27
+ "span",
28
+ {
29
+ "aria-hidden": "true",
30
+ className: a("rst:block rst:shrink-0 rst:rounded-full rst:border rst:border-transparent", k[l], h, o),
31
+ "data-skeleton": "circle"
32
+ }
33
+ );
34
+ }
35
+ if (t === "block")
36
+ return /* @__PURE__ */ s(
37
+ "span",
38
+ {
39
+ "aria-hidden": "true",
40
+ className: a("rst:block rst:w-full", x[c ?? "lg"], h, o),
41
+ style: { height: u ?? "8rem", width: e },
42
+ "data-skeleton": "block"
43
+ }
44
+ );
45
+ const m = r && r in f ? r : "md", n = Math.max(1, Math.floor(d)), b = (l) => {
46
+ const i = l === n - 1;
47
+ return /* @__PURE__ */ p(
48
+ "span",
49
+ {
50
+ className: a("rst:relative rst:block", n > 1 && !i && "rst:w-full"),
51
+ style: { width: n > 1 ? i ? e ?? "60%" : void 0 : e },
52
+ children: [
53
+ " ",
54
+ /* @__PURE__ */ s(
55
+ "span",
56
+ {
57
+ className: a("rst:absolute rst:inset-x-0 rst:top-1/2 rst:h-[0.7em] rst:-translate-y-1/2", x[c ?? "sm"], h)
58
+ }
59
+ )
60
+ ]
61
+ },
62
+ l
63
+ );
64
+ };
65
+ return /* @__PURE__ */ s("span", { "aria-hidden": "true", className: a("rst:block", f[m], o), "data-skeleton": "line", children: Array.from({ length: n }, (l, i) => b(i)) });
66
+ }
67
+ function L({ loading: t, skeleton: r, label: d = "Loading", announce: e = !0, children: u, className: c }) {
68
+ const [o, m] = y("");
69
+ return S(() => {
70
+ const n = setTimeout(() => m(t && e ? d : ""), t ? 50 : 0);
71
+ return () => clearTimeout(n);
72
+ }, [t, d, e]), /* @__PURE__ */ p(g, { children: [
73
+ /* @__PURE__ */ s("span", { role: "status", className: "rst:sr-only", "data-skeleton-status": "", children: o }),
74
+ /* @__PURE__ */ s("div", { "aria-busy": t || void 0, className: c, "data-skeleton-region": t ? "loading" : "ready", children: t ? /* @__PURE__ */ s("div", { "aria-hidden": "true", children: r }) : u })
75
+ ] });
76
+ }
77
+ export {
78
+ E as Skeleton,
79
+ L as SkeletonRegion
80
+ };
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),u=require("react"),t=require("../../../lib/utils.cjs"),h=require("./stat-variants.cjs"),o=require("../Eyebrow/Eyebrow.cjs"),d="rst:block rst:font-mono rst:text-[0.53125rem] rst:font-normal rst:normal-nums rst:leading-none rst:tracking-[0.06em] rst:text-gray-500 rst:opacity-75 rst:dark:text-gray-400",x=u.forwardRef(({value:a,label:n,source:r,size:m,colorScheme:j,semantics:g="definition",className:c,...i},l)=>{const e=h.statValueVariants({size:m,colorScheme:j});return g==="standalone"?s.jsxs("div",{ref:l,className:t.cn("rst:flex rst:flex-col rst:gap-[3px]",c),...i,children:[s.jsx("span",{className:e,children:a}),s.jsx(o.Eyebrow,{size:"xs",children:n}),r&&s.jsx("span",{className:d,children:r})]}):s.jsxs("div",{ref:l,className:t.cn("rst:grid rst:content-start rst:gap-[3px]",c),...i,children:[s.jsx("dt",{className:"rst:relative rst:col-start-1 rst:row-start-2",children:s.jsx(o.Eyebrow,{size:"xs",children:n})}),r?s.jsxs("dd",{className:t.cn("rst:m-0",e,"rst:col-start-1 rst:row-span-3 rst:row-start-1 rst:grid rst:grid-rows-subgrid"),children:[s.jsx("span",{className:"rst:row-start-1",children:a}),s.jsx("span",{className:t.cn(d,"rst:row-start-3"),children:r})]}):s.jsx("dd",{className:t.cn("rst:m-0 rst:col-start-1 rst:row-start-1",e),children:a})]})});x.displayName="Stat";exports.Stat=x;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),w=require("react"),t=require("../../../lib/utils.cjs"),x=require("./stat-variants.cjs"),d=require("../Eyebrow/Eyebrow.cjs"),o=x.statSourceClass,j=w.forwardRef(({value:a,label:n,source:r,size:m,colorScheme:u,semantics:h="definition",className:c,...i},l)=>{const e=x.statValueVariants({size:m,colorScheme:u});return h==="standalone"?s.jsxs("div",{ref:l,className:t.cn("rst:flex rst:flex-col rst:gap-[3px]",c),...i,children:[s.jsx("span",{className:e,children:a}),s.jsx(d.Eyebrow,{size:"xs",children:n}),r&&s.jsx("span",{className:o,children:r})]}):s.jsxs("div",{ref:l,className:t.cn("rst:grid rst:content-start rst:gap-[3px]",c),...i,children:[s.jsx("dt",{className:"rst:relative rst:col-start-1 rst:row-start-2",children:s.jsx(d.Eyebrow,{size:"xs",children:n})}),r?s.jsxs("dd",{className:t.cn("rst:m-0",e,"rst:col-start-1 rst:row-span-3 rst:row-start-1 rst:grid rst:grid-rows-subgrid"),children:[s.jsx("span",{className:"rst:row-start-1",children:a}),s.jsx("span",{className:t.cn(o,"rst:row-start-3"),children:r})]}):s.jsx("dd",{className:t.cn("rst:m-0 rst:col-start-1 rst:row-start-1",e),children:a})]})});j.displayName="Stat";exports.Stat=j;
@@ -1,24 +1,24 @@
1
1
  "use client";
2
- import { jsxs as n, jsx as t } from "react/jsx-runtime";
3
- import h from "react";
2
+ import { jsxs as i, jsx as s } from "react/jsx-runtime";
3
+ import w from "react";
4
4
  import { cn as r } from "../../../lib/utils.js";
5
- import { statValueVariants as g } from "./stat-variants.js";
6
- import { Eyebrow as d } from "../Eyebrow/Eyebrow.js";
7
- const m = "rst:block rst:font-mono rst:text-[0.53125rem] rst:font-normal rst:normal-nums rst:leading-none rst:tracking-[0.06em] rst:text-gray-500 rst:opacity-75 rst:dark:text-gray-400", w = h.forwardRef(
8
- ({ value: a, label: i, source: s, size: p, colorScheme: f, semantics: x = "definition", className: o, ...l }, c) => {
9
- const e = g({ size: p, colorScheme: f });
10
- return x === "standalone" ? /* @__PURE__ */ n("div", { ref: c, className: r("rst:flex rst:flex-col rst:gap-[3px]", o), ...l, children: [
11
- /* @__PURE__ */ t("span", { className: e, children: a }),
12
- /* @__PURE__ */ t(d, { size: "xs", children: i }),
13
- s && /* @__PURE__ */ t("span", { className: m, children: s })
5
+ import { statValueVariants as x, statSourceClass as N } from "./stat-variants.js";
6
+ import { Eyebrow as o } from "../Eyebrow/Eyebrow.js";
7
+ const m = N, g = w.forwardRef(
8
+ ({ value: a, label: l, source: t, size: p, colorScheme: f, semantics: h = "definition", className: n, ...c }, d) => {
9
+ const e = x({ size: p, colorScheme: f });
10
+ return h === "standalone" ? /* @__PURE__ */ i("div", { ref: d, className: r("rst:flex rst:flex-col rst:gap-[3px]", n), ...c, children: [
11
+ /* @__PURE__ */ s("span", { className: e, children: a }),
12
+ /* @__PURE__ */ s(o, { size: "xs", children: l }),
13
+ t && /* @__PURE__ */ s("span", { className: m, children: t })
14
14
  ] }) : (
15
15
  /* `content-start`: a Stat in a row of taller siblings is stretched to
16
16
  their height, and a grid shares that height out among its auto rows,
17
17
  which pushed the label of a Stat without a source down to meet
18
18
  nothing. The flex column this replaced never did. */
19
- /* @__PURE__ */ n("div", { ref: c, className: r("rst:grid rst:content-start rst:gap-[3px]", o), ...l, children: [
20
- /* @__PURE__ */ t("dt", { className: "rst:relative rst:col-start-1 rst:row-start-2", children: /* @__PURE__ */ t(d, { size: "xs", children: i }) }),
21
- s ? /* @__PURE__ */ n(
19
+ /* @__PURE__ */ i("div", { ref: d, className: r("rst:grid rst:content-start rst:gap-[3px]", n), ...c, children: [
20
+ /* @__PURE__ */ s("dt", { className: "rst:relative rst:col-start-1 rst:row-start-2", children: /* @__PURE__ */ s(o, { size: "xs", children: l }) }),
21
+ t ? /* @__PURE__ */ i(
22
22
  "dd",
23
23
  {
24
24
  className: r(
@@ -27,16 +27,16 @@ const m = "rst:block rst:font-mono rst:text-[0.53125rem] rst:font-normal rst:nor
27
27
  "rst:col-start-1 rst:row-span-3 rst:row-start-1 rst:grid rst:grid-rows-subgrid"
28
28
  ),
29
29
  children: [
30
- /* @__PURE__ */ t("span", { className: "rst:row-start-1", children: a }),
31
- /* @__PURE__ */ t("span", { className: r(m, "rst:row-start-3"), children: s })
30
+ /* @__PURE__ */ s("span", { className: "rst:row-start-1", children: a }),
31
+ /* @__PURE__ */ s("span", { className: r(m, "rst:row-start-3"), children: t })
32
32
  ]
33
33
  }
34
- ) : /* @__PURE__ */ t("dd", { className: r("rst:m-0 rst:col-start-1 rst:row-start-1", e), children: a })
34
+ ) : /* @__PURE__ */ s("dd", { className: r("rst:m-0 rst:col-start-1 rst:row-start-1", e), children: a })
35
35
  ] })
36
36
  );
37
37
  }
38
38
  );
39
- w.displayName = "Stat";
39
+ g.displayName = "Stat";
40
40
  export {
41
- w as Stat
41
+ g as Stat
42
42
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../../node_modules/class-variance-authority/dist/index.cjs"),r=t.cva("rst:block rst:font-bold rst:leading-none rst:tracking-[-0.04em] rst:tabular-nums",{variants:{size:{sm:"rst:text-xl",md:"rst:text-[clamp(1.5rem,3.6vw,2.25rem)]",lg:"rst:text-[clamp(2rem,5vw,3rem)]"},colorScheme:{primary:"rst:text-primary-600 rst:dark:text-primary-400",success:"rst:text-success-600 rst:dark:text-success-400",error:"rst:text-error-600 rst:dark:text-error-400",amber:"rst:text-amber-600 rst:dark:text-amber-400",neutral:"rst:text-gray-900 rst:dark:text-gray-100",current:"rst:text-current"}},defaultVariants:{size:"md",colorScheme:"neutral"}});exports.statValueVariants=r;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../../node_modules/class-variance-authority/dist/index.cjs"),r=t.cva("rst:block rst:font-bold rst:leading-none rst:tracking-[-0.04em] rst:tabular-nums",{variants:{size:{sm:"rst:text-xl",md:"rst:text-[clamp(1.5rem,3.6vw,2.25rem)]",lg:"rst:text-[clamp(2rem,5vw,3rem)]"},colorScheme:{primary:"rst:text-primary-600 rst:dark:text-primary-400",success:"rst:text-success-600 rst:dark:text-success-400",error:"rst:text-error-600 rst:dark:text-error-400",amber:"rst:text-amber-600 rst:dark:text-amber-400",neutral:"rst:text-gray-900 rst:dark:text-gray-100",current:"rst:text-current"}},defaultVariants:{size:"md",colorScheme:"neutral"}}),e="rst:block rst:font-mono rst:text-[0.53125rem] rst:font-normal rst:normal-nums rst:leading-none rst:tracking-[0.06em] rst:text-gray-500 rst:opacity-75 rst:dark:text-gray-400";exports.statSourceClass=e;exports.statValueVariants=r;
@@ -7,3 +7,4 @@ export declare const statValueVariants: (props?: ({
7
7
  size?: "sm" | "md" | "lg" | null | undefined;
8
8
  colorScheme?: "primary" | "amber" | "success" | "error" | "neutral" | "current" | null | undefined;
9
9
  } & import('class-variance-authority/types').ClassProp) | undefined) => string;
10
+ export declare const statSourceClass = "rst:block rst:font-mono rst:text-[0.53125rem] rst:font-normal rst:normal-nums rst:leading-none rst:tracking-[0.06em] rst:text-gray-500 rst:opacity-75 rst:dark:text-gray-400";
@@ -1,5 +1,5 @@
1
- import { cva as r } from "../../../node_modules/class-variance-authority/dist/index.js";
2
- const e = /* @__PURE__ */ r(
1
+ import { cva as t } from "../../../node_modules/class-variance-authority/dist/index.js";
2
+ const s = /* @__PURE__ */ t(
3
3
  "rst:block rst:font-bold rst:leading-none rst:tracking-[-0.04em] rst:tabular-nums",
4
4
  {
5
5
  variants: {
@@ -19,7 +19,8 @@ const e = /* @__PURE__ */ r(
19
19
  },
20
20
  defaultVariants: { size: "md", colorScheme: "neutral" }
21
21
  }
22
- );
22
+ ), e = "rst:block rst:font-mono rst:text-[0.53125rem] rst:font-normal rst:normal-nums rst:leading-none rst:tracking-[0.06em] rst:text-gray-500 rst:opacity-75 rst:dark:text-gray-400";
23
23
  export {
24
- e as statValueVariants
24
+ e as statSourceClass,
25
+ s as statValueVariants
25
26
  };
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),p=require("../../../lib/utils.cjs"),P=require("../../atoms/Button/Button.cjs"),R=require("./file-rules.cjs"),pt={choose:"Choose photos",dropHint:"or drag them here",dropHere:"Drop to add them",queued:"Waiting",uploading:n=>n===null?"Uploading":`Uploading, ${n}%`,processing:"Finishing up",done:"Uploaded",failed:"Didn't upload.",rejected:"Not added.",remove:n=>`Remove ${n}`,retry:n=>`Try ${n} again`,wrongType:()=>"That type of file isn't accepted.",tooLarge:(n,l)=>`It's over ${R.formatBytes(l)}.`,tooMany:n=>`Only ${n} can be added.`,duplicate:()=>"It's already added.",uploadError:n=>n instanceof Error&&n.message?n.message:"Something went wrong.",size:R.formatBytes,added:n=>`${n} ${n===1?"photo":"photos"} added.`,progress:(n,l)=>`${n} of ${l} uploaded.`,failedNotice:(n,l)=>`${n} didn't upload. ${l}`,rejectedNotice:(n,l)=>`${n} wasn't added. ${l}`,removed:n=>`${n} removed.`};function gt({file:n,status:l}){const[M,q]=o.useState(!1),B=!M&&(n.type.startsWith("image/")||/\.(jpe?g|png|gif|webp|avif|heic|heif)$/i.test(n.name)),N=o.useCallback(L=>{if(!L)return;const w=URL.createObjectURL(n);return L.src=w,()=>URL.revokeObjectURL(w)},[n]),x="rst:h-14 rst:w-14 rst:shrink-0 rst:rounded-md rst:border rst:border-[var(--roster-card-border)]";return B?e.jsx("img",{ref:N,alt:"",onError:()=>q(!0),className:p.cn(x,"rst:object-cover",l==="rejected"&&"rst:opacity-50"),"data-file-thumb":"image"}):e.jsx("span",{"aria-hidden":"true",className:p.cn(x,"rst:flex rst:items-center rst:justify-center rst:text-gray-500 rst:dark:text-gray-400"),"data-file-thumb":"placeholder",children:e.jsxs("svg",{viewBox:"0 0 24 24",width:"24",height:"24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),e.jsx("circle",{cx:"9",cy:"10",r:"1.6"}),e.jsx("path",{d:"m21 15-4.2-4.2a1.6 1.6 0 0 0-2.3 0L7 18"})]})})}const W="rst:cursor-not-allowed rst:opacity-50",S={width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};function ht({label:n,upload:l,onChange:M,accept:q="image/*",types:B,maxSize:N,maxFiles:x,validate:L,concurrency:w=3,helperText:E,errorMessage:T,disabled:u=!1,strings:K,className:Q}){const c={...pt,...K},D=o.useId(),I=`${D}-label`,G=`${D}-help`,V=`${D}-error`,[U,Y]=o.useState([]),d=o.useRef(U),Z=o.useRef(0),m=o.useRef(new Map),F=o.useRef(null),X=o.useRef(null),g=o.useRef({upload:l,onChange:M,concurrency:w,t:c,pump:()=>{}}),[O,tt]=o.useState({text:"",n:0}),v=o.useRef([]),y=o.useRef(null),$=o.useCallback((t,s=!1)=>{s&&(v.current=v.current.filter(r=>!r.count)),v.current.push({text:t,count:s}),!y.current&&(y.current=setTimeout(()=>{y.current=null;const r=v.current.map(i=>i.text).join(" ");v.current=[],tt(i=>({text:r,n:i.n+1}))},0))},[]),z=o.useRef(null),[rt,et]=o.useState(0),_=t=>{z.current=t,et(s=>s+1)};o.useLayoutEffect(()=>{const t=z.current;if(!t)return;z.current=null,(F.current?.querySelector(t)??F.current?.querySelector("[data-file-choose]"))?.focus()},[rt]);const j=o.useCallback(t=>{d.current=t,Y(t),g.current.onChange?.(t)},[]),b=o.useCallback((t,s)=>{d.current.some(r=>r.id===t)&&j(d.current.map(r=>r.id===t?{...r,...s}:r))},[j]);function k(){const{concurrency:t}=g.current,s=d.current.filter(i=>i.status==="uploading"||i.status==="processing").length,r=d.current.filter(i=>i.status==="queued").slice(0,Math.max(0,Math.max(1,t)-s));for(const i of r)st(i)}function st(t){const s=new AbortController;m.current.set(t.id,s),b(t.id,{status:"uploading",progress:null,reason:void 0});const r=()=>!s.signal.aborted&&m.current.get(t.id)===s,i={onProgress:a=>{if(!r())return;const f=Math.round(Math.min(1,Math.max(0,Number.isFinite(a)?a:0))*100)/100,h=d.current.find(ft=>ft.id===t.id);h?.status==="uploading"&&h.progress!==f&&b(t.id,{progress:f})},onProcessing:()=>{r()&&b(t.id,{status:"processing"})},signal:s.signal};new Promise(a=>a(g.current.upload(t.file,i))).then(a=>{if(!r())return;m.current.delete(t.id),b(t.id,{status:"done",progress:1,result:a});const f=d.current.filter(h=>h.status!=="rejected");$(g.current.t.progress(f.filter(h=>h.status==="done").length,f.length),!0),k()},a=>{if(!r())return;m.current.delete(t.id);const f=g.current.t.uploadError(a);b(t.id,{status:"failed",reason:f}),$(g.current.t.failedNotice(t.file.name,f)),k()})}o.useLayoutEffect(()=>{g.current={upload:l,onChange:M,concurrency:w,t:c,pump:k}}),o.useEffect(()=>{const t=m.current;return d.current.some(r=>(r.status==="uploading"||r.status==="processing")&&!t.has(r.id))&&(j(d.current.map(r=>(r.status==="uploading"||r.status==="processing")&&!t.has(r.id)?{...r,status:"queued",progress:null}:r)),g.current.pump()),()=>{for(const r of t.values())r.abort();t.clear(),y.current&&clearTimeout(y.current),y.current=null,v.current=[]}},[j]);const nt=B??R.acceptList(q),at=(t,s)=>{if(s.some(i=>R.sameFile(i.file,t)))return c.duplicate(t);const r=L?.(t);if(r)return r;if(!R.matchesType(t,nt))return c.wrongType(t);if(N!==void 0&&t.size>N)return c.tooLarge(t,N);if(x!==void 0&&s.length>=x)return c.tooMany(x)},J=t=>{if(u||t.length===0)return;const s=d.current.filter(a=>a.status!=="rejected"),r=[];for(const a of t){const f=at(a,[...s,...r.filter(h=>h.status!=="rejected")]);r.push({id:`${D}-file-${Z.current++}`,file:a,status:f?"rejected":"queued",progress:null,reason:f})}j([...d.current,...r]);const i=r.filter(a=>a.status==="queued").length;i&&$(c.added(i));for(const a of r)a.reason&&$(c.rejectedNotice(a.file.name,a.reason));k()},ot=t=>{if(u)return;const s=d.current,r=s.findIndex(a=>a.id===t);if(r<0)return;m.current.get(t)?.abort(),m.current.delete(t);const i=s[r+1]??s[r-1];j(s.filter(a=>a.id!==t)),$(c.removed(s[r].file.name)),_(i?`[data-file-remove="${i.id}"]`:"[data-file-choose]"),k()},ct=t=>{u||(b(t,{status:"queued",progress:null,reason:void 0}),_(`[data-file-remove="${t}"]`),k())},[it,A]=o.useState(0),C=t=>Array.from(t.dataTransfer?.types??[]).includes("Files"),ut={onDragEnter:t=>{C(t)&&(t.preventDefault(),A(s=>s+1))},onDragOver:t=>{C(t)&&(t.preventDefault(),t.dataTransfer.dropEffect=u?"none":"copy")},onDragLeave:t=>{C(t)&&A(s=>Math.max(0,s-1))},onDrop:t=>{C(t)&&(t.preventDefault(),A(0),J(Array.from(t.dataTransfer.files)))}},H=it>0&&!u,lt=t=>{switch(t.status){case"queued":return c.queued;case"uploading":return c.uploading(t.progress===null?null:Math.round(t.progress*100));case"processing":return c.processing;case"done":return c.done;case"failed":return`${c.failed} ${t.reason??""}`.trim();case"rejected":return`${c.rejected} ${t.reason??""}`.trim()}},dt=[E?G:null,T?V:null].filter(Boolean).join(" ")||void 0;return e.jsxs("div",{ref:F,role:"group","aria-labelledby":I,className:p.cn("rst:font-ui rst:w-full",Q),"data-file-upload":"",children:[e.jsx("p",{id:I,className:p.cn("rst:mb-1.5 rst:text-left rst:text-sm rst:font-medium rst:leading-none rst:text-[var(--roster-control-text)]",u&&"rst:opacity-70"),children:n}),e.jsxs("div",{...ut,"data-file-drop":"","data-dragging":H?"":void 0,className:p.cn("rst:flex rst:flex-col rst:items-center rst:justify-center rst:gap-2 rst:rounded-lg rst:border-2 rst:border-dashed rst:px-4 rst:py-6 rst:text-center rst:transition-colors rst:motion-reduce:transition-none",H?"rst:border-primary-500 rst:bg-primary-500/10":T?"rst:border-error-500 rst:dark:border-error-400":"rst:border-gray-300 rst:dark:border-gray-600"),children:[e.jsx(P.Button,{type:"button",variant:"outline",colorScheme:"neutral",size:"lg",className:p.cn("rst:px-5",u&&W),"aria-disabled":u||void 0,"aria-describedby":dt,onClick:()=>X.current?.click(),"data-file-choose":"",startIcon:e.jsx("svg",{...S,"aria-hidden":"true",children:e.jsx("path",{d:"M12 16V4M7 9l5-5 5 5M5 20h14"})}),children:c.choose}),e.jsx("p",{className:"rst:hidden rst:text-xs rst:text-gray-600 rst:pointer-fine:block rst:dark:text-gray-400","data-file-drop-hint":"",children:H?c.dropHere:c.dropHint}),e.jsx("input",{ref:X,type:"file",hidden:!0,tabIndex:-1,accept:q,multiple:x!==1,disabled:u,onChange:t=>{J(Array.from(t.currentTarget.files??[])),t.currentTarget.value=""},"data-file-input":""})]}),E&&e.jsx("p",{id:G,className:"rst:mt-1.5 rst:text-left rst:text-xs rst:text-gray-500 rst:dark:text-gray-400",children:E}),T&&e.jsx("p",{id:V,className:"rst:mt-1.5 rst:text-left rst:text-xs rst:font-medium rst:text-error-600 rst:dark:text-error-400",children:T}),U.length>0&&e.jsx("ul",{className:"rst:mt-3 rst:flex rst:flex-col rst:gap-2","aria-labelledby":I,children:U.map(t=>{const s=t.status==="failed"||t.status==="rejected",r=t.status==="uploading"||t.status==="processing"||t.status==="queued";return e.jsxs("li",{"data-file-item":t.id,"data-status":t.status,className:"rst:flex rst:items-center rst:gap-3 rst:rounded-md rst:border rst:border-[var(--roster-card-border)] rst:p-2",children:[e.jsx(gt,{file:t.file,status:t.status}),e.jsxs("div",{className:"rst:min-w-0 rst:flex-1 rst:text-left",children:[e.jsx("p",{className:"rst:truncate rst:text-sm rst:font-medium rst:text-[var(--roster-control-text)]",title:t.file.name,children:t.file.name}),e.jsxs("p",{className:p.cn("rst:mt-0.5 rst:flex rst:items-start rst:gap-1 rst:text-xs",s?"rst:text-error-600 rst:dark:text-error-400":"rst:text-gray-600 rst:dark:text-gray-400"),"data-file-status":"",children:[t.status==="done"&&e.jsx("svg",{...S,width:14,height:14,"aria-hidden":"true",className:"rst:mt-px rst:shrink-0 rst:text-success-600 rst:dark:text-success-400",children:e.jsx("path",{d:"M20 6 9 17l-5-5"})}),e.jsxs("span",{children:[e.jsx("span",{className:"rst:tabular-nums",children:c.size(t.file.size)}),e.jsx("span",{"aria-hidden":"true",children:" · "}),lt(t)]})]}),r&&e.jsx("div",{role:"progressbar","aria-label":t.file.name,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":t.status==="uploading"&&t.progress!==null?Math.round(t.progress*100):void 0,className:p.cn("rst:mt-1.5 rst:h-1.5 rst:overflow-hidden rst:rounded-full rst:bg-gray-200 rst:dark:bg-gray-700",t.status==="uploading"&&t.progress===null&&"rst:animate-pulse rst:motion-reduce:animate-none"),"data-file-progress":"",children:e.jsx("div",{className:p.cn("rst:h-full rst:origin-left rst:rounded-full rst:bg-primary-600 rst:transition-transform rst:motion-reduce:transition-none rst:dark:bg-primary-400",t.status==="processing"&&"rst:animate-pulse rst:motion-reduce:animate-none"),style:{transform:`scaleX(${t.status==="processing"?1:t.status==="uploading"?t.progress??0:0})`}})})]}),t.status==="failed"&&e.jsx(P.Button,{type:"button",variant:"ghost",colorScheme:"neutral",size:"icon",className:p.cn("rst:h-11 rst:w-11",u&&W),"aria-disabled":u||void 0,"aria-label":c.retry(t.file.name),onClick:()=>ct(t.id),"data-file-retry":t.id,children:e.jsxs("svg",{...S,"aria-hidden":"true",children:[e.jsx("path",{d:"M3 12a9 9 0 1 0 3-6.7L3 8"}),e.jsx("path",{d:"M3 3v5h5"})]})}),e.jsx(P.Button,{type:"button",variant:"ghost",colorScheme:"neutral",size:"icon",className:p.cn("rst:h-11 rst:w-11",u&&W),"aria-disabled":u||void 0,"aria-label":c.remove(t.file.name),onClick:()=>ot(t.id),"data-file-remove":t.id,children:e.jsx("svg",{...S,"aria-hidden":"true",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]},t.id)})}),e.jsxs("div",{role:"status","aria-live":"polite","aria-atomic":"true",className:"rst:sr-only","data-file-live":"","data-file-live-n":O.n,children:[O.text,O.n%2?" ":""]})]})}exports.FileUpload=ht;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),o=require("react"),p=require("../../../lib/utils.cjs"),H=require("../../atoms/Button/Button.cjs"),pt=require("../../atoms/Progress/Progress.cjs"),R=require("./file-rules.cjs"),gt={choose:"Choose photos",dropHint:"or drag them here",dropHere:"Drop to add them",queued:"Waiting",uploading:n=>n===null?"Uploading":`Uploading, ${n}%`,processing:"Finishing up",done:"Uploaded",failed:"Didn't upload.",rejected:"Not added.",remove:n=>`Remove ${n}`,retry:n=>`Try ${n} again`,wrongType:()=>"That type of file isn't accepted.",tooLarge:(n,d)=>`It's over ${R.formatBytes(d)}.`,tooMany:n=>`Only ${n} can be added.`,duplicate:()=>"It's already added.",uploadError:n=>n instanceof Error&&n.message?n.message:"Something went wrong.",size:R.formatBytes,added:n=>`${n} ${n===1?"photo":"photos"} added.`,progress:(n,d)=>`${n} of ${d} uploaded.`,failedNotice:(n,d)=>`${n} didn't upload. ${d}`,rejectedNotice:(n,d)=>`${n} wasn't added. ${d}`,removed:n=>`${n} removed.`};function ht({file:n,status:d}){const[q,M]=o.useState(!1),B=!q&&(n.type.startsWith("image/")||/\.(jpe?g|png|gif|webp|avif|heic|heif)$/i.test(n.name)),N=o.useCallback(L=>{if(!L)return;const w=URL.createObjectURL(n);return L.src=w,()=>URL.revokeObjectURL(w)},[n]),x="rst:h-14 rst:w-14 rst:shrink-0 rst:rounded-md rst:border rst:border-[var(--roster-card-border)]";return B?r.jsx("img",{ref:N,alt:"",onError:()=>M(!0),className:p.cn(x,"rst:object-cover",d==="rejected"&&"rst:opacity-50"),"data-file-thumb":"image"}):r.jsx("span",{"aria-hidden":"true",className:p.cn(x,"rst:flex rst:items-center rst:justify-center rst:text-gray-500 rst:dark:text-gray-400"),"data-file-thumb":"placeholder",children:r.jsxs("svg",{viewBox:"0 0 24 24",width:"24",height:"24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),r.jsx("circle",{cx:"9",cy:"10",r:"1.6"}),r.jsx("path",{d:"m21 15-4.2-4.2a1.6 1.6 0 0 0-2.3 0L7 18"})]})})}const W="rst:cursor-not-allowed rst:opacity-50",S={width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};function xt({label:n,upload:d,onChange:q,accept:M="image/*",types:B,maxSize:N,maxFiles:x,validate:L,concurrency:w=3,helperText:E,errorMessage:T,disabled:i=!1,strings:Q,className:X}){const c={...gt,...Q},D=o.useId(),I=`${D}-label`,G=`${D}-help`,V=`${D}-error`,[U,Y]=o.useState([]),l=o.useRef(U),Z=o.useRef(0),m=o.useRef(new Map),F=o.useRef(null),_=o.useRef(null),g=o.useRef({upload:d,onChange:q,concurrency:w,t:c,pump:()=>{}}),[z,tt]=o.useState({text:"",n:0}),j=o.useRef([]),v=o.useRef(null),$=o.useCallback((t,s=!1)=>{s&&(j.current=j.current.filter(e=>!e.count)),j.current.push({text:t,count:s}),!v.current&&(v.current=setTimeout(()=>{v.current=null;const e=j.current.map(u=>u.text).join(" ");j.current=[],tt(u=>({text:e,n:u.n+1}))},0))},[]),O=o.useRef(null),[et,rt]=o.useState(0),J=t=>{O.current=t,rt(s=>s+1)};o.useLayoutEffect(()=>{const t=O.current;if(!t)return;O.current=null,(F.current?.querySelector(t)??F.current?.querySelector("[data-file-choose]"))?.focus()},[et]);const y=o.useCallback(t=>{l.current=t,Y(t),g.current.onChange?.(t)},[]),b=o.useCallback((t,s)=>{l.current.some(e=>e.id===t)&&y(l.current.map(e=>e.id===t?{...e,...s}:e))},[y]);function k(){const{concurrency:t}=g.current,s=l.current.filter(u=>u.status==="uploading"||u.status==="processing").length,e=l.current.filter(u=>u.status==="queued").slice(0,Math.max(0,Math.max(1,t)-s));for(const u of e)st(u)}function st(t){const s=new AbortController;m.current.set(t.id,s),b(t.id,{status:"uploading",progress:null,reason:void 0});const e=()=>!s.signal.aborted&&m.current.get(t.id)===s,u={onProgress:a=>{if(!e())return;const f=Math.round(Math.min(1,Math.max(0,Number.isFinite(a)?a:0))*100)/100,h=l.current.find(ft=>ft.id===t.id);h?.status==="uploading"&&h.progress!==f&&b(t.id,{progress:f})},onProcessing:()=>{e()&&b(t.id,{status:"processing"})},signal:s.signal};new Promise(a=>a(g.current.upload(t.file,u))).then(a=>{if(!e())return;m.current.delete(t.id),b(t.id,{status:"done",progress:1,result:a});const f=l.current.filter(h=>h.status!=="rejected");$(g.current.t.progress(f.filter(h=>h.status==="done").length,f.length),!0),k()},a=>{if(!e())return;m.current.delete(t.id);const f=g.current.t.uploadError(a);b(t.id,{status:"failed",reason:f}),$(g.current.t.failedNotice(t.file.name,f)),k()})}o.useLayoutEffect(()=>{g.current={upload:d,onChange:q,concurrency:w,t:c,pump:k}}),o.useEffect(()=>{const t=m.current;return l.current.some(e=>(e.status==="uploading"||e.status==="processing")&&!t.has(e.id))&&(y(l.current.map(e=>(e.status==="uploading"||e.status==="processing")&&!t.has(e.id)?{...e,status:"queued",progress:null}:e)),g.current.pump()),()=>{for(const e of t.values())e.abort();t.clear(),v.current&&clearTimeout(v.current),v.current=null,j.current=[]}},[y]);const nt=B??R.acceptList(M),at=(t,s)=>{if(s.some(u=>R.sameFile(u.file,t)))return c.duplicate(t);const e=L?.(t);if(e)return e;if(!R.matchesType(t,nt))return c.wrongType(t);if(N!==void 0&&t.size>N)return c.tooLarge(t,N);if(x!==void 0&&s.length>=x)return c.tooMany(x)},K=t=>{if(i||t.length===0)return;const s=l.current.filter(a=>a.status!=="rejected"),e=[];for(const a of t){const f=at(a,[...s,...e.filter(h=>h.status!=="rejected")]);e.push({id:`${D}-file-${Z.current++}`,file:a,status:f?"rejected":"queued",progress:null,reason:f})}y([...l.current,...e]);const u=e.filter(a=>a.status==="queued").length;u&&$(c.added(u));for(const a of e)a.reason&&$(c.rejectedNotice(a.file.name,a.reason));k()},ot=t=>{if(i)return;const s=l.current,e=s.findIndex(a=>a.id===t);if(e<0)return;m.current.get(t)?.abort(),m.current.delete(t);const u=s[e+1]??s[e-1];y(s.filter(a=>a.id!==t)),$(c.removed(s[e].file.name)),J(u?`[data-file-remove="${u.id}"]`:"[data-file-choose]"),k()},ct=t=>{i||(b(t,{status:"queued",progress:null,reason:void 0}),J(`[data-file-remove="${t}"]`),k())},[ut,P]=o.useState(0),C=t=>Array.from(t.dataTransfer?.types??[]).includes("Files"),it={onDragEnter:t=>{C(t)&&(t.preventDefault(),P(s=>s+1))},onDragOver:t=>{C(t)&&(t.preventDefault(),t.dataTransfer.dropEffect=i?"none":"copy")},onDragLeave:t=>{C(t)&&P(s=>Math.max(0,s-1))},onDrop:t=>{C(t)&&(t.preventDefault(),P(0),K(Array.from(t.dataTransfer.files)))}},A=ut>0&&!i,dt=t=>{switch(t.status){case"queued":return c.queued;case"uploading":return c.uploading(t.progress===null?null:Math.round(t.progress*100));case"processing":return c.processing;case"done":return c.done;case"failed":return`${c.failed} ${t.reason??""}`.trim();case"rejected":return`${c.rejected} ${t.reason??""}`.trim()}},lt=[E?G:null,T?V:null].filter(Boolean).join(" ")||void 0;return r.jsxs("div",{ref:F,role:"group","aria-labelledby":I,className:p.cn("rst:font-ui rst:w-full",X),"data-file-upload":"",children:[r.jsx("p",{id:I,className:p.cn("rst:mb-1.5 rst:text-left rst:text-sm rst:font-medium rst:leading-none rst:text-[var(--roster-control-text)]",i&&"rst:opacity-70"),children:n}),r.jsxs("div",{...it,"data-file-drop":"","data-dragging":A?"":void 0,className:p.cn("rst:flex rst:flex-col rst:items-center rst:justify-center rst:gap-2 rst:rounded-lg rst:border-2 rst:border-dashed rst:px-4 rst:py-6 rst:text-center rst:transition-colors rst:motion-reduce:transition-none",A?"rst:border-primary-500 rst:bg-primary-500/10":T?"rst:border-error-500 rst:dark:border-error-400":"rst:border-gray-300 rst:dark:border-gray-600"),children:[r.jsx(H.Button,{type:"button",variant:"outline",colorScheme:"neutral",size:"lg",className:p.cn("rst:px-5",i&&W),"aria-disabled":i||void 0,"aria-describedby":lt,onClick:()=>_.current?.click(),"data-file-choose":"",startIcon:r.jsx("svg",{...S,"aria-hidden":"true",children:r.jsx("path",{d:"M12 16V4M7 9l5-5 5 5M5 20h14"})}),children:c.choose}),r.jsx("p",{className:"rst:hidden rst:text-xs rst:text-gray-600 rst:pointer-fine:block rst:dark:text-gray-400","data-file-drop-hint":"",children:A?c.dropHere:c.dropHint}),r.jsx("input",{ref:_,type:"file",hidden:!0,tabIndex:-1,accept:M,multiple:x!==1,disabled:i,onChange:t=>{K(Array.from(t.currentTarget.files??[])),t.currentTarget.value=""},"data-file-input":""})]}),E&&r.jsx("p",{id:G,className:"rst:mt-1.5 rst:text-left rst:text-xs rst:text-gray-500 rst:dark:text-gray-400",children:E}),T&&r.jsx("p",{id:V,className:"rst:mt-1.5 rst:text-left rst:text-xs rst:font-medium rst:text-error-600 rst:dark:text-error-400",children:T}),U.length>0&&r.jsx("ul",{className:"rst:mt-3 rst:flex rst:flex-col rst:gap-2","aria-labelledby":I,children:U.map(t=>{const s=t.status==="failed"||t.status==="rejected",e=t.status==="uploading"||t.status==="processing"||t.status==="queued";return r.jsxs("li",{"data-file-item":t.id,"data-status":t.status,className:"rst:flex rst:items-center rst:gap-3 rst:rounded-md rst:border rst:border-[var(--roster-card-border)] rst:p-2",children:[r.jsx(ht,{file:t.file,status:t.status}),r.jsxs("div",{className:"rst:min-w-0 rst:flex-1 rst:text-left",children:[r.jsx("p",{className:"rst:truncate rst:text-sm rst:font-medium rst:text-[var(--roster-control-text)]",title:t.file.name,children:t.file.name}),r.jsxs("p",{className:p.cn("rst:mt-0.5 rst:flex rst:items-start rst:gap-1 rst:text-xs",s?"rst:text-error-600 rst:dark:text-error-400":"rst:text-gray-600 rst:dark:text-gray-400"),"data-file-status":"",children:[t.status==="done"&&r.jsx("svg",{...S,width:14,height:14,"aria-hidden":"true",className:"rst:mt-px rst:shrink-0 rst:text-success-600 rst:dark:text-success-400",children:r.jsx("path",{d:"M20 6 9 17l-5-5"})}),r.jsxs("span",{children:[r.jsx("span",{className:"rst:tabular-nums",children:c.size(t.file.size)}),r.jsx("span",{"aria-hidden":"true",children:" · "}),dt(t)]})]}),e&&r.jsx("div",{className:"rst:mt-1.5","data-file-progress":"",children:r.jsx(pt.Progress,{size:"sm",value:t.status==="processing"?100:t.status==="uploading"?(t.progress??0)*100:0,busy:t.status==="processing"||t.status==="uploading"&&t.progress===null,announce:!1})})]}),t.status==="failed"&&r.jsx(H.Button,{type:"button",variant:"ghost",colorScheme:"neutral",size:"icon",className:p.cn("rst:h-11 rst:w-11",i&&W),"aria-disabled":i||void 0,"aria-label":c.retry(t.file.name),onClick:()=>ct(t.id),"data-file-retry":t.id,children:r.jsxs("svg",{...S,"aria-hidden":"true",children:[r.jsx("path",{d:"M3 12a9 9 0 1 0 3-6.7L3 8"}),r.jsx("path",{d:"M3 3v5h5"})]})}),r.jsx(H.Button,{type:"button",variant:"ghost",colorScheme:"neutral",size:"icon",className:p.cn("rst:h-11 rst:w-11",i&&W),"aria-disabled":i||void 0,"aria-label":c.remove(t.file.name),onClick:()=>ot(t.id),"data-file-remove":t.id,children:r.jsx("svg",{...S,"aria-hidden":"true",children:r.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]},t.id)})}),r.jsxs("div",{role:"status","aria-live":"polite","aria-atomic":"true",className:"rst:sr-only","data-file-live":"","data-file-live-n":z.n,children:[z.text,z.n%2?" ":""]})]})}exports.FileUpload=xt;