@docusaurus/theme-classic 0.0.0-4919 → 0.0.0-4922
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/getSwizzleConfig.js +7 -0
- package/lib/theme-classic.d.ts +31 -0
- package/lib/validateThemeConfig.js +17 -2
- package/lib-next/theme/NavbarItem/ComponentTypes.js +27 -0
- package/lib-next/theme/NavbarItem/index.js +4 -25
- package/package.json +13 -13
- package/src/getSwizzleConfig.ts +8 -0
- package/src/theme/NavbarItem/ComponentTypes.tsx +32 -0
- package/src/theme/NavbarItem/index.tsx +9 -40
- package/src/theme-classic.d.ts +31 -0
- package/src/validateThemeConfig.ts +23 -4
package/lib/getSwizzleConfig.js
CHANGED
|
@@ -200,6 +200,13 @@ function getSwizzleConfig() {
|
|
|
200
200
|
},
|
|
201
201
|
description: 'A component wrapping all MDX content and providing the MDXComponents to the MDX context'
|
|
202
202
|
},
|
|
203
|
+
'NavbarItem/ComponentTypes': {
|
|
204
|
+
actions: {
|
|
205
|
+
eject: 'safe',
|
|
206
|
+
wrap: 'forbidden'
|
|
207
|
+
},
|
|
208
|
+
description: 'The Navbar item components mapping. Can be ejected to add custom navbar item types. See https://github.com/facebook/docusaurus/issues/7227.'
|
|
209
|
+
},
|
|
203
210
|
// TODO should probably not even appear here
|
|
204
211
|
'NavbarItem/utils': {
|
|
205
212
|
actions: {
|
package/lib/theme-classic.d.ts
CHANGED
|
@@ -893,6 +893,37 @@ declare module '@theme/NavbarItem/HtmlNavbarItem' {
|
|
|
893
893
|
export default function HtmlNavbarItem(props: Props): JSX.Element;
|
|
894
894
|
}
|
|
895
895
|
|
|
896
|
+
declare module '@theme/NavbarItem/ComponentTypes' {
|
|
897
|
+
import type {ComponentType} from 'react';
|
|
898
|
+
|
|
899
|
+
import type DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
900
|
+
import type DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
|
|
901
|
+
import type LocaleDropdownNavbarItem from '@theme/NavbarItem/LocaleDropdownNavbarItem';
|
|
902
|
+
import type SearchNavbarItem from '@theme/NavbarItem/SearchNavbarItem';
|
|
903
|
+
import type HtmlNavbarItem from '@theme/NavbarItem/HtmlNavbarItem';
|
|
904
|
+
import type DocNavbarItem from '@theme/NavbarItem/DocNavbarItem';
|
|
905
|
+
import type DocSidebarNavbarItem from '@theme/NavbarItem/DocSidebarNavbarItem';
|
|
906
|
+
import type DocsVersionNavbarItem from '@theme/NavbarItem/DocsVersionNavbarItem';
|
|
907
|
+
import type DocsVersionDropdownNavbarItem from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
|
|
908
|
+
|
|
909
|
+
export type ComponentTypesObject = {
|
|
910
|
+
readonly default: typeof DefaultNavbarItem;
|
|
911
|
+
readonly localeDropdown: typeof LocaleDropdownNavbarItem;
|
|
912
|
+
readonly search: typeof SearchNavbarItem;
|
|
913
|
+
readonly dropdown: typeof DropdownNavbarItem;
|
|
914
|
+
readonly html: typeof HtmlNavbarItem;
|
|
915
|
+
readonly doc: typeof DocNavbarItem;
|
|
916
|
+
readonly docSidebar: typeof DocSidebarNavbarItem;
|
|
917
|
+
readonly docsVersion: typeof DocsVersionNavbarItem;
|
|
918
|
+
readonly docsVersionDropdown: typeof DocsVersionDropdownNavbarItem;
|
|
919
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
920
|
+
[customComponentType: string]: ComponentType<any>;
|
|
921
|
+
};
|
|
922
|
+
|
|
923
|
+
const ComponentTypes: ComponentTypesObject;
|
|
924
|
+
export default ComponentTypes;
|
|
925
|
+
}
|
|
926
|
+
|
|
896
927
|
declare module '@theme/NavbarItem' {
|
|
897
928
|
import type {ComponentProps} from 'react';
|
|
898
929
|
import type {Props as DefaultNavbarItemProps} from '@theme/NavbarItem/DefaultNavbarItem';
|
|
@@ -95,11 +95,20 @@ const HtmlNavbarItemSchema = _utilsValidation.Joi.object({
|
|
|
95
95
|
className: _utilsValidation.Joi.string(),
|
|
96
96
|
type: _utilsValidation.Joi.string().equal('html').required(),
|
|
97
97
|
value: _utilsValidation.Joi.string().required()
|
|
98
|
-
});
|
|
98
|
+
}); // A temporary workaround to allow users to add custom navbar items
|
|
99
|
+
// See https://github.com/facebook/docusaurus/issues/7227
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
const CustomNavbarItemRegexp = /custom-.*/;
|
|
103
|
+
|
|
104
|
+
const CustomNavbarItemSchema = _utilsValidation.Joi.object({
|
|
105
|
+
type: _utilsValidation.Joi.string().regex(CustomNavbarItemRegexp).required()
|
|
106
|
+
}).unknown();
|
|
99
107
|
|
|
100
108
|
const itemWithType = type => {
|
|
101
109
|
// Because equal(undefined) is not supported :/
|
|
102
|
-
const typeSchema =
|
|
110
|
+
const typeSchema = // eslint-disable-next-line no-nested-ternary
|
|
111
|
+
type instanceof RegExp ? _utilsValidation.Joi.string().required().regex(type) : type ? _utilsValidation.Joi.string().required().equal(type) : _utilsValidation.Joi.string().forbidden();
|
|
103
112
|
return _utilsValidation.Joi.object({
|
|
104
113
|
type: typeSchema
|
|
105
114
|
}).unknown().required();
|
|
@@ -123,6 +132,9 @@ const DropdownSubitemSchema = _utilsValidation.Joi.object({
|
|
|
123
132
|
}, {
|
|
124
133
|
is: itemWithType('html'),
|
|
125
134
|
then: HtmlNavbarItemSchema
|
|
135
|
+
}, {
|
|
136
|
+
is: itemWithType(CustomNavbarItemRegexp),
|
|
137
|
+
then: CustomNavbarItemSchema
|
|
126
138
|
}, {
|
|
127
139
|
is: _utilsValidation.Joi.alternatives().try(itemWithType('dropdown'), itemWithType('docsVersionDropdown'), itemWithType('localeDropdown'), itemWithType('search')),
|
|
128
140
|
then: _utilsValidation.Joi.forbidden().messages({
|
|
@@ -181,6 +193,9 @@ const NavbarItemSchema = _utilsValidation.Joi.object({
|
|
|
181
193
|
}, {
|
|
182
194
|
is: itemWithType('html'),
|
|
183
195
|
then: HtmlNavbarItemSchema
|
|
196
|
+
}, {
|
|
197
|
+
is: itemWithType(CustomNavbarItemRegexp),
|
|
198
|
+
then: CustomNavbarItemSchema
|
|
184
199
|
}, {
|
|
185
200
|
is: itemWithType(undefined),
|
|
186
201
|
then: _utilsValidation.Joi.object().when('.', {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
8
|
+
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
|
|
9
|
+
import LocaleDropdownNavbarItem from '@theme/NavbarItem/LocaleDropdownNavbarItem';
|
|
10
|
+
import SearchNavbarItem from '@theme/NavbarItem/SearchNavbarItem';
|
|
11
|
+
import HtmlNavbarItem from '@theme/NavbarItem/HtmlNavbarItem';
|
|
12
|
+
import DocNavbarItem from '@theme/NavbarItem/DocNavbarItem';
|
|
13
|
+
import DocSidebarNavbarItem from '@theme/NavbarItem/DocSidebarNavbarItem';
|
|
14
|
+
import DocsVersionNavbarItem from '@theme/NavbarItem/DocsVersionNavbarItem';
|
|
15
|
+
import DocsVersionDropdownNavbarItem from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
|
|
16
|
+
const ComponentTypes = {
|
|
17
|
+
default: DefaultNavbarItem,
|
|
18
|
+
localeDropdown: LocaleDropdownNavbarItem,
|
|
19
|
+
search: SearchNavbarItem,
|
|
20
|
+
dropdown: DropdownNavbarItem,
|
|
21
|
+
html: HtmlNavbarItem,
|
|
22
|
+
doc: DocNavbarItem,
|
|
23
|
+
docSidebar: DocSidebarNavbarItem,
|
|
24
|
+
docsVersion: DocsVersionNavbarItem,
|
|
25
|
+
docsVersionDropdown: DocsVersionDropdownNavbarItem,
|
|
26
|
+
};
|
|
27
|
+
export default ComponentTypes;
|
|
@@ -5,37 +5,16 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
|
-
import
|
|
9
|
-
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
|
|
10
|
-
import LocaleDropdownNavbarItem from '@theme/NavbarItem/LocaleDropdownNavbarItem';
|
|
11
|
-
import SearchNavbarItem from '@theme/NavbarItem/SearchNavbarItem';
|
|
12
|
-
import HtmlNavbarItem from '@theme/NavbarItem/HtmlNavbarItem';
|
|
13
|
-
const NavbarItemComponents = {
|
|
14
|
-
default: () => DefaultNavbarItem,
|
|
15
|
-
localeDropdown: () => LocaleDropdownNavbarItem,
|
|
16
|
-
search: () => SearchNavbarItem,
|
|
17
|
-
dropdown: () => DropdownNavbarItem,
|
|
18
|
-
html: () => HtmlNavbarItem,
|
|
19
|
-
// Need to lazy load these items as we don't know for sure the docs plugin is
|
|
20
|
-
// loaded. See https://github.com/facebook/docusaurus/issues/3360
|
|
21
|
-
|
|
22
|
-
/* eslint-disable @typescript-eslint/no-var-requires, global-require */
|
|
23
|
-
docsVersion: () => require('@theme/NavbarItem/DocsVersionNavbarItem').default,
|
|
24
|
-
docsVersionDropdown: () =>
|
|
25
|
-
require('@theme/NavbarItem/DocsVersionDropdownNavbarItem').default,
|
|
26
|
-
doc: () => require('@theme/NavbarItem/DocNavbarItem').default,
|
|
27
|
-
docSidebar: () => require('@theme/NavbarItem/DocSidebarNavbarItem').default,
|
|
28
|
-
/* eslint-enable @typescript-eslint/no-var-requires, global-require */
|
|
29
|
-
};
|
|
8
|
+
import ComponentTypes from '@theme/NavbarItem/ComponentTypes';
|
|
30
9
|
|
|
31
10
|
const getNavbarItemComponent = (type) => {
|
|
32
|
-
const
|
|
11
|
+
const component = ComponentTypes[type];
|
|
33
12
|
|
|
34
|
-
if (!
|
|
13
|
+
if (!component) {
|
|
35
14
|
throw new Error(`No NavbarItem component found for type "${type}".`);
|
|
36
15
|
}
|
|
37
16
|
|
|
38
|
-
return
|
|
17
|
+
return component;
|
|
39
18
|
};
|
|
40
19
|
|
|
41
20
|
function getComponentType(type, isDropdown) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-classic",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4922",
|
|
4
4
|
"description": "Classic theme for Docusaurus",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/theme-classic.d.ts",
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
"format:lib-next": "prettier --config ../../.prettierrc --write \"lib-next/**/*.{js,ts,jsx,tsc}\""
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@docusaurus/core": "0.0.0-
|
|
25
|
-
"@docusaurus/plugin-content-blog": "0.0.0-
|
|
26
|
-
"@docusaurus/plugin-content-docs": "0.0.0-
|
|
27
|
-
"@docusaurus/plugin-content-pages": "0.0.0-
|
|
28
|
-
"@docusaurus/theme-common": "0.0.0-
|
|
29
|
-
"@docusaurus/theme-translations": "0.0.0-
|
|
30
|
-
"@docusaurus/utils": "0.0.0-
|
|
31
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
32
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
24
|
+
"@docusaurus/core": "0.0.0-4922",
|
|
25
|
+
"@docusaurus/plugin-content-blog": "0.0.0-4922",
|
|
26
|
+
"@docusaurus/plugin-content-docs": "0.0.0-4922",
|
|
27
|
+
"@docusaurus/plugin-content-pages": "0.0.0-4922",
|
|
28
|
+
"@docusaurus/theme-common": "0.0.0-4922",
|
|
29
|
+
"@docusaurus/theme-translations": "0.0.0-4922",
|
|
30
|
+
"@docusaurus/utils": "0.0.0-4922",
|
|
31
|
+
"@docusaurus/utils-common": "0.0.0-4922",
|
|
32
|
+
"@docusaurus/utils-validation": "0.0.0-4922",
|
|
33
33
|
"@mdx-js/react": "^1.6.22",
|
|
34
34
|
"clsx": "^1.1.1",
|
|
35
35
|
"copy-text-to-clipboard": "^3.0.1",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"@babel/cli": "^7.17.6",
|
|
46
46
|
"@babel/core": "^7.17.9",
|
|
47
47
|
"@babel/preset-typescript": "^7.16.7",
|
|
48
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
49
|
-
"@docusaurus/types": "0.0.0-
|
|
48
|
+
"@docusaurus/module-type-aliases": "0.0.0-4922",
|
|
49
|
+
"@docusaurus/types": "0.0.0-4922",
|
|
50
50
|
"@types/mdx-js__react": "^1.5.5",
|
|
51
51
|
"@types/prismjs": "^1.26.0",
|
|
52
52
|
"@types/rtlcss": "^3.1.4",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">=14"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "b3d7e7e589a5b4b1fc29731f7c2cff6e923a992e"
|
|
66
66
|
}
|
package/src/getSwizzleConfig.ts
CHANGED
|
@@ -206,6 +206,14 @@ export default function getSwizzleConfig(): SwizzleConfig {
|
|
|
206
206
|
description:
|
|
207
207
|
'A component wrapping all MDX content and providing the MDXComponents to the MDX context',
|
|
208
208
|
},
|
|
209
|
+
'NavbarItem/ComponentTypes': {
|
|
210
|
+
actions: {
|
|
211
|
+
eject: 'safe',
|
|
212
|
+
wrap: 'forbidden',
|
|
213
|
+
},
|
|
214
|
+
description:
|
|
215
|
+
'The Navbar item components mapping. Can be ejected to add custom navbar item types. See https://github.com/facebook/docusaurus/issues/7227.',
|
|
216
|
+
},
|
|
209
217
|
// TODO should probably not even appear here
|
|
210
218
|
'NavbarItem/utils': {
|
|
211
219
|
actions: {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
9
|
+
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
|
|
10
|
+
import LocaleDropdownNavbarItem from '@theme/NavbarItem/LocaleDropdownNavbarItem';
|
|
11
|
+
import SearchNavbarItem from '@theme/NavbarItem/SearchNavbarItem';
|
|
12
|
+
import HtmlNavbarItem from '@theme/NavbarItem/HtmlNavbarItem';
|
|
13
|
+
import DocNavbarItem from '@theme/NavbarItem/DocNavbarItem';
|
|
14
|
+
import DocSidebarNavbarItem from '@theme/NavbarItem/DocSidebarNavbarItem';
|
|
15
|
+
import DocsVersionNavbarItem from '@theme/NavbarItem/DocsVersionNavbarItem';
|
|
16
|
+
import DocsVersionDropdownNavbarItem from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
|
|
17
|
+
|
|
18
|
+
import type {ComponentTypesObject} from '@theme/NavbarItem/ComponentTypes';
|
|
19
|
+
|
|
20
|
+
const ComponentTypes: ComponentTypesObject = {
|
|
21
|
+
default: DefaultNavbarItem,
|
|
22
|
+
localeDropdown: LocaleDropdownNavbarItem,
|
|
23
|
+
search: SearchNavbarItem,
|
|
24
|
+
dropdown: DropdownNavbarItem,
|
|
25
|
+
html: HtmlNavbarItem,
|
|
26
|
+
doc: DocNavbarItem,
|
|
27
|
+
docSidebar: DocSidebarNavbarItem,
|
|
28
|
+
docsVersion: DocsVersionNavbarItem,
|
|
29
|
+
docsVersionDropdown: DocsVersionDropdownNavbarItem,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default ComponentTypes;
|
|
@@ -6,57 +6,26 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import React from 'react';
|
|
9
|
-
import
|
|
10
|
-
import DropdownNavbarItem, {
|
|
11
|
-
type Props as DropdownNavbarItemProps,
|
|
12
|
-
} from '@theme/NavbarItem/DropdownNavbarItem';
|
|
13
|
-
import LocaleDropdownNavbarItem from '@theme/NavbarItem/LocaleDropdownNavbarItem';
|
|
14
|
-
import SearchNavbarItem from '@theme/NavbarItem/SearchNavbarItem';
|
|
15
|
-
import HtmlNavbarItem from '@theme/NavbarItem/HtmlNavbarItem';
|
|
9
|
+
import {type Props as DropdownNavbarItemProps} from '@theme/NavbarItem/DropdownNavbarItem';
|
|
16
10
|
import type {Types, Props} from '@theme/NavbarItem';
|
|
17
11
|
|
|
18
|
-
|
|
19
|
-
// Not really worth typing, as we pass all props down immediately
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
-
[type in Exclude<Types, undefined>]: () => (props: any) => JSX.Element;
|
|
22
|
-
} = {
|
|
23
|
-
default: () => DefaultNavbarItem,
|
|
24
|
-
localeDropdown: () => LocaleDropdownNavbarItem,
|
|
25
|
-
search: () => SearchNavbarItem,
|
|
26
|
-
dropdown: () => DropdownNavbarItem,
|
|
27
|
-
html: () => HtmlNavbarItem,
|
|
12
|
+
import ComponentTypes from '@theme/NavbarItem/ComponentTypes';
|
|
28
13
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
docsVersion: () => require('@theme/NavbarItem/DocsVersionNavbarItem').default,
|
|
33
|
-
docsVersionDropdown: () =>
|
|
34
|
-
require('@theme/NavbarItem/DocsVersionDropdownNavbarItem').default,
|
|
35
|
-
doc: () => require('@theme/NavbarItem/DocNavbarItem').default,
|
|
36
|
-
docSidebar: () => require('@theme/NavbarItem/DocSidebarNavbarItem').default,
|
|
37
|
-
/* eslint-enable @typescript-eslint/no-var-requires, global-require */
|
|
38
|
-
} as const;
|
|
39
|
-
|
|
40
|
-
type NavbarItemComponentType = keyof typeof NavbarItemComponents;
|
|
41
|
-
|
|
42
|
-
const getNavbarItemComponent = (type: NavbarItemComponentType) => {
|
|
43
|
-
const navbarItemComponentFn = NavbarItemComponents[type];
|
|
44
|
-
if (!navbarItemComponentFn) {
|
|
14
|
+
const getNavbarItemComponent = (type: NonNullable<Types>) => {
|
|
15
|
+
const component = ComponentTypes[type];
|
|
16
|
+
if (!component) {
|
|
45
17
|
throw new Error(`No NavbarItem component found for type "${type}".`);
|
|
46
18
|
}
|
|
47
|
-
return
|
|
19
|
+
return component;
|
|
48
20
|
};
|
|
49
21
|
|
|
50
|
-
function getComponentType(
|
|
51
|
-
type: Types,
|
|
52
|
-
isDropdown: boolean,
|
|
53
|
-
): NavbarItemComponentType {
|
|
22
|
+
function getComponentType(type: Types, isDropdown: boolean) {
|
|
54
23
|
// Backward compatibility: navbar item with no type set
|
|
55
24
|
// but containing dropdown items should use the type "dropdown"
|
|
56
25
|
if (!type || type === 'default') {
|
|
57
26
|
return isDropdown ? 'dropdown' : 'default';
|
|
58
27
|
}
|
|
59
|
-
return type as
|
|
28
|
+
return type as NonNullable<Types>;
|
|
60
29
|
}
|
|
61
30
|
|
|
62
31
|
export default function NavbarItem({type, ...props}: Props): JSX.Element {
|
|
@@ -65,5 +34,5 @@ export default function NavbarItem({type, ...props}: Props): JSX.Element {
|
|
|
65
34
|
(props as DropdownNavbarItemProps).items !== undefined,
|
|
66
35
|
);
|
|
67
36
|
const NavbarItemComponent = getNavbarItemComponent(componentType);
|
|
68
|
-
return <NavbarItemComponent {...props} />;
|
|
37
|
+
return <NavbarItemComponent {...(props as never)} />;
|
|
69
38
|
}
|
package/src/theme-classic.d.ts
CHANGED
|
@@ -893,6 +893,37 @@ declare module '@theme/NavbarItem/HtmlNavbarItem' {
|
|
|
893
893
|
export default function HtmlNavbarItem(props: Props): JSX.Element;
|
|
894
894
|
}
|
|
895
895
|
|
|
896
|
+
declare module '@theme/NavbarItem/ComponentTypes' {
|
|
897
|
+
import type {ComponentType} from 'react';
|
|
898
|
+
|
|
899
|
+
import type DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
900
|
+
import type DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
|
|
901
|
+
import type LocaleDropdownNavbarItem from '@theme/NavbarItem/LocaleDropdownNavbarItem';
|
|
902
|
+
import type SearchNavbarItem from '@theme/NavbarItem/SearchNavbarItem';
|
|
903
|
+
import type HtmlNavbarItem from '@theme/NavbarItem/HtmlNavbarItem';
|
|
904
|
+
import type DocNavbarItem from '@theme/NavbarItem/DocNavbarItem';
|
|
905
|
+
import type DocSidebarNavbarItem from '@theme/NavbarItem/DocSidebarNavbarItem';
|
|
906
|
+
import type DocsVersionNavbarItem from '@theme/NavbarItem/DocsVersionNavbarItem';
|
|
907
|
+
import type DocsVersionDropdownNavbarItem from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
|
|
908
|
+
|
|
909
|
+
export type ComponentTypesObject = {
|
|
910
|
+
readonly default: typeof DefaultNavbarItem;
|
|
911
|
+
readonly localeDropdown: typeof LocaleDropdownNavbarItem;
|
|
912
|
+
readonly search: typeof SearchNavbarItem;
|
|
913
|
+
readonly dropdown: typeof DropdownNavbarItem;
|
|
914
|
+
readonly html: typeof HtmlNavbarItem;
|
|
915
|
+
readonly doc: typeof DocNavbarItem;
|
|
916
|
+
readonly docSidebar: typeof DocSidebarNavbarItem;
|
|
917
|
+
readonly docsVersion: typeof DocsVersionNavbarItem;
|
|
918
|
+
readonly docsVersionDropdown: typeof DocsVersionDropdownNavbarItem;
|
|
919
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
920
|
+
[customComponentType: string]: ComponentType<any>;
|
|
921
|
+
};
|
|
922
|
+
|
|
923
|
+
const ComponentTypes: ComponentTypesObject;
|
|
924
|
+
export default ComponentTypes;
|
|
925
|
+
}
|
|
926
|
+
|
|
896
927
|
declare module '@theme/NavbarItem' {
|
|
897
928
|
import type {ComponentProps} from 'react';
|
|
898
929
|
import type {Props as DefaultNavbarItemProps} from '@theme/NavbarItem/DefaultNavbarItem';
|
|
@@ -99,11 +99,22 @@ const HtmlNavbarItemSchema = Joi.object({
|
|
|
99
99
|
value: Joi.string().required(),
|
|
100
100
|
});
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
// A temporary workaround to allow users to add custom navbar items
|
|
103
|
+
// See https://github.com/facebook/docusaurus/issues/7227
|
|
104
|
+
const CustomNavbarItemRegexp = /custom-.*/;
|
|
105
|
+
const CustomNavbarItemSchema = Joi.object({
|
|
106
|
+
type: Joi.string().regex(CustomNavbarItemRegexp).required(),
|
|
107
|
+
}).unknown();
|
|
108
|
+
|
|
109
|
+
const itemWithType = (type: string | RegExp | undefined) => {
|
|
103
110
|
// Because equal(undefined) is not supported :/
|
|
104
|
-
const typeSchema =
|
|
105
|
-
|
|
106
|
-
|
|
111
|
+
const typeSchema =
|
|
112
|
+
// eslint-disable-next-line no-nested-ternary
|
|
113
|
+
type instanceof RegExp
|
|
114
|
+
? Joi.string().required().regex(type)
|
|
115
|
+
: type
|
|
116
|
+
? Joi.string().required().equal(type)
|
|
117
|
+
: Joi.string().forbidden();
|
|
107
118
|
return Joi.object({
|
|
108
119
|
type: typeSchema,
|
|
109
120
|
})
|
|
@@ -135,6 +146,10 @@ const DropdownSubitemSchema = Joi.object({
|
|
|
135
146
|
is: itemWithType('html'),
|
|
136
147
|
then: HtmlNavbarItemSchema,
|
|
137
148
|
},
|
|
149
|
+
{
|
|
150
|
+
is: itemWithType(CustomNavbarItemRegexp),
|
|
151
|
+
then: CustomNavbarItemSchema,
|
|
152
|
+
},
|
|
138
153
|
{
|
|
139
154
|
is: Joi.alternatives().try(
|
|
140
155
|
itemWithType('dropdown'),
|
|
@@ -210,6 +225,10 @@ const NavbarItemSchema = Joi.object({
|
|
|
210
225
|
is: itemWithType('html'),
|
|
211
226
|
then: HtmlNavbarItemSchema,
|
|
212
227
|
},
|
|
228
|
+
{
|
|
229
|
+
is: itemWithType(CustomNavbarItemRegexp),
|
|
230
|
+
then: CustomNavbarItemSchema,
|
|
231
|
+
},
|
|
213
232
|
{
|
|
214
233
|
is: itemWithType(undefined),
|
|
215
234
|
then: Joi.object().when('.', {
|