运行命令和连接控件
interface EditorInstance {
execute(command: string, value?: unknown): void;
isActive(commandOrName: string, value?: unknown): boolean;
}
const bold = useIsActive(editor, 'toggleBold');
const heading = useIsActive(editor, 'setHeading', 2);
const undoAvailable = useCanUndo(editor);
const redoAvailable = useCanRedo(editor);
const isEmpty = useEditorState(editor, e => (e.el?.textContent ?? '') === '');
execute 按名称运行命令。isActive 查询选区格式。编辑器实例保持稳定,工具栏可以通过 React 钩子订阅状态。useEditorState 可直接返回布尔值、字符串或数字,避免新对象带来的重复渲染。