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.

59 lines (56 loc) 1.77 kB
/*! * NENT 2022 */ import { r as registerInstance, h, a as getElement } from './index-916ca544.js'; import { s as state, o as onChange } from './state-adf07580.js'; import './index-4bfabbbd.js'; const ViewDetect = class { constructor(hostRef) { 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.router) return; this.route = state.router.resolvePathname(this.route, this.parentUrl || '/'); if (this.routeMatch) { this.routeMatch = new RegExp(this.routeMatch, !this.strict ? 'i' : undefined); } const match = 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 = onChange('location', () => { this.checkRoutingState(); }); } render() { return this.match ? (h("slot", { name: "active" })) : (h("slot", { name: "inactive" })); } disconnectedCallback() { var _a; (_a = this.routeSubscription) === null || _a === void 0 ? void 0 : _a.call(this); } get el() { return getElement(this); } }; export { ViewDetect as n_view_detect };