@uva-glass/component-library
Version:
React components UvA
165 lines (164 loc) • 6.83 kB
JavaScript
import { p as X, O as _, U as x, d as y, m as F } from "./LexicalLink.prod-Du8ZoNsh.js";
import { o as G } from "./LexicalComposerContext.prod-DLlRM5wP.js";
import { j } from "./LexicalUtils.prod-DVr8VsHc.js";
import { a as v, c as E, P as H, J, Y as T, X as L, aE as Y, M as P, h as N } from "./Lexical.prod-CniF7zEE.js";
import { useEffect as B } from "react";
function b(t, e = (n) => n) {
return (n) => {
const i = t.exec(n);
return i === null ? null : { index: i.index, length: i[0].length, text: i[0], url: e(i[0]) };
};
}
function D(t, e) {
for (let n = 0; n < e.length; n++) {
const i = e[n](t);
if (i) return i;
}
return null;
}
const K = /[.,;\s]/;
function U(t) {
return K.test(t);
}
function I(t) {
return U(t[t.length - 1]);
}
function Z(t) {
return U(t[0]);
}
function $(t) {
let e = t.getPreviousSibling();
return N(e) && (e = e.getLastDescendant()), e === null || P(e) || T(e) && I(e.getTextContent());
}
function k(t) {
let e = t.getNextSibling();
return N(e) && (e = e.getFirstDescendant()), e === null || P(e) || T(e) && Z(e.getTextContent());
}
function W(t, e, n, i) {
return (t > 0 ? U(n[t - 1]) : $(i[0])) ? e < n.length ? U(n[e]) : k(i[i.length - 1]) : !1;
}
function q(t, e, n) {
const i = [], u = [], o = [];
let s = 0, r = 0;
const a = [...t];
for (; a.length > 0; ) {
const g = a[0], l = g.getTextContent().length, c = r;
r + l <= e ? (i.push(g), s += l) : c >= n ? o.push(g) : u.push(g), r += l, a.shift();
}
return [s, i, u, o];
}
function Q(t, e, n, i) {
const u = F(i.url, i.attributes);
if (t.length === 1) {
let o, s = t[0];
e === 0 ? [o, s] = s.splitText(n) : [, o, s] = s.splitText(e, n);
const r = L(i.text);
return r.setFormat(o.getFormat()), r.setDetail(o.getDetail()), r.setStyle(o.getStyle()), u.append(r), o.replace(u), s;
}
if (t.length > 1) {
const o = t[0];
let s, r = o.getTextContent().length;
e === 0 ? s = o : [, s] = o.splitText(e);
const a = [];
let g;
for (let h = 1; h < t.length; h++) {
const d = t[h], p = d.getTextContent().length, w = r;
if (w < n) if (r + p <= n) a.push(d);
else {
const [m, A] = d.splitText(n - w);
a.push(m), g = A;
}
r += p;
}
const l = v(), c = l ? l.getNodes().find(T) : void 0, f = L(s.getTextContent());
return f.setFormat(s.getFormat()), f.setDetail(s.getDetail()), f.setStyle(s.getStyle()), u.append(f, ...a), c && c === s && (E(l) ? f.select(l.anchor.offset, l.focus.offset) : Y(l) && f.select(0, f.getTextContent().length)), s.replace(u), g;
}
}
function z(t, e, n) {
const i = t.getChildren(), u = i.length;
for (let a = 0; a < u; a++) {
const g = i[a];
if (!T(g) || !g.isSimpleText()) return R(t), void n(null, t.getURL());
}
const o = t.getTextContent(), s = D(o, e);
if (s === null || s.text !== o || !$(t) || !k(t)) return R(t), void n(null, t.getURL());
const r = t.getURL();
if (r !== s.url && (t.setURL(s.url), n(s.url, r)), s.attributes) {
const a = t.getRel();
a !== s.attributes.rel && (t.setRel(s.attributes.rel || null), n(s.attributes.rel || null, a));
const g = t.getTarget();
g !== s.attributes.target && (t.setTarget(s.attributes.target || null), n(s.attributes.target || null, g));
}
}
function R(t) {
const e = t.getChildren();
for (let n = e.length - 1; n >= 0; n--) t.insertAfter(e[n]);
return t.remove(), e.map((n) => n.getLatest());
}
function V(t, e, n) {
B(() => {
t.hasNodes([X]) || function(u, ...o) {
const s = new URL("https://lexical.dev/docs/error"), r = new URLSearchParams();
r.append("code", u);
for (const a of o) r.append("v", a);
throw s.search = r.toString(), Error(`Minified Lexical error #${u}; visit ${s.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`);
}(77);
const i = (u, o) => {
n && n(u, o);
};
return j(t.registerNodeTransform(J, (u) => {
const o = u.getParentOrThrow(), s = u.getPreviousSibling();
if (x(o) && !o.getIsUnlinked()) z(o, e, i);
else if (!y(o)) {
if (u.isSimpleText() && (Z(u.getTextContent()) || !x(s))) {
const r = function(a) {
const g = [a];
let l = a.getNextSibling();
for (; l !== null && T(l) && l.isSimpleText() && (g.push(l), !/[\s]/.test(l.getTextContent())); ) l = l.getNextSibling();
return g;
}(u);
(function(a, g, l) {
let c = [...a];
const f = c.map((w) => w.getTextContent()).join("");
let h, d = f, p = 0;
for (; (h = D(d, g)) && h !== null; ) {
const w = h.index, m = w + h.length;
if (W(p + w, p + m, f, c)) {
const [A, , O, C] = q(c, p + w, p + m), S = Q(O, p + w - A, p + m - A, h);
c = S ? [S, ...C] : C, l(h.url, null), p = 0;
} else p += m;
d = d.substring(m);
}
})(r, e, i);
}
(function(r, a, g) {
const l = r.getPreviousSibling(), c = r.getNextSibling(), f = r.getTextContent();
var h;
!x(l) || l.getIsUnlinked() || Z(f) && (h = f, !(l.isEmailURI() ? /^\.[a-zA-Z]{2,}/.test(h) : /^\.[a-zA-Z0-9]{1,}/.test(h))) || (l.append(r), z(l, a, g), g(null, l.getURL())), !x(c) || c.getIsUnlinked() || I(f) || (R(c), z(c, a, g), g(null, c.getURL()));
})(u, e, i);
}
}), t.registerCommand(_, (u) => {
const o = v();
return u !== null || !E(o) || o.extract().forEach((s) => {
const r = s.getParent();
if (x(r)) return r.setIsUnlinked(!r.getIsUnlinked()), r.markDirty(), !0;
}), !1;
}, H));
}, [t, e, n]);
}
function at({ matchers: t, onChange: e }) {
const [n] = G();
return V(n, t, e), null;
}
const tt = /^(http|https):\/\//, M = /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/, et = /(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/, nt = /^(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})?$/, ut = (t) => t === "https://" || M.test(t), gt = (t) => t === "https://" || nt.test(t), ct = [
b(M, (t) => tt.test(t) ? t : `//${t}`),
b(et, (t) => `mailto:${t}`)
], ft = (t) => /^https?:\/\//i.test(t) ? t : `https://${t}`;
export {
ct as M,
ut as a,
ft as e,
gt as v,
at as w
};
//# sourceMappingURL=helpers-ChM6xtQG.js.map