@useinsider/guido 3.8.1-beta.2ee94c2 → 3.8.1-beta.5cf94b0
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/@types/config/schemas.js +70 -66
- package/dist/composables/useHtmlValidator.js +180 -133
- package/dist/composables/usePreviewMode.js +15 -14
- package/dist/composables/useRecommendationPreview.js +111 -0
- package/dist/config/compiler/recommendationCompilerRules.js +1 -1
- package/dist/config/compiler/utils/recommendationCompilerUtils.js +98 -89
- package/dist/config/compiler/utils/recommendationIgnoreUtils.js +15 -0
- package/dist/config/migrator/recommendation/extractors.js +44 -22
- package/dist/config/migrator/recommendation/htmlBuilder.js +170 -163
- package/dist/config/migrator/recommendation/settingsMapper.js +38 -33
- package/dist/config/migrator/recommendationMigrator.js +30 -31
- package/dist/extensions/Blocks/Recommendation/block.js +60 -41
- package/dist/extensions/Blocks/Recommendation/canvasPreview.css.js +16 -0
- package/dist/extensions/Blocks/Recommendation/constants/defaultConfig.js +41 -32
- package/dist/extensions/Blocks/Recommendation/constants/selectors.js +26 -20
- package/dist/extensions/Blocks/Recommendation/controls/cardComposition/index.js +359 -264
- package/dist/extensions/Blocks/Recommendation/controls/main/index.js +96 -83
- package/dist/extensions/Blocks/Recommendation/controls/main/layoutOrientation.js +43 -31
- package/dist/extensions/Blocks/Recommendation/controls/main/pricePlacement.js +133 -0
- package/dist/extensions/Blocks/Recommendation/controls/main/productCount.js +3 -2
- package/dist/extensions/Blocks/Recommendation/controls/main/productLayout.js +55 -45
- package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +175 -166
- package/dist/extensions/Blocks/Recommendation/controls/syncInfoMessage.js +7 -6
- package/dist/extensions/Blocks/Recommendation/extension.js +31 -29
- package/dist/extensions/Blocks/Recommendation/iconsRegistry.js +21 -7
- package/dist/extensions/Blocks/Recommendation/recommendation.css.js +64 -4
- package/dist/extensions/Blocks/Recommendation/settingsPanel.js +3 -2
- package/dist/extensions/Blocks/Recommendation/store/recommendation.js +6 -3
- package/dist/extensions/Blocks/Recommendation/templates/grid/elementRenderer.js +130 -96
- package/dist/extensions/Blocks/Recommendation/templates/grid/template.js +43 -53
- package/dist/extensions/Blocks/Recommendation/templates/index.js +20 -16
- package/dist/extensions/Blocks/Recommendation/templates/list/elementRenderer.js +86 -80
- package/dist/extensions/Blocks/Recommendation/templates/list/template.js +31 -40
- package/dist/extensions/Blocks/Recommendation/templates/utils.js +155 -102
- package/dist/src/@types/config/schemas.d.ts +16 -0
- package/dist/src/composables/useConfig.d.ts +4 -0
- package/dist/src/composables/useHtmlValidator.d.ts +27 -0
- package/dist/src/composables/useHtmlValidator.test.d.ts +1 -0
- package/dist/src/composables/useRecommendationPreview.d.ts +10 -0
- package/dist/src/config/compiler/utils/recommendationIgnoreUtils.d.ts +17 -0
- package/dist/src/config/compiler/utils/recommendationIgnoreUtils.test.d.ts +1 -0
- package/dist/src/config/migrator/recommendation/extractors.d.ts +15 -0
- package/dist/src/config/migrator/recommendation/htmlBuilder.d.ts +8 -0
- package/dist/src/config/migrator/recommendation/settingsMapper.d.ts +1 -1
- package/dist/src/extensions/Blocks/Recommendation/block.d.ts +10 -0
- package/dist/src/extensions/Blocks/Recommendation/constants/index.d.ts +1 -1
- package/dist/src/extensions/Blocks/Recommendation/constants/selectors.d.ts +21 -0
- package/dist/src/extensions/Blocks/Recommendation/controls/cardComposition/index.d.ts +36 -3
- package/dist/src/extensions/Blocks/Recommendation/controls/index.d.ts +1 -1
- package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +3 -1
- package/dist/src/extensions/Blocks/Recommendation/controls/main/layoutOrientation.d.ts +5 -0
- package/dist/src/extensions/Blocks/Recommendation/controls/main/pricePlacement.d.ts +59 -0
- package/dist/src/extensions/Blocks/Recommendation/controls/main/productLayout.d.ts +6 -0
- package/dist/src/extensions/Blocks/Recommendation/controls/main/utils.d.ts +9 -0
- package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +2 -0
- package/dist/src/extensions/Blocks/Recommendation/templates/grid/elementRenderer.d.ts +13 -1
- package/dist/src/extensions/Blocks/Recommendation/templates/grid/template.d.ts +4 -4
- package/dist/src/extensions/Blocks/Recommendation/templates/index.d.ts +1 -1
- package/dist/src/extensions/Blocks/Recommendation/templates/list/elementRenderer.d.ts +10 -1
- package/dist/src/extensions/Blocks/Recommendation/templates/list/template.d.ts +3 -3
- package/dist/src/extensions/Blocks/Recommendation/templates/utils.d.ts +51 -1
- package/dist/src/extensions/Blocks/Recommendation/types/nodeConfig.d.ts +15 -0
- package/dist/src/stores/config.d.ts +36 -0
- package/package.json +1 -1
|
@@ -1,172 +1,219 @@
|
|
|
1
|
-
import { useConfig as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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";
|
|
4
5
|
import { ToasterTypeOptions as c } from "../enums/toaster.js";
|
|
5
|
-
import { itemsBlockDynamicVariables as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 oe } from "./useToaster.js";
|
|
15
|
+
import { useTranslations as ie } from "./useTranslations.js";
|
|
16
|
+
const re = /recommendation-id="(\d+)"/g;
|
|
17
|
+
function ae(t) {
|
|
18
|
+
return [...t.matchAll(re)].map((m) => m[1]);
|
|
16
19
|
}
|
|
17
|
-
function
|
|
18
|
-
return
|
|
20
|
+
function ce(t, m) {
|
|
21
|
+
return m.some((f) => t.startsWith(`${f}_`));
|
|
19
22
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
const le = /^(\d+)_\d+_(.+)$/;
|
|
24
|
+
function me(t) {
|
|
25
|
+
const m = t.match(le);
|
|
26
|
+
return m ? { recoId: m[1], attribute: m[2] } : null;
|
|
27
|
+
}
|
|
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());
|
|
32
|
+
}), m;
|
|
33
|
+
}
|
|
34
|
+
function de(t, m, f, i, d) {
|
|
35
|
+
const u = t.match(/{{([a-zA-Z0-9_.\s]*)}}/gm);
|
|
36
|
+
if (!u)
|
|
37
|
+
return [];
|
|
38
|
+
const p = new Set(m.map((y) => y.toLowerCase())), h = [];
|
|
39
|
+
return u.forEach((y) => {
|
|
40
|
+
const g = y.slice(2, -2).trim().toLowerCase();
|
|
41
|
+
if (g !== "" && p.has(g))
|
|
42
|
+
return;
|
|
43
|
+
const E = me(g);
|
|
44
|
+
if (E && i.has(E.recoId)) {
|
|
45
|
+
if (!d || d.has(E.attribute))
|
|
46
|
+
return;
|
|
47
|
+
h.push(g);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
ce(g, f) || g.includes(".") || h.push(g);
|
|
51
|
+
}), h;
|
|
52
|
+
}
|
|
53
|
+
function fe(t) {
|
|
54
|
+
return (t.replace(U, "$1").match(j) ?? []).filter((i) => {
|
|
55
|
+
const d = i.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;
|
|
24
57
|
});
|
|
25
58
|
}
|
|
26
|
-
const
|
|
27
|
-
var
|
|
28
|
-
const { showToaster:
|
|
29
|
-
|
|
59
|
+
const xe = () => {
|
|
60
|
+
var I, b;
|
|
61
|
+
const { showToaster: t } = oe(), { post: m } = se(), { config: f } = W(), i = ie(), d = te(), u = J(), p = ((b = (I = f.value) == null ? void 0 : I.partner) == null ? void 0 : b.messageType) === H.transactional, h = async (e) => {
|
|
62
|
+
if (e.size === 0)
|
|
63
|
+
return /* @__PURE__ */ new Set();
|
|
64
|
+
try {
|
|
65
|
+
await u.fetchRecommendationFilters();
|
|
66
|
+
} catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return ue(u.filterList);
|
|
70
|
+
}, y = async (e) => {
|
|
71
|
+
const n = await m(
|
|
30
72
|
"/newsletter/template-library/check-template-html-body",
|
|
31
|
-
{ html:
|
|
32
|
-
), { status:
|
|
33
|
-
return
|
|
73
|
+
{ html: ne(e) }
|
|
74
|
+
), { status: o, message: a } = n.data;
|
|
75
|
+
return o || t({
|
|
34
76
|
type: c.Alert,
|
|
35
|
-
message:
|
|
36
|
-
}),
|
|
77
|
+
message: o === void 0 ? a : i("newsletter.invalid-url-link-for-toaster")
|
|
78
|
+
}), i($), a === i(Y) && t({
|
|
37
79
|
type: c.Alert,
|
|
38
|
-
message:
|
|
39
|
-
}),
|
|
40
|
-
},
|
|
41
|
-
const
|
|
42
|
-
let
|
|
43
|
-
return
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
46
|
-
const [
|
|
47
|
-
|
|
80
|
+
message: i("newsletter.already-in-progress")
|
|
81
|
+
}), o;
|
|
82
|
+
}, g = (e) => !["if", "endif", "else", "elif", "now"].includes(e.toLowerCase()), E = (e) => ["if", "endif"].includes(e.toLowerCase()), T = (e, s) => {
|
|
83
|
+
const n = e.match(/({%(.*?)%})/g);
|
|
84
|
+
let o = !0;
|
|
85
|
+
return n !== null && !p && n.forEach((a) => {
|
|
86
|
+
const r = a.slice(2, -2).trim().match(/(".*?"|[^"\s]+)(?=\s*|\s*$)/g);
|
|
87
|
+
if (r && r.length > 0) {
|
|
88
|
+
const [l] = r;
|
|
89
|
+
g(l) && !s.includes(l) && (t({
|
|
48
90
|
type: c.Warning,
|
|
49
|
-
message:
|
|
50
|
-
}),
|
|
91
|
+
message: i("custom-fields.invalid-custom-fields")
|
|
92
|
+
}), o = !1);
|
|
51
93
|
}
|
|
52
|
-
}),
|
|
53
|
-
},
|
|
54
|
-
const
|
|
55
|
-
return
|
|
56
|
-
},
|
|
94
|
+
}), o;
|
|
95
|
+
}, w = async (e, s, n) => {
|
|
96
|
+
const o = n ? await y(e) : !0;
|
|
97
|
+
return T(e, s) && o;
|
|
98
|
+
}, R = (e) => e.length > 0 ? !0 : (t({
|
|
57
99
|
type: c.Warning,
|
|
58
|
-
message:
|
|
59
|
-
}), !1),
|
|
60
|
-
const s = (e.match(/{/gm) || []).length,
|
|
61
|
-
return s >
|
|
100
|
+
message: i("newsletter.html-content-is-empty")
|
|
101
|
+
}), !1), _ = (e) => {
|
|
102
|
+
const s = (e.match(/{/gm) || []).length, n = (e.match(/}/gm) || []).length;
|
|
103
|
+
return s > n && t({
|
|
62
104
|
type: c.Warning,
|
|
63
|
-
message:
|
|
64
|
-
}), s <
|
|
105
|
+
message: i("custom-fields.missing-closing-braces")
|
|
106
|
+
}), s < n && t({
|
|
65
107
|
type: c.Warning,
|
|
66
|
-
message:
|
|
67
|
-
}), s ===
|
|
68
|
-
},
|
|
69
|
-
const s =
|
|
70
|
-
return s ||
|
|
108
|
+
message: i("custom-fields.missing-opening-braces")
|
|
109
|
+
}), s === n;
|
|
110
|
+
}, N = (e) => {
|
|
111
|
+
const s = fe(e).length === 0;
|
|
112
|
+
return s || t({
|
|
71
113
|
type: c.Warning,
|
|
72
|
-
message:
|
|
114
|
+
message: i("custom-fields.invalid-custom-fields")
|
|
73
115
|
}), s;
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
116
|
+
}, x = (e, s, n, o) => {
|
|
117
|
+
if (p)
|
|
118
|
+
return !0;
|
|
119
|
+
const a = de(
|
|
120
|
+
e,
|
|
121
|
+
s,
|
|
122
|
+
ae(e),
|
|
123
|
+
n,
|
|
124
|
+
o
|
|
125
|
+
);
|
|
126
|
+
if (a.length > 0) {
|
|
127
|
+
const r = `
|
|
128
|
+
<ul>
|
|
129
|
+
${a.map((l) => `<li>${l}</li>`).join("")}
|
|
130
|
+
</ul>
|
|
131
|
+
`;
|
|
132
|
+
return t({
|
|
133
|
+
type: c.Alert,
|
|
134
|
+
message: i("custom-fields.invalid-custom-fields") + r
|
|
135
|
+
}), !1;
|
|
92
136
|
}
|
|
93
137
|
return !0;
|
|
94
|
-
},
|
|
95
|
-
const s = e.match(/{%(.*?)%}/g),
|
|
96
|
-
let
|
|
97
|
-
if (s && s.forEach((
|
|
98
|
-
const
|
|
99
|
-
(!
|
|
138
|
+
}, O = (e) => {
|
|
139
|
+
const s = e.match(/{%(.*?)%}/g), n = [];
|
|
140
|
+
let o = !0;
|
|
141
|
+
if (s && s.forEach((a) => {
|
|
142
|
+
const r = a.match(P), l = a.match(X), v = (r == null ? void 0 : r.join("")) || "";
|
|
143
|
+
(!r || a !== v) && !l && (t({
|
|
100
144
|
type: c.Alert,
|
|
101
|
-
message:
|
|
102
|
-
}),
|
|
103
|
-
|
|
145
|
+
message: i("newsletter.display-conditions-invalid-syntax")
|
|
146
|
+
}), o = !1), r && r.forEach((C) => {
|
|
147
|
+
C.trim() === "=" && (t({
|
|
104
148
|
type: c.Alert,
|
|
105
|
-
message:
|
|
106
|
-
}),
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
149
|
+
message: i("custom-conditions.wrong-equality-operators")
|
|
150
|
+
}), o = !1);
|
|
151
|
+
const A = C.match(/^[a-zA-Z]*$/g);
|
|
152
|
+
A && A.forEach((S) => {
|
|
153
|
+
E(S) && n.push(S);
|
|
110
154
|
});
|
|
111
155
|
});
|
|
112
|
-
}),
|
|
113
|
-
const
|
|
114
|
-
|
|
156
|
+
}), n.length) {
|
|
157
|
+
const a = n.filter((l) => l === "if"), r = n.filter((l) => l === "endif");
|
|
158
|
+
a.length !== r.length && (t({
|
|
115
159
|
type: c.Alert,
|
|
116
|
-
message:
|
|
117
|
-
}),
|
|
160
|
+
message: i("custom-conditions.missing-if-endif-tag")
|
|
161
|
+
}), o = !1);
|
|
118
162
|
}
|
|
119
|
-
return
|
|
120
|
-
},
|
|
121
|
-
const s = (e.match(/{% /gm) || []).length,
|
|
122
|
-
return
|
|
163
|
+
return o;
|
|
164
|
+
}, k = (e) => {
|
|
165
|
+
const s = (e.match(/{% /gm) || []).length, n = (e.match(/ %}/gm) || []).length, o = s === n;
|
|
166
|
+
return o || t({
|
|
123
167
|
type: c.Warning,
|
|
124
|
-
message:
|
|
125
|
-
}),
|
|
126
|
-
},
|
|
168
|
+
message: i("custom-conditions.no-space-after-braces")
|
|
169
|
+
}), o;
|
|
170
|
+
}, B = (e) => (e.match(/({%(.*?)%})/g) || []).filter((n) => n.includes("if")).map((n) => (n.match(/{{.*}}/gm) || []).length).reduce((n, o) => n + o, 0) > 0 ? (t({
|
|
127
171
|
type: c.Warning,
|
|
128
|
-
message:
|
|
129
|
-
}), !1) : !0,
|
|
172
|
+
message: i("custom-conditions.no-braces-inside-if-tag")
|
|
173
|
+
}), !1) : !0, D = () => u.hasInvalidBlock() ? (t({
|
|
130
174
|
type: c.Alert,
|
|
131
|
-
message:
|
|
132
|
-
}), !1) : !0,
|
|
175
|
+
message: i(ee)
|
|
176
|
+
}), !1) : !0, F = () => d.recommendationConfigs && Object.values(d.recommendationConfigs).find((s) => s.filters.find((n) => n.value === "")) !== void 0 ? (t({
|
|
133
177
|
type: c.Alert,
|
|
134
|
-
message:
|
|
135
|
-
}), !1) : !0,
|
|
178
|
+
message: i("newsletter.fill-all-necessary-fields")
|
|
179
|
+
}), !1) : !0, L = (e) => {
|
|
136
180
|
const s = /src="[^"]*\.(svg|pst)"/gm;
|
|
137
|
-
return e.match(s) === null ? !0 : (
|
|
181
|
+
return e.match(s) === null ? !0 : (t({
|
|
138
182
|
type: c.Alert,
|
|
139
|
-
message:
|
|
183
|
+
message: i("newsletter.invalid-image-type")
|
|
140
184
|
}), !1);
|
|
141
|
-
},
|
|
142
|
-
const
|
|
143
|
-
return Array.from(
|
|
144
|
-
var
|
|
145
|
-
return !((
|
|
146
|
-
}) ? (
|
|
185
|
+
}, V = (e) => {
|
|
186
|
+
const o = new DOMParser().parseFromString(e, "text/html").querySelectorAll(".checkbox-block-v2");
|
|
187
|
+
return Array.from(o).find((r) => {
|
|
188
|
+
var l;
|
|
189
|
+
return !((l = r.id) != null && l.trim());
|
|
190
|
+
}) ? (t({
|
|
147
191
|
type: c.Alert,
|
|
148
|
-
message:
|
|
192
|
+
message: i("unsubscribe-templates.select-checkbox-groups")
|
|
149
193
|
}), !1) : !0;
|
|
150
|
-
},
|
|
151
|
-
const
|
|
152
|
-
return Array.from(
|
|
153
|
-
var
|
|
154
|
-
return !((
|
|
155
|
-
}) ? (
|
|
194
|
+
}, M = (e) => {
|
|
195
|
+
const o = new DOMParser().parseFromString(e, "text/html").querySelectorAll(".radio-button-v2");
|
|
196
|
+
return Array.from(o).find((r) => {
|
|
197
|
+
var l;
|
|
198
|
+
return !((l = r.id) != null && l.trim());
|
|
199
|
+
}) ? (t({
|
|
156
200
|
type: c.Alert,
|
|
157
|
-
message:
|
|
201
|
+
message: i("unsubscribe-templates.select-radio-button-groups")
|
|
158
202
|
}), !1) : !0;
|
|
159
203
|
};
|
|
160
|
-
return { validateHtml: async (e, s,
|
|
161
|
-
var
|
|
162
|
-
const
|
|
163
|
-
...s.map((
|
|
164
|
-
...
|
|
165
|
-
...((
|
|
166
|
-
];
|
|
167
|
-
return await
|
|
204
|
+
return { validateHtml: async (e, s, n = !1) => {
|
|
205
|
+
var v, C;
|
|
206
|
+
const o = [
|
|
207
|
+
...s.map((A) => A.value),
|
|
208
|
+
...z,
|
|
209
|
+
...((C = (v = f.value) == null ? void 0 : v.template) == null ? void 0 : C.customFieldAttributes) ?? []
|
|
210
|
+
], a = G(e), r = await h(a);
|
|
211
|
+
return await w(e, o, n) && R(e) && _(e) && N(e) && x(e, o, a, r) && O(e) && k(e) && B(e) && D() && F() && L(e) && V(e) && M(e);
|
|
168
212
|
} };
|
|
169
213
|
};
|
|
170
214
|
export {
|
|
171
|
-
|
|
215
|
+
ue as buildPartnerAttributeNameSet,
|
|
216
|
+
de as findInvalidCustomFields,
|
|
217
|
+
me as parseRecommendationVariable,
|
|
218
|
+
xe as useHtmlValidator
|
|
172
219
|
};
|
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import { useEditorStore as
|
|
2
|
-
import { usePreviewStore as
|
|
3
|
-
import { useActionsApi as
|
|
4
|
-
import { useCodeEditorApi as
|
|
5
|
-
import { useHtmlCompiler as
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { useEditorStore as n } from "../stores/editor.js";
|
|
2
|
+
import { usePreviewStore as p } from "../stores/preview.js";
|
|
3
|
+
import { useActionsApi as c } from "./useActionsApi.js";
|
|
4
|
+
import { useCodeEditorApi as u } from "./useCodeEditorApi.js";
|
|
5
|
+
import { useHtmlCompiler as v } from "./useHtmlCompiler.js";
|
|
6
|
+
import { useRecommendationPreview as w } from "./useRecommendationPreview.js";
|
|
7
|
+
const C = () => {
|
|
8
|
+
const t = n(), e = p(), { closeCodeEditor: a } = u(), { getPreviewData: m, getCompiledEmail: s } = c(), { compileHtml: l } = v(), { substituteRecommendationPreview: r } = w(), i = () => {
|
|
8
9
|
t.isPreviewModeOpen = !1, e.$reset();
|
|
9
10
|
};
|
|
10
11
|
return {
|
|
11
|
-
closePreviewMode:
|
|
12
|
+
closePreviewMode: i,
|
|
12
13
|
openPreviewMode: () => {
|
|
13
|
-
t.isCodeEditorOpen &&
|
|
14
|
+
t.isCodeEditorOpen && a(), t.isPreviewModeOpen = !0;
|
|
14
15
|
},
|
|
15
16
|
loadPreviewData: async () => {
|
|
16
17
|
if (!(t.loadingStatus || e.isLoaded)) {
|
|
17
18
|
t.loadingStatus = !0;
|
|
18
19
|
try {
|
|
19
|
-
const [o,
|
|
20
|
-
|
|
20
|
+
const [o, d] = await Promise.all([
|
|
21
|
+
m(),
|
|
21
22
|
s({ minimize: !0, resetDataSavedFlag: !1 })
|
|
22
23
|
]);
|
|
23
|
-
e.templateHtml = o.html || "", e.ampHtml = o.ampHtml || "", e.ampErrors = o.ampErrors || [], e.setEmailFormat(o.ampHtml ? "AMP" : "html"), e.emailSizeKB =
|
|
24
|
+
e.templateHtml = r(o.html || ""), e.ampHtml = r(o.ampHtml || ""), e.ampErrors = o.ampErrors || [], e.setEmailFormat(o.ampHtml ? "AMP" : "html"), e.emailSizeKB = l(d.html).estimatedSizeKB, e.isLoaded = !0;
|
|
24
25
|
} catch (o) {
|
|
25
|
-
console.error("Failed to load preview data:", o),
|
|
26
|
+
console.error("Failed to load preview data:", o), i();
|
|
26
27
|
} finally {
|
|
27
28
|
t.loadingStatus = !1;
|
|
28
29
|
}
|
|
@@ -31,5 +32,5 @@ const g = () => {
|
|
|
31
32
|
};
|
|
32
33
|
};
|
|
33
34
|
export {
|
|
34
|
-
|
|
35
|
+
C as usePreviewMode
|
|
35
36
|
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { BLOCK_ROOT_SELECTOR as S, CURRENCY_ATTR as p, CONTAINER_SELECTOR as O } from "../extensions/Blocks/Recommendation/constants/selectors.js";
|
|
2
|
+
import { useRecommendationExtensionStore as h } from "../extensions/Blocks/Recommendation/store/recommendation.js";
|
|
3
|
+
import { formatPrice as E } from "../extensions/Blocks/Recommendation/utils/priceFormatter.js";
|
|
4
|
+
const f = `${S}[recommendation-id]`, C = ".product-old-price", R = /\{\{(?:reco_)?(\d+_\d+_[a-zA-Z0-9_.]+)\}\}/g, T = new RegExp(
|
|
5
|
+
"\\{%\\s*if\\s+([\\s\\S]+?)\\s*%\\}([\\s\\S]*?)(?:\\{%\\s*else\\s*%\\}([\\s\\S]*?))?\\{%\\s*endif\\s*%\\}",
|
|
6
|
+
"g"
|
|
7
|
+
);
|
|
8
|
+
function b(e) {
|
|
9
|
+
return e.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
10
|
+
}
|
|
11
|
+
function _(e) {
|
|
12
|
+
var s;
|
|
13
|
+
const n = (s = e.replace(/[\u0000-\u0020]+/g, "").toLowerCase().match(/^([a-z][a-z0-9+.-]*):/)) == null ? void 0 : s[1];
|
|
14
|
+
return n && n !== "http" && n !== "https" && n !== "mailto" ? "" : e;
|
|
15
|
+
}
|
|
16
|
+
function N(e) {
|
|
17
|
+
const t = e.getAttribute(p.CURRENCY) || "USD", n = e.getAttribute(p.DECIMAL_SEPARATOR) || ".", s = e.getAttribute(p.THOUSAND_SEPARATOR) || ",";
|
|
18
|
+
return {
|
|
19
|
+
code: t,
|
|
20
|
+
symbol: e.getAttribute(p.SYMBOL) || t,
|
|
21
|
+
alignment: e.getAttribute(p.ALIGNMENT) === "0" ? "before" : "after",
|
|
22
|
+
decimalCount: parseInt(e.getAttribute(p.DECIMAL_COUNT) || "2") || 2,
|
|
23
|
+
decimalSeparator: n,
|
|
24
|
+
thousandSeparator: s
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function g(e, t) {
|
|
28
|
+
return (e == null ? void 0 : e[t]) ?? Object.values(e ?? {})[0] ?? 0;
|
|
29
|
+
}
|
|
30
|
+
function L(e, t) {
|
|
31
|
+
const n = g(e.original_price, t), s = g(e.price, t), o = n > 0 ? Math.round((n - s) / n * 100) : 0;
|
|
32
|
+
return o > 0 ? `${o}%` : "0%";
|
|
33
|
+
}
|
|
34
|
+
function P(e, t, n, s, o, a) {
|
|
35
|
+
s.forEach((i, c) => {
|
|
36
|
+
const r = (m) => `${n}_${c}_${m}`, u = E({ price: g(i.price, o.code), currency: o }), l = E({ price: g(i.original_price, o.code), currency: o }), d = L(i, o.code);
|
|
37
|
+
e.set(r("name"), i.name ?? ""), e.set(r("image_url"), _(i.image_url ?? "")), e.set(r("url"), _(i.url ?? "")), e.set(r("item_id"), i.item_id ?? ""), e.set(r("currency"), ""), e.set(r("price"), u), e.set(r("original_price"), l), e.set(r("discount"), d), e.set(r("omnibus_price"), l), e.set(r("omnibus_discount"), d), a && u === l && t.add(`${n}_${c}`), Object.entries(i.product_attributes ?? {}).forEach(([m, A]) => {
|
|
38
|
+
e.set(r(`product_attribute.${m}`), String(A)), e.set(r(m), String(A));
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function $(e, t) {
|
|
43
|
+
const n = e.match(/^(.+?)\s*(!=|==)\s*"([^"]*)"$/);
|
|
44
|
+
if (!n)
|
|
45
|
+
return !0;
|
|
46
|
+
const [, s, o, a] = n, i = t.get(s.trim()) ?? "";
|
|
47
|
+
return o === "!=" ? i !== a : i === a;
|
|
48
|
+
}
|
|
49
|
+
function z(e, t) {
|
|
50
|
+
return e.replace(
|
|
51
|
+
T,
|
|
52
|
+
(n, s, o, a) => s.split(/\s+and\s+/).every((c) => $(c.trim(), t)) ? o : a ?? ""
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
function w(e) {
|
|
56
|
+
let t = e;
|
|
57
|
+
for (; t.children.length === 1; )
|
|
58
|
+
[t] = t.children;
|
|
59
|
+
return t;
|
|
60
|
+
}
|
|
61
|
+
function D(e, t) {
|
|
62
|
+
var i;
|
|
63
|
+
if (!t.size)
|
|
64
|
+
return e;
|
|
65
|
+
const n = e.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), s = new DOMParser().parseFromString(n, "text/html");
|
|
66
|
+
s.querySelectorAll(f).forEach((c) => {
|
|
67
|
+
const r = Number(c.getAttribute("recommendation-id"));
|
|
68
|
+
if (!Number.isFinite(r))
|
|
69
|
+
return;
|
|
70
|
+
const u = c.querySelectorAll(O);
|
|
71
|
+
(u.length ? Array.from(u) : [c]).forEach((d) => {
|
|
72
|
+
d.querySelectorAll(C).forEach((m, A) => {
|
|
73
|
+
t.has(`${r}_${A}`) && (w(m).textContent = "");
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
const o = (i = e.match(/<!DOCTYPE[^>]*>/i)) == null ? void 0 : i[0];
|
|
78
|
+
return ((o ? `${o}
|
|
79
|
+
` : "") + s.documentElement.outerHTML).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}");
|
|
80
|
+
}
|
|
81
|
+
function I(e) {
|
|
82
|
+
if (!e || !e.includes("recommendation-block-v2"))
|
|
83
|
+
return e;
|
|
84
|
+
const t = h(), n = new DOMParser().parseFromString(e, "text/html"), s = Array.from(n.querySelectorAll(f)), o = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set();
|
|
85
|
+
if (s.forEach((c) => {
|
|
86
|
+
var l;
|
|
87
|
+
const r = Number(c.getAttribute("recommendation-id"));
|
|
88
|
+
if (!Number.isFinite(r))
|
|
89
|
+
return;
|
|
90
|
+
const u = ((l = t.blockStates[r]) == null ? void 0 : l.recommendationProducts) ?? [];
|
|
91
|
+
u.length && P(
|
|
92
|
+
o,
|
|
93
|
+
a,
|
|
94
|
+
r,
|
|
95
|
+
u,
|
|
96
|
+
N(c),
|
|
97
|
+
c.getAttribute("hide-price") === "true"
|
|
98
|
+
);
|
|
99
|
+
}), !o.size)
|
|
100
|
+
return e;
|
|
101
|
+
let i = D(e, a);
|
|
102
|
+
return i = i.replace(
|
|
103
|
+
R,
|
|
104
|
+
(c, r) => o.has(r) ? b(o.get(r)) : c
|
|
105
|
+
), i = z(i, o), i;
|
|
106
|
+
}
|
|
107
|
+
const q = () => ({ substituteRecommendationPreview: I });
|
|
108
|
+
export {
|
|
109
|
+
I as substituteRecommendationPreview,
|
|
110
|
+
q as useRecommendationPreview
|
|
111
|
+
};
|
|
@@ -111,7 +111,7 @@ const w = [
|
|
|
111
111
|
// Scoped to REC_START/REC_END markers so it cannot strip `product-attr`
|
|
112
112
|
// from Items block elements, which the items compiler rule depends on.
|
|
113
113
|
processor: (c) => {
|
|
114
|
-
const e = /\s+(?:esd-extension-block-id|data-attribute-type|data-visibility|data-text-before|data-text-after|product-attr|composition)="[^"]*"/g;
|
|
114
|
+
const e = /\s+(?:esd-extension-block-id|data-attribute-type|data-visibility|data-text-before|data-text-after|data-same-price|product-attr|composition)="[^"]*"/g;
|
|
115
115
|
return c.replace(
|
|
116
116
|
/<!--REC_START-->([\s\S]*?)<!--REC_END-->/g,
|
|
117
117
|
(l, n) => `<!--REC_START-->${n.replace(e, "")}<!--REC_END-->`
|