@useinsider/guido 3.25.0-beta.2954d1a → 3.25.0-beta.8e042c8

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.
@@ -1,71 +1,59 @@
1
1
  import { BlockId as b } from "../../enums/block.js";
2
- import { DEFAULT_NODE_CONFIG as h } from "../../extensions/Blocks/Recommendation/constants/defaultConfig.js";
3
- import { ATTR_RECOMMENDATION_TITLE as y } from "../../extensions/Blocks/Recommendation/constants/selectors.js";
4
- import { useTemplateStore as x } from "../../stores/template.js";
5
- import { mapComposition as S } from "./recommendation/compositionMapper.js";
6
- import { isPriceOnNextLine as L, extractCurrencyFromBlock as A, isOldPriceFirst as B, withRenderedTextTheme as E, extractTitleText as w, hasEmptyTitle as O, hasVisibleTitle as N, extractCardBgColor as P, isPartnerManagedBlock as H, extractRenderedBlockPadding as I } from "./recommendation/extractors.js";
7
- import { buildBlockHtml as _ } from "./recommendation/htmlBuilder.js";
8
- import { inferLegacyConfig as F } from "./recommendation/inferLegacyConfig.js";
9
- import { parseRecommendationId as $, parseLegacyConfig as k } from "./recommendation/parseLegacyConfig.js";
10
- import { mapSettings as D } from "./recommendation/settingsMapper.js";
11
- import { mapBlockPadding as G } from "./recommendation/themeMapper.js";
12
- const T = ":not(.recommendation-block-v2):not([esd-ext-config])", U = `td[class*="ins-recommendation-v3-block-"]${T}, td.product-block[esd-handler-name*="EmailRecommendationV3"]${T}`, V = "esd-dev-product-config";
13
- function q(o) {
14
- return !!(o != null && o.strategy);
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 s = e.hasAttribute(V), m = c[String(t)];
24
- if (!s && !q(m))
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\` empty or unparsable, or the rendered markup could not be inferred`
22
+ `[RecommendationMigrator] Aborting block id=${t} — \`esd-dev-product-config\` missing or unable to be parsed`
32
23
  ), !1;
33
- s || console.info(
34
- `[RecommendationMigrator] Block id=${t} has no \`esd-dev-product-config\` — rebuilt from its rendered markup`
35
- );
36
- const r = m ?? {}, n = {
37
- ...r,
38
- currencySettings: r.currencySettings ?? A(e),
39
- isPriceMovedToNextLine: r.isPriceMovedToNextLine ?? L(e)
40
- }, d = D(n, i, t), a = S(
41
- E((g = i.composition) == null ? void 0 : g.variables, e),
42
- { oldPriceFirst: B(e) }
43
- ), C = w(e);
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: a.composition,
49
- visibility: a.visibility,
50
- previousTitleHtml: h.previousTitleHtml,
51
- textTrimming: a.anyTextTrimming
52
- }, l = H(e), R = `
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: M,
61
- composition: a,
62
- cardBg: v,
63
- titleText: C,
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: l ? e.innerHTML : void 0,
67
- skipCompile: l,
68
- blockPadding: G(((u = (f = i.theme) == null ? void 0 : f.blockPadding) == null ? void 0 : u.desktop) ?? I(e))
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
- `, p = o.parseFromString(R, "text/html").querySelector("td.esd-structure");
77
- return !p || !e.parentNode ? (console.warn(
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(p, e), !0);
67
+ ), !1) : (e.parentNode.replaceChild(d, e), !0);
80
68
  }
81
- function ne(o, e = {}) {
82
- const c = new DOMParser();
69
+ function X(c, e = {}) {
70
+ const m = new DOMParser();
83
71
  let t;
84
72
  try {
85
- t = c.parseFromString(o, "text/html");
86
- } catch (r) {
87
- return console.error("[RecommendationMigrator] Failed to parse template:", r), o;
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 s = Array.from(t.querySelectorAll(U)), m = s.filter((r) => {
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
- x().$patch((n) => {
103
- n.migrations = {
104
- ...n.migrations,
105
- [b.Recommendation]: i
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
- return i === 0 ? o : (console.info(`[RecommendationMigrator] Migrated ${i} legacy Recommendation block(s)`), t.documentElement.outerHTML);
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
- ne as migrateRecommendation
99
+ X as migrateRecommendation
114
100
  };
@@ -1,9 +1,9 @@
1
- const o = "3.25.0-beta.2954d1a", s = { stripo: { version: "2.83.1" } }, t = {
1
+ const o = "3.25.0-beta.8e042c8", s = { stripo: { version: "2.83.1" } }, e = {
2
2
  version: o,
3
3
  guido: s
4
4
  };
5
5
  export {
6
- t as default,
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 empty or unable to be parsed — the caller treats
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
- /** Idempotent: the selector excludes `recommendation-block-v2`, so re-running on a migrated template is a no-op. */
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.2954d1a",
3
+ "version": "3.25.0-beta.8e042c8",
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;