1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | const __chunk_1 = require('./stencilrouter-a3d77a87.js');
|
6 | const __chunk_2 = require('./chunk-94c92d88.js');
|
7 | const __chunk_3 = require('./chunk-b786ea51.js');
|
8 | require('./chunk-e6311a56.js');
|
9 | const __chunk_5 = require('./chunk-b9bd6b52.js');
|
10 |
|
11 | const getUrl = (url, root) => {
|
12 |
|
13 | if (url.charAt(0) == '/' && root.charAt(root.length - 1) == '/') {
|
14 | return root.slice(0, root.length - 1) + url;
|
15 | }
|
16 | return root + url;
|
17 | };
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | class RouteLink {
|
24 | constructor(hostRef) {
|
25 | __chunk_1.registerInstance(this, hostRef);
|
26 | this.unsubscribe = () => { return; };
|
27 | this.activeClass = 'link-active';
|
28 | this.exact = false;
|
29 | this.strict = true;
|
30 | |
31 |
|
32 |
|
33 | this.custom = 'a';
|
34 | this.match = null;
|
35 | }
|
36 | componentWillLoad() {
|
37 | this.computeMatch();
|
38 | }
|
39 |
|
40 | computeMatch() {
|
41 | if (this.location) {
|
42 | this.match = __chunk_3.matchPath(this.location.pathname, {
|
43 | path: this.urlMatch || this.url,
|
44 | exact: this.exact,
|
45 | strict: this.strict
|
46 | });
|
47 | }
|
48 | }
|
49 | handleClick(e) {
|
50 | if (__chunk_5.isModifiedEvent(e) || !this.history || !this.url || !this.root) {
|
51 | return;
|
52 | }
|
53 | e.preventDefault();
|
54 | return this.history.push(getUrl(this.url, this.root));
|
55 | }
|
56 |
|
57 | render() {
|
58 | let anchorAttributes = {
|
59 | class: {
|
60 | [this.activeClass]: this.match !== null,
|
61 | },
|
62 | onClick: this.handleClick.bind(this)
|
63 | };
|
64 | if (this.anchorClass) {
|
65 | anchorAttributes.class[this.anchorClass] = true;
|
66 | }
|
67 | if (this.custom === 'a') {
|
68 | anchorAttributes = Object.assign({}, anchorAttributes, { href: this.url, title: this.anchorTitle, role: this.anchorRole, tabindex: this.anchorTabIndex, 'aria-haspopup': this.ariaHaspopup, id: this.anchorId, 'aria-posinset': this.ariaPosinset, 'aria-setsize': this.ariaSetsize, 'aria-label': this.ariaLabel });
|
69 | }
|
70 | return (__chunk_1.h(this.custom, Object.assign({}, anchorAttributes), __chunk_1.h("slot", null)));
|
71 | }
|
72 | get el() { return __chunk_1.getElement(this); }
|
73 | static get watchers() { return {
|
74 | "location": ["computeMatch"]
|
75 | }; }
|
76 | }
|
77 | __chunk_2.ActiveRouter.injectProps(RouteLink, [
|
78 | 'history',
|
79 | 'location',
|
80 | 'root'
|
81 | ]);
|
82 |
|
83 | exports.stencil_route_link = RouteLink;
|