UNPKG

@uva-glass/component-library

Version:

React components UvA

276 lines (275 loc) 8.31 kB
import { r as W, w as S } from "./LexicalUtils.prod-Dny9Fu94.js"; import { f as I, e as y, c as k, d as x, o as C, q as J, a as T, u as b, C as v, g as M } from "./Lexical.prod-CWyHQUEM.js"; const D = /* @__PURE__ */ new Set(["http:", "https:", "mailto:", "sms:", "tel:"]); class p extends I { static getType() { return "link"; } static clone(t) { return new p(t.__url, { rel: t.__rel, target: t.__target, title: t.__title }, t.__key); } constructor(t = "", e = {}, u) { super(u); const { target: o = null, rel: a = null, title: _ = null } = e; this.__url = t, this.__target = o, this.__rel = a, this.__title = _; } createDOM(t) { const e = document.createElement("a"); return e.href = this.sanitizeUrl(this.__url), this.__target !== null && (e.target = this.__target), this.__rel !== null && (e.rel = this.__rel), this.__title !== null && (e.title = this.__title), W(e, t.theme.link), e; } updateDOM(t, e, u) { if (y(e)) { const o = this.__url, a = this.__target, _ = this.__rel, c = this.__title; o !== t.__url && (e.href = o), a !== t.__target && (a ? e.target = a : e.removeAttribute("target")), _ !== t.__rel && (_ ? e.rel = _ : e.removeAttribute("rel")), c !== t.__title && (c ? e.title = c : e.removeAttribute("title")); } return !1; } static importDOM() { return { a: (t) => ({ conversion: B, priority: 1 }) }; } static importJSON(t) { return d().updateFromJSON(t); } updateFromJSON(t) { return super.updateFromJSON(t).setURL(t.url).setRel(t.rel || null).setTarget(t.target || null).setTitle(t.title || null); } sanitizeUrl(t) { try { const e = new URL(t); if (!D.has(e.protocol)) return "about:blank"; } catch { return t; } return t; } exportJSON() { return { ...super.exportJSON(), rel: this.getRel(), target: this.getTarget(), title: this.getTitle(), url: this.getURL() }; } getURL() { return this.getLatest().__url; } setURL(t) { const e = this.getWritable(); return e.__url = t, e; } getTarget() { return this.getLatest().__target; } setTarget(t) { const e = this.getWritable(); return e.__target = t, e; } getRel() { return this.getLatest().__rel; } setRel(t) { const e = this.getWritable(); return e.__rel = t, e; } getTitle() { return this.getLatest().__title; } setTitle(t) { const e = this.getWritable(); return e.__title = t, e; } insertNewAfter(t, e = !0) { const u = d(this.__url, { rel: this.__rel, target: this.__target, title: this.__title }); return this.insertAfter(u, e), u; } canInsertTextBefore() { return !1; } canInsertTextAfter() { return !1; } canBeEmpty() { return !1; } isInline() { return !0; } extractWithChild(t, e, u) { if (!k(e)) return !1; const o = e.anchor.getNode(), a = e.focus.getNode(); return this.isParentOf(o) && this.isParentOf(a) && e.getTextContent().length > 0; } isEmailURI() { return this.__url.startsWith("mailto:"); } isWebSiteURI() { return this.__url.startsWith("https://") || this.__url.startsWith("http://"); } } function B(n) { let t = null; if (y(n)) { const e = n.textContent; (e !== null && e !== "" || n.children.length > 0) && (t = d(n.getAttribute("href") || "", { rel: n.getAttribute("rel"), target: n.getAttribute("target"), title: n.getAttribute("title") })); } return { node: t }; } function d(n = "", t) { return J(new p(n, t)); } function f(n) { return n instanceof p; } class O extends p { constructor(t = "", e = {}, u) { super(t, e, u), this.__isUnlinked = e.isUnlinked !== void 0 && e.isUnlinked !== null && e.isUnlinked; } static getType() { return "autolink"; } static clone(t) { return new O(t.__url, { isUnlinked: t.__isUnlinked, rel: t.__rel, target: t.__target, title: t.__title }, t.__key); } getIsUnlinked() { return this.__isUnlinked; } setIsUnlinked(t) { const e = this.getWritable(); return e.__isUnlinked = t, e; } createDOM(t) { return this.__isUnlinked ? document.createElement("span") : super.createDOM(t); } updateDOM(t, e, u) { return super.updateDOM(t, e, u) || t.__isUnlinked !== this.__isUnlinked; } static importJSON(t) { return A().updateFromJSON(t); } updateFromJSON(t) { return super.updateFromJSON(t).setIsUnlinked(t.isUnlinked || !1); } static importDOM() { return null; } exportJSON() { return { ...super.exportJSON(), isUnlinked: this.__isUnlinked }; } insertNewAfter(t, e = !0) { const u = this.getParentOrThrow().insertNewAfter(t, e); if (x(u)) { const o = A(this.__url, { isUnlinked: this.__isUnlinked, rel: this.__rel, target: this.__target, title: this.__title }); return u.append(o), o; } return null; } } function A(n = "", t) { return J(new O(n, t)); } function U(n) { return n instanceof O; } const K = C(); function L(n, t) { if (n.type === "element") { const e = n.getNode(); return x(e) || function(u, ...o) { const a = new URL("https://lexical.dev/docs/error"), _ = new URLSearchParams(); _.append("code", u); for (const c of o) _.append("v", c); throw a.search = _.toString(), Error(`Minified Lexical error #${u}; visit ${a.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`); }(252), e.getChildren()[n.offset + t] || null; } return null; } function q(n, t = {}) { const { target: e, title: u } = t, o = t.rel === void 0 ? "noreferrer" : t.rel, a = T(); if (a === null || !k(a) && !b(a)) return; if (b(a)) { const i = a.getNodes(); return i.length === 0 ? void 0 : void i.forEach((r) => { if (n === null) { const s = S(r, (l) => !U(l) && f(l)); s && (s.insertBefore(r), s.getChildren().length === 0 && s.remove()); } else { const s = S(r, (l) => !U(l) && f(l)); if (s) s.setURL(n), e !== void 0 && s.setTarget(e), o !== void 0 && s.setRel(o); else { const l = d(n, { rel: o, target: e }); r.insertBefore(l), l.append(r); } } }); } const _ = a.extract(); if (n === null) return void _.forEach((i) => { const r = S(i, (s) => !U(s) && f(s)); if (r) { const s = r.getChildren(); for (let l = 0; l < s.length; l++) r.insertBefore(s[l]); r.remove(); } }); const c = /* @__PURE__ */ new Set(), w = (i) => { c.has(i.getKey()) || (c.add(i.getKey()), i.setURL(n), e !== void 0 && i.setTarget(e), o !== void 0 && i.setRel(o), u !== void 0 && i.setTitle(u)); }; if (_.length === 1) { const i = P(_[0], f); if (i !== null) return w(i); } (function(i) { const r = T(); if (!k(r)) return i(); const s = v(r), l = s.isBackward(), h = L(s.anchor, l ? -1 : 0), m = L(s.focus, l ? 0 : -1); if (i(), h || m) { const R = T(); if (k(R)) { const N = R.clone(); if (h) { const g = h.getParent(); g && N.anchor.set(g.getKey(), h.getIndexWithinParent() + (l ? 1 : 0), "element"); } if (m) { const g = m.getParent(); g && N.focus.set(g.getKey(), m.getIndexWithinParent() + (l ? 0 : 1), "element"); } M(v(N)); } } })(() => { let i = null; for (const r of _) { if (!r.isAttached()) continue; const s = P(r, f); if (s) { w(s); continue; } if (x(r)) { if (!r.isInline()) continue; if (f(r)) { if (!(U(r) || i !== null && i.getParentOrThrow().isParentOf(r))) { w(r), i = r; continue; } for (const h of r.getChildren()) r.insertBefore(h); r.remove(); continue; } } const l = r.getPreviousSibling(); f(l) && l.is(i) ? l.append(r) : (i = d(n, { rel: o, target: e, title: u }), r.insertAfter(i), i.append(r)); } }); } function P(n, t) { let e = n; for (; e !== null && e.getParent() !== null && !t(e); ) e = e.getParentOrThrow(); return t(e) ? e : null; } export { q as N, U as O, A as U, p as g, K as k, O as m, f as p }; //# sourceMappingURL=LexicalLink.prod-DbxnRszt.js.map