@useinsider/guido 3.24.0-beta.adaba3e → 3.24.0-beta.d510b6c

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 (89) hide show
  1. package/README.md +6 -2
  2. package/dist/@types/config/schemas.js +37 -39
  3. package/dist/components/Guido.vue.js +4 -4
  4. package/dist/components/Guido.vue2.js +92 -98
  5. package/dist/composables/useActionsApi.js +2 -2
  6. package/dist/composables/useBlocksConfig.js +20 -31
  7. package/dist/composables/useEditorTrackingIds.js +49 -0
  8. package/dist/composables/useHtmlCompiler.js +2 -0
  9. package/dist/composables/useStripo.js +70 -70
  10. package/dist/composables/useTranslations.js +1 -2
  11. package/dist/config/compiler/htmlCompilerRules.js +14 -6
  12. package/dist/config/compiler/utils/itemsCompilerUtils.js +42 -43
  13. package/dist/config/compiler/utils/recommendationCompilerUtils.js +64 -67
  14. package/dist/config/migrator/unsubscribeMigrator.js +94 -98
  15. package/dist/enums/academy.js +0 -1
  16. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +10 -8
  17. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +28 -24
  18. package/dist/extensions/Blocks/Recommendation/utils/nodeConfigWriter.js +23 -22
  19. package/dist/extensions/Blocks/Unsubscribe/block.js +104 -96
  20. package/dist/extensions/Blocks/Unsubscribe/utils/constants.js +4 -3
  21. package/dist/extensions/Blocks/Unsubscribe/utils/swapMergeTagInHref.js +5 -0
  22. package/dist/guido.css +1 -1
  23. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +92 -93
  24. package/dist/node_modules/valibot/dist/index.js +261 -297
  25. package/dist/package.json.js +4 -4
  26. package/dist/services/templateLibraryApi.js +39 -36
  27. package/dist/src/@types/config/schemas.d.ts +0 -4
  28. package/dist/src/composables/useConfig.d.ts +0 -2
  29. package/dist/src/composables/useEditorTrackingIds.d.ts +7 -0
  30. package/dist/src/composables/useStripo.d.ts +1 -1
  31. package/dist/src/enums/academy.d.ts +0 -1
  32. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +2 -0
  33. package/dist/src/extensions/Blocks/Unsubscribe/utils/constants.d.ts +1 -0
  34. package/dist/src/extensions/Blocks/Unsubscribe/utils/swapMergeTagInHref.d.ts +1 -0
  35. package/dist/src/stores/config.d.ts +0 -167
  36. package/dist/src/utils/linkTrackingIds.d.ts +24 -22
  37. package/dist/src/utils/trimHrefWhitespace.d.ts +5 -0
  38. package/dist/stores/config.js +6 -13
  39. package/dist/utils/linkTrackingIds.js +72 -72
  40. package/dist/utils/pairProductVariables.js +29 -30
  41. package/dist/utils/templatePreparation.js +59 -72
  42. package/dist/utils/trimHrefWhitespace.js +10 -0
  43. package/package.json +1 -1
  44. package/dist/@types/display-condition.js +0 -25
  45. package/dist/components/organisms/display-conditions/CodeEditorField.vue.js +0 -18
  46. package/dist/components/organisms/display-conditions/CodeEditorField.vue2.js +0 -41
  47. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.js +0 -30
  48. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue2.js +0 -81
  49. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.js +0 -34
  50. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue2.js +0 -63
  51. package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue.js +0 -17
  52. package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue2.js +0 -22
  53. package/dist/composables/useDisplayConditions.js +0 -117
  54. package/dist/enums/display-condition.js +0 -12
  55. package/dist/extensions/DisplayConditions/bridge.js +0 -25
  56. package/dist/extensions/DisplayConditions/constants.js +0 -17
  57. package/dist/extensions/DisplayConditions/control.js +0 -200
  58. package/dist/extensions/DisplayConditions/display-conditions.css.js +0 -201
  59. package/dist/extensions/DisplayConditions/extension.js +0 -28
  60. package/dist/extensions/DisplayConditions/iconsRegistry.js +0 -20
  61. package/dist/extensions/DisplayConditions/library.js +0 -30
  62. package/dist/extensions/DisplayConditions/settingsPanel.js +0 -17
  63. package/dist/extensions/LinkTracking/extension.js +0 -17
  64. package/dist/extensions/LinkTracking/writer.js +0 -41
  65. package/dist/services/displayConditionApi.js +0 -39
  66. package/dist/src/@types/display-condition.d.ts +0 -59
  67. package/dist/src/components/organisms/display-conditions/CodeEditorField.vue.d.ts +0 -43
  68. package/dist/src/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.d.ts +0 -2
  69. package/dist/src/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.d.ts +0 -2
  70. package/dist/src/components/organisms/display-conditions/DisplayConditionsHost.vue.d.ts +0 -2
  71. package/dist/src/composables/useDisplayConditions.d.ts +0 -18
  72. package/dist/src/enums/display-condition.d.ts +0 -15
  73. package/dist/src/extensions/DisplayConditions/bridge.d.ts +0 -7
  74. package/dist/src/extensions/DisplayConditions/constants.d.ts +0 -14
  75. package/dist/src/extensions/DisplayConditions/control.d.ts +0 -25
  76. package/dist/src/extensions/DisplayConditions/extension.d.ts +0 -2
  77. package/dist/src/extensions/DisplayConditions/iconsRegistry.d.ts +0 -4
  78. package/dist/src/extensions/DisplayConditions/library.d.ts +0 -8
  79. package/dist/src/extensions/DisplayConditions/settingsPanel.d.ts +0 -5
  80. package/dist/src/extensions/LinkTracking/extension.d.ts +0 -2
  81. package/dist/src/extensions/LinkTracking/writer.d.ts +0 -13
  82. package/dist/src/mock/api/display-conditions.d.ts +0 -2
  83. package/dist/src/services/displayConditionApi.d.ts +0 -8
  84. package/dist/src/stores/display-condition.d.ts +0 -84
  85. package/dist/src/utils/displayCondition.d.ts +0 -11
  86. package/dist/src/utils/protectTableText.d.ts +0 -2
  87. package/dist/stores/display-condition.js +0 -29
  88. package/dist/utils/displayCondition.js +0 -26
  89. package/dist/utils/protectTableText.js +0 -22
