Files
simple-react-app-kit/packages/lexical/src/actions/history.ts
T

28 lines
821 B
TypeScript
Raw Normal View History

import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin"
import { Redo2, Undo2 } from "lucide-react"
import { REDO_COMMAND, UNDO_COMMAND } from "lexical"
import type { LexicalActionDefinition } from "../types"
import { lexicalMessages } from "../messages"
export const undoAction: LexicalActionDefinition = {
name: "undo",
label: lexicalMessages.undo,
icon: Undo2,
plugins: [HistoryPlugin],
execute: ({ editor }) => {
editor.dispatchCommand(UNDO_COMMAND, undefined)
},
isDisabled: ({ state }) => !state.canUndo,
}
export const redoAction: LexicalActionDefinition = {
name: "redo",
label: lexicalMessages.redo,
icon: Redo2,
plugins: [HistoryPlugin],
execute: ({ editor }) => {
editor.dispatchCommand(REDO_COMMAND, undefined)
},
isDisabled: ({ state }) => !state.canRedo,
}