@useinsider/guido 3.23.0-beta.9f6bfbf → 3.23.0-beta.a3a0b68

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 (47) hide show
  1. package/README.md +0 -1
  2. package/dist/@types/config/schemas.js +15 -17
  3. package/dist/components/Guido.vue.js +1 -1
  4. package/dist/components/Guido.vue2.js +56 -58
  5. package/dist/composables/useHtmlCompiler.js +2 -0
  6. package/dist/composables/useModuleRepair.js +12 -14
  7. package/dist/config/compiler/htmlCompilerRules.js +14 -6
  8. package/dist/config/migrator/index.js +15 -16
  9. package/dist/extensions/Blocks/Items/block.js +77 -115
  10. package/dist/extensions/Blocks/Items/constants/currency.js +14 -59
  11. package/dist/extensions/Blocks/Items/controls/price/currencyLocation.js +22 -33
  12. package/dist/extensions/Blocks/Items/controls/price/currencySymbol.js +51 -62
  13. package/dist/extensions/Blocks/Items/controls/price/formattedPrice.js +17 -18
  14. package/dist/extensions/Blocks/Items/controls/price/singlePrice.js +31 -42
  15. package/dist/extensions/Blocks/Items/controls/settingsControl.js +120 -141
  16. package/dist/extensions/Blocks/Items/enums/controlEnums.js +1 -1
  17. package/dist/extensions/Blocks/Items/extension.js +8 -9
  18. package/dist/extensions/Blocks/Items/items.css.js +0 -19
  19. package/dist/extensions/Blocks/Items/settingsPanel.js +25 -34
  20. package/dist/extensions/Blocks/Items/template.js +212 -250
  21. package/dist/extensions/Blocks/Recommendation/utils/priceFormatter.js +0 -1
  22. package/dist/guido.css +1 -1
  23. package/dist/package.json.js +2 -2
  24. package/dist/src/@types/config/schemas.d.ts +0 -4
  25. package/dist/src/composables/useConfig.d.ts +0 -2
  26. package/dist/src/config/migrator/index.d.ts +1 -4
  27. package/dist/src/extensions/Blocks/Items/block.d.ts +9 -6
  28. package/dist/src/extensions/Blocks/Items/constants/currency.d.ts +0 -32
  29. package/dist/src/extensions/Blocks/Items/controls/settingsControl.d.ts +0 -1
  30. package/dist/src/extensions/Blocks/Items/enums/controlEnums.d.ts +0 -1
  31. package/dist/src/extensions/Blocks/Items/template.d.ts +1 -4
  32. package/dist/src/extensions/Blocks/Items/utils/nodeConfigUtils.d.ts +0 -3
  33. package/dist/src/extensions/Blocks/Recommendation/utils/priceFormatter.d.ts +0 -12
  34. package/dist/src/stores/config.d.ts +0 -20
  35. package/dist/src/utils/itemsCurrencyRepair.d.ts +1 -5
  36. package/dist/src/utils/trimHrefWhitespace.d.ts +5 -0
  37. package/dist/static/stripo-runtime-manifest.json.js +1 -1
  38. package/dist/utils/itemsCurrencyRepair.js +24 -29
  39. package/dist/utils/pairProductVariables.js +99 -119
  40. package/dist/utils/trimHrefWhitespace.js +10 -0
  41. package/package.json +2 -2
  42. package/dist/config/migrator/itemsPriceFormatMigrator.js +0 -20
  43. package/dist/extensions/Blocks/Items/controls/priceFormat.js +0 -145
  44. package/dist/extensions/Blocks/Items/utils/priceFormatOps.js +0 -185
  45. package/dist/src/config/migrator/itemsPriceFormatMigrator.d.ts +0 -1
  46. package/dist/src/extensions/Blocks/Items/controls/priceFormat.d.ts +0 -23
  47. package/dist/src/extensions/Blocks/Items/utils/priceFormatOps.d.ts +0 -61
