@rspress/runtime 2.0.0-beta.11 → 2.0.0-beta.13
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/Content.js +14 -14
- package/dist/NoSSR.js +5 -5
- package/dist/hooks.js +16 -16
- package/dist/index.js +9 -40
- package/dist/route.js +3 -3
- package/dist/utils.js +13 -17
- package/package.json +4 -4
package/dist/Content.js
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import
|
6
|
-
import
|
1
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
2
|
+
import { Suspense, memo, useMemo } from "react";
|
3
|
+
import { useLocation } from "react-router-dom";
|
4
|
+
import external_virtual_site_data_default from "virtual-site-data";
|
5
|
+
import { useViewTransition } from "./hooks.js";
|
6
|
+
import { pathnameToRouteService } from "./route.js";
|
7
7
|
function TransitionContentImpl(props) {
|
8
8
|
let element = props.el;
|
9
|
-
if (
|
9
|
+
if (external_virtual_site_data_default?.themeConfig?.enableContentAnimation) element = useViewTransition(props.el);
|
10
10
|
return element;
|
11
11
|
}
|
12
|
-
const TransitionContent = /*#__PURE__*/
|
13
|
-
const Content = ({ fallback = /*#__PURE__*/
|
14
|
-
const { pathname } =
|
15
|
-
const matchedElement =
|
16
|
-
const route =
|
12
|
+
const TransitionContent = /*#__PURE__*/ memo(TransitionContentImpl, (prevProps, nextProps)=>prevProps.el === nextProps.el);
|
13
|
+
const Content = ({ fallback = /*#__PURE__*/ jsx(Fragment, {}) })=>{
|
14
|
+
const { pathname } = useLocation();
|
15
|
+
const matchedElement = useMemo(()=>{
|
16
|
+
const route = pathnameToRouteService(pathname);
|
17
17
|
return route?.element;
|
18
18
|
}, [
|
19
19
|
pathname
|
20
20
|
]);
|
21
|
-
return /*#__PURE__*/
|
21
|
+
return /*#__PURE__*/ jsx(Suspense, {
|
22
22
|
fallback: fallback,
|
23
|
-
children: /*#__PURE__*/
|
23
|
+
children: /*#__PURE__*/ jsx(TransitionContent, {
|
24
24
|
el: matchedElement
|
25
25
|
})
|
26
26
|
});
|
package/dist/NoSSR.js
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
import
|
2
|
-
import
|
1
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
2
|
+
import { useEffect, useState } from "react";
|
3
3
|
function NoSSR(props) {
|
4
4
|
const { children } = props;
|
5
|
-
const [isMounted, setIsMounted] =
|
6
|
-
|
5
|
+
const [isMounted, setIsMounted] = useState(false);
|
6
|
+
useEffect(()=>{
|
7
7
|
setIsMounted(true);
|
8
8
|
}, []);
|
9
9
|
if (!isMounted) return null;
|
10
|
-
return /*#__PURE__*/
|
10
|
+
return /*#__PURE__*/ jsx(Fragment, {
|
11
11
|
children: children
|
12
12
|
});
|
13
13
|
}
|
package/dist/hooks.js
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import
|
4
|
-
const DataContext =
|
5
|
-
const ThemeContext =
|
1
|
+
import { createContext, useCallback, useContext, useLayoutEffect, useState } from "react";
|
2
|
+
import { flushSync } from "react-dom";
|
3
|
+
import external_virtual_i18n_text_default from "virtual-i18n-text";
|
4
|
+
const DataContext = createContext({});
|
5
|
+
const ThemeContext = createContext({});
|
6
6
|
function usePageData() {
|
7
|
-
const ctx =
|
7
|
+
const ctx = useContext(DataContext);
|
8
8
|
return ctx.data;
|
9
9
|
}
|
10
10
|
function useLang() {
|
11
|
-
const ctx =
|
11
|
+
const ctx = useContext(DataContext);
|
12
12
|
return ctx.data.page.lang || '';
|
13
13
|
}
|
14
14
|
function useVersion() {
|
15
|
-
const ctx =
|
15
|
+
const ctx = useContext(DataContext);
|
16
16
|
return ctx.data.page.version || '';
|
17
17
|
}
|
18
18
|
function useDark() {
|
19
|
-
const ctx =
|
19
|
+
const ctx = useContext(ThemeContext);
|
20
20
|
return 'dark' === ctx.theme;
|
21
21
|
}
|
22
22
|
function useI18n() {
|
23
23
|
const lang = useLang();
|
24
|
-
return
|
24
|
+
return useCallback((key)=>external_virtual_i18n_text_default[key][lang], [
|
25
25
|
lang
|
26
26
|
]);
|
27
27
|
}
|
28
28
|
function useViewTransition(dom) {
|
29
|
-
const [element, setElement] =
|
30
|
-
|
29
|
+
const [element, setElement] = useState(dom);
|
30
|
+
useLayoutEffect(()=>{
|
31
31
|
if (document.startViewTransition && element !== dom) document.startViewTransition(()=>{
|
32
|
-
|
32
|
+
flushSync(()=>{
|
33
33
|
setElement(dom);
|
34
34
|
});
|
35
35
|
window.dispatchEvent(new Event('RspressReloadContent'));
|
36
36
|
});
|
37
37
|
else {
|
38
|
-
|
38
|
+
flushSync(()=>{
|
39
39
|
setElement(dom);
|
40
40
|
});
|
41
41
|
window.dispatchEvent(new Event('RspressReloadContent'));
|
@@ -46,11 +46,11 @@ function useViewTransition(dom) {
|
|
46
46
|
return element;
|
47
47
|
}
|
48
48
|
function useWindowSize(initialWidth, initialHeight) {
|
49
|
-
const [size, setSize] =
|
49
|
+
const [size, setSize] = useState({
|
50
50
|
width: initialWidth ?? Number.POSITIVE_INFINITY,
|
51
51
|
height: initialHeight ?? Number.POSITIVE_INFINITY
|
52
52
|
});
|
53
|
-
|
53
|
+
useLayoutEffect(()=>{
|
54
54
|
const handleResize = ()=>{
|
55
55
|
setSize({
|
56
56
|
width: window.innerWidth,
|
package/dist/index.js
CHANGED
@@ -1,40 +1,9 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import
|
6
|
-
import
|
7
|
-
import
|
8
|
-
import
|
9
|
-
|
10
|
-
var __webpack_exports__Content = __WEBPACK_EXTERNAL_MODULE__Content_js_303edc82__.Content;
|
11
|
-
var __webpack_exports__DataContext = __WEBPACK_EXTERNAL_MODULE__hooks_js_5a9aefb7__.DataContext;
|
12
|
-
var __webpack_exports__Head = __WEBPACK_EXTERNAL_MODULE__unhead_react_6715e4ab__.Head;
|
13
|
-
var __webpack_exports__NoSSR = __WEBPACK_EXTERNAL_MODULE__NoSSR_js_7f7b6e71__.NoSSR;
|
14
|
-
var __webpack_exports__ThemeContext = __WEBPACK_EXTERNAL_MODULE__hooks_js_5a9aefb7__.ThemeContext;
|
15
|
-
var __webpack_exports__addLeadingSlash = __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.addLeadingSlash;
|
16
|
-
var __webpack_exports__createPortal = __WEBPACK_EXTERNAL_MODULE_react_dom_7136dc57__.createPortal;
|
17
|
-
var __webpack_exports__flushSync = __WEBPACK_EXTERNAL_MODULE_react_dom_7136dc57__.flushSync;
|
18
|
-
var __webpack_exports__isEqualPath = __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.isEqualPath;
|
19
|
-
var __webpack_exports__isProduction = __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.isProduction;
|
20
|
-
var __webpack_exports__matchPath = __WEBPACK_EXTERNAL_MODULE_react_router_dom_5358f3fe__.matchPath;
|
21
|
-
var __webpack_exports__matchRoutes = __WEBPACK_EXTERNAL_MODULE_react_router_dom_5358f3fe__.matchRoutes;
|
22
|
-
var __webpack_exports__normalizeHrefInRuntime = __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.normalizeHrefInRuntime;
|
23
|
-
var __webpack_exports__normalizeImagePath = __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.normalizeImagePath;
|
24
|
-
var __webpack_exports__normalizeRoutePath = __WEBPACK_EXTERNAL_MODULE__route_js_d0361f8a__.normalizeRoutePath;
|
25
|
-
var __webpack_exports__normalizeSlash = __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.normalizeSlash;
|
26
|
-
var __webpack_exports__pathnameToRouteService = __WEBPACK_EXTERNAL_MODULE__route_js_d0361f8a__.pathnameToRouteService;
|
27
|
-
var __webpack_exports__removeBase = __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.removeBase;
|
28
|
-
var __webpack_exports__removeTrailingSlash = __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.removeTrailingSlash;
|
29
|
-
var __webpack_exports__useDark = __WEBPACK_EXTERNAL_MODULE__hooks_js_5a9aefb7__.useDark;
|
30
|
-
var __webpack_exports__useI18n = __WEBPACK_EXTERNAL_MODULE__hooks_js_5a9aefb7__.useI18n;
|
31
|
-
var __webpack_exports__useLang = __WEBPACK_EXTERNAL_MODULE__hooks_js_5a9aefb7__.useLang;
|
32
|
-
var __webpack_exports__useLocation = __WEBPACK_EXTERNAL_MODULE_react_router_dom_5358f3fe__.useLocation;
|
33
|
-
var __webpack_exports__useNavigate = __WEBPACK_EXTERNAL_MODULE_react_router_dom_5358f3fe__.useNavigate;
|
34
|
-
var __webpack_exports__usePageData = __WEBPACK_EXTERNAL_MODULE__hooks_js_5a9aefb7__.usePageData;
|
35
|
-
var __webpack_exports__useSearchParams = __WEBPACK_EXTERNAL_MODULE_react_router_dom_5358f3fe__.useSearchParams;
|
36
|
-
var __webpack_exports__useVersion = __WEBPACK_EXTERNAL_MODULE__hooks_js_5a9aefb7__.useVersion;
|
37
|
-
var __webpack_exports__useViewTransition = __WEBPACK_EXTERNAL_MODULE__hooks_js_5a9aefb7__.useViewTransition;
|
38
|
-
var __webpack_exports__useWindowSize = __WEBPACK_EXTERNAL_MODULE__hooks_js_5a9aefb7__.useWindowSize;
|
39
|
-
var __webpack_exports__withBase = __WEBPACK_EXTERNAL_MODULE__utils_js_d88b7fe1__.withBase;
|
40
|
-
export { __webpack_exports__BrowserRouter as BrowserRouter, __webpack_exports__Content as Content, __webpack_exports__DataContext as DataContext, __webpack_exports__Head as Head, __webpack_exports__NoSSR as NoSSR, __webpack_exports__ThemeContext as ThemeContext, __webpack_exports__addLeadingSlash as addLeadingSlash, __webpack_exports__createPortal as createPortal, __webpack_exports__flushSync as flushSync, __webpack_exports__isEqualPath as isEqualPath, __webpack_exports__isProduction as isProduction, __webpack_exports__matchPath as matchPath, __webpack_exports__matchRoutes as matchRoutes, __webpack_exports__normalizeHrefInRuntime as normalizeHrefInRuntime, __webpack_exports__normalizeImagePath as normalizeImagePath, __webpack_exports__normalizeRoutePath as normalizeRoutePath, __webpack_exports__normalizeSlash as normalizeSlash, __webpack_exports__pathnameToRouteService as pathnameToRouteService, __webpack_exports__removeBase as removeBase, __webpack_exports__removeTrailingSlash as removeTrailingSlash, __webpack_exports__useDark as useDark, __webpack_exports__useI18n as useI18n, __webpack_exports__useLang as useLang, __webpack_exports__useLocation as useLocation, __webpack_exports__useNavigate as useNavigate, __webpack_exports__usePageData as usePageData, __webpack_exports__useSearchParams as useSearchParams, __webpack_exports__useVersion as useVersion, __webpack_exports__useViewTransition as useViewTransition, __webpack_exports__useWindowSize as useWindowSize, __webpack_exports__withBase as withBase };
|
1
|
+
import { DataContext, ThemeContext, useDark, useI18n, useLang, usePageData, useVersion, useViewTransition, useWindowSize } from "./hooks.js";
|
2
|
+
import { Content } from "./Content.js";
|
3
|
+
import { addLeadingSlash, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, normalizeSlash, removeBase, removeTrailingSlash, withBase } from "./utils.js";
|
4
|
+
import { BrowserRouter, matchPath, matchRoutes, useLocation, useNavigate, useSearchParams } from "react-router-dom";
|
5
|
+
import { createPortal, flushSync } from "react-dom";
|
6
|
+
import { normalizeRoutePath, pathnameToRouteService } from "./route.js";
|
7
|
+
import { Head } from "@unhead/react";
|
8
|
+
import { NoSSR } from "./NoSSR.js";
|
9
|
+
export { BrowserRouter, Content, DataContext, Head, NoSSR, ThemeContext, addLeadingSlash, createPortal, flushSync, isEqualPath, isProduction, matchPath, matchRoutes, normalizeHrefInRuntime, normalizeImagePath, normalizeRoutePath, normalizeSlash, pathnameToRouteService, removeBase, removeTrailingSlash, useDark, useI18n, useLang, useLocation, useNavigate, usePageData, useSearchParams, useVersion, useViewTransition, useWindowSize, withBase };
|
package/dist/route.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import
|
2
|
-
import
|
1
|
+
import { matchRoutes } from "react-router-dom";
|
2
|
+
import { routes } from "virtual-routes";
|
3
3
|
function normalizeRoutePath(routePath) {
|
4
4
|
return decodeURIComponent(routePath).replace(/\.html$/, '').replace(/\/index$/, '/');
|
5
5
|
}
|
@@ -7,7 +7,7 @@ const cache = new Map();
|
|
7
7
|
function pathnameToRouteService(pathname) {
|
8
8
|
const cacheItem = cache.get(pathname);
|
9
9
|
if (cacheItem) return cacheItem;
|
10
|
-
const matched =
|
10
|
+
const matched = matchRoutes(routes, normalizeRoutePath(pathname));
|
11
11
|
const route = matched?.[0]?.route;
|
12
12
|
if (route) cache.set(pathname, route);
|
13
13
|
return route;
|
package/dist/utils.js
CHANGED
@@ -1,30 +1,26 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
function
|
4
|
-
return
|
1
|
+
import { addLeadingSlash, isDataUrl, isExternalUrl, isProduction, normalizeHref, normalizeSlash, removeBase, removeHash, removeTrailingSlash, withBase } from "@rspress/shared";
|
2
|
+
import external_virtual_site_data_default from "virtual-site-data";
|
3
|
+
function utils_withBase(url = '/') {
|
4
|
+
return withBase(url, external_virtual_site_data_default.base);
|
5
5
|
}
|
6
|
-
function
|
7
|
-
return
|
6
|
+
function utils_removeBase(url) {
|
7
|
+
return removeBase(url, external_virtual_site_data_default.base);
|
8
8
|
}
|
9
9
|
function isEqualPath(a, b) {
|
10
|
-
return
|
10
|
+
return utils_withBase(normalizeHrefInRuntime(removeHash(a))) === utils_withBase(normalizeHrefInRuntime(removeHash(b)));
|
11
11
|
}
|
12
12
|
function normalizeHrefInRuntime(a) {
|
13
|
-
const cleanUrls = Boolean(
|
14
|
-
return
|
13
|
+
const cleanUrls = Boolean(external_virtual_site_data_default?.route?.cleanUrls);
|
14
|
+
return normalizeHref(a, cleanUrls);
|
15
15
|
}
|
16
16
|
function normalizeImagePath(imagePath) {
|
17
|
-
const isProd =
|
17
|
+
const isProd = isProduction();
|
18
18
|
if (!isProd) return imagePath;
|
19
19
|
if (isAbsoluteUrl(imagePath)) return imagePath;
|
20
20
|
if (!imagePath.startsWith('/')) return imagePath;
|
21
|
-
return
|
21
|
+
return utils_withBase(imagePath);
|
22
22
|
}
|
23
23
|
function isAbsoluteUrl(path) {
|
24
|
-
return
|
24
|
+
return isExternalUrl(path) || isDataUrl(path) || path.startsWith('//');
|
25
25
|
}
|
26
|
-
|
27
|
-
var __webpack_exports__isProduction = __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isProduction;
|
28
|
-
var __webpack_exports__normalizeSlash = __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeSlash;
|
29
|
-
var __webpack_exports__removeTrailingSlash = __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeTrailingSlash;
|
30
|
-
export { isAbsoluteUrl, isEqualPath, normalizeHrefInRuntime, normalizeImagePath, removeBase, withBase, __webpack_exports__addLeadingSlash as addLeadingSlash, __webpack_exports__isProduction as isProduction, __webpack_exports__normalizeSlash as normalizeSlash, __webpack_exports__removeTrailingSlash as removeTrailingSlash };
|
26
|
+
export { addLeadingSlash, isAbsoluteUrl, 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.13",
|
4
4
|
"description": "The Runtime of Rspress Documentation Framework",
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
6
6
|
"repository": {
|
@@ -37,11 +37,11 @@
|
|
37
37
|
"react": "^19.1.0",
|
38
38
|
"react-dom": "^19.1.0",
|
39
39
|
"react-router-dom": "^6.29.0",
|
40
|
-
"@rspress/shared": "2.0.0-beta.
|
40
|
+
"@rspress/shared": "2.0.0-beta.13"
|
41
41
|
},
|
42
42
|
"devDependencies": {
|
43
|
-
"@rsbuild/plugin-react": "~1.3.
|
44
|
-
"@rslib/core": "0.
|
43
|
+
"@rsbuild/plugin-react": "~1.3.2",
|
44
|
+
"@rslib/core": "0.9.2",
|
45
45
|
"@types/jest": "~29.5.14",
|
46
46
|
"@types/react": "^19.1.6",
|
47
47
|
"@types/react-dom": "^19.1.6",
|