@useinsider/guido 3.7.1 → 3.7.2-beta.0ef1511
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/useSave.js +17 -16
- package/dist/composables/validators/useUnsubscribeBlockValidator.js +32 -0
- package/dist/extensions/Blocks/Unsubscribe/block.js +16 -16
- package/dist/extensions/Blocks/Unsubscribe/utils/constants.js +4 -3
- package/dist/src/composables/validators/useUnsubscribeBlockValidator.d.ts +3 -0
- package/dist/src/composables/validators/useUnsubscribeBlockValidator.test.d.ts +1 -0
- package/dist/src/extensions/Blocks/Unsubscribe/utils/constants.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
import { useActionsApi as x } from "./useActionsApi.js";
|
|
2
2
|
import { useConfig as y } from "./useConfig.js";
|
|
3
|
-
import { useSaveStart as w, useSaveComplete as
|
|
4
|
-
import { useSyncModuleExtractor as
|
|
5
|
-
import { useStripoApi as
|
|
6
|
-
import { useTemplatePreparation as
|
|
7
|
-
import { useHtmlValidator as
|
|
3
|
+
import { useSaveStart as w, useSaveComplete as H } from "./useGuidoActions.js";
|
|
4
|
+
import { useSyncModuleExtractor as q } from "./useSyncModuleExtractor.js";
|
|
5
|
+
import { useStripoApi as C } from "../services/stripoApi.js";
|
|
6
|
+
import { useTemplatePreparation as E } from "../utils/templatePreparation.js";
|
|
7
|
+
import { useHtmlValidator as k } from "./useHtmlValidator.js";
|
|
8
8
|
import { useCouponBlockValidator as L } from "./validators/useCouponBlockValidator.js";
|
|
9
9
|
import { useLiquidValidator as P } from "./validators/useLiquidValidator.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
import { useUnsubscribeBlockValidator as B } from "./validators/useUnsubscribeBlockValidator.js";
|
|
11
|
+
const J = () => {
|
|
12
|
+
const o = w(), s = H(), { validateHtml: r } = k(), { validateLiquidSyntax: n } = P(), { validateCouponBlockTags: l } = L(), { validateUnsubscribeBlockUniqueness: d } = B(), { callbacks: i, isFeatureEnabled: u } = y(), { extractSyncModuleData: c } = q(), { setSyncModuleUnsubscriptionPages: m } = C(), { editorSave: p } = x();
|
|
13
|
+
return { save: async (f = !1, v = !1) => {
|
|
14
|
+
var a;
|
|
14
15
|
o();
|
|
15
|
-
const { prepareTemplateDetails:
|
|
16
|
-
if (!l(t.compiledHtml))
|
|
16
|
+
const { prepareTemplateDetails: S } = E(), t = await S();
|
|
17
|
+
if (!l(t.compiledHtml) || !d(t.compiledHtml))
|
|
17
18
|
return;
|
|
18
|
-
if (
|
|
19
|
+
if (u("liquidSyntax")) {
|
|
19
20
|
if (!await n(t.compiledHtml))
|
|
20
21
|
return;
|
|
21
22
|
} else if (!await r(t.compiledHtml, t.dynamicContentList, !0))
|
|
22
23
|
return;
|
|
23
|
-
if ((
|
|
24
|
+
if ((a = i.value) != null && a.externalValidation && !await i.value.externalValidation(t) || !await p())
|
|
24
25
|
return;
|
|
25
|
-
const { unsubscribePayload:
|
|
26
|
-
return await
|
|
26
|
+
const { unsubscribePayload: V, stripoModules: b } = c(t.rawHtml);
|
|
27
|
+
return await m(V), t.modules = b, f || s({ ...t, silent: v }), t;
|
|
27
28
|
} };
|
|
28
29
|
};
|
|
29
30
|
export {
|
|
30
|
-
|
|
31
|
+
J as useSave
|
|
31
32
|
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ToasterTypeOptions as i } from "../../enums/toaster.js";
|
|
2
|
+
import { PAGE_TYPES as n } from "../../enums/unsubscribe.js";
|
|
3
|
+
import { UNSUBSCRIBE_BLOCK_SELECTOR as u, DATA_ATTRIBUTES as l } from "../../extensions/Blocks/Unsubscribe/utils/constants.js";
|
|
4
|
+
import { useToaster as T } from "../useToaster.js";
|
|
5
|
+
import { useTranslations as E } from "../useTranslations.js";
|
|
6
|
+
const m = [
|
|
7
|
+
{
|
|
8
|
+
pageType: n.GLOBAL_UNSUBSCRIBE,
|
|
9
|
+
messageKey: "unsubscription-preference.duplicate-global-unsub"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
pageType: n.SUBSCRIPTION_PREFERENCE_CENTER,
|
|
13
|
+
messageKey: "unsubscription-preference.duplicate-pref-center"
|
|
14
|
+
}
|
|
15
|
+
], g = "unsubscription-preference.duplicate-both", y = () => {
|
|
16
|
+
const { showToaster: o } = T(), a = E();
|
|
17
|
+
return { validateUnsubscribeBlockUniqueness: (c) => {
|
|
18
|
+
const p = new DOMParser().parseFromString(c, "text/html"), t = /* @__PURE__ */ new Map();
|
|
19
|
+
p.querySelectorAll(u).forEach((e) => {
|
|
20
|
+
const r = Number(e.getAttribute(l.PAGE_TYPE));
|
|
21
|
+
t.set(r, (t.get(r) ?? 0) + 1);
|
|
22
|
+
});
|
|
23
|
+
const s = m.filter((e) => (t.get(e.pageType) ?? 0) > 1).map((e) => e.messageKey);
|
|
24
|
+
return s.length ? (o({
|
|
25
|
+
type: i.Alert,
|
|
26
|
+
message: a(s.length > 1 ? g : s[0])
|
|
27
|
+
}), !1) : !0;
|
|
28
|
+
} };
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
y as useUnsubscribeBlockValidator
|
|
32
|
+
};
|
|
@@ -7,9 +7,9 @@ import { PAGE_TYPES as h } from "../../../enums/unsubscribe.js";
|
|
|
7
7
|
import { useUnsubscribeStore as u } from "../../../stores/unsubscribe.js";
|
|
8
8
|
import { Block as y, BlockCompositionType as T, ContextActionType as k, ModificationDescription as d, BlockType as I } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
9
9
|
import { getDefaultTemplate as v } from "./template.js";
|
|
10
|
-
import { DATA_ATTRIBUTES as n, UNSUBSCRIBE_EVENTS as
|
|
10
|
+
import { UNSUBSCRIBE_BLOCK_SELECTOR as m, DATA_ATTRIBUTES as n, UNSUBSCRIBE_EVENTS as b } from "./utils/constants.js";
|
|
11
11
|
import { parsePageList as B } from "./utils/utils.js";
|
|
12
|
-
const C = "unsubscribe-block",
|
|
12
|
+
const C = "unsubscribe-block", E = 'a[data-unsubscribe-link="true"]', N = "{{ins-unsubscribe-link}}", U = "https://academy.insiderone.com/docs/adding-unsubscribe-pages-into-emails", R = "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.", D = {
|
|
13
13
|
[h.GLOBAL_UNSUBSCRIBE]: "{{ins-global-unsubscribe-link}}",
|
|
14
14
|
[h.SUBSCRIPTION_PREFERENCE_CENTER]: "{{ins-preferences-unsubscribe-link}}"
|
|
15
15
|
}, w = 3;
|
|
@@ -60,7 +60,7 @@ class H extends y {
|
|
|
60
60
|
onDocumentInit() {
|
|
61
61
|
try {
|
|
62
62
|
const e = this.api.getDocumentRoot();
|
|
63
|
-
e && "querySelectorAll" in e && e.querySelectorAll(
|
|
63
|
+
e && "querySelectorAll" in e && e.querySelectorAll(m).forEach((t) => {
|
|
64
64
|
this._ensureLeadingTextGuard(t);
|
|
65
65
|
});
|
|
66
66
|
} catch {
|
|
@@ -90,7 +90,7 @@ class H extends y {
|
|
|
90
90
|
_ensureLeadingTextGuard(e) {
|
|
91
91
|
if (!("querySelector" in e))
|
|
92
92
|
return;
|
|
93
|
-
const t = e.querySelector(
|
|
93
|
+
const t = e.querySelector(E);
|
|
94
94
|
if (!t)
|
|
95
95
|
return;
|
|
96
96
|
let s = t, r = s.parent();
|
|
@@ -100,8 +100,8 @@ class H extends y {
|
|
|
100
100
|
return;
|
|
101
101
|
const i = s.previousSibling();
|
|
102
102
|
if (!!(i && i.getType() === "text" && i.getTextContent())) {
|
|
103
|
-
const
|
|
104
|
-
|
|
103
|
+
const p = this._readBlockId(e);
|
|
104
|
+
p && this.guardAttemptsByBlockId.delete(p);
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
107
|
const g = this._getOrAssignBlockId(e);
|
|
@@ -112,13 +112,13 @@ class H extends y {
|
|
|
112
112
|
this.guardAttemptsByBlockId.set(g, _ + 1);
|
|
113
113
|
try {
|
|
114
114
|
this.api.getDocumentModifier().modifyHtml(r).prepend(" ").apply(new d("Ensure unsubscribe link text guard"));
|
|
115
|
-
} catch (
|
|
116
|
-
console.warn("[UnsubscribeBlock] Failed to ensure link text guard:",
|
|
115
|
+
} catch (p) {
|
|
116
|
+
console.warn("[UnsubscribeBlock] Failed to ensure link text guard:", p);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
_hasUnsubscribeLink(e) {
|
|
121
|
-
return "querySelector" in e ? !!e.querySelector(
|
|
121
|
+
return "querySelector" in e ? !!e.querySelector(E) : !1;
|
|
122
122
|
}
|
|
123
123
|
_readBlockId(e) {
|
|
124
124
|
return "getAttribute" in e ? e.getAttribute(n.BLOCK_ID) : null;
|
|
@@ -152,7 +152,7 @@ class H extends y {
|
|
|
152
152
|
let e = 0;
|
|
153
153
|
try {
|
|
154
154
|
const t = this.api.getDocumentRoot();
|
|
155
|
-
t && "querySelectorAll" in t && t.querySelectorAll(
|
|
155
|
+
t && "querySelectorAll" in t && t.querySelectorAll(m).forEach((r) => {
|
|
156
156
|
if ("getAttribute" in r) {
|
|
157
157
|
const i = r.getAttribute(n.BLOCK_ID), l = i ? parseInt(i) : 0;
|
|
158
158
|
l > e && (e = l);
|
|
@@ -183,18 +183,18 @@ class H extends y {
|
|
|
183
183
|
this._removeSelectEventListener(), this.selectEventListener = (e) => {
|
|
184
184
|
const t = e, { collectionType: s, selectedPages: r } = t.detail;
|
|
185
185
|
this._updateBlock(s, r.join(","));
|
|
186
|
-
}, document.addEventListener(
|
|
186
|
+
}, document.addEventListener(b.SELECT, this.selectEventListener);
|
|
187
187
|
}
|
|
188
188
|
_removeSelectEventListener() {
|
|
189
|
-
this.selectEventListener && (document.removeEventListener(
|
|
189
|
+
this.selectEventListener && (document.removeEventListener(b.SELECT, this.selectEventListener), this.selectEventListener = null);
|
|
190
190
|
}
|
|
191
191
|
_setupCancelEventListener() {
|
|
192
192
|
this._removeCancelEventListener(), this.cancelEventListener = () => {
|
|
193
193
|
this._handleCancel();
|
|
194
|
-
}, document.addEventListener(
|
|
194
|
+
}, document.addEventListener(b.CANCEL, this.cancelEventListener);
|
|
195
195
|
}
|
|
196
196
|
_removeCancelEventListener() {
|
|
197
|
-
this.cancelEventListener && (document.removeEventListener(
|
|
197
|
+
this.cancelEventListener && (document.removeEventListener(b.CANCEL, this.cancelEventListener), this.cancelEventListener = null);
|
|
198
198
|
}
|
|
199
199
|
_handleCancel() {
|
|
200
200
|
try {
|
|
@@ -211,7 +211,7 @@ class H extends y {
|
|
|
211
211
|
_updateBlock(e, t) {
|
|
212
212
|
if (!this.currentNode || !("querySelector" in this.currentNode))
|
|
213
213
|
return;
|
|
214
|
-
const s = this.currentNode.querySelector(
|
|
214
|
+
const s = this.currentNode.querySelector(E);
|
|
215
215
|
if (!s)
|
|
216
216
|
return;
|
|
217
217
|
const r = this._getMergeTag(e);
|
|
@@ -231,7 +231,7 @@ class H extends y {
|
|
|
231
231
|
}
|
|
232
232
|
_checkExistingBlocks() {
|
|
233
233
|
const e = u();
|
|
234
|
-
e.isGlobalUnsubscribeDisabled = !1, e.isSubscriptionPreferencesCenterDisabled = !1, this.api.getDocumentRoot().querySelectorAll(
|
|
234
|
+
e.isGlobalUnsubscribeDisabled = !1, e.isSubscriptionPreferencesCenterDisabled = !1, this.api.getDocumentRoot().querySelectorAll(m).forEach((s) => {
|
|
235
235
|
if ("getAttribute" in s) {
|
|
236
236
|
const r = s.getAttribute(n.PAGE_TYPE);
|
|
237
237
|
if (r) {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
const s = {
|
|
2
2
|
SELECT: "unsubscribe:select",
|
|
3
3
|
CANCEL: "unsubscribe:cancel"
|
|
4
|
-
},
|
|
4
|
+
}, b = {
|
|
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";
|
|
9
9
|
export {
|
|
10
|
-
|
|
10
|
+
b as DATA_ATTRIBUTES,
|
|
11
|
+
c as UNSUBSCRIBE_BLOCK_SELECTOR,
|
|
11
12
|
s as UNSUBSCRIBE_EVENTS
|
|
12
13
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useinsider/guido",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.2-beta.0ef1511",
|
|
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",
|