import { Editor, schemaCtx, serializerCtx } from '@weamd/core';
import { diagram } from '@weamd/plugin-diagram';
import { emoji } from '@weamd/plugin-emoji';
import { gfm } from '@weamd/preset-gfm';
import { Node, Schema } from 'prosemirror-model';

export class BaseEditor {
    #editor?: Editor;
    #schema?: Schema;
    #serializer?: (node: Node) => string;
    init = async () => {
        const editor = await Editor.make().use(emoji).use(gfm).use(diagram).create();
        return (this.#editor = editor);
    };
    getSchema = () => {
        if (!this.#schema) {
            this.#schema = this.#editor?.ctx.get(schemaCtx);
        }
        return this.#schema;
    };
    getSerializer = () => {
        if (!this.#serializer) {
            this.#serializer = this.#editor?.ctx.get(serializerCtx);
        }
        return this.#serializer;
    };
}
