From 73e1dd6b9cfa634775465f011148f86e6733bb6a Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sun, 18 Aug 2024 10:37:27 -0600 Subject: [PATCH] Add navigation.compactFolders option Resolves #2667 --- CHANGELOG.md | 1 + .../output/themes/default/DefaultTheme.tsx | 28 ++++++++++--------- src/lib/utils/options/declaration.ts | 1 + src/lib/utils/options/sources/typedoc.ts | 1 + 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9808c1521..b0f540e66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Use of the `@extends` block tag no longer produces warnings, #2659. This tag should only be used in JavaScript projects to specify the type parameters used when extending a parent class. It will not be rendered. +- Added new `navigation.compactFolders` option to prevent TypeDoc from compacting folders, similar to the VSCode option. #2667. ### Bug Fixes diff --git a/src/lib/output/themes/default/DefaultTheme.tsx b/src/lib/output/themes/default/DefaultTheme.tsx index af860ba89..a1ed29de6 100644 --- a/src/lib/output/themes/default/DefaultTheme.tsx +++ b/src/lib/output/themes/default/DefaultTheme.tsx @@ -445,19 +445,21 @@ export class DefaultTheme extends Theme { // Now merge single-possible-paths together so we don't have folders in our navigation // which contain only another single folder. - const queue = [...result]; - while (queue.length) { - const review = queue.shift()!; - queue.push(...(review.children || [])); - if (review.kind || review.path) continue; - - if (review.children?.length === 1) { - const copyFrom = review.children[0]; - const fullName = `${review.text}/${copyFrom.text}`; - delete review.children; - Object.assign(review, copyFrom); - review.text = fullName; - queue.push(review); + if (opts.compactFolders) { + const queue = [...result]; + while (queue.length) { + const review = queue.shift()!; + queue.push(...(review.children || [])); + if (review.kind || review.path) continue; + + if (review.children?.length === 1) { + const copyFrom = review.children[0]; + const fullName = `${review.text}/${copyFrom.text}`; + delete review.children; + Object.assign(review, copyFrom); + review.text = fullName; + queue.push(review); + } } } diff --git a/src/lib/utils/options/declaration.ts b/src/lib/utils/options/declaration.ts index 480cbd935..2441b1589 100644 --- a/src/lib/utils/options/declaration.ts +++ b/src/lib/utils/options/declaration.ts @@ -180,6 +180,7 @@ export interface TypeDocOptionMap { includeCategories: boolean; includeGroups: boolean; includeFolders: boolean; + compactFolders: boolean; }; visibilityFilters: ManuallyValidatedOption<{ protected?: boolean; diff --git a/src/lib/utils/options/sources/typedoc.ts b/src/lib/utils/options/sources/typedoc.ts index 8676ad79e..13ac34654 100644 --- a/src/lib/utils/options/sources/typedoc.ts +++ b/src/lib/utils/options/sources/typedoc.ts @@ -548,6 +548,7 @@ export function addTypeDocOptions(options: Pick) { includeCategories: false, includeGroups: false, includeFolders: true, + compactFolders: true, }, });