@votodigital-onpeui/react 0.1.31 → 0.1.36

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/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
- export { BrowserRecommended, Footer, ModalBrowserIncompatible, ModalDnieVersions, ModalNfc, ModalSystemIncompatible, NotRecommended, Overlay, Show } from './chunk-MFNWIYOJ.mjs';
2
- export { OnpeIdModal, useIframeCommunication, useIframePreload, useModalIframePreload, useOnpeIdAuth, useSendMessageToIframe, useSocketConnection } from './chunk-6RNDTVIJ.mjs';
1
+ export { BrowserRecommended, Footer, ModalBrowserIncompatible, ModalDnieVersions, ModalNfc, ModalSystemIncompatible, NotRecommended, Overlay, Show } from './chunk-4VUH3WMT.mjs';
2
+ export { OnpeIdModal, useIframeCommunication, useIframePreload, useModalIframePreload, useOnpeIdAuth, useSendMessageToIframe, useSocketConnection } from './chunk-6FILBCCN.mjs';
3
3
  import './chunk-KWOWOGBU.mjs';
4
- export { Button, ModalConfirm, ModalLoading } from './chunk-UGIZ3K3S.mjs';
4
+ export { Button, ModalConfirm, ModalLoading } from './chunk-52VIQAQL.mjs';
5
5
  export { FaceBookIcon, IconAndroid, IconApple, IconCheck, IconChrome, IconChromeColor, IconClose, IconEdge, IconEdgeColor, IconElectionsGeneral, IconElectionsRegionalesYMunicipales, IconHome, IconHuawei, IconInfo, IconLogoONPE, IconMozilla, IconMozillaColor, IconPhone, IconQuestion, IconSafari, IconSafariColor, IconSpinnerDesktop, IconSpinnerMobile, IconVotoDigital, IconWarning, IconWarningNotRecommended, IconWindow, InstagramIcon, TikTokIcon, WhatsappIcon, XIcon, YoutubeIcon } from './chunk-M2KQXQLY.mjs';
6
- export { Modal, Portal } from './chunk-4XHWFUHC.mjs';
6
+ export { Modal, Portal } from './chunk-FV3GKV22.mjs';
7
7
  export { IconCloseRadius } from './chunk-5FNWA3QC.mjs';
8
8
  //# sourceMappingURL=index.mjs.map
9
9
  //# sourceMappingURL=index.mjs.map
package/dist/modal.d.mts CHANGED
@@ -17,8 +17,12 @@ interface ModalGlobalProviderProps {
17
17
  preventBodyScroll?: boolean;
18
18
  /** Spinner personalizado para ModalLoading. Si no se provee, se usa el spinner por defecto. */
19
19
  loadingSpinner?: ReactNode;
20
+ /** Alinea el ModalLoadingPercentage al tope de la pantalla (default: false) */
21
+ loadingPercentageAlignTop?: boolean;
22
+ /** Reemplaza el contenido del ModalLoadingPercentage con un render personalizado */
23
+ loadingPercentageContent?: (percentage: number, message: string) => ReactNode;
20
24
  }
21
- declare const ModalGlobalProvider: ({ children, zIndexLevel, zIndexLoading, zIndexLoadingPercentage, animated, preventBodyScroll, loadingSpinner, }: ModalGlobalProviderProps) => react_jsx_runtime.JSX.Element;
25
+ declare const ModalGlobalProvider: ({ children, zIndexLevel, zIndexLoading, zIndexLoadingPercentage, animated, preventBodyScroll, loadingSpinner, loadingPercentageAlignTop, loadingPercentageContent, }: ModalGlobalProviderProps) => react_jsx_runtime.JSX.Element;
22
26
 
23
27
  type ModalResult = "confirm" | "cancel" | "close";
