diff --git a/apps/client/src/widgets/attribute_widgets/attribute_editor.ts b/apps/client/src/widgets/attribute_widgets/attribute_editor.ts index 24a4e09d2..016bd8776 100644 --- a/apps/client/src/widgets/attribute_widgets/attribute_editor.ts +++ b/apps/client/src/widgets/attribute_widgets/attribute_editor.ts @@ -212,29 +212,6 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem return $("
").html(str).text(); } - async initEditor() { - this.$widget.show(); - - this.$editor.on("click", (e) => this.handleEditorClick(e)); - - this.textEditor.model.document.on("change:data", () => this.dataChanged()); - this.textEditor.editing.view.document.on( - "enter", - (event, data) => { - // disable entering new line - see https://github.com/ckeditor/ckeditor5/issues/9422 - data.preventDefault(); - event.stop(); - }, - { priority: "high" } - ); - - // disable spellcheck for attribute editor - const documentRoot = this.textEditor.editing.view.document.getRoot(); - if (documentRoot) { - this.textEditor.editing.view.change((writer) => writer.setAttribute("spellcheck", "false", documentRoot)); - } - } - dataChanged() { this.lastUpdatedNoteId = this.noteId; diff --git a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx index 88bc85139..55c2d5968 100644 --- a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx +++ b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef } from "preact/hooks" +import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks" import { AttributeEditor as CKEditor, EditorConfig, MentionFeed } from "@triliumnext/ckeditor5"; import { t } from "../../../services/i18n"; import server from "../../../services/server"; @@ -61,17 +61,43 @@ const editorConfig: EditorConfig = { export default function AttributeEditor() { const editorContainerRef = useRef(null); + const [ attributeDetailVisible, setAttributeDetailVisible ] = useState(false); + + const onClick = useCallback(() => { + console.log("Clicked"); + }, []); useEffect(() => { if (!editorContainerRef.current) return; CKEditor.create(editorContainerRef.current, editorConfig).then((textEditor) => { + function onDataChanged() { + console.log("Data changed"); + } + // Prevent newlines + textEditor.editing.view.document.on( + "enter", + (event, data) => { + // disable entering new line - see https://github.com/ckeditor/ckeditor5/issues/9422 + data.preventDefault(); + event.stop(); + }, + { priority: "high" } + ); + + // disable spellcheck for attribute editor + const documentRoot = textEditor.editing.view.document.getRoot(); + if (documentRoot) { + textEditor.editing.view.change((writer) => writer.setAttribute("spellcheck", "false", documentRoot)); + } + + textEditor.model.document.on("change:data", onDataChanged); }); }, []); return ( -
+
)