Skip to content

Commit cd9b249

Browse files
committed
Ensure linked-to members are always visible
Resolves #2092
1 parent c40ed98 commit cd9b249

File tree

5 files changed

+76
-2
lines changed

5 files changed

+76
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
### Bug Fixes
88

9+
- Links to members hidden by filter settings now temporarily override the filter, #2092.
910
- If `src/` and `src/x` are specified as entry points, `src/` will no longer be ignored, #2121.
1011

1112
## v0.23.22 (2022-12-11)

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

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,67 @@ export function registerComponent(
3030
* TypeDoc application class.
3131
*/
3232
export class Application {
33+
alwaysVisibleMember: HTMLElement | null = null;
34+
3335
/**
3436
* Create a new Application instance.
3537
*/
3638
constructor() {
3739
this.createComponents(document.body);
40+
this.ensureFocusedElementVisible();
41+
window.addEventListener("hashchange", () =>
42+
this.ensureFocusedElementVisible()
43+
);
3844
}
3945

4046
/**
4147
* Create all components beneath the given element.
4248
*/
43-
public createComponents(context: HTMLElement) {
49+
private createComponents(context: HTMLElement) {
4450
components.forEach((c) => {
4551
context.querySelectorAll<HTMLElement>(c.selector).forEach((el) => {
4652
if (!el.dataset["hasInstance"]) {
47-
new c.constructor({ el: el });
53+
new c.constructor({ el, app: this });
4854
el.dataset["hasInstance"] = String(true);
4955
}
5056
});
5157
});
5258
}
59+
60+
public filterChanged() {
61+
this.ensureFocusedElementVisible();
62+
}
63+
64+
/**
65+
* Ensures that if a user was linked to a reflection which is hidden because of filter
66+
* settings, that reflection is still shown.
67+
*/
68+
private ensureFocusedElementVisible() {
69+
if (this.alwaysVisibleMember) {
70+
this.alwaysVisibleMember.classList.remove("always-visible");
71+
this.alwaysVisibleMember.firstElementChild!.remove();
72+
this.alwaysVisibleMember = null;
73+
}
74+
75+
const reflAnchor = document.getElementById(location.hash.substring(1));
76+
if (!reflAnchor) return;
77+
78+
let reflContainer = reflAnchor.parentElement!;
79+
while (reflContainer.tagName !== "SECTION") {
80+
reflContainer = reflContainer.parentElement!;
81+
}
82+
83+
if (reflContainer.offsetParent == null) {
84+
this.alwaysVisibleMember = reflContainer;
85+
86+
reflContainer.classList.add("always-visible");
87+
88+
const warning = document.createElement("p");
89+
warning.classList.add("warning");
90+
warning.textContent =
91+
"This member is normally hidden due to your filter settings.";
92+
93+
reflContainer.prepend(warning);
94+
}
95+
}
5396
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import { Application } from "./Application";
2+
13
export interface IComponentOptions {
4+
app: Application;
25
el: HTMLElement;
36
}
47

@@ -7,8 +10,10 @@ export interface IComponentOptions {
710
*/
811
export class Component {
912
protected el: HTMLElement;
13+
protected app: Application;
1014

1115
constructor(options: IComponentOptions) {
1216
this.el = options.el;
17+
this.app = options.app;
1318
}
1419
}

src/lib/output/themes/default/assets/typedoc/components/Filter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export class Filter extends Component {
5858
this.el.checked = this.value;
5959
document.documentElement.classList.toggle(this.key, this.value);
6060

61+
this.app.filterChanged();
62+
6163
// Hide index headings where all index items are hidden.
6264
// offsetParent == null checks for display: none
6365
document

static/style.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
/* Light */
33
--light-color-background: #f2f4f8;
44
--light-color-background-secondary: #eff0f1;
5+
--light-color-warning-text: #222;
6+
--light-color-background-warning: #e6e600;
57
--light-color-icon-background: var(--light-color-background);
68
--light-color-accent: #c5c7c9;
79
--light-color-text: #222;
@@ -21,6 +23,8 @@
2123
/* Dark */
2224
--dark-color-background: #2b2e33;
2325
--dark-color-background-secondary: #1e2024;
26+
--dark-color-background-warning: #bebe00;
27+
--dark-color-warning-text: #222;
2428
--dark-color-icon-background: var(--dark-color-background-secondary);
2529
--dark-color-accent: #9096a2;
2630
--dark-color-text: #f5f5f5;
@@ -42,6 +46,8 @@
4246
:root {
4347
--color-background: var(--light-color-background);
4448
--color-background-secondary: var(--light-color-background-secondary);
49+
--color-background-warning: var(--light-color-background-warning);
50+
--color-warning-text: var(--light-color-warning-text);
4551
--color-icon-background: var(--light-color-icon-background);
4652
--color-accent: var(--light-color-accent);
4753
--color-text: var(--light-color-text);
@@ -64,6 +70,8 @@
6470
:root {
6571
--color-background: var(--dark-color-background);
6672
--color-background-secondary: var(--dark-color-background-secondary);
73+
--color-background-warning: var(--dark-color-background-warning);
74+
--color-warning-text: var(--dark-color-warning-text);
6775
--color-icon-background: var(--dark-color-icon-background);
6876
--color-accent: var(--dark-color-accent);
6977
--color-text: var(--dark-color-text);
@@ -93,6 +101,8 @@ body {
93101
:root[data-theme="light"] {
94102
--color-background: var(--light-color-background);
95103
--color-background-secondary: var(--light-color-background-secondary);
104+
--color-background-warning: var(--light-color-background-warning);
105+
--color-warning-text: var(--light-color-warning-text);
96106
--color-icon-background: var(--light-color-icon-background);
97107
--color-accent: var(--light-color-accent);
98108
--color-text: var(--light-color-text);
@@ -113,6 +123,8 @@ body {
113123
:root[data-theme="dark"] {
114124
--color-background: var(--dark-color-background);
115125
--color-background-secondary: var(--dark-color-background-secondary);
126+
--color-background-warning: var(--dark-color-background-warning);
127+
--color-warning-text: var(--dark-color-warning-text);
116128
--color-icon-background: var(--dark-color-icon-background);
117129
--color-accent: var(--dark-color-accent);
118130
--color-text: var(--dark-color-text);
@@ -130,6 +142,11 @@ body {
130142
--color-scheme: var(--dark-color-scheme);
131143
}
132144

145+
.always-visible,
146+
.always-visible .tsd-signatures {
147+
display: inherit !important;
148+
}
149+
133150
h1,
134151
h2,
135152
h3,
@@ -1237,6 +1254,12 @@ img {
12371254
text-decoration: line-through;
12381255
}
12391256

1257+
.warning {
1258+
padding: 1rem;
1259+
color: var(--color-warning-text);
1260+
background: var(--color-background-warning);
1261+
}
1262+
12401263
* {
12411264
scrollbar-width: thin;
12421265
scrollbar-color: var(--color-accent) var(--color-icon-background);

0 commit comments

Comments
 (0)