@rspress/core 0.1.1 → 1.0.0-beta.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.js +62 -24
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +17 -33
- package/dist/loader.js.map +1 -1
- package/dist/runtime/App.js +4 -4
- package/dist/runtime/Content.js +14 -2
- package/dist/runtime/hooks.d.ts +17 -0
- package/dist/runtime/hooks.js +27 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/utils.d.ts +3 -2
- package/dist/runtime/utils.js +6 -2
- package/dist/theme/bundle.css +44 -4
- package/dist/theme/bundle.d.ts +6 -1
- package/dist/theme/bundle.js +150 -77
- package/dist/theme/bundle.js.map +1 -1
- package/package.json +7 -7
- package/src/runtime/App.tsx +5 -6
- package/src/runtime/Content.tsx +24 -2
- package/src/runtime/global.d.ts +4 -5
- package/src/runtime/hooks.ts +67 -1
- package/src/runtime/index.ts +1 -1
- package/src/runtime/utils.ts +9 -8
- package/src/theme-default/components/DocFooter/index.tsx +1 -1
- package/src/theme-default/components/HomeHero/index.tsx +1 -1
- package/src/theme-default/components/Link/index.module.scss +0 -1
- package/src/theme-default/components/Link/index.tsx +21 -2
- package/src/theme-default/components/Nav/NavMenuSingleItem.tsx +1 -1
- package/src/theme-default/components/Nav/index.tsx +19 -5
- package/src/theme-default/components/Overview/index.tsx +1 -1
- package/src/theme-default/components/Search/logic/search.ts +1 -1
- package/src/theme-default/components/Sidebar/SidebarGroup.tsx +1 -1
- package/src/theme-default/components/Sidebar/SidebarItem.tsx +1 -1
- package/src/theme-default/index.ts +2 -0
- package/src/theme-default/layout/DocLayout/docComponents/index.module.scss +4 -0
- package/src/theme-default/layout/DocLayout/docComponents/link.tsx +14 -23
- package/src/theme-default/layout/DocLayout/index.module.scss +46 -0
- package/src/theme-default/layout/HomeLayout/index.tsx +1 -0
- package/src/theme-default/logic/index.ts +1 -0
- package/src/theme-default/logic/sideEffects.ts +7 -0
- package/src/theme-default/logic/usePathUtils.ts +73 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
4
|
"description": "The Rspress Documentation Framework",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@mdx-js/react": "2.2.1",
|
|
43
43
|
"@modern-js/builder": "2.35.1",
|
|
44
44
|
"@modern-js/builder-rspack-provider": "2.35.1",
|
|
45
|
-
"@rspress/mdx-rs": "0.3.
|
|
45
|
+
"@rspress/mdx-rs": "0.3.2",
|
|
46
46
|
"@modern-js/utils": "2.35.1",
|
|
47
47
|
"@types/compression": "^1.7.2",
|
|
48
48
|
"@types/polka": "^0.5.4",
|
|
@@ -89,11 +89,11 @@
|
|
|
89
89
|
"unist-util-visit-children": "^2.0.1",
|
|
90
90
|
"yaml-front-matter": "^4.1.1",
|
|
91
91
|
"rspack-plugin-virtual-module": "0.1.12",
|
|
92
|
-
"@rspress/shared": "0.
|
|
93
|
-
"@rspress/plugin-medium-zoom": "0.
|
|
94
|
-
"@rspress/plugin-last-updated": "0.
|
|
95
|
-
"@rspress/plugin-auto-nav-sidebar": "0.
|
|
96
|
-
"@rspress/plugin-container-syntax": "0.
|
|
92
|
+
"@rspress/shared": "1.0.0-beta.0",
|
|
93
|
+
"@rspress/plugin-medium-zoom": "1.0.0-beta.0",
|
|
94
|
+
"@rspress/plugin-last-updated": "1.0.0-beta.0",
|
|
95
|
+
"@rspress/plugin-auto-nav-sidebar": "1.0.0-beta.0",
|
|
96
|
+
"@rspress/plugin-container-syntax": "1.0.0-beta.0"
|
|
97
97
|
},
|
|
98
98
|
"peerDependencies": {
|
|
99
99
|
"react": ">=17"
|
package/src/runtime/App.tsx
CHANGED
|
@@ -15,7 +15,6 @@ type RspressPageMeta = Record<
|
|
|
15
15
|
{
|
|
16
16
|
title: string;
|
|
17
17
|
toc: Header[];
|
|
18
|
-
frontmatter: Record<string, any>;
|
|
19
18
|
}
|
|
20
19
|
>;
|
|
21
20
|
|
|
@@ -44,12 +43,11 @@ export async function initPageData(routePath: string): Promise<PageData> {
|
|
|
44
43
|
toc = [],
|
|
45
44
|
// eslint-disable-next-line prefer-const
|
|
46
45
|
title = '',
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
] || {};
|
|
46
|
+
} =
|
|
47
|
+
(mod.default.__RSPRESS_PAGE_META as RspressPageMeta)?.[encodedPagePath] ||
|
|
48
|
+
{};
|
|
51
49
|
|
|
52
|
-
frontmatter =
|
|
50
|
+
const frontmatter = mod.frontmatter || {};
|
|
53
51
|
|
|
54
52
|
return {
|
|
55
53
|
siteData,
|
|
@@ -80,6 +78,7 @@ export async function initPageData(routePath: string): Promise<PageData> {
|
|
|
80
78
|
frontmatter: {},
|
|
81
79
|
title: '404',
|
|
82
80
|
toc: [],
|
|
81
|
+
version: '',
|
|
83
82
|
_filepath: '',
|
|
84
83
|
_relativePath: '',
|
|
85
84
|
},
|
package/src/runtime/Content.tsx
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
|
-
import { ReactNode, Suspense } from 'react';
|
|
1
|
+
import { ReactNode, Suspense, memo, ReactElement } from 'react';
|
|
2
2
|
import { matchRoutes, useLocation } from 'react-router-dom';
|
|
3
|
+
import siteData from 'virtual-site-data';
|
|
3
4
|
import { normalizeRoutePath } from './utils';
|
|
5
|
+
import { useViewTransition } from './hooks';
|
|
4
6
|
|
|
5
7
|
const { routes } = process.env.__SSR__
|
|
6
8
|
? (require('virtual-routes-ssr') as typeof import('virtual-routes-ssr'))
|
|
7
9
|
: (require('virtual-routes') as typeof import('virtual-routes'));
|
|
8
10
|
|
|
11
|
+
function TransitionContentImpl(props: { el: ReactElement }) {
|
|
12
|
+
let element = props.el;
|
|
13
|
+
if (siteData?.themeConfig?.enableContentAnimation) {
|
|
14
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
15
|
+
element = useViewTransition(props.el);
|
|
16
|
+
}
|
|
17
|
+
return element;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const TransitionContent = memo(
|
|
21
|
+
TransitionContentImpl,
|
|
22
|
+
(prevProps, nextProps) => prevProps.el === nextProps.el,
|
|
23
|
+
);
|
|
24
|
+
|
|
9
25
|
export const Content = ({ fallback = <></> }: { fallback?: ReactNode }) => {
|
|
10
26
|
const { pathname } = useLocation();
|
|
11
27
|
const matched = matchRoutes(routes, normalizeRoutePath(pathname));
|
|
@@ -13,9 +29,15 @@ export const Content = ({ fallback = <></> }: { fallback?: ReactNode }) => {
|
|
|
13
29
|
return <div></div>;
|
|
14
30
|
}
|
|
15
31
|
const routesElement = matched[0].route.element;
|
|
32
|
+
|
|
16
33
|
// React 17 Suspense SSR is not supported
|
|
17
34
|
if (!process.env.__IS_REACT_18__ && process.env.__SSR__) {
|
|
18
35
|
return routesElement;
|
|
19
36
|
}
|
|
20
|
-
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<Suspense fallback={fallback}>
|
|
40
|
+
<TransitionContent el={routesElement} />
|
|
41
|
+
</Suspense>
|
|
42
|
+
);
|
|
21
43
|
};
|
package/src/runtime/global.d.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
declare module 'virtual-routes' {
|
|
2
|
-
export { Route } from '
|
|
2
|
+
export { Route } from '@rspress/shared';
|
|
3
3
|
|
|
4
4
|
export const routes: Route[];
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
declare module 'virtual-routes-ssr' {
|
|
8
|
-
export { Route } from '
|
|
8
|
+
export { Route } from '@rspress/shared';
|
|
9
9
|
|
|
10
10
|
export const routes: Route[];
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
declare module 'virtual-site-data' {
|
|
14
|
-
import { SiteData } from 'shared
|
|
15
|
-
import ThemeConfig from 'shared/types/defaultTheme';
|
|
14
|
+
import { SiteData, DefaultThemeConfig } from '@rspress/shared';
|
|
16
15
|
|
|
17
|
-
const data: SiteData<
|
|
16
|
+
const data: SiteData<DefaultThemeConfig>;
|
|
18
17
|
export default data;
|
|
19
18
|
}
|
|
20
19
|
|
package/src/runtime/hooks.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { createContext, useContext } from 'react';
|
|
1
|
+
import { createContext, useContext, useLayoutEffect, useState } from 'react';
|
|
2
2
|
import { PageData } from '@rspress/shared';
|
|
3
3
|
import i18nTextData from 'virtual-i18n-text';
|
|
4
|
+
import { flushSync } from 'react-dom';
|
|
4
5
|
|
|
5
6
|
// Type shim for window.__EDEN_PAGE_DATA__
|
|
6
7
|
declare global {
|
|
@@ -32,6 +33,11 @@ export function useLang(): string {
|
|
|
32
33
|
return ctx.data.page.lang || '';
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
export function useVersion(): string {
|
|
37
|
+
const ctx = useContext(DataContext);
|
|
38
|
+
return ctx.data.page.version || '';
|
|
39
|
+
}
|
|
40
|
+
|
|
35
41
|
export function useDark() {
|
|
36
42
|
const ctx = useContext(ThemeContext);
|
|
37
43
|
return ctx.theme === 'dark';
|
|
@@ -42,3 +48,63 @@ export function useI18n<T = Record<string, Record<string, string>>>() {
|
|
|
42
48
|
|
|
43
49
|
return (key: keyof T) => i18nTextData[key][lang];
|
|
44
50
|
}
|
|
51
|
+
|
|
52
|
+
declare global {
|
|
53
|
+
interface Document {
|
|
54
|
+
startViewTransition: (callback: () => void) => void;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* There is a pitfall.
|
|
60
|
+
* I was working on the navigation between pages with hash. eg. from `guide/start` -> `config/repress#nav`
|
|
61
|
+
* I need a time to dispatch an event so that the sideEffect.ts would know that
|
|
62
|
+
* the dom is attached to the browser. Otherwise the scroll position and the
|
|
63
|
+
* animation would be incorrect. You can search for `RspressReloadContent` in this codebase
|
|
64
|
+
* to findout the logic that are consuming the event.
|
|
65
|
+
* The reason I didn't write it here is that I hope the logic of handling scroll and position
|
|
66
|
+
* could be in one place so that people wouldn't be confused.
|
|
67
|
+
*/
|
|
68
|
+
export function useViewTransition(dom) {
|
|
69
|
+
/**
|
|
70
|
+
* use a pesudo element to hold the actual JSX element so we can schedule the
|
|
71
|
+
* update later in sync
|
|
72
|
+
*/
|
|
73
|
+
const [element, setElement] = useState(dom);
|
|
74
|
+
|
|
75
|
+
useLayoutEffect(() => {
|
|
76
|
+
if (document.startViewTransition && element !== dom) {
|
|
77
|
+
/**
|
|
78
|
+
* the browser will take a screenshot here
|
|
79
|
+
*/
|
|
80
|
+
document.startViewTransition(() => {
|
|
81
|
+
/**
|
|
82
|
+
* react will batch all the updates in callback and flush it sync
|
|
83
|
+
*/
|
|
84
|
+
flushSync(() => {
|
|
85
|
+
setElement(dom);
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* react flushed the dom to browser
|
|
89
|
+
* and the browser will start the animation
|
|
90
|
+
*/
|
|
91
|
+
/**
|
|
92
|
+
* dispatchEvent for several logic
|
|
93
|
+
*/
|
|
94
|
+
window.dispatchEvent(new Event('RspressReloadContent'));
|
|
95
|
+
});
|
|
96
|
+
} else {
|
|
97
|
+
flushSync(() => {
|
|
98
|
+
setElement(dom);
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* dispatchEvent for several logic
|
|
102
|
+
*/
|
|
103
|
+
window.dispatchEvent(new Event('RspressReloadContent'));
|
|
104
|
+
}
|
|
105
|
+
}, [dom]);
|
|
106
|
+
/**
|
|
107
|
+
* take this element to the actual VDOM tree
|
|
108
|
+
*/
|
|
109
|
+
return element;
|
|
110
|
+
}
|
package/src/runtime/index.ts
CHANGED
package/src/runtime/utils.ts
CHANGED
|
@@ -24,13 +24,14 @@ export function removeBase(url: string): string {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export function isEqualPath(a: string, b: string) {
|
|
27
|
-
return
|
|
27
|
+
return (
|
|
28
|
+
withBase(normalizeHrefInRuntime(a)) === withBase(normalizeHrefInRuntime(b))
|
|
29
|
+
);
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
export {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
32
|
+
export function normalizeHrefInRuntime(a: string) {
|
|
33
|
+
const cleanUrls = Boolean(siteData?.route?.cleanUrls);
|
|
34
|
+
return normalizeHref(a, cleanUrls);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction };
|
|
@@ -2,7 +2,7 @@ import { useLocaleSiteData, usePrevNextPage } from '../../logic';
|
|
|
2
2
|
import EditLink from '../EditLink';
|
|
3
3
|
import { Link } from '../Link';
|
|
4
4
|
import styles from './index.module.scss';
|
|
5
|
-
import { normalizeHref, usePageData } from '@/runtime';
|
|
5
|
+
import { normalizeHrefInRuntime as normalizeHref, usePageData } from '@/runtime';
|
|
6
6
|
|
|
7
7
|
export function DocFooter() {
|
|
8
8
|
const { prevPage, nextPage } = usePrevNextPage();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FrontMatterMeta } from '@rspress/shared';
|
|
2
2
|
import { Button } from '../Button';
|
|
3
3
|
import styles from './index.module.scss';
|
|
4
|
-
import { normalizeHref } from '@/runtime';
|
|
4
|
+
import { normalizeHrefInRuntime as normalizeHref } from '@/runtime';
|
|
5
5
|
|
|
6
6
|
const DEFAULT_HERO = {
|
|
7
7
|
name: 'modern',
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { matchRoutes, useNavigate } from 'react-router-dom';
|
|
2
|
+
import { matchRoutes, useLocation, useNavigate } from 'react-router-dom';
|
|
3
3
|
import nprogress from 'nprogress';
|
|
4
4
|
import { routes } from 'virtual-routes';
|
|
5
5
|
import styles from './index.module.scss';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
normalizeHrefInRuntime as normalizeHref,
|
|
8
|
+
normalizeRoutePath,
|
|
9
|
+
withBase,
|
|
10
|
+
} from '@/runtime';
|
|
11
|
+
import { scrollToTarget } from '@/theme-default/logic';
|
|
7
12
|
|
|
8
13
|
export interface LinkProps {
|
|
9
14
|
href?: string;
|
|
@@ -23,10 +28,23 @@ export function Link(props: LinkProps) {
|
|
|
23
28
|
const rel = isExternal ? 'noopener noreferrer' : undefined;
|
|
24
29
|
const withBaseUrl = isExternal ? href : withBase(normalizeHref(href));
|
|
25
30
|
const navigate = useNavigate();
|
|
31
|
+
const { pathname } = useLocation();
|
|
32
|
+
const inCurrentPage = withBaseUrl.startsWith(pathname);
|
|
26
33
|
const handleNavigate = async (
|
|
27
34
|
e: React.MouseEvent<HTMLAnchorElement, MouseEvent>,
|
|
28
35
|
) => {
|
|
29
36
|
e.preventDefault();
|
|
37
|
+
// handle hash link in current page
|
|
38
|
+
const hash = withBaseUrl.split('#')[1];
|
|
39
|
+
if (!isExternal && inCurrentPage && hash) {
|
|
40
|
+
const el = document.getElementById(hash);
|
|
41
|
+
if (el) {
|
|
42
|
+
scrollToTarget(el, true);
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// handle normal link
|
|
30
48
|
if (!process.env.__SSR__) {
|
|
31
49
|
const matchedRoutes = matchRoutes(
|
|
32
50
|
routes,
|
|
@@ -44,6 +62,7 @@ export function Link(props: LinkProps) {
|
|
|
44
62
|
navigate(withBaseUrl, { replace: false });
|
|
45
63
|
}
|
|
46
64
|
};
|
|
65
|
+
|
|
47
66
|
if (!isExternal) {
|
|
48
67
|
return (
|
|
49
68
|
<a
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
import { Link } from '../Link';
|
|
7
7
|
import { Tag } from '../Tag';
|
|
8
8
|
import styles from './index.module.scss';
|
|
9
|
-
import { normalizeHref } from '@/runtime';
|
|
9
|
+
import { normalizeHrefInRuntime as normalizeHref } from '@/runtime';
|
|
10
10
|
|
|
11
11
|
interface Props {
|
|
12
12
|
pathname: string;
|
|
@@ -9,7 +9,7 @@ import { SwitchAppearance } from '../SwitchAppearance';
|
|
|
9
9
|
import { NavMenuGroup, NavMenuGroupItem } from './NavMenuGroup';
|
|
10
10
|
import { NavMenuSingleItem } from './NavMenuSingleItem';
|
|
11
11
|
import styles from './index.module.scss';
|
|
12
|
-
import { ThemeContext, usePageData, withBase } from '@/runtime';
|
|
12
|
+
import { ThemeContext, usePageData, useVersion, withBase } from '@/runtime';
|
|
13
13
|
|
|
14
14
|
export interface NavProps {
|
|
15
15
|
beforeNav?: React.ReactNode;
|
|
@@ -70,21 +70,35 @@ export function Nav(props: NavProps) {
|
|
|
70
70
|
const { pathname } = useLocation();
|
|
71
71
|
const { theme } = useContext(ThemeContext);
|
|
72
72
|
const localeData = useLocaleSiteData();
|
|
73
|
+
const currentVersion = useVersion();
|
|
73
74
|
const [isMobile, setIsMobile] = useState(false);
|
|
74
75
|
const localeLanguages = Object.values(siteData.themeConfig.locales || {});
|
|
75
76
|
const hasMultiLanguage = localeLanguages.length > 1;
|
|
76
77
|
const socialLinks = siteData.themeConfig.socialLinks || [];
|
|
77
78
|
const hasSocialLinks = socialLinks.length > 0;
|
|
78
|
-
const defaultLang = siteData.lang || '
|
|
79
|
+
const defaultLang = siteData.lang || '';
|
|
80
|
+
const defaultVersion = siteData.multiVersion.default || '';
|
|
79
81
|
const { lang } = page;
|
|
80
|
-
const langs = localeLanguages.map(item => item.lang || '
|
|
82
|
+
const langs = localeLanguages.map(item => item.lang || '') || [];
|
|
81
83
|
const [logo, setLogo] = useState(getLogoUrl(rawLogo, theme));
|
|
82
84
|
|
|
83
85
|
const translationMenuData = hasMultiLanguage
|
|
84
86
|
? {
|
|
85
87
|
items: localeLanguages.map(item => ({
|
|
86
88
|
text: item?.label,
|
|
87
|
-
link: replaceLang(
|
|
89
|
+
link: replaceLang(
|
|
90
|
+
pathname,
|
|
91
|
+
{
|
|
92
|
+
current: lang,
|
|
93
|
+
target: item.lang,
|
|
94
|
+
default: defaultLang,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
current: currentVersion,
|
|
98
|
+
default: defaultVersion,
|
|
99
|
+
},
|
|
100
|
+
base,
|
|
101
|
+
),
|
|
88
102
|
})),
|
|
89
103
|
activeValue: localeLanguages.find(item => lang === item.lang)?.label,
|
|
90
104
|
}
|
|
@@ -173,7 +187,7 @@ export function Nav(props: NavProps) {
|
|
|
173
187
|
};
|
|
174
188
|
return (
|
|
175
189
|
<header
|
|
176
|
-
className=
|
|
190
|
+
className="top-0 left-0 md:fixed w-full"
|
|
177
191
|
style={{
|
|
178
192
|
zIndex: 'var(--rp-z-index-nav)',
|
|
179
193
|
background: 'var(--rp-c-bg)',
|
|
@@ -3,7 +3,7 @@ import { Header, NormalizedSidebarGroup, SidebarItem } from '@rspress/shared';
|
|
|
3
3
|
import { useSidebarData } from '../../logic';
|
|
4
4
|
import { Link } from '../Link';
|
|
5
5
|
import styles from './index.module.scss';
|
|
6
|
-
import { usePageData, normalizeHref, withBase, isEqualPath } from '@/runtime';
|
|
6
|
+
import { usePageData, normalizeHrefInRuntime as normalizeHref, withBase, isEqualPath } from '@/runtime';
|
|
7
7
|
|
|
8
8
|
interface GroupItem {
|
|
9
9
|
text?: string;
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from './util';
|
|
14
14
|
import { LocalProvider } from './providers/LocalProvider';
|
|
15
15
|
import { RemoteProvider } from './providers/RemoteProvider';
|
|
16
|
-
import { normalizeHref } from '@/runtime';
|
|
16
|
+
import { normalizeHrefInRuntime as normalizeHref } from '@/runtime';
|
|
17
17
|
|
|
18
18
|
const THRESHOLD_CONTENT_LENGTH = 100;
|
|
19
19
|
|
|
@@ -6,7 +6,7 @@ import { Tag } from '../Tag';
|
|
|
6
6
|
import styles from './index.module.scss';
|
|
7
7
|
import { SidebarItem } from './SidebarItem';
|
|
8
8
|
import { highlightTitleStyle, matchCache, type SidebarItemProps } from '.';
|
|
9
|
-
import { normalizeHref, withBase } from '@/runtime';
|
|
9
|
+
import { normalizeHrefInRuntime as normalizeHref, withBase } from '@/runtime';
|
|
10
10
|
|
|
11
11
|
export function SidebarGroup(props: SidebarItemProps) {
|
|
12
12
|
const { item, depth = 0, activeMatcher, id, setSidebarData } = props;
|
|
@@ -4,7 +4,7 @@ import { Tag } from '../Tag';
|
|
|
4
4
|
import styles from './index.module.scss';
|
|
5
5
|
import { SidebarGroup } from './SidebarGroup';
|
|
6
6
|
import { SidebarItemProps, highlightTitleStyle } from '.';
|
|
7
|
-
import { normalizeHref } from '@/runtime';
|
|
7
|
+
import { normalizeHrefInRuntime as normalizeHref } from '@/runtime';
|
|
8
8
|
|
|
9
9
|
export function SidebarItem(props: SidebarItemProps) {
|
|
10
10
|
const { item, depth = 0, activeMatcher, id, setSidebarData } = props;
|
|
@@ -1,30 +1,21 @@
|
|
|
1
1
|
import { ComponentProps } from 'react';
|
|
2
|
-
import { isExternalUrl, normalizeHref, normalizeSlash } from '@rspress/shared';
|
|
3
2
|
import styles from './index.module.scss';
|
|
4
|
-
import {
|
|
3
|
+
import { usePathUtils } from '@/theme-default/logic';
|
|
4
|
+
import { Link } from '@/theme-default/components/Link';
|
|
5
5
|
|
|
6
6
|
export const A = (props: ComponentProps<'a'>) => {
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const pageData = usePageData();
|
|
10
|
-
const defaultLang = pageData.siteData.lang;
|
|
7
|
+
const { href = '', className = '' } = props;
|
|
8
|
+
const { normalizeLinkHref } = usePathUtils();
|
|
11
9
|
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
href = normalizeHref(withBase(href || ''));
|
|
10
|
+
if (className.includes('header-anchor')) {
|
|
11
|
+
return <a {...props} className={`${styles.link} ${className}`} />;
|
|
12
|
+
} else {
|
|
13
|
+
return (
|
|
14
|
+
<Link
|
|
15
|
+
{...props}
|
|
16
|
+
className={`${className} ${styles.link} ${styles['inline-link']}`}
|
|
17
|
+
href={normalizeLinkHref(href)}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
25
20
|
}
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<a {...props} className={`${styles.link} ${props.className}`} href={href} />
|
|
29
|
-
);
|
|
30
21
|
};
|
|
@@ -14,6 +14,52 @@
|
|
|
14
14
|
display: none;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
:global(.rspress-doc) {
|
|
18
|
+
min-height: 60vh;
|
|
19
|
+
view-transition-name: flip;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
:global(*) {
|
|
23
|
+
view-transition-name: none;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@keyframes fade-out {
|
|
28
|
+
from {
|
|
29
|
+
opacity: 1;
|
|
30
|
+
}
|
|
31
|
+
to {
|
|
32
|
+
opacity: 0;
|
|
33
|
+
transform: translateY(20px);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@keyframes fade-in {
|
|
38
|
+
from {
|
|
39
|
+
opacity: 0;
|
|
40
|
+
transform: translateY(20px);
|
|
41
|
+
}
|
|
42
|
+
to {
|
|
43
|
+
opacity: 1;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
::view-transition-old(flip),
|
|
48
|
+
::view-transition-new(flip) {
|
|
49
|
+
animation-time: 250ms;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
::view-transition-old(flip) {
|
|
53
|
+
animation-name: fade-out;
|
|
54
|
+
transition-timing-function: cubic-bezier(0, 0, 0.58, 1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
::view-transition-new(flip) {
|
|
58
|
+
animation-name: fade-in;
|
|
59
|
+
animation-delay: 180ms;
|
|
60
|
+
transition-timing-function: cubic-bezier(0.42, 0, 1, 1);
|
|
61
|
+
}
|
|
62
|
+
|
|
17
63
|
@media (max-width: 960px) {
|
|
18
64
|
.docLayout {
|
|
19
65
|
position: relative;
|
|
@@ -3,4 +3,5 @@ export { useEditLink } from './useEditLink';
|
|
|
3
3
|
export { useSidebarData } from './useSidebarData';
|
|
4
4
|
export { useLocaleSiteData } from './useLocaleSiteData';
|
|
5
5
|
export { setup, bindingAsideScroll, scrollToTarget } from './sideEffects';
|
|
6
|
+
export { usePathUtils } from './usePathUtils';
|
|
6
7
|
export * from './utils';
|
|
@@ -63,6 +63,13 @@ function bindingWindowScroll() {
|
|
|
63
63
|
scrollTo(link, hash, true);
|
|
64
64
|
// still emit the event so we can listen to it in themes
|
|
65
65
|
window.dispatchEvent(new Event('hashchange'));
|
|
66
|
+
} else {
|
|
67
|
+
window.addEventListener('RspressReloadContent', () => {
|
|
68
|
+
if (location.hash.length > 1) {
|
|
69
|
+
const ele = document.getElementById(location.hash.slice(1));
|
|
70
|
+
scrollToTarget(ele, false);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
66
73
|
}
|
|
67
74
|
}
|
|
68
75
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { isExternalUrl } from '@rspress/shared';
|
|
2
|
+
import {
|
|
3
|
+
removeBase,
|
|
4
|
+
useLang,
|
|
5
|
+
usePageData,
|
|
6
|
+
normalizeHrefInRuntime as normalizeHref,
|
|
7
|
+
useVersion,
|
|
8
|
+
withBase,
|
|
9
|
+
} from '@/runtime';
|
|
10
|
+
|
|
11
|
+
export function usePathUtils() {
|
|
12
|
+
const currentLang = useLang();
|
|
13
|
+
const currentVersion = useVersion();
|
|
14
|
+
const pageData = usePageData();
|
|
15
|
+
const defaultLang = pageData.siteData.lang;
|
|
16
|
+
const defaultVersion = pageData.siteData.multiVersion.default;
|
|
17
|
+
|
|
18
|
+
const normalizeLinkHref = (rawHref: string) => {
|
|
19
|
+
let href = rawHref;
|
|
20
|
+
if (
|
|
21
|
+
(defaultLang || defaultVersion) &&
|
|
22
|
+
!isExternalUrl(href) &&
|
|
23
|
+
!href.startsWith('#')
|
|
24
|
+
) {
|
|
25
|
+
href = removeBase(href);
|
|
26
|
+
const linkParts = href.split('/').filter(Boolean);
|
|
27
|
+
let versionPart = '';
|
|
28
|
+
let langPart = '';
|
|
29
|
+
let purePathPart = '';
|
|
30
|
+
|
|
31
|
+
// When add the version prefix, the situation is as follows:
|
|
32
|
+
// - current version is not default version
|
|
33
|
+
// - current link does not start with currrent version
|
|
34
|
+
if (defaultVersion) {
|
|
35
|
+
if (currentVersion !== defaultVersion) {
|
|
36
|
+
versionPart = currentVersion;
|
|
37
|
+
|
|
38
|
+
if (linkParts[0] === currentVersion) {
|
|
39
|
+
linkParts.shift();
|
|
40
|
+
}
|
|
41
|
+
} else if (linkParts[0] === defaultVersion) {
|
|
42
|
+
linkParts.shift();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (defaultLang) {
|
|
47
|
+
if (currentLang !== defaultLang) {
|
|
48
|
+
langPart = currentLang;
|
|
49
|
+
|
|
50
|
+
if (linkParts[0] === currentLang) {
|
|
51
|
+
linkParts.shift();
|
|
52
|
+
}
|
|
53
|
+
} else if (linkParts[0] === defaultLang) {
|
|
54
|
+
linkParts.shift();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
purePathPart = linkParts.join('/');
|
|
59
|
+
|
|
60
|
+
return normalizeHref(
|
|
61
|
+
withBase(
|
|
62
|
+
[versionPart, langPart, purePathPart].filter(Boolean).join('/'),
|
|
63
|
+
),
|
|
64
|
+
);
|
|
65
|
+
} else {
|
|
66
|
+
return href;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
normalizeLinkHref,
|
|
72
|
+
};
|
|
73
|
+
}
|