diff --git a/.eslintrc.js b/.eslintrc.js index 6708ef87f1f9..42e5e054f282 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -451,6 +451,7 @@ module.exports = { 'admin/**', 'jest/**', 'website/**', + 'packages/docusaurus-theme-common/removeThemeInternalReexport.mjs', 'packages/docusaurus-theme-translations/update.mjs', 'packages/docusaurus-theme-translations/src/utils.ts', ], diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f60d708e46a3..8cd830ce2321 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,3 +40,7 @@ jobs: run: yarn test - name: TypeCheck website run: yarn workspace website typecheck + - name: Remove Theme Internal Re-export + run: yarn workspace @docusaurus/theme-common removeThemeInternalReexport + - name: Docusaurus Build + run: yarn build:website:fast diff --git a/packages/docusaurus-theme-classic/src/theme-classic.d.ts b/packages/docusaurus-theme-classic/src/theme-classic.d.ts index c6d1fb357572..f248ab38a053 100644 --- a/packages/docusaurus-theme-classic/src/theme-classic.d.ts +++ b/packages/docusaurus-theme-classic/src/theme-classic.d.ts @@ -1103,7 +1103,7 @@ declare module '@theme/TOCItems' { } declare module '@theme/TOCItems/Tree' { - import type {TOCTreeNode} from '@docusaurus/theme-common'; + import type {TOCTreeNode} from '@docusaurus/theme-common/internal'; export interface Props { readonly toc: readonly TOCTreeNode[]; diff --git a/packages/docusaurus-theme-classic/src/theme/AnnouncementBar/index.tsx b/packages/docusaurus-theme-classic/src/theme/AnnouncementBar/index.tsx index 26ad85727639..771136d4d6da 100644 --- a/packages/docusaurus-theme-classic/src/theme/AnnouncementBar/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/AnnouncementBar/index.tsx @@ -7,7 +7,8 @@ import React from 'react'; import clsx from 'clsx'; -import {useThemeConfig, useAnnouncementBar} from '@docusaurus/theme-common'; +import {useThemeConfig} from '@docusaurus/theme-common'; +import {useAnnouncementBar} from '@docusaurus/theme-common/internal'; import {translate} from '@docusaurus/Translate'; import IconClose from '@theme/IconClose'; diff --git a/packages/docusaurus-theme-classic/src/theme/BackToTopButton/index.tsx b/packages/docusaurus-theme-classic/src/theme/BackToTopButton/index.tsx index d5e4edfc4134..f2d7a9ddb362 100644 --- a/packages/docusaurus-theme-classic/src/theme/BackToTopButton/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/BackToTopButton/index.tsx @@ -8,7 +8,8 @@ import React from 'react'; import clsx from 'clsx'; import {translate} from '@docusaurus/Translate'; -import {ThemeClassNames, useBackToTopButton} from '@docusaurus/theme-common'; +import {ThemeClassNames} from '@docusaurus/theme-common'; +import {useBackToTopButton} from '@docusaurus/theme-common/internal'; import styles from './styles.module.css'; diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Container/index.tsx b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Container/index.tsx index 3e3961027373..d4814add5a76 100644 --- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Container/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Container/index.tsx @@ -7,11 +7,8 @@ import React, {type ComponentProps} from 'react'; import clsx from 'clsx'; -import { - usePrismTheme, - getPrismCssVariables, - ThemeClassNames, -} from '@docusaurus/theme-common'; +import {ThemeClassNames, usePrismTheme} from '@docusaurus/theme-common'; +import {getPrismCssVariables} from '@docusaurus/theme-common/internal'; import styles from './styles.module.css'; export default function CodeBlockContainer({ diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx index 9947164ddbef..e1c72d0640ba 100644 --- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx +++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Content/String.tsx @@ -7,15 +7,14 @@ import React from 'react'; import clsx from 'clsx'; +import {useThemeConfig, usePrismTheme} from '@docusaurus/theme-common'; import { - useThemeConfig, parseCodeBlockTitle, parseLanguage, parseLines, containsLineNumbers, - usePrismTheme, useCodeWordWrap, -} from '@docusaurus/theme-common'; +} from '@docusaurus/theme-common/internal'; import Highlight, {defaultProps, type Language} from 'prism-react-renderer'; import Line from '@theme/CodeBlock/Line'; import CopyButton from '@theme/CodeBlock/CopyButton'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocBreadcrumbs/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocBreadcrumbs/index.tsx index 44200b2f329a..29fad8f97044 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocBreadcrumbs/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocBreadcrumbs/index.tsx @@ -7,11 +7,11 @@ import React, {type ReactNode} from 'react'; import clsx from 'clsx'; +import {ThemeClassNames} from '@docusaurus/theme-common'; import { - ThemeClassNames, useSidebarBreadcrumbs, useHomePageRoute, -} from '@docusaurus/theme-common'; +} from '@docusaurus/theme-common/internal'; import Link from '@docusaurus/Link'; import useBaseUrl from '@docusaurus/useBaseUrl'; import {translate} from '@docusaurus/Translate'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocCard/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocCard/index.tsx index fc63f1949f47..7409ee970370 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocCard/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocCard/index.tsx @@ -8,7 +8,10 @@ import React, {type ReactNode} from 'react'; import clsx from 'clsx'; import Link from '@docusaurus/Link'; -import {findFirstCategoryLink, useDocById} from '@docusaurus/theme-common'; +import { + findFirstCategoryLink, + useDocById, +} from '@docusaurus/theme-common/internal'; import isInternalUrl from '@docusaurus/isInternalUrl'; import {translate} from '@docusaurus/Translate'; import type {Props} from '@theme/DocCard'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocCardList/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocCardList/index.tsx index b2d480697ac3..c4ace5f5ee6c 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocCardList/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocCardList/index.tsx @@ -7,7 +7,7 @@ import React from 'react'; import clsx from 'clsx'; -import {findFirstCategoryLink} from '@docusaurus/theme-common'; +import {findFirstCategoryLink} from '@docusaurus/theme-common/internal'; import DocCard from '@theme/DocCard'; import type {Props} from '@theme/DocCardList'; import type {PropSidebarItem} from '@docusaurus/plugin-content-docs'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/Content/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocItem/Content/index.tsx index 4c7ff285c47b..7ac92026a05f 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/Content/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/Content/index.tsx @@ -7,7 +7,8 @@ import React from 'react'; import clsx from 'clsx'; -import {ThemeClassNames, useDoc} from '@docusaurus/theme-common'; +import {ThemeClassNames} from '@docusaurus/theme-common'; +import {useDoc} from '@docusaurus/theme-common/internal'; import Heading from '@theme/Heading'; import MDXContent from '@theme/MDXContent'; import type {Props} from '@theme/DocItem/Content'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/Footer/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocItem/Footer/index.tsx index 0522e95207a2..971d7a8ff754 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/Footer/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/Footer/index.tsx @@ -7,11 +7,8 @@ import React from 'react'; import clsx from 'clsx'; -import { - ThemeClassNames, - useDoc, - type DocContextValue, -} from '@docusaurus/theme-common'; +import {ThemeClassNames} from '@docusaurus/theme-common'; +import {useDoc, type DocContextValue} from '@docusaurus/theme-common/internal'; import LastUpdated from '@theme/LastUpdated'; import EditThisPage from '@theme/EditThisPage'; import TagsListInline, { diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/Layout/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocItem/Layout/index.tsx index b09d6744765e..ff5ab6d1a39a 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/Layout/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/Layout/index.tsx @@ -7,7 +7,8 @@ import React from 'react'; import clsx from 'clsx'; -import {useWindowSize, useDoc} from '@docusaurus/theme-common'; +import {useWindowSize} from '@docusaurus/theme-common'; +import {useDoc} from '@docusaurus/theme-common/internal'; import DocItemPaginator from '@theme/DocItem/Paginator'; import DocVersionBanner from '@theme/DocVersionBanner'; import DocVersionBadge from '@theme/DocVersionBadge'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/Metadata/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocItem/Metadata/index.tsx index c2f41a75628f..3e75ee053a0d 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/Metadata/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/Metadata/index.tsx @@ -6,7 +6,8 @@ */ import React from 'react'; -import {PageMetadata, useDoc} from '@docusaurus/theme-common'; +import {PageMetadata} from '@docusaurus/theme-common'; +import {useDoc} from '@docusaurus/theme-common/internal'; export default function DocItemMetadata(): JSX.Element { const {metadata, frontMatter, assets} = useDoc(); diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/Paginator/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocItem/Paginator/index.tsx index 6a42fc8abba9..0ef558cb529e 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/Paginator/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/Paginator/index.tsx @@ -6,7 +6,7 @@ */ import React from 'react'; -import {useDoc} from '@docusaurus/theme-common'; +import {useDoc} from '@docusaurus/theme-common/internal'; import DocPaginator from '@theme/DocPaginator'; /** diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/TOC/Desktop/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocItem/TOC/Desktop/index.tsx index 1ec0a1f59162..14bf447cd855 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/TOC/Desktop/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/TOC/Desktop/index.tsx @@ -6,7 +6,8 @@ */ import React from 'react'; -import {ThemeClassNames, useDoc} from '@docusaurus/theme-common'; +import {ThemeClassNames} from '@docusaurus/theme-common'; +import {useDoc} from '@docusaurus/theme-common/internal'; import TOC from '@theme/TOC'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/TOC/Mobile/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocItem/TOC/Mobile/index.tsx index dd3a954dbbfb..c941e77b6274 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/TOC/Mobile/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/TOC/Mobile/index.tsx @@ -7,7 +7,9 @@ import React from 'react'; import clsx from 'clsx'; -import {ThemeClassNames, useDoc} from '@docusaurus/theme-common'; +import {ThemeClassNames} from '@docusaurus/theme-common'; +import {useDoc} from '@docusaurus/theme-common/internal'; + import TOCCollapsible from '@theme/TOCCollapsible'; import styles from './styles.module.css'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocItem/index.tsx index ff960872b2ac..e4b0c7cf1046 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.tsx @@ -6,7 +6,8 @@ */ import React from 'react'; -import {HtmlClassNameProvider, DocProvider} from '@docusaurus/theme-common'; +import {HtmlClassNameProvider} from '@docusaurus/theme-common'; +import {DocProvider} from '@docusaurus/theme-common/internal'; import DocItemMetadata from '@theme/DocItem/Metadata'; import DocItemLayout from '@theme/DocItem/Layout'; import type {Props} from '@theme/DocItem'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocPage/Layout/Main/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocPage/Layout/Main/index.tsx index 61ccdafdb6cc..eb19b3549c89 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocPage/Layout/Main/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocPage/Layout/Main/index.tsx @@ -7,7 +7,7 @@ import React from 'react'; import clsx from 'clsx'; -import {useDocsSidebar} from '@docusaurus/theme-common'; +import {useDocsSidebar} from '@docusaurus/theme-common/internal'; import type {Props} from '@theme/DocPage/Layout/Main'; import styles from './styles.module.css'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocPage/Layout/Sidebar/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocPage/Layout/Sidebar/index.tsx index 150fd888a3ef..a88302612113 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocPage/Layout/Sidebar/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocPage/Layout/Sidebar/index.tsx @@ -7,7 +7,8 @@ import React, {type ReactNode, useState, useCallback} from 'react'; import clsx from 'clsx'; -import {ThemeClassNames, useDocsSidebar} from '@docusaurus/theme-common'; +import {ThemeClassNames} from '@docusaurus/theme-common'; +import {useDocsSidebar} from '@docusaurus/theme-common/internal'; import {useLocation} from '@docusaurus/router'; import DocSidebar from '@theme/DocSidebar'; import ExpandButton from '@theme/DocPage/Layout/Sidebar/ExpandButton'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocPage/Layout/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocPage/Layout/index.tsx index d5a48c1a68b1..0ff53b286d16 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocPage/Layout/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocPage/Layout/index.tsx @@ -6,7 +6,7 @@ */ import React, {useState} from 'react'; -import {useDocsSidebar} from '@docusaurus/theme-common'; +import {useDocsSidebar} from '@docusaurus/theme-common/internal'; import Layout from '@theme/Layout'; import BackToTopButton from '@theme/BackToTopButton'; import DocPageLayoutSidebar from '@theme/DocPage/Layout/Sidebar'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocPage/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocPage/index.tsx index 3e45dbbda399..506fd5c72aa7 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocPage/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocPage/index.tsx @@ -7,14 +7,13 @@ import React from 'react'; import clsx from 'clsx'; +import {HtmlClassNameProvider, ThemeClassNames} from '@docusaurus/theme-common'; import { - HtmlClassNameProvider, - ThemeClassNames, docVersionSearchTag, DocsSidebarProvider, DocsVersionProvider, useDocRouteMetadata, -} from '@docusaurus/theme-common'; +} from '@docusaurus/theme-common/internal'; import DocPageLayout from '@theme/DocPage/Layout'; import NotFound from '@theme/NotFound'; import SearchMetadata from '@theme/SearchMetadata'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocSidebar/Desktop/Content/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocSidebar/Desktop/Content/index.tsx index f72a9c27a3d0..120f4509c1a1 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocSidebar/Desktop/Content/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocSidebar/Desktop/Content/index.tsx @@ -7,11 +7,11 @@ import React, {useState} from 'react'; import clsx from 'clsx'; +import {ThemeClassNames} from '@docusaurus/theme-common'; import { - ThemeClassNames, useAnnouncementBar, useScrollPosition, -} from '@docusaurus/theme-common'; +} from '@docusaurus/theme-common/internal'; import DocSidebarItems from '@theme/DocSidebarItems'; import type {Props} from '@theme/DocSidebar/Desktop/Content'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocSidebar/Mobile/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocSidebar/Mobile/index.tsx index 48314ab6b12e..4cfd2b98a520 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocSidebar/Mobile/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocSidebar/Mobile/index.tsx @@ -11,8 +11,8 @@ import { NavbarSecondaryMenuFiller, type NavbarSecondaryMenuComponent, ThemeClassNames, - useNavbarMobileSidebar, } from '@docusaurus/theme-common'; +import {useNavbarMobileSidebar} from '@docusaurus/theme-common/internal'; import DocSidebarItems from '@theme/DocSidebarItems'; import type {Props} from '@theme/DocSidebar/Mobile'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/Category/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/Category/index.tsx index 18047a9225ab..52c683c001f8 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/Category/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/Category/index.tsx @@ -8,16 +8,18 @@ import React, {type ComponentProps, useEffect, useMemo} from 'react'; import clsx from 'clsx'; import { - isActiveSidebarItem, + ThemeClassNames, + useThemeConfig, usePrevious, Collapsible, useCollapsible, +} from '@docusaurus/theme-common'; +import { + isActiveSidebarItem, findFirstCategoryLink, - ThemeClassNames, - useThemeConfig, useDocSidebarItemsExpandedState, isSamePath, -} from '@docusaurus/theme-common'; +} from '@docusaurus/theme-common/internal'; import Link from '@docusaurus/Link'; import {translate} from '@docusaurus/Translate'; import useIsBrowser from '@docusaurus/useIsBrowser'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/Link/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/Link/index.tsx index fc87268e01f0..f5a686722212 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/Link/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/Link/index.tsx @@ -7,7 +7,8 @@ import React from 'react'; import clsx from 'clsx'; -import {isActiveSidebarItem, ThemeClassNames} from '@docusaurus/theme-common'; +import {ThemeClassNames} from '@docusaurus/theme-common'; +import {isActiveSidebarItem} from '@docusaurus/theme-common/internal'; import Link from '@docusaurus/Link'; import isInternalUrl from '@docusaurus/isInternalUrl'; import IconExternalLink from '@theme/IconExternalLink'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocSidebarItems/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocSidebarItems/index.tsx index 041c553f284f..84060b9179d7 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocSidebarItems/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocSidebarItems/index.tsx @@ -6,7 +6,7 @@ */ import React, {memo} from 'react'; -import {DocSidebarItemsExpandedStateProvider} from '@docusaurus/theme-common'; +import {DocSidebarItemsExpandedStateProvider} from '@docusaurus/theme-common/internal'; import DocSidebarItem from '@theme/DocSidebarItem'; import type {Props} from '@theme/DocSidebarItems'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocVersionBadge/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocVersionBadge/index.tsx index dc4a2c90bbb1..d867068d0ad4 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocVersionBadge/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocVersionBadge/index.tsx @@ -8,7 +8,8 @@ import React from 'react'; import clsx from 'clsx'; import Translate from '@docusaurus/Translate'; -import {ThemeClassNames, useDocsVersion} from '@docusaurus/theme-common'; +import {ThemeClassNames} from '@docusaurus/theme-common'; +import {useDocsVersion} from '@docusaurus/theme-common/internal'; import type {Props} from '@theme/DocVersionBadge'; export default function DocVersionBadge({ diff --git a/packages/docusaurus-theme-classic/src/theme/DocVersionBanner/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocVersionBanner/index.tsx index 979a4f2b90a7..a9c1835bdf44 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocVersionBanner/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocVersionBanner/index.tsx @@ -15,12 +15,11 @@ import { useDocVersionSuggestions, type GlobalVersion, } from '@docusaurus/plugin-content-docs/client'; +import {ThemeClassNames} from '@docusaurus/theme-common'; import { - ThemeClassNames, useDocsPreferredVersion, useDocsVersion, -} from '@docusaurus/theme-common'; - +} from '@docusaurus/theme-common/internal'; import type {Props} from '@theme/DocVersionBanner'; import type { VersionBanner, diff --git a/packages/docusaurus-theme-classic/src/theme/Layout/index.tsx b/packages/docusaurus-theme-classic/src/theme/Layout/index.tsx index 7f58712af95c..47253c1a4c2d 100644 --- a/packages/docusaurus-theme-classic/src/theme/Layout/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Layout/index.tsx @@ -8,11 +8,8 @@ import React from 'react'; import clsx from 'clsx'; import ErrorBoundary from '@docusaurus/ErrorBoundary'; -import { - PageMetadata, - ThemeClassNames, - useKeyboardNavigation, -} from '@docusaurus/theme-common'; +import {PageMetadata, ThemeClassNames} from '@docusaurus/theme-common'; +import {useKeyboardNavigation} from '@docusaurus/theme-common/internal'; import SkipToContent from '@theme/SkipToContent'; import AnnouncementBar from '@theme/AnnouncementBar'; import Navbar from '@theme/Navbar'; diff --git a/packages/docusaurus-theme-classic/src/theme/LayoutProviders/index.tsx b/packages/docusaurus-theme-classic/src/theme/LayoutProviders/index.tsx index 9eba0ff42336..063646f93a3c 100644 --- a/packages/docusaurus-theme-classic/src/theme/LayoutProviders/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/LayoutProviders/index.tsx @@ -14,7 +14,7 @@ import { ScrollControllerProvider, NavbarProvider, PluginHtmlClassNameProvider, -} from '@docusaurus/theme-common'; +} from '@docusaurus/theme-common/internal'; import type {Props} from '@theme/LayoutProviders'; export default function LayoutProviders({children}: Props): JSX.Element { diff --git a/packages/docusaurus-theme-classic/src/theme/Navbar/Content/index.tsx b/packages/docusaurus-theme-classic/src/theme/Navbar/Content/index.tsx index c81437a3fa8b..e499198ecabf 100644 --- a/packages/docusaurus-theme-classic/src/theme/Navbar/Content/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Navbar/Content/index.tsx @@ -6,11 +6,11 @@ */ import React, {type ReactNode} from 'react'; +import {useThemeConfig} from '@docusaurus/theme-common'; import { splitNavbarItems, useNavbarMobileSidebar, - useThemeConfig, -} from '@docusaurus/theme-common'; +} from '@docusaurus/theme-common/internal'; import NavbarItem, {type Props as NavbarItemConfig} from '@theme/NavbarItem'; import NavbarColorModeToggle from '@theme/Navbar/ColorModeToggle'; import SearchBar from '@theme/SearchBar'; diff --git a/packages/docusaurus-theme-classic/src/theme/Navbar/Layout/index.tsx b/packages/docusaurus-theme-classic/src/theme/Navbar/Layout/index.tsx index b674fe726985..b957573e8cc9 100644 --- a/packages/docusaurus-theme-classic/src/theme/Navbar/Layout/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Navbar/Layout/index.tsx @@ -7,11 +7,11 @@ import React, {type ComponentProps} from 'react'; import clsx from 'clsx'; +import {useThemeConfig} from '@docusaurus/theme-common'; import { - useThemeConfig, useHideableNavbar, useNavbarMobileSidebar, -} from '@docusaurus/theme-common'; +} from '@docusaurus/theme-common/internal'; import NavbarMobileSidebar from '@theme/Navbar/MobileSidebar'; import type {Props} from '@theme/Navbar/Layout'; diff --git a/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/Header/index.tsx b/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/Header/index.tsx index 139377115323..ed08c5375010 100644 --- a/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/Header/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/Header/index.tsx @@ -6,7 +6,7 @@ */ import React from 'react'; -import {useNavbarMobileSidebar} from '@docusaurus/theme-common'; +import {useNavbarMobileSidebar} from '@docusaurus/theme-common/internal'; import NavbarColorModeToggle from '@theme/Navbar/ColorModeToggle'; import IconClose from '@theme/IconClose'; import NavbarLogo from '@theme/Navbar/Logo'; diff --git a/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/Layout/index.tsx b/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/Layout/index.tsx index 6d63029dbd31..b3bbaec8fae0 100644 --- a/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/Layout/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/Layout/index.tsx @@ -7,7 +7,7 @@ import React from 'react'; import clsx from 'clsx'; -import {useNavbarSecondaryMenu} from '@docusaurus/theme-common'; +import {useNavbarSecondaryMenu} from '@docusaurus/theme-common/internal'; import type {Props} from '@theme/Navbar/MobileSidebar/Layout'; export default function NavbarMobileSidebarLayout({ diff --git a/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/PrimaryMenu/index.tsx b/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/PrimaryMenu/index.tsx index 3fec36ad617d..5b3c180b7506 100644 --- a/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/PrimaryMenu/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/PrimaryMenu/index.tsx @@ -6,7 +6,8 @@ */ import React from 'react'; -import {useNavbarMobileSidebar, useThemeConfig} from '@docusaurus/theme-common'; +import {useThemeConfig} from '@docusaurus/theme-common'; +import {useNavbarMobileSidebar} from '@docusaurus/theme-common/internal'; import NavbarItem, {type Props as NavbarItemConfig} from '@theme/NavbarItem'; function useNavbarItems() { diff --git a/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/SecondaryMenu/index.tsx b/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/SecondaryMenu/index.tsx index a15ba55c5684..3fe85e1a9b45 100644 --- a/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/SecondaryMenu/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/SecondaryMenu/index.tsx @@ -6,7 +6,8 @@ */ import React, {type ComponentProps} from 'react'; -import {useNavbarSecondaryMenu, useThemeConfig} from '@docusaurus/theme-common'; +import {useThemeConfig} from '@docusaurus/theme-common'; +import {useNavbarSecondaryMenu} from '@docusaurus/theme-common/internal'; import Translate from '@docusaurus/Translate'; function SecondaryMenuBackButton(props: ComponentProps<'button'>) { diff --git a/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/Toggle/index.tsx b/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/Toggle/index.tsx index 6ac64154d36c..537680caeded 100644 --- a/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/Toggle/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/Toggle/index.tsx @@ -6,7 +6,7 @@ */ import React from 'react'; -import {useNavbarMobileSidebar} from '@docusaurus/theme-common'; +import {useNavbarMobileSidebar} from '@docusaurus/theme-common/internal'; import IconMenu from '@theme/IconMenu'; export default function MobileSidebarToggle(): JSX.Element { diff --git a/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/index.tsx b/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/index.tsx index 4ee13c284efc..44467ae79363 100644 --- a/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Navbar/MobileSidebar/index.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { useLockBodyScroll, useNavbarMobileSidebar, -} from '@docusaurus/theme-common'; +} from '@docusaurus/theme-common/internal'; import NavbarMobileSidebarLayout from '@theme/Navbar/MobileSidebar/Layout'; import NavbarMobileSidebarHeader from '@theme/Navbar/MobileSidebar/Header'; import NavbarMobileSidebarPrimaryMenu from '@theme/Navbar/MobileSidebar/PrimaryMenu'; diff --git a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocNavbarItem.tsx b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocNavbarItem.tsx index 76df1591ba90..3703fdec1fa8 100644 --- a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocNavbarItem.tsx +++ b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocNavbarItem.tsx @@ -7,7 +7,7 @@ import React from 'react'; import {useActiveDocContext} from '@docusaurus/plugin-content-docs/client'; -import {useLayoutDoc} from '@docusaurus/theme-common'; +import {useLayoutDoc} from '@docusaurus/theme-common/internal'; import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem'; import type {Props} from '@theme/NavbarItem/DocNavbarItem'; diff --git a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocSidebarNavbarItem.tsx b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocSidebarNavbarItem.tsx index 08771f8aa6c7..2fefc7b3b2a9 100644 --- a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocSidebarNavbarItem.tsx +++ b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocSidebarNavbarItem.tsx @@ -7,7 +7,7 @@ import React from 'react'; import {useActiveDocContext} from '@docusaurus/plugin-content-docs/client'; -import {useLayoutDocsSidebar} from '@docusaurus/theme-common'; +import {useLayoutDocsSidebar} from '@docusaurus/theme-common/internal'; import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem'; import type {Props} from '@theme/NavbarItem/DocSidebarNavbarItem'; diff --git a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx index 8893306f7abd..831e6fb06b07 100644 --- a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +++ b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx @@ -13,7 +13,7 @@ import { import { useDocsPreferredVersion, useDocsVersionCandidates, -} from '@docusaurus/theme-common'; +} from '@docusaurus/theme-common/internal'; import {translate} from '@docusaurus/Translate'; import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem'; import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem'; diff --git a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionNavbarItem.tsx b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionNavbarItem.tsx index aade004e44d4..10d197992b7c 100644 --- a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionNavbarItem.tsx +++ b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionNavbarItem.tsx @@ -6,7 +6,7 @@ */ import React from 'react'; -import {useDocsVersionCandidates} from '@docusaurus/theme-common'; +import {useDocsVersionCandidates} from '@docusaurus/theme-common/internal'; import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem'; import type {Props} from '@theme/NavbarItem/DocsVersionNavbarItem'; import type {GlobalVersion} from '@docusaurus/plugin-content-docs/client'; diff --git a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem.tsx b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem.tsx index 3678d9d0bb03..f6fc318bbcae 100644 --- a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem.tsx +++ b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem.tsx @@ -8,12 +8,11 @@ import React, {useState, useRef, useEffect} from 'react'; import clsx from 'clsx'; import { - isSamePath, + isRegexpStringMatch, useCollapsible, Collapsible, - isRegexpStringMatch, - useLocalPathname, } from '@docusaurus/theme-common'; +import {isSamePath, useLocalPathname} from '@docusaurus/theme-common/internal'; import NavbarNavLink from '@theme/NavbarItem/NavbarNavLink'; import NavbarItem, {type LinkLikeNavbarItemProps} from '@theme/NavbarItem'; import type { diff --git a/packages/docusaurus-theme-classic/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx b/packages/docusaurus-theme-classic/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx index 3e6a20838393..3a6022c87e3d 100644 --- a/packages/docusaurus-theme-classic/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx @@ -7,7 +7,7 @@ import React from 'react'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; -import {useAlternatePageUtils} from '@docusaurus/theme-common'; +import {useAlternatePageUtils} from '@docusaurus/theme-common/internal'; import {translate} from '@docusaurus/Translate'; import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem'; import IconLanguage from '@theme/IconLanguage'; diff --git a/packages/docusaurus-theme-classic/src/theme/SiteMetadata/index.tsx b/packages/docusaurus-theme-classic/src/theme/SiteMetadata/index.tsx index 5fa827569181..9a30c775fff2 100644 --- a/packages/docusaurus-theme-classic/src/theme/SiteMetadata/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/SiteMetadata/index.tsx @@ -9,13 +9,12 @@ import React from 'react'; import Head from '@docusaurus/Head'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import useBaseUrl from '@docusaurus/useBaseUrl'; +import {PageMetadata, useThemeConfig} from '@docusaurus/theme-common'; import { - PageMetadata, DEFAULT_SEARCH_TAG, useAlternatePageUtils, - useThemeConfig, keyboardFocusedClassName, -} from '@docusaurus/theme-common'; +} from '@docusaurus/theme-common/internal'; import {useLocation} from '@docusaurus/router'; import SearchMetadata from '@theme/SearchMetadata'; diff --git a/packages/docusaurus-theme-classic/src/theme/SkipToContent/index.tsx b/packages/docusaurus-theme-classic/src/theme/SkipToContent/index.tsx index 6092df125130..0efd066e409f 100644 --- a/packages/docusaurus-theme-classic/src/theme/SkipToContent/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/SkipToContent/index.tsx @@ -7,7 +7,7 @@ import React from 'react'; import Translate from '@docusaurus/Translate'; -import {useSkipToContent} from '@docusaurus/theme-common'; +import {useSkipToContent} from '@docusaurus/theme-common/internal'; import styles from './styles.module.css'; diff --git a/packages/docusaurus-theme-classic/src/theme/TOCItems/index.tsx b/packages/docusaurus-theme-classic/src/theme/TOCItems/index.tsx index 3743706a4462..c150cf87cb09 100644 --- a/packages/docusaurus-theme-classic/src/theme/TOCItems/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/TOCItems/index.tsx @@ -6,12 +6,12 @@ */ import React, {useMemo} from 'react'; +import {useThemeConfig} from '@docusaurus/theme-common'; import { - type TOCHighlightConfig, - useThemeConfig, useTOCHighlight, useFilteredAndTreeifiedTOC, -} from '@docusaurus/theme-common'; + type TOCHighlightConfig, +} from '@docusaurus/theme-common/internal'; import TOCItemTree from '@theme/TOCItems/Tree'; import type {Props} from '@theme/TOCItems'; diff --git a/packages/docusaurus-theme-classic/src/theme/Tabs/__tests__/index.test.tsx b/packages/docusaurus-theme-classic/src/theme/Tabs/__tests__/index.test.tsx index 79329bf518aa..cedcbe9f4120 100644 --- a/packages/docusaurus-theme-classic/src/theme/Tabs/__tests__/index.test.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Tabs/__tests__/index.test.tsx @@ -10,7 +10,7 @@ import renderer from 'react-test-renderer'; import { TabGroupChoiceProvider, ScrollControllerProvider, -} from '@docusaurus/theme-common'; +} from '@docusaurus/theme-common/internal'; import Tabs from '../index'; import TabItem from '../../TabItem'; diff --git a/packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx b/packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx index 098879881f9e..029eec193a28 100644 --- a/packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx @@ -13,11 +13,11 @@ import React, { } from 'react'; import clsx from 'clsx'; import useIsBrowser from '@docusaurus/useIsBrowser'; +import {duplicates} from '@docusaurus/theme-common'; import { useScrollPositionBlocker, - duplicates, useTabGroupChoice, -} from '@docusaurus/theme-common'; +} from '@docusaurus/theme-common/internal'; import type {Props} from '@theme/Tabs'; import type {Props as TabItemProps} from '@theme/TabItem'; diff --git a/packages/docusaurus-theme-common/.npmignore b/packages/docusaurus-theme-common/.npmignore index 03c9ae1e1b54..e396a4cd86e9 100644 --- a/packages/docusaurus-theme-common/.npmignore +++ b/packages/docusaurus-theme-common/.npmignore @@ -1,3 +1,4 @@ .tsbuildinfo* tsconfig* __tests__ +removeThemeInternalReexport.mjs diff --git a/packages/docusaurus-theme-common/package.json b/packages/docusaurus-theme-common/package.json index 6769b7f0e6f5..0acd830999ac 100644 --- a/packages/docusaurus-theme-common/package.json +++ b/packages/docusaurus-theme-common/package.json @@ -10,13 +10,15 @@ ], "exports": { ".": "./lib/index.js", + "./internal": "./lib/internal.js", "./Details": "./lib/components/Details/index.js" }, "scripts": { "build": "tsc && node ../../admin/scripts/copyUntypedFiles.js", "watch": "run-p -c copy:watch build:watch", "build:watch": "tsc --watch", - "copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch" + "copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch", + "removeThemeInternalReexport": "node removeThemeInternalReexport.mjs" }, "publishConfig": { "access": "public" diff --git a/packages/docusaurus-theme-common/removeThemeInternalReexport.mjs b/packages/docusaurus-theme-common/removeThemeInternalReexport.mjs new file mode 100644 index 000000000000..111b1ba1e07d --- /dev/null +++ b/packages/docusaurus-theme-common/removeThemeInternalReexport.mjs @@ -0,0 +1,32 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import fs from 'fs-extra'; + +// See comment in src/internal.ts +// This script should be run by CI tests to remove: +// export * from './index' + +const filePath = 'lib/internal.js'; +const lineToRemove = "export * from './index';\n"; + +if (!(await fs.pathExists(filePath))) { + throw new Error(`internal entrypoint file not found at ${filePath}`); +} + +const fileContent = await fs.readFile(filePath, 'utf8'); + +const fileContentUpdated = fileContent.replaceAll(lineToRemove, ''); + +// Ensure the script correctly removes the re-export +if (fileContent === fileContentUpdated) { + throw new Error( + 'Unexpected: internal re-export has not been replaced.\nMake sure this script works, and is only run once.', + ); +} + +await fs.writeFile(filePath, fileContentUpdated); diff --git a/packages/docusaurus-theme-common/src/index.ts b/packages/docusaurus-theme-common/src/index.ts index 67c34bc8cead..c8b5ea484e39 100644 --- a/packages/docusaurus-theme-common/src/index.ts +++ b/packages/docusaurus-theme-common/src/index.ts @@ -5,6 +5,10 @@ * LICENSE file in the root directory of this source tree. */ +/* + * APIs to document + */ + export { useThemeConfig, type ThemeConfig, @@ -19,71 +23,41 @@ export { type FooterLinkItem, type ColorModeConfig, } from './utils/useThemeConfig'; -export { - DocSidebarItemsExpandedStateProvider, - useDocSidebarItemsExpandedState, -} from './contexts/docSidebarItemsExpandedState'; -export {DocsVersionProvider, useDocsVersion} from './contexts/docsVersion'; -export {DocsSidebarProvider, useDocsSidebar} from './contexts/docsSidebar'; -export {DocProvider, useDoc} from './contexts/doc'; -export type {DocContextValue} from './contexts/doc'; export {createStorageSlot, listStorageKeys} from './utils/storageUtils'; -export {useAlternatePageUtils} from './utils/useAlternatePageUtils'; +export {useContextualSearchFilters} from './utils/searchUtils'; -export { - parseCodeBlockTitle, - parseLanguage, - parseLines, - containsLineNumbers, - getPrismCssVariables, -} from './utils/codeBlockUtils'; - -export { - docVersionSearchTag, - DEFAULT_SEARCH_TAG, - useContextualSearchFilters, -} from './utils/searchUtils'; - -export { - isDocsPluginEnabled, - useDocById, - findSidebarCategory, - findFirstCategoryLink, - useCurrentSidebarCategory, - isActiveSidebarItem, - useSidebarBreadcrumbs, - useDocsVersionCandidates, - useLayoutDoc, - useLayoutDocsSidebar, - useDocRouteMetadata, -} from './utils/docsUtils'; - -export {useTitleFormatter} from './utils/generalUtils'; +export {useCurrentSidebarCategory} from './utils/docsUtils'; export {usePluralForm} from './utils/usePluralForm'; -export {useLocationChange} from './utils/useLocationChange'; - export {useCollapsible, Collapsible} from './components/Collapsible'; +export {ThemeClassNames} from './utils/ThemeClassNames'; + export { - useDocsPreferredVersion, - useDocsPreferredVersionByPluginId, - DocsPreferredVersionContextProvider, -} from './contexts/docsPreferredVersion'; + useIsomorphicLayoutEffect, + useDynamicCallback, // TODO rename to useEvent() + usePrevious, + ReactContextError, +} from './utils/reactUtils'; -export {duplicates, uniq} from './utils/jsUtils'; +export {PageMetadata, HtmlClassNameProvider} from './utils/metadataUtils'; -export {ThemeClassNames} from './utils/ThemeClassNames'; +export {useColorMode, type ColorMode} from './contexts/colorMode'; export { - AnnouncementBarProvider, - useAnnouncementBar, -} from './contexts/announcementBar'; + NavbarSecondaryMenuFiller, + type NavbarSecondaryMenuComponent, +} from './contexts/navbarSecondaryMenu/content'; -export {useLocalPathname} from './utils/useLocalPathname'; +export {useWindowSize} from './hooks/useWindowSize'; + +/* + * APIs kept undocumented, on purpose + * Note: we still guarantee retro-compatibility on those + */ export { translateTagsPageTitle, @@ -91,75 +65,10 @@ export { type TagLetterEntry, } from './utils/tagsUtils'; -export {useHistoryPopHandler} from './utils/historyUtils'; - -export { - useTOCHighlight, - type TOCHighlightConfig, -} from './hooks/useTOCHighlight'; - -export { - useFilteredAndTreeifiedTOC, - useTreeifiedTOC, - type TOCTreeNode, -} from './utils/tocUtils'; - export {isMultiColumnFooterLinks} from './utils/footerUtils'; -export { - ScrollControllerProvider, - useScrollController, - useScrollPosition, - useScrollPositionBlocker, - useSmoothScrollTo, -} from './utils/scrollUtils'; - -export { - useIsomorphicLayoutEffect, - useDynamicCallback, - usePrevious, - ReactContextError, -} from './utils/reactUtils'; - export {isRegexpStringMatch} from './utils/regexpUtils'; -export {useHomePageRoute, isSamePath} from './utils/routesUtils'; - -export { - PageMetadata, - HtmlClassNameProvider, - PluginHtmlClassNameProvider, -} from './utils/metadataUtils'; - -export { - useColorMode, - ColorModeProvider, - type ColorMode, -} from './contexts/colorMode'; - -export {splitNavbarItems, NavbarProvider} from './utils/navbarUtils'; - -export { - useTabGroupChoice, - TabGroupChoiceProvider, -} from './contexts/tabGroupChoice'; - -export {useNavbarMobileSidebar} from './contexts/navbarMobileSidebar'; -export { - NavbarSecondaryMenuFiller, - type NavbarSecondaryMenuComponent, -} from './contexts/navbarSecondaryMenu/content'; -export {useNavbarSecondaryMenu} from './contexts/navbarSecondaryMenu/display'; +export {duplicates, uniq} from './utils/jsUtils'; -export {useBackToTopButton} from './hooks/useBackToTopButton'; -export {useHideableNavbar} from './hooks/useHideableNavbar'; -export { - useKeyboardNavigation, - keyboardFocusedClassName, -} from './hooks/useKeyboardNavigation'; export {usePrismTheme} from './hooks/usePrismTheme'; -export {useLockBodyScroll} from './hooks/useLockBodyScroll'; -export {useWindowSize} from './hooks/useWindowSize'; -export {useSearchPage} from './hooks/useSearchPage'; -export {useCodeWordWrap} from './hooks/useCodeWordWrap'; -export {useSkipToContent} from './hooks/useSkipToContent'; diff --git a/packages/docusaurus-theme-common/src/internal.ts b/packages/docusaurus-theme-common/src/internal.ts new file mode 100644 index 000000000000..fc795f847dc6 --- /dev/null +++ b/packages/docusaurus-theme-common/src/internal.ts @@ -0,0 +1,117 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// This re-export permits to handle some level of retro-compatibility. Users +// might swizzle unsafe components and expose these internal imports. When we +// move an API from internal to public, former internal imports should keep +// working, so that the change doesn't become breaking. +// +// Important: this line is removed from build output with the +// "removeThemeInternalReexport" script for CI checks. This ensures that none of +// our internal code relies on this re-export and that we don't forget to +// migrate theme internal imports to public imports. +// +// eslint-disable-next-line no-restricted-syntax +export * from './index'; + +export { + DocSidebarItemsExpandedStateProvider, + useDocSidebarItemsExpandedState, +} from './contexts/docSidebarItemsExpandedState'; +export {DocsVersionProvider, useDocsVersion} from './contexts/docsVersion'; +export {DocsSidebarProvider, useDocsSidebar} from './contexts/docsSidebar'; +export {DocProvider, useDoc, type DocContextValue} from './contexts/doc'; + +export { + useDocsPreferredVersion, + useDocsPreferredVersionByPluginId, + DocsPreferredVersionContextProvider, +} from './contexts/docsPreferredVersion'; + +export { + AnnouncementBarProvider, + useAnnouncementBar, +} from './contexts/announcementBar'; + +export { + useTabGroupChoice, + TabGroupChoiceProvider, +} from './contexts/tabGroupChoice'; + +export {useNavbarMobileSidebar} from './contexts/navbarMobileSidebar'; +export {useNavbarSecondaryMenu} from './contexts/navbarSecondaryMenu/display'; + +export {ColorModeProvider} from './contexts/colorMode'; + +export {useAlternatePageUtils} from './utils/useAlternatePageUtils'; + +export { + parseCodeBlockTitle, + parseLanguage, + parseLines, + containsLineNumbers, +} from './utils/codeBlockUtils'; + +export {docVersionSearchTag, DEFAULT_SEARCH_TAG} from './utils/searchUtils'; + +export { + isDocsPluginEnabled, + useDocById, + findSidebarCategory, + findFirstCategoryLink, + isActiveSidebarItem, + useSidebarBreadcrumbs, + useDocsVersionCandidates, + useLayoutDoc, + useLayoutDocsSidebar, + useDocRouteMetadata, +} from './utils/docsUtils'; + +export {useTitleFormatter} from './utils/generalUtils'; + +export {useLocationChange} from './utils/useLocationChange'; + +export {useLocalPathname} from './utils/useLocalPathname'; + +export {useHistoryPopHandler} from './utils/historyUtils'; + +export { + useFilteredAndTreeifiedTOC, + useTreeifiedTOC, + type TOCTreeNode, +} from './utils/tocUtils'; + +export { + ScrollControllerProvider, + useScrollController, + useScrollPosition, + useScrollPositionBlocker, + useSmoothScrollTo, +} from './utils/scrollUtils'; + +export {useHomePageRoute, isSamePath} from './utils/routesUtils'; + +export {PluginHtmlClassNameProvider} from './utils/metadataUtils'; + +export {splitNavbarItems, NavbarProvider} from './utils/navbarUtils'; + +export { + useTOCHighlight, + type TOCHighlightConfig, +} from './hooks/useTOCHighlight'; + +export {useHideableNavbar} from './hooks/useHideableNavbar'; +export { + useKeyboardNavigation, + keyboardFocusedClassName, +} from './hooks/useKeyboardNavigation'; +export {useLockBodyScroll} from './hooks/useLockBodyScroll'; +export {useSearchPage} from './hooks/useSearchPage'; +export {useCodeWordWrap} from './hooks/useCodeWordWrap'; +export {useSkipToContent} from './hooks/useSkipToContent'; +export {getPrismCssVariables} from './utils/codeBlockUtils'; +export {useBackToTopButton} from './hooks/useBackToTopButton'; diff --git a/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.tsx b/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.tsx index beef496dffcd..52b6a1cf8558 100644 --- a/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.tsx +++ b/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.tsx @@ -12,7 +12,8 @@ import {useHistory} from '@docusaurus/router'; import {useBaseUrlUtils} from '@docusaurus/useBaseUrl'; import Link from '@docusaurus/Link'; import Head from '@docusaurus/Head'; -import {isRegexpStringMatch, useSearchPage} from '@docusaurus/theme-common'; +import {isRegexpStringMatch} from '@docusaurus/theme-common'; +import {useSearchPage} from '@docusaurus/theme-common/internal'; import {DocSearchButton, useDocSearchKeyboardEvents} from '@docsearch/react'; import {useAlgoliaContextualFacetFilters} from '@docusaurus/theme-search-algolia/client'; import Translate, {translate} from '@docusaurus/Translate'; diff --git a/packages/docusaurus-theme-search-algolia/src/theme/SearchPage/index.tsx b/packages/docusaurus-theme-search-algolia/src/theme/SearchPage/index.tsx index b10d82f207b9..02ce84569963 100644 --- a/packages/docusaurus-theme-search-algolia/src/theme/SearchPage/index.tsx +++ b/packages/docusaurus-theme-search-algolia/src/theme/SearchPage/index.tsx @@ -18,12 +18,14 @@ import Link from '@docusaurus/Link'; import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment'; import { HtmlClassNameProvider, - useTitleFormatter, usePluralForm, isRegexpStringMatch, useDynamicCallback, - useSearchPage, } from '@docusaurus/theme-common'; +import { + useTitleFormatter, + useSearchPage, +} from '@docusaurus/theme-common/internal'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import {useAllDocsData} from '@docusaurus/plugin-content-docs/client'; import Translate, {translate} from '@docusaurus/Translate'; diff --git a/website/src/components/Versions.tsx b/website/src/components/Versions.tsx index 9542c88a8328..98ff4f968231 100644 --- a/website/src/components/Versions.tsx +++ b/website/src/components/Versions.tsx @@ -12,7 +12,7 @@ import React, { useRef, type ReactNode, } from 'react'; -import {useDocsPreferredVersion} from '@docusaurus/theme-common'; +import {useDocsPreferredVersion} from '@docusaurus/theme-common/internal'; import {useVersions} from '@docusaurus/plugin-content-docs/client'; import Translate from '@docusaurus/Translate'; import CodeBlock from '@theme/CodeBlock'; diff --git a/website/src/theme/DocCategoryGeneratedIndexPage/index.tsx b/website/src/theme/DocCategoryGeneratedIndexPage/index.tsx index a407d9e4a2dc..f758f09d8205 100644 --- a/website/src/theme/DocCategoryGeneratedIndexPage/index.tsx +++ b/website/src/theme/DocCategoryGeneratedIndexPage/index.tsx @@ -6,7 +6,7 @@ */ import React from 'react'; -import {useLayoutDoc} from '@docusaurus/theme-common'; +import {useLayoutDoc} from '@docusaurus/theme-common/internal'; import Link from '@docusaurus/Link'; import Translate from '@docusaurus/Translate'; import DocCategoryGeneratedIndexPage from '@theme-original/DocCategoryGeneratedIndexPage';