@useinsider/guido 3.4.1 → 3.5.0-beta.17c0032

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.
Files changed (28) hide show
  1. package/README.md +2 -0
  2. package/dist/components/Guido.vue.js +1 -1
  3. package/dist/components/Guido.vue2.js +50 -48
  4. package/dist/components/organisms/extensions/recommendation/FilterItem.vue.js +2 -2
  5. package/dist/components/organisms/extensions/recommendation/FilterItem.vue2.js +49 -49
  6. package/dist/composables/useActionsApi.js +9 -5
  7. package/dist/composables/useSave.js +13 -14
  8. package/dist/config/compiler/utils/recommendationCompilerUtils.js +60 -58
  9. package/dist/config/migrator/itemsBlockMigrator.js +28 -18
  10. package/dist/extensions/Blocks/Recommendation/block.js +90 -45
  11. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +33 -14
  12. package/dist/extensions/Blocks/Recommendation/utils/filterUtil.js +24 -16
  13. package/dist/extensions/Blocks/Unsubscribe/block.js +133 -49
  14. package/dist/extensions/Blocks/Unsubscribe/template.js +8 -8
  15. package/dist/extensions/Blocks/Unsubscribe/utils/constants.js +2 -1
  16. package/dist/guido.css +1 -1
  17. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +145 -144
  18. package/dist/src/composables/useActionsApi.d.ts +1 -1
  19. package/dist/src/extensions/Blocks/Recommendation/block.d.ts +10 -0
  20. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +5 -0
  21. package/dist/src/extensions/Blocks/Recommendation/utils/filterUtil.d.ts +2 -0
  22. package/dist/src/extensions/Blocks/Unsubscribe/block.d.ts +20 -1
  23. package/dist/src/extensions/Blocks/Unsubscribe/utils/constants.d.ts +1 -0
  24. package/dist/src/stores/config.test.d.ts +1 -0
  25. package/dist/src/vitest.setup.d.ts +0 -0
  26. package/dist/stores/config.js +24 -23
  27. package/dist/utils/templatePreparation.js +51 -43
  28. package/package.json +3 -2
@@ -2,126 +2,128 @@ import { useConfig as S } from "../../../composables/useConfig.js";
2
2
  import { useRecommendation as g } from "../../../composables/useRecommendation.js";
3
3
  import { CSS_CLASS_RECO_BUTTON as _ } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
4
4
  import { useRecommendationExtensionStore as q } from "../../../extensions/Blocks/Recommendation/store/recommendation.js";
