@useinsider/guido 3.8.3-beta.96b5eeb → 3.9.0-beta.10a70b8

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 (60) hide show
  1. package/dist/@types/config/schemas.js +70 -66
  2. package/dist/composables/usePreviewMode.js +15 -14
  3. package/dist/composables/useRecommendationPreview.js +111 -0
  4. package/dist/config/compiler/recommendationCompilerRules.js +1 -1
  5. package/dist/config/compiler/utils/recommendationCompilerUtils.js +122 -106
  6. package/dist/config/migrator/recommendation/htmlBuilder.js +53 -52
  7. package/dist/config/migrator/recommendation/settingsMapper.js +38 -33
  8. package/dist/extensions/Blocks/Items/block.js +48 -29
  9. package/dist/extensions/Blocks/Items/utils/nodeConfigUtils.js +62 -45
  10. package/dist/extensions/Blocks/Recommendation/block.js +64 -42
  11. package/dist/extensions/Blocks/Recommendation/canvasPreview.css.js +16 -0
  12. package/dist/extensions/Blocks/Recommendation/constants/defaultConfig.js +41 -32
  13. package/dist/extensions/Blocks/Recommendation/controls/cardComposition/index.js +461 -363
  14. package/dist/extensions/Blocks/Recommendation/controls/main/algorithm.js +33 -25
  15. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +99 -87
  16. package/dist/extensions/Blocks/Recommendation/controls/main/pricePlacement.js +133 -0
  17. package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +162 -160
  18. package/dist/extensions/Blocks/Recommendation/extension.js +30 -29
  19. package/dist/extensions/Blocks/Recommendation/iconsRegistry.js +21 -7
  20. package/dist/extensions/Blocks/Recommendation/recommendation.css.js +126 -8
  21. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +3 -1
  22. package/dist/extensions/Blocks/Recommendation/templates/grid/elementRenderer.js +130 -96
  23. package/dist/extensions/Blocks/Recommendation/templates/grid/template.js +43 -54
  24. package/dist/extensions/Blocks/Recommendation/templates/index.js +17 -14
  25. package/dist/extensions/Blocks/Recommendation/templates/list/elementRenderer.js +86 -80
  26. package/dist/extensions/Blocks/Recommendation/templates/list/template.js +30 -39
  27. package/dist/extensions/Blocks/Recommendation/templates/utils.js +155 -102
  28. package/dist/extensions/Blocks/common-control.js +58 -45
  29. package/dist/extensions/Blocks/controlFactories.js +76 -57
  30. package/dist/src/@types/config/schemas.d.ts +16 -0
  31. package/dist/src/composables/useConfig.d.ts +4 -0
  32. package/dist/src/composables/useRecommendationPreview.d.ts +10 -0
  33. package/dist/src/config/migrator/recommendation/settingsMapper.d.ts +1 -1
  34. package/dist/src/extensions/Blocks/CouponBlock/controls/index.d.ts +1 -1
  35. package/dist/src/extensions/Blocks/Items/block.d.ts +8 -0
  36. package/dist/src/extensions/Blocks/Items/controls/index.d.ts +3 -3
  37. package/dist/src/extensions/Blocks/Items/utils/nodeConfigUtils.d.ts +1 -1
  38. package/dist/src/extensions/Blocks/Recommendation/block.d.ts +10 -0
  39. package/dist/src/extensions/Blocks/Recommendation/controls/cardComposition/index.d.ts +29 -3
  40. package/dist/src/extensions/Blocks/Recommendation/controls/index.d.ts +1 -1
  41. package/dist/src/extensions/Blocks/Recommendation/controls/main/algorithm.d.ts +2 -1
  42. package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +3 -1
  43. package/dist/src/extensions/Blocks/Recommendation/controls/main/pricePlacement.d.ts +59 -0
  44. package/dist/src/extensions/Blocks/Recommendation/controls/name/index.d.ts +1 -1
  45. package/dist/src/extensions/Blocks/Recommendation/controls/oldPrice/index.d.ts +1 -1
  46. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusDiscount/index.d.ts +1 -1
  47. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusPrice/index.d.ts +1 -1
  48. package/dist/src/extensions/Blocks/Recommendation/controls/price/index.d.ts +1 -1
  49. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +2 -0
  50. package/dist/src/extensions/Blocks/Recommendation/templates/grid/elementRenderer.d.ts +13 -1
  51. package/dist/src/extensions/Blocks/Recommendation/templates/grid/template.d.ts +4 -4
  52. package/dist/src/extensions/Blocks/Recommendation/templates/index.d.ts +1 -1
  53. package/dist/src/extensions/Blocks/Recommendation/templates/list/elementRenderer.d.ts +10 -1
  54. package/dist/src/extensions/Blocks/Recommendation/templates/list/template.d.ts +3 -3
  55. package/dist/src/extensions/Blocks/Recommendation/templates/utils.d.ts +51 -1
  56. package/dist/src/extensions/Blocks/Recommendation/types/nodeConfig.d.ts +15 -0
  57. package/dist/src/extensions/Blocks/common-control.d.ts +7 -0
  58. package/dist/src/extensions/Blocks/controlFactories.d.ts +10 -1
  59. package/dist/src/stores/config.d.ts +36 -0
  60. package/package.json +1 -1
