@umbraco-ui/uui-file-dropzone 1.2.1 → 1.3.0-rc.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
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"attributes": [
|
|
8
8
|
{
|
|
9
9
|
"name": "accept",
|
|
10
|
-
"description": "
|
|
10
|
+
"description": "Comma-separated list of accepted filetypes. Will allow all types if empty.",
|
|
11
11
|
"type": "string",
|
|
12
12
|
"default": "\"false\""
|
|
13
13
|
},
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
{
|
|
33
33
|
"name": "accept",
|
|
34
34
|
"attribute": "accept",
|
|
35
|
-
"description": "
|
|
35
|
+
"description": "Comma-separated list of accepted filetypes. Will allow all types if empty.",
|
|
36
36
|
"type": "string",
|
|
37
37
|
"default": "\"false\""
|
|
38
38
|
},
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
],
|
|
53
53
|
"events": [
|
|
54
54
|
{
|
|
55
|
-
"name": "
|
|
55
|
+
"name": "change",
|
|
56
56
|
"description": "fires when the a file has been selected."
|
|
57
57
|
}
|
|
58
58
|
],
|
|
@@ -3,5 +3,6 @@ import { UUIFileDropzoneElement } from './uui-file-dropzone.element';
|
|
|
3
3
|
export declare class UUIFileDropzoneEvent extends UUIEvent<{
|
|
4
4
|
files: File[];
|
|
5
5
|
}, UUIFileDropzoneElement> {
|
|
6
|
-
static readonly
|
|
6
|
+
static readonly CHANGE: string;
|
|
7
|
+
constructor(evName: string, eventInit?: any | null);
|
|
7
8
|
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -5,9 +5,28 @@ import { UUIEvent } from '@umbraco-ui/uui-base/lib/events';
|
|
|
5
5
|
import { LabelMixin } from '@umbraco-ui/uui-base/lib/mixins';
|
|
6
6
|
import { demandCustomElement } from '@umbraco-ui/uui-base/lib/utils';
|
|
7
7
|
|
|
8
|
+
var __defProp$1 = Object.defineProperty;
|
|
9
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
8
24
|
class UUIFileDropzoneEvent extends UUIEvent {
|
|
25
|
+
constructor(evName, eventInit = {}) {
|
|
26
|
+
super(evName, __spreadValues(__spreadValues({}, { bubbles: true }), eventInit));
|
|
27
|
+
}
|
|
9
28
|
}
|
|
10
|
-
UUIFileDropzoneEvent.
|
|
29
|
+
UUIFileDropzoneEvent.CHANGE = "change";
|
|
11
30
|
|
|
12
31
|
var __defProp = Object.defineProperty;
|
|
13
32
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -30,6 +49,10 @@ let UUIFileDropzoneElement = class extends LabelMixin("", LitElement) {
|
|
|
30
49
|
this.addEventListener("dragover", this._onDragOver, false);
|
|
31
50
|
this.addEventListener("drop", this._onDrop, false);
|
|
32
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Opens the native file picker to select a file.
|
|
54
|
+
* @method browse
|
|
55
|
+
*/
|
|
33
56
|
browse() {
|
|
34
57
|
this._input.click();
|
|
35
58
|
}
|
|
@@ -42,13 +65,10 @@ let UUIFileDropzoneElement = class extends LabelMixin("", LitElement) {
|
|
|
42
65
|
}
|
|
43
66
|
async _getAllFileEntries(dataTransferItemList) {
|
|
44
67
|
const fileEntries = [];
|
|
45
|
-
const queue = [];
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
68
|
+
const queue = [...dataTransferItemList];
|
|
69
|
+
const acceptList = [];
|
|
70
|
+
const wildcards = [];
|
|
49
71
|
if (this.accept) {
|
|
50
|
-
const acceptList = [];
|
|
51
|
-
const wildcards = [];
|
|
52
72
|
this.accept.split(",").forEach((item) => {
|
|
53
73
|
if (item.includes("*")) {
|
|
54
74
|
wildcards.push(item.split("*")[0].trim().toLowerCase());
|
|
@@ -56,36 +76,29 @@ let UUIFileDropzoneElement = class extends LabelMixin("", LitElement) {
|
|
|
56
76
|
acceptList.push(item.trim().toLowerCase());
|
|
57
77
|
}
|
|
58
78
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
)
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
while (queue.length > 0) {
|
|
74
|
-
const entry = queue.shift();
|
|
75
|
-
if (entry.isFile) {
|
|
76
|
-
fileEntries.push(entry);
|
|
77
|
-
} else if (entry.isDirectory) {
|
|
78
|
-
fileEntries.push(entry);
|
|
79
|
-
queue.push(
|
|
80
|
-
...await this._readAllDirectoryEntries(
|
|
81
|
-
entry.createReader()
|
|
82
|
-
)
|
|
83
|
-
);
|
|
79
|
+
}
|
|
80
|
+
while (queue.length > 0) {
|
|
81
|
+
const entry = queue.shift();
|
|
82
|
+
if (entry.kind === "file") {
|
|
83
|
+
const file = entry.getAsFile();
|
|
84
|
+
if (!file)
|
|
85
|
+
continue;
|
|
86
|
+
if (this._isAccepted(acceptList, wildcards, file)) {
|
|
87
|
+
fileEntries.push(file);
|
|
84
88
|
}
|
|
89
|
+
} else if (entry.kind === "directory") {
|
|
90
|
+
if ("webkitGetAsEntry" in entry === false)
|
|
91
|
+
continue;
|
|
92
|
+
const directory = entry.webkitGetAsEntry();
|
|
93
|
+
queue.push(
|
|
94
|
+
...await this._readAllDirectoryEntries(directory.createReader())
|
|
95
|
+
);
|
|
85
96
|
}
|
|
86
97
|
}
|
|
87
98
|
return fileEntries;
|
|
88
99
|
}
|
|
100
|
+
// Get all the entries (files or sub-directories) in a directory
|
|
101
|
+
// by calling readEntries until it returns empty array
|
|
89
102
|
async _readAllDirectoryEntries(directoryReader) {
|
|
90
103
|
const entries = [];
|
|
91
104
|
let readEntries = await this._readEntriesPromise(directoryReader);
|
|
@@ -104,13 +117,10 @@ let UUIFileDropzoneElement = class extends LabelMixin("", LitElement) {
|
|
|
104
117
|
console.log(err);
|
|
105
118
|
}
|
|
106
119
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
async _isAccepted(acceptList, wildcards, entry) {
|
|
113
|
-
const file = await this._getFile(entry);
|
|
120
|
+
_isAccepted(acceptList, wildcards, file) {
|
|
121
|
+
if (acceptList.length === 0 && wildcards.length === 0) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
114
124
|
const fileType = file.type.toLowerCase();
|
|
115
125
|
const fileExtension = "." + file.name.split(".")[1].toLowerCase();
|
|
116
126
|
if (acceptList.includes(fileExtension)) {
|
|
@@ -131,11 +141,11 @@ let UUIFileDropzoneElement = class extends LabelMixin("", LitElement) {
|
|
|
131
141
|
const items = (_a = e.dataTransfer) == null ? void 0 : _a.items;
|
|
132
142
|
if (items) {
|
|
133
143
|
let result = await this._getAllFileEntries(items);
|
|
134
|
-
if (this.multiple === false && result.length
|
|
144
|
+
if (this.multiple === false && result.length) {
|
|
135
145
|
result = [result[0]];
|
|
136
146
|
}
|
|
137
147
|
this.dispatchEvent(
|
|
138
|
-
new UUIFileDropzoneEvent(UUIFileDropzoneEvent.
|
|
148
|
+
new UUIFileDropzoneEvent(UUIFileDropzoneEvent.CHANGE, {
|
|
139
149
|
detail: { files: result }
|
|
140
150
|
})
|
|
141
151
|
);
|
|
@@ -155,7 +165,7 @@ let UUIFileDropzoneElement = class extends LabelMixin("", LitElement) {
|
|
|
155
165
|
_onFileInputChange() {
|
|
156
166
|
const files = this._input.files ? Array.from(this._input.files) : [];
|
|
157
167
|
this.dispatchEvent(
|
|
158
|
-
new UUIFileDropzoneEvent(UUIFileDropzoneEvent.
|
|
168
|
+
new UUIFileDropzoneEvent(UUIFileDropzoneEvent.CHANGE, {
|
|
159
169
|
detail: { files }
|
|
160
170
|
})
|
|
161
171
|
);
|
|
@@ -173,6 +183,7 @@ let UUIFileDropzoneElement = class extends LabelMixin("", LitElement) {
|
|
|
173
183
|
?multiple=${this.multiple}
|
|
174
184
|
@change=${this._onFileInputChange}
|
|
175
185
|
aria-label="${this.label}" />
|
|
186
|
+
<slot></slot>
|
|
176
187
|
</div>
|
|
177
188
|
`;
|
|
178
189
|
}
|
|
@@ -194,18 +205,18 @@ UUIFileDropzoneElement.styles = [
|
|
|
194
205
|
backdrop-filter: blur(2px);
|
|
195
206
|
}
|
|
196
207
|
#dropzone.hover {
|
|
197
|
-
border-color: var(--uui-color-default
|
|
208
|
+
border-color: var(--uui-color-default,var(--uui-palette-space-cadet));
|
|
198
209
|
}
|
|
199
210
|
#dropzone.hover::before {
|
|
200
211
|
content: '';
|
|
201
212
|
position: absolute;
|
|
202
213
|
inset: 0;
|
|
203
214
|
opacity: 0.2;
|
|
204
|
-
border-color: var(--uui-color-default
|
|
205
|
-
background-color: var(--uui-color-default
|
|
215
|
+
border-color: var(--uui-color-default,var(--uui-palette-space-cadet));
|
|
216
|
+
background-color: var(--uui-color-default,var(--uui-palette-space-cadet));
|
|
206
217
|
}
|
|
207
218
|
#symbol {
|
|
208
|
-
color: var(--uui-color-default
|
|
219
|
+
color: var(--uui-color-default,var(--uui-palette-space-cadet));
|
|
209
220
|
max-width: 100%;
|
|
210
221
|
max-height: 100%;
|
|
211
222
|
}
|
|
@@ -234,4 +245,4 @@ UUIFileDropzoneElement = __decorateClass([
|
|
|
234
245
|
defineElement("uui-file-dropzone")
|
|
235
246
|
], UUIFileDropzoneElement);
|
|
236
247
|
|
|
237
|
-
export { UUIFileDropzoneElement };
|
|
248
|
+
export { UUIFileDropzoneElement, UUIFileDropzoneEvent };
|
|
@@ -2,7 +2,7 @@ import { LitElement } from 'lit';
|
|
|
2
2
|
declare const UUIFileDropzoneElement_base: (new (...args: any[]) => import("@umbraco-ui/uui-base/lib/mixins").LabelMixinInterface) & typeof LitElement;
|
|
3
3
|
/**
|
|
4
4
|
* @element uui-file-dropzone
|
|
5
|
-
* @fires {UUIFileDropzoneEvent}
|
|
5
|
+
* @fires {UUIFileDropzoneEvent} change - fires when the a file has been selected.
|
|
6
6
|
* @slot - For the content of the dropzone
|
|
7
7
|
* @description - Dropzone for file upload. Supports native browsing and drag n drop.
|
|
8
8
|
*/
|
|
@@ -11,10 +11,14 @@ export declare class UUIFileDropzoneElement extends UUIFileDropzoneElement_base
|
|
|
11
11
|
private _input;
|
|
12
12
|
private _dropzone;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Comma-separated list of accepted filetypes. Will allow all types if empty.
|
|
15
15
|
* @type {string}
|
|
16
16
|
* @attr
|
|
17
17
|
* @default false
|
|
18
|
+
* @examples [
|
|
19
|
+
* "image/png,image/jpeg,image/gif",
|
|
20
|
+
* "gif,png,jpg,jpeg",
|
|
21
|
+
* ]
|
|
18
22
|
*/
|
|
19
23
|
accept: string;
|
|
20
24
|
/**
|
|
@@ -35,7 +39,6 @@ export declare class UUIFileDropzoneElement extends UUIFileDropzoneElement_base
|
|
|
35
39
|
private _getAllFileEntries;
|
|
36
40
|
private _readAllDirectoryEntries;
|
|
37
41
|
private _readEntriesPromise;
|
|
38
|
-
private _getFile;
|
|
39
42
|
private _isAccepted;
|
|
40
43
|
private _onDrop;
|
|
41
44
|
private _onDragOver;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umbraco-ui/uui-file-dropzone",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-rc.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.
|
|
34
|
-
"@umbraco-ui/uui-symbol-file-dropzone": "1.
|
|
33
|
+
"@umbraco-ui/uui-base": "1.3.0-rc.0",
|
|
34
|
+
"@umbraco-ui/uui-symbol-file-dropzone": "1.3.0-rc.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 dist lib/*.js lib/**/*.js custom-elements.json",
|
|
38
|
+
"clean": "tsc --build --clean && rimraf -g dist lib/*.js lib/**/*.js 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": "45c3824056586d9817efb3f61dc0bef5478747f0"
|
|
46
46
|
}
|