@exmg/exm-navigation 1.1.6-alpha.9 → 1.1.9-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,6 +43,11 @@ export declare class ExmNavigationBase extends ExmNavigationBase_base {
43
43
  */
44
44
  navigationHasSubmenu: Record<string, boolean>;
45
45
  static styles: import("lit").CSSResult[];
46
+ constructor();
47
+ /**
48
+ * Get the menu items and the current path and set the correct startPath for the navigation
49
+ */
50
+ private setPath;
46
51
  protected updated(changedProperties: PropertyValues): void;
47
52
  protected firstUpdated(changedProperties: PropertyValues): void;
48
53
  connectedCallback(): void;
@@ -17,7 +17,7 @@ import './exm-navigation-drawer.js';
17
17
  // eslint-disable-next-line new-cap
18
18
  export class ExmNavigationBase extends MediaQueries(ExmgElement) {
19
19
  constructor() {
20
- super(...arguments);
20
+ super();
21
21
  this.items = [];
22
22
  this.path = ['chat'];
23
23
  this.drawerWidth = 319;
@@ -43,6 +43,54 @@ export class ExmNavigationBase extends MediaQueries(ExmgElement) {
43
43
  * Object with menuitem and a bool for having that path sub items yes or no
44
44
  */
45
45
  this.navigationHasSubmenu = {};
46
+ /**
47
+ * Listen to popState changes. When the event has a state, the browser navigation buttons have been used and we have to update the path
48
+ */
49
+ window.addEventListener('popstate', (event) => {
50
+ if (event.state) {
51
+ this.setPath();
52
+ }
53
+ });
54
+ }
55
+ /**
56
+ * Get the menu items and the current path and set the correct startPath for the navigation
57
+ */
58
+ setPath() {
59
+ let path = [];
60
+ /**
61
+ * Set to true if we found the path. This is needed because for breaking out of a recursive function
62
+ */
63
+ let finished = false;
64
+ /**
65
+ * Loop through the items with a give depth. For every depth level the id of the route is set to that index
66
+ * If there is a matching path, we set finished to true, so all levels wil break out of their for-loop
67
+ * Every call done with depth 0 will reset the path, so no artifacts of the previous route will remain
68
+ *
69
+ * @param items The items to loop through
70
+ * @param depth The navigation depth
71
+ */
72
+ function checkItems(items, depth = 0) {
73
+ for (const item of items) {
74
+ if (finished) {
75
+ break;
76
+ }
77
+ if (depth === 0) {
78
+ path = [];
79
+ }
80
+ path[depth] = item.id;
81
+ if (item.path === window.location.pathname) {
82
+ finished = true;
83
+ break;
84
+ }
85
+ if ((item.items || []).length > 0) {
86
+ checkItems(item.items, depth + 1);
87
+ }
88
+ }
89
+ }
90
+ checkItems(this.items);
91
+ this.path = path;
92
+ this.selectedItem = path;
93
+ this.activeItem = path;
46
94
  }
47
95
  updated(changedProperties) {
48
96
  if (changedProperties.has('media')) {
@@ -61,6 +109,10 @@ export class ExmNavigationBase extends MediaQueries(ExmgElement) {
61
109
  if (changedProperties.has('media')) {
62
110
  this.handleMediaTypeChange.bind(this)();
63
111
  }
112
+ /**
113
+ * Set the start path
114
+ */
115
+ this.setPath();
64
116
  }
65
117
  connectedCallback() {
66
118
  super.connectedCallback();
@@ -17,7 +17,7 @@ export const style = css `
17
17
 
18
18
  aside {
19
19
  position: absolute;
20
- left: -300px;
20
+ left: calc(-1 * var(--exm-drawer-max-width, 300px) - 1px);
21
21
  width: var(--exm-drawer-max-width, 300px);
22
22
  height: 100%;
23
23
  transition: left 0.3s ease-out;
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@exmg/exm-navigation",
3
- "version": "1.1.6-alpha.9+3cc6892",
3
+ "version": "1.1.9-alpha.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
6
7
  "module": "dist/index.js",
7
8
  "exports": {
8
9
  ".": "./dist/index.js",
@@ -49,5 +50,5 @@
49
50
  "publishConfig": {
50
51
  "access": "public"
51
52
  },
52
- "gitHead": "3cc6892b878d133d6cf25d0795712e30412d9386"
53
+ "gitHead": "1973df6ecaaf0a57b688f5eb8852516295bc04d6"
53
54
  }