@uva-glass/component-library
Version:
React components UvA
96 lines (95 loc) • 3.41 kB
JavaScript
import { jsx as d } from "react/jsx-runtime";
import { o as I } from "../../../../LexicalComposerContext.prod-DLlRM5wP.js";
import { C as N, y as P, _ as k, n as K, a as f, c as E } from "../../../../LexicalList.prod-pZmYrwOC.js";
import { _ as O } from "../../../../LexicalSelection.prod-DkvWlcln.js";
import { useState as p, useEffect as y } from "react";
import { c as w } from "../../../../clsx-OuTLNxxd.js";
import { ap as x, N as U, S as v, a as b, c as h, E as B, T } from "../../../../Lexical.prod-CWyHQUEM.js";
import { Icon as $ } from "../../../Icon/Icon.js";
import { s as u } from "../../../../RteEditor.module-oFMKEW6f.js";
import { useTranslation as j } from "../../hooks/useTranslation.js";
const z = {
bullet: "BulletList",
number: "NumberedList"
}, Y = ["bullet", "number"], W = () => {
const l = j(), [e] = I(), [g, s] = p("paragraph"), [c, _] = p(!1), [m, L] = p(!1), S = () => {
e.update(() => {
const t = b();
h(t) && O(t, () => T());
});
}, D = (t) => {
t === "number" && g !== "number" ? (e.dispatchCommand(P, void 0), s("number")) : t === "bullet" && g !== "bullet" ? (e.dispatchCommand(k, void 0), s("bullet")) : (S(), s("paragraph"));
};
return y(() => {
const t = e.registerCommand(
x,
(r) => r.ctrlKey && r.shiftKey && r.code === "Digit7" ? (r.preventDefault(), m ? e.dispatchCommand(N, void 0) : e.dispatchCommand(P, void 0), !0) : r.ctrlKey && r.shiftKey && r.code === "Digit8" ? (r.preventDefault(), c ? e.dispatchCommand(N, void 0) : e.dispatchCommand(k, void 0), !0) : !1,
U
);
return () => {
t();
};
}, [e, m, c]), y(() => {
e.registerCommand(
v,
(r) => (r.preventDefault(), e.update(() => {
const i = b();
if (!h(i))
return;
const o = i.anchor.getNode(), n = o.getParent();
if (!K(n))
return;
const a = n.getParent();
if (f(a)) {
const C = E(f(a) ? a.getListType() : "bullet");
n.append(C), C.append(o);
}
}), !0),
B
);
const t = e.registerUpdateListener(({ editorState: r }) => {
r.read(() => {
const i = b();
if (h(i)) {
let o = i.anchor.getNode();
for (; o !== null; ) {
if (f(o)) {
const a = o.getTag();
_(a === "ul"), L(a === "ol"), a === "ul" && s("bullet"), a === "ol" && s("number");
return;
}
const n = o.getParent();
if (n === null) break;
o = n;
}
_(!1), L(!1), s("paragraph");
}
return !1;
});
});
return () => {
t();
};
}, [e]), /* @__PURE__ */ d("div", { className: u["editor__toolbar-button-group"], children: Y.map((t) => /* @__PURE__ */ d(
"button",
{
onClick: () => D(t),
title: l.format[`${t}Tooltip`],
className: w(
u["editor__toolbar-button"],
u[`editor__toolbar-button--${t}`],
t === "bullet" && c && u["editor__toolbar-button--active"],
t === "number" && m && u["editor__toolbar-button--active"]
),
"aria-label": l.aria.labels[t],
"aria-keyshortcuts": l.aria.keyshortcuts[t],
type: "button",
children: /* @__PURE__ */ d($, { name: z[t], size: 24 })
},
t
)) });
};
export {
W as ListPlugin
};
//# sourceMappingURL=ListPlugin.js.map