diff --git a/src/index.ts b/src/index.ts index fb6dc1db4..c67d34241 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,6 +30,7 @@ export { TSConfigReader, TypeDocReader, EntryPointStrategy, + VisibilityFilter, EventHooks, } from "./lib/utils"; diff --git a/src/lib/output/themes/default/assets/typedoc/components/Filter.ts b/src/lib/output/themes/default/assets/typedoc/components/Filter.ts index f644b8a97..05628b095 100644 --- a/src/lib/output/themes/default/assets/typedoc/components/Filter.ts +++ b/src/lib/output/themes/default/assets/typedoc/components/Filter.ts @@ -8,10 +8,10 @@ abstract class FilterItem { protected defaultValue: T; - constructor(key: string, value: T) { + constructor(key: string) { this.key = key; - this.value = value; - this.defaultValue = value; + this.value; + this.defaultValue; this.initialize(); @@ -50,6 +50,8 @@ class FilterItemCheckbox extends FilterItem { if (!checkbox) return; this.checkbox = checkbox; + this.value = !!checkbox.checked; + this.defaultValue = this.value; this.checkbox.addEventListener("change", () => { this.setValue(this.checkbox.checked); }); @@ -77,16 +79,18 @@ class FilterItemSelect extends FilterItem { private select!: HTMLElement; protected override initialize() { - document.documentElement.classList.add( - "toggle-" + this.key + this.value - ); - const select = document.querySelector( "#tsd-filter-" + this.key ); if (!select) return; + const selectedEl = select.querySelector("li.selected"); this.select = select; + this.value = selectedEl.getAttribute("data-value"); + this.defaultValue = this.value; + document.documentElement.classList.add( + "toggle-" + this.key + this.value + ); const onActivate = () => { this.select.classList.add("active"); }; @@ -151,9 +155,9 @@ export class Filter extends Component { constructor(options: IComponentOptions) { super(options); - this.optionVisibility = new FilterItemSelect("visibility", "private"); - this.optionInherited = new FilterItemCheckbox("inherited", true); - this.optionExternals = new FilterItemCheckbox("externals", true); + this.optionVisibility = new FilterItemSelect("visibility"); + this.optionInherited = new FilterItemCheckbox("inherited"); + this.optionExternals = new FilterItemCheckbox("externals"); } static isSupported(): boolean { diff --git a/src/lib/output/themes/default/partials/header.tsx b/src/lib/output/themes/default/partials/header.tsx index e95185d09..3c15b1b88 100644 --- a/src/lib/output/themes/default/partials/header.tsx +++ b/src/lib/output/themes/default/partials/header.tsx @@ -1,85 +1,113 @@ import type { Reflection } from "../../../../models"; -import { JSX } from "../../../../utils"; +import { JSX, VisibilityFilter } from "../../../../utils"; import type { PageEvent } from "../../../events"; import { hasTypeParameters, join } from "../../lib"; import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext"; -export const header = (context: DefaultThemeRenderContext, props: PageEvent) => ( -
-
-
-
- +export const header = (context: DefaultThemeRenderContext, props: PageEvent) => { + const defaultSelectedVisibility = context.options.getValue("visibility"); + const selectedVisibility = Object.keys(visibilityFilterLabels).includes(defaultSelectedVisibility) + ? (defaultSelectedVisibility as VisibilityFilter) + : VisibilityFilter.all; + const defaultInheritedChecked = context.options.getValue("showInherited"); + const defaultExternalsChecked = context.options.getValue("showExternals"); -
-
- - Options - -
-
- All -
    -
  • Public
  • -
  • Public/Protected
  • -
  • - All -
  • -
-
{" "} - -
-
-
- {!!props.model.parent &&
    {context.breadcrumb(props.model)}
} -

- {props.model.kindString !== "Project" && `${props.model.kindString ?? ""} `} - {props.model.name} - {hasTypeParameters(props.model) && ( - <> - {"<"} - {join(", ", props.model.typeParameters, (item) => item.name)} - {">"} - - )} -

+
+
+ {!!props.model.parent &&
    {context.breadcrumb(props.model)}
} +

+ {props.model.kindString !== "Project" && `${props.model.kindString ?? ""} `} + {props.model.name} + {hasTypeParameters(props.model) && ( + <> + {"<"} + {join(", ", props.model.typeParameters, (item) => item.name)} + {">"} + + )} +

+
-
-
-); + + ); +}; diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index be59a7d18..c2159daa4 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -28,6 +28,7 @@ export { ParameterType, TSConfigReader, TypeDocReader, + VisibilityFilter, } from "./options"; export type { ArrayDeclarationOption, diff --git a/src/lib/utils/options/declaration.ts b/src/lib/utils/options/declaration.ts index 5b600cba9..e03a9c0f4 100644 --- a/src/lib/utils/options/declaration.ts +++ b/src/lib/utils/options/declaration.ts @@ -49,6 +49,12 @@ export type TypeDocOptionValues = { : TypeDocOptionMap[K][keyof TypeDocOptionMap[K]]; }; +export enum VisibilityFilter { + all = "private", + public = "public", + protected = "protected", +} + /** * Describes all TypeDoc options. Used internally to provide better types when fetching options. * External consumers should likely use {@link TypeDocOptions} instead. @@ -60,6 +66,11 @@ export interface TypeDocOptionMap { entryPoints: string[]; entryPointStrategy: typeof EntryPointStrategy; + // typedoc header filters + visibility: string; + showInherited: boolean; + showExternals: boolean; + exclude: string[]; externalPattern: string[]; excludeExternals: boolean; diff --git a/src/lib/utils/options/index.ts b/src/lib/utils/options/index.ts index 4583415df..3d17b67be 100644 --- a/src/lib/utils/options/index.ts +++ b/src/lib/utils/options/index.ts @@ -1,7 +1,12 @@ export { Options, BindOption } from "./options"; export type { OptionsReader } from "./options"; export { ArgumentsReader, TypeDocReader, TSConfigReader } from "./readers"; -export { EmitStrategy, ParameterType, ParameterHint } from "./declaration"; +export { + EmitStrategy, + ParameterType, + ParameterHint, + VisibilityFilter, +} from "./declaration"; export type { TypeDocOptions, diff --git a/src/lib/utils/options/sources/typedoc.ts b/src/lib/utils/options/sources/typedoc.ts index 8d9ebd79d..ea6294d49 100644 --- a/src/lib/utils/options/sources/typedoc.ts +++ b/src/lib/utils/options/sources/typedoc.ts @@ -33,6 +33,25 @@ export function addTypeDocOptions(options: Pick) { defaultValue: EntryPointStrategy.Resolve, }); + options.addDeclaration({ + name: "visibility", + help: 'Specify the default visibility for methods, possible values: "private" | "public" | "protected"', + type: ParameterType.String, + defaultValue: "private", + }); + options.addDeclaration({ + name: "showInherited", + help: "Specify the default inherited checkbox value", + type: ParameterType.Boolean, + defaultValue: true, + }); + options.addDeclaration({ + name: "showExternals", + help: "Specify the default externals checkbox value", + type: ParameterType.Boolean, + defaultValue: true, + }); + options.addDeclaration({ name: "exclude", help: "Define patterns to be excluded when expanding a directory that was specified as an entry point.",