"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PeritextSurfaceState = void 0;
const rxjs_1 = require("rxjs");
const Log_1 = require("../../../json-crdt/log/Log");
const DomController_1 = require("../dom/DomController");
class PeritextSurfaceState {
    constructor(events, plugins) {
        this.events = events;
        this.plugins = plugins;
        this.render$ = new rxjs_1.BehaviorSubject(0);
        /** Overlay portal container element. */
        this.portalEl = void 0;
        this.rerender = () => {
            const { peritext, render$ } = this;
            peritext.refresh();
            render$.next(render$.getValue() + 1);
        };
        const peritext = (this.peritext = events.txt);
        const log = (this.log = Log_1.Log.from(peritext.model));
        this.dom = new DomController_1.DomController(events, log);
    }
    start() {
        const { dom, rerender, el } = this;
        dom.el = el;
        const stopDom = dom.start();
        const et = dom.et;
        et.addEventListener('change', rerender);
        return () => {
            this.log.destroy();
            stopDom();
            et.removeEventListener('change', rerender);
        };
    }
}
exports.PeritextSurfaceState = PeritextSurfaceState;
//# sourceMappingURL=index.js.map