@useinsider/guido 3.17.0 → 3.18.0

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 (110) hide show
  1. package/README.md +6 -5
  2. package/dist/@types/config/schemas.js +7 -6
  3. package/dist/components/Guido.vue.js +10 -10
  4. package/dist/components/Guido.vue2.js +82 -76
  5. package/dist/components/organisms/extensions/recommendation/AssignStrategyDrawer.vue.js +21 -0
  6. package/dist/components/organisms/extensions/recommendation/AssignStrategyDrawer.vue2.js +106 -0
  7. package/dist/components/organisms/extensions/recommendation/RemoveStrategyModal.vue.js +17 -0
  8. package/dist/components/organisms/extensions/recommendation/RemoveStrategyModal.vue2.js +57 -0
  9. package/dist/components/organisms/extensions/recommendation/StrategyInfoBoxContent.vue.js +19 -0
  10. package/dist/components/organisms/extensions/recommendation/StrategyInfoBoxContent.vue2.js +63 -0
  11. package/dist/composables/useCustomInterfaceAppearance.js +52 -38
  12. package/dist/composables/useModuleRepair.js +33 -0
  13. package/dist/composables/useRecommendation.js +41 -34
  14. package/dist/composables/useSave.js +30 -29
  15. package/dist/composables/useStripo.js +15 -15
  16. package/dist/composables/useSyncModuleExtractor.js +15 -13
  17. package/dist/composables/validators/useSyncModuleBlockValidator.js +24 -0
  18. package/dist/config/i18n/en/labels.json.js +1 -1
  19. package/dist/config/migrator/index.js +9 -8
  20. package/dist/config/migrator/recommendation/compositionMapper.js +20 -20
  21. package/dist/config/migrator/recommendation/extractors.js +29 -24
  22. package/dist/config/migrator/recommendation/htmlBuilder.js +116 -130
  23. package/dist/config/migrator/recommendation/settingsMapper.js +17 -17
  24. package/dist/config/migrator/recommendationMigrator.js +31 -25
  25. package/dist/config/migrator/recommendationTitleMigrator.js +119 -0
  26. package/dist/enums/academy.js +2 -1
  27. package/dist/enums/date.js +5 -3
  28. package/dist/enums/extensions/recommendationBlock.js +3 -1
  29. package/dist/extensions/Blocks/Items/block.js +118 -49
  30. package/dist/extensions/Blocks/Items/constants/currency.js +25 -0
  31. package/dist/extensions/Blocks/Items/controls/price/currencyLocation.js +25 -24
  32. package/dist/extensions/Blocks/Items/controls/price/currencySymbol.js +12 -11
  33. package/dist/extensions/Blocks/Items/template.js +153 -152
  34. package/dist/extensions/Blocks/Items/utils/constants.js +4 -0
  35. package/dist/extensions/Blocks/Recommendation/block.js +35 -29
  36. package/dist/extensions/Blocks/Recommendation/constants/blockIds.js +1 -1
  37. package/dist/extensions/Blocks/Recommendation/constants/controlIds.js +1 -1
  38. package/dist/extensions/Blocks/Recommendation/constants/defaultConfig.js +29 -27
  39. package/dist/extensions/Blocks/Recommendation/constants/selectors.js +35 -28
  40. package/dist/extensions/Blocks/Recommendation/controls/cardComposition/index.js +309 -236
  41. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +241 -180
  42. package/dist/extensions/Blocks/Recommendation/controls/main/strategy.js +124 -0
  43. package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +1 -0
  44. package/dist/extensions/Blocks/Recommendation/controls/title/index.js +44 -0
  45. package/dist/extensions/Blocks/Recommendation/extension.js +31 -29
  46. package/dist/extensions/Blocks/Recommendation/services/configService.js +54 -36
  47. package/dist/extensions/Blocks/Recommendation/settingsPanel.js +23 -4
  48. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +175 -79
  49. package/dist/extensions/Blocks/Recommendation/templates/grid/template.js +3 -3
  50. package/dist/extensions/Blocks/Recommendation/templates/titleRows.js +33 -0
  51. package/dist/extensions/Blocks/Recommendation/templates/utils.js +85 -107
  52. package/dist/extensions/Blocks/Recommendation/utils/nodeConfigWriter.js +22 -0
  53. package/dist/extensions/Blocks/Recommendation/utils/recommendationBlockCount.js +10 -6
  54. package/dist/extensions/Blocks/common-control.js +22 -19
  55. package/dist/guido.css +1 -1
  56. package/dist/services/recommendationApi.js +69 -30
  57. package/dist/src/@types/config/schemas.d.ts +2 -0
  58. package/dist/src/components/organisms/extensions/recommendation/AssignStrategyDrawer.vue.d.ts +3 -0
  59. package/dist/src/components/organisms/extensions/recommendation/RemoveStrategyModal.vue.d.ts +2 -0
  60. package/dist/src/components/organisms/extensions/recommendation/StrategyInfoBoxContent.vue.d.ts +15 -0
  61. package/dist/src/composables/useConfig.d.ts +2 -0
  62. package/dist/src/composables/useModuleRepair.d.ts +18 -0
  63. package/dist/src/composables/useRecommendation.d.ts +1 -0
  64. package/dist/src/composables/useSyncModuleExtractor.d.ts +2 -0
  65. package/dist/src/composables/validators/useSyncModuleBlockValidator.d.ts +3 -0
  66. package/dist/src/config/migrator/recommendation/extractors.d.ts +8 -0
  67. package/dist/src/config/migrator/recommendationTitleMigrator.d.ts +5 -0
  68. package/dist/src/enums/academy.d.ts +1 -0
  69. package/dist/src/enums/date.d.ts +1 -0
  70. package/dist/src/enums/extensions/recommendationBlock.d.ts +2 -0
  71. package/dist/src/extensions/Blocks/Items/block.d.ts +35 -0
  72. package/dist/src/extensions/Blocks/Items/constants/currency.d.ts +43 -0
  73. package/dist/src/extensions/Blocks/Items/utils/constants.d.ts +6 -0
  74. package/dist/src/extensions/Blocks/Recommendation/constants/blockIds.d.ts +2 -1
  75. package/dist/src/extensions/Blocks/Recommendation/constants/controlIds.d.ts +7 -0
  76. package/dist/src/extensions/Blocks/Recommendation/constants/defaultConfig.d.ts +3 -6
  77. package/dist/src/extensions/Blocks/Recommendation/constants/index.d.ts +2 -2
  78. package/dist/src/extensions/Blocks/Recommendation/constants/selectors.d.ts +12 -0
  79. package/dist/src/extensions/Blocks/Recommendation/controls/cardComposition/index.d.ts +11 -0
  80. package/dist/src/extensions/Blocks/Recommendation/controls/index.d.ts +1 -0
  81. package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +44 -8
  82. package/dist/src/extensions/Blocks/Recommendation/controls/main/strategy.d.ts +16 -0
  83. package/dist/src/extensions/Blocks/Recommendation/controls/main/utils.d.ts +1 -0
  84. package/dist/src/extensions/Blocks/Recommendation/controls/title/index.d.ts +86 -0
  85. package/dist/src/extensions/Blocks/Recommendation/services/configService.d.ts +12 -1
  86. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +176 -10
  87. package/dist/src/extensions/Blocks/Recommendation/templates/titleRows.d.ts +13 -0
  88. package/dist/src/extensions/Blocks/Recommendation/types/nodeConfig.d.ts +7 -0
  89. package/dist/src/extensions/Blocks/Recommendation/utils/nodeConfigWriter.d.ts +31 -0
  90. package/dist/src/extensions/Blocks/Recommendation/utils/recommendationBlockCount.d.ts +6 -2
  91. package/dist/src/extensions/Blocks/common-control.d.ts +4 -1
  92. package/dist/src/mock/api/recommendation-strategies.d.ts +2 -0
  93. package/dist/src/services/recommendationApi.d.ts +4 -1
  94. package/dist/src/stores/config.d.ts +18 -0
  95. package/dist/src/stores/save-as-template.d.ts +4 -3
  96. package/dist/src/utils/genericUtil.d.ts +5 -0
  97. package/dist/src/utils/itemsCurrencyRepair.d.ts +17 -0
  98. package/dist/static/assets/icons/line-change.svg.js +5 -0
  99. package/dist/static/assets/icons/line-delete.svg.js +5 -0
  100. package/dist/static/assets/icons/line-plus.svg.js +5 -0
  101. package/dist/static/styles/components/recommendation-strategy.css.js +155 -0
  102. package/dist/static/styles/customEditorStyle.css.js +3 -1
  103. package/dist/utils/dateUtil.js +23 -10
  104. package/dist/utils/genericUtil.js +28 -27
  105. package/dist/utils/itemsCurrencyRepair.js +39 -0
  106. package/dist/utils/pairProductVariables.js +58 -58
  107. package/dist/utils/templatePreparation.js +35 -34
  108. package/package.json +3 -2
  109. package/dist/composables/useModuleDynamicContentRepair.js +0 -37
  110. package/dist/src/composables/useModuleDynamicContentRepair.d.ts +0 -13
