@uxland/primary-shell 5.7.1 → 6.0.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.
@@ -1,7 +1,6 @@
1
- import { ConfirmationContentProps, ConfirmationOptions, ConfirmationResult, ConfirmationWithResultContentProps, PrimariaInteractionService } from './interaction-service';
1
+ import { ConfirmationOptions, ConfirmationResult, ConfirmComponentUI, PrimariaInteractionService } from './interaction-service';
2
2
 
3
- import * as React from "react";
4
3
  export declare class ParimariaInteractionServiceImpl extends PrimariaInteractionService {
5
- confirm<TData = undefined, TResult = undefined>(data: TData | undefined, DialogComponent: React.ComponentType<ConfirmationContentProps<TData, TResult> | ConfirmationWithResultContentProps<TData, TResult>> | (new () => HTMLElement), options?: ConfirmationOptions | undefined, styles?: any): Promise<ConfirmationResult<TResult | undefined>>;
4
+ confirm<TData = undefined, TResult = undefined>(data: TData | undefined, componentUI: ConfirmComponentUI<TData, TResult>, options?: ConfirmationOptions | undefined): Promise<ConfirmationResult<TResult | undefined>>;
6
5
  confirmMessage(message: string, options?: ConfirmationOptions | undefined): Promise<ConfirmationResult>;
7
6
  }
@@ -26,7 +26,11 @@ export interface ConfirmationOptions {
26
26
  closeOnOutsideClick?: boolean | undefined;
27
27
  state?: "success" | "info" | "alert" | "error";
28
28
  }
