@gengage/assistant-fe 0.4.21 → 0.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/README.md +1 -1
- package/dist/{api-paths-Bg6iwO5w.js → api-paths-y5nkfEBG.js} +1 -1
- package/dist/chat-runtime.js +1 -1
- package/dist/chat.iife.js +43 -43
- package/dist/chat.js +1 -1
- package/dist/common-BKPSOoIP.js +324 -0
- package/dist/common.js +64 -81
- package/dist/{connection-warning-BeD-B0Ec.js → connection-warning-DJiyLM46.js} +1 -1
- package/dist/{fastIntent-BeeDIwd2.js → fastIntent-1T2g9art.js} +2 -2
- package/dist/index.js +49 -52
- package/dist/{native-webview-Bbcvvi_5.js → native-webview-y3a9R9hH.js} +1 -1
- package/dist/native.iife.js +23 -23
- package/dist/native.js +1 -1
- package/dist/{overlay-O4nlUrzw.js → overlay-v3nvcGlE.js} +2 -5
- package/dist/overlay.js +2 -2
- package/dist/qna-runtime.js +1 -1
- package/dist/qna.iife.js +36 -36
- package/dist/qna.js +1 -1
- package/dist/{runtime-C8ZBidd2.js → runtime-BMNOS2Mq.js} +176 -196
- package/dist/runtime-DOS9yRRx.js +650 -0
- package/dist/{runtime-Ct1qOl8V.js → runtime-DsP6go8z.js} +2194 -2225
- package/dist/{simbut-BrAeZ6SH.js → simbut-BwxzoBcY.js} +7 -7
- package/dist/simbut.iife.js +12 -12
- package/dist/simbut.js +1 -1
- package/dist/{simrel-Cha5de6P.js → simrel-C07wZN8Q.js} +2 -2
- package/dist/simrel-runtime.js +1 -1
- package/dist/simrel.iife.js +35 -35
- package/dist/simrel.js +2 -2
- package/dist/widget-base-Dliq3QAf.js +362 -0
- package/package.json +1 -2
- package/dist/common-DDJSeQhg.js +0 -491
- package/dist/runtime-CRSFPLku.js +0 -688
- package/dist/widget-base-BtBl_PCR.js +0 -589
- /package/dist/{context-DGz5F81j.js → context-BBuSsXZ9.js} +0 -0
|
@@ -0,0 +1,650 @@
|
|
|
1
|
+
import { a as x, d as L, h as j, i as F, p as z, r as I, t as N } from "./api-paths-y5nkfEBG.js";
|
|
2
|
+
import { A as D, E as T, N as H, a as k, l as q, v as $ } from "./context-BBuSsXZ9.js";
|
|
3
|
+
import { o as W, t as J } from "./widget-base-Dliq3QAf.js";
|
|
4
|
+
import { t as Q } from "./locale-CfqNifrU.js";
|
|
5
|
+
import { a as V, n as Y, r as K, t as A } from "./price-formatter-xI3g9Cd4.js";
|
|
6
|
+
import { n as X } from "./connection-warning-DJiyLM46.js";
|
|
7
|
+
function R(e) {
|
|
8
|
+
const t = [];
|
|
9
|
+
for (const n of Object.values(e)) if (n.type === "ProductCard" && n.props) {
|
|
10
|
+
const r = n.props.product ?? n.props;
|
|
11
|
+
typeof r.sku == "string" && typeof r.name == "string" && t.push(r);
|
|
12
|
+
}
|
|
13
|
+
return t;
|
|
14
|
+
}
|
|
15
|
+
function M(e) {
|
|
16
|
+
const t = e.headers.get("Content-Type") ?? "";
|
|
17
|
+
return t.includes("application/x-ndjson") || t.includes("text/event-stream");
|
|
18
|
+
}
|
|
19
|
+
async function Z(e, t) {
|
|
20
|
+
const n = [], r = { onEvent: (i) => {
|
|
21
|
+
const s = I(i);
|
|
22
|
+
!s || s.type !== "ui_spec" || n.push(...R(s.spec.elements));
|
|
23
|
+
} };
|
|
24
|
+
return t !== void 0 && (r.signal = t), await L(e, r), n;
|
|
25
|
+
}
|
|
26
|
+
async function ee(e, t, n) {
|
|
27
|
+
const r = N("similar_products", t), i = {
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers: { "Content-Type": "application/json" },
|
|
30
|
+
body: JSON.stringify(e)
|
|
31
|
+
};
|
|
32
|
+
n !== void 0 && (i.signal = n);
|
|
33
|
+
const s = await fetch(r, i);
|
|
34
|
+
if (!s.ok) throw new Error(`HTTP ${s.status}: ${s.statusText}`);
|
|
35
|
+
if (M(s)) return Z(s, n);
|
|
36
|
+
const a = await s.text();
|
|
37
|
+
if (!a) throw new Error("Empty response body from similar_products endpoint");
|
|
38
|
+
try {
|
|
39
|
+
return x(JSON.parse(a));
|
|
40
|
+
} catch {
|
|
41
|
+
throw new Error("Invalid JSON from similar_products endpoint");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function te(e, t) {
|
|
45
|
+
const n = [];
|
|
46
|
+
let r = null;
|
|
47
|
+
const i = { onEvent: (s) => {
|
|
48
|
+
const a = I(s);
|
|
49
|
+
if (a) {
|
|
50
|
+
if (a.type === "metadata" && a.meta) {
|
|
51
|
+
const d = a.meta.group_name;
|
|
52
|
+
if (typeof d == "string") {
|
|
53
|
+
r = {
|
|
54
|
+
name: d,
|
|
55
|
+
products: []
|
|
56
|
+
};
|
|
57
|
+
const m = a.meta.highlight;
|
|
58
|
+
typeof m == "string" && (r.highlight = m), n.push(r);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
a.type === "ui_spec" && r && r.products.push(...R(a.spec.elements));
|
|
62
|
+
}
|
|
63
|
+
} };
|
|
64
|
+
return t !== void 0 && (i.signal = t), await L(e, i), n;
|
|
65
|
+
}
|
|
66
|
+
async function ne(e, t, n) {
|
|
67
|
+
const r = N("product_groupings", t), i = {
|
|
68
|
+
method: "POST",
|
|
69
|
+
headers: { "Content-Type": "application/json" },
|
|
70
|
+
body: JSON.stringify(e)
|
|
71
|
+
};
|
|
72
|
+
n !== void 0 && (i.signal = n);
|
|
73
|
+
const s = await fetch(r, i);
|
|
74
|
+
if (!s.ok) throw new Error(`HTTP ${s.status}: ${s.statusText}`);
|
|
75
|
+
if (M(s)) return te(s, n);
|
|
76
|
+
const a = await s.text();
|
|
77
|
+
if (!a) return [];
|
|
78
|
+
try {
|
|
79
|
+
return F(JSON.parse(a));
|
|
80
|
+
} catch {
|
|
81
|
+
throw new Error("Invalid JSON from product_groupings endpoint");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function U(e) {
|
|
85
|
+
const { product: t, index: n, discountType: r, onClick: i, onAddToCart: s, renderCard: a } = e, d = e.i18n, m = e.pricing;
|
|
86
|
+
if (e.renderCardElement) {
|
|
87
|
+
const o = e.renderCardElement(t, n);
|
|
88
|
+
if (o) return o;
|
|
89
|
+
}
|
|
90
|
+
if (a) {
|
|
91
|
+
const o = document.createElement("div");
|
|
92
|
+
return o.className = "gengage-simrel-card gengage-simrel-card--custom gds-card gds-product-card gds-card-interactive", o.dataset.gengagePart = "simrel-product-card", o.innerHTML = H(a(t, n)), o.addEventListener("click", (c) => {
|
|
93
|
+
c.target.closest(".gengage-simrel-atc") || c.target.closest(".gengage-chat-product-card-atc") || i(t);
|
|
94
|
+
}), o;
|
|
95
|
+
}
|
|
96
|
+
const l = document.createElement("article");
|
|
97
|
+
l.className = "gengage-simrel-card gengage-chat-product-card gds-card gds-product-card gds-card-interactive", l.dataset.gengagePart = "simrel-product-card", t.inStock === !1 && l.classList.add("gengage-simrel-card--out-of-stock"), l.setAttribute("role", "listitem"), l.dataset.sku = t.sku;
|
|
98
|
+
const g = document.createElement("div");
|
|
99
|
+
if (g.className = "gengage-simrel-card-image gengage-chat-product-card-img-wrapper", g.dataset.gengagePart = "simrel-product-card-image", t.imageUrl && D(t.imageUrl)) {
|
|
100
|
+
const o = document.createElement("img");
|
|
101
|
+
o.className = "gengage-chat-product-card-img", o.src = t.imageUrl, o.alt = t.name, o.loading = "lazy", Y(o), g.appendChild(o);
|
|
102
|
+
}
|
|
103
|
+
if (r === "badge" && t.discountPercent && t.discountPercent > 0) {
|
|
104
|
+
const o = document.createElement("span");
|
|
105
|
+
o.className = "gengage-simrel-badge gengage-chat-product-card-discount-badge", o.textContent = `%${K(t.discountPercent)}`, g.appendChild(o);
|
|
106
|
+
}
|
|
107
|
+
l.appendChild(g);
|
|
108
|
+
const u = document.createElement("div");
|
|
109
|
+
if (u.className = "gengage-simrel-card-info gengage-chat-product-card-body", u.dataset.gengagePart = "simrel-product-card-body", t.brand) {
|
|
110
|
+
const o = document.createElement("div");
|
|
111
|
+
o.className = "gengage-simrel-card-brand gengage-chat-product-card-brand", o.textContent = t.brand, u.appendChild(o);
|
|
112
|
+
}
|
|
113
|
+
const h = document.createElement("div");
|
|
114
|
+
if (h.className = "gengage-simrel-card-name gengage-chat-product-card-name", h.textContent = t.name, h.title = t.name, u.appendChild(h), t.rating != null && t.rating > 0) {
|
|
115
|
+
const o = document.createElement("div");
|
|
116
|
+
if (o.className = "gengage-simrel-card-rating gengage-chat-product-card-rating", o.appendChild(V(t.rating)), t.reviewCount != null) {
|
|
117
|
+
const c = document.createElement("span");
|
|
118
|
+
c.className = "gengage-simrel-card-review-count gengage-chat-product-card-review-count", c.textContent = ` (${t.reviewCount})`, o.appendChild(c);
|
|
119
|
+
}
|
|
120
|
+
u.appendChild(o);
|
|
121
|
+
}
|
|
122
|
+
const C = document.createElement("div");
|
|
123
|
+
if (C.className = "gengage-simrel-card-price gengage-chat-product-card-price", t.originalPrice && t.originalPrice !== t.price && (r === "strike-through" || !r)) {
|
|
124
|
+
const o = document.createElement("span");
|
|
125
|
+
o.className = "gengage-simrel-card-price-original gengage-chat-product-card-original-price", o.textContent = A(t.originalPrice, m), C.appendChild(o);
|
|
126
|
+
}
|
|
127
|
+
if (t.price && parseFloat(t.price) > 0) {
|
|
128
|
+
const o = document.createElement("span");
|
|
129
|
+
o.className = "gengage-simrel-card-price-current gengage-chat-product-card-price-current", o.textContent = A(t.price, m), C.appendChild(o);
|
|
130
|
+
}
|
|
131
|
+
u.appendChild(C), l.appendChild(u);
|
|
132
|
+
const f = document.createElement("button");
|
|
133
|
+
if (f.className = "gengage-simrel-card-cta gengage-chat-product-card-cta gds-btn gds-btn-secondary", f.type = "button", f.dataset.gengagePart = "simrel-product-card-cta", f.textContent = d?.ctaLabel ?? "View", f.addEventListener("click", (o) => {
|
|
134
|
+
o.preventDefault(), o.stopPropagation(), i(t);
|
|
135
|
+
}), l.appendChild(f), t.inStock === !1) {
|
|
136
|
+
const o = document.createElement("div");
|
|
137
|
+
o.className = "gengage-simrel-card-oos", o.textContent = d?.outOfStockLabel ?? "Out of Stock", l.appendChild(o);
|
|
138
|
+
} else if (t.cartCode) {
|
|
139
|
+
const o = document.createElement("button");
|
|
140
|
+
o.className = "gengage-simrel-atc gengage-simrel-atc-button gds-btn gds-btn-secondary", o.type = "button", o.textContent = d?.addToCartButton ?? "Add to Cart", o.addEventListener("click", (c) => {
|
|
141
|
+
c.preventDefault(), c.stopPropagation(), s({
|
|
142
|
+
sku: t.sku,
|
|
143
|
+
quantity: 1,
|
|
144
|
+
cartCode: t.cartCode
|
|
145
|
+
});
|
|
146
|
+
}), l.appendChild(o);
|
|
147
|
+
}
|
|
148
|
+
return l.addEventListener("click", (o) => {
|
|
149
|
+
o.target.closest(".gengage-simrel-atc") || o.target.closest(".gengage-chat-product-card-atc") || o.target.closest(".gengage-chat-product-card-cta") || i(t);
|
|
150
|
+
}), l;
|
|
151
|
+
}
|
|
152
|
+
function P(e) {
|
|
153
|
+
const t = document.createElement("div");
|
|
154
|
+
t.className = "gengage-simrel-grid", t.setAttribute("role", "list"), t.setAttribute("aria-label", e.i18n?.similarProductsAriaLabel ?? "Similar products"), e.columns && t.style.setProperty("--gengage-simrel-columns", String(e.columns));
|
|
155
|
+
for (let n = 0; n < e.products.length; n++) {
|
|
156
|
+
const r = {
|
|
157
|
+
product: e.products[n],
|
|
158
|
+
index: n,
|
|
159
|
+
onClick: e.onClick,
|
|
160
|
+
onAddToCart: e.onAddToCart
|
|
161
|
+
};
|
|
162
|
+
e.i18n !== void 0 && (r.i18n = e.i18n), e.discountType !== void 0 && (r.discountType = e.discountType), e.renderCard !== void 0 && (r.renderCard = e.renderCard), e.renderCardElement !== void 0 && (r.renderCardElement = e.renderCardElement);
|
|
163
|
+
const i = U(r);
|
|
164
|
+
t.appendChild(i);
|
|
165
|
+
}
|
|
166
|
+
return e.products.length === 0 && (t.style.display = "none", t.dataset.empty = "true"), t;
|
|
167
|
+
}
|
|
168
|
+
var re = 0;
|
|
169
|
+
function ie(e) {
|
|
170
|
+
const t = re++, n = document.createElement("div");
|
|
171
|
+
if (n.className = "gengage-simrel-groups", n.dataset.gengagePart = "simrel-groups", e.groups.length === 0)
|
|
172
|
+
return n.style.display = "none", n.dataset.empty = "true", n;
|
|
173
|
+
const r = document.createElement("div");
|
|
174
|
+
r.className = "gengage-simrel-tabs gds-toolbar", r.dataset.gengagePart = "simrel-tab-bar", r.setAttribute("role", "tablist");
|
|
175
|
+
const i = [], s = [];
|
|
176
|
+
let a = 0;
|
|
177
|
+
const d = (c) => {
|
|
178
|
+
const y = {
|
|
179
|
+
products: c.products,
|
|
180
|
+
onClick: e.onClick,
|
|
181
|
+
onAddToCart: e.onAddToCart
|
|
182
|
+
};
|
|
183
|
+
return e.i18n !== void 0 && (y.i18n = e.i18n), e.discountType !== void 0 && (y.discountType = e.discountType), e.renderCard !== void 0 && (y.renderCard = e.renderCard), e.renderCardElement !== void 0 && (y.renderCardElement = e.renderCardElement), e.columns !== void 0 && (y.columns = e.columns), y;
|
|
184
|
+
}, m = (c, y = !1) => {
|
|
185
|
+
if (y && c !== a && e.onGroupingActivate) {
|
|
186
|
+
const p = e.groups[c];
|
|
187
|
+
e.onGroupingActivate({
|
|
188
|
+
grouping_label: p.name,
|
|
189
|
+
grouping_index: c
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
a = c;
|
|
193
|
+
for (let p = 0; p < i.length; p++) {
|
|
194
|
+
const v = p === c;
|
|
195
|
+
i[p].classList.toggle("gengage-simrel-tab--active", v), i[p].setAttribute("aria-selected", String(v)), i[p].tabIndex = v ? 0 : -1;
|
|
196
|
+
}
|
|
197
|
+
const S = e.groups[c], _ = s[c];
|
|
198
|
+
_.innerHTML = "";
|
|
199
|
+
const b = P(d(S));
|
|
200
|
+
_.appendChild(b);
|
|
201
|
+
for (let p = 0; p < s.length; p++) {
|
|
202
|
+
const v = p === c;
|
|
203
|
+
s[p].style.display = v ? "" : "none", s[p].tabIndex = v ? 0 : -1;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
for (let c = 0; c < e.groups.length; c++) {
|
|
207
|
+
const y = e.groups[c], S = `gengage-simrel-tab-${t}-${c}`, _ = `gengage-simrel-panel-${t}-${c}`, b = document.createElement("button");
|
|
208
|
+
b.className = "gengage-simrel-tab gds-tab", b.type = "button", b.dataset.gengagePart = "simrel-tab", b.id = S, b.textContent = y.name, b.setAttribute("role", "tab"), b.setAttribute("aria-controls", _), b.setAttribute("aria-selected", String(c === 0)), b.tabIndex = c === 0 ? 0 : -1, c === 0 && b.classList.add("gengage-simrel-tab--active"), b.addEventListener("click", () => m(c, !0)), b.addEventListener("keydown", (v) => {
|
|
209
|
+
let E = -1;
|
|
210
|
+
v.key === "ArrowRight" || v.key === "ArrowDown" ? E = (c + 1) % e.groups.length : v.key === "ArrowLeft" || v.key === "ArrowUp" ? E = (c - 1 + e.groups.length) % e.groups.length : v.key === "Home" ? E = 0 : v.key === "End" && (E = e.groups.length - 1), E >= 0 && (v.preventDefault(), m(E, !0), i[E].focus());
|
|
211
|
+
}), i.push(b), r.appendChild(b);
|
|
212
|
+
const p = document.createElement("div");
|
|
213
|
+
p.className = "gengage-simrel-tab-panel", p.dataset.gengagePart = "simrel-tab-panel", p.id = _, p.setAttribute("role", "tabpanel"), p.setAttribute("aria-labelledby", S), p.tabIndex = c === 0 ? 0 : -1, c !== 0 && (p.style.display = "none"), s.push(p);
|
|
214
|
+
}
|
|
215
|
+
const l = document.createElement("button");
|
|
216
|
+
l.type = "button", l.className = "gengage-simrel-tabs-arrow gengage-simrel-tabs-arrow--left", l.setAttribute("aria-label", e.i18n?.scrollTabsLeft ?? "Scroll tabs left"), l.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>';
|
|
217
|
+
const g = document.createElement("button");
|
|
218
|
+
g.type = "button", g.className = "gengage-simrel-tabs-arrow gengage-simrel-tabs-arrow--right", g.setAttribute("aria-label", e.i18n?.scrollTabsRight ?? "Scroll tabs right"), g.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"/></svg>';
|
|
219
|
+
const u = 200;
|
|
220
|
+
l.addEventListener("click", () => {
|
|
221
|
+
r.scrollBy({
|
|
222
|
+
left: -u,
|
|
223
|
+
behavior: "smooth"
|
|
224
|
+
});
|
|
225
|
+
}), g.addEventListener("click", () => {
|
|
226
|
+
r.scrollBy({
|
|
227
|
+
left: u,
|
|
228
|
+
behavior: "smooth"
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
const h = () => {
|
|
232
|
+
const c = r.scrollLeft <= 4, y = r.scrollLeft + r.clientWidth >= r.scrollWidth - 4;
|
|
233
|
+
l.style.display = c ? "none" : "", g.style.display = y ? "none" : "", r.classList.toggle("gengage-simrel-tabs--peek-right", !y), r.classList.toggle("gengage-simrel-tabs--peek-left", !c);
|
|
234
|
+
};
|
|
235
|
+
r.addEventListener("scroll", h, { passive: !0 }), typeof ResizeObserver < "u" && new ResizeObserver(h).observe(r), l.style.display = "none", g.style.display = "none", requestAnimationFrame(h);
|
|
236
|
+
const C = document.createElement("div");
|
|
237
|
+
C.className = "gengage-simrel-tabs-wrapper", C.appendChild(l), C.appendChild(r), C.appendChild(g), n.appendChild(C);
|
|
238
|
+
const f = s[0], o = P(d(e.groups[0]));
|
|
239
|
+
f.appendChild(o);
|
|
240
|
+
for (const c of s) n.appendChild(c);
|
|
241
|
+
return n;
|
|
242
|
+
}
|
|
243
|
+
function w(e) {
|
|
244
|
+
if (!e || typeof e != "object") return null;
|
|
245
|
+
const t = e;
|
|
246
|
+
if (typeof t.sku != "string" || typeof t.name != "string" || typeof t.url != "string") return null;
|
|
247
|
+
const n = {
|
|
248
|
+
sku: t.sku,
|
|
249
|
+
name: t.name,
|
|
250
|
+
url: t.url
|
|
251
|
+
}, r = t.imageUrl;
|
|
252
|
+
typeof r == "string" && (n.imageUrl = r);
|
|
253
|
+
const i = t.price;
|
|
254
|
+
typeof i == "string" && (n.price = i);
|
|
255
|
+
const s = t.originalPrice;
|
|
256
|
+
typeof s == "string" && (n.originalPrice = s);
|
|
257
|
+
const a = t.discountPercent;
|
|
258
|
+
typeof a == "number" && (n.discountPercent = a);
|
|
259
|
+
const d = t.brand;
|
|
260
|
+
typeof d == "string" && (n.brand = d);
|
|
261
|
+
const m = t.rating;
|
|
262
|
+
typeof m == "number" && (n.rating = m);
|
|
263
|
+
const l = t.reviewCount;
|
|
264
|
+
typeof l == "number" && (n.reviewCount = l);
|
|
265
|
+
const g = t.cartCode;
|
|
266
|
+
typeof g == "string" && (n.cartCode = g);
|
|
267
|
+
const u = t.inStock;
|
|
268
|
+
typeof u == "boolean" && (n.inStock = u);
|
|
269
|
+
const h = t.extras;
|
|
270
|
+
return h != null && typeof h == "object" && (n.extras = h), n;
|
|
271
|
+
}
|
|
272
|
+
function se(e) {
|
|
273
|
+
if (!e || typeof e != "object") return null;
|
|
274
|
+
const t = e, n = t.title, r = t.type;
|
|
275
|
+
if (typeof n != "string" || typeof r != "string") return null;
|
|
276
|
+
const i = {
|
|
277
|
+
title: n,
|
|
278
|
+
type: r
|
|
279
|
+
};
|
|
280
|
+
return t.payload !== void 0 && (i.payload = t.payload), i;
|
|
281
|
+
}
|
|
282
|
+
var G = {
|
|
283
|
+
ProductGrid: ({ element: e, renderElement: t, context: n }) => {
|
|
284
|
+
const r = document.createElement("div");
|
|
285
|
+
r.className = "gengage-simrel-grid", r.setAttribute("role", "list");
|
|
286
|
+
const i = e.props?.columns;
|
|
287
|
+
let s;
|
|
288
|
+
typeof i == "number" && Number.isFinite(i) && i > 0 ? s = Math.floor(i) : typeof n.gridColumns == "number" && Number.isFinite(n.gridColumns) && n.gridColumns > 0 && (s = Math.floor(n.gridColumns)), s !== void 0 && r.style.setProperty("--gengage-simrel-columns", String(s));
|
|
289
|
+
for (const a of e.children ?? []) {
|
|
290
|
+
const d = t(a);
|
|
291
|
+
d && r.appendChild(d);
|
|
292
|
+
}
|
|
293
|
+
if (r.children.length === 0) {
|
|
294
|
+
const a = document.createElement("div");
|
|
295
|
+
a.className = "gengage-simrel-empty", a.textContent = n.i18n.emptyStateMessage, r.appendChild(a);
|
|
296
|
+
}
|
|
297
|
+
return r;
|
|
298
|
+
},
|
|
299
|
+
ProductCard: ({ element: e, context: t }) => {
|
|
300
|
+
const n = w(e.props?.product ?? e.props);
|
|
301
|
+
if (!n) return null;
|
|
302
|
+
const r = e.props?.index, i = typeof r == "number" && Number.isFinite(r) ? r : 0, s = e.props?.discountType, a = s === "strike-through" || s === "badge" ? s : t.discountType, d = {
|
|
303
|
+
product: n,
|
|
304
|
+
index: i,
|
|
305
|
+
onClick: t.onClick,
|
|
306
|
+
onAddToCart: t.onAddToCart,
|
|
307
|
+
i18n: t.i18n
|
|
308
|
+
};
|
|
309
|
+
return a !== void 0 && (d.discountType = a), t.renderCard !== void 0 && (d.renderCard = t.renderCard), t.renderCardElement !== void 0 && (d.renderCardElement = t.renderCardElement), t.pricing !== void 0 && (d.pricing = t.pricing), U(d);
|
|
310
|
+
},
|
|
311
|
+
GroupTabs: ({ element: e, context: t }) => {
|
|
312
|
+
const n = e.props?.groups;
|
|
313
|
+
if (!Array.isArray(n)) return null;
|
|
314
|
+
const r = [];
|
|
315
|
+
for (const a of n) {
|
|
316
|
+
if (!a || typeof a != "object") continue;
|
|
317
|
+
const d = a;
|
|
318
|
+
if (typeof d.name != "string") continue;
|
|
319
|
+
const m = [];
|
|
320
|
+
if (Array.isArray(d.products)) for (const g of d.products) {
|
|
321
|
+
const u = w(g);
|
|
322
|
+
u && m.push(u);
|
|
323
|
+
}
|
|
324
|
+
const l = {
|
|
325
|
+
name: d.name,
|
|
326
|
+
products: m
|
|
327
|
+
};
|
|
328
|
+
typeof d.highlight == "string" && (l.highlight = d.highlight), r.push(l);
|
|
329
|
+
}
|
|
330
|
+
const i = {
|
|
331
|
+
groups: r,
|
|
332
|
+
onClick: t.onClick,
|
|
333
|
+
onAddToCart: t.onAddToCart,
|
|
334
|
+
i18n: t.i18n
|
|
335
|
+
}, s = e.props?.columns;
|
|
336
|
+
return typeof s == "number" && Number.isFinite(s) && s > 0 ? i.columns = Math.floor(s) : typeof t.gridColumns == "number" && Number.isFinite(t.gridColumns) && t.gridColumns > 0 && (i.columns = Math.floor(t.gridColumns)), t.discountType !== void 0 && (i.discountType = t.discountType), t.renderCard !== void 0 && (i.renderCard = t.renderCard), t.renderCardElement !== void 0 && (i.renderCardElement = t.renderCardElement), t.onGroupingActivate !== void 0 && (i.onGroupingActivate = t.onGroupingActivate), ie(i);
|
|
337
|
+
},
|
|
338
|
+
EmptyState: ({ element: e, context: t }) => {
|
|
339
|
+
const n = document.createElement("div");
|
|
340
|
+
n.className = "gengage-simrel-empty";
|
|
341
|
+
const r = e.props?.message;
|
|
342
|
+
return n.textContent = typeof r == "string" ? r : t.i18n.emptyStateMessage, n;
|
|
343
|
+
},
|
|
344
|
+
AddToCartButton: ({ element: e, context: t }) => {
|
|
345
|
+
const n = e.props?.sku, r = e.props?.cartCode;
|
|
346
|
+
if (typeof n != "string" || typeof r != "string") return null;
|
|
347
|
+
const i = document.createElement("button");
|
|
348
|
+
i.className = "gengage-simrel-atc gengage-chat-product-card-cta", i.type = "button";
|
|
349
|
+
const s = e.props?.label;
|
|
350
|
+
return i.textContent = typeof s == "string" ? s : t.i18n.addToCartButton, i.addEventListener("click", (a) => {
|
|
351
|
+
a.preventDefault(), a.stopPropagation(), t.onAddToCart({
|
|
352
|
+
sku: n,
|
|
353
|
+
quantity: 1,
|
|
354
|
+
cartCode: r
|
|
355
|
+
});
|
|
356
|
+
}), i;
|
|
357
|
+
},
|
|
358
|
+
QuickActions: ({ element: e, context: t }) => {
|
|
359
|
+
const n = document.createElement("div");
|
|
360
|
+
n.className = "gengage-simrel-quick-actions";
|
|
361
|
+
const r = e.props?.actions;
|
|
362
|
+
if (!Array.isArray(r) || !t.onAction) return n;
|
|
363
|
+
for (const i of r) {
|
|
364
|
+
if (!i || typeof i != "object") continue;
|
|
365
|
+
const s = i, a = s.label, d = se(s.action);
|
|
366
|
+
if (typeof a != "string" || !d) continue;
|
|
367
|
+
const m = document.createElement("button");
|
|
368
|
+
m.className = "gengage-simrel-quick-action", m.type = "button", m.textContent = a, m.addEventListener("click", (l) => {
|
|
369
|
+
l.preventDefault(), l.stopPropagation(), t.onAction?.(d);
|
|
370
|
+
}), n.appendChild(m);
|
|
371
|
+
}
|
|
372
|
+
return n;
|
|
373
|
+
}
|
|
374
|
+
}, O = ({ element: e, renderElement: t }) => {
|
|
375
|
+
if (!e.children || e.children.length === 0) return null;
|
|
376
|
+
const n = document.createElement("div");
|
|
377
|
+
for (const r of e.children) {
|
|
378
|
+
const i = t(r);
|
|
379
|
+
i && n.appendChild(i);
|
|
380
|
+
}
|
|
381
|
+
return n;
|
|
382
|
+
};
|
|
383
|
+
function oe() {
|
|
384
|
+
return { ...G };
|
|
385
|
+
}
|
|
386
|
+
function ae(e, t, n = G, r = O) {
|
|
387
|
+
return j({
|
|
388
|
+
spec: e,
|
|
389
|
+
context: t,
|
|
390
|
+
registry: n,
|
|
391
|
+
containerClassName: "gengage-simrel-uispec",
|
|
392
|
+
unknownRenderer: r
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
var B = {
|
|
396
|
+
similarProductsAriaLabel: "Benzer ürünler",
|
|
397
|
+
emptyStateMessage: "Benzer ürün bulunamadı.",
|
|
398
|
+
addToCartButton: "Sepete Ekle",
|
|
399
|
+
ctaLabel: "İncele",
|
|
400
|
+
outOfStockLabel: "Stokta Yok",
|
|
401
|
+
decreaseLabel: "Azalt",
|
|
402
|
+
increaseLabel: "Artır",
|
|
403
|
+
errorLoadingMessage: "Benzer ürünler yüklenemedi.",
|
|
404
|
+
retryButtonText: "Tekrar dene",
|
|
405
|
+
priceSuffix: " TL",
|
|
406
|
+
scrollTabsLeft: "Sola kaydır",
|
|
407
|
+
scrollTabsRight: "Sağa kaydır"
|
|
408
|
+
}, ce = {
|
|
409
|
+
similarProductsAriaLabel: "Similar products",
|
|
410
|
+
emptyStateMessage: "No similar products found.",
|
|
411
|
+
addToCartButton: "Add to cart",
|
|
412
|
+
ctaLabel: "View",
|
|
413
|
+
outOfStockLabel: "Out of Stock",
|
|
414
|
+
decreaseLabel: "Decrease",
|
|
415
|
+
increaseLabel: "Increase",
|
|
416
|
+
errorLoadingMessage: "Could not load similar products.",
|
|
417
|
+
retryButtonText: "Try again",
|
|
418
|
+
priceSuffix: "",
|
|
419
|
+
scrollTabsLeft: "Scroll tabs left",
|
|
420
|
+
scrollTabsRight: "Scroll tabs right"
|
|
421
|
+
};
|
|
422
|
+
function de(e) {
|
|
423
|
+
return e ? e.toLowerCase().split("-")[0] ?? "tr" : "tr";
|
|
424
|
+
}
|
|
425
|
+
function le(e) {
|
|
426
|
+
return de(e) === "en" ? ce : B;
|
|
427
|
+
}
|
|
428
|
+
var ge = 12e4;
|
|
429
|
+
function ue(e) {
|
|
430
|
+
return e instanceof DOMException && e.name === "AbortError";
|
|
431
|
+
}
|
|
432
|
+
var pe = class extends J {
|
|
433
|
+
constructor(...e) {
|
|
434
|
+
super(...e), this._abortController = null, this._contentEl = null, this._lastResultCount = -1, this._i18n = B;
|
|
435
|
+
}
|
|
436
|
+
async onInit(e) {
|
|
437
|
+
this._i18n = this._resolveI18n(e), this._contentEl = document.createElement("div"), this._contentEl.className = "gengage-simrel-container", this._contentEl.dataset.gengagePart = "simrel-container", this._contentEl.lang = Q(e.locale);
|
|
438
|
+
const t = this._clampGridColumns(e.gridColumns);
|
|
439
|
+
t !== void 0 && this._contentEl.style.setProperty("--gengage-simrel-columns", String(t)), this.root.appendChild(this._contentEl), this._lastSku = e.sku, await this._fetchAndRender(e.sku), $("simrel");
|
|
440
|
+
}
|
|
441
|
+
onUpdate(e) {
|
|
442
|
+
const t = e.sku;
|
|
443
|
+
!t || t === this._lastSku && this._lastResultCount !== 0 || (this._lastSku = t, this._fetchAndRender(t));
|
|
444
|
+
}
|
|
445
|
+
onShow() {
|
|
446
|
+
this._contentEl && (this._contentEl.style.opacity = "0", this._contentEl.style.transition = "opacity 0.3s ease-in", requestAnimationFrame(() => {
|
|
447
|
+
this._contentEl && (this._contentEl.style.opacity = "1");
|
|
448
|
+
}));
|
|
449
|
+
}
|
|
450
|
+
onHide() {
|
|
451
|
+
}
|
|
452
|
+
onDestroy() {
|
|
453
|
+
this._abort(), this._contentEl && (this._contentEl.remove(), this._contentEl = null);
|
|
454
|
+
}
|
|
455
|
+
_handleProductClick(e) {
|
|
456
|
+
const t = {
|
|
457
|
+
sku: e.sku,
|
|
458
|
+
name: e.name,
|
|
459
|
+
url: e.url
|
|
460
|
+
};
|
|
461
|
+
if (e.imageUrl !== void 0 && (t.imageUrl = e.imageUrl), e.price !== void 0 && (t.price = e.price), e.originalPrice !== void 0 && (t.originalPrice = e.originalPrice), e.discountPercent !== void 0 && (t.discountPercent = e.discountPercent), e.brand !== void 0 && (t.brand = e.brand), e.rating !== void 0 && (t.rating = e.rating), e.reviewCount !== void 0 && (t.reviewCount = e.reviewCount), e.cartCode !== void 0 && (t.cartCode = e.cartCode), e.inStock !== void 0 && (t.inStock = e.inStock), this.config.onProductClick?.(t) === !1) return;
|
|
462
|
+
const n = this.config.session?.sessionId ?? null;
|
|
463
|
+
k("gengage:similar:product-click", {
|
|
464
|
+
sku: e.sku,
|
|
465
|
+
url: e.url,
|
|
466
|
+
sessionId: n,
|
|
467
|
+
productName: e.name
|
|
468
|
+
}), this.config.onProductNavigate?.(e.url, e.sku, n);
|
|
469
|
+
}
|
|
470
|
+
_handleAddToCart(e) {
|
|
471
|
+
q(e.sku, e.quantity), this.config.onAddToCart?.(e), k("gengage:similar:add-to-cart", e);
|
|
472
|
+
}
|
|
473
|
+
_abort() {
|
|
474
|
+
this._abortController?.abort(), this._abortController = null;
|
|
475
|
+
}
|
|
476
|
+
_isSuperseded(e) {
|
|
477
|
+
return this._abortController?.signal !== e;
|
|
478
|
+
}
|
|
479
|
+
_emitSimilarProductsImpression(e, t) {
|
|
480
|
+
const n = this.config.session?.sessionId ?? null;
|
|
481
|
+
k("gengage:similar:products-impression", {
|
|
482
|
+
source_sku: this.config.sku,
|
|
483
|
+
product_count: e,
|
|
484
|
+
grouped: t,
|
|
485
|
+
sessionId: n
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
_resolveRequestTimeoutMs() {
|
|
489
|
+
const e = this.config.requestTimeoutMs;
|
|
490
|
+
return typeof e != "number" || !Number.isFinite(e) || e <= 0 ? ge : Math.floor(e);
|
|
491
|
+
}
|
|
492
|
+
async _fetchAndRender(e) {
|
|
493
|
+
this._abort();
|
|
494
|
+
const t = new AbortController();
|
|
495
|
+
this._abortController = t;
|
|
496
|
+
const n = t.signal;
|
|
497
|
+
let r = !1;
|
|
498
|
+
const i = setTimeout(() => {
|
|
499
|
+
r = !0, t.abort();
|
|
500
|
+
}, this._resolveRequestTimeoutMs());
|
|
501
|
+
if (n.addEventListener("abort", () => clearTimeout(i), { once: !0 }), !this._contentEl) return;
|
|
502
|
+
this._contentEl.innerHTML = "", this._contentEl.style.display = "";
|
|
503
|
+
const s = document.createElement("div");
|
|
504
|
+
s.className = "gengage-simrel-loading", s.dataset.gengagePart = "simrel-loading";
|
|
505
|
+
const a = document.createElement("div");
|
|
506
|
+
a.className = "gengage-simrel-spinner", a.dataset.gengagePart = "simrel-loading-spinner", s.appendChild(a), this._contentEl.appendChild(s);
|
|
507
|
+
const d = { middlewareUrl: this.config.middlewareUrl }, m = X({
|
|
508
|
+
source: "simrel",
|
|
509
|
+
locale: this.config.locale
|
|
510
|
+
});
|
|
511
|
+
try {
|
|
512
|
+
const l = {
|
|
513
|
+
account_id: this.config.accountId,
|
|
514
|
+
session_id: this.config.session?.sessionId ?? "",
|
|
515
|
+
correlation_id: this.config.session?.sessionId ?? "",
|
|
516
|
+
sku: e
|
|
517
|
+
};
|
|
518
|
+
this.config.domain !== void 0 && (l.domain = this.config.domain);
|
|
519
|
+
const g = await ee(l, d, n);
|
|
520
|
+
if (this._lastResultCount = g.length, !this._contentEl) return;
|
|
521
|
+
if (this._contentEl.innerHTML = "", g.length > 0) try {
|
|
522
|
+
const u = g.map((f) => f.sku), h = new Map(g.map((f) => [f.sku, f])), C = (await ne({
|
|
523
|
+
account_id: this.config.accountId,
|
|
524
|
+
session_id: this.config.session?.sessionId ?? "",
|
|
525
|
+
correlation_id: this.config.session?.sessionId ?? "",
|
|
526
|
+
skus: u
|
|
527
|
+
}, d, n)).map((f) => ({
|
|
528
|
+
...f,
|
|
529
|
+
products: f.products.map((o) => ({
|
|
530
|
+
...h.get(o.sku),
|
|
531
|
+
...o
|
|
532
|
+
})).filter((o) => typeof o.sku == "string" && typeof o.name == "string" && typeof o.url == "string")
|
|
533
|
+
})).filter((f) => f.products.length > 0);
|
|
534
|
+
if (C.length > 0 && this._contentEl) {
|
|
535
|
+
const f = this._buildGroupsSpec(C), o = this._renderUISpec(f);
|
|
536
|
+
this._contentEl.appendChild(o), T("simrel"), this._emitSimilarProductsImpression(C.reduce((c, y) => c + y.products.length, 0), !0);
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
} catch {
|
|
540
|
+
}
|
|
541
|
+
if (this._isSuperseded(n)) return;
|
|
542
|
+
if (this._contentEl) {
|
|
543
|
+
const u = this._buildProductsSpec(g), h = this._renderUISpec(u);
|
|
544
|
+
this._contentEl.appendChild(h);
|
|
545
|
+
}
|
|
546
|
+
g.length > 0 && T("simrel"), this._emitSimilarProductsImpression(g.length, !1);
|
|
547
|
+
} catch (l) {
|
|
548
|
+
const g = ue(l);
|
|
549
|
+
if (g && this._isSuperseded(n)) return;
|
|
550
|
+
if (k("gengage:global:error", {
|
|
551
|
+
source: "simrel",
|
|
552
|
+
code: g && r ? "REQUEST_TIMEOUT" : "FETCH_ERROR",
|
|
553
|
+
message: W(this.config.locale, l)
|
|
554
|
+
}), this._contentEl) {
|
|
555
|
+
this._contentEl.innerHTML = "";
|
|
556
|
+
const u = document.createElement("div");
|
|
557
|
+
u.className = "gengage-simrel-error";
|
|
558
|
+
const h = document.createElement("span");
|
|
559
|
+
h.textContent = this._i18n.errorLoadingMessage, u.appendChild(h);
|
|
560
|
+
const C = document.createElement("button");
|
|
561
|
+
C.className = "gengage-simrel-retry", C.textContent = this._i18n.retryButtonText, C.addEventListener("click", () => {
|
|
562
|
+
this._fetchAndRender(this.config.sku);
|
|
563
|
+
}), u.appendChild(C), this._contentEl.appendChild(u);
|
|
564
|
+
}
|
|
565
|
+
} finally {
|
|
566
|
+
clearTimeout(i), m();
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
_clampGridColumns(e) {
|
|
570
|
+
if (!(e === void 0 || typeof e != "number" || !Number.isFinite(e)))
|
|
571
|
+
return Math.max(1, Math.min(12, Math.floor(e)));
|
|
572
|
+
}
|
|
573
|
+
_resolveI18n(e) {
|
|
574
|
+
return {
|
|
575
|
+
...le(e.locale),
|
|
576
|
+
...e.i18n
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
_resolveUISpecRegistry() {
|
|
580
|
+
return z(oe(), this.config.renderer?.registry);
|
|
581
|
+
}
|
|
582
|
+
_buildRenderContext() {
|
|
583
|
+
const e = this.config.renderCard, t = {
|
|
584
|
+
onClick: (r) => this._handleProductClick(r),
|
|
585
|
+
onAddToCart: (r) => this._handleAddToCart(r),
|
|
586
|
+
onGroupingActivate: (r) => {
|
|
587
|
+
k("gengage:similar:grouping-click", {
|
|
588
|
+
grouping_label: r.grouping_label,
|
|
589
|
+
grouping_index: r.grouping_index,
|
|
590
|
+
sessionId: this.config.session?.sessionId ?? null
|
|
591
|
+
});
|
|
592
|
+
},
|
|
593
|
+
i18n: this._i18n
|
|
594
|
+
};
|
|
595
|
+
this.config.discountType !== void 0 && (t.discountType = this.config.discountType), e !== void 0 && (t.renderCard = e), this.config.renderCardElement !== void 0 && (t.renderCardElement = this.config.renderCardElement), this.config.pricing !== void 0 && (t.pricing = this.config.pricing);
|
|
596
|
+
const n = this._clampGridColumns(this.config.gridColumns);
|
|
597
|
+
return n !== void 0 && (t.gridColumns = n), t;
|
|
598
|
+
}
|
|
599
|
+
_renderUISpec(e) {
|
|
600
|
+
const t = this._resolveUISpecRegistry(), n = this._buildRenderContext(), r = this.config.renderer?.unknownRenderer ?? O, i = (a, d) => ae(a, d, t, r), s = this.config.renderer?.renderUISpec;
|
|
601
|
+
return s ? s(e, n, {
|
|
602
|
+
registry: t,
|
|
603
|
+
unknownRenderer: r,
|
|
604
|
+
defaultRender: i
|
|
605
|
+
}) : i(e, n);
|
|
606
|
+
}
|
|
607
|
+
_buildProductsSpec(e) {
|
|
608
|
+
const t = {}, n = [];
|
|
609
|
+
for (let s = 0; s < e.length; s++) {
|
|
610
|
+
const a = e[s], d = `product-${s}`;
|
|
611
|
+
n.push(d), t[d] = {
|
|
612
|
+
type: "ProductCard",
|
|
613
|
+
props: {
|
|
614
|
+
product: a,
|
|
615
|
+
index: s,
|
|
616
|
+
discountType: this.config.discountType
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
const r = { layout: "grid" }, i = this._clampGridColumns(this.config.gridColumns);
|
|
621
|
+
return i !== void 0 && (r.columns = i), t.root = {
|
|
622
|
+
type: "ProductGrid",
|
|
623
|
+
props: r,
|
|
624
|
+
children: n
|
|
625
|
+
}, {
|
|
626
|
+
root: "root",
|
|
627
|
+
elements: t
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
_buildGroupsSpec(e) {
|
|
631
|
+
return {
|
|
632
|
+
root: "root",
|
|
633
|
+
elements: { root: {
|
|
634
|
+
type: "GroupTabs",
|
|
635
|
+
props: { groups: e }
|
|
636
|
+
} }
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
function ve() {
|
|
641
|
+
return new pe();
|
|
642
|
+
}
|
|
643
|
+
export {
|
|
644
|
+
ae as a,
|
|
645
|
+
O as i,
|
|
646
|
+
ve as n,
|
|
647
|
+
ie as o,
|
|
648
|
+
oe as r,
|
|
649
|
+
pe as t
|
|
650
|
+
};
|