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