@useinsider/guido 2.0.0-beta.a3f32aa → 2.0.0-beta.b46bbf6

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 (40) hide show
  1. package/dist/@types/config/schemas.js +33 -45
  2. package/dist/components/organisms/email-preview/desktop-preview/DesktopPreview.vue.js +2 -2
  3. package/dist/components/organisms/email-preview/mobile-preview/ContentView.vue.js +5 -5
  4. package/dist/components/organisms/header/RightSlot.vue2.js +10 -10
  5. package/dist/composables/useConfig.js +27 -29
  6. package/dist/composables/useSave.js +11 -13
  7. package/dist/composables/useStripo.js +54 -55
  8. package/dist/config/migrator/index.js +9 -8
  9. package/dist/config/migrator/itemsBlockMigrator.js +283 -0
  10. package/dist/extensions/Blocks/Items/block.js +39 -40
  11. package/dist/extensions/Blocks/Items/controls/cardComposition.js +46 -49
  12. package/dist/extensions/Blocks/Items/controls/price/priceOrientation.js +28 -26
  13. package/dist/extensions/Blocks/Items/controls/settingsControl.js +132 -127
  14. package/dist/extensions/Blocks/Items/enums/settingsEnums.js +2 -2
  15. package/dist/extensions/Blocks/Items/layouts/horizontal.html.js +58 -48
  16. package/dist/extensions/Blocks/Items/layouts/vertical.html.js +48 -58
  17. package/dist/extensions/Blocks/Items/store/items-block.js +2 -2
  18. package/dist/extensions/Blocks/Items/template.js +296 -123
  19. package/dist/extensions/Blocks/Items/utils/nodeConfigUtils.js +172 -0
  20. package/dist/extensions/Blocks/Items/utils/syncAttributesFromConfigBlock.js +11 -20
  21. package/dist/extensions/Blocks/Recommendation/control.js +1 -1
  22. package/dist/extensions/Blocks/Unsubscribe/extension.js +9 -9
  23. package/dist/extensions/Blocks/common-control.js +64 -53
  24. package/dist/guido.css +1 -1
  25. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +366 -287
  26. package/dist/src/@types/config/index.d.ts +2 -2
  27. package/dist/src/@types/config/schemas.d.ts +4 -26
  28. package/dist/src/@types/config/types.d.ts +1 -7
  29. package/dist/src/composables/useConfig.d.ts +2 -6
  30. package/dist/src/config/migrator/itemsBlockMigrator.d.ts +6 -0
  31. package/dist/src/extensions/Blocks/Items/controls/price/priceOrientation.d.ts +1 -1
  32. package/dist/src/extensions/Blocks/Items/controls/settingsControl.d.ts +0 -4
  33. package/dist/src/extensions/Blocks/Items/template.d.ts +20 -1
  34. package/dist/src/extensions/Blocks/Items/utils/nodeConfigUtils.d.ts +71 -0
  35. package/dist/src/extensions/Blocks/common-control.d.ts +13 -8
  36. package/dist/src/stores/config.d.ts +18 -145
  37. package/dist/static/styles/components/narrow-panel.css.js +0 -10
  38. package/dist/stores/config.js +0 -7
  39. package/package.json +3 -3
  40. package/dist/package.json.js +0 -7
