Skip to content

Commit 776f7a7

Browse files
committed
Fix useTsLinkResolution in block tags
1 parent 08b8348 commit 776f7a7

File tree

4 files changed

+59
-48
lines changed

4 files changed

+59
-48
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
### Bug Fixes
1111

12+
- `--useTsLinkResolution` is no longer ignored within block tags, #2260.
13+
- The current namespace will also be expanded in the navigation on page load, #2260.
14+
- Fixed flicker of navigation pane when reloading a page caused by updating expansion state after the page was loaded.
1215
- Fixed an infinite loop if more than one entry point was provided, and all entry points were the same.
1316

1417
### Thanks!

src/lib/converter/comments/blockLexer.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,27 @@ function getLinkTags(
4545
): ReadonlyArray<ts.JSDocLink | ts.JSDocLinkCode | ts.JSDocLinkPlain> {
4646
const result: (ts.JSDocLink | ts.JSDocLinkCode | ts.JSDocLinkPlain)[] = [];
4747

48-
if (!jsDoc || typeof jsDoc.comment !== "object") return result;
49-
50-
for (const part of jsDoc.comment) {
51-
switch (part.kind) {
52-
case ts.SyntaxKind.JSDocLink:
53-
case ts.SyntaxKind.JSDocLinkCode:
54-
case ts.SyntaxKind.JSDocLinkPlain:
55-
result.push(part);
48+
if (jsDoc?.comment && typeof jsDoc.comment !== "string") {
49+
for (const part of jsDoc.comment) {
50+
switch (part.kind) {
51+
case ts.SyntaxKind.JSDocLink:
52+
case ts.SyntaxKind.JSDocLinkCode:
53+
case ts.SyntaxKind.JSDocLinkPlain:
54+
result.push(part);
55+
}
56+
}
57+
}
58+
59+
for (const block of jsDoc?.tags || []) {
60+
if (!block.comment || typeof block.comment === "string") continue;
61+
62+
for (const part of block.comment) {
63+
switch (part.kind) {
64+
case ts.SyntaxKind.JSDocLink:
65+
case ts.SyntaxKind.JSDocLinkCode:
66+
case ts.SyntaxKind.JSDocLinkPlain:
67+
result.push(part);
68+
}
5669
}
5770
}
5871

src/lib/output/themes/default/assets/bootstrap.ts

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,17 @@ import { Filter } from "./typedoc/components/Filter";
55
import { Accordion } from "./typedoc/components/Accordion";
66
import { initTheme } from "./typedoc/Theme";
77

8-
addEventListener("load", () => {
9-
initSearch();
10-
initCopyCode();
8+
initSearch();
119

12-
registerComponent(Toggle, "a[data-toggle]");
13-
registerComponent(Accordion, ".tsd-index-accordion");
14-
registerComponent(Filter, ".tsd-filter-item input[type=checkbox]");
10+
registerComponent(Toggle, "a[data-toggle]");
11+
registerComponent(Accordion, ".tsd-index-accordion");
12+
registerComponent(Filter, ".tsd-filter-item input[type=checkbox]");
1513

16-
const themeChoice = document.getElementById("tsd-theme");
17-
if (themeChoice) {
18-
initTheme(themeChoice as HTMLOptionElement);
19-
}
20-
21-
const app = new Application();
14+
const themeChoice = document.getElementById("tsd-theme");
15+
if (themeChoice) {
16+
initTheme(themeChoice as HTMLOptionElement);
17+
}
2218

23-
Object.defineProperty(window, "app", { value: app });
24-
});
19+
const app = new Application();
2520

26-
function initCopyCode() {
27-
document.querySelectorAll("pre > button").forEach((button) => {
28-
let timeout: ReturnType<typeof setTimeout>;
29-
button.addEventListener("click", () => {
30-
if (button.previousElementSibling instanceof HTMLElement) {
31-
navigator.clipboard.writeText(
32-
button.previousElementSibling.innerText.trim()
33-
);
34-
}
35-
button.textContent = "Copied!";
36-
button.classList.add("visible");
37-
clearTimeout(timeout);
38-
timeout = setTimeout(() => {
39-
button.classList.remove("visible");
40-
timeout = setTimeout(() => {
41-
button.textContent = "Copy";
42-
}, 100);
43-
}, 1000);
44-
});
45-
});
46-
}
21+
Object.defineProperty(window, "app", { value: app });

src/lib/output/themes/default/assets/typedoc/Application.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class Application {
3939
this.createComponents(document.body);
4040
this.ensureActivePageVisible();
4141
this.ensureFocusedElementVisible();
42+
this.listenForCodeCopies();
4243
window.addEventListener("hashchange", () =>
4344
this.ensureFocusedElementVisible()
4445
);
@@ -66,11 +67,8 @@ export class Application {
6667
const pageLink = document.querySelector(".tsd-navigation .current");
6768
let iter = pageLink?.parentElement;
6869
while (iter && !iter.classList.contains(".tsd-navigation")) {
69-
// Expand parent namespaces if collapsed, don't expand current namespace
70-
if (
71-
iter instanceof HTMLDetailsElement &&
72-
pageLink?.parentElement?.parentElement !== iter
73-
) {
70+
// Expand parent namespaces if collapsed, and this module
71+
if (iter instanceof HTMLDetailsElement) {
7472
iter.open = true;
7573
}
7674
iter = iter.parentElement;
@@ -125,4 +123,26 @@ export class Application {
125123
reflContainer.prepend(warning);
126124
}
127125
}
126+
127+
private listenForCodeCopies() {
128+
document.querySelectorAll("pre > button").forEach((button) => {
129+
let timeout: ReturnType<typeof setTimeout>;
130+
button.addEventListener("click", () => {
131+
if (button.previousElementSibling instanceof HTMLElement) {
132+
navigator.clipboard.writeText(
133+
button.previousElementSibling.innerText.trim()
134+
);
135+
}
136+
button.textContent = "Copied!";
137+
button.classList.add("visible");
138+
clearTimeout(timeout);
139+
timeout = setTimeout(() => {
140+
button.classList.remove("visible");
141+
timeout = setTimeout(() => {
142+
button.textContent = "Copy";
143+
}, 100);
144+
}, 1000);
145+
});
146+
});
147+
}
128148
}

0 commit comments

Comments
 (0)