@useinsider/guido 3.17.0-beta.3a4c221 → 3.17.0-beta.3deafbf

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.
package/README.md CHANGED
@@ -633,16 +633,16 @@ toaster fires (useful before the host has wired the catalog).
633
633
 
634
634
  ```bash
635
635
  # Install
636
- bun install
636
+ npm install
637
637
 
638
638
  # Start dev server
639
- bun start
639
+ npm start
640
640
 
641
641
  # Build
642
- bun run build
642
+ npm run build
643
643
 
644
644
  # Lint & type-check
645
- bun run lint
645
+ npm run lint
646
646
  ```
647
647
 
648
648
  ### Environment Variables
@@ -660,7 +660,7 @@ VITE_STRIPO_USER=your_user
660
660
 
661
661
  ```bash
662
662
  # Build the package
663
- bun run build
663
+ npm run build
664
664
 
665
665
  # Create tarball
666
666
  npm pack
@@ -1,20 +1,30 @@
1
- import { BlockId as g } from "../../../enums/block.js";
2
- import { useOnboardingStore as y } from "../../../stores/onboarding.js";
3
- import { getMigrationBannerHtml as I } from "../../../utils/migrationBannerHtml.js";
4
- import { Block as C, BlockCompositionType as b, ModificationDescription as c } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
5
- import { SETTINGS_ENUMS as l, DefaultConfigValues as d } from "./enums/settingsEnums.js";
6
- import { getDefaultTemplate as h } from "./template.js";
7
- import { getItemsBlockContainer as u, getItemsBlockConfig as f, deriveItemNumber as D, getDefaultItemsBlockConfig as N } from "./utils/nodeConfigUtils.js";
8
- const p = g.Items;
9
- class E extends C {
1
+ var D = Object.defineProperty;
2
+ var k = (l, a, t) => a in l ? D(l, a, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[a] = t;
3
+ var I = (l, a, t) => k(l, typeof a != "symbol" ? a + "" : a, t);
4
+ import { BlockId as N } from "../../../enums/block.js";
5
+ import { useOnboardingStore as T } from "../../../stores/onboarding.js";
6
+ import { getMigrationBannerHtml as _ } from "../../../utils/migrationBannerHtml.js";
7
+ import { Block as A, BlockCompositionType as M, ModificationDescription as m } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
8
+ import { currencyPositionFromLocation as O, ITEMS_CURRENCY_ATTR as d } from "./constants/currency.js";
9
+ import { ItemsBlockId as R } from "./enums/controlEnums.js";
10
+ import { SETTINGS_ENUMS as b, DefaultConfigValues as f } from "./enums/settingsEnums.js";
11
+ import { getDefaultTemplate as E } from "./template.js";
12
+ import { getItemsBlockContainer as h, getItemsBlockConfig as C, deriveItemNumber as H, getDefaultItemsBlockConfig as B } from "./utils/nodeConfigUtils.js";
13
+ const S = N.Items, P = "Reconcile Items currency DOM attributes";
14
+ class G extends A {
15
+ constructor() {
16
+ super(...arguments);
17
+ /** Block instances whose currency attrs were already self-healed this session (SD-147588 — undo-safe). */
18
+ I(this, "_currencyHealed", /* @__PURE__ */ new Set());
19
+ }
10
20
  getId() {
11
- return p;
21
+ return S;
12
22
  }
13
23
  getIcon() {
14
24
  return "items-icon";
15
25
  }
16
26
  getBlockCompositionType() {
17
- return b.CONTAINER;
27
+ return M.CONTAINER;
18
28
  }
19
29
  getName() {
20
30
  return this.api.translate("Items");
@@ -23,20 +33,20 @@ class E extends C {
23
33
  return this.api.translate("Items lets you display personalized products based on user behavior.");
24
34
  }
25
35
  getSettingsPanelTitleHtml() {
26
- return I(
27
- p,
36
+ return _(
37
+ S,
28
38
  this.api.translate("Items"),
29
39
  this.api.translate("This block is switched from the Old Version to the New Version. We recommend you check the Items block and test your message to ensure it works properly.")
30
40
  );
31
41
  }
32
42
  getTemplate() {
33
- return h({
34
- orientation: l.ORIENTATION.VERTICAL,
35
- itemsType: l.ITEMS_TYPE.CART_ITEMS,
43
+ return E({
44
+ orientation: b.ORIENTATION.VERTICAL,
45
+ itemsType: b.ITEMS_TYPE.CART_ITEMS,
36
46
  itemId: "{{Abandoned Cart Item (1) Url}}",
37
- currencySymbol: d.productPriceCurrencySymbolControlValue,
38
- currencyLocation: d.productPriceCurrencyLocationControlValue,
39
- formattedPrice: d.productPriceFormattedControlValue === "1"
47
+ currencySymbol: f.productPriceCurrencySymbolControlValue,
48
+ currencyLocation: f.productPriceCurrencyLocationControlValue,
49
+ formattedPrice: f.productPriceFormattedControlValue === "1"
40
50
  });
41
51
  }
42
52
  allowInnerBlocksDND() {
@@ -45,24 +55,27 @@ class E extends C {
45
55
  canBeSavedAsModule() {
46
56
  return !0;
47
57
  }
48
- onCreated(n) {
49
- const t = this.api.getDocumentModifier(), a = this.api.getDocumentRootCssNode();
50
- a.querySelector('[product-attr="imageSrc"] img') || t.modifyCss(a).appendRule('[product-attr="imageSrc"] img {object-fit: contain;}');
51
- const e = u(n);
52
- if (!e)
58
+ onCreated(t) {
59
+ const o = this.api.getDocumentModifier(), s = this.api.getDocumentRootCssNode();
60
+ s.querySelector('[product-attr="imageSrc"] img') || o.modifyCss(s).appendRule('[product-attr="imageSrc"] img {object-fit: contain;}');
61
+ const r = h(t);
62
+ if (!r)
53
63
  return;
54
- const o = e.getNodeConfig(), r = o && Object.keys(o).length > 0, i = f(n);
55
- if (i != null && i.initialized)
56
- if (r)
57
- i.blockInstanceId || this.api.getDocumentModifier().modifyHtml(e).setNodeConfig({ ...i, blockInstanceId: String(Date.now()) }).apply(new c("Assign block instance ID to block"));
58
- else {
59
- const s = this.api.getDocumentModifier();
60
- s.modifyHtml(e).setNodeConfig(i), this._stampProductTdDomAttributes(e, i, s), s.apply(new c("Migrate legacy config to nodeConfig"));
64
+ const i = r.getNodeConfig(), c = i && Object.keys(i).length > 0, e = C(t);
65
+ if (e != null && e.initialized) {
66
+ if (!c) {
67
+ const u = this.api.getDocumentModifier();
68
+ u.modifyHtml(r).setNodeConfig(e), this._stampProductTdDomAttributes(r, e, u), u.apply(new m("Migrate legacy config to nodeConfig"));
69
+ return;
61
70
  }
62
- else {
63
- const s = N(), m = this.api.getDocumentModifier();
64
- m.modifyHtml(e).setNodeConfig(s), this._stampProductTdDomAttributes(e, s, m, !0), m.apply(new c("Initialize Items block with default configuration")), y().startOnboarding("itemsOnboarding");
71
+ } else {
72
+ const u = B(), g = this.api.getDocumentModifier();
73
+ g.modifyHtml(r).setNodeConfig(u), this._stampProductTdDomAttributes(r, u, g, !0), g.apply(new m("Initialize Items block with default configuration")), T().startOnboarding("itemsOnboarding");
74
+ return;
65
75
  }
76
+ const n = e.blockInstanceId || String(Date.now()), p = this.api.getDocumentModifier();
77
+ let y = !1;
78
+ e.blockInstanceId || (p.modifyHtml(r).setNodeConfig({ ...e, blockInstanceId: n }), y = !0), this._shouldReconcileCurrency(e) && this._reconcileCurrencyDomAttributes(r, e, p) && (y = !0), y && p.apply(new m("Assign Items block instance ID and reconcile currency")), this._markCurrencyHealed(n);
66
79
  }
67
80
  /**
68
81
  * Re-seeds nodeConfig from the persisted esd-ext-config when a saved module
@@ -70,18 +83,24 @@ class E extends C {
70
83
  * into nodeConfig, so without this a reused module would reset to defaults.
71
84
  * Guarded to the nodeConfig-empty case so it runs once and never loops.
72
85
  */
73
- onDocumentChanged(n) {
74
- const t = u(n);
75
- if (!t)
86
+ onDocumentChanged(t) {
87
+ const o = h(t);
88
+ if (!o)
76
89
  return;
77
- const a = t.getNodeConfig();
78
- if (a && Object.keys(a).length > 0)
90
+ const s = o.getNodeConfig();
91
+ if (s && Object.keys(s).length > 0) {
92
+ const e = C(t);
93
+ if (e != null && e.initialized && this._shouldReconcileCurrency(e)) {
94
+ const n = this.api.getDocumentModifier();
95
+ this._reconcileCurrencyDomAttributes(o, e, n) && n.apply(new m(P)), this._markCurrencyHealed(e.blockInstanceId);
96
+ }
79
97
  return;
80
- const o = f(n);
81
- if (!(o != null && o.initialized))
98
+ }
99
+ const i = C(t);
100
+ if (!(i != null && i.initialized))
82
101
  return;
83
- const r = this.api.getDocumentModifier();
84
- r.modifyHtml(t).setNodeConfig(o), this._stampProductTdDomAttributes(t, o, r), r.apply(new c("Recover Items block config from saved module"));
102
+ const c = this.api.getDocumentModifier();
103
+ c.modifyHtml(o).setNodeConfig(i), this._stampProductTdDomAttributes(o, i, c), c.apply(new m("Recover Items block config from saved module"));
85
104
  }
86
105
  /**
87
106
  * Bakes the compiler-read DOM attributes (`data-type`, `data-number`, `data-nodup`) onto the
@@ -91,14 +110,44 @@ class E extends C {
91
110
  * restored before export. The name `<a>` carries no data-type/data-number of its own and
92
111
  * relies on this td-level fallback in pairProductVariables.
93
112
  */
94
- _stampProductTdDomAttributes(n, t, a, e = !1) {
95
- const o = D(t.itemsSelectValue, t.type), r = (i, s) => {
96
- e && n.getAttribute(i) || a.modifyHtml(n).setAttribute(i, s);
113
+ _stampProductTdDomAttributes(t, o, s, r = !1) {
114
+ const i = H(o.itemsSelectValue, o.type), c = (e, n) => {
115
+ r && t.getAttribute(e) || s.modifyHtml(t).setAttribute(e, n);
97
116
  };
98
- r("data-type", t.type), r("data-number", o), r("data-nodup", String(t.priceHideDiscount));
117
+ c("data-type", o.type), c("data-number", i), c("data-nodup", String(o.priceHideDiscount));
118
+ }
119
+ /**
120
+ * Whether the currency self-heal should run for this block. Two guards (SD-147588):
121
+ * 1. Config is only authoritative when the symbol was actually customized — a symbol still at
122
+ * the 'USD' sentinel may be a migrator default, so we trust the DOM's real value over a
123
+ * defaulted config and never overwrite it.
124
+ * 2. Heal each instance at most once per session, so the auto-fix can't fight undo (undo
125
+ * re-drifts the attr, which would otherwise re-trigger the heal forever).
126
+ */
127
+ _shouldReconcileCurrency(t) {
128
+ const o = (t.priceCurrencySymbol ?? "").trim();
129
+ return !o || o === f.productPriceCurrencySymbolControlValue ? !1 : !t.blockInstanceId || !this._currencyHealed.has(t.blockInstanceId);
130
+ }
131
+ /** Marks a block instance's currency as reconciled so it is not healed again (undo-safe). */
132
+ _markCurrencyHealed(t) {
133
+ t && this._currencyHealed.add(t);
134
+ }
135
+ /**
136
+ * Stamps the export-read currency attrs onto every price `<p>` from config, so a template whose
137
+ * attrs drifted (e.g. a location toggle before the sync fix) self-heals to match the editor.
138
+ * Config is the source of truth — never derive from visible text. Callers gate this with
139
+ * `_shouldReconcileCurrency`. Returns true only when an attr actually changed, so the caller can
140
+ * skip an empty apply that would otherwise re-trigger onDocumentChanged and loop (SD-147588).
141
+ */
142
+ _reconcileCurrencyDomAttributes(t, o, s) {
143
+ const r = O(o.priceCurrencyLocation), i = (o.priceCurrencySymbol ?? "").trim(), c = t.querySelectorAll(`.${R.PRICE} p`);
144
+ let e = !1;
145
+ return c.forEach((n) => {
146
+ n.getAttribute(d.POSITION) !== r && (s.modifyHtml(n).setAttribute(d.POSITION, r), e = !0), i && n.getAttribute(d.SYMBOL) !== i && (s.modifyHtml(n).setAttribute(d.SYMBOL, i), e = !0);
147
+ }), e;
99
148
  }
100
149
  }
101
150
  export {
102
- p as BLOCK_ID,
103
- E as ItemsBlock
151
+ S as BLOCK_ID,
152
+ G as ItemsBlock
104
153
  };
@@ -0,0 +1,11 @@
1
+ const o = {
2
+ POSITION: "data-curency",
3
+ SYMBOL: "data-currency_symbol"
4
+ };
5
+ function c(r) {
6
+ return r === "1" ? "after" : "before";
7
+ }
8
+ export {
9
+ o as ITEMS_CURRENCY_ATTR,
10
+ c as currencyPositionFromLocation
11
+ };
@@ -1,14 +1,15 @@
1
- import { currencyLocationMaps as u } from "../../../../../enums/extensions/recommendationBlock.js";
2
- import { UEAttr as R, ModificationDescription as L } from "../../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
3
- import { CommonControl as N } from "../../../common-control.js";
1
+ import { currencyLocationMaps as p } from "../../../../../enums/extensions/recommendationBlock.js";
2
+ import { UEAttr as N, ModificationDescription as I } from "../../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
3
+ import { CommonControl as L } from "../../../common-control.js";
4
+ import { ITEMS_CURRENCY_ATTR as T, currencyPositionFromLocation as E } from "../../constants/currency.js";
4
5
  import { ItemsBlockControlId as m } from "../../enums/controlEnums.js";
5
- import { getItemsBlockConfig as C, setItemsBlockConfig as I, escapeReplacement as T } from "../../utils/nodeConfigUtils.js";
6
- const E = m.PRICE_CURRENCY_LOCATION, c = {
6
+ import { getItemsBlockConfig as l, setItemsBlockConfig as O, escapeReplacement as f } from "../../utils/nodeConfigUtils.js";
7
+ const b = m.PRICE_CURRENCY_LOCATION, c = {
7
8
  CURRENCY_LOCATION: "currencyLocation"
8
9
  };
9
- class A extends N {
10
+ class Y extends L {
10
11
  getId() {
11
- return E;
12
+ return b;
12
13
  }
13
14
  getTemplate() {
14
15
  return `