@@ -1,128 +1,108 @@
1
- import { isNewPriceFormatRoot as G, ITEMS_PRICE_FORMAT_ATTR as N, currencyPositionFromLocation as Y, ITEMS_CURRENCY_ATTR as U, isCustomCurrencySymbol as B } from "../extensions/Blocks/Items/constants/currency.js";
2
- import { productPairs as k } from "../extensions/Blocks/Items/enums/productEnums.js";
3
- import { escapeReplacement as v } from "../extensions/Blocks/Items/utils/nodeConfigUtils.js";
4
- import { preserveTextStyles as w } from "./preserveTextStyles.js";
1
+ import { ITEMS_CURRENCY_ATTR as U, isCustomCurrencySymbol as Y } from "../extensions/Blocks/Items/constants/currency.js";
2
+ import { productPairs as M } from "../extensions/Blocks/Items/enums/productEnums.js";
3
+ import { escapeReplacement as B } from "../extensions/Blocks/Items/utils/nodeConfigUtils.js";
4
+ import { preserveTextStyles as L } from "./preserveTextStyles.js";
5
5
  import { unwrapProductNameLinks as X } from "./unwrapProductNameLink.js";
6
6
  const q = {
7
7
  CART_ITEMS: "ins_apr",
8
8
  BROWSED_ITEMS: "browsed_item",
9
9
  PURCHASED_ITEMS: "purchased_item"
10
- }, W = (r) => r.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->");
11
- function j(r, h, p) {
12
- let u = h;
13
- for (; u > 0 && /\s/.test(r[u - 1]); )
14
- u -= 1;
15
- return p.some((A) => r.endsWith(A, u));
10
+ }, W = ($) => $.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->");
11
+ function v($, C, A) {
12
+ let d = C;
13
+ for (; d > 0 && /\s/.test($[d - 1]); )
14
+ d -= 1;
15
+ return A.some((E) => $.endsWith(E, d));
16
16
  }
