@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.
@@ -1,88 +1,94 @@
1
- import { productPairs as q } from "../extensions/Blocks/Items/enums/productEnums.js";
2
- import { DefaultConfigValues as O } from "../extensions/Blocks/Items/enums/settingsEnums.js";
3
- import { preserveTextStyles as C } from "./preserveTextStyles.js";
4
- import { unwrapProductNameLinks as U } from "./unwrapProductNameLink.js";
5
- function Y(L) {
6
- const H = L.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), b = new DOMParser().parseFromString(H, "text/html");
7
- U(b);
8
- const R = q.PAIRS_FOR_EXTENSION;
9
- Object.entries(R).forEach(([r, u]) => {
10
- b.querySelectorAll(".ins-product-td").forEach((l) => {
11
- const h = l.getAttribute("data-number") || "1", $ = l.getAttribute("data-type") || "CART_ITEMS";
12
- l.querySelectorAll(`[product-attr="${r}"]`).forEach((t) => {
13
- var F, I, w;
14
- const T = t.getAttribute("data-type") || $, f = t.getAttribute("data-number") || h, d = u[T];
15
- if (d)
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 = d.DEFAULT, a = d.ATTR;
27
+ const i = A.DEFAULT, s = A.ATTR;
22
28
  if (i && e.src) {
23
29
  const o = e.src;
24
- i.some((E) => {
25
- const s = E.split("/").pop() || "", g = o.split("/").pop() || "";
26
- return o.includes(E) || o.includes(s) || g === s;
27
- }) && (e.src = `{{${a}_${f}}}`);
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 = (I = (F = R.name) == null ? void 0 : F[T]) == null ? void 0 : I.ATTR;
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 = (w = R.itemLink) == null ? void 0 : w[T];
37
+ const o = (D = C.itemLink) == null ? void 0 : D[_];
32
38
  if (o) {
33
- const A = o.HREF, E = o.DEFAULT_HREF || "#!", s = c.href;
34
- (s === "#" || s === "" || s.endsWith("#!") || s.endsWith(E) || s === `${window.location.href}${E}` || !s || s === window.location.href) && (c.href = `{{${A}_${f}}}`);
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 = d, c = e.ATTR, i = e.DEFAULT_HREF || "#!", a = e.HREF;
41
- t.textContent && (t.innerHTML = C(t, `{{${c}_${f}}}`));
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 && a) {
44
- const o = n.href, A = `${window.location.href}${i}`;
45
- (o === A || o.endsWith(i)) && (n.href = `{{${a}_${f}}}`);
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 = d, c = t.getAttribute("data-formated"), i = t.getAttribute("data-single_price"), a = c === "true", n = i === "true", o = t.getAttribute("data-curency") || "before";
52
- let A;
53
- n ? A = a ? e.SINGLE_PRICE_FORMATTED : e.SINGLE_PRICE : A = a ? e.PRICE_FORMATTED : e.PRICE;
54
- const E = e.CURRENCY;
55
- let s = `{{${A}_${f}}}`;
56
- const g = (t.getAttribute("data-currency_symbol") || "").trim(), N = g !== "" && g !== O.productPriceCurrencySymbolControlValue;
57
- let m = "";
58
- N ? m = g : E && (m = `{{${E}_${f}}}`), m && (s = o === "after" ? `${s} ${m}` : `${m} ${s}`), t.innerHTML = C(t, s);
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 = d, c = e.ATTR, i = e.DEFAULT;
63
- t.textContent && t.textContent.trim() === i && (t.innerHTML = C(t, `{{${c}_${f}}}`));
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 = d, c = e.HREF, i = e.DEFAULT_HREF || "#!", a = t.tagName === "A" ? t : t.querySelector("a");
68
- if (a) {
69
- const n = a.href || "", o = `${window.location.href}${i}`;
70
- (n === "" || n === "#" || n === o || n.endsWith(i) || n.endsWith("#!") || n === window.location.href) && (a.href = `{{${c}_${f}}}`);
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 = d, c = e.HREF, i = e.DEFAULT_HREF || "#!", a = t;
76
- if (a.href) {
77
- const n = a.href, o = `${window.location.href}${i}`;
78
- (n === o || n.endsWith(i)) && (a.href = `{{${c}_${f}}}`);
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 d) {
84
- const e = d.ATTR;
85
- t.textContent && (t.innerHTML = C(t, `{{${e}_${f}}}`));
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 k = H.match(/<!DOCTYPE[^>]*>/i), P = k ? `${k[0]}
94
- ` : "", D = b.querySelectorAll(".ins-product-td"), M = [];
95
- D.forEach((r) => {
96
- const u = r.getAttribute("data-type") || "CART_ITEMS", p = r.getAttribute("data-number") || "1", l = r.outerHTML;
97
- M.push({
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: l,
100
- type: u,
101
- number: p
105
+ outerHtml: u,
106
+ type: l,
107
+ number: d
102
108
  });
103
109
  });
104
- let _ = P + b.documentElement.outerHTML;
105
- M.reverse().forEach(({ outerHtml: r, type: u, number: p }) => {
106
- let l = "";
107
- switch (u) {
108
- case "CART_ITEMS":
109
- l = "ins_apr_total_product_kind";
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 x = b.querySelectorAll('[product-attr="originalPrice"][data-type="CART_ITEMS"]'), S = [];
124
- return x.forEach((r) => {
125
- var $;
126
- const u = r.getAttribute("data-number"), p = r.getAttribute("data-type");
127
- if (!u || p !== "CART_ITEMS" || (($ = r.closest(".ins-product-td")) == null ? void 0 : $.getAttribute("data-nodup")) === "false")
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
- }), _.replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
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("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
141
142
  }
142
143
  export {
143
- Y as pairProductVariables
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.14.1-beta.9ad6513",
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",