@useinsider/guido 3.4.1-beta.6ed05e2 → 3.4.1-beta.7f60a52

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.
@@ -216,14 +216,6 @@ 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;
227
219
  /**
228
220
  * Marks a block as initialized (initial API data has been fetched).
229
221
  * Automatically cleaned up when removeBlockState deletes the block entry.
@@ -1,10 +1,11 @@
1
- import type { ImmutableHtmlElementNode } from '@stripoinc/ui-editor-extensions';
1
+ import type { ImmutableHtmlElementNode, ImmutableHtmlNode } from '@stripoinc/ui-editor-extensions';
2
2
  import { Block, BlockCompositionType } from '@stripoinc/ui-editor-extensions';
3
3
  export declare const UNSUBSCRIBE_BLOCK_ID = "unsubscribe-block";
4
4
  export declare class UnsubscribeBlock extends Block {
5
5
  private selectEventListener;
6
6
  private cancelEventListener;
7
7
  private currentNode?;
8
+ private linkStateByBlockId;
8
9
  constructor();
9
10
  getId(): string;
10
11
  getIcon(): string;
@@ -12,9 +13,27 @@ export declare class UnsubscribeBlock extends Block {
12
13
  getName(): string;
13
14
  getDescription(): string;
14
15
  getTemplate(): string;
16
+ getContextActionsIds(): string[];
15
17
  onSelect(node: ImmutableHtmlElementNode): void;
18
+ onDocumentChanged(node: ImmutableHtmlNode): void;
16
19
  onDelete(node: ImmutableHtmlElementNode): void;
17
20
  onDestroy(): void;
21
+ private _hasUnsubscribeLink;
22
+ private _readBlockId;
23
+ /**
24
+ * Returns the block's stable id, assigning one via the document modifier if
25
+ * the node has not been tagged yet. Idempotent: subsequent calls during
26
+ * the same document-change cycle (e.g. reentrant onDocumentChanged after
27
+ * `apply()`) short-circuit on the existing attribute.
28
+ */
29
+ private _getOrAssignBlockId;
30
+ /**
31
+ * Generates a unique id by scanning the document for the highest existing
32
+ * `data-unsubscribe-block-id` and returning max+1. Mirrors the strategy
33
+ * used by RecommendationBlock so reloaded templates don't collide.
34
+ */
35
+ private _generateNextBlockId;
36
+ private _warnLinkRemoved;
18
37
  private _setupSelectEventListener;
19
38
  private _removeSelectEventListener;
20
39
  private _setupCancelEventListener;
@@ -6,4 +6,5 @@ export type UnsubscribeEvent = typeof UNSUBSCRIBE_EVENTS[keyof typeof UNSUBSCRIB
6
6
  export declare const DATA_ATTRIBUTES: {
7
7
  readonly PAGE_TYPE: "data-unsubscribe-page-type";
8
8
  readonly PAGE_LIST: "data-unsubscribe-page-list";
9
+ readonly BLOCK_ID: "data-unsubscribe-block-id";
9
10
  };
@@ -1,106 +1,101 @@
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";
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";
5
4
  import { useRecommendationExtensionStore as b } from "../extensions/Blocks/Recommendation/store/recommendation.js";
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));
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));
16
15
  }
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)
16
+ async function U(i) {
17
+ const m = new DOMParser().parseFromString(i, "text/html").querySelectorAll(".recommendation-block-v2");
18
+ if (m.length === 0)
30
19
  return;
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;
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;
35
24
  if (!Number.isFinite(r))
36
25
  return;
37
- const o = n.getAttribute("esd-ext-config");
38
- if (!o)
26
+ const a = t.getAttribute("esd-ext-config");
27
+ if (!a)
39
28
  return;
40
29
  let e;
41
30
  try {
42
- e = JSON.parse(o);
31
+ e = JSON.parse(a);
43
32
  } catch {
44
33
  return;
45
34
  }
46
35
  if (!e || typeof e != "object" || Array.isArray(e))
47
36
  return;
48
- const l = {
49
- strategy: e.strategy ?? u.strategy,
50
- language: e.language ?? u.language,
51
- size: e.size ?? u.size,
37
+ const p = {
38
+ strategy: e.strategy ?? s.strategy,
39
+ language: e.language ?? s.language,
40
+ size: e.size ?? s.size,
52
41
  // Spread the default arrays so each block gets a fresh reference
53
42
  // instead of sharing the singleton in DEFAULT_NODE_CONFIG.
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
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
62
51
  };
63
- m.seedBlockUrlConfig(r, l);
52
+ l.seedBlockUrlConfig(r, p);
64
53
  });
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
+ }
65
62
  }
66
- const G = () => {
67
- const s = L(), t = F(), { getCompiledEmail: a, getTemplateData: m } = E(), { compileHtml: n } = P();
63
+ const _ = () => {
64
+ const i = P(), o = w(), { getCompiledEmail: m, getTemplateData: l } = C(), { compileHtml: t } = T();
68
65
  return {
69
66
  prepareTemplateDetails: async () => {
70
- const { html: r, ampHtml: o = "", ampErrors: e = [] } = await a({
67
+ const { html: r, ampHtml: a = "", ampErrors: e = [] } = await m({
71
68
  minimize: !0,
72
69
  resetDataSavedFlag: !1
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
- );
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();
78
73
  return console.debug("HTML Compilation Stats:", {
79
- originalSize: i.originalSize,
80
- compiledSize: i.compiledSize,
81
- reduction: `${i.reductionPercentage.toFixed(2)}%`,
82
- appliedRules: S,
83
- executionTime: `${i.executionTime.toFixed(2)}ms`
74
+ originalSize: n.originalSize,
75
+ compiledSize: n.compiledSize,
76
+ reduction: `${n.reductionPercentage.toFixed(2)}%`,
77
+ appliedRules: y,
78
+ executionTime: `${n.executionTime.toFixed(2)}ms`
84
79
  }), {
85
80
  dynamicContentList: h,
86
- compiledHtml: d,
87
- rawHtml: l,
88
- css: f,
89
- ampHtml: o,
81
+ compiledHtml: u,
82
+ rawHtml: p,
83
+ css: g,
84
+ ampHtml: a,
90
85
  ampErrors: e,
91
- modules: g.map(Number),
86
+ modules: f.map(Number),
92
87
  recommendation: {
93
- campaignUrls: C,
88
+ campaignUrls: A.recommendationCampaignUrls,
94
89
  configs: {}
95
90
  },
96
91
  unsubscribe: {
97
- status: t.unsubscribePagesStatus,
98
- config: I(d, t.selectedUnsubscribePages)
92
+ status: o.unsubscribePagesStatus,
93
+ config: E(u, o.selectedUnsubscribePages)
99
94
  }
100
95
  };
101
96
  }
102
97
  };
103
98
  };
104
99
  export {
105
- G as useTemplatePreparation
100
+ _ as useTemplatePreparation
106
101
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.4.1-beta.6ed05e2",
3
+ "version": "3.4.1-beta.7f60a52",
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",