diff --git a/plugins/theme/helpers/index.mjs b/plugins/theme/helpers/index.mjs index 880933e..d05b64d 100644 --- a/plugins/theme/helpers/index.mjs +++ b/plugins/theme/helpers/index.mjs @@ -15,15 +15,12 @@ export default (ctx) => ({ typedListItem({ label, name, type, comment }) { const namePart = label ? ` ${label}:` : name ? ` \`${name}\`` : ""; - const typePart = type ? ` ${typeof type === "string" ? type : ctx.partials.someType(type)}` : ""; - const descPart = comment ? ` ${ctx.helpers.getCommentParts(comment.summary ?? comment.content)}` : ""; - return `*${namePart}${typePart}${descPart}`; }, @@ -31,15 +28,25 @@ export default (ctx) => ({ return entries.map(ctx.helpers.typedListItem).join("\n"); }, + signatureTitle(name, params) { + const paramsStr = params + .map((param, index) => { + if (param.flags?.isOptional) { + return index === 0 ? `[${param.name}]` : `[, ${param.name}]`; + } + return index === 0 ? param.name : `, ${param.name}`; + }) + .join(""); + return `\`${name}(${paramsStr})\``; + }, + stabilityBlockquote(comment) { if (!comment) return null; - const deprecated = comment.blockTags?.find((t) => t.tag === "@deprecated"); const isExperimental = comment.modifierTags?.has("@experimental") || comment.modifierTags?.has("@beta"); const legacy = comment.blockTags?.find((t) => t.tag === "@legacy"); - if (deprecated) { const message = deprecated.content?.length ? ctx.helpers.getCommentParts(deprecated.content).trim() @@ -48,11 +55,9 @@ export default (ctx) => ({ ? `> Stability: 0 - Deprecated: ${message}` : `> Stability: 0 - Deprecated`; } - if (isExperimental) { return `> Stability: 1 - Experimental`; } - if (legacy) { const message = legacy.content?.length ? ctx.helpers.getCommentParts(legacy.content).trim() @@ -61,7 +66,6 @@ export default (ctx) => ({ ? `> Stability: 3 - Legacy: ${message}` : `> Stability: 3 - Legacy`; } - return null; }, -}); +}); \ No newline at end of file diff --git a/plugins/theme/index.mjs b/plugins/theme/index.mjs index badfa2f..4891923 100644 --- a/plugins/theme/index.mjs +++ b/plugins/theme/index.mjs @@ -13,14 +13,13 @@ export class DocKitTheme extends MarkdownTheme { export class DocKitThemeContext extends MarkdownThemeContext { helpers = helpers(this); - partials = partials(this); - templates = { ...this.templates, }; } +/** @param {import('typedoc').Application} app */ export function load(app) { app.renderer.defineTheme("doc-kit", DocKitTheme); } diff --git a/plugins/theme/partials/index.mjs b/plugins/theme/partials/index.mjs index 56463fb..743b42d 100644 --- a/plugins/theme/partials/index.mjs +++ b/plugins/theme/partials/index.mjs @@ -36,11 +36,7 @@ export default (ctx) => ({ ? model.comment : model.comment || model.parent?.comment; - const stability = ctx.helpers.stabilityBlockquote(comment); - return [ - stability, - stability && "", model.typeParameters?.length && ctx.partials.typeParametersList(model.typeParameters, { headingLevel: options.headingLevel, @@ -66,31 +62,95 @@ export default (ctx) => ({ }, memberTitle(model) { + const params = model.signatures?.[0]?.parameters ?? []; + if (model.kind === ReflectionKind.Constructor) { + const className = model.parent?.name ?? model.name; + return ctx.helpers.signatureTitle(`new ${className}`, params); + } const prefix = getMemberPrefix(model); - const params = model.signatures?.[0]?.parameters; + if (!params.length) return `${prefix}\`${model.name}\``; + return `${prefix}${ctx.helpers.signatureTitle(model.name, params)}`; + }, - if (!params) { - return `${prefix}\`${model.name}\``; + memberContainer: (model, options) => { + const md = []; + if (!ctx.router.hasOwnDocument(model)) { + md.push( + "#".repeat(options.headingLevel) + " " + + ctx.partials.memberTitle(model) + ); } + md.push(ctx.partials.member(model, { + headingLevel: options.headingLevel + 1, + nested: options.nested, + })); + return md.filter(Boolean).join("\n\n"); + }, - const paramsString = params - .map((param, index) => { - const paramName = param.name; - if (param.flags?.isOptional) { - // For optional params, wrap comma + name in brackets (except for first param) - return index === 0 ? `[${paramName}]` : `[, ${paramName}]`; - } else { - // For required params, add comma separator (except for first param) - return index === 0 ? paramName : `, ${paramName}`; - } + constructor: (model, options) => { + return model.signatures?.map(signature => { + const params = signature.parameters ?? []; + return params.length ? ctx.helpers.typedList(params) : ""; + }).filter(Boolean).join("\n\n") ?? ""; + }, + + members: (model, options) => { + const items = model.filter( + (item) => !ctx.router.hasOwnDocument(item) + ); + return items + .map(item => + ctx.partials.memberContainer(item, { + headingLevel: options.headingLevel, + groupTitle: options.groupTitle, + }) + ) + .filter(Boolean) + .join("\n\n"); + }, + + groups: (model, options) => { + return (model.groups ?? []) + .flatMap(group => { + const isPropertiesGroup = group.children?.every( + child => child.kind === ReflectionKind.Property + ); + if (isPropertiesGroup) return []; + const children = group.children?.filter( + child => child.isDeclaration() + ) ?? []; + if (!children.length) return []; + return [ + ctx.partials.members(children, { + headingLevel: options.headingLevel, + groupTitle: group.title, + }) + ]; }) - .join(""); + .filter(Boolean) + .join("\n\n"); + }, + + body: (model, options) => { + if (model.groups?.length) { + return ctx.partials.groups(model, { + headingLevel: options.headingLevel, + kind: model.kind, + }); + } + return ""; + }, - return `${prefix}\`${model.name}(${paramsString})\``; + declarationTitle: (model) => { + return ctx.helpers.typedListItem({ + name: model.name, + type: model.type, + comment: model.comment, + }); }, parametersList: ctx.helpers.typedList, typedParametersList: ctx.helpers.typedList, typeDeclarationList: ctx.helpers.typedList, propertiesTable: ctx.helpers.typedList, -}); +}); \ No newline at end of file