import { BehaviorSubject } from 'rxjs';
import { Log } from '../../../json-crdt/log/Log';
import { DomController } from '../dom/DomController';
export class PeritextSurfaceState {
    events;
    plugins;
    peritext;
    dom;
    log;
    render$ = new BehaviorSubject(0);
    /** Overlay portal container element. */
    portalEl = void 0;
    rerender = () => {
        const { peritext, render$ } = this;
        peritext.refresh();
        render$.next(render$.getValue() + 1);
    };
    constructor(events, plugins) {
        this.events = events;
        this.plugins = plugins;
        const peritext = (this.peritext = events.txt);
        const log = (this.log = Log.from(peritext.model));
        this.dom = new DomController(events, log);
    }
    /** -------------------------------------------------- {@link UiLifeCycles} */
    el;
    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);
        };
    }
}
//# sourceMappingURL=index.js.map