rasengan 1.1.1 → 1.1.3
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/CHANGELOG.md +10 -0
- package/lib/esm/cli/index.js +2 -2
- package/lib/esm/routing/components/index.js +94 -6
- package/lib/esm/routing/index.js +3 -3
- package/lib/esm/routing/utils/define-router.js +1 -1
- package/lib/esm/routing/utils/flat-routes.js +4 -3
- package/lib/esm/server/dev/handlers.js +15 -0
- package/lib/types/routing/components/index.d.ts +11 -0
- package/lib/types/routing/index.d.ts +3 -3
- package/lib/types/routing/types.d.ts +5 -0
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
package/lib/esm/cli/index.js
CHANGED
|
@@ -8,9 +8,9 @@ program
|
|
|
8
8
|
// Handle the dev command
|
|
9
9
|
program
|
|
10
10
|
.command('dev')
|
|
11
|
-
.option('-p <port>')
|
|
11
|
+
.option('-p, --port <port>', 'Port number')
|
|
12
12
|
.description('Start development server')
|
|
13
|
-
.action(async ({
|
|
13
|
+
.action(async ({ port }) => {
|
|
14
14
|
const convertedPort = Number(port);
|
|
15
15
|
// Checking port
|
|
16
16
|
if (port &&
|
|
@@ -1,12 +1,37 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
2
|
-
import { isRouteErrorResponse, Link, useParams, useRouteError, } from 'react-router';
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { isRouteErrorResponse, Link, useLocation, useParams, useRouteError, } from 'react-router';
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
// Extract the environment variables
|
|
5
|
+
const extractEnv = () => {
|
|
6
|
+
try {
|
|
7
|
+
const env = import.meta.env;
|
|
8
|
+
if (!env)
|
|
9
|
+
return {
|
|
10
|
+
DEV: false,
|
|
11
|
+
PROD: true,
|
|
12
|
+
TEST: false,
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
DEV: env.DEV,
|
|
16
|
+
PROD: env.PROD,
|
|
17
|
+
TEST: env.TEST,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.error(error);
|
|
22
|
+
return {
|
|
23
|
+
DEV: false,
|
|
24
|
+
PROD: true,
|
|
25
|
+
TEST: false,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
};
|
|
3
29
|
/**
|
|
4
30
|
* Error boundary component that will be displayed if an error occurs during a routing
|
|
5
31
|
* @returns
|
|
6
32
|
*/
|
|
7
33
|
export function ErrorBoundary() {
|
|
8
|
-
const { DEV } =
|
|
9
|
-
console.log(import.meta.env);
|
|
34
|
+
const { DEV } = extractEnv();
|
|
10
35
|
let error = useRouteError();
|
|
11
36
|
if (!DEV)
|
|
12
37
|
return (_jsx("section", { style: {
|
|
@@ -28,10 +53,31 @@ export function ErrorBoundary() {
|
|
|
28
53
|
fontSize: '18px',
|
|
29
54
|
}, children: "Application Error" }) }));
|
|
30
55
|
if (isRouteErrorResponse(error)) {
|
|
31
|
-
return (_jsxs(
|
|
56
|
+
return (_jsxs("section", { style: {
|
|
57
|
+
position: 'fixed',
|
|
58
|
+
top: 0,
|
|
59
|
+
left: 0,
|
|
60
|
+
right: 0,
|
|
61
|
+
bottom: 0,
|
|
62
|
+
zIndex: 100,
|
|
63
|
+
display: 'flex',
|
|
64
|
+
flexDirection: 'row',
|
|
65
|
+
justifyContent: 'center',
|
|
66
|
+
alignItems: 'center',
|
|
67
|
+
height: '100vh',
|
|
68
|
+
width: '100vw',
|
|
69
|
+
gap: 10,
|
|
70
|
+
backgroundColor: '#fff',
|
|
71
|
+
}, children: [_jsx("p", { style: {
|
|
72
|
+
fontSize: '18px',
|
|
73
|
+
}, children: "Application Error" }), _jsxs("h1", { style: {
|
|
74
|
+
fontSize: '18px',
|
|
75
|
+
}, children: [error.status, " ", error.statusText] }), _jsx("p", { style: {
|
|
76
|
+
fontSize: '18px',
|
|
77
|
+
}, children: error.data })] }));
|
|
32
78
|
}
|
|
33
79
|
else if (error instanceof Error) {
|
|
34
|
-
return (_jsxs("
|
|
80
|
+
return (_jsxs("section", { style: {
|
|
35
81
|
position: 'fixed',
|
|
36
82
|
top: 0,
|
|
37
83
|
left: 0,
|
|
@@ -129,3 +175,45 @@ export const CustomLink = (props) => {
|
|
|
129
175
|
}
|
|
130
176
|
return (_jsx(Link, { to: to, ...rest, children: children }));
|
|
131
177
|
};
|
|
178
|
+
// Store scroll positions globally (per location.key)
|
|
179
|
+
const scrollPositions = {};
|
|
180
|
+
/**
|
|
181
|
+
* Scroll restoration component
|
|
182
|
+
* @param {Props} props
|
|
183
|
+
* @returns
|
|
184
|
+
*/
|
|
185
|
+
export function ScrollRestoration({ alwaysToTop = false, target }) {
|
|
186
|
+
const location = useLocation();
|
|
187
|
+
const pathnameRef = useRef(location.pathname);
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
if (typeof window === 'undefined')
|
|
190
|
+
return;
|
|
191
|
+
const prevPathname = pathnameRef.current;
|
|
192
|
+
const el = target?.current; // easier to reference
|
|
193
|
+
if (alwaysToTop) {
|
|
194
|
+
if (el) {
|
|
195
|
+
el.scrollTo(0, 0);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
window.scrollTo(0, 0);
|
|
199
|
+
}
|
|
200
|
+
pathnameRef.current = location.pathname;
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
// Save scroll position of the previous page
|
|
204
|
+
if (prevPathname) {
|
|
205
|
+
scrollPositions[prevPathname] = el ? el.scrollTop : window.scrollY;
|
|
206
|
+
}
|
|
207
|
+
// Restore scroll position of the new page (default to 0 if not stored)
|
|
208
|
+
const storedY = scrollPositions[location.pathname] ?? 0;
|
|
209
|
+
if (el) {
|
|
210
|
+
el.scrollTo(0, storedY);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
window.scrollTo(0, storedY);
|
|
214
|
+
}
|
|
215
|
+
// Update ref
|
|
216
|
+
pathnameRef.current = location.pathname;
|
|
217
|
+
}, [location.pathname, target?.current]); // depend on target.current
|
|
218
|
+
return null;
|
|
219
|
+
}
|
package/lib/esm/routing/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CustomLink } from './components/index.js';
|
|
1
|
+
import { CustomLink, ScrollRestoration } from './components/index.js';
|
|
2
2
|
export { defineRouter, defineRoutesGroup, flatRoutes } from './utils/index.js';
|
|
3
3
|
export { RouterComponent } from './interfaces.js';
|
|
4
|
-
export { Outlet,
|
|
5
|
-
export { CustomLink as Link };
|
|
4
|
+
export { Outlet, useLocation, useNavigate, useNavigation, useParams, useSearchParams, useFetcher, useMatch, useRoutes, useResolvedPath, matchRoutes, generatePath, matchPath, createRoutesFromChildren, Navigate, NavLink, } from 'react-router';
|
|
5
|
+
export { CustomLink as Link, ScrollRestoration };
|
|
@@ -63,7 +63,7 @@ export const convertMDXPageToPageComponent = async (MDXPage) => {
|
|
|
63
63
|
};
|
|
64
64
|
export const isMDXPage = (page) => {
|
|
65
65
|
// Check if page is a MDX Page Component or not
|
|
66
|
-
if (page.
|
|
66
|
+
if (page.type === 'MDXPageComponent') {
|
|
67
67
|
return true;
|
|
68
68
|
}
|
|
69
69
|
return false;
|
|
@@ -71,9 +71,9 @@ function generateSkeletonTree(tree, modules) {
|
|
|
71
71
|
fullPath += '/' + segment;
|
|
72
72
|
}
|
|
73
73
|
else {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
if (fullPath === '') {
|
|
75
|
+
fullPath = '/';
|
|
76
|
+
}
|
|
77
77
|
}
|
|
78
78
|
const existing = tmpLevel.find((n) => n.segment === segment);
|
|
79
79
|
if (existing) {
|
|
@@ -343,6 +343,7 @@ export async function flatRoutes(fn) {
|
|
|
343
343
|
}
|
|
344
344
|
catch (error) {
|
|
345
345
|
console.error(error);
|
|
346
|
+
throw error;
|
|
346
347
|
// TODO: Handle error
|
|
347
348
|
}
|
|
348
349
|
}
|
|
@@ -58,6 +58,21 @@ export async function handleDocumentRequest(req, res, runner, options) {
|
|
|
58
58
|
// Create static router
|
|
59
59
|
let router = createStaticRouter(handler.dataRoutes, context);
|
|
60
60
|
const headers = extractHeadersFromRRContext(context);
|
|
61
|
+
// const route = await handler.queryRoute(request, {
|
|
62
|
+
// requestContext: context,
|
|
63
|
+
// });
|
|
64
|
+
// // TODO: Check this line again
|
|
65
|
+
// if (route['meta']?.title === 'Not Found') {
|
|
66
|
+
// // Set headers
|
|
67
|
+
// res.writeHead(404, {
|
|
68
|
+
// ...Object.fromEntries(headers),
|
|
69
|
+
// });
|
|
70
|
+
// } else {
|
|
71
|
+
// // Set headers
|
|
72
|
+
// res.writeHead(context.statusCode, {
|
|
73
|
+
// ...Object.fromEntries(headers),
|
|
74
|
+
// });
|
|
75
|
+
// }
|
|
61
76
|
// Set headers
|
|
62
77
|
res.writeHead(context.statusCode, {
|
|
63
78
|
...Object.fromEntries(headers),
|
|
@@ -20,3 +20,14 @@ export declare const NotFoundPageComponent: () => import("react/jsx-runtime.js")
|
|
|
20
20
|
* @returns React.ReactNode
|
|
21
21
|
*/
|
|
22
22
|
export declare const CustomLink: (props: LinkProps) => import("react/jsx-runtime.js").JSX.Element;
|
|
23
|
+
type Props = {
|
|
24
|
+
alwaysToTop?: boolean;
|
|
25
|
+
target?: React.RefObject<HTMLElement | null>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Scroll restoration component
|
|
29
|
+
* @param {Props} props
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export declare function ScrollRestoration({ alwaysToTop, target }: Props): any;
|
|
33
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CustomLink } from './components/index.js';
|
|
1
|
+
import { CustomLink, ScrollRestoration } from './components/index.js';
|
|
2
2
|
export type { Metadata, MetadataWithoutTitleAndDescription, LayoutComponent, PageComponent, MDXPageComponent, LoaderOptions, LoaderResponse, ReactComponentProps, TemplateProps, } from './types.js';
|
|
3
3
|
export { defineRouter, defineRoutesGroup, flatRoutes } from './utils/index.js';
|
|
4
4
|
export { RouterComponent } from './interfaces.js';
|
|
5
|
-
export { Outlet,
|
|
6
|
-
export { CustomLink as Link };
|
|
5
|
+
export { Outlet, useLocation, useNavigate, useNavigation, useParams, useSearchParams, useFetcher, useMatch, useRoutes, useResolvedPath, matchRoutes, generatePath, matchPath, createRoutesFromChildren, Navigate, NavLink, } from 'react-router';
|
|
6
|
+
export { CustomLink as Link, ScrollRestoration };
|
|
@@ -167,6 +167,10 @@ export type PageComponent<T = ReactComponentProps> = LayoutComponent<T> & {
|
|
|
167
167
|
* Metadata for the page omit title
|
|
168
168
|
*/
|
|
169
169
|
metadata?: Metadata;
|
|
170
|
+
/**
|
|
171
|
+
* Type of the page
|
|
172
|
+
*/
|
|
173
|
+
type?: string;
|
|
170
174
|
};
|
|
171
175
|
/**
|
|
172
176
|
* A React functional component that represents an MDX page.
|
|
@@ -182,6 +186,7 @@ export type MDXPageComponent = FunctionComponent & {
|
|
|
182
186
|
path?: string;
|
|
183
187
|
metadata?: Metadata;
|
|
184
188
|
};
|
|
189
|
+
type?: string;
|
|
185
190
|
};
|
|
186
191
|
/**
|
|
187
192
|
* A React functional component that represents a simple block element.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rasengan",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.3",
|
|
5
5
|
"description": "The modern React Framework",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "lib/esm/index.js",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
},
|
|
61
61
|
"homepage": "https://rasengan.dev",
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@vitejs/plugin-react": "^
|
|
63
|
+
"@vitejs/plugin-react": "^5.0.0",
|
|
64
64
|
"chalk": "^5.3.0",
|
|
65
65
|
"commander": "^11.1.0",
|
|
66
66
|
"compression": "^1.7.4",
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"less": "*",
|
|
79
79
|
"sass": "*",
|
|
80
80
|
"stylus": "*",
|
|
81
|
-
"vite": "^7.0.0",
|
|
82
|
-
"@rasenganjs/mdx": "^1.1.
|
|
81
|
+
"vite": "^6.3.0 || ^7.0.0",
|
|
82
|
+
"@rasenganjs/mdx": "^1.1.7"
|
|
83
83
|
},
|
|
84
84
|
"peerDependenciesMeta": {
|
|
85
85
|
"@types/node": {
|
|
@@ -101,14 +101,14 @@
|
|
|
101
101
|
"devDependencies": {
|
|
102
102
|
"@types/compression": "^1.7.4",
|
|
103
103
|
"@types/express": "^4.17.19",
|
|
104
|
-
"@types/node": "^
|
|
104
|
+
"@types/node": "^22.12.0",
|
|
105
105
|
"@types/react": "^19.0.1",
|
|
106
106
|
"@types/react-dom": "^19.0.1",
|
|
107
107
|
"cross-env": "^7.0.3"
|
|
108
108
|
},
|
|
109
109
|
"license": "MIT",
|
|
110
110
|
"engines": {
|
|
111
|
-
"node": ">=
|
|
111
|
+
"node": ">=22.12.0"
|
|
112
112
|
},
|
|
113
113
|
"files": [
|
|
114
114
|
"lib/",
|