@useinsider/guido 2.0.0-beta.1c331b8 → 2.0.0-beta.1f72712

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 (52) hide show
  1. package/dist/extensions/Blocks/Recommendation/block.js +40 -6
  2. package/dist/extensions/Blocks/Recommendation/constants/defaultConfig.js +64 -0
  3. package/dist/extensions/Blocks/Recommendation/constants/layout.js +9 -4
  4. package/dist/extensions/Blocks/Recommendation/constants/selectors.js +17 -9
  5. package/dist/extensions/Blocks/Recommendation/controls/cardComposition/index.js +48 -54
  6. package/dist/extensions/Blocks/Recommendation/controls/layout/index.js +42 -36
  7. package/dist/extensions/Blocks/Recommendation/controls/main/algorithm.js +51 -27
  8. package/dist/extensions/Blocks/Recommendation/controls/main/currency.js +146 -73
  9. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +49 -35
  10. package/dist/extensions/Blocks/Recommendation/controls/main/locale.js +23 -13
  11. package/dist/extensions/Blocks/Recommendation/controls/main/productLayout.js +41 -41
  12. package/dist/extensions/Blocks/Recommendation/controls/main/shuffle.js +27 -16
  13. package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +79 -67
  14. package/dist/extensions/Blocks/Recommendation/controls/omnibusDiscount/textAfter.js +1 -1
  15. package/dist/extensions/Blocks/Recommendation/controls/omnibusDiscount/textBefore.js +3 -3
  16. package/dist/extensions/Blocks/Recommendation/controls/spacing/index.js +85 -79
  17. package/dist/extensions/Blocks/Recommendation/recommendation.css.js +8 -4
  18. package/dist/extensions/Blocks/Recommendation/services/configService.js +239 -0
  19. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +30 -28
  20. package/dist/extensions/Blocks/Recommendation/templates/horizontal/elementRenderer.js +49 -25
  21. package/dist/extensions/Blocks/Recommendation/templates/horizontal/template.js +18 -19
  22. package/dist/extensions/Blocks/Recommendation/templates/utils.js +44 -101
  23. package/dist/extensions/Blocks/Recommendation/templates/vertical/elementRenderer.js +60 -35
  24. package/dist/extensions/Blocks/Recommendation/types/nodeConfig.js +6 -0
  25. package/dist/extensions/Blocks/Recommendation/utils/priceFormatter.js +29 -0
  26. package/dist/extensions/Blocks/Recommendation/utils/tagName.js +46 -0
  27. package/dist/extensions/Blocks/common-control.js +1 -1
  28. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +214 -157
  29. package/dist/src/components/wrappers/WpDrawer.vue.d.ts +1 -1
  30. package/dist/src/extensions/Blocks/Recommendation/block.d.ts +34 -0
  31. package/dist/src/extensions/Blocks/Recommendation/constants/defaultConfig.d.ts +49 -0
  32. package/dist/src/extensions/Blocks/Recommendation/constants/index.d.ts +3 -2
  33. package/dist/src/extensions/Blocks/Recommendation/constants/layout.d.ts +10 -0
  34. package/dist/src/extensions/Blocks/Recommendation/constants/selectors.d.ts +12 -0
  35. package/dist/src/extensions/Blocks/Recommendation/controls/layout/index.d.ts +3 -1
  36. package/dist/src/extensions/Blocks/Recommendation/controls/main/algorithm.d.ts +13 -1
  37. package/dist/src/extensions/Blocks/Recommendation/controls/main/currency.d.ts +30 -1
  38. package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +19 -0
  39. package/dist/src/extensions/Blocks/Recommendation/controls/main/locale.d.ts +9 -0
  40. package/dist/src/extensions/Blocks/Recommendation/controls/main/productLayout.d.ts +4 -2
  41. package/dist/src/extensions/Blocks/Recommendation/controls/main/shuffle.d.ts +8 -0
  42. package/dist/src/extensions/Blocks/Recommendation/controls/main/utils.d.ts +19 -0
  43. package/dist/src/extensions/Blocks/Recommendation/controls/spacing/index.d.ts +13 -2
  44. package/dist/src/extensions/Blocks/Recommendation/services/configService.d.ts +151 -0
  45. package/dist/src/extensions/Blocks/Recommendation/services/index.d.ts +6 -0
  46. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +1 -0
  47. package/dist/src/extensions/Blocks/Recommendation/types/index.d.ts +7 -0
  48. package/dist/src/extensions/Blocks/Recommendation/types/nodeConfig.d.ts +154 -0
  49. package/dist/src/extensions/Blocks/Recommendation/utils/priceFormatter.d.ts +33 -0
  50. package/dist/src/extensions/Blocks/Recommendation/utils/stylePreserver.d.ts +113 -0
  51. package/dist/src/extensions/Blocks/Recommendation/utils/tagName.d.ts +77 -0
  52. package/package.json +1 -1
