@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
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { MERGE_TAGS as
|
|
5
|
-
import { DATA_ATTRIBUTES as
|
|
6
|
-
import { useUnsubscribeStore as
|
|
7
|
-
class
|
|
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
|
-
|
|
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"),
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
45
|
-
return
|
|
66
|
+
const r = (e.getAttribute("class") || "").match(/\bes-p\d+\b/);
|
|
67
|
+
return r ? r[0] : "";
|
|
46
68
|
}
|
|
47
69
|
extractUnsubscribeContent(e) {
|
|
48
|
-
var
|
|
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
|
|
63
|
-
if (!
|
|
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:
|
|
73
|
-
paragraphStyle:
|
|
94
|
+
align: r,
|
|
95
|
+
paragraphStyle: n
|
|
74
96
|
};
|
|
75
|
-
const
|
|
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:
|
|
78
|
-
linkText:
|
|
79
|
-
linkHref: this.normalizeUnsubscribeHref(
|
|
80
|
-
linkStyle:
|
|
81
|
-
textAfter:
|
|
82
|
-
isBold:
|
|
83
|
-
isItalic:
|
|
84
|
-
align:
|
|
85
|
-
paragraphStyle:
|
|
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,
|
|
89
|
-
const
|
|
90
|
-
e.textBefore &&
|
|
91
|
-
let
|
|
92
|
-
e.isBold && e.isItalic ?
|
|
93
|
-
const
|
|
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="${
|
|
99
|
-
${
|
|
120
|
+
class="${n ? `${S} ${n}` : S}"
|
|
121
|
+
${m}${y}${T}${E}
|
|
100
122
|
>
|
|
101
123
|
<p path="1"${d}>
|
|
102
|
-
${
|
|
124
|
+
${i}
|
|
103
125
|
</p>
|
|
104
126
|
</td>
|
|
105
127
|
`;
|
|
106
128
|
}
|
|
107
129
|
getCollectionTypeFromMergeTag(e) {
|
|
108
|
-
return e ===
|
|
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(
|
|
133
|
+
if (Object.values(f).includes(e))
|
|
112
134
|
return e;
|
|
113
|
-
const
|
|
114
|
-
return
|
|
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(
|
|
120
|
-
return new
|
|
141
|
+
async function M(c) {
|
|
142
|
+
return new $().migrate(c);
|
|
121
143
|
}
|
|
122
144
|
export {
|
|
123
145
|
M as migrateUnsubscribe
|
package/dist/package.json.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useinsider/guido",
|
|
3
|
-
"version": "3.9.0-beta.
|
|
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.
|
|
107
|
+
"version": "2.66.0"
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
}
|