@smart-factor/gem-ui-components 0.0.143 → 0.0.145

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.
@@ -2,7 +2,7 @@ import './assets/SignEditor.css';var N4 = Object.defineProperty;
2
2
  var I4 = (o, e, t) => e in o ? N4(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
3
  var Eu = (o, e, t) => I4(o, typeof e != "symbol" ? e + "" : e, t);
4
4
  import { jsx as Vt, jsxs as ia, Fragment as o_ } from "react/jsx-runtime";
5
- import { G as Ib, u as i_, a as rA, Q as uc, b as hs, c as Lp, D as KE, B as sp, d as ow, e as M4, z as Dc, f as a_, s as $E, I as Of, A as WE, F as O4, U as Ax, g as q4, h as R4, i as Q4, j as G4, T as V4, K as D4, k as H4 } from "./index-D8LvCb2N.js";
5
+ import { G as Ib, u as i_, a as rA, Q as uc, b as hs, c as Lp, D as KE, B as sp, d as ow, e as M4, z as Dc, f as a_, s as $E, I as Of, A as WE, F as O4, U as Ax, g as q4, h as R4, i as Q4, j as G4, T as V4, K as D4, k as H4 } from "./index-D2k25Xjg.js";
6
6
  import { q as XE, s as Di, I as tu, J as r_, H as YE, S as lp } from "./Stack-Bsa5WF4E.js";
7
7
  import { createContext as U4, useContext as z4, useState as vl, useCallback as zu, useEffect as oc, useMemo as cp, useRef as K4 } from "react";
8
8
  import "react-dom";
@@ -5,6 +5,5 @@ export type SessionModalProps = {
5
5
  onSessionRenewed?: () => void;
6
6
  onSessionTerminated?: () => void;
7
7
  onSessionRenewClick?: () => void;
8
- whitelist?: string[];
9
8
  };
10
9
  export declare const SessionModal: import('react').ComponentType<SessionModalProps>;
@@ -0,0 +1,13 @@
1
+ export type UseSessionModalOptions = {
2
+ activated?: boolean;
3
+ loginUrl?: string;
4
+ };
5
+ /**
6
+ * Session modal and redirect logic:
7
+ * - Listens to session events (storage + custom event)
8
+ * - Shows modal when session expires during current run
9
+ * - Redirects to login when page loaded with already-expired session
10
+ */
11
+ export declare const useSessionModal: (whitelist?: string[], options?: UseSessionModalOptions) => {
12
+ showModal: boolean;
13
+ };
@@ -272953,6 +272953,24 @@ function withQueryClientProvider(s0) {
272953
272953
  const o0 = (r0) => /* @__PURE__ */ jsx(QueryClientProvider, { children: /* @__PURE__ */ jsx(s0, { ...r0 }) });
272954
272954
  return o0.displayName = `withQueryClientProvider(${s0.displayName || s0.name || "Component"})`, o0;
272955
272955
  }
272956
+ function useDidUpdate(s0, o0) {
272957
+ const r0 = useRef(void 0), l0 = useRef(!1);
272958
+ useEffect(() => {
272959
+ if (!l0.current) {
272960
+ l0.current = !0, r0.current = s0;
272961
+ return;
272962
+ }
272963
+ const u0 = r0.current;
272964
+ if (u0 !== s0)
272965
+ try {
272966
+ o0(u0, s0);
272967
+ } finally {
272968
+ r0.current = s0;
272969
+ }
272970
+ else
272971
+ r0.current = s0;
272972
+ }, [o0, s0]);
272973
+ }
272956
272974
  const ContentWrapper$1 = styled$1("div")(({ theme: s0 }) => ({
272957
272975
  padding: s0.spacing(3),
272958
272976
  display: "flex",
@@ -278023,54 +278041,6 @@ const o7 = class o7 {
278023
278041
  };
278024
278042
  Wl(o7, "SESSION_TERMINATED_REASON", "session-terminated");
278025
278043
  let SessionService = o7;
278026
- const useSessionModalOpen = (s0, o0 = []) => {
278027
- const r0 = s0 && !o0.includes(window.location.pathname), [l0, u0] = React__default.useState(r0), i0 = useCallback(
278028
- (F0) => {
278029
- if (o0.includes(window.location.pathname)) {
278030
- u0(!1);
278031
- return;
278032
- }
278033
- switch (F0.status) {
278034
- case "EXPIRED":
278035
- console.info("[SessionModal] Session expired"), u0(!0);
278036
- break;
278037
- case "AUTHORIZED":
278038
- console.info("[SessionModal] Session authorized"), u0(!1);
278039
- break;
278040
- }
278041
- },
278042
- [o0]
278043
- );
278044
- return useEffect(() => {
278045
- const F0 = (W0) => i0(W0.detail), $0 = (W0) => {
278046
- if (W0.key === SESSION_LOCAL_STORAGE_KEY) {
278047
- const J0 = getSession();
278048
- i0(J0);
278049
- }
278050
- };
278051
- return window.addEventListener(SESSION_CHANGED_EVENT, F0), window.addEventListener("storage", $0), () => {
278052
- window.removeEventListener(SESSION_CHANGED_EVENT, F0), window.removeEventListener("storage", $0);
278053
- };
278054
- }, [i0]), l0;
278055
- };
278056
- function useDidUpdate(s0, o0) {
278057
- const r0 = useRef(void 0), l0 = useRef(!1);
278058
- useEffect(() => {
278059
- if (!l0.current) {
278060
- l0.current = !0, r0.current = s0;
278061
- return;
278062
- }
278063
- const u0 = r0.current;
278064
- if (u0 !== s0)
278065
- try {
278066
- o0(u0, s0);
278067
- } finally {
278068
- r0.current = s0;
278069
- }
278070
- else
278071
- r0.current = s0;
278072
- }, [o0, s0]);
278073
- }
278074
278044
  function useSession() {
278075
278045
  const [s0, o0] = useState(
278076
278046
  () => SessionService.getSession()
@@ -278089,34 +278059,68 @@ function useSession() {
278089
278059
  };
278090
278060
  }, []), s0;
278091
278061
  }
278092
- const SessionModalBase = ({
278062
+ const useSessionExpiredInCurrentRun = () => {
278063
+ const { status: s0 } = useSession(), { current: o0 } = useRef(s0);
278064
+ return o0 !== "EXPIRED" && s0 === "EXPIRED";
278065
+ }, useSessionModal = (s0 = [], o0 = {}) => {
278066
+ const { activated: r0 = !0, loginUrl: l0 } = o0, { status: u0 } = useSession(), i0 = useSessionExpiredInCurrentRun(), [F0, $0] = useState(
278067
+ () => u0 === "EXPIRED" && !s0.includes(window.location.pathname)
278068
+ ), W0 = useCallback(
278069
+ (c1) => {
278070
+ if (s0.includes(window.location.pathname)) {
278071
+ $0(!1);
278072
+ return;
278073
+ }
278074
+ switch (c1.status) {
278075
+ case "EXPIRED":
278076
+ $0(!0);
278077
+ break;
278078
+ case "AUTHORIZED":
278079
+ $0(!1);
278080
+ break;
278081
+ }
278082
+ },
278083
+ [s0]
278084
+ );
278085
+ useEffect(() => {
278086
+ const c1 = (f1) => W0(f1.detail), X0 = (f1) => {
278087
+ f1.key === SESSION_LOCAL_STORAGE_KEY && W0(getSession());
278088
+ };
278089
+ return window.addEventListener(SESSION_CHANGED_EVENT, c1), window.addEventListener("storage", X0), () => {
278090
+ window.removeEventListener(SESSION_CHANGED_EVENT, c1), window.removeEventListener("storage", X0);
278091
+ };
278092
+ }, [W0]);
278093
+ const J0 = r0 && F0 && i0, t1 = r0 && F0 && !i0;
278094
+ return useEffect(() => {
278095
+ t1 && l0 && (window.location.href = SessionService.buildLoginUrl(l0));
278096
+ }, [t1, l0]), { showModal: J0 };
278097
+ }, SessionModalBase = ({
278093
278098
  activated: s0 = !0,
278094
278099
  loginUrl: o0,
278095
278100
  onSessionRenewClick: r0,
278096
278101
  onSessionRenewed: l0,
278097
- onSessionTerminated: u0,
278098
- whitelist: i0 = []
278102
+ onSessionTerminated: u0
278099
278103
  }) => {
278100
- const F0 = SessionService.getLoginPathname(o0), $0 = [.../* @__PURE__ */ new Set([F0, ...i0])], { status: W0 } = useSession(), J0 = useSessionModalOpen(
278101
- W0 === "EXPIRED",
278102
- $0
278103
- ), t1 = s0 && J0, c1 = useTheme$2(), X0 = useMediaQuery(c1.breakpoints.down("sm")), f1 = useCallback(
278104
- (d1, g1) => {
278105
- g1 ? u0 == null || u0() : l0 == null || l0();
278104
+ const i0 = SessionService.getLoginPathname(o0), F0 = useMemo(() => [i0], [i0]), { showModal: $0 } = useSessionModal(F0, {
278105
+ activated: s0,
278106
+ loginUrl: o0
278107
+ }), W0 = useTheme$2(), J0 = useMediaQuery(W0.breakpoints.down("sm")), t1 = useCallback(
278108
+ (X0, f1) => {
278109
+ f1 ? u0 == null || u0() : l0 == null || l0();
278106
278110
  },
278107
278111
  [u0, l0]
278108
278112
  );
278109
- useDidUpdate(t1, f1);
278110
- const h1 = useCallback(() => {
278113
+ useDidUpdate($0, t1);
278114
+ const c1 = useCallback(() => {
278111
278115
  window.open(SessionService.buildLoginUrl(o0), "_blank"), r0 == null || r0();
278112
278116
  }, [o0, r0]);
278113
278117
  return /* @__PURE__ */ jsx(
278114
278118
  Dialog$2,
278115
278119
  {
278116
- open: t1,
278120
+ open: $0,
278117
278121
  PaperProps: {
278118
278122
  sx: {
278119
- borderRadius: X0 ? 0 : 3,
278123
+ borderRadius: J0 ? 0 : 3,
278120
278124
  boxShadow: 6,
278121
278125
  padding: 0,
278122
278126
  zIndex: 9999
@@ -278132,7 +278136,7 @@ const SessionModalBase = ({
278132
278136
  variant: "contained",
278133
278137
  color: "primary",
278134
278138
  startIcon: /* @__PURE__ */ jsx(LoginIcon, {}),
278135
- onClick: h1,
278139
+ onClick: c1,
278136
278140
  sx: { mt: 1 },
278137
278141
  children: "Odnów sesję"
278138
278142
  }
package/dist/main.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx as d, jsxs as I, Fragment as We } from "react/jsx-runtime";
2
2
  import { P as l, R as Kn, U as Xn, V as Zn, W as Qn, y as eo, X as to, q as ne, T as Pe, Y as ro, Z as no, $ as oo, c as Tt, g as Ct, e as Se, A as Ee, k as $e, s as oe, l as Le, o as ce, t as so, a0 as Xr, D as ao, F as Z, N as Ae, a1 as io, a2 as co, a3 as Wt, a4 as qt, J as Oe, a5 as hr, a6 as lo, L as uo, w as ye, K as Ue, H as Zr, i as xt, I as le, a7 as fo, S as Jt, a8 as qe, _ as po } from "./Stack-Bsa5WF4E.js";
3
- import { l as ho, r as mo, L as go, m as bo, n as et, S as yo, o as vo, p as So, q as To, t as Co, v as Et, w as xo, x as wo, B as Be, j as Mo, d as mr, y as Oo, C as Qr, E as Ve, H as Je, J as Te, M as en, N as Po, O as ae, P as De, R as Eo, V as ve, W as Kt, X as mt, Y as tn, Z as Ie, _ as gt, $ as Ao, a0 as Xt, a1 as rn, a2 as $o, a3 as Lo, a4 as Do, a5 as L, a6 as Me, z as nn, b as Io, e as jo, G as _o, a7 as No, K as ko, a8 as Ro, a9 as se, aa as on, ab as Zt, i as sn, ac as je, ad as zo, ae as Yo, af as Bo, ag as Fo, F as Uo, ah as wt, ai as Vo, aj as Go, ak as Ho, al as an, am as Wo, an as cn, ao as ln, ap as qo, aq as Jo, ar as Ko, as as dn, at as Xo, au as Zo, av as Qo, aw as es, ax as ts, ay as rs, az as ns, aA as os, aB as ss, aC as as, h as is, aD as cs, aE as un, aF as fn, aG as pn, aH as tt, aI as ls, aJ as ds, aK as us } from "./index-D8LvCb2N.js";
4
- import { aW as Jf, b0 as Kf, A as Xf, D as Zf, aX as Qf, g as ep, aY as tp, aL as rp, I as np, aM as op, aN as sp, aO as ap, aP as ip, aQ as cp, aR as lp, aT as dp, T as up, U as fp, aZ as pp, a$ as hp, aV as mp, a_ as gp, aU as bp, aS as yp } from "./index-D8LvCb2N.js";
3
+ import { l as ho, r as mo, L as go, m as bo, n as et, S as yo, o as vo, p as So, q as To, t as Co, v as Et, w as xo, x as wo, B as Be, j as Mo, d as mr, y as Oo, C as Qr, E as Ve, H as Je, J as Te, M as en, N as Po, O as ae, P as De, R as Eo, V as ve, W as Kt, X as mt, Y as tn, Z as Ie, _ as gt, $ as Ao, a0 as Xt, a1 as rn, a2 as $o, a3 as Lo, a4 as Do, a5 as L, a6 as Me, z as nn, b as Io, e as jo, G as _o, a7 as No, K as ko, a8 as Ro, a9 as se, aa as on, ab as Zt, i as sn, ac as je, ad as zo, ae as Yo, af as Bo, ag as Fo, F as Uo, ah as wt, ai as Vo, aj as Go, ak as Ho, al as an, am as Wo, an as cn, ao as ln, ap as qo, aq as Jo, ar as Ko, as as dn, at as Xo, au as Zo, av as Qo, aw as es, ax as ts, ay as rs, az as ns, aA as os, aB as ss, aC as as, h as is, aD as cs, aE as un, aF as fn, aG as pn, aH as tt, aI as ls, aJ as ds, aK as us } from "./index-D2k25Xjg.js";
4
+ import { aW as Jf, b0 as Kf, A as Xf, D as Zf, aX as Qf, g as ep, aY as tp, aL as rp, I as np, aM as op, aN as sp, aO as ap, aP as ip, aQ as cp, aR as lp, aT as dp, T as up, U as fp, aZ as pp, a$ as hp, aV as mp, a_ as gp, aU as bp, aS as yp } from "./index-D2k25Xjg.js";
5
5
  import * as E from "react";
6
6
  import { useState as B, useCallback as de, useEffect as Q, useLayoutEffect as Ge, useMemo as te } from "react";
7
7
  import { e as hn, P as mn, i as fs } from "./Drawer-DbJg-t8M.js";
@@ -0,0 +1 @@
1
+ export declare const useSessionExpiredInCurrentRun: () => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart-factor/gem-ui-components",
3
- "version": "0.0.143",
3
+ "version": "0.0.145",
4
4
  "private": false,
5
5
  "description": "Gem UI Components",
6
6
  "type": "module",
@@ -1 +0,0 @@
1
- export declare const useSessionModalOpen: (initialValue: boolean, whitelist?: string[]) => boolean;