@useinsider/guido 3.9.0-beta.fcaa08b → 3.9.0
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,44 +1,44 @@
|
|
|
1
|
-
import { useConfig as
|
|
1
|
+
import { useConfig as _ } from "../../../composables/useConfig.js";
|
|
2
2
|
import { useRecommendation as g } from "../../../composables/useRecommendation.js";
|
|
3
3
|
import { CSS_CLASS_RECO_BUTTON as q } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
|
|
4
|
-
import { useRecommendationExtensionStore as
|
|
4
|
+
import { useRecommendationExtensionStore as C } from "../../../extensions/Blocks/Recommendation/store/recommendation.js";
|
|
5
5
|
import { isIgnoredRecommendationBlock as w } from "./recommendationIgnoreUtils.js";
|
|
6
|
-
function b(
|
|
7
|
-
const i = `{{${c}${
|
|
6
|
+
function b(e, n, t, o, c = "") {
|
|
7
|
+
const i = `{{${c}${e}_${n}_${t}}}`, r = `{{${c}${e}_${n}_currency}}`;
|
|
8
8
|
return o === "before" ? `${r} ${i}` : `${i} ${r}`;
|
|
9
9
|
}
|
|
10
|
-
function m(
|
|
11
|
-
let n =
|
|
10
|
+
function m(e) {
|
|
11
|
+
let n = e;
|
|
12
12
|
for (; n.children.length === 1; )
|
|
13
13
|
[n] = n.children;
|
|
14
14
|
return n;
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function h(e, n, t, o, c, i) {
|
|
17
17
|
switch (n) {
|
|
18
18
|
case "productImage": {
|
|
19
|
-
const r =
|
|
20
|
-
r && (r.setAttribute("src", `{{${i}${
|
|
21
|
-
const s =
|
|
22
|
-
s && (s.setAttribute("href", `{{${i}${
|
|
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));
|
|
23
23
|
break;
|
|
24
24
|
}
|
|
25
25
|
case "productName": {
|
|
26
|
-
const r =
|
|
27
|
-
r && (m(r).textContent = `{{${i}${
|
|
26
|
+
const r = e.querySelector("p");
|
|
27
|
+
r && (m(r).textContent = `{{${i}${t}_${o}_name}}`);
|
|
28
28
|
break;
|
|
29
29
|
}
|
|
30
30
|
case "productPrice": {
|
|
31
|
-
const r =
|
|
31
|
+
const r = e.querySelector(".product-price p") ?? e.querySelector("p");
|
|
32
32
|
r && (m(r).textContent = b(
|
|
33
|
-
|
|
33
|
+
t,
|
|
34
34
|
o,
|
|
35
35
|
"price",
|
|
36
36
|
c,
|
|
37
37
|
i
|
|
38
38
|
));
|
|
39
|
-
const s =
|
|
39
|
+
const s = e.querySelector(".product-old-price p");
|
|
40
40
|
s && (m(s).textContent = b(
|
|
41
|
-
|
|
41
|
+
t,
|
|
42
42
|
o,
|
|
43
43
|
"original_price",
|
|
44
44
|
c,
|
|
@@ -47,9 +47,9 @@ function y(t, n, e, o, c, i) {
|
|
|
47
47
|
break;
|
|
48
48
|
}
|
|
49
49
|
case "productOldPrice": {
|
|
50
|
-
const r =
|
|
50
|
+
const r = e.querySelector("p");
|
|
51
51
|
r && (m(r).textContent = b(
|
|
52
|
-
|
|
52
|
+
t,
|
|
53
53
|
o,
|
|
54
54
|
"original_price",
|
|
55
55
|
c,
|
|
@@ -58,117 +58,97 @@ function y(t, n, e, o, c, i) {
|
|
|
58
58
|
break;
|
|
59
59
|
}
|
|
60
60
|
case "productButton": {
|
|
61
|
-
const r =
|
|
62
|
-
r && r.setAttribute("href", `{{${i}${
|
|
61
|
+
const r = e.querySelector("a");
|
|
62
|
+
r && r.setAttribute("href", `{{${i}${t}_${o}_url}}`);
|
|
63
63
|
break;
|
|
64
64
|
}
|
|
65
65
|
case "productOmnibusPrice": {
|
|
66
|
-
const r =
|
|
66
|
+
const r = e.querySelector(".omnibus-price-value");
|
|
67
67
|
if (r) {
|
|
68
|
-
r.textContent = `{{${i}${
|
|
68
|
+
r.textContent = `{{${i}${t}_${o}_omnibus_price}}`;
|
|
69
69
|
const s = r.closest("p");
|
|
70
70
|
s && (s.setAttribute("product-attr", "omnibus_price"), s.setAttribute("composition", "true"));
|
|
71
71
|
}
|
|
72
72
|
break;
|
|
73
73
|
}
|
|
74
74
|
case "productOmnibusDiscount": {
|
|
75
|
-
const r =
|
|
75
|
+
const r = e.querySelector(".omnibus-discount-value");
|
|
76
76
|
if (r) {
|
|
77
|
-
r.textContent = `{{${i}${
|
|
77
|
+
r.textContent = `{{${i}${t}_${o}_omnibus_discount}}`;
|
|
78
78
|
const s = r.closest("p");
|
|
79
79
|
s && (s.setAttribute("product-attr", "omnibus_discount"), s.setAttribute("composition", "true"));
|
|
80
80
|
}
|
|
81
81
|
break;
|
|
82
82
|
}
|
|
83
83
|
default: {
|
|
84
|
-
const r =
|
|
84
|
+
const r = e.getAttribute("product-attr") ? e : e.querySelector("[product-attr]");
|
|
85
85
|
if (r) {
|
|
86
86
|
const s = r.getAttribute("product-attr"), a = r.querySelector("p");
|
|
87
|
-
a && (m(a).textContent = `{{${i}${
|
|
87
|
+
a && (m(a).textContent = `{{${i}${t}_${o}_${s}}}`);
|
|
88
88
|
}
|
|
89
89
|
break;
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const c = `${o}${n}_${e}_${R}`;
|
|
96
|
-
return {
|
|
97
|
-
open: t.createComment(`{% if ${c} and ${c} != "" %}`),
|
|
98
|
-
close: t.createComment("{% endif %}")
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
function P(t, n, e, o) {
|
|
102
|
-
if (!t.innerHTML.includes("{{"))
|
|
103
|
-
return;
|
|
104
|
-
const { open: c, close: i } = S(t.ownerDocument, n, e, o);
|
|
105
|
-
t.insertBefore(c, t.firstChild), t.appendChild(i);
|
|
106
|
-
}
|
|
107
|
-
function T(t, n, e, o) {
|
|
108
|
-
if (!t.innerHTML.includes("{{"))
|
|
109
|
-
return;
|
|
110
|
-
const { open: c, close: i } = S(t.ownerDocument, n, e, o), r = t.parentNode;
|
|
111
|
-
r.insertBefore(c, t), r.insertBefore(i, t.nextSibling);
|
|
112
|
-
}
|
|
113
|
-
function L(t, n, e, o) {
|
|
114
|
-
t.querySelectorAll(".recommendation-product-row").forEach((i, r) => {
|
|
93
|
+
function E(e, n, t, o) {
|
|
94
|
+
e.querySelectorAll(".recommendation-product-row").forEach((i, r) => {
|
|
115
95
|
i.querySelectorAll("[data-attribute-type]").forEach((a) => {
|
|
116
96
|
const u = a.getAttribute("data-attribute-type") || "", p = a.querySelectorAll(".attribute-cell");
|
|
117
97
|
p.length > 0 ? p.forEach((l) => {
|
|
118
|
-
|
|
119
|
-
}) :
|
|
120
|
-
})
|
|
98
|
+
h(l, u, n, r, t, o);
|
|
99
|
+
}) : h(a, u, n, r, t, o);
|
|
100
|
+
});
|
|
121
101
|
});
|
|
122
102
|
}
|
|
123
|
-
function
|
|
124
|
-
const c =
|
|
103
|
+
function P(e, n, t, o) {
|
|
104
|
+
const c = e.querySelectorAll(".recommendation-product-row");
|
|
125
105
|
if (!c.length)
|
|
126
106
|
return;
|
|
127
107
|
const [i] = c, r = i.querySelector("[data-attribute-type]"), s = r ? r.querySelectorAll(".attribute-cell").length : 1;
|
|
128
108
|
c.forEach((a, u) => {
|
|
129
109
|
a.querySelectorAll("[data-attribute-type]").forEach((l) => {
|
|
130
110
|
const d = l.getAttribute("data-attribute-type") || "";
|
|
131
|
-
l.querySelectorAll(".attribute-cell").forEach((
|
|
132
|
-
const
|
|
133
|
-
|
|
111
|
+
l.querySelectorAll(".attribute-cell").forEach((A, $) => {
|
|
112
|
+
const S = u * s + $;
|
|
113
|
+
h(A, d, n, S, t, o);
|
|
134
114
|
});
|
|
135
115
|
});
|
|
136
116
|
});
|
|
137
117
|
}
|
|
138
|
-
function
|
|
139
|
-
|
|
140
|
-
|
|
118
|
+
function R(e, n, t, o) {
|
|
119
|
+
e.querySelectorAll(".ins-recommendation-product-container").forEach((i) => {
|
|
120
|
+
P(i, n, t, o);
|
|
141
121
|
});
|
|
142
122
|
}
|
|
143
|
-
function
|
|
144
|
-
const o =
|
|
145
|
-
o === "list" ?
|
|
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);
|
|
146
126
|
}
|
|
147
|
-
function
|
|
148
|
-
const o = new RegExp(`${n}\\s*:\\s*(\\d+)\\s*px`, "i"), c =
|
|
149
|
-
return c ? parseInt(c[1]) :
|
|
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;
|
|
150
130
|
}
|
|
151
|
-
function
|
|
152
|
-
let
|
|
153
|
-
for (;
|
|
154
|
-
if (
|
|
155
|
-
const o =
|
|
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");
|
|
156
136
|
if (o && o.endsWith("%") && parseFloat(o) < 100)
|
|
157
|
-
return
|
|
137
|
+
return t;
|
|
158
138
|
}
|
|
159
|
-
|
|
139
|
+
t = t.parentElement;
|
|
160
140
|
}
|
|
161
141
|
return null;
|
|
162
142
|
}
|
|
163
|
-
function
|
|
164
|
-
const n =
|
|
165
|
-
c !== 0 &&
|
|
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) => {
|
|
166
146
|
if (i.hasAttribute("width"))
|
|
167
147
|
return;
|
|
168
|
-
const r =
|
|
148
|
+
const r = T(i, e);
|
|
169
149
|
if (!r)
|
|
170
150
|
return;
|
|
171
|
-
const s = r.getAttribute("width"), a = parseFloat(s), u =
|
|
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);
|
|
172
152
|
i.setAttribute("width", String(l));
|
|
173
153
|
const d = i.getAttribute("style") || "";
|
|
174
154
|
if (!/\bwidth\s*:\s*\d/i.test(d)) {
|
|
@@ -177,25 +157,25 @@ function M(t) {
|
|
|
177
157
|
}
|
|
178
158
|
});
|
|
179
159
|
}
|
|
180
|
-
function
|
|
181
|
-
const
|
|
182
|
-
return (
|
|
160
|
+
function W(e, n) {
|
|
161
|
+
const t = e.match(/<!DOCTYPE[^>]*>/i);
|
|
162
|
+
return (t ? `${t[0]}
|
|
183
163
|
` : "") + n.documentElement.outerHTML;
|
|
184
164
|
}
|
|
185
|
-
function
|
|
186
|
-
const n =
|
|
165
|
+
function F(e) {
|
|
166
|
+
const n = e.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), t = new DOMParser().parseFromString(n, "text/html"), o = t.querySelectorAll(".recommendation-block-v2");
|
|
187
167
|
if (!o.length)
|
|
188
|
-
return
|
|
189
|
-
const { buildCampaignUrl: c } = g(), i =
|
|
168
|
+
return e;
|
|
169
|
+
const { buildCampaignUrl: c } = g(), i = C();
|
|
190
170
|
i.recommendationCampaignUrls = {};
|
|
191
|
-
const { isFeatureEnabled: r } =
|
|
171
|
+
const { isFeatureEnabled: r } = _(), s = r("liquidSyntax") ? "reco_" : "";
|
|
192
172
|
return o.forEach((u) => {
|
|
193
173
|
var l, d;
|
|
194
174
|
const p = u.getAttribute("recommendation-id");
|
|
195
|
-
p && ((l = u.parentNode) == null || l.insertBefore(
|
|
196
|
-
}),
|
|
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("<!--{%", "{%").replaceAll("%}-->", "%}");
|
|
197
177
|
}
|
|
198
178
|
export {
|
|
199
179
|
b as formatPriceVariable,
|
|
200
|
-
|
|
180
|
+
F as prepareRecommendationBlocks
|
|
201
181
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useinsider/guido",
|
|
3
|
-
"version": "3.9.0
|
|
3
|
+
"version": "3.9.0",
|
|
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",
|