@useinsider/guido 3.21.2-beta.4b0fed7 → 3.21.2-beta.5a809f7

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 (24) hide show
  1. package/dist/composables/useSave.js +75 -68
  2. package/dist/composables/validators/useHtmlDocumentCountValidator.js +22 -0
  3. package/dist/config/migrator/recommendation/extractors.js +36 -27
  4. package/dist/config/migrator/recommendation/htmlBuilder.js +99 -105
  5. package/dist/config/migrator/recommendation/settingsMapper.js +13 -15
  6. package/dist/config/migrator/recommendationMigrator.js +62 -59
  7. package/dist/extensions/Blocks/Recommendation/controls/cardComposition/index.js +20 -19
  8. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +101 -100
  9. package/dist/extensions/Blocks/Recommendation/templates/grid/template.js +23 -22
  10. package/dist/extensions/Blocks/Recommendation/templates/list/template.js +19 -18
  11. package/dist/extensions/Blocks/Recommendation/templates/utils.js +82 -91
  12. package/dist/extensions/Blocks/Recommendation/utils/inlinePriceOrder.js +12 -0
  13. package/dist/extensions/Blocks/Recommendation/utils/legacyStrategyMap.js +2 -0
  14. package/dist/services/templateLibraryApi.js +36 -31
  15. package/dist/src/composables/validators/useHtmlDocumentCountValidator.d.ts +3 -0
  16. package/dist/src/config/migrator/recommendation/extractors.d.ts +6 -0
  17. package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +1 -1
  18. package/dist/src/extensions/Blocks/Recommendation/templates/utils.d.ts +1 -13
  19. package/dist/src/extensions/Blocks/Recommendation/utils/inlinePriceOrder.d.ts +9 -0
  20. package/dist/src/extensions/Blocks/Recommendation/utils/legacyStrategyMap.d.ts +2 -20
  21. package/dist/src/utils/templatePreparation.d.ts +2 -1
  22. package/dist/utils/pairProductVariables.js +98 -90
  23. package/dist/utils/templatePreparation.js +30 -30
  24. package/package.json +1 -1
@@ -1,54 +1,57 @@
1
1
  import { BlockId as y } from "../../enums/block.js";
2
- import { DEFAULT_NODE_CONFIG as T } from "../../extensions/Blocks/Recommendation/constants/defaultConfig.js";
3
- import { ATTR_RECOMMENDATION_TITLE as d } from "../../extensions/Blocks/Recommendation/constants/selectors.js";
4
- import { useTemplateStore as v } from "../../stores/template.js";
5
- import { mapComposition as b } from "./recommendation/compositionMapper.js";
6
- import { extractCurrencyFromBlock as C, isOldPriceFirst as M, withRenderedTextTheme as R, extractTitleText as h, hasEmptyTitle as w, hasVisibleTitle as x, extractCardBgColor as E, isPartnerManagedBlock as S } from "./recommendation/extractors.js";
7
- import { buildBlockHtml as A } from "./recommendation/htmlBuilder.js";
8
- import { parseRecommendationId as H, parseLegacyConfig as B } from "./recommendation/parseLegacyConfig.js";
9
- import { mapSettings as L } from "./recommendation/settingsMapper.js";
2
+ import { DEFAULT_NODE_CONFIG as v } from "../../extensions/Blocks/Recommendation/constants/defaultConfig.js";
3
+ import { ATTR_RECOMMENDATION_TITLE as p } from "../../extensions/Blocks/Recommendation/constants/selectors.js";
4
+ import { useTemplateStore as b } from "../../stores/template.js";
5
+ import { mapComposition as C } from "./recommendation/compositionMapper.js";
6
+ import { extractCurrencyFromBlock as M, isPriceOnNextLine as x, isOldPriceFirst as R, withRenderedTextTheme as h, extractTitleText as w, hasEmptyTitle as E, hasVisibleTitle as L, extractCardBgColor as S, isPartnerManagedBlock as A } from "./recommendation/extractors.js";
7
+ import { buildBlockHtml as H } from "./recommendation/htmlBuilder.js";
8
+ import { parseRecommendationId as B, parseLegacyConfig as N } from "./recommendation/parseLegacyConfig.js";
9
+ import { mapSettings as O } from "./recommendation/settingsMapper.js";
10
10
  const F = '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)';
