@rspress/core 0.0.9 → 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.d.ts +1 -10
- package/dist/index.js +237 -264
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +0 -3
- package/dist/loader.js.map +1 -1
- package/dist/theme/bundle.css +96 -159
- package/dist/theme/bundle.d.ts +1 -1
- package/dist/theme/bundle.js +879 -802
- package/dist/theme/bundle.js.map +1 -1
- package/package.json +15 -15
- package/src/theme-default/components/Aside/index.css +23 -0
- package/src/theme-default/components/Aside/index.tsx +7 -13
- package/src/theme-default/components/EditLink/index.module.scss +3 -3
- package/src/theme-default/components/EditLink/index.tsx +0 -5
- package/src/theme-default/components/HomeHero/index.module.scss +6 -0
- package/src/theme-default/components/HomeHero/index.tsx +4 -4
- 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.module.scss +0 -1
- package/src/theme-default/components/Nav/index.tsx +4 -3
- package/src/theme-default/components/NavScreenMenuGroup/NavScreenMenuGroup.tsx +18 -7
- package/src/theme-default/components/Search/logic/providers/LocalProvider.ts +1 -2
- package/src/theme-default/components/Sidebar/SidebarGroup.tsx +180 -0
- package/src/theme-default/components/Sidebar/SidebarItem.tsx +61 -0
- package/src/theme-default/components/Sidebar/index.module.scss +22 -5
- package/src/theme-default/components/Sidebar/index.tsx +39 -248
- package/src/theme-default/components/Tabs/index.module.scss +11 -18
- package/src/theme-default/components/Tabs/index.tsx +1 -1
- package/src/theme-default/layout/DocLayout/index.module.scss +17 -18
- package/src/theme-default/layout/Layout/index.tsx +19 -7
- package/src/theme-default/logic/sideEffects.ts +3 -1
- package/src/theme-default/logic/useEditLink.ts +6 -3
- package/src/theme-default/logic/useLocaleSiteData.ts +1 -1
- package/src/theme-default/logic/useSidebarData.ts +1 -1
- package/src/theme-default/styles/{doc/code.css → code.css} +4 -1
- package/src/theme-default/styles/index.ts +1 -3
- package/src/theme-default/styles/vars.css +2 -2
- package/src/theme-default/assets/edit.svg +0 -1
- package/src/theme-default/styles/doc/container.css +0 -103
- package/src/theme-default/styles/doc/index.css +0 -6
- /package/dist/theme/{index.ts → index.js} +0 -0
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": {
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"@mdx-js/loader": "2.2.1",
|
|
42
42
|
"@mdx-js/mdx": "2.2.1",
|
|
43
43
|
"@mdx-js/react": "2.2.1",
|
|
44
|
-
"@modern-js/builder": "2.
|
|
45
|
-
"@modern-js/builder-rspack-provider": "2.
|
|
46
|
-
"@modern-js/mdx-rs-binding": "0.2.
|
|
47
|
-
"@modern-js/utils": "2.
|
|
44
|
+
"@modern-js/builder": "2.34.0",
|
|
45
|
+
"@modern-js/builder-rspack-provider": "2.34.0",
|
|
46
|
+
"@modern-js/mdx-rs-binding": "0.2.6",
|
|
47
|
+
"@modern-js/utils": "2.34.0",
|
|
48
48
|
"@types/compression": "^1.7.2",
|
|
49
49
|
"@types/polka": "^0.5.4",
|
|
50
50
|
"acorn": "^8.8.1",
|
|
@@ -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,20 +90,21 @@
|
|
|
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
|
-
"
|
|
95
|
-
"@rspress/
|
|
96
|
-
"@rspress/plugin-
|
|
97
|
-
"@rspress/plugin-
|
|
98
|
-
"@rspress/
|
|
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"
|
|
99
99
|
},
|
|
100
100
|
"peerDependencies": {
|
|
101
101
|
"react": ">=17"
|
|
102
102
|
},
|
|
103
103
|
"devDependencies": {
|
|
104
|
-
"@modern-js/plugin-tailwindcss": "2.
|
|
105
|
-
"@modern-js/plugin-testing": "2.
|
|
106
|
-
"@modern-js/tsconfig": "2.
|
|
107
|
-
"@modern-js/types": "2.
|
|
104
|
+
"@modern-js/plugin-tailwindcss": "2.34.0",
|
|
105
|
+
"@modern-js/plugin-testing": "2.34.0",
|
|
106
|
+
"@modern-js/tsconfig": "2.34.0",
|
|
107
|
+
"@modern-js/types": "2.34.0",
|
|
108
108
|
"@types/body-scroll-lock": "^3.1.0",
|
|
109
109
|
"@types/fs-extra": "^9.0.13",
|
|
110
110
|
"@types/hast": "^2.3.4",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
.aside-link {
|
|
2
|
+
padding-bottom: 1px;
|
|
3
|
+
}
|
|
4
|
+
.aside-link-text {
|
|
5
|
+
padding: 0px 12px;
|
|
6
|
+
white-space: nowrap;
|
|
7
|
+
overflow: hidden;
|
|
8
|
+
text-overflow: ellipsis;
|
|
9
|
+
transition: all 0.2s ease-in-out;
|
|
10
|
+
border-radius: 10px 0 0 10px;
|
|
11
|
+
font-size: 13px;
|
|
12
|
+
line-height: 1.75rem;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.aside-link-text:hover {
|
|
16
|
+
background-color: var(--rp-c-bg-mute);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.aside-active,
|
|
20
|
+
.aside-active:hover {
|
|
21
|
+
color: var(--rp-c-brand-dark) !important;
|
|
22
|
+
background-color: var(--rp-c-brand-tint);
|
|
23
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useRef, useEffect } from 'react';
|
|
2
|
-
import { Header } from '@rspress/shared
|
|
2
|
+
import { Header } from '@rspress/shared';
|
|
3
3
|
import { bindingAsideScroll, scrollToTarget } from '../../logic';
|
|
4
|
+
import './index.css';
|
|
4
5
|
|
|
5
6
|
export function Aside(props: { headers: Header[]; outlineTitle: string }) {
|
|
6
7
|
const { headers } = props;
|
|
@@ -33,22 +34,15 @@ export function Aside(props: { headers: Header[]; outlineTitle: string }) {
|
|
|
33
34
|
};
|
|
34
35
|
}, [headers]);
|
|
35
36
|
|
|
36
|
-
// const handleHeaderClick = e => {};
|
|
37
|
-
|
|
38
37
|
const renderHeader = (header: Header) => {
|
|
39
38
|
return (
|
|
40
39
|
<li key={header.id}>
|
|
41
40
|
<a
|
|
42
41
|
href={`#${header.id}`}
|
|
43
|
-
className="
|
|
42
|
+
className="aside-link transition-all duration-300 hover:text-text-1 text-text-2 block"
|
|
44
43
|
style={{
|
|
45
|
-
fontSize: '13px',
|
|
46
44
|
paddingLeft: (header.depth - baseHeaderLevel) * 12,
|
|
47
|
-
|
|
48
|
-
overflow: 'hidden',
|
|
49
|
-
textOverflow: 'ellipsis',
|
|
50
|
-
fontWeight:
|
|
51
|
-
header.depth === baseHeaderLevel ? 'semibold' : 'normal',
|
|
45
|
+
fontWeight: 'semibold',
|
|
52
46
|
}}
|
|
53
47
|
onClick={e => {
|
|
54
48
|
e.preventDefault();
|
|
@@ -59,7 +53,7 @@ export function Aside(props: { headers: Header[]; outlineTitle: string }) {
|
|
|
59
53
|
}
|
|
60
54
|
}}
|
|
61
55
|
>
|
|
62
|
-
{header.text}
|
|
56
|
+
<span className="aside-link-text block">{header.text}</span>
|
|
63
57
|
</a>
|
|
64
58
|
</li>
|
|
65
59
|
);
|
|
@@ -68,8 +62,8 @@ export function Aside(props: { headers: Header[]; outlineTitle: string }) {
|
|
|
68
62
|
return (
|
|
69
63
|
<div className="flex flex-col">
|
|
70
64
|
<div className={hasOutline ? `<lg:hidden` : 'hidden'}>
|
|
71
|
-
<div id="aside-container" className="relative
|
|
72
|
-
<div className="leading-7 block text-sm font-semibold">
|
|
65
|
+
<div id="aside-container" className="relative text-sm font-medium">
|
|
66
|
+
<div className="leading-7 block text-sm font-semibold pl-3">
|
|
73
67
|
{props.outlineTitle}
|
|
74
68
|
</div>
|
|
75
69
|
<nav className="mt-1">
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
.editLink {
|
|
2
2
|
color: var(--rp-c-brand);
|
|
3
3
|
text-decoration: none;
|
|
4
|
-
font-size:
|
|
4
|
+
font-size: 15px;
|
|
5
5
|
font-weight: 500;
|
|
6
6
|
margin: 20px 0;
|
|
7
|
-
|
|
7
|
+
transition: all 0.2s ease-in-out;
|
|
8
8
|
&:hover {
|
|
9
|
-
|
|
9
|
+
color: var(--rp-c-brand-dark);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useEditLink } from '../../logic';
|
|
2
|
-
import Edit from '../../assets/edit.svg';
|
|
3
2
|
import styles from './index.module.scss';
|
|
4
3
|
|
|
5
4
|
export default function EditLink() {
|
|
@@ -13,10 +12,6 @@ export default function EditLink() {
|
|
|
13
12
|
|
|
14
13
|
return (
|
|
15
14
|
<a href={link} target="_blank" className={styles.editLink}>
|
|
16
|
-
<Edit
|
|
17
|
-
className="h-5.5 mr-2 inline-block"
|
|
18
|
-
style={{ verticalAlign: '-5px' }}
|
|
19
|
-
/>
|
|
20
15
|
{text}
|
|
21
16
|
</a>
|
|
22
17
|
);
|
|
@@ -24,8 +24,8 @@ export function HomeHero({ frontmatter }: { frontmatter: FrontMatterMeta }) {
|
|
|
24
24
|
></div>
|
|
25
25
|
<div className="m-auto flex flex-col md:flex-row max-w-6xl min-h-[50vh]">
|
|
26
26
|
<div className="flex flex-col justify-center text-center max-w-xl sm:max-w-4xl m-auto order-2 md:order-1">
|
|
27
|
-
<h1 className="font-bold text-3xl sm:text-6xl md:text-7xl m-auto sm:m-4 md:m-0 md:pb-3 lg:pb-
|
|
28
|
-
<span className={styles.clip} style={{ lineHeight: '1.
|
|
27
|
+
<h1 className="font-bold text-3xl sm:text-6xl md:text-7xl m-auto sm:m-4 md:m-0 md:pb-3 lg:pb-2 leading-tight z-10">
|
|
28
|
+
<span className={styles.clip} style={{ lineHeight: '1.3' }}>
|
|
29
29
|
{hero.name}
|
|
30
30
|
</span>
|
|
31
31
|
</h1>
|
|
@@ -34,7 +34,7 @@ export function HomeHero({ frontmatter }: { frontmatter: FrontMatterMeta }) {
|
|
|
34
34
|
className={`mx-auto md:m-0 text-3xl sm:text-5xl md:text-6xl pb-2 font-bold z-10 max-w-392px ${
|
|
35
35
|
hasImage ? 'sm:max-w-xl' : 'sm:max-w-4xl'
|
|
36
36
|
}`}
|
|
37
|
-
style={{ lineHeight: '1.
|
|
37
|
+
style={{ lineHeight: '1.2' }}
|
|
38
38
|
>
|
|
39
39
|
{hero.text}
|
|
40
40
|
</p>
|
|
@@ -58,7 +58,7 @@ export function HomeHero({ frontmatter }: { frontmatter: FrontMatterMeta }) {
|
|
|
58
58
|
</div>
|
|
59
59
|
|
|
60
60
|
{hasImage ? (
|
|
61
|
-
<div className="rspress-home-hero-image
|
|
61
|
+
<div className="rspress-home-hero-image md:flex-center m-auto order-1 md:order-2 sm:flex md:none lg:flex">
|
|
62
62
|
<img src={hero.image?.src} alt={hero.image?.alt} />
|
|
63
63
|
</div>
|
|
64
64
|
) : null}
|
|
@@ -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
|
);
|
|
@@ -100,7 +100,7 @@ export function Nav(props: NavProps) {
|
|
|
100
100
|
|
|
101
101
|
const NavMenu = ({ menuItems }: { menuItems: NavItem[] }) => {
|
|
102
102
|
return (
|
|
103
|
-
<div className="menu h-14">
|
|
103
|
+
<div className="rspress-nav-menu menu h-14">
|
|
104
104
|
{menuItems.map(item => {
|
|
105
105
|
return 'items' in item || Array.isArray(item) ? (
|
|
106
106
|
<div key={item.text} className="mx-3 last:mr-0">
|
|
@@ -108,6 +108,7 @@ export function Nav(props: NavProps) {
|
|
|
108
108
|
{...item}
|
|
109
109
|
base={base}
|
|
110
110
|
pathname={pathname}
|
|
111
|
+
langs={langs}
|
|
111
112
|
items={'items' in item ? item.items : item}
|
|
112
113
|
/>
|
|
113
114
|
</div>
|
|
@@ -140,11 +141,11 @@ export function Nav(props: NavProps) {
|
|
|
140
141
|
const hasAppearanceSwitch = siteData.themeConfig.darkMode !== false;
|
|
141
142
|
|
|
142
143
|
const leftNav = () => {
|
|
143
|
-
return (
|
|
144
|
+
return leftMenuItems.length > 0 ? (
|
|
144
145
|
<div className={styles.leftNav}>
|
|
145
146
|
<NavMenu menuItems={leftMenuItems} />
|
|
146
147
|
</div>
|
|
147
|
-
);
|
|
148
|
+
) : null;
|
|
148
149
|
};
|
|
149
150
|
|
|
150
151
|
const rightNav = () => {
|
|
@@ -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
|
})}
|
|
@@ -27,8 +27,7 @@ export class LocalProvider implements Provider {
|
|
|
27
27
|
|
|
28
28
|
async #getPages(lang: string): Promise<PageIndexInfo[]> {
|
|
29
29
|
const result = await fetch(
|
|
30
|
-
|
|
31
|
-
`${__ASSET_PREFIX__}/static/${SEARCH_INDEX_NAME}.${lang}.${searchIndexHash[lang]}.json`,
|
|
30
|
+
`${process.env.__ASSET_PREFIX__}/static/${SEARCH_INDEX_NAME}.${lang}.${searchIndexHash[lang]}.json`,
|
|
32
31
|
);
|
|
33
32
|
return result.json();
|
|
34
33
|
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { NormalizedSidebarGroup } from '@rspress/shared';
|
|
3
|
+
import { useNavigate } from 'react-router-dom';
|
|
4
|
+
import ArrowRight from '../../assets/arrow-right.svg';
|
|
5
|
+
import { Tag } from '../Tag';
|
|
6
|
+
import styles from './index.module.scss';
|
|
7
|
+
import { SidebarItem } from './SidebarItem';
|
|
8
|
+
import { highlightTitleStyle, matchCache, type SidebarItemProps } from '.';
|
|
9
|
+
import { normalizeHref, withBase } from '@/runtime';
|
|
10
|
+
|
|
11
|
+
export function SidebarGroup(props: SidebarItemProps) {
|
|
12
|
+
const { item, depth = 0, activeMatcher, id, setSidebarData } = props;
|
|
13
|
+
const navigate = useNavigate();
|
|
14
|
+
const isGroupMatched = matchCache.get(item);
|
|
15
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
16
|
+
const transitionRef = useRef<any>(null);
|
|
17
|
+
const innerRef = useRef<HTMLDivElement>(null);
|
|
18
|
+
const initialRender = useRef(true);
|
|
19
|
+
const initialState = useRef((item as NormalizedSidebarGroup).collapsed);
|
|
20
|
+
const active = item.link && activeMatcher(item.link);
|
|
21
|
+
const { collapsed, collapsible = true } = item as NormalizedSidebarGroup;
|
|
22
|
+
const collapsibleIcon = (
|
|
23
|
+
<div
|
|
24
|
+
style={{
|
|
25
|
+
cursor: 'pointer',
|
|
26
|
+
transition: 'transform 0.2s ease-out',
|
|
27
|
+
transform: collapsed ? 'rotate(0deg)' : 'rotate(90deg)',
|
|
28
|
+
}}
|
|
29
|
+
>
|
|
30
|
+
<ArrowRight />
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (initialRender.current) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!containerRef.current || !innerRef.current) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (transitionRef.current) {
|
|
44
|
+
clearTimeout(transitionRef.current);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const container = containerRef.current;
|
|
48
|
+
const inner = innerRef.current;
|
|
49
|
+
// We should add the margin-top(4px) of first item in list, which is a part of the height of the container
|
|
50
|
+
const contentHeight = inner.clientHeight + 4;
|
|
51
|
+
if (collapsed) {
|
|
52
|
+
container.style.maxHeight = `${contentHeight}px`;
|
|
53
|
+
container.style.transitionDuration = '0.5s';
|
|
54
|
+
inner.style.opacity = '0';
|
|
55
|
+
|
|
56
|
+
transitionRef.current = setTimeout(() => {
|
|
57
|
+
if (containerRef.current) {
|
|
58
|
+
containerRef.current.style.maxHeight = '0px';
|
|
59
|
+
}
|
|
60
|
+
}, 0);
|
|
61
|
+
} else {
|
|
62
|
+
container.style.maxHeight = `${contentHeight}px`;
|
|
63
|
+
container.style.transitionDuration = '0.3s';
|
|
64
|
+
inner.style.opacity = '1';
|
|
65
|
+
|
|
66
|
+
transitionRef.current = setTimeout(() => {
|
|
67
|
+
if (containerRef.current) {
|
|
68
|
+
containerRef.current.style.removeProperty('max-height');
|
|
69
|
+
}
|
|
70
|
+
}, 300);
|
|
71
|
+
}
|
|
72
|
+
}, [collapsed]);
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
initialRender.current = false;
|
|
76
|
+
}, []);
|
|
77
|
+
|
|
78
|
+
const toggleCollapse: React.MouseEventHandler<HTMLDivElement> = (e): void => {
|
|
79
|
+
e.stopPropagation();
|
|
80
|
+
// update collapsed state
|
|
81
|
+
setSidebarData(sidebarData => {
|
|
82
|
+
const newSidebarData = [...sidebarData];
|
|
83
|
+
const indexes = id.split('-').map(Number);
|
|
84
|
+
const initialIndex = indexes.shift()!;
|
|
85
|
+
const root = newSidebarData[initialIndex];
|
|
86
|
+
let current = root;
|
|
87
|
+
for (const index of indexes) {
|
|
88
|
+
current = (current as NormalizedSidebarGroup).items[index];
|
|
89
|
+
}
|
|
90
|
+
if ('items' in current) {
|
|
91
|
+
current.collapsed = !current.collapsed;
|
|
92
|
+
}
|
|
93
|
+
return newSidebarData;
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<section
|
|
99
|
+
key={id}
|
|
100
|
+
className="mt-0.5 block"
|
|
101
|
+
style={{
|
|
102
|
+
marginLeft: depth === 0 ? 0 : '18px',
|
|
103
|
+
}}
|
|
104
|
+
>
|
|
105
|
+
<div
|
|
106
|
+
className={`flex justify-between items-center ${
|
|
107
|
+
isGroupMatched && !active ? styles.menuGroupActive : ''
|
|
108
|
+
} ${
|
|
109
|
+
// eslint-disable-next-line no-nested-ternary
|
|
110
|
+
active
|
|
111
|
+
? styles.menuItemActive
|
|
112
|
+
: collapsible || item.link
|
|
113
|
+
? styles.menuItem
|
|
114
|
+
: styles.menuItemStatic
|
|
115
|
+
}`}
|
|
116
|
+
onMouseEnter={() => item.link && props.preloadLink(item.link)}
|
|
117
|
+
onClick={e => {
|
|
118
|
+
if (item.link) {
|
|
119
|
+
navigate(withBase(normalizeHref(item.link)));
|
|
120
|
+
collapsed && toggleCollapse(e);
|
|
121
|
+
} else {
|
|
122
|
+
collapsible && toggleCollapse(e);
|
|
123
|
+
}
|
|
124
|
+
}}
|
|
125
|
+
style={{
|
|
126
|
+
borderRadius: depth === 0 ? '0 1rem 1rem 0' : undefined,
|
|
127
|
+
cursor: collapsible || item.link ? 'pointer' : 'normal',
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
<h2
|
|
131
|
+
className="py-2.5 px-3 text-sm font-medium flex"
|
|
132
|
+
style={{
|
|
133
|
+
...(depth === 0 ? highlightTitleStyle : {}),
|
|
134
|
+
}}
|
|
135
|
+
>
|
|
136
|
+
<Tag tag={item.tag} />
|
|
137
|
+
{item.text}
|
|
138
|
+
</h2>
|
|
139
|
+
{collapsible && (
|
|
140
|
+
<div
|
|
141
|
+
className={`${styles.collapseContainer} p-2 rounded-xl`}
|
|
142
|
+
onClick={toggleCollapse}
|
|
143
|
+
>
|
|
144
|
+
{collapsibleIcon}
|
|
145
|
+
</div>
|
|
146
|
+
)}
|
|
147
|
+
</div>
|
|
148
|
+
<div
|
|
149
|
+
ref={containerRef}
|
|
150
|
+
className="transition-all duration-300 ease-in-out"
|
|
151
|
+
style={{
|
|
152
|
+
overflow: 'hidden',
|
|
153
|
+
maxHeight: initialState.current ? 0 : undefined,
|
|
154
|
+
}}
|
|
155
|
+
>
|
|
156
|
+
<div
|
|
157
|
+
ref={innerRef}
|
|
158
|
+
className="rspress-sidebar-group transition-opacity duration-500 ease-in-out"
|
|
159
|
+
style={{
|
|
160
|
+
opacity: initialState.current ? 0 : 1,
|
|
161
|
+
marginLeft: depth === 0 ? '12px' : 0,
|
|
162
|
+
}}
|
|
163
|
+
>
|
|
164
|
+
{(item as NormalizedSidebarGroup)?.items?.map((item, index) => (
|
|
165
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
166
|
+
<div key={index}>
|
|
167
|
+
<SidebarItem
|
|
168
|
+
{...props}
|
|
169
|
+
item={item}
|
|
170
|
+
depth={depth + 1}
|
|
171
|
+
id={`${id}-${index}`}
|
|
172
|
+
preloadLink={props.preloadLink}
|
|
173
|
+
/>
|
|
174
|
+
</div>
|
|
175
|
+
))}
|
|
176
|
+
</div>
|
|
177
|
+
</div>
|
|
178
|
+
</section>
|
|
179
|
+
);
|
|
180
|
+
}
|