@cedx/base 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ReadMe.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Belin.io Base
2
- ![.NET](https://badgen.net/badge/.net/%3E%3D9.0/green) ![Version](https://badgen.net/badge/project/v0.11.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.13.0/blue) ![Licence](https://badgen.net/badge/licence/MIT/blue)
3
3
 
4
4
  Base library by [Cédric Belin](https://belin.io), full stack developer,
5
5
  implemented in [C#](https://learn.microsoft.com/en-us/dotnet/csharp) and [TypeScript](https://www.typescriptlang.org).
@@ -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;;IAShD;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAKzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;CAS5B;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;;IAShD;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAKzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;CAQ5B;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,mBAAmB,EAAE,gBAAgB,CAAC;KACtC;CACD"}
@@ -12,19 +12,19 @@ export class OfflineIndicator extends HTMLElement {
12
12
  * Method invoked when this component is connected.
13
13
  */
14
14
  connectedCallback() {
15
- this.#updateHiddenState();
15
+ this.#update();
16
16
  for (const event of ["online", "offline"])
17
- addEventListener(event, this.#updateHiddenState);
17
+ addEventListener(event, this.#update);
18
18
  }
19
19
  /**
20
20
  * Method invoked when this component is disconnected.
21
21
  */
22
22
  disconnectedCallback() {
23
23
  for (const event of ["online", "offline"])
24
- removeEventListener(event, this.#updateHiddenState);
24
+ removeEventListener(event, this.#update);
25
25
  }
26
26
  /**
27
- * Updates the hidden state of this component according to the {@link navigator.onLine} property.
27
+ * Updates this component.
28
28
  */
29
- #updateHiddenState = () => this.hidden = navigator.onLine;
29
+ #update = () => this.hidden = navigator.onLine;
30
30
  }
@@ -25,7 +25,7 @@ export declare class TabActivator extends HTMLElement {
25
25
  /**
26
26
  * The tab list.
27
27
  */
28
- get tabs(): NodeListOf<HTMLButtonElement>;
28
+ get tabs(): NodeListOf<HTMLElement>;
29
29
  /**
30
30
  * Method invoked when this component is connected.
31
31
  */
@@ -1 +1 @@
1
- {"version":3,"file":"TabActivator.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/TabActivator.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAE9C;;GAEG;AACH,qBAAa,YAAa,SAAQ,WAAW;IAS5C;;OAEG;IACH,IAAI,cAAc,IAAI,MAAM,CAG3B;IACD,IAAI,cAAc,CAAC,KAAK,EAAE,MAAM,EAE/B;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,UAAU,CAAC,OAAO,CAEhC;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,WAAW,CAG7B;IACD,IAAI,WAAW,CAAC,KAAK,EAAE,WAAW,EAEjC;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,MAAM,CAGvB;IACD,IAAI,UAAU,CAAC,KAAK,EAAE,MAAM,EAE3B;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,UAAU,CAAC,iBAAiB,CAAC,CAExC;IAED;;OAEG;IACH,iBAAiB,IAAI,IAAI;CAQzB;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,eAAe,EAAE,YAAY,CAAC;KAC9B;CACD"}
1
+ {"version":3,"file":"TabActivator.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/TabActivator.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAE9C;;GAEG;AACH,qBAAa,YAAa,SAAQ,WAAW;IAS5C;;OAEG;IACH,IAAI,cAAc,IAAI,MAAM,CAG3B;IACD,IAAI,cAAc,CAAC,KAAK,EAAE,MAAM,EAE/B;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,UAAU,CAAC,OAAO,CAEhC;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,WAAW,CAG7B;IACD,IAAI,WAAW,CAAC,KAAK,EAAE,WAAW,EAEjC;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,MAAM,CAGvB;IACD,IAAI,UAAU,CAAC,KAAK,EAAE,MAAM,EAE3B;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,UAAU,CAAC,WAAW,CAAC,CAElC;IAED;;OAEG;IACH,iBAAiB,IAAI,IAAI;CAQzB;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,eAAe,EAAE,YAAY,CAAC;KAC9B;CACD"}
@@ -40,6 +40,10 @@ export declare class ThemeDropdown extends HTMLElement {
40
40
  * @param newValue The new attribute value.
41
41
  */
42
42
  attributeChangedCallback(attribute: string, oldValue: string | null, newValue: string | null): void;
43
+ /**
44
+ * Closes the dropdown menu.
45
+ */
46
+ close(): void;
43
47
  /**
44
48
  * Method invoked when this component is connected.
45
49
  */
@@ -48,6 +52,14 @@ export declare class ThemeDropdown extends HTMLElement {
48
52
  * Method invoked when this component is disconnected.
49
53
  */
50
54
  disconnectedCallback(): void;
55
+ /**
56
+ * Opens the dropdown menu.
57
+ */
58
+ open(): void;
59
+ /**
60
+ * Saves the current application theme into the local storage.
61
+ */
62
+ save(): void;
51
63
  }
52
64
  /**
53
65
  * Declaration merging.
@@ -1 +1 @@
1
- {"version":3,"file":"ThemeDropdown.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/ThemeDropdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAU,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAElD;;GAEG;AACH,qBAAa,aAAc,SAAQ,WAAW;;IAE7C;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAAsC;IAOxE;;OAEG;;IAaH;;OAEG;IACH,IAAI,SAAS,IAAI,aAAa,CAG7B;IACD,IAAI,SAAS,CAAC,KAAK,EAAE,aAAa,EAEjC;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,QAAQ,CAGvB;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAG3B;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAGlB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAEtB;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,MAAM,CAGvB;IACD,IAAI,UAAU,CAAC,KAAK,EAAE,MAAM,EAE3B;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;IAwB/F;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAMzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;CAsB5B;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,gBAAgB,EAAE,aAAa,CAAC;KAChC;CACD"}
1
+ {"version":3,"file":"ThemeDropdown.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/ThemeDropdown.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAU,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAElD;;GAEG;AACH,qBAAa,aAAc,SAAQ,WAAW;;IAE7C;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAAsC;IAYxE;;OAEG;;IAaH;;OAEG;IACH,IAAI,SAAS,IAAI,aAAa,CAG7B;IACD,IAAI,SAAS,CAAC,KAAK,EAAE,aAAa,EAEjC;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,QAAQ,CAGvB;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAE3B;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAGlB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAEtB;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,MAAM,CAGvB;IACD,IAAI,UAAU,CAAC,KAAK,EAAE,MAAM,EAE3B;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;IAe/F;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAQzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAK5B;;OAEG;IACH,IAAI,IAAI,IAAI;IAIZ;;OAEG;IACH,IAAI,IAAI,IAAI;CAkDZ;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,gBAAgB,EAAE,aAAa,CAAC;KAChC;CACD"}
@@ -1,3 +1,4 @@
1
+ import { Dropdown } from "bootstrap";
1
2
  import { AppTheme, getIcon } from "../AppTheme.js";
2
3
  import { MenuAlignment } from "../MenuAlignment.js";
3
4
  /**
@@ -8,6 +9,10 @@ export class ThemeDropdown extends HTMLElement {
8
9
  * The list of observed attributes.
9
10
  */
10
11
  static observedAttributes = ["alignment", "apptheme", "label"];
12
+ /**
13
+ * The dropdown menu.
14
+ */
15
+ #dropdown;
11
16
  /**
12
17
  * The media query used to check the application theme.
13
18
  */
@@ -18,7 +23,7 @@ export class ThemeDropdown extends HTMLElement {
18
23
  constructor() {
19
24
  super();
20
25
  for (const button of this.querySelectorAll("button"))
21
- button.addEventListener("click", this.#setTheme);
26
+ button.addEventListener("click", this.#setAppTheme);
22
27
  }
23
28
  /**
24
29
  * Registers the component.
@@ -45,7 +50,6 @@ export class ThemeDropdown extends HTMLElement {
45
50
  }
46
51
  set appTheme(value) {
47
52
  this.setAttribute("apptheme", value);
48
- localStorage.setItem(this.storageKey, this.appTheme);
49
53
  }
50
54
  /**
51
55
  * The label of the dropdown menu.
@@ -76,48 +80,57 @@ export class ThemeDropdown extends HTMLElement {
76
80
  attributeChangedCallback(attribute, oldValue, newValue) {
77
81
  if (newValue != oldValue)
78
82
  switch (attribute) {
79
- case "alignment": {
80
- const alignment = Object.values(MenuAlignment).includes(newValue) ? newValue : MenuAlignment.End;
81
- const { classList } = this.querySelector(".dropdown-menu");
82
- if (alignment == MenuAlignment.End)
83
- classList.add("dropdown-menu-end");
84
- else
85
- classList.remove("dropdown-menu-end");
83
+ case "alignment":
84
+ this.#updateAlignment(Object.values(MenuAlignment).includes(newValue) ? newValue : MenuAlignment.End);
86
85
  break;
87
- }
88
- case "apptheme": {
89
- const appTheme = Object.values(AppTheme).includes(newValue) ? newValue : AppTheme.System;
90
- this.querySelector(".dropdown-toggle > .icon").textContent = getIcon(appTheme);
91
- this.querySelector(`button[data-theme="${appTheme}"]`).appendChild(this.querySelector(".dropdown-item > .icon"));
92
- this.#applyTheme();
86
+ case "apptheme":
87
+ this.#updateAppTheme(Object.values(AppTheme).includes(newValue) ? newValue : AppTheme.System);
93
88
  break;
94
- }
95
- case "label": {
96
- this.querySelector(".dropdown-toggle > span").textContent = (newValue ?? "").trim() || "Thème";
89
+ case "label":
90
+ this.#updateLabel(newValue ?? "");
97
91
  break;
98
- }
99
92
  // No default
100
93
  }
101
94
  }
95
+ /**
96
+ * Closes the dropdown menu.
97
+ */
98
+ close() {
99
+ this.#dropdown.hide();
100
+ }
102
101
  /**
103
102
  * Method invoked when this component is connected.
104
103
  */
105
104
  connectedCallback() {
106
105
  const appTheme = localStorage.getItem(this.storageKey);
107
106
  if (appTheme)
108
- this.setAttribute("apptheme", appTheme);
109
- this.#mediaQuery.addEventListener("change", this.#applyTheme);
107
+ this.appTheme = appTheme;
108
+ this.#dropdown = new Dropdown(this.querySelector(".dropdown-toggle"));
109
+ this.#mediaQuery.addEventListener("change", this.#applyToDocument);
110
110
  }
111
111
  /**
112
112
  * Method invoked when this component is disconnected.
113
113
  */
114
114
  disconnectedCallback() {
115
- this.#mediaQuery.removeEventListener("change", this.#applyTheme);
115
+ this.#dropdown.dispose();
116
+ this.#mediaQuery.removeEventListener("change", this.#applyToDocument);
117
+ }
118
+ /**
119
+ * Opens the dropdown menu.
120
+ */
121
+ open() {
122
+ this.#dropdown.show();
123
+ }
124
+ /**
125
+ * Saves the current application theme into the local storage.
126
+ */
127
+ save() {
128
+ localStorage.setItem(this.storageKey, this.appTheme);
116
129
  }
117
130
  /**
118
131
  * Applies the application theme to the document.
119
132
  */
120
- #applyTheme = () => {
133
+ #applyToDocument = () => {
121
134
  const { appTheme } = this;
122
135
  const bsTheme = appTheme == AppTheme.System ? (this.#mediaQuery.matches ? AppTheme.Dark : AppTheme.Light) : appTheme;
123
136
  document.documentElement.dataset.bsTheme = bsTheme.toLowerCase();
@@ -126,9 +139,36 @@ export class ThemeDropdown extends HTMLElement {
126
139
  * Changes the current application theme.
127
140
  * @param event The dispatched event.
128
141
  */
129
- #setTheme = event => {
142
+ #setAppTheme = event => {
130
143
  event.preventDefault();
131
- const button = event.target.closest("button");
132
- this.appTheme = button.dataset.theme;
144
+ this.appTheme = event.target.closest("button").dataset.theme;
145
+ this.save();
133
146
  };
147
+ /**
148
+ * Updates the alignment of the dropdown menu.
149
+ * @param value The new value.
150
+ */
151
+ #updateAlignment(value) {
152
+ const { classList } = this.querySelector(".dropdown-menu");
153
+ if (value == MenuAlignment.End)
154
+ classList.add("dropdown-menu-end");
155
+ else
156
+ classList.remove("dropdown-menu-end");
157
+ }
158
+ /**
159
+ * Updates the application theme.
160
+ * @param value The new value.
161
+ */
162
+ #updateAppTheme(value) {
163
+ this.querySelector(".dropdown-toggle > .icon").textContent = getIcon(value);
164
+ this.querySelector(`button[data-theme="${value}"]`).appendChild(this.querySelector(".dropdown-item > .icon"));
165
+ this.#applyToDocument();
166
+ }
167
+ /**
168
+ * Updates the label of the dropdown menu.
169
+ * @param value The new value.
170
+ */
171
+ #updateLabel(value) {
172
+ this.querySelector(".dropdown-toggle > span").textContent = value.trim() || "Thème";
173
+ }
134
174
  }
@@ -0,0 +1,74 @@
1
+ import { Context } from "@cedx/base/UI/Context.js";
2
+ /**
3
+ * Manages the notification messages.
4
+ */
5
+ export declare class Toast extends HTMLElement {
6
+ #private;
7
+ /**
8
+ * The list of observed attributes.
9
+ */
10
+ static readonly observedAttributes: string[];
11
+ /**
12
+ * Value indicating whether to apply a fade transition.
13
+ */
14
+ get animation(): boolean;
15
+ set animation(value: boolean);
16
+ /**
17
+ * Value indicating whether to automatically hide the notification.
18
+ */
19
+ get autoHide(): boolean;
20
+ set autoHide(value: boolean);
21
+ /**
22
+ * The title displayed in the header.
23
+ */
24
+ get caption(): string;
25
+ set caption(value: string);
26
+ /**
27
+ * A contextual modifier.
28
+ */
29
+ get context(): Context;
30
+ set context(value: Context);
31
+ /**
32
+ * The culture used to format the relative time.
33
+ */
34
+ get culture(): Intl.Locale;
35
+ set culture(value: Intl.Locale);
36
+ /**
37
+ * The delay, in milliseconds, to hide the notification.
38
+ */
39
+ get delay(): number;
40
+ set delay(value: number);
41
+ /**
42
+ * The time elapsed since this component was initially shown, in milliseconds.
43
+ */
44
+ get elapsedTime(): number;
45
+ /**
46
+ * The icon displayed next to the caption.
47
+ */
48
+ get icon(): string;
49
+ set icon(value: string);
50
+ /**
51
+ * Method invoked when an attribute has been changed.
52
+ * @param attribute The attribute name.
53
+ * @param oldValue The previous attribute value.
54
+ * @param newValue The new attribute value.
55
+ */
56
+ attributeChangedCallback(attribute: string, oldValue: string | null, newValue: string | null): void;
57
+ /**
58
+ * Method invoked when this component is connected.
59
+ */
60
+ connectedCallback(): void;
61
+ /**
62
+ * Method invoked when this component is disconnected.
63
+ */
64
+ disconnectedCallback(): void;
65
+ /**
66
+ * Hides this toast.
67
+ */
68
+ hide(): void;
69
+ /**
70
+ * Shows this toast.
71
+ */
72
+ show(): void;
73
+ }
74
+ //# sourceMappingURL=Toast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Toast.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/Toast.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAiB,MAAM,0BAA0B,CAAC;AAGjE;;GAEG;AACH,qBAAa,KAAM,SAAQ,WAAW;;IAErC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAA6C;IAuC/E;;OAEG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IACD,IAAI,SAAS,CAAC,KAAK,EAAE,OAAO,EAG3B;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,OAAO,EAG1B;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,MAAM,CAEpB;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,MAAM,EAExB;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,CAGrB;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAEzB;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,IAAI,CAAC,MAAM,CAGzB;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAE7B;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAGlB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAEtB;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,MAAM,CAExB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAGjB;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,EAErB;IAED;;;;;OAKG;IACH,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAC,IAAI,GAAG,IAAI;IAkB/F;;OAEG;IACH,iBAAiB,IAAI,IAAI;IASzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAK5B;;OAEG;IACH,IAAI,IAAI,IAAI;IAIZ;;OAEG;IACH,IAAI,IAAI,IAAI;CA+DZ"}
@@ -0,0 +1,225 @@
1
+ import { Duration } from "@cedx/base/Duration.js";
2
+ import { Context, getIcon, toCss } from "@cedx/base/UI/Context.js";
3
+ import { Toast as BootstrapToast } from "bootstrap";
4
+ /**
5
+ * Manages the notification messages.
6
+ */
7
+ export class Toast extends HTMLElement {
8
+ /**
9
+ * The list of observed attributes.
10
+ */
11
+ static observedAttributes = ["caption", "context", "culture", "icon"];
12
+ /**
13
+ * The time units.
14
+ */
15
+ static #timeUnits = ["second", "minute", "hour"];
16
+ /**
17
+ * The formatter used to format the relative time.
18
+ */
19
+ #formatter;
20
+ /**
21
+ * The toast header.
22
+ */
23
+ #header = this.querySelector(".toast-header");
24
+ /**
25
+ * The time at which this component was initially shown.
26
+ */
27
+ #initialTime = Date.now();
28
+ /**
29
+ * The timer identifier.
30
+ */
31
+ #timer = 0;
32
+ /**
33
+ * The underlying Bootstrap toast.
34
+ */
35
+ #toast;
36
+ /**
37
+ * Registers the component.
38
+ */
39
+ static {
40
+ customElements.define("toaster-item", this);
41
+ }
42
+ /**
43
+ * Value indicating whether to apply a fade transition.
44
+ */
45
+ get animation() {
46
+ return this.hasAttribute("animation");
47
+ }
48
+ set animation(value) {
49
+ if (value)
50
+ this.setAttribute("animation", "");
51
+ else
52
+ this.removeAttribute("animation");
53
+ }
54
+ /**
55
+ * Value indicating whether to automatically hide the notification.
56
+ */
57
+ get autoHide() {
58
+ return this.hasAttribute("autohide");
59
+ }
60
+ set autoHide(value) {
61
+ if (value)
62
+ this.setAttribute("autohide", "");
63
+ else
64
+ this.removeAttribute("autohide");
65
+ }
66
+ /**
67
+ * The title displayed in the header.
68
+ */
69
+ get caption() {
70
+ return (this.getAttribute("caption") ?? "").trim();
71
+ }
72
+ set caption(value) {
73
+ this.setAttribute("caption", value);
74
+ }
75
+ /**
76
+ * A contextual modifier.
77
+ */
78
+ get context() {
79
+ const value = this.getAttribute("context");
80
+ return Object.values(Context).includes(value) ? value : Context.Info;
81
+ }
82
+ set context(value) {
83
+ this.setAttribute("context", value);
84
+ }
85
+ /**
86
+ * The culture used to format the relative time.
87
+ */
88
+ get culture() {
89
+ const value = this.getAttribute("culture") ?? "";
90
+ return new Intl.Locale(value.trim() || navigator.language);
91
+ }
92
+ set culture(value) {
93
+ this.setAttribute("culture", value.toString());
94
+ }
95
+ /**
96
+ * The delay, in milliseconds, to hide the notification.
97
+ */
98
+ get delay() {
99
+ const value = Number(this.getAttribute("delay"));
100
+ return Math.max(1, Number.isNaN(value) ? 5_000 : value);
101
+ }
102
+ set delay(value) {
103
+ this.setAttribute("delay", value.toString());
104
+ }
105
+ /**
106
+ * The time elapsed since this component was initially shown, in milliseconds.
107
+ */
108
+ get elapsedTime() {
109
+ return Date.now() - this.#initialTime;
110
+ }
111
+ /**
112
+ * The icon displayed next to the caption.
113
+ */
114
+ get icon() {
115
+ const value = this.getAttribute("icon") ?? "";
116
+ return value.trim() || getIcon(Context.Info);
117
+ }
118
+ set icon(value) {
119
+ this.setAttribute("icon", value);
120
+ }
121
+ /**
122
+ * Method invoked when an attribute has been changed.
123
+ * @param attribute The attribute name.
124
+ * @param oldValue The previous attribute value.
125
+ * @param newValue The new attribute value.
126
+ */
127
+ attributeChangedCallback(attribute, oldValue, newValue) {
128
+ if (newValue != oldValue)
129
+ switch (attribute) {
130
+ case "caption":
131
+ this.#updateCaption(newValue ?? "");
132
+ break;
133
+ case "context":
134
+ this.#updateContext(Object.values(Context).includes(newValue) ? newValue : Context.Info);
135
+ break;
136
+ case "culture":
137
+ this.#formatter = new Intl.RelativeTimeFormat((newValue ?? "").trim() || navigator.language, { style: "long" });
138
+ break;
139
+ case "icon":
140
+ this.#updateIcon(newValue ?? "");
141
+ break;
142
+ // No default
143
+ }
144
+ }
145
+ /**
146
+ * Method invoked when this component is connected.
147
+ */
148
+ connectedCallback() {
149
+ const toast = this.querySelector(".toast");
150
+ toast.addEventListener("hidden.bs.toast", () => clearInterval(this.#timer));
151
+ toast.addEventListener("show.bs.toast", () => this.#timer = window.setInterval(this.#updateElapsedTime, Duration.Second));
152
+ const { animation, autoHide: autohide, delay } = this;
153
+ this.#toast = new BootstrapToast(toast, { animation, autohide, delay });
154
+ }
155
+ /**
156
+ * Method invoked when this component is disconnected.
157
+ */
158
+ disconnectedCallback() {
159
+ clearInterval(this.#timer);
160
+ this.#toast.dispose();
161
+ }
162
+ /**
163
+ * Hides this toast.
164
+ */
165
+ hide() {
166
+ this.#toast.hide();
167
+ }
168
+ /**
169
+ * Shows this toast.
170
+ */
171
+ show() {
172
+ if (!this.#toast.isShown()) {
173
+ this.#initialTime = Date.now();
174
+ this.#updateElapsedTime();
175
+ }
176
+ this.#toast.show();
177
+ }
178
+ /**
179
+ * Formats the specified elapsed time.
180
+ * @param elapsed The elapsed time, in seconds.
181
+ * @returns The formated time.
182
+ */
183
+ #formatTime(elapsed) {
184
+ let index = 0;
185
+ while (elapsed > 60 && index < Toast.#timeUnits.length) {
186
+ elapsed /= 60;
187
+ index++;
188
+ }
189
+ return this.#formatter.format(Math.ceil(-elapsed), Toast.#timeUnits[index]);
190
+ }
191
+ /**
192
+ * Updates the title displayed in the header.
193
+ * @param value The new value.
194
+ */
195
+ #updateCaption(value) {
196
+ this.#header.querySelector("b").textContent = value.trim();
197
+ }
198
+ /**
199
+ * Updates the title displayed in the header.
200
+ * @param value The new value.
201
+ */
202
+ #updateContext(value) {
203
+ const contexts = Object.values(Context);
204
+ let { classList } = this.#header;
205
+ classList.remove(...contexts.map(context => `toast-header-${toCss(context)}`));
206
+ classList.add(`toast-header-${value}`);
207
+ ({ classList } = this.#header.querySelector(".icon"));
208
+ classList.remove(...contexts.map(context => `text-${toCss(context)}`));
209
+ classList.add(`text-${value}`);
210
+ }
211
+ /**
212
+ * Updates the label corresponding to the elapsed time.
213
+ */
214
+ #updateElapsedTime = () => {
215
+ const { elapsedTime } = this;
216
+ this.#header.querySelector("small").textContent = elapsedTime > 0 ? this.#formatTime(elapsedTime / Duration.Second) : "";
217
+ };
218
+ /**
219
+ * Updates the icon displayed next to the caption.
220
+ * @param value The new value.
221
+ */
222
+ #updateIcon(value) {
223
+ this.#header.querySelector(".icon").textContent = value.trim() || getIcon(Context.Info);
224
+ }
225
+ }
@@ -5,19 +5,19 @@ export declare const Context: Readonly<{
5
5
  /**
6
6
  * A danger.
7
7
  */
8
- Danger: "danger";
8
+ Danger: "Danger";
9
9
  /**
10
10
  * A warning.
11
11
  */
12
- Warning: "warning";
12
+ Warning: "Warning";
13
13
  /**
14
14
  * An information.
15
15
  */
16
- Info: "info";
16
+ Info: "Info";
17
17
  /**
18
18
  * A success.
19
19
  */
20
- Success: "success";
20
+ Success: "Success";
21
21
  }>;
22
22
  /**
23
23
  * Defines contextual modifiers.
@@ -29,4 +29,10 @@ export type Context = typeof Context[keyof typeof Context];
29
29
  * @returns The icon corresponding to the specified context.
30
30
  */
31
31
  export declare function getIcon(context: Context): string;
32
+ /**
33
+ * Returns the CSS representation of the specified context.
34
+ * @param context The context.
35
+ * @returns The CSS representation of the specified context.
36
+ */
37
+ export declare function toCss(context: Context): string;
32
38
  //# sourceMappingURL=Context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../src/Client/UI/Context.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,OAAO;IAEnB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAOhD"}
1
+ {"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../src/Client/UI/Context.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,OAAO;IAEnB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAOhD;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAE9C"}
package/lib/UI/Context.js CHANGED
@@ -5,19 +5,19 @@ export const Context = Object.freeze({
5
5
  /**
6
6
  * A danger.
7
7
  */
8
- Danger: "danger",
8
+ Danger: "Danger",
9
9
  /**
10
10
  * A warning.
11
11
  */
12
- Warning: "warning",
12
+ Warning: "Warning",
13
13
  /**
14
14
  * An information.
15
15
  */
16
- Info: "info",
16
+ Info: "Info",
17
17
  /**
18
18
  * A success.
19
19
  */
20
- Success: "success"
20
+ Success: "Success"
21
21
  });
22
22
  /**
23
23
  * Gets the icon corresponding to the specified context.
@@ -32,3 +32,11 @@ export function getIcon(context) {
32
32
  default: return "info";
33
33
  }
34
34
  }
35
+ /**
36
+ * Returns the CSS representation of the specified context.
37
+ * @param context The context.
38
+ * @returns The CSS representation of the specified context.
39
+ */
40
+ export function toCss(context) {
41
+ return context.toLowerCase();
42
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Defines the position of an element.
3
+ */
4
+ export declare const Position: Readonly<{
5
+ /**
6
+ * Top left.
7
+ */
8
+ TopStart: "TopStart";
9
+ /**
10
+ * Top center.
11
+ */
12
+ TopCenter: "TopCenter";
13
+ /**
14
+ * Top right.
15
+ */
16
+ TopEnd: "TopEnd";
17
+ /**
18
+ * Middle left.
19
+ */
20
+ MiddleStart: "MiddleStart";
21
+ /**
22
+ * Middle center.
23
+ */
24
+ MiddleCenter: "MiddleCenter";
25
+ /**
26
+ * Middle right.
27
+ */
28
+ MiddleEnd: "MiddleEnd";
29
+ /**
30
+ * Bottom left.
31
+ */
32
+ BottomStart: "BottomStart";
33
+ /**
34
+ * Bottom center.
35
+ */
36
+ BottomCenter: "BottomCenter";
37
+ /**
38
+ * Bottom right.
39
+ */
40
+ BottomEnd: "BottomEnd";
41
+ }>;
42
+ /**
43
+ * Defines the placement of an element.
44
+ */
45
+ export type Position = typeof Position[keyof typeof Position];
46
+ /**
47
+ * Returns the CSS representation of the specified position.
48
+ * @param position The position.
49
+ * @returns The CSS representation of the specified position.
50
+ */
51
+ export declare function toCss(position: Position): string;
52
+ //# sourceMappingURL=Position.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Position.d.ts","sourceRoot":"","sources":["../../src/Client/UI/Position.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,QAAQ;IAEpB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;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,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAYhD"}