Skip to content

Commit ed2208f

Browse files
committed
add references, fix expanding in search, switch virt
1 parent 993f717 commit ed2208f

13 files changed

Lines changed: 327 additions & 231 deletions

web/package-lock.json

Lines changed: 29 additions & 108 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
"test": "tsc --noEmit && npm run lint"
99
},
1010
"dependencies": {
11+
"@tanstack/react-virtual": "^3.13.22",
1112
"@types/react": "^19.2.14",
1213
"@types/react-dom": "^19.2.3",
13-
"@types/react-virtualized": "^9.21.10",
1414
"react": "^19.2.4",
1515
"react-dom": "^19.2.4",
1616
"react-router-dom": "^7.13.1",
17-
"react-virtualized": "^9.22.2",
1817
"styled-components": "^6.3.11"
1918
},
2019
"devDependencies": {

web/src/components/Docs/ContentList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { SchemaEnumView } from "./SchemaEnum";
77
import { Declaration } from "~components/Docs/api";
88
import { DeclarationsContext } from "~components/Docs/DeclarationsContext";
99

10-
function renderItem(declaration: Declaration, style?: React.CSSProperties) {
10+
function renderItem(declaration: Declaration) {
1111
let children: React.JSX.Element;
1212
switch (declaration.kind) {
1313
case "class":
@@ -19,7 +19,7 @@ function renderItem(declaration: Declaration, style?: React.CSSProperties) {
1919
}
2020

2121
return (
22-
<ListItem style={style} key={declaration.name}>
22+
<ListItem key={declaration.name}>
2323
{children}
2424
</ListItem>
2525
);
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import { createContext } from "react";
22
import { Declaration } from "~components/Docs/api";
33

4+
export type ReferenceEntry = {
5+
declarationName: string;
6+
declarationKind: "class" | "enum";
7+
fieldName?: string;
8+
relation: "field" | "parent";
9+
};
10+
411
export type DeclarationsContextType = {
512
root: string;
613
declarations: Declaration[];
14+
references: Map<string, ReferenceEntry[]>;
715
};
816

9-
export const DeclarationsContext = createContext<DeclarationsContextType>({ root: "", declarations: [] });
17+
export const DeclarationsContext = createContext<DeclarationsContextType>({ root: "", declarations: [], references: new Map() });
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import React, { useContext, useState } from "react";
2+
import { Link } from "react-router-dom";
3+
import styled from "styled-components";
4+
import { DeclarationsContext } from "./DeclarationsContext";
5+
import { KindIcon } from "./utils/components";
6+
7+
const COLLAPSE_THRESHOLD = 8;
8+
9+
const Wrapper = styled.div`
10+
padding: 8px 12px;
11+
border-top: 1px solid ${(props) => props.theme.groupBorder};
12+
`;
13+
14+
const Title = styled.div`
15+
font-size: 12px;
16+
font-weight: 600;
17+
text-transform: uppercase;
18+
letter-spacing: 0.04em;
19+
color: ${(props) => props.theme.textDim};
20+
margin-bottom: 4px;
21+
`;
22+
23+
const RefList = styled.div`
24+
display: flex;
25+
flex-wrap: wrap;
26+
gap: 4px;
27+
`;
28+
29+
const RefLink = styled(Link)`
30+
display: inline-flex;
31+
align-items: center;
32+
gap: 3px;
33+
padding: 2px 8px;
34+
border-radius: 4px;
35+
font-size: 14px;
36+
text-decoration: none;
37+
color: ${(props) => props.theme.text};
38+
background: ${(props) => props.theme.groupMembers};
39+
border: 1px solid ${(props) => props.theme.groupBorder};
40+
transition: border-color 0.1s;
41+
42+
&:hover {
43+
border-color: ${(props) => props.theme.highlight};
44+
}
45+
`;
46+
47+
const RefField = styled.span`
48+
color: ${(props) => props.theme.textDim};
49+
50+
&::before {
51+
content: ".";
52+
}
53+
`;
54+
55+
const ToggleButton = styled.button`
56+
background: none;
57+
border: none;
58+
color: ${(props) => props.theme.textDim};
59+
font-size: 12px;
60+
cursor: pointer;
61+
padding: 2px 4px;
62+
63+
&:hover {
64+
color: ${(props) => props.theme.text};
65+
}
66+
`;
67+
68+
export function ReferencedBy({ name }: { name: string }) {
69+
const { root, references } = useContext(DeclarationsContext);
70+
const [expanded, setExpanded] = useState(false);
71+
72+
const refs = references.get(name);
73+
if (!refs || refs.length === 0) return null;
74+
75+
const collapsible = refs.length > COLLAPSE_THRESHOLD;
76+
const visible = collapsible && !expanded ? refs.slice(0, COLLAPSE_THRESHOLD) : refs;
77+
78+
return (
79+
<Wrapper>
80+
<Title>Referenced by ({refs.length})</Title>
81+
<RefList>
82+
{visible.map((ref, i) => (
83+
<RefLink key={`${ref.declarationName}-${ref.fieldName ?? ""}-${i}`} to={`${root}/${ref.declarationName}`}>
84+
<KindIcon kind={ref.declarationKind} size="small" />
85+
<span>{ref.declarationName}{ref.fieldName && <RefField>{ref.fieldName}</RefField>}</span>
86+
</RefLink>
87+
))}
88+
{collapsible && (
89+
<ToggleButton onClick={() => setExpanded(!expanded)}>
90+
{expanded ? "show less" : `+${refs.length - COLLAPSE_THRESHOLD} more…`}
91+
</ToggleButton>
92+
)}
93+
</RefList>
94+
</Wrapper>
95+
);
96+
}

web/src/components/Docs/SchemaClass.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useContext } from "react";
22
import styled from "styled-components";
33
import * as api from "./api";
44
import { SchemaTypeView, MetadataTags } from "./SchemaType";
5+
import { ReferencedBy } from "./ReferencedBy";
56
import { KindIcon } from "./utils/components";
67
import { DeclarationsContext } from "./DeclarationsContext";
78
import {
@@ -93,6 +94,7 @@ export const SchemaClassView: React.FC<{
9394
))}
9495
</ClassMembers>
9596
)}
97+
<ReferencedBy name={declaration.name} />
9698
</CommonGroupWrapper>
9799
);
98100
};

0 commit comments

Comments
 (0)