@rspress/core 0.0.10 → 0.0.11
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/dist/index.js +77 -59
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +0 -1
- package/dist/loader.js.map +1 -1
- package/dist/theme/bundle.js +378 -305
- package/dist/theme/bundle.js.map +1 -1
- package/package.json +8 -9
- package/src/theme-default/components/Nav/NavMenuGroup.tsx +43 -23
- package/src/theme-default/components/Nav/NavMenuSingleItem.tsx +12 -4
- package/src/theme-default/components/Nav/index.tsx +1 -0
- package/src/theme-default/components/NavScreenMenuGroup/NavScreenMenuGroup.tsx +18 -7
- package/src/theme-default/components/Sidebar/SidebarItem.tsx +1 -0
- package/src/theme-default/layout/Layout/index.tsx +19 -6
- package/src/theme-default/logic/useLocaleSiteData.ts +1 -1
- package/src/theme-default/logic/useSidebarData.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "The Rspress Documentation Framework",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@mdx-js/react": "2.2.1",
|
|
44
44
|
"@modern-js/builder": "2.34.0",
|
|
45
45
|
"@modern-js/builder-rspack-provider": "2.34.0",
|
|
46
|
-
"@modern-js/mdx-rs-binding": "0.2.
|
|
46
|
+
"@modern-js/mdx-rs-binding": "0.2.6",
|
|
47
47
|
"@modern-js/utils": "2.34.0",
|
|
48
48
|
"@types/compression": "^1.7.2",
|
|
49
49
|
"@types/polka": "^0.5.4",
|
|
@@ -57,7 +57,6 @@
|
|
|
57
57
|
"fs-extra": "10.1.0",
|
|
58
58
|
"github-slugger": "^2.0.0",
|
|
59
59
|
"globby": "11.1.0",
|
|
60
|
-
"hast": "^1.0.0",
|
|
61
60
|
"hast-util-from-html": "^1.0.0",
|
|
62
61
|
"html-to-text": "^9.0.3",
|
|
63
62
|
"jsdom": "20.0.3",
|
|
@@ -91,12 +90,12 @@
|
|
|
91
90
|
"unist-util-visit": "^4.1.1",
|
|
92
91
|
"unist-util-visit-children": "^2.0.1",
|
|
93
92
|
"yaml-front-matter": "^4.1.1",
|
|
94
|
-
"rspack-plugin-virtual-module": "0.1.
|
|
95
|
-
"@rspress/shared": "0.0.
|
|
96
|
-
"@rspress/plugin-medium-zoom": "0.0.
|
|
97
|
-
"@rspress/plugin-last-updated": "0.0.
|
|
98
|
-
"@rspress/plugin-auto-nav-sidebar": "0.0.
|
|
99
|
-
"@rspress/plugin-container-syntax": "0.0.
|
|
93
|
+
"rspack-plugin-virtual-module": "0.1.12",
|
|
94
|
+
"@rspress/shared": "0.0.11",
|
|
95
|
+
"@rspress/plugin-medium-zoom": "0.0.11",
|
|
96
|
+
"@rspress/plugin-last-updated": "0.0.11",
|
|
97
|
+
"@rspress/plugin-auto-nav-sidebar": "0.0.11",
|
|
98
|
+
"@rspress/plugin-container-syntax": "0.0.11"
|
|
100
99
|
},
|
|
101
100
|
"peerDependencies": {
|
|
102
101
|
"react": ">=17"
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import {
|
|
3
|
+
NavItem,
|
|
3
4
|
NavItemWithChildren,
|
|
4
5
|
NavItemWithLink,
|
|
6
|
+
NavItemWithLinkAndChildren,
|
|
5
7
|
withoutBase,
|
|
6
8
|
} from '@rspress/shared';
|
|
7
9
|
import { Link } from '../Link';
|
|
8
10
|
import Translator from '../../assets/translator.svg';
|
|
9
11
|
import Down from '../../assets/down.svg';
|
|
10
12
|
import { Tag } from '../Tag';
|
|
13
|
+
import { NavMenuSingleItem } from './NavMenuSingleItem';
|
|
11
14
|
|
|
12
15
|
export interface NavMenuGroupItem {
|
|
13
16
|
text?: string | React.ReactElement;
|
|
14
|
-
|
|
17
|
+
link?: string;
|
|
18
|
+
items: NavItem[];
|
|
15
19
|
tag?: string;
|
|
16
20
|
// Design for i18n highlight.
|
|
17
21
|
activeValue?: string;
|
|
@@ -19,6 +23,8 @@ export interface NavMenuGroupItem {
|
|
|
19
23
|
pathname?: string;
|
|
20
24
|
// Base path.
|
|
21
25
|
base?: string;
|
|
26
|
+
// Locales
|
|
27
|
+
langs?: string[];
|
|
22
28
|
// When the item is transition, we need to give a react element instead of a string.
|
|
23
29
|
isTranslation?: boolean;
|
|
24
30
|
}
|
|
@@ -64,6 +70,7 @@ export function NavMenuGroup(item: NavMenuGroupItem) {
|
|
|
64
70
|
isTranslation,
|
|
65
71
|
items: groupItems,
|
|
66
72
|
base = '',
|
|
73
|
+
link = '',
|
|
67
74
|
pathname = '',
|
|
68
75
|
} = item;
|
|
69
76
|
const [isOpen, setIsOpen] = useState(false);
|
|
@@ -76,12 +83,18 @@ export function NavMenuGroup(item: NavMenuGroupItem) {
|
|
|
76
83
|
}
|
|
77
84
|
return <NormalGroupItem key={item.link} item={item} />;
|
|
78
85
|
};
|
|
79
|
-
const renderGroup = (
|
|
86
|
+
const renderGroup = (
|
|
87
|
+
item: NavItemWithChildren | NavItemWithLinkAndChildren,
|
|
88
|
+
) => {
|
|
80
89
|
return (
|
|
81
90
|
<div>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
91
|
+
{'link' in item ? (
|
|
92
|
+
renderLinkItem(item as NavItemWithLink)
|
|
93
|
+
) : (
|
|
94
|
+
<p className="font-bold text-gray-400 my-1 not:first:border">
|
|
95
|
+
{item.text}
|
|
96
|
+
</p>
|
|
97
|
+
)}
|
|
85
98
|
{(item.items as NavItemWithLink[]).map(renderLinkItem)}
|
|
86
99
|
</div>
|
|
87
100
|
);
|
|
@@ -95,25 +108,32 @@ export function NavMenuGroup(item: NavMenuGroupItem) {
|
|
|
95
108
|
onMouseEnter={() => setIsOpen(true)}
|
|
96
109
|
className="nav-menu-group-button flex-center items-center font-medium text-sm text-text-1 hover:text-text-2 transition-colors duration-200"
|
|
97
110
|
>
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
{isTranslation ? (
|
|
106
|
-
<Translator
|
|
111
|
+
{link ? (
|
|
112
|
+
// @ts-expect-error item.text may be ReactElement
|
|
113
|
+
<NavMenuSingleItem {...item} rightIcon={<Down />} />
|
|
114
|
+
) : (
|
|
115
|
+
<>
|
|
116
|
+
<span
|
|
117
|
+
className="text-sm font-medium flex"
|
|
107
118
|
style={{
|
|
108
|
-
|
|
109
|
-
height: '18px',
|
|
119
|
+
marginRight: '2px',
|
|
110
120
|
}}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
121
|
+
>
|
|
122
|
+
<Tag tag={item.tag} />
|
|
123
|
+
{isTranslation ? (
|
|
124
|
+
<Translator
|
|
125
|
+
style={{
|
|
126
|
+
with: '18px',
|
|
127
|
+
height: '18px',
|
|
128
|
+
}}
|
|
129
|
+
/>
|
|
130
|
+
) : (
|
|
131
|
+
item.text
|
|
132
|
+
)}
|
|
133
|
+
</span>
|
|
134
|
+
<Down />
|
|
135
|
+
</>
|
|
136
|
+
)}
|
|
117
137
|
</button>
|
|
118
138
|
<div
|
|
119
139
|
className="nav-menu-group-content absolute mx-0.8 transition-opacity duration-300"
|
|
@@ -138,7 +158,7 @@ export function NavMenuGroup(item: NavMenuGroupItem) {
|
|
|
138
158
|
{groupItems.map(item => {
|
|
139
159
|
return (
|
|
140
160
|
<div key={item.text}>
|
|
141
|
-
{'
|
|
161
|
+
{'items' in item ? renderGroup(item) : renderLinkItem(item)}
|
|
142
162
|
</div>
|
|
143
163
|
);
|
|
144
164
|
})}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
NavItemWithLink,
|
|
3
|
+
NavItemWithLinkAndChildren,
|
|
4
|
+
withoutBase,
|
|
5
|
+
} from '@rspress/shared';
|
|
2
6
|
import { Link } from '../Link';
|
|
3
7
|
import { Tag } from '../Tag';
|
|
4
8
|
import styles from './index.module.scss';
|
|
@@ -6,11 +10,14 @@ import { normalizeHref } from '@/runtime';
|
|
|
6
10
|
|
|
7
11
|
interface Props {
|
|
8
12
|
pathname: string;
|
|
9
|
-
langs
|
|
13
|
+
langs?: string[];
|
|
10
14
|
base: string;
|
|
15
|
+
rightIcon?: React.ReactNode;
|
|
11
16
|
}
|
|
12
17
|
|
|
13
|
-
export function NavMenuSingleItem(
|
|
18
|
+
export function NavMenuSingleItem(
|
|
19
|
+
item: (NavItemWithLink | NavItemWithLinkAndChildren) & Props,
|
|
20
|
+
) {
|
|
14
21
|
const { pathname, base } = item;
|
|
15
22
|
const isActive = new RegExp(item.activeMatch || item.link).test(
|
|
16
23
|
withoutBase(pathname, base),
|
|
@@ -22,10 +29,11 @@ export function NavMenuSingleItem(item: NavItemWithLink & Props) {
|
|
|
22
29
|
key={item.text}
|
|
23
30
|
className={`${styles.singleItem} ${
|
|
24
31
|
isActive ? styles.activeItem : ''
|
|
25
|
-
} text-sm font-medium mx-1.5 px-3 py-2 flex`}
|
|
32
|
+
} text-sm font-medium mx-1.5 px-3 py-2 flex items-center`}
|
|
26
33
|
>
|
|
27
34
|
<Tag tag={item.tag} />
|
|
28
35
|
{item.text}
|
|
36
|
+
{item.rightIcon}
|
|
29
37
|
</div>
|
|
30
38
|
</Link>
|
|
31
39
|
);
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
NavItem,
|
|
3
|
+
NavItemWithChildren,
|
|
4
|
+
NavItemWithLink,
|
|
5
|
+
NavItemWithLinkAndChildren,
|
|
6
|
+
} from '@rspress/shared';
|
|
2
7
|
import { useState } from 'react';
|
|
3
8
|
import Down from '../../assets/down.svg';
|
|
4
9
|
import { Link } from '../Link';
|
|
@@ -6,7 +11,7 @@ import styles from './index.module.scss';
|
|
|
6
11
|
|
|
7
12
|
export interface NavScreenMenuGroupItem {
|
|
8
13
|
text?: string | React.ReactElement;
|
|
9
|
-
items:
|
|
14
|
+
items: NavItem[];
|
|
10
15
|
activeValue?: string;
|
|
11
16
|
}
|
|
12
17
|
|
|
@@ -42,12 +47,18 @@ export function NavScreenMenuGroup(item: NavScreenMenuGroupItem) {
|
|
|
42
47
|
}
|
|
43
48
|
return <NormalGroupItem key={item.link} item={item} />;
|
|
44
49
|
};
|
|
45
|
-
const renderGroup = (
|
|
50
|
+
const renderGroup = (
|
|
51
|
+
item: NavItemWithChildren | NavItemWithLinkAndChildren,
|
|
52
|
+
) => {
|
|
46
53
|
return (
|
|
47
54
|
<div>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
{'link' in item ? (
|
|
56
|
+
renderLinkItem(item as NavItemWithLink)
|
|
57
|
+
) : (
|
|
58
|
+
<p className="font-bold text-gray-400 my-1 not:first:border">
|
|
59
|
+
{item.text}
|
|
60
|
+
</p>
|
|
61
|
+
)}
|
|
51
62
|
{(item.items as NavItemWithLink[]).map(renderLinkItem)}
|
|
52
63
|
</div>
|
|
53
64
|
);
|
|
@@ -73,7 +84,7 @@ export function NavScreenMenuGroup(item: NavScreenMenuGroupItem) {
|
|
|
73
84
|
{item.items.map(item => {
|
|
74
85
|
return (
|
|
75
86
|
<div key={item.text}>
|
|
76
|
-
{'
|
|
87
|
+
{'items' in item ? renderGroup(item) : renderLinkItem(item)}
|
|
77
88
|
</div>
|
|
78
89
|
);
|
|
79
90
|
})}
|
|
@@ -49,6 +49,7 @@ export function SidebarItem(props: SidebarItemProps) {
|
|
|
49
49
|
marginLeft: depth === 0 ? 0 : '18px',
|
|
50
50
|
borderRadius: '0 1rem 1rem 0',
|
|
51
51
|
...(depth === 0 ? highlightTitleStyle : {}),
|
|
52
|
+
...(active ? { color: 'var(--rp-c-brand)' } : {}),
|
|
52
53
|
}}
|
|
53
54
|
>
|
|
54
55
|
<Tag tag={item.tag} />
|
|
@@ -48,8 +48,10 @@ export const Layout: React.FC<LayoutProps> = props => {
|
|
|
48
48
|
} = page;
|
|
49
49
|
const localesData = useLocaleSiteData();
|
|
50
50
|
const defaultLang = siteData.lang || '';
|
|
51
|
+
// Priority: frontmatter.navbar > themeConfig.hideNavbar
|
|
52
|
+
// Always show sidebar by default
|
|
51
53
|
const hideNavbar =
|
|
52
|
-
frontmatter?.
|
|
54
|
+
!(frontmatter?.navbar ?? true) || (themeConfig?.hideNavbar ?? false);
|
|
53
55
|
// Priority: front matter title > h1 title
|
|
54
56
|
let title = (frontmatter?.title as string) ?? articleTitle;
|
|
55
57
|
const mainTitle = siteData.title || localesData.title;
|
|
@@ -140,11 +142,22 @@ export const Layout: React.FC<LayoutProps> = props => {
|
|
|
140
142
|
{bottom}
|
|
141
143
|
{
|
|
142
144
|
// Global UI
|
|
143
|
-
globalComponents.map((
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
globalComponents.map((componentInfo, index) => {
|
|
146
|
+
if (Array.isArray(componentInfo)) {
|
|
147
|
+
const [component, props] = componentInfo;
|
|
148
|
+
return React.createElement(component, {
|
|
149
|
+
// The component order is stable
|
|
150
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
151
|
+
key: index,
|
|
152
|
+
...props,
|
|
153
|
+
});
|
|
154
|
+
} else {
|
|
155
|
+
return React.createElement(componentInfo, {
|
|
156
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
157
|
+
key: index,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
})
|
|
148
161
|
}
|
|
149
162
|
</div>
|
|
150
163
|
);
|
|
@@ -9,7 +9,6 @@ export function useLocaleSiteData(): NormalizedLocales {
|
|
|
9
9
|
const themeConfig = pageData?.siteData?.themeConfig ?? {};
|
|
10
10
|
const defaultLang = pageData.siteData.lang ?? '';
|
|
11
11
|
const locales = themeConfig?.locales;
|
|
12
|
-
|
|
13
12
|
if (!locales || locales.length === 0) {
|
|
14
13
|
return {
|
|
15
14
|
nav: themeConfig.nav,
|
|
@@ -19,6 +18,7 @@ export function useLocaleSiteData(): NormalizedLocales {
|
|
|
19
18
|
} as NormalizedLocales;
|
|
20
19
|
}
|
|
21
20
|
const localeInfo = locales.find(locale => locale.lang === lang)!;
|
|
21
|
+
|
|
22
22
|
return {
|
|
23
23
|
...localeInfo,
|
|
24
24
|
langRoutePrefix: lang === defaultLang ? '/' : lang,
|
|
@@ -67,7 +67,7 @@ export function useSidebarData(): SidebarData {
|
|
|
67
67
|
useEffect(() => {
|
|
68
68
|
const newSidebarData = getSidebarGroupData(sidebar, pathname);
|
|
69
69
|
setSidebarData(newSidebarData);
|
|
70
|
-
}, [pathname,
|
|
70
|
+
}, [pathname, localeData.lang]);
|
|
71
71
|
|
|
72
72
|
return sidebarData;
|
|
73
73
|
}
|