@useinsider/guido 3.19.0-beta.cac604e → 3.19.0-beta.cd25cc8

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 (67) hide show
  1. package/dist/components/Guido.vue.js +6 -6
  2. package/dist/components/Guido.vue2.js +96 -85
  3. package/dist/components/organisms/base/AuthErrorModal.vue.js +18 -0
  4. package/dist/components/organisms/base/AuthErrorModal.vue2.js +42 -0
  5. package/dist/components/wrappers/WpModal.vue.js +1 -1
  6. package/dist/components/wrappers/WpModal.vue2.js +4 -3
  7. package/dist/composables/useAuthError.js +52 -0
  8. package/dist/composables/useAutoSave.js +11 -11
  9. package/dist/composables/useCortexBlueprintBridge.js +122 -54
  10. package/dist/composables/useEmailTemplateApplier.js +111 -50
  11. package/dist/composables/useHttp.js +64 -54
  12. package/dist/composables/useLegacyStrategyConversion.js +23 -19
  13. package/dist/composables/useStripo.js +24 -20
  14. package/dist/composables/useToaster.js +17 -15
  15. package/dist/composables/validators/useLiquidValidator.js +15 -15
  16. package/dist/config/migrator/index.js +14 -13
  17. package/dist/config/migrator/itemsBlockMigrator.js +236 -248
  18. package/dist/config/migrator/recommendationMigrator.js +28 -21
  19. package/dist/config/migrator/recommendationPartnerMigrator.js +56 -0
  20. package/dist/enums/extensions/recommendationBlock.js +30 -29
  21. package/dist/extensions/Blocks/Items/constants/cardLayout.js +20 -0
  22. package/dist/extensions/Blocks/Items/controls/name/trimming.js +18 -17
  23. package/dist/extensions/Blocks/Items/controls/settingsControl.js +114 -105
  24. package/dist/extensions/Blocks/Items/enums/productEnums.js +14 -9
  25. package/dist/extensions/Blocks/Items/layouts/horizontal.html.js +11 -9
  26. package/dist/extensions/Blocks/Items/template.js +219 -204
  27. package/dist/extensions/Blocks/Recommendation/block.js +53 -85
  28. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +90 -73
  29. package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +209 -203
  30. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +126 -112
  31. package/dist/extensions/Blocks/Recommendation/utils/blockUrlConfig.js +25 -0
  32. package/dist/extensions/Blocks/Recommendation/utils/nodeConfigWriter.js +26 -21
  33. package/dist/extensions/Blocks/Recommendation/utils/partnerScope.js +11 -12
  34. package/dist/extensions/Blocks/Recommendation/utils/strategyCommit.js +40 -17
  35. package/dist/guido.css +1 -1
  36. package/dist/src/components/organisms/base/AuthErrorModal.vue.d.ts +2 -0
  37. package/dist/src/components/wrappers/WpModal.vue.d.ts +5 -1
  38. package/dist/src/composables/useAuthError.d.ts +12 -0
  39. package/dist/src/composables/useCortexBlueprintBridge.d.ts +2 -3
  40. package/dist/src/composables/useEmailTemplateApplier.d.ts +18 -5
  41. package/dist/src/composables/useGuidoActions.d.ts +2 -0
  42. package/dist/src/composables/useHttp.d.ts +2 -0
  43. package/dist/src/config/migrator/index.d.ts +2 -1
  44. package/dist/src/config/migrator/recommendationPartnerMigrator.d.ts +19 -0
  45. package/dist/src/enums/extensions/recommendationBlock.d.ts +1 -1
  46. package/dist/src/extensions/Blocks/Items/constants/cardLayout.d.ts +44 -0
  47. package/dist/src/extensions/Blocks/Items/enums/productEnums.d.ts +3 -0
  48. package/dist/src/extensions/Blocks/Items/template.d.ts +19 -0
  49. package/dist/src/extensions/Blocks/Recommendation/block.d.ts +0 -6
  50. package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +2 -0
  51. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +16 -7
  52. package/dist/src/extensions/Blocks/Recommendation/utils/blockUrlConfig.d.ts +4 -0
  53. package/dist/src/extensions/Blocks/Recommendation/utils/nodeConfigWriter.d.ts +3 -1
  54. package/dist/src/extensions/Blocks/Recommendation/utils/partnerScope.d.ts +13 -7
  55. package/dist/src/extensions/Blocks/Recommendation/utils/strategyCommit.d.ts +7 -0
  56. package/dist/src/mock/cortexChatStore.d.ts +12 -0
  57. package/dist/src/stores/guido-email-editor.d.ts +20 -10
  58. package/dist/src/stores/onboarding.d.ts +4 -0
  59. package/dist/src/stores/recommendation.d.ts +5 -0
  60. package/dist/src/utils/dateUtil.d.ts +10 -0
  61. package/dist/src/utils/genericUtil.d.ts +3 -0
  62. package/dist/static/styles/components/version-history.css.js +2 -6
  63. package/dist/stores/guido-email-editor.js +3 -1
  64. package/dist/stores/onboarding.js +4 -0
  65. package/dist/utils/pairProductVariables.js +71 -71
  66. package/dist/utils/templatePreparation.js +61 -85
  67. package/package.json +1 -1
