Skip to content

Commit

Permalink
Add types summary
Browse files Browse the repository at this point in the history
  • Loading branch information
kossnocorp committed Nov 16, 2023
1 parent d0740f3 commit 87995eb
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/ui/screens/Docs/Doc/TypeDoc/Types/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
findDescription,
findFnSummary,
findSummary,
joinCommentParts,
traverseType,
Expand All @@ -8,6 +9,7 @@ import { h } from 'preact'
import { useMemo } from 'preact/hooks'
import type { DeclarationReflection, SignatureReflection } from 'typedoc'
import { Code } from '~/ui/components/Code'
import { Debug } from '~/ui/components/Debug'
import { DocUsage } from '~/ui/components/DocUsage'
import { Item } from '~/ui/components/Item'
import { Markdown } from '~/ui/components/Markdown'
Expand All @@ -21,20 +23,19 @@ import { SourceLink } from '~/ui/components/SourceLink'
import { TypeDocInterface } from '~/ui/components/TypeDocInterface'
import { TypeDocType } from '~/ui/components/TypeDocType'
import { InlineTypeContext } from '~/ui/contexts/InlineTypeContext'
import { useQuery } from '~/ui/hooks/useQuery'
import { useActiveItem } from '~/ui/hooks/useActiveItem'
import { useQuery } from '~/ui/hooks/useQuery'
import {
ParentTypesMap,
findSource,
generateTypeUsage,
inlineTypeHash,
inlineTypeId,
inlineTypeIdHighlightMatch,
ParentTypesMap,
typeHash,
typeId as typeIdStr,
} from '~/utils/docs'
import * as styles from './styles.css'
import { Debug } from '~/ui/components/Debug'

export interface TypesModalProps {
parent: string
Expand Down Expand Up @@ -69,7 +70,7 @@ export const useTypesModal = createModal<TypesModalProps>(
const navItems: TypeItem[] = useMemo(
() =>
types.map((t) => {
const summary = findSummary(t)
const summary = getSummary(t)
const description = findDescription(t)
return { type: t, summary, description }
}) || [],
Expand All @@ -91,6 +92,8 @@ export const useTypesModal = createModal<TypesModalProps>(

const { activeRef } = useActiveItem()

const summary = useMemo(() => type && getSummary(type), [type])

return (
<InlineTypeContext.Provider
value={
Expand Down Expand Up @@ -152,12 +155,10 @@ export const useTypesModal = createModal<TypesModalProps>(
<SourceLink source={findSource(type)} />
</div>

{type.comment?.summary && (
{summary && (
<RichText>
<div class={styles.summary}>
<Markdown
value={joinCommentParts(type.comment.summary)}
/>
<Markdown value={summary} />
</div>
</RichText>
)}
Expand Down Expand Up @@ -368,3 +369,9 @@ function buildParentTypesMap(

return map
}

function getSummary(refl: DeclarationReflection) {
return refl.comment?.summary
? joinCommentParts(refl.comment?.summary)
: refl.type?.type === 'reflection' && findFnSummary(refl.type.declaration)
}

0 comments on commit 87995eb

Please sign in to comment.