@jamsrui/file-upload 0.0.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/README.md +40 -0
- package/dist/chunk-6IBQMG7P.mjs +1 -0
- package/dist/chunk-VU6NRBJY.mjs +1 -0
- package/dist/chunk-XDA6AU4J.mjs +1 -0
- package/dist/chunk-XVMAP2VZ.mjs +1 -0
- package/dist/file-upload-config.d.mts +16 -0
- package/dist/file-upload-config.mjs +1 -0
- package/dist/file-upload.d.mts +10 -0
- package/dist/file-upload.mjs +1 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.mjs +1 -0
- package/dist/styles.d.mts +2 -0
- package/dist/styles.mjs +0 -0
- package/dist/use-file-upload.d.mts +37 -0
- package/dist/use-file-upload.mjs +1 -0
- package/dist/use-file.d.mts +47 -0
- package/dist/use-file.mjs +1 -0
- package/dist/utils.d.mts +3 -0
- package/dist/utils.mjs +1 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# π **JamsrUI**
|
|
2
|
+
|
|
3
|
+
**A comprehensive React UI component library designed for developers, with Tailwind CSS integration for seamless styling.**
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## π **Overview**
|
|
7
|
+
|
|
8
|
+
[JamsrUI](https://jamsr-ui.jamsrworld.com) is designed to help developers build modern, fast and visually appealing web applications with ease.
|
|
9
|
+
|
|
10
|
+
## π Getting Started
|
|
11
|
+
|
|
12
|
+
Boost & Build your websites using [JamsrUI](https://jamsr-ui.jamsrworld.com).
|
|
13
|
+
|
|
14
|
+
## β¨ Features
|
|
15
|
+
|
|
16
|
+
- π **Production-Ready**: Optimized for modern React projects.
|
|
17
|
+
- π¨ **Customizable**: Easily override styles and themes.
|
|
18
|
+
- π οΈ **Reusable Components**: Save time with prebuilt, efficient UI elements.
|
|
19
|
+
- β‘ **Developer-Friendly**: Simple API and well-documented usage.
|
|
20
|
+
- π¦ **Lightweight**: Minimal dependencies for fast performance.
|
|
21
|
+
- π₯οΈ **Modern Design**: Clean, responsive, and user-friendly components.
|
|
22
|
+
|
|
23
|
+
## π± Community
|
|
24
|
+
|
|
25
|
+
Weβre thrilled to see the community actively engage with **JamsrUI**! Whether you're sharing feedback, reporting bugs, requesting features, or showcasing projects built with JamsrUI, your involvement helps us grow and improve.
|
|
26
|
+
|
|
27
|
+
### How to Engage
|
|
28
|
+
|
|
29
|
+
- π¬ **Report Bugs**: [GitHub Issues](https://github.com/jamsrworld/jamsr-ui/issues)
|
|
30
|
+
- π **Request Features**: Share ideas for new components.
|
|
31
|
+
- π€ **Showcase Projects**: Let us know how you use JamsrUI.
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
We welcome contributions from developers of all skill levels!
|
|
36
|
+
|
|
37
|
+
## β Support the Project
|
|
38
|
+
|
|
39
|
+
If you find **JamsrUI** helpful, consider giving it a β on [GitHub](https://github.com/jamsrworld/jamsr-ui).
|
|
40
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as l}from"./chunk-VU6NRBJY.mjs";import{cn as c}from"@jamsrui/utils";import{useState as g}from"react";import{jsx as o,jsxs as i}from"react/jsx-runtime";var v=u=>{let[d,a]=g([]),{getInputProps:t,isDragging:n,files:p,removeFile:m}=l({onFilesAdded(e){a(r=>[...r,...e.map(s=>({fileId:s.id,progress:0,completed:!1}))])}});return i("div",{children:[o("input",{className:c("w-full h-24 border",n&&"border-dashed border-primary"),multiple:!0,...t({})}),p.length>0&&o("ul",{className:"flex gap-4 py-4",children:p.map(e=>{let r=d.find(s=>s.fileId===e.id);return i("li",{className:"flex flex-col gap-4",children:[o("img",{className:"size-20",src:e.preview,alt:e.file.name}),o("p",{children:e.file.name}),o("button",{onClick:()=>m(e.id),children:"Remove"}),r&&o("div",{})]},e.id)})})]})};export{v as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useCallback as n,useMemo as O,useRef as z,useState as y}from"react";import{cn as C,mergeProps as N}from"@jamsrui/utils";var j=x=>{let{accept:H,maxFiles:d=Number.POSITIVE_INFINITY,maxSize:m=Number.POSITIVE_INFINITY,multiple:a,onFilesAdded:F,onFilesChange:s}=x,[v,u]=y(!1),[r,o]=y([]),l=z(null),h=n(e=>e instanceof File?e.type.startsWith("image/")?URL.createObjectURL(e):void 0:e.url,[]),P=n(e=>e instanceof File?`${e.name}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`:e.id,[]),c=n(()=>{o(e=>{for(let t of e)t.preview&&t.file instanceof File&&URL.revokeObjectURL(t.preview);return[]}),s?.([])},[s]),p=n(e=>{if(e.length===0||(a||c(),a&&r.length+e.length>d))return;let t=[],f=Array.from(e);for(let i of f)a&&r.some(b=>b.file.name===i.name&&b.file.size===i.size)||i.size>m||t.push({file:i,id:P(i),preview:h(i)});t.length<1||(F?.(t),o(i=>{let g=a?[...i,...t]:t.slice(0,1);return s?.(g),g}),l.current&&(l.current.value=""))},[c,h,r,P,d,m,a,F,s]),D=n(e=>{if((e.target.files?.length??0)>0){let t=e.target.files;t&&p(t)}},[p]),I=n(e=>{let t=r.find(i=>i.id===e);t&&t.file instanceof File&&t.preview&&URL.revokeObjectURL(t.preview);let f=r.filter(i=>i.id!==e);s?.(f),o(f)},[r,s]),E=n(e=>{e.preventDefault(),e.stopPropagation(),u(!0)},[]),L=n(e=>{e.preventDefault(),e.stopPropagation(),!e.currentTarget.contains(e.relatedTarget)&&u(!1)},[]),R=n(e=>{e.preventDefault(),e.stopPropagation()},[]),w=n(e=>{e.preventDefault(),e.stopPropagation();let t=e.dataTransfer.files;t&&p(t),u(!1)},[p]),T=n(e=>({type:"file",multiple:a,ref:l,className:C(e.className,"sr-only"),...N(e,{onChange:D})}),[D,a]),U=n(e=>({...N(e,{onDragEnter:E,onDragLeave:L,onDrop:w,onDragOver:R})}),[E,L,w,R]),M=n(()=>{l.current&&l.current.click()},[]);return O(()=>({isDragging:v,getInputProps:T,files:r,setFiles:o,removeFile:I,getRootProps:U,openFileDialog:M,clearFiles:c}),[v,T,r,o,I,U,M,c])};export{j as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=(t,o=2)=>{if(t===0)return"0 Bytes";let r=1024,B=o<0?0:o,n=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],s=Math.floor(Math.log(t)/Math.log(r));return Number.parseFloat((t/r**s).toFixed(B))+" "+n[s]};export{e as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createConfigContext as o}from"@jamsrui/utils";var[i,p]=o({displayName:"FileUploadConfig"});export{i as a,p as b};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { GlobalConfigProps } from '@jamsrui/core';
|
|
3
|
+
import { FileUpload } from './file-upload.mjs';
|
|
4
|
+
import '@jamsrui/utils';
|
|
5
|
+
|
|
6
|
+
declare const useFileUploadConfig: () => Record<string, any>;
|
|
7
|
+
declare const FileUploadConfig: (props: Omit<Partial<Record<string, any>>, "children"> & {
|
|
8
|
+
merge?: boolean;
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
11
|
+
declare namespace FileUploadConfig {
|
|
12
|
+
interface Props extends FileUpload.Props, GlobalConfigProps<FileUpload.Props> {
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { FileUploadConfig, useFileUploadConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import{a,b}from"./chunk-XVMAP2VZ.mjs";export{a as FileUploadConfig,b as useFileUploadConfig};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { UIProps } from '@jamsrui/utils';
|
|
3
|
+
|
|
4
|
+
declare const FileUpload: (props: FileUpload.Props) => react_jsx_runtime.JSX.Element;
|
|
5
|
+
declare namespace FileUpload {
|
|
6
|
+
interface Props extends UIProps<"div"> {
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { FileUpload };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import{a}from"./chunk-6IBQMG7P.mjs";import"./chunk-VU6NRBJY.mjs";export{a as FileUpload};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { FileUpload } from './file-upload.mjs';
|
|
2
|
+
export { FileUploadConfig, useFileUploadConfig } from './file-upload-config.mjs';
|
|
3
|
+
export { useFileUpload } from './use-file-upload.mjs';
|
|
4
|
+
export { formatBytes } from './utils.mjs';
|
|
5
|
+
import 'react/jsx-runtime';
|
|
6
|
+
import '@jamsrui/utils';
|
|
7
|
+
import '@jamsrui/core';
|
|
8
|
+
import 'react';
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as o,b as e}from"./chunk-XVMAP2VZ.mjs";import{a as l}from"./chunk-6IBQMG7P.mjs";import{a as r}from"./chunk-VU6NRBJY.mjs";import{a as p}from"./chunk-XDA6AU4J.mjs";export{l as FileUpload,o as FileUploadConfig,p as formatBytes,r as useFileUpload,e as useFileUploadConfig};
|
package/dist/styles.mjs
ADDED
|
File without changes
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { PropGetter, UIProps } from '@jamsrui/utils';
|
|
3
|
+
|
|
4
|
+
type FileMetadata = {
|
|
5
|
+
name: string;
|
|
6
|
+
size: number;
|
|
7
|
+
type: string;
|
|
8
|
+
url: string;
|
|
9
|
+
id: string;
|
|
10
|
+
};
|
|
11
|
+
type FileWithPreview = {
|
|
12
|
+
file: File | FileMetadata;
|
|
13
|
+
id: string;
|
|
14
|
+
preview?: string;
|
|
15
|
+
};
|
|
16
|
+
declare const useFileUpload: (props: useFileUpload.Props) => {
|
|
17
|
+
isDragging: boolean;
|
|
18
|
+
getInputProps: PropGetter<UIProps<"input">>;
|
|
19
|
+
files: FileWithPreview[];
|
|
20
|
+
setFiles: react.Dispatch<react.SetStateAction<FileWithPreview[]>>;
|
|
21
|
+
removeFile: (id: string) => void;
|
|
22
|
+
getRootProps: PropGetter<UIProps<"div">>;
|
|
23
|
+
openFileDialog: () => void;
|
|
24
|
+
clearFiles: () => void;
|
|
25
|
+
};
|
|
26
|
+
declare namespace useFileUpload {
|
|
27
|
+
interface Props {
|
|
28
|
+
maxSize?: number;
|
|
29
|
+
maxFiles?: number;
|
|
30
|
+
accept?: string;
|
|
31
|
+
multiple?: boolean;
|
|
32
|
+
onFilesChange?: (files: FileWithPreview[]) => void;
|
|
33
|
+
onFilesAdded?: (files: FileWithPreview[]) => void;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { type FileMetadata, type FileWithPreview, useFileUpload };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import{a}from"./chunk-VU6NRBJY.mjs";export{a as useFileUpload};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { DragEvent, ChangeEvent, InputHTMLAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
type FileMetadata = {
|
|
4
|
+
name: string;
|
|
5
|
+
size: number;
|
|
6
|
+
type: string;
|
|
7
|
+
url: string;
|
|
8
|
+
id: string;
|
|
9
|
+
};
|
|
10
|
+
type FileWithPreview = {
|
|
11
|
+
file: File | FileMetadata;
|
|
12
|
+
id: string;
|
|
13
|
+
preview?: string;
|
|
14
|
+
};
|
|
15
|
+
type FileUploadOptions = {
|
|
16
|
+
maxFiles?: number;
|
|
17
|
+
maxSize?: number;
|
|
18
|
+
accept?: string;
|
|
19
|
+
multiple?: boolean;
|
|
20
|
+
initialFiles?: FileMetadata[];
|
|
21
|
+
onFilesChange?: (files: FileWithPreview[]) => void;
|
|
22
|
+
onFilesAdded?: (addedFiles: FileWithPreview[]) => void;
|
|
23
|
+
};
|
|
24
|
+
type FileUploadState = {
|
|
25
|
+
files: FileWithPreview[];
|
|
26
|
+
isDragging: boolean;
|
|
27
|
+
errors: string[];
|
|
28
|
+
};
|
|
29
|
+
type FileUploadActions = {
|
|
30
|
+
addFiles: (files: FileList | File[]) => void;
|
|
31
|
+
removeFile: (id: string) => void;
|
|
32
|
+
clearFiles: () => void;
|
|
33
|
+
clearErrors: () => void;
|
|
34
|
+
handleDragEnter: (e: DragEvent<HTMLElement>) => void;
|
|
35
|
+
handleDragLeave: (e: DragEvent<HTMLElement>) => void;
|
|
36
|
+
handleDragOver: (e: DragEvent<HTMLElement>) => void;
|
|
37
|
+
handleDrop: (e: DragEvent<HTMLElement>) => void;
|
|
38
|
+
handleFileChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
39
|
+
openFileDialog: () => void;
|
|
40
|
+
getInputProps: (props?: InputHTMLAttributes<HTMLInputElement>) => InputHTMLAttributes<HTMLInputElement> & {
|
|
41
|
+
ref: any;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
declare const useFileUpload: (options?: FileUploadOptions) => [FileUploadState, FileUploadActions];
|
|
45
|
+
declare const formatBytes: (bytes: number, decimals?: number) => string;
|
|
46
|
+
|
|
47
|
+
export { type FileMetadata, type FileUploadActions, type FileUploadOptions, type FileUploadState, type FileWithPreview, formatBytes, useFileUpload };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import{useCallback as r,useRef as A,useState as B}from"react";var N=(m={})=>{let{maxFiles:f=Number.POSITIVE_INFINITY,maxSize:a=Number.POSITIVE_INFINITY,accept:p="*",multiple:l=!1,initialFiles:F=[],onFilesChange:d,onFilesAdded:D}=m,[v,o]=B({errors:[],files:F.map(e=>({file:e,id:e.id,preview:e.url})),isDragging:!1}),u=A(null),L=r(e=>{if(e instanceof File){if(e.size>a)return`File "${e.name}" exceeds the maximum size of ${h(a)}.`}else if(e.size>a)return`File "${e.name}" exceeds the maximum size of ${h(a)}.`;if(p!=="*"){let i=p.split(",").map(s=>s.trim()),n=e instanceof File?e.type||"":e.type,c=`.${e instanceof File,e.name.split(".").pop()}`;if(!i.some(s=>{if(s.startsWith("."))return c.toLowerCase()===s.toLowerCase();if(s.endsWith("/*")){let x=s.split("/")[0];return n.startsWith(`${x}/`)}return n===s}))return`File "${e instanceof File,e.name}" is not an accepted file type.`}return null},[p,a]),M=r(e=>e instanceof File?URL.createObjectURL(e):e.url,[]),I=r(e=>e instanceof File?`${e.name}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`:e.id,[]),E=r(()=>{o(e=>{for(let n of e.files??[])n.preview&&n.file instanceof File&&n.file.type.startsWith("image/")&&URL.revokeObjectURL(n.preview);u.current&&(u.current.value="");let i={...e,errors:[],files:[]};return d?.(i.files),i})},[d]),g=r(e=>{if(!e||e.length===0)return;let i=Array.from(e),n=[];if(o(t=>({...t,errors:[]})),l||E(),l&&f!==Number.POSITIVE_INFINITY&&v.files.length+i.length>f){n.push(`You can only upload a maximum of ${f} files.`),o(t=>({...t,errors:n}));return}let c=[];for(let t of i){if(l&&v.files.some(b=>b.file.name===t.name&&b.file.size===t.size))continue;if(t.size>a){n.push(l?`Some files exceed the maximum size of ${h(a)}.`:`File exceeds the maximum size of ${h(a)}.`);continue}let s=L(t);if(s){n.push(s);continue}c.push({file:t,id:I(t),preview:M(t)})}c.length>0?(D?.(c),o(t=>{let s=l?[...t.files,...c]:c;return d?.(s),{...t,errors:n,files:s}})):n.length>0&&o(t=>({...t,errors:n})),u.current&&(u.current.value="")},[v.files,f,l,a,L,M,I,E,d,D]),w=r(e=>{o(i=>{let n=i.files.find(t=>t.id===e);n?.preview&&n.file instanceof File&&n.file.type.startsWith("image/")&&URL.revokeObjectURL(n.preview);let c=i.files.filter(t=>t.id!==e);return d?.(c),{...i,errors:[],files:c}})},[d]),y=r(()=>{o(e=>({...e,errors:[]}))},[]),H=r(e=>{e.preventDefault(),e.stopPropagation(),o(i=>({...i,isDragging:!0}))},[]),P=r(e=>{e.preventDefault(),e.stopPropagation(),!e.currentTarget.contains(e.relatedTarget)&&o(i=>({...i,isDragging:!1}))},[]),U=r(e=>{e.preventDefault(),e.stopPropagation()},[]),z=r(e=>{if(e.preventDefault(),e.stopPropagation(),o(i=>({...i,isDragging:!1})),!u.current?.disabled&&e.dataTransfer.files&&e.dataTransfer.files.length>0)if(l)g(e.dataTransfer.files);else{let i=e.dataTransfer.files[0];i&&g([i])}},[g,l]),T=r(e=>{e.target.files&&e.target.files.length>0&&g(e.target.files)},[g]),S=r(()=>{u.current&&u.current.click()},[]),$=r((e={})=>({...e,accept:e.accept||p,multiple:e.multiple!==void 0?e.multiple:l,onChange:T,ref:u,type:"file"}),[p,l,T]);return[v,{addFiles:g,clearErrors:y,clearFiles:E,getInputProps:$,handleDragEnter:H,handleDragLeave:P,handleDragOver:U,handleDrop:z,handleFileChange:T,openFileDialog:S,removeFile:w}]},h=(m,f=2)=>{if(m===0)return"0 Bytes";let a=1024,p=f<0?0:f,l=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],F=Math.floor(Math.log(m)/Math.log(a));return Number.parseFloat((m/a**F).toFixed(p))+l[F]};export{h as formatBytes,N as useFileUpload};
|
package/dist/utils.d.mts
ADDED
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"./chunk-XDA6AU4J.mjs";export{a as formatBytes};
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jamsrui/file-upload",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"react": ">=19"
|
|
6
|
+
},
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@jamsrui/hooks": "^0.0.13",
|
|
9
|
+
"@jamsrui/utils": "^0.0.13",
|
|
10
|
+
"@jamsrui/core": "^0.0.11"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.mjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"description": "A modern and beautiful Next.js UI components library.",
|
|
19
|
+
"keywords": [
|
|
20
|
+
"react",
|
|
21
|
+
"ui",
|
|
22
|
+
"UI components",
|
|
23
|
+
"Next.js",
|
|
24
|
+
"React",
|
|
25
|
+
"JamsrUI",
|
|
26
|
+
"jamsr-ui",
|
|
27
|
+
"TypeScript"
|
|
28
|
+
],
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"author": "@jamsrworld",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/jamsrworld/jamsr-ui"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/jamsrworld/jamsr-ui/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://jamsr-ui.jamsrworld.com",
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"README",
|
|
43
|
+
"README.md",
|
|
44
|
+
"package.json",
|
|
45
|
+
"LICENSE"
|
|
46
|
+
]
|
|
47
|
+
}
|