Skip to content
Snippets Groups Projects
Commit 9d73651b authored by Dennis Collaris's avatar Dennis Collaris Committed by Samed
Browse files

feat: add import/export capabilities to variable nodes

parent 3eafc3ce
No related branches found
No related tags found
1 merge request!344feat: persist report on the backend
This commit is part of merge request !344. Comments created here will be created in the context of that merge request.
import type { NodeKey, LexicalEditor, DOMExportOutput } from 'lexical';
import type { NodeKey, LexicalEditor, DOMExportOutput, SerializedLexicalNode, Spread } from 'lexical';
import { DecoratorNode, EditorConfig } from 'lexical';
export enum VariableType {
......@@ -6,6 +6,14 @@ export enum VariableType {
visualization = 'visualization',
}
export type SerializedVariableNode = Spread<
{
name: string,
variableType: VariableType
},
SerializedLexicalNode
>;
export class VariableNode extends DecoratorNode<JSX.Element> {
__name: string;
__variableType: VariableType;
......@@ -39,6 +47,22 @@ export class VariableNode extends DecoratorNode<JSX.Element> {
return `{{ ${self.__variableType}:${self.__name} }}`;
}
// Import and export
exportJSON(): SerializedVariableNode {
return {
type: this.getType(),
variableType: this.__variableType,
name: this.__name,
version: 1,
};
}
static importJSON(jsonNode: SerializedVariableNode): VariableNode {
const node = new VariableNode(jsonNode.name, jsonNode.variableType);
return node;
}
// View
createDOM(config: EditorConfig): HTMLElement {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment