mirror of
https://github.com/TriliumNext/Trilium.git
synced 2025-12-10 03:53:37 -06:00
chore(react/type_widget): refactor event handling slightly
This commit is contained in:
parent
f6631b7b9a
commit
8a185262fb
@ -31,10 +31,6 @@ export default function CKEditorWithWatchdog({ content, className, tabIndex, isC
|
|||||||
isClassicEditor: !!isClassicEditor
|
isClassicEditor: !!isClassicEditor
|
||||||
});
|
});
|
||||||
|
|
||||||
if (onNotificationWarning) {
|
|
||||||
editor.plugins.get("Notification").on("show:warning", onNotificationWarning);
|
|
||||||
}
|
|
||||||
|
|
||||||
setEditor(editor);
|
setEditor(editor);
|
||||||
|
|
||||||
return editor;
|
return editor;
|
||||||
@ -52,6 +48,14 @@ export default function CKEditorWithWatchdog({ content, className, tabIndex, isC
|
|||||||
// React to content changes.
|
// React to content changes.
|
||||||
useEffect(() => editor?.setData(content ?? ""), [ editor, content ]);
|
useEffect(() => editor?.setData(content ?? ""), [ editor, content ]);
|
||||||
|
|
||||||
|
// React to notification warning callback.
|
||||||
|
useEffect(() => {
|
||||||
|
if (!onNotificationWarning || !editor) return;
|
||||||
|
const notificationPlugin = editor.plugins.get("Notification");
|
||||||
|
notificationPlugin.on("show:warning", onNotificationWarning);
|
||||||
|
return () => notificationPlugin.off("show:warning", onNotificationWarning);
|
||||||
|
}, [ editor, onNotificationWarning ]);
|
||||||
|
|
||||||
// React to on change listener.
|
// React to on change listener.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!editor) return;
|
if (!editor) return;
|
||||||
@ -60,9 +64,7 @@ export default function CKEditorWithWatchdog({ content, className, tabIndex, isC
|
|||||||
}, [ editor, onChange ]);
|
}, [ editor, onChange ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={containerRef} className={className} tabIndex={tabIndex}>
|
<div ref={containerRef} className={className} tabIndex={tabIndex} />
|
||||||
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user