@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/cli/index.js +268 -0
- package/dist/cjs/cli/tanstackTypes.js +388 -0
- package/dist/cjs/cli.js +65 -0
- package/dist/cjs/runtime/DefaultNotFound.js +47 -0
- package/dist/cjs/runtime/basepathRewrite.js +62 -0
- package/dist/cjs/runtime/dataMutation.js +345 -0
- package/dist/cjs/runtime/hooks.js +57 -0
- package/dist/cjs/runtime/index.js +114 -0
- package/dist/cjs/runtime/lifecycle.js +125 -0
- package/dist/cjs/runtime/plugin.js +250 -0
- package/dist/cjs/runtime/plugin.node.js +304 -0
- package/dist/cjs/runtime/prefetchLink.js +55 -0
- package/dist/cjs/runtime/routeTree.js +492 -0
- package/dist/cjs/runtime/rsc/ClientSlot.js +53 -0
- package/dist/cjs/runtime/rsc/CompositeComponent.js +75 -0
- package/dist/cjs/runtime/rsc/ReplayableStream.js +141 -0
- package/dist/cjs/runtime/rsc/RscNodeRenderer.js +65 -0
- package/dist/cjs/runtime/rsc/SlotContext.js +54 -0
- package/dist/cjs/runtime/rsc/client.js +93 -0
- package/dist/cjs/runtime/rsc/createRscProxy.js +141 -0
- package/dist/cjs/runtime/rsc/index.js +42 -0
- package/dist/cjs/runtime/rsc/payloadRouter.js +211 -0
- package/dist/cjs/runtime/rsc/server.js +246 -0
- package/dist/cjs/runtime/rsc/slotUsageSanitizer.js +65 -0
- package/dist/cjs/runtime/rsc/symbols.js +72 -0
- package/dist/cjs/runtime/types.js +18 -0
- package/dist/cjs/runtime/utils.js +142 -0
- package/dist/cjs/runtime.js +58 -0
- package/dist/esm/cli/index.mjs +201 -0
- package/dist/esm/cli/tanstackTypes.mjs +341 -0
- package/dist/esm/cli.mjs +2 -0
- package/dist/esm/rslib-runtime.mjs +18 -0
- package/dist/esm/runtime/DefaultNotFound.mjs +13 -0
- package/dist/esm/runtime/basepathRewrite.mjs +28 -0
- package/dist/esm/runtime/dataMutation.mjs +305 -0
- package/dist/esm/runtime/hooks.mjs +8 -0
- package/dist/esm/runtime/index.mjs +6 -0
- package/dist/esm/runtime/lifecycle.mjs +82 -0
- package/dist/esm/runtime/plugin.mjs +214 -0
- package/dist/esm/runtime/plugin.node.mjs +268 -0
- package/dist/esm/runtime/prefetchLink.mjs +18 -0
- package/dist/esm/runtime/routeTree.mjs +452 -0
- package/dist/esm/runtime/rsc/ClientSlot.mjs +19 -0
- package/dist/esm/runtime/rsc/CompositeComponent.mjs +41 -0
- package/dist/esm/runtime/rsc/ReplayableStream.mjs +104 -0
- package/dist/esm/runtime/rsc/RscNodeRenderer.mjs +31 -0
- package/dist/esm/runtime/rsc/SlotContext.mjs +17 -0
- package/dist/esm/runtime/rsc/client.mjs +53 -0
- package/dist/esm/runtime/rsc/createRscProxy.mjs +107 -0
- package/dist/esm/runtime/rsc/index.mjs +1 -0
- package/dist/esm/runtime/rsc/payloadRouter.mjs +162 -0
- package/dist/esm/runtime/rsc/server.mjs +200 -0
- package/dist/esm/runtime/rsc/slotUsageSanitizer.mjs +31 -0
- package/dist/esm/runtime/rsc/symbols.mjs +17 -0
- package/dist/esm/runtime/types.mjs +0 -0
- package/dist/esm/runtime/utils.mjs +89 -0
- package/dist/esm/runtime.mjs +1 -0
- package/dist/esm-node/cli/index.mjs +205 -0
- package/dist/esm-node/cli/tanstackTypes.mjs +342 -0
- package/dist/esm-node/cli.mjs +3 -0
- package/dist/esm-node/rslib-runtime.mjs +19 -0
- package/dist/esm-node/runtime/DefaultNotFound.mjs +14 -0
- package/dist/esm-node/runtime/basepathRewrite.mjs +29 -0
- package/dist/esm-node/runtime/dataMutation.mjs +306 -0
- package/dist/esm-node/runtime/hooks.mjs +9 -0
- package/dist/esm-node/runtime/index.mjs +7 -0
- package/dist/esm-node/runtime/lifecycle.mjs +83 -0
- package/dist/esm-node/runtime/plugin.mjs +215 -0
- package/dist/esm-node/runtime/plugin.node.mjs +269 -0
- package/dist/esm-node/runtime/prefetchLink.mjs +19 -0
- package/dist/esm-node/runtime/routeTree.mjs +453 -0
- package/dist/esm-node/runtime/rsc/ClientSlot.mjs +20 -0
- package/dist/esm-node/runtime/rsc/CompositeComponent.mjs +42 -0
- package/dist/esm-node/runtime/rsc/ReplayableStream.mjs +105 -0
- package/dist/esm-node/runtime/rsc/RscNodeRenderer.mjs +32 -0
- package/dist/esm-node/runtime/rsc/SlotContext.mjs +18 -0
- package/dist/esm-node/runtime/rsc/client.mjs +54 -0
- package/dist/esm-node/runtime/rsc/createRscProxy.mjs +108 -0
- package/dist/esm-node/runtime/rsc/index.mjs +2 -0
- package/dist/esm-node/runtime/rsc/payloadRouter.mjs +163 -0
- package/dist/esm-node/runtime/rsc/server.mjs +201 -0
- package/dist/esm-node/runtime/rsc/slotUsageSanitizer.mjs +32 -0
- package/dist/esm-node/runtime/rsc/symbols.mjs +18 -0
- package/dist/esm-node/runtime/types.mjs +1 -0
- package/dist/esm-node/runtime/utils.mjs +90 -0
- package/dist/esm-node/runtime.mjs +2 -0
- package/dist/types/cli/index.d.ts +20 -0
- package/dist/types/cli/tanstackTypes.d.ts +11 -0
- package/dist/types/cli.d.ts +2 -0
- package/dist/types/runtime/DefaultNotFound.d.ts +2 -0
- package/dist/types/runtime/basepathRewrite.d.ts +8 -0
- package/dist/types/runtime/dataMutation.d.ts +29 -0
- package/dist/types/runtime/hooks.d.ts +18 -0
- package/dist/types/runtime/index.d.ts +9 -0
- package/dist/types/runtime/lifecycle.d.ts +22 -0
- package/dist/types/runtime/plugin.d.ts +17 -0
- package/dist/types/runtime/plugin.node.d.ts +17 -0
- package/dist/types/runtime/prefetchLink.d.ts +11 -0
- package/dist/types/runtime/routeTree.d.ts +11 -0
- package/dist/types/runtime/rsc/ClientSlot.d.ts +5 -0
- package/dist/types/runtime/rsc/CompositeComponent.d.ts +3 -0
- package/dist/types/runtime/rsc/ReplayableStream.d.ts +24 -0
- package/dist/types/runtime/rsc/RscNodeRenderer.d.ts +5 -0
- package/dist/types/runtime/rsc/SlotContext.d.ts +11 -0
- package/dist/types/runtime/rsc/client.d.ts +11 -0
- package/dist/types/runtime/rsc/createRscProxy.d.ts +7 -0
- package/dist/types/runtime/rsc/index.d.ts +2 -0
- package/dist/types/runtime/rsc/payloadRouter.d.ts +24 -0
- package/dist/types/runtime/rsc/server.d.ts +14 -0
- package/dist/types/runtime/rsc/slotUsageSanitizer.d.ts +2 -0
- package/dist/types/runtime/rsc/symbols.d.ts +46 -0
- package/dist/types/runtime/types.d.ts +68 -0
- package/dist/types/runtime/utils.d.ts +36 -0
- package/dist/types/runtime.d.ts +1 -0
- package/dist/types-direct/cli/index.d.ts +20 -0
- package/dist/types-direct/cli/tanstackTypes.d.ts +11 -0
- package/dist/types-direct/cli.d.ts +2 -0
- package/dist/types-direct/runtime/DefaultNotFound.d.ts +2 -0
- package/dist/types-direct/runtime/basepathRewrite.d.ts +8 -0
- package/dist/types-direct/runtime/dataMutation.d.ts +29 -0
- package/dist/types-direct/runtime/hooks.d.ts +18 -0
- package/dist/types-direct/runtime/index.d.ts +9 -0
- package/dist/types-direct/runtime/lifecycle.d.ts +22 -0
- package/dist/types-direct/runtime/plugin.d.ts +17 -0
- package/dist/types-direct/runtime/plugin.node.d.ts +17 -0
- package/dist/types-direct/runtime/prefetchLink.d.ts +11 -0
- package/dist/types-direct/runtime/routeTree.d.ts +11 -0
- package/dist/types-direct/runtime/rsc/ClientSlot.d.ts +5 -0
- package/dist/types-direct/runtime/rsc/CompositeComponent.d.ts +3 -0
- package/dist/types-direct/runtime/rsc/ReplayableStream.d.ts +24 -0
- package/dist/types-direct/runtime/rsc/RscNodeRenderer.d.ts +5 -0
- package/dist/types-direct/runtime/rsc/SlotContext.d.ts +11 -0
- package/dist/types-direct/runtime/rsc/client.d.ts +11 -0
- package/dist/types-direct/runtime/rsc/createRscProxy.d.ts +7 -0
- package/dist/types-direct/runtime/rsc/index.d.ts +2 -0
- package/dist/types-direct/runtime/rsc/payloadRouter.d.ts +24 -0
- package/dist/types-direct/runtime/rsc/server.d.ts +14 -0
- package/dist/types-direct/runtime/rsc/slotUsageSanitizer.d.ts +2 -0
- package/dist/types-direct/runtime/rsc/symbols.d.ts +46 -0
- package/dist/types-direct/runtime/types.d.ts +68 -0
- package/dist/types-direct/runtime/utils.d.ts +36 -0
- package/dist/types-direct/runtime.d.ts +1 -0
- package/package.json +126 -0
- package/rslib.config.mts +4 -0
- package/rstest.config.mts +43 -0
- package/src/cli/index.ts +388 -0
- package/src/cli/tanstackTypes.ts +503 -0
- package/src/cli.ts +2 -0
- package/src/runtime/DefaultNotFound.tsx +15 -0
- package/src/runtime/basepathRewrite.ts +59 -0
- package/src/runtime/dataMutation.tsx +517 -0
- package/src/runtime/hooks.ts +34 -0
- package/src/runtime/index.tsx +30 -0
- package/src/runtime/lifecycle.ts +150 -0
- package/src/runtime/plugin.node.tsx +534 -0
- package/src/runtime/plugin.tsx +395 -0
- package/src/runtime/prefetchLink.tsx +87 -0
- package/src/runtime/routeTree.ts +942 -0
- package/src/runtime/rsc/ClientSlot.tsx +25 -0
- package/src/runtime/rsc/CompositeComponent.tsx +65 -0
- package/src/runtime/rsc/ReplayableStream.ts +155 -0
- package/src/runtime/rsc/RscNodeRenderer.tsx +45 -0
- package/src/runtime/rsc/SlotContext.tsx +31 -0
- package/src/runtime/rsc/client.tsx +90 -0
- package/src/runtime/rsc/createRscProxy.tsx +189 -0
- package/src/runtime/rsc/index.ts +10 -0
- package/src/runtime/rsc/payloadRouter.ts +318 -0
- package/src/runtime/rsc/server.tsx +303 -0
- package/src/runtime/rsc/slotUsageSanitizer.ts +76 -0
- package/src/runtime/rsc/symbols.ts +106 -0
- package/src/runtime/ssr-shim.d.ts +12 -0
- package/src/runtime/types.ts +83 -0
- package/src/runtime/utils.tsx +161 -0
- package/src/runtime.ts +1 -0
- package/tests/router/cli.test.ts +386 -0
- package/tests/router/dataMutation.test.tsx +396 -0
- package/tests/router/prefetchLink.test.tsx +43 -0
- package/tests/router/routeTree.test.ts +502 -0
- package/tests/router/rsc.test.tsx +256 -0
- package/tests/router/tanstackTypes.test.ts +62 -0
- package/tsconfig.json +12 -0
- package/tsconfig.tsgo.json +6 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
|
|
3
|
+
export interface ServerComponentStream {
|
|
4
|
+
createReplayStream: () => ReadableStream<Uint8Array>;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const SERVER_COMPONENT_STREAM = Symbol.for('modern.tanstack.rsc.stream');
|
|
8
|
+
|
|
9
|
+
export const RENDERABLE_RSC = Symbol.for('modern.tanstack.rsc.renderable');
|
|
10
|
+
|
|
11
|
+
export const RSC_PROXY_GET_TREE = Symbol.for(
|
|
12
|
+
'modern.tanstack.rsc.proxy.getTree',
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const RSC_PROXY_PATH = Symbol.for('modern.tanstack.rsc.proxy.path');
|
|
16
|
+
|
|
17
|
+
export const RSC_SLOT_USAGES_STREAM = Symbol.for(
|
|
18
|
+
'modern.tanstack.rsc.slotUsages.stream',
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const RSC_SLOT_USAGES = Symbol.for('modern.tanstack.rsc.slotUsages');
|
|
22
|
+
|
|
23
|
+
export type SerializableSlotArg =
|
|
24
|
+
| string
|
|
25
|
+
| number
|
|
26
|
+
| boolean
|
|
27
|
+
| bigint
|
|
28
|
+
| null
|
|
29
|
+
| undefined
|
|
30
|
+
| SerializableSlotArg[]
|
|
31
|
+
| { [key: string]: SerializableSlotArg };
|
|
32
|
+
|
|
33
|
+
export type RscSlotUsageEvent = {
|
|
34
|
+
slot: string;
|
|
35
|
+
args?: SerializableSlotArg[];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export interface AnyRenderableServerComponent<TNode = React.ReactNode> {
|
|
39
|
+
[SERVER_COMPONENT_STREAM]: ServerComponentStream;
|
|
40
|
+
[RENDERABLE_RSC]: true;
|
|
41
|
+
[RSC_PROXY_GET_TREE]?: () => unknown;
|
|
42
|
+
[RSC_PROXY_PATH]?: string[];
|
|
43
|
+
[RSC_SLOT_USAGES_STREAM]?: ReadableStream<RscSlotUsageEvent>;
|
|
44
|
+
'~types'?: {
|
|
45
|
+
node: TNode;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface AnyCompositeComponent<
|
|
50
|
+
TProps extends object = Record<string, unknown>,
|
|
51
|
+
TReturn = React.ReactNode,
|
|
52
|
+
> {
|
|
53
|
+
[SERVER_COMPONENT_STREAM]?: ServerComponentStream;
|
|
54
|
+
[RSC_PROXY_GET_TREE]?: () => unknown;
|
|
55
|
+
[RSC_PROXY_PATH]?: string[];
|
|
56
|
+
[RSC_SLOT_USAGES]?: RscSlotUsageEvent[];
|
|
57
|
+
[RSC_SLOT_USAGES_STREAM]?: ReadableStream<RscSlotUsageEvent>;
|
|
58
|
+
'~types'?: {
|
|
59
|
+
props: TProps;
|
|
60
|
+
return: TReturn;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
type InferCompositeProps<TComp extends AnyCompositeComponent> =
|
|
65
|
+
TComp extends AnyCompositeComponent<infer TProps, unknown>
|
|
66
|
+
? TProps
|
|
67
|
+
: Record<string, unknown>;
|
|
68
|
+
|
|
69
|
+
export type CompositeComponentProps<TComp extends AnyCompositeComponent> = {
|
|
70
|
+
src: TComp;
|
|
71
|
+
strict?: boolean;
|
|
72
|
+
} & InferCompositeProps<TComp>;
|
|
73
|
+
|
|
74
|
+
export function isServerComponent(
|
|
75
|
+
value: unknown,
|
|
76
|
+
): value is AnyCompositeComponent | AnyRenderableServerComponent {
|
|
77
|
+
if (value === null || value === undefined) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (typeof value !== 'object' && typeof value !== 'function') {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
SERVER_COMPONENT_STREAM in value &&
|
|
87
|
+
typeof (value as { [SERVER_COMPONENT_STREAM]?: unknown })[
|
|
88
|
+
SERVER_COMPONENT_STREAM
|
|
89
|
+
] !== 'undefined'
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function isRenderableServerComponent(value: unknown): boolean {
|
|
94
|
+
if (value === null || value === undefined) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (typeof value !== 'object' && typeof value !== 'function') {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
RENDERABLE_RSC in value &&
|
|
104
|
+
(value as { [RENDERABLE_RSC]?: unknown })[RENDERABLE_RSC] === true
|
|
105
|
+
);
|
|
106
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare module '@tanstack/react-router/ssr/client' {
|
|
2
|
+
export function RouterClient(props: {
|
|
3
|
+
router: unknown;
|
|
4
|
+
}): import('react').JSX.Element;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
declare module '@tanstack/react-router/ssr/server' {
|
|
8
|
+
export function attachRouterServerSsrUtils(opts: {
|
|
9
|
+
router: unknown;
|
|
10
|
+
manifest?: unknown;
|
|
11
|
+
}): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { RequestContext } from '@modern-js/runtime-utils/node';
|
|
2
|
+
import type { RouteObject } from '@modern-js/runtime-utils/router';
|
|
3
|
+
import type { NestedRoute, PageRoute } from '@modern-js/types';
|
|
4
|
+
import type React from 'react';
|
|
5
|
+
|
|
6
|
+
export type BuiltInRouterFramework = 'react-router' | 'tanstack';
|
|
7
|
+
export type RouterFramework = BuiltInRouterFramework | (string & {});
|
|
8
|
+
|
|
9
|
+
export type RouterConfig = {
|
|
10
|
+
framework?: RouterFramework;
|
|
11
|
+
routesConfig: {
|
|
12
|
+
globalApp?: React.ComponentType<any>;
|
|
13
|
+
routes?: (NestedRoute | PageRoute)[];
|
|
14
|
+
};
|
|
15
|
+
oldVersion?: boolean;
|
|
16
|
+
serverBase?: string[];
|
|
17
|
+
supportHtml5History?: boolean;
|
|
18
|
+
basename?: string;
|
|
19
|
+
createRoutes?: () => RouteObject[];
|
|
20
|
+
future?: Partial<{
|
|
21
|
+
v7_startTransition: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
unstable_reloadOnURLMismatch?: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export interface RouterRouteMatchSnapshot {
|
|
27
|
+
routeId: string;
|
|
28
|
+
assetRouteId?: string;
|
|
29
|
+
pathname?: string;
|
|
30
|
+
params?: Record<string, string>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface InternalRouterServerSnapshot {
|
|
34
|
+
framework?: RouterFramework;
|
|
35
|
+
basename?: string;
|
|
36
|
+
statusCode?: number;
|
|
37
|
+
errors?: Record<string, unknown>;
|
|
38
|
+
routerData?: {
|
|
39
|
+
loaderData?: Record<string, unknown>;
|
|
40
|
+
errors?: Record<string, unknown>;
|
|
41
|
+
};
|
|
42
|
+
hydrationScript?: string;
|
|
43
|
+
hydrationScripts?: string[];
|
|
44
|
+
matchedRouteIds?: string[];
|
|
45
|
+
matches?: RouterRouteMatchSnapshot[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface InternalRouterRuntimeState {
|
|
49
|
+
framework: RouterFramework;
|
|
50
|
+
basename?: string;
|
|
51
|
+
instance?: unknown;
|
|
52
|
+
hydrationScript?: string;
|
|
53
|
+
hydrationScripts?: string[];
|
|
54
|
+
matchedRouteIds?: string[];
|
|
55
|
+
matches?: RouterRouteMatchSnapshot[];
|
|
56
|
+
serverSnapshot?: InternalRouterServerSnapshot;
|
|
57
|
+
cleanup?: () => void | Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface RouterServerPrepareResult {
|
|
61
|
+
state: InternalRouterRuntimeState;
|
|
62
|
+
snapshot?: InternalRouterServerSnapshot;
|
|
63
|
+
redirect?: Response;
|
|
64
|
+
cleanup?: () => void | Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface DataFunctionArgs<D = any> {
|
|
68
|
+
request: Request;
|
|
69
|
+
params: Record<string, string>;
|
|
70
|
+
context?: D;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type LoaderFunctionArgs<
|
|
74
|
+
P extends Record<string, unknown> = Record<string, unknown>,
|
|
75
|
+
> = DataFunctionArgs<RequestContext<P>>;
|
|
76
|
+
|
|
77
|
+
type DataFunctionValue = Response | NonNullable<unknown> | null;
|
|
78
|
+
|
|
79
|
+
export type LoaderFunction = <
|
|
80
|
+
P extends Record<string, unknown> = Record<string, unknown>,
|
|
81
|
+
>(
|
|
82
|
+
args: LoaderFunctionArgs<P>,
|
|
83
|
+
) => Promise<DataFunctionValue> | DataFunctionValue;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type { RouteObject } from '@modern-js/runtime-utils/router';
|
|
2
|
+
import type { NestedRoute, PageRoute, SSRMode } from '@modern-js/types';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { DefaultNotFound } from './DefaultNotFound';
|
|
5
|
+
|
|
6
|
+
type RouterConfig = {
|
|
7
|
+
routesConfig: {
|
|
8
|
+
globalApp?: React.ComponentType<any>;
|
|
9
|
+
routes?: (NestedRoute | PageRoute)[];
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type LayoutWrapperProps = {
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type GlobalAppProps = {
|
|
18
|
+
Component: React.ComponentType;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type ModernRouteObject = RouteObject & {
|
|
23
|
+
isClientComponent?: boolean;
|
|
24
|
+
hasClientLoader?: boolean;
|
|
25
|
+
hasLoader?: boolean;
|
|
26
|
+
hasAction?: boolean;
|
|
27
|
+
inValidSSRRoute?: boolean;
|
|
28
|
+
lazyImport?: () => Promise<{ default: React.ComponentType }>;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export function getRouteObjects(
|
|
32
|
+
routes: (NestedRoute | PageRoute)[],
|
|
33
|
+
{
|
|
34
|
+
globalApp,
|
|
35
|
+
ssrMode,
|
|
36
|
+
props,
|
|
37
|
+
}: {
|
|
38
|
+
globalApp?: React.ComponentType<GlobalAppProps>;
|
|
39
|
+
ssrMode?: SSRMode;
|
|
40
|
+
props?: Record<string, unknown>;
|
|
41
|
+
},
|
|
42
|
+
) {
|
|
43
|
+
const createLayoutElement = (
|
|
44
|
+
Component: React.ComponentType,
|
|
45
|
+
): React.ComponentType => {
|
|
46
|
+
const GlobalLayout = globalApp;
|
|
47
|
+
if (!GlobalLayout) {
|
|
48
|
+
return Component;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const LayoutWrapper = (props: LayoutWrapperProps) => {
|
|
52
|
+
const LayoutComponent = GlobalLayout;
|
|
53
|
+
return <LayoutComponent Component={Component} {...props} />;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return LayoutWrapper;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const routeObjects: RouteObject[] = [];
|
|
60
|
+
|
|
61
|
+
for (const route of routes) {
|
|
62
|
+
if (route.type === 'nested') {
|
|
63
|
+
const nestedRouteObject = {
|
|
64
|
+
path: route.path,
|
|
65
|
+
id: route.id,
|
|
66
|
+
loader: route.loader,
|
|
67
|
+
action: route.action,
|
|
68
|
+
hasErrorBoundary: route.hasErrorBoundary,
|
|
69
|
+
shouldRevalidate: route.shouldRevalidate,
|
|
70
|
+
handle: {
|
|
71
|
+
...route.handle,
|
|
72
|
+
...(typeof route.config === 'object' ? route.config?.handle : {}),
|
|
73
|
+
},
|
|
74
|
+
index: route.index,
|
|
75
|
+
hasLoader: Boolean(route.loader),
|
|
76
|
+
hasClientLoader: Boolean(route.clientData),
|
|
77
|
+
hasAction: Boolean(route.action),
|
|
78
|
+
...(route.isClientComponent ? { isClientComponent: true } : {}),
|
|
79
|
+
...(route.inValidSSRRoute ? { inValidSSRRoute: true } : {}),
|
|
80
|
+
lazyImport: route.lazyImport,
|
|
81
|
+
Component: route.component ? route.component : undefined,
|
|
82
|
+
errorElement: route.error ? <route.error /> : undefined,
|
|
83
|
+
children: route.children
|
|
84
|
+
? route.children.map(
|
|
85
|
+
child =>
|
|
86
|
+
getRouteObjects([child], { globalApp, ssrMode, props })[0],
|
|
87
|
+
)
|
|
88
|
+
: undefined,
|
|
89
|
+
} as ModernRouteObject;
|
|
90
|
+
|
|
91
|
+
routeObjects.push(nestedRouteObject);
|
|
92
|
+
} else if (
|
|
93
|
+
typeof route.component === 'function' ||
|
|
94
|
+
typeof route.component === 'object'
|
|
95
|
+
) {
|
|
96
|
+
const LayoutComponent = createLayoutElement(
|
|
97
|
+
route.component as React.ComponentType,
|
|
98
|
+
);
|
|
99
|
+
const routeObject: RouteObject = {
|
|
100
|
+
path: route.path,
|
|
101
|
+
element: React.createElement(LayoutComponent),
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
routeObjects.push(routeObject);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
routeObjects.push({
|
|
109
|
+
path: '*',
|
|
110
|
+
element: <DefaultNotFound />,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return routeObjects;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function createRouteObjectsFromConfig({
|
|
117
|
+
routesConfig,
|
|
118
|
+
props,
|
|
119
|
+
ssrMode,
|
|
120
|
+
}: {
|
|
121
|
+
routesConfig: RouterConfig['routesConfig'];
|
|
122
|
+
props?: Record<string, unknown>;
|
|
123
|
+
ssrMode?: SSRMode;
|
|
124
|
+
}): RouteObject[] | null {
|
|
125
|
+
if (!routesConfig) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
const { routes, globalApp } = routesConfig;
|
|
129
|
+
if (!routes) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
return getRouteObjects(routes, {
|
|
133
|
+
globalApp,
|
|
134
|
+
ssrMode,
|
|
135
|
+
props,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export const urlJoin = (...parts: string[]) => {
|
|
140
|
+
const separator = '/';
|
|
141
|
+
const replace = new RegExp(`${separator}{1,}`, 'g');
|
|
142
|
+
return standardSlash(parts.join(separator).replace(replace, separator));
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export function standardSlash(str: string) {
|
|
146
|
+
let addr = str;
|
|
147
|
+
if (!addr || typeof addr !== 'string') {
|
|
148
|
+
return addr;
|
|
149
|
+
}
|
|
150
|
+
if (addr.startsWith('.')) {
|
|
151
|
+
addr = addr.slice(1);
|
|
152
|
+
}
|
|
153
|
+
if (!addr.startsWith('/')) {
|
|
154
|
+
addr = `/${addr}`;
|
|
155
|
+
}
|
|
156
|
+
if (addr.endsWith('/') && addr !== '/') {
|
|
157
|
+
addr = addr.slice(0, addr.length - 1);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return addr;
|
|
161
|
+
}
|
package/src/runtime.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './runtime/index';
|