5
- function y(r, c, e, o, s = "") {
6
- const n = `{{${s}${r}_${c}_${e}}}`, t = `{{${s}${r}_${c}_currency}}`;
7
- return o === "before" ? `${t} ${n}` : `${n} ${t}`;
5
+ function y(r, i, e, o, s = "") {
6
+ const c = `{{${s}${r}_${i}_${e}}}`, t = `{{${s}${r}_${i}_currency}}`;
7
+ return o === "before" ? `${t} ${c}` : `${c} ${t}`;
8
8
  }
9
- function f(r, c, e, o, s, n) {
10
- switch (c) {
9
+ function f(r, i, e, o, s, c) {
10
+ switch (i) {
11
11
  case "productImage": {
12
12
  const t = r.querySelector("img");
13
- t && (t.setAttribute("src", `{{${n}${e}_${o}_image_url}}`), t.setAttribute("alt", `{{${n}${e}_${o}_name}}`));
14
- const i = r.querySelector("a");
15
- i && (i.setAttribute("href", `{{${n}${e}_${o}_url}}`), i.classList.add(_));
13
+ t && (t.setAttribute("src", `{{${c}${e}_${o}_image_url}}`), t.setAttribute("alt", `{{${c}${e}_${o}_name}}`));
14
+ const n = r.querySelector("a");
15
+ n && (n.setAttribute("href", `{{${c}${e}_${o}_url}}`), n.classList.add(_));
16
16
  break;
17
17
  }
18
18
  case "productName": {
19
19
  const t = r.querySelector("p");
20
20
  if (t) {
21
- const i = t.querySelector("strong") || t;
22
- i.textContent = `{{${n}${e}_${o}_name}}`;
21
+ const n = t.querySelector("strong") || t;
22
+ n.textContent = `{{${c}${e}_${o}_name}}`;
23
23
  }
24
24
  break;
25
25
  }
26
26
  case "productPrice": {
27
27
  const t = r.querySelector("p");
28
28
  if (t) {
29
- const i = t.querySelector("strong") || t;
30
- i.textContent = y(e, o, "price", s, n);
29
+ const n = t.querySelector("strong") || t;
30
+ n.textContent = y(e, o, "price", s, c);
31
31
  }
32
32
  break;
33
33
  }
34
34
  case "productOldPrice": {
35
35
  const t = r.querySelector("p");
36
36
  if (t) {
37
- const i = t.querySelector("strong") || t;
38
- i.textContent = y(
37
+ let n = t;
38
+ for (; n.children.length === 1; )
39
+ [n] = n.children;
40
+ n.textContent = y(
39
41
  e,
40
42
  o,
41
43
  "original_price",
42
44
  s,
43
- n
45
+ c
44
46
  ), t.setAttribute("product-attr", "discount");
45
47
  }
46
48
  break;
47
49
  }
48
50
  case "productButton": {
49
51
  const t = r.querySelector("a");
50
- t && t.setAttribute("href", `{{${n}${e}_${o}_url}}`);
52
+ t && t.setAttribute("href", `{{${c}${e}_${o}_url}}`);
51
53
  break;
52
54
  }
53
55
  case "productOmnibusPrice": {
54
56
  const t = r.querySelector(".omnibus-price-value");
55
57
  if (t) {
56
- t.textContent = `{{${n}${e}_${o}_omnibus_price}}`;
57
- const i = t.closest("p");
58
- i && (i.setAttribute("product-attr", "omnibus_price"), i.setAttribute("composition", "true"));
58
+ t.textContent = `{{${c}${e}_${o}_omnibus_price}}`;
59
+ const n = t.closest("p");
60
+ n && (n.setAttribute("product-attr", "omnibus_price"), n.setAttribute("composition", "true"));
59
61
  }
60
62
  break;
61
63
  }
62
64
  case "productOmnibusDiscount": {
63
65
  const t = r.querySelector(".omnibus-discount-value");
64
66
  if (t) {
65
- t.textContent = `{{${n}${e}_${o}_omnibus_discount}}`;
66
- const i = t.closest("p");
67
- i && (i.setAttribute("product-attr", "omnibus_discount"), i.setAttribute("composition", "true"));
67
+ t.textContent = `{{${c}${e}_${o}_omnibus_discount}}`;
68
+ const n = t.closest("p");
69
+ n && (n.setAttribute("product-attr", "omnibus_discount"), n.setAttribute("composition", "true"));
68
70
  }
69
71
  break;
70
72
  }
71
73
  default: {
72
74
  const t = r.getAttribute("product-attr") ? r : r.querySelector("[product-attr]");
73
75
  if (t) {
74
- const i = t.getAttribute("product-attr"), a = t.querySelector("p");
76
+ const n = t.getAttribute("product-attr"), a = t.querySelector("p");
75
77
  if (a) {
76
78
  const u = a.querySelector("strong") || a;
77
- u.textContent = `{{${n}${e}_${o}_${i}}}`;
79
+ u.textContent = `{{${c}${e}_${o}_${n}}}`;
78
80
  }
79
81
  }
80
82
  break;
81
83
  }
82
84
  }
83
85
  }
84
- function C(r, c, e, o) {
85
- r.querySelectorAll(".recommendation-product-row").forEach((n, t) => {
86
- n.querySelectorAll("[data-attribute-type]").forEach((a) => {
86
+ function C(r, i, e, o) {
87
+ r.querySelectorAll(".recommendation-product-row").forEach((c, t) => {
88
+ c.querySelectorAll("[data-attribute-type]").forEach((a) => {
87
89
  const u = a.getAttribute("data-attribute-type") || "", p = a.querySelectorAll(".attribute-cell");
88
90
  p.length > 0 ? p.forEach((l) => {
89
- f(l, u, c, t, e, o);
90
- }) : f(a, u, c, t, e, o);
91
+ f(l, u, i, t, e, o);
92
+ }) : f(a, u, i, t, e, o);
91
93
  });
92
94
  });
93
95
  }
94
- function E(r, c, e, o) {
96
+ function w(r, i, e, o) {
95
97
  const s = r.querySelectorAll(".recommendation-product-row");
96
98
  if (!s.length)
97
99
  return;
98
- const [n] = s, t = n.querySelector("[data-attribute-type]"), i = t ? t.querySelectorAll(".attribute-cell").length : 1;
100
+ const [c] = s, t = c.querySelector("[data-attribute-type]"), n = t ? t.querySelectorAll(".attribute-cell").length : 1;
99
101
  s.forEach((a, u) => {
100
102
  a.querySelectorAll("[data-attribute-type]").forEach((l) => {
101
103
  const d = l.getAttribute("data-attribute-type") || "";
102
104
  l.querySelectorAll(".attribute-cell").forEach((A, h) => {
103
- const $ = u * i + h;
104
- f(A, d, c, $, e, o);
105
+ const $ = u * n + h;
106
+ f(A, d, i, $, e, o);
105
107
  });
106
108
  });
107
109
  });
108
110
  }
109
- function w(r, c, e, o) {
110
- r.querySelectorAll(".ins-recommendation-product-container").forEach((n) => {
111
- E(n, c, e, o);
111
+ function E(r, i, e, o) {
112
+ r.querySelectorAll(".ins-recommendation-product-container").forEach((c) => {
113
+ w(c, i, e, o);
112
114
  });
113
115
  }
114
- function R(r, c, e) {
116
+ function R(r, i, e) {
115
117
  const o = r.getAttribute("data-layout") || "grid", s = r.getAttribute("currency-alignment") || "after";
116
- o === "list" ? C(r, c, s, e) : w(r, c, s, e);
118
+ o === "list" ? C(r, i, s, e) : E(r, i, s, e);
117
119
  }
118
- function b(r, c, e) {
119
- const o = new RegExp(`${c}\\s*:\\s*(\\d+)\\s*px`, "i"), s = r.match(o);
120
+ function b(r, i, e) {
121
+ const o = new RegExp(`${i}\\s*:\\s*(\\d+)\\s*px`, "i"), s = r.match(o);
120
122
  return s ? parseInt(s[1]) : e;
121
123
  }
122
- function P(r, c) {
124
+ function P(r, i) {
123
125
  let e = r.parentElement;
124
- for (; e && e !== c; ) {
126
+ for (; e && e !== i; ) {
125
127
  if (e.tagName === "TD") {
126
128
  const o = e.getAttribute("width");
127
129
  if (o && o.endsWith("%") && parseFloat(o) < 100)
@@ -132,39 +134,39 @@ function P(r, c) {
132
134
  return null;
133
135
  }
134
136
  function T(r) {
135
- const c = r.getAttribute("style") || "", e = b(c, "width", 600), o = b(c, "padding", 0) * 2, s = Math.max(0, e - o);
136
- s !== 0 && r.querySelectorAll("img.adapt-img").forEach((n) => {
137
- if (n.hasAttribute("width"))
137
+ const i = r.getAttribute("style") || "", e = b(i, "width", 600), o = b(i, "padding", 0) * 2, s = Math.max(0, e - o);
138
+ s !== 0 && r.querySelectorAll("img.adapt-img").forEach((c) => {
139
+ if (c.hasAttribute("width"))
138
140
  return;
139
- const t = P(n, r);
141
+ const t = P(c, r);
140
142
  if (!t)
141
143
  return;
142
- const i = t.getAttribute("width"), a = parseFloat(i), u = b(t.getAttribute("style") || "", "padding", 0) * 2, p = Math.floor(s * a / 100), l = Math.max(1, p - u);
143
- n.setAttribute("width", String(l));
144
- const d = n.getAttribute("style") || "";
144
+ const n = t.getAttribute("width"), a = parseFloat(n), u = b(t.getAttribute("style") || "", "padding", 0) * 2, p = Math.floor(s * a / 100), l = Math.max(1, p - u);
145
+ c.setAttribute("width", String(l));
146
+ const d = c.getAttribute("style") || "";
145
147
  if (!/\bwidth\s*:\s*\d/i.test(d)) {
146
148
  const m = d && !d.trim().endsWith(";") ? "; " : "";
147
- n.setAttribute("style", `${d}${m}width: ${l}px`);
149
+ c.setAttribute("style", `${d}${m}width: ${l}px`);
148
150
  }
149
151
  });
150
152
  }
151
- function v(r, c) {
153
+ function v(r, i) {
152
154
  const e = r.match(/<!DOCTYPE[^>]*>/i);
153
155
  return (e ? `${e[0]}
154
- ` : "") + c.documentElement.outerHTML;
156
+ ` : "") + i.documentElement.outerHTML;
155
157
  }
156
158
  function N(r) {
157
- const c = r.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), e = new DOMParser().parseFromString(c, "text/html"), o = e.querySelectorAll(".recommendation-block-v2");
159
+ const i = r.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), e = new DOMParser().parseFromString(i, "text/html"), o = e.querySelectorAll(".recommendation-block-v2");
158
160
  if (!o.length)
159
161
  return r;
160
- const { buildCampaignUrl: s } = g(), n = q();
161
- n.recommendationCampaignUrls = {};
162
- const { isFeatureEnabled: t } = S(), i = t("liquidSyntax") ? "reco_" : "";
162
+ const { buildCampaignUrl: s } = g(), c = q();
163
+ c.recommendationCampaignUrls = {};
164
+ const { isFeatureEnabled: t } = S(), n = t("liquidSyntax") ? "reco_" : "";
163
165
  return o.forEach((u) => {
164
166
  var l, d;
165
167
  const p = u.getAttribute("recommendation-id");
166
- p && ((l = u.parentNode) == null || l.insertBefore(e.createComment("REC_START"), u), (d = u.parentNode) == null || d.insertBefore(e.createComment("REC_END"), u.nextSibling), u.querySelectorAll('[data-visibility="0"]').forEach((m) => m.remove()), s(p), R(u, p, i), T(u));
167
- }), v(c, e).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
168
+ p && ((l = u.parentNode) == null || l.insertBefore(e.createComment("REC_START"), u), (d = u.parentNode) == null || d.insertBefore(e.createComment("REC_END"), u.nextSibling), u.querySelectorAll('[data-visibility="0"]').forEach((m) => m.remove()), s(p), R(u, p, n), T(u));
169
+ }), v(i, e).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
168
170
  }
169
171
  export {
170
172
  y as formatPriceVariable,
@@ -155,6 +155,8 @@ class z {
155
155
  }
156
156
  migrate(t) {
157
157
  try {
158
+ if (!this.containsItemsBlock(t))
159
+ return t;
158
160
  let o = this.removeJinjaConditionals(t);
159
161
  o = this.replaceTemplateVariables(o);
160
162
  const l = this.parser.parseFromString(o, "text/html"), a = l.querySelectorAll(
@@ -178,15 +180,15 @@ class z {
178
180
  originalPriceStyles: e.originalPriceStyles,
179
181
  quantityStyles: e.quantityStyles,
180
182
  nodeConfig: R(e.configBlockAttributes)
181
- }), d = this.parser.parseFromString(
183
+ }), u = this.parser.parseFromString(
182
184
  `<table><tbody><tr>${c}</tr></tbody></table>`,
183
185
  "text/html"
184
186
  ).querySelector("td");
185
- if (d && i.parentNode) {
187
+ if (u && i.parentNode) {
186
188
  const p = R(e.configBlockAttributes);
187
- d.setAttribute("esd-ext-config", JSON.stringify(p));
188
- const u = d.querySelector("esd-config-block");
189
- u && u.remove(), i.parentNode.replaceChild(d, i);
189
+ u.setAttribute("esd-ext-config", JSON.stringify(p));
190
+ const d = u.querySelector("esd-config-block");
191
+ d && d.remove(), i.parentNode.replaceChild(u, i);
190
192
  }
191
193
  }), l.documentElement.outerHTML);
192
194
  } catch (o) {
@@ -201,22 +203,22 @@ class z {
201
203
  */
202
204
  extractConfiguration(t) {
203
205
  var C, D, P;
204
- const o = ((C = t.querySelector("[data-type]")) == null ? void 0 : C.getAttribute("data-type")) || "CART_ITEMS", l = ((D = t.querySelector("[data-number]")) == null ? void 0 : D.getAttribute("data-number")) || "1", a = parseInt(l) - 1, n = T[o], i = ((P = n == null ? void 0 : n[a]) == null ? void 0 : P.value) || n[0].value, e = t.querySelector('[product-attr="price"]'), c = (e == null ? void 0 : e.getAttribute("data-currency_symbol")) || "USD", d = ((e == null ? void 0 : e.getAttribute("data-curency")) || "before") === "after" ? "1" : "0", p = (e == null ? void 0 : e.getAttribute("data-formated")) !== "false", u = this.extractConfigBlockAttributes(t, o, l), S = u["data-card_orientation_control_value"];
206
+ const o = ((C = t.querySelector("[data-type]")) == null ? void 0 : C.getAttribute("data-type")) || "CART_ITEMS", l = ((D = t.querySelector("[data-number]")) == null ? void 0 : D.getAttribute("data-number")) || "1", a = parseInt(l) - 1, n = T[o], i = ((P = n == null ? void 0 : n[a]) == null ? void 0 : P.value) || n[0].value, e = t.querySelector('[product-attr="price"]'), c = (e == null ? void 0 : e.getAttribute("data-currency_symbol")) || "USD", u = ((e == null ? void 0 : e.getAttribute("data-curency")) || "before") === "after" ? "1" : "0", p = (e == null ? void 0 : e.getAttribute("data-formated")) !== "false", d = this.extractConfigBlockAttributes(t, o, l), S = d["data-card_orientation_control_value"];
205
207
  let b;
206
208
  S ? b = S === "horizontal" ? "horizontal" : "vertical" : b = t.querySelector('[colspan="2"]') !== null ? "vertical" : "horizontal";
207
- const y = t.querySelector('a[product-attr="name"]'), I = (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, h = (e == null ? void 0 : e.getAttribute("style")) || void 0, A = t.querySelector("p.original-price"), k = (A == null ? void 0 : A.getAttribute("style")) || void 0, E = t.querySelector('[product-attr="quantity"]'), L = (E == null ? void 0 : E.getAttribute("style")) || void 0;
209
+ const y = t.querySelector('a[product-attr="name"]'), I = (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, k = (e == null ? void 0 : e.getAttribute("style")) || void 0, A = t.querySelector("p.original-price"), h = (A == null ? void 0 : A.getAttribute("style")) || void 0, E = t.querySelector('[product-attr="quantity"]'), L = (E == null ? void 0 : E.getAttribute("style")) || void 0;
208
210
  return {
209
211
  orientation: b,
210
212
  itemsType: o,
211
213
  itemId: i,
212
214
  currencySymbol: c,
213
- currencyLocation: d,
215
+ currencyLocation: u,
214
216
  formattedPrice: p,
215
- configBlockAttributes: u,
217
+ configBlockAttributes: d,
216
218
  nameStyles: I,
217
219
  buttonStyles: m,
218
- priceStyles: h,
219
- originalPriceStyles: k,
220
+ priceStyles: k,
221
+ originalPriceStyles: h,
220
222
  quantityStyles: L
221
223
  };
222
224
  }
@@ -296,6 +298,14 @@ class z {
296
298
  "data-product_button_link": "{{Abandoned Cart Item (1) Url}}"
297
299
  };
298
300
  }
301
+ /**
302
+ * Fast check for the presence of any items block (cart / browsed / purchased)
303
+ * in the raw HTML. Used to gate the migration pipeline so non-items templates
304
+ * are returned untouched.
305
+ */
306
+ containsItemsBlock(t) {
307
+ return t.includes("esd-cart-items-block") || t.includes("esd-browsed-items-block") || t.includes("esd-purchased-items-block");
308
+ }
299
309
  /**
300
310
  * Removes Jinja2 conditional statements from HTML
301
311
  * Handles all items block types:
@@ -337,18 +347,18 @@ class z {
337
347
  const [, i, e, c] = n, _ = x[i];
338
348
  if (!_)
339
349
  return console.warn(`Unknown variable prefix: ${i}`), l;
340
- const d = q[e];
341
- if (!d)
350
+ const u = q[e];
351
+ if (!u)
342
352
  return console.warn(`Unknown variable suffix mapping for: ${e}`), l;
343
- const { pairsKey: p, defaultKey: u, isArray: S } = d, y = o[p][_];
353
+ const { pairsKey: p, defaultKey: d, isArray: S } = u, y = o[p][_];
344
354
  if (!y)
345
355
  return console.warn(`No data found for: ${p}.${_}`), l;
346
356
  if (S) {
347
- const f = parseInt(c) - 1, m = y[u];
348
- return Array.isArray(m) && m[f] ? m[f] : (console.warn(`Array value not found: ${p}.${_}.${u}[${f}]`), l);
357
+ const f = parseInt(c) - 1, m = y[d];
358
+ return Array.isArray(m) && m[f] ? m[f] : (console.warn(`Array value not found: ${p}.${_}.${d}[${f}]`), l);
349
359
  }
350
- const I = y[u];
351
- return I !== void 0 ? String(I) : (console.warn(`Default value not found: ${p}.${_}.${u}`), l);
360
+ const I = y[d];
361
+ return I !== void 0 ? String(I) : (console.warn(`Default value not found: ${p}.${_}.${d}`), l);
352
362
  });
353
363
  }
354
364
  }
@@ -1,27 +1,27 @@
1
- var k = Object.defineProperty;
2
- var B = (r, n, t) => n in r ? k(r, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[n] = t;
3
- var g = (r, n, t) => B(r, typeof n != "symbol" ? n + "" : n, t);
4
- import { BlockId as _ } from "../../../enums/block.js";
1
+ var B = Object.defineProperty;
2
+ var C = (a, s, t) => s in a ? B(a, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[s] = t;
3
+ var p = (a, s, t) => C(a, typeof s != "symbol" ? s + "" : s, t);
4
+ import { BlockId as R } from "../../../enums/block.js";
5
5
  import { getMigrationBannerHtml as b } from "../../../utils/migrationBannerHtml.js";
6
- import { Block as R, BlockCompositionType as y, ModificationDescription as C } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
7
- import { regenerateMobileProductRows as A } from "./controls/main/utils.js";
8
- import { ensureMobileCssRulesExist as d, setMobileLayoutOptOut as p, hasMobileLayoutOptOut as D } from "./controls/mobileLayout/cssRules.js";
9
- import { RecommendationConfigService as s } from "./services/configService.js";
10
- import { useRecommendationExtensionStore as f } from "./store/recommendation.js";
11
- import { getDefaultTemplate as E } from "./templates/grid/template.js";
12
- const h = _.Recommendation, l = "recommendation-block-v2", m = "recommendation-id";
13
- let I = !1;
14
- class q extends R {
6
+ import { Block as A, BlockCompositionType as y, ModificationDescription as f } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
7
+ import { regenerateMobileProductRows as D } from "./controls/main/utils.js";
8
+ import { ensureMobileCssRulesExist as h, setMobileLayoutOptOut as I, hasMobileLayoutOptOut as E } from "./controls/mobileLayout/cssRules.js";
9
+ import { RecommendationConfigService as c } from "./services/configService.js";
10
+ import { useRecommendationExtensionStore as g } from "./store/recommendation.js";
11
+ import { getDefaultTemplate as N } from "./templates/grid/template.js";
12
+ const k = R.Recommendation, m = "recommendation-block-v2", u = "recommendation-id";
13
+ let _ = !1;
14
+ class q extends A {
15
15
  constructor() {
16
16
  super();
17
17
  /**
18
18
  * Stores the ID generated in getTemplate() so onCreated() can reuse it.
19
19
  * This avoids generating a new (different) ID in onCreated().
20
20
  */
21
- g(this, "_pendingBlockId", null);
21
+ p(this, "_pendingBlockId", null);
22
22
  }
23
23
  getId() {
24
- return h;
24
+ return k;
25
25
  }
26
26
  getIcon() {
27
27
  return "recommendation-icon";
@@ -39,7 +39,7 @@ class q extends R {
39
39
  }
40
40
  getSettingsPanelTitleHtml() {
41
41
  return b(
42
- h,
42
+ k,
43
43
  this.api.translate("Recommendation Block"),
44
44
  this.api.translate("This block is switched from the Old Version to the New Version. We recommend you check the Recommendation block and test your message to ensure it works properly.")
45
45
  );
@@ -59,7 +59,7 @@ class q extends R {
59
59
  */
60
60
  getTemplate() {
61
61
  const t = this._generateNextId();
62
- return this._pendingBlockId = t, E(t);
62
+ return this._pendingBlockId = t, N(t);
63
63
  }
64
64
  /**
65
65
  * Called when a new block is dropped into the template
@@ -70,24 +70,26 @@ class q extends R {
70
70
  */
71
71
  onCreated(t) {
72
72
  const e = this._getRecommendationId(t);
73
- if (e !== null && e > 0)
73
+ if (e !== null && e > 0) {
74
+ this._detectDuplicate(e) && this._handleDuplicate(t, e);
74
75
  return;
76
+ }
75
77
  const i = this._pendingBlockId ?? this._generateNextId();
76
78
  this._pendingBlockId = null, this._assignRecommendationId(t, i);
77
- const { config: o, wasFreshDrop: c } = s.initializeConfig(
79
+ const { config: n, wasFreshDrop: o } = c.initializeConfig(
78
80
  this.api,
79
81
  t,
80
82
  { recommendationId: i }
81
- ), a = f();
82
- if (a.setCurrentBlock(i), c) {
83
- d(this.api);
84
- const u = this._getBlockElement(t);
85
- u && (p(this.api, u, !0), A({
83
+ ), r = g();
84
+ if (r.setCurrentBlock(i), o) {
85
+ h(this.api);
86
+ const l = this._getBlockElement(t);
87
+ l && (I(this.api, l, !0), D({
86
88
  currentNode: t,
87
89
  documentModifier: this.api.getDocumentModifier()
88
90
  }));
89
91
  }
90
- a.patchCurrentBlockConfig({ language: o.language }, { triggerRefetch: !1 });
92
+ r.patchCurrentBlockConfig({ language: n.language }, { triggerRefetch: !1 });
91
93
  }
92
94
  /**
93
95
  * Called when the document changes or template is loaded
@@ -100,20 +102,20 @@ class q extends R {
100
102
  if (!(!t || !("getNodeConfig" in t))) {
101
103
  if (!this._getRecommendationId(t)) {
102
104
  const e = this._generateNextId();
103
- this._assignRecommendationId(t, e), s.hasConfig(t) && s.updateConfig(
105
+ this._assignRecommendationId(t, e), c.hasConfig(t) && c.updateConfig(
104
106
  this.api,
105
107
  t,
106
108
  { recommendationId: e },
107
109
  "Assign recommendation ID to legacy block"
108
110
  );
109
111
  }
110
- s.needsMigration(t) && this._migrateFromLegacy(t);
112
+ c.needsMigration(t) && this._migrateFromLegacy(t);
111
113
  try {
112
- I || (d(this.api), I = !0);
113
- const e = s.getConfig(t), i = this._getBlockElement(t);
114
+ _ || (h(this.api), _ = !0);
115
+ const e = c.getConfig(t), i = this._getBlockElement(t);
114
116
  if (i) {
115
- const o = !e.mobileLayoutEnabled;
116
- D(i) !== o && p(this.api, i, o);
117
+ const n = !e.mobileLayoutEnabled;
118
+ E(i) !== n && I(this.api, i, n);
117
119
  }
118
120
  } catch {
119
121
  }
@@ -127,7 +129,7 @@ class q extends R {
127
129
  */
128
130
  onDelete(t) {
129
131
  const e = this._getRecommendationId(t);
130
- e && f().removeBlockState(e);
132
+ e && g().removeBlockState(e);
131
133
  }
132
134
  /**
133
135
  * Generates the next unique recommendation ID by scanning all existing blocks
@@ -137,16 +139,59 @@ class q extends R {
137
139
  let t = 0;
138
140
  try {
139
141
  const e = this.api.getDocumentRoot();
140
- e && "querySelectorAll" in e && e.querySelectorAll(`.${l}`).forEach((o) => {
141
- if ("getAttribute" in o) {
142
- const c = o.getAttribute(m), a = c ? parseInt(c) : 0;
143
- a > t && (t = a);
142
+ e && "querySelectorAll" in e && e.querySelectorAll(`.${m}`).forEach((n) => {
143
+ if ("getAttribute" in n) {
144
+ const o = n.getAttribute(u), r = o ? parseInt(o) : 0;
145
+ r > t && (t = r);
144
146
  }
145
147
  });
146
148
  } catch {
147
149
  }
148
150
  return t + 1;
149
151
  }
152
+ /** True when another block already holds the same id — Stripo's duplication signal. */
153
+ _detectDuplicate(t) {
154
+ try {
155
+ const e = this.api.getDocumentRoot();
156
+ if (e && "querySelectorAll" in e)
157
+ return e.querySelectorAll(
158
+ `.${m}[${u}="${t}"]`
159
+ ).length > 1;
160
+ } catch {
161
+ }
162
+ return !1;
163
+ }
164
+ /** Assigns a fresh id to a duplicated block and syncs DOM, node config and store. */
165
+ _handleDuplicate(t, e) {
166
+ const i = this._generateNextId(), n = this._getBlockElement(t);
167
+ this._assignRecommendationId(t, i), n && this._reassignInstanceClass(n, e, i), c.hasConfig(t) && c.updateConfig(
168
+ this.api,
169
+ t,
170
+ { recommendationId: i },
171
+ `Reassign recommendation ID on duplicate (was ${e})`
172
+ );
173
+ const o = g();
174
+ o.cloneBlockState(e, i), o.setCurrentBlock(i);
175
+ }
176
+ /**
177
+ * Rewrites `ins-recommendation-v3-block-{id}` on the clone — the instance
178
+ * class scopes per-block CSS rules, so leaving the source's class would
179
+ * make stylistic edits leak between source and clone.
180
+ */
181
+ _reassignInstanceClass(t, e, i) {
182
+ if (!("getAttribute" in t))
183
+ return;
184
+ const n = t.getAttribute("class");
185
+ if (!n)
186
+ return;
187
+ const o = `ins-recommendation-v3-block-${e}`, r = `ins-recommendation-v3-block-${i}`;
188
+ if (!n.includes(o))
189
+ return;
190
+ const l = n.replace(o, r), d = this.api.getDocumentModifier();
191
+ d.modifyHtml(t).setAttribute("class", l), d.apply(new f(
192
+ `Reassign recommendation instance class ${o} -> ${r}`
193
+ ));
194
+ }
150
195
  /**
151
196
  * Assigns a recommendation-id attribute to the block element.
152
197
  * The instance class (ins-recommendation-v3-block-{id}) is embedded in the template
@@ -157,8 +202,8 @@ class q extends R {
157
202
  const i = this._getBlockElement(t);
158
203
  if (!i)
159
204
  return;
160
- const o = this.api.getDocumentModifier();
161
- o.modifyHtml(i).setAttribute(m, e.toString()), o.apply(new C(`Assign recommendation ID ${e}`));
205
+ const n = this.api.getDocumentModifier();
206
+ n.modifyHtml(i).setAttribute(u, e.toString()), n.apply(new f(`Assign recommendation ID ${e}`));
162
207
  }
163
208
  /**
164
209
  * Gets the recommendation-id from a block node
@@ -167,11 +212,11 @@ class q extends R {
167
212
  const e = this._getBlockElement(t);
168
213
  if (!e || !("getAttribute" in e))
169
214
  return null;
170
- const i = e.getAttribute(m);
215
+ const i = e.getAttribute(u);
171
216
  if (!i)
172
217
  return null;
173
- const o = parseInt(i);
174
- return Number.isNaN(o) ? null : o;
218
+ const n = parseInt(i);
219
+ return Number.isNaN(n) ? null : n;
175
220
  }
176
221
  /**
177
222
  * Gets the block element (the element with BLOCK_CLASS)
@@ -179,19 +224,19 @@ class q extends R {
179
224
  _getBlockElement(t) {
180
225
  if ("getAttribute" in t) {
181
226
  const e = t.getAttribute("class");
182
- if (e && e.includes(l))
227
+ if (e && e.includes(m))
183
228
  return t;
184
229
  }
185
- return "querySelector" in t ? t.querySelector(`.${l}`) ?? null : null;
230
+ return "querySelector" in t ? t.querySelector(`.${m}`) ?? null : null;
186
231
  }
187
232
  /**
188
233
  * Migrate configuration from legacy format
189
234
  */
190
235
  _migrateFromLegacy(t) {
191
- s.migrateFromDataAttributes(this.api, t);
236
+ c.migrateFromDataAttributes(this.api, t);
192
237
  }
193
238
  }
194
239
  export {
195
- h as BLOCK_ID,
240
+ k as BLOCK_ID,
196
241
  q as RecommendationBlock
197
242
  };