Skip to content

Commit

Permalink
fix: UI tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Apr 26, 2023
1 parent 567b484 commit 46bf8fa
Show file tree
Hide file tree
Showing 11 changed files with 322 additions and 227 deletions.
4 changes: 2 additions & 2 deletions packages/typedoc-plugin-markdown/src/partials/hierarchy.ts
@@ -1,5 +1,5 @@
import { DeclarationHierarchy, SomeType, Type } from 'typedoc';
import { bold, unorderedList } from '../support/els';
import { backTicks, bold, unorderedList } from '../support/els';
import { MarkdownThemeRenderContext } from '../theme-render-context';

export function hierarchy(
Expand Down Expand Up @@ -43,6 +43,6 @@ function getHierarchyType(
context: MarkdownThemeRenderContext,
) {
return isTarget
? bold(hierarchyType.toString())
? bold(backTicks(hierarchyType.toString()))
: context.partials.someType(hierarchyType as SomeType);
}
Expand Up @@ -61,6 +61,10 @@ function declarationBody(
md.push(context.partials.comment(declaration.comment, headingLevel));
}

if (!parentHeadingLevel && declaration.sources) {
md.push(context.partials.sources(declaration));
}

if (declaration.typeParameters) {
md.push(heading(headingLevel, `Type parameters${titleSuffix}`));
md.push(context.partials.typeParametersTable(declaration.typeParameters));
Expand Down Expand Up @@ -101,7 +105,7 @@ function declarationBody(
}

if (!parentHeadingLevel) {
md.push(context.partials.sources(declaration, headingLevel));
md.push(context.partials.inheritance(declaration, headingLevel));
}
return md.join('\n\n');
}
@@ -0,0 +1,84 @@
import {
ArrayType,
DeclarationReflection,
ReferenceType,
SignatureReflection,
} from 'typedoc';
import { backTicks, heading, link } from '../support/els';
import { MarkdownThemeRenderContext } from '../theme-render-context';

import { escapeChars } from '../support/utils';

export function inheritance(
context: MarkdownThemeRenderContext,
reflection: DeclarationReflection | SignatureReflection,
headingLevel: number,
) {
const md: string[] = [];

if (reflection.implementationOf) {
md.push(heading(headingLevel, 'Implementation of'));
md.push(typeAndParent(context, reflection.implementationOf));
}

if (reflection.inheritedFrom) {
md.push(heading(headingLevel, 'Inherited from'));
md.push(typeAndParent(context, reflection.inheritedFrom));
}

if (reflection.overwrites) {
md.push(heading(headingLevel, 'Overrides'));
md.push(typeAndParent(context, reflection.overwrites));
}

return md.join('\n\n');
}

const typeAndParent = (
context: MarkdownThemeRenderContext,
props: ArrayType | ReferenceType,
) => {
const getUrl = (name: string, url: string) =>
link(backTicks(name), context.relativeURL(url));

if (props) {
if ('elementType' in props) {
return typeAndParent(context, props.elementType as any) + '[]';
} else {
if (props.reflection) {
const md: string[] = [];
if (props.reflection instanceof SignatureReflection) {
if (props.reflection.parent?.parent?.url) {
md.push(
getUrl(
props.reflection.parent.parent.name,
props.reflection.parent.parent.url,
),
);
if (props.reflection.parent.url) {
md.push(
getUrl(
props.reflection.parent.name,
props.reflection.parent.url,
),
);
}
}
} else {
if (props.reflection.parent?.url) {
md.push(
getUrl(props.reflection.parent.name, props.reflection.parent.url),
);
if (props.reflection.url) {
md.push(getUrl(props.reflection.name, props.reflection.url));
}
}
}
return md.length > 0 ? md.join('.') : props.name;
} else {
return escapeChars(props.toString());
}
}
}
return 'void';
};
20 changes: 13 additions & 7 deletions packages/typedoc-plugin-markdown/src/partials/member.signature.ts
@@ -1,5 +1,5 @@
import { DeclarationReflection, SignatureReflection } from 'typedoc';
import { codeBlock, heading } from '../support/els';
import { blockQuoteBlock, codeBlock, heading } from '../support/els';
import { getReflectionHeadingLevel } from '../support/helpers';
import { MarkdownThemeRenderContext } from '../theme-render-context';

Expand All @@ -11,7 +11,9 @@ export function signatureMember(
const md: string[] = [];

if (parentHeadingLevel) {
md.push(signatureBody(context, signature, parentHeadingLevel));
md.push(
blockQuoteBlock(signatureBody(context, signature, parentHeadingLevel)),
);
} else {
md.push(signatureBody(context, signature));
}
Expand All @@ -34,16 +36,20 @@ function signatureBody(
context.getOption('groupByKinds'),
)) + 1;

if (signature.comment) {
md.push(context.partials.comment(signature.comment, headingLevel));
}

if (context.getOption('indentifiersAsCodeBlocks')) {
md.push(codeBlock(context.partials.signatureMemberIdentifier(signature)));
} else {
md.push(`> ${context.partials.signatureMemberIdentifier(signature)}`);
}

if (signature.comment) {
md.push(context.partials.comment(signature.comment, headingLevel));
}

if (!parentHeadingLevel && signature.sources) {
md.push(context.partials.sources(signature));
}

const typeDeclaration = (signature.type as any)
?.declaration as DeclarationReflection;

Expand Down Expand Up @@ -89,7 +95,7 @@ function signatureBody(
}
}
if (!parentHeadingLevel) {
md.push(context.partials.sources(signature, headingLevel));
md.push(context.partials.inheritance(signature, headingLevel));
}
}

