@rspress/runtime 2.0.0-beta.28 → 2.0.0-beta.29
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/hooks/usePage.d.ts +8 -8
- package/dist/hooks/usePage.js +5 -4
- package/dist/hooks/usePageData.d.ts +2 -8
- package/dist/hooks/usePageData.js +14 -5
- package/dist/hooks/usePages.d.ts +4 -0
- package/dist/hooks/usePages.js +7 -0
- package/dist/hooks/useSite.d.ts +2 -1
- package/dist/hooks/useSite.js +2 -3
- package/dist/index.d.ts +6 -5
- package/dist/index.js +5 -4
- package/dist/utils.d.ts +5 -1
- package/dist/utils.js +10 -7
- package/package.json +4 -4
package/dist/hooks/usePage.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import type { PageDataLegacy } from '@rspress/shared';
|
|
2
|
+
interface IPageContext {
|
|
3
|
+
data: PageDataLegacy['page'];
|
|
4
|
+
setData?: (data: PageDataLegacy['page']) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare const PageContext: import("react").Context<IPageContext>;
|
|
1
7
|
export declare function usePage(): {
|
|
2
|
-
page:
|
|
3
|
-
[key: string]: unknown;
|
|
4
|
-
headingTitle?: string;
|
|
5
|
-
pagePath: string;
|
|
6
|
-
lastUpdatedTime?: string;
|
|
7
|
-
description?: string;
|
|
8
|
-
pageType: import("@rspress/shared").PageType;
|
|
9
|
-
};
|
|
8
|
+
page: PageDataLegacy['page'];
|
|
10
9
|
};
|
|
10
|
+
export {};
|
package/dist/hooks/usePage.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
const PageContext = createContext({});
|
|
2
3
|
function usePage() {
|
|
3
|
-
const
|
|
4
|
+
const ctx = useContext(PageContext);
|
|
4
5
|
return {
|
|
5
|
-
page
|
|
6
|
+
page: ctx.data
|
|
6
7
|
};
|
|
7
8
|
}
|
|
8
|
-
export { usePage };
|
|
9
|
+
export { PageContext, usePage };
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
interface IDataContext {
|
|
3
|
-
data: PageData;
|
|
4
|
-
setData?: (data: PageData) => void;
|
|
5
|
-
}
|
|
6
|
-
export declare const DataContext: import("react").Context<IDataContext>;
|
|
1
|
+
import type { PageDataLegacy } from '@rspress/shared';
|
|
7
2
|
/**
|
|
8
3
|
* should use `usePage` and `useSite` instead
|
|
9
4
|
*/
|
|
10
|
-
export declare function usePageData():
|
|
11
|
-
export {};
|
|
5
|
+
export declare function usePageData(): PageDataLegacy;
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { usePage } from "./usePage.js";
|
|
2
|
+
import { usePages } from "./usePages.js";
|
|
3
|
+
import { useSite } from "./useSite.js";
|
|
3
4
|
function usePageData() {
|
|
4
|
-
const
|
|
5
|
-
|
|
5
|
+
const { page } = usePage();
|
|
6
|
+
const { pages } = usePages();
|
|
7
|
+
const { site } = useSite();
|
|
8
|
+
return {
|
|
9
|
+
page,
|
|
10
|
+
siteData: {
|
|
11
|
+
...site,
|
|
12
|
+
pages
|
|
13
|
+
}
|
|
14
|
+
};
|
|
6
15
|
}
|
|
7
|
-
export {
|
|
16
|
+
export { usePageData };
|
package/dist/hooks/useSite.d.ts
CHANGED
package/dist/hooks/useSite.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Head } from '@unhead/react';
|
|
2
|
-
export { createPortal, flushSync
|
|
2
|
+
export { createPortal, flushSync } from 'react-dom';
|
|
3
3
|
export { BrowserRouter, matchPath, matchRoutes, useLocation, useNavigate, useSearchParams, } from 'react-router-dom';
|
|
4
4
|
export { Content } from './Content.js';
|
|
5
5
|
export { ThemeContext, useDark } from './hooks/useDark.js';
|
|
@@ -8,12 +8,13 @@ export { useI18n } from './hooks/useI18n.js';
|
|
|
8
8
|
export { useLang } from './hooks/useLang.js';
|
|
9
9
|
export { useLocaleSiteData } from './hooks/useLocaleSiteData.js';
|
|
10
10
|
export { useNav } from './hooks/useNav.js';
|
|
11
|
-
export { usePage } from './hooks/usePage.js';
|
|
12
|
-
export {
|
|
11
|
+
export { PageContext, usePage } from './hooks/usePage.js';
|
|
12
|
+
export { usePageData } from './hooks/usePageData.js';
|
|
13
|
+
export { usePages } from './hooks/usePages.js';
|
|
13
14
|
export { getSidebarDataGroup, useSidebar } from './hooks/useSidebar.js';
|
|
14
15
|
export { useSite } from './hooks/useSite.js';
|
|
15
16
|
export { useVersion } from './hooks/useVersion.js';
|
|
16
17
|
export { useWindowSize } from './hooks/useWindowSize.js';
|
|
17
18
|
export { NoSSR } from './NoSSR.js';
|
|
18
|
-
export { isActive, pathnameToRouteService
|
|
19
|
-
export { addLeadingSlash, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, normalizeSlash, removeBase, removeTrailingSlash, withBase, } from './utils.js';
|
|
19
|
+
export { isActive, pathnameToRouteService } from './route.js';
|
|
20
|
+
export { addLeadingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, normalizeSlash, removeBase, removeTrailingSlash, withBase, } from './utils.js';
|
package/dist/index.js
CHANGED
|
@@ -8,13 +8,14 @@ import { useI18n } from "./hooks/useI18n.js";
|
|
|
8
8
|
import { useLang } from "./hooks/useLang.js";
|
|
9
9
|
import { useLocaleSiteData } from "./hooks/useLocaleSiteData.js";
|
|
10
10
|
import { useNav } from "./hooks/useNav.js";
|
|
11
|
-
import { usePage } from "./hooks/usePage.js";
|
|
12
|
-
import {
|
|
11
|
+
import { PageContext, usePage } from "./hooks/usePage.js";
|
|
12
|
+
import { usePageData } from "./hooks/usePageData.js";
|
|
13
|
+
import { usePages } from "./hooks/usePages.js";
|
|
13
14
|
import { getSidebarDataGroup, useSidebar } from "./hooks/useSidebar.js";
|
|
14
15
|
import { useSite } from "./hooks/useSite.js";
|
|
15
16
|
import { useVersion } from "./hooks/useVersion.js";
|
|
16
17
|
import { useWindowSize } from "./hooks/useWindowSize.js";
|
|
17
18
|
import { NoSSR } from "./NoSSR.js";
|
|
18
19
|
import { isActive, pathnameToRouteService } from "./route.js";
|
|
19
|
-
import { addLeadingSlash, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, normalizeSlash, removeBase, removeTrailingSlash, withBase } from "./utils.js";
|
|
20
|
-
export { BrowserRouter, Content,
|
|
20
|
+
import { addLeadingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, normalizeSlash, removeBase, removeTrailingSlash, withBase } from "./utils.js";
|
|
21
|
+
export { BrowserRouter, Content, Head, NoSSR, PageContext, ThemeContext, addLeadingSlash, cleanUrlByConfig, createPortal, flushSync, getSidebarDataGroup, isActive, isEqualPath, isProduction, matchPath, matchRoutes, normalizeHrefInRuntime, normalizeImagePath, normalizeSlash, pathnameToRouteService, removeBase, removeTrailingSlash, useDark, useFrontmatter, useI18n, useLang, useLocaleSiteData, useLocation, useNav, useNavigate, usePage, usePageData, usePages, useSearchParams, useSidebar, useSite, useVersion, useWindowSize, withBase };
|
package/dist/utils.d.ts
CHANGED
|
@@ -2,6 +2,10 @@ import { addLeadingSlash, isProduction, normalizeSlash, removeTrailingSlash } fr
|
|
|
2
2
|
export declare function withBase(url?: string): string;
|
|
3
3
|
export declare function removeBase(url: string): string;
|
|
4
4
|
export declare function isEqualPath(a: string, b: string): boolean;
|
|
5
|
-
export declare function normalizeHrefInRuntime(
|
|
5
|
+
export declare function normalizeHrefInRuntime(link: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* we do cleanUrls in runtime side
|
|
8
|
+
*/
|
|
9
|
+
export declare function cleanUrlByConfig(link: string): string;
|
|
6
10
|
export declare function normalizeImagePath(imagePath: string): string;
|
|
7
11
|
export { addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction };
|
package/dist/utils.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { addLeadingSlash, isDataUrl, isExternalUrl, isProduction, normalizeHref, normalizeSlash, removeBase, removeHash, removeTrailingSlash, withBase } from "@rspress/shared";
|
|
2
|
-
import { base } from "virtual-runtime-config";
|
|
3
2
|
import virtual_site_data from "virtual-site-data";
|
|
4
3
|
function utils_withBase(url = '/') {
|
|
5
|
-
return withBase(url, base);
|
|
4
|
+
return withBase(url, virtual_site_data.base);
|
|
6
5
|
}
|
|
7
6
|
function utils_removeBase(url) {
|
|
8
|
-
return removeBase(url, base);
|
|
7
|
+
return removeBase(url, virtual_site_data.base);
|
|
9
8
|
}
|
|
10
9
|
function isEqualPath(a, b) {
|
|
11
|
-
return utils_removeBase(
|
|
10
|
+
return utils_removeBase(normalizeHref(removeHash(a), true)) === utils_removeBase(normalizeHref(removeHash(b), true));
|
|
12
11
|
}
|
|
13
|
-
function normalizeHrefInRuntime(
|
|
12
|
+
function normalizeHrefInRuntime(link) {
|
|
14
13
|
const cleanUrls = Boolean(virtual_site_data?.route?.cleanUrls);
|
|
15
|
-
return normalizeHref(
|
|
14
|
+
return normalizeHref(link, cleanUrls);
|
|
15
|
+
}
|
|
16
|
+
function cleanUrlByConfig(link) {
|
|
17
|
+
if (virtual_site_data?.route?.cleanUrls) return normalizeHref(link, true);
|
|
18
|
+
return link;
|
|
16
19
|
}
|
|
17
20
|
function normalizeImagePath(imagePath) {
|
|
18
21
|
if (isAbsoluteUrl(imagePath)) return imagePath;
|
|
@@ -22,4 +25,4 @@ function normalizeImagePath(imagePath) {
|
|
|
22
25
|
function isAbsoluteUrl(path) {
|
|
23
26
|
return isExternalUrl(path) || isDataUrl(path) || path.startsWith('//');
|
|
24
27
|
}
|
|
25
|
-
export { addLeadingSlash, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, normalizeSlash, utils_removeBase as removeBase, removeTrailingSlash, utils_withBase as withBase };
|
|
28
|
+
export { addLeadingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, normalizeSlash, utils_removeBase as removeBase, removeTrailingSlash, utils_withBase as withBase };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/runtime",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.29",
|
|
4
4
|
"description": "The Runtime of Rspress Documentation Framework",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"react": "^19.1.1",
|
|
38
38
|
"react-dom": "^19.1.1",
|
|
39
39
|
"react-router-dom": "^6.30.1",
|
|
40
|
-
"@rspress/shared": "2.0.0-beta.
|
|
40
|
+
"@rspress/shared": "2.0.0-beta.29"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@rsbuild/plugin-react": "~1.3.5",
|
|
44
|
-
"@rslib/core": "0.12.
|
|
44
|
+
"@rslib/core": "0.12.2",
|
|
45
45
|
"@types/jest": "~29.5.14",
|
|
46
|
-
"@types/react": "^19.1.
|
|
46
|
+
"@types/react": "^19.1.11",
|
|
47
47
|
"@types/react-dom": "^19.1.7",
|
|
48
48
|
"rsbuild-plugin-publint": "^0.3.3",
|
|
49
49
|
"typescript": "^5.8.2",
|