@docusaurus/theme-classic 0.0.0-5044 → 0.0.0-5049

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.
package/lib/index.js CHANGED
@@ -131,7 +131,7 @@ function themeClassic(context, options) {
131
131
  const plugin = {
132
132
  postcssPlugin: 'RtlCssPlugin',
133
133
  prepare: (result) => {
134
- const file = result.root?.source?.input?.file;
134
+ const file = result.root.source?.input.file;
135
135
  // Skip Infima as we are using the its RTL version.
136
136
  if (file === resolvedInfimaFile) {
137
137
  return {};
@@ -46,7 +46,7 @@ export default function CodeBlockString({
46
46
  magicComments,
47
47
  });
48
48
  const showLineNumbers =
49
- showLineNumbersProp || containsLineNumbers(metastring);
49
+ showLineNumbersProp ?? containsLineNumbers(metastring);
50
50
  return (
51
51
  <Container
52
52
  as="div"
@@ -15,7 +15,7 @@ export default function DocSidebarItemHtml({item, level, index}) {
15
15
  className={clsx(
16
16
  ThemeClassNames.docs.docSidebarItemLink,
17
17
  ThemeClassNames.docs.docSidebarItemLinkLevel(level),
18
- defaultStyle && `${styles.menuHtmlItem} menu__list-item`,
18
+ defaultStyle && [styles.menuHtmlItem, 'menu__list-item'],
19
19
  className,
20
20
  )}
21
21
  key={index}
@@ -15,7 +15,7 @@ function ColumnLinkItem({item}) {
15
15
  dangerouslySetInnerHTML={{__html: item.html}}
16
16
  />
17
17
  ) : (
18
- <li key={item.href || item.to} className="footer__item">
18
+ <li key={item.href ?? item.to} className="footer__item">
19
19
  <LinkItem item={item} />
20
20
  </li>
21
21
  );
@@ -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
@@ -95,7 +95,7 @@ function TabsComponent(props) {
95
95
  blockElementScrollPositionUntilNextRender(newTab);
96
96
  setSelectedValue(newTabValue);
97
97
  if (groupId != null) {
98
- setTabGroupChoices(groupId, newTabValue);
98
+ setTabGroupChoices(groupId, String(newTabValue));
99
99
  }
100
100
  }
101
101
  };
@@ -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-5044",
3
+ "version": "0.0.0-5049",
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-5044",
24
- "@docusaurus/plugin-content-blog": "0.0.0-5044",
25
- "@docusaurus/plugin-content-docs": "0.0.0-5044",
26
- "@docusaurus/plugin-content-pages": "0.0.0-5044",
27
- "@docusaurus/theme-common": "0.0.0-5044",
28
- "@docusaurus/theme-translations": "0.0.0-5044",
29
- "@docusaurus/utils": "0.0.0-5044",
30
- "@docusaurus/utils-common": "0.0.0-5044",
31
- "@docusaurus/utils-validation": "0.0.0-5044",
23
+ "@docusaurus/core": "0.0.0-5049",
24
+ "@docusaurus/plugin-content-blog": "0.0.0-5049",
25
+ "@docusaurus/plugin-content-docs": "0.0.0-5049",
26
+ "@docusaurus/plugin-content-pages": "0.0.0-5049",
27
+ "@docusaurus/theme-common": "0.0.0-5049",
28
+ "@docusaurus/theme-translations": "0.0.0-5049",
29
+ "@docusaurus/utils": "0.0.0-5049",
30
+ "@docusaurus/utils-common": "0.0.0-5049",
31
+ "@docusaurus/utils-validation": "0.0.0-5049",
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-5044",
47
- "@docusaurus/types": "0.0.0-5044",
46
+ "@docusaurus/module-type-aliases": "0.0.0-5049",
47
+ "@docusaurus/types": "0.0.0-5049",
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": "9ffd6ca265dc2af7ed5b96daf5ebf32708e899cf"
63
+ "gitHead": "527b2a01c46b67483327a1a6873fccf81bc19e2c"
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`
@@ -177,7 +178,7 @@ export default function themeClassic(
177
178
  const plugin: PostCssPlugin = {
178
179
  postcssPlugin: 'RtlCssPlugin',
179
180
  prepare: (result) => {
180
- const file = result.root?.source?.input?.file;
181
+ const file = result.root.source?.input.file;
181
182
  // Skip Infima as we are using the its RTL version.
182
183
  if (file === resolvedInfimaFile) {
183
184
  return {};
@@ -52,7 +52,7 @@ export default function CodeBlockString({
52
52
  magicComments,
53
53
  });
54
54
  const showLineNumbers =
55
- showLineNumbersProp || containsLineNumbers(metastring);
55
+ showLineNumbersProp ?? containsLineNumbers(metastring);
56
56
 
57
57
  return (
58
58
  <Container
@@ -23,7 +23,7 @@ export default function DocSidebarItemHtml({
23
23
  className={clsx(
24
24
  ThemeClassNames.docs.docSidebarItemLink,
25
25
  ThemeClassNames.docs.docSidebarItemLinkLevel(level),
26
- defaultStyle && `${styles.menuHtmlItem} menu__list-item`,
26
+ defaultStyle && [styles.menuHtmlItem, 'menu__list-item'],
27
27
  className,
28
28
  )}
29
29
  key={index}
@@ -21,7 +21,7 @@ function ColumnLinkItem({item}: {item: ColumnItemType}) {
21
21
  dangerouslySetInnerHTML={{__html: item.html}}
22
22
  />
23
23
  ) : (
24
- <li key={item.href || item.to} className="footer__item">
24
+ <li key={item.href ?? item.to} className="footer__item">
25
25
  <LinkItem item={item} />
26
26
  </li>
27
27
  );
@@ -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
@@ -115,7 +115,7 @@ function TabsComponent(props: Props): JSX.Element {
115
115
  setSelectedValue(newTabValue);
116
116
 
117
117
  if (groupId != null) {
118
- setTabGroupChoices(groupId, newTabValue);
118
+ setTabGroupChoices(groupId, String(newTabValue));
119
119
  }
120
120
  }
121
121
  };
@@ -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:
@@ -21,12 +21,14 @@
21
21
  // in their tsconfig.
22
22
 
23
23
  declare module '@docusaurus/theme-classic' {
24
- import type {LoadContext, Plugin} from '@docusaurus/types';
24
+ import type {LoadContext, Plugin, PluginModule} from '@docusaurus/types';
25
25
 
26
26
  export type Options = {
27
27
  customCss?: string | string[];
28
28
  };
29
29
 
30
+ export const getSwizzleConfig: PluginModule['getSwizzleConfig'];
31
+
30
32
  export default function themeClassic(
31
33
  context: LoadContext,
32
34
  options: Options,
@@ -814,7 +816,6 @@ declare module '@theme/NavbarItem/NavbarNavLink' {
814
816
 
815
817
  declare module '@theme/NavbarItem/DropdownNavbarItem' {
816
818
  import type {Props as NavbarNavLinkProps} from '@theme/NavbarItem/NavbarNavLink';
817
-
818
819
  import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem';
819
820
 
820
821
  export type DesktopOrMobileNavBarItemProps = NavbarNavLinkProps & {
@@ -974,7 +975,7 @@ declare module '@theme/NavbarItem' {
974
975
  } & SearchNavbarItemProps)
975
976
  );
976
977
 
977
- export type Types = Props['type'];
978
+ export type NavbarItemType = Props['type'];
978
979
 
979
980
  export default function NavbarItem(props: Props): JSX.Element;
980
981
  }
@@ -1031,10 +1032,10 @@ declare module '@theme/Tabs' {
1031
1032
  readonly lazy?: boolean;
1032
1033
  readonly block?: boolean;
1033
1034
  readonly children: readonly ReactElement<TabItemProps>[];
1034
- readonly defaultValue?: string | null;
1035
+ readonly defaultValue?: string | number | null;
1035
1036
  readonly values?: readonly {
1036
- value: string;
1037
- label?: string;
1037
+ value: string | number;
1038
+ label?: string | number;
1038
1039
  attributes?: {[key: string]: unknown};
1039
1040
  }[];
1040
1041
  readonly groupId?: string;