@cedx/base 0.23.0 → 0.25.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.23.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.25.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).
@@ -2,7 +2,6 @@
2
2
  * A component that moves back in the session history when clicked.
3
3
  */
4
4
  export declare class BackButton extends HTMLElement {
5
- #private;
6
5
  /**
7
6
  * Creates a new back button.
8
7
  */
@@ -12,6 +11,11 @@ export declare class BackButton extends HTMLElement {
12
11
  */
13
12
  get steps(): number;
14
13
  set steps(value: number);
14
+ /**
15
+ * Moves back in the session history.
16
+ * @param event The dispatched event.
17
+ */
18
+ goBack(event?: Event): void;
15
19
  }
16
20
  /**
17
21
  * Declaration merging.
@@ -1 +1 @@
1
- {"version":3,"file":"BackButton.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/BackButton.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,UAAW,SAAQ,WAAW;;IAE1C;;OAEG;;IAaH;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAGlB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAEtB;CAUD;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,aAAa,EAAE,UAAU,CAAC;KAC1B;CACD"}
1
+ {"version":3,"file":"BackButton.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/BackButton.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,UAAW,SAAQ,WAAW;IAE1C;;OAEG;;IAaH;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAGlB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAEtB;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI;CAI3B;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,aAAa,EAAE,UAAU,CAAC;KAC1B;CACD"}
@@ -7,7 +7,7 @@ export class BackButton extends HTMLElement {
7
7
  */
8
8
  constructor() {
9
9
  super();
10
- this.addEventListener("click", this.#goBack.bind(this));
10
+ this.addEventListener("click", this.goBack.bind(this), { capture: true });
11
11
  }
12
12
  /**
13
13
  * Registers the component.
@@ -29,8 +29,8 @@ export class BackButton extends HTMLElement {
29
29
  * Moves back in the session history.
30
30
  * @param event The dispatched event.
31
31
  */
32
- #goBack(event) {
33
- event.preventDefault();
32
+ goBack(event) {
33
+ event?.stopPropagation();
34
34
  history.go(-this.steps);
35
35
  }
36
36
  }
@@ -228,7 +228,7 @@ export class DialogBox extends HTMLElement {
228
228
  */
229
229
  #close(event) {
230
230
  event.preventDefault();
231
- this.close(event.target.closest("button").value);
231
+ this.close(event.currentTarget.value);
232
232
  }
233
233
  /**
234
234
  * Updates the title displayed in the header.
@@ -8,7 +8,7 @@ export declare class FullScreenToggler extends HTMLElement {
8
8
  */
9
9
  constructor();
10
10
  /**
11
- * The CSS selector used to target the element.
11
+ * The CSS selector specifying the target element.
12
12
  */
13
13
  get target(): string;
14
14
  set target(value: string);
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export class FullScreenToggler extends HTMLElement {
5
5
  /**
6
- * The associated element.
6
+ * The target element.
7
7
  */
8
8
  #element = document.body;
9
9
  /**
@@ -15,7 +15,7 @@ export class FullScreenToggler extends HTMLElement {
15
15
  */
16
16
  constructor() {
17
17
  super();
18
- this.addEventListener("click", this.toggleFullScreen.bind(this)); // eslint-disable-line @typescript-eslint/no-misused-promises
18
+ this.addEventListener("click", this.toggleFullScreen.bind(this), { capture: true }); // eslint-disable-line @typescript-eslint/no-misused-promises
19
19
  }
20
20
  /**
21
21
  * Registers the component.
@@ -24,7 +24,7 @@ export class FullScreenToggler extends HTMLElement {
24
24
  customElements.define("fullscreen-toggler", this);
25
25
  }
26
26
  /**
27
- * The CSS selector used to target the element.
27
+ * The CSS selector specifying the target element.
28
28
  */
29
29
  get target() {
30
30
  const value = this.getAttribute("target") ?? "";
@@ -63,7 +63,7 @@ export class FullScreenToggler extends HTMLElement {
63
63
  * @returns Resolves when the full-screen mode has been toggled.
64
64
  */
65
65
  async toggleFullScreen(event) {
66
- event?.preventDefault();
66
+ event?.stopPropagation();
67
67
  if (document.fullscreenElement)
68
68
  await document.exitFullscreen();
69
69
  else
@@ -67,7 +67,7 @@ export class KeyboardAccelerator extends HTMLElement {
67
67
  return;
68
68
  if (!(modifiers & KeyboardModifiers.Meta) && event.metaKey)
69
69
  return;
70
- event.preventDefault();
70
+ event.stopPropagation();
71
71
  this.firstElementChild?.click();
72
72
  };
73
73
  }
@@ -2,10 +2,15 @@
2
2
  * A component that activates the items of a menu, based on the current document URL.
3
3
  */
4
4
  export declare class MenuActivator extends HTMLElement {
5
+ #private;
5
6
  /**
6
7
  * Method invoked when this component is connected.
7
8
  */
8
9
  connectedCallback(): void;
10
+ /**
11
+ * Method invoked when this component is disconnected.
12
+ */
13
+ disconnectedCallback(): void;
9
14
  }
10
15
  /**
11
16
  * Declaration merging.
@@ -1 +1 @@
1
- {"version":3,"file":"MenuActivator.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/MenuActivator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,aAAc,SAAQ,WAAW;IAS7C;;OAEG;IACH,iBAAiB,IAAI,IAAI;CAQzB;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,gBAAgB,EAAE,aAAa,CAAC;KAChC;CACD"}
1
+ {"version":3,"file":"MenuActivator.d.ts","sourceRoot":"","sources":["../../../src/Client/UI/Components/MenuActivator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,aAAc,SAAQ,WAAW;;IAS7C;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAMzB;;OAEG;IACH,oBAAoB,IAAI,IAAI;CAgB5B;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,qBAAqB;QAC9B,gBAAgB,EAAE,aAAa,CAAC;KAChC;CACD"}
@@ -12,12 +12,28 @@ export class MenuActivator extends HTMLElement {
12
12
  * Method invoked when this component is connected.
13
13
  */
14
14
  connectedCallback() {
15
- for (const anchor of this.querySelectorAll("a"))
16
- if (anchor.href != location.href)
17
- anchor.classList.remove("active");
18
- else {
19
- anchor.classList.add("active");
20
- anchor.closest(".dropdown")?.querySelector('[data-bs-toggle="dropdown"]')?.classList.add("active");
21
- }
15
+ this.#update();
16
+ addEventListener("popstate", this.#update);
17
+ document.body.addEventListener("htmx:afterRequest", this.#update);
18
+ }
19
+ /**
20
+ * Method invoked when this component is disconnected.
21
+ */
22
+ disconnectedCallback() {
23
+ removeEventListener("popstate", this.#update);
24
+ document.body.removeEventListener("htmx:afterRequest", this.#update);
22
25
  }
26
+ /**
27
+ * Updates this component.
28
+ * @param event The dispatched event.
29
+ */
30
+ #update = () => {
31
+ for (const element of this.querySelectorAll(".active"))
32
+ element.classList.remove("active");
33
+ for (const element of this.querySelectorAll("a"))
34
+ if (element.href == location.href) {
35
+ element.classList.add("active");
36
+ element.closest(".dropdown")?.querySelector(".dropdown-toggle")?.classList.add("active");
37
+ }
38
+ };
23
39
  }
@@ -141,7 +141,7 @@ export class ThemeDropdown extends HTMLElement {
141
141
  */
142
142
  #setAppTheme(event) {
143
143
  event.preventDefault();
144
- this.appTheme = event.target.closest("button").dataset.theme;
144
+ this.appTheme = event.currentTarget.dataset.theme;
145
145
  this.save();
146
146
  }
147
147
  /**
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "name": "@cedx/base",
8
8
  "repository": "cedx/base",
9
9
  "type": "module",
10
- "version": "0.23.0",
10
+ "version": "0.25.0",
11
11
  "devDependencies": {
12
12
  "@playwright/browser-chromium": "^1.55.0",
13
13
  "@types/bootstrap": "^5.2.10",
@@ -8,7 +8,7 @@ export class BackButton extends HTMLElement {
8
8
  */
9
9
  constructor() {
10
10
  super();
11
- this.addEventListener("click", this.#goBack.bind(this));
11
+ this.addEventListener("click", this.goBack.bind(this), {capture: true});
12
12
  }
13
13
 
14
14
  /**
@@ -33,8 +33,8 @@ export class BackButton extends HTMLElement {
33
33
  * Moves back in the session history.
34
34
  * @param event The dispatched event.
35
35
  */
36
- #goBack(event: Event): void {
37
- event.preventDefault();
36
+ goBack(event?: Event): void {
37
+ event?.stopPropagation();
38
38
  history.go(-this.steps);
39
39
  }
40
40
  }
@@ -286,7 +286,7 @@ export class DialogBox extends HTMLElement {
286
286
  */
287
287
  #close(event: Event): void {
288
288
  event.preventDefault();
289
- this.close((event.target as Element).closest("button")!.value);
289
+ this.close((event.currentTarget as HTMLButtonElement).value);
290
290
  }
291
291
 
292
292
  /**
@@ -4,7 +4,7 @@
4
4
  export class FullScreenToggler extends HTMLElement {
5
5
 
6
6
  /**
7
- * The associated element.
7
+ * The target element.
8
8
  */
9
9
  #element: Element = document.body;
10
10
 
@@ -18,7 +18,7 @@ export class FullScreenToggler extends HTMLElement {
18
18
  */
19
19
  constructor() {
20
20
  super();
21
- this.addEventListener("click", this.toggleFullScreen.bind(this)); // eslint-disable-line @typescript-eslint/no-misused-promises
21
+ this.addEventListener("click", this.toggleFullScreen.bind(this), {capture: true}); // eslint-disable-line @typescript-eslint/no-misused-promises
22
22
  }
23
23
 
24
24
  /**
@@ -29,7 +29,7 @@ export class FullScreenToggler extends HTMLElement {
29
29
  }
30
30
 
31
31
  /**
32
- * The CSS selector used to target the element.
32
+ * The CSS selector specifying the target element.
33
33
  */
34
34
  get target(): string {
35
35
  const value = this.getAttribute("target") ?? "";
@@ -72,7 +72,7 @@ export class FullScreenToggler extends HTMLElement {
72
72
  * @returns Resolves when the full-screen mode has been toggled.
73
73
  */
74
74
  async toggleFullScreen(event?: Event): Promise<void> {
75
- event?.preventDefault();
75
+ event?.stopPropagation();
76
76
  if (document.fullscreenElement) await document.exitFullscreen();
77
77
  else await this.#element.requestFullscreen();
78
78
  }
@@ -72,7 +72,7 @@ export class KeyboardAccelerator extends HTMLElement {
72
72
  if (!(modifiers & KeyboardModifiers.Alt) && event.altKey) return;
73
73
  if (!(modifiers & KeyboardModifiers.Meta) && event.metaKey) return;
74
74
 
75
- event.preventDefault();
75
+ event.stopPropagation();
76
76
  (this.firstElementChild as HTMLElement|null)?.click();
77
77
  }
78
78
  }
@@ -14,13 +14,30 @@ export class MenuActivator extends HTMLElement {
14
14
  * Method invoked when this component is connected.
15
15
  */
16
16
  connectedCallback(): void {
17
- for (const anchor of this.querySelectorAll("a"))
18
- if (anchor.href != location.href) anchor.classList.remove("active");
19
- else {
20
- anchor.classList.add("active");
21
- anchor.closest(".dropdown")?.querySelector('[data-bs-toggle="dropdown"]')?.classList.add("active");
22
- }
17
+ this.#update();
18
+ addEventListener("popstate", this.#update);
19
+ document.body.addEventListener("htmx:afterRequest", this.#update);
23
20
  }
21
+
22
+ /**
23
+ * Method invoked when this component is disconnected.
24
+ */
25
+ disconnectedCallback(): void {
26
+ removeEventListener("popstate", this.#update);
27
+ document.body.removeEventListener("htmx:afterRequest", this.#update);
28
+ }
29
+
30
+ /**
31
+ * Updates this component.
32
+ * @param event The dispatched event.
33
+ */
34
+ readonly #update: (event?: Event) => void = () => {
35
+ for (const element of this.querySelectorAll(".active")) element.classList.remove("active");
36
+ for (const element of this.querySelectorAll("a")) if (element.href == location.href) {
37
+ element.classList.add("active");
38
+ element.closest(".dropdown")?.querySelector(".dropdown-toggle")?.classList.add("active");
39
+ }
40
+ };
24
41
  }
25
42
 
26
43
  /**
@@ -151,7 +151,7 @@ export class ThemeDropdown extends HTMLElement {
151
151
  */
152
152
  #setAppTheme(event: Event): void {
153
153
  event.preventDefault();
154
- this.appTheme = (event.target as Element).closest("button")!.dataset.theme! as AppTheme;
154
+ this.appTheme = (event.currentTarget as HTMLElement).dataset.theme! as AppTheme;
155
155
  this.save();
156
156
  }
157
157