@cedx/base 0.21.1 → 0.23.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/BackButton.d.ts +2 -1
- package/lib/UI/Components/BackButton.d.ts.map +1 -1
- package/lib/UI/Components/BackButton.js +10 -2
- package/lib/UI/Components/DialogBox.d.ts +39 -23
- package/lib/UI/Components/DialogBox.d.ts.map +1 -1
- package/lib/UI/Components/DialogBox.js +48 -70
- package/lib/UI/Components/FullScreenToggler.d.ts +46 -0
- package/lib/UI/Components/FullScreenToggler.d.ts.map +1 -0
- package/lib/UI/Components/FullScreenToggler.js +109 -0
- package/lib/UI/Components/ThemeDropdown.js +3 -3
- package/lib/UI/Components/Toast.d.ts +0 -37
- package/lib/UI/Components/Toast.d.ts.map +1 -1
- package/lib/UI/Components/Toast.js +4 -4
- package/lib/UI/Components/Toaster.d.ts +39 -3
- package/lib/UI/Components/Toaster.d.ts.map +1 -1
- package/lib/UI/Components/Toaster.js +10 -5
- package/lib/UI/DialogResult.d.ts +2 -10
- package/lib/UI/DialogResult.d.ts.map +1 -1
- package/lib/UI/DialogResult.js +3 -11
- package/lib/UI/Tag.js +10 -6
- package/lib/UI/Variant.d.ts +12 -8
- package/lib/UI/Variant.d.ts.map +1 -1
- package/lib/UI/Variant.js +10 -8
- package/package.json +1 -1
- package/src/Client/UI/Components/BackButton.ts +11 -2
- package/src/Client/UI/Components/DialogBox.ts +79 -97
- package/src/Client/UI/Components/FullScreenToggler.ts +127 -0
- package/src/Client/UI/Components/ThemeDropdown.ts +3 -3
- package/src/Client/UI/Components/Toast.ts +4 -50
- package/src/Client/UI/Components/Toaster.ts +51 -14
- package/src/Client/UI/DialogResult.ts +3 -13
- package/src/Client/UI/Tag.ts +10 -4
- package/src/Client/UI/Variant.ts +11 -8
- package/lib/UI/Components/DialogButton.d.ts +0 -82
- package/lib/UI/Components/DialogButton.d.ts.map +0 -1
- package/lib/UI/Components/DialogButton.js +0 -151
- package/src/Client/UI/Components/DialogButton.ts +0 -190
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A component for toggling an element to full-screen.
|
|
3
|
+
*/
|
|
4
|
+
export class FullScreenToggler extends HTMLElement {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The associated element.
|
|
8
|
+
*/
|
|
9
|
+
#element: Element = document.body;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The handle to the underlying platform wake lock.
|
|
13
|
+
*/
|
|
14
|
+
#sentinel: WakeLockSentinel|null = null;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new full-screen toggler.
|
|
18
|
+
*/
|
|
19
|
+
constructor() {
|
|
20
|
+
super();
|
|
21
|
+
this.addEventListener("click", this.toggleFullScreen.bind(this)); // eslint-disable-line @typescript-eslint/no-misused-promises
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Registers the component.
|
|
26
|
+
*/
|
|
27
|
+
static {
|
|
28
|
+
customElements.define("fullscreen-toggler", this);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The CSS selector used to target the element.
|
|
33
|
+
*/
|
|
34
|
+
get target(): string {
|
|
35
|
+
const value = this.getAttribute("target") ?? "";
|
|
36
|
+
return value.trim() || "body";
|
|
37
|
+
}
|
|
38
|
+
set target(value: string) {
|
|
39
|
+
this.setAttribute("target", value);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Value indicating whether to prevent the device screen from dimming or locking when in full-screen mode.
|
|
44
|
+
*/
|
|
45
|
+
get wakeLock(): boolean {
|
|
46
|
+
return this.hasAttribute("wakeLock");
|
|
47
|
+
}
|
|
48
|
+
set wakeLock(value: boolean) {
|
|
49
|
+
this.toggleAttribute("target", value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Method invoked when this component is connected.
|
|
54
|
+
*/
|
|
55
|
+
connectedCallback(): void {
|
|
56
|
+
document.addEventListener("visibilitychange", this.#onVisibilityChanged);
|
|
57
|
+
this.#element = document.querySelector(this.target) ?? document.body;
|
|
58
|
+
this.#element.addEventListener("fullscreenchange", this.#onFullScreenChanged);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Method invoked when this component is disconnected.
|
|
63
|
+
*/
|
|
64
|
+
disconnectedCallback(): void {
|
|
65
|
+
document.removeEventListener("visibilitychange", this.#onVisibilityChanged);
|
|
66
|
+
this.#element.removeEventListener("fullscreenchange", this.#onFullScreenChanged);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Toggles the full-screen mode of the associated element.
|
|
71
|
+
* @param event The dispatched event.
|
|
72
|
+
* @returns Resolves when the full-screen mode has been toggled.
|
|
73
|
+
*/
|
|
74
|
+
async toggleFullScreen(event?: Event): Promise<void> {
|
|
75
|
+
event?.preventDefault();
|
|
76
|
+
if (document.fullscreenElement) await document.exitFullscreen();
|
|
77
|
+
else await this.#element.requestFullscreen();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Acquires a new wake lock.
|
|
82
|
+
* @returns Resolves when the wake lock has been acquired.
|
|
83
|
+
*/
|
|
84
|
+
async #acquireWakeLock(): Promise<void> {
|
|
85
|
+
if (this.#sentinel && !this.#sentinel.released) return;
|
|
86
|
+
if (this.wakeLock) this.#sentinel = await navigator.wakeLock.request();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Acquires or releases the wake lock when the document enters or exits the full-screen mode.
|
|
91
|
+
* @param event The dispatched event.
|
|
92
|
+
*/
|
|
93
|
+
readonly #onFullScreenChanged: (event: Event) => void = () => {
|
|
94
|
+
if (document.fullscreenElement) void this.#acquireWakeLock();
|
|
95
|
+
else void this.#releaseWakeLock();
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Eventually acquires a new wake lock when the document visibility has changed.
|
|
100
|
+
* @param event The dispatched event.
|
|
101
|
+
*/
|
|
102
|
+
readonly #onVisibilityChanged: (event: Event) => void = () => {
|
|
103
|
+
if (document.fullscreenElement && !document.hidden) void this.#acquireWakeLock();
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Releases the acquired wake lock.
|
|
108
|
+
* @returns Resolves when the wake lock has been released.
|
|
109
|
+
*/
|
|
110
|
+
async #releaseWakeLock(): Promise<void> {
|
|
111
|
+
if (!this.#sentinel || this.#sentinel.released) return;
|
|
112
|
+
await this.#sentinel.release();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Declaration merging.
|
|
118
|
+
*/
|
|
119
|
+
declare global {
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The map of HTML tag names.
|
|
123
|
+
*/
|
|
124
|
+
interface HTMLElementTagNameMap {
|
|
125
|
+
"fullscreen-toggler": FullScreenToggler;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -27,7 +27,7 @@ export class ThemeDropdown extends HTMLElement {
|
|
|
27
27
|
*/
|
|
28
28
|
constructor() {
|
|
29
29
|
super();
|
|
30
|
-
for (const button of this.querySelectorAll(".dropdown-menu button")) button.addEventListener("click", this.#setAppTheme);
|
|
30
|
+
for (const button of this.querySelectorAll(".dropdown-menu button")) button.addEventListener("click", this.#setAppTheme.bind(this));
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
@@ -149,11 +149,11 @@ export class ThemeDropdown extends HTMLElement {
|
|
|
149
149
|
* Changes the current application theme.
|
|
150
150
|
* @param event The dispatched event.
|
|
151
151
|
*/
|
|
152
|
-
|
|
152
|
+
#setAppTheme(event: Event): void {
|
|
153
153
|
event.preventDefault();
|
|
154
154
|
this.appTheme = (event.target as Element).closest("button")!.dataset.theme! as AppTheme;
|
|
155
155
|
this.save();
|
|
156
|
-
}
|
|
156
|
+
}
|
|
157
157
|
|
|
158
158
|
/**
|
|
159
159
|
* Updates the alignment of the dropdown menu.
|
|
@@ -1,52 +1,6 @@
|
|
|
1
1
|
import {Toast as BootstrapToast} from "bootstrap";
|
|
2
2
|
import {Context, getIcon, toCss} from "../Context.js";
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Represents a notification.
|
|
6
|
-
*/
|
|
7
|
-
export interface IToast {
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Value indicating whether to automatically hide the toast.
|
|
11
|
-
*/
|
|
12
|
-
autoHide?: boolean;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The child content displayed in the body.
|
|
16
|
-
*/
|
|
17
|
-
body: DocumentFragment;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The title displayed in the header.
|
|
21
|
-
*/
|
|
22
|
-
caption: string;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The default contextual modifier.
|
|
26
|
-
*/
|
|
27
|
-
context?: Context;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The culture used to format the relative time.
|
|
31
|
-
*/
|
|
32
|
-
culture?: Intl.Locale;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* The delay, in milliseconds, to hide the toast.
|
|
36
|
-
*/
|
|
37
|
-
delay?: number;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Value indicating whether to apply a transition.
|
|
41
|
-
*/
|
|
42
|
-
fade?: boolean;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* The icon displayed next to the caption.
|
|
46
|
-
*/
|
|
47
|
-
icon?: string|null;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
4
|
/**
|
|
51
5
|
* Represents a notification.
|
|
52
6
|
*/
|
|
@@ -219,8 +173,8 @@ export class Toast extends HTMLElement {
|
|
|
219
173
|
*/
|
|
220
174
|
connectedCallback(): void {
|
|
221
175
|
const toast = this.firstElementChild!;
|
|
222
|
-
toast.addEventListener("
|
|
223
|
-
toast.addEventListener("show.bs.toast", () => this.#timer = window.setInterval(this.#updateElapsedTime, 1_000));
|
|
176
|
+
toast.addEventListener("hide.bs.toast", () => clearInterval(this.#timer));
|
|
177
|
+
toast.addEventListener("show.bs.toast", () => this.#timer = window.setInterval(() => this.#updateElapsedTime(), 1_000));
|
|
224
178
|
|
|
225
179
|
this.#toast = new BootstrapToast(toast);
|
|
226
180
|
if (this.open) this.show();
|
|
@@ -305,10 +259,10 @@ export class Toast extends HTMLElement {
|
|
|
305
259
|
/**
|
|
306
260
|
* Updates the label corresponding to the elapsed time.
|
|
307
261
|
*/
|
|
308
|
-
|
|
262
|
+
#updateElapsedTime(): void {
|
|
309
263
|
const {elapsedTime} = this;
|
|
310
264
|
this.querySelector(".toast-header small")!.textContent = elapsedTime > 0 ? this.#formatTime(elapsedTime / 1_000) : "";
|
|
311
|
-
}
|
|
265
|
+
}
|
|
312
266
|
|
|
313
267
|
/**
|
|
314
268
|
* Updates the value indicating whether to apply a transition.
|
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
import {Context} from "../Context.js";
|
|
2
2
|
import {Position, toCss} from "../Position.js";
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Represents a notification.
|
|
6
|
+
*/
|
|
7
|
+
export interface IToast {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Value indicating whether to automatically hide the toast.
|
|
11
|
+
*/
|
|
12
|
+
autoHide?: boolean;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The child content displayed in the body.
|
|
16
|
+
*/
|
|
17
|
+
body: DocumentFragment;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The title displayed in the header.
|
|
21
|
+
*/
|
|
22
|
+
caption: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The default contextual modifier.
|
|
26
|
+
*/
|
|
27
|
+
context?: Context;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The culture used to format the relative time.
|
|
31
|
+
*/
|
|
32
|
+
culture?: Intl.Locale;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The delay, in milliseconds, to hide the toast.
|
|
36
|
+
*/
|
|
37
|
+
delay?: number;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Value indicating whether to apply a transition.
|
|
41
|
+
*/
|
|
42
|
+
fade?: boolean;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The icon displayed next to the caption.
|
|
46
|
+
*/
|
|
47
|
+
icon?: string;
|
|
48
|
+
}
|
|
4
49
|
|
|
5
50
|
/**
|
|
6
51
|
* Manages the notifications.
|
|
@@ -125,25 +170,17 @@ export class Toaster extends HTMLElement {
|
|
|
125
170
|
* Shows a toast.
|
|
126
171
|
* @param context The contextual modifier.
|
|
127
172
|
* @param caption The title displayed in the toast header.
|
|
128
|
-
* @param
|
|
173
|
+
* @param message The child content displayed in the toast body.
|
|
129
174
|
*/
|
|
130
|
-
|
|
175
|
+
notify(context: Context, caption: string, message: DocumentFragment): void {
|
|
176
|
+
return this.show({body: message, caption, context});
|
|
177
|
+
}
|
|
131
178
|
|
|
132
179
|
/**
|
|
133
180
|
* Shows a toast.
|
|
134
181
|
* @param toast The toast to show.
|
|
135
182
|
*/
|
|
136
|
-
show(toast: IToast): void
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Shows a toast.
|
|
140
|
-
* @param toast The toast to show, or the contextual modifier.
|
|
141
|
-
* @param caption The title displayed in the toast header.
|
|
142
|
-
* @param body The child content displayed in the toast body.
|
|
143
|
-
*/
|
|
144
|
-
show(toast: IToast|Context, caption = "", body = document.createDocumentFragment()): void {
|
|
145
|
-
if (typeof toast == "string") toast = {context: toast, caption, body};
|
|
146
|
-
|
|
183
|
+
show(toast: IToast): void {
|
|
147
184
|
const item = document.createElement("toaster-item");
|
|
148
185
|
const childContent = (this.#toastTemplate.cloneNode(true) as DocumentFragment).querySelector(".toast")!;
|
|
149
186
|
childContent.addEventListener("hidden.bs.toast", () => item.remove());
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Specifies
|
|
2
|
+
* Specifies common return values of a dialog box.
|
|
3
3
|
*/
|
|
4
4
|
export const DialogResult = Object.freeze({
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* The dialog box does not return any value.
|
|
8
8
|
*/
|
|
9
|
-
None: "
|
|
9
|
+
None: "",
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* The return value of the dialog box is "OK".
|
|
@@ -31,17 +31,7 @@ export const DialogResult = Object.freeze({
|
|
|
31
31
|
/**
|
|
32
32
|
* The return value of the dialog box is "Ignore".
|
|
33
33
|
*/
|
|
34
|
-
Ignore: "Ignore"
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* The return value of the dialog box is "Yes".
|
|
38
|
-
*/
|
|
39
|
-
Yes: "Yes",
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* The return value of the dialog box is "No".
|
|
43
|
-
*/
|
|
44
|
-
No: "No"
|
|
34
|
+
Ignore: "Ignore"
|
|
45
35
|
});
|
|
46
36
|
|
|
47
37
|
/**
|
package/src/Client/UI/Tag.ts
CHANGED
|
@@ -33,8 +33,11 @@ export function html(fragments: TemplateStringsArray, ...values: unknown[]): Doc
|
|
|
33
33
|
* @returns The CSS string corresponding to the specified value.
|
|
34
34
|
*/
|
|
35
35
|
function stringFromCss(value: unknown): string {
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
if (!(value instanceof CSSStyleSheet)) {
|
|
37
|
+
if (Array.isArray(value)) return value.map(stringFromCss).join("\n");
|
|
38
|
+
return value === null || typeof value == "undefined" ? "" : String(value); // eslint-disable-line @typescript-eslint/no-base-to-string
|
|
39
|
+
}
|
|
40
|
+
|
|
38
41
|
return Array.from(value.cssRules).map(cssRule => cssRule.cssText).join("\n");
|
|
39
42
|
}
|
|
40
43
|
|
|
@@ -44,8 +47,11 @@ function stringFromCss(value: unknown): string {
|
|
|
44
47
|
* @returns The HTML string corresponding to the specified value.
|
|
45
48
|
*/
|
|
46
49
|
function stringFromHtml(value: unknown): string {
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
if (!(value instanceof DocumentFragment)) {
|
|
51
|
+
if (Array.isArray(value)) return value.map(stringFromHtml).join("");
|
|
52
|
+
return value === null || typeof value == "undefined" ? "" : String(value); // eslint-disable-line @typescript-eslint/no-base-to-string
|
|
53
|
+
}
|
|
54
|
+
|
|
49
55
|
const element = document.createElement("div");
|
|
50
56
|
element.appendChild(value);
|
|
51
57
|
return element.innerHTML;
|
package/src/Client/UI/Variant.ts
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
|
+
import {Context} from "./Context.js";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Defines tone variants.
|
|
3
5
|
*/
|
|
4
6
|
export const Variant = Object.freeze({
|
|
7
|
+
...Context,
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
|
-
* A
|
|
10
|
+
* A primary tone.
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
Primary: "Primary",
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
|
-
* A
|
|
15
|
+
* A secondary tone.
|
|
13
16
|
*/
|
|
14
|
-
|
|
17
|
+
Secondary: "Secondary",
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
|
-
* A
|
|
20
|
+
* A light tone.
|
|
18
21
|
*/
|
|
19
|
-
|
|
22
|
+
Light: "Light",
|
|
20
23
|
|
|
21
24
|
/**
|
|
22
|
-
* A
|
|
25
|
+
* A dark tone.
|
|
23
26
|
*/
|
|
24
|
-
|
|
27
|
+
Dark: "Dark"
|
|
25
28
|
});
|
|
26
29
|
|
|
27
30
|
/**
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { Context } from "../Context.js";
|
|
2
|
-
import { DialogResult } from "../DialogResult.js";
|
|
3
|
-
import { Variant } from "../Variant.js";
|
|
4
|
-
/**
|
|
5
|
-
* Represents a dialog box button.
|
|
6
|
-
*/
|
|
7
|
-
export interface IDialogButton {
|
|
8
|
-
/**
|
|
9
|
-
* A contextual modifier.
|
|
10
|
-
*/
|
|
11
|
-
context?: Context | null;
|
|
12
|
-
/**
|
|
13
|
-
* The button icon.
|
|
14
|
-
*/
|
|
15
|
-
icon?: string | null;
|
|
16
|
-
/**
|
|
17
|
-
* The button label.
|
|
18
|
-
*/
|
|
19
|
-
label?: string;
|
|
20
|
-
/**
|
|
21
|
-
* The button value.
|
|
22
|
-
*/
|
|
23
|
-
value?: DialogResult;
|
|
24
|
-
/**
|
|
25
|
-
* A tone variant.
|
|
26
|
-
*/
|
|
27
|
-
variant?: Variant | null;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Represents a dialog box button.
|
|
31
|
-
*/
|
|
32
|
-
export declare class DialogButton extends HTMLElement {
|
|
33
|
-
#private;
|
|
34
|
-
/**
|
|
35
|
-
* The list of observed attributes.
|
|
36
|
-
*/
|
|
37
|
-
static readonly observedAttributes: string[];
|
|
38
|
-
/**
|
|
39
|
-
* A contextual modifier.
|
|
40
|
-
*/
|
|
41
|
-
get context(): Context | null;
|
|
42
|
-
set context(value: Context | null);
|
|
43
|
-
/**
|
|
44
|
-
* The button icon.
|
|
45
|
-
*/
|
|
46
|
-
get icon(): string | null;
|
|
47
|
-
set icon(value: string | null);
|
|
48
|
-
/**
|
|
49
|
-
* The button label.
|
|
50
|
-
*/
|
|
51
|
-
get label(): string;
|
|
52
|
-
set label(value: string);
|
|
53
|
-
/**
|
|
54
|
-
* The button value.
|
|
55
|
-
*/
|
|
56
|
-
get value(): DialogResult;
|
|
57
|
-
set value(value: DialogResult);
|
|
58
|
-
/**
|
|
59
|
-
* A tone variant.
|
|
60
|
-
*/
|
|
61
|
-
get variant(): Variant | null;
|
|
62
|
-
set variant(value: Variant | null);
|
|
63
|
-
/**
|
|
64
|
-
* Method invoked when an attribute has been changed.
|
|
65
|
-
* @param attribute The attribute name.
|
|
66
|
-
* @param oldValue The previous attribute value.
|
|
67
|
-
* @param newValue The new attribute value.
|
|
68
|
-
*/
|
|
69
|
-
attributeChangedCallback(attribute: string, oldValue: string | null, newValue: string | null): void;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Declaration merging.
|
|
73
|
-
*/
|
|
74
|
-
declare global {
|
|
75
|
-
/**
|
|
76
|
-
* The map of HTML tag names.
|
|
77
|
-
*/
|
|
78
|
-
interface HTMLElementTagNameMap {
|
|
79
|
-
"dialog-button": DialogButton;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
//# sourceMappingURL=DialogButton.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DialogButton.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/DialogButton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAsB,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAC,OAAO,EAAsB,MAAM,eAAe,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,aAAa;IAE7B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,GAAC,IAAI,CAAC;IAEvB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAC,IAAI,CAAC;IAEnB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;IAErB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,GAAC,IAAI,CAAC;CACvB;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,WAAW;;IAE5C;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAAoD;IAStF;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,GAAC,IAAI,CAG1B;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,GAAC,IAAI,EAG9B;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,GAAC,IAAI,CAGtB;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,GAAC,IAAI,EAG1B;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAEtB;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,YAAY,CAGxB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,YAAY,EAE5B;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,GAAC,IAAI,CAG1B;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,GAAC,IAAI,EAG9B;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;CA6D/F;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,eAAe,EAAE,YAAY,CAAC;KAC9B;CACD"}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { Context, toCss as contextCss } from "../Context.js";
|
|
2
|
-
import { DialogResult } from "../DialogResult.js";
|
|
3
|
-
import { Variant, toCss as variantCss } from "../Variant.js";
|
|
4
|
-
/**
|
|
5
|
-
* Represents a dialog box button.
|
|
6
|
-
*/
|
|
7
|
-
export class DialogButton extends HTMLElement {
|
|
8
|
-
/**
|
|
9
|
-
* The list of observed attributes.
|
|
10
|
-
*/
|
|
11
|
-
static observedAttributes = ["context", "icon", "label", "value", "variant"];
|
|
12
|
-
/**
|
|
13
|
-
* Registers the component.
|
|
14
|
-
*/
|
|
15
|
-
static {
|
|
16
|
-
customElements.define("dialog-button", this);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* A contextual modifier.
|
|
20
|
-
*/
|
|
21
|
-
get context() {
|
|
22
|
-
const value = this.getAttribute("context");
|
|
23
|
-
return Object.values(Context).includes(value) ? value : null;
|
|
24
|
-
}
|
|
25
|
-
set context(value) {
|
|
26
|
-
if (value)
|
|
27
|
-
this.setAttribute("context", value);
|
|
28
|
-
else
|
|
29
|
-
this.removeAttribute("context");
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* The button icon.
|
|
33
|
-
*/
|
|
34
|
-
get icon() {
|
|
35
|
-
const value = this.getAttribute("icon") ?? "";
|
|
36
|
-
return value.trim() || null;
|
|
37
|
-
}
|
|
38
|
-
set icon(value) {
|
|
39
|
-
if (value)
|
|
40
|
-
this.setAttribute("icon", value);
|
|
41
|
-
else
|
|
42
|
-
this.removeAttribute("icon");
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* The button label.
|
|
46
|
-
*/
|
|
47
|
-
get label() {
|
|
48
|
-
return (this.getAttribute("label") ?? "").trim();
|
|
49
|
-
}
|
|
50
|
-
set label(value) {
|
|
51
|
-
this.setAttribute("label", value);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* The button value.
|
|
55
|
-
*/
|
|
56
|
-
get value() {
|
|
57
|
-
const value = this.getAttribute("value");
|
|
58
|
-
return Object.values(DialogResult).includes(value) ? value : DialogResult.None;
|
|
59
|
-
}
|
|
60
|
-
set value(value) {
|
|
61
|
-
this.setAttribute("value", value);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* A tone variant.
|
|
65
|
-
*/
|
|
66
|
-
get variant() {
|
|
67
|
-
const value = this.getAttribute("variant");
|
|
68
|
-
return Object.values(Variant).includes(value) ? value : null;
|
|
69
|
-
}
|
|
70
|
-
set variant(value) {
|
|
71
|
-
if (value)
|
|
72
|
-
this.setAttribute("variant", value);
|
|
73
|
-
else
|
|
74
|
-
this.removeAttribute("variant");
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Method invoked when an attribute has been changed.
|
|
78
|
-
* @param attribute The attribute name.
|
|
79
|
-
* @param oldValue The previous attribute value.
|
|
80
|
-
* @param newValue The new attribute value.
|
|
81
|
-
*/
|
|
82
|
-
attributeChangedCallback(attribute, oldValue, newValue) {
|
|
83
|
-
if (newValue != oldValue)
|
|
84
|
-
switch (attribute) {
|
|
85
|
-
case "context":
|
|
86
|
-
this.#updateContext(Object.values(Context).includes(newValue) ? newValue : null);
|
|
87
|
-
break;
|
|
88
|
-
case "icon":
|
|
89
|
-
this.#updateIcon(newValue);
|
|
90
|
-
break;
|
|
91
|
-
case "label":
|
|
92
|
-
this.#updateLabel(newValue ?? "");
|
|
93
|
-
break;
|
|
94
|
-
case "value":
|
|
95
|
-
this.#updateValue(Object.values(DialogResult).includes(newValue) ? newValue : DialogResult.None);
|
|
96
|
-
break;
|
|
97
|
-
case "variant":
|
|
98
|
-
this.#updateVariant(Object.values(Variant).includes(newValue) ? newValue : null);
|
|
99
|
-
break;
|
|
100
|
-
// No default
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Updates the contextual modifier.
|
|
105
|
-
* @param value The new value.
|
|
106
|
-
*/
|
|
107
|
-
#updateContext(value) {
|
|
108
|
-
const { classList } = this.querySelector("button");
|
|
109
|
-
classList.remove(...Object.values(Context).map(context => `btn-${contextCss(context)}`));
|
|
110
|
-
if (value)
|
|
111
|
-
classList.add(`btn-${contextCss(value)}`);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Updates the button icon.
|
|
115
|
-
* @param value The new value.
|
|
116
|
-
*/
|
|
117
|
-
#updateIcon(value) {
|
|
118
|
-
const element = this.querySelector(".icon");
|
|
119
|
-
const icon = (value ?? "").trim();
|
|
120
|
-
element.textContent = icon;
|
|
121
|
-
element.hidden = !icon;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Updates the button label.
|
|
125
|
-
* @param value The new value.
|
|
126
|
-
*/
|
|
127
|
-
#updateLabel(value) {
|
|
128
|
-
const element = this.querySelector("span");
|
|
129
|
-
const label = value.trim();
|
|
130
|
-
element.textContent = label;
|
|
131
|
-
element.hidden = !label;
|
|
132
|
-
this.querySelector(".icon").classList.toggle("me-1", !element.hidden);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Updates the button value.
|
|
136
|
-
* @param value The new value.
|
|
137
|
-
*/
|
|
138
|
-
#updateValue(value) {
|
|
139
|
-
this.querySelector("button").value = value;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Updates the tone variant.
|
|
143
|
-
* @param value The new value.
|
|
144
|
-
*/
|
|
145
|
-
#updateVariant(value) {
|
|
146
|
-
const { classList } = this.querySelector("button");
|
|
147
|
-
classList.remove(...Object.values(Variant).map(variant => `btn-${variantCss(variant)}`));
|
|
148
|
-
if (value)
|
|
149
|
-
classList.add(`btn-${variantCss(value)}`);
|
|
150
|
-
}
|
|
151
|
-
}
|