File tree Expand file tree Collapse file tree 7 files changed +79
-26
lines changed Expand file tree Collapse file tree 7 files changed +79
-26
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ export const FuncTemplate: FC<FuncTemplateProps> = ({
57
57
</ h2 >
58
58
59
59
< div class = "mb-6" >
60
- < FunctionDefinition func = { content } prefix = { content . name } />
60
+ < FunctionDefinition func = { content } />
61
61
</ div >
62
62
63
63
{ content . example && (
@@ -67,7 +67,7 @@ export const FuncTemplate: FC<FuncTemplateProps> = ({
67
67
) }
68
68
69
69
< div class = "my-6" >
70
- < FunctionParameters func = { content } prefix = { content . name } />
70
+ < FunctionParameters func = { content } />
71
71
</ div >
72
72
73
73
{ content . scope . length > 0 && (
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ export const GroupTemplate: FC<GroupTemplateProps> = ({
41
41
42
42
{ content . functions . map ( ( method , index ) => (
43
43
< div key = { method . name } >
44
- < h3 id = { `definitions -${ method . name } ` } class = "method-head" >
44
+ < h3 id = { `functions -${ method . name } ` } class = "method-head" >
45
45
< code class = "text-base font-medium" > { method . name } </ code >
46
46
< div class = "flex flex-wrap items-center gap-2 text-sm" >
47
47
{ method . element && < Tooltip kind = "element" /> }
@@ -50,7 +50,7 @@ export const GroupTemplate: FC<GroupTemplateProps> = ({
50
50
</ h3 >
51
51
< FunctionDisplay
52
52
func = { method }
53
- prefix = { `definitions -${ method . name } ` }
53
+ prefix = { `functions -${ method . name } ` }
54
54
isExampleFolding = { false }
55
55
/>
56
56
</ div >
Original file line number Diff line number Diff line change @@ -2,16 +2,21 @@ import type { FC } from "hono/jsx";
2
2
import type { Func } from "../../types/model" ;
3
3
import { TypeIcon } from "./TypeIcon" ;
4
4
import { genPath } from "./genPath" ;
5
- import { type2href } from "./type2href" ;
5
+ import { buildParamId , type2href } from "./type2href" ;
6
6
7
7
type FunctionDefinitionProps = {
8
8
func : Func ;
9
- prefix ?: string ;
9
+ /**
10
+ * The prefix for parameter IDs
11
+ *
12
+ * See `buildParamId`.
13
+ */
14
+ prefix ?: string | undefined ;
10
15
} ;
11
16
12
17
export const FunctionDefinition : FC < FunctionDefinitionProps > = ( {
13
18
func,
14
- prefix = "" ,
19
+ prefix = undefined ,
15
20
} ) => {
16
21
return (
17
22
< div class = "bg-gray-50 p-4 rounded-md border border-gray-100 overflow-x-auto" >
@@ -28,7 +33,7 @@ export const FunctionDefinition: FC<FunctionDefinitionProps> = ({
28
33
{ ! param . positional && (
29
34
< div class = "flex-shrink-0" >
30
35
< a
31
- href = { `#${ prefix } - ${ func . name } -parameters- ${ param . name } ` }
36
+ href = { `#${ buildParamId ( param . name , prefix ) } ` }
32
37
class = "text-gray-800 hover:text-blue-500 transition-colors mr-1"
33
38
>
34
39
< span class = "font-medium" > { param . name } </ span >
Original file line number Diff line number Diff line change @@ -7,13 +7,18 @@ import { HtmlContent } from "./HtmlContent";
7
7
8
8
type FunctionDisplayProps = {
9
9
func : Func ;
10
- prefix ?: string ;
10
+ /**
11
+ * The prefix for IDs of function parameters
12
+ *
13
+ * See `buildParamId`.
14
+ */
15
+ prefix ?: string | undefined ;
11
16
isExampleFolding ?: boolean ;
12
17
} ;
13
18
14
19
export const FunctionDisplay : FC < FunctionDisplayProps > = ( {
15
20
func,
16
- prefix = "" ,
21
+ prefix = undefined ,
17
22
isExampleFolding = true ,
18
23
} ) => {
19
24
return (
Original file line number Diff line number Diff line change @@ -4,16 +4,21 @@ import { ChevronRightIcon } from "../icons";
4
4
import { HtmlContent } from "./HtmlContent" ;
5
5
import { Tooltip } from "./Tooltip" ;
6
6
import { TypeIcon } from "./TypeIcon" ;
7
- import { type2href } from "./type2href" ;
7
+ import { buildParamId , type2href } from "./type2href" ;
8
8
9
9
type FunctionParametersProps = {
10
10
func : Func ;
11
- prefix ?: string ;
11
+ /**
12
+ * The prefix for IDs
13
+ *
14
+ * See `buildParamId`.
15
+ */
16
+ prefix ?: string | undefined ;
12
17
} ;
13
18
14
19
export const FunctionParameters : FC < FunctionParametersProps > = ( {
15
20
func,
16
- prefix = "" ,
21
+ prefix = undefined ,
17
22
} ) => {
18
23
return (
19
24
< div class = "space-y-6" >
@@ -23,7 +28,7 @@ export const FunctionParameters: FC<FunctionParametersProps> = ({
23
28
class = "bg-gray-50 rounded-md p-4 border border-gray-100"
24
29
>
25
30
< h4
26
- id = { ` ${ prefix } - ${ func . name } -parameters- ${ param . name } ` }
31
+ id = { buildParamId ( param . name , prefix ) }
27
32
class = "flex flex-wrap items-center gap-2 mb-3"
28
33
>
29
34
< code class = "text-base font-medium" > { param . name } </ code >
Original file line number Diff line number Diff line change @@ -4,6 +4,30 @@ export type TableOfContentsProps = {
4
4
outline : OutlineItem [ ] ;
5
5
} ;
6
6
7
+ const PlainTableOfContents = ( {
8
+ outline,
9
+ topLevel = false ,
10
+ } : TableOfContentsProps & { topLevel ?: boolean } ) => {
11
+ return (
12
+ // Indent for succeeding levels
13
+ < ol class = { `space-y-1 ${ ! topLevel && "pl-4" } text-sm text-neutral-700` } >
14
+ { outline . map ( ( item ) => (
15
+ < li key = { item . id } data-assoc = { item . id } >
16
+ < a
17
+ href = { `#${ item . id } ` }
18
+ class = "block px-2 py-1 rounded hover:bg-neutral-100 transition-colors"
19
+ >
20
+ { item . name }
21
+ </ a >
22
+ { item . children . length > 0 && (
23
+ < PlainTableOfContents outline = { item . children } />
24
+ ) }
25
+ </ li >
26
+ ) ) }
27
+ </ ol >
28
+ ) ;
29
+ } ;
30
+
7
31
export const TableOfContents = ( { outline } : TableOfContentsProps ) => {
8
32
if ( outline . length === 0 ) {
9
33
return null ;
@@ -17,18 +41,7 @@ export const TableOfContents = ({ outline }: TableOfContentsProps) => {
17
41
< strong class = "block mb-2 text-sm text-neutral-500 font-semibold tracking-wide" >
18
42
目次
19
43
</ strong >
20
- < ol class = "space-y-1 text-sm text-neutral-700" >
21
- { outline . map ( ( item ) => (
22
- < li key = { item . id } data-assoc = { item . id } >
23
- < a
24
- href = { `#${ item . id } ` }
25
- class = "block px-2 py-1 rounded hover:bg-neutral-100 transition-colors"
26
- >
27
- { item . name }
28
- </ a >
29
- </ li >
30
- ) ) }
31
- </ ol >
44
+ < PlainTableOfContents outline = { outline } topLevel = { true } />
32
45
</ nav >
33
46
) ;
34
47
} ;
Original file line number Diff line number Diff line change @@ -58,3 +58,28 @@ export const type2href = (parameterType: string): string | null => {
58
58
}
59
59
return null ;
60
60
} ;
61
+
62
+ /**
63
+ * Build the ID of a parameter with prefix
64
+ *
65
+ * If the parameter belongs to a top-level function on a page, leave `prefix` empty;
66
+ * Otherwise, set it to an appropriate prefix.
67
+ *
68
+ * ## Example values of `prefix`
69
+ *
70
+ * | Page (kind) | Function | Parameter | `prefix` |
71
+ * | ------------------- | ---------------- | ---------- | ----------------------- |
72
+ * | `figure` (function) | `figure` | `body` | `undefined` |
73
+ * | `figure` (function) | `figure.caption` | `body` | `"definitions-caption"` |
74
+ * | `calc` (group) | `calc.abs` | `value` | `"functions-abs"` |
75
+ * | `array` (type) | `array.at` | `index` | `"definitions-at"` |
76
+ * | `array` (type) | Constructor | `value` | `"constructor"` |
77
+ */
78
+ export function buildParamId (
79
+ parameterName : string ,
80
+ prefix : string | undefined ,
81
+ ) : string {
82
+ return prefix === undefined
83
+ ? `parameters-${ parameterName } `
84
+ : `${ prefix } -${ parameterName } ` ;
85
+ }
You can’t perform that action at this time.
0 commit comments