@@ -0,0 +1,283 @@
1
+ var B = Object.defineProperty;
2
+ var q = (o, t, r) => t in o ? B(o, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : o[t] = r;
3
+ var A = (o, t, r) => q(o, typeof t != "symbol" ? t + "" : t, r);
4
+ import { productPairs as L } from "../../extensions/Blocks/Items/enums/productEnums.js";
5
+ import { ItemInCartOptions as I, DefaultConfigValues as m, SETTINGS_ENUMS as l } from "../../extensions/Blocks/Items/enums/settingsEnums.js";
6
+ import { getDefaultTemplate as K } from "../../extensions/Blocks/Items/template.js";
7
+ const V = {
8
+ ins_apr_img: {
9
+ pairsKey: "imageSrc",
10
+ defaultKey: "DEFAULT",
11
+ isArray: !0
12
+ },
13
+ ins_apr_name: {
14
+ pairsKey: "name",
15
+ defaultKey: "DEFAULT",
16
+ isArray: !0
17
+ },
18
+ ins_apr_url: {
19
+ pairsKey: "button",
20
+ defaultKey: "DEFAULT_HREF",
21
+ isArray: !1
22
+ },
23
+ ins_apr_formattedprice: {
24
+ pairsKey: "price",
25
+ defaultKey: "DEFAULT_PRICE_FORMATTED",
26
+ isArray: !1
27
+ },
28
+ ins_apr_productcurrency: {
29
+ pairsKey: "price",
30
+ defaultKey: "DEFAULT_CURRENCY",
31
+ isArray: !1
32
+ },
33
+ ins_apr_quantity: {
34
+ pairsKey: "quantity",
35
+ defaultKey: "DEFAULT",
36
+ isArray: !1
37
+ },
38
+ ins_apr_price: {
39
+ pairsKey: "price",
40
+ defaultKey: "DEFAULT_PRICE",
41
+ isArray: !1
42
+ },
43
+ ins_apr_originalprice: {
44
+ pairsKey: "originalPrice",
45
+ defaultKey: "DEFAULT_PRICE",
46
+ isArray: !1
47
+ },
48
+ ins_apr_originalformattedprice: {
49
+ pairsKey: "originalPrice",
50
+ defaultKey: "DEFAULT_PRICE_FORMATTED",
51
+ isArray: !1
52
+ }
53
+ };
54
+ function U() {
55
+ return String(Date.now() + Math.floor(Math.random() * 1e3));
56
+ }
57
+ function F(o) {
58
+ return o ? {
59
+ CartItems: l.ITEMS_TYPE.CART_ITEMS,
60
+ BrowsedItems: l.ITEMS_TYPE.BROWSED_ITEMS,
61
+ PurchasedItems: l.ITEMS_TYPE.PURCHASED_ITEMS,
62
+ CART_ITEMS: l.ITEMS_TYPE.CART_ITEMS,
63
+ BROWSED_ITEMS: l.ITEMS_TYPE.BROWSED_ITEMS,
64
+ PURCHASED_ITEMS: l.ITEMS_TYPE.PURCHASED_ITEMS
65
+ }[o] || l.ITEMS_TYPE.CART_ITEMS : l.ITEMS_TYPE.CART_ITEMS;
66
+ }
67
+ function D(o) {
68
+ const t = (e, a) => e == null ? a : e === "1" || e === "true", r = (e, a) => e || a, c = o["data-type"] || o["data-source"], n = F(c);
69
+ let i = o["data-cart_items_select_control_value"] || m.cartItemsSelectControlValue;
70
+ if (i && !i.includes("{{") && /^\d+$/.test(i)) {
71
+ const e = parseInt(i) - 1, a = I[n];
72
+ a && a[e] && (i = a[e].value);
73
+ }
74
+ return {
75
+ initialized: !0,
76
+ blockInstanceId: r(o["data-block-instance-id"], U()),
77
+ source: n,
78
+ type: n,
79
+ itemsSelectValue: i,
80
+ orientation: o["data-card_orientation_control_value"] || l.ORIENTATION.VERTICAL,
81
+ nameTrimming: t(o["data-product_name_trimming"], !0),
82
+ nameControlEnabled: t(o["data-product_name_control_enabled"], !0),
83
+ priceHideDiscount: t(o["data-product_price_hide_discount"], !1),
84
+ priceFormatted: t(o["data-product_price_formatted"], !0),
85
+ priceCurrencySymbol: r(
86
+ o["data-product_price_currency_symbol"],
87
+ m.productPriceCurrencySymbolControlValue
88
+ ),
89
+ priceCurrencyLocation: r(
90
+ o["data-product_price_currency_location"],
91
+ m.productPriceCurrencyLocationControlValue
92
+ ),
93
+ priceControlOpened: t(o["data-product_price_control_opened"], !0),
94
+ priceOrientation: o["data-product_original_price_control_orientation"] || "horizontal",
95
+ quantityControlEnabled: t(o["data-product_quantity_control_enabled"], !0),
96
+ buttonLink: r(o["data-product_button_link"], m.productButtonLinkControlValue),
97
+ imageLink: r(o["data-product_image_link"], m.productImageLinkControlValue),
98
+ buttonLabel: r(o["data-product_button_control_label"], "Buy"),
99
+ imageVisible: t(o["data-product_image_visible"], !0),
100
+ nameVisible: t(o["data-product_name_visible"], !0),
101
+ quantityVisible: t(o["data-product_quantity_visible"], !0),
102
+ priceVisible: t(o["data-product_price_visible"], !0),
103
+ originalPriceVisible: t(o["data-product_original_price_control_enabled"], !0),
104
+ buttonVisible: t(o["data-product_button_visible"], !0)
105
+ };
106
+ }
107
+ class w {
108
+ constructor() {
109
+ A(this, "parser");
110
+ A(this, "DATA_TYPE", "CART_ITEMS");
111
+ this.parser = new DOMParser();
112
+ }
113
+ migrate(t) {
114
+ try {
115
+ let r = this.removeJinjaConditionals(t);
116
+ r = this.replaceTemplateVariables(r);
117
+ const c = this.parser.parseFromString(r, "text/html"), n = c.querySelectorAll("td.esd-cart-items-block");
118
+ return n.length === 0 ? (console.warn('ItemsBlockMigrator: No blocks found with selector "td.esd-cart-items-block"'), r) : (n.forEach((i) => {
119
+ const e = this.extractConfiguration(i), a = K({
120
+ orientation: e.orientation,
121
+ itemsType: e.itemsType,
122
+ itemId: e.itemId,
123
+ currencySymbol: e.currencySymbol,
124
+ currencyLocation: e.currencyLocation,
125
+ formattedPrice: e.formattedPrice,
126
+ configBlockAttributes: e.configBlockAttributes,
127
+ migrate: !0,
128
+ nameStyles: e.nameStyles,
129
+ buttonStyles: e.buttonStyles,
130
+ priceStyles: e.priceStyles,
131
+ originalPriceStyles: e.originalPriceStyles,
132
+ quantityStyles: e.quantityStyles,
133
+ nodeConfig: D(e.configBlockAttributes)
134
+ }), u = this.parser.parseFromString(
135
+ `<table><tbody><tr>${a}</tr></tbody></table>`,
136
+ "text/html"
137
+ ).querySelector("td");
138
+ if (u && i.parentNode) {
139
+ const s = D(e.configBlockAttributes);
140
+ u.setAttribute("esd-ext-config", JSON.stringify(s));
141
+ const p = u.querySelector("esd-config-block");
142
+ p && p.remove(), i.parentNode.replaceChild(u, i);
143
+ }
144
+ }), c.documentElement.outerHTML);
145
+ } catch (r) {
146
+ return console.error("ItemsBlockMigrator failed:", r), t;
147
+ }
148
+ }
149
+ /**
150
+ * Extracts configuration from legacy HTML block
151
+ * Parses data attributes and structure to determine:
152
+ * - orientation, itemsType, itemNumber, currency settings, esd-config-block attributes
153
+ * - UI styles from product elements (name, price, button, quantity, etc.)
154
+ */
155
+ extractConfiguration(t) {
156
+ var E, C, P;
157
+ const r = ((E = t.querySelector("[data-type]")) == null ? void 0 : E.getAttribute("data-type")) || "CART_ITEMS", c = ((C = t.querySelector("[data-number]")) == null ? void 0 : C.getAttribute("data-number")) || "1", n = parseInt(c) - 1, i = I[r], e = ((P = i == null ? void 0 : i[n]) == null ? void 0 : P.value) || i[0].value, a = t.querySelector('[product-attr="price"]'), _ = (a == null ? void 0 : a.getAttribute("data-currency_symbol")) || void 0, s = ((a == null ? void 0 : a.getAttribute("data-curency")) || "before") === "after" ? "1" : "0", p = (a == null ? void 0 : a.getAttribute("data-formated")) !== "false", y = this.extractConfigBlockAttributes(t, r), f = y["data-product_original_price_control_orientation"] === "vertical" ? "vertical" : "horizontal", d = t.querySelector('a[product-attr="name"]'), v = (d == null ? void 0 : d.getAttribute("style")) || void 0, b = t.querySelector('a[product-attr="button"]'), M = (b == null ? void 0 : b.getAttribute("style")) || void 0, h = (a == null ? void 0 : a.getAttribute("style")) || void 0, S = t.querySelector('[product-attr="originalPrice"]'), R = (S == null ? void 0 : S.getAttribute("style")) || void 0, T = t.querySelector('[product-attr="quantity"]'), k = (T == null ? void 0 : T.getAttribute("style")) || void 0;
158
+ return {
159
+ orientation: f,
160
+ itemsType: r,
161
+ itemId: e,
162
+ currencySymbol: _,
163
+ currencyLocation: s,
164
+ formattedPrice: p,
165
+ configBlockAttributes: y,
166
+ nameStyles: v,
167
+ buttonStyles: M,
168
+ priceStyles: h,
169
+ originalPriceStyles: R,
170
+ quantityStyles: k
171
+ };
172
+ }
173
+ /**
174
+ * Extracts all data-* attributes from the esd-config-block element
175
+ * Returns a key-value mapping of all configuration attributes
176
+ * @param block - The block element containing the esd-config-block
177
+ * @param itemsType - The type of items (CART_ITEMS, BROWSED_ITEMS, PURCHASED_ITEMS)
178
+ */
179
+ extractConfigBlockAttributes(t, r) {
180
+ const c = t.querySelector("esd-config-block"), n = {};
181
+ if (!c)
182
+ return this.getDefaultConfigBlockAttributes();
183
+ if (Array.from(c.attributes).forEach((e) => {
184
+ e.name.startsWith("data-") && (n[e.name] = e.value);
185
+ }), n["data-cart_items_select_control_value"]) {
186
+ const e = n["data-cart_items_select_control_value"];
187
+ if (/^\d+$/.test(e)) {
188
+ const a = parseInt(e) - 1, _ = I[r];
189
+ _ && _[a] && (n["data-cart_items_select_control_value"] = _[a].value);
190
+ }
191
+ }
192
+ if (n["data-product_price_control_curency"]) {
193
+ const e = n["data-product_price_control_curency"];
194
+ e === "before" ? n["data-product_price_control_curency"] = "0" : e === "after" && (n["data-product_price_control_curency"] = "1");
195
+ }
196
+ (!n["data-product_price_currency_symbol"] || n["data-product_price_currency_symbol"].trim() === "") && (n["data-product_price_currency_symbol"] = "USD");
197
+ const i = { ...this.getDefaultConfigBlockAttributes(), ...n };
198
+ return i["data-type"] = r, i["data-source"] = r, i;
199
+ }
200
+ /**
201
+ * Returns default esd-config-block attributes based on the old template structure
202
+ * These serve as fallbacks when attributes are missing
203
+ */
204
+ getDefaultConfigBlockAttributes() {
205
+ return {
206
+ "data-type": "CART_ITEMS",
207
+ "data-product_image_control_opened": "false",
208
+ "data-product_image_control_image-width": "250",
209
+ "data-product_image_control_image-height": "250",
210
+ "data-product_image_control_align_button": "true",
211
+ "data-product_image_control_padding_mobile": "true",
212
+ "data-product_name_control_opened": "false",
213
+ "data-product_quantity_control_opened": "true",
214
+ // DONE
215
+ "data-product_quantity_control_enabled": "false",
216
+ "data-product_name_control_font_font_size": "20",
217
+ "data-product_price_control_opened": "false",
218
+ "data-product_price_control_font_font_size": "20",
219
+ "data-product_price_control_color": "#060606",
220
+ "data-product_price_control_curency": "0",
221
+ "data-product_price_currency_symbol": "USD",
222
+ "data-product_original_price_control_opened": "false",
223
+ "data-product_original_price_control_font_font_size": "19",
224
+ "data-product_original_price_control_align_align_desktop": "center",
225
+ "data-product_original_price_control_orientation": "vertical",
226
+ "data-product_button_control_opened": "true",
227
+ "data-product_button_control_label": "Comprar",
228
+ // DONE
229
+ "data-product_button_control_font_font_size": "17",
230
+ "data-product_button_control_color": "#ffffff",
231
+ "data-product_button_control_background": "#010101",
232
+ "data-product_button_control_atw": "false",
233
+ "data-product_original_price_control_enabled": "false"
234
+ };
235
+ }
236
+ /**
237
+ * Removes Jinja2 conditional statements from HTML
238
+ * - Removes {% if ins_apr_total_product_kind > N %}
239
+ * - Removes {% if ins_apr_price_N != ins_apr_originalprice_N %}
240
+ * - Removes {% endif %}
241
+ */
242
+ removeJinjaConditionals(t) {
243
+ let r = t.replace(/\{%\s*if\s+ins_apr_total_product_kind\s*(&gt;|>)\s*\d+\s*%\}/g, "");
244
+ return r = r.replace(/\{%\s*if\s+ins_apr_price_\d+\s*(!&#61;|!=)\s*ins_apr_originalprice_\d+\s*%\}/g, ""), r = r.replace(/\{%\s*endif\s*%\}/g, ""), r = r.replace(/\n\s*\n\s*\n/g, `
245
+
246
+ `), r;
247
+ }
248
+ /**
249
+ * Replaces template variables with default values from productPairs
250
+ *
251
+ * Examples:
252
+ * - {{ins_apr_img_1}} → https://s3.../ins_apr_img_1.jpeg (array-based, uses index 0)
253
+ * - {{ins_apr_name_2}} → 'Set of Sprite Yoga Straps' (array-based, uses index 1)
254
+ * - {{ins_apr_formattedprice_1}} → '1,100.00' (single value, ignores index)
255
+ * - {{ins_apr_url_3}} → '#!' (single value, ignores index)
256
+ */
257
+ replaceTemplateVariables(t) {
258
+ const { PAIRS_FOR_EXTENSION: r } = L;
259
+ return t.replace(/{{([^}]+)}}/g, (c, n) => {
260
+ const i = n.match(/^(ins_apr_[a-z]+)_(\d+)$/);
261
+ if (!i)
262
+ return c;
263
+ const [, e, a] = i, _ = V[e];
264
+ if (!_)
265
+ return console.warn(`Unknown variable mapping for: ${e}`), c;
266
+ const { pairsKey: u, defaultKey: s, isArray: p } = _, y = r[u][this.DATA_TYPE];
267
+ if (!y)
268
+ return console.warn(`No data found for: ${u}.${this.DATA_TYPE}`), c;
269
+ if (p) {
270
+ const f = parseInt(a) - 1, d = y[s];
271
+ return Array.isArray(d) && d[f] ? d[f] : (console.warn(`Array value not found: ${u}.${this.DATA_TYPE}.${s}[${f}]`), c);
272
+ }
273
+ const g = y[s];
274
+ return g !== void 0 ? String(g) : (console.warn(`Default value not found: ${u}.${this.DATA_TYPE}.${s}`), c);
275
+ });
276
+ }
277
+ }
278
+ function $(o) {
279
+ return new w().migrate(o);
280
+ }
281
+ export {
282
+ $ as migrateItemsBlock
283
+ };
@@ -1,20 +1,20 @@
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 d } from "../../../stores/onboarding.js";
2
+ import { Block as u, BlockCompositionType as p, ModificationDescription as n } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
3
+ import { ItemsBlockId as f } from "./enums/controlEnums.js";
4
+ import { SETTINGS_ENUMS as c, DefaultConfigValues as o } from "./enums/settingsEnums.js";
5
+ import { useItemsBlockStore as g } from "./store/items-block.js";
6
+ import { getDefaultTemplate as y } from "./template.js";
7
+ import { getItemsBlockContainer as C, getItemsBlockConfig as a, getDefaultItemsBlockConfig as I } from "./utils/nodeConfigUtils.js";
8
+ const b = "items-block";
9
+ class O extends u {
10
10
  getId() {
11
- return M;
11
+ return b;
12
12
  }
13
13
  getIcon() {
14
14
  return "items-icon";
15
15
  }
16
16
  getBlockCompositionType() {
17
- return L.CONTAINER;
17
+ return p.CONTAINER;
18
18
  }
19
19
  getName() {
20
20
  return this.api.translate("Items");
@@ -23,45 +23,44 @@ class x extends R {
23
23
  return this.api.translate("Items lets you display personalized products based on user behavior.");
24
24
  }
25
25
  getTemplate() {
26
- return V({
27
- orientation: l.ORIENTATION.HORIZONTAL,
28
- itemsType: l.ITEMS_TYPE.CART_ITEMS,
26
+ return y({
27
+ orientation: c.ORIENTATION.VERTICAL,
28
+ itemsType: c.ITEMS_TYPE.CART_ITEMS,
29
29
  itemId: "{{Abandoned Cart Item (1) Url}}",
30
- currencySymbol: e.productPriceCurrencySymbolControlValue,
31
- currencyLocation: e.productPriceCurrencyLocationControlValue,
32
- formattedPrice: e.productPriceFormattedControlValue === "1"
30
+ currencySymbol: o.productPriceCurrencySymbolControlValue,
31
+ currencyLocation: o.productPriceCurrencyLocationControlValue,
32
+ formattedPrice: o.productPriceFormattedControlValue === "1"
33
33
  });
34
34
  }
35
35
  allowInnerBlocksDND() {
36
36
  return !1;
37
37
  }
38
- onCreated(r) {
39
- const n = r.querySelector("esd-config-block");
40
- if (!n)
38
+ onCreated(i) {
39
+ const e = C(i);
40
+ if (!e)
41
41
  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");
42
+ const t = e.getNodeConfig(), l = t && Object.keys(t).length > 0, r = a(i);
43
+ if (r != null && r.initialized)
44
+ l ? r.blockInstanceId || this.api.getDocumentModifier().modifyHtml(e).setNodeConfig({ ...r, blockInstanceId: String(Date.now()) }).apply(new n("Assign block instance ID to block")) : this.api.getDocumentModifier().modifyHtml(e).setNodeConfig(r).apply(new n("Migrate legacy esd-config-block to nodeConfig"));
45
+ else {
46
+ const m = I();
47
+ this.api.getDocumentModifier().modifyHtml(e).setNodeConfig(m).apply(new n("Initialize Items block with default configuration")), d().startOnboarding("itemsOnboarding");
54
48
  }
49
+ const s = `[esd-extension-block-id="${f.IMAGE}"] img`;
50
+ this.api.getDocumentModifier().modifyHtml(i.querySelector(s)).setStyle("object-fit", "contain").apply(new n("Updated image object-fit"));
55
51
  }
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);
52
+ onSelect(i) {
53
+ const e = g(), t = a(i);
54
+ t && (e.setItemsType(t.type || o.itemsType), e.setItemIds(t.itemsSelectValue || o.cartItemsSelectControlValue), e.setOrientation(t.orientation || o.cardOrientationControlValue), e.setCurrencySymbol(
55
+ t.priceCurrencySymbol || o.productPriceCurrencySymbolControlValue
56
+ ), e.setCurrencyLocation(
57
+ t.priceCurrencyLocation || o.productPriceCurrencyLocationControlValue
58
+ ), e.setFormattedPrice(
59
+ t.priceFormatted ?? o.productPriceFormattedControlValue === "1"
60
+ ));
62
61
  }
63
62
  }
64
63
  export {
65
- M as BLOCK_ID,
66
- x as ItemsBlock
64
+ b as BLOCK_ID,
65
+ O as ItemsBlock
67
66
  };
@@ -1,14 +1,13 @@
1
- var c = Object.defineProperty;
2
- var I = (a, n, t) => n in a ? c(a, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[n] = t;
3
- var _ = (a, n, t) => I(a, typeof n != "symbol" ? n + "" : n, t);
4
- import { ModificationDescription as l } from "../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
5
- import { CommonControl as R } from "../../common-control.js";
1
+ var P = Object.defineProperty;
2
+ var _ = (a, n, t) => n in a ? P(a, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[n] = t;
3
+ var d = (a, n, t) => _(a, typeof n != "symbol" ? n + "" : n, t);
4
+ import { ModificationDescription as r } from "../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
5
+ import { CommonControl as u } from "../../common-control.js";
6
6
  import { ItemsBlockId as s } from "../enums/controlEnums.js";
7
- import { configAttributes as C } from "../enums/productEnums.js";
8
- import { SETTINGS_ENUMS as u } from "../enums/settingsEnums.js";
7
+ import { SETTINGS_ENUMS as R } from "../enums/settingsEnums.js";
9
8
  import { useItemsBlockStore as O } from "../store/items-block.js";
10
- import { getConfigBlock as P, attributeToBoolean as U } from "../utils/configBlockUtils.js";
11
- const h = "ui-elements-items-card-composition-block", i = {
9
+ import { getItemsBlockConfig as C, setItemsBlockConfig as h } from "../utils/nodeConfigUtils.js";
10
+ const I = "ui-elements-items-card-composition-block", i = {
12
11
  PRODUCT_IMAGE: "image",
13
12
  PRODUCT_NAME: "name",
14
13
  PRODUCT_QUANTITY: "quantity",
@@ -16,11 +15,11 @@ const h = "ui-elements-items-card-composition-block", i = {
16
15
  PRODUCT_ORIGINAL_PRICE: "originalPrice",
17
16
  PRODUCT_BUTTON: "button"
18
17
  };
19
- class g extends R {
18
+ class N extends u {
20
19
  constructor() {
21
20
  super(...arguments);
22
- _(this, "store", O());
23
- _(this, "visibilityState", {
21
+ d(this, "store", O());
22
+ d(this, "visibilityState", {
24
23
  [i.PRODUCT_IMAGE]: !0,
25
24
  [i.PRODUCT_NAME]: !0,
26
25
  [i.PRODUCT_QUANTITY]: !0,
@@ -30,7 +29,7 @@ class g extends R {
30
29
  });
31
30
  }
32
31
  getId() {
33
- return h;
32
+ return I;
34
33
  }
35
34
  getTemplate() {
36
35
  return `
@@ -83,20 +82,20 @@ class g extends R {
83
82
  });
84
83
  }
85
84
  _syncVisibilityFromAttributes() {
86
- const t = P(this.currentNode);
85
+ const t = C(this.currentNode);
87
86
  if (!t)
88
87
  return;
89
88
  const e = {
90
- [i.PRODUCT_IMAGE]: "PRODUCT_IMAGE_VISIBLE",
91
- [i.PRODUCT_NAME]: "PRODUCT_NAME_VISIBLE",
92
- [i.PRODUCT_QUANTITY]: "PRODUCT_QUANTITY_VISIBLE",
93
- [i.PRODUCT_PRICE]: "PRODUCT_PRICE_VISIBLE",
94
- [i.PRODUCT_ORIGINAL_PRICE]: "PRODUCT_ORIGINAL_PRICE_VISIBLE",
95
- [i.PRODUCT_BUTTON]: "PRODUCT_BUTTON_VISIBLE"
89
+ [i.PRODUCT_IMAGE]: "imageVisible",
90
+ [i.PRODUCT_NAME]: "nameVisible",
91
+ [i.PRODUCT_QUANTITY]: "quantityControlEnabled",
92
+ [i.PRODUCT_PRICE]: "priceVisible",
93
+ [i.PRODUCT_ORIGINAL_PRICE]: "originalPriceVisible",
94
+ [i.PRODUCT_BUTTON]: "buttonVisible"
96
95
  };
97
- Object.entries(e).forEach(([o, r]) => {
98
- const T = t.getAttribute(C[r]);
99
- this.visibilityState[o] = U(T, !0);
96
+ Object.entries(e).forEach(([o, l]) => {
97
+ const T = t[l];
98
+ this.visibilityState[o] = T !== !1;
100
99
  });
101
100
  }
102
101
  /**
@@ -105,11 +104,10 @@ class g extends R {
105
104
  * and mark it as '0'
106
105
  */
107
106
  _handleBrowsedItemsQuantity() {
108
- var r;
109
- const t = this.store.itemsType !== u.ITEMS_TYPE.BROWSED_ITEMS, e = (r = this.currentNode) == null ? void 0 : r.querySelector("esd-config-block");
107
+ const t = this.store.itemsType !== R.ITEMS_TYPE.BROWSED_ITEMS, e = C(this.currentNode);
110
108
  if (!e)
111
109
  return;
112
- const o = e.getAttribute(C.PRODUCT_QUANTITY_VISIBLE) === "1";
110
+ const o = e.quantityControlEnabled !== !1;
113
111
  this.visibilityState[i.PRODUCT_QUANTITY] = t && o, this.api.setVisibility(`${i.PRODUCT_QUANTITY}Container`, t), this._updateVisibilityAttribute(i.PRODUCT_QUANTITY, t && o);
114
112
  }
115
113
  _applyVisibilityStyles() {
@@ -122,27 +120,26 @@ class g extends R {
122
120
  [i.PRODUCT_BUTTON]: s.BUTTON
123
121
  };
124
122
  Object.entries(t).forEach(([e, o]) => {
125
- var d;
126
- const r = (d = this.currentNode) == null ? void 0 : d.querySelector(`[esd-extension-block-id="${o}"]`);
127
- if (!r)
123
+ var c;
124
+ const l = (c = this.currentNode) == null ? void 0 : c.querySelector(`[esd-extension-block-id="${o}"]`);
125
+ if (!l)
128
126
  return;
129
127
  const T = this.visibilityState[e];
130
- this.api.getDocumentModifier().modifyHtml(r).setStyle("display", T ? "table-cell" : "none").apply(new l(`Applied ${e} visibility from attributes`));
128
+ this.api.getDocumentModifier().modifyHtml(l).setStyle("display", T ? "table-cell" : "none").apply(new r(`Applied ${e} visibility from attributes`));
131
129
  });
132
130
  }
133
131
  _updateVisibilityAttribute(t, e) {
134
- const o = P(this.currentNode);
135
- if (!o)
136
- return;
137
- const T = {
138
- [i.PRODUCT_IMAGE]: "PRODUCT_IMAGE_VISIBLE",
139
- [i.PRODUCT_NAME]: "PRODUCT_NAME_VISIBLE",
140
- [i.PRODUCT_QUANTITY]: "PRODUCT_QUANTITY_VISIBLE",
141
- [i.PRODUCT_PRICE]: "PRODUCT_PRICE_VISIBLE",
142
- [i.PRODUCT_ORIGINAL_PRICE]: "PRODUCT_ORIGINAL_PRICE_VISIBLE",
143
- [i.PRODUCT_BUTTON]: "PRODUCT_BUTTON_VISIBLE"
132
+ const l = {
133
+ [i.PRODUCT_IMAGE]: "imageVisible",
134
+ [i.PRODUCT_NAME]: "nameVisible",
135
+ [i.PRODUCT_QUANTITY]: "quantityControlEnabled",
136
+ [i.PRODUCT_PRICE]: "priceVisible",
137
+ [i.PRODUCT_ORIGINAL_PRICE]: "originalPriceVisible",
138
+ [i.PRODUCT_BUTTON]: "buttonVisible"
144
139
  }[t];
145
- T && this.api.getDocumentModifier().modifyHtml(o).setAttribute(C[T], e ? "1" : "0").apply(new l(`Updated ${t} visibility attribute`));
140
+ l && h(this.currentNode, this.api, {
141
+ [l]: e
142
+ });
146
143
  }
147
144
  _listenToFormUpdates() {
148
145
  this.api.onValueChanged(i.PRODUCT_IMAGE, (t) => this._onProductImageChange(t)), this.api.onValueChanged(i.PRODUCT_NAME, (t) => this._onProductNameChange(t)), this.api.onValueChanged(i.PRODUCT_QUANTITY, (t) => this._onProductQuantityChange(t)), this.api.onValueChanged(i.PRODUCT_PRICE, (t) => this._onProductPriceChange(t)), this.api.onValueChanged(
@@ -153,41 +150,41 @@ class g extends R {
153
150
  _onProductImageChange(t) {
154
151
  var o;
155
152
  const e = (o = this.currentNode) == null ? void 0 : o.querySelector(`[esd-extension-block-id="${s.IMAGE}"]`);
156
- e && (this.visibilityState[i.PRODUCT_IMAGE] = t, this.api.getDocumentModifier().modifyHtml(e).setStyle("display", t ? "table-cell" : "none").apply(new l(`Product image visibility changed to ${t ? "visible" : "hidden"}`)), this._updateVisibilityAttribute(i.PRODUCT_IMAGE, t));
153
+ e && (this.visibilityState[i.PRODUCT_IMAGE] = t, this.api.getDocumentModifier().modifyHtml(e).setStyle("display", t ? "table-cell" : "none").apply(new r(`Product image visibility changed to ${t ? "visible" : "hidden"}`)), this._updateVisibilityAttribute(i.PRODUCT_IMAGE, t));
157
154
  }
158
155
  _onProductNameChange(t) {
159
156
  var o;
160
157
  const e = (o = this.currentNode) == null ? void 0 : o.querySelector(`[esd-extension-block-id="${s.NAME}"]`);
161
- e && (this.visibilityState[i.PRODUCT_NAME] = t, this.api.getDocumentModifier().modifyHtml(e).setStyle("display", t ? "table-cell" : "none").apply(new l(`Product name visibility changed to ${t ? "visible" : "hidden"}`)), this._updateVisibilityAttribute(i.PRODUCT_NAME, t));
158
+ e && (this.visibilityState[i.PRODUCT_NAME] = t, this.api.getDocumentModifier().modifyHtml(e).setStyle("display", t ? "table-cell" : "none").apply(new r(`Product name visibility changed to ${t ? "visible" : "hidden"}`)), this._updateVisibilityAttribute(i.PRODUCT_NAME, t));
162
159
  }
163
160
  _onProductQuantityChange(t) {
164
161
  var o;
165
162
  const e = (o = this.currentNode) == null ? void 0 : o.querySelector(`[esd-extension-block-id="${s.QUANTITY}"]`);
166
- e && (this.visibilityState[i.PRODUCT_QUANTITY] = t, this.api.getDocumentModifier().modifyHtml(e).setStyle("display", t ? "table-cell" : "none").apply(new l(
163
+ e && (this.visibilityState[i.PRODUCT_QUANTITY] = t, this.api.getDocumentModifier().modifyHtml(e).setStyle("display", t ? "table-cell" : "none").apply(new r(
167
164
  `Product quantity visibility changed to ${t ? "visible" : "hidden"}`
168
165
  )), this._updateVisibilityAttribute(i.PRODUCT_QUANTITY, t));
169
166
  }
170
167
  _onProductPriceChange(t) {
171
168
  var o;
172
169
  const e = (o = this.currentNode) == null ? void 0 : o.querySelector(`[esd-extension-block-id="${s.PRICE}"]`);
173
- e && (this.visibilityState[i.PRODUCT_PRICE] = t, this.api.getDocumentModifier().modifyHtml(e).setStyle("display", t ? "table-cell" : "none").apply(new l(`Product price visibility changed to ${t ? "visible" : "hidden"}`)), this._updateVisibilityAttribute(i.PRODUCT_PRICE, t));
170
+ e && (this.visibilityState[i.PRODUCT_PRICE] = t, this.api.getDocumentModifier().modifyHtml(e).setStyle("display", t ? "table-cell" : "none").apply(new r(`Product price visibility changed to ${t ? "visible" : "hidden"}`)), this._updateVisibilityAttribute(i.PRODUCT_PRICE, t));
174
171
  }
175
172
  _onProductOriginalPriceChange(t) {
176
173
  var o;
177
174
  const e = (o = this.currentNode) == null ? void 0 : o.querySelector(
178
175
  `[esd-extension-block-id="${s.ORIGINAL_PRICE}"]`
179
176
  );
180
- e && (this.visibilityState[i.PRODUCT_ORIGINAL_PRICE] = t, this.api.getDocumentModifier().modifyHtml(e).setStyle("display", t ? "table-cell" : "none").apply(new l(
177
+ e && (this.visibilityState[i.PRODUCT_ORIGINAL_PRICE] = t, this.api.getDocumentModifier().modifyHtml(e).setStyle("display", t ? "table-cell" : "none").apply(new r(
181
178
  `Product original price visibility changed to ${t ? "visible" : "hidden"}`
182
179
  )), this._updateVisibilityAttribute(i.PRODUCT_ORIGINAL_PRICE, t));
183
180
  }
184
181
  _onProductButtonChange(t) {
185
182
  var o;
186
183
  const e = (o = this.currentNode) == null ? void 0 : o.querySelector(`[esd-extension-block-id="${s.BUTTON}"]`);
187
- e && (this.visibilityState[i.PRODUCT_BUTTON] = t, this.api.getDocumentModifier().modifyHtml(e).setStyle("display", t ? "table-cell" : "none").apply(new l(`Product button visibility changed to ${t ? "visible" : "hidden"}`)), this._updateVisibilityAttribute(i.PRODUCT_BUTTON, t));
184
+ e && (this.visibilityState[i.PRODUCT_BUTTON] = t, this.api.getDocumentModifier().modifyHtml(e).setStyle("display", t ? "table-cell" : "none").apply(new r(`Product button visibility changed to ${t ? "visible" : "hidden"}`)), this._updateVisibilityAttribute(i.PRODUCT_BUTTON, t));
188
185
  }
189
186
  }
190
187
  export {
191
- h as COMPOSITION_CONTROL_BLOCK_ID,
192
- g as ItemsBlockCardCompositionControl
188
+ I as COMPOSITION_CONTROL_BLOCK_ID,
189
+ N as ItemsBlockCardCompositionControl
193
190
  };