System.register(["@stratusjs/runtime/stratus", "lodash", "quill"], function (exports_1, context_1) {
    "use strict";
    var stratus_1, lodash_1, quill_1, QuillInputButtonPlugin;
    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 (quill_1_1) {
                quill_1 = quill_1_1;
            }
        ],
        execute: function () {
            QuillInputButtonPlugin = class QuillInputButtonPlugin {
                constructor(quill, options) {
                    this.debug = false;
                    this.buttonHTML = '<i class="fas fa-carrot"></i>';
                    this.buttonTitle = 'Input Button';
                    this.name = 'inputButton';
                    this.eventName = 'input-button';
                    this.uid = lodash_1.default.uniqueId(`quill_input_button_`);
                    stratus_1.Stratus.Instances[this.uid] = this;
                    this.debug = options && options.debug;
                    if (!options || typeof options !== 'object') {
                        options = {};
                    }
                    this.buttonHTML = options.buttonHTML || this.buttonHTML;
                    this.buttonTitle = options.buttonTitle || this.buttonTitle;
                    this.name = options.name || this.name;
                    this.eventName = options.eventName || this.eventName;
                    this.createToolbarModule(quill);
                }
                createToolbarModule(quill) {
                    const toolbarModule = quill.getModule('toolbar');
                    if (!toolbarModule) {
                        throw new Error(`quill.${this.name} requires the "toolbar" module`);
                    }
                    this.registerDivModule();
                    const toolbarEl = toolbarModule.container;
                    const buttonContainer = document.createElement('span');
                    buttonContainer.setAttribute('class', 'ql-formats');
                    const button = document.createElement('button');
                    button.innerHTML = this.buttonHTML;
                    button.title = this.buttonTitle;
                    button.onclick = (e) => {
                        e.preventDefault();
                        this.onClick(quill);
                    };
                    buttonContainer.appendChild(button);
                    toolbarEl.appendChild(buttonContainer);
                }
                registerDivModule() {
                    const Block = quill_1.default.import('blots/block');
                    class Div extends Block {
                    }
                    Div.tagName = 'div';
                    Div.blotName = 'div';
                    Div.allowedChildren = Block.allowedChildren;
                    Div.allowedChildren.push(Block);
                    quill_1.default.register(Div);
                }
                findUID(el) {
                    if ('uid' in el.dataset) {
                        return el.dataset.uid;
                    }
                    return this.findUID(el.parentElement);
                }
                getInstance(uid) {
                    if (!(uid in stratus_1.Stratus.Instances)) {
                        return undefined;
                    }
                    return stratus_1.Stratus.Instances[uid];
                }
                onClick(quill) {
                    const container = quill.container;
                    const uid = this.findUID(container);
                    const instance = this.getInstance(uid);
                    if (!instance) {
                        return;
                    }
                    instance.trigger(this.eventName, null, this);
                }
                trigger(name, data, callee) {
                    if (this.debug) {
                        console.log(`quill.${this.name}.trigger:`, name, data, callee);
                    }
                }
            };
            exports_1("QuillInputButtonPlugin", QuillInputButtonPlugin);
        }
    };
});

//# sourceMappingURL=quill-input-button.plugin.js.map
