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