mirror of
https://github.com/zadam/trilium.git
synced 2025-10-30 02:37:17 +08:00
chore(react/type_widget): port notification warning
This commit is contained in:
parent
78b83cd17b
commit
f00f2ee5e4
3 changed files with 26 additions and 16 deletions
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue