@cedx/base 0.10.1 → 0.12.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 +1 -1
- package/lib/Data/Pagination.d.ts +3 -3
- package/lib/Data/Pagination.js +10 -10
- package/lib/UI/Components/KeyboardAccelerator.d.ts +11 -0
- package/lib/UI/Components/KeyboardAccelerator.d.ts.map +1 -1
- package/lib/UI/Components/KeyboardAccelerator.js +1 -1
- package/lib/UI/Components/OfflineIndicator.d.ts +0 -4
- package/lib/UI/Components/OfflineIndicator.d.ts.map +1 -1
- package/lib/UI/Components/OfflineIndicator.js +5 -11
- package/lib/UI/Components/TabActivator.d.ts +2 -2
- package/lib/UI/Components/TabActivator.d.ts.map +1 -1
- package/lib/UI/Components/TabActivator.js +6 -6
- package/lib/UI/Components/ThemeDropdown.d.ts +16 -0
- package/lib/UI/Components/ThemeDropdown.d.ts.map +1 -1
- package/lib/UI/Components/ThemeDropdown.js +73 -29
- package/lib/UI/Components/Toast.d.ts +74 -0
- package/lib/UI/Components/Toast.d.ts.map +1 -0
- package/lib/UI/Components/Toast.js +225 -0
- package/lib/UI/ElementExtensions.d.ts +13 -0
- package/lib/UI/ElementExtensions.d.ts.map +1 -0
- package/lib/UI/ElementExtensions.js +18 -0
- package/lib/UI/Position.d.ts +46 -0
- package/lib/UI/Position.d.ts.map +1 -0
- package/lib/UI/Position.js +41 -0
- package/lib/UI/Size.d.ts +34 -0
- package/lib/UI/Size.d.ts.map +1 -0
- package/lib/UI/Size.js +29 -0
- package/lib/UI/Variant.d.ts +26 -0
- package/lib/UI/Variant.d.ts.map +1 -0
- package/lib/UI/Variant.js +21 -0
- package/lib/UI/ViewportScroller.js +1 -1
- package/package.json +5 -5
- package/src/Client/Data/Pagination.ts +11 -11
- package/src/Client/UI/Components/KeyboardAccelerator.ts +14 -1
- package/src/Client/UI/Components/MessageBox.old +242 -0
- package/src/Client/UI/Components/OfflineIndicator.ts +5 -13
- package/src/Client/UI/Components/TabActivator.ts +7 -7
- package/src/Client/UI/Components/ThemeDropdown.ts +79 -26
- package/src/Client/UI/Components/Toast.ts +252 -0
- package/src/Client/UI/Components/Toaster.old +0 -0
- package/src/Client/UI/ElementExtensions.ts +19 -0
- package/src/Client/UI/Position.ts +55 -0
- package/src/Client/UI/Size.ts +40 -0
- package/src/Client/UI/Variant.ts +30 -0
- package/src/Client/UI/ViewportScroller.ts +1 -1
package/ReadMe.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Belin.io Base
|
|
2
|
-
   
