@useinsider/guido 3.21.0-beta.c9edf3a → 3.21.0-beta.db22471

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,85 +1,84 @@
1
- import { useActionsApi as q } from "./useActionsApi.js";
2
- import { useConfig as O } from "./useConfig.js";
3
- import { useEditorLock as D } from "./useEditorLock.js";
4
- import { useSaveStart as F, useSaveComplete as j } from "./useGuidoActions.js";
5
- import { useSaveValidation as z } from "./useSaveValidation.js";
6
- import { useSaveValidationRollout as G } from "./useSaveValidationRollout.js";
7
- import { useSyncModuleExtractor as I } from "./useSyncModuleExtractor.js";
8
- import { ToasterTypeOptions as J } from "../enums/toaster.js";
9
- import { useStripoApi as K } from "../services/stripoApi.js";
10
- import { useConfigStore as N } from "../stores/config.js";
11
- import { useDynamicContentStore as Q } from "../stores/dynamic-content.js";
12
- import { useSaveValidationStore as X } from "../stores/save-validation.js";
13
- import { useTemplatePreparation as Y, getHtmlReferencedUnsubscribePages as Z } from "../utils/templatePreparation.js";
14
- import { useAllowlist as _ } from "./useAllowlist.js";
15
- import { useHtmlValidator as $ } from "./useHtmlValidator.js";
16
- import { useToaster as tt } from "./useToaster.js";
17
- import { useCouponBlockValidator as et } from "./validators/useCouponBlockValidator.js";
18
- import { useHtmlDocumentCountValidator as ot } from "./validators/useHtmlDocumentCountValidator.js";
19
- import { useLiquidValidator as it } from "./validators/useLiquidValidator.js";
20
- import { useSyncModuleBlockValidator as rt } from "./validators/useSyncModuleBlockValidator.js";
1
+ import { useActionsApi as R } from "./useActionsApi.js";
2
+ import { useConfig as q } from "./useConfig.js";
3
+ import { useEditorLock as O } from "./useEditorLock.js";
4
+ import { useSaveStart as D, useSaveComplete as F } from "./useGuidoActions.js";
5
+ import { useSaveValidation as j } from "./useSaveValidation.js";
6
+ import { useSaveValidationRollout as z } from "./useSaveValidationRollout.js";
7
+ import { useSyncModuleExtractor as G } from "./useSyncModuleExtractor.js";
8
+ import { ToasterTypeOptions as I } from "../enums/toaster.js";
9
+ import { useStripoApi as J } from "../services/stripoApi.js";
10
+ import { useConfigStore as K } from "../stores/config.js";
11
+ import { useDynamicContentStore as N } from "../stores/dynamic-content.js";
12
+ import { useSaveValidationStore as Q } from "../stores/save-validation.js";
13
+ import { useTemplatePreparation as X, getHtmlReferencedUnsubscribePages as Y } from "../utils/templatePreparation.js";
14
+ import { useAllowlist as Z } from "./useAllowlist.js";
15
+ import { useHtmlValidator as _ } from "./useHtmlValidator.js";
16
+ import { useToaster as $ } from "./useToaster.js";
17
+ import { useCouponBlockValidator as tt } from "./validators/useCouponBlockValidator.js";
18
+ import { useLiquidValidator as et } from "./validators/useLiquidValidator.js";
19
+ import { useSyncModuleBlockValidator as ot } from "./validators/useSyncModuleBlockValidator.js";
21
20
  import { useUnsubscribeBlockValidator as st } from "./validators/useUnsubscribeBlockValidator.js";
