@useinsider/guido 3.9.0 → 3.9.1-beta.65a8ac1

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,55 +1,59 @@
1
- import { useEmailTemplateApplier as m, resetEmailTemplateApplier as w } from "./useEmailTemplateApplier.js";
2
- import { useToaster as _ } from "./useToaster.js";
3
- import { useTranslations as I } from "./useTranslations.js";
1
+ import { useEmailTemplateApplier as w, resetEmailTemplateApplier as _ } from "./useEmailTemplateApplier.js";
2
+ import { useToaster as I } from "./useToaster.js";
3
+ import { useTranslations as P } from "./useTranslations.js";
4
4
  import { ToasterTypeOptions as S } from "../enums/toaster.js";
5
5
  import { getActivePinia as v } from "pinia";
6
6
  import { watch as B, onUnmounted as D } from "vue";
7
- const P = "email_template", x = "chat", L = "guido:debug:ai", M = () => {
7
+ const x = "email_template", L = "chat", M = "guido:debug:ai", R = () => {
8
8
  if (typeof window > "u")
9
9
  return !1;
10
10
  try {
11
- return window.localStorage.getItem(L) === "1";
11
+ return window.localStorage.getItem(M) === "1";
12
12
  } catch {
13
13
  return !1;
14
14
  }
15
- }, O = () => {
16
- const a = v();
17
- if (!a)
15
+ }, H = () => {
16
+ const c = v();
17
+ if (!c)
18
18
  return;
19
- const l = a._s, p = l == null ? void 0 : l.get(x);
19
+ const l = c._s, p = l == null ? void 0 : l.get(L);
20
20
  if (!p)
21
21
  return;
22
- const { applyTemplate: d, applyTemplateDebounced: f } = m(), { showToaster: T } = _(), h = I(), A = (e, t) => {
23
- const r = h(e);
24
- return r === e ? t : r;
25
- }, i = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Set(), u = M(), E = (e, t) => {
26
- u && console.debug(`[guido:cortex] msg=${e ?? "?"} type=${(t == null ? void 0 : t.type) ?? "?"}`, t);
27
- }, y = (e) => {
28
- if (e.blueprintType !== P)
22
+ const { markPending: d, applyTemplate: f, applyTemplateDebounced: T } = w(), { showToaster: h } = I(), y = P(), A = (r, t) => {
23
+ const e = y(r);
24
+ return e === r ? t : e;
25
+ }, i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set(), u = R(), E = (r, t) => {
26
+ u && console.debug(`[guido:cortex] msg=${r ?? "?"} type=${(t == null ? void 0 : t.type) ?? "?"}`, t);
27
+ }, b = (r) => {
28
+ if (r.blueprintType !== x)
29
29
  return;
30
- const t = e.blueprintId, r = e.blueprintData;
31
- if (!t || !(r != null && r.html))
30
+ const t = r.blueprintId, e = r.blueprintData;
31
+ if (!t || !(e != null && e.html))
32
32
  return;
33
+ if (!r.applyRequested) {
34
+ d(t);
35
+ return;
36
+ }
33
37
  const o = i.get(t);
34
- o === void 0 ? (i.set(t, r.html), d(t, r)) : o !== r.html && (i.set(t, r.html), f(t, r));
35
- }, s = (e) => e === void 0 || c.has(e) ? !1 : (c.add(e), T({
38
+ o === void 0 ? (i.set(t, e.html), f(t, e)) : o !== e.html && (i.set(t, e.html), T(t, e));
39
+ }, s = (r) => r === void 0 || a.has(r) ? !1 : (a.add(r), h({
36
40
  type: S.Alert,
37
41
  message: A("newsletter.ai-template-failed", "AI couldn't generate the template. Please try again.")
38
- }), !0), b = B(
42
+ }), !0), m = B(
39
43
  () => p.messages,
40
- (e) => {
41
- Array.isArray(e) && e.forEach((t) => {
42
- const r = t == null ? void 0 : t.id;
43
- (t == null ? void 0 : t.isError) === !0 && s(r) && u && console.debug(`[guido:cortex] message-level error id=${r}`, t);
44
+ (r) => {
45
+ Array.isArray(r) && r.forEach((t) => {
46
+ const e = t == null ? void 0 : t.id;
47
+ (t == null ? void 0 : t.isError) === !0 && s(e) && u && console.debug(`[guido:cortex] message-level error id=${e}`, t);
44
48
  const o = t == null ? void 0 : t.segments;
45
49
  Array.isArray(o) && o.forEach((n) => {
46
50
  if (n)
47
- switch (E(r, n), n.type) {
51
+ switch (E(e, n), n.type) {
48
52
  case "blueprint":
49
- y(n);
53
+ b(n);
50
54
  break;
51
55
  case "error":
52
- s(r);
56
+ s(e);
53
57
  break;
54
58
  }
55
59
  });
@@ -58,9 +62,9 @@ const P = "email_template", x = "chat", L = "guido:debug:ai", M = () => {
58
62
  { deep: !0, immediate: !0 }
59
63
  );
60
64
  D(() => {
61
- b(), i.clear(), c.clear(), w();
65
+ m(), i.clear(), a.clear(), _();
62
66
  });
63
67
  };
64
68
  export {
65
- O as useCortexBlueprintBridge
69
+ H as useCortexBlueprintBridge
66
70
  };
@@ -1,10 +1,12 @@
1
- import { useActionsApi as u } from "./useActionsApi.js";
2
- import { useToaster as T } from "./useToaster.js";
3
- import { useTranslations as f } from "./useTranslations.js";
1
+ import { useActionsApi as T } from "./useActionsApi.js";
2
+ import { useToaster as f } from "./useToaster.js";
3
+ import { useTranslations as y } from "./useTranslations.js";
4
4
  import { ToasterTypeOptions as n } from "../enums/toaster.js";
5
- import { ref as y } from "vue";
6
- const h = 250, s = y({}), o = {}, j = () => {
7
- const { updateHtmlAndCss: l } = u(), { showToaster: r } = T(), i = f(), c = (e, t, p) => {
5
+ import { ref as v } from "vue";
6
+ const h = 250, s = v({}), o = {}, j = () => {
7
+ const { updateHtmlAndCss: l } = T(), { showToaster: r } = f(), i = y(), u = (e) => {
8
+ s.value[e] === void 0 && (s.value = { ...s.value, [e]: "pending" });
9
+ }, c = (e, t, p) => {
8
10
  s.value = { ...s.value, [e]: "applying" };
9
11
  try {
10
12
  l(t, p), s.value = { ...s.value, [e]: "applied" }, r({
@@ -21,7 +23,7 @@ const h = 250, s = y({}), o = {}, j = () => {
21
23
  const t = o[e];
22
24
  t && (clearTimeout(t), delete o[e]);
23
25
  };
24
- return { applyStatus: s, applyTemplate: (e, t) => {
26
+ return { applyStatus: s, markPending: u, applyTemplate: (e, t) => {
25
27
  t.html && (m(e), c(e, t.html, t.css ?? ""));
26
28
  }, applyTemplateDebounced: (e, t) => {
27
29
  if (!t.html)
@@ -32,10 +34,10 @@ const h = 250, s = y({}), o = {}, j = () => {
32
34
  delete o[e], c(e, p, a);
33
35
  }, h);
34
36
  } };
35
- }, w = () => {
37
+ }, k = () => {
36
38
  Object.values(o).forEach(clearTimeout), Object.keys(o).forEach((l) => delete o[l]), s.value = {};
37
39
  };
38
40
  export {
39
- w as resetEmailTemplateApplier,
41
+ k as resetEmailTemplateApplier,
40
42
  j as useEmailTemplateApplier
41
43
  };
@@ -1,181 +1,189 @@
1
- import { useConfig as _ } from "../../../composables/useConfig.js";
2
- import { useRecommendation as g } from "../../../composables/useRecommendation.js";
3
- import { CSS_CLASS_RECO_BUTTON as q } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
4
- import { useRecommendationExtensionStore as C } from "../../../extensions/Blocks/Recommendation/store/recommendation.js";
5
- import { isIgnoredRecommendationBlock as w } from "./recommendationIgnoreUtils.js";
6
- function b(e, n, t, o, c = "") {
7
- const i = `{{${c}${e}_${n}_${t}}}`, r = `{{${c}${e}_${n}_currency}}`;
8
- return o === "before" ? `${r} ${i}` : `${i} ${r}`;
1
+ import { useConfig as q } from "../../../composables/useConfig.js";
2
+ import { useRecommendation as C } from "../../../composables/useRecommendation.js";
3
+ import { CSS_CLASS_RECO_BUTTON as E } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
4
+ import { useRecommendationExtensionStore as w } from "../../../extensions/Blocks/Recommendation/store/recommendation.js";
5
+ import { isIgnoredRecommendationBlock as P } from "./recommendationIgnoreUtils.js";
6
+ function f(t, o, e, n, s = "") {
7
+ const i = `{{${s}${t}_${o}_${e}}}`, r = `{{${s}${t}_${o}_currency}}`;
8
+ return n === "before" ? `${r} ${i}` : `${i} ${r}`;
9
9
  }
10
- function m(e) {
11
- let n = e;
12
- for (; n.children.length === 1; )
13
- [n] = n.children;
14
- return n;
10
+ function m(t) {
11
+ let o = t;
12
+ for (; o.children.length === 1; )
13
+ [o] = o.children;
14
+ return o;
15
15
  }
16
- function h(e, n, t, o, c, i) {
17
- switch (n) {
16
+ function h(t, o, e, n, s, i) {
17
+ switch (o) {
18
18
  case "productImage": {
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));
19
+ const r = t.querySelector("img");
20
+ r && (r.setAttribute("src", `{{${i}${e}_${n}_image_url}}`), r.setAttribute("alt", `{{${i}${e}_${n}_name}}`));
21
+ const c = t.querySelector("a");
22
+ c && (c.setAttribute("href", `{{${i}${e}_${n}_url}}`), c.classList.add(E));
23
23
  break;
24
24
  }
25
25
  case "productName": {
26
- const r = e.querySelector("p");
27
- r && (m(r).textContent = `{{${i}${t}_${o}_name}}`);
26
+ const r = t.querySelector("p");
27
+ r && (m(r).textContent = `{{${i}${e}_${n}_name}}`);
28
28
  break;
29
29
  }
30
30
  case "productPrice": {
31
- const r = e.querySelector(".product-price p") ?? e.querySelector("p");
32
- r && (m(r).textContent = b(
33
- t,
34
- o,
31
+ const r = t.querySelector(".product-price p") ?? t.querySelector("p");
32
+ r && (m(r).textContent = f(
33
+ e,
34
+ n,
35
35
  "price",
36
- c,
36
+ s,
37
37
  i
38
38
  ));
39
- const s = e.querySelector(".product-old-price p");
40
- s && (m(s).textContent = b(
41
- t,
42
- o,
39
+ const c = t.querySelector(".product-old-price p");
40
+ c && (m(c).textContent = f(
41
+ e,
42
+ n,
43
43
  "original_price",
44
- c,
44
+ s,
45
45
  i
46
46
  ));
47
47
  break;
48
48
  }
49
49
  case "productOldPrice": {
50
- const r = e.querySelector("p");
51
- r && (m(r).textContent = b(
52
- t,
53
- o,
50
+ const r = t.querySelector("p");
51
+ r && (m(r).textContent = f(
52
+ e,
53
+ n,
54
54
  "original_price",
55
- c,
55
+ s,
56
56
  i
57
57
  ));
58
58
  break;
59
59
  }
60
60
  case "productButton": {
61
- const r = e.querySelector("a");
62
- r && r.setAttribute("href", `{{${i}${t}_${o}_url}}`);
61
+ const r = t.querySelector("a");
62
+ r && r.setAttribute("href", `{{${i}${e}_${n}_url}}`);
63
63
  break;
64
64
  }
65
65
  case "productOmnibusPrice": {
66
- const r = e.querySelector(".omnibus-price-value");
66
+ const r = t.querySelector(".omnibus-price-value");
67
67
  if (r) {
68
- r.textContent = `{{${i}${t}_${o}_omnibus_price}}`;
69
- const s = r.closest("p");
70
- s && (s.setAttribute("product-attr", "omnibus_price"), s.setAttribute("composition", "true"));
68
+ r.textContent = `{{${i}${e}_${n}_omnibus_price}}`;
69
+ const c = r.closest("p");
70
+ c && (c.setAttribute("product-attr", "omnibus_price"), c.setAttribute("composition", "true"));
71
71
  }
72
72
  break;
73
73
  }
74
74
  case "productOmnibusDiscount": {
75
- const r = e.querySelector(".omnibus-discount-value");
75
+ const r = t.querySelector(".omnibus-discount-value");
76
76
  if (r) {
77
- r.textContent = `{{${i}${t}_${o}_omnibus_discount}}`;
78
- const s = r.closest("p");
79
- s && (s.setAttribute("product-attr", "omnibus_discount"), s.setAttribute("composition", "true"));
77
+ r.textContent = `{{${i}${e}_${n}_omnibus_discount}}`;
78
+ const c = r.closest("p");
79
+ c && (c.setAttribute("product-attr", "omnibus_discount"), c.setAttribute("composition", "true"));
80
80
  }
81
81
  break;
82
82
  }
83
83
  default: {
84
- const r = e.getAttribute("product-attr") ? e : e.querySelector("[product-attr]");
84
+ const r = t.getAttribute("product-attr") ? t : t.querySelector("[product-attr]");
85
85
  if (r) {
86
- const s = r.getAttribute("product-attr"), a = r.querySelector("p");
87
- a && (m(a).textContent = `{{${i}${t}_${o}_${s}}}`);
86
+ const c = r.getAttribute("product-attr"), l = r.querySelector("p");
87
+ l && (m(l).textContent = `{{${i}${e}_${n}_${c}}}`);
88
88
  }
89
89
  break;
90
90
  }
91
91
  }
92
92
  }
93
- function E(e, n, t, o) {
94
- e.querySelectorAll(".recommendation-product-row").forEach((i, r) => {
95
- i.querySelectorAll("[data-attribute-type]").forEach((a) => {
96
- const u = a.getAttribute("data-attribute-type") || "", p = a.querySelectorAll(".attribute-cell");
97
- p.length > 0 ? p.forEach((l) => {
98
- h(l, u, n, r, t, o);
99
- }) : h(a, u, n, r, t, o);
93
+ function R(t, o, e, n) {
94
+ t.querySelectorAll(".recommendation-product-row").forEach((i, r) => {
95
+ i.querySelectorAll("[data-attribute-type]").forEach((l) => {
96
+ const u = l.getAttribute("data-attribute-type") || "", p = l.querySelectorAll(".attribute-cell");
97
+ p.length > 0 ? p.forEach((a) => {
98
+ h(a, u, o, r, e, n);
99
+ }) : h(l, u, o, r, e, n);
100
100
  });
101
101
  });
102
102
  }
103
- function P(e, n, t, o) {
104
- const c = e.querySelectorAll(".recommendation-product-row");
105
- if (!c.length)
103
+ function W(t, o, e, n) {
104
+ const s = t.querySelectorAll(".recommendation-product-row");
105
+ if (!s.length)
106
106
  return;
107
- const [i] = c, r = i.querySelector("[data-attribute-type]"), s = r ? r.querySelectorAll(".attribute-cell").length : 1;
108
- c.forEach((a, u) => {
109
- a.querySelectorAll("[data-attribute-type]").forEach((l) => {
110
- const d = l.getAttribute("data-attribute-type") || "";
111
- l.querySelectorAll(".attribute-cell").forEach((A, $) => {
112
- const S = u * s + $;
113
- h(A, d, n, S, t, o);
107
+ const [i] = s, r = i.querySelector("[data-attribute-type]"), c = r ? r.querySelectorAll(".attribute-cell").length : 1;
108
+ s.forEach((l, u) => {
109
+ l.querySelectorAll("[data-attribute-type]").forEach((a) => {
110
+ const d = a.getAttribute("data-attribute-type") || "";
111
+ a.querySelectorAll(".attribute-cell").forEach((S, _) => {
112
+ const g = u * c + _;
113
+ h(S, d, o, g, e, n);
114
114
  });
115
115
  });
116
116
  });
117
117
  }
118
- function R(e, n, t, o) {
119
- e.querySelectorAll(".ins-recommendation-product-container").forEach((i) => {
120
- P(i, n, t, o);
118
+ function v(t, o, e, n) {
119
+ t.querySelectorAll(".ins-recommendation-product-container").forEach((i) => {
120
+ W(i, o, e, n);
121
121
  });
122
122
  }
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);
123
+ function O(t, o, e) {
124
+ const n = t.getAttribute("data-layout") || "grid", s = t.getAttribute("currency-alignment") || "after";
125
+ n === "list" ? R(t, o, s, e) : v(t, o, s, e);
126
126
  }
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;
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;
130
130
  }
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");
136
- if (o && o.endsWith("%") && parseFloat(o) < 100)
137
- return t;
138
- }
139
- t = t.parentElement;
131
+ function A(t) {
132
+ const o = t.trim();
133
+ return o.endsWith("%") ? parseFloat(o) < 100 : /^\d+(?:\.\d+)?(?:px)?$/.test(o) && parseInt(o) > 0;
134
+ }
135
+ function $(t) {
136
+ const o = t.getAttribute("width");
137
+ if (o && A(o))
138
+ return o.trim();
139
+ const e = (t.getAttribute("style") || "").match(/(?:^|[;\s])width\s*:\s*(\d+(?:\.\d+)?(?:px|%))/i);
140
+ return e && A(e[1]) ? e[1] : null;
141
+ }
142
+ function T(t, o) {
143
+ let e = t.parentElement;
144
+ for (; e && e !== o; ) {
145
+ if (e.tagName === "TD" && $(e))
146
+ return e;
147
+ e = e.parentElement;
140
148
  }
141
149
  return null;
142
150
  }
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) => {
151
+ function M(t) {
152
+ const o = t.getAttribute("style") || "", e = b(o, "width", 600), n = b(o, "padding", 0) * 2, s = Math.max(0, e - n);
153
+ s !== 0 && t.querySelectorAll("img.adapt-img").forEach((i) => {
146
154
  if (i.hasAttribute("width"))
147
155
  return;
148
- const r = T(i, e);
156
+ const r = T(i, t);
149
157
  if (!r)
150
158
  return;
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);
152
- i.setAttribute("width", String(l));
153
- const d = i.getAttribute("style") || "";
154
- if (!/\bwidth\s*:\s*\d/i.test(d)) {
155
- const f = d && !d.trim().endsWith(";") ? "; " : "";
156
- i.setAttribute("style", `${d}${f}width: ${l}px`);
159
+ const c = $(r), l = b(r.getAttribute("style") || "", "padding", 0) * 2, u = c.endsWith("%") ? Math.floor(s * parseFloat(c) / 100) : parseInt(c), p = Math.max(1, u - l);
160
+ i.setAttribute("width", String(p));
161
+ const a = i.getAttribute("style") || "";
162
+ if (!/\bwidth\s*:\s*\d/i.test(a)) {
163
+ const d = a && !a.trim().endsWith(";") ? "; " : "";
164
+ i.setAttribute("style", `${a}${d}width: ${p}px`);
157
165
  }
158
166
  });
159
167
  }
160
- function W(e, n) {
161
- const t = e.match(/<!DOCTYPE[^>]*>/i);
162
- return (t ? `${t[0]}
163
- ` : "") + n.documentElement.outerHTML;
168
+ function B(t, o) {
169
+ const e = t.match(/<!DOCTYPE[^>]*>/i);
170
+ return (e ? `${e[0]}
171
+ ` : "") + o.documentElement.outerHTML;
164
172
  }
165
- function F(e) {
166
- const n = e.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), t = new DOMParser().parseFromString(n, "text/html"), o = t.querySelectorAll(".recommendation-block-v2");
167
- if (!o.length)
168
- return e;
169
- const { buildCampaignUrl: c } = g(), i = C();
173
+ function G(t) {
174
+ const o = t.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), e = new DOMParser().parseFromString(o, "text/html"), n = e.querySelectorAll(".recommendation-block-v2");
175
+ if (!n.length)
176
+ return t;
177
+ const { buildCampaignUrl: s } = C(), i = w();
170
178
  i.recommendationCampaignUrls = {};
171
- const { isFeatureEnabled: r } = _(), s = r("liquidSyntax") ? "reco_" : "";
172
- return o.forEach((u) => {
173
- var l, d;
179
+ const { isFeatureEnabled: r } = q(), c = r("liquidSyntax") ? "reco_" : "";
180
+ return n.forEach((u) => {
181
+ var a, d;
174
182
  const p = u.getAttribute("recommendation-id");
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("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
183
+ p && ((a = u.parentNode) == null || a.insertBefore(e.createComment("REC_START"), u), (d = u.parentNode) == null || d.insertBefore(e.createComment("REC_END"), u.nextSibling), u.querySelectorAll('[data-visibility="0"]').forEach((y) => y.remove()), s(p), P(u) || O(u, p, c), M(u));
184
+ }), B(o, e).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
177
185
  }
178
186
  export {
179
- b as formatPriceVariable,
180
- F as prepareRecommendationBlocks
187
+ f as formatPriceVariable,
188
+ G as prepareRecommendationBlocks
181
189
  };