@@ -18,32 +19,32 @@ class A extends N {
18
19
  `;
19
20
  }
20
21
  onRender() {
21
- const e = C(this.currentNode);
22
- this.api.setUIEAttribute(c.CURRENCY_LOCATION, R.SELECTPICKER.items, u), this.api.updateValues({ [c.CURRENCY_LOCATION]: (e == null ? void 0 : e.priceCurrencyLocation) ?? "0" }), this.api.onValueChanged(c.CURRENCY_LOCATION, (t) => {
22
+ const e = l(this.currentNode);
23
+ this.api.setUIEAttribute(c.CURRENCY_LOCATION, N.SELECTPICKER.items, p), this.api.updateValues({ [c.CURRENCY_LOCATION]: (e == null ? void 0 : e.priceCurrencyLocation) ?? "0" }), this.api.onValueChanged(c.CURRENCY_LOCATION, (t) => {
23
24
  this._onCurrencyLocationChange(t);
24
25
  });
25
26
  }
26
27
  onTemplateNodeUpdated(e) {
27
28
  super.onTemplateNodeUpdated(e), this.handleBlockInstanceChange(() => {
28
- const t = C(this.currentNode);
29
+ const t = l(this.currentNode);
29
30
  this.api.updateValues({ [c.CURRENCY_LOCATION]: (t == null ? void 0 : t.priceCurrencyLocation) ?? "0" });
30
31
  });
31
32
  }
32
33
  _onCurrencyLocationChange(e) {
33
- if (console.debug("Currency location changed to: ", e), I(this.currentNode, this.api, { priceCurrencyLocation: e }), !this.currentNode)
34
+ if (console.debug("Currency location changed to: ", e), O(this.currentNode, this.api, { priceCurrencyLocation: e }), !this.currentNode)
34
35
  return;
35
36
  const t = this._getPriceBlocks();
36
37
  if (!t || t.length === 0)
37
38
  return;
38
- const r = C(this.currentNode), n = e || "0", o = (r == null ? void 0 : r.priceCurrencySymbol) ?? "", i = this.api.getDocumentModifier();
39
- t.forEach((a) => {
40
- const s = this._getParagraph(a);
41
- if (!s)
39
+ const r = l(this.currentNode), n = e || "0", o = (r == null ? void 0 : r.priceCurrencySymbol) ?? "", i = E(n), s = this.api.getDocumentModifier();
40
+ t.forEach((h) => {
41
+ const a = this._getParagraph(h);
42
+ if (!a)
42
43
  return;
43
- const h = s.getInnerHTML().trim() || "", l = s.getInnerText().trim() || "", p = (o == null ? void 0 : o.trim()) || "", d = this._removeCurrencySymbol(l, p), g = this._detectSymbolInText(l) || p, _ = this._buildPriceContent(d, g, n), y = h.replace(l, T(_));
44
- i.modifyHtml(s).setInnerHtml(y);
45
- }), i.apply(new L(
46
- `Updated currency location to ${n === "1" ? "after" : "before"}`
44
+ const d = a.getInnerHTML().trim() || "", C = a.getInnerText().trim() || "", u = (o == null ? void 0 : o.trim()) || "", _ = this._removeCurrencySymbol(C, u), g = this._detectSymbolInText(C) || u, R = this._buildPriceContent(_, g, n), y = d.replace(C, f(R));
45
+ s.modifyHtml(a).setInnerHtml(y).setAttribute(T.POSITION, i);
46
+ }), s.apply(new I(
47
+ `Updated currency location to ${i}`
47
48
  ));
48
49
  }
49
50
  _getPriceBlocks() {
@@ -65,8 +66,8 @@ class A extends N {
65
66
  } else {
66
67
  const o = r.match(/([^0-9.,\s]+)/);
67
68
  if (o && o[1]) {
68
- const i = o[1].trim(), a = new RegExp(`\\s*${this._escapeRegex(i)}\\s*`);
69
- n = r.replace(a, "").trim();
69
+ const i = o[1].trim(), s = new RegExp(`\\s*${this._escapeRegex(i)}\\s*`);
70
+ n = r.replace(s, "").trim();
70
71
  }
71
72
  }
72
73
  return n;
@@ -85,13 +86,13 @@ class A extends N {
85
86
  this._GuSelect({
86
87
  name: c.CURRENCY_LOCATION,
87
88
  placeholder: "",
88
- options: u
89
+ options: p
89
90
  })
90
91
  ])}
91
92
  `;
92
93
  }
