@useinsider/guido 3.9.0 → 3.9.1
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/config/compiler/utils/recommendationCompilerUtils.js +118 -110
- package/dist/config/migrator/itemsBlockMigrator.js +159 -114
- package/dist/config/migrator/unsubscribeMigrator.js +89 -67
- package/dist/extensions/Blocks/Items/block.js +57 -37
- package/dist/extensions/Blocks/Items/controls/name/trimming.js +17 -18
- package/dist/extensions/Blocks/Items/controls/settingsControl.js +67 -78
- package/dist/extensions/Blocks/Items/layouts/horizontal.html.js +13 -9
- package/dist/extensions/Blocks/Items/layouts/vertical.html.js +26 -14
- package/dist/extensions/Blocks/Items/template.js +245 -247
- package/dist/extensions/Blocks/Items/utils/nodeConfigUtils.js +53 -45
- package/dist/extensions/Blocks/Recommendation/templates/list/template.js +15 -15
- package/dist/package.json.js +1 -1
- package/dist/src/extensions/Blocks/Items/block.d.ts +9 -0
- package/dist/src/extensions/Blocks/Items/template.d.ts +7 -0
- package/dist/src/extensions/Blocks/Items/utils/nodeConfigUtils.d.ts +12 -0
- package/package.json +2 -2
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var M = (
|
|
4
|
-
import { BLOCK_ID as
|
|
1
|
+
var v = Object.defineProperty;
|
|
2
|
+
var U = (o, t, r) => t in o ? v(o, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : o[t] = r;
|
|
3
|
+
var M = (o, t, r) => U(o, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { BLOCK_ID as w } from "../../extensions/Blocks/Items/block.js";
|
|
5
5
|
import { productPairs as K } from "../../extensions/Blocks/Items/enums/productEnums.js";
|
|
6
|
-
import { ItemInCartOptions as
|
|
7
|
-
import { getDefaultTemplate as
|
|
8
|
-
import { useTemplateStore as
|
|
9
|
-
const
|
|
6
|
+
import { ItemInCartOptions as I, DefaultConfigValues as g, SETTINGS_ENUMS as p } from "../../extensions/Blocks/Items/enums/settingsEnums.js";
|
|
7
|
+
import { getDefaultTemplate as F } from "../../extensions/Blocks/Items/template.js";
|
|
8
|
+
import { useTemplateStore as q } from "../../stores/template.js";
|
|
9
|
+
const x = {
|
|
10
10
|
img: {
|
|
11
11
|
pairsKey: "imageSrc",
|
|
12
12
|
defaultKey: "DEFAULT",
|
|
@@ -76,77 +76,77 @@ const q = {
|
|
|
76
76
|
function O() {
|
|
77
77
|
return String(Date.now() + Math.floor(Math.random() * 1e3));
|
|
78
78
|
}
|
|
79
|
-
function
|
|
80
|
-
return
|
|
81
|
-
CartItems:
|
|
82
|
-
BrowsedItems:
|
|
83
|
-
PurchasedItems:
|
|
84
|
-
CART_ITEMS:
|
|
85
|
-
BROWSED_ITEMS:
|
|
86
|
-
PURCHASED_ITEMS:
|
|
87
|
-
}[
|
|
79
|
+
function k(o) {
|
|
80
|
+
return o ? {
|
|
81
|
+
CartItems: p.ITEMS_TYPE.CART_ITEMS,
|
|
82
|
+
BrowsedItems: p.ITEMS_TYPE.BROWSED_ITEMS,
|
|
83
|
+
PurchasedItems: p.ITEMS_TYPE.PURCHASED_ITEMS,
|
|
84
|
+
CART_ITEMS: p.ITEMS_TYPE.CART_ITEMS,
|
|
85
|
+
BROWSED_ITEMS: p.ITEMS_TYPE.BROWSED_ITEMS,
|
|
86
|
+
PURCHASED_ITEMS: p.ITEMS_TYPE.PURCHASED_ITEMS
|
|
87
|
+
}[o] || p.ITEMS_TYPE.CART_ITEMS : p.ITEMS_TYPE.CART_ITEMS;
|
|
88
88
|
}
|
|
89
|
-
function
|
|
89
|
+
function h(o) {
|
|
90
90
|
var e;
|
|
91
|
-
const t = (c,
|
|
92
|
-
let
|
|
93
|
-
if (
|
|
94
|
-
const c = parseInt(
|
|
95
|
-
|
|
91
|
+
const t = (c, u) => c == null ? u : c === "1" || c === "true", r = (c, u) => c || u, l = o["data-type"] || o["data-source"], a = k(l), i = I[a];
|
|
92
|
+
let n = o["data-cart_items_select_control_value"] || ((e = i == null ? void 0 : i[0]) == null ? void 0 : e.value) || g.cartItemsSelectControlValue;
|
|
93
|
+
if (n && !n.includes("{{") && /^\d+$/.test(n)) {
|
|
94
|
+
const c = parseInt(n) - 1, u = I[a];
|
|
95
|
+
u && u[c] && (n = u[c].value);
|
|
96
96
|
}
|
|
97
97
|
return {
|
|
98
98
|
initialized: !0,
|
|
99
|
-
blockInstanceId: o
|
|
99
|
+
blockInstanceId: r(o["data-block-instance-id"], O()),
|
|
100
100
|
source: a,
|
|
101
101
|
type: a,
|
|
102
|
-
itemsSelectValue:
|
|
103
|
-
orientation:
|
|
104
|
-
nameTrimming: t(
|
|
105
|
-
priceHideDiscount: t(
|
|
106
|
-
priceFormatted: t(
|
|
107
|
-
priceSinglePrice: t(
|
|
108
|
-
priceCurrencySymbol:
|
|
109
|
-
|
|
102
|
+
itemsSelectValue: n,
|
|
103
|
+
orientation: o["data-card_orientation_control_value"] || p.ORIENTATION.VERTICAL,
|
|
104
|
+
nameTrimming: t(o["data-product_name_control_trim"], !0),
|
|
105
|
+
priceHideDiscount: t(o["data-product_price_control_nodup"], !0),
|
|
106
|
+
priceFormatted: t(o["data-product_price_control_formated"], !0),
|
|
107
|
+
priceSinglePrice: t(o["data-product_price_control_single_price"], !1),
|
|
108
|
+
priceCurrencySymbol: r(
|
|
109
|
+
o["data-product_price_control_currency_symbol"],
|
|
110
110
|
g.productPriceCurrencySymbolControlValue
|
|
111
111
|
),
|
|
112
|
-
priceCurrencyLocation:
|
|
113
|
-
|
|
112
|
+
priceCurrencyLocation: r(
|
|
113
|
+
o["data-product_price_currency_location"],
|
|
114
114
|
g.productPriceCurrencyLocationControlValue
|
|
115
115
|
),
|
|
116
|
-
priceOrientation:
|
|
117
|
-
quantityControlEnabled: t(
|
|
118
|
-
buttonLink: o
|
|
119
|
-
imageLink: o
|
|
120
|
-
buttonLabel: o
|
|
121
|
-
buttonFullWidth: t(
|
|
122
|
-
imageVisible: t(
|
|
123
|
-
nameVisible: t(
|
|
124
|
-
quantityVisible: t(
|
|
125
|
-
priceVisible: t(
|
|
126
|
-
originalPriceVisible: t(
|
|
127
|
-
buttonVisible: t(
|
|
116
|
+
priceOrientation: o["data-product_original_price_control_orientation"] || "horizontal",
|
|
117
|
+
quantityControlEnabled: t(o["data-product_quantity_control_enabled"], !0),
|
|
118
|
+
buttonLink: r(o["data-product_button_link"], g.productButtonLinkControlValue),
|
|
119
|
+
imageLink: r(o["data-product_image_link"], g.productImageLinkControlValue),
|
|
120
|
+
buttonLabel: r(o["data-product_button_control_label"], "Buy"),
|
|
121
|
+
buttonFullWidth: t(o["data-product_button_control_atw"], !0),
|
|
122
|
+
imageVisible: t(o["data-product_image_control_enabled"], !0),
|
|
123
|
+
nameVisible: t(o["data-product_name_control_enabled"], !0),
|
|
124
|
+
quantityVisible: t(o["data-product_quantity_control_enabled"], !0),
|
|
125
|
+
priceVisible: t(o["data-product_price_control_enabled"], !0),
|
|
126
|
+
originalPriceVisible: t(o["data-product_original_price_control_enabled"], !0),
|
|
127
|
+
buttonVisible: t(o["data-product_button_control_enabled"], !0)
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
|
-
const
|
|
130
|
+
const V = {
|
|
131
131
|
ins_apr: "CART_ITEMS",
|
|
132
132
|
browsed_item: "BROWSED_ITEMS",
|
|
133
133
|
purchased_item: "PURCHASED_ITEMS"
|
|
134
134
|
};
|
|
135
|
-
function
|
|
136
|
-
const
|
|
135
|
+
function $(o, t) {
|
|
136
|
+
const r = {
|
|
137
137
|
CART_ITEMS: `{{Abandoned Cart Item (${t}) Image}}`,
|
|
138
138
|
BROWSED_ITEMS: `{{Browsed Item (${t}) Image}}`,
|
|
139
139
|
PURCHASED_ITEMS: `{{Purchased Item (${t}) Image}}`
|
|
140
140
|
};
|
|
141
|
-
return o
|
|
141
|
+
return r[o] || r.CART_ITEMS;
|
|
142
142
|
}
|
|
143
|
-
function N(
|
|
144
|
-
const
|
|
143
|
+
function N(o, t) {
|
|
144
|
+
const r = {
|
|
145
145
|
CART_ITEMS: `{{Abandoned Cart Item (${t}) Url}}`,
|
|
146
146
|
BROWSED_ITEMS: `{{Browsed Item (${t}) Url}}`,
|
|
147
147
|
PURCHASED_ITEMS: `{{Purchased Item (${t}) Url}}`
|
|
148
148
|
};
|
|
149
|
-
return o
|
|
149
|
+
return r[o] || r.CART_ITEMS;
|
|
150
150
|
}
|
|
151
151
|
class z {
|
|
152
152
|
constructor() {
|
|
@@ -156,16 +156,16 @@ class z {
|
|
|
156
156
|
migrate(t) {
|
|
157
157
|
try {
|
|
158
158
|
if (!this.containsItemsBlock(t))
|
|
159
|
-
return t;
|
|
160
|
-
let
|
|
161
|
-
|
|
162
|
-
const l = this.parser.parseFromString(
|
|
159
|
+
return this.backfillV2ProductTdAttributes(t);
|
|
160
|
+
let r = this.removeJinjaConditionals(t);
|
|
161
|
+
r = this.replaceTemplateVariables(r);
|
|
162
|
+
const l = this.parser.parseFromString(r, "text/html"), a = l.querySelectorAll(
|
|
163
163
|
"td.esd-cart-items-block, td.esd-browsed-items-block, td.esd-purchased-items-block"
|
|
164
164
|
);
|
|
165
|
-
return
|
|
166
|
-
|
|
167
|
-
}), a.length === 0 ? (console.warn("ItemsBlockMigrator: No blocks found with items block selectors"),
|
|
168
|
-
const e = this.extractConfiguration(
|
|
165
|
+
return q().$patch((n) => {
|
|
166
|
+
n.migrations = { ...n.migrations, [w]: a.length };
|
|
167
|
+
}), a.length === 0 ? (console.warn("ItemsBlockMigrator: No blocks found with items block selectors"), r) : (a.forEach((n) => {
|
|
168
|
+
const e = this.extractConfiguration(n), c = F({
|
|
169
169
|
orientation: e.orientation,
|
|
170
170
|
itemsType: e.itemsType,
|
|
171
171
|
itemId: e.itemId,
|
|
@@ -179,20 +179,20 @@ class z {
|
|
|
179
179
|
priceStyles: e.priceStyles,
|
|
180
180
|
originalPriceStyles: e.originalPriceStyles,
|
|
181
181
|
quantityStyles: e.quantityStyles,
|
|
182
|
-
nodeConfig:
|
|
183
|
-
}),
|
|
182
|
+
nodeConfig: h(e.configBlockAttributes)
|
|
183
|
+
}), s = this.parser.parseFromString(
|
|
184
184
|
`<table><tbody><tr>${c}</tr></tbody></table>`,
|
|
185
185
|
"text/html"
|
|
186
186
|
).querySelector("td");
|
|
187
|
-
if (
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
const d =
|
|
191
|
-
d && d.remove(),
|
|
187
|
+
if (s && n.parentNode) {
|
|
188
|
+
const _ = h(e.configBlockAttributes);
|
|
189
|
+
s.setAttribute("esd-ext-config", JSON.stringify(_)), s.setAttribute("data-type", _.type);
|
|
190
|
+
const d = s.querySelector("esd-config-block");
|
|
191
|
+
d && d.remove(), n.parentNode.replaceChild(s, n);
|
|
192
192
|
}
|
|
193
193
|
}), l.documentElement.outerHTML);
|
|
194
|
-
} catch (
|
|
195
|
-
return console.error("ItemsBlockMigrator failed:",
|
|
194
|
+
} catch (r) {
|
|
195
|
+
return console.error("ItemsBlockMigrator failed:", r), t;
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
/**
|
|
@@ -203,23 +203,25 @@ class z {
|
|
|
203
203
|
*/
|
|
204
204
|
extractConfiguration(t) {
|
|
205
205
|
var C, D, P;
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
206
|
+
const r = k(
|
|
207
|
+
((C = t.querySelector("[data-type]")) == null ? void 0 : C.getAttribute("data-type")) ?? null
|
|
208
|
+
), l = ((D = t.querySelector("[data-number]")) == null ? void 0 : D.getAttribute("data-number")) || "1", a = parseInt(l) - 1, i = I[r], n = ((P = i == null ? void 0 : i[a]) == null ? void 0 : P.value) || i[0].value, e = t.querySelector('[product-attr="price"]'), c = (e == null ? void 0 : e.getAttribute("data-currency_symbol")) || "USD", s = ((e == null ? void 0 : e.getAttribute("data-curency")) || "before") === "after" ? "1" : "0", _ = (e == null ? void 0 : e.getAttribute("data-formated")) !== "false", d = this.extractConfigBlockAttributes(t, r, l), b = d["data-card_orientation_control_value"];
|
|
209
|
+
let S;
|
|
210
|
+
b ? S = b === "horizontal" ? "horizontal" : "vertical" : S = t.querySelector('[colspan="2"]') !== null ? "vertical" : "horizontal";
|
|
211
|
+
const y = t.querySelector('a[product-attr="name"]'), A = (y == null ? void 0 : y.getAttribute("style")) || void 0, f = t.querySelector('a[product-attr="button"]'), m = (f == null ? void 0 : f.getAttribute("style")) || void 0, R = (e == null ? void 0 : e.getAttribute("style")) || void 0, T = t.querySelector("p.original-price"), L = (T == null ? void 0 : T.getAttribute("style")) || void 0, E = t.querySelector('[product-attr="quantity"]'), B = (E == null ? void 0 : E.getAttribute("style")) || void 0;
|
|
210
212
|
return {
|
|
211
|
-
orientation:
|
|
212
|
-
itemsType:
|
|
213
|
-
itemId:
|
|
213
|
+
orientation: S,
|
|
214
|
+
itemsType: r,
|
|
215
|
+
itemId: n,
|
|
214
216
|
currencySymbol: c,
|
|
215
|
-
currencyLocation:
|
|
216
|
-
formattedPrice:
|
|
217
|
+
currencyLocation: s,
|
|
218
|
+
formattedPrice: _,
|
|
217
219
|
configBlockAttributes: d,
|
|
218
|
-
nameStyles:
|
|
220
|
+
nameStyles: A,
|
|
219
221
|
buttonStyles: m,
|
|
220
|
-
priceStyles:
|
|
221
|
-
originalPriceStyles:
|
|
222
|
-
quantityStyles:
|
|
222
|
+
priceStyles: R,
|
|
223
|
+
originalPriceStyles: L,
|
|
224
|
+
quantityStyles: B
|
|
223
225
|
};
|
|
224
226
|
}
|
|
225
227
|
/**
|
|
@@ -229,27 +231,27 @@ class z {
|
|
|
229
231
|
* @param itemsType - The type of items (CART_ITEMS, BROWSED_ITEMS, PURCHASED_ITEMS)
|
|
230
232
|
* @param itemNumber - The item number (1-based index)
|
|
231
233
|
*/
|
|
232
|
-
extractConfigBlockAttributes(t,
|
|
233
|
-
const a = t.querySelector("esd-config-block"),
|
|
234
|
+
extractConfigBlockAttributes(t, r, l) {
|
|
235
|
+
const a = t.querySelector("esd-config-block"), i = {};
|
|
234
236
|
if (!a)
|
|
235
237
|
return this.getDefaultConfigBlockAttributes();
|
|
236
238
|
if (Array.from(a.attributes).forEach((e) => {
|
|
237
|
-
e.name.startsWith("data-") && (
|
|
238
|
-
}),
|
|
239
|
-
const e =
|
|
239
|
+
e.name.startsWith("data-") && (i[e.name] = e.value);
|
|
240
|
+
}), i["data-cart_items_select_control_value"]) {
|
|
241
|
+
const e = i["data-cart_items_select_control_value"];
|
|
240
242
|
if (/^\d+$/.test(e)) {
|
|
241
|
-
const c = parseInt(e) - 1,
|
|
242
|
-
|
|
243
|
+
const c = parseInt(e) - 1, u = I[r];
|
|
244
|
+
u && u[c] && (i["data-cart_items_select_control_value"] = u[c].value);
|
|
243
245
|
}
|
|
244
246
|
}
|
|
245
|
-
if (
|
|
246
|
-
const e =
|
|
247
|
+
if (i["data-product_price_control_curency"]) {
|
|
248
|
+
const e = i["data-product_price_control_curency"];
|
|
247
249
|
let c = e;
|
|
248
|
-
e === "before" ? c = "0" : e === "after" && (c = "1"),
|
|
250
|
+
e === "before" ? c = "0" : e === "after" && (c = "1"), i["data-product_price_control_curency"] = c, i["data-product_price_currency_location"] = c;
|
|
249
251
|
}
|
|
250
|
-
(!
|
|
251
|
-
const
|
|
252
|
-
return
|
|
252
|
+
(!i["data-product_price_control_currency_symbol"] || i["data-product_price_control_currency_symbol"].trim() === "") && (i["data-product_price_control_currency_symbol"] = "USD");
|
|
253
|
+
const n = { ...this.getDefaultConfigBlockAttributes(), ...i };
|
|
254
|
+
return n["data-type"] = r, n["data-source"] = r, n["data-product_image_link"] = $(r, l), n["data-product_button_link"] = N(r, l), n;
|
|
253
255
|
}
|
|
254
256
|
/**
|
|
255
257
|
* Returns default esd-config-block attributes based on the old template structure
|
|
@@ -298,6 +300,49 @@ class z {
|
|
|
298
300
|
"data-product_button_link": "{{Abandoned Cart Item (1) Url}}"
|
|
299
301
|
};
|
|
300
302
|
}
|
|
303
|
+
/**
|
|
304
|
+
* Backfills data-type (and data-number) onto v2 `.ins-product-td` elements
|
|
305
|
+
* from their persisted `esd-ext-config` nodeConfig, and strips the legacy
|
|
306
|
+
* static `width` that older builds baked onto the product-td.
|
|
307
|
+
*
|
|
308
|
+
* Why (data-type): templates migrated and saved by an older build can carry the
|
|
309
|
+
* correct product type in `esd-ext-config` while the `.ins-product-td` is missing
|
|
310
|
+
* the `data-type` DOM attribute. Stripo strips `esd-*` attributes during compile,
|
|
311
|
+
* so by save time only `data-type` survives for `pairProductVariables` to read
|
|
312
|
+
* when choosing the merge-tag namespace. Restoring it here (at load, before the
|
|
313
|
+
* editor compiles) makes the namespace resolve to the real source
|
|
314
|
+
* (browsed_item_ / purchased_item_) instead of defaulting to ins_apr_ (Cart).
|
|
315
|
+
*
|
|
316
|
+
* Why (width): the migrate output used to hardcode `width="560"` on the product-td,
|
|
317
|
+
* which made the block overflow narrow (33%/50%) columns and wrap. The generator
|
|
318
|
+
* no longer emits it; here we heal already-saved templates by removing it so the
|
|
319
|
+
* cell inherits its column width. width="560" was only ever written alongside
|
|
320
|
+
* esd-ext-config, so the guard below still catches every affected template.
|
|
321
|
+
*
|
|
322
|
+
* Only re-serializes when something actually changed, so healthy templates
|
|
323
|
+
* (data-type present, no static width) pass through byte-for-byte.
|
|
324
|
+
*/
|
|
325
|
+
backfillV2ProductTdAttributes(t) {
|
|
326
|
+
if (!t.includes("ins-product-td") || !t.includes("esd-ext-config"))
|
|
327
|
+
return t;
|
|
328
|
+
const r = this.parser.parseFromString(t, "text/html");
|
|
329
|
+
let l = !1;
|
|
330
|
+
return r.querySelectorAll(".ins-product-td").forEach((a) => {
|
|
331
|
+
if (a.hasAttribute("width") && (a.removeAttribute("width"), l = !0), a.getAttribute("data-type"))
|
|
332
|
+
return;
|
|
333
|
+
const i = a.getAttribute("esd-ext-config");
|
|
334
|
+
if (i)
|
|
335
|
+
try {
|
|
336
|
+
const n = JSON.parse(i), e = n.type || n.source;
|
|
337
|
+
if (!e)
|
|
338
|
+
return;
|
|
339
|
+
a.setAttribute("data-type", e), l = !0;
|
|
340
|
+
const c = typeof n.itemsSelectValue == "string" ? n.itemsSelectValue.match(/\((\d+)\)/) : null;
|
|
341
|
+
c && a.getAttribute("data-number") !== c[1] && a.setAttribute("data-number", c[1]);
|
|
342
|
+
} catch {
|
|
343
|
+
}
|
|
344
|
+
}), l ? r.documentElement.outerHTML : t;
|
|
345
|
+
}
|
|
301
346
|
/**
|
|
302
347
|
* Fast check for the presence of any items block (cart / browsed / purchased)
|
|
303
348
|
* in the raw HTML. Used to gate the migration pipeline so non-items templates
|
|
@@ -317,15 +362,15 @@ class z {
|
|
|
317
362
|
* contains display condition Jinja scripts that should NOT be removed.
|
|
318
363
|
*/
|
|
319
364
|
removeJinjaConditionals(t) {
|
|
320
|
-
const
|
|
321
|
-
let a = l ? t.replace(l[0],
|
|
365
|
+
const r = "__ESD_DISPLAY_CONDITIONS_PLACEHOLDER__", l = t.match(/esd-custom-display-conditions="[^"]*"/);
|
|
366
|
+
let a = l ? t.replace(l[0], r) : t;
|
|
322
367
|
return a = a.replace(
|
|
323
368
|
/\{%\s*if\s+(ins_apr|browsed_item|purchased_item)_total_product_kind\s*(>|>)\s*\d+\s*%\}/g,
|
|
324
369
|
""
|
|
325
370
|
), a = a.replace(
|
|
326
371
|
/\{%\s*if\s+(ins_apr|browsed_item|purchased_item)_price_\d+\s*(!=|!=)\s*\1_originalprice_\d+\s*%\}/g,
|
|
327
372
|
""
|
|
328
|
-
), a = a.replace(/\{%\s*endif\s*%\}/g, ""), l && (a = a.replace(
|
|
373
|
+
), a = a.replace(/\{%\s*endif\s*%\}/g, ""), l && (a = a.replace(r, l[0])), a = a.replace(/\n\s*\n\s*\n/g, `
|
|
329
374
|
|
|
330
375
|
`), a;
|
|
331
376
|
}
|
|
@@ -339,31 +384,31 @@ class z {
|
|
|
339
384
|
* - {{purchased_item_formattedprice_5}} → '1,490.49' (PURCHASED_ITEMS)
|
|
340
385
|
*/
|
|
341
386
|
replaceTemplateVariables(t) {
|
|
342
|
-
const { PAIRS_FOR_EXTENSION:
|
|
387
|
+
const { PAIRS_FOR_EXTENSION: r } = K;
|
|
343
388
|
return t.replace(/{{([^}]+)}}/g, (l, a) => {
|
|
344
|
-
const
|
|
345
|
-
if (!
|
|
389
|
+
const i = a.match(/^(ins_apr|browsed_item|purchased_item)_([a-z_]+)_(\d+)$/);
|
|
390
|
+
if (!i)
|
|
346
391
|
return l;
|
|
347
|
-
const [,
|
|
348
|
-
if (!_)
|
|
349
|
-
return console.warn(`Unknown variable prefix: ${i}`), l;
|
|
350
|
-
const u = q[e];
|
|
392
|
+
const [, n, e, c] = i, u = V[n];
|
|
351
393
|
if (!u)
|
|
394
|
+
return console.warn(`Unknown variable prefix: ${n}`), l;
|
|
395
|
+
const s = x[e];
|
|
396
|
+
if (!s)
|
|
352
397
|
return console.warn(`Unknown variable suffix mapping for: ${e}`), l;
|
|
353
|
-
const { pairsKey:
|
|
398
|
+
const { pairsKey: _, defaultKey: d, isArray: b } = s, y = r[_][u];
|
|
354
399
|
if (!y)
|
|
355
|
-
return console.warn(`No data found for: ${
|
|
356
|
-
if (
|
|
400
|
+
return console.warn(`No data found for: ${_}.${u}`), l;
|
|
401
|
+
if (b) {
|
|
357
402
|
const f = parseInt(c) - 1, m = y[d];
|
|
358
|
-
return Array.isArray(m) && m[f] ? m[f] : (console.warn(`Array value not found: ${
|
|
403
|
+
return Array.isArray(m) && m[f] ? m[f] : (console.warn(`Array value not found: ${_}.${u}.${d}[${f}]`), l);
|
|
359
404
|
}
|
|
360
|
-
const
|
|
361
|
-
return
|
|
405
|
+
const A = y[d];
|
|
406
|
+
return A !== void 0 ? String(A) : (console.warn(`Default value not found: ${_}.${u}.${d}`), l);
|
|
362
407
|
});
|
|
363
408
|
}
|
|
364
409
|
}
|
|
365
|
-
function Q(
|
|
366
|
-
return new z().migrate(
|
|
410
|
+
function Q(o) {
|
|
411
|
+
return new z().migrate(o);
|
|
367
412
|
}
|
|
368
413
|
export {
|
|
369
414
|
Q as migrateItemsBlock
|
|
@@ -1,52 +1,74 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { MERGE_TAGS as
|
|
5
|
-
import { DATA_ATTRIBUTES as
|
|
6
|
-
import { useUnsubscribeStore as
|
|
7
|
-
class
|
|
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 $ {
|
|
8
8
|
constructor() {
|
|
9
|
-
|
|
9
|
+
A(this, "parser");
|
|
10
10
|
this.parser = new DOMParser();
|
|
11
11
|
}
|
|
12
12
|
async migrate(e) {
|
|
13
13
|
try {
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
pageIds: b,
|
|
24
|
-
paddingClass: g,
|
|
25
|
-
bgColor: u
|
|
26
|
-
});
|
|
27
|
-
const f = this.buildUnsubscribeBlock(
|
|
28
|
-
n,
|
|
29
|
-
s,
|
|
30
|
-
b,
|
|
31
|
-
g,
|
|
32
|
-
u
|
|
33
|
-
), a = this.parser.parseFromString(
|
|
34
|
-
`<table id="tempDoc"><tbody><tr>${f}</tr></tbody></table>`,
|
|
35
|
-
"text/html"
|
|
36
|
-
).querySelector(".unsubscribe-block-v2");
|
|
37
|
-
a && r.parentNode && (a.setAttribute("id", c || ""), r.parentNode.replaceChild(a, r));
|
|
38
|
-
}), t.documentElement.outerHTML;
|
|
39
|
-
} catch (t) {
|
|
40
|
-
return console.error("UnsubscribeMigrator failed:", t), e;
|
|
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);
|
|
18
|
+
}
|
|
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;
|
|
41
23
|
}
|
|
42
24
|
}
|
|
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);
|
|
28
|
+
console.debug("[UnsubscribeMigrator]", {
|
|
29
|
+
mergeTag: a.linkHref,
|
|
30
|
+
collectionType: o,
|
|
31
|
+
pageIds: b,
|
|
32
|
+
paddingClass: s,
|
|
33
|
+
bgColor: l
|
|
34
|
+
});
|
|
35
|
+
const u = this.buildUnsubscribeBlock(
|
|
36
|
+
a,
|
|
37
|
+
o,
|
|
38
|
+
b,
|
|
39
|
+
s,
|
|
40
|
+
l
|
|
41
|
+
), i = this.parser.parseFromString(
|
|
42
|
+
`<table id="tempDoc"><tbody><tr>${u}</tr></tbody></table>`,
|
|
43
|
+
"text/html"
|
|
44
|
+
).querySelector(h);
|
|
45
|
+
i && t.parentNode && (i.setAttribute("id", n || ""), t.parentNode.replaceChild(i, t));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
// Re-derives the typed merge tag from data-unsubscribe-page-type for any v2
|
|
49
|
+
// block whose anchor href is missing or the legacy default. Returns true when
|
|
50
|
+
// at least one href was rewritten. Typed tags and custom URLs are left intact.
|
|
51
|
+
repairUnsubscribeLinks(e) {
|
|
52
|
+
const r = e.querySelectorAll(`${h}[${k.PAGE_TYPE}]`);
|
|
53
|
+
let t = !1;
|
|
54
|
+
return r.forEach((n) => {
|
|
55
|
+
const s = n.querySelector('a[data-unsubscribe-link="true"], a.unsubscribe-link');
|
|
56
|
+
if (!s)
|
|
57
|
+
return;
|
|
58
|
+
const l = s.getAttribute("href") || "";
|
|
59
|
+
if (l && l !== f.default)
|
|
60
|
+
return;
|
|
61
|
+
const a = Number(n.getAttribute(k.PAGE_TYPE)), o = f[a];
|
|
62
|
+
o && (s.setAttribute("href", o), t = !0);
|
|
63
|
+
}), t;
|
|
64
|
+
}
|
|
43
65
|
extractPaddingClass(e) {
|
|
44
|
-
const
|
|
45
|
-
return
|
|
66
|
+
const t = (e.getAttribute("class") || "").match(/\bes-p\d+\b/);
|
|
67
|
+
return t ? t[0] : "";
|
|
46
68
|
}
|
|
47
69
|
extractUnsubscribeContent(e) {
|
|
48
|
-
var
|
|
49
|
-
const t = e.querySelector("p");
|
|
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");
|
|
50
72
|
if (!t)
|
|
51
73
|
return {
|
|
52
74
|
textBefore: "You can ",
|
|
@@ -59,7 +81,7 @@ class C {
|
|
|
59
81
|
align: "center",
|
|
60
82
|
paragraphStyle: ""
|
|
61
83
|
};
|
|
62
|
-
const
|
|
84
|
+
const n = e.getAttribute("align") || t.getAttribute("align") || "center", s = t.getAttribute("style") || "";
|
|
63
85
|
if (!r)
|
|
64
86
|
return {
|
|
65
87
|
textBefore: "You can ",
|
|
@@ -69,55 +91,55 @@ class C {
|
|
|
69
91
|
textAfter: " from our emails, if you need to.",
|
|
70
92
|
isBold: !1,
|
|
71
93
|
isItalic: !1,
|
|
72
|
-
align:
|
|
73
|
-
paragraphStyle:
|
|
94
|
+
align: n,
|
|
95
|
+
paragraphStyle: s
|
|
74
96
|
};
|
|
75
|
-
const
|
|
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");
|
|
76
98
|
return {
|
|
77
|
-
textBefore:
|
|
78
|
-
linkText:
|
|
79
|
-
linkHref: this.normalizeUnsubscribeHref(
|
|
80
|
-
linkStyle:
|
|
81
|
-
textAfter:
|
|
82
|
-
isBold:
|
|
83
|
-
isItalic:
|
|
84
|
-
align:
|
|
85
|
-
paragraphStyle:
|
|
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
|
|
86
108
|
};
|
|
87
109
|
}
|
|
88
|
-
buildUnsubscribeBlock(e,
|
|
89
|
-
const
|
|
90
|
-
e.textBefore &&
|
|
91
|
-
let
|
|
92
|
-
e.isBold && e.isItalic ?
|
|
93
|
-
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";
|
|
94
116
|
return `
|
|
95
117
|
<td
|
|
96
118
|
data-migration="true"
|
|
97
119
|
esd-extension-block-id="unsubscribe-block"
|
|
98
|
-
class="${
|
|
99
|
-
${
|
|
120
|
+
class="${n ? `${S} ${n}` : S}"
|
|
121
|
+
${m}${y}${E}${T}
|
|
100
122
|
>
|
|
101
123
|
<p path="1"${d}>
|
|
102
|
-
${
|
|
124
|
+
${i}
|
|
103
125
|
</p>
|
|
104
126
|
</td>
|
|
105
127
|
`;
|
|
106
128
|
}
|
|
107
129
|
getCollectionTypeFromMergeTag(e) {
|
|
108
|
-
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;
|
|
109
131
|
}
|
|
110
132
|
normalizeUnsubscribeHref(e) {
|
|
111
|
-
if (Object.values(
|
|
133
|
+
if (Object.values(f).includes(e))
|
|
112
134
|
return e;
|
|
113
|
-
const
|
|
114
|
-
return
|
|
135
|
+
const t = e.match(/{{ins-(?:global-)?(?:preferences-)?unsubscribe-link}}/);
|
|
136
|
+
return t ? t[0] : e.includes("unsubscribe") || e.includes("unsub") ? (console.warn(
|
|
115
137
|
`[UnsubscribeMigrator] Unrecognized unsubscribe href format: "${e}". Defaulting to {{ins-unsubscribe-link}}`
|
|
116
138
|
), "{{ins-unsubscribe-link}}") : e;
|
|
117
139
|
}
|
|
118
140
|
}
|
|
119
|
-
async function M(
|
|
120
|
-
return new
|
|
141
|
+
async function M(c) {
|
|
142
|
+
return new $().migrate(c);
|
|
121
143
|
}
|
|
122
144
|
export {
|
|
123
145
|
M as migrateUnsubscribe
|