@useinsider/guido 3.24.0 → 3.25.0-beta.2954d1a

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 (68) hide show
  1. package/README.md +7 -1
  2. package/dist/@types/config/schemas.js +9 -7
  3. package/dist/components/Guido.vue.js +1 -1
  4. package/dist/components/Guido.vue2.js +79 -77
  5. package/dist/composables/useActionsApi.js +2 -2
  6. package/dist/composables/useEditorTrackingIds.js +49 -0
  7. package/dist/composables/useHtmlCompiler.js +2 -0
  8. package/dist/composables/useModuleRepair.js +14 -12
  9. package/dist/composables/useStripo.js +70 -70
  10. package/dist/config/compiler/htmlCompilerRules.js +14 -6
  11. package/dist/config/migrator/index.js +16 -15
  12. package/dist/config/migrator/itemsPriceFormatMigrator.js +20 -0
  13. package/dist/config/migrator/recommendation/inferLegacyConfig.js +133 -0
  14. package/dist/config/migrator/recommendationMigrator.js +78 -64
  15. package/dist/extensions/Blocks/Items/block.js +115 -77
  16. package/dist/extensions/Blocks/Items/constants/currency.js +59 -14
  17. package/dist/extensions/Blocks/Items/controls/blockBackground/index.js +11 -0
  18. package/dist/extensions/Blocks/Items/controls/price/currencyLocation.js +34 -23
  19. package/dist/extensions/Blocks/Items/controls/price/currencySymbol.js +62 -51
  20. package/dist/extensions/Blocks/Items/controls/price/formattedPrice.js +18 -17
  21. package/dist/extensions/Blocks/Items/controls/price/singlePrice.js +42 -31
  22. package/dist/extensions/Blocks/Items/controls/priceFormat.js +135 -0
  23. package/dist/extensions/Blocks/Items/controls/settingsControl.js +141 -120
  24. package/dist/extensions/Blocks/Items/enums/controlEnums.js +2 -2
  25. package/dist/extensions/Blocks/Items/extension.js +15 -13
  26. package/dist/extensions/Blocks/Items/items.css.js +19 -0
  27. package/dist/extensions/Blocks/Items/settingsPanel.js +35 -25
  28. package/dist/extensions/Blocks/Items/template.js +250 -212
  29. package/dist/extensions/Blocks/Items/utils/priceFormatOps.js +185 -0
  30. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +10 -8
  31. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +28 -24
  32. package/dist/extensions/Blocks/Recommendation/utils/nodeConfigWriter.js +23 -22
  33. package/dist/extensions/Blocks/Recommendation/utils/priceFormatter.js +1 -0
  34. package/dist/extensions/Blocks/controlFactories.js +104 -104
  35. package/dist/guido.css +1 -1
  36. package/dist/package.json.js +2 -2
  37. package/dist/services/templateLibraryApi.js +39 -36
  38. package/dist/src/@types/config/schemas.d.ts +4 -0
  39. package/dist/src/composables/useConfig.d.ts +2 -0
  40. package/dist/src/composables/useEditorTrackingIds.d.ts +7 -0
  41. package/dist/src/composables/useStripo.d.ts +1 -1
  42. package/dist/src/config/migrator/index.d.ts +4 -1
  43. package/dist/src/config/migrator/itemsPriceFormatMigrator.d.ts +1 -0
  44. package/dist/src/config/migrator/recommendation/inferLegacyConfig.d.ts +6 -0
  45. package/dist/src/config/migrator/recommendation/parseLegacyConfig.d.ts +1 -1
  46. package/dist/src/config/migrator/recommendationMigrator.d.ts +1 -5
  47. package/dist/src/extensions/Blocks/Items/block.d.ts +6 -9
  48. package/dist/src/extensions/Blocks/Items/constants/currency.d.ts +32 -0
  49. package/dist/src/extensions/Blocks/Items/controls/blockBackground/index.d.ts +15 -0
  50. package/dist/src/extensions/Blocks/Items/controls/priceFormat.d.ts +24 -0
  51. package/dist/src/extensions/Blocks/Items/controls/settingsControl.d.ts +1 -0
  52. package/dist/src/extensions/Blocks/Items/enums/controlEnums.d.ts +2 -0
  53. package/dist/src/extensions/Blocks/Items/template.d.ts +4 -1
  54. package/dist/src/extensions/Blocks/Items/utils/nodeConfigUtils.d.ts +3 -0
  55. package/dist/src/extensions/Blocks/Items/utils/priceFormatOps.d.ts +66 -0
  56. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +2 -0
  57. package/dist/src/extensions/Blocks/Recommendation/utils/priceFormatter.d.ts +12 -0
  58. package/dist/src/extensions/Blocks/controlFactories.d.ts +1 -1
  59. package/dist/src/stores/config.d.ts +20 -0
  60. package/dist/src/utils/itemsCurrencyRepair.d.ts +5 -1
  61. package/dist/src/utils/linkTrackingIds.d.ts +19 -0
  62. package/dist/src/utils/trimHrefWhitespace.d.ts +5 -0
  63. package/dist/utils/itemsCurrencyRepair.js +29 -24
  64. package/dist/utils/linkTrackingIds.js +82 -48
  65. package/dist/utils/pairProductVariables.js +119 -99
  66. package/dist/utils/templatePreparation.js +30 -33
  67. package/dist/utils/trimHrefWhitespace.js +10 -0
  68. package/package.json +1 -1
