Skip to content

Commit 7a2a9dd

Browse files
committed
refactor: Simplify some of the theme code
1 parent 37ae3a4 commit 7a2a9dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+307
-347
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# Disable core.autocrlf's line ending conversion behavior to prevent test failures on Windows
22
* text=auto eol=lf
3+
4+
*.png binary
5+
*.psd binary

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"postpublish": "node scripts/set_strict.js true",
8686
"clean": "rm -rf node_modules package-lock.json lib coverage",
8787
"test:visual-regression-report": "node ./dist/test/capture-screenshots.js && reg-suit compare",
88-
"test:visual-regression-report:copy-actual-to-expected": "mkdir -p ./dist/tmp/.reg/expected/foo && rm -r ./dist/tmp/.reg/expected/* && cp -r ./dist/tmp/__screenshots__/* ./dist/tmp/.reg/expected/"
88+
"test:visual-regression-report:accept": "node ./scripts/accept_visual_regression.js"
8989
},
9090
"keywords": [
9191
"typescript",

scripts/accept_visual_regression.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ts-check
2+
3+
const { remove, copy } = require("../dist/lib/utils/fs");
4+
const { join } = require("path");
5+
6+
const expectedDir = join(__dirname, "../dist/tmp/.reg/expected");
7+
const outputDir = join(__dirname, "../dist/tmp/__screenshots__");
8+
9+
remove(expectedDir)
10+
.then(() => copy(outputDir, expectedDir))
11+
.catch((err) => {
12+
console.error(err);
13+
process.exit(1);
14+
});

src/lib/output/themes/default/partials/header.tsx

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export const header =
5656
</label>
5757
{!props.settings.excludeExternals && (
5858
<>
59-
{" "}
6059
<input type="checkbox" id="tsd-filter-externals" checked={true} />
6160
<label class="tsd-widget" for="tsd-filter-externals">
6261
Externals
@@ -77,22 +76,20 @@ export const header =
7776
<div class="container">
7877
{!!props.model.parent && <ul class="tsd-breadcrumb">{partials.breadcrumb(props.model)}</ul>}
7978
<h1>
80-
<>
81-
{props.model.kindString !== "Project" && `${props.model.kindString ?? ""} `}
82-
{props.model.name}
83-
{hasTypeParameters(props.model) && (
84-
<>
85-
{"<"}
86-
{props.model.typeParameters.map((item, i) => (
87-
<>
88-
{i > 0 && ", "}
89-
{item.name}
90-
</>
91-
))}
92-
{">"}
93-
</>
94-
)}
95-
</>
79+
{props.model.kindString !== "Project" && `${props.model.kindString ?? ""} `}
80+
{props.model.name}
81+
{hasTypeParameters(props.model) && (
82+
<>
83+
{"<"}
84+
{props.model.typeParameters.map((item, i) => (
85+
<>
86+
{i > 0 && ", "}
87+
{item.name}
88+
</>
89+
))}
90+
{">"}
91+
</>
92+
)}
9693
</h1>
9794
</div>
9895
</div>

src/lib/output/themes/default/partials/member.declaration.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { wbr } from "../../lib";
1+
import { wbr, join } from "../../lib";
22
import { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
33
import { createElement } from "../../../../utils";
44
import { DeclarationReflection, ReflectionType } from "../../../../models";
@@ -12,17 +12,12 @@ export const memberDeclaration =
1212
{!!props.typeParameters && (
1313
<>
1414
{"<"}
15-
{props.typeParameters.map((item, i) => (
16-
<>
17-
{i > 0 && ",\xA0"}
18-
{item.name}
19-
</>
20-
))}
15+
{join(", ", props.typeParameters, (item) => item.name)}
2116
{">"}
2217
</>
2318
)}
2419
<span class="tsd-signature-symbol">{!!props.flags.isOptional && "?"}:</span>{" "}
25-
{props.type && partials.type(props.type)}
20+
{partials.type(props.type)}
2621
{!!props.defaultValue && (
2722
<>
2823
<span class="tsd-signature-symbol">
@@ -44,12 +39,10 @@ export const memberDeclaration =
4439
</>
4540
)}
4641
{props.type instanceof ReflectionType && (
47-
<>
48-
<div class="tsd-type-declaration">
49-
<h4>Type declaration</h4>
50-
{partials.parameter(props.type.declaration)}
51-
</div>
52-
</>
42+
<div class="tsd-type-declaration">
43+
<h4>Type declaration</h4>
44+
{partials.parameter(props.type.declaration)}
45+
</div>
5346
)}
5447
</>
5548
);

src/lib/output/themes/default/partials/member.signature.body.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
22
import { createElement, Raw } from "../../../../utils";
33
import { ReflectionType, SignatureReflection } from "../../../../models";
4+
import { renderFlags } from "../../lib";
45
export const memberSignatureBody =
56
({ partials, markdown }: DefaultThemeRenderContext) =>
67
(props: SignatureReflection, { hideSources = false }: { hideSources?: boolean } = {}) =>
78
(
89
<>
9-
{!hideSources && <> {partials.memberSources(props)}</>}
10+
{!hideSources && partials.memberSources(props)}
1011
{partials.comment(props)}
1112

1213
{!!props.typeParameters && (
@@ -22,15 +23,11 @@ export const memberSignatureBody =
2223
{props.parameters.map((item) => (
2324
<li>
2425
<h5>
25-
{item.flags.map((item) => (
26-
<>
27-
<span class={"tsd-flag ts-flag" + item}>{item}</span>{" "}
28-
</>
29-
))}
26+
{renderFlags(item.flags)}
3027
{!!item.flags.isRest && <span class="tsd-signature-symbol">...</span>}
3128
{item.name}
3229
{": "}
33-
{item.type && partials.type(item.type)}
30+
{partials.type(item.type)}
3431
{item.defaultValue != null && (
3532
<span class="tsd-signature-symbol">
3633
{" = "}

src/lib/output/themes/default/partials/member.signature.title.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { wbr } from "../../lib";
1+
import { join, wbr } from "../../lib";
22
import { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
33
import { createElement } from "../../../../utils";
44
import { SignatureReflection } from "../../../../models";
@@ -25,38 +25,28 @@ export const memberSignatureTitle =
2525
{!!props.typeParameters && (
2626
<>
2727
{"<"}
28-
{props.typeParameters.map((item, i) => (
29-
<>
30-
{i > 0 && ", "}
31-
{item.name}
32-
</>
33-
))}
28+
{join(", ", props.typeParameters, (item) => item.name)}
3429
{">"}
3530
</>
3631
)}
3732
<span class="tsd-signature-symbol">(</span>
38-
{props.parameters?.map((item, i) => (
33+
{join(", ", props.parameters ?? [], (item) => (
3934
<>
40-
{!!i && ", "}
4135
{!!item.flags.isRest && <span class="tsd-signature-symbol">...</span>}
4236
{item.name}
4337
<span class="tsd-signature-symbol">
4438
{!!item.flags.isOptional && "?"}
4539
{!!item.defaultValue && "?"}
4640
{": "}
4741
</span>
48-
{item.type && partials.type(item.type)}
42+
{partials.type(item.type)}
4943
</>
5044
))}
5145
<span class="tsd-signature-symbol">)</span>
5246
{!!props.type && (
5347
<>
54-
{arrowStyle ? (
55-
<span class="tsd-signature-symbol"> ={">"} </span>
56-
) : (
57-
<span class="tsd-signature-symbol">: </span>
58-
)}
59-
{!!props.type && partials.type(props.type)}
48+
<span class="tsd-signature-symbol">{arrowStyle ? " => " : ": "}</span>
49+
{partials.type(props.type)}
6050
</>
6151
)}
6252
</>

src/lib/output/themes/default/partials/member.sources.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export const memberSources =
77
(
88
<>
99
<aside class="tsd-sources">
10-
{" "}
1110
{!!props.implementationOf && (
1211
<p>
1312
{"Implementation of "}

src/lib/output/themes/default/partials/member.tsx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertIsDeclarationReflection, wbr } from "../../lib";
1+
import { assertIsDeclarationReflection, renderFlags, wbr } from "../../lib";
22
import { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
33
import { createElement } from "../../../../utils";
44
import { DeclarationReflection, ReferenceReflection } from "../../../../models";
@@ -11,23 +11,17 @@ export const member =
1111
<a name={props.anchor} class="tsd-anchor"></a>
1212
{!!props.name && (
1313
<h3>
14-
{props.flags.map((item) => (
15-
<>
16-
<span class={"tsd-flag ts-flag" + item}>{item}</span>{" "}
17-
</>
18-
))}
14+
{renderFlags(props.flags)}
1915
{wbr(props.name)}
2016
</h3>
2117
)}
22-
{props.signatures ? (
23-
<> {partials.memberSignatures(props)}</>
24-
) : props.hasGetterOrSetter() ? (
25-
partials.memberGetterSetter(props)
26-
) : props instanceof ReferenceReflection ? (
27-
partials.memberReference(props)
28-
) : (
29-
<> {partials.memberDeclaration(props)}</>
30-
)}
18+
{props.signatures
19+
? partials.memberSignatures(props)
20+
: props.hasGetterOrSetter()
21+
? partials.memberGetterSetter(props)
22+
: props instanceof ReferenceReflection
23+
? partials.memberReference(props)
24+
: partials.memberDeclaration(props)}
3125

3226
{props.groups?.map((item) =>
3327
item.children.map(

src/lib/output/themes/default/partials/members.group.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ export const membersGroup =
1414
{group.title}
1515
</h2>
1616
{item.children.map(
17-
(item) => !item.hasOwnDocument && <> {partials.member(assertIsDeclarationReflection(item))}</>
17+
(item) => !item.hasOwnDocument && partials.member(assertIsDeclarationReflection(item))
1818
)}
1919
</section>
2020
))
2121
) : (
22-
<>
23-
<section class={"tsd-panel-group tsd-member-group " + group.cssClasses}>
24-
<h2>{group.title}</h2>
25-
{group.children.map(
26-
(item) => !item.hasOwnDocument && <> {partials.member(assertIsDeclarationReflection(item))}</>
27-
)}
28-
</section>
29-
</>
22+
<section class={"tsd-panel-group tsd-member-group " + group.cssClasses}>
23+
<h2>{group.title}</h2>
24+
{group.children.map(
25+
(item) => !item.hasOwnDocument && partials.member(assertIsDeclarationReflection(item))
26+
)}
27+
</section>
3028
);

0 commit comments

Comments
 (0)