@nent/core
Version:
92 lines (88 loc) • 2.95 kB
JavaScript
/*!
* NENT 2022
*/
import { proxyCustomElement, HTMLElement, forceUpdate, h, Host } from '@stencil/core/internal/client';
import { R as ROUTE_EVENTS } from './interfaces4.js';
import { s as state } from './state4.js';
const ViewNotFound = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
constructor() {
super();
this.__registerHost();
this.__attachShadow();
/**
* The title for this view. This is prefixed
* before the app title configured in n-views
*
*/
this.pageTitle = 'Not Found';
/**
* Header height or offset for scroll-top on this
* view.
*/
this.scrollTopOffset = 0;
}
async setPageTags(router) {
if (router.hasExactRoute())
return;
await router.setPageTags({
title: this.pageTitle,
robots: 'nofollow',
});
router.scrollTo(this.scrollTopOffset);
}
componentWillLoad() {
const { router } = state;
if (!router) {
return;
}
this.transition = this.transition || (router === null || router === void 0 ? void 0 : router.transition);
this.routeChangeStartSubscription = router.eventBus.on(ROUTE_EVENTS.RouteChanged, async () => {
forceUpdate(this);
await this.setPageTags(router);
});
this.routeMatchedSubscription = router.eventBus.on(ROUTE_EVENTS.RouteMatchedExact, async () => {
forceUpdate(this);
await this.setPageTags(router);
});
this.routeFinalizeSubscription = router.eventBus.on(ROUTE_EVENTS.RouteChangeFinish, async () => {
await this.setPageTags(router);
forceUpdate(this);
});
}
render() {
var _a;
const hide = ((_a = state.router) === null || _a === void 0 ? void 0 : _a.hasExactRoute()) || false;
return (h(Host, { hidden: hide, class: this.transition }, h("slot", null)));
}
async componentDidLoad() {
await this.setPageTags(state.router);
}
disconnectedCallback() {
var _a, _b, _c;
(_a = this.routeChangeStartSubscription) === null || _a === void 0 ? void 0 : _a.call(this);
(_b = this.routeMatchedSubscription) === null || _b === void 0 ? void 0 : _b.call(this);
(_c = this.routeFinalizeSubscription) === null || _c === void 0 ? void 0 : _c.call(this);
}
get el() { return this; }
static get style() { return ":host { display: block; }"; }
}, [1, "n-view-not-found", {
"pageTitle": [1, "page-title"],
"scrollTopOffset": [2, "scroll-top-offset"],
"transition": [1025]
}]);
function defineCustomElement$1() {
if (typeof customElements === "undefined") {
return;
}
const components = ["n-view-not-found"];
components.forEach(tagName => { switch (tagName) {
case "n-view-not-found":
if (!customElements.get(tagName)) {
customElements.define(tagName, ViewNotFound);
}
break;
} });
}
const NViewNotFound = ViewNotFound;
const defineCustomElement = defineCustomElement$1;
export { NViewNotFound, defineCustomElement };