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.

74 lines (69 loc) 2.33 kB
/*! * NENT 2022 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const index = require('./index-1829aebc.js'); const index$1 = require('./index-637e8c28.js'); const interfaces = require('./interfaces-1da33056.js'); const state = require('./state-246c735d.js'); require('./index-96f3ab3f.js'); const ViewLinkNext = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.route = null; } get parentView() { return this.el.closest('n-view'); } get parentViewPrompt() { return this.el.closest('n-view-prompt'); } async componentWillLoad() { if (state.state.router) { await this.setupRoute(); } else { const dispose = state.onChange('router', async () => { await this.setupRoute(); dispose(); }); } } async setupRoute() { if (this.parentViewPrompt) { this.setPage(this.parentViewPrompt.route); } else if (this.parentView) { this.setPage(this.parentView.route); } else { await this.subscribe(); } } async setPage(route) { var _a; this.route = await route.getNextRoute(); this.title = await ((_a = this.route) === null || _a === void 0 ? void 0 : _a.resolvePageTitle()); } async subscribe() { var _a, _b; this.matchSubscription = index$1.eventBus.on(interfaces.ROUTE_EVENTS.RouteMatchedExact, async ({ route }) => { await this.setPage(route); }); if ((_a = state.state.router) === null || _a === void 0 ? void 0 : _a.exactRoute) await this.setPage((_b = state.state.router) === null || _b === void 0 ? void 0 : _b.exactRoute); } render() { var _a; const text = this.text || this.title; return (index.h("n-view-link", { "link-class": this.linkClass, path: ((_a = this.route) === null || _a === void 0 ? void 0 : _a.path) || '', title: this.title, "active-class": "none", validate: true }, index.h("slot", { name: "start" }), text ? text : index.h("slot", null), index.h("slot", { name: "end" }))); } disconnectedCallback() { var _a; (_a = this.matchSubscription) === null || _a === void 0 ? void 0 : _a.call(this); } get el() { return index.getElement(this); } }; ViewLinkNext.style = "n-view-link-next { display: inline-block; }"; exports.n_view_link_next = ViewLinkNext;