22
- const Pt = () => {
23
- const a = F(), p = j(), { validateHtml: S } = $(), { validateLiquidSyntax: w } = it(), { validateCouponBlockTags: y } = et(), { validateUnsubscribeBlockUniqueness: H, validateUnsubscribeBlockHasTemplate: E } = st(), { validateSyncModuleBlocks: n } = rt(), { validateSingleHtmlDocument: l } = ot(), { callbacks: s, isFeatureEnabled: d } = O(), { extractSyncModuleData: b } = I(), { setSyncModuleUnsubscriptionPages: g } = K(), { editorSave: V, getTemplateData: x } = q(), { showToaster: C } = tt(), { getBlockedDomains: k, resolveToast: B } = _(), { prepareTemplateDetails: f } = Y(), { collectSaveValidationErrors: h } = z(), { isEnabled: T } = G(), P = X(), L = Q(), v = N(), { runExclusive: c } = D(), u = async (t, e, o) => {
21
+ const Bt = () => {
22
+ const a = D(), p = F(), { validateHtml: v } = _(), { validateLiquidSyntax: S } = et(), { validateCouponBlockTags: y } = tt(), { validateUnsubscribeBlockUniqueness: w, validateUnsubscribeBlockHasTemplate: E } = st(), { validateSyncModuleBlocks: n } = ot(), { callbacks: r, isFeatureEnabled: d } = q(), { extractSyncModuleData: b } = G(), { setSyncModuleUnsubscriptionPages: g } = J(), { editorSave: H, getTemplateData: V } = R(), { showToaster: x } = $(), { getBlockedDomains: k, resolveToast: C } = Z(), { prepareTemplateDetails: m } = X(), { collectSaveValidationErrors: B } = j(), { isEnabled: h } = z(), T = Q(), P = N(), f = K(), { runExclusive: l } = O(), c = async (t, e, o) => {
24
23
  if (!d("allowlistEnabled"))
25
24
  return !1;
26
- const r = await k(t, e);
27
- if (!r.length)
25
+ const i = await k(t, e);
26
+ if (!i.length)
28
27
  return !1;
29
28
  if (!o) {
30
- const i = await B(r);
31
- i != null && i.message && C({
32
- type: J.Warning,
33
- message: i.message,
34
- actionButton: i.actionButton
29
+ const s = await C(i);
30
+ s != null && s.message && x({
31
+ type: I.Warning,
32
+ message: s.message,
33
+ actionButton: s.actionButton
35
34
  });
36
35
  }
37
36
  return !0;
38
- }, U = async (t) => !y(t.compiledHtml) || !H(t.compiledHtml) || !E(t.compiledHtml) ? !1 : d("liquidSyntax") ? w(t.compiledHtml) : S(t.compiledHtml, t.dynamicContentList, !0), m = async (t, e) => {
39
- if (!await V())
37
+ }, L = async (t) => !y(t.compiledHtml) || !w(t.compiledHtml) || !E(t.compiledHtml) ? !1 : d("liquidSyntax") ? S(t.compiledHtml) : v(t.compiledHtml, t.dynamicContentList, !0), u = async (t, e) => {
38
+ if (!await H())
40
39
  return;
41
- const { unsubscribePayload: r, stripoModules: i } = b(t.rawHtml);
42
- if (await g(r), t.modules = i, !e.suppress) {
43
- const R = e.blankCompiled ? { compiledHtml: "", ampHtml: "" } : {};
44
- p({ ...t, ...R, silent: e.silent });
40
+ const { unsubscribePayload: i, stripoModules: s } = b(t.rawHtml);
41
+ if (await g(i), t.modules = s, !e.suppress) {
42
+ const W = e.blankCompiled ? { compiledHtml: "", ampHtml: "" } : {};
43
+ p({ ...t, ...W, silent: e.silent });
45
44
  }
46
45
  return t;
47
- }, A = async (t, e) => {
48
- var r;
46
+ }, U = async (t, e) => {
47
+ var i;
49
48
  a();
50
- const o = await f();
51
- if (l(o.rawHtml, e) && n(o.rawHtml, e)) {
52
- if (T.value && !e) {
53
- const i = await h(
49
+ const o = await m();
50
+ if (n(o.rawHtml, e)) {
51
+ if (h.value && !e) {
52
+ const s = await B(
54
53
  o.compiledHtml,
55
54
  o.dynamicContentList
56
55
  );
57
- if (i.length) {
58
- P.open(i, "save");
56
+ if (s.length) {
57
+ T.open(s, "save");
59
58
  return;
60
59
  }
61
- } else if (!await U(o))
60
+ } else if (!await L(o))
62
61
  return;
63
- if (!((r = s.value) != null && r.externalValidation && !await s.value.externalValidation(o)) && !await u(o.compiledHtml, o.css, e))
64
- return m(o, { silent: e, suppress: t });
62
+ if (!((i = r.value) != null && i.externalValidation && !await r.value.externalValidation(o)) && !await c(o.compiledHtml, o.css, e))
63
+ return u(o, { silent: e, suppress: t });
65
64
  }
66
- }, M = async () => {
65
+ }, A = async () => {
67
66
  var e;
68
- if (!v.allowSaveWithErrors)
67
+ if (!f.allowSaveWithErrors)
69
68
  return;
70
69
  a();
71
- const t = await f();
72
- if (l(t.rawHtml, !1) && n(t.rawHtml, !1) && !((e = s.value) != null && e.externalValidation && !await s.value.externalValidation(t)) && !await u(t.compiledHtml, t.css, !1))
73
- return m(t, { silent: !1, blankCompiled: !0 });
74
- }, W = async () => {
75
- if (!v.allowSaveWithErrors)
70
+ const t = await m();
71
+ if (n(t.rawHtml, !1) && !((e = r.value) != null && e.externalValidation && !await r.value.externalValidation(t)) && !await c(t.compiledHtml, t.css, !1))
72
+ return u(t, { silent: !1, blankCompiled: !0 });
73
+ }, M = async () => {
74
+ if (!f.allowSaveWithErrors)
76
75
  return;
77
76
  a();
78
- const { html: t, css: e } = await x();
79
- if (!l(t, !0) || !n(t, !0) || await u(t, e, !0))
77
+ const { html: t, css: e } = await V();
78
+ if (!n(t, !0) || await c(t, e, !0))
80
79
  return;
81
- const o = Z(t), r = {
82
- dynamicContentList: L.getSelectedDynamicContentList,
80
+ const o = Y(t), i = {
81
+ dynamicContentList: P.getSelectedDynamicContentList,
83
82
  compiledHtml: "",
84
83
  rawHtml: t,
85
84
  css: e,
@@ -93,12 +92,12 @@ const Pt = () => {
93
92
  config: o
94
93
  }
95
94
  };
96
- return m(r, { silent: !0 });
95
+ return u(i, { silent: !0 });
97
96
  };
98
- return { save: (t = !1, e = !1) => c(
99
- () => A(t, e)
100
- ), saveWithErrors: () => c(M), saveRawOnly: () => c(W) };
97
+ return { save: (t = !1, e = !1) => l(
98
+ () => U(t, e)
99
+ ), saveWithErrors: () => l(A), saveRawOnly: () => l(M) };
101
100
  };
102
101
  export {
103
- Pt as useSave
102
+ Bt as useSave
104
103
  };
@@ -7,13 +7,13 @@ function L(t, r, e, o, c = "") {
7
7
  const i = `{{${c}${t}_${r}_${e}}}`, n = `{{${c}${t}_${r}_currency}}`;
8
8
  return o === "before" ? `${n} ${i}` : `${i} ${n}`;
9
9
  }
10
- function _(t) {
10
+ function A(t) {
11
11
  let r = t;
12
12
  for (; r.children.length === 1; )
13
13
  [r] = r.children;
14
14
  return r;
15
15
  }
16
- function A(t, r, e, o, c, i) {
16
+ function y(t, r, e, o, c, i) {
17
17
  switch (r) {
18
18
  case "productImage": {
19
19
  const n = t.querySelector("img");
@@ -24,7 +24,7 @@ function A(t, r, e, o, c, i) {
24
24
  }
25
25
  case "productName": {
26
26
  const n = t.querySelector("p");
27
- n && (_(n).textContent = `{{${i}${e}_${o}_name}}`);
27
+ n && (A(n).textContent = `{{${i}${e}_${o}_name}}`);
28
28
  break;
29
29
  }
30
30
  // Inline mode ("Move to next line" OFF) merges BOTH prices into one row
@@ -32,16 +32,16 @@ function A(t, r, e, o, c, i) {
32
32
  // substitute by cell content, not by the row's anchor (SD-145161).
33
33
  case "productPrice":
34
34
  case "productOldPrice": {
35
- const n = (l, d) => {
36
- l && (_(l).textContent = L(
35
+ const n = (a, l) => {
36
+ a && (A(a).textContent = L(
37
37
  e,
38
38
  o,
39
- d,
39
+ l,
40
40
  c,
41
41
  i
42
42
  ));
43
- }, s = t.querySelector(".product-price p"), a = t.querySelector(".product-old-price p"), u = !s && !a ? t.querySelector("p") : null;
44
- n(s ?? (r === "productPrice" ? u : null), "price"), n(a ?? (r === "productOldPrice" ? u : null), "original_price");
43
+ }, s = t.querySelector(".product-price p"), d = t.querySelector(".product-old-price p"), u = !s && !d ? t.querySelector("p") : null;
44
+ n(s ?? (r === "productPrice" ? u : null), "price"), n(d ?? (r === "productOldPrice" ? u : null), "original_price");
45
45
  break;
46
46
  }
47
47
  case "productButton": {
@@ -70,8 +70,8 @@ function A(t, r, e, o, c, i) {
70
70
  default: {
71
71
  const n = t.getAttribute("product-attr") ? t : t.querySelector("[product-attr]");
72
72
  if (n) {
73
- const s = n.getAttribute("product-attr"), a = n.querySelector("p");
74
- a && (_(a).textContent = `{{${i}${e}_${o}_${s}}}`);
73
+ const s = n.getAttribute("product-attr"), d = n.querySelector("p");
74
+ d && (A(d).textContent = `{{${i}${e}_${o}_${s}}}`);
75
75
  }
76
76
  break;
77
77
  }
@@ -88,54 +88,54 @@ function b(t, r, e, o) {
88
88
  function R(t, r, e) {
89
89
  return b(t, r, 0, e);
90
90
  }
91
- function D(t, r, e, o) {
91
+ function w(t, r, e, o) {
92
92
  if (!t.innerHTML.includes("{{"))
93
93
  return;
94
94
  const { open: c, close: i } = b(t.ownerDocument, r, e, o);
95
95
  t.insertBefore(c, t.firstChild), t.appendChild(i);
96
96
  }
97
- function w(t, r, e, o) {
97
+ function D(t, r, e, o) {
98
98
  var n, s;
99
99
  if (!t.innerHTML.includes("{{"))
100
100
  return;
101
101
  const { open: c, close: i } = b(t.ownerDocument, r, e, o);
102
102
  (n = t.parentNode) == null || n.insertBefore(c, t), (s = t.parentNode) == null || s.insertBefore(i, t.nextSibling);
103
103
  }
104
- function W(t, r, e, o) {
104
+ function v(t, r, e, o) {
105
105
  t.querySelectorAll(".recommendation-product-row").forEach((i, n) => {
106
- i.querySelectorAll("[data-attribute-type]").forEach((a) => {
107
- const u = a.getAttribute("data-attribute-type") || "", l = a.querySelectorAll(".attribute-cell");
108
- l.length > 0 ? l.forEach((d) => {
109
- A(d, u, r, n, e, o);
110
- }) : A(a, u, r, n, e, o);
111
- }), w(i, r, n, o);
106
+ i.querySelectorAll("[data-attribute-type]").forEach((d) => {
107
+ const u = d.getAttribute("data-attribute-type") || "", a = d.querySelectorAll(".attribute-cell");
108
+ a.length > 0 ? a.forEach((l) => {
109
+ y(l, u, r, n, e, o);
110
+ }) : y(d, u, r, n, e, o);
111
+ }), D(i, r, n, o);
112
112
  });
113
113
  }
114
- function v(t, r, e, o) {
114
+ function H(t, r, e, o) {
115
115
  const c = t.querySelectorAll(".recommendation-product-row");
116
116
  if (!c.length)
117
117
  return;
118
118
  const [i] = c, n = i.querySelector("[data-attribute-type]"), s = n ? n.querySelectorAll(".attribute-cell").length : 1;
119
- c.forEach((a, u) => {
120
- a.querySelectorAll("[data-attribute-type]").forEach((d) => {
121
- const p = d.getAttribute("data-attribute-type") || "";
122
- d.querySelectorAll(".attribute-cell").forEach((f, m) => {
123
- const h = u * s + m;
124
- A(f, p, r, h, e, o), D(f, r, h, o);
119
+ c.forEach((d, u) => {
120
+ d.querySelectorAll("[data-attribute-type]").forEach((l) => {
121
+ const p = l.getAttribute("data-attribute-type") || "";
122
+ l.querySelectorAll(".attribute-cell").forEach((f, h) => {
123
+ const S = u * s + h;
124
+ y(f, p, r, S, e, o), w(f, r, S, o);
125
125
  });
126
126
  });
127
127
  });
128
128
  }
129
- function H(t, r, e, o) {
129
+ function W(t, r, e, o) {
130
130
  t.querySelectorAll(".ins-recommendation-product-container").forEach((i) => {
131
- v(i, r, e, o);
131
+ H(i, r, e, o);
132
132
  });
133
133
  }
134
134
  function F(t, r, e) {
135
135
  const o = t.getAttribute("data-layout") || "grid", c = t.getAttribute("currency-alignment") || "after";
136
- o === "list" ? W(t, r, c, e) : H(t, r, c, e);
136
+ o === "list" ? v(t, r, c, e) : W(t, r, c, e);
137
137
  }
138
- function y(t, r, e) {
138
+ function _(t, r, e) {
139
139
  const o = new RegExp(`${r}\\s*:\\s*(\\d+)\\s*px`, "i"), c = t.match(o);
140
140
  return c ? parseInt(c[1]) : e;
141
141
  }
@@ -150,7 +150,7 @@ function C(t) {
150
150
  const e = (t.getAttribute("style") || "").match(/(?:^|[;\s])width\s*:\s*(\d+(?:\.\d+)?(?:px|%))/i);
151
151
  return e && $(e[1]) ? e[1] : null;
152
152
  }
153
- function G(t, r) {
153
+ function x(t, r) {
154
154
  let e = t.parentElement;
155
155
  for (; e && e !== r; ) {
156
156
  if (e.tagName === "TD" && C(e))
@@ -159,35 +159,37 @@ function G(t, r) {
159
159
  }
160
160
  return null;
161
161
  }
162
- function V(t) {
163
- const r = t.getAttribute("style") || "", e = y(r, "width", 600), o = y(r, "padding", 0) * 2, c = Math.max(0, e - o);
162
+ function G(t) {
163
+ const r = t.getAttribute("style") || "", e = _(r, "width", 600), o = _(r, "padding", 0) * 2, c = Math.max(0, e - o);
164
164
  c !== 0 && t.querySelectorAll("img.adapt-img").forEach((i) => {
165
165
  if (i.hasAttribute("width"))
166
166
  return;
167
- const n = G(i, t);
167
+ const n = x(i, t);
168
168
  if (!n)
169
169
  return;
170
- const s = C(n), a = y(n.getAttribute("style") || "", "padding", 0) * 2, u = s.endsWith("%") ? Math.floor(c * parseFloat(s) / 100) : parseInt(s), l = Math.max(1, u - a);
171
- i.setAttribute("width", String(l));
172
- const d = i.getAttribute("style") || "";
173
- if (!/\bwidth\s*:\s*\d/i.test(d)) {
174
- const p = d && !d.trim().endsWith(";") ? "; " : "";
175
- i.setAttribute("style", `${d}${p}width: ${l}px`);
170
+ const s = C(n), d = _(n.getAttribute("style") || "", "padding", 0) * 2, u = s.endsWith("%") ? Math.floor(c * parseFloat(s) / 100) : parseInt(s), a = Math.max(1, u - d), l = i.getAttribute("style") || "", p = /(?:^|[;\s])max-height\s*:\s*(\d+(?:\.\d+)?)px/i.exec(l);
171
+ if (p) {
172
+ i.setAttribute("width", String(Math.max(1, Math.min(a, Math.floor(parseFloat(p[1])))))), i.removeAttribute("height");
173
+ return;
174
+ }
175
+ if (i.setAttribute("width", String(a)), !/\bwidth\s*:\s*\d/i.test(l)) {
176
+ const m = l && !l.trim().endsWith(";") ? "; " : "";
177
+ i.setAttribute("style", `${l}${m}width: ${a}px`);
176
178
  }
177
179
  });
178
180
  }
179
- const E = "MSO_MOBILE_HIDE_START", U = "MSO_MOBILE_HIDE_END";
180
- function X(t, r) {
181
+ const E = "MSO_MOBILE_HIDE_START", V = "MSO_MOBILE_HIDE_END";
182
+ function U(t, r) {
181
183
  t.querySelectorAll(q).forEach((e) => {
182
184
  var i, n;
183
185
  const o = e.querySelector(M);
184
186
  if (!o || o.children.length === 0)
185
187
  return;
186
188
  const c = e.previousSibling;
187
- (c == null ? void 0 : c.nodeType) === Node.COMMENT_NODE && c.data === E || ((i = e.parentNode) == null || i.insertBefore(r.createComment(E), e), (n = e.parentNode) == null || n.insertBefore(r.createComment(U), e.nextSibling));
189
+ (c == null ? void 0 : c.nodeType) === Node.COMMENT_NODE && c.data === E || ((i = e.parentNode) == null || i.insertBefore(r.createComment(E), e), (n = e.parentNode) == null || n.insertBefore(r.createComment(V), e.nextSibling));
188
190
  });
189
191
  }
190
- function j(t, r) {
192
+ function X(t, r) {
191
193
  const e = t.match(/<!DOCTYPE[^>]*>/i);
192
194
  return (e ? `${e[0]}
193
195
  ` : "") + r.documentElement.outerHTML;
@@ -200,17 +202,17 @@ function Q(t) {
200
202
  i.recommendationCampaignUrls = {};
201
203
  const { isFeatureEnabled: n } = g(), s = n("liquidSyntax") ? "reco_" : "";
202
204
  return o.forEach((u) => {
203
- var d, p, S, f;
204
- const l = u.getAttribute("recommendation-id");
205
- if (l) {
206
- if ((d = u.parentNode) == null || d.insertBefore(e.createComment("REC_START"), u), (p = u.parentNode) == null || p.insertBefore(e.createComment("REC_END"), u.nextSibling), u.querySelectorAll('[data-visibility="0"]').forEach((m) => m.remove()), c(l), X(u, e), !T(u)) {
207
- F(u, l, s);
208
- const { open: m, close: h } = R(e, l, s);
209
- (S = u.parentNode) == null || S.insertBefore(m, u), (f = u.parentNode) == null || f.insertBefore(h, u.nextSibling);
205
+ var l, p, m, f;
206
+ const a = u.getAttribute("recommendation-id");
207
+ if (a) {
208
+ if ((l = u.parentNode) == null || l.insertBefore(e.createComment("REC_START"), u), (p = u.parentNode) == null || p.insertBefore(e.createComment("REC_END"), u.nextSibling), u.querySelectorAll('[data-visibility="0"]').forEach((h) => h.remove()), c(a), U(u, e), !T(u)) {
209
+ F(u, a, s);
210
+ const { open: h, close: S } = R(e, a, s);
211
+ (m = u.parentNode) == null || m.insertBefore(h, u), (f = u.parentNode) == null || f.insertBefore(S, u.nextSibling);
210
212
  }
211
- V(u);
213
+ G(u);
212
214
  }
213
- }), j(r, e).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
215
+ }), X(r, e).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
214
216
  }
215
217
  export {
216
218
  L as formatPriceVariable,