@bleedingdev/modern-js-renderer-solid 0.0.0-stage → 3.9.3-ultramodern.10

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 (301) hide show
  1. package/dist/esm/actions.js +282 -0
  2. package/dist/esm/application-router.js +30 -0
  3. package/dist/esm/client.js +49 -0
  4. package/dist/esm/entry-application.js +60 -0
  5. package/dist/esm/entry-client.js +24 -0
  6. package/dist/esm/federation-context.js +25 -0
  7. package/dist/esm/federation-ssr.js +92 -0
  8. package/dist/esm/federation.js +87 -0
  9. package/dist/esm/i18n/I18nProvider.js +33 -0
  10. package/dist/esm/i18n/LocalizedLink.js +52 -0
  11. package/dist/esm/i18n/context.js +3 -0
  12. package/dist/esm/i18n/index.js +8 -0
  13. package/dist/esm/i18n/languageSync.js +50 -0
  14. package/dist/esm/i18n/types.js +0 -0
  15. package/dist/esm/i18n/useI18n.js +74 -0
  16. package/dist/esm/index.js +58 -0
  17. package/dist/esm/manifest.js +150 -0
  18. package/dist/esm/route-completion.js +151 -0
  19. package/dist/esm/route-data-error.js +108 -0
  20. package/dist/esm/router-binding/Asset.js +202 -0
  21. package/dist/esm/router-binding/CatchBoundary.js +94 -0
  22. package/dist/esm/router-binding/ClientOnly.js +26 -0
  23. package/dist/esm/router-binding/HeadContent.js +8 -0
  24. package/dist/esm/router-binding/LICENSE +21 -0
  25. package/dist/esm/router-binding/Match.js +319 -0
  26. package/dist/esm/router-binding/Matches.js +124 -0
  27. package/dist/esm/router-binding/PROVENANCE.json +94 -0
  28. package/dist/esm/router-binding/RouterProvider.js +52 -0
  29. package/dist/esm/router-binding/SafeFragment.js +5 -0
  30. package/dist/esm/router-binding/ScriptOnce.js +15 -0
  31. package/dist/esm/router-binding/Scripts.js +30 -0
  32. package/dist/esm/router-binding/ScrollRestoration.js +16 -0
  33. package/dist/esm/router-binding/Transitioner.js +109 -0
  34. package/dist/esm/router-binding/awaited.js +48 -0
  35. package/dist/esm/router-binding/fileRoute.js +83 -0
  36. package/dist/esm/router-binding/flightData.js +23 -0
  37. package/dist/esm/router-binding/headContentUtils.js +168 -0
  38. package/dist/esm/router-binding/history.js +0 -0
  39. package/dist/esm/router-binding/index.js +35 -0
  40. package/dist/esm/router-binding/lazyRouteComponent.js +30 -0
  41. package/dist/esm/router-binding/link.js +387 -0
  42. package/dist/esm/router-binding/matchContext.js +7 -0
  43. package/dist/esm/router-binding/nonRouteComponentContext.js +13 -0
  44. package/dist/esm/router-binding/not-found.js +35 -0
  45. package/dist/esm/router-binding/publicMatchData.js +447 -0
  46. package/dist/esm/router-binding/registryTransfer.js +223 -0
  47. package/dist/esm/router-binding/renderRouteNotFound.js +23 -0
  48. package/dist/esm/router-binding/route.js +143 -0
  49. package/dist/esm/router-binding/router.js +14 -0
  50. package/dist/esm/router-binding/routerContext.js +3 -0
  51. package/dist/esm/router-binding/routerOptions.js +0 -0
  52. package/dist/esm/router-binding/routerStores.js +50 -0
  53. package/dist/esm/router-binding/scroll-restoration.js +13 -0
  54. package/dist/esm/router-binding/typePrimitives.js +0 -0
  55. package/dist/esm/router-binding/useBlocker.js +152 -0
  56. package/dist/esm/router-binding/useCanGoBack.js +7 -0
  57. package/dist/esm/router-binding/useLoaderData.js +8 -0
  58. package/dist/esm/router-binding/useLoaderDeps.js +8 -0
  59. package/dist/esm/router-binding/useLocation.js +14 -0
  60. package/dist/esm/router-binding/useMatch.js +28 -0
  61. package/dist/esm/router-binding/useNavigate.js +25 -0
  62. package/dist/esm/router-binding/useParams.js +11 -0
  63. package/dist/esm/router-binding/useRouteContext.js +8 -0
  64. package/dist/esm/router-binding/useRouter.js +10 -0
  65. package/dist/esm/router-binding/useRouterState.js +19 -0
  66. package/dist/esm/router-binding/useSearch.js +11 -0
  67. package/dist/esm/router-binding/utils.js +23 -0
  68. package/dist/esm/router.js +187 -0
  69. package/dist/esm-node/actions.js +263 -0
  70. package/dist/esm-node/application-router.js +30 -0
  71. package/dist/esm-node/client.js +49 -0
  72. package/dist/esm-node/entry-application.js +110 -0
  73. package/dist/esm-node/entry-client.js +24 -0
  74. package/dist/esm-node/entry-server.js +47 -0
  75. package/dist/esm-node/federation-context.js +25 -0
  76. package/dist/esm-node/federation-ssr.js +92 -0
  77. package/dist/esm-node/federation.js +87 -0
  78. package/dist/esm-node/i18n/I18nProvider.js +42 -0
  79. package/dist/esm-node/i18n/LocalizedLink.js +88 -0
  80. package/dist/esm-node/i18n/context.js +3 -0
  81. package/dist/esm-node/i18n/index.js +8 -0
  82. package/dist/esm-node/i18n/languageSync.js +50 -0
  83. package/dist/esm-node/i18n/types.js +1 -0
  84. package/dist/esm-node/i18n/useI18n.js +74 -0
  85. package/dist/esm-node/index.js +58 -0
  86. package/dist/esm-node/manifest.js +150 -0
  87. package/dist/esm-node/native-promise-serialization.js +113 -0
  88. package/dist/esm-node/plugin/compiler.js +209 -0
  89. package/dist/esm-node/plugin/create.js +236 -0
  90. package/dist/esm-node/plugin/index.js +70 -0
  91. package/dist/esm-node/plugin/profile.js +51 -0
  92. package/dist/esm-node/route-completion.js +161 -0
  93. package/dist/esm-node/route-data-error.js +108 -0
  94. package/dist/esm-node/router-binding/Asset.js +172 -0
  95. package/dist/esm-node/router-binding/CatchBoundary.js +136 -0
  96. package/dist/esm-node/router-binding/ClientOnly.js +46 -0
  97. package/dist/esm-node/router-binding/HeadContent.js +8 -0
  98. package/dist/esm-node/router-binding/LICENSE +21 -0
  99. package/dist/esm-node/router-binding/Match.js +660 -0
  100. package/dist/esm-node/router-binding/Matches.js +161 -0
  101. package/dist/esm-node/router-binding/PROVENANCE.json +94 -0
  102. package/dist/esm-node/router-binding/RouterProvider.js +88 -0
  103. package/dist/esm-node/router-binding/SafeFragment.js +5 -0
  104. package/dist/esm-node/router-binding/ScriptOnce.js +16 -0
  105. package/dist/esm-node/router-binding/Scripts.js +49 -0
  106. package/dist/esm-node/router-binding/ScrollRestoration.js +16 -0
  107. package/dist/esm-node/router-binding/Transitioner.js +109 -0
  108. package/dist/esm-node/router-binding/awaited.js +75 -0
  109. package/dist/esm-node/router-binding/fileRoute.js +83 -0
  110. package/dist/esm-node/router-binding/flightData.js +23 -0
  111. package/dist/esm-node/router-binding/headContentUtils.js +168 -0
  112. package/dist/esm-node/router-binding/history.js +1 -0
  113. package/dist/esm-node/router-binding/index.js +35 -0
  114. package/dist/esm-node/router-binding/lazyRouteComponent.js +30 -0
  115. package/dist/esm-node/router-binding/link.js +399 -0
  116. package/dist/esm-node/router-binding/matchContext.js +7 -0
  117. package/dist/esm-node/router-binding/nonRouteComponentContext.js +22 -0
  118. package/dist/esm-node/router-binding/not-found.js +49 -0
  119. package/dist/esm-node/router-binding/publicMatchData.js +447 -0
  120. package/dist/esm-node/router-binding/registryTransfer.js +223 -0
  121. package/dist/esm-node/router-binding/renderRouteNotFound.js +22 -0
  122. package/dist/esm-node/router-binding/route.js +162 -0
  123. package/dist/esm-node/router-binding/router.js +14 -0
  124. package/dist/esm-node/router-binding/routerContext.js +3 -0
  125. package/dist/esm-node/router-binding/routerOptions.js +1 -0
  126. package/dist/esm-node/router-binding/routerStores.js +50 -0
  127. package/dist/esm-node/router-binding/scroll-restoration.js +12 -0
  128. package/dist/esm-node/router-binding/typePrimitives.js +1 -0
  129. package/dist/esm-node/router-binding/useBlocker.js +152 -0
  130. package/dist/esm-node/router-binding/useCanGoBack.js +7 -0
  131. package/dist/esm-node/router-binding/useLoaderData.js +8 -0
  132. package/dist/esm-node/router-binding/useLoaderDeps.js +8 -0
  133. package/dist/esm-node/router-binding/useLocation.js +14 -0
  134. package/dist/esm-node/router-binding/useMatch.js +28 -0
  135. package/dist/esm-node/router-binding/useNavigate.js +25 -0
  136. package/dist/esm-node/router-binding/useParams.js +11 -0
  137. package/dist/esm-node/router-binding/useRouteContext.js +8 -0
  138. package/dist/esm-node/router-binding/useRouter.js +10 -0
  139. package/dist/esm-node/router-binding/useRouterState.js +19 -0
  140. package/dist/esm-node/router-binding/useSearch.js +11 -0
  141. package/dist/esm-node/router-binding/utils.js +23 -0
  142. package/dist/esm-node/router.js +187 -0
  143. package/dist/esm-node/server.js +396 -0
  144. package/dist/types/actions.d.ts +45 -0
  145. package/dist/types/application-router.d.ts +5 -0
  146. package/dist/types/client.d.ts +23 -0
  147. package/dist/types/entry-application.d.ts +10 -0
  148. package/dist/types/entry-client.d.ts +5 -0
  149. package/dist/types/entry-server.d.ts +5 -0
  150. package/dist/types/federation-context.d.ts +16 -0
  151. package/dist/types/federation-ssr.d.ts +19 -0
  152. package/dist/types/federation.d.ts +30 -0
  153. package/dist/types/i18n/I18nProvider.d.ts +21 -0
  154. package/dist/types/i18n/LocalizedLink.d.ts +15 -0
  155. package/dist/types/i18n/context.d.ts +11 -0
  156. package/dist/types/i18n/index.d.ts +9 -0
  157. package/dist/types/i18n/languageSync.d.ts +31 -0
  158. package/dist/types/i18n/types.d.ts +33 -0
  159. package/dist/types/i18n/useI18n.d.ts +24 -0
  160. package/dist/types/index.d.ts +41 -0
  161. package/dist/types/manifest.d.ts +55 -0
  162. package/dist/types/native-promise-serialization.d.ts +9 -0
  163. package/dist/types/plugin/compiler.d.ts +6 -0
  164. package/dist/types/plugin/create.d.ts +21 -0
  165. package/dist/types/plugin/index.d.ts +3 -0
  166. package/dist/types/plugin/lazy-modules.d.cts +15 -0
  167. package/dist/types/plugin/preserve-import-loader.d.cts +3 -0
  168. package/dist/types/plugin/profile.d.ts +2 -0
  169. package/dist/types/plugin/solid-loader.d.cts +2 -0
  170. package/dist/types/plugin/svg-component-template.d.cts +6 -0
  171. package/dist/types/route-completion.d.ts +21 -0
  172. package/dist/types/route-data-error.d.ts +17 -0
  173. package/dist/types/router-binding/Asset.d.ts +3 -0
  174. package/dist/types/router-binding/CatchBoundary.d.ts +13 -0
  175. package/dist/types/router-binding/ClientOnly.d.ts +31 -0
  176. package/dist/types/router-binding/HeadContent.d.ts +13 -0
  177. package/dist/types/router-binding/Match.d.ts +6 -0
  178. package/dist/types/router-binding/Matches.d.ts +26 -0
  179. package/dist/types/router-binding/RouterProvider.d.ts +11 -0
  180. package/dist/types/router-binding/SafeFragment.d.ts +2 -0
  181. package/dist/types/router-binding/ScriptOnce.d.ts +6 -0
  182. package/dist/types/router-binding/Scripts.d.ts +2 -0
  183. package/dist/types/router-binding/ScrollRestoration.d.ts +14 -0
  184. package/dist/types/router-binding/Transitioner.d.ts +2 -0
  185. package/dist/types/router-binding/awaited.d.ts +11 -0
  186. package/dist/types/router-binding/fileRoute.d.ts +54 -0
  187. package/dist/types/router-binding/flightData.d.ts +38 -0
  188. package/dist/types/router-binding/headContentUtils.d.ts +15 -0
  189. package/dist/types/router-binding/history.d.ts +8 -0
  190. package/dist/types/router-binding/index.d.ts +46 -0
  191. package/dist/types/router-binding/lazyRouteComponent.d.ts +2 -0
  192. package/dist/types/router-binding/link.d.ts +43 -0
  193. package/dist/types/router-binding/matchContext.d.ts +7 -0
  194. package/dist/types/router-binding/nonRouteComponentContext.d.ts +5 -0
  195. package/dist/types/router-binding/not-found.d.ts +11 -0
  196. package/dist/types/router-binding/publicMatchData.d.ts +19 -0
  197. package/dist/types/router-binding/registryTransfer.d.ts +49 -0
  198. package/dist/types/router-binding/renderRouteNotFound.d.ts +11 -0
  199. package/dist/types/router-binding/route.d.ts +105 -0
  200. package/dist/types/router-binding/router.d.ts +70 -0
  201. package/dist/types/router-binding/routerContext.d.ts +3 -0
  202. package/dist/types/router-binding/routerOptions.d.ts +6 -0
  203. package/dist/types/router-binding/routerStores.d.ts +2 -0
  204. package/dist/types/router-binding/scroll-restoration.d.ts +2 -0
  205. package/dist/types/router-binding/typePrimitives.d.ts +10 -0
  206. package/dist/types/router-binding/useBlocker.d.ts +70 -0
  207. package/dist/types/router-binding/useCanGoBack.d.ts +2 -0
  208. package/dist/types/router-binding/useLoaderData.d.ts +8 -0
  209. package/dist/types/router-binding/useLoaderDeps.d.ts +8 -0
  210. package/dist/types/router-binding/useLocation.d.ts +7 -0
  211. package/dist/types/router-binding/useMatch.d.ts +10 -0
  212. package/dist/types/router-binding/useNavigate.d.ts +5 -0
  213. package/dist/types/router-binding/useParams.d.ts +9 -0
  214. package/dist/types/router-binding/useRouteContext.d.ts +4 -0
  215. package/dist/types/router-binding/useRouter.d.ts +4 -0
  216. package/dist/types/router-binding/useRouterState.d.ts +8 -0
  217. package/dist/types/router-binding/useSearch.d.ts +9 -0
  218. package/dist/types/router-binding/utils.d.ts +25 -0
  219. package/dist/types/router.d.ts +31 -0
  220. package/dist/types/server.d.ts +47 -0
  221. package/package.json +130 -4
  222. package/src/actions.tsx +441 -0
  223. package/src/application-router.tsx +47 -0
  224. package/src/client.ts +106 -0
  225. package/src/entry-application.tsx +73 -0
  226. package/src/entry-client.tsx +49 -0
  227. package/src/entry-server.tsx +85 -0
  228. package/src/federation-context.ts +47 -0
  229. package/src/federation-ssr.ts +136 -0
  230. package/src/federation.tsx +197 -0
  231. package/src/i18n/I18nProvider.tsx +54 -0
  232. package/src/i18n/LocalizedLink.tsx +83 -0
  233. package/src/i18n/context.ts +13 -0
  234. package/src/i18n/index.ts +31 -0
  235. package/src/i18n/languageSync.ts +113 -0
  236. package/src/i18n/types.ts +35 -0
  237. package/src/i18n/useI18n.ts +121 -0
  238. package/src/index.ts +41 -0
  239. package/src/manifest.ts +337 -0
  240. package/src/native-promise-serialization.ts +167 -0
  241. package/src/plugin/compiler.ts +320 -0
  242. package/src/plugin/create.ts +271 -0
  243. package/src/plugin/index.ts +69 -0
  244. package/src/plugin/lazy-modules.cjs +146 -0
  245. package/src/plugin/preserve-import-loader.cjs +46 -0
  246. package/src/plugin/profile.ts +42 -0
  247. package/src/plugin/solid-loader.cjs +83 -0
  248. package/src/plugin/svg-component-template.cjs +19 -0
  249. package/src/route-completion.tsx +226 -0
  250. package/src/route-data-error.ts +175 -0
  251. package/src/router-binding/Asset.tsx +284 -0
  252. package/src/router-binding/CatchBoundary.tsx +130 -0
  253. package/src/router-binding/ClientOnly.tsx +76 -0
  254. package/src/router-binding/HeadContent.tsx +23 -0
  255. package/src/router-binding/LICENSE +21 -0
  256. package/src/router-binding/Match.tsx +397 -0
  257. package/src/router-binding/Matches.tsx +242 -0
  258. package/src/router-binding/PROVENANCE.json +94 -0
  259. package/src/router-binding/RouterProvider.tsx +128 -0
  260. package/src/router-binding/SafeFragment.tsx +5 -0
  261. package/src/router-binding/ScriptOnce.tsx +23 -0
  262. package/src/router-binding/Scripts.tsx +44 -0
  263. package/src/router-binding/ScrollRestoration.tsx +49 -0
  264. package/src/router-binding/Transitioner.tsx +177 -0
  265. package/src/router-binding/awaited.tsx +71 -0
  266. package/src/router-binding/fileRoute.ts +268 -0
  267. package/src/router-binding/flightData.ts +90 -0
  268. package/src/router-binding/headContentUtils.tsx +292 -0
  269. package/src/router-binding/history.ts +9 -0
  270. package/src/router-binding/index.tsx +315 -0
  271. package/src/router-binding/lazyRouteComponent.tsx +70 -0
  272. package/src/router-binding/link.tsx +865 -0
  273. package/src/router-binding/matchContext.tsx +15 -0
  274. package/src/router-binding/nonRouteComponentContext.tsx +23 -0
  275. package/src/router-binding/not-found.tsx +65 -0
  276. package/src/router-binding/publicMatchData.ts +674 -0
  277. package/src/router-binding/registryTransfer.ts +400 -0
  278. package/src/router-binding/renderRouteNotFound.tsx +53 -0
  279. package/src/router-binding/route.tsx +665 -0
  280. package/src/router-binding/router.ts +123 -0
  281. package/src/router-binding/routerContext.tsx +6 -0
  282. package/src/router-binding/routerOptions.ts +26 -0
  283. package/src/router-binding/routerStores.ts +85 -0
  284. package/src/router-binding/scroll-restoration.tsx +15 -0
  285. package/src/router-binding/typePrimitives.ts +74 -0
  286. package/src/router-binding/useBlocker.tsx +359 -0
  287. package/src/router-binding/useCanGoBack.ts +9 -0
  288. package/src/router-binding/useLoaderData.tsx +51 -0
  289. package/src/router-binding/useLoaderDeps.tsx +46 -0
  290. package/src/router-binding/useLocation.tsx +43 -0
  291. package/src/router-binding/useMatch.tsx +111 -0
  292. package/src/router-binding/useNavigate.tsx +45 -0
  293. package/src/router-binding/useParams.tsx +70 -0
  294. package/src/router-binding/useRouteContext.ts +30 -0
  295. package/src/router-binding/useRouter.tsx +17 -0
  296. package/src/router-binding/useRouterState.tsx +50 -0
  297. package/src/router-binding/useSearch.tsx +70 -0
  298. package/src/router-binding/utils.ts +59 -0
  299. package/src/router.ts +376 -0
  300. package/src/server.ts +645 -0
  301. package/README.md +0 -3
