@useinsider/guido 3.20.0 → 3.20.1-beta.04cd240

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 (78) hide show
  1. package/dist/composables/useLegacyStrategyConversion.js +16 -16
  2. package/dist/composables/useStripo.js +11 -10
  3. package/dist/composables/useVersionHistoryApi.js +42 -37
  4. package/dist/config/compiler/itemsCompilerRules.js +21 -5
  5. package/dist/config/compiler/utils/itemsCompilerUtils.js +64 -17
  6. package/dist/config/migrator/itemsBlockMigrator.js +112 -108
  7. package/dist/extensions/Blocks/Items/block.js +76 -64
  8. package/dist/extensions/Blocks/Items/constants/cardWidth.js +20 -0
  9. package/dist/extensions/Blocks/Items/layouts/vertical.html.js +1 -1
  10. package/dist/extensions/Blocks/Recommendation/block.js +60 -49
  11. package/dist/extensions/Blocks/Recommendation/controls/cardComposition/index.js +163 -149
  12. package/dist/extensions/Blocks/Recommendation/controls/customAttribute/textTrim.js +1 -2
  13. package/dist/extensions/Blocks/Recommendation/controls/main/currency.js +102 -78
  14. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +313 -210
  15. package/dist/extensions/Blocks/Recommendation/controls/main/layoutOrientation.js +15 -13
  16. package/dist/extensions/Blocks/Recommendation/controls/main/pricePlacement.js +17 -12
  17. package/dist/extensions/Blocks/Recommendation/controls/main/productLayout.js +92 -84
  18. package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +219 -193
  19. package/dist/extensions/Blocks/Recommendation/controls/mobileLayout/cssRules.js +23 -18
  20. package/dist/extensions/Blocks/Recommendation/controls/name/textTrim.js +1 -2
  21. package/dist/extensions/Blocks/Recommendation/controls/shared/textTrimCssRules.js +6 -6
  22. package/dist/extensions/Blocks/Recommendation/controls/spacing/index.js +12 -9
  23. package/dist/extensions/Blocks/Recommendation/extension.js +4 -2
  24. package/dist/extensions/Blocks/Recommendation/settingsPanel.js +4 -2
  25. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +240 -190
  26. package/dist/extensions/Blocks/Recommendation/utils/blockRefresh.js +19 -0
  27. package/dist/extensions/Blocks/Recommendation/utils/blockUrlConfig.js +25 -0
  28. package/dist/extensions/Blocks/Recommendation/utils/captureStyleTemplates.js +72 -70
  29. package/dist/extensions/Blocks/Recommendation/utils/compositionKeys.js +69 -60
  30. package/dist/extensions/Blocks/Recommendation/utils/followUpApply.js +34 -0
  31. package/dist/extensions/Blocks/Recommendation/utils/nodeConfigWriter.js +73 -28
  32. package/dist/extensions/Blocks/Recommendation/utils/restoreRefresh.js +36 -0
  33. package/dist/extensions/Blocks/Recommendation/utils/strategyCommit.js +39 -20
  34. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +271 -192
  35. package/dist/package.json.js +1 -1
  36. package/dist/src/config/compiler/utils/itemsCompilerUtils.d.ts +10 -0
  37. package/dist/src/extensions/Blocks/Checkbox/controls/blockBackground/index.d.ts +1 -0
  38. package/dist/src/extensions/Blocks/CouponBlock/controls/index.d.ts +8 -0
  39. package/dist/src/extensions/Blocks/Items/block.d.ts +5 -0
  40. package/dist/src/extensions/Blocks/Items/constants/cardWidth.d.ts +12 -0
  41. package/dist/src/extensions/Blocks/Items/controls/index.d.ts +40 -0
  42. package/dist/src/extensions/Blocks/RadioButton/controls/blockBackground/index.d.ts +1 -0
  43. package/dist/src/extensions/Blocks/Recommendation/block.d.ts +3 -0
  44. package/dist/src/extensions/Blocks/Recommendation/controls/blockBackground/index.d.ts +1 -0
  45. package/dist/src/extensions/Blocks/Recommendation/controls/button/index.d.ts +11 -0
  46. package/dist/src/extensions/Blocks/Recommendation/controls/cardComposition/index.d.ts +3 -0
  47. package/dist/src/extensions/Blocks/Recommendation/controls/customAttribute/index.d.ts +7 -0
  48. package/dist/src/extensions/Blocks/Recommendation/controls/image/index.d.ts +2 -0
  49. package/dist/src/extensions/Blocks/Recommendation/controls/main/currency.d.ts +3 -0
  50. package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +22 -3
  51. package/dist/src/extensions/Blocks/Recommendation/controls/main/productLayout.d.ts +1 -18
  52. package/dist/src/extensions/Blocks/Recommendation/controls/main/utils.d.ts +8 -0
  53. package/dist/src/extensions/Blocks/Recommendation/controls/mobileLayout/cssRules.d.ts +10 -6
  54. package/dist/src/extensions/Blocks/Recommendation/controls/name/index.d.ts +7 -0
  55. package/dist/src/extensions/Blocks/Recommendation/controls/oldPrice/index.d.ts +7 -0
  56. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusDiscount/index.d.ts +7 -0
  57. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusPrice/index.d.ts +7 -0
  58. package/dist/src/extensions/Blocks/Recommendation/controls/price/index.d.ts +7 -0
  59. package/dist/src/extensions/Blocks/Recommendation/controls/shared/textTrimCssRules.d.ts +2 -3
  60. package/dist/src/extensions/Blocks/Recommendation/controls/spacing/index.d.ts +1 -1
  61. package/dist/src/extensions/Blocks/Recommendation/controls/title/index.d.ts +7 -0
  62. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +28 -6
  63. package/dist/src/extensions/Blocks/Recommendation/utils/blockRefresh.d.ts +19 -0
  64. package/dist/src/extensions/Blocks/Recommendation/utils/blockUrlConfig.d.ts +4 -0
  65. package/dist/src/extensions/Blocks/Recommendation/utils/compositionKeys.d.ts +4 -0
  66. package/dist/src/extensions/Blocks/Recommendation/utils/followUpApply.d.ts +20 -0
  67. package/dist/src/extensions/Blocks/Recommendation/utils/nodeConfigWriter.d.ts +15 -2
  68. package/dist/src/extensions/Blocks/Recommendation/utils/restoreRefresh.d.ts +2 -0
  69. package/dist/src/extensions/Blocks/Recommendation/utils/strategyCommit.d.ts +7 -0
  70. package/dist/src/extensions/Blocks/_Boilerplate/controls/blockBackground/index.d.ts +1 -0
  71. package/dist/src/extensions/Blocks/controlFactories.d.ts +22 -0
  72. package/dist/src/stores/editor.d.ts +3 -1
  73. package/dist/src/utils/liquidProtection.d.ts +3 -0
  74. package/dist/static/styles/components/button.css.js +5 -0
  75. package/dist/stores/editor.js +5 -0
  76. package/dist/utils/liquidProtection.js +5 -0
  77. package/dist/utils/templatePreparation.js +61 -85
  78. package/package.json +3 -3
