@useinsider/guido 3.2.0-beta.e0b6612 → 3.2.0-beta.e0e56ef

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.
Files changed (56) hide show
  1. package/dist/@types/config/schemas.js +150 -94
  2. package/dist/components/Guido.vue.js +1 -1
  3. package/dist/components/Guido.vue2.js +88 -87
  4. package/dist/config/migrator/index.js +9 -9
  5. package/dist/config/migrator/radioButtonMigrator.js +44 -64
  6. package/dist/config/migrator/recommendation/compositionMapper.js +98 -0
  7. package/dist/config/migrator/recommendation/extractors.js +27 -0
  8. package/dist/config/migrator/recommendation/htmlBuilder.js +496 -0
  9. package/dist/config/migrator/recommendation/parseLegacyConfig.js +33 -0
  10. package/dist/config/migrator/recommendation/settingsMapper.js +78 -0
  11. package/dist/config/migrator/recommendation/themeMapper.js +93 -0
  12. package/dist/config/migrator/recommendationMigrator.js +74 -290
  13. package/dist/enums/extensions/recommendationBlock.js +2 -1
  14. package/dist/extensions/Blocks/RadioButton/template.js +1 -1
  15. package/dist/extensions/Blocks/Recommendation/block.js +35 -32
  16. package/dist/extensions/Blocks/Recommendation/constants/defaultConfig.js +5 -5
  17. package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +228 -181
  18. package/dist/extensions/Blocks/Recommendation/services/configService.js +65 -29
  19. package/dist/extensions/Blocks/Recommendation/templates/grid/template.js +8 -8
  20. package/dist/extensions/Blocks/Recommendation/templates/utils.js +1 -1
  21. package/dist/extensions/Blocks/Recommendation/utils/preserveTextStyles.js +13 -22
  22. package/dist/guido.css +1 -1
  23. package/dist/node_modules/valibot/dist/index.js +450 -235
  24. package/dist/src/@types/config/defaults.d.ts +5 -1
  25. package/dist/src/@types/config/index.d.ts +3 -3
  26. package/dist/src/@types/config/schemas.d.ts +213 -0
  27. package/dist/src/@types/config/types.d.ts +9 -1
  28. package/dist/src/components/wrappers/WpModal.vue.d.ts +1 -1
  29. package/dist/src/composables/useConfig.d.ts +56 -0
  30. package/dist/src/config/migrator/index.d.ts +2 -1
  31. package/dist/src/config/migrator/recommendation/compositionMapper.d.ts +2 -0
  32. package/dist/src/config/migrator/recommendation/compositionMapper.test.d.ts +1 -0
  33. package/dist/src/config/migrator/recommendation/extractors.d.ts +7 -0
  34. package/dist/src/config/migrator/recommendation/extractors.test.d.ts +1 -0
  35. package/dist/src/config/migrator/recommendation/htmlBuilder.d.ts +11 -0
  36. package/dist/src/config/migrator/recommendation/parseLegacyConfig.d.ts +15 -0
  37. package/dist/src/config/migrator/recommendation/parseLegacyConfig.test.d.ts +1 -0
  38. package/dist/src/config/migrator/recommendation/settingsMapper.d.ts +7 -0
  39. package/dist/src/config/migrator/recommendation/settingsMapper.test.d.ts +1 -0
  40. package/dist/src/config/migrator/recommendation/themeMapper.d.ts +5 -0
  41. package/dist/src/config/migrator/recommendation/themeMapper.test.d.ts +1 -0
  42. package/dist/src/config/migrator/recommendation/types.d.ts +205 -0
  43. package/dist/src/config/migrator/recommendationMigrator.d.ts +13 -1
  44. package/dist/src/config/migrator/recommendationMigrator.test.d.ts +1 -0
  45. package/dist/src/extensions/Blocks/RadioButton/template.d.ts +1 -1
  46. package/dist/src/extensions/Blocks/Recommendation/controls/main/utils.test.d.ts +1 -0
  47. package/dist/src/extensions/Blocks/Recommendation/services/configService.d.ts +10 -0
  48. package/dist/src/extensions/Blocks/Recommendation/services/configService.test.d.ts +1 -0
  49. package/dist/src/extensions/Blocks/Recommendation/types/nodeConfig.d.ts +1 -1
  50. package/dist/src/extensions/Blocks/Recommendation/utils/preserveTextStyles.d.ts +0 -3
  51. package/dist/src/stores/config.d.ts +504 -0
  52. package/dist/src/utils/htmlEscape.d.ts +5 -0
  53. package/dist/src/utils/htmlEscape.test.d.ts +1 -0
  54. package/dist/utils/htmlEscape.js +13 -0
  55. package/package.json +5 -1
  56. package/dist/extensions/Blocks/Recommendation/templates/grid/migration.js +0 -251