@@ -1,6 +1,6 @@
1
1
  import { useToaster as L } from "../../../../composables/useToaster.js";
2
2
  import { useTranslations as U } from "../../../../composables/useTranslations.js";
3
- import { getRecommendationFeedSourceMaps as F, strategyEditPath as z, strategyCreatePath as B, getOperatorOptions as M, PriceAttributes as N } from "../../../../enums/extensions/recommendationBlock.js";
3
+ import { getRecommendationFeedSourceMaps as w, strategyEditPath as z, strategyCreatePath as B, getOperatorOptions as M, PriceAttributes as N } from "../../../../enums/extensions/recommendationBlock.js";
4
4
  import { ToasterTypeOptions as E } from "../../../../enums/toaster.js";
5
5
  import { useRecommendationApi as O } from "../../../../services/recommendationApi.js";
6
6
  import { useConfigStore as R } from "../../../../stores/config.js";
@@ -8,21 +8,21 @@ import { defineStore as V } from "pinia";
8
8
  import "../constants/selectors.js";
9
9
  import { DEFAULT_MOBILE_CARDS_IN_ROW as A, DEFAULT_CARDS_IN_ROW as x } from "../constants/layout.js";
10
10
  import { CURRENT_CONFIG_VERSION as C, DEFAULT_NODE_CONFIG as T, EXCLUDED_ALGORITHM_IDS as j } from "../constants/defaultConfig.js";
11
- import { getDefaultProducts as w } from "../templates/utils.js";
11
+ import { getDefaultProducts as F } from "../templates/utils.js";
12
12
  import { generateCompleteFilterQuery as P } from "../utils/filterUtil.js";
13
13
  import { isLegacyStrategyConfig as $ } from "../utils/legacyStrategyMigration.js";
14
14
  import { getPartnerRecommendationParams as q } from "../utils/partnerCustomizations.js";
15
15
  import { sanitizeProductIds as K } from "../utils/productIds.js";
16
16
  import { isFilterValid as H } from "../validation/filterSchema.js";
17
17
  import { getInvalidFields as J, isConfigValid as Q } from "../validation/requiredFields.js";
18
- const m = O();
18
+ const u = O();
19
19
  let p = null, y = null;
20
20
  const I = /* @__PURE__ */ new Map();
21
21
  let k = null, b = 0;
22
- const u = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Map();
22
+ const m = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Map();
23
23
  function W(t) {
24
24
  const e = _.get(t);
25
- return e && e.token === u.get(t) ? e.outcome : !1;
25
+ return e && e.token === m.get(t) ? e.outcome : !1;
26
26
  }
27
27
  let l = null;
28
28
  const X = () => {
@@ -80,7 +80,8 @@ function G() {
80
80
  syncedConfigFingerprint: null,
81
81
  legacyConversionLoading: !1,
82
82
  configVersion: 0,
83
- adoptedSizeVersion: 0
83
+ adoptedSizeVersion: 0,
84
+ drawnProducts: null
84
85
  };
85
86
  }
