chore(react/type_widget): port notification warning

This commit is contained in:
Elian Doran 2025-09-22 12:07:44 +03:00
parent 78b83cd17b
commit f00f2ee5e4
No known key found for this signature in database
3 changed files with 26 additions and 16 deletions

View file

@ -6,9 +6,10 @@ interface CKEditorWithWatchdogProps extends Pick<HTMLProps<HTMLDivElement>, "cla
isClassicEditor?: boolean;
watchdogConfig?: WatchdogConfig;
buildEditorOpts: Omit<BuildEditorOptions, "isClassicEditor">;
onNotificationWarning?: (evt: any, data: any) => void;
}
export default function CKEditorWithWatchdog({ className, tabIndex, isClassicEditor, watchdogConfig, buildEditorOpts }: CKEditorWithWatchdogProps) {
export default function CKEditorWithWatchdog({ className, tabIndex, isClassicEditor, watchdogConfig, buildEditorOpts, onNotificationWarning }: CKEditorWithWatchdogProps) {
const containerRef = useRef<HTMLDivElement>(null);
useEffect(() => {
@ -16,13 +17,21 @@ export default function CKEditorWithWatchdog({ className, tabIndex, isClassicEdi
if (!container) return;
const watchdog = buildWatchdog(!!isClassicEditor, watchdogConfig);
watchdog.setCreator(async () => {
const editor = buildEditor(container, !!isClassicEditor, {
const editor = await buildEditor(container, !!isClassicEditor, {
...buildEditorOpts,
isClassicEditor: !!isClassicEditor
});
if (onNotificationWarning) {
editor.plugins.get("Notification").on("show:warning", onNotificationWarning);
}
return editor;
});
watchdog.create(container);
return () => watchdog.destroy();
}, []);
return (

View file

@ -1,3 +1,4 @@
import toast from "../../../services/toast";
import { isMobile } from "../../../services/utils";
import { useNoteLabel, useTriliumOption } from "../../react/hooks";
import { TypeWidgetProps } from "../type_widget";
@ -32,7 +33,21 @@ export default function EditableText({ note }: TypeWidgetProps) {
contentLanguage: language ?? null,
forceGplLicense: false,
}}
onNotificationWarning={onNotificationWarning}
/>
</div>
)
}
function onNotificationWarning(data, evt) {
const title = data.title;
const message = data.message.message;
if (title && message) {
toast.showErrorTitleAndMessage(data.title, data.message.message);
} else if (title) {
toast.showError(title || message);
}
evt.stop();
}

View file

@ -57,20 +57,6 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
this.watchdog.setCreator(async (_, editorConfig) => {
logInfo("Creating new CKEditor");
const notificationsPlugin = editor.plugins.get("Notification");
notificationsPlugin.on("show:warning", (evt, data) => {
const title = data.title;
const message = data.message.message;
if (title && message) {
toast.showErrorTitleAndMessage(data.title, data.message.message);
} else if (title) {
toast.showError(title || message);
}
evt.stop();
});
if (isClassicEditor) {
const $classicToolbarWidget = this.findClassicToolbar();