@native-router/react 1.1.1 → 1.2.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/README.md +216 -44
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +1 -2
- package/dist/server.js +1 -2
- package/dist/ssr-BVFDJcr7.cjs +2 -0
- package/dist/ssr-BVFDJcr7.cjs.map +1 -0
- package/dist/ssr-C17nRDBM.js +8 -0
- package/dist/ssr-C17nRDBM.js.map +1 -0
- package/dist/types/components/Link.d.ts +1 -1
- package/dist/types/components/NavLink.d.ts +22 -0
- package/dist/types/components/PrefetchLink.d.ts +9 -2
- package/dist/types/components/Router.d.ts +6 -6
- package/dist/types/components/ScrollRestoration.d.ts +43 -0
- package/dist/types/components/link-behavior.d.ts +22 -0
- package/dist/types/context.d.ts +15 -4
- package/dist/types/index.d.ts +5 -2
- package/dist/types/resolve-view.d.ts +3 -3
- package/dist/types/ssr.d.ts +18 -4
- package/dist/types/types.d.ts +93 -9
- package/dist/types/use-search-params.d.ts +56 -0
- package/package.json +57 -57
- package/dist/server.cjs.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/ssr-CiHFLO3B.js +0 -6
- package/dist/ssr-CiHFLO3B.js.map +0 -1
- package/dist/ssr-CsvbhYZu.cjs +0 -2
- package/dist/ssr-CsvbhYZu.cjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@native-router/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
|
+
"types": "./dist/types/index.d.ts",
|
|
7
8
|
"import": "./dist/index.js",
|
|
8
|
-
"require": "./dist/index.cjs"
|
|
9
|
-
"types": "./dist/types/index.d.ts"
|
|
9
|
+
"require": "./dist/index.cjs"
|
|
10
10
|
},
|
|
11
11
|
"./server": {
|
|
12
|
+
"types": "./dist/types/server.d.ts",
|
|
12
13
|
"import": "./dist/server.js",
|
|
13
|
-
"require": "./dist/server.cjs"
|
|
14
|
-
"types": "./dist/types/server.d.ts"
|
|
14
|
+
"require": "./dist/server.cjs"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"keywords": [
|
|
@@ -40,13 +40,12 @@
|
|
|
40
40
|
"test": "vitest",
|
|
41
41
|
"test:ui": "vitest --ui",
|
|
42
42
|
"test:run": "vitest run",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"serve": "vite preview"
|
|
43
|
+
"serve": "vite preview",
|
|
44
|
+
"typecheck": "tsc -p tsconfig.production.json --noEmit && tsc -p tsconfig.test.json --noEmit"
|
|
46
45
|
},
|
|
47
46
|
"repository": {
|
|
48
47
|
"type": "git",
|
|
49
|
-
"url": "https://github.com/native-router/react"
|
|
48
|
+
"url": "git+https://github.com/native-router/react.git"
|
|
50
49
|
},
|
|
51
50
|
"sideEffects": false,
|
|
52
51
|
"author": "wmzy",
|
|
@@ -56,67 +55,68 @@
|
|
|
56
55
|
},
|
|
57
56
|
"homepage": "https://github.com/native-router/react",
|
|
58
57
|
"engines": {
|
|
59
|
-
"node": ">=
|
|
58
|
+
"node": ">=18"
|
|
60
59
|
},
|
|
61
60
|
"peerDependencies": {
|
|
62
61
|
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
63
62
|
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
64
63
|
},
|
|
65
64
|
"dependencies": {
|
|
66
|
-
"@native-router/core": "^1.
|
|
67
|
-
"history": "^5.3.0"
|
|
65
|
+
"@native-router/core": "^1.4.1",
|
|
66
|
+
"history": "^5.3.0",
|
|
67
|
+
"use-sync-external-store": "^1.6.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@babel/core": "^
|
|
71
|
-
"@babel/preset-env": "^
|
|
72
|
-
"@babel/preset-react": "^
|
|
73
|
-
"@babel/preset-typescript": "^
|
|
74
|
-
"@
|
|
75
|
-
"@
|
|
76
|
-
"@linaria/
|
|
70
|
+
"@babel/core": "^8.0.1",
|
|
71
|
+
"@babel/preset-env": "^8.0.2",
|
|
72
|
+
"@babel/preset-react": "^8.0.1",
|
|
73
|
+
"@babel/preset-typescript": "^8.0.1",
|
|
74
|
+
"@eslint-react/eslint-plugin": "^5.18.6",
|
|
75
|
+
"@eslint/js": "^10.0.1",
|
|
76
|
+
"@linaria/babel-preset": "^5.0.4",
|
|
77
|
+
"@linaria/core": "^8.2.0",
|
|
78
|
+
"@linaria/vite": "^5.0.4",
|
|
77
79
|
"@testing-library/dom": "^10.4.1",
|
|
78
|
-
"@testing-library/react": "^
|
|
79
|
-
"@types/node": "^
|
|
80
|
-
"@types/react": "^19.
|
|
81
|
-
"@types/react-dom": "^19.
|
|
82
|
-
"@
|
|
83
|
-
"@
|
|
84
|
-
"@
|
|
85
|
-
"@vitest/coverage-v8": "^4.0.18",
|
|
86
|
-
"@vitest/ui": "^4.0.18",
|
|
80
|
+
"@testing-library/react": "^16.3.2",
|
|
81
|
+
"@types/node": "^26.2.0",
|
|
82
|
+
"@types/react": "^19.2.18",
|
|
83
|
+
"@types/react-dom": "^19.2.4",
|
|
84
|
+
"@vitejs/plugin-react": "^6.1.0",
|
|
85
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
86
|
+
"@vitest/ui": "^4.1.11",
|
|
87
87
|
"babel-plugin-transform-jsx-class": "^0.1.3",
|
|
88
88
|
"babel-plugin-transform-jsx-condition": "^0.1.3",
|
|
89
89
|
"babel-runtime-jsx-plus": "^0.1.5",
|
|
90
|
-
"commitizen": "^4.3.
|
|
91
|
-
"core-js": "^3.
|
|
92
|
-
"cross-env": "^
|
|
93
|
-
"eslint": "^
|
|
94
|
-
"eslint-config-
|
|
95
|
-
"eslint-
|
|
96
|
-
"eslint-
|
|
97
|
-
"eslint-import-
|
|
98
|
-
"eslint-plugin-
|
|
99
|
-
"eslint-plugin-
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
"prettier": "^3.0.3",
|
|
110
|
-
"react": "^19.0.0",
|
|
111
|
-
"react-dom": "^19.0.0",
|
|
90
|
+
"commitizen": "^4.3.2",
|
|
91
|
+
"core-js": "^3.50.0",
|
|
92
|
+
"cross-env": "^10.1.0",
|
|
93
|
+
"eslint": "^10.9.0",
|
|
94
|
+
"eslint-config-prettier": "^10.1.8",
|
|
95
|
+
"eslint-import-resolver-typescript": "^4.4.5",
|
|
96
|
+
"eslint-plugin-compat": "^7.0.2",
|
|
97
|
+
"eslint-plugin-import-x": "^4.17.1",
|
|
98
|
+
"eslint-plugin-prettier": "^5.5.6",
|
|
99
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
100
|
+
"gh-pages": "^6.3.0",
|
|
101
|
+
"global-jsdom": "^29.0.0",
|
|
102
|
+
"globals": "^17.11.0",
|
|
103
|
+
"husky": "^9.1.7",
|
|
104
|
+
"jsdom": "^30.0.1",
|
|
105
|
+
"lint-staged": "^17.3.0",
|
|
106
|
+
"prettier": "^3.9.6",
|
|
107
|
+
"react": "^19.2.8",
|
|
108
|
+
"react-dom": "^19.2.8",
|
|
112
109
|
"rollup-plugin-type-as-json-schema": "^0.2.6",
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
"
|
|
110
|
+
"semantic-release": "^25.0.9",
|
|
111
|
+
"terser": "^5.50.0",
|
|
112
|
+
"tsc-alias": "^1.9.2",
|
|
113
|
+
"typedoc": "^0.28.20",
|
|
116
114
|
"typedoc-plugin-mark-react-functional-components": "^0.2.2",
|
|
117
|
-
"typedoc-plugin-missing-exports": "^
|
|
118
|
-
"typescript": "^
|
|
119
|
-
"
|
|
120
|
-
"
|
|
115
|
+
"typedoc-plugin-missing-exports": "^4.1.4",
|
|
116
|
+
"typescript": "^6.0.3",
|
|
117
|
+
"typescript-eslint": "^8.67.0",
|
|
118
|
+
"vite": "^8.2.2",
|
|
119
|
+
"vitest": "^4.1.11",
|
|
120
|
+
"eslint-plugin-jsx-a11y": "^6.10.2"
|
|
121
121
|
}
|
|
122
122
|
}
|
package/dist/server.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/server.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/ssr-CiHFLO3B.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{createMemoryHistory as n,createBrowserHistory as t,createHashHistory as r}from"history";import{getCurrentView as e,listen as i,create as o,setOptions as u,resolve as a,toLocation as c}from"@native-router/core";import{splitProps as s,uniqId as l,isString as d}from"@native-router/core/util";import{useContext as f,createContext as h,useMemo as m,useState as v,useEffect as p}from"react";import{jsx as y,jsxs as P,Fragment as g}from"react/jsx-runtime";const w=/* @__PURE__ */h(null);function b(n){/* @__PURE__ */
|
|
2
|
-
return y(w.Provider,{...n})}function x(){return f(w)}function A(){return x()}const E=/* @__PURE__ */h([void 0,{}]);function K(){return f(E)}function R({children:n,name:t,data:r}){const e=K()[1],i=m(()=>[r,t?{...e,[t]:r}:e],[r,t,e]);/* @__PURE__ */
|
|
3
|
-
return y(E.Provider,{value:i,children:n})}const S=/* @__PURE__ */h(void 0);function j(){return f(S)}function k(n){const[t,r]=K();return n?r[n]:t}const H=/* @__PURE__ */h(void 0);function I(){return f(H)}function M(n,t){return _(n,t,(n,t)=>n?.(t))}const O=/* @__PURE__ */new WeakMap;function V(n,t){const r=new Array(n.length);return _(n,t,(n,t)=>Promise.resolve(n?.(t)).then(n=>r[t.index]=n)).then(n=>(O.set(n,r),n))}function _(n,{router:t,location:r},e){return Promise.all(n.map(({params:i,route:o},u)=>{const a={matched:n,params:i,index:u,router:t,location:r};return Promise.all([e(o.data,a),function(){if(!o.component)return A;const n=o.component(a);return Promise.resolve(n).then(n=>"default"in n?n.default:n)}()]).then(([n,t])=>/* @__PURE__ */y(R,{data:n,name:o.name,children:/* @__PURE__ */y(S.Provider,{value:a,children:/* @__PURE__ */y(t,{})})}))})).then(n=>n.reverse().reduce((n,t)=>/* @__PURE__ */y(b,{value:n,children:t})))}const L=/* @__PURE__ */h(null);function W({router:n,children:t}){const[r,o]=v(e(n));return p(()=>i(n,o),[n]),/* @__PURE__ */y(L.Provider,{value:n,children:"undefined"===t?r:/* @__PURE__ */y(b,{value:r,children:t})})}function $(n,t,{resolveView:r=M,...e}={}){return o(n,t,r,e)}function C({routes:n,children:t,...r},e){const[i,o]=s(r,["baseUrl","currentView"]),a=m(()=>$(n,e(),i),[n,e,...Object.keys(i),...Object.values(i)]),[c,d]=v();u(a,{...o,onLoadingChange(n){d(n&&{key:l(),status:n})}});const f=m(()=>/* @__PURE__ */y(W,{router:a,children:t}),[a,t]);/* @__PURE__ */
|
|
4
|
-
return y(H.Provider,{value:c,children:f})}function D(n){return C(n,t)}function J(n){return C(n,r)}function N({initialEntries:t,initialIndex:r,...e}){return C(e,m(()=>()=>n({initialEntries:t,initialIndex:r}),[t,r]))}function T(){return f(L)}const U="_nativeRouterReactSSRData";function q(n,t,r){return a(n,t).then(e=>{const i=function(n){return O.get(n)}(e);/* @__PURE__ */
|
|
5
|
-
return P(g,{children:[/* @__PURE__ */y(W,{router:n,children:e}),/* @__PURE__ */y("script",{...r?.scriptAttributes,suppressHydrationWarning:!0,dangerouslySetInnerHTML:{__html:`window.${r?.hydrateKey||U} = ${JSON.stringify({data:i,location:t})};`}})]})})}function z(t,r,{scriptAttributes:e,hydrateKey:i,...u}={}){const a=o(t,n({initialEntries:[r]}),V,u);return q(a,d(r)?c(a,r):r,{scriptAttributes:e,hydrateKey:i})}function B(t,r){const{data:e,location:i}=window[r?.hydrateKey||U],u=o(t,n({initialEntries:[i]}),function(n){return(t,r)=>_(t,r,(t,r)=>n[r.index])}(e),r);return a(u,i)}export{J as H,N as M,W as R,A as V,D as a,M as b,$ as c,B as d,k as e,I as f,j as g,x as h,z as r,T as u};
|
|
6
|
-
//# sourceMappingURL=ssr-CiHFLO3B.js.map
|
package/dist/ssr-CiHFLO3B.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-CiHFLO3B.js","sources":["../src/context.tsx","../src/resolve-view.tsx","../src/components/Router.tsx","../src/ssr.tsx"],"sourcesContent":["import {createContext, ReactNode, useContext, useMemo} from 'react';\nimport type {Context, LoadStatus, Route} from './types';\n\nconst ViewContext = createContext<ReactNode>(null);\n\nexport function ViewProvider(props: {children: ReactNode; value: ReactNode}) {\n return <ViewContext.Provider {...props} />;\n}\n\n/**\n * @group Hooks\n * @see {@link View View Component}\n */\nexport function useView() {\n return useContext(ViewContext);\n}\n\n/**\n * Used for route component to render child route component.\n * It just render the return of {@link useView}\n * @group Components\n */\nexport function View() {\n return useView();\n}\n\nconst DataContext = createContext<[any, Record<string, any>]>([undefined, {}]);\n\nfunction useDataContext() {\n return useContext(DataContext);\n}\n\n/**\n * @group Hooks\n */\nexport function useNamedData() {\n return useDataContext()[1];\n}\n\nexport function DataProvider({\n children,\n name,\n data\n}: {\n children: ReactNode;\n data: any;\n name?: string;\n}) {\n const namedData = useNamedData();\n const value = useMemo(\n () => [data, name ? {...namedData, [name]: data} : namedData] as [any, any],\n [data, name, namedData]\n );\n return <DataContext.Provider value={value}>{children}</DataContext.Provider>;\n}\n\nexport const MatchedContext = createContext<Context<Route> | undefined>(\n undefined\n);\n\n/**\n * @group Hooks\n */\nexport function useMatched() {\n return useContext(MatchedContext)!;\n}\n\n/**\n * @group Hooks\n */\nexport function useData(name?: string) {\n const [data, namedData] = useDataContext();\n return name ? namedData[name] : data;\n}\n\nexport const LoadingContext = createContext<LoadStatus | undefined>(undefined);\n\n/**\n * @group Hooks\n */\nexport function useLoading() {\n return useContext(LoadingContext);\n}\n","import type {ComponentType, ReactElement} from 'react';\nimport type {Context, ResolveViewContext, Route} from '@@/types';\nimport type {Matched} from '@native-router/core';\nimport {DataProvider, MatchedContext, View, ViewProvider} from './context';\n\n/**\n * The default implementation of resolve view\n * @param matched the matched result\n * @param viewContext resolved view context\n * @returns the resolve view\n * @see {@link create router->create}\n */\nexport default function resolveView(\n matched: Matched<Route>[],\n ctx: ResolveViewContext<Route>\n) {\n return resolveViewBase(matched, ctx, (data, dataCtx) => data?.(dataCtx));\n}\n\nconst viewDataMap = new WeakMap<ReactElement, any[]>();\n\nexport function resolveViewServer(\n matched: Matched<Route>[],\n ctx: ResolveViewContext<Route>\n) {\n const dataResults = new Array(matched.length);\n return resolveViewBase(matched, ctx, (data, dataCtx) =>\n Promise.resolve(data?.(dataCtx)).then(\n (result) => (dataResults[dataCtx.index] = result)\n )\n ).then((view) => {\n viewDataMap.set(view, dataResults);\n return view;\n });\n}\n\nexport function createHydrateResolveView(data: any[]) {\n return (matched: Matched<Route>[], ctx: ResolveViewContext<Route>) =>\n resolveViewBase(matched, ctx, (_, dataCtx) => data[dataCtx.index]);\n}\n\nexport function getViewData(view: ReactElement) {\n return viewDataMap.get(view);\n}\n\nfunction resolveViewBase(\n matched: Matched<Route>[],\n {router, location}: ResolveViewContext<Route>,\n resolveData: (\n dataFetcher: ((ctx: Context<Route>) => any) | undefined,\n ctx: Context<Route>\n ) => any\n) {\n return Promise.all(\n matched.map(({params, route}, index) => {\n const ctx = {\n matched: matched!,\n params,\n index,\n router,\n location\n };\n function resolveComponent(): ComponentType | Promise<ComponentType> {\n if (!route.component) return View;\n const r = route.component(ctx);\n return Promise.resolve(r).then((m) => ('default' in m ? m.default : m));\n }\n\n return Promise.all([\n resolveData(route.data, ctx),\n resolveComponent()\n ]).then(([data, C]) => (\n <DataProvider data={data} name={route.name}>\n <MatchedContext.Provider value={ctx}>\n <C />\n </MatchedContext.Provider>\n </DataProvider>\n ));\n })\n ).then((views) =>\n views\n .reverse()\n .reduce((acc, view) => <ViewProvider value={acc}>{view}</ViewProvider>)\n );\n}\n","import {\n ReactNode,\n createContext,\n useContext,\n useEffect,\n useState,\n useMemo\n} from 'react';\nimport {\n History,\n createBrowserHistory,\n createHashHistory,\n createMemoryHistory,\n MemoryHistoryOptions\n} from 'history';\nimport type {LoadStatus, Route} from '@@/types';\nimport {LoadingContext, ViewProvider} from '@@/context';\nimport {create, getCurrentView, listen, setOptions} from '@native-router/core';\nimport type {Options, ResolveView, RouterInstance} from '@native-router/core';\nimport {splitProps, uniqId} from '@native-router/core/util';\nimport defaultResolve from '@@/resolve-view';\n\nconst RouterContext = createContext<RouterInstance<Route, ReactNode> | null>(\n null\n);\n\ntype Props = {\n children: ReactNode;\n routes: Route[] | Route;\n resolveView?: typeof defaultResolve;\n} & Omit<Options<ReactNode>, 'onLoadingChange'>;\n\n/**\n * Base Router Component.\n * @group Components\n */\nexport function Router({\n router,\n children\n}: {\n children: ReactNode;\n router: RouterInstance<Route, ReactNode>;\n}) {\n const [view, setView] = useState<ReactNode>(getCurrentView(router));\n\n useEffect(() => listen(router, setView), [router]);\n return (\n <RouterContext.Provider value={router}>\n {children === 'undefined' ? (\n view\n ) : (\n <ViewProvider value={view}>{children}</ViewProvider>\n )}\n </RouterContext.Provider>\n );\n}\n\nexport function createRouter(\n routes: Route | Route[],\n history: History,\n {\n resolveView = defaultResolve,\n ...options\n }: Options<ReactNode> & {resolveView?: ResolveView<Route, ReactNode>} = {}\n): RouterInstance<Route, ReactNode> {\n return create(routes, history, resolveView, options);\n}\n\nfunction useNewRouter(\n {routes, children, ...options}: Props,\n createHistory: () => History\n) {\n const [tracked, rest] = splitProps(options, ['baseUrl', 'currentView']);\n const router = useMemo(\n () => createRouter(routes, createHistory(), tracked),\n [routes, createHistory, ...Object.keys(tracked), ...Object.values(tracked)]\n );\n\n const [loading, setLoading] = useState<LoadStatus>();\n setOptions(router, {\n ...rest,\n onLoadingChange(status) {\n setLoading(status && {key: uniqId(), status});\n }\n });\n\n const r = useMemo(\n () => <Router router={router}>{children}</Router>,\n [router, children]\n );\n\n return <LoadingContext.Provider value={loading}>{r}</LoadingContext.Provider>;\n}\n\n/**\n * History mode Router Component.\n * @group Components\n */\nexport function HistoryRouter(props: Props) {\n return useNewRouter(props, createBrowserHistory);\n}\n\n/**\n * Hash mode Router Component.\n * @group Components\n */\nexport function HashRouter(props: Props) {\n return useNewRouter(props, createHashHistory);\n}\n\n/**\n * Memory mode Router Component.\n * @group Components\n */\nexport function MemoryRouter({\n initialEntries,\n initialIndex,\n ...props\n}: Props & MemoryHistoryOptions) {\n const createHistory = useMemo(\n () => () => createMemoryHistory({initialEntries, initialIndex}),\n [initialEntries, initialIndex]\n );\n return useNewRouter(props, createHistory);\n}\n\n/**\n * Get Router instance.\n * @group Hooks\n * @returns Router Instance\n */\nexport function useRouter() {\n return useContext(RouterContext)!;\n}\n","import {createMemoryHistory} from 'history';\nimport {ReactElement, ReactNode} from 'react';\nimport {create, resolve, toLocation} from '@native-router/core';\nimport type {Location, Options, RouterInstance} from '@native-router/core';\nimport {isString} from '@native-router/core/util';\nimport {Router} from './components/Router';\nimport {\n createHydrateResolveView,\n getViewData,\n resolveViewServer\n} from './resolve-view';\nimport type {Route} from './types';\n\nconst defaultHydrateKey = '_nativeRouterReactSSRData';\n\nexport function resolveServerViewBase(\n router: RouterInstance<Route, ReactNode>,\n location: Location,\n options?: {\n scriptAttributes?: Record<string, string>;\n hydrateKey?: string;\n }\n) {\n return resolve<Route, ReactNode>(router, location).then((view) => {\n const data = getViewData(view as ReactElement);\n return (\n <>\n <Router router={router}>{view}</Router>\n <script\n {...options?.scriptAttributes}\n suppressHydrationWarning\n // eslint-disable-next-line react/no-danger\n dangerouslySetInnerHTML={{\n __html: `window.${\n options?.hydrateKey || defaultHydrateKey\n } = ${JSON.stringify({data, location})};`\n }}\n />\n </>\n );\n });\n}\n\nexport function resolveServerView(\n routes: Route | Route[],\n location: Location | string,\n {\n scriptAttributes,\n hydrateKey,\n ...options\n }: Options<ReactElement> & {\n scriptAttributes?: Record<string, string>;\n hydrateKey?: string;\n } = {}\n) {\n const router = create(\n routes,\n createMemoryHistory({initialEntries: [location]}),\n resolveViewServer,\n options\n );\n\n return resolveServerViewBase(\n router,\n isString(location) ? toLocation(router, location) : location,\n {\n scriptAttributes,\n hydrateKey\n }\n );\n}\n\nexport function resolveClientView(\n routes: Route | Route[],\n options?: Options<ReactElement> & {\n hydrateKey?: string;\n }\n) {\n const {data, location} = (window as any)[\n options?.hydrateKey || defaultHydrateKey\n ] as {data: any[]; location: Location};\n const router = create(\n routes,\n createMemoryHistory({initialEntries: [location]}),\n createHydrateResolveView(data),\n options\n );\n return resolve(router, location);\n}\n"],"names":["ViewContext","ViewProvider","props","_jsx","Provider","useView","useContext","View","DataContext","createContext","undefined","useDataContext","DataProvider","children","name","data","namedData","value","useMemo","MatchedContext","useMatched","useData","LoadingContext","useLoading","resolveView","matched","ctx","resolveViewBase","dataCtx","viewDataMap","WeakMap","resolveViewServer","dataResults","Array","length","Promise","resolve","then","result","index","view","set","router","location","resolveData","all","map","params","route","component","r","m","default","resolveComponent","C","views","reverse","reduce","acc","RouterContext","Router","setView","useState","getCurrentView","useEffect","listen","createRouter","routes","history","defaultResolve","options","create","useNewRouter","createHistory","tracked","rest","splitProps","Object","keys","values","loading","setLoading","setOptions","onLoadingChange","status","key","uniqId","HistoryRouter","createBrowserHistory","HashRouter","createHashHistory","MemoryRouter","initialEntries","initialIndex","createMemoryHistory","useRouter","defaultHydrateKey","resolveServerViewBase","get","getViewData","_Fragment","scriptAttributes","suppressHydrationWarning","dangerouslySetInnerHTML","__html","hydrateKey","JSON","stringify","resolveServerView","isString","toLocation","resolveClientView","window","_","createHydrateResolveView"],"mappings":"ycAGA,MAAMA,mBAAuC,MAEtC,SAASC,EAAaC;AAC3B,OAAOC,EAACH,EAAYI,SAAQ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2BC,IACjCC,EAAgBF,EAASC,EAAK,CAACuF,EAAGrF,IAAYb,EAAKa,EAAQW,OAC/D,CE6CI2E,CAAyBnG,GACzBuD,GAEF,OAAOlC,EAAQM,EAAQC,EACzB"}
|
package/dist/ssr-CsvbhYZu.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("history"),t=require("@native-router/core"),r=require("@native-router/core/util"),n=require("react"),o=require("react/jsx-runtime"),i=n.createContext(null);function s(e){return o.jsx(i.Provider,{...e})}function u(){return n.useContext(i)}function c(){return u()}const a=n.createContext([void 0,{}]);function l(){return n.useContext(a)}function d({children:e,name:t,data:r}){const i=l()[1],s=n.useMemo(()=>[r,t?{...i,[t]:r}:i],[r,t,i]);return o.jsx(a.Provider,{value:s,children:e})}const x=n.createContext(void 0);const f=n.createContext(void 0);function h(e,t){return y(e,t,(e,t)=>e?.(t))}const p=new WeakMap;function v(e,t){const r=new Array(e.length);return y(e,t,(e,t)=>Promise.resolve(e?.(t)).then(e=>r[t.index]=e)).then(e=>(p.set(e,r),e))}function y(e,{router:t,location:r},n){return Promise.all(e.map(({params:i,route:s},u)=>{const a={matched:e,params:i,index:u,router:t,location:r};return Promise.all([n(s.data,a),function(){if(!s.component)return c;const e=s.component(a);return Promise.resolve(e).then(e=>"default"in e?e.default:e)}()]).then(([e,t])=>o.jsx(d,{data:e,name:s.name,children:o.jsx(x.Provider,{value:a,children:o.jsx(t,{})})}))})).then(e=>e.reverse().reduce((e,t)=>o.jsx(s,{value:e,children:t})))}const m=n.createContext(null);function j({router:e,children:r}){const[i,u]=n.useState(t.getCurrentView(e));return n.useEffect(()=>t.listen(e,u),[e]),o.jsx(m.Provider,{value:e,children:"undefined"===r?i:o.jsx(s,{value:i,children:r})})}function w(e,r,{resolveView:n=h,...o}={}){return t.create(e,r,n,o)}function C({routes:e,children:i,...s},u){const[c,a]=r.splitProps(s,["baseUrl","currentView"]),l=n.useMemo(()=>w(e,u(),c),[e,u,...Object.keys(c),...Object.values(c)]),[d,x]=n.useState();t.setOptions(l,{...a,onLoadingChange(e){x(e&&{key:r.uniqId(),status:e})}});const h=n.useMemo(()=>o.jsx(j,{router:l,children:i}),[l,i]);return o.jsx(f.Provider,{value:d,children:h})}const g="_nativeRouterReactSSRData";function M(e,r,n){return t.resolve(e,r).then(t=>{const i=function(e){return p.get(e)}(t);return o.jsxs(o.Fragment,{children:[o.jsx(j,{router:e,children:t}),o.jsx("script",{...n?.scriptAttributes,suppressHydrationWarning:!0,dangerouslySetInnerHTML:{__html:`window.${n?.hydrateKey||g} = ${JSON.stringify({data:i,location:r})};`}})]})})}exports.HashRouter=function(t){return C(t,e.createHashHistory)},exports.HistoryRouter=function(t){return C(t,e.createBrowserHistory)},exports.MemoryRouter=function({initialEntries:t,initialIndex:r,...o}){return C(o,n.useMemo(()=>()=>e.createMemoryHistory({initialEntries:t,initialIndex:r}),[t,r]))},exports.Router=j,exports.View=c,exports.createRouter=w,exports.resolveClientView=function(r,n){const{data:o,location:i}=window[n?.hydrateKey||g],s=t.create(r,e.createMemoryHistory({initialEntries:[i]}),function(e){return(t,r)=>y(t,r,(t,r)=>e[r.index])}(o),n);return t.resolve(s,i)},exports.resolveServerView=function(n,o,{scriptAttributes:i,hydrateKey:s,...u}={}){const c=t.create(n,e.createMemoryHistory({initialEntries:[o]}),v,u);return M(c,r.isString(o)?t.toLocation(c,o):o,{scriptAttributes:i,hydrateKey:s})},exports.resolveView=h,exports.useData=function(e){const[t,r]=l();return e?r[e]:t},exports.useLoading=function(){return n.useContext(f)},exports.useMatched=function(){return n.useContext(x)},exports.useRouter=function(){return n.useContext(m)},exports.useView=u;
|
|
2
|
-
//# sourceMappingURL=ssr-CsvbhYZu.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-CsvbhYZu.cjs","sources":["../src/context.tsx","../src/resolve-view.tsx","../src/components/Router.tsx","../src/ssr.tsx"],"sourcesContent":["import {createContext, ReactNode, useContext, useMemo} from 'react';\nimport type {Context, LoadStatus, Route} from './types';\n\nconst ViewContext = createContext<ReactNode>(null);\n\nexport function ViewProvider(props: {children: ReactNode; value: ReactNode}) {\n return <ViewContext.Provider {...props} />;\n}\n\n/**\n * @group Hooks\n * @see {@link View View Component}\n */\nexport function useView() {\n return useContext(ViewContext);\n}\n\n/**\n * Used for route component to render child route component.\n * It just render the return of {@link useView}\n * @group Components\n */\nexport function View() {\n return useView();\n}\n\nconst DataContext = createContext<[any, Record<string, any>]>([undefined, {}]);\n\nfunction useDataContext() {\n return useContext(DataContext);\n}\n\n/**\n * @group Hooks\n */\nexport function useNamedData() {\n return useDataContext()[1];\n}\n\nexport function DataProvider({\n children,\n name,\n data\n}: {\n children: ReactNode;\n data: any;\n name?: string;\n}) {\n const namedData = useNamedData();\n const value = useMemo(\n () => [data, name ? {...namedData, [name]: data} : namedData] as [any, any],\n [data, name, namedData]\n );\n return <DataContext.Provider value={value}>{children}</DataContext.Provider>;\n}\n\nexport const MatchedContext = createContext<Context<Route> | undefined>(\n undefined\n);\n\n/**\n * @group Hooks\n */\nexport function useMatched() {\n return useContext(MatchedContext)!;\n}\n\n/**\n * @group Hooks\n */\nexport function useData(name?: string) {\n const [data, namedData] = useDataContext();\n return name ? namedData[name] : data;\n}\n\nexport const LoadingContext = createContext<LoadStatus | undefined>(undefined);\n\n/**\n * @group Hooks\n */\nexport function useLoading() {\n return useContext(LoadingContext);\n}\n","import type {ComponentType, ReactElement} from 'react';\nimport type {Context, ResolveViewContext, Route} from '@@/types';\nimport type {Matched} from '@native-router/core';\nimport {DataProvider, MatchedContext, View, ViewProvider} from './context';\n\n/**\n * The default implementation of resolve view\n * @param matched the matched result\n * @param viewContext resolved view context\n * @returns the resolve view\n * @see {@link create router->create}\n */\nexport default function resolveView(\n matched: Matched<Route>[],\n ctx: ResolveViewContext<Route>\n) {\n return resolveViewBase(matched, ctx, (data, dataCtx) => data?.(dataCtx));\n}\n\nconst viewDataMap = new WeakMap<ReactElement, any[]>();\n\nexport function resolveViewServer(\n matched: Matched<Route>[],\n ctx: ResolveViewContext<Route>\n) {\n const dataResults = new Array(matched.length);\n return resolveViewBase(matched, ctx, (data, dataCtx) =>\n Promise.resolve(data?.(dataCtx)).then(\n (result) => (dataResults[dataCtx.index] = result)\n )\n ).then((view) => {\n viewDataMap.set(view, dataResults);\n return view;\n });\n}\n\nexport function createHydrateResolveView(data: any[]) {\n return (matched: Matched<Route>[], ctx: ResolveViewContext<Route>) =>\n resolveViewBase(matched, ctx, (_, dataCtx) => data[dataCtx.index]);\n}\n\nexport function getViewData(view: ReactElement) {\n return viewDataMap.get(view);\n}\n\nfunction resolveViewBase(\n matched: Matched<Route>[],\n {router, location}: ResolveViewContext<Route>,\n resolveData: (\n dataFetcher: ((ctx: Context<Route>) => any) | undefined,\n ctx: Context<Route>\n ) => any\n) {\n return Promise.all(\n matched.map(({params, route}, index) => {\n const ctx = {\n matched: matched!,\n params,\n index,\n router,\n location\n };\n function resolveComponent(): ComponentType | Promise<ComponentType> {\n if (!route.component) return View;\n const r = route.component(ctx);\n return Promise.resolve(r).then((m) => ('default' in m ? m.default : m));\n }\n\n return Promise.all([\n resolveData(route.data, ctx),\n resolveComponent()\n ]).then(([data, C]) => (\n <DataProvider data={data} name={route.name}>\n <MatchedContext.Provider value={ctx}>\n <C />\n </MatchedContext.Provider>\n </DataProvider>\n ));\n })\n ).then((views) =>\n views\n .reverse()\n .reduce((acc, view) => <ViewProvider value={acc}>{view}</ViewProvider>)\n );\n}\n","import {\n ReactNode,\n createContext,\n useContext,\n useEffect,\n useState,\n useMemo\n} from 'react';\nimport {\n History,\n createBrowserHistory,\n createHashHistory,\n createMemoryHistory,\n MemoryHistoryOptions\n} from 'history';\nimport type {LoadStatus, Route} from '@@/types';\nimport {LoadingContext, ViewProvider} from '@@/context';\nimport {create, getCurrentView, listen, setOptions} from '@native-router/core';\nimport type {Options, ResolveView, RouterInstance} from '@native-router/core';\nimport {splitProps, uniqId} from '@native-router/core/util';\nimport defaultResolve from '@@/resolve-view';\n\nconst RouterContext = createContext<RouterInstance<Route, ReactNode> | null>(\n null\n);\n\ntype Props = {\n children: ReactNode;\n routes: Route[] | Route;\n resolveView?: typeof defaultResolve;\n} & Omit<Options<ReactNode>, 'onLoadingChange'>;\n\n/**\n * Base Router Component.\n * @group Components\n */\nexport function Router({\n router,\n children\n}: {\n children: ReactNode;\n router: RouterInstance<Route, ReactNode>;\n}) {\n const [view, setView] = useState<ReactNode>(getCurrentView(router));\n\n useEffect(() => listen(router, setView), [router]);\n return (\n <RouterContext.Provider value={router}>\n {children === 'undefined' ? (\n view\n ) : (\n <ViewProvider value={view}>{children}</ViewProvider>\n )}\n </RouterContext.Provider>\n );\n}\n\nexport function createRouter(\n routes: Route | Route[],\n history: History,\n {\n resolveView = defaultResolve,\n ...options\n }: Options<ReactNode> & {resolveView?: ResolveView<Route, ReactNode>} = {}\n): RouterInstance<Route, ReactNode> {\n return create(routes, history, resolveView, options);\n}\n\nfunction useNewRouter(\n {routes, children, ...options}: Props,\n createHistory: () => History\n) {\n const [tracked, rest] = splitProps(options, ['baseUrl', 'currentView']);\n const router = useMemo(\n () => createRouter(routes, createHistory(), tracked),\n [routes, createHistory, ...Object.keys(tracked), ...Object.values(tracked)]\n );\n\n const [loading, setLoading] = useState<LoadStatus>();\n setOptions(router, {\n ...rest,\n onLoadingChange(status) {\n setLoading(status && {key: uniqId(), status});\n }\n });\n\n const r = useMemo(\n () => <Router router={router}>{children}</Router>,\n [router, children]\n );\n\n return <LoadingContext.Provider value={loading}>{r}</LoadingContext.Provider>;\n}\n\n/**\n * History mode Router Component.\n * @group Components\n */\nexport function HistoryRouter(props: Props) {\n return useNewRouter(props, createBrowserHistory);\n}\n\n/**\n * Hash mode Router Component.\n * @group Components\n */\nexport function HashRouter(props: Props) {\n return useNewRouter(props, createHashHistory);\n}\n\n/**\n * Memory mode Router Component.\n * @group Components\n */\nexport function MemoryRouter({\n initialEntries,\n initialIndex,\n ...props\n}: Props & MemoryHistoryOptions) {\n const createHistory = useMemo(\n () => () => createMemoryHistory({initialEntries, initialIndex}),\n [initialEntries, initialIndex]\n );\n return useNewRouter(props, createHistory);\n}\n\n/**\n * Get Router instance.\n * @group Hooks\n * @returns Router Instance\n */\nexport function useRouter() {\n return useContext(RouterContext)!;\n}\n","import {createMemoryHistory} from 'history';\nimport {ReactElement, ReactNode} from 'react';\nimport {create, resolve, toLocation} from '@native-router/core';\nimport type {Location, Options, RouterInstance} from '@native-router/core';\nimport {isString} from '@native-router/core/util';\nimport {Router} from './components/Router';\nimport {\n createHydrateResolveView,\n getViewData,\n resolveViewServer\n} from './resolve-view';\nimport type {Route} from './types';\n\nconst defaultHydrateKey = '_nativeRouterReactSSRData';\n\nexport function resolveServerViewBase(\n router: RouterInstance<Route, ReactNode>,\n location: Location,\n options?: {\n scriptAttributes?: Record<string, string>;\n hydrateKey?: string;\n }\n) {\n return resolve<Route, ReactNode>(router, location).then((view) => {\n const data = getViewData(view as ReactElement);\n return (\n <>\n <Router router={router}>{view}</Router>\n <script\n {...options?.scriptAttributes}\n suppressHydrationWarning\n // eslint-disable-next-line react/no-danger\n dangerouslySetInnerHTML={{\n __html: `window.${\n options?.hydrateKey || defaultHydrateKey\n } = ${JSON.stringify({data, location})};`\n }}\n />\n </>\n );\n });\n}\n\nexport function resolveServerView(\n routes: Route | Route[],\n location: Location | string,\n {\n scriptAttributes,\n hydrateKey,\n ...options\n }: Options<ReactElement> & {\n scriptAttributes?: Record<string, string>;\n hydrateKey?: string;\n } = {}\n) {\n const router = create(\n routes,\n createMemoryHistory({initialEntries: [location]}),\n resolveViewServer,\n options\n );\n\n return resolveServerViewBase(\n router,\n isString(location) ? toLocation(router, location) : location,\n {\n scriptAttributes,\n hydrateKey\n }\n );\n}\n\nexport function resolveClientView(\n routes: Route | Route[],\n options?: Options<ReactElement> & {\n hydrateKey?: string;\n }\n) {\n const {data, location} = (window as any)[\n options?.hydrateKey || defaultHydrateKey\n ] as {data: any[]; location: Location};\n const router = create(\n routes,\n createMemoryHistory({initialEntries: [location]}),\n createHydrateResolveView(data),\n options\n );\n return resolve(router, location);\n}\n"],"names":["ViewContext","ViewProvider","props","_jsx","Provider","useView","useContext","View","DataContext","createContext","undefined","useDataContext","DataProvider","children","name","data","namedData","value","useMemo","MatchedContext","LoadingContext","resolveView","matched","ctx","resolveViewBase","dataCtx","viewDataMap","WeakMap","resolveViewServer","dataResults","Array","length","Promise","resolve","then","result","index","view","set","router","location","resolveData","all","map","params","route","component","r","m","default","resolveComponent","C","views","reverse","reduce","acc","RouterContext","Router","setView","useState","getCurrentView","useEffect","listen","createRouter","routes","history","defaultResolve","options","create","useNewRouter","createHistory","tracked","rest","splitProps","Object","keys","values","loading","setLoading","setOptions","onLoadingChange","status","key","uniqId","defaultHydrateKey","resolveServerViewBase","get","getViewData","_Fragment","scriptAttributes","suppressHydrationWarning","dangerouslySetInnerHTML","__html","hydrateKey","JSON","stringify","createHashHistory","createBrowserHistory","initialEntries","initialIndex","createMemoryHistory","window","_","createHydrateResolveView","isString","toLocation"],"mappings":"iKAGMA,kBAAuC,MAEtC,SAASC,EAAaC,GAC3B,OAAOC,EAAAA,IAACH,EAAYI,SAAQ,IAAKF,GACnC,CAMO,SAASG,IACd,OAAOC,EAAAA,WAAWN,EACpB,CAOO,SAASO,IACd,OAAOF,GACT,CAEA,MAAMG,EAAcC,EAAAA,cAA0C,MAACC,EAAW,CAAA,IAE1E,SAASC,IACP,OAAOL,EAAAA,WAAWE,EACpB,CASO,SAASI,GAAaC,SAC3BA,EAAAA,KACAC,EAAAA,KACAC,IAMA,MAAMC,EAZCL,IAAiB,GAalBM,EAAQC,EAAAA,QACZ,IAAM,CAACH,EAAMD,EAAO,IAAIE,EAAWF,CAACA,GAAOC,GAAQC,GACnD,CAACD,EAAMD,EAAME,IAEf,OAAOb,EAAAA,IAACK,EAAYJ,SAAQ,CAACa,QAAaJ,YAC5C,CAEO,MAAMM,0BAmBN,MAAMC,0BC/Db,SAAwBC,EACtBC,EAC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