@@ -0,0 +1,187 @@
1
+ import { DataProtocolError } from "@modern-js/renderer-core/data";
2
+ import { RouteDataError, loadFileSystemRoute, matchApplicationRouteIds, matchApplicationRoutes, nativeRoutePath, resolveRouteData, selectApplicationDataRoute, splitFileSystemRoutes, untilAborted } from "@modern-js/renderer-core/router";
3
+ import { createApplicationRouter, createRouteCompletionScope, registerRouteCompletionScope } from "./route-completion.js";
4
+ import { restoreRouteDataError } from "./route-data-error.js";
5
+ import { Outlet, createRootRoute, createRoute, isNotFound, isRedirect, notFound, preparePublicContextData, preparePublicLoaderData, preparePublicMatchError, redirect } from "./router-binding/index.js";
6
+ export * from "./router-binding/index.js";
7
+ function isPublicRecord(value) {
8
+ if (!value || "object" != typeof value) return false;
9
+ const prototype = Object.getPrototypeOf(value);
10
+ return prototype === Object.prototype || null === prototype;
11
+ }
12
+ function resolveApplicationRedirect(router) {
13
+ const result = router._serverResult;
14
+ const value = result?.type === "redirect" ? result.redirect : void 0;
15
+ return isRedirect(value) ? router.resolveRedirect(value) : void 0;
16
+ }
17
+ function getApplicationStatus(router) {
18
+ const result = router._serverResult;
19
+ if (!result) throw new Error("Load the native Solid router before resolving HTTP status");
20
+ return "render" === result.type ? result.status : result.redirect.status;
21
+ }
22
+ function router_resolveRouteData(routeId, outcome, project) {
23
+ return resolveRouteData({
24
+ redirect: redirect,
25
+ notFound: notFound
26
+ }, routeId, outcome, project);
27
+ }
28
+ function createFileSystemRouteTree(routes, modules, options = {}) {
29
+ const { root: rootDescriptor, children } = splitFileSystemRoutes(routes);
30
+ const privateRoots = options.context && ("object" == typeof options.context || "function" == typeof options.context) ? [
31
+ options.context
32
+ ] : [];
33
+ const completionScope = createRouteCompletionScope(privateRoots, options.session);
34
+ const moduleFields = new Set([
35
+ "component",
36
+ "pendingComponent",
37
+ "errorComponent",
38
+ "notFoundComponent",
39
+ "head",
40
+ "beforeLoad",
41
+ "context",
42
+ "validateSearch"
43
+ ]);
44
+ function projectModuleContext(authored, source) {
45
+ try {
46
+ const value = preparePublicContextData(authored, options.session ?? completionScope.hydrationOwner, [
47
+ options.context
48
+ ]);
49
+ if ("context" === source && void 0 !== value && !isPublicRecord(value)) throw new DataProtocolError("Native Solid route context must return a synchronous public record");
50
+ if ("search" === source && !isPublicRecord(value)) throw new DataProtocolError("Native Solid search validation must return a public record");
51
+ return value;
52
+ } catch (error) {
53
+ options.session?.fail(error);
54
+ throw error;
55
+ }
56
+ }
57
+ function routeModuleOptions(id) {
58
+ const module = modules[id] ?? {};
59
+ const prototype = Object.getPrototypeOf(module);
60
+ if (prototype !== Object.prototype && null !== prototype) throw new DataProtocolError("Native Solid filesystem route modules require plain option records");
61
+ for (const key of Reflect.ownKeys(module)){
62
+ const descriptor = Object.getOwnPropertyDescriptor(module, key);
63
+ if ("string" != typeof key || !moduleFields.has(key) || descriptor.get || descriptor.set) throw new DataProtocolError("Unsupported native Solid filesystem route option; use the declared public route module contract");
64
+ }
65
+ const beforeLoad = module.beforeLoad;
66
+ const validateSearch = module.validateSearch;
67
+ const context = module.context;
68
+ const contextOptions = context ? {
69
+ context (...args) {
70
+ return projectModuleContext(context(...args), "context");
71
+ }
72
+ } : {};
73
+ const searchOptions = validateSearch ? {
74
+ validateSearch (search) {
75
+ return projectModuleContext(validateSearch(search), "search");
76
+ }
77
+ } : {};
78
+ if (!beforeLoad) return {
79
+ ...module,
80
+ ...searchOptions,
81
+ ...contextOptions
82
+ };
83
+ return {
84
+ ...module,
85
+ ...searchOptions,
86
+ ...contextOptions,
87
+ beforeLoad: async (...args)=>{
88
+ const signal = args[0]?.abortController?.signal;
89
+ let value;
90
+ try {
91
+ value = await (signal ? untilAborted(beforeLoad(...args), signal) : beforeLoad(...args));
92
+ } catch (error) {
93
+ if (signal?.aborted) throw error;
94
+ if (isRedirect(error)) throw error;
95
+ let projected;
96
+ try {
97
+ projected = isNotFound(error) ? preparePublicContextData(error, options.session, [
98
+ options.context
99
+ ]) : preparePublicMatchError(error, options.session, [
100
+ options.context
101
+ ]);
102
+ } catch (invalid) {
103
+ options.session?.fail(invalid);
104
+ throw invalid;
105
+ }
106
+ if (isNotFound(projected)) throw projected;
107
+ if (projected && "object" == typeof projected && Object.getOwnPropertyDescriptor(projected, "kind")?.value === "ultramodern-route-data-error") throw Object.freeze(restoreRouteDataError(projected));
108
+ const message = projected && "object" == typeof projected ? Object.getOwnPropertyDescriptor(projected, "message")?.value : void 0;
109
+ const name = projected && "object" == typeof projected ? Object.getOwnPropertyDescriptor(projected, "name")?.value : void 0;
110
+ const diagnostic = new Error("string" == typeof message ? message : "Unexpected Server Error");
111
+ diagnostic.name = "string" == typeof name ? name : "Error";
112
+ if (projected && "object" == typeof projected) for (const key of [
113
+ "cause",
114
+ "stack"
115
+ ]){
116
+ const descriptor = Object.getOwnPropertyDescriptor(projected, key);
117
+ if (descriptor && !descriptor.get && !descriptor.set) Object.defineProperty(diagnostic, key, {
118
+ value: descriptor.value,
119
+ configurable: true,
120
+ writable: true
121
+ });
122
+ }
123
+ throw Object.freeze(diagnostic);
124
+ }
125
+ return projectModuleContext(value, "beforeLoad");
126
+ }
127
+ };
128
+ }
129
+ function loaderOptions(route) {
130
+ const loadRoute = options.loadRoute;
131
+ if (!(route.modules?.data || route.modules?.clientData) || !loadRoute) return {};
132
+ return {
133
+ loader: async (match)=>{
134
+ const { outcome, request, signal } = await loadFileSystemRoute(route, loadRoute, options, match);
135
+ options.onOutcome?.(route.id, outcome);
136
+ const generation = completionScope.begin(signal, ()=>match.abortController.abort());
137
+ const owner = options.session ?? generation.owner;
138
+ const project = (value)=>{
139
+ try {
140
+ return preparePublicLoaderData(value, owner, [
141
+ options.context,
142
+ request
143
+ ]);
144
+ } catch (error) {
145
+ owner.fail(error);
146
+ throw error;
147
+ }
148
+ };
149
+ const value = router_resolveRouteData(route.id, outcome, project);
150
+ generation.publish(value, "completion" in outcome ? outcome.completion : void 0);
151
+ return value;
152
+ }
153
+ };
154
+ }
155
+ const root = createRootRoute({
156
+ ...routeModuleOptions(rootDescriptor?.id ?? ""),
157
+ component: completionScope.component(modules[rootDescriptor?.id ?? ""]?.component ?? Outlet),
158
+ staticData: {
159
+ ultramodernRouteId: rootDescriptor?.id
160
+ },
161
+ ...rootDescriptor ? loaderOptions(rootDescriptor) : {}
162
+ });
163
+ function bind(route, parent, inheritedErrorComponent) {
164
+ const errorComponent = modules[route.id]?.errorComponent ?? inheritedErrorComponent;
165
+ const native = createRoute({
166
+ getParentRoute: ()=>parent,
167
+ ...nativeRoutePath(route),
168
+ ...routeModuleOptions(route.id),
169
+ ...errorComponent ? {
170
+ errorComponent
171
+ } : {},
172
+ component: completionScope.component(modules[route.id]?.component ?? Outlet),
173
+ staticData: {
174
+ ultramodernRouteId: route.id
175
+ },
176
+ ...loaderOptions(route)
177
+ });
178
+ return native.addChildren(route.children.map((child)=>bind(child, native, errorComponent)));
179
+ }
180
+ const rootErrorComponent = modules[rootDescriptor?.id ?? ""]?.errorComponent;
181
+ const tree = root.addChildren(children.map((route)=>bind(route, root, rootErrorComponent)));
182
+ registerRouteCompletionScope(tree, completionScope);
183
+ return tree;
184
+ }
185
+ export { ActionForm, RouteActionError, createRouteAction, useRouteAction } from "./actions.js";
186
+ export { ApplicationRouter } from "./application-router.js";
187
+ export { RouteDataError, createApplicationRouter, createFileSystemRouteTree, getApplicationStatus, matchApplicationRouteIds, matchApplicationRoutes, resolveApplicationRedirect, router_resolveRouteData as resolveRouteData, selectApplicationDataRoute };
@@ -0,0 +1,263 @@
1
+ import { getRequestEvent, ssrElement, ssrElementAttribute } from "@solidjs/web";
2
+ import { createDataClient } from "@modern-js/renderer-core/data";
3
+ import { assertRendererIdentity, identityCacheKey } from "@modern-js/renderer-core/identity";
4
+ import { createSignal, getOwner, omit, onCleanup, untrack } from "solid-js";
5
+ import { redirect, useMatch, useRouter } from "./router-binding/index.js";
6
+ import { preparePublicLoaderData, preparePublicMatchError } from "./router-binding/publicMatchData.js";
7
+ var _sk$ = (k)=>"action" === k || "method" === k || "enctype" === k;
8
+ class RouteActionError extends Error {
9
+ constructor(routeId, outcome){
10
+ super("error" === outcome.kind ? outcome.error.message : "Action route not found");
11
+ this.name = "error" === outcome.kind ? outcome.error.name : "RouteNotFound";
12
+ this.routeId = routeId;
13
+ this.status = outcome.status;
14
+ this.data = "error" === outcome.kind ? outcome.data : outcome.value;
15
+ this.outcome = outcome;
16
+ Reflect.deleteProperty(this, "stack");
17
+ const stack = "error" === outcome.kind ? Object.getOwnPropertyDescriptor(outcome.error, "stack")?.value : void 0;
18
+ if ("string" == typeof stack) this.stack = stack;
19
+ Object.freeze(this);
20
+ }
21
+ }
22
+ function actionFailure(cause, owner, privateContexts = []) {
23
+ let projection;
24
+ try {
25
+ projection = preparePublicMatchError(cause instanceof Error ? cause : new Error("The Solid route action failed", {
26
+ cause
27
+ }), owner, privateContexts);
28
+ } catch {
29
+ projection = Object.freeze({
30
+ name: "DataProtocolError",
31
+ message: "Invalid public Solid action error"
32
+ });
33
+ }
34
+ const nested = "error" in projection ? projection.error : void 0;
35
+ const diagnostic = nested && "object" == typeof nested ? nested : projection;
36
+ const failure = new Error("string" == typeof diagnostic.message && "Unexpected Server Error" !== diagnostic.message ? diagnostic.message : "The Solid route action failed", Object.hasOwn(diagnostic, "cause") ? {
37
+ cause: diagnostic.cause
38
+ } : void 0);
39
+ failure.name = "string" == typeof diagnostic.name ? diagnostic.name : "Error";
40
+ Reflect.deleteProperty(failure, "stack");
41
+ if ("string" == typeof diagnostic.stack) failure.stack = diagnostic.stack;
42
+ return Object.freeze(failure);
43
+ }
44
+ function actionOutcome(result, owner, privateContexts) {
45
+ if ("success" !== result.kind) return preparePublicLoaderData(result, owner, privateContexts);
46
+ return Object.freeze({
47
+ kind: "success",
48
+ value: preparePublicLoaderData(result.value, owner, privateContexts),
49
+ status: result.status
50
+ });
51
+ }
52
+ function routerIdentity(router) {
53
+ const context = router.options.context;
54
+ if (context?.ultramodern === void 0) return;
55
+ const identity = context.ultramodern?.rendererIdentity;
56
+ if (!identity) throw new Error("Solid router context requires its renderer identity");
57
+ identityCacheKey(identity);
58
+ return identity;
59
+ }
60
+ function createRouteAction(options) {
61
+ const { router, routeId } = options;
62
+ if (!routeId) throw new Error("A Solid action requires its filesystem route ID");
63
+ identityCacheKey(options.rendererIdentity);
64
+ if ("solid" !== options.rendererIdentity.renderer) throw new Error("A Solid action requires the Solid renderer identity");
65
+ const configuredIdentity = routerIdentity(router);
66
+ if (configuredIdentity) assertRendererIdentity(options.rendererIdentity, configuredIdentity);
67
+ const identity = Object.freeze({
68
+ ...options.rendererIdentity
69
+ });
70
+ const client = createDataClient(routeId, identity, options.fetch ? {
71
+ fetch: options.fetch
72
+ } : {});
73
+ const requestURL = getRequestEvent()?.request.url;
74
+ const url = ()=>{
75
+ const base = "u" < typeof window ? requestURL : window.location.href;
76
+ const location = options.url ?? router.state.location.publicHref;
77
+ if (!base && !URL.canParse(String(location))) throw new Error("A server Solid action requires its native request URL");
78
+ return new URL(location, base).href;
79
+ };
80
+ const [pending, setPending] = createSignal(false);
81
+ const [outcome, setOutcome] = createSignal();
82
+ const [error, setError] = createSignal();
83
+ let active;
84
+ let disposed = false;
85
+ function cancel() {
86
+ const current = active;
87
+ if (!current) return;
88
+ active = void 0;
89
+ current.abort(new DOMException("The action was cancelled", "AbortError"));
90
+ setPending(false);
91
+ }
92
+ function dispose() {
93
+ if (disposed) return;
94
+ disposed = true;
95
+ cancel();
96
+ }
97
+ function submit(request) {
98
+ if (disposed) throw new Error("The Solid action owner has been disposed");
99
+ if ("GET" === request.method || "HEAD" === request.method) throw new Error("A Solid action requires a mutation Request");
100
+ cancel();
101
+ const controller = new AbortController();
102
+ active = controller;
103
+ const signal = controller.signal;
104
+ const abortRequest = ()=>controller.abort(request.signal.reason);
105
+ if (request.signal.aborted) abortRequest();
106
+ else request.signal.addEventListener("abort", abortRequest, {
107
+ once: true
108
+ });
109
+ const current = ()=>active === controller && !signal.aborted && !disposed;
110
+ const privateContexts = [
111
+ router.options.context,
112
+ request
113
+ ];
114
+ const owner = {
115
+ signal,
116
+ fail (failure) {
117
+ if (!current()) return;
118
+ setError(actionFailure(failure, owner, privateContexts));
119
+ controller.abort(failure);
120
+ }
121
+ };
122
+ setOutcome(void 0);
123
+ setError(void 0);
124
+ setPending(true);
125
+ const cancelled = Symbol("cancelled action");
126
+ let resolveCancellation;
127
+ const cancellation = new Promise((resolve)=>{
128
+ resolveCancellation = resolve;
129
+ });
130
+ const abort = ()=>{
131
+ if (active === controller) {
132
+ active = void 0;
133
+ setPending(false);
134
+ }
135
+ resolveCancellation(cancelled);
136
+ };
137
+ if (signal.aborted) abort();
138
+ else signal.addEventListener("abort", abort, {
139
+ once: true
140
+ });
141
+ return (async ()=>{
142
+ try {
143
+ if (!current()) return;
144
+ const result = await Promise.race([
145
+ client.action({
146
+ request: new Request(request, {
147
+ signal
148
+ })
149
+ }),
150
+ cancellation
151
+ ]);
152
+ if (result === cancelled || !current()) return;
153
+ const publicResult = actionOutcome(result, owner, privateContexts);
154
+ setOutcome(publicResult);
155
+ if (await Promise.race([
156
+ Promise.resolve(result.completion),
157
+ cancellation
158
+ ]) === cancelled || !current()) return;
159
+ if ("error" === publicResult.kind || "not-found" === publicResult.kind) setError(new RouteActionError(routeId, publicResult));
160
+ else if ("redirect" === result.kind) {
161
+ if (307 === result.status || 308 === result.status || (301 === result.status || 302 === result.status) && "POST" !== request.method) throw new Error(`A native action redirect must not preserve the method (HTTP ${result.status} after ${request.method}); redirect with 303 to navigate after the mutation`);
162
+ const resolved = router.resolveRedirect(redirect({
163
+ href: new URL(result.location, request.url).href,
164
+ statusCode: result.status
165
+ }));
166
+ const navigation = router.navigate({
167
+ ...resolved.options,
168
+ replace: true
169
+ });
170
+ const refresh = resolved.options.reloadDocument ? Promise.resolve() : router.invalidate({
171
+ sync: true
172
+ });
173
+ await Promise.race([
174
+ Promise.all([
175
+ navigation,
176
+ refresh
177
+ ]),
178
+ cancellation
179
+ ]);
180
+ } else if (result.status < 400) await Promise.race([
181
+ router.invalidate({
182
+ sync: true
183
+ }),
184
+ cancellation
185
+ ]);
186
+ return current() ? publicResult : void 0;
187
+ } catch (failure) {
188
+ owner.fail(failure);
189
+ return;
190
+ } finally{
191
+ request.signal.removeEventListener("abort", abortRequest);
192
+ signal.removeEventListener("abort", abort);
193
+ if (active === controller) {
194
+ active = void 0;
195
+ setPending(false);
196
+ }
197
+ }
198
+ })();
199
+ }
200
+ async function submitForm(form, submitter) {
201
+ try {
202
+ const button = submitter instanceof HTMLButtonElement || submitter instanceof HTMLInputElement ? submitter : void 0;
203
+ const method = button?.hasAttribute("formmethod") ? button.formMethod : form.method;
204
+ if ("post" !== method.toLowerCase()) throw new Error("A Solid action form requires method=\"post\"");
205
+ const target = button?.hasAttribute("formtarget") ? button.formTarget : form.target;
206
+ if (target && "_self" !== target.toLowerCase()) throw new Error("A Solid action form requires the current browsing context");
207
+ const destination = button?.hasAttribute("formaction") ? button.formAction : form.action;
208
+ const formData = new FormData(form, button);
209
+ const encoding = button?.hasAttribute("formenctype") ? button.formEnctype : form.enctype;
210
+ let body;
211
+ if ("multipart/form-data" === encoding) body = formData;
212
+ else if ("application/x-www-form-urlencoded" === encoding) {
213
+ const encoded = new URLSearchParams();
214
+ for (const [name, value] of formData)encoded.append(name, "string" == typeof value ? value : value.name);
215
+ body = encoded;
216
+ } else throw new Error(`Unsupported Solid action form encoding: ${encoding}`);
217
+ return await submit(new Request(new URL(destination || url(), url()), {
218
+ method: "POST",
219
+ body,
220
+ credentials: "same-origin"
221
+ }));
222
+ } catch (failure) {
223
+ if (!disposed) setError(actionFailure(failure, void 0, [
224
+ router.options.context
225
+ ]));
226
+ return;
227
+ }
228
+ }
229
+ if (getOwner()) onCleanup(dispose);
230
+ return Object.freeze({
231
+ routeId,
232
+ pending,
233
+ outcome,
234
+ error,
235
+ url,
236
+ submit,
237
+ submitForm,
238
+ cancel,
239
+ dispose
240
+ });
241
+ }
242
+ function useRouteAction() {
243
+ const router = useRouter();
244
+ if (!router) throw new Error("useRouteAction requires a native Solid router");
245
+ const identity = routerIdentity(router);
246
+ if (!identity) throw new Error("useRouteAction requires the application renderer identity");
247
+ const match = useMatch({
248
+ strict: false
249
+ });
250
+ const routeMatch = untrack(match);
251
+ const route = router.routesById[routeMatch.routeId];
252
+ const routeId = route?.options.staticData?.ultramodernRouteId;
253
+ if (!routeId) throw new Error("useRouteAction requires a native filesystem route");
254
+ return createRouteAction({
255
+ router,
256
+ routeId,
257
+ rendererIdentity: identity
258
+ });
259
+ }
260
+ function ActionForm(props) {
261
+ return ssrElement("form", ()=>omit(props, "action"), void 0, true, _sk$, ()=>ssrElementAttribute("action", props.action.url()) + " method=\"post\"" + ssrElementAttribute("enctype", props.enctype ?? "application/x-www-form-urlencoded"));
262
+ }
263
+ export { ActionForm, RouteActionError, createRouteAction, useRouteAction };
@@ -0,0 +1,30 @@
1
+ import { getRequestEvent, mergeProps, useHead } from "@solidjs/web";
2
+ import { DataProtocolError } from "@modern-js/renderer-core/data";
3
+ import { ownApplicationRouteData } from "./route-completion.js";
4
+ import { toHeadTags, useTags } from "./router-binding/headContentUtils.js";
5
+ import { Matches } from "./router-binding/Matches.js";
6
+ import { RouterContextProvider } from "./router-binding/RouterProvider.js";
7
+ function ApplicationHead() {
8
+ const tags = useTags();
9
+ useHead(()=>toHeadTags(tags()));
10
+ return null;
11
+ }
12
+ function ApplicationRouter(props) {
13
+ if (Object.hasOwn(props, "context")) {
14
+ const error = new DataProtocolError("Set public Solid router context in createApplicationRouter; ApplicationRouter context overrides are unsupported");
15
+ const session = getRequestEvent()?.locals.session;
16
+ session?.fail(error);
17
+ throw error;
18
+ }
19
+ const { router, ...rest } = props;
20
+ ownApplicationRouteData(router);
21
+ return RouterContextProvider(mergeProps({
22
+ router
23
+ }, rest, {
24
+ children: ()=>[
25
+ ApplicationHead(),
26
+ Matches({})
27
+ ]
28
+ }));
29
+ }
30
+ export { ApplicationRouter };
@@ -0,0 +1,49 @@
1
+ import { readDocumentBootstrap } from "@modern-js/renderer-core/document";
2
+ import { hydrate, render } from "@solidjs/web";
3
+ import { runWithOwner } from "solid-js";
4
+ import { createFederationScope, provideFederation } from "./federation-context.js";
5
+ function readSolidDocumentBootstrap(document, expectedIdentity) {
6
+ if ("solid" !== expectedIdentity.renderer) throw new Error("The Solid document requires a Solid renderer identity");
7
+ const { identity, documentId, hydrating } = readDocumentBootstrap(document, expectedIdentity);
8
+ return {
9
+ identity,
10
+ documentId,
11
+ hydrating
12
+ };
13
+ }
14
+ const applications = new WeakSet();
15
+ function createApplication(view, element, options, hydrating) {
16
+ if (applications.has(element)) throw new Error("A Solid application already owns this mount element");
17
+ let nativeDispose;
18
+ let disposed = false;
19
+ applications.add(element);
20
+ const dispose = ()=>{
21
+ if (disposed) return;
22
+ disposed = true;
23
+ try {
24
+ nativeDispose?.();
25
+ } finally{
26
+ applications.delete(element);
27
+ }
28
+ };
29
+ try {
30
+ const nativeOptions = {
31
+ renderId: options.renderId,
32
+ onError: options.onError
33
+ };
34
+ const root = provideFederation(createFederationScope(options.federation), view);
35
+ nativeDispose = runWithOwner(null, ()=>hydrating ? hydrate(root, element, nativeOptions) : render(root, element, void 0, nativeOptions));
36
+ options.hot?.dispose(dispose);
37
+ return dispose;
38
+ } catch (error) {
39
+ dispose();
40
+ throw error;
41
+ }
42
+ }
43
+ function mountApplication(view, element, options = {}) {
44
+ return createApplication(view, element, options, false);
45
+ }
46
+ function hydrateApplication(view, element, options = {}) {
47
+ return createApplication(view, element, options, true);
48
+ }
49
+ export { hydrateApplication, mountApplication, readSolidDocumentBootstrap };
@@ -0,0 +1,110 @@
1
+ import { ApplicationRouter } from "./application-router.js";
2
+ import { I18nProvider } from "./i18n/I18nProvider.js";
3
+ import { createApplicationRouter } from "./route-completion.js";
4
+ import { createFileSystemRouteTree } from "./router.js";
5
+ import { createMemoryHistory } from "./router-binding/index.js";
6
+ var _m$ = Symbol(), _m$2 = Symbol();
7
+ var _d$ = {
8
+ get () {
9
+ const i18n = this[_m$];
10
+ return i18n.instance;
11
+ },
12
+ enumerable: true,
13
+ configurable: true
14
+ }, _d$2 = {
15
+ get () {
16
+ const i18n = this[_m$];
17
+ return i18n.languages;
18
+ },
19
+ enumerable: true,
20
+ configurable: true
21
+ }, _d$3 = {
22
+ get () {
23
+ const i18n = this[_m$];
24
+ return i18n.localisedUrls;
25
+ },
26
+ enumerable: true,
27
+ configurable: true
28
+ }, _d$4 = {
29
+ get () {
30
+ const App = this[_m$2];
31
+ return App({});
32
+ },
33
+ enumerable: true,
34
+ configurable: true
35
+ };
36
+ function _P$(_p, _p2) {
37
+ this[_m$] = _p;
38
+ this[_m$2] = _p2;
39
+ Object.defineProperty(this, "instance", _d$);
40
+ Object.defineProperty(this, "languages", _d$2);
41
+ Object.defineProperty(this, "localisedUrls", _d$3);
42
+ Object.defineProperty(this, "children", _d$4);
43
+ }
44
+ _P$.prototype = Object.prototype;
45
+ var _d$5 = {
46
+ get () {
47
+ const i18n = this[_m$];
48
+ return i18n.instance;
49
+ },
50
+ enumerable: true,
51
+ configurable: true
52
+ }, _d$6 = {
53
+ get () {
54
+ const i18n = this[_m$];
55
+ return i18n.languages;
56
+ },
57
+ enumerable: true,
58
+ configurable: true
59
+ }, _d$7 = {
60
+ get () {
61
+ const i18n = this[_m$];
62
+ return i18n.localisedUrls;
63
+ },
64
+ enumerable: true,
65
+ configurable: true
66
+ }, _d$8 = {
67
+ get () {
68
+ const router = this[_m$2];
69
+ return ApplicationRouter({
70
+ router
71
+ });
72
+ },
73
+ enumerable: true,
74
+ configurable: true
75
+ };
76
+ function _P$2(_p3, _p4) {
77
+ this[_m$] = _p3;
78
+ this[_m$2] = _p4;
79
+ Object.defineProperty(this, "instance", _d$5);
80
+ Object.defineProperty(this, "languages", _d$6);
81
+ Object.defineProperty(this, "localisedUrls", _d$7);
82
+ Object.defineProperty(this, "children", _d$8);
83
+ }
84
+ _P$2.prototype = Object.prototype;
85
+ const solidRouterFactory = {
86
+ routeTree: (routes, modules, options)=>createFileSystemRouteTree(routes, modules, options),
87
+ router: ({ location, ...options })=>createApplicationRouter({
88
+ ...options,
89
+ ...location ? {
90
+ origin: location.origin,
91
+ history: createMemoryHistory({
92
+ initialEntries: [
93
+ location.href
94
+ ]
95
+ })
96
+ } : {}
97
+ })
98
+ };
99
+ function componentView(component, i18n) {
100
+ const App = component;
101
+ if (!i18n) return ()=>App({});
102
+ return ()=>I18nProvider(new _P$(i18n, App));
103
+ }
104
+ function routerView(router, i18n) {
105
+ if (!i18n) return ()=>ApplicationRouter({
106
+ router
107
+ });
108
+ return ()=>I18nProvider(new _P$2(i18n, router));
109
+ }
110
+ export { componentView, routerView, solidRouterFactory };
@@ -0,0 +1,24 @@
1
+ import { startNativeClientEntry } from "@modern-js/renderer-core/entry-client";
2
+ import { createNativeRouter } from "@modern-js/renderer-core/router";
3
+ import { hydrateApplication, mountApplication, readSolidDocumentBootstrap } from "./client.js";
4
+ import { componentView, routerView, solidRouterFactory } from "./entry-application.js";
5
+ function startNativeClient(options) {
6
+ startNativeClientEntry(options, {
7
+ readBootstrap: readSolidDocumentBootstrap,
8
+ createRouter: (application, routerOptions)=>createNativeRouter(application, routerOptions, solidRouterFactory),
9
+ disposeRouter: (router)=>router.history.destroy(),
10
+ async prepareRouter (router, hydrating) {
11
+ if (!hydrating) await router.load();
12
+ },
13
+ async start ({ root, bootstrap, load }) {
14
+ const view = await load();
15
+ return (bootstrap?.hydrating ? hydrateApplication : mountApplication)("component" === view.kind ? componentView(view.component, view.i18n) : routerView(view.router, view.i18n), root, {
16
+ ...bootstrap ? {
17
+ renderId: bootstrap.documentId
18
+ } : {},
19
+ federation: options.federation
20
+ });
21
+ }
22
+ });
23
+ }
24
+ export { startNativeClient };