@cedx/base 0.20.0 → 0.21.1

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 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.20.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.1/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).
@@ -1,14 +1,10 @@
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 transition.
10
- */
11
- animation?: boolean;
12
8
  /**
13
9
  * The child content displayed in the body.
14
10
  */
@@ -17,45 +13,24 @@ export interface IMessage {
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
19
  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;
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 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);
@@ -115,7 +85,7 @@ export declare class MessageBox extends HTMLElement {
115
85
  */
116
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;
@@ -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,15 +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 { html } from "../Tag.js";
4
5
  import { Variant } from "../Variant.js";
5
6
  /**
6
- * 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.
7
8
  */
8
- export class MessageBox extends HTMLElement {
9
+ export class DialogBox extends HTMLElement {
9
10
  /**
10
11
  * The list of observed attributes.
11
12
  */
12
- static observedAttributes = ["animation", "caption", "centered", "context", "icon", "modal", "scrollable"];
13
+ static observedAttributes = ["caption", "centered", "fade", "modal", "scrollable"];
13
14
  /**
14
15
  * The template for a button.
15
16
  */
@@ -27,7 +28,7 @@ export class MessageBox extends HTMLElement {
27
28
  */
28
29
  #result = DialogResult.None;
29
30
  /**
30
- * Creates a new message box.
31
+ * Creates a new dialog box.
31
32
  */
32
33
  constructor() {
33
34
  super();
@@ -40,22 +41,13 @@ export class MessageBox extends HTMLElement {
40
41
  * Registers the component.
41
42
  */
42
43
  static {
43
- customElements.define("message-box", this);
44
- }
45
- /**
46
- * Value indicating whether to apply a transition.
47
- */
48
- get animation() {
49
- return this.hasAttribute("animation");
50
- }
51
- set animation(value) {
52
- this.toggleAttribute("animation", value);
44
+ customElements.define("dialog-box", this);
53
45
  }
54
46
  /**
55
47
  * The child content displayed in the body.
56
48
  */
57
49
  set body(value) {
58
- this.querySelector(".modal-body > div").replaceChildren(...value.childNodes);
50
+ this.querySelector(".modal-body").replaceChildren(...value.childNodes);
59
51
  }
60
52
  /**
61
53
  * The title displayed in the header.
@@ -67,7 +59,7 @@ export class MessageBox extends HTMLElement {
67
59
  this.setAttribute("caption", value);
68
60
  }
69
61
  /**
70
- * Value indicating whether to vertically center this message box.
62
+ * Value indicating whether to vertically center this dialog box.
71
63
  */
72
64
  get centered() {
73
65
  return this.hasAttribute("centered");
@@ -76,14 +68,13 @@ export class MessageBox extends HTMLElement {
76
68
  this.toggleAttribute("centered", value);
77
69
  }
78
70
  /**
79
- * A contextual modifier.
71
+ * Value indicating whether to apply a transition.
80
72
  */
81
- get context() {
82
- const value = this.getAttribute("context");
83
- return Object.values(Context).includes(value) ? value : Context.Info;
73
+ get fade() {
74
+ return this.hasAttribute("fade");
84
75
  }
85
- set context(value) {
86
- this.setAttribute("context", value);
76
+ set fade(value) {
77
+ this.toggleAttribute("fade", value);
87
78
  }
88
79
  /**
89
80
  * The child content displayed in the footer.
@@ -94,17 +85,7 @@ export class MessageBox extends HTMLElement {
94
85
  footer.replaceChildren(...value.childNodes);
95
86
  }
96
87
  /**
97
- * The icon displayed next to the body.
98
- */
99
- get icon() {
100
- const value = this.getAttribute("icon") ?? "";
101
- return value.trim() || null;
102
- }
103
- set icon(value) {
104
- this.toggleAttribute("icon", Boolean(value));
105
- }
106
- /**
107
- * 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.
108
89
  */
109
90
  get modal() {
110
91
  return this.hasAttribute("modal");
@@ -113,7 +94,7 @@ export class MessageBox extends HTMLElement {
113
94
  this.toggleAttribute("modal", value);
114
95
  }
115
96
  /**
116
- * Value indicating whether to initially show this message box.
97
+ * Value indicating whether to initially show this component.
117
98
  */
118
99
  get open() {
119
100
  return this.hasAttribute("open");
@@ -139,26 +120,20 @@ export class MessageBox extends HTMLElement {
139
120
  attributeChangedCallback(attribute, oldValue, newValue) {
140
121
  if (newValue != oldValue)
141
122
  switch (attribute) {
142
- case "animation":
143
- this.#updateAnimation(newValue != null);
144
- break;
145
123
  case "caption":
146
124
  this.#updateCaption(newValue ?? "");
147
125
  break;
148
126
  case "centered":
149
127
  this.#updateCentered(newValue != null);
150
128
  break;
151
- case "context":
152
- this.#updateContext(Object.values(Context).includes(newValue) ? newValue : Context.Info);
153
- break;
154
- case "icon":
155
- this.#updateIcon(newValue);
156
- break;
157
129
  case "modal":
158
130
  this.#updateModal(newValue != null);
159
131
  break;
132
+ case "fade":
133
+ this.#updateFade(newValue != null);
134
+ break;
160
135
  case "scrollable":
161
- this.#updateScrolling(newValue != null);
136
+ this.#updateScrollable(newValue != null);
162
137
  break;
163
138
  // No default
164
139
  }
@@ -170,13 +145,13 @@ export class MessageBox extends HTMLElement {
170
145
  * @param body The child content displayed in the body.
171
146
  * @returns The dialog box result.
172
147
  */
173
- async alert(context, caption, body) {
174
- return await this.show(context, caption, body, [
148
+ alert(context, caption, body) {
149
+ return this.show(context, caption, this.#getBodyTemplate(context, body), [
175
150
  { label: "OK", value: DialogResult.OK, variant: Variant.Primary }
176
151
  ]);
177
152
  }
178
153
  /**
179
- * Closes this message box.
154
+ * Closes this dialog box.
180
155
  * @param result The dialog box result.
181
156
  */
182
157
  close(result = DialogResult.None) {
@@ -190,8 +165,8 @@ export class MessageBox extends HTMLElement {
190
165
  * @param body The child content displayed in the body.
191
166
  * @returns The dialog box result.
192
167
  */
193
- async confirm(context, caption, body) {
194
- return await this.show(context, caption, body, [
168
+ confirm(context, caption, body) {
169
+ return this.show(context, caption, this.#getBodyTemplate(context, body), [
195
170
  { label: "OK", value: DialogResult.OK, variant: Variant.Primary },
196
171
  { label: "Annuler", value: DialogResult.Cancel, variant: Variant.Secondary }
197
172
  ]);
@@ -222,16 +197,14 @@ export class MessageBox extends HTMLElement {
222
197
  if (typeof message == "string") {
223
198
  const footer = document.createDocumentFragment();
224
199
  footer.append(...buttons.map(button => this.#createButton(button)));
225
- message = { context: message, caption, body, footer };
200
+ message = { body, caption, footer };
226
201
  }
227
- if (typeof message == "object" && message) {
228
- this.body = message.body;
229
- this.caption = message.caption;
230
- this.context = message.context ?? Context.Info;
231
- this.icon = message.icon ?? getIcon(this.context);
202
+ if (message) {
232
203
  const footer = message.footer ?? document.createDocumentFragment();
233
204
  for (const button of footer.querySelectorAll("button"))
234
205
  button.addEventListener("click", this.#close);
206
+ this.body = message.body;
207
+ this.caption = message.caption;
235
208
  this.footer = footer;
236
209
  }
237
210
  const { promise, resolve } = Promise.withResolvers();
@@ -241,7 +214,7 @@ export class MessageBox extends HTMLElement {
241
214
  return promise;
242
215
  }
243
216
  /**
244
- * Closes this message box.
217
+ * Closes this dialog box.
245
218
  * @param event The dispatched event.
246
219
  */
247
220
  #close = event => {
@@ -266,11 +239,18 @@ export class MessageBox extends HTMLElement {
266
239
  return element;
267
240
  }
268
241
  /**
269
- * Updates the message box animation.
270
- * @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.
271
246
  */
272
- #updateAnimation(value) {
273
- 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
+ `;
274
254
  }
275
255
  /**
276
256
  * Updates the title displayed in the header.
@@ -280,40 +260,31 @@ export class MessageBox extends HTMLElement {
280
260
  this.querySelector(".modal-title").textContent = value.trim();
281
261
  }
282
262
  /**
283
- * Updates the value indicating whether to vertically center this message box.
263
+ * Updates the value indicating whether to vertically center this dialog box.
284
264
  * @param value The new value.
285
265
  */
286
266
  #updateCentered(value) {
287
267
  this.querySelector(".modal-dialog").classList.toggle("modal-dialog-centered", value);
288
268
  }
289
269
  /**
290
- * Updates the contextual modifier.
291
- * @param value The new value.
292
- */
293
- #updateContext(value) {
294
- const { classList } = this.querySelector(".modal-body > .icon");
295
- classList.remove(...Object.values(Context).map(context => `text-${toCss(context)}`));
296
- classList.add(`text-${toCss(value)}`);
297
- }
298
- /**
299
- * Updates the icon displayed next to the body.
270
+ * Updates the value indicating whether to apply a transition.
300
271
  * @param value The new value.
301
272
  */
302
- #updateIcon(value) {
303
- this.querySelector(".modal-body > .icon").textContent = (value ?? "").trim() || getIcon(this.context);
273
+ #updateFade(value) {
274
+ this.firstElementChild.classList.toggle("fade", value);
304
275
  }
305
276
  /**
306
- * 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.
307
278
  * @param value The new value.
308
279
  */
309
280
  #updateModal(value) {
310
281
  this.firstElementChild.dataset.bsBackdrop = value ? "static" : "true";
311
282
  }
312
283
  /**
313
- * Updates the body scrolling.
284
+ * Updates the value indicating whether the body is scrollable.
314
285
  * @param value The new value.
315
286
  */
316
- #updateScrolling(value) {
287
+ #updateScrollable(value) {
317
288
  this.querySelector(".modal-dialog").classList.toggle("modal-dialog-scrollable", value);
318
289
  }
319
290
  }
@@ -10,8 +10,13 @@ export declare class LoadingIndicator extends HTMLElement {
10
10
  /**
11
11
  * Value indicating whether to apply a transition.
12
12
  */
13
- get animation(): boolean;
14
- set animation(value: boolean);
13
+ get fade(): boolean;
14
+ set fade(value: boolean);
15
+ /**
16
+ * Value indicating whether to initially show this component.
17
+ */
18
+ get open(): boolean;
19
+ set open(value: boolean);
15
20
  /**
16
21
  * Method invoked when an attribute has been changed.
17
22
  * @param attribute The attribute name.
@@ -20,14 +25,18 @@ export declare class LoadingIndicator extends HTMLElement {
20
25
  */
21
26
  attributeChangedCallback(attribute: string, oldValue: string | null, newValue: string | null): void;
22
27
  /**
23
- * Hides the loading indicator.
28
+ * Method invoked when this component is connected.
29
+ */
30
+ connectedCallback(): void;
31
+ /**
32
+ * Hides this loading indicator.
24
33
  * @param options Value indicating whether to force the loading indicator to hide.
25
34
  */
26
35
  hide(options?: {
27
36
  force?: boolean;
28
37
  }): void;
29
38
  /**
30
- * Shows the loading indicator.
39
+ * Shows this loading indicator.
31
40
  */
32
41
  show(): void;
33
42
  }
@@ -1 +1 @@
1
- {"version":3,"file":"LoadingIndicator.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/LoadingIndicator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,WAAW;;IAEhD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAAiB;IAcnD;;OAEG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IACD,IAAI,SAAS,CAAC,KAAK,EAAE,OAAO,EAE3B;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;IAO/F;;;OAGG;IACH,IAAI,CAAC,OAAO,GAAE;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAM,GAAG,IAAI;IAU3C;;OAEG;IACH,IAAI,IAAI,IAAI;CAcZ;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,mBAAmB,EAAE,gBAAgB,CAAC;KACtC;CACD"}
1
+ {"version":3,"file":"LoadingIndicator.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/LoadingIndicator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,WAAW;;IAEhD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAAY;IAc9C;;OAEG;IACH,IAAI,IAAI,IAAI,OAAO,CAElB;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,OAAO,EAEtB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,OAAO,CAElB;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,OAAO,EAEtB;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;IAO/F;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAIzB;;;OAGG;IACH,IAAI,CAAC,OAAO,GAAE;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAM,GAAG,IAAI;IAU3C;;OAEG;IACH,IAAI,IAAI,IAAI;CAcZ;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,mBAAmB,EAAE,gBAAgB,CAAC;KACtC;CACD"}
@@ -5,7 +5,7 @@ export class LoadingIndicator extends HTMLElement {
5
5
  /**
6
6
  * The list of observed attributes.
7
7
  */
8
- static observedAttributes = ["animation"];
8
+ static observedAttributes = ["fade"];
9
9
  /**
10
10
  * The number of concurrent HTTP requests.
11
11
  */
@@ -19,11 +19,20 @@ export class LoadingIndicator extends HTMLElement {
19
19
  /**
20
20
  * Value indicating whether to apply a transition.
21
21
  */
22
- get animation() {
23
- return this.hasAttribute("animation");
22
+ get fade() {
23
+ return this.hasAttribute("fade");
24
24
  }
25
- set animation(value) {
26
- this.toggleAttribute("animation", value);
25
+ set fade(value) {
26
+ this.toggleAttribute("fade", value);
27
+ }
28
+ /**
29
+ * Value indicating whether to initially show this component.
30
+ */
31
+ get open() {
32
+ return this.hasAttribute("open");
33
+ }
34
+ set open(value) {
35
+ this.toggleAttribute("open", value);
27
36
  }
28
37
  /**
29
38
  * Method invoked when an attribute has been changed.
@@ -34,14 +43,21 @@ export class LoadingIndicator extends HTMLElement {
34
43
  attributeChangedCallback(attribute, oldValue, newValue) {
35
44
  if (newValue != oldValue)
36
45
  switch (attribute) {
37
- case "animation":
38
- this.#updateAnimation(newValue != null);
46
+ case "fade":
47
+ this.#updateFade(newValue != null);
39
48
  break;
40
49
  // No default
41
50
  }
42
51
  }
43
52
  /**
44
- * Hides the loading indicator.
53
+ * Method invoked when this component is connected.
54
+ */
55
+ connectedCallback() {
56
+ if (this.open)
57
+ this.show();
58
+ }
59
+ /**
60
+ * Hides this loading indicator.
45
61
  * @param options Value indicating whether to force the loading indicator to hide.
46
62
  */
47
63
  hide(options = {}) {
@@ -54,7 +70,7 @@ export class LoadingIndicator extends HTMLElement {
54
70
  }
55
71
  }
56
72
  /**
57
- * Shows the loading indicator.
73
+ * Shows this loading indicator.
58
74
  */
59
75
  show() {
60
76
  this.#requestCount++;
@@ -66,7 +82,7 @@ export class LoadingIndicator extends HTMLElement {
66
82
  * Updates the value indicating whether to apply a transition.
67
83
  * @param value The new value.
68
84
  */
69
- #updateAnimation(value) {
85
+ #updateFade(value) {
70
86
  this.classList.toggle("fade", value);
71
87
  }
72
88
  }
@@ -10,8 +10,13 @@ export declare class OfflineIndicator extends HTMLElement {
10
10
  /**
11
11
  * Value indicating whether to apply a transition.
12
12
  */
13
- get animation(): boolean;
14
- set animation(value: boolean);
13
+ get fade(): boolean;
14
+ set fade(value: boolean);
15
+ /**
16
+ * Value indicating whether to initially show this component.
17
+ */
18
+ get open(): boolean;
19
+ set open(value: boolean);
15
20
  /**
16
21
  * Method invoked when an attribute has been changed.
17
22
  * @param attribute The attribute name.
@@ -27,6 +32,14 @@ export declare class OfflineIndicator extends HTMLElement {
27
32
  * Method invoked when this component is disconnected.
28
33
  */
29
34
  disconnectedCallback(): void;
35
+ /**
36
+ * Hides this offline indicator.
37
+ */
38
+ hide(): void;
39
+ /**
40
+ * Shows this offline indicator.
41
+ */
42
+ show(): void;
30
43
  }
31
44
  /**
32
45
  * Declaration merging.
@@ -1 +1 @@
1
- {"version":3,"file":"OfflineIndicator.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/OfflineIndicator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,WAAW;;IAEhD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAAiB;IASnD;;OAEG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IACD,IAAI,SAAS,CAAC,KAAK,EAAE,OAAO,EAE3B;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;IAO/F;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAKzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;CAmB5B;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,mBAAmB,EAAE,gBAAgB,CAAC;KACtC;CACD"}
1
+ {"version":3,"file":"OfflineIndicator.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/OfflineIndicator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,WAAW;;IAEhD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAAY;IAS9C;;OAEG;IACH,IAAI,IAAI,IAAI,OAAO,CAElB;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,OAAO,EAEtB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,OAAO,CAElB;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,OAAO,EAEtB;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;IAO/F;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAMzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAI5B;;OAEG;IACH,IAAI,IAAI,IAAI;IAKZ;;OAEG;IACH,IAAI,IAAI,IAAI;CAoBZ;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,mBAAmB,EAAE,gBAAgB,CAAC;KACtC;CACD"}
@@ -5,7 +5,7 @@ export class OfflineIndicator extends HTMLElement {
5
5
  /**
6
6
  * The list of observed attributes.
7
7
  */
8
- static observedAttributes = ["animation"];
8
+ static observedAttributes = ["fade"];
9
9
  /**
10
10
  * Registers the component.
11
11
  */
@@ -15,11 +15,20 @@ export class OfflineIndicator extends HTMLElement {
15
15
  /**
16
16
  * Value indicating whether to apply a transition.
17
17
  */
18
- get animation() {
19
- return this.hasAttribute("animation");
18
+ get fade() {
19
+ return this.hasAttribute("fade");
20
20
  }
21
- set animation(value) {
22
- this.toggleAttribute("animation", value);
21
+ set fade(value) {
22
+ this.toggleAttribute("fade", value);
23
+ }
24
+ /**
25
+ * Value indicating whether to initially show this component.
26
+ */
27
+ get open() {
28
+ return this.hasAttribute("open");
29
+ }
30
+ set open(value) {
31
+ this.toggleAttribute("open", value);
23
32
  }
24
33
  /**
25
34
  * Method invoked when an attribute has been changed.
@@ -30,8 +39,8 @@ export class OfflineIndicator extends HTMLElement {
30
39
  attributeChangedCallback(attribute, oldValue, newValue) {
31
40
  if (newValue != oldValue)
32
41
  switch (attribute) {
33
- case "animation":
34
- this.#updateAnimation(newValue != null);
42
+ case "fade":
43
+ this.#updateFade(newValue != null);
35
44
  break;
36
45
  // No default
37
46
  }
@@ -40,29 +49,48 @@ export class OfflineIndicator extends HTMLElement {
40
49
  * Method invoked when this component is connected.
41
50
  */
42
51
  connectedCallback() {
43
- this.#update();
44
52
  for (const event of ["online", "offline"])
45
- addEventListener(event, this.#update);
53
+ addEventListener(event, this.#updateVisibility);
54
+ if (this.open)
55
+ this.show();
56
+ else
57
+ this.#updateVisibility();
46
58
  }
47
59
  /**
48
60
  * Method invoked when this component is disconnected.
49
61
  */
50
62
  disconnectedCallback() {
51
63
  for (const event of ["online", "offline"])
52
- removeEventListener(event, this.#update);
64
+ removeEventListener(event, this.#updateVisibility);
65
+ }
66
+ /**
67
+ * Hides this offline indicator.
68
+ */
69
+ hide() {
70
+ this.classList.remove("show");
71
+ this.classList.add("hide");
72
+ }
73
+ /**
74
+ * Shows this offline indicator.
75
+ */
76
+ show() {
77
+ this.classList.remove("hide");
78
+ this.classList.add("show");
53
79
  }
54
80
  /**
55
81
  * Updates the value indicating whether to apply a transition.
56
82
  * @param value The new value.
57
83
  */
58
- #updateAnimation(value) {
84
+ #updateFade(value) {
59
85
  this.classList.toggle("fade", value);
60
86
  }
61
87
  /**
62
- * Updates this component.
88
+ * Updates the visibility of this component.
63
89
  */
64
- #update = () => {
65
- this.classList.toggle("hide", navigator.onLine);
66
- this.classList.toggle("show", !navigator.onLine);
90
+ #updateVisibility = () => {
91
+ if (navigator.onLine)
92
+ this.hide();
93
+ else
94
+ this.show();
67
95
  };
68
96
  }