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