11
- function I(n, t, c) {
12
- var l;
13
- const r = H(t);
14
- if (r === null)
11
+ function I(c, e, s) {
12
+ var d;
13
+ const t = B(e);
14
+ if (t === null)
15
15
  return console.warn(
16
16
  "[RecommendationMigrator] Skipping block — missing/invalid `ins-recommendation-v3-campaign-id`"
17
17
  ), !1;
18
- const o = B(t);
19
- if (!o)
18
+ const r = N(e);
19
+ if (!r)
20
20
  return console.warn(
21
- `[RecommendationMigrator] Aborting block id=${r} — \`esd-dev-product-config\` missing or unable to be parsed`
21
+ `[RecommendationMigrator] Aborting block id=${t} — \`esd-dev-product-config\` missing or unable to be parsed`
22
22
  ), !1;
23
- const a = c[String(r)] ?? {
24
- currencySettings: C(t)
25
- }, i = L(a, o, r), e = b(
26
- R((l = o.composition) == null ? void 0 : l.variables, t),
27
- { oldPriceFirst: M(t) }
28
- ), p = h(t);
29
- w(t) ? e.visibility[d] = !1 : e.titleVariable || (e.visibility[d] = x(t));
30
- const g = E(t), u = {
23
+ const i = s[String(t)] ?? {
24
+ currencySettings: M(e)
25
+ }, n = {
31
26
  ...i,
27
+ isPriceMovedToNextLine: i.isPriceMovedToNextLine ?? x(e)
28
+ }, a = O(n, r, t), o = C(
29
+ h((d = r.composition) == null ? void 0 : d.variables, e),
30
+ { oldPriceFirst: R(e) }
31
+ ), g = w(e);
32
+ E(e) ? o.visibility[p] = !1 : o.titleVariable || (o.visibility[p] = L(e));
33
+ const f = S(e), u = {
34
+ ...a,
32
35
  strategyId: "",
33
- composition: e.composition,
34
- visibility: e.visibility,
35
- previousTitleHtml: T.previousTitleHtml,
36
- textTrimming: e.anyTextTrimming
37
- }, m = S(t), f = `
36
+ composition: o.composition,
37
+ visibility: o.visibility,
38
+ previousTitleHtml: v.previousTitleHtml,
39
+ textTrimming: o.anyTextTrimming
40
+ }, m = A(e), T = `
38
41
  <table>
39
42
  <tbody>
40
43
  <tr>
41
44
  <td class="esd-structure" align="left">
42
45
  <table width="100%" cellpadding="0" cellspacing="0">
43
46
  <tbody>
44
- <tr>${A({
47
+ <tr>${H({
45
48
  nodeConfig: u,
46
- composition: e,
47
- cardBg: g,
48
- titleText: p,
49
- legacyId: t.getAttribute("id") ?? void 0,
50
- legacyBgColor: t.getAttribute("bgcolor") ?? void 0,
51
- preserveInnerHtml: m ? t.innerHTML : void 0,
49
+ composition: o,
50
+ cardBg: f,
51
+ titleText: g,
52
+ legacyId: e.getAttribute("id") ?? void 0,
53
+ legacyBgColor: e.getAttribute("bgcolor") ?? void 0,
54
+ preserveInnerHtml: m ? e.innerHTML : void 0,
52
55
  skipCompile: m
53
56
  })}</tr>
54
57
  </tbody>
@@ -57,40 +60,40 @@ function I(n, t, c) {
57
60
  </tr>
58
61
  </tbody>
59
62
  </table>
60
- `, s = n.parseFromString(f, "text/html").querySelector("td.esd-structure");
61
- return !s || !t.parentNode ? (console.warn(
62
- `[RecommendationMigrator] Aborting block id=${r} — failed to construct new HTML element`
63
- ), !1) : (t.parentNode.replaceChild(s, t), !0);
63
+ `, l = c.parseFromString(T, "text/html").querySelector("td.esd-structure");
64
+ return !l || !e.parentNode ? (console.warn(
65
+ `[RecommendationMigrator] Aborting block id=${t} — failed to construct new HTML element`
66
+ ), !1) : (e.parentNode.replaceChild(l, e), !0);
64
67
  }
65
- function K(n, t = {}) {
66
- const c = new DOMParser();
67
- let r;
68
+ function j(c, e = {}) {
69
+ const s = new DOMParser();
70
+ let t;
68
71
  try {
69
- r = c.parseFromString(n, "text/html");
70
- } catch (i) {
71
- return console.error("[RecommendationMigrator] Failed to parse template:", i), n;
72
+ t = s.parseFromString(c, "text/html");
73
+ } catch (n) {
74
+ return console.error("[RecommendationMigrator] Failed to parse template:", n), c;
72
75
  }
73
- const o = Array.from(r.querySelectorAll(F));
76
+ const r = Array.from(t.querySelectorAll(F));
74
77
  try {
75
- v().$patch((e) => {
76
- e.migrations = {
77
- ...e.migrations,
78
- [y.Recommendation]: o.length
78
+ b().$patch((a) => {
79
+ a.migrations = {
80
+ ...a.migrations,
81
+ [y.Recommendation]: r.length
79
82
  };
80
83
  });
81
84
  } catch {
82
85
  }
83
- if (o.length === 0)
84
- return n;
85
- let a = 0;
86
- return o.forEach((i) => {
86
+ if (r.length === 0)
87
+ return c;
88
+ let i = 0;
89
+ return r.forEach((n) => {
87
90
  try {
88
- I(c, i, t) && (a += 1);
89
- } catch (e) {
90
- console.error("[RecommendationMigrator] Unexpected error migrating block:", e);
91
+ I(s, n, e) && (i += 1);
92
+ } catch (a) {
93
+ console.error("[RecommendationMigrator] Unexpected error migrating block:", a);
91
94
  }
92
- }), a > 0 && console.info(`[RecommendationMigrator] Migrated ${a} legacy Recommendation block(s)`), r.documentElement.outerHTML;
95
+ }), i > 0 && console.info(`[RecommendationMigrator] Migrated ${i} legacy Recommendation block(s)`), t.documentElement.outerHTML;
93
96
  }
94
97
  export {
95
- K as migrateRecommendation
98
+ j as migrateRecommendation
96
99
  };
@@ -11,10 +11,11 @@ import { useRecommendationExtensionStore as ft } from "../../store/recommendatio
11
11
  import { ATTRIBUTE_CELL_CLASS as bt, gridElementRenderer as yt, DEFAULT_CELL_PADDING as Tt, buildFillerCell as Ct } from "../../templates/grid/elementRenderer.js";
12
12
  import { listElementRenderer as St } from "../../templates/list/elementRenderer.js";
13
13
  import { buildTitleRows as At, DEFAULT_TITLE_PARAGRAPH as It, DEFAULT_TITLE_TEXT as $t } from "../../templates/titleRows.js";
14
- import { resolveInlinePriceOrder as vt, toDisplayName as Nt, toDisplayableAttributeValue as Et, buildElementRenderer as J } from "../../templates/utils.js";
15
- import { normalizeCompositionKeys as Rt, normalizeCustomAttrValues as Lt, compositionKeyToProductAttr as k, resolveRowVisibilityKeys as Ot, filterToProductAttrValue as C, findAttributeRow as Dt, rewriteLegacyRowKeyHtml as Q, bareAttributeName as H, isDefaultProductAttr as Ht, productAttrToCompositionKey as M } from "../../utils/compositionKeys.js";
16
- import { getTableDisplayValue as Pt } from "../../utils/tagName.js";
17
- import { isPartnerManagedBlock as wt, regenerateProductRowsWithStyles as Bt, getMainContainerTbody as kt, getCurrentLayout as Mt } from "../main/utils.js";
14
+ import { toDisplayName as vt, toDisplayableAttributeValue as Nt, buildElementRenderer as J } from "../../templates/utils.js";
15
+ import { normalizeCompositionKeys as Et, normalizeCustomAttrValues as Rt, compositionKeyToProductAttr as k, resolveRowVisibilityKeys as Lt, filterToProductAttrValue as C, findAttributeRow as Ot, rewriteLegacyRowKeyHtml as Q, bareAttributeName as H, isDefaultProductAttr as Dt, productAttrToCompositionKey as M } from "../../utils/compositionKeys.js";
16
+ import { getTableDisplayValue as Ht } from "../../utils/tagName.js";
17
+ import { isPartnerManagedBlock as Pt, regenerateProductRowsWithStyles as wt, getMainContainerTbody as Bt, getCurrentLayout as kt } from "../main/utils.js";
18
+ import { resolveInlinePriceOrder as Mt } from "../../utils/inlinePriceOrder.js";
18
19
  const Ut = "ui-elements-recommendation-card-composition", U = ".product-card-wrapper > tbody", Z = ".product-info-cell > table > tbody", tt = {
19
20
  ADD_ATTRIBUTE: "addAttribute"
20
21
  }, b = 5, P = "reorderIcon_", qt = '<svg width="14" height="10" viewBox="0 0 14 10" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><circle cx="2" cy="2.5" r="1.2"/><circle cx="7" cy="2.5" r="1.2"/><circle cx="12" cy="2.5" r="1.2"/><circle cx="2" cy="7.5" r="1.2"/><circle cx="7" cy="7.5" r="1.2"/><circle cx="12" cy="7.5" r="1.2"/></svg>', m = [
@@ -26,7 +27,7 @@ const Ut = "ui-elements-recommendation-card-composition", U = ".product-card-wra
26
27
  { key: pt, label: "Omnibus Discount" },
27
28
  { key: F, label: "Product Button" }
28
29
  ], L = { key: $, label: "Title" }, Ft = new Set(m.map((_) => _.key)), A = "customAttr_", w = "deleteAttr_";
29
- class se extends ut {
30
+ class oe extends ut {
30
31
  constructor() {
31
32
  super(...arguments);
32
33
  v(this, "store", ft());
@@ -155,7 +156,7 @@ class se extends ut {
155
156
  const t = (r = this.getContainer()) == null ? void 0 : r.querySelector("[data-card-composition-control]");
156
157
  if (!t)
157
158
  return;
158
- const e = wt(this.currentNode);
159
+ const e = Pt(this.currentNode);
159
160
  t.style.pointerEvents = e ? "none" : "", t.style.opacity = e ? "0.5" : "";
160
161
  }
161
162
  onTemplateNodeUpdated(t) {
@@ -198,7 +199,7 @@ class se extends ut {
198
199
  }
199
200
  /** Upgrades legacy bare-name custom keys to the canonical form. (SD-147101) */
200
201
  _normalizeComposition(t) {
201
- return Rt(t, this.currentNode, this.store.filterList);
202
+ return Et(t, this.currentNode, this.store.filterList);
202
203
  }
203
204
  _readCustomAttributesFromNode() {
204
205
  if (!this.currentNode || !("getAttribute" in this.currentNode))
@@ -206,7 +207,7 @@ class se extends ut {
206
207
  const t = this.currentNode.getAttribute(W);
207
208
  if (t)
208
209
  try {
209
- return Lt(
210
+ return Rt(
210
211
  JSON.parse(t).map((e) => String(e)),
211
212
  this.currentNode,
212
213
  this.store.filterList
@@ -241,7 +242,7 @@ class se extends ut {
241
242
  if (!("getAttribute" in r))
242
243
  return;
243
244
  const i = r.getAttribute(D);
244
- i !== null && Ot(r).forEach((s) => {
245
+ i !== null && Lt(r).forEach((s) => {
245
246
  e[s] = this._parseVisibilityValue(i);
246
247
  });
247
248
  }), e;
@@ -276,7 +277,7 @@ class se extends ut {
276
277
  if (!(i.dataset.inlinePrices !== String(s)) && this._tryReorderInPlace(i, t))
277
278
  return !1;
278
279
  i.dataset.inlinePrices = String(s);
279
- const n = new Set(e), l = vt(t);
280
+ const n = new Set(e), l = Mt(t);
280
281
  let a = 0, d = 0;
281
282
  const c = t.map((u) => {
282
283
  if (s && (u === p || u === I))
@@ -653,7 +654,7 @@ class se extends ut {
653
654
  try {
654
655
  this._updateBothAttributes(t, e);
655
656
  const r = this._isInlinePrices();
656
- this._getCurrentLayout() === "grid" && !r ? this._reorderProductAttributes(t) : this.currentNode && Bt({
657
+ this._getCurrentLayout() === "grid" && !r ? this._reorderProductAttributes(t) : this.currentNode && wt({
657
658
  currentNode: this.currentNode,
658
659
  documentModifier: this.api.getDocumentModifier()
659
660
  });
@@ -671,7 +672,7 @@ class se extends ut {
671
672
  * DOM converge on the next composition change without writing on open.
672
673
  */
673
674
  _getExistingRowHtml(t, e) {
674
- const r = Dt(t, e);
675
+ const r = Ot(t, e);
675
676
  if (r && "getOuterHTML" in r)
676
677
  return Q(r.getOuterHTML(), e);
677
678
  const i = t.querySelector(
@@ -815,7 +816,7 @@ class se extends ut {
815
816
  return;
816
817
  const o = e ? "1" : "0", n = e ? this.api.translate("visible") : this.api.translate("hidden"), l = `${this.api.translate("Set visibility")}: ${t} → ${n}`, a = this.api.getDocumentModifier();
817
818
  s.forEach((c) => {
818
- const u = Pt(c), h = e ? u : "none";
819
+ const u = Ht(c), h = e ? u : "none";
819
820
  a.modifyHtml(c).setStyle("display", h).setAttribute(D, o);
820
821
  });
821
822
  const d = {
@@ -877,7 +878,7 @@ class se extends ut {
877
878
  return "children" in t && t.children().some((e) => "hasClass" in e && e.hasClass(_t));
878
879
  }
879
880
  _findTitleContainerBody() {
880
- return (this.currentNode ? kt(this.currentNode) : null) ?? void 0;
881
+ return (this.currentNode ? Bt(this.currentNode) : null) ?? void 0;
881
882
  }
882
883
  _readInnerHtml(t) {
883
884
  return "getInnerHTML" in t && typeof t.getInnerHTML == "function" ? t.getInnerHTML().trim() : null;
@@ -904,7 +905,7 @@ class se extends ut {
904
905
  return -1;
905
906
  }
906
907
  _getCurrentLayout() {
907
- return this.store.recommendationConfigs.orientation || Mt(this.currentNode);
908
+ return this.store.recommendationConfigs.orientation || kt(this.currentNode);
908
909
  }
909
910
  /**
910
911
  * Extracts background color properties from existing card elements.
@@ -1000,7 +1001,7 @@ class se extends ut {
1000
1001
  */
1001
1002
  _getDisplayNameForAttribute(t) {
1002
1003
  const e = Object.values(this.store.filterList).find((r) => C(r) === t);
1003
- return e ? e.displayName : Nt(H(t));
1004
+ return e ? e.displayName : vt(H(t));
1004
1005
  }
1005
1006
  /**
1006
1007
  * Resolves the display content for a custom attribute cell.
@@ -1008,8 +1009,8 @@ class se extends ut {
1008
1009
  */
1009
1010
  _resolveAttributeContent(t, e, r) {
1010
1011
  var l;
1011
- const s = this.store.recommendationProducts[r], o = H(t), n = Ht(t) ? s == null ? void 0 : s[o] : (l = s == null ? void 0 : s.product_attributes) == null ? void 0 : l[o];
1012
- return Et(n) ?? e;
1012
+ const s = this.store.recommendationProducts[r], o = H(t), n = Dt(t) ? s == null ? void 0 : s[o] : (l = s == null ? void 0 : s.product_attributes) == null ? void 0 : l[o];
1013
+ return Nt(n) ?? e;
1013
1014
  }
1014
1015
  _getGridCellHtml(t, e, r, i = "", s = "", o = "") {
1015
1016
  const n = M(t), l = H(t), a = J(yt, [n], this.store.filterList), d = {
@@ -1032,5 +1033,5 @@ class se extends ut {
1032
1033
  }
1033
1034
  export {
1034
1035
  Ut as COMPOSITION_CONTROL_BLOCK_ID,
1035
- se as RecommendationCardCompositionControl
1036
+ oe as RecommendationCardCompositionControl
1036
1037
  };