UNPKG

@nent/core

Version:

Functional elements to add routing, data-binding, dynamic HTML, declarative actions, audio, video, and so much more. Supercharge static HTML files into web apps without script or builds.

106 lines (101 loc) 3.87 kB
/*! * NENT 2022 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const index = require('./index-1829aebc.js'); const remote = require('./remote-d40ac61b.js'); const elements = require('./elements-87859bcf.js'); const interfaces = require('./interfaces-95d0415a.js'); const jsonata_worker = require('./jsonata.worker-5efab898.js'); const interfaces$1 = require('./interfaces-1da33056.js'); const state$1 = require('./state-246c735d.js'); const stateSubscriber = require('./state-subscriber-0ded559f.js'); const state = require('./state-f97ff0e6.js'); const logging = require('./logging-37c154cf.js'); require('./tokens-4f8bcd42.js'); require('./factory-0d7ddff9.js'); require('./index-637e8c28.js'); require('./index-96f3ab3f.js'); require('./values-b2399e33.js'); require('./promises-463f4e01.js'); require('./expressions-531d82f5.js'); require('./strings-fe5a8e44.js'); const ContentInclude = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.contentClass = 'remote-content'; this.contentElement = null; /** * Cross Origin Mode */ this.mode = 'cors'; /** * Before rendering HTML, replace any data-tokens with their * resolved values. This also commands this element to * re-render it's HTML for data-changes. This can affect * performance. */ this.resolveTokens = false; /** * If set, disables auto-rendering of this instance. * To fetch the contents change to false or remove * attribute. */ this.deferLoad = false; } componentWillLoad() { if (this.resolveTokens || this.when != undefined) { this.dataSubscription = new stateSubscriber.CommonStateSubscriber(this, 'dataEnabled', interfaces.DATA_EVENTS.DataChanged); this.routeSubscription = new stateSubscriber.CommonStateSubscriber(this, 'routingEnabled', interfaces$1.ROUTE_EVENTS.RouteChanged); } } async componentWillRender() { let shouldRender = !this.deferLoad; if (state.state.dataEnabled && this.when) { const { evaluatePredicate } = await Promise.resolve().then(function () { return require('./expressions-531d82f5.js'); }).then(function (n) { return n.expressions; }); shouldRender = await evaluatePredicate(this.when); } if (shouldRender) this.contentElement = this.src ? await this.resolveContentElement() : null; else if (this.resolveTokens) this.contentElement = null; } async resolveContentElement() { var _a; try { let content = await remote.resolveRemoteContent(window, this.src, this.mode, this.resolveTokens); if (content && this.json) { logging.debugIf(state.state.debug, `n-content-include: filtering: ${this.json}`); const data = JSON.parse(content); content = await jsonata_worker.filterData(this.json, data); } if (content == null) return null; const div = document.createElement('div'); div.innerHTML = content; div.className = this.contentClass; if (state.state.elementsEnabled) elements.resolveChildElementXAttributes(div); (_a = state$1.state.router) === null || _a === void 0 ? void 0 : _a.captureInnerLinks(div); return div; } catch (_b) { logging.warn(`n-content: unable to retrieve from ${this.src}`); return null; } } render() { remote.replaceHtmlInElement(this.el, `.${this.contentClass}`, this.contentElement); return index.h(index.Host, { hidden: this.contentElement == null }); } disconnectedCallback() { var _a, _b; (_a = this.dataSubscription) === null || _a === void 0 ? void 0 : _a.destroy(); (_b = this.routeSubscription) === null || _b === void 0 ? void 0 : _b.destroy(); } get el() { return index.getElement(this); } }; exports.n_content_include = ContentInclude;