@mainframework/dropzone 1.0.20 → 1.0.22
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/index.d.ts +62 -1
- package/dist/index.js +3466 -2
- package/dist/index.js.map +1 -1
- package/package.json +7 -3
- package/dist/shared/components/FileSelector/FileSelector.d.ts +0 -3
- package/dist/shared/components/FileSelector/FileSelector.js +0 -53
- package/dist/shared/components/FileSelector/FileSelector.js.map +0 -1
- package/dist/shared/components/FileSelector/index.d.ts +0 -1
- package/dist/shared/components/FileSelector/index.js +0 -2
- package/dist/shared/components/FileSelector/index.js.map +0 -1
- package/dist/shared/hooks/useCustomCallback.d.ts +0 -1
- package/dist/shared/hooks/useCustomCallback.js +0 -16
- package/dist/shared/hooks/useCustomCallback.js.map +0 -1
- package/dist/shared/hooks/useFileSelector.d.ts +0 -20
- package/dist/shared/hooks/useFileSelector.js +0 -220
- package/dist/shared/hooks/useFileSelector.js.map +0 -1
- package/dist/shared/types/types.d.ts +0 -38
- package/dist/shared/types/types.js +0 -2
- package/dist/shared/types/types.js.map +0 -1
- package/dist/shared/utils/dragAndDrop.d.ts +0 -2
- package/dist/shared/utils/dragAndDrop.js +0 -9
- package/dist/shared/utils/dragAndDrop.js.map +0 -1
- package/dist/shared/utils/mergeStyles.d.ts +0 -2
- package/dist/shared/utils/mergeStyles.js +0 -5
- package/dist/shared/utils/mergeStyles.js.map +0 -1
- package/dist/shared/utils/processUploadedFiles.d.ts +0 -23
- package/dist/shared/utils/processUploadedFiles.js +0 -156
- package/dist/shared/utils/processUploadedFiles.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { FileSelector } from "./FileSelector";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/shared/components/FileSelector/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useCustomCallback: <T extends (...args: any[]) => any>(callback: T, dependencies: unknown[]) => T;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useRef } from "react";
|
|
3
|
-
import { isEqual } from "@mainframework/is-deep-equal";
|
|
4
|
-
export const useCustomCallback = (callback, dependencies) => {
|
|
5
|
-
const refCallback = useRef(callback);
|
|
6
|
-
const refDependencies = useRef(dependencies);
|
|
7
|
-
// Update refs synchronously during render
|
|
8
|
-
if (!dependencies.every((dep, index) => isEqual(dep, refDependencies.current[index]))) {
|
|
9
|
-
refDependencies.current = dependencies;
|
|
10
|
-
refCallback.current = callback;
|
|
11
|
-
}
|
|
12
|
-
// Stable callback, always calls latest callback
|
|
13
|
-
const stableCallback = useRef((...args) => refCallback.current(...args)).current;
|
|
14
|
-
return stableCallback;
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=useCustomCallback.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useCustomCallback.js","sourceRoot":"","sources":["../../../src/shared/hooks/useCustomCallback.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAEvD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAoC,QAAW,EAAE,YAAuB,EAAK,EAAE;IAC9G,MAAM,WAAW,GAAG,MAAM,CAAI,QAAQ,CAAC,CAAC;IACxC,MAAM,eAAe,GAAG,MAAM,CAAY,YAAY,CAAC,CAAC;IAExD,0CAA0C;IAC1C,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QACtF,eAAe,CAAC,OAAO,GAAG,YAAY,CAAC;QACvC,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC;IACjC,CAAC;IAED,gDAAgD;IAChD,MAAM,cAAc,GAAG,MAAM,CAAC,CAAC,GAAG,IAAmB,EAAiB,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;IAE/G,OAAO,cAAmB,CAAC;AAC7B,CAAC,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ErrorMessage, FileData, FileSelectorProps, 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
|
-
(props: Omit<FileSelectorProps, "onChange" | "onDragOver" | "onDrop" | "onDragEnter" | "onDragLeave">): import("react/jsx-runtime").JSX.Element;
|
|
18
|
-
displayName: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useCallback, useRef, useState, useMemo } from "react";
|
|
4
|
-
import { defaultTypeExtensions, maximumUploadCount as maxUploadCount, maximumFileSize as maxFileSize, printableMaximumFileSize, checkFilesMaximumSize, isValidFileType, SvgXmlnsAttributeCheck, checkFile, clearBlobFromMemory, } from "../utils/processUploadedFiles";
|
|
5
|
-
import { useCustomCallback } from "./useCustomCallback";
|
|
6
|
-
import { FileSelector } from "../components/FileSelector";
|
|
7
|
-
export const useFileSelector = ({ maximumUploadCount = maxUploadCount, maximumFileSize = maxFileSize, acceptedTypes = defaultTypeExtensions, } = {}) => {
|
|
8
|
-
//State
|
|
9
|
-
//Trigger a re-render
|
|
10
|
-
const [, setUpdateTrigger] = useState(0);
|
|
11
|
-
const [validFiles, SetValidFiles] = useState([]);
|
|
12
|
-
const [invalidFiles, SetInvalidFiles] = useState([]);
|
|
13
|
-
//Refs
|
|
14
|
-
const maxUploadErrorRef = useRef({
|
|
15
|
-
status: false,
|
|
16
|
-
message: "",
|
|
17
|
-
});
|
|
18
|
-
const maxFileSizeErrorRef = useRef({
|
|
19
|
-
status: false,
|
|
20
|
-
message: "",
|
|
21
|
-
});
|
|
22
|
-
const setMaximumUploadsExceeded = useCallback((status = false, fileCount, maximumUploads) => {
|
|
23
|
-
maxUploadErrorRef.current.status = status;
|
|
24
|
-
maxUploadErrorRef.current.message = status
|
|
25
|
-
? `You have attempted to upload ${fileCount} files. The maximum allowable uploads for this feature is ${maximumUploads}`
|
|
26
|
-
: "";
|
|
27
|
-
setUpdateTrigger((state) => (state += 1));
|
|
28
|
-
}, []);
|
|
29
|
-
const setMaximumFileSizeExceeded = useCallback((status = false) => {
|
|
30
|
-
maxFileSizeErrorRef.current.status = status;
|
|
31
|
-
maxFileSizeErrorRef.current.message = status
|
|
32
|
-
? `You have attempted upload a file(s) that exceeds the maximum size of ${printableMaximumFileSize}`
|
|
33
|
-
: "";
|
|
34
|
-
setUpdateTrigger((state) => (state += 1));
|
|
35
|
-
}, []);
|
|
36
|
-
const clearBlobs = useCustomCallback(() => {
|
|
37
|
-
//Remove any blobs created in memory
|
|
38
|
-
let i = 0;
|
|
39
|
-
while (i < validFiles.length) {
|
|
40
|
-
const file = validFiles[i].file;
|
|
41
|
-
if (file instanceof File) {
|
|
42
|
-
clearBlobFromMemory(file);
|
|
43
|
-
}
|
|
44
|
-
i++;
|
|
45
|
-
}
|
|
46
|
-
}, [validFiles]);
|
|
47
|
-
const clearCache = useCustomCallback(() => {
|
|
48
|
-
//Clear any blobs held in memory
|
|
49
|
-
clearBlobs();
|
|
50
|
-
SetInvalidFiles([]);
|
|
51
|
-
SetValidFiles([]);
|
|
52
|
-
}, [clearBlobs]);
|
|
53
|
-
const onCancel = useCustomCallback(() => {
|
|
54
|
-
clearCache();
|
|
55
|
-
}, [clearCache]);
|
|
56
|
-
const getValidFileStreams = useCallback(() => (validFiles.length ? validFiles.map(({ file }) => file) : []), [validFiles]);
|
|
57
|
-
//Main Engine to deal with files
|
|
58
|
-
const processFiles = useCustomCallback((files) => {
|
|
59
|
-
const maxFileSizeCheck = checkFilesMaximumSize(files, maximumFileSize) && !maxFileSizeErrorRef.current.status;
|
|
60
|
-
const maxUploadCountCheck = typeof maximumUploadCount !== "undefined"
|
|
61
|
-
? !maxUploadErrorRef.current.status && files.length > maximumUploadCount
|
|
62
|
-
: false;
|
|
63
|
-
if (maxFileSizeCheck || maxUploadCountCheck) {
|
|
64
|
-
if (maxFileSizeCheck)
|
|
65
|
-
setMaximumFileSizeExceeded(true);
|
|
66
|
-
if (maxUploadCountCheck)
|
|
67
|
-
setMaximumUploadsExceeded(true, files.length, maximumUploadCount);
|
|
68
|
-
onCancel();
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
const valid = [];
|
|
72
|
-
const invalid = [];
|
|
73
|
-
let i = 0;
|
|
74
|
-
while (i < files.length) {
|
|
75
|
-
const file = files[i];
|
|
76
|
-
if (isValidFileType(file, acceptedTypes)) {
|
|
77
|
-
valid.push(SvgXmlnsAttributeCheck(file, acceptedTypes));
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
invalid.push(file);
|
|
81
|
-
}
|
|
82
|
-
i++;
|
|
83
|
-
}
|
|
84
|
-
if (valid.length > 0) {
|
|
85
|
-
Promise.all(valid)
|
|
86
|
-
.then((results) => {
|
|
87
|
-
const filteredResults = [];
|
|
88
|
-
let j = 0;
|
|
89
|
-
while (j < results.length) {
|
|
90
|
-
const result = results[j];
|
|
91
|
-
if (result !== null) {
|
|
92
|
-
filteredResults.push(result);
|
|
93
|
-
}
|
|
94
|
-
j++;
|
|
95
|
-
}
|
|
96
|
-
SetValidFiles(filteredResults);
|
|
97
|
-
})
|
|
98
|
-
.catch((error) => {
|
|
99
|
-
console.error("File processing error:", error);
|
|
100
|
-
// Optionally expose error state to engineers
|
|
101
|
-
SetInvalidFiles(invalid.concat(files)); // Treat all as invalid on error
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
if (invalid.length > 0) {
|
|
105
|
-
SetInvalidFiles(invalid);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}, [
|
|
109
|
-
acceptedTypes,
|
|
110
|
-
maximumFileSize,
|
|
111
|
-
maximumUploadCount,
|
|
112
|
-
setMaximumFileSizeExceeded,
|
|
113
|
-
setMaximumUploadsExceeded,
|
|
114
|
-
onCancel,
|
|
115
|
-
]);
|
|
116
|
-
const onRemoveFile = useCustomCallback((index) => {
|
|
117
|
-
const updatedValidFiles = [];
|
|
118
|
-
let i = 0;
|
|
119
|
-
while (i < validFiles.length) {
|
|
120
|
-
if (i === index) {
|
|
121
|
-
const file = validFiles[i].file;
|
|
122
|
-
if (file instanceof File) {
|
|
123
|
-
clearBlobFromMemory(file);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
updatedValidFiles.push(validFiles[i]);
|
|
128
|
-
}
|
|
129
|
-
i++;
|
|
130
|
-
}
|
|
131
|
-
SetValidFiles(updatedValidFiles);
|
|
132
|
-
}, [validFiles]);
|
|
133
|
-
const onIdChange = useCallback((index, id, files) => {
|
|
134
|
-
const updatedValidFiles = files.map((fileData, i) => {
|
|
135
|
-
if (i === index) {
|
|
136
|
-
const renamedFile = checkFile(id, fileData.file);
|
|
137
|
-
return { ...fileData, file: renamedFile, id };
|
|
138
|
-
}
|
|
139
|
-
return fileData;
|
|
140
|
-
});
|
|
141
|
-
SetValidFiles(updatedValidFiles);
|
|
142
|
-
}, []);
|
|
143
|
-
const onInputChange = useCustomCallback((event) => {
|
|
144
|
-
const files = Array.from(event.target.files || []);
|
|
145
|
-
processFiles(files);
|
|
146
|
-
}, [processFiles]);
|
|
147
|
-
//Drag and Drop
|
|
148
|
-
const onDrop = useCustomCallback((e) => {
|
|
149
|
-
e.preventDefault();
|
|
150
|
-
processFiles(Array.from(e.dataTransfer.files));
|
|
151
|
-
}, [processFiles]);
|
|
152
|
-
const onDragOver = useCallback((e) => {
|
|
153
|
-
e.preventDefault();
|
|
154
|
-
e.dataTransfer.dropEffect = "copy";
|
|
155
|
-
}, []);
|
|
156
|
-
const onDragEnter = useCallback((e) => {
|
|
157
|
-
e.preventDefault();
|
|
158
|
-
const { classList } = e.currentTarget;
|
|
159
|
-
classList.add("border-yellow-400");
|
|
160
|
-
classList.remove("border-silver-600");
|
|
161
|
-
}, []);
|
|
162
|
-
const onDragLeave = useCallback((e) => {
|
|
163
|
-
e.preventDefault();
|
|
164
|
-
const currentTarget = e.currentTarget;
|
|
165
|
-
const timeoutId = setTimeout(() => {
|
|
166
|
-
if (currentTarget && !currentTarget.contains(e.relatedTarget)) {
|
|
167
|
-
const { classList } = currentTarget;
|
|
168
|
-
classList.remove("border-yellow-400");
|
|
169
|
-
classList.add("border-silver-600");
|
|
170
|
-
}
|
|
171
|
-
clearTimeout(timeoutId);
|
|
172
|
-
}, 200);
|
|
173
|
-
}, []);
|
|
174
|
-
// const FileSelectorRef = useRef(() => (
|
|
175
|
-
// <FileSelector
|
|
176
|
-
// acceptTypes={acceptTypes}
|
|
177
|
-
// onChange={onInputChange}
|
|
178
|
-
// onDragOver={onDragOver}
|
|
179
|
-
// onDrop={onDrop}
|
|
180
|
-
// onDragEnter={onDragEnter}
|
|
181
|
-
// onDragLeave={onDragLeave}
|
|
182
|
-
// />
|
|
183
|
-
// ));
|
|
184
|
-
// In useFileSelector.ts, create a wrapper component
|
|
185
|
-
const createFileSelectorComponent = (handlers) => {
|
|
186
|
-
// Return a component that accepts only the visual/accessibility props
|
|
187
|
-
const Component = (props) => (_jsx(FileSelector, { ...props, onChange: handlers.onInputChange, onDragOver: handlers.onDragOver, onDrop: handlers.onDrop, onDragEnter: handlers.onDragEnter, onDragLeave: handlers.onDragLeave }));
|
|
188
|
-
Component.displayName = "FileSelectorWrapper"; // <-- fix the ESLint warning
|
|
189
|
-
return Component;
|
|
190
|
-
};
|
|
191
|
-
// Then in the hook's return:
|
|
192
|
-
const BoundFileSelector = useMemo(() => createFileSelectorComponent({
|
|
193
|
-
onInputChange,
|
|
194
|
-
onDragOver,
|
|
195
|
-
onDrop,
|
|
196
|
-
onDragEnter,
|
|
197
|
-
onDragLeave,
|
|
198
|
-
}), [onInputChange, onDragOver, onDrop, onDragEnter, onDragLeave]);
|
|
199
|
-
return {
|
|
200
|
-
//Properties
|
|
201
|
-
validFiles,
|
|
202
|
-
invalidFiles,
|
|
203
|
-
//Methods
|
|
204
|
-
clearCache,
|
|
205
|
-
getValidFileStreams,
|
|
206
|
-
onCancel,
|
|
207
|
-
onIdChange,
|
|
208
|
-
onRemoveFile,
|
|
209
|
-
clearBlobs,
|
|
210
|
-
clearBlob: clearBlobFromMemory,
|
|
211
|
-
//Errors
|
|
212
|
-
maxUploadError: maxUploadErrorRef.current,
|
|
213
|
-
maxFileSizeError: maxFileSizeErrorRef.current,
|
|
214
|
-
setMaximumFileSizeExceeded,
|
|
215
|
-
setMaximumUploadsExceeded,
|
|
216
|
-
//Component - Export the FileSelector
|
|
217
|
-
FileSelector: BoundFileSelector,
|
|
218
|
-
};
|
|
219
|
-
};
|
|
220
|
-
//# sourceMappingURL=useFileSelector.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,YAAY;QACZ,UAAU;QACV,SAAS,EAAE,mBAAmB;QAE9B,QAAQ;QACR,cAAc,EAAE,iBAAiB,CAAC,OAAO;QACzC,gBAAgB,EAAE,mBAAmB,CAAC,OAAO;QAC7C,0BAA0B;QAC1B,yBAAyB;QAEzB,qCAAqC;QACrC,YAAY,EAAE,iBAAiB;KAChC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { ChangeEvent, DragEvent } from "react";
|
|
2
|
-
export interface FileSelectorProps {
|
|
3
|
-
inputId?: string;
|
|
4
|
-
acceptTypes?: 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
|
-
ariaLabelledBy?: string;
|
|
17
|
-
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
18
|
-
onDragOver: (e: DragEvent<HTMLButtonElement>) => void;
|
|
19
|
-
onDrop: (e: DragEvent<HTMLButtonElement>) => void;
|
|
20
|
-
onDragEnter: (e: DragEvent<HTMLButtonElement>) => void;
|
|
21
|
-
onDragLeave: (e: DragEvent<HTMLButtonElement>) => void;
|
|
22
|
-
}
|
|
23
|
-
export interface IFileUploaderProps {
|
|
24
|
-
acceptTypes?: string;
|
|
25
|
-
maximumUploadCount?: number;
|
|
26
|
-
maximumFileSize?: number;
|
|
27
|
-
acceptedTypes?: Record<string, string>;
|
|
28
|
-
}
|
|
29
|
-
export interface FileData {
|
|
30
|
-
id: string;
|
|
31
|
-
file: File | Blob;
|
|
32
|
-
url: string;
|
|
33
|
-
type: string;
|
|
34
|
-
}
|
|
35
|
-
export interface ErrorMessage {
|
|
36
|
-
status: boolean;
|
|
37
|
-
message: string;
|
|
38
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/shared/types/types.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dragAndDrop.js","sourceRoot":"","sources":["../../../src/shared/utils/dragAndDrop.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAGb,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAA2B,OAAuB,EAAE,EAAE;IACpF,OAAO,CAAC,CAAI,EAAE,EAAE;QACd,CAAC,CAAC,cAAc,EAAE,CAAC;QACnB,CAAC,CAAC,eAAe,EAAE,CAAC;QACpB,OAAO,CAAC,CAAC,CAAC,CAAC;IACb,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mergeStyles.js","sourceRoot":"","sources":["../../../src/shared/utils/mergeStyles.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,IAAI,EAAmB,MAAM,MAAM,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAG,MAAoB,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export declare const defaultTypeExtensions: Record<string, string>;
|
|
2
|
-
export declare const maximumUploadCount = 30;
|
|
3
|
-
export declare const maximumFileSize = 5000000;
|
|
4
|
-
export declare const printableMaximumFileSize = "5 Megabytes";
|
|
5
|
-
type TypeExtensions = Readonly<Record<string, string>>;
|
|
6
|
-
export declare const createUrlString: (file: File) => string;
|
|
7
|
-
export declare const clearBlobFromMemory: (file: File) => void;
|
|
8
|
-
export declare const createUrlStringWithAutoCleanup: (file: File, autoCleanupMs?: number) => {
|
|
9
|
-
url: string;
|
|
10
|
-
cancel: () => void;
|
|
11
|
-
};
|
|
12
|
-
export declare const isValidFileType: (file: File, acceptedTypes?: TypeExtensions) => boolean;
|
|
13
|
-
export declare const hasSurpassedMaxSize: (file: File | Blob, maxSize?: number) => boolean;
|
|
14
|
-
export declare const checkFilesMaximumSize: (files: readonly (File | Blob)[], max?: number) => boolean;
|
|
15
|
-
export declare const SvgXmlnsAttributeCheck: (file: File, allowableTypes?: TypeExtensions) => Promise<{
|
|
16
|
-
id: string;
|
|
17
|
-
type: string;
|
|
18
|
-
file: File;
|
|
19
|
-
url: string;
|
|
20
|
-
} | null>;
|
|
21
|
-
export declare const renameFile: (file: Blob, name: string) => File;
|
|
22
|
-
export declare const checkFile: (id: string, file: File | Blob) => File | Blob;
|
|
23
|
-
export {};
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
//Use this to quickly get the file extensions
|
|
3
|
-
//Devs can pass their own custom type mappings to override these defaults
|
|
4
|
-
export const defaultTypeExtensions = {
|
|
5
|
-
"image/png": ".png",
|
|
6
|
-
"image/jpeg": ".jpeg",
|
|
7
|
-
"image/jpg": ".jpg",
|
|
8
|
-
"image/svg+xml": ".svg",
|
|
9
|
-
"application/pdf": ".pdf",
|
|
10
|
-
"application/msword": ".doc",
|
|
11
|
-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": ".docx",
|
|
12
|
-
};
|
|
13
|
-
//This is the attribute that should be present in all svg files
|
|
14
|
-
const xmlns = "<svg xmlns='http://www.w3.org/2000/svg'";
|
|
15
|
-
export const maximumUploadCount = 30;
|
|
16
|
-
export const maximumFileSize = 5e6; //5 mb's
|
|
17
|
-
export const printableMaximumFileSize = "5 Megabytes";
|
|
18
|
-
// HELPER: Extract file ID (filename without extension)
|
|
19
|
-
/*
|
|
20
|
-
* Extracts filename without extension, handling multiple dots correctly.
|
|
21
|
-
* "my.photo.final.png" -> "my.photo.final"
|
|
22
|
-
* "README.md" -> "README"
|
|
23
|
-
* "no-extension" -> "no-extension"
|
|
24
|
-
*/
|
|
25
|
-
const getFileId = (fileName) => {
|
|
26
|
-
const lastDotIndex = fileName.lastIndexOf(".");
|
|
27
|
-
return lastDotIndex > 0 ? fileName.slice(0, lastDotIndex) : fileName;
|
|
28
|
-
};
|
|
29
|
-
// BLOB URL REGISTRY - WeakMap for automatic GC cleanup
|
|
30
|
-
/*
|
|
31
|
-
* WeakMap prevents memory leaks by allowing GC to reclaim File objects.
|
|
32
|
-
* No manual cleanup needed when Files are no longer referenced.
|
|
33
|
-
*/
|
|
34
|
-
const blobUrlRegistry = new WeakMap();
|
|
35
|
-
export const createUrlString = (file) => {
|
|
36
|
-
const existing = blobUrlRegistry.get(file);
|
|
37
|
-
if (existing)
|
|
38
|
-
return existing;
|
|
39
|
-
const url = URL.createObjectURL(file);
|
|
40
|
-
blobUrlRegistry.set(file, url);
|
|
41
|
-
return url;
|
|
42
|
-
};
|
|
43
|
-
export const clearBlobFromMemory = (file) => {
|
|
44
|
-
const url = blobUrlRegistry.get(file);
|
|
45
|
-
if (!url)
|
|
46
|
-
return;
|
|
47
|
-
URL.revokeObjectURL(url);
|
|
48
|
-
blobUrlRegistry.delete(file);
|
|
49
|
-
};
|
|
50
|
-
/*
|
|
51
|
-
* Creates a blob URL with automatic cleanup after specified duration.
|
|
52
|
-
* Returns object with url and cancel function for lifecycle control.
|
|
53
|
-
*
|
|
54
|
-
* @param file - The file to create a URL for
|
|
55
|
-
* @param autoCleanupMs - Milliseconds before auto-cleanup (default: 5 minutes)
|
|
56
|
-
* @returns Object with url and cancel function
|
|
57
|
-
*/
|
|
58
|
-
export const createUrlStringWithAutoCleanup = (file, autoCleanupMs = 300_000) => {
|
|
59
|
-
const url = createUrlString(file);
|
|
60
|
-
const timer = setTimeout(() => {
|
|
61
|
-
clearBlobFromMemory(file);
|
|
62
|
-
}, autoCleanupMs);
|
|
63
|
-
return {
|
|
64
|
-
url,
|
|
65
|
-
cancel: () => {
|
|
66
|
-
clearTimeout(timer);
|
|
67
|
-
clearBlobFromMemory(file);
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
// VALIDATION FUNCTIONS
|
|
72
|
-
/*
|
|
73
|
-
* Checks if file type is in accepted types map.
|
|
74
|
-
* Uses 'in' operator for better performance than Boolean() conversion.
|
|
75
|
-
*/
|
|
76
|
-
export const isValidFileType = (file, acceptedTypes = defaultTypeExtensions) => file.type in acceptedTypes;
|
|
77
|
-
export const hasSurpassedMaxSize = (file, maxSize = maximumFileSize) => file.size > maxSize;
|
|
78
|
-
/*
|
|
79
|
-
* Returns true if ANY file exceeds the maximum size limit.
|
|
80
|
-
* Optimized with for-loop to avoid callback allocations in hot path.
|
|
81
|
-
*/
|
|
82
|
-
export const checkFilesMaximumSize = (files, max = maximumFileSize) => {
|
|
83
|
-
let i = 0;
|
|
84
|
-
while (i < files.length) {
|
|
85
|
-
if (files[i].size > max)
|
|
86
|
-
return true;
|
|
87
|
-
i++;
|
|
88
|
-
}
|
|
89
|
-
return false;
|
|
90
|
-
};
|
|
91
|
-
// DOCUMENT CREATION
|
|
92
|
-
/*
|
|
93
|
-
* Creates document data object with file metadata.
|
|
94
|
-
* Returns null if file type is not in allowableTypes to prevent invalid state.
|
|
95
|
-
*/
|
|
96
|
-
const createDocumentData = (file, allowableTypes = defaultTypeExtensions) => {
|
|
97
|
-
const type = allowableTypes[file.type];
|
|
98
|
-
if (!type)
|
|
99
|
-
return null;
|
|
100
|
-
return {
|
|
101
|
-
id: getFileId(file.name),
|
|
102
|
-
type,
|
|
103
|
-
file,
|
|
104
|
-
url: createUrlString(file),
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
/*
|
|
108
|
-
* Optimized SVG xmlns check - only reads first 2KB initially.
|
|
109
|
-
* Avoids toLowerCase() allocation and uses safer regex for replacement.
|
|
110
|
-
*/
|
|
111
|
-
export const SvgXmlnsAttributeCheck = async (file, allowableTypes = defaultTypeExtensions) => {
|
|
112
|
-
if (file.type !== "image/svg+xml") {
|
|
113
|
-
return createDocumentData(file, allowableTypes);
|
|
114
|
-
}
|
|
115
|
-
// OPTIMIZATION: Only read first 2KB to check for xmlns
|
|
116
|
-
const chunk = file.slice(0, 2048);
|
|
117
|
-
const text = await chunk.text();
|
|
118
|
-
// No toLowerCase() needed - xmlns attribute is case-sensitive in XML
|
|
119
|
-
if (text.includes("xmlns=")) {
|
|
120
|
-
return createDocumentData(file, allowableTypes);
|
|
121
|
-
}
|
|
122
|
-
// Missing the xmlns attribute, add it
|
|
123
|
-
// Need full file content for modification
|
|
124
|
-
const fullText = await file.text();
|
|
125
|
-
// SAFER: Use regex with word boundary instead of simple string replace
|
|
126
|
-
// Handles <svg> without space and various attribute orders
|
|
127
|
-
const svgWithXmlns = fullText.replace(/<svg\b/, xmlns);
|
|
128
|
-
return createDocumentData(new File([svgWithXmlns], file.name, {
|
|
129
|
-
type: file.type,
|
|
130
|
-
}), allowableTypes);
|
|
131
|
-
};
|
|
132
|
-
// FILE RENAMING
|
|
133
|
-
/*
|
|
134
|
-
* Renames a file or blob. Optimized to avoid unnecessary File creation
|
|
135
|
-
* if name already matches.
|
|
136
|
-
*/
|
|
137
|
-
export const renameFile = (file, name) => file instanceof File && file.name === name ? file : new File([file], name, { type: file.type });
|
|
138
|
-
/*
|
|
139
|
-
* Checks if file needs renaming based on ID comparison.
|
|
140
|
-
* - Handles Blobs (no name) by converting to File
|
|
141
|
-
* - Avoids repeated string operations
|
|
142
|
-
* - Case-sensitive comparison
|
|
143
|
-
*/
|
|
144
|
-
export const checkFile = (id, file) => {
|
|
145
|
-
// No ID provided, return as-is
|
|
146
|
-
if (!id)
|
|
147
|
-
return file;
|
|
148
|
-
// Handle Blob (not a File subclass)
|
|
149
|
-
if (!(file instanceof File)) {
|
|
150
|
-
return renameFile(file, id);
|
|
151
|
-
}
|
|
152
|
-
// It's a File - check if renaming is needed
|
|
153
|
-
const currentId = getFileId(file.name);
|
|
154
|
-
return id === currentId ? file : renameFile(file, id);
|
|
155
|
-
};
|
|
156
|
-
//# sourceMappingURL=processUploadedFiles.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"processUploadedFiles.js","sourceRoot":"","sources":["../../../src/shared/utils/processUploadedFiles.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,6CAA6C;AAC7C,yEAAyE;AAEzE,MAAM,CAAC,MAAM,qBAAqB,GAA2B;IAC3D,WAAW,EAAE,MAAM;IACnB,YAAY,EAAE,OAAO;IACrB,WAAW,EAAE,MAAM;IACnB,eAAe,EAAE,MAAM;IACvB,iBAAiB,EAAE,MAAM;IACzB,oBAAoB,EAAE,MAAM;IAC5B,yEAAyE,EAAE,OAAO;CACnF,CAAC;AAEF,+DAA+D;AAC/D,MAAM,KAAK,GAAG,yCAAyC,CAAC;AAExD,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AACrC,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAC,CAAC,QAAQ;AAC5C,MAAM,CAAC,MAAM,wBAAwB,GAAG,aAAa,CAAC;AAMtD,uDAAuD;AAEvD;;;;;GAKG;AACH,MAAM,SAAS,GAAG,CAAC,QAAgB,EAAU,EAAE;IAC7C,MAAM,YAAY,GAAG,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAC/C,OAAO,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AACvE,CAAC,CAAC;AAEF,uDAAuD;AAEvD;;;GAGG;AACH,MAAM,eAAe,GAAG,IAAI,OAAO,EAAgB,CAAC;AAEpD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAU,EAAU,EAAE;IACpD,MAAM,QAAQ,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