@useinsider/guido 3.25.0-beta.2954d1a → 3.25.0-beta.fe154f7
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/migrator/recommendationMigrator.js +64 -78
- package/dist/package.json.js +2 -2
- package/dist/src/config/migrator/recommendation/parseLegacyConfig.d.ts +1 -1
- package/dist/src/config/migrator/recommendationMigrator.d.ts +5 -1
- package/package.json +1 -1
- package/dist/config/migrator/recommendation/inferLegacyConfig.js +0 -133
- package/dist/src/config/migrator/recommendation/inferLegacyConfig.d.ts +0 -6
|
@@ -1,71 +1,59 @@
|
|
|
1
1
|
import { BlockId as b } from "../../enums/block.js";
|
|
2
|
-
import { DEFAULT_NODE_CONFIG as
|
|
3
|
-
import { ATTR_RECOMMENDATION_TITLE as
|
|
4
|
-
import { useTemplateStore as
|
|
5
|
-
import { mapComposition as
|
|
6
|
-
import { isPriceOnNextLine as
|
|
7
|
-
import { buildBlockHtml as
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
function K(o, e, c) {
|
|
17
|
-
var g, f, u;
|
|
18
|
-
const t = $(e);
|
|
2
|
+
import { DEFAULT_NODE_CONFIG as C } from "../../extensions/Blocks/Recommendation/constants/defaultConfig.js";
|
|
3
|
+
import { ATTR_RECOMMENDATION_TITLE as f } from "../../extensions/Blocks/Recommendation/constants/selectors.js";
|
|
4
|
+
import { useTemplateStore as M } from "../../stores/template.js";
|
|
5
|
+
import { mapComposition as x } from "./recommendation/compositionMapper.js";
|
|
6
|
+
import { isPriceOnNextLine as R, extractCurrencyFromBlock as h, isOldPriceFirst as S, withRenderedTextTheme as w, extractTitleText as E, hasEmptyTitle as L, hasVisibleTitle as B, extractCardBgColor as P, isPartnerManagedBlock as A, extractRenderedBlockPadding as H } from "./recommendation/extractors.js";
|
|
7
|
+
import { buildBlockHtml as N } from "./recommendation/htmlBuilder.js";
|
|
8
|
+
import { parseRecommendationId as O, parseLegacyConfig as F } from "./recommendation/parseLegacyConfig.js";
|
|
9
|
+
import { mapSettings as I } from "./recommendation/settingsMapper.js";
|
|
10
|
+
import { mapBlockPadding as _ } from "./recommendation/themeMapper.js";
|
|
11
|
+
const k = 'td[esd-dev-product-config][class*="ins-recommendation-v3-block-"]:not(.recommendation-block-v2), td.product-block[esd-handler-name*="EmailRecommendationV3"][esd-dev-product-config]:not(.recommendation-block-v2)';
|
|
12
|
+
function $(c, e, m) {
|
|
13
|
+
var l, g, p;
|
|
14
|
+
const t = O(e);
|
|
19
15
|
if (t === null)
|
|
20
16
|
return console.warn(
|
|
21
17
|
"[RecommendationMigrator] Skipping block — missing/invalid `ins-recommendation-v3-campaign-id`"
|
|
22
18
|
), !1;
|
|
23
|
-
const
|
|
24
|
-
if (!
|
|
25
|
-
return console.warn(
|
|
26
|
-
`[RecommendationMigrator] Skipping block id=${t} — no \`esd-dev-product-config\` and no recommendationConfigs strategy to rebuild from`
|
|
27
|
-
), !1;
|
|
28
|
-
const i = s ? k(e) : F(e, t);
|
|
29
|
-
if (!i)
|
|
19
|
+
const r = F(e);
|
|
20
|
+
if (!r)
|
|
30
21
|
return console.warn(
|
|
31
|
-
`[RecommendationMigrator] Aborting block id=${t} — \`esd-dev-product-config\`
|
|
22
|
+
`[RecommendationMigrator] Aborting block id=${t} — \`esd-dev-product-config\` missing or unable to be parsed`
|
|
32
23
|
), !1;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
O(e) ? a.visibility[y] = !1 : a.titleVariable || (a.visibility[y] = N(e));
|
|
45
|
-
const v = P(e), M = {
|
|
46
|
-
...d,
|
|
24
|
+
const o = m[String(t)] ?? {}, n = {
|
|
25
|
+
...o,
|
|
26
|
+
currencySettings: o.currencySettings ?? h(e),
|
|
27
|
+
isPriceMovedToNextLine: o.isPriceMovedToNextLine ?? R(e)
|
|
28
|
+
}, a = I(n, r, t), i = x(
|
|
29
|
+
w((l = r.composition) == null ? void 0 : l.variables, e),
|
|
30
|
+
{ oldPriceFirst: S(e) }
|
|
31
|
+
), u = E(e);
|
|
32
|
+
L(e) ? i.visibility[f] = !1 : i.titleVariable || (i.visibility[f] = B(e));
|
|
33
|
+
const y = P(e), T = {
|
|
34
|
+
...a,
|
|
47
35
|
strategyId: "",
|
|
48
|
-
composition:
|
|
49
|
-
visibility:
|
|
50
|
-
previousTitleHtml:
|
|
51
|
-
textTrimming:
|
|
52
|
-
},
|
|
36
|
+
composition: i.composition,
|
|
37
|
+
visibility: i.visibility,
|
|
38
|
+
previousTitleHtml: C.previousTitleHtml,
|
|
39
|
+
textTrimming: i.anyTextTrimming
|
|
40
|
+
}, s = A(e), v = `
|
|
53
41
|
<table>
|
|
54
42
|
<tbody>
|
|
55
43
|
<tr>
|
|
56
44
|
<td class="esd-structure" align="left">
|
|
57
45
|
<table width="100%" cellpadding="0" cellspacing="0">
|
|
58
46
|
<tbody>
|
|
59
|
-
<tr>${
|
|
60
|
-
nodeConfig:
|
|
61
|
-
composition:
|
|
62
|
-
cardBg:
|
|
63
|
-
titleText:
|
|
47
|
+
<tr>${N({
|
|
48
|
+
nodeConfig: T,
|
|
49
|
+
composition: i,
|
|
50
|
+
cardBg: y,
|
|
51
|
+
titleText: u,
|
|
64
52
|
legacyId: e.getAttribute("id") ?? void 0,
|
|
65
53
|
legacyBgColor: e.getAttribute("bgcolor") ?? void 0,
|
|
66
|
-
preserveInnerHtml:
|
|
67
|
-
skipCompile:
|
|
68
|
-
blockPadding:
|
|
54
|
+
preserveInnerHtml: s ? e.innerHTML : void 0,
|
|
55
|
+
skipCompile: s,
|
|
56
|
+
blockPadding: _(((p = (g = r.theme) == null ? void 0 : g.blockPadding) == null ? void 0 : p.desktop) ?? H(e))
|
|
69
57
|
})}</tr>
|
|
70
58
|
</tbody>
|
|
71
59
|
</table>
|
|
@@ -73,42 +61,40 @@ function K(o, e, c) {
|
|
|
73
61
|
</tr>
|
|
74
62
|
</tbody>
|
|
75
63
|
</table>
|
|
76
|
-
`,
|
|
77
|
-
return !
|
|
64
|
+
`, d = c.parseFromString(v, "text/html").querySelector("td.esd-structure");
|
|
65
|
+
return !d || !e.parentNode ? (console.warn(
|
|
78
66
|
`[RecommendationMigrator] Aborting block id=${t} — failed to construct new HTML element`
|
|
79
|
-
), !1) : (e.parentNode.replaceChild(
|
|
67
|
+
), !1) : (e.parentNode.replaceChild(d, e), !0);
|
|
80
68
|
}
|
|
81
|
-
function
|
|
82
|
-
const
|
|
69
|
+
function X(c, e = {}) {
|
|
70
|
+
const m = new DOMParser();
|
|
83
71
|
let t;
|
|
84
72
|
try {
|
|
85
|
-
t =
|
|
86
|
-
} catch (
|
|
87
|
-
return console.error("[RecommendationMigrator] Failed to parse template:",
|
|
73
|
+
t = m.parseFromString(c, "text/html");
|
|
74
|
+
} catch (n) {
|
|
75
|
+
return console.error("[RecommendationMigrator] Failed to parse template:", n), c;
|
|
88
76
|
}
|
|
89
|
-
const
|
|
90
|
-
var n;
|
|
91
|
-
return !((n = r.parentElement) != null && n.closest(".recommendation-block-v2")) && !s.some((d) => d !== r && d.contains(r));
|
|
92
|
-
});
|
|
93
|
-
let i = 0;
|
|
94
|
-
m.forEach((r) => {
|
|
95
|
-
try {
|
|
96
|
-
K(c, r, e) && (i += 1);
|
|
97
|
-
} catch (n) {
|
|
98
|
-
console.error("[RecommendationMigrator] Unexpected error migrating block:", n);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
77
|
+
const r = Array.from(t.querySelectorAll(k));
|
|
101
78
|
try {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
...
|
|
105
|
-
[b.Recommendation]:
|
|
79
|
+
M().$patch((a) => {
|
|
80
|
+
a.migrations = {
|
|
81
|
+
...a.migrations,
|
|
82
|
+
[b.Recommendation]: r.length
|
|
106
83
|
};
|
|
107
84
|
});
|
|
108
85
|
} catch {
|
|
109
86
|
}
|
|
110
|
-
|
|
87
|
+
if (r.length === 0)
|
|
88
|
+
return c;
|
|
89
|
+
let o = 0;
|
|
90
|
+
return r.forEach((n) => {
|
|
91
|
+
try {
|
|
92
|
+
$(m, n, e) && (o += 1);
|
|
93
|
+
} catch (a) {
|
|
94
|
+
console.error("[RecommendationMigrator] Unexpected error migrating block:", a);
|
|
95
|
+
}
|
|
96
|
+
}), o > 0 && console.info(`[RecommendationMigrator] Migrated ${o} legacy Recommendation block(s)`), t.documentElement.outerHTML;
|
|
111
97
|
}
|
|
112
98
|
export {
|
|
113
|
-
|
|
99
|
+
X as migrateRecommendation
|
|
114
100
|
};
|
package/dist/package.json.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const o = "3.25.0-beta.
|
|
1
|
+
const o = "3.25.0-beta.fe154f7", s = { stripo: { version: "2.83.1" } }, e = {
|
|
2
2
|
version: o,
|
|
3
3
|
guido: s
|
|
4
4
|
};
|
|
5
5
|
export {
|
|
6
|
-
|
|
6
|
+
e as default,
|
|
7
7
|
s as guido,
|
|
8
8
|
o as version
|
|
9
9
|
};
|
|
@@ -3,7 +3,7 @@ import type { LegacyProductConfig } from './types';
|
|
|
3
3
|
* `esd-dev-product-config` is double-HTML-encoded JSON: serialization
|
|
4
4
|
* escapes once to embed inside the attribute, and Stripo's templating
|
|
5
5
|
* layer escapes a second time when round-tripping. Returns `null` when
|
|
6
|
-
* the attribute is
|
|
6
|
+
* the attribute is missing or unable to be parsed — the caller treats
|
|
7
7
|
* either case as an abort.
|
|
8
8
|
*/
|
|
9
9
|
export declare function parseLegacyConfig(block: Element): LegacyProductConfig | null;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Idempotent: the selector matches only blocks that have
|
|
3
|
+
* `esd-dev-product-config` AND lack `recommendation-block-v2`, so
|
|
4
|
+
* re-running on a migrated template is a no-op.
|
|
5
|
+
*/
|
|
2
6
|
import type { LegacyRecommendationConfig } from '@@/Types/config';
|
|
3
7
|
/**
|
|
4
8
|
* Migrate all legacy Recommendation Blocks in the given HTML string.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useinsider/guido",
|
|
3
|
-
"version": "3.25.0-beta.
|
|
3
|
+
"version": "3.25.0-beta.fe154f7",
|
|
4
4
|
"description": "Guido is a Vue + TypeScript wrapper for Email Plugin. Easily embed the email editor in your Vue applications.",
|
|
5
5
|
"main": "./dist/guido.umd.cjs",
|
|
6
6
|
"module": "./dist/library.js",
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { MAX_PRODUCTS_PER_ROW as _ } from "../../../extensions/Blocks/Recommendation/constants/layout.js";
|
|
2
|
-
const T = "td.product-card", x = '[class*="ext-product-"]', d = ".ext-ins-attr p[product-attr]", y = ".ext-ins-attr", S = ["font-family", "font-size", "font-weight", "font-style"], a = [
|
|
3
|
-
["p_image", ".ext-product-image"],
|
|
4
|
-
["p_name", ".ext-product-name"],
|
|
5
|
-
["p_price", ".ext-product-price"],
|
|
6
|
-
["p_original_price", ".ext-product-original-price"],
|
|
7
|
-
["p_omnibus_price", ".ext-product-omnibus-price", !0],
|
|
8
|
-
["p_omnibus_discount", ".ext-product-omnibus-discount", !0],
|
|
9
|
-
["p_button", ".ext-product-button"]
|
|
10
|
-
], l = a.map(([, t]) => t).join(", ");
|
|
11
|
-
function s(t, e) {
|
|
12
|
-
const n = new RegExp(`(?:^|;)\\s*${e}\\s*:\\s*([^;]+)`, "i"), r = ((t == null ? void 0 : t.getAttribute("style")) ?? "").match(n);
|
|
13
|
-
return (r == null ? void 0 : r[1].trim()) || void 0;
|
|
14
|
-
}
|
|
15
|
-
function p(t) {
|
|
16
|
-
return /^none\b/.test(s(t, "display") ?? "");
|
|
17
|
-
}
|
|
18
|
-
function h(t) {
|
|
19
|
-
return p(t) || p(t.closest("tr"));
|
|
20
|
-
}
|
|
21
|
-
function f(t) {
|
|
22
|
-
const e = {};
|
|
23
|
-
return S.forEach((n) => {
|
|
24
|
-
const r = s(t, n);
|
|
25
|
-
r && (e[n] = r);
|
|
26
|
-
}), Object.keys(e).length > 0 ? e : void 0;
|
|
27
|
-
}
|
|
28
|
-
function g(t) {
|
|
29
|
-
return Object.keys(t).length > 0 ? t : void 0;
|
|
30
|
-
}
|
|
31
|
-
function m(t) {
|
|
32
|
-
const e = t.querySelector("p") ?? t, n = f(e), r = s(e, "color"), i = t.getAttribute("align") ?? s(e, "text-align"), o = s(e, "line-height");
|
|
33
|
-
return g({
|
|
34
|
-
...n ? { textStyle: n } : {},
|
|
35
|
-
...r ? { textColor: { color: r } } : {},
|
|
36
|
-
...i ? { textAlign: { align: i } } : {},
|
|
37
|
-
...o ? { textLineSpacing: { lineSpacing: o } } : {}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
function A(t) {
|
|
41
|
-
var u;
|
|
42
|
-
const e = t.querySelector("a") ?? t, n = (u = e.textContent) == null ? void 0 : u.trim(), r = s(e, "background-color") ?? s(e, "background"), i = s(e, "color"), o = f(e), c = t.getAttribute("align");
|
|
43
|
-
return g({
|
|
44
|
-
...n ? { buttonText: { text: n } } : {},
|
|
45
|
-
...r ? { buttonColor: { color: r } } : {},
|
|
46
|
-
...i ? { textButtonColor: { color: i } } : {},
|
|
47
|
-
...o ? { buttonStyle: o } : {},
|
|
48
|
-
...c ? { buttonAlign: { align: c } } : {}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
function C(t) {
|
|
52
|
-
const e = t.querySelector("img"), n = Number(e == null ? void 0 : e.getAttribute("width")), r = Number(e == null ? void 0 : e.getAttribute("height")), i = { ...n > 0 ? { width: n } : {}, ...r > 0 ? { height: r } : {} };
|
|
53
|
-
return Object.keys(i).length > 0 ? { imageSize: i } : void 0;
|
|
54
|
-
}
|
|
55
|
-
function R(t, e) {
|
|
56
|
-
switch (t) {
|
|
57
|
-
case "p_image":
|
|
58
|
-
return C(e);
|
|
59
|
-
case "p_button":
|
|
60
|
-
return A(e);
|
|
61
|
-
default:
|
|
62
|
-
return m(e);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function L(t, e) {
|
|
66
|
-
const n = Array.from(t.querySelectorAll(`[class*="show-recommendation-${e}-"]`));
|
|
67
|
-
return n.length > 0 ? n : Array.from(t.querySelectorAll(T));
|
|
68
|
-
}
|
|
69
|
-
function w(t, e) {
|
|
70
|
-
const n = (o) => e.filter((c) => o.contains(c)).length;
|
|
71
|
-
let r = e[0].parentElement;
|
|
72
|
-
for (; r && r !== t && n(r) < 2; )
|
|
73
|
-
r = r.parentElement;
|
|
74
|
-
if (!r || r === t)
|
|
75
|
-
return e.length === 1 ? 1 : void 0;
|
|
76
|
-
const i = r.tagName === "TBODY" || r.tagName === "TABLE" ? 1 : n(r);
|
|
77
|
-
return Math.min(i, _);
|
|
78
|
-
}
|
|
79
|
-
function v(t) {
|
|
80
|
-
const e = Array.from(t.querySelectorAll(x)).filter((n) => !n.matches(l) && !n.querySelector(l)).flatMap((n) => Array.from(n.classList).filter((r) => r.startsWith("ext-product-")));
|
|
81
|
-
return [...new Set(e)];
|
|
82
|
-
}
|
|
83
|
-
function O(t, e, n) {
|
|
84
|
-
const r = t.closest(y) ?? t, i = m(r);
|
|
85
|
-
return {
|
|
86
|
-
variable: `p_attribute_${e}`,
|
|
87
|
-
variableType: "p_attribute",
|
|
88
|
-
value: t.getAttribute("product-attr") ?? "",
|
|
89
|
-
positionIdx: n,
|
|
90
|
-
hidden: h(r),
|
|
91
|
-
...i ? { theme: i } : {}
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
function N(t) {
|
|
95
|
-
const e = /* @__PURE__ */ new Set(), n = [];
|
|
96
|
-
let r = 0;
|
|
97
|
-
t.querySelectorAll(`${l}, ${d}`).forEach((o) => {
|
|
98
|
-
if (o.matches(d)) {
|
|
99
|
-
n.push(O(o, r, n.length)), r += 1;
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
const c = a.find(
|
|
103
|
-
([b, E]) => !e.has(b) && o.matches(E)
|
|
104
|
-
);
|
|
105
|
-
if (!c)
|
|
106
|
-
return;
|
|
107
|
-
const u = R(c[0], o);
|
|
108
|
-
e.add(c[0]), n.push({
|
|
109
|
-
variable: c[0],
|
|
110
|
-
positionIdx: n.length,
|
|
111
|
-
hidden: h(o),
|
|
112
|
-
...u ? { theme: u } : {}
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
const i = a.filter(([o, , c]) => !c && !e.has(o)).map(([o]) => ({ variable: o, hidden: !0 }));
|
|
116
|
-
return [...n, ...i];
|
|
117
|
-
}
|
|
118
|
-
function q(t, e) {
|
|
119
|
-
const n = L(t, e);
|
|
120
|
-
if (n.length === 0)
|
|
121
|
-
return null;
|
|
122
|
-
const r = v(n[0]);
|
|
123
|
-
return r.length > 0 ? (console.warn(
|
|
124
|
-
`[RecommendationMigrator] Block id=${e} — legacy card cells the rebuild cannot map: ${r.join(", ")}`
|
|
125
|
-
), null) : {
|
|
126
|
-
totalCount: n.length,
|
|
127
|
-
rowCount: w(t, n),
|
|
128
|
-
composition: { variables: N(n[0]) }
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
export {
|
|
132
|
-
q as inferLegacyConfig
|
|
133
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { LegacyProductConfig } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Rebuilds the `esd-dev-product-config` a pre-Guido block never carried from what it rendered.
|
|
4
|
-
* Null when no product card renders or a card cell cannot be mapped (the rebuild would lose it); other fields default.
|
|
5
|
-
*/
|
|
6
|
-
export declare function inferLegacyConfig(block: Element, id: number): LegacyProductConfig | null;
|