@@ -1,173 +1,189 @@
1
- import { useConfig as _ } from "../../../composables/useConfig.js";
2
- import { useRecommendation as g } from "../../../composables/useRecommendation.js";
3
- import { CSS_CLASS_RECO_BUTTON as q } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
4
- import { useRecommendationExtensionStore as C } from "../../../extensions/Blocks/Recommendation/store/recommendation.js";
5
- import { isIgnoredRecommendationBlock as w } from "./recommendationIgnoreUtils.js";
6
- function h(r, n, e, o, c = "") {
7
- const i = `{{${c}${r}_${n}_${e}}}`, t = `{{${c}${r}_${n}_currency}}`;
8
- return o === "before" ? `${t} ${i}` : `${i} ${t}`;
1
+ import { useConfig as q } from "../../../composables/useConfig.js";
2
+ import { useRecommendation as C } from "../../../composables/useRecommendation.js";
3
+ import { CSS_CLASS_RECO_BUTTON as E } from "../../../extensions/Blocks/Recommendation/constants/selectors.js";
4
+ import { useRecommendationExtensionStore as w } from "../../../extensions/Blocks/Recommendation/store/recommendation.js";
5
+ import { isIgnoredRecommendationBlock as P } from "./recommendationIgnoreUtils.js";
6
+ function f(t, o, e, n, s = "") {
7
+ const i = `{{${s}${t}_${o}_${e}}}`, r = `{{${s}${t}_${o}_currency}}`;
8
+ return n === "before" ? `${r} ${i}` : `${i} ${r}`;
9
9
  }
10
- function f(r) {
11
- let n = r;
12
- for (; n.children.length === 1; )
13
- [n] = n.children;
14
- return n;
10
+ function m(t) {
11
+ let o = t;
12
+ for (; o.children.length === 1; )
13
+ [o] = o.children;
14
+ return o;
15
15
  }
16
- function A(r, n, e, o, c, i) {
17
- switch (n) {
16
+ function h(t, o, e, n, s, i) {
17
+ switch (o) {
18
18
  case "productImage": {
19
- const t = r.querySelector("img");
20
- t && (t.setAttribute("src", `{{${i}${e}_${o}_image_url}}`), t.setAttribute("alt", `{{${i}${e}_${o}_name}}`));
21
- const s = r.querySelector("a");
22
- s && (s.setAttribute("href", `{{${i}${e}_${o}_url}}`), s.classList.add(q));
19
+ const r = t.querySelector("img");
20
+ r && (r.setAttribute("src", `{{${i}${e}_${n}_image_url}}`), r.setAttribute("alt", `{{${i}${e}_${n}_name}}`));
21
+ const c = t.querySelector("a");
22
+ c && (c.setAttribute("href", `{{${i}${e}_${n}_url}}`), c.classList.add(E));
23
23
  break;
24
24
  }
25
25
  case "productName": {
26
- const t = r.querySelector("p");
27
- t && (f(t).textContent = `{{${i}${e}_${o}_name}}`);
26
+ const r = t.querySelector("p");
27
+ r && (m(r).textContent = `{{${i}${e}_${n}_name}}`);
28
28
  break;
29
29
  }
30
30
  case "productPrice": {
31
- const t = r.querySelector("p");
32
- t && (f(t).textContent = h(
31
+ const r = t.querySelector(".product-price p") ?? t.querySelector("p");
32
+ r && (m(r).textContent = f(
33
33
  e,
34
- o,
34
+ n,
35
35
  "price",
36
- c,
36
+ s,
37
+ i
38
+ ));
39
+ const c = t.querySelector(".product-old-price p");
40
+ c && (m(c).textContent = f(
41
+ e,
42
+ n,
43
+ "original_price",
44
+ s,
37
45
  i
38
46
  ));
39
47
  break;
40
48
  }
41
49
  case "productOldPrice": {
42
- const t = r.querySelector("p");
43
- t && (f(t).textContent = h(
50
+ const r = t.querySelector("p");
51
+ r && (m(r).textContent = f(
44
52
  e,
45
- o,
53
+ n,
46
54
  "original_price",
47
- c,
55
+ s,
48
56
  i
49
- ), t.setAttribute("product-attr", "discount"));
57
+ ));
50
58
  break;
51
59
  }
52
60
  case "productButton": {
53
- const t = r.querySelector("a");
54
- t && t.setAttribute("href", `{{${i}${e}_${o}_url}}`);
61
+ const r = t.querySelector("a");
62
+ r && r.setAttribute("href", `{{${i}${e}_${n}_url}}`);
55
63
  break;
56
64
  }
57
65
  case "productOmnibusPrice": {
58
- const t = r.querySelector(".omnibus-price-value");
59
- if (t) {
60
- t.textContent = `{{${i}${e}_${o}_omnibus_price}}`;
61
- const s = t.closest("p");
62
- s && (s.setAttribute("product-attr", "omnibus_price"), s.setAttribute("composition", "true"));
66
+ const r = t.querySelector(".omnibus-price-value");
67
+ if (r) {
68
+ r.textContent = `{{${i}${e}_${n}_omnibus_price}}`;
69
+ const c = r.closest("p");
70
+ c && (c.setAttribute("product-attr", "omnibus_price"), c.setAttribute("composition", "true"));
63
71
  }
64
72
  break;
65
73
  }
66
74
  case "productOmnibusDiscount": {
67
- const t = r.querySelector(".omnibus-discount-value");
68
- if (t) {
69
- t.textContent = `{{${i}${e}_${o}_omnibus_discount}}`;
70
- const s = t.closest("p");
71
- s && (s.setAttribute("product-attr", "omnibus_discount"), s.setAttribute("composition", "true"));
75
+ const r = t.querySelector(".omnibus-discount-value");
76
+ if (r) {
77
+ r.textContent = `{{${i}${e}_${n}_omnibus_discount}}`;
78
+ const c = r.closest("p");
79
+ c && (c.setAttribute("product-attr", "omnibus_discount"), c.setAttribute("composition", "true"));
72
80
  }
73
81
  break;
74
82
  }
75
83
  default: {
76
- const t = r.getAttribute("product-attr") ? r : r.querySelector("[product-attr]");
77
- if (t) {
78
- const s = t.getAttribute("product-attr"), a = t.querySelector("p");
79
- a && (f(a).textContent = `{{${i}${e}_${o}_${s}}}`);
84
+ const r = t.getAttribute("product-attr") ? t : t.querySelector("[product-attr]");
85
+ if (r) {
86
+ const c = r.getAttribute("product-attr"), l = r.querySelector("p");
87
+ l && (m(l).textContent = `{{${i}${e}_${n}_${c}}}`);
80
88
  }
81
89
  break;
82
90
  }
83
91
  }
84
92
  }
85
- function E(r, n, e, o) {
86
- r.querySelectorAll(".recommendation-product-row").forEach((i, t) => {
87
- i.querySelectorAll("[data-attribute-type]").forEach((a) => {
88
- const u = a.getAttribute("data-attribute-type") || "", p = a.querySelectorAll(".attribute-cell");
89
- p.length > 0 ? p.forEach((l) => {
90
- A(l, u, n, t, e, o);
91
- }) : A(a, u, n, t, e, o);
93
+ function R(t, o, e, n) {
94
+ t.querySelectorAll(".recommendation-product-row").forEach((i, r) => {
95
+ i.querySelectorAll("[data-attribute-type]").forEach((l) => {
96
+ const u = l.getAttribute("data-attribute-type") || "", p = l.querySelectorAll(".attribute-cell");
97
+ p.length > 0 ? p.forEach((a) => {
98
+ h(a, u, o, r, e, n);
99
+ }) : h(l, u, o, r, e, n);
92
100
  });
93
101
  });
94
102
  }
95
- function R(r, n, e, o) {
96
- const c = r.querySelectorAll(".recommendation-product-row");
97
- if (!c.length)
103
+ function W(t, o, e, n) {
104
+ const s = t.querySelectorAll(".recommendation-product-row");
105
+ if (!s.length)
98
106
  return;
99
- const [i] = c, t = i.querySelector("[data-attribute-type]"), s = t ? t.querySelectorAll(".attribute-cell").length : 1;
100
- c.forEach((a, u) => {
101
- a.querySelectorAll("[data-attribute-type]").forEach((l) => {
102
- const m = l.getAttribute("data-attribute-type") || "";
103
- l.querySelectorAll(".attribute-cell").forEach((y, $) => {
104
- const S = u * s + $;
105
- A(y, m, n, S, e, o);
107
+ const [i] = s, r = i.querySelector("[data-attribute-type]"), c = r ? r.querySelectorAll(".attribute-cell").length : 1;
108
+ s.forEach((l, u) => {
109
+ l.querySelectorAll("[data-attribute-type]").forEach((a) => {
110
+ const d = a.getAttribute("data-attribute-type") || "";
111
+ a.querySelectorAll(".attribute-cell").forEach((S, _) => {
112
+ const g = u * c + _;
113
+ h(S, d, o, g, e, n);
106
114
  });
107
115
  });
108
116
  });
109
117
  }
110
- function P(r, n, e, o) {
111
- r.querySelectorAll(".ins-recommendation-product-container").forEach((i) => {
112
- R(i, n, e, o);
118
+ function v(t, o, e, n) {
119
+ t.querySelectorAll(".ins-recommendation-product-container").forEach((i) => {
120
+ W(i, o, e, n);
113
121
  });
114
122
  }
115
- function T(r, n, e) {
116
- const o = r.getAttribute("data-layout") || "grid", c = r.getAttribute("currency-alignment") || "after";
117
- o === "list" ? E(r, n, c, e) : P(r, n, c, e);
123
+ function O(t, o, e) {
124
+ const n = t.getAttribute("data-layout") || "grid", s = t.getAttribute("currency-alignment") || "after";
125
+ n === "list" ? R(t, o, s, e) : v(t, o, s, e);
118
126
  }
119
- function b(r, n, e) {
120
- const o = new RegExp(`${n}\\s*:\\s*(\\d+)\\s*px`, "i"), c = r.match(o);
121
- return c ? parseInt(c[1]) : e;
127
+ function b(t, o, e) {
128
+ const n = new RegExp(`${o}\\s*:\\s*(\\d+)\\s*px`, "i"), s = t.match(n);
129
+ return s ? parseInt(s[1]) : e;
122
130
  }
123
- function v(r, n) {
124
- let e = r.parentElement;
125
- for (; e && e !== n; ) {
126
- if (e.tagName === "TD") {
127
- const o = e.getAttribute("width");
128
- if (o && o.endsWith("%") && parseFloat(o) < 100)
129
- return e;
130
- }
131
+ function A(t) {
132
+ const o = t.trim();
133
+ return o.endsWith("%") ? parseFloat(o) < 100 : /^\d+(?:\.\d+)?(?:px)?$/.test(o) && parseInt(o) > 0;
134
+ }
135
+ function $(t) {
136
+ const o = t.getAttribute("width");
137
+ if (o && A(o))
138
+ return o.trim();
139
+ const e = (t.getAttribute("style") || "").match(/(?:^|[;\s])width\s*:\s*(\d+(?:\.\d+)?(?:px|%))/i);
140
+ return e && A(e[1]) ? e[1] : null;
141
+ }
142
+ function T(t, o) {
143
+ let e = t.parentElement;
144
+ for (; e && e !== o; ) {
145
+ if (e.tagName === "TD" && $(e))
146
+ return e;
131
147
  e = e.parentElement;
132
148
  }
133
149
  return null;
134
150
  }
135
- function O(r) {
136
- const n = r.getAttribute("style") || "", e = b(n, "width", 600), o = b(n, "padding", 0) * 2, c = Math.max(0, e - o);
137
- c !== 0 && r.querySelectorAll("img.adapt-img").forEach((i) => {
151
+ function M(t) {
152
+ const o = t.getAttribute("style") || "", e = b(o, "width", 600), n = b(o, "padding", 0) * 2, s = Math.max(0, e - n);
153
+ s !== 0 && t.querySelectorAll("img.adapt-img").forEach((i) => {
138
154
  if (i.hasAttribute("width"))
139
155
  return;
140
- const t = v(i, r);
141
- if (!t)
156
+ const r = T(i, t);
157
+ if (!r)
142
158
  return;
143
- const s = t.getAttribute("width"), a = parseFloat(s), u = b(t.getAttribute("style") || "", "padding", 0) * 2, p = Math.floor(c * a / 100), l = Math.max(1, p - u);
144
- i.setAttribute("width", String(l));
145
- const m = i.getAttribute("style") || "";
146
- if (!/\bwidth\s*:\s*\d/i.test(m)) {
147
- const d = m && !m.trim().endsWith(";") ? "; " : "";
148
- i.setAttribute("style", `${m}${d}width: ${l}px`);
159
+ const c = $(r), l = b(r.getAttribute("style") || "", "padding", 0) * 2, u = c.endsWith("%") ? Math.floor(s * parseFloat(c) / 100) : parseInt(c), p = Math.max(1, u - l);
160
+ i.setAttribute("width", String(p));
161
+ const a = i.getAttribute("style") || "";
162
+ if (!/\bwidth\s*:\s*\d/i.test(a)) {
163
+ const d = a && !a.trim().endsWith(";") ? "; " : "";
164
+ i.setAttribute("style", `${a}${d}width: ${p}px`);
149
165
  }
150
166
  });
151
167
  }
152
- function W(r, n) {
153
- const e = r.match(/<!DOCTYPE[^>]*>/i);
168
+ function B(t, o) {
169
+ const e = t.match(/<!DOCTYPE[^>]*>/i);
154
170
  return (e ? `${e[0]}
155
- ` : "") + n.documentElement.outerHTML;
171
+ ` : "") + o.documentElement.outerHTML;
156
172
  }
157
- function F(r) {
158
- const n = r.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), e = new DOMParser().parseFromString(n, "text/html"), o = e.querySelectorAll(".recommendation-block-v2");
159
- if (!o.length)
160
- return r;
161
- const { buildCampaignUrl: c } = g(), i = C();
173
+ function G(t) {
174
+ const o = t.replaceAll("{%", "<!--{%").replaceAll("%}", "%}-->"), e = new DOMParser().parseFromString(o, "text/html"), n = e.querySelectorAll(".recommendation-block-v2");
175
+ if (!n.length)
176
+ return t;
177
+ const { buildCampaignUrl: s } = C(), i = w();
162
178
  i.recommendationCampaignUrls = {};
163
- const { isFeatureEnabled: t } = _(), s = t("liquidSyntax") ? "reco_" : "";
164
- return o.forEach((u) => {
165
- var l, m;
179
+ const { isFeatureEnabled: r } = q(), c = r("liquidSyntax") ? "reco_" : "";
180
+ return n.forEach((u) => {
181
+ var a, d;
166
182
  const p = u.getAttribute("recommendation-id");
167
- p && ((l = u.parentNode) == null || l.insertBefore(e.createComment("REC_START"), u), (m = u.parentNode) == null || m.insertBefore(e.createComment("REC_END"), u.nextSibling), u.querySelectorAll('[data-visibility="0"]').forEach((d) => d.remove()), c(p), w(u) || T(u, p, s), O(u));
168
- }), W(n, e).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
183
+ p && ((a = u.parentNode) == null || a.insertBefore(e.createComment("REC_START"), u), (d = u.parentNode) == null || d.insertBefore(e.createComment("REC_END"), u.nextSibling), u.querySelectorAll('[data-visibility="0"]').forEach((y) => y.remove()), s(p), P(u) || O(u, p, c), M(u));
184
+ }), B(o, e).replaceAll("<!--{%", "{%").replaceAll("%}-->", "%}").replaceAll("&lt;!--{%", "{%").replaceAll("%}--&gt;", "%}");
169
185
  }
170
186
  export {
171
- h as formatPriceVariable,
172
- F as prepareRecommendationBlocks
187
+ f as formatPriceVariable,
188
+ G as prepareRecommendationBlocks
173
189
  };