|
|
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).
|
package/lib/Data/Pagination.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class Pagination {
|
|
|
9
9
|
*/
|
|
10
10
|
constructor(options?: PaginationOptions);
|
|
11
11
|
/**
|
|
12
|
-
* The
|
|
12
|
+
* The current page index.
|
|
13
13
|
*/
|
|
14
14
|
get currentPageIndex(): number;
|
|
15
15
|
set currentPageIndex(value: number);
|
|
@@ -27,7 +27,7 @@ export declare class Pagination {
|
|
|
27
27
|
get itemsPerPage(): number;
|
|
28
28
|
set itemsPerPage(value: number);
|
|
29
29
|
/**
|
|
30
|
-
* The
|
|
30
|
+
* The last page index.
|
|
31
31
|
*/
|
|
32
32
|
get lastPageIndex(): number;
|
|
33
33
|
/**
|
|
@@ -59,7 +59,7 @@ export declare class Pagination {
|
|
|
59
59
|
*/
|
|
60
60
|
export type PaginationOptions = Partial<{
|
|
61
61
|
/**
|
|
62
|
-
* The
|
|
62
|
+
* The current page index.
|
|
63
63
|
*/
|
|
64
64
|
currentPageIndex: number;
|
|
65
65
|
/**
|
package/lib/Data/Pagination.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export class Pagination {
|
|
5
5
|
/**
|
|
6
|
-
* The
|
|
6
|
+
* The current page index.
|
|
7
7
|
*/
|
|
8
8
|
#currentPageIndex;
|
|
9
9
|
/**
|
|
@@ -19,18 +19,18 @@ export class Pagination {
|
|
|
19
19
|
* @param options An object providing values to initialize this instance.
|
|
20
20
|
*/
|
|
21
21
|
constructor(options = {}) {
|
|
22
|
-
this.currentPageIndex = options.currentPageIndex ??
|
|
22
|
+
this.currentPageIndex = options.currentPageIndex ?? 0;
|
|
23
23
|
this.itemsPerPage = options.itemsPerPage ?? 25;
|
|
24
24
|
this.totalItemCount = options.totalItemCount ?? 0;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
* The
|
|
27
|
+
* The current page index.
|
|
28
28
|
*/
|
|
29
29
|
get currentPageIndex() {
|
|
30
30
|
return this.#currentPageIndex;
|
|
31
31
|
}
|
|
32
32
|
set currentPageIndex(value) {
|
|
33
|
-
this.#currentPageIndex = Math.max(
|
|
33
|
+
this.#currentPageIndex = Math.max(0, value);
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Value indicating whether a next page exists.
|
|
@@ -42,7 +42,7 @@ export class Pagination {
|
|
|
42
42
|
* Value indicating whether a previous page exists.
|
|
43
43
|
*/
|
|
44
44
|
get hasPreviousPage() {
|
|
45
|
-
return this.#currentPageIndex >
|
|
45
|
+
return this.#currentPageIndex > 0;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* The number of items per page.
|
|
@@ -54,10 +54,10 @@ export class Pagination {
|
|
|
54
54
|
this.#itemsPerPage = Math.max(1, Math.min(1000, value));
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
|
-
* The
|
|
57
|
+
* The last page index.
|
|
58
58
|
*/
|
|
59
59
|
get lastPageIndex() {
|
|
60
|
-
return this.#totalItemCount > 0 ? Math.ceil(this.#totalItemCount / this.#itemsPerPage) :
|
|
60
|
+
return this.#totalItemCount > 0 ? Math.ceil(this.#totalItemCount / this.#itemsPerPage) - 1 : 0;
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* The data limit.
|
|
@@ -69,13 +69,13 @@ export class Pagination {
|
|
|
69
69
|
* The data offset.
|
|
70
70
|
*/
|
|
71
71
|
get offset() {
|
|
72
|
-
return
|
|
72
|
+
return this.#currentPageIndex * this.#itemsPerPage;
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* The search parameters corresponding to this object.
|
|
76
76
|
*/
|
|
77
77
|
get searchParams() {
|
|
78
|
-
return new URLSearchParams({ page: this.#currentPageIndex.toString(), perPage: this.#itemsPerPage.toString() });
|
|
78
|
+
return new URLSearchParams({ page: (this.#currentPageIndex + 1).toString(), perPage: this.#itemsPerPage.toString() });
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* The total number of items.
|
|
@@ -93,7 +93,7 @@ export class Pagination {
|
|
|
93
93
|
*/
|
|
94
94
|
static fromResponse(response) {
|
|
95
95
|
return new this({
|
|
96
|
-
currentPageIndex: Number(response.headers.get("X-Pagination-Current-Page") ?? "1"),
|
|
96
|
+
currentPageIndex: Number(response.headers.get("X-Pagination-Current-Page") ?? "1") - 1,
|
|
97
97
|
itemsPerPage: Number(response.headers.get("X-Pagination-Per-Page") ?? "25"),
|
|
98
98
|
totalItemCount: Number(response.headers.get("X-Pagination-Total-Count") ?? "0")
|
|
99
99
|
});
|
|
@@ -22,4 +22,15 @@ export declare class KeyboardAccelerator extends HTMLElement {
|
|
|
22
22
|
*/
|
|
23
23
|
disconnectedCallback(): void;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Declaration merging.
|
|
27
|
+
*/
|
|
28
|
+
declare global {
|
|
29
|
+
/**
|
|
30
|
+
* The map of HTML tag names.
|
|
31
|
+
*/
|
|
32
|
+
interface HTMLElementTagNameMap {
|
|
33
|
+
"keyboard-accelerator": KeyboardAccelerator;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
25
36
|
//# sourceMappingURL=KeyboardAccelerator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeyboardAccelerator.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/KeyboardAccelerator.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,WAAW;;IAcnD;;OAEG;IACH,IAAI,GAAG,IAAI,MAAM,CAEhB;IACD,IAAI,GAAG,CAAC,KAAK,EAAE,MAAM,EAEpB;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,CAItB;IACD,IAAI,SAAS,CAAC,KAAK,EAAE,MAAM,EAK1B;IAED;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAIzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;CAuB5B"}
|
|
1
|
+
{"version":3,"file":"KeyboardAccelerator.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/KeyboardAccelerator.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,WAAW;;IAcnD;;OAEG;IACH,IAAI,GAAG,IAAI,MAAM,CAEhB;IACD,IAAI,GAAG,CAAC,KAAK,EAAE,MAAM,EAEpB;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,CAItB;IACD,IAAI,SAAS,CAAC,KAAK,EAAE,MAAM,EAK1B;IAED;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAIzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;CAuB5B;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,sBAAsB,EAAE,mBAAmB,CAAC;KAC5C;CACD"}
|
|
@@ -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;;
|
|
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"}
|
|
@@ -2,13 +2,6 @@
|
|
|
2
2
|
* A component that shows up when the network is unavailable, and hides when connectivity is restored.
|
|
3
3
|
*/
|
|
4
4
|
export class OfflineIndicator extends HTMLElement {
|
|
5
|
-
/**
|
|
6
|
-
* Creates a new offline indicator.
|
|
7
|
-
*/
|
|
8
|
-
constructor() {
|
|
9
|
-
super();
|
|
10
|
-
this.#updateHiddenState();
|
|
11
|
-
}
|
|
12
5
|
/**
|
|
13
6
|
* Registers the component.
|
|
14
7
|
*/
|
|
@@ -19,18 +12,19 @@ export class OfflineIndicator extends HTMLElement {
|
|
|
19
12
|
* Method invoked when this component is connected.
|
|
20
13
|
*/
|
|
21
14
|
connectedCallback() {
|
|
15
|
+
this.#update();
|
|
22
16
|
for (const event of ["online", "offline"])
|
|
23
|
-
addEventListener(event, this.#
|
|
17
|
+
addEventListener(event, this.#update);
|
|
24
18
|
}
|
|
25
19
|
/**
|
|
26
20
|
* Method invoked when this component is disconnected.
|
|
27
21
|
*/
|
|
28
22
|
disconnectedCallback() {
|
|
29
23
|
for (const event of ["online", "offline"])
|
|
30
|
-
removeEventListener(event, this.#
|
|
24
|
+
removeEventListener(event, this.#update);
|
|
31
25
|
}
|
|
32
26
|
/**
|
|
33
|
-
* Updates
|
|
27
|
+
* Updates this component.
|
|
34
28
|
*/
|
|
35
|
-
#
|
|
29
|
+
#update = () => this.hidden = navigator.onLine;
|
|
36
30
|
}
|
|
@@ -4,7 +4,7 @@ import { StorageArea } from "../StorageArea.js";
|
|
|
4
4
|
*/
|
|
5
5
|
export declare class TabActivator extends HTMLElement {
|
|
6
6
|
/**
|
|
7
|
-
* The
|
|
7
|
+
* The index of the active tab.
|
|
8
8
|
*/
|
|
9
9
|
get activeTabIndex(): number;
|
|
10
10
|
set activeTabIndex(value: number);
|
|
@@ -25,7 +25,7 @@ export declare class TabActivator extends HTMLElement {
|
|
|
25
25
|
/**
|
|
26
26
|
* The tab list.
|
|
27
27
|
*/
|
|
28
|
-
get tabs(): NodeListOf<
|
|
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,
|
|
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"}
|
|
@@ -11,14 +11,14 @@ export class TabActivator extends HTMLElement {
|
|
|
11
11
|
customElements.define("tab-activator", this);
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* The
|
|
14
|
+
* The index of the active tab.
|
|
15
15
|
*/
|
|
16
16
|
get activeTabIndex() {
|
|
17
|
-
const index = Number
|
|
18
|
-
return Math.max(
|
|
17
|
+
const index = Number(this.storage.getItem(this.storageKey) ?? "1");
|
|
18
|
+
return Math.max(0, Math.min(this.tabs.length, Number.isNaN(index) ? 0 : index - 1));
|
|
19
19
|
}
|
|
20
20
|
set activeTabIndex(value) {
|
|
21
|
-
this.storage.setItem(this.storageKey, value.toString());
|
|
21
|
+
this.storage.setItem(this.storageKey, (value + 1).toString());
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* The storage object corresponding to the current {@link storageArea}.
|
|
@@ -57,8 +57,8 @@ export class TabActivator extends HTMLElement {
|
|
|
57
57
|
*/
|
|
58
58
|
connectedCallback() {
|
|
59
59
|
const { activeTabIndex, tabs } = this;
|
|
60
|
-
for (let index =
|
|
61
|
-
const tab = tabs.item(index
|
|
60
|
+
for (let index = 0; index < tabs.length - 1; index++) {
|
|
61
|
+
const tab = tabs.item(index);
|
|
62
62
|
tab.addEventListener("click", () => this.activeTabIndex = index);
|
|
63
63
|
if (index == activeTabIndex)
|
|
64
64
|
Tab.getOrCreateInstance(tab).show();
|
|
@@ -9,6 +9,10 @@ export declare class ThemeDropdown extends HTMLElement {
|
|
|
9
9
|
* The list of observed attributes.
|
|
10
10
|
*/
|
|
11
11
|
static readonly observedAttributes: string[];
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new theme dropdown.
|
|
14
|
+
*/
|
|
15
|
+
constructor();
|
|
12
16
|
/**
|
|
13
17
|
* The alignment of the dropdown menu.
|
|
14
18
|
*/
|
|
@@ -36,6 +40,10 @@ export declare class ThemeDropdown extends HTMLElement {
|
|
|
36
40
|
* @param newValue The new attribute value.
|
|
37
41
|
*/
|
|
38
42
|
attributeChangedCallback(attribute: string, oldValue: string | null, newValue: string | null): void;
|
|
43
|
+
/**
|
|
44
|
+
* Closes the dropdown menu.
|
|
45
|
+
*/
|
|
46
|
+
close(): void;
|
|
39
47
|
/**
|
|
40
48
|
* Method invoked when this component is connected.
|
|
41
49
|
*/
|
|
@@ -44,6 +52,14 @@ export declare class ThemeDropdown extends HTMLElement {
|
|
|
44
52
|
* Method invoked when this component is disconnected.
|
|
45
53
|
*/
|
|
46
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;
|
|
47
63
|
}
|
|
48
64
|
/**
|
|
49
65
|
* Declaration merging.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeDropdown.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/ThemeDropdown.ts"],"names":[],"mappings":"
|
|
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,10 +9,22 @@ 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
|
*/
|
|
14
19
|
#mediaQuery = matchMedia("(prefers-color-scheme: dark)");
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new theme dropdown.
|
|
22
|
+
*/
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
for (const button of this.querySelectorAll("button"))
|
|
26
|
+
button.addEventListener("click", this.#setAppTheme);
|
|
27
|
+
}
|
|
15
28
|
/**
|
|
16
29
|
* Registers the component.
|
|
17
30
|
*/
|
|
@@ -37,7 +50,6 @@ export class ThemeDropdown extends HTMLElement {
|
|
|
37
50
|
}
|
|
38
51
|
set appTheme(value) {
|
|
39
52
|
this.setAttribute("apptheme", value);
|
|
40
|
-
localStorage.setItem(this.storageKey, this.appTheme);
|
|
41
53
|
}
|
|
42
54
|
/**
|
|
43
55
|
* The label of the dropdown menu.
|
|
@@ -68,52 +80,57 @@ export class ThemeDropdown extends HTMLElement {
|
|
|
68
80
|
attributeChangedCallback(attribute, oldValue, newValue) {
|
|
69
81
|
if (newValue != oldValue)
|
|
70
82
|
switch (attribute) {
|
|
71
|
-
case "alignment":
|
|
72
|
-
|
|
73
|
-
const { classList } = this.querySelector(".dropdown-menu");
|
|
74
|
-
if (alignment == MenuAlignment.End)
|
|
75
|
-
classList.add("dropdown-menu-end");
|
|
76
|
-
else
|
|
77
|
-
classList.remove("dropdown-menu-end");
|
|
83
|
+
case "alignment":
|
|
84
|
+
this.#updateAlignment(Object.values(MenuAlignment).includes(newValue) ? newValue : MenuAlignment.End);
|
|
78
85
|
break;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const appTheme = Object.values(AppTheme).includes(newValue) ? newValue : AppTheme.System;
|
|
82
|
-
this.querySelector(".dropdown-toggle > .icon").textContent = getIcon(appTheme);
|
|
83
|
-
this.querySelector(`button[data-theme="${appTheme}"]`).appendChild(this.querySelector(".dropdown-item > .icon"));
|
|
84
|
-
this.#applyTheme();
|
|
86
|
+
case "apptheme":
|
|
87
|
+
this.#updateAppTheme(Object.values(AppTheme).includes(newValue) ? newValue : AppTheme.System);
|
|
85
88
|
break;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this.querySelector(".dropdown-toggle > span").textContent = (newValue ?? "").trim() || "Thème";
|
|
89
|
+
case "label":
|
|
90
|
+
this.#updateLabel(newValue ?? "");
|
|
89
91
|
break;
|
|
90
|
-
}
|
|
91
92
|
// No default
|
|
92
93
|
}
|
|
93
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Closes the dropdown menu.
|
|
97
|
+
*/
|
|
98
|
+
close() {
|
|
99
|
+
this.#dropdown.hide();
|
|
100
|
+
}
|
|
94
101
|
/**
|
|
95
102
|
* Method invoked when this component is connected.
|
|
96
103
|
*/
|
|
97
104
|
connectedCallback() {
|
|
98
|
-
for (const button of this.querySelectorAll("button"))
|
|
99
|
-
button.addEventListener("click", this.#setTheme);
|
|
100
|
-
this.#mediaQuery.addEventListener("change", this.#applyTheme);
|
|
101
105
|
const appTheme = localStorage.getItem(this.storageKey);
|
|
102
106
|
if (appTheme)
|
|
103
|
-
this.
|
|
107
|
+
this.appTheme = appTheme;
|
|
108
|
+
this.#dropdown = new Dropdown(this.querySelector(".dropdown-toggle"));
|
|
109
|
+
this.#mediaQuery.addEventListener("change", this.#applyToDocument);
|
|
104
110
|
}
|
|
105
111
|
/**
|
|
106
112
|
* Method invoked when this component is disconnected.
|
|
107
113
|
*/
|
|
108
114
|
disconnectedCallback() {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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);
|
|
112
129
|
}
|
|
113
130
|
/**
|
|
114
131
|
* Applies the application theme to the document.
|
|
115
132
|
*/
|
|
116
|
-
#
|
|
133
|
+
#applyToDocument = () => {
|
|
117
134
|
const { appTheme } = this;
|
|
118
135
|
const bsTheme = appTheme == AppTheme.System ? (this.#mediaQuery.matches ? AppTheme.Dark : AppTheme.Light) : appTheme;
|
|
119
136
|
document.documentElement.dataset.bsTheme = bsTheme.toLowerCase();
|
|
@@ -122,9 +139,36 @@ export class ThemeDropdown extends HTMLElement {
|
|
|
122
139
|
* Changes the current application theme.
|
|
123
140
|
* @param event The dispatched event.
|
|
124
141
|
*/
|
|
125
|
-
#
|
|
142
|
+
#setAppTheme = event => {
|
|
126
143
|
event.preventDefault();
|
|
127
|
-
|
|
128
|
-
this.
|
|
144
|
+
this.appTheme = event.target.closest("button").dataset.theme;
|
|
145
|
+
this.save();
|
|
129
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
|
+
}
|
|
130
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,EAAU,MAAM,0BAA0B,CAAC;AAG1D;;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"}
|