UNPKG

@haxtheweb/haxcms-nodejs

Version:

HAXcms single and multisite nodejs server, api, and administration

10 lines 6.63 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"./boot.js";import{PropertyEffects as t}from"../mixins/property-effects.js";import{MutableData as e}from"../mixins/mutable-data.js";import{strictTemplatePolicy as o,legacyWarnings as n}from"./settings.js";import{wrap as s}from"./wrap.js";let a=null;function HTMLTemplateElementExtension(){return a}HTMLTemplateElementExtension.prototype=Object.create(HTMLTemplateElement.prototype,{constructor:{value:HTMLTemplateElementExtension,writable:!0}});const r=t(HTMLTemplateElementExtension),p=e(r);const i=t(class{});export function showHideChildren(t,e){for(let o=0;o<e.length;o++){let n=e[o];if(Boolean(t)!=Boolean(n.__hideTemplateChildren__))if(n.nodeType===Node.TEXT_NODE)t?(n.__polymerTextContent__=n.textContent,n.textContent=""):n.textContent=n.__polymerTextContent__;else if("slot"===n.localName)if(t)n.__polymerReplaced__=document.createComment("hidden-slot"),s(s(n).parentNode).replaceChild(n.__polymerReplaced__,n);else{const t=n.__polymerReplaced__;t&&s(s(t).parentNode).replaceChild(n,t)}else n.style&&(t?(n.__polymerDisplay__=n.style.display,n.style.display="none"):n.style.display=n.__polymerDisplay__);n.__hideTemplateChildren__=t,n._showHideChildren&&n._showHideChildren(t)}}class TemplateInstanceBase extends i{constructor(t){super(),this._configureProperties(t),this.root=this._stampTemplate(this.__dataHost);let e=[];this.children=e;for(let t=this.root.firstChild;t;t=t.nextSibling)e.push(t),t.__templatizeInstance=this;this.__templatizeOwner&&this.__templatizeOwner.__hideTemplateChildren__&&this._showHideChildren(!0);let o=this.__templatizeOptions;(t&&o.instanceProps||!o.instanceProps)&&this._enableProperties()}_configureProperties(t){if(this.__templatizeOptions.forwardHostProp)for(let t in this.__hostProps)this._setPendingProperty(t,this.__dataHost["_host_"+t]);for(let e in t)this._setPendingProperty(e,t[e])}forwardHostProp(t,e){this._setPendingPropertyOrPath(t,e,!1,!0)&&this.__dataHost._enqueueClient(this)}_addEventListenerToNode(t,e,o){if(this._methodHost&&this.__templatizeOptions.parentModel)this._methodHost._addEventListenerToNode(t,e,(t=>{t.model=this,o(t)}));else{let n=this.__dataHost.__dataHost;n&&n._addEventListenerToNode(t,e,o)}}_showHideChildren(t){showHideChildren(t,this.children)}_setUnmanagedPropertyToNode(t,e,o){t.__hideTemplateChildren__&&t.nodeType==Node.TEXT_NODE&&"textContent"==e?t.__polymerTextContent__=o:super._setUnmanagedPropertyToNode(t,e,o)}get parentModel(){let t=this.__parentModel;if(!t){let e;t=this;do{t=t.__dataHost.__dataHost}while((e=t.__templatizeOptions)&&!e.parentModel);this.__parentModel=t}return t}dispatchEvent(t){return!0}}TemplateInstanceBase.prototype.__dataHost,TemplateInstanceBase.prototype.__templatizeOptions,TemplateInstanceBase.prototype._methodHost,TemplateInstanceBase.prototype.__templatizeOwner,TemplateInstanceBase.prototype.__hostProps;const l=e(TemplateInstanceBase);function findMethodHost(t){let e=t.__dataHost;return e&&e._methodHost||e}function createTemplatizerClass(t,e,o){let n=o.mutableData?l:TemplateInstanceBase;templatize.mixin&&(n=templatize.mixin(n));let s=class extends n{};return s.prototype.__templatizeOptions=o,s.prototype._bindTemplate(t),function addNotifyEffects(t,e,o,n){let s=o.hostProps||{};for(let e in n.instanceProps){delete s[e];let o=n.notifyInstanceProp;o&&t.prototype._addPropertyEffect(e,t.prototype.PROPERTY_EFFECT_TYPES.NOTIFY,{fn:createNotifyInstancePropEffect(e,o)})}if(n.forwardHostProp&&e.__dataHost)for(let e in s)o.hasHostProps||(o.hasHostProps=!0),t.prototype._addPropertyEffect(e,t.prototype.PROPERTY_EFFECT_TYPES.NOTIFY,{fn:function notifyHostProp(t,e,o){t.__dataHost._setPendingPropertyOrPath("_host_"+e,o[e],!0,!0)}})}(s,t,e,o),s}function addPropagateEffects(t,e,o,s){let i=o.forwardHostProp;if(i&&e.hasHostProps){const l="template"==t.localName;let _=e.templatizeTemplateClass;if(!_){if(l){let t=o.mutableData?p:r;class TemplatizedTemplate extends t{}_=e.templatizeTemplateClass=TemplatizedTemplate}else{const o=t.constructor;class TemplatizedTemplateExtension extends o{}_=e.templatizeTemplateClass=TemplatizedTemplateExtension}let a=e.hostProps;for(let t in a)_.prototype._addPropertyEffect("_host_"+t,_.prototype.PROPERTY_EFFECT_TYPES.PROPAGATE,{fn:createForwardHostPropEffect(t,i)}),_.prototype._createNotifyingProperty("_host_"+t);n&&s&&function warnOnUndeclaredProperties(t,e,o){const n=o.constructor._properties,{propertyEffects:s}=t,{instanceProps:a}=e;for(let t in s)if(!(n[t]||a&&a[t])){const e=s[t];for(let o=0;o<e.length;o++){const{part:n}=e[o].info;if(!n.signature||!n.signature.static){console.warn(`Property '${t}' used in template but not declared in 'properties'; attribute will not be observed.`);break}}}}(e,o,s)}if(t.__dataProto&&Object.assign(t.__data,t.__dataProto),l)!function upgradeTemplate(t,e){a=t,Object.setPrototypeOf(t,e.prototype),new e,a=null}(t,_),t.__dataTemp={},t.__dataPending=null,t.__dataOld=null,t._enableProperties();else{Object.setPrototypeOf(t,_.prototype);const o=e.hostProps;for(let e in o)if(e="_host_"+e,e in t){const o=t[e];delete t[e],t.__data[e]=o}}}}function createForwardHostPropEffect(t,e){return function forwardHostProp(t,o,n){e.call(t.__templatizeOwner,o.substring(6),n[o])}}function createNotifyInstancePropEffect(t,e){return function notifyInstanceProp(t,o,n){e.call(t.__templatizeOwner,t,o,n[o])}}export function templatize(t,e,n){if(o&&!findMethodHost(t))throw new Error("strictTemplatePolicy: template owner not trusted");if(n=n||{},t.__templatizeOwner)throw new Error("A <template> can only be templatized once");t.__templatizeOwner=e;let s=(e?e.constructor:TemplateInstanceBase)._parseTemplate(t),a=s.templatizeInstanceClass;a||(a=createTemplatizerClass(t,s,n),s.templatizeInstanceClass=a);const r=findMethodHost(t);addPropagateEffects(t,s,n,r);let p=class TemplateInstance extends a{};return p.prototype._methodHost=r,p.prototype.__dataHost=t,p.prototype.__templatizeOwner=e,p.prototype.__hostProps=s.hostProps,p}export function modelForElement(t,e){let o;for(;e;)if(o=e.__dataHost?e:e.__templatizeInstance){if(o.__dataHost==t)return o;e=o.__dataHost}else e=s(e).parentNode;return null}export{TemplateInstanceBase};