@useinsider/guido 3.26.0-beta.19d84af → 3.26.0-beta.d0b09c0

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 (84) hide show
  1. package/README.md +10 -0
  2. package/dist/@types/config/schemas.js +98 -94
  3. package/dist/@types/display-condition.js +25 -0
  4. package/dist/components/Guido.vue.js +7 -7
  5. package/dist/components/Guido.vue2.js +113 -104
  6. package/dist/components/organisms/display-conditions/CodeEditorField.vue.js +17 -0
  7. package/dist/components/organisms/display-conditions/CodeEditorField.vue2.js +41 -0
  8. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.js +30 -0
  9. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue2.js +81 -0
  10. package/dist/components/organisms/display-conditions/DisplayConditionListState.vue.js +17 -0
  11. package/dist/components/organisms/display-conditions/DisplayConditionListState.vue2.js +45 -0
  12. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.js +36 -0
  13. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue2.js +63 -0
  14. package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue.js +17 -0
  15. package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue2.js +22 -0
  16. package/dist/components/organisms/unsubscribe/LegacyUnsubscribeConvertedModal.vue.js +17 -0
  17. package/dist/components/organisms/unsubscribe/LegacyUnsubscribeConvertedModal.vue2.js +30 -0
  18. package/dist/composables/useBlocksConfig.js +29 -20
  19. package/dist/composables/useDisplayConditions.js +116 -0
  20. package/dist/composables/useModuleRepair.js +33 -24
  21. package/dist/composables/useTranslations.js +2 -1
  22. package/dist/config/compiler/utils/itemsCompilerUtils.js +43 -42
  23. package/dist/config/compiler/utils/recommendationCompilerUtils.js +67 -64
  24. package/dist/config/migrator/index.js +8 -7
  25. package/dist/config/migrator/legacyUnsubscribeTextMigrator.js +16 -0
  26. package/dist/config/migrator/unsubscribeMigrator.js +114 -100
  27. package/dist/enums/academy.js +3 -1
  28. package/dist/enums/display-condition.js +12 -0
  29. package/dist/extensions/Blocks/Unsubscribe/block.js +104 -96
  30. package/dist/extensions/Blocks/Unsubscribe/utils/constants.js +4 -3
  31. package/dist/extensions/Blocks/Unsubscribe/utils/swapMergeTagInHref.js +5 -0
  32. package/dist/extensions/DisplayConditions/bridge.js +25 -0
  33. package/dist/extensions/DisplayConditions/constants.js +26 -0
  34. package/dist/extensions/DisplayConditions/control.js +215 -0
  35. package/dist/extensions/DisplayConditions/display-conditions.css.js +226 -0
  36. package/dist/extensions/DisplayConditions/extension.js +28 -0
  37. package/dist/extensions/DisplayConditions/iconsRegistry.js +20 -0
  38. package/dist/extensions/DisplayConditions/library.js +30 -0
  39. package/dist/extensions/DisplayConditions/settingsPanel.js +17 -0
  40. package/dist/guido.css +1 -1
  41. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +93 -92
  42. package/dist/node_modules/valibot/dist/index.js +297 -261
  43. package/dist/package.json.js +1 -1
  44. package/dist/services/displayConditionApi.js +39 -0
  45. package/dist/src/@types/config/schemas.d.ts +8 -0
  46. package/dist/src/@types/display-condition.d.ts +61 -0
  47. package/dist/src/components/organisms/display-conditions/CodeEditorField.vue.d.ts +43 -0
  48. package/dist/src/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.d.ts +2 -0
  49. package/dist/src/components/organisms/display-conditions/DisplayConditionListState.vue.d.ts +18 -0
  50. package/dist/src/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.d.ts +2 -0
  51. package/dist/src/components/organisms/display-conditions/DisplayConditionsHost.vue.d.ts +2 -0
  52. package/dist/src/components/organisms/unsubscribe/LegacyUnsubscribeConvertedModal.vue.d.ts +2 -0
  53. package/dist/src/composables/useConfig.d.ts +4 -0
  54. package/dist/src/composables/useDisplayConditions.d.ts +18 -0
  55. package/dist/src/composables/useModuleRepair.d.ts +2 -11
  56. package/dist/src/config/migrator/legacyUnsubscribeTextMigrator.d.ts +1 -0
  57. package/dist/src/enums/academy.d.ts +2 -0
  58. package/dist/src/enums/display-condition.d.ts +15 -0
  59. package/dist/src/extensions/Blocks/Unsubscribe/utils/constants.d.ts +1 -0
  60. package/dist/src/extensions/Blocks/Unsubscribe/utils/swapMergeTagInHref.d.ts +1 -0
  61. package/dist/src/extensions/DisplayConditions/bridge.d.ts +7 -0
  62. package/dist/src/extensions/DisplayConditions/constants.d.ts +23 -0
  63. package/dist/src/extensions/DisplayConditions/control.d.ts +25 -0
  64. package/dist/src/extensions/DisplayConditions/extension.d.ts +2 -0
  65. package/dist/src/extensions/DisplayConditions/iconsRegistry.d.ts +4 -0
  66. package/dist/src/extensions/DisplayConditions/library.d.ts +8 -0
  67. package/dist/src/extensions/DisplayConditions/settingsPanel.d.ts +5 -0
  68. package/dist/src/mock/api/display-conditions.d.ts +2 -0
  69. package/dist/src/services/displayConditionApi.d.ts +8 -0
  70. package/dist/src/stores/config.d.ts +190 -0
  71. package/dist/src/stores/display-condition.d.ts +86 -0
  72. package/dist/src/stores/editor.d.ts +27 -0
  73. package/dist/src/utils/displayCondition.d.ts +11 -0
  74. package/dist/src/utils/legacyUnsubscribeConversion.d.ts +10 -0
  75. package/dist/src/utils/protectTableText.d.ts +2 -0
  76. package/dist/static/styles/variables.css.js +1 -0
  77. package/dist/stores/config.js +13 -6
  78. package/dist/stores/display-condition.js +29 -0
  79. package/dist/stores/editor.js +1 -0
  80. package/dist/utils/displayCondition.js +29 -0
  81. package/dist/utils/legacyUnsubscribeConversion.js +49 -0
  82. package/dist/utils/pairProductVariables.js +29 -28
  83. package/dist/utils/protectTableText.js +22 -0
  84. package/package.json +1 -1
