wj-elements 0.1.101 → 0.1.102
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/wje-dialog.js +17 -10
- package/dist/wje-file-upload-item.js +1 -1
- package/dist/wje-file-upload.js +77 -37
- package/package.json +1 -1
package/dist/wje-dialog.js
CHANGED
|
@@ -6,13 +6,15 @@ var __publicField = (obj, key, value) => {
|
|
|
6
6
|
};
|
|
7
7
|
import WJElement, { event } from "./wje-element.js";
|
|
8
8
|
import "./wje-icon.js";
|
|
9
|
-
const styles = '/*\r\n[ WJ Dialog ]\r\n*/\r\n\r\n:host {\r\n .close {\r\n margin-left: auto;\r\n }\r\n\r\n .modal-content {\r\n border-radius: 3px;\r\n box-shadow: none;\r\n }\r\n\r\n .dialog-header {\r\n position: relative;\r\n border-bottom: 0;\r\n padding-inline: var(--wje-dialog-padding);\r\n padding-top: var(--wje-dialog-padding);\r\n padding-bottom: var(--wje-dialog-padding);\r\n display: flex;\r\n align-items: center;\r\n span {\r\n font-family: var(--wje-font-family-secondary);\r\n font-size: 10.5px;\r\n text-transform: uppercase;\r\n display: inline-block;\r\n letter-spacing: 0.06em;\r\n font-weight: 500;\r\n margin: 0;\r\n padding: 0;\r\n line-height: normal;\r\n overflow: hidden;\r\n text-overflow: ellipsis;\r\n filter: alpha(opacity=40);\r\n }\r\n }\r\n\r\n .dialog-content {\r\n box-shadow: none;\r\n padding-inline: var(--wje-dialog-padding);\r\n white-space: normal;\r\n z-index: 1;\r\n }\r\n\r\n .dialog-footer {\r\n display: flex;\r\n justify-content: end;\r\n border-top: none;\r\n box-shadow: none;\r\n margin-top: 0;\r\n padding-inline: var(--wje-dialog-padding-inline);\r\n padding-top: var(--wje-dialog-padding-top);\r\n padding-bottom: var(--wje-dialog-padding-bottom);\r\n }\r\n}\r\n\r\ndialog::backdrop {\r\n opacity: var(--wje-backdrop-opacity);\r\n background-color: var(--wje-backdrop);\r\n}\r\n\r\ndialog:focus-visible {\r\n outline: none;\r\n}\r\n\r\n:host(.separator) .dialog-header:after {\r\n content: "";\r\n height: 1px;\r\n background: rgba(0, 0, 0, 0.08);\r\n left: var(--wje-dialog-padding);\r\n right: var(--wje-dialog-padding);\r\n position: absolute;\r\n bottom: 0;\r\n}\r\n\r\n:host {\r\n dialog {\r\n box-sizing: border-box;\r\n transition: all 0.2s !important;\r\n width: var(--wje-dialog-width);\r\n height: var(--wje-dialog-height);\r\n box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);\r\n\r\n border-radius: var(--wje-dialog-border-radius);\r\n border-width: var(--wje-dialog-border-width);\r\n border-style: var(--wje-dialog-border-style);\r\n border-color: var(--wje-dialog-border-color);\r\n\r\n margin-top: var(--wje-dialog-margin-top);\r\n\r\n margin-bottom: var(--wje-dialog-margin-bottom);\r\n margin-inline: var(--wje-dialog-margin-start) var(--wje-dialog-margin-end);\r\n\r\n padding: 0;\r\n }\r\n}\r\n\r\n/*Top*/\r\n:host(.stick-up) {\r\n --wje-dialog-width: 300px !important;\r\n --wje-dialog-height: fit-content;\r\n --wje-dialog-border-radius: 0 0 8px 8px;\r\n --wje-dialog-border-width: 0 1px 1px 1px;\r\n --wje-dialog-margin-top: 0;\r\n --wje-dialog-translate-from: translateY(-110%);\r\n --wje-dialog-template-to: translateX(0);\r\n}\r\n\r\n/*Cenetered*/\r\n:host(.slide-up) {\r\n --wje-dialog-width: 300px !important;\r\n --wje-dialog-height: fit-content;\r\n --wje-dialog-border-radius: 8px;\r\n --wje-dialog-border-width: 1px;\r\n --wje-dialog-opacity-from: 0;\r\n --wje-dialog-translate-from: scale(.9);\r\n --wje-dialog-translate-to: scale(1);\r\n}\r\n\r\n/*Fullscreen*/\r\n:host(.fill-in) {\r\n --wje-dialog-width: 100%;\r\n --wje-dialog-height: 100%;\r\n --wje-dialog-border-radius: 0 0 0 0 !important;\r\n --wje-dialog-border-width: 0;\r\n --wje-dialog-margin-top: 0;\r\n --wje-dialog-margin-start: 0;\r\n --wje-dialog-margin-end: 0;\r\n --wje-dialog-margin-bottom: 0;\r\n --wje-dialog-translate-from: scale(.95);\r\n --wje-dialog-translate-to: scale(1);\r\n dialog {\r\n min-width: var(--wje-dialog-width);\r\n min-height: var(--wje-dialog-height);\r\n }\r\n}\r\n\r\n/*Slide Left*/\r\n:host(.slide-left) {\r\n --wje-dialog-width: 300px !important;\r\n --wje-dialog-height: 100% !important;\r\n --wje-dialog-border-radius: 0;\r\n --wje-dialog-border-width: 0 1px 0 0;\r\n --wje-dialog-margin-top: 0;\r\n --wje-dialog-margin-start: 0;\r\n --wje-dialog-margin-end: auto;\r\n --wje-dialog-margin-bottom: 0;\r\n dialog {\r\n min-height: var(--wje-dialog-height);\r\n --wje-dialog-translate-from: translateX(-110%);\r\n --wje-dialog-template-to: translateX(0);\r\n }\r\n}\r\n\r\n/*Slide Right*/\r\n:host(.slide-right) {\r\n --wje-dialog-width: 300px !important;\r\n --wje-dialog-height: 100% !important;\r\n --wje-dialog-border-radius: 0;\r\n --wje-dialog-border-width: 0 0 0 1px;\r\n --wje-dialog-margin-top: 0;\r\n --wje-dialog-margin-start: auto;\r\n --wje-dialog-margin-end: 0;\r\n --wje-dialog-margin-bottom: 0;\r\n dialog {\r\n min-height: var(--wje-dialog-height);\r\n --wje-dialog-translate-from: translateX(110%);\r\n --wje-dialog-template-to: translateX(0);\r\n }\r\n}\r\n\r\n:host(.small) {\r\n --wje-dialog-width: 300px !important;\r\n}\r\n\r\n:host(.medium) {\r\n --wje-dialog-width: 500px !important;\r\n}\r\n\r\n:host(.large) {\r\n --wje-dialog-width: 600px !important;\r\n}\r\n\r\n:host(.ex-large) {\r\n --wje-dialog-width: 900px !important;\r\n}\r\n\r\ndialog[open] {\r\n animation: show .5s ease normal;\r\n}\r\n\r\n@keyframes show{\r\n from {\r\n opacity: var(--wje-dialog-opacity-from, 1);\r\n transform: var(--wje-dialog-translate-from);\r\n }\r\n to {\r\n opacity: 1;\r\n transform: var(--wje-dialog-translate-to);\r\n }\r\n}';
|
|
9
|
+
const styles = '/*\r\n[ WJ Dialog ]\r\n*/\r\n\r\n:host {\r\n --wje-dialog-header-actions-gap: 0.5rem;\r\n \r\n .close {\r\n margin-left: auto;\r\n }\r\n\r\n .header-actions {\r\n margin-left: auto;\r\n display: flex;\r\n align-items: center;\r\n gap: var(--wje-dialog-header-actions-gap);\r\n }\r\n\r\n .modal-content {\r\n border-radius: 3px;\r\n box-shadow: none;\r\n }\r\n\r\n .dialog-header {\r\n position: relative;\r\n border-bottom: 0;\r\n padding-inline: var(--wje-dialog-padding);\r\n padding-top: var(--wje-dialog-padding);\r\n padding-bottom: var(--wje-dialog-padding);\r\n display: flex;\r\n align-items: center;\r\n span {\r\n font-family: var(--wje-font-family-secondary);\r\n font-size: 10.5px;\r\n text-transform: uppercase;\r\n display: inline-block;\r\n letter-spacing: 0.06em;\r\n font-weight: 500;\r\n margin: 0;\r\n padding: 0;\r\n line-height: normal;\r\n overflow: hidden;\r\n text-overflow: ellipsis;\r\n filter: alpha(opacity=40);\r\n }\r\n }\r\n\r\n .dialog-content {\r\n box-shadow: none;\r\n padding-inline: var(--wje-dialog-padding);\r\n white-space: normal;\r\n z-index: 1;\r\n }\r\n\r\n .dialog-footer {\r\n display: flex;\r\n justify-content: end;\r\n border-top: none;\r\n box-shadow: none;\r\n margin-top: 0;\r\n padding-inline: var(--wje-dialog-padding-inline);\r\n padding-top: var(--wje-dialog-padding-top);\r\n padding-bottom: var(--wje-dialog-padding-bottom);\r\n }\r\n}\r\n\r\ndialog::backdrop {\r\n opacity: var(--wje-backdrop-opacity);\r\n background-color: var(--wje-backdrop);\r\n}\r\n\r\ndialog:focus-visible {\r\n outline: none;\r\n}\r\n\r\n:host(.separator) .dialog-header:after {\r\n content: "";\r\n height: 1px;\r\n background: rgba(0, 0, 0, 0.08);\r\n left: var(--wje-dialog-padding);\r\n right: var(--wje-dialog-padding);\r\n position: absolute;\r\n bottom: 0;\r\n}\r\n\r\n:host {\r\n dialog {\r\n box-sizing: border-box;\r\n transition: all 0.2s !important;\r\n width: var(--wje-dialog-width);\r\n height: var(--wje-dialog-height);\r\n box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);\r\n\r\n border-radius: var(--wje-dialog-border-radius);\r\n border-width: var(--wje-dialog-border-width);\r\n border-style: var(--wje-dialog-border-style);\r\n border-color: var(--wje-dialog-border-color);\r\n\r\n margin-top: var(--wje-dialog-margin-top);\r\n\r\n margin-bottom: var(--wje-dialog-margin-bottom);\r\n margin-inline: var(--wje-dialog-margin-start) var(--wje-dialog-margin-end);\r\n\r\n padding: 0;\r\n }\r\n}\r\n\r\n/*Top*/\r\n:host(.stick-up) {\r\n --wje-dialog-width: 300px !important;\r\n --wje-dialog-height: fit-content;\r\n --wje-dialog-border-radius: 0 0 8px 8px;\r\n --wje-dialog-border-width: 0 1px 1px 1px;\r\n --wje-dialog-margin-top: 0;\r\n --wje-dialog-translate-from: translateY(-110%);\r\n --wje-dialog-template-to: translateX(0);\r\n}\r\n\r\n/*Cenetered*/\r\n:host(.slide-up) {\r\n --wje-dialog-width: 300px !important;\r\n --wje-dialog-height: fit-content;\r\n --wje-dialog-border-radius: 8px;\r\n --wje-dialog-border-width: 1px;\r\n --wje-dialog-opacity-from: 0;\r\n --wje-dialog-translate-from: scale(.9);\r\n --wje-dialog-translate-to: scale(1);\r\n}\r\n\r\n/*Fullscreen*/\r\n:host(.fill-in) {\r\n --wje-dialog-width: 100%;\r\n --wje-dialog-height: 100%;\r\n --wje-dialog-border-radius: 0 0 0 0 !important;\r\n --wje-dialog-border-width: 0;\r\n --wje-dialog-margin-top: 0;\r\n --wje-dialog-margin-start: 0;\r\n --wje-dialog-margin-end: 0;\r\n --wje-dialog-margin-bottom: 0;\r\n --wje-dialog-translate-from: scale(.95);\r\n --wje-dialog-translate-to: scale(1);\r\n dialog {\r\n min-width: var(--wje-dialog-width);\r\n min-height: var(--wje-dialog-height);\r\n }\r\n}\r\n\r\n/*Slide Left*/\r\n:host(.slide-left) {\r\n --wje-dialog-width: 300px !important;\r\n --wje-dialog-height: 100% !important;\r\n --wje-dialog-border-radius: 0;\r\n --wje-dialog-border-width: 0 1px 0 0;\r\n --wje-dialog-margin-top: 0;\r\n --wje-dialog-margin-start: 0;\r\n --wje-dialog-margin-end: auto;\r\n --wje-dialog-margin-bottom: 0;\r\n dialog {\r\n min-height: var(--wje-dialog-height);\r\n --wje-dialog-translate-from: translateX(-110%);\r\n --wje-dialog-template-to: translateX(0);\r\n }\r\n}\r\n\r\n/*Slide Right*/\r\n:host(.slide-right) {\r\n --wje-dialog-width: 300px !important;\r\n --wje-dialog-height: 100% !important;\r\n --wje-dialog-border-radius: 0;\r\n --wje-dialog-border-width: 0 0 0 1px;\r\n --wje-dialog-margin-top: 0;\r\n --wje-dialog-margin-start: auto;\r\n --wje-dialog-margin-end: 0;\r\n --wje-dialog-margin-bottom: 0;\r\n dialog {\r\n min-height: var(--wje-dialog-height);\r\n --wje-dialog-translate-from: translateX(110%);\r\n --wje-dialog-template-to: translateX(0);\r\n }\r\n}\r\n\r\n:host(.small) {\r\n --wje-dialog-width: 300px !important;\r\n}\r\n\r\n:host(.medium) {\r\n --wje-dialog-width: 500px !important;\r\n}\r\n\r\n:host(.large) {\r\n --wje-dialog-width: 600px !important;\r\n}\r\n\r\n:host(.ex-large) {\r\n --wje-dialog-width: 900px !important;\r\n}\r\n\r\ndialog[open] {\r\n animation: show .5s ease normal;\r\n}\r\n\r\n@keyframes show{\r\n from {\r\n opacity: var(--wje-dialog-opacity-from, 1);\r\n transform: var(--wje-dialog-translate-from);\r\n }\r\n to {\r\n opacity: 1;\r\n transform: var(--wje-dialog-translate-to);\r\n }\r\n}';
|
|
10
10
|
class Dialog extends WJElement {
|
|
11
11
|
constructor() {
|
|
12
12
|
super();
|
|
13
13
|
__publicField(this, "className", "Dialog");
|
|
14
14
|
__publicField(this, "onOpen", (e) => {
|
|
15
|
+
this.dialog.innerHTML = "";
|
|
15
16
|
Promise.resolve(this.beforeOpen(this, e)).then((res) => {
|
|
17
|
+
this.htmlDialogBody(this.dialog);
|
|
16
18
|
this.dialog.showModal();
|
|
17
19
|
if (this.dialog.open) {
|
|
18
20
|
Promise.resolve(this.afterOpen(this, e));
|
|
@@ -52,16 +54,19 @@ class Dialog extends WJElement {
|
|
|
52
54
|
draw(context, store, params) {
|
|
53
55
|
let fragment = document.createDocumentFragment();
|
|
54
56
|
this.classList.add("fade", this.placement, params.size);
|
|
55
|
-
let slot = document.createElement("slot");
|
|
56
57
|
let dialog = document.createElement("dialog");
|
|
57
58
|
dialog.classList.add("modal-dialog");
|
|
59
|
+
fragment.appendChild(dialog);
|
|
60
|
+
this.dialog = dialog;
|
|
61
|
+
return fragment;
|
|
62
|
+
}
|
|
63
|
+
htmlDialogBody(dialog) {
|
|
58
64
|
let icon = document.createElement("wje-icon");
|
|
59
65
|
icon.setAttribute("name", "x");
|
|
60
66
|
icon.setAttribute("slot", "icon-only");
|
|
61
67
|
let close = document.createElement("wje-button");
|
|
62
68
|
close.setAttribute("fill", "link");
|
|
63
69
|
close.setAttribute("size", "small");
|
|
64
|
-
close.classList.add("close");
|
|
65
70
|
close.addEventListener("click", () => {
|
|
66
71
|
this.close();
|
|
67
72
|
});
|
|
@@ -70,15 +75,20 @@ class Dialog extends WJElement {
|
|
|
70
75
|
header.setAttribute("part", "header");
|
|
71
76
|
header.classList.add("dialog-header");
|
|
72
77
|
if (this.hasAttribute("headline"))
|
|
73
|
-
header.innerHTML = `<span part="headline">${this.headline}</span>`;
|
|
74
|
-
header.appendChild(close);
|
|
78
|
+
header.innerHTML = `<span part="headline">${this.getAttribute("headline")}</span>`;
|
|
75
79
|
let slotHeader = document.createElement("slot");
|
|
76
80
|
slotHeader.setAttribute("name", "header");
|
|
77
|
-
|
|
81
|
+
const headerActions = document.createElement("div");
|
|
82
|
+
headerActions.classList.add("header-actions");
|
|
83
|
+
headerActions.setAttribute("part", "header-actions");
|
|
84
|
+
headerActions.appendChild(slotHeader);
|
|
85
|
+
header.appendChild(headerActions);
|
|
86
|
+
header.appendChild(close);
|
|
87
|
+
let contentSlot = document.createElement("slot");
|
|
78
88
|
let body = document.createElement("div");
|
|
79
89
|
body.setAttribute("part", "body");
|
|
80
90
|
body.classList.add("dialog-content");
|
|
81
|
-
body.appendChild(
|
|
91
|
+
body.appendChild(contentSlot);
|
|
82
92
|
let footer = document.createElement("div");
|
|
83
93
|
footer.setAttribute("part", "footer");
|
|
84
94
|
footer.classList.add("dialog-footer");
|
|
@@ -89,9 +99,6 @@ class Dialog extends WJElement {
|
|
|
89
99
|
dialog.appendChild(header);
|
|
90
100
|
dialog.appendChild(body);
|
|
91
101
|
dialog.appendChild(footer);
|
|
92
|
-
fragment.appendChild(dialog);
|
|
93
|
-
this.dialog = dialog;
|
|
94
|
-
return fragment;
|
|
95
102
|
}
|
|
96
103
|
close() {
|
|
97
104
|
this.onClose();
|
|
@@ -67,7 +67,7 @@ class FileUploadItem extends WJElement {
|
|
|
67
67
|
if (name === "uploaded" && this.drawingStatus === "AFTER") {
|
|
68
68
|
this.uploadedEl.setAttribute("value", this.uploaded);
|
|
69
69
|
let progress = +this.uploaded / +this.size * 100 || 0;
|
|
70
|
-
this.sliderEl.
|
|
70
|
+
this.sliderEl.value = Math.round(progress, 0);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
/**
|
package/dist/wje-file-upload.js
CHANGED
|
@@ -84,43 +84,55 @@ function isValidFileType(file, acceptedFileTypes) {
|
|
|
84
84
|
}
|
|
85
85
|
return false;
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
};
|
|
105
|
-
xhr.onload = () => {
|
|
106
|
-
if (xhr.status == 200 || xhr.status == 201) {
|
|
107
|
-
progressArray[chunkIndex] = 100;
|
|
108
|
-
start2 += chunkSize;
|
|
109
|
-
if (start2 < file.size) {
|
|
110
|
-
preview.setAttribute("uploaded", start2);
|
|
111
|
-
readAndUploadChunk(start2, Math.min(start2 + chunkSize, file.size));
|
|
112
|
-
} else {
|
|
113
|
-
preview.setAttribute("uploaded", start2);
|
|
87
|
+
function upload(url, chunkSize = 1024 * 1024) {
|
|
88
|
+
return (file, preview) => uploadFileInChunks(url, chunkSize, file, preview);
|
|
89
|
+
}
|
|
90
|
+
async function uploadFileInChunks(url, chunkSize = 1024 * 1024, file, preview) {
|
|
91
|
+
let offset = 0;
|
|
92
|
+
const totalChunks = Math.ceil(file.size / chunkSize);
|
|
93
|
+
const partResponses = [];
|
|
94
|
+
while (offset < file.size) {
|
|
95
|
+
const chunk = file.slice(offset, offset + chunkSize);
|
|
96
|
+
const stream = new ReadableStream({
|
|
97
|
+
start(controller) {
|
|
98
|
+
const reader = chunk.stream().getReader();
|
|
99
|
+
let uploadedBytes = 0;
|
|
100
|
+
reader.read().then(function process({ done, value }) {
|
|
101
|
+
if (done) {
|
|
102
|
+
controller.close();
|
|
103
|
+
return;
|
|
114
104
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
105
|
+
uploadedBytes += value.byteLength;
|
|
106
|
+
const percentComplete = (offset + uploadedBytes) / file.size * 100;
|
|
107
|
+
console.log(`Upload Progress: ${percentComplete.toFixed(2)}%`);
|
|
108
|
+
preview.setAttribute("uploaded", offset + uploadedBytes);
|
|
109
|
+
controller.enqueue(value);
|
|
110
|
+
return reader.read().then(process);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
const formData = new FormData();
|
|
115
|
+
formData.append("file", new Blob([stream]));
|
|
116
|
+
formData.append("chunkIndex", Math.floor(offset / chunkSize));
|
|
117
|
+
formData.append("totalChunks", totalChunks);
|
|
118
|
+
try {
|
|
119
|
+
const response = await fetch(url, {
|
|
120
|
+
method: "POST",
|
|
121
|
+
body: formData
|
|
122
|
+
});
|
|
123
|
+
if (!response.ok) {
|
|
124
|
+
throw new Error(`Failed to upload chunk ${Math.floor(offset / chunkSize) + 1}: ${response.statusText}`);
|
|
125
|
+
}
|
|
126
|
+
console.log(`Chunk ${Math.floor(offset / chunkSize) + 1}/${totalChunks} uploaded successfully.`);
|
|
127
|
+
partResponses.push(response);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
console.error("Error uploading chunk:", error);
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
offset += chunkSize;
|
|
133
|
+
}
|
|
134
|
+
console.log("File upload complete!");
|
|
135
|
+
return partResponses.at(-1).json();
|
|
124
136
|
}
|
|
125
137
|
const styles = '/*\r\n[ WJ File Upload ]\r\n*/\r\n\r\n:host {\r\n width: 100%;\r\n}\r\n\r\n.native-file-upload {\r\n width: 100%;\r\n}\r\n\r\n.file-label {\r\n background: var(--wje-color-contrast-0);\r\n border: 1px dashed var(--wje-border-color);\r\n border-radius: var(--wje-border-radius-medium);\r\n align-items: center;\r\n justify-content: center;\r\n display: flex;\r\n padding: 1rem;\r\n margin-bottom: .5rem;\r\n flex-direction: column;\r\n}\r\n\r\n.file-preview {\r\n display: grid;\r\n grid-template-columns: auto 1fr 1fr;\r\n grid-template-rows: auto auto auto;\r\n gap: 0 0;\r\n grid-template-areas:\r\n "image name name"\r\n "image size size"\r\n "progress progress progress";\r\n}\r\n\r\n.file-image {\r\n grid-area: image;\r\n align-items: center;\r\n display: flex;\r\n}\r\n\r\n.file-name {\r\n grid-area: name;\r\n white-space: nowrap;\r\n overflow: hidden;\r\n text-overflow: ellipsis;\r\n}\r\n\r\n.file-size {\r\n grid-area: size;\r\n display: flex;\r\n}\r\n\r\n.file-progress { grid-area: progress; }\r\n\r\nwje-icon {\r\n margin-right: .25rem;\r\n}\r\n\r\nwje-img {\r\n margin-right: .25rem;\r\n}\r\n\r\n.file-info > span {\r\n white-space: nowrap;\r\n overflow: hidden;\r\n text-overflow: ellipsis;\r\n}\r\n\r\nwje-slider {\r\n flex-basis: 100%;\r\n margin-top: .5rem;\r\n}\r\n\r\n::part(slider) {\r\n &::-webkit-slider-thumb {\r\n visibility: hidden;\r\n }\r\n\r\n &::-moz-range-thumb {\r\n visibility: hidden;\r\n }\r\n\r\n &::-ms-thumb {\r\n visibility: hidden;\r\n }\r\n}\r\n\r\nwje-img {\r\n width: 50px;\r\n height: 50px;\r\n display: flex;\r\n align-items: center;\r\n padding: .25rem;\r\n border: 1px solid var(--wje-border-color);\r\n border-radius: var(--wje-border-radius-medium);\r\n}';
|
|
126
138
|
class FileUpload extends WJElement {
|
|
@@ -160,6 +172,7 @@ class FileUpload extends WJElement {
|
|
|
160
172
|
}
|
|
161
173
|
});
|
|
162
174
|
this.localizer = new Localizer(this);
|
|
175
|
+
this._uploadedFiles = [];
|
|
163
176
|
}
|
|
164
177
|
/**
|
|
165
178
|
* Setter for acceptedTypes attribute.
|
|
@@ -206,6 +219,28 @@ class FileUpload extends WJElement {
|
|
|
206
219
|
const fileSize = this.getAttribute("max-file-size");
|
|
207
220
|
return this.hasAttribute("max-file-size") ? fileSize * 1024 * 1024 : 1024 * 1024;
|
|
208
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Sets the upload URL for the file upload element.
|
|
224
|
+
*
|
|
225
|
+
* @param {string} value - The URL to set as the upload URL.
|
|
226
|
+
*/
|
|
227
|
+
set uploadUrl(value) {
|
|
228
|
+
this.setAttribute("upload-url", value);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Retrieves the upload URL for the file upload element.
|
|
232
|
+
*
|
|
233
|
+
* @returns {string} The upload URL.
|
|
234
|
+
*/
|
|
235
|
+
get uploadUrl() {
|
|
236
|
+
return this.getAttribute("upload-url") ?? "/upload";
|
|
237
|
+
}
|
|
238
|
+
set uploadedFiles(value) {
|
|
239
|
+
this._uploadedFiles = value;
|
|
240
|
+
}
|
|
241
|
+
get uploadedFiles() {
|
|
242
|
+
return this._uploadedFiles;
|
|
243
|
+
}
|
|
209
244
|
/**
|
|
210
245
|
* Getter for cssStyleSheet.
|
|
211
246
|
* @returns {string} The CSS styles for the component.
|
|
@@ -226,6 +261,9 @@ class FileUpload extends WJElement {
|
|
|
226
261
|
setupAttributes() {
|
|
227
262
|
this.isShadowRoot = "open";
|
|
228
263
|
}
|
|
264
|
+
beforeDraw() {
|
|
265
|
+
this.uploadFunction = upload(this.uploadUrl, this.chunkSize);
|
|
266
|
+
}
|
|
229
267
|
/**
|
|
230
268
|
* Method to draw the component.
|
|
231
269
|
* @param {Object} context - The context of the component.
|
|
@@ -323,7 +361,9 @@ class FileUpload extends WJElement {
|
|
|
323
361
|
reader.onload = (e) => {
|
|
324
362
|
preview = this.createPreview(file, reader);
|
|
325
363
|
this.fileList.appendChild(preview);
|
|
326
|
-
|
|
364
|
+
this.uploadFunction(file, preview).then((res) => {
|
|
365
|
+
this.uploadedFiles.push(res);
|
|
366
|
+
});
|
|
327
367
|
};
|
|
328
368
|
reader.readAsDataURL(file);
|
|
329
369
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wj-elements",
|
|
3
3
|
"description": "WebJET Elements is a modern set of user interface tools harnessing the power of web components designed to simplify web application development.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.102",
|
|
5
5
|
"homepage": "https://github.com/lencys/wj-elements",
|
|
6
6
|
"author": "Lukáš Ondrejček <lukas.ondrejcek@gmail.com>",
|
|
7
7
|
"license": "MIT",
|