@siamf/upload 1.0.0 → 1.0.1

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 (50) hide show
  1. package/README.md +691 -0
  2. package/dist/cjs/components/file/FileUpload.d.ts +3 -0
  3. package/dist/cjs/components/file/FileUpload.js +120 -0
  4. package/dist/cjs/components/file/FileUpload.js.map +1 -0
  5. package/dist/cjs/components/file/MultiFileUpload.d.ts +4 -0
  6. package/dist/cjs/components/file/MultiFileUpload.js +160 -0
  7. package/dist/cjs/components/file/MultiFileUpload.js.map +1 -0
  8. package/dist/cjs/components/file/typings.d.ts +103 -0
  9. package/dist/cjs/components/file/typings.js +57 -0
  10. package/dist/cjs/components/file/typings.js.map +1 -0
  11. package/dist/cjs/components/image/ImageUpload.d.ts +3 -0
  12. package/dist/cjs/components/image/ImageUpload.js +126 -0
  13. package/dist/cjs/components/image/ImageUpload.js.map +1 -0
  14. package/dist/cjs/components/image/MultiImageUpload.d.ts +3 -0
  15. package/dist/cjs/components/image/MultiImageUpload.js +162 -0
  16. package/dist/cjs/components/image/MultiImageUpload.js.map +1 -0
  17. package/dist/cjs/components/image/typings.d.ts +73 -0
  18. package/dist/cjs/components/image/typings.js +18 -0
  19. package/dist/cjs/components/image/typings.js.map +1 -0
  20. package/dist/cjs/components/utils/utils.d.ts +9 -0
  21. package/dist/cjs/components/utils/utils.js +78 -0
  22. package/dist/cjs/components/utils/utils.js.map +1 -0
  23. package/dist/cjs/index.d.ts +8 -0
  24. package/dist/cjs/index.js +21 -0
  25. package/dist/cjs/index.js.map +1 -0
  26. package/dist/esm/components/file/FileUpload.d.ts +3 -0
  27. package/dist/esm/components/file/FileUpload.js +118 -0
  28. package/dist/esm/components/file/FileUpload.js.map +1 -0
  29. package/dist/esm/components/file/MultiFileUpload.d.ts +4 -0
  30. package/dist/esm/components/file/MultiFileUpload.js +157 -0
  31. package/dist/esm/components/file/MultiFileUpload.js.map +1 -0
  32. package/dist/esm/components/file/typings.d.ts +103 -0
  33. package/dist/esm/components/file/typings.js +54 -0
  34. package/dist/esm/components/file/typings.js.map +1 -0
  35. package/dist/esm/components/image/ImageUpload.d.ts +3 -0
  36. package/dist/esm/components/image/ImageUpload.js +124 -0
  37. package/dist/esm/components/image/ImageUpload.js.map +1 -0
  38. package/dist/esm/components/image/MultiImageUpload.d.ts +3 -0
  39. package/dist/esm/components/image/MultiImageUpload.js +160 -0
  40. package/dist/esm/components/image/MultiImageUpload.js.map +1 -0
  41. package/dist/esm/components/image/typings.d.ts +73 -0
  42. package/dist/esm/components/image/typings.js +15 -0
  43. package/dist/esm/components/image/typings.js.map +1 -0
  44. package/dist/esm/components/utils/utils.d.ts +9 -0
  45. package/dist/esm/components/utils/utils.js +69 -0
  46. package/dist/esm/components/utils/utils.js.map +1 -0
  47. package/dist/esm/index.d.ts +8 -0
  48. package/dist/esm/index.js +9 -0
  49. package/dist/esm/index.js.map +1 -0
  50. package/package.json +52 -8
@@ -0,0 +1,73 @@
1
+ import { DragEvent } from "react";
2
+ export type ImageType = {
3
+ file?: File;
4
+ dataURL?: string;
5
+ } | null;
6
+ type TExportTypes = {
7
+ dragProps: {
8
+ onDrop: (e: DragEvent<HTMLDivElement>) => void;
9
+ onDragEnter: (e: DragEvent<HTMLDivElement>) => void;
10
+ onDragLeave: (e: DragEvent<HTMLDivElement>) => void;
11
+ onDragOver: (e: DragEvent<HTMLDivElement>) => void;
12
+ onDragStart: (e: DragEvent<HTMLDivElement>) => void;
13
+ };
14
+ isDragging: boolean;
15
+ onImageUpload: () => void;
16
+ };
17
+ type TPropsTypes = {
18
+ inputProps?: React.HTMLProps<HTMLInputElement>;
19
+ acceptType?: ImageAcceptType | Exclude<ImageAcceptType, ImageAcceptType.ALL>[];
20
+ maxFileSize?: number;
21
+ resolutionWidth?: number;
22
+ resolutionHeight?: number;
23
+ resolutionType?: ResolutionType;
24
+ };
25
+ export declare enum ImageAcceptType {
26
+ ALL = "all",
27
+ SVG = "image/svg+xml",
28
+ PNG = "image/png",
29
+ JPEG = "image/jpeg",
30
+ GIF = "image/gif",
31
+ BMP = "image/bmp",
32
+ WEBP = "image/webp",
33
+ TIFF = "image/tiff",
34
+ ICO = "image/x-icon",
35
+ HEIC = "image/heic",
36
+ HEIF = "image/heif"
37
+ }
38
+ export type ImageErrorTypes = {
39
+ maxFileSize: boolean;
40
+ acceptType: boolean;
41
+ resolution: boolean;
42
+ };
43
+ export interface ImageExportTypes extends TExportTypes {
44
+ imageInfo: ImageType;
45
+ errors: ImageErrorTypes;
46
+ onImageRemove: () => void;
47
+ }
48
+ export interface ImagePropsTypes extends TPropsTypes {
49
+ children: (props: ImageExportTypes) => React.ReactNode;
50
+ onChange: (value: ImageType) => void;
51
+ value: ImageType;
52
+ onError?: (errors: ImageErrorTypes) => void;
53
+ }
54
+ export type MultiImageType = ImageType[];
55
+ export interface MultiImageErrorTypes extends ImageErrorTypes {
56
+ maxNumber: boolean;
57
+ }
58
+ export interface MultiImageExportTypes extends TExportTypes {
59
+ imageInfo: MultiImageType;
60
+ errors: MultiImageErrorTypes;
61
+ onImageRemove: (index: number) => void;
62
+ onImageUpdate: (index: number) => void;
63
+ onImageRemoveAll: () => void;
64
+ }
65
+ export interface MultiImagePropsTypes extends TPropsTypes {
66
+ children: (props: MultiImageExportTypes) => React.ReactNode;
67
+ onChange: (value: MultiImageType) => void;
68
+ value: MultiImageType;
69
+ onError?: (errors: MultiImageErrorTypes) => void;
70
+ maxNumber?: number;
71
+ }
72
+ export type ResolutionType = "absolute" | "less" | "more" | "ratio";
73
+ export {};
@@ -0,0 +1,15 @@
1
+ export var ImageAcceptType;
2
+ (function (ImageAcceptType) {
3
+ ImageAcceptType["ALL"] = "all";
4
+ ImageAcceptType["SVG"] = "image/svg+xml";
5
+ ImageAcceptType["PNG"] = "image/png";
6
+ ImageAcceptType["JPEG"] = "image/jpeg";
7
+ ImageAcceptType["GIF"] = "image/gif";
8
+ ImageAcceptType["BMP"] = "image/bmp";
9
+ ImageAcceptType["WEBP"] = "image/webp";
10
+ ImageAcceptType["TIFF"] = "image/tiff";
11
+ ImageAcceptType["ICO"] = "image/x-icon";
12
+ ImageAcceptType["HEIC"] = "image/heic";
13
+ ImageAcceptType["HEIF"] = "image/heif";
14
+ })(ImageAcceptType || (ImageAcceptType = {}));
15
+ //# sourceMappingURL=typings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typings.js","sourceRoot":"","sources":["../../../../src/components/image/typings.ts"],"names":[],"mappings":"AA6BA,MAAM,CAAN,IAAY,eAYX;AAZD,WAAY,eAAe;IACvB,8BAAW,CAAA;IACX,wCAAqB,CAAA;IACrB,oCAAiB,CAAA;IACjB,sCAAmB,CAAA;IACnB,oCAAiB,CAAA;IACjB,oCAAiB,CAAA;IACjB,sCAAmB,CAAA;IACnB,sCAAmB,CAAA;IACnB,uCAAoB,CAAA;IACpB,sCAAmB,CAAA;IACnB,sCAAmB,CAAA;AACvB,CAAC,EAZW,eAAe,KAAf,eAAe,QAY1B"}
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import { FileAcceptType } from "../file/typings";
3
+ import { ImageAcceptType, ResolutionType } from "../image/typings";
4
+ export declare const openFileDialog: (inputRef: React.RefObject<HTMLInputElement | null>) => void;
5
+ export declare const getFileAccepts: (acceptType?: FileAcceptType | Exclude<FileAcceptType, FileAcceptType.ALL>[]) => string[];
6
+ export declare const getImageAccepts: (acceptType?: ImageAcceptType | Exclude<ImageAcceptType, ImageAcceptType.ALL>[]) => string[];
7
+ export declare const getImage: (file: File) => Promise<HTMLImageElement>;
8
+ export declare const getBase64: (file: File) => Promise<string>;
9
+ export declare const isResolutionValid: (image: HTMLImageElement, resolutionType: ResolutionType, resolutionWidth: number | undefined, resolutionHeight: number | undefined) => boolean;
@@ -0,0 +1,69 @@
1
+ import { FileAcceptType } from "../file/typings";
2
+ import { ImageAcceptType } from "../image/typings";
3
+ export const openFileDialog = (inputRef) => {
4
+ if (inputRef.current)
5
+ inputRef.current.click();
6
+ };
7
+ export const getFileAccepts = (acceptType) => {
8
+ if (!acceptType || acceptType === FileAcceptType.ALL) {
9
+ const defaultArray = Object.values(FileAcceptType).filter(value => value !== FileAcceptType.ALL);
10
+ return defaultArray;
11
+ }
12
+ else {
13
+ return acceptType;
14
+ }
15
+ };
16
+ export const getImageAccepts = (acceptType) => {
17
+ if (!acceptType || acceptType === ImageAcceptType.ALL) {
18
+ const defaultArray = Object.values(ImageAcceptType).filter(value => value !== ImageAcceptType.ALL);
19
+ return defaultArray;
20
+ }
21
+ else {
22
+ return acceptType;
23
+ }
24
+ };
25
+ export const getImage = (file) => {
26
+ const image = new Image();
27
+ return new Promise((resolve) => {
28
+ image.addEventListener('load', () => resolve(image));
29
+ image.src = URL.createObjectURL(file);
30
+ });
31
+ };
32
+ export const getBase64 = (file) => {
33
+ const reader = new FileReader();
34
+ return new Promise((resolve) => {
35
+ reader.addEventListener('load', () => resolve(String(reader.result)));
36
+ reader.readAsDataURL(file);
37
+ });
38
+ };
39
+ export const isResolutionValid = (image, resolutionType, resolutionWidth, resolutionHeight) => {
40
+ if (!resolutionWidth || !resolutionHeight || !image.width || !image.height)
41
+ return true;
42
+ switch (resolutionType) {
43
+ case 'absolute': {
44
+ if (image.width === resolutionWidth && image.height === resolutionHeight)
45
+ return true;
46
+ break;
47
+ }
48
+ case 'ratio': {
49
+ const ratio = resolutionWidth / resolutionHeight;
50
+ if (image.width / image.height === ratio)
51
+ return true;
52
+ break;
53
+ }
54
+ case 'less': {
55
+ if (image.width <= resolutionWidth && image.height <= resolutionHeight)
56
+ return true;
57
+ break;
58
+ }
59
+ case 'more': {
60
+ if (image.width >= resolutionWidth && image.height >= resolutionHeight)
61
+ return true;
62
+ break;
63
+ }
64
+ default:
65
+ break;
66
+ }
67
+ return false;
68
+ };
69
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/components/utils/utils.ts"],"names":[],"mappings":"AACA,OAA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AAC,KAAK,IAAI,eAAe,IAAI,KAAK,CAAC,MAAM,IAAI,gBAAgB;gBAClE,OAAO,IAAI,CAAC;YAChB,MAAM;QACV,CAAC;QACD,KAAK,MAAM,CAAC,CAAC,CAAC;YACV,IAAI,KAAK,CAAC,KAAK,IAAI,eAAe,IAAI,KAAK,CAAC,MAAM,IAAI,gBAAgB;gBAClE,OAAO,IAAI,CAAC;YAChB,MAAM;QACV,CAAC;QACD;YACI,MAAM;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { default as FileUpload } from "./components/file/FileUpload";
2
+ export { default as MultiFileUpload } from "./components/file/MultiFileUpload";
3
+ export { FileAcceptType } from "./components/file/typings";
4
+ export type { FileType, MultiFileType, FileErrorTypes, MultiFileErrorTypes } from "./components/file/typings";
5
+ export { default as ImageUpload } from "./components/image/ImageUpload";
6
+ export { default as MultiImageUpload } from "./components/image/MultiImageUpload";
7
+ export { ImageAcceptType } from "./components/image/typings";
8
+ export type { ImageType, MultiImageType, ImageErrorTypes, MultiImageErrorTypes } from "./components/image/typings";
@@ -0,0 +1,9 @@
1
+ //Files
2
+ export { default as FileUpload } from "./components/file/FileUpload";
3
+ export { default as MultiFileUpload } from "./components/file/MultiFileUpload";
4
+ export { FileAcceptType } from "./components/file/typings";
5
+ //Image
6
+ export { default as ImageUpload } from "./components/image/ImageUpload";
7
+ export { default as MultiImageUpload } from "./components/image/MultiImageUpload";
8
+ export { ImageAcceptType } from "./components/image/typings";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO;AACP,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D,OAAO;AACP,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC"}
package/package.json CHANGED
@@ -1,12 +1,56 @@
1
1
  {
2
2
  "name": "@siamf/upload",
3
- "version": "1.0.0",
4
- "description": "",
5
- "license": "ISC",
6
- "author": "",
7
- "type": "commonjs",
8
- "main": "index.js",
3
+ "version": "1.0.1",
4
+ "description": "A fully headless React package for handling image and file uploads with complete UI control. It provides four flexible components—ImageUpload, MultiImageUpload, FileUpload, and MultiFileUpload.",
5
+ "homepage": "https://github.com/siamahnaf/siamf-upload",
6
+ "main": "dist/cjs/index.js",
7
+ "module": "dist/esm/index.js",
8
+ "files": [
9
+ "dist"
10
+ ],
9
11
  "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
12
+ "build": "rimraf dist && npm run build:esm && npm run build:cjs",
13
+ "build:esm": "tsc",
14
+ "build:cjs": "tsc --module CommonJS --outDir dist/cjs"
15
+ },
16
+ "author": {
17
+ "name": "Siam Ahnaf",
18
+ "email": "mail@siamahnaf.com",
19
+ "url": "https://www.siamahnaf.com"
20
+ },
21
+ "license": "MIT",
22
+ "keywords": [
23
+ "image",
24
+ "images",
25
+ "upload",
26
+ "uploader",
27
+ "uploading",
28
+ "react image upload",
29
+ "react images uploading",
30
+ "drag",
31
+ "drag and drop",
32
+ "image drag and drop",
33
+ "reactjs",
34
+ "typescript",
35
+ "javascript",
36
+ "render props",
37
+ "react-component"
38
+ ],
39
+ "repository": {
40
+ "type": "git",
41
+ "directory": "https://github.com/siamahnaf/siamf-upload",
42
+ "url": "https://github.com/siamahnaf/siamf-upload"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^22.12.0",
46
+ "@types/react": "^19.0.8",
47
+ "@types/react-dom": "^19.0.3",
48
+ "react": "^19.0.0",
49
+ "react-dom": "^19.0.0",
50
+ "typescript": "^5.7.3"
51
+ },
52
+ "peerDependencies": {
53
+ "react": "^17 || ^18 || ^19",
54
+ "react-dom": "^17 || ^18 || ^19"
11
55
  }
12
- }
56
+ }