feat: prevent command crash

This commit is contained in:
Nevo David 2025-08-01 17:38:49 +07:00
parent 5a333a06b9
commit 0165d73ce9
6 changed files with 16 additions and 16 deletions

View File

@ -75,9 +75,9 @@ export const BoldText: FC<{
currentValue: string;
}> = ({ editor }) => {
const mark = () => {
editor.commands.unsetUnderline();
editor.commands.toggleBold();
editor.commands.focus();
editor?.commands?.unsetUnderline();
editor?.commands?.toggleBold();
editor?.commands?.focus();
};
return (
<div

View File

@ -7,7 +7,7 @@ export const Bullets: FC<{
currentValue: string;
}> = ({ editor }) => {
const bullet = () => {
editor.commands.toggleBulletList();
editor?.commands?.toggleBulletList();
};
return (
<div

View File

@ -64,8 +64,8 @@ const InterceptBoldShortcut = Extension.create({
return {
'Mod-b': () => {
// For example, toggle bold while removing underline
this.editor.commands.unsetUnderline();
return this.editor.commands.toggleBold();
this?.editor?.commands?.unsetUnderline();
return this?.editor?.commands?.toggleBold();
},
};
},
@ -78,8 +78,8 @@ const InterceptUnderlineShortcut = Extension.create({
return {
'Mod-u': () => {
// For example, toggle bold while removing underline
this.editor.commands.unsetBold();
return this.editor.commands.toggleUnderline();
this?.editor?.commands?.unsetBold();
return this?.editor?.commands?.toggleUnderline();
},
};
},
@ -505,8 +505,8 @@ export const Editor: FC<{
const addText = useCallback(
(emoji: string) => {
editorRef?.current?.editor.commands.insertContent(emoji);
editorRef?.current?.editor.commands.focus();
editorRef?.current?.editor?.commands?.insertContent(emoji);
editorRef?.current?.editor?.commands?.focus();
},
[props.value, id]
);

View File

@ -7,7 +7,7 @@ export const HeadingComponent: FC<{
currentValue: string;
}> = ({ editor }) => {
const setHeading = (level: number) => () => {
editor.commands.toggleHeading({ level })
editor?.commands?.toggleHeading({ level })
};
return (

View File

@ -75,9 +75,9 @@ export const UText: FC<{
currentValue: string;
}> = ({ editor }) => {
const mark = () => {
editor.commands.unsetBold();
editor.commands.toggleUnderline();
editor.commands.focus();
editor?.commands?.unsetBold();
editor?.commands?.toggleUnderline();
editor?.commands?.focus();
};
return (
<div

View File

@ -10,8 +10,8 @@ export const SignatureBox: FC<{
setShowModal(true);
}, [showModal]);
const appendValue = (val: string) => {
editor?.commands.insertContent("\n\n" + val);
editor?.commands.focus();
editor?.commands?.insertContent("\n\n" + val);
editor?.commands?.focus();
setShowModal(false);
};
return (