@@ -1,54 +1,54 @@
1
- import { useActionsApi as M } from "./useActionsApi.js";
2
- import { useBlocksConfig as N } from "./useBlocksConfig.js";
3
- import { useConfig as j } from "./useConfig.js";
4
- import { useCustomInterfaceAppearance as _ } from "./useCustomInterfaceAppearance.js";
5
- import { useFullStoryBridge as z } from "./useFullStoryBridge.js";
6
- import { useModuleRepair as $ } from "./useModuleRepair.js";
7
- import { useStripoEventHandler as G } from "./useStripoEventHandler.js";
8
- import { useStripoNotifications as X } from "./useStripoNotifications.js";
9
- import { useToaster as J } from "./useToaster.js";
10
- import { localePatch as K } from "../config/i18n/index.js";
1
+ import { useActionsApi as N } from "./useActionsApi.js";
2
+ import { useBlocksConfig as j } from "./useBlocksConfig.js";
3
+ import { useConfig as z } from "./useConfig.js";
4
+ import { useCustomInterfaceAppearance as v } from "./useCustomInterfaceAppearance.js";
5
+ import { useFullStoryBridge as $ } from "./useFullStoryBridge.js";
6
+ import { useModuleRepair as G } from "./useModuleRepair.js";
7
+ import { useStripoEventHandler as X } from "./useStripoEventHandler.js";
8
+ import { useStripoNotifications as J } from "./useStripoNotifications.js";
9
+ import { useToaster as K } from "./useToaster.js";
10
+ import { localePatch as Q } from "../config/i18n/index.js";
11
11
  import { en as B } from "../config/i18n/en/index.js";