93
94
  }
94
95
  export {
95
- E as CONTROL_BLOCK_ID,
96
- A as PriceCurrencyLocationControl
96
+ b as CONTROL_BLOCK_ID,
97
+ Y as PriceCurrencyLocationControl
97
98
  };
@@ -1,20 +1,21 @@
1
1
  var R = Object.defineProperty;
2
2
  var N = (s, c, e) => c in s ? R(s, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[c] = e;
3
3
  var h = (s, c, e) => N(s, typeof c != "symbol" ? c + "" : c, e);
4
- import { ModificationDescription as B } from "../../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
5
- import { CommonControl as E } from "../../../common-control.js";
4
+ import { ModificationDescription as E } from "../../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
5
+ import { CommonControl as B } from "../../../common-control.js";
6
+ import { ITEMS_CURRENCY_ATTR as T } from "../../constants/currency.js";
6
7
  import { ItemsBlockControlId as y } from "../../enums/controlEnums.js";
7
- import { getItemsBlockConfig as p, setItemsBlockConfig as x, escapeReplacement as f } from "../../utils/nodeConfigUtils.js";
8
- const I = y.PRICE_CURRENCY_SYMBOL, u = {
8
+ import { getItemsBlockConfig as p, setItemsBlockConfig as Y, escapeReplacement as f } from "../../utils/nodeConfigUtils.js";
9
+ const x = y.PRICE_CURRENCY_SYMBOL, u = {
9
10
  CURRENCY_SYMBOL: "currencySymbol"
10
11
  };
11
- class P extends E {
12
+ class $ extends B {
12
13
  constructor() {
13
14
  super(...arguments);
14
15
  h(this, "originalPriceContents", /* @__PURE__ */ new Map());
15
16
  }
16
17
  getId() {
17
- return I;
18
+ return x;
18
19
  }
19
20
  getTemplate() {
20
21
  return `
@@ -42,7 +43,7 @@ class P extends E {
42
43
  var a;
43
44
  console.debug("Currency symbol changed to: ", e);
44
45
  const t = p(this.currentNode), o = ((a = t == null ? void 0 : t.priceCurrencySymbol) == null ? void 0 : a.trim()) || "";
45
- if (x(this.currentNode, this.api, { priceCurrencySymbol: e }), !this.currentNode)
46
+ if (Y(this.currentNode, this.api, { priceCurrencySymbol: e }), !this.currentNode)
46
47
  return;
47
48
  const r = this._getPriceBlocks();
48
49
  if (!r || r.length === 0)
@@ -53,8 +54,8 @@ class P extends E {
53
54
  if (!m)
54
55
  return;
55
56
  const g = m.getInnerHTML().trim() || "", C = m.getInnerText().trim() || "", _ = this._removeCurrencySymbol(C, o), S = this._buildPriceContent(_, n, l), b = g.replace(C, f(S));
56
- i.modifyHtml(m).setInnerHtml(b).setAttribute("data-currency_symbol", n);
57
- }), i.apply(new B(
57
+ i.modifyHtml(m).setInnerHtml(b).setAttribute(T.SYMBOL, n);
58
+ }), i.apply(new E(
58
59
  `Updated currency symbol to ${n || "removed"}`
59
60
  ));
60
61
  }
@@ -115,6 +116,6 @@ class P extends E {
115
116
  }
116
117
  }
117
118
  export {
118
- I as CONTROL_BLOCK_ID,
119
- P as PriceCurrencySymbolControl
119
+ x as CONTROL_BLOCK_ID,
120
+ $ as PriceCurrencySymbolControl
120
121
  };