@useinsider/guido 3.24.0-beta.0abeefe → 3.24.0-beta.297168
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/README.md +6 -2
- package/dist/@types/config/schemas.js +37 -39
- package/dist/components/Guido.vue.js +4 -4
- package/dist/components/Guido.vue2.js +92 -98
- package/dist/composables/useBlocksConfig.js +20 -31
- package/dist/composables/useHtmlCompiler.js +2 -0
- package/dist/composables/useStripo.js +70 -70
- package/dist/composables/useTranslations.js +1 -2
- package/dist/config/compiler/htmlCompilerRules.js +14 -6
- package/dist/config/compiler/utils/itemsCompilerUtils.js +42 -43
- package/dist/config/compiler/utils/recommendationCompilerUtils.js +64 -67
- package/dist/config/migrator/unsubscribeMigrator.js +91 -100
- package/dist/enums/academy.js +0 -1
- package/dist/extensions/Blocks/Unsubscribe/block.js +104 -96
- package/dist/extensions/Blocks/Unsubscribe/utils/constants.js +4 -3
- package/dist/extensions/Blocks/Unsubscribe/utils/swapMergeTagInHref.js +5 -0
- package/dist/guido.css +1 -1
- package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +92 -93
- package/dist/node_modules/valibot/dist/index.js +261 -297
- package/dist/package.json.js +6 -6
- package/dist/src/@types/config/schemas.d.ts +0 -4
- package/dist/src/composables/useConfig.d.ts +0 -2
- package/dist/src/composables/useStripo.d.ts +1 -1
- package/dist/src/enums/academy.d.ts +0 -1
- package/dist/src/extensions/Blocks/Unsubscribe/utils/constants.d.ts +1 -0
- package/dist/src/extensions/Blocks/Unsubscribe/utils/swapMergeTagInHref.d.ts +1 -0
- package/dist/src/stores/config.d.ts +0 -167
- package/dist/src/utils/linkTrackingIds.d.ts +5 -22
- package/dist/src/utils/trimHrefWhitespace.d.ts +5 -0
- package/dist/stores/config.js +6 -13
- package/dist/utils/linkTrackingIds.js +48 -82
- package/dist/utils/pairProductVariables.js +29 -30
- package/dist/utils/templatePreparation.js +57 -67
- package/dist/utils/trimHrefWhitespace.js +10 -0
- package/package.json +1 -1
- package/dist/@types/display-condition.js +0 -25
- package/dist/components/organisms/display-conditions/CodeEditorField.vue.js +0 -17
- package/dist/components/organisms/display-conditions/CodeEditorField.vue2.js +0 -41
- package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.js +0 -30
- package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue2.js +0 -81
- package/dist/components/organisms/display-conditions/DisplayConditionListState.vue.js +0 -17
- package/dist/components/organisms/display-conditions/DisplayConditionListState.vue2.js +0 -45
- package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.js +0 -36
- package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue2.js +0 -63
- package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue.js +0 -17
- package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue2.js +0 -22
- package/dist/composables/useDisplayConditions.js +0 -117
- package/dist/enums/display-condition.js +0 -12
- package/dist/extensions/DisplayConditions/bridge.js +0 -25
- package/dist/extensions/DisplayConditions/constants.js +0 -26
- package/dist/extensions/DisplayConditions/control.js +0 -215
- package/dist/extensions/DisplayConditions/display-conditions.css.js +0 -226
- package/dist/extensions/DisplayConditions/extension.js +0 -28
- package/dist/extensions/DisplayConditions/iconsRegistry.js +0 -20
- package/dist/extensions/DisplayConditions/library.js +0 -30
- package/dist/extensions/DisplayConditions/settingsPanel.js +0 -17
- package/dist/extensions/LinkTracking/extension.js +0 -17
- package/dist/extensions/LinkTracking/writer.js +0 -41
- package/dist/services/displayConditionApi.js +0 -39
- package/dist/src/@types/display-condition.d.ts +0 -60
- package/dist/src/components/organisms/display-conditions/CodeEditorField.vue.d.ts +0 -43
- package/dist/src/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.d.ts +0 -2
- package/dist/src/components/organisms/display-conditions/DisplayConditionListState.vue.d.ts +0 -18
- package/dist/src/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.d.ts +0 -2
- package/dist/src/components/organisms/display-conditions/DisplayConditionsHost.vue.d.ts +0 -2
- package/dist/src/composables/useDisplayConditions.d.ts +0 -18
- package/dist/src/enums/display-condition.d.ts +0 -15
- package/dist/src/extensions/DisplayConditions/bridge.d.ts +0 -7
- package/dist/src/extensions/DisplayConditions/constants.d.ts +0 -23
- package/dist/src/extensions/DisplayConditions/control.d.ts +0 -25
- package/dist/src/extensions/DisplayConditions/extension.d.ts +0 -2
- package/dist/src/extensions/DisplayConditions/iconsRegistry.d.ts +0 -4
- package/dist/src/extensions/DisplayConditions/library.d.ts +0 -8
- package/dist/src/extensions/DisplayConditions/settingsPanel.d.ts +0 -5
- package/dist/src/extensions/LinkTracking/extension.d.ts +0 -2
- package/dist/src/extensions/LinkTracking/writer.d.ts +0 -13
- package/dist/src/mock/api/display-conditions.d.ts +0 -2
- package/dist/src/services/displayConditionApi.d.ts +0 -8
- package/dist/src/stores/display-condition.d.ts +0 -84
- package/dist/src/utils/displayCondition.d.ts +0 -11
- package/dist/src/utils/protectTableText.d.ts +0 -2
- package/dist/stores/display-condition.js +0 -29
- package/dist/utils/displayCondition.js +0 -26
- package/dist/utils/protectTableText.js +0 -22
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { useConfig as C } from "../../../composables/useConfig.js";
|
|
2
2
|
import { useRecommendation as O } from "../../../composables/useRecommendation.js";
|
|
3
|
-
import { MOBILE_ROW_SELECTOR as q, MOBILE_CONTAINER_SELECTOR as M, CSS_CLASS_RECO_BUTTON as
|
|
4
|
-
import { useRecommendationExtensionStore as
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
function R(t, r, e, o, c = "") {
|
|
3
|
+
import { MOBILE_ROW_SELECTOR as q, MOBILE_CONTAINER_SELECTOR as M, CSS_CLASS_RECO_BUTTON as B } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
|
|
4
|
+
import { useRecommendationExtensionStore as N } from "../../../extensions/Blocks/Recommendation/store/recommendation.js";
|
|
5
|
+
import { isIgnoredRecommendationBlock as T } from "./recommendationIgnoreUtils.js";
|
|
6
|
+
function L(t, r, e, o, c = "") {
|
|
8
7
|
const i = `{{${c}${t}_${r}_${e}}}`, n = `{{${c}${t}_${r}_currency}}`;
|
|
9
8
|
return o === "before" ? `${n} ${i}` : `${i} ${n}`;
|
|
10
9
|
}
|
|
11
|
-
function
|
|
10
|
+
function A(t) {
|
|
12
11
|
let r = t;
|
|
13
12
|
for (; r.children.length === 1; )
|
|
14
13
|
[r] = r.children;
|
|
@@ -20,12 +19,12 @@ function _(t, r, e, o, c, i) {
|
|
|
20
19
|
const n = t.querySelector("img");
|
|
21
20
|
n && (n.setAttribute("src", `{{${i}${e}_${o}_image_url}}`), n.setAttribute("alt", `{{${i}${e}_${o}_name}}`));
|
|
22
21
|
const s = t.querySelector("a");
|
|
23
|
-
s && (s.setAttribute("href", `{{${i}${e}_${o}_url}}`), s.classList.add(
|
|
22
|
+
s && (s.setAttribute("href", `{{${i}${e}_${o}_url}}`), s.classList.add(B));
|
|
24
23
|
break;
|
|
25
24
|
}
|
|
26
25
|
case "productName": {
|
|
27
26
|
const n = t.querySelector("p");
|
|
28
|
-
n && (
|
|
27
|
+
n && (A(n).textContent = `{{${i}${e}_${o}_name}}`);
|
|
29
28
|
break;
|
|
30
29
|
}
|
|
31
30
|
// Inline mode ("Move to next line" OFF) merges BOTH prices into one row
|
|
@@ -33,16 +32,16 @@ function _(t, r, e, o, c, i) {
|
|
|
33
32
|
// substitute by cell content, not by the row's anchor (SD-145161).
|
|
34
33
|
case "productPrice":
|
|
35
34
|
case "productOldPrice": {
|
|
36
|
-
const n = (
|
|
37
|
-
|
|
35
|
+
const n = (a, l) => {
|
|
36
|
+
a && (A(a).textContent = L(
|
|
38
37
|
e,
|
|
39
38
|
o,
|
|
40
|
-
|
|
39
|
+
l,
|
|
41
40
|
c,
|
|
42
41
|
i
|
|
43
42
|
));
|
|
44
|
-
}, s = t.querySelector(".product-price p"),
|
|
45
|
-
n(s ?? (r === "productPrice" ? u : null), "price"), n(
|
|
43
|
+
}, s = t.querySelector(".product-price p"), d = t.querySelector(".product-old-price p"), u = !s && !d ? t.querySelector("p") : null;
|
|
44
|
+
n(s ?? (r === "productPrice" ? u : null), "price"), n(d ?? (r === "productOldPrice" ? u : null), "original_price");
|
|
46
45
|
break;
|
|
47
46
|
}
|
|
48
47
|
case "productButton": {
|
|
@@ -71,72 +70,72 @@ function _(t, r, e, o, c, i) {
|
|
|
71
70
|
default: {
|
|
72
71
|
const n = t.getAttribute("product-attr") ? t : t.querySelector("[product-attr]");
|
|
73
72
|
if (n) {
|
|
74
|
-
const s = n.getAttribute("product-attr"),
|
|
75
|
-
|
|
73
|
+
const s = n.getAttribute("product-attr"), d = n.querySelector("p");
|
|
74
|
+
d && (A(d).textContent = `{{${i}${e}_${o}_${s}}}`);
|
|
76
75
|
}
|
|
77
76
|
break;
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
79
|
}
|
|
81
|
-
const
|
|
80
|
+
const P = "name";
|
|
82
81
|
function y(t, r, e, o) {
|
|
83
|
-
const c = `${o}${r}_${e}_${
|
|
82
|
+
const c = `${o}${r}_${e}_${P}`;
|
|
84
83
|
return {
|
|
85
84
|
open: t.createComment(`{% if ${c} and ${c} != "" %}`),
|
|
86
85
|
close: t.createComment("{% endif %}")
|
|
87
86
|
};
|
|
88
87
|
}
|
|
89
|
-
function
|
|
88
|
+
function R(t, r, e) {
|
|
90
89
|
return y(t, r, 0, e);
|
|
91
90
|
}
|
|
92
|
-
function
|
|
91
|
+
function w(t, r, e, o) {
|
|
93
92
|
if (!t.innerHTML.includes("{{"))
|
|
94
93
|
return;
|
|
95
94
|
const { open: c, close: i } = y(t.ownerDocument, r, e, o);
|
|
96
95
|
t.insertBefore(c, t.firstChild), t.appendChild(i);
|
|
97
96
|
}
|
|
98
|
-
function
|
|
97
|
+
function D(t, r, e, o) {
|
|
99
98
|
var n, s;
|
|
100
99
|
if (!t.innerHTML.includes("{{"))
|
|
101
100
|
return;
|
|
102
101
|
const { open: c, close: i } = y(t.ownerDocument, r, e, o);
|
|
103
102
|
(n = t.parentNode) == null || n.insertBefore(c, t), (s = t.parentNode) == null || s.insertBefore(i, t.nextSibling);
|
|
104
103
|
}
|
|
105
|
-
function
|
|
104
|
+
function v(t, r, e, o) {
|
|
106
105
|
t.querySelectorAll(".recommendation-product-row").forEach((i, n) => {
|
|
107
|
-
i.querySelectorAll("[data-attribute-type]").forEach((
|
|
108
|
-
const u =
|
|
109
|
-
|
|
110
|
-
_(
|
|
111
|
-
}) : _(
|
|
112
|
-
}),
|
|
106
|
+
i.querySelectorAll("[data-attribute-type]").forEach((d) => {
|
|
107
|
+
const u = d.getAttribute("data-attribute-type") || "", a = d.querySelectorAll(".attribute-cell");
|
|
108
|
+
a.length > 0 ? a.forEach((l) => {
|
|
109
|
+
_(l, u, r, n, e, o);
|
|
110
|
+
}) : _(d, u, r, n, e, o);
|
|
111
|
+
}), D(i, r, n, o);
|
|
113
112
|
});
|
|
114
113
|
}
|
|
115
|
-
function
|
|
114
|
+
function H(t, r, e, o) {
|
|
116
115
|
const c = t.querySelectorAll(".recommendation-product-row");
|
|
117
116
|
if (!c.length)
|
|
118
117
|
return;
|
|
119
118
|
const [i] = c, n = i.querySelector("[data-attribute-type]"), s = n ? n.querySelectorAll(".attribute-cell").length : 1;
|
|
120
|
-
c.forEach((
|
|
121
|
-
|
|
122
|
-
const p =
|
|
123
|
-
|
|
119
|
+
c.forEach((d, u) => {
|
|
120
|
+
d.querySelectorAll("[data-attribute-type]").forEach((l) => {
|
|
121
|
+
const p = l.getAttribute("data-attribute-type") || "";
|
|
122
|
+
l.querySelectorAll(".attribute-cell").forEach((m, h) => {
|
|
124
123
|
const S = u * s + h;
|
|
125
|
-
_(m, p, r, S, e, o),
|
|
124
|
+
_(m, p, r, S, e, o), w(m, r, S, o);
|
|
126
125
|
});
|
|
127
126
|
});
|
|
128
127
|
});
|
|
129
128
|
}
|
|
130
|
-
function
|
|
129
|
+
function W(t, r, e, o) {
|
|
131
130
|
t.querySelectorAll(".ins-recommendation-product-container").forEach((i) => {
|
|
132
|
-
|
|
131
|
+
H(i, r, e, o);
|
|
133
132
|
});
|
|
134
133
|
}
|
|
135
|
-
function
|
|
134
|
+
function F(t, r, e) {
|
|
136
135
|
const o = t.getAttribute("data-layout") || "grid", c = t.getAttribute("currency-alignment"), i = c === "0" || c === "before" ? "before" : "after";
|
|
137
|
-
o === "list" ?
|
|
136
|
+
o === "list" ? v(t, r, i, e) : W(t, r, i, e);
|
|
138
137
|
}
|
|
139
|
-
function
|
|
138
|
+
function b(t, r, e) {
|
|
140
139
|
const o = new RegExp(`${r}\\s*:\\s*(\\d+)\\s*px`, "i"), c = t.match(o);
|
|
141
140
|
return c ? parseInt(c[1]) : e;
|
|
142
141
|
}
|
|
@@ -151,7 +150,7 @@ function g(t) {
|
|
|
151
150
|
const e = (t.getAttribute("style") || "").match(/(?:^|[;\s])width\s*:\s*(\d+(?:\.\d+)?(?:px|%))/i);
|
|
152
151
|
return e && $(e[1]) ? e[1] : null;
|
|
153
152
|
}
|
|
154
|
-
function
|
|
153
|
+
function x(t, r) {
|
|
155
154
|
let e = t.parentElement;
|
|
156
155
|
for (; e && e !== r; ) {
|
|
157
156
|
if (e.tagName === "TD" && g(e))
|
|
@@ -160,64 +159,62 @@ function V(t, r) {
|
|
|
160
159
|
}
|
|
161
160
|
return null;
|
|
162
161
|
}
|
|
163
|
-
function
|
|
164
|
-
const r = t.getAttribute("style") || "", e =
|
|
162
|
+
function G(t) {
|
|
163
|
+
const r = t.getAttribute("style") || "", e = b(r, "width", 600), o = b(r, "padding", 0) * 2, c = Math.max(0, e - o);
|
|
165
164
|
c !== 0 && t.querySelectorAll("img.adapt-img").forEach((i) => {
|
|
166
165
|
if (i.hasAttribute("width"))
|
|
167
166
|
return;
|
|
168
|
-
const n =
|
|
167
|
+
const n = x(i, t);
|
|
169
168
|
if (!n)
|
|
170
169
|
return;
|
|
171
|
-
const s = g(n),
|
|
170
|
+
const s = g(n), d = b(n.getAttribute("style") || "", "padding", 0) * 2, u = s.endsWith("%") ? Math.floor(c * parseFloat(s) / 100) : parseInt(s), a = Math.max(1, u - d), l = i.getAttribute("style") || "", p = /(?:^|[;\s])max-height\s*:\s*(\d+(?:\.\d+)?)px/i.exec(l);
|
|
172
171
|
if (p) {
|
|
173
|
-
i.setAttribute("width", String(Math.max(1, Math.min(
|
|
172
|
+
i.setAttribute("width", String(Math.max(1, Math.min(a, Math.floor(parseFloat(p[1])))))), i.removeAttribute("height");
|
|
174
173
|
return;
|
|
175
174
|
}
|
|
176
|
-
if (i.setAttribute("width", String(
|
|
177
|
-
const f =
|
|
178
|
-
i.setAttribute("style", `${
|
|
175
|
+
if (i.setAttribute("width", String(a)), !/\bwidth\s*:\s*\d/i.test(l)) {
|
|
176
|
+
const f = l && !l.trim().endsWith(";") ? "; " : "";
|
|
177
|
+
i.setAttribute("style", `${l}${f}width: ${a}px`);
|
|
179
178
|
}
|
|
180
179
|
});
|
|
181
180
|
}
|
|
182
|
-
const E = "MSO_MOBILE_HIDE_START",
|
|
183
|
-
function
|
|
181
|
+
const E = "MSO_MOBILE_HIDE_START", V = "MSO_MOBILE_HIDE_END";
|
|
182
|
+
function U(t, r) {
|
|
184
183
|
t.querySelectorAll(q).forEach((e) => {
|
|
185
184
|
var i, n;
|
|
186
185
|
const o = e.querySelector(M);
|
|
187
186
|
if (!o || o.children.length === 0)
|
|
188
187
|
return;
|
|
189
188
|
const c = e.previousSibling;
|
|
190
|
-
(c == null ? void 0 : c.nodeType) === Node.COMMENT_NODE && c.data === E || ((i = e.parentNode) == null || i.insertBefore(r.createComment(E), e), (n = e.parentNode) == null || n.insertBefore(r.createComment(
|
|
189
|
+
(c == null ? void 0 : c.nodeType) === Node.COMMENT_NODE && c.data === E || ((i = e.parentNode) == null || i.insertBefore(r.createComment(E), e), (n = e.parentNode) == null || n.insertBefore(r.createComment(V), e.nextSibling));
|
|
191
190
|
});
|
|
192
191
|
}
|
|
193
|
-
function
|
|
192
|
+
function X(t, r) {
|
|
194
193
|
const e = t.match(/<!DOCTYPE[^>]*>/i);
|
|
195
194
|
return (e ? `${e[0]}
|
|
196
195
|
` : "") + r.documentElement.outerHTML;
|
|
197
196
|
}
|
|
198
|
-
function
|
|
199
|
-
const r =
|
|
197
|
+
function Q(t) {
|
|
198
|
+
const r = t.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), e = new DOMParser().parseFromString(r, "text/html"), o = e.querySelectorAll(".recommendation-block-v2");
|
|
200
199
|
if (!o.length)
|
|
201
200
|
return t;
|
|
202
|
-
const { buildCampaignUrl: c } = O(), i =
|
|
201
|
+
const { buildCampaignUrl: c } = O(), i = N();
|
|
203
202
|
i.recommendationCampaignUrls = {};
|
|
204
203
|
const { isFeatureEnabled: n } = C(), s = n("liquidSyntax") ? "reco_" : "";
|
|
205
|
-
o.forEach((u) => {
|
|
206
|
-
var
|
|
207
|
-
const
|
|
208
|
-
if (
|
|
209
|
-
if ((
|
|
210
|
-
|
|
211
|
-
const { open: h, close: S } =
|
|
204
|
+
return o.forEach((u) => {
|
|
205
|
+
var l, p, f, m;
|
|
206
|
+
const a = u.getAttribute("recommendation-id");
|
|
207
|
+
if (a) {
|
|
208
|
+
if ((l = u.parentNode) == null || l.insertBefore(e.createComment("REC_START"), u), (p = u.parentNode) == null || p.insertBefore(e.createComment("REC_END"), u.nextSibling), u.querySelectorAll('[data-visibility="0"]').forEach((h) => h.remove()), c(a), U(u, e), !T(u)) {
|
|
209
|
+
F(u, a, s);
|
|
210
|
+
const { open: h, close: S } = R(e, a, s);
|
|
212
211
|
(f = u.parentNode) == null || f.insertBefore(h, u), (m = u.parentNode) == null || m.insertBefore(S, u.nextSibling);
|
|
213
212
|
}
|
|
214
|
-
|
|
213
|
+
G(u);
|
|
215
214
|
}
|
|
216
|
-
});
|
|
217
|
-
const a = Y(r, e);
|
|
218
|
-
return L(a.replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}"));
|
|
215
|
+
}), X(r, e).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}");
|
|
219
216
|
}
|
|
220
217
|
export {
|
|
221
|
-
|
|
222
|
-
|
|
218
|
+
L as formatPriceVariable,
|
|
219
|
+
Q as prepareRecommendationBlocks
|
|
223
220
|
};
|
|
@@ -1,146 +1,137 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { MERGE_TAGS as
|
|
5
|
-
import { UNSUBSCRIBE_BLOCK_SELECTOR as
|
|
6
|
-
import {
|
|
7
|
-
|
|
1
|
+
var $ = Object.defineProperty;
|
|
2
|
+
var L = (b, e, t) => e in b ? $(b, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : b[e] = t;
|
|
3
|
+
var m = (b, e, t) => L(b, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { MERGE_TAGS as l, PAGE_TYPES as h } from "../../enums/unsubscribe.js";
|
|
5
|
+
import { UNSUBSCRIBE_BLOCK_SELECTOR as A, UNSUBSCRIBE_MERGE_TAG_REGEX as y, DATA_ATTRIBUTES as d } from "../../extensions/Blocks/Unsubscribe/utils/constants.js";
|
|
6
|
+
import { swapMergeTagInHref as _ } from "../../extensions/Blocks/Unsubscribe/utils/swapMergeTagInHref.js";
|
|
7
|
+
import { useUnsubscribeStore as B } from "../../stores/unsubscribe.js";
|
|
8
|
+
const S = "unsubscribe", R = "You can ", M = " from our emails, if you need to.", k = "{-{-UNSUBSCRIBE-LINK-}-}";
|
|
9
|
+
class N {
|
|
8
10
|
constructor() {
|
|
9
|
-
|
|
11
|
+
m(this, "parser");
|
|
10
12
|
this.parser = new DOMParser();
|
|
11
13
|
}
|
|
12
14
|
async migrate(e) {
|
|
13
15
|
try {
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
const s =
|
|
17
|
-
await s.fetchTemplates(), this.migrateLegacyBlocks(
|
|
16
|
+
const t = this.parser.parseFromString(e, "text/html"), r = t.querySelectorAll("td.unsubscribe-block");
|
|
17
|
+
if (r.length) {
|
|
18
|
+
const s = B();
|
|
19
|
+
await s.fetchTemplates(), this.migrateLegacyBlocks(r, s, this.collectBlockTags(t));
|
|
18
20
|
}
|
|
19
|
-
const n = this.repairUnsubscribeLinks(
|
|
20
|
-
return !
|
|
21
|
-
} catch (
|
|
22
|
-
return console.error("UnsubscribeMigrator failed:",
|
|
21
|
+
const n = this.repairUnsubscribeLinks(t);
|
|
22
|
+
return !r.length && !n ? e : t.documentElement.outerHTML;
|
|
23
|
+
} catch (t) {
|
|
24
|
+
return console.error("UnsubscribeMigrator failed:", t), e;
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
|
-
migrateLegacyBlocks(e, r) {
|
|
26
|
-
e.forEach((
|
|
27
|
-
const
|
|
27
|
+
migrateLegacyBlocks(e, t, r) {
|
|
28
|
+
e.forEach((n) => {
|
|
29
|
+
const s = n.getAttribute("id"), a = this.extractPaddingClass(n), o = n.getAttribute("bgcolor") || "", i = this.extractUnsubscribeContent(n, r), g = this.getCollectionTypeFromMergeTag(i.linkHref), p = t.getSelectedUnsubscribePagesByCollection(g);
|
|
28
30
|
console.debug("[UnsubscribeMigrator]", {
|
|
29
|
-
mergeTag:
|
|
30
|
-
collectionType:
|
|
31
|
-
pageIds:
|
|
32
|
-
paddingClass:
|
|
33
|
-
bgColor:
|
|
31
|
+
mergeTag: i.linkHref,
|
|
32
|
+
collectionType: g,
|
|
33
|
+
pageIds: p,
|
|
34
|
+
paddingClass: a,
|
|
35
|
+
bgColor: o
|
|
34
36
|
});
|
|
35
|
-
const
|
|
37
|
+
const c = this.buildUnsubscribeBlock(
|
|
38
|
+
i,
|
|
39
|
+
g,
|
|
40
|
+
p,
|
|
36
41
|
a,
|
|
37
|
-
o
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
l
|
|
41
|
-
), i = this.parser.parseFromString(
|
|
42
|
-
`<table id="tempDoc"><tbody><tr>${u}</tr></tbody></table>`,
|
|
42
|
+
o
|
|
43
|
+
), u = this.parser.parseFromString(
|
|
44
|
+
`<table id="tempDoc"><tbody><tr>${c}</tr></tbody></table>`,
|
|
43
45
|
"text/html"
|
|
44
|
-
).querySelector(
|
|
45
|
-
|
|
46
|
+
).querySelector(A);
|
|
47
|
+
u && n.parentNode && (u.setAttribute("id", s || ""), n.parentNode.replaceChild(u, n));
|
|
46
48
|
});
|
|
47
49
|
}
|
|
50
|
+
collectBlockTags(e) {
|
|
51
|
+
const t = e.querySelectorAll(`td.unsubscribe-block, ${A}`), r = /* @__PURE__ */ new Set();
|
|
52
|
+
return t.forEach((n) => {
|
|
53
|
+
var o, i;
|
|
54
|
+
const s = n.querySelector("a.unsubscribe-link") ?? n.querySelector('a[href*="unsubscribe"]'), a = (i = (o = s == null ? void 0 : s.getAttribute("href")) == null ? void 0 : o.match(y)) == null ? void 0 : i[0];
|
|
55
|
+
a && r.add(l[this.getCollectionTypeFromMergeTag(a)]);
|
|
56
|
+
}), r;
|
|
57
|
+
}
|
|
48
58
|
// Re-derives the typed merge tag from data-unsubscribe-page-type for any v2
|
|
49
59
|
// block whose anchor href is missing or the legacy default. Returns true when
|
|
50
60
|
// at least one href was rewritten. Typed tags and custom URLs are left intact.
|
|
51
61
|
repairUnsubscribeLinks(e) {
|
|
52
|
-
const
|
|
53
|
-
let
|
|
54
|
-
return
|
|
62
|
+
const t = e.querySelectorAll(`${A}[${d.PAGE_TYPE}]`);
|
|
63
|
+
let r = !1;
|
|
64
|
+
return t.forEach((n) => {
|
|
55
65
|
const s = n.querySelector('a[data-unsubscribe-link="true"], a.unsubscribe-link');
|
|
56
66
|
if (!s)
|
|
57
67
|
return;
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
68
|
+
const a = s.getAttribute("href") || "";
|
|
69
|
+
if (a && a !== l.default)
|
|
60
70
|
return;
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
}),
|
|
71
|
+
const o = Number(n.getAttribute(d.PAGE_TYPE)), i = l[o];
|
|
72
|
+
i && (s.setAttribute("href", i), r = !0);
|
|
73
|
+
}), r;
|
|
64
74
|
}
|
|
65
75
|
extractPaddingClass(e) {
|
|
66
|
-
const
|
|
67
|
-
return
|
|
76
|
+
const r = (e.getAttribute("class") || "").match(/\bes-p\d+\b/);
|
|
77
|
+
return r ? r[0] : "";
|
|
78
|
+
}
|
|
79
|
+
hasVisibleContent(e) {
|
|
80
|
+
var t;
|
|
81
|
+
return !!((t = e.textContent) != null && t.trim() || e.querySelector("img"));
|
|
68
82
|
}
|
|
69
|
-
extractUnsubscribeContent(e) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
|
83
|
+
extractUnsubscribeContent(e, t) {
|
|
84
|
+
const r = e.cloneNode(!0), n = Array.from(/* @__PURE__ */ new Set([
|
|
85
|
+
...Array.from(r.querySelectorAll("a.unsubscribe-link")),
|
|
86
|
+
...Array.from(r.querySelectorAll('a[href*="unsubscribe"]'))
|
|
87
|
+
])), s = n.find((g) => this.hasVisibleContent(g)) ?? n[0], a = (s == null ? void 0 : s.closest("p")) ?? null, o = a || r.querySelector("p"), i = {
|
|
88
|
+
paragraphsHtml: "",
|
|
89
|
+
linkText: S,
|
|
90
|
+
linkHref: l.default,
|
|
91
|
+
linkStyle: "",
|
|
92
|
+
align: "center",
|
|
93
|
+
paragraphStyle: ""
|
|
108
94
|
};
|
|
95
|
+
if (!o || (i.align = e.getAttribute("align") || o.getAttribute("align") || "center", i.paragraphStyle = o.getAttribute("style") || "", !s))
|
|
96
|
+
return i;
|
|
97
|
+
if (i.linkText = this.hasVisibleContent(s) ? s.innerHTML.trim() : S, i.linkHref = this.normalizeUnsubscribeHref(s.getAttribute("href") || l.default), i.linkStyle = s.getAttribute("style") || "", a) {
|
|
98
|
+
const g = this.getCollectionTypeFromMergeTag(i.linkHref), p = l[g];
|
|
99
|
+
r.querySelectorAll("a[href]").forEach((c) => {
|
|
100
|
+
var T;
|
|
101
|
+
const f = c.getAttribute("href") || "", u = (T = f.match(y)) == null ? void 0 : T[0];
|
|
102
|
+
u && c.setAttribute("href", _(f, t.has(u) ? u : p));
|
|
103
|
+
}), n.filter((c) => c !== s && !this.hasVisibleContent(c)).forEach((c) => c.replaceWith(...Array.from(c.childNodes))), s.replaceWith(r.ownerDocument.createTextNode(k)), i.paragraphsHtml = Array.from(r.querySelectorAll("p"), (c) => c.outerHTML).join("");
|
|
104
|
+
}
|
|
105
|
+
return i;
|
|
109
106
|
}
|
|
110
|
-
buildUnsubscribeBlock(e,
|
|
111
|
-
const
|
|
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";
|
|
107
|
+
buildUnsubscribeBlock(e, t, r, n, s) {
|
|
108
|
+
const a = e.linkStyle ? ` style="${e.linkStyle}"` : "", p = `<a ${`href="${Object.values(l).includes(e.linkHref) ? l[t] : e.linkHref}" class="unsubscribe-link" target="_blank" data-unsubscribe-link="true"`}${a}>${e.linkText}</a>`, c = e.paragraphStyle ? ` style="${e.paragraphStyle}"` : "", f = e.paragraphsHtml ? e.paragraphsHtml.replace(k, () => p) : `<p path="1"${c}>${R}${p}${M}</p>`, u = e.align ? ` align="${e.align}"` : "", T = s ? ` bgcolor="${s}"` : "", C = r.length > 0 ? ` ${d.PAGE_LIST}="${r.join(",")}"` : "", U = ` ${d.PAGE_TYPE}="${t}"`, E = "esd-block-text unsubscribe-block-v2 esd-block-unsubscribe esd-unsubscribe-block esd-extension-block";
|
|
116
109
|
return `
|
|
117
110
|
<td
|
|
118
111
|
data-migration="true"
|
|
119
112
|
esd-extension-block-id="unsubscribe-block"
|
|
120
|
-
class="${n ? `${
|
|
121
|
-
${
|
|
113
|
+
class="${n ? `${E} ${n}` : E}"
|
|
114
|
+
${u}${T}${U}${C}
|
|
122
115
|
>
|
|
123
|
-
|
|
124
|
-
${i}
|
|
125
|
-
</p>
|
|
116
|
+
${f}
|
|
126
117
|
</td>
|
|
127
118
|
`;
|
|
128
119
|
}
|
|
129
120
|
getCollectionTypeFromMergeTag(e) {
|
|
130
|
-
return e ===
|
|
121
|
+
return e === l[h.SUBSCRIPTION_PREFERENCE_CENTER] ? h.SUBSCRIPTION_PREFERENCE_CENTER : e === l[h.GLOBAL_UNSUBSCRIBE] ? h.GLOBAL_UNSUBSCRIBE : h.GLOBAL_UNSUBSCRIBE;
|
|
131
122
|
}
|
|
132
123
|
normalizeUnsubscribeHref(e) {
|
|
133
|
-
if (Object.values(
|
|
124
|
+
if (Object.values(l).includes(e))
|
|
134
125
|
return e;
|
|
135
|
-
const
|
|
136
|
-
return
|
|
126
|
+
const r = e.match(/{{ins-(?:global-)?(?:preferences-)?unsubscribe-link}}/);
|
|
127
|
+
return r ? r[0] : e.includes("unsubscribe") || e.includes("unsub") ? (console.warn(
|
|
137
128
|
`[UnsubscribeMigrator] Unrecognized unsubscribe href format: "${e}". Defaulting to {{ins-unsubscribe-link}}`
|
|
138
129
|
), "{{ins-unsubscribe-link}}") : e;
|
|
139
130
|
}
|
|
140
131
|
}
|
|
141
|
-
async function
|
|
142
|
-
return new
|
|
132
|
+
async function G(b) {
|
|
133
|
+
return new N().migrate(b);
|
|
143
134
|
}
|
|
144
135
|
export {
|
|
145
|
-
|
|
136
|
+
G as migrateUnsubscribe
|
|
146
137
|
};
|
package/dist/enums/academy.js
CHANGED
|
@@ -2,7 +2,6 @@ const e = "https://academy.insiderone.com", o = {
|
|
|
2
2
|
EMAIL_EDITOR: `${e}/docs/email-drag-and-drop-editor`,
|
|
3
3
|
GLOBAL_UNSUBSCRIBE: `${e}/docs/global-unsubscribe-preference-center`,
|
|
4
4
|
AMP_FOR_EMAILS: `${e}/docs/amp-for-emails`,
|
|
5
|
-
EMAIL_DISPLAY_CONDITIONS: `${e}/docs/new-editor-add-display-conditions-to-an-email`,
|
|
6
5
|
EMAIL_RECOMMENDATION_BLOCK: `${e}/docs/new-editor-email-recommendation-block`
|
|
7
6
|
};
|
|
8
7
|
export {
|