24
28
  /**
@@ -91,8 +95,9 @@ declare const useModalGlobalStore: zustand.UseBoundStore<zustand.StoreApi<ModalG
91
95
  interface ModalLoadingState {
92
96
  isOpen: boolean;
93
97
  message: string;
94
- openLoading: (message?: string) => void;
95
- closeLoading: () => void;
98
+ sessionId: number;
99
+ openLoading: (message?: string) => number;
100
+ closeLoading: (sessionId?: number) => void;
96
101
  }
97
102
  declare const useModalLoadingStore: zustand.UseBoundStore<zustand.StoreApi<ModalLoadingState>>;
98
103
 
@@ -100,9 +105,11 @@ interface ModalLoadingPercentageState {
100
105
  isOpen: boolean;
101
106
  message: string;
102
107
  percentage: number;
103
- openLoadingPercentage: (message?: string) => void;
104
- updatePercentage: (percentage: number) => void;
105
- closeLoadingPercentage: () => void;
108
+ /** ID de sesión actual — se incrementa en cada apertura */
109
+ sessionId: number;
110
+ openLoadingPercentage: (message?: string, initialPercentage?: number) => number;
111
+ updatePercentage: (percentage: number, sessionId?: number) => void;
112
+ closeLoadingPercentage: (sessionId?: number) => void;
106
113
  }
107
114
  declare const useModalLoadingPercentageStore: zustand.UseBoundStore<zustand.StoreApi<ModalLoadingPercentageState>>;
108
115
 
@@ -171,9 +178,9 @@ declare const isAlreadyHandled: () => boolean;
171
178
  * await api.save(data);
172
179
  * closeGlobalLoading();
173
180
  */
174
- declare const showGlobalLoading: (message?: string) => void;
175
- /** Close the global loading modal. */
176
- declare const closeGlobalLoading: () => void;
181
+ declare const showGlobalLoading: (message?: string) => number;
182
+ /** Close the global loading modal. If sessionId is provided, only closes if it matches. */
183
+ declare const closeGlobalLoading: (sessionId?: number) => void;
177
184
  /** Returns true if the global loading modal is currently visible. */
178
185
  declare const isGlobalLoadingOpen: () => boolean;
179
186
  /**
@@ -187,11 +194,17 @@ declare const isGlobalLoadingOpen: () => boolean;
187
194
  * }
188
195
  * closeGlobalLoadingPercentage();
189
196
  */
190
- declare const showGlobalLoadingPercentage: (message?: string) => void;
191
- /** Update the percentage value (0–100). Clamped automatically. */
192
- declare const updateGlobalLoadingPercentage: (percentage: number) => void;
193
- /** Close the global loading percentage modal. */
194
- declare const closeGlobalLoadingPercentage: () => void;
197
+ /**
198
+ * Abre el modal de loading con porcentaje. Retorna un sessionId para evitar
199
+ * interferencias si se abre otro modal del mismo tipo antes de cerrar el actual.
200
+ * Pasar el sessionId a updateGlobalLoadingPercentage y closeGlobalLoadingPercentage
201
+ * garantiza que solo la instancia activa pueda actualizar o cerrar el modal.
202
+ */
203
+ declare const showGlobalLoadingPercentage: (message?: string, initialPercentage?: number) => number;
204
+ /** Update the percentage value (0–100). Si se pasa sessionId y no coincide con la sesión activa, se ignora. */
205
+ declare const updateGlobalLoadingPercentage: (percentage: number, sessionId?: number) => void;
206
+ /** Close the global loading percentage modal. Si se pasa sessionId y no coincide con la sesión activa, se ignora. */
207
+ declare const closeGlobalLoadingPercentage: (sessionId?: number) => void;
195
208
  /** Returns true if the global loading percentage modal is currently visible. */
196
209
  declare const isGlobalLoadingPercentageOpen: () => boolean;
197
210
 
package/dist/modal.d.ts CHANGED
@@ -17,8 +17,12 @@ interface ModalGlobalProviderProps {
17
17
  preventBodyScroll?: boolean;
18
18
  /** Spinner personalizado para ModalLoading. Si no se provee, se usa el spinner por defecto. */
19
19
  loadingSpinner?: ReactNode;
20
+ /** Alinea el ModalLoadingPercentage al tope de la pantalla (default: false) */
21
+ loadingPercentageAlignTop?: boolean;
22
+ /** Reemplaza el contenido del ModalLoadingPercentage con un render personalizado */
23
+ loadingPercentageContent?: (percentage: number, message: string) => ReactNode;
20
24
  }
