UNPKG

@haxtheweb/haxcms-nodejs

Version:

HAXcms single and multisite nodejs server, api, and administration

10 lines 5.53 kB
/** @license Copyright (c) 2017 The Polymer Project Authors. All rights reserved. This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as part of the polymer project is also subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt */ import{PolymerElement as t}from"../../polymer-element.js";import{Debouncer as e}from"../utils/debounce.js";import{enqueueDebouncer as s,flush as n}from"../utils/flush.js";import{microTask as i}from"../utils/async.js";import{root as _}from"../utils/path.js";import{wrap as r}from"../utils/wrap.js";import{hideElementsGlobally as o}from"../utils/hide-template-controls.js";import{fastDomIf as a,strictTemplatePolicy as h,suppressTemplateNotifications as c}from"../utils/settings.js";import{showHideChildren as l,templatize as d}from"../utils/templatize.js";class DomIfBase extends t{static get is(){return"dom-if"}static get template(){return null}static get properties(){return{if:{type:Boolean,observer:"__debounceRender"},restamp:{type:Boolean,observer:"__debounceRender"},notifyDomChange:{type:Boolean}}}constructor(){super(),this.__renderDebouncer=null,this._lastIf=!1,this.__hideTemplateChildren__=!1,this.__template,this._templateInfo}__debounceRender(){this.__renderDebouncer=e.debounce(this.__renderDebouncer,i,(()=>this.__render())),s(this.__renderDebouncer)}disconnectedCallback(){super.disconnectedCallback();const t=r(this).parentNode;t&&(t.nodeType!=Node.DOCUMENT_FRAGMENT_NODE||r(t).host)||this.__teardownInstance()}connectedCallback(){super.connectedCallback(),o()||(this.style.display="none"),this.if&&this.__debounceRender()}__ensureTemplate(){if(!this.__template){const t=this;let e=t._templateInfo?t:r(t).querySelector("template");if(!e){let t=new MutationObserver((()=>{if(!r(this).querySelector("template"))throw new Error("dom-if requires a <template> child");t.disconnect(),this.__render()}));return t.observe(this,{childList:!0}),!1}this.__template=e}return!0}__ensureInstance(){let t=r(this).parentNode;if(this.__hasInstance()){let e=this.__getInstanceNodes();if(e&&e.length){if(r(this).previousSibling!==e[e.length-1])for(let s,n=0;n<e.length&&(s=e[n]);n++)r(t).insertBefore(s,this)}}else{if(!t)return!1;if(!this.__ensureTemplate())return!1;this.__createAndInsertInstance(t)}return!0}render(){n()}__render(){if(this.if){if(!this.__ensureInstance())return}else this.restamp&&this.__teardownInstance();this._showHideChildren(),c&&!this.notifyDomChange||this.if==this._lastIf||(this.dispatchEvent(new CustomEvent("dom-change",{bubbles:!0,composed:!0})),this._lastIf=this.if)}__hasInstance(){}__getInstanceNodes(){}__createAndInsertInstance(t){}__teardownInstance(){}_showHideChildren(){}}export const DomIf=a?class DomIfFast extends DomIfBase{constructor(){super(),this.__instance=null,this.__syncInfo=null}__hasInstance(){return Boolean(this.__instance)}__getInstanceNodes(){return this.__instance.templateInfo.childNodes}__createAndInsertInstance(t){const e=this.__dataHost||this;if(h&&!this.__dataHost)throw new Error("strictTemplatePolicy: template owner not trusted");const s=e._bindTemplate(this.__template,!0);s.runEffects=(t,e,s)=>{let n=this.__syncInfo;if(this.if)n&&(this.__syncInfo=null,this._showHideChildren(),e=Object.assign(n.changedProps,e)),t(e,s);else if(this.__instance)if(n||(n=this.__syncInfo={runEffects:t,changedProps:{}}),s)for(const t in e){const e=_(t);n.changedProps[e]=this.__dataHost[e]}else Object.assign(n.changedProps,e)},this.__instance=e._stampTemplate(this.__template,s),r(t).insertBefore(this.__instance,this)}__syncHostProperties(){const t=this.__syncInfo;t&&(this.__syncInfo=null,t.runEffects(t.changedProps,!1))}__teardownInstance(){const t=this.__dataHost||this;this.__instance&&(t._removeBoundDom(this.__instance),this.__instance=null,this.__syncInfo=null)}_showHideChildren(){const t=this.__hideTemplateChildren__||!this.if;this.__instance&&Boolean(this.__instance.__hidden)!==t&&(this.__instance.__hidden=t,l(t,this.__instance.templateInfo.childNodes)),t||this.__syncHostProperties()}}:class DomIfLegacy extends DomIfBase{constructor(){super(),this.__ctor=null,this.__instance=null,this.__invalidProps=null}__hasInstance(){return Boolean(this.__instance)}__getInstanceNodes(){return this.__instance.children}__createAndInsertInstance(t){this.__ctor||(this.__ctor=d(this.__template,this,{mutableData:!0,forwardHostProp:function(t,e){this.__instance&&(this.if?this.__instance.forwardHostProp(t,e):(this.__invalidProps=this.__invalidProps||Object.create(null),this.__invalidProps[_(t)]=!0))}})),this.__instance=new this.__ctor,r(t).insertBefore(this.__instance.root,this)}__teardownInstance(){if(this.__instance){let t=this.__instance.children;if(t&&t.length){let e=r(t[0]).parentNode;if(e){e=r(e);for(let s,n=0;n<t.length&&(s=t[n]);n++)e.removeChild(s)}}this.__invalidProps=null,this.__instance=null}}__syncHostProperties(){let t=this.__invalidProps;if(t){this.__invalidProps=null;for(let e in t)this.__instance._setPendingProperty(e,this.__dataHost[e]);this.__instance._flushProperties()}}_showHideChildren(){const t=this.__hideTemplateChildren__||!this.if;this.__instance&&Boolean(this.__instance.__hidden)!==t&&(this.__instance.__hidden=t,this.__instance._showHideChildren(t)),t||this.__syncHostProperties()}};customElements.define(DomIf.is,DomIf);