Skip to content

Commit 4501255

Browse files
chore: sync with upstream models (#17)
1 parent 6515cd1 commit 4501255

File tree

12 files changed

+301
-101
lines changed

12 files changed

+301
-101
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
matrix:
4444
kind: [official]
4545
tag:
46-
- v0.14.0-rc.1
46+
- v0.14.0
4747
- main.2025-09-19.586b049
4848
- v0.13.1
4949
# These are `docs-*` tags in https://github.com/typst-community/dev-builds.

src/components/templates/FuncTemplate.tsx

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import type { FC } from "hono/jsx";
22
import { Translation } from "../../translation/";
33
import type { Func, FuncBody, Page } from "../../types/model";
4+
import {
5+
normalizeDeprecation,
6+
normalizeDetailBlocks,
7+
} from "../../utils/normalizeModel.js";
48
import {
59
FunctionDefinition,
610
FunctionDisplay,
@@ -42,15 +46,28 @@ export const FuncTemplate: FC<FuncTemplateProps> = ({
4246
</small>
4347
</h1>
4448

45-
{content.deprecation && (
46-
<div className="mt-2">
47-
<DeprecationWarning message={content.deprecation} />
48-
</div>
49-
)}
49+
{<DeprecationWarning item={content} level="top" />}
5050

51-
<div class="my-4 text-gray-700">
52-
<HtmlContent html={content.details} />
53-
</div>
51+
{normalizeDetailBlocks(content).map((block) => {
52+
switch (block.kind) {
53+
case "html":
54+
return (
55+
<div class="my-4 text-gray-700">
56+
<HtmlContent html={block.content} />
57+
</div>
58+
);
59+
case "example":
60+
// This will never reach for Typst v0.13.1 and v0.14.0-rc.1 documentations.
61+
return (
62+
<div class="my-6 bg-gray-50 p-4 rounded-md border border-gray-200">
63+
{block.content.title}
64+
<HtmlContent html={block.content.body} />
65+
</div>
66+
);
67+
default:
68+
return null;
69+
}
70+
})}
5471

5572
<h2 id="parameters" class="flex items-baseline gap-1">
5673
<Translation translationKey="parameters" />
@@ -61,14 +78,8 @@ export const FuncTemplate: FC<FuncTemplateProps> = ({
6178
<FunctionDefinition func={content} />
6279
</div>
6380

64-
{content.example && (
65-
<div class="my-6 bg-gray-50 p-4 rounded-md border border-gray-200">
66-
<HtmlContent html={content.example} />
67-
</div>
68-
)}
69-
7081
<div class="my-6">
71-
<FunctionParameters func={content} />
82+
<FunctionParameters params={content.params} />
7283
</div>
7384

7485
<ScopedDefinitions scope={content.scope} />
@@ -121,7 +132,7 @@ function ScopedDefinitions({
121132
<code
122133
class="text-base font-medium"
123134
style={
124-
method.deprecation
135+
normalizeDeprecation(method) !== null
125136
? { textDecoration: "line-through" }
126137
: undefined
127138
}
@@ -135,11 +146,7 @@ function ScopedDefinitions({
135146
</small>
136147
</h3>
137148

138-
{method.deprecation && (
139-
<div className="mt-1">
140-
<DeprecationWarning message={method.deprecation} />
141-
</div>
142-
)}
149+
{<DeprecationWarning item={method} level="scoped" />}
143150

144151
<div class="pl-2">
145152
<FunctionDisplay func={method} prefix={methodId} />

src/components/templates/GroupTemplate.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { FC } from "hono/jsx";
2+
import { Translation } from "../../translation/index.js";
23
import type { GroupBody, Page } from "../../types/model";
3-
import { FunctionDisplay, Tooltip } from "../ui";
4+
import { FunctionDisplay, FunctionParameters, Tooltip } from "../ui";
45
import { HtmlContent } from "../ui/HtmlContent";
56
import BaseTemplate, { type BaseTemplateProps } from "./BaseTemplate";
67

@@ -52,6 +53,19 @@ export const GroupTemplate: FC<GroupTemplateProps> = ({
5253
))}
5354
</>
5455
)}
56+
57+
{content.global_attributes && content.global_attributes.length > 0 && (
58+
<>
59+
<h2 id="global-attributes">
60+
<Translation translationKey="globalAttributes" />
61+
</h2>
62+
<FunctionParameters
63+
params={content.global_attributes}
64+
globalAttributes={true}
65+
prefix="global-attributes"
66+
/>
67+
</>
68+
)}
5569
</BaseTemplate>
5670
);
5771
};
Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,44 @@
11
import type { FC } from "hono/jsx";
2+
import { Translation } from "../../translation/";
3+
import type { WithDeprecation } from "../../types/model";
4+
import { normalizeDeprecation } from "../../utils/normalizeModel.js";
25
import { AlertTriangleIcon } from "../icons";
36

47
type DeprecationWarningProps = {
5-
message: string;
8+
item: WithDeprecation;
9+
level: "top" | "scoped";
610
};
711

12+
/**
13+
* Generate a deprecation warning if the item deprecated; return null otherwise.
14+
*/
815
export const DeprecationWarning: FC<DeprecationWarningProps> = ({
9-
message,
16+
item,
17+
level,
1018
}) => {
11-
return (
19+
const deprecation = normalizeDeprecation(item);
20+
if (!deprecation) {
21+
return null;
22+
}
23+
24+
const body = (
1225
<small className="deprecation ml-2 flex items-center bg-yellow-50 px-2 py-1 rounded-md border border-yellow-200">
1326
<div className="w-4 h-4 text-yellow-500 mr-1.5 flex-shrink-0">
1427
<AlertTriangleIcon />
1528
</div>
16-
<span className="text-xs text-yellow-800">{message}</span>
29+
<span className="text-xs text-yellow-800">
30+
<Translation
31+
translationKey="deprecationWarning"
32+
message={deprecation.message}
33+
until={deprecation.until}
34+
/>
35+
</span>
1736
</small>
1837
);
38+
39+
return level === "top" ? (
40+
<div className="mt-1">{body}</div>
41+
) : (
42+
<div className="mt-2">{body}</div>
43+
);
1944
};

src/components/ui/FunctionDisplay.tsx

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { FC } from "hono/jsx";
22
import { Translation } from "../../translation/";
33
import type { Func } from "../../types/model";
4+
import { normalizeDetailBlocks } from "../../utils/normalizeModel.js";
45
import { ChevronRightIcon } from "../icons";
56
import { FunctionDefinition } from "./FunctionDefinition";
67
import { FunctionParameters } from "./FunctionParameters";
@@ -24,34 +25,42 @@ export const FunctionDisplay: FC<FunctionDisplayProps> = ({
2425
}) => {
2526
return (
2627
<>
27-
<HtmlContent html={func.details} />
28+
{normalizeDetailBlocks(func).map((block) => {
29+
switch (block.kind) {
30+
case "html":
31+
return <HtmlContent html={block.content} />;
32+
case "example":
33+
return isExampleFolding ? (
34+
<details class="folding-example group">
35+
<summary class="flex items-center gap-1 text-sm font-medium text-blue-600 cursor-pointer hover:text-blue-800">
36+
<div class="w-4 h-4 text-gray-400 transform transition-transform duration-200 group-open:rotate-90">
37+
<ChevronRightIcon />
38+
</div>
39+
<Translation
40+
translationKey="showExample"
41+
title={block.content.title}
42+
/>
43+
</summary>
44+
<div class="mt-2 bg-white p-3 rounded-md border border-gray-200 text-sm">
45+
<HtmlContent html={block.content.body} />
46+
</div>
47+
</details>
48+
) : (
49+
<div class="bg-gray-50 p-4 rounded-md border border-gray-200">
50+
<HtmlContent html={block.content.body} />
51+
</div>
52+
);
53+
default:
54+
return null;
55+
}
56+
})}
2857

2958
<div class="my-4">
3059
<FunctionDefinition func={func} prefix={prefix} />
3160
</div>
3261

33-
{func.example && isExampleFolding && (
34-
<details class="my-4 folding-example group">
35-
<summary class="flex items-center gap-1 text-sm font-medium text-blue-600 cursor-pointer hover:text-blue-800">
36-
<div class="w-4 h-4 text-gray-400 transform transition-transform duration-200 group-open:rotate-90">
37-
<ChevronRightIcon />
38-
</div>
39-
<Translation translationKey="showExample" />
40-
</summary>
41-
<div class="mt-2 bg-white p-3 rounded-md border border-gray-200 text-sm">
42-
<HtmlContent html={func.example} />
43-
</div>
44-
</details>
45-
)}
46-
47-
{func.example && !isExampleFolding && (
48-
<div class="my-6 bg-gray-50 p-4 rounded-md border border-gray-200">
49-
<HtmlContent html={func.example} />
50-
</div>
51-
)}
52-
5362
<div class="my-4">
54-
<FunctionParameters func={func} prefix={prefix} />
63+
<FunctionParameters params={func.params} prefix={prefix} />
5564
</div>
5665
</>
5766
);

src/components/ui/FunctionParameters.tsx

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { FC } from "hono/jsx";
22
import { basePath } from "../../metadata";
33
import { Translation } from "../../translation/";
4-
import type { Func } from "../../types/model";
4+
import type { Param } from "../../types/model";
5+
import { normalizeDetailBlocks } from "../../utils/normalizeModel";
56
import { joinPath } from "../../utils/path";
67
import { ChevronRightIcon } from "../icons";
78
import { HtmlContent } from "./HtmlContent";
@@ -10,7 +11,9 @@ import { TypeIcon } from "./TypeIcon";
1011
import { buildParamId, type2href } from "./type2href";
1112

1213
type FunctionParametersProps = {
13-
func: Func;
14+
params: Param[];
15+
/** Whether these parameter are global attributes */
16+
globalAttributes?: boolean;
1417
/**
1518
* The prefix for IDs
1619
*
@@ -20,17 +23,19 @@ type FunctionParametersProps = {
2023
};
2124

2225
export const FunctionParameters: FC<FunctionParametersProps> = ({
23-
func,
26+
params,
27+
globalAttributes = false,
2428
prefix = undefined,
2529
}) => {
30+
const Heading = globalAttributes ? "h3" : "h4";
2631
return (
2732
<div class="space-y-6">
28-
{func.params.map((param, _index) => (
33+
{params.map((param, _index) => (
2934
<div
3035
key={param.name}
3136
class="bg-gray-50 rounded-md p-4 border border-gray-100"
3237
>
33-
<h4
38+
<Heading
3439
id={buildParamId(param.name, prefix)}
3540
class="flex flex-wrap items-center gap-2 mb-3"
3641
>
@@ -56,24 +61,37 @@ export const FunctionParameters: FC<FunctionParametersProps> = ({
5661
{param.variadic && <Tooltip kind="variadic" />}
5762
{param.settable && <Tooltip kind="settable" />}
5863
</div>
59-
</h4>
64+
</Heading>
6065

61-
<div class="mb-3 text-gray-700">
62-
<HtmlContent html={param.details} />
63-
</div>
64-
65-
{param.default && (
66-
<p class="mt-3 text-sm">
67-
<span class="font-medium">
68-
<Translation translationKey="defaultValue" />
69-
</span>{" "}
70-
<span class="text-gray-700">
71-
<HtmlContent html={param.default} />
72-
</span>
73-
</p>
74-
)}
75-
76-
{/* Put all collapsible blocks after non-collapsible blocks. */}
66+
{normalizeDetailBlocks(param).map((block) => {
67+
switch (block.kind) {
68+
case "html":
69+
return (
70+
<div class="text-gray-700">
71+
<HtmlContent html={block.content} />
72+
</div>
73+
);
74+
case "example":
75+
return (
76+
<details class="folding-example group">
77+
<summary class="flex items-center gap-1 text-sm font-medium text-blue-600 cursor-pointer hover:text-blue-800">
78+
<div class="w-4 h-4 text-gray-400 transform transition-transform duration-200 group-open:rotate-90">
79+
<ChevronRightIcon />
80+
</div>
81+
<Translation
82+
translationKey="showExample"
83+
title={block.content.title}
84+
/>
85+
</summary>
86+
<div class="mt-2 bg-white p-3 rounded-md border border-gray-200 text-sm">
87+
<HtmlContent html={block.content.body} />
88+
</div>
89+
</details>
90+
);
91+
default:
92+
return null;
93+
}
94+
})}
7795

7896
{param.strings.length > 0 && (
7997
<details
@@ -104,18 +122,15 @@ export const FunctionParameters: FC<FunctionParametersProps> = ({
104122
</details>
105123
)}
106124

107-
{param.example && (
108-
<details class="my-4 folding-example group">
109-
<summary class="flex items-center gap-1 text-sm font-medium text-blue-600 cursor-pointer hover:text-blue-800">
110-
<div class="w-4 h-4 text-gray-400 transform transition-transform duration-200 group-open:rotate-90">
111-
<ChevronRightIcon />
112-
</div>
113-
<Translation translationKey="showExample" />
114-
</summary>
115-
<div class="mt-2 bg-white p-3 rounded-md border border-gray-200 text-sm">
116-
<HtmlContent html={param.example} />
117-
</div>
118-
</details>
125+
{param.default && (
126+
<p class="mt-5 text-sm">
127+
<span class="font-medium">
128+
<Translation translationKey="defaultValue" />
129+
</span>{" "}
130+
<span class="text-gray-700">
131+
<HtmlContent html={param.default} />
132+
</span>
133+
</p>
119134
)}
120135
</div>
121136
))}

src/components/ui/type2href.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ export const type2href = (parameterType: string): string | null => {
7373
* | `figure` (function) | `figure.caption` | `body` | `"definitions-caption"` |
7474
* | `calc` (group) | `calc.abs` | `value` | `"functions-abs"` |
7575
* | `array` (type) | `array.at` | `index` | `"definitions-at"` |
76-
* | `array` (type) | Constructor | `value` | `"constructor"` |
76+
* | `array` (type) | Constructor | `value` | `"constructor"` |
77+
* | typed HTML functions (in a group) | `id` | `"global-attributes"` |
7778
*/
7879
export function buildParamId(
7980
parameterName: string,

0 commit comments

Comments
 (0)