laif-ds
Version:
Design System di Laif con componenti React basati su principi di Atomic Design
70 lines (69 loc) • 2.21 kB
JavaScript
"use client";
import { jsxs as f, jsx as o } from "react/jsx-runtime";
import { useState as s, useEffect as u } from "react";
import { useLexicalComposerContext as N } from "../../../../node_modules/@lexical/react/LexicalComposerContext.prod.js";
import { mergeRegister as b } from "../../../../node_modules/@lexical/utils/LexicalUtils.prod.js";
import { CAN_REDO_COMMAND as R, COMMAND_PRIORITY_CRITICAL as n, CAN_UNDO_COMMAND as M, UNDO_COMMAND as O, REDO_COMMAND as D } from "../../../../node_modules/lexical/Lexical.prod.js";
import { useToolbarContext as g } from "../../context/toolbar-context.js";
import { Button as d } from "../../../ui/button.js";
import x from "../../../../node_modules/lucide-react/dist/esm/icons/undo.js";
import A from "../../../../node_modules/lucide-react/dist/esm/icons/redo.js";
function j() {
const [i] = N(), { activeEditor: t, $updateToolbar: a } = g(), [r, l] = s(i.isEditable()), [m, c] = s(!1), [C, p] = s(!1);
return u(() => b(
i.registerEditableListener((e) => {
l(e);
}),
t.registerUpdateListener(({ editorState: e }) => {
e.read(() => {
a();
});
}),
t.registerCommand(
M,
(e) => (c(e), !1),
n
),
t.registerCommand(
R,
(e) => (p(e), !1),
n
)
), [a, t, i]), /* @__PURE__ */ f("div", { className: "flex items-center gap-1", children: [
/* @__PURE__ */ o(
d,
{
disabled: !m || !r,
onClick: () => {
t.dispatchCommand(O, void 0);
},
title: "Undo (⌘Z)",
type: "button",
"aria-label": "Undo",
size: "icon",
className: "!h-8 !w-8",
variant: "outline",
children: /* @__PURE__ */ o(x, { className: "size-4" })
}
),
/* @__PURE__ */ o(
d,
{
disabled: !C || !r,
onClick: () => {
t.dispatchCommand(D, void 0);
},
title: "Redo (⇧⌘Z)",
type: "button",
"aria-label": "Redo",
variant: "outline",
size: "icon",
className: "!h-8 !w-8",
children: /* @__PURE__ */ o(A, { className: "size-4" })
}
)
] });
}
export {
j as HistoryToolbarPlugin
};