UNPKG

@uva-glass/component-library

Version:

React components UvA

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