@useinsider/guido 3.4.1-beta.ac571e2 → 3.4.1-beta.c04b4e7
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,31 +1,34 @@
|
|
|
1
1
|
var d = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
var _ = (n, i, e) => i in n ? d(n, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[i] = e;
|
|
3
|
+
var c = (n, i, e) => _(n, typeof i != "symbol" ? i + "" : i, e);
|
|
4
|
+
import { useToaster as L } from "../../../composables/useToaster.js";
|
|
5
|
+
import { ToasterTypeOptions as S } from "../../../enums/toaster.js";
|
|
6
|
+
import { PAGE_TYPES as b } from "../../../enums/unsubscribe.js";
|
|
7
|
+
import { useUnsubscribeStore as a } from "../../../stores/unsubscribe.js";
|
|
8
|
+
import { Block as g, BlockCompositionType as v, BlockType as k, ModificationDescription as E } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
9
|
+
import { getDefaultTemplate as f } from "./template.js";
|
|
10
|
+
import { UNSUBSCRIBE_EVENTS as u, DATA_ATTRIBUTES as o } from "./utils/constants.js";
|
|
11
|
+
import { parsePageList as h } from "./utils/utils.js";
|
|
12
|
+
const T = "unsubscribe-block", p = 'a[data-unsubscribe-link="true"]', B = ".unsubscribe-block-v2", U = "{{ins-unsubscribe-link}}", C = "https://academy.insiderone.com/docs/adding-unsubscribe-pages-into-emails", A = "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.", N = {
|
|
13
|
+
[b.GLOBAL_UNSUBSCRIBE]: "{{ins-global-unsubscribe-link}}",
|
|
14
|
+
[b.SUBSCRIPTION_PREFERENCE_CENTER]: "{{ins-preferences-unsubscribe-link}}"
|
|
13
15
|
};
|
|
14
|
-
class
|
|
16
|
+
class x extends g {
|
|
15
17
|
constructor() {
|
|
16
18
|
super();
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
c(this, "selectEventListener", null);
|
|
20
|
+
c(this, "cancelEventListener", null);
|
|
21
|
+
c(this, "currentNode");
|
|
22
|
+
c(this, "hadUnsubscribeLink", !1);
|
|
20
23
|
}
|
|
21
24
|
getId() {
|
|
22
|
-
return
|
|
25
|
+
return T;
|
|
23
26
|
}
|
|
24
27
|
getIcon() {
|
|
25
28
|
return "unsubscribe-icon";
|
|
26
29
|
}
|
|
27
30
|
getBlockCompositionType() {
|
|
28
|
-
return
|
|
31
|
+
return v.BLOCK;
|
|
29
32
|
}
|
|
30
33
|
getName() {
|
|
31
34
|
return this.api.translate("Unsubscribe Block");
|
|
@@ -34,39 +37,63 @@ class I extends _ {
|
|
|
34
37
|
return this.api.translate("Unsubscribe Block Description");
|
|
35
38
|
}
|
|
36
39
|
getTemplate() {
|
|
37
|
-
return
|
|
40
|
+
return f();
|
|
38
41
|
}
|
|
39
42
|
onSelect(e) {
|
|
40
|
-
this.currentNode = e, !("getAttribute" in e && e.getAttribute("data-migration")) && (this._resetStoreState(), this._loadBlockState(e), this._setupSelectEventListener(), this._setupCancelEventListener(), this._checkExistingBlocks(), this._openDrawer());
|
|
43
|
+
this.currentNode = e, this.hadUnsubscribeLink = this._hasUnsubscribeLink(e), !("getAttribute" in e && e.getAttribute("data-migration")) && (this._resetStoreState(), this._loadBlockState(e), this._setupSelectEventListener(), this._setupCancelEventListener(), this._checkExistingBlocks(), this._openDrawer());
|
|
44
|
+
}
|
|
45
|
+
onDocumentChanged(e) {
|
|
46
|
+
const t = this._hasUnsubscribeLink(e);
|
|
47
|
+
this.hadUnsubscribeLink && !t && this._warnLinkRemoved(), this.hadUnsubscribeLink = t;
|
|
41
48
|
}
|
|
42
49
|
onDelete(e) {
|
|
43
|
-
this._removeEventListeners(), this._removeBlockTemplatesFromStore(e), this._resetStoreState();
|
|
50
|
+
this._removeEventListeners(), this._removeBlockTemplatesFromStore(e), this._resetStoreState(), this.hadUnsubscribeLink = !1;
|
|
44
51
|
}
|
|
45
52
|
onDestroy() {
|
|
46
|
-
this._removeEventListeners(), this.currentNode = void 0;
|
|
53
|
+
this._removeEventListeners(), this.currentNode = void 0, this.hadUnsubscribeLink = !1;
|
|
54
|
+
}
|
|
55
|
+
_hasUnsubscribeLink(e) {
|
|
56
|
+
return "querySelector" in e ? !!e.querySelector(p) : !1;
|
|
57
|
+
}
|
|
58
|
+
_warnLinkRemoved() {
|
|
59
|
+
try {
|
|
60
|
+
const { showToaster: e } = L();
|
|
61
|
+
e({
|
|
62
|
+
type: S.Warning,
|
|
63
|
+
message: this.api.translate(A),
|
|
64
|
+
actionButton: {
|
|
65
|
+
text: this.api.translate("Visit Academy"),
|
|
66
|
+
onClick: () => {
|
|
67
|
+
window.open(C, "_blank", "noopener,noreferrer");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
} catch (e) {
|
|
72
|
+
console.error("[UnsubscribeBlock] Failed to show warning toaster:", e);
|
|
73
|
+
}
|
|
47
74
|
}
|
|
48
75
|
_setupSelectEventListener() {
|
|
49
76
|
this._removeSelectEventListener(), this.selectEventListener = (e) => {
|
|
50
|
-
const
|
|
51
|
-
this._updateBlock(
|
|
52
|
-
}, document.addEventListener(
|
|
77
|
+
const t = e, { collectionType: r, selectedPages: s } = t.detail;
|
|
78
|
+
this._updateBlock(r, s.join(","));
|
|
79
|
+
}, document.addEventListener(u.SELECT, this.selectEventListener);
|
|
53
80
|
}
|
|
54
81
|
_removeSelectEventListener() {
|
|
55
|
-
this.selectEventListener && (document.removeEventListener(
|
|
82
|
+
this.selectEventListener && (document.removeEventListener(u.SELECT, this.selectEventListener), this.selectEventListener = null);
|
|
56
83
|
}
|
|
57
84
|
_setupCancelEventListener() {
|
|
58
85
|
this._removeCancelEventListener(), this.cancelEventListener = () => {
|
|
59
86
|
this._handleCancel();
|
|
60
|
-
}, document.addEventListener(
|
|
87
|
+
}, document.addEventListener(u.CANCEL, this.cancelEventListener);
|
|
61
88
|
}
|
|
62
89
|
_removeCancelEventListener() {
|
|
63
|
-
this.cancelEventListener && (document.removeEventListener(
|
|
90
|
+
this.cancelEventListener && (document.removeEventListener(u.CANCEL, this.cancelEventListener), this.cancelEventListener = null);
|
|
64
91
|
}
|
|
65
92
|
_handleCancel() {
|
|
66
93
|
try {
|
|
67
94
|
if (!this.currentNode)
|
|
68
95
|
return;
|
|
69
|
-
this.api.getDocumentModifier().modifyHtml(this.currentNode).replaceWith(`<${
|
|
96
|
+
this.api.getDocumentModifier().modifyHtml(this.currentNode).replaceWith(`<${k.EMPTY_CONTAINER}/>`).apply(new E("Removed unsubscribe block due to cancel"));
|
|
70
97
|
} catch (e) {
|
|
71
98
|
console.warn("[UnsubscribeBlock] Failed to remove unsubscribe block:", e);
|
|
72
99
|
}
|
|
@@ -74,35 +101,35 @@ class I extends _ {
|
|
|
74
101
|
_removeEventListeners() {
|
|
75
102
|
this._removeSelectEventListener(), this._removeCancelEventListener();
|
|
76
103
|
}
|
|
77
|
-
_updateBlock(e,
|
|
104
|
+
_updateBlock(e, t) {
|
|
78
105
|
if (!this.currentNode || !("querySelector" in this.currentNode))
|
|
79
106
|
return;
|
|
80
|
-
const
|
|
81
|
-
if (!
|
|
107
|
+
const r = this.currentNode.querySelector(p);
|
|
108
|
+
if (!r)
|
|
82
109
|
return;
|
|
83
|
-
const
|
|
84
|
-
this.api.getDocumentModifier().modifyHtml(
|
|
110
|
+
const s = this._getMergeTag(e);
|
|
111
|
+
this.api.getDocumentModifier().modifyHtml(r).setAttribute("href", s).apply(new E(`Updated unsubscribe link to ${s}`)), this.api.getDocumentModifier().modifyHtml(this.currentNode).setAttribute(o.PAGE_TYPE, e.toString()).setAttribute(o.PAGE_LIST, t).apply(new E("Updated unsubscribe block metadata"));
|
|
85
112
|
}
|
|
86
113
|
_getMergeTag(e) {
|
|
87
|
-
return
|
|
114
|
+
return N[e] ?? U;
|
|
88
115
|
}
|
|
89
116
|
_openDrawer() {
|
|
90
117
|
if (!(this.currentNode && this.currentNode.getAttribute("data-unsubscribe-page-type")))
|
|
91
118
|
try {
|
|
92
|
-
const e =
|
|
119
|
+
const e = a();
|
|
93
120
|
e.typeSelectionDrawerStatus = !0;
|
|
94
121
|
} catch (e) {
|
|
95
122
|
console.error("[UnsubscribeBlock] Failed to open drawer:", e);
|
|
96
123
|
}
|
|
97
124
|
}
|
|
98
125
|
_checkExistingBlocks() {
|
|
99
|
-
const e =
|
|
100
|
-
e.isGlobalUnsubscribeDisabled = !1, e.isSubscriptionPreferencesCenterDisabled = !1, this.api.getDocumentRoot().querySelectorAll(
|
|
101
|
-
if ("getAttribute" in
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
104
|
-
const l = Number(
|
|
105
|
-
l ===
|
|
126
|
+
const e = a();
|
|
127
|
+
e.isGlobalUnsubscribeDisabled = !1, e.isSubscriptionPreferencesCenterDisabled = !1, this.api.getDocumentRoot().querySelectorAll(B).forEach((r) => {
|
|
128
|
+
if ("getAttribute" in r) {
|
|
129
|
+
const s = r.getAttribute(o.PAGE_TYPE);
|
|
130
|
+
if (s) {
|
|
131
|
+
const l = Number(s);
|
|
132
|
+
l === b.GLOBAL_UNSUBSCRIBE ? e.isGlobalUnsubscribeDisabled = !0 : l === b.SUBSCRIPTION_PREFERENCE_CENTER && (e.isSubscriptionPreferencesCenterDisabled = !0);
|
|
106
133
|
}
|
|
107
134
|
}
|
|
108
135
|
});
|
|
@@ -110,26 +137,26 @@ class I extends _ {
|
|
|
110
137
|
async _loadBlockState(e) {
|
|
111
138
|
if (!("getAttribute" in e))
|
|
112
139
|
return;
|
|
113
|
-
const
|
|
114
|
-
if (!
|
|
140
|
+
const t = e.getAttribute(o.PAGE_TYPE), r = e.getAttribute(o.PAGE_LIST);
|
|
141
|
+
if (!t || !r)
|
|
115
142
|
return;
|
|
116
|
-
const
|
|
117
|
-
await
|
|
143
|
+
const s = a(), l = Number(t), m = h(r);
|
|
144
|
+
await s.fetchTemplates(), s.setCollectionWithoutAutoSelection(l), s.loadSelectedTemplates(m);
|
|
118
145
|
}
|
|
119
146
|
_resetStoreState() {
|
|
120
|
-
|
|
147
|
+
a().$reset();
|
|
121
148
|
}
|
|
122
149
|
_removeBlockTemplatesFromStore(e) {
|
|
123
150
|
if (!("getAttribute" in e))
|
|
124
151
|
return;
|
|
125
|
-
const
|
|
126
|
-
if (!
|
|
152
|
+
const t = e.getAttribute(o.PAGE_LIST);
|
|
153
|
+
if (!t)
|
|
127
154
|
return;
|
|
128
|
-
const
|
|
129
|
-
|
|
155
|
+
const r = a(), s = h(t);
|
|
156
|
+
r.removeUnsubscribePages(s);
|
|
130
157
|
}
|
|
131
158
|
}
|
|
132
159
|
export {
|
|
133
|
-
|
|
134
|
-
|
|
160
|
+
T as UNSUBSCRIBE_BLOCK_ID,
|
|
161
|
+
x as UnsubscribeBlock
|
|
135
162
|
};
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { BlockType as
|
|
2
|
-
const
|
|
3
|
-
<${
|
|
1
|
+
import { BlockType as s } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
2
|
+
const e = "unsubscribe", n = "{{ins-unsubscribe-link}}", t = `
|
|
3
|
+
<${s.BLOCK_TEXT}
|
|
4
4
|
class="unsubscribe-block-v2 esd-block-unsubscribe es-p0"
|
|
5
5
|
align="center"
|
|
6
6
|
data-unsubscribe-page-type=""
|
|
7
7
|
data-unsubscribe-page-list=""
|
|
8
8
|
>
|
|
9
|
-
<p
|
|
9
|
+
<p> <strong><a
|
|
10
10
|
href="${n}"
|
|
11
11
|
class="unsubscribe-link"
|
|
12
12
|
target="_blank"
|
|
13
13
|
data-unsubscribe-link="true"
|
|
14
|
-
>${
|
|
15
|
-
</${
|
|
14
|
+
>${e}</a></strong></p>
|
|
15
|
+
</${s.BLOCK_TEXT}>
|
|
16
16
|
`;
|
|
17
|
-
function
|
|
17
|
+
function u() {
|
|
18
18
|
return t;
|
|
19
19
|
}
|
|
20
20
|
export {
|
|
21
|
-
|
|
21
|
+
u as getDefaultTemplate
|
|
22
22
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { ImmutableHtmlElementNode } from '@stripoinc/ui-editor-extensions';
|
|
1
|
+
import type { ImmutableHtmlElementNode, ImmutableHtmlNode } from '@stripoinc/ui-editor-extensions';
|
|
2
2
|
import { Block, BlockCompositionType } from '@stripoinc/ui-editor-extensions';
|
|
3
3
|
export declare const UNSUBSCRIBE_BLOCK_ID = "unsubscribe-block";
|
|
4
4
|
export declare class UnsubscribeBlock extends Block {
|
|
5
5
|
private selectEventListener;
|
|
6
6
|
private cancelEventListener;
|
|
7
7
|
private currentNode?;
|
|
8
|
+
private hadUnsubscribeLink;
|
|
8
9
|
constructor();
|
|
9
10
|
getId(): string;
|
|
10
11
|
getIcon(): string;
|
|
@@ -13,8 +14,11 @@ export declare class UnsubscribeBlock extends Block {
|
|
|
13
14
|
getDescription(): string;
|
|
14
15
|
getTemplate(): string;
|
|
15
16
|
onSelect(node: ImmutableHtmlElementNode): void;
|
|
17
|
+
onDocumentChanged(node: ImmutableHtmlNode): void;
|
|
16
18
|
onDelete(node: ImmutableHtmlElementNode): void;
|
|
17
19
|
onDestroy(): void;
|
|
20
|
+
private _hasUnsubscribeLink;
|
|
21
|
+
private _warnLinkRemoved;
|
|
18
22
|
private _setupSelectEventListener;
|
|
19
23
|
private _removeSelectEventListener;
|
|
20
24
|
private _setupCancelEventListener;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useinsider/guido",
|
|
3
|
-
"version": "3.4.1-beta.
|
|
3
|
+
"version": "3.4.1-beta.c04b4e7",
|
|
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",
|