UNPKG

@uva-glass/component-library

Version:

React components UvA

96 lines (95 loc) 3.41 kB
import { jsx as d } from "react/jsx-runtime"; import { o as K } from "../../../../LexicalComposerContext.prod-DLlRM5wP.js"; import { s as N, r as P, e as k, H as S, t as f, Z as y } from "../../../../LexicalList.prod-BUcoZhe4.js"; import { _ as E } from "../../../../LexicalSelection.prod-BfAlhGGm.js"; import { useState as p, useEffect as w } from "react"; import { c as O } from "../../../../clsx-OuTLNxxd.js"; import { ao as x, E as U, T as v, a as b, c as h, P as B, w as $ } from "../../../../Lexical.prod-CniF7zEE.js"; import { Icon as j } from "../../../Icon/Icon.js"; import { s as u } from "../../../../RteEditor.module-oFMKEW6f.js"; import { useTranslation as z } from "../../hooks/useTranslation.js"; const H = { bullet: "BulletList", number: "NumberedList" }, T = ["bullet", "number"], V = () => { const l = z(), [e] = K(), [g, s] = p("paragraph"), [c, L] = p(!1), [m, _] = p(!1), D = () => { e.update(() => { const t = b(); h(t) && E(t, () => $()); }); }, I = (t) => { t === "number" && g !== "number" ? (e.dispatchCommand(P, void 0), s("number")) : t === "bullet" && g !== "bullet" ? (e.dispatchCommand(k, void 0), s("bullet")) : (D(), s("paragraph")); }; return w(() => { 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]), w(() => { e.registerCommand( v, (r) => (r.preventDefault(), e.update(() => { const i = b(); if (!h(i)) return; const o = i.anchor.getNode(), n = o.getParent(); if (!S(n)) return; const a = n.getParent(); if (f(a)) { const C = y(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(); L(a === "ul"), _(a === "ol"), a === "ul" && s("bullet"), a === "ol" && s("number"); return; } const n = o.getParent(); if (n === null) break; o = n; } L(!1), _(!1), s("paragraph"); } return !1; }); }); return () => { t(); }; }, [e]), /* @__PURE__ */ d("div", { className: u["editor__toolbar-button-group"], children: T.map((t) => /* @__PURE__ */ d( "button", { onClick: () => I(t), title: l.format[`${t}Tooltip`], className: O( 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(j, { name: H[t], size: 24 }) }, t )) }); }; export { V as ListPlugin }; //# sourceMappingURL=ListPlugin.js.map