@useinsider/guido 3.4.1-beta.ac571e2 → 3.4.1-beta.c04b4e7

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.
@@ -1,31 +1,34 @@
1
1
  var d = Object.defineProperty;
2
- var h = (n, i, e) => i in n ? d(n, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[i] = e;
3
- var u = (n, i, e) => h(n, typeof i != "symbol" ? i + "" : i, e);
4
- import { PAGE_TYPES as E } from "../../../enums/unsubscribe.js";
5
- import { useUnsubscribeStore as c } from "../../../stores/unsubscribe.js";
6
- import { Block as _, BlockCompositionType as S, BlockType as L, ModificationDescription as b } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
7
- import { getDefaultTemplate as v } from "./template.js";
8
- import { UNSUBSCRIBE_EVENTS as a, DATA_ATTRIBUTES as o } from "./utils/constants.js";
9
- import { parsePageList as p } from "./utils/utils.js";
10
- const g = "unsubscribe-block", T = 'a[data-unsubscribe-link="true"]', f = ".unsubscribe-block-v2", B = "{{ins-unsubscribe-link}}", C = {
11
- [E.GLOBAL_UNSUBSCRIBE]: "{{ins-global-unsubscribe-link}}",
12
- [E.SUBSCRIPTION_PREFERENCE_CENTER]: "{{ins-preferences-unsubscribe-link}}"
2
+ var _ = (n, i, e) => i in n ? d(n, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[i] = e;
3
+ var c = (n, i, e) => _(n, typeof i != "symbol" ? i + "" : i, e);
4
+ import { useToaster as L } from "../../../composables/useToaster.js";
5
+ import { ToasterTypeOptions as S } from "../../../enums/toaster.js";
6
+ import { PAGE_TYPES as b } from "../../../enums/unsubscribe.js";
7
+ import { useUnsubscribeStore as a } from "../../../stores/unsubscribe.js";
8
+ import { Block as g, BlockCompositionType as v, BlockType as k, ModificationDescription as E } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
9
+ import { getDefaultTemplate as f } from "./template.js";
10
+ import { UNSUBSCRIBE_EVENTS as u, DATA_ATTRIBUTES as o } from "./utils/constants.js";
11
+ import { parsePageList as h } from "./utils/utils.js";
12
+ const T = "unsubscribe-block", p = 'a[data-unsubscribe-link="true"]', B = ".unsubscribe-block-v2", U = "{{ins-unsubscribe-link}}", C = "https://academy.insiderone.com/docs/adding-unsubscribe-pages-into-emails", A = "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.", N = {
13
+ [b.GLOBAL_UNSUBSCRIBE]: "{{ins-global-unsubscribe-link}}",
14
+ [b.SUBSCRIPTION_PREFERENCE_CENTER]: "{{ins-preferences-unsubscribe-link}}"
13
15
  };
14
- class I extends _ {
16
+ class x extends g {
15
17
  constructor() {
16
18
  super();
17
- u(this, "selectEventListener", null);
18
- u(this, "cancelEventListener", null);
19
- u(this, "currentNode");
19
+ c(this, "selectEventListener", null);
20
+ c(this, "cancelEventListener", null);
21
+ c(this, "currentNode");
22
+ c(this, "hadUnsubscribeLink", !1);
20
23
  }
21
24
  getId() {
22
- return g;
25
+ return T;
23
26
  }
24
27
  getIcon() {
25
28
  return "unsubscribe-icon";
26
29
  }
27
30
  getBlockCompositionType() {
28
- return S.BLOCK;
31
+ return v.BLOCK;
29
32
  }
30
33
  getName() {
31
34
  return this.api.translate("Unsubscribe Block");
@@ -34,39 +37,63 @@ class I extends _ {
34
37
  return this.api.translate("Unsubscribe Block Description");
35
38
  }
36
39
  getTemplate() {
37
- return v();
40
+ return f();
38
41
  }
39
42
  onSelect(e) {
40
- this.currentNode = e, !("getAttribute" in e && e.getAttribute("data-migration")) && (this._resetStoreState(), this._loadBlockState(e), this._setupSelectEventListener(), this._setupCancelEventListener(), this._checkExistingBlocks(), this._openDrawer());
43
+ this.currentNode = e, this.hadUnsubscribeLink = this._hasUnsubscribeLink(e), !("getAttribute" in e && e.getAttribute("data-migration")) && (this._resetStoreState(), this._loadBlockState(e), this._setupSelectEventListener(), this._setupCancelEventListener(), this._checkExistingBlocks(), this._openDrawer());
44
+ }
45
+ onDocumentChanged(e) {
46
+ const t = this._hasUnsubscribeLink(e);
47
+ this.hadUnsubscribeLink && !t && this._warnLinkRemoved(), this.hadUnsubscribeLink = t;
41
48
  }
42
49
  onDelete(e) {
43
- this._removeEventListeners(), this._removeBlockTemplatesFromStore(e), this._resetStoreState();
50
+ this._removeEventListeners(), this._removeBlockTemplatesFromStore(e), this._resetStoreState(), this.hadUnsubscribeLink = !1;
44
51
  }
45
52
  onDestroy() {
46
- this._removeEventListeners(), this.currentNode = void 0;
53
+ this._removeEventListeners(), this.currentNode = void 0, this.hadUnsubscribeLink = !1;
54
+ }
55
+ _hasUnsubscribeLink(e) {
56
+ return "querySelector" in e ? !!e.querySelector(p) : !1;
57
+ }
58
+ _warnLinkRemoved() {
59
+ try {
60
+ const { showToaster: e } = L();
61
+ e({
62
+ type: S.Warning,
63
+ message: this.api.translate(A),
64
+ actionButton: {
65
+ text: this.api.translate("Visit Academy"),
66
+ onClick: () => {
67
+ window.open(C, "_blank", "noopener,noreferrer");
68
+ }
69
+ }
70
+ });
71
+ } catch (e) {
72
+ console.error("[UnsubscribeBlock] Failed to show warning toaster:", e);
73
+ }
47
74
  }
48
75
  _setupSelectEventListener() {
49
76
  this._removeSelectEventListener(), this.selectEventListener = (e) => {
50
- const r = e, { collectionType: s, selectedPages: t } = r.detail;
51
- this._updateBlock(s, t.join(","));
52
- }, document.addEventListener(a.SELECT, this.selectEventListener);
77
+ const t = e, { collectionType: r, selectedPages: s } = t.detail;
78
+ this._updateBlock(r, s.join(","));
79
+ }, document.addEventListener(u.SELECT, this.selectEventListener);
53
80
  }
54
81
  _removeSelectEventListener() {
55
- this.selectEventListener && (document.removeEventListener(a.SELECT, this.selectEventListener), this.selectEventListener = null);
82
+ this.selectEventListener && (document.removeEventListener(u.SELECT, this.selectEventListener), this.selectEventListener = null);
56
83
  }
57
84
  _setupCancelEventListener() {
58
85
  this._removeCancelEventListener(), this.cancelEventListener = () => {
59
86
  this._handleCancel();
60
- }, document.addEventListener(a.CANCEL, this.cancelEventListener);
87
+ }, document.addEventListener(u.CANCEL, this.cancelEventListener);
61
88
  }
62
89
  _removeCancelEventListener() {
63
- this.cancelEventListener && (document.removeEventListener(a.CANCEL, this.cancelEventListener), this.cancelEventListener = null);
90
+ this.cancelEventListener && (document.removeEventListener(u.CANCEL, this.cancelEventListener), this.cancelEventListener = null);
64
91
  }
65
92
  _handleCancel() {
66
93
  try {
67
94
  if (!this.currentNode)
68
95
  return;
69
- this.api.getDocumentModifier().modifyHtml(this.currentNode).replaceWith(`<${L.EMPTY_CONTAINER}/>`).apply(new b("Removed unsubscribe block due to cancel"));
96
+ this.api.getDocumentModifier().modifyHtml(this.currentNode).replaceWith(`<${k.EMPTY_CONTAINER}/>`).apply(new E("Removed unsubscribe block due to cancel"));
70
97
  } catch (e) {
71
98
  console.warn("[UnsubscribeBlock] Failed to remove unsubscribe block:", e);
72
99
  }
@@ -74,35 +101,35 @@ class I extends _ {
74
101
  _removeEventListeners() {
75
102
  this._removeSelectEventListener(), this._removeCancelEventListener();
76
103
  }
77
- _updateBlock(e, r) {
104
+ _updateBlock(e, t) {
78
105
  if (!this.currentNode || !("querySelector" in this.currentNode))
79
106
  return;
80
- const s = this.currentNode.querySelector(T);
81
- if (!s)
107
+ const r = this.currentNode.querySelector(p);
108
+ if (!r)
82
109
  return;
83
- const t = this._getMergeTag(e);
84
- this.api.getDocumentModifier().modifyHtml(s).setAttribute("href", t).apply(new b(`Updated unsubscribe link to ${t}`)), this.api.getDocumentModifier().modifyHtml(this.currentNode).setAttribute(o.PAGE_TYPE, e.toString()).setAttribute(o.PAGE_LIST, r).apply(new b("Updated unsubscribe block metadata"));
110
+ const s = this._getMergeTag(e);
111
+ this.api.getDocumentModifier().modifyHtml(r).setAttribute("href", s).apply(new E(`Updated unsubscribe link to ${s}`)), this.api.getDocumentModifier().modifyHtml(this.currentNode).setAttribute(o.PAGE_TYPE, e.toString()).setAttribute(o.PAGE_LIST, t).apply(new E("Updated unsubscribe block metadata"));
85
112
  }
86
113
  _getMergeTag(e) {
87
- return C[e] ?? B;
114
+ return N[e] ?? U;
88
115
  }
89
116
  _openDrawer() {
90
117
  if (!(this.currentNode && this.currentNode.getAttribute("data-unsubscribe-page-type")))
91
118
  try {
92
- const e = c();
119
+ const e = a();
93
120
  e.typeSelectionDrawerStatus = !0;
94
121
  } catch (e) {
95
122
  console.error("[UnsubscribeBlock] Failed to open drawer:", e);
96
123
  }
97
124
  }
98
125
  _checkExistingBlocks() {
99
- const e = c();
100
- e.isGlobalUnsubscribeDisabled = !1, e.isSubscriptionPreferencesCenterDisabled = !1, this.api.getDocumentRoot().querySelectorAll(f).forEach((s) => {
101
- if ("getAttribute" in s) {
102
- const t = s.getAttribute(o.PAGE_TYPE);
103
- if (t) {
104
- const l = Number(t);
105
- l === E.GLOBAL_UNSUBSCRIBE ? e.isGlobalUnsubscribeDisabled = !0 : l === E.SUBSCRIPTION_PREFERENCE_CENTER && (e.isSubscriptionPreferencesCenterDisabled = !0);
126
+ const e = a();
127
+ e.isGlobalUnsubscribeDisabled = !1, e.isSubscriptionPreferencesCenterDisabled = !1, this.api.getDocumentRoot().querySelectorAll(B).forEach((r) => {
128
+ if ("getAttribute" in r) {
129
+ const s = r.getAttribute(o.PAGE_TYPE);
130
+ if (s) {
131
+ const l = Number(s);
132
+ l === b.GLOBAL_UNSUBSCRIBE ? e.isGlobalUnsubscribeDisabled = !0 : l === b.SUBSCRIPTION_PREFERENCE_CENTER && (e.isSubscriptionPreferencesCenterDisabled = !0);
106
133
  }
107
134
  }
108
135
  });
@@ -110,26 +137,26 @@ class I extends _ {
110
137
  async _loadBlockState(e) {
111
138
  if (!("getAttribute" in e))
112
139
  return;
113
- const r = e.getAttribute(o.PAGE_TYPE), s = e.getAttribute(o.PAGE_LIST);
114
- if (!r || !s)
140
+ const t = e.getAttribute(o.PAGE_TYPE), r = e.getAttribute(o.PAGE_LIST);
141
+ if (!t || !r)
115
142
  return;
116
- const t = c(), l = Number(r), m = p(s);
117
- await t.fetchTemplates(), t.setCollectionWithoutAutoSelection(l), t.loadSelectedTemplates(m);
143
+ const s = a(), l = Number(t), m = h(r);
144
+ await s.fetchTemplates(), s.setCollectionWithoutAutoSelection(l), s.loadSelectedTemplates(m);
118
145
  }
119
146
  _resetStoreState() {
120
- c().$reset();
147
+ a().$reset();
121
148
  }
122
149
  _removeBlockTemplatesFromStore(e) {
123
150
  if (!("getAttribute" in e))
124
151
  return;
125
- const r = e.getAttribute(o.PAGE_LIST);
126
- if (!r)
152
+ const t = e.getAttribute(o.PAGE_LIST);
153
+ if (!t)
127
154
  return;
128
- const s = c(), t = p(r);
129
- s.removeUnsubscribePages(t);
155
+ const r = a(), s = h(t);
156
+ r.removeUnsubscribePages(s);
130
157
  }
131
158
  }
132
159
  export {
133
- g as UNSUBSCRIBE_BLOCK_ID,
134
- I as UnsubscribeBlock
160
+ T as UNSUBSCRIBE_BLOCK_ID,
161
+ x as UnsubscribeBlock
135
162
  };
@@ -1,22 +1,22 @@
1
- import { BlockType as e } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
2
- const s = "unsubscribe", n = "{{ins-unsubscribe-link}}", t = `
3
- <${e.BLOCK_TEXT}
1
+ import { BlockType as s } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
2
+ const e = "unsubscribe", n = "{{ins-unsubscribe-link}}", t = `
3
+ <${s.BLOCK_TEXT}
4
4
  class="unsubscribe-block-v2 esd-block-unsubscribe es-p0"
5
5
  align="center"
6
6
  data-unsubscribe-page-type=""
7
7
  data-unsubscribe-page-list=""
8
8
  >
9
- <p>You can <strong><a
9
+ <p>&nbsp;<strong><a
10
10
  href="${n}"
11
11
  class="unsubscribe-link"
12
12
  target="_blank"
13
13
  data-unsubscribe-link="true"
14
- >${s}</a></strong> from our emails, if you need to.</p>
15
- </${e.BLOCK_TEXT}>
14
+ >${e}</a></strong></p>
15
+ </${s.BLOCK_TEXT}>
16
16
  `;
17
- function r() {
17
+ function u() {
18
18
  return t;
19
19
  }
20
20
  export {
21
- r as getDefaultTemplate
21
+ u as getDefaultTemplate
22
22
  };
@@ -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 hadUnsubscribeLink;
8
9
  constructor();
9
10
  getId(): string;
10
11
  getIcon(): string;
@@ -13,8 +14,11 @@ export declare class UnsubscribeBlock extends Block {
13
14
  getDescription(): string;
14
15
  getTemplate(): string;
15
16
  onSelect(node: ImmutableHtmlElementNode): void;
17
+ onDocumentChanged(node: ImmutableHtmlNode): void;
16
18
  onDelete(node: ImmutableHtmlElementNode): void;
17
19
  onDestroy(): void;
20
+ private _hasUnsubscribeLink;
21
+ private _warnLinkRemoved;
18
22
  private _setupSelectEventListener;
19
23
  private _removeSelectEventListener;
20
24
  private _setupCancelEventListener;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.4.1-beta.ac571e2",
3
+ "version": "3.4.1-beta.c04b4e7",
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",