Skip to content

Commit aeb1bf8

Browse files
feat(network-navigation): package-info switch (#476)
1 parent 083e9a5 commit aeb1bf8

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

public/components/package/package.js

+34
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,40 @@ export class PackageInfo {
1515
window.dispatchEvent(new CustomEvent("package-info-closed", { detail: null }));
1616
}
1717

18+
/**
19+
* @param {"previous"|"next"} direction
20+
*/
21+
static switch(direction) {
22+
const packageHTMLElement = document.getElementById(PackageInfo.DOMElementName);
23+
const packageNavigation = packageHTMLElement.querySelector(".package-navigation");
24+
const activeElement = packageNavigation.querySelector(".active");
25+
26+
const enabledChilren = [...packageNavigation.children].filter((child) => child.classList.contains("disabled") === false);
27+
const activeElementIndex = [...enabledChilren].indexOf(activeElement);
28+
29+
const nextElement = direction === "next"
30+
? enabledChilren[enabledChilren.length === activeElementIndex + 1 ? 1 : activeElementIndex + 1]
31+
: enabledChilren[activeElementIndex === 1 ? enabledChilren.length - 1 : activeElementIndex - 1];
32+
33+
nextElement.click();
34+
}
35+
36+
/**
37+
*
38+
* @param {"up"|"down"} direction
39+
*/
40+
static scroll(direction) {
41+
const packageHTMLElement = document.getElementById(PackageInfo.DOMElementName);
42+
const scrollableContainer = [...packageHTMLElement.querySelectorAll(".package-container")]
43+
.find((child) => child.classList.contains("hidden") === false);
44+
45+
if (scrollableContainer.scrollHeight <= scrollableContainer.clientHeight) {
46+
return;
47+
}
48+
49+
scrollableContainer.scrollTop += direction === "up" ? -50 : 50;
50+
}
51+
1852
/**
1953
* @param {*} dependencyVersionData
2054
* @param {*} dependency

public/core/network-navigation.js

+26
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Import Internal Dependencies
2+
import { PackageInfo } from "../components/package/package.js";
3+
14
export class NetworkNavigation {
25
/**
36
* @type {import("@nodesecure/vis-network").NodeSecureDataSet}
@@ -62,6 +65,11 @@ export class NetworkNavigation {
6265
* Represents the active locked node index.
6366
*/
6467
#lockedNodesActiveIndex = 0;
68+
/**
69+
* -`true` package info navigation\
70+
* -`false` network navigation
71+
*/
72+
#packageInfoFocus = false;
6573

6674
set currentNodeParams(params) {
6775
this.#currentNodeParams = params;
@@ -119,6 +127,24 @@ export class NetworkNavigation {
119127
return;
120128
}
121129

130+
if (event.code === "Enter") {
131+
this.#packageInfoFocus = !this.#packageInfoFocus;
132+
console.log(`[INFO] keyboard navigation switched (focus:${this.#packageInfoFocus ? "package-info" : "network"})`);
133+
}
134+
135+
if (this.#packageInfoFocus) {
136+
if (["ArrowLeft", "ArrowRight"].includes(event.code)) {
137+
const direction = event.code === "ArrowLeft" ? "previous" : "next";
138+
PackageInfo.switch(direction);
139+
}
140+
else if (["ArrowUp", "ArrowDown"].includes(event.code)) {
141+
const direction = event.code === "ArrowUp" ? "up" : "down";
142+
PackageInfo.scroll(direction);
143+
}
144+
145+
return;
146+
}
147+
122148
const nodeParam = this.#currentNodeParams ?? this.rootNodeParams;
123149

124150
if (this.#nsn.lastHighlightedIds === null) {

0 commit comments

Comments
 (0)