@useinsider/guido 3.21.2-beta.bb1c5dd → 3.21.2-beta.c321b5c

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,84 +1,91 @@
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";
20
- import { useUnsubscribeBlockValidator as st } from "./validators/useUnsubscribeBlockValidator.js";
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) => {
23
- if (!d("allowlistEnabled"))
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 st } from "./validators/useSyncModuleBlockValidator.js";
21
+ import { useUnsubscribeBlockValidator as at } from "./validators/useUnsubscribeBlockValidator.js";
22
+ const Pt = () => {
23
+ const n = F(), w = j(), { validateHtml: y } = $(), { validateLiquidSyntax: E } = it(), { validateCouponBlockTags: b } = et(), { validateUnsubscribeBlockUniqueness: g, validateUnsubscribeBlockHasTemplate: H } = at(), { validateSyncModuleBlocks: l } = st(), { validateSingleHtmlDocument: c } = ot(), { callbacks: r, isFeatureEnabled: v } = O(), { extractSyncModuleData: V } = I(), { setSyncModuleUnsubscriptionPages: x } = K(), { editorSave: C, getTemplateData: u } = q(), { showToaster: k } = tt(), { getBlockedDomains: h, resolveToast: B } = _(), { prepareTemplateDetails: p } = Y(), { collectSaveValidationErrors: T } = z(), { isEnabled: P } = G(), L = X(), U = Q(), S = N(), { runExclusive: m } = D(), d = async (t, e, i) => {
24
+ if (!v("allowlistEnabled"))
24
25
  return !1;
25
- const i = await k(t, e);
26
- if (!i.length)
26
+ const o = await h(t, e);
27
+ if (!o.length)
27
28
  return !1;
28
- if (!o) {
29
- const s = await C(i);
30
- s != null && s.message && x({
31
- type: I.Warning,
29
+ if (!i) {
30
+ const s = await B(o);
31
+ s != null && s.message && k({
32
+ type: J.Warning,
32
33
  message: s.message,
33
34
  actionButton: s.actionButton
34
35
  });
35
36
  }
36
37
  return !0;
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())
38
+ }, A = async (t) => !b(t.compiledHtml) || !g(t.compiledHtml) || !H(t.compiledHtml) ? !1 : v("liquidSyntax") ? E(t.compiledHtml) : y(t.compiledHtml, t.dynamicContentList, !0), f = async (t, e) => {
39
+ if (!await C())
39
40
  return;
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 });
41
+ const { unsubscribePayload: o, stripoModules: s } = V(t.rawHtml);
42
+ if (await x(o), t.modules = s, !e.suppress) {
43
+ const a = e.blankCompiled ? { compiledHtml: "", ampHtml: "" } : {};
44
+ w({ ...t, ...a, silent: e.silent });
44
45
  }
45
46
  return t;
46
- }, U = async (t, e) => {
47
- var i;
48
- a();
49
- const o = await m();
50
- if (n(o.rawHtml, e)) {
51
- if (h.value && !e) {
52
- const s = await B(
47
+ }, M = async (t, e) => {
48
+ var s;
49
+ n();
50
+ const i = await u();
51
+ if (!c(i.html, e))
52
+ return;
53
+ const o = await p(i);
54
+ if (l(o.rawHtml, e)) {
55
+ if (P.value && !e) {
56
+ const a = await T(
53
57
  o.compiledHtml,
54
58
  o.dynamicContentList
55
59
  );
56
- if (s.length) {
57
- T.open(s, "save");
60
+ if (a.length) {
61
+ L.open(a, "save");
58
62
  return;
59
63
  }
60
- } else if (!await L(o))
64
+ } else if (!await A(o))
61
65
  return;
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 });
66
+ if (!((s = r.value) != null && s.externalValidation && !await r.value.externalValidation(o)) && !await d(o.compiledHtml, o.css, e))
67
+ return f(o, { silent: e, suppress: t });
64
68
  }
65
- }, A = async () => {
66
- var e;
67
- if (!f.allowSaveWithErrors)
69
+ }, W = async () => {
70
+ var i;
71
+ if (!S.allowSaveWithErrors)
72
+ return;
73
+ n();
74
+ const t = await u();
75
+ if (!c(t.html, !1))
68
76
  return;
69
- a();
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)
77
+ const e = await p(t);
78
+ if (l(e.rawHtml, !1) && !((i = r.value) != null && i.externalValidation && !await r.value.externalValidation(e)) && !await d(e.compiledHtml, e.css, !1))
79
+ return f(e, { silent: !1, blankCompiled: !0 });
80
+ }, R = async () => {
81
+ if (!S.allowSaveWithErrors)
75
82
  return;
76
- a();
77
- const { html: t, css: e } = await V();
78
- if (!n(t, !0) || await c(t, e, !0))
83
+ n();
84
+ const { html: t, css: e } = await u();
85
+ if (!c(t, !0) || !l(t, !0) || await d(t, e, !0))
79
86
  return;
80
- const o = Y(t), i = {
81
- dynamicContentList: P.getSelectedDynamicContentList,
87
+ const i = Z(t), o = {
88
+ dynamicContentList: U.getSelectedDynamicContentList,
82
89
  compiledHtml: "",
83
90
  rawHtml: t,
84
91
  css: e,
@@ -88,16 +95,16 @@ const Bt = () => {
88
95
  // No campaignUrls: hosts overwrite their stored map with any object, and raw HTML can't rebuild it.
89
96
  recommendation: { configs: {} },
90
97
  unsubscribe: {
91
- status: o.length > 0,
92
- config: o
98
+ status: i.length > 0,
99
+ config: i
93
100
  }
94
101
  };
95
- return u(i, { silent: !0 });
102
+ return f(o, { silent: !0 });
96
103
  };
97
- return { save: (t = !1, e = !1) => l(
98
- () => U(t, e)
99
- ), saveWithErrors: () => l(A), saveRawOnly: () => l(M) };
104
+ return { save: (t = !1, e = !1) => m(
105
+ () => M(t, e)
106
+ ), saveWithErrors: () => m(W), saveRawOnly: () => m(R) };
100
107
  };
101
108
  export {
102
- Bt as useSave
109
+ Pt as useSave
103
110
  };
@@ -0,0 +1,22 @@
1
+ import { useToaster as i } from "../useToaster.js";
2
+ import { useTranslations as m } from "../useTranslations.js";
3
+ import { ToasterTypeOptions as c } from "../../enums/toaster.js";
4
+ const u = "newsletter.multiple-html-designs-detected", r = `(?:[^>"']|"[^"]*"|'[^']*')*`, a = "style|script|noscript|xmp|iframe|noembed|noframes|textarea|title", T = /<html(?=[\s>/])/gi, A = new RegExp(
5
+ `<!--[\\s\\S]*?-->|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>|<(${a})(?=[\\s/>])${r}>[\\s\\S]*?</\\1\\s*>|<([a-zA-Z][\\w:-]*)${r}>`,
6
+ "gi"
7
+ ), p = (e) => Array.from(e.matchAll(A)).filter(([, , t]) => (t == null ? void 0 : t.toLowerCase()) === "html").length, g = () => {
8
+ const { showToaster: e } = i(), t = m();
9
+ return { validateSingleHtmlDocument: (o, l = !1) => {
10
+ var n;
11
+ if ((((n = o.match(T)) == null ? void 0 : n.length) ?? 0) < 2)
12
+ return !0;
13
+ const s = p(o);
14
+ return s <= 1 ? !0 : (console.debug("guido:save:blocked", { reason: "multiple-html-documents", htmlRootCount: s }), l || e({
15
+ type: c.Warning,
16
+ message: t(u)
17
+ }), !1);
18
+ } };
19
+ };
20
+ export {
21
+ g as useHtmlDocumentCountValidator
22
+ };
@@ -1,24 +1,26 @@
1
- import { useConfig as w } from "../composables/useConfig.js";
2
- import { useHttp as b } from "../composables/useHttp.js";
3
- import { useToaster as C } from "../composables/useToaster.js";
4
- import { useTranslations as h } from "../composables/useTranslations.js";
5
- import { useLiquidValidator as S } from "../composables/validators/useLiquidValidator.js";
6
- import { EditorType as v } from "../enums/defaults.js";
7
- import { ToasterTypeOptions as x } from "../enums/toaster.js";
8
- import { useRecommendationExtensionStore as E } from "../extensions/Blocks/Recommendation/store/recommendation.js";
9
- import { useSaveAsTemplateStore as N } from "../stores/save-as-template.js";
1
+ import { useActionsApi as h } from "../composables/useActionsApi.js";
2
+ import { useConfig as S } from "../composables/useConfig.js";
3
+ import { useHttp as v } from "../composables/useHttp.js";
4
+ import { useToaster as x } from "../composables/useToaster.js";
5
+ import { useTranslations as A } from "../composables/useTranslations.js";
6
+ import { useHtmlDocumentCountValidator as E } from "../composables/validators/useHtmlDocumentCountValidator.js";
7
+ import { useLiquidValidator as N } from "../composables/validators/useLiquidValidator.js";
8
+ import { EditorType as H } from "../enums/defaults.js";
9
+ import { ToasterTypeOptions as P } from "../enums/toaster.js";
10
+ import { useRecommendationExtensionStore as D } from "../extensions/Blocks/Recommendation/store/recommendation.js";
11
+ import { useSaveAsTemplateStore as L } from "../stores/save-as-template.js";
10
12
  import { base64EncodeWithSpecialChars as r } from "../utils/base64.js";
11
- import { isPlainObject as P } from "../utils/genericUtil.js";
12
- import { useTemplatePreparation as A } from "../utils/templatePreparation.js";
13
- const B = () => {
14
- const { get: n, post: m } = b(), { handleError: o, showToaster: l } = C(), { config: c, isFeatureEnabled: p } = w(), { validateLiquidSyntax: f } = S(), u = h();
13
+ import { isPlainObject as q } from "../utils/genericUtil.js";
14
+ import { useTemplatePreparation as F } from "../utils/templatePreparation.js";
15
+ const Z = () => {
16
+ const { get: n, post: m } = v(), { handleError: s, showToaster: l } = x(), { config: c, isFeatureEnabled: p } = S(), { validateLiquidSyntax: T } = N(), { validateSingleHtmlDocument: w } = E(), { getTemplateData: b } = h(), u = A();
15
17
  return {
16
18
  getCategories: async () => {
17
19
  try {
18
20
  const { data: e = [] } = await n("/newsletter/template-library/get-template-categories");
19
21
  return e;
20
22
  } catch (e) {
21
- return o(e, "Failed to fetch template categories"), [];
23
+ return s(e, "Failed to fetch template categories"), [];
22
24
  }
23
25
  },
24
26
  checkTemplateNameAvailability: async (e) => {
@@ -35,27 +37,30 @@ const B = () => {
35
37
  );
36
38
  return t.toString();
37
39
  } catch (t) {
38
- return o(t, "Failed to create category"), "";
40
+ return s(t, "Failed to create category"), "";
39
41
  }
40
42
  },
41
43
  createTemplate: async () => {
42
44
  var e, t, d, y;
43
45
  try {
44
- const { prepareTemplateDetails: i } = A(), s = N(), a = await i();
45
- if (p("liquidSyntax") && !await f(a.compiledHtml))
46
+ const { prepareTemplateDetails: i } = F(), o = L(), g = await b();
47
+ if (!w(g.html))
46
48
  return !1;
47
- const T = {
48
- name: s.getTemplateName,
49
- categories: s.getSelectedCategoryIds,
49
+ const a = await i(g);
50
+ if (p("liquidSyntax") && !await T(a.compiledHtml))
51
+ return !1;
52
+ const C = {
53
+ name: o.getTemplateName,
54
+ categories: o.getSelectedCategoryIds,
50
55
  productId: ((t = (e = c.value) == null ? void 0 : e.partner) == null ? void 0 : t.productType) || 0,
51
- editorType: v,
56
+ editorType: H,
52
57
  messageType: ((y = (d = c.value) == null ? void 0 : d.partner) == null ? void 0 : y.messageType) || 0,
53
58
  content: r(a.compiledHtml),
54
59
  css: r(a.css),
55
60
  unsubscriptionPreferencePageStatus: !1,
56
61
  unsubscriptionPreferencePages: [],
57
62
  recommendationCampaignUrls: r(
58
- E().recommendationCampaignUrls
63
+ D().recommendationCampaignUrls
59
64
  ),
60
65
  recommendationConfigs: r({}),
61
66
  isGuido: !0,
@@ -67,31 +72,31 @@ const B = () => {
67
72
  css: a.css,
68
73
  dynamicContentList: a.dynamicContentList
69
74
  })
70
- }, { data: g } = await m(
75
+ }, { data: f } = await m(
71
76
  "/newsletter/template-library/create-template",
72
- T
77
+ C
73
78
  );
74
- if (!P(g))
79
+ if (!q(f))
75
80
  throw new Error("Unexpected create-template response");
76
- return g.type === "alert" ? (l({
81
+ return f.type === "alert" ? (l({
77
82
  message: u(
78
83
  "newsletter.template-library-save-alert",
79
- { templateName: s.getTemplateName }
84
+ { templateName: o.getTemplateName }
80
85
  ),
81
- type: x.Error
86
+ type: P.Error
82
87
  }), !1) : (l({
83
88
  message: u(
84
89
  "newsletter.template-library-save-success",
85
- { templateName: s.getTemplateName }
90
+ { templateName: o.getTemplateName }
86
91
  ),
87
92
  type: "success"
88
93
  }), !0);
89
94
  } catch (i) {
90
- return o(i, "Failed to create template"), !1;
95
+ return s(i, "Failed to create template"), !1;
91
96
  }
92
97
  }
93
98
  };
94
99
  };
95
100
  export {
96
- B as useTemplateLibraryApi
101
+ Z as useTemplateLibraryApi
97
102
  };
@@ -0,0 +1,3 @@
1
+ export declare const useHtmlDocumentCountValidator: () => {
2
+ validateSingleHtmlDocument: (rawHtml: string, silent?: boolean) => boolean;
3
+ };
@@ -1,3 +1,4 @@
1
+ import type { TemplateData } from '@@/Types/actions-api';
1
2
  import type { SavedTemplateDetails } from '@@/Types/stripo';
2
3
  /**
3
4
  * Collects every unsubscribe page id referenced by the unsubscribe blocks
@@ -44,7 +45,7 @@ export declare function getHtmlReferencedUnsubscribePages(html: string): number[
44
45
  */
45
46
  declare function hydrateRecommendationStoreFromRawHtml(rawHtml: string): Promise<void>;
46
47
  export declare const useTemplatePreparation: () => {
47
- prepareTemplateDetails: () => Promise<Omit<SavedTemplateDetails, "metadata">>;
48
+ prepareTemplateDetails: (prefetched?: TemplateData) => Promise<Omit<SavedTemplateDetails, "metadata">>;
48
49
  hydrateRecommendationStore: typeof hydrateRecommendationStoreFromRawHtml;
49
50
  };
50
51
  export {};
@@ -1,100 +1,108 @@
1
- import { ITEMS_CURRENCY_ATTR as x, isCustomCurrencySymbol as Y } from "../extensions/Blocks/Items/constants/currency.js";
2
- import { productPairs as w } from "../extensions/Blocks/Items/enums/productEnums.js";
3
- import { escapeReplacement as X } from "../extensions/Blocks/Items/utils/nodeConfigUtils.js";
4
- import { preserveTextStyles as P } from "./preserveTextStyles.js";
5
- import { unwrapProductNameLinks as v } from "./unwrapProductNameLink.js";
6
- const O = {
1
+ import { ITEMS_CURRENCY_ATTR as U, isCustomCurrencySymbol as Y } from "../extensions/Blocks/Items/constants/currency.js";
2
+ import { productPairs as M } from "../extensions/Blocks/Items/enums/productEnums.js";
3
+ import { escapeReplacement as B } from "../extensions/Blocks/Items/utils/nodeConfigUtils.js";
4
+ import { preserveTextStyles as L } from "./preserveTextStyles.js";
5
+ import { unwrapProductNameLinks as X } from "./unwrapProductNameLink.js";
6
+ const q = {
7
7
  CART_ITEMS: "ins_apr",
8
8
  BROWSED_ITEMS: "browsed_item",
9
9
  PURCHASED_ITEMS: "purchased_item"
10
- }, q = (S) => S.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->");
11
- function B(S, y, b) {
12
- let h = y;
13
- for (; h > 0 && /\s/.test(S[h - 1]); )
14
- h -= 1;
15
- return b.some((I) => S.endsWith(I, h));
10
+ }, W = ($) => $.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->");
11
+ function v($, C, A) {
12
+ let d = C;
13
+ for (; d > 0 && /\s/.test($[d - 1]); )
14
+ d -= 1;
15
+ return A.some((E) => $.endsWith(E, d));
16
16
  }
17
- function Z(S) {
18
- const y = q(S), b = new DOMParser().parseFromString(y, "text/html");
19
- v(b);
20
- const h = w.PAIRS_FOR_EXTENSION;
21
- Object.entries(h).forEach(([n, d]) => {
22
- b.querySelectorAll(".ins-product-td").forEach((r) => {
23
- const E = r.getAttribute("data-number") || "1", m = r.getAttribute("data-type") || "CART_ITEMS";
24
- r.querySelectorAll(`[product-attr="${n}"]`).forEach((t) => {
25
- var $, F, D, N;
26
- const g = t.getAttribute("data-type") || m, o = t.getAttribute("data-number") || E, f = d[g];
17
+ const j = /(\s)href=(["'])(?:[^"']*#!|#)?\2/gi;
18
+ function Q($, C) {
19
+ var d;
20
+ const A = $.ownerDocument.createTreeWalker($, NodeFilter.SHOW_COMMENT);
21
+ for (let E = A.nextNode(); E; E = A.nextNode())
22
+ (d = E.nodeValue) != null && d.includes("[if mso]") && (E.nodeValue = E.nodeValue.replace(j, (k, P) => `${P}href="${C}"`));
23
+ }
24
+ function et($) {
25
+ const C = W($), A = new DOMParser().parseFromString(C, "text/html");
26
+ X(A);
27
+ const d = M.PAIRS_FOR_EXTENSION;
28
+ Object.entries(d).forEach(([o, p]) => {
29
+ A.querySelectorAll(".ins-product-td").forEach((r) => {
30
+ const _ = r.getAttribute("data-number") || "1", y = r.getAttribute("data-type") || "CART_ITEMS";
31
+ r.querySelectorAll(`[product-attr="${o}"]`).forEach((t) => {
32
+ var S, I, O, x;
33
+ const m = t.getAttribute("data-type") || y, n = t.getAttribute("data-number") || _, f = p[m];
27
34
  if (f)
28
- switch (n) {
35
+ switch (o) {
29
36
  case "imageSrc": {
30
- let e = null, a = null;
31
- if (t.tagName === "IMG" ? (e = t, a = e.closest("a")) : (e = t.querySelector("img"), a = t.querySelector("a") || t.closest("a")), !e)
37
+ let e = null, s = null;
38
+ if (t.tagName === "IMG" ? (e = t, s = e.closest("a")) : (e = t.querySelector("img"), s = t.querySelector("a") || t.closest("a")), !e)
32
39
  break;
33
40
  const l = f.DEFAULT, c = f.ATTR;
34
41
  if (l && e.src) {
35
- const s = e.src;
36
- l.some((R) => {
37
- const u = R.split("/").pop() || "", H = s.split("/").pop() || "";
38
- return s.includes(R) || s.includes(u) || H === u;
39
- }) && (e.src = `{{${c}_${o}}}`);
42
+ const a = e.src;
43
+ l.some((g) => {
44
+ const u = g.split("/").pop() || "", H = a.split("/").pop() || "";
45
+ return a.includes(g) || a.includes(u) || H === u;
46
+ }) && (e.src = `{{${c}_${n}}}`);
40
47
  }
41
- const i = (F = ($ = h.name) == null ? void 0 : $[g]) == null ? void 0 : F.ATTR;
42
- if (i && e.setAttribute("alt", `{{${i}_${o}}}`), a) {
43
- const s = (D = h.itemLink) == null ? void 0 : D[g];
44
- if (s) {
45
- const _ = s.HREF, R = s.DEFAULT_HREF || "#!", u = a.href;
46
- (u === "#" || u === "" || u.endsWith("#!") || u.endsWith(R) || u === `${window.location.href}${R}` || !u || u === window.location.href) && (a.href = `{{${_}_${o}}}`);
48
+ const i = (I = (S = d.name) == null ? void 0 : S[m]) == null ? void 0 : I.ATTR;
49
+ if (i && e.setAttribute("alt", `{{${i}_${n}}}`), s) {
50
+ const a = (O = d.itemLink) == null ? void 0 : O[m];
51
+ if (a) {
52
+ const b = a.HREF, g = a.DEFAULT_HREF || "#!", u = s.href;
53
+ (u === "#" || u === "" || u.endsWith("#!") || u.endsWith(g) || u === `${window.location.href}${g}` || !u || u === window.location.href) && (s.href = `{{${b}_${n}}}`);
47
54
  }
48
55
  }
49
56
  break;
50
57
  }
51
58
  case "name": {
52
- const e = f, a = e.ATTR, l = e.DEFAULT_HREF || "#!", c = e.HREF;
53
- t.textContent && (t.innerHTML = P(t, `{{${a}_${o}}}`));
59
+ const e = f, s = e.ATTR, l = e.DEFAULT_HREF || "#!", c = e.HREF;
60
+ t.textContent && (t.innerHTML = L(t, `{{${s}_${n}}}`));
54
61
  const i = t.closest("a") || (t.tagName === "A" ? t : null);
55
62
  if (i && c) {
56
- const s = i.href, _ = `${window.location.href}${l}`;
57
- (s === _ || s.endsWith(l)) && (i.href = `{{${c}_${o}}}`);
63
+ const a = i.href, b = `${window.location.href}${l}`;
64
+ (a === b || a.endsWith(l)) && (i.href = `{{${c}_${n}}}`);
58
65
  }
59
66
  break;
60
67
  }
61
68
  case "price":
62
69
  case "originalPrice": {
63
- const e = f, a = t.getAttribute("data-formated"), l = t.getAttribute("data-single_price"), c = a === "true", i = l === "true", s = t.getAttribute(x.POSITION) || "before";
64
- let _;
65
- i ? _ = c ? e.SINGLE_PRICE_FORMATTED : e.SINGLE_PRICE : _ = c ? e.PRICE_FORMATTED : e.PRICE;
66
- const R = e.CURRENCY;
67
- let u = `{{${_}_${o}}}`;
68
- const H = (t.getAttribute(x.SYMBOL) || "").trim(), G = Y(H);
69
- let C = "";
70
- G ? C = H : R && (C = `{{${R}_${o}}}`), C && (u = s === "after" ? `${u} ${C}` : `${C} ${u}`), t.innerHTML = P(t, u);
70
+ const e = f, s = t.getAttribute("data-formated"), l = t.getAttribute("data-single_price"), c = s === "true", i = l === "true", a = t.getAttribute(U.POSITION) || "before";
71
+ let b;
72
+ i ? b = c ? e.SINGLE_PRICE_FORMATTED : e.SINGLE_PRICE : b = c ? e.PRICE_FORMATTED : e.PRICE;
73
+ const g = e.CURRENCY;
74
+ let u = `{{${b}_${n}}}`;
75
+ const H = (t.getAttribute(U.SYMBOL) || "").trim(), G = Y(H);
76
+ let F = "";
77
+ G ? F = H : g && (F = `{{${g}_${n}}}`), F && (u = a === "after" ? `${u} ${F}` : `${F} ${u}`), t.innerHTML = L(t, u);
71
78
  break;
72
79
  }
73
80
  case "quantity": {
74
- const e = f, a = e.ATTR, l = [e.DEFAULT, ...e.LEGACY_DEFAULTS], c = (N = t.textContent) == null ? void 0 : N.trim();
75
- c && l.includes(c) && (t.innerHTML = P(t, `{{${a}_${o}}}`));
81
+ const e = f, s = e.ATTR, l = [e.DEFAULT, ...e.LEGACY_DEFAULTS], c = (x = t.textContent) == null ? void 0 : x.trim();
82
+ c && l.includes(c) && (t.innerHTML = L(t, `{{${s}_${n}}}`));
76
83
  break;
77
84
  }
78
85
  case "button": {
79
- const e = f, a = e.HREF, l = e.DEFAULT_HREF || "#!", c = t.tagName === "A" ? t : t.querySelector("a");
86
+ const e = f, s = e.HREF, l = e.DEFAULT_HREF || "#!", c = t.tagName === "A" ? t : t.querySelector("a");
80
87
  if (c) {
81
- const i = c.href || "", s = `${window.location.href}${l}`;
82
- (i === "" || i === "#" || i === s || i.endsWith(l) || i.endsWith("#!") || i === window.location.href) && (c.href = `{{${a}_${o}}}`);
88
+ const i = c.href || "", a = `${window.location.href}${l}`;
89
+ (i === "" || i === "#" || i === a || i.endsWith(l) || i.endsWith("#!") || i === window.location.href) && (c.href = `{{${s}_${n}}}`);
83
90
  }
91
+ Q(t, `{{${s}_${n}}}`);
84
92
  break;
85
93
  }
86
94
  case "itemLink": {
87
- const e = f, a = e.HREF, l = e.DEFAULT_HREF || "#!", c = t;
95
+ const e = f, s = e.HREF, l = e.DEFAULT_HREF || "#!", c = t;
88
96
  if (c.href) {
89
- const i = c.href, s = `${window.location.href}${l}`;
90
- (i === s || i.endsWith(l)) && (c.href = `{{${a}_${o}}}`);
97
+ const i = c.href, a = `${window.location.href}${l}`;
98
+ (i === a || i.endsWith(l)) && (c.href = `{{${s}_${n}}}`);
91
99
  }
92
100
  break;
93
101
  }
94
102
  default: {
95
103
  if ("ATTR" in f) {
96
104
  const e = f.ATTR;
97
- t.textContent && (t.innerHTML = P(t, `{{${e}_${o}}}`));
105
+ t.textContent && (t.innerHTML = L(t, `{{${e}_${n}}}`));
98
106
  }
99
107
  break;
100
108
  }
@@ -102,49 +110,49 @@ function Z(S) {
102
110
  });
103
111
  });
104
112
  });
105
- const I = y.match(/<!DOCTYPE[^>]*>/i), U = I ? `${I[0]}
106
- ` : "", W = b.querySelectorAll(".ins-product-td"), M = [];
107
- W.forEach((n) => {
108
- const d = n.getAttribute("data-type") || "CART_ITEMS", p = n.getAttribute("data-number") || "1", r = n.outerHTML;
109
- M.push({
110
- element: n,
113
+ const E = C.match(/<!DOCTYPE[^>]*>/i), k = E ? `${E[0]}
114
+ ` : "", P = A.querySelectorAll(".ins-product-td"), N = [];
115
+ P.forEach((o) => {
116
+ const p = o.getAttribute("data-type") || "CART_ITEMS", T = o.getAttribute("data-number") || "1", r = o.outerHTML;
117
+ N.push({
118
+ element: o,
111
119
  outerHtml: r,
112
- type: d,
113
- number: p
120
+ type: p,
121
+ number: T
114
122
  });
115
123
  });
116
- let A = U + b.documentElement.outerHTML;
117
- M.reverse().forEach(({ outerHtml: n, type: d, number: p }) => {
118
- const r = O[d], E = r ? `${r}_total_product_kind` : "";
119
- if (E) {
120
- const T = parseInt(p) - 1, o = `${`{% if ${E} > ${T} %}`}${n}{% endif %}`;
121
- A = A.replace(n, X(o));
124
+ let h = k + A.documentElement.outerHTML;
125
+ N.reverse().forEach(({ outerHtml: o, type: p, number: T }) => {
126
+ const r = q[p], _ = r ? `${r}_total_product_kind` : "";
127
+ if (_) {
128
+ const R = parseInt(T) - 1, n = `${`{% if ${_} > ${R} %}`}${o}{% endif %}`;
129
+ h = h.replace(o, B(n));
122
130
  }
123
131
  });
124
- const V = b.querySelectorAll('[product-attr="originalPrice"][data-type]'), L = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Set();
125
- return V.forEach((n) => {
132
+ const V = A.querySelectorAll('[product-attr="originalPrice"][data-type]'), w = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Set();
133
+ return V.forEach((o) => {
126
134
  var t;
127
- const d = n.getAttribute("data-number"), p = n.getAttribute("data-type");
128
- if (!d || !O[p])
135
+ const p = o.getAttribute("data-number"), T = o.getAttribute("data-type");
136
+ if (!p || !q[T])
129
137
  return;
130
- const r = n.closest(".product-original-price-class");
131
- if (!r || k.has(r))
138
+ const r = o.closest(".product-original-price-class");
139
+ if (!r || D.has(r))
132
140
  return;
133
- k.add(r);
134
- const E = r.outerHTML, m = (t = n.closest(".ins-product-td")) == null ? void 0 : t.getAttribute("data-nodup"), T = L.get(E) ?? { number: d, type: p, wrap: [] };
135
- T.wrap.push(m !== "false"), L.set(E, T);
136
- }), L.forEach(({ number: n, type: d, wrap: p }, r) => {
137
- if (r.includes("{% if") || !p.some(Boolean))
141
+ D.add(r);
142
+ const _ = r.outerHTML, y = (t = o.closest(".ins-product-td")) == null ? void 0 : t.getAttribute("data-nodup"), R = w.get(_) ?? { number: p, type: T, wrap: [] };
143
+ R.wrap.push(y !== "false"), w.set(_, R);
144
+ }), w.forEach(({ number: o, type: p, wrap: T }, r) => {
145
+ if (r.includes("{% if") || !T.some(Boolean))
138
146
  return;
139
- const E = w.PAIRS_FOR_EXTENSION.price[d].PRICE, m = w.PAIRS_FOR_EXTENSION.originalPrice[d].PRICE, T = `{% if ${E}_${n} != ${m}_${n} %}`, t = [T, q(T)];
140
- let g = "", o = 0, f = 0, $ = A.indexOf(r);
141
- for (; $ !== -1; ) {
142
- const F = p[f] === !0 && !B(A, $, t);
143
- g += A.slice(o, $) + (F ? `${T}${r}{% endif %}` : r), o = $ + r.length, f += 1, $ = A.indexOf(r, o);
147
+ const _ = M.PAIRS_FOR_EXTENSION.price[p].PRICE, y = M.PAIRS_FOR_EXTENSION.originalPrice[p].PRICE, R = `{% if ${_}_${o} != ${y}_${o} %}`, t = [R, W(R)];
148
+ let m = "", n = 0, f = 0, S = h.indexOf(r);
149
+ for (; S !== -1; ) {
150
+ const I = T[f] === !0 && !v(h, S, t);
151
+ m += h.slice(n, S) + (I ? `${R}${r}{% endif %}` : r), n = S + r.length, f += 1, S = h.indexOf(r, n);
144
152
  }
145
- A = g + A.slice(o);
146
- }), A.replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
153
+ h = m + h.slice(n);
154
+ }), h.replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
147
155
  }
148
156
  export {
149
- Z as pairProductVariables
157
+ et as pairProductVariables
150
158
  };
@@ -1,20 +1,20 @@
1
- import { useActionsApi as D } from "../composables/useActionsApi.js";
2
- import { useConfig as E } from "../composables/useConfig.js";
3
- import { useHtmlCompiler as F } from "../composables/useHtmlCompiler.js";
1
+ import { useActionsApi as E } from "../composables/useActionsApi.js";
2
+ import { useConfig as F } from "../composables/useConfig.js";
3
+ import { useHtmlCompiler as I } from "../composables/useHtmlCompiler.js";
4
4
  import { useRecommendationExtensionStore as b } from "../extensions/Blocks/Recommendation/store/recommendation.js";
5
- import { toBlockUrlConfig as I } from "../extensions/Blocks/Recommendation/utils/blockUrlConfig.js";
5
+ import { toBlockUrlConfig as R } from "../extensions/Blocks/Recommendation/utils/blockUrlConfig.js";
6
6
  import { DATA_ATTRIBUTES as g } from "../extensions/Blocks/Unsubscribe/utils/constants.js";
7
- import { parsePageList as R } from "../extensions/Blocks/Unsubscribe/utils/utils.js";
8
- import { useDynamicContentStore as U } from "../stores/dynamic-content.js";
9
- import { useEditorStore as L } from "../stores/editor.js";
10
- import { useUnsubscribeStore as N } from "../stores/unsubscribe.js";
11
- import { isPlainObject as v } from "./genericUtil.js";
12
- import { assignTrackingIds as z } from "./linkTrackingIds.js";
13
- function M(n) {
7
+ import { parsePageList as U } from "../extensions/Blocks/Unsubscribe/utils/utils.js";
8
+ import { useDynamicContentStore as L } from "../stores/dynamic-content.js";
9
+ import { useEditorStore as N } from "../stores/editor.js";
10
+ import { useUnsubscribeStore as v } from "../stores/unsubscribe.js";
11
+ import { isPlainObject as z } from "./genericUtil.js";
12
+ import { assignTrackingIds as M } from "./linkTrackingIds.js";
13
+ function O(n) {
14
14
  const r = new DOMParser().parseFromString(n, "text/html").querySelectorAll(`[${g.PAGE_LIST}]`), e = [];
15
15
  return r.forEach((i) => {
16
16
  const t = i.getAttribute(g.PAGE_LIST);
17
- t && e.push(...R(t));
17
+ t && e.push(...U(t));
18
18
  }), [...new Set(e)];
19
19
  }
20
20
  async function S(n) {
@@ -35,7 +35,7 @@ async function S(n) {
35
35
  } catch {
36
36
  return;
37
37
  }
38
- v(a) && r.seedBlockUrlConfig(t, I(a));
38
+ z(a) && r.seedBlockUrlConfig(t, R(a));
39
39
  });
40
40
  try {
41
41
  await r.fetchRecommendationCreateData();
@@ -46,40 +46,40 @@ async function S(n) {
46
46
  );
47
47
  }
48
48
  }
49
- const Y = () => {
50
- const n = U(), c = L(), o = N(), { getCompiledEmail: r, getTemplateData: e, updateHtmlAndCss: i } = D(), { compileHtml: t, compileAmpHtml: m } = F(), { isFeatureEnabled: a } = E();
49
+ const Z = () => {
50
+ const n = L(), c = N(), o = v(), { getCompiledEmail: r, getTemplateData: e, updateHtmlAndCss: i } = E(), { compileHtml: t, compileAmpHtml: m } = I(), { isFeatureEnabled: a } = F();
51
51
  return {
52
- prepareTemplateDetails: async () => {
53
- let { html: s, css: u, syncModulesIds: h = [] } = await e();
52
+ prepareTemplateDetails: async (h) => {
53
+ let { html: s, css: u, syncModulesIds: y = [] } = h ?? await e();
54
54
  if (a("linkTrackingIds"))
55
55
  try {
56
- const { html: d, changed: P, nextSeq: x } = z(s, c.trackIdSessionFloor);
57
- c.trackIdSessionFloor = x, P && (s = d, await i(d, u));
56
+ const { html: d, changed: x, nextSeq: D } = M(s, c.trackIdSessionFloor);
57
+ c.trackIdSessionFloor = D, x && (s = d, await i(d, u));
58
58
  } catch (d) {
59
59
  console.error("Tracking-id step failed, saving anyway:", d);
60
60
  }
61
- const { html: y, ampHtml: p = "", ampErrors: T = [] } = await r({
61
+ const { html: T, ampHtml: p = "", ampErrors: A = [] } = await r({
62
62
  minimize: !0,
63
63
  resetDataSavedFlag: !1
64
64
  });
65
65
  o.selectedUnsubscribePages.length && await o.fetchTemplates(), await S(s);
66
- const { compiledHtml: A, stats: l, appliedRules: w } = t(y), C = p && m(p).compiledHtml, H = n.getSelectedDynamicContentList, k = b(), f = M(s);
66
+ const { compiledHtml: w, stats: l, appliedRules: C } = t(T), H = p && m(p).compiledHtml, k = n.getSelectedDynamicContentList, P = b(), f = O(s);
67
67
  return console.debug("HTML Compilation Stats:", {
68
68
  originalSize: l.originalSize,
69
69
  compiledSize: l.compiledSize,
70
70
  reduction: `${l.reductionPercentage.toFixed(2)}%`,
71
- appliedRules: w,
71
+ appliedRules: C,
72
72
  executionTime: `${l.executionTime.toFixed(2)}ms`
73
73
  }), {
74
- dynamicContentList: H,
75
- compiledHtml: A,
74
+ dynamicContentList: k,
75
+ compiledHtml: w,
76
76
  rawHtml: s,
77
77
  css: u,
78
- ampHtml: C,
79
- ampErrors: T,
80
- modules: h.map(Number),
78
+ ampHtml: H,
79
+ ampErrors: A,
80
+ modules: y.map(Number),
81
81
  recommendation: {
82
- campaignUrls: k.recommendationCampaignUrls,
82
+ campaignUrls: P.recommendationCampaignUrls,
83
83
  configs: {}
84
84
  },
85
85
  unsubscribe: {
@@ -94,6 +94,6 @@ const Y = () => {
94
94
  };
95
95
  };
96
96
  export {
97
- M as getHtmlReferencedUnsubscribePages,
98
- Y as useTemplatePreparation
97
+ O as getHtmlReferencedUnsubscribePages,
98
+ Z as useTemplatePreparation
99
99
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.21.2-beta.bb1c5dd",
3
+ "version": "3.21.2-beta.c321b5c",
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",