@cedx/base 0.21.0 → 0.22.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/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/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 +3 -3
- 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/DialogBox.ts +79 -97
- package/src/Client/UI/Components/ThemeDropdown.ts +3 -3
- package/src/Client/UI/Components/Toast.ts +3 -49
- 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
package/lib/UI/Variant.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
+
import { Context } from "./Context.js";
|
|
1
2
|
/**
|
|
2
3
|
* Defines tone variants.
|
|
3
4
|
*/
|
|
4
5
|
export const Variant = Object.freeze({
|
|
6
|
+
...Context,
|
|
5
7
|
/**
|
|
6
|
-
* A
|
|
8
|
+
* A primary tone.
|
|
7
9
|
*/
|
|
8
|
-
|
|
10
|
+
Primary: "Primary",
|
|
9
11
|
/**
|
|
10
|
-
* A
|
|
12
|
+
* A secondary tone.
|
|
11
13
|
*/
|
|
12
|
-
|
|
14
|
+
Secondary: "Secondary",
|
|
13
15
|
/**
|
|
14
|
-
* A
|
|
16
|
+
* A light tone.
|
|
15
17
|
*/
|
|
16
|
-
|
|
18
|
+
Light: "Light",
|
|
17
19
|
/**
|
|
18
|
-
* A
|
|
20
|
+
* A dark tone.
|
|
19
21
|
*/
|
|
20
|
-
|
|
22
|
+
Dark: "Dark"
|
|
21
23
|
});
|
|
22
24
|
/**
|
|
23
25
|
* Returns the CSS representation of the specified variant.
|
package/package.json
CHANGED
|
@@ -1,14 +1,39 @@
|
|
|
1
1
|
import {Modal} from "bootstrap";
|
|
2
|
-
import {type Context,
|
|
2
|
+
import {type Context, toCss as contextCss, getIcon} from "../Context.js";
|
|
3
3
|
import {DialogResult} from "../DialogResult.js";
|
|
4
4
|
import {html} from "../Tag.js";
|
|
5
|
-
import {Variant} from "../Variant.js";
|
|
6
|
-
|
|
5
|
+
import {Variant, toCss as variantCss} from "../Variant.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Represents a dialog box button.
|
|
9
|
+
*/
|
|
10
|
+
export interface IDialogButton {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The button icon.
|
|
14
|
+
*/
|
|
15
|
+
icon?: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The button label.
|
|
19
|
+
*/
|
|
20
|
+
label?: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The button value.
|
|
24
|
+
*/
|
|
25
|
+
value?: string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A tone variant.
|
|
29
|
+
*/
|
|
30
|
+
variant?: Context|Variant;
|
|
31
|
+
}
|
|
7
32
|
|
|
8
33
|
/**
|
|
9
34
|
* Represents a message to display in a dialog box.
|
|
10
35
|
*/
|
|
11
|
-
export interface
|
|
36
|
+
export interface IDialogMessage {
|
|
12
37
|
|
|
13
38
|
/**
|
|
14
39
|
* The child content displayed in the body.
|
|
@@ -36,25 +61,20 @@ export class DialogBox extends HTMLElement {
|
|
|
36
61
|
*/
|
|
37
62
|
static readonly observedAttributes = ["caption", "centered", "fade", "modal", "scrollable"];
|
|
38
63
|
|
|
39
|
-
/**
|
|
40
|
-
* The template for a button.
|
|
41
|
-
*/
|
|
42
|
-
readonly #buttonTemplate: DocumentFragment = this.querySelector("template")!.content;
|
|
43
|
-
|
|
44
64
|
/**
|
|
45
65
|
* The underlying Bootstrap modal.
|
|
46
66
|
*/
|
|
47
67
|
#modal!: Modal;
|
|
48
68
|
|
|
49
69
|
/**
|
|
50
|
-
* The function invoked to
|
|
70
|
+
* The function invoked to resolve the dialog result.
|
|
51
71
|
*/
|
|
52
|
-
#resolve
|
|
72
|
+
#resolve!: (value: string) => void;
|
|
53
73
|
|
|
54
74
|
/**
|
|
55
|
-
* The dialog result.
|
|
75
|
+
* The promise providing the dialog result.
|
|
56
76
|
*/
|
|
57
|
-
#result:
|
|
77
|
+
#result: string = DialogResult.None;
|
|
58
78
|
|
|
59
79
|
/**
|
|
60
80
|
* Creates a new dialog box.
|
|
@@ -62,8 +82,8 @@ export class DialogBox extends HTMLElement {
|
|
|
62
82
|
constructor() {
|
|
63
83
|
super();
|
|
64
84
|
this.firstElementChild!.addEventListener("hidden.bs.modal", () => this.#resolve(this.#result));
|
|
65
|
-
this.querySelector(".btn-close")!.addEventListener("click", this.#close);
|
|
66
|
-
for (const button of this.querySelectorAll(".modal-footer button")) button.addEventListener("click", this.#close);
|
|
85
|
+
this.querySelector(".btn-close")!.addEventListener("click", event => this.#close(event));
|
|
86
|
+
for (const button of this.querySelectorAll(".modal-footer button")) button.addEventListener("click", event => this.#close(event));
|
|
67
87
|
}
|
|
68
88
|
|
|
69
89
|
/**
|
|
@@ -77,7 +97,7 @@ export class DialogBox extends HTMLElement {
|
|
|
77
97
|
* The child content displayed in the body.
|
|
78
98
|
*/
|
|
79
99
|
set body(value: DocumentFragment) { // eslint-disable-line accessor-pairs
|
|
80
|
-
this.querySelector(".modal-body
|
|
100
|
+
this.querySelector(".modal-body")!.replaceChildren(...value.childNodes);
|
|
81
101
|
}
|
|
82
102
|
|
|
83
103
|
/**
|
|
@@ -139,6 +159,13 @@ export class DialogBox extends HTMLElement {
|
|
|
139
159
|
this.toggleAttribute("open", value);
|
|
140
160
|
}
|
|
141
161
|
|
|
162
|
+
/**
|
|
163
|
+
* The dialog result.
|
|
164
|
+
*/
|
|
165
|
+
get result(): string {
|
|
166
|
+
return this.#result;
|
|
167
|
+
}
|
|
168
|
+
|
|
142
169
|
/**
|
|
143
170
|
* Value indicating whether the body is scrollable.
|
|
144
171
|
*/
|
|
@@ -167,23 +194,38 @@ export class DialogBox extends HTMLElement {
|
|
|
167
194
|
}
|
|
168
195
|
|
|
169
196
|
/**
|
|
170
|
-
* Shows an alert message with an "OK" button.
|
|
197
|
+
* Shows an alert message with an "OK" button by default.
|
|
171
198
|
* @param context The contextual modifier.
|
|
172
199
|
* @param caption The title displayed in the header.
|
|
173
|
-
* @param
|
|
174
|
-
* @
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
200
|
+
* @param message The child content displayed in the body.
|
|
201
|
+
* @param buttons The buttons displayed in the footer.
|
|
202
|
+
* @returns The dialog result.
|
|
203
|
+
*/
|
|
204
|
+
alert(context: Context, caption: string, message: DocumentFragment, buttons: IDialogButton[] = []): Promise<string> {
|
|
205
|
+
return this.show({
|
|
206
|
+
caption,
|
|
207
|
+
body: html`
|
|
208
|
+
<div class="d-flex gap-2">
|
|
209
|
+
<i class="icon icon-fill fs-1 text-${contextCss(context)}"> ${getIcon(context)}</i>
|
|
210
|
+
<div class="flex-grow-1">${message}</div>
|
|
211
|
+
</div>
|
|
212
|
+
`,
|
|
213
|
+
footer: html`
|
|
214
|
+
${(buttons.length ? buttons : [{label: "OK", value: DialogResult.OK, variant: Variant.Primary}]).map(button => html`
|
|
215
|
+
<button class="btn btn-${variantCss(button.variant ?? Variant.Primary)}" type="button" value="${button.value ?? DialogResult.None}">
|
|
216
|
+
${button.icon ? html`<i class="icon ${button.label ? "me-1" : ""}">${button.icon}</i>` : ""}
|
|
217
|
+
${button.label}
|
|
218
|
+
</button>
|
|
219
|
+
`)}
|
|
220
|
+
`
|
|
221
|
+
});
|
|
180
222
|
}
|
|
181
223
|
|
|
182
224
|
/**
|
|
183
225
|
* Closes this dialog box.
|
|
184
|
-
* @param result The dialog
|
|
226
|
+
* @param result The dialog result.
|
|
185
227
|
*/
|
|
186
|
-
close(result:
|
|
228
|
+
close(result: string = DialogResult.None): void {
|
|
187
229
|
this.#result = result;
|
|
188
230
|
this.#modal.hide();
|
|
189
231
|
}
|
|
@@ -192,11 +234,11 @@ export class DialogBox extends HTMLElement {
|
|
|
192
234
|
* Shows a confirmation message with two buttons, "OK" and "Cancel".
|
|
193
235
|
* @param context The contextual modifier.
|
|
194
236
|
* @param caption The title displayed in the header.
|
|
195
|
-
* @param
|
|
196
|
-
* @returns The dialog
|
|
237
|
+
* @param message The child content displayed in the body.
|
|
238
|
+
* @returns The dialog result.
|
|
197
239
|
*/
|
|
198
|
-
confirm(context: Context, caption: string,
|
|
199
|
-
return this.
|
|
240
|
+
confirm(context: Context, caption: string, message: DocumentFragment): Promise<string> {
|
|
241
|
+
return this.alert(context, caption, message, [
|
|
200
242
|
{label: "OK", value: DialogResult.OK, variant: Variant.Primary},
|
|
201
243
|
{label: "Annuler", value: DialogResult.Cancel, variant: Variant.Secondary}
|
|
202
244
|
]);
|
|
@@ -220,44 +262,18 @@ export class DialogBox extends HTMLElement {
|
|
|
220
262
|
/**
|
|
221
263
|
* Shows a message.
|
|
222
264
|
* @param message The message to show.
|
|
223
|
-
* @returns The dialog
|
|
224
|
-
*/
|
|
225
|
-
show(message?: IMessage): Promise<DialogResult>;
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Shows a message.
|
|
229
|
-
* @param context The contextual modifier.
|
|
230
|
-
* @param caption The title displayed in the header.
|
|
231
|
-
* @param body The child content displayed in the body.
|
|
232
|
-
* @param buttons The buttons displayed in the footer.
|
|
233
|
-
* @returns The dialog box result.
|
|
265
|
+
* @returns The dialog result.
|
|
234
266
|
*/
|
|
235
|
-
show(
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Shows a message.
|
|
239
|
-
* @param message The message to show, or the contextual modifier.
|
|
240
|
-
* @param caption The title displayed in the header.
|
|
241
|
-
* @param body The child content displayed in the body.
|
|
242
|
-
* @param buttons The buttons displayed in the footer.
|
|
243
|
-
* @returns The dialog box result.
|
|
244
|
-
*/
|
|
245
|
-
show(message: IMessage|Context|null = null, caption = "", body = document.createDocumentFragment(), buttons: IDialogButton[] = []): Promise<DialogResult> {
|
|
246
|
-
if (typeof message == "string") {
|
|
247
|
-
const footer = document.createDocumentFragment();
|
|
248
|
-
footer.append(...buttons.map(button => this.#createButton(button)));
|
|
249
|
-
message = {body, caption, footer};
|
|
250
|
-
}
|
|
251
|
-
|
|
267
|
+
show(message: IDialogMessage|null = null): Promise<string> {
|
|
252
268
|
if (message) {
|
|
253
269
|
const footer = message.footer ?? document.createDocumentFragment();
|
|
254
|
-
for (const button of footer.querySelectorAll("button")) button.addEventListener("click", this.#close);
|
|
270
|
+
for (const button of footer.querySelectorAll("button")) button.addEventListener("click", event => this.#close(event));
|
|
255
271
|
this.body = message.body;
|
|
256
272
|
this.caption = message.caption;
|
|
257
273
|
this.footer = footer;
|
|
258
274
|
}
|
|
259
275
|
|
|
260
|
-
const {promise, resolve} = Promise.withResolvers<
|
|
276
|
+
const {promise, resolve} = Promise.withResolvers<string>();
|
|
261
277
|
this.#resolve = resolve;
|
|
262
278
|
this.#result = DialogResult.None;
|
|
263
279
|
this.#modal.show();
|
|
@@ -268,43 +284,9 @@ export class DialogBox extends HTMLElement {
|
|
|
268
284
|
* Closes this dialog box.
|
|
269
285
|
* @param event The dispatched event.
|
|
270
286
|
*/
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
this.close(
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Creates the component instance corresponding to the specified button.
|
|
278
|
-
* @param button An object describing the appearance of the button.
|
|
279
|
-
* @returns The component instance corresponding to the specified button.
|
|
280
|
-
*/
|
|
281
|
-
#createButton(button: IDialogButton): DialogButton {
|
|
282
|
-
const element = document.createElement("dialog-button");
|
|
283
|
-
const childContent = (this.#buttonTemplate.cloneNode(true) as DocumentFragment).querySelector("button")!;
|
|
284
|
-
childContent.addEventListener("click", this.#close);
|
|
285
|
-
element.appendChild(childContent);
|
|
286
|
-
|
|
287
|
-
element.context = button.context ?? null;
|
|
288
|
-
element.icon = button.icon ?? null;
|
|
289
|
-
element.label = button.label ?? "";
|
|
290
|
-
element.value = button.value ?? DialogResult.None;
|
|
291
|
-
element.variant = button.variant ?? null;
|
|
292
|
-
return element;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Gets the body template corresponding to the specified context and message.
|
|
297
|
-
* @param context The contextual modifier.
|
|
298
|
-
* @param message The child content displayed in the body.
|
|
299
|
-
* @returns The body template corresponding to the specified context and message.
|
|
300
|
-
*/
|
|
301
|
-
#getBodyTemplate(context: Context, message: DocumentFragment): DocumentFragment {
|
|
302
|
-
return html`
|
|
303
|
-
<div class="d-flex gap-2">
|
|
304
|
-
<i class="icon icon-fill fs-1 text-${toCss(context)}"> ${getIcon(context)}</i>
|
|
305
|
-
<div class="flex-grow-1">${message}</div>
|
|
306
|
-
</div>
|
|
307
|
-
`;
|
|
287
|
+
#close(event: Event): void {
|
|
288
|
+
event.preventDefault();
|
|
289
|
+
this.close((event.target as Element).closest("button")!.value);
|
|
308
290
|
}
|
|
309
291
|
|
|
310
292
|
/**
|
|
@@ -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", event => this.#setAppTheme(event));
|
|
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
|
*/
|
|
@@ -220,7 +174,7 @@ export class Toast extends HTMLElement {
|
|
|
220
174
|
connectedCallback(): void {
|
|
221
175
|
const toast = this.firstElementChild!;
|
|
222
176
|
toast.addEventListener("hidden.bs.toast", () => clearInterval(this.#timer));
|
|
223
|
-
toast.addEventListener("show.bs.toast", () => this.#timer = window.setInterval(this.#updateElapsedTime, 1_000));
|
|
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"}
|