@useinsider/guido 3.9.0-beta.1549171 → 3.9.0-beta.1a5491e
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/config/compiler/utils/recommendationCompilerUtils.js +118 -110
- package/dist/config/migrator/itemsBlockMigrator.js +33 -34
- package/dist/extensions/Blocks/Items/block.js +57 -37
- package/dist/extensions/Blocks/Items/controls/settingsControl.js +43 -54
- package/dist/extensions/Blocks/Items/template.js +125 -133
- package/dist/extensions/Blocks/Items/utils/nodeConfigUtils.js +53 -45
- package/dist/extensions/Blocks/Recommendation/templates/list/template.js +15 -15
- package/dist/src/extensions/Blocks/Items/block.d.ts +9 -0
- package/dist/src/extensions/Blocks/Items/utils/nodeConfigUtils.d.ts +12 -0
- package/package.json +1 -1
|
@@ -1,181 +1,189 @@
|
|
|
1
|
-
import { useConfig as
|
|
2
|
-
import { useRecommendation as
|
|
3
|
-
import { CSS_CLASS_RECO_BUTTON as
|
|
4
|
-
import { useRecommendationExtensionStore as
|
|
5
|
-
import { isIgnoredRecommendationBlock as
|
|
6
|
-
function
|
|
7
|
-
const i = `{{${
|
|
8
|
-
return
|
|
1
|
+
import { useConfig as q } from "../../../composables/useConfig.js";
|
|
2
|
+
import { useRecommendation as C } from "../../../composables/useRecommendation.js";
|
|
3
|
+
import { CSS_CLASS_RECO_BUTTON as E } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
|
|
4
|
+
import { useRecommendationExtensionStore as w } from "../../../extensions/Blocks/Recommendation/store/recommendation.js";
|
|
5
|
+
import { isIgnoredRecommendationBlock as P } from "./recommendationIgnoreUtils.js";
|
|
6
|
+
function f(t, o, e, n, s = "") {
|
|
7
|
+
const i = `{{${s}${t}_${o}_${e}}}`, r = `{{${s}${t}_${o}_currency}}`;
|
|
8
|
+
return n === "before" ? `${r} ${i}` : `${i} ${r}`;
|
|
9
9
|
}
|
|
10
|
-
function m(
|
|
11
|
-
let
|
|
12
|
-
for (;
|
|
13
|
-
[
|
|
14
|
-
return
|
|
10
|
+
function m(t) {
|
|
11
|
+
let o = t;
|
|
12
|
+
for (; o.children.length === 1; )
|
|
13
|
+
[o] = o.children;
|
|
14
|
+
return o;
|
|
15
15
|
}
|
|
16
|
-
function h(
|
|
17
|
-
switch (
|
|
16
|
+
function h(t, o, e, n, s, i) {
|
|
17
|
+
switch (o) {
|
|
18
18
|
case "productImage": {
|
|
19
|
-
const r =
|
|
20
|
-
r && (r.setAttribute("src", `{{${i}${
|
|
21
|
-
const
|
|
22
|
-
|
|
19
|
+
const r = t.querySelector("img");
|
|
20
|
+
r && (r.setAttribute("src", `{{${i}${e}_${n}_image_url}}`), r.setAttribute("alt", `{{${i}${e}_${n}_name}}`));
|
|
21
|
+
const c = t.querySelector("a");
|
|
22
|
+
c && (c.setAttribute("href", `{{${i}${e}_${n}_url}}`), c.classList.add(E));
|
|
23
23
|
break;
|
|
24
24
|
}
|
|
25
25
|
case "productName": {
|
|
26
|
-
const r =
|
|
27
|
-
r && (m(r).textContent = `{{${i}${
|
|
26
|
+
const r = t.querySelector("p");
|
|
27
|
+
r && (m(r).textContent = `{{${i}${e}_${n}_name}}`);
|
|
28
28
|
break;
|
|
29
29
|
}
|
|
30
30
|
case "productPrice": {
|
|
31
|
-
const r =
|
|
32
|
-
r && (m(r).textContent =
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
const r = t.querySelector(".product-price p") ?? t.querySelector("p");
|
|
32
|
+
r && (m(r).textContent = f(
|
|
33
|
+
e,
|
|
34
|
+
n,
|
|
35
35
|
"price",
|
|
36
|
-
|
|
36
|
+
s,
|
|
37
37
|
i
|
|
38
38
|
));
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
const c = t.querySelector(".product-old-price p");
|
|
40
|
+
c && (m(c).textContent = f(
|
|
41
|
+
e,
|
|
42
|
+
n,
|
|
43
43
|
"original_price",
|
|
44
|
-
|
|
44
|
+
s,
|
|
45
45
|
i
|
|
46
46
|
));
|
|
47
47
|
break;
|
|
48
48
|
}
|
|
49
49
|
case "productOldPrice": {
|
|
50
|
-
const r =
|
|
51
|
-
r && (m(r).textContent =
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
const r = t.querySelector("p");
|
|
51
|
+
r && (m(r).textContent = f(
|
|
52
|
+
e,
|
|
53
|
+
n,
|
|
54
54
|
"original_price",
|
|
55
|
-
|
|
55
|
+
s,
|
|
56
56
|
i
|
|
57
57
|
));
|
|
58
58
|
break;
|
|
59
59
|
}
|
|
60
60
|
case "productButton": {
|
|
61
|
-
const r =
|
|
62
|
-
r && r.setAttribute("href", `{{${i}${
|
|
61
|
+
const r = t.querySelector("a");
|
|
62
|
+
r && r.setAttribute("href", `{{${i}${e}_${n}_url}}`);
|
|
63
63
|
break;
|
|
64
64
|
}
|
|
65
65
|
case "productOmnibusPrice": {
|
|
66
|
-
const r =
|
|
66
|
+
const r = t.querySelector(".omnibus-price-value");
|
|
67
67
|
if (r) {
|
|
68
|
-
r.textContent = `{{${i}${
|
|
69
|
-
const
|
|
70
|
-
|
|
68
|
+
r.textContent = `{{${i}${e}_${n}_omnibus_price}}`;
|
|
69
|
+
const c = r.closest("p");
|
|
70
|
+
c && (c.setAttribute("product-attr", "omnibus_price"), c.setAttribute("composition", "true"));
|
|
71
71
|
}
|
|
72
72
|
break;
|
|
73
73
|
}
|
|
74
74
|
case "productOmnibusDiscount": {
|
|
75
|
-
const r =
|
|
75
|
+
const r = t.querySelector(".omnibus-discount-value");
|
|
76
76
|
if (r) {
|
|
77
|
-
r.textContent = `{{${i}${
|
|
78
|
-
const
|
|
79
|
-
|
|
77
|
+
r.textContent = `{{${i}${e}_${n}_omnibus_discount}}`;
|
|
78
|
+
const c = r.closest("p");
|
|
79
|
+
c && (c.setAttribute("product-attr", "omnibus_discount"), c.setAttribute("composition", "true"));
|
|
80
80
|
}
|
|
81
81
|
break;
|
|
82
82
|
}
|
|
83
83
|
default: {
|
|
84
|
-
const r =
|
|
84
|
+
const r = t.getAttribute("product-attr") ? t : t.querySelector("[product-attr]");
|
|
85
85
|
if (r) {
|
|
86
|
-
const
|
|
87
|
-
|
|
86
|
+
const c = r.getAttribute("product-attr"), l = r.querySelector("p");
|
|
87
|
+
l && (m(l).textContent = `{{${i}${e}_${n}_${c}}}`);
|
|
88
88
|
}
|
|
89
89
|
break;
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
|
|
95
|
-
i.querySelectorAll("[data-attribute-type]").forEach((
|
|
96
|
-
const u =
|
|
97
|
-
p.length > 0 ? p.forEach((
|
|
98
|
-
h(
|
|
99
|
-
}) : h(
|
|
93
|
+
function R(t, o, e, n) {
|
|
94
|
+
t.querySelectorAll(".recommendation-product-row").forEach((i, r) => {
|
|
95
|
+
i.querySelectorAll("[data-attribute-type]").forEach((l) => {
|
|
96
|
+
const u = l.getAttribute("data-attribute-type") || "", p = l.querySelectorAll(".attribute-cell");
|
|
97
|
+
p.length > 0 ? p.forEach((a) => {
|
|
98
|
+
h(a, u, o, r, e, n);
|
|
99
|
+
}) : h(l, u, o, r, e, n);
|
|
100
100
|
});
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
|
-
function
|
|
104
|
-
const
|
|
105
|
-
if (!
|
|
103
|
+
function W(t, o, e, n) {
|
|
104
|
+
const s = t.querySelectorAll(".recommendation-product-row");
|
|
105
|
+
if (!s.length)
|
|
106
106
|
return;
|
|
107
|
-
const [i] =
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const d =
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
h(
|
|
107
|
+
const [i] = s, r = i.querySelector("[data-attribute-type]"), c = r ? r.querySelectorAll(".attribute-cell").length : 1;
|
|
108
|
+
s.forEach((l, u) => {
|
|
109
|
+
l.querySelectorAll("[data-attribute-type]").forEach((a) => {
|
|
110
|
+
const d = a.getAttribute("data-attribute-type") || "";
|
|
111
|
+
a.querySelectorAll(".attribute-cell").forEach((S, _) => {
|
|
112
|
+
const g = u * c + _;
|
|
113
|
+
h(S, d, o, g, e, n);
|
|
114
114
|
});
|
|
115
115
|
});
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
|
-
function
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
function v(t, o, e, n) {
|
|
119
|
+
t.querySelectorAll(".ins-recommendation-product-container").forEach((i) => {
|
|
120
|
+
W(i, o, e, n);
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
|
-
function O(
|
|
124
|
-
const
|
|
125
|
-
|
|
123
|
+
function O(t, o, e) {
|
|
124
|
+
const n = t.getAttribute("data-layout") || "grid", s = t.getAttribute("currency-alignment") || "after";
|
|
125
|
+
n === "list" ? R(t, o, s, e) : v(t, o, s, e);
|
|
126
126
|
}
|
|
127
|
-
function
|
|
128
|
-
const
|
|
129
|
-
return
|
|
127
|
+
function b(t, o, e) {
|
|
128
|
+
const n = new RegExp(`${o}\\s*:\\s*(\\d+)\\s*px`, "i"), s = t.match(n);
|
|
129
|
+
return s ? parseInt(s[1]) : e;
|
|
130
130
|
}
|
|
131
|
-
function
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
131
|
+
function A(t) {
|
|
132
|
+
const o = t.trim();
|
|
133
|
+
return o.endsWith("%") ? parseFloat(o) < 100 : /^\d+(?:\.\d+)?(?:px)?$/.test(o) && parseInt(o) > 0;
|
|
134
|
+
}
|
|
135
|
+
function $(t) {
|
|
136
|
+
const o = t.getAttribute("width");
|
|
137
|
+
if (o && A(o))
|
|
138
|
+
return o.trim();
|
|
139
|
+
const e = (t.getAttribute("style") || "").match(/(?:^|[;\s])width\s*:\s*(\d+(?:\.\d+)?(?:px|%))/i);
|
|
140
|
+
return e && A(e[1]) ? e[1] : null;
|
|
141
|
+
}
|
|
142
|
+
function T(t, o) {
|
|
143
|
+
let e = t.parentElement;
|
|
144
|
+
for (; e && e !== o; ) {
|
|
145
|
+
if (e.tagName === "TD" && $(e))
|
|
146
|
+
return e;
|
|
147
|
+
e = e.parentElement;
|
|
140
148
|
}
|
|
141
149
|
return null;
|
|
142
150
|
}
|
|
143
|
-
function
|
|
144
|
-
const
|
|
145
|
-
|
|
151
|
+
function M(t) {
|
|
152
|
+
const o = t.getAttribute("style") || "", e = b(o, "width", 600), n = b(o, "padding", 0) * 2, s = Math.max(0, e - n);
|
|
153
|
+
s !== 0 && t.querySelectorAll("img.adapt-img").forEach((i) => {
|
|
146
154
|
if (i.hasAttribute("width"))
|
|
147
155
|
return;
|
|
148
|
-
const r = T(i,
|
|
156
|
+
const r = T(i, t);
|
|
149
157
|
if (!r)
|
|
150
158
|
return;
|
|
151
|
-
const
|
|
152
|
-
i.setAttribute("width", String(
|
|
153
|
-
const
|
|
154
|
-
if (!/\bwidth\s*:\s*\d/i.test(
|
|
155
|
-
const
|
|
156
|
-
i.setAttribute("style", `${
|
|
159
|
+
const c = $(r), l = b(r.getAttribute("style") || "", "padding", 0) * 2, u = c.endsWith("%") ? Math.floor(s * parseFloat(c) / 100) : parseInt(c), p = Math.max(1, u - l);
|
|
160
|
+
i.setAttribute("width", String(p));
|
|
161
|
+
const a = i.getAttribute("style") || "";
|
|
162
|
+
if (!/\bwidth\s*:\s*\d/i.test(a)) {
|
|
163
|
+
const d = a && !a.trim().endsWith(";") ? "; " : "";
|
|
164
|
+
i.setAttribute("style", `${a}${d}width: ${p}px`);
|
|
157
165
|
}
|
|
158
166
|
});
|
|
159
167
|
}
|
|
160
|
-
function
|
|
161
|
-
const
|
|
162
|
-
return (
|
|
163
|
-
` : "") +
|
|
168
|
+
function B(t, o) {
|
|
169
|
+
const e = t.match(/<!DOCTYPE[^>]*>/i);
|
|
170
|
+
return (e ? `${e[0]}
|
|
171
|
+
` : "") + o.documentElement.outerHTML;
|
|
164
172
|
}
|
|
165
|
-
function
|
|
166
|
-
const
|
|
167
|
-
if (!
|
|
168
|
-
return
|
|
169
|
-
const { buildCampaignUrl:
|
|
173
|
+
function G(t) {
|
|
174
|
+
const o = t.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), e = new DOMParser().parseFromString(o, "text/html"), n = e.querySelectorAll(".recommendation-block-v2");
|
|
175
|
+
if (!n.length)
|
|
176
|
+
return t;
|
|
177
|
+
const { buildCampaignUrl: s } = C(), i = w();
|
|
170
178
|
i.recommendationCampaignUrls = {};
|
|
171
|
-
const { isFeatureEnabled: r } =
|
|
172
|
-
return
|
|
173
|
-
var
|
|
179
|
+
const { isFeatureEnabled: r } = q(), c = r("liquidSyntax") ? "reco_" : "";
|
|
180
|
+
return n.forEach((u) => {
|
|
181
|
+
var a, d;
|
|
174
182
|
const p = u.getAttribute("recommendation-id");
|
|
175
|
-
p && ((
|
|
176
|
-
}),
|
|
183
|
+
p && ((a = u.parentNode) == null || a.insertBefore(e.createComment("REC_START"), u), (d = u.parentNode) == null || d.insertBefore(e.createComment("REC_END"), u.nextSibling), u.querySelectorAll('[data-visibility="0"]').forEach((y) => y.remove()), s(p), P(u) || O(u, p, c), M(u));
|
|
184
|
+
}), B(o, e).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}");
|
|
177
185
|
}
|
|
178
186
|
export {
|
|
179
|
-
|
|
180
|
-
|
|
187
|
+
f as formatPriceVariable,
|
|
188
|
+
G as prepareRecommendationBlocks
|
|
181
189
|
};
|
|
@@ -88,11 +88,11 @@ function k(o) {
|
|
|
88
88
|
}
|
|
89
89
|
function h(o) {
|
|
90
90
|
var e;
|
|
91
|
-
const t = (
|
|
91
|
+
const t = (c, u) => c == null ? u : c === "1" || c === "true", r = (c, u) => c || u, l = o["data-type"] || o["data-source"], a = k(l), i = I[a];
|
|
92
92
|
let n = o["data-cart_items_select_control_value"] || ((e = i == null ? void 0 : i[0]) == null ? void 0 : e.value) || g.cartItemsSelectControlValue;
|
|
93
93
|
if (n && !n.includes("{{") && /^\d+$/.test(n)) {
|
|
94
|
-
const
|
|
95
|
-
u && u[
|
|
94
|
+
const c = parseInt(n) - 1, u = I[a];
|
|
95
|
+
u && u[c] && (n = u[c].value);
|
|
96
96
|
}
|
|
97
97
|
return {
|
|
98
98
|
initialized: !0,
|
|
@@ -159,13 +159,13 @@ class z {
|
|
|
159
159
|
return this.backfillV2ProductTdAttributes(t);
|
|
160
160
|
let r = this.removeJinjaConditionals(t);
|
|
161
161
|
r = this.replaceTemplateVariables(r);
|
|
162
|
-
const
|
|
162
|
+
const l = this.parser.parseFromString(r, "text/html"), a = l.querySelectorAll(
|
|
163
163
|
"td.esd-cart-items-block, td.esd-browsed-items-block, td.esd-purchased-items-block"
|
|
164
164
|
);
|
|
165
165
|
return q().$patch((n) => {
|
|
166
166
|
n.migrations = { ...n.migrations, [w]: a.length };
|
|
167
167
|
}), a.length === 0 ? (console.warn("ItemsBlockMigrator: No blocks found with items block selectors"), r) : (a.forEach((n) => {
|
|
168
|
-
const e = this.extractConfiguration(n),
|
|
168
|
+
const e = this.extractConfiguration(n), c = F({
|
|
169
169
|
orientation: e.orientation,
|
|
170
170
|
itemsType: e.itemsType,
|
|
171
171
|
itemId: e.itemId,
|
|
@@ -181,7 +181,7 @@ class z {
|
|
|
181
181
|
quantityStyles: e.quantityStyles,
|
|
182
182
|
nodeConfig: h(e.configBlockAttributes)
|
|
183
183
|
}), s = this.parser.parseFromString(
|
|
184
|
-
`<table><tbody><tr>${
|
|
184
|
+
`<table><tbody><tr>${c}</tr></tbody></table>`,
|
|
185
185
|
"text/html"
|
|
186
186
|
).querySelector("td");
|
|
187
187
|
if (s && n.parentNode) {
|
|
@@ -190,7 +190,7 @@ class z {
|
|
|
190
190
|
const d = s.querySelector("esd-config-block");
|
|
191
191
|
d && d.remove(), n.parentNode.replaceChild(s, n);
|
|
192
192
|
}
|
|
193
|
-
}),
|
|
193
|
+
}), l.documentElement.outerHTML);
|
|
194
194
|
} catch (r) {
|
|
195
195
|
return console.error("ItemsBlockMigrator failed:", r), t;
|
|
196
196
|
}
|
|
@@ -205,7 +205,7 @@ class z {
|
|
|
205
205
|
var C, D, P;
|
|
206
206
|
const r = k(
|
|
207
207
|
((C = t.querySelector("[data-type]")) == null ? void 0 : C.getAttribute("data-type")) ?? null
|
|
208
|
-
),
|
|
208
|
+
), l = ((D = t.querySelector("[data-number]")) == null ? void 0 : D.getAttribute("data-number")) || "1", a = parseInt(l) - 1, i = I[r], n = ((P = i == null ? void 0 : i[a]) == null ? void 0 : P.value) || i[0].value, e = t.querySelector('[product-attr="price"]'), c = (e == null ? void 0 : e.getAttribute("data-currency_symbol")) || "USD", s = ((e == null ? void 0 : e.getAttribute("data-curency")) || "before") === "after" ? "1" : "0", _ = (e == null ? void 0 : e.getAttribute("data-formated")) !== "false", d = this.extractConfigBlockAttributes(t, r, l), b = d["data-card_orientation_control_value"];
|
|
209
209
|
let S;
|
|
210
210
|
b ? S = b === "horizontal" ? "horizontal" : "vertical" : S = t.querySelector('[colspan="2"]') !== null ? "vertical" : "horizontal";
|
|
211
211
|
const y = t.querySelector('a[product-attr="name"]'), A = (y == null ? void 0 : y.getAttribute("style")) || void 0, f = t.querySelector('a[product-attr="button"]'), m = (f == null ? void 0 : f.getAttribute("style")) || void 0, R = (e == null ? void 0 : e.getAttribute("style")) || void 0, T = t.querySelector("p.original-price"), L = (T == null ? void 0 : T.getAttribute("style")) || void 0, E = t.querySelector('[product-attr="quantity"]'), B = (E == null ? void 0 : E.getAttribute("style")) || void 0;
|
|
@@ -213,7 +213,7 @@ class z {
|
|
|
213
213
|
orientation: S,
|
|
214
214
|
itemsType: r,
|
|
215
215
|
itemId: n,
|
|
216
|
-
currencySymbol:
|
|
216
|
+
currencySymbol: c,
|
|
217
217
|
currencyLocation: s,
|
|
218
218
|
formattedPrice: _,
|
|
219
219
|
configBlockAttributes: d,
|
|
@@ -231,7 +231,7 @@ class z {
|
|
|
231
231
|
* @param itemsType - The type of items (CART_ITEMS, BROWSED_ITEMS, PURCHASED_ITEMS)
|
|
232
232
|
* @param itemNumber - The item number (1-based index)
|
|
233
233
|
*/
|
|
234
|
-
extractConfigBlockAttributes(t, r,
|
|
234
|
+
extractConfigBlockAttributes(t, r, l) {
|
|
235
235
|
const a = t.querySelector("esd-config-block"), i = {};
|
|
236
236
|
if (!a)
|
|
237
237
|
return this.getDefaultConfigBlockAttributes();
|
|
@@ -240,18 +240,18 @@ class z {
|
|
|
240
240
|
}), i["data-cart_items_select_control_value"]) {
|
|
241
241
|
const e = i["data-cart_items_select_control_value"];
|
|
242
242
|
if (/^\d+$/.test(e)) {
|
|
243
|
-
const
|
|
244
|
-
u && u[
|
|
243
|
+
const c = parseInt(e) - 1, u = I[r];
|
|
244
|
+
u && u[c] && (i["data-cart_items_select_control_value"] = u[c].value);
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
if (i["data-product_price_control_curency"]) {
|
|
248
248
|
const e = i["data-product_price_control_curency"];
|
|
249
|
-
let
|
|
250
|
-
e === "before" ?
|
|
249
|
+
let c = e;
|
|
250
|
+
e === "before" ? c = "0" : e === "after" && (c = "1"), i["data-product_price_control_curency"] = c, i["data-product_price_currency_location"] = c;
|
|
251
251
|
}
|
|
252
252
|
(!i["data-product_price_control_currency_symbol"] || i["data-product_price_control_currency_symbol"].trim() === "") && (i["data-product_price_control_currency_symbol"] = "USD");
|
|
253
253
|
const n = { ...this.getDefaultConfigBlockAttributes(), ...i };
|
|
254
|
-
return n["data-type"] = r, n["data-source"] = r, n["data-product_image_link"] = $(r,
|
|
254
|
+
return n["data-type"] = r, n["data-source"] = r, n["data-product_image_link"] = $(r, l), n["data-product_button_link"] = N(r, l), n;
|
|
255
255
|
}
|
|
256
256
|
/**
|
|
257
257
|
* Returns default esd-config-block attributes based on the old template structure
|
|
@@ -326,9 +326,9 @@ class z {
|
|
|
326
326
|
if (!t.includes("ins-product-td") || !t.includes("esd-ext-config"))
|
|
327
327
|
return t;
|
|
328
328
|
const r = this.parser.parseFromString(t, "text/html");
|
|
329
|
-
let
|
|
329
|
+
let l = !1;
|
|
330
330
|
return r.querySelectorAll(".ins-product-td").forEach((a) => {
|
|
331
|
-
if (a.hasAttribute("width") && (a.removeAttribute("width"),
|
|
331
|
+
if (a.hasAttribute("width") && (a.removeAttribute("width"), l = !0), a.getAttribute("data-type"))
|
|
332
332
|
return;
|
|
333
333
|
const i = a.getAttribute("esd-ext-config");
|
|
334
334
|
if (i)
|
|
@@ -336,13 +336,12 @@ class z {
|
|
|
336
336
|
const n = JSON.parse(i), e = n.type || n.source;
|
|
337
337
|
if (!e)
|
|
338
338
|
return;
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
339
|
+
a.setAttribute("data-type", e), l = !0;
|
|
340
|
+
const c = typeof n.itemsSelectValue == "string" ? n.itemsSelectValue.match(/\((\d+)\)/) : null;
|
|
341
|
+
c && a.getAttribute("data-number") !== c[1] && a.setAttribute("data-number", c[1]);
|
|
343
342
|
} catch {
|
|
344
343
|
}
|
|
345
|
-
}),
|
|
344
|
+
}), l ? r.documentElement.outerHTML : t;
|
|
346
345
|
}
|
|
347
346
|
/**
|
|
348
347
|
* Fast check for the presence of any items block (cart / browsed / purchased)
|
|
@@ -363,15 +362,15 @@ class z {
|
|
|
363
362
|
* contains display condition Jinja scripts that should NOT be removed.
|
|
364
363
|
*/
|
|
365
364
|
removeJinjaConditionals(t) {
|
|
366
|
-
const r = "__ESD_DISPLAY_CONDITIONS_PLACEHOLDER__",
|
|
367
|
-
let a =
|
|
365
|
+
const r = "__ESD_DISPLAY_CONDITIONS_PLACEHOLDER__", l = t.match(/esd-custom-display-conditions="[^"]*"/);
|
|
366
|
+
let a = l ? t.replace(l[0], r) : t;
|
|
368
367
|
return a = a.replace(
|
|
369
368
|
/\{%\s*if\s+(ins_apr|browsed_item|purchased_item)_total_product_kind\s*(>|>)\s*\d+\s*%\}/g,
|
|
370
369
|
""
|
|
371
370
|
), a = a.replace(
|
|
372
371
|
/\{%\s*if\s+(ins_apr|browsed_item|purchased_item)_price_\d+\s*(!=|!=)\s*\1_originalprice_\d+\s*%\}/g,
|
|
373
372
|
""
|
|
374
|
-
), a = a.replace(/\{%\s*endif\s*%\}/g, ""),
|
|
373
|
+
), a = a.replace(/\{%\s*endif\s*%\}/g, ""), l && (a = a.replace(r, l[0])), a = a.replace(/\n\s*\n\s*\n/g, `
|
|
375
374
|
|
|
376
375
|
`), a;
|
|
377
376
|
}
|
|
@@ -386,25 +385,25 @@ class z {
|
|
|
386
385
|
*/
|
|
387
386
|
replaceTemplateVariables(t) {
|
|
388
387
|
const { PAIRS_FOR_EXTENSION: r } = K;
|
|
389
|
-
return t.replace(/{{([^}]+)}}/g, (
|
|
388
|
+
return t.replace(/{{([^}]+)}}/g, (l, a) => {
|
|
390
389
|
const i = a.match(/^(ins_apr|browsed_item|purchased_item)_([a-z_]+)_(\d+)$/);
|
|
391
390
|
if (!i)
|
|
392
|
-
return
|
|
393
|
-
const [, n, e,
|
|
391
|
+
return l;
|
|
392
|
+
const [, n, e, c] = i, u = V[n];
|
|
394
393
|
if (!u)
|
|
395
|
-
return console.warn(`Unknown variable prefix: ${n}`),
|
|
394
|
+
return console.warn(`Unknown variable prefix: ${n}`), l;
|
|
396
395
|
const s = x[e];
|
|
397
396
|
if (!s)
|
|
398
|
-
return console.warn(`Unknown variable suffix mapping for: ${e}`),
|
|
397
|
+
return console.warn(`Unknown variable suffix mapping for: ${e}`), l;
|
|
399
398
|
const { pairsKey: _, defaultKey: d, isArray: b } = s, y = r[_][u];
|
|
400
399
|
if (!y)
|
|
401
|
-
return console.warn(`No data found for: ${_}.${u}`),
|
|
400
|
+
return console.warn(`No data found for: ${_}.${u}`), l;
|
|
402
401
|
if (b) {
|
|
403
|
-
const f = parseInt(
|
|
404
|
-
return Array.isArray(m) && m[f] ? m[f] : (console.warn(`Array value not found: ${_}.${u}.${d}[${f}]`),
|
|
402
|
+
const f = parseInt(c) - 1, m = y[d];
|
|
403
|
+
return Array.isArray(m) && m[f] ? m[f] : (console.warn(`Array value not found: ${_}.${u}.${d}[${f}]`), l);
|
|
405
404
|
}
|
|
406
405
|
const A = y[d];
|
|
407
|
-
return A !== void 0 ? String(A) : (console.warn(`Default value not found: ${_}.${u}.${d}`),
|
|
406
|
+
return A !== void 0 ? String(A) : (console.warn(`Default value not found: ${_}.${u}.${d}`), l);
|
|
408
407
|
});
|
|
409
408
|
}
|
|
410
409
|
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { BlockId as
|
|
1
|
+
import { BlockId as g } from "../../../enums/block.js";
|
|
2
2
|
import { useOnboardingStore as p } from "../../../stores/onboarding.js";
|
|
3
|
-
import { getMigrationBannerHtml as
|
|
4
|
-
import { Block as I, BlockCompositionType as
|
|
5
|
-
import { SETTINGS_ENUMS as
|
|
6
|
-
import { getDefaultTemplate as
|
|
7
|
-
import { getItemsBlockContainer as
|
|
8
|
-
const
|
|
9
|
-
class
|
|
3
|
+
import { getMigrationBannerHtml as y } from "../../../utils/migrationBannerHtml.js";
|
|
4
|
+
import { Block as I, BlockCompositionType as C, ModificationDescription as c } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
5
|
+
import { SETTINGS_ENUMS as l, DefaultConfigValues as m } from "./enums/settingsEnums.js";
|
|
6
|
+
import { getDefaultTemplate as b } from "./template.js";
|
|
7
|
+
import { getItemsBlockContainer as d, getItemsBlockConfig as u, deriveItemNumber as h, getDefaultItemsBlockConfig as N } from "./utils/nodeConfigUtils.js";
|
|
8
|
+
const f = g.Items;
|
|
9
|
+
class P extends I {
|
|
10
10
|
getId() {
|
|
11
|
-
return
|
|
11
|
+
return f;
|
|
12
12
|
}
|
|
13
13
|
getIcon() {
|
|
14
14
|
return "items-icon";
|
|
15
15
|
}
|
|
16
16
|
getBlockCompositionType() {
|
|
17
|
-
return
|
|
17
|
+
return C.CONTAINER;
|
|
18
18
|
}
|
|
19
19
|
getName() {
|
|
20
20
|
return this.api.translate("Items");
|
|
@@ -23,20 +23,20 @@ class E extends I {
|
|
|
23
23
|
return this.api.translate("Items lets you display personalized products based on user behavior.");
|
|
24
24
|
}
|
|
25
25
|
getSettingsPanelTitleHtml() {
|
|
26
|
-
return
|
|
27
|
-
|
|
26
|
+
return y(
|
|
27
|
+
f,
|
|
28
28
|
this.api.translate("Items"),
|
|
29
29
|
this.api.translate("This block is switched from the Old Version to the New Version. We recommend you check the Items block and test your message to ensure it works properly.")
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
32
|
getTemplate() {
|
|
33
|
-
return
|
|
34
|
-
orientation:
|
|
35
|
-
itemsType:
|
|
33
|
+
return b({
|
|
34
|
+
orientation: l.ORIENTATION.VERTICAL,
|
|
35
|
+
itemsType: l.ITEMS_TYPE.CART_ITEMS,
|
|
36
36
|
itemId: "{{Abandoned Cart Item (1) Url}}",
|
|
37
|
-
currencySymbol:
|
|
38
|
-
currencyLocation:
|
|
39
|
-
formattedPrice:
|
|
37
|
+
currencySymbol: m.productPriceCurrencySymbolControlValue,
|
|
38
|
+
currencyLocation: m.productPriceCurrencyLocationControlValue,
|
|
39
|
+
formattedPrice: m.productPriceFormattedControlValue === "1"
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
allowInnerBlocksDND() {
|
|
@@ -45,18 +45,23 @@ class E extends I {
|
|
|
45
45
|
canBeSavedAsModule() {
|
|
46
46
|
return !0;
|
|
47
47
|
}
|
|
48
|
-
onCreated(
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
if (!
|
|
48
|
+
onCreated(o) {
|
|
49
|
+
const t = this.api.getDocumentModifier(), i = this.api.getDocumentRootCssNode();
|
|
50
|
+
i.querySelector('[product-attr="imageSrc"] img') || t.modifyCss(i).appendRule('[product-attr="imageSrc"] img {object-fit: contain;}');
|
|
51
|
+
const e = d(o);
|
|
52
|
+
if (!e)
|
|
53
53
|
return;
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
|
|
54
|
+
const r = e.getNodeConfig(), s = r && Object.keys(r).length > 0, n = u(o);
|
|
55
|
+
if (n != null && n.initialized)
|
|
56
|
+
if (s)
|
|
57
|
+
n.blockInstanceId || this.api.getDocumentModifier().modifyHtml(e).setNodeConfig({ ...n, blockInstanceId: String(Date.now()) }).apply(new c("Assign block instance ID to block"));
|
|
58
|
+
else {
|
|
59
|
+
const a = this.api.getDocumentModifier();
|
|
60
|
+
a.modifyHtml(e).setNodeConfig(n), this._stampProductTdDomAttributes(e, n, a), a.apply(new c("Migrate legacy config to nodeConfig"));
|
|
61
|
+
}
|
|
57
62
|
else {
|
|
58
|
-
const
|
|
59
|
-
this.api.getDocumentModifier().modifyHtml(
|
|
63
|
+
const a = N();
|
|
64
|
+
this.api.getDocumentModifier().modifyHtml(e).setNodeConfig(a).apply(new c("Initialize Items block with default configuration")), p().startOnboarding("itemsOnboarding");
|
|
60
65
|
}
|
|
61
66
|
}
|
|
62
67
|
/**
|
|
@@ -65,18 +70,33 @@ class E extends I {
|
|
|
65
70
|
* into nodeConfig, so without this a reused module would reset to defaults.
|
|
66
71
|
* Guarded to the nodeConfig-empty case so it runs once and never loops.
|
|
67
72
|
*/
|
|
68
|
-
onDocumentChanged(
|
|
69
|
-
const
|
|
70
|
-
if (!
|
|
73
|
+
onDocumentChanged(o) {
|
|
74
|
+
const t = d(o);
|
|
75
|
+
if (!t)
|
|
76
|
+
return;
|
|
77
|
+
const i = t.getNodeConfig();
|
|
78
|
+
if (i && Object.keys(i).length > 0)
|
|
71
79
|
return;
|
|
72
|
-
const r =
|
|
73
|
-
if (r &&
|
|
80
|
+
const r = u(o);
|
|
81
|
+
if (!(r != null && r.initialized))
|
|
74
82
|
return;
|
|
75
|
-
const
|
|
76
|
-
|
|
83
|
+
const s = this.api.getDocumentModifier();
|
|
84
|
+
s.modifyHtml(t).setNodeConfig(r), this._stampProductTdDomAttributes(t, r, s), s.apply(new c("Recover Items block config from saved module"));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Bakes the compiler-read DOM attributes (`data-type`, `data-number`) onto the
|
|
88
|
+
* `.ins-product-td` container from the recovered config. Required for saved modules:
|
|
89
|
+
* `migrate()` (which backfills these) only runs at template load — never when a module
|
|
90
|
+
* is dropped into a live editor — so this is the one place the namespace + index get
|
|
91
|
+
* restored before export. The name `<a>` carries no data-type/data-number of its own and
|
|
92
|
+
* relies on this td-level fallback in pairProductVariables.
|
|
93
|
+
*/
|
|
94
|
+
_stampProductTdDomAttributes(o, t, i) {
|
|
95
|
+
const e = h(t.itemsSelectValue, t.type);
|
|
96
|
+
i.modifyHtml(o).setAttribute("data-type", t.type), i.modifyHtml(o).setAttribute("data-number", e);
|
|
77
97
|
}
|
|
78
98
|
}
|
|
79
99
|
export {
|
|
80
|
-
|
|
81
|
-
|
|
100
|
+
f as BLOCK_ID,
|
|
101
|
+
P as ItemsBlock
|
|
82
102
|
};
|