@mainframework/dropzone 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.
- package/LICENSE +21 -0
- package/README.md +113 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/shared/components/FileSelector/FileSelector.d.ts +3 -0
- package/dist/esm/shared/components/FileSelector/FileSelector.js +35 -0
- package/dist/esm/shared/components/FileSelector/FileSelector.js.map +1 -0
- package/dist/esm/shared/components/FileSelector/index.d.ts +1 -0
- package/dist/esm/shared/components/FileSelector/index.js +2 -0
- package/dist/esm/shared/components/FileSelector/index.js.map +1 -0
- package/dist/esm/shared/hooks/useCustomCallback.d.ts +1 -0
- package/dist/esm/shared/hooks/useCustomCallback.js +14 -0
- package/dist/esm/shared/hooks/useCustomCallback.js.map +1 -0
- package/dist/esm/shared/hooks/useFileSelector.d.ts +13 -0
- package/dist/esm/shared/hooks/useFileSelector.js +155 -0
- package/dist/esm/shared/hooks/useFileSelector.js.map +1 -0
- package/dist/esm/shared/types/types.d.ts +29 -0
- package/dist/esm/shared/types/types.js +2 -0
- package/dist/esm/shared/types/types.js.map +1 -0
- package/dist/esm/shared/utils/equalityChecks.d.ts +1 -0
- package/dist/esm/shared/utils/equalityChecks.js +41 -0
- package/dist/esm/shared/utils/equalityChecks.js.map +1 -0
- package/dist/esm/shared/utils/processUploadedFiles.d.ts +16 -0
- package/dist/esm/shared/utils/processUploadedFiles.js +124 -0
- package/dist/esm/shared/utils/processUploadedFiles.js.map +1 -0
- package/package.json +82 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Igor Gaponov (gapon2401)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
### A React package, that allows for the selection of files, through drag and drop or the File Dialog api
|
|
2
|
+
|
|
3
|
+
### Installation:
|
|
4
|
+
|
|
5
|
+
npm i @mainframework/dropzone
|
|
6
|
+
yarn @mainframework/dropzone
|
|
7
|
+
|
|
8
|
+
### Configuration and properties
|
|
9
|
+
|
|
10
|
+
`Hook config properties`
|
|
11
|
+
{
|
|
12
|
+
maximumUploadCount:5, //Defaults to 30
|
|
13
|
+
maximumFileSize = maxFileSize, //Defaults to 10 mb's
|
|
14
|
+
acceptedTypes = defaultTypeExtensions, //See the default extensions above
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
`Hook - returned properties`
|
|
18
|
+
|
|
19
|
+
```JS | TS
|
|
20
|
+
{
|
|
21
|
+
//Properties
|
|
22
|
+
validFiles, //These are the valid files selected
|
|
23
|
+
invalidFiles, //The invalid files a user attempted to select
|
|
24
|
+
|
|
25
|
+
//Methods
|
|
26
|
+
clearCache, // This will clear out the valid and invalid files
|
|
27
|
+
getValidFileStreams, //This will provde the actual File | Blobs that are within the valid Files
|
|
28
|
+
onCancel, //This will call clearCache
|
|
29
|
+
onIdChange, //Use this, if you want to change the name of a File.
|
|
30
|
+
onRemoveFile, //Remove a file from the valid files array
|
|
31
|
+
setMaximumFileSizeExceeded, //Use this for any errors generated, regarding the maximum file size
|
|
32
|
+
setMaximumUploadsExceeded, //Use this for any errors generated regarding the maximum number of uploads
|
|
33
|
+
|
|
34
|
+
//Component - Export the FileSelector: Use this ready made comopnent.
|
|
35
|
+
FileSelector: () => (
|
|
36
|
+
<FileSelector
|
|
37
|
+
inputId={"SomeID"} //Optional
|
|
38
|
+
messageParagraph={"A message to display in the dropzone"} //Optional - Defaults to "Drag 'n' drop some files here, or click to select files"
|
|
39
|
+
inputClassName={"some css classes"} //Optional - You can add your own css. The default is hidden, a tailwindcss class
|
|
40
|
+
clickableAreaClassName={"some css classes"} //Optional - You can add your own css. The default is composed of some tailwindclasses. It's either or.
|
|
41
|
+
dropZoneWrapperClassName={"some css classes"} //Optional - You can add your own css. The default is composed of some tailwindclasses. It's either or.
|
|
42
|
+
messageParagraphClassName={"some css classes"} //Optional - You can add your own css. The default is composed of some tailwindclasses. It's either or.
|
|
43
|
+
onChange={onInputChange}
|
|
44
|
+
onDragOver={onDragOver}
|
|
45
|
+
onDrop={onDrop}
|
|
46
|
+
onDragEnter={onDragEnter}
|
|
47
|
+
onDragLeave={onDragLeave}
|
|
48
|
+
/>
|
|
49
|
+
),
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```JS | TS
|
|
54
|
+
//Here are the default upload types the pacakge will handle. You can send in your own, so long as it's in the following format.
|
|
55
|
+
export const defaultTypeExtensions: Record<string, string> = {
|
|
56
|
+
"image/png": ".png",
|
|
57
|
+
"image/jpeg": ".jpeg",
|
|
58
|
+
"image/jpg": ".jpg",
|
|
59
|
+
"image/svg+xml": ".svg",
|
|
60
|
+
"application/pdf": ".pdf",
|
|
61
|
+
"application/msword": ".doc",
|
|
62
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": ".docx",
|
|
63
|
+
};
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Hook configuration
|
|
67
|
+
|
|
68
|
+
```JS | TS
|
|
69
|
+
//Here you can set the following properties for the FileSelector. These are all optional
|
|
70
|
+
const { validFiles, onIdChange, onCancel, onRemoveFile, FileSelector } = useFileSelector({
|
|
71
|
+
maximumUploadCount:5, //Defaults to 30
|
|
72
|
+
maximumFileSize = maxFileSize, //Defaults to 10 mb's
|
|
73
|
+
acceptedTypes = defaultTypeExtensions, //See the default extensions above
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Usage
|
|
79
|
+
|
|
80
|
+
### App.tsx
|
|
81
|
+
|
|
82
|
+
Once the package is installed, import the hook
|
|
83
|
+
|
|
84
|
+
```JS | TS
|
|
85
|
+
import { useFileSelector } from "@mainframework/dropzone";
|
|
86
|
+
|
|
87
|
+
export const App = ()=>{
|
|
88
|
+
//Note: You can set the following props for the hook maximumUploadCount, maximumFileSize, acceptedTypes
|
|
89
|
+
const { validFiles, onIdChange, onCancel, onRemoveFile, FileSelector } = useFileSelector();
|
|
90
|
+
|
|
91
|
+
const onSelect = () => {
|
|
92
|
+
if (Array.isArray(validFiles)) {
|
|
93
|
+
//This will be used to select the files. Won't be used here
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<>
|
|
99
|
+
<FileSelector /> {/*This is the component that will display the dropzone*/}
|
|
100
|
+
|
|
101
|
+
{validFiles.length > 0 && (
|
|
102
|
+
<PreviewImages //<---PreviewImages is a component where you render the images. It's up to you to provide this functionality
|
|
103
|
+
validFiles={validFiles}
|
|
104
|
+
onChange={onIdChange}
|
|
105
|
+
onSelect={onSelect}
|
|
106
|
+
onCancel={onCancel}
|
|
107
|
+
onRemoveFile={onRemoveFile}
|
|
108
|
+
/>
|
|
109
|
+
)}
|
|
110
|
+
</>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useFileSelector } from "./shared/hooks/useFileSelector";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { FileSelectorProps } from "../../types/types";
|
|
2
|
+
import "../../../tailwind.css";
|
|
3
|
+
export declare const FileSelector: ({ inputId, messageParagraph, inputClassName, clickableAreaClassName, dropZoneWrapperClassName, messageParagraphClassName, onChange, onDragOver, onDrop, onDragEnter, onDragLeave, }: FileSelectorProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import "../../../tailwind.css";
|
|
4
|
+
export var FileSelector = function (_a) {
|
|
5
|
+
var inputId = _a.inputId, messageParagraph = _a.messageParagraph, inputClassName = _a.inputClassName, clickableAreaClassName = _a.clickableAreaClassName, dropZoneWrapperClassName = _a.dropZoneWrapperClassName, messageParagraphClassName = _a.messageParagraphClassName, onChange = _a.onChange, onDragOver = _a.onDragOver, onDrop = _a.onDrop, onDragEnter = _a.onDragEnter, onDragLeave = _a.onDragLeave;
|
|
6
|
+
var fileInputRef = useRef(null);
|
|
7
|
+
var refCallback = function (ref) {
|
|
8
|
+
fileInputRef.current = ref;
|
|
9
|
+
};
|
|
10
|
+
var dropZoneButtonClickRef = useRef(function () {
|
|
11
|
+
var _a;
|
|
12
|
+
(_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click();
|
|
13
|
+
});
|
|
14
|
+
//Css classes
|
|
15
|
+
var inputClassesRef = useRef("hidden ".concat(inputClassName !== null && inputClassName !== void 0 ? inputClassName : ""));
|
|
16
|
+
var clickableAreaClassNameRef = useRef("".concat(clickableAreaClassName !== null && clickableAreaClassName !== void 0 ? clickableAreaClassName : "dropzone border-dashed border-2 border-silver-600 p-4 rounded-md text-center cursor-pointer bg-inherit hover:border-yellow-400 text-white font-bold py-2 px-4"));
|
|
17
|
+
var dropZoneWrapperClassNameRef = useRef("".concat(dropZoneWrapperClassName !== null && dropZoneWrapperClassName !== void 0 ? dropZoneWrapperClassName : "p-4 border border-gray-300 rounded-md shadow-md"));
|
|
18
|
+
var messageParagraphClassNameRef = useRef("".concat(messageParagraphClassName !== null && messageParagraphClassName !== void 0 ? messageParagraphClassName : "text-silver-600"));
|
|
19
|
+
var messageParagraphRef = useRef("".concat(messageParagraph !== null && messageParagraph !== void 0 ? messageParagraph : "Drag 'n' drop some files here, or click to select files"));
|
|
20
|
+
useEffect(function () {
|
|
21
|
+
//Wire up the drag and drop
|
|
22
|
+
var preventDefault = function (event) {
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
};
|
|
25
|
+
document.addEventListener("dragover", preventDefault);
|
|
26
|
+
document.addEventListener("drop", preventDefault);
|
|
27
|
+
return function () {
|
|
28
|
+
//Clean up
|
|
29
|
+
document.removeEventListener("dragover", preventDefault);
|
|
30
|
+
document.removeEventListener("drop", preventDefault);
|
|
31
|
+
};
|
|
32
|
+
}, []);
|
|
33
|
+
return (_jsxs("div", { className: dropZoneWrapperClassNameRef.current, draggable: false, children: [_jsx("button", { className: clickableAreaClassNameRef.current, onDragOver: onDragOver, onDrop: onDrop, onDragEnter: onDragEnter, onDragLeave: onDragLeave, onClick: dropZoneButtonClickRef.current, draggable: true, children: _jsx("p", { className: messageParagraphClassNameRef.current, children: messageParagraphRef.current }) }), _jsx("input", { ref: refCallback, id: inputId, type: "file", className: inputClassesRef.current, onChange: onChange, accept: ".png, .jpg, .jpeg, .pdf, .svg, image/svg+xml, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document", multiple: true })] }));
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=FileSelector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileSelector.js","sourceRoot":"","sources":["../../../../../src/shared/components/FileSelector/FileSelector.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAe,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGvD,OAAO,uBAAuB,CAAC;AAC/B,MAAM,CAAC,IAAM,YAAY,GAAG,UAAC,EAYT;QAXlB,OAAO,aAAA,EACP,gBAAgB,sBAAA,EAChB,cAAc,oBAAA,EACd,sBAAsB,4BAAA,EACtB,wBAAwB,8BAAA,EACxB,yBAAyB,+BAAA,EACzB,QAAQ,cAAA,EACR,UAAU,gBAAA,EACV,MAAM,YAAA,EACN,WAAW,iBAAA,EACX,WAAW,iBAAA;IAEX,IAAM,YAAY,GAAG,MAAM,CAA0B,IAAI,CAAC,CAAC;IAE3D,IAAM,WAAW,GAAkC,UAAC,GAAG;QACrD,YAAY,CAAC,OAAO,GAAG,GAAG,CAAC;IAC7B,CAAC,CAAC;IACF,IAAM,sBAAsB,GAAG,MAAM,CAAC;;QACpC,MAAA,YAAY,CAAC,OAAO,0CAAE,KAAK,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,aAAa;IACb,IAAM,eAAe,GAAG,MAAM,CAAS,iBAAU,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,EAAE,CAAE,CAAC,CAAC;IAEzE,IAAM,yBAAyB,GAAG,MAAM,CACtC,UAAG,sBAAsB,aAAtB,sBAAsB,cAAtB,sBAAsB,GAAI,gKAAgK,CAAE,CAChM,CAAC;IAEF,IAAM,2BAA2B,GAAG,MAAM,CACxC,UAAG,wBAAwB,aAAxB,wBAAwB,cAAxB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M,EAAC,2IAA2I,EAClJ,QAAQ,SACR,IACE,CACP,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FileSelector } from "./FileSelector";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/shared/components/FileSelector/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useCustomCallback: <T extends (...args: any[]) => unknown>(callback: T, dependencies: unknown[]) => T;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useCallback, useRef } from "react";
|
|
2
|
+
import { isEqual } from "../utils/equalityChecks";
|
|
3
|
+
//Need any here to get around TS not liking uknown. I don't know the shape of a function coming into this hook
|
|
4
|
+
export var useCustomCallback = function (callback, dependencies) {
|
|
5
|
+
var refDependencies = useRef([]);
|
|
6
|
+
if (refDependencies.current.length === 0 ||
|
|
7
|
+
!dependencies.every(function (dep, index) { return isEqual(dep, refDependencies.current[index]); })) {
|
|
8
|
+
//add the callback as a dependency to address the eslint error: react-hooks/exhaustive-deps
|
|
9
|
+
dependencies.push(callback);
|
|
10
|
+
refDependencies.current = dependencies;
|
|
11
|
+
}
|
|
12
|
+
return useCallback(callback, refDependencies.current);
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=useCustomCallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCustomCallback.js","sourceRoot":"","sources":["../../../../src/shared/hooks/useCustomCallback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,gHAAgH;AAChH,MAAM,CAAC,IAAM,iBAAiB,GAAG,UAAwC,QAAW,EAAE,YAAuB;IAC3G,IAAM,eAAe,GAAG,MAAM,CAAY,EAAE,CAAC,CAAC;IAE9C,IACE,eAAe,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;QACpC,CAAC,YAAY,CAAC,KAAK,CAAC,UAAC,GAAG,EAAE,KAAK,IAAK,OAAA,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAA5C,CAA4C,CAAC,EACjF,CAAC;QACD,2FAA2F;QAC3F,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC5B,eAAe,CAAC,OAAO,GAAG,YAAY,CAAC;IACzC,CAAC;IACD,OAAO,WAAW,CAAC,QAAQ,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;AACxD,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FileData, 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
|
+
setMaximumFileSizeExceeded: (status?: boolean) => void;
|
|
11
|
+
setMaximumUploadsExceeded: (status?: boolean, fileCount?: number, maximumUploads?: number) => void;
|
|
12
|
+
FileSelector: () => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { useCallback, useRef, useState } from "react";
|
|
14
|
+
import { defaultTypeExtensions, maximumUploadCount as maxUploadCount, maximumFileSize as maxFileSize, printableMaximumFileSize, checkFilesMaximumSize, isValidFileType, SvgXmlnsAttributeCheck, checkFile, } from "../utils/processUploadedFiles";
|
|
15
|
+
import { useCustomCallback } from "./useCustomCallback";
|
|
16
|
+
import { FileSelector } from "../components/FileSelector";
|
|
17
|
+
export var useFileSelector = function (_a) {
|
|
18
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.maximumUploadCount, maximumUploadCount = _c === void 0 ? maxUploadCount : _c, _d = _b.maximumFileSize, maximumFileSize = _d === void 0 ? maxFileSize : _d, _e = _b.acceptedTypes, acceptedTypes = _e === void 0 ? defaultTypeExtensions : _e;
|
|
19
|
+
//State
|
|
20
|
+
//Trigger a re-render
|
|
21
|
+
var _f = useState(0), setUpdateTrigger = _f[1];
|
|
22
|
+
var _g = useState([]), validFiles = _g[0], SetValidFiles = _g[1];
|
|
23
|
+
var _h = useState([]), invalidFiles = _h[0], SetInvalidFiles = _h[1];
|
|
24
|
+
//Refs
|
|
25
|
+
var maxUploadErrorRef = useRef({
|
|
26
|
+
status: false,
|
|
27
|
+
message: "",
|
|
28
|
+
});
|
|
29
|
+
var maxFileSizeErrorRef = useRef({
|
|
30
|
+
status: false,
|
|
31
|
+
message: "",
|
|
32
|
+
});
|
|
33
|
+
var setMaximumUploadsExceeded = useCallback(function (status, fileCount, maximumUploads) {
|
|
34
|
+
if (status === void 0) { status = false; }
|
|
35
|
+
maxUploadErrorRef.current.status = status;
|
|
36
|
+
maxUploadErrorRef.current.message = status
|
|
37
|
+
? "You have attempted to upload ".concat(fileCount, " files. The maximum allowable uploads for this feature is ").concat(maximumUploads)
|
|
38
|
+
: "";
|
|
39
|
+
setUpdateTrigger(function (state) { return (state += 1); });
|
|
40
|
+
}, []);
|
|
41
|
+
var setMaximumFileSizeExceeded = useCallback(function (status) {
|
|
42
|
+
if (status === void 0) { status = false; }
|
|
43
|
+
maxFileSizeErrorRef.current.status = status;
|
|
44
|
+
maxFileSizeErrorRef.current.message = status
|
|
45
|
+
? "You have attempted upload a file(s) that exceeds the maximum size of ".concat(printableMaximumFileSize)
|
|
46
|
+
: "";
|
|
47
|
+
setUpdateTrigger(function (state) { return (state += 1); });
|
|
48
|
+
}, []);
|
|
49
|
+
//Callbacks
|
|
50
|
+
var clearCache = useCallback(function () {
|
|
51
|
+
SetInvalidFiles([]);
|
|
52
|
+
SetValidFiles([]);
|
|
53
|
+
}, []);
|
|
54
|
+
var onCancel = useCallback(function () {
|
|
55
|
+
clearCache();
|
|
56
|
+
}, [clearCache]);
|
|
57
|
+
var getValidFileStreams = useCallback(function () { return (validFiles.length ? validFiles.map(function (_a) {
|
|
58
|
+
var file = _a.file;
|
|
59
|
+
return file;
|
|
60
|
+
}) : []); }, [validFiles]);
|
|
61
|
+
//Main Engine to deal with files
|
|
62
|
+
var processFiles = useCustomCallback(function (files) {
|
|
63
|
+
var maxFileSizeCheck = checkFilesMaximumSize(files, maximumFileSize) && !maxFileSizeErrorRef.current.status;
|
|
64
|
+
var maxUploadCountCheck = typeof maximumUploadCount !== "undefined"
|
|
65
|
+
? !maxUploadErrorRef.current.status && files.length > maximumUploadCount
|
|
66
|
+
: false;
|
|
67
|
+
if (maxFileSizeCheck || maxUploadCountCheck) {
|
|
68
|
+
if (maxFileSizeCheck)
|
|
69
|
+
setMaximumFileSizeExceeded(true);
|
|
70
|
+
if (maxUploadCountCheck)
|
|
71
|
+
setMaximumUploadsExceeded(true, files.length, maximumUploadCount);
|
|
72
|
+
onCancel();
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
var _a = files.reduce(function (acc, file) {
|
|
76
|
+
if (isValidFileType(file, acceptedTypes))
|
|
77
|
+
acc.valid.push(SvgXmlnsAttributeCheck(file, defaultTypeExtensions));
|
|
78
|
+
else
|
|
79
|
+
acc.invalid.push(file);
|
|
80
|
+
return acc;
|
|
81
|
+
}, { valid: [], invalid: [] }), valid = _a.valid, invalid = _a.invalid;
|
|
82
|
+
if (valid.length > 0) {
|
|
83
|
+
Promise.all(valid).then(function (results) {
|
|
84
|
+
//validFiles.next(results);
|
|
85
|
+
SetValidFiles(results);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (invalid.length > 0) {
|
|
89
|
+
//invalidFiles.next(invalid);
|
|
90
|
+
SetInvalidFiles(invalid);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}, [SvgXmlnsAttributeCheck, checkFilesMaximumSize, setMaximumFileSizeExceeded, setMaximumUploadsExceeded]);
|
|
94
|
+
var onRemoveFile = useCustomCallback(function (index) {
|
|
95
|
+
var updatedValidFiles = validFiles.filter(function (_, i) { return i !== index; });
|
|
96
|
+
SetValidFiles(updatedValidFiles);
|
|
97
|
+
}, [validFiles]);
|
|
98
|
+
var onIdChange = useCallback(function (index, id, files) {
|
|
99
|
+
var updatedValidFiles = files.map(function (fileData, i) {
|
|
100
|
+
if (i === index) {
|
|
101
|
+
var renamedFile = checkFile(id, fileData.file);
|
|
102
|
+
return __assign(__assign({}, fileData), { file: renamedFile, id: id });
|
|
103
|
+
}
|
|
104
|
+
return fileData;
|
|
105
|
+
});
|
|
106
|
+
SetValidFiles(updatedValidFiles);
|
|
107
|
+
}, []);
|
|
108
|
+
var onInputChange = useCustomCallback(function (event) {
|
|
109
|
+
var files = Array.from(event.target.files || []);
|
|
110
|
+
processFiles(files);
|
|
111
|
+
}, [processFiles]);
|
|
112
|
+
//Drag and Drop
|
|
113
|
+
var onDrop = useCustomCallback(function (e) {
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
processFiles(Array.from(e.dataTransfer.files));
|
|
116
|
+
}, [processFiles]);
|
|
117
|
+
var onDragOver = useCustomCallback(function (e) {
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
e.dataTransfer.dropEffect = "copy";
|
|
120
|
+
}, []);
|
|
121
|
+
var onDragEnter = useCustomCallback(function (e) {
|
|
122
|
+
e.preventDefault();
|
|
123
|
+
var classList = e.currentTarget.classList;
|
|
124
|
+
classList.add("border-yellow-400");
|
|
125
|
+
classList.remove("border-silver-600");
|
|
126
|
+
}, []);
|
|
127
|
+
var onDragLeave = useCustomCallback(function (e) {
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
var currentTarget = e.currentTarget;
|
|
130
|
+
var timeoutId = setTimeout(function () {
|
|
131
|
+
if (currentTarget && !currentTarget.contains(e.relatedTarget)) {
|
|
132
|
+
var classList = currentTarget.classList;
|
|
133
|
+
classList.remove("border-yellow-400");
|
|
134
|
+
classList.add("border-silver-600");
|
|
135
|
+
}
|
|
136
|
+
clearTimeout(timeoutId);
|
|
137
|
+
}, 200);
|
|
138
|
+
}, []);
|
|
139
|
+
return {
|
|
140
|
+
//Properties
|
|
141
|
+
validFiles: validFiles,
|
|
142
|
+
invalidFiles: invalidFiles,
|
|
143
|
+
//Methods
|
|
144
|
+
clearCache: clearCache,
|
|
145
|
+
getValidFileStreams: getValidFileStreams,
|
|
146
|
+
onCancel: onCancel,
|
|
147
|
+
onIdChange: onIdChange,
|
|
148
|
+
onRemoveFile: onRemoveFile,
|
|
149
|
+
setMaximumFileSizeExceeded: setMaximumFileSizeExceeded,
|
|
150
|
+
setMaximumUploadsExceeded: setMaximumUploadsExceeded,
|
|
151
|
+
//Component - Export the FileSelector
|
|
152
|
+
FileSelector: function () { return (_jsx(FileSelector, { onChange: onInputChange, onDragOver: onDragOver, onDrop: onDrop, onDragEnter: onDragEnter, onDragLeave: onDragLeave })); },
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=useFileSelector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFileSelector.js","sourceRoot":"","sources":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AAC,CAAC;IAEP,OAAO;QACL,YAAY;QACZ,UAAU,YAAA;QACV,YAAY,cAAA;QAEZ,SAAS;QACT,UAAU,YAAA;QACV,mBAAmB,qBAAA;QACnB,QAAQ,UAAA;QACR,UAAU,YAAA;QACV,YAAY,cAAA;QACZ,0BAA0B,4BAAA;QAC1B,yBAAyB,2BAAA;QAEzB,qCAAqC;QACrC,YAAY,EAAE,cAAM,OAAA,CAClB,KAAC,YAAY,IACX,QAAQ,EAAE,aAAa,EACvB,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,GACxB,CACH,EARmB,CAQnB;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ChangeEvent, DragEvent } from "react";
|
|
2
|
+
export interface FileSelectorProps {
|
|
3
|
+
inputId?: string;
|
|
4
|
+
messageParagraph?: string;
|
|
5
|
+
inputClassName?: string;
|
|
6
|
+
clickableAreaClassName?: string;
|
|
7
|
+
dropZoneWrapperClassName?: string;
|
|
8
|
+
messageParagraphClassName?: string;
|
|
9
|
+
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
10
|
+
onDragOver: (e: DragEvent<HTMLButtonElement>) => void;
|
|
11
|
+
onDrop: (e: DragEvent<HTMLButtonElement>) => void;
|
|
12
|
+
onDragEnter: (e: DragEvent<HTMLButtonElement>) => void;
|
|
13
|
+
onDragLeave: (e: DragEvent<HTMLButtonElement>) => void;
|
|
14
|
+
}
|
|
15
|
+
export interface IFileUploaderProps {
|
|
16
|
+
maximumUploadCount?: number;
|
|
17
|
+
maximumFileSize?: number;
|
|
18
|
+
acceptedTypes?: Record<string, string>;
|
|
19
|
+
}
|
|
20
|
+
export interface FileData {
|
|
21
|
+
id: string;
|
|
22
|
+
file: File | Blob;
|
|
23
|
+
url: string;
|
|
24
|
+
type: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ErrorMessage {
|
|
27
|
+
status: boolean;
|
|
28
|
+
message: string;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/shared/types/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isEqual: (a: unknown, b: unknown) => boolean;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export var isEqual = function (a, b) {
|
|
2
|
+
if (typeof a !== typeof b) {
|
|
3
|
+
return false; // Types are different
|
|
4
|
+
}
|
|
5
|
+
if (typeof a !== "object" || a === null) {
|
|
6
|
+
return a === b; // For non-object types, perform simple comparison
|
|
7
|
+
}
|
|
8
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
9
|
+
if (a.length !== b.length) {
|
|
10
|
+
return false; // Arrays have different lengths
|
|
11
|
+
}
|
|
12
|
+
var i = 0;
|
|
13
|
+
while (i < a.length) {
|
|
14
|
+
if (!isEqual(a[i], b[i])) {
|
|
15
|
+
return false; // Array elements are different
|
|
16
|
+
}
|
|
17
|
+
i += 1;
|
|
18
|
+
}
|
|
19
|
+
return true; // All array elements are equal
|
|
20
|
+
}
|
|
21
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
22
|
+
return false; // One is an array and the other is not, they can't be equal
|
|
23
|
+
}
|
|
24
|
+
var objA = a;
|
|
25
|
+
var objB = b;
|
|
26
|
+
var keysA = Object.keys(objA);
|
|
27
|
+
var keysB = Object.keys(objB);
|
|
28
|
+
if (keysA.length !== keysB.length) {
|
|
29
|
+
return false; // Objects have different number of keys
|
|
30
|
+
}
|
|
31
|
+
var j = 0;
|
|
32
|
+
while (j < keysA.length) {
|
|
33
|
+
var key = keysA[j];
|
|
34
|
+
if (!keysB.includes(key) || !isEqual(objA[key], objB[key])) {
|
|
35
|
+
return false; // Keys are different or their values are not equal
|
|
36
|
+
}
|
|
37
|
+
j += 1;
|
|
38
|
+
}
|
|
39
|
+
return true; // All keys and their values are equal
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=equalityChecks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"equalityChecks.js","sourceRoot":"","sources":["../../../../src/shared/utils/equalityChecks.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,OAAO,GAAG,UAAC,CAAU,EAAE,CAAU;IAC5C,IAAI,OAAO,CAAC,KAAK,OAAO,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC,CAAC,sBAAsB;IACtC,CAAC;IAED,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QACxC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,kDAAkD;IACpE,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACzC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;YAC1B,OAAO,KAAK,CAAC,CAAC,gCAAgC;QAChD,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;YACpB,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzB,OAAO,KAAK,CAAC,CAAC,+BAA+B;YAC/C,CAAC;YACD,CAAC,IAAI,CAAC,CAAC;QACT,CAAC;QAED,OAAO,IAAI,CAAC,CAAC,+BAA+B;IAC9C,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC,CAAC,4DAA4D;IAC5E,CAAC;IAED,IAAM,IAAI,GAAG,CAAqC,CAAC;IACnD,IAAM,IAAI,GAAG,CAAqC,CAAC;IAEnD,IAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,IAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEhC,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC,CAAC,wCAAwC;IACxD,CAAC;IAED,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QACxB,IAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACrB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAC3D,OAAO,KAAK,CAAC,CAAC,mDAAmD;QACnE,CAAC;QACD,CAAC,IAAI,CAAC,CAAC;IACT,CAAC;IAED,OAAO,IAAI,CAAC,CAAC,sCAAsC;AACrD,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const defaultTypeExtensions: Record<string, string>;
|
|
2
|
+
export declare const maximumUploadCount = 30;
|
|
3
|
+
export declare const maximumFileSize = 1000000;
|
|
4
|
+
export declare const printableMaximumFileSize = "5 Megabytes";
|
|
5
|
+
export declare const isValidFileType: (file: File, acceptedTypes?: Record<string, string>) => boolean;
|
|
6
|
+
export declare const hasSurpassedMaxSize: (file: File | Blob, maxSize?: number) => boolean;
|
|
7
|
+
export declare const checkFilesMaximumSize: (files: (File | Blob)[], maxFileSize?: number) => boolean;
|
|
8
|
+
export declare const createUrlString: (file: File) => string;
|
|
9
|
+
export declare const SvgXmlnsAttributeCheck: (file: File, allowableTypes?: Record<string, string>) => Promise<{
|
|
10
|
+
id: string;
|
|
11
|
+
type: string;
|
|
12
|
+
file: File;
|
|
13
|
+
url: string;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const renameFile: (file: File | Blob, newName: string) => File;
|
|
16
|
+
export declare const checkFile: (id: string, file: File | Blob) => File | Blob;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
38
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
39
|
+
if (ar || !(i in from)) {
|
|
40
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
41
|
+
ar[i] = from[i];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
45
|
+
};
|
|
46
|
+
//Use this to quickly get the file extensions
|
|
47
|
+
//TODO: This needs to be updatable by a dev, programmatically.
|
|
48
|
+
export var defaultTypeExtensions = {
|
|
49
|
+
"image/png": ".png",
|
|
50
|
+
"image/jpeg": ".jpeg",
|
|
51
|
+
"image/jpg": ".jpg",
|
|
52
|
+
"image/svg+xml": ".svg",
|
|
53
|
+
"application/pdf": ".pdf",
|
|
54
|
+
"application/msword": ".doc",
|
|
55
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": ".docx",
|
|
56
|
+
};
|
|
57
|
+
//This is the attribute that should be present in all svg files
|
|
58
|
+
var xmlns = "<svg xmlns='http://www.w3.org/2000/svg' ";
|
|
59
|
+
export var maximumUploadCount = 30;
|
|
60
|
+
export var maximumFileSize = 1e6; //5e6; //5 mb's
|
|
61
|
+
export var printableMaximumFileSize = "5 Megabytes";
|
|
62
|
+
export var isValidFileType = function (file, acceptedTypes) {
|
|
63
|
+
if (acceptedTypes === void 0) { acceptedTypes = defaultTypeExtensions; }
|
|
64
|
+
return Boolean(acceptedTypes[file.type]);
|
|
65
|
+
};
|
|
66
|
+
export var hasSurpassedMaxSize = function (file, maxSize) {
|
|
67
|
+
if (maxSize === void 0) { maxSize = maximumFileSize; }
|
|
68
|
+
return file.size > maxSize;
|
|
69
|
+
};
|
|
70
|
+
export var checkFilesMaximumSize = function (files, maxFileSize) {
|
|
71
|
+
if (maxFileSize === void 0) { maxFileSize = maximumFileSize; }
|
|
72
|
+
return files.every(function (file) { return hasSurpassedMaxSize(file, maxFileSize); });
|
|
73
|
+
};
|
|
74
|
+
export var createUrlString = function (file) { return URL.createObjectURL(file); };
|
|
75
|
+
var createDocumentData = function (file, allowableTypes) {
|
|
76
|
+
if (allowableTypes === void 0) { allowableTypes = defaultTypeExtensions; }
|
|
77
|
+
return ({
|
|
78
|
+
id: file.name.split(".")[0],
|
|
79
|
+
type: allowableTypes[file.type],
|
|
80
|
+
file: file,
|
|
81
|
+
url: createUrlString(file),
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
export var SvgXmlnsAttributeCheck = function (file_1) {
|
|
85
|
+
var args_1 = [];
|
|
86
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
87
|
+
args_1[_i - 1] = arguments[_i];
|
|
88
|
+
}
|
|
89
|
+
return __awaiter(void 0, __spreadArray([file_1], args_1, true), void 0, function (file, allowableTypes) {
|
|
90
|
+
var text, svgWithXmlns;
|
|
91
|
+
if (allowableTypes === void 0) { allowableTypes = defaultTypeExtensions; }
|
|
92
|
+
return __generator(this, function (_a) {
|
|
93
|
+
switch (_a.label) {
|
|
94
|
+
case 0:
|
|
95
|
+
if (file.type !== "image/svg+xml")
|
|
96
|
+
return [2 /*return*/, createDocumentData(file, allowableTypes)];
|
|
97
|
+
return [4 /*yield*/, file.text()];
|
|
98
|
+
case 1:
|
|
99
|
+
text = _a.sent();
|
|
100
|
+
if (text.includes("xmlns"))
|
|
101
|
+
return [2 /*return*/, createDocumentData(file, allowableTypes)];
|
|
102
|
+
svgWithXmlns = text.replace("<svg ", xmlns);
|
|
103
|
+
return [2 /*return*/, createDocumentData(new File([svgWithXmlns], file.name, {
|
|
104
|
+
type: file.type,
|
|
105
|
+
}), allowableTypes)];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
export var renameFile = function (file, newName) {
|
|
111
|
+
return new File([file], "".concat(newName), { type: file.type });
|
|
112
|
+
};
|
|
113
|
+
export var checkFile = function (id, file) {
|
|
114
|
+
//Blobs don't have a name, so we need to convert it to a file, then we can rename it
|
|
115
|
+
if (file instanceof Blob) {
|
|
116
|
+
return id.length > 0 ? renameFile(file, id) : file;
|
|
117
|
+
}
|
|
118
|
+
//It's a file, let's process it.
|
|
119
|
+
if (id.length === 0 || id.toLocaleLowerCase() === file.name.toLocaleLowerCase().split(".")[0]) {
|
|
120
|
+
return file;
|
|
121
|
+
}
|
|
122
|
+
return renameFile(file, id);
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=processUploadedFiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processUploadedFiles.js","sourceRoot":"","sources":["../../../../src/shared/utils/processUploadedFiles.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA6C;AAC7C,+DAA+D;AAC/D,MAAM,CAAC,IAAM,qBAAqB,GAA2B;IAC3D,WAAW,EAAE,MAAM;IACnB,YAAY,EAAE,OAAO;IACrB,WAAW,EAAE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AC9E,CAAC;IAED,gCAAgC;IAChC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC,iBAAiB,EAAE,KAAM,IAAa,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACxG,OAAO,IAAY,CAAC;IACtB,CAAC;IACD,OAAO,UAAU,CAAC,IAAmB,EAAE,EAAE,CAAC,CAAC;AAC7C,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mainframework/dropzone",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Package to handle the selection of files for upload",
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"module": "./dist/esm/index.js",
|
|
7
|
+
"types": "./dist/esm/index.d.ts",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/TerrySlack/mainframework-dropzone.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/TerrySlack/mainframework-dropzone/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/TerrySlack/mainframework-dropzone#readme",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build:css:dev": "npx tailwindcss -i ./src/index.css -o ./src/tailwind.css --watch",
|
|
18
|
+
"build:css:prod": "npx tailwindcss -i ./src/index.css -o ./src/tailwind.css --minify ",
|
|
19
|
+
"husky": "husky",
|
|
20
|
+
"clean": "rimraf dist",
|
|
21
|
+
"lint": "eslint --ext 'ts,tsx' --max-warnings=0 --fix",
|
|
22
|
+
"lint-staged": "lint-staged",
|
|
23
|
+
"prebuild": "yarn husky && yarn clean",
|
|
24
|
+
"build": "cross-env yarn prebuild && yarn build:css:prod && yarn build:esm",
|
|
25
|
+
"build:esm": "tsc",
|
|
26
|
+
"build:cjs": "tsc --module commonjs --outDir dist/cjs",
|
|
27
|
+
"test": "jest --config jestconfig.json"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"react": ">=17"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"LICENSE",
|
|
35
|
+
"README.md"
|
|
36
|
+
],
|
|
37
|
+
"keywords": [
|
|
38
|
+
"react",
|
|
39
|
+
"typescript",
|
|
40
|
+
"awesome-project"
|
|
41
|
+
],
|
|
42
|
+
"author": "Terry Slack",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"husky": {
|
|
45
|
+
"hooks": {
|
|
46
|
+
"pre-commit": "npm run lint-staged && git add --all"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"lint-staged": {
|
|
50
|
+
"*.(ts|tsx)": [
|
|
51
|
+
"eslint --fix",
|
|
52
|
+
"prettier --write"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@tailwindcss/aspect-ratio": "^0.4.2",
|
|
57
|
+
"@tailwindcss/forms": "^0.5.7",
|
|
58
|
+
"@testing-library/react": "^16.0.0",
|
|
59
|
+
"@types/jest": "^29.5.12",
|
|
60
|
+
"@types/react": "^18.3.3",
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
62
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
63
|
+
"cross-env": "^7.0.3",
|
|
64
|
+
"eslint": "^8.57.0",
|
|
65
|
+
"eslint-config-prettier": "^9.1.0",
|
|
66
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
67
|
+
"eslint-plugin-react": "^7.35.0",
|
|
68
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
|
69
|
+
"husky": "^9.1.4",
|
|
70
|
+
"jest": "^29.7.0",
|
|
71
|
+
"jest-canvas-mock": "^2.5.2",
|
|
72
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
73
|
+
"lint-staged": "^15.2.7",
|
|
74
|
+
"prettier": "^3.2.5",
|
|
75
|
+
"react": "^18.3.1",
|
|
76
|
+
"rimraf": "^6.0.1",
|
|
77
|
+
"tailwindcss": "^3.4.7",
|
|
78
|
+
"ts-jest": "^29.2.3",
|
|
79
|
+
"tslib": "^2.6.3",
|
|
80
|
+
"typescript": "^5.5.4"
|
|
81
|
+
}
|
|
82
|
+
}
|