@modern-js/runtime 2.15.1-alpha.2 → 2.16.1-alpha.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.
Files changed (261) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/cli/index.js +32 -48
  3. package/dist/cjs/common.js +13 -27
  4. package/dist/cjs/config.js +4 -15
  5. package/dist/cjs/core/appConfig.js +13 -26
  6. package/dist/cjs/core/compatible.js +170 -158
  7. package/dist/cjs/core/index.js +38 -45
  8. package/dist/cjs/core/loader/index.js +12 -35
  9. package/dist/cjs/core/loader/loaderManager.js +42 -56
  10. package/dist/cjs/core/loader/useLoader.js +80 -105
  11. package/dist/cjs/core/plugin.js +28 -40
  12. package/dist/cjs/core/types.js +4 -15
  13. package/dist/cjs/document/Body.js +61 -37
  14. package/dist/cjs/document/Comment.js +22 -32
  15. package/dist/cjs/document/DocumentContext.js +14 -37
  16. package/dist/cjs/document/DocumentStructureContext.js +14 -37
  17. package/dist/cjs/document/Head.js +71 -40
  18. package/dist/cjs/document/Html.js +46 -58
  19. package/dist/cjs/document/Links.js +18 -28
  20. package/dist/cjs/document/Root.js +73 -44
  21. package/dist/cjs/document/Script.js +22 -32
  22. package/dist/cjs/document/Scripts.js +18 -28
  23. package/dist/cjs/document/cli/index.js +161 -207
  24. package/dist/cjs/document/constants.js +36 -75
  25. package/dist/cjs/document/index.js +28 -27
  26. package/dist/cjs/exports/head.js +27 -37
  27. package/dist/cjs/exports/loadable.js +27 -37
  28. package/dist/cjs/exports/server.js +7 -25
  29. package/dist/cjs/exports/styled.js +27 -37
  30. package/dist/cjs/index.js +22 -42
  31. package/dist/cjs/router/cli/index.js +91 -114
  32. package/dist/cjs/router/index.js +32 -39
  33. package/dist/cjs/router/runtime/DefaultNotFound.js +23 -38
  34. package/dist/cjs/router/runtime/DeferredDataScripts.js +8 -24
  35. package/dist/cjs/router/runtime/DeferredDataScripts.node.js +69 -112
  36. package/dist/cjs/router/runtime/PrefetchLink.js +117 -96
  37. package/dist/cjs/router/runtime/fetch.js +7 -25
  38. package/dist/cjs/router/runtime/fetch.node.js +7 -25
  39. package/dist/cjs/router/runtime/fetch.worker.js +7 -25
  40. package/dist/cjs/router/runtime/hooks.js +8 -26
  41. package/dist/cjs/router/runtime/index.js +97 -149
  42. package/dist/cjs/router/runtime/plugin.js +56 -76
  43. package/dist/cjs/router/runtime/plugin.node.js +95 -74
  44. package/dist/cjs/router/runtime/server.js +18 -17
  45. package/dist/cjs/router/runtime/types.js +4 -15
  46. package/dist/cjs/router/runtime/utils.js +57 -83
  47. package/dist/cjs/router/runtime/withRouter.js +24 -39
  48. package/dist/cjs/runtimeContext.js +14 -27
  49. package/dist/cjs/ssr/cli/babel-plugin-ssr-loader-id.js +75 -59
  50. package/dist/cjs/ssr/cli/index.js +120 -150
  51. package/dist/cjs/ssr/index.js +149 -132
  52. package/dist/cjs/ssr/index.node.js +73 -74
  53. package/dist/cjs/ssr/prefetch.js +51 -59
  54. package/dist/cjs/ssr/react/index.js +15 -28
  55. package/dist/cjs/ssr/react/nossr/index.js +51 -43
  56. package/dist/cjs/ssr/react/prerender/index.js +93 -59
  57. package/dist/cjs/ssr/react/prerender/type.js +4 -15
  58. package/dist/cjs/ssr/react/prerender/util.js +32 -51
  59. package/dist/cjs/ssr/react/withCallback/index.js +53 -29
  60. package/dist/cjs/ssr/serverRender/helmet.js +15 -26
  61. package/dist/cjs/ssr/serverRender/index.js +14 -32
  62. package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.after.js +15 -34
  63. package/dist/cjs/ssr/serverRender/renderToStream/buildTemplate.share.js +12 -28
  64. package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +28 -55
  65. package/dist/cjs/ssr/serverRender/renderToStream/index.js +23 -48
  66. package/dist/cjs/ssr/serverRender/renderToStream/loadable.js +13 -32
  67. package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.js +33 -64
  68. package/dist/cjs/ssr/serverRender/renderToStream/renderToPipe.worker.js +26 -54
  69. package/dist/cjs/ssr/serverRender/renderToStream/styledComponent.js +9 -27
  70. package/dist/cjs/ssr/serverRender/renderToStream/template.js +11 -32
  71. package/dist/cjs/ssr/serverRender/renderToStream/type.js +4 -15
  72. package/dist/cjs/ssr/serverRender/renderToString/entry.js +133 -99
  73. package/dist/cjs/ssr/serverRender/renderToString/index.js +21 -48
  74. package/dist/cjs/ssr/serverRender/renderToString/loadable.js +20 -45
  75. package/dist/cjs/ssr/serverRender/renderToString/reduce.js +13 -25
  76. package/dist/cjs/ssr/serverRender/renderToString/styledComponent.js +9 -27
  77. package/dist/cjs/ssr/serverRender/renderToString/template.js +42 -37
  78. package/dist/cjs/ssr/serverRender/renderToString/type.js +10 -28
  79. package/dist/cjs/ssr/serverRender/time.js +7 -25
  80. package/dist/cjs/ssr/serverRender/time.worker.js +11 -26
  81. package/dist/cjs/ssr/serverRender/types.js +7 -25
  82. package/dist/cjs/ssr/serverRender/utils.js +12 -27
  83. package/dist/cjs/ssr/utils.js +26 -51
  84. package/dist/cjs/state/cli/index.js +71 -95
  85. package/dist/cjs/state/index.js +32 -39
  86. package/dist/cjs/state/plugins.js +26 -46
  87. package/dist/cjs/state/runtime/index.js +27 -37
  88. package/dist/cjs/state/runtime/plugin.js +82 -84
  89. package/dist/cjs/state/types.js +4 -15
  90. package/dist/esm/cli/index.js +184 -176
  91. package/dist/esm/common.js +4 -5
  92. package/dist/esm/config.js +1 -1
  93. package/dist/esm/core/appConfig.js +8 -7
  94. package/dist/esm/core/compatible.js +470 -448
  95. package/dist/esm/core/index.js +3 -4
  96. package/dist/esm/core/loader/index.js +1 -2
  97. package/dist/esm/core/loader/loaderManager.js +391 -366
  98. package/dist/esm/core/loader/useLoader.js +173 -162
  99. package/dist/esm/core/plugin.js +162 -155
  100. package/dist/esm/core/types.js +1 -1
  101. package/dist/esm/document/Body.js +12 -13
  102. package/dist/esm/document/Comment.js +11 -12
  103. package/dist/esm/document/DocumentContext.js +4 -5
  104. package/dist/esm/document/DocumentStructureContext.js +6 -7
  105. package/dist/esm/document/Head.js +16 -17
  106. package/dist/esm/document/Html.js +84 -85
  107. package/dist/esm/document/Links.js +5 -6
  108. package/dist/esm/document/Root.js +20 -21
  109. package/dist/esm/document/Script.js +12 -13
  110. package/dist/esm/document/Scripts.js +5 -6
  111. package/dist/esm/document/cli/index.js +390 -371
  112. package/dist/esm/document/constants.js +33 -34
  113. package/dist/esm/exports/head.js +1 -2
  114. package/dist/esm/exports/loadable.js +1 -2
  115. package/dist/esm/exports/server.js +2 -3
  116. package/dist/esm/exports/styled.js +1 -2
  117. package/dist/esm/index.js +2 -3
  118. package/dist/esm/router/cli/index.js +141 -141
  119. package/dist/esm/router/index.js +2 -3
  120. package/dist/esm/router/runtime/DefaultNotFound.js +12 -13
  121. package/dist/esm/router/runtime/DeferredDataScripts.js +4 -4
  122. package/dist/esm/router/runtime/DeferredDataScripts.node.js +154 -143
  123. package/dist/esm/router/runtime/PrefetchLink.js +418 -394
  124. package/dist/esm/router/runtime/fetch.js +2 -1
  125. package/dist/esm/router/runtime/fetch.worker.js +2 -1
  126. package/dist/esm/router/runtime/index.js +62 -9
  127. package/dist/esm/router/runtime/plugin.js +141 -142
  128. package/dist/esm/router/runtime/plugin.node.js +372 -353
  129. package/dist/esm/router/runtime/types.js +1 -1
  130. package/dist/esm/router/runtime/utils.js +295 -279
  131. package/dist/esm/router/runtime/withRouter.js +57 -58
  132. package/dist/esm/runtimeContext.js +2 -3
  133. package/dist/esm/ssr/cli/babel-plugin-ssr-loader-id.js +105 -118
  134. package/dist/esm/ssr/cli/index.js +146 -146
  135. package/dist/esm/ssr/index.js +303 -297
  136. package/dist/esm/ssr/index.node.js +227 -221
  137. package/dist/esm/ssr/prefetch.js +192 -186
  138. package/dist/esm/ssr/react/index.js +2 -3
  139. package/dist/esm/ssr/react/nossr/index.js +58 -47
  140. package/dist/esm/ssr/react/prerender/index.js +214 -206
  141. package/dist/esm/ssr/react/prerender/type.js +1 -1
  142. package/dist/esm/ssr/react/prerender/util.js +91 -92
  143. package/dist/esm/ssr/react/withCallback/index.js +13 -14
  144. package/dist/esm/ssr/serverRender/helmet.js +34 -35
  145. package/dist/esm/ssr/serverRender/index.js +167 -160
  146. package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.after.js +58 -59
  147. package/dist/esm/ssr/serverRender/renderToStream/buildTemplate.share.js +5 -6
  148. package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +106 -93
  149. package/dist/esm/ssr/serverRender/renderToStream/index.js +157 -151
  150. package/dist/esm/ssr/serverRender/renderToStream/loadable.js +17 -18
  151. package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.js +117 -117
  152. package/dist/esm/ssr/serverRender/renderToStream/renderToPipe.worker.js +286 -279
  153. package/dist/esm/ssr/serverRender/renderToStream/styledComponent.js +8 -9
  154. package/dist/esm/ssr/serverRender/renderToStream/template.js +62 -51
  155. package/dist/esm/ssr/serverRender/renderToStream/type.js +1 -1
  156. package/dist/esm/ssr/serverRender/renderToString/entry.js +393 -383
  157. package/dist/esm/ssr/serverRender/renderToString/index.js +158 -152
  158. package/dist/esm/ssr/serverRender/renderToString/loadable.js +46 -47
  159. package/dist/esm/ssr/serverRender/renderToString/reduce.js +7 -8
  160. package/dist/esm/ssr/serverRender/renderToString/styledComponent.js +6 -7
  161. package/dist/esm/ssr/serverRender/renderToString/template.js +142 -128
  162. package/dist/esm/ssr/serverRender/renderToString/type.js +6 -7
  163. package/dist/esm/ssr/serverRender/time.js +57 -46
  164. package/dist/esm/ssr/serverRender/time.worker.js +72 -61
  165. package/dist/esm/ssr/serverRender/utils.js +14 -15
  166. package/dist/esm/ssr/utils.js +128 -117
  167. package/dist/esm/state/cli/index.js +67 -67
  168. package/dist/esm/state/index.js +2 -3
  169. package/dist/esm/state/plugins.js +7 -8
  170. package/dist/esm/state/runtime/index.js +1 -2
  171. package/dist/esm/state/runtime/plugin.js +177 -166
  172. package/dist/esm/state/types.js +1 -1
  173. package/dist/esm-node/cli/index.js +11 -9
  174. package/dist/esm-node/common.js +3 -8
  175. package/dist/esm-node/config.js +1 -0
  176. package/dist/esm-node/core/appConfig.js +2 -6
  177. package/dist/esm-node/core/compatible.js +104 -120
  178. package/dist/esm-node/core/index.js +3 -13
  179. package/dist/esm-node/core/loader/index.js +1 -4
  180. package/dist/esm-node/core/loader/loaderManager.js +25 -25
  181. package/dist/esm-node/core/loader/useLoader.js +60 -74
  182. package/dist/esm-node/core/plugin.js +9 -15
  183. package/dist/esm-node/core/types.js +1 -0
  184. package/dist/esm-node/document/Body.js +11 -15
  185. package/dist/esm-node/document/Comment.js +10 -14
  186. package/dist/esm-node/document/DocumentContext.js +1 -4
  187. package/dist/esm-node/document/DocumentStructureContext.js +1 -4
  188. package/dist/esm-node/document/Head.js +14 -14
  189. package/dist/esm-node/document/Html.js +31 -34
  190. package/dist/esm-node/document/Links.js +5 -6
  191. package/dist/esm-node/document/Root.js +19 -21
  192. package/dist/esm-node/document/Script.js +10 -14
  193. package/dist/esm-node/document/Scripts.js +5 -6
  194. package/dist/esm-node/document/cli/index.js +136 -184
  195. package/dist/esm-node/document/constants.js +22 -52
  196. package/dist/esm-node/exports/head.js +1 -4
  197. package/dist/esm-node/exports/loadable.js +1 -4
  198. package/dist/esm-node/exports/server.js +1 -4
  199. package/dist/esm-node/exports/styled.js +1 -4
  200. package/dist/esm-node/index.js +2 -22
  201. package/dist/esm-node/router/cli/index.js +83 -98
  202. package/dist/esm-node/router/index.js +2 -6
  203. package/dist/esm-node/router/runtime/DefaultNotFound.js +11 -17
  204. package/dist/esm-node/router/runtime/DeferredDataScripts.js +1 -4
  205. package/dist/esm-node/router/runtime/DeferredDataScripts.node.js +51 -85
  206. package/dist/esm-node/router/runtime/PrefetchLink.js +53 -59
  207. package/dist/esm-node/router/runtime/fetch.js +1 -3
  208. package/dist/esm-node/router/runtime/fetch.node.js +1 -3
  209. package/dist/esm-node/router/runtime/fetch.worker.js +1 -3
  210. package/dist/esm-node/router/runtime/hooks.js +1 -3
  211. package/dist/esm-node/router/runtime/index.js +10 -69
  212. package/dist/esm-node/router/runtime/plugin.js +27 -41
  213. package/dist/esm-node/router/runtime/plugin.node.js +24 -32
  214. package/dist/esm-node/router/runtime/types.js +1 -0
  215. package/dist/esm-node/router/runtime/utils.js +34 -50
  216. package/dist/esm-node/router/runtime/withRouter.js +8 -14
  217. package/dist/esm-node/runtimeContext.js +2 -6
  218. package/dist/esm-node/ssr/cli/babel-plugin-ssr-loader-id.js +99 -119
  219. package/dist/esm-node/ssr/cli/index.js +106 -125
  220. package/dist/esm-node/ssr/index.js +112 -96
  221. package/dist/esm-node/ssr/index.node.js +39 -39
  222. package/dist/esm-node/ssr/prefetch.js +40 -35
  223. package/dist/esm-node/ssr/react/index.js +2 -6
  224. package/dist/esm-node/ssr/react/nossr/index.js +2 -9
  225. package/dist/esm-node/ssr/react/prerender/index.js +32 -23
  226. package/dist/esm-node/ssr/react/prerender/type.js +1 -0
  227. package/dist/esm-node/ssr/react/prerender/util.js +23 -33
  228. package/dist/esm-node/ssr/react/withCallback/index.js +4 -5
  229. package/dist/esm-node/ssr/serverRender/helmet.js +2 -5
  230. package/dist/esm-node/ssr/serverRender/index.js +5 -10
  231. package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.after.js +5 -9
  232. package/dist/esm-node/ssr/serverRender/renderToStream/buildTemplate.share.js +3 -10
  233. package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +7 -17
  234. package/dist/esm-node/ssr/serverRender/renderToStream/index.js +2 -7
  235. package/dist/esm-node/ssr/serverRender/renderToStream/loadable.js +4 -8
  236. package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.js +21 -39
  237. package/dist/esm-node/ssr/serverRender/renderToStream/renderToPipe.worker.js +16 -31
  238. package/dist/esm-node/ssr/serverRender/renderToStream/styledComponent.js +1 -4
  239. package/dist/esm-node/ssr/serverRender/renderToStream/template.js +2 -8
  240. package/dist/esm-node/ssr/serverRender/renderToStream/type.js +1 -0
  241. package/dist/esm-node/ssr/serverRender/renderToString/entry.js +50 -39
  242. package/dist/esm-node/ssr/serverRender/renderToString/index.js +1 -8
  243. package/dist/esm-node/ssr/serverRender/renderToString/loadable.js +8 -18
  244. package/dist/esm-node/ssr/serverRender/renderToString/reduce.js +1 -4
  245. package/dist/esm-node/ssr/serverRender/renderToString/styledComponent.js +1 -4
  246. package/dist/esm-node/ssr/serverRender/renderToString/template.js +32 -18
  247. package/dist/esm-node/ssr/serverRender/renderToString/type.js +3 -6
  248. package/dist/esm-node/ssr/serverRender/time.js +1 -4
  249. package/dist/esm-node/ssr/serverRender/time.worker.js +5 -5
  250. package/dist/esm-node/ssr/serverRender/types.js +1 -3
  251. package/dist/esm-node/ssr/serverRender/utils.js +4 -10
  252. package/dist/esm-node/ssr/utils.js +8 -19
  253. package/dist/esm-node/state/cli/index.js +63 -78
  254. package/dist/esm-node/state/index.js +2 -6
  255. package/dist/esm-node/state/plugins.js +4 -10
  256. package/dist/esm-node/state/runtime/index.js +1 -4
  257. package/dist/esm-node/state/runtime/plugin.js +47 -44
  258. package/dist/esm-node/state/types.js +1 -0
  259. package/dist/types/router/runtime/index.d.ts +1 -1
  260. package/package.json +14 -10
  261. package/types/model.d.ts +1 -0
