@nent/core
Version:
74 lines (69 loc) • 2.31 kB
JavaScript
/*!
* NENT 2022
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
const index = require('./index-1829aebc.js');
const index$1 = require('./index-637e8c28.js');
const interfaces = require('./interfaces-1da33056.js');
const state = require('./state-246c735d.js');
require('./index-96f3ab3f.js');
const ViewLinkBack = class {
constructor(hostRef) {
index.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.state.router) {
await this.setupRoute();
}
else {
const dispose = state.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 {
this.subscribe();
}
}
async setPage(route) {
var _a;
this.route = await route.getPreviousRoute();
this.title = await ((_a = this.route) === null || _a === void 0 ? void 0 : _a.resolvePageTitle());
}
async subscribe() {
var _a, _b;
this.matchSubscription = index$1.eventBus.on(interfaces.ROUTE_EVENTS.RouteMatchedExact, async ({ route }) => {
await this.setPage(route);
});
if ((_a = state.state.router) === null || _a === void 0 ? void 0 : _a.exactRoute)
await this.setPage((_b = state.state.router) === null || _b === void 0 ? void 0 : _b.exactRoute);
}
render() {
var _a;
const text = this.text || this.title;
return (index.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" }, index.h("slot", { name: "start" }), text ? text : index.h("slot", null), index.h("slot", { name: "end" })));
}
disconnectedCallback() {
var _a;
(_a = this.matchSubscription) === null || _a === void 0 ? void 0 : _a.call(this);
}
get el() { return index.getElement(this); }
};
ViewLinkBack.style = "n-view-link-back { display: inline-block; }";
exports.n_view_link_back = ViewLinkBack;