Hello everyone,
I’m trying to play around and use the native Jupyterlab CodeEditor in my extension.
However I struggle with what I believe a change in the API with the 4.0 and can’t find examples to help me.
For example this extension uses the CodeEditor but for JLAB v3. My problem is with the value. It looks like we could set the value of the text in the code editor with model.value but it seems to not be the case now.
Here is the code I have for now:
export const CodeTextarea: React.FC<CodeTextareaProps> = ({
field,
value,
handleChange,
advanced,
}) => {
const editorRef = useRef<HTMLDivElement | null>(null);
const [editor, setEditor] = useState<CodeEditor.IEditor | null>(null);
useEffect(() => {
if (editorRef.current) {
const languages = new EditorLanguageRegistry();
const factory = new CodeMirrorEditorFactory({
extensions: new EditorExtensionRegistry(),
languages
});
const model = new CodeEditor.Model({
mimeType: 'text/x-python',
});
const editor = factory.newInlineEditor({
host: editorRef.current,
model: model,
config: {
value: value,
mode: 'text/x-python',
lineNumbers: true
}
});
setEditor(editor);
return () => {
editor.dispose();
};
}
}, [value]);
useEffect(() => {
if (editor) {
editor.model.value.changed.connect((sender, args) => {
handleChange(editor.model.value.text, field.id);
});
}
}, [editor, handleChange, field.id]);
return (
<div ref={editorRef} style={{ height: '300px', width: '100%' }} />
);
};
Errors are with:
editor.model.value.changed.connect((sender, args) => {
handleChange(editor.model.value.text, field.id);
});
}
because:
Property ‘value’ does not exist on type ‘IModel’.ts(2339)
Of course, I checked the reference API, but don’t necessarily understand the documentation.
Any pointers on what I’m missing would be really appreciated, thanks in advance
Thibaut