@@ -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
+ };
@@ -0,0 +1,25 @@
1
+ import { DisplayConditionEvent as i } from "../../enums/display-condition.js";
2
+ let n = null;
3
+ const d = () => {
4
+ n == null || n.detach();
5
+ }, L = (p, e) => {
6
+ var C;
7
+ const t = n;
8
+ t == null || t.detach(), (C = t == null ? void 0 : t.onCancel) == null || C.call(t);
9
+ let o = () => {
10
+ };
11
+ const l = (c) => {
12
+ const m = c.detail;
13
+ o(), m.applied = e.onApply(m.condition);
14
+ }, a = () => {
15
+ var c;
16
+ o(), (c = e.onCancel) == null || c.call(e);
17
+ };
18
+ return o = () => {
19
+ document.removeEventListener(i.APPLY, l), document.removeEventListener(i.CANCEL, a), (n == null ? void 0 : n.detach) === o && (n = null);
20
+ }, document.addEventListener(i.APPLY, l), document.addEventListener(i.CANCEL, a), n = { detach: o, onCancel: e.onCancel }, document.dispatchEvent(new CustomEvent(i.OPEN, { detail: p })), o;
21
+ };
22
+ export {
23
+ d as disposeDisplayConditionRequest,
24
+ L as requestDisplayCondition
25
+ };
@@ -0,0 +1,26 @@
1
+ import { BlockType as o } from "../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
2
+ const n = "conditions", t = "guido-display-conditions-control", d = 10, s = [o.STRIPE, o.STRUCTURE, o.CONTAINER], c = {
3
+ PLUS: "guido-display-condition-plus",
4
+ EDIT: "guido-display-condition-edit",
5
+ TRASH: "guido-display-condition-trash",
6
+ CHEVRON: "guido-display-condition-chevron"
7
+ }, e = {
8
+ ADD: "guidoDisplayConditionAdd",
9
+ CREATE: "guidoDisplayConditionCreate",
10
+ SELECT: "guidoDisplayConditionSelect",
11
+ SHOW_MORE: "guidoDisplayConditionShowMore",
12
+ SHOW_LESS: "guidoDisplayConditionShowLess",
13
+ EDIT: "guidoDisplayConditionEdit",
14
+ REMOVE: "guidoDisplayConditionRemove"
15
+ }, C = ["applyConditionSwitcher", "applyCondition", "displayConditions"], a = "You can add Display Condition by selecting an existing condition or creating a new one to show specific content.", O = "You can create or select a display condition to control content visibility based on your recipients' properties or events.";
16
+ export {
17
+ O as APPLIED_DESCRIPTION,
18
+ C as BUILT_IN_CONDITION_CONTROLS,
19
+ t as CONDITIONS_CONTROL_ID,
20
+ n as CONDITIONS_TAB_ID,
21
+ s as CONDITION_BLOCK_TYPES,
22
+ e as CONDITION_BUTTONS,
23
+ c as CONDITION_ICONS,
24
+ a as EMPTY_DESCRIPTION,
25
+ d as MAX_COLLAPSED_LINES
26
+ };
@@ -0,0 +1,215 @@
1
+ var b = Object.defineProperty;
2
+ var v = (c, a, i) => a in c ? b(c, a, { enumerable: !0, configurable: !0, writable: !0, value: i }) : c[a] = i;
3
+ var u = (c, a, i) => v(c, typeof a != "symbol" ? a + "" : a, i);
4
+ import { useToaster as O } from "../../composables/useToaster.js";
5
+ import { useTranslations as w } from "../../composables/useTranslations.js";
6
+ import { DisplayConditionSourceType as N } from "../../enums/display-condition.js";
7
+ import { ToasterTypeOptions as S } from "../../enums/toaster.js";
8
+ import { CommonControl as E } from "../Blocks/common-control.js";
9
+ import { toAppliedCondition as D, parseSource as T } from "../../utils/displayCondition.js";
10
+ import { escapeHtml as f } from "../../utils/htmlEscape.js";
11
+ import { ModificationDescription as I } from "../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
12
+ import { requestDisplayCondition as M } from "./bridge.js";
13
+ import { CONDITIONS_CONTROL_ID as $, CONDITION_ICONS as h, CONDITION_BUTTONS as r, APPLIED_DESCRIPTION as x, EMPTY_DESCRIPTION as L, MAX_COLLAPSED_LINES as C } from "./constants.js";
14
+ const l = ".guido-display-conditions", R = { id: 0, name: "", description: "", beforeScript: "", afterScript: "" };
15
+ class F extends E {
16
+ constructor() {
17
+ super(...arguments);
18
+ u(this, "expanded", !1);
19
+ u(this, "listeners", []);
20
+ u(this, "resizeObserver", null);
21
+ u(this, "detachOutsideClick", null);
22
+ }
23
+ getId() {
24
+ return $;
25
+ }
26
+ getTemplate() {
27
+ return `
28
+ <div class="guido-display-conditions">
29
+ <div class="guido-display-conditions__header">
30
+ <p class="guido-display-conditions__title">${this.api.translate("Display Conditions")}</p>
31
+ <p class="guido-display-conditions__description" data-dc-description></p>
32
+ </div>
33
+ <div class="guido-display-conditions__empty" data-dc-empty>
34
+ ${this._GuButton({
35
+ name: r.ADD,
36
+ id: "guido__btn-add-display-condition",
37
+ className: "guido-display-conditions__add",
38
+ icon: h.PLUS,
39
+ label: this.api.translate("Add Display Condition")
40
+ })}
41
+ <div class="guido-display-conditions__menu" data-dc-menu hidden>
42
+ ${this._GuButton({
43
+ name: r.CREATE,
44
+ id: "guido__btn-display-condition-create",
45
+ className: "guido-display-conditions__menu-item",
46
+ label: this.api.translate("Create New Condition")
47
+ })}
48
+ ${this._GuButton({
49
+ name: r.SELECT,
50
+ id: "guido__btn-display-condition-select",
51
+ className: "guido-display-conditions__menu-item",
52
+ label: this.api.translate("Select Saved Condition")
53
+ })}
54
+ </div>
55
+ </div>
56
+ <div class="guido-display-conditions__applied" data-dc-applied hidden>
57
+ <div class="guido-display-conditions__code-box">
58
+ <p class="guido-display-conditions__name" data-dc-name></p>
59
+ <div class="guido-display-conditions__sections" data-dc-sections>
60
+ <p class="guido-display-conditions__section-label">
61
+ ${this.api.translate("Code Before Module")}
62
+ </p>
63
+ <pre class="guido-display-conditions__code" data-dc-before></pre>
64
+ <p class="guido-display-conditions__section-label" data-dc-after-label>
65
+ ${this.api.translate("Code After Module")}
66
+ </p>
67
+ <pre class="guido-display-conditions__code" data-dc-after></pre>
68
+ </div>
69
+ ${this._GuButton({
70
+ name: r.SHOW_MORE,
71
+ id: "guido__btn-display-condition-show-more",
72
+ className: "guido-display-conditions__toggle",
73
+ icon: h.CHEVRON,
74
+ label: this.api.translate("Show More")
75
+ })}
76
+ ${this._GuButton({
77
+ name: r.SHOW_LESS,
78
+ id: "guido__btn-display-condition-show-less",
79
+ className: "guido-display-conditions__toggle guido-display-conditions__toggle--less",
80
+ icon: h.CHEVRON,
81
+ label: this.api.translate("Show Less")
82
+ })}
83
+ </div>
84
+ <div class="guido-display-conditions__actions">
85
+ ${this._GuButton({
86
+ name: r.EDIT,
87
+ id: "guido__btn-edit-display-condition",
88
+ className: "guido-display-conditions__action guido-display-conditions__action--edit",
89
+ icon: h.EDIT,
90
+ label: this.api.translate("Edit")
91
+ })}
92
+ ${this._GuButton({
93
+ name: r.REMOVE,
94
+ id: "guido__btn-remove-display-condition",
95
+ className: "guido-display-conditions__action guido-display-conditions__action--remove",
96
+ icon: h.TRASH,
97
+ label: this.api.translate("Remove")
98
+ })}
99
+ </div>
100
+ </div>
101
+ </div>
102
+ `;
103
+ }
104
+ onRender() {
105
+ this.forgetLastPanelNode(), this.teardown(), this.wire("#guido__btn-add-display-condition", () => this.toggleMenu()), this.wire("#guido__btn-display-condition-create", () => this.openDrawer("create")), this.wire("#guido__btn-display-condition-select", () => this.openDrawer("select")), this.wire("#guido__btn-edit-display-condition", () => this.openDrawer("edit")), this.wire("#guido__btn-remove-display-condition", () => this.removeCondition()), this.wire("#guido__btn-display-condition-show-more", () => this.setExpanded(!0)), this.wire("#guido__btn-display-condition-show-less", () => this.setExpanded(!1)), this.observeCodeSize();
106
+ }
107
+ onTemplateNodeUpdated(i) {
108
+ const t = i !== this.currentNode;
109
+ super.onTemplateNodeUpdated(i), t && (this.expanded = !1, this.toggleMenu(!1)), this.paint();
110
+ }
111
+ onDestroy() {
112
+ super.onDestroy(), this.teardown();
113
+ }
114
+ setExpanded(i) {
115
+ this.expanded = i, this.paint();
116
+ }
117
+ getCondition() {
118
+ var t;
119
+ const i = this.currentNode;
120
+ return D((t = i == null ? void 0 : i.getDisplayCondition) == null ? void 0 : t.call(i));
121
+ }
122
+ toggleMenu(i) {
123
+ var o, s, n;
124
+ const t = (o = this.getContainer()) == null ? void 0 : o.querySelector(`${l} [data-dc-menu]`);
125
+ if (!t)
126
+ return;
127
+ t.hidden = i === void 0 ? !t.hidden : !i, (s = this.detachOutsideClick) == null || s.call(this), t.hidden || this.listenOutsideClick();
128
+ const e = (n = this.getContainer()) == null ? void 0 : n.querySelector(`${l} #guido__btn-add-display-condition`);
129
+ t.style.width = !t.hidden && e ? `${e.getBoundingClientRect().width}px` : "";
130
+ }
131
+ listenOutsideClick() {
132
+ var e;
133
+ const i = ((e = this.getContainer()) == null ? void 0 : e.ownerDocument) ?? document, t = (o) => {
134
+ o.composedPath().some((n) => n instanceof HTMLElement && n.matches(`${l} [data-dc-menu], ${l} #guido__btn-add-display-condition`)) || this.toggleMenu(!1);
135
+ };
136
+ i.addEventListener("pointerdown", t, !0), this.detachOutsideClick = () => {
137
+ i.removeEventListener("pointerdown", t, !0), this.detachOutsideClick = null;
138
+ };
139
+ }
140
+ openDrawer(i) {
141
+ const t = this.currentNode;
142
+ this.toggleMenu(!1), M(
143
+ { mode: i, current: i === "edit" ? this.getCondition() : null },
144
+ { onApply: (e) => this.applyCondition(e, t) }
145
+ );
146
+ }
147
+ // The drawer flows toast through useDisplayConditions; Remove has no drawer, so it toasts here.
148
+ removeCondition() {
149
+ this.applyCondition(null) || O().showToaster({
150
+ type: S.Error,
151
+ message: w()("products.something-went-wrong")
152
+ });
153
+ }
154
+ // The panel can move to another block while the drawer is open; apply onto the block it was opened for.
155
+ applyCondition(i, t = this.currentNode) {
156
+ if (!t)
157
+ return !1;
158
+ try {
159
+ const e = this.api.getDocumentModifier().modifyHtml(t);
160
+ return e.setDisplayCondition(i || R), e.apply(new I(
161
+ i ? `Set display condition ${i.name}` : "Remove display condition"
162
+ )), !0;
163
+ } catch (e) {
164
+ return console.warn("Display condition could not be applied.", e), !1;
165
+ }
166
+ }
167
+ wire(i, t) {
168
+ var o;
169
+ const e = (o = this.getContainer()) == null ? void 0 : o.querySelector(`${l} ${i}`);
170
+ e && (e.addEventListener("click", t), this.listeners.push({ element: e, handler: t }));
171
+ }
172
+ teardown() {
173
+ var i, t;
174
+ this.listeners.forEach(({ element: e, handler: o }) => e.removeEventListener("click", o)), this.listeners = [], (i = this.resizeObserver) == null || i.disconnect(), this.resizeObserver = null, (t = this.detachOutsideClick) == null || t.call(this);
175
+ }
176
+ // Line counts depend on layout: the panel font loads late and the panel can be resized.
177
+ observeCodeSize() {
178
+ var t;
179
+ const i = (t = this.getContainer()) == null ? void 0 : t.querySelectorAll(`${l} .guido-display-conditions__code`);
180
+ !(i != null && i.length) || typeof ResizeObserver > "u" || (this.resizeObserver = new ResizeObserver(() => this.paint()), i.forEach((e) => {
181
+ var o;
182
+ return (o = this.resizeObserver) == null ? void 0 : o.observe(e);
183
+ }));
184
+ }
185
+ paint() {
186
+ var y;
187
+ const i = (y = this.getContainer()) == null ? void 0 : y.querySelector(l);
188
+ if (!i)
189
+ return;
190
+ const t = this.getCondition(), e = (_) => i.querySelector(_);
191
+ if (e("[data-dc-empty]").hidden = !!t, e("[data-dc-applied]").hidden = !t, e("[data-dc-description]").textContent = this.api.translate(t ? x : L), !t)
192
+ return;
193
+ e("[data-dc-name]").textContent = t.name;
194
+ const o = T(t) === N.INLINE;
195
+ e("#guido__btn-edit-display-condition").hidden = !o;
196
+ const s = e("[data-dc-sections]"), n = e("[data-dc-before]"), d = e("[data-dc-after]");
197
+ n.innerHTML = f(t.beforeScript), d.innerHTML = f(t.afterScript), d.hidden = !t.afterScript, e("[data-dc-after-label]").hidden = !t.afterScript, s.style.maxHeight = "";
198
+ const p = parseFloat(getComputedStyle(n).lineHeight) || 24, m = (_) => _.hidden ? 0 : Math.round(_.scrollHeight / p), g = m(n) + m(d) > C;
199
+ e("#guido__btn-display-condition-show-more").hidden = !g || this.expanded, e("#guido__btn-display-condition-show-less").hidden = !g || !this.expanded, g && !this.expanded && (s.style.maxHeight = `${this.collapsedHeight(s, [n, d], p)}px`);
200
+ }
201
+ // Labels do not count toward the line limit, so the cut lands after the 10th rendered code line.
202
+ collapsedHeight(i, t, e) {
203
+ const { top: o } = i.getBoundingClientRect();
204
+ let s = C, n = 0;
205
+ return t.filter((d) => !d.hidden).forEach((d) => {
206
+ if (s <= 0)
207
+ return;
208
+ const p = Math.min(s, Math.round(d.scrollHeight / e));
209
+ n = d.getBoundingClientRect().top - o + p * e, s -= p;
210
+ }), n;
211
+ }
212
+ }
213
+ export {
214
+ F as DisplayConditionsControl
215
+ };