@useinsider/guido 3.4.1-beta.5e1fcb5 → 3.4.1-beta.6ed05e2

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
@@ -8,6 +8,8 @@
8
8
 
9
9
  # @useinsider/guido
10
10
 
11
+ [![Coverus](https://github.com/useinsider/coverus-artifacts/raw/main/badges/github/useinsider/guido/coverage.svg)](http://coverus.internal.dataforce/app/project/github/useinsider/guido)
12
+
11
13
  Guido is a Vue 2 + TypeScript wrapper for the Stripo Email Editor plugin. Easily embed the professional email editor in your Vue applications with a clean, type-safe configuration.
12
14
 
13
15
  ## Installation
@@ -1,24 +1,24 @@
1
1
  var k = Object.defineProperty;
2
- var B = (r, n, t) => n in r ? k(r, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[n] = t;
3
- var g = (r, n, t) => B(r, typeof n != "symbol" ? n + "" : n, t);
2
+ var B = (a, i, t) => i in a ? k(a, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[i] = t;
3
+ var d = (a, i, t) => B(a, typeof i != "symbol" ? i + "" : i, t);
4
4
  import { BlockId as _ } from "../../../enums/block.js";
5
- import { getMigrationBannerHtml as b } from "../../../utils/migrationBannerHtml.js";
6
- import { Block as R, BlockCompositionType as y, ModificationDescription as C } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
5
+ import { getMigrationBannerHtml as C } from "../../../utils/migrationBannerHtml.js";
6
+ import { Block as b, BlockCompositionType as R, ModificationDescription as y } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
7
7
  import { regenerateMobileProductRows as A } from "./controls/main/utils.js";
8
- import { ensureMobileCssRulesExist as d, setMobileLayoutOptOut as p, hasMobileLayoutOptOut as D } from "./controls/mobileLayout/cssRules.js";
9
- import { RecommendationConfigService as s } from "./services/configService.js";
10
- import { useRecommendationExtensionStore as f } from "./store/recommendation.js";
11
- import { getDefaultTemplate as E } from "./templates/grid/template.js";
12
- const h = _.Recommendation, l = "recommendation-block-v2", m = "recommendation-id";
8
+ import { ensureMobileCssRulesExist as p, setMobileLayoutOptOut as f, hasMobileLayoutOptOut as N } from "./controls/mobileLayout/cssRules.js";
9
+ import { RecommendationConfigService as c } from "./services/configService.js";
10
+ import { useRecommendationExtensionStore as m } from "./store/recommendation.js";
11
+ import { getDefaultTemplate as D } from "./templates/grid/template.js";
12
+ const h = _.Recommendation, u = "recommendation-block-v2", l = "recommendation-id";
13
13
  let I = !1;
14
- class q extends R {
14
+ class q extends b {
15
15
  constructor() {
16
16
  super();
17
17
  /**
18
18
  * Stores the ID generated in getTemplate() so onCreated() can reuse it.
19
19
  * This avoids generating a new (different) ID in onCreated().
20
20
  */
21
- g(this, "_pendingBlockId", null);
21
+ d(this, "_pendingBlockId", null);
22
22
  }
23
23
  getId() {
24
24
  return h;
@@ -27,7 +27,7 @@ class q extends R {
27
27
  return "recommendation-icon";
28
28
  }
29
29
  getBlockCompositionType() {
30
- return y.CONTAINER;
30
+ return R.CONTAINER;
31
31
  }
32
32
  getName() {
33
33
  return this.api.translate("Recommendation Block");
@@ -38,7 +38,7 @@ class q extends R {
38
38
  );
39
39
  }
40
40
  getSettingsPanelTitleHtml() {
41
- return b(
41
+ return C(
42
42
  h,
43
43
  this.api.translate("Recommendation Block"),
44
44
  this.api.translate("This block is switched from the Old Version to the New Version. We recommend you check the Recommendation block and test your message to ensure it works properly.")
@@ -59,7 +59,7 @@ class q extends R {
59
59
  */
60
60
  getTemplate() {
61
61
  const t = this._generateNextId();
62
- return this._pendingBlockId = t, E(t);
62
+ return this._pendingBlockId = t, D(t);
63
63
  }
64
64
  /**
65
65
  * Called when a new block is dropped into the template
@@ -72,22 +72,22 @@ class q extends R {
72
72
  const e = this._getRecommendationId(t);
73
73
  if (e !== null && e > 0)
74
74
  return;
75
- const i = this._pendingBlockId ?? this._generateNextId();
76
- this._pendingBlockId = null, this._assignRecommendationId(t, i);
77
- const { config: o, wasFreshDrop: c } = s.initializeConfig(
75
+ const o = this._pendingBlockId ?? this._generateNextId();
76
+ this._pendingBlockId = null, this._assignRecommendationId(t, o);
77
+ const { config: n, wasFreshDrop: s } = c.initializeConfig(
78
78
  this.api,
79
79
  t,
80
- { recommendationId: i }
81
- ), a = f();
82
- if (a.setCurrentBlock(i), c) {
83
- d(this.api);
84
- const u = this._getBlockElement(t);
85
- u && (p(this.api, u, !0), A({
80
+ { recommendationId: o }
81
+ ), r = m();
82
+ if (r.setCurrentBlock(o), s) {
83
+ p(this.api);
84
+ const g = this._getBlockElement(t);
85
+ g && (f(this.api, g, !0), A({
86
86
  currentNode: t,
87
87
  documentModifier: this.api.getDocumentModifier()
88
88
  }));
89
89
  }
90
- a.patchCurrentBlockConfig({ language: o.language }, { triggerRefetch: !1 });
90
+ r.patchCurrentBlockConfig({ language: n.language }, { triggerRefetch: !1 });
91
91
  }
92
92
  /**
93
93
  * Called when the document changes or template is loaded
@@ -100,20 +100,20 @@ class q extends R {
100
100
  if (!(!t || !("getNodeConfig" in t))) {
101
101
  if (!this._getRecommendationId(t)) {
102
102
  const e = this._generateNextId();
103
- this._assignRecommendationId(t, e), s.hasConfig(t) && s.updateConfig(
103
+ this._assignRecommendationId(t, e), c.hasConfig(t) && c.updateConfig(
104
104
  this.api,
105
105
  t,
106
106
  { recommendationId: e },
107
107
  "Assign recommendation ID to legacy block"
108
108
  );
109
109
  }
110
- s.needsMigration(t) && this._migrateFromLegacy(t);
110
+ c.needsMigration(t) && this._migrateFromLegacy(t);
111
111
  try {
112
- I || (d(this.api), I = !0);
113
- const e = s.getConfig(t), i = this._getBlockElement(t);
114
- if (i) {
115
- const o = !e.mobileLayoutEnabled;
116
- D(i) !== o && p(this.api, i, o);
112
+ I || (p(this.api), I = !0);
113
+ const e = c.getConfig(t), o = this._getBlockElement(t);
114
+ if (o) {
115
+ const n = !e.mobileLayoutEnabled;
116
+ N(o) !== n && f(this.api, o, n);
117
117
  }
118
118
  } catch {
119
119
  }
@@ -127,7 +127,26 @@ class q extends R {
127
127
  */
128
128
  onDelete(t) {
129
129
  const e = this._getRecommendationId(t);
130
- e && f().removeBlockState(e);
130
+ e && m().removeBlockState(e);
131
+ }
132
+ /**
133
+ * Lifecycle hook fired when Stripo's UI Duplicate button copies a block.
134
+ * Stripo passes an `HtmlNodeModifier` already targeting the cloned node;
135
+ * its mutations are committed when this method returns. We stamp a fresh
136
+ * `recommendation-id` on the clone and seed its blockStates entry from
137
+ * the source so the duplicate enters the DOM as a fully independent block
138
+ * — no shared id, no shared store, no API refetch flash.
139
+ *
140
+ * Stripo does NOT fire `onCreated` for blocks created via duplicate
141
+ * (per Block.d.ts:54-69 — `onCreated` is drag-and-drop only), so this
142
+ * hook is the sole production path for clone id assignment.
143
+ */
144
+ onCopy(t) {
145
+ const e = t.getTargetNode(), o = this._getRecommendationId(e), n = this._generateNextId(), s = c.getConfig(e);
146
+ if (t.setAttribute(l, n.toString()).setNodeConfig({ ...s, recommendationId: n }), o !== null && o > 0) {
147
+ const r = m();
148
+ r.cloneBlockState(o, n), r.setCurrentBlock(n);
149
+ }
131
150
  }
132
151
  /**
133
152
  * Generates the next unique recommendation ID by scanning all existing blocks
@@ -137,10 +156,10 @@ class q extends R {
137
156
  let t = 0;
138
157
  try {
139
158
  const e = this.api.getDocumentRoot();
140
- e && "querySelectorAll" in e && e.querySelectorAll(`.${l}`).forEach((o) => {
141
- if ("getAttribute" in o) {
142
- const c = o.getAttribute(m), a = c ? parseInt(c) : 0;
143
- a > t && (t = a);
159
+ e && "querySelectorAll" in e && e.querySelectorAll(`.${u}`).forEach((n) => {
160
+ if ("getAttribute" in n) {
161
+ const s = n.getAttribute(l), r = s ? parseInt(s) : 0;
162
+ r > t && (t = r);
144
163
  }
145
164
  });
146
165
  } catch {
@@ -154,11 +173,11 @@ class q extends R {
154
173
  * added classes via setAttribute.
155
174
  */
156
175
  _assignRecommendationId(t, e) {
157
- const i = this._getBlockElement(t);
158
- if (!i)
176
+ const o = this._getBlockElement(t);
177
+ if (!o)
159
178
  return;
160
- const o = this.api.getDocumentModifier();
161
- o.modifyHtml(i).setAttribute(m, e.toString()), o.apply(new C(`Assign recommendation ID ${e}`));
179
+ const n = this.api.getDocumentModifier();
180
+ n.modifyHtml(o).setAttribute(l, e.toString()), n.apply(new y(`Assign recommendation ID ${e}`));
162
181
  }
163
182
  /**
164
183
  * Gets the recommendation-id from a block node
@@ -167,11 +186,11 @@ class q extends R {
167
186
  const e = this._getBlockElement(t);
168
187
  if (!e || !("getAttribute" in e))
169
188
  return null;
170
- const i = e.getAttribute(m);
171
- if (!i)
189
+ const o = e.getAttribute(l);
190
+ if (!o)
172
191
  return null;
173
- const o = parseInt(i);
174
- return Number.isNaN(o) ? null : o;
192
+ const n = parseInt(o);
193
+ return Number.isNaN(n) ? null : n;
175
194
  }
176
195
  /**
177
196
  * Gets the block element (the element with BLOCK_CLASS)
@@ -179,16 +198,16 @@ class q extends R {
179
198
  _getBlockElement(t) {
180
199
  if ("getAttribute" in t) {
181
200
  const e = t.getAttribute("class");
182
- if (e && e.includes(l))
201
+ if (e && e.includes(u))
183
202
  return t;
184
203
  }
185
- return "querySelector" in t ? t.querySelector(`.${l}`) ?? null : null;
204
+ return "querySelector" in t ? t.querySelector(`.${u}`) ?? null : null;
186
205
  }
187
206
  /**
188
207
  * Migrate configuration from legacy format
189
208
  */
190
209
  _migrateFromLegacy(t) {
191
- s.migrateFromDataAttributes(this.api, t);
210
+ c.migrateFromDataAttributes(this.api, t);
192
211
  }
193
212
  }
194
213
  export {
@@ -1,18 +1,18 @@
1
- import { getRecommendationFeedSourceMaps as g, getOperatorOptions as R, PriceAttributes as y } from "../../../../enums/extensions/recommendationBlock.js";
2
- import { useRecommendationApi as C } from "../../../../services/recommendationApi.js";
1
+ import { getRecommendationFeedSourceMaps as S, getOperatorOptions as R, PriceAttributes as C } from "../../../../enums/extensions/recommendationBlock.js";
2
+ import { useRecommendationApi as y } from "../../../../services/recommendationApi.js";
3
3
  import { useConfigStore as G } from "../../../../stores/config.js";
4
4
  import { defineStore as P } from "pinia";
5
- import { DEFAULT_CARDS_IN_ROW as F } from "../constants/layout.js";
6
- import { EXCLUDED_ALGORITHM_IDS as D } from "../constants/defaultConfig.js";
7
- import { getDefaultProducts as S } from "../templates/utils.js";
5
+ import { DEFAULT_CARDS_IN_ROW as D } from "../constants/layout.js";
6
+ import { EXCLUDED_ALGORITHM_IDS as F } from "../constants/defaultConfig.js";
7
+ import { getDefaultProducts as g } from "../templates/utils.js";
8
8
  import { generateCompleteFilterQuery as b } from "../utils/filterUtil.js";
9
9
  import { isFilterValid as w } from "../validation/filterSchema.js";
10
10
  import { isConfigValid as v } from "../validation/requiredFields.js";
11
- const h = C();
11
+ const h = y();
12
12
  let m = null, u = null, d = null;
13
13
  function k() {
14
14
  return {
15
- cardsInRow: F,
15
+ cardsInRow: D,
16
16
  currencySettings: {
17
17
  name: "USD",
18
18
  value: "USD",
@@ -114,8 +114,8 @@ const N = () => ({
114
114
  return [...new Set(t.map((e) => e.filterGroup))].sort((e, r) => e - r);
115
115
  },
116
116
  getActivePredictiveAlgorithms: (t) => {
117
- const e = g(), r = [];
118
- return t.activePredictiveAlgorithms.filter((n) => !D.includes(n)).forEach((n) => {
117
+ const e = S(), r = [];
118
+ return t.activePredictiveAlgorithms.filter((n) => !F.includes(n)).forEach((n) => {
119
119
  r.push(...e.filter((c) => c.id === n));
120
120
  }), r.map((n) => ({
121
121
  text: n.name,
@@ -133,7 +133,7 @@ const N = () => ({
133
133
  getFilterList() {
134
134
  return Object.values(this.filterList).map((t) => {
135
135
  let e;
136
- return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` : y.includes(t.attributeName) ? e = `${t.attributeName}.${this.recommendationConfigs.currencySettings.value}` : e = t.attributeName, {
136
+ return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` : C.includes(t.attributeName) ? e = `${t.attributeName}.${this.recommendationConfigs.currencySettings.value}` : e = t.attributeName, {
137
137
  text: t.displayName,
138
138
  value: e,
139
139
  type: t.attributeType
@@ -174,6 +174,34 @@ const N = () => ({
174
174
  this.currentRecommendationId = n.length > 0 ? n[0] : null;
175
175
  }
176
176
  },
177
+ /**
178
+ * Copies blockStates[fromId] into a new blockStates[toId] entry so a
179
+ * duplicated block immediately renders the source's products/filters
180
+ * without re-fetching from the API (SD-142352). No-op when the source
181
+ * was never selected (no entry in blockStates) — the caller falls back
182
+ * to setCurrentBlock's default initialization.
183
+ */
184
+ cloneBlockState(t, e) {
185
+ const r = this.blockStates[t];
186
+ !r || this.blockStates[e] || (this.blockStates = {
187
+ ...this.blockStates,
188
+ [e]: {
189
+ ...r,
190
+ recommendationProducts: [...r.recommendationProducts],
191
+ recommendationConfigs: {
192
+ ...r.recommendationConfigs,
193
+ id: e,
194
+ filters: r.recommendationConfigs.filters.map((n) => ({ ...n })),
195
+ productIds: [...r.recommendationConfigs.productIds],
196
+ customAttributes: [...r.recommendationConfigs.customAttributes],
197
+ recommendedProducts: [...r.recommendationConfigs.recommendedProducts],
198
+ currencySettings: { ...r.recommendationConfigs.currencySettings }
199
+ },
200
+ filterSnapshot: null,
201
+ filterSelectionDrawerStatus: !1
202
+ }
203
+ });
204
+ },
177
205
  /**
178
206
  * Marks a block as initialized (initial API data has been fetched).
179
207
  * Automatically cleaned up when removeBlockState deletes the block entry.
@@ -426,7 +454,7 @@ const N = () => ({
426
454
  },
427
455
  async _doFetchProducts() {
428
456
  var p;
429
- const t = this.currentRecommendationId, e = this.blockStates[t], { recommendationConfigs: r } = e, n = r.filters.filter((l) => l.isValid), c = b(n), i = ((p = g().find((l) => l.key === r.strategy)) == null ? void 0 : p.path) || "", o = G(), s = parseInt(r.size) || 6, a = {
457
+ const t = this.currentRecommendationId, e = this.blockStates[t], { recommendationConfigs: r } = e, n = r.filters.filter((l) => l.isValid), c = b(n), i = ((p = S().find((l) => l.key === r.strategy)) == null ? void 0 : p.path) || "", o = G(), s = parseInt(r.size) || 6, a = {
430
458
  locale: r.language,
431
459
  currency: r.currencySettings.value,
432
460
  partnerName: o.partnerName,
@@ -442,10 +470,10 @@ const N = () => ({
442
470
  f = [];
443
471
  }
444
472
  if (this.blockStates[t]) {
445
- const l = f.length > 0 ? f : S(s);
473
+ const l = f.length > 0 ? f : g(s);
446
474
  l.length < s ? this.blockStates[t].recommendationProducts = [
447
475
  ...l,
448
- ...S(s - l.length)
476
+ ...g(s - l.length)
449
477
  ] : l.length > s ? this.blockStates[t].recommendationProducts = l.slice(0, s) : this.blockStates[t].recommendationProducts = l;
450
478
  }
451
479
  }
@@ -9,25 +9,25 @@ const o = [
9
9
  getValue: (e) => e.currencySettings.value,
10
10
  getAvailableOptions: (e) => e.currencyList.map((n) => n.text)
11
11
  }
12
- ], u = "newsletter.recommendation-fill-required-fields";
13
- function l(e, n) {
12
+ ], l = "newsletter.recommendation-fill-required-fields";
13
+ function u(e, n) {
14
14
  return o.filter((t) => {
15
15
  var a;
16
16
  if (t.condition && !t.condition(e))
17
17
  return !1;
18
- const r = t.getValue(e);
19
- if (!r)
18
+ const i = t.getValue(e);
19
+ if (!i)
20
20
  return !0;
21
- const i = (a = t.getAvailableOptions) == null ? void 0 : a.call(t, n);
22
- return i !== void 0 && i.length > 0 && !i.includes(r);
21
+ const r = (a = t.getAvailableOptions) == null ? void 0 : a.call(t, n);
22
+ return r !== void 0 && !r.includes(i);
23
23
  }).map((t) => t.key);
24
24
  }
25
25
  function s(e, n) {
26
- return l(e, n).length === 0;
26
+ return u(e, n).length === 0;
27
27
  }
28
28
  export {
29
29
  o as REQUIRED_RECOMMENDATION_FIELDS,
30
- u as RecommendationRequiredFieldsKey,
31
- l as getInvalidFields,
30
+ l as RecommendationRequiredFieldsKey,
31
+ u as getInvalidFields,
32
32
  s as isConfigValid
33
33
  };
@@ -6,7 +6,7 @@
6
6
  * Supports multiple block instances with unique recommendation-id attributes.
7
7
  */
8
8
  import type { BlockId } from '@@/Types/extensions/block';
9
- import type { ImmutableHtmlNode } from '@stripoinc/ui-editor-extensions';
9
+ import type { HtmlNodeModifier, ImmutableHtmlNode } from '@stripoinc/ui-editor-extensions';
10
10
  import { Block, BlockCompositionType } from '@stripoinc/ui-editor-extensions';
11
11
  export declare const BLOCK_ID: BlockId;
12
12
  export declare class RecommendationBlock extends Block {
@@ -55,6 +55,19 @@ export declare class RecommendationBlock extends Block {
55
55
  * @param node - The block node being deleted
56
56
  */
57
57
  onDelete(node: ImmutableHtmlNode): void;
58
+ /**
59
+ * Lifecycle hook fired when Stripo's UI Duplicate button copies a block.
60
+ * Stripo passes an `HtmlNodeModifier` already targeting the cloned node;
61
+ * its mutations are committed when this method returns. We stamp a fresh
62
+ * `recommendation-id` on the clone and seed its blockStates entry from
63
+ * the source so the duplicate enters the DOM as a fully independent block
64
+ * — no shared id, no shared store, no API refetch flash.
65
+ *
66
+ * Stripo does NOT fire `onCreated` for blocks created via duplicate
67
+ * (per Block.d.ts:54-69 — `onCreated` is drag-and-drop only), so this
68
+ * hook is the sole production path for clone id assignment.
69
+ */
70
+ onCopy(modifier: HtmlNodeModifier): void;
58
71
  /**
59
72
  * Generates the next unique recommendation ID by scanning all existing blocks
60
73
  * in the document and finding the maximum existing ID + 1.
@@ -216,6 +216,14 @@ export declare const useRecommendationExtensionStore: import("pinia").StoreDefin
216
216
  * Resets currentRecommendationId if it was the deleted block.
217
217
  */
218
218
  removeBlockState(id: number): void;
219
+ /**
220
+ * Copies blockStates[fromId] into a new blockStates[toId] entry so a
221
+ * duplicated block immediately renders the source's products/filters
222
+ * without re-fetching from the API (SD-142352). No-op when the source
223
+ * was never selected (no entry in blockStates) — the caller falls back
224
+ * to setCurrentBlock's default initialization.
225
+ */
226
+ cloneBlockState(fromId: number, toId: number): void;
219
227
  /**
220
228
  * Marks a block as initialized (initial API data has been fetched).
221
229
  * Automatically cleaned up when removeBlockState deletes the block entry.
File without changes
@@ -1,8 +1,8 @@
1
1
  import "../@types/config/schemas.js";
2
2
  import "../@types/config/defaults.js";
3
- import { parseConfig as n } from "../@types/config/validator.js";
4
- import { defineStore as o } from "pinia";
5
- const s = o("guido-config", {
3
+ import { parseConfig as o } from "../@types/config/validator.js";
4
+ import { defineStore as r } from "pinia";
5
+ const f = r("guido-config", {
6
6
  state: () => ({
7
7
  initialized: !1,
8
8
  config: null
@@ -75,64 +75,65 @@ const s = o("guido-config", {
75
75
  * Get the template ID
76
76
  */
77
77
  templateId: (i) => {
78
- var e;
79
- return ((e = i.config) == null ? void 0 : e.identity.templateId) ?? "";
78
+ var e, t;
79
+ return ((t = (e = i.config) == null ? void 0 : e.identity) == null ? void 0 : t.templateId) ?? "";
80
80
  },
81
81
  /**
82
82
  * Get the user ID
83
83
  */
84
84
  userId: (i) => {
85
- var e;
86
- return ((e = i.config) == null ? void 0 : e.identity.userId) ?? "";
85
+ var e, t;
86
+ return ((t = (e = i.config) == null ? void 0 : e.identity) == null ? void 0 : t.userId) ?? "";
87
87
  },
88
88
  /**
89
89
  * Get the variation ID
90
90
  */
91
91
  variationId: (i) => {
92
- var e;
93
- return ((e = i.config) == null ? void 0 : e.identity.variationId) ?? "";
92
+ var e, t;
93
+ return ((t = (e = i.config) == null ? void 0 : e.identity) == null ? void 0 : t.variationId) ?? "";
94
94
  },
95
95
  /**
96
96
  * Get the partner name
97
97
  */
98
98
  partnerName: (i) => {
99
- var e;
100
- return ((e = i.config) == null ? void 0 : e.partner.name) ?? "";
99
+ var e, t;
100
+ return ((t = (e = i.config) == null ? void 0 : e.partner) == null ? void 0 : t.name) ?? "";
101
101
  },
102
102
  /**
103
103
  * Get the product type
104
104
  */
105
105
  productType: (i) => {
106
- var e;
107
- return ((e = i.config) == null ? void 0 : e.partner.productType) ?? 60;
106
+ var e, t;
107
+ return ((t = (e = i.config) == null ? void 0 : e.partner) == null ? void 0 : t.productType) ?? 60;
108
108
  },
109
109
  /**
110
110
  * Get the message type
111
111
  */
112
112
  messageType: (i) => {
113
- var e;
114
- return ((e = i.config) == null ? void 0 : e.partner.messageType) ?? 1;
113
+ var e, t;
114
+ return ((t = (e = i.config) == null ? void 0 : e.partner) == null ? void 0 : t.messageType) ?? 1;
115
115
  },
116
116
  /**
117
117
  * Get the username
118
118
  */
119
119
  username: (i) => {
120
- var e;
121
- return ((e = i.config) == null ? void 0 : e.partner.username) ?? "Guido User";
120
+ var e, t;
121
+ return ((t = (e = i.config) == null ? void 0 : e.partner) == null ? void 0 : t.username) ?? "Guido User";
122
122
  },
123
123
  /**
124
124
  * Check if header should be shown
125
125
  */
126
126
  showHeader: (i) => {
127
- var e;
128
- return ((e = i.config) == null ? void 0 : e.ui.showHeader) ?? !0;
127
+ var e, t;
128
+ return ((t = (e = i.config) == null ? void 0 : e.ui) == null ? void 0 : t.showHeader) ?? !0;
129
129
  },
130
130
  /**
131
131
  * Check if a specific feature is enabled
132
132
  */
133
+ // eslint-disable-next-line @stylistic/max-len
133
134
  isFeatureEnabled: (i) => (e) => {
134
- var t;
135
- return ((t = i.config) == null ? void 0 : t.features[e]) ?? !0;
135
+ var t, n;
136
+ return ((n = (t = i.config) == null ? void 0 : t.features) == null ? void 0 : n[e]) ?? !0;
136
137
  }
137
138
  },
138
139
  actions: {
@@ -140,7 +141,7 @@ const s = o("guido-config", {
140
141
  * Initialize the config store with validated configuration
141
142
  */
142
143
  init(i) {
143
- const e = n(i);
144
+ const e = o(i);
144
145
  this.config = e, this.initialized = !0;
145
146
  },
146
147
  /**
@@ -152,5 +153,5 @@ const s = o("guido-config", {
152
153
  }
153
154
  });
154
155
  export {
155
- s as useConfigStore
156
+ f as useConfigStore
156
157
  };
@@ -1,101 +1,106 @@
1
- import { useActionsApi as C } from "../composables/useActionsApi.js";
2
- import { useHtmlCompiler as T } from "../composables/useHtmlCompiler.js";
3
- import { DEFAULT_CURRENCY as d, DEFAULT_NODE_CONFIG as s } from "../extensions/Blocks/Recommendation/constants/defaultConfig.js";
1
+ import { useActionsApi as E } from "../composables/useActionsApi.js";
2
+ import { useHtmlCompiler as P } from "../composables/useHtmlCompiler.js";
3
+ import { DEFAULT_CURRENCY as p, DEFAULT_NODE_CONFIG as u } from "../extensions/Blocks/Recommendation/constants/defaultConfig.js";
4
+ import { BLOCK_ROOT_SELECTOR as R, CONTAINER_SELECTOR as N } from "../extensions/Blocks/Recommendation/constants/selectors.js";
4
5
  import { useRecommendationExtensionStore as b } from "../extensions/Blocks/Recommendation/store/recommendation.js";
5
- import { DATA_ATTRIBUTES as S } from "../extensions/Blocks/Unsubscribe/utils/constants.js";
6
- import { parsePageList as D } from "../extensions/Blocks/Unsubscribe/utils/utils.js";
7
- import { useDynamicContentStore as P } from "../stores/dynamic-content.js";
8
- import { useUnsubscribeStore as w } from "../stores/unsubscribe.js";
9
- function E(i, o) {
10
- const t = new DOMParser().parseFromString(i, "text/html").querySelectorAll(`[${S.PAGE_LIST}]`), c = [];
11
- return t.forEach((r) => {
12
- const a = r.getAttribute(S.PAGE_LIST);
13
- a && c.push(...D(a));
14
- }), o.filter((r) => c.includes(r));
6
+ import { DATA_ATTRIBUTES as y } from "../extensions/Blocks/Unsubscribe/utils/constants.js";
7
+ import { parsePageList as O } from "../extensions/Blocks/Unsubscribe/utils/utils.js";
8
+ import { useDynamicContentStore as L } from "../stores/dynamic-content.js";
9
+ import { useUnsubscribeStore as F } from "../stores/unsubscribe.js";
10
+ function I(s, t) {
11
+ const n = new DOMParser().parseFromString(s, "text/html").querySelectorAll(`[${y.PAGE_LIST}]`), c = [];
12
+ return n.forEach((r) => {
13
+ const o = r.getAttribute(y.PAGE_LIST);
14
+ o && c.push(...O(o));
15
+ }), t.filter((r) => c.includes(r));
15
16
  }
16
- async function U(i) {
17
- const m = new DOMParser().parseFromString(i, "text/html").querySelectorAll(".recommendation-block-v2");
18
- if (m.length === 0)
17
+ function w(s) {
18
+ var c, r;
19
+ const t = (r = (c = document.querySelector("ui-editor")) == null ? void 0 : c.shadowRoot) == null ? void 0 : r.querySelector("iframe"), m = (t == null ? void 0 : t.contentDocument) ?? new DOMParser().parseFromString(s, "text/html"), n = /* @__PURE__ */ new Set();
20
+ return m.querySelectorAll(R).forEach((o) => {
21
+ if (!o.querySelector(N))
22
+ return;
23
+ const e = Number(o.getAttribute("recommendation-id"));
24
+ Number.isFinite(e) && e > 0 && n.add(e);
25
+ }), n;
26
+ }
27
+ function x(s) {
28
+ const a = new DOMParser().parseFromString(s, "text/html").querySelectorAll(".recommendation-block-v2");
29
+ if (a.length === 0)
19
30
  return;
20
- const l = b();
21
- m.forEach((t) => {
22
- var g, f, u, n, y;
23
- const c = t.getAttribute("recommendation-id"), r = c ? Number(c) : NaN;
31
+ const m = b();
32
+ a.forEach((n) => {
33
+ var f, g, d, i, S;
34
+ const c = n.getAttribute("recommendation-id"), r = c ? Number(c) : NaN;
24
35
  if (!Number.isFinite(r))
25
36
  return;
26
- const a = t.getAttribute("esd-ext-config");
27
- if (!a)
37
+ const o = n.getAttribute("esd-ext-config");
38
+ if (!o)
28
39
  return;
29
40
  let e;
30
41
  try {
31
- e = JSON.parse(a);
42
+ e = JSON.parse(o);
32
43
  } catch {
33
44
  return;
34
45
  }
35
46
  if (!e || typeof e != "object" || Array.isArray(e))
36
47
  return;
37
- const p = {
38
- strategy: e.strategy ?? s.strategy,
39
- language: e.language ?? s.language,
40
- size: e.size ?? s.size,
48
+ const l = {
49
+ strategy: e.strategy ?? u.strategy,
50
+ language: e.language ?? u.language,
51
+ size: e.size ?? u.size,
41
52
  // Spread the default arrays so each block gets a fresh reference
42
53
  // instead of sharing the singleton in DEFAULT_NODE_CONFIG.
43
- productIds: e.productIds ?? [...s.productIds],
44
- filters: e.filters ?? [...s.filters],
45
- shuffleProducts: e.shuffleProducts ?? s.shuffleProducts,
46
- currencyCode: ((g = e.currency) == null ? void 0 : g.code) ?? d.code,
47
- currencyAlignment: ((f = e.currency) == null ? void 0 : f.alignment) ?? d.alignment,
48
- currencyDecimalCount: ((u = e.currency) == null ? void 0 : u.decimalCount) ?? d.decimalCount,
49
- currencyDecimalSeparator: ((n = e.currency) == null ? void 0 : n.decimalSeparator) ?? d.decimalSeparator,
50
- currencyThousandSeparator: ((y = e.currency) == null ? void 0 : y.thousandSeparator) ?? d.thousandSeparator
54
+ productIds: e.productIds ?? [...u.productIds],
55
+ filters: e.filters ?? [...u.filters],
56
+ shuffleProducts: e.shuffleProducts ?? u.shuffleProducts,
57
+ currencyCode: ((f = e.currency) == null ? void 0 : f.code) ?? p.code,
58
+ currencyAlignment: ((g = e.currency) == null ? void 0 : g.alignment) ?? p.alignment,
59
+ currencyDecimalCount: ((d = e.currency) == null ? void 0 : d.decimalCount) ?? p.decimalCount,
60
+ currencyDecimalSeparator: ((i = e.currency) == null ? void 0 : i.decimalSeparator) ?? p.decimalSeparator,
61
+ currencyThousandSeparator: ((S = e.currency) == null ? void 0 : S.thousandSeparator) ?? p.thousandSeparator
51
62
  };
52
- l.seedBlockUrlConfig(r, p);
63
+ m.seedBlockUrlConfig(r, l);
53
64
  });
54
- try {
55
- await l.fetchRecommendationCreateData();
56
- } catch (t) {
57
- console.warn(
58
- "Recommendation reference data pre-load failed; validator will skip the availability check.",
59
- t
60
- );
61
- }
62
65
  }
63
- const _ = () => {
64
- const i = P(), o = w(), { getCompiledEmail: m, getTemplateData: l } = C(), { compileHtml: t } = T();
66
+ const G = () => {
67
+ const s = L(), t = F(), { getCompiledEmail: a, getTemplateData: m } = E(), { compileHtml: n } = P();
65
68
  return {
66
69
  prepareTemplateDetails: async () => {
67
- const { html: r, ampHtml: a = "", ampErrors: e = [] } = await m({
70
+ const { html: r, ampHtml: o = "", ampErrors: e = [] } = await a({
68
71
  minimize: !0,
69
72
  resetDataSavedFlag: !1
70
- }), { html: p, css: g, syncModulesIds: f = [] } = await l();
71
- o.selectedUnsubscribePages.length && await o.fetchTemplates(), await U(p);
72
- const { compiledHtml: u, stats: n, appliedRules: y } = t(r), h = i.getSelectedDynamicContentList, A = b();
73
+ }), { html: l, css: f, syncModulesIds: g = [] } = await m();
74
+ t.selectedUnsubscribePages.length && await t.fetchTemplates(), x(l);
75
+ const { compiledHtml: d, stats: i, appliedRules: S } = n(r), h = s.getSelectedDynamicContentList, A = b(), T = w(l), C = Object.fromEntries(
76
+ Object.entries(A.recommendationCampaignUrls).filter(([D]) => T.has(Number(D)))
77
+ );
73
78
  return console.debug("HTML Compilation Stats:", {
74
- originalSize: n.originalSize,
75
- compiledSize: n.compiledSize,
76
- reduction: `${n.reductionPercentage.toFixed(2)}%`,
77
- appliedRules: y,
78
- executionTime: `${n.executionTime.toFixed(2)}ms`
79
+ originalSize: i.originalSize,
80
+ compiledSize: i.compiledSize,
81
+ reduction: `${i.reductionPercentage.toFixed(2)}%`,
82
+ appliedRules: S,
83
+ executionTime: `${i.executionTime.toFixed(2)}ms`
79
84
  }), {
80
85
  dynamicContentList: h,
81
- compiledHtml: u,
82
- rawHtml: p,
83
- css: g,
84
- ampHtml: a,
86
+ compiledHtml: d,
87
+ rawHtml: l,
88
+ css: f,
89
+ ampHtml: o,
85
90
  ampErrors: e,
86
- modules: f.map(Number),
91
+ modules: g.map(Number),
87
92
  recommendation: {
88
- campaignUrls: A.recommendationCampaignUrls,
93
+ campaignUrls: C,
89
94
  configs: {}
90
95
  },
91
96
  unsubscribe: {
92
- status: o.unsubscribePagesStatus,
93
- config: E(u, o.selectedUnsubscribePages)
97
+ status: t.unsubscribePagesStatus,
98
+ config: I(d, t.selectedUnsubscribePages)
94
99
  }
95
100
  };
96
101
  }
97
102
  };
98
103
  };
99
104
  export {
100
- _ as useTemplatePreparation
105
+ G as useTemplatePreparation
101
106
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.4.1-beta.5e1fcb5",
3
+ "version": "3.4.1-beta.6ed05e2",
4
4
  "description": "Guido is a Vue + TypeScript wrapper for Email Plugin. Easily embed the email editor in your Vue applications.",
5
5
  "main": "./dist/guido.umd.cjs",
6
6
  "module": "./dist/library.js",
@@ -24,7 +24,7 @@
24
24
  "lint": "NODE_OPTIONS=--max-old-space-size=2048 eslint ./ && bun run type-check",
25
25
  "lint:fix": "NODE_OPTIONS=--max-old-space-size=2048 eslint --fix ./",
26
26
  "type-check": "vue-tsc --noEmit --project tsconfig.config.json && vue-tsc --noEmit --project tsconfig.app.json",
27
- "test": "vitest run",
27
+ "test": "vitest run --coverage",
28
28
  "test:watch": "vitest",
29
29
  "test:visual-update": "npx playwright test --update-snapshots --reporter html",
30
30
  "prepare": "husky",
@@ -61,6 +61,7 @@
61
61
  "@typescript-eslint/parser": "7.18.0",
62
62
  "@useinsider/eslint-config": "1.5.3",
63
63
  "@vitejs/plugin-vue2": "2.3.1",
64
+ "@vitest/coverage-v8": "2.1.9",
64
65
  "eslint": "8.57.1",
65
66
  "eslint-config-airbnb-base": "15.0.0",
66
67
  "eslint-config-airbnb-typescript": "18.0.0",