@useinsider/guido 3.9.0-beta.93e438c → 3.9.0-beta.c3e1698

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,51 +1,73 @@
1
- var h = Object.defineProperty;
2
- var x = (l, e, t) => e in l ? h(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
3
- var S = (l, e, t) => x(l, typeof e != "symbol" ? e + "" : e, t);
4
- import { MERGE_TAGS as k, PAGE_TYPES as p } from "../../enums/unsubscribe.js";
5
- import { DATA_ATTRIBUTES as A } from "../../extensions/Blocks/Unsubscribe/utils/constants.js";
6
- import { useUnsubscribeStore as T } from "../../stores/unsubscribe.js";
7
- class C {
1
+ var x = Object.defineProperty;
2
+ var B = (c, e, t) => e in c ? x(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t;
3
+ var A = (c, e, t) => B(c, typeof e != "symbol" ? e + "" : e, t);
4
+ import { MERGE_TAGS as f, PAGE_TYPES as p } from "../../enums/unsubscribe.js";
5
+ import { UNSUBSCRIBE_BLOCK_SELECTOR as h, DATA_ATTRIBUTES as k } from "../../extensions/Blocks/Unsubscribe/utils/constants.js";
6
+ import { useUnsubscribeStore as C } from "../../stores/unsubscribe.js";
7
+ class $ {
8
8
  constructor() {
9
- S(this, "parser");
9
+ A(this, "parser");
10
10
  this.parser = new DOMParser();
11
11
  }
12
12
  async migrate(e) {
13
13
  try {
14
- const t = this.parser.parseFromString(e, "text/html"), i = t.querySelectorAll("td.unsubscribe-block");
15
- if (!i.length)
16
- return e;
17
- const o = T();
18
- return await o.fetchTemplates(), i.forEach((r) => {
19
- const c = r.getAttribute("id"), g = this.extractPaddingClass(r), u = r.getAttribute("bgcolor") || "", n = this.extractUnsubscribeContent(r), s = this.getCollectionTypeFromMergeTag(n.linkHref), b = o.getSelectedUnsubscribePagesByCollection(s);
20
- console.debug("[UnsubscribeMigrator]", {
21
- mergeTag: n.linkHref,
22
- collectionType: s,
23
- pageIds: b,
24
- paddingClass: g,
25
- bgColor: u
26
- });
27
- const f = this.buildUnsubscribeBlock(
28
- n,
29
- s,
30
- b,
31
- g,
32
- u
33
- ), a = this.parser.parseFromString(
34
- `<table id="tempDoc"><tbody><tr>${f}</tr></tbody></table>`,
35
- "text/html"
36
- ).querySelector(".unsubscribe-block-v2");
37
- a && r.parentNode && (a.setAttribute("id", c || ""), r.parentNode.replaceChild(a, r));
38
- }), t.documentElement.outerHTML;
14
+ const t = this.parser.parseFromString(e, "text/html"), r = t.querySelectorAll("td.unsubscribe-block");
15
+ if (r.length) {
16
+ const s = C();
17
+ await s.fetchTemplates(), this.migrateLegacyBlocks(r, s);
18
+ }
19
+ const n = this.repairUnsubscribeLinks(t);
20
+ return !r.length && !n ? e : t.documentElement.outerHTML;
39
21
  } catch (t) {
40
22
  return console.error("UnsubscribeMigrator failed:", t), e;
41
23
  }
42
24
  }
25
+ migrateLegacyBlocks(e, t) {
26
+ e.forEach((r) => {
27
+ const n = r.getAttribute("id"), s = this.extractPaddingClass(r), l = r.getAttribute("bgcolor") || "", a = this.extractUnsubscribeContent(r), o = this.getCollectionTypeFromMergeTag(a.linkHref), b = t.getSelectedUnsubscribePagesByCollection(o);
28
+ console.debug("[UnsubscribeMigrator]", {
29
+ mergeTag: a.linkHref,
30
+ collectionType: o,
31
+ pageIds: b,
32
+ paddingClass: s,
33
+ bgColor: l
34
+ });
35
+ const u = this.buildUnsubscribeBlock(
36
+ a,
37
+ o,
38
+ b,
39
+ s,
40
+ l
41
+ ), i = this.parser.parseFromString(
42
+ `<table id="tempDoc"><tbody><tr>${u}</tr></tbody></table>`,
43
+ "text/html"
44
+ ).querySelector(h);
45
+ i && r.parentNode && (i.setAttribute("id", n || ""), r.parentNode.replaceChild(i, r));
46
+ });
47
+ }
48
+ // Re-derives the typed merge tag from data-unsubscribe-page-type for any v2
49
+ // block whose anchor href is missing or the legacy default. Returns true when
50
+ // at least one href was rewritten. Typed tags and custom URLs are left intact.
51
+ repairUnsubscribeLinks(e) {
52
+ const t = e.querySelectorAll(`${h}[${k.PAGE_TYPE}]`);
53
+ let r = !1;
54
+ return t.forEach((n) => {
55
+ const s = n.querySelector('a[data-unsubscribe-link="true"], a.unsubscribe-link');
56
+ if (!s)
57
+ return;
58
+ const l = s.getAttribute("href") || "";
59
+ if (l && l !== f.default)
60
+ return;
61
+ const a = Number(n.getAttribute(k.PAGE_TYPE)), o = f[a];
62
+ o && (s.setAttribute("href", o), r = !0);
63
+ }), r;
64
+ }
43
65
  extractPaddingClass(e) {
44
- const i = (e.getAttribute("class") || "").match(/\bes-p\d+\b/);
45
- return i ? i[0] : "";
66
+ const r = (e.getAttribute("class") || "").match(/\bes-p\d+\b/);
67
+ return r ? r[0] : "";
46
68
  }
47
69
  extractUnsubscribeContent(e) {
48
- var m;
70
+ var d;
49
71
  const t = e.querySelector("p");
50
72
  if (!t)
51
73
  return {
@@ -59,8 +81,8 @@ class C {
59
81
  align: "center",
60
82
  paragraphStyle: ""
61
83
  };
62
- const i = e.getAttribute("align") || t.getAttribute("align") || "center", o = t.getAttribute("style") || "", r = t.querySelector("a.unsubscribe-link") || t.querySelector('a[href*="unsubscribe"]');
63
- if (!r)
84
+ const r = e.getAttribute("align") || t.getAttribute("align") || "center", n = t.getAttribute("style") || "", s = t.querySelector("a.unsubscribe-link") || t.querySelector('a[href*="unsubscribe"]');
85
+ if (!s)
64
86
  return {
65
87
  textBefore: "You can ",
66
88
  linkText: "unsubscribe",
@@ -69,55 +91,55 @@ class C {
69
91
  textAfter: " from our emails, if you need to.",
70
92
  isBold: !1,
71
93
  isItalic: !1,
72
- align: i,
73
- paragraphStyle: o
94
+ align: r,
95
+ paragraphStyle: n
74
96
  };
75
- const c = ((m = r.textContent) == null ? void 0 : m.trim()) || "unsubscribe", g = r.getAttribute("href") || "{{ins-unsubscribe-link}}", u = r.getAttribute("style") || "", n = t.textContent || "", s = n.indexOf(c), b = s >= 0 ? n.substring(0, s).trim() : "You can ", f = s >= 0 ? n.substring(s + c.length).trim() : " from our emails, if you need to.", d = !!t.querySelector("b, strong"), a = !!t.querySelector("i, em");
97
+ const l = ((d = s.textContent) == null ? void 0 : d.trim()) || "unsubscribe", a = s.getAttribute("href") || "{{ins-unsubscribe-link}}", o = s.getAttribute("style") || "", b = t.textContent || "", u = b.indexOf(l), g = u >= 0 ? b.substring(0, u).trim() : "You can ", i = u >= 0 ? b.substring(u + l.length).trim() : " from our emails, if you need to.", m = !!t.querySelector("b, strong"), y = !!t.querySelector("i, em");
76
98
  return {
77
- textBefore: b,
78
- linkText: c,
79
- linkHref: this.normalizeUnsubscribeHref(g),
80
- linkStyle: u,
81
- textAfter: f,
82
- isBold: d,
83
- isItalic: a,
84
- align: i,
85
- paragraphStyle: o
99
+ textBefore: g,
100
+ linkText: l,
101
+ linkHref: this.normalizeUnsubscribeHref(a),
102
+ linkStyle: o,
103
+ textAfter: i,
104
+ isBold: m,
105
+ isItalic: y,
106
+ align: r,
107
+ paragraphStyle: n
86
108
  };
87
109
  }
88
- buildUnsubscribeBlock(e, t, i, o, r) {
89
- const c = e.linkStyle ? ` style="${e.linkStyle}"` : "", u = `<a ${`href="${e.linkHref}" class="unsubscribe-link" target="_blank" data-unsubscribe-link="true"`}${c}>${e.linkText}</a>`, n = [];
90
- e.textBefore && n.push(e.textBefore), n.push(u), e.textAfter && n.push(e.textAfter);
91
- let s = n.join(" ");
92
- e.isBold && e.isItalic ? s = `<strong path="1,0"><em path="1,0,0">${s}</em></strong>` : e.isBold ? s = `<strong path="1,0">${s}</strong>` : e.isItalic && (s = `<em path="1,0">${s}</em>`);
93
- const b = e.align ? ` align="${e.align}"` : "", f = r ? ` bgcolor="${r}"` : "", d = e.paragraphStyle ? ` style="${e.paragraphStyle}"` : "", a = i.length > 0 ? ` ${A.PAGE_LIST}="${i.join(",")}"` : "", m = ` ${A.PAGE_TYPE}="${t}"`, y = "esd-block-text unsubscribe-block-v2 esd-block-unsubscribe esd-unsubscribe-block esd-extension-block";
110
+ buildUnsubscribeBlock(e, t, r, n, s) {
111
+ const l = e.linkStyle ? ` style="${e.linkStyle}"` : "", u = `<a ${`href="${Object.values(f).includes(e.linkHref) ? f[t] : e.linkHref}" class="unsubscribe-link" target="_blank" data-unsubscribe-link="true"`}${l}>${e.linkText}</a>`, g = [];
112
+ e.textBefore && g.push(e.textBefore), g.push(u), e.textAfter && g.push(e.textAfter);
113
+ let i = g.join(" ");
114
+ e.isBold && e.isItalic ? i = `<strong path="1,0"><em path="1,0,0">${i}</em></strong>` : e.isBold ? i = `<strong path="1,0">${i}</strong>` : e.isItalic && (i = `<em path="1,0">${i}</em>`);
115
+ const m = e.align ? ` align="${e.align}"` : "", y = s ? ` bgcolor="${s}"` : "", d = e.paragraphStyle ? ` style="${e.paragraphStyle}"` : "", E = r.length > 0 ? ` ${k.PAGE_LIST}="${r.join(",")}"` : "", T = ` ${k.PAGE_TYPE}="${t}"`, S = "esd-block-text unsubscribe-block-v2 esd-block-unsubscribe esd-unsubscribe-block esd-extension-block";
94
116
  return `
95
117
  <td
96
118
  data-migration="true"
97
119
  esd-extension-block-id="unsubscribe-block"
98
- class="${o ? `${y} ${o}` : y}"
99
- ${b}${f}${m}${a}
120
+ class="${n ? `${S} ${n}` : S}"
121
+ ${m}${y}${T}${E}
100
122
  >
101
123
  <p path="1"${d}>
102
- ${s}
124
+ ${i}
103
125
  </p>
104
126
  </td>
105
127
  `;
106
128
  }
107
129
  getCollectionTypeFromMergeTag(e) {
108
- return e === k[p.SUBSCRIPTION_PREFERENCE_CENTER] ? p.SUBSCRIPTION_PREFERENCE_CENTER : e === k[p.GLOBAL_UNSUBSCRIBE] ? p.GLOBAL_UNSUBSCRIBE : p.GLOBAL_UNSUBSCRIBE;
130
+ return e === f[p.SUBSCRIPTION_PREFERENCE_CENTER] ? p.SUBSCRIPTION_PREFERENCE_CENTER : e === f[p.GLOBAL_UNSUBSCRIBE] ? p.GLOBAL_UNSUBSCRIBE : p.GLOBAL_UNSUBSCRIBE;
109
131
  }
110
132
  normalizeUnsubscribeHref(e) {
111
- if (Object.values(k).includes(e))
133
+ if (Object.values(f).includes(e))
112
134
  return e;
113
- const i = e.match(/{{ins-(?:global-)?(?:preferences-)?unsubscribe-link}}/);
114
- return i ? i[0] : e.includes("unsubscribe") || e.includes("unsub") ? (console.warn(
135
+ const r = e.match(/{{ins-(?:global-)?(?:preferences-)?unsubscribe-link}}/);
136
+ return r ? r[0] : e.includes("unsubscribe") || e.includes("unsub") ? (console.warn(
115
137
  `[UnsubscribeMigrator] Unrecognized unsubscribe href format: "${e}". Defaulting to {{ins-unsubscribe-link}}`
116
138
  ), "{{ins-unsubscribe-link}}") : e;
117
139
  }
118
140
  }
119
- async function M(l) {
120
- return new C().migrate(l);
141
+ async function M(c) {
142
+ return new $().migrate(c);
121
143
  }
122
144
  export {
123
145
  M as migrateUnsubscribe
@@ -1,4 +1,4 @@
1
- const o = { stripo: { version: "2.68.0" } }, s = {
1
+ const o = { stripo: { version: "2.66.0" } }, s = {
2
2
  guido: o
3
3
  };
4
4
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.9.0-beta.93e438c",
3
+ "version": "3.9.0-beta.c3e1698",
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",
@@ -104,7 +104,7 @@
104
104
  },
105
105
  "guido": {
106
106
  "stripo": {
107
- "version": "2.68.0"
107
+ "version": "2.66.0"
108
108
  }
109
109
  }
110
110
  }