|
1 | 1 | import { heading } from '@plugin/libs/markdown/index.js';
|
2 | 2 | import { MarkdownThemeContext } from '@plugin/theme/index.js';
|
3 | 3 | import {
|
| 4 | + ContainerReflection, |
4 | 5 | DeclarationReflection,
|
5 |
| - ReflectionGroup, |
| 6 | + ProjectReflection, |
6 | 7 | ReflectionKind,
|
7 | 8 | } from 'typedoc';
|
8 | 9 |
|
9 | 10 | export function groups(
|
10 | 11 | this: MarkdownThemeContext,
|
11 |
| - model: ReflectionGroup[], |
| 12 | + model: ContainerReflection, |
12 | 13 | options: { headingLevel: number; kind: ReflectionKind },
|
13 | 14 | ) {
|
14 |
| - const groupsWithChildren = model?.filter( |
15 |
| - (group) => !group.allChildrenHaveOwnDocument(), |
16 |
| - ); |
17 |
| - |
18 | 15 | const md: string[] = [];
|
19 | 16 |
|
20 | 17 | const getGroupTitle = (groupTitle: string) => {
|
21 | 18 | return groupTitle;
|
22 | 19 | };
|
23 | 20 |
|
24 |
| - groupsWithChildren?.forEach((group) => { |
25 |
| - const isEventProps = getGroupTitle(group.title) === 'Events'; |
26 |
| - if (group.categories) { |
27 |
| - md.push(heading(options.headingLevel, getGroupTitle(group.title))); |
28 |
| - if (group.description) { |
29 |
| - md.push(this.helpers.getCommentParts(group.description)); |
| 21 | + model.groups?.forEach((group) => { |
| 22 | + if ( |
| 23 | + group.title === this.i18n.kind_plural_module() || |
| 24 | + group.allChildrenHaveOwnDocument() |
| 25 | + ) { |
| 26 | + const isPackages = |
| 27 | + this.options.getValue('entryPointStrategy') === 'packages' && |
| 28 | + this.getPackagesCount() > 1 && |
| 29 | + group.title === this.i18n.kind_plural_module() && |
| 30 | + model.kind === ReflectionKind.Project; |
| 31 | + if (isPackages) { |
| 32 | + md.push(heading(options.headingLevel, this.i18n.theme_packages())); |
| 33 | + } else { |
| 34 | + md.push(heading(options.headingLevel, group.title)); |
30 | 35 | }
|
31 |
| - md.push( |
32 |
| - this.partials.categories(group.categories, { |
33 |
| - headingLevel: options.headingLevel + 1, |
34 |
| - }), |
35 |
| - ); |
36 |
| - } else { |
37 |
| - const isPropertiesGroup = group.children.every( |
38 |
| - (child) => child.kind === ReflectionKind.Property, |
39 |
| - ); |
40 |
| - |
41 |
| - const isEnumGroup = group.children.every( |
42 |
| - (child) => child.kind === ReflectionKind.EnumMember, |
43 |
| - ); |
44 |
| - |
45 |
| - md.push(heading(options.headingLevel, getGroupTitle(group.title))); |
46 |
| - |
47 | 36 | if (group.description) {
|
48 | 37 | md.push(this.helpers.getCommentParts(group.description));
|
49 | 38 | }
|
50 |
| - if ( |
51 |
| - isPropertiesGroup && |
52 |
| - this.helpers.useTableFormat('properties', options.kind) |
53 |
| - ) { |
54 |
| - md.push( |
55 |
| - this.partials.propertiesTable( |
56 |
| - group.children as DeclarationReflection[], |
57 |
| - { |
58 |
| - isEventProps, |
59 |
| - }, |
60 |
| - ), |
61 |
| - ); |
62 |
| - } else if (isEnumGroup && this.helpers.useTableFormat('enums')) { |
| 39 | + if (group.categories) { |
| 40 | + group.categories.forEach((categoryGroup) => { |
| 41 | + md.push(heading(options.headingLevel + 1, categoryGroup.title)); |
| 42 | + if (categoryGroup.description) { |
| 43 | + md.push(this.helpers.getCommentParts(categoryGroup.description)); |
| 44 | + } |
| 45 | + md.push(this.partials.groupIndex(categoryGroup)); |
| 46 | + }); |
| 47 | + } else { |
| 48 | + if (isPackages) { |
| 49 | + md.push(this.partials.packagesIndex(model as ProjectReflection)); |
| 50 | + } else { |
| 51 | + md.push(this.partials.groupIndex(group)); |
| 52 | + } |
| 53 | + } |
| 54 | + } else { |
| 55 | + const isEventProps = getGroupTitle(group.title) === 'Events'; |
| 56 | + if (group.categories) { |
| 57 | + md.push(heading(options.headingLevel, getGroupTitle(group.title))); |
| 58 | + if (group.description) { |
| 59 | + md.push(this.helpers.getCommentParts(group.description)); |
| 60 | + } |
63 | 61 | md.push(
|
64 |
| - this.partials.enumMembersTable( |
65 |
| - group.children as DeclarationReflection[], |
66 |
| - ), |
| 62 | + this.partials.categories(group.categories, { |
| 63 | + headingLevel: options.headingLevel + 1, |
| 64 | + }), |
67 | 65 | );
|
68 | 66 | } else {
|
69 |
| - if (group.children) { |
| 67 | + const isPropertiesGroup = group.children.every( |
| 68 | + (child) => child.kind === ReflectionKind.Property, |
| 69 | + ); |
| 70 | + |
| 71 | + const isEnumGroup = group.children.every( |
| 72 | + (child) => child.kind === ReflectionKind.EnumMember, |
| 73 | + ); |
| 74 | + |
| 75 | + md.push(heading(options.headingLevel, getGroupTitle(group.title))); |
| 76 | + |
| 77 | + if (group.description) { |
| 78 | + md.push(this.helpers.getCommentParts(group.description)); |
| 79 | + } |
| 80 | + if ( |
| 81 | + isPropertiesGroup && |
| 82 | + this.helpers.useTableFormat('properties', options.kind) |
| 83 | + ) { |
| 84 | + md.push( |
| 85 | + this.partials.propertiesTable( |
| 86 | + group.children as DeclarationReflection[], |
| 87 | + { |
| 88 | + isEventProps, |
| 89 | + }, |
| 90 | + ), |
| 91 | + ); |
| 92 | + } else if (isEnumGroup && this.helpers.useTableFormat('enums')) { |
70 | 93 | md.push(
|
71 |
| - this.partials.members(group.children as DeclarationReflection[], { |
72 |
| - headingLevel: options.headingLevel + 1, |
73 |
| - groupTitle: group.title, |
74 |
| - }), |
| 94 | + this.partials.enumMembersTable( |
| 95 | + group.children as DeclarationReflection[], |
| 96 | + ), |
75 | 97 | );
|
| 98 | + } else { |
| 99 | + if (group.children) { |
| 100 | + md.push( |
| 101 | + this.partials.members(group.children as DeclarationReflection[], { |
| 102 | + headingLevel: options.headingLevel + 1, |
| 103 | + groupTitle: group.title, |
| 104 | + }), |
| 105 | + ); |
| 106 | + } |
76 | 107 | }
|
77 | 108 | }
|
78 | 109 | }
|
|
0 commit comments