@pixpilot/shadcn 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/rolldown_runtime.cjs +25 -1
- package/dist/components/index.cjs +30 -1
- package/dist/components/index.js +30 -1
- package/dist/components/ui/OrContinueWithSeparator.cjs +30 -1
- package/dist/components/ui/OrContinueWithSeparator.js +27 -1
- package/dist/components/ui/alert-dialog.cjs +101 -1
- package/dist/components/ui/alert-dialog.js +87 -1
- package/dist/components/ui/alert.cjs +45 -1
- package/dist/components/ui/alert.d.cts +4 -4
- package/dist/components/ui/alert.js +39 -1
- package/dist/components/ui/avatar.cjs +37 -1
- package/dist/components/ui/avatar.js +31 -1
- package/dist/components/ui/badge.cjs +33 -1
- package/dist/components/ui/badge.js +27 -1
- package/dist/components/ui/button.cjs +52 -1
- package/dist/components/ui/button.js +46 -1
- package/dist/components/ui/calendar.cjs +113 -1
- package/dist/components/ui/calendar.js +107 -1
- package/dist/components/ui/card.cjs +67 -1
- package/dist/components/ui/card.js +58 -1
- package/dist/components/ui/checkbox.cjs +31 -1
- package/dist/components/ui/checkbox.js +26 -1
- package/dist/components/ui/command.cjs +104 -1
- package/dist/components/ui/command.js +91 -1
- package/dist/components/ui/dialog.cjs +102 -1
- package/dist/components/ui/dialog.js +88 -1
- package/dist/components/ui/dropdown-menu.cjs +144 -1
- package/dist/components/ui/dropdown-menu.js +125 -1
- package/dist/components/ui/file-upload.cjs +926 -1
- package/dist/components/ui/file-upload.js +910 -1
- package/dist/components/ui/form.cjs +101 -1
- package/dist/components/ui/form.js +89 -1
- package/dist/components/ui/index.cjs +29 -1
- package/dist/components/ui/index.js +29 -1
- package/dist/components/ui/input.cjs +20 -1
- package/dist/components/ui/input.js +17 -1
- package/dist/components/ui/label.cjs +21 -1
- package/dist/components/ui/label.js +17 -1
- package/dist/components/ui/pagination.cjs +92 -1
- package/dist/components/ui/pagination.js +82 -1
- package/dist/components/ui/popover.cjs +44 -1
- package/dist/components/ui/popover.js +37 -1
- package/dist/components/ui/radio-group.cjs +36 -1
- package/dist/components/ui/radio-group.js +30 -1
- package/dist/components/ui/select.cjs +116 -1
- package/dist/components/ui/select.js +102 -1
- package/dist/components/ui/separator.cjs +23 -1
- package/dist/components/ui/separator.js +19 -1
- package/dist/components/ui/shadcn-io/tags/index.cjs +146 -1
- package/dist/components/ui/shadcn-io/tags/index.js +134 -1
- package/dist/components/ui/shadcn-io/tags-input-inline/index.cjs +66 -1
- package/dist/components/ui/shadcn-io/tags-input-inline/index.js +57 -1
- package/dist/components/ui/sheet.cjs +96 -1
- package/dist/components/ui/sheet.js +84 -1
- package/dist/components/ui/slider.cjs +42 -1
- package/dist/components/ui/slider.js +38 -1
- package/dist/components/ui/switch.cjs +28 -1
- package/dist/components/ui/switch.js +24 -1
- package/dist/components/ui/tabs.cjs +45 -1
- package/dist/components/ui/tabs.js +38 -1
- package/dist/components/ui/textarea.cjs +19 -1
- package/dist/components/ui/textarea.js +16 -1
- package/dist/components/ui/tooltip.cjs +45 -1
- package/dist/components/ui/tooltip.d.cts +5 -5
- package/dist/components/ui/tooltip.js +38 -1
- package/dist/index.cjs +189 -1
- package/dist/index.js +34 -1
- package/dist/lib/index.cjs +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/utils.cjs +13 -1
- package/dist/lib/utils.js +10 -1
- package/package.json +1 -1
|
@@ -1 +1,926 @@
|
|
|
1
|
-
"use client";const e=require(`../../_virtual/rolldown_runtime.cjs`),t=require(`../../lib/utils.cjs`);require(`../../lib/index.cjs`);let n=require(`react`);n=e.__toESM(n);let r=require(`react/jsx-runtime`);r=e.__toESM(r);let i=require(`@radix-ui/react-slot`);i=e.__toESM(i);let a=require(`lucide-react`);a=e.__toESM(a);let o=require(`@radix-ui/react-direction`);o=e.__toESM(o);const s=`FileUpload`,c=`FileUploadDropzone`,l=`FileUploadTrigger`,u=`FileUploadList`,d=`FileUploadItem`,f=`FileUploadItemPreview`,p=`FileUploadItemMetadata`,m=`FileUploadItemProgress`,h=`FileUploadItemDelete`,g=`FileUploadClear`;function _(e){let t=n.useRef(null);return t.current===null&&(t.current=e()),t}function v(e,t,n,r,i){let a={files:t,dragOver:!1,invalid:r};function o(e,r){switch(r.type){case`ADD_FILES`:for(let e of r.files)t.set(e,{file:e,progress:0,status:`idle`});return i&&i(Array.from(t.values()).map(e=>e.file)),{...e,files:t};case`SET_FILES`:{let n=new Set(r.files);for(let e of t.keys())n.has(e)||t.delete(e);for(let e of r.files)t.get(e)||t.set(e,{file:e,progress:0,status:`idle`});return{...e,files:t}}case`SET_PROGRESS`:{let n=t.get(r.file);return n&&t.set(r.file,{...n,progress:r.progress,status:`uploading`}),{...e,files:t}}case`SET_SUCCESS`:{let n=t.get(r.file);return n&&t.set(r.file,{...n,progress:100,status:`success`}),{...e,files:t}}case`SET_ERROR`:{let n=t.get(r.file);return n&&t.set(r.file,{...n,error:r.error,status:`error`}),{...e,files:t}}case`REMOVE_FILE`:if(n){let e=n.get(r.file);e&&(URL.revokeObjectURL(e),n.delete(r.file))}return t.delete(r.file),i&&i(Array.from(t.values()).map(e=>e.file)),{...e,files:t};case`SET_DRAG_OVER`:return{...e,dragOver:r.dragOver};case`SET_INVALID`:return{...e,invalid:r.invalid};case`CLEAR`:if(n)for(let e of t.keys()){let t=n.get(e);t&&(URL.revokeObjectURL(t),n.delete(e))}return t.clear(),i&&i([]),{...e,files:t,invalid:!1};default:return e}}function s(){return a}function c(t){a=o(a,t);for(let t of e)t()}function l(t){return e.add(t),()=>e.delete(t)}return{getState:s,dispatch:c,subscribe:l}}const y=n.createContext(null);function b(e){let t=n.use(y);if(!t)throw Error(`\`${e}\` must be used within \`${s}\``);return t}function x(e){let t=b(`useStore`),r=_(()=>null),i=n.useCallback(()=>{let n=t.getState(),i=r.current;if(i&&i.state===n)return i.value;let a=e(n);return r.current={value:a,state:n},a},[t,e,r]);return n.useSyncExternalStore(t.subscribe,i,i)}const S=n.createContext(null);function C(e){let t=n.use(S);if(!t)throw Error(`\`${e}\` must be used within \`${s}\``);return t}function w(e){let{value:a,defaultValue:s,onValueChange:c,onAccept:l,onFileAccept:u,onFileReject:d,onFilesReject:f,onFileValidate:p,onUpload:m,accept:h,maxFiles:g,maxSize:b,dir:x,label:C,name:w,asChild:T,disabled:E=!1,invalid:D=!1,multiple:O=!1,required:k=!1,children:A,className:j,...M}=e,N=n.useId(),P=n.useId(),F=n.useId(),I=n.useId(),L=(0,o.useDirection)(x),R=_(()=>new Set).current,z=_(()=>new Map).current,B=_(()=>new WeakMap).current,V=n.useRef(null),H=a!==void 0,U=n.useMemo(()=>v(R,z,B,D,c),[R,z,D,c,B]),W=n.useMemo(()=>h?.split(`,`).map(e=>e.trim())??null,[h]),G=_(()=>{let e=0;return(t,n)=>{e||=requestAnimationFrame(()=>{e=0,U.dispatch({type:`SET_PROGRESS`,file:t,progress:Math.min(Math.max(0,n),100)})})}}).current;n.useEffect(()=>{H?U.dispatch({type:`SET_FILES`,files:a}):s&&s.length>0&&!U.getState().files.size&&U.dispatch({type:`SET_FILES`,files:s})},[a,s,H,U]),n.useEffect(()=>()=>{for(let e of z.keys()){let t=B.get(e);t&&URL.revokeObjectURL(t)}},[z,B]);let K=n.useCallback(async e=>{try{for(let t of e)U.dispatch({type:`SET_PROGRESS`,file:t,progress:0});if(m)await m(e,{onProgress:G,onSuccess:e=>{U.dispatch({type:`SET_SUCCESS`,file:e})},onError:(e,t)=>{U.dispatch({type:`SET_ERROR`,file:e,error:t.message??`Upload failed`})}});else for(let t of e)U.dispatch({type:`SET_SUCCESS`,file:t})}catch(t){let n=t instanceof Error?t.message:`Upload failed`;for(let t of e)U.dispatch({type:`SET_ERROR`,file:t,error:n})}},[U,m,G]),q=n.useCallback(e=>{if(E)return;let t=[...e],n=!1,r=[];if(g){let e=U.getState().files.size,i=Math.max(0,g-e);if(i<t.length){let e=t.slice(i);n=!0,t=t.slice(0,i);for(let t of e){let e=`Maximum ${g} files allowed`;if(p){let n=p(t);n&&(e=n)}d?.(t,e),r.push({file:t,message:e})}}}let i=[],a=[];for(let e of t){let t=!1,r=``;if(p){let i=p(e);if(i){r=i,d?.(e,r),t=!0,n=!0;continue}}if(W){let i=e.type,a=`.${e.name.split(`.`).pop()}`;W.some(e=>e===i||e===a||e.includes(`/*`)&&i.startsWith(e.replace(`/*`,`/`)))||(r=`File type not accepted`,d?.(e,r),t=!0,n=!0)}b&&e.size>b&&(r=`File too large`,d?.(e,r),t=!0,n=!0),t?a.push({file:e,message:r}):i.push(e)}if(r.push(...a),n&&(U.dispatch({type:`SET_INVALID`,invalid:n}),setTimeout(()=>{U.dispatch({type:`SET_INVALID`,invalid:!1})},2e3)),r.length>0&&f?.(r),i.length>0){U.dispatch({type:`ADD_FILES`,files:i}),H&&c&&c([...Array.from(U.getState().files.values()).map(e=>e.file)]),l&&l(i);for(let e of i)u?.(e);m&&requestAnimationFrame(()=>{K(i)})}},[U,H,c,l,u,m,K,g,p,d,f,W,b,E]),J=n.useCallback(e=>{q(Array.from(e.target.files??[])),e.target.value=``},[q]),Y=n.useMemo(()=>({dropzoneId:P,inputId:N,listId:F,labelId:I,dir:L,disabled:E,inputRef:V,urlCache:B}),[P,N,F,I,L,E,B]),X=T?i.Slot:`div`;return(0,r.jsx)(y.Provider,{value:U,children:(0,r.jsx)(S.Provider,{value:Y,children:(0,r.jsxs)(X,{"data-disabled":E?``:void 0,"data-slot":`file-upload`,dir:L,...M,className:t.cn(`relative flex flex-col gap-2`,j),children:[A,(0,r.jsx)(`input`,{type:`file`,id:N,"aria-labelledby":I,"aria-describedby":P,ref:V,tabIndex:-1,accept:h,name:w,className:`sr-only`,disabled:E,multiple:O,required:k,onChange:J}),(0,r.jsx)(`span`,{id:I,className:`sr-only`,children:C??`File upload`})]})})})}function T(e){let{asChild:a,className:o,onClick:s,onDragOver:l,onDragEnter:u,onDragLeave:d,onDrop:f,onPaste:p,onKeyDown:m,...h}=e,g=C(c),_=b(c),v=x(e=>e.dragOver),y=x(e=>e.invalid),S=n.useCallback(e=>{if(s?.(e),e.defaultPrevented)return;let{target:t}=e;t instanceof HTMLElement&&t.closest(`[data-slot="file-upload-trigger"]`)||g.inputRef.current?.click()},[g.inputRef,s]),w=n.useCallback(e=>{l?.(e),!e.defaultPrevented&&(e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!0}))},[_,l]),T=n.useCallback(e=>{u?.(e),!e.defaultPrevented&&(e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!0}))},[_,u]),E=n.useCallback(e=>{if(d?.(e),e.defaultPrevented)return;let{relatedTarget:t}=e;t&&t instanceof Node&&e.currentTarget.contains(t)||(e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!1}))},[_,d]),D=n.useCallback(e=>{if(f?.(e),e.defaultPrevented)return;e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!1});let t=Array.from(e.dataTransfer.files),n=g.inputRef.current;if(!n)return;let r=new DataTransfer;for(let e of t)r.items.add(e);n.files=r.files,n.dispatchEvent(new Event(`change`,{bubbles:!0}))},[_,g.inputRef,f]),O=n.useCallback(e=>{if(p?.(e),e.defaultPrevented)return;e.preventDefault(),_.dispatch({type:`SET_DRAG_OVER`,dragOver:!1});let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e=0;e<t.length;e++){let r=t[e];if(r?.kind===`file`){let e=r.getAsFile();e&&n.push(e)}}if(n.length===0)return;let r=g.inputRef.current;if(!r)return;let i=new DataTransfer;for(let e of n)i.items.add(e);r.files=i.files,r.dispatchEvent(new Event(`change`,{bubbles:!0}))},[_,g.inputRef,p]),k=n.useCallback(e=>{m?.(e),!e.defaultPrevented&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),g.inputRef.current?.click())},[g.inputRef,m]);return(0,r.jsx)(a?i.Slot:`div`,{role:`region`,id:g.dropzoneId,"aria-controls":`${g.inputId} ${g.listId}`,"aria-disabled":g.disabled,"aria-invalid":y,"data-disabled":g.disabled?``:void 0,"data-dragging":v?``:void 0,"data-invalid":y?``:void 0,"data-slot":`file-upload-dropzone`,dir:g.dir,tabIndex:g.disabled?void 0:0,...h,className:t.cn(`relative flex select-none flex-col items-center justify-center gap-2 rounded-lg border-2 border-dashed p-6 outline-none transition-colors hover:bg-accent/30 focus-visible:border-ring/50 data-disabled:pointer-events-none data-dragging:border-primary/30 data-invalid:border-destructive data-dragging:bg-accent/30 data-invalid:ring-destructive/20`,o),onClick:S,onDragEnter:T,onDragLeave:E,onDragOver:w,onDrop:D,onKeyDown:k,onPaste:O})}function E(e){let{asChild:t,onClick:a,...o}=e,s=C(`FileUploadTrigger`),c=n.useCallback(e=>{a?.(e),!e.defaultPrevented&&s.inputRef.current?.click()},[s.inputRef,a]);return(0,r.jsx)(t?i.Slot:`button`,{type:`button`,"aria-controls":s.inputId,"data-disabled":s.disabled?``:void 0,"data-slot":`file-upload-trigger`,...o,disabled:s.disabled,onClick:c})}function D(e){let{className:n,orientation:a=`vertical`,asChild:o,forceMount:s,...c}=e,l=C(`FileUploadList`),u=x(e=>e.files.size),d=s||u>0;return d?(0,r.jsx)(o?i.Slot:`div`,{role:`list`,id:l.listId,"aria-orientation":a,"data-orientation":a,"data-slot":`file-upload-list`,"data-state":d?`active`:`inactive`,dir:l.dir,...c,className:t.cn(`data-[state=inactive]:fade-out-0 data-[state=active]:fade-in-0 data-[state=inactive]:slide-out-to-top-2 data-[state=active]:slide-in-from-top-2 flex flex-col gap-2 data-[state=active]:animate-in data-[state=inactive]:animate-out`,a===`horizontal`&&`flex-row overflow-x-auto p-1.5`,n)}):null}const O=n.createContext(null);function k(e){let t=n.use(O);if(!t)throw Error(`\`${e}\` must be used within \`${d}\``);return t}function A(e){let{value:a,asChild:o,className:s,...c}=e,l=n.useId(),u=`${l}-status`,f=`${l}-name`,p=`${l}-size`,m=`${l}-message`,h=C(d),g=x(e=>e.files.get(a)),_=x(e=>e.files.size),v=x(e=>Array.from(e.files.keys()).indexOf(a)+1),y=n.useMemo(()=>({id:l,fileState:g,nameId:f,sizeId:p,statusId:u,messageId:m}),[l,g,u,f,p,m]);if(!g)return null;let b=g.error?`Error: ${g.error}`:g.status===`uploading`?`Uploading: ${g.progress}% complete`:g.status===`success`?`Upload complete`:`Ready to upload`,S=o?i.Slot:`div`;return(0,r.jsx)(O.Provider,{value:y,children:(0,r.jsxs)(S,{role:`listitem`,id:l,"aria-setsize":_,"aria-posinset":v,"aria-describedby":`${f} ${p} ${u} ${g.error?m:``}`,"aria-labelledby":f,"data-slot":`file-upload-item`,dir:h.dir,...c,className:t.cn(`relative flex items-center rounded-md border p-3`,s),children:[e.children,(0,r.jsx)(`span`,{id:u,className:`sr-only`,children:b})]})})}function j(e){if(e===0)return`0 B`;let t=[`B`,`KB`,`MB`,`GB`,`TB`],n=Math.floor(Math.log(e)/Math.log(1024));return`${(e/1024**n).toFixed(n?1:0)} ${t[n]}`}function M(e){let{type:t}=e,n=e.name.split(`.`).pop()?.toLowerCase()??``;return t.startsWith(`video/`)?(0,r.jsx)(a.FileVideoIcon,{}):t.startsWith(`audio/`)?(0,r.jsx)(a.FileAudioIcon,{}):t.startsWith(`text/`)||[`txt`,`md`,`rtf`,`pdf`].includes(n)?(0,r.jsx)(a.FileTextIcon,{}):[`html`,`css`,`js`,`jsx`,`ts`,`tsx`,`json`,`xml`,`php`,`py`,`rb`,`java`,`c`,`cpp`,`cs`].includes(n)?(0,r.jsx)(a.FileCodeIcon,{}):[`zip`,`rar`,`7z`,`tar`,`gz`,`bz2`].includes(n)?(0,r.jsx)(a.FileArchiveIcon,{}):[`exe`,`msi`,`app`,`apk`,`deb`,`rpm`].includes(n)||t.startsWith(`application/`)?(0,r.jsx)(a.FileCogIcon,{}):(0,r.jsx)(a.FileIcon,{})}function N(e){let{render:a,asChild:o,children:s,className:c,...l}=e,u=k(f),d=C(f),p=n.useCallback(e=>{if(u.fileState?.file.type.startsWith(`image/`)){let t=d.urlCache.get(e);return t||(t=URL.createObjectURL(e),d.urlCache.set(e,t)),(0,r.jsx)(`img`,{src:t,alt:e.name,className:`size-full object-cover`})}return M(e)},[u.fileState?.file.type,d.urlCache]),m=n.useCallback(e=>a?a(e,()=>p(e)):p(e),[a,p]);return u.fileState?(0,r.jsxs)(o?i.Slot:`div`,{"aria-labelledby":u.nameId,"data-slot":`file-upload-preview`,...l,className:t.cn(`relative flex size-10 shrink-0 items-center justify-center overflow-hidden rounded border bg-accent/50 [&>svg]:size-10`,c),children:[m(u.fileState.file),s]}):null}function P(e){let{asChild:n,size:a=`default`,children:o,className:s,...c}=e,l=C(p),u=k(p);return u.fileState?(0,r.jsx)(n?i.Slot:`div`,{"data-slot":`file-upload-metadata`,dir:l.dir,...c,className:t.cn(`flex min-w-0 flex-1 flex-col`,s),children:o??(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(`span`,{id:u.nameId,className:t.cn(`truncate font-medium text-sm`,a===`sm`&&`font-normal text-[13px] leading-snug`),children:u.fileState.file.name}),(0,r.jsx)(`span`,{id:u.sizeId,className:t.cn(`truncate text-muted-foreground text-xs`,a===`sm`&&`text-[11px] leading-snug`),children:j(u.fileState.file.size)}),u.fileState.error&&(0,r.jsx)(`span`,{id:u.messageId,className:`text-destructive text-xs`,children:u.fileState.error})]})}):null}function F(e){let{variant:n=`linear`,size:a=40,strokeWidth:o=2,asChild:s,forceMount:c,className:l,...u}=e,d=k(`FileUploadItemProgress`);if(!d.fileState||!(c||d.fileState.progress!==100))return null;let f=s?i.Slot:`div`;switch(n){case`circular`:{let e=2*Math.PI*((a-4)/2),n=e-d.fileState.progress/100*e;return(0,r.jsx)(f,{role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":d.fileState.progress,"aria-valuetext":`${d.fileState.progress}%`,"aria-labelledby":d.nameId,"data-slot":`file-upload-progress`,...u,className:t.cn(`-translate-x-1/2 -translate-y-1/2 absolute top-1/2 left-1/2`,l),children:(0,r.jsxs)(`svg`,{className:`-rotate-90 transform`,width:a,height:a,viewBox:`0 0 ${a} ${a}`,fill:`none`,stroke:`currentColor`,children:[(0,r.jsx)(`circle`,{className:`text-primary/20`,strokeWidth:o,cx:a/2,cy:a/2,r:(a-4)/2}),(0,r.jsx)(`circle`,{className:`text-primary transition-[stroke-dashoffset] duration-300 ease-linear`,strokeWidth:o,strokeLinecap:`round`,strokeDasharray:e,strokeDashoffset:n,cx:a/2,cy:a/2,r:(a-4)/2})]})})}case`fill`:{let e=d.fileState.progress,n=100-e;return(0,r.jsx)(f,{role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":e,"aria-valuetext":`${e}%`,"aria-labelledby":d.nameId,"data-slot":`file-upload-progress`,...u,className:t.cn(`absolute inset-0 bg-primary/50 transition-[clip-path] duration-300 ease-linear`,l),style:{clipPath:`inset(${n}% 0% 0% 0%)`}})}default:return(0,r.jsx)(f,{role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":d.fileState.progress,"aria-valuetext":`${d.fileState.progress}%`,"aria-labelledby":d.nameId,"data-slot":`file-upload-progress`,...u,className:t.cn(`relative h-1.5 w-full overflow-hidden rounded-full bg-primary/20`,l),children:(0,r.jsx)(`div`,{className:`h-full w-full flex-1 bg-primary transition-transform duration-300 ease-linear`,style:{transform:`translateX(-${100-d.fileState.progress}%)`}})})}}function I(e){let{asChild:t,onClick:a,...o}=e,s=b(h),c=k(h),l=n.useCallback(e=>{a?.(e),!(!c.fileState||e.defaultPrevented)&&s.dispatch({type:`REMOVE_FILE`,file:c.fileState.file})},[s,c.fileState,a]);return c.fileState?(0,r.jsx)(t?i.Slot:`button`,{type:`button`,"aria-controls":c.id,"aria-describedby":c.nameId,"data-slot":`file-upload-item-delete`,...o,onClick:l}):null}function L(e){let{asChild:t,forceMount:a,disabled:o,onClick:s,...c}=e,l=C(g),u=b(g),d=x(e=>e.files.size),f=o||l.disabled,p=n.useCallback(e=>{s?.(e),!e.defaultPrevented&&u.dispatch({type:`CLEAR`})},[u,s]);return a||d>0?(0,r.jsx)(t?i.Slot:`button`,{type:`button`,"aria-controls":l.listId,"data-slot":`file-upload-clear`,"data-disabled":f?``:void 0,...c,disabled:f,onClick:p}):null}exports.FileUploadClear=L,exports.FileUploadDropzone=T,exports.FileUploadItem=A,exports.FileUploadItemDelete=I,exports.FileUploadItemMetadata=P,exports.FileUploadItemPreview=N,exports.FileUploadItemProgress=F,exports.FileUploadList=D,exports.FileUploadRoot=w,exports.FileUploadTrigger=E,exports.useStore=x;
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
5
|
+
const require_utils = require('../../lib/utils.cjs');
|
|
6
|
+
require('../../lib/index.cjs');
|
|
7
|
+
let react = require("react");
|
|
8
|
+
react = require_rolldown_runtime.__toESM(react);
|
|
9
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
|
+
react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
|
|
11
|
+
let __radix_ui_react_slot = require("@radix-ui/react-slot");
|
|
12
|
+
__radix_ui_react_slot = require_rolldown_runtime.__toESM(__radix_ui_react_slot);
|
|
13
|
+
let lucide_react = require("lucide-react");
|
|
14
|
+
lucide_react = require_rolldown_runtime.__toESM(lucide_react);
|
|
15
|
+
let __radix_ui_react_direction = require("@radix-ui/react-direction");
|
|
16
|
+
__radix_ui_react_direction = require_rolldown_runtime.__toESM(__radix_ui_react_direction);
|
|
17
|
+
|
|
18
|
+
//#region src/components/ui/file-upload.tsx
|
|
19
|
+
const ROOT_NAME = "FileUpload";
|
|
20
|
+
const DROPZONE_NAME = "FileUploadDropzone";
|
|
21
|
+
const TRIGGER_NAME = "FileUploadTrigger";
|
|
22
|
+
const LIST_NAME = "FileUploadList";
|
|
23
|
+
const ITEM_NAME = "FileUploadItem";
|
|
24
|
+
const ITEM_PREVIEW_NAME = "FileUploadItemPreview";
|
|
25
|
+
const ITEM_METADATA_NAME = "FileUploadItemMetadata";
|
|
26
|
+
const ITEM_PROGRESS_NAME = "FileUploadItemProgress";
|
|
27
|
+
const ITEM_DELETE_NAME = "FileUploadItemDelete";
|
|
28
|
+
const CLEAR_NAME = "FileUploadClear";
|
|
29
|
+
function useLazyRef(fn) {
|
|
30
|
+
const ref = react.useRef(null);
|
|
31
|
+
if (ref.current === null) ref.current = fn();
|
|
32
|
+
return ref;
|
|
33
|
+
}
|
|
34
|
+
function createStore(listeners, files, urlCache, invalid, onValueChange) {
|
|
35
|
+
let state = {
|
|
36
|
+
files,
|
|
37
|
+
dragOver: false,
|
|
38
|
+
invalid
|
|
39
|
+
};
|
|
40
|
+
function reducer(state$1, action) {
|
|
41
|
+
switch (action.type) {
|
|
42
|
+
case "ADD_FILES":
|
|
43
|
+
for (const file of action.files) files.set(file, {
|
|
44
|
+
file,
|
|
45
|
+
progress: 0,
|
|
46
|
+
status: "idle"
|
|
47
|
+
});
|
|
48
|
+
if (onValueChange) onValueChange(Array.from(files.values()).map((fileState) => fileState.file));
|
|
49
|
+
return {
|
|
50
|
+
...state$1,
|
|
51
|
+
files
|
|
52
|
+
};
|
|
53
|
+
case "SET_FILES": {
|
|
54
|
+
const newFileSet = new Set(action.files);
|
|
55
|
+
for (const existingFile of files.keys()) if (!newFileSet.has(existingFile)) files.delete(existingFile);
|
|
56
|
+
for (const file of action.files) if (!files.get(file)) files.set(file, {
|
|
57
|
+
file,
|
|
58
|
+
progress: 0,
|
|
59
|
+
status: "idle"
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
...state$1,
|
|
63
|
+
files
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
case "SET_PROGRESS": {
|
|
67
|
+
const fileState = files.get(action.file);
|
|
68
|
+
if (fileState) files.set(action.file, {
|
|
69
|
+
...fileState,
|
|
70
|
+
progress: action.progress,
|
|
71
|
+
status: "uploading"
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
...state$1,
|
|
75
|
+
files
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
case "SET_SUCCESS": {
|
|
79
|
+
const fileState = files.get(action.file);
|
|
80
|
+
if (fileState) files.set(action.file, {
|
|
81
|
+
...fileState,
|
|
82
|
+
progress: 100,
|
|
83
|
+
status: "success"
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
...state$1,
|
|
87
|
+
files
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
case "SET_ERROR": {
|
|
91
|
+
const fileState = files.get(action.file);
|
|
92
|
+
if (fileState) files.set(action.file, {
|
|
93
|
+
...fileState,
|
|
94
|
+
error: action.error,
|
|
95
|
+
status: "error"
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
...state$1,
|
|
99
|
+
files
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
case "REMOVE_FILE":
|
|
103
|
+
if (urlCache) {
|
|
104
|
+
const cachedUrl = urlCache.get(action.file);
|
|
105
|
+
if (cachedUrl) {
|
|
106
|
+
URL.revokeObjectURL(cachedUrl);
|
|
107
|
+
urlCache.delete(action.file);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
files.delete(action.file);
|
|
111
|
+
if (onValueChange) onValueChange(Array.from(files.values()).map((fileState) => fileState.file));
|
|
112
|
+
return {
|
|
113
|
+
...state$1,
|
|
114
|
+
files
|
|
115
|
+
};
|
|
116
|
+
case "SET_DRAG_OVER": return {
|
|
117
|
+
...state$1,
|
|
118
|
+
dragOver: action.dragOver
|
|
119
|
+
};
|
|
120
|
+
case "SET_INVALID": return {
|
|
121
|
+
...state$1,
|
|
122
|
+
invalid: action.invalid
|
|
123
|
+
};
|
|
124
|
+
case "CLEAR":
|
|
125
|
+
if (urlCache) for (const file of files.keys()) {
|
|
126
|
+
const cachedUrl = urlCache.get(file);
|
|
127
|
+
if (cachedUrl) {
|
|
128
|
+
URL.revokeObjectURL(cachedUrl);
|
|
129
|
+
urlCache.delete(file);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
files.clear();
|
|
133
|
+
if (onValueChange) onValueChange([]);
|
|
134
|
+
return {
|
|
135
|
+
...state$1,
|
|
136
|
+
files,
|
|
137
|
+
invalid: false
|
|
138
|
+
};
|
|
139
|
+
default: return state$1;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function getState() {
|
|
143
|
+
return state;
|
|
144
|
+
}
|
|
145
|
+
function dispatch(action) {
|
|
146
|
+
state = reducer(state, action);
|
|
147
|
+
for (const listener of listeners) listener();
|
|
148
|
+
}
|
|
149
|
+
function subscribe(listener) {
|
|
150
|
+
listeners.add(listener);
|
|
151
|
+
return () => listeners.delete(listener);
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
getState,
|
|
155
|
+
dispatch,
|
|
156
|
+
subscribe
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const StoreContext = react.createContext(null);
|
|
160
|
+
function useStoreContext(consumerName) {
|
|
161
|
+
const context = react.use(StoreContext);
|
|
162
|
+
if (!context) throw new Error(`\`${consumerName}\` must be used within \`${ROOT_NAME}\``);
|
|
163
|
+
return context;
|
|
164
|
+
}
|
|
165
|
+
function useStore(selector) {
|
|
166
|
+
const store = useStoreContext("useStore");
|
|
167
|
+
const lastValueRef = useLazyRef(() => null);
|
|
168
|
+
const getSnapshot = react.useCallback(() => {
|
|
169
|
+
const state = store.getState();
|
|
170
|
+
const prevValue = lastValueRef.current;
|
|
171
|
+
if (prevValue && prevValue.state === state) return prevValue.value;
|
|
172
|
+
const nextValue = selector(state);
|
|
173
|
+
lastValueRef.current = {
|
|
174
|
+
value: nextValue,
|
|
175
|
+
state
|
|
176
|
+
};
|
|
177
|
+
return nextValue;
|
|
178
|
+
}, [
|
|
179
|
+
store,
|
|
180
|
+
selector,
|
|
181
|
+
lastValueRef
|
|
182
|
+
]);
|
|
183
|
+
return react.useSyncExternalStore(store.subscribe, getSnapshot, getSnapshot);
|
|
184
|
+
}
|
|
185
|
+
const FileUploadContext = react.createContext(null);
|
|
186
|
+
function useFileUploadContext(consumerName) {
|
|
187
|
+
const context = react.use(FileUploadContext);
|
|
188
|
+
if (!context) throw new Error(`\`${consumerName}\` must be used within \`${ROOT_NAME}\``);
|
|
189
|
+
return context;
|
|
190
|
+
}
|
|
191
|
+
function FileUploadRoot(props) {
|
|
192
|
+
const { value, defaultValue, onValueChange, onAccept, onFileAccept, onFileReject, onFilesReject, onFileValidate, onUpload, accept, maxFiles, maxSize, dir: dirProp, label, name, asChild, disabled = false, invalid = false, multiple = false, required = false, children, className,...rootProps } = props;
|
|
193
|
+
const inputId = react.useId();
|
|
194
|
+
const dropzoneId = react.useId();
|
|
195
|
+
const listId = react.useId();
|
|
196
|
+
const labelId = react.useId();
|
|
197
|
+
const dir = (0, __radix_ui_react_direction.useDirection)(dirProp);
|
|
198
|
+
const listeners = useLazyRef(() => /* @__PURE__ */ new Set()).current;
|
|
199
|
+
const files = useLazyRef(() => /* @__PURE__ */ new Map()).current;
|
|
200
|
+
const urlCache = useLazyRef(() => /* @__PURE__ */ new WeakMap()).current;
|
|
201
|
+
const inputRef = react.useRef(null);
|
|
202
|
+
const isControlled = value !== void 0;
|
|
203
|
+
const store = react.useMemo(() => createStore(listeners, files, urlCache, invalid, onValueChange), [
|
|
204
|
+
listeners,
|
|
205
|
+
files,
|
|
206
|
+
invalid,
|
|
207
|
+
onValueChange,
|
|
208
|
+
urlCache
|
|
209
|
+
]);
|
|
210
|
+
const acceptTypes = react.useMemo(() => accept?.split(",").map((t) => t.trim()) ?? null, [accept]);
|
|
211
|
+
const onProgress = useLazyRef(() => {
|
|
212
|
+
let frame = 0;
|
|
213
|
+
return (file, progress) => {
|
|
214
|
+
if (frame) return;
|
|
215
|
+
frame = requestAnimationFrame(() => {
|
|
216
|
+
frame = 0;
|
|
217
|
+
store.dispatch({
|
|
218
|
+
type: "SET_PROGRESS",
|
|
219
|
+
file,
|
|
220
|
+
progress: Math.min(Math.max(0, progress), 100)
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
}).current;
|
|
225
|
+
react.useEffect(() => {
|
|
226
|
+
if (isControlled) store.dispatch({
|
|
227
|
+
type: "SET_FILES",
|
|
228
|
+
files: value
|
|
229
|
+
});
|
|
230
|
+
else if (defaultValue && defaultValue.length > 0 && !store.getState().files.size) store.dispatch({
|
|
231
|
+
type: "SET_FILES",
|
|
232
|
+
files: defaultValue
|
|
233
|
+
});
|
|
234
|
+
}, [
|
|
235
|
+
value,
|
|
236
|
+
defaultValue,
|
|
237
|
+
isControlled,
|
|
238
|
+
store
|
|
239
|
+
]);
|
|
240
|
+
react.useEffect(() => {
|
|
241
|
+
return () => {
|
|
242
|
+
for (const file of files.keys()) {
|
|
243
|
+
const cachedUrl = urlCache.get(file);
|
|
244
|
+
if (cachedUrl) URL.revokeObjectURL(cachedUrl);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
}, [files, urlCache]);
|
|
248
|
+
const onFilesUpload = react.useCallback(async (files$1) => {
|
|
249
|
+
try {
|
|
250
|
+
for (const file of files$1) store.dispatch({
|
|
251
|
+
type: "SET_PROGRESS",
|
|
252
|
+
file,
|
|
253
|
+
progress: 0
|
|
254
|
+
});
|
|
255
|
+
if (onUpload) await onUpload(files$1, {
|
|
256
|
+
onProgress,
|
|
257
|
+
onSuccess: (file) => {
|
|
258
|
+
store.dispatch({
|
|
259
|
+
type: "SET_SUCCESS",
|
|
260
|
+
file
|
|
261
|
+
});
|
|
262
|
+
},
|
|
263
|
+
onError: (file, error) => {
|
|
264
|
+
store.dispatch({
|
|
265
|
+
type: "SET_ERROR",
|
|
266
|
+
file,
|
|
267
|
+
error: error.message ?? "Upload failed"
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
else for (const file of files$1) store.dispatch({
|
|
272
|
+
type: "SET_SUCCESS",
|
|
273
|
+
file
|
|
274
|
+
});
|
|
275
|
+
} catch (error) {
|
|
276
|
+
const errorMessage = error instanceof Error ? error.message : "Upload failed";
|
|
277
|
+
for (const file of files$1) store.dispatch({
|
|
278
|
+
type: "SET_ERROR",
|
|
279
|
+
file,
|
|
280
|
+
error: errorMessage
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}, [
|
|
284
|
+
store,
|
|
285
|
+
onUpload,
|
|
286
|
+
onProgress
|
|
287
|
+
]);
|
|
288
|
+
const onFilesChange = react.useCallback((originalFiles) => {
|
|
289
|
+
if (disabled) return;
|
|
290
|
+
let filesToProcess = [...originalFiles];
|
|
291
|
+
let invalid$1 = false;
|
|
292
|
+
const allRejectedFiles = [];
|
|
293
|
+
if (maxFiles) {
|
|
294
|
+
const currentCount = store.getState().files.size;
|
|
295
|
+
const remainingSlotCount = Math.max(0, maxFiles - currentCount);
|
|
296
|
+
if (remainingSlotCount < filesToProcess.length) {
|
|
297
|
+
const rejectedFromMaxFiles = filesToProcess.slice(remainingSlotCount);
|
|
298
|
+
invalid$1 = true;
|
|
299
|
+
filesToProcess = filesToProcess.slice(0, remainingSlotCount);
|
|
300
|
+
for (const file of rejectedFromMaxFiles) {
|
|
301
|
+
let rejectionMessage = `Maximum ${maxFiles} files allowed`;
|
|
302
|
+
if (onFileValidate) {
|
|
303
|
+
const validationMessage = onFileValidate(file);
|
|
304
|
+
if (validationMessage) rejectionMessage = validationMessage;
|
|
305
|
+
}
|
|
306
|
+
onFileReject?.(file, rejectionMessage);
|
|
307
|
+
allRejectedFiles.push({
|
|
308
|
+
file,
|
|
309
|
+
message: rejectionMessage
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const acceptedFiles = [];
|
|
315
|
+
const rejectedFiles = [];
|
|
316
|
+
for (const file of filesToProcess) {
|
|
317
|
+
let rejected = false;
|
|
318
|
+
let rejectionMessage = "";
|
|
319
|
+
if (onFileValidate) {
|
|
320
|
+
const validationMessage = onFileValidate(file);
|
|
321
|
+
if (validationMessage) {
|
|
322
|
+
rejectionMessage = validationMessage;
|
|
323
|
+
onFileReject?.(file, rejectionMessage);
|
|
324
|
+
rejected = true;
|
|
325
|
+
invalid$1 = true;
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (acceptTypes) {
|
|
330
|
+
const fileType = file.type;
|
|
331
|
+
const fileExtension = `.${file.name.split(".").pop()}`;
|
|
332
|
+
if (!acceptTypes.some((type) => type === fileType || type === fileExtension || type.includes("/*") && fileType.startsWith(type.replace("/*", "/")))) {
|
|
333
|
+
rejectionMessage = "File type not accepted";
|
|
334
|
+
onFileReject?.(file, rejectionMessage);
|
|
335
|
+
rejected = true;
|
|
336
|
+
invalid$1 = true;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (maxSize && file.size > maxSize) {
|
|
340
|
+
rejectionMessage = "File too large";
|
|
341
|
+
onFileReject?.(file, rejectionMessage);
|
|
342
|
+
rejected = true;
|
|
343
|
+
invalid$1 = true;
|
|
344
|
+
}
|
|
345
|
+
if (!rejected) acceptedFiles.push(file);
|
|
346
|
+
else rejectedFiles.push({
|
|
347
|
+
file,
|
|
348
|
+
message: rejectionMessage
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
allRejectedFiles.push(...rejectedFiles);
|
|
352
|
+
if (invalid$1) {
|
|
353
|
+
store.dispatch({
|
|
354
|
+
type: "SET_INVALID",
|
|
355
|
+
invalid: invalid$1
|
|
356
|
+
});
|
|
357
|
+
setTimeout(() => {
|
|
358
|
+
store.dispatch({
|
|
359
|
+
type: "SET_INVALID",
|
|
360
|
+
invalid: false
|
|
361
|
+
});
|
|
362
|
+
}, 2e3);
|
|
363
|
+
}
|
|
364
|
+
if (allRejectedFiles.length > 0) onFilesReject?.(allRejectedFiles);
|
|
365
|
+
if (acceptedFiles.length > 0) {
|
|
366
|
+
store.dispatch({
|
|
367
|
+
type: "ADD_FILES",
|
|
368
|
+
files: acceptedFiles
|
|
369
|
+
});
|
|
370
|
+
if (isControlled && onValueChange) onValueChange([...Array.from(store.getState().files.values()).map((f) => f.file)]);
|
|
371
|
+
if (onAccept) onAccept(acceptedFiles);
|
|
372
|
+
for (const file of acceptedFiles) onFileAccept?.(file);
|
|
373
|
+
if (onUpload) requestAnimationFrame(() => {
|
|
374
|
+
onFilesUpload(acceptedFiles);
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
}, [
|
|
378
|
+
store,
|
|
379
|
+
isControlled,
|
|
380
|
+
onValueChange,
|
|
381
|
+
onAccept,
|
|
382
|
+
onFileAccept,
|
|
383
|
+
onUpload,
|
|
384
|
+
onFilesUpload,
|
|
385
|
+
maxFiles,
|
|
386
|
+
onFileValidate,
|
|
387
|
+
onFileReject,
|
|
388
|
+
onFilesReject,
|
|
389
|
+
acceptTypes,
|
|
390
|
+
maxSize,
|
|
391
|
+
disabled
|
|
392
|
+
]);
|
|
393
|
+
const onInputChange = react.useCallback((event) => {
|
|
394
|
+
onFilesChange(Array.from(event.target.files ?? []));
|
|
395
|
+
event.target.value = "";
|
|
396
|
+
}, [onFilesChange]);
|
|
397
|
+
const contextValue = react.useMemo(() => ({
|
|
398
|
+
dropzoneId,
|
|
399
|
+
inputId,
|
|
400
|
+
listId,
|
|
401
|
+
labelId,
|
|
402
|
+
dir,
|
|
403
|
+
disabled,
|
|
404
|
+
inputRef,
|
|
405
|
+
urlCache
|
|
406
|
+
}), [
|
|
407
|
+
dropzoneId,
|
|
408
|
+
inputId,
|
|
409
|
+
listId,
|
|
410
|
+
labelId,
|
|
411
|
+
dir,
|
|
412
|
+
disabled,
|
|
413
|
+
urlCache
|
|
414
|
+
]);
|
|
415
|
+
const RootPrimitive = asChild ? __radix_ui_react_slot.Slot : "div";
|
|
416
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StoreContext.Provider, {
|
|
417
|
+
value: store,
|
|
418
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FileUploadContext.Provider, {
|
|
419
|
+
value: contextValue,
|
|
420
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(RootPrimitive, {
|
|
421
|
+
"data-disabled": disabled ? "" : void 0,
|
|
422
|
+
"data-slot": "file-upload",
|
|
423
|
+
dir,
|
|
424
|
+
...rootProps,
|
|
425
|
+
className: require_utils.cn("relative flex flex-col gap-2", className),
|
|
426
|
+
children: [
|
|
427
|
+
children,
|
|
428
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
429
|
+
type: "file",
|
|
430
|
+
id: inputId,
|
|
431
|
+
"aria-labelledby": labelId,
|
|
432
|
+
"aria-describedby": dropzoneId,
|
|
433
|
+
ref: inputRef,
|
|
434
|
+
tabIndex: -1,
|
|
435
|
+
accept,
|
|
436
|
+
name,
|
|
437
|
+
className: "sr-only",
|
|
438
|
+
disabled,
|
|
439
|
+
multiple,
|
|
440
|
+
required,
|
|
441
|
+
onChange: onInputChange
|
|
442
|
+
}),
|
|
443
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
444
|
+
id: labelId,
|
|
445
|
+
className: "sr-only",
|
|
446
|
+
children: label ?? "File upload"
|
|
447
|
+
})
|
|
448
|
+
]
|
|
449
|
+
})
|
|
450
|
+
})
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
function FileUploadDropzone(props) {
|
|
454
|
+
const { asChild, className, onClick: onClickProp, onDragOver: onDragOverProp, onDragEnter: onDragEnterProp, onDragLeave: onDragLeaveProp, onDrop: onDropProp, onPaste: onPasteProp, onKeyDown: onKeyDownProp,...dropzoneProps } = props;
|
|
455
|
+
const context = useFileUploadContext(DROPZONE_NAME);
|
|
456
|
+
const store = useStoreContext(DROPZONE_NAME);
|
|
457
|
+
const dragOver = useStore((state) => state.dragOver);
|
|
458
|
+
const invalid = useStore((state) => state.invalid);
|
|
459
|
+
const onClick = react.useCallback((event) => {
|
|
460
|
+
onClickProp?.(event);
|
|
461
|
+
if (event.defaultPrevented) return;
|
|
462
|
+
const { target } = event;
|
|
463
|
+
if (!(target instanceof HTMLElement && target.closest("[data-slot=\"file-upload-trigger\"]"))) context.inputRef.current?.click();
|
|
464
|
+
}, [context.inputRef, onClickProp]);
|
|
465
|
+
const onDragOver = react.useCallback((event) => {
|
|
466
|
+
onDragOverProp?.(event);
|
|
467
|
+
if (event.defaultPrevented) return;
|
|
468
|
+
event.preventDefault();
|
|
469
|
+
store.dispatch({
|
|
470
|
+
type: "SET_DRAG_OVER",
|
|
471
|
+
dragOver: true
|
|
472
|
+
});
|
|
473
|
+
}, [store, onDragOverProp]);
|
|
474
|
+
const onDragEnter = react.useCallback((event) => {
|
|
475
|
+
onDragEnterProp?.(event);
|
|
476
|
+
if (event.defaultPrevented) return;
|
|
477
|
+
event.preventDefault();
|
|
478
|
+
store.dispatch({
|
|
479
|
+
type: "SET_DRAG_OVER",
|
|
480
|
+
dragOver: true
|
|
481
|
+
});
|
|
482
|
+
}, [store, onDragEnterProp]);
|
|
483
|
+
const onDragLeave = react.useCallback((event) => {
|
|
484
|
+
onDragLeaveProp?.(event);
|
|
485
|
+
if (event.defaultPrevented) return;
|
|
486
|
+
const { relatedTarget } = event;
|
|
487
|
+
if (relatedTarget && relatedTarget instanceof Node && event.currentTarget.contains(relatedTarget)) return;
|
|
488
|
+
event.preventDefault();
|
|
489
|
+
store.dispatch({
|
|
490
|
+
type: "SET_DRAG_OVER",
|
|
491
|
+
dragOver: false
|
|
492
|
+
});
|
|
493
|
+
}, [store, onDragLeaveProp]);
|
|
494
|
+
const onDrop = react.useCallback((event) => {
|
|
495
|
+
onDropProp?.(event);
|
|
496
|
+
if (event.defaultPrevented) return;
|
|
497
|
+
event.preventDefault();
|
|
498
|
+
store.dispatch({
|
|
499
|
+
type: "SET_DRAG_OVER",
|
|
500
|
+
dragOver: false
|
|
501
|
+
});
|
|
502
|
+
const files = Array.from(event.dataTransfer.files);
|
|
503
|
+
const inputElement = context.inputRef.current;
|
|
504
|
+
if (!inputElement) return;
|
|
505
|
+
const dataTransfer = new DataTransfer();
|
|
506
|
+
for (const file of files) dataTransfer.items.add(file);
|
|
507
|
+
inputElement.files = dataTransfer.files;
|
|
508
|
+
inputElement.dispatchEvent(new Event("change", { bubbles: true }));
|
|
509
|
+
}, [
|
|
510
|
+
store,
|
|
511
|
+
context.inputRef,
|
|
512
|
+
onDropProp
|
|
513
|
+
]);
|
|
514
|
+
const onPaste = react.useCallback((event) => {
|
|
515
|
+
onPasteProp?.(event);
|
|
516
|
+
if (event.defaultPrevented) return;
|
|
517
|
+
event.preventDefault();
|
|
518
|
+
store.dispatch({
|
|
519
|
+
type: "SET_DRAG_OVER",
|
|
520
|
+
dragOver: false
|
|
521
|
+
});
|
|
522
|
+
const items = event.clipboardData?.items;
|
|
523
|
+
if (!items) return;
|
|
524
|
+
const files = [];
|
|
525
|
+
for (let i = 0; i < items.length; i++) {
|
|
526
|
+
const item = items[i];
|
|
527
|
+
if (item?.kind === "file") {
|
|
528
|
+
const file = item.getAsFile();
|
|
529
|
+
if (file) files.push(file);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
if (files.length === 0) return;
|
|
533
|
+
const inputElement = context.inputRef.current;
|
|
534
|
+
if (!inputElement) return;
|
|
535
|
+
const dataTransfer = new DataTransfer();
|
|
536
|
+
for (const file of files) dataTransfer.items.add(file);
|
|
537
|
+
inputElement.files = dataTransfer.files;
|
|
538
|
+
inputElement.dispatchEvent(new Event("change", { bubbles: true }));
|
|
539
|
+
}, [
|
|
540
|
+
store,
|
|
541
|
+
context.inputRef,
|
|
542
|
+
onPasteProp
|
|
543
|
+
]);
|
|
544
|
+
const onKeyDown = react.useCallback((event) => {
|
|
545
|
+
onKeyDownProp?.(event);
|
|
546
|
+
if (!event.defaultPrevented && (event.key === "Enter" || event.key === " ")) {
|
|
547
|
+
event.preventDefault();
|
|
548
|
+
context.inputRef.current?.click();
|
|
549
|
+
}
|
|
550
|
+
}, [context.inputRef, onKeyDownProp]);
|
|
551
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(asChild ? __radix_ui_react_slot.Slot : "div", {
|
|
552
|
+
role: "region",
|
|
553
|
+
id: context.dropzoneId,
|
|
554
|
+
"aria-controls": `${context.inputId} ${context.listId}`,
|
|
555
|
+
"aria-disabled": context.disabled,
|
|
556
|
+
"aria-invalid": invalid,
|
|
557
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
558
|
+
"data-dragging": dragOver ? "" : void 0,
|
|
559
|
+
"data-invalid": invalid ? "" : void 0,
|
|
560
|
+
"data-slot": "file-upload-dropzone",
|
|
561
|
+
dir: context.dir,
|
|
562
|
+
tabIndex: context.disabled ? void 0 : 0,
|
|
563
|
+
...dropzoneProps,
|
|
564
|
+
className: require_utils.cn("relative flex select-none flex-col items-center justify-center gap-2 rounded-lg border-2 border-dashed p-6 outline-none transition-colors hover:bg-accent/30 focus-visible:border-ring/50 data-disabled:pointer-events-none data-dragging:border-primary/30 data-invalid:border-destructive data-dragging:bg-accent/30 data-invalid:ring-destructive/20", className),
|
|
565
|
+
onClick,
|
|
566
|
+
onDragEnter,
|
|
567
|
+
onDragLeave,
|
|
568
|
+
onDragOver,
|
|
569
|
+
onDrop,
|
|
570
|
+
onKeyDown,
|
|
571
|
+
onPaste
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
function FileUploadTrigger(props) {
|
|
575
|
+
const { asChild, onClick: onClickProp,...triggerProps } = props;
|
|
576
|
+
const context = useFileUploadContext(TRIGGER_NAME);
|
|
577
|
+
const onClick = react.useCallback((event) => {
|
|
578
|
+
onClickProp?.(event);
|
|
579
|
+
if (event.defaultPrevented) return;
|
|
580
|
+
context.inputRef.current?.click();
|
|
581
|
+
}, [context.inputRef, onClickProp]);
|
|
582
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(asChild ? __radix_ui_react_slot.Slot : "button", {
|
|
583
|
+
type: "button",
|
|
584
|
+
"aria-controls": context.inputId,
|
|
585
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
586
|
+
"data-slot": "file-upload-trigger",
|
|
587
|
+
...triggerProps,
|
|
588
|
+
disabled: context.disabled,
|
|
589
|
+
onClick
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
function FileUploadList(props) {
|
|
593
|
+
const { className, orientation = "vertical", asChild, forceMount,...listProps } = props;
|
|
594
|
+
const context = useFileUploadContext(LIST_NAME);
|
|
595
|
+
const fileCount = useStore((state) => state.files.size);
|
|
596
|
+
const shouldRender = forceMount || fileCount > 0;
|
|
597
|
+
if (!shouldRender) return null;
|
|
598
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(asChild ? __radix_ui_react_slot.Slot : "div", {
|
|
599
|
+
role: "list",
|
|
600
|
+
id: context.listId,
|
|
601
|
+
"aria-orientation": orientation,
|
|
602
|
+
"data-orientation": orientation,
|
|
603
|
+
"data-slot": "file-upload-list",
|
|
604
|
+
"data-state": shouldRender ? "active" : "inactive",
|
|
605
|
+
dir: context.dir,
|
|
606
|
+
...listProps,
|
|
607
|
+
className: require_utils.cn("data-[state=inactive]:fade-out-0 data-[state=active]:fade-in-0 data-[state=inactive]:slide-out-to-top-2 data-[state=active]:slide-in-from-top-2 flex flex-col gap-2 data-[state=active]:animate-in data-[state=inactive]:animate-out", orientation === "horizontal" && "flex-row overflow-x-auto p-1.5", className)
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
const FileUploadItemContext = react.createContext(null);
|
|
611
|
+
function useFileUploadItemContext(consumerName) {
|
|
612
|
+
const context = react.use(FileUploadItemContext);
|
|
613
|
+
if (!context) throw new Error(`\`${consumerName}\` must be used within \`${ITEM_NAME}\``);
|
|
614
|
+
return context;
|
|
615
|
+
}
|
|
616
|
+
function FileUploadItem(props) {
|
|
617
|
+
const { value, asChild, className,...itemProps } = props;
|
|
618
|
+
const id = react.useId();
|
|
619
|
+
const statusId = `${id}-status`;
|
|
620
|
+
const nameId = `${id}-name`;
|
|
621
|
+
const sizeId = `${id}-size`;
|
|
622
|
+
const messageId = `${id}-message`;
|
|
623
|
+
const context = useFileUploadContext(ITEM_NAME);
|
|
624
|
+
const fileState = useStore((state) => state.files.get(value));
|
|
625
|
+
const fileCount = useStore((state) => state.files.size);
|
|
626
|
+
const fileIndex = useStore((state) => {
|
|
627
|
+
return Array.from(state.files.keys()).indexOf(value) + 1;
|
|
628
|
+
});
|
|
629
|
+
const itemContext = react.useMemo(() => ({
|
|
630
|
+
id,
|
|
631
|
+
fileState,
|
|
632
|
+
nameId,
|
|
633
|
+
sizeId,
|
|
634
|
+
statusId,
|
|
635
|
+
messageId
|
|
636
|
+
}), [
|
|
637
|
+
id,
|
|
638
|
+
fileState,
|
|
639
|
+
statusId,
|
|
640
|
+
nameId,
|
|
641
|
+
sizeId,
|
|
642
|
+
messageId
|
|
643
|
+
]);
|
|
644
|
+
if (!fileState) return null;
|
|
645
|
+
const statusText = fileState.error ? `Error: ${fileState.error}` : fileState.status === "uploading" ? `Uploading: ${fileState.progress}% complete` : fileState.status === "success" ? "Upload complete" : "Ready to upload";
|
|
646
|
+
const ItemPrimitive = asChild ? __radix_ui_react_slot.Slot : "div";
|
|
647
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FileUploadItemContext.Provider, {
|
|
648
|
+
value: itemContext,
|
|
649
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ItemPrimitive, {
|
|
650
|
+
role: "listitem",
|
|
651
|
+
id,
|
|
652
|
+
"aria-setsize": fileCount,
|
|
653
|
+
"aria-posinset": fileIndex,
|
|
654
|
+
"aria-describedby": `${nameId} ${sizeId} ${statusId} ${fileState.error ? messageId : ""}`,
|
|
655
|
+
"aria-labelledby": nameId,
|
|
656
|
+
"data-slot": "file-upload-item",
|
|
657
|
+
dir: context.dir,
|
|
658
|
+
...itemProps,
|
|
659
|
+
className: require_utils.cn("relative flex items-center rounded-md border p-3", className),
|
|
660
|
+
children: [props.children, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
661
|
+
id: statusId,
|
|
662
|
+
className: "sr-only",
|
|
663
|
+
children: statusText
|
|
664
|
+
})]
|
|
665
|
+
})
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
function formatBytes(bytes) {
|
|
669
|
+
if (bytes === 0) return "0 B";
|
|
670
|
+
const sizes = [
|
|
671
|
+
"B",
|
|
672
|
+
"KB",
|
|
673
|
+
"MB",
|
|
674
|
+
"GB",
|
|
675
|
+
"TB"
|
|
676
|
+
];
|
|
677
|
+
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
678
|
+
return `${(bytes / 1024 ** i).toFixed(i ? 1 : 0)} ${sizes[i]}`;
|
|
679
|
+
}
|
|
680
|
+
function getFileIcon(file) {
|
|
681
|
+
const { type } = file;
|
|
682
|
+
const extension = file.name.split(".").pop()?.toLowerCase() ?? "";
|
|
683
|
+
if (type.startsWith("video/")) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.FileVideoIcon, {});
|
|
684
|
+
if (type.startsWith("audio/")) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.FileAudioIcon, {});
|
|
685
|
+
if (type.startsWith("text/") || [
|
|
686
|
+
"txt",
|
|
687
|
+
"md",
|
|
688
|
+
"rtf",
|
|
689
|
+
"pdf"
|
|
690
|
+
].includes(extension)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.FileTextIcon, {});
|
|
691
|
+
if ([
|
|
692
|
+
"html",
|
|
693
|
+
"css",
|
|
694
|
+
"js",
|
|
695
|
+
"jsx",
|
|
696
|
+
"ts",
|
|
697
|
+
"tsx",
|
|
698
|
+
"json",
|
|
699
|
+
"xml",
|
|
700
|
+
"php",
|
|
701
|
+
"py",
|
|
702
|
+
"rb",
|
|
703
|
+
"java",
|
|
704
|
+
"c",
|
|
705
|
+
"cpp",
|
|
706
|
+
"cs"
|
|
707
|
+
].includes(extension)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.FileCodeIcon, {});
|
|
708
|
+
if ([
|
|
709
|
+
"zip",
|
|
710
|
+
"rar",
|
|
711
|
+
"7z",
|
|
712
|
+
"tar",
|
|
713
|
+
"gz",
|
|
714
|
+
"bz2"
|
|
715
|
+
].includes(extension)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.FileArchiveIcon, {});
|
|
716
|
+
if ([
|
|
717
|
+
"exe",
|
|
718
|
+
"msi",
|
|
719
|
+
"app",
|
|
720
|
+
"apk",
|
|
721
|
+
"deb",
|
|
722
|
+
"rpm"
|
|
723
|
+
].includes(extension) || type.startsWith("application/")) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.FileCogIcon, {});
|
|
724
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.FileIcon, {});
|
|
725
|
+
}
|
|
726
|
+
function FileUploadItemPreview(props) {
|
|
727
|
+
const { render, asChild, children, className,...previewProps } = props;
|
|
728
|
+
const itemContext = useFileUploadItemContext(ITEM_PREVIEW_NAME);
|
|
729
|
+
const context = useFileUploadContext(ITEM_PREVIEW_NAME);
|
|
730
|
+
const getDefaultRender = react.useCallback((file) => {
|
|
731
|
+
if (itemContext.fileState?.file.type.startsWith("image/")) {
|
|
732
|
+
let url = context.urlCache.get(file);
|
|
733
|
+
if (!url) {
|
|
734
|
+
url = URL.createObjectURL(file);
|
|
735
|
+
context.urlCache.set(file, url);
|
|
736
|
+
}
|
|
737
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
|
|
738
|
+
src: url,
|
|
739
|
+
alt: file.name,
|
|
740
|
+
className: "size-full object-cover"
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
return getFileIcon(file);
|
|
744
|
+
}, [itemContext.fileState?.file.type, context.urlCache]);
|
|
745
|
+
const onPreviewRender = react.useCallback((file) => {
|
|
746
|
+
if (render) return render(file, () => getDefaultRender(file));
|
|
747
|
+
return getDefaultRender(file);
|
|
748
|
+
}, [render, getDefaultRender]);
|
|
749
|
+
if (!itemContext.fileState) return null;
|
|
750
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(asChild ? __radix_ui_react_slot.Slot : "div", {
|
|
751
|
+
"aria-labelledby": itemContext.nameId,
|
|
752
|
+
"data-slot": "file-upload-preview",
|
|
753
|
+
...previewProps,
|
|
754
|
+
className: require_utils.cn("relative flex size-10 shrink-0 items-center justify-center overflow-hidden rounded border bg-accent/50 [&>svg]:size-10", className),
|
|
755
|
+
children: [onPreviewRender(itemContext.fileState.file), children]
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
function FileUploadItemMetadata(props) {
|
|
759
|
+
const { asChild, size = "default", children, className,...metadataProps } = props;
|
|
760
|
+
const context = useFileUploadContext(ITEM_METADATA_NAME);
|
|
761
|
+
const itemContext = useFileUploadItemContext(ITEM_METADATA_NAME);
|
|
762
|
+
if (!itemContext.fileState) return null;
|
|
763
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(asChild ? __radix_ui_react_slot.Slot : "div", {
|
|
764
|
+
"data-slot": "file-upload-metadata",
|
|
765
|
+
dir: context.dir,
|
|
766
|
+
...metadataProps,
|
|
767
|
+
className: require_utils.cn("flex min-w-0 flex-1 flex-col", className),
|
|
768
|
+
children: children ?? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
769
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
770
|
+
id: itemContext.nameId,
|
|
771
|
+
className: require_utils.cn("truncate font-medium text-sm", size === "sm" && "font-normal text-[13px] leading-snug"),
|
|
772
|
+
children: itemContext.fileState.file.name
|
|
773
|
+
}),
|
|
774
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
775
|
+
id: itemContext.sizeId,
|
|
776
|
+
className: require_utils.cn("truncate text-muted-foreground text-xs", size === "sm" && "text-[11px] leading-snug"),
|
|
777
|
+
children: formatBytes(itemContext.fileState.file.size)
|
|
778
|
+
}),
|
|
779
|
+
itemContext.fileState.error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
780
|
+
id: itemContext.messageId,
|
|
781
|
+
className: "text-destructive text-xs",
|
|
782
|
+
children: itemContext.fileState.error
|
|
783
|
+
})
|
|
784
|
+
] })
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
function FileUploadItemProgress(props) {
|
|
788
|
+
const { variant = "linear", size = 40, strokeWidth = 2, asChild, forceMount, className,...progressProps } = props;
|
|
789
|
+
const itemContext = useFileUploadItemContext(ITEM_PROGRESS_NAME);
|
|
790
|
+
if (!itemContext.fileState) return null;
|
|
791
|
+
if (!(forceMount || itemContext.fileState.progress !== 100)) return null;
|
|
792
|
+
const ItemProgressPrimitive = asChild ? __radix_ui_react_slot.Slot : "div";
|
|
793
|
+
switch (variant) {
|
|
794
|
+
case "circular": {
|
|
795
|
+
const circumference = 2 * Math.PI * ((size - 4) / 2);
|
|
796
|
+
const strokeDashoffset = circumference - itemContext.fileState.progress / 100 * circumference;
|
|
797
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ItemProgressPrimitive, {
|
|
798
|
+
role: "progressbar",
|
|
799
|
+
"aria-valuemin": 0,
|
|
800
|
+
"aria-valuemax": 100,
|
|
801
|
+
"aria-valuenow": itemContext.fileState.progress,
|
|
802
|
+
"aria-valuetext": `${itemContext.fileState.progress}%`,
|
|
803
|
+
"aria-labelledby": itemContext.nameId,
|
|
804
|
+
"data-slot": "file-upload-progress",
|
|
805
|
+
...progressProps,
|
|
806
|
+
className: require_utils.cn("-translate-x-1/2 -translate-y-1/2 absolute top-1/2 left-1/2", className),
|
|
807
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
808
|
+
className: "-rotate-90 transform",
|
|
809
|
+
width: size,
|
|
810
|
+
height: size,
|
|
811
|
+
viewBox: `0 0 ${size} ${size}`,
|
|
812
|
+
fill: "none",
|
|
813
|
+
stroke: "currentColor",
|
|
814
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
815
|
+
className: "text-primary/20",
|
|
816
|
+
strokeWidth,
|
|
817
|
+
cx: size / 2,
|
|
818
|
+
cy: size / 2,
|
|
819
|
+
r: (size - 4) / 2
|
|
820
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
821
|
+
className: "text-primary transition-[stroke-dashoffset] duration-300 ease-linear",
|
|
822
|
+
strokeWidth,
|
|
823
|
+
strokeLinecap: "round",
|
|
824
|
+
strokeDasharray: circumference,
|
|
825
|
+
strokeDashoffset,
|
|
826
|
+
cx: size / 2,
|
|
827
|
+
cy: size / 2,
|
|
828
|
+
r: (size - 4) / 2
|
|
829
|
+
})]
|
|
830
|
+
})
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
case "fill": {
|
|
834
|
+
const progressPercentage = itemContext.fileState.progress;
|
|
835
|
+
const topInset = 100 - progressPercentage;
|
|
836
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ItemProgressPrimitive, {
|
|
837
|
+
role: "progressbar",
|
|
838
|
+
"aria-valuemin": 0,
|
|
839
|
+
"aria-valuemax": 100,
|
|
840
|
+
"aria-valuenow": progressPercentage,
|
|
841
|
+
"aria-valuetext": `${progressPercentage}%`,
|
|
842
|
+
"aria-labelledby": itemContext.nameId,
|
|
843
|
+
"data-slot": "file-upload-progress",
|
|
844
|
+
...progressProps,
|
|
845
|
+
className: require_utils.cn("absolute inset-0 bg-primary/50 transition-[clip-path] duration-300 ease-linear", className),
|
|
846
|
+
style: { clipPath: `inset(${topInset}% 0% 0% 0%)` }
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
default: return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ItemProgressPrimitive, {
|
|
850
|
+
role: "progressbar",
|
|
851
|
+
"aria-valuemin": 0,
|
|
852
|
+
"aria-valuemax": 100,
|
|
853
|
+
"aria-valuenow": itemContext.fileState.progress,
|
|
854
|
+
"aria-valuetext": `${itemContext.fileState.progress}%`,
|
|
855
|
+
"aria-labelledby": itemContext.nameId,
|
|
856
|
+
"data-slot": "file-upload-progress",
|
|
857
|
+
...progressProps,
|
|
858
|
+
className: require_utils.cn("relative h-1.5 w-full overflow-hidden rounded-full bg-primary/20", className),
|
|
859
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
860
|
+
className: "h-full w-full flex-1 bg-primary transition-transform duration-300 ease-linear",
|
|
861
|
+
style: { transform: `translateX(-${100 - itemContext.fileState.progress}%)` }
|
|
862
|
+
})
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
function FileUploadItemDelete(props) {
|
|
867
|
+
const { asChild, onClick: onClickProp,...deleteProps } = props;
|
|
868
|
+
const store = useStoreContext(ITEM_DELETE_NAME);
|
|
869
|
+
const itemContext = useFileUploadItemContext(ITEM_DELETE_NAME);
|
|
870
|
+
const onClick = react.useCallback((event) => {
|
|
871
|
+
onClickProp?.(event);
|
|
872
|
+
if (!itemContext.fileState || event.defaultPrevented) return;
|
|
873
|
+
store.dispatch({
|
|
874
|
+
type: "REMOVE_FILE",
|
|
875
|
+
file: itemContext.fileState.file
|
|
876
|
+
});
|
|
877
|
+
}, [
|
|
878
|
+
store,
|
|
879
|
+
itemContext.fileState,
|
|
880
|
+
onClickProp
|
|
881
|
+
]);
|
|
882
|
+
if (!itemContext.fileState) return null;
|
|
883
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(asChild ? __radix_ui_react_slot.Slot : "button", {
|
|
884
|
+
type: "button",
|
|
885
|
+
"aria-controls": itemContext.id,
|
|
886
|
+
"aria-describedby": itemContext.nameId,
|
|
887
|
+
"data-slot": "file-upload-item-delete",
|
|
888
|
+
...deleteProps,
|
|
889
|
+
onClick
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
function FileUploadClear(props) {
|
|
893
|
+
const { asChild, forceMount, disabled, onClick: onClickProp,...clearProps } = props;
|
|
894
|
+
const context = useFileUploadContext(CLEAR_NAME);
|
|
895
|
+
const store = useStoreContext(CLEAR_NAME);
|
|
896
|
+
const fileCount = useStore((state) => state.files.size);
|
|
897
|
+
const isDisabled = disabled || context.disabled;
|
|
898
|
+
const onClick = react.useCallback((event) => {
|
|
899
|
+
onClickProp?.(event);
|
|
900
|
+
if (event.defaultPrevented) return;
|
|
901
|
+
store.dispatch({ type: "CLEAR" });
|
|
902
|
+
}, [store, onClickProp]);
|
|
903
|
+
if (!(forceMount || fileCount > 0)) return null;
|
|
904
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(asChild ? __radix_ui_react_slot.Slot : "button", {
|
|
905
|
+
type: "button",
|
|
906
|
+
"aria-controls": context.listId,
|
|
907
|
+
"data-slot": "file-upload-clear",
|
|
908
|
+
"data-disabled": isDisabled ? "" : void 0,
|
|
909
|
+
...clearProps,
|
|
910
|
+
disabled: isDisabled,
|
|
911
|
+
onClick
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
//#endregion
|
|
916
|
+
exports.FileUploadClear = FileUploadClear;
|
|
917
|
+
exports.FileUploadDropzone = FileUploadDropzone;
|
|
918
|
+
exports.FileUploadItem = FileUploadItem;
|
|
919
|
+
exports.FileUploadItemDelete = FileUploadItemDelete;
|
|
920
|
+
exports.FileUploadItemMetadata = FileUploadItemMetadata;
|
|
921
|
+
exports.FileUploadItemPreview = FileUploadItemPreview;
|
|
922
|
+
exports.FileUploadItemProgress = FileUploadItemProgress;
|
|
923
|
+
exports.FileUploadList = FileUploadList;
|
|
924
|
+
exports.FileUploadRoot = FileUploadRoot;
|
|
925
|
+
exports.FileUploadTrigger = FileUploadTrigger;
|
|
926
|
+
exports.useStore = useStore;
|