|
2 | 2 |
|
3 | 3 | import { Tooltip } from "bootstrap";
|
4 | 4 | import { TreeView } from "./tree_view.js";
|
5 |
| -import { StatisticsView } from "./statistics.js"; |
| 5 | +import { SyntaxView } from "./syntax_view.js"; |
| 6 | +import { StatisticsView } from "./statistics_view.js"; |
6 | 7 | import { Popover } from "./popover.js";
|
7 | 8 | import { WebSocketClient } from "./websocket.js";
|
8 | 9 | import { debounce } from "./debounce.js";
|
@@ -52,7 +53,9 @@ export class App {
|
52 | 53 | this.treeViewContainer = document.getElementById("structure");
|
53 | 54 | this.popover = new Popover();
|
54 | 55 |
|
55 |
| - this.syntaxMapContainer = document.getElementById("syntax-map"); |
| 56 | + this.syntaxView = new SyntaxView( |
| 57 | + document.getElementById("syntax-container") |
| 58 | + ); |
56 | 59 | this.statisticsView = new StatisticsView(
|
57 | 60 | document.getElementById("statistics-container")
|
58 | 61 | );
|
@@ -163,28 +166,24 @@ export class App {
|
163 | 166 | );
|
164 | 167 |
|
165 | 168 | this.updateStructure(structureData);
|
166 |
| - |
167 |
| - this.syntaxMapContainer.innerHTML = data.syntaxHTML; |
168 |
| - this.updateSyntaxMap(); |
| 169 | + this.updateSyntaxMap(data.syntaxHTML); |
169 | 170 |
|
170 | 171 | const statistics = structureData
|
171 | 172 | .filter((node) => node.token === undefined)
|
172 | 173 | .reduce((acc, item) => {
|
173 | 174 | const existingItem = acc.find((a) => a.text === item.text);
|
174 |
| - |
175 | 175 | if (existingItem) {
|
176 | 176 | existingItem.ranges.push(item.range);
|
177 | 177 | } else {
|
178 | 178 | acc.push({ text: item.text, ranges: [item.range] });
|
179 | 179 | }
|
180 |
| - |
181 | 180 | return acc;
|
182 | 181 | }, []);
|
183 | 182 | this.updateStatistics(statistics);
|
184 | 183 |
|
185 | 184 | document.getElementById("structure").style.maxHeight =
|
186 | 185 | this.contentMaxHeight;
|
187 |
| - document.getElementById("syntax-map").style.maxHeight = |
| 186 | + document.getElementById("syntax-container").style.maxHeight = |
188 | 187 | this.contentMaxHeight;
|
189 | 188 | document.getElementById("statistics-container").style.maxHeight =
|
190 | 189 | this.contentMaxHeight;
|
@@ -402,77 +401,8 @@ export class App {
|
402 | 401 | };
|
403 | 402 | }
|
404 | 403 |
|
405 |
| - updateSyntaxMap() { |
406 |
| - const popover = this.popover; |
407 |
| - const tabContainerRect = document |
408 |
| - .querySelector(".tab-content") |
409 |
| - .getBoundingClientRect(); |
410 |
| - |
411 |
| - let mouseoverCancel = undefined; |
412 |
| - $(this.syntaxMapContainer) |
413 |
| - .find("span") |
414 |
| - .each(function () { |
415 |
| - $(this).mouseover(function (event) { |
416 |
| - event.preventDefault(); |
417 |
| - event.stopPropagation(); |
418 |
| - |
419 |
| - if (mouseoverCancel) { |
420 |
| - cancelAnimationFrame(mouseoverCancel); |
421 |
| - } |
422 |
| - mouseoverCancel = requestAnimationFrame(() => { |
423 |
| - const contents = []; |
424 |
| - |
425 |
| - $(this) |
426 |
| - .parents("span") |
427 |
| - .each(function (index, element) { |
428 |
| - createDOMRectElement(element.getBoundingClientRect()); |
429 |
| - contents.push([element.dataset.title, element.dataset.content]); |
430 |
| - if (index > 0) { |
431 |
| - return false; |
432 |
| - } |
433 |
| - }); |
434 |
| - |
435 |
| - let element = event.target; |
436 |
| - element.style.backgroundColor = "rgba(81, 101, 255, 0.5)"; |
437 |
| - |
438 |
| - contents.reverse(); |
439 |
| - contents.push([element.dataset.title, element.dataset.content]); |
440 |
| - |
441 |
| - const dl = `<dl>${contents |
442 |
| - .map((content) => { |
443 |
| - return `<dt>${content[0]}</dt><dd>${content[1]}</dd>`; |
444 |
| - }) |
445 |
| - .join("")}</dl>`; |
446 |
| - popover.content = dl; |
447 |
| - |
448 |
| - popover.show(element, { |
449 |
| - lowerLimit: tabContainerRect.top + tabContainerRect.height, |
450 |
| - offsetX: 40, |
451 |
| - }); |
452 |
| - }); |
453 |
| - }); |
454 |
| - |
455 |
| - let mouseoutCancel = undefined; |
456 |
| - $(this).mouseout(function (event) { |
457 |
| - event.preventDefault(); |
458 |
| - event.stopPropagation(); |
459 |
| - |
460 |
| - if (mouseoutCancel) { |
461 |
| - cancelAnimationFrame(mouseoutCancel); |
462 |
| - } |
463 |
| - mouseoutCancel = requestAnimationFrame(() => { |
464 |
| - let element = event.target; |
465 |
| - element.style.backgroundColor = ""; |
466 |
| - |
467 |
| - let rectElements = document.getElementsByClassName("dom-rect"); |
468 |
| - for (let i = 0, l = rectElements.length; l > i; i++) { |
469 |
| - rectElements[0].parentNode.removeChild(rectElements[0]); |
470 |
| - } |
471 |
| - |
472 |
| - popover.hide(); |
473 |
| - }); |
474 |
| - }); |
475 |
| - }); |
| 404 | + updateSyntaxMap(syntaxHTML) { |
| 405 | + this.syntaxView.update(syntaxHTML); |
476 | 406 | }
|
477 | 407 |
|
478 | 408 | updateStatistics(statistics) {
|
@@ -523,25 +453,6 @@ function hideLoading() {
|
523 | 453 | document.getElementById("run-button-spinner").classList.add("d-none");
|
524 | 454 | }
|
525 | 455 |
|
526 |
| -function createDOMRectElement(domRect) { |
527 |
| - let rectElements = document.getElementsByClassName("dom-rect"); |
528 |
| - for (let i = 0, l = rectElements.length; l > i; i++) { |
529 |
| - rectElements[0].parentNode.removeChild(rectElements[0]); |
530 |
| - } |
531 |
| - |
532 |
| - let rectElement = document.createElement("div"); |
533 |
| - rectElement.className = "dom-rect"; |
534 |
| - rectElement.style.left = domRect.x - 1 + "px"; |
535 |
| - rectElement.style.top = domRect.y - 1 + "px"; |
536 |
| - rectElement.style.width = domRect.width + "px"; |
537 |
| - rectElement.style.height = domRect.height + "px"; |
538 |
| - rectElement.style.pointerEvents = "none"; |
539 |
| - rectElement.style.position = "absolute"; |
540 |
| - rectElement.style.border = "1px solid rgb(81, 101, 255)"; |
541 |
| - rectElement.style.backgroundColor = "rgba(81, 101, 255, 0.25)"; |
542 |
| - document.body.appendChild(rectElement); |
543 |
| -} |
544 |
| - |
545 | 456 | function stripHTMLTag(text) {
|
546 | 457 | const div = document.createElement("div");
|
547 | 458 | div.innerHTML = text
|
|
0 commit comments