@useinsider/guido 3.24.0-beta.2a3ba08 → 3.24.0-beta.33e70b5

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 (114) hide show
  1. package/README.md +7 -2
  2. package/dist/@types/config/schemas.js +40 -40
  3. package/dist/@types/display-condition.js +25 -0
  4. package/dist/components/Guido.vue.js +2 -2
  5. package/dist/components/Guido.vue2.js +100 -97
  6. package/dist/components/organisms/display-conditions/CodeEditorField.vue.js +17 -0
  7. package/dist/components/organisms/display-conditions/CodeEditorField.vue2.js +41 -0
  8. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.js +30 -0
  9. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue2.js +81 -0
  10. package/dist/components/organisms/display-conditions/DisplayConditionListState.vue.js +17 -0
  11. package/dist/components/organisms/display-conditions/DisplayConditionListState.vue2.js +45 -0
  12. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.js +36 -0
  13. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue2.js +63 -0
  14. package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue.js +17 -0
  15. package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue2.js +22 -0
  16. package/dist/composables/useActionsApi.js +2 -2
  17. package/dist/composables/useBlocksConfig.js +29 -20
  18. package/dist/composables/useDisplayConditions.js +116 -0
  19. package/dist/composables/useEditorTrackingIds.js +49 -0
  20. package/dist/composables/useHtmlCompiler.js +2 -0
  21. package/dist/composables/useModuleRepair.js +12 -14
  22. package/dist/composables/useStripo.js +70 -70
  23. package/dist/composables/useTranslations.js +2 -1
  24. package/dist/config/compiler/htmlCompilerRules.js +14 -6
  25. package/dist/config/compiler/utils/itemsCompilerUtils.js +43 -42
  26. package/dist/config/compiler/utils/recommendationCompilerUtils.js +67 -64
  27. package/dist/config/migrator/index.js +15 -16
  28. package/dist/enums/academy.js +1 -0
  29. package/dist/enums/display-condition.js +12 -0
  30. package/dist/extensions/Blocks/Items/block.js +77 -115
  31. package/dist/extensions/Blocks/Items/constants/currency.js +14 -59
  32. package/dist/extensions/Blocks/Items/controls/price/currencyLocation.js +22 -33
  33. package/dist/extensions/Blocks/Items/controls/price/currencySymbol.js +51 -62
  34. package/dist/extensions/Blocks/Items/controls/price/formattedPrice.js +17 -18
  35. package/dist/extensions/Blocks/Items/controls/price/singlePrice.js +31 -42
  36. package/dist/extensions/Blocks/Items/controls/settingsControl.js +120 -141
  37. package/dist/extensions/Blocks/Items/enums/controlEnums.js +1 -1
  38. package/dist/extensions/Blocks/Items/extension.js +8 -9
  39. package/dist/extensions/Blocks/Items/items.css.js +0 -19
  40. package/dist/extensions/Blocks/Items/settingsPanel.js +25 -34
  41. package/dist/extensions/Blocks/Items/template.js +212 -250
  42. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +10 -8
  43. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +28 -24
  44. package/dist/extensions/Blocks/Recommendation/utils/nodeConfigWriter.js +23 -22
  45. package/dist/extensions/Blocks/Recommendation/utils/priceFormatter.js +0 -1
  46. package/dist/extensions/DisplayConditions/bridge.js +25 -0
  47. package/dist/extensions/DisplayConditions/constants.js +26 -0
  48. package/dist/extensions/DisplayConditions/control.js +215 -0
  49. package/dist/extensions/DisplayConditions/display-conditions.css.js +226 -0
  50. package/dist/extensions/DisplayConditions/extension.js +28 -0
  51. package/dist/extensions/DisplayConditions/iconsRegistry.js +20 -0
  52. package/dist/extensions/DisplayConditions/library.js +30 -0
  53. package/dist/extensions/DisplayConditions/settingsPanel.js +17 -0
  54. package/dist/guido.css +1 -1
  55. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +93 -92
  56. package/dist/node_modules/valibot/dist/index.js +297 -261
  57. package/dist/package.json.js +2 -2
  58. package/dist/services/displayConditionApi.js +39 -0
  59. package/dist/services/templateLibraryApi.js +39 -36
  60. package/dist/src/@types/config/schemas.d.ts +4 -4
  61. package/dist/src/@types/display-condition.d.ts +61 -0
  62. package/dist/src/components/organisms/display-conditions/CodeEditorField.vue.d.ts +43 -0
  63. package/dist/src/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.d.ts +2 -0
  64. package/dist/src/components/organisms/display-conditions/DisplayConditionListState.vue.d.ts +18 -0
  65. package/dist/src/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.d.ts +2 -0
  66. package/dist/src/components/organisms/display-conditions/DisplayConditionsHost.vue.d.ts +2 -0
  67. package/dist/src/composables/useConfig.d.ts +2 -2
  68. package/dist/src/composables/useDisplayConditions.d.ts +18 -0
  69. package/dist/src/composables/useEditorTrackingIds.d.ts +7 -0
  70. package/dist/src/composables/useStripo.d.ts +1 -1
  71. package/dist/src/config/migrator/index.d.ts +1 -4
  72. package/dist/src/enums/academy.d.ts +1 -0
  73. package/dist/src/enums/display-condition.d.ts +15 -0
  74. package/dist/src/extensions/Blocks/Items/block.d.ts +9 -6
  75. package/dist/src/extensions/Blocks/Items/constants/currency.d.ts +0 -32
  76. package/dist/src/extensions/Blocks/Items/controls/settingsControl.d.ts +0 -1
  77. package/dist/src/extensions/Blocks/Items/enums/controlEnums.d.ts +0 -1
  78. package/dist/src/extensions/Blocks/Items/template.d.ts +1 -4
  79. package/dist/src/extensions/Blocks/Items/utils/nodeConfigUtils.d.ts +0 -3
  80. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +2 -0
  81. package/dist/src/extensions/Blocks/Recommendation/utils/priceFormatter.d.ts +0 -12
  82. package/dist/src/extensions/DisplayConditions/bridge.d.ts +7 -0
  83. package/dist/src/extensions/DisplayConditions/constants.d.ts +23 -0
  84. package/dist/src/extensions/DisplayConditions/control.d.ts +25 -0
  85. package/dist/src/extensions/DisplayConditions/extension.d.ts +2 -0
  86. package/dist/src/extensions/DisplayConditions/iconsRegistry.d.ts +4 -0
  87. package/dist/src/extensions/DisplayConditions/library.d.ts +8 -0
  88. package/dist/src/extensions/DisplayConditions/settingsPanel.d.ts +5 -0
  89. package/dist/src/mock/api/display-conditions.d.ts +2 -0
  90. package/dist/src/services/displayConditionApi.d.ts +8 -0
  91. package/dist/src/stores/config.d.ts +167 -20
  92. package/dist/src/stores/display-condition.d.ts +86 -0
  93. package/dist/src/utils/displayCondition.d.ts +11 -0
  94. package/dist/src/utils/itemsCurrencyRepair.d.ts +1 -5
  95. package/dist/src/utils/linkTrackingIds.d.ts +19 -0
  96. package/dist/src/utils/protectTableText.d.ts +2 -0
  97. package/dist/src/utils/trimHrefWhitespace.d.ts +5 -0
  98. package/dist/static/styles/variables.css.js +1 -0
  99. package/dist/stores/config.js +13 -6
  100. package/dist/stores/display-condition.js +29 -0
  101. package/dist/utils/displayCondition.js +29 -0
  102. package/dist/utils/itemsCurrencyRepair.js +24 -29
  103. package/dist/utils/linkTrackingIds.js +82 -48
  104. package/dist/utils/pairProductVariables.js +100 -119
  105. package/dist/utils/protectTableText.js +22 -0
  106. package/dist/utils/templatePreparation.js +30 -33
  107. package/dist/utils/trimHrefWhitespace.js +10 -0
  108. package/package.json +1 -1
  109. package/dist/config/migrator/itemsPriceFormatMigrator.js +0 -20
  110. package/dist/extensions/Blocks/Items/controls/priceFormat.js +0 -145
  111. package/dist/extensions/Blocks/Items/utils/priceFormatOps.js +0 -185
  112. package/dist/src/config/migrator/itemsPriceFormatMigrator.d.ts +0 -1
  113. package/dist/src/extensions/Blocks/Items/controls/priceFormat.d.ts +0 -23
  114. package/dist/src/extensions/Blocks/Items/utils/priceFormatOps.d.ts +0 -61