29
+ export interface ConfirmComponentUI<TData = undefined, TResult = undefined> {
30
+ component: React.ComponentType<ConfirmationContentProps<TData, TResult> | ConfirmationWithResultContentProps<TData, TResult>> | (new () => HTMLElement);
31
+ styles?: string;
32
+ }
29
33
  export declare abstract class PrimariaInteractionService {
30
- abstract confirm<TData = undefined, TResult = undefined>(data: TData | undefined, dialogComponent: React.ComponentType<ConfirmationContentProps<TData, TResult> | ConfirmationWithResultContentProps<TData, TResult>> | (new () => HTMLElement), options?: ConfirmationOptions | undefined): Promise<ConfirmationResult<TResult | undefined>>;
34
+ abstract confirm<TData = undefined, TResult = undefined>(data: TData | undefined, componentUI: ConfirmComponentUI<TData, TResult>, options?: ConfirmationOptions | undefined): Promise<ConfirmationResult<TResult | undefined>>;
31
35
  abstract confirmMessage(message: string, options?: ConfirmationOptions | undefined): Promise<ConfirmationResult>;
32
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxland/primary-shell",
3
- "version": "5.7.1",
3
+ "version": "6.0.0",
4
4
  "description": "Primaria Shell",
5
5
  "author": "UXLand <dev@uxland.es>",
6
6
  "homepage": "https://github.com/uxland/harmonix/tree/app#readme",
@@ -1,8 +1,7 @@
1
1
  import {
2
- ConfirmationContentProps,
3
2
  ConfirmationOptions,
4
3
  ConfirmationResult,
5
- ConfirmationWithResultContentProps,
4
+ ConfirmComponentUI,
6
5
  PrimariaInteractionService,
7
6
  } from "./interaction-service";
8
7
  import * as React from "react";
@@ -25,23 +24,23 @@ const defaultOptions: ConfirmationOptions = {
25
24
  export class ParimariaInteractionServiceImpl extends PrimariaInteractionService {
26
25
  confirm<TData = undefined, TResult = undefined>(
27
26
  data: TData | undefined,
28
- DialogComponent:
29
- | React.ComponentType<ConfirmationContentProps<TData, TResult> | ConfirmationWithResultContentProps<TData, TResult>>
30
- | (new () => HTMLElement),
31
- options?: ConfirmationOptions | undefined,
32
- styles?: any
27
+ componentUI: ConfirmComponentUI<TData, TResult>,
28
+ options?: ConfirmationOptions | undefined
33
29
  ): Promise<ConfirmationResult<TResult | undefined>> {
34
30
  const finalOptions: ConfirmationOptions = { ...defaultOptions, ...(options || {}) };
35
31
  return new Promise((resolve) => {
36
32
  const div = document.createElement("div");
37
33
  document.body.appendChild(div);
38
- const wrapperStyles = document.createElement("style");
39
- wrapperStyles.textContent = modalStyles;
40
- document.head.appendChild(wrapperStyles);
41
- if(styles) {
42
- const style = document.createElement("style");
43
- style.textContent = styles;
44
- document.head.appendChild(style);
34
+ const wrapperHeadStyles = document.createElement("style");
35
+ wrapperHeadStyles.textContent = modalStyles;
36
+ document.head.appendChild(wrapperHeadStyles);
37
+ const DialogComponent = componentUI.component;
38
+ const DialogComponentStyles = componentUI.styles;
39
+ let componentHeadStyles;
40
+ if(DialogComponentStyles) {
41
+ componentHeadStyles = document.createElement("style");
42
+ componentHeadStyles.textContent = componentUI?.styles;
43
+ document.head.appendChild(componentHeadStyles);
45
44
  }
46
45
 
47
46
  const DialogWrapper = () => {
@@ -111,7 +110,9 @@ export class ParimariaInteractionServiceImpl extends PrimariaInteractionService
111
110
  };
112
111
  resolve(confirmationResult);
113
112
  document.body.removeChild(div);
114
- document.head.removeChild(style);
113
+ document.head.removeChild(wrapperHeadStyles);
114
+ if (DialogComponentStyles)
115
+ document.head.removeChild(componentHeadStyles);
115
116
  window.removeEventListener('keydown', handleKeydown);
116
117
  }, 300);
117
118
  };
@@ -203,6 +204,6 @@ export class ParimariaInteractionServiceImpl extends PrimariaInteractionService
203
204
  message: string,
204
205
  options?: ConfirmationOptions | undefined,
205
206
  ): Promise<ConfirmationResult> {
206
- return this.confirm(message, ConfirmationMessage, options);
207
+ return this.confirm(message, {component: ConfirmationMessage}, options);
207
208
  }
208
209
  }
@@ -31,12 +31,16 @@ export interface ConfirmationOptions {
31
31
  state?: "success" | "info" | "alert" | "error";
32
32
  }
33
33
 
34
+ export interface ConfirmComponentUI<TData = undefined, TResult = undefined> {
35
+ component: | React.ComponentType<ConfirmationContentProps<TData, TResult> | ConfirmationWithResultContentProps<TData, TResult>>
36
+ | (new () => HTMLElement);
37
+ styles?: string;
38
+ }
39
+
34
40
  export abstract class PrimariaInteractionService {
35
41
  abstract confirm<TData = undefined, TResult = undefined>(
36
42
  data: TData | undefined,
37
- dialogComponent:
38
- | React.ComponentType<ConfirmationContentProps<TData, TResult> | ConfirmationWithResultContentProps<TData, TResult>>
39
- | (new () => HTMLElement),
43
+ componentUI: ConfirmComponentUI<TData, TResult>,
40
44
  options?: ConfirmationOptions | undefined,
41
45
  ): Promise<ConfirmationResult<TResult | undefined>>;
42
46
  abstract confirmMessage(
@@ -74,8 +74,8 @@ describe("ExitShellHandler", () => {
74
74
 
75
75
  await handler.handle(message);
76
76
 
77
- expect(mockApi.interactionService.confirm).toHaveBeenCalledWith({ busyTasks }, PluginBusyList, {
78
- title: expect.any(String),
77
+ expect(mockApi.interactionService.confirm).toHaveBeenCalledWith({ busyTasks }, {component: PluginBusyList}, {
78
+ title: "actions.askExit",
79
79
  state: "error",
80
80
  confirmButtonText: "Sí",
81
81
  cancelButtonText: "No",
@@ -23,7 +23,7 @@ export class ExitShellHandler {
23
23
  // Per si un plugin tarda molt en fer dispose, màxim deixarem 5 segons, per no interrompre el tancar infinitament
24
24
  await Promise.race([
25
25
  disposePlugins(), // S'intenta executar un dispose normal
26
- this.timeout(5000), // Si passen 5s, es segueix amb l'execució
26
+ this.timeout(10000), // Si passen 5s, es segueix amb l'execució
27
27
  ]);
28
28
  disposeShell();
29
29
  this.emitClose(evt);
@@ -34,7 +34,7 @@ export class ExitShellHandler {
34
34
  }
35
35
 
36
36
  private askForClose(busyTasks: PluginBusyTask[]) {
37
- return this.api.interactionService.confirm({ busyTasks }, PluginBusyList, {
37
+ return this.api.interactionService.confirm({ busyTasks }, {component: PluginBusyList}, {
38
38
  title: translate("actions.askExit"),
39
39
  state: "error",
40
40
  confirmButtonText: "Sí",
@@ -5,7 +5,7 @@ import { ExportPdfModal } from "./export-pdf-modal/export-pdf-modal";
5
5
  export class ExportToPdfHandler extends ApiBaseHandler {
6
6
  async handle() {
7
7
  try {
8
- this.api.interactionService.confirm(undefined, ExportPdfModal, {
8
+ this.api.interactionService.confirm(undefined, {component: ExportPdfModal}, {
9
9
  title: translate("modal.selectExportOption"),
10
10
  confirmButtonText: "Exportar",
11
11
  cancelButtonText: "Cancelar",