@useinsider/guido 2.1.0-beta.42f5dfa → 2.1.0-beta.486ee9c

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 (112) hide show
  1. package/README.md +36 -0
  2. package/dist/@types/config/schemas.js +70 -65
  3. package/dist/components/Guido.vue.js +1 -1
  4. package/dist/components/Guido.vue2.js +69 -58
  5. package/dist/components/organisms/base/Toaster.vue.js +4 -4
  6. package/dist/components/organisms/base/Toaster.vue2.js +12 -9
  7. package/dist/components/organisms/email-preview/desktop-preview/EmailSizeIndicator.vue.js +5 -5
  8. package/dist/components/organisms/email-preview/desktop-preview/EmailSizeIndicator.vue2.js +2 -2
  9. package/dist/components/organisms/extensions/recommendation/FilterItem.vue.js +11 -13
  10. package/dist/components/organisms/extensions/recommendation/FilterItem.vue2.js +54 -23
  11. package/dist/components/organisms/extensions/recommendation/FilterSelectionDrawer.vue.js +7 -5
  12. package/dist/components/organisms/extensions/recommendation/FilterSelectionDrawer.vue2.js +34 -21
  13. package/dist/components/organisms/extensions/recommendation/Filters.vue.js +11 -11
  14. package/dist/components/organisms/extensions/recommendation/Filters.vue2.js +48 -36
  15. package/dist/components/organisms/extensions/recommendation/LogicAdapter.vue2.js +11 -9
  16. package/dist/components/organisms/header/HeaderWrapper.vue.js +9 -9
  17. package/dist/components/organisms/unsubscribe/UnsubscribePageSelection.vue.js +1 -1
  18. package/dist/components/organisms/unsubscribe/UnsubscribePageSelection.vue2.js +19 -19
  19. package/dist/composables/useBlocksConfig.js +26 -16
  20. package/dist/composables/useHtmlValidator.js +107 -119
  21. package/dist/composables/useRecommendation.js +9 -9
  22. package/dist/composables/useStripo.js +25 -23
  23. package/dist/composables/useVersionHistoryApi.js +1 -1
  24. package/dist/config/compiler/utils/recommendationCompilerUtils.js +28 -23
  25. package/dist/config/i18n/en/index.js +11 -0
  26. package/dist/config/i18n/en/labels.json.js +7 -0
  27. package/dist/config/i18n/en/toasters.json.js +56 -0
  28. package/dist/config/i18n/en/tooltips.json.js +82 -0
  29. package/dist/config/i18n/index.js +7 -0
  30. package/dist/config/migrator/itemsBlockMigrator.js +127 -122
  31. package/dist/config/migrator/recommendationMigrator.js +1 -1
  32. package/dist/enums/defaults.js +8 -4
  33. package/dist/extensions/Blocks/Recommendation/block.js +26 -23
  34. package/dist/extensions/Blocks/Recommendation/constants/defaultConfig.js +37 -33
  35. package/dist/extensions/Blocks/Recommendation/constants/layout.js +16 -12
  36. package/dist/extensions/Blocks/Recommendation/constants/selectors.js +15 -11
  37. package/dist/extensions/Blocks/Recommendation/controls/button/index.js +9 -9
  38. package/dist/extensions/Blocks/Recommendation/controls/image/index.js +1 -1
  39. package/dist/extensions/Blocks/Recommendation/controls/layout/index.js +41 -29
  40. package/dist/extensions/Blocks/Recommendation/controls/main/algorithm.js +16 -16
  41. package/dist/extensions/Blocks/Recommendation/controls/main/currency.js +30 -32
  42. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +217 -94
  43. package/dist/extensions/Blocks/Recommendation/controls/main/locale.js +9 -9
  44. package/dist/extensions/Blocks/Recommendation/controls/main/productLayout.js +97 -39
  45. package/dist/extensions/Blocks/Recommendation/controls/main/shuffle.js +16 -16
  46. package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +304 -209
  47. package/dist/extensions/Blocks/Recommendation/controls/mobileLayout/cssRules.js +21 -0
  48. package/dist/extensions/Blocks/Recommendation/controls/name/index.js +10 -10
  49. package/dist/extensions/Blocks/Recommendation/controls/name/textTrim.js +5 -5
  50. package/dist/extensions/Blocks/Recommendation/controls/oldPrice/index.js +14 -14
  51. package/dist/extensions/Blocks/Recommendation/controls/omnibusDiscount/index.js +9 -9
  52. package/dist/extensions/Blocks/Recommendation/controls/omnibusDiscount/textAfter.js +3 -3
  53. package/dist/extensions/Blocks/Recommendation/controls/omnibusDiscount/textBefore.js +1 -1
  54. package/dist/extensions/Blocks/Recommendation/controls/omnibusPrice/index.js +9 -9
  55. package/dist/extensions/Blocks/Recommendation/controls/omnibusPrice/textAfter.js +3 -3
  56. package/dist/extensions/Blocks/Recommendation/controls/omnibusPrice/textBefore.js +13 -13
  57. package/dist/extensions/Blocks/Recommendation/controls/price/index.js +3 -3
  58. package/dist/extensions/Blocks/Recommendation/controls/spacing/index.js +223 -99
  59. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +237 -140
  60. package/dist/extensions/Blocks/Recommendation/templates/grid/elementRenderer.js +27 -32
  61. package/dist/extensions/Blocks/Recommendation/templates/grid/migration.js +1 -1
  62. package/dist/extensions/Blocks/Recommendation/templates/grid/template.js +27 -30
  63. package/dist/extensions/Blocks/Recommendation/templates/list/elementRenderer.js +22 -27
  64. package/dist/extensions/Blocks/Recommendation/templates/utils.js +50 -38
  65. package/dist/extensions/Blocks/Recommendation/utils/filterUtil.js +8 -8
  66. package/dist/extensions/Blocks/Recommendation/validation/filterSchema.js +29 -0
  67. package/dist/extensions/Blocks/Unsubscribe/block.js +29 -29
  68. package/dist/extensions/Blocks/Unsubscribe/control.js +12 -9
  69. package/dist/extensions/Blocks/Unsubscribe/elements/preview.js +13 -11
  70. package/dist/extensions/Blocks/Unsubscribe/styles.css.js +31 -1
  71. package/dist/extensions/ModulesTabIcons/extension.js +17 -0
  72. package/dist/guido.css +1 -1
  73. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +257 -187
  74. package/dist/services/recommendationApi.js +11 -9
  75. package/dist/services/stripoApi.js +20 -17
  76. package/dist/src/@types/config/schemas.d.ts +8 -0
  77. package/dist/src/components/organisms/extensions/recommendation/FilterItem.vue.d.ts +1 -0
  78. package/dist/src/components/organisms/extensions/recommendation/Filters.vue.d.ts +17 -1
  79. package/dist/src/composables/useConfig.d.ts +4 -0
  80. package/dist/src/config/i18n/en/index.d.ts +1 -0
  81. package/dist/src/config/i18n/index.d.ts +16 -0
  82. package/dist/src/enums/defaults.d.ts +4 -0
  83. package/dist/src/extensions/Blocks/Recommendation/constants/defaultConfig.d.ts +6 -0
  84. package/dist/src/extensions/Blocks/Recommendation/constants/index.d.ts +3 -3
  85. package/dist/src/extensions/Blocks/Recommendation/constants/layout.d.ts +12 -2
  86. package/dist/src/extensions/Blocks/Recommendation/constants/selectors.d.ts +12 -1
  87. package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +50 -11
  88. package/dist/src/extensions/Blocks/Recommendation/controls/main/productLayout.d.ts +22 -4
  89. package/dist/src/extensions/Blocks/Recommendation/controls/main/utils.d.ts +36 -16
  90. package/dist/src/extensions/Blocks/Recommendation/controls/mobileLayout/cssRules.d.ts +29 -0
  91. package/dist/src/extensions/Blocks/Recommendation/controls/spacing/index.d.ts +50 -17
  92. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +26 -2
  93. package/dist/src/extensions/Blocks/Recommendation/templates/grid/migration.d.ts +1 -1
  94. package/dist/src/extensions/Blocks/Recommendation/templates/grid/template.d.ts +1 -1
  95. package/dist/src/extensions/Blocks/Recommendation/templates/index.d.ts +4 -0
  96. package/dist/src/extensions/Blocks/Recommendation/templates/list/migration.d.ts +1 -1
  97. package/dist/src/extensions/Blocks/Recommendation/templates/utils.d.ts +12 -3
  98. package/dist/src/extensions/Blocks/Recommendation/types/nodeConfig.d.ts +14 -0
  99. package/dist/src/extensions/Blocks/Recommendation/validation/filterSchema.d.ts +15 -0
  100. package/dist/src/extensions/Blocks/Unsubscribe/control.d.ts +1 -0
  101. package/dist/src/extensions/ModulesTabIcons/extension.d.ts +2 -0
  102. package/dist/src/stores/config.d.ts +36 -0
  103. package/dist/static/styles/components/notification.css.js +19 -0
  104. package/dist/static/styles/components/tools.css.js +6 -2
  105. package/dist/static/styles/components/version-history.css.js +10 -2
  106. package/dist/static/styles/components/wide-panel.css.js +18 -2
  107. package/dist/static/styles/customEditorStyle.css.js +59 -31
  108. package/dist/static/styles/variables.css.js +2 -0
  109. package/dist/static/templates/empty/index.html.js +74 -0
  110. package/dist/static/templates/empty/style.css.js +779 -0
  111. package/dist/stores/unsubscribe.js +37 -34
  112. package/package.json +2 -2
