UNPKG

iportal

Version:

web-portal

77 lines (72 loc) 2.81 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const nativeShim = function (shadowWindow) { if ( // No Reflect, no classes, no need for shim because native custom elements // require ES2015 classes or Reflect. shadowWindow.Reflect === undefined || shadowWindow.customElements === undefined || // The webcomponentsjs custom elements polyfill doesn't require // ES2015-compatible construction (`super()` or `Reflect.construct`). shadowWindow.customElements['polyfillWrapFlushCallback']) return; const BuiltInHTMLElement = shadowWindow.HTMLElement; /** * With jscompiler's RECOMMENDED_FLAGS the function name will be optimized away. * However, if we declare the function as a property on an object literal, and * use quotes for the property name, then closure will leave that much intact, * which is enough for the JS VM to correctly set Function.prototype.name. */ const wrapperForTheName = { 'HTMLElement': /** @this {!Object} */ function HTMLElement() { return shadowWindow.Reflect.construct(BuiltInHTMLElement, [], /** @type {!Function} */ (this.constructor)); } }; shadowWindow.HTMLElement = wrapperForTheName['HTMLElement']; shadowWindow.HTMLElement.prototype = BuiltInHTMLElement.prototype; shadowWindow.HTMLElement.prototype.constructor = shadowWindow.HTMLElement; shadowWindow.Object.setPrototypeOf(shadowWindow.HTMLElement, BuiltInHTMLElement); }; nativeShim(window); class Runaway extends HTMLElement { constructor() { super(); this.style.cssText = ` position: absolute; top: 0; right: 0; bottom: 0; left: 0; inset: 0; width: 100%; height: 100%; `; const tmpl = document.createElement('template'); tmpl.innerHTML = ` <slot name="module"></slot> `; const shadowRoot = this.attachShadow({ mode: 'open' }); shadowRoot.appendChild(tmpl.content.cloneNode(true)); } connectedCallback() { const id = this.id; if (id) { if (!window.__application_preset) { window.__application_preset = { modules: {} }; } else if (!window.__application_preset.modules) { window.__application_preset.modules = {}; } if (window.__application_preset.modules) { window.__application_preset.modules[id] = this; } } else { console.error('<run-away> required parameter id is missing!'); } } } customElements.define('run-away', Runaway); exports.Runaway = Runaway;