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.

63 lines (58 loc) 1.84 kB
/*! * NENT 2022 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const index = require('./index-1829aebc.js'); const state = require('./state-246c735d.js'); require('./index-96f3ab3f.js'); const ViewDetect = class { constructor(hostRef) { index.registerInstance(this, hostRef); /** * Only active on the exact href match, * and not on child routes */ this.exact = false; /** * Only active on the exact href match * using every aspect of the URL including * parameters. */ this.strict = true; } get parentUrl() { var _a, _b; return (((_a = this.el.closest('n-view-prompt')) === null || _a === void 0 ? void 0 : _a.path) || ((_b = this.el.closest('n-view')) === null || _b === void 0 ? void 0 : _b.path)); } checkRoutingState() { if (!state.state || !state.state.router) return; this.route = state.state.router.resolvePathname(this.route, this.parentUrl || '/'); if (this.routeMatch) { this.routeMatch = new RegExp(this.routeMatch, !this.strict ? 'i' : undefined); } const match = state.state.router.matchPath({ path: this.routeMatch != null ? this.routeMatch : this.route, exact: this.exact, strict: this.strict, }); this.match = match ? Object.assign({}, match) : null; } componentWillLoad() { this.checkRoutingState(); this.routeSubscription = state.onChange('location', () => { this.checkRoutingState(); }); } render() { return this.match ? (index.h("slot", { name: "active" })) : (index.h("slot", { name: "inactive" })); } disconnectedCallback() { var _a; (_a = this.routeSubscription) === null || _a === void 0 ? void 0 : _a.call(this); } get el() { return index.getElement(this); } }; exports.n_view_detect = ViewDetect;