@uva-glass/component-library
Version:
React components UvA
813 lines (812 loc) • 32.8 kB
JavaScript
import { jsx as h, jsxs as F, Fragment as Pe } from "react/jsx-runtime";
import { t as Je, r as Ve, o as T } from "../../LexicalComposerContext.prod-DLlRM5wP.js";
import { aF as Te, ae as z, w as Re, a as p, al as W, h as q, N as Xe, Y as M, c as g, T as Ye, E as m, aG as Ge, ad as Ie, o as Qe, j as Me, aH as Ze, K as et, aE as P, aB as tt, aI as nt, aJ as rt, aK as ot, s as ne, aL as it, aM as st, a0 as at, C as lt, u as ut, y as ct, aN as dt, aO as fe, b as me, I as ft, F as re, G as mt, a1 as Oe, aP as pe, x as pt, v as gt, p as ht, aQ as ge, q as Ct, aR as yt, aS as Et, aT as wt, aA as vt, R as bt, O as St, aU as _t, S as kt, D as xt, z as Nt, g as Lt, P as he, aV as Dt, n as $t, aq as Y, ap as G, aW as Pt, aX as Tt, as as Rt, ar as It } from "../../Lexical.prod-CniF7zEE.js";
import * as oe from "react";
import { useMemo as J, useLayoutEffect as j, useEffect as k, useState as O, useRef as Ke, Suspense as Mt, forwardRef as Fe, useCallback as Ot } from "react";
import { j as U, L as A, y as Kt, w as de } from "../../LexicalUtils.prod-DVr8VsHc.js";
import { flushSync as Ft, createPortal as At } from "react-dom";
import { D as Ce, _ as ye, h as zt, m as Bt } from "../../LexicalClipboard.prod-BXVNkwwS.js";
import { W as Ee, G as we } from "../../LexicalSelection.prod-BfAlhGGm.js";
import { j as Ae, K as ze, i as jt } from "../../LexicalList.prod-BUcoZhe4.js";
import { h as Be, O as ve, N as ie, d as Ut, p as Ht } from "../../LexicalLink.prod-Du8ZoNsh.js";
import { Q as Wt, d as qt, h as Jt, u as Vt, y as je, O as Xt, Z as Yt } from "../../LexicalTable.prod-CYafu_j9.js";
import { a as Gt, w as Qt, M as Zt } from "../../helpers-ChM6xtQG.js";
import { c as en } from "../../clsx-OuTLNxxd.js";
import { exportMap as tn, isStartingWithHtmlTag as nn, mergeBoldStrongTags as rn } from "./helpers.js";
import { s as I } from "../../RteEditor.module-oFMKEW6f.js";
import { ToolBarPlugin as on } from "./Plugins/ToolbarPlugin/ToolbarPlugin.js";
import { useTranslation as sn } from "./hooks/useTranslation.js";
import "../../TablePlugin-MjKuocl4.js";
import "./Plugins/LinkPlugin/LinkContextMenu/LinkContextMenu.js";
import "./hooks/components/Flyout.js";
import "../Buttons/Button.js";
import "../Buttons/LinkButton.js";
import "@react-aria/button";
import "../Checkbox/Checkbox.js";
import "@react-aria/dialog";
import "@react-aria/focus";
import "@react-aria/overlays";
import "../OverlayCloseButton/OverlayCloseButton.js";
import { FeedbackBox as an } from "../FeedbackBox/FeedbackBox.js";
import "../GridRow/GridRow.js";
import "../IconButton/IconButton.js";
import "../Input/Input.js";
import "../InputField/InputField.js";
import "react-router";
import "../SelectListbox/SelectListbox.js";
import "../SelectListbox/SelectProvider.js";
import "../Sortable/components/SortableItem.js";
import "../../SortableProvider-Ck_XnBVq.js";
import { UvaTheme as ln } from "./UvaTheme/UvaTheme.js";
import { EditorHeader as un } from "./EditorHeader/EditorHeader.js";
import { LanguageProvider as cn, useLanguage as dn } from "./Providers/LanguageProvider.js";
import { PasteHandlerPlugin as fn } from "./Plugins/PasteHandlerPlugin/PasteHandlerPlugin.js";
const Ue = typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0, mn = Ue ? j : k, Q = { tag: "history-merge" };
function pn({ initialConfig: n, children: e }) {
const t = J(() => {
const { theme: o, namespace: i, nodes: r, onError: s, editorState: a, html: l } = n, u = Je(null, o), c = Te({ editable: n.editable, html: l, namespace: i, nodes: r, onError: (d) => s(d, c), theme: o });
return function(d, f) {
if (f !== null) {
if (f === void 0) d.update(() => {
const C = z();
if (C.isEmpty()) {
const y = Re();
C.append(y);
const v = Ue ? document.activeElement : null;
(p() !== null || v !== null && v === d.getRootElement()) && y.select();
}
}, Q);
else if (f !== null) switch (typeof f) {
case "string": {
const C = d.parseEditorState(f);
d.setEditorState(C, Q);
break;
}
case "object":
d.setEditorState(f, Q);
break;
case "function":
d.update(() => {
z().isEmpty() && f(d);
}, Q);
}
}
}(c, a), [c, u];
}, []);
return mn(() => {
const o = n.editable, [i] = t;
i.setEditable(o === void 0 || o);
}, []), h(Ve.Provider, { value: t, children: e });
}
const gn = typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0 ? j : k;
function hn(n) {
return { initialValueFn: () => n.isEditable(), subscribe: (e) => n.registerEditableListener(e) };
}
function Cn() {
return function(n) {
const [e] = T(), t = J(() => n(e), [e, n]), [o, i] = O(() => t.initialValueFn()), r = Ke(o);
return gn(() => {
const { initialValueFn: s, subscribe: a } = t, l = s();
return r.current !== l && (r.current = l, i(l)), a((u) => {
r.current = u, i(u);
});
}, [t, n]), o;
}(hn);
}
function yn() {
return z().getTextContent();
}
function En(n, e = !0) {
if (n) return !1;
let t = yn();
return e && (t = t.trim()), t === "";
}
function wn(n) {
if (!En(n, !1)) return !1;
const e = z().getChildren(), t = e.length;
if (t > 1) return !1;
for (let o = 0; o < t; o++) {
const i = e[o];
if (W(i)) return !1;
if (q(i)) {
if (!Xe(i) || i.__indent !== 0) return !1;
const r = i.getChildren(), s = r.length;
for (let a = 0; a < s; a++) {
const l = r[o];
if (!M(l)) return !1;
}
}
}
return !0;
}
function He(n) {
return () => wn(n);
}
function vn(n) {
const e = window.location.origin, t = (o) => {
if (o.origin !== e) return;
const i = n.getRootElement();
if (document.activeElement !== i) return;
const r = o.data;
if (typeof r == "string") {
let s;
try {
s = JSON.parse(r);
} catch {
return;
}
if (s && s.protocol === "nuanria_messaging" && s.type === "request") {
const a = s.payload;
if (a && a.functionId === "makeChanges") {
const l = a.args;
if (l) {
const [u, c, d, f, C, y] = l;
n.update(() => {
const v = p();
if (g(v)) {
const x = v.anchor;
let E = x.getNode(), w = 0, S = 0;
if (M(E) && u >= 0 && c >= 0 && (w = u, S = u + c, v.setTextNodeRange(E, w, E, S)), w === S && d === "" || (v.insertRawText(d), E = x.getNode()), M(E)) {
w = f, S = f + C;
const N = E.getTextContentSize();
w = w > N ? N : w, S = S > N ? N : S, v.setTextNodeRange(E, w, E, S);
}
o.stopImmediatePropagation();
}
});
}
}
}
}
};
return window.addEventListener("message", t, !0), () => {
window.removeEventListener("message", t, !0);
};
}
function be(n, e) {
if (document.caretRangeFromPoint !== void 0) {
const t = document.caretRangeFromPoint(n, e);
return t === null ? null : { node: t.startContainer, offset: t.startOffset };
}
if (document.caretPositionFromPoint !== "undefined") {
const t = document.caretPositionFromPoint(n, e);
return t === null ? null : { node: t.offsetNode, offset: t.offset };
}
return null;
}
const H = typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0, bn = H && "documentMode" in document ? document.documentMode : null, Sn = !(!H || !("InputEvent" in window) || bn) && "getTargetRanges" in new window.InputEvent("input"), _n = H && /Version\/[\d.]+.*Safari/.test(navigator.userAgent), Se = H && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream, kn = H && /^(?=.*Chrome).*/i.test(navigator.userAgent), xn = H && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !kn, _e = Qe();
function Z(n) {
let e = null;
if (A(n, DragEvent) ? e = n.dataTransfer : A(n, ClipboardEvent) && (e = n.clipboardData), e === null) return [!1, [], !1];
const t = e.types, o = t.includes("Files"), i = t.includes("text/html") || t.includes("text/plain");
return [o, Array.from(e.files), i];
}
function ke(n) {
const e = p();
if (!g(e)) return !1;
const t = /* @__PURE__ */ new Set(), o = e.getNodes();
for (let i = 0; i < o.length; i++) {
const r = o[i], s = r.getKey();
if (t.has(s)) continue;
const a = de(r, (u) => q(u) && !u.isInline());
if (a === null) continue;
const l = a.getKey();
a.canIndent() && !t.has(l) && (t.add(l), n(a));
}
return t.size > 0;
}
function ee(n) {
const e = ne(n);
return W(e);
}
function se(n) {
for (const e of ["lowercase", "uppercase", "capitalize"]) n.hasFormat(e) && n.toggleFormat(e);
}
function Nn(n) {
return U(n.registerCommand(Lt, (e) => {
const t = p();
return !!P(t) && (t.clear(), !0);
}, 0), n.registerCommand(re, (e) => {
const t = p();
return g(t) ? (t.deleteCharacter(e), !0) : !!P(t) && (t.deleteNodes(), !0);
}, m), n.registerCommand(Nt, (e) => {
const t = p();
return !!g(t) && (t.deleteWord(e), !0);
}, m), n.registerCommand(xt, (e) => {
const t = p();
return !!g(t) && (t.deleteLine(e), !0);
}, m), n.registerCommand(kt, (e) => {
const t = p();
if (typeof e == "string") t !== null && t.insertText(e);
else {
if (t === null) return !1;
const o = e.dataTransfer;
if (o != null) Ce(o, t, n);
else if (g(t)) {
const i = e.data;
return i && t.insertText(i), !0;
}
}
return !0;
}, m), n.registerCommand(_t, () => {
const e = p();
return !!g(e) && (e.removeText(), !0);
}, m), n.registerCommand(St, (e) => {
const t = p();
return !!g(t) && (t.formatText(e), !0);
}, m), n.registerCommand(bt, (e) => {
const t = p();
if (!g(t) && !P(t)) return !1;
const o = t.getNodes();
for (const i of o) {
const r = de(i, (s) => q(s) && !s.isInline());
r !== null && r.setFormat(e);
}
return !0;
}, m), n.registerCommand(fe, (e) => {
const t = p();
return !!g(t) && (t.insertLineBreak(e), !0);
}, m), n.registerCommand(me, () => {
const e = p();
return !!g(e) && (e.insertParagraph(), !0);
}, m), n.registerCommand(Et, () => (wt([vt()]), !0), m), n.registerCommand(yt, () => ke((e) => {
const t = e.getIndent();
e.setIndent(t + 1);
}), m), n.registerCommand(pe, () => ke((e) => {
const t = e.getIndent();
t > 0 && e.setIndent(t - 1);
}), m), n.registerCommand(Ct, (e) => {
const t = p();
if (P(t) && !ee(e.target)) {
const o = t.getNodes();
if (o.length > 0) return o[0].selectPrevious(), !0;
} else if (g(t)) {
const o = ge(t.focus, !0);
if (!e.shiftKey && W(o) && !o.isIsolated() && !o.isInline()) return o.selectPrevious(), e.preventDefault(), !0;
}
return !1;
}, m), n.registerCommand(ht, (e) => {
const t = p();
if (P(t)) {
const o = t.getNodes();
if (o.length > 0) return o[0].selectNext(0, 0), !0;
} else if (g(t)) {
if (function(i) {
const r = i.focus;
return r.key === "root" && r.offset === z().getChildrenSize();
}(t)) return e.preventDefault(), !0;
const o = ge(t.focus, !1);
if (!e.shiftKey && W(o) && !o.isIsolated() && !o.isInline()) return o.selectNext(), e.preventDefault(), !0;
}
return !1;
}, m), n.registerCommand(gt, (e) => {
const t = p();
if (P(t)) {
const o = t.getNodes();
if (o.length > 0) return e.preventDefault(), o[0].selectPrevious(), !0;
}
if (!g(t)) return !1;
if (Ee(t, !0)) {
const o = e.shiftKey;
return e.preventDefault(), we(t, o, !0), !0;
}
return !1;
}, m), n.registerCommand(pt, (e) => {
const t = p();
if (P(t) && !ee(e.target)) {
const i = t.getNodes();
if (i.length > 0) return e.preventDefault(), i[0].selectNext(0, 0), !0;
}
if (!g(t)) return !1;
const o = e.shiftKey;
return !!Ee(t, !1) && (e.preventDefault(), we(t, o, !1), !0);
}, m), n.registerCommand(mt, (e) => {
if (ee(e.target)) return !1;
const t = p();
if (g(t)) {
const { anchor: o } = t, i = o.getNode();
if (t.isCollapsed() && o.offset === 0 && !Oe(i) && Kt(i).getIndent() > 0)
return e.preventDefault(), n.dispatchCommand(pe, void 0);
if (Se && navigator.language === "ko-KR") return !1;
} else if (!P(t)) return !1;
return e.preventDefault(), n.dispatchCommand(re, !0);
}, m), n.registerCommand(ft, (e) => {
if (ee(e.target)) return !1;
const t = p();
return !(!g(t) && !P(t)) && (e.preventDefault(), n.dispatchCommand(re, !1));
}, m), n.registerCommand(dt, (e) => {
const t = p();
if (!g(t)) return !1;
if (se(t), e !== null) {
if ((Se || _n || xn) && Sn) return !1;
if (e.preventDefault(), e.shiftKey) return n.dispatchCommand(fe, !1);
}
return n.dispatchCommand(me, void 0);
}, m), n.registerCommand(ct, () => {
const e = p();
return !!g(e) && (n.blur(), !0);
}, m), n.registerCommand(st, (e) => {
const [, t] = Z(e);
if (t.length > 0) {
const i = be(e.clientX, e.clientY);
if (i !== null) {
const { offset: r, node: s } = i, a = ne(s);
if (a !== null) {
const l = at();
if (M(a)) l.anchor.set(a.getKey(), r, "text"), l.focus.set(a.getKey(), r, "text");
else {
const c = a.getParentOrThrow().getKey(), d = a.getIndexWithinParent() + 1;
l.anchor.set(c, d, "element"), l.focus.set(c, d, "element");
}
const u = lt(l);
ut(u);
}
n.dispatchCommand(_e, t);
}
return e.preventDefault(), !0;
}
const o = p();
return !!g(o);
}, m), n.registerCommand(it, (e) => {
const [t] = Z(e), o = p();
return !(t && !g(o));
}, m), n.registerCommand(ot, (e) => {
const [t] = Z(e), o = p();
if (t && !g(o)) return !1;
const i = be(e.clientX, e.clientY);
if (i !== null) {
const r = ne(i.node);
W(r) && e.preventDefault();
}
return !0;
}, m), n.registerCommand(nt, () => (rt(), !0), m), n.registerCommand(tt, (e) => (ye(n, A(e, ClipboardEvent) ? e : null), !0), m), n.registerCommand(et, (e) => (async function(t, o) {
await ye(o, A(t, ClipboardEvent) ? t : null), o.update(() => {
const i = p();
g(i) ? i.removeText() : P(i) && i.getNodes().forEach((r) => r.remove());
});
}(e, n), !0), m), n.registerCommand(Ie, (e) => {
const [, t, o] = Z(e);
return t.length > 0 && !o ? (n.dispatchCommand(_e, t), !0) : Me(e.target) && Ze(e.target) ? !1 : p() !== null && (function(i, r) {
i.preventDefault(), r.update(() => {
const s = p(), a = A(i, InputEvent) || A(i, KeyboardEvent) ? null : i.clipboardData;
a != null && s !== null && Ce(a, s, r);
}, { tag: "paste" });
}(e, n), !0);
}, m), n.registerCommand(Ge, (e) => {
const t = p();
return g(t) && se(t), !1;
}, m), n.registerCommand(Ye, (e) => {
const t = p();
return g(t) && se(t), !1;
}, m));
}
const ae = typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0 ? j : k;
function xe(n) {
return n.getEditorState().read(He(n.isComposing()));
}
function Ln({ contentEditable: n, placeholder: e = null, ErrorBoundary: t }) {
const [o] = T(), i = function(r, s) {
const [a, l] = O(() => r.getDecorators());
return ae(() => r.registerDecoratorListener((u) => {
Ft(() => {
l(u);
});
}), [r]), k(() => {
l(r.getDecorators());
}, [r]), J(() => {
const u = [], c = Object.keys(a);
for (let d = 0; d < c.length; d++) {
const f = c[d], C = h(s, { onError: (v) => r._onError(v), children: h(Mt, { fallback: null, children: a[f] }) }), y = r.getElementByKey(f);
y !== null && u.push(At(C, y, f));
}
return u;
}, [s, a, r]);
}(o, t);
return function(r) {
ae(() => U(Nn(r), vn(r)), [r]);
}(o), F(Pe, { children: [n, h(Dn, { content: e }), i] });
}
function Dn({ content: n }) {
const [e] = T(), t = function(i) {
const [r, s] = O(() => xe(i));
return ae(() => {
function a() {
const l = xe(i);
s(l);
}
return a(), U(i.registerUpdateListener(() => {
a();
}), i.registerEditableListener(() => {
a();
}));
}, [i]), r;
}(e), o = Cn();
return t ? typeof n == "function" ? n(o) : n : null;
}
const We = typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0 ? j : k;
function $n({ editor: n, ariaActiveDescendant: e, ariaAutoComplete: t, ariaControls: o, ariaDescribedBy: i, ariaErrorMessage: r, ariaExpanded: s, ariaInvalid: a, ariaLabel: l, ariaLabelledBy: u, ariaMultiline: c, ariaOwns: d, ariaRequired: f, autoCapitalize: C, className: y, id: v, role: x = "textbox", spellCheck: E = !0, style: w, tabIndex: S, "data-testid": N, ...b }, L) {
const [_, R] = O(n.isEditable()), K = Ot((D) => {
D && D.ownerDocument && D.ownerDocument.defaultView ? n.setRootElement(D) : n.setRootElement(null);
}, [n]), B = J(() => /* @__PURE__ */ function(...D) {
return (V) => {
D.forEach((X) => {
typeof X == "function" ? X(V) : X != null && (X.current = V);
});
};
}(L, K), [K, L]);
return We(() => (R(n.isEditable()), n.registerEditableListener((D) => {
R(D);
})), [n]), h("div", { "aria-activedescendant": _ ? e : void 0, "aria-autocomplete": _ ? t : "none", "aria-controls": _ ? o : void 0, "aria-describedby": i, ...r != null ? { "aria-errormessage": r } : {}, "aria-expanded": _ && x === "combobox" ? !!s : void 0, ...a != null ? { "aria-invalid": a } : {}, "aria-label": l, "aria-labelledby": u, "aria-multiline": c, "aria-owns": _ ? d : void 0, "aria-readonly": !_ || void 0, "aria-required": f, autoCapitalize: C, className: y, contentEditable: _, "data-testid": N, id: v, ref: B, role: _ ? x : void 0, spellCheck: E, style: w, tabIndex: S, ...b });
}
const Pn = Fe($n);
function Ne(n) {
return n.getEditorState().read(He(n.isComposing()));
}
const Tn = Fe(Rn);
function Rn(n, e) {
const { placeholder: t, ...o } = n, [i] = T();
return F(Pe, { children: [h(Pn, { editor: i, ...o, ref: e }), t != null && h(In, { editor: i, content: t })] });
}
function In({ content: n, editor: e }) {
const t = function(s) {
const [a, l] = O(() => Ne(s));
return We(() => {
function u() {
const c = Ne(s);
l(c);
}
return u(), U(s.registerUpdateListener(() => {
u();
}), s.registerEditableListener(() => {
u();
}));
}, [s]), a;
}(e), [o, i] = O(e.isEditable());
if (j(() => (i(e.isEditable()), e.registerEditableListener((s) => {
i(s);
})), [e]), !t) return null;
let r = null;
return typeof n == "function" ? r = n(o) : n !== null && (r = n), r === null ? null : h("div", { "aria-hidden": !0, children: r });
}
function le(n, e) {
return le = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(t, o) {
return t.__proto__ = o, t;
}, le(n, e);
}
var Le = { error: null }, Mn = function(n) {
var e, t;
function o() {
for (var r, s = arguments.length, a = new Array(s), l = 0; l < s; l++) a[l] = arguments[l];
return (r = n.call.apply(n, [this].concat(a)) || this).state = Le, r.resetErrorBoundary = function() {
for (var u, c = arguments.length, d = new Array(c), f = 0; f < c; f++) d[f] = arguments[f];
r.props.onReset == null || (u = r.props).onReset.apply(u, d), r.reset();
}, r;
}
t = n, (e = o).prototype = Object.create(t.prototype), e.prototype.constructor = e, le(e, t), o.getDerivedStateFromError = function(r) {
return { error: r };
};
var i = o.prototype;
return i.reset = function() {
this.setState(Le);
}, i.componentDidCatch = function(r, s) {
var a, l;
(a = (l = this.props).onError) == null || a.call(l, r, s);
}, i.componentDidUpdate = function(r, s) {
var a, l, u, c, d = this.state.error, f = this.props.resetKeys;
d !== null && s.error !== null && ((u = r.resetKeys) === void 0 && (u = []), (c = f) === void 0 && (c = []), u.length !== c.length || u.some(function(C, y) {
return !Object.is(C, c[y]);
})) && ((a = (l = this.props).onResetKeysChange) == null || a.call(l, r.resetKeys, f), this.reset());
}, i.render = function() {
var r = this.state.error, s = this.props, a = s.fallbackRender, l = s.FallbackComponent, u = s.fallback;
if (r !== null) {
var c = { error: r, resetErrorBoundary: this.resetErrorBoundary };
if (oe.isValidElement(u)) return u;
if (typeof a == "function") return a(c);
if (l) return oe.createElement(l, c);
throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop");
}
return this.props.children;
}, o;
}(oe.Component);
function On({ children: n, onError: e }) {
return h(Mn, { fallback: h("div", { style: { border: "1px solid #f00", color: "#f00", padding: "8px" }, children: "An error was thrown." }), onError: e, children: n });
}
const Kn = typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0 ? j : k;
function Fn({ ignoreHistoryMergeTagChange: n = !0, ignoreSelectionChange: e = !1, onChange: t }) {
const [o] = T();
return Kn(() => {
if (t) return o.registerUpdateListener(({ editorState: i, dirtyElements: r, dirtyLeaves: s, prevEditorState: a, tags: l }) => {
e && r.size === 0 && s.size === 0 || n && l.has("history-merge") || a.isEmpty() || t(i, o, l);
});
}, [o, n, e, t]), null;
}
function An() {
const [n] = T();
return k(() => {
if (!n.hasNodes([Ae, ze])) throw new Error("ListPlugin: ListNode and/or ListItemNode not registered on editor");
}, [n]), function(e) {
k(() => jt(e), [e]);
}(n), null;
}
function zn({ validateUrl: n, attributes: e }) {
const [t] = T();
return k(() => {
if (!t.hasNodes([Be])) throw new Error("LinkPlugin: LinkNode not registered on editor");
return U(t.registerCommand(ve, (o) => {
if (o === null) return ie(o), !0;
if (typeof o == "string") return !(n !== void 0 && !n(o)) && (ie(o, e), !0);
{
const { url: i, target: r, rel: s, title: a } = o;
return ie(i, { ...e, rel: s, target: r, title: a }), !0;
}
}, he), n !== void 0 ? t.registerCommand(Ie, (o) => {
const i = p();
if (!g(i) || i.isCollapsed() || !A(o, ClipboardEvent) || o.clipboardData === null) return !1;
const r = o.clipboardData.getData("text");
return !!n(r) && !i.getNodes().some((s) => q(s)) && (t.dispatchCommand(ve, { ...e, url: r }), o.preventDefault(), !0);
}, he) : () => {
});
}, [t, n, e]), null;
}
function Bn({ newTab: n = !0, disabled: e = !1 }) {
const [t] = T();
return k(() => {
const o = (r) => {
const s = r.target;
if (!Me(s)) return;
const a = Dt(s);
if (a === null) return;
let l = null, u = null;
if (a.update(() => {
const f = ne(s);
if (f !== null) {
const C = de(f, q);
if (!e) if (Ut(C)) l = C.sanitizeUrl(C.getURL()), u = C.getTarget();
else {
const y = function(v, x) {
let E = v;
for (; E != null; ) {
if (x(E)) return E;
E = E.parentNode;
}
return null;
}(s, $t);
y !== null && (l = y.href, u = y.target);
}
}
}), l === null || l === "") return;
const c = t.getEditorState().read(p);
if (g(c) && !c.isCollapsed()) return void r.preventDefault();
const d = r.type === "auxclick" && r.button === 1;
window.open(l, n || d || r.metaKey || r.ctrlKey || u === "_blank" ? "_blank" : "_self"), r.preventDefault();
}, i = (r) => {
r.button === 1 && o(r);
};
return t.registerRootListener((r, s) => {
s !== null && (s.removeEventListener("click", o), s.removeEventListener("mouseup", i)), r !== null && (r.addEventListener("click", o), r.addEventListener("mouseup", i));
});
}, [t, n, e]), null;
}
const te = 0, ue = 1, ce = 2, $ = 0, jn = 1, De = 2, Un = 3, Hn = 4;
function Wn(n, e, t, o, i) {
if (n === null || t.size === 0 && o.size === 0 && !i) return $;
const r = e._selection, s = n._selection;
if (i) return jn;
if (!(g(r) && g(s) && s.isCollapsed() && r.isCollapsed())) return $;
const a = function(E, w, S) {
const N = E._nodeMap, b = [];
for (const L of w) {
const _ = N.get(L);
_ !== void 0 && b.push(_);
}
for (const [L, _] of S) {
if (!_) continue;
const R = N.get(L);
R === void 0 || Oe(R) || b.push(R);
}
return b;
}(e, t, o);
if (a.length === 0) return $;
if (a.length > 1) {
const E = e._nodeMap, w = E.get(r.anchor.key), S = E.get(s.anchor.key);
return w && S && !n._nodeMap.has(w.__key) && M(w) && w.__text.length === 1 && r.anchor.offset === 1 ? De : $;
}
const l = a[0], u = n._nodeMap.get(l.__key);
if (!M(u) || !M(l) || u.__mode !== l.__mode) return $;
const c = u.__text, d = l.__text;
if (c === d) return $;
const f = r.anchor, C = s.anchor;
if (f.key !== C.key || f.type !== "text") return $;
const y = f.offset, v = C.offset, x = d.length - c.length;
return x === 1 && v === y - 1 ? De : x === -1 && v === y + 1 ? Un : x === -1 && v === y ? Hn : $;
}
function qn(n, e) {
let t = Date.now(), o = $;
return (i, r, s, a, l, u) => {
const c = Date.now();
if (u.has("historic")) return o = $, t = c, ce;
const d = Wn(i, r, a, l, n.isComposing()), f = (() => {
const C = s === null || s.editor === n, y = u.has("history-push");
if (!y && C && u.has("history-merge")) return te;
if (i === null) return ue;
const v = r._selection;
return a.size > 0 || l.size > 0 ? y === !1 && d !== $ && d === o && c < t + e && C || a.size === 1 && function(x, E, w) {
const S = E._nodeMap.get(x), N = w._nodeMap.get(x), b = E._selection, L = w._selection;
return !(g(b) && g(L) && b.anchor.type === "element" && b.focus.type === "element" && L.anchor.type === "text" && L.focus.type === "text" || !M(S) || !M(N) || S.__parent !== N.__parent) && JSON.stringify(E.read(() => S.exportJSON())) === JSON.stringify(w.read(() => N.exportJSON()));
}(Array.from(a)[0], i, r) ? te : ue : v !== null ? te : ce;
})();
return t = c, o = d, f;
};
}
function $e(n) {
n.undoStack = [], n.redoStack = [], n.current = null;
}
function Jn(n, e, t) {
const o = qn(n, t);
return U(n.registerCommand(It, () => (function(r, s) {
const a = s.redoStack, l = s.undoStack;
if (l.length !== 0) {
const u = s.current, c = l.pop();
u !== null && (a.push(u), r.dispatchCommand(Y, !0)), l.length === 0 && r.dispatchCommand(G, !1), s.current = c || null, c && c.editor.setEditorState(c.editorState, { tag: "historic" });
}
}(n, e), !0), m), n.registerCommand(Rt, () => (function(r, s) {
const a = s.redoStack, l = s.undoStack;
if (a.length !== 0) {
const u = s.current;
u !== null && (l.push(u), r.dispatchCommand(G, !0));
const c = a.pop();
a.length === 0 && r.dispatchCommand(Y, !1), s.current = c || null, c && c.editor.setEditorState(c.editorState, { tag: "historic" });
}
}(n, e), !0), m), n.registerCommand(Tt, () => ($e(e), !1), m), n.registerCommand(Pt, () => ($e(e), n.dispatchCommand(Y, !1), n.dispatchCommand(G, !1), !0), m), n.registerUpdateListener(({ editorState: r, prevEditorState: s, dirtyLeaves: a, dirtyElements: l, tags: u }) => {
const c = e.current, d = e.redoStack, f = e.undoStack, C = c === null ? null : c.editorState;
if (c !== null && r === C) return;
const y = o(s, r, c, a, l, u);
if (y === ue) d.length !== 0 && (e.redoStack = [], n.dispatchCommand(Y, !1)), c !== null && (f.push({ ...c }), n.dispatchCommand(G, !0));
else if (y === ce) return;
e.current = { editor: n, editorState: r };
}));
}
function Vn() {
return { current: null, redoStack: [], undoStack: [] };
}
function Xn({ delay: n, externalHistoryState: e }) {
const [t] = T();
return function(o, i, r = 1e3) {
const s = J(() => i || Vn(), [i]);
k(() => Jn(o, s, r), [r, o, s]);
}(t, e, n), null;
}
function Yn({ hasCellMerge: n = !0, hasCellBackgroundColor: e = !0, hasTabHandler: t = !0, hasHorizontalScroll: o = !1 }) {
const [i] = T();
return k(() => {
Wt(i, o);
}, [i, o]), k(() => qt(i), [i]), k(() => Jt(i, t), [i, t]), k(() => {
if (!n) return Vt(i);
}, [i, n]), k(() => {
if (!e) return i.registerNodeTransform(je, (r) => {
r.getBackgroundColor() !== null && r.setBackgroundColor(null);
});
}, [i, e, n]), null;
}
const qe = 200, Gn = ({
currentLanguage: n = "NL",
initialValue: e = "",
placeholder: t = "",
label: o = "",
info: i = "",
required: r = !1,
notValidatedText: s = "",
maxHeightInRem: a = "20rem",
maxWords: l = qe,
onChange: u
}) => {
const { switchLanguage: c } = dn(), d = sn(), [f] = O(() => Te()), [C, y] = O(0), [v, x] = O(0), E = Ke(null), w = {
html: {
export: tn
},
namespace: "UvaRte",
editor: f,
theme: ln,
onError(b) {
throw b;
},
nodes: [Ae, ze, Be, Ht, je, Xt, Yt],
editorState: (b) => {
const _ = new DOMParser().parseFromString(e, "text/html"), R = zt(b, _), K = z();
if (K.clear(), nn(e))
R.forEach((B) => {
K.append(B);
});
else {
const B = Re();
R.forEach((D, V) => {
V === 0 ? (B.append(D), K.append(B)) : K.append(D);
});
}
}
}, S = (b) => b.trim().length === 0 ? 0 : b.split(" ").length, N = (b, L) => {
b.read(() => {
let _ = "";
y(S(z().getTextContent().replace(/\s+/g, " ").trim())), _ = rn(Bt(L)), u(_);
});
};
return k(() => {
c(n.toLocaleLowerCase());
}, [n, c]), k(() => {
const b = e.replace(/<br\s*\/?>| /gi, " ").replace(/<\/?[^>]+(>|$)|&[a-z]+;/g, "").replace(/\s+/g, " ").trim();
y(S(b));
}, []), /* @__PURE__ */ F("div", { className: I.editor__container, children: [
/* @__PURE__ */ F("div", { className: I.editor__header, children: [
/* @__PURE__ */ h(un, { label: o, info: i, required: r }),
/* @__PURE__ */ F("div", { className: I["editor__header-word-count"], children: [
/* @__PURE__ */ h("span", { className: en({ [I["editor__header-word-count--alert"]]: C > l }), children: C }),
" / ",
l
] })
] }),
/* @__PURE__ */ h("div", { className: I.editor, children: /* @__PURE__ */ F(pn, { initialConfig: w, children: [
/* @__PURE__ */ h(on, { editorScrollPosition: v }),
/* @__PURE__ */ F("div", { className: I["editor__field-wrapper"], children: [
/* @__PURE__ */ h(
Ln,
{
contentEditable: /* @__PURE__ */ h(
Tn,
{
className: I.editor__field,
"aria-label": d.common.rteAriaLabel,
"aria-placeholder": t,
title: d.common.rteTitle,
placeholder: /* @__PURE__ */ h("div", { className: I.editor__placeholder, children: t }),
spellCheck: !1,
id: "rteEditor",
style: { height: `${a}`, maxHeight: `${a}` },
onScroll: (b) => x(b.currentTarget.scrollTop),
ref: E
}
),
placeholder: /* @__PURE__ */ h("div", { className: I.editor__placeholder, children: t }),
ErrorBoundary: On
}
),
/* @__PURE__ */ h(Yn, {}),
/* @__PURE__ */ h(Xn, {}),
/* @__PURE__ */ h(An, {}),
/* @__PURE__ */ h(zn, { validateUrl: Gt }),
/* @__PURE__ */ h(Qt, { matchers: Zt }),
/* @__PURE__ */ h(Bn, {}),
/* @__PURE__ */ h(Fn, { onChange: N }),
/* @__PURE__ */ h(fn, {})
] })
] }) }),
s !== "" && /* @__PURE__ */ h(an, { level: "error", feedback: s })
] });
}, zr = ({
currentLanguage: n = "NL",
initialValue: e = "",
placeholder: t = "",
label: o = "",
info: i = "",
required: r = !1,
notValidatedText: s = "",
maxWords: a = qe,
onChange: l
}) => /* @__PURE__ */ h(cn, { children: /* @__PURE__ */ h(
Gn,
{
currentLanguage: n,
initialValue: e,
placeholder: t,
label: o,
info: i,
required: r,
notValidatedText: s,
maxWords: a,
onChange: l
}
) });
export {
Gn as Rte,
zr as RteEditor
};
//# sourceMappingURL=RteEditor.js.map