@mainframework/dropzone 1.0.27 → 1.1.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.
- package/README.md +52 -5
- package/dist/index.d.ts +2 -57
- package/dist/index.js +555 -369
- package/dist/index.js.map +1 -1
- package/dist/shared/components/FileSelector/FileSelector.d.ts +6 -0
- package/dist/shared/components/FileSelector/index.d.ts +1 -0
- package/dist/shared/hooks/useFileSelector.d.ts +20 -0
- package/dist/shared/types/types.d.ts +46 -0
- package/dist/shared/utils/dragAndDrop.d.ts +2 -0
- package/dist/shared/utils/mergeStyles.d.ts +2 -0
- package/dist/shared/utils/processUploadedFiles.d.ts +23 -0
- package/package.json +28 -22
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FileSelectorProps } from "../../types/types";
|
|
2
|
+
import "./tailwind.css";
|
|
3
|
+
export declare const FileSelector: {
|
|
4
|
+
({ inputId, accept, messageParagraph, inputClassName, clickableAreaClassName, dropZoneWrapperClassName, messageParagraphClassName, ariaLabel, ariaDescribedBy, ariaLabelButton, onChange, onDragOver, onDrop, onDragEnter, onDragLeave, }: FileSelectorProps): import("react").JSX.Element;
|
|
5
|
+
displayName: string;
|
|
6
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FileSelector } from "./FileSelector";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ErrorMessage, FileData, FileSelectorViewProps, IFileUploaderProps } from "../types/types";
|
|
2
|
+
export declare const useFileSelector: ({ maximumUploadCount, maximumFileSize, acceptedTypes, }?: IFileUploaderProps) => {
|
|
3
|
+
validFiles: FileData[];
|
|
4
|
+
invalidFiles: File[];
|
|
5
|
+
clearCache: () => void;
|
|
6
|
+
getValidFileStreams: () => (File | Blob)[];
|
|
7
|
+
onCancel: () => void;
|
|
8
|
+
onIdChange: (index: number, id: string, files: FileData[]) => void;
|
|
9
|
+
onRemoveFile: (index: number) => void;
|
|
10
|
+
clearBlobs: () => void;
|
|
11
|
+
clearBlob: (file: File) => void;
|
|
12
|
+
maxUploadError: ErrorMessage;
|
|
13
|
+
maxFileSizeError: ErrorMessage;
|
|
14
|
+
setMaximumFileSizeExceeded: (status?: boolean) => void;
|
|
15
|
+
setMaximumUploadsExceeded: (status?: boolean, fileCount?: number, maximumUploads?: number) => void;
|
|
16
|
+
FileSelector: {
|
|
17
|
+
({ inputId, messageParagraph, inputClassName, clickableAreaClassName, dropZoneWrapperClassName, messageParagraphClassName, ariaLabel, ariaDescribedBy, ariaLabelButton, }: FileSelectorViewProps): import("react").JSX.Element;
|
|
18
|
+
displayName: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ChangeEvent, DragEvent } from "react";
|
|
2
|
+
/** Props for styling, copy, and accessibility on the dropzone. Used by the `FileSelector` returned from `useFileSelector`. */
|
|
3
|
+
export interface FileSelectorViewProps {
|
|
4
|
+
inputId?: string;
|
|
5
|
+
messageParagraph?: string;
|
|
6
|
+
inputClassName?: string;
|
|
7
|
+
clickableAreaClassName?: string;
|
|
8
|
+
dropZoneWrapperClassName?: string;
|
|
9
|
+
messageParagraphClassName?: string;
|
|
10
|
+
/** Accessible name for the drop zone region (default: "File upload") */
|
|
11
|
+
ariaLabel?: string;
|
|
12
|
+
/** ID of element that describes the drop zone (e.g. help text) */
|
|
13
|
+
ariaDescribedBy?: string;
|
|
14
|
+
/** Accessible label for the file input button when messageParagraph is not sufficient */
|
|
15
|
+
ariaLabelButton?: string;
|
|
16
|
+
}
|
|
17
|
+
/** File input and drag-and-drop handlers; supplied internally by `useFileSelector` to the presentational component. */
|
|
18
|
+
export interface FileSelectorHandlerProps {
|
|
19
|
+
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
20
|
+
onDragOver: (e: DragEvent<HTMLButtonElement>) => void;
|
|
21
|
+
onDrop: (e: DragEvent<HTMLButtonElement>) => void;
|
|
22
|
+
onDragEnter: (e: DragEvent<HTMLButtonElement>) => void;
|
|
23
|
+
onDragLeave: (e: DragEvent<HTMLButtonElement>) => void;
|
|
24
|
+
}
|
|
25
|
+
/** Internal props injected by `useFileSelector` (not part of the public view props). */
|
|
26
|
+
export interface FileSelectorInternalProps {
|
|
27
|
+
accept?: string;
|
|
28
|
+
}
|
|
29
|
+
/** Full props for the internal `FileSelector` component (view + handlers). */
|
|
30
|
+
export interface FileSelectorProps extends FileSelectorViewProps, FileSelectorHandlerProps, FileSelectorInternalProps {
|
|
31
|
+
}
|
|
32
|
+
export interface IFileUploaderProps {
|
|
33
|
+
maximumUploadCount?: number;
|
|
34
|
+
maximumFileSize?: number;
|
|
35
|
+
acceptedTypes?: Record<string, string>;
|
|
36
|
+
}
|
|
37
|
+
export interface FileData {
|
|
38
|
+
id: string;
|
|
39
|
+
file: File | Blob;
|
|
40
|
+
url: string;
|
|
41
|
+
type: string;
|
|
42
|
+
}
|
|
43
|
+
export interface ErrorMessage {
|
|
44
|
+
status: boolean;
|
|
45
|
+
message: string;
|
|
46
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const hasSurpassedMaxSize: (file: File | Blob, maxSize?: number) => boolean;
|
|
2
|
+
export declare const defaultTypeExtensions: Readonly<Record<string, string>>;
|
|
3
|
+
export declare const maximumUploadCount = 30;
|
|
4
|
+
export declare const maximumFileSize = 5000000;
|
|
5
|
+
export declare const formatFileSize: (bytes: number) => string;
|
|
6
|
+
export declare const buildAcceptString: (acceptedTypes: Record<string, string>) => string;
|
|
7
|
+
type TypeExtensions = Readonly<Record<string, string>>;
|
|
8
|
+
export declare const createUrlString: (file: File) => string;
|
|
9
|
+
export declare const clearBlobFromMemory: (file: File) => void;
|
|
10
|
+
export declare const createUrlStringWithClear: (file: File) => {
|
|
11
|
+
url: string;
|
|
12
|
+
clear: () => void;
|
|
13
|
+
};
|
|
14
|
+
export declare const isValidFileType: (file: File, acceptedTypes?: TypeExtensions) => boolean;
|
|
15
|
+
export declare const checkFilesMaximumSize: (files: readonly (File | Blob)[], max?: number) => boolean;
|
|
16
|
+
export declare const svgXmlnsAttributeCheck: (file: File, allowableTypes?: TypeExtensions) => Promise<{
|
|
17
|
+
id: string;
|
|
18
|
+
type: string;
|
|
19
|
+
file: File;
|
|
20
|
+
url: string;
|
|
21
|
+
} | null>;
|
|
22
|
+
export declare const renameFile: (id: string, file: File | Blob) => File | Blob;
|
|
23
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mainframework/dropzone",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A file selection package, without all of the re-rendering issues that come with other dropzone packages",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -24,11 +24,10 @@
|
|
|
24
24
|
"build:css:prod": "npx @tailwindcss/cli -i ./src/index.css -o ./src/shared/components/FileSelector/tailwind.css --minify && npx postcss ./src/shared/components/FileSelector/tailwind.css -o ./src/shared/components/FileSelector/tailwind.css",
|
|
25
25
|
"husky": "husky",
|
|
26
26
|
"clean": "rimraf dist",
|
|
27
|
-
"lint": "eslint --
|
|
27
|
+
"lint": "eslint --max-warnings=0 --fix",
|
|
28
28
|
"lint-staged": "lint-staged",
|
|
29
29
|
"prebuild": "yarn husky && yarn clean",
|
|
30
|
-
"
|
|
31
|
-
"build": "yarn build:css:prod && rollup -c",
|
|
30
|
+
"build": "yarn build:css:prod && rollup -c && npx tsc --emitDeclarationOnly",
|
|
32
31
|
"test": "jest --config jestconfig.json"
|
|
33
32
|
},
|
|
34
33
|
"peerDependencies": {
|
|
@@ -68,45 +67,52 @@
|
|
|
68
67
|
]
|
|
69
68
|
},
|
|
70
69
|
"devDependencies": {
|
|
71
|
-
"@
|
|
70
|
+
"@babel/core": "^8.0.1",
|
|
71
|
+
"@babel/preset-react": "^8.0.1",
|
|
72
|
+
"@babel/preset-typescript": "^8.0.1",
|
|
73
|
+
"@eslint/js": "^10.0.1",
|
|
74
|
+
"@mainframework/is-deep-equal": "^1.1.0",
|
|
75
|
+
"@rollup/plugin-babel": "^7.1.0",
|
|
72
76
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
73
77
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
74
78
|
"@tailwindcss/aspect-ratio": "^0.4.2",
|
|
75
|
-
"@tailwindcss/cli": "^4.2
|
|
79
|
+
"@tailwindcss/cli": "^4.3.2",
|
|
76
80
|
"@tailwindcss/forms": "^0.5.11",
|
|
77
81
|
"@testing-library/dom": "^10.4.1",
|
|
78
82
|
"@testing-library/jest-dom": "^6.9.1",
|
|
79
83
|
"@testing-library/react": "^16.3.2",
|
|
80
84
|
"@types/jest": "^30.0.0",
|
|
81
|
-
"@types/react": "^19.2.
|
|
85
|
+
"@types/react": "^19.2.17",
|
|
86
|
+
"babel-plugin-react-compiler": "^1.0.0",
|
|
82
87
|
"clsx": "^2.1.1",
|
|
83
88
|
"copyfiles": "^2.4.1",
|
|
84
89
|
"cross-env": "^10.1.0",
|
|
85
|
-
"eslint": "^10.
|
|
90
|
+
"eslint": "^10.6.0",
|
|
86
91
|
"eslint-config-prettier": "^10.1.8",
|
|
87
|
-
"eslint-plugin-prettier": "^5.5.
|
|
92
|
+
"eslint-plugin-prettier": "^5.5.6",
|
|
88
93
|
"eslint-plugin-react": "^7.37.5",
|
|
89
94
|
"eslint-plugin-react-hooks": "^7.1.1",
|
|
95
|
+
"globals": "^17.7.0",
|
|
90
96
|
"husky": "^9.1.7",
|
|
91
|
-
"jest": "^30.4.
|
|
92
|
-
"jest-canvas-mock": "^2.5.
|
|
93
|
-
"jest-environment-jsdom": "^30.4.
|
|
94
|
-
"lint-staged": "
|
|
95
|
-
"postcss": "^8.5.
|
|
97
|
+
"jest": "^30.4.2",
|
|
98
|
+
"jest-canvas-mock": "^2.5.8",
|
|
99
|
+
"jest-environment-jsdom": "^30.4.1",
|
|
100
|
+
"lint-staged": "17.0.8",
|
|
101
|
+
"postcss": "^8.5.16",
|
|
96
102
|
"postcss-cli": "^11.0.1",
|
|
97
103
|
"postcss-prefix-selector": "^2.1.1",
|
|
98
|
-
"prettier": "^3.
|
|
99
|
-
"react": "^19.2.
|
|
100
|
-
"react-dom": "^19.2.
|
|
104
|
+
"prettier": "^3.9.5",
|
|
105
|
+
"react": "^19.2.7",
|
|
106
|
+
"react-dom": "^19.2.7",
|
|
101
107
|
"rimraf": "^6.1.3",
|
|
102
|
-
"rollup": "^4.
|
|
108
|
+
"rollup": "^4.62.2",
|
|
103
109
|
"rollup-plugin-dts": "^6.4.1",
|
|
104
110
|
"rollup-plugin-postcss": "^4.0.2",
|
|
105
|
-
"tailwind-merge": "^3.
|
|
106
|
-
"tailwindcss": "^4.2
|
|
107
|
-
"ts-jest": "^29.4.
|
|
111
|
+
"tailwind-merge": "^3.6.0",
|
|
112
|
+
"tailwindcss": "^4.3.2",
|
|
113
|
+
"ts-jest": "^29.4.11",
|
|
108
114
|
"tslib": "^2.8.1",
|
|
109
115
|
"typescript": "^6.0.3",
|
|
110
|
-
"typescript-eslint": "^8.
|
|
116
|
+
"typescript-eslint": "^8.63.0"
|
|
111
117
|
}
|
|
112
118
|
}
|