@nent/core
Version:
4 lines • 2.19 kB
JavaScript
/*!
* NENT 2022
*/
import{r as t,h as s,a as i,H as e}from"./index-916ca544.js";import{b as r,r as n}from"./remote-0f753d9a.js";import{r as o}from"./elements-1b845a48.js";import{D as a}from"./interfaces-8c5cd1b8.js";import{f as c}from"./jsonata.worker-8bcb5e74.js";import{R as l}from"./interfaces-3b78db83.js";import{s as m}from"./state-adf07580.js";import{C as h}from"./state-subscriber-eb44164a.js";import{a as d}from"./state-27a8a5bc.js";import{f,w as u}from"./logging-5a93c8af.js";import"./tokens-78f8cdbe.js";import"./factory-acbf0d3d.js";import"./index-f7016b94.js";import"./index-4bfabbbd.js";import"./values-ddfac998.js";import"./promises-584c4ece.js";import"./expressions-2c27c47c.js";import"./strings-47d55561.js";const p=class{constructor(s){t(this,s),this.contentClass="remote-content",this.contentElement=null,this.mode="cors",this.resolveTokens=!1,this.deferLoad=!1}componentWillLoad(){(this.resolveTokens||null!=this.when)&&(this.dataSubscription=new h(this,"dataEnabled",a.DataChanged),this.routeSubscription=new h(this,"routingEnabled",l.RouteChanged))}async componentWillRender(){let t=!this.deferLoad;if(d.dataEnabled&&this.when){const{evaluatePredicate:s}=await import("./expressions-2c27c47c.js").then((function(t){return t.f}));t=await s(this.when)}t?this.contentElement=this.src?await this.resolveContentElement():null:this.resolveTokens&&(this.contentElement=null)}async resolveContentElement(){var t;try{let s=await r(window,this.src,this.mode,this.resolveTokens);if(s&&this.json){f(d.debug,`n-content-include: filtering: ${this.json}`);const t=JSON.parse(s);s=await c(this.json,t)}if(null==s)return null;const i=document.createElement("div");return i.innerHTML=s,i.className=this.contentClass,d.elementsEnabled&&o(i),null===(t=m.router)||void 0===t||t.captureInnerLinks(i),i}catch(t){return u(`n-content: unable to retrieve from ${this.src}`),null}}render(){return n(this.el,`.${this.contentClass}`,this.contentElement),s(e,{hidden:null==this.contentElement})}disconnectedCallback(){var t,s;null===(t=this.dataSubscription)||void 0===t||t.destroy(),null===(s=this.routeSubscription)||void 0===s||s.destroy()}get el(){return i(this)}};export{p as n_content_include}