@aikaara/chat-sdk 1.4.33 → 1.5.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.
- package/dist/{AikaaraLinkButton-CzDd0aue.mjs → AikaaraLinkButton--vcUguMg.mjs} +1 -1
- package/dist/{AikaaraLinkButton-CsQp2JnI.cjs → AikaaraLinkButton-BU0Njp0Y.cjs} +1 -1
- package/dist/AikaaraPaymentLink-D-tyM5fI.mjs +217 -0
- package/dist/AikaaraPaymentLink-Dq3uDB0c.cjs +1 -0
- package/dist/{MountTenant-DD2D52YE.mjs → MountTenant-CdW5PnSv.mjs} +7 -3
- package/dist/{MountTenant-CCmWpyVW.cjs → MountTenant-TQ5sAymp.cjs} +7 -3
- package/dist/cdn/aikaara-chat.iife.js +54 -50
- package/dist/headless.cjs +1 -1
- package/dist/headless.mjs +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +2 -2
- package/dist/ui.cjs +1 -1
- package/dist/ui.mjs +1 -1
- package/package.json +1 -1
- package/dist/AikaaraPaymentLink-C-GhGZ4c.cjs +0 -1
- package/dist/AikaaraPaymentLink-C82ApGKH.mjs +0 -155
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./MountTenant-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./MountTenant-TQ5sAymp.cjs");class l extends HTMLElement{shadow;payload=null;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render()}setPayload(e){this.payload=e,this.render()}render(){const e=this.payload;this.shadow.innerHTML=`
|
|
2
2
|
<style>
|
|
3
3
|
:host { display: block; margin-top: 8px; }
|
|
4
4
|
button {
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
const k = "https://checkout.razorpay.com/v1/checkout.js";
|
|
2
|
+
let f = null;
|
|
3
|
+
function m() {
|
|
4
|
+
return window;
|
|
5
|
+
}
|
|
6
|
+
class g extends HTMLElement {
|
|
7
|
+
shadow;
|
|
8
|
+
payloadData = [];
|
|
9
|
+
message = "";
|
|
10
|
+
// Per-payload-index lock so a successful payment disables only that
|
|
11
|
+
// button (other rows in the same template remain clickable).
|
|
12
|
+
paidIdx = {};
|
|
13
|
+
constructor() {
|
|
14
|
+
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
15
|
+
}
|
|
16
|
+
setPayload(e, n) {
|
|
17
|
+
this.payloadData = Array.isArray(e) ? e : [], this.message = n ?? "", this.render();
|
|
18
|
+
}
|
|
19
|
+
render() {
|
|
20
|
+
const e = this.payloadData.filter(
|
|
21
|
+
(t) => !!t && typeof t == "object" && t.type === "link" && typeof t.url == "string"
|
|
22
|
+
), n = e.map((t, i) => {
|
|
23
|
+
const o = t.name || "Open link", r = !!this.paidIdx[i];
|
|
24
|
+
return `<button class="link${r ? " paid" : ""}" data-i="${i}" type="button"${r ? " disabled" : ""}><span class="lbl">${b(r ? "Paid" : o)}</span>` + (r ? '<svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 8.5 L7 12 L13 5"/></svg>' : '<svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M5 11 L11 5 M6 5 H11 V10"/></svg>') + "</button>";
|
|
25
|
+
}).join("");
|
|
26
|
+
this.shadow.innerHTML = "<style>:host { display:block; margin:6px 0; font-family:inherit; }.bubble { padding:12px 16px; border-radius:14px; background:var(--aikaara-bot-bubble-bg, #d8e5f5); color:var(--aikaara-bot-bubble-text, #1a2845); font-size:14px; line-height:1.55; margin-bottom:10px; }.links { display:flex; flex-direction:column; gap:8px; }.link { display:inline-flex; align-items:center; justify-content:center; gap:8px; padding:11px 22px; border:1.5px solid var(--aikaara-primary, #1849a9); background:var(--aikaara-primary, #1849a9); color:var(--aikaara-primary-contrast, #fff); border-radius:24px; font-size:14px; font-weight:600; cursor:pointer; font-family:inherit; text-decoration:none; transition: filter 120ms; width:150px; align-self:flex-start; }.link:hover:not(:disabled) { filter: brightness(0.94); }.link.paid, .link:disabled { background:#e7f5ec; color:#0e7c3a; border-color:#0e7c3a; cursor:default; }.icon { width:13px; height:13px; }</style>" + (this.message ? `<div class="bubble">${this.message}</div>` : "") + `<div class="links">${n}</div>`, this.shadow.querySelectorAll(".link").forEach((t) => {
|
|
27
|
+
t.addEventListener("click", () => {
|
|
28
|
+
if (t.disabled) return;
|
|
29
|
+
const i = Number(t.dataset.i || 0), o = e[i];
|
|
30
|
+
o && this.handleClick(i, o);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
handleClick(e, n) {
|
|
35
|
+
const t = w(n), i = m().__aikaara_descriptor__, o = i?.partnerPayment, r = i?.razorpay;
|
|
36
|
+
if (t && o?.paymentLinkUrl) {
|
|
37
|
+
this.openPartnerPaymentLink(e, t, n, o);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!t || !r?.keyId) {
|
|
41
|
+
C(n.url, n.name || "Pay"), this.dispatchEvent(
|
|
42
|
+
new CustomEvent("template-action", {
|
|
43
|
+
detail: {
|
|
44
|
+
text: n.name || "link-click",
|
|
45
|
+
attributes: {
|
|
46
|
+
action: { type: "link", url: n.url, orderId: t || n.orderId, openedIn: "modal" }
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
bubbles: !0,
|
|
50
|
+
composed: !0
|
|
51
|
+
})
|
|
52
|
+
);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
_(r.preferredBanksUrl, t, r.preferredBanksMethod, r.preferredBanksHeaders).catch((s) => (console.warn("[payment_link] preferred-banks fetch failed; continuing with default UI", s), [])).then((s) => P().then(() => this.openRazorpay(e, t, r, s))).catch((s) => {
|
|
56
|
+
console.error("[payment_link] Razorpay launch failed", s);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
openPartnerPaymentLink(e, n, t, i) {
|
|
60
|
+
v(n, i).then((o) => {
|
|
61
|
+
if (!o) {
|
|
62
|
+
y("Failed to generate payment link, please try again later");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const r = (o.paymentStatus ?? "").toLowerCase();
|
|
66
|
+
if (r === "paid" || r === "success" || r === "completed") {
|
|
67
|
+
this.paidIdx[e] = !0, this.render(), y("Payment already completed");
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const s = o.vendorPaymentLink;
|
|
71
|
+
if (!s) {
|
|
72
|
+
y("Failed to generate payment link, please try again later");
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
x(s), this.dispatchEvent(
|
|
76
|
+
new CustomEvent("template-action", {
|
|
77
|
+
detail: {
|
|
78
|
+
text: t.name || "link-click",
|
|
79
|
+
attributes: {
|
|
80
|
+
action: { type: "partner-payment", url: s, orderId: n, openedIn: "external" }
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
bubbles: !0,
|
|
84
|
+
composed: !0
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
}).catch((o) => {
|
|
88
|
+
console.error("[payment_link] partner payment link fetch failed", o), y("Failed to generate payment link, please try again later");
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
openRazorpay(e, n, t, i) {
|
|
92
|
+
const o = m(), r = o.__aikaara_runtime__?.identity ?? {}, s = {
|
|
93
|
+
key: t.keyId,
|
|
94
|
+
order_id: n,
|
|
95
|
+
name: t.name || o.__aikaara_descriptor__?.title || "Payment",
|
|
96
|
+
prefill: {},
|
|
97
|
+
handler: () => {
|
|
98
|
+
this.paidIdx[e] = !0, this.render();
|
|
99
|
+
},
|
|
100
|
+
modal: {
|
|
101
|
+
// No auto-hide on dismiss: user can re-click Pay Now. Per spec,
|
|
102
|
+
// button only locks on confirmed success.
|
|
103
|
+
ondismiss: () => {
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
typeof r.mobile == "string" ? s.prefill.contact = r.mobile : typeof r.phone == "string" && (s.prefill.contact = r.phone), typeof r.email == "string" && (s.prefill.email = r.email), typeof r.name == "string" ? s.prefill.name = r.name : typeof r.userName == "string" && (s.prefill.name = r.userName), Array.isArray(i) && i.length && (s.config = {
|
|
108
|
+
display: {
|
|
109
|
+
blocks: {
|
|
110
|
+
utib: {
|
|
111
|
+
name: "Pay Using Preferred Netbanking",
|
|
112
|
+
instruments: [{ method: "netbanking", banks: i }]
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
sequence: ["block.utib", "netbanking", "card", "upi"],
|
|
116
|
+
preferences: { show_default_blocks: !0 }
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
const l = o.Razorpay;
|
|
120
|
+
if (typeof l != "function")
|
|
121
|
+
throw new Error("Razorpay Checkout script not available");
|
|
122
|
+
const c = new l(s);
|
|
123
|
+
c.on("payment.failed", (d) => {
|
|
124
|
+
console.warn("[payment_link] payment.failed", d?.error);
|
|
125
|
+
}), c.open();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function b(a) {
|
|
129
|
+
return String(a ?? "").replace(/[&<>]/g, (e) => e === "&" ? "&" : e === "<" ? "<" : ">");
|
|
130
|
+
}
|
|
131
|
+
function w(a) {
|
|
132
|
+
if (typeof a.orderId == "string" && a.orderId) return a.orderId;
|
|
133
|
+
try {
|
|
134
|
+
const e = new URL(a.url, window.location.origin), n = e.searchParams.get("orderId") || e.searchParams.get("order_id");
|
|
135
|
+
if (n) return n;
|
|
136
|
+
if (e.hash && e.hash.length > 1) {
|
|
137
|
+
const t = new URLSearchParams(e.hash.replace(/^#/, "")), i = t.get("orderId") || t.get("order_id");
|
|
138
|
+
if (i) return i;
|
|
139
|
+
}
|
|
140
|
+
} catch {
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
function P() {
|
|
145
|
+
return typeof m().Razorpay == "function" ? Promise.resolve() : f || (f = new Promise((a, e) => {
|
|
146
|
+
const n = document.querySelector('script[data-aikaara-razorpay="1"]');
|
|
147
|
+
if (n) {
|
|
148
|
+
n.addEventListener("load", () => a()), n.addEventListener("error", () => e(new Error("checkout.js failed to load")));
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const t = document.createElement("script");
|
|
152
|
+
t.src = k, t.async = !0, t.dataset.aikaaraRazorpay = "1", t.onload = () => a(), t.onerror = () => {
|
|
153
|
+
f = null, e(new Error("checkout.js failed to load"));
|
|
154
|
+
}, document.head.appendChild(t);
|
|
155
|
+
}), f);
|
|
156
|
+
}
|
|
157
|
+
function _(a, e, n, t) {
|
|
158
|
+
if (!a) return Promise.resolve([]);
|
|
159
|
+
const i = String(n || "GET").toUpperCase() === "POST" ? "POST" : "GET", o = a.includes("{orderId}") ? a.replace("{orderId}", encodeURIComponent(e)) : a + (a.includes("?") ? "&" : "?") + "orderId=" + encodeURIComponent(e), r = m().__aikaara_runtime__ ?? {};
|
|
160
|
+
return (typeof r.getSessionToken == "function" ? r.getSessionToken() : typeof r.getChatJwt == "function" ? r.getChatJwt() : Promise.resolve(null)).then((l) => {
|
|
161
|
+
const c = { Accept: "application/json", ...t ?? {} };
|
|
162
|
+
l && (c.Authorization = `Bearer ${l}`);
|
|
163
|
+
const d = { method: i, headers: c, credentials: "omit" };
|
|
164
|
+
return i === "POST" && (c["Content-Type"] = "application/json", d.body = JSON.stringify({ orderId: e })), fetch(o, d);
|
|
165
|
+
}).then((l) => {
|
|
166
|
+
if (!l.ok) throw new Error(`preferred-banks ${l.status}`);
|
|
167
|
+
return l.json();
|
|
168
|
+
}).then((l) => {
|
|
169
|
+
const c = l, d = c?.data && typeof c.data == "object" && !Array.isArray(c.data) ? c.data : null;
|
|
170
|
+
return (Array.isArray(l) ? l : Array.isArray(c?.banks) ? c.banks : Array.isArray(c?.data) ? c.data : Array.isArray(d?.preferredPaymentBank) ? d.preferredPaymentBank : Array.isArray(d?.banks) ? d.banks : []).map((p) => {
|
|
171
|
+
if (typeof p == "string") return p;
|
|
172
|
+
if (p && typeof p == "object") {
|
|
173
|
+
const h = p;
|
|
174
|
+
return h.code || h.bankCode || h.bank_code || null;
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}).filter((p) => !!p);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
async function v(a, e) {
|
|
181
|
+
const n = String(e.method || "GET").toUpperCase() === "POST" ? "POST" : "GET", t = e.paymentLinkUrl, i = t.includes("{orderId}") ? t.replace("{orderId}", encodeURIComponent(a)) : t + (t.includes("?") ? "&" : "?") + "orderId=" + encodeURIComponent(a), o = m().__aikaara_runtime__ ?? {}, r = typeof o.getSessionToken == "function" ? await o.getSessionToken() : typeof o.getChatJwt == "function" ? await o.getChatJwt() : null, s = { Accept: "application/json", ...e.headers ?? {} };
|
|
182
|
+
r && (s.Authorization = `Bearer ${r}`);
|
|
183
|
+
const l = { method: n, headers: s, credentials: "omit" };
|
|
184
|
+
n === "POST" && (s["Content-Type"] = "application/json", l.body = JSON.stringify({ orderId: a }));
|
|
185
|
+
const c = await fetch(i, l);
|
|
186
|
+
if (!c.ok) throw new Error(`partner-payment-link ${c.status}`);
|
|
187
|
+
const u = (await c.json())?.data;
|
|
188
|
+
return !u || typeof u.vendorPaymentLink != "string" ? null : { vendorPaymentLink: u.vendorPaymentLink, paymentStatus: u.paymentStatus ?? "" };
|
|
189
|
+
}
|
|
190
|
+
function x(a) {
|
|
191
|
+
if (typeof window > "u") return;
|
|
192
|
+
const e = navigator.userAgent.toLowerCase();
|
|
193
|
+
e.includes("iphone") || e.includes("ipad") || e.includes("ipod") ? window.location.href = a : window.open(a, "_blank", "noopener,noreferrer");
|
|
194
|
+
}
|
|
195
|
+
function y(a) {
|
|
196
|
+
try {
|
|
197
|
+
const e = document.querySelector("aikaara-error-banner");
|
|
198
|
+
if (e && typeof e.show == "function") {
|
|
199
|
+
e.show(a);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
} catch {
|
|
203
|
+
}
|
|
204
|
+
console.warn("[payment_link]", a);
|
|
205
|
+
}
|
|
206
|
+
function C(a, e) {
|
|
207
|
+
if (!a) return;
|
|
208
|
+
let n = document.querySelector("aikaara-link-modal");
|
|
209
|
+
n || (n = document.createElement("aikaara-link-modal"), document.body.appendChild(n)), typeof n.show == "function" ? n.show(a, e) : window.open(a, "_blank", "noopener,noreferrer");
|
|
210
|
+
}
|
|
211
|
+
function S() {
|
|
212
|
+
typeof customElements > "u" || customElements.get("aikaara-template-payment-link") || customElements.define("aikaara-template-payment-link", g);
|
|
213
|
+
}
|
|
214
|
+
export {
|
|
215
|
+
g as AikaaraPaymentLink,
|
|
216
|
+
S as registerAikaaraPaymentLink
|
|
217
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g="https://checkout.razorpay.com/v1/checkout.js";let f=null;function m(){return window}class k extends HTMLElement{shadow;payloadData=[];message="";paidIdx={};constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}setPayload(e,n){this.payloadData=Array.isArray(e)?e:[],this.message=n??"",this.render()}render(){const e=this.payloadData.filter(t=>!!t&&typeof t=="object"&&t.type==="link"&&typeof t.url=="string"),n=e.map((t,i)=>{const o=t.name||"Open link",r=!!this.paidIdx[i];return`<button class="link${r?" paid":""}" data-i="${i}" type="button"${r?" disabled":""}><span class="lbl">${b(r?"Paid":o)}</span>`+(r?'<svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 8.5 L7 12 L13 5"/></svg>':'<svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M5 11 L11 5 M6 5 H11 V10"/></svg>')+"</button>"}).join("");this.shadow.innerHTML="<style>:host { display:block; margin:6px 0; font-family:inherit; }.bubble { padding:12px 16px; border-radius:14px; background:var(--aikaara-bot-bubble-bg, #d8e5f5); color:var(--aikaara-bot-bubble-text, #1a2845); font-size:14px; line-height:1.55; margin-bottom:10px; }.links { display:flex; flex-direction:column; gap:8px; }.link { display:inline-flex; align-items:center; justify-content:center; gap:8px; padding:11px 22px; border:1.5px solid var(--aikaara-primary, #1849a9); background:var(--aikaara-primary, #1849a9); color:var(--aikaara-primary-contrast, #fff); border-radius:24px; font-size:14px; font-weight:600; cursor:pointer; font-family:inherit; text-decoration:none; transition: filter 120ms; width:150px; align-self:flex-start; }.link:hover:not(:disabled) { filter: brightness(0.94); }.link.paid, .link:disabled { background:#e7f5ec; color:#0e7c3a; border-color:#0e7c3a; cursor:default; }.icon { width:13px; height:13px; }</style>"+(this.message?`<div class="bubble">${this.message}</div>`:"")+`<div class="links">${n}</div>`,this.shadow.querySelectorAll(".link").forEach(t=>{t.addEventListener("click",()=>{if(t.disabled)return;const i=Number(t.dataset.i||0),o=e[i];o&&this.handleClick(i,o)})})}handleClick(e,n){const t=w(n),i=m().__aikaara_descriptor__,o=i?.partnerPayment,r=i?.razorpay;if(t&&o?.paymentLinkUrl){this.openPartnerPaymentLink(e,t,n,o);return}if(!t||!r?.keyId){C(n.url,n.name||"Pay"),this.dispatchEvent(new CustomEvent("template-action",{detail:{text:n.name||"link-click",attributes:{action:{type:"link",url:n.url,orderId:t||n.orderId,openedIn:"modal"}}},bubbles:!0,composed:!0}));return}_(r.preferredBanksUrl,t,r.preferredBanksMethod,r.preferredBanksHeaders).catch(s=>(console.warn("[payment_link] preferred-banks fetch failed; continuing with default UI",s),[])).then(s=>P().then(()=>this.openRazorpay(e,t,r,s))).catch(s=>{console.error("[payment_link] Razorpay launch failed",s)})}openPartnerPaymentLink(e,n,t,i){v(n,i).then(o=>{if(!o){y("Failed to generate payment link, please try again later");return}const r=(o.paymentStatus??"").toLowerCase();if(r==="paid"||r==="success"||r==="completed"){this.paidIdx[e]=!0,this.render(),y("Payment already completed");return}const s=o.vendorPaymentLink;if(!s){y("Failed to generate payment link, please try again later");return}x(s),this.dispatchEvent(new CustomEvent("template-action",{detail:{text:t.name||"link-click",attributes:{action:{type:"partner-payment",url:s,orderId:n,openedIn:"external"}}},bubbles:!0,composed:!0}))}).catch(o=>{console.error("[payment_link] partner payment link fetch failed",o),y("Failed to generate payment link, please try again later")})}openRazorpay(e,n,t,i){const o=m(),r=o.__aikaara_runtime__?.identity??{},s={key:t.keyId,order_id:n,name:t.name||o.__aikaara_descriptor__?.title||"Payment",prefill:{},handler:()=>{this.paidIdx[e]=!0,this.render()},modal:{ondismiss:()=>{}}};typeof r.mobile=="string"?s.prefill.contact=r.mobile:typeof r.phone=="string"&&(s.prefill.contact=r.phone),typeof r.email=="string"&&(s.prefill.email=r.email),typeof r.name=="string"?s.prefill.name=r.name:typeof r.userName=="string"&&(s.prefill.name=r.userName),Array.isArray(i)&&i.length&&(s.config={display:{blocks:{utib:{name:"Pay Using Preferred Netbanking",instruments:[{method:"netbanking",banks:i}]}},sequence:["block.utib","netbanking","card","upi"],preferences:{show_default_blocks:!0}}});const l=o.Razorpay;if(typeof l!="function")throw new Error("Razorpay Checkout script not available");const c=new l(s);c.on("payment.failed",d=>{console.warn("[payment_link] payment.failed",d?.error)}),c.open()}}function b(a){return String(a??"").replace(/[&<>]/g,e=>e==="&"?"&":e==="<"?"<":">")}function w(a){if(typeof a.orderId=="string"&&a.orderId)return a.orderId;try{const e=new URL(a.url,window.location.origin),n=e.searchParams.get("orderId")||e.searchParams.get("order_id");if(n)return n;if(e.hash&&e.hash.length>1){const t=new URLSearchParams(e.hash.replace(/^#/,"")),i=t.get("orderId")||t.get("order_id");if(i)return i}}catch{}return null}function P(){return typeof m().Razorpay=="function"?Promise.resolve():f||(f=new Promise((a,e)=>{const n=document.querySelector('script[data-aikaara-razorpay="1"]');if(n){n.addEventListener("load",()=>a()),n.addEventListener("error",()=>e(new Error("checkout.js failed to load")));return}const t=document.createElement("script");t.src=g,t.async=!0,t.dataset.aikaaraRazorpay="1",t.onload=()=>a(),t.onerror=()=>{f=null,e(new Error("checkout.js failed to load"))},document.head.appendChild(t)}),f)}function _(a,e,n,t){if(!a)return Promise.resolve([]);const i=String(n||"GET").toUpperCase()==="POST"?"POST":"GET",o=a.includes("{orderId}")?a.replace("{orderId}",encodeURIComponent(e)):a+(a.includes("?")?"&":"?")+"orderId="+encodeURIComponent(e),r=m().__aikaara_runtime__??{};return(typeof r.getSessionToken=="function"?r.getSessionToken():typeof r.getChatJwt=="function"?r.getChatJwt():Promise.resolve(null)).then(l=>{const c={Accept:"application/json",...t??{}};l&&(c.Authorization=`Bearer ${l}`);const d={method:i,headers:c,credentials:"omit"};return i==="POST"&&(c["Content-Type"]="application/json",d.body=JSON.stringify({orderId:e})),fetch(o,d)}).then(l=>{if(!l.ok)throw new Error(`preferred-banks ${l.status}`);return l.json()}).then(l=>{const c=l,d=c?.data&&typeof c.data=="object"&&!Array.isArray(c.data)?c.data:null;return(Array.isArray(l)?l:Array.isArray(c?.banks)?c.banks:Array.isArray(c?.data)?c.data:Array.isArray(d?.preferredPaymentBank)?d.preferredPaymentBank:Array.isArray(d?.banks)?d.banks:[]).map(p=>{if(typeof p=="string")return p;if(p&&typeof p=="object"){const h=p;return h.code||h.bankCode||h.bank_code||null}return null}).filter(p=>!!p)})}async function v(a,e){const n=String(e.method||"GET").toUpperCase()==="POST"?"POST":"GET",t=e.paymentLinkUrl,i=t.includes("{orderId}")?t.replace("{orderId}",encodeURIComponent(a)):t+(t.includes("?")?"&":"?")+"orderId="+encodeURIComponent(a),o=m().__aikaara_runtime__??{},r=typeof o.getSessionToken=="function"?await o.getSessionToken():typeof o.getChatJwt=="function"?await o.getChatJwt():null,s={Accept:"application/json",...e.headers??{}};r&&(s.Authorization=`Bearer ${r}`);const l={method:n,headers:s,credentials:"omit"};n==="POST"&&(s["Content-Type"]="application/json",l.body=JSON.stringify({orderId:a}));const c=await fetch(i,l);if(!c.ok)throw new Error(`partner-payment-link ${c.status}`);const u=(await c.json())?.data;return!u||typeof u.vendorPaymentLink!="string"?null:{vendorPaymentLink:u.vendorPaymentLink,paymentStatus:u.paymentStatus??""}}function x(a){if(typeof window>"u")return;const e=navigator.userAgent.toLowerCase();e.includes("iphone")||e.includes("ipad")||e.includes("ipod")?window.location.href=a:window.open(a,"_blank","noopener,noreferrer")}function y(a){try{const e=document.querySelector("aikaara-error-banner");if(e&&typeof e.show=="function"){e.show(a);return}}catch{}console.warn("[payment_link]",a)}function C(a,e){if(!a)return;let n=document.querySelector("aikaara-link-modal");n||(n=document.createElement("aikaara-link-modal"),document.body.appendChild(n)),typeof n.show=="function"?n.show(a,e):window.open(a,"_blank","noopener,noreferrer")}function S(){typeof customElements>"u"||customElements.get("aikaara-template-payment-link")||customElements.define("aikaara-template-payment-link",k)}exports.AikaaraPaymentLink=k;exports.registerAikaaraPaymentLink=S;
|
|
@@ -14491,7 +14491,7 @@ function Ed(s, e = 5e3) {
|
|
|
14491
14491
|
});
|
|
14492
14492
|
}
|
|
14493
14493
|
const Ad = {
|
|
14494
|
-
"aikaara-template-payment-link": () => import("./AikaaraPaymentLink-
|
|
14494
|
+
"aikaara-template-payment-link": () => import("./AikaaraPaymentLink-D-tyM5fI.mjs").then(({ registerAikaaraPaymentLink: s }) => s())
|
|
14495
14495
|
};
|
|
14496
14496
|
function Id(s) {
|
|
14497
14497
|
const e = `template:${s}`, t = window.__aikaara_descriptor__?.components?.[e];
|
|
@@ -14685,7 +14685,7 @@ class Td extends HTMLElement {
|
|
|
14685
14685
|
*/
|
|
14686
14686
|
mountLinkButton(e) {
|
|
14687
14687
|
const t = this.renderGen;
|
|
14688
|
-
import("./AikaaraLinkButton
|
|
14688
|
+
import("./AikaaraLinkButton--vcUguMg.mjs").then(({ registerAikaaraLinkButton: r, AikaaraLinkButton: o }) => {
|
|
14689
14689
|
if (t !== this.renderGen) return;
|
|
14690
14690
|
r();
|
|
14691
14691
|
const n = document.createElement("aikaara-link-button");
|
|
@@ -15967,7 +15967,7 @@ class Vd extends HTMLElement {
|
|
|
15967
15967
|
this.render();
|
|
15968
15968
|
}
|
|
15969
15969
|
setSchema(e) {
|
|
15970
|
-
this.schema = e, this.isRepeatable() && !Array.isArray(this.value) ? this.value = [] : !this.isRepeatable() && Array.isArray(this.value) && (this.value = {}), this.render();
|
|
15970
|
+
this.collapsed.clear(), this.collapseSeeded.clear(), this.schema = e, this.isRepeatable() && !Array.isArray(this.value) ? this.value = [] : !this.isRepeatable() && Array.isArray(this.value) && (this.value = {}), this.render();
|
|
15971
15971
|
}
|
|
15972
15972
|
setValue(e) {
|
|
15973
15973
|
this.isRepeatable() ? (this.value = Array.isArray(e) ? [...e] : [], this.value.length === 0 && this.value.push({})) : this.value = e && typeof e == "object" ? { ...e } : {}, this.render();
|
|
@@ -16270,6 +16270,10 @@ class Vd extends HTMLElement {
|
|
|
16270
16270
|
padding: 8px 13px 0;
|
|
16271
16271
|
}
|
|
16272
16272
|
.group-body { padding: 12px 13px; display: flex; flex-direction: column; gap: 12px; }
|
|
16273
|
+
/* The display:flex above is an author rule and so beats the UA
|
|
16274
|
+
stylesheet's [hidden] rule. Without this, the hidden attribute
|
|
16275
|
+
toggles but nothing moves and a collapsible group looks stuck open. */
|
|
16276
|
+
.group-body[hidden] { display: none; }
|
|
16273
16277
|
.group--collapsible { padding: 0; }
|
|
16274
16278
|
.group-toggle {
|
|
16275
16279
|
width: 100%; display: flex; align-items: center; justify-content: space-between;
|
|
@@ -743,7 +743,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
743
743
|
<span class="message"></span>
|
|
744
744
|
<button class="dismiss">Dismiss</button>
|
|
745
745
|
</div>
|
|
746
|
-
`,this.container=this.shadow.querySelector(".banner"),this.shadow.querySelector(".dismiss")?.addEventListener("click",()=>this.hide())}show(e,t){const r=this.container.querySelector(".message");r&&(r.textContent=e),this.container.classList.add("visible"),this.dismissTimer&&clearTimeout(this.dismissTimer),t&&(this.dismissTimer=setTimeout(()=>this.hide(),t))}hide(){this.container.classList.remove("visible"),this.dismissTimer&&(clearTimeout(this.dismissTimer),this.dismissTimer=null)}}const an=new Map;function ic(s){const e=an.get(s);if(e)return e;const t=new Promise((r,o)=>{const n=document.querySelector(`script[data-aikaara-src="${CSS.escape(s)}"]`);if(n){n.dataset.aikaaraReady==="1"?r():(n.addEventListener("load",()=>r(),{once:!0}),n.addEventListener("error",()=>o(new Error(`Failed to load ${s}`)),{once:!0}));return}const i=document.createElement("script");i.src=s,i.async=!0,i.crossOrigin="anonymous",i.dataset.aikaaraSrc=s,i.addEventListener("load",()=>{i.dataset.aikaaraReady="1",r()},{once:!0}),i.addEventListener("error",()=>{an.delete(s),o(new Error(`Failed to load ${s}`))},{once:!0}),document.head.appendChild(i)});return an.set(s,t),t}function Wd(s,e=5e3){return new Promise((t,r)=>{const o=setTimeout(()=>r(new Error(`Custom element <${s}> not registered within ${e}ms`)),e);customElements.whenDefined(s).then(()=>{clearTimeout(o),t()})})}const zd={"aikaara-template-payment-link":()=>Promise.resolve().then(()=>require("./AikaaraPaymentLink-
|
|
746
|
+
`,this.container=this.shadow.querySelector(".banner"),this.shadow.querySelector(".dismiss")?.addEventListener("click",()=>this.hide())}show(e,t){const r=this.container.querySelector(".message");r&&(r.textContent=e),this.container.classList.add("visible"),this.dismissTimer&&clearTimeout(this.dismissTimer),t&&(this.dismissTimer=setTimeout(()=>this.hide(),t))}hide(){this.container.classList.remove("visible"),this.dismissTimer&&(clearTimeout(this.dismissTimer),this.dismissTimer=null)}}const an=new Map;function ic(s){const e=an.get(s);if(e)return e;const t=new Promise((r,o)=>{const n=document.querySelector(`script[data-aikaara-src="${CSS.escape(s)}"]`);if(n){n.dataset.aikaaraReady==="1"?r():(n.addEventListener("load",()=>r(),{once:!0}),n.addEventListener("error",()=>o(new Error(`Failed to load ${s}`)),{once:!0}));return}const i=document.createElement("script");i.src=s,i.async=!0,i.crossOrigin="anonymous",i.dataset.aikaaraSrc=s,i.addEventListener("load",()=>{i.dataset.aikaaraReady="1",r()},{once:!0}),i.addEventListener("error",()=>{an.delete(s),o(new Error(`Failed to load ${s}`))},{once:!0}),document.head.appendChild(i)});return an.set(s,t),t}function Wd(s,e=5e3){return new Promise((t,r)=>{const o=setTimeout(()=>r(new Error(`Custom element <${s}> not registered within ${e}ms`)),e);customElements.whenDefined(s).then(()=>{clearTimeout(o),t()})})}const zd={"aikaara-template-payment-link":()=>Promise.resolve().then(()=>require("./AikaaraPaymentLink-Dq3uDB0c.cjs")).then(({registerAikaaraPaymentLink:s})=>s())};function Vd(s){const e=`template:${s}`,t=window.__aikaara_descriptor__?.components?.[e];return t&&t.kind==="iife-element"?{render:t.tag,scriptUrl:t.scriptUrl,props:t.props}:window.__aikaara_descriptor__?.templates?.[s]}class oc extends HTMLElement{shadow;payloadData=null;innerMessage="";renderGen=0;_consumedValues=null;static get observedAttributes(){return["content-type","template-id","message-id"]}constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render(),this.addEventListener("template-action",e=>{const t=e.detail,r=this.getAttribute("message-id");if(r&&t?.attributes?.action){const o=Yd(t.attributes.action);if(Object.keys(o).length>0)try{localStorage.setItem(`aikaara_form:${r}`,JSON.stringify(o))}catch{}}this.dataset.consumed="true",this._applyConsumedToChildren()})}attributeChangedCallback(){this.render()}setPayload(e,t){this.payloadData=e,t!==void 0&&(this.innerMessage=t),this.render()}setConsumedValues(e){this._consumedValues=e,this._applyConsumedToChildren()}_applyConsumedToChildren(){let e=this._consumedValues;if(!e){const r=this.getAttribute("message-id");if(r)try{const o=localStorage.getItem(`aikaara_form:${r}`);o&&(e=JSON.parse(o))}catch{}}if(e){const r=e;this.querySelectorAll("aikaara-option-list").forEach(o=>{const n=o,i=n.getName?.();i&&r[i]?.length&&n.setPreSelected?.(r[i])})}this.querySelectorAll("aikaara-submit-action, aikaara-modal-action, aikaara-link-button").forEach(r=>{r.style.display="none"});const t=new Set(["aikaara-option-list","aikaara-submit-action","aikaara-modal-action","aikaara-link-button"]);this.querySelectorAll("*").forEach(r=>{if(t.has(r.tagName.toLowerCase()))return;e&&r.setConsumedValues?.(e),r.dataset.consumed="true"})}render(){const e=this.getAttribute("content-type")??"",t=this.getAttribute("template-id")??"";for(this.renderGen+=1,this.shadow.innerHTML=`
|
|
747
747
|
<style>
|
|
748
748
|
:host { display: block; }
|
|
749
749
|
::slotted(*) { display: block; }
|
|
@@ -757,7 +757,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
757
757
|
}
|
|
758
758
|
</style>
|
|
759
759
|
<slot></slot>
|
|
760
|
-
`;this.firstChild;)this.removeChild(this.firstChild);if(!e)return;const r=t?Vd(t):void 0,o=r?.render??(t?`aikaara-template-${t}`:`aikaara-template-${e}`),n=zd[o];if(n&&!customElements.get(o)?n().then(()=>this.render()).catch(i=>console.warn(`[aikaara-template-renderer] native template ${o} failed to load`,i)):r?.scriptUrl&&!customElements.get(o)&&ic(r.scriptUrl).then(()=>Wd(o)).then(()=>this.render()).catch(i=>console.warn(`[aikaara-template-renderer] failed to lazy-load ${r.scriptUrl}`,i)),customElements.get(o)){const i=document.createElement(o);if(r?.props){for(const[a,l]of Object.entries(r.props))if(typeof i[a]=="function")try{i[a](l)}catch(c){console.warn(`[aikaara-template-renderer] props.${a} threw on <${o}>`,c)}}i.setPayload?.(this.payloadData,this.innerMessage),this.appendChild(i),this.dataset.consumed==="true"&&(this._consumedValues&&Object.keys(this._consumedValues).length>0&&i.setConsumedValues?.(this._consumedValues),i.dataset.consumed="true");return}if(Array.isArray(this.payloadData)){const i=this.payloadData;if(i.length>0&&i.every(l=>l&&typeof l=="object"&&!Array.isArray(l)&&!("type"in l)&&!("data"in l)&&typeof l.message=="string")){const l=document.createElement("aikaara-option-list");l.setPayload({name:"quick-reply",type:"button",options:i.map(c=>{const u=typeof c.title=="string"?c.title:"",h=c.message;return{label:u||h,value:h}})}),this.appendChild(l);return}for(const l of i)this.mountField(l)}else if(this.payloadData&&typeof this.payloadData=="object"){const i=this.payloadData;typeof i.message=="string"&&(i.okLabel||i.action||i.ok)&&this.mountModal(i)}this.dataset.consumed==="true"&&this._applyConsumedToChildren()}mountField(e){if(!e||typeof e!="object")return;const t=e.type??e.data?.type;if(t==="link"){this.mountLinkButton(e);return}const r=e.data;if(r){if(t==="text"){const o=document.createElement("aikaara-text-input");o.setPayload(r),this.appendChild(o);return}if(t==="checkbox"||t==="radio"||t==="button"){const o=document.createElement("aikaara-option-list");o.setPayload({name:r.name??"",title:r.title,options:r.options??[],type:t}),this.appendChild(o);return}if(t==="submit"){const o=document.createElement("aikaara-submit-action"),n=this.getAttribute("message-id")??void 0;o.setPayload({name:r.name??"Submit",action:r.action??{message:r.name??"Submit"},messageId:n}),this.appendChild(o);return}t==="modal"&&this.mountModal({message:r.message??"",okLabel:r.okLabel,cancelLabel:r.cancelLabel,action:r.action})}}mountLinkButton(e){const t=this.renderGen;Promise.resolve().then(()=>require("./AikaaraLinkButton-
|
|
760
|
+
`;this.firstChild;)this.removeChild(this.firstChild);if(!e)return;const r=t?Vd(t):void 0,o=r?.render??(t?`aikaara-template-${t}`:`aikaara-template-${e}`),n=zd[o];if(n&&!customElements.get(o)?n().then(()=>this.render()).catch(i=>console.warn(`[aikaara-template-renderer] native template ${o} failed to load`,i)):r?.scriptUrl&&!customElements.get(o)&&ic(r.scriptUrl).then(()=>Wd(o)).then(()=>this.render()).catch(i=>console.warn(`[aikaara-template-renderer] failed to lazy-load ${r.scriptUrl}`,i)),customElements.get(o)){const i=document.createElement(o);if(r?.props){for(const[a,l]of Object.entries(r.props))if(typeof i[a]=="function")try{i[a](l)}catch(c){console.warn(`[aikaara-template-renderer] props.${a} threw on <${o}>`,c)}}i.setPayload?.(this.payloadData,this.innerMessage),this.appendChild(i),this.dataset.consumed==="true"&&(this._consumedValues&&Object.keys(this._consumedValues).length>0&&i.setConsumedValues?.(this._consumedValues),i.dataset.consumed="true");return}if(Array.isArray(this.payloadData)){const i=this.payloadData;if(i.length>0&&i.every(l=>l&&typeof l=="object"&&!Array.isArray(l)&&!("type"in l)&&!("data"in l)&&typeof l.message=="string")){const l=document.createElement("aikaara-option-list");l.setPayload({name:"quick-reply",type:"button",options:i.map(c=>{const u=typeof c.title=="string"?c.title:"",h=c.message;return{label:u||h,value:h}})}),this.appendChild(l);return}for(const l of i)this.mountField(l)}else if(this.payloadData&&typeof this.payloadData=="object"){const i=this.payloadData;typeof i.message=="string"&&(i.okLabel||i.action||i.ok)&&this.mountModal(i)}this.dataset.consumed==="true"&&this._applyConsumedToChildren()}mountField(e){if(!e||typeof e!="object")return;const t=e.type??e.data?.type;if(t==="link"){this.mountLinkButton(e);return}const r=e.data;if(r){if(t==="text"){const o=document.createElement("aikaara-text-input");o.setPayload(r),this.appendChild(o);return}if(t==="checkbox"||t==="radio"||t==="button"){const o=document.createElement("aikaara-option-list");o.setPayload({name:r.name??"",title:r.title,options:r.options??[],type:t}),this.appendChild(o);return}if(t==="submit"){const o=document.createElement("aikaara-submit-action"),n=this.getAttribute("message-id")??void 0;o.setPayload({name:r.name??"Submit",action:r.action??{message:r.name??"Submit"},messageId:n}),this.appendChild(o);return}t==="modal"&&this.mountModal({message:r.message??"",okLabel:r.okLabel,cancelLabel:r.cancelLabel,action:r.action})}}mountLinkButton(e){const t=this.renderGen;Promise.resolve().then(()=>require("./AikaaraLinkButton-BU0Njp0Y.cjs")).then(({registerAikaaraLinkButton:r,AikaaraLinkButton:o})=>{if(t!==this.renderGen)return;r();const n=document.createElement("aikaara-link-button");n.setPayload({name:e.name??"Open",url:e.url??"",openLinkInNewTab:e.openLinkInNewTab,orderId:e.orderId,extra:Gd(e),messageId:this.getAttribute("message-id")??void 0}),this.appendChild(n)})}mountModal(e){const t=document.createElement("aikaara-modal-action");t.setPayload(e),this.appendChild(t)}}const Kd=new Set(["type","url","name","openLinkInNewTab","orderId"]);function Gd(s){const e={};for(const[t,r]of Object.entries(s))Kd.has(t)||(e[t]=r);return e}function Yd(s){const e=new Set(["message_id","formAction","requestType","serviceType"]),t={};for(const[r,o]of Object.entries(s))e.has(r)||(Array.isArray(o)&&o.every(n=>typeof n=="string")?t[r]=o:typeof o=="string"&&(t[r]=[o]));return t}class sc extends HTMLElement{shadow;static get observedAttributes(){return["text","subtext"]}constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render()}attributeChangedCallback(){this.render()}render(){const e=this.getAttribute("text")??this.textContent??"",t=this.getAttribute("subtext")??"";this.shadow.innerHTML=`
|
|
761
761
|
<style>
|
|
762
762
|
:host {
|
|
763
763
|
display: flex;
|
|
@@ -1321,7 +1321,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
1321
1321
|
border-radius: 16px 16px 0 0;
|
|
1322
1322
|
}
|
|
1323
1323
|
}
|
|
1324
|
-
`}}const Qs='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',Zd='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>';function ef(s){return s.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function Xs(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}class mc extends HTMLElement{shadow;schema=null;value={};errors=new Map;collapsed=new Set;collapseSeeded=new Set;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render()}setSchema(e){this.schema=e,this.isRepeatable()&&!Array.isArray(this.value)?this.value=[]:!this.isRepeatable()&&Array.isArray(this.value)&&(this.value={}),this.render()}setValue(e){this.isRepeatable()?(this.value=Array.isArray(e)?[...e]:[],this.value.length===0&&this.value.push({})):this.value=e&&typeof e=="object"?{...e}:{},this.render()}isRepeatable(){return!!this.schema?.repeatable&&this.schema.repeatable.maxCount>0}getEntries(){return this.isRepeatable()?this.value:[this.value]}setEntry(e,t,r){this.setEntryNoRender(e,t,r),this.render()}setEntryNoRender(e,t,r){const o=this.getEntries(),n={...o[e]||{}};n[t]=r,o[e]=n,this.isRepeatable()?this.value=o:this.value=n}addEntry(){if(!this.isRepeatable()||!this.schema?.repeatable)return;const e=this.getEntries();e.length>=this.schema.repeatable.maxCount||(e.push({}),this.value=e,this.render())}removeEntry(e){if(!this.isRepeatable())return;const t=this.getEntries();t.length<=1||(t.splice(e,1),this.value=t,this.render())}fieldVisible(e,t){const r=i=>{if(!i)return null;const a=t[i.field];return"equals"in i?a===i.equals:Array.isArray(i.in)?i.in.includes(a):null};return!(r(e.showWhen)===!1||r(e.hideWhen)===!0)}validate(){return this.errors.clear(),this.getEntries().forEach((t,r)=>{this.walkFields(this.schema?.fields||[],o=>{if(!this.fieldVisible(o,t)||o.type==="group")return;const n=t[o.id],i=`${r}.${o.id}`;if(o.required&&(n==null||n==="")){this.errors.set(i,"Required");return}if(o.type==="text"&&typeof n=="string"&&(o.pattern&&n&&!new RegExp(o.pattern).test(n)?this.errors.set(i,"Invalid format"):o.maxLength&&n.length>o.maxLength&&this.errors.set(i,`Max ${o.maxLength} characters`)),o.type==="textarea"&&typeof n=="string"&&o.maxLength&&n.length>o.maxLength&&this.errors.set(i,`Max ${o.maxLength} characters`),o.type==="number"&&n!==void 0&&n!==null&&n!==""){const a=typeof n=="number"?n:Number(n),l=o;Number.isNaN(a)?this.errors.set(i,"Must be a number"):l.min!==void 0&&a<l.min?this.errors.set(i,`Minimum ${l.min}`):l.max!==void 0&&a>l.max&&this.errors.set(i,`Maximum ${l.max.toLocaleString("en-IN")}`)}})}),this.errors.size===0}walkFields(e,t){for(const r of e)t(r),r.type==="group"&&this.walkFields(r.fields,t)}handleSubmit(){if(!this.schema)return;if(!this.validate()){this.render(),this.shadow.querySelector(".field.has-error")?.scrollIntoView({behavior:"smooth",block:"center"});return}const e=this.isRepeatable()?this.getEntries():this.value;this.dispatchEvent(new CustomEvent("aikaara-form-submit",{detail:{sectionId:this.schema.id,value:e},bubbles:!0,composed:!0}))}render(){if(!this.schema){this.shadow.innerHTML="<style>:host{display:block;}</style>";return}const e=this.getEntries(),t=e.map((o,n)=>this.renderEntry(o,n)).join(""),r=this.isRepeatable()&&e.length<(this.schema.repeatable?.maxCount||1);this.shadow.innerHTML=`
|
|
1324
|
+
`}}const Qs='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',Zd='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>';function ef(s){return s.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function Xs(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}class mc extends HTMLElement{shadow;schema=null;value={};errors=new Map;collapsed=new Set;collapseSeeded=new Set;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render()}setSchema(e){this.collapsed.clear(),this.collapseSeeded.clear(),this.schema=e,this.isRepeatable()&&!Array.isArray(this.value)?this.value=[]:!this.isRepeatable()&&Array.isArray(this.value)&&(this.value={}),this.render()}setValue(e){this.isRepeatable()?(this.value=Array.isArray(e)?[...e]:[],this.value.length===0&&this.value.push({})):this.value=e&&typeof e=="object"?{...e}:{},this.render()}isRepeatable(){return!!this.schema?.repeatable&&this.schema.repeatable.maxCount>0}getEntries(){return this.isRepeatable()?this.value:[this.value]}setEntry(e,t,r){this.setEntryNoRender(e,t,r),this.render()}setEntryNoRender(e,t,r){const o=this.getEntries(),n={...o[e]||{}};n[t]=r,o[e]=n,this.isRepeatable()?this.value=o:this.value=n}addEntry(){if(!this.isRepeatable()||!this.schema?.repeatable)return;const e=this.getEntries();e.length>=this.schema.repeatable.maxCount||(e.push({}),this.value=e,this.render())}removeEntry(e){if(!this.isRepeatable())return;const t=this.getEntries();t.length<=1||(t.splice(e,1),this.value=t,this.render())}fieldVisible(e,t){const r=i=>{if(!i)return null;const a=t[i.field];return"equals"in i?a===i.equals:Array.isArray(i.in)?i.in.includes(a):null};return!(r(e.showWhen)===!1||r(e.hideWhen)===!0)}validate(){return this.errors.clear(),this.getEntries().forEach((t,r)=>{this.walkFields(this.schema?.fields||[],o=>{if(!this.fieldVisible(o,t)||o.type==="group")return;const n=t[o.id],i=`${r}.${o.id}`;if(o.required&&(n==null||n==="")){this.errors.set(i,"Required");return}if(o.type==="text"&&typeof n=="string"&&(o.pattern&&n&&!new RegExp(o.pattern).test(n)?this.errors.set(i,"Invalid format"):o.maxLength&&n.length>o.maxLength&&this.errors.set(i,`Max ${o.maxLength} characters`)),o.type==="textarea"&&typeof n=="string"&&o.maxLength&&n.length>o.maxLength&&this.errors.set(i,`Max ${o.maxLength} characters`),o.type==="number"&&n!==void 0&&n!==null&&n!==""){const a=typeof n=="number"?n:Number(n),l=o;Number.isNaN(a)?this.errors.set(i,"Must be a number"):l.min!==void 0&&a<l.min?this.errors.set(i,`Minimum ${l.min}`):l.max!==void 0&&a>l.max&&this.errors.set(i,`Maximum ${l.max.toLocaleString("en-IN")}`)}})}),this.errors.size===0}walkFields(e,t){for(const r of e)t(r),r.type==="group"&&this.walkFields(r.fields,t)}handleSubmit(){if(!this.schema)return;if(!this.validate()){this.render(),this.shadow.querySelector(".field.has-error")?.scrollIntoView({behavior:"smooth",block:"center"});return}const e=this.isRepeatable()?this.getEntries():this.value;this.dispatchEvent(new CustomEvent("aikaara-form-submit",{detail:{sectionId:this.schema.id,value:e},bubbles:!0,composed:!0}))}render(){if(!this.schema){this.shadow.innerHTML="<style>:host{display:block;}</style>";return}const e=this.getEntries(),t=e.map((o,n)=>this.renderEntry(o,n)).join(""),r=this.isRepeatable()&&e.length<(this.schema.repeatable?.maxCount||1);this.shadow.innerHTML=`
|
|
1325
1325
|
<style>${this.css()}</style>
|
|
1326
1326
|
<div class="container">
|
|
1327
1327
|
<div class="scroll">
|
|
@@ -1472,6 +1472,10 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
1472
1472
|
padding: 8px 13px 0;
|
|
1473
1473
|
}
|
|
1474
1474
|
.group-body { padding: 12px 13px; display: flex; flex-direction: column; gap: 12px; }
|
|
1475
|
+
/* The display:flex above is an author rule and so beats the UA
|
|
1476
|
+
stylesheet's [hidden] rule. Without this, the hidden attribute
|
|
1477
|
+
toggles but nothing moves and a collapsible group looks stuck open. */
|
|
1478
|
+
.group-body[hidden] { display: none; }
|
|
1475
1479
|
.group--collapsible { padding: 0; }
|
|
1476
1480
|
.group-toggle {
|
|
1477
1481
|
width: 100%; display: flex; align-items: center; justify-content: space-between;
|