@levo-so/studio 0.3.18 → 0.3.20

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@levo-so/studio",
3
- "version": "0.3.18",
3
+ "version": "0.3.20",
4
4
  "author": "Levo Engineering <devs@theinternetfolks.com>",
5
5
  "description": "Levo Studio components and utilities for building block-based pages",
6
6
  "type": "module",
@@ -89,6 +89,7 @@
89
89
  "@assistant-ui/store": "0.3.13",
90
90
  "@assistant-ui/tap": "0.9.17",
91
91
  "remark-gfm": "4.0.1",
92
+ "@cashfreepayments/cashfree-js": "1.0.7",
92
93
  "@emotion/is-prop-valid": "1.3.1",
93
94
  "@stripe/react-stripe-js": "3.1.1",
94
95
  "@stripe/stripe-js": "5.5.0",
@@ -120,9 +121,9 @@
120
121
  "yup": "1.7.1"
121
122
  },
122
123
  "peerDependencies": {
123
- "@levo-so/insights": "0.3.18",
124
- "@levo-so/core": "0.3.18",
125
- "@levo-so/react": "0.3.18",
124
+ "@levo-so/insights": "0.3.20",
125
+ "@levo-so/core": "0.3.20",
126
+ "@levo-so/react": "0.3.20",
126
127
  "react": ">=19",
127
128
  "next": ">=14",
128
129
  "react-dom": ">=19"
@@ -0,0 +1,161 @@
1
+ "use client";
2
+ import { t as e } from "./cn-B6c1DjO_.js";
3
+ import { useCallback as t, useEffect as n, useMemo as r, useRef as i, useState as a } from "react";
4
+ import { jsx as o, jsxs as s } from "react/jsx-runtime";
5
+ import { XIcon as c } from "lucide-react";
6
+ import { Portal as l } from "radix-ui";
7
+ import { useRazorpay as u } from "react-razorpay";
8
+ import { EmbeddedCheckout as d, EmbeddedCheckoutProvider as f } from "@stripe/react-stripe-js";
9
+ //#region src/components/checkout/openCashfreeCheckout.ts
10
+ var p = async (e) => {
11
+ let { payment_session_id: t, order_id: n } = e;
12
+ if (!t || !n) throw Error("Cashfree payment session missing");
13
+ let { load: r } = await import("@cashfreepayments/cashfree-js"), i = await r({ mode: e.environment || "production" });
14
+ if (!i) throw Error("Cashfree checkout failed to load");
15
+ let a = await i.checkout({
16
+ paymentSessionId: t,
17
+ redirectTarget: "_modal"
18
+ });
19
+ return a.paymentDetails ? {
20
+ status: "completed",
21
+ confirmation: { order_id: n }
22
+ } : a.redirect ? { status: "redirect" } : {
23
+ status: "closed",
24
+ message: a.error?.message
25
+ };
26
+ }, m = () => typeof window < "u" && "Razorpay" in window, h = ({ order: e, onSettled: t, onError: r }) => {
27
+ let { Razorpay: a, isLoading: o, error: s } = u(), c = i({
28
+ onSettled: t,
29
+ onError: r
30
+ });
31
+ c.current = {
32
+ onSettled: t,
33
+ onError: r
34
+ };
35
+ let l = i(!1);
36
+ return n(() => {
37
+ if (l.current) return;
38
+ if (s) {
39
+ l.current = !0, c.current.onError(Error(s));
40
+ return;
41
+ }
42
+ if (!a || !m()) return;
43
+ l.current = !0;
44
+ let t;
45
+ try {
46
+ let n = new a({
47
+ key: e.key,
48
+ amount: e.amount,
49
+ currency: e.currency,
50
+ order_id: e.orderId,
51
+ name: e.merchantName,
52
+ description: e.description,
53
+ prefill: e.prefill,
54
+ theme: e.themeColor ? { color: e.themeColor } : void 0,
55
+ handler: (e) => c.current.onSettled({
56
+ status: "completed",
57
+ confirmation: {
58
+ order_id: e.razorpay_order_id,
59
+ payment_id: e.razorpay_payment_id,
60
+ signature: e.razorpay_signature
61
+ }
62
+ }),
63
+ modal: { ondismiss: () => c.current.onSettled({
64
+ status: "closed",
65
+ message: t
66
+ }) }
67
+ });
68
+ n.on("payment.failed", (e) => {
69
+ t = e?.error?.description;
70
+ }), n.open();
71
+ } catch (e) {
72
+ c.current.onError(e instanceof Error ? e : /* @__PURE__ */ Error("Razorpay checkout failed to open"));
73
+ }
74
+ }, [
75
+ a,
76
+ o,
77
+ s,
78
+ e
79
+ ]), null;
80
+ }, g = ({ stripePromise: t, clientSecret: n, onClose: a, onComplete: u }) => {
81
+ let p = i(u);
82
+ p.current = u;
83
+ let m = r(() => ({
84
+ clientSecret: n,
85
+ onComplete: () => p.current()
86
+ }), [n]);
87
+ return /* @__PURE__ */ o(l.Root, { children: /* @__PURE__ */ o("div", {
88
+ className: "fixed inset-0 z-[2147483001] flex items-start justify-center overflow-y-auto bg-black/50 p-4 pt-8 md:p-6 md:pt-10",
89
+ children: /* @__PURE__ */ s("div", {
90
+ className: e("relative flex w-full flex-col overflow-hidden rounded-2xl bg-white shadow-2xl", "max-w-[98vw] md:max-w-[1000px] lg:max-w-[1100px]", "min-h-[500px]", "my-auto", "fade-in-0 zoom-in-95 animate-in duration-200"),
91
+ children: [/* @__PURE__ */ o("button", {
92
+ type: "button",
93
+ onClick: a,
94
+ "aria-label": "Close payment",
95
+ className: "absolute top-4 right-4 z-10 rounded-full bg-white/90 p-2.5 text-gray-500 shadow-md backdrop-blur-sm transition-all hover:bg-white hover:text-gray-700",
96
+ children: /* @__PURE__ */ o(c, { className: "size-5" })
97
+ }), /* @__PURE__ */ o("div", {
98
+ className: "flex-1 overflow-hidden rounded-2xl py-6",
99
+ children: /* @__PURE__ */ o(f, {
100
+ stripe: t,
101
+ options: m,
102
+ children: /* @__PURE__ */ o(d, { className: "stripe-embedded-checkout h-full" })
103
+ })
104
+ })]
105
+ })
106
+ }) });
107
+ }, _ = () => {
108
+ let [e, n] = a(null), r = t(async (e, t) => {
109
+ if (e.provider === "cashfree") return p(e);
110
+ if (e.provider === "stripe") {
111
+ let { client_secret: t, session_id: r } = e;
112
+ if (!t || !r) throw Error("Stripe checkout session missing");
113
+ let { loadStripe: i } = await import("@stripe/stripe-js"), a = i(e.key);
114
+ return new Promise((e, i) => n({
115
+ provider: "stripe",
116
+ stripePromise: a,
117
+ clientSecret: t,
118
+ sessionId: r,
119
+ settle: {
120
+ resolve: e,
121
+ reject: i
122
+ }
123
+ }));
124
+ }
125
+ let { order_id: r } = e;
126
+ if (!r) throw Error("Razorpay order missing");
127
+ return new Promise((i, a) => n({
128
+ provider: "razorpay",
129
+ order: {
130
+ ...t,
131
+ key: e.key,
132
+ currency: e.currency || "INR",
133
+ orderId: r
134
+ },
135
+ settle: {
136
+ resolve: i,
137
+ reject: a
138
+ }
139
+ }));
140
+ }, []), i = (e, t) => {
141
+ n(null), t instanceof Error ? e.settle.reject(t) : e.settle.resolve(t);
142
+ }, s = null;
143
+ return e?.provider === "stripe" ? s = /* @__PURE__ */ o(g, {
144
+ stripePromise: e.stripePromise,
145
+ clientSecret: e.clientSecret,
146
+ onComplete: () => i(e, {
147
+ status: "completed",
148
+ confirmation: { session_id: e.sessionId }
149
+ }),
150
+ onClose: () => i(e, { status: "closed" })
151
+ }) : e?.provider === "razorpay" && (s = /* @__PURE__ */ o(h, {
152
+ order: e.order,
153
+ onSettled: (t) => i(e, t),
154
+ onError: (t) => i(e, t)
155
+ })), {
156
+ open: r,
157
+ element: s
158
+ };
159
+ };
160
+ //#endregion
161
+ export { _ as t };
@@ -1,56 +0,0 @@
1
- "use client";
2
- import { t as e } from "./cn-B6c1DjO_.js";
3
- import { useCallback as t, useState as n } from "react";
4
- import { jsx as r, jsxs as i } from "react/jsx-runtime";
5
- import { XIcon as a } from "lucide-react";
6
- import { Portal as o } from "radix-ui";
7
- import { EmbeddedCheckout as s, EmbeddedCheckoutProvider as c } from "@stripe/react-stripe-js";
8
- //#region src/hooks/useStripePayment.tsx
9
- var l = () => {
10
- let [e, r] = n(null), [i, a] = n(null), [o, s] = n(!1), [c, l] = n(null);
11
- return {
12
- stripePromise: e,
13
- config: i,
14
- isOpen: o,
15
- openStripeCheckout: t(async (e) => {
16
- try {
17
- let { loadStripe: t } = await import("@stripe/stripe-js");
18
- r(t(e.key)), a({ clientSecret: e.client_secret }), s(!0);
19
- } catch (e) {
20
- console.error("Failed to initialize Stripe checkout:", e);
21
- }
22
- }, []),
23
- closeStripeCheckout: t(() => {
24
- s(!1), setTimeout(() => {
25
- a(null), r(null);
26
- }, 300);
27
- }, []),
28
- onComplete: c,
29
- setOnComplete: t((e) => {
30
- l(() => e);
31
- }, [])
32
- };
33
- }, u = ({ isOpen: t, onClose: n, stripePromise: l, clientSecret: u, onComplete: d }) => !t || !l || !u ? null : /* @__PURE__ */ r(o.Root, { children: /* @__PURE__ */ r("div", {
34
- className: "fixed inset-0 z-[2147483001] flex items-start justify-center overflow-y-auto bg-black/50 p-4 pt-8 md:p-6 md:pt-10",
35
- children: /* @__PURE__ */ i("div", {
36
- className: e("relative flex w-full flex-col overflow-hidden rounded-2xl bg-white shadow-2xl", "max-w-[98vw] md:max-w-[1000px] lg:max-w-[1100px]", "min-h-[500px]", "my-auto", "fade-in-0 zoom-in-95 animate-in duration-200"),
37
- children: [/* @__PURE__ */ r("button", {
38
- type: "button",
39
- onClick: n,
40
- className: "absolute top-4 right-4 z-10 rounded-full bg-white/90 p-2.5 text-gray-500 shadow-md backdrop-blur-sm transition-all hover:bg-white hover:text-gray-700",
41
- children: /* @__PURE__ */ r(a, { className: "size-5" })
42
- }), /* @__PURE__ */ r("div", {
43
- className: "flex-1 overflow-hidden rounded-2xl py-6",
44
- children: /* @__PURE__ */ r(c, {
45
- stripe: l,
46
- options: {
47
- clientSecret: u,
48
- onComplete: d
49
- },
50
- children: /* @__PURE__ */ r(s, { className: "stripe-embedded-checkout h-full" })
51
- })
52
- })]
53
- })
54
- }) });
55
- //#endregion
56
- export { l as n, u as t };