@useinsider/guido 3.6.0-beta.5cbaa8f → 3.6.0-beta.6c3407e
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/enums/toaster.js +1 -1
- package/dist/extensions/Blocks/Recommendation/block.js +35 -16
- package/dist/extensions/Blocks/Recommendation/useRecommendationBlockWarning.js +16 -0
- package/dist/extensions/Blocks/Recommendation/utils/recommendationBlockCount.js +9 -0
- package/dist/extensions/Blocks/Unsubscribe/block.js +72 -122
- package/dist/src/enums/toaster.d.ts +2 -1
- package/dist/src/extensions/Blocks/Recommendation/block.d.ts +13 -0
- package/dist/src/extensions/Blocks/Recommendation/block.test.d.ts +1 -0
- package/dist/src/extensions/Blocks/Recommendation/useRecommendationBlockWarning.d.ts +12 -0
- package/dist/src/extensions/Blocks/Recommendation/utils/recommendationBlockCount.d.ts +28 -0
- package/dist/src/extensions/Blocks/Recommendation/utils/recommendationBlockCount.test.d.ts +1 -0
- package/dist/src/extensions/Blocks/Unsubscribe/block.d.ts +0 -9
- package/package.json +1 -1
package/dist/enums/toaster.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var c = /* @__PURE__ */ ((r) => (r.Success = "success", r.Warning = "warning", r.Alert = "alert", r))(c || {});
|
|
1
|
+
var c = /* @__PURE__ */ ((r) => (r.Success = "success", r.Warning = "warning", r.Alert = "alert", r.Dark = "dark", r))(c || {});
|
|
2
2
|
export {
|
|
3
3
|
c as ToasterTypeOptions
|
|
4
4
|
};
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
var k = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var d = (a, r, t) =>
|
|
4
|
-
import { BlockId as
|
|
5
|
-
import { getMigrationBannerHtml as
|
|
6
|
-
import { Block as
|
|
2
|
+
var B = (a, r, t) => r in a ? k(a, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[r] = t;
|
|
3
|
+
var d = (a, r, t) => B(a, typeof r != "symbol" ? r + "" : r, t);
|
|
4
|
+
import { BlockId as R } from "../../../enums/block.js";
|
|
5
|
+
import { getMigrationBannerHtml as y } from "../../../utils/migrationBannerHtml.js";
|
|
6
|
+
import { Block as D, BlockCompositionType as C, ModificationDescription as h } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
7
7
|
import { regenerateMobileProductRows as b } from "./controls/main/utils.js";
|
|
8
8
|
import { ensureMobileCssRulesExist as p, setMobileLayoutOptOut as f, hasMobileLayoutOptOut as A } from "./controls/mobileLayout/cssRules.js";
|
|
9
9
|
import { RecommendationConfigService as c } from "./services/configService.js";
|
|
10
10
|
import { useRecommendationExtensionStore as g } from "./store/recommendation.js";
|
|
11
11
|
import { getDefaultTemplate as E } from "./templates/grid/template.js";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
import { useRecommendationBlockWarning as M } from "./useRecommendationBlockWarning.js";
|
|
13
|
+
const I = R.Recommendation, m = "recommendation-block-v2", u = "recommendation-id";
|
|
14
|
+
let _ = !1;
|
|
15
|
+
class H extends D {
|
|
15
16
|
constructor() {
|
|
16
17
|
super();
|
|
17
18
|
/**
|
|
@@ -21,7 +22,7 @@ class q extends R {
|
|
|
21
22
|
d(this, "_pendingBlockId", null);
|
|
22
23
|
}
|
|
23
24
|
getId() {
|
|
24
|
-
return
|
|
25
|
+
return I;
|
|
25
26
|
}
|
|
26
27
|
getIcon() {
|
|
27
28
|
return "recommendation-icon";
|
|
@@ -38,8 +39,8 @@ class q extends R {
|
|
|
38
39
|
);
|
|
39
40
|
}
|
|
40
41
|
getSettingsPanelTitleHtml() {
|
|
41
|
-
return
|
|
42
|
-
|
|
42
|
+
return y(
|
|
43
|
+
I,
|
|
43
44
|
this.api.translate("Recommendation Block"),
|
|
44
45
|
this.api.translate("This block is switched from the Old Version to the New Version. We recommend you check the Recommendation block and test your message to ensure it works properly.")
|
|
45
46
|
);
|
|
@@ -95,7 +96,7 @@ class q extends R {
|
|
|
95
96
|
documentModifier: this.api.getDocumentModifier()
|
|
96
97
|
}));
|
|
97
98
|
}
|
|
98
|
-
s.patchCurrentBlockConfig({ language: n.language }, { triggerRefetch: !1 });
|
|
99
|
+
s.patchCurrentBlockConfig({ language: n.language }, { triggerRefetch: !1 }), this._warnIfMultipleBlocks();
|
|
99
100
|
}
|
|
100
101
|
/**
|
|
101
102
|
* Called when the document changes or template is loaded
|
|
@@ -117,7 +118,7 @@ class q extends R {
|
|
|
117
118
|
}
|
|
118
119
|
this._healLingeringDuplicate(t), c.needsMigration(t) && this._migrateFromLegacy(t);
|
|
119
120
|
try {
|
|
120
|
-
|
|
121
|
+
_ || (p(this.api), _ = !0);
|
|
121
122
|
const e = c.getConfig(t), i = this._getBlockElement(t);
|
|
122
123
|
if (i) {
|
|
123
124
|
const n = !e.mobileLayoutEnabled;
|
|
@@ -137,6 +138,24 @@ class q extends R {
|
|
|
137
138
|
const e = this._getRecommendationId(t);
|
|
138
139
|
e && g().removeBlockState(e);
|
|
139
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Warns (dark advisory toaster) when the design holds more than one live
|
|
143
|
+
* recommendation block. Triggered from the user-add paths only (fresh drop
|
|
144
|
+
* and duplicate) — never from document-load/migration, so opening a template
|
|
145
|
+
* that already has multiple blocks does not fire it. `onCreated` also runs
|
|
146
|
+
* for a reco block that arrives inside a saved structure (SD-143028), so this
|
|
147
|
+
* covers that case too — no separate `module_dropped` handling is needed.
|
|
148
|
+
*
|
|
149
|
+
* Counting lives in `useRecommendationBlockWarning`, whose DOM-based logic
|
|
150
|
+
* ignores the empty shells deletions leave behind (SD-143028). Wrapped in
|
|
151
|
+
* try/catch because the document root may be unavailable during initial load.
|
|
152
|
+
*/
|
|
153
|
+
_warnIfMultipleBlocks() {
|
|
154
|
+
try {
|
|
155
|
+
M().warnIfMultipleBlocks(this.api.getDocumentRootHtmlNode());
|
|
156
|
+
} catch {
|
|
157
|
+
}
|
|
158
|
+
}
|
|
140
159
|
/**
|
|
141
160
|
* Generates the next unique recommendation ID by scanning all existing blocks
|
|
142
161
|
* in the document and finding the maximum existing ID + 1.
|
|
@@ -209,7 +228,7 @@ class q extends R {
|
|
|
209
228
|
/** Assigns a fresh id to a duplicated block and syncs DOM, node config and store. */
|
|
210
229
|
_handleDuplicate(t, e) {
|
|
211
230
|
const i = this._reassignDuplicateId(t, e), n = g();
|
|
212
|
-
n.cloneBlockState(e, i), n.setCurrentBlock(i);
|
|
231
|
+
n.cloneBlockState(e, i), n.setCurrentBlock(i), this._warnIfMultipleBlocks();
|
|
213
232
|
}
|
|
214
233
|
/**
|
|
215
234
|
* Core id-reassignment for a duplicated block: rewrites the DOM
|
|
@@ -291,6 +310,6 @@ class q extends R {
|
|
|
291
310
|
}
|
|
292
311
|
}
|
|
293
312
|
export {
|
|
294
|
-
|
|
295
|
-
|
|
313
|
+
I as BLOCK_ID,
|
|
314
|
+
H as RecommendationBlock
|
|
296
315
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useToaster as r } from "../../../composables/useToaster.js";
|
|
2
|
+
import { useTranslations as s } from "../../../composables/useTranslations.js";
|
|
3
|
+
import { ToasterTypeOptions as n } from "../../../enums/toaster.js";
|
|
4
|
+
import { countLiveRecommendationBlocks as i } from "./utils/recommendationBlockCount.js";
|
|
5
|
+
const a = "newsletter.multiple-reco-blocks-warning", f = () => {
|
|
6
|
+
const { showToaster: o } = r(), t = s();
|
|
7
|
+
return { warnIfMultipleBlocks: (e) => {
|
|
8
|
+
i(e) > 1 && o({
|
|
9
|
+
type: n.Dark,
|
|
10
|
+
message: t(a)
|
|
11
|
+
});
|
|
12
|
+
} };
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
f as useRecommendationBlockWarning
|
|
16
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const r = ".recommendation-block-v2", t = ".recommendation-product-row";
|
|
2
|
+
function n(o) {
|
|
3
|
+
return Array.from(o.querySelectorAll(r)).filter((e) => e.querySelector(t)).length;
|
|
4
|
+
}
|
|
5
|
+
export {
|
|
6
|
+
r as RECOMMENDATION_BLOCK_SELECTOR,
|
|
7
|
+
t as RECOMMENDATION_PRODUCT_ROW_SELECTOR,
|
|
8
|
+
n as countLiveRecommendationBlocks
|
|
9
|
+
};
|
|
@@ -1,41 +1,39 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { useToaster as
|
|
5
|
-
import { ToasterTypeOptions as
|
|
6
|
-
import { PAGE_TYPES as
|
|
7
|
-
import { useUnsubscribeStore as
|
|
8
|
-
import { Block as
|
|
9
|
-
import { getDefaultTemplate as
|
|
10
|
-
import { DATA_ATTRIBUTES as
|
|
11
|
-
import { parsePageList as
|
|
12
|
-
const
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
}
|
|
16
|
-
class
|
|
1
|
+
var g = Object.defineProperty;
|
|
2
|
+
var k = (c, n, e) => n in c ? g(c, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[n] = e;
|
|
3
|
+
var l = (c, n, e) => k(c, typeof n != "symbol" ? n + "" : n, e);
|
|
4
|
+
import { useToaster as B } from "../../../composables/useToaster.js";
|
|
5
|
+
import { ToasterTypeOptions as S } from "../../../enums/toaster.js";
|
|
6
|
+
import { PAGE_TYPES as E } from "../../../enums/unsubscribe.js";
|
|
7
|
+
import { useUnsubscribeStore as a } from "../../../stores/unsubscribe.js";
|
|
8
|
+
import { Block as L, BlockCompositionType as f, ContextActionType as h, ModificationDescription as b, BlockType as v } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
9
|
+
import { getDefaultTemplate as A } from "./template.js";
|
|
10
|
+
import { DATA_ATTRIBUTES as i, UNSUBSCRIBE_EVENTS as d } from "./utils/constants.js";
|
|
11
|
+
import { parsePageList as p } from "./utils/utils.js";
|
|
12
|
+
const y = "unsubscribe-block", m = 'a[data-unsubscribe-link="true"]', _ = ".unsubscribe-block-v2", I = "{{ins-unsubscribe-link}}", T = "https://academy.insiderone.com/docs/adding-unsubscribe-pages-into-emails", C = "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
|
+
[E.GLOBAL_UNSUBSCRIBE]: "{{ins-global-unsubscribe-link}}",
|
|
14
|
+
[E.SUBSCRIPTION_PREFERENCE_CENTER]: "{{ins-preferences-unsubscribe-link}}"
|
|
15
|
+
};
|
|
16
|
+
class F extends L {
|
|
17
17
|
constructor() {
|
|
18
18
|
super();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
l(this, "selectEventListener", null);
|
|
20
|
+
l(this, "cancelEventListener", null);
|
|
21
|
+
l(this, "currentNode");
|
|
22
22
|
// Per-block "did this instance have a link last time we saw it?" tracking.
|
|
23
23
|
// Keyed by the stable `data-unsubscribe-block-id` we assign, because
|
|
24
24
|
// ImmutableHtmlNode instances are recreated on every document mutation and
|
|
25
25
|
// can't be used as Map keys directly. A singleton boolean here would be
|
|
26
26
|
// polluted across blocks since Stripo fires onDocumentChanged per-instance.
|
|
27
|
-
|
|
28
|
-
// Per-block prepend retry counter for the leading text guard (SD-143097).
|
|
29
|
-
a(this, "guardAttemptsByBlockId", /* @__PURE__ */ new Map());
|
|
27
|
+
l(this, "linkStateByBlockId", /* @__PURE__ */ new Map());
|
|
30
28
|
}
|
|
31
29
|
getId() {
|
|
32
|
-
return
|
|
30
|
+
return y;
|
|
33
31
|
}
|
|
34
32
|
getIcon() {
|
|
35
33
|
return "unsubscribe-icon";
|
|
36
34
|
}
|
|
37
35
|
getBlockCompositionType() {
|
|
38
|
-
return
|
|
36
|
+
return f.BLOCK;
|
|
39
37
|
}
|
|
40
38
|
getName() {
|
|
41
39
|
return this.api.translate("Unsubscribe Block");
|
|
@@ -44,84 +42,36 @@ class H extends y {
|
|
|
44
42
|
return this.api.translate("Unsubscribe Block Description");
|
|
45
43
|
}
|
|
46
44
|
getTemplate() {
|
|
47
|
-
return
|
|
45
|
+
return A();
|
|
48
46
|
}
|
|
49
47
|
getContextActionsIds() {
|
|
50
|
-
return [
|
|
48
|
+
return [h.MOVE, h.REMOVE];
|
|
51
49
|
}
|
|
52
50
|
onSelect(e) {
|
|
53
51
|
this.currentNode = e;
|
|
54
52
|
const t = this._getOrAssignBlockId(e);
|
|
55
53
|
t && this.linkStateByBlockId.set(t, this._hasUnsubscribeLink(e)), !("getAttribute" in e && e.getAttribute("data-migration")) && (this._resetStoreState(), this._loadBlockState(e), this._setupSelectEventListener(), this._setupCancelEventListener(), this._checkExistingBlocks(), this._openDrawer());
|
|
56
54
|
}
|
|
57
|
-
onCreated(e) {
|
|
58
|
-
this._ensureLeadingTextGuard(e);
|
|
59
|
-
}
|
|
60
|
-
onDocumentInit() {
|
|
61
|
-
try {
|
|
62
|
-
const e = this.api.getDocumentRoot();
|
|
63
|
-
e && "querySelectorAll" in e && e.querySelectorAll(E).forEach((t) => {
|
|
64
|
-
this._ensureLeadingTextGuard(t);
|
|
65
|
-
});
|
|
66
|
-
} catch {
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
55
|
onDocumentChanged(e) {
|
|
70
|
-
this._ensureLeadingTextGuard(e);
|
|
71
56
|
const t = this._getOrAssignBlockId(e);
|
|
72
57
|
if (!t)
|
|
73
58
|
return;
|
|
74
|
-
const
|
|
75
|
-
this.linkStateByBlockId.get(t) === !0 && !
|
|
59
|
+
const r = this._hasUnsubscribeLink(e);
|
|
60
|
+
this.linkStateByBlockId.get(t) === !0 && !r && this._warnLinkRemoved(), this.linkStateByBlockId.set(t, r);
|
|
76
61
|
}
|
|
77
62
|
onDelete(e) {
|
|
78
63
|
this._removeEventListeners(), this._removeBlockTemplatesFromStore(e), this._resetStoreState();
|
|
79
64
|
const t = this._readBlockId(e);
|
|
80
|
-
t &&
|
|
65
|
+
t && this.linkStateByBlockId.delete(t);
|
|
81
66
|
}
|
|
82
67
|
onDestroy() {
|
|
83
|
-
this._removeEventListeners(), this.currentNode = void 0, this.linkStateByBlockId.clear()
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Guarantees a plain-text node before the link's wrapper inside the <p>.
|
|
87
|
-
* Without it the only caret position left of the link is inside the anchor,
|
|
88
|
-
* so anything typed there becomes part of the link (SD-143097).
|
|
89
|
-
*/
|
|
90
|
-
_ensureLeadingTextGuard(e) {
|
|
91
|
-
if (!("querySelector" in e))
|
|
92
|
-
return;
|
|
93
|
-
const t = e.querySelector(m);
|
|
94
|
-
if (!t)
|
|
95
|
-
return;
|
|
96
|
-
let s = t, r = s.parent();
|
|
97
|
-
for (; r && "getTagName" in r && r.getTagName().toLowerCase() !== "p"; )
|
|
98
|
-
s = r, r = r.parent();
|
|
99
|
-
if (!r || !("getTagName" in r) || r.getTagName().toLowerCase() !== "p")
|
|
100
|
-
return;
|
|
101
|
-
const i = s.previousSibling();
|
|
102
|
-
if (!!(i && i.getType() === "text" && i.getTextContent())) {
|
|
103
|
-
const b = this._readBlockId(e);
|
|
104
|
-
b && this.guardAttemptsByBlockId.delete(b);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const g = this._getOrAssignBlockId(e);
|
|
108
|
-
if (!g)
|
|
109
|
-
return;
|
|
110
|
-
const _ = this.guardAttemptsByBlockId.get(g) ?? 0;
|
|
111
|
-
if (!(_ >= w)) {
|
|
112
|
-
this.guardAttemptsByBlockId.set(g, _ + 1);
|
|
113
|
-
try {
|
|
114
|
-
this.api.getDocumentModifier().modifyHtml(r).prepend(" ").apply(new d("Ensure unsubscribe link text guard"));
|
|
115
|
-
} catch (b) {
|
|
116
|
-
console.warn("[UnsubscribeBlock] Failed to ensure link text guard:", b);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
68
|
+
this._removeEventListeners(), this.currentNode = void 0, this.linkStateByBlockId.clear();
|
|
119
69
|
}
|
|
120
70
|
_hasUnsubscribeLink(e) {
|
|
121
71
|
return "querySelector" in e ? !!e.querySelector(m) : !1;
|
|
122
72
|
}
|
|
123
73
|
_readBlockId(e) {
|
|
124
|
-
return "getAttribute" in e ? e.getAttribute(
|
|
74
|
+
return "getAttribute" in e ? e.getAttribute(i.BLOCK_ID) : null;
|
|
125
75
|
}
|
|
126
76
|
/**
|
|
127
77
|
* Returns the block's stable id, assigning one via the document modifier if
|
|
@@ -135,13 +85,13 @@ class H extends y {
|
|
|
135
85
|
return t;
|
|
136
86
|
if (!("getAttribute" in e))
|
|
137
87
|
return null;
|
|
138
|
-
const
|
|
88
|
+
const r = this._generateNextBlockId();
|
|
139
89
|
try {
|
|
140
|
-
this.api.getDocumentModifier().modifyHtml(e).setAttribute(
|
|
141
|
-
} catch (
|
|
142
|
-
return console.warn("[UnsubscribeBlock] Failed to assign block id:",
|
|
90
|
+
this.api.getDocumentModifier().modifyHtml(e).setAttribute(i.BLOCK_ID, r).apply(new b(`Assign unsubscribe block id ${r}`));
|
|
91
|
+
} catch (s) {
|
|
92
|
+
return console.warn("[UnsubscribeBlock] Failed to assign block id:", s), null;
|
|
143
93
|
}
|
|
144
|
-
return
|
|
94
|
+
return r;
|
|
145
95
|
}
|
|
146
96
|
/**
|
|
147
97
|
* Generates a unique id by scanning the document for the highest existing
|
|
@@ -152,10 +102,10 @@ class H extends y {
|
|
|
152
102
|
let e = 0;
|
|
153
103
|
try {
|
|
154
104
|
const t = this.api.getDocumentRoot();
|
|
155
|
-
t && "querySelectorAll" in t && t.querySelectorAll(
|
|
156
|
-
if ("getAttribute" in
|
|
157
|
-
const
|
|
158
|
-
|
|
105
|
+
t && "querySelectorAll" in t && t.querySelectorAll(_).forEach((s) => {
|
|
106
|
+
if ("getAttribute" in s) {
|
|
107
|
+
const o = s.getAttribute(i.BLOCK_ID), u = o ? parseInt(o) : 0;
|
|
108
|
+
u > e && (e = u);
|
|
159
109
|
}
|
|
160
110
|
});
|
|
161
111
|
} catch {
|
|
@@ -164,14 +114,14 @@ class H extends y {
|
|
|
164
114
|
}
|
|
165
115
|
_warnLinkRemoved() {
|
|
166
116
|
try {
|
|
167
|
-
const { showToaster: e } =
|
|
117
|
+
const { showToaster: e } = B();
|
|
168
118
|
e({
|
|
169
|
-
type:
|
|
170
|
-
message: this.api.translate(
|
|
119
|
+
type: S.Warning,
|
|
120
|
+
message: this.api.translate(C),
|
|
171
121
|
actionButton: {
|
|
172
122
|
text: this.api.translate("Visit Academy"),
|
|
173
123
|
onClick: () => {
|
|
174
|
-
window.open(
|
|
124
|
+
window.open(T, "_blank", "noopener,noreferrer");
|
|
175
125
|
}
|
|
176
126
|
}
|
|
177
127
|
});
|
|
@@ -181,26 +131,26 @@ class H extends y {
|
|
|
181
131
|
}
|
|
182
132
|
_setupSelectEventListener() {
|
|
183
133
|
this._removeSelectEventListener(), this.selectEventListener = (e) => {
|
|
184
|
-
const t = e, { collectionType:
|
|
185
|
-
this._updateBlock(
|
|
186
|
-
}, document.addEventListener(
|
|
134
|
+
const t = e, { collectionType: r, selectedPages: s } = t.detail;
|
|
135
|
+
this._updateBlock(r, s.join(","));
|
|
136
|
+
}, document.addEventListener(d.SELECT, this.selectEventListener);
|
|
187
137
|
}
|
|
188
138
|
_removeSelectEventListener() {
|
|
189
|
-
this.selectEventListener && (document.removeEventListener(
|
|
139
|
+
this.selectEventListener && (document.removeEventListener(d.SELECT, this.selectEventListener), this.selectEventListener = null);
|
|
190
140
|
}
|
|
191
141
|
_setupCancelEventListener() {
|
|
192
142
|
this._removeCancelEventListener(), this.cancelEventListener = () => {
|
|
193
143
|
this._handleCancel();
|
|
194
|
-
}, document.addEventListener(
|
|
144
|
+
}, document.addEventListener(d.CANCEL, this.cancelEventListener);
|
|
195
145
|
}
|
|
196
146
|
_removeCancelEventListener() {
|
|
197
|
-
this.cancelEventListener && (document.removeEventListener(
|
|
147
|
+
this.cancelEventListener && (document.removeEventListener(d.CANCEL, this.cancelEventListener), this.cancelEventListener = null);
|
|
198
148
|
}
|
|
199
149
|
_handleCancel() {
|
|
200
150
|
try {
|
|
201
151
|
if (!this.currentNode)
|
|
202
152
|
return;
|
|
203
|
-
this.api.getDocumentModifier().modifyHtml(this.currentNode).replaceWith(`<${
|
|
153
|
+
this.api.getDocumentModifier().modifyHtml(this.currentNode).replaceWith(`<${v.EMPTY_CONTAINER}/>`).apply(new b("Removed unsubscribe block due to cancel"));
|
|
204
154
|
} catch (e) {
|
|
205
155
|
console.warn("[UnsubscribeBlock] Failed to remove unsubscribe block:", e);
|
|
206
156
|
}
|
|
@@ -211,32 +161,32 @@ class H extends y {
|
|
|
211
161
|
_updateBlock(e, t) {
|
|
212
162
|
if (!this.currentNode || !("querySelector" in this.currentNode))
|
|
213
163
|
return;
|
|
214
|
-
const
|
|
215
|
-
if (!
|
|
164
|
+
const r = this.currentNode.querySelector(m);
|
|
165
|
+
if (!r)
|
|
216
166
|
return;
|
|
217
|
-
const
|
|
218
|
-
this.api.getDocumentModifier().modifyHtml(
|
|
167
|
+
const s = this._getMergeTag(e);
|
|
168
|
+
this.api.getDocumentModifier().modifyHtml(r).setAttribute("href", s).apply(new b(`Updated unsubscribe link to ${s}`)), this.api.getDocumentModifier().modifyHtml(this.currentNode).setAttribute(i.PAGE_TYPE, e.toString()).setAttribute(i.PAGE_LIST, t).apply(new b("Updated unsubscribe block metadata"));
|
|
219
169
|
}
|
|
220
170
|
_getMergeTag(e) {
|
|
221
|
-
return
|
|
171
|
+
return N[e] ?? I;
|
|
222
172
|
}
|
|
223
173
|
_openDrawer() {
|
|
224
174
|
if (!(this.currentNode && this.currentNode.getAttribute("data-unsubscribe-page-type")))
|
|
225
175
|
try {
|
|
226
|
-
const e =
|
|
176
|
+
const e = a();
|
|
227
177
|
e.typeSelectionDrawerStatus = !0;
|
|
228
178
|
} catch (e) {
|
|
229
179
|
console.error("[UnsubscribeBlock] Failed to open drawer:", e);
|
|
230
180
|
}
|
|
231
181
|
}
|
|
232
182
|
_checkExistingBlocks() {
|
|
233
|
-
const e =
|
|
234
|
-
e.isGlobalUnsubscribeDisabled = !1, e.isSubscriptionPreferencesCenterDisabled = !1, this.api.getDocumentRoot().querySelectorAll(
|
|
235
|
-
if ("getAttribute" in
|
|
236
|
-
const
|
|
237
|
-
if (
|
|
238
|
-
const
|
|
239
|
-
|
|
183
|
+
const e = a();
|
|
184
|
+
e.isGlobalUnsubscribeDisabled = !1, e.isSubscriptionPreferencesCenterDisabled = !1, this.api.getDocumentRoot().querySelectorAll(_).forEach((r) => {
|
|
185
|
+
if ("getAttribute" in r) {
|
|
186
|
+
const s = r.getAttribute(i.PAGE_TYPE);
|
|
187
|
+
if (s) {
|
|
188
|
+
const o = Number(s);
|
|
189
|
+
o === E.GLOBAL_UNSUBSCRIBE ? e.isGlobalUnsubscribeDisabled = !0 : o === E.SUBSCRIPTION_PREFERENCE_CENTER && (e.isSubscriptionPreferencesCenterDisabled = !0);
|
|
240
190
|
}
|
|
241
191
|
}
|
|
242
192
|
});
|
|
@@ -244,26 +194,26 @@ class H extends y {
|
|
|
244
194
|
async _loadBlockState(e) {
|
|
245
195
|
if (!("getAttribute" in e))
|
|
246
196
|
return;
|
|
247
|
-
const t = e.getAttribute(
|
|
248
|
-
if (!t || !
|
|
197
|
+
const t = e.getAttribute(i.PAGE_TYPE), r = e.getAttribute(i.PAGE_LIST);
|
|
198
|
+
if (!t || !r)
|
|
249
199
|
return;
|
|
250
|
-
const
|
|
251
|
-
await
|
|
200
|
+
const s = a(), o = Number(t), u = p(r);
|
|
201
|
+
await s.fetchTemplates(), s.setCollectionWithoutAutoSelection(o), s.loadSelectedTemplates(u);
|
|
252
202
|
}
|
|
253
203
|
_resetStoreState() {
|
|
254
|
-
|
|
204
|
+
a().$reset();
|
|
255
205
|
}
|
|
256
206
|
_removeBlockTemplatesFromStore(e) {
|
|
257
207
|
if (!("getAttribute" in e))
|
|
258
208
|
return;
|
|
259
|
-
const t = e.getAttribute(
|
|
209
|
+
const t = e.getAttribute(i.PAGE_LIST);
|
|
260
210
|
if (!t)
|
|
261
211
|
return;
|
|
262
|
-
const
|
|
263
|
-
|
|
212
|
+
const r = a(), s = p(t);
|
|
213
|
+
r.removeUnsubscribePages(s);
|
|
264
214
|
}
|
|
265
215
|
}
|
|
266
216
|
export {
|
|
267
|
-
|
|
268
|
-
|
|
217
|
+
y as UNSUBSCRIBE_BLOCK_ID,
|
|
218
|
+
F as UnsubscribeBlock
|
|
269
219
|
};
|
|
@@ -55,6 +55,19 @@ export declare class RecommendationBlock extends Block {
|
|
|
55
55
|
* @param node - The block node being deleted
|
|
56
56
|
*/
|
|
57
57
|
onDelete(node: ImmutableHtmlNode): void;
|
|
58
|
+
/**
|
|
59
|
+
* Warns (dark advisory toaster) when the design holds more than one live
|
|
60
|
+
* recommendation block. Triggered from the user-add paths only (fresh drop
|
|
61
|
+
* and duplicate) — never from document-load/migration, so opening a template
|
|
62
|
+
* that already has multiple blocks does not fire it. `onCreated` also runs
|
|
63
|
+
* for a reco block that arrives inside a saved structure (SD-143028), so this
|
|
64
|
+
* covers that case too — no separate `module_dropped` handling is needed.
|
|
65
|
+
*
|
|
66
|
+
* Counting lives in `useRecommendationBlockWarning`, whose DOM-based logic
|
|
67
|
+
* ignores the empty shells deletions leave behind (SD-143028). Wrapped in
|
|
68
|
+
* try/catch because the document root may be unavailable during initial load.
|
|
69
|
+
*/
|
|
70
|
+
private _warnIfMultipleBlocks;
|
|
58
71
|
/**
|
|
59
72
|
* Generates the next unique recommendation ID by scanning all existing blocks
|
|
60
73
|
* in the document and finding the maximum existing ID + 1.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { QueryableRoot } from './utils/recommendationBlockCount';
|
|
2
|
+
/**
|
|
3
|
+
* Advisory shown when a design ends up with more than one recommendation block,
|
|
4
|
+
* since multiple blocks can slow campaign delivery. Driven from the block
|
|
5
|
+
* lifecycle (`onCreated` for direct drop / duplicate, counting the editor's
|
|
6
|
+
* document root). `onCreated` also fires for a reco block that arrives inside a
|
|
7
|
+
* saved structure (SD-143028), so that case is covered without a separate
|
|
8
|
+
* `module_dropped` re-check.
|
|
9
|
+
*/
|
|
10
|
+
export declare const useRecommendationBlockWarning: () => {
|
|
11
|
+
warnIfMultipleBlocks: (root: QueryableRoot) => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Counts *live* recommendation blocks in a document.
|
|
3
|
+
*
|
|
4
|
+
* Deleting a recommendation block strips its inner content but leaves an empty
|
|
5
|
+
* `.recommendation-block-v2` container shell behind — present in every document
|
|
6
|
+
* representation the editor exposes (`getDocumentRoot`, `getDocumentRootHtmlNode`
|
|
7
|
+
* and even `getTemplateData`). A raw class count therefore over-reports after a
|
|
8
|
+
* delete→add cycle (SD-143028). The product row (`.recommendation-product-row`)
|
|
9
|
+
* is present on every live block from drop time (the default template ships
|
|
10
|
+
* product rows, both grid and list layouts) and is removed from a deleted
|
|
11
|
+
* block's leftover shell, so filtering by it cleanly separates live blocks from
|
|
12
|
+
* ghosts without reading any store.
|
|
13
|
+
*/
|
|
14
|
+
export declare const RECOMMENDATION_BLOCK_SELECTOR = ".recommendation-block-v2";
|
|
15
|
+
export declare const RECOMMENDATION_PRODUCT_ROW_SELECTOR = ".recommendation-product-row";
|
|
16
|
+
interface QueryableNode {
|
|
17
|
+
querySelector(selector: string): unknown;
|
|
18
|
+
}
|
|
19
|
+
export interface QueryableRoot {
|
|
20
|
+
querySelectorAll(selector: string): Iterable<QueryableNode>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Counts the live recommendation blocks reachable from `root`. Works on the
|
|
24
|
+
* editor's `ImmutableHtmlNode` document root (the `onCreated` drop / duplicate
|
|
25
|
+
* paths) and on any DOM-like root exposing `querySelectorAll`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function countLiveRecommendationBlocks(root: QueryableRoot): number;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -6,7 +6,6 @@ export declare class UnsubscribeBlock extends Block {
|
|
|
6
6
|
private cancelEventListener;
|
|
7
7
|
private currentNode?;
|
|
8
8
|
private linkStateByBlockId;
|
|
9
|
-
private guardAttemptsByBlockId;
|
|
10
9
|
constructor();
|
|
11
10
|
getId(): string;
|
|
12
11
|
getIcon(): string;
|
|
@@ -16,17 +15,9 @@ export declare class UnsubscribeBlock extends Block {
|
|
|
16
15
|
getTemplate(): string;
|
|
17
16
|
getContextActionsIds(): string[];
|
|
18
17
|
onSelect(node: ImmutableHtmlElementNode): void;
|
|
19
|
-
onCreated(node: ImmutableHtmlNode): void;
|
|
20
|
-
onDocumentInit(): void;
|
|
21
18
|
onDocumentChanged(node: ImmutableHtmlNode): void;
|
|
22
19
|
onDelete(node: ImmutableHtmlElementNode): void;
|
|
23
20
|
onDestroy(): void;
|
|
24
|
-
/**
|
|
25
|
-
* Guarantees a plain-text node before the link's wrapper inside the <p>.
|
|
26
|
-
* Without it the only caret position left of the link is inside the anchor,
|
|
27
|
-
* so anything typed there becomes part of the link (SD-143097).
|
|
28
|
-
*/
|
|
29
|
-
private _ensureLeadingTextGuard;
|
|
30
21
|
private _hasUnsubscribeLink;
|
|
31
22
|
private _readBlockId;
|
|
32
23
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useinsider/guido",
|
|
3
|
-
"version": "3.6.0-beta.
|
|
3
|
+
"version": "3.6.0-beta.6c3407e",
|
|
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",
|