@useinsider/guido 3.17.0-beta.bc6e089 → 3.17.0-beta.c93afa9
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/useModuleRepair.js +33 -0
- package/dist/composables/useStripo.js +1 -1
- package/dist/config/migrator/itemsBlockMigrator.js +156 -204
- package/dist/extensions/Blocks/Items/block.js +118 -49
- package/dist/extensions/Blocks/Items/constants/currency.js +25 -0
- package/dist/extensions/Blocks/Items/controls/name/trimming.js +17 -18
- package/dist/extensions/Blocks/Items/controls/price/currencyLocation.js +25 -24
- package/dist/extensions/Blocks/Items/controls/price/currencySymbol.js +12 -11
- package/dist/extensions/Blocks/Items/controls/settingsControl.js +55 -58
- package/dist/extensions/Blocks/Items/enums/productEnums.js +9 -14
- package/dist/extensions/Blocks/Items/layouts/horizontal.html.js +9 -11
- package/dist/extensions/Blocks/Items/template.js +236 -243
- package/dist/src/composables/useModuleRepair.d.ts +18 -0
- package/dist/src/extensions/Blocks/Items/block.d.ts +35 -0
- package/dist/src/extensions/Blocks/Items/constants/currency.d.ts +43 -0
- package/dist/src/extensions/Blocks/Items/enums/productEnums.d.ts +0 -3
- package/dist/src/utils/itemsCurrencyRepair.d.ts +17 -0
- package/dist/utils/itemsCurrencyRepair.js +39 -0
- package/dist/utils/pairProductVariables.js +66 -66
- package/package.json +1 -1
- package/dist/composables/useModuleDynamicContentRepair.js +0 -37
- package/dist/extensions/Blocks/Items/constants/cardLayout.js +0 -20
- package/dist/src/composables/useModuleDynamicContentRepair.d.ts +0 -13
- package/dist/src/extensions/Blocks/Items/constants/cardLayout.d.ts +0 -44
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useConfig as C } from "./useConfig.js";
|
|
2
|
+
import { useToaster as T } from "./useToaster.js";
|
|
3
|
+
import { useTranslations as g } from "./useTranslations.js";
|
|
4
|
+
import { ToasterTypeOptions as D } from "../enums/toaster.js";
|
|
5
|
+
import { buildDynamicContentLookup as f, convertModuleDynamicContent as h } from "../utils/dynamicContentConverter.js";
|
|
6
|
+
import { flattenDynamicContentList as O } from "../utils/genericUtil.js";
|
|
7
|
+
import { repairItemsCurrencyAttributes as M } from "../utils/itemsCurrencyRepair.js";
|
|
8
|
+
const N = "dynamic-content.unresolved-attributes-on-drop", R = () => {
|
|
9
|
+
const { template: p, isFeatureEnabled: m } = C(), { showToaster: a } = T(), y = g();
|
|
10
|
+
return { handleModuleAdd: (e, o) => {
|
|
11
|
+
var s, l, u;
|
|
12
|
+
try {
|
|
13
|
+
if ((e == null ? void 0 : e.action) !== "ADD" && (e == null ? void 0 : e.action) !== "COPY")
|
|
14
|
+
return;
|
|
15
|
+
const t = (s = o == null ? void 0 : o.getTargetNode) == null ? void 0 : s.call(o), r = (l = t == null ? void 0 : t.getOuterHTML) == null ? void 0 : l.call(t);
|
|
16
|
+
if (!t || typeof r != "string")
|
|
17
|
+
return;
|
|
18
|
+
let n = M(r);
|
|
19
|
+
const c = f(O((u = p.value) == null ? void 0 : u.dynamicContentList));
|
|
20
|
+
let i = [];
|
|
21
|
+
c.size > 0 && ({ html: n, unresolved: i } = h(n, c, m("liquidSyntax"))), n !== r && o.modifyHtml(t).replaceWith(n), i.length > 0 && a({
|
|
22
|
+
type: D.Warning,
|
|
23
|
+
message: y(N)
|
|
24
|
+
});
|
|
25
|
+
} catch (t) {
|
|
26
|
+
console.error("Failed to repair module on add:", t);
|
|
27
|
+
}
|
|
28
|
+
} };
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
N as UNRESOLVED_DYNAMIC_CONTENT_ON_DROP_KEY,
|
|
32
|
+
R as useModuleRepair
|
|
33
|
+
};
|
|
@@ -3,7 +3,7 @@ import { useBlocksConfig as O } from "./useBlocksConfig.js";
|
|
|
3
3
|
import { useConfig as q } from "./useConfig.js";
|
|
4
4
|
import { useCustomInterfaceAppearance as H } from "./useCustomInterfaceAppearance.js";
|
|
5
5
|
import { useFullStoryBridge as N } from "./useFullStoryBridge.js";
|
|
6
|
-
import {
|
|
6
|
+
import { useModuleRepair as j } from "./useModuleRepair.js";
|
|
7
7
|
import { useStripoEventHandler as z } from "./useStripoEventHandler.js";
|
|
8
8
|
import { useStripoNotifications as $ } from "./useStripoNotifications.js";
|
|
9
9
|
import { useToaster as G } from "./useToaster.js";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
2
|
-
var U = (
|
|
3
|
-
var
|
|
4
|
-
import { BLOCK_ID as
|
|
5
|
-
import { productPairs as
|
|
6
|
-
import { ItemInCartOptions as I, DefaultConfigValues as
|
|
7
|
-
import { getDefaultTemplate as
|
|
8
|
-
import { useTemplateStore as
|
|
9
|
-
const
|
|
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
|
+
import { productPairs as K } from "../../extensions/Blocks/Items/enums/productEnums.js";
|
|
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",
|
|
@@ -73,126 +73,126 @@ const V = {
|
|
|
73
73
|
isArray: !1
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
-
function
|
|
76
|
+
function O() {
|
|
77
77
|
return String(Date.now() + Math.floor(Math.random() * 1e3));
|
|
78
78
|
}
|
|
79
|
-
function
|
|
80
|
-
return
|
|
79
|
+
function k(o) {
|
|
80
|
+
return o ? {
|
|
81
81
|
CartItems: p.ITEMS_TYPE.CART_ITEMS,
|
|
82
82
|
BrowsedItems: p.ITEMS_TYPE.BROWSED_ITEMS,
|
|
83
83
|
PurchasedItems: p.ITEMS_TYPE.PURCHASED_ITEMS,
|
|
84
84
|
CART_ITEMS: p.ITEMS_TYPE.CART_ITEMS,
|
|
85
85
|
BROWSED_ITEMS: p.ITEMS_TYPE.BROWSED_ITEMS,
|
|
86
86
|
PURCHASED_ITEMS: p.ITEMS_TYPE.PURCHASED_ITEMS
|
|
87
|
-
}[
|
|
87
|
+
}[o] || p.ITEMS_TYPE.CART_ITEMS : p.ITEMS_TYPE.CART_ITEMS;
|
|
88
88
|
}
|
|
89
|
-
function
|
|
90
|
-
var
|
|
91
|
-
const t = (l, u) => l == null ? u : l === "1" || l === "true",
|
|
92
|
-
let
|
|
93
|
-
if (
|
|
94
|
-
const l = parseInt(
|
|
95
|
-
u && u[l] && (
|
|
89
|
+
function h(o) {
|
|
90
|
+
var e;
|
|
91
|
+
const t = (l, u) => l == null ? u : l === "1" || l === "true", r = (l, u) => l || u, c = o["data-type"] || o["data-source"], a = k(c), 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 l = parseInt(n) - 1, u = I[a];
|
|
95
|
+
u && u[l] && (n = u[l].value);
|
|
96
96
|
}
|
|
97
97
|
return {
|
|
98
98
|
initialized: !0,
|
|
99
|
-
blockInstanceId:
|
|
100
|
-
source:
|
|
101
|
-
type:
|
|
102
|
-
itemsSelectValue:
|
|
103
|
-
orientation:
|
|
104
|
-
nameTrimming: t(
|
|
105
|
-
priceHideDiscount: t(
|
|
106
|
-
priceFormatted: t(
|
|
107
|
-
priceSinglePrice: t(
|
|
108
|
-
priceCurrencySymbol:
|
|
109
|
-
|
|
110
|
-
|
|
99
|
+
blockInstanceId: r(o["data-block-instance-id"], O()),
|
|
100
|
+
source: a,
|
|
101
|
+
type: a,
|
|
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
|
+
g.productPriceCurrencySymbolControlValue
|
|
111
111
|
),
|
|
112
|
-
priceCurrencyLocation:
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
priceCurrencyLocation: r(
|
|
113
|
+
o["data-product_price_currency_location"],
|
|
114
|
+
g.productPriceCurrencyLocationControlValue
|
|
115
115
|
),
|
|
116
|
-
priceOrientation:
|
|
117
|
-
quantityControlEnabled: t(
|
|
118
|
-
buttonLink:
|
|
119
|
-
imageLink:
|
|
120
|
-
buttonLabel:
|
|
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
|
|
141
|
+
return r[o] || r.CART_ITEMS;
|
|
142
142
|
}
|
|
143
|
-
function
|
|
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
|
|
149
|
+
return r[o] || r.CART_ITEMS;
|
|
150
150
|
}
|
|
151
|
-
class
|
|
151
|
+
class H {
|
|
152
152
|
constructor() {
|
|
153
|
-
|
|
153
|
+
M(this, "parser");
|
|
154
154
|
this.parser = new DOMParser();
|
|
155
155
|
}
|
|
156
156
|
migrate(t) {
|
|
157
157
|
try {
|
|
158
158
|
if (!this.containsItemsBlock(t))
|
|
159
159
|
return this.backfillV2ProductTdAttributes(t);
|
|
160
|
-
let
|
|
161
|
-
|
|
162
|
-
const c = this.parser.parseFromString(
|
|
160
|
+
let r = this.removeJinjaConditionals(t);
|
|
161
|
+
r = this.replaceTemplateVariables(r);
|
|
162
|
+
const c = this.parser.parseFromString(r, "text/html"), a = c.querySelectorAll(
|
|
163
163
|
"td.esd-cart-items-block, td.esd-browsed-items-block, td.esd-purchased-items-block"
|
|
164
164
|
);
|
|
165
|
-
return
|
|
166
|
-
|
|
167
|
-
}),
|
|
168
|
-
const
|
|
169
|
-
orientation:
|
|
170
|
-
itemsType:
|
|
171
|
-
itemId:
|
|
172
|
-
currencySymbol:
|
|
173
|
-
currencyLocation:
|
|
174
|
-
formattedPrice:
|
|
175
|
-
configBlockAttributes:
|
|
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), l = F({
|
|
169
|
+
orientation: e.orientation,
|
|
170
|
+
itemsType: e.itemsType,
|
|
171
|
+
itemId: e.itemId,
|
|
172
|
+
currencySymbol: e.currencySymbol,
|
|
173
|
+
currencyLocation: e.currencyLocation,
|
|
174
|
+
formattedPrice: e.formattedPrice,
|
|
175
|
+
configBlockAttributes: e.configBlockAttributes,
|
|
176
176
|
migrate: !0,
|
|
177
|
-
nameStyles:
|
|
178
|
-
buttonStyles:
|
|
179
|
-
priceStyles:
|
|
180
|
-
originalPriceStyles:
|
|
181
|
-
quantityStyles:
|
|
182
|
-
nodeConfig:
|
|
177
|
+
nameStyles: e.nameStyles,
|
|
178
|
+
buttonStyles: e.buttonStyles,
|
|
179
|
+
priceStyles: e.priceStyles,
|
|
180
|
+
originalPriceStyles: e.originalPriceStyles,
|
|
181
|
+
quantityStyles: e.quantityStyles,
|
|
182
|
+
nodeConfig: h(e.configBlockAttributes)
|
|
183
183
|
}), s = this.parser.parseFromString(
|
|
184
184
|
`<table><tbody><tr>${l}</tr></tbody></table>`,
|
|
185
185
|
"text/html"
|
|
186
186
|
).querySelector("td");
|
|
187
|
-
if (s &&
|
|
188
|
-
const _ =
|
|
187
|
+
if (s && n.parentNode) {
|
|
188
|
+
const _ = h(e.configBlockAttributes);
|
|
189
189
|
s.setAttribute("esd-ext-config", JSON.stringify(_)), s.setAttribute("data-type", _.type);
|
|
190
190
|
const d = s.querySelector("esd-config-block");
|
|
191
|
-
d && d.remove(),
|
|
191
|
+
d && d.remove(), n.parentNode.replaceChild(s, n);
|
|
192
192
|
}
|
|
193
193
|
}), c.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
|
/**
|
|
@@ -202,76 +202,28 @@ class W {
|
|
|
202
202
|
* - UI styles from product elements (name, price, button, quantity, etc.)
|
|
203
203
|
*/
|
|
204
204
|
extractConfiguration(t) {
|
|
205
|
-
var D, P
|
|
206
|
-
const
|
|
207
|
-
((
|
|
208
|
-
), c = ((
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
_ && (d = _ === "after" ? "1" : "0");
|
|
213
|
-
const A = (u == null ? void 0 : u.getAttribute("data-formated")) ?? r["data-product_price_control_formated"], h = A !== "false" && A !== "0", m = r["data-card_orientation_control_value"];
|
|
214
|
-
let g;
|
|
215
|
-
m ? g = m === "horizontal" ? "horizontal" : "vertical" : g = t.querySelector('[colspan="2"]') !== null ? "vertical" : "horizontal";
|
|
216
|
-
const f = t.querySelector('a[product-attr="name"]'), b = (f == null ? void 0 : f.getAttribute("style")) || void 0, E = t.querySelector('a[product-attr="button"]'), w = (E == null ? void 0 : E.getAttribute("style")) || void 0, v = (l == null ? void 0 : l.getAttribute("style")) || void 0, y = t.querySelector("p.original-price") ?? t.querySelector('[product-attr="originalPrice"]'), T = y != null && y.getAttribute("style") ? y : (y == null ? void 0 : y.closest("p")) ?? y, B = (T == null ? void 0 : T.getAttribute("style")) || void 0, C = t.querySelector('[product-attr="quantity"]'), q = (C == null ? void 0 : C.getAttribute("style")) || void 0;
|
|
205
|
+
var C, D, P;
|
|
206
|
+
const r = k(
|
|
207
|
+
((C = t.querySelector("[data-type]")) == null ? void 0 : C.getAttribute("data-type")) ?? null
|
|
208
|
+
), c = ((D = t.querySelector("[data-number]")) == null ? void 0 : D.getAttribute("data-number")) || "1", a = parseInt(c) - 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"]'), l = (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, c), 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, E = t.querySelector("p.original-price"), L = (E == null ? void 0 : E.getAttribute("style")) || void 0, T = t.querySelector('[product-attr="quantity"]'), B = (T == null ? void 0 : T.getAttribute("style")) || void 0;
|
|
217
212
|
return {
|
|
218
|
-
orientation:
|
|
219
|
-
itemsType:
|
|
220
|
-
itemId:
|
|
221
|
-
currencySymbol:
|
|
222
|
-
currencyLocation:
|
|
223
|
-
formattedPrice:
|
|
224
|
-
configBlockAttributes:
|
|
225
|
-
nameStyles:
|
|
226
|
-
buttonStyles:
|
|
227
|
-
priceStyles:
|
|
228
|
-
originalPriceStyles:
|
|
229
|
-
quantityStyles:
|
|
213
|
+
orientation: S,
|
|
214
|
+
itemsType: r,
|
|
215
|
+
itemId: n,
|
|
216
|
+
currencySymbol: l,
|
|
217
|
+
currencyLocation: s,
|
|
218
|
+
formattedPrice: _,
|
|
219
|
+
configBlockAttributes: d,
|
|
220
|
+
nameStyles: A,
|
|
221
|
+
buttonStyles: m,
|
|
222
|
+
priceStyles: R,
|
|
223
|
+
originalPriceStyles: L,
|
|
224
|
+
quantityStyles: B
|
|
230
225
|
};
|
|
231
226
|
}
|
|
232
|
-
/**
|
|
233
|
-
* DOM fallback for hand-edited templates whose esd-config-block was deleted. With no
|
|
234
|
-
* toggle record left, derive each field's enabled state from whether its product-attr
|
|
235
|
-
* element still exists and read the button label from the live caption — a deleted
|
|
236
|
-
* element means the field is off, not an all-ON default. A present config block stays
|
|
237
|
-
* authoritative (a missing flag there still means "default on"), so we no-op for it.
|
|
238
|
-
*/
|
|
239
|
-
applyDomFallbacks(t, e) {
|
|
240
|
-
var u;
|
|
241
|
-
const c = t.querySelector("esd-config-block");
|
|
242
|
-
if (Object.entries({
|
|
243
|
-
image: '[product-attr="imageSrc"]',
|
|
244
|
-
name: '[product-attr="name"]',
|
|
245
|
-
price: '[product-attr="price"]',
|
|
246
|
-
original_price: '[product-attr="originalPrice"], p.original-price',
|
|
247
|
-
quantity: '[product-attr="quantity"]',
|
|
248
|
-
button: '[product-attr="button"]'
|
|
249
|
-
}).forEach(([s, _]) => {
|
|
250
|
-
const d = `data-product_${s}_control_enabled`;
|
|
251
|
-
(!c || !c.hasAttribute(d)) && (e[d] = t.querySelector(_) ? "true" : "false");
|
|
252
|
-
}), c)
|
|
253
|
-
return;
|
|
254
|
-
e["data-card_orientation_control_value"] = t.querySelector('[colspan="2"]') ? "vertical" : "horizontal";
|
|
255
|
-
const n = t.querySelector('a[product-attr="button"]'), i = (u = n == null ? void 0 : n.textContent) == null ? void 0 : u.replace(/\s+/g, " ").trim();
|
|
256
|
-
i && (e["data-product_button_control_label"] = i), /display:\s*inline/.test((n == null ? void 0 : n.getAttribute("style")) || "") && (e["data-product_button_control_atw"] = "false");
|
|
257
|
-
const r = t.querySelector('[product-attr="imageSrc"]'), l = r ? this.readImageDimension(r) : null;
|
|
258
|
-
l && (e["data-product_image_control_image-height"] = l, e["data-product_image_control_image-width"] = l);
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Reads a pixel dimension for the product image from its DOM element — the legacy
|
|
262
|
-
* `width` attribute first, then a px value in the inline style. An explicit `width` wins
|
|
263
|
-
* over `max-width`, which is only an upper bound; `max-width` still covers the common
|
|
264
|
-
* `width: 100%` case, where no pixel size can be read from `width` itself.
|
|
265
|
-
* Returns null when no pixel size is present.
|
|
266
|
-
*/
|
|
267
|
-
readImageDimension(t) {
|
|
268
|
-
var n;
|
|
269
|
-
const e = (n = t.getAttribute("width")) == null ? void 0 : n.trim();
|
|
270
|
-
if (e && /^\d+$/.test(e))
|
|
271
|
-
return e;
|
|
272
|
-
const c = t.getAttribute("style") || "", o = c.match(/(?:^|;)\s*width:\s*(\d+)px/) || c.match(/max-width:\s*(\d+)px/);
|
|
273
|
-
return o ? o[1] : null;
|
|
274
|
-
}
|
|
275
227
|
/**
|
|
276
228
|
* Extracts all data-* attributes from the esd-config-block element
|
|
277
229
|
* Returns a key-value mapping of all configuration attributes
|
|
@@ -279,27 +231,27 @@ class W {
|
|
|
279
231
|
* @param itemsType - The type of items (CART_ITEMS, BROWSED_ITEMS, PURCHASED_ITEMS)
|
|
280
232
|
* @param itemNumber - The item number (1-based index)
|
|
281
233
|
*/
|
|
282
|
-
extractConfigBlockAttributes(t,
|
|
283
|
-
const
|
|
284
|
-
if (
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
234
|
+
extractConfigBlockAttributes(t, r, c) {
|
|
235
|
+
const a = t.querySelector("esd-config-block"), i = {};
|
|
236
|
+
if (!a)
|
|
237
|
+
return this.getDefaultConfigBlockAttributes();
|
|
238
|
+
if (Array.from(a.attributes).forEach((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"];
|
|
242
|
+
if (/^\d+$/.test(e)) {
|
|
243
|
+
const l = parseInt(e) - 1, u = I[r];
|
|
244
|
+
u && u[l] && (i["data-cart_items_select_control_value"] = u[l].value);
|
|
293
245
|
}
|
|
294
|
-
if (n["data-product_price_control_curency"]) {
|
|
295
|
-
const r = n["data-product_price_control_curency"];
|
|
296
|
-
let l = r;
|
|
297
|
-
r === "before" ? l = "0" : r === "after" && (l = "1"), n["data-product_price_control_curency"] = l, n["data-product_price_currency_location"] = l;
|
|
298
|
-
}
|
|
299
|
-
(!n["data-product_price_control_currency_symbol"] || n["data-product_price_control_currency_symbol"].trim() === "") && (n["data-product_price_control_currency_symbol"] = "USD");
|
|
300
246
|
}
|
|
301
|
-
|
|
302
|
-
|
|
247
|
+
if (i["data-product_price_control_curency"]) {
|
|
248
|
+
const e = i["data-product_price_control_curency"];
|
|
249
|
+
let l = e;
|
|
250
|
+
e === "before" ? l = "0" : e === "after" && (l = "1"), i["data-product_price_control_curency"] = l, i["data-product_price_currency_location"] = l;
|
|
251
|
+
}
|
|
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, c), n["data-product_button_link"] = N(r, c), n;
|
|
303
255
|
}
|
|
304
256
|
/**
|
|
305
257
|
* Returns default esd-config-block attributes based on the old template structure
|
|
@@ -373,25 +325,25 @@ class W {
|
|
|
373
325
|
backfillV2ProductTdAttributes(t) {
|
|
374
326
|
if (!t.includes("ins-product-td") || !t.includes("esd-ext-config"))
|
|
375
327
|
return t;
|
|
376
|
-
const
|
|
328
|
+
const r = this.parser.parseFromString(t, "text/html");
|
|
377
329
|
let c = !1;
|
|
378
|
-
return
|
|
379
|
-
|
|
380
|
-
const
|
|
381
|
-
let
|
|
330
|
+
return r.querySelectorAll(".ins-product-td").forEach((a) => {
|
|
331
|
+
a.hasAttribute("width") && (a.removeAttribute("width"), c = !0);
|
|
332
|
+
const i = a.getAttribute("esd-ext-config");
|
|
333
|
+
let n = null;
|
|
382
334
|
try {
|
|
383
|
-
|
|
335
|
+
n = i ? JSON.parse(i) : null;
|
|
384
336
|
} catch {
|
|
385
337
|
}
|
|
386
|
-
if (!
|
|
338
|
+
if (!n || (!a.getAttribute("data-nodup") && typeof n.priceHideDiscount == "boolean" && (a.setAttribute("data-nodup", String(n.priceHideDiscount)), c = !0), a.getAttribute("data-type")))
|
|
387
339
|
return;
|
|
388
|
-
const
|
|
389
|
-
if (!
|
|
340
|
+
const e = n.type || n.source;
|
|
341
|
+
if (!e)
|
|
390
342
|
return;
|
|
391
|
-
|
|
392
|
-
const l = typeof
|
|
393
|
-
l &&
|
|
394
|
-
}), c ?
|
|
343
|
+
a.setAttribute("data-type", e), c = !0;
|
|
344
|
+
const l = typeof n.itemsSelectValue == "string" ? n.itemsSelectValue.match(/\((\d+)\)/) : null;
|
|
345
|
+
l && a.getAttribute("data-number") !== l[1] && a.setAttribute("data-number", l[1]);
|
|
346
|
+
}), c ? r.documentElement.outerHTML : t;
|
|
395
347
|
}
|
|
396
348
|
/**
|
|
397
349
|
* Fast check for the presence of any items block (cart / browsed / purchased)
|
|
@@ -412,17 +364,17 @@ class W {
|
|
|
412
364
|
* contains display condition Jinja scripts that should NOT be removed.
|
|
413
365
|
*/
|
|
414
366
|
removeJinjaConditionals(t) {
|
|
415
|
-
const
|
|
416
|
-
let
|
|
417
|
-
return
|
|
367
|
+
const r = "__ESD_DISPLAY_CONDITIONS_PLACEHOLDER__", c = t.match(/esd-custom-display-conditions="[^"]*"/);
|
|
368
|
+
let a = c ? t.replace(c[0], r) : t;
|
|
369
|
+
return a = a.replace(
|
|
418
370
|
/\{%\s*if\s+(ins_apr|browsed_item|purchased_item)_total_product_kind\s*(>|>)\s*\d+\s*%\}/g,
|
|
419
371
|
""
|
|
420
|
-
),
|
|
372
|
+
), a = a.replace(
|
|
421
373
|
/\{%\s*if\s+(ins_apr|browsed_item|purchased_item)_price_\d+\s*(!=|!=)\s*\1_originalprice_\d+\s*%\}/g,
|
|
422
374
|
""
|
|
423
|
-
),
|
|
375
|
+
), a = a.replace(/\{%\s*endif\s*%\}/g, ""), c && (a = a.replace(r, c[0])), a = a.replace(/\n\s*\n\s*\n/g, `
|
|
424
376
|
|
|
425
|
-
`),
|
|
377
|
+
`), a;
|
|
426
378
|
}
|
|
427
379
|
/**
|
|
428
380
|
* Replaces template variables with default values from productPairs
|
|
@@ -434,32 +386,32 @@ class W {
|
|
|
434
386
|
* - {{purchased_item_formattedprice_5}} → '1,490.49' (PURCHASED_ITEMS)
|
|
435
387
|
*/
|
|
436
388
|
replaceTemplateVariables(t) {
|
|
437
|
-
const { PAIRS_FOR_EXTENSION:
|
|
438
|
-
return t.replace(/{{([^}]+)}}/g, (c,
|
|
439
|
-
const
|
|
440
|
-
if (!
|
|
389
|
+
const { PAIRS_FOR_EXTENSION: r } = K;
|
|
390
|
+
return t.replace(/{{([^}]+)}}/g, (c, a) => {
|
|
391
|
+
const i = a.match(/^(ins_apr|browsed_item|purchased_item)_([a-z_]+)_(\d+)$/);
|
|
392
|
+
if (!i)
|
|
441
393
|
return c;
|
|
442
|
-
const [,
|
|
394
|
+
const [, n, e, l] = i, u = V[n];
|
|
443
395
|
if (!u)
|
|
444
|
-
return console.warn(`Unknown variable prefix: ${
|
|
445
|
-
const s =
|
|
396
|
+
return console.warn(`Unknown variable prefix: ${n}`), c;
|
|
397
|
+
const s = x[e];
|
|
446
398
|
if (!s)
|
|
447
|
-
return console.warn(`Unknown variable suffix mapping for: ${
|
|
448
|
-
const { pairsKey: _, defaultKey: d, isArray:
|
|
449
|
-
if (!
|
|
399
|
+
return console.warn(`Unknown variable suffix mapping for: ${e}`), c;
|
|
400
|
+
const { pairsKey: _, defaultKey: d, isArray: b } = s, y = r[_][u];
|
|
401
|
+
if (!y)
|
|
450
402
|
return console.warn(`No data found for: ${_}.${u}`), c;
|
|
451
|
-
if (
|
|
452
|
-
const f = parseInt(l) - 1,
|
|
453
|
-
return Array.isArray(
|
|
403
|
+
if (b) {
|
|
404
|
+
const f = parseInt(l) - 1, m = y[d];
|
|
405
|
+
return Array.isArray(m) && m[f] ? m[f] : (console.warn(`Array value not found: ${_}.${u}.${d}[${f}]`), c);
|
|
454
406
|
}
|
|
455
|
-
const
|
|
456
|
-
return
|
|
407
|
+
const A = y[d];
|
|
408
|
+
return A !== void 0 ? String(A) : (console.warn(`Default value not found: ${_}.${u}.${d}`), c);
|
|
457
409
|
});
|
|
458
410
|
}
|
|
459
411
|
}
|
|
460
|
-
function
|
|
461
|
-
return new
|
|
412
|
+
function Q(o) {
|
|
413
|
+
return new H().migrate(o);
|
|
462
414
|
}
|
|
463
415
|
export {
|
|
464
|
-
|
|
416
|
+
Q as migrateItemsBlock
|
|
465
417
|
};
|