@useinsider/guido 1.0.3-beta.fb2b45b → 1.0.3-beta.ff71e68

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 (69) hide show
  1. package/dist/@types/generic.d.ts +0 -9
  2. package/dist/components/Guido.vue.d.ts +2 -2
  3. package/dist/components/Guido.vue.js +8 -8
  4. package/dist/components/Guido.vue2.js +69 -74
  5. package/dist/components/wrappers/WpDrawer.vue.d.ts +4 -6
  6. package/dist/components/wrappers/WpDrawer.vue.js +4 -6
  7. package/dist/composables/useStripo.js +13 -17
  8. package/dist/config/compiler/unsubscribeCompilerRules.js +29 -42
  9. package/dist/config/migrator/couponBlockMigrator.d.ts +1 -0
  10. package/dist/config/migrator/couponBlockMigrator.js +67 -0
  11. package/dist/config/migrator/index.d.ts +1 -1
  12. package/dist/config/migrator/index.js +7 -7
  13. package/dist/enums/defaults.js +3 -6
  14. package/dist/enums/unsubscribe.d.ts +0 -19
  15. package/dist/enums/unsubscribe.js +6 -39
  16. package/dist/extensions/Blocks/Checkbox/control.js +41 -43
  17. package/dist/extensions/Blocks/CouponBlock/block.d.ts +12 -0
  18. package/dist/extensions/Blocks/CouponBlock/block.js +33 -0
  19. package/dist/extensions/Blocks/CouponBlock/extension.js +8 -0
  20. package/dist/extensions/Blocks/{Unsubscribe → CouponBlock}/iconsRegistry.d.ts +1 -1
  21. package/dist/extensions/Blocks/CouponBlock/iconsRegistry.js +33 -0
  22. package/dist/extensions/Blocks/{Unsubscribe → CouponBlock}/settingsPanel.d.ts +1 -1
  23. package/dist/extensions/Blocks/CouponBlock/settingsPanel.js +24 -0
  24. package/dist/extensions/Blocks/CouponBlock/template.d.ts +3 -0
  25. package/dist/extensions/Blocks/CouponBlock/template.js +18 -0
  26. package/dist/extensions/Blocks/RadioButton/control.js +23 -25
  27. package/dist/guido.css +1 -1
  28. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +1 -2
  29. package/dist/stores/unsubscribe.d.ts +5 -253
  30. package/dist/stores/unsubscribe.js +6 -126
  31. package/dist/utils/templatePreparation.js +16 -17
  32. package/package.json +1 -1
  33. package/dist/components/organisms/unsubscribe/UnsubscribeBreadcrumb.vue.d.ts +0 -2
  34. package/dist/components/organisms/unsubscribe/UnsubscribeBreadcrumb.vue.js +0 -18
  35. package/dist/components/organisms/unsubscribe/UnsubscribeBreadcrumb.vue2.js +0 -16
  36. package/dist/components/organisms/unsubscribe/UnsubscribePageSelection.vue.d.ts +0 -2
  37. package/dist/components/organisms/unsubscribe/UnsubscribePageSelection.vue.js +0 -24
  38. package/dist/components/organisms/unsubscribe/UnsubscribePageSelection.vue2.js +0 -64
  39. package/dist/components/organisms/unsubscribe/UnsubscribeTypeSelection.vue.d.ts +0 -2
  40. package/dist/components/organisms/unsubscribe/UnsubscribeTypeSelection.vue.js +0 -18
  41. package/dist/components/organisms/unsubscribe/UnsubscribeTypeSelection.vue2.js +0 -107
  42. package/dist/components/organisms/unsubscribe/UnsubscribeWrapper.vue.d.ts +0 -2
  43. package/dist/components/organisms/unsubscribe/UnsubscribeWrapper.vue.js +0 -18
  44. package/dist/components/organisms/unsubscribe/UnsubscribeWrapper.vue2.js +0 -12
  45. package/dist/config/migrator/unsubscribeMigrator.d.ts +0 -1
  46. package/dist/config/migrator/unsubscribeMigrator.js +0 -124
  47. package/dist/extensions/Blocks/Unsubscribe/block.d.ts +0 -32
  48. package/dist/extensions/Blocks/Unsubscribe/block.js +0 -131
  49. package/dist/extensions/Blocks/Unsubscribe/control.d.ts +0 -29
  50. package/dist/extensions/Blocks/Unsubscribe/control.js +0 -167
  51. package/dist/extensions/Blocks/Unsubscribe/elements/preview.d.ts +0 -11
  52. package/dist/extensions/Blocks/Unsubscribe/elements/preview.js +0 -42
  53. package/dist/extensions/Blocks/Unsubscribe/extension.js +0 -21
  54. package/dist/extensions/Blocks/Unsubscribe/iconsRegistry.js +0 -21
  55. package/dist/extensions/Blocks/Unsubscribe/settingsPanel.js +0 -35
  56. package/dist/extensions/Blocks/Unsubscribe/styles.css.js +0 -42
  57. package/dist/extensions/Blocks/Unsubscribe/tagRegistry.d.ts +0 -4
  58. package/dist/extensions/Blocks/Unsubscribe/tagRegistry.js +0 -10
  59. package/dist/extensions/Blocks/Unsubscribe/template.d.ts +0 -12
  60. package/dist/extensions/Blocks/Unsubscribe/template.js +0 -22
  61. package/dist/extensions/Blocks/Unsubscribe/utils/constants.d.ts +0 -9
  62. package/dist/extensions/Blocks/Unsubscribe/utils/constants.js +0 -11
  63. package/dist/extensions/Blocks/Unsubscribe/utils/utils.d.ts +0 -7
  64. package/dist/extensions/Blocks/Unsubscribe/utils/utils.js +0 -6
  65. package/dist/services/unsubscribeApi.d.ts +0 -4
  66. package/dist/services/unsubscribeApi.js +0 -16
  67. package/dist/stores/config.d.ts +0 -96
  68. package/dist/stores/config.js +0 -17
  69. /package/dist/extensions/Blocks/{Unsubscribe → CouponBlock}/extension.d.ts +0 -0
