@nent/core
Version:
70 lines (67 loc) • 2.24 kB
JavaScript
/*!
* NENT 2022
*/
import { r as registerInstance, h, a as getElement } from './index-916ca544.js';
import { e as eventBus } from './index-f7016b94.js';
import { R as ROUTE_EVENTS } from './interfaces-3b78db83.js';
import { s as state, o as onChange } from './state-adf07580.js';
import './index-4bfabbbd.js';
const ViewLinkNext = class {
constructor(hostRef) {
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.router) {
await this.setupRoute();
}
else {
const dispose = 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 = eventBus.on(ROUTE_EVENTS.RouteMatchedExact, async ({ route }) => {
await this.setPage(route);
});
if ((_a = state.router) === null || _a === void 0 ? void 0 : _a.exactRoute)
await this.setPage((_b = state.router) === null || _b === void 0 ? void 0 : _b.exactRoute);
}
render() {
var _a;
const text = this.text || this.title;
return (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 }, h("slot", { name: "start" }), text ? text : h("slot", null), h("slot", { name: "end" })));
}
disconnectedCallback() {
var _a;
(_a = this.matchSubscription) === null || _a === void 0 ? void 0 : _a.call(this);
}
get el() { return getElement(this); }
};
ViewLinkNext.style = "n-view-link-next { display: inline-block; }";
export { ViewLinkNext as n_view_link_next };