@useinsider/guido 3.24.0-beta.b9ec78b → 3.24.0-beta.e2e5de9
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.
- package/dist/composables/useActionsApi.js +2 -2
- package/dist/composables/useEditorTrackingIds.js +49 -0
- package/dist/config/migrator/unsubscribeMigrator.js +98 -94
- package/dist/extensions/Blocks/Unsubscribe/block.js +96 -104
- package/dist/extensions/Blocks/Unsubscribe/utils/constants.js +3 -4
- package/dist/package.json.js +6 -6
- package/dist/src/composables/useEditorTrackingIds.d.ts +7 -0
- package/dist/src/extensions/Blocks/Unsubscribe/utils/constants.d.ts +0 -1
- package/dist/src/utils/linkTrackingIds.d.ts +19 -0
- package/dist/utils/linkTrackingIds.js +82 -48
- package/dist/utils/templatePreparation.js +30 -33
- package/package.json +1 -1
- package/dist/extensions/Blocks/Unsubscribe/utils/swapMergeTagInHref.js +0 -5
- package/dist/src/extensions/Blocks/Unsubscribe/utils/swapMergeTagInHref.d.ts +0 -1
|
@@ -111,8 +111,8 @@ const H = 1e4, T = 3e4, m = (n, l, A) => new Promise((C, p) => {
|
|
|
111
111
|
}),
|
|
112
112
|
updateHtmlAndCss: (t, e) => {
|
|
113
113
|
const { actionsApi: i } = r();
|
|
114
|
-
return m("updateHtmlAndCss", H, (a) => {
|
|
115
|
-
i.updateHtmlAndCss(t, e, () => a());
|
|
114
|
+
return m("updateHtmlAndCss", H, (a, o) => {
|
|
115
|
+
i.updateHtmlAndCss(t, e, () => a(), o);
|
|
116
116
|
});
|
|
117
117
|
},
|
|
118
118
|
editorSave: () => m(
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { TRACK_ID_ATTRIBUTE as u, writeAnchorTrackIds as I, TRACK_SEQ_ATTRIBUTE as f, planTrackingIds as h, parseTrackSeq as w, readAnchorTrackIds as k } from "../utils/linkTrackingIds.js";
|
|
2
|
+
import { getEditorApi as A } from "../utils/stripoEditorApi.js";
|
|
3
|
+
import { ModificationDescription as x } from "../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
4
|
+
function T(t, r = []) {
|
|
5
|
+
const o = t.getType();
|
|
6
|
+
if (o === "comment") {
|
|
7
|
+
const e = t.getTextContent() ?? "", i = k(e);
|
|
8
|
+
return i.length && r.push({ kind: "comment", node: t, text: e, rawIds: i }), r;
|
|
9
|
+
}
|
|
10
|
+
if (o === "element") {
|
|
11
|
+
const e = t;
|
|
12
|
+
e.getTagName().toLowerCase() === "a" && r.push({ kind: "element", node: e, rawIds: [e.getAttribute(u) ?? ""] });
|
|
13
|
+
}
|
|
14
|
+
return t.childNodes().forEach((e) => T(e, r)), r;
|
|
15
|
+
}
|
|
16
|
+
function y(t, r) {
|
|
17
|
+
if (!t)
|
|
18
|
+
throw new Error("The editor exposes no editorCopilotApi.");
|
|
19
|
+
const o = t.getDocumentRootHtmlNode(), e = o.querySelector("body");
|
|
20
|
+
if (!e)
|
|
21
|
+
throw new Error("The editor document has no <body> to record tracking ids on.");
|
|
22
|
+
const i = T(o), s = h(
|
|
23
|
+
i.flatMap((d) => d.rawIds),
|
|
24
|
+
w(e.getAttribute(f)),
|
|
25
|
+
r
|
|
26
|
+
);
|
|
27
|
+
return { api: t, seqHost: e, hosts: i, plan: s };
|
|
28
|
+
}
|
|
29
|
+
const H = () => ({ writeTrackingIds: (r) => {
|
|
30
|
+
const { editorCopilotApi: o } = A();
|
|
31
|
+
let e;
|
|
32
|
+
try {
|
|
33
|
+
e = y(o, r);
|
|
34
|
+
} catch (n) {
|
|
35
|
+
return console.warn("Tracking ids skipped for this save:", n), { changed: !1, nextSeq: r };
|
|
36
|
+
}
|
|
37
|
+
const { api: i, seqHost: s, hosts: d, plan: c } = e;
|
|
38
|
+
if (!c.changed)
|
|
39
|
+
return { changed: !1, nextSeq: c.nextSeq };
|
|
40
|
+
const a = i.getTemplateModifier();
|
|
41
|
+
let l = 0;
|
|
42
|
+
return d.forEach((n) => {
|
|
43
|
+
const m = n.rawIds.map((p, g) => c.reassigned[l + g] ? c.ids[l + g] : null);
|
|
44
|
+
l += n.rawIds.length, !m.every((p) => p === null) && (n.kind === "element" ? a.modifyHtml(n.node).setAttribute(u, String(m[0])) : a.modifyHtml(n.node).replaceWith(`<!--${I(n.text, m)}-->`));
|
|
45
|
+
}), a.modifyHtml(s).setAttribute(f, String(c.nextSeq)), a.apply(new x("Updated Insider tracking IDs").asHidden()), { changed: !0, nextSeq: c.nextSeq };
|
|
46
|
+
} });
|
|
47
|
+
export {
|
|
48
|
+
H as useEditorTrackingIds
|
|
49
|
+
};
|
|
@@ -1,142 +1,146 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { MERGE_TAGS as
|
|
5
|
-
import { UNSUBSCRIBE_BLOCK_SELECTOR as
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import { escapeHtml as h } from "../../utils/htmlEscape.js";
|
|
9
|
-
const S = "unsubscribe", R = "You can ", M = " from our emails, if you need to.", C = "{-{-UNSUBSCRIBE-LINK-}-}";
|
|
10
|
-
class P {
|
|
1
|
+
var x = Object.defineProperty;
|
|
2
|
+
var B = (c, e, r) => e in c ? x(c, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : c[e] = r;
|
|
3
|
+
var A = (c, e, r) => B(c, typeof e != "symbol" ? e + "" : e, r);
|
|
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 $ {
|
|
11
8
|
constructor() {
|
|
12
|
-
|
|
9
|
+
A(this, "parser");
|
|
13
10
|
this.parser = new DOMParser();
|
|
14
11
|
}
|
|
15
12
|
async migrate(e) {
|
|
16
13
|
try {
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
const s =
|
|
20
|
-
await s.fetchTemplates(), this.migrateLegacyBlocks(
|
|
14
|
+
const r = this.parser.parseFromString(e, "text/html"), t = r.querySelectorAll("td.unsubscribe-block");
|
|
15
|
+
if (t.length) {
|
|
16
|
+
const s = C();
|
|
17
|
+
await s.fetchTemplates(), this.migrateLegacyBlocks(t, s);
|
|
21
18
|
}
|
|
22
|
-
const n = this.repairUnsubscribeLinks(
|
|
23
|
-
return !
|
|
24
|
-
} catch (
|
|
25
|
-
return console.error("UnsubscribeMigrator failed:",
|
|
19
|
+
const n = this.repairUnsubscribeLinks(r);
|
|
20
|
+
return !t.length && !n ? e : r.documentElement.outerHTML;
|
|
21
|
+
} catch (r) {
|
|
22
|
+
return console.error("UnsubscribeMigrator failed:", r), e;
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
|
-
migrateLegacyBlocks(e,
|
|
29
|
-
e.forEach((
|
|
30
|
-
const
|
|
25
|
+
migrateLegacyBlocks(e, r) {
|
|
26
|
+
e.forEach((t) => {
|
|
27
|
+
const n = t.getAttribute("id"), s = this.extractPaddingClass(t), l = t.getAttribute("bgcolor") || "", a = this.extractUnsubscribeContent(t), o = this.getCollectionTypeFromMergeTag(a.linkHref), b = r.getSelectedUnsubscribePagesByCollection(o);
|
|
31
28
|
console.debug("[UnsubscribeMigrator]", {
|
|
32
29
|
mergeTag: a.linkHref,
|
|
33
|
-
collectionType:
|
|
34
|
-
pageIds:
|
|
35
|
-
paddingClass:
|
|
36
|
-
bgColor:
|
|
30
|
+
collectionType: o,
|
|
31
|
+
pageIds: b,
|
|
32
|
+
paddingClass: s,
|
|
33
|
+
bgColor: l
|
|
37
34
|
});
|
|
38
|
-
const
|
|
35
|
+
const u = this.buildUnsubscribeBlock(
|
|
39
36
|
a,
|
|
37
|
+
o,
|
|
40
38
|
b,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
`<table id="tempDoc"><tbody><tr>${o}</tr></tbody></table>`,
|
|
39
|
+
s,
|
|
40
|
+
l
|
|
41
|
+
), i = this.parser.parseFromString(
|
|
42
|
+
`<table id="tempDoc"><tbody><tr>${u}</tr></tbody></table>`,
|
|
46
43
|
"text/html"
|
|
47
|
-
).querySelector(
|
|
48
|
-
|
|
44
|
+
).querySelector(h);
|
|
45
|
+
i && t.parentNode && (i.setAttribute("id", n || ""), t.parentNode.replaceChild(i, t));
|
|
49
46
|
});
|
|
50
47
|
}
|
|
51
|
-
collectBlockTags(e) {
|
|
52
|
-
const t = e.querySelectorAll(`td.unsubscribe-block, ${A}`), r = /* @__PURE__ */ new Set();
|
|
53
|
-
return t.forEach((n) => {
|
|
54
|
-
var a, b, u;
|
|
55
|
-
const s = Number(n.getAttribute(T.PAGE_TYPE)), i = l[s], c = (u = (b = (a = this.findLinkCandidates(n).primary) == null ? void 0 : a.getAttribute("href")) == null ? void 0 : b.match(E)) == null ? void 0 : u[0];
|
|
56
|
-
i ? r.add(i) : c && r.add(l[this.getCollectionTypeFromMergeTag(c)]);
|
|
57
|
-
}), r;
|
|
58
|
-
}
|
|
59
48
|
// Re-derives the typed merge tag from data-unsubscribe-page-type for any v2
|
|
60
49
|
// block whose anchor href is missing or the legacy default. Returns true when
|
|
61
50
|
// at least one href was rewritten. Typed tags and custom URLs are left intact.
|
|
62
51
|
repairUnsubscribeLinks(e) {
|
|
63
|
-
const
|
|
64
|
-
let
|
|
65
|
-
return
|
|
52
|
+
const r = e.querySelectorAll(`${h}[${k.PAGE_TYPE}]`);
|
|
53
|
+
let t = !1;
|
|
54
|
+
return r.forEach((n) => {
|
|
66
55
|
const s = n.querySelector('a[data-unsubscribe-link="true"], a.unsubscribe-link');
|
|
67
56
|
if (!s)
|
|
68
57
|
return;
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
58
|
+
const l = s.getAttribute("href") || "";
|
|
59
|
+
if (l && l !== f.default)
|
|
71
60
|
return;
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
}),
|
|
61
|
+
const a = Number(n.getAttribute(k.PAGE_TYPE)), o = f[a];
|
|
62
|
+
o && (s.setAttribute("href", o), t = !0);
|
|
63
|
+
}), t;
|
|
75
64
|
}
|
|
76
65
|
extractPaddingClass(e) {
|
|
77
|
-
const
|
|
78
|
-
return
|
|
79
|
-
}
|
|
80
|
-
hasVisibleContent(e) {
|
|
81
|
-
var t;
|
|
82
|
-
return !!((t = e.textContent) != null && t.trim() || e.querySelector("img"));
|
|
66
|
+
const t = (e.getAttribute("class") || "").match(/\bes-p\d+\b/);
|
|
67
|
+
return t ? t[0] : "";
|
|
83
68
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
69
|
+
extractUnsubscribeContent(e) {
|
|
70
|
+
var d;
|
|
71
|
+
const r = e.querySelector("a.unsubscribe-link") || e.querySelector('a[href*="unsubscribe"]'), t = (r == null ? void 0 : r.closest("p")) || e.querySelector("p");
|
|
72
|
+
if (!t)
|
|
73
|
+
return {
|
|
74
|
+
textBefore: "You can ",
|
|
75
|
+
linkText: "unsubscribe",
|
|
76
|
+
linkHref: "{{ins-unsubscribe-link}}",
|
|
77
|
+
linkStyle: "",
|
|
78
|
+
textAfter: " from our emails, if you need to.",
|
|
79
|
+
isBold: !1,
|
|
80
|
+
isItalic: !1,
|
|
81
|
+
align: "center",
|
|
82
|
+
paragraphStyle: ""
|
|
83
|
+
};
|
|
84
|
+
const n = e.getAttribute("align") || t.getAttribute("align") || "center", s = t.getAttribute("style") || "";
|
|
85
|
+
if (!r)
|
|
86
|
+
return {
|
|
87
|
+
textBefore: "You can ",
|
|
88
|
+
linkText: "unsubscribe",
|
|
89
|
+
linkHref: "{{ins-unsubscribe-link}}",
|
|
90
|
+
linkStyle: "",
|
|
91
|
+
textAfter: " from our emails, if you need to.",
|
|
92
|
+
isBold: !1,
|
|
93
|
+
isItalic: !1,
|
|
94
|
+
align: n,
|
|
95
|
+
paragraphStyle: s
|
|
96
|
+
};
|
|
97
|
+
const l = ((d = r.textContent) == null ? void 0 : d.trim()) || "unsubscribe", a = r.getAttribute("href") || "{{ins-unsubscribe-link}}", o = r.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");
|
|
98
|
+
return {
|
|
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: n,
|
|
107
|
+
paragraphStyle: s
|
|
99
108
|
};
|
|
100
|
-
if (!c || (a.align = e.getAttribute("align") || c.getAttribute("align") || "center", i || (a.paragraphStyle = c.getAttribute("style") || ""), !s))
|
|
101
|
-
return a;
|
|
102
|
-
if (a.linkText = this.hasVisibleContent(s) ? s.innerHTML.trim() : S, a.linkHref = this.normalizeUnsubscribeHref(s.getAttribute("href") || l.default), a.linkStyle = s.getAttribute("style") || "", i) {
|
|
103
|
-
const b = this.getCollectionTypeFromMergeTag(a.linkHref), u = l[b];
|
|
104
|
-
r.querySelectorAll("a[href]").forEach((o) => {
|
|
105
|
-
var m;
|
|
106
|
-
const d = o.getAttribute("href") || "", g = (m = d.match(E)) == null ? void 0 : m[0];
|
|
107
|
-
g && o.setAttribute("href", B(d, t.has(g) ? g : u));
|
|
108
|
-
}), n.filter((o) => o !== s && !this.hasVisibleContent(o)).forEach((o) => o.replaceWith(...Array.from(o.childNodes))), s.replaceWith(r.ownerDocument.createTextNode(C)), a.footerHtml = r.innerHTML.trim();
|
|
109
|
-
}
|
|
110
|
-
return a;
|
|
111
109
|
}
|
|
112
|
-
buildUnsubscribeBlock(e,
|
|
113
|
-
const
|
|
110
|
+
buildUnsubscribeBlock(e, r, t, n, s) {
|
|
111
|
+
const l = e.linkStyle ? ` style="${e.linkStyle}"` : "", u = `<a ${`href="${Object.values(f).includes(e.linkHref) ? f[r] : 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}"` : "", T = t.length > 0 ? ` ${k.PAGE_LIST}="${t.join(",")}"` : "", E = ` ${k.PAGE_TYPE}="${r}"`, S = "esd-block-text unsubscribe-block-v2 esd-block-unsubscribe esd-unsubscribe-block esd-extension-block";
|
|
114
116
|
return `
|
|
115
117
|
<td
|
|
116
118
|
data-migration="true"
|
|
117
119
|
esd-extension-block-id="unsubscribe-block"
|
|
118
|
-
class="${n ? `${
|
|
119
|
-
${
|
|
120
|
+
class="${n ? `${S} ${n}` : S}"
|
|
121
|
+
${m}${y}${E}${T}
|
|
120
122
|
>
|
|
121
|
-
${d}
|
|
123
|
+
<p path="1"${d}>
|
|
124
|
+
${i}
|
|
125
|
+
</p>
|
|
122
126
|
</td>
|
|
123
127
|
`;
|
|
124
128
|
}
|
|
125
129
|
getCollectionTypeFromMergeTag(e) {
|
|
126
|
-
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;
|
|
127
131
|
}
|
|
128
132
|
normalizeUnsubscribeHref(e) {
|
|
129
|
-
if (Object.values(
|
|
133
|
+
if (Object.values(f).includes(e))
|
|
130
134
|
return e;
|
|
131
|
-
const
|
|
132
|
-
return
|
|
135
|
+
const t = e.match(/{{ins-(?:global-)?(?:preferences-)?unsubscribe-link}}/);
|
|
136
|
+
return t ? t[0] : e.includes("unsubscribe") || e.includes("unsub") ? (console.warn(
|
|
133
137
|
`[UnsubscribeMigrator] Unrecognized unsubscribe href format: "${e}". Defaulting to {{ins-unsubscribe-link}}`
|
|
134
138
|
), "{{ins-unsubscribe-link}}") : e;
|
|
135
139
|
}
|
|
136
140
|
}
|
|
137
|
-
async function
|
|
138
|
-
return new
|
|
141
|
+
async function M(c) {
|
|
142
|
+
return new $().migrate(c);
|
|
139
143
|
}
|
|
140
144
|
export {
|
|
141
|
-
|
|
145
|
+
M as migrateUnsubscribe
|
|
142
146
|
};
|
|
@@ -1,49 +1,48 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { useToaster as
|
|
5
|
-
import { ToasterTypeOptions as
|
|
6
|
-
import { PAGE_TYPES as
|
|
7
|
-
import { useEditorStore as
|
|
8
|
-
import { useUnsubscribeStore as
|
|
9
|
-
import { Block as
|
|
10
|
-
import { getDefaultTemplate as
|
|
11
|
-
import { UNSUBSCRIBE_BLOCK_SELECTOR as
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
[
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
N(), U();
|
|
1
|
+
var y = Object.defineProperty;
|
|
2
|
+
var I = (c, o, e) => o in c ? y(c, o, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[o] = e;
|
|
3
|
+
var g = (c, o, e) => I(c, typeof o != "symbol" ? o + "" : o, e);
|
|
4
|
+
import { useToaster as L } from "../../../composables/useToaster.js";
|
|
5
|
+
import { ToasterTypeOptions as C } from "../../../enums/toaster.js";
|
|
6
|
+
import { PAGE_TYPES as m } from "../../../enums/unsubscribe.js";
|
|
7
|
+
import { useEditorStore as N } from "../../../stores/editor.js";
|
|
8
|
+
import { useUnsubscribeStore as a } from "../../../stores/unsubscribe.js";
|
|
9
|
+
import { Block as U, BlockCompositionType as R, ContextActionType as f, ModificationDescription as u, BlockType as v } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
10
|
+
import { getDefaultTemplate as D } from "./template.js";
|
|
11
|
+
import { UNSUBSCRIBE_BLOCK_SELECTOR as B, DATA_ATTRIBUTES as n, UNSUBSCRIBE_EVENTS as h } from "./utils/constants.js";
|
|
12
|
+
import { parsePageList as S } from "./utils/utils.js";
|
|
13
|
+
const w = "unsubscribe-block", E = 'a[data-unsubscribe-link="true"]', P = "{{ins-unsubscribe-link}}", x = "https://academy.insiderone.com/docs/adding-unsubscribe-pages-into-emails", G = "Removing the unsubscribe text leaves an empty block, but an active unsubscribe link is required. Undo your last action to restore the text, or delete the unsubscribe block entirely.", M = {
|
|
14
|
+
[m.GLOBAL_UNSUBSCRIBE]: "{{ins-global-unsubscribe-link}}",
|
|
15
|
+
[m.SUBSCRIPTION_PREFERENCE_CENTER]: "{{ins-preferences-unsubscribe-link}}"
|
|
16
|
+
}, O = 3;
|
|
17
|
+
let d = null, p = null;
|
|
18
|
+
const A = () => {
|
|
19
|
+
d && (document.removeEventListener(h.SELECT, d), d = null);
|
|
20
|
+
}, T = () => {
|
|
21
|
+
p && (document.removeEventListener(h.CANCEL, p), p = null);
|
|
22
|
+
}, q = () => {
|
|
23
|
+
A(), T();
|
|
25
24
|
};
|
|
26
|
-
class
|
|
25
|
+
class J extends U {
|
|
27
26
|
constructor() {
|
|
28
27
|
super();
|
|
29
|
-
|
|
28
|
+
g(this, "currentNode");
|
|
30
29
|
// Per-block "did this instance have a link last time we saw it?" tracking.
|
|
31
30
|
// Keyed by the stable `data-unsubscribe-block-id` we assign, because
|
|
32
31
|
// ImmutableHtmlNode instances are recreated on every document mutation and
|
|
33
32
|
// can't be used as Map keys directly. A singleton boolean here would be
|
|
34
33
|
// polluted across blocks since Stripo fires onDocumentChanged per-instance.
|
|
35
|
-
|
|
34
|
+
g(this, "linkStateByBlockId", /* @__PURE__ */ new Map());
|
|
36
35
|
// Per-block prepend retry counter for the leading text guard (SD-143097).
|
|
37
|
-
|
|
36
|
+
g(this, "guardAttemptsByBlockId", /* @__PURE__ */ new Map());
|
|
38
37
|
}
|
|
39
38
|
getId() {
|
|
40
|
-
return
|
|
39
|
+
return w;
|
|
41
40
|
}
|
|
42
41
|
getIcon() {
|
|
43
42
|
return "unsubscribe-icon";
|
|
44
43
|
}
|
|
45
44
|
getBlockCompositionType() {
|
|
46
|
-
return
|
|
45
|
+
return R.BLOCK;
|
|
47
46
|
}
|
|
48
47
|
getName() {
|
|
49
48
|
return this.api.translate("Unsubscribe Block");
|
|
@@ -52,16 +51,16 @@ class se extends P {
|
|
|
52
51
|
return this.api.translate("Unsubscribe Block Description");
|
|
53
52
|
}
|
|
54
53
|
getTemplate() {
|
|
55
|
-
return
|
|
54
|
+
return D();
|
|
56
55
|
}
|
|
57
56
|
getContextActionsIds() {
|
|
58
|
-
return [
|
|
57
|
+
return [f.MOVE, f.REMOVE];
|
|
59
58
|
}
|
|
60
59
|
onSelect(e) {
|
|
61
|
-
if (this.currentNode = e,
|
|
60
|
+
if (this.currentNode = e, N().isPreviewModeOpen)
|
|
62
61
|
return;
|
|
63
62
|
const t = this._getOrAssignBlockId(e);
|
|
64
|
-
t && this.linkStateByBlockId.set(t, this._hasUnsubscribeLink(e)), this._setupSelectEventListener(), this._setupCancelEventListener(t), !("getAttribute" in e && e.getAttribute("data-migration")) && (this._resetStoreState(), t && (
|
|
63
|
+
t && this.linkStateByBlockId.set(t, this._hasUnsubscribeLink(e)), this._setupSelectEventListener(), this._setupCancelEventListener(t), !("getAttribute" in e && e.getAttribute("data-migration")) && (this._resetStoreState(), t && (a().pendingBlockId = t), this._loadBlockState(e), this._checkExistingBlocks(), this._openDrawer());
|
|
65
64
|
}
|
|
66
65
|
onCreated(e) {
|
|
67
66
|
this._ensureLeadingTextGuard(e);
|
|
@@ -69,7 +68,7 @@ class se extends P {
|
|
|
69
68
|
onDocumentInit() {
|
|
70
69
|
try {
|
|
71
70
|
const e = this.api.getDocumentRoot();
|
|
72
|
-
e && "querySelectorAll" in e && e.querySelectorAll(
|
|
71
|
+
e && "querySelectorAll" in e && e.querySelectorAll(B).forEach((t) => {
|
|
73
72
|
this._ensureLeadingTextGuard(t);
|
|
74
73
|
});
|
|
75
74
|
} catch {
|
|
@@ -80,11 +79,11 @@ class se extends P {
|
|
|
80
79
|
const t = this._getOrAssignBlockId(e);
|
|
81
80
|
if (!t)
|
|
82
81
|
return;
|
|
83
|
-
const
|
|
84
|
-
this.linkStateByBlockId.get(t) === !0 && !
|
|
82
|
+
const s = this._hasUnsubscribeLink(e);
|
|
83
|
+
this.linkStateByBlockId.get(t) === !0 && !s && this._warnLinkRemoved(), this.linkStateByBlockId.set(t, s);
|
|
85
84
|
}
|
|
86
85
|
onDelete(e) {
|
|
87
|
-
|
|
86
|
+
q(), this._removeBlockTemplatesFromStore(e), this._resetStoreState();
|
|
88
87
|
const t = this._readBlockId(e);
|
|
89
88
|
t && (this.linkStateByBlockId.delete(t), this.guardAttemptsByBlockId.delete(t));
|
|
90
89
|
}
|
|
@@ -96,38 +95,38 @@ class se extends P {
|
|
|
96
95
|
_ensureLeadingTextGuard(e) {
|
|
97
96
|
if (!("querySelector" in e))
|
|
98
97
|
return;
|
|
99
|
-
const t = e.querySelector(
|
|
98
|
+
const t = e.querySelector(E);
|
|
100
99
|
if (!t)
|
|
101
100
|
return;
|
|
102
|
-
let
|
|
101
|
+
let s = t, r = s.parent();
|
|
103
102
|
for (; r && "getTagName" in r && r.getTagName().toLowerCase() !== "p"; )
|
|
104
|
-
|
|
103
|
+
s = r, r = r.parent();
|
|
105
104
|
if (!r || !("getTagName" in r) || r.getTagName().toLowerCase() !== "p")
|
|
106
105
|
return;
|
|
107
|
-
const
|
|
108
|
-
if (!!(
|
|
109
|
-
const
|
|
110
|
-
|
|
106
|
+
const i = s.previousSibling();
|
|
107
|
+
if (!!(i && i.getType() === "text" && i.getTextContent())) {
|
|
108
|
+
const b = this._readBlockId(e);
|
|
109
|
+
b && this.guardAttemptsByBlockId.delete(b);
|
|
111
110
|
return;
|
|
112
111
|
}
|
|
113
|
-
const
|
|
114
|
-
if (!
|
|
112
|
+
const k = this._getOrAssignBlockId(e);
|
|
113
|
+
if (!k)
|
|
115
114
|
return;
|
|
116
|
-
const
|
|
117
|
-
if (!(
|
|
118
|
-
this.guardAttemptsByBlockId.set(
|
|
115
|
+
const _ = this.guardAttemptsByBlockId.get(k) ?? 0;
|
|
116
|
+
if (!(_ >= O)) {
|
|
117
|
+
this.guardAttemptsByBlockId.set(k, _ + 1);
|
|
119
118
|
try {
|
|
120
|
-
this.api.getDocumentModifier().modifyHtml(r).prepend(" ").apply(new
|
|
121
|
-
} catch (
|
|
122
|
-
console.warn("[UnsubscribeBlock] Failed to ensure link text guard:",
|
|
119
|
+
this.api.getDocumentModifier().modifyHtml(r).prepend(" ").apply(new u("Ensure unsubscribe link text guard"));
|
|
120
|
+
} catch (b) {
|
|
121
|
+
console.warn("[UnsubscribeBlock] Failed to ensure link text guard:", b);
|
|
123
122
|
}
|
|
124
123
|
}
|
|
125
124
|
}
|
|
126
125
|
_hasUnsubscribeLink(e) {
|
|
127
|
-
return "querySelector" in e ? !!e.querySelector(
|
|
126
|
+
return "querySelector" in e ? !!e.querySelector(E) : !1;
|
|
128
127
|
}
|
|
129
128
|
_readBlockId(e) {
|
|
130
|
-
return "getAttribute" in e ? e.getAttribute(
|
|
129
|
+
return "getAttribute" in e ? e.getAttribute(n.BLOCK_ID) : null;
|
|
131
130
|
}
|
|
132
131
|
/**
|
|
133
132
|
* Returns the block's stable id, assigning one via the document modifier if
|
|
@@ -141,13 +140,13 @@ class se extends P {
|
|
|
141
140
|
return t;
|
|
142
141
|
if (!("getAttribute" in e))
|
|
143
142
|
return null;
|
|
144
|
-
const
|
|
143
|
+
const s = this._generateNextBlockId();
|
|
145
144
|
try {
|
|
146
|
-
this.api.getDocumentModifier().modifyHtml(e).setAttribute(
|
|
145
|
+
this.api.getDocumentModifier().modifyHtml(e).setAttribute(n.BLOCK_ID, s).apply(new u(`Assign unsubscribe block id ${s}`));
|
|
147
146
|
} catch (r) {
|
|
148
147
|
return console.warn("[UnsubscribeBlock] Failed to assign block id:", r), null;
|
|
149
148
|
}
|
|
150
|
-
return
|
|
149
|
+
return s;
|
|
151
150
|
}
|
|
152
151
|
/**
|
|
153
152
|
* Generates a unique id by scanning the document for the highest existing
|
|
@@ -158,10 +157,10 @@ class se extends P {
|
|
|
158
157
|
let e = 0;
|
|
159
158
|
try {
|
|
160
159
|
const t = this.api.getDocumentRoot();
|
|
161
|
-
t && "querySelectorAll" in t && t.querySelectorAll(
|
|
160
|
+
t && "querySelectorAll" in t && t.querySelectorAll(B).forEach((r) => {
|
|
162
161
|
if ("getAttribute" in r) {
|
|
163
|
-
const
|
|
164
|
-
|
|
162
|
+
const i = r.getAttribute(n.BLOCK_ID), l = i ? parseInt(i) : 0;
|
|
163
|
+
l > e && (e = l);
|
|
165
164
|
}
|
|
166
165
|
});
|
|
167
166
|
} catch {
|
|
@@ -170,14 +169,14 @@ class se extends P {
|
|
|
170
169
|
}
|
|
171
170
|
_warnLinkRemoved() {
|
|
172
171
|
try {
|
|
173
|
-
const { showToaster: e } =
|
|
172
|
+
const { showToaster: e } = L();
|
|
174
173
|
e({
|
|
175
|
-
type:
|
|
176
|
-
message: this.api.translate(
|
|
174
|
+
type: C.Warning,
|
|
175
|
+
message: this.api.translate(G),
|
|
177
176
|
actionButton: {
|
|
178
177
|
text: this.api.translate("Visit Academy"),
|
|
179
178
|
onClick: () => {
|
|
180
|
-
window.open(
|
|
179
|
+
window.open(x, "_blank", "noopener,noreferrer");
|
|
181
180
|
}
|
|
182
181
|
}
|
|
183
182
|
});
|
|
@@ -186,62 +185,55 @@ class se extends P {
|
|
|
186
185
|
}
|
|
187
186
|
}
|
|
188
187
|
_setupSelectEventListener() {
|
|
189
|
-
|
|
190
|
-
const t = e, { collectionType:
|
|
191
|
-
this._updateBlock(
|
|
192
|
-
}, document.addEventListener(
|
|
188
|
+
A(), d = (e) => {
|
|
189
|
+
const t = e, { collectionType: s, selectedPages: r } = t.detail;
|
|
190
|
+
this._updateBlock(s, r.join(","));
|
|
191
|
+
}, document.addEventListener(h.SELECT, d);
|
|
193
192
|
}
|
|
194
193
|
_setupCancelEventListener(e) {
|
|
195
|
-
|
|
196
|
-
const { detail:
|
|
197
|
-
((
|
|
198
|
-
}, document.addEventListener(
|
|
194
|
+
T(), p = (t) => {
|
|
195
|
+
const { detail: s } = t;
|
|
196
|
+
((s == null ? void 0 : s.blockId) ?? null) === e && this._handleCancel();
|
|
197
|
+
}, document.addEventListener(h.CANCEL, p);
|
|
199
198
|
}
|
|
200
199
|
_handleCancel() {
|
|
201
200
|
try {
|
|
202
201
|
if (!this.currentNode)
|
|
203
202
|
return;
|
|
204
|
-
this.api.getDocumentModifier().modifyHtml(this.currentNode).replaceWith(`<${
|
|
203
|
+
this.api.getDocumentModifier().modifyHtml(this.currentNode).replaceWith(`<${v.EMPTY_CONTAINER}/>`).apply(new u("Removed unsubscribe block due to cancel"));
|
|
205
204
|
} catch (e) {
|
|
206
205
|
console.warn("[UnsubscribeBlock] Failed to remove unsubscribe block:", e);
|
|
207
206
|
}
|
|
208
207
|
}
|
|
209
208
|
_updateBlock(e, t) {
|
|
210
|
-
var a;
|
|
211
209
|
if (!this.currentNode || !("querySelector" in this.currentNode))
|
|
212
210
|
return;
|
|
213
|
-
const
|
|
214
|
-
if (!
|
|
211
|
+
const s = this.currentNode.querySelector(E);
|
|
212
|
+
if (!s)
|
|
215
213
|
return;
|
|
216
|
-
const r = this._getMergeTag(e)
|
|
217
|
-
|
|
218
|
-
var T;
|
|
219
|
-
if (!("getAttribute" in m) || m.getAttribute("data-unsubscribe-link") === "true")
|
|
220
|
-
return;
|
|
221
|
-
const S = m.getAttribute("href") ?? "", A = (T = S.match(I)) == null ? void 0 : T[0];
|
|
222
|
-
A && p.includes(A) && s.modifyHtml(m).setAttribute("href", q(S, r));
|
|
223
|
-
}), s.modifyHtml(this.currentNode).setAttribute(o.PAGE_TYPE, e.toString()).setAttribute(o.PAGE_LIST, t), s.apply(new k(`Updated unsubscribe link to ${r}`));
|
|
214
|
+
const r = this._getMergeTag(e);
|
|
215
|
+
this.api.getDocumentModifier().modifyHtml(s).setAttribute("href", r).apply(new u(`Updated unsubscribe link to ${r}`)), this.api.getDocumentModifier().modifyHtml(this.currentNode).setAttribute(n.PAGE_TYPE, e.toString()).setAttribute(n.PAGE_LIST, t).apply(new u("Updated unsubscribe block metadata"));
|
|
224
216
|
}
|
|
225
217
|
_getMergeTag(e) {
|
|
226
|
-
return
|
|
218
|
+
return M[e] ?? P;
|
|
227
219
|
}
|
|
228
220
|
_openDrawer() {
|
|
229
221
|
if (!(this.currentNode && this.currentNode.getAttribute("data-unsubscribe-page-type")))
|
|
230
222
|
try {
|
|
231
|
-
const e =
|
|
223
|
+
const e = a();
|
|
232
224
|
e.typeSelectionDrawerStatus = !0;
|
|
233
225
|
} catch (e) {
|
|
234
226
|
console.error("[UnsubscribeBlock] Failed to open drawer:", e);
|
|
235
227
|
}
|
|
236
228
|
}
|
|
237
229
|
_checkExistingBlocks() {
|
|
238
|
-
const e =
|
|
239
|
-
e.isGlobalUnsubscribeDisabled = !1, e.isSubscriptionPreferencesCenterDisabled = !1, this.api.getDocumentRoot().querySelectorAll(
|
|
240
|
-
if ("getAttribute" in
|
|
241
|
-
const r =
|
|
230
|
+
const e = a();
|
|
231
|
+
e.isGlobalUnsubscribeDisabled = !1, e.isSubscriptionPreferencesCenterDisabled = !1, this.api.getDocumentRoot().querySelectorAll(B).forEach((s) => {
|
|
232
|
+
if ("getAttribute" in s) {
|
|
233
|
+
const r = s.getAttribute(n.PAGE_TYPE);
|
|
242
234
|
if (r) {
|
|
243
|
-
const
|
|
244
|
-
|
|
235
|
+
const i = Number(r);
|
|
236
|
+
i === m.GLOBAL_UNSUBSCRIBE ? e.isGlobalUnsubscribeDisabled = !0 : i === m.SUBSCRIPTION_PREFERENCE_CENTER && (e.isSubscriptionPreferencesCenterDisabled = !0);
|
|
245
237
|
}
|
|
246
238
|
}
|
|
247
239
|
});
|
|
@@ -249,27 +241,27 @@ class se extends P {
|
|
|
249
241
|
async _loadBlockState(e) {
|
|
250
242
|
if (!("getAttribute" in e))
|
|
251
243
|
return;
|
|
252
|
-
const t = e.getAttribute(
|
|
253
|
-
if (!t || !
|
|
244
|
+
const t = e.getAttribute(n.PAGE_TYPE), s = e.getAttribute(n.PAGE_LIST);
|
|
245
|
+
if (!t || !s)
|
|
254
246
|
return;
|
|
255
|
-
const r =
|
|
256
|
-
await r.fetchTemplates(), r.setCollectionWithoutAutoSelection(
|
|
247
|
+
const r = a(), i = Number(t), l = S(s);
|
|
248
|
+
await r.fetchTemplates(), r.setCollectionWithoutAutoSelection(i), r.loadSelectedTemplates(l);
|
|
257
249
|
}
|
|
258
250
|
_resetStoreState() {
|
|
259
|
-
|
|
251
|
+
a().$reset();
|
|
260
252
|
}
|
|
261
253
|
_removeBlockTemplatesFromStore(e) {
|
|
262
254
|
if (!("getAttribute" in e))
|
|
263
255
|
return;
|
|
264
|
-
const t = e.getAttribute(
|
|
256
|
+
const t = e.getAttribute(n.PAGE_LIST);
|
|
265
257
|
if (!t)
|
|
266
258
|
return;
|
|
267
|
-
const
|
|
268
|
-
|
|
259
|
+
const s = a(), r = S(t);
|
|
260
|
+
s.removeUnsubscribePages(r);
|
|
269
261
|
}
|
|
270
262
|
}
|
|
271
263
|
export {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
264
|
+
w as UNSUBSCRIBE_BLOCK_ID,
|
|
265
|
+
J as UnsubscribeBlock,
|
|
266
|
+
q as disposeUnsubscribeListeners
|
|
275
267
|
};
|
|
@@ -5,11 +5,10 @@ const s = {
|
|
|
5
5
|
PAGE_TYPE: "data-unsubscribe-page-type",
|
|
6
6
|
PAGE_LIST: "data-unsubscribe-page-list",
|
|
7
7
|
BLOCK_ID: "data-unsubscribe-block-id"
|
|
8
|
-
},
|
|
8
|
+
}, c = ".unsubscribe-block-v2", u = 'a[data-unsubscribe-link="true"], a.unsubscribe-link';
|
|
9
9
|
export {
|
|
10
10
|
b as DATA_ATTRIBUTES,
|
|
11
|
-
|
|
11
|
+
c as UNSUBSCRIBE_BLOCK_SELECTOR,
|
|
12
12
|
s as UNSUBSCRIBE_EVENTS,
|
|
13
|
-
|
|
14
|
-
E as UNSUBSCRIBE_MERGE_TAG_REGEX
|
|
13
|
+
u as UNSUBSCRIBE_LINK_SELECTOR
|
|
15
14
|
};
|
package/dist/package.json.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const
|
|
2
|
-
version:
|
|
3
|
-
guido:
|
|
1
|
+
const e = "3.24.0-beta.e2e5de9", o = { stripo: { version: "2.83.1" } }, s = {
|
|
2
|
+
version: e,
|
|
3
|
+
guido: o
|
|
4
4
|
};
|
|
5
5
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
s as default,
|
|
7
|
+
o as guido,
|
|
8
|
+
e as version
|
|
9
9
|
};
|
|
@@ -9,5 +9,4 @@ export declare const DATA_ATTRIBUTES: {
|
|
|
9
9
|
readonly BLOCK_ID: "data-unsubscribe-block-id";
|
|
10
10
|
};
|
|
11
11
|
export declare const UNSUBSCRIBE_BLOCK_SELECTOR = ".unsubscribe-block-v2";
|
|
12
|
-
export declare const UNSUBSCRIBE_MERGE_TAG_REGEX: RegExp;
|
|
13
12
|
export declare const UNSUBSCRIBE_LINK_SELECTOR = "a[data-unsubscribe-link=\"true\"], a.unsubscribe-link";
|
|
@@ -20,6 +20,25 @@ export declare function readTrackSeq(html: string): number;
|
|
|
20
20
|
* Scans the document because a rewrite can strip the seq host but keep the ids.
|
|
21
21
|
*/
|
|
22
22
|
export declare function readTrackFloor(html: string, persistedCounter?: number): number;
|
|
23
|
+
export interface TrackingIdPlan {
|
|
24
|
+
/** Final id per anchor, in the order the raw values were given. */
|
|
25
|
+
ids: number[];
|
|
26
|
+
reassigned: boolean[];
|
|
27
|
+
nextSeq: number;
|
|
28
|
+
seqChanged: boolean;
|
|
29
|
+
changed: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The id rule shared by the string transform and the editor-model writer: `rawIds` are the
|
|
33
|
+
* anchors' current `data-ins-track-id` values in document order ('' when absent).
|
|
34
|
+
*/
|
|
35
|
+
export declare function planTrackingIds(rawIds: readonly string[], persistedSeq: number, floor?: number): TrackingIdPlan;
|
|
36
|
+
/** Reads a `data-ins-track-seq` attribute value the way readTrackSeq reads it from HTML. */
|
|
37
|
+
export declare function parseTrackSeq(value: string | null): number;
|
|
38
|
+
/** The `data-ins-track-id` value of every `<a>` opening tag in `html`, in order ('' when absent). */
|
|
39
|
+
export declare function readAnchorTrackIds(html: string): string[];
|
|
40
|
+
/** Writes `ids[i]` onto the i-th `<a>` opening tag of `html`; `null` or a missing entry leaves it untouched. */
|
|
41
|
+
export declare function writeAnchorTrackIds(html: string, ids: readonly (number | null)[]): string;
|
|
23
42
|
/**
|
|
24
43
|
* Ensures every <a> opening tag carries a unique positive-integer id and the
|
|
25
44
|
* document records the id high-water mark. Ids are minted above
|
|
@@ -1,56 +1,90 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
3
|
-
const
|
|
4
|
-
return Number.isSafeInteger(
|
|
5
|
-
}
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const o = (r = s.exec(e)) == null ? void 0 : r[0];
|
|
11
|
-
return o ? S.exec(o) : null;
|
|
12
|
-
}, t = n(b) ?? n(N), c = (t == null ? void 0 : t[1]) ?? (t == null ? void 0 : t[2]) ?? (t == null ? void 0 : t[3]) ?? ((a = _.exec(e)) == null ? void 0 : a[1]) ?? "";
|
|
13
|
-
return m(c);
|
|
14
|
-
}
|
|
15
|
-
function P(e, n = 0) {
|
|
16
|
-
let t = 0;
|
|
17
|
-
[...e.matchAll(f)].forEach(([a]) => {
|
|
18
|
-
const s = I.exec(a), o = s ? s[1] ?? s[2] ?? s[3] ?? "" : "";
|
|
19
|
-
w.test(o) && (t = Math.max(t, Number(o)));
|
|
1
|
+
const l = "data-ins-track-id", E = "data-ins-track-seq", A = `(?:[^>"']|"[^"]*"|'[^']*')*`, k = new RegExp(`<a\\b${A}>`, "gi"), R = new RegExp(`<body\\b${A}>`, "i"), _ = new RegExp(`<html\\b${A}>`, "i"), m = new RegExp(`\\b${l}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i"), f = new RegExp(`\\b${E}\\s*=\\s*(?:"(\\d+)"|'(\\d+)'|(\\d+))`, "i"), p = "ins-track-seq", x = new RegExp(`<!--\\s*${p}:(\\d+)\\s*-->`, "i"), $ = /^[1-9][0-9]{0,14}$/, q = 999999999999999;
|
|
2
|
+
function I(e) {
|
|
3
|
+
const c = Number(e);
|
|
4
|
+
return Number.isSafeInteger(c) && c > 0 ? c : 0;
|
|
5
|
+
}
|
|
6
|
+
function T(e) {
|
|
7
|
+
return [...e.matchAll(k)].map((c) => {
|
|
8
|
+
const [n] = c, t = m.exec(n), r = t ? t[1] ?? t[2] ?? t[3] ?? "" : "";
|
|
9
|
+
return { index: c.index, tag: n, attrMatch: t, rawValue: r };
|
|
20
10
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
11
|
+
}
|
|
12
|
+
function b(e) {
|
|
13
|
+
var r;
|
|
14
|
+
const c = (s) => {
|
|
15
|
+
var a;
|
|
16
|
+
const o = (a = s.exec(e)) == null ? void 0 : a[0];
|
|
17
|
+
return o ? f.exec(o) : null;
|
|
18
|
+
}, n = c(R) ?? c(_), t = (n == null ? void 0 : n[1]) ?? (n == null ? void 0 : n[2]) ?? (n == null ? void 0 : n[3]) ?? ((r = x.exec(e)) == null ? void 0 : r[1]) ?? "";
|
|
19
|
+
return I(t);
|
|
20
|
+
}
|
|
21
|
+
function h(e, c = 0) {
|
|
22
|
+
let n = 0;
|
|
23
|
+
T(e).forEach(({ rawValue: r }) => {
|
|
24
|
+
$.test(r) && (n = Math.max(n, Number(r)));
|
|
25
|
+
});
|
|
26
|
+
const t = Number.isSafeInteger(c) && c > 0 ? c : 0;
|
|
27
|
+
return Math.max(b(e), n, t);
|
|
28
|
+
}
|
|
29
|
+
function w(e, c) {
|
|
30
|
+
const n = `${E}="${c}"`, t = R.exec(e) ?? _.exec(e);
|
|
31
|
+
if (t) {
|
|
32
|
+
const [s] = t, o = f.exec(s), a = o ? s.replace(o[0], n) : s.replace(/\/?>$/, (u) => ` ${n}${u}`);
|
|
33
|
+
return e.slice(0, t.index) + a + e.slice(t.index + s.length);
|
|
29
34
|
}
|
|
30
|
-
const
|
|
31
|
-
return
|
|
35
|
+
const r = `<!--${p}:${c}-->`;
|
|
36
|
+
return x.test(e) ? e.replace(x, r) : `${r}${e}`;
|
|
32
37
|
}
|
|
33
|
-
function
|
|
34
|
-
const
|
|
35
|
-
return
|
|
38
|
+
function M(e, c, n) {
|
|
39
|
+
const t = `${l}="${n}"`;
|
|
40
|
+
return c ? e.replace(c[0], t) : e.replace(/^<a\b/i, (r) => `${r} ${t}`);
|
|
36
41
|
}
|
|
37
|
-
function C(e, n = 0) {
|
|
42
|
+
function C(e, c, n = 0) {
|
|
38
43
|
const t = /* @__PURE__ */ new Set();
|
|
39
|
-
let
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
let r = 0;
|
|
45
|
+
const s = e.map((i) => {
|
|
46
|
+
if (!$.test(i) || t.has(Number(i)))
|
|
47
|
+
return null;
|
|
48
|
+
const d = Number(i);
|
|
49
|
+
return t.add(d), r = Math.max(r, d), d;
|
|
50
|
+
}), o = Number.isSafeInteger(n) && n > 0 && n < q ? n : 0;
|
|
51
|
+
let a = Math.max(c, r, o);
|
|
52
|
+
const u = s.map((i) => i === null), S = s.map((i) => i !== null ? i : (a += 1, a)), g = a > 0 && c !== a;
|
|
53
|
+
return { ids: S, reassigned: u, nextSeq: a, seqChanged: g, changed: g || u.includes(!0) };
|
|
54
|
+
}
|
|
55
|
+
function D(e) {
|
|
56
|
+
return e !== null && /^\d+$/.test(e) ? I(e) : 0;
|
|
57
|
+
}
|
|
58
|
+
function N(e, c, n) {
|
|
59
|
+
let t = "", r = 0;
|
|
60
|
+
return c.forEach((s, o) => {
|
|
61
|
+
const a = n[o] ?? null;
|
|
62
|
+
t += e.slice(r, s.index), t += a === null ? s.tag : M(s.tag, s.attrMatch, a), r = s.index + s.tag.length;
|
|
63
|
+
}), t + e.slice(r);
|
|
64
|
+
}
|
|
65
|
+
function P(e) {
|
|
66
|
+
return T(e).map((c) => c.rawValue);
|
|
67
|
+
}
|
|
68
|
+
function K(e, c) {
|
|
69
|
+
return N(e, T(e), c);
|
|
70
|
+
}
|
|
71
|
+
function O(e, c = 0) {
|
|
72
|
+
const n = T(e), t = C(n.map((s) => s.rawValue), b(e), c);
|
|
73
|
+
let r = N(
|
|
74
|
+
e,
|
|
75
|
+
n,
|
|
76
|
+
t.ids.map((s, o) => t.reassigned[o] ? s : null)
|
|
77
|
+
);
|
|
78
|
+
return t.seqChanged && (r = w(r, t.nextSeq)), { html: r, changed: t.changed, nextSeq: t.nextSeq };
|
|
49
79
|
}
|
|
50
80
|
export {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
81
|
+
l as TRACK_ID_ATTRIBUTE,
|
|
82
|
+
E as TRACK_SEQ_ATTRIBUTE,
|
|
83
|
+
O as assignTrackingIds,
|
|
84
|
+
D as parseTrackSeq,
|
|
85
|
+
C as planTrackingIds,
|
|
86
|
+
P as readAnchorTrackIds,
|
|
87
|
+
h as readTrackFloor,
|
|
88
|
+
b as readTrackSeq,
|
|
89
|
+
K as writeAnchorTrackIds
|
|
56
90
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useActionsApi as
|
|
2
|
-
import { useConfig as
|
|
1
|
+
import { useActionsApi as x } from "../composables/useActionsApi.js";
|
|
2
|
+
import { useConfig as D } from "../composables/useConfig.js";
|
|
3
|
+
import { useEditorTrackingIds as F } from "../composables/useEditorTrackingIds.js";
|
|
3
4
|
import { useHtmlCompiler as I } from "../composables/useHtmlCompiler.js";
|
|
4
5
|
import { useRecommendationExtensionStore as b } from "../extensions/Blocks/Recommendation/store/recommendation.js";
|
|
5
6
|
import { toBlockUrlConfig as R } from "../extensions/Blocks/Recommendation/utils/blockUrlConfig.js";
|
|
@@ -7,10 +8,9 @@ import { DATA_ATTRIBUTES as g } from "../extensions/Blocks/Unsubscribe/utils/con
|
|
|
7
8
|
import { parsePageList as U } from "../extensions/Blocks/Unsubscribe/utils/utils.js";
|
|
8
9
|
import { useDynamicContentStore as L } from "../stores/dynamic-content.js";
|
|
9
10
|
import { useEditorStore as N } from "../stores/editor.js";
|
|
10
|
-
import { useUnsubscribeStore as
|
|
11
|
-
import { isPlainObject as
|
|
12
|
-
|
|
13
|
-
function O(n) {
|
|
11
|
+
import { useUnsubscribeStore as z } from "../stores/unsubscribe.js";
|
|
12
|
+
import { isPlainObject as v } from "./genericUtil.js";
|
|
13
|
+
function M(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);
|
|
@@ -26,16 +26,16 @@ async function S(n) {
|
|
|
26
26
|
const i = e.getAttribute("recommendation-id"), t = i ? Number(i) : NaN;
|
|
27
27
|
if (!Number.isFinite(t))
|
|
28
28
|
return;
|
|
29
|
-
const
|
|
30
|
-
if (!
|
|
29
|
+
const c = e.getAttribute("esd-ext-config");
|
|
30
|
+
if (!c)
|
|
31
31
|
return;
|
|
32
32
|
let a;
|
|
33
33
|
try {
|
|
34
|
-
a = JSON.parse(
|
|
34
|
+
a = JSON.parse(c);
|
|
35
35
|
} catch {
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
v(a) && r.seedBlockUrlConfig(t, R(a));
|
|
39
39
|
});
|
|
40
40
|
try {
|
|
41
41
|
await r.fetchRecommendationCreateData();
|
|
@@ -46,40 +46,37 @@ async function S(n) {
|
|
|
46
46
|
);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
const
|
|
50
|
-
const n = L(),
|
|
49
|
+
const Y = () => {
|
|
50
|
+
const n = L(), s = N(), o = z(), { getCompiledEmail: r, getTemplateData: e } = x(), { writeTrackingIds: i } = F(), { compileHtml: t, compileAmpHtml: c } = I(), { isFeatureEnabled: a } = D();
|
|
51
51
|
return {
|
|
52
52
|
prepareTemplateDetails: async (h) => {
|
|
53
|
-
let { html:
|
|
54
|
-
if (a("linkTrackingIds"))
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
console.error("Tracking-id step failed, saving anyway:", d);
|
|
60
|
-
}
|
|
61
|
-
const { html: T, ampHtml: p = "", ampErrors: A = [] } = await r({
|
|
53
|
+
let { html: m, css: p, syncModulesIds: u = [] } = h ?? await e();
|
|
54
|
+
if (a("linkTrackingIds")) {
|
|
55
|
+
const { changed: P, nextSeq: E } = i(s.trackIdSessionFloor);
|
|
56
|
+
s.trackIdSessionFloor = E, P && ({ html: m, css: p, syncModulesIds: u = [] } = await e());
|
|
57
|
+
}
|
|
58
|
+
const { html: T, ampHtml: d = "", ampErrors: w = [] } = await r({
|
|
62
59
|
minimize: !0,
|
|
63
60
|
resetDataSavedFlag: !1
|
|
64
61
|
});
|
|
65
|
-
o.selectedUnsubscribePages.length && await o.fetchTemplates(), await S(
|
|
66
|
-
const { compiledHtml:
|
|
62
|
+
o.selectedUnsubscribePages.length && await o.fetchTemplates(), await S(m);
|
|
63
|
+
const { compiledHtml: A, stats: l, appliedRules: y } = t(T), C = d && c(d).compiledHtml, k = n.getSelectedDynamicContentList, H = b(), f = M(m);
|
|
67
64
|
return console.debug("HTML Compilation Stats:", {
|
|
68
65
|
originalSize: l.originalSize,
|
|
69
66
|
compiledSize: l.compiledSize,
|
|
70
67
|
reduction: `${l.reductionPercentage.toFixed(2)}%`,
|
|
71
|
-
appliedRules:
|
|
68
|
+
appliedRules: y,
|
|
72
69
|
executionTime: `${l.executionTime.toFixed(2)}ms`
|
|
73
70
|
}), {
|
|
74
71
|
dynamicContentList: k,
|
|
75
|
-
compiledHtml:
|
|
76
|
-
rawHtml:
|
|
77
|
-
css:
|
|
78
|
-
ampHtml:
|
|
79
|
-
ampErrors:
|
|
80
|
-
modules:
|
|
72
|
+
compiledHtml: A,
|
|
73
|
+
rawHtml: m,
|
|
74
|
+
css: p,
|
|
75
|
+
ampHtml: C,
|
|
76
|
+
ampErrors: w,
|
|
77
|
+
modules: u.map(Number),
|
|
81
78
|
recommendation: {
|
|
82
|
-
campaignUrls:
|
|
79
|
+
campaignUrls: H.recommendationCampaignUrls,
|
|
83
80
|
configs: {}
|
|
84
81
|
},
|
|
85
82
|
unsubscribe: {
|
|
@@ -94,6 +91,6 @@ const Z = () => {
|
|
|
94
91
|
};
|
|
95
92
|
};
|
|
96
93
|
export {
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
M as getHtmlReferencedUnsubscribePages,
|
|
95
|
+
Y as useTemplatePreparation
|
|
99
96
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useinsider/guido",
|
|
3
|
-
"version": "3.24.0-beta.
|
|
3
|
+
"version": "3.24.0-beta.e2e5de9",
|
|
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",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const swapMergeTagInHref: (href: string, mergeTag: string) => string;
|