mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-01-03 23:42:28 +03:00
Lexical: Started converting drawio to TS
Converted events service to TS as part of this.
This commit is contained in:
@@ -2,7 +2,6 @@ import {EditorDecorator} from "../framework/decorator";
|
||||
import {EditorUiContext} from "../framework/core";
|
||||
import {$openCodeEditorForNode, CodeBlockNode} from "../../nodes/code-block";
|
||||
import {$selectionContainsNode, $selectSingleNode} from "../../helpers";
|
||||
import {context} from "esbuild";
|
||||
import {BaseSelection} from "lexical";
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,35 @@
|
||||
import {EditorDecorator} from "../framework/decorator";
|
||||
import {EditorUiContext} from "../framework/core";
|
||||
import {$selectionContainsNode, $selectSingleNode} from "../../helpers";
|
||||
import {$openCodeEditorForNode, CodeBlockNode} from "../../nodes/code-block";
|
||||
import {BaseSelection} from "lexical";
|
||||
import {$openDrawingEditorForNode, DiagramNode} from "../../nodes/diagram";
|
||||
|
||||
|
||||
export class DiagramDecorator extends EditorDecorator {
|
||||
protected completedSetup: boolean = false;
|
||||
|
||||
setup(context: EditorUiContext, element: HTMLElement) {
|
||||
//
|
||||
const diagramNode = this.getNode();
|
||||
element.addEventListener('click', event => {
|
||||
context.editor.update(() => {
|
||||
$selectSingleNode(this.getNode());
|
||||
})
|
||||
});
|
||||
|
||||
element.addEventListener('dblclick', event => {
|
||||
context.editor.getEditorState().read(() => {
|
||||
$openDrawingEditorForNode(context.editor, (this.getNode() as DiagramNode));
|
||||
});
|
||||
});
|
||||
|
||||
const selectionChange = (selection: BaseSelection|null): void => {
|
||||
element.classList.toggle('selected', $selectionContainsNode(selection, diagramNode));
|
||||
};
|
||||
context.manager.onSelectionChange(selectionChange);
|
||||
this.onDestroy(() => {
|
||||
context.manager.offSelectionChange(selectionChange);
|
||||
});
|
||||
|
||||
this.completedSetup = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user