|
1 | 1 | // Import Internal Dependencies |
2 | 2 | import { PackageInfo } from "../components/package/package.js"; |
| 3 | +import { EVENTS } from "./events.js"; |
3 | 4 |
|
4 | 5 | export class NetworkNavigation { |
5 | 6 | /** |
@@ -118,6 +119,13 @@ export class NetworkNavigation { |
118 | 119 |
|
119 | 120 | this.#dependenciesMapByLevel.set(0, this.rootNodeParams); |
120 | 121 |
|
| 122 | + window.addEventListener(EVENTS.MOVED_TO_NEXT_LOCKED_NODE, () => { |
| 123 | + this.#moveToNextLockedNode(); |
| 124 | + }); |
| 125 | + window.addEventListener(EVENTS.MOVED_TO_PREVIOUS_LOCKED_NODE, () => { |
| 126 | + this.#moveToPreviousLockedNode(); |
| 127 | + }); |
| 128 | + |
121 | 129 | document.addEventListener("keydown", (event) => { |
122 | 130 | const isNetworkViewHidden = document.getElementById("network--view").classList.contains("hidden"); |
123 | 131 | const isWikiOpen = document.getElementById("documentation-root-element").classList.contains("slide-in"); |
@@ -147,22 +155,9 @@ export class NetworkNavigation { |
147 | 155 |
|
148 | 156 | const nodeParam = this.#currentNodeParams ?? this.rootNodeParams; |
149 | 157 |
|
150 | | - if (this.#nsn.lastHighlightedIds === null) { |
151 | | - this.#lockedNodes = []; |
152 | | - } |
153 | | - else { |
154 | | - this.#lockedNodes = this.#sortByAngle( |
155 | | - [...this.#nsn.lastHighlightedIds].map( |
156 | | - (id) => [id, { |
157 | | - ...this.#secureDataSet.linker.get(id), |
158 | | - position: nsn.network.getPosition(id) |
159 | | - }] |
160 | | - ), |
161 | | - { ...nsn.network.getPosition(this.rootNodeParams.nodes[0]) } |
162 | | - ); |
163 | | - } |
| 158 | + this.#updateLockedNodes(); |
164 | 159 |
|
165 | | - if (this.#lockedNodes.length > 0) { |
| 160 | + if (this.#hasLockedNodes()) { |
166 | 161 | this.#navigateBetweenLockedNodes(event); |
167 | 162 |
|
168 | 163 | return; |
@@ -361,32 +356,81 @@ export class NetworkNavigation { |
361 | 356 | this.#navigateTreeLevel(nearthestNode); |
362 | 357 | } |
363 | 358 |
|
| 359 | + #updateLockedNodes() { |
| 360 | + if (this.#nsn.lastHighlightedIds === null) { |
| 361 | + this.#lockedNodes = []; |
| 362 | + } |
| 363 | + else { |
| 364 | + this.#lockedNodes = this.#sortByAngle( |
| 365 | + [...this.#nsn.lastHighlightedIds].map( |
| 366 | + (id) => [id, { |
| 367 | + ...this.#secureDataSet.linker.get(id), |
| 368 | + position: this.#nsn.network.getPosition(id) |
| 369 | + }] |
| 370 | + ), |
| 371 | + { ...this.#nsn.network.getPosition(this.rootNodeParams.nodes[0]) } |
| 372 | + ); |
| 373 | + } |
| 374 | + } |
| 375 | + |
| 376 | + #moveToPreviousLockedNode() { |
| 377 | + this.#updateLockedNodes(); |
| 378 | + if (this.#hasLockedNodes()) { |
| 379 | + this.#selectPreviousLockedNode(); |
| 380 | + this.#focusOnActiveLockedNode(); |
| 381 | + } |
| 382 | + } |
| 383 | + |
| 384 | + #moveToNextLockedNode() { |
| 385 | + this.#updateLockedNodes(); |
| 386 | + if (this.#hasLockedNodes()) { |
| 387 | + this.#selectNextLockedNode(); |
| 388 | + this.#focusOnActiveLockedNode(); |
| 389 | + } |
| 390 | + } |
| 391 | + |
364 | 392 | #navigateBetweenLockedNodes(event) { |
365 | 393 | switch (event.code) { |
366 | 394 | case "ArrowLeft": |
367 | | - if (this.#lockedNodesActiveIndex === 0) { |
368 | | - this.#lockedNodesActiveIndex = this.#lockedNodes.length - 1; |
369 | | - } |
370 | | - else { |
371 | | - this.#lockedNodesActiveIndex--; |
372 | | - } |
| 395 | + this.#selectPreviousLockedNode(); |
373 | 396 | break; |
374 | 397 | case "ArrowRight": |
375 | | - if (this.#lockedNodesActiveIndex === this.#lockedNodes.length - 1) { |
376 | | - this.#lockedNodesActiveIndex = 0; |
377 | | - } |
378 | | - else { |
379 | | - this.#lockedNodesActiveIndex++; |
380 | | - } |
| 398 | + this.#selectNextLockedNode(); |
381 | 399 | break; |
382 | 400 | default: |
383 | 401 | return; |
384 | 402 | } |
385 | 403 |
|
| 404 | + this.#focusOnActiveLockedNode(); |
| 405 | + } |
| 406 | + |
| 407 | + #selectPreviousLockedNode() { |
| 408 | + if (this.#lockedNodesActiveIndex === 0) { |
| 409 | + this.#lockedNodesActiveIndex = this.#lockedNodes.length - 1; |
| 410 | + } |
| 411 | + else { |
| 412 | + this.#lockedNodesActiveIndex--; |
| 413 | + } |
| 414 | + } |
| 415 | + |
| 416 | + #selectNextLockedNode() { |
| 417 | + if (this.#lockedNodesActiveIndex === this.#lockedNodes.length - 1) { |
| 418 | + this.#lockedNodesActiveIndex = 0; |
| 419 | + } |
| 420 | + else { |
| 421 | + this.#lockedNodesActiveIndex++; |
| 422 | + } |
| 423 | + } |
| 424 | + |
| 425 | + #focusOnActiveLockedNode() { |
386 | 426 | this.#nsn.network.focus(this.#lockedNodes[this.#lockedNodesActiveIndex][0], { |
387 | 427 | animation: true, |
388 | 428 | scale: 0.35, |
389 | 429 | offset: { x: 150, y: 0 } |
390 | 430 | }); |
391 | 431 | } |
| 432 | + |
| 433 | + #hasLockedNodes() { |
| 434 | + return this.#lockedNodes.length > 0; |
| 435 | + } |
392 | 436 | } |
0 commit comments