@useinsider/guido 3.24.0-beta.7275faa → 3.24.0-beta.7cfd3b1
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/recommendation/inferLegacyConfig.js +99 -0
- package/dist/config/migrator/recommendationMigrator.js +66 -59
- package/dist/package.json.js +2 -2
- package/dist/src/config/migrator/recommendation/inferLegacyConfig.d.ts +6 -0
- package/dist/src/config/migrator/recommendation/parseLegacyConfig.d.ts +1 -1
- package/dist/src/config/migrator/recommendationMigrator.d.ts +1 -5
- package/package.json +1 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const g = "td.product-card", p = "td.esd-structure.esd-extension-internal-block", h = ["font-family", "font-size", "font-weight", "font-style"], a = [
|
|
2
|
+
["p_image", ".ext-product-image"],
|
|
3
|
+
["p_name", ".ext-product-name"],
|
|
4
|
+
["p_price", ".ext-product-price"],
|
|
5
|
+
["p_original_price", ".ext-product-original-price"],
|
|
6
|
+
["p_button", ".ext-product-button"]
|
|
7
|
+
], l = a.map(([, e]) => e).join(", ");
|
|
8
|
+
function s(e, t) {
|
|
9
|
+
const n = new RegExp(`(?:^|;)\\s*${t}\\s*:\\s*([^;]+)`, "i"), o = ((e == null ? void 0 : e.getAttribute("style")) ?? "").match(n);
|
|
10
|
+
return (o == null ? void 0 : o[1].trim()) || void 0;
|
|
11
|
+
}
|
|
12
|
+
function d(e) {
|
|
13
|
+
return /^none\b/.test(s(e, "display") ?? "");
|
|
14
|
+
}
|
|
15
|
+
function f(e) {
|
|
16
|
+
const t = {};
|
|
17
|
+
return h.forEach((n) => {
|
|
18
|
+
const o = s(e, n);
|
|
19
|
+
o && (t[n] = o);
|
|
20
|
+
}), Object.keys(t).length > 0 ? t : void 0;
|
|
21
|
+
}
|
|
22
|
+
function m(e) {
|
|
23
|
+
const t = e.querySelector("p") ?? e, n = f(t), o = e.getAttribute("align") ?? s(t, "text-align"), r = s(t, "line-height");
|
|
24
|
+
if (!(!n && !o && !r))
|
|
25
|
+
return {
|
|
26
|
+
...n ? { textStyle: n } : {},
|
|
27
|
+
...o ? { textAlign: { align: o } } : {},
|
|
28
|
+
...r ? { textLineSpacing: { lineSpacing: r } } : {}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function y(e) {
|
|
32
|
+
var c;
|
|
33
|
+
const t = e.querySelector("a") ?? e, n = (c = t.textContent) == null ? void 0 : c.trim(), o = s(t, "background-color") ?? s(t, "background"), r = s(t, "color"), i = f(t), u = e.getAttribute("align");
|
|
34
|
+
return {
|
|
35
|
+
...n ? { buttonText: { text: n } } : {},
|
|
36
|
+
...o ? { buttonColor: { color: o } } : {},
|
|
37
|
+
...r ? { textButtonColor: { color: r } } : {},
|
|
38
|
+
...i ? { buttonStyle: i } : {},
|
|
39
|
+
...u ? { buttonAlign: { align: u } } : {}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function b(e) {
|
|
43
|
+
const t = e.querySelector("img"), n = Number(t == null ? void 0 : t.getAttribute("width")), o = Number(t == null ? void 0 : t.getAttribute("height")), r = { ...n > 0 ? { width: n } : {}, ...o > 0 ? { height: o } : {} };
|
|
44
|
+
return Object.keys(r).length > 0 ? { imageSize: r } : void 0;
|
|
45
|
+
}
|
|
46
|
+
function x(e, t) {
|
|
47
|
+
switch (e) {
|
|
48
|
+
case "p_image":
|
|
49
|
+
return b(t);
|
|
50
|
+
case "p_button":
|
|
51
|
+
return y(t);
|
|
52
|
+
default:
|
|
53
|
+
return m(t);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function E(e, t) {
|
|
57
|
+
const n = Array.from(e.querySelectorAll(`[class*="show-recommendation-${t}-"]`));
|
|
58
|
+
return n.length > 0 ? n : Array.from(e.querySelectorAll(g));
|
|
59
|
+
}
|
|
60
|
+
function S(e) {
|
|
61
|
+
const t = e[0].closest(p) ?? e[0].closest("tr");
|
|
62
|
+
return t ? e.filter((n) => t.contains(n)).length : void 0;
|
|
63
|
+
}
|
|
64
|
+
function A(e, t) {
|
|
65
|
+
const n = Array.from(e.querySelectorAll('[class*="ext-product-"]')).filter((o) => !o.matches(l) && !o.closest(l)).flatMap((o) => Array.from(o.classList).filter((r) => r.startsWith("ext-product-")));
|
|
66
|
+
n.length > 0 && console.info(
|
|
67
|
+
`[RecommendationMigrator] Block id=${t} — legacy card cells left out of the rebuild: ${[...new Set(n)].join(", ")}`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
function _(e) {
|
|
71
|
+
const t = /* @__PURE__ */ new Map();
|
|
72
|
+
e.querySelectorAll(l).forEach((r) => {
|
|
73
|
+
const i = a.find(
|
|
74
|
+
([u, c]) => !t.has(u) && r.matches(c)
|
|
75
|
+
);
|
|
76
|
+
i && t.set(i[0], r);
|
|
77
|
+
});
|
|
78
|
+
const n = Array.from(t, ([r, i], u) => {
|
|
79
|
+
const c = x(r, i);
|
|
80
|
+
return {
|
|
81
|
+
variable: r,
|
|
82
|
+
positionIdx: u,
|
|
83
|
+
hidden: d(i) || d(i.closest("tr")),
|
|
84
|
+
...c ? { theme: c } : {}
|
|
85
|
+
};
|
|
86
|
+
}), o = a.filter(([r]) => !t.has(r)).map(([r]) => ({ variable: r, hidden: !0 }));
|
|
87
|
+
return [...n, ...o];
|
|
88
|
+
}
|
|
89
|
+
function T(e, t) {
|
|
90
|
+
const n = E(e, t);
|
|
91
|
+
return n.length === 0 ? null : (A(n[0], t), {
|
|
92
|
+
totalCount: n.length,
|
|
93
|
+
rowCount: S(n),
|
|
94
|
+
composition: { variables: _(n[0]) }
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
export {
|
|
98
|
+
T as inferLegacyConfig
|
|
99
|
+
};
|
|
@@ -1,59 +1,63 @@
|
|
|
1
|
-
import { BlockId as
|
|
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
|
-
|
|
1
|
+
import { BlockId as h } from "../../enums/block.js";
|
|
2
|
+
import { DEFAULT_NODE_CONFIG as M } from "../../extensions/Blocks/Recommendation/constants/defaultConfig.js";
|
|
3
|
+
import { ATTR_RECOMMENDATION_TITLE as u } from "../../extensions/Blocks/Recommendation/constants/selectors.js";
|
|
4
|
+
import { useTemplateStore as R } from "../../stores/template.js";
|
|
5
|
+
import { mapComposition as b } from "./recommendation/compositionMapper.js";
|
|
6
|
+
import { isPriceOnNextLine as x, extractCurrencyFromBlock as A, isOldPriceFirst as E, withRenderedTextTheme as L, extractTitleText as w, hasEmptyTitle as S, hasVisibleTitle as B, extractCardBgColor as P, isPartnerManagedBlock as H, extractRenderedBlockPadding as N } from "./recommendation/extractors.js";
|
|
7
|
+
import { buildBlockHtml as O } from "./recommendation/htmlBuilder.js";
|
|
8
|
+
import { inferLegacyConfig as F } from "./recommendation/inferLegacyConfig.js";
|
|
9
|
+
import { parseRecommendationId as I, parseLegacyConfig as _ } from "./recommendation/parseLegacyConfig.js";
|
|
10
|
+
import { mapSettings as $ } from "./recommendation/settingsMapper.js";
|
|
11
|
+
import { mapBlockPadding as k } from "./recommendation/themeMapper.js";
|
|
12
|
+
const D = 'td[class*="ins-recommendation-v3-block-"]:not(.recommendation-block-v2), td.product-block[esd-handler-name*="EmailRecommendationV3"]:not(.recommendation-block-v2)', G = "esd-dev-product-config";
|
|
13
|
+
function V(c, e, m) {
|
|
14
|
+
var p, g, f;
|
|
15
|
+
const t = I(e);
|
|
15
16
|
if (t === null)
|
|
16
17
|
return console.warn(
|
|
17
18
|
"[RecommendationMigrator] Skipping block — missing/invalid `ins-recommendation-v3-campaign-id`"
|
|
18
19
|
), !1;
|
|
19
|
-
const
|
|
20
|
-
if (!
|
|
20
|
+
const s = e.hasAttribute(G), n = s ? _(e) : F(e, t);
|
|
21
|
+
if (!n)
|
|
21
22
|
return console.warn(
|
|
22
|
-
`[RecommendationMigrator] Aborting block id=${t} — \`esd-dev-product-config\`
|
|
23
|
+
`[RecommendationMigrator] Aborting block id=${t} — \`esd-dev-product-config\` empty or unparsable, or missing with no rendered product cards`
|
|
23
24
|
), !1;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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 = {
|
|
25
|
+
s || console.info(
|
|
26
|
+
`[RecommendationMigrator] Block id=${t} has no \`esd-dev-product-config\` — rebuilt from its rendered markup`
|
|
27
|
+
);
|
|
28
|
+
const a = m[String(t)] ?? {}, r = {
|
|
34
29
|
...a,
|
|
30
|
+
currencySettings: a.currencySettings ?? A(e),
|
|
31
|
+
isPriceMovedToNextLine: a.isPriceMovedToNextLine ?? x(e)
|
|
32
|
+
}, i = $(r, n, t), o = b(
|
|
33
|
+
L((p = n.composition) == null ? void 0 : p.variables, e),
|
|
34
|
+
{ oldPriceFirst: E(e) }
|
|
35
|
+
), y = w(e);
|
|
36
|
+
S(e) ? o.visibility[u] = !1 : o.titleVariable || (o.visibility[u] = B(e));
|
|
37
|
+
const T = P(e), v = {
|
|
38
|
+
...i,
|
|
35
39
|
strategyId: "",
|
|
36
|
-
composition:
|
|
37
|
-
visibility:
|
|
38
|
-
previousTitleHtml:
|
|
39
|
-
textTrimming:
|
|
40
|
-
},
|
|
40
|
+
composition: o.composition,
|
|
41
|
+
visibility: o.visibility,
|
|
42
|
+
previousTitleHtml: M.previousTitleHtml,
|
|
43
|
+
textTrimming: o.anyTextTrimming
|
|
44
|
+
}, d = H(e), C = `
|
|
41
45
|
<table>
|
|
42
46
|
<tbody>
|
|
43
47
|
<tr>
|
|
44
48
|
<td class="esd-structure" align="left">
|
|
45
49
|
<table width="100%" cellpadding="0" cellspacing="0">
|
|
46
50
|
<tbody>
|
|
47
|
-
<tr>${
|
|
48
|
-
nodeConfig:
|
|
49
|
-
composition:
|
|
50
|
-
cardBg:
|
|
51
|
-
titleText:
|
|
51
|
+
<tr>${O({
|
|
52
|
+
nodeConfig: v,
|
|
53
|
+
composition: o,
|
|
54
|
+
cardBg: T,
|
|
55
|
+
titleText: y,
|
|
52
56
|
legacyId: e.getAttribute("id") ?? void 0,
|
|
53
57
|
legacyBgColor: e.getAttribute("bgcolor") ?? void 0,
|
|
54
|
-
preserveInnerHtml:
|
|
55
|
-
skipCompile:
|
|
56
|
-
blockPadding:
|
|
58
|
+
preserveInnerHtml: d ? e.innerHTML : void 0,
|
|
59
|
+
skipCompile: d,
|
|
60
|
+
blockPadding: k(((f = (g = n.theme) == null ? void 0 : g.blockPadding) == null ? void 0 : f.desktop) ?? N(e))
|
|
57
61
|
})}</tr>
|
|
58
62
|
</tbody>
|
|
59
63
|
</table>
|
|
@@ -61,40 +65,43 @@ function $(c, e, m) {
|
|
|
61
65
|
</tr>
|
|
62
66
|
</tbody>
|
|
63
67
|
</table>
|
|
64
|
-
`,
|
|
65
|
-
return !
|
|
68
|
+
`, l = c.parseFromString(C, "text/html").querySelector("td.esd-structure");
|
|
69
|
+
return !l || !e.parentNode ? (console.warn(
|
|
66
70
|
`[RecommendationMigrator] Aborting block id=${t} — failed to construct new HTML element`
|
|
67
|
-
), !1) : (e.parentNode.replaceChild(
|
|
71
|
+
), !1) : (e.parentNode.replaceChild(l, e), !0);
|
|
68
72
|
}
|
|
69
|
-
function
|
|
73
|
+
function re(c, e = {}) {
|
|
70
74
|
const m = new DOMParser();
|
|
71
75
|
let t;
|
|
72
76
|
try {
|
|
73
77
|
t = m.parseFromString(c, "text/html");
|
|
74
|
-
} catch (
|
|
75
|
-
return console.error("[RecommendationMigrator] Failed to parse template:",
|
|
78
|
+
} catch (r) {
|
|
79
|
+
return console.error("[RecommendationMigrator] Failed to parse template:", r), c;
|
|
76
80
|
}
|
|
77
|
-
const
|
|
81
|
+
const s = Array.from(t.querySelectorAll(D)), n = s.filter((r) => {
|
|
82
|
+
var i;
|
|
83
|
+
return !((i = r.parentElement) != null && i.closest(".recommendation-block-v2")) && !s.some((o) => o !== r && o.contains(r));
|
|
84
|
+
});
|
|
78
85
|
try {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
...
|
|
82
|
-
[
|
|
86
|
+
R().$patch((i) => {
|
|
87
|
+
i.migrations = {
|
|
88
|
+
...i.migrations,
|
|
89
|
+
[h.Recommendation]: n.length
|
|
83
90
|
};
|
|
84
91
|
});
|
|
85
92
|
} catch {
|
|
86
93
|
}
|
|
87
|
-
if (
|
|
94
|
+
if (n.length === 0)
|
|
88
95
|
return c;
|
|
89
|
-
let
|
|
90
|
-
return
|
|
96
|
+
let a = 0;
|
|
97
|
+
return n.forEach((r) => {
|
|
91
98
|
try {
|
|
92
|
-
|
|
93
|
-
} catch (
|
|
94
|
-
console.error("[RecommendationMigrator] Unexpected error migrating block:",
|
|
99
|
+
V(m, r, e) && (a += 1);
|
|
100
|
+
} catch (i) {
|
|
101
|
+
console.error("[RecommendationMigrator] Unexpected error migrating block:", i);
|
|
95
102
|
}
|
|
96
|
-
}),
|
|
103
|
+
}), a > 0 && console.info(`[RecommendationMigrator] Migrated ${a} legacy Recommendation block(s)`), t.documentElement.outerHTML;
|
|
97
104
|
}
|
|
98
105
|
export {
|
|
99
|
-
|
|
106
|
+
re as migrateRecommendation
|
|
100
107
|
};
|
package/dist/package.json.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const o = "3.24.0-beta.
|
|
1
|
+
const o = "3.24.0-beta.7cfd3b1", s = { stripo: { version: "2.83.1" } }, t = {
|
|
2
2
|
version: o,
|
|
3
3
|
guido: s
|
|
4
4
|
};
|
|
5
5
|
export {
|
|
6
|
-
|
|
6
|
+
t as default,
|
|
7
7
|
s as guido,
|
|
8
8
|
o as version
|
|
9
9
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LegacyProductConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Rebuilds the `esd-dev-product-config` a pre-Guido block never carried from what it rendered (SD-158005).
|
|
4
|
+
* Null when no product card renders (nothing to infer from); other unanswered fields stay undefined for the defaults.
|
|
5
|
+
*/
|
|
6
|
+
export declare function inferLegacyConfig(block: Element, id: number): LegacyProductConfig | null;
|
|
@@ -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 empty 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,8 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
/** Idempotent: the selector excludes `recommendation-block-v2`, so re-running on a migrated template is a no-op. */
|
|
6
2
|
import type { LegacyRecommendationConfig } from '@@/Types/config';
|
|
7
3
|
/**
|
|
8
4
|
* 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.24.0-beta.
|
|
3
|
+
"version": "3.24.0-beta.7cfd3b1",
|
|
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",
|