21
- declare const ModalGlobalProvider: ({ children, zIndexLevel, zIndexLoading, zIndexLoadingPercentage, animated, preventBodyScroll, loadingSpinner, }: ModalGlobalProviderProps) => react_jsx_runtime.JSX.Element;
25
+ declare const ModalGlobalProvider: ({ children, zIndexLevel, zIndexLoading, zIndexLoadingPercentage, animated, preventBodyScroll, loadingSpinner, loadingPercentageAlignTop, loadingPercentageContent, }: ModalGlobalProviderProps) => react_jsx_runtime.JSX.Element;
22
26
 
23
27
  type ModalResult = "confirm" | "cancel" | "close";
24
28
  /**
@@ -91,8 +95,9 @@ declare const useModalGlobalStore: zustand.UseBoundStore<zustand.StoreApi<ModalG
91
95
  interface ModalLoadingState {
92
96
  isOpen: boolean;
93
97
  message: string;
94
- openLoading: (message?: string) => void;
95
- closeLoading: () => void;
98
+ sessionId: number;
99
+ openLoading: (message?: string) => number;
100
+ closeLoading: (sessionId?: number) => void;
96
101
  }
97
102
  declare const useModalLoadingStore: zustand.UseBoundStore<zustand.StoreApi<ModalLoadingState>>;
98
103
 
@@ -100,9 +105,11 @@ interface ModalLoadingPercentageState {
100
105
  isOpen: boolean;
101
106
  message: string;
102
107
  percentage: number;
103
- openLoadingPercentage: (message?: string) => void;
104
- updatePercentage: (percentage: number) => void;
105
- closeLoadingPercentage: () => void;
108
+ /** ID de sesión actual — se incrementa en cada apertura */
109
+ sessionId: number;
110
+ openLoadingPercentage: (message?: string, initialPercentage?: number) => number;
111
+ updatePercentage: (percentage: number, sessionId?: number) => void;
112
+ closeLoadingPercentage: (sessionId?: number) => void;
106
113
  }
107
114
  declare const useModalLoadingPercentageStore: zustand.UseBoundStore<zustand.StoreApi<ModalLoadingPercentageState>>;
108
115
 
@@ -171,9 +178,9 @@ declare const isAlreadyHandled: () => boolean;
171
178
  * await api.save(data);
172
179
  * closeGlobalLoading();
173
180
  */
174
- declare const showGlobalLoading: (message?: string) => void;
175
- /** Close the global loading modal. */
176
- declare const closeGlobalLoading: () => void;
181
+ declare const showGlobalLoading: (message?: string) => number;
182
+ /** Close the global loading modal. If sessionId is provided, only closes if it matches. */
183
+ declare const closeGlobalLoading: (sessionId?: number) => void;
177
184
  /** Returns true if the global loading modal is currently visible. */
178
185
  declare const isGlobalLoadingOpen: () => boolean;
179
186
  /**
@@ -187,11 +194,17 @@ declare const isGlobalLoadingOpen: () => boolean;
187
194
  * }
188
195
  * closeGlobalLoadingPercentage();
189
196
  */
190
- declare const showGlobalLoadingPercentage: (message?: string) => void;
191
- /** Update the percentage value (0–100). Clamped automatically. */
192
- declare const updateGlobalLoadingPercentage: (percentage: number) => void;
193
- /** Close the global loading percentage modal. */
194
- declare const closeGlobalLoadingPercentage: () => void;
197
+ /**
198
+ * Abre el modal de loading con porcentaje. Retorna un sessionId para evitar
199
+ * interferencias si se abre otro modal del mismo tipo antes de cerrar el actual.
200
+ * Pasar el sessionId a updateGlobalLoadingPercentage y closeGlobalLoadingPercentage
201
+ * garantiza que solo la instancia activa pueda actualizar o cerrar el modal.
202
+ */
203
+ declare const showGlobalLoadingPercentage: (message?: string, initialPercentage?: number) => number;
204
+ /** Update the percentage value (0–100). Si se pasa sessionId y no coincide con la sesión activa, se ignora. */
205
+ declare const updateGlobalLoadingPercentage: (percentage: number, sessionId?: number) => void;
206
+ /** Close the global loading percentage modal. Si se pasa sessionId y no coincide con la sesión activa, se ignora. */
207
+ declare const closeGlobalLoadingPercentage: (sessionId?: number) => void;
195
208
  /** Returns true if the global loading percentage modal is currently visible. */
