@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.
@@ -6,7 +6,7 @@ export class OfflineIndicator extends HTMLElement {
6
6
  /**
7
7
  * The list of observed attributes.
8
8
  */
9
- static readonly observedAttributes = ["animation"];
9
+ static readonly observedAttributes = ["fade"];
10
10
 
11
11
  /**
12
12
  * Registers the component.
@@ -18,11 +18,21 @@ export class OfflineIndicator extends HTMLElement {
18
18
  /**
19
19
  * Value indicating whether to apply a transition.
20
20
  */
21
- get animation(): boolean {
22
- return this.hasAttribute("animation");
21
+ get fade(): boolean {
22
+ return this.hasAttribute("fade");
23
23
  }
24
- set animation(value: boolean) {
25
- this.toggleAttribute("animation", value);
24
+ set fade(value: boolean) {
25
+ this.toggleAttribute("fade", value);
26
+ }
27
+
28
+ /**
29
+ * Value indicating whether to initially show this component.
30
+ */
31
+ get open(): boolean {
32
+ return this.hasAttribute("open");
33
+ }
34
+ set open(value: boolean) {
35
+ this.toggleAttribute("open", value);
26
36
  }
27
37
 
28
38
  /**
@@ -33,7 +43,7 @@ export class OfflineIndicator extends HTMLElement {
33
43
  */
34
44
  attributeChangedCallback(attribute: string, oldValue: string|null, newValue: string|null): void {
35
45
  if (newValue != oldValue) switch (attribute) {
36
- case "animation": this.#updateAnimation(newValue != null); break;
46
+ case "fade": this.#updateFade(newValue != null); break;
37
47
  // No default
38
48
  }
39
49
  }
@@ -42,31 +52,48 @@ export class OfflineIndicator extends HTMLElement {
42
52
  * Method invoked when this component is connected.
43
53
  */
44
54
  connectedCallback(): void {
45
- this.#update();
46
- for (const event of ["online", "offline"]) addEventListener(event, this.#update);
55
+ for (const event of ["online", "offline"]) addEventListener(event, this.#updateVisibility);
56
+ if (this.open) this.show();
57
+ else this.#updateVisibility();
47
58
  }
48
59
 
49
60
  /**
50
61
  * Method invoked when this component is disconnected.
51
62
  */
52
63
  disconnectedCallback(): void {
53
- for (const event of ["online", "offline"]) removeEventListener(event, this.#update);
64
+ for (const event of ["online", "offline"]) removeEventListener(event, this.#updateVisibility);
65
+ }
66
+
67
+ /**
68
+ * Hides this offline indicator.
69
+ */
70
+ hide(): void {
71
+ this.classList.remove("show");
72
+ this.classList.add("hide");
73
+ }
74
+
75
+ /**
76
+ * Shows this offline indicator.
77
+ */
78
+ show(): void {
79
+ this.classList.remove("hide");
80
+ this.classList.add("show");
54
81
  }
55
82
 
56
83
  /**
57
84
  * Updates the value indicating whether to apply a transition.
58
85
  * @param value The new value.
59
86
  */
60
- #updateAnimation(value: boolean): void {
87
+ #updateFade(value: boolean): void {
61
88
  this.classList.toggle("fade", value);
62
89
  }
63
90
 
64
91
  /**
65
- * Updates this component.
92
+ * Updates the visibility of this component.
66
93
  */
67
- readonly #update: () => void = () => {
68
- this.classList.toggle("hide", navigator.onLine);
69
- this.classList.toggle("show", !navigator.onLine);
94
+ readonly #updateVisibility: () => void = () => {
95
+ if (navigator.onLine) this.hide();
96
+ else this.show();
70
97
  }
71
98
  }
72
99
 
@@ -6,11 +6,6 @@ import {Context, getIcon, toCss} from "../Context.js";
6
6
  */
7
7
  export interface IToast {
8
8
 
9
- /**
10
- * Value indicating whether to apply a transition.
11
- */
12
- animation?: boolean;
13
-
14
9
  /**
15
10
  * Value indicating whether to automatically hide the toast.
16
11
  */
@@ -41,6 +36,11 @@ export interface IToast {
41
36
  */
42
37
  delay?: number;
43
38
 
39
+ /**
40
+ * Value indicating whether to apply a transition.
41
+ */
42
+ fade?: boolean;
43
+
44
44
  /**
45
45
  * The icon displayed next to the caption.
46
46
  */
@@ -55,7 +55,7 @@ export class Toast extends HTMLElement {
55
55
  /**
56
56
  * The list of observed attributes.
57
57
  */
58
- static readonly observedAttributes = ["animation", "autohide", "caption", "context", "culture", "delay", "icon"];
58
+ static readonly observedAttributes = ["autohide", "caption", "context", "culture", "delay", "fade", "icon"];
59
59
 
60
60
  /**
61
61
  * The time units.
@@ -89,16 +89,6 @@ export class Toast extends HTMLElement {
89
89
  customElements.define("toaster-item", this);
90
90
  }
91
91
 
92
- /**
93
- * Value indicating whether to apply a transition.
94
- */
95
- get animation(): boolean {
96
- return this.hasAttribute("animation");
97
- }
98
- set animation(value: boolean) {
99
- this.toggleAttribute("animation", value);
100
- }
101
-
102
92
  /**
103
93
  * Value indicating whether to automatically hide this toast.
104
94
  */
@@ -166,6 +156,16 @@ export class Toast extends HTMLElement {
166
156
  return Date.now() - this.#initialTime;
167
157
  }
168
158
 
159
+ /**
160
+ * Value indicating whether to apply a transition.
161
+ */
162
+ get fade(): boolean {
163
+ return this.hasAttribute("fade");
164
+ }
165
+ set fade(value: boolean) {
166
+ this.toggleAttribute("fade", value);
167
+ }
168
+
169
169
  /**
170
170
  * The icon displayed next to the caption.
171
171
  */
@@ -179,7 +179,7 @@ export class Toast extends HTMLElement {
179
179
  }
180
180
 
181
181
  /**
182
- * Value indicating whether to initially show this toast.
182
+ * Value indicating whether to initially show this component.
183
183
  */
184
184
  get open(): boolean {
185
185
  return this.hasAttribute("open");
@@ -196,12 +196,12 @@ export class Toast extends HTMLElement {
196
196
  */
197
197
  attributeChangedCallback(attribute: string, oldValue: string|null, newValue: string|null): void {
198
198
  if (newValue != oldValue) switch (attribute) {
199
- case "animation": this.#updateAnimation(newValue != null); break;
200
199
  case "autohide": this.#updateAutoHide(newValue != null); break;
201
200
  case "caption": this.#updateCaption(newValue ?? ""); break;
202
201
  case "context": this.#updateContext(Object.values(Context).includes(newValue as Context) ? newValue as Context : Context.Info); break;
203
202
  case "culture": this.#formatter = new Intl.RelativeTimeFormat((newValue ?? "").trim() || navigator.language, {style: "long"}); break;
204
203
  case "delay": this.#updateDelay(Number(newValue)); break;
204
+ case "fade": this.#updateFade(newValue != null); break;
205
205
  case "icon": this.#updateIcon(newValue); break;
206
206
  // No default
207
207
  }
@@ -261,14 +261,6 @@ export class Toast extends HTMLElement {
261
261
  return this.#formatter.format(Math.ceil(-elapsed), Toast.#timeUnits[index]);
262
262
  }
263
263
 
264
- /**
265
- * Updates the value indicating whether to apply a transition.
266
- * @param value The new value.
267
- */
268
- #updateAnimation(value: boolean): void {
269
- (this.firstElementChild! as HTMLElement).dataset.bsAnimation = value ? "true" : "false";
270
- }
271
-
272
264
  /**
273
265
  * Updates the value indicating whether to automatically hide this toast.
274
266
  * @param value The new value.
@@ -318,6 +310,14 @@ export class Toast extends HTMLElement {
318
310
  this.querySelector(".toast-header small")!.textContent = elapsedTime > 0 ? this.#formatTime(elapsedTime / 1_000) : "";
319
311
  };
320
312
 
313
+ /**
314
+ * Updates the value indicating whether to apply a transition.
315
+ * @param value The new value.
316
+ */
317
+ #updateFade(value: boolean): void {
318
+ (this.firstElementChild! as HTMLElement).dataset.bsAnimation = value ? "true" : "false";
319
+ }
320
+
321
321
  /**
322
322
  * Updates the icon displayed next to the caption.
323
323
  * @param value The new value.
@@ -32,16 +32,6 @@ export class Toaster extends HTMLElement {
32
32
  customElements.define("toaster-container", this);
33
33
  }
34
34
 
35
- /**
36
- * Value indicating whether to apply a transition.
37
- */
38
- get animation(): boolean {
39
- return this.hasAttribute("animation");
40
- }
41
- set animation(value: boolean) {
42
- this.toggleAttribute("animation", value);
43
- }
44
-
45
35
  /**
46
36
  * Value indicating whether to automatically hide the toasts.
47
37
  */
@@ -85,6 +75,16 @@ export class Toaster extends HTMLElement {
85
75
  this.setAttribute("delay", value.toString());
86
76
  }
87
77
 
78
+ /**
79
+ * Value indicating whether to apply a transition.
80
+ */
81
+ get fade(): boolean {
82
+ return this.hasAttribute("fade");
83
+ }
84
+ set fade(value: boolean) {
85
+ this.toggleAttribute("fade", value);
86
+ }
87
+
88
88
  /**
89
89
  * The default icon displayed next to the captions.
90
90
  */
@@ -149,13 +149,13 @@ export class Toaster extends HTMLElement {
149
149
  childContent.addEventListener("hidden.bs.toast", () => item.remove());
150
150
  item.appendChild(childContent);
151
151
 
152
- item.animation = toast.animation ?? this.animation;
153
152
  item.autoHide = toast.autoHide ?? this.autoHide;
154
153
  item.body = toast.body;
155
154
  item.caption = toast.caption;
156
155
  item.context = toast.context ?? this.context;
157
156
  item.culture = toast.culture ?? this.culture;
158
157
  item.delay = toast.delay ?? this.delay;
158
+ item.fade = toast.fade ?? this.fade;
159
159
  item.icon = toast.icon ?? this.icon;
160
160
 
161
161
  this.firstElementChild!.appendChild(item);
@@ -33,7 +33,8 @@ export function html(fragments: TemplateStringsArray, ...values: unknown[]): Doc
33
33
  * @returns The CSS string corresponding to the specified value.
34
34
  */
35
35
  function stringFromCss(value: unknown): string {
36
- if (!(value instanceof CSSStyleSheet)) return String(value);
36
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
37
+ if (!(value instanceof CSSStyleSheet)) return value === null || typeof value == "undefined" ? "" : String(value);
37
38
  return Array.from(value.cssRules).map(cssRule => cssRule.cssText).join("\n");
38
39
  }
39
40
 
@@ -43,7 +44,8 @@ function stringFromCss(value: unknown): string {
43
44
  * @returns The HTML string corresponding to the specified value.
44
45
  */
45
46
  function stringFromHtml(value: unknown): string {
46
- if (!(value instanceof DocumentFragment)) return String(value);
47
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
48
+ if (!(value instanceof DocumentFragment)) return value === null || typeof value == "undefined" ? "" : String(value);
47
49
  const element = document.createElement("div");
48
50
  element.appendChild(value);
49
51
  return element.innerHTML;
@@ -1 +0,0 @@
1
- {"version":3,"file":"MessageBox.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/MessageBox.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAiB,MAAM,eAAe,CAAC;AACtD,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,KAAK,EAAe,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,QAAQ;IAExB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,IAAI,EAAE,gBAAgB,CAAC;IAEvB;;OAEG;IACH,OAAO,EAAE,MA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