@useinsider/guido 2.0.0-beta.18d5b06 → 2.0.0-beta.1acfbd1

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 (66) hide show
  1. package/dist/components/organisms/email-preview/amp/AmpErrorModal.vue.js +3 -3
  2. package/dist/components/organisms/email-preview/amp/AmpErrorModal.vue2.js +1 -1
  3. package/dist/components/organisms/email-preview/amp/AmpToggle.vue.js +7 -6
  4. package/dist/components/organisms/email-preview/desktop-preview/DesktopPreview.vue.js +9 -4
  5. package/dist/components/organisms/email-preview/mobile-preview/ContentView.vue.js +9 -9
  6. package/dist/components/organisms/header/EditorActions.vue.js +5 -4
  7. package/dist/components/organisms/header/LeftSlot.vue.js +7 -7
  8. package/dist/components/organisms/header/LeftSlot.vue2.js +3 -3
  9. package/dist/composables/useActionsApi.js +33 -30
  10. package/dist/config/migrator/index.js +9 -8
  11. package/dist/config/migrator/itemsBlockMigrator.js +334 -0
  12. package/dist/extensions/Blocks/Items/block.js +36 -40
  13. package/dist/extensions/Blocks/Items/controls/button/link.js +22 -29
  14. package/dist/extensions/Blocks/Items/controls/cardComposition.js +66 -46
  15. package/dist/extensions/Blocks/Items/controls/image/link.js +23 -30
  16. package/dist/extensions/Blocks/Items/controls/name/trimming.js +25 -25
  17. package/dist/extensions/Blocks/Items/controls/price/currencyLocation.js +19 -17
  18. package/dist/extensions/Blocks/Items/controls/price/currencySymbol.js +31 -29
  19. package/dist/extensions/Blocks/Items/controls/price/formattedPrice.js +44 -38
  20. package/dist/extensions/Blocks/Items/controls/price/hideDiscount.js +21 -19
  21. package/dist/extensions/Blocks/Items/controls/price/priceOrientation.js +29 -27
  22. package/dist/extensions/Blocks/Items/controls/price/singlePrice.js +93 -0
  23. package/dist/extensions/Blocks/Items/controls/settingsControl.js +146 -131
  24. package/dist/extensions/Blocks/Items/enums/controlEnums.js +2 -2
  25. package/dist/extensions/Blocks/Items/enums/productEnums.js +43 -45
  26. package/dist/extensions/Blocks/Items/enums/settingsEnums.js +4 -5
  27. package/dist/extensions/Blocks/Items/extension.js +11 -9
  28. package/dist/extensions/Blocks/Items/layouts/horizontal.html.js +58 -49
  29. package/dist/extensions/Blocks/Items/layouts/vertical.html.js +48 -59
  30. package/dist/extensions/Blocks/Items/settingsPanel.js +27 -26
  31. package/dist/extensions/Blocks/Items/store/items-block.js +11 -7
  32. package/dist/extensions/Blocks/Items/template.js +389 -141
  33. package/dist/extensions/Blocks/Items/utils/nodeConfigUtils.js +176 -0
  34. package/dist/extensions/Blocks/Recommendation/control.js +1 -1
  35. package/dist/extensions/Blocks/common-control.js +26 -27
  36. package/dist/extensions/Blocks/controlFactories.js +55 -45
  37. package/dist/guido.css +1 -1
  38. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +364 -285
  39. package/dist/package.json.js +1 -1
  40. package/dist/src/composables/useActionsApi.d.ts +1 -0
  41. package/dist/src/config/migrator/itemsBlockMigrator.d.ts +6 -0
  42. package/dist/src/extensions/Blocks/Items/controls/button/link.d.ts +0 -2
  43. package/dist/src/extensions/Blocks/Items/controls/cardComposition.d.ts +9 -0
  44. package/dist/src/extensions/Blocks/Items/controls/image/link.d.ts +0 -2
  45. package/dist/src/extensions/Blocks/Items/controls/price/priceOrientation.d.ts +1 -1
  46. package/dist/src/extensions/Blocks/Items/controls/price/singlePrice.d.ts +18 -0
  47. package/dist/src/extensions/Blocks/Items/controls/settingsControl.d.ts +0 -4
  48. package/dist/src/extensions/Blocks/Items/enums/controlEnums.d.ts +1 -0
  49. package/dist/src/extensions/Blocks/Items/enums/productEnums.d.ts +24 -26
  50. package/dist/src/extensions/Blocks/Items/enums/settingsEnums.d.ts +1 -2
  51. package/dist/src/extensions/Blocks/Items/store/items-block.d.ts +2 -0
  52. package/dist/src/extensions/Blocks/Items/template.d.ts +22 -1
  53. package/dist/src/extensions/Blocks/Items/utils/nodeConfigUtils.d.ts +76 -0
  54. package/dist/src/extensions/Blocks/common-control.d.ts +9 -10
  55. package/dist/static/styles/components/wide-panel.css.js +1 -1
  56. package/dist/utils/pairProductVariables.js +61 -58
  57. package/dist/utils/templatePreparation.js +17 -17
  58. package/package.json +3 -3
  59. package/dist/extensions/Blocks/Items/utils/configBlockUtils.js +0 -17
  60. package/dist/extensions/Blocks/Items/utils/syncAttributeFromConfigBlock.js +0 -28
  61. package/dist/extensions/Blocks/Items/utils/syncAttributesFromConfigBlock.js +0 -76
  62. package/dist/extensions/Blocks/Items/utils/updateAttributes.js +0 -46
  63. package/dist/src/extensions/Blocks/Items/utils/configBlockUtils.d.ts +0 -23
  64. package/dist/src/extensions/Blocks/Items/utils/syncAttributeFromConfigBlock.d.ts +0 -32
  65. package/dist/src/extensions/Blocks/Items/utils/syncAttributesFromConfigBlock.d.ts +0 -50
  66. package/dist/src/extensions/Blocks/Items/utils/updateAttributes.d.ts +0 -8
