@glance-networks/agent-plugin
Version:
Glance Networks Agent Plugin
2 lines (1 loc) • 8.95 kB
JavaScript
"use strict";var t=Object.defineProperty,e=(e,o,r)=>(((e,o,r)=>{o in e?t(e,o,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[o]=r})(e,"symbol"!=typeof o?o+"":o,r),r);const o=require("./index.cjs");function r(t){const e={};for(const r in t)e[r]=[o(t[r])];function o(t){return function(){return{c:function(){},m:function(e,o){!function(t,e,o){t.insertBefore(e,o||null)}(e,t.cloneNode(!0),o)},d:function(e){var o;e&&(o=t).parentNode&&o.parentNode.removeChild(o)},l:function(){}}}}return e}function s(t){let e=t.parentElement;for(;e;){if(-1!==e.tagName.indexOf("-"))return e;e=e.parentElement}return null}function n(t){let e=document.createDocumentFragment();for(;t.firstChild;)e.appendChild(t.firstChild);return e}require("svelte/internal"),require("svelte");const i=new Map,a=new MutationObserver((t=>{t.forEach((t=>{const e=t.target,o=t.attributeName,r=e.getAttribute(o),s=t.target.propTypes,n=t.target.attributeParseTypes,i=s[o];s&&i?e.forwardAttributeToProp(o,n[i](r)):e.forwardAttributeToProp(o,r)}))}));function l(t){let e=document.querySelectorAll("[data-component-wrapper-render]");if(0!==e.length)for(let o of e)o.isConnected&&null===o.parentElement.closest('[data-component-wrapper-render="light"]')&&(o.removeAttribute("data-component-wrapper-render"),o._renderSvelteComponent())}var h;h={component:o.ComboTextField,tagname:"gds-combo-text-input",attributes:!0,propTypes:{disabled:"boolean",skeleton:"boolean",size:"string",label:"string",placeholder:"string",value:"string",id:"string",shape:"string",warn:"boolean",error:"boolean",errorMessage:"string",warnMessage:"string",helpMessage:"string",severityIcon:"boolean"},shadow:!0,href:"https://fonts.googleapis.com/css2?family=Fira+Code:wght@300..700&family=Inter:wght@100..900&display=swap"},window.customElements.get("component-wrapper")||(window.customElements.define("component-wrapper",class extends HTMLElement{}),window.customElements.define("component-wrapper-default",class extends HTMLElement{})),window.customElements.define(h.tagname,class extends HTMLElement{constructor(){if(super(),e(this,"attributeParseTypes",{string:t=>t,number:t=>parseFloat(t),boolean:t=>"true"===t,object:t=>JSON.parse(t),array:t=>JSON.parse(t),function:t=>new Function(`return ${t}`)()}),e(this,"propTypes",h.propTypes),this._debug("constructor()"),this.attributesObserved=!1,h.shadow&&(this.attachShadow({mode:"open"}),this._root=document.createElement("component-wrapper"),this.shadowRoot.appendChild(this._root),h.href)){let t=document.createElement("link");t.setAttribute("href",h.href),t.setAttribute("rel","stylesheet"),this.shadowRoot.appendChild(t)}}static get observedAttributes(){return Array.isArray(h.attributes)?h.attributes:[]}connectedCallback(){this._debug("connectedCallback()"),this.slotEls={};const t="loading"===document.readyState;if(!h.shadow)if(this.hasAttribute("data-component-wrapper-hydratable")){if(t)return void this._onSlotsReady((()=>{this._initLightRoot(),this._hydrateLightSlots(),this._queueForRender()}));this._initLightRoot(),this._hydrateLightSlots()}else this._initLightRoot();h.shadow?this._observeSlots(!0):t&&(this._observeSlots(!0),this._onSlotsReady((()=>{this._observeSlots(!1)}))),this._queueForRender(),h.hydratable&&this.setAttribute("data-component-wrapper-hydratable","")}disconnectedCallback(){if(this._debug("disconnectedCallback()"),this.removeAttribute("data-component-wrapper-render"),this.removeAttribute("data-component-wrapper-hydratable"),this._observeSlots(!1),this.componentInstance)try{this.componentInstance.$destroy(),delete this.componentInstance}catch(t){console.error(`Error destroying Svelte component in '${this.tagName}'s disconnectedCallback(): ${t}`)}h.shadow||(this._restoreLightSlots(),this.removeChild(this._root))}attributeChangedCallback(t,e,o){this._debug("attributes changed",{name:t,oldValue:e,newValue:o}),this.forwardAttributeToProp(t,o)}forwardAttributeToProp(t,e){if(this._debug("forwardAttributeToProp",{name:t,value:e}),this.componentInstance){let o=this._translateAttribute(t);this.componentInstance.$set({[o]:e})}}_initLightRoot(){let t=this.querySelector("component-wrapper");null!==t&&t.parentElement===this?(this._debug("_initLightRoot(): Restore from existing light DOM root"),this._root=t):(this._root=document.createElement("component-wrapper"),this.prepend(this._root))}_onSlotsReady(t){document.addEventListener("readystatechange",(()=>{"interactive"===document.readyState&&t()}))}_translateAttribute(t){return t=t.toLowerCase(),this.propMap&&this.propMap.has(t)?this.propMap.get(t):(this._debug(`_translateAttribute(): ${t} not found`),t)}_getAncestorContext(){var t,e;let o=this;for(;o.parentNode;){o=o.parentNode;let r=null==(e=null==(t=null==o?void 0:o.componentInstance)?void 0:t.$$)?void 0:e.context;if(r instanceof Map)return r}return null}_queueForRender(){this.isConnected?null===this.parentElement.closest('[data-component-wrapper-render="light"]')?(this.setAttribute("data-component-wrapper-render",h.shadow?"shadow":"light"),requestAnimationFrame(l)):this._debug("queueForRender(): skipped, light DOM parent is queued for render"):this._debug("queueForRender(): skipped, already disconnected")}_renderSvelteComponent(){this._debug("renderSvelteComponent()"),h.shadow?this.slotEls=this._getShadowSlots():this.slotEls=this._getLightSlots(),this._root.innerHTML="";const t=this._getAncestorContext()||new Map;let e={$$scope:{},$$slots:r(this.slotEls)};if(i.has(this.tagName)){this.propMap=i.get(this.tagName);for(let t of[...this.attributes])-1===t.name.indexOf("data-component-wrapper")&&(e[this._translateAttribute(t.name)]=t.value)}else this.propMap=new Map,i.set(this.tagName,this.propMap),e=new Proxy(e,{get:(t,e)=>{let o=e.toString();-1===e.indexOf("$$")&&this.propMap.set(o.toLowerCase(),o);let r=this.attributes.getNamedItem(o);if(null!==r){if(h.propTypes&&h.propTypes[o]){const e=h.propTypes[o];return t[o]=this.attributeParseTypes[e](r.value)}return t[o]=r.value}return t[e]}});this.componentInstance=new h.component({target:this._root,props:e,context:t}),!0!==h.attributes||this.attributesObserved||(this.attributesObserved=!0,this.propMap.size>0?a.observe(this,{attributes:!0,attributeFilter:[...this.propMap.keys()]}):this._debug("renderSvelteComponent(): skipped attribute observer, no props")),this._debug("renderSvelteComponent(): completed")}_hydrateLightSlots(){let t=this._root.querySelectorAll("[data-component-wrapper-slot]");for(let o of t){if(s(o)!==this._root)continue;let t=o.getAttribute("slot");this.slotEls[t]=o}let e=this.querySelector("component-wrapper-default");return null!==e&&(this.slotEls.default=e),this._restoreLightSlots(),!0}_isOwnSlot(t){let e=s(t);return null!==e&&e===this}_getLightSlots(){this._debug("_getLightSlots()");let t={};const e=this.querySelectorAll("[slot]");for(let n of e)this._isOwnSlot(n)&&(t[n.slot]=n,h.hydratable&&n.setAttribute("data-component-wrapper-slot",""),this.removeChild(n));let o=document.createDocumentFragment();h.hydratable&&(o=document.createElement("component-wrapper-default"));let r=[...this.childNodes],s="";for(let n of r)n instanceof HTMLElement&&"SVELTE-RETAG"===n.tagName?this._debug("_getLightSlots(): skipping <component-wrapper> container"):(n instanceof Text?s+=n.textContent:n.outerHTML&&(s+=n.outerHTML),o.appendChild(n));return""!==s.trim()&&(t.default?console.error(`svelteWrapper: '${this.tagName}': Found elements without slot attribute when using slot="default"`):t.default=o),t}_restoreLightSlots(){this._debug("_restoreLightSlots:",this.slotEls);for(let t in this.slotEls){let e=this.slotEls[t];"COMPONENT-WRAPPER-DEFAULT"===e.tagName?this.prepend(n(e)):(this.prepend(e),e instanceof HTMLElement&&e.hasAttribute("data-component-wrapper-slot")&&e.removeAttribute("data-component-wrapper-slot"))}this.slotEls={}}_getShadowSlots(){this._debug("_getShadowSlots()");const t=this.querySelectorAll("[slot]");let e={},o=this.innerHTML.length;return t.forEach((t=>{e[t.slot]=document.createElement("slot"),e[t.slot].setAttribute("name",t.slot),o-=t.outerHTML.length})),o>0&&(e.default=document.createElement("slot")),e}_observeSlots(t){t!==this.slotObserverActive&&(this.slotObserver||(this.slotObserver=new MutationObserver((t=>{this._processSlotMutations(t)}))),t?(this.slotObserver.observe(this,{childList:!0,subtree:!1,attributes:!1}),this._debug("_observeSlots: OBSERVE")):(this.slotObserver.disconnect(),this._debug("_observeSlots: DISCONNECT")),this.slotObserverActive=t)}_processSlotMutations(t){this._debug("_processSlotMutations()",t);let e=!1;for(let o of t)if("childList"===o.type){if(h.shadow){e=!0;break}if(o.addedNodes.length>0){e=!0;break}}e&&(h.shadow||(this._observeSlots(!1),this._restoreLightSlots(),this._observeSlots(!0)),this._debug("_processMutations(): Queue rerender"),this._queueForRender())}_debug(){h.debugMode&&("cli"===h.debugMode?console.log.apply(null,[performance.now(),this.tagName,...arguments]):console.log.apply(null,[performance.now(),this,...arguments]))}});