@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.
Files changed (183) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/cli/index.js +268 -0
  3. package/dist/cjs/cli/tanstackTypes.js +388 -0
  4. package/dist/cjs/cli.js +65 -0
  5. package/dist/cjs/runtime/DefaultNotFound.js +47 -0
  6. package/dist/cjs/runtime/basepathRewrite.js +62 -0
  7. package/dist/cjs/runtime/dataMutation.js +345 -0
  8. package/dist/cjs/runtime/hooks.js +57 -0
  9. package/dist/cjs/runtime/index.js +114 -0
  10. package/dist/cjs/runtime/lifecycle.js +125 -0
  11. package/dist/cjs/runtime/plugin.js +250 -0
  12. package/dist/cjs/runtime/plugin.node.js +304 -0
  13. package/dist/cjs/runtime/prefetchLink.js +55 -0
  14. package/dist/cjs/runtime/routeTree.js +492 -0
  15. package/dist/cjs/runtime/rsc/ClientSlot.js +53 -0
  16. package/dist/cjs/runtime/rsc/CompositeComponent.js +75 -0
  17. package/dist/cjs/runtime/rsc/ReplayableStream.js +141 -0
  18. package/dist/cjs/runtime/rsc/RscNodeRenderer.js +65 -0
  19. package/dist/cjs/runtime/rsc/SlotContext.js +54 -0
  20. package/dist/cjs/runtime/rsc/client.js +93 -0
  21. package/dist/cjs/runtime/rsc/createRscProxy.js +141 -0
  22. package/dist/cjs/runtime/rsc/index.js +42 -0
  23. package/dist/cjs/runtime/rsc/payloadRouter.js +211 -0
  24. package/dist/cjs/runtime/rsc/server.js +246 -0
  25. package/dist/cjs/runtime/rsc/slotUsageSanitizer.js +65 -0
  26. package/dist/cjs/runtime/rsc/symbols.js +72 -0
  27. package/dist/cjs/runtime/types.js +18 -0
  28. package/dist/cjs/runtime/utils.js +142 -0
  29. package/dist/cjs/runtime.js +58 -0
  30. package/dist/esm/cli/index.mjs +201 -0
  31. package/dist/esm/cli/tanstackTypes.mjs +341 -0
  32. package/dist/esm/cli.mjs +2 -0
  33. package/dist/esm/rslib-runtime.mjs +18 -0
  34. package/dist/esm/runtime/DefaultNotFound.mjs +13 -0
  35. package/dist/esm/runtime/basepathRewrite.mjs +28 -0
  36. package/dist/esm/runtime/dataMutation.mjs +305 -0
  37. package/dist/esm/runtime/hooks.mjs +8 -0
  38. package/dist/esm/runtime/index.mjs +6 -0
  39. package/dist/esm/runtime/lifecycle.mjs +82 -0
  40. package/dist/esm/runtime/plugin.mjs +214 -0
  41. package/dist/esm/runtime/plugin.node.mjs +268 -0
  42. package/dist/esm/runtime/prefetchLink.mjs +18 -0
  43. package/dist/esm/runtime/routeTree.mjs +452 -0
  44. package/dist/esm/runtime/rsc/ClientSlot.mjs +19 -0
  45. package/dist/esm/runtime/rsc/CompositeComponent.mjs +41 -0
  46. package/dist/esm/runtime/rsc/ReplayableStream.mjs +104 -0
  47. package/dist/esm/runtime/rsc/RscNodeRenderer.mjs +31 -0
  48. package/dist/esm/runtime/rsc/SlotContext.mjs +17 -0
  49. package/dist/esm/runtime/rsc/client.mjs +53 -0
  50. package/dist/esm/runtime/rsc/createRscProxy.mjs +107 -0
  51. package/dist/esm/runtime/rsc/index.mjs +1 -0
  52. package/dist/esm/runtime/rsc/payloadRouter.mjs +162 -0
  53. package/dist/esm/runtime/rsc/server.mjs +200 -0
  54. package/dist/esm/runtime/rsc/slotUsageSanitizer.mjs +31 -0
  55. package/dist/esm/runtime/rsc/symbols.mjs +17 -0
  56. package/dist/esm/runtime/types.mjs +0 -0
  57. package/dist/esm/runtime/utils.mjs +89 -0
  58. package/dist/esm/runtime.mjs +1 -0
  59. package/dist/esm-node/cli/index.mjs +205 -0
  60. package/dist/esm-node/cli/tanstackTypes.mjs +342 -0
  61. package/dist/esm-node/cli.mjs +3 -0
  62. package/dist/esm-node/rslib-runtime.mjs +19 -0
  63. package/dist/esm-node/runtime/DefaultNotFound.mjs +14 -0
  64. package/dist/esm-node/runtime/basepathRewrite.mjs +29 -0
  65. package/dist/esm-node/runtime/dataMutation.mjs +306 -0
  66. package/dist/esm-node/runtime/hooks.mjs +9 -0
  67. package/dist/esm-node/runtime/index.mjs +7 -0
  68. package/dist/esm-node/runtime/lifecycle.mjs +83 -0
  69. package/dist/esm-node/runtime/plugin.mjs +215 -0
  70. package/dist/esm-node/runtime/plugin.node.mjs +269 -0
  71. package/dist/esm-node/runtime/prefetchLink.mjs +19 -0
  72. package/dist/esm-node/runtime/routeTree.mjs +453 -0
  73. package/dist/esm-node/runtime/rsc/ClientSlot.mjs +20 -0
  74. package/dist/esm-node/runtime/rsc/CompositeComponent.mjs +42 -0
  75. package/dist/esm-node/runtime/rsc/ReplayableStream.mjs +105 -0
  76. package/dist/esm-node/runtime/rsc/RscNodeRenderer.mjs +32 -0
  77. package/dist/esm-node/runtime/rsc/SlotContext.mjs +18 -0
  78. package/dist/esm-node/runtime/rsc/client.mjs +54 -0
  79. package/dist/esm-node/runtime/rsc/createRscProxy.mjs +108 -0
  80. package/dist/esm-node/runtime/rsc/index.mjs +2 -0
  81. package/dist/esm-node/runtime/rsc/payloadRouter.mjs +163 -0
  82. package/dist/esm-node/runtime/rsc/server.mjs +201 -0
  83. package/dist/esm-node/runtime/rsc/slotUsageSanitizer.mjs +32 -0
  84. package/dist/esm-node/runtime/rsc/symbols.mjs +18 -0
  85. package/dist/esm-node/runtime/types.mjs +1 -0
  86. package/dist/esm-node/runtime/utils.mjs +90 -0
  87. package/dist/esm-node/runtime.mjs +2 -0
  88. package/dist/types/cli/index.d.ts +20 -0
  89. package/dist/types/cli/tanstackTypes.d.ts +11 -0
  90. package/dist/types/cli.d.ts +2 -0
  91. package/dist/types/runtime/DefaultNotFound.d.ts +2 -0
  92. package/dist/types/runtime/basepathRewrite.d.ts +8 -0
  93. package/dist/types/runtime/dataMutation.d.ts +29 -0
  94. package/dist/types/runtime/hooks.d.ts +18 -0
  95. package/dist/types/runtime/index.d.ts +9 -0
  96. package/dist/types/runtime/lifecycle.d.ts +22 -0
  97. package/dist/types/runtime/plugin.d.ts +17 -0
  98. package/dist/types/runtime/plugin.node.d.ts +17 -0
  99. package/dist/types/runtime/prefetchLink.d.ts +11 -0
  100. package/dist/types/runtime/routeTree.d.ts +11 -0
  101. package/dist/types/runtime/rsc/ClientSlot.d.ts +5 -0
  102. package/dist/types/runtime/rsc/CompositeComponent.d.ts +3 -0
  103. package/dist/types/runtime/rsc/ReplayableStream.d.ts +24 -0
  104. package/dist/types/runtime/rsc/RscNodeRenderer.d.ts +5 -0
  105. package/dist/types/runtime/rsc/SlotContext.d.ts +11 -0
  106. package/dist/types/runtime/rsc/client.d.ts +11 -0
  107. package/dist/types/runtime/rsc/createRscProxy.d.ts +7 -0
  108. package/dist/types/runtime/rsc/index.d.ts +2 -0
  109. package/dist/types/runtime/rsc/payloadRouter.d.ts +24 -0
  110. package/dist/types/runtime/rsc/server.d.ts +14 -0
  111. package/dist/types/runtime/rsc/slotUsageSanitizer.d.ts +2 -0
  112. package/dist/types/runtime/rsc/symbols.d.ts +46 -0
  113. package/dist/types/runtime/types.d.ts +68 -0
  114. package/dist/types/runtime/utils.d.ts +36 -0
  115. package/dist/types/runtime.d.ts +1 -0
  116. package/dist/types-direct/cli/index.d.ts +20 -0
  117. package/dist/types-direct/cli/tanstackTypes.d.ts +11 -0
  118. package/dist/types-direct/cli.d.ts +2 -0
  119. package/dist/types-direct/runtime/DefaultNotFound.d.ts +2 -0
  120. package/dist/types-direct/runtime/basepathRewrite.d.ts +8 -0
  121. package/dist/types-direct/runtime/dataMutation.d.ts +29 -0
  122. package/dist/types-direct/runtime/hooks.d.ts +18 -0
  123. package/dist/types-direct/runtime/index.d.ts +9 -0
  124. package/dist/types-direct/runtime/lifecycle.d.ts +22 -0
  125. package/dist/types-direct/runtime/plugin.d.ts +17 -0
  126. package/dist/types-direct/runtime/plugin.node.d.ts +17 -0
  127. package/dist/types-direct/runtime/prefetchLink.d.ts +11 -0
  128. package/dist/types-direct/runtime/routeTree.d.ts +11 -0
  129. package/dist/types-direct/runtime/rsc/ClientSlot.d.ts +5 -0
  130. package/dist/types-direct/runtime/rsc/CompositeComponent.d.ts +3 -0
  131. package/dist/types-direct/runtime/rsc/ReplayableStream.d.ts +24 -0
  132. package/dist/types-direct/runtime/rsc/RscNodeRenderer.d.ts +5 -0
  133. package/dist/types-direct/runtime/rsc/SlotContext.d.ts +11 -0
  134. package/dist/types-direct/runtime/rsc/client.d.ts +11 -0
  135. package/dist/types-direct/runtime/rsc/createRscProxy.d.ts +7 -0
  136. package/dist/types-direct/runtime/rsc/index.d.ts +2 -0
  137. package/dist/types-direct/runtime/rsc/payloadRouter.d.ts +24 -0
  138. package/dist/types-direct/runtime/rsc/server.d.ts +14 -0
  139. package/dist/types-direct/runtime/rsc/slotUsageSanitizer.d.ts +2 -0
  140. package/dist/types-direct/runtime/rsc/symbols.d.ts +46 -0
  141. package/dist/types-direct/runtime/types.d.ts +68 -0
  142. package/dist/types-direct/runtime/utils.d.ts +36 -0
  143. package/dist/types-direct/runtime.d.ts +1 -0
  144. package/package.json +126 -0
  145. package/rslib.config.mts +4 -0
  146. package/rstest.config.mts +43 -0
  147. package/src/cli/index.ts +388 -0
  148. package/src/cli/tanstackTypes.ts +503 -0
  149. package/src/cli.ts +2 -0
  150. package/src/runtime/DefaultNotFound.tsx +15 -0
  151. package/src/runtime/basepathRewrite.ts +59 -0
  152. package/src/runtime/dataMutation.tsx +517 -0
  153. package/src/runtime/hooks.ts +34 -0
  154. package/src/runtime/index.tsx +30 -0
  155. package/src/runtime/lifecycle.ts +150 -0
  156. package/src/runtime/plugin.node.tsx +534 -0
  157. package/src/runtime/plugin.tsx +395 -0
  158. package/src/runtime/prefetchLink.tsx +87 -0
  159. package/src/runtime/routeTree.ts +942 -0
  160. package/src/runtime/rsc/ClientSlot.tsx +25 -0
  161. package/src/runtime/rsc/CompositeComponent.tsx +65 -0
  162. package/src/runtime/rsc/ReplayableStream.ts +155 -0
  163. package/src/runtime/rsc/RscNodeRenderer.tsx +45 -0
  164. package/src/runtime/rsc/SlotContext.tsx +31 -0
  165. package/src/runtime/rsc/client.tsx +90 -0
  166. package/src/runtime/rsc/createRscProxy.tsx +189 -0
  167. package/src/runtime/rsc/index.ts +10 -0
  168. package/src/runtime/rsc/payloadRouter.ts +318 -0
  169. package/src/runtime/rsc/server.tsx +303 -0
  170. package/src/runtime/rsc/slotUsageSanitizer.ts +76 -0
  171. package/src/runtime/rsc/symbols.ts +106 -0
  172. package/src/runtime/ssr-shim.d.ts +12 -0
  173. package/src/runtime/types.ts +83 -0
  174. package/src/runtime/utils.tsx +161 -0
  175. package/src/runtime.ts +1 -0
  176. package/tests/router/cli.test.ts +386 -0
  177. package/tests/router/dataMutation.test.tsx +396 -0
  178. package/tests/router/prefetchLink.test.tsx +43 -0
  179. package/tests/router/routeTree.test.ts +502 -0
  180. package/tests/router/rsc.test.tsx +256 -0
  181. package/tests/router/tanstackTypes.test.ts +62 -0
  182. package/tsconfig.json +12 -0
  183. 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';