@@ -17,9 +17,9 @@ import { CurrencyControl as U } from "./currency.js";
17
17
  import { CURRENCY_CONTROL_ID as Ie } from "./currency.js";
18
18
  import { FiltersControl as v } from "./filters.js";
19
19
  import { FILTERS_CONTROL_ID as ke } from "./filters.js";
20
- import { LayoutOrientationControl as A } from "./layoutOrientation.js";
20
+ import { LayoutOrientationControl as w } from "./layoutOrientation.js";
21
21
  import { LAYOUT_ORIENTATION_CONTROL_ID as Oe } from "./layoutOrientation.js";
22
- import { LocaleControl as w } from "./locale.js";
22
+ import { LocaleControl as A } from "./locale.js";
23
23
  import { LOCALE_CONTROL_ID as Be } from "./locale.js";
24
24
  import { PricePlacementControl as V } from "./pricePlacement.js";
25
25
  import { PRICE_PLACEMENT_CONTROL_ID as Le } from "./pricePlacement.js";
@@ -28,7 +28,7 @@ import { PRODUCT_COUNT_CONTROL_ID as Ee } from "./productCount.js";
28
28
  import { ProductLayoutControl as x } from "./productLayout.js";
29
29
  import { PRODUCT_LAYOUT_CONTROL_ID as ve } from "./productLayout.js";
30
30
  import { ShuffleControl as M } from "./shuffle.js";
31
- import { SHUFFLE_CONTROL_ID as we } from "./shuffle.js";
31
+ import { SHUFFLE_CONTROL_ID as Ae } from "./shuffle.js";
32
32
  import { StrategyControl as G } from "./strategy.js";
33
33
  import { STRATEGY_CONTROL_ID as We } from "./strategy.js";
34
34
  import { setCurrencyAttributes as $, getBlockElement as z, isPartnerManagedBlock as H, updateProductContentInPlace as Y, regenerateProductRowsWithStyles as j } from "./utils.js";