@@ -1,41 +1,41 @@
1
- var D = Object.defineProperty;
2
- var S = (m, c, t) => c in m ? D(m, c, { enumerable: !0, configurable: !0, writable: !0, value: t }) : m[c] = t;
3
- var _ = (m, c, t) => S(m, typeof c != "symbol" ? c + "" : c, t);
1
+ var b = Object.defineProperty;
2
+ var C = (l, c, t) => c in l ? b(l, c, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[c] = t;
3
+ var h = (l, c, t) => C(l, typeof c != "symbol" ? c + "" : c, t);
4
4
  import { useConfig as g } from "../../../composables/useConfig.js";
5
- import { BlockId as T } from "../../../enums/block.js";
6
- import { getMigrationBannerHtml as N } from "../../../utils/migrationBannerHtml.js";
7
- import { Block as O, BlockCompositionType as M, ModificationDescription as h } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
8
- import { CURRENT_CONFIG_VERSION as w, PRE_RRS_CONFIG_VERSION as v } from "./constants/defaultConfig.js";
9
- import { RECOMMENDATION_ID_ATTR as d, SELECTOR_ATTRIBUTE_ROW as F, ATTR_CUSTOM_PREFIX as H, ATTR_DATA_CARD_COMPOSITION as P, ATTR_DATA_CUSTOM_ATTRIBUTES as x } from "./constants/selectors.js";
10
- import { regenerateMobileProductRows as $ } from "./controls/main/utils.js";
11
- import { ensureMobileCssRulesExist as C, setMobileLayoutOptOut as b, hasMobileLayoutOptOut as L } from "./controls/mobileLayout/cssRules.js";
5
+ import { BlockId as D } from "../../../enums/block.js";
6
+ import { getMigrationBannerHtml as A } from "../../../utils/migrationBannerHtml.js";
7
+ import { Block as E, BlockCompositionType as S, ModificationDescription as p } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
8
+ import { CURRENT_CONFIG_VERSION as N, PRE_RRS_CONFIG_VERSION as O } from "./constants/defaultConfig.js";
9
+ import { RECOMMENDATION_ID_ATTR as m } from "./constants/selectors.js";
10
+ import { regenerateMobileProductRows as M } from "./controls/main/utils.js";
11
+ import { ensureMobileCssRulesExist as I, setMobileLayoutOptOut as R, hasMobileLayoutOptOut as w } from "./controls/mobileLayout/cssRules.js";
12
12
  import { RecommendationConfigService as s } from "./services/configService.js";
13
- import { useRecommendationExtensionStore as p } from "./store/recommendation.js";
14
- import { getDefaultTemplate as q } from "./templates/grid/template.js";
15
- import { useRecommendationBlockWarning as U } from "./useRecommendationBlockWarning.js";
16
- import { resolveRowCompositionKey as V } from "./utils/compositionKeys.js";
17
- import { carriesForeignPartnerConfig as W, loadedRecommendationIds as K, withoutCustomAttributes as z } from "./utils/partnerScope.js";
18
- const y = T.Recommendation, f = "recommendation-block-v2", B = "hide-price";
19
- let E = !1;
20
- class at extends O {
13
+ import { useRecommendationExtensionStore as d } from "./store/recommendation.js";
14
+ import { getDefaultTemplate as T } from "./templates/grid/template.js";
15
+ import { useRecommendationBlockWarning as x } from "./useRecommendationBlockWarning.js";
16
+ import { registerNodeConfigWriter as H } from "./utils/nodeConfigWriter.js";
17
+ import { refreshDuplicatedStrategyBlocks as $ } from "./utils/strategyCommit.js";
18
+ const k = D.Recommendation, u = "recommendation-block-v2", y = "hide-price";
19
+ let B = !1;
20
+ class Y extends E {
21
21
  constructor() {
22
22
  super();
23
23
  /**
24
24
  * Stores the ID generated in getTemplate() so onCreated() can reuse it.
25
25
  * This avoids generating a new (different) ID in onCreated().
26
26
  */
27
- _(this, "_pendingBlockId", null);
27
+ h(this, "_pendingBlockId", null);
28
28
  /** Ids already reset under their new name, so the deferred pass skips their stale snapshot. */
29
- _(this, "_resetSourceIds", /* @__PURE__ */ new Set());
29
+ h(this, "_resetSourceIds", /* @__PURE__ */ new Set());
30
30
  }
31
31
  getId() {
32
- return y;
32
+ return k;
33
33
  }
34
34
  getIcon() {
35
35
  return "recommendation-icon";
36
36
  }
37
37
  getBlockCompositionType() {
38
- return M.CONTAINER;
38
+ return S.CONTAINER;
39
39
  }
40
40
  getName() {
41
41
  return this.api.translate("Recommendation Block");
@@ -46,8 +46,8 @@ class at extends O {
46
46
  );
47
47
  }
48
48
  getSettingsPanelTitleHtml() {
49
- return N(
50
- y,
49
+ return A(
50
+ k,
51
51
  this.api.translate("Recommendation Block"),
52
52
  this.api.translate("This block is switched from the Old Version to the New Version. We recommend you check the Recommendation block and test your message to ensure it works properly.")
53
53
  );
@@ -70,7 +70,7 @@ class at extends O {
70
70
  */
71
71
  getTemplate() {
72
72
  const t = this._generateNextId();
73
- return this._pendingBlockId = t, q(t);
73
+ return this._pendingBlockId = t, T(t);
74
74
  }
75
75
  /**
76
76
  * Called when a new block is dropped into the template
@@ -98,23 +98,23 @@ class at extends O {
98
98
  t,
99
99
  {
100
100
  recommendationId: i,
101
- configVersion: n ? w : v,
101
+ configVersion: n ? N : O,
102
102
  ...o ? { partnerName: g().partnerName.value } : {},
103
103
  // An RRS block picks a strategy, not an algorithm, and its algorithm control is
104
104
  // hidden. Keeping the `mostPopular` default would bake a most-popular feed URL
105
105
  // at save for a block the user never configured.
106
106
  ...o ? { strategy: "" } : {}
107
107
  }
108
- ), u = p();
109
- if (u.setCurrentBlock(i), this._stampHidePrice(t, r.priceHideIfSameAsDiscounted), a) {
110
- C(this.api);
111
- const l = this._getBlockElement(t);
112
- l && (b(this.api, l, !0), $({
108
+ ), f = d();
109
+ if (f.setCurrentBlock(i), this._stampHidePrice(t, r.priceHideIfSameAsDiscounted), a) {
110
+ I(this.api);
111
+ const _ = this._getBlockElement(t);
112
+ _ && (R(this.api, _, !0), M({
113
113
  currentNode: t,
114
114
  documentModifier: this.api.getDocumentModifier()
115
115
  }));
116
116
  }
117
- u.patchCurrentBlockConfig({ language: r.language }, { triggerRefetch: !1 }), this._warnIfMultipleBlocks();
117
+ f.patchCurrentBlockConfig({ language: r.language }, { triggerRefetch: !1 }), this._warnIfMultipleBlocks();
118
118
  }
119
119
  /**
120
120
  * Called when the document changes or template is loaded
@@ -134,13 +134,13 @@ class at extends O {
134
134
  "Assign recommendation ID to legacy block"
135
135
  );
136
136
  }
137
- this._healLingeringDuplicate(t), s.needsMigration(t) && this._migrateFromLegacy(t), this._healHidePriceAttr(t), this._resetForeignPartnerConfig(t);
137
+ this._healLingeringDuplicate(t), s.needsMigration(t) && this._migrateFromLegacy(t), this._healHidePriceAttr(t);
138
138
  try {
139
- E || (C(this.api), E = !0);
139
+ B || (I(this.api), B = !0);
140
140
  const e = s.getConfig(t), i = this._getBlockElement(t);
141
141
  if (i) {
142
142
  const n = !e.mobileLayoutEnabled;
143
- L(i) !== n && b(this.api, i, n);
143
+ w(i) !== n && R(this.api, i, n);
144
144
  }
145
145
  } catch {
146
146
  }
@@ -154,7 +154,7 @@ class at extends O {
154
154
  */
155
155
  onDelete(t) {
156
156
  const e = this._getRecommendationId(t);
157
- e && p().removeBlockState(e);
157
+ e && d().removeBlockState(e);
158
158
  }
159
159
  /**
160
160
  * Warns (dark advisory toaster) when the design holds more than one live
@@ -170,7 +170,7 @@ class at extends O {
170
170
  */
171
171
  _warnIfMultipleBlocks() {
172
172
  try {
173
- U().warnIfMultipleBlocks(this.api.getDocumentRootHtmlNode());
173
+ x().warnIfMultipleBlocks(this.api.getDocumentRootHtmlNode());
174
174
  } catch {
175
175
  }
176
176
  }
@@ -182,9 +182,9 @@ class at extends O {
182
182
  let t = 0;
183
183
  try {
184
184
  const e = this.api.getDocumentRoot();
185
- e && "querySelectorAll" in e && e.querySelectorAll(`.${f}`).forEach((n) => {
185
+ e && "querySelectorAll" in e && e.querySelectorAll(`.${u}`).forEach((n) => {
186
186
  if ("getAttribute" in n) {
187
- const o = n.getAttribute(d), r = o ? parseInt(o) : 0;
187
+ const o = n.getAttribute(m), r = o ? parseInt(o) : 0;
188
188
  r > t && (t = r);
189
189
  }
190
190
  });
@@ -202,7 +202,7 @@ class at extends O {
202
202
  _scheduleArrivalReset(t) {
203
203
  g().isFeatureEnabled("reusableRecommendationStrategy") && setTimeout(() => {
204
204
  const e = this._getRecommendationId(t);
205
- e !== null && e > 0 && !this._resetSourceIds.delete(e) && p().resetArrivedBlock(e);
205
+ e !== null && e > 0 && !this._resetSourceIds.delete(e) && d().resetArrivedBlock(e);
206
206
  }, 0);
207
207
  }
208
208
  /**
@@ -225,7 +225,7 @@ class at extends O {
225
225
  if (!i || !("querySelectorAll" in i))
226
226
  return;
227
227
  const n = i.querySelectorAll(
228
- `.${f}[${d}="${e}"]`
228
+ `.${u}[${m}="${e}"]`
229
229
  );
230
230
  if (n.length <= 1)
231
231
  return;
@@ -250,7 +250,7 @@ class at extends O {
250
250
  const e = this.api.getDocumentRoot();
251
251
  if (e && "querySelectorAll" in e)
252
252
  return e.querySelectorAll(
253
- `.${f}[${d}="${t}"]`
253
+ `.${u}[${m}="${t}"]`
254
254
  ).length > 1;
255
255
  } catch {
256
256
  }
@@ -258,8 +258,8 @@ class at extends O {
258
258
  }
259
259
  /** Assigns a fresh id to a duplicated block and syncs DOM, node config and store. */
260
260
  _handleDuplicate(t, e) {
261
- const i = this._reassignDuplicateId(t, e), n = p();
262
- n.cloneBlockState(e, i), n.setCurrentBlock(i), g().isFeatureEnabled("reusableRecommendationStrategy") && (this._resetSourceIds.add(e), n.resetArrivedBlock(i)), this._warnIfMultipleBlocks();
261
+ const i = this._reassignDuplicateId(t, e), n = d();
262
+ n.cloneBlockState(e, i), n.setCurrentBlock(i), g().isFeatureEnabled("reusableRecommendationStrategy") && (this._resetSourceIds.add(e), H(this.api), $(e, i, s.getConfig(t)).catch((o) => console.error("[recommendation] refreshing a duplicated strategy failed", o))), this._warnIfMultipleBlocks();
263
263
  }
264
264
  /**
265
265
  * Core id-reassignment for a duplicated block: rewrites the DOM
@@ -292,7 +292,7 @@ class at extends O {
292
292
  if (!("getAttribute" in t))
293
293
  return;
294
294
  const n = `ins-recommendation-v3-block-${e}`, o = `ins-recommendation-v3-block-${i}`, r = this.api.getDocumentModifier();
295
- r.modifyHtml(t).removeClass(n).setClass(o), r.apply(new h(
295
+ r.modifyHtml(t).removeClass(n).setClass(o), r.apply(new p(
296
296
  `Reassign recommendation instance class ${n} -> ${o}`
297
297
  ));
298
298
  }
@@ -307,7 +307,7 @@ class at extends O {
307
307
  if (!i)
308
308
  return;
309
309
  const n = this.api.getDocumentModifier();
310
- n.modifyHtml(i).setAttribute(d, e.toString()), n.apply(new h(`Assign recommendation ID ${e}`));
310
+ n.modifyHtml(i).setAttribute(m, e.toString()), n.apply(new p(`Assign recommendation ID ${e}`));
311
311
  }
312
312
  /**
313
313
  * Stamps the `hide-price` attribute (read by email-service at send time) on
@@ -315,7 +315,7 @@ class at extends O {
315
315
  */
316
316
  _stampHidePrice(t, e) {
317
317
  const i = this._getBlockElement(t);
318
- i && this.api.getDocumentModifier().modifyHtml(i).setAttribute(B, String(e)).apply(new h("Stamp hide-price"));
318
+ i && this.api.getDocumentModifier().modifyHtml(i).setAttribute(y, String(e)).apply(new p("Stamp hide-price"));
319
319
  }
320
320
  /**
321
321
  * Stamps `hide-price` from config only when the block lacks the attribute —
@@ -323,43 +323,11 @@ class at extends O {
323
323
  */
324
324
  _healHidePriceAttr(t) {
325
325
  const e = this._getBlockElement(t);
326
- if (!e || !("getAttribute" in e) || e.getAttribute(B) !== null)
326
+ if (!e || !("getAttribute" in e) || e.getAttribute(y) !== null)
327
327
  return;
328
328
  const { priceHideIfSameAsDiscounted: i } = s.getConfig(t);
329
329
  this._stampHidePrice(t, i);
330
330
  }
331
- /**
332
- * Empties a block copied in from another account: its strategy and attribute types
333
- * are account-scoped and would not resolve here (SD-151945). Layout, locale and
334
- * currency stay. The write stamps the current account, so the next pass is a no-op.
335
- */
336
- _resetForeignPartnerConfig(t) {
337
- var I, R;
338
- const e = this._getRecommendationId(t), i = this._getBlockElement(t);
339
- if (e === null || !i || !s.hasConfig(t))
340
- return;
341
- const { partnerName: n, template: o } = g(), r = s.getConfig(t);
342
- if (!W({
343
- config: r,
344
- blockId: e,
345
- partnerName: n.value,
346
- campaignUrls: (I = o.value) == null ? void 0 : I.recommendationCampaignUrls,
347
- loadedIds: K(((R = o.value) == null ? void 0 : R.html) ?? "")
348
- }))
349
- return;
350
- const u = z(r.composition), l = this.api.getDocumentModifier();
351
- i.querySelectorAll(F).forEach((k) => {
352
- var A;
353
- (A = V(k)) != null && A.startsWith(H) && l.modifyHtml(k).delete();
354
- }), l.modifyHtml(i).setAttribute(P, u.join(",")).setAttribute(x, "[]"), s.stageConfig(l, t, {
355
- strategyId: "",
356
- strategy: "",
357
- filters: [],
358
- productIds: [],
359
- composition: u,
360
- partnerName: n.value
361
- }), l.apply(new h("Reset recommendation block copied from another account")), p().resetPartnerScopedConfig(e);
362
- }
363
331
  /**
364
332
  * Gets the recommendation-id from a block node
365
333
  */
@@ -367,7 +335,7 @@ class at extends O {
367
335
  const e = this._getBlockElement(t);
368
336
  if (!e || !("getAttribute" in e))
369
337
  return null;
370
- const i = e.getAttribute(d);
338
+ const i = e.getAttribute(m);
371
339
  if (!i)
372
340
  return null;
373
341
  const n = parseInt(i);
@@ -379,10 +347,10 @@ class at extends O {
379
347
  _getBlockElement(t) {
380
348
  if ("getAttribute" in t) {
381
349
  const e = t.getAttribute("class");
382
- if (e && e.includes(f))
350
+ if (e && e.includes(u))
383
351
  return t;
384
352
  }
385
- return "querySelector" in t ? t.querySelector(`.${f}`) ?? null : null;
353
+ return "querySelector" in t ? t.querySelector(`.${u}`) ?? null : null;
386
354
  }
387
355
  /**
388
356
  * Migrate configuration from legacy format
@@ -392,6 +360,6 @@ class at extends O {
392
360
  }
393
361
  }
394
362
  export {
395
- y as BLOCK_ID,
396
- at as RecommendationBlock
363
+ k as BLOCK_ID,
364
+ Y as RecommendationBlock
397
365
  };
@@ -9,28 +9,28 @@ import { RECOMMENDATION_ID_ATTR as I } from "../../constants/selectors.js";
9
9
  import { RecommendationConfigService as c } from "../../services/configService.js";
10
10
  import { useRecommendationExtensionStore as R } from "../../store/recommendation.js";
11
11
  import { registerNodeConfigWriter as b } from "../../utils/nodeConfigWriter.js";
12
- import { AlgorithmControl as T } from "./algorithm.js";
12
+ import { AlgorithmControl as P } from "./algorithm.js";
13
13
  import { ALGORITHM_CONTROL_ID as ut } from "./algorithm.js";
14
- import { CurrencyControl as P } from "./currency.js";
14
+ import { CurrencyControl as T } from "./currency.js";
15
15
  import { CURRENCY_CONTROL_ID as gt } from "./currency.js";
16
16
  import { FiltersControl as S } from "./filters.js";
17
17
  import { FILTERS_CONTROL_ID as ft } from "./filters.js";
18
18
  import { LayoutOrientationControl as O } from "./layoutOrientation.js";
19
19
  import { LAYOUT_ORIENTATION_CONTROL_ID as Ct } from "./layoutOrientation.js";
20
- import { LocaleControl as L } from "./locale.js";
20
+ import { LocaleControl as k } from "./locale.js";
21
21
  import { LOCALE_CONTROL_ID as yt } from "./locale.js";
22
- import { PricePlacementControl as k } from "./pricePlacement.js";
22
+ import { PricePlacementControl as L } from "./pricePlacement.js";
23
23
  import { PRICE_PLACEMENT_CONTROL_ID as _t } from "./pricePlacement.js";
24
24
  import { ProductCountControl as E } from "./productCount.js";
25
25
  import { PRODUCT_COUNT_CONTROL_ID as Rt } from "./productCount.js";
26
26
  import { ProductLayoutControl as F } from "./productLayout.js";
27
- import { PRODUCT_LAYOUT_CONTROL_ID as Tt } from "./productLayout.js";
27
+ import { PRODUCT_LAYOUT_CONTROL_ID as Pt } from "./productLayout.js";
28
28
  import { ShuffleControl as D } from "./shuffle.js";
29
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";
30
+ import { StrategyControl as B } from "./strategy.js";
31
+ import { STRATEGY_CONTROL_ID as kt } from "./strategy.js";
32
+ import { setCurrencyAttributes as w, getBlockElement as v, isPartnerManagedBlock as A, updateProductContentInPlace as x, regenerateProductRowsWithStyles as U } from "./utils.js";
33
+ import { adjustProductsToSize as Et, formatProductPrice as Ft, getCardComposition as Dt, getCurrentLayout as Bt, getMainContainerTbody as wt, regenerateMobileProductRows as vt, updatePricesInPlace as At, updateSingleProductContent as xt } from "./utils.js";
34
34
  import { useDebounceFn as f } from "../../../../../node_modules/@vueuse/shared/index.js";
35
35
  const W = "ui-elements-recommendation-block";
36
36
  class at extends N {
@@ -77,23 +77,21 @@ class at extends N {
77
77
  * fails when the size actually changed.
78
78
  */
79
79
  i(this, "_debouncedRegenerateWithProducts", f(() => {
80
- const t = this.store.recommendationProducts;
81
80
  if (!this.currentNode || !this.api)
82
81
  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());
82
+ const t = this._getRecommendationIdFromNode(this.currentNode), e = this.store.currentRecommendationId;
83
+ if (t === null || e === null || t === e || !this.store.blockStates[t]) {
84
+ this._regenerateWithProducts();
86
85
  return;
87
86
  }
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
- });
87
+ if (this.store.blockStates[t].recommendationProducts.length) {
88
+ this.store.setCurrentBlock(t);
89
+ try {
90
+ this._regenerateWithProducts();
91
+ } finally {
92
+ this.store.setCurrentBlock(e);
93
+ }
94
+ }
97
95
  }, 100));
98
96
  }
99
97
  getId() {
@@ -118,7 +116,7 @@ class at extends N {
118
116
  return this.rrsEnabled = h().isFeatureEnabled("reusableRecommendationStrategy"), this._subControls.forEach((e) => {
119
117
  var o;
120
118
  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) => {
119
+ }), this.algorithmControl = new P(), this.localeControl = new k(), this.currencyControl = new T(), this.productCountControl = new E(), this.productLayoutControl = new F(), this.filtersControl = new S(), this.shuffleControl = new D(), this.pricePlacementControl = new L(), this.layoutOrientationControl = new O(), this.strategyControl = this.rrsEnabled ? new B() : null, this._subControls.forEach((e) => {
122
120
  e && (e.api = this.api);
123
121
  }), `
124
122
  <div class="recommendation-controls-container">
@@ -136,12 +134,12 @@ class at extends N {
136
134
  `;
137
135
  }
138
136
  _showControlsForBlock(t) {
139
- var r;
140
- const e = (r = this.getContainer()) == null ? void 0 : r.querySelector(".recommendation-controls-container");
137
+ var n;
138
+ const e = (n = this.getContainer()) == null ? void 0 : n.querySelector(".recommendation-controls-container");
141
139
  if (!e)
142
140
  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);
141
+ const o = this._getRecommendationIdFromNode(t) === null ? null : c.getConfig(t), r = this.rrsEnabled && !!o && (!!(o != null && o.strategyId) || ((o == null ? void 0 : o.configVersion) ?? 0) >= _), s = this.rrsEnabled && !!o && !r;
142
+ e.classList.toggle("strategy-block", r), e.classList.toggle("legacy-strategy-block", s);
145
143
  }
146
144
  async onRender() {
147
145
  var o;
@@ -159,9 +157,9 @@ class at extends N {
159
157
  const e = this._getRecommendationIdFromNode(t);
160
158
  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(() => {
161
159
  this._initializeSubControls();
162
- }), this._subControls.forEach((n) => {
160
+ }), this._subControls.forEach((r) => {
163
161
  var s;
164
- n != null && n.api && (n.currentNode = t, (s = n.onTemplateNodeUpdated) == null || s.call(n, t));
162
+ r != null && r.api && (r.currentNode = t, (s = r.onTemplateNodeUpdated) == null || s.call(r, t));
165
163
  });
166
164
  }
167
165
  onDestroy() {
@@ -209,8 +207,8 @@ class at extends N {
209
207
  const e = this.store.blockStates[t];
210
208
  if (!e)
211
209
  return;
212
- const o = JSON.stringify(c.getConfig(this.currentNode)), n = e.syncedConfigFingerprint;
213
- e.syncedConfigFingerprint = o, n !== o && (this.pendingNodeConfigWrite || this._syncNodeConfigToStore());
210
+ const o = JSON.stringify(c.getConfig(this.currentNode)), r = e.syncedConfigFingerprint;
211
+ e.syncedConfigFingerprint = o, r !== o && (this.pendingNodeConfigWrite || this._syncNodeConfigToStore());
214
212
  }
215
213
  /** Whether the deferred write would move the node's strategyId — see the caller (SD-149916). */
216
214
  _isPendingStrategyIdChange() {
@@ -221,16 +219,16 @@ class at extends N {
221
219
  const t = this.store.currentRecommendationId;
222
220
  if (!this.currentNode || !this.api || t === null)
223
221
  return;
224
- const { filters: e, strategy: o, strategyId: n, size: s, nodeConfigVersion: r } = this.store.recommendationConfigs, { partnerName: l } = h();
222
+ const { filters: e, strategy: o, strategyId: r, size: s, nodeConfigVersion: n } = this.store.recommendationConfigs, { partnerName: l } = h();
225
223
  this.pendingNodeConfigWrite = {
226
224
  blockId: t,
227
225
  node: this.currentNode,
228
226
  updates: {
229
227
  filters: e,
230
228
  strategy: o,
231
- strategyId: n,
229
+ strategyId: r,
232
230
  size: s,
233
- configVersion: r,
231
+ configVersion: n,
234
232
  ...l.value ? { partnerName: l.value } : {}
235
233
  }
236
234
  };
@@ -275,8 +273,8 @@ class at extends N {
275
273
  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");
276
274
  }
277
275
  _syncNodeConfigToStore() {
278
- 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);
276
+ var r;
277
+ const t = c.getConfig(this.currentNode), e = this.store.currentRecommendationId, o = e !== null && ((r = this.store.blockStates[e]) == null ? void 0 : r.isInitialized);
280
278
  this.store.patchCurrentBlockConfig({
281
279
  strategy: t.strategy,
282
280
  strategyId: t.strategyId,
@@ -319,8 +317,8 @@ class at extends N {
319
317
  t !== null && this.store.markBlockInitialized(t), (await Promise.allSettled([
320
318
  this.store.fetchRecommendationCreateData(),
321
319
  this.store.fetchRecommendationFilters()
322
- ])).forEach((o, n) => {
323
- o.status === "rejected" && console.warn(`Recommendation block: ${["fetchRecommendationCreateData", "fetchRecommendationFilters"][n]} failed`, o.reason);
320
+ ])).forEach((o, r) => {
321
+ o.status === "rejected" && console.warn(`Recommendation block: ${["fetchRecommendationCreateData", "fetchRecommendationFilters"][r]} failed`, o.reason);
324
322
  }), this._applySmartDefaults();
325
323
  try {
326
324
  await this.store.fetchRecommendationProducts();
@@ -342,35 +340,35 @@ class at extends N {
342
340
  if (!this.currentNode || !this.api)
343
341
  return;
344
342
  const t = c.getConfig(this.currentNode), e = {};
345
- let o = null, n = null, s = null;
343
+ let o = null, r = null, s = null;
346
344
  if (t.currency.code === a.currency.code) {
347
- const { currencyList: r } = this.store;
348
- r.length > 0 && (r.some(
345
+ const { currencyList: n } = this.store;
346
+ n.length > 0 && (n.some(
349
347
  (d) => d.value === `price.${a.currency.code}`
350
- ) || (o = r[0].value.replace("price.", ""), e.currency = {
348
+ ) || (o = n[0].value.replace("price.", ""), e.currency = {
351
349
  ...a.currency,
352
350
  code: o,
353
351
  symbol: o
354
352
  }));
355
353
  }
356
354
  if (t.strategy === a.strategy) {
357
- const r = this.store.getActivePredictiveAlgorithms;
358
- r.length > 0 && (r.some(
355
+ const n = this.store.getActivePredictiveAlgorithms;
356
+ n.length > 0 && (n.some(
359
357
  (d) => d.value === a.strategy
360
- ) || (n = r[0].value, e.strategy = n));
358
+ ) || (r = n[0].value, e.strategy = r));
361
359
  }
362
360
  if (t.language === a.language) {
363
- const r = this.store.getLanguages;
364
- r.length > 0 && (r.some(
361
+ const n = this.store.getLanguages;
362
+ n.length > 0 && (n.some(
365
363
  (d) => d.value === a.language
366
- ) || (s = r[0].value, e.language = s));
364
+ ) || (s = n[0].value, e.language = s));
367
365
  }
368
- !o && !n && !s || (c.updateConfig(
366
+ !o && !r && !s || (c.updateConfig(
369
367
  this.api,
370
368
  this.currentNode,
371
369
  e,
372
370
  "Applied smart defaults"
373
- ), o && e.currency && v({
371
+ ), o && e.currency && w({
374
372
  currentNode: this.currentNode,
375
373
  documentModifier: this.api.getDocumentModifier(),
376
374
  currency: e.currency
@@ -386,7 +384,7 @@ class at extends N {
386
384
  thousandSeparator: a.currency.thousandSeparator
387
385
  }
388
386
  } : {},
389
- ...n ? { strategy: n } : {},
387
+ ...r ? { strategy: r } : {},
390
388
  ...s ? { language: s } : {}
391
389
  }, { triggerRefetch: !1 }));
392
390
  }
@@ -394,14 +392,33 @@ class at extends N {
394
392
  * Reads the recommendation-id attribute from the block element within the node
395
393
  */
396
394
  _getRecommendationIdFromNode(t) {
397
- const e = A(t);
395
+ const e = v(t);
398
396
  if (!e || !("getAttribute" in e))
399
397
  return null;
400
398
  const o = e.getAttribute(I);
401
399
  if (!o)
402
400
  return null;
403
- const n = parseInt(o);
404
- return Number.isNaN(n) ? null : n;
401
+ const r = parseInt(o);
402
+ return Number.isNaN(r) ? null : r;
403
+ }
404
+ /** Draws the current block's products into this panel's node. */
405
+ _regenerateWithProducts() {
406
+ if (!this.currentNode || !this.api)
407
+ return;
408
+ const t = this.store.recommendationProducts, e = this.api.getDocumentModifier(), o = this._stagePendingNodeConfig(e);
409
+ if (A(this.currentNode)) {
410
+ o && (e.apply(new y("Update recommendation configuration")), this.pendingNodeConfigWrite = null, this._clearConfigFlush());
411
+ return;
412
+ }
413
+ x({
414
+ currentNode: this.currentNode,
415
+ documentModifier: e,
416
+ products: t
417
+ }) || U({
418
+ currentNode: this.currentNode,
419
+ documentModifier: e,
420
+ products: t
421
+ });
405
422
  }
406
423
  /**
407
424
  * Listen to store changes that require product refresh or regeneration.
@@ -418,15 +435,15 @@ class at extends N {
418
435
  */
419
436
  _listenStateUpdates() {
420
437
  const { store: t } = this;
421
- let e = t.recommendationProducts, o = t.$state.configVersion, n = t.currentRecommendationId;
438
+ let e = t.recommendationProducts, o = t.$state.configVersion, r = t.currentRecommendationId;
422
439
  this.storeUnsubscription = t.$subscribe(() => {
423
440
  const s = t.currentRecommendationId;
424
- if (s !== n) {
425
- n = s, e = t.recommendationProducts, o = t.$state.configVersion;
441
+ if (s !== r) {
442
+ r = s, e = t.recommendationProducts, o = t.$state.configVersion;
426
443
  return;
427
444
  }
428
- const r = t.$state.configVersion;
429
- r !== o && (o = r, this._capturePendingNodeConfigWrite(), this._isPendingStrategyIdChange() && this._flushPendingNodeConfig(), this._debouncedFetchProducts());
445
+ const n = t.$state.configVersion;
446
+ n !== o && (o = n, this._capturePendingNodeConfigWrite(), this._isPendingStrategyIdChange() && this._flushPendingNodeConfig(), this._debouncedFetchProducts());
430
447
  const l = t.recommendationProducts, d = l !== e, m = Array.isArray(l) && l.length > 0;
431
448
  d && m && (e = l, this._debouncedRegenerateWithProducts());
432
449
  });
@@ -434,38 +451,38 @@ class at extends N {
434
451
  }
435
452
  export {
436
453
  ut as ALGORITHM_CONTROL_ID,
437
- T as AlgorithmControl,
454
+ P as AlgorithmControl,
438
455
  W as CONTROL_BLOCK_ID,
439
456
  gt as CURRENCY_CONTROL_ID,
440
- P as CurrencyControl,
457
+ T as CurrencyControl,
441
458
  ft as FILTERS_CONTROL_ID,
442
459
  S as FiltersControl,
443
460
  Ct as LAYOUT_ORIENTATION_CONTROL_ID,
444
461
  yt as LOCALE_CONTROL_ID,
445
462
  O as LayoutOrientationControl,
446
- L as LocaleControl,
463
+ k as LocaleControl,
447
464
  _t as PRICE_PLACEMENT_CONTROL_ID,
448
465
  Rt as PRODUCT_COUNT_CONTROL_ID,
449
- Tt as PRODUCT_LAYOUT_CONTROL_ID,
450
- k as PricePlacementControl,
466
+ Pt as PRODUCT_LAYOUT_CONTROL_ID,
467
+ L as PricePlacementControl,
451
468
  E as ProductCountControl,
452
469
  F as ProductLayoutControl,
453
470
  at as RecommendationBlockControl,
454
471
  St as SHUFFLE_CONTROL_ID,
455
- Lt as STRATEGY_CONTROL_ID,
472
+ kt as STRATEGY_CONTROL_ID,
456
473
  D as ShuffleControl,
457
- w as StrategyControl,
474
+ B as StrategyControl,
458
475
  Et as adjustProductsToSize,
459
476
  Ft as formatProductPrice,
460
- A as getBlockElement,
477
+ v as getBlockElement,
461
478
  Dt as getCardComposition,
462
- wt as getCurrentLayout,
463
- vt as getMainContainerTbody,
464
- B as isPartnerManagedBlock,
465
- At as regenerateMobileProductRows,
479
+ Bt as getCurrentLayout,
480
+ wt as getMainContainerTbody,
481
+ A as isPartnerManagedBlock,
482
+ vt as regenerateMobileProductRows,
466
483
  U as regenerateProductRowsWithStyles,
467
- v as setCurrencyAttributes,
468
- Bt as updatePricesInPlace,
484
+ w as setCurrencyAttributes,
485
+ At as updatePricesInPlace,
469
486
  x as updateProductContentInPlace,
470
487
  xt as updateSingleProductContent
471
488
  };