define(["require", "exports", "wed"], function (require, exports, wed_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const { isElement, isText } = wed_1.domtypeguards;
    /**
     * A decorator for the generic mode.
     */
    class GenericDecorator extends wed_1.Decorator {
        /**
         * @param mode The mode object.
         *
         * @param editor The wed editor to which the mode is applied.
         *
         * @param metadata Meta-information about the schema.
         *
         * @param options The options object passed to the mode which uses this
         * decorator.
         *
         */
        // tslint:disable-next-line:no-any
        constructor(mode, editor, metadata, 
        // tslint:disable-next-line:no-any
        options) {
            super(mode, editor);
            this.metadata = metadata;
            this.options = options;
        }
        addHandlers() {
            this.domlistener.addHandler("included-element", wed_1.util.classFromOriginalName("*", {}), (root, _tree, _parent, _prev, _next, el) => {
                // Skip elements which would already have been removed from the
                // tree. Unlikely but...
                if (!root.contains(el)) {
                    return;
                }
                this.elementDecorator(root, el);
                const klass = this.getAdditionalClasses(el);
                if (klass.length > 0) {
                    el.className += ` ${klass}`;
                }
            });
            this.domlistener.addHandler("children-changed", wed_1.util.classFromOriginalName("*", {}), (root, added, removed, _previousSibling, _nextSibling, el) => {
                for (const child of added.concat(removed)) {
                    if (isText(child) || (isElement(child) &&
                        (child.classList.contains("_real") ||
                            child.classList.contains("_phantom_wrap")))) {
                        this.elementDecorator(root, el);
                        break;
                    }
                }
            });
            this.domlistener.addHandler("text-changed", wed_1.util.classFromOriginalName("*", {}), (root, node) => {
                this.elementDecorator(root, node.parentNode);
            });
            this.domlistener.addHandler("attribute-changed", wed_1.util.classFromOriginalName("*", {}), (root, el) => {
                this.elementDecorator(root, el);
            });
        }
        elementDecorator(root, el) {
            super.elementDecorator(root, el, 1, this.contextMenuHandler.bind(this, true), this.contextMenuHandler.bind(this, false));
        }
        /**
         * Returns additional classes that should apply to a node.
         *
         * @param node The node to check.
         *
         * @returns A string that contains all the class names separated by spaces. In
         * other words, a string that could be put as the value of the ``class``
         * attribute in an HTML tree.
         */
        getAdditionalClasses(node) {
            const ret = [];
            if (this.metadata.isInline(node)) {
                ret.push("_inline");
            }
            return ret.join(" ");
        }
    }
    exports.GenericDecorator = GenericDecorator;
});
//  LocalWords:  Dubeau MPL Mangalam util klass
//# sourceMappingURL=generic-decorator.js.map