@uva-glass/component-library
Version:
React components UvA
815 lines (814 loc) • 32.9 kB
JavaScript
import { jsx as h, jsxs as K, Fragment as Te } from "react/jsx-runtime";
import { t as qe, r as Ve, o as P } from "../../LexicalComposerContext.prod-DLlRM5wP.js";
import { aF as Pe, af as z, T as Re, a as p, am as W, d as J, w as Ge, Y as M, c as g, S as Xe, N as m, aG as Ye, ae as Ie, o as Qe, r as Me, aH as Ze, O as et, u as T, aC as tt, aI as nt, aJ as rt, aK as ot, i as te, aL as it, aM as st, a1 as at, C as lt, g as ut, L as ct, aN as dt, aO as de, b as fe, K as ft, D as ne, I as mt, a2 as Oe, aP as me, y as pt, x as gt, t as ht, aQ as pe, v as Ct, aR as yt, aS as Et, aT as wt, aB as vt, Q as bt, P as St, aU as _t, R as kt, B as xt, A as Nt, j as Lt, E as ge, aV as Dt, e as $t, ar as X, aq as Y, aW as Tt, aX as Pt, at as Rt, as as It } from "../../Lexical.prod-CWyHQUEM.js";
import * as re from "react";
import { useMemo as q, useLayoutEffect as U, useEffect as _, useState as O, useRef as Fe, Suspense as Mt, forwardRef as Ke, useCallback as Ot } from "react";
import { j, L as A, y as Ft, w as ce } from "../../LexicalUtils.prod-Dny9Fu94.js";
import { flushSync as Kt, createPortal as At } from "react-dom";
import { D as he, _ as Ce, h as zt, m as Bt } from "../../LexicalClipboard.prod-DbqSWANZ.js";
import { W as ye, G as Ee } from "../../LexicalSelection.prod-DkvWlcln.js";
import { r as Ae, G as ze, v as Ut, T as jt } from "../../LexicalList.prod-pZmYrwOC.js";
import { g as Be, k as we, N as oe, p as Ht, m as Wt } from "../../LexicalLink.prod-DbxnRszt.js";
import { c as Jt, b as qt, w as Vt, S as Gt, y as Ue, O as Xt, a as Yt } from "../../LexicalTable.prod-C6duSS2P.js";
import { a as Qt, w as Zt, M as en } from "../../helpers-BUwfVZhW.js";
import { c as tn } from "../../clsx-OuTLNxxd.js";
import { exportMap as nn, isStartingWithHtmlTag as rn, mergeBoldStrongTags as on } from "./helpers.js";
import { s as I } from "../../RteEditor.module-oFMKEW6f.js";
import { ToolBarPlugin as sn } from "./Plugins/ToolbarPlugin/ToolbarPlugin.js";
import { useTranslation as an } from "./hooks/useTranslation.js";
import "../../TablePlugin-Ba6PaBhf.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 ln } 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 un } from "./UvaTheme/UvaTheme.js";
import { EditorHeader as cn } from "./EditorHeader/EditorHeader.js";
import { LanguageProvider as dn, useLanguage as fn } from "./Providers/LanguageProvider.js";
import { PasteHandlerPlugin as mn } from "./Plugins/PasteHandlerPlugin/PasteHandlerPlugin.js";
const je = typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0, pn = je ? U : _, Q = { tag: "history-merge" };
function gn({ initialConfig: n, children: e }) {
const t = q(() => {
const { theme: o, namespace: i, nodes: r, onError: s, editorState: a, html: l } = n, u = qe(null, o), c = Pe({ 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 = je ? 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 pn(() => {
const o = n.editable, [i] = t;
i.setEditable(o === void 0 || o);
}, []), h(Ve.Provider, { value: t, children: e });
}
const hn = typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0 ? U : _;
function Cn(n) {
return { initialValueFn: () => n.isEditable(), subscribe: (e) => n.registerEditableListener(e) };
}
function yn() {
return function(n) {
const [e] = P(), t = q(() => n(e), [e, n]), [o, i] = O(() => t.initialValueFn()), r = Fe(o);
return hn(() => {
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;
}(Cn);
}
function En() {
return z().getTextContent();
}
function wn(n, e = !0) {
if (n) return !1;
let t = En();
return e && (t = t.trim()), t === "";
}
function vn(n) {
if (!wn(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 (J(i)) {
if (!Ge(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 () => vn(n);
}
function bn(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 ve(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, Sn = H && "documentMode" in document ? document.documentMode : null, _n = !(!H || !("InputEvent" in window) || Sn) && "getTargetRanges" in new window.InputEvent("input"), kn = H && /Version\/[\d.]+.*Safari/.test(navigator.userAgent), be = H && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream, xn = H && /^(?=.*Chrome).*/i.test(navigator.userAgent), Nn = H && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !xn, Se = 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 _e(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 = ce(r, (u) => J(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 ke(n) {
const e = te(n);
return W(e);
}
function ie(n) {
for (const e of ["lowercase", "uppercase", "capitalize"]) n.hasFormat(e) && n.toggleFormat(e);
}
function Ln(n) {
return j(n.registerCommand(Lt, (e) => {
const t = p();
return !!T(t) && (t.clear(), !0);
}, 0), n.registerCommand(ne, (e) => {
const t = p();
return g(t) ? (t.deleteCharacter(e), !0) : !!T(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) he(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) && !T(t)) return !1;
const o = t.getNodes();
for (const i of o) {
const r = ce(i, (s) => J(s) && !s.isInline());
r !== null && r.setFormat(e);
}
return !0;
}, m), n.registerCommand(de, (e) => {
const t = p();
return !!g(t) && (t.insertLineBreak(e), !0);
}, m), n.registerCommand(fe, () => {
const e = p();
return !!g(e) && (e.insertParagraph(), !0);
}, m), n.registerCommand(Et, () => (wt([vt()]), !0), m), n.registerCommand(yt, () => _e((e) => {
const t = e.getIndent();
e.setIndent(t + 1);
}), m), n.registerCommand(me, () => _e((e) => {
const t = e.getIndent();
t > 0 && e.setIndent(Math.max(0, t - 1));
}), m), n.registerCommand(Ct, (e) => {
const t = p();
if (T(t)) {
const o = t.getNodes();
if (o.length > 0) return o[0].selectPrevious(), !0;
} else if (g(t)) {
const o = pe(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 (T(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 = pe(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 (T(t)) {
const o = t.getNodes();
if (o.length > 0) return e.preventDefault(), o[0].selectPrevious(), !0;
}
if (!g(t)) return !1;
if (ye(t, !0)) {
const o = e.shiftKey;
return e.preventDefault(), Ee(t, o, !0), !0;
}
return !1;
}, m), n.registerCommand(pt, (e) => {
const t = p();
if (T(t)) {
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 !!ye(t, !1) && (e.preventDefault(), Ee(t, o, !1), !0);
}, m), n.registerCommand(mt, (e) => {
if (ke(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) && Ft(i).getIndent() > 0)
return e.preventDefault(), n.dispatchCommand(me, void 0);
if (be && navigator.language === "ko-KR") return !1;
} else if (!T(t)) return !1;
return e.preventDefault(), n.dispatchCommand(ne, !0);
}, m), n.registerCommand(ft, (e) => {
if (ke(e.target)) return !1;
const t = p();
return !(!g(t) && !T(t)) && (e.preventDefault(), n.dispatchCommand(ne, !1));
}, m), n.registerCommand(dt, (e) => {
const t = p();
if (!g(t)) return !1;
if (ie(t), e !== null) {
if ((be || kn || Nn) && _n) return !1;
if (e.preventDefault(), e.shiftKey) return n.dispatchCommand(de, !1);
}
return n.dispatchCommand(fe, 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 = ve(e.clientX, e.clientY);
if (i !== null) {
const { offset: r, node: s } = i, a = te(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(Se, 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 = ve(e.clientX, e.clientY);
if (i !== null) {
const r = te(i.node);
W(r) && e.preventDefault();
}
return !0;
}, m), n.registerCommand(nt, () => (rt(), !0), m), n.registerCommand(tt, (e) => (Ce(n, A(e, ClipboardEvent) ? e : null), !0), m), n.registerCommand(et, (e) => (async function(t, o) {
await Ce(o, A(t, ClipboardEvent) ? t : null), o.update(() => {
const i = p();
g(i) ? i.removeText() : T(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(Se, 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 && he(a, s, r);
}, { tag: "paste" });
}(e, n), !0);
}, m), n.registerCommand(Ye, (e) => {
const t = p();
return g(t) && ie(t), !1;
}, m), n.registerCommand(Xe, (e) => {
const t = p();
return g(t) && ie(t), !1;
}, m));
}
const se = typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0 ? U : _;
function xe(n) {
return n.getEditorState().read(He(n.isComposing()));
}
function Dn({ contentEditable: n, placeholder: e = null, ErrorBoundary: t }) {
const [o] = P(), i = function(r, s) {
const [a, l] = O(() => r.getDecorators());
return se(() => r.registerDecoratorListener((u) => {
Kt(() => {
l(u);
});
}), [r]), _(() => {
l(r.getDecorators());
}, [r]), q(() => {
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) {
se(() => j(Ln(r), bn(r)), [r]);
}(o), K(Te, { children: [n, h($n, { content: e }), i] });
}
function $n({ content: n }) {
const [e] = P(), t = function(i) {
const [r, s] = O(() => xe(i));
return se(() => {
function a() {
const l = xe(i);
s(l);
}
return a(), j(i.registerUpdateListener(() => {
a();
}), i.registerEditableListener(() => {
a();
}));
}, [i]), r;
}(e), o = yn();
return t ? typeof n == "function" ? n(o) : n : null;
}
const We = typeof window < "u" && window.document !== void 0 && window.document.createElement !== void 0 ? U : _;
function Tn({ 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 [k, R] = O(n.isEditable()), F = Ot((D) => {
D && D.ownerDocument && D.ownerDocument.defaultView ? n.setRootElement(D) : n.setRootElement(null);
}, [n]), B = q(() => /* @__PURE__ */ function(...D) {
return (V) => {
D.forEach((G) => {
typeof G == "function" ? G(V) : G != null && (G.current = V);
});
};
}(L, F), [F, L]);
return We(() => (R(n.isEditable()), n.registerEditableListener((D) => {
R(D);
})), [n]), h("div", { "aria-activedescendant": k ? e : void 0, "aria-autocomplete": k ? t : "none", "aria-controls": k ? o : void 0, "aria-describedby": i, ...r != null ? { "aria-errormessage": r } : {}, "aria-expanded": k && x === "combobox" ? !!s : void 0, ...a != null ? { "aria-invalid": a } : {}, "aria-label": l, "aria-labelledby": u, "aria-multiline": c, "aria-owns": k ? d : void 0, "aria-readonly": !k || void 0, "aria-required": f, autoCapitalize: C, className: y, contentEditable: k, "data-testid": N, id: v, ref: B, role: k ? x : void 0, spellCheck: E, style: w, tabIndex: S, ...b });
}
const Pn = Ke(Tn);
function Ne(n) {
return n.getEditorState().read(He(n.isComposing()));
}
const Rn = Ke(In);
function In(n, e) {
const { placeholder: t, ...o } = n, [i] = P();
return K(Te, { children: [h(Pn, { editor: i, ...o, ref: e }), t != null && h(Mn, { editor: i, content: t })] });
}
function Mn({ 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(), j(s.registerUpdateListener(() => {
u();
}), s.registerEditableListener(() => {
u();
}));
}, [s]), a;
}(e), [o, i] = O(e.isEditable());
if (U(() => (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 ae(n, e) {
return ae = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(t, o) {
return t.__proto__ = o, t;
}, ae(n, e);
}
var Le = { error: null }, On = 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, ae(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 (re.isValidElement(u)) return u;
if (typeof a == "function") return a(c);
if (l) return re.createElement(l, c);
throw new Error("react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop");
}
return this.props.children;
}, o;
}(re.Component);
function Fn({ children: n, onError: e }) {
return h(On, { 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 ? U : _;
function An({ ignoreHistoryMergeTagChange: n = !0, ignoreSelectionChange: e = !1, onChange: t }) {
const [o] = P();
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 zn({ hasStrictIndent: n = !1 }) {
const [e] = P();
return _(() => {
if (!e.hasNodes([Ae, ze])) throw new Error("ListPlugin: ListNode and/or ListItemNode not registered on editor");
}, [e]), _(() => {
if (n) return Ut(e);
}, [e, n]), function(t) {
_(() => jt(t), [t]);
}(e), null;
}
function Bn({ validateUrl: n, attributes: e }) {
const [t] = P();
return _(() => {
if (!t.hasNodes([Be])) throw new Error("LinkPlugin: LinkNode not registered on editor");
return j(t.registerCommand(we, (o) => {
if (o === null) return oe(o), !0;
if (typeof o == "string") return !(n !== void 0 && !n(o)) && (oe(o, e), !0);
{
const { url: i, target: r, rel: s, title: a } = o;
return oe(i, { ...e, rel: s, target: r, title: a }), !0;
}
}, ge), 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) => J(s)) && (t.dispatchCommand(we, { ...e, url: r }), o.preventDefault(), !0);
}, ge) : () => {
});
}, [t, n, e]), null;
}
function Un({ newTab: n = !0, disabled: e = !1 }) {
const [t] = P();
return _(() => {
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 = te(s);
if (f !== null) {
const C = ce(f, J);
if (!e) if (Ht(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 ee = 0, le = 1, ue = 2, $ = 0, jn = 1, De = 2, Hn = 3, Wn = 4;
function Jn(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 k = N.get(L);
k !== void 0 && b.push(k);
}
for (const [L, k] of S) {
if (!k) 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 ? Hn : x === -1 && v === y ? Wn : $;
}
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, ue;
const d = Jn(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 ee;
if (i === null) return le;
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) ? ee : le : v !== null ? ee : ue;
})();
return t = c, o = d, f;
};
}
function $e(n) {
n.undoStack = [], n.redoStack = [], n.current = null;
}
function Vn(n, e, t) {
const o = qn(n, t);
return j(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(X, !0)), l.length === 0 && r.dispatchCommand(Y, !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(Y, !0));
const c = a.pop();
a.length === 0 && r.dispatchCommand(X, !1), s.current = c || null, c && c.editor.setEditorState(c.editorState, { tag: "historic" });
}
}(n, e), !0), m), n.registerCommand(Pt, () => ($e(e), !1), m), n.registerCommand(Tt, () => ($e(e), n.dispatchCommand(X, !1), n.dispatchCommand(Y, !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 === le) d.length !== 0 && (e.redoStack = [], n.dispatchCommand(X, !1)), c !== null && (f.push({ ...c }), n.dispatchCommand(Y, !0));
else if (y === ue) return;
e.current = { editor: n, editorState: r };
}));
}
function Gn() {
return { current: null, redoStack: [], undoStack: [] };
}
function Xn({ delay: n, externalHistoryState: e }) {
const [t] = P();
return function(o, i, r = 1e3) {
const s = q(() => i || Gn(), [i]);
_(() => Vn(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] = P();
return _(() => {
Jt(i, o);
}, [i, o]), _(() => qt(i), [i]), _(() => Vt(i, t), [i, t]), _(() => {
if (!n) return Gt(i);
}, [i, n]), _(() => {
if (!e) return i.registerNodeTransform(Ue, (r) => {
r.getBackgroundColor() !== null && r.setBackgroundColor(null);
});
}, [i, e, n]), null;
}
const Je = 200, Qn = ({
currentLanguage: n = "NL",
initialValue: e = "",
placeholder: t = "",
label: o = "",
info: i = "",
required: r = !1,
notValidatedText: s = "",
maxHeightInRem: a = "20rem",
maxWords: l = Je,
onChange: u
}) => {
const { switchLanguage: c } = fn(), d = an(), [f] = O(() => Pe()), [C, y] = O(0), [v, x] = O(0), E = Fe(null), w = {
html: {
export: nn
},
namespace: "UvaRte",
editor: f,
theme: un,
onError(b) {
throw b;
},
nodes: [Ae, ze, Be, Wt, Ue, Xt, Yt],
editorState: (b) => {
const k = new DOMParser().parseFromString(e, "text/html"), R = zt(b, k), F = z();
if (F.clear(), rn(e))
R.forEach((B) => {
F.append(B);
});
else {
const B = Re();
R.forEach((D, V) => {
V === 0 ? (B.append(D), F.append(B)) : F.append(D);
});
}
}
}, S = (b) => b.trim().length === 0 ? 0 : b.split(" ").length, N = (b, L) => {
b.read(() => {
let k = "";
y(S(z().getTextContent().replace(/\s+/g, " ").trim())), k = on(Bt(L)), u(k);
});
};
return _(() => {
c(n.toLocaleLowerCase());
}, [n, c]), _(() => {
const b = e.replace(/<br\s*\/?>| /gi, " ").replace(/<\/?[^>]+(>|$)|&[a-z]+;/g, "").replace(/\s+/g, " ").trim();
y(S(b));
}, []), /* @__PURE__ */ K("div", { className: I.editor__container, children: [
/* @__PURE__ */ K("div", { className: I.editor__header, children: [
/* @__PURE__ */ h(cn, { label: o, info: i, required: r }),
/* @__PURE__ */ K("div", { className: I["editor__header-word-count"], children: [
/* @__PURE__ */ h("span", { className: tn({ [I["editor__header-word-count--alert"]]: C > l }), children: C }),
" / ",
l
] })
] }),
/* @__PURE__ */ h("div", { className: I.editor, children: /* @__PURE__ */ K(gn, { initialConfig: w, children: [
/* @__PURE__ */ h(sn, { editorScrollPosition: v }),
/* @__PURE__ */ K("div", { className: I["editor__field-wrapper"], children: [
/* @__PURE__ */ h(
Dn,
{
contentEditable: /* @__PURE__ */ h(
Rn,
{
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: Fn
}
),
/* @__PURE__ */ h(Yn, {}),
/* @__PURE__ */ h(Xn, {}),
/* @__PURE__ */ h(zn, {}),
/* @__PURE__ */ h(Bn, { validateUrl: Qt }),
/* @__PURE__ */ h(Zt, { matchers: en }),
/* @__PURE__ */ h(Un, {}),
/* @__PURE__ */ h(An, { onChange: N }),
/* @__PURE__ */ h(mn, {})
] })
] }) }),
s !== "" && /* @__PURE__ */ h(ln, { level: "error", feedback: s })
] });
}, Br = ({
currentLanguage: n = "NL",
initialValue: e = "",
placeholder: t = "",
label: o = "",
info: i = "",
required: r = !1,
notValidatedText: s = "",
maxWords: a = Je,
onChange: l
}) => /* @__PURE__ */ h(dn, { children: /* @__PURE__ */ h(
Qn,
{
currentLanguage: n,
initialValue: e,
placeholder: t,
label: o,
info: i,
required: r,
notValidatedText: s,
maxWords: a,
onChange: l
}
) });
export {
Qn as Rte,
Br as RteEditor
};
//# sourceMappingURL=RteEditor.js.map