@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.
@@ -1,181 +1,189 @@
1
- import { useConfig as _ } from "../../../composables/useConfig.js";
2
- import { useRecommendation as g } from "../../../composables/useRecommendation.js";
3
- import { CSS_CLASS_RECO_BUTTON as q } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
4
- import { useRecommendationExtensionStore as C } from "../../../extensions/Blocks/Recommendation/store/recommendation.js";
5
- import { isIgnoredRecommendationBlock as w } from "./recommendationIgnoreUtils.js";
6
- function b(e, n, t, o, c = "") {
7
- const i = `{{${c}${e}_${n}_${t}}}`, r = `{{${c}${e}_${n}_currency}}`;
8
- return o === "before" ? `${r} ${i}` : `${i} ${r}`;
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(e) {
11
- let n = e;
12
- for (; n.children.length === 1; )
13
- [n] = n.children;
14
- return n;
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(e, n, t, o, c, i) {
17
- switch (n) {
16
+ function h(t, o, e, n, s, i) {
17
+ switch (o) {
18
18
  case "productImage": {
19
- const r = e.querySelector("img");
20
- r && (r.setAttribute("src", `{{${i}${t}_${o}_image_url}}`), r.setAttribute("alt", `{{${i}${t}_${o}_name}}`));
21
- const s = e.querySelector("a");
22
- s && (s.setAttribute("href", `{{${i}${t}_${o}_url}}`), s.classList.add(q));
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 = e.querySelector("p");
27
- r && (m(r).textContent = `{{${i}${t}_${o}_name}}`);
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 = e.querySelector(".product-price p") ?? e.querySelector("p");
32
- r && (m(r).textContent = b(
33
- t,
34
- o,
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
- c,
36
+ s,
37
37
  i
38
38
  ));
39
- const s = e.querySelector(".product-old-price p");
40
- s && (m(s).textContent = b(
41
- t,
42
- o,
39
+ const c = t.querySelector(".product-old-price p");
40
+ c && (m(c).textContent = f(
41
+ e,
42
+ n,
43
43
  "original_price",
44
- c,
44
+ s,
45
45
  i
46
46
  ));
47
47
  break;
48
48
  }
49
49
  case "productOldPrice": {
50
- const r = e.querySelector("p");
51
- r && (m(r).textContent = b(
52
- t,
53
- o,
50
+ const r = t.querySelector("p");
51
+ r && (m(r).textContent = f(
52
+ e,
53
+ n,
54
54
  "original_price",
55
- c,
55
+ s,
56
56
  i
57
57
  ));
58
58
  break;
59
59
  }
60
60
  case "productButton": {
61
- const r = e.querySelector("a");
62
- r && r.setAttribute("href", `{{${i}${t}_${o}_url}}`);
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 = e.querySelector(".omnibus-price-value");
66
+ const r = t.querySelector(".omnibus-price-value");
67
67
  if (r) {
68
- r.textContent = `{{${i}${t}_${o}_omnibus_price}}`;
69
- const s = r.closest("p");
70
- s && (s.setAttribute("product-attr", "omnibus_price"), s.setAttribute("composition", "true"));
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 = e.querySelector(".omnibus-discount-value");
75
+ const r = t.querySelector(".omnibus-discount-value");
76
76
  if (r) {
77
- r.textContent = `{{${i}${t}_${o}_omnibus_discount}}`;
78
- const s = r.closest("p");
79
- s && (s.setAttribute("product-attr", "omnibus_discount"), s.setAttribute("composition", "true"));
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 = e.getAttribute("product-attr") ? e : e.querySelector("[product-attr]");
84
+ const r = t.getAttribute("product-attr") ? t : t.querySelector("[product-attr]");
85
85
  if (r) {
86
- const s = r.getAttribute("product-attr"), a = r.querySelector("p");
87
- a && (m(a).textContent = `{{${i}${t}_${o}_${s}}}`);
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 E(e, n, t, o) {
94
- e.querySelectorAll(".recommendation-product-row").forEach((i, r) => {
95
- i.querySelectorAll("[data-attribute-type]").forEach((a) => {
96
- const u = a.getAttribute("data-attribute-type") || "", p = a.querySelectorAll(".attribute-cell");
97
- p.length > 0 ? p.forEach((l) => {
98
- h(l, u, n, r, t, o);
99
- }) : h(a, u, n, r, t, o);
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 P(e, n, t, o) {
104
- const c = e.querySelectorAll(".recommendation-product-row");
105
- if (!c.length)
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] = c, r = i.querySelector("[data-attribute-type]"), s = r ? r.querySelectorAll(".attribute-cell").length : 1;
108
- c.forEach((a, u) => {
109
- a.querySelectorAll("[data-attribute-type]").forEach((l) => {
110
- const d = l.getAttribute("data-attribute-type") || "";
111
- l.querySelectorAll(".attribute-cell").forEach((A, $) => {
112
- const S = u * s + $;
113
- h(A, d, n, S, t, o);
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 R(e, n, t, o) {
119
- e.querySelectorAll(".ins-recommendation-product-container").forEach((i) => {
120
- P(i, n, t, o);
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(e, n, t) {
124
- const o = e.getAttribute("data-layout") || "grid", c = e.getAttribute("currency-alignment") || "after";
125
- o === "list" ? E(e, n, c, t) : R(e, n, c, t);
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 y(e, n, t) {
128
- const o = new RegExp(`${n}\\s*:\\s*(\\d+)\\s*px`, "i"), c = e.match(o);
129
- return c ? parseInt(c[1]) : t;
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 T(e, n) {
132
- let t = e.parentElement;
133
- for (; t && t !== n; ) {
134
- if (t.tagName === "TD") {
135
- const o = t.getAttribute("width");
136
- if (o && o.endsWith("%") && parseFloat(o) < 100)
137
- return t;
138
- }
139
- t = t.parentElement;
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 v(e) {
144
- const n = e.getAttribute("style") || "", t = y(n, "width", 600), o = y(n, "padding", 0) * 2, c = Math.max(0, t - o);
145
- c !== 0 && e.querySelectorAll("img.adapt-img").forEach((i) => {
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, e);
156
+ const r = T(i, t);
149
157
  if (!r)
150
158
  return;
151
- const s = r.getAttribute("width"), a = parseFloat(s), u = y(r.getAttribute("style") || "", "padding", 0) * 2, p = Math.floor(c * a / 100), l = Math.max(1, p - u);
152
- i.setAttribute("width", String(l));
153
- const d = i.getAttribute("style") || "";
154
- if (!/\bwidth\s*:\s*\d/i.test(d)) {
155
- const f = d && !d.trim().endsWith(";") ? "; " : "";
156
- i.setAttribute("style", `${d}${f}width: ${l}px`);
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 W(e, n) {
161
- const t = e.match(/<!DOCTYPE[^>]*>/i);
162
- return (t ? `${t[0]}
163
- ` : "") + n.documentElement.outerHTML;
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 F(e) {
166
- const n = e.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), t = new DOMParser().parseFromString(n, "text/html"), o = t.querySelectorAll(".recommendation-block-v2");
167
- if (!o.length)
168
- return e;
169
- const { buildCampaignUrl: c } = g(), i = C();
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 } = _(), s = r("liquidSyntax") ? "reco_" : "";
172
- return o.forEach((u) => {
173
- var l, d;
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 && ((l = u.parentNode) == null || l.insertBefore(t.createComment("REC_START"), u), (d = u.parentNode) == null || d.insertBefore(t.createComment("REC_END"), u.nextSibling), u.querySelectorAll('[data-visibility="0"]').forEach((f) => f.remove()), c(p), w(u) || O(u, p, s), v(u));
176
- }), W(n, t).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
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("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
177
185
  }
178
186
  export {
179
- b as formatPriceVariable,
180
- F as prepareRecommendationBlocks
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 = (l, u) => l == null ? u : l === "1" || l === "true", r = (l, u) => l || u, c = o["data-type"] || o["data-source"], a = k(c), i = I[a];
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 l = parseInt(n) - 1, u = I[a];
95
- u && u[l] && (n = u[l].value);
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 c = this.parser.parseFromString(r, "text/html"), a = c.querySelectorAll(
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), l = F({
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>${l}</tr></tbody></table>`,
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
- }), c.documentElement.outerHTML);
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
- ), c = ((D = t.querySelector("[data-number]")) == null ? void 0 : D.getAttribute("data-number")) || "1", a = parseInt(c) - 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"]'), l = (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, c), b = d["data-card_orientation_control_value"];
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: l,
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, c) {
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 l = parseInt(e) - 1, u = I[r];
244
- u && u[l] && (i["data-cart_items_select_control_value"] = u[l].value);
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 l = e;
250
- e === "before" ? l = "0" : e === "after" && (l = "1"), i["data-product_price_control_curency"] = l, i["data-product_price_currency_location"] = l;
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, c), n["data-product_button_link"] = N(r, c), n;
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 c = !1;
329
+ let l = !1;
330
330
  return r.querySelectorAll(".ins-product-td").forEach((a) => {
331
- if (a.hasAttribute("width") && (a.removeAttribute("width"), c = !0), a.getAttribute("data-type"))
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
- if (a.setAttribute("data-type", e), c = !0, !a.getAttribute("data-number")) {
340
- const l = typeof n.itemsSelectValue == "string" ? n.itemsSelectValue.match(/\((\d+)\)/) : null;
341
- l && a.setAttribute("data-number", l[1]);
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
- }), c ? r.documentElement.outerHTML : t;
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__", c = t.match(/esd-custom-display-conditions="[^"]*"/);
367
- let a = c ? t.replace(c[0], r) : t;
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*(&gt;|>)\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*(!&#61;|!=)\s*\1_originalprice_\d+\s*%\}/g,
373
372
  ""
374
- ), a = a.replace(/\{%\s*endif\s*%\}/g, ""), c && (a = a.replace(r, c[0])), a = a.replace(/\n\s*\n\s*\n/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, (c, a) => {
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 c;
393
- const [, n, e, l] = i, u = V[n];
391
+ return l;
392
+ const [, n, e, c] = i, u = V[n];
394
393
  if (!u)
395
- return console.warn(`Unknown variable prefix: ${n}`), c;
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}`), c;
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}`), c;
400
+ return console.warn(`No data found for: ${_}.${u}`), l;
402
401
  if (b) {
403
- const f = parseInt(l) - 1, m = y[d];
404
- return Array.isArray(m) && m[f] ? m[f] : (console.warn(`Array value not found: ${_}.${u}.${d}[${f}]`), c);
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}`), c);
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 u } from "../../../enums/block.js";
1
+ import { BlockId as g } from "../../../enums/block.js";
2
2
  import { useOnboardingStore as p } from "../../../stores/onboarding.js";
3
- import { getMigrationBannerHtml as C } from "../../../utils/migrationBannerHtml.js";
4
- import { Block as I, BlockCompositionType as y, ModificationDescription as s } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
5
- import { SETTINGS_ENUMS as c, DefaultConfigValues as a } from "./enums/settingsEnums.js";
6
- import { getDefaultTemplate as h } from "./template.js";
7
- import { getItemsBlockContainer as l, getItemsBlockConfig as m, getDefaultItemsBlockConfig as b } from "./utils/nodeConfigUtils.js";
8
- const d = u.Items;
9
- class E extends I {
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 d;
11
+ return f;
12
12
  }
13
13
  getIcon() {
14
14
  return "items-icon";
15
15
  }
16
16
  getBlockCompositionType() {
17
- return y.CONTAINER;
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 C(
27
- d,
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 h({
34
- orientation: c.ORIENTATION.VERTICAL,
35
- itemsType: c.ITEMS_TYPE.CART_ITEMS,
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: a.productPriceCurrencySymbolControlValue,
38
- currencyLocation: a.productPriceCurrencyLocationControlValue,
39
- formattedPrice: a.productPriceFormattedControlValue === "1"
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(i) {
49
- const n = this.api.getDocumentModifier(), r = this.api.getDocumentRootCssNode();
50
- r.querySelector('[product-attr="imageSrc"] img') || n.modifyCss(r).appendRule('[product-attr="imageSrc"] img {object-fit: contain;}');
51
- const t = l(i);
52
- if (!t)
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 e = t.getNodeConfig(), g = e && Object.keys(e).length > 0, o = m(i);
55
- if (o != null && o.initialized)
56
- g ? o.blockInstanceId || this.api.getDocumentModifier().modifyHtml(t).setNodeConfig({ ...o, blockInstanceId: String(Date.now()) }).apply(new s("Assign block instance ID to block")) : this.api.getDocumentModifier().modifyHtml(t).setNodeConfig(o).apply(new s("Migrate legacy config to nodeConfig"));
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 f = b();
59
- this.api.getDocumentModifier().modifyHtml(t).setNodeConfig(f).apply(new s("Initialize Items block with default configuration")), p().startOnboarding("itemsOnboarding");
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(i) {
69
- const n = l(i);
70
- if (!n)
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 = n.getNodeConfig();
73
- if (r && Object.keys(r).length > 0)
80
+ const r = u(o);
81
+ if (!(r != null && r.initialized))
74
82
  return;
75
- const e = m(i);
76
- e != null && e.initialized && this.api.getDocumentModifier().modifyHtml(n).setNodeConfig(e).apply(new s("Recover Items block config from saved module"));
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
- d as BLOCK_ID,
81
- E as ItemsBlock
100
+ f as BLOCK_ID,
101
+ P as ItemsBlock
82
102
  };