@@ -1,7 +1,8 @@
1
- import { Block as e, BlockCompositionType as t } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
2
- import { getDefaultTemplate as o } from "./templates/vertical/template.js";
1
+ import { Block as o, BlockCompositionType as i } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
2
+ import { RecommendationConfigService as t } from "./services/configService.js";
3
+ import { getDefaultTemplate as r } from "./templates/vertical/template.js";
3
4
  const n = "recommendation-block";
4
- class m extends e {
5
+ class g extends o {
5
6
  constructor() {
6
7
  super();
7
8
  }
@@ -12,7 +13,7 @@ class m extends e {
12
13
  return "recommendation-icon";
13
14
  }
14
15
  getBlockCompositionType() {
15
- return t.CONTAINER;
16
+ return i.CONTAINER;
16
17
  }
17
18
  getName() {
18
19
  return this.api.translate("Recommendation Block");
@@ -21,10 +22,43 @@ class m extends e {
21
22
  return this.api.translate("Recommendation Block Title Description");
22
23
  }
23
24
  getTemplate() {
24
- return o();
25
+ return r();
26
+ }
27
+ /**
28
+ * Called when a new block is dropped into the template
29
+ *
30
+ * Initializes the block with default configuration stored via node config.
31
+ * This ensures the configuration persists with the template.
32
+ * @param node - The newly created block node
33
+ */
34
+ onCreated(e) {
35
+ t.initializeConfig(this.api, e);
36
+ }
37
+ /**
38
+ * Called when the document changes or template is loaded
39
+ *
40
+ * Handles migration from legacy templates that don't have node config.
41
+ * Also handles config version upgrades for future migrations.
42
+ * @param node - The block node that may need migration
43
+ */
44
+ onDocumentChanged(e) {
45
+ !e || !("getNodeConfig" in e) || t.needsMigration(e) && this._migrateFromLegacy(e);
46
+ }
47
+ /**
48
+ * Migrate configuration from legacy format
49
+ *
50
+ * Legacy templates may store configuration in:
51
+ * - data-attributes (data-layout, data-card-composition, etc.)
52
+ * - Pinia store (lost on reload - this is what we're fixing)
53
+ *
54
+ * This method reads what we can from the DOM and initializes proper node config.
55
+ * @param node - The block node to migrate
56
+ */
57
+ _migrateFromLegacy(e) {
58
+ t.migrateFromDataAttributes(this.api, e);
25
59
  }
26
60
  }
27
61
  export {
28
62
  n as BLOCK_ID,
29
- m as RecommendationBlock
63
+ g as RecommendationBlock
30
64
  };
@@ -0,0 +1,64 @@
1
+ import { DEFAULT_ROW_SPACING as s, DEFAULT_COLUMN_SPACING as R, DEFAULT_CARDS_IN_ROW as n } from "./layout.js";
2
+ import { ATTR_PRODUCT_IMAGE as t, ATTR_PRODUCT_NAME as e, ATTR_PRODUCT_OLD_PRICE as T, ATTR_PRODUCT_PRICE as o, ATTR_PRODUCT_OMNIBUS_PRICE as _, ATTR_PRODUCT_OMNIBUS_DISCOUNT as r, ATTR_PRODUCT_BUTTON as U } from "./selectors.js";
3
+ const I = {
4
+ code: "USD",
5
+ symbol: "USD",
6
+ alignment: "after",
7
+ decimalCount: 2,
8
+ decimalSeparator: ".",
9
+ thousandSeparator: ","
10
+ }, O = {
11
+ textBefore: "",
12
+ textAfter: ""
13
+ }, i = {
14
+ textBefore: "",
15
+ textAfter: ""
16
+ }, C = [
17
+ t,
18
+ e,
19
+ T,
20
+ o,
21
+ _,
22
+ r,
23
+ U
24
+ ], D = {
25
+ [t]: !0,
26
+ [e]: !0,
27
+ [o]: !0,
28
+ [T]: !0,
29
+ [_]: !1,
30
+ [r]: !1,
31
+ [U]: !0
32
+ }, a = {
33
+ // Settings
34
+ strategy: "mostPopular",
35
+ productIds: [],
36
+ size: "6",
37
+ shuffleProducts: !1,
38
+ language: "en_US",
39
+ currency: I,
40
+ filters: [],
41
+ // Layout
42
+ layout: "vertical",
43
+ cardsInRow: n,
44
+ columnSpacing: R,
45
+ rowSpacing: s,
46
+ // Composition
47
+ composition: C,
48
+ visibility: D,
49
+ // Element settings
50
+ omnibusPrice: O,
51
+ omnibusDiscount: i,
52
+ textTrimming: !1,
53
+ // Meta
54
+ configVersion: 1
55
+ }, E = 1;
56
+ export {
57
+ E as CURRENT_CONFIG_VERSION,
58
+ C as DEFAULT_COMPOSITION,
59
+ I as DEFAULT_CURRENCY,
60
+ a as DEFAULT_NODE_CONFIG,
61
+ i as DEFAULT_OMNIBUS_DISCOUNT,
62
+ O as DEFAULT_OMNIBUS_PRICE,
63
+ D as DEFAULT_VISIBILITY
64
+ };
@@ -1,7 +1,12 @@
1
- const _ = 3, R = 3, O = 9, D = 4;
1
+ const _ = 3, A = 3, C = 9, P = 4, o = 10, t = 20, R = 0, c = 50, n = 5;
2
2
  export {
3
- R as DEFAULT_CARDS_IN_ROW,
3
+ A as DEFAULT_CARDS_IN_ROW,
4
+ o as DEFAULT_COLUMN_SPACING,
4
5
  _ as DEFAULT_PRODUCTS_PER_ROW,
5
- D as MAX_PRODUCTS_PER_ROW,
6
- O as MAX_PRODUCT_COUNT
6
+ t as DEFAULT_ROW_SPACING,
7
+ P as MAX_PRODUCTS_PER_ROW,
8
+ C as MAX_PRODUCT_COUNT,
9
+ c as MAX_SPACING,
10
+ R as MIN_SPACING,
11
+ n as SPACING_STEP
7
12
  };
@@ -1,11 +1,19 @@
1
- const T = ".ins-recommendation-product-container", c = "productImage", o = "productName", t = "productPrice", R = "productOldPrice", _ = "productOmnibusPrice", n = "productOmnibusDiscount", O = "productButton";
1
+ const c = ".ins-recommendation-product-container", T = {
2
+ CURRENCY: "currency",
3
+ SYMBOL: "currency-symbol",
4
+ ALIGNMENT: "currency-alignment",
5
+ THOUSAND_SEPARATOR: "currency-thousand-separator",
6
+ DECIMAL_SEPARATOR: "currency-decimal-separator",
7
+ DECIMAL_COUNT: "currency-decimal-count"
8
+ }, r = "productImage", n = "productName", o = "productPrice", t = "productOldPrice", R = "productOmnibusPrice", O = "productOmnibusDiscount", _ = "productButton";
2
9
  export {
3
- O as ATTR_PRODUCT_BUTTON,
4
- c as ATTR_PRODUCT_IMAGE,
5
- o as ATTR_PRODUCT_NAME,
6
- R as ATTR_PRODUCT_OLD_PRICE,
7
- n as ATTR_PRODUCT_OMNIBUS_DISCOUNT,
8
- _ as ATTR_PRODUCT_OMNIBUS_PRICE,
9
- t as ATTR_PRODUCT_PRICE,
10
- T as CONTAINER_SELECTOR
10
+ _ as ATTR_PRODUCT_BUTTON,
11
+ r as ATTR_PRODUCT_IMAGE,
12
+ n as ATTR_PRODUCT_NAME,
13
+ t as ATTR_PRODUCT_OLD_PRICE,
14
+ O as ATTR_PRODUCT_OMNIBUS_DISCOUNT,
15
+ R as ATTR_PRODUCT_OMNIBUS_PRICE,
16
+ o as ATTR_PRODUCT_PRICE,
17
+ c as CONTAINER_SELECTOR,
18
+ T as CURRENCY_ATTR
11
19
  };
@@ -1,33 +1,34 @@
1
- var C = Object.defineProperty;
2
- var f = (a, s, t) => s in a ? C(a, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[s] = t;
3
- var c = (a, s, t) => f(a, typeof s != "symbol" ? s + "" : s, t);
4
- import { ModificationDescription as d } from "../../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
5
- import { CommonControl as O } from "../../../common-control.js";
6
- import { ATTR_PRODUCT_IMAGE as g, ATTR_PRODUCT_NAME as R, ATTR_PRODUCT_PRICE as A, ATTR_PRODUCT_OLD_PRICE as N, ATTR_PRODUCT_OMNIBUS_PRICE as D, ATTR_PRODUCT_OMNIBUS_DISCOUNT as E, ATTR_PRODUCT_BUTTON as I } from "../../constants/selectors.js";
7
- import { useRecommendationExtensionStore as V } from "../../store/recommendation.js";
1
+ var T = Object.defineProperty;
2
+ var C = (a, n, t) => n in a ? T(a, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[n] = t;
3
+ var l = (a, n, t) => C(a, typeof n != "symbol" ? n + "" : n, t);
4
+ import { ModificationDescription as u } from "../../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
5
+ import { CommonControl as f } from "../../../common-control.js";
6
+ import { ATTR_PRODUCT_IMAGE as O, ATTR_PRODUCT_NAME as g, ATTR_PRODUCT_PRICE as R, ATTR_PRODUCT_OLD_PRICE as A, ATTR_PRODUCT_OMNIBUS_PRICE as D, ATTR_PRODUCT_OMNIBUS_DISCOUNT as N, ATTR_PRODUCT_BUTTON as V } from "../../constants/selectors.js";
7
+ import { useRecommendationExtensionStore as E } from "../../store/recommendation.js";
8
+ import { getTableDisplayValue as I } from "../../utils/tagName.js";
8
9
  import { getCurrentLayout as P } from "../main/utils.js";
9
10
  const S = "ui-elements-recommendation-card-composition", k = {
10
11
  ORDERABLE: "cardComposition"
11
- }, b = ".recommendation-attribute-row", v = ".product-card-wrapper > tbody", T = "data-card-composition", p = "data-attribute-type", y = "data-visibility", n = [
12
- { key: g, label: "Product Image", visible: !0 },
13
- { key: R, label: "Product Name", visible: !0 },
14
- { key: A, label: "Product Price", visible: !0 },
15
- { key: N, label: "Product Original Price", visible: !0 },
12
+ }, c = ".recommendation-attribute-row", v = ".product-card-wrapper > tbody", _ = "data-card-composition", d = "data-attribute-type", m = "data-visibility", s = [
13
+ { key: O, label: "Product Image", visible: !0 },
14
+ { key: g, label: "Product Name", visible: !0 },
15
+ { key: R, label: "Product Price", visible: !0 },
16
+ { key: A, label: "Product Original Price", visible: !0 },
16
17
  { key: D, label: "Omnibus Price", visible: !1 },
17
- { key: E, label: "Omnibus Discount", visible: !1 },
18
- { key: I, label: "Product Button", visible: !0 }
18
+ { key: N, label: "Omnibus Discount", visible: !1 },
19
+ { key: V, label: "Product Button", visible: !0 }
19
20
  ];
20
- class q extends O {
21
+ class H extends f {
21
22
  constructor() {
22
23
  super(...arguments);
23
- c(this, "store", V());
24
- c(this, "unsubscribeOrientation", null);
24
+ l(this, "store", E());
25
+ l(this, "unsubscribeOrientation", null);
25
26
  }
26
27
  getId() {
27
28
  return S;
28
29
  }
29
30
  getTemplate() {
30
- const t = n.map((e) => ({
31
+ const t = s.map((e) => ({
31
32
  key: e.key,
32
33
  label: e.label,
33
34
  content: this._createItemContent(e.label, e.key)
@@ -63,7 +64,7 @@ class q extends O {
63
64
  _registerValueChangeListeners() {
64
65
  this.api.onValueChanged("cardComposition", (t) => {
65
66
  this._applyCompositionToBlock(t);
66
- }), n.forEach((t) => {
67
+ }), s.forEach((t) => {
67
68
  this.api.onValueChanged(`visibility_${t.key}`, (e) => {
68
69
  this._applyVisibilityToBlock(t.key, e);
69
70
  });
@@ -85,15 +86,15 @@ class q extends O {
85
86
  */
86
87
  _readCompositionFromNode() {
87
88
  if (!this.currentNode || !("getAttribute" in this.currentNode))
88
- return n.map((e) => e.key);
89
- const t = this.currentNode.getAttribute(T);
90
- return t ? t.split(",").filter(Boolean) : n.map((e) => e.key);
89
+ return s.map((e) => e.key);
90
+ const t = this.currentNode.getAttribute(_);
91
+ return t ? t.split(",").filter(Boolean) : s.map((e) => e.key);
91
92
  }
92
93
  /**
93
94
  * Builds visibility values object from the visibility map
94
95
  */
95
96
  _buildVisibilityValues(t) {
96
- return n.reduce((e, i) => (e[`visibility_${i.key}`] = t[i.key] ?? !0, e), {});
97
+ return s.reduce((e, i) => (e[`visibility_${i.key}`] = t[i.key] ?? !0, e), {});
97
98
  }
98
99
  /**
99
100
  * Read visibility state from individual row elements' data-visibility attributes
@@ -102,14 +103,14 @@ class q extends O {
102
103
  _readVisibilityFromRows() {
103
104
  if (!this.currentNode)
104
105
  return this._getDefaultVisibilities();
105
- const t = Array.from(this.currentNode.querySelectorAll(b)), e = this._extractVisibilityFromRows(t);
106
+ const t = Array.from(this.currentNode.querySelectorAll(c)), e = this._extractVisibilityFromRows(t);
106
107
  return this._mergeWithDefaults(e);
107
108
  }
108
109
  /**
109
110
  * Returns default visibility values for all items
110
111
  */
111
112
  _getDefaultVisibilities() {
112
- return n.reduce((t, e) => (t[e.key] = e.visible, t), {});
113
+ return s.reduce((t, e) => (t[e.key] = e.visible, t), {});
113
114
  }
114
115
  /**
115
116
  * Extracts visibility values from DOM nodes
@@ -119,8 +120,8 @@ class q extends O {
119
120
  return t.forEach((i) => {
120
121
  if (!("getAttribute" in i))
121
122
  return;
122
- const r = i.getAttribute(p), o = i.getAttribute(y);
123
- r && o !== null && (e[r] = this._parseVisibilityValue(o));
123
+ const o = i.getAttribute(d), r = i.getAttribute(m);
124
+ o && r !== null && (e[o] = this._parseVisibilityValue(r));
124
125
  }), e;
125
126
  }
126
127
  /**
@@ -134,7 +135,7 @@ class q extends O {
134
135
  * Merges extracted visibilities with default values for missing keys
135
136
  */
136
137
  _mergeWithDefaults(t) {
137
- return n.forEach((e) => {
138
+ return s.forEach((e) => {
138
139
  e.key in t || (t[e.key] = e.visible);
139
140
  }), t;
140
141
  }
@@ -147,7 +148,7 @@ class q extends O {
147
148
  if (!this.currentNode)
148
149
  return;
149
150
  const e = this._getCurrentLayout();
150
- this.api.getDocumentModifier().modifyHtml(this.currentNode).setAttribute(T, t.join(",")).apply(new d("Update card composition")), e === "vertical" && this._reorderProductAttributes(t);
151
+ this.api.getDocumentModifier().modifyHtml(this.currentNode).setAttribute(_, t.join(",")).apply(new u("Update card composition")), e === "vertical" && this._reorderProductAttributes(t);
151
152
  }
152
153
  /**
153
154
  * Reorders attribute rows within each product card based on composition order
@@ -160,18 +161,18 @@ class q extends O {
160
161
  if (!(e != null && e.length))
161
162
  return;
162
163
  const i = this.api.getDocumentModifier();
163
- e.forEach((r) => {
164
- const o = this._buildCompositionHtml(r, t);
165
- i.modifyHtml(r).setInnerHtml(o);
166
- }), i.apply(new d("Reorder product attributes"));
164
+ e.forEach((o) => {
165
+ const r = this._buildCompositionHtml(o, t);
166
+ i.modifyHtml(o).setInnerHtml(r);
167
+ }), i.apply(new u("Reorder product attributes"));
167
168
  }
168
169
  /**
169
170
  * Builds HTML string with attributes ordered according to composition
170
171
  */
171
172
  _buildCompositionHtml(t, e) {
172
- return e.reduce((i, r) => {
173
- const o = t.querySelector(`${b}[${p}="${r}"]`);
174
- return o && "getOuterHTML" in o ? i + o.getOuterHTML() : i;
173
+ return e.reduce((i, o) => {
174
+ const r = t.querySelector(`${c}[${d}="${o}"]`);
175
+ return r && "getOuterHTML" in r ? i + r.getOuterHTML() : i;
175
176
  }, "");
176
177
  }
177
178
  /**
@@ -183,21 +184,14 @@ class q extends O {
183
184
  _applyVisibilityToBlock(t, e) {
184
185
  if (!this.currentNode)
185
186
  return;
186
- const i = this.currentNode.querySelectorAll(`${b}[${p}="${t}"]`);
187
+ const i = this.currentNode.querySelectorAll(`${c}[${d}="${t}"]`);
187
188
  if (!(i != null && i.length))
188
189
  return;
189
- const r = e ? "1" : "0", o = `Set ${t} visibility to ${e ? "visible" : "hidden"}`, m = this.api.getDocumentModifier();
190
- i.forEach((l) => {
191
- let u = "TR";
192
- if ("tagName" in l && l.tagName)
193
- u = l.tagName.toUpperCase();
194
- else if ("getTagName" in l) {
195
- const _ = l;
196
- typeof _.getTagName == "function" && (u = _.getTagName().toUpperCase());
197
- }
198
- const h = e ? u === "TD" || u === "BLOCK_IMAGE" || u === "BLOCK_BUTTON" ? "table-cell" : "table-row" : "none";
199
- m.modifyHtml(l).setStyle("display", h).setAttribute(y, r);
200
- }), m.apply(new d(o));
190
+ const o = e ? "1" : "0", r = `Set ${t} visibility to ${e ? "visible" : "hidden"}`, b = this.api.getDocumentModifier();
191
+ i.forEach((p) => {
192
+ const y = I(p), h = e ? y : "none";
193
+ b.modifyHtml(p).setStyle("display", h).setAttribute(m, o);
194
+ }), b.apply(new u(r));
201
195
  }
202
196
  /**
203
197
  * Gets the current layout orientation from store or DOM
@@ -213,11 +207,11 @@ class q extends O {
213
207
  const e = this._getCurrentLayout() === "horizontal", i = this.getContainer();
214
208
  if (!i)
215
209
  return;
216
- const r = i.querySelector("[data-card-composition-control]");
217
- if (!r)
210
+ const o = i.querySelector("[data-card-composition-control]");
211
+ if (!o)
218
212
  return;
219
- const o = r.querySelector("ue-orderable");
220
- o && o.classList.toggle("orderable-disabled", e);
213
+ const r = o.querySelector("ue-orderable");
214
+ r && r.classList.toggle("orderable-disabled", e);
221
215
  }
222
216
  /**
223
217
  * Subscribe to store orientation changes
@@ -234,5 +228,5 @@ class q extends O {
234
228
  }
235
229
  export {
236
230
  S as COMPOSITION_CONTROL_BLOCK_ID,
237
- q as RecommendationCardCompositionControl
231
+ H as RecommendationCardCompositionControl
238
232
  };
@@ -1,29 +1,30 @@
1
- var h = Object.defineProperty;
2
- var p = (e, o, t) => o in e ? h(e, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[o] = t;
3
- var i = (e, o, t) => p(e, typeof o != "symbol" ? o + "" : o, t);
4
- import { ModificationDescription as a } from "../../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
5
- import { CommonControl as g } from "../../../common-control.js";
1
+ var g = Object.defineProperty;
2
+ var p = (e, o, t) => o in e ? g(e, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[o] = t;
3
+ var s = (e, o, t) => p(e, typeof o != "symbol" ? o + "" : o, t);
4
+ import { ModificationDescription as c } from "../../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
5
+ import { CommonControl as f } from "../../../common-control.js";
6
6
  import { CONTAINER_SELECTOR as C } from "../../constants/selectors.js";
7
- import { useRecommendationExtensionStore as f } from "../../store/recommendation.js";
8
- import { prepareProductRows as L } from "../../templates/index.js";
9
- import { getCurrentLayout as u, getBlockElement as T, getCurrentCardBackgroundColor as y, getCardComposition as N, applyCardBackgroundColor as _ } from "../main/utils.js";
10
- import { getDefaultProducts as O } from "../../templates/utils.js";
11
- const R = "recommendation-layout-control", s = {
7
+ import { RecommendationConfigService as i } from "../../services/configService.js";
8
+ import { useRecommendationExtensionStore as L } from "../../store/recommendation.js";
9
+ import { prepareProductRows as y } from "../../templates/index.js";
10
+ import { getCurrentLayout as d, getBlockElement as N, getCurrentCardBackgroundColor as T, getCardComposition as _, applyCardBackgroundColor as O } from "../main/utils.js";
11
+ import { getDefaultProducts as R } from "../../templates/utils.js";
12
+ const A = "recommendation-layout-control", a = {
12
13
  LAYOUT: "layout"
13
- }, A = {
14
+ }, U = {
14
15
  LAYOUT: "data-layout"
15
- }, U = [
16
+ }, w = [
16
17
  { text: "Vertical", value: "vertical" },
17
18
  { text: "Horizontal", value: "horizontal" }
18
19
  ];
19
- class I extends g {
20
+ class V extends f {
20
21
  constructor() {
21
22
  super(...arguments);
22
- i(this, "store", f());
23
- i(this, "isChangingLayout", !1);
23
+ s(this, "store", L());
24
+ s(this, "isChangingLayout", !1);
24
25
  }
25
26
  getId() {
26
- return R;
27
+ return A;
27
28
  }
28
29
  getTemplate() {
29
30
  return `
@@ -31,8 +32,8 @@ class I extends g {
31
32
  ${this._GuTwoColumns([
32
33
  this._GuLabel({ text: "Layout Orientation" }),
33
34
  this._GuRadioButton({
34
- name: s.LAYOUT,
35
- buttons: U
35
+ name: a.LAYOUT,
36
+ buttons: w
36
37
  })
37
38
  ])}
38
39
  </div>
@@ -45,27 +46,32 @@ class I extends g {
45
46
  super.onTemplateNodeUpdated(t), this._setFormValues();
46
47
  }
47
48
  _setFormValues() {
48
- const t = u(this.currentNode);
49
+ const r = i.getConfig(this.currentNode).layout || d(this.currentNode);
49
50
  this.api.updateValues({
50
- [s.LAYOUT]: t
51
+ [a.LAYOUT]: r
51
52
  });
52
53
  }
53
54
  /**
54
55
  * Handles layout change
55
- * Updates the block's data attribute and regenerates product rows
56
+ * Updates node config, data attribute and regenerates product rows
56
57
  */
57
58
  _onLayoutChange(t) {
58
- if (this.isChangingLayout || u(this.currentNode) === t)
59
+ if (this.isChangingLayout || !this.currentNode || (i.getConfig(this.currentNode).layout || d(this.currentNode)) === t)
59
60
  return;
60
- const r = T(this.currentNode);
61
- if (r) {
61
+ const n = N(this.currentNode);
62
+ if (n) {
62
63
  this.isChangingLayout = !0;
63
64
  try {
64
- this.store.$patch({
65
+ i.updateConfig(
66
+ this.api,
67
+ this.currentNode,
68
+ { layout: t },
69
+ `Changed layout to ${t}`
70
+ ), this.store.$patch({
65
71
  recommendationConfigs: {
66
72
  orientation: t
67
73
  }
68
- }), this.api.getDocumentModifier().modifyHtml(r).setAttribute(A.LAYOUT, t).apply(new a(`Update layout to ${t}`)), this._regenerateProductRows(t);
74
+ }), this.api.getDocumentModifier().modifyHtml(n).setAttribute(U.LAYOUT, t).apply(new c(`Update layout to ${t}`)), this._regenerateProductRows(t);
69
75
  } finally {
70
76
  this.isChangingLayout = !1;
71
77
  }
@@ -78,27 +84,27 @@ class I extends g {
78
84
  _regenerateProductRows(t) {
79
85
  if (!this.currentNode || !("querySelector" in this.currentNode))
80
86
  return;
81
- const n = this.currentNode.querySelector(C);
82
- if (!n)
87
+ const r = this.currentNode.querySelector(C);
88
+ if (!r)
83
89
  return;
84
- const r = y(this.currentNode), c = this.store.recommendationProducts.length > 0 ? this.store.recommendationProducts : O(), { cardsInRow: d } = this.store.recommendationConfigs, m = N(this.currentNode), l = L(c, t, {
85
- productsPerRow: d,
86
- composition: m
90
+ const u = T(this.currentNode), n = this.store.recommendationProducts.length > 0 ? this.store.recommendationProducts : R(), m = i.getConfig(this.currentNode), l = _(this.currentNode), h = y(n, t, {
91
+ productsPerRow: m.cardsInRow,
92
+ composition: l
87
93
  });
88
- this.api.getDocumentModifier().modifyHtml(n).setInnerHtml(l).apply(new a(`Regenerated products for ${t} layout`)), _({
94
+ this.api.getDocumentModifier().modifyHtml(r).setInnerHtml(h).apply(new c(`Regenerated products for ${t} layout`)), O({
89
95
  currentNode: this.currentNode,
90
96
  documentModifier: this.api.getDocumentModifier(),
91
- bgColor: r,
97
+ bgColor: u,
92
98
  layout: t
93
99
  });
94
100
  }
95
101
  _listenToFormUpdates() {
96
- this.api.onValueChanged(s.LAYOUT, (t) => {
102
+ this.api.onValueChanged(a.LAYOUT, (t) => {
97
103
  this._onLayoutChange(t);
98
104
  });
99
105
  }
100
106
  }
101
107
  export {
102
- R as LAYOUT_CONTROL_ID,
103
- I as LayoutControl
108
+ A as LAYOUT_CONTROL_ID,
109
+ V as LayoutControl
104
110
  };
@@ -1,20 +1,22 @@
1
- var r = Object.defineProperty;
2
- var a = (s, i, t) => i in s ? r(s, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[i] = t;
3
- var n = (s, i, t) => a(s, typeof i != "symbol" ? i + "" : i, t);
4
- import { UEAttr as l } from "../../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
5
- import { CommonControl as m } from "../../../common-control.js";
6
- import { useRecommendationExtensionStore as h } from "../../store/recommendation.js";
7
- const c = "recommendation-algorithm-control", e = {
1
+ var d = Object.defineProperty;
2
+ var c = (o, i, t) => i in o ? d(o, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[i] = t;
3
+ var a = (o, i, t) => c(o, typeof i != "symbol" ? i + "" : i, t);
4
+ import { UEAttr as h } from "../../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
5
+ import { CommonControl as l } from "../../../common-control.js";
6
+ import { RecommendationConfigService as n } from "../../services/configService.js";
7
+ import { useRecommendationExtensionStore as m } from "../../store/recommendation.js";
8
+ const g = "recommendation-algorithm-control", e = {
8
9
  ALGORITHM: "strategy",
9
10
  PRODUCT_IDS: "productIds"
10
11
  };
11
- class _ extends m {
12
+ class T extends l {
12
13
  constructor() {
13
14
  super(...arguments);
14
- n(this, "store", h());
15
+ // Store is used ONLY for API-fetched data (algorithms list), not for config
16
+ a(this, "store", m());
15
17
  }
16
18
  getId() {
17
- return c;
19
+ return g;
18
20
  }
19
21
  getTemplate() {
20
22
  return `
@@ -39,36 +41,58 @@ class _ extends m {
39
41
  onRender() {
40
42
  this._initializeSelectItems(), this._setFormValues(), this._listenToFormUpdates();
41
43
  }
44
+ onTemplateNodeUpdated(t) {
45
+ super.onTemplateNodeUpdated(t), this._setFormValues();
46
+ }
42
47
  _setFormValues() {
43
- const { recommendationConfigs: t } = this.store;
44
- this._setProductIdsVisibility(), this.api.updateValues({
48
+ const t = n.getConfig(this.currentNode);
49
+ this._setProductIdsVisibility(t.strategy), this.api.updateValues({
45
50
  [e.ALGORITHM]: t.strategy,
46
51
  [e.PRODUCT_IDS]: t.productIds.join(",")
47
52
  });
48
53
  }
49
54
  _initializeSelectItems() {
50
- this.api.setUIEAttribute(
51
- e.ALGORITHM,
52
- l.SELECTPICKER.items,
53
- this.store.getActivePredictiveAlgorithms
54
- );
55
+ var s;
56
+ const t = (s = this.store) == null ? void 0 : s.getActivePredictiveAlgorithms;
57
+ if (t != null && t.length)
58
+ try {
59
+ this.api.setUIEAttribute(
60
+ e.ALGORITHM,
61
+ h.SELECTPICKER.items,
62
+ t
63
+ );
64
+ } catch (r) {
65
+ console.warn("[AlgorithmControl] Failed to set algorithm options:", r);
66
+ }
55
67
  }
56
- _setProductIdsVisibility() {
57
- const { recommendationConfigs: t } = this.store, o = t.strategy === "manualMerchandising";
58
- this.api.setVisibility(e.PRODUCT_IDS, o), this.api.setVisibility(`${e.PRODUCT_IDS}_label`, o);
68
+ _setProductIdsVisibility(t) {
69
+ const r = (t ?? n.getConfig(this.currentNode).strategy) === "manualMerchandising";
70
+ this.api.setVisibility(e.PRODUCT_IDS, r), this.api.setVisibility(`${e.PRODUCT_IDS}_label`, r);
59
71
  }
60
72
  _onAlgorithmChange(t) {
61
- this.store.$patch({
73
+ this.currentNode && (n.updateConfig(
74
+ this.api,
75
+ this.currentNode,
76
+ { strategy: t },
77
+ `Changed algorithm to ${t}`
78
+ ), this.store.$patch({
62
79
  recommendationConfigs: {
63
80
  strategy: t
64
81
  }
65
- }), this._setProductIdsVisibility();
82
+ }), this._setProductIdsVisibility(t));
66
83
  }
67
84
  _onProductIdsChange(t) {
68
- const o = t.split(",").filter(Boolean);
69
- this.store.$patch({
85
+ if (!this.currentNode)
86
+ return;
87
+ const s = t.split(",").map((r) => r.trim()).filter(Boolean);
88
+ n.updateConfig(
89
+ this.api,
90
+ this.currentNode,
91
+ { productIds: s },
92
+ "Updated product IDs"
93
+ ), this.store.$patch({
70
94
  recommendationConfigs: {
71
- productIds: o
95
+ productIds: s
72
96
  }
73
97
  });
74
98
  }
@@ -81,6 +105,6 @@ class _ extends m {
81
105
  }
82
106
  }
83
107
  export {
84
- c as ALGORITHM_CONTROL_ID,
85
- _ as AlgorithmControl
108
+ g as ALGORITHM_CONTROL_ID,
109
+ T as AlgorithmControl
86
110
  };