@@ -128,7 +128,7 @@ class _e extends I {
128
128
  return this.rrsEnabled = f().isFeatureEnabled("reusableRecommendationStrategy"), this._subControls.forEach((t) => {
129
129
  var o;
130
130
  return (o = t == null ? void 0 : t.onDestroy) == null ? void 0 : o.call(t);
131
- }), this.algorithmControl = new E(), this.localeControl = new w(), this.currencyControl = new U(), this.productCountControl = new W(), this.productLayoutControl = new x(), this.filtersControl = new v(), this.shuffleControl = new M(), this.pricePlacementControl = new V(), this.layoutOrientationControl = new A(), this.strategyControl = this.rrsEnabled ? new G() : null, this._subControls.forEach((t) => {
131
+ }), this.algorithmControl = new E(), this.localeControl = new A(), this.currencyControl = new U(), this.productCountControl = new W(), this.productLayoutControl = new x(), this.filtersControl = new v(), this.shuffleControl = new M(), this.pricePlacementControl = new V(), this.layoutOrientationControl = new w(), this.strategyControl = this.rrsEnabled ? new G() : null, this._subControls.forEach((t) => {
132
132
  t && (t.api = this.api);
133
133
  }), `
134
134
  <div class="recommendation-controls-container">
@@ -452,7 +452,9 @@ class _e extends I {
452
452
  e,
453
453
  this._getNodeConfigUpdates(n.recommendationConfigs),
454
454
  h
455
- ) && console.error("[recommendation] config write outside the panel did not reach a node", { blockId: e }), (i || o) && this._refreshOutsidePanel(e, i);
455
+ ) && console.error("[recommendation] config write outside the panel did not reach a node", { blockId: e });
456
+ const s = o && n.drawnProducts !== n.recommendationProducts;
457
+ (i || s) && this._refreshOutsidePanel(e, i);
456
458
  } catch (n) {
457
459
  console.error("[recommendation] finishing the block outside the panel failed", n);
458
460
  }
@@ -552,8 +554,8 @@ export {
552
554
  v as FiltersControl,
553
555
  Oe as LAYOUT_ORIENTATION_CONTROL_ID,
554
556
  Be as LOCALE_CONTROL_ID,
555
- A as LayoutOrientationControl,
556
- w as LocaleControl,
557
+ w as LayoutOrientationControl,
558
+ A as LocaleControl,
557
559
  Le as PRICE_PLACEMENT_CONTROL_ID,
558
560
  Ee as PRODUCT_COUNT_CONTROL_ID,
559
561
  ve as PRODUCT_LAYOUT_CONTROL_ID,
@@ -561,7 +563,7 @@ export {
561
563
  W as ProductCountControl,
562
564
  x as ProductLayoutControl,
563
565
  _e as RecommendationBlockControl,
564
- we as SHUFFLE_CONTROL_ID,
566
+ Ae as SHUFFLE_CONTROL_ID,
565
567
  We as STRATEGY_CONTROL_ID,
566
568
  M as ShuffleControl,
567
569
  G as StrategyControl,
@@ -1,6 +1,6 @@
1
1
  import { useToaster as L } from "../../../../composables/useToaster.js";
2
2
  import { useTranslations as U } from "../../../../composables/useTranslations.js";
3
- import { getRecommendationFeedSourceMaps as F, strategyEditPath as z, strategyCreatePath as B, getOperatorOptions as M, PriceAttributes as N } from "../../../../enums/extensions/recommendationBlock.js";
3
+ import { getRecommendationFeedSourceMaps as w, strategyEditPath as z, strategyCreatePath as B, getOperatorOptions as M, PriceAttributes as N } from "../../../../enums/extensions/recommendationBlock.js";
4
4
  import { ToasterTypeOptions as E } from "../../../../enums/toaster.js";
5
5
  import { useRecommendationApi as O } from "../../../../services/recommendationApi.js";
6
6
  import { useConfigStore as R } from "../../../../stores/config.js";
@@ -8,21 +8,21 @@ import { defineStore as V } from "pinia";
8
8
  import "../constants/selectors.js";
9
9
  import { DEFAULT_MOBILE_CARDS_IN_ROW as A, DEFAULT_CARDS_IN_ROW as x } from "../constants/layout.js";
10
10
  import { CURRENT_CONFIG_VERSION as C, DEFAULT_NODE_CONFIG as T, EXCLUDED_ALGORITHM_IDS as j } from "../constants/defaultConfig.js";
11
- import { getDefaultProducts as w } from "../templates/utils.js";
11
+ import { getDefaultProducts as F } from "../templates/utils.js";
12
12
  import { generateCompleteFilterQuery as P } from "../utils/filterUtil.js";
13
13
  import { isLegacyStrategyConfig as $ } from "../utils/legacyStrategyMigration.js";
14
14
  import { getPartnerRecommendationParams as q } from "../utils/partnerCustomizations.js";
15
15
  import { sanitizeProductIds as K } from "../utils/productIds.js";
16
16
  import { isFilterValid as H } from "../validation/filterSchema.js";
17
17
  import { getInvalidFields as J, isConfigValid as Q } from "../validation/requiredFields.js";
18
- const m = O();
18
+ const u = O();
19
19
  let p = null, y = null;
20
20
  const I = /* @__PURE__ */ new Map();
21
21
  let k = null, b = 0;
22
- const u = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Map();
22
+ const m = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Map();
23
23
  function W(t) {
24
24
  const e = _.get(t);
25
- return e && e.token === u.get(t) ? e.outcome : !1;
25
+ return e && e.token === m.get(t) ? e.outcome : !1;
26
26
  }
27
27
  let l = null;
28
28
  const X = () => {
@@ -80,7 +80,8 @@ function G() {
80
80
  syncedConfigFingerprint: null,
81
81
  legacyConversionLoading: !1,
82
82
  configVersion: 0,
83
- adoptedSizeVersion: 0
83
+ adoptedSizeVersion: 0,
84
+ drawnProducts: null
84
85
  };
85
86
  }
86
87
  const Y = () => ({
@@ -173,7 +174,7 @@ const Y = () => ({
173
174
  return [...new Set(t.map((e) => e.filterGroup))].sort((e, n) => e - n);
174
175
  },
175
176
  getActivePredictiveAlgorithms: (t) => {
176
- const e = F(), n = [];
177
+ const e = w(), n = [];
177
178
  return t.activePredictiveAlgorithms.filter((r) => !j.includes(r)).forEach((r) => {
178
179
  n.push(...e.filter((o) => o.id === r));
179
180
  }), n.map((r) => ({
@@ -245,7 +246,7 @@ const Y = () => ({
245
246
  const n = this.blockStates[t];
246
247
  if (n) {
247
248
  const s = structuredClone(n);
248
- s.recommendationConfigs.id = e, s.recommendationConfigs.strategyId && R().isFeatureEnabled("reusableRecommendationStrategy") && (s.isInitialized = !1, s.syncedConfigFingerprint = null), this.blockStates = {
249
+ s.recommendationConfigs.id = e, s.drawnProducts = null, s.recommendationConfigs.strategyId && R().isFeatureEnabled("reusableRecommendationStrategy") && (s.isInitialized = !1, s.syncedConfigFingerprint = null), this.blockStates = {
249
250
  ...this.blockStates,
250
251
  [e]: s
251
252
  };
@@ -256,6 +257,9 @@ const Y = () => ({
256
257
  [o]: i
257
258
  });
258
259
  },
260
+ markProductsDrawn(t, e) {
261
+ this.blockStates[t] && (this.blockStates[t].drawnProducts = e);
262
+ },
259
263
  /**
260
264
  * Marks a block as initialized (initial API data has been fetched).
261
265
  * Automatically cleaned up when removeBlockState deletes the block entry.
@@ -401,7 +405,7 @@ const Y = () => ({
401
405
  const t = b, e = (async () => {
402
406
  this.strategiesLoading = !0;
403
407
  try {
404
- const n = await m.fetchRecommendationStrategies();
408
+ const n = await u.fetchRecommendationStrategies();
405
409
  if (t !== b)
406
410
  return;
407
411
  this.strategies = n, this.strategiesFetched = !0;
@@ -495,7 +499,7 @@ const Y = () => ({
495
499
  const n = typeof t.updated_at == "string" ? t.updated_at : "", r = n ? `${t.strategy_id}:${n}:${e}` : "", o = r ? this.strategyUrlTemplates[r] : void 0;
496
500
  if (o)
497
501
  return o;
498
- const { full_path: i = "" } = await m.generateStrategyEndpoint(t, e) ?? {};
502
+ const { full_path: i = "" } = await u.generateStrategyEndpoint(t, e) ?? {};
499
503
  return r && i && (this.strategyUrlTemplates = {
500
504
  ...this.strategyUrlTemplates,
501
505
  [r]: i
@@ -513,7 +517,7 @@ const Y = () => ({
513
517
  throw new Error("[Guido] convertLegacyStrategy called without an active block");
514
518
  this.blockStates[n].legacyConversionLoading = !0;
515
519
  try {
516
- const r = await m.migrateLegacyStrategy(t, e);
520
+ const r = await u.migrateLegacyStrategy(t, e);
517
521
  this.invalidateStrategies();
518
522
  try {
519
523
  await this.fetchStrategies();
@@ -562,7 +566,7 @@ const Y = () => ({
562
566
  activePredictiveAlgorithms: t,
563
567
  languages: e,
564
568
  currencies: n
565
- } = await m.fetchRecommendationCreateData();
569
+ } = await u.fetchRecommendationCreateData();
566
570
  if (this.activePredictiveAlgorithms = t, this.languages = e, this.currentRecommendationId !== null && this.blockStates[this.currentRecommendationId]) {
567
571
  const r = this.blockStates[this.currentRecommendationId];
568
572
  r.filterStatus = !!r.recommendationConfigs.filters.length;
@@ -583,7 +587,7 @@ const Y = () => ({
583
587
  return;
584
588
  }
585
589
  y = (async () => {
586
- const t = await m.fetchRecommendationFilters();
590
+ const t = await u.fetchRecommendationFilters();
587
591
  this.filterList = t;
588
592
  })();
589
593
  try {
@@ -709,14 +713,14 @@ const Y = () => ({
709
713
  await this._doFetchStrategyProducts(e);
710
714
  return;
711
715
  }
712
- const i = (u.get(e) ?? 0) + 1;
713
- u.set(e, i);
716
+ const i = (m.get(e) ?? 0) + 1;
717
+ m.set(e, i);
714
718
  const s = parseInt(r.size) || 6;
715
719
  if (!r.strategy) {
716
720
  this._setBlockProducts(e, [], s);
717
721
  return;
718
722
  }
719
- const a = r.filters.filter((h) => h.isValid), d = P(a), f = ((S = F().find((h) => h.key === r.strategy)) == null ? void 0 : S.path) || "", c = {
723
+ const a = r.filters.filter((h) => h.isValid), d = P(a), f = ((S = w().find((h) => h.key === r.strategy)) == null ? void 0 : S.path) || "", c = {
720
724
  locale: r.language,
721
725
  currency: r.currencySettings.value,
722
726
  partnerName: o.partnerName,
@@ -730,11 +734,11 @@ const Y = () => ({
730
734
  );
731
735
  let g;
732
736
  try {
733
- g = await m.fetchRecommendationProducts(f, c);
737
+ g = await u.fetchRecommendationProducts(f, c);
734
738
  } catch {
735
739
  g = [];
736
740
  }
737
- u.get(e) === i && this._setBlockProducts(e, g, s);
741
+ m.get(e) === i && this._setBlockProducts(e, g, s);
738
742
  },
739
743
  /**
740
744
  * Block-scoped counterpart of `fetchRecommendationProducts`, which only serves the selected block:
@@ -773,8 +777,8 @@ const Y = () => ({
773
777
  return !0;
774
778
  },
775
779
  _doFetchStrategyProducts(t, e = {}) {
776
- const n = (u.get(t) ?? 0) + 1;
777
- u.set(t, n);
780
+ const n = (m.get(t) ?? 0) + 1;
781
+ m.set(t, n);
778
782
  const r = this._loadStrategyProducts(t, n, e);
779
783
  return _.set(t, { token: n, outcome: r }), r;
780
784
  },
@@ -789,20 +793,20 @@ const Y = () => ({
789
793
  if (s) {
790
794
  i = parseInt(String(s.size ?? "")) || i;
791
795
  const a = r.currencySettings.value, f = (await this.resolveStrategyUrlTemplate(s, a)).replaceAll("{locale}", r.language).replaceAll("{currency}", a), c = f.indexOf("?"), g = c === -1 ? f : f.slice(0, c), S = (c === -1 ? "" : f.slice(c + 1)).split("&").filter((v) => v && !v.startsWith("user_id=")), h = S.length ? `${g}?${S.join("&")}` : g;
792
- h && (o = await m.fetchRecommendationProductsByUrl(h));
796
+ h && (o = await u.fetchRecommendationProductsByUrl(h));
793
797
  }
794
798
  } catch {
795
799
  o = [];
796
800
  }
797
- return u.get(t) !== e ? W(t) : !o.length && n ? !1 : (this._setBlockProducts(t, o, i), o.length > 0);
801
+ return m.get(t) !== e ? W(t) : !o.length && n ? !1 : (this._setBlockProducts(t, o, i), o.length > 0);
798
802
  },
799
803
  _setBlockProducts(t, e, n) {
800
804
  if (!this.blockStates[t])
801
805
  return;
802
- const r = e.length > 0 ? e : w(n);
806
+ const r = e.length > 0 ? e : F(n);
803
807
  this.blockStates[t].recommendationProducts = [
804
808
  ...r.slice(0, n),
805
- ...w(Math.max(0, n - r.length))
809
+ ...F(Math.max(0, n - r.length))
806
810
  ];
807
811
  }
808
812
  }
@@ -1,13 +1,13 @@
1
1
  import { ModificationDescription as a } from "../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
2
2
  import { RECOMMENDATION_ID_ATTR as m } from "../constants/selectors.js";
3
- import { isPartnerManagedBlock as y, updateProductContentInPlace as I, regenerateProductRowsWithStyles as N } from "../controls/main/utils.js";
3
+ import { isPartnerManagedBlock as N, updateProductContentInPlace as I, regenerateProductRowsWithStyles as O } from "../controls/main/utils.js";
4
4
  import { RecommendationConfigService as c } from "../services/configService.js";
5
- import { useRecommendationExtensionStore as O } from "../store/recommendation.js";
5
+ import { useRecommendationExtensionStore as C } from "../store/recommendation.js";
6
6
  let r = null;
7
- function $(t) {
7
+ function T(t) {
8
8
  r = t;
9
9
  }
10
- function C(t) {
10
+ function p(t) {
11
11
  const n = r == null ? void 0 : r.getDocumentRootHtmlNode();
12
12
  return !n || !("querySelector" in n) ? null : n.querySelector(`[${m}="${t}"]`) ?? null;
13
13
  }
@@ -19,18 +19,18 @@ function R(t, n) {
19
19
  const o = c.getConfig(t);
20
20
  return ["filters", "strategy", "strategyId", "size", "productIds"].some((e) => e in n && JSON.stringify(o[e]) !== JSON.stringify(n[e]));
21
21
  }
22
- const p = "Updated product IDs";
23
- function S(t, n) {
22
+ const S = "Updated product IDs";
23
+ function y(t, n) {
24
24
  if (!("productIds" in n))
25
25
  return !1;
26
26
  const o = c.getConfig(t);
27
27
  return JSON.stringify(o.productIds) !== JSON.stringify(n.productIds);
28
28
  }
29
29
  function h(t, n, o) {
30
- return S(t, n) ? p : o;
30
+ return y(t, n) ? S : o;
31
31
  }
32
- function k(t, n, o) {
33
- const e = C(t);
32
+ function $(t, n, o) {
33
+ const e = p(t);
34
34
  if (!r || !e)
35
35
  return !1;
36
36
  if (R(e, n)) {
@@ -40,7 +40,7 @@ function k(t, n, o) {
40
40
  return !0;
41
41
  }
42
42
  function P(t, n) {
43
- const o = O(), e = o.currentRecommendationId;
43
+ const o = C(), e = o.currentRecommendationId;
44
44
  if (e === t || !o.blockStates[t]) {
45
45
  n();
46
46
  return;
@@ -52,16 +52,17 @@ function P(t, n) {
52
52
  o.$patch({ currentRecommendationId: e });
53
53
  }
54
54
  }
55
- function q(t) {
55
+ function k(t) {
56
56
  const n = r == null ? void 0 : r.getDocumentRootHtmlNode();
57
57
  return !n || !("querySelectorAll" in n) ? [] : n.querySelectorAll(`[${m}="${t}"]`).map((o) => c.getConfig(o));
58
58
  }
59
- function w(t, n, o, e) {
60
- const i = C(t);
59
+ function q(t, n, o, e) {
60
+ const i = p(t);
61
61
  if (!r || !i)
62
62
  return !1;
63
- const f = r.getDocumentModifier(), d = D(i, n), g = S(i, n), s = g ? p : e, l = { currentNode: i, documentModifier: f, products: o, ...g ? { description: s } : {} };
64
- if (c.stageConfig(f, i, n), y(i))
63
+ C().markProductsDrawn(t, o);
64
+ const f = r.getDocumentModifier(), d = D(i, n), g = y(i, n), s = g ? S : e, l = { currentNode: i, documentModifier: f, products: o, ...g ? { description: s } : {} };
65
+ if (c.stageConfig(f, i, n), N(i))
65
66
  return d && f.apply(new a(s)), !0;
66
67
  let u = !1;
67
68
  return P(t, () => {
@@ -70,16 +71,16 @@ function w(t, n, o, e) {
70
71
  onApplied: () => {
71
72
  u = !0;
72
73
  }
73
- }) || (u = N(l));
74
+ }) || (u = O(l));
74
75
  }), !u && d && f.apply(new a(s)), !0;
75
76
  }
76
77
  export {
77
- p as PRODUCT_IDS_DESCRIPTION,
78
- w as commitBlockChangeOutsidePanel,
78
+ S as PRODUCT_IDS_DESCRIPTION,
79
+ q as commitBlockChangeOutsidePanel,
79
80
  R as hasEditedConfigChange,
80
- S as isProductIdsChange,
81
+ y as isProductIdsChange,
81
82
  h as pickConfigDescription,
82
- q as readBlockNodeConfigs,
83
- $ as registerNodeConfigWriter,
84
- k as writeBlockConfigOutsidePanel
83
+ k as readBlockNodeConfigs,
84
+ T as registerNodeConfigWriter,
85
+ $ as writeBlockConfigOutsidePanel
85
86
  };
@@ -25,6 +25,5 @@ function f(c) {
25
25
  return r === "before" ? `${e} ${a}` : `${a} ${e}`;
26
26
  }
27
27
  export {
28
- d as formatNumber,
29
28
  f as formatPrice
30
29
  };
@@ -0,0 +1,25 @@
1
+ import { DisplayConditionEvent as i } from "../../enums/display-condition.js";
2
+ let n = null;
3
+ const d = () => {
4
+ n == null || n.detach();
5
+ }, L = (p, e) => {
6
+ var C;
7
+ const t = n;
8
+ t == null || t.detach(), (C = t == null ? void 0 : t.onCancel) == null || C.call(t);
9
+ let o = () => {
10
+ };
11
+ const l = (c) => {
12
+ const m = c.detail;
13
+ o(), m.applied = e.onApply(m.condition);
14
+ }, a = () => {
15
+ var c;
16
+ o(), (c = e.onCancel) == null || c.call(e);
17
+ };
18
+ return o = () => {
19
+ document.removeEventListener(i.APPLY, l), document.removeEventListener(i.CANCEL, a), (n == null ? void 0 : n.detach) === o && (n = null);
20
+ }, document.addEventListener(i.APPLY, l), document.addEventListener(i.CANCEL, a), n = { detach: o, onCancel: e.onCancel }, document.dispatchEvent(new CustomEvent(i.OPEN, { detail: p })), o;
21
+ };
22
+ export {
23
+ d as disposeDisplayConditionRequest,
24
+ L as requestDisplayCondition
25
+ };
@@ -0,0 +1,26 @@
1
+ import { BlockType as o } from "../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
2
+ const n = "conditions", t = "guido-display-conditions-control", d = 10, s = [o.STRIPE, o.STRUCTURE, o.CONTAINER], c = {
3
+ PLUS: "guido-display-condition-plus",
4
+ EDIT: "guido-display-condition-edit",
5
+ TRASH: "guido-display-condition-trash",
6
+ CHEVRON: "guido-display-condition-chevron"
7
+ }, e = {
8
+ ADD: "guidoDisplayConditionAdd",
9
+ CREATE: "guidoDisplayConditionCreate",
10
+ SELECT: "guidoDisplayConditionSelect",
11
+ SHOW_MORE: "guidoDisplayConditionShowMore",
12
+ SHOW_LESS: "guidoDisplayConditionShowLess",
13
+ EDIT: "guidoDisplayConditionEdit",
14
+ REMOVE: "guidoDisplayConditionRemove"
15
+ }, C = ["applyConditionSwitcher", "applyCondition", "displayConditions"], a = "You can add Display Condition by selecting an existing condition or creating a new one to show specific content.", O = "You can create or select a display condition to control content visibility based on your recipients' properties or events.";
16
+ export {
17
+ O as APPLIED_DESCRIPTION,
18
+ C as BUILT_IN_CONDITION_CONTROLS,
19
+ t as CONDITIONS_CONTROL_ID,
20
+ n as CONDITIONS_TAB_ID,
21
+ s as CONDITION_BLOCK_TYPES,
22
+ e as CONDITION_BUTTONS,
23
+ c as CONDITION_ICONS,
24
+ a as EMPTY_DESCRIPTION,
25
+ d as MAX_COLLAPSED_LINES
26
+ };
@@ -0,0 +1,215 @@
1
+ var b = Object.defineProperty;
2
+ var v = (c, a, i) => a in c ? b(c, a, { enumerable: !0, configurable: !0, writable: !0, value: i }) : c[a] = i;
3
+ var u = (c, a, i) => v(c, typeof a != "symbol" ? a + "" : a, i);
4
+ import { useToaster as O } from "../../composables/useToaster.js";
5
+ import { useTranslations as w } from "../../composables/useTranslations.js";
6
+ import { DisplayConditionSourceType as N } from "../../enums/display-condition.js";
7
+ import { ToasterTypeOptions as S } from "../../enums/toaster.js";
8
+ import { CommonControl as E } from "../Blocks/common-control.js";
9
+ import { toAppliedCondition as D, parseSource as T } from "../../utils/displayCondition.js";
10
+ import { escapeHtml as f } from "../../utils/htmlEscape.js";
11
+ import { ModificationDescription as I } from "../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
12
+ import { requestDisplayCondition as M } from "./bridge.js";
13
+ import { CONDITIONS_CONTROL_ID as $, CONDITION_ICONS as h, CONDITION_BUTTONS as r, APPLIED_DESCRIPTION as x, EMPTY_DESCRIPTION as L, MAX_COLLAPSED_LINES as C } from "./constants.js";
14
+ const l = ".guido-display-conditions", R = { id: 0, name: "", description: "", beforeScript: "", afterScript: "" };
15
+ class F extends E {
16
+ constructor() {
17
+ super(...arguments);
18
+ u(this, "expanded", !1);
19
+ u(this, "listeners", []);
20
+ u(this, "resizeObserver", null);
21
+ u(this, "detachOutsideClick", null);
22
+ }
23
+ getId() {
24
+ return $;
25
+ }
26
+ getTemplate() {
27
+ return `
28
+ <div class="guido-display-conditions">
29
+ <div class="guido-display-conditions__header">
30
+ <p class="guido-display-conditions__title">${this.api.translate("Display Conditions")}</p>
31
+ <p class="guido-display-conditions__description" data-dc-description></p>
32
+ </div>
33
+ <div class="guido-display-conditions__empty" data-dc-empty>
34
+ ${this._GuButton({
35
+ name: r.ADD,
36
+ id: "guido__btn-add-display-condition",
37
+ className: "guido-display-conditions__add",
38
+ icon: h.PLUS,
39
+ label: this.api.translate("Add Display Condition")
40
+ })}
41
+ <div class="guido-display-conditions__menu" data-dc-menu hidden>
42
+ ${this._GuButton({
43
+ name: r.CREATE,
44
+ id: "guido__btn-display-condition-create",
45
+ className: "guido-display-conditions__menu-item",
46
+ label: this.api.translate("Create New Condition")
47
+ })}
48
+ ${this._GuButton({
49
+ name: r.SELECT,
50
+ id: "guido__btn-display-condition-select",
51
+ className: "guido-display-conditions__menu-item",
52
+ label: this.api.translate("Select Saved Condition")
53
+ })}
54
+ </div>
55
+ </div>
56
+ <div class="guido-display-conditions__applied" data-dc-applied hidden>
57
+ <div class="guido-display-conditions__code-box">
58
+ <p class="guido-display-conditions__name" data-dc-name></p>
59
+ <div class="guido-display-conditions__sections" data-dc-sections>
60
+ <p class="guido-display-conditions__section-label">
61
+ ${this.api.translate("Code Before Module")}
62
+ </p>
63
+ <pre class="guido-display-conditions__code" data-dc-before></pre>
64
+ <p class="guido-display-conditions__section-label" data-dc-after-label>
65
+ ${this.api.translate("Code After Module")}
66
+ </p>
67
+ <pre class="guido-display-conditions__code" data-dc-after></pre>
68
+ </div>
69
+ ${this._GuButton({
70
+ name: r.SHOW_MORE,
71
+ id: "guido__btn-display-condition-show-more",
72
+ className: "guido-display-conditions__toggle",
73
+ icon: h.CHEVRON,
74
+ label: this.api.translate("Show More")
75
+ })}
76
+ ${this._GuButton({
77
+ name: r.SHOW_LESS,
78
+ id: "guido__btn-display-condition-show-less",
79
+ className: "guido-display-conditions__toggle guido-display-conditions__toggle--less",
80
+ icon: h.CHEVRON,
81
+ label: this.api.translate("Show Less")
82
+ })}
83
+ </div>
84
+ <div class="guido-display-conditions__actions">
85
+ ${this._GuButton({
86
+ name: r.EDIT,
87
+ id: "guido__btn-edit-display-condition",
88
+ className: "guido-display-conditions__action guido-display-conditions__action--edit",
89
+ icon: h.EDIT,
90
+ label: this.api.translate("Edit")
91
+ })}
92
+ ${this._GuButton({
93
+ name: r.REMOVE,
94
+ id: "guido__btn-remove-display-condition",
95
+ className: "guido-display-conditions__action guido-display-conditions__action--remove",
96
+ icon: h.TRASH,
97
+ label: this.api.translate("Remove")
98
+ })}
99
+ </div>
100
+ </div>
101
+ </div>
102
+ `;
103
+ }
104
+ onRender() {
105
+ this.forgetLastPanelNode(), this.teardown(), this.wire("#guido__btn-add-display-condition", () => this.toggleMenu()), this.wire("#guido__btn-display-condition-create", () => this.openDrawer("create")), this.wire("#guido__btn-display-condition-select", () => this.openDrawer("select")), this.wire("#guido__btn-edit-display-condition", () => this.openDrawer("edit")), this.wire("#guido__btn-remove-display-condition", () => this.removeCondition()), this.wire("#guido__btn-display-condition-show-more", () => this.setExpanded(!0)), this.wire("#guido__btn-display-condition-show-less", () => this.setExpanded(!1)), this.observeCodeSize();
106
+ }
107
+ onTemplateNodeUpdated(i) {
108
+ const t = i !== this.currentNode;
109
+ super.onTemplateNodeUpdated(i), t && (this.expanded = !1, this.toggleMenu(!1)), this.paint();
110
+ }
111
+ onDestroy() {
112
+ super.onDestroy(), this.teardown();
113
+ }
114
+ setExpanded(i) {
115
+ this.expanded = i, this.paint();
116
+ }
117
+ getCondition() {
118
+ var t;
119
+ const i = this.currentNode;
120
+ return D((t = i == null ? void 0 : i.getDisplayCondition) == null ? void 0 : t.call(i));
121
+ }
122
+ toggleMenu(i) {
123
+ var o, s, n;
124
+ const t = (o = this.getContainer()) == null ? void 0 : o.querySelector(`${l} [data-dc-menu]`);
125
+ if (!t)
126
+ return;
127
+ t.hidden = i === void 0 ? !t.hidden : !i, (s = this.detachOutsideClick) == null || s.call(this), t.hidden || this.listenOutsideClick();
128
+ const e = (n = this.getContainer()) == null ? void 0 : n.querySelector(`${l} #guido__btn-add-display-condition`);
129
+ t.style.width = !t.hidden && e ? `${e.getBoundingClientRect().width}px` : "";
130
+ }
131
+ listenOutsideClick() {
132
+ var e;
133
+ const i = ((e = this.getContainer()) == null ? void 0 : e.ownerDocument) ?? document, t = (o) => {
134
+ o.composedPath().some((n) => n instanceof HTMLElement && n.matches(`${l} [data-dc-menu], ${l} #guido__btn-add-display-condition`)) || this.toggleMenu(!1);
135
+ };
136
+ i.addEventListener("pointerdown", t, !0), this.detachOutsideClick = () => {
137
+ i.removeEventListener("pointerdown", t, !0), this.detachOutsideClick = null;
138
+ };
139
+ }
140
+ openDrawer(i) {
141
+ const t = this.currentNode;
142
+ this.toggleMenu(!1), M(
143
+ { mode: i, current: i === "edit" ? this.getCondition() : null },
144
+ { onApply: (e) => this.applyCondition(e, t) }
145
+ );
146
+ }
147
+ // The drawer flows toast through useDisplayConditions; Remove has no drawer, so it toasts here.
148
+ removeCondition() {
149
+ this.applyCondition(null) || O().showToaster({
150
+ type: S.Error,
151
+ message: w()("products.something-went-wrong")
152
+ });
153
+ }
154
+ // The panel can move to another block while the drawer is open; apply onto the block it was opened for.
155
+ applyCondition(i, t = this.currentNode) {
156
+ if (!t)
157
+ return !1;
158
+ try {
159
+ const e = this.api.getDocumentModifier().modifyHtml(t);
160
+ return e.setDisplayCondition(i || R), e.apply(new I(
161
+ i ? `Set display condition ${i.name}` : "Remove display condition"
162
+ )), !0;
163
+ } catch (e) {
164
+ return console.warn("Display condition could not be applied.", e), !1;
165
+ }
166
+ }
167
+ wire(i, t) {
168
+ var o;
169
+ const e = (o = this.getContainer()) == null ? void 0 : o.querySelector(`${l} ${i}`);
170
+ e && (e.addEventListener("click", t), this.listeners.push({ element: e, handler: t }));
171
+ }
172
+ teardown() {
173
+ var i, t;
174
+ this.listeners.forEach(({ element: e, handler: o }) => e.removeEventListener("click", o)), this.listeners = [], (i = this.resizeObserver) == null || i.disconnect(), this.resizeObserver = null, (t = this.detachOutsideClick) == null || t.call(this);
175
+ }
176
+ // Line counts depend on layout: the panel font loads late and the panel can be resized.
177
+ observeCodeSize() {
178
+ var t;
179
+ const i = (t = this.getContainer()) == null ? void 0 : t.querySelectorAll(`${l} .guido-display-conditions__code`);
180
+ !(i != null && i.length) || typeof ResizeObserver > "u" || (this.resizeObserver = new ResizeObserver(() => this.paint()), i.forEach((e) => {
181
+ var o;
182
+ return (o = this.resizeObserver) == null ? void 0 : o.observe(e);
183
+ }));
184
+ }
185
+ paint() {
186
+ var y;
187
+ const i = (y = this.getContainer()) == null ? void 0 : y.querySelector(l);
188
+ if (!i)
189
+ return;
190
+ const t = this.getCondition(), e = (_) => i.querySelector(_);
191
+ if (e("[data-dc-empty]").hidden = !!t, e("[data-dc-applied]").hidden = !t, e("[data-dc-description]").textContent = this.api.translate(t ? x : L), !t)
192
+ return;
193
+ e("[data-dc-name]").textContent = t.name;
194
+ const o = T(t) === N.INLINE;
195
+ e("#guido__btn-edit-display-condition").hidden = !o;
196
+ const s = e("[data-dc-sections]"), n = e("[data-dc-before]"), d = e("[data-dc-after]");
197
+ n.innerHTML = f(t.beforeScript), d.innerHTML = f(t.afterScript), d.hidden = !t.afterScript, e("[data-dc-after-label]").hidden = !t.afterScript, s.style.maxHeight = "";
198
+ const p = parseFloat(getComputedStyle(n).lineHeight) || 24, m = (_) => _.hidden ? 0 : Math.round(_.scrollHeight / p), g = m(n) + m(d) > C;
199
+ e("#guido__btn-display-condition-show-more").hidden = !g || this.expanded, e("#guido__btn-display-condition-show-less").hidden = !g || !this.expanded, g && !this.expanded && (s.style.maxHeight = `${this.collapsedHeight(s, [n, d], p)}px`);
200
+ }
201
+ // Labels do not count toward the line limit, so the cut lands after the 10th rendered code line.
202
+ collapsedHeight(i, t, e) {
203
+ const { top: o } = i.getBoundingClientRect();
204
+ let s = C, n = 0;
205
+ return t.filter((d) => !d.hidden).forEach((d) => {
206
+ if (s <= 0)
207
+ return;
208
+ const p = Math.min(s, Math.round(d.scrollHeight / e));
209
+ n = d.getBoundingClientRect().top - o + p * e, s -= p;
210
+ }), n;
211
+ }
212
+ }
213
+ export {
214
+ F as DisplayConditionsControl
215
+ };