@@ -1,31 +1,37 @@
1
1
  import { BlockId as f } from "../../enums/block.js";
2
- import { useTemplateStore as b } from "../../stores/template.js";
3
- import { mapComposition as y } from "./recommendation/compositionMapper.js";
4
- import { extractCurrencyFromBlock as v, extractTitleText as C, extractCardBgColor as M, isPartnerManagedBlock as S } from "./recommendation/extractors.js";
2
+ import { DEFAULT_NODE_CONFIG as b } from "../../extensions/Blocks/Recommendation/constants/defaultConfig.js";
3
+ import { ATTR_RECOMMENDATION_TITLE as y } from "../../extensions/Blocks/Recommendation/constants/selectors.js";
4
+ import { useTemplateStore as T } from "../../stores/template.js";
5
+ import { mapComposition as v } from "./recommendation/compositionMapper.js";
6
+ import { extractCurrencyFromBlock as C, extractTitleText as M, hasVisibleTitle as R, extractCardBgColor as S, isPartnerManagedBlock as h } from "./recommendation/extractors.js";
5
7
  import { buildBlockHtml as w } from "./recommendation/htmlBuilder.js";
6
- import { parseRecommendationId as x, parseLegacyConfig as R } from "./recommendation/parseLegacyConfig.js";
7
- import { mapSettings as T } from "./recommendation/settingsMapper.js";
8
- const h = 'td[esd-dev-product-config][class*="ins-recommendation-v3-block-"]:not(.recommendation-block-v2), td.product-block[esd-handler-name*="EmailRecommendationV3"][esd-dev-product-config]:not(.recommendation-block-v2)';
9
- function B(i, t, a) {
10
- var d;
8
+ import { parseRecommendationId as x, parseLegacyConfig as E } from "./recommendation/parseLegacyConfig.js";
9
+ import { mapSettings as A } from "./recommendation/settingsMapper.js";
10
+ const H = 'td[esd-dev-product-config][class*="ins-recommendation-v3-block-"]:not(.recommendation-block-v2), td.product-block[esd-handler-name*="EmailRecommendationV3"][esd-dev-product-config]:not(.recommendation-block-v2)';
11
+ function B(n, t, a) {
12
+ var l;
11
13
  const o = x(t);
12
14
  if (o === null)
13
15
  return console.warn(
14
16
  "[RecommendationMigrator] Skipping block — missing/invalid `ins-recommendation-v3-campaign-id`"
15
17
  ), !1;
16
- const r = R(t);
18
+ const r = E(t);
17
19
  if (!r)
18
20
  return console.warn(
19
21
  `[RecommendationMigrator] Aborting block id=${o} — \`esd-dev-product-config\` missing or unable to be parsed`
20
22
  ), !1;
21
- const n = a[String(o)] ?? {
22
- currencySettings: v(t)
23
- }, c = T(n, r, o), e = y((d = r.composition) == null ? void 0 : d.variables), l = C(t), g = M(t), p = {
23
+ const i = a[String(o)] ?? {
24
+ currencySettings: C(t)
25
+ }, c = A(i, r, o), e = v((l = r.composition) == null ? void 0 : l.variables), d = M(t);
26
+ e.titleVariable || (e.visibility[y] = R(t));
27
+ const p = S(t), g = {
24
28
  ...c,
29
+ strategyId: "",
25
30
  composition: e.composition,
26
31
  visibility: e.visibility,
32
+ previousTitleHtml: b.previousTitleHtml,
27
33
  textTrimming: e.anyTextTrimming
28
- }, m = S(t), u = `
34
+ }, m = h(t), u = `
29
35
  <table>
30
36
  <tbody>
31
37
  <tr>
@@ -33,10 +39,10 @@ function B(i, t, a) {
33
39
  <table width="100%" cellpadding="0" cellspacing="0">
34
40
  <tbody>
35
41
  <tr>${w({
36
- nodeConfig: p,
42
+ nodeConfig: g,
37
43
  composition: e,
38
- cardBg: g,
39
- titleText: l,
44
+ cardBg: p,
45
+ titleText: d,
40
46
  legacyId: t.getAttribute("id") ?? void 0,
41
47
  legacyBgColor: t.getAttribute("bgcolor") ?? void 0,
42
48
  preserveInnerHtml: m ? t.innerHTML : void 0,
@@ -48,15 +54,15 @@ function B(i, t, a) {
48
54
  </tr>
49
55
  </tbody>
50
56
  </table>
51
- `, s = i.parseFromString(u, "text/html").querySelector("td.esd-structure");
57
+ `, s = n.parseFromString(u, "text/html").querySelector("td.esd-structure");
52
58
  return !s || !t.parentNode ? (console.warn(
53
59
  `[RecommendationMigrator] Aborting block id=${o} — failed to construct new HTML element`
54
60
  ), !1) : (t.parentNode.replaceChild(s, t), !0);
55
61
  }
56
- function q(i, t = {}) {
57
- const a = new DOMParser(), o = a.parseFromString(i, "text/html"), r = Array.from(o.querySelectorAll(h));
62
+ function G(n, t = {}) {
63
+ const a = new DOMParser(), o = a.parseFromString(n, "text/html"), r = Array.from(o.querySelectorAll(H));
58
64
  try {
59
- b().$patch((e) => {
65
+ T().$patch((e) => {
60
66
  e.migrations = {
61
67
  ...e.migrations,
62
68
  [f.Recommendation]: r.length
@@ -65,16 +71,16 @@ function q(i, t = {}) {
65
71
  } catch {
66
72
  }
67
73
  if (r.length === 0)
68
- return i;
69
- let n = 0;
74
+ return n;
75
+ let i = 0;
70
76
  return r.forEach((c) => {
71
77
  try {
72
- B(a, c, t) && (n += 1);
78
+ B(a, c, t) && (i += 1);
73
79
  } catch (e) {
74
80
  console.error("[RecommendationMigrator] Unexpected error migrating block:", e);
75
81
  }
76
- }), n > 0 && console.info(`[RecommendationMigrator] Migrated ${n} legacy Recommendation block(s)`), o.documentElement.outerHTML;
82
+ }), i > 0 && console.info(`[RecommendationMigrator] Migrated ${i} legacy Recommendation block(s)`), o.documentElement.outerHTML;
77
83
  }
78
84
  export {
79
- q as migrateRecommendation
85
+ G as migrateRecommendation
80
86
  };
@@ -0,0 +1,119 @@
1
+ var R = Object.defineProperty;
2
+ var f = (s, t, e) => t in s ? R(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var a = (s, t, e) => f(s, typeof t != "symbol" ? t + "" : t, e);
4
+ import { RecommendationBlockId as d } from "../../extensions/Blocks/Recommendation/constants/blockIds.js";
5
+ import { BLOCK_ROOT_SELECTOR as u, CSS_CLASS_SKIP_COMPILE as m, ATTR_DATA_ATTRIBUTE_TYPE as S, ATTR_RECOMMENDATION_TITLE as l, CONTAINER_SELECTOR as E, CSS_CLASS_TITLE_CELL as c, CSS_CLASS_SPACER as C, CSS_CLASS_ATTRIBUTE_ROW as A, ATTR_DATA_VISIBILITY as L } from "../../extensions/Blocks/Recommendation/constants/selectors.js";
6
+ const p = u.slice(1), g = `${u}:not(.${m})`, O = `[${S}="${l}"]`, h = "td.esd-block-text", _ = "table.container > tbody", T = "esd-ext-config";
7
+ class y {
8
+ constructor() {
9
+ a(this, "parser");
10
+ this.parser = new DOMParser();
11
+ }
12
+ migrate(t) {
13
+ try {
14
+ if (!t.includes(p))
15
+ return t;
16
+ const e = this.parser.parseFromString(t, "text/html");
17
+ return Array.from(e.querySelectorAll(g)).reduce(
18
+ (n, o) => this._migrateBlock(o) || n,
19
+ !1
20
+ ) ? e.documentElement.outerHTML : t;
21
+ } catch (e) {
22
+ return console.error("RecommendationTitleMigrator failed:", e), t;
23
+ }
24
+ }
25
+ /** Migrates one block. Returns `true` when the block was changed. */
26
+ _migrateBlock(t) {
27
+ if (t.querySelector(O) || this._hasRecordedTitleState(t))
28
+ return !1;
29
+ const e = this._findTitleCell(t), i = e !== null && (e.textContent ?? "").trim().length > 0;
30
+ return i ? this._tagExistingTitle(t, e) : this._removeTitleRemnants(t, e), this._writeVisibility(t, i), !0;
31
+ }
32
+ /** The only `esd-block-text` cell outside the product containers is the title. */
33
+ _findTitleCell(t) {
34
+ return Array.from(t.querySelectorAll(h)).find((e) => !e.closest(E) && this._isTitlePosition(t, e)) ?? null;
35
+ }
36
+ _isTitlePosition(t, e) {
37
+ var r;
38
+ const i = this._wrapperRowOf(t, e);
39
+ return e.classList.contains(c) || i !== null && i === ((r = i.parentElement) == null ? void 0 : r.firstElementChild);
40
+ }
41
+ /**
42
+ * Stamps the attribute-row tagging onto the title's wrapper row and the spacer
43
+ * below it, so one toggle governs the pair and the compiler drops both when off.
44
+ */
45
+ _tagExistingTitle(t, e) {
46
+ e.classList.add(c), e.setAttribute("esd-extension-block-id", d.TITLE);
47
+ const i = this._wrapperRowOf(t, e);
48
+ if (!i)
49
+ return;
50
+ this._tagRow(i);
51
+ const r = i.nextElementSibling;
52
+ r && this._isSpacerRow(r) && this._tagRow(r);
53
+ }
54
+ /** The `<tr>` inside `table.container > tbody` that wraps the title's own table. */
55
+ _wrapperRowOf(t, e) {
56
+ if (!e)
57
+ return null;
58
+ const i = t.querySelector(_);
59
+ return Array.from((i == null ? void 0 : i.children) ?? []).find((r) => r.contains(e)) ?? null;
60
+ }
61
+ /**
62
+ * Direct children only — a product-container row holds spacer cells further down,
63
+ * and `querySelector` would happily reach them. (`:scope >` is unsupported in happy-dom.)
64
+ */
65
+ _isSpacerRow(t) {
66
+ return Array.from(t.children).some((e) => e.classList.contains(C));
67
+ }
68
+ _tagRow(t) {
69
+ t.classList.add(A), t.setAttribute(S, l), t.setAttribute(L, "1");
70
+ }
71
+ /**
72
+ * A deleted title leaves nothing to tag — the toggle re-injects the markup only
73
+ * when the user switches it back on. Its leftovers (an emptied wrapper row, the
74
+ * spacer that trailed it) would otherwise render as blank padding on top.
75
+ */
76
+ _removeTitleRemnants(t, e) {
77
+ var o;
78
+ const i = this._wrapperRowOf(t, e), r = i == null ? void 0 : i.nextElementSibling;
79
+ if (r && this._isSpacerRow(r) && r.remove(), i) {
80
+ i.remove();
81
+ return;
82
+ }
83
+ const n = (o = t.querySelector(_)) == null ? void 0 : o.firstElementChild;
84
+ n && this._isSpacerRow(n) && n.remove();
85
+ }
86
+ /**
87
+ * Mirrors the resolved state into the persisted config blob, so a saved module
88
+ * whose `data-*` attributes Stripo strips on re-drop still restores the toggle.
89
+ */
90
+ _writeVisibility(t, e) {
91
+ const i = this._readConfig(t);
92
+ if (!i)
93
+ return;
94
+ const r = typeof i.visibility == "object" && i.visibility !== null ? i.visibility : {};
95
+ i.visibility = { ...r, [l]: e }, t.setAttribute(T, JSON.stringify(i));
96
+ }
97
+ _hasRecordedTitleState(t) {
98
+ var i;
99
+ const e = (i = this._readConfig(t)) == null ? void 0 : i.visibility;
100
+ return typeof e == "object" && e !== null && l in e;
101
+ }
102
+ _readConfig(t) {
103
+ const e = t.getAttribute(T);
104
+ if (!e)
105
+ return null;
106
+ try {
107
+ const i = JSON.parse(e);
108
+ return typeof i == "object" && i !== null ? i : null;
109
+ } catch {
110
+ return null;
111
+ }
112
+ }
113
+ }
114
+ function v(s) {
115
+ return new y().migrate(s);
116
+ }
117
+ export {
118
+ v as migrateRecommendationTitle
119
+ };
@@ -1,7 +1,8 @@
1
1
  const e = "https://academy.insiderone.com", o = {
2
2
  EMAIL_EDITOR: `${e}/docs/email-drag-and-drop-editor`,
3
3
  GLOBAL_UNSUBSCRIBE: `${e}/docs/global-unsubscribe-preference-center`,
4
- AMP_FOR_EMAILS: `${e}/docs/amp-for-emails`
4
+ AMP_FOR_EMAILS: `${e}/docs/amp-for-emails`,
5
+ EMAIL_RECOMMENDATION_BLOCK: `${e}/docs/new-editor-email-recommendation-block`
5
6
  };
6
7
  export {
7
8
  o as ACADEMY_LINKS
@@ -1,5 +1,7 @@
1
- const t = "tr-TR", L = "default";
1
+ const T = "tr-TR", t = "tr-TR", E = "default", L = "UTC";
2
2
  export {
3
- L as DEFAULT,
4
- t as DEFAULT_LOCALE
3
+ E as DEFAULT,
4
+ T as DEFAULT_LOCALE,
5
+ L as DEFAULT_TZ,
6
+ t as DOTTED_DATE_LOCALE
5
7
  };
@@ -2,7 +2,9 @@ import { useTranslations as r } from "../../composables/useTranslations.js";
2
2
  const l = {
3
3
  RECOMMENDATION_API_URL: "https://recommendationv2.api.useinsider.com",
4
4
  // Relative path → same-origin as the embedding inone dashboard.
5
- PRODUCT_ATTRIBUTES_PATH: "/product-attributes/get-attributes"
5
+ PRODUCT_ATTRIBUTES_PATH: "/product-attributes/get-attributes",
6
+ RECOMMENDATION_STRATEGIES_PATH: "/api/recommendation-strategies",
7
+ RECOMMENDATION_STRATEGIES_PANEL_PATH: "/discovery/recommendation-strategies"
6
8
  }, c = {
7
9
  CLIENT_ID: "clientId"
8
10
  }, d = () => {
@@ -1,20 +1,32 @@
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 k = Object.defineProperty;
2
+ var D = (l, a, t) => a in l ? k(l, a, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[a] = t;
3
+ var y = (l, a, t) => D(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 S } from "../../../utils/migrationBannerHtml.js";
7
+ import { Block as A, BlockCompositionType as M, ModificationDescription as u } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
8
+ import { currencyAttrTargets as H, ITEMS_CURRENCY_ATTR as m } from "./constants/currency.js";
9
+ import { ItemsBlockId as R } from "./enums/controlEnums.js";
10
+ import { SETTINGS_ENUMS as C, DefaultConfigValues as g } from "./enums/settingsEnums.js";
11
+ import { getDefaultTemplate as O } from "./template.js";
12
+ import { getItemsBlockContainer as b, getItemsBlockConfig as h, deriveItemNumber as B, generateBlockInstanceId as E, getDefaultItemsBlockConfig as w } from "./utils/nodeConfigUtils.js";
13
+ const _ = N.Items, P = "Reconcile Items currency DOM attributes";
14
+ class K extends A {
15
+ constructor() {
16
+ super(...arguments);
17
+ /** Block instances whose currency attrs were already self-healed this session (SD-147588 — undo-safe). */
18
+ y(this, "_currencyHealed", /* @__PURE__ */ new Set());
19
+ /** blockInstanceIds already claimed by a live block this session (SD-147588 collision detection). */
20
+ y(this, "_seenInstanceIds", /* @__PURE__ */ new Set());
21
+ }
10
22
  getId() {
11
- return p;
23
+ return _;
12
24
  }
13
25
  getIcon() {
14
26
  return "items-icon";
15
27
  }
16
28
  getBlockCompositionType() {
17
- return b.CONTAINER;
29
+ return M.CONTAINER;
18
30
  }
19
31
  getName() {
20
32
  return this.api.translate("Items");
@@ -23,20 +35,20 @@ class E extends C {
23
35
  return this.api.translate("Items lets you display personalized products based on user behavior.");
24
36
  }
25
37
  getSettingsPanelTitleHtml() {
26
- return I(
27
- p,
38
+ return S(
39
+ _,
28
40
  this.api.translate("Items"),
29
41
  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
42
  );
31
43
  }
32
44
  getTemplate() {
33
- return h({
34
- orientation: l.ORIENTATION.VERTICAL,
35
- itemsType: l.ITEMS_TYPE.CART_ITEMS,
45
+ return O({
46
+ orientation: C.ORIENTATION.VERTICAL,
47
+ itemsType: C.ITEMS_TYPE.CART_ITEMS,
36
48
  itemId: "{{Abandoned Cart Item (1) Url}}",
37
- currencySymbol: d.productPriceCurrencySymbolControlValue,
38
- currencyLocation: d.productPriceCurrencyLocationControlValue,
39
- formattedPrice: d.productPriceFormattedControlValue === "1"
49
+ currencySymbol: g.productPriceCurrencySymbolControlValue,
50
+ currencyLocation: g.productPriceCurrencyLocationControlValue,
51
+ formattedPrice: g.productPriceFormattedControlValue === "1"
40
52
  });
41
53
  }
42
54
  allowInnerBlocksDND() {
@@ -45,24 +57,27 @@ class E extends C {
45
57
  canBeSavedAsModule() {
46
58
  return !0;
47
59
  }
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)
60
+ onCreated(t) {
61
+ const o = this.api.getDocumentModifier(), c = this.api.getDocumentRootCssNode();
62
+ c.querySelector('[product-attr="imageSrc"] img') || o.modifyCss(c).appendRule('[product-attr="imageSrc"] img {object-fit: contain;}');
63
+ const i = b(t);
64
+ if (!i)
53
65
  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"));
66
+ const r = i.getNodeConfig(), s = r && Object.keys(r).length > 0, e = h(t);
67
+ if (e != null && e.initialized) {
68
+ if (!s) {
69
+ const d = this.api.getDocumentModifier();
70
+ d.modifyHtml(i).setNodeConfig(e), this._stampProductTdDomAttributes(i, e, d), this._shouldReconcileCurrency(e) && this._reconcileCurrencyDomAttributes(i, e, d), d.apply(new u("Migrate legacy config to nodeConfig")), this._markCurrencyHealed(e.blockInstanceId);
71
+ return;
61
72
  }
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");
73
+ } else {
74
+ const d = w(), p = this.api.getDocumentModifier();
75
+ p.modifyHtml(i).setNodeConfig(d), this._stampProductTdDomAttributes(i, d, p, !0), p.apply(new u("Initialize Items block with default configuration")), T().startOnboarding("itemsOnboarding");
76
+ return;
65
77
  }
78
+ const n = this._resolveInstanceId(e.blockInstanceId), f = this.api.getDocumentModifier();
79
+ let I = !1;
80
+ n !== e.blockInstanceId && (f.modifyHtml(i).setNodeConfig({ ...e, blockInstanceId: n }), I = !0), !this._currencyHealed.has(n) && this._reconcileCurrencyDomAttributes(i, e, f) && (I = !0), I && f.apply(new u("Assign Items block instance ID and reconcile currency")), this._markCurrencyHealed(n);
66
81
  }
67
82
  /**
68
83
  * Re-seeds nodeConfig from the persisted esd-ext-config when a saved module
@@ -70,18 +85,24 @@ class E extends C {
70
85
  * into nodeConfig, so without this a reused module would reset to defaults.
71
86
  * Guarded to the nodeConfig-empty case so it runs once and never loops.
72
87
  */
73
- onDocumentChanged(n) {
74
- const t = u(n);
75
- if (!t)
88
+ onDocumentChanged(t) {
89
+ const o = b(t);
90
+ if (!o)
76
91
  return;
77
- const a = t.getNodeConfig();
78
- if (a && Object.keys(a).length > 0)
92
+ const c = o.getNodeConfig();
93
+ if (c && Object.keys(c).length > 0) {
94
+ const e = h(t);
95
+ if (e != null && e.initialized && this._shouldReconcileCurrency(e)) {
96
+ const n = this.api.getDocumentModifier();
97
+ this._reconcileCurrencyDomAttributes(o, e, n) && n.apply(new u(P)), this._markCurrencyHealed(e.blockInstanceId);
98
+ }
79
99
  return;
80
- const o = f(n);
81
- if (!(o != null && o.initialized))
100
+ }
101
+ const r = h(t);
102
+ if (!(r != null && r.initialized))
82
103
  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"));
104
+ const s = this.api.getDocumentModifier();
105
+ s.modifyHtml(o).setNodeConfig(r), this._stampProductTdDomAttributes(o, r, s), this._shouldReconcileCurrency(r) && this._reconcileCurrencyDomAttributes(o, r, s), s.apply(new u("Recover Items block config from saved module")), this._markCurrencyHealed(r.blockInstanceId);
85
106
  }
86
107
  /**
87
108
  * Bakes the compiler-read DOM attributes (`data-type`, `data-number`, `data-nodup`) onto the
@@ -91,14 +112,62 @@ class E extends C {
91
112
  * restored before export. The name `<a>` carries no data-type/data-number of its own and
92
113
  * relies on this td-level fallback in pairProductVariables.
93
114
  */
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);
115
+ _stampProductTdDomAttributes(t, o, c, i = !1) {
116
+ const r = B(o.itemsSelectValue, o.type), s = (e, n) => {
117
+ i && t.getAttribute(e) || c.modifyHtml(t).setAttribute(e, n);
97
118
  };
98
- r("data-type", t.type), r("data-number", o), r("data-nodup", String(t.priceHideDiscount));
119
+ s("data-type", o.type), s("data-number", r), s("data-nodup", String(o.priceHideDiscount));
120
+ }
121
+ /**
122
+ * Whether a currency self-heal pass should run for this block (SD-147588). The only gate here is
123
+ * once-per-session: heal each instance at most once, so the auto-fix can't fight undo (undo
124
+ * re-drifts the attr, which would otherwise re-trigger the heal forever). The position-vs-symbol
125
+ * authority split lives in `_reconcileCurrencyDomAttributes` — position is always authoritative,
126
+ * the symbol write alone is skipped for the 'USD' sentinel — so we must NOT gate the whole pass
127
+ * on symbol customization here, or a default-symbol block with a toggled location never heals.
128
+ */
129
+ _shouldReconcileCurrency(t) {
130
+ return !t.blockInstanceId || !this._currencyHealed.has(t.blockInstanceId);
131
+ }
132
+ /** Marks a block instance's currency as reconciled so it is not healed again (undo-safe). */
133
+ _markCurrencyHealed(t) {
134
+ t && this._currencyHealed.add(t);
135
+ }
136
+ /**
137
+ * Resolves the id for a just-created block to one that is unique per live instance.
138
+ * A saved module serializes its blockInstanceId, so every re-drop of the same module
139
+ * arrives with an id already owned by a live instance — reusing it collides both the
140
+ * currency heal guard and settings-panel switch detection. Mint a fresh id on absence
141
+ * or collision, otherwise keep the existing one. Registers the result as claimed.
142
+ */
143
+ _resolveInstanceId(t) {
144
+ let o = t;
145
+ if (!o || this._seenInstanceIds.has(o))
146
+ do
147
+ o = E();
148
+ while (this._seenInstanceIds.has(o));
149
+ return this._seenInstanceIds.add(o), o;
150
+ }
151
+ /**
152
+ * Stamps the export-read currency attrs onto every price `<p>` from config, so a template whose
153
+ * attrs drifted (e.g. a location toggle before the sync fix) self-heals to match the editor.
154
+ * Config is the source of truth — never derive from visible text.
155
+ *
156
+ * Authority split lives in `currencyAttrTargets` (SD-147588) — position only when a location
157
+ * is recorded, symbol only when customized — so this heal and the module-drop repair can't drift.
158
+ *
159
+ * Returns true only when an attr actually changed, so the caller can skip an empty apply that
160
+ * would otherwise re-trigger onDocumentChanged and loop.
161
+ */
162
+ _reconcileCurrencyDomAttributes(t, o, c) {
163
+ const { position: i, symbol: r } = H(o), s = t.querySelectorAll(`.${R.PRICE} p`);
164
+ let e = !1;
165
+ return s.forEach((n) => {
166
+ i !== void 0 && n.getAttribute(m.POSITION) !== i && (c.modifyHtml(n).setAttribute(m.POSITION, i), e = !0), r !== void 0 && n.getAttribute(m.SYMBOL) !== r && (c.modifyHtml(n).setAttribute(m.SYMBOL, r), e = !0);
167
+ }), e;
99
168
  }
100
169
  }
101
170
  export {
102
- p as BLOCK_ID,
103
- E as ItemsBlock
171
+ _ as BLOCK_ID,
172
+ K as ItemsBlock
104
173
  };
@@ -0,0 +1,25 @@
1
+ import { DefaultConfigValues as c } from "../enums/settingsEnums.js";
2
+ const s = {
3
+ POSITION: "data-curency",
4
+ SYMBOL: "data-currency_symbol"
5
+ };
6
+ function e(r) {
7
+ return r === "1" ? "after" : "before";
8
+ }
9
+ function i(r) {
10
+ const o = (r ?? "").trim();
11
+ return o !== "" && o !== c.productPriceCurrencySymbolControlValue;
12
+ }
13
+ function a(r) {
14
+ const o = r.priceCurrencyLocation, n = typeof o == "string" && o.trim() !== "", t = (r.priceCurrencySymbol ?? "").trim();
15
+ return {
16
+ position: n ? e(o) : void 0,
17
+ symbol: i(t) ? t : void 0
18
+ };
19
+ }
20
+ export {
21
+ s as ITEMS_CURRENCY_ATTR,
22
+ a as currencyAttrTargets,
23
+ e as currencyPositionFromLocation,
24
+ i as isCustomCurrencySymbol
25
+ };
@@ -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
  };