@useinsider/guido 3.2.0-beta.c2a858e → 3.2.0-beta.cb38cc7

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,29 +1,32 @@
1
- import { useActionsApi as S } from "./useActionsApi.js";
2
- import { useConfig as V } from "./useConfig.js";
3
- import { useSaveStart as x, useSaveComplete as y } from "./useGuidoActions.js";
4
- import { useSyncModuleExtractor as w } from "./useSyncModuleExtractor.js";
5
- import { useStripoApi as b } from "../services/stripoApi.js";
6
- import { useTemplatePreparation as q } from "../utils/templatePreparation.js";
7
- import { useHtmlValidator as H } from "./useHtmlValidator.js";
8
- import { useLiquidValidator as L } from "./validators/useLiquidValidator.js";
9
- const F = () => {
10
- const o = x(), s = y(), { validateHtml: r } = H(), { validateLiquidSyntax: n } = L(), { callbacks: a, isFeatureEnabled: l } = V(), { extractSyncModuleData: d } = w(), { setSyncModuleUnsubscriptionPages: u } = b(), { editorSave: c } = S();
11
- return { save: async (m = !1) => {
1
+ import { useActionsApi as V } from "./useActionsApi.js";
2
+ import { useConfig as x } from "./useConfig.js";
3
+ import { useSaveStart as y, useSaveComplete as w } from "./useGuidoActions.js";
4
+ import { useSyncModuleExtractor as C } from "./useSyncModuleExtractor.js";
5
+ import { useStripoApi as H } from "../services/stripoApi.js";
6
+ import { useTemplatePreparation as b } from "../utils/templatePreparation.js";
7
+ import { useHtmlValidator as q } from "./useHtmlValidator.js";
8
+ import { useCouponBlockValidator as L } from "./validators/useCouponBlockValidator.js";
9
+ import { useLiquidValidator as P } from "./validators/useLiquidValidator.js";
10
+ const h = () => {
11
+ const o = y(), s = w(), { validateHtml: r } = q(), { validateLiquidSyntax: l } = P(), { validateCouponBlockTags: n } = L(), { callbacks: a, isFeatureEnabled: d } = x(), { extractSyncModuleData: u } = C(), { setSyncModuleUnsubscriptionPages: c } = H(), { editorSave: m } = V();
12
+ return { save: async (p = !1) => {
12
13
  var i;
13
14
  o();
14
- const { prepareTemplateDetails: p } = q(), t = await p();
15
- if (l("liquidSyntax")) {
16
- if (!await n(t.compiledHtml))
15
+ const { prepareTemplateDetails: f } = b(), t = await f();
16
+ if (!n(t.compiledHtml))
17
+ return;
18
+ if (d("liquidSyntax")) {
19
+ if (!await l(t.compiledHtml))
17
20
  return;
18
21
  } else if (!await r(t.compiledHtml, t.dynamicContentList, !0))
19
22
  return;
20
23
  if ((i = a.value) != null && i.externalValidation && !await a.value.externalValidation(t))
21
24
  return;
22
- await c();
23
- const { unsubscribePayload: f, stripoModules: v } = d(t.rawHtml);
24
- return await u(f), t.modules = v, m || s(t), t;
25
+ await m();
26
+ const { unsubscribePayload: v, stripoModules: S } = u(t.rawHtml);
27
+ return await c(v), t.modules = S, p || s(t), t;
25
28
  } };
26
29
  };
27
30
  export {
28
- F as useSave
31
+ h as useSave
29
32
  };
@@ -0,0 +1,24 @@
1
+ import { ToasterTypeOptions as c } from "../../enums/toaster.js";
2
+ import { COUPON_PLACEHOLDER_DEFAULT as i, COUPON_PLACEHOLDER_LIQUID as l } from "../../extensions/Blocks/CouponBlock/template.js";
3
+ import { useToaster as m } from "../useToaster.js";
4
+ import { useTranslations as p } from "../useTranslations.js";
5
+ const u = /* @__PURE__ */ new Set([
6
+ i,
7
+ l
8
+ ]), A = () => {
9
+ const { showToaster: t } = m(), r = p();
10
+ return { validateCouponBlockTags: (e) => {
11
+ const n = new DOMParser().parseFromString(e, "text/html");
12
+ return Array.from(n.querySelectorAll(".coupon-block")).find((s) => {
13
+ var o;
14
+ const a = ((o = s.textContent) == null ? void 0 : o.trim()) ?? "";
15
+ return !u.has(a);
16
+ }) ? (t({
17
+ type: c.Warning,
18
+ message: r("newsletter.coupon-tag-modified")
19
+ }), !1) : !0;
20
+ } };
21
+ };
22
+ export {
23
+ A as useCouponBlockValidator
24
+ };
@@ -1,54 +1,34 @@
1
1
  var x = Object.defineProperty;
2
- var T = (l, e, t) => e in l ? x(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
3
- var b = (l, e, t) => T(l, typeof e != "symbol" ? e + "" : e, t);
4
- import S from "../../extensions/Blocks/RadioButton/template.js";
5
- class B {
2
+ var f = (r, t, e) => t in r ? x(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var b = (r, t, e) => f(r, typeof t != "symbol" ? t + "" : t, e);
4
+ import h from "../../extensions/Blocks/RadioButton/template.js";
5
+ class T {
6
6
  constructor() {
7
7
  b(this, "parser");
8
8
  this.parser = new DOMParser();
9
9
  }
10
- migrate(e) {
10
+ migrate(t) {
11
11
  try {
12
- const t = this.parser.parseFromString(e, "text/html"), i = t.querySelectorAll("td.radio-button-block"), s = t.querySelectorAll("td.radio-button-v2");
13
- if (i.length === 0 && s.length === 0)
14
- return e;
15
- let o = !1;
16
- return i.forEach((r) => {
17
- if (r.classList.contains("radio-button-v2"))
12
+ const e = this.parser.parseFromString(t, "text/html"), i = e.querySelectorAll("td.radio-button-block");
13
+ return i.length === 0 ? t : (i.forEach((s) => {
14
+ if (s.classList.contains("radio-button-v2"))
18
15
  return;
19
- const n = r.getAttribute("id"), a = this.extractTextFromElement(r, "ins-title"), g = this.extractTextFromElement(r, "ins-description"), c = this.extractTextFromElement(r, "ins-subscribe"), u = this.extractTextFromElement(r, "ins-unsubscribe"), d = this.buildTextBlock(a), p = this.buildTextBlock(g), y = this.buildTextBlock({ ...c, classList: "" }), f = this.buildTextBlock({ ...u, classList: "" }), h = S.replace("{-{-TITLE-}-}", d).replace("{-{-DESCRIPTION-}-}", p).replace("{-{-YES-}-}", y).replace("{-{-NO-}-}", f), m = this.parser.parseFromString(
20
- `<table id="tempDoc"><tbody><tr>${h}</tr></tbody></table>`,
16
+ const n = s.getAttribute("id"), l = this.extractTextFromElement(s, "ins-title"), a = this.extractTextFromElement(s, "ins-description"), p = this.extractTextFromElement(s, "ins-subscribe"), u = this.extractTextFromElement(s, "ins-unsubscribe"), d = this.buildTextBlock(l), g = this.buildTextBlock(a), m = this.buildTextBlock({ ...p, classList: "" }), o = this.buildTextBlock({ ...u, classList: "" }), c = h.replace("{-{-TITLE-}-}", d).replace("{-{-DESCRIPTION-}-}", g).replace("{-{-YES-}-}", m).replace("{-{-NO-}-}", o), y = this.parser.parseFromString(
17
+ `<table id="tempDoc"><tbody><tr>${c}</tr></tbody></table>`,
21
18
  "text/html"
22
19
  ).querySelector(".radio-button-v2");
23
- m && r.parentNode && (m.setAttribute("id", n || ""), r.parentNode.replaceChild(m, r), o = !0);
24
- }), o = this.healRadioButtonV2(t) || o, o ? t.documentElement.outerHTML : e;
25
- } catch (t) {
26
- return console.error("RadioButtonMigrator failed:", t), e;
20
+ y && s.parentNode && (y.setAttribute("id", n || ""), s.parentNode.replaceChild(y, s));
21
+ }), e.documentElement.outerHTML);
22
+ } catch (e) {
23
+ return console.error("RadioButtonMigrator failed:", e), t;
27
24
  }
28
25
  }
29
- healRadioButtonV2(e) {
30
- let t = !1;
31
- return e.querySelectorAll("td.radio-button-v2").forEach((i) => {
32
- var p;
33
- const s = i.querySelector("input#radioYes"), o = i.querySelector("input#radioNo");
34
- if (!s || !o)
35
- return;
36
- const r = ((p = s.parentElement) == null ? void 0 : p.querySelector(":scope > p")) || null;
37
- if (!r && !s.hasAttribute("align"))
38
- return;
39
- const n = s.closest("tr"), a = o.closest("tr");
40
- if (!n || !a || n === a || !n.parentNode)
41
- return;
42
- const g = (r == null ? void 0 : r.innerHTML.trim()) || "Yes", c = a.cloneNode(!0), u = c.querySelector("input#radioNo"), d = c.querySelector("p");
43
- u && (u.setAttribute("id", "radioYes"), u.removeAttribute("align")), d && (d.innerHTML = g), n.parentNode.replaceChild(c, n), t = !0;
44
- }), t;
45
- }
46
- extractTextFromElement(e, t) {
47
- var p, y;
48
- const i = e.querySelector(`.${t}`);
26
+ extractTextFromElement(t, e) {
27
+ var o, c;
28
+ const i = t.querySelector(`.${e}`);
49
29
  if (!i)
50
30
  return {
51
- text: t === "ins-title" ? "Title" : "Description",
31
+ text: e === "ins-title" ? "Title" : "Description",
52
32
  isBold: !1,
53
33
  isItalic: !1,
54
34
  align: "left",
@@ -58,51 +38,51 @@ class B {
58
38
  const s = i.querySelector("p");
59
39
  if (!s)
60
40
  return {
61
- text: ((p = i.textContent) == null ? void 0 : p.trim()) || (t === "ins-title" ? "Title" : "Description"),
41
+ text: ((o = i.textContent) == null ? void 0 : o.trim()) || (e === "ins-title" ? "Title" : "Description"),
62
42
  isBold: !1,
63
43
  isItalic: !1,
64
44
  align: i.getAttribute("align") || "left",
65
45
  styles: "",
66
46
  classList: ""
67
47
  };
68
- const o = ((y = s.textContent) == null ? void 0 : y.trim()) || (t === "ins-title" ? "Title" : "Description"), r = s.getAttribute("style") || "", n = i.getAttribute("align") || s.getAttribute("align") || "left", a = /font-weight\s*:\s*bold/i.test(r) || !!s.querySelector("b, strong"), g = /font-style\s*:\s*italic/i.test(r) || !!s.querySelector("i, em"), c = this.removeStyleProperties(r, ["font-weight", "font-style"]), u = this.convertInlineToBlock(c), d = i.getAttribute("class") || "";
48
+ const n = ((c = s.textContent) == null ? void 0 : c.trim()) || (e === "ins-title" ? "Title" : "Description"), l = s.getAttribute("style") || "", a = i.getAttribute("align") || s.getAttribute("align") || "left", p = /font-weight\s*:\s*bold/i.test(l) || !!s.querySelector("b, strong"), u = /font-style\s*:\s*italic/i.test(l) || !!s.querySelector("i, em"), d = this.removeStyleProperties(l, ["font-weight", "font-style"]), g = this.convertInlineToBlock(d), m = i.getAttribute("class") || "";
69
49
  return {
70
- text: o,
71
- isBold: a,
72
- isItalic: g,
73
- align: n,
74
- styles: u,
75
- classList: d
50
+ text: n,
51
+ isBold: p,
52
+ isItalic: u,
53
+ align: a,
54
+ styles: g,
55
+ classList: m
76
56
  };
77
57
  }
78
- buildTextBlock(e) {
79
- let t = e.text;
80
- e.isBold && e.isItalic ? t = `<strong path="1,0"><em path="1,0,0">${t}</em></strong>` : e.isBold ? t = `<strong path="1,0">${t}</strong>` : e.isItalic && (t = `<em path="1,0">${t}</em>`);
81
- const i = e.align ? ` align="${e.align}"` : "", s = e.styles ? ` style="${e.styles.replaceAll('"', "'")}"` : "";
58
+ buildTextBlock(t) {
59
+ let e = t.text;
60
+ t.isBold && t.isItalic ? e = `<strong path="1,0"><em path="1,0,0">${e}</em></strong>` : t.isBold ? e = `<strong path="1,0">${e}</strong>` : t.isItalic && (e = `<em path="1,0">${e}</em>`);
61
+ const i = t.align ? ` align="${t.align}"` : "", s = t.styles ? ` style="${t.styles.replaceAll('"', "'")}"` : "";
82
62
  return `
83
- <td class="esd-block-text ${e.classList}" ${i}>
63
+ <td class="esd-block-text ${t.classList}" ${i}>
84
64
  <p path="1" ${s}>
85
- ${t}
65
+ ${e}
86
66
  </p>
87
67
  </td>
88
68
  `;
89
69
  }
90
- removeStyleProperties(e, t) {
91
- return e ? t.reduce((s, o) => {
92
- const r = new RegExp(`${o}\\s*:\\s*[^;]*;?`, "gi");
93
- return s.replace(r, "");
94
- }, e).replace(/;\s*;/g, ";").replace(/^;|;$/g, "").trim() : "";
70
+ removeStyleProperties(t, e) {
71
+ return t ? e.reduce((s, n) => {
72
+ const l = new RegExp(`${n}\\s*:\\s*[^;]*;?`, "gi");
73
+ return s.replace(l, "");
74
+ }, t).replace(/;\s*;/g, ";").replace(/^;|;$/g, "").trim() : "";
95
75
  }
96
- convertInlineToBlock(e) {
97
- if (!e)
76
+ convertInlineToBlock(t) {
77
+ if (!t)
98
78
  return "";
99
- let t = e.replace(/display\s*:\s*inline/gi, "display: block");
100
- return /display\s*:/i.test(t) || (t = t ? `${t}; display: block` : "display: block"), t.replace(/;\s*;/g, ";").replace(/^;|;$/g, "").trim();
79
+ let e = t.replace(/display\s*:\s*inline/gi, "display: block");
80
+ return /display\s*:/i.test(e) || (e = e ? `${e}; display: block` : "display: block"), e.replace(/;\s*;/g, ";").replace(/^;|;$/g, "").trim();
101
81
  }
102
82
  }
103
- function q(l) {
104
- return new B().migrate(l);
83
+ function A(r) {
84
+ return new T().migrate(r);
105
85
  }
106
86
  export {
107
- q as migrateRadioButton
87
+ A as migrateRadioButton
108
88
  };
@@ -119,7 +119,7 @@ const e = {
119
119
  id="radioYes"
120
120
  name="unsubscribe"
121
121
  data-cke-editable="1"
122
- style="margin: 0px; vertical-align: middle;">
122
+ style="margin: 0px; vertical-align: middle;>
123
123
  </td>
124
124
  {-{-YES-}-}
125
125
  </tr>
@@ -0,0 +1,3 @@
1
+ export declare const useCouponBlockValidator: () => {
2
+ validateCouponBlockTags: (html: string) => boolean;
3
+ };
@@ -1,4 +1,4 @@
1
- declare const migrationTemplate = "\n <td\n align=\"left\"\n esd-extension-block-id=\"radio-button-block\"\n esd-handler-name=\"esd-extension-RadioButtonBlock\"\n class=\"\n radio-button\n radio-button-v2\n esd-block-ra\n esd-radio-button-block\n esd-extension-block\n es-p10t\n es-p10b\n es-p30r\n es-p30l\"\n >\n <table cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\">\n <tbody>\n <tr>\n <td align=\"left\" width=\"70%\" style=\"vertical-align: top;\">\n <table cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\">\n <tbody>\n <tr>\n {-{-TITLE-}-}\n </tr>\n <tr>\n {-{-DESCRIPTION-}-}\n </tr>\n </tbody>\n </table>\n </td>\n <td align=\"right\" width=\"30%\" style=\"vertical-align: middle;\">\n <table cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\">\n <tbody>\n <tr>\n <td width=\"50%\">\n <table width=\"100%\">\n <tr>\n <td width=\"24\">\n <input\n type=\"radio\"\n id=\"radioYes\"\n name=\"unsubscribe\"\n data-cke-editable=\"1\"\n style=\"margin: 0px; vertical-align: middle;\">\n </td>\n {-{-YES-}-}\n </tr>\n </table>\n </td>\n <td width=\"50%\">\n <table width=\"100%\">\n <tr>\n <td width=\"24\">\n <input\n type=\"radio\"\n id=\"radioNo\"\n name=\"unsubscribe\"\n data-cke-editable=\"1\"\n style=\"margin: 0px; vertical-align: middle;\">\n </td>\n {-{-NO-}-}\n </tr>\n </table>\n </td>\n </tr>\n </tbody>\n </table>\n </td>\n </tr>\n </tbody>\n </table>\n </td>\n";
1
+ declare const migrationTemplate = "\n <td\n align=\"left\"\n esd-extension-block-id=\"radio-button-block\"\n esd-handler-name=\"esd-extension-RadioButtonBlock\"\n class=\"\n radio-button\n radio-button-v2\n esd-block-ra\n esd-radio-button-block\n esd-extension-block\n es-p10t\n es-p10b\n es-p30r\n es-p30l\"\n >\n <table cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\">\n <tbody>\n <tr>\n <td align=\"left\" width=\"70%\" style=\"vertical-align: top;\">\n <table cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\">\n <tbody>\n <tr>\n {-{-TITLE-}-}\n </tr>\n <tr>\n {-{-DESCRIPTION-}-}\n </tr>\n </tbody>\n </table>\n </td>\n <td align=\"right\" width=\"30%\" style=\"vertical-align: middle;\">\n <table cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\" width=\"100%\">\n <tbody>\n <tr>\n <td width=\"50%\">\n <table width=\"100%\">\n <tr>\n <td width=\"24\">\n <input\n type=\"radio\"\n id=\"radioYes\"\n name=\"unsubscribe\"\n data-cke-editable=\"1\"\n style=\"margin: 0px; vertical-align: middle;>\n </td>\n {-{-YES-}-}\n </tr>\n </table>\n </td>\n <td width=\"50%\">\n <table width=\"100%\">\n <tr>\n <td width=\"24\">\n <input\n type=\"radio\"\n id=\"radioNo\"\n name=\"unsubscribe\"\n data-cke-editable=\"1\"\n style=\"margin: 0px; vertical-align: middle;\">\n </td>\n {-{-NO-}-}\n </tr>\n </table>\n </td>\n </tr>\n </tbody>\n </table>\n </td>\n </tr>\n </tbody>\n </table>\n </td>\n";
2
2
  /**
3
3
  * @returns The template for the default checkbox block
4
4
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.2.0-beta.c2a858e",
3
+ "version": "3.2.0-beta.cb38cc7",
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",