@ichaingo/with-login 1.4.65 → 1.4.68

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.
Files changed (2) hide show
  1. package/dist/index.js +34 -34
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,49 +1,49 @@
1
1
  'use client';
2
- import { jsx as m, jsxs as I } from "react/jsx-runtime";
3
- import M, { createContext as N, useState as w, useRef as R, useCallback as c, useEffect as p, useContext as O } from "react";
4
- import { useLocale as P } from "next-intl";
2
+ import { jsx as m, jsxs as y } from "react/jsx-runtime";
3
+ import I, { createContext as M, useState as w, useRef as N, useCallback as c, useEffect as p, useContext as R } from "react";
4
+ import { useLocale as O } from "next-intl";
5
5
  import { twMerge as $ } from "tailwind-merge";
6
- import { useTheme as y } from "@ichaingo/next-themes";
6
+ import { useTheme as P } from "@ichaingo/next-themes";
7
7
  import k from "js-cookie";
8
8
  const q = () => !!k.get("id_token");
9
- var A = /* @__PURE__ */ ((e) => (e.CLOSE_LOGIN_MODAL = "closeLoginModal", e.LOGIN_SUCCESS = "loginSuccess", e))(A || {}), B = /* @__PURE__ */ ((e) => (e.LOGIN = "login", e.REGISTER = "register", e))(B || {});
10
- const C = N(void 0);
9
+ var z = /* @__PURE__ */ ((e) => (e.CLOSE_LOGIN_MODAL = "closeLoginModal", e.LOGIN_SUCCESS = "loginSuccess", e))(z || {}), A = /* @__PURE__ */ ((e) => (e.LOGIN = "login", e.REGISTER = "register", e))(A || {});
10
+ const C = M(void 0);
11
11
  function F({ children: e, loginSuccessCallback: n = () => Promise.resolve() }) {
12
- const [i, s] = w(!1), [l, h] = w(!1), [a, v] = w(null), _ = R(/* @__PURE__ */ new Set()), u = P(), { resolvedTheme: U } = y(), t = l && U ? U : "light", L = c((o) => {
13
- const r = typeof window < "u" ? window.location.href : "", g = `${process.env.NEXT_PUBLIC_AUTH_URL}/${u}/login?mode=dialog&theme=${t}&redirect_uri=${r}`, f = `${process.env.NEXT_PUBLIC_AUTH_URL}/${u}/register?mode=dialog&theme=${t}&redirect_uri=${r}`;
12
+ const [i, s] = w(!1), [l, h] = w(!1), [a, v] = w(null), _ = N(/* @__PURE__ */ new Set()), u = O(), { resolvedTheme: U } = P(), r = l && U ? U : "light", L = c((o) => {
13
+ const t = typeof window < "u" ? window.location.href : "", g = `${process.env.NEXT_PUBLIC_AUTH_URL}/${u}/login?mode=dialog&theme=${r}&redirect_uri=${t}`, f = `${process.env.NEXT_PUBLIC_AUTH_URL}/${u}/register?mode=dialog&theme=${r}&redirect_uri=${t}`;
14
14
  s(!0), v(o === "register" ? f : g);
15
- }, [t, u]), d = c(() => {
15
+ }, [r, u]), d = c(() => {
16
16
  s(!1);
17
17
  }, []), E = c((o) => {
18
18
  s(o);
19
19
  }, []);
20
20
  p(() => {
21
- if (t) {
22
- const o = typeof window < "u" ? window.location.href : "", r = `${process.env.NEXT_PUBLIC_AUTH_URL}/${u}/login?mode=dialog&theme=${t}&redirect_uri=${o}`;
23
- v(r);
21
+ if (r) {
22
+ const o = typeof window < "u" ? window.location.href : "", t = `${process.env.NEXT_PUBLIC_AUTH_URL}/${u}/login?mode=dialog&theme=${r}&redirect_uri=${o}`;
23
+ v(t);
24
24
  }
25
- }, [t]), p(() => {
25
+ }, [r]), p(() => {
26
26
  h(!0);
27
- const o = (r) => {
27
+ const o = (t) => {
28
28
  var g, f;
29
- ((g = r.data) == null ? void 0 : g.type) === "closeLoginModal" && d(), ((f = r.data) == null ? void 0 : f.type) === "loginSuccess" && (console.log("handleMessage", r.data.type), d(), window.location.reload());
29
+ ((g = t.data) == null ? void 0 : g.type) === "closeLoginModal" && d(), ((f = t.data) == null ? void 0 : f.type) === "loginSuccess" && (console.log("handleMessage", t.data.type), d(), window.location.reload());
30
30
  };
31
31
  return window.addEventListener("message", o), () => {
32
32
  window.removeEventListener("message", o);
33
33
  };
34
34
  }, [d, n]);
35
- const x = c((o) => (_.current.add(o), () => {
35
+ const S = c((o) => (_.current.add(o), () => {
36
36
  _.current.delete(o);
37
- }), []), S = c(
38
- ({ children: o, ...r }) => /* @__PURE__ */ m("div", { onClick: () => L(), style: { cursor: "pointer" }, ...r, children: o }),
37
+ }), []), x = c(
38
+ ({ children: o, ...t }) => /* @__PURE__ */ m("div", { onClick: () => L(), style: { cursor: "pointer" }, ...t, children: o }),
39
39
  [L]
40
- ), T = M.useMemo(() => /* @__PURE__ */ m(
40
+ ), T = I.useMemo(() => /* @__PURE__ */ m(
41
41
  "div",
42
42
  {
43
43
  className: $(
44
- "fixed left-0 bottom-0 w-px h-px bg-[rgba(0,0,0,0.7)] z-1002",
45
- "transition-all duration-500 ease-in-out",
46
- i && "w-full h-full "
44
+ " left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full h-full bg-[rgba(0,0,0,0.7)] opacity-0 z-[-1]",
45
+ "transition-all duration-500 zoom-in-out fixed block",
46
+ i && "z-99999 opacity-100"
47
47
  ),
48
48
  children: a && /* @__PURE__ */ m(
49
49
  "iframe",
@@ -56,11 +56,11 @@ function F({ children: e, loginSuccessCallback: n = () => Promise.resolve() }) {
56
56
  title: "Login",
57
57
  sandbox: "allow-scripts allow-forms allow-same-origin"
58
58
  },
59
- `login-iframe-${t}`
59
+ `login-iframe-${r}`
60
60
  )
61
61
  }
62
62
  ), [
63
- t,
63
+ r,
64
64
  i,
65
65
  a
66
66
  ]), b = {
@@ -69,35 +69,35 @@ function F({ children: e, loginSuccessCallback: n = () => Promise.resolve() }) {
69
69
  closeLogin: d,
70
70
  setLoginOpen: E,
71
71
  url: a,
72
- currentTheme: t,
72
+ currentTheme: r,
73
73
  mounted: l,
74
- Trigger: S,
75
- registerLoginSuccessCallback: x
74
+ Trigger: x,
75
+ registerLoginSuccessCallback: S
76
76
  };
77
- return /* @__PURE__ */ I(C.Provider, { value: b, children: [
77
+ return /* @__PURE__ */ y(C.Provider, { value: b, children: [
78
78
  e,
79
79
  T
80
80
  ] });
81
81
  }
82
- function G() {
83
- const e = O(C);
82
+ function B() {
83
+ const e = R(C);
84
84
  if (e === void 0)
85
85
  throw new Error("useLogin must be used within a LoginProvider");
86
86
  return e;
87
87
  }
88
88
  function J({ children: e, onClick: n, ...i }) {
89
- const { Trigger: s, registerLoginSuccessCallback: l } = G();
89
+ const { Trigger: s, registerLoginSuccessCallback: l } = B();
90
90
  return p(() => {
91
91
  if (n)
92
92
  return l(n);
93
93
  }, [n, l]), e ? /* @__PURE__ */ m(s, { ...i, children: e }) : null;
94
94
  }
95
95
  export {
96
- A as LoginMessageType,
96
+ z as LoginMessageType,
97
97
  F as LoginProvider,
98
- B as OpenLoginType,
98
+ A as OpenLoginType,
99
99
  J as WithLogin,
100
100
  J as default,
101
101
  q as isLogin,
102
- G as useLogin
102
+ B as useLogin
103
103
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ichaingo/with-login",
3
- "version": "1.4.65",
3
+ "version": "1.4.68",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",