wj-elements 0.7.6 → 0.8.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/dist/animations.js +28 -51
- package/dist/animations.js.map +1 -1
- package/dist/base-path.js +19 -31
- package/dist/base-path.js.map +1 -1
- package/dist/custom-elements.json +9053 -9048
- package/dist/dark.css +1 -302
- package/dist/date.js +16 -36
- package/dist/date.js.map +1 -1
- package/dist/element-utils.js +20 -81
- package/dist/element-utils.js.map +1 -1
- package/dist/event.js +49 -165
- package/dist/event.js.map +1 -1
- package/dist/form-associated-element-BjeJn7j8.js +101 -0
- package/dist/{form-associated-element-DEQ4y-jn.js.map → form-associated-element-BjeJn7j8.js.map} +1 -1
- package/dist/icon-DmsqtDpL.js +102 -0
- package/dist/{icon-CReYMzAK.js.map → icon-DmsqtDpL.js.map} +1 -1
- package/dist/light.css +1 -731
- package/dist/localize.js +36 -111
- package/dist/localize.js.map +1 -1
- package/dist/packages/wje-accordion-item/accordion-item.element.d.ts +3 -2
- package/dist/packages/wje-img/img.element.d.ts +4 -4
- package/dist/permissions.js +14 -41
- package/dist/permissions.js.map +1 -1
- package/dist/popup.element-CbkhthPP.js +806 -0
- package/dist/{popup.element-CwXvVFK7.js.map → popup.element-CbkhthPP.js.map} +1 -1
- package/dist/router-links-CNsJ-elb.js +105 -0
- package/dist/{router-links-wjqCnncc.js.map → router-links-CNsJ-elb.js.map} +1 -1
- package/dist/skeleton.css +1 -197
- package/dist/styles.css +1 -866
- package/dist/universal-service.js +48 -109
- package/dist/universal-service.js.map +1 -1
- package/dist/utils.js +11 -18
- package/dist/utils.js.map +1 -1
- package/dist/web-types.json +698 -698
- package/dist/wje-accordion-item.js +33 -106
- package/dist/wje-accordion-item.js.map +1 -1
- package/dist/wje-accordion.js +19 -84
- package/dist/wje-accordion.js.map +1 -1
- package/dist/wje-animation.js +37 -4258
- package/dist/wje-animation.js.map +1 -1
- package/dist/wje-aside.js +9 -34
- package/dist/wje-aside.js.map +1 -1
- package/dist/wje-avatar.js +36 -126
- package/dist/wje-avatar.js.map +1 -1
- package/dist/wje-badge.js +10 -52
- package/dist/wje-badge.js.map +1 -1
- package/dist/wje-breadcrumb.js +205 -668
- package/dist/wje-breadcrumb.js.map +1 -1
- package/dist/wje-breadcrumbs.js +177 -633
- package/dist/wje-breadcrumbs.js.map +1 -1
- package/dist/wje-button-group.js +48 -153
- package/dist/wje-button-group.js.map +1 -1
- package/dist/wje-button.js +92 -413
- package/dist/wje-button.js.map +1 -1
- package/dist/wje-card-content.js +7 -30
- package/dist/wje-card-content.js.map +1 -1
- package/dist/wje-card-controls.js +7 -30
- package/dist/wje-card-controls.js.map +1 -1
- package/dist/wje-card-header.js +7 -30
- package/dist/wje-card-header.js.map +1 -1
- package/dist/wje-card-subtitle.js +7 -34
- package/dist/wje-card-subtitle.js.map +1 -1
- package/dist/wje-card-title.js +7 -34
- package/dist/wje-card-title.js.map +1 -1
- package/dist/wje-card.js +15 -71
- package/dist/wje-card.js.map +1 -1
- package/dist/wje-carousel-item.js +12 -56
- package/dist/wje-carousel-item.js.map +1 -1
- package/dist/wje-carousel.js +154 -509
- package/dist/wje-carousel.js.map +1 -1
- package/dist/wje-checkbox.js +50 -227
- package/dist/wje-checkbox.js.map +1 -1
- package/dist/wje-chip.js +43 -160
- package/dist/wje-chip.js.map +1 -1
- package/dist/wje-col.js +7 -20
- package/dist/wje-col.js.map +1 -1
- package/dist/wje-color-picker.js +445 -1464
- package/dist/wje-color-picker.js.map +1 -1
- package/dist/wje-container.js +9 -35
- package/dist/wje-container.js.map +1 -1
- package/dist/wje-copy-button.js +64 -204
- package/dist/wje-copy-button.js.map +1 -1
- package/dist/wje-dialog.js +85 -553
- package/dist/wje-dialog.js.map +1 -1
- package/dist/wje-divider.js +7 -34
- package/dist/wje-divider.js.map +1 -1
- package/dist/wje-dropdown.js +78 -305
- package/dist/wje-dropdown.js.map +1 -1
- package/dist/wje-element.js +191 -700
- package/dist/wje-element.js.map +1 -1
- package/dist/wje-file-upload-item.js +51 -156
- package/dist/wje-file-upload-item.js.map +1 -1
- package/dist/wje-file-upload.js +181 -619
- package/dist/wje-file-upload.js.map +1 -1
- package/dist/wje-footer.js +7 -31
- package/dist/wje-footer.js.map +1 -1
- package/dist/wje-form.js +7 -32
- package/dist/wje-form.js.map +1 -1
- package/dist/wje-format-digital.js +26 -118
- package/dist/wje-format-digital.js.map +1 -1
- package/dist/wje-grid.js +7 -33
- package/dist/wje-grid.js.map +1 -1
- package/dist/wje-header.js +9 -35
- package/dist/wje-header.js.map +1 -1
- package/dist/wje-icon-library.js +12 -18
- package/dist/wje-icon-library.js.map +1 -1
- package/dist/wje-icon-picker.js +65 -320
- package/dist/wje-icon-picker.js.map +1 -1
- package/dist/wje-icon.js +1 -1
- package/dist/wje-img-comparer.js +37 -114
- package/dist/wje-img-comparer.js.map +1 -1
- package/dist/wje-img.js +50 -197
- package/dist/wje-img.js.map +1 -1
- package/dist/wje-infinite-scroll.js +94 -346
- package/dist/wje-infinite-scroll.js.map +1 -1
- package/dist/wje-input-file.js +23 -84
- package/dist/wje-input-file.js.map +1 -1
- package/dist/wje-input.js +78 -392
- package/dist/wje-input.js.map +1 -1
- package/dist/wje-item.js +11 -64
- package/dist/wje-item.js.map +1 -1
- package/dist/wje-kanban.js +124 -401
- package/dist/wje-kanban.js.map +1 -1
- package/dist/wje-label.js +9 -32
- package/dist/wje-label.js.map +1 -1
- package/dist/wje-level-indicator.js +38 -157
- package/dist/wje-level-indicator.js.map +1 -1
- package/dist/wje-list.js +10 -40
- package/dist/wje-list.js.map +1 -1
- package/dist/wje-main.js +7 -31
- package/dist/wje-main.js.map +1 -1
- package/dist/wje-masonry.js +66 -211
- package/dist/wje-masonry.js.map +1 -1
- package/dist/wje-master.js +45 -161
- package/dist/wje-master.js.map +1 -1
- package/dist/wje-menu-button.js +10 -38
- package/dist/wje-menu-button.js.map +1 -1
- package/dist/wje-menu-item.js +127 -577
- package/dist/wje-menu-item.js.map +1 -1
- package/dist/wje-menu-label.js +9 -35
- package/dist/wje-menu-label.js.map +1 -1
- package/dist/wje-menu.js +14 -49
- package/dist/wje-menu.js.map +1 -1
- package/dist/wje-option.js +48 -279
- package/dist/wje-option.js.map +1 -1
- package/dist/wje-options.js +130 -384
- package/dist/wje-options.js.map +1 -1
- package/dist/wje-orgchart-group.js +16 -52
- package/dist/wje-orgchart-group.js.map +1 -1
- package/dist/wje-orgchart-item.js +24 -93
- package/dist/wje-orgchart-item.js.map +1 -1
- package/dist/wje-orgchart.js +18 -68
- package/dist/wje-orgchart.js.map +1 -1
- package/dist/wje-pagination.js +113 -397
- package/dist/wje-pagination.js.map +1 -1
- package/dist/wje-popup.js +3 -3
- package/dist/wje-popup.js.map +1 -1
- package/dist/wje-progress-bar.js +53 -205
- package/dist/wje-progress-bar.js.map +1 -1
- package/dist/wje-qr-code.js +398 -2980
- package/dist/wje-qr-code.js.map +1 -1
- package/dist/wje-radio-group.js +52 -190
- package/dist/wje-radio-group.js.map +1 -1
- package/dist/wje-radio.js +24 -118
- package/dist/wje-radio.js.map +1 -1
- package/dist/wje-rate.js +62 -266
- package/dist/wje-rate.js.map +1 -1
- package/dist/wje-relative-time.js +24 -99
- package/dist/wje-relative-time.js.map +1 -1
- package/dist/wje-reorder-dropzone.js +9 -31
- package/dist/wje-reorder-dropzone.js.map +1 -1
- package/dist/wje-reorder-handle.js +67 -204
- package/dist/wje-reorder-handle.js.map +1 -1
- package/dist/wje-reorder-item.js +14 -44
- package/dist/wje-reorder-item.js.map +1 -1
- package/dist/wje-reorder.js +61 -246
- package/dist/wje-reorder.js.map +1 -1
- package/dist/wje-route.js +6 -24
- package/dist/wje-route.js.map +1 -1
- package/dist/wje-router-link.js +11 -39
- package/dist/wje-router-link.js.map +1 -1
- package/dist/wje-router-outlet.js +76 -172
- package/dist/wje-router-outlet.js.map +1 -1
- package/dist/wje-routerx.js +537 -1331
- package/dist/wje-routerx.js.map +1 -1
- package/dist/wje-row.js +9 -31
- package/dist/wje-row.js.map +1 -1
- package/dist/wje-select.js +326 -1152
- package/dist/wje-select.js.map +1 -1
- package/dist/wje-slider.js +44 -225
- package/dist/wje-slider.js.map +1 -1
- package/dist/wje-sliding-container.js +295 -1319
- package/dist/wje-sliding-container.js.map +1 -1
- package/dist/wje-split-view.js +35 -121
- package/dist/wje-split-view.js.map +1 -1
- package/dist/wje-status.js +14 -45
- package/dist/wje-status.js.map +1 -1
- package/dist/wje-step.js +9 -32
- package/dist/wje-step.js.map +1 -1
- package/dist/wje-stepper.js +109 -357
- package/dist/wje-stepper.js.map +1 -1
- package/dist/wje-store.js +67 -360
- package/dist/wje-store.js.map +1 -1
- package/dist/wje-tab-group.js +85 -314
- package/dist/wje-tab-group.js.map +1 -1
- package/dist/wje-tab-panel.js +7 -28
- package/dist/wje-tab-panel.js.map +1 -1
- package/dist/wje-tab.js +21 -198
- package/dist/wje-tab.js.map +1 -1
- package/dist/wje-textarea.js +64 -264
- package/dist/wje-textarea.js.map +1 -1
- package/dist/wje-thumbnail.js +10 -51
- package/dist/wje-thumbnail.js.map +1 -1
- package/dist/wje-toast.js +127 -632
- package/dist/wje-toast.js.map +1 -1
- package/dist/wje-toggle.js +52 -177
- package/dist/wje-toggle.js.map +1 -1
- package/dist/wje-toolbar-action.js +128 -456
- package/dist/wje-toolbar-action.js.map +1 -1
- package/dist/wje-toolbar.js +75 -270
- package/dist/wje-toolbar.js.map +1 -1
- package/dist/wje-tooltip.js +50 -161
- package/dist/wje-tooltip.js.map +1 -1
- package/dist/wje-tree-item.js +70 -301
- package/dist/wje-tree-item.js.map +1 -1
- package/dist/wje-tree.js +145 -489
- package/dist/wje-tree.js.map +1 -1
- package/dist/wje-visually-hidden.js +7 -34
- package/dist/wje-visually-hidden.js.map +1 -1
- package/package.json +4 -2
- package/dist/form-associated-element-DEQ4y-jn.js +0 -245
- package/dist/icon-CReYMzAK.js +0 -245
- package/dist/popup.element-CwXvVFK7.js +0 -2133
- package/dist/router-links-wjqCnncc.js +0 -156
package/dist/wje-file-upload.js
CHANGED
|
@@ -1,700 +1,262 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import { Localizer } from "./localize.js";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { isValidFileType } from "./utils.js";
|
|
8
|
-
import { event } from "./event.js";
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
type: ["zip", "rar", "cab", "jar", "tar", "gzip", "uue", "bz2", "scorm", "war"],
|
|
17
|
-
name: "file-type-zip"
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
type: ["mov", "mp4", "avi", "flv"],
|
|
21
|
-
name: "video"
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
type: ["m4a", "mp3", "wav"],
|
|
25
|
-
name: "audio"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
type: ["html", "html"],
|
|
29
|
-
name: "file-type-html"
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
type: ["css"],
|
|
33
|
-
name: "code"
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
type: ["txt"],
|
|
37
|
-
name: "file-type-txt"
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
type: [
|
|
41
|
-
"doc",
|
|
42
|
-
"docx",
|
|
43
|
-
"msword",
|
|
44
|
-
"vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
45
|
-
"vnd.ms-word.document.macroenabled.12",
|
|
46
|
-
"vnd.openxmlformats-officedocument.wordprocessingml.template",
|
|
47
|
-
"vnd.ms-word.template.macroenabled.12",
|
|
48
|
-
"vnd.oasis.opendocument.text"
|
|
49
|
-
],
|
|
50
|
-
name: "file-type-doc"
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
type: [
|
|
54
|
-
"xls",
|
|
55
|
-
"xlsx",
|
|
56
|
-
"vnd.ms-excel",
|
|
57
|
-
"vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
58
|
-
"vnd.ms-excel.sheet.macroenabled.12",
|
|
59
|
-
"vnd.openxmlformats-officedocument.spreadsheetml.template",
|
|
60
|
-
"vnd.ms-excel.template.macroenabled.12",
|
|
61
|
-
"vnd.ms-excel.addin.macroenabled.12",
|
|
62
|
-
"vnd.ms-excel.sheet.binary.macroenabled.12",
|
|
63
|
-
"vnd.oasis.opendocument.spreadsheet"
|
|
64
|
-
],
|
|
65
|
-
name: "file-type-xls"
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
type: ["pdf"],
|
|
69
|
-
name: "file-type-pdf"
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
type: [
|
|
73
|
-
"ppt",
|
|
74
|
-
"pptx",
|
|
75
|
-
"odp",
|
|
76
|
-
"vnd.ms-powerpoint",
|
|
77
|
-
"vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
78
|
-
"vnd.ms-powerpoint.presentation.macroenabled.12",
|
|
79
|
-
"vnd.openxmlformats-officedocument.presentationml.slideshow",
|
|
80
|
-
"vnd.ms-powerpoint.slideshow.macroenabled.12",
|
|
81
|
-
"vnd.openxmlformats-officedocument.presentationml.template",
|
|
82
|
-
"vnd.ms-powerpoint.template.macroenabled.12",
|
|
83
|
-
"vnd.oasis.opendocument.presentation"
|
|
84
|
-
],
|
|
85
|
-
name: "file-type-ppt"
|
|
86
|
-
}
|
|
87
|
-
];
|
|
4
|
+
import { Localizer as e } from "./localize.js";
|
|
5
|
+
import t from "./wje-element.js";
|
|
6
|
+
import i from "./wje-button.js";
|
|
7
|
+
import { isValidFileType as s } from "./utils.js";
|
|
8
|
+
import { event as r } from "./event.js";
|
|
9
|
+
function a(e2) {
|
|
10
|
+
let t2;
|
|
11
|
+
return e2 ? ("folder" !== e2.toLowerCase() ? [{ type: ["jpg", "jpeg", "png", "gif", "bpm", "tiff", "svg"], name: "photo" }, { type: ["zip", "rar", "cab", "jar", "tar", "gzip", "uue", "bz2", "scorm", "war"], name: "file-type-zip" }, { type: ["mov", "mp4", "avi", "flv"], name: "video" }, { type: ["m4a", "mp3", "wav"], name: "audio" }, { type: ["html", "html"], name: "file-type-html" }, { type: ["css"], name: "code" }, { type: ["txt"], name: "file-type-txt" }, { type: ["doc", "docx", "msword", "vnd.openxmlformats-officedocument.wordprocessingml.document", "vnd.ms-word.document.macroenabled.12", "vnd.openxmlformats-officedocument.wordprocessingml.template", "vnd.ms-word.template.macroenabled.12", "vnd.oasis.opendocument.text"], name: "file-type-doc" }, { type: ["xls", "xlsx", "vnd.ms-excel", "vnd.openxmlformats-officedocument.spreadsheetml.sheet", "vnd.ms-excel.sheet.macroenabled.12", "vnd.openxmlformats-officedocument.spreadsheetml.template", "vnd.ms-excel.template.macroenabled.12", "vnd.ms-excel.addin.macroenabled.12", "vnd.ms-excel.sheet.binary.macroenabled.12", "vnd.oasis.opendocument.spreadsheet"], name: "file-type-xls" }, { type: ["pdf"], name: "file-type-pdf" }, { type: ["ppt", "pptx", "odp", "vnd.ms-powerpoint", "vnd.openxmlformats-officedocument.presentationml.presentation", "vnd.ms-powerpoint.presentation.macroenabled.12", "vnd.openxmlformats-officedocument.presentationml.slideshow", "vnd.ms-powerpoint.slideshow.macroenabled.12", "vnd.openxmlformats-officedocument.presentationml.template", "vnd.ms-powerpoint.template.macroenabled.12", "vnd.oasis.opendocument.presentation"], name: "file-type-ppt" }].forEach((i2) => {
|
|
12
|
+
i2.type.includes(e2.toLowerCase()) && (t2 = i2.name);
|
|
13
|
+
}) : t2 = "folder", t2) : t2;
|
|
88
14
|
}
|
|
89
|
-
function
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return
|
|
93
|
-
|
|
94
|
-
if (type.toLowerCase() !== "folder") {
|
|
95
|
-
fileType().forEach((i) => {
|
|
96
|
-
if (i.type.includes(type.toLowerCase())) {
|
|
97
|
-
searchType = i.name;
|
|
98
|
-
}
|
|
15
|
+
function l(e2, t2 = 1048576, i2 = false) {
|
|
16
|
+
return i2 ? (t3, i3) => (function(e3, t4, i4) {
|
|
17
|
+
const s2 = new FormData();
|
|
18
|
+
return s2.append("file", t4), fetch(e3, { method: "POST", body: s2 }).then((e4) => e4.json()).then((e4) => (i4.setAttribute("uploaded", t4.size), { data: e4, file: t4 })).catch((e4) => {
|
|
19
|
+
console.error("Error:", e4);
|
|
99
20
|
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return (file, preview) => uploadFileInChunks(url, file, preview, chunkSize);
|
|
110
|
-
}
|
|
111
|
-
async function uploadFileInChunks(url, file, preview, chunkSize = 1024 * 1024) {
|
|
112
|
-
let offset = 0;
|
|
113
|
-
const totalChunks = Math.ceil(file.size / chunkSize);
|
|
114
|
-
const partResponses = [];
|
|
115
|
-
while (offset < file.size) {
|
|
116
|
-
const chunk = file.slice(offset, offset + chunkSize);
|
|
117
|
-
const stream = new ReadableStream({
|
|
118
|
-
start(controller) {
|
|
119
|
-
const reader = chunk.stream().getReader();
|
|
120
|
-
let uploadedBytes = 0;
|
|
121
|
-
reader.read().then(function process({ done, value }) {
|
|
122
|
-
if (done) {
|
|
123
|
-
controller.close();
|
|
124
|
-
return Promise.resolve();
|
|
125
|
-
}
|
|
126
|
-
uploadedBytes += value.byteLength;
|
|
127
|
-
(offset + uploadedBytes) / file.size * 100;
|
|
128
|
-
preview.setAttribute("uploaded", offset + uploadedBytes);
|
|
129
|
-
controller.enqueue(value);
|
|
130
|
-
return reader.read().then(process);
|
|
21
|
+
})(e2, t3, i3) : (i3, s2) => (async function(e3, t3, i4, s3 = 1048576) {
|
|
22
|
+
let r2 = 0;
|
|
23
|
+
const a2 = Math.ceil(t3.size / s3), l2 = [];
|
|
24
|
+
for (; r2 < t3.size; ) {
|
|
25
|
+
const o2 = t3.slice(r2, r2 + s3), n = new ReadableStream({ start(e4) {
|
|
26
|
+
const s4 = o2.stream().getReader();
|
|
27
|
+
let a3 = 0;
|
|
28
|
+
s4.read().then(function l3({ done: o3, value: n2 }) {
|
|
29
|
+
return o3 ? (e4.close(), Promise.resolve()) : (a3 += n2.byteLength, t3.size, i4.setAttribute("uploaded", r2 + a3), e4.enqueue(n2), s4.read().then(l3));
|
|
131
30
|
});
|
|
31
|
+
} }), d = new FormData();
|
|
32
|
+
d.append("file", new Blob([n])), d.append("chunkIndex", Math.floor(r2 / s3)), d.append("totalChunks", a2), d.append("fileName", t3.name);
|
|
33
|
+
try {
|
|
34
|
+
const t4 = await fetch(e3, { method: "POST", body: d });
|
|
35
|
+
if (!t4.ok) throw new Error(`Failed to upload chunk ${Math.floor(r2 / s3) + 1}: ${t4.statusText}`);
|
|
36
|
+
l2.push(t4);
|
|
37
|
+
} catch (e4) {
|
|
38
|
+
console.error("Error uploading chunk:", e4);
|
|
39
|
+
break;
|
|
132
40
|
}
|
|
133
|
-
|
|
134
|
-
const formData = new FormData();
|
|
135
|
-
formData.append("file", new Blob([stream]));
|
|
136
|
-
formData.append("chunkIndex", Math.floor(offset / chunkSize));
|
|
137
|
-
formData.append("totalChunks", totalChunks);
|
|
138
|
-
formData.append("fileName", file.name);
|
|
139
|
-
try {
|
|
140
|
-
const response2 = await fetch(url, {
|
|
141
|
-
method: "POST",
|
|
142
|
-
body: formData
|
|
143
|
-
});
|
|
144
|
-
if (!response2.ok) {
|
|
145
|
-
throw new Error(`Failed to upload chunk ${Math.floor(offset / chunkSize) + 1}: ${response2.statusText}`);
|
|
146
|
-
}
|
|
147
|
-
partResponses.push(response2);
|
|
148
|
-
} catch (error) {
|
|
149
|
-
console.error("Error uploading chunk:", error);
|
|
150
|
-
break;
|
|
41
|
+
r2 += s3;
|
|
151
42
|
}
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
const response = await partResponses.at(-1).json();
|
|
155
|
-
return {
|
|
156
|
-
data: response,
|
|
157
|
-
file
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
function uploadWholeFile(url, file, preview) {
|
|
161
|
-
const formData = new FormData();
|
|
162
|
-
formData.append("file", file);
|
|
163
|
-
return fetch(url, {
|
|
164
|
-
method: "POST",
|
|
165
|
-
body: formData
|
|
166
|
-
}).then((response) => response.json()).then((data) => {
|
|
167
|
-
preview.setAttribute("uploaded", file.size);
|
|
168
|
-
return {
|
|
169
|
-
data,
|
|
170
|
-
file
|
|
171
|
-
};
|
|
172
|
-
}).catch((error) => {
|
|
173
|
-
console.error("Error:", error);
|
|
174
|
-
});
|
|
43
|
+
return { data: await l2.at(-1).json(), file: t3 };
|
|
44
|
+
})(e2, i3, s2, t2);
|
|
175
45
|
}
|
|
176
|
-
|
|
177
|
-
class FileUpload extends WJElement {
|
|
178
|
-
/**
|
|
179
|
-
* Constructor for FileUpload.
|
|
180
|
-
* Initializes a new instance of the Localizer.
|
|
181
|
-
*/
|
|
46
|
+
class o extends t {
|
|
182
47
|
constructor() {
|
|
183
48
|
super();
|
|
184
|
-
|
|
185
|
-
* Dependencies for the FileUpload component.
|
|
186
|
-
* @type {object}
|
|
187
|
-
*/
|
|
188
|
-
__publicField(this, "dependencies", {
|
|
189
|
-
"wje-button": Button
|
|
190
|
-
});
|
|
49
|
+
__publicField(this, "dependencies", { "wje-button": i });
|
|
191
50
|
__publicField(this, "className", "FileUpload");
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
__publicField(this, "handleDrop", (e) => {
|
|
197
|
-
e.preventDefault();
|
|
198
|
-
const fileList = e.dataTransfer.files;
|
|
199
|
-
this.resetFormState();
|
|
200
|
-
this.addFilesToQueue(fileList);
|
|
51
|
+
__publicField(this, "handleDrop", (e2) => {
|
|
52
|
+
e2.preventDefault();
|
|
53
|
+
const t2 = e2.dataTransfer.files;
|
|
54
|
+
this.resetFormState(), this.addFilesToQueue(t2);
|
|
201
55
|
});
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
*/
|
|
206
|
-
__publicField(this, "handleInputChange", (e) => {
|
|
207
|
-
const files = Array.from(e.target.files);
|
|
208
|
-
event.dispatchCustomEvent(this, "wje-file-upload:files-selected", files);
|
|
209
|
-
this.resetFormState();
|
|
56
|
+
__publicField(this, "handleInputChange", (e2) => {
|
|
57
|
+
const t2 = Array.from(e2.target.files);
|
|
58
|
+
r.dispatchCustomEvent(this, "wje-file-upload:files-selected", t2), this.resetFormState();
|
|
210
59
|
try {
|
|
211
|
-
this.handleSubmit(
|
|
212
|
-
} catch (
|
|
213
|
-
console.error(
|
|
60
|
+
this.handleSubmit(e2);
|
|
61
|
+
} catch (e3) {
|
|
62
|
+
console.error(e3);
|
|
214
63
|
}
|
|
215
64
|
});
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
var _a2;
|
|
234
|
-
res.item = preview;
|
|
235
|
-
event.dispatchCustomEvent(this, "wje-file-upload:file-uploaded", res);
|
|
236
|
-
(_a2 = this.onUploadedFileComplete) == null ? void 0 : _a2.call(this, res);
|
|
237
|
-
this.uploadedFiles.push(res);
|
|
238
|
-
resolve(res);
|
|
239
|
-
});
|
|
240
|
-
};
|
|
241
|
-
reader.readAsDataURL(file);
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
this.localizer = new Localizer(this);
|
|
245
|
-
this._uploadedFiles = [];
|
|
246
|
-
this._queuedFiles = [];
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Setter for acceptedTypes attribute.
|
|
250
|
-
* @param {string} value The accepted file types for upload.
|
|
251
|
-
*/
|
|
252
|
-
set acceptedTypes(value) {
|
|
253
|
-
this.setAttribute("accepted-types", value);
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Getter for acceptedTypes attribute.
|
|
257
|
-
* @returns {string} The accepted file types for upload.
|
|
258
|
-
*/
|
|
65
|
+
__publicField(this, "createUploadPromise", (e2) => new Promise((t2, i2) => {
|
|
66
|
+
let s2;
|
|
67
|
+
this.assertFilesValid(e2);
|
|
68
|
+
let a2 = new FileReader();
|
|
69
|
+
a2.onload = () => {
|
|
70
|
+
var _a;
|
|
71
|
+
r.dispatchCustomEvent(this, "wje-file-upload:started", e2), (_a = this.onUploadStarted) == null ? void 0 : _a.call(this, e2), s2 = this.createPreview(e2, a2), this.appendChild(s2), this.uploadFunction(e2, s2).then((e3) => {
|
|
72
|
+
var _a2;
|
|
73
|
+
e3.item = s2, r.dispatchCustomEvent(this, "wje-file-upload:file-uploaded", e3), (_a2 = this.onUploadedFileComplete) == null ? void 0 : _a2.call(this, e3), this.uploadedFiles.push(e3), t2(e3);
|
|
74
|
+
});
|
|
75
|
+
}, a2.readAsDataURL(e2);
|
|
76
|
+
}));
|
|
77
|
+
this.localizer = new e(this), this._uploadedFiles = [], this._queuedFiles = [];
|
|
78
|
+
}
|
|
79
|
+
set acceptedTypes(e2) {
|
|
80
|
+
this.setAttribute("accepted-types", e2);
|
|
81
|
+
}
|
|
259
82
|
get acceptedTypes() {
|
|
260
|
-
const
|
|
261
|
-
return this.hasAttribute("accepted-types") ?
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
*/
|
|
267
|
-
set chunkSize(value) {
|
|
268
|
-
this.setAttribute("chunk-size", value);
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Getter for chunkSize attribute.
|
|
272
|
-
* @returns {number} The chunk size for file upload.
|
|
273
|
-
*/
|
|
83
|
+
const e2 = this.getAttribute("accepted-types");
|
|
84
|
+
return this.hasAttribute("accepted-types") ? e2 : "image/*";
|
|
85
|
+
}
|
|
86
|
+
set chunkSize(e2) {
|
|
87
|
+
this.setAttribute("chunk-size", e2);
|
|
88
|
+
}
|
|
274
89
|
get chunkSize() {
|
|
275
|
-
const
|
|
276
|
-
return this.hasAttribute("chunk-size") ?
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
*/
|
|
282
|
-
set maxFileSize(value) {
|
|
283
|
-
this.setAttribute("max-file-size", value);
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Getter for maxFileSize attribute.
|
|
287
|
-
* @returns {number} The maximum file size for upload.
|
|
288
|
-
*/
|
|
90
|
+
const e2 = this.getAttribute("chunk-size");
|
|
91
|
+
return this.hasAttribute("chunk-size") ? e2 : 1048576;
|
|
92
|
+
}
|
|
93
|
+
set maxFileSize(e2) {
|
|
94
|
+
this.setAttribute("max-file-size", e2);
|
|
95
|
+
}
|
|
289
96
|
get maxFileSize() {
|
|
290
|
-
const
|
|
291
|
-
return this.hasAttribute("max-file-size") ?
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
*/
|
|
297
|
-
set uploadUrl(value) {
|
|
298
|
-
this.setAttribute("upload-url", value);
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Gets the upload URL for the file upload element.
|
|
302
|
-
* @returns {string} The upload URL for the file upload element.
|
|
303
|
-
*/
|
|
97
|
+
const e2 = this.getAttribute("max-file-size");
|
|
98
|
+
return this.hasAttribute("max-file-size") ? 1024 * e2 * 1024 : 1048576;
|
|
99
|
+
}
|
|
100
|
+
set uploadUrl(e2) {
|
|
101
|
+
this.setAttribute("upload-url", e2);
|
|
102
|
+
}
|
|
304
103
|
get uploadUrl() {
|
|
305
104
|
return this.getAttribute("upload-url") ?? "/upload";
|
|
306
105
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
*/
|
|
311
|
-
set autoProcessFiles(value) {
|
|
312
|
-
this.setAttribute("auto-process-files", value);
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Gets the autoProcessFiles attribute.
|
|
316
|
-
* @returns {any|boolean}
|
|
317
|
-
*/
|
|
106
|
+
set autoProcessFiles(e2) {
|
|
107
|
+
this.setAttribute("auto-process-files", e2);
|
|
108
|
+
}
|
|
318
109
|
get autoProcessFiles() {
|
|
319
110
|
return JSON.parse(this.getAttribute("auto-process-files")) ?? true;
|
|
320
111
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
*/
|
|
325
|
-
set noUploadButton(value) {
|
|
326
|
-
this.setAttribute("no-upload-button", value);
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Gets the noUploadButton attribute.
|
|
330
|
-
* @returns {boolean}
|
|
331
|
-
*/
|
|
112
|
+
set noUploadButton(e2) {
|
|
113
|
+
this.setAttribute("no-upload-button", e2);
|
|
114
|
+
}
|
|
332
115
|
get noUploadButton() {
|
|
333
116
|
return this.hasAttribute("no-upload-button");
|
|
334
117
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
*/
|
|
339
|
-
set uploadedFiles(value) {
|
|
340
|
-
this._uploadedFiles = value;
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Return the uploaded files.
|
|
344
|
-
* @returns {[]}
|
|
345
|
-
*/
|
|
118
|
+
set uploadedFiles(e2) {
|
|
119
|
+
this._uploadedFiles = e2;
|
|
120
|
+
}
|
|
346
121
|
get uploadedFiles() {
|
|
347
122
|
return this._uploadedFiles;
|
|
348
123
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
*/
|
|
353
|
-
set toChunk(value) {
|
|
354
|
-
this.setAttribute("to-chunk", value);
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Gets the to-chunk attribute.
|
|
358
|
-
* @returns {boolean}
|
|
359
|
-
*/
|
|
124
|
+
set toChunk(e2) {
|
|
125
|
+
this.setAttribute("to-chunk", e2);
|
|
126
|
+
}
|
|
360
127
|
get toChunk() {
|
|
361
128
|
return this.hasAttribute("to-chunk");
|
|
362
129
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
this.setAttribute("max-files", value);
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Sets the label attribute for the upload button.
|
|
373
|
-
* @param {string} value
|
|
374
|
-
*/
|
|
375
|
-
set label(value) {
|
|
376
|
-
this.setAttribute("label", value);
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Gets the label attribute for the upload button.
|
|
380
|
-
* @returns {string}
|
|
381
|
-
*/
|
|
130
|
+
set maxFiles(e2) {
|
|
131
|
+
this.setAttribute("max-files", e2);
|
|
132
|
+
}
|
|
133
|
+
set label(e2) {
|
|
134
|
+
this.setAttribute("label", e2);
|
|
135
|
+
}
|
|
382
136
|
get label() {
|
|
383
137
|
return this.getAttribute("label") || "";
|
|
384
138
|
}
|
|
385
|
-
/**
|
|
386
|
-
* Retrieves the maximum number of files allowed from the `max-files` attribute.
|
|
387
|
-
* If the attribute is not set or is invalid, defaults to 0.
|
|
388
|
-
* @returns {number} The maximum number of files allowed.
|
|
389
|
-
*/
|
|
390
139
|
get maxFiles() {
|
|
391
140
|
return parseInt(this.getAttribute("max-files")) || 10;
|
|
392
141
|
}
|
|
393
|
-
/**
|
|
394
|
-
* Getter for cssStyleSheet.
|
|
395
|
-
* @returns {string} The CSS styles for the component.
|
|
396
|
-
*/
|
|
397
142
|
static get cssStyleSheet() {
|
|
398
|
-
return
|
|
143
|
+
return ':host{width:100%}:host p{margin:0}.native-file-upload{width:100%;position:relative;border:1px dashed var(--wje-file-upload-border-color, var(--wje-border-color));border-radius:var(--wje-border-radius-medium);transition:border-color var(--wje-transition-fast);padding:var(--wje-file-upload-padding, 0)}.native-file-upload.highlight{border-color:var(--wje-file-upload-border-color-highlight, var(--wje-color-success-9))}.file-error{margin:0 1rem 1rem;padding:.5rem .75rem;border:1px solid var(--wje-file-upload-error-border-color, var(--wje-color-danger-3));border-radius:var(--wje-border-radius-medium);background:var(--wje-file-upload-error-background, var(--wje-color-danger-1));color:var(--wje-file-upload-error-color, var(--wje-color-danger-9));font-size:var(--wje-font-size-small)}.file-error[hidden]{display:none}.file-label{background:var(--wje-color-contrast-0);align-items:center;justify-content:center;display:flex;padding:1rem;flex-direction:column;position:relative}.file-preview{display:grid;grid-template-columns:auto 1fr 1fr;grid-template-rows:auto auto auto;gap:0 0;grid-template-areas:"image name name" "image size size" "progress progress progress"}.file-image{grid-area:image;align-items:center;display:flex}.file-name{grid-area:name;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.file-size{grid-area:size;display:flex}.file-progress{grid-area:progress}wje-icon{margin-right:.25rem}wje-img{margin-right:.25rem}.file-info>span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}wje-slider{flex-basis:100%;margin-top:.5rem}wje-img{width:50px;height:50px;display:flex;align-items:center;padding:.25rem;border:1px solid var(--wje-border-color);border-radius:var(--wje-border-radius-medium)}';
|
|
399
144
|
}
|
|
400
|
-
/**
|
|
401
|
-
* Getter for observedAttributes.
|
|
402
|
-
* @returns {Array} An empty array as no attributes are observed.
|
|
403
|
-
*/
|
|
404
145
|
static get observedAttributes() {
|
|
405
146
|
return ["label"];
|
|
406
147
|
}
|
|
407
|
-
attributeChangedCallback(
|
|
148
|
+
attributeChangedCallback(e2, t2, i2) {
|
|
408
149
|
var _a;
|
|
409
|
-
(_a = super.attributeChangedCallback) == null ? void 0 : _a.call(this,
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
this.button.innerText = nextLabel;
|
|
413
|
-
this.button.setAttribute("aria-label", nextLabel);
|
|
150
|
+
if ((_a = super.attributeChangedCallback) == null ? void 0 : _a.call(this, e2, t2, i2), "label" === e2 && this.button) {
|
|
151
|
+
const e3 = this.label || this.localizer.translate("wj.file.upload.button");
|
|
152
|
+
this.button.innerText = e3, this.button.setAttribute("label", e3);
|
|
414
153
|
}
|
|
415
154
|
}
|
|
416
|
-
/**
|
|
417
|
-
* Method to setup attributes for the component.
|
|
418
|
-
*/
|
|
419
155
|
setupAttributes() {
|
|
420
|
-
this.isShadowRoot = "open";
|
|
421
|
-
this.setAriaState({
|
|
422
|
-
role: "group"
|
|
423
|
-
});
|
|
156
|
+
this.isShadowRoot = "open", this.setAriaState({ role: "group" });
|
|
424
157
|
}
|
|
425
158
|
beforeDraw() {
|
|
426
|
-
this.uploadFunction =
|
|
159
|
+
this.uploadFunction = l(this.uploadUrl, this.chunkSize, !this.toChunk);
|
|
427
160
|
}
|
|
428
|
-
/**
|
|
429
|
-
* Method to draw the component on the screen.
|
|
430
|
-
* @returns {DocumentFragment} The fragment containing the component.
|
|
431
|
-
*/
|
|
432
161
|
draw() {
|
|
433
|
-
let
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
let
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
errorMessage.setAttribute("part", "error-message");
|
|
448
|
-
errorMessage.setAttribute("role", "alert");
|
|
449
|
-
errorMessage.setAttribute("aria-live", "polite");
|
|
450
|
-
errorMessage.classList.add("file-error");
|
|
451
|
-
errorMessage.hidden = true;
|
|
452
|
-
let fileInput = document.createElement("input");
|
|
453
|
-
fileInput.setAttribute("type", "file");
|
|
454
|
-
fileInput.setAttribute("multiple", "");
|
|
455
|
-
fileInput.setAttribute("style", "display:none;");
|
|
456
|
-
fileInput.setAttribute("aria-hidden", "true");
|
|
457
|
-
if (!this.noUploadButton) {
|
|
458
|
-
let button = document.createElement("wje-button");
|
|
459
|
-
button.innerText = this.label || this.localizer.translate("wj.file.upload.button");
|
|
460
|
-
button.setAttribute("part", "upload-button");
|
|
461
|
-
button.setAttribute("aria-label", button.innerText);
|
|
462
|
-
label.appendChild(button);
|
|
463
|
-
this.button = button;
|
|
162
|
+
let e2 = document.createDocumentFragment(), t2 = document.createElement("div");
|
|
163
|
+
t2.classList.add("native-file-upload"), t2.setAttribute("part", "native");
|
|
164
|
+
let i2 = document.createElement("div");
|
|
165
|
+
i2.setAttribute("part", "file-label"), i2.classList.add("file-label");
|
|
166
|
+
let s2 = document.createElement("slot");
|
|
167
|
+
s2.setAttribute("name", "item"), s2.setAttribute("part", "items"), s2.classList.add("file-list");
|
|
168
|
+
let r2 = document.createElement("slot");
|
|
169
|
+
i2.appendChild(r2);
|
|
170
|
+
let a2 = document.createElement("div");
|
|
171
|
+
a2.setAttribute("part", "error-message"), a2.setAttribute("role", "alert"), a2.setAttribute("aria-live", "polite"), a2.classList.add("file-error"), a2.hidden = true;
|
|
172
|
+
let l2 = document.createElement("input");
|
|
173
|
+
if (l2.setAttribute("type", "file"), l2.setAttribute("multiple", ""), l2.setAttribute("style", "display:none;"), l2.setAttribute("aria-hidden", "true"), !this.noUploadButton) {
|
|
174
|
+
let e3 = document.createElement("wje-button");
|
|
175
|
+
e3.innerText = this.label || this.localizer.translate("wj.file.upload.button"), e3.setAttribute("part", "upload-button"), e3.setAttribute("label", e3.innerText), i2.appendChild(e3), this.button = e3;
|
|
464
176
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
native.appendChild(errorMessage);
|
|
468
|
-
native.appendChild(fileList);
|
|
469
|
-
fragment.appendChild(native);
|
|
470
|
-
this.native = native;
|
|
471
|
-
this.fileList = fileList;
|
|
472
|
-
this.fileInput = fileInput;
|
|
473
|
-
this.errorMessage = errorMessage;
|
|
474
|
-
return fragment;
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Method to perform actions after the component is drawn.
|
|
478
|
-
*/
|
|
177
|
+
return t2.appendChild(l2), t2.appendChild(i2), t2.appendChild(a2), t2.appendChild(s2), e2.appendChild(t2), this.native = t2, this.fileList = s2, this.fileInput = l2, this.errorMessage = a2, e2;
|
|
178
|
+
}
|
|
479
179
|
afterDraw() {
|
|
480
180
|
var _a;
|
|
481
181
|
(_a = this.button) == null ? void 0 : _a.addEventListener("click", () => {
|
|
482
182
|
this.fileInput.click();
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
this.native.addEventListener("
|
|
486
|
-
|
|
487
|
-
this.native.addEventListener("
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
})
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
this.native.addEventListener("dragleave", (e) => {
|
|
501
|
-
e.preventDefault();
|
|
502
|
-
dragEventCounter -= 1;
|
|
503
|
-
if (dragEventCounter <= 0) {
|
|
504
|
-
dragEventCounter = 0;
|
|
505
|
-
this.native.classList.remove("highlight");
|
|
506
|
-
}
|
|
507
|
-
});
|
|
508
|
-
this.native.addEventListener("drop", (e) => {
|
|
509
|
-
e.preventDefault();
|
|
510
|
-
dragEventCounter = 0;
|
|
511
|
-
this.native.classList.remove("highlight");
|
|
512
|
-
});
|
|
513
|
-
this.addEventListener("wje-file-upload-item:remove", (e) => {
|
|
514
|
-
const file = e.detail;
|
|
515
|
-
if (!(file instanceof File)) {
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
let count = this.uploadedFiles.length;
|
|
519
|
-
this.uploadedFiles = this.uploadedFiles.filter((entry) => {
|
|
183
|
+
}), this.fileInput.addEventListener("change", this.handleInputChange), this.native.addEventListener("drop", this.handleDrop);
|
|
184
|
+
let e2 = 0;
|
|
185
|
+
this.native.addEventListener("dragenter", (t2) => {
|
|
186
|
+
t2.preventDefault(), 0 === e2 && this.native.classList.add("highlight"), e2 += 1;
|
|
187
|
+
}), this.native.addEventListener("dragover", (t2) => {
|
|
188
|
+
t2.preventDefault(), 0 === e2 && (e2 = 1);
|
|
189
|
+
}), this.native.addEventListener("dragleave", (t2) => {
|
|
190
|
+
t2.preventDefault(), e2 -= 1, e2 <= 0 && (e2 = 0, this.native.classList.remove("highlight"));
|
|
191
|
+
}), this.native.addEventListener("drop", (t2) => {
|
|
192
|
+
t2.preventDefault(), e2 = 0, this.native.classList.remove("highlight");
|
|
193
|
+
}), this.addEventListener("wje-file-upload-item:remove", (e3) => {
|
|
194
|
+
const t2 = e3.detail;
|
|
195
|
+
if (!(t2 instanceof File)) return;
|
|
196
|
+
let i2 = this.uploadedFiles.length;
|
|
197
|
+
this.uploadedFiles = this.uploadedFiles.filter((e4) => {
|
|
520
198
|
var _a2;
|
|
521
|
-
return ((_a2 =
|
|
522
|
-
});
|
|
523
|
-
if (count !== this.uploadedFiles.length)
|
|
524
|
-
event.dispatchCustomEvent(this, "wje-file-upload:file-removed", file);
|
|
199
|
+
return ((_a2 = e4 == null ? void 0 : e4.file) == null ? void 0 : _a2.lastModified) !== t2.lastModified;
|
|
200
|
+
}), i2 !== this.uploadedFiles.length && r.dispatchCustomEvent(this, "wje-file-upload:file-removed", t2);
|
|
525
201
|
});
|
|
526
202
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
handleSubmit(e) {
|
|
532
|
-
e.preventDefault();
|
|
533
|
-
this.addFilesToQueue(this.fileInput.files);
|
|
534
|
-
}
|
|
535
|
-
/**
|
|
536
|
-
* Method to add files to the queue.
|
|
537
|
-
* @param files
|
|
538
|
-
*/
|
|
539
|
-
addFilesToQueue(files) {
|
|
203
|
+
handleSubmit(e2) {
|
|
204
|
+
e2.preventDefault(), this.addFilesToQueue(this.fileInput.files);
|
|
205
|
+
}
|
|
206
|
+
addFilesToQueue(e2) {
|
|
540
207
|
var _a;
|
|
541
|
-
const
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
code: "MAX-FILES-EXCEEDED",
|
|
546
|
-
files,
|
|
547
|
-
maxFiles: this.maxFiles,
|
|
548
|
-
currentCount,
|
|
549
|
-
attemptedToAdd: files.length,
|
|
550
|
-
allowedRemaining: Math.max(this.maxFiles - currentCount, 0)
|
|
551
|
-
};
|
|
552
|
-
event.dispatchCustomEvent(this, "wje-file-upload:error", detail);
|
|
553
|
-
this.showError(detail);
|
|
554
|
-
return;
|
|
555
|
-
}
|
|
556
|
-
this._queuedFiles = [...this._queuedFiles || [], ...files];
|
|
557
|
-
this.clearError();
|
|
558
|
-
event.dispatchCustomEvent(this, "wje-file-upload:files-added", files);
|
|
559
|
-
(_a = this.onAddedFiles) == null ? void 0 : _a.call(this);
|
|
560
|
-
if (this.autoProcessFiles) {
|
|
561
|
-
this.uploadFiles();
|
|
208
|
+
const t2 = (Array.isArray(this.uploadedFiles) ? this.uploadedFiles.length : 0) + (Array.isArray(this._queuedFiles) ? this._queuedFiles.length : 0), i2 = t2 + e2.length;
|
|
209
|
+
if (this.maxFiles && i2 > this.maxFiles) {
|
|
210
|
+
const i3 = { code: "MAX-FILES-EXCEEDED", files: e2, maxFiles: this.maxFiles, currentCount: t2, attemptedToAdd: e2.length, allowedRemaining: Math.max(this.maxFiles - t2, 0) };
|
|
211
|
+
return r.dispatchCustomEvent(this, "wje-file-upload:error", i3), void this.showError(i3);
|
|
562
212
|
}
|
|
563
|
-
this.fileInput.value = "";
|
|
213
|
+
this._queuedFiles = [...this._queuedFiles || [], ...e2], this.clearError(), r.dispatchCustomEvent(this, "wje-file-upload:files-added", e2), (_a = this.onAddedFiles) == null ? void 0 : _a.call(this), this.autoProcessFiles && this.uploadFiles(), this.fileInput.value = "";
|
|
564
214
|
}
|
|
565
|
-
/**
|
|
566
|
-
* Method to upload files.
|
|
567
|
-
*/
|
|
568
215
|
uploadFiles() {
|
|
569
|
-
if (this._queuedFiles.length
|
|
570
|
-
|
|
571
|
-
}
|
|
572
|
-
const uploadPromises = this._queuedFiles.map((file) => this.createUploadPromise(file));
|
|
573
|
-
uploadPromises.reduce((prev, curr) => {
|
|
574
|
-
return prev.then(() => {
|
|
575
|
-
return curr;
|
|
576
|
-
});
|
|
577
|
-
}, Promise.resolve()).then(() => {
|
|
216
|
+
if (0 === this._queuedFiles.length) return;
|
|
217
|
+
this._queuedFiles.map((e2) => this.createUploadPromise(e2)).reduce((e2, t2) => e2.then(() => t2), Promise.resolve()).then(() => {
|
|
578
218
|
var _a;
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
this._queuedFiles =
|
|
582
|
-
}).catch((err) => {
|
|
583
|
-
this._queuedFiles = this._queuedFiles.filter((file) => file !== err.file);
|
|
584
|
-
this.showError(err);
|
|
585
|
-
event.dispatchCustomEvent(this, "wje-file-upload:error", err);
|
|
219
|
+
r.dispatchCustomEvent(this, "wje-file-upload:files-uploaded", this.uploadedFiles), (_a = this.onAllFilesUploaded) == null ? void 0 : _a.call(this), this._queuedFiles = [];
|
|
220
|
+
}).catch((e2) => {
|
|
221
|
+
this._queuedFiles = this._queuedFiles.filter((t2) => t2 !== e2.file), this.showError(e2), r.dispatchCustomEvent(this, "wje-file-upload:error", e2);
|
|
586
222
|
});
|
|
587
223
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
preview.setAttribute("uploaded", "0");
|
|
602
|
-
preview.innerHTML = `<wje-icon slot="img" name="${icon}" size="large"></wje-icon>`;
|
|
603
|
-
preview.data = file;
|
|
604
|
-
return preview;
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
* Method to create a thumbnail for the file.
|
|
608
|
-
* @param {File} file The file for which the thumbnail is to be created.
|
|
609
|
-
* @param {FileReader} reader The FileReader instance to read the file.
|
|
610
|
-
* @returns {HTMLElement} The created thumbnail.
|
|
611
|
-
*/
|
|
612
|
-
createThumbnail(file, reader) {
|
|
613
|
-
let img = document.createElement("img");
|
|
614
|
-
img.setAttribute("src", reader.result);
|
|
615
|
-
return img;
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* Method to validate the files.
|
|
619
|
-
* @param {File} file The file to be validated.
|
|
620
|
-
* TODO: alowed types a size limit by malo byt cez attributy
|
|
621
|
-
*/
|
|
622
|
-
assertFilesValid(file) {
|
|
623
|
-
const { name: fileName, size: fileSize } = file;
|
|
624
|
-
if (!isValidFileType(file, this.acceptedTypes)) {
|
|
625
|
-
const err = new Error("");
|
|
626
|
-
err.code = "INVALID-FILE-TYPE";
|
|
627
|
-
err.file = file;
|
|
628
|
-
err.acceptedTypes = this.acceptedTypes;
|
|
629
|
-
throw err;
|
|
224
|
+
createPreview(e2, t2) {
|
|
225
|
+
let i2 = document.createElement("wje-file-upload-item"), s2 = a(e2.type ? e2.type.split("/")[1] : e2.name.split(".").pop()) || "file";
|
|
226
|
+
return i2.setAttribute("slot", "item"), i2.setAttribute("name", e2.name), i2.setAttribute("size", e2.size), i2.setAttribute("uploaded", "0"), i2.innerHTML = `<wje-icon slot="img" name="${s2}" size="large"></wje-icon>`, i2.data = e2, i2;
|
|
227
|
+
}
|
|
228
|
+
createThumbnail(e2, t2) {
|
|
229
|
+
let i2 = document.createElement("img");
|
|
230
|
+
return i2.setAttribute("src", t2.result), i2;
|
|
231
|
+
}
|
|
232
|
+
assertFilesValid(e2) {
|
|
233
|
+
const { name: t2, size: i2 } = e2;
|
|
234
|
+
if (!s(e2, this.acceptedTypes)) {
|
|
235
|
+
const t3 = new Error("");
|
|
236
|
+
throw t3.code = "INVALID-FILE-TYPE", t3.file = e2, t3.acceptedTypes = this.acceptedTypes, t3;
|
|
630
237
|
}
|
|
631
|
-
if (
|
|
632
|
-
const
|
|
633
|
-
|
|
634
|
-
err.file = file;
|
|
635
|
-
err.maxFileSize = this.maxFileSize;
|
|
636
|
-
throw err;
|
|
238
|
+
if (i2 > this.maxFileSize) {
|
|
239
|
+
const t3 = new Error("");
|
|
240
|
+
throw t3.code = "FILE-TOO-LARGE", t3.file = e2, t3.maxFileSize = this.maxFileSize, t3;
|
|
637
241
|
}
|
|
638
242
|
}
|
|
639
|
-
/**
|
|
640
|
-
* Method to reset the form state.
|
|
641
|
-
*/
|
|
642
243
|
resetFormState() {
|
|
643
244
|
this.fileList.textContent = "";
|
|
644
245
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
*/
|
|
649
|
-
showError(error) {
|
|
650
|
-
if (!this.errorMessage) return;
|
|
651
|
-
this.errorMessage.textContent = this.getErrorMessage(error);
|
|
652
|
-
this.errorMessage.hidden = false;
|
|
653
|
-
}
|
|
654
|
-
/**
|
|
655
|
-
* Clears the currently displayed validation error.
|
|
656
|
-
*/
|
|
246
|
+
showError(e2) {
|
|
247
|
+
this.errorMessage && (this.errorMessage.textContent = this.getErrorMessage(e2), this.errorMessage.hidden = false);
|
|
248
|
+
}
|
|
657
249
|
clearError() {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
}
|
|
662
|
-
/**
|
|
663
|
-
* Resolves a readable upload error message.
|
|
664
|
-
* @param {object|Error} error Error payload used to resolve the translated message.
|
|
665
|
-
* @returns {string}
|
|
666
|
-
*/
|
|
667
|
-
getErrorMessage(error = {}) {
|
|
250
|
+
this.errorMessage && (this.errorMessage.textContent = "", this.errorMessage.hidden = true);
|
|
251
|
+
}
|
|
252
|
+
getErrorMessage(e2 = {}) {
|
|
668
253
|
var _a;
|
|
669
|
-
const
|
|
670
|
-
|
|
671
|
-
"INVALID-FILE-TYPE": {
|
|
672
|
-
key: "wj.file.upload.error.invalid.type",
|
|
673
|
-
fallback: `This file type is not supported. Allowed formats: ${error.acceptedTypes || this.acceptedTypes}.`,
|
|
674
|
-
params: { acceptedTypes: error.acceptedTypes || this.acceptedTypes }
|
|
675
|
-
},
|
|
676
|
-
"FILE-TOO-LARGE": {
|
|
677
|
-
key: "wj.file.upload.error.file.too.large",
|
|
678
|
-
fallback: `The file is too large. Maximum size is ${this.localizer.formatNumber(this.maxFileSize / 1024 / 1024)} MB.`,
|
|
679
|
-
params: { maxFileSize: this.localizer.formatNumber(this.maxFileSize / 1024 / 1024) }
|
|
680
|
-
},
|
|
681
|
-
"MAX-FILES-EXCEEDED": {
|
|
682
|
-
key: "wj.file.upload.error.max.files",
|
|
683
|
-
fallback: `You can upload up to ${error.maxFiles || this.maxFiles} files.`,
|
|
684
|
-
params: { maxFiles: error.maxFiles || this.maxFiles }
|
|
685
|
-
}
|
|
686
|
-
};
|
|
687
|
-
const message = messages[code] || {
|
|
688
|
-
key: "wj.file.upload.error.generic",
|
|
689
|
-
fallback: "The file could not be uploaded.",
|
|
690
|
-
params: {}
|
|
691
|
-
};
|
|
692
|
-
const translated = this.localizer.translateWithParams(message.key, message.params);
|
|
693
|
-
return translated === message.key ? message.fallback : translated;
|
|
254
|
+
const t2 = e2.code || ((_a = e2.detail) == null ? void 0 : _a.code), i2 = { "INVALID-FILE-TYPE": { key: "wj.file.upload.error.invalid.type", fallback: `This file type is not supported. Allowed formats: ${e2.acceptedTypes || this.acceptedTypes}.`, params: { acceptedTypes: e2.acceptedTypes || this.acceptedTypes } }, "FILE-TOO-LARGE": { key: "wj.file.upload.error.file.too.large", fallback: `The file is too large. Maximum size is ${this.localizer.formatNumber(this.maxFileSize / 1024 / 1024)} MB.`, params: { maxFileSize: this.localizer.formatNumber(this.maxFileSize / 1024 / 1024) } }, "MAX-FILES-EXCEEDED": { key: "wj.file.upload.error.max.files", fallback: `You can upload up to ${e2.maxFiles || this.maxFiles} files.`, params: { maxFiles: e2.maxFiles || this.maxFiles } } }[t2] || { key: "wj.file.upload.error.generic", fallback: "The file could not be uploaded.", params: {} }, s2 = this.localizer.translateWithParams(i2.key, i2.params);
|
|
255
|
+
return s2 === i2.key ? i2.fallback : s2;
|
|
694
256
|
}
|
|
695
257
|
}
|
|
696
|
-
|
|
258
|
+
o.define("wje-file-upload", o);
|
|
697
259
|
export {
|
|
698
|
-
|
|
260
|
+
o as default
|
|
699
261
|
};
|
|
700
262
|
//# sourceMappingURL=wje-file-upload.js.map
|