86
87
  const Y = () => ({
@@ -173,7 +174,7 @@ const Y = () => ({
173
174
  return [...new Set(t.map((e) => e.filterGroup))].sort((e, n) => e - n);
174
175
  },
175
176
  getActivePredictiveAlgorithms: (t) => {
176
- const e = F(), n = [];
177
+ const e = w(), n = [];
177
178
  return t.activePredictiveAlgorithms.filter((r) => !j.includes(r)).forEach((r) => {
178
179
  n.push(...e.filter((o) => o.id === r));
179
180
  }), n.map((r) => ({
@@ -245,7 +246,7 @@ const Y = () => ({
245
246
  const n = this.blockStates[t];
246
247
  if (n) {
247
248
  const s = structuredClone(n);
248
- s.recommendationConfigs.id = e, s.recommendationConfigs.strategyId && R().isFeatureEnabled("reusableRecommendationStrategy") && (s.isInitialized = !1, s.syncedConfigFingerprint = null), this.blockStates = {
249
+ s.recommendationConfigs.id = e, s.drawnProducts = null, s.recommendationConfigs.strategyId && R().isFeatureEnabled("reusableRecommendationStrategy") && (s.isInitialized = !1, s.syncedConfigFingerprint = null), this.blockStates = {
249
250
  ...this.blockStates,
250
251
  [e]: s
251
252
  };
@@ -256,6 +257,9 @@ const Y = () => ({
256
257
  [o]: i
257
258
  });
258
259
  },
260
+ markProductsDrawn(t, e) {
261
+ this.blockStates[t] && (this.blockStates[t].drawnProducts = e);
262
+ },
259
263
  /**
260
264
  * Marks a block as initialized (initial API data has been fetched).
261
265
  * Automatically cleaned up when removeBlockState deletes the block entry.
@@ -401,7 +405,7 @@ const Y = () => ({
401
405
  const t = b, e = (async () => {
402
406
  this.strategiesLoading = !0;
403
407
  try {
404
- const n = await m.fetchRecommendationStrategies();
408
+ const n = await u.fetchRecommendationStrategies();
405
409
  if (t !== b)
406
410
  return;
407
411
  this.strategies = n, this.strategiesFetched = !0;
@@ -495,7 +499,7 @@ const Y = () => ({
495
499
  const n = typeof t.updated_at == "string" ? t.updated_at : "", r = n ? `${t.strategy_id}:${n}:${e}` : "", o = r ? this.strategyUrlTemplates[r] : void 0;
496
500
  if (o)
497
501
  return o;
498
- const { full_path: i = "" } = await m.generateStrategyEndpoint(t, e) ?? {};
502
+ const { full_path: i = "" } = await u.generateStrategyEndpoint(t, e) ?? {};
499
503
  return r && i && (this.strategyUrlTemplates = {
500
504
  ...this.strategyUrlTemplates,
501
505
  [r]: i
@@ -513,7 +517,7 @@ const Y = () => ({
513
517
  throw new Error("[Guido] convertLegacyStrategy called without an active block");
514
518
  this.blockStates[n].legacyConversionLoading = !0;
515
519
  try {
516
- const r = await m.migrateLegacyStrategy(t, e);
520
+ const r = await u.migrateLegacyStrategy(t, e);
517
521
  this.invalidateStrategies();
518
522
  try {
519
523
  await this.fetchStrategies();
@@ -562,7 +566,7 @@ const Y = () => ({
562
566
  activePredictiveAlgorithms: t,
563
567
  languages: e,
564
568
  currencies: n
565
- } = await m.fetchRecommendationCreateData();
569
+ } = await u.fetchRecommendationCreateData();
566
570
  if (this.activePredictiveAlgorithms = t, this.languages = e, this.currentRecommendationId !== null && this.blockStates[this.currentRecommendationId]) {
567
571
  const r = this.blockStates[this.currentRecommendationId];
568
572
  r.filterStatus = !!r.recommendationConfigs.filters.length;
@@ -583,7 +587,7 @@ const Y = () => ({
583
587
  return;
584
588
  }
585
589
  y = (async () => {
586
- const t = await m.fetchRecommendationFilters();
590
+ const t = await u.fetchRecommendationFilters();
587
591
  this.filterList = t;
588
592
  })();
589
593
  try {
@@ -709,14 +713,14 @@ const Y = () => ({
709
713
  await this._doFetchStrategyProducts(e);
710
714
  return;
711
715
  }
712
- const i = (u.get(e) ?? 0) + 1;
713
- u.set(e, i);
716
+ const i = (m.get(e) ?? 0) + 1;
717
+ m.set(e, i);
714
718
  const s = parseInt(r.size) || 6;
715
719
  if (!r.strategy) {
716
720
  this._setBlockProducts(e, [], s);
717
721
  return;
718
722
  }
719
- const a = r.filters.filter((h) => h.isValid), d = P(a), f = ((S = F().find((h) => h.key === r.strategy)) == null ? void 0 : S.path) || "", c = {
723
+ const a = r.filters.filter((h) => h.isValid), d = P(a), f = ((S = w().find((h) => h.key === r.strategy)) == null ? void 0 : S.path) || "", c = {
720
724
  locale: r.language,
721
725
  currency: r.currencySettings.value,
722
726
  partnerName: o.partnerName,
@@ -730,11 +734,11 @@ const Y = () => ({
730
734
  );
731
735
  let g;
732
736
  try {
733
- g = await m.fetchRecommendationProducts(f, c);
737
+ g = await u.fetchRecommendationProducts(f, c);
734
738
  } catch {
735
739
  g = [];
736
740
  }
737
- u.get(e) === i && this._setBlockProducts(e, g, s);
741
+ m.get(e) === i && this._setBlockProducts(e, g, s);
738
742
  },
739
743
  /**
740
744
  * Block-scoped counterpart of `fetchRecommendationProducts`, which only serves the selected block:
@@ -773,8 +777,8 @@ const Y = () => ({
773
777
  return !0;
774
778
  },
775
779
  _doFetchStrategyProducts(t, e = {}) {
776
- const n = (u.get(t) ?? 0) + 1;
777
- u.set(t, n);
780
+ const n = (m.get(t) ?? 0) + 1;
781
+ m.set(t, n);
778
782
  const r = this._loadStrategyProducts(t, n, e);
779
783
  return _.set(t, { token: n, outcome: r }), r;
780
784
  },
@@ -789,20 +793,20 @@ const Y = () => ({
789
793
  if (s) {
790
794
  i = parseInt(String(s.size ?? "")) || i;
791
795
  const a = r.currencySettings.value, f = (await this.resolveStrategyUrlTemplate(s, a)).replaceAll("{locale}", r.language).replaceAll("{currency}", a), c = f.indexOf("?"), g = c === -1 ? f : f.slice(0, c), S = (c === -1 ? "" : f.slice(c + 1)).split("&").filter((v) => v && !v.startsWith("user_id=")), h = S.length ? `${g}?${S.join("&")}` : g;
792
- h && (o = await m.fetchRecommendationProductsByUrl(h));
796
+ h && (o = await u.fetchRecommendationProductsByUrl(h));
793
797
  }
794
798
  } catch {
795
799
  o = [];
796
800
  }
797
- return u.get(t) !== e ? W(t) : !o.length && n ? !1 : (this._setBlockProducts(t, o, i), o.length > 0);
801
+ return m.get(t) !== e ? W(t) : !o.length && n ? !1 : (this._setBlockProducts(t, o, i), o.length > 0);
798
802
  },
799
803
  _setBlockProducts(t, e, n) {
800
804
  if (!this.blockStates[t])
801
805
  return;
802
- const r = e.length > 0 ? e : w(n);
806
+ const r = e.length > 0 ? e : F(n);
803
807
  this.blockStates[t].recommendationProducts = [
804
808
  ...r.slice(0, n),
805
- ...w(Math.max(0, n - r.length))
809
+ ...F(Math.max(0, n - r.length))
806
810
  ];
807
811
  }
808
812
  }
@@ -1,13 +1,13 @@
1
1
  import { ModificationDescription as a } from "../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
2
2
  import { RECOMMENDATION_ID_ATTR as m } from "../constants/selectors.js";
3
- import { isPartnerManagedBlock as y, updateProductContentInPlace as I, regenerateProductRowsWithStyles as N } from "../controls/main/utils.js";
3
+ import { isPartnerManagedBlock as N, updateProductContentInPlace as I, regenerateProductRowsWithStyles as O } from "../controls/main/utils.js";
4
4
  import { RecommendationConfigService as c } from "../services/configService.js";
5
- import { useRecommendationExtensionStore as O } from "../store/recommendation.js";
5
+ import { useRecommendationExtensionStore as C } from "../store/recommendation.js";
6
6
  let r = null;
7
- function $(t) {
7
+ function T(t) {
8
8
  r = t;
9
9
  }
10
- function C(t) {
10
+ function p(t) {
11
11
  const n = r == null ? void 0 : r.getDocumentRootHtmlNode();
12
12
  return !n || !("querySelector" in n) ? null : n.querySelector(`[${m}="${t}"]`) ?? null;
13
13
  }
@@ -19,18 +19,18 @@ function R(t, n) {
19
19
  const o = c.getConfig(t);
20
20
  return ["filters", "strategy", "strategyId", "size", "productIds"].some((e) => e in n && JSON.stringify(o[e]) !== JSON.stringify(n[e]));
21
21
  }
22
- const p = "Updated product IDs";
23
- function S(t, n) {
22
+ const S = "Updated product IDs";
23
+ function y(t, n) {
24
24
  if (!("productIds" in n))
25
25
  return !1;
26
26
  const o = c.getConfig(t);
27
27
  return JSON.stringify(o.productIds) !== JSON.stringify(n.productIds);
28
28
  }
29
29
  function h(t, n, o) {
30
- return S(t, n) ? p : o;
30
+ return y(t, n) ? S : o;
31
31
  }
32
- function k(t, n, o) {
33
- const e = C(t);
32
+ function $(t, n, o) {
33
+ const e = p(t);
34
34
  if (!r || !e)
35
35
  return !1;
36
36
  if (R(e, n)) {
@@ -40,7 +40,7 @@ function k(t, n, o) {
40
40
  return !0;
41
41
  }
42
42
  function P(t, n) {
43
- const o = O(), e = o.currentRecommendationId;
43
+ const o = C(), e = o.currentRecommendationId;
44
44
  if (e === t || !o.blockStates[t]) {
45
45
  n();
46
46
  return;
@@ -52,16 +52,17 @@ function P(t, n) {
52
52
  o.$patch({ currentRecommendationId: e });
53
53
  }
54
54
  }
55
- function q(t) {
55
+ function k(t) {
56
56
  const n = r == null ? void 0 : r.getDocumentRootHtmlNode();
57
57
  return !n || !("querySelectorAll" in n) ? [] : n.querySelectorAll(`[${m}="${t}"]`).map((o) => c.getConfig(o));
58
58
  }
59
- function w(t, n, o, e) {
60
- const i = C(t);
59
+ function q(t, n, o, e) {
60
+ const i = p(t);
61
61
  if (!r || !i)
62
62
  return !1;
63
- const f = r.getDocumentModifier(), d = D(i, n), g = S(i, n), s = g ? p : e, l = { currentNode: i, documentModifier: f, products: o, ...g ? { description: s } : {} };
64
- if (c.stageConfig(f, i, n), y(i))
63
+ C().markProductsDrawn(t, o);
64
+ const f = r.getDocumentModifier(), d = D(i, n), g = y(i, n), s = g ? S : e, l = { currentNode: i, documentModifier: f, products: o, ...g ? { description: s } : {} };
65
+ if (c.stageConfig(f, i, n), N(i))
65
66
  return d && f.apply(new a(s)), !0;
66
67
  let u = !1;
67
68
  return P(t, () => {
@@ -70,16 +71,16 @@ function w(t, n, o, e) {
70
71
  onApplied: () => {
71
72
  u = !0;
72
73
  }
73
- }) || (u = N(l));
74
+ }) || (u = O(l));
74
75
  }), !u && d && f.apply(new a(s)), !0;
75
76
  }
76
77
  export {
77
- p as PRODUCT_IDS_DESCRIPTION,
78
- w as commitBlockChangeOutsidePanel,
78
+ S as PRODUCT_IDS_DESCRIPTION,
79
+ q as commitBlockChangeOutsidePanel,
79
80
  R as hasEditedConfigChange,
80
- S as isProductIdsChange,
81
+ y as isProductIdsChange,
81
82
  h as pickConfigDescription,
82
- q as readBlockNodeConfigs,
83
- $ as registerNodeConfigWriter,
84
- k as writeBlockConfigOutsidePanel
83
+ k as readBlockNodeConfigs,
84
+ T as registerNodeConfigWriter,
85
+ $ as writeBlockConfigOutsidePanel
85
86
  };
@@ -1,48 +1,49 @@
1
- var y = Object.defineProperty;
2
- var I = (c, o, e) => o in c ? y(c, o, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[o] = e;
3
- var g = (c, o, e) => I(c, typeof o != "symbol" ? o + "" : o, e);
4
- import { useToaster as L } from "../../../composables/useToaster.js";
5
- import { ToasterTypeOptions as C } from "../../../enums/toaster.js";
6
- import { PAGE_TYPES as m } from "../../../enums/unsubscribe.js";
7
- import { useEditorStore as N } from "../../../stores/editor.js";
8
- import { useUnsubscribeStore as a } from "../../../stores/unsubscribe.js";
9
- import { Block as U, BlockCompositionType as R, ContextActionType as f, ModificationDescription as u, BlockType as v } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
10
- import { getDefaultTemplate as D } from "./template.js";
11
- import { UNSUBSCRIBE_BLOCK_SELECTOR as B, DATA_ATTRIBUTES as n, UNSUBSCRIBE_EVENTS as h } from "./utils/constants.js";
12
- import { parsePageList as S } from "./utils/utils.js";
13
- const w = "unsubscribe-block", E = 'a[data-unsubscribe-link="true"]', P = "{{ins-unsubscribe-link}}", x = "https://academy.insiderone.com/docs/adding-unsubscribe-pages-into-emails", G = "Removing the unsubscribe text leaves an empty block, but an active unsubscribe link is required. Undo your last action to restore the text, or delete the unsubscribe block entirely.", M = {
14
- [m.GLOBAL_UNSUBSCRIBE]: "{{ins-global-unsubscribe-link}}",
15
- [m.SUBSCRIPTION_PREFERENCE_CENTER]: "{{ins-preferences-unsubscribe-link}}"
16
- }, O = 3;
17
- let d = null, p = null;
18
- const A = () => {
19
- d && (document.removeEventListener(h.SELECT, d), d = null);
20
- }, T = () => {
21
- p && (document.removeEventListener(h.CANCEL, p), p = null);
22
- }, q = () => {
23
- A(), T();
1
+ var R = Object.defineProperty;
2
+ var v = (l, c, e) => c in l ? R(l, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[c] = e;
3
+ var h = (l, c, e) => v(l, typeof c != "symbol" ? c + "" : c, e);
4
+ import { useToaster as D } from "../../../composables/useToaster.js";
5
+ import { ToasterTypeOptions as w } from "../../../enums/toaster.js";
6
+ import { PAGE_TYPES as B } from "../../../enums/unsubscribe.js";
7
+ import { useEditorStore as G } from "../../../stores/editor.js";
8
+ import { useUnsubscribeStore as u } from "../../../stores/unsubscribe.js";
9
+ import { Block as P, BlockCompositionType as x, ContextActionType as y, ModificationDescription as k, BlockType as M } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
10
+ import { getDefaultTemplate as O } from "./template.js";
11
+ import { UNSUBSCRIBE_BLOCK_SELECTOR as f, DATA_ATTRIBUTES as o, UNSUBSCRIBE_EVENTS as E, UNSUBSCRIBE_MERGE_TAG_REGEX as I } from "./utils/constants.js";
12
+ import { swapMergeTagInHref as q } from "./utils/swapMergeTagInHref.js";
13
+ import { parsePageList as L } from "./utils/utils.js";
14
+ const F = "unsubscribe-block", _ = 'a[data-unsubscribe-link="true"]', C = "{{ins-unsubscribe-link}}", K = "https://academy.insiderone.com/docs/adding-unsubscribe-pages-into-emails", H = "Removing the unsubscribe text leaves an empty block, but an active unsubscribe link is required. Undo your last action to restore the text, or delete the unsubscribe block entirely.", Y = {
15
+ [B.GLOBAL_UNSUBSCRIBE]: "{{ins-global-unsubscribe-link}}",
16
+ [B.SUBSCRIPTION_PREFERENCE_CENTER]: "{{ins-preferences-unsubscribe-link}}"
17
+ }, V = 3;
18
+ let d = null, b = null;
19
+ const N = () => {
20
+ d && (document.removeEventListener(E.SELECT, d), d = null);
21
+ }, U = () => {
22
+ b && (document.removeEventListener(E.CANCEL, b), b = null);
23
+ }, W = () => {
24
+ N(), U();
24
25
  };
25
- class J extends U {
26
+ class se extends P {
26
27
  constructor() {
27
28
  super();
28
- g(this, "currentNode");
29
+ h(this, "currentNode");
29
30
  // Per-block "did this instance have a link last time we saw it?" tracking.
30
31
  // Keyed by the stable `data-unsubscribe-block-id` we assign, because
31
32
  // ImmutableHtmlNode instances are recreated on every document mutation and
32
33
  // can't be used as Map keys directly. A singleton boolean here would be
33
34
  // polluted across blocks since Stripo fires onDocumentChanged per-instance.
34
- g(this, "linkStateByBlockId", /* @__PURE__ */ new Map());
35
+ h(this, "linkStateByBlockId", /* @__PURE__ */ new Map());
35
36
  // Per-block prepend retry counter for the leading text guard (SD-143097).
36
- g(this, "guardAttemptsByBlockId", /* @__PURE__ */ new Map());
37
+ h(this, "guardAttemptsByBlockId", /* @__PURE__ */ new Map());
37
38
  }
38
39
  getId() {
39
- return w;
40
+ return F;
40
41
  }
41
42
  getIcon() {
42
43
  return "unsubscribe-icon";
43
44
  }
44
45
  getBlockCompositionType() {
45
- return R.BLOCK;
46
+ return x.BLOCK;
46
47
  }
47
48
  getName() {
48
49
  return this.api.translate("Unsubscribe Block");
@@ -51,16 +52,16 @@ class J extends U {
51
52
  return this.api.translate("Unsubscribe Block Description");
52
53
  }
53
54
  getTemplate() {
54
- return D();
55
+ return O();
55
56
  }
56
57
  getContextActionsIds() {
57
- return [f.MOVE, f.REMOVE];
58
+ return [y.MOVE, y.REMOVE];
58
59
  }
59
60
  onSelect(e) {
60
- if (this.currentNode = e, N().isPreviewModeOpen)
61
+ if (this.currentNode = e, G().isPreviewModeOpen)
61
62
  return;
62
63
  const t = this._getOrAssignBlockId(e);
63
- t && this.linkStateByBlockId.set(t, this._hasUnsubscribeLink(e)), this._setupSelectEventListener(), this._setupCancelEventListener(t), !("getAttribute" in e && e.getAttribute("data-migration")) && (this._resetStoreState(), t && (a().pendingBlockId = t), this._loadBlockState(e), this._checkExistingBlocks(), this._openDrawer());
64
+ t && this.linkStateByBlockId.set(t, this._hasUnsubscribeLink(e)), this._setupSelectEventListener(), this._setupCancelEventListener(t), !("getAttribute" in e && e.getAttribute("data-migration")) && (this._resetStoreState(), t && (u().pendingBlockId = t), this._loadBlockState(e), this._checkExistingBlocks(), this._openDrawer());
64
65
  }
65
66
  onCreated(e) {
66
67
  this._ensureLeadingTextGuard(e);
@@ -68,7 +69,7 @@ class J extends U {
68
69
  onDocumentInit() {
69
70
  try {
70
71
  const e = this.api.getDocumentRoot();
71
- e && "querySelectorAll" in e && e.querySelectorAll(B).forEach((t) => {
72
+ e && "querySelectorAll" in e && e.querySelectorAll(f).forEach((t) => {
72
73
  this._ensureLeadingTextGuard(t);
73
74
  });
74
75
  } catch {
@@ -79,11 +80,11 @@ class J extends U {
79
80
  const t = this._getOrAssignBlockId(e);
80
81
  if (!t)
81
82
  return;
82
- const s = this._hasUnsubscribeLink(e);
83
- this.linkStateByBlockId.get(t) === !0 && !s && this._warnLinkRemoved(), this.linkStateByBlockId.set(t, s);
83
+ const i = this._hasUnsubscribeLink(e);
84
+ this.linkStateByBlockId.get(t) === !0 && !i && this._warnLinkRemoved(), this.linkStateByBlockId.set(t, i);
84
85
  }
85
86
  onDelete(e) {
86
- q(), this._removeBlockTemplatesFromStore(e), this._resetStoreState();
87
+ W(), this._removeBlockTemplatesFromStore(e), this._resetStoreState();
87
88
  const t = this._readBlockId(e);
88
89
  t && (this.linkStateByBlockId.delete(t), this.guardAttemptsByBlockId.delete(t));
89
90
  }
@@ -95,38 +96,38 @@ class J extends U {
95
96
  _ensureLeadingTextGuard(e) {
96
97
  if (!("querySelector" in e))
97
98
  return;
98
- const t = e.querySelector(E);
99
+ const t = e.querySelector(_);
99
100
  if (!t)
100
101
  return;
101
- let s = t, r = s.parent();
102
+ let i = t, r = i.parent();
102
103
  for (; r && "getTagName" in r && r.getTagName().toLowerCase() !== "p"; )
103
- s = r, r = r.parent();
104
+ i = r, r = r.parent();
104
105
  if (!r || !("getTagName" in r) || r.getTagName().toLowerCase() !== "p")
105
106
  return;
106
- const i = s.previousSibling();
107
- if (!!(i && i.getType() === "text" && i.getTextContent())) {
108
- const b = this._readBlockId(e);
109
- b && this.guardAttemptsByBlockId.delete(b);
107
+ const s = i.previousSibling();
108
+ if (!!(s && s.getType() === "text" && s.getTextContent())) {
109
+ const a = this._readBlockId(e);
110
+ a && this.guardAttemptsByBlockId.delete(a);
110
111
  return;
111
112
  }
112
- const k = this._getOrAssignBlockId(e);
113
- if (!k)
113
+ const g = this._getOrAssignBlockId(e);
114
+ if (!g)
114
115
  return;
115
- const _ = this.guardAttemptsByBlockId.get(k) ?? 0;
116
- if (!(_ >= O)) {
117
- this.guardAttemptsByBlockId.set(k, _ + 1);
116
+ const p = this.guardAttemptsByBlockId.get(g) ?? 0;
117
+ if (!(p >= V)) {
118
+ this.guardAttemptsByBlockId.set(g, p + 1);
118
119
  try {
119
- this.api.getDocumentModifier().modifyHtml(r).prepend(" ").apply(new u("Ensure unsubscribe link text guard"));
120
- } catch (b) {
121
- console.warn("[UnsubscribeBlock] Failed to ensure link text guard:", b);
120
+ this.api.getDocumentModifier().modifyHtml(r).prepend(" ").apply(new k("Ensure unsubscribe link text guard"));
121
+ } catch (a) {
122
+ console.warn("[UnsubscribeBlock] Failed to ensure link text guard:", a);
122
123
  }
123
124
  }
124
125
  }
125
126
  _hasUnsubscribeLink(e) {
126
- return "querySelector" in e ? !!e.querySelector(E) : !1;
127
+ return "querySelector" in e ? !!e.querySelector(_) : !1;
127
128
  }
128
129
  _readBlockId(e) {
129
- return "getAttribute" in e ? e.getAttribute(n.BLOCK_ID) : null;
130
+ return "getAttribute" in e ? e.getAttribute(o.BLOCK_ID) : null;
130
131
  }
131
132
  /**
132
133
  * Returns the block's stable id, assigning one via the document modifier if
@@ -140,13 +141,13 @@ class J extends U {
140
141
  return t;
141
142
  if (!("getAttribute" in e))
142
143
  return null;
143
- const s = this._generateNextBlockId();
144
+ const i = this._generateNextBlockId();
144
145
  try {
145
- this.api.getDocumentModifier().modifyHtml(e).setAttribute(n.BLOCK_ID, s).apply(new u(`Assign unsubscribe block id ${s}`));
146
+ this.api.getDocumentModifier().modifyHtml(e).setAttribute(o.BLOCK_ID, i).apply(new k(`Assign unsubscribe block id ${i}`));
146
147
  } catch (r) {
147
148
  return console.warn("[UnsubscribeBlock] Failed to assign block id:", r), null;
148
149
  }
149
- return s;
150
+ return i;
150
151
  }
151
152
  /**
152
153
  * Generates a unique id by scanning the document for the highest existing
@@ -157,10 +158,10 @@ class J extends U {
157
158
  let e = 0;
158
159
  try {
159
160
  const t = this.api.getDocumentRoot();
160
- t && "querySelectorAll" in t && t.querySelectorAll(B).forEach((r) => {
161
+ t && "querySelectorAll" in t && t.querySelectorAll(f).forEach((r) => {
161
162
  if ("getAttribute" in r) {
162
- const i = r.getAttribute(n.BLOCK_ID), l = i ? parseInt(i) : 0;
163
- l > e && (e = l);
163
+ const s = r.getAttribute(o.BLOCK_ID), n = s ? parseInt(s) : 0;
164
+ n > e && (e = n);
164
165
  }
165
166
  });
166
167
  } catch {
@@ -169,14 +170,14 @@ class J extends U {
169
170
  }
170
171
  _warnLinkRemoved() {
171
172
  try {
172
- const { showToaster: e } = L();
173
+ const { showToaster: e } = D();
173
174
  e({
174
- type: C.Warning,
175
- message: this.api.translate(G),
175
+ type: w.Warning,
176
+ message: this.api.translate(H),
176
177
  actionButton: {
177
178
  text: this.api.translate("Visit Academy"),
178
179
  onClick: () => {
179
- window.open(x, "_blank", "noopener,noreferrer");
180
+ window.open(K, "_blank", "noopener,noreferrer");
180
181
  }
181
182
  }
182
183
  });
@@ -185,55 +186,62 @@ class J extends U {
185
186
  }
186
187
  }
187
188
  _setupSelectEventListener() {
188
- A(), d = (e) => {
189
- const t = e, { collectionType: s, selectedPages: r } = t.detail;
190
- this._updateBlock(s, r.join(","));
191
- }, document.addEventListener(h.SELECT, d);
189
+ N(), d = (e) => {
190
+ const t = e, { collectionType: i, selectedPages: r } = t.detail;
191
+ this._updateBlock(i, r.join(","));
192
+ }, document.addEventListener(E.SELECT, d);
192
193
  }
193
194
  _setupCancelEventListener(e) {
194
- T(), p = (t) => {
195
- const { detail: s } = t;
196
- ((s == null ? void 0 : s.blockId) ?? null) === e && this._handleCancel();
197
- }, document.addEventListener(h.CANCEL, p);
195
+ U(), b = (t) => {
196
+ const { detail: i } = t;
197
+ ((i == null ? void 0 : i.blockId) ?? null) === e && this._handleCancel();
198
+ }, document.addEventListener(E.CANCEL, b);
198
199
  }
199
200
  _handleCancel() {
200
201
  try {
201
202
  if (!this.currentNode)
202
203
  return;
203
- this.api.getDocumentModifier().modifyHtml(this.currentNode).replaceWith(`<${v.EMPTY_CONTAINER}/>`).apply(new u("Removed unsubscribe block due to cancel"));
204
+ this.api.getDocumentModifier().modifyHtml(this.currentNode).replaceWith(`<${M.EMPTY_CONTAINER}/>`).apply(new k("Removed unsubscribe block due to cancel"));
204
205
  } catch (e) {
205
206
  console.warn("[UnsubscribeBlock] Failed to remove unsubscribe block:", e);
206
207
  }
207
208
  }
208
209
  _updateBlock(e, t) {
210
+ var a;
209
211
  if (!this.currentNode || !("querySelector" in this.currentNode))
210
212
  return;
211
- const s = this.currentNode.querySelector(E);
212
- if (!s)
213
+ const i = this.currentNode.querySelector(_);
214
+ if (!i)
213
215
  return;
214
- const r = this._getMergeTag(e);
215
- this.api.getDocumentModifier().modifyHtml(s).setAttribute("href", r).apply(new u(`Updated unsubscribe link to ${r}`)), this.api.getDocumentModifier().modifyHtml(this.currentNode).setAttribute(n.PAGE_TYPE, e.toString()).setAttribute(n.PAGE_LIST, t).apply(new u("Updated unsubscribe block metadata"));
216
+ const r = this._getMergeTag(e), s = this.api.getDocumentModifier(), n = "getAttribute" in i ? i.getAttribute("href") : null, p = [(a = n == null ? void 0 : n.match(I)) == null ? void 0 : a[0], C];
217
+ s.modifyHtml(i).setAttribute("href", r), this.currentNode.querySelectorAll("a[href]").forEach((m) => {
218
+ var T;
219
+ if (!("getAttribute" in m) || m.getAttribute("data-unsubscribe-link") === "true")
220
+ return;
221
+ const S = m.getAttribute("href") ?? "", A = (T = S.match(I)) == null ? void 0 : T[0];
222
+ A && p.includes(A) && s.modifyHtml(m).setAttribute("href", q(S, r));
223
+ }), s.modifyHtml(this.currentNode).setAttribute(o.PAGE_TYPE, e.toString()).setAttribute(o.PAGE_LIST, t), s.apply(new k(`Updated unsubscribe link to ${r}`));
216
224
  }
217
225
  _getMergeTag(e) {
218
- return M[e] ?? P;
226
+ return Y[e] ?? C;
219
227
  }
220
228
  _openDrawer() {
221
229
  if (!(this.currentNode && this.currentNode.getAttribute("data-unsubscribe-page-type")))
222
230
  try {
223
- const e = a();
231
+ const e = u();
224
232
  e.typeSelectionDrawerStatus = !0;
225
233
  } catch (e) {
226
234
  console.error("[UnsubscribeBlock] Failed to open drawer:", e);
227
235
  }
228
236
  }
229
237
  _checkExistingBlocks() {
230
- const e = a();
231
- e.isGlobalUnsubscribeDisabled = !1, e.isSubscriptionPreferencesCenterDisabled = !1, this.api.getDocumentRoot().querySelectorAll(B).forEach((s) => {
232
- if ("getAttribute" in s) {
233
- const r = s.getAttribute(n.PAGE_TYPE);
238
+ const e = u();
239
+ e.isGlobalUnsubscribeDisabled = !1, e.isSubscriptionPreferencesCenterDisabled = !1, this.api.getDocumentRoot().querySelectorAll(f).forEach((i) => {
240
+ if ("getAttribute" in i) {
241
+ const r = i.getAttribute(o.PAGE_TYPE);
234
242
  if (r) {
235
- const i = Number(r);
236
- i === m.GLOBAL_UNSUBSCRIBE ? e.isGlobalUnsubscribeDisabled = !0 : i === m.SUBSCRIPTION_PREFERENCE_CENTER && (e.isSubscriptionPreferencesCenterDisabled = !0);
243
+ const s = Number(r);
244
+ s === B.GLOBAL_UNSUBSCRIBE ? e.isGlobalUnsubscribeDisabled = !0 : s === B.SUBSCRIPTION_PREFERENCE_CENTER && (e.isSubscriptionPreferencesCenterDisabled = !0);
237
245
  }
238
246
  }
239
247
  });
@@ -241,27 +249,27 @@ class J extends U {
241
249
  async _loadBlockState(e) {
242
250
  if (!("getAttribute" in e))
243
251
  return;
244
- const t = e.getAttribute(n.PAGE_TYPE), s = e.getAttribute(n.PAGE_LIST);
245
- if (!t || !s)
252
+ const t = e.getAttribute(o.PAGE_TYPE), i = e.getAttribute(o.PAGE_LIST);
253
+ if (!t || !i)
246
254
  return;
247
- const r = a(), i = Number(t), l = S(s);
248
- await r.fetchTemplates(), r.setCollectionWithoutAutoSelection(i), r.loadSelectedTemplates(l);
255
+ const r = u(), s = Number(t), n = L(i);
256
+ await r.fetchTemplates(), r.setCollectionWithoutAutoSelection(s), r.loadSelectedTemplates(n);
249
257
  }
250
258
  _resetStoreState() {
251
- a().$reset();
259
+ u().$reset();
252
260
  }
253
261
  _removeBlockTemplatesFromStore(e) {
254
262
  if (!("getAttribute" in e))
255
263
  return;
256
- const t = e.getAttribute(n.PAGE_LIST);
264
+ const t = e.getAttribute(o.PAGE_LIST);
257
265
  if (!t)
258
266
  return;
259
- const s = a(), r = S(t);
260
- s.removeUnsubscribePages(r);
267
+ const i = u(), r = L(t);
268
+ i.removeUnsubscribePages(r);
261
269
  }
262
270
  }
263
271
  export {
264
- w as UNSUBSCRIBE_BLOCK_ID,
265
- J as UnsubscribeBlock,
266
- q as disposeUnsubscribeListeners
272
+ F as UNSUBSCRIBE_BLOCK_ID,
273
+ se as UnsubscribeBlock,
274
+ W as disposeUnsubscribeListeners
267
275
  };
@@ -5,10 +5,11 @@ const s = {
5
5
  PAGE_TYPE: "data-unsubscribe-page-type",
6
6
  PAGE_LIST: "data-unsubscribe-page-list",
7
7
  BLOCK_ID: "data-unsubscribe-block-id"
8
- }, c = ".unsubscribe-block-v2", u = 'a[data-unsubscribe-link="true"], a.unsubscribe-link';
8
+ }, e = ".unsubscribe-block-v2", E = /{{ins-(?:global-)?(?:preferences-)?unsubscribe-link}}/, c = 'a[data-unsubscribe-link="true"], a.unsubscribe-link';
9
9
  export {
10
10
  b as DATA_ATTRIBUTES,
11
- c as UNSUBSCRIBE_BLOCK_SELECTOR,
11
+ e as UNSUBSCRIBE_BLOCK_SELECTOR,
12
12
  s as UNSUBSCRIBE_EVENTS,
13
- u as UNSUBSCRIBE_LINK_SELECTOR
13
+ c as UNSUBSCRIBE_LINK_SELECTOR,
14
+ E as UNSUBSCRIBE_MERGE_TAG_REGEX
14
15
  };
@@ -0,0 +1,5 @@
1
+ import { UNSUBSCRIBE_MERGE_TAG_REGEX as E } from "./constants.js";
2
+ const o = (r, p) => r.replace(E, () => p).replace(`${p}?`, () => `${p}&`);
3
+ export {
4
+ o as swapMergeTagInHref
5
+ };