@rspress/core 1.2.1 → 1.3.0
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 +2 -0
- package/dist/index.js +53 -40
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js.map +1 -1
- package/dist/runtime/App.js +8 -4
- package/dist/runtime/clientEntry.js +7 -4
- package/dist/runtime/ssrEntry.js +2 -2
- package/package.json +19 -15
- package/runtime.ts +1 -1
- package/src/runtime/App.tsx +8 -4
- package/src/runtime/clientEntry.tsx +7 -4
- package/src/runtime/ssrEntry.tsx +2 -2
- package/theme.ts +2 -2
- package/dist/runtime/Content.d.ts +0 -6
- package/dist/runtime/Content.js +0 -33
- package/dist/runtime/NoSSR.d.ts +0 -4
- package/dist/runtime/NoSSR.js +0 -17
- package/dist/runtime/hooks.d.ts +0 -39
- package/dist/runtime/hooks.js +0 -54
- package/dist/runtime/index.d.ts +0 -6
- package/dist/runtime/index.js +0 -34
- package/dist/runtime/utils.d.ts +0 -8
- package/dist/runtime/utils.js +0 -45
- package/dist/theme/bundle.css +0 -2691
- package/dist/theme/bundle.d.ts +0 -176
- package/dist/theme/bundle.js +0 -4433
- package/dist/theme/bundle.js.map +0 -1
- package/dist/theme/index.js +0 -6
- package/src/runtime/Content.tsx +0 -43
- package/src/runtime/NoSSR.tsx +0 -16
- package/src/runtime/hooks.ts +0 -110
- package/src/runtime/index.ts +0 -17
- package/src/runtime/utils.ts +0 -46
- package/src/theme-default/assets/arrow-down.svg +0 -1
- package/src/theme-default/assets/arrow-right.svg +0 -1
- package/src/theme-default/assets/copy.svg +0 -1
- package/src/theme-default/assets/down.svg +0 -1
- package/src/theme-default/assets/github.svg +0 -1
- package/src/theme-default/assets/loading.svg +0 -1
- package/src/theme-default/assets/menu.svg +0 -1
- package/src/theme-default/assets/moon.svg +0 -3
- package/src/theme-default/assets/right.svg +0 -1
- package/src/theme-default/assets/small-menu.svg +0 -1
- package/src/theme-default/assets/success.svg +0 -1
- package/src/theme-default/assets/sun.svg +0 -11
- package/src/theme-default/assets/translator.svg +0 -1
- package/src/theme-default/components/Aside/index.css +0 -22
- package/src/theme-default/components/Aside/index.tsx +0 -75
- package/src/theme-default/components/BackDrop/index.module.scss +0 -14
- package/src/theme-default/components/BackDrop/index.tsx +0 -13
- package/src/theme-default/components/Button/index.module.scss +0 -68
- package/src/theme-default/components/Button/index.tsx +0 -40
- package/src/theme-default/components/DocFooter/index.module.scss +0 -60
- package/src/theme-default/components/DocFooter/index.tsx +0 -66
- package/src/theme-default/components/EditLink/index.module.scss +0 -11
- package/src/theme-default/components/EditLink/index.tsx +0 -18
- package/src/theme-default/components/HomeFeatures/index.module.scss +0 -50
- package/src/theme-default/components/HomeFeatures/index.tsx +0 -65
- package/src/theme-default/components/HomeFooter/index.tsx +0 -15
- package/src/theme-default/components/HomeHero/index.module.scss +0 -42
- package/src/theme-default/components/HomeHero/index.tsx +0 -75
- package/src/theme-default/components/Link/index.module.scss +0 -9
- package/src/theme-default/components/Link/index.tsx +0 -90
- package/src/theme-default/components/LocalSideBar/index.scss +0 -40
- package/src/theme-default/components/LocalSideBar/index.tsx +0 -39
- package/src/theme-default/components/Nav/NavBarTitle.tsx +0 -43
- package/src/theme-default/components/Nav/NavMenuGroup.tsx +0 -156
- package/src/theme-default/components/Nav/NavMenuSingleItem.tsx +0 -40
- package/src/theme-default/components/Nav/NavTranslations.tsx +0 -16
- package/src/theme-default/components/Nav/NavVersions.tsx +0 -16
- package/src/theme-default/components/Nav/index.module.scss +0 -115
- package/src/theme-default/components/Nav/index.tsx +0 -150
- package/src/theme-default/components/Nav/menuDataHooks.tsx +0 -75
- package/src/theme-default/components/NavHambmger/index.module.scss +0 -81
- package/src/theme-default/components/NavHambmger/index.tsx +0 -39
- package/src/theme-default/components/NavScreen/NavScreenMenuGroup.tsx +0 -95
- package/src/theme-default/components/NavScreen/index.module.scss +0 -88
- package/src/theme-default/components/NavScreen/index.tsx +0 -123
- package/src/theme-default/components/Overview/index.module.scss +0 -154
- package/src/theme-default/components/Overview/index.tsx +0 -136
- package/src/theme-default/components/PackageManagerTabs/icons/Bun.tsx +0 -101
- package/src/theme-default/components/PackageManagerTabs/icons/Npm.tsx +0 -16
- package/src/theme-default/components/PackageManagerTabs/icons/Pnpm.tsx +0 -22
- package/src/theme-default/components/PackageManagerTabs/icons/Yarn.tsx +0 -18
- package/src/theme-default/components/PackageManagerTabs/index.scss +0 -5
- package/src/theme-default/components/PackageManagerTabs/index.tsx +0 -110
- package/src/theme-default/components/Search/NoSearchResult.tsx +0 -13
- package/src/theme-default/components/Search/SearchPanel.tsx +0 -340
- package/src/theme-default/components/Search/SuggestItem.tsx +0 -135
- package/src/theme-default/components/Search/assets/close.svg +0 -1
- package/src/theme-default/components/Search/assets/file.svg +0 -1
- package/src/theme-default/components/Search/assets/header.svg +0 -1
- package/src/theme-default/components/Search/assets/jump.svg +0 -1
- package/src/theme-default/components/Search/assets/loading.svg +0 -1
- package/src/theme-default/components/Search/assets/search.svg +0 -1
- package/src/theme-default/components/Search/assets/title.svg +0 -1
- package/src/theme-default/components/Search/empty.svg +0 -4
- package/src/theme-default/components/Search/index.module.scss +0 -236
- package/src/theme-default/components/Search/index.tsx +0 -39
- package/src/theme-default/components/Search/logic/Provider.ts +0 -35
- package/src/theme-default/components/Search/logic/providers/LocalProvider.ts +0 -102
- package/src/theme-default/components/Search/logic/providers/RemoteProvider.ts +0 -40
- package/src/theme-default/components/Search/logic/search.ts +0 -341
- package/src/theme-default/components/Search/logic/util.test.ts +0 -21
- package/src/theme-default/components/Search/logic/util.ts +0 -127
- package/src/theme-default/components/Sidebar/SidebarGroup.tsx +0 -180
- package/src/theme-default/components/Sidebar/SidebarItem.tsx +0 -61
- package/src/theme-default/components/Sidebar/index.module.scss +0 -142
- package/src/theme-default/components/Sidebar/index.tsx +0 -156
- package/src/theme-default/components/SocialLinks/HiddenLinks.tsx +0 -30
- package/src/theme-default/components/SocialLinks/LinkContent.tsx +0 -90
- package/src/theme-default/components/SocialLinks/ShownLinks.tsx +0 -32
- package/src/theme-default/components/SocialLinks/index.module.scss +0 -18
- package/src/theme-default/components/SocialLinks/index.tsx +0 -36
- package/src/theme-default/components/SocialLinks/presetIcons.tsx +0 -165
- package/src/theme-default/components/SwitchAppearance/index.module.scss +0 -15
- package/src/theme-default/components/SwitchAppearance/index.tsx +0 -35
- package/src/theme-default/components/Tabs/index.module.scss +0 -46
- package/src/theme-default/components/Tabs/index.tsx +0 -123
- package/src/theme-default/components/Tag/index.tsx +0 -18
- package/src/theme-default/components/Toc/index.css +0 -18
- package/src/theme-default/components/Toc/index.tsx +0 -42
- package/src/theme-default/index.ts +0 -26
- package/src/theme-default/layout/DocLayout/docComponents/code.tsx +0 -112
- package/src/theme-default/layout/DocLayout/docComponents/hr.tsx +0 -10
- package/src/theme-default/layout/DocLayout/docComponents/index.module.scss +0 -69
- package/src/theme-default/layout/DocLayout/docComponents/index.tsx +0 -33
- package/src/theme-default/layout/DocLayout/docComponents/link.tsx +0 -22
- package/src/theme-default/layout/DocLayout/docComponents/list.tsx +0 -13
- package/src/theme-default/layout/DocLayout/docComponents/paragraph.tsx +0 -19
- package/src/theme-default/layout/DocLayout/docComponents/pre.tsx +0 -37
- package/src/theme-default/layout/DocLayout/docComponents/prisim-theme.ts +0 -73
- package/src/theme-default/layout/DocLayout/docComponents/table.tsx +0 -37
- package/src/theme-default/layout/DocLayout/docComponents/title.tsx +0 -40
- package/src/theme-default/layout/DocLayout/index.module.scss +0 -138
- package/src/theme-default/layout/DocLayout/index.tsx +0 -125
- package/src/theme-default/layout/HomeLayout/index.css +0 -18
- package/src/theme-default/layout/HomeLayout/index.tsx +0 -39
- package/src/theme-default/layout/Layout/index.tsx +0 -176
- package/src/theme-default/layout/NotFountLayout/index.tsx +0 -40
- package/src/theme-default/logic/TabDataContext.ts +0 -14
- package/src/theme-default/logic/index.ts +0 -8
- package/src/theme-default/logic/sideEffects.ts +0 -174
- package/src/theme-default/logic/useAppearance.ts +0 -57
- package/src/theme-default/logic/useEditLink.ts +0 -33
- package/src/theme-default/logic/useHiddenNav.ts +0 -58
- package/src/theme-default/logic/useLocaleSiteData.ts +0 -26
- package/src/theme-default/logic/useNav.ts +0 -36
- package/src/theme-default/logic/usePathUtils.ts +0 -73
- package/src/theme-default/logic/usePrevNextPage.ts +0 -40
- package/src/theme-default/logic/useSidebarData.ts +0 -73
- package/src/theme-default/logic/utils.ts +0 -38
- package/src/theme-default/styles/base.css +0 -102
- package/src/theme-default/styles/code.css +0 -177
- package/src/theme-default/styles/index.ts +0 -7
- package/src/theme-default/styles/scrollbar.css +0 -28
- package/src/theme-default/styles/vars.css +0 -81
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef } from 'react';
|
|
2
|
-
import { Link } from '../Link';
|
|
3
|
-
import { Tag } from '../Tag';
|
|
4
|
-
import styles from './index.module.scss';
|
|
5
|
-
import { SidebarGroup } from './SidebarGroup';
|
|
6
|
-
import { SidebarItemProps, highlightTitleStyle } from '.';
|
|
7
|
-
import { normalizeHrefInRuntime as normalizeHref } from '@/runtime';
|
|
8
|
-
|
|
9
|
-
export function SidebarItem(props: SidebarItemProps) {
|
|
10
|
-
const { item, depth = 0, activeMatcher, id, setSidebarData } = props;
|
|
11
|
-
const active = item.link && activeMatcher(item.link);
|
|
12
|
-
|
|
13
|
-
const ref = useRef<HTMLDivElement>(null);
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
if (active) {
|
|
16
|
-
ref.current?.scrollIntoView({
|
|
17
|
-
block: 'center',
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}, []);
|
|
21
|
-
|
|
22
|
-
const { text } = item;
|
|
23
|
-
|
|
24
|
-
if ('items' in item) {
|
|
25
|
-
return (
|
|
26
|
-
<SidebarGroup
|
|
27
|
-
id={id}
|
|
28
|
-
key={`${item.text}-${id}`}
|
|
29
|
-
item={item}
|
|
30
|
-
depth={depth}
|
|
31
|
-
activeMatcher={activeMatcher}
|
|
32
|
-
collapsed={item.collapsed}
|
|
33
|
-
setSidebarData={setSidebarData}
|
|
34
|
-
preloadLink={props.preloadLink}
|
|
35
|
-
/>
|
|
36
|
-
);
|
|
37
|
-
} else {
|
|
38
|
-
return (
|
|
39
|
-
<Link href={normalizeHref(item.link)} className={styles.menuLink}>
|
|
40
|
-
<div
|
|
41
|
-
ref={ref}
|
|
42
|
-
onMouseEnter={() => props.preloadLink(item.link)}
|
|
43
|
-
className={`${
|
|
44
|
-
active ? styles.menuItemActive : styles.menuItem
|
|
45
|
-
} mt-0.5 py-2 px-3 font-medium flex`}
|
|
46
|
-
style={{
|
|
47
|
-
// The first level menu item will have the same font size as the sidebar group
|
|
48
|
-
fontSize: depth === 0 ? '14px' : '13px',
|
|
49
|
-
marginLeft: depth === 0 ? 0 : '18px',
|
|
50
|
-
borderRadius: '0 1rem 1rem 0',
|
|
51
|
-
...(depth === 0 ? highlightTitleStyle : {}),
|
|
52
|
-
...(active ? { color: 'var(--rp-c-brand)' } : {}),
|
|
53
|
-
}}
|
|
54
|
-
>
|
|
55
|
-
<Tag tag={item.tag} />
|
|
56
|
-
{text}
|
|
57
|
-
</div>
|
|
58
|
-
</Link>
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
.navTitleMask {
|
|
2
|
-
padding-left: 1.5rem;
|
|
3
|
-
height: var(--rp-nav-height);
|
|
4
|
-
display: flex;
|
|
5
|
-
align-items: center;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.sidebar {
|
|
9
|
-
position: fixed;
|
|
10
|
-
top: 0;
|
|
11
|
-
bottom: 0;
|
|
12
|
-
left: 0;
|
|
13
|
-
z-index: var(--rp-z-index-sidebar);
|
|
14
|
-
padding: 0 12px 96px 0;
|
|
15
|
-
width: calc(100vw - 64px);
|
|
16
|
-
max-width: 320px;
|
|
17
|
-
opacity: 0;
|
|
18
|
-
transform: translateX(-100%);
|
|
19
|
-
transition: opacity 0.5s, transform 0.25s ease;
|
|
20
|
-
background: var(--rp-c-bg);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.sidebarContent {
|
|
24
|
-
overflow-x: hidden;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.sidebar.open {
|
|
28
|
-
opacity: 1;
|
|
29
|
-
visibility: visible;
|
|
30
|
-
transform: translateX(0);
|
|
31
|
-
transition: opacity 0.25s, transform 0.5s cubic-bezier(0.19, 1, 0.22, 1);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@media (min-width: 960px) {
|
|
35
|
-
.sidebar {
|
|
36
|
-
// Lower than z-index of nav
|
|
37
|
-
z-index: 5;
|
|
38
|
-
opacity: 1;
|
|
39
|
-
visibility: visible;
|
|
40
|
-
position: sticky;
|
|
41
|
-
margin-top: calc(var(--rp-nav-height) * -1);
|
|
42
|
-
height: 100vh;
|
|
43
|
-
width: var(--rp-sidebar-width);
|
|
44
|
-
transform: translateX(0);
|
|
45
|
-
box-shadow: var(--rp-c-shadow-3);
|
|
46
|
-
mask-image: linear-gradient(transparent, #000 20px),
|
|
47
|
-
linear-gradient(270deg, #000 10px, transparent 0);
|
|
48
|
-
--webkit-mask-image: linear-gradient(270deg, #000 10px, transparent 0);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@media (min-width: 1440px) {
|
|
53
|
-
.sidebar {
|
|
54
|
-
padding-left: 0;
|
|
55
|
-
width: var(--rp-sidebar-width);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
.menuLink {
|
|
60
|
-
opacity: 1;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
.menuLink:hover {
|
|
64
|
-
color: inherit;
|
|
65
|
-
transition: all 0.2s;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
.menuItem:hover {
|
|
69
|
-
background-color: var(--rp-c-bg-mute);
|
|
70
|
-
transition: all 0.2s;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
.collapseContainer:hover {
|
|
74
|
-
background-color: rgba(229, 229, 229, 0.4);
|
|
75
|
-
transition: all 0.2s;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
:global(.dark) .menuItem:hover,
|
|
79
|
-
:global(.dark) .collapseContainer:hover {
|
|
80
|
-
background-color: var(--rp-c-bg-mute);
|
|
81
|
-
transition: all 0.2s;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
.menuItem,
|
|
85
|
-
.menuItemStatic,
|
|
86
|
-
.menuItemActive {
|
|
87
|
-
font-size: 13px;
|
|
88
|
-
line-height: 19px;
|
|
89
|
-
border-radius: 0 1rem 1rem 0;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
.menuItem,
|
|
93
|
-
.menuItemStatic {
|
|
94
|
-
color: var(--rp-c-text-2);
|
|
95
|
-
transition: color 0.2s;
|
|
96
|
-
font-weight: 500;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
.menuItemActive {
|
|
100
|
-
background-color: var(--rp-c-brand-tint);
|
|
101
|
-
color: var(--rp-c-brand);
|
|
102
|
-
font-weight: bolder;
|
|
103
|
-
position: relative;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
.menuItemActive::before {
|
|
107
|
-
content: '';
|
|
108
|
-
position: absolute;
|
|
109
|
-
top: 0;
|
|
110
|
-
left: 0;
|
|
111
|
-
width: 1px;
|
|
112
|
-
height: 100%;
|
|
113
|
-
background-color: var(--rp-c-brand);
|
|
114
|
-
transition: all 0.2s ease;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
.menuGroupActive {
|
|
118
|
-
background-color: var(--rp-c-bg-mute);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
:global(.rspress-sidebar-group) {
|
|
122
|
-
position: relative;
|
|
123
|
-
&::before {
|
|
124
|
-
content: '';
|
|
125
|
-
position: absolute;
|
|
126
|
-
top: 0;
|
|
127
|
-
left: 18px;
|
|
128
|
-
width: 1px;
|
|
129
|
-
height: 100%;
|
|
130
|
-
background-color: var(--rp-c-gray-light-4);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
:global(.dark) {
|
|
135
|
-
:global(.rspress-sidebar-group)::before {
|
|
136
|
-
background-color: var(--rp-c-bg-mute);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
.sidebar {
|
|
140
|
-
box-shadow: var(--rp-shadow-1);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
NormalizedSidebarGroup,
|
|
4
|
-
SidebarItem as ISidebarItem,
|
|
5
|
-
normalizeSlash,
|
|
6
|
-
} from '@rspress/shared';
|
|
7
|
-
import { routes } from 'virtual-routes';
|
|
8
|
-
import {
|
|
9
|
-
isActive,
|
|
10
|
-
useDisableNav,
|
|
11
|
-
useLocaleSiteData,
|
|
12
|
-
useSidebarData,
|
|
13
|
-
} from '../../logic';
|
|
14
|
-
import { NavBarTitle } from '../Nav/NavBarTitle';
|
|
15
|
-
import styles from './index.module.scss';
|
|
16
|
-
import { SidebarItem } from './SidebarItem';
|
|
17
|
-
import { matchRoutes, useLocation, removeBase } from '@/runtime';
|
|
18
|
-
|
|
19
|
-
export interface SidebarItemProps {
|
|
20
|
-
id: string;
|
|
21
|
-
item: ISidebarItem | NormalizedSidebarGroup;
|
|
22
|
-
depth: number;
|
|
23
|
-
activeMatcher: (link: string) => boolean;
|
|
24
|
-
collapsed?: boolean;
|
|
25
|
-
setSidebarData: React.Dispatch<
|
|
26
|
-
React.SetStateAction<(NormalizedSidebarGroup | ISidebarItem)[]>
|
|
27
|
-
>;
|
|
28
|
-
preloadLink: (link: string) => void;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
interface Props {
|
|
32
|
-
isSidebarOpen?: boolean;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const highlightTitleStyle = {
|
|
36
|
-
color: 'var(--rp-c-text-1)',
|
|
37
|
-
fontSize: '14px',
|
|
38
|
-
paddingLeft: '24px',
|
|
39
|
-
fontWeight: 'bold',
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// Note: the cache object won't be reassign in other module
|
|
43
|
-
// eslint-disable-next-line import/no-mutable-exports
|
|
44
|
-
export let matchCache: WeakMap<NormalizedSidebarGroup | ISidebarItem, boolean> =
|
|
45
|
-
new WeakMap();
|
|
46
|
-
|
|
47
|
-
export function SideBar(props: Props) {
|
|
48
|
-
const { isSidebarOpen } = props;
|
|
49
|
-
const { items: rawSidebarData } = useSidebarData();
|
|
50
|
-
const localesData = useLocaleSiteData();
|
|
51
|
-
const { pathname: rawPathname } = useLocation();
|
|
52
|
-
|
|
53
|
-
const langRoutePrefix = normalizeSlash(localesData.langRoutePrefix || '');
|
|
54
|
-
const [hideNavbar] = useDisableNav();
|
|
55
|
-
const [sidebarData, setSidebarData] = useState<
|
|
56
|
-
(ISidebarItem | NormalizedSidebarGroup)[]
|
|
57
|
-
>(rawSidebarData.filter(Boolean).flat());
|
|
58
|
-
const pathname = decodeURIComponent(rawPathname);
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
if (rawSidebarData === sidebarData) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
// 1. Update sidebarData when pathname changes
|
|
64
|
-
// 2. For current active item, expand its parent group
|
|
65
|
-
// Cache, Avoid redundant calculation
|
|
66
|
-
matchCache = new WeakMap<NormalizedSidebarGroup | ISidebarItem, boolean>();
|
|
67
|
-
const match = (item: NormalizedSidebarGroup | ISidebarItem) => {
|
|
68
|
-
if (matchCache.has(item)) {
|
|
69
|
-
return matchCache.get(item);
|
|
70
|
-
}
|
|
71
|
-
if (item.link && activeMatcher(item.link)) {
|
|
72
|
-
matchCache.set(item, true);
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
if ('items' in item) {
|
|
76
|
-
const result = item.items.some(child => match(child));
|
|
77
|
-
if (result) {
|
|
78
|
-
matchCache.set(item, true);
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
matchCache.set(item, false);
|
|
83
|
-
return false;
|
|
84
|
-
};
|
|
85
|
-
const traverse = (item: NormalizedSidebarGroup | ISidebarItem) => {
|
|
86
|
-
if ('items' in item) {
|
|
87
|
-
item.items.forEach(traverse);
|
|
88
|
-
if (match(item)) {
|
|
89
|
-
item.collapsed = false;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
const newSidebarData = rawSidebarData.filter(Boolean).flat();
|
|
94
|
-
newSidebarData.forEach(traverse);
|
|
95
|
-
setSidebarData(newSidebarData);
|
|
96
|
-
}, [rawSidebarData, pathname]);
|
|
97
|
-
|
|
98
|
-
const removeLangPrefix = (path: string) => {
|
|
99
|
-
return path.replace(langRoutePrefix, '');
|
|
100
|
-
};
|
|
101
|
-
const activeMatcher = (path: string) =>
|
|
102
|
-
isActive(
|
|
103
|
-
removeBase(removeLangPrefix(pathname)),
|
|
104
|
-
removeLangPrefix(path),
|
|
105
|
-
true,
|
|
106
|
-
);
|
|
107
|
-
const preloadLink = (link: string) => {
|
|
108
|
-
const match = matchRoutes(routes, link);
|
|
109
|
-
if (match?.length) {
|
|
110
|
-
const { route } = match[0];
|
|
111
|
-
route.preload();
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
return (
|
|
115
|
-
<aside
|
|
116
|
-
className={`${styles.sidebar} rspress-sidebar ${
|
|
117
|
-
isSidebarOpen ? styles.open : ''
|
|
118
|
-
}`}
|
|
119
|
-
>
|
|
120
|
-
{hideNavbar ? null : (
|
|
121
|
-
<div className={styles.navTitleMask}>
|
|
122
|
-
<NavBarTitle />
|
|
123
|
-
</div>
|
|
124
|
-
)}
|
|
125
|
-
|
|
126
|
-
<div className={`mt-1 ${styles.sidebarContent}`}>
|
|
127
|
-
<div
|
|
128
|
-
className="rspress-scrollbar"
|
|
129
|
-
style={{
|
|
130
|
-
maxHeight: 'calc(100vh - var(--rp-nav-height) - 8px)',
|
|
131
|
-
overflow: 'scroll',
|
|
132
|
-
}}
|
|
133
|
-
>
|
|
134
|
-
<nav className="pb-2">
|
|
135
|
-
{sidebarData.map(
|
|
136
|
-
(item: NormalizedSidebarGroup | ISidebarItem, index: number) => (
|
|
137
|
-
<SidebarItem
|
|
138
|
-
id={String(index)}
|
|
139
|
-
item={item}
|
|
140
|
-
depth={0}
|
|
141
|
-
activeMatcher={activeMatcher}
|
|
142
|
-
// The siderbarData is stable, so it's safe to use index as key
|
|
143
|
-
// eslint-disable-next-line react/no-array-index-key
|
|
144
|
-
key={index}
|
|
145
|
-
collapsed={(item as NormalizedSidebarGroup).collapsed ?? true}
|
|
146
|
-
setSidebarData={setSidebarData}
|
|
147
|
-
preloadLink={preloadLink}
|
|
148
|
-
/>
|
|
149
|
-
),
|
|
150
|
-
)}
|
|
151
|
-
</nav>
|
|
152
|
-
</div>
|
|
153
|
-
</div>
|
|
154
|
-
</aside>
|
|
155
|
-
);
|
|
156
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { SocialLink } from '@rspress/shared';
|
|
2
|
-
import { LinkContent } from './LinkContent';
|
|
3
|
-
|
|
4
|
-
interface IHiddenLinksProps {
|
|
5
|
-
links: SocialLink[];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const HiddenLinks = (props: IHiddenLinksProps) => {
|
|
9
|
-
const { links } = props;
|
|
10
|
-
|
|
11
|
-
return (
|
|
12
|
-
<div
|
|
13
|
-
style={{
|
|
14
|
-
boxShadow: 'var(--rp-shadow-3)',
|
|
15
|
-
marginRight: '-2px',
|
|
16
|
-
border: '1px solid var(--rp-c-divider-light)',
|
|
17
|
-
background: 'var(--rp-c-bg)',
|
|
18
|
-
}}
|
|
19
|
-
className="absolute top-8 right-0 z-1 p-3 w-32 rounded-2xl flex flex-wrap gap-4"
|
|
20
|
-
>
|
|
21
|
-
{links.map(item => (
|
|
22
|
-
<LinkContent
|
|
23
|
-
key={item.content}
|
|
24
|
-
link={item}
|
|
25
|
-
popperStyle={{ top: '1.25rem' }}
|
|
26
|
-
/>
|
|
27
|
-
))}
|
|
28
|
-
</div>
|
|
29
|
-
);
|
|
30
|
-
};
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
import { SocialLink } from '@rspress/shared';
|
|
3
|
-
import styles from './index.module.scss';
|
|
4
|
-
import presetIcons from './presetIcons';
|
|
5
|
-
|
|
6
|
-
interface ILinkContentComp {
|
|
7
|
-
link: SocialLink;
|
|
8
|
-
popperStyle?: Record<string, unknown>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const LinkContent = (props: ILinkContentComp) => {
|
|
12
|
-
const { link, popperStyle = {} } = props;
|
|
13
|
-
const { icon, mode = 'link', content } = link;
|
|
14
|
-
const IconComp =
|
|
15
|
-
typeof icon === 'object' ? (
|
|
16
|
-
// eslint-disable-next-line react/no-danger
|
|
17
|
-
<div dangerouslySetInnerHTML={{ __html: icon.svg }}></div>
|
|
18
|
-
) : (
|
|
19
|
-
presetIcons[icon as keyof typeof presetIcons]
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
const [contentVisible, setContentVisible] = useState(false);
|
|
23
|
-
const mouseEnterIcon = () => {
|
|
24
|
-
setContentVisible(true);
|
|
25
|
-
};
|
|
26
|
-
const mouseLeavePopper = () => {
|
|
27
|
-
setContentVisible(false);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
if (mode === 'link') {
|
|
31
|
-
return (
|
|
32
|
-
<a
|
|
33
|
-
key={content}
|
|
34
|
-
href={content}
|
|
35
|
-
target="_blank"
|
|
36
|
-
rel="noopener noreferrer"
|
|
37
|
-
className="social-links"
|
|
38
|
-
>
|
|
39
|
-
<div className={`${styles.socialLinksIcon}`}>{IconComp}</div>
|
|
40
|
-
</a>
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
if (mode === 'text') {
|
|
44
|
-
return (
|
|
45
|
-
<div
|
|
46
|
-
className={`${styles.socialLinksIcon} cursor-pointer relative mx-3`}
|
|
47
|
-
onMouseEnter={mouseEnterIcon}
|
|
48
|
-
onMouseLeave={mouseLeavePopper}
|
|
49
|
-
>
|
|
50
|
-
{IconComp}
|
|
51
|
-
{contentVisible ? (
|
|
52
|
-
<div
|
|
53
|
-
style={{
|
|
54
|
-
boxShadow: 'var(--rp-shadow-3)',
|
|
55
|
-
border: '1px solid var(--rp-c-divider-light)',
|
|
56
|
-
...popperStyle,
|
|
57
|
-
}}
|
|
58
|
-
className="z-[1] p-3 w-50 absolute right-0 bg-white dark:bg-dark"
|
|
59
|
-
>
|
|
60
|
-
<div className="text-md">{content}</div>
|
|
61
|
-
</div>
|
|
62
|
-
) : null}
|
|
63
|
-
</div>
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
if (mode === 'img') {
|
|
67
|
-
return (
|
|
68
|
-
<div
|
|
69
|
-
className={`${styles.socialLinksIcon} cursor-pointer relative`}
|
|
70
|
-
onMouseEnter={mouseEnterIcon}
|
|
71
|
-
onMouseLeave={mouseLeavePopper}
|
|
72
|
-
>
|
|
73
|
-
{IconComp}
|
|
74
|
-
{contentVisible ? (
|
|
75
|
-
<div
|
|
76
|
-
className="break-all z-[1] p-3 w-[50px] h-[50px] absolute right-0 bg-white dark:bg-dark rounded-xl"
|
|
77
|
-
style={{
|
|
78
|
-
boxShadow: 'var(--rp-shadow-3)',
|
|
79
|
-
...popperStyle,
|
|
80
|
-
}}
|
|
81
|
-
>
|
|
82
|
-
<img src={content} alt="img" />
|
|
83
|
-
</div>
|
|
84
|
-
) : null}
|
|
85
|
-
</div>
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return <div></div>;
|
|
90
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { SocialLink } from '@rspress/shared';
|
|
2
|
-
import ArrowDown from '../../assets/arrow-down.svg';
|
|
3
|
-
import { LinkContent } from './LinkContent';
|
|
4
|
-
|
|
5
|
-
interface IShownLinksProps {
|
|
6
|
-
links: SocialLink[];
|
|
7
|
-
moreIconVisible?: boolean;
|
|
8
|
-
mouseEnter: () => void;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const ShownLinks = (props: IShownLinksProps) => {
|
|
12
|
-
const { links, moreIconVisible = false, mouseEnter } = props;
|
|
13
|
-
|
|
14
|
-
return (
|
|
15
|
-
<>
|
|
16
|
-
<div className="flex-center h-full gap-x-4 transition-colors duration-300 md:mr-2">
|
|
17
|
-
{links.map((item, index) => (
|
|
18
|
-
<LinkContent
|
|
19
|
-
key={index}
|
|
20
|
-
link={item}
|
|
21
|
-
popperStyle={{ top: '2.5rem' }}
|
|
22
|
-
/>
|
|
23
|
-
))}
|
|
24
|
-
</div>
|
|
25
|
-
{moreIconVisible ? (
|
|
26
|
-
<div className="md:ml-1 p-2" onMouseEnter={mouseEnter}>
|
|
27
|
-
<ArrowDown />
|
|
28
|
-
</div>
|
|
29
|
-
) : null}
|
|
30
|
-
</>
|
|
31
|
-
);
|
|
32
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
.social-links-icon {
|
|
2
|
-
width: 24px;
|
|
3
|
-
height: 100%;
|
|
4
|
-
display: flex;
|
|
5
|
-
fill: currentColor;
|
|
6
|
-
margin-left: 0.5rem;
|
|
7
|
-
color: var(--rp-c-text-2);
|
|
8
|
-
|
|
9
|
-
&:hover {
|
|
10
|
-
color: var(--rp-c-text-1);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
@media (max-width: 768px) {
|
|
15
|
-
.menu-item:before {
|
|
16
|
-
display: none;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
import { SocialLink } from '@rspress/shared';
|
|
3
|
-
import { ShownLinks } from './ShownLinks';
|
|
4
|
-
import { HiddenLinks } from './HiddenLinks';
|
|
5
|
-
import styles from './index.module.scss';
|
|
6
|
-
|
|
7
|
-
export const SocialLinks = ({ socialLinks }: { socialLinks: SocialLink[] }) => {
|
|
8
|
-
const moreThanThree = socialLinks.length > 3;
|
|
9
|
-
|
|
10
|
-
const shownLinks: SocialLink[] = [];
|
|
11
|
-
const hiddenLinks: SocialLink[] = [];
|
|
12
|
-
|
|
13
|
-
socialLinks.forEach((item, index) => {
|
|
14
|
-
if (index < 3) {
|
|
15
|
-
shownLinks.push(item);
|
|
16
|
-
} else {
|
|
17
|
-
hiddenLinks.push(item);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const [moreLinksVisible, setMoreLinksVisible] = useState(false);
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<div
|
|
25
|
-
className={`social-links ${styles.menuItem} flex-center relative`}
|
|
26
|
-
onMouseLeave={() => setMoreLinksVisible(false)}
|
|
27
|
-
>
|
|
28
|
-
<ShownLinks
|
|
29
|
-
links={shownLinks}
|
|
30
|
-
moreIconVisible={moreThanThree}
|
|
31
|
-
mouseEnter={() => setMoreLinksVisible(true)}
|
|
32
|
-
/>
|
|
33
|
-
{moreLinksVisible ? <HiddenLinks links={hiddenLinks} /> : null}
|
|
34
|
-
</div>
|
|
35
|
-
);
|
|
36
|
-
};
|