All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.frontend.uibuilder-dom-bind.uibuilder-dom-bind.js Maven / Gradle / Ivy

The newest version!
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import { GestureEventListeners } from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
import { PropertyEffects } from '@polymer/polymer/lib/mixins/property-effects.js';
import { OptionalMutableData } from '@polymer/polymer/lib/mixins/mutable-data.js';

class UIBuilderDomBind extends GestureEventListeners(OptionalMutableData(PropertyEffects(PolymerElement))) {

    static get is() {
        return "uibuilder-dom-bind";
    }

    static get properties() {
        return {};
    }

    static get observedAttributes() {
        return ['mutable-data'];
    }

    constructor() {
        super();
        this.root = null;
        this.$ = null;
        this.__children = null;
    }

    attributeChangedCallback() {
        this.mutableData = true;
    }

    connectedCallback() {
        this.style.display = 'none';
    }

    disconnectedCallback() {
        this.__removeChildren();
    }

    __insertChildren() {
        this.parentNode.insertBefore(this.root, this);
    }

    __removeChildren() {
        if (this.__children) {
            for (let i = 0; i < this.__children.length; i++) {
                this.root.appendChild(this.__children[i]);
            }
        }
    }

    render() {
        this._render(null);
    }

    _render(template) {
        if (!this.__children) {
            template = /** @type {HTMLTemplateElement} */(template || this.querySelector('template'));
            if (!template) {
                // Wait until childList changes and template should be there by then
                let observer = new MutationObserver(() => {
                    template = /** @type {HTMLTemplateElement} */(this.querySelector('template'));
                    if (template) {
                        observer.disconnect();
                        this.render();
                    } else {
                        throw new Error('dom-bind requires a