@useinsider/guido 3.14.1-beta.9ad6513 → 3.15.0-beta.360c5d6
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/dist/composables/useEmailTemplateApplier.js +46 -32
- package/dist/composables/useHtmlValidator.js +111 -106
- package/dist/extensions/Blocks/Items/block.js +44 -42
- package/dist/extensions/Blocks/Items/template.js +86 -86
- package/dist/src/stores/dynamic-content.d.ts +8 -0
- package/dist/src/utils/registerUsedDynamicContent.d.ts +8 -0
- package/dist/stores/dynamic-content.js +12 -2
- package/dist/utils/pairProductVariables.js +93 -92
- package/dist/utils/registerUsedDynamicContent.js +23 -0
- package/package.json +1 -1
|
@@ -1,88 +1,94 @@
|
|
|
1
|
-
import { productPairs as
|
|
2
|
-
import { DefaultConfigValues as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { productPairs as I } from "../extensions/Blocks/Items/enums/productEnums.js";
|
|
2
|
+
import { DefaultConfigValues as G } from "../extensions/Blocks/Items/enums/settingsEnums.js";
|
|
3
|
+
import { escapeReplacement as N } from "../extensions/Blocks/Items/utils/nodeConfigUtils.js";
|
|
4
|
+
import { preserveTextStyles as S } from "./preserveTextStyles.js";
|
|
5
|
+
import { unwrapProductNameLinks as X } from "./unwrapProductNameLink.js";
|
|
6
|
+
const x = {
|
|
7
|
+
CART_ITEMS: "ins_apr",
|
|
8
|
+
BROWSED_ITEMS: "browsed_item",
|
|
9
|
+
PURCHASED_ITEMS: "purchased_item"
|
|
10
|
+
}, O = (m) => m.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->");
|
|
11
|
+
function z(m) {
|
|
12
|
+
const P = O(m), b = new DOMParser().parseFromString(P, "text/html");
|
|
13
|
+
X(b);
|
|
14
|
+
const C = I.PAIRS_FOR_EXTENSION;
|
|
15
|
+
Object.entries(C).forEach(([r, l]) => {
|
|
16
|
+
b.querySelectorAll(".ins-product-td").forEach((u) => {
|
|
17
|
+
const p = u.getAttribute("data-number") || "1", T = u.getAttribute("data-type") || "CART_ITEMS";
|
|
18
|
+
u.querySelectorAll(`[product-attr="${r}"]`).forEach((t) => {
|
|
19
|
+
var w, k, D;
|
|
20
|
+
const _ = t.getAttribute("data-type") || T, f = t.getAttribute("data-number") || p, A = l[_];
|
|
21
|
+
if (A)
|
|
16
22
|
switch (r) {
|
|
17
23
|
case "imageSrc": {
|
|
18
24
|
let e = null, c = null;
|
|
19
25
|
if (t.tagName === "IMG" ? (e = t, c = e.closest("a")) : (e = t.querySelector("img"), c = t.querySelector("a") || t.closest("a")), !e)
|
|
20
26
|
break;
|
|
21
|
-
const i =
|
|
27
|
+
const i = A.DEFAULT, s = A.ATTR;
|
|
22
28
|
if (i && e.src) {
|
|
23
29
|
const o = e.src;
|
|
24
|
-
i.some((
|
|
25
|
-
const
|
|
26
|
-
return o.includes(
|
|
27
|
-
}) && (e.src = `{{${
|
|
30
|
+
i.some(($) => {
|
|
31
|
+
const a = $.split("/").pop() || "", g = o.split("/").pop() || "";
|
|
32
|
+
return o.includes($) || o.includes(a) || g === a;
|
|
33
|
+
}) && (e.src = `{{${s}_${f}}}`);
|
|
28
34
|
}
|
|
29
|
-
const n = (
|
|
35
|
+
const n = (k = (w = C.name) == null ? void 0 : w[_]) == null ? void 0 : k.ATTR;
|
|
30
36
|
if (n && e.setAttribute("alt", `{{${n}_${f}}}`), c) {
|
|
31
|
-
const o = (
|
|
37
|
+
const o = (D = C.itemLink) == null ? void 0 : D[_];
|
|
32
38
|
if (o) {
|
|
33
|
-
const
|
|
34
|
-
(
|
|
39
|
+
const E = o.HREF, $ = o.DEFAULT_HREF || "#!", a = c.href;
|
|
40
|
+
(a === "#" || a === "" || a.endsWith("#!") || a.endsWith($) || a === `${window.location.href}${$}` || !a || a === window.location.href) && (c.href = `{{${E}_${f}}}`);
|
|
35
41
|
}
|
|
36
42
|
}
|
|
37
43
|
break;
|
|
38
44
|
}
|
|
39
45
|
case "name": {
|
|
40
|
-
const e =
|
|
41
|
-
t.textContent && (t.innerHTML =
|
|
46
|
+
const e = A, c = e.ATTR, i = e.DEFAULT_HREF || "#!", s = e.HREF;
|
|
47
|
+
t.textContent && (t.innerHTML = S(t, `{{${c}_${f}}}`));
|
|
42
48
|
const n = t.closest("a") || (t.tagName === "A" ? t : null);
|
|
43
|
-
if (n &&
|
|
44
|
-
const o = n.href,
|
|
45
|
-
(o ===
|
|
49
|
+
if (n && s) {
|
|
50
|
+
const o = n.href, E = `${window.location.href}${i}`;
|
|
51
|
+
(o === E || o.endsWith(i)) && (n.href = `{{${s}_${f}}}`);
|
|
46
52
|
}
|
|
47
53
|
break;
|
|
48
54
|
}
|
|
49
55
|
case "price":
|
|
50
56
|
case "originalPrice": {
|
|
51
|
-
const e =
|
|
52
|
-
let
|
|
53
|
-
n ?
|
|
54
|
-
const
|
|
55
|
-
let
|
|
56
|
-
const g = (t.getAttribute("data-currency_symbol") || "").trim(),
|
|
57
|
-
let
|
|
58
|
-
|
|
57
|
+
const e = A, c = t.getAttribute("data-formated"), i = t.getAttribute("data-single_price"), s = c === "true", n = i === "true", o = t.getAttribute("data-curency") || "before";
|
|
58
|
+
let E;
|
|
59
|
+
n ? E = s ? e.SINGLE_PRICE_FORMATTED : e.SINGLE_PRICE : E = s ? e.PRICE_FORMATTED : e.PRICE;
|
|
60
|
+
const $ = e.CURRENCY;
|
|
61
|
+
let a = `{{${E}_${f}}}`;
|
|
62
|
+
const g = (t.getAttribute("data-currency_symbol") || "").trim(), W = g !== "" && g !== G.productPriceCurrencySymbolControlValue;
|
|
63
|
+
let y = "";
|
|
64
|
+
W ? y = g : $ && (y = `{{${$}_${f}}}`), y && (a = o === "after" ? `${a} ${y}` : `${y} ${a}`), t.innerHTML = S(t, a);
|
|
59
65
|
break;
|
|
60
66
|
}
|
|
61
67
|
case "quantity": {
|
|
62
|
-
const e =
|
|
63
|
-
t.textContent && t.textContent.trim() === i && (t.innerHTML =
|
|
68
|
+
const e = A, c = e.ATTR, i = e.DEFAULT;
|
|
69
|
+
t.textContent && t.textContent.trim() === i && (t.innerHTML = S(t, `{{${c}_${f}}}`));
|
|
64
70
|
break;
|
|
65
71
|
}
|
|
66
72
|
case "button": {
|
|
67
|
-
const e =
|
|
68
|
-
if (
|
|
69
|
-
const n =
|
|
70
|
-
(n === "" || n === "#" || n === o || n.endsWith(i) || n.endsWith("#!") || n === window.location.href) && (
|
|
73
|
+
const e = A, c = e.HREF, i = e.DEFAULT_HREF || "#!", s = t.tagName === "A" ? t : t.querySelector("a");
|
|
74
|
+
if (s) {
|
|
75
|
+
const n = s.href || "", o = `${window.location.href}${i}`;
|
|
76
|
+
(n === "" || n === "#" || n === o || n.endsWith(i) || n.endsWith("#!") || n === window.location.href) && (s.href = `{{${c}_${f}}}`);
|
|
71
77
|
}
|
|
72
78
|
break;
|
|
73
79
|
}
|
|
74
80
|
case "itemLink": {
|
|
75
|
-
const e =
|
|
76
|
-
if (
|
|
77
|
-
const n =
|
|
78
|
-
(n === o || n.endsWith(i)) && (
|
|
81
|
+
const e = A, c = e.HREF, i = e.DEFAULT_HREF || "#!", s = t;
|
|
82
|
+
if (s.href) {
|
|
83
|
+
const n = s.href, o = `${window.location.href}${i}`;
|
|
84
|
+
(n === o || n.endsWith(i)) && (s.href = `{{${c}_${f}}}`);
|
|
79
85
|
}
|
|
80
86
|
break;
|
|
81
87
|
}
|
|
82
88
|
default: {
|
|
83
|
-
if ("ATTR" in
|
|
84
|
-
const e =
|
|
85
|
-
t.textContent && (t.innerHTML =
|
|
89
|
+
if ("ATTR" in A) {
|
|
90
|
+
const e = A.ATTR;
|
|
91
|
+
t.textContent && (t.innerHTML = S(t, `{{${e}_${f}}}`));
|
|
86
92
|
}
|
|
87
93
|
break;
|
|
88
94
|
}
|
|
@@ -90,55 +96,50 @@ function Y(L) {
|
|
|
90
96
|
});
|
|
91
97
|
});
|
|
92
98
|
});
|
|
93
|
-
const
|
|
94
|
-
` : "",
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
99
|
+
const F = P.match(/<!DOCTYPE[^>]*>/i), q = F ? `${F[0]}
|
|
100
|
+
` : "", U = b.querySelectorAll(".ins-product-td"), L = [];
|
|
101
|
+
U.forEach((r) => {
|
|
102
|
+
const l = r.getAttribute("data-type") || "CART_ITEMS", d = r.getAttribute("data-number") || "1", u = r.outerHTML;
|
|
103
|
+
L.push({
|
|
98
104
|
element: r,
|
|
99
|
-
outerHtml:
|
|
100
|
-
type:
|
|
101
|
-
number:
|
|
105
|
+
outerHtml: u,
|
|
106
|
+
type: l,
|
|
107
|
+
number: d
|
|
102
108
|
});
|
|
103
109
|
});
|
|
104
|
-
let
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
break;
|
|
111
|
-
case "BROWSED_ITEMS":
|
|
112
|
-
l = "browsed_item_total_product_kind";
|
|
113
|
-
break;
|
|
114
|
-
case "PURCHASED_ITEMS":
|
|
115
|
-
l = "purchased_item_total_product_kind";
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
if (l) {
|
|
119
|
-
const $ = parseInt(p) - 1, T = `${`{% if ${l} > ${$} %}`}${r}{% endif %}`;
|
|
120
|
-
_ = _.replace(r, T);
|
|
110
|
+
let h = q + b.documentElement.outerHTML;
|
|
111
|
+
L.reverse().forEach(({ outerHtml: r, type: l, number: d }) => {
|
|
112
|
+
const u = x[l], p = u ? `${u}_total_product_kind` : "";
|
|
113
|
+
if (p) {
|
|
114
|
+
const R = parseInt(d) - 1, f = `${`{% if ${p} > ${R} %}`}${r}{% endif %}`;
|
|
115
|
+
h = h.replace(r, N(f));
|
|
121
116
|
}
|
|
122
117
|
});
|
|
123
|
-
const
|
|
124
|
-
return
|
|
125
|
-
var
|
|
126
|
-
const
|
|
127
|
-
if (!
|
|
118
|
+
const V = b.querySelectorAll('[product-attr="originalPrice"][data-type]'), H = [], M = /* @__PURE__ */ new Set();
|
|
119
|
+
return V.forEach((r) => {
|
|
120
|
+
var t;
|
|
121
|
+
const l = r.getAttribute("data-number"), d = r.getAttribute("data-type");
|
|
122
|
+
if (!l || !x[d])
|
|
123
|
+
return;
|
|
124
|
+
const u = r.closest(".product-original-price-class");
|
|
125
|
+
if (!u)
|
|
126
|
+
return;
|
|
127
|
+
const p = u.outerHTML;
|
|
128
|
+
if (((t = r.closest(".ins-product-td")) == null ? void 0 : t.getAttribute("data-nodup")) === "false") {
|
|
129
|
+
M.add(p);
|
|
128
130
|
return;
|
|
129
|
-
const h = r.closest(".product-original-price-class");
|
|
130
|
-
if (h) {
|
|
131
|
-
const y = h.outerHTML;
|
|
132
|
-
S.some((T) => T.tdOuterHtml === y) || S.push({ tdOuterHtml: y, number: u });
|
|
133
|
-
}
|
|
134
|
-
}), S.reverse().forEach(({ tdOuterHtml: r, number: u }) => {
|
|
135
|
-
const p = `{% if ins_apr_price_${u} != ins_apr_originalprice_${u} %}`;
|
|
136
|
-
if (!_.includes(p) && !r.includes("{% if")) {
|
|
137
|
-
const h = `${p}${r}{% endif %}`;
|
|
138
|
-
_ = _.replace(r, h);
|
|
139
131
|
}
|
|
140
|
-
|
|
132
|
+
H.some((_) => _.tdOuterHtml === p) || H.push({ tdOuterHtml: p, number: l, type: d });
|
|
133
|
+
}), H.forEach(({ tdOuterHtml: r, number: l, type: d }) => {
|
|
134
|
+
if (M.has(r))
|
|
135
|
+
return;
|
|
136
|
+
const u = I.PAIRS_FOR_EXTENSION.price[d].PRICE, p = I.PAIRS_FOR_EXTENSION.originalPrice[d].PRICE, T = `{% if ${u}_${l} != ${p}_${l} %}`, R = h.includes(`${T}${r}`) || h.includes(`${O(T)}${r}`);
|
|
137
|
+
r.includes("{% if") || R || (h = h.replaceAll(
|
|
138
|
+
r,
|
|
139
|
+
N(`${T}${r}{% endif %}`)
|
|
140
|
+
));
|
|
141
|
+
}), h.replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}");
|
|
141
142
|
}
|
|
142
143
|
export {
|
|
143
|
-
|
|
144
|
+
z as pairProductVariables
|
|
144
145
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DATA_ATTRIBUTE_REGEX as T } from "../enums/html-validator.js";
|
|
2
|
+
const d = /{{([a-zA-Z0-9_.\s]*)}}/gm, h = (n, e) => {
|
|
3
|
+
if (!e || e.length === 0)
|
|
4
|
+
return { matched: [], unmatchedTokens: [] };
|
|
5
|
+
const s = n.replace(T, "$1").match(d);
|
|
6
|
+
if (!s)
|
|
7
|
+
return { matched: [], unmatchedTokens: [] };
|
|
8
|
+
const u = new Map(
|
|
9
|
+
e.map((c) => [c.value.trim().toLowerCase(), c])
|
|
10
|
+
), a = /* @__PURE__ */ new Set(), o = [], m = [];
|
|
11
|
+
return s.forEach((c) => {
|
|
12
|
+
const t = c.slice(2, -2).trim().toLowerCase();
|
|
13
|
+
if (t === "" || a.has(t))
|
|
14
|
+
return;
|
|
15
|
+
a.add(t);
|
|
16
|
+
const r = u.get(t);
|
|
17
|
+
r ? o.push(r) : m.push(t);
|
|
18
|
+
}), { matched: o, unmatchedTokens: m };
|
|
19
|
+
}, E = (n, e) => h(n, e).matched, k = (n, e) => h(n, e).unmatchedTokens;
|
|
20
|
+
export {
|
|
21
|
+
E as extractUsedDynamicContent,
|
|
22
|
+
k as getUnmatchedDynamicContentTokens
|
|
23
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useinsider/guido",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.15.0-beta.360c5d6",
|
|
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",
|