@@ -1,107 +0,0 @@
1
- import { defineComponent as h, ref as b, computed as m, watch as _ } from "vue";
2
- import v from "../../wrappers/WpDrawer.vue.js";
3
- import { useToaster as B } from "../../../composables/useToaster.js";
4
- import { useTranslations as N } from "../../../composables/useTranslations.js";
5
- import { ToasterTypeOptions as U } from "../../../enums/toaster.js";
6
- import { PAGE_TYPES as l, ACADEMY_LINK as w, UNSUBSCRIBE_PAGES_LINK as P, TYPE_TRANSLATIONS as R } from "../../../enums/unsubscribe.js";
7
- import { useUnsubscribeStore as D } from "../../../stores/unsubscribe.js";
8
- import { InSegments as I } from "@useinsider/design-system-vue";
9
- const z = /* @__PURE__ */ h({
10
- __name: "UnsubscribeTypeSelection",
11
- setup(G) {
12
- const e = N(), { showToaster: f } = B(), t = D(), n = b(!1), i = b(!0), o = b(l.GLOBAL_UNSUBSCRIBE), S = e(
13
- "unsubscription-preference.select-unsubscribe-page-description",
14
- { action: `<a href="${w}" target="_blank">${e("ds-rules.visit-academy")}</a>` }
15
- ), T = m(() => [
16
- {
17
- description: e("unsubscription-preference.type-global-unsubscribe-description"),
18
- icon: "line-contact-global-unsub-page",
19
- text: e("unsubscription-preference.type-global-unsubscribe"),
20
- value: l.GLOBAL_UNSUBSCRIBE,
21
- disable: t.isGlobalUnsubscribeDisabled,
22
- position: "bottom",
23
- tooltipText: t.isGlobalUnsubscribeDisabled ? e("unsubscription-preference.global-unsub-added") : ""
24
- },
25
- {
26
- description: e("unsubscription-preference.type-subscription-preferences-center-description"),
27
- icon: "line-contact-sub-pref-center-page",
28
- text: e("unsubscription-preference.type-subscription-preferences-center"),
29
- value: l.SUBSCRIPTION_PREFERENCE_CENTER,
30
- disable: t.isSubscriptionPreferencesCenterDisabled,
31
- tooltipText: t.isSubscriptionPreferencesCenterDisabled ? e("unsubscription-preference.pref-center-added") : ""
32
- }
33
- ]), y = m(() => ({
34
- primaryButton: {
35
- styling: "solid",
36
- type: "primary",
37
- labelText: e(
38
- n.value ? "unsubscription-preference.selecting-type" : "products.select-and-continue"
39
- ),
40
- loadingStatus: n.value,
41
- disabledStatus: !1,
42
- skeletonStatus: i.value,
43
- skeletonSizing: { width: 168, height: 40 }
44
- },
45
- cancelOrBackButton: {
46
- styling: "ghost",
47
- type: "secondary",
48
- labelText: e("products.cancel"),
49
- disabledStatus: n.value,
50
- skeletonStatus: i.value,
51
- skeletonSizing: { width: 78, height: 40 }
52
- }
53
- })), d = (s) => {
54
- t.typeSelectionDrawerStatus = !1, document.dispatchEvent(new CustomEvent("unsubscribe:cancel")), s && setTimeout(() => {
55
- s();
56
- }, 500);
57
- }, E = (s) => {
58
- o.value = s;
59
- }, g = () => {
60
- const s = t.hasTemplatesByCollectionType, r = [];
61
- if (Object.entries(s).forEach(([c, p]) => {
62
- p || r.push(Number(c));
63
- }), r.length === 0)
64
- return !0;
65
- const a = r.map((c) => R[c]);
66
- let u = "";
67
- if (r.length === 1)
68
- u = e("unsubscription-preference.create-page-to-continue", {
69
- page: a[0]
70
- });
71
- else if (r.length === 2)
72
- u = e("unsubscription-preference.create-pages-to-continue", {
73
- page1: a[0],
74
- page2: a[1]
75
- });
76
- else {
77
- const c = a.pop() ?? "", p = a.join(", ");
78
- u = e("unsubscription-preference.create-multiple-pages-to-continue", {
79
- pages: p,
80
- lastPage: c
81
- });
82
- }
83
- return f({
84
- type: U.Warning,
85
- message: u,
86
- actionButton: {
87
- text: "Go to Unsubscribe Pages",
88
- onClick: () => {
89
- window.location.href = P;
90
- }
91
- }
92
- }), !1;
93
- }, C = async () => {
94
- if (n.value = !0, await t.fetchTemplates(), t.setCollection(o.value), !g()) {
95
- n.value = !1, d();
96
- return;
97
- }
98
- n.value = !1, t.typeSelectionDrawerStatus = !1, t.pageSelectionDrawerStatus = !0;
99
- };
100
- return _(() => t.typeSelectionDrawerStatus, (s) => {
101
- s && (i.value = !0, o.value = l.GLOBAL_UNSUBSCRIBE, t.isGlobalUnsubscribeDisabled && (o.value = t.isSubscriptionPreferencesCenterDisabled ? 0 : l.SUBSCRIPTION_PREFERENCE_CENTER), i.value = !1);
102
- }), { __sfc: !0, trans: e, showToaster: f, unsubscribeStore: t, isSelecting: n, skeletonStatus: i, selectedCollection: o, descriptionText: S, segmentList: T, footerButtonGroupOptions: y, closeModal: d, changeCollection: E, validateTemplates: g, selectCollection: C, WpDrawer: v, InSegments: I };
103
- }
104
- });
105
- export {
106
- z as default
107
- };
@@ -1,2 +0,0 @@
1
- declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue/types/v3-component-options.js").ComponentOptionsMixin, import("vue/types/v3-component-options.js").ComponentOptionsMixin, {}, string, Readonly<import("vue").ExtractPropTypes<{}>>, {}>;
2
- export default _default;
@@ -1,18 +0,0 @@
1
- import o from "./UnsubscribeWrapper.vue2.js";
2
- import t from "../../../_virtual/_plugin-vue2_normalizer.js";
3
- var _ = function() {
4
- var s;
5
- var e = this, n = e._self._c, r = e._self._setupProxy;
6
- return (s = r.config.extensions) != null && s.unsubscribe ? n("div", [n(r.UnsubscribeTypeSelection), n(r.UnsubscribePageSelection)], 1) : e._e();
7
- }, c = [], i = /* @__PURE__ */ t(
8
- o,
9
- _,
10
- c,
11
- !1,
12
- null,
13
- null
14
- );
15
- const l = i.exports;
16
- export {
17
- l as default
18
- };
@@ -1,12 +0,0 @@
1
- import { defineComponent as t, defineAsyncComponent as e } from "vue";
2
- import { useConfig as r } from "../../../composables/useConfig.js";
3
- const m = /* @__PURE__ */ t({
4
- __name: "UnsubscribeWrapper",
5
- setup(i) {
6
- const n = e(() => import("./UnsubscribePageSelection.vue.js")), o = e(() => import("./UnsubscribeTypeSelection.vue.js")), { config: s } = r();
7
- return { __sfc: !0, UnsubscribePageSelection: n, UnsubscribeTypeSelection: o, config: s };
8
- }
9
- });
10
- export {
11
- m as default
12
- };
@@ -1 +0,0 @@
1
- export declare function migrateUnsubscribe(html: string): Promise<string>;
@@ -1,124 +0,0 @@
1
- var h = Object.defineProperty;
2
- var x = (l, e, t) => e in l ? h(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
3
- var S = (l, e, t) => x(l, typeof e != "symbol" ? e + "" : e, t);
4
- import { MERGE_TAGS as k, PAGE_TYPES as p } from "../../enums/unsubscribe.js";
5
- import { DATA_ATTRIBUTES as A } from "../../extensions/Blocks/Unsubscribe/utils/constants.js";
6
- import { useUnsubscribeStore as T } from "../../stores/unsubscribe.js";
7
- class C {
8
- constructor() {
9
- S(this, "parser");
10
- this.parser = new DOMParser();
11
- }
12
- async migrate(e) {
13
- try {
14
- const t = this.parser.parseFromString(e, "text/html"), i = t.querySelectorAll("td.unsubscribe-block");
15
- if (!i.length)
16
- return e;
17
- const o = T();
18
- return await o.fetchTemplates(), i.forEach((r) => {
19
- const c = r.getAttribute("id"), g = this.extractPaddingClass(r), u = r.getAttribute("bgcolor") || "", n = this.extractUnsubscribeContent(r), s = this.getCollectionTypeFromMergeTag(n.linkHref), b = o.getSelectedUnsubscribePagesByCollection(s);
20
- console.debug("[UnsubscribeMigrator]", {
21
- mergeTag: n.linkHref,
22
- collectionType: s,
23
- pageIds: b,
24
- paddingClass: g,
25
- bgColor: u
26
- });
27
- const f = this.buildUnsubscribeBlock(
28
- n,
29
- s,
30
- b,
31
- g,
32
- u
33
- ), a = this.parser.parseFromString(
34
- `<table id="tempDoc"><tbody><tr>${f}</tr></tbody></table>`,
35
- "text/html"
36
- ).querySelector(".unsubscribe-block-v2");
37
- a && r.parentNode && (a.setAttribute("id", c || ""), r.parentNode.replaceChild(a, r));
38
- }), t.documentElement.outerHTML;
39
- } catch (t) {
40
- return console.error("UnsubscribeMigrator failed:", t), e;
41
- }
42
- }
43
- extractPaddingClass(e) {
44
- const i = (e.getAttribute("class") || "").match(/\bes-p\d+\b/);
45
- return i ? i[0] : "";
46
- }
47
- extractUnsubscribeContent(e) {
48
- var m;
49
- const t = e.querySelector("p");
50
- if (!t)
51
- return {
52
- textBefore: "You can ",
53
- linkText: "unsubscribe",
54
- linkHref: "{{ins-unsubscribe-link}}",
55
- linkStyle: "",
56
- textAfter: " from our emails, if you need to.",
57
- isBold: !1,
58
- isItalic: !1,
59
- align: "center",
60
- paragraphStyle: ""
61
- };
62
- const i = e.getAttribute("align") || t.getAttribute("align") || "center", o = t.getAttribute("style") || "", r = t.querySelector("a.unsubscribe-link") || t.querySelector('a[href*="unsubscribe"]');
63
- if (!r)
64
- return {
65
- textBefore: "You can ",
66
- linkText: "unsubscribe",
67
- linkHref: "{{ins-unsubscribe-link}}",
68
- linkStyle: "",
69
- textAfter: " from our emails, if you need to.",
70
- isBold: !1,
71
- isItalic: !1,
72
- align: i,
73
- paragraphStyle: o
74
- };
75
- const c = ((m = r.textContent) == null ? void 0 : m.trim()) || "unsubscribe", g = r.getAttribute("href") || "{{ins-unsubscribe-link}}", u = r.getAttribute("style") || "", n = t.textContent || "", s = n.indexOf(c), b = s >= 0 ? n.substring(0, s).trim() : "You can ", f = s >= 0 ? n.substring(s + c.length).trim() : " from our emails, if you need to.", d = !!t.querySelector("b, strong"), a = !!t.querySelector("i, em");
76
- return {
77
- textBefore: b,
78
- linkText: c,
79
- linkHref: this.normalizeUnsubscribeHref(g),
80
- linkStyle: u,
81
- textAfter: f,
82
- isBold: d,
83
- isItalic: a,
84
- align: i,
85
- paragraphStyle: o
86
- };
87
- }
88
- buildUnsubscribeBlock(e, t, i, o, r) {
89
- const c = e.linkStyle ? ` style="${e.linkStyle}"` : "", u = `<a ${`href="${e.linkHref}" class="unsubscribe-link" target="_blank" data-unsubscribe-link="true"`}${c}>${e.linkText}</a>`, n = [];
90
- e.textBefore && n.push(e.textBefore), n.push(u), e.textAfter && n.push(e.textAfter);
91
- let s = n.join(" ");
92
- e.isBold && e.isItalic ? s = `<strong path="1,0"><em path="1,0,0">${s}</em></strong>` : e.isBold ? s = `<strong path="1,0">${s}</strong>` : e.isItalic && (s = `<em path="1,0">${s}</em>`);
93
- const b = e.align ? ` align="${e.align}"` : "", f = r ? ` bgcolor="${r}"` : "", d = e.paragraphStyle ? ` style="${e.paragraphStyle}"` : "", a = i.length > 0 ? ` ${A.PAGE_LIST}="${i.join(",")}"` : "", m = ` ${A.PAGE_TYPE}="${t}"`, y = "esd-block-text unsubscribe-block-v2 esd-block-unsubscribe esd-unsubscribe-block esd-extension-block";
94
- return `
95
- <td
96
- data-migration="true"
97
- esd-extension-block-id="unsubscribe-block"
98
- class="${o ? `${y} ${o}` : y}"
99
- ${b}${f}${m}${a}
100
- >
101
- <p path="1"${d}>
102
- ${s}
103
- </p>
104
- </td>
105
- `;
106
- }
107
- getCollectionTypeFromMergeTag(e) {
108
- return e === k[p.SUBSCRIPTION_PREFERENCE_CENTER] ? p.SUBSCRIPTION_PREFERENCE_CENTER : e === k[p.GLOBAL_UNSUBSCRIBE] ? p.GLOBAL_UNSUBSCRIBE : p.GLOBAL_UNSUBSCRIBE;
109
- }
110
- normalizeUnsubscribeHref(e) {
111
- if (Object.values(k).includes(e))
112
- return e;
113
- const i = e.match(/{{ins-(?:global-)?(?:preferences-)?unsubscribe-link}}/);
114
- return i ? i[0] : e.includes("unsubscribe") || e.includes("unsub") ? (console.warn(
115
- `[UnsubscribeMigrator] Unrecognized unsubscribe href format: "${e}". Defaulting to {{ins-unsubscribe-link}}`
116
- ), "{{ins-unsubscribe-link}}") : e;
117
- }
118
- }
119
- async function M(l) {
120
- return new C().migrate(l);
121
- }
122
- export {
123
- M as migrateUnsubscribe
124
- };
@@ -1,32 +0,0 @@
1
- import type { ImmutableHtmlNode } from '@stripoinc/ui-editor-extensions';
2
- import { Block, BlockCompositionType } from '@stripoinc/ui-editor-extensions';
3
- export declare const UNSUBSCRIBE_BLOCK_ID = "unsubscribe-block";
4
- export declare class UnsubscribeBlock extends Block {
5
- private selectEventListener;
6
- private cancelEventListener;
7
- private currentNode?;
8
- constructor();
9
- getId(): string;
10
- getIcon(): string;
11
- getBlockCompositionType(): BlockCompositionType;
12
- getName(): string;
13
- getDescription(): string;
14
- getTemplate(): string;
15
- onCreated(node: ImmutableHtmlNode): void;
16
- onSelect(node: ImmutableHtmlNode): undefined;
17
- onDelete(node: ImmutableHtmlNode): undefined;
18
- onDestroy(): void;
19
- private _setupSelectEventListener;
20
- private _removeSelectEventListener;
21
- private _setupCancelEventListener;
22
- private _removeCancelEventListener;
23
- private _handleCancel;
24
- private _removeEventListeners;
25
- private _updateBlock;
26
- private _getMergeTag;
27
- private _openDrawer;
28
- private _checkExistingBlocks;
29
- private _loadBlockState;
30
- private _resetStoreState;
31
- private _removeBlockTemplatesFromStore;
32
- }
@@ -1,131 +0,0 @@
1
- var _ = Object.defineProperty;
2
- var d = (n, i, e) => i in n ? _(n, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[i] = e;
3
- var u = (n, i, e) => d(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 S, BlockCompositionType as h, ModificationDescription as b } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
7
- import { getDefaultTemplate as L } from "./template.js";
8
- import { UNSUBSCRIBE_EVENTS as a, DATA_ATTRIBUTES as o } from "./utils/constants.js";
9
- import { parsePageList as m } from "./utils/utils.js";
10
- const v = "unsubscribe-block", g = 'a[data-unsubscribe-link="true"]', B = ".unsubscribe-block-v2", f = "{{ins-unsubscribe-link}}", C = {
11
- [E.GLOBAL_UNSUBSCRIBE]: "{{ins-global-unsubscribe-link}}",
12
- [E.SUBSCRIPTION_PREFERENCE_CENTER]: "{{ins-preferences-unsubscribe-link}}"
13
- };
14
- class D extends S {
15
- constructor() {
16
- super();
17
- u(this, "selectEventListener", null);
18
- u(this, "cancelEventListener", null);
19
- u(this, "currentNode");
20
- }
21
- getId() {
22
- return v;
23
- }
24
- getIcon() {
25
- return "unsubscribe-icon";
26
- }
27
- getBlockCompositionType() {
28
- return h.BLOCK;
29
- }
30
- getName() {
31
- return this.api.translate("Unsubscribe Block");
32
- }
33
- getDescription() {
34
- return this.api.translate("Unsubscribe Block Description");
35
- }
36
- getTemplate() {
37
- return L();
38
- }
39
- onCreated(e) {
40
- "getAttribute" in e && e.getAttribute("data-migration") || (this.currentNode = e, this._resetStoreState(), this._setupSelectEventListener(), this._setupCancelEventListener(), this._checkExistingBlocks(), this._openDrawer());
41
- }
42
- onSelect(e) {
43
- this.currentNode = e, this._resetStoreState(), this._loadBlockState(e), this._setupSelectEventListener();
44
- }
45
- onDelete(e) {
46
- this._removeEventListeners(), this._removeBlockTemplatesFromStore(e), this._resetStoreState();
47
- }
48
- onDestroy() {
49
- this._removeEventListeners(), this.currentNode = void 0;
50
- }
51
- _setupSelectEventListener() {
52
- this._removeSelectEventListener(), this.selectEventListener = (e) => {
53
- const r = e, { collectionType: t, selectedPages: s } = r.detail;
54
- this._updateBlock(t, s.join(","));
55
- }, document.addEventListener(a.SELECT, this.selectEventListener);
56
- }
57
- _removeSelectEventListener() {
58
- this.selectEventListener && (document.removeEventListener(a.SELECT, this.selectEventListener), this.selectEventListener = null);
59
- }
60
- _setupCancelEventListener() {
61
- this._removeCancelEventListener(), this.cancelEventListener = () => {
62
- this._handleCancel();
63
- }, document.addEventListener(a.CANCEL, this.cancelEventListener);
64
- }
65
- _removeCancelEventListener() {
66
- this.cancelEventListener && (document.removeEventListener(a.CANCEL, this.cancelEventListener), this.cancelEventListener = null);
67
- }
68
- _handleCancel() {
69
- this.currentNode && this.api.getDocumentModifier().modifyHtml(this.currentNode).delete().apply(new b("Removed unsubscribe block due to cancel"));
70
- }
71
- _removeEventListeners() {
72
- this._removeSelectEventListener(), this._removeCancelEventListener();
73
- }
74
- _updateBlock(e, r) {
75
- if (!this.currentNode || !("querySelector" in this.currentNode))
76
- return;
77
- const t = this.currentNode.querySelector(g);
78
- if (!t)
79
- return;
80
- const s = this._getMergeTag(e);
81
- this.api.getDocumentModifier().modifyHtml(t).setAttribute("href", s).apply(new b(`Updated unsubscribe link to ${s}`)), this.api.getDocumentModifier().modifyHtml(this.currentNode).setAttribute(o.PAGE_TYPE, e.toString()).setAttribute(o.PAGE_LIST, r).apply(new b("Updated unsubscribe block metadata"));
82
- }
83
- _getMergeTag(e) {
84
- return C[e] ?? f;
85
- }
86
- _openDrawer() {
87
- try {
88
- const e = c();
89
- e.typeSelectionDrawerStatus = !0;
90
- } catch (e) {
91
- console.error("[UnsubscribeBlock] Failed to open drawer:", e);
92
- }
93
- }
94
- _checkExistingBlocks() {
95
- const e = c();
96
- e.isGlobalUnsubscribeDisabled = !1, e.isSubscriptionPreferencesCenterDisabled = !1, this.api.getDocumentRoot().querySelectorAll(B).forEach((t) => {
97
- if ("getAttribute" in t) {
98
- const s = t.getAttribute(o.PAGE_TYPE);
99
- if (s) {
100
- const l = Number(s);
101
- l === E.GLOBAL_UNSUBSCRIBE ? e.isGlobalUnsubscribeDisabled = !0 : l === E.SUBSCRIPTION_PREFERENCE_CENTER && (e.isSubscriptionPreferencesCenterDisabled = !0);
102
- }
103
- }
104
- });
105
- }
106
- _loadBlockState(e) {
107
- if (!("getAttribute" in e))
108
- return;
109
- const r = e.getAttribute(o.PAGE_TYPE), t = e.getAttribute(o.PAGE_LIST);
110
- if (!r || !t)
111
- return;
112
- const s = c(), l = Number(r), p = m(t);
113
- s.setCollectionWithoutAutoSelection(l), s.loadSelectedTemplates(p);
114
- }
115
- _resetStoreState() {
116
- c().$reset();
117
- }
118
- _removeBlockTemplatesFromStore(e) {
119
- if (!("getAttribute" in e))
120
- return;
121
- const r = e.getAttribute(o.PAGE_LIST);
122
- if (!r)
123
- return;
124
- const t = c(), s = m(r);
125
- t.removeUnsubscribePages(s);
126
- }
127
- }
128
- export {
129
- v as UNSUBSCRIBE_BLOCK_ID,
130
- D as UnsubscribeBlock
131
- };
@@ -1,29 +0,0 @@
1
- import type { ImmutableHtmlNode } from '@stripoinc/ui-editor-extensions';
2
- import { Control } from '@stripoinc/ui-editor-extensions';
3
- export declare const UNSUBSCRIBE_CONTROL_ID = "ui-elements-unsubscribe";
4
- export declare class UnsubscribeControl extends Control {
5
- private currentPreviewIndex;
6
- private currentNode?;
7
- private currentPages?;
8
- private valueChangeHandlers;
9
- private lastParsedAttribute?;
10
- getId(): string;
11
- getTemplate(): string;
12
- onTemplateNodeUpdated(node: ImmutableHtmlNode): void;
13
- onRender(): void;
14
- onDestroy(): void;
15
- private get totalTemplates();
16
- private _listenToFormUpdates;
17
- private _onButtonClick;
18
- private _onPrevClick;
19
- private _onNextClick;
20
- private _updatePreview;
21
- private _updateCounter;
22
- private _getPreview;
23
- private _getButton;
24
- private _getLabel;
25
- private _getIconButton;
26
- private _getPrevButton;
27
- private _getNextButton;
28
- private _getCounterText;
29
- }
@@ -1,167 +0,0 @@
1
- var h = Object.defineProperty;
2
- var d = (a, s, e) => s in a ? h(a, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[s] = e;
3
- var u = (a, s, e) => d(a, typeof s != "symbol" ? s + "" : s, e);
4
- import { useUnsubscribeStore as l } from "../../../stores/unsubscribe.js";
5
- import { Control as T, UEAttr as i, UIElementType as n } from "../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
6
- import { DATA_ATTRIBUTES as p } from "./utils/constants.js";
7
- import { parsePageList as _ } from "./utils/utils.js";
8
- const g = "ui-elements-unsubscribe", r = {
9
- SELECT_BUTTON: "selectTemplateButton",
10
- PREV_BUTTON: "prevButton",
11
- NEXT_BUTTON: "nextButton",
12
- COUNTER_TEXT: "counterText",
13
- PREVIEW_IMAGE: "previewImage"
14
- };
15
- class N extends T {
16
- constructor() {
17
- super(...arguments);
18
- u(this, "currentPreviewIndex", 0);
19
- u(this, "currentNode");
20
- u(this, "currentPages");
21
- u(this, "valueChangeHandlers", []);
22
- u(this, "lastParsedAttribute");
23
- }
24
- getId() {
25
- return g;
26
- }
27
- getTemplate() {
28
- return `
29
- <div class="unsubscribe-controls-container container stretch widest-spacing">
30
- ${this._getPreview()}
31
- ${this._getButton()}
32
- </div>
33
- `;
34
- }
35
- onTemplateNodeUpdated(e) {
36
- if (this.currentNode = e, "getAttribute" in this.currentNode) {
37
- const t = this.currentNode.getAttribute(p.PAGE_LIST);
38
- t && (t !== this.lastParsedAttribute && (this.currentPages = _(t), this.lastParsedAttribute = t, this.currentPreviewIndex = 0), this._updatePreview(), this._updateCounter());
39
- }
40
- }
41
- onRender() {
42
- this._listenToFormUpdates(), this._updateCounter();
43
- }
44
- onDestroy() {
45
- this.valueChangeHandlers.forEach((e) => {
46
- typeof e == "function" && e();
47
- }), this.valueChangeHandlers = [], this.currentNode = void 0, this.currentPages = void 0, this.currentPreviewIndex = 0, this.lastParsedAttribute = void 0;
48
- }
49
- get totalTemplates() {
50
- var e;
51
- return ((e = this.currentPages) == null ? void 0 : e.length) ?? 0;
52
- }
53
- _listenToFormUpdates() {
54
- this.valueChangeHandlers.push(
55
- this.api.onValueChanged(r.SELECT_BUTTON, () => this._onButtonClick())
56
- ), this.valueChangeHandlers.push(
57
- this.api.onValueChanged(r.PREV_BUTTON, () => this._onPrevClick())
58
- ), this.valueChangeHandlers.push(
59
- this.api.onValueChanged(r.NEXT_BUTTON, () => this._onNextClick())
60
- );
61
- }
62
- _onButtonClick() {
63
- try {
64
- const e = l();
65
- e.activeType = e.getSelectedCollection[this.currentPreviewIndex], e.pageSelectionUpdateStatus = !0, e.pageSelectionDrawerStatus = !0;
66
- } catch (e) {
67
- console.error("[UnsubscribeControl] Failed to open drawer:", e);
68
- }
69
- }
70
- _onPrevClick() {
71
- this.currentPreviewIndex > 0 && (this.currentPreviewIndex--, this._updatePreview(), this._updateCounter());
72
- }
73
- _onNextClick() {
74
- this.currentPreviewIndex < this.totalTemplates - 1 && (this.currentPreviewIndex++, this._updatePreview(), this._updateCounter());
75
- }
76
- _updatePreview() {
77
- var e;
78
- if ((e = this.currentPages) != null && e.length)
79
- try {
80
- const t = this.currentPages[this.currentPreviewIndex], o = l().getThumbnailByTemplateId(t);
81
- if (!o) {
82
- console.warn("[UnsubscribeControl] No thumbnail found for page:", t);
83
- return;
84
- }
85
- this.api.updateValues({
86
- [r.PREVIEW_IMAGE]: o
87
- });
88
- } catch (t) {
89
- console.error("[UnsubscribeControl] Failed to update preview:", t);
90
- }
91
- }
92
- _updateCounter() {
93
- const e = this.currentPreviewIndex + 1, t = this.totalTemplates, c = this.currentPreviewIndex === 0, o = this.currentPreviewIndex >= t - 1;
94
- this.api.setUIEAttribute(r.PREV_BUTTON, i.BUTTON.disabled, c), this.api.setUIEAttribute(r.NEXT_BUTTON, i.BUTTON.disabled, o), this.api.setUIEAttribute(
95
- r.COUNTER_TEXT,
96
- i.LABEL.text,
97
- `${this.api.translate("Showing")} ${e} ${this.api.translate("of")} ${t}`
98
- );
99
- }
100
- _getPreview() {
101
- return `
102
- <div class="unsubscribe-preview-container">
103
- <div class="unsubscribe-preview-header">
104
- <div class="unsubscribe-preview-title">${this.api.translate("Unsubscribe Template")}</div>
105
- <div class="unsubscribe-preview-controls">
106
- ${this._getPrevButton()}
107
- ${this._getCounterText()}
108
- ${this._getNextButton()}
109
- </div>
110
- </div>
111
- <unsubscribe-preview name="${r.PREVIEW_IMAGE}"></unsubscribe-preview>
112
- </div>
113
- `;
114
- }
115
- _getButton() {
116
- return `
117
- <${n.BUTTON}
118
- id="${r.SELECT_BUTTON}"
119
- class="primary full-width"
120
- ${i.BUTTON.name}="${r.SELECT_BUTTON}"
121
- ${i.BUTTON.caption}="${this.api.translate("Select Template")}"
122
- >
123
- </${n.BUTTON}>
124
- `;
125
- }
126
- _getLabel(e, t) {
127
- return `
128
- <${n.LABEL}
129
- ${i.LABEL.text}="${e}"
130
- ${i.LABEL.name}="${t}"
131
- >
132
- </${n.LABEL}>
133
- `;
134
- }
135
- _getIconButton(e, t, c) {
136
- const o = c ? `${i.BUTTON.disabled}="true"` : "";
137
- return `
138
- <${n.BUTTON}
139
- id="${e}"
140
- class="flat-inline flat-white"
141
- ${i.BUTTON.name}="${e}"
142
- ${o}
143
- >
144
- <${n.ICON}
145
- src="${t}"
146
- class="icon-button"
147
- ></${n.ICON}>
148
- </${n.BUTTON}>
149
- `;
150
- }
151
- _getPrevButton() {
152
- const e = this.currentPreviewIndex === 0;
153
- return this._getIconButton(r.PREV_BUTTON, "arrow-back", e);
154
- }
155
- _getNextButton() {
156
- const e = this.currentPreviewIndex >= this.totalTemplates - 1;
157
- return this._getIconButton(r.NEXT_BUTTON, "arrow-right", e);
158
- }
159
- _getCounterText() {
160
- const t = `Showing ${this.currentPreviewIndex + 1} of ${this.totalTemplates}`;
161
- return this._getLabel(t, r.COUNTER_TEXT);
162
- }
163
- }
164
- export {
165
- g as UNSUBSCRIBE_CONTROL_ID,
166
- N as UnsubscribeControl
167
- };
@@ -1,11 +0,0 @@
1
- import { UIElement } from '@stripoinc/ui-editor-extensions';
2
- export declare const PREVIEW_UI_ELEMENT_ID = "unsubscribe-preview";
3
- export declare class PreviewUIElement extends UIElement {
4
- private imgElement?;
5
- getId(): string;
6
- getTemplate(): string;
7
- onRender(container: HTMLElement): void;
8
- setValue(value: string): void;
9
- getValue(): string;
10
- onDestroy(): void;
11
- }