@cedx/base 0.29.0 → 0.30.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
  # Cédric Belin's Base
2
- ![.NET](https://badgen.net/badge/.net/%3E%3D9.0/green) ![Version](https://badgen.net/badge/project/v0.29.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.30.0/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).
package/lib/TimeSpan.d.ts CHANGED
@@ -9,7 +9,7 @@ export declare const TimeSpan: Readonly<{
9
9
  /**
10
10
  * The number of minutes in 1 day.
11
11
  */
12
- MinutesPerDay: 1440;
12
+ MinutesPerDay: number;
13
13
  /**
14
14
  * The number of minutes in 1 hour.
15
15
  */
@@ -17,11 +17,11 @@ export declare const TimeSpan: Readonly<{
17
17
  /**
18
18
  * The number of seconds in 1 day.
19
19
  */
20
- SecondsPerDay: 86400;
20
+ SecondsPerDay: number;
21
21
  /**
22
22
  * The number of seconds in 1 hour.
23
23
  */
24
- SecondsPerHour: 3600;
24
+ SecondsPerHour: number;
25
25
  /**
26
26
  * The number of seconds in 1 minute.
27
27
  */
@@ -29,15 +29,15 @@ export declare const TimeSpan: Readonly<{
29
29
  /**
30
30
  * The number of milliseconds in 1 day.
31
31
  */
32
- MillisecondsPerDay: 86400000;
32
+ MillisecondsPerDay: number;
33
33
  /**
34
34
  * The number of milliseconds in 1 hour.
35
35
  */
36
- MillisecondsPerHour: 3600000;
36
+ MillisecondsPerHour: number;
37
37
  /**
38
38
  * The number of milliseconds in 1 minute.
39
39
  */
40
- MillisecondsPerMinute: 60000;
40
+ MillisecondsPerMinute: number;
41
41
  /**
42
42
  * The number of milliseconds in 1 second.
43
43
  */
package/lib/TimeSpan.js CHANGED
@@ -9,7 +9,7 @@ export const TimeSpan = Object.freeze({
9
9
  /**
10
10
  * The number of minutes in 1 day.
11
11
  */
12
- MinutesPerDay: 1_440,
12
+ MinutesPerDay: 24 * 60,
13
13
  /**
14
14
  * The number of minutes in 1 hour.
15
15
  */
@@ -17,11 +17,11 @@ export const TimeSpan = Object.freeze({
17
17
  /**
18
18
  * The number of seconds in 1 day.
19
19
  */
20
- SecondsPerDay: 86_400,
20
+ SecondsPerDay: 24 * 60 * 60,
21
21
  /**
22
22
  * The number of seconds in 1 hour.
23
23
  */
24
- SecondsPerHour: 3_600,
24
+ SecondsPerHour: 60 * 60,
25
25
  /**
26
26
  * The number of seconds in 1 minute.
27
27
  */
@@ -29,15 +29,15 @@ export const TimeSpan = Object.freeze({
29
29
  /**
30
30
  * The number of milliseconds in 1 day.
31
31
  */
32
- MillisecondsPerDay: 86_400_000,
32
+ MillisecondsPerDay: 24 * 60 * 60 * 1_000,
33
33
  /**
34
34
  * The number of milliseconds in 1 hour.
35
35
  */
36
- MillisecondsPerHour: 3_600_000,
36
+ MillisecondsPerHour: 60 * 60 * 1_000,
37
37
  /**
38
38
  * The number of milliseconds in 1 minute.
39
39
  */
40
- MillisecondsPerMinute: 60_000,
40
+ MillisecondsPerMinute: 60 * 1_000,
41
41
  /**
42
42
  * The number of milliseconds in 1 second.
43
43
  */
@@ -23,6 +23,16 @@ export declare class ThemeDropdown extends HTMLElement {
23
23
  */
24
24
  get appTheme(): AppTheme;
25
25
  set appTheme(value: AppTheme);
26
+ /**
27
+ * Value indicating whether to store the application theme in a cookie.
28
+ */
29
+ get cookie(): boolean;
30
+ set cookie(value: boolean);
31
+ /**
32
+ * The URI for which the associated cookie is valid.
33
+ */
34
+ get cookieDomain(): string;
35
+ set cookieDomain(value: string);
26
36
  /**
27
37
  * The label of the dropdown menu.
28
38
  */
@@ -46,8 +56,9 @@ export declare class ThemeDropdown extends HTMLElement {
46
56
  close(): void;
47
57
  /**
48
58
  * Method invoked when this component is connected.
59
+ * @returns Completes when this component has been connected.
49
60
  */
50
- connectedCallback(): void;
61
+ connectedCallback(): Promise<void>;
51
62
  /**
52
63
  * Method invoked when this component is disconnected.
53
64
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ThemeDropdown.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/ThemeDropdown.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAC,QAAQ,EAAU,MAAM,gBAAgB,CAAC;AAEjD;;GAEG;AACH,qBAAa,aAAc,SAAQ,WAAW;;IAE7C;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAAsC;IAYxE;;OAEG;;IAcH;;OAEG;IACH,IAAI,SAAS,IAAI,SAAS,CAGzB;IACD,IAAI,SAAS,CAAC,KAAK,EAAE,SAAS,EAE7B;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;IAS/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;;OA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I;IAIb;;;OAGG;IACG,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAYxC;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAK5B;;OAEG;IACH,IAAI,IAAI,IAAI;IAIZ;;OAEG;IACH,IAAI,IAAI,IAAI;CAwDZ;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,gBAAgB,EAAE,aAAa,CAAC;KAChC;CACD"}
@@ -51,6 +51,24 @@ export class ThemeDropdown extends HTMLElement {
51
51
  set appTheme(value) {
52
52
  this.setAttribute("apptheme", value);
53
53
  }
54
+ /**
55
+ * Value indicating whether to store the application theme in a cookie.
56
+ */
57
+ get cookie() {
58
+ return this.hasAttribute("cookie");
59
+ }
60
+ set cookie(value) {
61
+ this.toggleAttribute("cookie", value);
62
+ }
63
+ /**
64
+ * The URI for which the associated cookie is valid.
65
+ */
66
+ get cookieDomain() {
67
+ return (this.getAttribute("cookiedomain") ?? "").trim();
68
+ }
69
+ set cookieDomain(value) {
70
+ this.setAttribute("cookiedomain", value);
71
+ }
54
72
  /**
55
73
  * The label of the dropdown menu.
56
74
  */
@@ -100,13 +118,19 @@ export class ThemeDropdown extends HTMLElement {
100
118
  }
101
119
  /**
102
120
  * Method invoked when this component is connected.
121
+ * @returns Completes when this component has been connected.
103
122
  */
104
- connectedCallback() {
105
- const appTheme = localStorage.getItem(this.storageKey);
106
- if (appTheme)
107
- this.appTheme = appTheme;
123
+ async connectedCallback() {
108
124
  this.#dropdown = new Dropdown(this.querySelector(".dropdown-toggle"));
109
125
  this.#mediaQuery.addEventListener("change", this.#applyToDocument);
126
+ const cookie = this.cookie ? await cookieStore.get(this.storageKey) : null;
127
+ if (cookie)
128
+ this.appTheme = cookie.value;
129
+ else {
130
+ const storage = localStorage.getItem(this.storageKey);
131
+ if (storage)
132
+ this.appTheme = storage;
133
+ }
110
134
  }
111
135
  /**
112
136
  * Method invoked when this component is disconnected.
@@ -125,7 +149,15 @@ export class ThemeDropdown extends HTMLElement {
125
149
  * Saves the current application theme into the local storage.
126
150
  */
127
151
  save() {
128
- localStorage.setItem(this.storageKey, this.appTheme);
152
+ const { appTheme, cookieDomain } = this;
153
+ localStorage.setItem(this.storageKey, appTheme);
154
+ if (this.cookie)
155
+ void cookieStore.set({
156
+ domain: cookieDomain ? cookieDomain : null,
157
+ expires: Date.now() + (365 * 24 * 60 * 60 * 1_000),
158
+ name: this.storageKey,
159
+ value: appTheme
160
+ });
129
161
  }
130
162
  /**
131
163
  * Applies the application theme to the document.
package/package.json CHANGED
@@ -7,13 +7,13 @@
7
7
  "name": "@cedx/base",
8
8
  "repository": "cedx/base",
9
9
  "type": "module",
10
- "version": "0.29.0",
10
+ "version": "0.30.0",
11
11
  "devDependencies": {
12
12
  "@playwright/browser-chromium": "^1.55.0",
13
13
  "@types/bootstrap": "^5.2.10",
14
14
  "@types/chai": "^5.2.2",
15
15
  "@types/mocha": "^10.0.10",
16
- "@types/node": "^24.3.0",
16
+ "@types/node": "^24.3.1",
17
17
  "@types/serve-handler": "^6.1.4",
18
18
  "chai": "^6.0.1",
19
19
  "esbuild": "^0.25.9",
@@ -11,7 +11,7 @@ export const TimeSpan = Object.freeze({
11
11
  /**
12
12
  * The number of minutes in 1 day.
13
13
  */
14
- MinutesPerDay: 1_440,
14
+ MinutesPerDay: 24 * 60,
15
15
 
16
16
  /**
17
17
  * The number of minutes in 1 hour.
@@ -21,12 +21,12 @@ export const TimeSpan = Object.freeze({
21
21
  /**
22
22
  * The number of seconds in 1 day.
23
23
  */
24
- SecondsPerDay: 86_400,
24
+ SecondsPerDay: 24 * 60 * 60,
25
25
 
26
26
  /**
27
27
  * The number of seconds in 1 hour.
28
28
  */
29
- SecondsPerHour: 3_600,
29
+ SecondsPerHour: 60 * 60,
30
30
 
31
31
  /**
32
32
  * The number of seconds in 1 minute.
@@ -36,17 +36,17 @@ export const TimeSpan = Object.freeze({
36
36
  /**
37
37
  * The number of milliseconds in 1 day.
38
38
  */
39
- MillisecondsPerDay: 86_400_000,
39
+ MillisecondsPerDay: 24 * 60 * 60 * 1_000,
40
40
 
41
41
  /**
42
42
  * The number of milliseconds in 1 hour.
43
43
  */
44
- MillisecondsPerHour: 3_600_000,
44
+ MillisecondsPerHour: 60 * 60 * 1_000,
45
45
 
46
46
  /**
47
47
  * The number of milliseconds in 1 minute.
48
48
  */
49
- MillisecondsPerMinute: 60_000,
49
+ MillisecondsPerMinute: 60 * 1_000,
50
50
 
51
51
  /**
52
52
  * The number of milliseconds in 1 second.
@@ -60,6 +60,26 @@ export class ThemeDropdown extends HTMLElement {
60
60
  this.setAttribute("apptheme", value);
61
61
  }
62
62
 
63
+ /**
64
+ * Value indicating whether to store the application theme in a cookie.
65
+ */
66
+ get cookie(): boolean {
67
+ return this.hasAttribute("cookie");
68
+ }
69
+ set cookie(value: boolean) {
70
+ this.toggleAttribute("cookie", value);
71
+ }
72
+
73
+ /**
74
+ * The URI for which the associated cookie is valid.
75
+ */
76
+ get cookieDomain(): string {
77
+ return (this.getAttribute("cookiedomain") ?? "").trim();
78
+ }
79
+ set cookieDomain(value: string) {
80
+ this.setAttribute("cookiedomain", value);
81
+ }
82
+
63
83
  /**
64
84
  * The label of the dropdown menu.
65
85
  */
@@ -106,13 +126,18 @@ export class ThemeDropdown extends HTMLElement {
106
126
 
107
127
  /**
108
128
  * Method invoked when this component is connected.
129
+ * @returns Completes when this component has been connected.
109
130
  */
110
- connectedCallback(): void {
111
- const appTheme = localStorage.getItem(this.storageKey) as AppTheme|null;
112
- if (appTheme) this.appTheme = appTheme;
113
-
131
+ async connectedCallback(): Promise<void> {
114
132
  this.#dropdown = new Dropdown(this.querySelector(".dropdown-toggle")!);
115
133
  this.#mediaQuery.addEventListener("change", this.#applyToDocument);
134
+
135
+ const cookie = this.cookie ? await cookieStore.get(this.storageKey) : null;
136
+ if (cookie) this.appTheme = cookie.value as AppTheme;
137
+ else {
138
+ const storage = localStorage.getItem(this.storageKey);
139
+ if (storage) this.appTheme = storage as AppTheme;
140
+ }
116
141
  }
117
142
 
118
143
  /**
@@ -134,7 +159,15 @@ export class ThemeDropdown extends HTMLElement {
134
159
  * Saves the current application theme into the local storage.
135
160
  */
136
161
  save(): void {
137
- localStorage.setItem(this.storageKey, this.appTheme);
162
+ const {appTheme, cookieDomain} = this;
163
+ localStorage.setItem(this.storageKey, appTheme);
164
+
165
+ if (this.cookie) void cookieStore.set({
166
+ domain: cookieDomain ? cookieDomain : null,
167
+ expires: Date.now() + (365 * 24 * 60 * 60 * 1_000),
168
+ name: this.storageKey,
169
+ value: appTheme
170
+ });
138
171
  }
139
172
 
140
173
  /**