@docusaurus/theme-classic 0.0.0-5047 → 0.0.0-5048

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,9 @@ export default function MDXDetails(props) {
10
10
  const items = React.Children.toArray(props.children);
11
11
  // Split summary item from the rest to pass it as a separate prop to the
12
12
  // Details theme component
13
- const summary = items.find((item) => item?.props?.mdxType === 'summary');
13
+ const summary = items.find(
14
+ (item) => React.isValidElement(item) && item.props?.mdxType === 'summary',
15
+ );
14
16
  const children = <>{items.filter((item) => item !== summary)}</>;
15
17
  return (
16
18
  <Details {...props} summary={summary}>
@@ -9,7 +9,7 @@ import Head from '@docusaurus/Head';
9
9
  // MDX elements are wrapped through the MDX pragma. In some cases (notably usage
10
10
  // with Head/Helmet) we need to unwrap those elements.
11
11
  function unwrapMDXElement(element) {
12
- if (element?.props?.mdxType && element?.props?.originalType) {
12
+ if (element.props?.mdxType && element.props.originalType) {
13
13
  const {mdxType, originalType, ...newProps} = element.props;
14
14
  return React.createElement(element.props.originalType, newProps);
15
15
  }
@@ -17,7 +17,7 @@ function unwrapMDXElement(element) {
17
17
  }
18
18
  export default function MDXHead(props) {
19
19
  const unwrappedChildren = React.Children.map(props.children, (child) =>
20
- unwrapMDXElement(child),
20
+ React.isValidElement(child) ? unwrapMDXElement(child) : child,
21
21
  );
22
22
  return <Head {...props}>{unwrappedChildren}</Head>;
23
23
  }
@@ -11,8 +11,8 @@ export default function MDXPre(props) {
11
11
  <CodeBlock
12
12
  // If this pre is created by a ``` fenced codeblock, unwrap the children
13
13
  {...(isValidElement(props.children) &&
14
- props.children.props.originalType === 'code'
15
- ? props.children?.props
14
+ props.children.props?.originalType === 'code'
15
+ ? props.children.props
16
16
  : {...props})}
17
17
  />
18
18
  );
@@ -33,13 +33,13 @@ export default function DocsVersionDropdownNavbarItem({
33
33
  // We try to link to the same doc, in another version
34
34
  // When not possible, fallback to the "main doc" of the version
35
35
  const versionDoc =
36
- activeDocContext?.alternateDocVersions[version.name] ??
36
+ activeDocContext.alternateDocVersions[version.name] ??
37
37
  getVersionMainDoc(version);
38
38
  return {
39
39
  isNavLink: true,
40
40
  label: version.label,
41
41
  to: versionDoc.path,
42
- isActive: () => version === activeDocContext?.activeVersion,
42
+ isActive: () => version === activeDocContext.activeVersion,
43
43
  onClick: () => savePreferredVersionName(version.name),
44
44
  };
45
45
  });
@@ -6,23 +6,19 @@
6
6
  */
7
7
  import React from 'react';
8
8
  import ComponentTypes from '@theme/NavbarItem/ComponentTypes';
9
- const getNavbarItemComponent = (type) => {
10
- const component = ComponentTypes[type];
11
- if (!component) {
12
- throw new Error(`No NavbarItem component found for type "${type}".`);
13
- }
14
- return component;
15
- };
16
- function getComponentType(type, isDropdown) {
9
+ function normalizeComponentType(type, props) {
17
10
  // Backward compatibility: navbar item with no type set
18
11
  // but containing dropdown items should use the type "dropdown"
19
12
  if (!type || type === 'default') {
20
- return isDropdown ? 'dropdown' : 'default';
13
+ return 'items' in props ? 'dropdown' : 'default';
21
14
  }
22
15
  return type;
23
16
  }
24
17
  export default function NavbarItem({type, ...props}) {
25
- const componentType = getComponentType(type, props.items !== undefined);
26
- const NavbarItemComponent = getNavbarItemComponent(componentType);
18
+ const componentType = normalizeComponentType(type, props);
19
+ const NavbarItemComponent = ComponentTypes[componentType];
20
+ if (!NavbarItemComponent) {
21
+ throw new Error(`No NavbarItem component found for type "${type}".`);
22
+ }
27
23
  return <NavbarItemComponent {...props} />;
28
24
  }
@@ -62,7 +62,7 @@ function TabsComponent(props) {
62
62
  ? defaultValueProp
63
63
  : defaultValueProp ??
64
64
  children.find((child) => child.props.default)?.props.value ??
65
- children[0]?.props.value;
65
+ children[0].props.value;
66
66
  if (defaultValue !== null && !values.some((a) => a.value === defaultValue)) {
67
67
  throw new Error(
68
68
  `Docusaurus error: The <Tabs> has a defaultValue "${defaultValue}" but none of its children has the corresponding value. Available values are: ${values
@@ -104,12 +104,12 @@ function TabsComponent(props) {
104
104
  switch (event.key) {
105
105
  case 'ArrowRight': {
106
106
  const nextTab = tabRefs.indexOf(event.currentTarget) + 1;
107
- focusElement = tabRefs[nextTab] || tabRefs[0];
107
+ focusElement = tabRefs[nextTab] ?? tabRefs[0];
108
108
  break;
109
109
  }
110
110
  case 'ArrowLeft': {
111
111
  const prevTab = tabRefs.indexOf(event.currentTarget) - 1;
112
- focusElement = tabRefs[prevTab] || tabRefs[tabRefs.length - 1];
112
+ focusElement = tabRefs[prevTab] ?? tabRefs[tabRefs.length - 1];
113
113
  break;
114
114
  }
115
115
  default:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-classic",
3
- "version": "0.0.0-5047",
3
+ "version": "0.0.0-5048",
4
4
  "description": "Classic theme for Docusaurus",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/theme-classic.d.ts",
@@ -20,15 +20,15 @@
20
20
  "copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
21
21
  },
22
22
  "dependencies": {
23
- "@docusaurus/core": "0.0.0-5047",
24
- "@docusaurus/plugin-content-blog": "0.0.0-5047",
25
- "@docusaurus/plugin-content-docs": "0.0.0-5047",
26
- "@docusaurus/plugin-content-pages": "0.0.0-5047",
27
- "@docusaurus/theme-common": "0.0.0-5047",
28
- "@docusaurus/theme-translations": "0.0.0-5047",
29
- "@docusaurus/utils": "0.0.0-5047",
30
- "@docusaurus/utils-common": "0.0.0-5047",
31
- "@docusaurus/utils-validation": "0.0.0-5047",
23
+ "@docusaurus/core": "0.0.0-5048",
24
+ "@docusaurus/plugin-content-blog": "0.0.0-5048",
25
+ "@docusaurus/plugin-content-docs": "0.0.0-5048",
26
+ "@docusaurus/plugin-content-pages": "0.0.0-5048",
27
+ "@docusaurus/theme-common": "0.0.0-5048",
28
+ "@docusaurus/theme-translations": "0.0.0-5048",
29
+ "@docusaurus/utils": "0.0.0-5048",
30
+ "@docusaurus/utils-common": "0.0.0-5048",
31
+ "@docusaurus/utils-validation": "0.0.0-5048",
32
32
  "@mdx-js/react": "^1.6.22",
33
33
  "clsx": "^1.1.1",
34
34
  "copy-text-to-clipboard": "^3.0.1",
@@ -43,8 +43,8 @@
43
43
  "tslib": "^2.4.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@docusaurus/module-type-aliases": "0.0.0-5047",
47
- "@docusaurus/types": "0.0.0-5047",
46
+ "@docusaurus/module-type-aliases": "0.0.0-5048",
47
+ "@docusaurus/types": "0.0.0-5048",
48
48
  "@types/mdx-js__react": "^1.5.5",
49
49
  "@types/nprogress": "^0.2.0",
50
50
  "@types/prismjs": "^1.26.0",
@@ -60,5 +60,5 @@
60
60
  "engines": {
61
61
  "node": ">=14"
62
62
  },
63
- "gitHead": "67ac297469d98ac3eb8482d8636aee4648586f33"
63
+ "gitHead": "f5680d2f2633fbd6594972ae1f4c1ddb1467f9ac"
64
64
  }
package/src/index.ts CHANGED
@@ -19,8 +19,9 @@ import type webpack from 'webpack';
19
19
  const requireFromDocusaurusCore = createRequire(
20
20
  require.resolve('@docusaurus/core/package.json'),
21
21
  );
22
- const ContextReplacementPlugin: typeof webpack.ContextReplacementPlugin =
23
- requireFromDocusaurusCore('webpack/lib/ContextReplacementPlugin');
22
+ const ContextReplacementPlugin = requireFromDocusaurusCore(
23
+ 'webpack/lib/ContextReplacementPlugin',
24
+ ) as typeof webpack.ContextReplacementPlugin;
24
25
 
25
26
  // Need to be inlined to prevent dark mode FOUC
26
27
  // Make sure the key is the same as the one in `/theme/hooks/useTheme.js`
@@ -10,11 +10,13 @@ import Details from '@theme/Details';
10
10
  import type {Props} from '@theme/MDXComponents/Details';
11
11
 
12
12
  export default function MDXDetails(props: Props): JSX.Element {
13
- const items = React.Children.toArray(props.children) as ReactElement[];
13
+ const items = React.Children.toArray(props.children);
14
14
  // Split summary item from the rest to pass it as a separate prop to the
15
15
  // Details theme component
16
- const summary: ReactElement<ComponentProps<'summary'>> | undefined =
17
- items.find((item) => item?.props?.mdxType === 'summary');
16
+ const summary = items.find(
17
+ (item): item is ReactElement<ComponentProps<'summary'>> =>
18
+ React.isValidElement(item) && item.props?.mdxType === 'summary',
19
+ );
18
20
  const children = <>{items.filter((item) => item !== summary)}</>;
19
21
 
20
22
  return (
@@ -11,8 +11,10 @@ import type {Props} from '@theme/MDXComponents/Head';
11
11
 
12
12
  // MDX elements are wrapped through the MDX pragma. In some cases (notably usage
13
13
  // with Head/Helmet) we need to unwrap those elements.
14
- function unwrapMDXElement(element: ReactElement) {
15
- if (element?.props?.mdxType && element?.props?.originalType) {
14
+ function unwrapMDXElement(
15
+ element: ReactElement<{mdxType?: string; originalType?: string} | undefined>,
16
+ ) {
17
+ if (element.props?.mdxType && element.props.originalType) {
16
18
  const {mdxType, originalType, ...newProps} = element.props;
17
19
  return React.createElement(element.props.originalType, newProps);
18
20
  }
@@ -21,7 +23,7 @@ function unwrapMDXElement(element: ReactElement) {
21
23
 
22
24
  export default function MDXHead(props: Props): JSX.Element {
23
25
  const unwrappedChildren = React.Children.map(props.children, (child) =>
24
- unwrapMDXElement(child as ReactElement),
26
+ React.isValidElement(child) ? unwrapMDXElement(child) : child,
25
27
  );
26
28
  return (
27
29
  <Head {...(props as ComponentProps<typeof Head>)}>{unwrappedChildren}</Head>
@@ -14,8 +14,8 @@ export default function MDXPre(props: Props): JSX.Element {
14
14
  <CodeBlock
15
15
  // If this pre is created by a ``` fenced codeblock, unwrap the children
16
16
  {...(isValidElement(props.children) &&
17
- props.children.props.originalType === 'code'
18
- ? props.children?.props
17
+ props.children.props?.originalType === 'code'
18
+ ? props.children.props
19
19
  : {...props})}
20
20
  />
21
21
  );
@@ -11,13 +11,12 @@ import {
11
11
  useNavbarMobileSidebar,
12
12
  useThemeConfig,
13
13
  } from '@docusaurus/theme-common';
14
- import NavbarItem from '@theme/NavbarItem';
14
+ import NavbarItem, {type Props as NavbarItemConfig} from '@theme/NavbarItem';
15
15
  import NavbarColorModeToggle from '@theme/Navbar/ColorModeToggle';
16
16
  import SearchBar from '@theme/SearchBar';
17
17
  import NavbarMobileSidebarToggle from '@theme/Navbar/MobileSidebar/Toggle';
18
18
  import NavbarLogo from '@theme/Navbar/Logo';
19
19
  import NavbarSearch from '@theme/Navbar/Search';
20
- import type {Props as NavbarItemConfig} from '@theme/NavbarItem';
21
20
 
22
21
  import styles from './styles.module.css';
23
22
 
@@ -7,8 +7,7 @@
7
7
 
8
8
  import React from 'react';
9
9
  import {useNavbarMobileSidebar, useThemeConfig} from '@docusaurus/theme-common';
10
- import NavbarItem from '@theme/NavbarItem';
11
- import type {Props as NavbarItemConfig} from '@theme/NavbarItem';
10
+ import NavbarItem, {type Props as NavbarItemConfig} from '@theme/NavbarItem';
12
11
 
13
12
  function useNavbarItems() {
14
13
  // TODO temporary casting until ThemeConfig type is improved
@@ -38,13 +38,13 @@ export default function DocsVersionDropdownNavbarItem({
38
38
  // We try to link to the same doc, in another version
39
39
  // When not possible, fallback to the "main doc" of the version
40
40
  const versionDoc =
41
- activeDocContext?.alternateDocVersions[version.name] ??
41
+ activeDocContext.alternateDocVersions[version.name] ??
42
42
  getVersionMainDoc(version);
43
43
  return {
44
44
  isNavLink: true,
45
45
  label: version.label,
46
46
  to: versionDoc.path,
47
- isActive: () => version === activeDocContext?.activeVersion,
47
+ isActive: () => version === activeDocContext.activeVersion,
48
48
  onClick: () => savePreferredVersionName(version.name),
49
49
  };
50
50
  });
@@ -15,12 +15,11 @@ import {
15
15
  useLocalPathname,
16
16
  } from '@docusaurus/theme-common';
17
17
  import NavbarNavLink from '@theme/NavbarItem/NavbarNavLink';
18
- import NavbarItem from '@theme/NavbarItem';
18
+ import NavbarItem, {type LinkLikeNavbarItemProps} from '@theme/NavbarItem';
19
19
  import type {
20
20
  DesktopOrMobileNavBarItemProps,
21
21
  Props,
22
22
  } from '@theme/NavbarItem/DropdownNavbarItem';
23
- import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem';
24
23
 
25
24
  const dropdownLinkActiveClass = 'dropdown__link--active';
26
25
 
@@ -7,31 +7,22 @@
7
7
 
8
8
  import React from 'react';
9
9
  import ComponentTypes from '@theme/NavbarItem/ComponentTypes';
10
- import {type Props as DropdownNavbarItemProps} from '@theme/NavbarItem/DropdownNavbarItem';
11
- import type {Types, Props} from '@theme/NavbarItem';
10
+ import type {NavbarItemType, Props} from '@theme/NavbarItem';
12
11
 
13
- const getNavbarItemComponent = (type: NonNullable<Types>) => {
14
- const component = ComponentTypes[type];
15
- if (!component) {
16
- throw new Error(`No NavbarItem component found for type "${type}".`);
17
- }
18
- return component;
19
- };
20
-
21
- function getComponentType(type: Types, isDropdown: boolean) {
12
+ function normalizeComponentType(type: NavbarItemType, props: object) {
22
13
  // Backward compatibility: navbar item with no type set
23
14
  // but containing dropdown items should use the type "dropdown"
24
15
  if (!type || type === 'default') {
25
- return isDropdown ? 'dropdown' : 'default';
16
+ return 'items' in props ? 'dropdown' : 'default';
26
17
  }
27
- return type as NonNullable<Types>;
18
+ return type;
28
19
  }
29
20
 
30
21
  export default function NavbarItem({type, ...props}: Props): JSX.Element {
31
- const componentType = getComponentType(
32
- type,
33
- (props as DropdownNavbarItemProps).items !== undefined,
34
- );
35
- const NavbarItemComponent = getNavbarItemComponent(componentType);
22
+ const componentType = normalizeComponentType(type, props);
23
+ const NavbarItemComponent = ComponentTypes[componentType];
24
+ if (!NavbarItemComponent) {
25
+ throw new Error(`No NavbarItem component found for type "${type}".`);
26
+ }
36
27
  return <NavbarItemComponent {...(props as never)} />;
37
28
  }
@@ -75,7 +75,7 @@ function TabsComponent(props: Props): JSX.Element {
75
75
  ? defaultValueProp
76
76
  : defaultValueProp ??
77
77
  children.find((child) => child.props.default)?.props.value ??
78
- children[0]?.props.value;
78
+ children[0]!.props.value;
79
79
  if (defaultValue !== null && !values.some((a) => a.value === defaultValue)) {
80
80
  throw new Error(
81
81
  `Docusaurus error: The <Tabs> has a defaultValue "${defaultValue}" but none of its children has the corresponding value. Available values are: ${values
@@ -126,12 +126,12 @@ function TabsComponent(props: Props): JSX.Element {
126
126
  switch (event.key) {
127
127
  case 'ArrowRight': {
128
128
  const nextTab = tabRefs.indexOf(event.currentTarget) + 1;
129
- focusElement = tabRefs[nextTab] || tabRefs[0]!;
129
+ focusElement = tabRefs[nextTab] ?? tabRefs[0]!;
130
130
  break;
131
131
  }
132
132
  case 'ArrowLeft': {
133
133
  const prevTab = tabRefs.indexOf(event.currentTarget) - 1;
134
- focusElement = tabRefs[prevTab] || tabRefs[tabRefs.length - 1]!;
134
+ focusElement = tabRefs[prevTab] ?? tabRefs[tabRefs.length - 1]!;
135
135
  break;
136
136
  }
137
137
  default:
@@ -816,7 +816,6 @@ declare module '@theme/NavbarItem/NavbarNavLink' {
816
816
 
817
817
  declare module '@theme/NavbarItem/DropdownNavbarItem' {
818
818
  import type {Props as NavbarNavLinkProps} from '@theme/NavbarItem/NavbarNavLink';
819
-
820
819
  import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem';
821
820
 
822
821
  export type DesktopOrMobileNavBarItemProps = NavbarNavLinkProps & {
@@ -976,7 +975,7 @@ declare module '@theme/NavbarItem' {
976
975
  } & SearchNavbarItemProps)
977
976
  );
978
977
 
979
- export type Types = Props['type'];
978
+ export type NavbarItemType = Props['type'];
980
979
 
981
980
  export default function NavbarItem(props: Props): JSX.Element;
982
981
  }