@cedx/base 0.19.0 → 0.21.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/{DateExtensions.d.ts → Date.d.ts} +9 -9
- package/lib/Date.d.ts.map +1 -0
- package/lib/{DateExtensions.js → Date.js} +12 -10
- package/lib/{FileExtensions.d.ts → File.d.ts} +1 -1
- package/lib/File.d.ts.map +1 -0
- package/lib/{NumberExtensions.d.ts → Number.d.ts} +1 -1
- package/lib/Number.d.ts.map +1 -0
- package/lib/{StringExtensions.d.ts → String.d.ts} +1 -19
- package/lib/String.d.ts.map +1 -0
- package/lib/{StringExtensions.js → String.js} +0 -40
- package/lib/UI/Components/{MessageBox.d.ts → DialogBox.d.ts} +18 -48
- package/lib/UI/Components/DialogBox.d.ts.map +1 -0
- package/lib/UI/Components/{MessageBox.js → DialogBox.js} +49 -79
- package/lib/UI/Components/LoadingIndicator.d.ts +27 -2
- package/lib/UI/Components/LoadingIndicator.d.ts.map +1 -1
- package/lib/UI/Components/LoadingIndicator.js +55 -2
- package/lib/UI/Components/OfflineIndicator.d.ts +29 -0
- package/lib/UI/Components/OfflineIndicator.d.ts.map +1 -1
- package/lib/UI/Components/OfflineIndicator.js +70 -7
- package/lib/UI/Components/Toast.d.ts +11 -11
- package/lib/UI/Components/Toast.d.ts.map +1 -1
- package/lib/UI/Components/Toast.js +21 -21
- package/lib/UI/Components/Toaster.d.ts +6 -6
- package/lib/UI/Components/Toaster.d.ts.map +1 -1
- package/lib/UI/Components/Toaster.js +12 -13
- package/lib/UI/{FormExtensions.d.ts → Form.d.ts} +1 -1
- package/lib/UI/Form.d.ts.map +1 -0
- package/lib/UI/Tag.d.ts +15 -0
- package/lib/UI/Tag.d.ts.map +1 -0
- package/lib/UI/Tag.js +44 -0
- package/package.json +1 -1
- package/src/Client/{DateExtensions.ts → Date.ts} +13 -10
- package/src/Client/{StringExtensions.ts → String.ts} +0 -40
- package/src/Client/UI/Components/{MessageBox.ts → DialogBox.ts} +51 -106
- package/src/Client/UI/Components/LoadingIndicator.ts +57 -2
- package/src/Client/UI/Components/OfflineIndicator.ts +70 -7
- package/src/Client/UI/Components/Toast.ts +27 -27
- package/src/Client/UI/Components/Toaster.ts +14 -15
- package/src/Client/UI/Tag.ts +52 -0
- package/src/Client/tsconfig.json +0 -2
- package/lib/DateExtensions.d.ts.map +0 -1
- package/lib/FileExtensions.d.ts.map +0 -1
- package/lib/Hosting/Environment.d.ts +0 -22
- package/lib/Hosting/Environment.d.ts.map +0 -1
- package/lib/Hosting/Environment.js +0 -17
- package/lib/Hosting/HostEnvironment.d.ts +0 -61
- package/lib/Hosting/HostEnvironment.d.ts.map +0 -1
- package/lib/Hosting/HostEnvironment.js +0 -56
- package/lib/Net/Http/HttpMethod.d.ts +0 -46
- package/lib/Net/Http/HttpMethod.d.ts.map +0 -1
- package/lib/Net/Http/HttpMethod.js +0 -41
- package/lib/Net/Http/StatusCode.d.ts +0 -122
- package/lib/Net/Http/StatusCode.d.ts.map +0 -1
- package/lib/Net/Http/StatusCode.js +0 -117
- package/lib/Net/Mime/DispositionType.d.ts +0 -18
- package/lib/Net/Mime/DispositionType.d.ts.map +0 -1
- package/lib/Net/Mime/DispositionType.js +0 -13
- package/lib/Net/Mime/MediaType.d.ts +0 -151
- package/lib/Net/Mime/MediaType.d.ts.map +0 -1
- package/lib/Net/Mime/MediaType.js +0 -150
- package/lib/NumberExtensions.d.ts.map +0 -1
- package/lib/StringExtensions.d.ts.map +0 -1
- package/lib/UI/Components/MessageBox.d.ts.map +0 -1
- package/lib/UI/ElementExtensions.d.ts +0 -13
- package/lib/UI/ElementExtensions.d.ts.map +0 -1
- package/lib/UI/ElementExtensions.js +0 -18
- package/lib/UI/FormExtensions.d.ts.map +0 -1
- package/src/Client/Hosting/Environment.ts +0 -25
- package/src/Client/Hosting/HostEnvironment.ts +0 -86
- package/src/Client/Hosting/tsconfig.json +0 -13
- package/src/Client/Net/Http/HttpMethod.ts +0 -55
- package/src/Client/Net/Http/StatusCode.ts +0 -150
- package/src/Client/Net/Mime/DispositionType.ts +0 -20
- package/src/Client/Net/Mime/MediaType.ts +0 -185
- package/src/Client/Net/tsconfig.json +0 -13
- package/src/Client/UI/ElementExtensions.ts +0 -19
- /package/lib/{FileExtensions.js → File.js} +0 -0
- /package/lib/{NumberExtensions.js → Number.js} +0 -0
- /package/lib/UI/{FormExtensions.js → Form.js} +0 -0
- /package/src/Client/{FileExtensions.ts → File.ts} +0 -0
- /package/src/Client/{NumberExtensions.ts → Number.ts} +0 -0
- /package/src/Client/UI/{FormExtensions.ts → Form.ts} +0 -0
|
@@ -19,11 +19,13 @@ export function daysInMonth(date: Date): number {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* Gets the date of Easter for
|
|
23
|
-
* @param
|
|
24
|
-
* @returns The date of Easter for the specified
|
|
22
|
+
* Gets the date of Easter for the year corresponding to the specified date.
|
|
23
|
+
* @param date The date.
|
|
24
|
+
* @returns The date of Easter for the year corresponding to the specified date.
|
|
25
25
|
*/
|
|
26
|
-
export function getEaster(
|
|
26
|
+
export function getEaster(date: Date): Date {
|
|
27
|
+
const year = date.getFullYear();
|
|
28
|
+
|
|
27
29
|
/* eslint-disable id-length */
|
|
28
30
|
const n = year % 19;
|
|
29
31
|
const c = Math.trunc(year / 100);
|
|
@@ -38,12 +40,13 @@ export function getEaster(year = new Date().getFullYear()): Date {
|
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
/**
|
|
41
|
-
* Gets the list of holidays for
|
|
42
|
-
* @param
|
|
43
|
-
* @returns The list of holidays for the specified
|
|
43
|
+
* Gets the list of holidays for the year corresponding to the specified date.
|
|
44
|
+
* @param date The date.
|
|
45
|
+
* @returns The list of holidays for the year corresponding to the specified date.
|
|
44
46
|
*/
|
|
45
|
-
export function getHolidays(
|
|
47
|
+
export function getHolidays(date: Date): Date[] {
|
|
46
48
|
const holidays = [];
|
|
49
|
+
const year = date.getFullYear();
|
|
47
50
|
|
|
48
51
|
// Fixed holidays.
|
|
49
52
|
holidays.push(new Date(year, 0, 1)); // New year.
|
|
@@ -56,7 +59,7 @@ export function getHolidays(year = new Date().getFullYear()): Date[] {
|
|
|
56
59
|
holidays.push(new Date(year, 11, 25)); // Christmas.
|
|
57
60
|
|
|
58
61
|
// Holidays depending on Easter.
|
|
59
|
-
const easter = getEaster(
|
|
62
|
+
const easter = getEaster(date);
|
|
60
63
|
holidays.push(new Date(easter.getTime() + Duration.Day)); // Easter monday.
|
|
61
64
|
holidays.push(new Date(easter.getTime() + (39 * Duration.Day))); // Ascension thursday.
|
|
62
65
|
holidays.push(new Date(easter.getTime() + (50 * Duration.Day))); // Pentecost monday.
|
|
@@ -101,7 +104,7 @@ export function inLeapYear(date: Date): boolean {
|
|
|
101
104
|
*/
|
|
102
105
|
export function isHoliday(date: Date): boolean {
|
|
103
106
|
const timestamp = atMidnight(date).getTime();
|
|
104
|
-
return getHolidays(date
|
|
107
|
+
return getHolidays(date).some(holiday => holiday.getTime() == timestamp);
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
/**
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The mapping between special characters and the corresponding XML entities.
|
|
3
|
-
*/
|
|
4
|
-
const xmlEntities = new Map([
|
|
5
|
-
["&", "&"],
|
|
6
|
-
["<", "<"],
|
|
7
|
-
[">", ">"],
|
|
8
|
-
['"', """],
|
|
9
|
-
["'", "'"]
|
|
10
|
-
]);
|
|
11
|
-
|
|
12
1
|
/**
|
|
13
2
|
* Converts the first character to uppercase.
|
|
14
3
|
* @param value The string to process.
|
|
@@ -56,26 +45,6 @@ export function stripTags(value: string): string {
|
|
|
56
45
|
return value.replace(/<[^>]+>/g, "");
|
|
57
46
|
}
|
|
58
47
|
|
|
59
|
-
/**
|
|
60
|
-
* Removes whitespace from both ends of the items of the specified array.
|
|
61
|
-
* @param array The array to process.
|
|
62
|
-
* @returns The input array.
|
|
63
|
-
*/
|
|
64
|
-
export function trimArray<T>(array: T[]): T[] {
|
|
65
|
-
for (const [index, value] of array.entries()) if (typeof value == "string") Reflect.set(array, index, value.trim());
|
|
66
|
-
return array;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Removes whitespace from both ends of the properties of the specified object.
|
|
71
|
-
* @param object The object to process.
|
|
72
|
-
* @returns The input object.
|
|
73
|
-
*/
|
|
74
|
-
export function trimObject<T>(object: Record<string, T>): Record<string, T> {
|
|
75
|
-
for (const [key, value] of Object.entries(object)) if (typeof value == "string") Reflect.set(object, key, value.trim());
|
|
76
|
-
return object;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
48
|
/**
|
|
80
49
|
* Truncates the specified string to the given number of characters.
|
|
81
50
|
* @param value The string to be truncated.
|
|
@@ -86,12 +55,3 @@ export function trimObject<T>(object: Record<string, T>): Record<string, T> {
|
|
|
86
55
|
export function truncate(value: string, length: number, ellipsis = "..."): string {
|
|
87
56
|
return value.length > length ? value.slice(0, length) + ellipsis : value;
|
|
88
57
|
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Replaces invalid XML characters in a string with their valid XML equivalent.
|
|
92
|
-
* @param value The string to process.
|
|
93
|
-
* @returns The processed string.
|
|
94
|
-
*/
|
|
95
|
-
export function xmlEscape(value: string): string {
|
|
96
|
-
return value.replace(/[&<>"']/g, character => xmlEntities.get(character) ?? character);
|
|
97
|
-
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Modal} from "bootstrap";
|
|
2
|
-
import {Context, getIcon, toCss} from "../Context.js";
|
|
2
|
+
import {type Context, getIcon, toCss} from "../Context.js";
|
|
3
3
|
import {DialogResult} from "../DialogResult.js";
|
|
4
|
-
import {
|
|
4
|
+
import {html} from "../Tag.js";
|
|
5
5
|
import {Variant} from "../Variant.js";
|
|
6
6
|
import type {DialogButton, IDialogButton} from "./DialogButton.js";
|
|
7
7
|
|
|
@@ -10,56 +10,31 @@ import type {DialogButton, IDialogButton} from "./DialogButton.js";
|
|
|
10
10
|
*/
|
|
11
11
|
export interface IMessage {
|
|
12
12
|
|
|
13
|
-
/**
|
|
14
|
-
* Value indicating whether to apply a fade transition.
|
|
15
|
-
*/
|
|
16
|
-
animation?: boolean;
|
|
17
|
-
|
|
18
13
|
/**
|
|
19
14
|
* The child content displayed in the body.
|
|
20
15
|
*/
|
|
21
|
-
body: DocumentFragment
|
|
16
|
+
body: DocumentFragment;
|
|
22
17
|
|
|
23
18
|
/**
|
|
24
19
|
* The title displayed in the header.
|
|
25
20
|
*/
|
|
26
21
|
caption: string;
|
|
27
22
|
|
|
28
|
-
/**
|
|
29
|
-
* Value indicating whether to vertically center this message box.
|
|
30
|
-
*/
|
|
31
|
-
centered?: boolean;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* A contextual modifier.
|
|
35
|
-
*/
|
|
36
|
-
context?: Context;
|
|
37
|
-
|
|
38
23
|
/**
|
|
39
24
|
* The child content displayed in the footer.
|
|
40
25
|
*/
|
|
41
|
-
footer?: DocumentFragment
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The icon displayed next to the body.
|
|
45
|
-
*/
|
|
46
|
-
icon?: string|null;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Value indicating whether the body is scrollable.
|
|
50
|
-
*/
|
|
51
|
-
scrollable?: boolean;
|
|
26
|
+
footer?: DocumentFragment;
|
|
52
27
|
}
|
|
53
28
|
|
|
54
29
|
/**
|
|
55
|
-
* Displays a
|
|
30
|
+
* Displays a dialog box, which presents a message to the user.
|
|
56
31
|
*/
|
|
57
|
-
export class
|
|
32
|
+
export class DialogBox extends HTMLElement {
|
|
58
33
|
|
|
59
34
|
/**
|
|
60
35
|
* The list of observed attributes.
|
|
61
36
|
*/
|
|
62
|
-
static readonly observedAttributes = ["
|
|
37
|
+
static readonly observedAttributes = ["caption", "centered", "fade", "modal", "scrollable"];
|
|
63
38
|
|
|
64
39
|
/**
|
|
65
40
|
* The template for a button.
|
|
@@ -82,7 +57,7 @@ export class MessageBox extends HTMLElement {
|
|
|
82
57
|
#result: DialogResult = DialogResult.None;
|
|
83
58
|
|
|
84
59
|
/**
|
|
85
|
-
* Creates a new
|
|
60
|
+
* Creates a new dialog box.
|
|
86
61
|
*/
|
|
87
62
|
constructor() {
|
|
88
63
|
super();
|
|
@@ -95,17 +70,7 @@ export class MessageBox extends HTMLElement {
|
|
|
95
70
|
* Registers the component.
|
|
96
71
|
*/
|
|
97
72
|
static {
|
|
98
|
-
customElements.define("
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Value indicating whether to apply a fade transition.
|
|
103
|
-
*/
|
|
104
|
-
get animation(): boolean {
|
|
105
|
-
return this.hasAttribute("animation");
|
|
106
|
-
}
|
|
107
|
-
set animation(value: boolean) {
|
|
108
|
-
this.toggleAttribute("animation", value);
|
|
73
|
+
customElements.define("dialog-box", this);
|
|
109
74
|
}
|
|
110
75
|
|
|
111
76
|
/**
|
|
@@ -126,7 +91,7 @@ export class MessageBox extends HTMLElement {
|
|
|
126
91
|
}
|
|
127
92
|
|
|
128
93
|
/**
|
|
129
|
-
* Value indicating whether to vertically center this
|
|
94
|
+
* Value indicating whether to vertically center this dialog box.
|
|
130
95
|
*/
|
|
131
96
|
get centered(): boolean {
|
|
132
97
|
return this.hasAttribute("centered");
|
|
@@ -136,14 +101,13 @@ export class MessageBox extends HTMLElement {
|
|
|
136
101
|
}
|
|
137
102
|
|
|
138
103
|
/**
|
|
139
|
-
*
|
|
104
|
+
* Value indicating whether to apply a transition.
|
|
140
105
|
*/
|
|
141
|
-
get
|
|
142
|
-
|
|
143
|
-
return Object.values(Context).includes(value) ? value : Context.Info;
|
|
106
|
+
get fade(): boolean {
|
|
107
|
+
return this.hasAttribute("fade");
|
|
144
108
|
}
|
|
145
|
-
set
|
|
146
|
-
this.
|
|
109
|
+
set fade(value: boolean) {
|
|
110
|
+
this.toggleAttribute("fade", value);
|
|
147
111
|
}
|
|
148
112
|
|
|
149
113
|
/**
|
|
@@ -156,18 +120,7 @@ export class MessageBox extends HTMLElement {
|
|
|
156
120
|
}
|
|
157
121
|
|
|
158
122
|
/**
|
|
159
|
-
*
|
|
160
|
-
*/
|
|
161
|
-
get icon(): string|null {
|
|
162
|
-
const value = this.getAttribute("icon") ?? "";
|
|
163
|
-
return value.trim() || null;
|
|
164
|
-
}
|
|
165
|
-
set icon(value: string|null) {
|
|
166
|
-
this.toggleAttribute("icon", Boolean(value));
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Value indicating whether to this message box will not close when clicking outside of it.
|
|
123
|
+
* Value indicating whether to this dialog box will not close when clicking outside of it.
|
|
171
124
|
*/
|
|
172
125
|
get modal(): boolean {
|
|
173
126
|
return this.hasAttribute("modal");
|
|
@@ -177,7 +130,7 @@ export class MessageBox extends HTMLElement {
|
|
|
177
130
|
}
|
|
178
131
|
|
|
179
132
|
/**
|
|
180
|
-
* Value indicating whether to initially show this
|
|
133
|
+
* Value indicating whether to initially show this component.
|
|
181
134
|
*/
|
|
182
135
|
get open(): boolean {
|
|
183
136
|
return this.hasAttribute("open");
|
|
@@ -204,13 +157,11 @@ export class MessageBox extends HTMLElement {
|
|
|
204
157
|
*/
|
|
205
158
|
attributeChangedCallback(attribute: string, oldValue: string|null, newValue: string|null): void {
|
|
206
159
|
if (newValue != oldValue) switch (attribute) {
|
|
207
|
-
case "animation": this.#updateAnimation(newValue != null); break;
|
|
208
160
|
case "caption": this.#updateCaption(newValue ?? ""); break;
|
|
209
161
|
case "centered": this.#updateCentered(newValue != null); break;
|
|
210
|
-
case "context": this.#updateContext(Object.values(Context).includes(newValue as Context) ? newValue as Context : Context.Info); break;
|
|
211
|
-
case "icon": this.#updateIcon(newValue); break;
|
|
212
162
|
case "modal": this.#updateModal(newValue != null); break;
|
|
213
|
-
case "
|
|
163
|
+
case "fade": this.#updateFade(newValue != null); break;
|
|
164
|
+
case "scrollable": this.#updateScrollable(newValue != null); break;
|
|
214
165
|
// No default
|
|
215
166
|
}
|
|
216
167
|
}
|
|
@@ -222,14 +173,14 @@ export class MessageBox extends HTMLElement {
|
|
|
222
173
|
* @param body The child content displayed in the body.
|
|
223
174
|
* @returns The dialog box result.
|
|
224
175
|
*/
|
|
225
|
-
|
|
226
|
-
return
|
|
176
|
+
alert(context: Context, caption: string, body: DocumentFragment): Promise<DialogResult> {
|
|
177
|
+
return this.show(context, caption, this.#getBodyTemplate(context, body), [
|
|
227
178
|
{label: "OK", value: DialogResult.OK, variant: Variant.Primary}
|
|
228
179
|
]);
|
|
229
180
|
}
|
|
230
181
|
|
|
231
182
|
/**
|
|
232
|
-
* Closes this
|
|
183
|
+
* Closes this dialog box.
|
|
233
184
|
* @param result The dialog box result.
|
|
234
185
|
*/
|
|
235
186
|
close(result: DialogResult = DialogResult.None): void {
|
|
@@ -244,8 +195,8 @@ export class MessageBox extends HTMLElement {
|
|
|
244
195
|
* @param body The child content displayed in the body.
|
|
245
196
|
* @returns The dialog box result.
|
|
246
197
|
*/
|
|
247
|
-
|
|
248
|
-
return
|
|
198
|
+
confirm(context: Context, caption: string, body: DocumentFragment): Promise<DialogResult> {
|
|
199
|
+
return this.show(context, caption, this.#getBodyTemplate(context, body), [
|
|
249
200
|
{label: "OK", value: DialogResult.OK, variant: Variant.Primary},
|
|
250
201
|
{label: "Annuler", value: DialogResult.Cancel, variant: Variant.Secondary}
|
|
251
202
|
]);
|
|
@@ -281,7 +232,7 @@ export class MessageBox extends HTMLElement {
|
|
|
281
232
|
* @param buttons The buttons displayed in the footer.
|
|
282
233
|
* @returns The dialog box result.
|
|
283
234
|
*/
|
|
284
|
-
show(context: Context, caption: string, body: DocumentFragment
|
|
235
|
+
show(context: Context, caption: string, body: DocumentFragment, buttons?: IDialogButton[]): Promise<DialogResult>;
|
|
285
236
|
|
|
286
237
|
/**
|
|
287
238
|
* Shows a message.
|
|
@@ -291,21 +242,18 @@ export class MessageBox extends HTMLElement {
|
|
|
291
242
|
* @param buttons The buttons displayed in the footer.
|
|
292
243
|
* @returns The dialog box result.
|
|
293
244
|
*/
|
|
294
|
-
show(message: IMessage|Context|null = null, caption = "", body
|
|
245
|
+
show(message: IMessage|Context|null = null, caption = "", body = document.createDocumentFragment(), buttons: IDialogButton[] = []): Promise<DialogResult> {
|
|
295
246
|
if (typeof message == "string") {
|
|
296
247
|
const footer = document.createDocumentFragment();
|
|
297
248
|
footer.append(...buttons.map(button => this.#createButton(button)));
|
|
298
|
-
message = {
|
|
249
|
+
message = {body, caption, footer};
|
|
299
250
|
}
|
|
300
251
|
|
|
301
|
-
if (
|
|
302
|
-
|
|
303
|
-
this.caption = message.caption;
|
|
304
|
-
this.context = message.context ?? Context.Info;
|
|
305
|
-
this.icon = message.icon ?? getIcon(this.context);
|
|
306
|
-
|
|
307
|
-
const footer = typeof message.footer == "string" ? createDocumentFragment(message.footer) : (message.footer ?? document.createDocumentFragment());
|
|
252
|
+
if (message) {
|
|
253
|
+
const footer = message.footer ?? document.createDocumentFragment();
|
|
308
254
|
for (const button of footer.querySelectorAll("button")) button.addEventListener("click", this.#close);
|
|
255
|
+
this.body = message.body;
|
|
256
|
+
this.caption = message.caption;
|
|
309
257
|
this.footer = footer;
|
|
310
258
|
}
|
|
311
259
|
|
|
@@ -317,7 +265,7 @@ export class MessageBox extends HTMLElement {
|
|
|
317
265
|
}
|
|
318
266
|
|
|
319
267
|
/**
|
|
320
|
-
* Closes this
|
|
268
|
+
* Closes this dialog box.
|
|
321
269
|
* @param event The dispatched event.
|
|
322
270
|
*/
|
|
323
271
|
readonly #close: (event: Event) => void = event => {
|
|
@@ -345,11 +293,18 @@ export class MessageBox extends HTMLElement {
|
|
|
345
293
|
}
|
|
346
294
|
|
|
347
295
|
/**
|
|
348
|
-
*
|
|
349
|
-
* @param
|
|
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.
|
|
350
300
|
*/
|
|
351
|
-
#
|
|
352
|
-
|
|
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
|
+
`;
|
|
353
308
|
}
|
|
354
309
|
|
|
355
310
|
/**
|
|
@@ -361,7 +316,7 @@ export class MessageBox extends HTMLElement {
|
|
|
361
316
|
}
|
|
362
317
|
|
|
363
318
|
/**
|
|
364
|
-
* Updates the value indicating whether to vertically center this
|
|
319
|
+
* Updates the value indicating whether to vertically center this dialog box.
|
|
365
320
|
* @param value The new value.
|
|
366
321
|
*/
|
|
367
322
|
#updateCentered(value: boolean): void {
|
|
@@ -369,25 +324,15 @@ export class MessageBox extends HTMLElement {
|
|
|
369
324
|
}
|
|
370
325
|
|
|
371
326
|
/**
|
|
372
|
-
* Updates the
|
|
327
|
+
* Updates the value indicating whether to apply a transition.
|
|
373
328
|
* @param value The new value.
|
|
374
329
|
*/
|
|
375
|
-
#
|
|
376
|
-
|
|
377
|
-
classList.remove(...Object.values(Context).map(context => `text-${toCss(context)}`));
|
|
378
|
-
classList.add(`text-${toCss(value)}`);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Updates the icon displayed next to the body.
|
|
383
|
-
* @param value The new value.
|
|
384
|
-
*/
|
|
385
|
-
#updateIcon(value: string|null): void {
|
|
386
|
-
this.querySelector(".modal-body > .icon")!.textContent = (value ?? "").trim() || getIcon(this.context);
|
|
330
|
+
#updateFade(value: boolean): void {
|
|
331
|
+
this.firstElementChild!.classList.toggle("fade", value);
|
|
387
332
|
}
|
|
388
333
|
|
|
389
334
|
/**
|
|
390
|
-
* Updates the value indicating whether to this
|
|
335
|
+
* Updates the value indicating whether to this dialog box will not close when clicking outside of it.
|
|
391
336
|
* @param value The new value.
|
|
392
337
|
*/
|
|
393
338
|
#updateModal(value: boolean): void {
|
|
@@ -395,10 +340,10 @@ export class MessageBox extends HTMLElement {
|
|
|
395
340
|
}
|
|
396
341
|
|
|
397
342
|
/**
|
|
398
|
-
* Updates the body
|
|
343
|
+
* Updates the value indicating whether the body is scrollable.
|
|
399
344
|
* @param value The new value.
|
|
400
345
|
*/
|
|
401
|
-
#
|
|
346
|
+
#updateScrollable(value: boolean): void {
|
|
402
347
|
this.querySelector(".modal-dialog")!.classList.toggle("modal-dialog-scrollable", value);
|
|
403
348
|
}
|
|
404
349
|
}
|
|
@@ -412,6 +357,6 @@ declare global {
|
|
|
412
357
|
* The map of HTML tag names.
|
|
413
358
|
*/
|
|
414
359
|
interface HTMLElementTagNameMap {
|
|
415
|
-
"
|
|
360
|
+
"dialog-box": DialogBox;
|
|
416
361
|
}
|
|
417
362
|
}
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export class LoadingIndicator extends HTMLElement {
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* The list of observed attributes.
|
|
8
|
+
*/
|
|
9
|
+
static readonly observedAttributes = ["fade"];
|
|
10
|
+
|
|
6
11
|
/**
|
|
7
12
|
* The number of concurrent HTTP requests.
|
|
8
13
|
*/
|
|
@@ -16,7 +21,47 @@ export class LoadingIndicator extends HTMLElement {
|
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
/**
|
|
19
|
-
*
|
|
24
|
+
* Value indicating whether to apply a transition.
|
|
25
|
+
*/
|
|
26
|
+
get fade(): boolean {
|
|
27
|
+
return this.hasAttribute("fade");
|
|
28
|
+
}
|
|
29
|
+
set fade(value: boolean) {
|
|
30
|
+
this.toggleAttribute("fade", value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Value indicating whether to initially show this component.
|
|
35
|
+
*/
|
|
36
|
+
get open(): boolean {
|
|
37
|
+
return this.hasAttribute("open");
|
|
38
|
+
}
|
|
39
|
+
set open(value: boolean) {
|
|
40
|
+
this.toggleAttribute("open", value);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Method invoked when an attribute has been changed.
|
|
45
|
+
* @param attribute The attribute name.
|
|
46
|
+
* @param oldValue The previous attribute value.
|
|
47
|
+
* @param newValue The new attribute value.
|
|
48
|
+
*/
|
|
49
|
+
attributeChangedCallback(attribute: string, oldValue: string|null, newValue: string|null): void {
|
|
50
|
+
if (newValue != oldValue) switch (attribute) {
|
|
51
|
+
case "fade": this.#updateFade(newValue != null); break;
|
|
52
|
+
// No default
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Method invoked when this component is connected.
|
|
58
|
+
*/
|
|
59
|
+
connectedCallback(): void {
|
|
60
|
+
if (this.open) this.show();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Hides this loading indicator.
|
|
20
65
|
* @param options Value indicating whether to force the loading indicator to hide.
|
|
21
66
|
*/
|
|
22
67
|
hide(options: {force?: boolean} = {}): void {
|
|
@@ -25,16 +70,26 @@ export class LoadingIndicator extends HTMLElement {
|
|
|
25
70
|
this.#requestCount = 0;
|
|
26
71
|
this.classList.add("hide");
|
|
27
72
|
this.classList.remove("show");
|
|
73
|
+
document.body.classList.remove("loading");
|
|
28
74
|
}
|
|
29
75
|
}
|
|
30
76
|
|
|
31
77
|
/**
|
|
32
|
-
* Shows
|
|
78
|
+
* Shows this loading indicator.
|
|
33
79
|
*/
|
|
34
80
|
show(): void {
|
|
35
81
|
this.#requestCount++;
|
|
36
82
|
this.classList.remove("hide");
|
|
37
83
|
this.classList.add("show");
|
|
84
|
+
document.body.classList.add("loading");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Updates the value indicating whether to apply a transition.
|
|
89
|
+
* @param value The new value.
|
|
90
|
+
*/
|
|
91
|
+
#updateFade(value: boolean): void {
|
|
92
|
+
this.classList.toggle("fade", value);
|
|
38
93
|
}
|
|
39
94
|
}
|
|
40
95
|
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export class OfflineIndicator extends HTMLElement {
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* The list of observed attributes.
|
|
8
|
+
*/
|
|
9
|
+
static readonly observedAttributes = ["fade"];
|
|
10
|
+
|
|
6
11
|
/**
|
|
7
12
|
* Registers the component.
|
|
8
13
|
*/
|
|
@@ -10,27 +15,85 @@ export class OfflineIndicator extends HTMLElement {
|
|
|
10
15
|
customElements.define("offline-indicator", this);
|
|
11
16
|
}
|
|
12
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Value indicating whether to apply a transition.
|
|
20
|
+
*/
|
|
21
|
+
get fade(): boolean {
|
|
22
|
+
return this.hasAttribute("fade");
|
|
23
|
+
}
|
|
24
|
+
set fade(value: boolean) {
|
|
25
|
+
this.toggleAttribute("fade", value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Value indicating whether to initially show this component.
|
|
30
|
+
*/
|
|
31
|
+
get open(): boolean {
|
|
32
|
+
return this.hasAttribute("open");
|
|
33
|
+
}
|
|
34
|
+
set open(value: boolean) {
|
|
35
|
+
this.toggleAttribute("open", value);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Method invoked when an attribute has been changed.
|
|
40
|
+
* @param attribute The attribute name.
|
|
41
|
+
* @param oldValue The previous attribute value.
|
|
42
|
+
* @param newValue The new attribute value.
|
|
43
|
+
*/
|
|
44
|
+
attributeChangedCallback(attribute: string, oldValue: string|null, newValue: string|null): void {
|
|
45
|
+
if (newValue != oldValue) switch (attribute) {
|
|
46
|
+
case "fade": this.#updateFade(newValue != null); break;
|
|
47
|
+
// No default
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
13
51
|
/**
|
|
14
52
|
* Method invoked when this component is connected.
|
|
15
53
|
*/
|
|
16
54
|
connectedCallback(): void {
|
|
17
|
-
this.#
|
|
18
|
-
|
|
55
|
+
for (const event of ["online", "offline"]) addEventListener(event, this.#updateVisibility);
|
|
56
|
+
if (this.open) this.show();
|
|
57
|
+
else this.#updateVisibility();
|
|
19
58
|
}
|
|
20
59
|
|
|
21
60
|
/**
|
|
22
61
|
* Method invoked when this component is disconnected.
|
|
23
62
|
*/
|
|
24
63
|
disconnectedCallback(): void {
|
|
25
|
-
for (const event of ["online", "offline"]) removeEventListener(event, this.#
|
|
64
|
+
for (const event of ["online", "offline"]) removeEventListener(event, this.#updateVisibility);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Hides this offline indicator.
|
|
69
|
+
*/
|
|
70
|
+
hide(): void {
|
|
71
|
+
this.classList.remove("show");
|
|
72
|
+
this.classList.add("hide");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Shows this offline indicator.
|
|
77
|
+
*/
|
|
78
|
+
show(): void {
|
|
79
|
+
this.classList.remove("hide");
|
|
80
|
+
this.classList.add("show");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Updates the value indicating whether to apply a transition.
|
|
85
|
+
* @param value The new value.
|
|
86
|
+
*/
|
|
87
|
+
#updateFade(value: boolean): void {
|
|
88
|
+
this.classList.toggle("fade", value);
|
|
26
89
|
}
|
|
27
90
|
|
|
28
91
|
/**
|
|
29
|
-
* Updates this component.
|
|
92
|
+
* Updates the visibility of this component.
|
|
30
93
|
*/
|
|
31
|
-
readonly #
|
|
32
|
-
|
|
33
|
-
this.
|
|
94
|
+
readonly #updateVisibility: () => void = () => {
|
|
95
|
+
if (navigator.onLine) this.hide();
|
|
96
|
+
else this.show();
|
|
34
97
|
}
|
|
35
98
|
}
|
|
36
99
|
|