@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.
Files changed (83) hide show
  1. package/ReadMe.md +1 -1
  2. package/lib/{DateExtensions.d.ts → Date.d.ts} +9 -9
  3. package/lib/Date.d.ts.map +1 -0
  4. package/lib/{DateExtensions.js → Date.js} +12 -10
  5. package/lib/{FileExtensions.d.ts → File.d.ts} +1 -1
  6. package/lib/File.d.ts.map +1 -0
  7. package/lib/{NumberExtensions.d.ts → Number.d.ts} +1 -1
  8. package/lib/Number.d.ts.map +1 -0
  9. package/lib/{StringExtensions.d.ts → String.d.ts} +1 -19
  10. package/lib/String.d.ts.map +1 -0
  11. package/lib/{StringExtensions.js → String.js} +0 -40
  12. package/lib/UI/Components/{MessageBox.d.ts → DialogBox.d.ts} +18 -48
  13. package/lib/UI/Components/DialogBox.d.ts.map +1 -0
  14. package/lib/UI/Components/{MessageBox.js → DialogBox.js} +49 -79
  15. package/lib/UI/Components/LoadingIndicator.d.ts +27 -2
  16. package/lib/UI/Components/LoadingIndicator.d.ts.map +1 -1
  17. package/lib/UI/Components/LoadingIndicator.js +55 -2
  18. package/lib/UI/Components/OfflineIndicator.d.ts +29 -0
  19. package/lib/UI/Components/OfflineIndicator.d.ts.map +1 -1
  20. package/lib/UI/Components/OfflineIndicator.js +70 -7
  21. package/lib/UI/Components/Toast.d.ts +11 -11
  22. package/lib/UI/Components/Toast.d.ts.map +1 -1
  23. package/lib/UI/Components/Toast.js +21 -21
  24. package/lib/UI/Components/Toaster.d.ts +6 -6
  25. package/lib/UI/Components/Toaster.d.ts.map +1 -1
  26. package/lib/UI/Components/Toaster.js +12 -13
  27. package/lib/UI/{FormExtensions.d.ts → Form.d.ts} +1 -1
  28. package/lib/UI/Form.d.ts.map +1 -0
  29. package/lib/UI/Tag.d.ts +15 -0
  30. package/lib/UI/Tag.d.ts.map +1 -0
  31. package/lib/UI/Tag.js +44 -0
  32. package/package.json +1 -1
  33. package/src/Client/{DateExtensions.ts → Date.ts} +13 -10
  34. package/src/Client/{StringExtensions.ts → String.ts} +0 -40
  35. package/src/Client/UI/Components/{MessageBox.ts → DialogBox.ts} +51 -106
  36. package/src/Client/UI/Components/LoadingIndicator.ts +57 -2
  37. package/src/Client/UI/Components/OfflineIndicator.ts +70 -7
  38. package/src/Client/UI/Components/Toast.ts +27 -27
  39. package/src/Client/UI/Components/Toaster.ts +14 -15
  40. package/src/Client/UI/Tag.ts +52 -0
  41. package/src/Client/tsconfig.json +0 -2
  42. package/lib/DateExtensions.d.ts.map +0 -1
  43. package/lib/FileExtensions.d.ts.map +0 -1
  44. package/lib/Hosting/Environment.d.ts +0 -22
  45. package/lib/Hosting/Environment.d.ts.map +0 -1
  46. package/lib/Hosting/Environment.js +0 -17
  47. package/lib/Hosting/HostEnvironment.d.ts +0 -61
  48. package/lib/Hosting/HostEnvironment.d.ts.map +0 -1
  49. package/lib/Hosting/HostEnvironment.js +0 -56
  50. package/lib/Net/Http/HttpMethod.d.ts +0 -46
  51. package/lib/Net/Http/HttpMethod.d.ts.map +0 -1
  52. package/lib/Net/Http/HttpMethod.js +0 -41
  53. package/lib/Net/Http/StatusCode.d.ts +0 -122
  54. package/lib/Net/Http/StatusCode.d.ts.map +0 -1
  55. package/lib/Net/Http/StatusCode.js +0 -117
  56. package/lib/Net/Mime/DispositionType.d.ts +0 -18
  57. package/lib/Net/Mime/DispositionType.d.ts.map +0 -1
  58. package/lib/Net/Mime/DispositionType.js +0 -13
  59. package/lib/Net/Mime/MediaType.d.ts +0 -151
  60. package/lib/Net/Mime/MediaType.d.ts.map +0 -1
  61. package/lib/Net/Mime/MediaType.js +0 -150
  62. package/lib/NumberExtensions.d.ts.map +0 -1
  63. package/lib/StringExtensions.d.ts.map +0 -1
  64. package/lib/UI/Components/MessageBox.d.ts.map +0 -1
  65. package/lib/UI/ElementExtensions.d.ts +0 -13
  66. package/lib/UI/ElementExtensions.d.ts.map +0 -1
  67. package/lib/UI/ElementExtensions.js +0 -18
  68. package/lib/UI/FormExtensions.d.ts.map +0 -1
  69. package/src/Client/Hosting/Environment.ts +0 -25
  70. package/src/Client/Hosting/HostEnvironment.ts +0 -86
  71. package/src/Client/Hosting/tsconfig.json +0 -13
  72. package/src/Client/Net/Http/HttpMethod.ts +0 -55
  73. package/src/Client/Net/Http/StatusCode.ts +0 -150
  74. package/src/Client/Net/Mime/DispositionType.ts +0 -20
  75. package/src/Client/Net/Mime/MediaType.ts +0 -185
  76. package/src/Client/Net/tsconfig.json +0 -13
  77. package/src/Client/UI/ElementExtensions.ts +0 -19
  78. /package/lib/{FileExtensions.js → File.js} +0 -0
  79. /package/lib/{NumberExtensions.js → Number.js} +0 -0
  80. /package/lib/UI/{FormExtensions.js → Form.js} +0 -0
  81. /package/src/Client/{FileExtensions.ts → File.ts} +0 -0
  82. /package/src/Client/{NumberExtensions.ts → Number.ts} +0 -0
  83. /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
