mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 18:13:29 +01:00
feat(website): Show constructor information (#8540)
This commit is contained in:
381
packages/website/src/DocModel/ApiNodeJSONEncoder.ts
Normal file
381
packages/website/src/DocModel/ApiNodeJSONEncoder.ts
Normal file
@@ -0,0 +1,381 @@
|
||||
import {
|
||||
ApiModel,
|
||||
ApiDeclaredItem,
|
||||
ApiPropertyItem,
|
||||
ApiMethod,
|
||||
ApiParameterListMixin,
|
||||
ApiTypeParameterListMixin,
|
||||
ApiClass,
|
||||
ApiFunction,
|
||||
ApiItemKind,
|
||||
ApiTypeAlias,
|
||||
ApiEnum,
|
||||
ApiInterface,
|
||||
ApiMethodSignature,
|
||||
ApiPropertySignature,
|
||||
ApiVariable,
|
||||
ApiItem,
|
||||
ApiConstructor,
|
||||
ApiItemContainerMixin,
|
||||
} from '@microsoft/api-extractor-model';
|
||||
import { generateTypeParamData } from './TypeParameterMixin';
|
||||
import { Visibility } from './Visibility';
|
||||
import { createCommentNode } from './comment';
|
||||
import type { DocBlockJSON } from './comment/CommentBlock';
|
||||
import type { AnyDocNodeJSON } from './comment/CommentNode';
|
||||
import { DocNodeContainerJSON, nodeContainer } from './comment/CommentNodeContainer';
|
||||
import {
|
||||
generatePath,
|
||||
genParameter,
|
||||
genReference,
|
||||
genToken,
|
||||
resolveName,
|
||||
TokenDocumentation,
|
||||
} from '~/util/parse.server';
|
||||
|
||||
export interface ReferenceData {
|
||||
name: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface InheritanceData {
|
||||
parentName: string;
|
||||
path: string;
|
||||
parentKey: string;
|
||||
}
|
||||
|
||||
export interface ApiInheritableJSON {
|
||||
inheritanceData: InheritanceData | null;
|
||||
}
|
||||
|
||||
export interface ApiItemJSON {
|
||||
kind: string;
|
||||
name: string;
|
||||
referenceData: ReferenceData;
|
||||
excerpt: string;
|
||||
excerptTokens: TokenDocumentation[];
|
||||
remarks: DocNodeContainerJSON | null;
|
||||
summary: DocNodeContainerJSON | null;
|
||||
deprecated: DocNodeContainerJSON | null;
|
||||
comment: AnyDocNodeJSON | null;
|
||||
containerKey: string;
|
||||
path: string[];
|
||||
}
|
||||
|
||||
export interface ApiPropertyItemJSON extends ApiItemJSON, ApiInheritableJSON {
|
||||
propertyTypeTokens: TokenDocumentation[];
|
||||
readonly: boolean;
|
||||
optional: boolean;
|
||||
}
|
||||
|
||||
export interface ApiTypeParameterListJSON {
|
||||
typeParameters: ApiTypeParameterJSON[];
|
||||
}
|
||||
|
||||
export interface ApiTypeParameterJSON {
|
||||
name: string;
|
||||
constraintTokens: TokenDocumentation[];
|
||||
defaultTokens: TokenDocumentation[];
|
||||
optional: boolean;
|
||||
commentBlock: DocBlockJSON | null;
|
||||
}
|
||||
|
||||
export interface ApiParameterListJSON {
|
||||
parameters: ApiParameterJSON[];
|
||||
}
|
||||
|
||||
export interface ApiMethodSignatureJSON
|
||||
extends ApiItemJSON,
|
||||
ApiTypeParameterListJSON,
|
||||
ApiParameterListJSON,
|
||||
ApiInheritableJSON {
|
||||
returnTypeTokens: TokenDocumentation[];
|
||||
optional: boolean;
|
||||
overloadIndex: number;
|
||||
}
|
||||
|
||||
export interface ApiMethodJSON extends ApiMethodSignatureJSON {
|
||||
static: boolean;
|
||||
visibility: Visibility;
|
||||
}
|
||||
|
||||
export interface ApiParameterJSON {
|
||||
name: string;
|
||||
isOptional: boolean;
|
||||
tokens: TokenDocumentation[];
|
||||
paramCommentBlock: DocBlockJSON | null;
|
||||
}
|
||||
|
||||
export interface ApiClassJSON extends ApiItemJSON, ApiTypeParameterListJSON {
|
||||
constructor: ApiConstructorJSON | null;
|
||||
properties: ApiPropertyItemJSON[];
|
||||
methods: ApiMethodJSON[];
|
||||
extendsTokens: TokenDocumentation[];
|
||||
implementsTokens: TokenDocumentation[][];
|
||||
}
|
||||
|
||||
export interface ApiTypeAliasJSON extends ApiItemJSON, ApiTypeParameterListJSON {
|
||||
typeTokens: TokenDocumentation[];
|
||||
}
|
||||
|
||||
export interface EnumMemberData {
|
||||
name: string;
|
||||
initializerTokens: TokenDocumentation[];
|
||||
summary: DocNodeContainerJSON | null;
|
||||
}
|
||||
|
||||
export interface ApiEnumJSON extends ApiItemJSON {
|
||||
members: EnumMemberData[];
|
||||
}
|
||||
|
||||
export interface ApiInterfaceJSON extends ApiItemJSON, ApiTypeParameterListJSON {
|
||||
properties: ApiPropertyItemJSON[];
|
||||
methods: ApiMethodSignatureJSON[];
|
||||
extendsTokens: TokenDocumentation[][] | null;
|
||||
}
|
||||
|
||||
export interface ApiVariableJSON extends ApiItemJSON {
|
||||
typeTokens: TokenDocumentation[];
|
||||
readonly: boolean;
|
||||
}
|
||||
|
||||
export interface ApiFunctionJSON extends ApiItemJSON, ApiTypeParameterListJSON, ApiParameterListJSON {
|
||||
returnTypeTokens: TokenDocumentation[];
|
||||
overloadIndex: number;
|
||||
}
|
||||
|
||||
export interface ApiConstructorJSON extends ApiItemJSON, ApiParameterListJSON {
|
||||
protected: boolean;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
||||
export class ApiNodeJSONEncoder {
|
||||
public static encode(model: ApiModel, node: ApiItem) {
|
||||
if (!(node instanceof ApiDeclaredItem)) {
|
||||
throw new Error(`Cannot serialize node of type ${node.kind}`);
|
||||
}
|
||||
|
||||
switch (node.kind) {
|
||||
case ApiItemKind.Class:
|
||||
return this.encodeClass(model, node as ApiClass);
|
||||
case ApiItemKind.Function:
|
||||
return this.encodeFunction(model, node as ApiFunction);
|
||||
case ApiItemKind.Interface:
|
||||
return this.encodeInterface(model, node as ApiInterface);
|
||||
case ApiItemKind.TypeAlias:
|
||||
return this.encodeTypeAlias(model, node as ApiTypeAlias);
|
||||
case ApiItemKind.Enum:
|
||||
return this.encodeEnum(model, node as ApiEnum);
|
||||
case ApiItemKind.Variable:
|
||||
return this.encodeVariable(model, node as ApiVariable);
|
||||
default:
|
||||
throw new Error(`Unknown API item kind: ${node.kind}`);
|
||||
}
|
||||
}
|
||||
|
||||
public static encodeItem(model: ApiModel, item: ApiDeclaredItem): ApiItemJSON {
|
||||
const path = [];
|
||||
for (const _item of item.getHierarchy()) {
|
||||
switch (_item.kind) {
|
||||
case 'None':
|
||||
case 'EntryPoint':
|
||||
case 'Model':
|
||||
break;
|
||||
default:
|
||||
path.push(resolveName(_item));
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
kind: item.kind,
|
||||
name: resolveName(item),
|
||||
referenceData: genReference(item),
|
||||
excerpt: item.excerpt.text,
|
||||
excerptTokens: item.excerpt.spannedTokens.map((token) => genToken(model, token)),
|
||||
remarks: item.tsdocComment?.remarksBlock
|
||||
? (createCommentNode(item.tsdocComment.remarksBlock, model, item.parent) as DocNodeContainerJSON)
|
||||
: null,
|
||||
summary: item.tsdocComment?.summarySection
|
||||
? (createCommentNode(item.tsdocComment.summarySection, model, item.parent) as DocNodeContainerJSON)
|
||||
: null,
|
||||
deprecated: item.tsdocComment?.deprecatedBlock
|
||||
? (createCommentNode(item.tsdocComment.deprecatedBlock, model, item.parent) as DocNodeContainerJSON)
|
||||
: null,
|
||||
path,
|
||||
containerKey: item.containerKey,
|
||||
comment: item.tsdocComment ? createCommentNode(item.tsdocComment, model, item.parent) : null,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeParameterList(
|
||||
model: ApiModel,
|
||||
item: ApiParameterListMixin & ApiDeclaredItem,
|
||||
): { parameters: ApiParameterJSON[] } {
|
||||
return {
|
||||
parameters: item.parameters.map((param) => genParameter(model, param)),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeTypeParameterList(model: ApiModel, item: ApiTypeParameterListMixin & ApiDeclaredItem) {
|
||||
return {
|
||||
typeParameters: item.typeParameters.map((param) => generateTypeParamData(model, param, item.parent)),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeProperty(
|
||||
model: ApiModel,
|
||||
item: ApiPropertyItem,
|
||||
parent: ApiItemContainerMixin,
|
||||
): ApiPropertyItemJSON {
|
||||
return {
|
||||
...this.encodeItem(model, item),
|
||||
...this.encodeInheritanceData(item, parent),
|
||||
propertyTypeTokens: item.propertyTypeExcerpt.spannedTokens.map((token) => genToken(model, token)),
|
||||
readonly: item.isReadonly,
|
||||
optional: item.isOptional,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeInheritanceData(item: ApiDeclaredItem, parent: ApiItemContainerMixin): ApiInheritableJSON {
|
||||
return {
|
||||
inheritanceData:
|
||||
item.parent && item.parent.containerKey !== parent.containerKey
|
||||
? {
|
||||
parentKey: item.parent.containerKey,
|
||||
parentName: item.parent.displayName,
|
||||
path: generatePath(item.parent.getHierarchy()),
|
||||
}
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeFunction(model: ApiModel, item: ApiFunction) {
|
||||
return {
|
||||
...this.encodeItem(model, item),
|
||||
...this.encodeParameterList(model, item),
|
||||
...this.encodeTypeParameterList(model, item),
|
||||
returnTypeTokens: item.returnTypeExcerpt.spannedTokens.map((token) => genToken(model, token)),
|
||||
overloadIndex: item.overloadIndex,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeMethodSignature(
|
||||
model: ApiModel,
|
||||
item: ApiMethodSignature,
|
||||
parent: ApiItemContainerMixin,
|
||||
): ApiMethodSignatureJSON {
|
||||
return {
|
||||
...this.encodeFunction(model, item),
|
||||
...this.encodeInheritanceData(item, parent),
|
||||
optional: item.isOptional,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeMethod(model: ApiModel, item: ApiMethod, parent: ApiItemContainerMixin): ApiMethodJSON {
|
||||
return {
|
||||
...this.encodeMethodSignature(model, item, parent),
|
||||
static: item.isStatic,
|
||||
visibility: item.isProtected ? Visibility.Protected : Visibility.Public,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeClass(model: ApiModel, item: ApiClass): ApiClassJSON {
|
||||
const extendsExcerpt = item.extendsType?.excerpt;
|
||||
|
||||
const methods: ApiMethodJSON[] = [];
|
||||
const properties: ApiPropertyItemJSON[] = [];
|
||||
|
||||
let constructor: ApiConstructor | undefined;
|
||||
|
||||
for (const member of item.findMembersWithInheritance().items) {
|
||||
switch (member.kind) {
|
||||
case ApiItemKind.Method:
|
||||
methods.push(this.encodeMethod(model, member as ApiMethod, item));
|
||||
break;
|
||||
case ApiItemKind.Property:
|
||||
properties.push(this.encodeProperty(model, member as ApiPropertyItem, item));
|
||||
break;
|
||||
case ApiItemKind.Constructor:
|
||||
constructor = member as ApiConstructor;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...this.encodeItem(model, item),
|
||||
...this.encodeTypeParameterList(model, item),
|
||||
constructor: constructor ? this.encodeConstructor(model, constructor) : null,
|
||||
extendsTokens: extendsExcerpt ? extendsExcerpt.spannedTokens.map((token) => genToken(model, token)) : [],
|
||||
implementsTokens: item.implementsTypes.map((excerpt) =>
|
||||
excerpt.excerpt.spannedTokens.map((token) => genToken(model, token)),
|
||||
),
|
||||
methods,
|
||||
properties,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeTypeAlias(model: ApiModel, item: ApiTypeAlias): ApiTypeAliasJSON {
|
||||
return {
|
||||
...this.encodeItem(model, item),
|
||||
...this.encodeTypeParameterList(model, item),
|
||||
typeTokens: item.typeExcerpt.spannedTokens.map((token) => genToken(model, token)),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeEnum(model: ApiModel, item: ApiEnum): ApiEnumJSON {
|
||||
return {
|
||||
...this.encodeItem(model, item),
|
||||
members: item.members.map((member) => ({
|
||||
name: member.name,
|
||||
initializerTokens: member.initializerExcerpt?.spannedTokens.map((token) => genToken(model, token)) ?? [],
|
||||
summary: member.tsdocComment ? nodeContainer(member.tsdocComment.summarySection, model, member) : null,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeInterface(model: ApiModel, item: ApiInterface): ApiInterfaceJSON {
|
||||
const methods: ApiMethodSignatureJSON[] = [];
|
||||
const properties: ApiPropertyItemJSON[] = [];
|
||||
|
||||
for (const member of item.findMembersWithInheritance().items) {
|
||||
switch (member.kind) {
|
||||
case ApiItemKind.MethodSignature:
|
||||
methods.push(this.encodeMethodSignature(model, member as ApiMethodSignature, item));
|
||||
break;
|
||||
case ApiItemKind.PropertySignature:
|
||||
properties.push(this.encodeProperty(model, member as ApiPropertySignature, item));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...this.encodeItem(model, item),
|
||||
...this.encodeTypeParameterList(model, item),
|
||||
extendsTokens: item.extendsTypes.map((excerpt) =>
|
||||
excerpt.excerpt.spannedTokens.map((token) => genToken(model, token)),
|
||||
),
|
||||
methods,
|
||||
properties,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeVariable(model: ApiModel, item: ApiVariable): ApiVariableJSON {
|
||||
return {
|
||||
...this.encodeItem(model, item),
|
||||
typeTokens: item.variableTypeExcerpt.spannedTokens.map((token) => genToken(model, token)),
|
||||
readonly: item.isReadonly,
|
||||
};
|
||||
}
|
||||
|
||||
public static encodeConstructor(model: ApiModel, item: ApiConstructor): ApiConstructorJSON {
|
||||
return {
|
||||
...this.encodeItem(model, item),
|
||||
...this.encodeParameterList(model, item),
|
||||
protected: item.isProtected,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
import {
|
||||
type ApiClass,
|
||||
type ApiModel,
|
||||
ApiItemKind,
|
||||
type ApiMethod,
|
||||
type ApiPropertyItem,
|
||||
} from '@microsoft/api-extractor-model';
|
||||
import { DocItem } from './DocItem';
|
||||
import { DocMethod } from './DocMethod';
|
||||
import { DocProperty } from './DocProperty';
|
||||
import { TypeParameterMixin } from './TypeParameterMixin';
|
||||
import { type TokenDocumentation, genToken } from '~/util/parse.server';
|
||||
|
||||
export class DocClass extends TypeParameterMixin(DocItem<ApiClass>) {
|
||||
public readonly extendsTokens: TokenDocumentation[] | null;
|
||||
public readonly implementsTokens: TokenDocumentation[][];
|
||||
public readonly methods: DocMethod[] = [];
|
||||
public readonly properties: DocProperty[] = [];
|
||||
|
||||
public constructor(model: ApiModel, item: ApiClass) {
|
||||
super(model, item);
|
||||
const extendsExcerpt = item.extendsType?.excerpt;
|
||||
|
||||
this.extendsTokens = extendsExcerpt
|
||||
? extendsExcerpt.spannedTokens.map((token) => genToken(this.model, token))
|
||||
: null;
|
||||
|
||||
this.implementsTokens = item.implementsTypes.map((excerpt) =>
|
||||
excerpt.excerpt.spannedTokens.map((token) => genToken(this.model, token)),
|
||||
);
|
||||
|
||||
for (const member of item.findMembersWithInheritance().items) {
|
||||
switch (member.kind) {
|
||||
case ApiItemKind.Method: {
|
||||
const method = member as ApiMethod;
|
||||
|
||||
if (method.parent?.containerKey !== this.containerKey) {
|
||||
this.methods.push(new DocMethod(this.model, method, true));
|
||||
break;
|
||||
}
|
||||
this.methods.push(new DocMethod(this.model, method));
|
||||
break;
|
||||
}
|
||||
case ApiItemKind.Property: {
|
||||
const property = member as ApiPropertyItem;
|
||||
|
||||
if (property.parent?.containerKey !== this.containerKey) {
|
||||
this.properties.push(new DocProperty(this.model, property, true));
|
||||
break;
|
||||
}
|
||||
|
||||
this.properties.push(new DocProperty(this.model, property));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override toJSON() {
|
||||
return {
|
||||
...super.toJSON(),
|
||||
extendsTokens: this.extendsTokens,
|
||||
implementsTokens: this.implementsTokens,
|
||||
methods: this.methods.map((method) => method.toJSON()),
|
||||
properties: this.properties.map((prop) => prop.toJSON()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import type { ApiEnum, ApiModel } from '@microsoft/api-extractor-model';
|
||||
import { DocItem } from './DocItem';
|
||||
import { nodeContainer } from './comment/CommentNodeContainer';
|
||||
import { genToken, TokenDocumentation } from '~/util/parse.server';
|
||||
|
||||
export interface EnumMemberData {
|
||||
name: string;
|
||||
initializerTokens: TokenDocumentation[];
|
||||
summary: ReturnType<DocItem['toJSON']>['summary'];
|
||||
}
|
||||
|
||||
export class DocEnum extends DocItem<ApiEnum> {
|
||||
public readonly members: EnumMemberData[] = [];
|
||||
|
||||
public constructor(model: ApiModel, item: ApiEnum) {
|
||||
super(model, item);
|
||||
|
||||
this.members = item.members.map((member) => ({
|
||||
name: member.name,
|
||||
initializerTokens: member.initializerExcerpt?.spannedTokens.map((token) => genToken(this.model, token)) ?? [],
|
||||
summary: member.tsdocComment ? nodeContainer(member.tsdocComment.summarySection, model, member) : null,
|
||||
}));
|
||||
}
|
||||
|
||||
public override toJSON() {
|
||||
return {
|
||||
...super.toJSON(),
|
||||
members: this.members,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import type { ApiFunction, ApiModel, ApiParameterListMixin } from '@microsoft/api-extractor-model';
|
||||
import { DocItem } from './DocItem';
|
||||
import { TypeParameterMixin } from './TypeParameterMixin';
|
||||
import { type TokenDocumentation, genToken, genParameter, ParameterDocumentation } from '~/util/parse.server';
|
||||
|
||||
export class DocFunction extends TypeParameterMixin(DocItem<ApiFunction>) {
|
||||
public readonly returnTypeTokens: TokenDocumentation[];
|
||||
public readonly overloadIndex: number;
|
||||
public readonly parameters: ParameterDocumentation[];
|
||||
|
||||
public constructor(model: ApiModel, item: ApiFunction) {
|
||||
super(model, item);
|
||||
this.returnTypeTokens = item.returnTypeExcerpt.spannedTokens.map((token) => genToken(this.model, token));
|
||||
this.overloadIndex = item.overloadIndex;
|
||||
this.parameters = (item as ApiParameterListMixin).parameters.map((param) => genParameter(this.model, param));
|
||||
}
|
||||
|
||||
public override toJSON() {
|
||||
return {
|
||||
...super.toJSON(),
|
||||
parameters: this.parameters,
|
||||
returnTypeTokens: this.returnTypeTokens,
|
||||
overloadIndex: this.overloadIndex,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
import { DocItem } from './DocItem';
|
||||
import { DocMethodSignature } from './DocMethodSignature';
|
||||
import { DocProperty } from './DocProperty';
|
||||
import { TypeParameterMixin } from './TypeParameterMixin';
|
||||
import {
|
||||
ApiInterface,
|
||||
ApiItemKind,
|
||||
ApiMethodSignature,
|
||||
ApiModel,
|
||||
ApiPropertySignature,
|
||||
} from '~/util/api-extractor.server';
|
||||
import { type TokenDocumentation, genToken } from '~/util/parse.server';
|
||||
|
||||
export class DocInterface extends TypeParameterMixin(DocItem<ApiInterface>) {
|
||||
public readonly extendsTokens: TokenDocumentation[][] | null;
|
||||
public readonly methods: DocMethodSignature[] = [];
|
||||
public readonly properties: DocProperty[] = [];
|
||||
|
||||
public constructor(model: ApiModel, item: ApiInterface) {
|
||||
super(model, item);
|
||||
|
||||
this.extendsTokens = item.extendsTypes.map((excerpt) =>
|
||||
excerpt.excerpt.spannedTokens.map((token) => genToken(this.model, token)),
|
||||
);
|
||||
|
||||
for (const member of item.findMembersWithInheritance().items) {
|
||||
switch (member.kind) {
|
||||
case ApiItemKind.MethodSignature: {
|
||||
const method = member as ApiMethodSignature;
|
||||
|
||||
if (method.parent?.containerKey !== this.containerKey) {
|
||||
this.methods.push(new DocMethodSignature(this.model, method, true));
|
||||
break;
|
||||
}
|
||||
this.methods.push(new DocMethodSignature(this.model, method));
|
||||
break;
|
||||
}
|
||||
case ApiItemKind.PropertySignature: {
|
||||
const property = member as ApiPropertySignature;
|
||||
|
||||
if (property.parent?.containerKey !== this.containerKey) {
|
||||
this.properties.push(new DocProperty(this.model, property, true));
|
||||
break;
|
||||
}
|
||||
|
||||
this.properties.push(new DocProperty(this.model, property));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override toJSON() {
|
||||
return {
|
||||
...super.toJSON(),
|
||||
extendsTokens: this.extendsTokens,
|
||||
methods: this.methods.map((method) => method.toJSON()),
|
||||
properties: this.properties.map((prop) => prop.toJSON()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
import type { ApiModel, ApiDeclaredItem } from '@microsoft/api-extractor-model';
|
||||
import { createCommentNode } from './comment';
|
||||
import type { AnyDocNodeJSON } from './comment/CommentNode';
|
||||
import type { DocNodeContainerJSON } from './comment/CommentNodeContainer';
|
||||
import type { ReferenceData } from '~/util/model.server';
|
||||
import { resolveName, genReference, TokenDocumentation, genToken } from '~/util/parse.server';
|
||||
|
||||
export type DocItemConstructor<T = DocItem> = new (...args: any[]) => T;
|
||||
|
||||
export class DocItem<T extends ApiDeclaredItem = ApiDeclaredItem> {
|
||||
public readonly item: T;
|
||||
public readonly name: string;
|
||||
public readonly referenceData: ReferenceData;
|
||||
public readonly model: ApiModel;
|
||||
public readonly excerpt: string;
|
||||
public readonly excerptTokens: TokenDocumentation[] = [];
|
||||
public readonly kind: string;
|
||||
public readonly remarks: DocNodeContainerJSON | null;
|
||||
public readonly summary: DocNodeContainerJSON | null;
|
||||
public readonly deprecated: DocNodeContainerJSON | null;
|
||||
public readonly containerKey: string;
|
||||
public readonly comment: AnyDocNodeJSON | null;
|
||||
|
||||
public constructor(model: ApiModel, item: T) {
|
||||
this.item = item;
|
||||
this.kind = item.kind;
|
||||
this.model = model;
|
||||
this.name = resolveName(item);
|
||||
this.referenceData = genReference(item);
|
||||
this.excerpt = item.excerpt.text;
|
||||
this.excerptTokens = item.excerpt.spannedTokens.map((token) => genToken(model, token));
|
||||
this.remarks = item.tsdocComment?.remarksBlock
|
||||
? (createCommentNode(item.tsdocComment.remarksBlock, model, item.parent) as DocNodeContainerJSON)
|
||||
: null;
|
||||
this.summary = item.tsdocComment?.summarySection
|
||||
? (createCommentNode(item.tsdocComment.summarySection, model, item.parent) as DocNodeContainerJSON)
|
||||
: null;
|
||||
this.deprecated = item.tsdocComment?.deprecatedBlock
|
||||
? (createCommentNode(item.tsdocComment.deprecatedBlock, model, item.parent) as DocNodeContainerJSON)
|
||||
: null;
|
||||
this.containerKey = item.containerKey;
|
||||
this.comment = item.tsdocComment ? createCommentNode(item.tsdocComment, model, item.parent) : null;
|
||||
}
|
||||
|
||||
public get path() {
|
||||
const path = [];
|
||||
for (const item of this.item.getHierarchy()) {
|
||||
switch (item.kind) {
|
||||
case 'None':
|
||||
case 'EntryPoint':
|
||||
case 'Model':
|
||||
break;
|
||||
default:
|
||||
path.push(resolveName(item));
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public toJSON() {
|
||||
return {
|
||||
name: this.name,
|
||||
referenceData: this.referenceData,
|
||||
summary: this.summary,
|
||||
excerpt: this.excerpt,
|
||||
excerptTokens: this.excerptTokens,
|
||||
kind: this.kind,
|
||||
remarks: this.remarks,
|
||||
deprecated: this.deprecated,
|
||||
path: this.path,
|
||||
containerKey: this.containerKey,
|
||||
comment: this.comment,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import type { ApiMethod, ApiModel } from '@microsoft/api-extractor-model';
|
||||
import { DocFunction } from './DocFunction';
|
||||
import { Visibility } from './Visibility';
|
||||
import { generatePath } from '~/util/parse.server';
|
||||
|
||||
export interface InheritanceData {
|
||||
parentName: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export class DocMethod extends DocFunction {
|
||||
public readonly static: boolean;
|
||||
public readonly optional: boolean;
|
||||
public readonly visibility: Visibility;
|
||||
public readonly inheritanceData: InheritanceData | null;
|
||||
|
||||
public constructor(model: ApiModel, item: ApiMethod, inherited = false) {
|
||||
super(model, item);
|
||||
this.static = item.isStatic;
|
||||
this.optional = item.isOptional;
|
||||
this.visibility = item.isProtected ? Visibility.Protected : Visibility.Public;
|
||||
this.inheritanceData =
|
||||
inherited && item.parent
|
||||
? {
|
||||
parentName: item.parent.displayName,
|
||||
path: generatePath(item.parent.getHierarchy()),
|
||||
}
|
||||
: null;
|
||||
}
|
||||
|
||||
public override toJSON() {
|
||||
return {
|
||||
...super.toJSON(),
|
||||
static: this.static,
|
||||
optional: this.optional,
|
||||
visibility: this.visibility,
|
||||
inheritanceData: this.inheritanceData,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import type { ApiMethodSignature, ApiModel } from '@microsoft/api-extractor-model';
|
||||
import { DocFunction } from './DocFunction';
|
||||
import type { InheritanceData } from './DocMethod';
|
||||
import { generatePath } from '~/util/parse.server';
|
||||
|
||||
export class DocMethodSignature extends DocFunction {
|
||||
public readonly optional: boolean;
|
||||
public readonly inheritanceData: InheritanceData | null;
|
||||
|
||||
public constructor(model: ApiModel, item: ApiMethodSignature, inherited = false) {
|
||||
super(model, item);
|
||||
this.optional = item.isOptional;
|
||||
this.inheritanceData =
|
||||
inherited && item.parent
|
||||
? {
|
||||
parentName: item.parent.displayName,
|
||||
path: generatePath(item.parent.getHierarchy()),
|
||||
}
|
||||
: null;
|
||||
}
|
||||
|
||||
public override toJSON() {
|
||||
return {
|
||||
...super.toJSON(),
|
||||
optional: this.optional,
|
||||
inheritanceData: this.inheritanceData,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
import type { ApiPropertyItem, ApiModel, ApiPropertySignature } from '@microsoft/api-extractor-model';
|
||||
import { DocItem } from './DocItem';
|
||||
import type { InheritanceData } from './DocMethod';
|
||||
import { type TokenDocumentation, genToken, generatePath } from '~/util/parse.server';
|
||||
|
||||
export class DocProperty extends DocItem<ApiPropertyItem> {
|
||||
public readonly propertyTypeTokens: TokenDocumentation[];
|
||||
public readonly readonly: boolean;
|
||||
public readonly optional: boolean;
|
||||
public readonly inheritanceData: InheritanceData | null;
|
||||
|
||||
public constructor(model: ApiModel, item: ApiPropertyItem | ApiPropertySignature, inherited = false) {
|
||||
super(model, item);
|
||||
this.propertyTypeTokens = item.propertyTypeExcerpt.spannedTokens.map((token) => genToken(this.model, token));
|
||||
this.readonly = item.isReadonly;
|
||||
this.optional = item.isOptional;
|
||||
this.inheritanceData =
|
||||
inherited && item.parent
|
||||
? {
|
||||
parentName: item.parent.displayName,
|
||||
path: generatePath(item.parent.getHierarchy()),
|
||||
}
|
||||
: null;
|
||||
}
|
||||
|
||||
public override toJSON() {
|
||||
return {
|
||||
...super.toJSON(),
|
||||
propertyTypeTokens: this.propertyTypeTokens,
|
||||
readonly: this.readonly,
|
||||
optional: this.optional,
|
||||
inheritanceData: this.inheritanceData,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import type { ApiModel, ApiTypeAlias } from '@microsoft/api-extractor-model';
|
||||
import { DocItem } from './DocItem';
|
||||
import { TypeParameterMixin } from './TypeParameterMixin';
|
||||
import { type TokenDocumentation, genToken } from '~/util/parse.server';
|
||||
|
||||
export class DocTypeAlias extends TypeParameterMixin(DocItem<ApiTypeAlias>) {
|
||||
public readonly typeTokens: TokenDocumentation[];
|
||||
|
||||
public constructor(model: ApiModel, item: ApiTypeAlias) {
|
||||
super(model, item);
|
||||
this.typeTokens = item.typeExcerpt.spannedTokens.map((token) => genToken(model, token));
|
||||
}
|
||||
|
||||
public override toJSON() {
|
||||
return {
|
||||
...super.toJSON(),
|
||||
typeTokens: this.typeTokens,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import type { ApiModel, ApiVariable } from '@microsoft/api-extractor-model';
|
||||
import { DocItem } from './DocItem';
|
||||
import { genToken, TokenDocumentation } from '~/util/parse.server';
|
||||
|
||||
export class DocVariable extends DocItem<ApiVariable> {
|
||||
public readonly typeTokens: TokenDocumentation[] = [];
|
||||
public readonly readonly: boolean;
|
||||
|
||||
public constructor(model: ApiModel, item: ApiVariable) {
|
||||
super(model, item);
|
||||
this.typeTokens = item.variableTypeExcerpt.spannedTokens.map((token) => genToken(model, token));
|
||||
this.readonly = item.isReadonly;
|
||||
}
|
||||
|
||||
public override toJSON() {
|
||||
return {
|
||||
...super.toJSON(),
|
||||
typeTokens: this.typeTokens,
|
||||
readonly: this.readonly,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { ApiItem, ApiModel, ApiTypeParameterListMixin, TypeParameter } from '@microsoft/api-extractor-model';
|
||||
import type { DocItemConstructor } from './DocItem';
|
||||
import type { ApiItem, ApiModel, TypeParameter } from '@microsoft/api-extractor-model';
|
||||
import { block, DocBlockJSON } from './comment/CommentBlock';
|
||||
import { genToken, TokenDocumentation } from '~/util/parse.server';
|
||||
|
||||
@@ -27,24 +26,3 @@ export function generateTypeParamData(
|
||||
commentBlock: typeParam.tsdocTypeParamBlock ? block(typeParam.tsdocTypeParamBlock, model, parentItem) : null,
|
||||
};
|
||||
}
|
||||
|
||||
export function TypeParameterMixin<TBase extends DocItemConstructor>(Base: TBase) {
|
||||
return class Mixed extends Base {
|
||||
public readonly typeParameters: TypeParameterData[] = [];
|
||||
|
||||
public constructor(...args: any[]);
|
||||
public constructor(model: ApiModel, item: ApiItem) {
|
||||
super(model, item);
|
||||
this.typeParameters = (item as ApiTypeParameterListMixin).typeParameters.map((typeParam) =>
|
||||
generateTypeParamData(this.model, typeParam, item.parent),
|
||||
);
|
||||
}
|
||||
|
||||
public override toJSON() {
|
||||
return {
|
||||
...super.toJSON(),
|
||||
typeParameterData: this.typeParameters,
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,8 +3,7 @@ import type { ReactNode } from 'react';
|
||||
import { HyperlinkedText } from './HyperlinkedText';
|
||||
import { InheritanceText } from './InheritanceText';
|
||||
import { TSDoc } from './tsdoc/TSDoc';
|
||||
import type { DocItem } from '~/DocModel/DocItem';
|
||||
import type { InheritanceData } from '~/DocModel/DocMethod';
|
||||
import type { ApiItemJSON, InheritanceData } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
import type { AnyDocNodeJSON } from '~/DocModel/comment/CommentNode';
|
||||
import type { TokenDocumentation } from '~/util/parse.server';
|
||||
|
||||
@@ -30,7 +29,7 @@ export function CodeListing({
|
||||
typeTokens: TokenDocumentation[];
|
||||
readonly?: boolean;
|
||||
optional?: boolean;
|
||||
summary?: ReturnType<DocItem['toJSON']>['summary'];
|
||||
summary?: ApiItemJSON['summary'];
|
||||
comment?: AnyDocNodeJSON | null;
|
||||
children?: ReactNode;
|
||||
deprecation?: AnyDocNodeJSON | null;
|
||||
|
||||
@@ -9,8 +9,7 @@ import { Section } from './Section';
|
||||
import { TableOfContentsItems } from './TableOfContentsItems';
|
||||
import { TypeParamTable } from './TypeParamTable';
|
||||
import { TSDoc } from './tsdoc/TSDoc';
|
||||
import type { DocClass } from '~/DocModel/DocClass';
|
||||
import type { DocItem } from '~/DocModel/DocItem';
|
||||
import type { ApiClassJSON, ApiItemJSON } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
import type { TypeParameterData } from '~/DocModel/TypeParameterMixin';
|
||||
import type { AnyDocNodeJSON } from '~/DocModel/comment/CommentNode';
|
||||
import { generateIcon } from '~/util/icon';
|
||||
@@ -20,13 +19,13 @@ export interface DocContainerProps {
|
||||
name: string;
|
||||
kind: string;
|
||||
excerpt: string;
|
||||
summary?: ReturnType<DocItem['toJSON']>['summary'];
|
||||
summary?: ApiItemJSON['summary'];
|
||||
children?: ReactNode;
|
||||
extendsTokens?: TokenDocumentation[] | null;
|
||||
implementsTokens?: TokenDocumentation[][];
|
||||
typeParams?: TypeParameterData[];
|
||||
comment?: AnyDocNodeJSON | null;
|
||||
methods?: ReturnType<DocClass['toJSON']>['methods'] | null;
|
||||
methods?: ApiClassJSON['methods'] | null;
|
||||
}
|
||||
|
||||
export function DocContainer({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Anchor, Text } from '@mantine/core';
|
||||
import Link from 'next/link';
|
||||
import type { InheritanceData } from '~/DocModel/DocMethod';
|
||||
import type { InheritanceData } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
|
||||
export function InheritanceText({ data }: { data: InheritanceData }) {
|
||||
return (
|
||||
|
||||
@@ -3,11 +3,10 @@ import { HyperlinkedText } from './HyperlinkedText';
|
||||
import { InheritanceText } from './InheritanceText';
|
||||
import { ParameterTable } from './ParameterTable';
|
||||
import { TSDoc } from './tsdoc/TSDoc';
|
||||
import type { DocMethod } from '~/DocModel/DocMethod';
|
||||
import type { DocMethodSignature } from '~/DocModel/DocMethodSignature';
|
||||
import type { ApiMethodJSON, ApiMethodSignatureJSON } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
import { Visibility } from '~/DocModel/Visibility';
|
||||
|
||||
type MethodResolvable = ReturnType<DocMethod['toJSON']> | ReturnType<DocMethodSignature['toJSON']>;
|
||||
type MethodResolvable = ApiMethodJSON | ApiMethodSignatureJSON;
|
||||
|
||||
function getShorthandName(data: MethodResolvable) {
|
||||
return `${data.name}${data.optional ? '?' : ''}(${data.parameters.reduce((prev, cur, index) => {
|
||||
@@ -20,7 +19,8 @@ function getShorthandName(data: MethodResolvable) {
|
||||
}
|
||||
|
||||
export function MethodItem({ data }: { data: MethodResolvable }) {
|
||||
const method = data as ReturnType<DocMethod['toJSON']>;
|
||||
const method = data as ApiMethodJSON;
|
||||
|
||||
return (
|
||||
<Stack
|
||||
id={`${data.name}${data.overloadIndex && data.overloadIndex > 1 ? `:${data.overloadIndex}` : ''}`}
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
import { Divider, Stack } from '@mantine/core';
|
||||
import { Fragment } from 'react';
|
||||
import { MethodItem } from './MethodItem';
|
||||
import type { DocMethod } from '~/DocModel/DocMethod';
|
||||
import type { DocMethodSignature } from '~/DocModel/DocMethodSignature';
|
||||
import type { ApiMethodJSON, ApiMethodSignatureJSON } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
|
||||
export function MethodList({
|
||||
data,
|
||||
}: {
|
||||
data: (ReturnType<DocMethod['toJSON']> | ReturnType<DocMethodSignature['toJSON']>)[];
|
||||
}) {
|
||||
export function MethodList({ data }: { data: (ApiMethodJSON | ApiMethodSignatureJSON)[] }) {
|
||||
return (
|
||||
<Stack>
|
||||
{data.map((method) => (
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Stack } from '@mantine/core';
|
||||
import { CodeListing } from './CodeListing';
|
||||
import type { DocProperty } from '~/DocModel/DocProperty';
|
||||
import type { ApiPropertyItemJSON } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
|
||||
export function PropertyList({ data }: { data: ReturnType<DocProperty['toJSON']>[] }) {
|
||||
export function PropertyList({ data }: { data: ApiPropertyItemJSON[] }) {
|
||||
return (
|
||||
<Stack>
|
||||
{data.map((prop) => (
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
import { Stack, Group, Badge, Title } from '@mantine/core';
|
||||
import { useMediaQuery } from '@mantine/hooks';
|
||||
import { VscSymbolConstant, VscSymbolMethod, VscSymbolProperty } from 'react-icons/vsc';
|
||||
|
||||
import { MethodList } from './MethodList';
|
||||
import { ParameterTable } from './ParameterTable';
|
||||
import { PropertyList } from './PropertyList';
|
||||
import { Section } from './Section';
|
||||
import type { DocClass } from '~/DocModel/DocClass';
|
||||
import type { DocInterface } from '~/DocModel/DocInterface';
|
||||
import { TSDoc } from './tsdoc/TSDoc';
|
||||
import type { ApiClassJSON, ApiConstructorJSON, ApiInterfaceJSON } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
import type { ParameterDocumentation } from '~/util/parse.server';
|
||||
|
||||
export function PropertiesSection({
|
||||
data,
|
||||
}: {
|
||||
data: ReturnType<DocClass['toJSON']>['properties'] | ReturnType<DocInterface['toJSON']>['properties'];
|
||||
}) {
|
||||
export function PropertiesSection({ data }: { data: ApiClassJSON['properties'] | ApiInterfaceJSON['properties'] }) {
|
||||
const matches = useMediaQuery('(max-width: 768px)', true, { getInitialValueInEffect: false });
|
||||
|
||||
return data.length ? (
|
||||
@@ -22,11 +20,7 @@ export function PropertiesSection({
|
||||
) : null;
|
||||
}
|
||||
|
||||
export function MethodsSection({
|
||||
data,
|
||||
}: {
|
||||
data: ReturnType<DocClass['toJSON']>['methods'] | ReturnType<DocInterface['toJSON']>['methods'];
|
||||
}) {
|
||||
export function MethodsSection({ data }: { data: ApiClassJSON['methods'] | ApiInterfaceJSON['methods'] }) {
|
||||
const matches = useMediaQuery('(max-width: 768px)', true, { getInitialValueInEffect: false });
|
||||
|
||||
return data.length ? (
|
||||
@@ -45,3 +39,48 @@ export function ParametersSection({ data }: { data: ParameterDocumentation[] })
|
||||
</Section>
|
||||
) : null;
|
||||
}
|
||||
|
||||
export function ConstructorSection({ data }: { data: ApiConstructorJSON }) {
|
||||
const matches = useMediaQuery('(max-width: 768px)', true, { getInitialValueInEffect: false });
|
||||
|
||||
function getShorthandName(): string {
|
||||
return `constructor(${data.parameters.reduce((prev, cur, index) => {
|
||||
if (index === 0) {
|
||||
return `${prev}${cur.isOptional ? `[${cur.name}]` : cur.name}`;
|
||||
}
|
||||
|
||||
return `${prev}, ${cur.isOptional ? `[${cur.name}]` : cur.name}`;
|
||||
}, '')})`;
|
||||
}
|
||||
|
||||
return data.parameters.length ? (
|
||||
<Section title="Constructor" icon={<VscSymbolMethod />} padded dense={matches}>
|
||||
<Stack id={`${data.name}`} className="scroll-mt-30" spacing="xs">
|
||||
<Group>
|
||||
<Stack>
|
||||
<Group>
|
||||
{data.deprecated ? (
|
||||
<Badge variant="filled" color="red">
|
||||
Deprecated
|
||||
</Badge>
|
||||
) : null}
|
||||
{data.protected ? <Badge variant="filled">Protected</Badge> : null}
|
||||
<Title sx={{ wordBreak: 'break-all' }} order={4} className="font-mono">
|
||||
{getShorthandName()}
|
||||
</Title>
|
||||
</Group>
|
||||
</Stack>
|
||||
</Group>
|
||||
<Group sx={{ display: data.summary || data.parameters.length ? 'block' : 'none' }} mb="lg">
|
||||
<Stack>
|
||||
{data.deprecated ? <TSDoc node={data.deprecated} /> : null}
|
||||
{data.summary ? <TSDoc node={data.summary} /> : null}
|
||||
{data.remarks ? <TSDoc node={data.remarks} /> : null}
|
||||
{data.comment ? <TSDoc node={data.comment} /> : null}
|
||||
{data.parameters.length ? <ParameterTable data={data.parameters} /> : null}
|
||||
</Stack>
|
||||
</Group>
|
||||
</Stack>
|
||||
</Section>
|
||||
) : null;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import { type PropsWithChildren, useState } from 'react';
|
||||
import { VscChevronDown, VscPackage } from 'react-icons/vsc';
|
||||
import { WiDaySunny, WiNightClear } from 'react-icons/wi';
|
||||
import { SidebarItems } from './SidebarItems';
|
||||
import type { DocItem } from '~/DocModel/DocItem';
|
||||
import type { ApiItemJSON } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
import type { findMember } from '~/util/model.server';
|
||||
import type { getMembers } from '~/util/parse.server';
|
||||
|
||||
@@ -36,7 +36,7 @@ export interface SidebarLayoutProps {
|
||||
member: ReturnType<typeof findMember>;
|
||||
};
|
||||
|
||||
selectedMember?: ReturnType<DocItem['toJSON']> | undefined;
|
||||
selectedMember?: ApiItemJSON | undefined;
|
||||
}
|
||||
|
||||
export type Members = SidebarLayoutProps['data']['members'];
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { createStyles, Group, Text, Box } from '@mantine/core';
|
||||
import { VscListSelection } from 'react-icons/vsc';
|
||||
import type { DocClass } from '~/DocModel/DocClass';
|
||||
import type { DocInterface } from '~/DocModel/DocInterface';
|
||||
import type { ApiClassJSON, ApiInterfaceJSON } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
|
||||
const useStyles = createStyles((theme) => ({
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
@@ -25,11 +24,7 @@ const useStyles = createStyles((theme) => ({
|
||||
},
|
||||
}));
|
||||
|
||||
export function TableOfContentsItems({
|
||||
members,
|
||||
}: {
|
||||
members: ReturnType<DocClass['toJSON']>['methods'] | ReturnType<DocInterface['toJSON']>['methods'];
|
||||
}) {
|
||||
export function TableOfContentsItems({ members }: { members: ApiClassJSON['methods'] | ApiInterfaceJSON['methods'] }) {
|
||||
const { classes } = useStyles();
|
||||
|
||||
const items = members.map((member) => {
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
import { DocContainer } from '../DocContainer';
|
||||
import { MethodsSection, PropertiesSection } from '../Sections';
|
||||
import type { DocClass } from '~/DocModel/DocClass';
|
||||
import { ConstructorSection, MethodsSection, PropertiesSection } from '../Sections';
|
||||
import type { ApiClassJSON } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
|
||||
export function Class({ data }: { data: ReturnType<DocClass['toJSON']> }) {
|
||||
export function Class({ data }: { data: ApiClassJSON }) {
|
||||
return (
|
||||
<DocContainer
|
||||
name={data.name}
|
||||
kind={data.kind}
|
||||
excerpt={data.excerpt}
|
||||
summary={data.summary}
|
||||
typeParams={data.typeParameterData}
|
||||
typeParams={data.typeParameters}
|
||||
extendsTokens={data.extendsTokens}
|
||||
implementsTokens={data.implementsTokens}
|
||||
comment={data.comment}
|
||||
methods={data.methods}
|
||||
>
|
||||
{data.constructor ? <ConstructorSection data={data.constructor} /> : null}
|
||||
<PropertiesSection data={data.properties} />
|
||||
<MethodsSection data={data.methods} />
|
||||
</DocContainer>
|
||||
|
||||
@@ -4,9 +4,9 @@ import { VscSymbolEnumMember } from 'react-icons/vsc';
|
||||
import { CodeListing, CodeListingSeparatorType } from '../CodeListing';
|
||||
import { DocContainer } from '../DocContainer';
|
||||
import { Section } from '../Section';
|
||||
import type { DocEnum } from '~/DocModel/DocEnum';
|
||||
import type { ApiEnumJSON } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
|
||||
export function Enum({ data }: { data: ReturnType<DocEnum['toJSON']> }) {
|
||||
export function Enum({ data }: { data: ApiEnumJSON }) {
|
||||
const matches = useMediaQuery('(max-width: 768px)', true, { getInitialValueInEffect: false });
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { DocContainer } from '../DocContainer';
|
||||
import { ParametersSection } from '../Sections';
|
||||
import type { DocFunction } from '~/DocModel/DocFunction';
|
||||
import type { ApiFunctionJSON } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
|
||||
export function Function({ data }: { data: ReturnType<DocFunction['toJSON']> }) {
|
||||
export function Function({ data }: { data: ApiFunctionJSON }) {
|
||||
return (
|
||||
<DocContainer
|
||||
name={`${data.name}${data.overloadIndex && data.overloadIndex > 1 ? ` (${data.overloadIndex})` : ''}`}
|
||||
kind={data.kind}
|
||||
excerpt={data.excerpt}
|
||||
summary={data.summary}
|
||||
typeParams={data.typeParameterData}
|
||||
typeParams={data.typeParameters}
|
||||
>
|
||||
<ParametersSection data={data.parameters} />
|
||||
</DocContainer>
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { DocContainer } from '../DocContainer';
|
||||
import { MethodsSection, PropertiesSection } from '../Sections';
|
||||
import type { DocInterface } from '~/DocModel/DocInterface';
|
||||
import type { ApiInterfaceJSON } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
|
||||
export function Interface({ data }: { data: ReturnType<DocInterface['toJSON']> }) {
|
||||
export function Interface({ data }: { data: ApiInterfaceJSON }) {
|
||||
return (
|
||||
<DocContainer
|
||||
name={data.name}
|
||||
kind={data.kind}
|
||||
excerpt={data.excerpt}
|
||||
summary={data.summary}
|
||||
typeParams={data.typeParameterData}
|
||||
typeParams={data.typeParameters}
|
||||
>
|
||||
<PropertiesSection data={data.properties} />
|
||||
<MethodsSection data={data.methods} />
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { DocContainer } from '../DocContainer';
|
||||
import type { DocTypeAlias } from '~/DocModel/DocTypeAlias';
|
||||
import type { ApiTypeAliasJSON } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
|
||||
export function TypeAlias({ data }: { data: ReturnType<DocTypeAlias['toJSON']> }) {
|
||||
export function TypeAlias({ data }: { data: ApiTypeAliasJSON }) {
|
||||
return (
|
||||
<DocContainer
|
||||
name={data.name}
|
||||
kind={data.kind}
|
||||
excerpt={data.excerpt}
|
||||
summary={data.summary}
|
||||
typeParams={data.typeParameterData}
|
||||
typeParams={data.typeParameters}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DocContainer } from '../DocContainer';
|
||||
import type { DocVariable } from '~/DocModel/DocVariable';
|
||||
import type { ApiVariableJSON } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
|
||||
export function Variable({ data }: { data: ReturnType<DocVariable['toJSON']> }) {
|
||||
export function Variable({ data }: { data: ApiVariableJSON }) {
|
||||
return <DocContainer name={data.name} kind={data.kind} excerpt={data.excerpt} summary={data.summary} />;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import { createContext } from 'react';
|
||||
import type { DocItem } from '~/DocModel/DocItem';
|
||||
import type { ApiItemJSON } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
|
||||
export type DocItemJSON = ReturnType<DocItem['toJSON']>;
|
||||
|
||||
export const MemberContext = createContext<DocItemJSON | undefined>(undefined);
|
||||
export const MemberContext = createContext<ApiItemJSON | undefined>(undefined);
|
||||
|
||||
export const MemberProvider = ({
|
||||
member,
|
||||
children,
|
||||
}: {
|
||||
member: DocItemJSON | undefined;
|
||||
member: ApiItemJSON | undefined;
|
||||
children: React.ReactNode;
|
||||
}) => <MemberContext.Provider value={member}>{children}</MemberContext.Provider>;
|
||||
|
||||
@@ -4,12 +4,14 @@ import { join } from 'node:path';
|
||||
import { Box } from '@mantine/core';
|
||||
import { ApiFunction } from '@microsoft/api-extractor-model';
|
||||
import type { GetStaticPaths, GetStaticProps } from 'next/types';
|
||||
import type { DocClass } from '~/DocModel/DocClass';
|
||||
import type { DocEnum } from '~/DocModel/DocEnum';
|
||||
import type { DocFunction } from '~/DocModel/DocFunction';
|
||||
import type { DocInterface } from '~/DocModel/DocInterface';
|
||||
import type { DocTypeAlias } from '~/DocModel/DocTypeAlias';
|
||||
import type { DocVariable } from '~/DocModel/DocVariable';
|
||||
import type {
|
||||
ApiClassJSON,
|
||||
ApiEnumJSON,
|
||||
ApiFunctionJSON,
|
||||
ApiInterfaceJSON,
|
||||
ApiTypeAliasJSON,
|
||||
ApiVariableJSON,
|
||||
} from '~/DocModel/ApiNodeJSONEncoder';
|
||||
import { SidebarLayout, type SidebarLayoutProps } from '~/components/SidebarLayout';
|
||||
import { Class } from '~/components/model/Class';
|
||||
import { Enum } from '~/components/model/Enum';
|
||||
@@ -110,8 +112,7 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
|
||||
packageName,
|
||||
data: {
|
||||
members: pkg ? getMembers(pkg) : [],
|
||||
member:
|
||||
memberName && containerKey ? findMemberByKey(model, packageName, containerKey)?.toJSON() ?? null : null,
|
||||
member: memberName && containerKey ? findMemberByKey(model, packageName, containerKey) ?? null : null,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -128,17 +129,17 @@ const member = (props: any) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
switch (props.kind) {
|
||||
case 'Class':
|
||||
return <Class data={props as ReturnType<DocClass['toJSON']>} />;
|
||||
return <Class data={props as ApiClassJSON} />;
|
||||
case 'Function':
|
||||
return <Function data={props as ReturnType<DocFunction['toJSON']>} />;
|
||||
return <Function data={props as ApiFunctionJSON} />;
|
||||
case 'Interface':
|
||||
return <Interface data={props as ReturnType<DocInterface['toJSON']>} />;
|
||||
return <Interface data={props as ApiInterfaceJSON} />;
|
||||
case 'TypeAlias':
|
||||
return <TypeAlias data={props as ReturnType<DocTypeAlias['toJSON']>} />;
|
||||
return <TypeAlias data={props as ApiTypeAliasJSON} />;
|
||||
case 'Variable':
|
||||
return <Variable data={props as ReturnType<DocVariable['toJSON']>} />;
|
||||
return <Variable data={props as ApiVariableJSON} />;
|
||||
case 'Enum':
|
||||
return <Enum data={props as ReturnType<DocEnum['toJSON']>} />;
|
||||
return <Enum data={props as ApiEnumJSON} />;
|
||||
default:
|
||||
return <Box>Cannot render that item type</Box>;
|
||||
}
|
||||
|
||||
@@ -1,52 +1,6 @@
|
||||
import {
|
||||
ApiClass,
|
||||
ApiDeclaredItem,
|
||||
ApiEntryPoint,
|
||||
ApiEnum,
|
||||
ApiFunction,
|
||||
ApiInterface,
|
||||
ApiItem,
|
||||
ApiItemKind,
|
||||
ApiModel,
|
||||
ApiTypeAlias,
|
||||
ApiVariable,
|
||||
} from '@microsoft/api-extractor-model';
|
||||
import type { ApiEntryPoint, ApiModel } from '@microsoft/api-extractor-model';
|
||||
import { findPackage } from './parse.server';
|
||||
import { DocClass } from '../DocModel/DocClass';
|
||||
import { DocEnum } from '../DocModel/DocEnum';
|
||||
import { DocFunction } from '../DocModel/DocFunction';
|
||||
import { DocInterface } from '../DocModel/DocInterface';
|
||||
import { DocItem } from '../DocModel/DocItem';
|
||||
import { DocTypeAlias } from '../DocModel/DocTypeAlias';
|
||||
import { DocVariable } from '../DocModel/DocVariable';
|
||||
|
||||
export interface ReferenceData {
|
||||
name: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
function createDocItem(model: ApiModel, member: ApiItem) {
|
||||
if (!(member instanceof ApiDeclaredItem)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
switch (member.kind) {
|
||||
case ApiItemKind.Class:
|
||||
return new DocClass(model, member as ApiClass);
|
||||
case ApiItemKind.Function:
|
||||
return new DocFunction(model, member as ApiFunction);
|
||||
case ApiItemKind.Interface:
|
||||
return new DocInterface(model, member as ApiInterface);
|
||||
case ApiItemKind.TypeAlias:
|
||||
return new DocTypeAlias(model, member as ApiTypeAlias);
|
||||
case ApiItemKind.Variable:
|
||||
return new DocVariable(model, member as ApiVariable);
|
||||
case ApiItemKind.Enum:
|
||||
return new DocEnum(model, member as ApiEnum);
|
||||
default:
|
||||
return new DocItem(model, member);
|
||||
}
|
||||
}
|
||||
import { ApiNodeJSONEncoder } from '~/DocModel/ApiNodeJSONEncoder';
|
||||
|
||||
export function findMemberByKey(model: ApiModel, packageName: string, containerKey: string) {
|
||||
const pkg = findPackage(model, packageName)!;
|
||||
@@ -56,10 +10,14 @@ export function findMemberByKey(model: ApiModel, packageName: string, containerK
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return createDocItem(model, member);
|
||||
return ApiNodeJSONEncoder.encode(model, member);
|
||||
}
|
||||
|
||||
export function findMember(model: ApiModel, packageName: string, memberName: string): DocItem | undefined {
|
||||
export function findMember(
|
||||
model: ApiModel,
|
||||
packageName: string,
|
||||
memberName: string,
|
||||
): ReturnType<typeof ApiNodeJSONEncoder['encode']> | undefined {
|
||||
const pkg = findPackage(model, packageName)!;
|
||||
const member = (pkg.members[0] as ApiEntryPoint).findMembersByName(memberName)[0];
|
||||
|
||||
@@ -67,5 +25,5 @@ export function findMember(model: ApiModel, packageName: string, memberName: str
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return createDocItem(model, member);
|
||||
return ApiNodeJSONEncoder.encode(model, member);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user