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.

82 lines (78 loc) 2.38 kB
/*! * NENT 2022 */ import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client'; import { s as state, o as onChange } from './state4.js'; const ViewDetect = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement { constructor() { super(); this.__registerHost(); this.__attachShadow(); /** * 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 this; } }, [1, "n-view-detect", { "route": [1025], "routeMatch": [1025, "route-match"], "exact": [4], "strict": [4], "match": [32] }]); function defineCustomElement$1() { if (typeof customElements === "undefined") { return; } const components = ["n-view-detect"]; components.forEach(tagName => { switch (tagName) { case "n-view-detect": if (!customElements.get(tagName)) { customElements.define(tagName, ViewDetect); } break; } }); } const NViewDetect = ViewDetect; const defineCustomElement = defineCustomElement$1; export { NViewDetect, defineCustomElement };