@@ -1,39 +1,40 @@
1
- var C = Object.defineProperty;
2
- var p = (g, u, t) => u in g ? C(g, u, { enumerable: !0, configurable: !0, writable: !0, value: t }) : g[u] = t;
3
- var i = (g, u, t) => p(g, typeof u != "symbol" ? u + "" : u, t);
4
- import { useConfig as h } from "../../../../../composables/useConfig.js";
5
- import { ModificationDescription as y } from "../../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
1
+ var _ = Object.defineProperty;
2
+ var y = (h, c, e) => c in h ? _(h, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : h[c] = e;
3
+ var i = (h, c, e) => y(h, typeof c != "symbol" ? c + "" : c, e);
4
+ import { useConfig as g } from "../../../../../composables/useConfig.js";
6
5
  import { CommonControl as N } from "../../../common-control.js";
7
- import { RRS_CONFIG_VERSION as _, DEFAULT_NODE_CONFIG as a } from "../../constants/defaultConfig.js";
8
- import { RECOMMENDATION_ID_ATTR as I } from "../../constants/selectors.js";
9
- import { RecommendationConfigService as c } from "../../services/configService.js";
6
+ import { RRS_CONFIG_VERSION as P, DEFAULT_NODE_CONFIG as l } from "../../constants/defaultConfig.js";
7
+ import { RECOMMENDATION_ID_ATTR as k } from "../../constants/selectors.js";
8
+ import { RecommendationConfigService as d } from "../../services/configService.js";
10
9
  import { useRecommendationExtensionStore as R } from "../../store/recommendation.js";
11
- import { registerNodeConfigWriter as b } from "../../utils/nodeConfigWriter.js";
12
- import { AlgorithmControl as T } from "./algorithm.js";
13
- import { ALGORITHM_CONTROL_ID as ut } from "./algorithm.js";
14
- import { CurrencyControl as P } from "./currency.js";
15
- import { CURRENCY_CONTROL_ID as gt } from "./currency.js";
16
- import { FiltersControl as S } from "./filters.js";
17
- import { FILTERS_CONTROL_ID as ft } from "./filters.js";
18
- import { LayoutOrientationControl as O } from "./layoutOrientation.js";
19
- import { LAYOUT_ORIENTATION_CONTROL_ID as Ct } from "./layoutOrientation.js";
20
- import { LocaleControl as L } from "./locale.js";
21
- import { LOCALE_CONTROL_ID as yt } from "./locale.js";
22
- import { PricePlacementControl as k } from "./pricePlacement.js";
23
- import { PRICE_PLACEMENT_CONTROL_ID as _t } from "./pricePlacement.js";
24
- import { ProductCountControl as E } from "./productCount.js";
25
- import { PRODUCT_COUNT_CONTROL_ID as Rt } from "./productCount.js";
26
- import { ProductLayoutControl as F } from "./productLayout.js";
27
- import { PRODUCT_LAYOUT_CONTROL_ID as Tt } from "./productLayout.js";
28
- import { ShuffleControl as D } from "./shuffle.js";
29
- import { SHUFFLE_CONTROL_ID as St } from "./shuffle.js";
30
- import { StrategyControl as w } from "./strategy.js";
31
- import { STRATEGY_CONTROL_ID as Lt } from "./strategy.js";
32
- import { setCurrencyAttributes as v, getBlockElement as A, isPartnerManagedBlock as B, updateProductContentInPlace as x, regenerateProductRowsWithStyles as U } from "./utils.js";
33
- import { adjustProductsToSize as Et, formatProductPrice as Ft, getCardComposition as Dt, getCurrentLayout as wt, getMainContainerTbody as vt, regenerateMobileProductRows as At, updatePricesInPlace as Bt, updateSingleProductContent as xt } from "./utils.js";
34
- import { useDebounceFn as f } from "../../../../../node_modules/@vueuse/shared/index.js";
35
- const W = "ui-elements-recommendation-block";
36
- class at extends N {
10
+ import { refreshBlockOutsidePanel as I } from "../../utils/blockRefresh.js";
11
+ import { captureUndoTop as S, isUndoTopUnchanged as b, applyFollowUp as T } from "../../utils/followUpApply.js";
12
+ import { registerNodeConfigWriter as O, writeBlockConfigOutsidePanel as m, hasEditedConfigChange as B } from "../../utils/nodeConfigWriter.js";
13
+ import { AlgorithmControl as U } from "./algorithm.js";
14
+ import { ALGORITHM_CONTROL_ID as pe } from "./algorithm.js";
15
+ import { CurrencyControl as E } from "./currency.js";
16
+ import { CURRENCY_CONTROL_ID as ye } from "./currency.js";
17
+ import { FiltersControl as L } from "./filters.js";
18
+ import { FILTERS_CONTROL_ID as Pe } from "./filters.js";
19
+ import { LayoutOrientationControl as F } from "./layoutOrientation.js";
20
+ import { LAYOUT_ORIENTATION_CONTROL_ID as Re } from "./layoutOrientation.js";
21
+ import { LocaleControl as w } from "./locale.js";
22
+ import { LOCALE_CONTROL_ID as Se } from "./locale.js";
23
+ import { PricePlacementControl as A } from "./pricePlacement.js";
24
+ import { PRICE_PLACEMENT_CONTROL_ID as Te } from "./pricePlacement.js";
25
+ import { ProductCountControl as D } from "./productCount.js";
26
+ import { PRODUCT_COUNT_CONTROL_ID as Be } from "./productCount.js";
27
+ import { ProductLayoutControl as v } from "./productLayout.js";
28
+ import { PRODUCT_LAYOUT_CONTROL_ID as Ee } from "./productLayout.js";
29
+ import { ShuffleControl as V } from "./shuffle.js";
30
+ import { SHUFFLE_CONTROL_ID as Fe } from "./shuffle.js";
31
+ import { StrategyControl as x } from "./strategy.js";
32
+ import { STRATEGY_CONTROL_ID as Ae } from "./strategy.js";
33
+ import { setCurrencyAttributes as W, getBlockElement as G, isPartnerManagedBlock as M, updateProductContentInPlace as z, regenerateProductRowsWithStyles as $ } from "./utils.js";
34
+ import { adjustProductsToSize as ve, formatProductPrice as Ve, getCardComposition as xe, getCurrencyAttributesFromBlock as We, getCurrentLayout as Ge, getMainContainerTbody as Me, regenerateMobileProductRows as ze, updatePricesInPlace as $e, updateSingleProductContent as He } from "./utils.js";
35
+ import { useDebounceFn as C } from "../../../../../node_modules/@vueuse/shared/index.js";
36
+ const f = "Update recommendation filters", H = "ui-elements-recommendation-block";
37
+ class ge extends N {
37
38
  constructor() {
38
39
  super(...arguments);
39
40
  i(this, "store", R());
@@ -43,6 +44,14 @@ class at extends N {
43
44
  // re-render's single apply() — one user action must cost one undo press.
44
45
  i(this, "pendingNodeConfigWrite", null);
45
46
  i(this, "pendingConfigFlushTimer", null);
47
+ // What the panel still owes the block it watches — finished outside the panel on teardown
48
+ // and block switch. A new generation tells debounced work queued for the old one to stand down.
49
+ i(this, "trackedBlockId", null);
50
+ i(this, "fetchedConfigVersion", 0);
51
+ i(this, "hasUnrenderedProducts", !1);
52
+ i(this, "followUpAnchor", null);
53
+ i(this, "panelGeneration", 0);
54
+ i(this, "isPanelAlive", !0);
46
55
  // Sub-control instances for lifecycle management
47
56
  i(this, "algorithmControl", null);
48
57
  i(this, "localeControl", null);
@@ -58,11 +67,15 @@ class at extends N {
58
67
  /**
59
68
  * Debounced product fetch to prevent rapid API calls during config changes
60
69
  */
61
- i(this, "_debouncedFetchProducts", f(async () => {
70
+ i(this, "_debouncedFetchProducts", C(async (e, t) => {
71
+ if (t !== this.panelGeneration)
72
+ return;
73
+ this.followUpAnchor = S();
74
+ const o = this._getBlockConfigVersion(e);
62
75
  try {
63
- await this.store.fetchRecommendationProducts();
76
+ await (e === null ? this.store.fetchRecommendationProducts() : this.store.fetchRecommendationProductsForBlock(e)), t === this.panelGeneration && (this.fetchedConfigVersion = Math.max(this.fetchedConfigVersion, o));
64
77
  } finally {
65
- this._scheduleConfigFlush();
78
+ t === this.panelGeneration && this._scheduleConfigFlush();
66
79
  }
67
80
  }, 500));
68
81
  /**
@@ -76,28 +89,26 @@ class at extends N {
76
89
  * count. The store pads products to the configured size, so in-place only
77
90
  * fails when the size actually changed.
78
91
  */
79
- i(this, "_debouncedRegenerateWithProducts", f(() => {
80
- const t = this.store.recommendationProducts;
81
- if (!this.currentNode || !this.api)
92
+ i(this, "_debouncedRegenerateWithProducts", C((e) => {
93
+ if (e !== this.panelGeneration || !this.currentNode || !this.api)
82
94
  return;
83
- const e = this.api.getDocumentModifier(), o = this._stagePendingNodeConfig(e);
84
- if (B(this.currentNode)) {
85
- o && (e.apply(new y("Update recommendation configuration")), this.pendingNodeConfigWrite = null, this._clearConfigFlush());
95
+ const t = this._getRecommendationIdFromNode(this.currentNode), o = this.store.currentRecommendationId;
96
+ if (t === null || o === null || t === o || !this.store.blockStates[t]) {
97
+ this.hasUnrenderedProducts = !1, this._regenerateWithProducts();
86
98
  return;
87
99
  }
88
- x({
89
- currentNode: this.currentNode,
90
- documentModifier: e,
91
- products: t
92
- }) || U({
93
- currentNode: this.currentNode,
94
- documentModifier: e,
95
- products: t
96
- });
100
+ if (this.store.blockStates[t].recommendationProducts.length) {
101
+ this.store.setCurrentBlock(t);
102
+ try {
103
+ this._regenerateWithProducts();
104
+ } finally {
105
+ this.store.setCurrentBlock(o);
106
+ }
107
+ }
97
108
  }, 100));
98
109
  }
99
110
  getId() {
100
- return W;
111
+ return H;
101
112
  }
102
113
  get _subControls() {
103
114
  return [
@@ -114,15 +125,15 @@ class at extends N {
114
125
  ];
115
126
  }
116
127
  getTemplate() {
117
- var t;
118
- return this.rrsEnabled = h().isFeatureEnabled("reusableRecommendationStrategy"), this._subControls.forEach((e) => {
128
+ var e;
129
+ return this.rrsEnabled = g().isFeatureEnabled("reusableRecommendationStrategy"), this._subControls.forEach((t) => {
119
130
  var o;
120
- return (o = e == null ? void 0 : e.onDestroy) == null ? void 0 : o.call(e);
121
- }), this.algorithmControl = new T(), this.localeControl = new L(), this.currencyControl = new P(), this.productCountControl = new E(), this.productLayoutControl = new F(), this.filtersControl = new S(), this.shuffleControl = new D(), this.pricePlacementControl = new k(), this.layoutOrientationControl = new O(), this.strategyControl = this.rrsEnabled ? new w() : null, this._subControls.forEach((e) => {
122
- e && (e.api = this.api);
131
+ return (o = t == null ? void 0 : t.onDestroy) == null ? void 0 : o.call(t);
132
+ }), this.algorithmControl = new U(), this.localeControl = new w(), this.currencyControl = new E(), this.productCountControl = new D(), this.productLayoutControl = new v(), this.filtersControl = new L(), this.shuffleControl = new V(), this.pricePlacementControl = new A(), this.layoutOrientationControl = new F(), this.strategyControl = this.rrsEnabled ? new x() : null, this._subControls.forEach((t) => {
133
+ t && (t.api = this.api);
123
134
  }), `
124
135
  <div class="recommendation-controls-container">
125
- ${((t = this.strategyControl) == null ? void 0 : t.getTemplate()) ?? ""}
136
+ ${((e = this.strategyControl) == null ? void 0 : e.getTemplate()) ?? ""}
126
137
  ${this.layoutOrientationControl.getTemplate()}
127
138
  ${this.productCountControl.getTemplate()}
128
139
  ${this.productLayoutControl.getTemplate()}
@@ -135,39 +146,39 @@ class at extends N {
135
146
  </div>
136
147
  `;
137
148
  }
138
- _showControlsForBlock(t) {
149
+ _showControlsForBlock(e) {
139
150
  var r;
140
- const e = (r = this.getContainer()) == null ? void 0 : r.querySelector(".recommendation-controls-container");
141
- if (!e)
151
+ const t = (r = this.getContainer()) == null ? void 0 : r.querySelector(".recommendation-controls-container");
152
+ if (!t)
142
153
  return;
143
- const o = this._getRecommendationIdFromNode(t) === null ? null : c.getConfig(t), n = this.rrsEnabled && !!o && (!!(o != null && o.strategyId) || ((o == null ? void 0 : o.configVersion) ?? 0) >= _), s = this.rrsEnabled && !!o && !n;
144
- e.classList.toggle("strategy-block", n), e.classList.toggle("legacy-strategy-block", s);
154
+ const o = this._getRecommendationIdFromNode(e) === null ? null : d.getConfig(e), n = this.rrsEnabled && !!o && (!!(o != null && o.strategyId) || ((o == null ? void 0 : o.configVersion) ?? 0) >= P), s = this.rrsEnabled && !!o && !n;
155
+ t.classList.toggle("strategy-block", n), t.classList.toggle("legacy-strategy-block", s);
145
156
  }
146
157
  async onRender() {
147
158
  var o;
148
- b(this.api);
149
- const t = this._getRecommendationIdFromNode(this.currentNode), e = t ?? this.store.currentRecommendationId;
150
- if (e !== null && this.store.setCurrentBlock(e), t !== null && this._syncNodeConfigIfChanged(t), this._listenStateUpdates(), this._showControlsForBlock(this.currentNode), t !== null && this.strategyControl && (this.strategyControl.api = this.api, this.strategyControl.currentNode = this.currentNode, this.strategyControl.onRender()), e !== null && ((o = this.store.blockStates[e]) != null && o.isInitialized)) {
159
+ O(this.api);
160
+ const e = this._getRecommendationIdFromNode(this.currentNode), t = e ?? this.store.currentRecommendationId;
161
+ if (t !== null && this.store.setCurrentBlock(t), e !== null && this._syncNodeConfigIfChanged(e), this._listenStateUpdates(), this._showControlsForBlock(this.currentNode), e !== null && this.strategyControl && (this.strategyControl.api = this.api, this.strategyControl.currentNode = this.currentNode, this.strategyControl.onRender()), t !== null && ((o = this.store.blockStates[t]) != null && o.isInitialized)) {
151
162
  this._initializeSubControls();
152
163
  return;
153
164
  }
154
- await this._fetchBlockData(e), this._initializeSubControls();
165
+ await this._fetchBlockData(t), this._initializeSubControls();
155
166
  }
156
- onTemplateNodeUpdated(t) {
167
+ onTemplateNodeUpdated(e) {
157
168
  var o;
158
- super.onTemplateNodeUpdated(t);
159
- const e = this._getRecommendationIdFromNode(t);
160
- e !== null && e !== this.store.currentRecommendationId && this.store.setCurrentBlock(e), e !== null && this._syncNodeConfigIfChanged(e), this._showControlsForBlock(t), e !== null && !((o = this.store.blockStates[e]) != null && o.isInitialized) && this._fetchBlockData(e).then(() => {
169
+ super.onTemplateNodeUpdated(e);
170
+ const t = this._getRecommendationIdFromNode(e);
171
+ t !== null && t !== this.store.currentRecommendationId && this.store.setCurrentBlock(t), t !== null && this._syncNodeConfigIfChanged(t), this._showControlsForBlock(e), t !== null && !((o = this.store.blockStates[t]) != null && o.isInitialized) && this._fetchBlockData(t).then(() => {
161
172
  this._initializeSubControls();
162
173
  }), this._subControls.forEach((n) => {
163
174
  var s;
164
- n != null && n.api && (n.currentNode = t, (s = n.onTemplateNodeUpdated) == null || s.call(n, t));
175
+ n != null && n.api && (n.currentNode = e, (s = n.onTemplateNodeUpdated) == null || s.call(n, e));
165
176
  });
166
177
  }
167
178
  onDestroy() {
168
- this.storeUnsubscription(), this._flushPendingNodeConfig(), this._subControls.forEach((t) => {
169
- var e;
170
- return (e = t == null ? void 0 : t.onDestroy) == null ? void 0 : e.call(t);
179
+ this.panelGeneration++, this.isPanelAlive = !1, this.storeUnsubscription(), this._finishBlockOutsidePanel(), this.hasUnrenderedProducts = !1, this._subControls.forEach((e) => {
180
+ var t;
181
+ return (t = e == null ? void 0 : e.onDestroy) == null ? void 0 : t.call(e);
171
182
  });
172
183
  }
173
184
  /**
@@ -175,9 +186,9 @@ class at extends N {
175
186
  * Each sub-control manages its own form values and event listeners
176
187
  */
177
188
  _initializeSubControls() {
178
- this._subControls.forEach((t) => {
179
- var e;
180
- t && (t.api = this.api, t.currentNode = this.currentNode, (e = t.onRender) == null || e.call(t));
189
+ this._subControls.forEach((e) => {
190
+ var t;
191
+ e && (e.api = this.api, e.currentNode = this.currentNode, (t = e.onRender) == null || t.call(e));
181
192
  });
182
193
  }
183
194
  /**
@@ -204,35 +215,36 @@ class at extends N {
204
215
  * that state and made a re-dropped saved module keep the defaults its wiped
205
216
  * state was rebuilt with (SD-150347).
206
217
  */
207
- _syncNodeConfigIfChanged(t) {
208
- this.pendingNodeConfigWrite && this.pendingNodeConfigWrite.blockId !== t && this._flushPendingNodeConfig();
209
- const e = this.store.blockStates[t];
210
- if (!e)
218
+ _syncNodeConfigIfChanged(e) {
219
+ var s;
220
+ this.pendingNodeConfigWrite && this.pendingNodeConfigWrite.blockId !== e && this._flushPendingNodeConfig();
221
+ const t = this.store.blockStates[e];
222
+ if (!t)
211
223
  return;
212
- const o = JSON.stringify(c.getConfig(this.currentNode)), n = e.syncedConfigFingerprint;
213
- e.syncedConfigFingerprint = o, n !== o && (this.pendingNodeConfigWrite || this._syncNodeConfigToStore());
224
+ const o = JSON.stringify(d.getConfig(this.currentNode)), n = t.syncedConfigFingerprint;
225
+ t.syncedConfigFingerprint = o, n !== o && ((s = this.pendingNodeConfigWrite) == null ? void 0 : s.blockId) !== e && this._syncNodeConfigToStore();
214
226
  }
215
227
  /** Whether the deferred write would move the node's strategyId — see the caller (SD-149916). */
216
228
  _isPendingStrategyIdChange() {
217
- const t = this.pendingNodeConfigWrite;
218
- return t ? c.getConfig(this.currentNode).strategyId !== t.updates.strategyId : !1;
229
+ const e = this.pendingNodeConfigWrite;
230
+ return e ? d.getConfig(this.currentNode).strategyId !== e.updates.strategyId : !1;
219
231
  }
220
232
  _capturePendingNodeConfigWrite() {
221
- const t = this.store.currentRecommendationId;
222
- if (!this.currentNode || !this.api || t === null)
223
- return;
224
- const { filters: e, strategy: o, strategyId: n, size: s, nodeConfigVersion: r } = this.store.recommendationConfigs, { partnerName: l } = h();
225
- this.pendingNodeConfigWrite = {
226
- blockId: t,
227
- node: this.currentNode,
228
- updates: {
229
- filters: e,
230
- strategy: o,
231
- strategyId: n,
232
- size: s,
233
- configVersion: r,
234
- ...l.value ? { partnerName: l.value } : {}
235
- }
233
+ const e = this.store.currentRecommendationId, t = e === null ? void 0 : this.store.blockStates[e];
234
+ !this.currentNode || !this.api || e === null || !t || (this.pendingNodeConfigWrite = {
235
+ blockId: e,
236
+ updates: this._getNodeConfigUpdates(t.recommendationConfigs)
237
+ });
238
+ }
239
+ _getNodeConfigUpdates(e) {
240
+ const { filters: t, strategy: o, strategyId: n, size: s, nodeConfigVersion: r } = e, { partnerName: a } = g();
241
+ return {
242
+ filters: t,
243
+ strategy: o,
244
+ strategyId: n,
245
+ size: s,
246
+ configVersion: r,
247
+ ...a.value ? { partnerName: a.value } : {}
236
248
  };
237
249
  }
238
250
  /**
@@ -245,9 +257,9 @@ class at extends N {
245
257
  * @param documentModifier - The batch to accumulate into
246
258
  * @returns Whether anything was staged
247
259
  */
248
- _stagePendingNodeConfig(t) {
249
- const e = this.pendingNodeConfigWrite;
250
- return !e || !this.currentNode ? !1 : (c.stageConfig(t, this.currentNode, e.updates), !0);
260
+ _stagePendingNodeConfig(e) {
261
+ const t = this.pendingNodeConfigWrite;
262
+ return !t || !this.currentNode ? !1 : (d.stageConfig(e, this.currentNode, t.updates), !0);
251
263
  }
252
264
  /**
253
265
  * Arms the guaranteed fallback write, once the product fetch has settled. The
@@ -264,45 +276,57 @@ class at extends N {
264
276
  }
265
277
  /**
266
278
  * Writes the deferred change standalone when the batch it was staged into never
267
- * committed. Always targets the LIVE node — the captured one is an immutable
268
- * snapshot the intervening re-render staled, and saveConfig swallows that failure.
279
+ * committed. Always targets a LIVE node — a captured one is an immutable snapshot
280
+ * the intervening re-render staled, and saveConfig swallows that failure.
269
281
  */
270
282
  _flushPendingNodeConfig() {
271
- const t = this.pendingNodeConfigWrite;
272
- if (this.pendingNodeConfigWrite = null, this._clearConfigFlush(), !t || !this.api)
273
- return;
274
- const e = t.blockId === this.store.currentRecommendationId && this.currentNode ? this.currentNode : t.node, o = c.getConfig(e);
275
- JSON.stringify(o.filters) === JSON.stringify(t.updates.filters) && o.strategy === t.updates.strategy && o.strategyId === t.updates.strategyId && o.size === t.updates.size || c.updateConfig(this.api, e, t.updates, "Update recommendation filters");
283
+ const e = this.pendingNodeConfigWrite;
284
+ if (this.pendingNodeConfigWrite = null, this._clearConfigFlush(), !(!e || !this.api)) {
285
+ if (e.blockId !== this.store.currentRecommendationId || !this.currentNode) {
286
+ const { blockId: t, updates: o } = e;
287
+ !m(t, o, f) && this.store.blockStates[t] && console.error("[recommendation] pending config write did not reach a node", { blockId: t });
288
+ return;
289
+ }
290
+ this._isEditedConfigChange(e) && d.updateConfig(
291
+ this.api,
292
+ this.currentNode,
293
+ e.updates,
294
+ f
295
+ );
296
+ }
297
+ }
298
+ _isEditedConfigChange(e) {
299
+ return !e || !this.currentNode ? !1 : B(this.currentNode, e.updates);
276
300
  }
277
301
  _syncNodeConfigToStore() {
278
302
  var n;
279
- const t = c.getConfig(this.currentNode), e = this.store.currentRecommendationId, o = e !== null && ((n = this.store.blockStates[e]) == null ? void 0 : n.isInitialized);
303
+ const e = d.getConfig(this.currentNode), t = this.store.currentRecommendationId, o = t !== null && ((n = this.store.blockStates[t]) == null ? void 0 : n.isInitialized);
280
304
  this.store.patchCurrentBlockConfig({
281
- strategy: t.strategy,
282
- strategyId: t.strategyId,
283
- nodeConfigVersion: t.configVersion,
284
- language: t.language,
285
- size: t.size,
286
- productIds: t.productIds,
287
- cardsInRow: t.cardsInRow,
288
- mobileCardsInRow: t.mobileCardsInRow,
289
- mobileLayoutEnabled: t.mobileLayoutEnabled,
290
- orientation: t.layout,
305
+ strategy: e.strategy,
306
+ strategyId: e.strategyId,
307
+ nodeConfigVersion: e.configVersion,
308
+ language: e.language,
309
+ size: e.size,
310
+ productIds: e.productIds,
311
+ cardsInRow: e.cardsInRow,
312
+ mobileCardsInRow: e.mobileCardsInRow,
313
+ mobileLayoutEnabled: e.mobileLayoutEnabled,
314
+ orientation: e.layout,
291
315
  // Only sync filters from node config during initial load.
292
316
  // After initialization, the Pinia store is the source of truth
293
317
  // for filters (edited via the filter drawer).
294
- ...o ? {} : { filters: t.filters },
295
- shuffleProducts: t.shuffleProducts,
296
- priceMovedToNextLine: t.priceMovedToNextLine,
297
- priceHideIfSameAsDiscounted: t.priceHideIfSameAsDiscounted,
318
+ ...o ? {} : { filters: e.filters },
319
+ shuffleProducts: e.shuffleProducts,
320
+ priceMovedToNextLine: e.priceMovedToNextLine,
321
+ priceHideIfSameAsDiscounted: e.priceHideIfSameAsDiscounted,
298
322
  currencySettings: {
299
- name: t.currency.code,
300
- value: t.currency.code,
301
- symbol: t.currency.symbol,
302
- alignment: t.currency.alignment === "before" ? "0" : "1",
303
- decimalCount: t.currency.decimalCount.toString(),
304
- decimalSeparator: t.currency.decimalSeparator,
305
- thousandSeparator: t.currency.thousandSeparator
323
+ name: e.currency.code,
324
+ value: e.currency.code,
325
+ symbol: e.currency.symbol,
326
+ alignment: e.currency.alignment === "before" ? "0" : "1",
327
+ decimalCount: e.currency.decimalCount.toString(),
328
+ decimalSeparator: e.currency.decimalSeparator,
329
+ thousandSeparator: e.currency.thousandSeparator
306
330
  }
307
331
  }, { triggerRefetch: !1 });
308
332
  }
@@ -315,18 +339,27 @@ class at extends N {
315
339
  * Shared by onRender() and onTemplateNodeUpdated() to avoid duplication.
316
340
  * Marks the block as initialized to prevent redundant fetches on re-selection.
317
341
  */
318
- async _fetchBlockData(t) {
319
- t !== null && this.store.markBlockInitialized(t), (await Promise.allSettled([
342
+ async _fetchBlockData(e) {
343
+ if (e !== null && this.store.markBlockInitialized(e), (await Promise.allSettled([
320
344
  this.store.fetchRecommendationCreateData(),
321
345
  this.store.fetchRecommendationFilters()
322
- ])).forEach((o, n) => {
323
- o.status === "rejected" && console.warn(`Recommendation block: ${["fetchRecommendationCreateData", "fetchRecommendationFilters"][n]} failed`, o.reason);
324
- }), this._applySmartDefaults();
346
+ ])).forEach((n, s) => {
347
+ n.status === "rejected" && console.warn(`Recommendation block: ${["fetchRecommendationCreateData", "fetchRecommendationFilters"][s]} failed`, n.reason);
348
+ }), e !== null && this.store.currentRecommendationId !== e) {
349
+ this._refreshOutsidePanel(e, !0);
350
+ return;
351
+ }
352
+ this._applySmartDefaults();
353
+ const o = this._getBlockConfigVersion(e);
325
354
  try {
326
355
  await this.store.fetchRecommendationProducts();
327
- } catch (o) {
328
- console.warn("Recommendation block: fetchRecommendationProducts failed", o);
356
+ } catch (n) {
357
+ console.warn("Recommendation block: fetchRecommendationProducts failed", n);
329
358
  }
359
+ e !== null && !this._isPanelOn(e) && this._refreshOutsidePanel(e, this._getBlockConfigVersion(e) !== o);
360
+ }
361
+ _isPanelOn(e) {
362
+ return this.isPanelAlive && this.store.currentRecommendationId === e;
330
363
  }
331
364
  /**
332
365
  * Applies smart defaults for newly dropped blocks.
@@ -341,49 +374,49 @@ class at extends N {
341
374
  _applySmartDefaults() {
342
375
  if (!this.currentNode || !this.api)
343
376
  return;
344
- const t = c.getConfig(this.currentNode), e = {};
377
+ const e = d.getConfig(this.currentNode), t = {};
345
378
  let o = null, n = null, s = null;
346
- if (t.currency.code === a.currency.code) {
379
+ if (e.currency.code === l.currency.code) {
347
380
  const { currencyList: r } = this.store;
348
381
  r.length > 0 && (r.some(
349
- (d) => d.value === `price.${a.currency.code}`
350
- ) || (o = r[0].value.replace("price.", ""), e.currency = {
351
- ...a.currency,
382
+ (u) => u.value === `price.${l.currency.code}`
383
+ ) || (o = r[0].value.replace("price.", ""), t.currency = {
384
+ ...l.currency,
352
385
  code: o,
353
386
  symbol: o
354
387
  }));
355
388
  }
356
- if (t.strategy === a.strategy) {
389
+ if (e.strategy === l.strategy) {
357
390
  const r = this.store.getActivePredictiveAlgorithms;
358
391
  r.length > 0 && (r.some(
359
- (d) => d.value === a.strategy
360
- ) || (n = r[0].value, e.strategy = n));
392
+ (u) => u.value === l.strategy
393
+ ) || (n = r[0].value, t.strategy = n));
361
394
  }
362
- if (t.language === a.language) {
395
+ if (e.language === l.language) {
363
396
  const r = this.store.getLanguages;
364
397
  r.length > 0 && (r.some(
365
- (d) => d.value === a.language
366
- ) || (s = r[0].value, e.language = s));
398
+ (u) => u.value === l.language
399
+ ) || (s = r[0].value, t.language = s));
367
400
  }
368
- !o && !n && !s || (c.updateConfig(
401
+ !o && !n && !s || (d.updateConfig(
369
402
  this.api,
370
403
  this.currentNode,
371
- e,
404
+ t,
372
405
  "Applied smart defaults"
373
- ), o && e.currency && v({
406
+ ), o && t.currency && W({
374
407
  currentNode: this.currentNode,
375
408
  documentModifier: this.api.getDocumentModifier(),
376
- currency: e.currency
409
+ currency: t.currency
377
410
  }), this.store.patchCurrentBlockConfig({
378
411
  ...o ? {
379
412
  currencySettings: {
380
413
  name: o,
381
414
  value: o,
382
415
  symbol: o,
383
- alignment: a.currency.alignment === "before" ? "0" : "1",
384
- decimalCount: a.currency.decimalCount.toString(),
385
- decimalSeparator: a.currency.decimalSeparator,
386
- thousandSeparator: a.currency.thousandSeparator
416
+ alignment: l.currency.alignment === "before" ? "0" : "1",
417
+ decimalCount: l.currency.decimalCount.toString(),
418
+ decimalSeparator: l.currency.decimalSeparator,
419
+ thousandSeparator: l.currency.thousandSeparator
387
420
  }
388
421
  } : {},
389
422
  ...n ? { strategy: n } : {},
@@ -393,20 +426,88 @@ class at extends N {
393
426
  /**
394
427
  * Reads the recommendation-id attribute from the block element within the node
395
428
  */
396
- _getRecommendationIdFromNode(t) {
397
- const e = A(t);
398
- if (!e || !("getAttribute" in e))
429
+ _getRecommendationIdFromNode(e) {
430
+ const t = G(e);
431
+ if (!t || !("getAttribute" in t))
399
432
  return null;
400
- const o = e.getAttribute(I);
433
+ const o = t.getAttribute(k);
401
434
  if (!o)
402
435
  return null;
403
436
  const n = parseInt(o);
404
437
  return Number.isNaN(n) ? null : n;
405
438
  }
439
+ /**
440
+ * Lands what the panel still owes its block before it stops watching it: the config now, the
441
+ * products through a block-scoped refresh. Never throws — it runs from Stripo's teardown.
442
+ */
443
+ _finishBlockOutsidePanel(e = this._trackedBlockSnapshot()) {
444
+ const { blockId: t, fetchedConfigVersion: o, hasUnrenderedProducts: n, followUpAnchor: s } = e;
445
+ try {
446
+ this._flushPendingNodeConfig();
447
+ const r = t === null ? void 0 : this.store.blockStates[t];
448
+ if (t === null || !r)
449
+ return;
450
+ const a = o !== r.configVersion;
451
+ a && !m(
452
+ t,
453
+ this._getNodeConfigUpdates(r.recommendationConfigs),
454
+ f
455
+ ) && console.error("[recommendation] config write outside the panel did not reach a node", { blockId: t }), (a || n) && this._refreshOutsidePanel(t, a, a ? null : s);
456
+ } catch (r) {
457
+ console.error("[recommendation] finishing the block outside the panel failed", r);
458
+ }
459
+ }
460
+ _trackedBlockSnapshot() {
461
+ return {
462
+ blockId: this.trackedBlockId,
463
+ fetchedConfigVersion: this.fetchedConfigVersion,
464
+ hasUnrenderedProducts: this.hasUnrenderedProducts,
465
+ followUpAnchor: this.followUpAnchor
466
+ };
467
+ }
468
+ _refreshOutsidePanel(e, t, o = null) {
469
+ I(e, {
470
+ pickUpdates: (n) => this._getNodeConfigUpdates(n),
471
+ description: "Update recommendation configuration",
472
+ fetch: t,
473
+ followUpAnchor: o
474
+ }).then((n) => {
475
+ !n && this.store.blockStates[e] && console.error("[recommendation] refresh outside the panel did not reach a node", { blockId: e });
476
+ }).catch((n) => {
477
+ console.error("[recommendation] refresh outside the panel failed", n);
478
+ });
479
+ }
480
+ _getBlockConfigVersion(e) {
481
+ var t;
482
+ return e === null ? 0 : ((t = this.store.blockStates[e]) == null ? void 0 : t.configVersion) ?? 0;
483
+ }
484
+ /** Draws the current block's products into this panel's node. */
485
+ _regenerateWithProducts() {
486
+ if (!this.currentNode || !this.api)
487
+ return;
488
+ const e = this.store.recommendationProducts, t = this.api.getDocumentModifier(), o = !this._isEditedConfigChange(this.pendingNodeConfigWrite) && b(this.followUpAnchor);
489
+ this.followUpAnchor = null;
490
+ const n = this._stagePendingNodeConfig(t);
491
+ if (M(this.currentNode)) {
492
+ n && (T(t, "Update recommendation configuration", o), this.pendingNodeConfigWrite = null, this._clearConfigFlush());
493
+ return;
494
+ }
495
+ z({
496
+ currentNode: this.currentNode,
497
+ documentModifier: t,
498
+ products: e,
499
+ hidden: o
500
+ }) || $({
501
+ currentNode: this.currentNode,
502
+ documentModifier: t,
503
+ products: e,
504
+ hidden: o
505
+ });
506
+ }
406
507
  /**
407
508
  * Listen to store changes that require product refresh or regeneration.
408
509
  *
409
- * Uses configVersion counter (incremented only by patchCurrentBlockConfig)
510
+ * Uses the block's configVersion counter (bumped by patchCurrentBlockConfig and legacy conversion)
410
511
  * to distinguish user-initiated config changes from internal mutations
411
512
  * (e.g., fetchRecommendationCreateData setting preferred currency).
412
513
  *
@@ -417,55 +518,57 @@ class at extends N {
417
518
  * We skip that tick and update tracking references instead.
418
519
  */
419
520
  _listenStateUpdates() {
420
- const { store: t } = this;
421
- let e = t.recommendationProducts, o = t.$state.configVersion, n = t.currentRecommendationId;
422
- this.storeUnsubscription = t.$subscribe(() => {
423
- const s = t.currentRecommendationId;
424
- if (s !== n) {
425
- n = s, e = t.recommendationProducts, o = t.$state.configVersion;
521
+ const { store: e } = this;
522
+ let t = e.recommendationProducts, o = this._getBlockConfigVersion(e.currentRecommendationId);
523
+ this.panelGeneration++, this.isPanelAlive = !0, this.trackedBlockId = e.currentRecommendationId, this.fetchedConfigVersion = o, this.hasUnrenderedProducts = !1, this.followUpAnchor = null, this.storeUnsubscription = e.$subscribe(() => {
524
+ const n = e.currentRecommendationId;
525
+ if (n !== this.trackedBlockId) {
526
+ const p = this._trackedBlockSnapshot();
527
+ this.panelGeneration++, this.trackedBlockId = n, t = e.recommendationProducts, o = this._getBlockConfigVersion(n), this.fetchedConfigVersion = o, this.hasUnrenderedProducts = !1, this.followUpAnchor = null, this._finishBlockOutsidePanel(p);
426
528
  return;
427
529
  }
428
- const r = t.$state.configVersion;
429
- r !== o && (o = r, this._capturePendingNodeConfigWrite(), this._isPendingStrategyIdChange() && this._flushPendingNodeConfig(), this._debouncedFetchProducts());
430
- const l = t.recommendationProducts, d = l !== e, m = Array.isArray(l) && l.length > 0;
431
- d && m && (e = l, this._debouncedRegenerateWithProducts());
530
+ const s = this._getBlockConfigVersion(n);
531
+ s !== o && (o = s, this._capturePendingNodeConfigWrite(), this._isPendingStrategyIdChange() && this._flushPendingNodeConfig(), this._debouncedFetchProducts(n, this.panelGeneration));
532
+ const r = e.recommendationProducts, a = r !== t, u = Array.isArray(r) && r.length > 0;
533
+ a && u && (t = r, this.hasUnrenderedProducts = !0, this._debouncedRegenerateWithProducts(this.panelGeneration));
432
534
  });
433
535
  }
434
536
  }
435
537
  export {
436
- ut as ALGORITHM_CONTROL_ID,
437
- T as AlgorithmControl,
438
- W as CONTROL_BLOCK_ID,
439
- gt as CURRENCY_CONTROL_ID,
440
- P as CurrencyControl,
441
- ft as FILTERS_CONTROL_ID,
442
- S as FiltersControl,
443
- Ct as LAYOUT_ORIENTATION_CONTROL_ID,
444
- yt as LOCALE_CONTROL_ID,
445
- O as LayoutOrientationControl,
446
- L as LocaleControl,
447
- _t as PRICE_PLACEMENT_CONTROL_ID,
448
- Rt as PRODUCT_COUNT_CONTROL_ID,
449
- Tt as PRODUCT_LAYOUT_CONTROL_ID,
450
- k as PricePlacementControl,
451
- E as ProductCountControl,
452
- F as ProductLayoutControl,
453
- at as RecommendationBlockControl,
454
- St as SHUFFLE_CONTROL_ID,
455
- Lt as STRATEGY_CONTROL_ID,
456
- D as ShuffleControl,
457
- w as StrategyControl,
458
- Et as adjustProductsToSize,
459
- Ft as formatProductPrice,
460
- A as getBlockElement,
461
- Dt as getCardComposition,
462
- wt as getCurrentLayout,
463
- vt as getMainContainerTbody,
464
- B as isPartnerManagedBlock,
465
- At as regenerateMobileProductRows,
466
- U as regenerateProductRowsWithStyles,
467
- v as setCurrencyAttributes,
468
- Bt as updatePricesInPlace,
469
- x as updateProductContentInPlace,
470
- xt as updateSingleProductContent
538
+ pe as ALGORITHM_CONTROL_ID,
539
+ U as AlgorithmControl,
540
+ H as CONTROL_BLOCK_ID,
541
+ ye as CURRENCY_CONTROL_ID,
542
+ E as CurrencyControl,
543
+ Pe as FILTERS_CONTROL_ID,
544
+ L as FiltersControl,
545
+ Re as LAYOUT_ORIENTATION_CONTROL_ID,
546
+ Se as LOCALE_CONTROL_ID,
547
+ F as LayoutOrientationControl,
548
+ w as LocaleControl,
549
+ Te as PRICE_PLACEMENT_CONTROL_ID,
550
+ Be as PRODUCT_COUNT_CONTROL_ID,
551
+ Ee as PRODUCT_LAYOUT_CONTROL_ID,
552
+ A as PricePlacementControl,
553
+ D as ProductCountControl,
554
+ v as ProductLayoutControl,
555
+ ge as RecommendationBlockControl,
556
+ Fe as SHUFFLE_CONTROL_ID,
557
+ Ae as STRATEGY_CONTROL_ID,
558
+ V as ShuffleControl,
559
+ x as StrategyControl,
560
+ ve as adjustProductsToSize,
561
+ Ve as formatProductPrice,
562
+ G as getBlockElement,
563
+ xe as getCardComposition,
564
+ We as getCurrencyAttributesFromBlock,
565
+ Ge as getCurrentLayout,
566
+ Me as getMainContainerTbody,
567
+ M as isPartnerManagedBlock,
568
+ ze as regenerateMobileProductRows,
569
+ $ as regenerateProductRowsWithStyles,
570
+ W as setCurrencyAttributes,
571
+ $e as updatePricesInPlace,
572
+ z as updateProductContentInPlace,
573
+ He as updateSingleProductContent
471
574
  };