@uxland/primary-shell 7.35.1 → 7.35.2

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.
@@ -29,7 +29,7 @@ export declare const commonNavMenuItems: {
29
29
  label: string;
30
30
  type: string;
31
31
  sortHint: string;
32
- callbackFn: () => Promise<unknown>;
32
+ callbackFn: () => any;
33
33
  }[];
34
34
  export declare const registerNavMenuViews: (views: MenuItemConfig[]) => void;
35
35
  export declare const registerCommunicationNavMenu: () => void;
@@ -1,5 +1,7 @@
1
1
  import { PrimariaNotificationService } from './notification-service';
2
2
  export declare class PrimariaNotificationServiceImpl extends PrimariaNotificationService {
3
+ private getOrCreateContainer;
4
+ private removeContainerIfEmpty;
3
5
  private notify;
4
6
  info(message: string, duration?: number): void;
5
7
  warning(message: string, duration?: number): void;
@@ -13,5 +13,5 @@ interface PrimariaBootstrappedPlugin extends BootstrappedPlugin<PrimariaApi> {
13
13
  }
14
14
  export declare const bootstrapPlugins: (plugins: PluginDefinition[], startup?: PrimariaStartupPlugin) => Promise<void>;
15
15
  export declare const handleStartupPlugin: (plugins: PrimariaBootstrappedPlugin[], startupPlugin?: PrimariaStartupPlugin) => void;
16
- export declare const disposePlugins: () => Promise<void[]>;
16
+ export declare const disposePlugins: () => Promise<any>;
17
17
  export type Plugin = PluginType<PrimariaApi>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxland/primary-shell",
3
- "version": "7.35.1",
3
+ "version": "7.35.2",
4
4
  "description": "Primaria Shell",
5
5
  "author": "UXLand <dev@uxland.es>",
6
6
  "homepage": "https://github.com/uxland/harmonix/tree/app#readme",
@@ -37,6 +37,13 @@ describe("PrimariaNotificationServiceImpl", () => {
37
37
  assertToast(state, message);
38
38
  });
39
39
 
40
+ it("should create a container for toasts", () => {
41
+ service.info("Test");
42
+ const container = document.getElementById("primaria-toast-container");
43
+ expect(container).not.toBeNull();
44
+ expect(container?.style.position).toBe("fixed");
45
+ });
46
+
40
47
  it("should remove the toast after the duration", () => {
41
48
  service.info("Temporary toast", 2000);
42
49
 
@@ -53,4 +60,24 @@ describe("PrimariaNotificationServiceImpl", () => {
53
60
  toast = document.querySelector("dss-toast") as HTMLElement;
54
61
  expect(toast).toBeNull();
55
62
  });
63
+
64
+ it("should remove the container when all toasts are dismissed", () => {
65
+ service.info("Toast 1", 1000);
66
+
67
+ vi.advanceTimersByTime(1000);
68
+ vi.advanceTimersByTime(300);
69
+
70
+ const container = document.getElementById("primaria-toast-container");
71
+ expect(container).toBeNull();
72
+ });
73
+
74
+ it("should stack multiple toasts in the same container", () => {
75
+ service.info("Toast 1");
76
+ service.warning("Toast 2");
77
+ service.error("Toast 3");
78
+
79
+ const container = document.getElementById("primaria-toast-container");
80
+ const toasts = container?.querySelectorAll("dss-toast");
81
+ expect(toasts?.length).toBe(3);
82
+ });
56
83
  });
@@ -1,12 +1,33 @@
1
1
  import { PrimariaNotificationService } from "./notification-service";
2
2
 
3
+ const CONTAINER_ID = "primaria-toast-container";
4
+
3
5
  export class PrimariaNotificationServiceImpl extends PrimariaNotificationService {
6
+ private getOrCreateContainer(): HTMLElement {
7
+ let container = document.getElementById(CONTAINER_ID);
8
+ if (!container) {
9
+ container = document.createElement("div");
10
+ container.id = CONTAINER_ID;
11
+ container.style.cssText =
12
+ "position:fixed;bottom:var(--dss-spacing-xxs,8px);left:var(--dss-spacing-xxs,8px);display:flex;flex-direction:column-reverse;gap:var(--dss-spacing-xs,4px);z-index:999;pointer-events:none;";
13
+ document.body.appendChild(container);
14
+ }
15
+ return container;
16
+ }
17
+
18
+ private removeContainerIfEmpty(container: HTMLElement): void {
19
+ if (container.childElementCount === 0) {
20
+ container.remove();
21
+ }
22
+ }
23
+
4
24
  private notify(
5
25
  message: string,
6
26
  state: "info" | "warning" | "error" | "success",
7
27
  duration = 3000,
8
28
  ): void {
9
- // Crear el Web Component
29
+ const container = this.getOrCreateContainer();
30
+
10
31
  const toast = document.createElement("dss-toast");
11
32
  toast.setAttribute("isshow", "true");
12
33
  toast.setAttribute("state", state);
@@ -14,16 +35,19 @@ export class PrimariaNotificationServiceImpl extends PrimariaNotificationService
14
35
  toast.setAttribute("text", message);
15
36
  toast.setAttribute("hasicon", "true");
16
37
  toast.setAttribute("duration", duration.toString());
38
+ toast.style.position = "relative";
39
+ toast.style.bottom = "auto";
40
+ toast.style.left = "auto";
41
+ toast.style.pointerEvents = "auto";
17
42
 
18
- // Agregar al body
19
- document.body.appendChild(toast);
43
+ container.appendChild(toast);
20
44
 
21
- // Remover después del tiempo de duración
22
45
  setTimeout(() => {
23
46
  toast.setAttribute("isshow", "false");
24
47
  setTimeout(() => {
25
48
  toast.remove();
26
- }, 300); // Espera un poco para animación de salida (ajustable)
49
+ this.removeContainerIfEmpty(container);
50
+ }, 300);
27
51
  }, duration);
28
52
  }
29
53