@bleedingdev/modern-js-renderer-solid 0.0.0-bootstrap → 3.9.3-ultramodern.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/actions.js +283 -0
- package/dist/esm/application-router.js +25 -0
- package/dist/esm/client.js +49 -0
- package/dist/esm/entry-application.js +60 -0
- package/dist/esm/entry-client.js +23 -0
- package/dist/esm/federation-context.js +25 -0
- package/dist/esm/federation-ssr.js +84 -0
- package/dist/esm/federation.js +83 -0
- package/dist/esm/i18n/I18nProvider.js +33 -0
- package/dist/esm/i18n/LocalizedLink.js +74 -0
- package/dist/esm/i18n/context.js +3 -0
- package/dist/esm/i18n/index.js +8 -0
- package/dist/esm/i18n/languageSync.js +50 -0
- package/dist/esm/i18n/types.js +0 -0
- package/dist/esm/i18n/useI18n.js +74 -0
- package/dist/esm/index.js +58 -0
- package/dist/esm/manifest.js +150 -0
- package/dist/esm/route-completion.js +150 -0
- package/dist/esm/route-data-error.js +108 -0
- package/dist/esm/router-binding/Asset.js +201 -0
- package/dist/esm/router-binding/CatchBoundary.js +94 -0
- package/dist/esm/router-binding/ClientOnly.js +26 -0
- package/dist/esm/router-binding/HeadContent.js +8 -0
- package/dist/esm/router-binding/LICENSE +21 -0
- package/dist/esm/router-binding/Match.js +319 -0
- package/dist/esm/router-binding/Matches.js +117 -0
- package/dist/esm/router-binding/PROVENANCE.json +94 -0
- package/dist/esm/router-binding/RouterProvider.js +51 -0
- package/dist/esm/router-binding/SafeFragment.js +5 -0
- package/dist/esm/router-binding/ScriptOnce.js +15 -0
- package/dist/esm/router-binding/Scripts.js +30 -0
- package/dist/esm/router-binding/ScrollRestoration.js +16 -0
- package/dist/esm/router-binding/Transitioner.js +103 -0
- package/dist/esm/router-binding/awaited.js +48 -0
- package/dist/esm/router-binding/fileRoute.js +83 -0
- package/dist/esm/router-binding/flightData.js +23 -0
- package/dist/esm/router-binding/headContentUtils.js +162 -0
- package/dist/esm/router-binding/history.js +0 -0
- package/dist/esm/router-binding/index.js +35 -0
- package/dist/esm/router-binding/lazyRouteComponent.js +30 -0
- package/dist/esm/router-binding/link.js +389 -0
- package/dist/esm/router-binding/matchContext.js +7 -0
- package/dist/esm/router-binding/nonRouteComponentContext.js +13 -0
- package/dist/esm/router-binding/not-found.js +35 -0
- package/dist/esm/router-binding/publicMatchData.js +447 -0
- package/dist/esm/router-binding/registryTransfer.js +210 -0
- package/dist/esm/router-binding/renderRouteNotFound.js +23 -0
- package/dist/esm/router-binding/route.js +143 -0
- package/dist/esm/router-binding/router.js +13 -0
- package/dist/esm/router-binding/routerContext.js +3 -0
- package/dist/esm/router-binding/routerStores.js +50 -0
- package/dist/esm/router-binding/scroll-restoration.js +13 -0
- package/dist/esm/router-binding/typePrimitives.js +0 -0
- package/dist/esm/router-binding/useBlocker.js +152 -0
- package/dist/esm/router-binding/useCanGoBack.js +7 -0
- package/dist/esm/router-binding/useLoaderData.js +9 -0
- package/dist/esm/router-binding/useLoaderDeps.js +8 -0
- package/dist/esm/router-binding/useLocation.js +14 -0
- package/dist/esm/router-binding/useMatch.js +28 -0
- package/dist/esm/router-binding/useNavigate.js +19 -0
- package/dist/esm/router-binding/useParams.js +13 -0
- package/dist/esm/router-binding/useRouteContext.js +8 -0
- package/dist/esm/router-binding/useRouter.js +10 -0
- package/dist/esm/router-binding/useRouterState.js +19 -0
- package/dist/esm/router-binding/useSearch.js +13 -0
- package/dist/esm/router-binding/utils.js +23 -0
- package/dist/esm/router.js +187 -0
- package/dist/esm-node/actions.js +263 -0
- package/dist/esm-node/application-router.js +25 -0
- package/dist/esm-node/client.js +49 -0
- package/dist/esm-node/entry-application.js +110 -0
- package/dist/esm-node/entry-client.js +23 -0
- package/dist/esm-node/entry-server.js +47 -0
- package/dist/esm-node/federation-context.js +25 -0
- package/dist/esm-node/federation-ssr.js +84 -0
- package/dist/esm-node/federation.js +83 -0
- package/dist/esm-node/i18n/I18nProvider.js +42 -0
- package/dist/esm-node/i18n/LocalizedLink.js +142 -0
- package/dist/esm-node/i18n/context.js +3 -0
- package/dist/esm-node/i18n/index.js +8 -0
- package/dist/esm-node/i18n/languageSync.js +50 -0
- package/dist/esm-node/i18n/types.js +1 -0
- package/dist/esm-node/i18n/useI18n.js +74 -0
- package/dist/esm-node/index.js +58 -0
- package/dist/esm-node/manifest.js +150 -0
- package/dist/esm-node/native-promise-serialization.js +113 -0
- package/dist/esm-node/plugin/compiler.js +209 -0
- package/dist/esm-node/plugin/create.js +235 -0
- package/dist/esm-node/plugin/index.js +73 -0
- package/dist/esm-node/plugin/profile.js +52 -0
- package/dist/esm-node/route-completion.js +160 -0
- package/dist/esm-node/route-data-error.js +108 -0
- package/dist/esm-node/router-binding/Asset.js +171 -0
- package/dist/esm-node/router-binding/CatchBoundary.js +136 -0
- package/dist/esm-node/router-binding/ClientOnly.js +46 -0
- package/dist/esm-node/router-binding/HeadContent.js +8 -0
- package/dist/esm-node/router-binding/LICENSE +21 -0
- package/dist/esm-node/router-binding/Match.js +660 -0
- package/dist/esm-node/router-binding/Matches.js +161 -0
- package/dist/esm-node/router-binding/PROVENANCE.json +94 -0
- package/dist/esm-node/router-binding/RouterProvider.js +87 -0
- package/dist/esm-node/router-binding/SafeFragment.js +5 -0
- package/dist/esm-node/router-binding/ScriptOnce.js +16 -0
- package/dist/esm-node/router-binding/Scripts.js +49 -0
- package/dist/esm-node/router-binding/ScrollRestoration.js +16 -0
- package/dist/esm-node/router-binding/Transitioner.js +103 -0
- package/dist/esm-node/router-binding/awaited.js +75 -0
- package/dist/esm-node/router-binding/fileRoute.js +83 -0
- package/dist/esm-node/router-binding/flightData.js +23 -0
- package/dist/esm-node/router-binding/headContentUtils.js +162 -0
- package/dist/esm-node/router-binding/history.js +1 -0
- package/dist/esm-node/router-binding/index.js +35 -0
- package/dist/esm-node/router-binding/lazyRouteComponent.js +30 -0
- package/dist/esm-node/router-binding/link.js +399 -0
- package/dist/esm-node/router-binding/matchContext.js +7 -0
- package/dist/esm-node/router-binding/nonRouteComponentContext.js +22 -0
- package/dist/esm-node/router-binding/not-found.js +49 -0
- package/dist/esm-node/router-binding/publicMatchData.js +447 -0
- package/dist/esm-node/router-binding/registryTransfer.js +210 -0
- package/dist/esm-node/router-binding/renderRouteNotFound.js +22 -0
- package/dist/esm-node/router-binding/route.js +162 -0
- package/dist/esm-node/router-binding/router.js +13 -0
- package/dist/esm-node/router-binding/routerContext.js +3 -0
- package/dist/esm-node/router-binding/routerStores.js +50 -0
- package/dist/esm-node/router-binding/scroll-restoration.js +12 -0
- package/dist/esm-node/router-binding/typePrimitives.js +1 -0
- package/dist/esm-node/router-binding/useBlocker.js +152 -0
- package/dist/esm-node/router-binding/useCanGoBack.js +7 -0
- package/dist/esm-node/router-binding/useLoaderData.js +9 -0
- package/dist/esm-node/router-binding/useLoaderDeps.js +8 -0
- package/dist/esm-node/router-binding/useLocation.js +14 -0
- package/dist/esm-node/router-binding/useMatch.js +28 -0
- package/dist/esm-node/router-binding/useNavigate.js +19 -0
- package/dist/esm-node/router-binding/useParams.js +13 -0
- package/dist/esm-node/router-binding/useRouteContext.js +8 -0
- package/dist/esm-node/router-binding/useRouter.js +10 -0
- package/dist/esm-node/router-binding/useRouterState.js +19 -0
- package/dist/esm-node/router-binding/useSearch.js +13 -0
- package/dist/esm-node/router-binding/utils.js +23 -0
- package/dist/esm-node/router.js +187 -0
- package/dist/esm-node/server.js +396 -0
- package/dist/types/actions.d.ts +45 -0
- package/dist/types/application-router.d.ts +5 -0
- package/dist/types/client.d.ts +23 -0
- package/dist/types/entry-application.d.ts +10 -0
- package/dist/types/entry-client.d.ts +5 -0
- package/dist/types/entry-server.d.ts +5 -0
- package/dist/types/federation-context.d.ts +16 -0
- package/dist/types/federation-ssr.d.ts +21 -0
- package/dist/types/federation.d.ts +30 -0
- package/dist/types/i18n/I18nProvider.d.ts +21 -0
- package/dist/types/i18n/LocalizedLink.d.ts +43 -0
- package/dist/types/i18n/context.d.ts +11 -0
- package/dist/types/i18n/index.d.ts +9 -0
- package/dist/types/i18n/languageSync.d.ts +31 -0
- package/dist/types/i18n/types.d.ts +33 -0
- package/dist/types/i18n/useI18n.d.ts +24 -0
- package/dist/types/index.d.ts +41 -0
- package/dist/types/manifest.d.ts +55 -0
- package/dist/types/native-promise-serialization.d.ts +9 -0
- package/dist/types/plugin/compiler.d.ts +6 -0
- package/dist/types/plugin/create.d.ts +21 -0
- package/dist/types/plugin/index.d.ts +3 -0
- package/dist/types/plugin/lazy-modules.d.cts +15 -0
- package/dist/types/plugin/preserve-import-loader.d.cts +3 -0
- package/dist/types/plugin/profile.d.ts +2 -0
- package/dist/types/plugin/solid-loader.d.cts +2 -0
- package/dist/types/plugin/svg-component-template.d.cts +6 -0
- package/dist/types/route-completion.d.ts +21 -0
- package/dist/types/route-data-error.d.ts +17 -0
- package/dist/types/router-binding/Asset.d.ts +3 -0
- package/dist/types/router-binding/CatchBoundary.d.ts +13 -0
- package/dist/types/router-binding/ClientOnly.d.ts +31 -0
- package/dist/types/router-binding/HeadContent.d.ts +13 -0
- package/dist/types/router-binding/Match.d.ts +6 -0
- package/dist/types/router-binding/Matches.d.ts +26 -0
- package/dist/types/router-binding/RouterProvider.d.ts +10 -0
- package/dist/types/router-binding/SafeFragment.d.ts +2 -0
- package/dist/types/router-binding/ScriptOnce.d.ts +6 -0
- package/dist/types/router-binding/Scripts.d.ts +2 -0
- package/dist/types/router-binding/ScrollRestoration.d.ts +14 -0
- package/dist/types/router-binding/Transitioner.d.ts +2 -0
- package/dist/types/router-binding/awaited.d.ts +11 -0
- package/dist/types/router-binding/fileRoute.d.ts +54 -0
- package/dist/types/router-binding/flightData.d.ts +38 -0
- package/dist/types/router-binding/headContentUtils.d.ts +15 -0
- package/dist/types/router-binding/history.d.ts +8 -0
- package/dist/types/router-binding/index.d.ts +45 -0
- package/dist/types/router-binding/lazyRouteComponent.d.ts +2 -0
- package/dist/types/router-binding/link.d.ts +43 -0
- package/dist/types/router-binding/matchContext.d.ts +7 -0
- package/dist/types/router-binding/nonRouteComponentContext.d.ts +5 -0
- package/dist/types/router-binding/not-found.d.ts +11 -0
- package/dist/types/router-binding/publicMatchData.d.ts +19 -0
- package/dist/types/router-binding/registryTransfer.d.ts +47 -0
- package/dist/types/router-binding/renderRouteNotFound.d.ts +11 -0
- package/dist/types/router-binding/route.d.ts +105 -0
- package/dist/types/router-binding/router.d.ts +70 -0
- package/dist/types/router-binding/routerContext.d.ts +3 -0
- package/dist/types/router-binding/routerStores.d.ts +2 -0
- package/dist/types/router-binding/scroll-restoration.d.ts +2 -0
- package/dist/types/router-binding/typePrimitives.d.ts +10 -0
- package/dist/types/router-binding/useBlocker.d.ts +70 -0
- package/dist/types/router-binding/useCanGoBack.d.ts +2 -0
- package/dist/types/router-binding/useLoaderData.d.ts +8 -0
- package/dist/types/router-binding/useLoaderDeps.d.ts +8 -0
- package/dist/types/router-binding/useLocation.d.ts +7 -0
- package/dist/types/router-binding/useMatch.d.ts +10 -0
- package/dist/types/router-binding/useNavigate.d.ts +5 -0
- package/dist/types/router-binding/useParams.d.ts +9 -0
- package/dist/types/router-binding/useRouteContext.d.ts +4 -0
- package/dist/types/router-binding/useRouter.d.ts +4 -0
- package/dist/types/router-binding/useRouterState.d.ts +8 -0
- package/dist/types/router-binding/useSearch.d.ts +9 -0
- package/dist/types/router-binding/utils.d.ts +25 -0
- package/dist/types/router.d.ts +31 -0
- package/dist/types/server.d.ts +47 -0
- package/package.json +118 -4
- package/src/actions.tsx +437 -0
- package/src/application-router.tsx +41 -0
- package/src/client.ts +106 -0
- package/src/entry-application.tsx +73 -0
- package/src/entry-client.tsx +48 -0
- package/src/entry-server.tsx +85 -0
- package/src/federation-context.ts +47 -0
- package/src/federation-ssr.ts +117 -0
- package/src/federation.tsx +193 -0
- package/src/i18n/I18nProvider.tsx +54 -0
- package/src/i18n/LocalizedLink.tsx +122 -0
- package/src/i18n/context.ts +13 -0
- package/src/i18n/index.ts +35 -0
- package/src/i18n/languageSync.ts +113 -0
- package/src/i18n/types.ts +35 -0
- package/src/i18n/useI18n.ts +121 -0
- package/src/index.ts +41 -0
- package/src/manifest.ts +337 -0
- package/src/native-promise-serialization.ts +167 -0
- package/src/plugin/compiler.ts +320 -0
- package/src/plugin/create.ts +270 -0
- package/src/plugin/index.ts +72 -0
- package/src/plugin/lazy-modules.cjs +146 -0
- package/src/plugin/preserve-import-loader.cjs +46 -0
- package/src/plugin/profile.ts +42 -0
- package/src/plugin/solid-loader.cjs +83 -0
- package/src/plugin/svg-component-template.cjs +19 -0
- package/src/route-completion.tsx +222 -0
- package/src/route-data-error.ts +175 -0
- package/src/router-binding/Asset.tsx +283 -0
- package/src/router-binding/CatchBoundary.tsx +130 -0
- package/src/router-binding/ClientOnly.tsx +76 -0
- package/src/router-binding/HeadContent.tsx +23 -0
- package/src/router-binding/LICENSE +21 -0
- package/src/router-binding/Match.tsx +397 -0
- package/src/router-binding/Matches.tsx +242 -0
- package/src/router-binding/PROVENANCE.json +94 -0
- package/src/router-binding/RouterProvider.tsx +129 -0
- package/src/router-binding/SafeFragment.tsx +5 -0
- package/src/router-binding/ScriptOnce.tsx +23 -0
- package/src/router-binding/Scripts.tsx +44 -0
- package/src/router-binding/ScrollRestoration.tsx +49 -0
- package/src/router-binding/Transitioner.tsx +172 -0
- package/src/router-binding/awaited.tsx +71 -0
- package/src/router-binding/fileRoute.ts +268 -0
- package/src/router-binding/flightData.ts +90 -0
- package/src/router-binding/headContentUtils.tsx +290 -0
- package/src/router-binding/history.ts +9 -0
- package/src/router-binding/index.tsx +318 -0
- package/src/router-binding/lazyRouteComponent.tsx +70 -0
- package/src/router-binding/link.tsx +865 -0
- package/src/router-binding/matchContext.tsx +15 -0
- package/src/router-binding/nonRouteComponentContext.tsx +23 -0
- package/src/router-binding/not-found.tsx +65 -0
- package/src/router-binding/publicMatchData.ts +674 -0
- package/src/router-binding/registryTransfer.ts +383 -0
- package/src/router-binding/renderRouteNotFound.tsx +53 -0
- package/src/router-binding/route.tsx +665 -0
- package/src/router-binding/router.ts +121 -0
- package/src/router-binding/routerContext.tsx +6 -0
- package/src/router-binding/routerStores.ts +85 -0
- package/src/router-binding/scroll-restoration.tsx +15 -0
- package/src/router-binding/typePrimitives.ts +74 -0
- package/src/router-binding/useBlocker.tsx +359 -0
- package/src/router-binding/useCanGoBack.ts +9 -0
- package/src/router-binding/useLoaderData.tsx +50 -0
- package/src/router-binding/useLoaderDeps.tsx +46 -0
- package/src/router-binding/useLocation.tsx +43 -0
- package/src/router-binding/useMatch.tsx +111 -0
- package/src/router-binding/useNavigate.tsx +43 -0
- package/src/router-binding/useParams.tsx +72 -0
- package/src/router-binding/useRouteContext.ts +30 -0
- package/src/router-binding/useRouter.tsx +17 -0
- package/src/router-binding/useRouterState.tsx +50 -0
- package/src/router-binding/useSearch.tsx +72 -0
- package/src/router-binding/utils.ts +59 -0
- package/src/router.ts +376 -0
- package/src/server.ts +645 -0
|
@@ -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, {
|
|
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,25 @@
|
|
|
1
|
+
import { 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")) throw new DataProtocolError("Set public Solid router context in createApplicationRouter; ApplicationRouter context overrides are unsupported");
|
|
14
|
+
const { router, ...rest } = props;
|
|
15
|
+
ownApplicationRouteData(router);
|
|
16
|
+
return RouterContextProvider(mergeProps({
|
|
17
|
+
router
|
|
18
|
+
}, rest, {
|
|
19
|
+
children: ()=>[
|
|
20
|
+
ApplicationHead(),
|
|
21
|
+
Matches({})
|
|
22
|
+
]
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
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,23 @@
|
|
|
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
|
+
async prepareRouter (router, hydrating) {
|
|
10
|
+
if (!hydrating) await router.load();
|
|
11
|
+
},
|
|
12
|
+
async start ({ root, bootstrap, load }) {
|
|
13
|
+
const view = await load();
|
|
14
|
+
return (bootstrap?.hydrating ? hydrateApplication : mountApplication)("component" === view.kind ? componentView(view.component, view.i18n) : routerView(view.router, view.i18n), root, {
|
|
15
|
+
...bootstrap ? {
|
|
16
|
+
renderId: bootstrap.documentId
|
|
17
|
+
} : {},
|
|
18
|
+
federation: options.federation
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export { startNativeClient };
|