mirror of
https://github.com/docmost/docmost.git
synced 2026-08-29 10:05:03 +08:00
fix: safe editor
This commit is contained in:
+5
-5
@@ -25,11 +25,11 @@ export const BlockTypeGroup: FC<Props> = ({ editor }) => {
|
||||
const state = useEditorState({
|
||||
editor,
|
||||
selector: (ctx) => ({
|
||||
isHeading1: ctx.editor.isActive("heading", { level: 1 }),
|
||||
isHeading2: ctx.editor.isActive("heading", { level: 2 }),
|
||||
isHeading3: ctx.editor.isActive("heading", { level: 3 }),
|
||||
isBlockquote: ctx.editor.isActive("blockquote"),
|
||||
isCodeBlock: ctx.editor.isActive("codeBlock"),
|
||||
isHeading1: !!ctx.editor?.isActive("heading", { level: 1 }),
|
||||
isHeading2: !!ctx.editor?.isActive("heading", { level: 2 }),
|
||||
isHeading3: !!ctx.editor?.isActive("heading", { level: 3 }),
|
||||
isBlockquote: !!ctx.editor?.isActive("blockquote"),
|
||||
isCodeBlock: !!ctx.editor?.isActive("codeBlock"),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ export interface ToolbarState {
|
||||
// static editor (mainExtensions only, undoRedo disabled), neither is loaded
|
||||
// and editor.can().undo/redo is undefined.
|
||||
function safeCan(editor: Editor, command: "undo" | "redo"): boolean {
|
||||
const can = editor.can() as Record<string, unknown>;
|
||||
const can = editor?.can() as Record<string, unknown>;
|
||||
const fn = can[command];
|
||||
return typeof fn === "function" ? (fn as () => boolean)() : false;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ export function useToolbarState(editor: Editor | null): ToolbarState | null {
|
||||
return useEditorState({
|
||||
editor,
|
||||
selector: (ctx) => {
|
||||
if (!ctx.editor) return null;
|
||||
if (!ctx.editor || ctx.editor.isDestroyed) return null;
|
||||
return {
|
||||
isBold: ctx.editor.isActive("bold"),
|
||||
isItalic: ctx.editor.isActive("italic"),
|
||||
|
||||
Reference in New Issue
Block a user