@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.
- package/README.md +5 -5
- package/dist/config/migrator/itemsBlockMigrator.js +194 -150
- package/dist/extensions/Blocks/Items/block.js +98 -49
- package/dist/extensions/Blocks/Items/constants/currency.js +11 -0
- package/dist/extensions/Blocks/Items/controls/price/currencyLocation.js +25 -24
- package/dist/extensions/Blocks/Items/controls/price/currencySymbol.js +12 -11
- package/dist/extensions/Blocks/Items/enums/productEnums.js +5 -5
- package/dist/extensions/Blocks/Items/template.js +196 -195
- package/dist/package.json.js +1 -1
- package/dist/src/extensions/Blocks/Items/block.d.ts +21 -0
- package/dist/src/extensions/Blocks/Items/constants/currency.d.ts +19 -0
- package/dist/utils/pairProductVariables.js +60 -59
- package/package.json +3 -3
|
@@ -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
|
|
3
|
-
import { escapeReplacement as
|
|
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
|
|
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
|
-
},
|
|
11
|
-
function v(S,
|
|
12
|
-
let
|
|
13
|
-
for (;
|
|
14
|
-
|
|
15
|
-
return
|
|
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
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
Object.entries(
|
|
22
|
-
|
|
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
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
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 =
|
|
34
|
+
const a = u.DEFAULT, l = u.ATTR;
|
|
34
35
|
if (a && e.src) {
|
|
35
36
|
const i = e.src;
|
|
36
|
-
a.some((
|
|
37
|
-
const
|
|
38
|
-
return i.includes(
|
|
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 = (
|
|
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 =
|
|
44
|
+
const i = (D = h.itemLink) == null ? void 0 : D[g];
|
|
44
45
|
if (i) {
|
|
45
|
-
const
|
|
46
|
-
(
|
|
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 =
|
|
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,
|
|
57
|
-
(i ===
|
|
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 =
|
|
64
|
-
let
|
|
65
|
-
c ?
|
|
66
|
-
const
|
|
67
|
-
let
|
|
68
|
-
const
|
|
69
|
-
let
|
|
70
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
|
96
|
-
const e =
|
|
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
|
|
106
|
-
` : "",
|
|
107
|
-
|
|
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 =
|
|
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
|
|
121
|
-
A = A.replace(n,
|
|
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
|
|
125
|
-
return
|
|
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"),
|
|
135
|
-
|
|
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,
|
|
140
|
-
let
|
|
141
|
-
for (;
|
|
142
|
-
const
|
|
143
|
-
|
|
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 =
|
|
146
|
+
A = g + A.slice(o);
|
|
146
147
|
}), A.replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}");
|
|
147
148
|
}
|
|
148
149
|
export {
|
|
149
|
-
|
|
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.
|
|
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 ./ &&
|
|
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.
|
|
120
|
+
"version": "2.72.1"
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
}
|