-
Notifications
You must be signed in to change notification settings - Fork 1
/
getInterfaceTable.ts
182 lines (164 loc) · 4.93 KB
/
getInterfaceTable.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import { MarkdownEmitter } from "@microsoft/api-documenter/lib/markdown/MarkdownEmitter";
import { DocEmphasisSpan } from "@microsoft/api-documenter/lib/nodes/DocEmphasisSpan";
import { DocTable } from "@microsoft/api-documenter/lib/nodes/DocTable";
import { DocTableRow } from "@microsoft/api-documenter/lib/nodes/DocTableRow";
import {
ApiDocumentedItem,
ApiInterface,
ApiItem,
ApiPropertyItem,
ApiReleaseTagMixin,
ReleaseTag,
} from "@microsoft/api-extractor-model";
import {
DocParagraph,
DocPlainText,
DocSection,
StringBuilder,
TSDocConfiguration,
} from "@microsoft/tsdoc";
import { ApiItems } from "../api/getApiItems";
import { createParagraphForTypeExcerpt } from "./createParagraphForTypeExcerpt";
import { IndentedTableCell } from "./IndentedTableCell";
const createTitleCell = (
apiItem: ApiItem,
{ configuration }: { configuration: TSDocConfiguration }
): IndentedTableCell => {
return new IndentedTableCell(
{ configuration },
[
new DocParagraph({ configuration }, [
new DocPlainText({ configuration, text: apiItem.displayName }),
]),
],
{ isIndented: true, characterBreakingLine: "," }
);
};
const createPropertyTypeCell = (
apiItem: ApiItem,
{
configuration,
items,
}: { configuration: TSDocConfiguration; items: ApiItems }
): IndentedTableCell => {
const section: DocSection = new DocSection({ configuration });
if (apiItem instanceof ApiPropertyItem) {
section.appendNode(
createParagraphForTypeExcerpt(apiItem.propertyTypeExcerpt, {
configuration,
items,
})
);
}
return new IndentedTableCell({ configuration }, section.nodes, {
isIndented: true,
characterBreakingLine: ";",
});
};
const createDescriptionCell = (
apiItem: ApiItem,
{ configuration }: { configuration: TSDocConfiguration }
): IndentedTableCell => {
const section: DocSection = new DocSection({ configuration });
if (ApiReleaseTagMixin.isBaseClassOf(apiItem)) {
if (apiItem.releaseTag === ReleaseTag.Beta) {
section.appendNodesInParagraph([
new DocEmphasisSpan({ configuration, bold: true, italic: true }, [
new DocPlainText({ configuration, text: "(BETA)" }),
]),
new DocPlainText({ configuration, text: " " }),
]);
}
}
if (apiItem instanceof ApiDocumentedItem) {
if (apiItem.tsdocComment !== undefined) {
let firstNode: boolean = true;
for (const node of apiItem.tsdocComment.summarySection.nodes) {
if (firstNode) {
if (node.kind === "Paragraph") {
section.appendNodesInParagraph(node.getChildNodes());
firstNode = false;
continue;
}
}
firstNode = false;
section.appendNode(node);
}
}
}
return new IndentedTableCell({ configuration }, section.nodes);
};
export const getInterfaceTable = (
item: ApiInterface,
{
configuration,
items,
markdownEmitter,
}: {
configuration: TSDocConfiguration;
items: ApiItems;
markdownEmitter: MarkdownEmitter;
}
): string => {
const docSection = new DocSection({ configuration });
const eventsTable = new DocTable({
configuration,
headerTitles: ["Property", "Type", "Description"],
});
const propertiesTable = new DocTable({
configuration,
headerTitles: ["Property", "Type", "Description"],
});
const methodsTable = new DocTable({
configuration,
headerTitles: ["Method", "Description"],
});
for (const apiMember of item.members) {
switch (apiMember.kind) {
case "ConstructSignature":
case "MethodSignature": {
methodsTable.addRow(
new DocTableRow({ configuration }, [
createTitleCell(apiMember, { configuration }),
createDescriptionCell(apiMember, { configuration }),
])
);
break;
}
case "PropertySignature": {
if ((apiMember as ApiPropertyItem).isEventProperty) {
eventsTable.addRow(
new DocTableRow({ configuration }, [
createTitleCell(apiMember, { configuration }),
createPropertyTypeCell(apiMember, { configuration, items }),
createDescriptionCell(apiMember, { configuration }),
])
);
} else {
propertiesTable.addRow(
new DocTableRow({ configuration }, [
createTitleCell(apiMember, { configuration }),
createPropertyTypeCell(apiMember, { configuration, items }),
createDescriptionCell(apiMember, { configuration }),
])
);
}
break;
}
}
}
if (eventsTable.rows.length > 0) {
docSection.appendNode(eventsTable);
}
if (propertiesTable.rows.length > 0) {
docSection.appendNode(propertiesTable);
}
if (methodsTable.rows.length > 0) {
docSection.appendNode(methodsTable);
}
return markdownEmitter
.emit(new StringBuilder(), docSection, {
configuration,
})
.trim();
};