@@ -1,14 +1,14 @@
1
1
  import { useRouteLoaderData as useRouteData } from "react-router-dom";
2
2
  import { routerPlugin } from "./plugin";
3
- var runtime_default = routerPlugin;
4
- import { modifyRoutes } from "./plugin";
3
+ export default routerPlugin;
4
+ export { modifyRoutes } from "./plugin";
5
5
  export * from "./withRouter";
6
- import { Link, NavLink } from "./PrefetchLink";
7
- const useRouteLoaderData = (routeId) => {
8
- const realRouteId = routeId.replace(/\((.*?)\)/g, "[$1]");
6
+ export { Link, NavLink } from "./PrefetchLink";
7
+ export const useRouteLoaderData = (routeId) => {
8
+ const realRouteId = routeId.replace(/\([.*?]\)/g, "($1)");
9
9
  return useRouteData(realRouteId);
10
10
  };
11
- import {
11
+ export {
12
12
  createBrowserRouter,
13
13
  createHashRouter,
14
14
  createMemoryRouter,
@@ -59,67 +59,8 @@ import {
59
59
  matchRoutes,
60
60
  renderMatches,
61
61
  resolvePath,
62
- createPath
63
- } from "react-router-dom";
64
- import { defer, json, redirect } from "@modern-js/utils/universal/remix-router";
65
- export {
66
- Await,
67
- BrowserRouter,
68
- Form,
69
- HashRouter,
70
- Link,
71
- MemoryRouter,
72
- NavLink,
73
- Navigate,
74
- Outlet,
75
- Route,
76
- Router,
77
- RouterProvider,
78
- Routes,
79
- ScrollRestoration,
80
- createBrowserRouter,
81
- createHashRouter,
82
- createMemoryRouter,
83
62
  createPath,
84
- createRoutesFromChildren,
85
- createRoutesFromElements,
86
- createSearchParams,
87
- runtime_default as default,
88
- defer,
89
- generatePath,
90
- isRouteErrorResponse,
91
- json,
92
- matchPath,
93
- matchRoutes,
94
- modifyRoutes,
95
- redirect,
96
- renderMatches,
97
- resolvePath,
98
- useActionData,
99
- useAsyncError,
100
- useAsyncValue,
101
- useBeforeUnload,
102
- useFetcher,
103
- useFetchers,
104
- useFormAction,
105
- useHref,
106
- useInRouterContext,
107
- useLinkClickHandler,
108
- useLoaderData,
109
- useLocation,
110
- useMatch,
111
- useMatches,
112
- useNavigate,
113
- useNavigation,
114
- useNavigationType,
115
- useOutlet,
116
- useOutletContext,
117
- useParams,
118
- useResolvedPath,
119
- useRevalidator,
120
- useRouteError,
121
- useRouteLoaderData,
122
- useRoutes,
123
- useSearchParams,
124
- useSubmit
125
- };
63
+ unstable_useBlocker,
64
+ unstable_usePrompt
65
+ } from "react-router-dom";
66
+ export { defer, json, redirect } from "@modern-js/utils/universal/remix-router";
@@ -1,38 +1,23 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import {
3
- createBrowserRouter,
4
- createHashRouter,
5
- RouterProvider,
6
- createRoutesFromElements,
7
- useMatches,
8
- useLocation
9
- } from "react-router-dom";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createBrowserRouter, createHashRouter, RouterProvider, createRoutesFromElements, useMatches, useLocation } from "react-router-dom";
10
3
  import hoistNonReactStatics from "hoist-non-react-statics";
11
4
  import { parsedJSONFromElement } from "@modern-js/utils/runtime";
12
5
  import { modifyRoutes as modifyRoutesHook } from "./hooks";
13
6
  import { deserializeErrors, renderRoutes, urlJoin } from "./utils";
14
- let finalRouteConfig = {
7
+ export let finalRouteConfig = {
15
8
  routes: []
16
9
  };
17
- let beforeCreateRouter = true;
18
- function modifyRoutes(modifyFunction) {
10
+ export let beforeCreateRouter = true;
11
+ export function modifyRoutes(modifyFunction) {
19
12
  if (beforeCreateRouter) {
20
13
  const { routes: originRoutes } = finalRouteConfig;
21
14
  const newRoutes = modifyFunction(originRoutes);
22
15
  finalRouteConfig.routes = newRoutes;
23
16
  } else {
24
- console.error(
25
- "It is not allowed to modify routes config after create router."
26
- );
17
+ console.error("It is not allowed to modify routes config after create router.");
27
18
  }
28
19
  }
29
- const routerPlugin = ({
30
- serverBase = [],
31
- supportHtml5History = true,
32
- basename = "",
33
- routesConfig,
34
- createRoutes
35
- }) => {
20
+ export const routerPlugin = ({ serverBase = [], supportHtml5History = true, basename = "", routesConfig, createRoutes }) => {
36
21
  const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
37
22
  let routes = [];
38
23
  finalRouteConfig = routesConfig;
@@ -54,28 +39,30 @@ const routerPlugin = ({
54
39
  return routes;
55
40
  }
56
41
  });
57
- return next({ context });
42
+ return next({
43
+ context
44
+ });
58
45
  },
59
46
  hoc: ({ App }, next) => {
60
47
  if (!finalRouteConfig && !createRoutes) {
61
- return next({ App });
48
+ return next({
49
+ App
50
+ });
62
51
  }
63
52
  const getRouteApp = () => {
64
53
  return (props) => {
65
- var _a;
54
+ var _window__SERVER_DATA;
66
55
  beforeCreateRouter = false;
67
- routes = createRoutes ? createRoutes() : createRoutesFromElements(
68
- renderRoutes({
69
- routesConfig: finalRouteConfig,
70
- props
71
- })
72
- );
56
+ routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
57
+ routesConfig: finalRouteConfig,
58
+ props
59
+ }));
73
60
  const runner = api.useHookRunners();
74
61
  routes = runner.modifyRoutes(routes);
75
- const baseUrl = ((_a = window._SERVER_DATA) == null ? void 0 : _a.router.baseUrl) || select(location.pathname);
62
+ const baseUrl = ((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname);
76
63
  const _basename = baseUrl === "/" ? urlJoin(baseUrl, basename) : baseUrl;
77
64
  let hydrationData = window._ROUTER_DATA;
78
- if (hydrationData == null ? void 0 : hydrationData.errors) {
65
+ if (hydrationData === null || hydrationData === void 0 ? void 0 : hydrationData.errors) {
79
66
  hydrationData = {
80
67
  ...hydrationData,
81
68
  errors: deserializeErrors(hydrationData.errors)
@@ -88,14 +75,19 @@ const routerPlugin = ({
88
75
  basename: _basename,
89
76
  hydrationData
90
77
  });
91
- return /* @__PURE__ */ jsx(App, { ...props, children: /* @__PURE__ */ jsx(RouterProvider, { router }) });
78
+ return /* @__PURE__ */ _jsx(App, {
79
+ ...props,
80
+ children: /* @__PURE__ */ _jsx(RouterProvider, {
81
+ router
82
+ })
83
+ });
92
84
  };
93
85
  };
94
86
  let RouteApp = getRouteApp();
95
87
  if (App) {
96
88
  RouteApp = hoistNonReactStatics(RouteApp, App);
97
89
  }
98
- if (routesConfig == null ? void 0 : routesConfig.globalApp) {
90
+ if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
99
91
  return next({
100
92
  App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
101
93
  });
@@ -108,9 +100,3 @@ const routerPlugin = ({
108
100
  }
109
101
  };
110
102
  };
111
- export {
112
- beforeCreateRouter,
113
- finalRouteConfig,
114
- modifyRoutes,
115
- routerPlugin
116
- };
@@ -1,10 +1,7 @@
1
- import { jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useContext } from "react";
3
3
  import { createStaticHandler } from "@modern-js/utils/universal/remix-router";
4
- import {
5
- createStaticRouter,
6
- StaticRouterProvider
7
- } from "react-router-dom/server";
4
+ import { createStaticRouter, StaticRouterProvider } from "react-router-dom/server";
8
5
  import hoistNonReactStatics from "hoist-non-react-statics";
9
6
  import { createRoutesFromElements } from "react-router-dom";
10
7
  import { RuntimeReactContext } from "../../core";
@@ -23,7 +20,7 @@ function createFetchRequest(req) {
23
20
  };
24
21
  return new Request(url.href, init);
25
22
  }
26
- function createFetchHeaders(requestHeaders) {
23
+ export function createFetchHeaders(requestHeaders) {
27
24
  const headers = new Headers();
28
25
  for (const [key, values] of Object.entries(requestHeaders || {})) {
29
26
  if (values) {
@@ -38,11 +35,7 @@ function createFetchHeaders(requestHeaders) {
38
35
  }
39
36
  return headers;
40
37
  }
41
- const routerPlugin = ({
42
- basename = "",
43
- routesConfig,
44
- createRoutes
45
- }) => {
38
+ export const routerPlugin = ({ basename = "", routesConfig, createRoutes }) => {
46
39
  return {
47
40
  name: "@modern-js/plugin-router",
48
41
  registerHook: {
@@ -52,17 +45,17 @@ const routerPlugin = ({
52
45
  return {
53
46
  async init({ context }, next) {
54
47
  if (!routesConfig && !createRoutes) {
55
- return next({ context });
48
+ return next({
49
+ context
50
+ });
56
51
  }
57
52
  const { request, mode: ssrMode } = context.ssrContext;
58
53
  const baseUrl = request.baseUrl;
59
54
  const _basename = baseUrl === "/" ? urlJoin(baseUrl, basename) : baseUrl;
60
- const routes = createRoutes ? createRoutes() : createRoutesFromElements(
61
- renderRoutes({
62
- routesConfig,
63
- ssrMode
64
- })
65
- );
55
+ const routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes({
56
+ routesConfig,
57
+ ssrMode
58
+ }));
66
59
  const { query } = createStaticHandler(routes, {
67
60
  basename: _basename
68
61
  });
@@ -78,27 +71,31 @@ const routerPlugin = ({
78
71
  context.routeManifest = context.ssrContext.routeManifest;
79
72
  const runner = api.useHookRunners();
80
73
  runner.modifyRoutes(routes);
81
- return next({ context });
74
+ return next({
75
+ context
76
+ });
82
77
  },
83
78
  hoc: ({ App }, next) => {
84
79
  if (!routesConfig) {
85
- return next({ App });
80
+ return next({
81
+ App
82
+ });
86
83
  }
87
84
  const getRouteApp = () => {
88
85
  return (props) => {
89
86
  const { router, routerContext } = useContext(RuntimeReactContext);
90
- return /* @__PURE__ */ jsx(App, { ...props, children: /* @__PURE__ */ jsx(
91
- StaticRouterProvider,
92
- {
87
+ return /* @__PURE__ */ _jsx(App, {
88
+ ...props,
89
+ children: /* @__PURE__ */ _jsx(StaticRouterProvider, {
93
90
  router,
94
91
  context: routerContext,
95
92
  hydrate: false
96
- }
97
- ) });
93
+ })
94
+ });
98
95
  };
99
96
  };
100
97
  const RouteApp = getRouteApp();
101
- if (routesConfig == null ? void 0 : routesConfig.globalApp) {
98
+ if (routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp) {
102
99
  return next({
103
100
  App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
104
101
  });
@@ -111,10 +108,5 @@ const routerPlugin = ({
111
108
  }
112
109
  };
113
110
  };
114
- const modifyRoutes = () => {
115
- };
116
- export {
117
- createFetchHeaders,
118
- modifyRoutes,
119
- routerPlugin
111
+ export const modifyRoutes = () => {
120
112
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,23 +1,21 @@
1
- import { jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Route } from "react-router-dom";
3
- import {
4
- ErrorResponse,
5
- isRouteErrorResponse
6
- } from "@modern-js/utils/universal/remix-router";
3
+ import { ErrorResponse, isRouteErrorResponse } from "@modern-js/utils/universal/remix-router";
7
4
  import { renderNestedRoute } from "@modern-js/utils/universal/nestedRoutes";
8
5
  import { DefaultNotFound } from "./DefaultNotFound";
9
6
  import DeferredDataScripts from "./DeferredDataScripts";
10
- function getRouteComponents(routes, {
11
- globalApp,
12
- ssrMode,
13
- props
14
- }) {
7
+ export function getRouteComponents(routes, { globalApp, ssrMode, props }) {
15
8
  const Layout = ({ Component, ...props2 }) => {
16
9
  const GlobalLayout = globalApp;
17
10
  if (!GlobalLayout) {
18
- return /* @__PURE__ */ jsx(Component, { ...props2 });
11
+ return /* @__PURE__ */ _jsx(Component, {
12
+ ...props2
13
+ });
19
14
  }
20
- return /* @__PURE__ */ jsx(GlobalLayout, { Component, ...props2 });
15
+ return /* @__PURE__ */ _jsx(GlobalLayout, {
16
+ Component,
17
+ ...props2
18
+ });
21
19
  };
22
20
  const routeElements = [];
23
21
  for (const route of routes) {
@@ -28,25 +26,22 @@ function getRouteComponents(routes, {
28
26
  });
29
27
  routeElements.push(routeElement);
30
28
  } else {
31
- const routeElement = /* @__PURE__ */ jsx(
32
- Route,
33
- {
34
- path: route.path,
35
- element: /* @__PURE__ */ jsx(Layout, { Component: route.component })
36
- },
37
- route.path
38
- );
29
+ const routeElement = /* @__PURE__ */ _jsx(Route, {
30
+ path: route.path,
31
+ element: /* @__PURE__ */ _jsx(Layout, {
32
+ Component: route.component
33
+ })
34
+ }, route.path);
39
35
  routeElements.push(routeElement);
40
36
  }
41
37
  }
42
- routeElements.push(/* @__PURE__ */ jsx(Route, { path: "*", element: /* @__PURE__ */ jsx(DefaultNotFound, {}) }, "*"));
38
+ routeElements.push(/* @__PURE__ */ _jsx(Route, {
39
+ path: "*",
40
+ element: /* @__PURE__ */ _jsx(DefaultNotFound, {})
41
+ }, "*"));
43
42
  return routeElements;
44
43
  }
45
- function renderRoutes({
46
- routesConfig,
47
- props,
48
- ssrMode
49
- }) {
44
+ export function renderRoutes({ routesConfig, props, ssrMode }) {
50
45
  if (!routesConfig) {
51
46
  return null;
52
47
  }
@@ -61,22 +56,22 @@ function renderRoutes({
61
56
  });
62
57
  return routeElements;
63
58
  }
64
- function getLocation(serverContext) {
65
- var _a;
66
- const { pathname, url } = (serverContext == null ? void 0 : serverContext.request) || {};
67
- const cleanUrl = (_a = url == null ? void 0 : url.replace("http://", "")) == null ? void 0 : _a.replace("https://", "");
59
+ export function getLocation(serverContext) {
60
+ var _url_replace;
61
+ const { pathname, url } = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {};
62
+ const cleanUrl = (_url_replace = url === null || url === void 0 ? void 0 : url.replace("http://", "")) === null || _url_replace === void 0 ? void 0 : _url_replace.replace("https://", "");
68
63
  const index = (cleanUrl || "").indexOf(pathname);
69
64
  if (index === -1) {
70
65
  return pathname;
71
66
  }
72
67
  return cleanUrl.substring(index);
73
68
  }
74
- const urlJoin = (...parts) => {
69
+ export const urlJoin = (...parts) => {
75
70
  const separator = "/";
76
71
  const replace = new RegExp(`${separator}{1,}`, "g");
77
72
  return standardSlash(parts.join(separator).replace(replace, separator));
78
73
  };
79
- function standardSlash(str) {
74
+ export function standardSlash(str) {
80
75
  let addr = str;
81
76
  if (!addr || typeof addr !== "string") {
82
77
  return addr;
@@ -92,7 +87,7 @@ function standardSlash(str) {
92
87
  }
93
88
  return addr;
94
89
  }
95
- function serializeErrors(errors) {
90
+ export function serializeErrors(errors) {
96
91
  if (!errors) {
97
92
  return null;
98
93
  }
@@ -100,7 +95,10 @@ function serializeErrors(errors) {
100
95
  const serialized = {};
101
96
  for (const [key, val] of entries) {
102
97
  if (isRouteErrorResponse(val)) {
103
- serialized[key] = { ...val, __type: "RouteErrorResponse" };
98
+ serialized[key] = {
99
+ ...val,
100
+ __type: "RouteErrorResponse"
101
+ };
104
102
  } else if (val instanceof Error) {
105
103
  serialized[key] = {
106
104
  message: val.message,
@@ -113,7 +111,7 @@ function serializeErrors(errors) {
113
111
  }
114
112
  return serialized;
115
113
  }
116
- function deserializeErrors(errors) {
114
+ export function deserializeErrors(errors) {
117
115
  if (!errors) {
118
116
  return null;
119
117
  }
@@ -121,12 +119,7 @@ function deserializeErrors(errors) {
121
119
  const serialized = {};
122
120
  for (const [key, val] of entries) {
123
121
  if (val && val.__type === "RouteErrorResponse") {
124
- serialized[key] = new ErrorResponse(
125
- val.status,
126
- val.statusText,
127
- val.data,
128
- val.internal === true
129
- );
122
+ serialized[key] = new ErrorResponse(val.status, val.statusText, val.data, val.internal === true);
130
123
  } else if (val && val.__type === "Error") {
131
124
  const error = new Error(val.message);
132
125
  error.stack = val.stack;
@@ -137,12 +130,3 @@ function deserializeErrors(errors) {
137
130
  }
138
131
  return serialized;
139
132
  }
140
- export {
141
- deserializeErrors,
142
- getLocation,
143
- getRouteComponents,
144
- renderRoutes,
145
- serializeErrors,
146
- standardSlash,
147
- urlJoin
148
- };
@@ -1,21 +1,15 @@
1
- import { jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useLocation, useNavigate, useParams } from "react-router-dom";
3
- const withRouter = (Component) => {
3
+ export const withRouter = (Component) => {
4
4
  return (props) => {
5
5
  const location = useLocation();
6
6
  const params = useParams();
7
7
  const navigate = useNavigate();
8
- return /* @__PURE__ */ jsx(
9
- Component,
10
- {
11
- ...props,
12
- location,
13
- params,
14
- navigate
15
- }
16
- );
8
+ return /* @__PURE__ */ _jsx(Component, {
9
+ ...props,
10
+ location,
11
+ params,
12
+ navigate
13
+ });
17
14
  };
18
15
  };
19
- export {
20
- withRouter
21
- };
@@ -1,7 +1,3 @@
1
1
  import { createContext } from "react";
2
- const RuntimeReactContext = createContext({});
3
- const ServerRouterContext = createContext({});
4
- export {
5
- RuntimeReactContext,
6
- ServerRouterContext
7
- };
2
+ export const RuntimeReactContext = createContext({});
3
+ export const ServerRouterContext = createContext({});