@@ -1,13 +1,17 @@
1
- import { RecommendationFeedSourceMaps as u, PriceAttributes as g } from "../../../../enums/extensions/recommendationBlock.js";
2
- import { useRecommendationApi as S } from "../../../../services/recommendationApi.js";
3
- import { useConfigStore as p } from "../../../../stores/config.js";
4
- import { defineStore as b } from "pinia";
5
- import { DEFAULT_CARDS_IN_ROW as I } from "../constants/layout.js";
6
- import { generateCompleteFilterQuery as d } from "../utils/filterUtil.js";
7
- const l = S();
8
- function f() {
1
+ import { RecommendationFeedSourceMaps as g, getOperatorOptions as R, PriceAttributes as k } from "../../../../enums/extensions/recommendationBlock.js";
2
+ import { useRecommendationApi as y } from "../../../../services/recommendationApi.js";
3
+ import { useConfigStore as C } from "../../../../stores/config.js";
4
+ import { defineStore as G } from "pinia";
5
+ import { DEFAULT_CARDS_IN_ROW as F } from "../constants/layout.js";
6
+ import { EXCLUDED_ALGORITHM_IDS as w } from "../constants/defaultConfig.js";
7
+ import { getDefaultProducts as S } from "../templates/utils.js";
8
+ import { generateCompleteFilterQuery as I } from "../utils/filterUtil.js";
9
+ import { isFilterValid as D } from "../validation/filterSchema.js";
10
+ const h = y();
11
+ let u = null, m = null, d = null;
12
+ function b() {
9
13
  return {
10
- cardsInRow: I,
14
+ cardsInRow: F,
11
15
  currencySettings: {
12
16
  name: "USD",
13
17
  value: "USD",
@@ -20,7 +24,7 @@ function f() {
20
24
  filters: [],
21
25
  productIds: [],
22
26
  id: 1,
23
- language: "tr_TR",
27
+ language: "en_US",
24
28
  orientation: "grid",
25
29
  recommendedProducts: [],
26
30
  sendProductRequestFlag: !1,
@@ -31,16 +35,18 @@ function f() {
31
35
  size: "6"
32
36
  };
33
37
  }
34
- function R() {
38
+ function P() {
35
39
  return {
36
- recommendationConfigs: f(),
40
+ recommendationConfigs: b(),
37
41
  recommendationProducts: [],
38
42
  filterStatus: !1,
39
43
  filterSelectionDrawerStatus: !1,
40
- filterGroup: 1
44
+ filterGroup: 1,
45
+ isInitialized: !1,
46
+ filterSnapshot: null
41
47
  };
42
48
  }
43
- const k = () => ({
49
+ const v = () => ({
44
50
  recommendationCampaignUrls: {},
45
51
  activePredictiveAlgorithms: [],
46
52
  languages: {},
@@ -49,8 +55,8 @@ const k = () => ({
49
55
  blockStates: {},
50
56
  currentRecommendationId: null,
51
57
  configVersion: 0
52
- }), D = b("guidoRecommendationExtension", {
53
- state: () => k(),
58
+ }), E = G("guidoRecommendationExtension", {
59
+ state: () => v(),
54
60
  getters: {
55
61
  // ====================================================================
56
62
  // Proxy Getters — Backward Compatible Access to Current Block State
@@ -59,32 +65,32 @@ const k = () => ({
59
65
  * Proxy getter: delegates to blockStates[currentRecommendationId].recommendationConfigs
60
66
  * This allows all existing code that reads `store.recommendationConfigs` to work unchanged.
61
67
  */
62
- recommendationConfigs(e) {
63
- return e.currentRecommendationId !== null && e.blockStates[e.currentRecommendationId] ? e.blockStates[e.currentRecommendationId].recommendationConfigs : f();
68
+ recommendationConfigs(t) {
69
+ return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs : b();
64
70
  },
65
71
  /**
66
72
  * Proxy getter: delegates to blockStates[currentRecommendationId].recommendationProducts
67
73
  */
68
- recommendationProducts(e) {
69
- return e.currentRecommendationId !== null && e.blockStates[e.currentRecommendationId] ? e.blockStates[e.currentRecommendationId].recommendationProducts : [];
74
+ recommendationProducts(t) {
75
+ return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationProducts : [];
70
76
  },
71
77
  /**
72
78
  * Proxy getter: delegates to blockStates[currentRecommendationId].filterSelectionDrawerStatus
73
79
  */
74
- filterSelectionDrawerStatus(e) {
75
- return e.currentRecommendationId !== null && e.blockStates[e.currentRecommendationId] ? e.blockStates[e.currentRecommendationId].filterSelectionDrawerStatus : !1;
80
+ filterSelectionDrawerStatus(t) {
81
+ return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].filterSelectionDrawerStatus : !1;
76
82
  },
77
83
  /**
78
84
  * Proxy getter: delegates to blockStates[currentRecommendationId].filterStatus
79
85
  */
80
- filterStatus(e) {
81
- return e.currentRecommendationId !== null && e.blockStates[e.currentRecommendationId] ? e.blockStates[e.currentRecommendationId].filterStatus : !1;
86
+ filterStatus(t) {
87
+ return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].filterStatus : !1;
82
88
  },
83
89
  /**
84
90
  * Proxy getter: delegates to blockStates[currentRecommendationId].filterGroup
85
91
  */
86
- filterGroup(e) {
87
- return e.currentRecommendationId !== null && e.blockStates[e.currentRecommendationId] ? e.blockStates[e.currentRecommendationId].filterGroup : 1;
92
+ filterGroup(t) {
93
+ return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].filterGroup : 1;
88
94
  },
89
95
  // ====================================================================
90
96
  // Existing Getters (now reading through proxy)
@@ -92,40 +98,48 @@ const k = () => ({
92
98
  hasFilters() {
93
99
  return !!this.recommendationConfigs.filters.length;
94
100
  },
101
+ hasValidFilters() {
102
+ const { filters: t } = this.recommendationConfigs;
103
+ return t.length ? t.every((r) => r.isValid) : !1;
104
+ },
95
105
  getFilterGroupCount() {
96
- const { filters: e } = this.recommendationConfigs;
97
- return e.length && e[e.length - 1].filterGroup || 0;
106
+ const { filters: t } = this.recommendationConfigs;
107
+ return t.length ? new Set(t.map((r) => r.filterGroup)).size : 0;
108
+ },
109
+ getUniqueFilterGroups() {
110
+ const { filters: t } = this.recommendationConfigs;
111
+ return [...new Set(t.map((r) => r.filterGroup))].sort((r, e) => r - e);
98
112
  },
99
- getActivePredictiveAlgorithms: (e) => {
113
+ getActivePredictiveAlgorithms: (t) => {
100
114
  const r = [];
101
- return e.activePredictiveAlgorithms.forEach((t) => {
102
- r.push(...u.filter((n) => n.id === t));
103
- }), r.map((t) => ({
104
- text: t.name,
105
- value: t.key
115
+ return t.activePredictiveAlgorithms.filter((e) => !w.includes(e)).forEach((e) => {
116
+ r.push(...g.filter((n) => n.id === e));
117
+ }), r.map((e) => ({
118
+ text: e.name,
119
+ value: e.key
106
120
  }));
107
121
  },
108
- getLanguages: (e) => Object.entries(e.languages).map(([r, t]) => ({
109
- text: t,
122
+ getLanguages: (t) => Object.entries(t.languages).map(([r, e]) => ({
123
+ text: e,
110
124
  value: r
111
125
  })),
112
- getCurrencySymbolList: (e) => e.currencyList.map((r) => ({
126
+ getCurrencySymbolList: (t) => t.currencyList.map((r) => ({
113
127
  text: r.text,
114
128
  value: r.text
115
129
  })),
116
130
  getFilterList() {
117
- return Object.values(this.filterList).map((e) => {
118
- const r = e.type === "defaultAttribute", t = g.includes(e.attributeName);
119
- let n = r ? e.attributeName : `product_attributes.${e.attributeName}`;
120
- return n = t ? `${n}.${this.recommendationConfigs.currencySettings.value}` : n, {
121
- text: e.displayName,
131
+ return Object.values(this.filterList).map((t) => {
132
+ const r = t.type === "defaultAttribute", e = k.includes(t.attributeName);
133
+ let n = r ? t.attributeName : `product_attributes.${t.attributeName}`;
134
+ return n = e ? `${n}.${this.recommendationConfigs.currencySettings.value}` : n, {
135
+ text: t.displayName,
122
136
  value: n,
123
- type: e.attributeType
137
+ type: t.attributeType
124
138
  };
125
139
  });
126
140
  },
127
141
  getSelectedFilterGroup() {
128
- return (e) => [...this.recommendationConfigs.filters].filter((r) => r.filterGroup === e);
142
+ return (t) => [...this.recommendationConfigs.filters].filter((r) => r.filterGroup === t);
129
143
  }
130
144
  },
131
145
  actions: {
@@ -136,169 +150,252 @@ const k = () => ({
136
150
  * Sets the currently active block ID.
137
151
  * Creates a new entry in blockStates if one doesn't exist.
138
152
  */
139
- setCurrentBlock(e) {
140
- this.blockStates[e] || (this.blockStates = {
153
+ setCurrentBlock(t) {
154
+ this.blockStates[t] || (this.blockStates = {
141
155
  ...this.blockStates,
142
- [e]: R()
143
- }), this.currentRecommendationId = e;
156
+ [t]: P()
157
+ }), this.currentRecommendationId = t;
144
158
  },
145
159
  /**
146
160
  * Removes a block's state from the store.
147
161
  * Resets currentRecommendationId if it was the deleted block.
148
162
  */
149
- removeBlockState(e) {
163
+ removeBlockState(t) {
150
164
  const r = { ...this.blockStates };
151
- if (delete r[e], this.blockStates = r, this.currentRecommendationId === e) {
152
- const t = Object.keys(this.blockStates).map(Number);
153
- this.currentRecommendationId = t.length > 0 ? t[0] : null;
165
+ if (delete r[t], this.blockStates = r, this.currentRecommendationId === t) {
166
+ const e = Object.keys(this.blockStates).map(Number);
167
+ this.currentRecommendationId = e.length > 0 ? e[0] : null;
154
168
  }
155
169
  },
170
+ /**
171
+ * Marks a block as initialized (initial API data has been fetched).
172
+ * Automatically cleaned up when removeBlockState deletes the block entry.
173
+ */
174
+ markBlockInitialized(t) {
175
+ this.blockStates[t] && (this.blockStates[t].isInitialized = !0);
176
+ },
156
177
  /**
157
178
  * Patches the current block's recommendationConfigs.
158
179
  * Replaces `store.$patch({ recommendationConfigs: { ... } })` pattern.
159
180
  */
160
- patchCurrentBlockConfig(e, r = {}) {
181
+ patchCurrentBlockConfig(t, r = {}) {
161
182
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
162
183
  return;
163
- const t = this.blockStates[this.currentRecommendationId];
164
- t.recommendationConfigs = {
165
- ...t.recommendationConfigs,
166
- ...e,
184
+ const e = this.blockStates[this.currentRecommendationId];
185
+ e.recommendationConfigs = {
186
+ ...e.recommendationConfigs,
187
+ ...t,
167
188
  currencySettings: {
168
- ...t.recommendationConfigs.currencySettings,
169
- ...e.currencySettings || {}
189
+ ...e.recommendationConfigs.currencySettings,
190
+ ...t.currencySettings || {}
170
191
  }
171
192
  };
172
193
  const { triggerRefetch: n = !0 } = r;
173
194
  n && this.configVersion++;
174
195
  },
175
196
  /**
176
- * Opens the filter selection drawer for the current block.
177
- * If no filters exist, initializes with a default empty filter
178
- * so the user has a starting point for input.
197
+ * Creates a filter with the first available attribute and operator pre-selected.
179
198
  */
180
- openFilterDrawer() {
181
- if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
182
- return;
183
- const e = this.blockStates[this.currentRecommendationId];
184
- e.recommendationConfigs.filters.length || (e.recommendationConfigs.filters = [{
199
+ createDefaultFilter(t, r) {
200
+ const [e] = this.getFilterList, [n] = R(e == null ? void 0 : e.type);
201
+ return {
185
202
  type: "standardFilter",
186
- attribute: "",
187
- operatorReplace: "",
188
- operator: "",
203
+ attribute: (e == null ? void 0 : e.value) ?? "",
204
+ operator: (n == null ? void 0 : n.value) ?? "",
189
205
  innerGroupOperator: "*",
190
206
  outerGroupOperator: "*",
191
- filterNumber: 1,
192
- filterGroup: 1,
207
+ filterNumber: r,
208
+ filterGroup: t,
193
209
  isValid: !1,
194
210
  value: ""
195
- }]), e.filterSelectionDrawerStatus = !0;
211
+ };
196
212
  },
197
213
  /**
198
- * Closes the filter selection drawer for the current block
214
+ * Opens the filter selection drawer for the current block.
215
+ * Saves a snapshot of current filters for cancel/revert.
216
+ * If no filters exist, initializes with a default filter
217
+ * so the user has a starting point for input.
218
+ */
219
+ openFilterDrawer() {
220
+ if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
221
+ return;
222
+ const t = this.blockStates[this.currentRecommendationId];
223
+ t.filterSnapshot = JSON.parse(
224
+ JSON.stringify(t.recommendationConfigs.filters)
225
+ ), t.recommendationConfigs.filters.length || (t.recommendationConfigs.filters = [this.createDefaultFilter(1, 1)]), t.filterSelectionDrawerStatus = !0;
226
+ },
227
+ /**
228
+ * Closes the filter selection drawer for the current block.
229
+ * Called after successful apply — discards the snapshot.
199
230
  */
200
231
  closeFilterDrawer() {
201
- this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId] || (this.blockStates[this.currentRecommendationId].filterSelectionDrawerStatus = !1);
232
+ if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
233
+ return;
234
+ const t = this.blockStates[this.currentRecommendationId];
235
+ t.filterSnapshot = null, t.filterSelectionDrawerStatus = !1;
236
+ },
237
+ /**
238
+ * Cancels the filter selection drawer and reverts filters
239
+ * to the snapshot taken when the drawer was opened.
240
+ */
241
+ cancelFilterDrawer() {
242
+ if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
243
+ return;
244
+ const t = this.blockStates[this.currentRecommendationId];
245
+ t.filterSnapshot !== null && (t.recommendationConfigs.filters = t.filterSnapshot, t.filterSnapshot = null), t.filterSelectionDrawerStatus = !1;
202
246
  },
203
247
  // ====================================================================
204
248
  // Shared Data Fetching (fetched once, used by all blocks)
205
249
  // ====================================================================
206
250
  async fetchRecommendationCreateData() {
207
- if (this.activePredictiveAlgorithms.length)
208
- return;
209
- const {
210
- activePredictiveAlgorithms: e,
211
- languages: r,
212
- currencies: t
213
- } = await l.fetchRecommendationCreateData();
214
- this.activePredictiveAlgorithms = e, this.languages = r;
215
- const [n] = t, o = n.value.includes(".") ? n.value.split(".")[1] : n.value;
216
- if (this.currentRecommendationId !== null && this.blockStates[this.currentRecommendationId]) {
217
- const i = this.blockStates[this.currentRecommendationId];
218
- i.recommendationConfigs.currencySettings.name = n.text, i.recommendationConfigs.currencySettings.value = o, i.filterStatus = !!i.recommendationConfigs.filters.length;
251
+ if (!this.activePredictiveAlgorithms.length) {
252
+ if (u) {
253
+ await u;
254
+ return;
255
+ }
256
+ u = (async () => {
257
+ const {
258
+ activePredictiveAlgorithms: t,
259
+ languages: r,
260
+ currencies: e
261
+ } = await h.fetchRecommendationCreateData();
262
+ if (this.activePredictiveAlgorithms = t, this.languages = r, this.currentRecommendationId !== null && this.blockStates[this.currentRecommendationId]) {
263
+ const n = this.blockStates[this.currentRecommendationId];
264
+ n.filterStatus = !!n.recommendationConfigs.filters.length;
265
+ }
266
+ this.currencyList = e;
267
+ })();
268
+ try {
269
+ await u;
270
+ } finally {
271
+ u = null;
272
+ }
219
273
  }
220
- this.currencyList = t;
221
274
  },
222
275
  async fetchRecommendationFilters() {
223
- const e = await l.fetchRecommendationFilters();
224
- this.filterList = e;
276
+ if (!Object.keys(this.filterList).length) {
277
+ if (m) {
278
+ await m;
279
+ return;
280
+ }
281
+ m = (async () => {
282
+ const t = await h.fetchRecommendationFilters();
283
+ this.filterList = t;
284
+ })();
285
+ try {
286
+ await m;
287
+ } finally {
288
+ m = null;
289
+ }
290
+ }
225
291
  },
226
292
  // ====================================================================
227
293
  // Per-Block Filter Actions
228
294
  // ====================================================================
229
- addFilterGroup(e) {
230
- this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId] || this.blockStates[this.currentRecommendationId].recommendationConfigs.filters.push({
231
- type: "standardFilter",
232
- attribute: "",
233
- operatorReplace: "",
234
- operator: "",
235
- innerGroupOperator: "",
236
- outerGroupOperator: "",
237
- value: "",
238
- filterNumber: 1,
239
- isValid: !0,
240
- filterGroup: e
241
- });
295
+ addFilterGroup(t) {
296
+ this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId] || this.blockStates[this.currentRecommendationId].recommendationConfigs.filters.push(
297
+ this.createDefaultFilter(t, 1)
298
+ );
299
+ },
300
+ deleteFilterGroup(t) {
301
+ if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
302
+ return;
303
+ const r = this.blockStates[this.currentRecommendationId], e = r.recommendationConfigs.filters.filter((i) => i.filterGroup !== t), n = [...new Set(e.map((i) => i.filterGroup))].sort((i, o) => i - o), c = new Map(n.map((i, o) => [i, o + 1]));
304
+ r.recommendationConfigs.filters = e.map((i) => ({
305
+ ...i,
306
+ filterGroup: c.get(i.filterGroup) ?? i.filterGroup
307
+ }));
242
308
  },
243
- updateFilter(e) {
309
+ updateFilter(t) {
244
310
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
245
311
  return;
246
- const r = this.blockStates[this.currentRecommendationId], t = r.recommendationConfigs.filters.findIndex((n) => n.filterNumber === e.filterNumber && n.filterGroup === e.filterGroup);
247
- if (t !== -1) {
312
+ const r = this.blockStates[this.currentRecommendationId], e = r.recommendationConfigs.filters.findIndex((n) => n.filterNumber === t.filterNumber && n.filterGroup === t.filterGroup);
313
+ if (e !== -1) {
248
314
  const n = [...r.recommendationConfigs.filters];
249
- n[t] = e, e.value.length && e.operator && e.attribute && e.innerGroupOperator && e.outerGroupOperator ? n[t].isValid = !0 : n[t].isValid = !1, r.recommendationConfigs.filters = n;
315
+ n[e] = {
316
+ ...t,
317
+ isValid: D(t)
318
+ }, r.recommendationConfigs.filters = n;
250
319
  }
251
320
  },
252
- deleteFilter(e) {
321
+ deleteFilter(t) {
253
322
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
254
323
  return;
255
- const r = this.blockStates[this.currentRecommendationId], t = [...r.recommendationConfigs.filters].findIndex((n) => n.filterNumber === e.filterNumber && n.filterGroup === e.filterGroup);
256
- if (t !== -1) {
257
- const n = [...r.recommendationConfigs.filters];
258
- n.splice(t, 1), r.recommendationConfigs.filters = n;
324
+ const r = this.blockStates[this.currentRecommendationId], e = [...r.recommendationConfigs.filters].findIndex((n) => n.filterNumber === t.filterNumber && n.filterGroup === t.filterGroup);
325
+ if (e !== -1) {
326
+ let n = [...r.recommendationConfigs.filters];
327
+ if (n.splice(e, 1), n.some((i) => i.filterGroup === t.filterGroup)) {
328
+ let i = 1;
329
+ n = n.map((o) => o.filterGroup === t.filterGroup ? { ...o, filterNumber: i++ } : o);
330
+ } else {
331
+ const i = [...new Set(n.map((s) => s.filterGroup))].sort((s, l) => s - l), o = new Map(i.map((s, l) => [s, l + 1]));
332
+ n = n.map((s) => ({
333
+ ...s,
334
+ filterGroup: o.get(s.filterGroup) ?? s.filterGroup
335
+ }));
336
+ }
337
+ r.recommendationConfigs.filters = n;
259
338
  }
260
339
  },
261
- addFilter(e) {
340
+ addFilter(t) {
262
341
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
263
342
  return;
264
- const r = this.blockStates[this.currentRecommendationId], t = [...r.recommendationConfigs.filters], o = t.filter(
265
- (c) => c.filterGroup === e.filterGroup
266
- ).length + 1, i = t.findLastIndex((c) => c.filterGroup === e.filterGroup);
267
- i !== -1 ? t.splice(i + 1, 0, {
268
- ...e,
269
- filterNumber: o
270
- }) : t.push({
271
- ...e,
272
- filterNumber: o
273
- }), r.recommendationConfigs.filters = t;
343
+ const r = this.blockStates[this.currentRecommendationId], e = [...r.recommendationConfigs.filters], c = e.filter(
344
+ (o) => o.filterGroup === t.filterGroup
345
+ ).length + 1, i = e.findLastIndex((o) => o.filterGroup === t.filterGroup);
346
+ i !== -1 ? e.splice(i + 1, 0, {
347
+ ...t,
348
+ filterNumber: c
349
+ }) : e.push({
350
+ ...t,
351
+ filterNumber: c
352
+ }), r.recommendationConfigs.filters = e;
274
353
  },
275
354
  generateFilterQuery() {
276
- return d(this.recommendationConfigs.filters);
355
+ return I(this.recommendationConfigs.filters);
277
356
  },
278
357
  // ====================================================================
279
358
  // Per-Block Product Fetching
280
359
  // ====================================================================
281
360
  async fetchRecommendationProducts() {
282
- var m;
283
- if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
284
- return;
285
- const e = this.currentRecommendationId, r = this.blockStates[e], { recommendationConfigs: t } = r, n = t.filters.filter((a) => a.isValid), o = d(n), i = ((m = u.find((a) => a.key === t.strategy)) == null ? void 0 : m.path) || "", c = p(), s = {
286
- locale: t.language,
287
- currency: t.currencySettings.value,
288
- partnerName: c.partnerName,
289
- size: t.size,
361
+ if (!(this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])) {
362
+ if (d) {
363
+ await d;
364
+ return;
365
+ }
366
+ d = this._doFetchProducts();
367
+ try {
368
+ await d;
369
+ } finally {
370
+ d = null;
371
+ }
372
+ }
373
+ },
374
+ async _doFetchProducts() {
375
+ var p;
376
+ const t = this.currentRecommendationId, r = this.blockStates[t], { recommendationConfigs: e } = r, n = e.filters.filter((a) => a.isValid), c = I(n), i = ((p = g.find((a) => a.key === e.strategy)) == null ? void 0 : p.path) || "", o = C(), s = {
377
+ locale: e.language,
378
+ currency: e.currencySettings.value,
379
+ partnerName: o.partnerName,
380
+ size: e.size,
290
381
  details: !0,
291
- campaignId: c.variationId
382
+ campaignId: o.variationId
292
383
  };
293
- t.strategy === "manualMerchandising" ? s.productId = t.productIds.join(",") : t.strategy === "similarViewed" && (s.productId = "{itemId}"), o && (s.filter = o), t.shuffleProducts && (s.shuffle = !0);
294
- const h = await l.fetchRecommendationProducts(
295
- i,
296
- s
297
- );
298
- this.blockStates[e] && (this.blockStates[e].recommendationProducts = h);
384
+ e.strategy === "manualMerchandising" ? s.productId = e.productIds.join(",") : e.strategy === "similarViewed" && (s.productId = "{itemId}"), e.strategy === "userBased" && (s.userId = "{user_id}"), c && (s.filter = c), e.shuffleProducts && (s.shuffle = !0);
385
+ const l = parseInt(e.size) || 6;
386
+ let f;
387
+ try {
388
+ f = await h.fetchRecommendationProducts(i, s);
389
+ } catch {
390
+ f = [];
391
+ }
392
+ if (this.blockStates[t]) {
393
+ const a = f.length > 0 ? f : S(l);
394
+ this.blockStates[t].recommendationProducts = a.length < l ? [...a, ...S(l - a.length)] : a;
395
+ }
299
396
  }
300
397
  }
301
398
  });
302
399
  export {
303
- D as useRecommendationExtensionStore
400
+ E as useRecommendationExtensionStore
304
401
  };