@cedx/ui 0.1.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 (108) hide show
  1. package/License.md +20 -0
  2. package/ReadMe.md +17 -0
  3. package/lib/Alignment.d.ts +22 -0
  4. package/lib/Alignment.d.ts.map +1 -0
  5. package/lib/Alignment.js +17 -0
  6. package/lib/AppTheme.d.ts +34 -0
  7. package/lib/AppTheme.d.ts.map +1 -0
  8. package/lib/AppTheme.js +41 -0
  9. package/lib/Components/BackButton.d.ts +27 -0
  10. package/lib/Components/BackButton.d.ts.map +1 -0
  11. package/lib/Components/BackButton.js +29 -0
  12. package/lib/Components/DialogBox.d.ts +151 -0
  13. package/lib/Components/DialogBox.d.ts.map +1 -0
  14. package/lib/Components/DialogBox.js +268 -0
  15. package/lib/Components/FullScreenToggler.d.ts +42 -0
  16. package/lib/Components/FullScreenToggler.d.ts.map +1 -0
  17. package/lib/Components/FullScreenToggler.js +103 -0
  18. package/lib/Components/KeyboardAccelerator.d.ts +36 -0
  19. package/lib/Components/KeyboardAccelerator.d.ts.map +1 -0
  20. package/lib/Components/KeyboardAccelerator.js +78 -0
  21. package/lib/Components/LoadingIndicator.d.ts +58 -0
  22. package/lib/Components/LoadingIndicator.d.ts.map +1 -0
  23. package/lib/Components/LoadingIndicator.js +93 -0
  24. package/lib/Components/MenuActivator.d.ts +26 -0
  25. package/lib/Components/MenuActivator.d.ts.map +1 -0
  26. package/lib/Components/MenuActivator.js +42 -0
  27. package/lib/Components/OfflineIndicator.d.ts +59 -0
  28. package/lib/Components/OfflineIndicator.d.ts.map +1 -0
  29. package/lib/Components/OfflineIndicator.js +106 -0
  30. package/lib/Components/TabActivator.d.ts +49 -0
  31. package/lib/Components/TabActivator.d.ts.map +1 -0
  32. package/lib/Components/TabActivator.js +70 -0
  33. package/lib/Components/ThemeDropdown.d.ts +86 -0
  34. package/lib/Components/ThemeDropdown.d.ts.map +1 -0
  35. package/lib/Components/ThemeDropdown.js +207 -0
  36. package/lib/Components/Toast.d.ts +94 -0
  37. package/lib/Components/Toast.d.ts.map +1 -0
  38. package/lib/Components/Toast.js +284 -0
  39. package/lib/Components/Toaster.d.ts +119 -0
  40. package/lib/Components/Toaster.d.ts.map +1 -0
  41. package/lib/Components/Toaster.js +153 -0
  42. package/lib/Components/TypeAhead.d.ts +53 -0
  43. package/lib/Components/TypeAhead.d.ts.map +1 -0
  44. package/lib/Components/TypeAhead.js +138 -0
  45. package/lib/Context.d.ts +38 -0
  46. package/lib/Context.d.ts.map +1 -0
  47. package/lib/Context.js +42 -0
  48. package/lib/DialogResult.d.ts +30 -0
  49. package/lib/DialogResult.d.ts.map +1 -0
  50. package/lib/DialogResult.js +29 -0
  51. package/lib/File.d.ts +25 -0
  52. package/lib/File.d.ts.map +1 -0
  53. package/lib/File.js +66 -0
  54. package/lib/Form.d.ts +33 -0
  55. package/lib/Form.d.ts.map +1 -0
  56. package/lib/Form.js +50 -0
  57. package/lib/Htmx.d.ts +12 -0
  58. package/lib/Htmx.d.ts.map +1 -0
  59. package/lib/Htmx.js +2 -0
  60. package/lib/KeyboardModifiers.d.ts +26 -0
  61. package/lib/KeyboardModifiers.d.ts.map +1 -0
  62. package/lib/KeyboardModifiers.js +25 -0
  63. package/lib/Position.d.ts +52 -0
  64. package/lib/Position.d.ts.map +1 -0
  65. package/lib/Position.js +59 -0
  66. package/lib/Size.d.ts +40 -0
  67. package/lib/Size.d.ts.map +1 -0
  68. package/lib/Size.js +44 -0
  69. package/lib/StorageArea.d.ts +18 -0
  70. package/lib/StorageArea.d.ts.map +1 -0
  71. package/lib/StorageArea.js +13 -0
  72. package/lib/Tags.d.ts +15 -0
  73. package/lib/Tags.d.ts.map +1 -0
  74. package/lib/Tags.js +48 -0
  75. package/lib/Variant.d.ts +36 -0
  76. package/lib/Variant.d.ts.map +1 -0
  77. package/lib/Variant.js +31 -0
  78. package/lib/ViewportScroller.d.ts +49 -0
  79. package/lib/ViewportScroller.d.ts.map +1 -0
  80. package/lib/ViewportScroller.js +69 -0
  81. package/package.json +58 -0
  82. package/src/Client/Alignment.ts +25 -0
  83. package/src/Client/AppTheme.ts +51 -0
  84. package/src/Client/Components/BackButton.ts +45 -0
  85. package/src/Client/Components/DialogBox.ts +344 -0
  86. package/src/Client/Components/FullScreenToggler.ts +122 -0
  87. package/src/Client/Components/KeyboardAccelerator.ts +97 -0
  88. package/src/Client/Components/LoadingIndicator.ts +113 -0
  89. package/src/Client/Components/MenuActivator.ts +58 -0
  90. package/src/Client/Components/OfflineIndicator.ts +125 -0
  91. package/src/Client/Components/TabActivator.ts +93 -0
  92. package/src/Client/Components/ThemeDropdown.ts +235 -0
  93. package/src/Client/Components/Toast.ts +319 -0
  94. package/src/Client/Components/Toaster.ts +224 -0
  95. package/src/Client/Components/TypeAhead.ts +153 -0
  96. package/src/Client/Context.ts +53 -0
  97. package/src/Client/DialogResult.ts +35 -0
  98. package/src/Client/File.ts +73 -0
  99. package/src/Client/Form.ts +55 -0
  100. package/src/Client/Htmx.ts +13 -0
  101. package/src/Client/KeyboardModifiers.ts +30 -0
  102. package/src/Client/Position.ts +74 -0
  103. package/src/Client/Size.ts +56 -0
  104. package/src/Client/StorageArea.ts +20 -0
  105. package/src/Client/Tags.ts +58 -0
  106. package/src/Client/Variant.ts +42 -0
  107. package/src/Client/ViewportScroller.ts +89 -0
  108. package/src/Client/tsconfig.json +19 -0