12
- import { ToasterTypeOptions as Q } from "../enums/toaster.js";
13
- import { useStripoApi as W } from "../services/stripoApi.js";
14
- import Y from "../static/styles/customEditorStyle.css.js";
15
- import { useEditorStore as v } from "../stores/editor.js";
16
- import { buildMergeTagEntries as Z, flattenDynamicContentList as ee } from "../utils/genericUtil.js";
17
- import { getStripoRuntimeBaseUrl as te } from "../utils/stripoRuntime.js";
18
- let d = null, T = !1;
19
- const we = (e) => {
20
- const { features: u, template: m, isFeatureEnabled: p } = j(), { handleError: f, showToaster: F } = J(), { getToken: A, getCustomFonts: P, getSyncModulesStatus: R } = W(), { handleEvent: U } = G(), { handleModuleAdd: V } = $(), { getStripoBlocksConfig: D } = N(), { getStripoNotifications: I } = X(), g = () => d || (d = new Promise((a, s) => {
12
+ import { ToasterTypeOptions as W } from "../enums/toaster.js";
13
+ import { useStripoApi as Y } from "../services/stripoApi.js";
14
+ import Z from "../static/styles/customEditorStyle.css.js";
15
+ import { useEditorStore as T } from "../stores/editor.js";
16
+ import { buildMergeTagEntries as ee, flattenDynamicContentList as te } from "../utils/genericUtil.js";
17
+ import { getStripoRuntimeBaseUrl as oe } from "../utils/stripoRuntime.js";
18
+ let d = null, F = !1;
19
+ const ke = (t) => {
20
+ const { features: u, template: m, isFeatureEnabled: p } = z(), { handleError: f, showToaster: A } = K(), { getToken: P, getCustomFonts: R, getSyncModulesStatus: U } = Y(), { handleEvent: V } = X(), { handleModuleAdd: D } = G(), { getStripoBlocksConfig: I } = j(), { getStripoNotifications: L } = J(), g = () => d || (d = new Promise((n, a) => {
21
21
  if (document.getElementById("UiEditorScript")) {
22
- a();
22
+ n();
23
23
  return;
24
24
  }
25
- const i = te();
25
+ const i = oe();
26
26
  if (!i) {
27
- s(
27
+ a(
28
28
  new Error("guido.stripo.version is not set in package.json. Please configure the Stripo version.")
29
29
  );
30
30
  return;
31
31
  }
32
- const n = `${i}UIEditor.js`, t = document.createElement("script");
33
- t.id = "UiEditorScript", t.type = "module", t.src = n, t.onload = () => {
34
- T = !0, a();
35
- }, t.onerror = () => {
36
- t.remove(), s(new Error(`Failed to load Stripo UIEditor script from S3: ${n}`));
37
- }, document.body.appendChild(t);
32
+ const s = `${i}UIEditor.js`, e = document.createElement("script");
33
+ e.id = "UiEditorScript", e.type = "module", e.src = s, e.onload = () => {
34
+ F = !0, n();
35
+ }, e.onerror = () => {
36
+ e.remove(), a(new Error(`Failed to load Stripo UIEditor script from S3: ${s}`));
37
+ }, document.body.appendChild(e);
38
38
  }), d.catch(() => {
39
39
  d = null;
40
- }), d), L = async (a, s, i, n = [], t = !1) => {
41
- var C, w, k, b;
42
- const o = v(), { html: c, css: S } = a, { baseBlocks: y, extensions: q } = await D();
43
- e.mark("blocks_config_ready");
44
- const E = ((C = u.value) == null ? void 0 : C.displayConditions) ?? !0, x = ((w = u.value) == null ? void 0 : w.modulesDisabled) ?? !1, h = !!c || (((k = m.value) == null ? void 0 : k.forceRecreate) ?? !1), O = "https://email-static.useinsider.com https://edge.fullstory.com https://rs.fullstory.com";
45
- e.setTemplate({ html: c, css: S, forceRecreate: h }), _().importCss(), e.mark("init_editor"), await window.UIEditor.initEditor(
40
+ }), d), q = async (n, a, i, s = [], e = !1, c = !1) => {
41
+ var w, k, b, _;
42
+ const o = T(), { html: S, css: y } = n, { baseBlocks: E, extensions: x } = await I();
43
+ t.mark("blocks_config_ready");
44
+ const h = ((w = u.value) == null ? void 0 : w.displayConditions) ?? !0, O = ((k = u.value) == null ? void 0 : k.modulesDisabled) ?? !1, C = c || (((b = m.value) == null ? void 0 : b.forceRecreate) ?? !1), H = "https://email-static.useinsider.com https://edge.fullstory.com https://rs.fullstory.com";
45
+ t.setTemplate({ html: S, css: y, forceRecreate: C }), v().importCss(), t.mark("init_editor"), await window.UIEditor.initEditor(
46
46
  document.querySelector("#guido-editor"),
47
47
  {
48
- metadata: s,
49
- html: c,
50
- css: S,
51
- forceRecreate: h,
48
+ metadata: a,
49
+ html: S,
50
+ css: y,
51
+ forceRecreate: C,
52
52
  locale: "en",
53
53
  undoButtonSelector: "#guido__undo-button",
54
54
  redoButtonSelector: "#guido__redo-button",
@@ -58,12 +58,12 @@ const we = (e) => {
58
58
  customAppearanceMergetags: !p("liquidSyntax"),
59
59
  customAppearanceMergetagsBorderColor: "#f1f3fe",
60
60
  customAppearanceMergetagsBackgroundColor: "#f1f3fe",
61
- customViewStyles: Y,
62
- conditionsEnabled: E,
63
- customConditionsEnabled: E,
61
+ customViewStyles: Z,
62
+ conditionsEnabled: h,
63
+ customConditionsEnabled: h,
64
64
  enableXSSSecurity: !0,
65
- modulesDisabled: x,
66
- syncModulesEnabled: t,
65
+ modulesDisabled: O,
66
+ syncModulesEnabled: e,
67
67
  messageSettingsEnabled: !0,
68
68
  displayGmailAnnotations: !0,
69
69
  displayHiddenPreheader: !1,
@@ -73,37 +73,37 @@ const we = (e) => {
73
73
  copyPasteEnabled: !1,
74
74
  selectElementAfterDrop: !0,
75
75
  sameFontSizeForOutlook: !0,
76
- allowedScriptSourceDomains: O,
77
- ...y ? { baseBlocks: y } : {},
76
+ allowedScriptSourceDomains: H,
77
+ ...E ? { baseBlocks: E } : {},
78
78
  editorFonts: {
79
79
  showDefaultStandardFonts: !0,
80
80
  showDefaultNotStandardFonts: !0,
81
- customFonts: n
81
+ customFonts: s
82
82
  },
83
83
  mergeTags: [
84
84
  {
85
- entries: Z(
85
+ entries: ee(
86
86
  i.preselectedDynamicContentList,
87
- ee((b = m.value) == null ? void 0 : b.dynamicContentList),
87
+ te((_ = m.value) == null ? void 0 : _.dynamicContentList),
88
88
  p("liquidSyntax")
89
89
  )
90
90
  }
91
91
  ],
92
92
  async onTokenRefreshRequest(r) {
93
93
  try {
94
- e.mark("token_start");
95
- const l = await A();
96
- e.mark("token_end"), r(l);
94
+ t.mark("token_start");
95
+ const l = await P();
96
+ t.mark("token_end"), r(l);
97
97
  } catch (l) {
98
98
  f(l, "Failed to refresh token");
99
99
  }
100
100
  },
101
101
  onTemplateLoaded() {
102
102
  try {
103
- const { activateCustomViewStyles: r, updateTimerInClonedTemplate: l } = M(), { injectFullStory: H } = z();
104
- _().importCss(), r(), H(), l(), i.onReady(), o.isStripoInitialized = !0, o.loadingStatus = !1, setTimeout(() => {
103
+ const { activateCustomViewStyles: r, updateTimerInClonedTemplate: l } = N(), { injectFullStory: M } = $();
104
+ v().importCss(), r(), M(), l(), i.onReady(), o.isStripoInitialized = !0, o.loadingStatus = !1, setTimeout(() => {
105
105
  o.hasChanges = !1;
106
- }, 1e3), e.markReady();
106
+ }, 1e3), t.markReady();
107
107
  } catch (r) {
108
108
  f(r, "Failed to load custom interface appearance");
109
109
  }
@@ -120,9 +120,9 @@ const we = (e) => {
120
120
  onDataChanged() {
121
121
  o.hasChanges = !0, o.changeSeq += 1;
122
122
  },
123
- onEvent: U,
124
- onModuleAdd: V,
125
- notifications: I(),
123
+ onEvent: V,
124
+ onModuleAdd: D,
125
+ notifications: L(),
126
126
  // Stripo deselects the block on any click outside the canvas, so every surface
127
127
  // that belongs to the block's own flow has to be listed here (SD-153273).
128
128
  ignoreClickOutsideSelectors: [
@@ -132,29 +132,29 @@ const we = (e) => {
132
132
  ".in-modal-v2-wrapper",
133
133
  ".in-toasts-wrapper"
134
134
  ],
135
- extensions: q,
136
- localePatch: K
135
+ extensions: x,
136
+ localePatch: Q
137
137
  }
138
138
  );
139
139
  };
140
- return { initPlugin: async (a, s, i) => {
141
- const n = v();
140
+ return { initPlugin: async (n, a, i, s = !1) => {
141
+ const e = T();
142
142
  try {
143
- e.mark("plugin_start"), e.setScriptPreloaded(T), await g(), e.mark("script_ready");
144
- const [t, o] = await Promise.all([
145
- P(),
146
- R()
143
+ t.mark("plugin_start"), t.setScriptPreloaded(F), await g(), t.mark("script_ready");
144
+ const [c, o] = await Promise.all([
145
+ R(),
146
+ U()
147
147
  ]);
148
- e.mark("fonts_sync_ready"), n.syncModulesEnabled = o, await L(a, s, i, t, o);
148
+ t.mark("fonts_sync_ready"), e.syncModulesEnabled = o, await q(n, a, i, c, o, s);
149
149
  } catch {
150
- n.loadingStatus = !1, F({
151
- type: Q.Error,
150
+ e.loadingStatus = !1, A({
151
+ type: W.Error,
152
152
  message: B["An error has occurred. Please report the error code to support."],
153
153
  actionButton: {
154
154
  text: B["Reload page"],
155
155
  onClick: () => window.location.reload()
156
156
  }
157
- }), e.markFailed();
157
+ }), t.markFailed();
158
158
  }
159
159
  }, preloadRuntime: () => {
160
160
  g().catch(() => {
@@ -162,5 +162,5 @@ const we = (e) => {
162
162
  } };
163
163
  };
164
164
  export {
165
- we as useStripo
165
+ ke as useStripo
166
166
  };
@@ -1,5 +1,6 @@
1
- import { stripFontTags as p } from "../../utils/stripFontTags.js";
2
- const d = [
1
+ import { stripFontTags as c } from "../../utils/stripFontTags.js";
2
+ import { trimHrefWhitespace as l } from "../../utils/trimHrefWhitespace.js";
3
+ const f = [
3
4
  {
4
5
  id: "fix-url-encoding-start",
5
6
  description: "Replace {%22 with %7B%22 to fix URL encoding",
@@ -58,9 +59,16 @@ const d = [
58
59
  id: "strip-font-tags",
59
60
  description: 'Unwrap browser-translate-injected <font dir="auto"> tags, keeping inner content; other <font> elements are left intact.',
60
61
  type: "custom",
61
- processor: (e) => p(e),
62
+ processor: (e) => c(e),
62
63
  priority: 15
63
64
  },
65
+ {
66
+ id: "trim-href-whitespace",
67
+ description: "Trim leading/trailing whitespace and &nbsp; from every href value",
68
+ type: "custom",
69
+ processor: (e) => l(e),
70
+ priority: 16
71
+ },
64
72
  {
65
73
  id: "remove-apty-iframe",
66
74
  description: "Cleanup Apty Iframe Code",
@@ -157,8 +165,8 @@ const d = [
157
165
  processor: (e) => {
158
166
  const t = (i) => i.toString(16).padStart(2, "0");
159
167
  return e.replace(/rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/gi, (i, o, n, r) => {
160
- const [s, a, c] = [Number(o), Number(n), Number(r)];
161
- return s > 255 || a > 255 || c > 255 ? i : `#${t(s)}${t(a)}${t(c)}`;
168
+ const [s, a, p] = [Number(o), Number(n), Number(r)];
169
+ return s > 255 || a > 255 || p > 255 ? i : `#${t(s)}${t(a)}${t(p)}`;
162
170
  }).replace(/#([0-9a-f])\1([0-9a-f])\2([0-9a-f])\3\b/gi, "#$1$2$3");
163
171
  },
164
172
  priority: 44
@@ -200,5 +208,5 @@ const d = [
200
208
  }
201
209
  ];
202
210
  export {
203
- d as defaultHtmlCompilerRules
211
+ f as defaultHtmlCompilerRules
204
212
  };
@@ -1,18 +1,19 @@
1
- import { migrateCheckbox as i } from "./checkboxMigrator.js";
2
- import { migrateCouponBlock as e } from "./couponBlockMigrator.js";
3
- import { migrateFullStoryScripts as a } from "./fullStoryScriptMigrator.js";
4
- import { migrateItemsBlock as n } from "./itemsBlockMigrator.js";
5
- import { migrateProductNameLink as c } from "./productNameLinkMigrator.js";
6
- import { migrateRadioButton as g } from "./radioButtonMigrator.js";
7
- import { migrateRecommendation as p } from "./recommendationMigrator.js";
8
- import { migrateRecommendationPartnerScope as f } from "./recommendationPartnerMigrator.js";
9
- import { migrateRecommendationTitle as l } from "./recommendationTitleMigrator.js";
10
- import { migrateSocialIcons as s } from "./socialIconMigrator.js";
11
- import { migrateUnsubscribe as d } from "./unsubscribeMigrator.js";
12
- const h = async (o, t = {}, r) => {
13
- let m = o;
14
- return m = i(m), m = g(m), m = await d(m), m = e(m), m = p(m, t), r && (m = f(m, r)), m = l(m), m = n(m), m = c(m), m = s(m), m = a(m), m;
1
+ import { migrateCheckbox as e } from "./checkboxMigrator.js";
2
+ import { migrateCouponBlock as a } from "./couponBlockMigrator.js";
3
+ import { migrateFullStoryScripts as c } from "./fullStoryScriptMigrator.js";
4
+ import { migrateItemsBlock as g } from "./itemsBlockMigrator.js";
5
+ import { migrateItemsPriceFormat as n } from "./itemsPriceFormatMigrator.js";
6
+ import { migrateProductNameLink as p } from "./productNameLinkMigrator.js";
7
+ import { migrateRadioButton as f } from "./radioButtonMigrator.js";
8
+ import { migrateRecommendation as l } from "./recommendationMigrator.js";
9
+ import { migrateRecommendationPartnerScope as d } from "./recommendationPartnerMigrator.js";
10
+ import { migrateRecommendationTitle as s } from "./recommendationTitleMigrator.js";
11
+ import { migrateSocialIcons as k } from "./socialIconMigrator.js";
12
+ import { migrateUnsubscribe as P } from "./unsubscribeMigrator.js";
13
+ const H = async (t, i = {}, r, o) => {
14
+ let m = t;
15
+ return m = e(m), m = f(m), m = await P(m), m = a(m), m = l(m, i), r && (m = d(m, r)), m = s(m), m = g(m), o != null && o.itemsPriceFormatting && (m = n(m)), m = p(m), m = k(m), m = c(m), m;
15
16
  };
16
17
  export {
17
- h as migrate
18
+ H as migrate
18
19
  };
@@ -0,0 +1,20 @@
1
+ import { ITEMS_PRICE_FORMAT_ATTR as e } from "../../extensions/Blocks/Items/constants/currency.js";
2
+ import { applyPriceFormatOpsToElement as o, planPriceFormatOps as n, snapshotPriceFormatFromElement as c } from "../../extensions/Blocks/Items/utils/priceFormatOps.js";
3
+ import { protectLiquid as i, restoreLiquid as s } from "../../utils/liquidProtection.js";
4
+ const m = `td.ins-product-td.items-block-v2:not([${e.DECIMAL_COUNT}])`, a = (r) => o(
5
+ r,
6
+ n(c(r), { convertLegacy: !0 })
7
+ );
8
+ function T(r) {
9
+ if (typeof r != "string" || !r.includes("ins-product-td"))
10
+ return r;
11
+ try {
12
+ const t = new DOMParser().parseFromString(i(r), "text/html");
13
+ return Array.from(t.querySelectorAll(m)).map(a).includes(!0) ? s(t.documentElement.outerHTML) : r;
14
+ } catch (t) {
15
+ return console.error("ItemsPriceFormatMigrator failed:", t), r;
16
+ }
17
+ }
18
+ export {
19
+ T as migrateItemsPriceFormat
20
+ };
@@ -0,0 +1,133 @@
1
+ import { MAX_PRODUCTS_PER_ROW as _ } from "../../../extensions/Blocks/Recommendation/constants/layout.js";
2
+ const T = "td.product-card", x = '[class*="ext-product-"]', d = ".ext-ins-attr p[product-attr]", y = ".ext-ins-attr", S = ["font-family", "font-size", "font-weight", "font-style"], a = [
3
+ ["p_image", ".ext-product-image"],
4
+ ["p_name", ".ext-product-name"],
5
+ ["p_price", ".ext-product-price"],
6
+ ["p_original_price", ".ext-product-original-price"],
7
+ ["p_omnibus_price", ".ext-product-omnibus-price", !0],
8
+ ["p_omnibus_discount", ".ext-product-omnibus-discount", !0],
9
+ ["p_button", ".ext-product-button"]
10
+ ], l = a.map(([, t]) => t).join(", ");
11
+ function s(t, e) {
12
+ const n = new RegExp(`(?:^|;)\\s*${e}\\s*:\\s*([^;]+)`, "i"), r = ((t == null ? void 0 : t.getAttribute("style")) ?? "").match(n);
13
+ return (r == null ? void 0 : r[1].trim()) || void 0;
14
+ }
15
+ function p(t) {
16
+ return /^none\b/.test(s(t, "display") ?? "");
17
+ }
18
+ function h(t) {
19
+ return p(t) || p(t.closest("tr"));
20
+ }
21
+ function f(t) {
22
+ const e = {};
23
+ return S.forEach((n) => {
24
+ const r = s(t, n);
25
+ r && (e[n] = r);
26
+ }), Object.keys(e).length > 0 ? e : void 0;
27
+ }
28
+ function g(t) {
29
+ return Object.keys(t).length > 0 ? t : void 0;
30
+ }
31
+ function m(t) {
32
+ const e = t.querySelector("p") ?? t, n = f(e), r = s(e, "color"), i = t.getAttribute("align") ?? s(e, "text-align"), o = s(e, "line-height");
33
+ return g({
34
+ ...n ? { textStyle: n } : {},
35
+ ...r ? { textColor: { color: r } } : {},
36
+ ...i ? { textAlign: { align: i } } : {},
37
+ ...o ? { textLineSpacing: { lineSpacing: o } } : {}
38
+ });
39
+ }
40
+ function A(t) {
41
+ var u;
42
+ const e = t.querySelector("a") ?? t, n = (u = e.textContent) == null ? void 0 : u.trim(), r = s(e, "background-color") ?? s(e, "background"), i = s(e, "color"), o = f(e), c = t.getAttribute("align");
43
+ return g({
44
+ ...n ? { buttonText: { text: n } } : {},
45
+ ...r ? { buttonColor: { color: r } } : {},
46
+ ...i ? { textButtonColor: { color: i } } : {},
47
+ ...o ? { buttonStyle: o } : {},
48
+ ...c ? { buttonAlign: { align: c } } : {}
49
+ });
50
+ }
51
+ function C(t) {
52
+ const e = t.querySelector("img"), n = Number(e == null ? void 0 : e.getAttribute("width")), r = Number(e == null ? void 0 : e.getAttribute("height")), i = { ...n > 0 ? { width: n } : {}, ...r > 0 ? { height: r } : {} };
53
+ return Object.keys(i).length > 0 ? { imageSize: i } : void 0;
54
+ }
55
+ function R(t, e) {
56
+ switch (t) {
57
+ case "p_image":
58
+ return C(e);
59
+ case "p_button":
60
+ return A(e);
61
+ default:
62
+ return m(e);
63
+ }
64
+ }
65
+ function L(t, e) {
66
+ const n = Array.from(t.querySelectorAll(`[class*="show-recommendation-${e}-"]`));
67
+ return n.length > 0 ? n : Array.from(t.querySelectorAll(T));
68
+ }
69
+ function w(t, e) {
70
+ const n = (o) => e.filter((c) => o.contains(c)).length;
71
+ let r = e[0].parentElement;
72
+ for (; r && r !== t && n(r) < 2; )
73
+ r = r.parentElement;
74
+ if (!r || r === t)
75
+ return e.length === 1 ? 1 : void 0;
76
+ const i = r.tagName === "TBODY" || r.tagName === "TABLE" ? 1 : n(r);
77
+ return Math.min(i, _);
78
+ }
79
+ function v(t) {
80
+ const e = Array.from(t.querySelectorAll(x)).filter((n) => !n.matches(l) && !n.querySelector(l)).flatMap((n) => Array.from(n.classList).filter((r) => r.startsWith("ext-product-")));
81
+ return [...new Set(e)];
82
+ }
83
+ function O(t, e, n) {
84
+ const r = t.closest(y) ?? t, i = m(r);
85
+ return {
86
+ variable: `p_attribute_${e}`,
87
+ variableType: "p_attribute",
88
+ value: t.getAttribute("product-attr") ?? "",
89
+ positionIdx: n,
90
+ hidden: h(r),
91
+ ...i ? { theme: i } : {}
92
+ };
93
+ }
94
+ function N(t) {
95
+ const e = /* @__PURE__ */ new Set(), n = [];
96
+ let r = 0;
97
+ t.querySelectorAll(`${l}, ${d}`).forEach((o) => {
98
+ if (o.matches(d)) {
99
+ n.push(O(o, r, n.length)), r += 1;
100
+ return;
101
+ }
102
+ const c = a.find(
103
+ ([b, E]) => !e.has(b) && o.matches(E)
104
+ );
105
+ if (!c)
106
+ return;
107
+ const u = R(c[0], o);
108
+ e.add(c[0]), n.push({
109
+ variable: c[0],
110
+ positionIdx: n.length,
111
+ hidden: h(o),
112
+ ...u ? { theme: u } : {}
113
+ });
114
+ });
115
+ const i = a.filter(([o, , c]) => !c && !e.has(o)).map(([o]) => ({ variable: o, hidden: !0 }));
116
+ return [...n, ...i];
117
+ }
118
+ function q(t, e) {
119
+ const n = L(t, e);
120
+ if (n.length === 0)
121
+ return null;
122
+ const r = v(n[0]);
123
+ return r.length > 0 ? (console.warn(
124
+ `[RecommendationMigrator] Block id=${e} — legacy card cells the rebuild cannot map: ${r.join(", ")}`
125
+ ), null) : {
126
+ totalCount: n.length,
127
+ rowCount: w(t, n),
128
+ composition: { variables: N(n[0]) }
129
+ };
130
+ }
131
+ export {
132
+ q as inferLegacyConfig
133
+ };
@@ -1,59 +1,71 @@
1
1
  import { BlockId as b } from "../../enums/block.js";
2
- import { DEFAULT_NODE_CONFIG as C } from "../../extensions/Blocks/Recommendation/constants/defaultConfig.js";
3
- import { ATTR_RECOMMENDATION_TITLE as f } from "../../extensions/Blocks/Recommendation/constants/selectors.js";
4
- import { useTemplateStore as M } from "../../stores/template.js";
5
- import { mapComposition as x } from "./recommendation/compositionMapper.js";
6
- import { isPriceOnNextLine as R, extractCurrencyFromBlock as h, isOldPriceFirst as S, withRenderedTextTheme as w, extractTitleText as E, hasEmptyTitle as L, hasVisibleTitle as B, extractCardBgColor as P, isPartnerManagedBlock as A, extractRenderedBlockPadding as H } from "./recommendation/extractors.js";
7
- import { buildBlockHtml as N } from "./recommendation/htmlBuilder.js";
8
- import { parseRecommendationId as O, parseLegacyConfig as F } from "./recommendation/parseLegacyConfig.js";
9
- import { mapSettings as I } from "./recommendation/settingsMapper.js";
10
- import { mapBlockPadding as _ } from "./recommendation/themeMapper.js";
11
- const k = '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)';
12
- function $(c, e, m) {
13
- var l, g, p;
14
- const t = O(e);
2
+ import { DEFAULT_NODE_CONFIG as h } 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 x } from "../../stores/template.js";
5
+ import { mapComposition as S } from "./recommendation/compositionMapper.js";
6
+ import { isPriceOnNextLine as L, extractCurrencyFromBlock as A, isOldPriceFirst as B, withRenderedTextTheme as E, extractTitleText as w, hasEmptyTitle as O, hasVisibleTitle as N, extractCardBgColor as P, isPartnerManagedBlock as H, extractRenderedBlockPadding as I } from "./recommendation/extractors.js";
7
+ import { buildBlockHtml as _ } from "./recommendation/htmlBuilder.js";
8
+ import { inferLegacyConfig as F } from "./recommendation/inferLegacyConfig.js";
9
+ import { parseRecommendationId as $, parseLegacyConfig as k } from "./recommendation/parseLegacyConfig.js";
10
+ import { mapSettings as D } from "./recommendation/settingsMapper.js";
11
+ import { mapBlockPadding as G } from "./recommendation/themeMapper.js";
12
+ const T = ":not(.recommendation-block-v2):not([esd-ext-config])", U = `td[class*="ins-recommendation-v3-block-"]${T}, td.product-block[esd-handler-name*="EmailRecommendationV3"]${T}`, V = "esd-dev-product-config";
13
+ function q(o) {
14
+ return !!(o != null && o.strategy);
15
+ }
16
+ function K(o, e, c) {
17
+ var g, f, u;
18
+ const t = $(e);
15
19
  if (t === null)
16
20
  return console.warn(
17
21
  "[RecommendationMigrator] Skipping block — missing/invalid `ins-recommendation-v3-campaign-id`"
18
22
  ), !1;
19
- const r = F(e);
20
- if (!r)
23
+ const s = e.hasAttribute(V), m = c[String(t)];
24
+ if (!s && !q(m))
25
+ return console.warn(
26
+ `[RecommendationMigrator] Skipping block id=${t} — no \`esd-dev-product-config\` and no recommendationConfigs strategy to rebuild from`
27
+ ), !1;
28
+ const i = s ? k(e) : F(e, t);
29
+ if (!i)
21
30
  return console.warn(
22
- `[RecommendationMigrator] Aborting block id=${t} — \`esd-dev-product-config\` missing or unable to be parsed`
31
+ `[RecommendationMigrator] Aborting block id=${t} — \`esd-dev-product-config\` empty or unparsable, or the rendered markup could not be inferred`
23
32
  ), !1;
24
- const o = m[String(t)] ?? {}, n = {
25
- ...o,
26
- currencySettings: o.currencySettings ?? h(e),
27
- isPriceMovedToNextLine: o.isPriceMovedToNextLine ?? R(e)
28
- }, a = I(n, r, t), i = x(
29
- w((l = r.composition) == null ? void 0 : l.variables, e),
30
- { oldPriceFirst: S(e) }
31
- ), u = E(e);
32
- L(e) ? i.visibility[f] = !1 : i.titleVariable || (i.visibility[f] = B(e));
33
- const y = P(e), T = {
34
- ...a,
33
+ s || console.info(
34
+ `[RecommendationMigrator] Block id=${t} has no \`esd-dev-product-config\` — rebuilt from its rendered markup`
35
+ );
36
+ const r = m ?? {}, n = {
37
+ ...r,
38
+ currencySettings: r.currencySettings ?? A(e),
39
+ isPriceMovedToNextLine: r.isPriceMovedToNextLine ?? L(e)
40
+ }, d = D(n, i, t), a = S(
41
+ E((g = i.composition) == null ? void 0 : g.variables, e),
42
+ { oldPriceFirst: B(e) }
43
+ ), C = w(e);
44
+ O(e) ? a.visibility[y] = !1 : a.titleVariable || (a.visibility[y] = N(e));
45
+ const v = P(e), M = {
46
+ ...d,
35
47
  strategyId: "",
36
- composition: i.composition,
37
- visibility: i.visibility,
38
- previousTitleHtml: C.previousTitleHtml,
39
- textTrimming: i.anyTextTrimming
40
- }, s = A(e), v = `
48
+ composition: a.composition,
49
+ visibility: a.visibility,
50
+ previousTitleHtml: h.previousTitleHtml,
51
+ textTrimming: a.anyTextTrimming
52
+ }, l = H(e), R = `
41
53
  <table>
42
54
  <tbody>
43
55
  <tr>
44
56
  <td class="esd-structure" align="left">
45
57
  <table width="100%" cellpadding="0" cellspacing="0">
46
58
  <tbody>
47
- <tr>${N({
48
- nodeConfig: T,
49
- composition: i,
50
- cardBg: y,
51
- titleText: u,
59
+ <tr>${_({
60
+ nodeConfig: M,
61
+ composition: a,
62
+ cardBg: v,
63
+ titleText: C,
52
64
  legacyId: e.getAttribute("id") ?? void 0,
53
65
  legacyBgColor: e.getAttribute("bgcolor") ?? void 0,
54
- preserveInnerHtml: s ? e.innerHTML : void 0,
55
- skipCompile: s,
56
- blockPadding: _(((p = (g = r.theme) == null ? void 0 : g.blockPadding) == null ? void 0 : p.desktop) ?? H(e))
66
+ preserveInnerHtml: l ? e.innerHTML : void 0,
67
+ skipCompile: l,
68
+ blockPadding: G(((u = (f = i.theme) == null ? void 0 : f.blockPadding) == null ? void 0 : u.desktop) ?? I(e))
57
69
  })}</tr>
58
70
  </tbody>
59
71
  </table>
@@ -61,40 +73,42 @@ function $(c, e, m) {
61
73
  </tr>
62
74
  </tbody>
63
75
  </table>
64
- `, d = c.parseFromString(v, "text/html").querySelector("td.esd-structure");
65
- return !d || !e.parentNode ? (console.warn(
76
+ `, p = o.parseFromString(R, "text/html").querySelector("td.esd-structure");
77
+ return !p || !e.parentNode ? (console.warn(
66
78
  `[RecommendationMigrator] Aborting block id=${t} — failed to construct new HTML element`
67
- ), !1) : (e.parentNode.replaceChild(d, e), !0);
79
+ ), !1) : (e.parentNode.replaceChild(p, e), !0);
68
80
  }
69
- function X(c, e = {}) {
70
- const m = new DOMParser();
81
+ function ne(o, e = {}) {
82
+ const c = new DOMParser();
71
83
  let t;
72
84
  try {
73
- t = m.parseFromString(c, "text/html");
74
- } catch (n) {
75
- return console.error("[RecommendationMigrator] Failed to parse template:", n), c;
85
+ t = c.parseFromString(o, "text/html");
86
+ } catch (r) {
87
+ return console.error("[RecommendationMigrator] Failed to parse template:", r), o;
76
88
  }
77
- const r = Array.from(t.querySelectorAll(k));
89
+ const s = Array.from(t.querySelectorAll(U)), m = s.filter((r) => {
90
+ var n;
91
+ return !((n = r.parentElement) != null && n.closest(".recommendation-block-v2")) && !s.some((d) => d !== r && d.contains(r));
92
+ });
93
+ let i = 0;
94
+ m.forEach((r) => {
95
+ try {
96
+ K(c, r, e) && (i += 1);
97
+ } catch (n) {
98
+ console.error("[RecommendationMigrator] Unexpected error migrating block:", n);
99
+ }
100
+ });
78
101
  try {
79
- M().$patch((a) => {
80
- a.migrations = {
81
- ...a.migrations,
82
- [b.Recommendation]: r.length
102
+ x().$patch((n) => {
103
+ n.migrations = {
104
+ ...n.migrations,
105
+ [b.Recommendation]: i
83
106
  };
84
107
  });
85
108
  } catch {
86
109
  }
87
- if (r.length === 0)
88
- return c;
89
- let o = 0;
90
- return r.forEach((n) => {
91
- try {
92
- $(m, n, e) && (o += 1);
93
- } catch (a) {
94
- console.error("[RecommendationMigrator] Unexpected error migrating block:", a);
95
- }
96
- }), o > 0 && console.info(`[RecommendationMigrator] Migrated ${o} legacy Recommendation block(s)`), t.documentElement.outerHTML;
110
+ return i === 0 ? o : (console.info(`[RecommendationMigrator] Migrated ${i} legacy Recommendation block(s)`), t.documentElement.outerHTML);
97
111
  }
98
112
  export {
99
- X as migrateRecommendation
113
+ ne as migrateRecommendation
100
114
  };