@cedx/base 0.17.0 → 0.19.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/ReadMe.md +1 -1
- package/lib/UI/Components/DialogButton.d.ts.map +1 -1
- package/lib/UI/Components/DialogButton.js +12 -3
- package/lib/UI/Components/LoadingIndicator.d.ts.map +1 -1
- package/lib/UI/Components/LoadingIndicator.js +4 -2
- package/lib/UI/Components/MessageBox.d.ts +165 -0
- package/lib/UI/Components/MessageBox.d.ts.map +1 -0
- package/lib/UI/Components/MessageBox.js +320 -0
- package/lib/UI/Components/OfflineIndicator.d.ts.map +1 -1
- package/lib/UI/Components/OfflineIndicator.js +4 -1
- package/lib/UI/Components/ThemeDropdown.d.ts.map +1 -1
- package/lib/UI/Components/Toast.d.ts.map +1 -1
- package/lib/UI/Components/Toast.js +31 -16
- package/lib/UI/Components/Toaster.d.ts +6 -2
- package/lib/UI/Components/Toaster.d.ts.map +1 -1
- package/lib/UI/Components/Toaster.js +19 -12
- package/package.json +3 -3
- package/src/Client/UI/Components/DialogButton.ts +6 -3
- package/src/Client/UI/Components/LoadingIndicator.ts +4 -2
- package/src/Client/UI/Components/MessageBox.ts +417 -0
- package/src/Client/UI/Components/OfflineIndicator.ts +4 -1
- package/src/Client/UI/Components/ThemeDropdown.ts +3 -9
- package/src/Client/UI/Components/Toast.ts +26 -15
- package/src/Client/UI/Components/Toaster.ts +27 -11
|
@@ -89,15 +89,9 @@ export class ThemeDropdown extends HTMLElement {
|
|
|
89
89
|
*/
|
|
90
90
|
attributeChangedCallback(attribute: string, oldValue: string|null, newValue: string|null): void {
|
|
91
91
|
if (newValue != oldValue) switch (attribute) {
|
|
92
|
-
case "alignment":
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
case "apptheme":
|
|
96
|
-
this.#updateAppTheme(Object.values(AppTheme).includes(newValue as AppTheme) ? newValue as AppTheme : AppTheme.System);
|
|
97
|
-
break;
|
|
98
|
-
case "label":
|
|
99
|
-
this.#updateLabel(newValue ?? "");
|
|
100
|
-
break;
|
|
92
|
+
case "alignment": this.#updateAlignment(Object.values(Alignment).includes(newValue as Alignment) ? newValue as Alignment : Alignment.End); break;
|
|
93
|
+
case "apptheme": this.#updateAppTheme(Object.values(AppTheme).includes(newValue as AppTheme) ? newValue as AppTheme : AppTheme.System); break;
|
|
94
|
+
case "label": this.#updateLabel(newValue ?? ""); break;
|
|
101
95
|
// No default
|
|
102
96
|
}
|
|
103
97
|
}
|
|
@@ -55,7 +55,7 @@ export class Toast extends HTMLElement {
|
|
|
55
55
|
/**
|
|
56
56
|
* The list of observed attributes.
|
|
57
57
|
*/
|
|
58
|
-
static readonly observedAttributes = ["animation", "caption", "context", "culture", "
|
|
58
|
+
static readonly observedAttributes = ["animation", "autohide", "caption", "context", "culture", "delay", "icon"];
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* The time units.
|
|
@@ -174,7 +174,8 @@ export class Toast extends HTMLElement {
|
|
|
174
174
|
return value.trim() || null;
|
|
175
175
|
}
|
|
176
176
|
set icon(value: string|null) {
|
|
177
|
-
this.
|
|
177
|
+
if (value) this.setAttribute("icon", value);
|
|
178
|
+
else this.removeAttribute("icon");
|
|
178
179
|
}
|
|
179
180
|
|
|
180
181
|
/**
|
|
@@ -196,11 +197,12 @@ export class Toast extends HTMLElement {
|
|
|
196
197
|
attributeChangedCallback(attribute: string, oldValue: string|null, newValue: string|null): void {
|
|
197
198
|
if (newValue != oldValue) switch (attribute) {
|
|
198
199
|
case "animation": this.#updateAnimation(newValue != null); break;
|
|
200
|
+
case "autohide": this.#updateAutoHide(newValue != null); break;
|
|
199
201
|
case "caption": this.#updateCaption(newValue ?? ""); break;
|
|
200
202
|
case "context": this.#updateContext(Object.values(Context).includes(newValue as Context) ? newValue as Context : Context.Info); break;
|
|
201
203
|
case "culture": this.#formatter = new Intl.RelativeTimeFormat((newValue ?? "").trim() || navigator.language, {style: "long"}); break;
|
|
204
|
+
case "delay": this.#updateDelay(Number(newValue)); break;
|
|
202
205
|
case "icon": this.#updateIcon(newValue); break;
|
|
203
|
-
case "open": this.#updateVisibility(newValue != null); break;
|
|
204
206
|
// No default
|
|
205
207
|
}
|
|
206
208
|
}
|
|
@@ -220,8 +222,8 @@ export class Toast extends HTMLElement {
|
|
|
220
222
|
toast.addEventListener("hidden.bs.toast", () => clearInterval(this.#timer));
|
|
221
223
|
toast.addEventListener("show.bs.toast", () => this.#timer = window.setInterval(this.#updateElapsedTime, 1_000));
|
|
222
224
|
|
|
223
|
-
|
|
224
|
-
this
|
|
225
|
+
this.#toast = new BootstrapToast(toast);
|
|
226
|
+
if (this.open) this.show();
|
|
225
227
|
}
|
|
226
228
|
|
|
227
229
|
/**
|
|
@@ -260,11 +262,19 @@ export class Toast extends HTMLElement {
|
|
|
260
262
|
}
|
|
261
263
|
|
|
262
264
|
/**
|
|
263
|
-
* Updates the
|
|
265
|
+
* Updates the value indicating whether to apply a fade transition.
|
|
264
266
|
* @param value The new value.
|
|
265
267
|
*/
|
|
266
268
|
#updateAnimation(value: boolean): void {
|
|
267
|
-
this.firstElementChild
|
|
269
|
+
(this.firstElementChild! as HTMLElement).dataset.bsAnimation = value ? "true" : "false";
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Updates the value indicating whether to automatically hide this toast.
|
|
274
|
+
* @param value The new value.
|
|
275
|
+
*/
|
|
276
|
+
#updateAutoHide(value: boolean): void {
|
|
277
|
+
(this.firstElementChild! as HTMLElement).dataset.bsAutohide = value ? "true" : "false";
|
|
268
278
|
}
|
|
269
279
|
|
|
270
280
|
/**
|
|
@@ -291,6 +301,15 @@ export class Toast extends HTMLElement {
|
|
|
291
301
|
classList.add(`text-${toCss(value)}`);
|
|
292
302
|
}
|
|
293
303
|
|
|
304
|
+
/**
|
|
305
|
+
* Updates the delay to hide the toast.
|
|
306
|
+
* @param value The new value.
|
|
307
|
+
*/
|
|
308
|
+
#updateDelay(value: number): void {
|
|
309
|
+
const delay = Math.max(0, Number.isNaN(value) ? 5_000 : value);
|
|
310
|
+
(this.firstElementChild! as HTMLElement).dataset.bsDelay = delay.toString();
|
|
311
|
+
}
|
|
312
|
+
|
|
294
313
|
/**
|
|
295
314
|
* Updates the label corresponding to the elapsed time.
|
|
296
315
|
*/
|
|
@@ -306,14 +325,6 @@ export class Toast extends HTMLElement {
|
|
|
306
325
|
#updateIcon(value: string|null): void {
|
|
307
326
|
this.querySelector(".toast-header .icon")!.textContent = (value ?? "").trim() || getIcon(this.context);
|
|
308
327
|
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Updates the toast visibility.
|
|
312
|
-
* @param value The new value.
|
|
313
|
-
*/
|
|
314
|
-
#updateVisibility(value: boolean): void {
|
|
315
|
-
this.firstElementChild!.classList.toggle("show", value);
|
|
316
|
-
}
|
|
317
328
|
}
|
|
318
329
|
|
|
319
330
|
/**
|
|
@@ -18,6 +18,14 @@ export class Toaster extends HTMLElement {
|
|
|
18
18
|
*/
|
|
19
19
|
readonly #toastTemplate: DocumentFragment = this.querySelector("template")!.content;
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new toaster.
|
|
23
|
+
*/
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
for (const toast of this.querySelectorAll("toaster-item")) toast.addEventListener("hidden.bs.toast", () => toast.remove());
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
/**
|
|
22
30
|
* Registers the component.
|
|
23
31
|
*/
|
|
@@ -86,7 +94,8 @@ export class Toaster extends HTMLElement {
|
|
|
86
94
|
return value.trim() || null;
|
|
87
95
|
}
|
|
88
96
|
set icon(value: string|null) {
|
|
89
|
-
this.
|
|
97
|
+
if (value) this.setAttribute("icon", value);
|
|
98
|
+
else this.removeAttribute("icon");
|
|
90
99
|
}
|
|
91
100
|
|
|
92
101
|
/**
|
|
@@ -108,9 +117,7 @@ export class Toaster extends HTMLElement {
|
|
|
108
117
|
*/
|
|
109
118
|
attributeChangedCallback(attribute: string, oldValue: string|null, newValue: string|null): void {
|
|
110
119
|
if (newValue != oldValue) switch (attribute) {
|
|
111
|
-
case "position":
|
|
112
|
-
this.#updatePosition(Object.values(Position).includes(newValue as Position) ? newValue as Position : Position.BottomEnd);
|
|
113
|
-
break;
|
|
120
|
+
case "position": this.#updatePosition(Object.values(Position).includes(newValue as Position) ? newValue as Position : Position.BottomEnd); break;
|
|
114
121
|
// No default
|
|
115
122
|
}
|
|
116
123
|
}
|
|
@@ -121,18 +128,27 @@ export class Toaster extends HTMLElement {
|
|
|
121
128
|
* @param caption The title displayed in the toast header.
|
|
122
129
|
* @param body The child content displayed in the toast body.
|
|
123
130
|
*/
|
|
124
|
-
|
|
125
|
-
this.show({context, caption, body});
|
|
126
|
-
}
|
|
131
|
+
show(context: Context, caption: string, body: DocumentFragment|string): void;
|
|
127
132
|
|
|
128
133
|
/**
|
|
129
|
-
* Shows
|
|
134
|
+
* Shows a toast.
|
|
130
135
|
* @param toast The toast to show.
|
|
131
136
|
*/
|
|
132
|
-
show(toast: IToast): void
|
|
137
|
+
show(toast: IToast): void;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Shows a toast.
|
|
141
|
+
* @param toast The toast to show, or the contextual modifier.
|
|
142
|
+
* @param caption The title displayed in the toast header.
|
|
143
|
+
* @param body The child content displayed in the toast body.
|
|
144
|
+
*/
|
|
145
|
+
show(toast: IToast|Context, caption = "", body: DocumentFragment|string = ""): void {
|
|
146
|
+
if (typeof toast == "string") toast = {context: toast, caption, body};
|
|
147
|
+
|
|
133
148
|
const item = document.createElement("toaster-item");
|
|
134
|
-
|
|
135
|
-
|
|
149
|
+
const childContent = (this.#toastTemplate.cloneNode(true) as DocumentFragment).querySelector(".toast")!;
|
|
150
|
+
childContent.addEventListener("hidden.bs.toast", () => item.remove());
|
|
151
|
+
item.appendChild(childContent);
|
|
136
152
|
|
|
137
153
|
item.animation = toast.animation ?? this.animation;
|
|
138
154
|
item.autoHide = toast.autoHide ?? this.autoHide;
|