react-smart-file-uploader 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,72 @@
1
+ export interface ImageFile {
2
+ name: string;
3
+ size: number;
4
+ type: string;
5
+ lastModified: number;
6
+ fileCategory: 'image' | 'pdf' | 'excel' | 'word' | 'other';
7
+ }
8
+ export interface ProcessedImage {
9
+ file: ImageFile;
10
+ base64: string;
11
+ blob: Blob;
12
+ url: string;
13
+ }
14
+ export interface CropConfig {
15
+ enabled: boolean;
16
+ shape: 'circle' | 'square';
17
+ width?: number;
18
+ height?: number;
19
+ aspect?: number;
20
+ }
21
+ export interface CompressionConfig {
22
+ quality: number;
23
+ maxWidth?: number;
24
+ maxHeight?: number;
25
+ convertSize?: number;
26
+ }
27
+ export interface SessionConfig {
28
+ enabled: boolean;
29
+ key?: string;
30
+ clearOnUnmount?: boolean;
31
+ }
32
+ export interface CustomUIProps {
33
+ isDragActive: boolean;
34
+ isDragReject: boolean;
35
+ files: ProcessedImage[];
36
+ isLoading: boolean;
37
+ openFileDialog: () => void;
38
+ removeFile: (index: number) => void;
39
+ }
40
+ export interface ImageUploaderProps {
41
+ multiple?: boolean;
42
+ accept?: string;
43
+ maxFiles?: number;
44
+ maxSize?: number;
45
+ disabled?: boolean;
46
+ compression?: CompressionConfig | null;
47
+ crop?: CropConfig;
48
+ session?: SessionConfig;
49
+ customUI?: (props: CustomUIProps) => React.ReactNode;
50
+ showPreview?: boolean;
51
+ showProgress?: boolean;
52
+ className?: string;
53
+ style?: React.CSSProperties;
54
+ uploadText?: string;
55
+ dragText?: string;
56
+ errorText?: {
57
+ fileSize?: string;
58
+ fileType?: string;
59
+ maxFiles?: string;
60
+ };
61
+ onFilesChange?: (files: ProcessedImage[]) => void;
62
+ onError?: (error: string) => void;
63
+ onProgress?: (progress: number) => void;
64
+ onCrop?: (croppedImage: ProcessedImage) => void;
65
+ }
66
+ export interface ImageUploaderRef {
67
+ openFileDialog: () => void;
68
+ clearFiles: () => void;
69
+ getFiles: () => ProcessedImage[];
70
+ addFiles: (files: File[]) => void;
71
+ }
72
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,OAAO,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;CAC5D;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,SAAS,EAAE,OAAO,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,IAAI,CAAC;IAC3B,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,QAAQ,EAAE,MAAM,cAAc,EAAE,CAAC;IACjC,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;CACnC"}
@@ -0,0 +1,15 @@
1
+ import { ProcessedImage, CompressionConfig } from './types';
2
+ export declare const validateFileSize: (file: File, maxSize: number) => boolean;
3
+ export declare const validateFileType: (file: File, acceptedTypes: string[]) => boolean;
4
+ export declare const getFileCategory: (file: File) => "image" | "pdf" | "excel" | "word" | "other";
5
+ export declare const fileToBase64: (file: File) => Promise<string>;
6
+ export declare const compressImage: (file: File, config: CompressionConfig) => Promise<File>;
7
+ export declare const compressPDF: (file: File, config: CompressionConfig) => Promise<File>;
8
+ export declare const processFile: (file: File, compression?: CompressionConfig | null) => Promise<ProcessedImage>;
9
+ export declare const saveToSession: (key: string, data: ProcessedImage[]) => void;
10
+ export declare const loadFromSession: (key: string) => Promise<ProcessedImage[]>;
11
+ export declare const clearSession: (key: string) => void;
12
+ export declare const parseAcceptProp: (accept?: string) => string[];
13
+ export declare const formatFileSize: (bytes: number) => string;
14
+ export declare const cleanupUrls: (images: ProcessedImage[]) => void;
15
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAG5D,eAAO,MAAM,gBAAgB,GAAI,MAAM,IAAI,EAAE,SAAS,MAAM,KAAG,OAE9D,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,MAAM,IAAI,EAAE,eAAe,MAAM,EAAE,KAAG,OAQtE,CAAC;AAGF,eAAO,MAAM,eAAe,GAAI,MAAM,IAAI,KAAG,OAAO,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,OAmCjF,CAAC;AAGF,eAAO,MAAM,YAAY,GAAI,MAAM,IAAI,KAAG,OAAO,CAAC,MAAM,CAOvD,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,MAAM,IAAI,EACV,QAAQ,iBAAiB,KACxB,OAAO,CAAC,IAAI,CAWd,CAAC;AAGF,eAAO,MAAM,WAAW,GACtB,MAAM,IAAI,EACV,QAAQ,iBAAiB,KACxB,OAAO,CAAC,IAAI,CA4Bd,CAAC;AAEF,eAAO,MAAM,WAAW,GACtB,MAAM,IAAI,EACV,cAAc,iBAAiB,GAAG,IAAI,KACrC,OAAO,CAAC,cAAc,CA4CxB,CAAC;AAGF,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,EAAE,MAAM,cAAc,EAAE,KAAG,IAWnE,CAAC;AAaF,eAAO,MAAM,eAAe,GAAU,KAAK,MAAM,KAAG,OAAO,CAAC,cAAc,EAAE,CA+B3E,CAAC;AAcF,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,KAAG,IAM1C,CAAC;AAGF,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,KAAG,MAAM,EAGvD,CAAC;AAGF,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,MAM9C,CAAC;AAGF,eAAO,MAAM,WAAW,GAAI,QAAQ,cAAc,EAAE,KAAG,IAMtD,CAAC"}
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "react-smart-file-uploader",
3
+ "version": "2.0.0",
4
+ "description": "A powerful and customizable file uploader component for React with support for images, PDFs, Excel, and Word documents. Features compression, cropping, and session persistence",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.esm.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "README.md",
11
+ "LICENSE"
12
+ ],
13
+ "scripts": {
14
+ "build": "rollup -c",
15
+ "dev": "rollup -c -w",
16
+ "test": "jest",
17
+ "lint": "eslint src --ext .ts,.tsx",
18
+ "lint:fix": "eslint src --ext .ts,.tsx --fix",
19
+ "prepublishOnly": "npm run build"
20
+ },
21
+ "keywords": [
22
+ "react",
23
+ "image",
24
+ "upload",
25
+ "uploader",
26
+ "crop",
27
+ "compression",
28
+ "base64",
29
+ "typescript",
30
+ "component",
31
+ "ui"
32
+ ],
33
+ "author": "Your Name <your.email@example.com>",
34
+ "license": "MIT",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/optimalresource/react-smart-file-uploader.git"
38
+ },
39
+ "bugs": {
40
+ "url": "https://github.com/optimalresource/react-smart-file-uploader/issues"
41
+ },
42
+ "homepage": "https://github.com/optimalresource/react-smart-file-uploader#readme",
43
+ "peerDependencies": {
44
+ "react": ">=16.8.0",
45
+ "react-dom": ">=16.8.0"
46
+ },
47
+ "dependencies": {
48
+ "compressorjs": "^1.2.1",
49
+ "pdf-lib": "^1.17.1",
50
+ "react-image-crop": "^11.0.5"
51
+ },
52
+ "devDependencies": {
53
+ "@rollup/plugin-commonjs": "^25.0.0",
54
+ "@rollup/plugin-json": "^6.1.0",
55
+ "@rollup/plugin-node-resolve": "^15.0.0",
56
+ "@rollup/plugin-typescript": "^11.0.0",
57
+ "@types/react": "^18.2.0",
58
+ "@types/react-dom": "^18.2.0",
59
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
60
+ "@typescript-eslint/parser": "^6.21.0",
61
+ "eslint": "^8.0.0",
62
+ "eslint-plugin-react": "^7.37.5",
63
+ "eslint-plugin-react-hooks": "^4.6.2",
64
+ "jest": "^29.0.0",
65
+ "rollup": "^3.0.0",
66
+ "rollup-plugin-dts": "^6.0.0",
67
+ "rollup-plugin-peer-deps-external": "^2.2.4",
68
+ "rollup-plugin-postcss": "^4.0.2",
69
+ "tslib": "^2.8.1",
70
+ "typescript": "^5.0.0"
71
+ }
72
+ }