]> BookStack Code Mirror - bookstack/blobdiff - resources/js/wysiwyg/nodes/diagram.ts
ExportFormatter: Add book description and check for empty book and chapter descriptio...
[bookstack] / resources / js / wysiwyg / nodes / diagram.ts
index 15726813c9b0f3b7bb1e451c635ddefdd8a46997..bd37b200c80ba610f14bb42c65daffae2ff8e9f3 100644 (file)
@@ -3,13 +3,13 @@ import {
     DOMConversion,
     DOMConversionMap,
     DOMConversionOutput,
-    LexicalEditor, LexicalNode,
+    LexicalEditor,
     SerializedLexicalNode,
     Spread
 } from "lexical";
 import type {EditorConfig} from "lexical/LexicalEditor";
-import {el} from "../helpers";
 import {EditorDecoratorAdapter} from "../ui/framework/decorator";
+import {el} from "../utils/dom";
 
 export type SerializedDiagramNode = Spread<{
     id: string;
@@ -27,7 +27,9 @@ export class DiagramNode extends DecoratorNode<EditorDecoratorAdapter> {
     }
 
     static clone(node: DiagramNode): DiagramNode {
-        return new DiagramNode(node.__drawingId, node.__drawingUrl);
+        const newNode = new DiagramNode(node.__drawingId, node.__drawingUrl);
+        newNode.__id = node.__id;
+        return newNode;
     }
 
     constructor(drawingId: string, drawingUrl: string, key?: string) {
@@ -42,10 +44,10 @@ export class DiagramNode extends DecoratorNode<EditorDecoratorAdapter> {
         self.__drawingId = drawingId;
     }
 
-    getDrawingIdAndUrl(): {id: string, url: string} {
+    getDrawingIdAndUrl(): { id: string, url: string } {
         const self = this.getLatest();
         return {
-            id: self.__drawingUrl,
+            id: self.__drawingId,
             url: self.__drawingUrl,
         };
     }
@@ -103,24 +105,27 @@ export class DiagramNode extends DecoratorNode<EditorDecoratorAdapter> {
         return false;
     }
 
-    static importDOM(): DOMConversionMap|null {
+    static importDOM(): DOMConversionMap | null {
         return {
-            div(node: HTMLElement): DOMConversion|null {
+            div(node: HTMLElement): DOMConversion | null {
 
                 if (!node.hasAttribute('drawio-diagram')) {
                     return null;
                 }
 
                 return {
-                    conversion: (element: HTMLElement): DOMConversionOutput|null => {
+                    conversion: (element: HTMLElement): DOMConversionOutput | null => {
 
                         const img = element.querySelector('img');
                         const drawingUrl = img?.getAttribute('src') || '';
                         const drawingId = element.getAttribute('drawio-diagram') || '';
+                        const node = $createDiagramNode(drawingId, drawingUrl);
 
-                        return {
-                            node: $createDiagramNode(drawingId, drawingUrl),
-                        };
+                        if (element.id) {
+                            node.setId(element.id);
+                        }
+
+                        return { node };
                     },
                     priority: 3,
                 };
@@ -148,11 +153,3 @@ export class DiagramNode extends DecoratorNode<EditorDecoratorAdapter> {
 export function $createDiagramNode(drawingId: string = '', drawingUrl: string = ''): DiagramNode {
     return new DiagramNode(drawingId, drawingUrl);
 }
-
-export function $isDiagramNode(node: LexicalNode | null | undefined) {
-    return node instanceof DiagramNode;
-}
-
-export function $openDrawingEditorForNode(editor: LexicalEditor, node: DiagramNode): void {
-    // Todo
-}
\ No newline at end of file