@useinsider/guido 3.14.0-beta.38ef0be → 3.14.0-beta.5d003b0
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/useHtmlValidator.js +106 -111
- package/dist/config/compiler/itemsCompilerRules.js +4 -25
- package/dist/config/migrator/index.js +8 -9
- package/dist/config/migrator/itemsBlockMigrator.js +45 -47
- package/dist/extensions/Blocks/Items/block.js +30 -30
- package/dist/extensions/Blocks/Items/controls/name/trimming.js +16 -16
- package/dist/extensions/Blocks/Items/controls/price/hideDiscount.js +22 -26
- package/dist/extensions/Blocks/Items/controls/settingsControl.js +35 -36
- package/dist/extensions/Blocks/Items/template.js +263 -228
- package/dist/src/extensions/Blocks/Items/block.d.ts +1 -1
- package/dist/utils/pairProductVariables.js +72 -75
- package/package.json +1 -1
- package/dist/config/compiler/utils/itemsCompilerUtils.js +0 -28
- package/dist/config/migrator/productNameLinkMigrator.js +0 -27
- package/dist/extensions/Blocks/Items/utils/nameNode.js +0 -4
- package/dist/src/config/compiler/utils/itemsCompilerUtils.d.ts +0 -12
- package/dist/src/config/migrator/productNameLinkMigrator.d.ts +0 -1
- package/dist/src/extensions/Blocks/Items/utils/nameNode.d.ts +0 -9
- package/dist/src/utils/unwrapProductNameLink.d.ts +0 -15
- package/dist/utils/unwrapProductNameLink.js +0 -37
|
@@ -1,69 +1,64 @@
|
|
|
1
|
-
import { useConfig as
|
|
2
|
-
import { getIgnoredRecommendationBlockIds as
|
|
3
|
-
import { TemplateTypes as
|
|
4
|
-
import { DISPLAY_CONDITIONS_REGEX as
|
|
1
|
+
import { useConfig as W } from "./useConfig.js";
|
|
2
|
+
import { getIgnoredRecommendationBlockIds as G } from "../config/compiler/utils/recommendationIgnoreUtils.js";
|
|
3
|
+
import { TemplateTypes as H } from "../enums/defaults.js";
|
|
4
|
+
import { DISPLAY_CONDITIONS_REGEX as P, DISPLAY_CONDITIONS_EXCEPTIONS_REGEX as X, CampaignCouldNotBeSavedKey as $, CanNotMakeAnyChangesForRunningKey as Y, DATA_ATTRIBUTE_REGEX as U, DYNAMIC_CONTENT_TAG_REGEX as j, ALLOWED_DYNAMIC_SYSTEM_TOKENS as q, VALID_DYNAMIC_VARIABLE_REGEX as K } from "../enums/html-validator.js";
|
|
5
5
|
import { ToasterTypeOptions as c } from "../enums/toaster.js";
|
|
6
|
-
import { itemsBlockDynamicVariables as
|
|
7
|
-
import { RECOMMENDATION_VARIABLE_BUILTIN_ATTRIBUTES as
|
|
8
|
-
import { useRecommendationExtensionStore as
|
|
9
|
-
import { resolveProductAttrValue as
|
|
10
|
-
import { RecommendationRequiredFieldsKey as
|
|
11
|
-
import { useRecommendationStore as
|
|
12
|
-
import { base64EncodeWithSpecialChars as
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return [...n.matchAll(oe)].map((m) => m[1]);
|
|
6
|
+
import { itemsBlockDynamicVariables as z } from "../extensions/Blocks/Items/enums/productEnums.js";
|
|
7
|
+
import { RECOMMENDATION_VARIABLE_BUILTIN_ATTRIBUTES as Z } from "../extensions/Blocks/Recommendation/constants/selectors.js";
|
|
8
|
+
import { useRecommendationExtensionStore as J } from "../extensions/Blocks/Recommendation/store/recommendation.js";
|
|
9
|
+
import { resolveProductAttrValue as Q } from "../extensions/Blocks/Recommendation/templates/utils.js";
|
|
10
|
+
import { RecommendationRequiredFieldsKey as ee } from "../extensions/Blocks/Recommendation/validation/requiredFields.js";
|
|
11
|
+
import { useRecommendationStore as te } from "../stores/recommendation.js";
|
|
12
|
+
import { base64EncodeWithSpecialChars as ne } from "../utils/base64.js";
|
|
13
|
+
import { useHttp as se } from "./useHttp.js";
|
|
14
|
+
import { useToaster as re } from "./useToaster.js";
|
|
15
|
+
import { useTranslations as oe } from "./useTranslations.js";
|
|
16
|
+
const ie = /recommendation-id="(\d+)"/g;
|
|
17
|
+
function ae(t) {
|
|
18
|
+
return [...t.matchAll(ie)].map((m) => m[1]);
|
|
20
19
|
}
|
|
21
|
-
function
|
|
22
|
-
return m.some((f) =>
|
|
20
|
+
function ce(t, m) {
|
|
21
|
+
return m.some((f) => t.startsWith(`${f}_`));
|
|
23
22
|
}
|
|
24
|
-
const
|
|
25
|
-
function
|
|
26
|
-
const m =
|
|
23
|
+
const le = /^(\d+)_\d+_(.+)$/;
|
|
24
|
+
function me(t) {
|
|
25
|
+
const m = t.match(le);
|
|
27
26
|
return m ? { recoId: m[1], attribute: m[2] } : null;
|
|
28
27
|
}
|
|
29
|
-
function
|
|
30
|
-
const m = new Set(
|
|
31
|
-
return Object.values(
|
|
32
|
-
m.add(
|
|
28
|
+
function ue(t) {
|
|
29
|
+
const m = new Set(Z);
|
|
30
|
+
return Object.values(t).forEach((f) => {
|
|
31
|
+
m.add(Q(f.attributeName, t).toLowerCase());
|
|
33
32
|
}), m;
|
|
34
33
|
}
|
|
35
|
-
function
|
|
36
|
-
const u =
|
|
34
|
+
function de(t, m, f, o, d) {
|
|
35
|
+
const u = t.match(/{{([a-zA-Z0-9_.\s]*)}}/gm);
|
|
37
36
|
if (!u)
|
|
38
37
|
return [];
|
|
39
|
-
const
|
|
38
|
+
const p = new Set(m.map((h) => h.toLowerCase())), E = [];
|
|
40
39
|
return u.forEach((h) => {
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
40
|
+
const g = h.slice(2, -2).trim().toLowerCase();
|
|
41
|
+
if (g !== "" && p.has(g))
|
|
43
42
|
return;
|
|
44
|
-
const y =
|
|
43
|
+
const y = me(g);
|
|
45
44
|
if (y && o.has(y.recoId)) {
|
|
46
45
|
if (!d || d.has(y.attribute))
|
|
47
46
|
return;
|
|
48
|
-
E.push(
|
|
47
|
+
E.push(g);
|
|
49
48
|
return;
|
|
50
49
|
}
|
|
51
|
-
|
|
50
|
+
ce(g, f) || g.includes(".") || E.push(g);
|
|
52
51
|
}), E;
|
|
53
52
|
}
|
|
54
|
-
function
|
|
55
|
-
return (
|
|
56
|
-
const d = o.slice(2, -2), u = d.indexOf("|"),
|
|
57
|
-
return
|
|
53
|
+
function fe(t) {
|
|
54
|
+
return (t.replace(U, "$1").match(j) ?? []).filter((o) => {
|
|
55
|
+
const d = o.slice(2, -2), u = d.indexOf("|"), p = (u === -1 ? d : d.slice(0, u)).trim();
|
|
56
|
+
return q.includes(p) ? !1 : K.test(p) ? u !== -1 && d.slice(u + 1).trim() === "" : !0;
|
|
58
57
|
});
|
|
59
58
|
}
|
|
60
59
|
const xe = () => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var e, t;
|
|
64
|
-
return ((t = (e = f.value) == null ? void 0 : e.partner) == null ? void 0 : t.messageType) === W.transactional;
|
|
65
|
-
}
|
|
66
|
-
), E = async (e) => {
|
|
60
|
+
var b, S;
|
|
61
|
+
const { showToaster: t } = re(), { post: m } = se(), { config: f } = W(), o = oe(), d = te(), u = J(), p = ((S = (b = f.value) == null ? void 0 : b.partner) == null ? void 0 : S.messageType) === H.transactional, E = async (e) => {
|
|
67
62
|
if (e.size === 0)
|
|
68
63
|
return /* @__PURE__ */ new Set();
|
|
69
64
|
try {
|
|
@@ -71,61 +66,61 @@ const xe = () => {
|
|
|
71
66
|
} catch {
|
|
72
67
|
return null;
|
|
73
68
|
}
|
|
74
|
-
return
|
|
69
|
+
return ue(u.filterList);
|
|
75
70
|
}, h = async (e) => {
|
|
76
|
-
const
|
|
71
|
+
const n = await m(
|
|
77
72
|
"/newsletter/template-library/check-template-html-body",
|
|
78
|
-
{ html:
|
|
79
|
-
), { status: r, message: a } =
|
|
80
|
-
return r ||
|
|
73
|
+
{ html: ne(e) }
|
|
74
|
+
), { status: r, message: a } = n.data;
|
|
75
|
+
return r || t({
|
|
81
76
|
type: c.Error,
|
|
82
77
|
message: r === void 0 ? a : o("newsletter.invalid-url-link-for-toaster")
|
|
83
|
-
}), o(
|
|
78
|
+
}), o($), a === o(Y) && t({
|
|
84
79
|
type: c.Error,
|
|
85
80
|
message: o("newsletter.already-in-progress")
|
|
86
81
|
}), r;
|
|
87
|
-
},
|
|
88
|
-
const
|
|
82
|
+
}, g = (e) => !["if", "endif", "else", "elif", "now"].includes(e.toLowerCase()), y = (e) => ["if", "endif"].includes(e.toLowerCase()), T = (e, s) => {
|
|
83
|
+
const n = e.match(/({%(.*?)%})/g);
|
|
89
84
|
let r = !0;
|
|
90
|
-
return
|
|
85
|
+
return n !== null && !p && n.forEach((a) => {
|
|
91
86
|
const i = a.slice(2, -2).trim().match(/(".*?"|[^"\s]+)(?=\s*|\s*$)/g);
|
|
92
87
|
if (i && i.length > 0) {
|
|
93
88
|
const [l] = i;
|
|
94
|
-
|
|
89
|
+
g(l) && !s.includes(l) && (t({
|
|
95
90
|
type: c.Warning,
|
|
96
91
|
message: o("custom-fields.invalid-custom-fields")
|
|
97
92
|
}), r = !1);
|
|
98
93
|
}
|
|
99
94
|
}), r;
|
|
100
|
-
},
|
|
101
|
-
const r =
|
|
102
|
-
return
|
|
103
|
-
},
|
|
95
|
+
}, w = async (e, s, n) => {
|
|
96
|
+
const r = n ? await h(e) : !0;
|
|
97
|
+
return T(e, s) && r;
|
|
98
|
+
}, R = (e) => e.length > 0 ? !0 : (t({
|
|
104
99
|
type: c.Warning,
|
|
105
100
|
message: o("newsletter.html-content-is-empty")
|
|
106
|
-
}), !1),
|
|
107
|
-
const
|
|
108
|
-
return
|
|
101
|
+
}), !1), _ = (e) => {
|
|
102
|
+
const s = (e.match(/{/gm) || []).length, n = (e.match(/}/gm) || []).length;
|
|
103
|
+
return s > n && t({
|
|
109
104
|
type: c.Warning,
|
|
110
105
|
message: o("custom-fields.missing-closing-braces")
|
|
111
|
-
}),
|
|
106
|
+
}), s < n && t({
|
|
112
107
|
type: c.Warning,
|
|
113
108
|
message: o("custom-fields.missing-opening-braces")
|
|
114
|
-
}),
|
|
115
|
-
},
|
|
116
|
-
const
|
|
117
|
-
return
|
|
109
|
+
}), s === n;
|
|
110
|
+
}, N = (e) => {
|
|
111
|
+
const s = fe(e).length === 0;
|
|
112
|
+
return s || t({
|
|
118
113
|
type: c.Warning,
|
|
119
114
|
message: o("custom-fields.invalid-custom-fields")
|
|
120
|
-
}),
|
|
121
|
-
},
|
|
122
|
-
if (
|
|
115
|
+
}), s;
|
|
116
|
+
}, x = (e, s, n, r) => {
|
|
117
|
+
if (p)
|
|
123
118
|
return !0;
|
|
124
|
-
const a =
|
|
119
|
+
const a = de(
|
|
125
120
|
e,
|
|
126
|
-
t,
|
|
127
|
-
ie(e),
|
|
128
121
|
s,
|
|
122
|
+
ae(e),
|
|
123
|
+
n,
|
|
129
124
|
r
|
|
130
125
|
);
|
|
131
126
|
if (a.length > 0) {
|
|
@@ -134,91 +129,91 @@ const xe = () => {
|
|
|
134
129
|
${a.map((l) => `<li>${l}</li>`).join("")}
|
|
135
130
|
</ul>
|
|
136
131
|
`;
|
|
137
|
-
return
|
|
132
|
+
return t({
|
|
138
133
|
type: c.Error,
|
|
139
134
|
message: o("custom-fields.invalid-custom-fields") + i
|
|
140
135
|
}), !1;
|
|
141
136
|
}
|
|
142
137
|
return !0;
|
|
143
|
-
},
|
|
144
|
-
const
|
|
138
|
+
}, O = (e) => {
|
|
139
|
+
const s = e.match(/{%(.*?)%}/g), n = [];
|
|
145
140
|
let r = !0;
|
|
146
|
-
if (
|
|
147
|
-
const i = a.match(
|
|
148
|
-
(!i || a !==
|
|
141
|
+
if (s && s.forEach((a) => {
|
|
142
|
+
const i = a.match(P), l = a.match(X), v = (i == null ? void 0 : i.join("")) || "";
|
|
143
|
+
(!i || a !== v) && !l && (t({
|
|
149
144
|
type: c.Error,
|
|
150
145
|
message: o("newsletter.display-conditions-invalid-syntax")
|
|
151
|
-
}), r = !1), i && i.forEach((
|
|
152
|
-
|
|
146
|
+
}), r = !1), i && i.forEach((C) => {
|
|
147
|
+
C.trim() === "=" && (t({
|
|
153
148
|
type: c.Error,
|
|
154
149
|
message: o("custom-conditions.wrong-equality-operators")
|
|
155
150
|
}), r = !1);
|
|
156
|
-
const I =
|
|
157
|
-
I && I.forEach((
|
|
158
|
-
y(
|
|
151
|
+
const I = C.match(/^[a-zA-Z]*$/g);
|
|
152
|
+
I && I.forEach((A) => {
|
|
153
|
+
y(A) && n.push(A);
|
|
159
154
|
});
|
|
160
155
|
});
|
|
161
|
-
}),
|
|
162
|
-
const a =
|
|
163
|
-
a.length !== i.length && (
|
|
156
|
+
}), n.length) {
|
|
157
|
+
const a = n.filter((l) => l === "if"), i = n.filter((l) => l === "endif");
|
|
158
|
+
a.length !== i.length && (t({
|
|
164
159
|
type: c.Error,
|
|
165
160
|
message: o("custom-conditions.missing-if-endif-tag")
|
|
166
161
|
}), r = !1);
|
|
167
162
|
}
|
|
168
163
|
return r;
|
|
169
|
-
},
|
|
170
|
-
const
|
|
171
|
-
return r ||
|
|
164
|
+
}, k = (e) => {
|
|
165
|
+
const s = (e.match(/{% /gm) || []).length, n = (e.match(/ %}/gm) || []).length, r = s === n;
|
|
166
|
+
return r || t({
|
|
172
167
|
type: c.Warning,
|
|
173
168
|
message: o("custom-conditions.no-space-after-braces")
|
|
174
169
|
}), r;
|
|
175
|
-
},
|
|
170
|
+
}, B = (e) => (e.match(/({%(.*?)%})/g) || []).filter((n) => n.includes("if")).map((n) => (n.match(/{{.*}}/gm) || []).length).reduce((n, r) => n + r, 0) > 0 ? (t({
|
|
176
171
|
type: c.Warning,
|
|
177
172
|
message: o("custom-conditions.no-braces-inside-if-tag")
|
|
178
|
-
}), !1) : !0,
|
|
173
|
+
}), !1) : !0, D = () => u.hasInvalidBlock() ? (t({
|
|
179
174
|
type: c.Error,
|
|
180
|
-
message: o(
|
|
181
|
-
}), !1) : !0,
|
|
175
|
+
message: o(ee)
|
|
176
|
+
}), !1) : !0, F = () => d.recommendationConfigs && Object.values(d.recommendationConfigs).find((s) => s.filters.find((n) => n.value === "")) !== void 0 ? (t({
|
|
182
177
|
type: c.Error,
|
|
183
178
|
message: o("newsletter.fill-all-necessary-fields")
|
|
184
|
-
}), !1) : !0,
|
|
185
|
-
const
|
|
186
|
-
return e.match(
|
|
179
|
+
}), !1) : !0, L = (e) => {
|
|
180
|
+
const s = /src="[^"]*\.(svg|pst)"/gm;
|
|
181
|
+
return e.match(s) === null ? !0 : (t({
|
|
187
182
|
type: c.Error,
|
|
188
183
|
message: o("newsletter.invalid-image-type")
|
|
189
184
|
}), !1);
|
|
190
|
-
},
|
|
185
|
+
}, V = (e) => {
|
|
191
186
|
const r = new DOMParser().parseFromString(e, "text/html").querySelectorAll(".checkbox-block-v2");
|
|
192
187
|
return Array.from(r).find((i) => {
|
|
193
188
|
var l;
|
|
194
189
|
return !((l = i.id) != null && l.trim());
|
|
195
|
-
}) ? (
|
|
190
|
+
}) ? (t({
|
|
196
191
|
type: c.Error,
|
|
197
192
|
message: o("unsubscribe-templates.select-checkbox-groups")
|
|
198
193
|
}), !1) : !0;
|
|
199
|
-
},
|
|
194
|
+
}, M = (e) => {
|
|
200
195
|
const r = new DOMParser().parseFromString(e, "text/html").querySelectorAll(".radio-button-v2");
|
|
201
196
|
return Array.from(r).find((i) => {
|
|
202
197
|
var l;
|
|
203
198
|
return !((l = i.id) != null && l.trim());
|
|
204
|
-
}) ? (
|
|
199
|
+
}) ? (t({
|
|
205
200
|
type: c.Error,
|
|
206
201
|
message: o("unsubscribe-templates.select-radio-button-groups")
|
|
207
202
|
}), !1) : !0;
|
|
208
203
|
};
|
|
209
|
-
return { validateHtml: async (e,
|
|
210
|
-
var
|
|
204
|
+
return { validateHtml: async (e, s, n = !1) => {
|
|
205
|
+
var v, C;
|
|
211
206
|
const r = [
|
|
212
|
-
...
|
|
213
|
-
...
|
|
214
|
-
...((
|
|
215
|
-
], a =
|
|
216
|
-
return await
|
|
207
|
+
...s.map((I) => I.value),
|
|
208
|
+
...z,
|
|
209
|
+
...((C = (v = f.value) == null ? void 0 : v.template) == null ? void 0 : C.customFieldAttributes) ?? []
|
|
210
|
+
], a = G(e), i = await E(a);
|
|
211
|
+
return await w(e, r, n) && R(e) && _(e) && N(e) && x(e, r, a, i) && O(e) && k(e) && B(e) && D() && F() && L(e) && V(e) && M(e);
|
|
217
212
|
} };
|
|
218
213
|
};
|
|
219
214
|
export {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
215
|
+
ue as buildPartnerAttributeNameSet,
|
|
216
|
+
de as findInvalidCustomFields,
|
|
217
|
+
me as parseRecommendationVariable,
|
|
223
218
|
xe as useHtmlValidator
|
|
224
219
|
};
|
|
@@ -1,35 +1,14 @@
|
|
|
1
|
-
import { pairProductVariables as
|
|
2
|
-
|
|
3
|
-
const a = [
|
|
1
|
+
import { pairProductVariables as r } from "../../utils/pairProductVariables.js";
|
|
2
|
+
const t = [
|
|
4
3
|
{
|
|
5
4
|
id: "pair-product-variables",
|
|
6
5
|
description: "Replace product default values with template variables",
|
|
7
6
|
type: "custom",
|
|
8
|
-
processor:
|
|
7
|
+
processor: r,
|
|
9
8
|
priority: 60
|
|
10
9
|
// After recommendation rules (priority 50-53)
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
id: "wrap-hidden-price-mso-conditional",
|
|
14
|
-
// SD-147597: Outlook ignores display:none on <td>, so the horizontal layout's
|
|
15
|
-
// hidden price fallback renders too — duplicate price. Mark the hidden td(s)
|
|
16
|
-
// with safe placeholder comments and collapse them inline for web-engine Outlook.
|
|
17
|
-
description: "Mark hidden Items price tds for Outlook conditional hiding",
|
|
18
|
-
type: "custom",
|
|
19
|
-
processor: r,
|
|
20
|
-
priority: 65
|
|
21
|
-
// After pair-product-variables (60), before outlook rules (70+)
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
id: "swap-items-mso-markers",
|
|
25
|
-
// Injecting the delicate `<!-- -->` ghost token LAST (after reco minify P99
|
|
26
|
-
// and reco swap P100) keeps it out of every whitespace/comment-mangling pass.
|
|
27
|
-
description: "Swap Items MSO markers into [if !mso] conditional comments",
|
|
28
|
-
type: "custom",
|
|
29
|
-
processor: (i) => i.replaceAll(`<!--${e}-->`, "<!--[if !mso]><!-- -->").replaceAll(`<!--${t}-->`, "<!--<![endif]-->"),
|
|
30
|
-
priority: 101
|
|
31
10
|
}
|
|
32
11
|
];
|
|
33
12
|
export {
|
|
34
|
-
|
|
13
|
+
t as itemsCompilerRules
|
|
35
14
|
};
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { migrateCheckbox as t } from "./checkboxMigrator.js";
|
|
2
2
|
import { migrateCouponBlock as i } from "./couponBlockMigrator.js";
|
|
3
3
|
import { migrateItemsBlock as e } from "./itemsBlockMigrator.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return m = t(m), m = c(m), m = await p(m), m = i(m), m = g(m, o), m = e(m), m = a(m), m = n(m), m;
|
|
4
|
+
import { migrateRadioButton as a } from "./radioButtonMigrator.js";
|
|
5
|
+
import { migrateRecommendation as c } from "./recommendationMigrator.js";
|
|
6
|
+
import { migrateSocialIcons as g } from "./socialIconMigrator.js";
|
|
7
|
+
import { migrateUnsubscribe as n } from "./unsubscribeMigrator.js";
|
|
8
|
+
const k = async (o, r = {}) => {
|
|
9
|
+
let m = o;
|
|
10
|
+
return m = t(m), m = a(m), m = await n(m), m = i(m), m = c(m, r), m = e(m), m = g(m), m;
|
|
12
11
|
};
|
|
13
12
|
export {
|
|
14
|
-
|
|
13
|
+
k as migrate
|
|
15
14
|
};
|
|
@@ -88,11 +88,11 @@ function k(o) {
|
|
|
88
88
|
}
|
|
89
89
|
function h(o) {
|
|
90
90
|
var e;
|
|
91
|
-
const t = (
|
|
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
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
93
|
if (n && !n.includes("{{") && /^\d+$/.test(n)) {
|
|
94
|
-
const
|
|
95
|
-
u && u[
|
|
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,
|
|
@@ -148,7 +148,7 @@ function N(o, t) {
|
|
|
148
148
|
};
|
|
149
149
|
return r[o] || r.CART_ITEMS;
|
|
150
150
|
}
|
|
151
|
-
class
|
|
151
|
+
class z {
|
|
152
152
|
constructor() {
|
|
153
153
|
M(this, "parser");
|
|
154
154
|
this.parser = new DOMParser();
|
|
@@ -159,13 +159,13 @@ class H {
|
|
|
159
159
|
return this.backfillV2ProductTdAttributes(t);
|
|
160
160
|
let r = this.removeJinjaConditionals(t);
|
|
161
161
|
r = this.replaceTemplateVariables(r);
|
|
162
|
-
const
|
|
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
165
|
return q().$patch((n) => {
|
|
166
166
|
n.migrations = { ...n.migrations, [w]: a.length };
|
|
167
167
|
}), a.length === 0 ? (console.warn("ItemsBlockMigrator: No blocks found with items block selectors"), r) : (a.forEach((n) => {
|
|
168
|
-
const e = this.extractConfiguration(n),
|
|
168
|
+
const e = this.extractConfiguration(n), c = F({
|
|
169
169
|
orientation: e.orientation,
|
|
170
170
|
itemsType: e.itemsType,
|
|
171
171
|
itemId: e.itemId,
|
|
@@ -181,7 +181,7 @@ class H {
|
|
|
181
181
|
quantityStyles: e.quantityStyles,
|
|
182
182
|
nodeConfig: h(e.configBlockAttributes)
|
|
183
183
|
}), s = this.parser.parseFromString(
|
|
184
|
-
`<table><tbody><tr>${
|
|
184
|
+
`<table><tbody><tr>${c}</tr></tbody></table>`,
|
|
185
185
|
"text/html"
|
|
186
186
|
).querySelector("td");
|
|
187
187
|
if (s && n.parentNode) {
|
|
@@ -190,7 +190,7 @@ class H {
|
|
|
190
190
|
const d = s.querySelector("esd-config-block");
|
|
191
191
|
d && d.remove(), n.parentNode.replaceChild(s, n);
|
|
192
192
|
}
|
|
193
|
-
}),
|
|
193
|
+
}), l.documentElement.outerHTML);
|
|
194
194
|
} catch (r) {
|
|
195
195
|
return console.error("ItemsBlockMigrator failed:", r), t;
|
|
196
196
|
}
|
|
@@ -205,15 +205,15 @@ class H {
|
|
|
205
205
|
var C, D, P;
|
|
206
206
|
const r = k(
|
|
207
207
|
((C = t.querySelector("[data-type]")) == null ? void 0 : C.getAttribute("data-type")) ?? null
|
|
208
|
-
),
|
|
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
209
|
let S;
|
|
210
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,
|
|
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;
|
|
212
212
|
return {
|
|
213
213
|
orientation: S,
|
|
214
214
|
itemsType: r,
|
|
215
215
|
itemId: n,
|
|
216
|
-
currencySymbol:
|
|
216
|
+
currencySymbol: c,
|
|
217
217
|
currencyLocation: s,
|
|
218
218
|
formattedPrice: _,
|
|
219
219
|
configBlockAttributes: d,
|
|
@@ -231,7 +231,7 @@ class H {
|
|
|
231
231
|
* @param itemsType - The type of items (CART_ITEMS, BROWSED_ITEMS, PURCHASED_ITEMS)
|
|
232
232
|
* @param itemNumber - The item number (1-based index)
|
|
233
233
|
*/
|
|
234
|
-
extractConfigBlockAttributes(t, r,
|
|
234
|
+
extractConfigBlockAttributes(t, r, l) {
|
|
235
235
|
const a = t.querySelector("esd-config-block"), i = {};
|
|
236
236
|
if (!a)
|
|
237
237
|
return this.getDefaultConfigBlockAttributes();
|
|
@@ -240,18 +240,18 @@ class H {
|
|
|
240
240
|
}), i["data-cart_items_select_control_value"]) {
|
|
241
241
|
const e = i["data-cart_items_select_control_value"];
|
|
242
242
|
if (/^\d+$/.test(e)) {
|
|
243
|
-
const
|
|
244
|
-
u && u[
|
|
243
|
+
const c = parseInt(e) - 1, u = I[r];
|
|
244
|
+
u && u[c] && (i["data-cart_items_select_control_value"] = u[c].value);
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
if (i["data-product_price_control_curency"]) {
|
|
248
248
|
const e = i["data-product_price_control_curency"];
|
|
249
|
-
let
|
|
250
|
-
e === "before" ?
|
|
249
|
+
let c = e;
|
|
250
|
+
e === "before" ? c = "0" : e === "after" && (c = "1"), i["data-product_price_control_curency"] = c, i["data-product_price_currency_location"] = c;
|
|
251
251
|
}
|
|
252
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
253
|
const n = { ...this.getDefaultConfigBlockAttributes(), ...i };
|
|
254
|
-
return n["data-type"] = r, n["data-source"] = r, n["data-product_image_link"] = $(r,
|
|
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;
|
|
255
255
|
}
|
|
256
256
|
/**
|
|
257
257
|
* Returns default esd-config-block attributes based on the old template structure
|
|
@@ -301,7 +301,7 @@ class H {
|
|
|
301
301
|
};
|
|
302
302
|
}
|
|
303
303
|
/**
|
|
304
|
-
* Backfills data-type (and data-number
|
|
304
|
+
* Backfills data-type (and data-number) onto v2 `.ins-product-td` elements
|
|
305
305
|
* from their persisted `esd-ext-config` nodeConfig, and strips the legacy
|
|
306
306
|
* static `width` that older builds baked onto the product-td.
|
|
307
307
|
*
|
|
@@ -326,24 +326,22 @@ class H {
|
|
|
326
326
|
if (!t.includes("ins-product-td") || !t.includes("esd-ext-config"))
|
|
327
327
|
return t;
|
|
328
328
|
const r = this.parser.parseFromString(t, "text/html");
|
|
329
|
-
let
|
|
329
|
+
let l = !1;
|
|
330
330
|
return r.querySelectorAll(".ins-product-td").forEach((a) => {
|
|
331
|
-
a.hasAttribute("width") && (a.removeAttribute("width"),
|
|
332
|
-
const i = a.getAttribute("esd-ext-config");
|
|
333
|
-
let n = null;
|
|
334
|
-
try {
|
|
335
|
-
n = i ? JSON.parse(i) : null;
|
|
336
|
-
} catch {
|
|
337
|
-
}
|
|
338
|
-
if (!n || (!a.getAttribute("data-nodup") && typeof n.priceHideDiscount == "boolean" && (a.setAttribute("data-nodup", String(n.priceHideDiscount)), c = !0), a.getAttribute("data-type")))
|
|
339
|
-
return;
|
|
340
|
-
const e = n.type || n.source;
|
|
341
|
-
if (!e)
|
|
331
|
+
if (a.hasAttribute("width") && (a.removeAttribute("width"), l = !0), a.getAttribute("data-type"))
|
|
342
332
|
return;
|
|
343
|
-
a.
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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;
|
|
347
345
|
}
|
|
348
346
|
/**
|
|
349
347
|
* Fast check for the presence of any items block (cart / browsed / purchased)
|
|
@@ -364,15 +362,15 @@ class H {
|
|
|
364
362
|
* contains display condition Jinja scripts that should NOT be removed.
|
|
365
363
|
*/
|
|
366
364
|
removeJinjaConditionals(t) {
|
|
367
|
-
const r = "__ESD_DISPLAY_CONDITIONS_PLACEHOLDER__",
|
|
368
|
-
let a =
|
|
365
|
+
const r = "__ESD_DISPLAY_CONDITIONS_PLACEHOLDER__", l = t.match(/esd-custom-display-conditions="[^"]*"/);
|
|
366
|
+
let a = l ? t.replace(l[0], r) : t;
|
|
369
367
|
return a = a.replace(
|
|
370
368
|
/\{%\s*if\s+(ins_apr|browsed_item|purchased_item)_total_product_kind\s*(>|>)\s*\d+\s*%\}/g,
|
|
371
369
|
""
|
|
372
370
|
), a = a.replace(
|
|
373
371
|
/\{%\s*if\s+(ins_apr|browsed_item|purchased_item)_price_\d+\s*(!=|!=)\s*\1_originalprice_\d+\s*%\}/g,
|
|
374
372
|
""
|
|
375
|
-
), a = a.replace(/\{%\s*endif\s*%\}/g, ""),
|
|
373
|
+
), a = a.replace(/\{%\s*endif\s*%\}/g, ""), l && (a = a.replace(r, l[0])), a = a.replace(/\n\s*\n\s*\n/g, `
|
|
376
374
|
|
|
377
375
|
`), a;
|
|
378
376
|
}
|
|
@@ -387,30 +385,30 @@ class H {
|
|
|
387
385
|
*/
|
|
388
386
|
replaceTemplateVariables(t) {
|
|
389
387
|
const { PAIRS_FOR_EXTENSION: r } = K;
|
|
390
|
-
return t.replace(/{{([^}]+)}}/g, (
|
|
388
|
+
return t.replace(/{{([^}]+)}}/g, (l, a) => {
|
|
391
389
|
const i = a.match(/^(ins_apr|browsed_item|purchased_item)_([a-z_]+)_(\d+)$/);
|
|
392
390
|
if (!i)
|
|
393
|
-
return
|
|
394
|
-
const [, n, e,
|
|
391
|
+
return l;
|
|
392
|
+
const [, n, e, c] = i, u = V[n];
|
|
395
393
|
if (!u)
|
|
396
|
-
return console.warn(`Unknown variable prefix: ${n}`),
|
|
394
|
+
return console.warn(`Unknown variable prefix: ${n}`), l;
|
|
397
395
|
const s = x[e];
|
|
398
396
|
if (!s)
|
|
399
|
-
return console.warn(`Unknown variable suffix mapping for: ${e}`),
|
|
397
|
+
return console.warn(`Unknown variable suffix mapping for: ${e}`), l;
|
|
400
398
|
const { pairsKey: _, defaultKey: d, isArray: b } = s, y = r[_][u];
|
|
401
399
|
if (!y)
|
|
402
|
-
return console.warn(`No data found for: ${_}.${u}`),
|
|
400
|
+
return console.warn(`No data found for: ${_}.${u}`), l;
|
|
403
401
|
if (b) {
|
|
404
|
-
const f = parseInt(
|
|
405
|
-
return Array.isArray(m) && m[f] ? m[f] : (console.warn(`Array value not found: ${_}.${u}.${d}[${f}]`),
|
|
402
|
+
const f = parseInt(c) - 1, m = y[d];
|
|
403
|
+
return Array.isArray(m) && m[f] ? m[f] : (console.warn(`Array value not found: ${_}.${u}.${d}[${f}]`), l);
|
|
406
404
|
}
|
|
407
405
|
const A = y[d];
|
|
408
|
-
return A !== void 0 ? String(A) : (console.warn(`Default value not found: ${_}.${u}.${d}`),
|
|
406
|
+
return A !== void 0 ? String(A) : (console.warn(`Default value not found: ${_}.${u}.${d}`), l);
|
|
409
407
|
});
|
|
410
408
|
}
|
|
411
409
|
}
|
|
412
410
|
function Q(o) {
|
|
413
|
-
return new
|
|
411
|
+
return new z().migrate(o);
|
|
414
412
|
}
|
|
415
413
|
export {
|
|
416
414
|
Q as migrateItemsBlock
|