package/License.md ADDED
@@ -0,0 +1,20 @@
1
+ # MIT License
2
+ Copyright © Cédric Belin
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/ReadMe.md ADDED
@@ -0,0 +1,17 @@
1
+ # Belin UI
2
+ Component library by [Cédric Belin](https://cedric-belin.fr), full stack developer,
3
+ implemented in [C#](https://learn.microsoft.com/en-us/dotnet/csharp) and [TypeScript](https://www.typescriptlang.org).
4
+
5
+ > This library is dedicated to personal/side projects.
6
+ > **Use at your own risk!** No support will be provided.
7
+
8
+ ## Documentation
9
+ - [User guide](https://github.com/cedx/ui/tree/main/docs)
10
+ - [Examples](https://github.com/cedx/ui/tree/main/example)
11
+
12
+ ## Development
13
+ - [Git repository](https://github.com/cedx/ui)
14
+ - [Submit an issue](https://github.com/cedx/ui/issues)
15
+
16
+ ## Licence
17
+ [Belin UI](https://github.com/cedx/ui) is distributed under the MIT License.
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Defines the alignment of a component.
3
+ */
4
+ export declare const Alignment: Readonly<{
5
+ /**
6
+ * The element is aligned at the start.
7
+ */
8
+ Start: "Start";
9
+ /**
10
+ * The element is aligned in the center.
11
+ */
12
+ Center: "Center";
13
+ /**
14
+ * The element is aligned at the end.
15
+ */
16
+ End: "End";
17
+ }>;
18
+ /**
19
+ * Defines the alignment of a component.
20
+ */
21
+ export type Alignment = typeof Alignment[keyof typeof Alignment];
22
+ //# sourceMappingURL=Alignment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Alignment.d.ts","sourceRoot":"","sources":["../src/Client/Alignment.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,SAAS;IAErB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Defines the alignment of a component.
3
+ */
4
+ export const Alignment = Object.freeze({
5
+ /**
6
+ * The element is aligned at the start.
7
+ */
8
+ Start: "Start",
9
+ /**
10
+ * The element is aligned in the center.
11
+ */
12
+ Center: "Center",
13
+ /**
14
+ * The element is aligned at the end.
15
+ */
16
+ End: "End"
17
+ });
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Enumerates different themes an operating system or application can show.
3
+ */
4
+ export declare const AppTheme: Readonly<{
5
+ /**
6
+ * The system theme.
7
+ */
8
+ System: "System";
9
+ /**
10
+ * The light theme.
11
+ */
12
+ Light: "Light";
13
+ /**
14
+ * The dark theme.
15
+ */
16
+ Dark: "Dark";
17
+ }>;
18
+ /**
19
+ * Enumerates different themes an operating system or application can show.
20
+ */
21
+ export type AppTheme = typeof AppTheme[keyof typeof AppTheme];
22
+ /**
23
+ * Gets the icon corresponding to the specified theme.
24
+ * @param theme The application theme.
25
+ * @returns The icon corresponding to the specified theme.
26
+ */
27
+ export declare function icon(theme: AppTheme): string;
28
+ /**
29
+ * Gets the label corresponding to the specified theme.
30
+ * @param theme The application theme.
31
+ * @returns The label corresponding to the specified theme.
32
+ */
33
+ export declare function label(theme: AppTheme): string;
34
+ //# sourceMappingURL=AppTheme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AppTheme.d.ts","sourceRoot":"","sources":["../src/Client/AppTheme.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,QAAQ;IAEpB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAE9D;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAM5C;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAM7C"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Enumerates different themes an operating system or application can show.
3
+ */
4
+ export const AppTheme = Object.freeze({
5
+ /**
6
+ * The system theme.
7
+ */
8
+ System: "System",
9
+ /**
10
+ * The light theme.
11
+ */
12
+ Light: "Light",
13
+ /**
14
+ * The dark theme.
15
+ */
16
+ Dark: "Dark"
17
+ });
18
+ /**
19
+ * Gets the icon corresponding to the specified theme.
20
+ * @param theme The application theme.
21
+ * @returns The icon corresponding to the specified theme.
22
+ */
23
+ export function icon(theme) {
24
+ switch (theme) {
25
+ case AppTheme.Dark: return "dark_mode";
26
+ case AppTheme.Light: return "light_mode";
27
+ default: return "contrast";
28
+ }
29
+ }
30
+ /**
31
+ * Gets the label corresponding to the specified theme.
32
+ * @param theme The application theme.
33
+ * @returns The label corresponding to the specified theme.
34
+ */
35
+ export function label(theme) {
36
+ switch (theme) {
37
+ case AppTheme.Dark: return "Sombre";
38
+ case AppTheme.Light: return "Clair";
39
+ default: return "Auto";
40
+ }
41
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * A component that moves back in the session history when clicked.
3
+ */
4
+ export declare class BackButton extends HTMLElement {
5
+ /**
6
+ * The number of pages to go back.
7
+ */
8
+ get steps(): number;
9
+ set steps(value: number);
10
+ /**
11
+ * Moves back in the session history.
12
+ * @param event The dispatched event.
13
+ */
14
+ goBack(event?: Event): void;
15
+ }
16
+ /**
17
+ * Declaration merging.
18
+ */
19
+ declare global {
20
+ /**
21
+ * The map of HTML tag names.
22
+ */
23
+ interface HTMLElementTagNameMap {
24
+ "back-button": BackButton;
25
+ }
26
+ }
27
+ //# sourceMappingURL=BackButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BackButton.d.ts","sourceRoot":"","sources":["../../src/Client/Components/BackButton.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,UAAW,SAAQ,WAAW;IAS1C;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAGlB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAEtB;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI;CAI3B;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,aAAa,EAAE,UAAU,CAAC;KAC1B;CACD"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * A component that moves back in the session history when clicked.
3
+ */
4
+ export class BackButton extends HTMLElement {
5
+ /**
6
+ * Registers the component.
7
+ */
8
+ static {
9
+ customElements.define("back-button", this);
10
+ }
11
+ /**
12
+ * The number of pages to go back.
13
+ */
14
+ get steps() {
15
+ const value = Number(this.getAttribute("steps"));
16
+ return Math.max(0, Number.isNaN(value) ? 1 : value);
17
+ }
18
+ set steps(value) {
19
+ this.setAttribute("steps", value.toString());
20
+ }
21
+ /**
22
+ * Moves back in the session history.
23
+ * @param event The dispatched event.
24
+ */
25
+ goBack(event) {
26
+ event?.preventDefault();
27
+ history.go(-this.steps);
28
+ }
29
+ }
@@ -0,0 +1,151 @@
1
+ import { type Context } from "../Context.js";
2
+ import { Variant } from "../Variant.js";
3
+ /**
4
+ * Represents a dialog box button.
5
+ */
6
+ export interface IDialogButton {
7
+ /**
8
+ * The button icon.
9
+ */
10
+ icon?: string;
11
+ /**
12
+ * The button label.
13
+ */
14
+ label?: string;
15
+ /**
16
+ * The button value.
17
+ */
18
+ value?: string;
19
+ /**
20
+ * A tone variant.
21
+ */
22
+ variant?: Variant;
23
+ }
24
+ /**
25
+ * Represents a message to display in a dialog box.
26
+ */
27
+ export interface IDialogMessage {
28
+ /**
29
+ * The child content displayed in the body.
30
+ */
31
+ body: DocumentFragment;
32
+ /**
33
+ * The title displayed in the header.
34
+ */
35
+ caption: string;
36
+ /**
37
+ * The child content displayed in the footer.
38
+ */
39
+ footer?: DocumentFragment;
40
+ }
41
+ /**
42
+ * Displays a dialog box, which presents a message to the user.
43
+ */
44
+ export declare class DialogBox extends HTMLElement {
45
+ #private;
46
+ /**
47
+ * The list of observed attributes.
48
+ */
49
+ static readonly observedAttributes: string[];
50
+ /**
51
+ * Creates a new dialog box.
52
+ */
53
+ constructor();
54
+ /**
55
+ * The child content displayed in the body.
56
+ */
57
+ set body(value: DocumentFragment);
58
+ /**
59
+ * The title displayed in the header.
60
+ */
61
+ get caption(): string;
62
+ set caption(value: string);
63
+ /**
64
+ * Value indicating whether to vertically center this dialog box.
65
+ */
66
+ get centered(): boolean;
67
+ set centered(value: boolean);
68
+ /**
69
+ * Value indicating whether to apply a transition.
70
+ */
71
+ get fade(): boolean;
72
+ set fade(value: boolean);
73
+ /**
74
+ * The child content displayed in the footer.
75
+ */
76
+ set footer(value: DocumentFragment);
77
+ /**
78
+ * Value indicating whether to this dialog box will not close when clicking outside of it.
79
+ */
80
+ get modal(): boolean;
81
+ set modal(value: boolean);
82
+ /**
83
+ * Value indicating whether to initially show this component.
84
+ */
85
+ get open(): boolean;
86
+ set open(value: boolean);
87
+ /**
88
+ * The dialog result.
89
+ */
90
+ get result(): string;
91
+ /**
92
+ * Value indicating whether the body is scrollable.
93
+ */
94
+ get scrollable(): boolean;
95
+ set scrollable(value: boolean);
96
+ /**
97
+ * Method invoked when an attribute has been changed.
98
+ * @param attribute The attribute name.
99
+ * @param oldValue The previous attribute value.
100
+ * @param newValue The new attribute value.
101
+ */
102
+ attributeChangedCallback(attribute: string, oldValue: string | null, newValue: string | null): void;
103
+ /**
104
+ * Shows an alert message with an "OK" button by default.
105
+ * @param context The contextual modifier.
106
+ * @param caption The title displayed in the header.
107
+ * @param message The child content displayed in the body.
108
+ * @param buttons The buttons displayed in the footer.
109
+ * @returns The dialog result.
110
+ */
111
+ alert(context: Context, caption: string, message: DocumentFragment, buttons?: IDialogButton[]): Promise<string>;
112
+ /**
113
+ * Closes this dialog box.
114
+ * @param result The dialog result.
115
+ */
116
+ close(result?: string): void;
117
+ /**
118
+ * Shows a confirmation message with two buttons, "OK" and "Cancel".
119
+ * @param context The contextual modifier.
120
+ * @param caption The title displayed in the header.
121
+ * @param message The child content displayed in the body.
122
+ * @returns The dialog result.
123
+ */
124
+ confirm(context: Context, caption: string, message: DocumentFragment): Promise<string>;
125
+ /**
126
+ * Method invoked when this component is connected.
127
+ */
128
+ connectedCallback(): void;
129
+ /**
130
+ * Method invoked when this component is disconnected.
131
+ */
132
+ disconnectedCallback(): void;
133
+ /**
134
+ * Shows a message.
135
+ * @param message The message to show.
136
+ * @returns The dialog result.
137
+ */
138
+ show(message?: IDialogMessage | null): Promise<string>;
139
+ }
140
+ /**
141
+ * Declaration merging.
142
+ */
143
+ declare global {
144
+ /**
145
+ * The map of HTML tag names.
146
+ */
147
+ interface HTMLElementTagNameMap {
148
+ "dialog-box": DialogBox;
149
+ }
150
+ }
151
+ //# sourceMappingURL=DialogBox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DialogBox.d.ts","sourceRoot":"","sources":["../../src/Client/Components/DialogBox.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,OAAO,EAAmD,MAAM,eAAe,CAAC;AAG7F,OAAO,EAAC,OAAO,EAA8B,MAAM,eAAe,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,aAAa;IAE7B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAE9B;;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;IAiB5F;;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,MAAM,IAAI,MAAM,CAEnB;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;;;;;;;OAOG;IACH,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,GAAE,aAAa,EAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBnH;;;OAGG;IACH,KAAK,CAAC,MAAM,GAAE,MAA0B,GAAG,IAAI;IAK/C;;;;;;OAMG;IACH,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC;IAOtF;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAKzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAI5B;;;;OAIG;IACH,IAAI,CAAC,OAAO,GAAE,cAAc,GAAC,IAAW,GAAG,OAAO,CAAC,MAAM,CAAC;CAgE1D;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,YAAY,EAAE,SAAS,CAAC;KACxB;CACD"}
@@ -0,0 +1,268 @@
1
+ import { Modal } from "bootstrap";
2
+ import { cssClass as contextCssClass, icon as contextIcon } from "../Context.js";
3
+ import { DialogResult } from "../DialogResult.js";
4
+ import { html } from "../Tags.js";
5
+ import { Variant, cssClass as variantCssClass } from "../Variant.js";
6
+ /**
7
+ * Displays a dialog box, which presents a message to the user.
8
+ */
9
+ export class DialogBox extends HTMLElement {
10
+ /**
11
+ * The list of observed attributes.
12
+ */
13
+ static observedAttributes = ["caption", "centered", "fade", "modal", "scrollable"];
14
+ /**
15
+ * The underlying Bootstrap modal.
16
+ */
17
+ #modal;
18
+ /**
19
+ * The function invoked to resolve the dialog result.
20
+ */
21
+ #resolve;
22
+ /**
23
+ * The promise providing the dialog result.
24
+ */
25
+ #result = DialogResult.None;
26
+ /**
27
+ * Creates a new dialog box.
28
+ */
29
+ constructor() {
30
+ super();
31
+ this.firstElementChild.addEventListener("hide.bs.modal", () => this.#resolve(this.#result));
32
+ this.querySelector(".btn-close").addEventListener("click", this.#close);
33
+ for (const button of this.querySelectorAll(".modal-footer button"))
34
+ button.addEventListener("click", this.#close);
35
+ }
36
+ /**
37
+ * Registers the component.
38
+ */
39
+ static {
40
+ customElements.define("dialog-box", this);
41
+ }
42
+ /**
43
+ * The child content displayed in the body.
44
+ */
45
+ set body(value) {
46
+ this.querySelector(".modal-body").replaceChildren(...value.childNodes);
47
+ }
48
+ /**
49
+ * The title displayed in the header.
50
+ */
51
+ get caption() {
52
+ return (this.getAttribute("caption") ?? "").trim();
53
+ }
54
+ set caption(value) {
55
+ this.setAttribute("caption", value);
56
+ }
57
+ /**
58
+ * Value indicating whether to vertically center this dialog box.
59
+ */
60
+ get centered() {
61
+ return this.hasAttribute("centered");
62
+ }
63
+ set centered(value) {
64
+ this.toggleAttribute("centered", value);
65
+ }
66
+ /**
67
+ * Value indicating whether to apply a transition.
68
+ */
69
+ get fade() {
70
+ return this.hasAttribute("fade");
71
+ }
72
+ set fade(value) {
73
+ this.toggleAttribute("fade", value);
74
+ }
75
+ /**
76
+ * The child content displayed in the footer.
77
+ */
78
+ set footer(value) {
79
+ const footer = this.querySelector(".modal-footer");
80
+ footer.hidden = !value.hasChildNodes();
81
+ footer.replaceChildren(...value.childNodes);
82
+ }
83
+ /**
84
+ * Value indicating whether to this dialog box will not close when clicking outside of it.
85
+ */
86
+ get modal() {
87
+ return this.hasAttribute("modal");
88
+ }
89
+ set modal(value) {
90
+ this.toggleAttribute("modal", value);
91
+ }
92
+ /**
93
+ * Value indicating whether to initially show this component.
94
+ */
95
+ get open() {
96
+ return this.hasAttribute("open");
97
+ }
98
+ set open(value) {
99
+ this.toggleAttribute("open", value);
100
+ }
101
+ /**
102
+ * The dialog result.
103
+ */
104
+ get result() {
105
+ return this.#result;
106
+ }
107
+ /**
108
+ * Value indicating whether the body is scrollable.
109
+ */
110
+ get scrollable() {
111
+ return this.hasAttribute("scrollable");
112
+ }
113
+ set scrollable(value) {
114
+ this.toggleAttribute("scrollable", value);
115
+ }
116
+ /**
117
+ * Method invoked when an attribute has been changed.
118
+ * @param attribute The attribute name.
119
+ * @param oldValue The previous attribute value.
120
+ * @param newValue The new attribute value.
121
+ */
122
+ attributeChangedCallback(attribute, oldValue, newValue) {
123
+ if (newValue != oldValue)
124
+ switch (attribute) {
125
+ case "caption":
126
+ this.#updateCaption(newValue ?? "");
127
+ break;
128
+ case "centered":
129
+ this.#updateCentered(newValue != null);
130
+ break;
131
+ case "fade":
132
+ this.#updateFade(newValue != null);
133
+ break;
134
+ case "modal":
135
+ this.#updateModal(newValue != null);
136
+ break;
137
+ case "scrollable":
138
+ this.#updateScrollable(newValue != null);
139
+ break;
140
+ // No default
141
+ }
142
+ }
143
+ /**
144
+ * Shows an alert message with an "OK" button by default.
145
+ * @param context The contextual modifier.
146
+ * @param caption The title displayed in the header.
147
+ * @param message The child content displayed in the body.
148
+ * @param buttons The buttons displayed in the footer.
149
+ * @returns The dialog result.
150
+ */
151
+ alert(context, caption, message, buttons = []) {
152
+ return this.show({
153
+ caption,
154
+ body: html `
155
+ <div class="d-flex gap-2">
156
+ <i class="icon icon-fill fs-1 text-${contextCssClass(context)}"> ${contextIcon(context)}</i>
157
+ <div class="flex-grow-1">${message}</div>
158
+ </div>
159
+ `,
160
+ footer: html `
161
+ ${(buttons.length ? buttons : [{ label: "OK", value: DialogResult.OK, variant: Variant.Primary }]).map(button => html `
162
+ <button class="btn btn-${variantCssClass(button.variant ?? Variant.Primary)}" type="button" value="${button.value ?? DialogResult.None}">
163
+ ${button.icon ? html `<i class="icon ${button.label ? "me-1" : ""}">${button.icon}</i>` : ""}
164
+ ${button.label}
165
+ </button>
166
+ `)}
167
+ `
168
+ });
169
+ }
170
+ /**
171
+ * Closes this dialog box.
172
+ * @param result The dialog result.
173
+ */
174
+ close(result = DialogResult.None) {
175
+ this.#result = result;
176
+ this.#modal.hide();
177
+ }
178
+ /**
179
+ * Shows a confirmation message with two buttons, "OK" and "Cancel".
180
+ * @param context The contextual modifier.
181
+ * @param caption The title displayed in the header.
182
+ * @param message The child content displayed in the body.
183
+ * @returns The dialog result.
184
+ */
185
+ confirm(context, caption, message) {
186
+ return this.alert(context, caption, message, [
187
+ { label: "OK", value: DialogResult.OK, variant: Variant.Primary },
188
+ { label: "Annuler", value: DialogResult.Cancel, variant: Variant.Secondary }
189
+ ]);
190
+ }
191
+ /**
192
+ * Method invoked when this component is connected.
193
+ */
194
+ connectedCallback() {
195
+ this.#modal = new Modal(this.firstElementChild);
196
+ if (this.open)
197
+ void this.show();
198
+ }
199
+ /**
200
+ * Method invoked when this component is disconnected.
201
+ */
202
+ disconnectedCallback() {
203
+ this.#modal.dispose();
204
+ }
205
+ /**
206
+ * Shows a message.
207
+ * @param message The message to show.
208
+ * @returns The dialog result.
209
+ */
210
+ show(message = null) {
211
+ if (message) {
212
+ const footer = message.footer ?? document.createDocumentFragment();
213
+ for (const button of footer.querySelectorAll("button"))
214
+ button.addEventListener("click", this.#close);
215
+ this.body = message.body;
216
+ this.caption = message.caption;
217
+ this.footer = footer;
218
+ }
219
+ const { promise, resolve } = Promise.withResolvers();
220
+ this.#resolve = resolve;
221
+ this.#result = DialogResult.None;
222
+ this.#modal.show();
223
+ return promise;
224
+ }
225
+ /**
226
+ * Closes this dialog box.
227
+ * @param event The dispatched event.
228
+ */
229
+ #close = event => {
230
+ event.preventDefault();
231
+ this.close(event.currentTarget.value);
232
+ };
233
+ /**
234
+ * Updates the title displayed in the header.
235
+ * @param value The new value.
236
+ */
237
+ #updateCaption(value) {
238
+ this.querySelector(".modal-title").textContent = value.trim();
239
+ }
240
+ /**
241
+ * Updates the value indicating whether to vertically center this dialog box.
242
+ * @param value The new value.
243
+ */
244
+ #updateCentered(value) {
245
+ this.querySelector(".modal-dialog").classList.toggle("modal-dialog-centered", value);
246
+ }
247
+ /**
248
+ * Updates the value indicating whether to apply a transition.
249
+ * @param value The new value.
250
+ */
251
+ #updateFade(value) {
252
+ this.firstElementChild.classList.toggle("fade", value);
253
+ }
254
+ /**
255
+ * Updates the value indicating whether to this dialog box will not close when clicking outside of it.
256
+ * @param value The new value.
257
+ */
258
+ #updateModal(value) {
259
+ this.firstElementChild.dataset.bsBackdrop = value ? "static" : "true";
260
+ }
261
+ /**
262
+ * Updates the value indicating whether the body is scrollable.
263
+ * @param value The new value.
264
+ */
265
+ #updateScrollable(value) {
266
+ this.querySelector(".modal-dialog").classList.toggle("modal-dialog-scrollable", value);
267
+ }
268
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * A component for toggling an element to full-screen.
3
+ */
4
+ export declare class FullScreenToggler extends HTMLElement {
5
+ #private;
6
+ /**
7
+ * The CSS selector specifying the target element.
8
+ */
9
+ get target(): string;
10
+ set target(value: string);
11
+ /**
12
+ * Value indicating whether to prevent the device screen from dimming or locking when in full-screen mode.
13
+ */
14
+ get wakeLock(): boolean;
15
+ set wakeLock(value: boolean);
16
+ /**
17
+ * Method invoked when this component is connected.
18
+ */
19
+ connectedCallback(): void;
20
+ /**
21
+ * Method invoked when this component is disconnected.
22
+ */
23
+ disconnectedCallback(): void;
24
+ /**
25
+ * Toggles the full-screen mode of the associated element.
26
+ * @param event The dispatched event.
27
+ * @returns Completes when the full-screen mode has been toggled.
28
+ */
29
+ toggleFullScreen(event?: Event): Promise<void>;
30
+ }
31
+ /**
32
+ * Declaration merging.
33
+ */
34
+ declare global {
35
+ /**
36
+ * The map of HTML tag names.
37
+ */
38
+ interface HTMLElementTagNameMap {
39
+ "fullscreen-toggler": FullScreenToggler;
40
+ }
41
+ }
42
+ //# sourceMappingURL=FullScreenToggler.d.ts.map