@umbraco-ui/uui-file-dropzone 1.3.0-rc.0 → 1.3.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/custom-elements.json +4 -6
- package/lib/index.js +37 -30
- package/lib/uui-file-dropzone.element.d.ts +8 -6
- package/package.json +5 -5
package/custom-elements.json
CHANGED
|
@@ -7,9 +7,8 @@
|
|
|
7
7
|
"attributes": [
|
|
8
8
|
{
|
|
9
9
|
"name": "accept",
|
|
10
|
-
"description": "Comma-separated list of accepted
|
|
11
|
-
"type": "string"
|
|
12
|
-
"default": "\"false\""
|
|
10
|
+
"description": "Comma-separated list of accepted mime types or file extensions (denoted with a `.`).\nIf this is left empty, it will allow all types.",
|
|
11
|
+
"type": "string"
|
|
13
12
|
},
|
|
14
13
|
{
|
|
15
14
|
"name": "multiple",
|
|
@@ -32,9 +31,8 @@
|
|
|
32
31
|
{
|
|
33
32
|
"name": "accept",
|
|
34
33
|
"attribute": "accept",
|
|
35
|
-
"description": "Comma-separated list of accepted
|
|
36
|
-
"type": "string"
|
|
37
|
-
"default": "\"false\""
|
|
34
|
+
"description": "Comma-separated list of accepted mime types or file extensions (denoted with a `.`).\nIf this is left empty, it will allow all types.",
|
|
35
|
+
"type": "string"
|
|
38
36
|
},
|
|
39
37
|
{
|
|
40
38
|
"name": "multiple",
|
package/lib/index.js
CHANGED
|
@@ -42,13 +42,33 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
42
42
|
let UUIFileDropzoneElement = class extends LabelMixin("", LitElement) {
|
|
43
43
|
constructor() {
|
|
44
44
|
super();
|
|
45
|
-
this.
|
|
45
|
+
this._acceptedFileExtensions = [];
|
|
46
|
+
this._acceptedMimeTypes = [];
|
|
46
47
|
this.multiple = false;
|
|
47
48
|
this.addEventListener("dragenter", this._onDragEnter, false);
|
|
48
49
|
this.addEventListener("dragleave", this._onDragLeave, false);
|
|
49
50
|
this.addEventListener("dragover", this._onDragOver, false);
|
|
50
51
|
this.addEventListener("drop", this._onDrop, false);
|
|
51
52
|
}
|
|
53
|
+
set accept(value) {
|
|
54
|
+
if (value) {
|
|
55
|
+
const mimetypes = [];
|
|
56
|
+
const fileextensions = [];
|
|
57
|
+
value.split(",").forEach((item) => {
|
|
58
|
+
item = item.trim().toLowerCase();
|
|
59
|
+
if (new RegExp("[a-z]+\\/[a-z*]", "s").test(item)) {
|
|
60
|
+
mimetypes.push(item);
|
|
61
|
+
} else {
|
|
62
|
+
fileextensions.push(item.replace(/^\./, ""));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
this._acceptedMimeTypes = mimetypes;
|
|
66
|
+
this._acceptedFileExtensions = fileextensions;
|
|
67
|
+
} else {
|
|
68
|
+
this._acceptedMimeTypes = [];
|
|
69
|
+
this._acceptedFileExtensions = [];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
52
72
|
/**
|
|
53
73
|
* Opens the native file picker to select a file.
|
|
54
74
|
* @method browse
|
|
@@ -60,30 +80,16 @@ let UUIFileDropzoneElement = class extends LabelMixin("", LitElement) {
|
|
|
60
80
|
super.connectedCallback();
|
|
61
81
|
demandCustomElement(this, "uui-symbol-file-dropzone");
|
|
62
82
|
}
|
|
63
|
-
_checkIsItDirectory(dtItem) {
|
|
64
|
-
return !dtItem.type ? dtItem.webkitGetAsEntry().isDirectory : false;
|
|
65
|
-
}
|
|
66
83
|
async _getAllFileEntries(dataTransferItemList) {
|
|
67
84
|
const fileEntries = [];
|
|
68
85
|
const queue = [...dataTransferItemList];
|
|
69
|
-
const acceptList = [];
|
|
70
|
-
const wildcards = [];
|
|
71
|
-
if (this.accept) {
|
|
72
|
-
this.accept.split(",").forEach((item) => {
|
|
73
|
-
if (item.includes("*")) {
|
|
74
|
-
wildcards.push(item.split("*")[0].trim().toLowerCase());
|
|
75
|
-
} else {
|
|
76
|
-
acceptList.push(item.trim().toLowerCase());
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
86
|
while (queue.length > 0) {
|
|
81
87
|
const entry = queue.shift();
|
|
82
88
|
if (entry.kind === "file") {
|
|
83
89
|
const file = entry.getAsFile();
|
|
84
90
|
if (!file)
|
|
85
91
|
continue;
|
|
86
|
-
if (this._isAccepted(
|
|
92
|
+
if (this._isAccepted(file)) {
|
|
87
93
|
fileEntries.push(file);
|
|
88
94
|
}
|
|
89
95
|
} else if (entry.kind === "directory") {
|
|
@@ -117,20 +123,21 @@ let UUIFileDropzoneElement = class extends LabelMixin("", LitElement) {
|
|
|
117
123
|
console.log(err);
|
|
118
124
|
}
|
|
119
125
|
}
|
|
120
|
-
_isAccepted(
|
|
121
|
-
if (
|
|
126
|
+
_isAccepted(file) {
|
|
127
|
+
if (this._acceptedFileExtensions.length === 0 && this._acceptedMimeTypes.length === 0) {
|
|
122
128
|
return true;
|
|
123
129
|
}
|
|
124
130
|
const fileType = file.type.toLowerCase();
|
|
125
|
-
const fileExtension =
|
|
126
|
-
if (
|
|
131
|
+
const fileExtension = file.name.split(".").pop();
|
|
132
|
+
if (fileExtension && this._acceptedFileExtensions.includes(fileExtension.toLowerCase())) {
|
|
127
133
|
return true;
|
|
128
134
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
135
|
+
for (const mimeType in this._acceptedMimeTypes) {
|
|
136
|
+
if (fileType === mimeType) {
|
|
137
|
+
return true;
|
|
138
|
+
} else if (mimeType.endsWith("/*") && fileType.startsWith(mimeType.replace("/*", ""))) {
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
134
141
|
}
|
|
135
142
|
return false;
|
|
136
143
|
}
|
|
@@ -205,18 +212,18 @@ UUIFileDropzoneElement.styles = [
|
|
|
205
212
|
backdrop-filter: blur(2px);
|
|
206
213
|
}
|
|
207
214
|
#dropzone.hover {
|
|
208
|
-
border-color: var(--uui-color-default
|
|
215
|
+
border-color: var(--uui-color-default,#1b264f);
|
|
209
216
|
}
|
|
210
217
|
#dropzone.hover::before {
|
|
211
218
|
content: '';
|
|
212
219
|
position: absolute;
|
|
213
220
|
inset: 0;
|
|
214
221
|
opacity: 0.2;
|
|
215
|
-
border-color: var(--uui-color-default
|
|
216
|
-
background-color: var(--uui-color-default
|
|
222
|
+
border-color: var(--uui-color-default,#1b264f);
|
|
223
|
+
background-color: var(--uui-color-default,#1b264f);
|
|
217
224
|
}
|
|
218
225
|
#symbol {
|
|
219
|
-
color: var(--uui-color-default
|
|
226
|
+
color: var(--uui-color-default,#1b264f);
|
|
220
227
|
max-width: 100%;
|
|
221
228
|
max-height: 100%;
|
|
222
229
|
}
|
|
@@ -237,7 +244,7 @@ __decorateClass([
|
|
|
237
244
|
], UUIFileDropzoneElement.prototype, "_dropzone", 2);
|
|
238
245
|
__decorateClass([
|
|
239
246
|
property({ type: String })
|
|
240
|
-
], UUIFileDropzoneElement.prototype, "accept",
|
|
247
|
+
], UUIFileDropzoneElement.prototype, "accept", 1);
|
|
241
248
|
__decorateClass([
|
|
242
249
|
property({ type: Boolean })
|
|
243
250
|
], UUIFileDropzoneElement.prototype, "multiple", 2);
|
|
@@ -10,17 +10,20 @@ export declare class UUIFileDropzoneElement extends UUIFileDropzoneElement_base
|
|
|
10
10
|
static styles: import("lit").CSSResult[];
|
|
11
11
|
private _input;
|
|
12
12
|
private _dropzone;
|
|
13
|
+
private _acceptedFileExtensions;
|
|
14
|
+
private _acceptedMimeTypes;
|
|
13
15
|
/**
|
|
14
|
-
* Comma-separated list of accepted
|
|
16
|
+
* Comma-separated list of accepted mime types or file extensions (denoted with a `.`).
|
|
17
|
+
* If this is left empty, it will allow all types.
|
|
18
|
+
*
|
|
15
19
|
* @type {string}
|
|
16
20
|
* @attr
|
|
17
|
-
* @default false
|
|
18
21
|
* @examples [
|
|
19
|
-
* "image/
|
|
20
|
-
* "gif
|
|
22
|
+
* "image/*,application/pdf",
|
|
23
|
+
* ".gif,.png,.jpg,.jpeg,.pdf",
|
|
21
24
|
* ]
|
|
22
25
|
*/
|
|
23
|
-
accept: string;
|
|
26
|
+
set accept(value: string);
|
|
24
27
|
/**
|
|
25
28
|
* Allows for multiple files to be selected.
|
|
26
29
|
* @type {boolean}
|
|
@@ -35,7 +38,6 @@ export declare class UUIFileDropzoneElement extends UUIFileDropzoneElement_base
|
|
|
35
38
|
browse(): void;
|
|
36
39
|
constructor();
|
|
37
40
|
connectedCallback(): void;
|
|
38
|
-
protected _checkIsItDirectory(dtItem: DataTransferItem): boolean;
|
|
39
41
|
private _getAllFileEntries;
|
|
40
42
|
private _readAllDirectoryEntries;
|
|
41
43
|
private _readEntriesPromise;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umbraco-ui/uui-file-dropzone",
|
|
3
|
-
"version": "1.3.0
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Umbraco",
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
"custom-elements.json"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@umbraco-ui/uui-base": "1.3.0
|
|
34
|
-
"@umbraco-ui/uui-symbol-file-dropzone": "1.3.0
|
|
33
|
+
"@umbraco-ui/uui-base": "1.3.0",
|
|
34
|
+
"@umbraco-ui/uui-symbol-file-dropzone": "1.3.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "npm run analyze && tsc --build --force && rollup -c rollup.config.js",
|
|
38
|
-
"clean": "tsc --build --clean && rimraf -g dist lib/*.js lib/**/*.js custom-elements.json",
|
|
38
|
+
"clean": "tsc --build --clean && rimraf -g dist lib/*.js lib/**/*.js *.tgz lib/**/*.d.ts custom-elements.json",
|
|
39
39
|
"analyze": "web-component-analyzer **/*.element.ts --outFile custom-elements.json"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
44
|
"homepage": "https://uui.umbraco.com/?path=/story/uui-file-dropzone",
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "e662ac3be21cef08076d1dbb978748c2dd30e596"
|
|
46
46
|
}
|