rari 0.2.1 → 0.2.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/dist/client-dev.d.ts +2 -0
- package/dist/client-dev.js +3 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/{runtime-client-CC4YQweh.js → runtime-client-CcEhh-F7.js} +48 -18
- package/dist/{runtime-client-BEWMJWMx.d.ts → runtime-client-P4vvSVPV.d.ts} +1 -0
- package/dist/{server-DeSCwqZZ.js → server-BwDou3Zb.js} +256 -33
- package/dist/{server-MY0-nRif.d.ts → server-Ph4oyo0B.d.ts} +47 -2
- package/dist/server.d.ts +3 -3
- package/dist/server.js +3 -3
- package/package.json +12 -7
- package/src/client-dev.ts +59 -0
- package/src/client.ts +3 -10
- package/src/router/index.ts +12 -6
- package/src/router/router.tsx +101 -45
- package/src/router/types.ts +2 -1
- package/src/server.ts +5 -14
- package/src/vite/index.ts +475 -48
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Route, RouteGenerationOptions } from "./runtime-client-
|
|
1
|
+
import { Route, RouteGenerationOptions } from "./runtime-client-P4vvSVPV.js";
|
|
2
2
|
import { Plugin, UserConfig } from "rolldown-vite";
|
|
3
3
|
|
|
4
4
|
//#region src/router/file-routes.d.ts
|
|
@@ -62,8 +62,53 @@ interface RariOptions {
|
|
|
62
62
|
serverHandler?: boolean;
|
|
63
63
|
}
|
|
64
64
|
declare function rari(options?: RariOptions): Plugin[];
|
|
65
|
+
declare function createReactDOMOptimization(): {
|
|
66
|
+
build: {
|
|
67
|
+
rollupOptions: {
|
|
68
|
+
output: {
|
|
69
|
+
manualChunks: (id: string) => "react-dom" | "react" | "scheduler" | "vendor" | undefined;
|
|
70
|
+
};
|
|
71
|
+
treeshake: {
|
|
72
|
+
moduleSideEffects: (id: string) => boolean;
|
|
73
|
+
unknownGlobalSideEffects: boolean;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
minify: string;
|
|
77
|
+
target: string[];
|
|
78
|
+
cssMinify: string;
|
|
79
|
+
sourcemap: boolean;
|
|
80
|
+
terserOptions: {
|
|
81
|
+
compress: {
|
|
82
|
+
drop_console: boolean;
|
|
83
|
+
drop_debugger: boolean;
|
|
84
|
+
pure_funcs: string[];
|
|
85
|
+
passes: number;
|
|
86
|
+
unsafe: boolean;
|
|
87
|
+
unsafe_comps: boolean;
|
|
88
|
+
unsafe_Function: boolean;
|
|
89
|
+
unsafe_math: boolean;
|
|
90
|
+
unsafe_symbols: boolean;
|
|
91
|
+
unsafe_methods: boolean;
|
|
92
|
+
unsafe_proto: boolean;
|
|
93
|
+
unsafe_regexp: boolean;
|
|
94
|
+
unsafe_undefined: boolean;
|
|
95
|
+
dead_code: boolean;
|
|
96
|
+
side_effects: boolean;
|
|
97
|
+
};
|
|
98
|
+
mangle: {
|
|
99
|
+
safari10: boolean;
|
|
100
|
+
properties: {
|
|
101
|
+
regex: RegExp;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
format: {
|
|
105
|
+
comments: boolean;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
};
|
|
65
110
|
declare function defineRariConfig(config: UserConfig & {
|
|
66
111
|
plugins?: Plugin[];
|
|
67
112
|
}): UserConfig;
|
|
68
113
|
//#endregion
|
|
69
|
-
export { FileRouteGenerator, convertFilePatternToRoutePattern, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes };
|
|
114
|
+
export { FileRouteGenerator, convertFilePatternToRoutePattern, createReactDOMOptimization, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ErrorBoundaryProps, FileRouteInfo, HttpRuntimeClient, LayoutProps, Link, LinkProps, LoadingProps, Navigate, NavigationOptions, NavigationState, Outlet, PageComponent, PageProps, Route, RouteComponent, RouteGenerationOptions, RouteMatch, RouteMeta, RouteParams, RouterConfig, RouterContext, RouterProvider, RouterProviderProps, Routes, RuntimeClient, SearchParams, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-
|
|
2
|
-
import { FileRouteGenerator, convertFilePatternToRoutePattern, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-
|
|
3
|
-
export { ErrorBoundaryProps, FileRouteGenerator, FileRouteInfo, HttpRuntimeClient, LayoutProps, Link, LinkProps, LoadingProps, Navigate, NavigationOptions, NavigationState, Outlet, PageComponent, PageProps, RouteComponent as Route, RouteGenerationOptions, RouteMatch, RouteMeta, RouteParams, Route as RouteType, RouterConfig, RouterContext, RouterProvider, RouterProviderProps, Routes, RuntimeClient, SearchParams, buildSearchString, buildUrl, convertFilePatternToRoutePattern, createHttpRuntimeClient, createRouteManifest, defineRariConfig, extractParamNames, findMatchingRoute, generateFileRoutes, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, loadRouteManifest, normalizePathname, parseSearchParams, parseUrl, rari, rariRouter, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, validateRoutes, watchFileRoutes, withRouter };
|
|
1
|
+
import { ErrorBoundaryProps, FileRouteInfo, HttpRuntimeClient, LayoutProps, Link, LinkProps, LoadingProps, Navigate, NavigationOptions, NavigationState, Outlet, PageComponent, PageProps, Route, RouteComponent, RouteGenerationOptions, RouteMatch, RouteMeta, RouteParams, RouterConfig, RouterContext, RouterProvider, RouterProviderProps, Routes, RuntimeClient, SearchParams, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-P4vvSVPV.js";
|
|
2
|
+
import { FileRouteGenerator, convertFilePatternToRoutePattern, createReactDOMOptimization, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-Ph4oyo0B.js";
|
|
3
|
+
export { ErrorBoundaryProps, FileRouteGenerator, FileRouteInfo, HttpRuntimeClient, LayoutProps, Link, LinkProps, LoadingProps, Navigate, NavigationOptions, NavigationState, Outlet, PageComponent, PageProps, RouteComponent as Route, RouteGenerationOptions, RouteMatch, RouteMeta, RouteParams, Route as RouteType, RouterConfig, RouterContext, RouterProvider, RouterProviderProps, Routes, RuntimeClient, SearchParams, buildSearchString, buildUrl, convertFilePatternToRoutePattern, createHttpRuntimeClient, createReactDOMOptimization, createRouteManifest, defineRariConfig, extractParamNames, findMatchingRoute, generateFileRoutes, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, loadRouteManifest, normalizePathname, parseSearchParams, parseUrl, rari, rariRouter, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, validateRoutes, watchFileRoutes, withRouter };
|
package/dist/server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent, Routes, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, router_default, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-
|
|
2
|
-
import { FileRouteGenerator, convertFilePatternToRoutePattern, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-
|
|
1
|
+
import { HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent, Routes, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, router_default, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-CcEhh-F7.js";
|
|
2
|
+
import { FileRouteGenerator, convertFilePatternToRoutePattern, createReactDOMOptimization, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-BwDou3Zb.js";
|
|
3
3
|
import "./server-build-DaBgiV55.js";
|
|
4
4
|
|
|
5
|
-
export { FileRouteGenerator, HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent as Route, router_default as RouterProvider, Routes, buildSearchString, buildUrl, convertFilePatternToRoutePattern, createHttpRuntimeClient, createRouteManifest, defineRariConfig, extractParamNames, findMatchingRoute, generateFileRoutes, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, loadRouteManifest, normalizePathname, parseSearchParams, parseUrl, rari, rariRouter, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, validateRoutes, watchFileRoutes, withRouter };
|
|
5
|
+
export { FileRouteGenerator, HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent as Route, router_default as RouterProvider, Routes, buildSearchString, buildUrl, convertFilePatternToRoutePattern, createHttpRuntimeClient, createReactDOMOptimization, createRouteManifest, defineRariConfig, extractParamNames, findMatchingRoute, generateFileRoutes, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, loadRouteManifest, normalizePathname, parseSearchParams, parseUrl, rari, rariRouter, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, validateRoutes, watchFileRoutes, withRouter };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rari",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.3",
|
|
5
5
|
"description": "Runtime Accelerated Rendering Infrastructure (Rari)",
|
|
6
6
|
"author": "Ryan Skinner",
|
|
7
7
|
"license": "MIT",
|
|
@@ -43,6 +43,10 @@
|
|
|
43
43
|
"types": "./dist/client.d.ts",
|
|
44
44
|
"default": "./dist/client.js"
|
|
45
45
|
},
|
|
46
|
+
"./client-dev": {
|
|
47
|
+
"types": "./dist/client-dev.d.ts",
|
|
48
|
+
"default": "./dist/client-dev.js"
|
|
49
|
+
},
|
|
46
50
|
"./server": {
|
|
47
51
|
"types": "./dist/server.d.ts",
|
|
48
52
|
"default": "./dist/server.js"
|
|
@@ -74,14 +78,15 @@
|
|
|
74
78
|
"dependencies": {
|
|
75
79
|
"acorn": "^8.15.0",
|
|
76
80
|
"esbuild": "^0.25.9",
|
|
77
|
-
"picocolors": "^1.1.1"
|
|
81
|
+
"picocolors": "^1.1.1",
|
|
82
|
+
"rollup-plugin-esbuild": "^6.2.1"
|
|
78
83
|
},
|
|
79
84
|
"optionalDependencies": {
|
|
80
|
-
"rari-darwin-arm64": "0.2.
|
|
81
|
-
"rari-darwin-x64": "0.2.
|
|
82
|
-
"rari-linux-arm64": "0.2.
|
|
83
|
-
"rari-linux-x64": "0.2.
|
|
84
|
-
"rari-win32-x64": "0.2.
|
|
85
|
+
"rari-darwin-arm64": "0.2.2",
|
|
86
|
+
"rari-darwin-x64": "0.2.2",
|
|
87
|
+
"rari-linux-arm64": "0.2.2",
|
|
88
|
+
"rari-linux-x64": "0.2.2",
|
|
89
|
+
"rari-win32-x64": "0.2.2"
|
|
85
90
|
},
|
|
86
91
|
"devDependencies": {
|
|
87
92
|
"@types/node": "^24.2.1",
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export { Link } from './router'
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
buildSearchString,
|
|
5
|
+
buildUrl,
|
|
6
|
+
extractParamNames,
|
|
7
|
+
findMatchingRoute,
|
|
8
|
+
isDynamicRoute,
|
|
9
|
+
isPathActive,
|
|
10
|
+
joinPaths,
|
|
11
|
+
normalizePathname,
|
|
12
|
+
parseSearchParams,
|
|
13
|
+
parseUrl,
|
|
14
|
+
} from './router'
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
Navigate,
|
|
18
|
+
Outlet,
|
|
19
|
+
RouteComponent as Route,
|
|
20
|
+
RouterProvider,
|
|
21
|
+
Routes,
|
|
22
|
+
useNavigation,
|
|
23
|
+
useParams,
|
|
24
|
+
usePathname,
|
|
25
|
+
useRoute,
|
|
26
|
+
useRouter,
|
|
27
|
+
useSearchParams,
|
|
28
|
+
withRouter,
|
|
29
|
+
} from './router'
|
|
30
|
+
|
|
31
|
+
export type {
|
|
32
|
+
ErrorBoundaryProps,
|
|
33
|
+
FileRouteInfo,
|
|
34
|
+
LayoutProps,
|
|
35
|
+
LinkProps,
|
|
36
|
+
LoadingProps,
|
|
37
|
+
NavigationOptions,
|
|
38
|
+
NavigationState,
|
|
39
|
+
PageComponent,
|
|
40
|
+
PageProps,
|
|
41
|
+
RouteGenerationOptions,
|
|
42
|
+
RouteMatch,
|
|
43
|
+
RouteMeta,
|
|
44
|
+
RouteParams,
|
|
45
|
+
RouterConfig,
|
|
46
|
+
RouterContext,
|
|
47
|
+
RouterProviderProps,
|
|
48
|
+
Route as RouteType,
|
|
49
|
+
SearchParams,
|
|
50
|
+
} from './router'
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
createHttpRuntimeClient,
|
|
54
|
+
HttpRuntimeClient,
|
|
55
|
+
} from './runtime-client'
|
|
56
|
+
|
|
57
|
+
export type {
|
|
58
|
+
RuntimeClient,
|
|
59
|
+
} from './runtime-client'
|
package/src/client.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
Link,
|
|
3
|
-
} from './router'
|
|
1
|
+
export { Link } from './router'
|
|
4
2
|
|
|
5
3
|
export {
|
|
6
4
|
buildSearchString,
|
|
@@ -51,11 +49,6 @@ export type {
|
|
|
51
49
|
SearchParams,
|
|
52
50
|
} from './router'
|
|
53
51
|
|
|
54
|
-
export {
|
|
55
|
-
createHttpRuntimeClient,
|
|
56
|
-
HttpRuntimeClient,
|
|
57
|
-
} from './runtime-client'
|
|
52
|
+
export { createHttpRuntimeClient, HttpRuntimeClient } from './runtime-client'
|
|
58
53
|
|
|
59
|
-
export type {
|
|
60
|
-
RuntimeClient,
|
|
61
|
-
} from './runtime-client'
|
|
54
|
+
export type { RuntimeClient } from './runtime-client'
|
package/src/router/index.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export {
|
|
2
|
-
Link,
|
|
3
|
-
Navigate,
|
|
4
2
|
Outlet,
|
|
5
3
|
RouteComponent,
|
|
6
4
|
RouterContext,
|
|
7
5
|
RouteRenderer,
|
|
8
6
|
default as RouterProvider,
|
|
9
7
|
Routes,
|
|
8
|
+
} from './router'
|
|
9
|
+
|
|
10
|
+
export {
|
|
10
11
|
useNavigation,
|
|
11
12
|
useParams,
|
|
12
13
|
usePathname,
|
|
@@ -16,24 +17,29 @@ export {
|
|
|
16
17
|
withRouter,
|
|
17
18
|
} from './router'
|
|
18
19
|
|
|
20
|
+
export { Link, Navigate } from './router'
|
|
21
|
+
|
|
19
22
|
export type * from './types'
|
|
20
23
|
|
|
24
|
+
export {
|
|
25
|
+
findMatchingRoute,
|
|
26
|
+
isDynamicRoute,
|
|
27
|
+
normalizePathname,
|
|
28
|
+
parseUrl,
|
|
29
|
+
} from './utils'
|
|
30
|
+
|
|
21
31
|
export {
|
|
22
32
|
analyzeFilePath,
|
|
23
33
|
buildSearchString,
|
|
24
34
|
buildUrl,
|
|
25
35
|
extractParamNames,
|
|
26
36
|
filePathToRoutePath,
|
|
27
|
-
findMatchingRoute,
|
|
28
37
|
getParentPath,
|
|
29
38
|
getParentPaths,
|
|
30
|
-
isDynamicRoute,
|
|
31
39
|
isPathActive,
|
|
32
40
|
joinPaths,
|
|
33
41
|
matchRoute,
|
|
34
|
-
normalizePathname,
|
|
35
42
|
parseSearchParams,
|
|
36
|
-
parseUrl,
|
|
37
43
|
routePathsEqual,
|
|
38
44
|
routePathToRegex,
|
|
39
45
|
sortRoutesBySpecificity,
|
package/src/router/router.tsx
CHANGED
|
@@ -47,10 +47,9 @@ export function RouterProvider({
|
|
|
47
47
|
}),
|
|
48
48
|
[config],
|
|
49
49
|
)
|
|
50
|
-
const [currentRoute, setCurrentRoute] = useState<RouteMatch | null>(null)
|
|
51
50
|
|
|
52
|
-
const
|
|
53
|
-
(url: string) => {
|
|
51
|
+
const resolveRoute = useCallback(
|
|
52
|
+
(url: string): RouteMatch | null => {
|
|
54
53
|
const { pathname, search, hash, searchParams } = parseUrl(url)
|
|
55
54
|
const normalizedPathname = normalizePathname(pathname)
|
|
56
55
|
|
|
@@ -64,17 +63,56 @@ export function RouterProvider({
|
|
|
64
63
|
hash,
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
enhancedMatch.childMatch = findDeepestChildMatch(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
setCurrentRoute(null)
|
|
66
|
+
enhancedMatch.childMatch = findDeepestChildMatch(
|
|
67
|
+
enhancedMatch,
|
|
68
|
+
normalizedPathname,
|
|
69
|
+
)
|
|
70
|
+
return enhancedMatch
|
|
73
71
|
}
|
|
72
|
+
|
|
73
|
+
return null
|
|
74
74
|
},
|
|
75
75
|
[routes],
|
|
76
76
|
)
|
|
77
77
|
|
|
78
|
+
const [routerState, setRouterState] = useState<{
|
|
79
|
+
currentRoute: RouteMatch | null
|
|
80
|
+
isReady: boolean
|
|
81
|
+
}>(() => {
|
|
82
|
+
if (typeof window === 'undefined') {
|
|
83
|
+
return { currentRoute: null, isReady: false }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const url = mergedConfig.useHash
|
|
87
|
+
? window.location.hash.slice(1) || '/'
|
|
88
|
+
: window.location.pathname
|
|
89
|
+
+ window.location.search
|
|
90
|
+
+ window.location.hash
|
|
91
|
+
|
|
92
|
+
let initialRoute
|
|
93
|
+
try {
|
|
94
|
+
initialRoute = resolveRoute(url)
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
console.error('Error resolving initial route:', error)
|
|
98
|
+
initialRoute = null
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const isReady = true
|
|
102
|
+
return { currentRoute: initialRoute, isReady }
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
const currentRoute = routerState.currentRoute
|
|
106
|
+
const isReady = routerState.isReady
|
|
107
|
+
|
|
108
|
+
const updateCurrentRoute = useCallback(
|
|
109
|
+
(url: string) => {
|
|
110
|
+
const route = resolveRoute(url)
|
|
111
|
+
setRouterState({ currentRoute: route, isReady: true })
|
|
112
|
+
},
|
|
113
|
+
[resolveRoute],
|
|
114
|
+
)
|
|
115
|
+
|
|
78
116
|
useEffect(() => {
|
|
79
117
|
const handleLocationChange = () => {
|
|
80
118
|
const url = mergedConfig.useHash
|
|
@@ -86,8 +124,6 @@ export function RouterProvider({
|
|
|
86
124
|
updateCurrentRoute(url)
|
|
87
125
|
}
|
|
88
126
|
|
|
89
|
-
handleLocationChange()
|
|
90
|
-
|
|
91
127
|
const handlePopState = () => {
|
|
92
128
|
handleLocationChange()
|
|
93
129
|
}
|
|
@@ -175,8 +211,8 @@ export function RouterProvider({
|
|
|
175
211
|
[currentRoute],
|
|
176
212
|
)
|
|
177
213
|
|
|
178
|
-
const contextValue: IRouterContext = useMemo(
|
|
179
|
-
|
|
214
|
+
const contextValue: IRouterContext = useMemo(() => {
|
|
215
|
+
return {
|
|
180
216
|
currentRoute,
|
|
181
217
|
routes,
|
|
182
218
|
navigate,
|
|
@@ -185,18 +221,19 @@ export function RouterProvider({
|
|
|
185
221
|
replace,
|
|
186
222
|
isActive,
|
|
187
223
|
config: mergedConfig,
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
224
|
+
isReady,
|
|
225
|
+
}
|
|
226
|
+
}, [
|
|
227
|
+
currentRoute,
|
|
228
|
+
routes,
|
|
229
|
+
navigate,
|
|
230
|
+
back,
|
|
231
|
+
forward,
|
|
232
|
+
replace,
|
|
233
|
+
isActive,
|
|
234
|
+
mergedConfig,
|
|
235
|
+
isReady,
|
|
236
|
+
])
|
|
200
237
|
|
|
201
238
|
return <RouterContext value={contextValue}>{children}</RouterContext>
|
|
202
239
|
}
|
|
@@ -244,8 +281,7 @@ export function useParams() {
|
|
|
244
281
|
}
|
|
245
282
|
|
|
246
283
|
export function useSearchParams() {
|
|
247
|
-
const { currentRoute } = useRouter()
|
|
248
|
-
const { navigate } = useRouter()
|
|
284
|
+
const { currentRoute, navigate } = useRouter()
|
|
249
285
|
|
|
250
286
|
const searchParams = currentRoute?.searchParams || {}
|
|
251
287
|
|
|
@@ -254,7 +290,7 @@ export function useSearchParams() {
|
|
|
254
290
|
params:
|
|
255
291
|
| Record<string, string | string[]>
|
|
256
292
|
| ((
|
|
257
|
-
prev: Record<string, string | string[]
|
|
293
|
+
prev: Record<string, string | string[]>,
|
|
258
294
|
) => Record<string, string | string[]>),
|
|
259
295
|
options: NavigationOptions = DEFAULT_CONFIG,
|
|
260
296
|
) => {
|
|
@@ -357,16 +393,25 @@ export function Outlet() {
|
|
|
357
393
|
return null
|
|
358
394
|
}
|
|
359
395
|
|
|
360
|
-
return
|
|
396
|
+
return (
|
|
397
|
+
<ChildComponent
|
|
398
|
+
{...childRoute.params}
|
|
399
|
+
searchParams={childRoute.searchParams}
|
|
400
|
+
/>
|
|
401
|
+
)
|
|
361
402
|
}
|
|
362
403
|
|
|
363
|
-
function findChildRouteForCurrentLevel(
|
|
404
|
+
function findChildRouteForCurrentLevel(
|
|
405
|
+
currentRoute: RouteMatch,
|
|
406
|
+
): RouteMatch | null {
|
|
364
407
|
if (currentRoute.childMatch) {
|
|
365
408
|
return currentRoute.childMatch
|
|
366
409
|
}
|
|
367
410
|
|
|
368
411
|
if (currentRoute.route.children) {
|
|
369
|
-
const indexRoute = currentRoute.route.children.find(
|
|
412
|
+
const indexRoute = currentRoute.route.children.find(
|
|
413
|
+
child => child.isIndex,
|
|
414
|
+
)
|
|
370
415
|
if (indexRoute) {
|
|
371
416
|
return {
|
|
372
417
|
route: indexRoute,
|
|
@@ -385,14 +430,26 @@ function findChildRouteForCurrentLevel(currentRoute: RouteMatch): RouteMatch | n
|
|
|
385
430
|
export function RouteRenderer({ routeMatch }: { routeMatch: RouteMatch }) {
|
|
386
431
|
if (!routeMatch.layouts || routeMatch.layouts.length === 0) {
|
|
387
432
|
const Component = routeMatch.route.component
|
|
388
|
-
return Component
|
|
433
|
+
return Component
|
|
434
|
+
? (
|
|
435
|
+
<Component
|
|
436
|
+
{...routeMatch.params}
|
|
437
|
+
searchParams={routeMatch.searchParams}
|
|
438
|
+
/>
|
|
439
|
+
)
|
|
440
|
+
: null
|
|
389
441
|
}
|
|
390
442
|
|
|
391
443
|
let rendered: ReactNode = null
|
|
392
444
|
const Component = routeMatch.route.component
|
|
393
445
|
|
|
394
446
|
if (Component) {
|
|
395
|
-
rendered =
|
|
447
|
+
rendered = (
|
|
448
|
+
<Component
|
|
449
|
+
{...routeMatch.params}
|
|
450
|
+
searchParams={routeMatch.searchParams}
|
|
451
|
+
/>
|
|
452
|
+
)
|
|
396
453
|
}
|
|
397
454
|
|
|
398
455
|
for (let i = routeMatch.layouts.length - 1; i >= 0; i--) {
|
|
@@ -400,7 +457,9 @@ export function RouteRenderer({ routeMatch }: { routeMatch: RouteMatch }) {
|
|
|
400
457
|
const LayoutComponent = layout.component
|
|
401
458
|
|
|
402
459
|
if (LayoutComponent) {
|
|
403
|
-
rendered =
|
|
460
|
+
rendered = (
|
|
461
|
+
<LayoutComponent route={routeMatch}>{rendered}</LayoutComponent>
|
|
462
|
+
)
|
|
404
463
|
}
|
|
405
464
|
}
|
|
406
465
|
|
|
@@ -428,7 +487,10 @@ export function Navigate({
|
|
|
428
487
|
export default RouterProvider
|
|
429
488
|
export { RouterContext }
|
|
430
489
|
|
|
431
|
-
function findDeepestChildMatch(
|
|
490
|
+
function findDeepestChildMatch(
|
|
491
|
+
routeMatch: RouteMatch,
|
|
492
|
+
pathname: string,
|
|
493
|
+
): RouteMatch | null {
|
|
432
494
|
if (!routeMatch.route.children || routeMatch.route.children.length === 0) {
|
|
433
495
|
return null
|
|
434
496
|
}
|
|
@@ -486,18 +548,12 @@ export function Link({
|
|
|
486
548
|
)
|
|
487
549
|
|
|
488
550
|
const isLinkActive = isActive(to, exact)
|
|
489
|
-
const finalClassName = [
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
].filter(Boolean).join(' ')
|
|
551
|
+
const finalClassName = [className, isLinkActive && activeClassName]
|
|
552
|
+
.filter(Boolean)
|
|
553
|
+
.join(' ')
|
|
493
554
|
|
|
494
555
|
return (
|
|
495
|
-
<a
|
|
496
|
-
href={to}
|
|
497
|
-
className={finalClassName}
|
|
498
|
-
onClick={handleClick}
|
|
499
|
-
{...props}
|
|
500
|
-
>
|
|
556
|
+
<a href={to} className={finalClassName} onClick={handleClick} {...props}>
|
|
501
557
|
{children}
|
|
502
558
|
</a>
|
|
503
559
|
)
|
package/src/router/types.ts
CHANGED
|
@@ -75,6 +75,7 @@ export interface RouterContext {
|
|
|
75
75
|
replace: (path: string, options?: Omit<NavigationOptions, 'replace'>) => void
|
|
76
76
|
isActive: (path: string, exact?: boolean) => boolean
|
|
77
77
|
config: RouterConfig
|
|
78
|
+
isReady: boolean
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
export interface NavigationState {
|
|
@@ -122,7 +123,7 @@ export type RouteGenerator = (
|
|
|
122
123
|
options: RouteGenerationOptions,
|
|
123
124
|
) => Promise<Route[]>
|
|
124
125
|
|
|
125
|
-
export interface UseRouterReturn extends RouterContext {
|
|
126
|
+
export interface UseRouterReturn extends RouterContext {}
|
|
126
127
|
|
|
127
128
|
export interface UseNavigationReturn extends NavigationState {
|
|
128
129
|
navigate: RouterContext['navigate']
|
package/src/server.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
Link,
|
|
3
|
-
} from './router'
|
|
1
|
+
export { Link } from './router'
|
|
4
2
|
|
|
5
3
|
export {
|
|
6
4
|
buildSearchString,
|
|
@@ -61,19 +59,12 @@ export {
|
|
|
61
59
|
watchFileRoutes,
|
|
62
60
|
} from './router/file-routes'
|
|
63
61
|
|
|
64
|
-
export {
|
|
65
|
-
getRoutePriority,
|
|
66
|
-
} from './router/utils'
|
|
62
|
+
export { getRoutePriority } from './router/utils'
|
|
67
63
|
|
|
68
64
|
export { rariRouter } from './router/vite-plugin'
|
|
69
65
|
|
|
70
|
-
export {
|
|
71
|
-
createHttpRuntimeClient,
|
|
72
|
-
HttpRuntimeClient,
|
|
73
|
-
} from './runtime-client'
|
|
66
|
+
export { createHttpRuntimeClient, HttpRuntimeClient } from './runtime-client'
|
|
74
67
|
|
|
75
|
-
export type {
|
|
76
|
-
RuntimeClient,
|
|
77
|
-
} from './runtime-client'
|
|
68
|
+
export type { RuntimeClient } from './runtime-client'
|
|
78
69
|
|
|
79
|
-
export { defineRariConfig, rari } from './vite'
|
|
70
|
+
export { createReactDOMOptimization, defineRariConfig, rari } from './vite'
|