Expand Down
99 changes: 12 additions & 87 deletions packages/typedoc-plugin-markdown/src/partials/member.sources.ts
@@ -1,97 +1,22 @@
import {
ArrayType,
DeclarationReflection,
ReferenceType,
SignatureReflection,
} from 'typedoc';
import { heading, link } from '../support/els';
import { DeclarationReflection, SignatureReflection } from 'typedoc';
import { link } from '../support/els';
import { MarkdownThemeRenderContext } from '../theme-render-context';

import { escapeChars } from '../support/utils';

export function sources(
context: MarkdownThemeRenderContext,
reflection: DeclarationReflection | SignatureReflection,
headingLevel: number,
) {
const md: string[] = [];

if (reflection.implementationOf) {
md.push(heading(headingLevel, 'Implementation of'));
md.push(typeAndParent(context, reflection.implementationOf));
}

if (reflection.inheritedFrom) {
md.push(heading(headingLevel, 'Inherited from'));
md.push(typeAndParent(context, reflection.inheritedFrom));
}

if (reflection.overwrites) {
md.push(heading(headingLevel, 'Overrides'));
md.push(typeAndParent(context, reflection.overwrites));
}

if (reflection.sources) {
const definedInMd = [heading(headingLevel, 'Defined in')];

reflection.sources.forEach((source) => {
if (source.url) {
definedInMd.push(
link(`${escapeChars(source.fileName)}:${source.line}`, source.url),
);
} else {
definedInMd.push(`${escapeChars(source.fileName)}:${source.line}`);
}
});
md.push(definedInMd.join('\n'));
}
return md.join('\n\n');
}

const typeAndParent = (
context: MarkdownThemeRenderContext,
props: ArrayType | ReferenceType,
) => {
const getUrl = (name: string, url: string) =>
`[${name}](${context.relativeURL(url)})`;
if (props) {
if ('elementType' in props) {
return typeAndParent(context, props.elementType as any) + '[]';
const md = ['Defined in:'];
reflection.sources?.forEach((source) => {
if (source.url) {
md.push(
link(`${escapeChars(source.fileName)}:${source.line}`, source.url),
);
} else {
if (props.reflection) {
const md: string[] = [];
if (props.reflection instanceof SignatureReflection) {
if (props.reflection.parent?.parent?.url) {
md.push(
getUrl(
props.reflection.parent.parent.name,
props.reflection.parent.parent.url,
),
);
if (props.reflection.parent.url) {
md.push(
getUrl(
props.reflection.parent.name,
props.reflection.parent.url,
),
);
}
}
} else {
if (props.reflection.parent?.url) {
md.push(
getUrl(props.reflection.parent.name, props.reflection.parent.url),
);
if (props.reflection.url) {
md.push(getUrl(props.reflection.name, props.reflection.url));
}
}
}
return md.length > 0 ? md.join('.') : props.name;
} else {
return escapeChars(props.toString());
}
md.push(`${escapeChars(source.fileName)}:${source.line}`);
}
}
return 'void';
};
});
return md.join(' ');
}
5 changes: 4 additions & 1 deletion packages/typedoc-plugin-markdown/src/partials/member.ts
Expand Up @@ -25,7 +25,10 @@ export function member(
md.push(`<a id="${reflection.anchor}" name="${reflection.anchor}"></a>`);
}

if (!reflection.hasOwnDocument) {
if (
!reflection.hasOwnDocument &&
!reflection.kindOf(ReflectionKind.Constructor)
) {
md.push(heading(headingLevel, `${getReflectionTitle(reflection)}`));
}

Expand Down
5 changes: 4 additions & 1 deletion packages/typedoc-plugin-markdown/src/resources.ts
Expand Up @@ -41,6 +41,7 @@ import { declarationMemberIdentifier } from './partials/member.declaration.ident
import { declarationMemberName } from './partials/member.declaration.name';
import { declarationMember } from './partials/member.declaration';
import { indexSignatureTitle } from './partials/member.indexsignature.title';
import { inheritance } from './partials/member.inheritance';
import { referenceMember } from './partials/member.reference';
import { reflectionMember } from './partials/member.reflection';
import { signatureMemberIdentifier } from './partials/member.signature.identifier';
Expand Down Expand Up @@ -94,11 +95,12 @@ export type Partials = {
declarationMemberName: (declaration: DeclarationReflection, emphasis?: boolean) => string;
declarationMember: (declaration: DeclarationReflection, parentHeadingLevel?: number | undefined) => string;
indexSignatureTitle: (signature: SignatureReflection) => string;
inheritance: (reflection: DeclarationReflection | SignatureReflection, headingLevel: number) => string;
referenceMember: (props: ReferenceReflection) => string;
reflectionMember: (reflection: DeclarationReflection) => string;
signatureMemberIdentifier: (signature: SignatureReflection) => string;
signatureMember: (signature: SignatureReflection, parentHeadingLevel?: number | undefined) => string;
sources: (reflection: DeclarationReflection | SignatureReflection, headingLevel: number) => string;
sources: (reflection: DeclarationReflection | SignatureReflection) => string;
member: (reflection: DeclarationReflection) => string;
typeDeclarationMember: (declarations: DeclarationReflection[], parentHeadingLevel: number) => string;
members: (container: ContainerReflection) => string;
Expand Down Expand Up @@ -145,6 +147,7 @@ export const partials = (context: MarkdownThemeRenderContext): Partials => ({
declarationMemberName: bind(declarationMemberName, context),
declarationMember: bind(declarationMember, context),
indexSignatureTitle: bind(indexSignatureTitle, context),
inheritance: bind(inheritance, context),
referenceMember: bind(referenceMember, context),
reflectionMember: bind(reflectionMember, context),
signatureMemberIdentifier: bind(signatureMemberIdentifier, context),
Expand Down

0 comments on commit 46bf8fa

Please sign in to comment.