- ![.NET](https://badgen.net/badge/.net/%3E%3D9.0/green) ![Version](https://badgen.net/badge/project/v0.19.0/blue) ![Licence](https://badgen.net/badge/licence/MIT/blue)
2
+ ![.NET](https://badgen.net/badge/.net/%3E%3D9.0/green) ![Version](https://badgen.net/badge/project/v0.21.0/blue) ![Licence](https://badgen.net/badge/licence/MIT/blue)
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 a given year.
15
- * @param year The year.
16
- * @returns The date of Easter for the specified year.
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(year?: number): Date;
18
+ export declare function getEaster(date: Date): Date;
19
19
  /**
20
- * Gets the list of holidays for a given year.
21
- * @param year The year.
22
- * @returns The list of holidays for the specified year.
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(year?: number): Date[];
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=DateExtensions.d.ts.map
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 a given year.
20
- * @param year The year.
21
- * @returns The date of Easter for the specified year.
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(year = new Date().getFullYear()) {
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 a given year.
37
- * @param year The year.
38
- * @returns The list of holidays for the specified year.
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(year = new Date().getFullYear()) {
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(year);
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.getFullYear()).some(holiday => holiday.getTime() == timestamp);
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.
@@ -22,4 +22,4 @@ export declare function print(file: File): void;
22
22
  * @returns The data URL corresponding to the given file.
23
23
  */
24
24
  export declare function toDataUrl(file: File): Promise<URL>;
25
- //# sourceMappingURL=FileExtensions.d.ts.map
25
+ //# sourceMappingURL=File.d.ts.map
@@ -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"}
@@ -5,4 +5,4 @@
5
5
  * @returns The value rounded to the given precision.
6
6
  */
7
7
  export declare function round(value: number, precision?: number): number;
8
- //# sourceMappingURL=NumberExtensions.d.ts.map
8
+ //# sourceMappingURL=Number.d.ts.map
@@ -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
- ["&", "&amp;"],
6
- ["<", "&lt;"],
7
- [">", "&gt;"],
8
- ['"', "&quot;"],
9
- ["'", "&#39;"]
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 | string;
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 | string;
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 message window, also known as dialog box, which presents a message to the user.
22
+ * Displays a dialog box, which presents a message to the user.
43
23
  */
44
- export declare class MessageBox extends HTMLElement {
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 message box.
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 message box.
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
- * A contextual modifier.
49
+ * Value indicating whether to apply a transition.
75
50
  */
76
- get context(): Context;
77
- set context(value: Context);
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
- * The icon displayed next to the body.
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 message box.
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 | string): Promise<DialogResult>;
86
+ alert(context: Context, caption: string, body: DocumentFragment): Promise<DialogResult>;
117
87
  /**
118
- * Closes this message box.
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 | string): Promise<DialogResult>;
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 | string, buttons?: IDialogButton[]): Promise<DialogResult>;
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
- "message-box": MessageBox;
132
+ "dialog-box": DialogBox;
163
133
  }
164
134
  }
165
- //# sourceMappingURL=MessageBox.d.ts.map
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 { Context, getIcon, toCss } from "../Context.js";
2
+ import { getIcon, toCss } from "../Context.js";
3
3
  import { DialogResult } from "../DialogResult.js";
4
- import { createDocumentFragment } from "../ElementExtensions.js";
4
+ import { html } from "../Tag.js";
5
5
  import { Variant } from "../Variant.js";
6
6
  /**
7
- * Displays a message window, also known as dialog box, which presents a message to the user.
7
+ * Displays a dialog box, which presents a message to the user.
8
8
  */
9
- export class MessageBox extends HTMLElement {
9
+ export class DialogBox extends HTMLElement {
10
10
  /**
11
11
  * The list of observed attributes.
12
12
  */
13
- static observedAttributes = ["animation", "caption", "centered", "context", "icon", "modal", "scrollable"];
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 message box.
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("message-box", this);
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 message box.
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
- * A contextual modifier.
71
+ * Value indicating whether to apply a transition.
81
72
  */
82
- get context() {
83
- const value = this.getAttribute("context");
84
- return Object.values(Context).includes(value) ? value : Context.Info;
73
+ get fade() {
74
+ return this.hasAttribute("fade");
85
75
  }
86
- set context(value) {
87
- this.setAttribute("context", value);
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
- * The icon displayed next to the body.
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 message box.
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.#updateScrolling(newValue != null);
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
- async alert(context, caption, body) {
175
- return await this.show(context, caption, body, [
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 message box.
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
- async confirm(context, caption, body) {
195
- return await this.show(context, caption, body, [
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 = "", buttons = []) {
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 = { context: message, caption, body, footer };
200
+ message = { body, caption, footer };
227
201
  }
228
- if (typeof message == "object" && message) {
229
- this.body = typeof message.body == "string" ? createDocumentFragment(message.body) : message.body;
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 message box.
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
- * Updates the message box animation.
271
- * @param value The new value.
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
- #updateAnimation(value) {
274
- this.firstElementChild.classList.toggle("fade", value);
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 message box.
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 contextual modifier.
270
+ * Updates the value indicating whether to apply a transition.
292
271
  * @param value The new value.
293
272
  */
294
- #updateContext(value) {
295
- const { classList } = this.querySelector(".modal-body > .icon");
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 message box will not close when clicking outside of it.
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 scrolling.
284
+ * Updates the value indicating whether the body is scrollable.
315
285
  * @param value The new value.
316
286
  */
317
- #updateScrolling(value) {
287
+ #updateScrollable(value) {
318
288
  this.querySelector(".modal-dialog").classList.toggle("modal-dialog-scrollable", value);
319
289
  }
320
290
  }