17
- const Q = /(\s)href=(["'])(?:[^"']*#!|#)?\2/gi;
18
- function z(r, h) {
19
- var u;
20
- const p = r.ownerDocument.createTreeWalker(r, NodeFilter.SHOW_COMMENT);
21
- for (let A = p.nextNode(); A; A = p.nextNode())
22
- (u = A.nodeValue) != null && u.includes("[if mso]") && (A.nodeValue = A.nodeValue.replace(Q, (L, P) => `${P}href="${h}"`));
17
+ const j = /(\s)href=(["'])(?:[^"']*#!|#)?\2/gi;
18
+ function Q($, C) {
19
+ var d;
20
+ const A = $.ownerDocument.createTreeWalker($, NodeFilter.SHOW_COMMENT);
21
+ for (let E = A.nextNode(); E; E = A.nextNode())
22
+ (d = E.nodeValue) != null && d.includes("[if mso]") && (E.nodeValue = E.nodeValue.replace(j, (k, P) => `${P}href="${C}"`));
23
23
  }
24
- function J(r) {
25
- return {
26
- isFormatted: r.getAttribute("data-formated") === "true",
27
- isSinglePrice: r.getAttribute("data-single_price") === "true",
28
- currencyPosition: r.getAttribute(U.POSITION) || "before",
29
- configuredSymbol: (r.getAttribute(U.SYMBOL) || "").trim()
30
- };
31
- }
32
- function K(r) {
33
- return {
34
- isFormatted: !1,
35
- isSinglePrice: r.getAttribute(N.SINGLE_PRICE) === "true",
36
- currencyPosition: Y(
37
- r.getAttribute(N.ALIGNMENT) ?? void 0
38
- ),
39
- configuredSymbol: (r.getAttribute(N.SYMBOL) || "").trim()
40
- };
41
- }
42
- function Z(r, h, p) {
43
- const { isFormatted: u, isSinglePrice: A, currencyPosition: L, configuredSymbol: P } = p;
44
- let y;
45
- A ? y = u ? r.SINGLE_PRICE_FORMATTED : r.SINGLE_PRICE : y = u ? r.PRICE_FORMATTED : r.PRICE;
46
- const E = r.CURRENCY;
47
- let F = `{{${y}_${h}}}`, R = "";
48
- return B(P) ? R = P : E && (R = `{{${E}_${h}}}`), R && (F = L === "after" ? `${F} ${R}` : `${R} ${F}`), F;
49
- }
50
- function ct(r) {
51
- const h = W(r), p = new DOMParser().parseFromString(h, "text/html");
52
- X(p);
53
- const u = k.PAIRS_FOR_EXTENSION;
54
- Object.entries(u).forEach(([o, T]) => {
55
- p.querySelectorAll(".ins-product-td").forEach((n) => {
56
- const S = n.getAttribute("data-number") || "1", I = n.getAttribute("data-type") || "CART_ITEMS";
57
- n.querySelectorAll(`[product-attr="${o}"]`).forEach((t) => {
58
- var b, M, D, x;
59
- const m = t.getAttribute("data-type") || I, c = t.getAttribute("data-number") || S, f = T[m];
24
+ function et($) {
25
+ const C = W($), A = new DOMParser().parseFromString(C, "text/html");
26
+ X(A);
27
+ const d = M.PAIRS_FOR_EXTENSION;
28
+ Object.entries(d).forEach(([o, p]) => {
29
+ A.querySelectorAll(".ins-product-td").forEach((r) => {
30
+ const _ = r.getAttribute("data-number") || "1", y = r.getAttribute("data-type") || "CART_ITEMS";
31
+ r.querySelectorAll(`[product-attr="${o}"]`).forEach((t) => {
32
+ var S, I, O, x;
33
+ const m = t.getAttribute("data-type") || y, n = t.getAttribute("data-number") || _, f = p[m];
60
34
  if (f)
61
35
  switch (o) {
62
36
  case "imageSrc": {
63
- let e = null, i = null;
64
- if (t.tagName === "IMG" ? (e = t, i = e.closest("a")) : (e = t.querySelector("img"), i = t.querySelector("a") || t.closest("a")), !e)
37
+ let e = null, s = null;
38
+ if (t.tagName === "IMG" ? (e = t, s = e.closest("a")) : (e = t.querySelector("img"), s = t.querySelector("a") || t.closest("a")), !e)
65
39
  break;
66
- const d = f.DEFAULT, a = f.ATTR;
67
- if (d && e.src) {
68
- const l = e.src;
69
- d.some((C) => {
70
- const $ = C.split("/").pop() || "", V = l.split("/").pop() || "";
71
- return l.includes(C) || l.includes($) || V === $;
72
- }) && (e.src = `{{${a}_${c}}}`);
40
+ const l = f.DEFAULT, c = f.ATTR;
41
+ if (l && e.src) {
42
+ const a = e.src;
43
+ l.some((g) => {
44
+ const u = g.split("/").pop() || "", H = a.split("/").pop() || "";
45
+ return a.includes(g) || a.includes(u) || H === u;
46
+ }) && (e.src = `{{${c}_${n}}}`);
73
47
  }
74
- const s = (M = (b = u.name) == null ? void 0 : b[m]) == null ? void 0 : M.ATTR;
75
- if (s && e.setAttribute("alt", `{{${s}_${c}}}`), i) {
76
- const l = (D = u.itemLink) == null ? void 0 : D[m];
77
- if (l) {
78
- const H = l.HREF, C = l.DEFAULT_HREF || "#!", $ = i.href;
79
- ($ === "#" || $ === "" || $.endsWith("#!") || $.endsWith(C) || $ === `${window.location.href}${C}` || !$ || $ === window.location.href) && (i.href = `{{${H}_${c}}}`);
48
+ const i = (I = (S = d.name) == null ? void 0 : S[m]) == null ? void 0 : I.ATTR;
49
+ if (i && e.setAttribute("alt", `{{${i}_${n}}}`), s) {
50
+ const a = (O = d.itemLink) == null ? void 0 : O[m];
51
+ if (a) {
52
+ const b = a.HREF, g = a.DEFAULT_HREF || "#!", u = s.href;
53
+ (u === "#" || u === "" || u.endsWith("#!") || u.endsWith(g) || u === `${window.location.href}${g}` || !u || u === window.location.href) && (s.href = `{{${b}_${n}}}`);
80
54
  }
81
55
  }
82
56
  break;
83
57
  }
84
58
  case "name": {
85
- const e = f, i = e.ATTR, d = e.DEFAULT_HREF || "#!", a = e.HREF;
86
- t.textContent && (t.innerHTML = w(t, `{{${i}_${c}}}`));
87
- const s = t.closest("a") || (t.tagName === "A" ? t : null);
88
- if (s && a) {
89
- const l = s.href, H = `${window.location.href}${d}`;
90
- (l === H || l.endsWith(d)) && (s.href = `{{${a}_${c}}}`);
59
+ const e = f, s = e.ATTR, l = e.DEFAULT_HREF || "#!", c = e.HREF;
60
+ t.textContent && (t.innerHTML = L(t, `{{${s}_${n}}}`));
61
+ const i = t.closest("a") || (t.tagName === "A" ? t : null);
62
+ if (i && c) {
63
+ const a = i.href, b = `${window.location.href}${l}`;
64
+ (a === b || a.endsWith(l)) && (i.href = `{{${c}_${n}}}`);
91
65
  }
92
66
  break;
93
67
  }
94
68
  case "price":
95
69
  case "originalPrice": {
96
- const e = f, i = G(n) ? K(n) : J(t);
97
- t.innerHTML = w(t, Z(e, c, i));
70
+ const e = f, s = t.getAttribute("data-formated"), l = t.getAttribute("data-single_price"), c = s === "true", i = l === "true", a = t.getAttribute(U.POSITION) || "before";
71
+ let b;
72
+ i ? b = c ? e.SINGLE_PRICE_FORMATTED : e.SINGLE_PRICE : b = c ? e.PRICE_FORMATTED : e.PRICE;
73
+ const g = e.CURRENCY;
74
+ let u = `{{${b}_${n}}}`;
75
+ const H = (t.getAttribute(U.SYMBOL) || "").trim(), G = Y(H);
76
+ let F = "";
77
+ G ? F = H : g && (F = `{{${g}_${n}}}`), F && (u = a === "after" ? `${u} ${F}` : `${F} ${u}`), t.innerHTML = L(t, u);
98
78
  break;
99
79
  }
100
80
  case "quantity": {
101
- const e = f, i = e.ATTR, d = [e.DEFAULT, ...e.LEGACY_DEFAULTS], a = (x = t.textContent) == null ? void 0 : x.trim();
102
- a && d.includes(a) && (t.innerHTML = w(t, `{{${i}_${c}}}`));
81
+ const e = f, s = e.ATTR, l = [e.DEFAULT, ...e.LEGACY_DEFAULTS], c = (x = t.textContent) == null ? void 0 : x.trim();
82
+ c && l.includes(c) && (t.innerHTML = L(t, `{{${s}_${n}}}`));
103
83
  break;
104
84
  }
105
85
  case "button": {
106
- const e = f, i = e.HREF, d = e.DEFAULT_HREF || "#!", a = t.tagName === "A" ? t : t.querySelector("a");
107
- if (a) {
108
- const s = a.href || "", l = `${window.location.href}${d}`;
109
- (s === "" || s === "#" || s === l || s.endsWith(d) || s.endsWith("#!") || s === window.location.href) && (a.href = `{{${i}_${c}}}`);
86
+ const e = f, s = e.HREF, l = e.DEFAULT_HREF || "#!", c = t.tagName === "A" ? t : t.querySelector("a");
87
+ if (c) {
88
+ const i = c.href || "", a = `${window.location.href}${l}`;
89
+ (i === "" || i === "#" || i === a || i.endsWith(l) || i.endsWith("#!") || i === window.location.href) && (c.href = `{{${s}_${n}}}`);
110
90
  }
111
- z(t, `{{${i}_${c}}}`);
91
+ Q(t, `{{${s}_${n}}}`);
112
92
  break;
113
93
  }
114
94
  case "itemLink": {
115
- const e = f, i = e.HREF, d = e.DEFAULT_HREF || "#!", a = t;
116
- if (a.href) {
117
- const s = a.href, l = `${window.location.href}${d}`;
118
- (s === l || s.endsWith(d)) && (a.href = `{{${i}_${c}}}`);
95
+ const e = f, s = e.HREF, l = e.DEFAULT_HREF || "#!", c = t;
96
+ if (c.href) {
97
+ const i = c.href, a = `${window.location.href}${l}`;
98
+ (i === a || i.endsWith(l)) && (c.href = `{{${s}_${n}}}`);
119
99
  }
120
100
  break;
121
101
  }
122
102
  default: {
123
103
  if ("ATTR" in f) {
124
104
  const e = f.ATTR;
125
- t.textContent && (t.innerHTML = w(t, `{{${e}_${c}}}`));
105
+ t.textContent && (t.innerHTML = L(t, `{{${e}_${n}}}`));
126
106
  }
127
107
  break;
128
108
  }
@@ -130,49 +110,49 @@ function ct(r) {
130
110
  });
131
111
  });
132
112
  });
133
- const A = h.match(/<!DOCTYPE[^>]*>/i), L = A ? `${A[0]}
134
- ` : "", P = p.querySelectorAll(".ins-product-td"), y = [];
113
+ const E = C.match(/<!DOCTYPE[^>]*>/i), k = E ? `${E[0]}
114
+ ` : "", P = A.querySelectorAll(".ins-product-td"), N = [];
135
115
  P.forEach((o) => {
136
- const T = o.getAttribute("data-type") || "CART_ITEMS", _ = o.getAttribute("data-number") || "1", n = o.outerHTML;
137
- y.push({
116
+ const p = o.getAttribute("data-type") || "CART_ITEMS", T = o.getAttribute("data-number") || "1", r = o.outerHTML;
117
+ N.push({
138
118
  element: o,
139
- outerHtml: n,
140
- type: T,
141
- number: _
119
+ outerHtml: r,
120
+ type: p,
121
+ number: T
142
122
  });
143
123
  });
144
- let E = L + p.documentElement.outerHTML;
145
- y.reverse().forEach(({ outerHtml: o, type: T, number: _ }) => {
146
- const n = q[T], S = n ? `${n}_total_product_kind` : "";
147
- if (S) {
148
- const g = parseInt(_) - 1, c = `${`{% if ${S} > ${g} %}`}${o}{% endif %}`;
149
- E = E.replace(o, v(c));
124
+ let h = k + A.documentElement.outerHTML;
125
+ N.reverse().forEach(({ outerHtml: o, type: p, number: T }) => {
126
+ const r = q[p], _ = r ? `${r}_total_product_kind` : "";
127
+ if (_) {
128
+ const R = parseInt(T) - 1, n = `${`{% if ${_} > ${R} %}`}${o}{% endif %}`;
129
+ h = h.replace(o, B(n));
150
130
  }
151
131
  });
152
- const F = p.querySelectorAll('[product-attr="originalPrice"][data-type]'), R = /* @__PURE__ */ new Map(), O = /* @__PURE__ */ new Set();
153
- return F.forEach((o) => {
132
+ const V = A.querySelectorAll('[product-attr="originalPrice"][data-type]'), w = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Set();
133
+ return V.forEach((o) => {
154
134
  var t;
155
- const T = o.getAttribute("data-number"), _ = o.getAttribute("data-type");
156
- if (!T || !q[_])
135
+ const p = o.getAttribute("data-number"), T = o.getAttribute("data-type");
136
+ if (!p || !q[T])
157
137
  return;
158
- const n = o.closest(".product-original-price-class");
159
- if (!n || O.has(n))
138
+ const r = o.closest(".product-original-price-class");
139
+ if (!r || D.has(r))
160
140
  return;
161
- O.add(n);
162
- const S = n.outerHTML, I = (t = o.closest(".ins-product-td")) == null ? void 0 : t.getAttribute("data-nodup"), g = R.get(S) ?? { number: T, type: _, wrap: [] };
163
- g.wrap.push(I !== "false"), R.set(S, g);
164
- }), R.forEach(({ number: o, type: T, wrap: _ }, n) => {
165
- if (n.includes("{% if") || !_.some(Boolean))
141
+ D.add(r);
142
+ const _ = r.outerHTML, y = (t = o.closest(".ins-product-td")) == null ? void 0 : t.getAttribute("data-nodup"), R = w.get(_) ?? { number: p, type: T, wrap: [] };
143
+ R.wrap.push(y !== "false"), w.set(_, R);
144
+ }), w.forEach(({ number: o, type: p, wrap: T }, r) => {
145
+ if (r.includes("{% if") || !T.some(Boolean))
166
146
  return;
167
- const S = k.PAIRS_FOR_EXTENSION.price[T].PRICE, I = k.PAIRS_FOR_EXTENSION.originalPrice[T].PRICE, g = `{% if ${S}_${o} != ${I}_${o} %}`, t = [g, W(g)];
168
- let m = "", c = 0, f = 0, b = E.indexOf(n);
169
- for (; b !== -1; ) {
170
- const M = _[f] === !0 && !j(E, b, t);
171
- m += E.slice(c, b) + (M ? `${g}${n}{% endif %}` : n), c = b + n.length, f += 1, b = E.indexOf(n, c);
147
+ const _ = M.PAIRS_FOR_EXTENSION.price[p].PRICE, y = M.PAIRS_FOR_EXTENSION.originalPrice[p].PRICE, R = `{% if ${_}_${o} != ${y}_${o} %}`, t = [R, W(R)];
148
+ let m = "", n = 0, f = 0, S = h.indexOf(r);
149
+ for (; S !== -1; ) {
150
+ const I = T[f] === !0 && !v(h, S, t);
151
+ m += h.slice(n, S) + (I ? `${R}${r}{% endif %}` : r), n = S + r.length, f += 1, S = h.indexOf(r, n);
172
152
  }
173
- E = m + E.slice(c);
174
- }), E.replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
153
+ h = m + h.slice(n);
154
+ }), h.replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
175
155
  }
176
156
  export {
177
- ct as pairProductVariables
157
+ et as pairProductVariables
178
158
  };
@@ -0,0 +1,10 @@
1
+ const E = /(<[a-z][\w:-]*(?:\s[^>]*?)?\shref\s*=\s*)(["'])([\s\S]*?)\2/gi, c = /^(?:\s|&nbsp;|&#160;|&#xa0;)+|(?:\s|&nbsp;|&#160;|&#xa0;)+$/gi;
2
+ function a(e) {
3
+ return !e || !/href/i.test(e) ? e : e.replace(E, (i, s, r, n) => {
4
+ const t = n.replace(c, "");
5
+ return `${s}${r}${t}${r}`;
6
+ });
7
+ }
8
+ export {
9
+ a as trimHrefWhitespace
10
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.23.0-beta.9f6bfbf",
3
+ "version": "3.23.0-beta.a3a0b68",
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",
@@ -128,7 +128,7 @@
128
128
  },
129
129
  "guido": {
130
130
  "stripo": {
131
- "version": "2.81.1"
131
+ "version": "2.83.1"
132
132
  }
133
133
  }
134
134
  }
@@ -1,20 +0,0 @@
1
- import { ITEMS_PRICE_FORMAT_ATTR as e } from "../../extensions/Blocks/Items/constants/currency.js";
2
- import { applyPriceFormatOpsToElement as o, planPriceFormatOps as n, snapshotPriceFormatFromElement as c } from "../../extensions/Blocks/Items/utils/priceFormatOps.js";
3
- import { protectLiquid as i, restoreLiquid as s } from "../../utils/liquidProtection.js";
4
- const m = `td.ins-product-td.items-block-v2:not([${e.DECIMAL_COUNT}])`, a = (r) => o(
5
- r,
6
- n(c(r), { convertLegacy: !0 })
7
- );
8
- function T(r) {
9
- if (typeof r != "string" || !r.includes("ins-product-td"))
10
- return r;
11
- try {
12
- const t = new DOMParser().parseFromString(i(r), "text/html");
13
- return Array.from(t.querySelectorAll(m)).map(a).includes(!0) ? s(t.documentElement.outerHTML) : r;
14
- } catch (t) {
15
- return console.error("ItemsPriceFormatMigrator failed:", t), r;
16
- }
17
- }
18
- export {
19
- T as migrateItemsPriceFormat
20
- };
@@ -1,145 +0,0 @@
1
- var f = Object.defineProperty;
2
- var P = (o, i, t) => i in o ? f(o, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[i] = t;
3
- var E = (o, i, t) => P(o, typeof i != "symbol" ? i + "" : i, t);
4
- import { currencyOperators as m, currencyDecimalCounts as _ } from "../../../../enums/extensions/recommendationBlock.js";
5
- import { UEAttr as d, ModificationDescription as L } from "../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
6
- import { CommonControl as N } from "../../common-control.js";
7
- import { priceFormatFromConfig as T, normalizeDecimalCount as U, isNewPriceFormatRoot as M } from "../constants/currency.js";
8
- import { ItemsBlockControlId as I, ItemsBlockId as R } from "../enums/controlEnums.js";
9
- import { getItemsBlockConfig as h, getItemsBlockContainer as g, setItemsBlockConfig as F } from "../utils/nodeConfigUtils.js";
10
- import { planPriceFormatOps as w, buildPriceFormatSnapshot as b, priceTextsFromConfig as x, samePriceText as y, replacePriceText as k } from "../utils/priceFormatOps.js";
11
- const B = I.PRICE_FORMAT, a = {
12
- THOUSAND_SEPARATOR: "priceThousandSeparator",
13
- DECIMAL_SEPARATOR: "priceDecimalSeparator",
14
- DECIMAL_COUNT: "priceDecimalCount"
15
- }, H = [
16
- ["price", R.PRICE],
17
- ["originalPrice", R.ORIGINAL_PRICE]
18
- ];
19
- function V(o) {
20
- return H.flatMap(([i, t]) => o.querySelectorAll(
21
- `[esd-extension-block-id="${t}"]`
22
- ).flatMap((r) => {
23
- const c = r.querySelector("p");
24
- return c ? [{ kind: i, paragraph: c }] : [];
25
- }));
26
- }
27
- function Q(o) {
28
- return M(g(o));
29
- }
30
- function K(o, i, t, e) {
31
- const r = g(o);
32
- if (!r)
33
- return;
34
- const c = { ...h(o), ...t }, C = V(r), p = w(b({
35
- rootAttr: (n) => r.getAttribute(n),
36
- config: c,
37
- paragraphs: C.map(({ kind: n, paragraph: s }) => ({
38
- kind: n,
39
- attr: (u) => s.getAttribute(u),
40
- text: s.getInnerText()
41
- }))
42
- }), { convertLegacy: !0 }), S = p.texts ?? x(c), l = i.getDocumentModifier();
43
- F(o, i, { ...t, ...p.configPatch }, l);
44
- const D = l.modifyHtml(r);
45
- Object.entries(p.rootSet).forEach(([n, s]) => {
46
- D.setAttribute(n, s);
47
- }), C.forEach(({ kind: n, paragraph: s }) => {
48
- const u = l.modifyHtml(s), A = s.getInnerText().trim();
49
- p.paragraphRemove.forEach((O) => {
50
- u.removeAttribute(O);
51
- }), y(A, S[n]) || u.setInnerHtml(k(s.getInnerHTML(), A, S[n]));
52
- }), l.apply(new L(e));
53
- }
54
- class X extends N {
55
- constructor() {
56
- super(...arguments);
57
- // The format of the last write, until Stripo hands back the updated node: guards the echo
58
- // of the select this control itself repaints on an auto-swap.
59
- E(this, "lastWritten", null);
60
- }
61
- getId() {
62
- return B;
63
- }
64
- getTemplate() {
65
- return `
66
- <div class="${I.PRICE_FORMAT}">
67
- ${this._getSelectRow("Thousand Separator", a.THOUSAND_SEPARATOR, m)}
68
- ${this._getSelectRow("Decimal Separator", a.DECIMAL_SEPARATOR, m)}
69
- ${this._getSelectRow("Decimal Count", a.DECIMAL_COUNT, _)}
70
- </div>
71
- `;
72
- }
73
- onRender() {
74
- this.forgetLastPanelNode(), this.api.setUIEAttribute(a.THOUSAND_SEPARATOR, d.SELECTPICKER.items, m), this.api.setUIEAttribute(a.DECIMAL_SEPARATOR, d.SELECTPICKER.items, m), this.api.setUIEAttribute(a.DECIMAL_COUNT, d.SELECTPICKER.items, _), this.api.onValueChanged(a.THOUSAND_SEPARATOR, (t) => {
75
- this._onThousandSeparatorChange(t);
76
- }), this.api.onValueChanged(a.DECIMAL_SEPARATOR, (t) => {
77
- this._onDecimalSeparatorChange(t);
78
- }), this.api.onValueChanged(a.DECIMAL_COUNT, (t) => {
79
- this._onDecimalCountChange(t);
80
- });
81
- }
82
- onTemplateNodeUpdated(t) {
83
- super.onTemplateNodeUpdated(t), this.lastWritten = null, this.handleBlockInstanceChange(() => {
84
- this.api.updateValues(this._formValues(T(h(this.currentNode))));
85
- });
86
- }
87
- onDestroy() {
88
- super.onDestroy(), this.lastWritten = null;
89
- }
90
- _onThousandSeparatorChange(t) {
91
- const e = this._currentFormat();
92
- if (t === e.thousandSeparator)
93
- return;
94
- const r = t === e.decimalSeparator;
95
- this._write({
96
- ...e,
97
- thousandSeparator: t,
98
- decimalSeparator: r ? e.thousandSeparator : e.decimalSeparator
99
- }, "Updated price thousand separator"), r && this.api.updateValues({ [a.DECIMAL_SEPARATOR]: e.thousandSeparator });
100
- }
101
- _onDecimalSeparatorChange(t) {
102
- const e = this._currentFormat();
103
- if (t === e.decimalSeparator)
104
- return;
105
- const r = t === e.thousandSeparator;
106
- this._write({
107
- ...e,
108
- decimalSeparator: t,
109
- thousandSeparator: r ? e.decimalSeparator : e.thousandSeparator
110
- }, "Updated price decimal separator"), r && this.api.updateValues({ [a.THOUSAND_SEPARATOR]: e.decimalSeparator });
111
- }
112
- _onDecimalCountChange(t) {
113
- const e = this._currentFormat(), r = U(t);
114
- r !== e.decimalCount && this._write({ ...e, decimalCount: r }, "Updated price decimal count");
115
- }
116
- _currentFormat() {
117
- return this.lastWritten ?? T(h(this.currentNode));
118
- }
119
- _write(t, e) {
120
- this.lastWritten = t, K(this.currentNode, this.api, {
121
- priceThousandSeparator: t.thousandSeparator,
122
- priceDecimalSeparator: t.decimalSeparator,
123
- priceDecimalCount: t.decimalCount
124
- }, e);
125
- }
126
- _formValues(t) {
127
- return {
128
- [a.THOUSAND_SEPARATOR]: t.thousandSeparator,
129
- [a.DECIMAL_SEPARATOR]: t.decimalSeparator,
130
- [a.DECIMAL_COUNT]: String(t.decimalCount)
131
- };
132
- }
133
- _getSelectRow(t, e, r) {
134
- return this._GuTwoColumns([
135
- this._GuLabel({ text: this.api.translate(t) }),
136
- this._GuSelect({ name: e, placeholder: "", options: r })
137
- ], "no-separator");
138
- }
139
- }
140
- export {
141
- B as CONTROL_BLOCK_ID,
142
- X as ItemsBlockPriceFormatControl,
143
- K as applyPriceFormatChange,
144
- Q as isNewPriceFormatBlock
145
- };