@@ -1,54 +1,34 @@
1
1
  var x = Object.defineProperty;
2
- var T = (l, e, t) => e in l ? x(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
3
- var b = (l, e, t) => T(l, typeof e != "symbol" ? e + "" : e, t);
4
- import S from "../../extensions/Blocks/RadioButton/template.js";
5
- class B {
2
+ var f = (r, t, e) => t in r ? x(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var b = (r, t, e) => f(r, typeof t != "symbol" ? t + "" : t, e);
4
+ import h from "../../extensions/Blocks/RadioButton/template.js";
5
+ class T {
6
6
  constructor() {
7
7
  b(this, "parser");
8
8
  this.parser = new DOMParser();
9
9
  }
10
- migrate(e) {
10
+ migrate(t) {
11
11
  try {
12
- const t = this.parser.parseFromString(e, "text/html"), i = t.querySelectorAll("td.radio-button-block"), s = t.querySelectorAll("td.radio-button-v2");
13
- if (i.length === 0 && s.length === 0)
14
- return e;
15
- let o = !1;
16
- return i.forEach((r) => {
17
- if (r.classList.contains("radio-button-v2"))
12
+ const e = this.parser.parseFromString(t, "text/html"), i = e.querySelectorAll("td.radio-button-block");
13
+ return i.length === 0 ? t : (i.forEach((s) => {
14
+ if (s.classList.contains("radio-button-v2"))
18
15
  return;
19
- const n = r.getAttribute("id"), a = this.extractTextFromElement(r, "ins-title"), g = this.extractTextFromElement(r, "ins-description"), c = this.extractTextFromElement(r, "ins-subscribe"), u = this.extractTextFromElement(r, "ins-unsubscribe"), d = this.buildTextBlock(a), p = this.buildTextBlock(g), y = this.buildTextBlock({ ...c, classList: "" }), f = this.buildTextBlock({ ...u, classList: "" }), h = S.replace("{-{-TITLE-}-}", d).replace("{-{-DESCRIPTION-}-}", p).replace("{-{-YES-}-}", y).replace("{-{-NO-}-}", f), m = this.parser.parseFromString(
20
- `<table id="tempDoc"><tbody><tr>${h}</tr></tbody></table>`,
16
+ const n = s.getAttribute("id"), l = this.extractTextFromElement(s, "ins-title"), a = this.extractTextFromElement(s, "ins-description"), p = this.extractTextFromElement(s, "ins-subscribe"), u = this.extractTextFromElement(s, "ins-unsubscribe"), d = this.buildTextBlock(l), g = this.buildTextBlock(a), m = this.buildTextBlock({ ...p, classList: "" }), o = this.buildTextBlock({ ...u, classList: "" }), c = h.replace("{-{-TITLE-}-}", d).replace("{-{-DESCRIPTION-}-}", g).replace("{-{-YES-}-}", m).replace("{-{-NO-}-}", o), y = this.parser.parseFromString(
17
+ `<table id="tempDoc"><tbody><tr>${c}</tr></tbody></table>`,
21
18
  "text/html"
22
19
  ).querySelector(".radio-button-v2");
23
- m && r.parentNode && (m.setAttribute("id", n || ""), r.parentNode.replaceChild(m, r), o = !0);
24
- }), o = this.healRadioButtonV2(t) || o, o ? t.documentElement.outerHTML : e;
25
- } catch (t) {
26
- return console.error("RadioButtonMigrator failed:", t), e;
20
+ y && s.parentNode && (y.setAttribute("id", n || ""), s.parentNode.replaceChild(y, s));
21
+ }), e.documentElement.outerHTML);
22
+ } catch (e) {
23
+ return console.error("RadioButtonMigrator failed:", e), t;
27
24
  }
28
25
  }
29
- healRadioButtonV2(e) {
30
- let t = !1;
31
- return e.querySelectorAll("td.radio-button-v2").forEach((i) => {
32
- var p;
33
- const s = i.querySelector("input#radioYes"), o = i.querySelector("input#radioNo");
34
- if (!s || !o)
35
- return;
36
- const r = ((p = s.parentElement) == null ? void 0 : p.querySelector(":scope > p")) || null;
37
- if (!r && !s.hasAttribute("align"))
38
- return;
39
- const n = s.closest("tr"), a = o.closest("tr");
40
- if (!n || !a || n === a || !n.parentNode)
41
- return;
42
- const g = (r == null ? void 0 : r.innerHTML.trim()) || "Yes", c = a.cloneNode(!0), u = c.querySelector("input#radioNo"), d = c.querySelector("p");
43
- u && (u.setAttribute("id", "radioYes"), u.removeAttribute("align")), d && (d.innerHTML = g), n.parentNode.replaceChild(c, n), t = !0;
44
- }), t;
45
- }
46
- extractTextFromElement(e, t) {
47
- var p, y;
48
- const i = e.querySelector(`.${t}`);
26
+ extractTextFromElement(t, e) {
27
+ var o, c;
28
+ const i = t.querySelector(`.${e}`);
49
29
  if (!i)
50
30
  return {
51
- text: t === "ins-title" ? "Title" : "Description",
31
+ text: e === "ins-title" ? "Title" : "Description",
52
32
  isBold: !1,
53
33
  isItalic: !1,
54
34
  align: "left",
@@ -58,51 +38,51 @@ class B {
58
38
  const s = i.querySelector("p");
59
39
  if (!s)
60
40
  return {
61
- text: ((p = i.textContent) == null ? void 0 : p.trim()) || (t === "ins-title" ? "Title" : "Description"),
41
+ text: ((o = i.textContent) == null ? void 0 : o.trim()) || (e === "ins-title" ? "Title" : "Description"),
62
42
  isBold: !1,
63
43
  isItalic: !1,
64
44
  align: i.getAttribute("align") || "left",
65
45
  styles: "",
66
46
  classList: ""
67
47
  };
68
- const o = ((y = s.textContent) == null ? void 0 : y.trim()) || (t === "ins-title" ? "Title" : "Description"), r = s.getAttribute("style") || "", n = i.getAttribute("align") || s.getAttribute("align") || "left", a = /font-weight\s*:\s*bold/i.test(r) || !!s.querySelector("b, strong"), g = /font-style\s*:\s*italic/i.test(r) || !!s.querySelector("i, em"), c = this.removeStyleProperties(r, ["font-weight", "font-style"]), u = this.convertInlineToBlock(c), d = i.getAttribute("class") || "";
48
+ const n = ((c = s.textContent) == null ? void 0 : c.trim()) || (e === "ins-title" ? "Title" : "Description"), l = s.getAttribute("style") || "", a = i.getAttribute("align") || s.getAttribute("align") || "left", p = /font-weight\s*:\s*bold/i.test(l) || !!s.querySelector("b, strong"), u = /font-style\s*:\s*italic/i.test(l) || !!s.querySelector("i, em"), d = this.removeStyleProperties(l, ["font-weight", "font-style"]), g = this.convertInlineToBlock(d), m = i.getAttribute("class") || "";
69
49
  return {
70
- text: o,
71
- isBold: a,
72
- isItalic: g,
73
- align: n,
74
- styles: u,
75
- classList: d
50
+ text: n,
51
+ isBold: p,
52
+ isItalic: u,
53
+ align: a,
54
+ styles: g,
55
+ classList: m
76
56
  };
77
57
  }
78
- buildTextBlock(e) {
79
- let t = e.text;
80
- e.isBold && e.isItalic ? t = `<strong path="1,0"><em path="1,0,0">${t}</em></strong>` : e.isBold ? t = `<strong path="1,0">${t}</strong>` : e.isItalic && (t = `<em path="1,0">${t}</em>`);
81
- const i = e.align ? ` align="${e.align}"` : "", s = e.styles ? ` style="${e.styles.replaceAll('"', "'")}"` : "";
58
+ buildTextBlock(t) {
59
+ let e = t.text;
60
+ t.isBold && t.isItalic ? e = `<strong path="1,0"><em path="1,0,0">${e}</em></strong>` : t.isBold ? e = `<strong path="1,0">${e}</strong>` : t.isItalic && (e = `<em path="1,0">${e}</em>`);
61
+ const i = t.align ? ` align="${t.align}"` : "", s = t.styles ? ` style="${t.styles.replaceAll('"', "'")}"` : "";
82
62
  return `
83
- <td class="esd-block-text ${e.classList}" ${i}>
63
+ <td class="esd-block-text ${t.classList}" ${i}>
84
64
  <p path="1" ${s}>
85
- ${t}
65
+ ${e}
86
66
  </p>
87
67
  </td>
88
68
  `;
89
69
  }
90
- removeStyleProperties(e, t) {
91
- return e ? t.reduce((s, o) => {
92
- const r = new RegExp(`${o}\\s*:\\s*[^;]*;?`, "gi");
93
- return s.replace(r, "");
94
- }, e).replace(/;\s*;/g, ";").replace(/^;|;$/g, "").trim() : "";
70
+ removeStyleProperties(t, e) {
71
+ return t ? e.reduce((s, n) => {
72
+ const l = new RegExp(`${n}\\s*:\\s*[^;]*;?`, "gi");
73
+ return s.replace(l, "");
74
+ }, t).replace(/;\s*;/g, ";").replace(/^;|;$/g, "").trim() : "";
95
75
  }
96
- convertInlineToBlock(e) {
97
- if (!e)
76
+ convertInlineToBlock(t) {
77
+ if (!t)
98
78
  return "";
99
- let t = e.replace(/display\s*:\s*inline/gi, "display: block");
100
- return /display\s*:/i.test(t) || (t = t ? `${t}; display: block` : "display: block"), t.replace(/;\s*;/g, ";").replace(/^;|;$/g, "").trim();
79
+ let e = t.replace(/display\s*:\s*inline/gi, "display: block");
80
+ return /display\s*:/i.test(e) || (e = e ? `${e}; display: block` : "display: block"), e.replace(/;\s*;/g, ";").replace(/^;|;$/g, "").trim();
101
81
  }
102
82
  }
103
- function q(l) {
104
- return new B().migrate(l);
83
+ function A(r) {
84
+ return new T().migrate(r);
105
85
  }
106
86
  export {
107
- q as migrateRadioButton
87
+ A as migrateRadioButton
108
88
  };
@@ -0,0 +1,98 @@
1
+ import { DEFAULT_COMPOSITION as d, DEFAULT_VISIBILITY as I } from "../../../extensions/Blocks/Recommendation/constants/defaultConfig.js";
2
+ import { ATTR_CUSTOM_PREFIX as l, ATTR_PRODUCT_BUTTON as k, ATTR_PRODUCT_OMNIBUS_DISCOUNT as A, ATTR_PRODUCT_OMNIBUS_PRICE as x, ATTR_PRODUCT_OLD_PRICE as f, ATTR_PRODUCT_PRICE as R, ATTR_PRODUCT_NAME as h, ATTR_PRODUCT_IMAGE as y } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
3
+ import { mapTextTheme as E, mapButtonTheme as O, mapImageTheme as b } from "./themeMapper.js";
4
+ const C = "__title__", a = "product_attribute.";
5
+ function N(r) {
6
+ const t = r.variable ?? "";
7
+ switch (t) {
8
+ case "p_recommendation_title":
9
+ return { key: C, kind: "title" };
10
+ case "p_image":
11
+ return { key: y, kind: "image" };
12
+ case "p_name":
13
+ return { key: h, kind: "text" };
14
+ case "p_price":
15
+ return { key: R, kind: "text" };
16
+ case "p_original_price":
17
+ return { key: f, kind: "text" };
18
+ case "p_omnibus_price":
19
+ return { key: x, kind: "text" };
20
+ case "p_omnibus_discount":
21
+ return { key: A, kind: "text" };
22
+ case "p_button":
23
+ return { key: k, kind: "button" };
24
+ default:
25
+ if (r.variableType === "p_attribute" || t.startsWith("p_attribute_")) {
26
+ const s = r.value ?? "", o = s.startsWith(a) ? s.slice(a.length) : s;
27
+ return o ? {
28
+ key: `${l}${o}`,
29
+ kind: "custom",
30
+ customAttrName: o,
31
+ customAttrValue: s || `${a}${o}`
32
+ } : null;
33
+ }
34
+ return null;
35
+ }
36
+ }
37
+ function p(r) {
38
+ const t = d.indexOf(r);
39
+ return t === -1 ? Number.POSITIVE_INFINITY : t;
40
+ }
41
+ function S(r) {
42
+ const t = {
43
+ composition: [],
44
+ visibility: { ...I },
45
+ customAttributes: [],
46
+ customAttrValues: {},
47
+ perElementStyles: {},
48
+ anyTextTrimming: !1
49
+ };
50
+ if (!r || r.length === 0)
51
+ return t.composition = [...d], t;
52
+ const s = [];
53
+ r.forEach((e, i) => {
54
+ const n = N(e);
55
+ if (n) {
56
+ if (n.kind === "title") {
57
+ t.titleVariable = e;
58
+ return;
59
+ }
60
+ s.push({
61
+ key: n.key,
62
+ kind: n.kind,
63
+ hidden: e.hidden === !0,
64
+ positionIdx: typeof e.positionIdx == "number" ? e.positionIdx : Number.MAX_SAFE_INTEGER,
65
+ legacy: e,
66
+ customAttrName: n.customAttrName,
67
+ customAttrValue: n.customAttrValue,
68
+ originalIndex: i
69
+ });
70
+ }
71
+ }), s.sort((e, i) => {
72
+ if (e.positionIdx !== i.positionIdx)
73
+ return e.positionIdx - i.positionIdx;
74
+ const n = p(e.key), u = p(i.key);
75
+ return n !== u ? n - u : e.originalIndex - i.originalIndex;
76
+ });
77
+ const o = {};
78
+ return s.forEach((e) => {
79
+ const { key: i, kind: n, hidden: u, legacy: m, customAttrName: c, customAttrValue: T } = e;
80
+ switch (t.composition.push(i), t.visibility[i] = !u, n === "custom" && c && T && (t.customAttributes.includes(c) || t.customAttributes.push(c), t.customAttrValues[i] = T), n) {
81
+ case "image":
82
+ o[i] = b(m.theme);
83
+ break;
84
+ case "button":
85
+ o[i] = O(m.theme);
86
+ break;
87
+ case "text":
88
+ case "custom": {
89
+ const _ = E(m.theme);
90
+ o[i] = _, _.textTrimming && (t.anyTextTrimming = !0);
91
+ break;
92
+ }
93
+ }
94
+ }), t.perElementStyles = o, t;
95
+ }
96
+ export {
97
+ S as mapComposition
98
+ };
@@ -0,0 +1,27 @@
1
+ const i = "You May Also Like!";
2
+ function s(r) {
3
+ var e;
4
+ const o = r.querySelector(".ext-recommendation-title");
5
+ if (!o)
6
+ return i;
7
+ const t = (e = o.textContent) == null ? void 0 : e.trim();
8
+ return t && t.length > 0 ? t : i;
9
+ }
10
+ function u(r) {
11
+ const o = [
12
+ r,
13
+ ...Array.from(r.querySelectorAll(".product-card, .ext-recommendation-card"))
14
+ ];
15
+ let t = "";
16
+ return o.some((e) => {
17
+ const n = e.getAttribute("bgcolor");
18
+ if (n && n.trim())
19
+ return t = n.trim(), !0;
20
+ const c = (e.getAttribute("style") ?? "").match(/background-color\s*:\s*([^;]+)/i);
21
+ return c && c[1] ? (t = c[1].trim(), !0) : !1;
22
+ }), t;
23
+ }
24
+ export {
25
+ u as extractCardBgColor,
26
+ s as extractTitleText
27
+ };