System.register(["@stratusjs/runtime/stratus", "lodash", "codemirror"], function (exports_1, context_1) {
    "use strict";
    var stratus_1, lodash_1, codemirror_1, CodeMirrorBridge;
    var __moduleName = context_1 && context_1.id;
    return {
        setters: [
            function (stratus_1_1) {
                stratus_1 = stratus_1_1;
            },
            function (lodash_1_1) {
                lodash_1 = lodash_1_1;
            },
            function (codemirror_1_1) {
                codemirror_1 = codemirror_1_1;
            }
        ],
        execute: function () {
            CodeMirrorBridge = class CodeMirrorBridge {
                constructor(opts) {
                    this.uid = lodash_1.uniqueId(`code_mirror_bridge_`);
                    stratus_1.Stratus.Instances[this.uid] = this;
                    if (!opts || !(typeof opts === 'object')) {
                        return;
                    }
                    this.extensions = opts.extensions;
                }
                fromTextArea(el, opts) {
                    this.dom = el;
                    this.editorView = new codemirror_1.EditorView({
                        doc: el.value,
                        extensions: this.extensions || [],
                    });
                    el.parentNode.insertBefore(this.editorView.dom, el);
                    el.style.display = 'none';
                    if (el.form)
                        el.form.addEventListener('submit', () => {
                            el.value = this.editorView.state.doc.toString();
                        });
                    return this;
                }
                focus() {
                    return this.editorView.focus();
                }
                refresh() {
                    console.warn('CodeMirror Bridge has not implemented a refresh function.');
                }
                clearHistory() {
                    console.warn('CodeMirror Bridge has not implemented a clearHistory function.');
                }
                on(event, func) {
                    this.editorView.contentDOM.addEventListener(event, func);
                }
                setSize(width, height) {
                    this.editorView.dom.style.width = width || '';
                    this.editorView.dom.style.height = height || '';
                }
                getValue() {
                    return this.editorView.state.doc.toString();
                }
                setValue(html) {
                    this.editorView.dispatch({
                        changes: { from: 0, to: this.editorView.state.doc.length, insert: html }
                    });
                }
                setSelection(start, end) {
                    const posToOffset = (pos) => {
                        const doc = this.editorView.state.doc;
                        return doc.line(pos.line + 1).from + pos.ch;
                    };
                    this.editorView.dispatch({
                        selection: {
                            anchor: posToOffset(start),
                            head: posToOffset(end)
                        }
                    });
                }
                toTextArea() {
                    this.editorView.destroy();
                }
            };
            exports_1("CodeMirrorBridge", CodeMirrorBridge);
        }
    };
});

//# sourceMappingURL=code-mirror-bridge.js.map
