@uva-glass/component-library
Version:
React components UvA
241 lines (240 loc) • 7.82 kB
JavaScript
import { jsx as k, jsxs as X } from "react/jsx-runtime";
import { o as Y } from "../../../../LexicalComposerContext.prod-DLlRM5wP.js";
import { c as q } from "../../../../clsx-OuTLNxxd.js";
import { d as U, O as G, N as J } from "../../../../LexicalLink.prod-Du8ZoNsh.js";
import { useRef as a, useState as Q, useEffect as m } from "react";
import { W as Z, a as f, g as $, ao as tt, c as w, E as et, u as ot, X as rt } from "../../../../Lexical.prod-CniF7zEE.js";
import { A as nt } from "../../../../TablePlugin-MjKuocl4.js";
import { e as it } from "../../../../helpers-ChM6xtQG.js";
import { LinkContextMenu as st } from "./LinkContextMenu/LinkContextMenu.js";
import { useFlyout as ct } from "../../hooks/useFlyout.js";
import { Icon as lt } from "../../../Icon/Icon.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 "../../../GridRow/GridRow.js";
import "../../../IconButton/IconButton.js";
import "../../../Input/Input.js";
import "../../../InputField/InputField.js";
import "react-router";
import { setScrollableContainers as O, removeScrollableContainers as at } from "../../helpers.js";
import { s as h } from "../../../../RteEditor.module-oFMKEW6f.js";
import { useTranslation as ut } from "../../hooks/useTranslation.js";
import "../../Providers/LanguageProvider.js";
import "../../../../index-B3c5pcHk.js";
import "../../../SelectListbox/SelectListbox.js";
import "../../../SelectListbox/SelectProvider.js";
import "../../../Sortable/components/SortableItem.js";
import "../../../../SortableProvider-Ck_XnBVq.js";
const mt = 200, z = (p) => {
let n = p;
for (; n; ) {
if (U(n))
return n;
n = n.getParent();
}
return null;
}, I = (p) => {
let n = p;
for (; n; ) {
if (U(n))
return {
active: !0,
url: n.getURL(),
linktext: n.getTextContent()
};
n = n.getParent();
}
return !1;
}, Wt = ({ parentScrollPosition: p }) => {
const n = ut(), [c] = Y(), { flyout: A, showFlyout: _, hideFlyout: C, isVisible: u } = ct(), d = a(void 0), N = a(!1), y = a(""), g = a(""), [L, H] = Q({ active: !1, url: "", linktext: "" }), P = a(u), x = a(null), S = a(null), T = a(void 0), b = () => {
c.update(() => {
const e = f();
x.current = e;
});
}, R = () => {
c.update(() => {
x.current && ot(x.current);
});
}, M = (e, t) => {
_({
position: t,
children: /* @__PURE__ */ k(
st,
{
url: e,
onSave: (o) => K(o, ""),
onDelete: () => V(),
onClose: D,
ref: T
}
)
});
}, D = () => {
var e;
(e = T.current) == null || e.clearForm(), C(), R();
}, E = () => {
var t;
const e = (t = S.current) == null ? void 0 : t.getBoundingClientRect();
!N.current && e && (b(), _({ position: { top: e.bottom, left: e.left }, ...j }), setTimeout(() => {
var o;
return (o = d.current) == null ? void 0 : o.setDefaults("", g.current);
}, 0));
}, v = () => {
C(), R();
}, K = (e, t) => {
c.update(() => {
const o = f();
if (w(o)) {
const i = o.anchor.getNode(), s = z(i);
if (t && t !== "") {
if (s) {
const l = rt(t);
s.replace(l), l.select();
}
if (t !== y.current && y.current === "") {
const { anchor: l, focus: F } = o;
o.insertText(t), l.offset -= t.length, F.offset = l.offset + t.length;
}
}
J(it(e), { target: "_blank" });
}
v();
});
}, V = () => {
c.dispatchCommand(G, null), D();
}, j = {
children: /* @__PURE__ */ k(
nt,
{
isLink: L,
onCloseHandler: v,
onSaveHandler: (e, t) => K(e, t),
ref: d
}
)
};
return m(() => {
var e, t;
u ? (N.current = !0, (t = d.current) == null || t.focusFirstField()) : ((e = d.current) == null || e.clearForm(), y.current = g.current = "", setTimeout(() => N.current = !1, mt));
}, [d, u]), m(() => {
const e = (r) => {
if (w(r) && r.isCollapsed()) {
const i = I(r.anchor.getNode());
if (i) {
const s = c.getElementByKey(r.anchor.getNode().getKey()), l = s ? { top: s.getBoundingClientRect().bottom, left: s.getBoundingClientRect().left } : { top: 0, left: 0 };
return M(i.url, l), !0;
}
}
return !1;
}, t = c.registerCommand(
Z,
() => {
const r = f();
return g.current = (r == null ? void 0 : r.getTextContent()) ?? "", e(r), !1;
},
0
), o = c.registerCommand(
$,
(r) => {
const i = f();
return b(), r.preventDefault(), r.stopPropagation(), r.stopImmediatePropagation(), e(i), !1;
},
0
);
return () => {
o(), t();
};
}, [c]), m(() => {
const e = c.registerCommand(
tt,
(o) => {
if (o.ctrlKey && o.shiftKey && o.key === "U") {
const r = f();
if (b(), !w(r))
return !1;
const i = I(r.anchor.getNode()), s = (F = "", W = "") => {
E(), setTimeout(() => {
var B;
return (B = d.current) == null ? void 0 : B.setDefaults(F, W);
}, 0);
};
if (i)
return o.preventDefault(), o.stopPropagation(), o.stopImmediatePropagation(), y.current = i.linktext, s(i.url, i.linktext), !0;
const l = r.getTextContent();
return l !== "" ? (g.current = l, s("", g.current), !0) : (E(), !0);
}
return !1;
},
et
), t = c.registerUpdateListener(({ editorState: o }) => {
H(
o.read(() => {
const r = f();
if (b(), w(r)) {
const i = r.anchor.getNode(), s = z(i);
if (s)
return {
active: !0,
url: s.getURL(),
linktext: s.getTextContent()
};
}
return {
active: !1,
url: "",
linktext: ""
};
})
);
});
return () => {
e(), t();
};
}, [c]), m(() => {
var e;
P.current = u, u || (e = T.current) == null || e.clearForm();
}, [u]), m(() => {
u && v();
}, [p]), m(() => {
L.active || C();
}, [L]), m(() => {
const e = (o) => (O(t), o.key === "Escape" && P.current && (o.preventDefault(), o.stopPropagation(), v()), !0);
window.addEventListener("keydown", e, { capture: !0 });
const t = () => {
C();
};
return O(t), window.addEventListener("scroll", t), window.addEventListener("resize", t), () => {
window.removeEventListener("keydown", e), window.removeEventListener("scroll", t), window.removeEventListener("resize", t), at(t);
};
}, []), /* @__PURE__ */ k("div", { className: h["editor__toolbar-button-group"], children: /* @__PURE__ */ X("div", { className: h["editor__toolbar-button-flyoutwrapper"], children: [
/* @__PURE__ */ k(
"button",
{
onClick: E,
title: n.links.linkTooltip,
className: q(
h["editor__toolbar-button"],
h["editor__toolbar-button--link"],
L.active && h["editor__toolbar-button--active"]
),
"aria-label": n.aria.labels.link,
"aria-keyshortcuts": n.aria.keyshortcuts.link,
type: "button",
ref: S,
children: /* @__PURE__ */ k(lt, { name: "Link", size: 20 })
}
),
A
] }) });
};
export {
Wt as LinkPlugin,
I as getLinkNodeTag
};
//# sourceMappingURL=LinkPlugin.js.map