From 2eab8b92d59d26becf6bc0dcc08bbaa541352484 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 22 Sep 2025 12:49:03 +0300 Subject: [PATCH] chore(react/type_widget): react to content language changes --- .../text/CKEditorWithWatchdog.tsx | 14 ++++---- .../type_widgets/text/EditableText.tsx | 5 +-- .../widgets/type_widgets_old/editable_text.ts | 34 ------------------- 3 files changed, 8 insertions(+), 45 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx b/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx index e3615cd2e..6896de045 100644 --- a/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx +++ b/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx @@ -1,20 +1,19 @@ import { HTMLProps, RefObject, useEffect, useRef, useState } from "preact/compat"; import { PopupEditor, ClassicEditor, EditorWatchdog, type WatchdogConfig, CKTextEditor } from "@triliumnext/ckeditor5"; import { buildConfig, BuildEditorOptions } from "./config"; -import { Editor } from "tabulator-tables"; interface CKEditorWithWatchdogProps extends Pick, "className" | "tabIndex"> { - content?: string; + content: string | undefined; + contentLanguage: string | null | undefined; isClassicEditor?: boolean; watchdogRef: RefObject; watchdogConfig?: WatchdogConfig; - buildEditorOpts: Omit; onNotificationWarning?: (evt: any, data: any) => void; onWatchdogStateChange?: (watchdog: EditorWatchdog) => void; onChange: () => void; } -export default function CKEditorWithWatchdog({ content, className, tabIndex, isClassicEditor, watchdogRef: externalWatchdogRef, watchdogConfig, buildEditorOpts, onNotificationWarning, onWatchdogStateChange, onChange }: CKEditorWithWatchdogProps) { +export default function CKEditorWithWatchdog({ content, contentLanguage, className, tabIndex, isClassicEditor, watchdogRef: externalWatchdogRef, watchdogConfig, buildEditorOpts, onNotificationWarning, onWatchdogStateChange, onChange }: CKEditorWithWatchdogProps) { const containerRef = useRef(null); const watchdogRef = useRef(null); const [ editor, setEditor ] = useState(); @@ -27,8 +26,9 @@ export default function CKEditorWithWatchdog({ content, className, tabIndex, isC externalWatchdogRef.current = watchdog; watchdog.setCreator(async () => { const editor = await buildEditor(container, !!isClassicEditor, { - ...buildEditorOpts, - isClassicEditor: !!isClassicEditor + forceGplLicense: false, + isClassicEditor: !!isClassicEditor, + contentLanguage: contentLanguage ?? null }); setEditor(editor); @@ -43,7 +43,7 @@ export default function CKEditorWithWatchdog({ content, className, tabIndex, isC watchdog.create(container); return () => watchdog.destroy(); - }, []); + }, [ contentLanguage ]); // React to content changes. useEffect(() => editor?.setData(content ?? ""), [ editor, content ]); diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.tsx b/apps/client/src/widgets/type_widgets/text/EditableText.tsx index def4f62e9..1330852a8 100644 --- a/apps/client/src/widgets/type_widgets/text/EditableText.tsx +++ b/apps/client/src/widgets/type_widgets/text/EditableText.tsx @@ -47,6 +47,7 @@ export default function EditableText({ note }: TypeWidgetProps) { {note && spacedUpdate.scheduleUpdate()} diff --git a/apps/client/src/widgets/type_widgets_old/editable_text.ts b/apps/client/src/widgets/type_widgets_old/editable_text.ts index 22117f7c2..d3f23e0aa 100644 --- a/apps/client/src/widgets/type_widgets_old/editable_text.ts +++ b/apps/client/src/widgets/type_widgets_old/editable_text.ts @@ -92,18 +92,6 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { await this.createEditor(); } - async doRefresh(note: FNote) { - const blob = await note.getBlob(); - - await this.spacedUpdate.allowUpdateWithoutChange(async () => { - const data = blob?.content || ""; - const newContentLanguage = this.note?.getLabelValue("language"); - if (this.contentLanguage !== newContentLanguage) { - await this.reinitializeWithData(data); - } - }); - } - focus() { const editor = this.watchdog.editor; if (editor) { @@ -130,14 +118,6 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { return this.watchdog?.editor; } - cleanup() { - if (this.watchdog?.editor) { - this.spacedUpdate.allowUpdateWithoutChange(() => { - this.watchdog.editor?.setData(""); - }); - } - } - insertDateTimeToTextCommand() { const date = new Date(); const customDateTimeFormat = options.get("customDateTimeFormat"); @@ -323,16 +303,6 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { this.refreshIncludedNote(this.$editor, noteId); } - async reinitializeWithData(data: string) { - if (!this.watchdog) { - return; - } - - this.watchdog.destroy(); - await this.createEditor(); - this.watchdog.editor?.setData(data); - } - async reinitialize() { const data = this.watchdog.editor?.getData(); await this.reinitializeWithData(data ?? ""); @@ -342,10 +312,6 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { await this.reinitialize(); } - async onLanguageChanged() { - await this.reinitialize(); - } - async entitiesReloadedEvent(e: EventData<"entitiesReloaded">) { await super.entitiesReloadedEvent(e);