]> BookStack Code Mirror - bookstack/blobdiff - resources/js/wysiwyg/nodes/custom-quote.ts
System CLI: Updated to 126de5599c state
[bookstack] / resources / js / wysiwyg / nodes / custom-quote.ts
index 58c62f76919ee87b82f2d9a7a311099f61cd7885..39ae7bf8af3b6f3f1728c016db4b8766d9f44bcd 100644 (file)
@@ -1,19 +1,25 @@
 import {
     DOMConversionMap,
-    DOMConversionOutput, ElementFormatType,
+    DOMConversionOutput,
     LexicalNode,
     Spread
 } from "lexical";
 import {EditorConfig} from "lexical/LexicalEditor";
 import {QuoteNode, SerializedQuoteNode} from "@lexical/rich-text";
+import {
+    CommonBlockAlignment, commonPropertiesDifferent, deserializeCommonBlockNode,
+    SerializedCommonBlockNode,
+    setCommonBlockPropsFromElement,
+    updateElementWithCommonBlockProps
+} from "./_common";
 
 
-export type SerializedCustomQuoteNode = Spread<{
-    id: string;
-}, SerializedQuoteNode>
+export type SerializedCustomQuoteNode = Spread<SerializedCommonBlockNode, SerializedQuoteNode>
 
 export class CustomQuoteNode extends QuoteNode {
     __id: string = '';
+    __alignment: CommonBlockAlignment = '';
+    __inset: number = 0;
 
     static getType() {
         return 'custom-quote';
@@ -29,33 +35,58 @@ export class CustomQuoteNode extends QuoteNode {
         return self.__id;
     }
 
+    setAlignment(alignment: CommonBlockAlignment) {
+        const self = this.getWritable();
+        self.__alignment = alignment;
+    }
+
+    getAlignment(): CommonBlockAlignment {
+        const self = this.getLatest();
+        return self.__alignment;
+    }
+
+    setInset(size: number) {
+        const self = this.getWritable();
+        self.__inset = size;
+    }
+
+    getInset(): number {
+        const self = this.getLatest();
+        return self.__inset;
+    }
+
     static clone(node: CustomQuoteNode) {
         const newNode = new CustomQuoteNode(node.__key);
         newNode.__id = node.__id;
+        newNode.__alignment = node.__alignment;
+        newNode.__inset = node.__inset;
         return newNode;
     }
 
     createDOM(config: EditorConfig): HTMLElement {
         const dom = super.createDOM(config);
-        if (this.__id) {
-            dom.setAttribute('id', this.__id);
-        }
-
+        updateElementWithCommonBlockProps(dom, this);
         return dom;
     }
 
+    updateDOM(prevNode: CustomQuoteNode): boolean {
+        return commonPropertiesDifferent(prevNode, this);
+    }
+
     exportJSON(): SerializedCustomQuoteNode {
         return {
             ...super.exportJSON(),
             type: 'custom-quote',
             version: 1,
             id: this.__id,
+            alignment: this.__alignment,
+            inset: this.__inset,
         };
     }
 
     static importJSON(serializedNode: SerializedCustomQuoteNode): CustomQuoteNode {
         const node = $createCustomQuoteNode();
-        node.setId(serializedNode.id);
+        deserializeCommonBlockNode(serializedNode, node);
         return node;
     }
 
@@ -71,12 +102,7 @@ export class CustomQuoteNode extends QuoteNode {
 
 function $convertBlockquoteElement(element: HTMLElement): DOMConversionOutput {
     const node = $createCustomQuoteNode();
-    if (element.style !== null) {
-        node.setFormat(element.style.textAlign as ElementFormatType);
-    }
-    if (element.id) {
-        node.setId(element.id);
-    }
+    setCommonBlockPropsFromElement(element, node);
     return {node};
 }