Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions packages/docusaurus-theme-common/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,16 @@ export {
useTitleFormatter,
} from './utils/titleFormatterUtils';

export {useLocationChange} from './utils/useLocationChange';

export {useLocalPathname} from './utils/useLocalPathname';

export {
useHistoryPopHandler,
useHistorySelector,
useQueryStringValue,
} from './utils/historyUtils';
export {useQueryStringValue} from './utils/historyUtils';

export {
useFilteredAndTreeifiedTOC,
useTreeifiedTOC,
type TOCTreeNode,
} from './utils/tocUtils';
export {useFilteredAndTreeifiedTOC, type TOCTreeNode} from './utils/tocUtils';

export {
ScrollControllerProvider,
useScrollController,
useScrollPosition,
useScrollPositionBlocker,
useSmoothScrollTo,
} from './utils/scrollUtils';

export {useHomePageRoute, isSamePath} from './utils/routesUtils';
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// @vitest-environment jsdom
import {describe, expect, it} from 'vitest';
import {renderHook} from '@testing-library/react';
import {useFilteredAndTreeifiedTOC, useTreeifiedTOC} from '../tocUtils';
import {useFilteredAndTreeifiedTOC} from '../tocUtils';
import type {TOCItem} from '@docusaurus/mdx-loader';

const mockTOC: TOCItem[] = [
Expand Down Expand Up @@ -38,14 +38,6 @@ const mockTOC: TOCItem[] = [
},
];

describe('useTreeifiedTOC', () => {
it('treeifies TOC without filtering', () => {
expect(
renderHook(() => useTreeifiedTOC(mockTOC)).result.current,
).toMatchSnapshot();
});
});

describe('useFilteredAndTreeifiedTOC', () => {
it('filters a toc with all heading levels', () => {
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function ScrollControllerProvider({
* This API permits to temporarily disable/ignore scroll events. Motivated by
* https://github.com/facebook/docusaurus/pull/5618
*/
export function useScrollController(): ScrollController {
function useScrollController(): ScrollController {
const context = useContext(ScrollMonitorContext);
if (context == null) {
throw new ReactContextError('ScrollControllerProvider');
Expand Down
10 changes: 1 addition & 9 deletions packages/docusaurus-theme-common/src/utils/tocUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ function treeifyTOC(flatTOC: readonly TOCItem[]): TOCTreeNode[] {
return rootNodes;
}

/**
* Takes a flat TOC list (from the MDX loader) and treeifies it into what the
* TOC components expect. Memoized for performance.
*/
export function useTreeifiedTOC(toc: TOCItem[]): readonly TOCTreeNode[] {
return useMemo(() => treeifyTOC(toc), [toc]);
}

function filterTOC({
toc,
minHeadingLevel,
Expand Down Expand Up @@ -96,7 +88,7 @@ function filterTOC({
* TOC components expect, applying the `minHeadingLevel` and `maxHeadingLevel`.
* Memoized for performance.
*
* **Important**: this is not the same as `useTreeifiedTOC(toc.filter(...))`,
* **Important**: this is not the same as `treeifyTOC(toc.filter(...))`,
* because we have to filter the TOC after it has been treeified. This is mostly
* to ensure that weird TOC structures preserve their semantics. For example, an
* h3-h2-h4 sequence should not be treeified as an "h3 > h4" hierarchy with
Expand Down
Loading