196
209
  declare const isGlobalLoadingPercentageOpen: () => boolean;
197
210
 
package/dist/modal.js CHANGED
@@ -50,19 +50,38 @@ var useModalGlobalStore = zustand.create((set, get) => ({
50
50
  set({ isOpen: false, payload: null, isTriState: false, _resolve: null, _resolveWithClose: null });
51
51
  }
52
52
  }));
53
- var useModalLoadingStore = zustand.create((set) => ({
53
+ var useModalLoadingStore = zustand.create((set, get) => ({
54
54
  isOpen: false,
55
55
  message: "Cargando...",
56
- openLoading: (message = "Cargando...") => set({ isOpen: true, message }),
57
- closeLoading: () => set({ isOpen: false, message: "Cargando..." })
56
+ sessionId: 0,
57
+ openLoading: (message = "Cargando...") => {
58
+ const nextId = get().sessionId + 1;
59
+ set({ isOpen: true, message, sessionId: nextId });
60
+ return nextId;
61
+ },
62
+ closeLoading: (sessionId) => {
63
+ if (sessionId !== void 0 && sessionId !== get().sessionId) return;
64
+ set({ isOpen: false, message: "Cargando..." });
65
+ }
58
66
  }));
59
- var useModalLoadingPercentageStore = zustand.create((set) => ({
67
+ var useModalLoadingPercentageStore = zustand.create((set, get) => ({
60
68
  isOpen: false,
61
69
  message: "Cargando...",
62
70
  percentage: 0,
63
- openLoadingPercentage: (message = "Cargando...") => set({ isOpen: true, message, percentage: 0 }),
64
- updatePercentage: (percentage) => set({ percentage: Math.min(100, Math.max(0, percentage)) }),
65
- closeLoadingPercentage: () => set({ isOpen: false, message: "Cargando...", percentage: 0 })
71
+ sessionId: 0,
72
+ openLoadingPercentage: (message = "Cargando...", initialPercentage = 0) => {
73
+ const nextId = get().sessionId + 1;
74
+ set({ isOpen: true, message, percentage: Math.min(100, Math.max(0, initialPercentage)), sessionId: nextId });
75
+ return nextId;
76
+ },
77
+ updatePercentage: (percentage, sessionId) => {
78
+ if (sessionId !== void 0 && sessionId !== get().sessionId) return;
79
+ set({ percentage: Math.min(100, Math.max(0, percentage)) });
80
+ },
81
+ closeLoadingPercentage: (sessionId) => {
82
+ if (sessionId !== void 0 && sessionId !== get().sessionId) return;
83
+ set({ isOpen: false, message: "Cargando...", percentage: 0 });
84
+ }
66
85
  }));
67
86
  var Portal = ({ children, container }) => {
68
87
  const [mounted, setMounted] = react.useState(false);
@@ -117,6 +136,7 @@ var Modal = ({
117
136
  }
118
137
  }, [isOpen, children]);
119
138
  react.useEffect(() => {
139
+ if (!animated) return;
120
140
  if (isOpen) {
121
141
  setMounted(true);
122
142
  const raf = requestAnimationFrame(() => {
@@ -131,7 +151,7 @@ var Modal = ({
131
151
  }, 200);
132
152
  return () => clearTimeout(timer);
133
153
  }
134
- }, [isOpen, onCloseComplete]);
154
+ }, [isOpen, animated, onCloseComplete]);
135
155
  react.useEffect(() => {
136
156
  if (!preventBodyScroll) return;
137
157
  if (isOpen) {
@@ -336,7 +356,8 @@ var Modal = ({
336
356
  disableFocusRestore,
337
357
  ariaLabelledBy
338
358
  ]);
339
- if (!mounted) return null;
359
+ if (!animated && !isOpen) return null;
360
+ if (animated && !mounted) return null;
340
361
  const contentClass = [
341
362
  "relative flex flex-col items-center justify-start",
342
363
  whitoutBackground ? "bg-transparent" : [
@@ -383,7 +404,7 @@ var Modal = ({
383
404
  "aria-describedby": props["aria-describedby"],
384
405
  "aria-label": props["aria-label"],
385
406
  children: [
386
- /* @__PURE__ */ jsxRuntime.jsx("div", { ref: contentRef, className: contentClass, children: cachedChildren }),
407
+ /* @__PURE__ */ jsxRuntime.jsx("div", { ref: contentRef, className: contentClass, children: isOpen ? children : cachedChildren }),
387
408
  closeButton && /* @__PURE__ */ jsxRuntime.jsx(
388
409
  "button",
389
410
  {
@@ -604,14 +625,21 @@ var ModalConfirm = ({
604
625
  children: title
605
626
  }
606
627
  ),
607
- effectiveMessage && /* @__PURE__ */ jsxRuntime.jsx(
628
+ effectiveMessage && (typeof effectiveMessage === "string" ? /* @__PURE__ */ jsxRuntime.jsx(
629
+ "div",
630
+ {
631
+ id: messageId,
632
+ className: `mt-7 text-sm md:text-lg max-w-full text-black ${alignJustify ? "text-justify" : "text-center"}`,
633
+ dangerouslySetInnerHTML: { __html: effectiveMessage }
634
+ }
635
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
608
636
  "div",
609
637
  {
610
638
  id: messageId,
611
639
  className: `mt-7 text-sm md:text-lg max-w-full text-black ${alignJustify ? "text-justify" : "text-center"}`,
612
640
  children: effectiveMessage
613
641
  }
614
- ),
642
+ )),
615
643
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center w-full gap-5 mt-11 md:hidden", children: [
616
644
  /* @__PURE__ */ jsxRuntime.jsx(
617
645
  Button,
@@ -724,7 +752,9 @@ var ModalLoadingPercentage = ({
724
752
  percentage,
725
753
  zIndexLevel = 300,
726
754
  animated = true,
727
- preventBodyScroll = true
755
+ preventBodyScroll = true,
756
+ alignTop = false,
757
+ renderContent
728
758
  }) => {
729
759
  const clamped = Math.min(100, Math.max(0, percentage));
730
760
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -739,7 +769,8 @@ var ModalLoadingPercentage = ({
739
769
  zIndexLevel,
740
770
  animated,
741
771
  preventBodyScroll,
742
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-6 px-4 w-full max-w-xs md:max-w-sm", children: [
772
+ alignTop,
773
+ children: renderContent ? renderContent(clamped, message) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-6 px-4 w-full max-w-xs md:max-w-sm", children: [
743
774
  /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-white text-5xl md:text-[80px] font-semibold leading-none", children: [
744
775
  clamped,
745
776
  "%"
@@ -768,15 +799,21 @@ var ModalGlobalProvider = ({
768
799
  zIndexLoadingPercentage = 300,
769
800
  animated = true,
770
801
  preventBodyScroll = true,
771
- loadingSpinner
802
+ loadingSpinner,
803
+ loadingPercentageAlignTop = false,
804
+ loadingPercentageContent
772
805
  }) => {
773
- const { isOpen, payload, modalId, isTriState, closeModal, closeModalWithResult } = useModalGlobalStore();
774
- const { isOpen: isLoadingOpen, message: loadingMessage } = useModalLoadingStore();
775
- const {
776
- isOpen: isPercentageOpen,
777
- message: percentageMessage,
778
- percentage
779
- } = useModalLoadingPercentageStore();
806
+ const isOpen = useModalGlobalStore((s) => s.isOpen);
807
+ const payload = useModalGlobalStore((s) => s.payload);
808
+ const modalId = useModalGlobalStore((s) => s.modalId);
809
+ const isTriState = useModalGlobalStore((s) => s.isTriState);
810
+ const closeModal = useModalGlobalStore((s) => s.closeModal);
811
+ const closeModalWithResult = useModalGlobalStore((s) => s.closeModalWithResult);
812
+ const isLoadingOpen = useModalLoadingStore((s) => s.isOpen);
813
+ const loadingMessage = useModalLoadingStore((s) => s.message);
814
+ const isPercentageOpen = useModalLoadingPercentageStore((s) => s.isOpen);
815
+ const percentageMessage = useModalLoadingPercentageStore((s) => s.message);
816
+ const percentage = useModalLoadingPercentageStore((s) => s.percentage);
780
817
  react.useEffect(() => {
781
818
  if (!isOpen || !payload?.autoConfirmTimeout) return;
782
819
  const timerId = setTimeout(async () => {
@@ -838,24 +875,40 @@ var ModalGlobalProvider = ({
838
875
  percentage,
839
876
  zIndexLevel: zIndexLoadingPercentage,
840
877
  animated,
841
- preventBodyScroll
878
+ preventBodyScroll,
879
+ alignTop: loadingPercentageAlignTop,
880
+ renderContent: loadingPercentageContent
842
881
  }
843
882
  )
844
883
  ] });
845
884
  };
846
885
 
847
886
  // src/utils/showGlobalModal.ts
848
- var showGlobalModal = (payload) => useModalGlobalStore.getState().openModal(payload);
849
- var showGlobalModalWithClose = (payload) => useModalGlobalStore.getState().openModalWithClose(payload);
887
+ var showGlobalModal = (payload) => {
888
+ useModalLoadingStore.getState().closeLoading();
889
+ useModalLoadingPercentageStore.getState().closeLoadingPercentage();
890
+ return useModalGlobalStore.getState().openModal(payload);
891
+ };
892
+ var showGlobalModalWithClose = (payload) => {
893
+ useModalLoadingStore.getState().closeLoading();
894
+ useModalLoadingPercentageStore.getState().closeLoadingPercentage();
895
+ return useModalGlobalStore.getState().openModalWithClose(payload);
896
+ };
850
897
  var closeGlobalModal = () => useModalGlobalStore.getState().closeModal(false);
851
898
  var isGlobalModalOpen = () => useModalGlobalStore.getState().isOpen;
852
899
  var isAlreadyHandled = () => useModalGlobalStore.getState().payload?.alreadyHandled ?? false;
853
- var showGlobalLoading = (message) => useModalLoadingStore.getState().openLoading(message);
854
- var closeGlobalLoading = () => useModalLoadingStore.getState().closeLoading();
900
+ var showGlobalLoading = (message) => {
901
+ useModalLoadingPercentageStore.getState().closeLoadingPercentage();
902
+ return useModalLoadingStore.getState().openLoading(message);
903
+ };
904
+ var closeGlobalLoading = (sessionId) => useModalLoadingStore.getState().closeLoading(sessionId);
855
905
  var isGlobalLoadingOpen = () => useModalLoadingStore.getState().isOpen;
856
- var showGlobalLoadingPercentage = (message) => useModalLoadingPercentageStore.getState().openLoadingPercentage(message);
857
- var updateGlobalLoadingPercentage = (percentage) => useModalLoadingPercentageStore.getState().updatePercentage(percentage);
858
- var closeGlobalLoadingPercentage = () => useModalLoadingPercentageStore.getState().closeLoadingPercentage();
906
+ var showGlobalLoadingPercentage = (message, initialPercentage) => {
907
+ useModalLoadingStore.getState().closeLoading();
908
+ return useModalLoadingPercentageStore.getState().openLoadingPercentage(message, initialPercentage);
909
+ };
910
+ var updateGlobalLoadingPercentage = (percentage, sessionId) => useModalLoadingPercentageStore.getState().updatePercentage(percentage, sessionId);
911
+ var closeGlobalLoadingPercentage = (sessionId) => useModalLoadingPercentageStore.getState().closeLoadingPercentage(sessionId);
859
912
  var isGlobalLoadingPercentageOpen = () => useModalLoadingPercentageStore.getState().isOpen;
860
913
 
861
914
  exports.ModalGlobalProvider = ModalGlobalProvider;