Skip to content

Commit 55a8d2f

Browse files
committed
chore: docs
1 parent d6f0245 commit 55a8d2f

File tree

3 files changed

+236
-79
lines changed

3 files changed

+236
-79
lines changed

packages/docs/src/components/ui/reference/docRef.tsx

+21-66
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,26 @@ type DocsJson = {
4343

4444
const newJson = docsJson_ as ExportedTypeFile;
4545

46-
// console.log('test', (newJson['DockviewApi'] as any).children);
47-
console.log('test', firstLevel((newJson['DockviewApi'] as any).children[29]));
46+
console.log(newJson);
47+
48+
export const DocumentRef = (props: { value: TypeSystem.Type }) => {
49+
if (!props.value) {
50+
return null;
51+
}
52+
53+
switch (props.value.kind) {
54+
case 'typealias':
55+
return codify(props.value);
56+
case 'interface':
57+
return codify(props.value);
58+
case 'class':
59+
return codify(props.value);
60+
case 'function':
61+
return codify(props.value);
62+
default:
63+
return <div>{'error'}</div>;
64+
}
65+
};
4866

4967
export const Text = (props: { content: DocsContent[] }) => {
5068
return (
@@ -96,69 +114,6 @@ export const Markdown = (props: { children: string }) => {
96114
return <span>{props.children}</span>;
97115
};
98116

99-
const ClassPiece = (props: { value: DocJson; name: string }) => {
100-
let code = `interface ${props.name} {\n`;
101-
102-
code += props.value.children
103-
.map((child) => {
104-
switch (child.kind) {
105-
case 'accessor':
106-
return `\t${child.name}: ${child.code};`;
107-
case 'method':
108-
return `\t${child.name}${child.code};`;
109-
default:
110-
return null;
111-
}
112-
})
113-
.filter(Boolean)
114-
.join('\n');
115-
116-
code += `\n}`;
117-
118-
return <CodeBlock language="tsx">{code}</CodeBlock>;
119-
};
120-
121-
const InterfacePiece = (props: { value: DocJson; name: string }) => {
122-
let code = `interface ${props.name} {\n`;
123-
124-
code += props.value.children
125-
.map((child) => {
126-
switch (child.kind) {
127-
case 'property':
128-
return `\t${child.name}: ${child.code};`;
129-
default:
130-
return null;
131-
}
132-
})
133-
.join('\n');
134-
135-
code += `\n}`;
136-
137-
return <CodeBlock language="tsx">{code}</CodeBlock>;
138-
};
139-
140-
const Piece = (props: { piece: string }) => {
141-
const item = docsJson[props.piece];
142-
143-
if (!item) {
144-
return null;
145-
}
146-
147-
if (item.kind === 'class') {
148-
return <ClassPiece name={props.piece} value={item} />;
149-
}
150-
151-
if (item.kind === 'interface') {
152-
return <InterfacePiece name={props.piece} value={item} />;
153-
}
154-
155-
if (!item.metadata?.code) {
156-
return null;
157-
}
158-
159-
return <CodeBlock language="tsx">{item.metadata.code}</CodeBlock>;
160-
};
161-
162117
const Row = (props: { doc: TypeSystem.Type }) => {
163118
const comment =
164119
props.doc.kind === 'accessor'
@@ -259,7 +214,7 @@ export const DocRef = (props: DocRefProps) => {
259214
<div>
260215
{firstLevel(doc).map((x) => (
261216
<span style={{ padding: '0px 2px' }}>
262-
{x}
217+
<DocumentRef value={newJson[x]} />
263218
</span>
264219
))}
265220
</div>

packages/docs/src/components/ui/reference/types.ts

+34-1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ export function codify(value: TypeSystem.Type | null) {
154154

155155
if (value.kind === 'property') {
156156
let code = '';
157+
158+
if (value.flags.isProtected) {
159+
code += 'protected ';
160+
}
161+
157162
if (value.flags.isReadonly) {
158163
code += 'readonly ';
159164
}
@@ -222,6 +227,18 @@ export function codify(value: TypeSystem.Type | null) {
222227
return '';
223228
}
224229

230+
if (value.kind === 'interface') {
231+
return `interface ${value.name} { ${value.children
232+
.map(codify)
233+
.join(',')} }`;
234+
}
235+
236+
if (value.kind === 'class') {
237+
return `interface ${value.name} { ${value.children
238+
.map(codify)
239+
.join(',')} }`;
240+
}
241+
225242
console.log('unreachable', value);
226243
throw new Error(`unreachable`);
227244
}
@@ -266,6 +283,13 @@ export namespace TypeSystem {
266283
comment?: Comment;
267284
};
268285

286+
export type Function = {
287+
name: string;
288+
kind: 'function';
289+
signature: TypeSystem.CallSignature;
290+
comment?: Comment;
291+
};
292+
269293
export type Property = {
270294
kind: 'property';
271295
name: string;
@@ -302,6 +326,13 @@ export namespace TypeSystem {
302326
comment?: Comment;
303327
};
304328

329+
export type Interface = {
330+
name: string;
331+
kind: 'interface';
332+
children: TypeSystem.Type[];
333+
comment?: Comment;
334+
};
335+
305336
export type Parameter = {
306337
name: string;
307338
kind: 'parameter';
@@ -342,7 +373,9 @@ export namespace TypeSystem {
342373
| TypeSystem.Constructor
343374
| TypeSystem.ConstructorSignature
344375
| TypeSystem.TypeLiteral
345-
| TypeSystem.Parameter;
376+
| TypeSystem.Parameter
377+
| TypeSystem.Interface
378+
| TypeSystem.Function;
346379
}
347380

348381
export namespace TypeDescriptor {

0 commit comments

Comments
 (0)