1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Lexical: Linked code block to editor, added button

This commit is contained in:
Dan Brown
2024-07-02 17:34:03 +01:00
parent 97f570a4ee
commit d0a5a5ef37
8 changed files with 128 additions and 25 deletions

View File

@ -73,7 +73,6 @@ export class CodeBlockNode extends DecoratorNode<EditorDecoratorAdapter> {
}
decorate(editor: LexicalEditor, config: EditorConfig): EditorDecoratorAdapter {
// TODO
return {
type: 'code',
getNode: () => this,
@ -165,4 +164,22 @@ export function $createCodeBlockNode(language: string = '', code: string = ''):
export function $isCodeBlockNode(node: LexicalNode | null | undefined) {
return node instanceof CodeBlockNode;
}
export function $openCodeEditorForNode(editor: LexicalEditor, node: CodeBlockNode): void {
const code = node.getCode();
const language = node.getLanguage();
// @ts-ignore
const codeEditor = window.$components.first('code-editor');
// TODO - Handle direction
codeEditor.open(code, language, 'ltr', (newCode: string, newLang: string) => {
editor.update(() => {
node.setCode(newCode);
node.setLanguage(newLang);
});
// TODO - Re-focus
}, () => {
// TODO - Re-focus
});
}