chore(react/ribbon): load current attributes in editor

This commit is contained in:
Elian Doran
2025-08-23 12:39:49 +03:00
parent befc5a9530
commit e5caf37697
4 changed files with 35 additions and 18 deletions

View File

@@ -2,6 +2,7 @@ import { CKTextEditor, type AttributeEditor, type EditorConfig, type ModelPositi
import { useEffect, useRef } from "preact/compat";
interface CKEditorOpts {
currentValue?: string;
className: string;
tabIndex?: number;
config: EditorConfig;
@@ -12,7 +13,7 @@ interface CKEditorOpts {
onClick?: (pos?: ModelPosition | null) => void;
}
export default function CKEditor({ className, tabIndex, editor, config, disableNewlines, disableSpellcheck, onChange, onClick }: CKEditorOpts) {
export default function CKEditor({ currentValue, className, tabIndex, editor, config, disableNewlines, disableSpellcheck, onChange, onClick }: CKEditorOpts) {
const editorContainerRef = useRef<HTMLDivElement>(null);
const textEditorRef = useRef<CKTextEditor>(null);
@@ -44,9 +45,18 @@ export default function CKEditor({ className, tabIndex, editor, config, disableN
if (onChange) {
textEditor.model.document.on("change:data", onChange);
}
if (currentValue) {
textEditor.setData(currentValue);
}
});
}, []);
useEffect(() => {
if (!textEditorRef.current) return;
textEditorRef.current.setData(currentValue ?? "");
}, [ currentValue ]);
return (
<div
ref={editorContainerRef}