@useinsider/guido 3.30.0-beta.232ea3c → 3.30.0-beta.2d741af

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,49 +1,90 @@
1
- import { protectLiquid as a, restoreLiquid as u } from "./liquidProtection.js";
2
- const b = "td.unsubscribe-block", l = ["a.unsubscribe-link", 'a[href*="unsubscribe"]'], d = "esd-block-text", m = [
1
+ import { hasInsiderUnsubscribeCode as f } from "../composables/validators/useUnsubscribeBlockValidator.js";
2
+ import { UNSUBSCRIBE_LINK_SELECTOR as A } from "../extensions/Blocks/Unsubscribe/utils/constants.js";
3
+ import { protectLiquid as C, restoreLiquid as _ } from "./liquidProtection.js";
4
+ const u = "td.unsubscribe-block", p = ["a.unsubscribe-link", 'a[href*="unsubscribe"]'], v = `${u}, .unsubscribe-block-v2`, y = "esd-block-text", U = [
3
5
  "unsubscribe-block",
4
6
  "esd-extension",
5
7
  "esd-extension-block",
6
8
  "esd-unsubscribe-block",
7
9
  "esd-block-unsubscribe"
8
- ], L = "esd-extension-block-id", S = "data-unsubscribe-", E = "address,article,aside,blockquote,center,details,dialog,dir,div,dd,dl,dt,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,li,listing,main,menu,nav,ol,p,plaintext,pre,search,section,summary,table,ul,xmp", f = new RegExp(`class\\s*=\\s*(?:["'][^"']*)?(?<![\\w-])unsubscribe-block(?![\\w-])`, "i"), p = (e) => typeof e == "string" && f.test(e), y = (e) => l.some((t) => e.querySelector(t) !== null), g = (e) => {
9
- e.classList.remove(...m), e.classList.add(d), e.removeAttribute(L), Array.from(e.attributes).filter(({ name: t }) => t.startsWith(S)).forEach(({ name: t }) => e.removeAttribute(t)), e.querySelector(E) || (e.innerHTML = `<p path="1">${e.innerHTML}</p>`);
10
- }, h = (e) => {
11
- const t = Array.from(e.querySelectorAll(b)).filter((r) => !y(r));
12
- return t.forEach(g), t.length;
13
- }, v = (e) => {
10
+ ], h = "unsubscribe-block-v2", T = "esd-extension-block-id", l = "data-unsubscribe-", g = "unsubscribe-link", k = "address,article,aside,blockquote,center,details,dialog,dir,div,dd,dl,dt,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,hr,li,listing,main,menu,nav,ol,p,plaintext,pre,search,section,summary,table,ul,xmp", I = new RegExp(`class\\s*=\\s*(?:["'][^"']*)?(?<![\\w-])unsubscribe-block(?![\\w-])`, "i"), N = new RegExp(`class\\s*=\\s*(?:["'][^"']*)?(?<![\\w-])unsubscribe-block(?:-v2)?(?![\\w-])`, "i"), R = (e) => typeof e == "string" && I.test(e), B = (e) => p.some((t) => e.querySelector(t) !== null), b = (e) => {
11
+ e.classList.remove(...U), e.classList.add(y), e.removeAttribute(T), Array.from(e.attributes).filter(({ name: t }) => t.startsWith(l)).forEach(({ name: t }) => e.removeAttribute(t)), e.querySelector(k) || (e.innerHTML = `<p path="1">${e.innerHTML}</p>`);
12
+ }, O = (e) => {
13
+ const t = e.getAttribute("href") ?? "";
14
+ return f(t) || t.trim() === "" && e.matches(A);
15
+ }, M = (e) => {
16
+ e.classList.remove(g), e.classList.length === 0 && e.removeAttribute("class"), Array.from(e.attributes).filter(({ name: t }) => t.startsWith(l)).forEach(({ name: t }) => e.removeAttribute(t));
17
+ }, x = (e) => {
18
+ Array.from(e.querySelectorAll("a")).forEach((t) => {
19
+ if (O(t)) {
20
+ t.replaceWith(...Array.from(t.childNodes));
21
+ return;
22
+ }
23
+ M(t);
24
+ });
25
+ }, q = (e) => typeof e == "string" && N.test(e), D = (e) => {
26
+ const t = Array.from(e.querySelectorAll(v));
27
+ return t.forEach((r) => {
28
+ r.classList.remove(h), x(r), b(r);
29
+ }), t.length;
30
+ }, H = (e) => {
31
+ const t = Array.from(e.querySelectorAll(u)).filter((r) => !B(r));
32
+ return t.forEach(b), t.length;
33
+ }, a = (e) => {
14
34
  const t = e.trimStart(), r = new DOMParser();
15
35
  return /^<t[dh][\s>]/i.test(t) ? r.parseFromString(`<table><tbody><tr>${e}</tr></tbody></table>`, "text/html").querySelector("tr") : /^<tr[\s>]/i.test(t) ? r.parseFromString(`<table><tbody>${e}</tbody></table>`, "text/html").querySelector("tbody") : /^<table[\s>]/i.test(t) ? r.parseFromString(e, "text/html").body : (console.debug("[LegacyUnsubscribeConversion] Skipped module with a non-table root"), null);
16
- }, c = (e) => {
36
+ }, d = (e) => {
17
37
  const t = e.search(/<html[\s>]/i), r = [...e.matchAll(/<\/html\s*>/gi)].at(-1), s = (r == null ? void 0 : r.index) === void 0 ? -1 : r.index + r[0].length;
18
38
  return t < 0 || s <= t ? { head: "", root: e, tail: "" } : { head: e.slice(0, t), root: e.slice(t, s), tail: e.slice(s) };
19
- }, i = (e, t, r, s) => {
20
- if (!p(e))
39
+ }, K = {
40
+ detect: R,
41
+ convertCells: H
42
+ }, S = {
43
+ detect: q,
44
+ convertCells: D
45
+ }, n = (e, t, r, s, i = K) => {
46
+ if (!i.detect(e))
21
47
  return { html: e, converted: !1 };
22
48
  try {
23
- const o = a(e), n = t(o);
24
- return !n || h(n) === 0 ? { html: e, converted: !1 } : { html: u(r(n, o)), converted: !0 };
49
+ const o = C(e), c = t(o);
50
+ return !c || i.convertCells(c) === 0 ? { html: e, converted: !1 } : { html: _(r(c, o)), converted: !0 };
25
51
  } catch (o) {
26
52
  return console.error(`Failed to convert legacy unsubscribe blocks in ${s}:`, o), { html: e, converted: !1 };
27
53
  }
28
- }, C = (e) => i(
54
+ }, m = (e) => e.innerHTML, E = (e) => new DOMParser().parseFromString(d(e).root, "text/html"), L = (e, t) => {
55
+ const { head: r, tail: s } = d(t);
56
+ return `${r}${e.documentElement.outerHTML}${s}`;
57
+ }, F = (e) => n(
29
58
  e,
30
- v,
31
- (t) => t.innerHTML,
59
+ a,
60
+ m,
32
61
  "module"
33
- ), _ = (e) => i(
62
+ ), G = (e) => n(
34
63
  e,
35
- (t) => new DOMParser().parseFromString(c(t).root, "text/html"),
36
- (t, r) => {
37
- const { head: s, tail: o } = c(r);
38
- return `${s}${t.documentElement.outerHTML}${o}`;
39
- },
64
+ E,
65
+ L,
40
66
  "document"
67
+ ), P = (e) => n(
68
+ e,
69
+ a,
70
+ m,
71
+ "module",
72
+ S
73
+ ), V = (e) => n(
74
+ e,
75
+ E,
76
+ L,
77
+ "document",
78
+ S
41
79
  );
42
80
  export {
43
- l as LEGACY_UNSUBSCRIBE_LINK_SELECTORS,
44
- b as LEGACY_UNSUBSCRIBE_SELECTOR,
45
- _ as convertLegacyUnsubscribeInDocumentHtml,
46
- C as convertLegacyUnsubscribeInModuleHtml,
47
- h as convertLinklessLegacyUnsubscribeBlocks,
48
- p as hasLegacyUnsubscribeClass
81
+ p as LEGACY_UNSUBSCRIBE_LINK_SELECTORS,
82
+ u as LEGACY_UNSUBSCRIBE_SELECTOR,
83
+ V as convertAllUnsubscribeInDocumentHtml,
84
+ P as convertAllUnsubscribeInModuleHtml,
85
+ G as convertLegacyUnsubscribeInDocumentHtml,
86
+ F as convertLegacyUnsubscribeInModuleHtml,
87
+ H as convertLinklessLegacyUnsubscribeBlocks,
88
+ q as hasAnyUnsubscribeClass,
89
+ R as hasLegacyUnsubscribeClass
49
90
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.30.0-beta.232ea3c",
3
+ "version": "3.30.0-beta.2d741af",
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",