@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
package/ReadMe.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Cédric Belin's Base
|
|
2
|
-
   
|
|
3
3
|
|
|
4
4
|
Base library by [Cédric Belin](https://cedric-belin.fr), full stack developer,
|
|
5
5
|
implemented in [C#](https://learn.microsoft.com/en-us/dotnet/csharp) and [TypeScript](https://www.typescriptlang.org).
|
|
@@ -11,17 +11,17 @@ export declare function atMidnight(date: Date): Date;
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function daysInMonth(date: Date): number;
|
|
13
13
|
/**
|
|
14
|
-
* Gets the date of Easter for
|
|
15
|
-
* @param
|
|
16
|
-
* @returns The date of Easter for the specified
|
|
14
|
+
* Gets the date of Easter for the year corresponding to the specified date.
|
|
15
|
+
* @param date The date.
|
|
16
|
+
* @returns The date of Easter for the year corresponding to the specified date.
|
|
17
17
|
*/
|
|
18
|
-
export declare function getEaster(
|
|
18
|
+
export declare function getEaster(date: Date): Date;
|
|
19
19
|
/**
|
|
20
|
-
* Gets the list of holidays for
|
|
21
|
-
* @param
|
|
22
|
-
* @returns The list of holidays for the specified
|
|
20
|
+
* Gets the list of holidays for the year corresponding to the specified date.
|
|
21
|
+
* @param date The date.
|
|
22
|
+
* @returns The list of holidays for the year corresponding to the specified date.
|
|
23
23
|
*/
|
|
24
|
-
export declare function getHolidays(
|
|
24
|
+
export declare function getHolidays(date: Date): Date[];
|
|
25
25
|
/**
|
|
26
26
|
* Gets the quarter corresponding to the specified date.
|
|
27
27
|
* @param date The date.
|
|
@@ -69,4 +69,4 @@ export declare function toYmdHms(date: Date, options?: {
|
|
|
69
69
|
excludeTime?: boolean;
|
|
70
70
|
separator?: string;
|
|
71
71
|
}): string;
|
|
72
|
-
//# sourceMappingURL=
|
|
72
|
+
//# sourceMappingURL=Date.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Date.d.ts","sourceRoot":"","sources":["../src/Client/Date.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE9C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAc1C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,CAqB9C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE7C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAIhD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAG9C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAG7C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAGhD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE5C;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE;IAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAM,GAAG,MAAM,CAM7H"}
|
|
@@ -16,11 +16,12 @@ export function daysInMonth(date) {
|
|
|
16
16
|
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* Gets the date of Easter for
|
|
20
|
-
* @param
|
|
21
|
-
* @returns The date of Easter for the specified
|
|
19
|
+
* Gets the date of Easter for the year corresponding to the specified date.
|
|
20
|
+
* @param date The date.
|
|
21
|
+
* @returns The date of Easter for the year corresponding to the specified date.
|
|
22
22
|
*/
|
|
23
|
-
export function getEaster(
|
|
23
|
+
export function getEaster(date) {
|
|
24
|
+
const year = date.getFullYear();
|
|
24
25
|
/* eslint-disable id-length */
|
|
25
26
|
const n = year % 19;
|
|
26
27
|
const c = Math.trunc(year / 100);
|
|
@@ -33,12 +34,13 @@ export function getEaster(year = new Date().getFullYear()) {
|
|
|
33
34
|
return new Date(year, Math.trunc(result / 31) - 1, (result % 31) + 1);
|
|
34
35
|
}
|
|
35
36
|
/**
|
|
36
|
-
* Gets the list of holidays for
|
|
37
|
-
* @param
|
|
38
|
-
* @returns The list of holidays for the specified
|
|
37
|
+
* Gets the list of holidays for the year corresponding to the specified date.
|
|
38
|
+
* @param date The date.
|
|
39
|
+
* @returns The list of holidays for the year corresponding to the specified date.
|
|
39
40
|
*/
|
|
40
|
-
export function getHolidays(
|
|
41
|
+
export function getHolidays(date) {
|
|
41
42
|
const holidays = [];
|
|
43
|
+
const year = date.getFullYear();
|
|
42
44
|
// Fixed holidays.
|
|
43
45
|
holidays.push(new Date(year, 0, 1)); // New year.
|
|
44
46
|
holidays.push(new Date(year, 4, 1)); // Labor day.
|
|
@@ -49,7 +51,7 @@ export function getHolidays(year = new Date().getFullYear()) {
|
|
|
49
51
|
holidays.push(new Date(year, 10, 11)); // Armistice (1918).
|
|
50
52
|
holidays.push(new Date(year, 11, 25)); // Christmas.
|
|
51
53
|
// Holidays depending on Easter.
|
|
52
|
-
const easter = getEaster(
|
|
54
|
+
const easter = getEaster(date);
|
|
53
55
|
holidays.push(new Date(easter.getTime() + Duration.Day)); // Easter monday.
|
|
54
56
|
holidays.push(new Date(easter.getTime() + (39 * Duration.Day))); // Ascension thursday.
|
|
55
57
|
holidays.push(new Date(easter.getTime() + (50 * Duration.Day))); // Pentecost monday.
|
|
@@ -89,7 +91,7 @@ export function inLeapYear(date) {
|
|
|
89
91
|
*/
|
|
90
92
|
export function isHoliday(date) {
|
|
91
93
|
const timestamp = atMidnight(date).getTime();
|
|
92
|
-
return getHolidays(date
|
|
94
|
+
return getHolidays(date).some(holiday => holiday.getTime() == timestamp);
|
|
93
95
|
}
|
|
94
96
|
/**
|
|
95
97
|
* Returns a value indicating whether the specified date is a working day.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"File.d.ts","sourceRoot":"","sources":["../src/Client/File.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAUzC;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAM,GAAG,IAAI,CAkBvE;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAatC;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAOlD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Number.d.ts","sourceRoot":"","sources":["../src/Client/Number.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,MAAM,CAG1D"}
|
|
@@ -30,18 +30,6 @@ export declare function split(value: string, splitLength?: number): string[];
|
|
|
30
30
|
* @returns The processed string.
|
|
31
31
|
*/
|
|
32
32
|
export declare function stripTags(value: string): string;
|
|
33
|
-
/**
|
|
34
|
-
* Removes whitespace from both ends of the items of the specified array.
|
|
35
|
-
* @param array The array to process.
|
|
36
|
-
* @returns The input array.
|
|
37
|
-
*/
|
|
38
|
-
export declare function trimArray<T>(array: T[]): T[];
|
|
39
|
-
/**
|
|
40
|
-
* Removes whitespace from both ends of the properties of the specified object.
|
|
41
|
-
* @param object The object to process.
|
|
42
|
-
* @returns The input object.
|
|
43
|
-
*/
|
|
44
|
-
export declare function trimObject<T>(object: Record<string, T>): Record<string, T>;
|
|
45
33
|
/**
|
|
46
34
|
* Truncates the specified string to the given number of characters.
|
|
47
35
|
* @param value The string to be truncated.
|
|
@@ -50,10 +38,4 @@ export declare function trimObject<T>(object: Record<string, T>): Record<string,
|
|
|
50
38
|
* @returns The truncated string.
|
|
51
39
|
*/
|
|
52
40
|
export declare function truncate(value: string, length: number, ellipsis?: string): string;
|
|
53
|
-
|
|
54
|
-
* Replaces invalid XML characters in a string with their valid XML equivalent.
|
|
55
|
-
* @param value The string to process.
|
|
56
|
-
* @returns The processed string.
|
|
57
|
-
*/
|
|
58
|
-
export declare function xmlEscape(value: string): string;
|
|
59
|
-
//# sourceMappingURL=StringExtensions.d.ts.map
|
|
41
|
+
//# sourceMappingURL=String.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"String.d.ts","sourceRoot":"","sources":["../src/Client/String.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,IAAI,CAAC,MAAM,GAAC,MAA2B,GAAG,MAAM,CAEjG;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,SAAI,GAAG,MAAM,EAAE,CAE9D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,SAAQ,GAAG,MAAM,CAEhF"}
|
|
@@ -1,13 +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
1
|
/**
|
|
12
2
|
* Converts the first character to uppercase.
|
|
13
3
|
* @param value The string to process.
|
|
@@ -50,28 +40,6 @@ export function split(value, splitLength = 1) {
|
|
|
50
40
|
export function stripTags(value) {
|
|
51
41
|
return value.replace(/<[^>]+>/g, "");
|
|
52
42
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Removes whitespace from both ends of the items of the specified array.
|
|
55
|
-
* @param array The array to process.
|
|
56
|
-
* @returns The input array.
|
|
57
|
-
*/
|
|
58
|
-
export function trimArray(array) {
|
|
59
|
-
for (const [index, value] of array.entries())
|
|
60
|
-
if (typeof value == "string")
|
|
61
|
-
Reflect.set(array, index, value.trim());
|
|
62
|
-
return array;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Removes whitespace from both ends of the properties of the specified object.
|
|
66
|
-
* @param object The object to process.
|
|
67
|
-
* @returns The input object.
|
|
68
|
-
*/
|
|
69
|
-
export function trimObject(object) {
|
|
70
|
-
for (const [key, value] of Object.entries(object))
|
|
71
|
-
if (typeof value == "string")
|
|
72
|
-
Reflect.set(object, key, value.trim());
|
|
73
|
-
return object;
|
|
74
|
-
}
|
|
75
43
|
/**
|
|
76
44
|
* Truncates the specified string to the given number of characters.
|
|
77
45
|
* @param value The string to be truncated.
|
|
@@ -82,11 +50,3 @@ export function trimObject(object) {
|
|
|
82
50
|
export function truncate(value, length, ellipsis = "...") {
|
|
83
51
|
return value.length > length ? value.slice(0, length) + ellipsis : value;
|
|
84
52
|
}
|
|
85
|
-
/**
|
|
86
|
-
* Replaces invalid XML characters in a string with their valid XML equivalent.
|
|
87
|
-
* @param value The string to process.
|
|
88
|
-
* @returns The processed string.
|
|
89
|
-
*/
|
|
90
|
-
export function xmlEscape(value) {
|
|
91
|
-
return value.replace(/[&<>"']/g, character => xmlEntities.get(character) ?? character);
|
|
92
|
-
}
|
|
@@ -1,61 +1,36 @@
|
|
|
1
|
-
import { Context } from "../Context.js";
|
|
1
|
+
import { type Context } from "../Context.js";
|
|
2
2
|
import { DialogResult } from "../DialogResult.js";
|
|
3
3
|
import type { IDialogButton } from "./DialogButton.js";
|
|
4
4
|
/**
|
|
5
5
|
* Represents a message to display in a dialog box.
|
|
6
6
|
*/
|
|
7
7
|
export interface IMessage {
|
|
8
|
-
/**
|
|
9
|
-
* Value indicating whether to apply a fade transition.
|
|
10
|
-
*/
|
|
11
|
-
animation?: boolean;
|
|
12
8
|
/**
|
|
13
9
|
* The child content displayed in the body.
|
|
14
10
|
*/
|
|
15
|
-
body: DocumentFragment
|
|
11
|
+
body: DocumentFragment;
|
|
16
12
|
/**
|
|
17
13
|
* The title displayed in the header.
|
|
18
14
|
*/
|
|
19
15
|
caption: string;
|
|
20
|
-
/**
|
|
21
|
-
* Value indicating whether to vertically center this message box.
|
|
22
|
-
*/
|
|
23
|
-
centered?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* A contextual modifier.
|
|
26
|
-
*/
|
|
27
|
-
context?: Context;
|
|
28
16
|
/**
|
|
29
17
|
* The child content displayed in the footer.
|
|
30
18
|
*/
|
|
31
|
-
footer?: DocumentFragment
|
|
32
|
-
/**
|
|
33
|
-
* The icon displayed next to the body.
|
|
34
|
-
*/
|
|
35
|
-
icon?: string | null;
|
|
36
|
-
/**
|
|
37
|
-
* Value indicating whether the body is scrollable.
|
|
38
|
-
*/
|
|
39
|
-
scrollable?: boolean;
|
|
19
|
+
footer?: DocumentFragment;
|
|
40
20
|
}
|
|
41
21
|
/**
|
|
42
|
-
* Displays a
|
|
22
|
+
* Displays a dialog box, which presents a message to the user.
|
|
43
23
|
*/
|
|
44
|
-
export declare class
|
|
24
|
+
export declare class DialogBox extends HTMLElement {
|
|
45
25
|
#private;
|
|
46
26
|
/**
|
|
47
27
|
* The list of observed attributes.
|
|
48
28
|
*/
|
|
49
29
|
static readonly observedAttributes: string[];
|
|
50
30
|
/**
|
|
51
|
-
* Creates a new
|
|
31
|
+
* Creates a new dialog box.
|
|
52
32
|
*/
|
|
53
33
|
constructor();
|
|
54
|
-
/**
|
|
55
|
-
* Value indicating whether to apply a fade transition.
|
|
56
|
-
*/
|
|
57
|
-
get animation(): boolean;
|
|
58
|
-
set animation(value: boolean);
|
|
59
34
|
/**
|
|
60
35
|
* The child content displayed in the body.
|
|
61
36
|
*/
|
|
@@ -66,31 +41,26 @@ export declare class MessageBox extends HTMLElement {
|
|
|
66
41
|
get caption(): string;
|
|
67
42
|
set caption(value: string);
|
|
68
43
|
/**
|
|
69
|
-
* Value indicating whether to vertically center this
|
|
44
|
+
* Value indicating whether to vertically center this dialog box.
|
|
70
45
|
*/
|
|
71
46
|
get centered(): boolean;
|
|
72
47
|
set centered(value: boolean);
|
|
73
48
|
/**
|
|
74
|
-
*
|
|
49
|
+
* Value indicating whether to apply a transition.
|
|
75
50
|
*/
|
|
76
|
-
get
|
|
77
|
-
set
|
|
51
|
+
get fade(): boolean;
|
|
52
|
+
set fade(value: boolean);
|
|
78
53
|
/**
|
|
79
54
|
* The child content displayed in the footer.
|
|
80
55
|
*/
|
|
81
56
|
set footer(value: DocumentFragment);
|
|
82
57
|
/**
|
|
83
|
-
*
|
|
84
|
-
*/
|
|
85
|
-
get icon(): string | null;
|
|
86
|
-
set icon(value: string | null);
|
|
87
|
-
/**
|
|
88
|
-
* Value indicating whether to this message box will not close when clicking outside of it.
|
|
58
|
+
* Value indicating whether to this dialog box will not close when clicking outside of it.
|
|
89
59
|
*/
|
|
90
60
|
get modal(): boolean;
|
|
91
61
|
set modal(value: boolean);
|
|
92
62
|
/**
|
|
93
|
-
* Value indicating whether to initially show this
|
|
63
|
+
* Value indicating whether to initially show this component.
|
|
94
64
|
*/
|
|
95
65
|
get open(): boolean;
|
|
96
66
|
set open(value: boolean);
|
|
@@ -113,9 +83,9 @@ export declare class MessageBox extends HTMLElement {
|
|
|
113
83
|
* @param body The child content displayed in the body.
|
|
114
84
|
* @returns The dialog box result.
|
|
115
85
|
*/
|
|
116
|
-
alert(context: Context, caption: string, body: DocumentFragment
|
|
86
|
+
alert(context: Context, caption: string, body: DocumentFragment): Promise<DialogResult>;
|
|
117
87
|
/**
|
|
118
|
-
* Closes this
|
|
88
|
+
* Closes this dialog box.
|
|
119
89
|
* @param result The dialog box result.
|
|
120
90
|
*/
|
|
121
91
|
close(result?: DialogResult): void;
|
|
@@ -126,7 +96,7 @@ export declare class MessageBox extends HTMLElement {
|
|
|
126
96
|
* @param body The child content displayed in the body.
|
|
127
97
|
* @returns The dialog box result.
|
|
128
98
|
*/
|
|
129
|
-
confirm(context: Context, caption: string, body: DocumentFragment
|
|
99
|
+
confirm(context: Context, caption: string, body: DocumentFragment): Promise<DialogResult>;
|
|
130
100
|
/**
|
|
131
101
|
* Method invoked when this component is connected.
|
|
132
102
|
*/
|
|
@@ -149,7 +119,7 @@ export declare class MessageBox extends HTMLElement {
|
|
|
149
119
|
* @param buttons The buttons displayed in the footer.
|
|
150
120
|
* @returns The dialog box result.
|
|
151
121
|
*/
|
|
152
|
-
show(context: Context, caption: string, body: DocumentFragment
|
|
122
|
+
show(context: Context, caption: string, body: DocumentFragment, buttons?: IDialogButton[]): Promise<DialogResult>;
|
|
153
123
|
}
|
|
154
124
|
/**
|
|
155
125
|
* Declaration merging.
|
|
@@ -159,7 +129,7 @@ declare global {
|
|
|
159
129
|
* The map of HTML tag names.
|
|
160
130
|
*/
|
|
161
131
|
interface HTMLElementTagNameMap {
|
|
162
|
-
"
|
|
132
|
+
"dialog-box": DialogBox;
|
|
163
133
|
}
|
|
164
134
|
}
|
|
165
|
-
//# sourceMappingURL=
|
|
135
|
+
//# sourceMappingURL=DialogBox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DialogBox.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/DialogBox.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,OAAO,EAAiB,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAGhD,OAAO,KAAK,EAAe,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,QAAQ;IAExB;;OAEG;IACH,IAAI,EAAE,gBAAgB,CAAC;IAEvB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC1B;AAED;;GAEG;AACH,qBAAa,SAAU,SAAQ,WAAW;;IAEzC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAA0D;IAsB5F;;OAEG;;IAeH;;OAEG;IACH,IAAI,IAAI,CAAC,KAAK,EAAE,gBAAgB,EAE/B;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,MAAM,CAEpB;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,MAAM,EAExB;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,OAAO,EAE1B;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,OAAO,CAElB;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,OAAO,EAEtB;IAED;;OAEG;IACH,IAAI,MAAM,CAAC,KAAK,EAAE,gBAAgB,EAIjC;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,OAAO,CAEnB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,OAAO,EAEvB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,OAAO,CAElB;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,OAAO,EAEtB;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,OAAO,CAExB;IACD,IAAI,UAAU,CAAC,KAAK,EAAE,OAAO,EAE5B;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;IAW/F;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC;IAMvF;;;OAGG;IACH,KAAK,CAAC,MAAM,GAAE,YAAgC,GAAG,IAAI;IAKrD;;;;;;OAMG;IACH,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC;IAOzF;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAKzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAI5B;;;;OAIG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC;IAE/C;;;;;;;OAOG;IACH,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC;CAkHjH;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,YAAY,EAAE,SAAS,CAAC;KACxB;CACD"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Modal } from "bootstrap";
|
|
2
|
-
import {
|
|
2
|
+
import { 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
|
/**
|
|
7
|
-
* Displays a
|
|
7
|
+
* Displays a dialog box, which presents a message to the user.
|
|
8
8
|
*/
|
|
9
|
-
export class
|
|
9
|
+
export class DialogBox extends HTMLElement {
|
|
10
10
|
/**
|
|
11
11
|
* The list of observed attributes.
|
|
12
12
|
*/
|
|
13
|
-
static observedAttributes = ["
|
|
13
|
+
static observedAttributes = ["caption", "centered", "fade", "modal", "scrollable"];
|
|
14
14
|
/**
|
|
15
15
|
* The template for a button.
|
|
16
16
|
*/
|
|
@@ -28,7 +28,7 @@ export class MessageBox extends HTMLElement {
|
|
|
28
28
|
*/
|
|
29
29
|
#result = DialogResult.None;
|
|
30
30
|
/**
|
|
31
|
-
* Creates a new
|
|
31
|
+
* Creates a new dialog box.
|
|
32
32
|
*/
|
|
33
33
|
constructor() {
|
|
34
34
|
super();
|
|
@@ -41,16 +41,7 @@ export class MessageBox extends HTMLElement {
|
|
|
41
41
|
* Registers the component.
|
|
42
42
|
*/
|
|
43
43
|
static {
|
|
44
|
-
customElements.define("
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Value indicating whether to apply a fade transition.
|
|
48
|
-
*/
|
|
49
|
-
get animation() {
|
|
50
|
-
return this.hasAttribute("animation");
|
|
51
|
-
}
|
|
52
|
-
set animation(value) {
|
|
53
|
-
this.toggleAttribute("animation", value);
|
|
44
|
+
customElements.define("dialog-box", this);
|
|
54
45
|
}
|
|
55
46
|
/**
|
|
56
47
|
* The child content displayed in the body.
|
|
@@ -68,7 +59,7 @@ export class MessageBox extends HTMLElement {
|
|
|
68
59
|
this.setAttribute("caption", value);
|
|
69
60
|
}
|
|
70
61
|
/**
|
|
71
|
-
* Value indicating whether to vertically center this
|
|
62
|
+
* Value indicating whether to vertically center this dialog box.
|
|
72
63
|
*/
|
|
73
64
|
get centered() {
|
|
74
65
|
return this.hasAttribute("centered");
|
|
@@ -77,14 +68,13 @@ export class MessageBox extends HTMLElement {
|
|
|
77
68
|
this.toggleAttribute("centered", value);
|
|
78
69
|
}
|
|
79
70
|
/**
|
|
80
|
-
*
|
|
71
|
+
* Value indicating whether to apply a transition.
|
|
81
72
|
*/
|
|
82
|
-
get
|
|
83
|
-
|
|
84
|
-
return Object.values(Context).includes(value) ? value : Context.Info;
|
|
73
|
+
get fade() {
|
|
74
|
+
return this.hasAttribute("fade");
|
|
85
75
|
}
|
|
86
|
-
set
|
|
87
|
-
this.
|
|
76
|
+
set fade(value) {
|
|
77
|
+
this.toggleAttribute("fade", value);
|
|
88
78
|
}
|
|
89
79
|
/**
|
|
90
80
|
* The child content displayed in the footer.
|
|
@@ -95,17 +85,7 @@ export class MessageBox extends HTMLElement {
|
|
|
95
85
|
footer.replaceChildren(...value.childNodes);
|
|
96
86
|
}
|
|
97
87
|
/**
|
|
98
|
-
*
|
|
99
|
-
*/
|
|
100
|
-
get icon() {
|
|
101
|
-
const value = this.getAttribute("icon") ?? "";
|
|
102
|
-
return value.trim() || null;
|
|
103
|
-
}
|
|
104
|
-
set icon(value) {
|
|
105
|
-
this.toggleAttribute("icon", Boolean(value));
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Value indicating whether to this message box will not close when clicking outside of it.
|
|
88
|
+
* Value indicating whether to this dialog box will not close when clicking outside of it.
|
|
109
89
|
*/
|
|
110
90
|
get modal() {
|
|
111
91
|
return this.hasAttribute("modal");
|
|
@@ -114,7 +94,7 @@ export class MessageBox extends HTMLElement {
|
|
|
114
94
|
this.toggleAttribute("modal", value);
|
|
115
95
|
}
|
|
116
96
|
/**
|
|
117
|
-
* Value indicating whether to initially show this
|
|
97
|
+
* Value indicating whether to initially show this component.
|
|
118
98
|
*/
|
|
119
99
|
get open() {
|
|
120
100
|
return this.hasAttribute("open");
|
|
@@ -140,26 +120,20 @@ export class MessageBox extends HTMLElement {
|
|
|
140
120
|
attributeChangedCallback(attribute, oldValue, newValue) {
|
|
141
121
|
if (newValue != oldValue)
|
|
142
122
|
switch (attribute) {
|
|
143
|
-
case "animation":
|
|
144
|
-
this.#updateAnimation(newValue != null);
|
|
145
|
-
break;
|
|
146
123
|
case "caption":
|
|
147
124
|
this.#updateCaption(newValue ?? "");
|
|
148
125
|
break;
|
|
149
126
|
case "centered":
|
|
150
127
|
this.#updateCentered(newValue != null);
|
|
151
128
|
break;
|
|
152
|
-
case "context":
|
|
153
|
-
this.#updateContext(Object.values(Context).includes(newValue) ? newValue : Context.Info);
|
|
154
|
-
break;
|
|
155
|
-
case "icon":
|
|
156
|
-
this.#updateIcon(newValue);
|
|
157
|
-
break;
|
|
158
129
|
case "modal":
|
|
159
130
|
this.#updateModal(newValue != null);
|
|
160
131
|
break;
|
|
132
|
+
case "fade":
|
|
133
|
+
this.#updateFade(newValue != null);
|
|
134
|
+
break;
|
|
161
135
|
case "scrollable":
|
|
162
|
-
this.#
|
|
136
|
+
this.#updateScrollable(newValue != null);
|
|
163
137
|
break;
|
|
164
138
|
// No default
|
|
165
139
|
}
|
|
@@ -171,13 +145,13 @@ export class MessageBox extends HTMLElement {
|
|
|
171
145
|
* @param body The child content displayed in the body.
|
|
172
146
|
* @returns The dialog box result.
|
|
173
147
|
*/
|
|
174
|
-
|
|
175
|
-
return
|
|
148
|
+
alert(context, caption, body) {
|
|
149
|
+
return this.show(context, caption, this.#getBodyTemplate(context, body), [
|
|
176
150
|
{ label: "OK", value: DialogResult.OK, variant: Variant.Primary }
|
|
177
151
|
]);
|
|
178
152
|
}
|
|
179
153
|
/**
|
|
180
|
-
* Closes this
|
|
154
|
+
* Closes this dialog box.
|
|
181
155
|
* @param result The dialog box result.
|
|
182
156
|
*/
|
|
183
157
|
close(result = DialogResult.None) {
|
|
@@ -191,8 +165,8 @@ export class MessageBox extends HTMLElement {
|
|
|
191
165
|
* @param body The child content displayed in the body.
|
|
192
166
|
* @returns The dialog box result.
|
|
193
167
|
*/
|
|
194
|
-
|
|
195
|
-
return
|
|
168
|
+
confirm(context, caption, body) {
|
|
169
|
+
return this.show(context, caption, this.#getBodyTemplate(context, body), [
|
|
196
170
|
{ label: "OK", value: DialogResult.OK, variant: Variant.Primary },
|
|
197
171
|
{ label: "Annuler", value: DialogResult.Cancel, variant: Variant.Secondary }
|
|
198
172
|
]);
|
|
@@ -219,20 +193,18 @@ export class MessageBox extends HTMLElement {
|
|
|
219
193
|
* @param buttons The buttons displayed in the footer.
|
|
220
194
|
* @returns The dialog box result.
|
|
221
195
|
*/
|
|
222
|
-
show(message = null, caption = "", body =
|
|
196
|
+
show(message = null, caption = "", body = document.createDocumentFragment(), buttons = []) {
|
|
223
197
|
if (typeof message == "string") {
|
|
224
198
|
const footer = document.createDocumentFragment();
|
|
225
199
|
footer.append(...buttons.map(button => this.#createButton(button)));
|
|
226
|
-
message = {
|
|
200
|
+
message = { body, caption, footer };
|
|
227
201
|
}
|
|
228
|
-
if (
|
|
229
|
-
|
|
230
|
-
this.caption = message.caption;
|
|
231
|
-
this.context = message.context ?? Context.Info;
|
|
232
|
-
this.icon = message.icon ?? getIcon(this.context);
|
|
233
|
-
const footer = typeof message.footer == "string" ? createDocumentFragment(message.footer) : (message.footer ?? document.createDocumentFragment());
|
|
202
|
+
if (message) {
|
|
203
|
+
const footer = message.footer ?? document.createDocumentFragment();
|
|
234
204
|
for (const button of footer.querySelectorAll("button"))
|
|
235
205
|
button.addEventListener("click", this.#close);
|
|
206
|
+
this.body = message.body;
|
|
207
|
+
this.caption = message.caption;
|
|
236
208
|
this.footer = footer;
|
|
237
209
|
}
|
|
238
210
|
const { promise, resolve } = Promise.withResolvers();
|
|
@@ -242,7 +214,7 @@ export class MessageBox extends HTMLElement {
|
|
|
242
214
|
return promise;
|
|
243
215
|
}
|
|
244
216
|
/**
|
|
245
|
-
* Closes this
|
|
217
|
+
* Closes this dialog box.
|
|
246
218
|
* @param event The dispatched event.
|
|
247
219
|
*/
|
|
248
220
|
#close = event => {
|
|
@@ -267,11 +239,18 @@ export class MessageBox extends HTMLElement {
|
|
|
267
239
|
return element;
|
|
268
240
|
}
|
|
269
241
|
/**
|
|
270
|
-
*
|
|
271
|
-
* @param
|
|
242
|
+
* Gets the body template corresponding to the specified context and message.
|
|
243
|
+
* @param context The contextual modifier.
|
|
244
|
+
* @param message The child content displayed in the body.
|
|
245
|
+
* @returns The body template corresponding to the specified context and message.
|
|
272
246
|
*/
|
|
273
|
-
#
|
|
274
|
-
|
|
247
|
+
#getBodyTemplate(context, message) {
|
|
248
|
+
return html `
|
|
249
|
+
<div class="d-flex gap-2">
|
|
250
|
+
<i class="icon icon-fill fs-1 text-${toCss(context)}"> ${getIcon(context)}</i>
|
|
251
|
+
<div class="flex-grow-1">${message}</div>
|
|
252
|
+
</div>
|
|
253
|
+
`;
|
|
275
254
|
}
|
|
276
255
|
/**
|
|
277
256
|
* Updates the title displayed in the header.
|
|
@@ -281,40 +260,31 @@ export class MessageBox extends HTMLElement {
|
|
|
281
260
|
this.querySelector(".modal-title").textContent = value.trim();
|
|
282
261
|
}
|
|
283
262
|
/**
|
|
284
|
-
* Updates the value indicating whether to vertically center this
|
|
263
|
+
* Updates the value indicating whether to vertically center this dialog box.
|
|
285
264
|
* @param value The new value.
|
|
286
265
|
*/
|
|
287
266
|
#updateCentered(value) {
|
|
288
267
|
this.querySelector(".modal-dialog").classList.toggle("modal-dialog-centered", value);
|
|
289
268
|
}
|
|
290
269
|
/**
|
|
291
|
-
* Updates the
|
|
270
|
+
* Updates the value indicating whether to apply a transition.
|
|
292
271
|
* @param value The new value.
|
|
293
272
|
*/
|
|
294
|
-
#
|
|
295
|
-
|
|
296
|
-
classList.remove(...Object.values(Context).map(context => `text-${toCss(context)}`));
|
|
297
|
-
classList.add(`text-${toCss(value)}`);
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Updates the icon displayed next to the body.
|
|
301
|
-
* @param value The new value.
|
|
302
|
-
*/
|
|
303
|
-
#updateIcon(value) {
|
|
304
|
-
this.querySelector(".modal-body > .icon").textContent = (value ?? "").trim() || getIcon(this.context);
|
|
273
|
+
#updateFade(value) {
|
|
274
|
+
this.firstElementChild.classList.toggle("fade", value);
|
|
305
275
|
}
|
|
306
276
|
/**
|
|
307
|
-
* Updates the value indicating whether to this
|
|
277
|
+
* Updates the value indicating whether to this dialog box will not close when clicking outside of it.
|
|
308
278
|
* @param value The new value.
|
|
309
279
|
*/
|
|
310
280
|
#updateModal(value) {
|
|
311
281
|
this.firstElementChild.dataset.bsBackdrop = value ? "static" : "true";
|
|
312
282
|
}
|
|
313
283
|
/**
|
|
314
|
-
* Updates the body
|
|
284
|
+
* Updates the value indicating whether the body is scrollable.
|
|
315
285
|
* @param value The new value.
|
|
316
286
|
*/
|
|
317
|
-
#
|
|
287
|
+
#updateScrollable(value) {
|
|
318
288
|
this.querySelector(".modal-dialog").classList.toggle("modal-dialog-scrollable", value);
|
|
319
289
|
}
|
|
320
290
|
}
|