@useinsider/guido 3.17.0-beta.77567eb → 3.17.0-beta.a51375c

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.
@@ -16,6 +16,8 @@ export declare const BLOCK_ID: BlockId;
16
16
  * - Onboarding support
17
17
  */
18
18
  export declare class ItemsBlock extends Block {
19
+ /** Block instances whose currency attrs were already self-healed this session (SD-147588 — undo-safe). */
20
+ private _currencyHealed;
19
21
  getId(): string;
20
22
  getIcon(): string;
21
23
  getBlockCompositionType(): BlockCompositionType;
@@ -42,4 +44,23 @@ export declare class ItemsBlock extends Block {
42
44
  * relies on this td-level fallback in pairProductVariables.
43
45
  */
44
46
  private _stampProductTdDomAttributes;
47
+ /**
48
+ * Whether the currency self-heal should run for this block. Two guards (SD-147588):
49
+ * 1. Config is only authoritative when the symbol was actually customized — a symbol still at
50
+ * the 'USD' sentinel may be a migrator default, so we trust the DOM's real value over a
51
+ * defaulted config and never overwrite it.
52
+ * 2. Heal each instance at most once per session, so the auto-fix can't fight undo (undo
53
+ * re-drifts the attr, which would otherwise re-trigger the heal forever).
54
+ */
55
+ private _shouldReconcileCurrency;
56
+ /** Marks a block instance's currency as reconciled so it is not healed again (undo-safe). */
57
+ private _markCurrencyHealed;
58
+ /**
59
+ * Stamps the export-read currency attrs onto every price `<p>` from config, so a template whose
60
+ * attrs drifted (e.g. a location toggle before the sync fix) self-heals to match the editor.
61
+ * Config is the source of truth — never derive from visible text. Callers gate this with
62
+ * `_shouldReconcileCurrency`. Returns true only when an attr actually changed, so the caller can
63
+ * skip an empty apply that would otherwise re-trigger onDocumentChanged and loop (SD-147588).
64
+ */
65
+ private _reconcileCurrencyDomAttributes;
45
66
  }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Single owner for the Items price currency export contract (SD-147588).
3
+ *
4
+ * `data-curency` is deliberately misspelled (one `r`) — it is the attribute the
5
+ * server-side export transform (pairProductVariables) actually reads, so every
6
+ * layer that writes it and the live reader (template, controls, block self-heal,
7
+ * pairProductVariables) MUST go through these constants. A typo fix or mapping change
8
+ * in one of them would otherwise silently break sync with the others and ship the wrong
9
+ * currency position/token to the inbox. Mirrors the Recommendation block's `CURRENCY_ATTR`.
10
+ *
11
+ * Exception: the legacy migrator reads the raw misspelled string on purpose — it parses
12
+ * old templates frozen with that exact attr name, so it must NOT follow a future rename here.
13
+ */
14
+ export declare const ITEMS_CURRENCY_ATTR: {
15
+ readonly POSITION: "data-curency";
16
+ readonly SYMBOL: "data-currency_symbol";
17
+ };
18
+ /** Currency location select value `'1'` = after (price then symbol), anything else = before. */
19
+ export declare function currencyPositionFromLocation(location: string | undefined): 'after' | 'before';
@@ -1,82 +1,83 @@
1
+ import { ITEMS_CURRENCY_ATTR as N } from "../extensions/Blocks/Items/constants/currency.js";
1
2
  import { productPairs as L } from "../extensions/Blocks/Items/enums/productEnums.js";
2
- import { DefaultConfigValues as V } from "../extensions/Blocks/Items/enums/settingsEnums.js";
3
- import { escapeReplacement as G } from "../extensions/Blocks/Items/utils/nodeConfigUtils.js";
3
+ import { DefaultConfigValues as G } from "../extensions/Blocks/Items/enums/settingsEnums.js";
4
+ import { escapeReplacement as X } from "../extensions/Blocks/Items/utils/nodeConfigUtils.js";
4
5
  import { preserveTextStyles as F } from "./preserveTextStyles.js";
5
- import { unwrapProductNameLinks as X } from "./unwrapProductNameLink.js";
6
+ import { unwrapProductNameLinks as Y } from "./unwrapProductNameLink.js";
6
7
  const x = {
7
8
  CART_ITEMS: "ins_apr",
8
9
  BROWSED_ITEMS: "browsed_item",
9
10
  PURCHASED_ITEMS: "purchased_item"
10
- }, N = (S) => S.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->");
11
- function v(S, H, g) {
12
- let $ = H;
13
- for (; $ > 0 && /\s/.test(S[$ - 1]); )
14
- $ -= 1;
15
- return g.some((I) => S.endsWith(I, $));
11
+ }, O = (S) => S.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->");
12
+ function v(S, I, b) {
13
+ let h = I;
14
+ for (; h > 0 && /\s/.test(S[h - 1]); )
15
+ h -= 1;
16
+ return b.some((P) => S.endsWith(P, h));
16
17
  }
17
- function J(S) {
18
- const H = N(S), g = new DOMParser().parseFromString(H, "text/html");
19
- X(g);
20
- const $ = L.PAIRS_FOR_EXTENSION;
21
- Object.entries($).forEach(([n, d]) => {
22
- g.querySelectorAll(".ins-product-td").forEach((r) => {
18
+ function Z(S) {
19
+ const I = O(S), b = new DOMParser().parseFromString(I, "text/html");
20
+ Y(b);
21
+ const h = L.PAIRS_FOR_EXTENSION;
22
+ Object.entries(h).forEach(([n, d]) => {
23
+ b.querySelectorAll(".ins-product-td").forEach((r) => {
23
24
  const E = r.getAttribute("data-number") || "1", m = r.getAttribute("data-type") || "CART_ITEMS";
24
25
  r.querySelectorAll(`[product-attr="${n}"]`).forEach((t) => {
25
- var T, P, D;
26
- const R = t.getAttribute("data-type") || m, o = t.getAttribute("data-number") || E, f = d[R];
27
- if (f)
26
+ var $, H, D;
27
+ const g = t.getAttribute("data-type") || m, o = t.getAttribute("data-number") || E, u = d[g];
28
+ if (u)
28
29
  switch (n) {
29
30
  case "imageSrc": {
30
31
  let e = null, s = null;
31
32
  if (t.tagName === "IMG" ? (e = t, s = e.closest("a")) : (e = t.querySelector("img"), s = t.querySelector("a") || t.closest("a")), !e)
32
33
  break;
33
- const a = f.DEFAULT, l = f.ATTR;
34
+ const a = u.DEFAULT, l = u.ATTR;
34
35
  if (a && e.src) {
35
36
  const i = e.src;
36
- a.some((b) => {
37
- const u = b.split("/").pop() || "", y = i.split("/").pop() || "";
38
- return i.includes(b) || i.includes(u) || y === u;
37
+ a.some((_) => {
38
+ const f = _.split("/").pop() || "", C = i.split("/").pop() || "";
39
+ return i.includes(_) || i.includes(f) || C === f;
39
40
  }) && (e.src = `{{${l}_${o}}}`);
40
41
  }
41
- const c = (P = (T = $.name) == null ? void 0 : T[R]) == null ? void 0 : P.ATTR;
42
+ const c = (H = ($ = h.name) == null ? void 0 : $[g]) == null ? void 0 : H.ATTR;
42
43
  if (c && e.setAttribute("alt", `{{${c}_${o}}}`), s) {
43
- const i = (D = $.itemLink) == null ? void 0 : D[R];
44
+ const i = (D = h.itemLink) == null ? void 0 : D[g];
44
45
  if (i) {
45
- const _ = i.HREF, b = i.DEFAULT_HREF || "#!", u = s.href;
46
- (u === "#" || u === "" || u.endsWith("#!") || u.endsWith(b) || u === `${window.location.href}${b}` || !u || u === window.location.href) && (s.href = `{{${_}_${o}}}`);
46
+ const R = i.HREF, _ = i.DEFAULT_HREF || "#!", f = s.href;
47
+ (f === "#" || f === "" || f.endsWith("#!") || f.endsWith(_) || f === `${window.location.href}${_}` || !f || f === window.location.href) && (s.href = `{{${R}_${o}}}`);
47
48
  }
48
49
  }
49
50
  break;
50
51
  }
51
52
  case "name": {
52
- const e = f, s = e.ATTR, a = e.DEFAULT_HREF || "#!", l = e.HREF;
53
+ const e = u, s = e.ATTR, a = e.DEFAULT_HREF || "#!", l = e.HREF;
53
54
  t.textContent && (t.innerHTML = F(t, `{{${s}_${o}}}`));
54
55
  const c = t.closest("a") || (t.tagName === "A" ? t : null);
55
56
  if (c && l) {
56
- const i = c.href, _ = `${window.location.href}${a}`;
57
- (i === _ || i.endsWith(a)) && (c.href = `{{${l}_${o}}}`);
57
+ const i = c.href, R = `${window.location.href}${a}`;
58
+ (i === R || i.endsWith(a)) && (c.href = `{{${l}_${o}}}`);
58
59
  }
59
60
  break;
60
61
  }
61
62
  case "price":
62
63
  case "originalPrice": {
63
- const e = f, s = t.getAttribute("data-formated"), a = t.getAttribute("data-single_price"), l = s === "true", c = a === "true", i = t.getAttribute("data-curency") || "before";
64
- let _;
65
- c ? _ = l ? e.SINGLE_PRICE_FORMATTED : e.SINGLE_PRICE : _ = l ? e.PRICE_FORMATTED : e.PRICE;
66
- const b = e.CURRENCY;
67
- let u = `{{${_}_${o}}}`;
68
- const y = (t.getAttribute("data-currency_symbol") || "").trim(), W = y !== "" && y !== V.productPriceCurrencySymbolControlValue;
69
- let C = "";
70
- W ? C = y : b && (C = `{{${b}_${o}}}`), C && (u = i === "after" ? `${u} ${C}` : `${C} ${u}`), t.innerHTML = F(t, u);
64
+ const e = u, s = t.getAttribute("data-formated"), a = t.getAttribute("data-single_price"), l = s === "true", c = a === "true", i = t.getAttribute(N.POSITION) || "before";
65
+ let R;
66
+ c ? R = l ? e.SINGLE_PRICE_FORMATTED : e.SINGLE_PRICE : R = l ? e.PRICE_FORMATTED : e.PRICE;
67
+ const _ = e.CURRENCY;
68
+ let f = `{{${R}_${o}}}`;
69
+ const C = (t.getAttribute(N.SYMBOL) || "").trim(), V = C !== "" && C !== G.productPriceCurrencySymbolControlValue;
70
+ let y = "";
71
+ V ? y = C : _ && (y = `{{${_}_${o}}}`), y && (f = i === "after" ? `${f} ${y}` : `${y} ${f}`), t.innerHTML = F(t, f);
71
72
  break;
72
73
  }
73
74
  case "quantity": {
74
- const e = f, s = e.ATTR, a = e.DEFAULT;
75
+ const e = u, s = e.ATTR, a = e.DEFAULT;
75
76
  t.textContent && t.textContent.trim() === a && (t.innerHTML = F(t, `{{${s}_${o}}}`));
76
77
  break;
77
78
  }
78
79
  case "button": {
79
- const e = f, s = e.HREF, a = e.DEFAULT_HREF || "#!", l = t.tagName === "A" ? t : t.querySelector("a");
80
+ const e = u, s = e.HREF, a = e.DEFAULT_HREF || "#!", l = t.tagName === "A" ? t : t.querySelector("a");
80
81
  if (l) {
81
82
  const c = l.href || "", i = `${window.location.href}${a}`;
82
83
  (c === "" || c === "#" || c === i || c.endsWith(a) || c.endsWith("#!") || c === window.location.href) && (l.href = `{{${s}_${o}}}`);
@@ -84,7 +85,7 @@ function J(S) {
84
85
  break;
85
86
  }
86
87
  case "itemLink": {
87
- const e = f, s = e.HREF, a = e.DEFAULT_HREF || "#!", l = t;
88
+ const e = u, s = e.HREF, a = e.DEFAULT_HREF || "#!", l = t;
88
89
  if (l.href) {
89
90
  const c = l.href, i = `${window.location.href}${a}`;
90
91
  (c === i || c.endsWith(a)) && (l.href = `{{${s}_${o}}}`);
@@ -92,8 +93,8 @@ function J(S) {
92
93
  break;
93
94
  }
94
95
  default: {
95
- if ("ATTR" in f) {
96
- const e = f.ATTR;
96
+ if ("ATTR" in u) {
97
+ const e = u.ATTR;
97
98
  t.textContent && (t.innerHTML = F(t, `{{${e}_${o}}}`));
98
99
  }
99
100
  break;
@@ -102,9 +103,9 @@ function J(S) {
102
103
  });
103
104
  });
104
105
  });
105
- const I = H.match(/<!DOCTYPE[^>]*>/i), O = I ? `${I[0]}
106
- ` : "", q = g.querySelectorAll(".ins-product-td"), M = [];
107
- q.forEach((n) => {
106
+ const P = I.match(/<!DOCTYPE[^>]*>/i), q = P ? `${P[0]}
107
+ ` : "", U = b.querySelectorAll(".ins-product-td"), M = [];
108
+ U.forEach((n) => {
108
109
  const d = n.getAttribute("data-type") || "CART_ITEMS", p = n.getAttribute("data-number") || "1", r = n.outerHTML;
109
110
  M.push({
110
111
  element: n,
@@ -113,16 +114,16 @@ function J(S) {
113
114
  number: p
114
115
  });
115
116
  });
116
- let A = O + g.documentElement.outerHTML;
117
+ let A = q + b.documentElement.outerHTML;
117
118
  M.reverse().forEach(({ outerHtml: n, type: d, number: p }) => {
118
119
  const r = x[d], E = r ? `${r}_total_product_kind` : "";
119
120
  if (E) {
120
- const h = parseInt(p) - 1, o = `${`{% if ${E} > ${h} %}`}${n}{% endif %}`;
121
- A = A.replace(n, G(o));
121
+ const T = parseInt(p) - 1, o = `${`{% if ${E} > ${T} %}`}${n}{% endif %}`;
122
+ A = A.replace(n, X(o));
122
123
  }
123
124
  });
124
- const U = g.querySelectorAll('[product-attr="originalPrice"][data-type]'), w = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Set();
125
- return U.forEach((n) => {
125
+ const W = b.querySelectorAll('[product-attr="originalPrice"][data-type]'), w = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Set();
126
+ return W.forEach((n) => {
126
127
  var t;
127
128
  const d = n.getAttribute("data-number"), p = n.getAttribute("data-type");
128
129
  if (!d || !x[p])
@@ -131,20 +132,20 @@ function J(S) {
131
132
  if (!r || k.has(r))
132
133
  return;
133
134
  k.add(r);
134
- const E = r.outerHTML, m = (t = n.closest(".ins-product-td")) == null ? void 0 : t.getAttribute("data-nodup"), h = w.get(E) ?? { number: d, type: p, wrap: [] };
135
- h.wrap.push(m !== "false"), w.set(E, h);
135
+ const E = r.outerHTML, m = (t = n.closest(".ins-product-td")) == null ? void 0 : t.getAttribute("data-nodup"), T = w.get(E) ?? { number: d, type: p, wrap: [] };
136
+ T.wrap.push(m !== "false"), w.set(E, T);
136
137
  }), w.forEach(({ number: n, type: d, wrap: p }, r) => {
137
138
  if (r.includes("{% if") || !p.some(Boolean))
138
139
  return;
139
- const E = L.PAIRS_FOR_EXTENSION.price[d].PRICE, m = L.PAIRS_FOR_EXTENSION.originalPrice[d].PRICE, h = `{% if ${E}_${n} != ${m}_${n} %}`, t = [h, N(h)];
140
- let R = "", o = 0, f = 0, T = A.indexOf(r);
141
- for (; T !== -1; ) {
142
- const P = p[f] === !0 && !v(A, T, t);
143
- R += A.slice(o, T) + (P ? `${h}${r}{% endif %}` : r), o = T + r.length, f += 1, T = A.indexOf(r, o);
140
+ const E = L.PAIRS_FOR_EXTENSION.price[d].PRICE, m = L.PAIRS_FOR_EXTENSION.originalPrice[d].PRICE, T = `{% if ${E}_${n} != ${m}_${n} %}`, t = [T, O(T)];
141
+ let g = "", o = 0, u = 0, $ = A.indexOf(r);
142
+ for (; $ !== -1; ) {
143
+ const H = p[u] === !0 && !v(A, $, t);
144
+ g += A.slice(o, $) + (H ? `${T}${r}{% endif %}` : r), o = $ + r.length, u += 1, $ = A.indexOf(r, o);
144
145
  }
145
- A = R + A.slice(o);
146
+ A = g + A.slice(o);
146
147
  }), A.replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
147
148
  }
148
149
  export {
149
- J as pairProductVariables
150
+ Z as pairProductVariables
150
151
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.17.0-beta.77567eb",
3
+ "version": "3.17.0-beta.a51375c",
4
4
  "description": "Guido is a Vue + TypeScript wrapper for Email Plugin. Easily embed the email editor in your Vue applications.",
5
5
  "main": "./dist/guido.umd.cjs",
6
6
  "module": "./dist/library.js",
@@ -25,7 +25,7 @@
25
25
  "start": "vite",
26
26
  "build": "vite build && vue-tsc --declaration --emitDeclarationOnly --project tsconfig.app.json",
27
27
  "preview": "vite preview",
28
- "lint": "NODE_OPTIONS=--max-old-space-size=2048 eslint ./ && npm run type-check",
28
+ "lint": "NODE_OPTIONS=--max-old-space-size=2048 eslint ./ && bun run type-check",
29
29
  "lint:fix": "NODE_OPTIONS=--max-old-space-size=2048 eslint --fix ./",
30
30
  "lint:e2e-quality": "node scripts/lint-e2e-quality.mjs",
31
31
  "lint:e2e-quality:ci": "node scripts/lint-e2e-quality.mjs --ci",
@@ -117,7 +117,7 @@
117
117
  },
118
118
  "guido": {
119
119
  "stripo": {
120
- "version": "2.73.0"
120
+ "version": "2.72.1"
121
121
  }
122
122
  }
123
123
  }