@@ -0,0 +1,334 @@
1
+ var L = Object.defineProperty;
2
+ var K = (o, t, r) => t in o ? L(o, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : o[t] = r;
3
+ var R = (o, t, r) => K(o, typeof t != "symbol" ? t + "" : t, r);
4
+ import { productPairs as B } from "../../extensions/Blocks/Items/enums/productEnums.js";
5
+ import { ItemInCartOptions as E, DefaultConfigValues as g, SETTINGS_ENUMS as _ } from "../../extensions/Blocks/Items/enums/settingsEnums.js";
6
+ import { getDefaultTemplate as U } from "../../extensions/Blocks/Items/template.js";
7
+ const w = {
8
+ img: {
9
+ pairsKey: "imageSrc",
10
+ defaultKey: "DEFAULT",
11
+ isArray: !0
12
+ },
13
+ name: {
14
+ pairsKey: "name",
15
+ defaultKey: "DEFAULT",
16
+ isArray: !0
17
+ },
18
+ url: {
19
+ pairsKey: "button",
20
+ defaultKey: "DEFAULT_HREF",
21
+ isArray: !1
22
+ },
23
+ formattedprice: {
24
+ pairsKey: "price",
25
+ defaultKey: "DEFAULT_PRICE_FORMATTED",
26
+ isArray: !1
27
+ },
28
+ productcurrency: {
29
+ pairsKey: "price",
30
+ defaultKey: "DEFAULT_CURRENCY",
31
+ isArray: !1
32
+ },
33
+ quantity: {
34
+ pairsKey: "quantity",
35
+ defaultKey: "DEFAULT",
36
+ isArray: !1
37
+ },
38
+ price: {
39
+ pairsKey: "price",
40
+ defaultKey: "DEFAULT_PRICE",
41
+ isArray: !1
42
+ },
43
+ originalprice: {
44
+ pairsKey: "originalPrice",
45
+ defaultKey: "DEFAULT_PRICE",
46
+ isArray: !1
47
+ },
48
+ originalformattedprice: {
49
+ pairsKey: "originalPrice",
50
+ defaultKey: "DEFAULT_PRICE_FORMATTED",
51
+ isArray: !1
52
+ },
53
+ single_price: {
54
+ pairsKey: "price",
55
+ defaultKey: "DEFAULT_SINGLE_PRICE",
56
+ isArray: !1
57
+ },
58
+ single_formattedprice: {
59
+ pairsKey: "price",
60
+ defaultKey: "DEFAULT_SINGLE_PRICE_FORMATTED",
61
+ isArray: !1
62
+ },
63
+ single_originalprice: {
64
+ pairsKey: "originalPrice",
65
+ defaultKey: "DEFAULT_SINGLE_PRICE",
66
+ isArray: !1
67
+ },
68
+ single_originalformattedprice: {
69
+ pairsKey: "originalPrice",
70
+ defaultKey: "DEFAULT_SINGLE_PRICE_FORMATTED",
71
+ isArray: !1
72
+ }
73
+ };
74
+ function F() {
75
+ return String(Date.now() + Math.floor(Math.random() * 1e3));
76
+ }
77
+ function q(o) {
78
+ return o ? {
79
+ CartItems: _.ITEMS_TYPE.CART_ITEMS,
80
+ BrowsedItems: _.ITEMS_TYPE.BROWSED_ITEMS,
81
+ PurchasedItems: _.ITEMS_TYPE.PURCHASED_ITEMS,
82
+ CART_ITEMS: _.ITEMS_TYPE.CART_ITEMS,
83
+ BROWSED_ITEMS: _.ITEMS_TYPE.BROWSED_ITEMS,
84
+ PURCHASED_ITEMS: _.ITEMS_TYPE.PURCHASED_ITEMS
85
+ }[o] || _.ITEMS_TYPE.CART_ITEMS : _.ITEMS_TYPE.CART_ITEMS;
86
+ }
87
+ function M(o) {
88
+ const t = (e, a) => e == null ? a : e === "1" || e === "true", r = (e, a) => e || a, c = o["data-type"] || o["data-source"], n = q(c);
89
+ let i = o["data-cart_items_select_control_value"] || g.cartItemsSelectControlValue;
90
+ if (i && !i.includes("{{") && /^\d+$/.test(i)) {
91
+ const e = parseInt(i) - 1, a = E[n];
92
+ a && a[e] && (i = a[e].value);
93
+ }
94
+ return {
95
+ initialized: !0,
96
+ blockInstanceId: r(o["data-block-instance-id"], F()),
97
+ source: n,
98
+ type: n,
99
+ itemsSelectValue: i,
100
+ orientation: o["data-card_orientation_control_value"] || _.ORIENTATION.VERTICAL,
101
+ nameTrimming: t(o["data-product_name_control_trim"], !0),
102
+ priceHideDiscount: t(o["data-product_price_control_nodup"], !0),
103
+ priceFormatted: t(o["data-product_price_control_formated"], !0),
104
+ priceSinglePrice: t(o["data-product_price_control_single_price"], !1),
105
+ priceCurrencySymbol: r(
106
+ o["data-product_price_currency_symbol"],
107
+ g.productPriceCurrencySymbolControlValue
108
+ ),
109
+ priceCurrencyLocation: r(
110
+ o["data-product_price_currency_location"],
111
+ g.productPriceCurrencyLocationControlValue
112
+ ),
113
+ priceOrientation: o["data-product_original_price_control_orientation"] || "horizontal",
114
+ quantityControlEnabled: t(o["data-product_quantity_control_enabled"], !0),
115
+ buttonLink: r(o["data-product_button_link"], g.productButtonLinkControlValue),
116
+ imageLink: r(o["data-product_image_link"], g.productImageLinkControlValue),
117
+ buttonLabel: r(o["data-product_button_control_label"], "Buy"),
118
+ buttonFullWidth: t(o["data-product_button_control_atw"], !0),
119
+ imageVisible: t(o["data-product_image_control_enabled"], !0),
120
+ nameVisible: t(o["data-product_name_control_enabled"], !0),
121
+ quantityVisible: t(o["data-product_quantity_control_enabled"], !0),
122
+ priceVisible: t(o["data-product_price_control_enabled"], !0),
123
+ originalPriceVisible: t(o["data-product_original_price_control_enabled"], !0),
124
+ buttonVisible: t(o["data-product_button_control_enabled"], !0)
125
+ };
126
+ }
127
+ const x = {
128
+ ins_apr: "CART_ITEMS",
129
+ browsed_item: "BROWSED_ITEMS",
130
+ purchased_item: "PURCHASED_ITEMS"
131
+ };
132
+ class N {
133
+ constructor() {
134
+ R(this, "parser");
135
+ this.parser = new DOMParser();
136
+ }
137
+ migrate(t) {
138
+ try {
139
+ let r = this.removeJinjaConditionals(t);
140
+ r = this.replaceTemplateVariables(r);
141
+ const c = this.parser.parseFromString(r, "text/html"), n = c.querySelectorAll(
142
+ "td.esd-cart-items-block, td.esd-browsed-items-block, td.esd-purchased-items-block"
143
+ );
144
+ return n.length === 0 ? (console.warn("ItemsBlockMigrator: No blocks found with items block selectors"), r) : (n.forEach((i) => {
145
+ const e = this.extractConfiguration(i), a = U({
146
+ orientation: e.orientation,
147
+ itemsType: e.itemsType,
148
+ itemId: e.itemId,
149
+ currencySymbol: e.currencySymbol,
150
+ currencyLocation: e.currencyLocation,
151
+ formattedPrice: e.formattedPrice,
152
+ configBlockAttributes: e.configBlockAttributes,
153
+ migrate: !0,
154
+ nameStyles: e.nameStyles,
155
+ buttonStyles: e.buttonStyles,
156
+ priceStyles: e.priceStyles,
157
+ originalPriceStyles: e.originalPriceStyles,
158
+ quantityStyles: e.quantityStyles,
159
+ nodeConfig: M(e.configBlockAttributes)
160
+ }), l = this.parser.parseFromString(
161
+ `<table><tbody><tr>${a}</tr></tbody></table>`,
162
+ "text/html"
163
+ ).querySelector("td");
164
+ if (l && i.parentNode) {
165
+ const f = M(e.configBlockAttributes);
166
+ l.setAttribute("esd-ext-config", JSON.stringify(f));
167
+ const u = l.querySelector("esd-config-block");
168
+ u && u.remove(), i.parentNode.replaceChild(l, i);
169
+ }
170
+ }), c.documentElement.outerHTML);
171
+ } catch (r) {
172
+ return console.error("ItemsBlockMigrator failed:", r), t;
173
+ }
174
+ }
175
+ /**
176
+ * Extracts configuration from legacy HTML block
177
+ * Parses data attributes and structure to determine:
178
+ * - orientation, itemsType, itemNumber, currency settings, esd-config-block attributes
179
+ * - UI styles from product elements (name, price, button, quantity, etc.)
180
+ */
181
+ extractConfiguration(t) {
182
+ var C, D, P;
183
+ const r = ((C = t.querySelector("[data-type]")) == null ? void 0 : C.getAttribute("data-type")) || "CART_ITEMS", c = ((D = t.querySelector("[data-number]")) == null ? void 0 : D.getAttribute("data-number")) || "1", n = parseInt(c) - 1, i = E[r], e = ((P = i == null ? void 0 : i[n]) == null ? void 0 : P.value) || i[0].value, a = t.querySelector('[product-attr="price"]'), d = (a == null ? void 0 : a.getAttribute("data-currency_symbol")) || "USD", f = ((a == null ? void 0 : a.getAttribute("data-curency")) || "before") === "after" ? "1" : "0", u = (a == null ? void 0 : a.getAttribute("data-formated")) !== "false", s = this.extractConfigBlockAttributes(t, r), b = s["data-card_orientation_control_value"];
184
+ let S;
185
+ b ? S = b === "horizontal" ? "horizontal" : "vertical" : S = t.querySelector('[colspan="2"]') !== null ? "vertical" : "horizontal";
186
+ const p = t.querySelector('a[product-attr="name"]'), T = (p == null ? void 0 : p.getAttribute("style")) || void 0, y = t.querySelector('a[product-attr="button"]'), m = (y == null ? void 0 : y.getAttribute("style")) || void 0, h = (a == null ? void 0 : a.getAttribute("style")) || void 0, A = t.querySelector("p.original-price"), k = (A == null ? void 0 : A.getAttribute("style")) || void 0, I = t.querySelector('[product-attr="quantity"]'), v = (I == null ? void 0 : I.getAttribute("style")) || void 0;
187
+ return {
188
+ orientation: S,
189
+ itemsType: r,
190
+ itemId: e,
191
+ currencySymbol: d,
192
+ currencyLocation: f,
193
+ formattedPrice: u,
194
+ configBlockAttributes: s,
195
+ nameStyles: T,
196
+ buttonStyles: m,
197
+ priceStyles: h,
198
+ originalPriceStyles: k,
199
+ quantityStyles: v
200
+ };
201
+ }
202
+ /**
203
+ * Extracts all data-* attributes from the esd-config-block element
204
+ * Returns a key-value mapping of all configuration attributes
205
+ * @param block - The block element containing the esd-config-block
206
+ * @param itemsType - The type of items (CART_ITEMS, BROWSED_ITEMS, PURCHASED_ITEMS)
207
+ */
208
+ extractConfigBlockAttributes(t, r) {
209
+ const c = t.querySelector("esd-config-block"), n = {};
210
+ if (!c)
211
+ return this.getDefaultConfigBlockAttributes();
212
+ if (Array.from(c.attributes).forEach((e) => {
213
+ e.name.startsWith("data-") && (n[e.name] = e.value);
214
+ }), n["data-cart_items_select_control_value"]) {
215
+ const e = n["data-cart_items_select_control_value"];
216
+ if (/^\d+$/.test(e)) {
217
+ const a = parseInt(e) - 1, d = E[r];
218
+ d && d[a] && (n["data-cart_items_select_control_value"] = d[a].value);
219
+ }
220
+ }
221
+ if (n["data-product_price_control_curency"]) {
222
+ const e = n["data-product_price_control_curency"];
223
+ let a = e;
224
+ e === "before" ? a = "0" : e === "after" && (a = "1"), n["data-product_price_control_curency"] = a, n["data-product_price_currency_location"] = a;
225
+ }
226
+ (!n["data-product_price_currency_symbol"] || n["data-product_price_currency_symbol"].trim() === "") && (n["data-product_price_currency_symbol"] = "USD");
227
+ const i = { ...this.getDefaultConfigBlockAttributes(), ...n };
228
+ return i["data-type"] = r, i["data-source"] = r, i;
229
+ }
230
+ /**
231
+ * Returns default esd-config-block attributes based on the old template structure
232
+ * These serve as fallbacks when attributes are missing
233
+ */
234
+ getDefaultConfigBlockAttributes() {
235
+ return {
236
+ // Core settings
237
+ "data-type": "CART_ITEMS",
238
+ "data-card_orientation_control_value": "vertical",
239
+ // Image settings
240
+ "data-product_image_control_image-width": "70",
241
+ "data-product_image_control_image-height": "70",
242
+ "data-product_image_control_align_button": "true",
243
+ "data-product_image_control_padding_mobile": "true",
244
+ "data-product_image_link": "{{Abandoned Cart Item (1) Image}}",
245
+ "data-product_image_control_enabled": "true",
246
+ // Name settings
247
+ "data-product_name_control_enabled": "true",
248
+ "data-product_name_control_font_font_size": "20",
249
+ "data-product_name_control_trim": "1",
250
+ // Quantity settings
251
+ "data-product_quantity_control_enabled": "true",
252
+ // Price settings
253
+ "data-product_price_control_font_font_size": "20",
254
+ "data-product_price_control_color": "#060606",
255
+ "data-product_price_control_curency": "0",
256
+ "data-product_price_currency_location": "0",
257
+ "data-product_price_currency_symbol": "USD",
258
+ "data-product_price_control_formated": "1",
259
+ "data-product_price_control_nodup": "1",
260
+ "data-product_price_control_single_price": "false",
261
+ "data-product_price_control_enabled": "true",
262
+ // Original price settings
263
+ "data-product_original_price_control_font_font_size": "19",
264
+ "data-product_original_price_control_align_align_desktop": "center",
265
+ "data-product_original_price_control_orientation": "horizontal",
266
+ "data-product_original_price_control_enabled": "true",
267
+ // Button settings
268
+ "data-product_button_control_enabled": "true",
269
+ "data-product_button_control_label": "Buy",
270
+ "data-product_button_control_font_font_size": "17",
271
+ "data-product_button_control_color": "#ffffff",
272
+ "data-product_button_control_background": "#010101",
273
+ "data-product_button_control_atw": "true",
274
+ "data-product_button_link": "{{Abandoned Cart Item (1) Url}}"
275
+ };
276
+ }
277
+ /**
278
+ * Removes Jinja2 conditional statements from HTML
279
+ * Handles all items block types:
280
+ * - Cart Items: ins_apr_total_product_kind, ins_apr_price_N, ins_apr_originalprice_N
281
+ * - Browsed Items: browsed_item_total_product_kind, browsed_item_price_N, browsed_item_originalprice_N
282
+ * - Purchased Items: purchased_item_total_product_kind, purchased_item_price_N, purchased_item_originalprice_N
283
+ */
284
+ removeJinjaConditionals(t) {
285
+ let r = t.replace(
286
+ /\{%\s*if\s+(ins_apr|browsed_item|purchased_item)_total_product_kind\s*(&gt;|>)\s*\d+\s*%\}/g,
287
+ ""
288
+ );
289
+ return r = r.replace(
290
+ /\{%\s*if\s+(ins_apr|browsed_item|purchased_item)_price_\d+\s*(!&#61;|!=)\s*\1_originalprice_\d+\s*%\}/g,
291
+ ""
292
+ ), r = r.replace(/\{%\s*endif\s*%\}/g, ""), r = r.replace(/\n\s*\n\s*\n/g, `
293
+
294
+ `), r;
295
+ }
296
+ /**
297
+ * Replaces template variables with default values from productPairs
298
+ * Supports all block types by detecting prefix and using appropriate type:
299
+ *
300
+ * Examples:
301
+ * - {{ins_apr_img_1}} → https://s3.../img_1.jpeg (CART_ITEMS)
302
+ * - {{browsed_item_name_2}} → 'Set of Sprite Yoga Straps' (BROWSED_ITEMS)
303
+ * - {{purchased_item_formattedprice_5}} → '1,490.49' (PURCHASED_ITEMS)
304
+ */
305
+ replaceTemplateVariables(t) {
306
+ const { PAIRS_FOR_EXTENSION: r } = B;
307
+ return t.replace(/{{([^}]+)}}/g, (c, n) => {
308
+ const i = n.match(/^(ins_apr|browsed_item|purchased_item)_([a-z_]+)_(\d+)$/);
309
+ if (!i)
310
+ return c;
311
+ const [, e, a, d] = i, l = x[e];
312
+ if (!l)
313
+ return console.warn(`Unknown variable prefix: ${e}`), c;
314
+ const f = w[a];
315
+ if (!f)
316
+ return console.warn(`Unknown variable suffix mapping for: ${a}`), c;
317
+ const { pairsKey: u, defaultKey: s, isArray: b } = f, p = r[u][l];
318
+ if (!p)
319
+ return console.warn(`No data found for: ${u}.${l}`), c;
320
+ if (b) {
321
+ const y = parseInt(d) - 1, m = p[s];
322
+ return Array.isArray(m) && m[y] ? m[y] : (console.warn(`Array value not found: ${u}.${l}.${s}[${y}]`), c);
323
+ }
324
+ const T = p[s];
325
+ return T !== void 0 ? String(T) : (console.warn(`Default value not found: ${u}.${l}.${s}`), c);
326
+ });
327
+ }
328
+ }
329
+ function Y(o) {
330
+ return new N().migrate(o);
331
+ }
332
+ export {
333
+ Y as migrateItemsBlock
334
+ };
@@ -1,20 +1,19 @@
1
- import { useOnboardingStore as y } from "../../../stores/onboarding.js";
2
- import { Block as R, BlockCompositionType as L, ModificationDescription as a } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
3
- import { configAttributes as t } from "./enums/productEnums.js";
4
- import { DefaultConfigValues as e, SETTINGS_ENUMS as l } from "./enums/settingsEnums.js";
5
- import { useItemsBlockStore as S } from "./store/items-block.js";
6
- import { getDefaultTemplate as V } from "./template.js";
7
- import { syncCurrencySymbolFromAttributes as B, syncCurrencyLocationFromAttributes as U, syncFormattedPriceFromAttributes as k } from "./utils/syncAttributesFromConfigBlock.js";
8
- const M = "items-block";
9
- class x extends R {
1
+ import { useOnboardingStore as m } from "../../../stores/onboarding.js";
2
+ import { Block as u, BlockCompositionType as d, ModificationDescription as i } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
3
+ import { SETTINGS_ENUMS as c, DefaultConfigValues as o } from "./enums/settingsEnums.js";
4
+ import { useItemsBlockStore as p } from "./store/items-block.js";
5
+ import { getDefaultTemplate as f } from "./template.js";
6
+ import { getItemsBlockContainer as g, getItemsBlockConfig as a, getDefaultItemsBlockConfig as C } from "./utils/nodeConfigUtils.js";
7
+ const y = "items-block";
8
+ class B extends u {
10
9
  getId() {
11
- return M;
10
+ return y;
12
11
  }
13
12
  getIcon() {
14
13
  return "items-icon";
15
14
  }
16
15
  getBlockCompositionType() {
17
- return L.CONTAINER;
16
+ return d.CONTAINER;
18
17
  }
19
18
  getName() {
20
19
  return this.api.translate("Items");
@@ -23,45 +22,42 @@ class x extends R {
23
22
  return this.api.translate("Items lets you display personalized products based on user behavior.");
24
23
  }
25
24
  getTemplate() {
26
- return V({
27
- orientation: l.ORIENTATION.HORIZONTAL,
28
- itemsType: l.ITEMS_TYPE.CART_ITEMS,
25
+ return f({
26
+ orientation: c.ORIENTATION.VERTICAL,
27
+ itemsType: c.ITEMS_TYPE.CART_ITEMS,
29
28
  itemId: "{{Abandoned Cart Item (1) Url}}",
30
- currencySymbol: e.productPriceCurrencySymbolControlValue,
31
- currencyLocation: e.productPriceCurrencyLocationControlValue,
32
- formattedPrice: e.productPriceFormattedControlValue === "1"
29
+ currencySymbol: o.productPriceCurrencySymbolControlValue,
30
+ currencyLocation: o.productPriceCurrencyLocationControlValue,
31
+ formattedPrice: o.productPriceFormattedControlValue === "1"
33
32
  });
34
33
  }
35
34
  allowInnerBlocksDND() {
36
35
  return !1;
37
36
  }
38
- onCreated(r) {
39
- const n = r.querySelector("esd-config-block");
40
- if (!n)
37
+ onCreated(n) {
38
+ const e = g(n);
39
+ if (!e)
41
40
  return;
42
- const o = n, s = o.getAttribute("data-initialized") || "0", u = o.getAttribute(t.BLOCK_INSTANCE_ID), c = () => String(Date.now() + Math.floor(Math.random() * 1e3));
43
- if (Number(s)) {
44
- if (!u) {
45
- const i = c();
46
- this.api.getDocumentModifier().modifyHtml(o).setAttribute(t.BLOCK_INSTANCE_ID, i).apply(new a("Assign block instance ID to legacy block"));
47
- }
48
- } else {
49
- const i = e.itemsType, I = e.cartItemsSelectControlValue, d = e.cardOrientationControlValue, m = e.productNameTrimmingControlValue, C = e.productPriceHideDiscountControlValue, b = e.productPriceFormattedControlValue, T = e.productPriceCurrencySymbolControlValue, A = e.productPriceCurrencyLocationControlValue, E = e.productButtonLinkControlValue, O = e.productImageLinkControlValue, _ = e.productImageVisible, p = e.productNameVisible, N = e.productQuantityVisible, f = e.productPriceVisible, g = e.productOriginalPriceVisible, D = e.productButtonVisible, P = c();
50
- this.api.getDocumentModifier().modifyHtml(o).setAttribute("data-source", i).setAttribute(t.TYPE, i).setAttribute(t.ITEMS_INDEX_SELECT_CONTROL_VALUE, I).setAttribute(t.ORIENTATION, d).setAttribute(t.PRODUCT_NAME_TRIMMING, m).setAttribute(t.PRODUCT_PRICE_HIDE_DISCOUNT, C).setAttribute(t.PRODUCT_PRICE_FORMATTED, b).setAttribute(t.PRODUCT_PRICE_CURRENCY_SYMBOL, T).setAttribute(t.PRODUCT_PRICE_CURRENCY_LOCATION, A).setAttribute(t.PRODUCT_BUTTON_LINK, E).setAttribute(t.PRODUCT_IMAGE_LINK, O).setAttribute(t.BLOCK_INSTANCE_ID, P).setAttribute("data-initialized", "1").setAttribute(t.NAME_CONTROL_ENABLED, e.productNameControlEnabled).setAttribute(
51
- t.QUANTITY_CONTROL_ENABLED,
52
- e.productQuantityControlEnabled
53
- ).setAttribute(t.PRICE_CONTROL_OPENED, e.productPriceControlOpened).setAttribute(t.PRODUCT_IMAGE_VISIBLE, _).setAttribute(t.PRODUCT_NAME_VISIBLE, p).setAttribute(t.PRODUCT_QUANTITY_VISIBLE, N).setAttribute(t.PRODUCT_PRICE_VISIBLE, f).setAttribute(t.PRODUCT_ORIGINAL_PRICE_VISIBLE, g).setAttribute(t.PRODUCT_BUTTON_VISIBLE, D).apply(new a("Initialize config block attributes with defaults")), y().startOnboarding("itemsOnboarding");
41
+ const t = e.getNodeConfig(), l = t && Object.keys(t).length > 0, r = a(n);
42
+ if (r != null && r.initialized)
43
+ l ? r.blockInstanceId || this.api.getDocumentModifier().modifyHtml(e).setNodeConfig({ ...r, blockInstanceId: String(Date.now()) }).apply(new i("Assign block instance ID to block")) : this.api.getDocumentModifier().modifyHtml(e).setNodeConfig(r).apply(new i("Migrate legacy config to nodeConfig"));
44
+ else {
45
+ const s = C();
46
+ this.api.getDocumentModifier().modifyHtml(e).setNodeConfig(s).apply(new i("Initialize Items block with default configuration")), m().startOnboarding("itemsOnboarding");
54
47
  }
55
48
  }
56
- onSelect(r) {
57
- const n = r.querySelector("esd-config-block"), o = S();
58
- if (!n)
59
- return;
60
- const s = n, u = s.getAttribute(t.TYPE) || e.itemsType, c = s.getAttribute(t.ITEMS_INDEX_SELECT_CONTROL_VALUE) || e.cartItemsSelectControlValue, i = s.getAttribute(t.ORIENTATION) || e.cardOrientationControlValue;
61
- o.setItemsType(u), o.setItemIds(c), o.setOrientation(i), B(r), U(r), k(r);
49
+ onSelect(n) {
50
+ const e = p(), t = a(n);
51
+ t && (e.setItemsType(t.type || o.itemsType), e.setItemIds(t.itemsSelectValue || o.cartItemsSelectControlValue), e.setOrientation(t.orientation || o.cardOrientationControlValue), e.setCurrencySymbol(
52
+ t.priceCurrencySymbol || o.productPriceCurrencySymbolControlValue
53
+ ), e.setCurrencyLocation(
54
+ t.priceCurrencyLocation || o.productPriceCurrencyLocationControlValue
55
+ ), e.setFormattedPrice(
56
+ t.priceFormatted ?? o.productPriceFormattedControlValue === "1"
57
+ ));
62
58
  }
63
59
  }
64
60
  export {
65
- M as BLOCK_ID,
66
- x as ItemsBlock
61
+ y as BLOCK_ID,
62
+ B as ItemsBlock
67
63
  };
@@ -1,59 +1,52 @@
1
- var r = Object.defineProperty;
2
- var a = (o, e, t) => e in o ? r(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
- var s = (o, e, t) => a(o, typeof e != "symbol" ? e + "" : e, t);
1
+ var a = Object.defineProperty;
2
+ var l = (e, t, n) => t in e ? a(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var i = (e, t, n) => l(e, typeof t != "symbol" ? t + "" : t, n);
4
4
  import { CommonControl as u } from "../../../common-control.js";
5
5
  import { ItemsBlockControlId as d } from "../../enums/controlEnums.js";
6
- import { useItemsBlockStore as l } from "../../store/items-block.js";
7
- import { syncButtonLinkFromAttributes as h } from "../../utils/syncAttributesFromConfigBlock.js";
8
- import { updateConfigBlockAttributes as m } from "../../utils/updateAttributes.js";
9
- const i = d.BUTTON_LINK, n = {
6
+ import { useItemsBlockStore as m } from "../../store/items-block.js";
7
+ import { getItemsBlockConfig as L } from "../../utils/nodeConfigUtils.js";
8
+ const r = d.BUTTON_LINK, s = {
10
9
  LINK: "link"
11
10
  };
12
- class C extends u {
11
+ class N extends u {
13
12
  constructor() {
14
13
  super(...arguments);
15
- s(this, "store", l());
14
+ i(this, "store", m());
16
15
  }
17
16
  getId() {
18
- return i;
17
+ return r;
19
18
  }
20
19
  getTemplate() {
21
20
  return `
22
- <div class="${i}">
21
+ <div class="container ${r}">
23
22
  ${this._getLink()}
24
23
  </div>
25
24
  `;
26
25
  }
27
26
  onRender() {
28
27
  this.api.updateValues({
29
- [n.LINK]: this.store.buttonLink
30
- }), this._listenToFormUpdates();
28
+ [s.LINK]: this.store.buttonLink
29
+ });
31
30
  }
32
- onTemplateNodeUpdated(t) {
33
- super.onTemplateNodeUpdated(t), this.handleBlockInstanceChange(
34
- () => h(this.currentNode),
31
+ onTemplateNodeUpdated(n) {
32
+ super.onTemplateNodeUpdated(n), this.handleBlockInstanceChange(
33
+ () => {
34
+ const o = L(this.currentNode);
35
+ o != null && o.buttonLink && this.store.setButtonLink(o.buttonLink);
36
+ },
35
37
  () => {
36
38
  this.api.updateValues({
37
- [n.LINK]: this.store.buttonLink
39
+ [s.LINK]: this.store.buttonLink
38
40
  });
39
41
  }
40
42
  );
41
43
  }
42
- _listenToFormUpdates() {
43
- this.api.onValueChanged(
44
- n.LINK,
45
- (t) => this._onLinkChange(t)
46
- );
47
- }
48
- _onLinkChange(t) {
49
- console.debug("Button link changed to: ", t), this.store.setButtonLink(t), m(this.currentNode, this.api);
50
- }
51
44
  _getLink() {
52
45
  return `
53
46
  ${this._GuOneColumn([
54
47
  this._GuLabel({ text: "Link" }),
55
48
  this._GuTextInput({
56
- name: n.LINK,
49
+ name: s.LINK,
57
50
  placeholder: "Enter Link",
58
51
  className: "es-100",
59
52
  disabled: !0
@@ -63,6 +56,6 @@ class C extends u {
63
56
  }
64
57
  }
65
58
  export {
66
- C as ButtonLinkControl,
67
- i as CONTROL_BLOCK_ID
59
+ N as ButtonLinkControl,
60
+ r as CONTROL_BLOCK_ID
68
61
  };