UNPKG

@uva-glass/component-library

Version:

React components UvA

256 lines (255 loc) 8.64 kB
import { B as E, R as k } from "./LexicalSelection.prod-DkvWlcln.js"; import { au as _, av as O, af as P, U as z, aw as v, ax as D, ay as b, d as m, az as F, Y as C, n as I, aA as L, T as j, c as S, a as y, aB as q, _ as H, aC as G, H as K, k as Q, aD as V, aE as X, h as Z } from "./Lexical.prod-CWyHQUEM.js"; import { L as ee } from "./LexicalUtils.prod-Dny9Fu94.js"; function ne(n, e) { const o = e.body ? e.body.childNodes : []; let s = []; const l = []; for (let c = 0; c < o.length; c++) { const r = o[c]; if (!$.has(r.nodeName)) { const t = U(r, n, l, !1); t !== null && (s = s.concat(t)); } } return function(c) { for (const r of c) r.getNextSibling() instanceof _ && r.insertAfter(O()); for (const r of c) { const t = r.getChildren(); for (const a of t) r.insertBefore(a); r.remove(); } }(l), s; } function te(n, e) { if (typeof document > "u" || typeof window > "u" && global.window === void 0) throw new Error("To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function."); const o = document.createElement("div"), s = P().getChildren(); for (let l = 0; l < s.length; l++) J(n, s[l], o, e); return o.innerHTML; } function J(n, e, o, s = null) { let l = s === null || e.isSelected(s); const c = m(e) && e.excludeFromCopy("html"); let r = e; if (s !== null) { let p = F(e); p = C(p) && s !== null ? E(s, p) : p, r = p; } const t = m(r) ? r.getChildren() : [], a = n._nodes.get(r.getType()); let i; i = a && a.exportDOM !== void 0 ? a.exportDOM(n, r) : r.exportDOM(n); const { element: u, after: h } = i; if (!u) return !1; const d = document.createDocumentFragment(); for (let p = 0; p < t.length; p++) { const f = t[p], w = J(n, f, d, s); !l && m(e) && w && e.extractWithChild(f, s, "html") && (l = !0); } if (l && !c) { if ((I(u) || L(u)) && u.append(d), o.append(u), h) { const p = h.call(r, u); p && (L(u) ? u.replaceChildren(p) : u.replaceWith(p)); } } else o.append(d); return l; } const $ = /* @__PURE__ */ new Set(["STYLE", "SCRIPT"]); function U(n, e, o, s, l = /* @__PURE__ */ new Map(), c) { let r = []; if ($.has(n.nodeName)) return r; let t = null; const a = function(f, w) { const { nodeName: B } = f, A = w._htmlConversions.get(B.toLowerCase()); let x = null; if (A !== void 0) for (const W of A) { const N = W(f); N !== null && (x === null || (x.priority || 0) <= (N.priority || 0)) && (x = N); } return x !== null ? x.conversion : null; }(n, e), i = a ? a(n) : null; let u = null; if (i !== null) { u = i.after; const f = i.node; if (t = Array.isArray(f) ? f[f.length - 1] : f, t !== null) { for (const [, w] of l) if (t = w(t, c), !t) break; t && r.push(...Array.isArray(f) ? f : [t]); } i.forChild != null && l.set(n.nodeName, i.forChild); } const h = n.childNodes; let d = []; const p = (t == null || !z(t)) && (t != null && v(t) || s); for (let f = 0; f < h.length; f++) d.push(...U(h[f], e, o, p, new Map(l), t)); return u != null && (d = u(d)), D(n) && (d = oe(n, d, p ? () => { const f = new _(); return o.push(f), f; } : j)), t == null ? d.length > 0 ? r = r.concat(d) : D(n) && function(f) { return f.nextSibling == null || f.previousSibling == null ? !1 : b(f.nextSibling) && b(f.previousSibling); }(n) && (r = r.concat(O())) : m(t) && t.append(...d), r; } function oe(n, e, o) { const s = n.style.textAlign, l = []; let c = []; for (let r = 0; r < e.length; r++) { const t = e[r]; if (v(t)) s && !t.getFormat() && t.setFormat(s), l.push(t); else if (c.push(t), r === e.length - 1 || r < e.length - 1 && v(e[r + 1])) { const a = o(); a.setFormat(s), a.append(...c), l.push(a), c = []; } } return l; } function T(n, ...e) { const o = new URL("https://lexical.dev/docs/error"), s = new URLSearchParams(); s.append("code", n); for (const l of e) s.append("v", l); throw o.search = s.toString(), Error(`Minified Lexical error #${n}; visit ${o.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`); } function re(n, e = y()) { return e == null && T(166), S(e) && e.isCollapsed() || e.getNodes().length === 0 ? "" : te(n, e); } function le(n, e = y()) { return e == null && T(166), S(e) && e.isCollapsed() || e.getNodes().length === 0 ? null : JSON.stringify(se(n, e)); } function he(n, e, o) { const s = n.getData("application/x-lexical-editor"); if (s) try { const t = JSON.parse(s); if (t.namespace === o._config.namespace && Array.isArray(t.nodes)) return R(o, ie(t.nodes), e); } catch { } const l = n.getData("text/html"), c = n.getData("text/plain"); if (l && c !== l) try { const t = new DOMParser().parseFromString(function(a) { return window.trustedTypes && window.trustedTypes.createPolicy ? window.trustedTypes.createPolicy("lexical", { createHTML: (i) => i }).createHTML(a) : a; }(l), "text/html"); return R(o, ne(o, t), e); } catch { } const r = c || n.getData("text/uri-list"); if (r != null) if (S(e)) { const t = r.split(/(\r?\n|\t)/); t[t.length - 1] === "" && t.pop(); for (let a = 0; a < t.length; a++) { const i = y(); if (S(i)) { const u = t[a]; u === ` ` || u === `\r ` ? i.insertParagraph() : u === " " ? i.insertNodes([q()]) : i.insertText(u); } } } else e.insertRawText(r); } function R(n, e, o) { n.dispatchCommand(Q, { nodes: e, selection: o }) || o.insertNodes(e); } function Y(n, e, o, s = []) { let l = e === null || o.isSelected(e); const c = m(o) && o.excludeFromCopy("html"); let r = o; if (e !== null) { let i = F(o); i = C(i) && e !== null ? E(e, i) : i, r = i; } const t = m(r) ? r.getChildren() : [], a = function(i) { const u = i.exportJSON(), h = i.constructor; if (u.type !== h.getType() && T(58, h.name), m(i)) { const d = u.children; Array.isArray(d) || T(59, h.name); } return u; }(r); if (C(r)) { const i = r.__text; i.length > 0 ? a.text = i : l = !1; } for (let i = 0; i < t.length; i++) { const u = t[i], h = Y(n, e, u, a.children); !l && m(o) && h && o.extractWithChild(u, e, "clone") && (l = !0); } if (l && !c) s.push(a); else if (Array.isArray(a.children)) for (let i = 0; i < a.children.length; i++) { const u = a.children[i]; s.push(u); } return l; } function se(n, e) { const o = [], s = P().getChildren(); for (let l = 0; l < s.length; l++) Y(n, e, s[l], o); return { namespace: n._config.namespace, nodes: o }; } function ie(n) { const e = []; for (let o = 0; o < n.length; o++) { const s = n[o], l = V(s); C(l) && k(l), e.push(l); } return e; } let g = null; async function me(n, e, o) { if (g !== null) return !1; if (e !== null) return new Promise((i, u) => { n.update(() => { i(M(n, e, o)); }); }); const s = n.getRootElement(), l = n._window || window, c = window.document, r = H(l); if (s === null || r === null) return !1; const t = c.createElement("span"); t.style.cssText = "position: fixed; top: -1000px;", t.append(c.createTextNode("#")), s.append(t); const a = new Range(); return a.setStart(t, 0), a.setEnd(t, 1), r.removeAllRanges(), r.addRange(a), new Promise((i, u) => { const h = n.registerCommand(G, (d) => (ee(d, ClipboardEvent) && (h(), g !== null && (window.clearTimeout(g), g = null), i(M(n, d, o))), !0), K); g = window.setTimeout(() => { h(), g = null, i(!1); }, 50), c.execCommand("copy"), t.remove(); }); } function M(n, e, o) { if (o === void 0) { const l = H(n._window); if (!l) return !1; const c = l.anchorNode, r = l.focusNode; if (c !== null && r !== null && !X(n, c, r)) return !1; const t = y(); if (t === null) return !1; o = ce(t); } e.preventDefault(); const s = e.clipboardData; return s !== null && (ue(s, o), !0); } const ae = [["text/html", re], ["application/x-lexical-editor", le]]; function ce(n = y()) { const e = { "text/plain": n ? n.getTextContent() : "" }; if (n) { const o = Z(); for (const [s, l] of ae) { const c = l(o, n); c !== null && (e[s] = c); } } return e; } function ue(n, e) { for (const o in e) { const s = e[o]; s !== void 0 && n.setData(o, s); } } export { he as D, ce as M, me as _, ne as h, te as m }; //# sourceMappingURL=LexicalClipboard.prod-DbqSWANZ.js.map