@bleedingdev/modern-js-runtime 3.2.0-ultramodern.2 → 3.2.0-ultramodern.22
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/cjs/cli/ssr/index.js +3 -2
- package/dist/cjs/cli/template.server.js +1 -0
- package/dist/cjs/core/context/serverPayload/index.js +1 -1
- package/dist/cjs/core/plugin/index.js +3 -2
- package/dist/cjs/core/server/helmet.js +2 -2
- package/dist/cjs/core/server/stream/beforeTemplate.worker.js +105 -0
- package/dist/cjs/core/server/stream/createReadableStream.worker.js +2 -1
- package/dist/cjs/core/server/stream/shared.js +1 -0
- package/dist/cjs/router/cli/code/tanstackTypes.js +20 -6
- package/dist/cjs/router/runtime/tanstack/plugin.js +2 -0
- package/dist/cjs/router/runtime/tanstack/routeTree.js +38 -2
- package/dist/cjs/rsc/server.worker.js +58 -0
- package/dist/esm/cli/ssr/index.mjs +3 -2
- package/dist/esm/cli/template.server.mjs +1 -0
- package/dist/esm/core/context/serverPayload/index.mjs +1 -1
- package/dist/esm/core/plugin/index.mjs +3 -2
- package/dist/esm/core/server/helmet.mjs +1 -1
- package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +61 -0
- package/dist/esm/core/server/stream/createReadableStream.worker.mjs +2 -1
- package/dist/esm/core/server/stream/shared.mjs +1 -0
- package/dist/esm/router/cli/code/tanstackTypes.mjs +20 -6
- package/dist/esm/router/runtime/tanstack/plugin.mjs +2 -0
- package/dist/esm/router/runtime/tanstack/routeTree.mjs +38 -2
- package/dist/esm/rsc/server.worker.mjs +1 -0
- package/dist/esm-node/cli/ssr/index.mjs +3 -2
- package/dist/esm-node/cli/template.server.mjs +1 -0
- package/dist/esm-node/core/context/serverPayload/index.mjs +1 -1
- package/dist/esm-node/core/plugin/index.mjs +3 -2
- package/dist/esm-node/core/server/helmet.mjs +1 -1
- package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +62 -0
- package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +2 -1
- package/dist/esm-node/core/server/stream/shared.mjs +1 -0
- package/dist/esm-node/router/cli/code/tanstackTypes.mjs +20 -6
- package/dist/esm-node/router/runtime/tanstack/plugin.mjs +2 -0
- package/dist/esm-node/router/runtime/tanstack/routeTree.mjs +38 -2
- package/dist/esm-node/rsc/server.worker.mjs +2 -0
- package/dist/types/cache/index.d.ts +1 -0
- package/dist/types/cli/alias.d.ts +7 -0
- package/dist/types/cli/code.d.ts +3 -0
- package/dist/types/cli/constants.d.ts +9 -0
- package/dist/types/cli/entry.d.ts +2 -0
- package/dist/types/cli/index.d.ts +11 -0
- package/dist/types/cli/ssr/index.d.ts +6 -0
- package/dist/types/cli/ssr/loadable-bundler-plugin.d.ts +31 -0
- package/dist/types/cli/ssr/mode.d.ts +15 -0
- package/dist/types/cli/template.d.ts +50 -0
- package/dist/types/cli/template.server.d.ts +20 -0
- package/dist/types/common.d.ts +8 -0
- package/dist/types/core/browser/hydrate.d.ts +5 -0
- package/dist/types/core/browser/index.d.ts +9 -0
- package/dist/types/core/browser/withCallback.d.ts +5 -0
- package/dist/types/core/compat/hooks.d.ts +4 -0
- package/dist/types/core/compat/index.d.ts +2 -0
- package/dist/types/core/compat/requestContext.d.ts +5 -0
- package/dist/types/core/config.d.ts +6 -0
- package/dist/types/core/constants.d.ts +6 -0
- package/dist/types/core/context/index.d.ts +50 -0
- package/dist/types/core/context/monitors/default.d.ts +2 -0
- package/dist/types/core/context/monitors/index.d.ts +1 -0
- package/dist/types/core/context/monitors/index.server.d.ts +2 -0
- package/dist/types/core/context/request/index.d.ts +1 -0
- package/dist/types/core/context/request/index.server.d.ts +1 -0
- package/dist/types/core/context/response/index.d.ts +4 -0
- package/dist/types/core/context/response/index.server.d.ts +4 -0
- package/dist/types/core/context/runtime.d.ts +42 -0
- package/dist/types/core/context/serverPayload/index.d.ts +4 -0
- package/dist/types/core/context/serverPayload/index.server.d.ts +31 -0
- package/dist/types/core/index.d.ts +5 -0
- package/dist/types/core/plugin/index.d.ts +5 -0
- package/dist/types/core/plugin/types.d.ts +10 -0
- package/dist/types/core/react/index.d.ts +2 -0
- package/dist/types/core/react/wrapper.d.ts +3 -0
- package/dist/types/core/server/constants.d.ts +4 -0
- package/dist/types/core/server/helmet.d.ts +3 -0
- package/dist/types/core/server/index.d.ts +4 -0
- package/dist/types/core/server/react/index.d.ts +2 -0
- package/dist/types/core/server/react/no-ssr-cache/index.d.ts +2 -0
- package/dist/types/core/server/react/nossr/index.d.ts +4 -0
- package/dist/types/core/server/requestHandler.d.ts +13 -0
- package/dist/types/core/server/server.d.ts +4 -0
- package/dist/types/core/server/shared.d.ts +8 -0
- package/dist/types/core/server/stream/afterTemplate.d.ts +13 -0
- package/dist/types/core/server/stream/beforeTemplate.d.ts +9 -0
- package/dist/types/core/server/stream/beforeTemplate.worker.d.ts +9 -0
- package/dist/types/core/server/stream/createReadableStream.d.ts +2 -0
- package/dist/types/core/server/stream/createReadableStream.worker.d.ts +2 -0
- package/dist/types/core/server/stream/deferredScript.d.ts +15 -0
- package/dist/types/core/server/stream/index.d.ts +1 -0
- package/dist/types/core/server/stream/shared.d.ts +40 -0
- package/dist/types/core/server/stream/template.d.ts +9 -0
- package/dist/types/core/server/string/index.d.ts +2 -0
- package/dist/types/core/server/string/loadable.d.ts +36 -0
- package/dist/types/core/server/string/ssrData.d.ts +20 -0
- package/dist/types/core/server/string/types.d.ts +12 -0
- package/dist/types/core/server/tracer.d.ts +17 -0
- package/dist/types/core/server/utils.d.ts +19 -0
- package/dist/types/core/types.d.ts +49 -0
- package/dist/types/document/Body.d.ts +2 -0
- package/dist/types/document/Comment.d.ts +5 -0
- package/dist/types/document/DocumentContext.d.ts +13 -0
- package/dist/types/document/DocumentStructureContext.d.ts +12 -0
- package/dist/types/document/Head.d.ts +5 -0
- package/dist/types/document/Html.d.ts +4 -0
- package/dist/types/document/Links.d.ts +2 -0
- package/dist/types/document/Root.d.ts +7 -0
- package/dist/types/document/Script.d.ts +4 -0
- package/dist/types/document/Scripts.d.ts +2 -0
- package/dist/types/document/Style.d.ts +5 -0
- package/dist/types/document/Title.d.ts +1 -0
- package/dist/types/document/cli/index.d.ts +5 -0
- package/dist/types/document/constants.d.ts +25 -0
- package/dist/types/document/index.d.ts +12 -0
- package/dist/types/exports/config-routes.d.ts +9 -0
- package/dist/types/exports/head.d.ts +4 -0
- package/dist/types/exports/loadable.d.ts +3 -0
- package/dist/types/exports/tanstack-router.d.ts +5 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/internal.d.ts +2 -0
- package/dist/types/react-server.d.ts +3 -0
- package/dist/types/router/cli/code/getClientRoutes/getRoutes.d.ts +8 -0
- package/dist/types/router/cli/code/getClientRoutes/index.d.ts +1 -0
- package/dist/types/router/cli/code/getClientRoutes/utils.d.ts +4 -0
- package/dist/types/router/cli/code/index.d.ts +12 -0
- package/dist/types/router/cli/code/inspect.d.ts +22 -0
- package/dist/types/router/cli/code/makeLegalIdentifier.d.ts +1 -0
- package/dist/types/router/cli/code/nestedRoutes.d.ts +13 -0
- package/dist/types/router/cli/code/tanstackTypes.d.ts +10 -0
- package/dist/types/router/cli/code/templates.d.ts +28 -0
- package/dist/types/router/cli/code/utils.d.ts +12 -0
- package/dist/types/router/cli/config-routes/converter.d.ts +15 -0
- package/dist/types/router/cli/config-routes/parseRouteConfig.d.ts +32 -0
- package/dist/types/router/cli/constants.d.ts +31 -0
- package/dist/types/router/cli/entry.d.ts +18 -0
- package/dist/types/router/cli/handler.d.ts +28 -0
- package/dist/types/router/cli/index.d.ts +5 -0
- package/dist/types/router/index.d.ts +1 -0
- package/dist/types/router/internal.d.ts +2 -0
- package/dist/types/router/runtime/CSSLinks.d.ts +9 -0
- package/dist/types/router/runtime/DefaultNotFound.d.ts +2 -0
- package/dist/types/router/runtime/DeferredDataScripts.d.ts +2 -0
- package/dist/types/router/runtime/DeferredDataScripts.node.d.ts +11 -0
- package/dist/types/router/runtime/PrefetchLink.d.ts +27 -0
- package/dist/types/router/runtime/constants.d.ts +146 -0
- package/dist/types/router/runtime/hooks.d.ts +18 -0
- package/dist/types/router/runtime/index.d.ts +7 -0
- package/dist/types/router/runtime/internal.d.ts +11 -0
- package/dist/types/router/runtime/lifecycle.d.ts +25 -0
- package/dist/types/router/runtime/plugin.d.ts +9 -0
- package/dist/types/router/runtime/plugin.node.d.ts +7 -0
- package/dist/types/router/runtime/routerHelper.d.ts +5 -0
- package/dist/types/router/runtime/rsc-router.d.ts +20 -0
- package/dist/types/router/runtime/rsc.d.ts +1 -0
- package/dist/types/router/runtime/server.d.ts +1 -0
- package/dist/types/router/runtime/tanstack/basepathRewrite.d.ts +8 -0
- package/dist/types/router/runtime/tanstack/dataMutation.d.ts +29 -0
- package/dist/types/router/runtime/tanstack/plugin.d.ts +6 -0
- package/dist/types/router/runtime/tanstack/plugin.node.d.ts +6 -0
- package/dist/types/router/runtime/tanstack/prefetchLink.d.ts +11 -0
- package/dist/types/router/runtime/tanstack/routeTree.d.ts +8 -0
- package/dist/types/router/runtime/tanstack/rsc/ClientSlot.d.ts +5 -0
- package/dist/types/router/runtime/tanstack/rsc/CompositeComponent.d.ts +3 -0
- package/dist/types/router/runtime/tanstack/rsc/ReplayableStream.d.ts +24 -0
- package/dist/types/router/runtime/tanstack/rsc/RscNodeRenderer.d.ts +5 -0
- package/dist/types/router/runtime/tanstack/rsc/SlotContext.d.ts +11 -0
- package/dist/types/router/runtime/tanstack/rsc/client.d.ts +11 -0
- package/dist/types/router/runtime/tanstack/rsc/createRscProxy.d.ts +7 -0
- package/dist/types/router/runtime/tanstack/rsc/index.d.ts +2 -0
- package/dist/types/router/runtime/tanstack/rsc/server.d.ts +14 -0
- package/dist/types/router/runtime/tanstack/rsc/slotUsageSanitizer.d.ts +2 -0
- package/dist/types/router/runtime/tanstack/rsc/symbols.d.ts +46 -0
- package/dist/types/router/runtime/types.d.ts +119 -0
- package/dist/types/router/runtime/utils.d.ts +48 -0
- package/dist/types/router/runtime/withRouter.d.ts +10 -0
- package/dist/types/rsc/client.d.ts +2 -0
- package/dist/types/rsc/server.d.ts +1 -0
- package/dist/types/rsc/server.worker.d.ts +1 -0
- package/package.json +16 -16
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Title(): import("react").JSX.Element;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AppTools, CliPlugin } from '@modern-js/app-tools';
|
|
2
|
+
import type { Entrypoint } from '@modern-js/types/cli';
|
|
3
|
+
export declare const getDocumentByEntryName: (entrypoints: Entrypoint[], entryName: string, fallbackDir?: string) => string | undefined;
|
|
4
|
+
export declare const documentPlugin: () => CliPlugin<AppTools>;
|
|
5
|
+
export default documentPlugin;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const DOC_EXT: string[];
|
|
2
|
+
export declare const DOCUMENT_META_PLACEHOLDER: string;
|
|
3
|
+
export declare const DOCUMENT_TITLE_PLACEHOLDER: string;
|
|
4
|
+
export declare const HTML_SEPARATOR = "<!--<?- html ?>-->";
|
|
5
|
+
export declare const HEAD_PARTICALS_SEPARATOR: string;
|
|
6
|
+
export declare const BODY_PARTICALS_SEPARATOR: string;
|
|
7
|
+
export declare const TOP_PARTICALS_SEPARATOR: string;
|
|
8
|
+
export declare const HTML_SSRDATASCRIPT_SEPARATOR = "<!--<?- SSRDataScript ?>-->";
|
|
9
|
+
export declare const DOCUMENT_SSR_PLACEHOLDER: string;
|
|
10
|
+
export declare const DOCUMENT_CHUNKSMAP_PLACEHOLDER: string;
|
|
11
|
+
export declare const DOCUMENT_SSRDATASCRIPT_PLACEHOLDER: string;
|
|
12
|
+
export declare const DOCUMENT_FILE_NAME = "Document";
|
|
13
|
+
export declare const DOCUMENT_SCRIPTS_PLACEHOLDER: string;
|
|
14
|
+
export declare const DOCUMENT_LINKS_PLACEHOLDER: string;
|
|
15
|
+
export declare const DOCUMENT_SCRIPT_PLACEHOLDER_START: string;
|
|
16
|
+
export declare const DOCUMENT_SCRIPT_PLACEHOLDER_END: string;
|
|
17
|
+
export declare const DOCUMENT_SCRIPT_ATTRIBUTES_START: string;
|
|
18
|
+
export declare const DOCUMENT_SCRIPT_ATTRIBUTES_END: string;
|
|
19
|
+
export declare const DOCUMENT_STYLE_PLACEHOLDER_START: string;
|
|
20
|
+
export declare const DOCUMENT_STYLE_PLACEHOLDER_END: string;
|
|
21
|
+
export declare const DOCUMENT_COMMENT_PLACEHOLDER_START: string;
|
|
22
|
+
export declare const DOCUMENT_COMMENT_PLACEHOLDER_END: string;
|
|
23
|
+
export declare const PLACEHOLDER_REPLACER_MAP: {
|
|
24
|
+
[x: string]: string;
|
|
25
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './Body';
|
|
2
|
+
export * from './Comment';
|
|
3
|
+
export * from './constants';
|
|
4
|
+
export * from './DocumentContext';
|
|
5
|
+
export * from './DocumentStructureContext';
|
|
6
|
+
export * from './Head';
|
|
7
|
+
export * from './Html';
|
|
8
|
+
export * from './Links';
|
|
9
|
+
export * from './Root';
|
|
10
|
+
export * from './Script';
|
|
11
|
+
export * from './Scripts';
|
|
12
|
+
export * from './Style';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for config-based routing
|
|
3
|
+
*/
|
|
4
|
+
import type { DefineRoutesFunction, LayoutFunction, PageFunction, RouteConfig, RouteFunction, RouteFunctions, WildcardFunction } from '../router/cli/config-routes/parseRouteConfig';
|
|
5
|
+
export type { DefineRoutesFunction, LayoutFunction, PageFunction, RouteConfig, RouteFunction, RouteFunctions, WildcardFunction, };
|
|
6
|
+
/**
|
|
7
|
+
* defineRoutes - main function to define route configurations
|
|
8
|
+
*/
|
|
9
|
+
export declare function defineRoutes(routesCallback: (routeFunctions: RouteFunctions, fileRoutes: RouteConfig[]) => RouteConfig[]): (routeFunctions: RouteFunctions, fileRoutes: RouteConfig[]) => RouteConfig[];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export * from '@tanstack/react-router';
|
|
2
|
+
export type { Fetcher, FetcherState, FetcherSubmitOptions, FormProps, SubmitOptions, } from '../router/runtime/tanstack/dataMutation';
|
|
3
|
+
export { Form, RouteActionResponseError, useFetcher, } from '../router/runtime/tanstack/dataMutation';
|
|
4
|
+
export type { LinkProps, NavLinkProps, PrefetchBehavior, } from '../router/runtime/tanstack/prefetchLink';
|
|
5
|
+
export { Link, NavLink } from '../router/runtime/tanstack/prefetchLink';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RouterConfig } from './router/internal';
|
|
2
|
+
export type { RuntimeConfig } from './common';
|
|
3
|
+
export { isBrowser } from './common';
|
|
4
|
+
export type { RuntimePlugin } from './core';
|
|
5
|
+
export { defineRuntimeConfig, RuntimeContext, useRuntimeContext, } from './core';
|
|
6
|
+
export { getMonitors } from './core/context/monitors';
|
|
7
|
+
export { getRequest } from './core/context/request';
|
|
8
|
+
export { redirect, setHeaders, setStatus } from './core/context/response';
|
|
9
|
+
export type { TRuntimeContext } from './core/context/runtime';
|
|
10
|
+
export type { RouterConfig };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Entrypoint, NestedRouteForCli, PageRoute } from '@modern-js/types';
|
|
2
|
+
export declare const getClientRoutes: ({ entrypoint, srcDirectory, srcAlias, internalDirectory, internalDirAlias, }: {
|
|
3
|
+
entrypoint: Entrypoint;
|
|
4
|
+
srcDirectory: string;
|
|
5
|
+
srcAlias: string;
|
|
6
|
+
internalDirectory: string;
|
|
7
|
+
internalDirAlias: string;
|
|
8
|
+
}) => (NestedRouteForCli | PageRoute)[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getClientRoutes } from './getRoutes';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AppNormalizedConfig, AppTools, AppToolsContext } from '@modern-js/app-tools';
|
|
2
|
+
import type { CLIPluginAPI } from '@modern-js/plugin';
|
|
3
|
+
import type { Entrypoint, NestedRouteForCli, PageRoute } from '@modern-js/types';
|
|
4
|
+
/**
|
|
5
|
+
* Generate routing information for a single entry point (can be reused by the routes inspect feature)
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateRoutesForEntry(entrypoint: Entrypoint, appContext: AppToolsContext): Promise<NestedRouteForCli[]>;
|
|
8
|
+
export declare const generateCode: (appContext: AppToolsContext, config: AppNormalizedConfig, entrypoints: Entrypoint[], api: CLIPluginAPI<AppTools>, options?: {
|
|
9
|
+
enableTanstackTypes?: boolean;
|
|
10
|
+
}) => Promise<Record<string, (NestedRouteForCli | PageRoute)[]>>;
|
|
11
|
+
export declare function generatorRegisterCode(internalDirectory: string, entryName: string, code: string): void;
|
|
12
|
+
export declare function generatorServerRegisterCode(internalDirectory: string, entryName: string, code: string): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AppTools } from '@modern-js/app-tools';
|
|
2
|
+
import type { CLIPluginAPI } from '@modern-js/plugin';
|
|
3
|
+
export interface RouteInspectInfo {
|
|
4
|
+
path?: string;
|
|
5
|
+
component: string;
|
|
6
|
+
data?: string;
|
|
7
|
+
clientData?: string;
|
|
8
|
+
error?: string;
|
|
9
|
+
loading?: string;
|
|
10
|
+
config?: string;
|
|
11
|
+
params?: string[];
|
|
12
|
+
children?: RouteInspectInfo[];
|
|
13
|
+
}
|
|
14
|
+
export interface RoutesInspectReport {
|
|
15
|
+
routes: RouteInspectInfo[];
|
|
16
|
+
}
|
|
17
|
+
export interface MultiEntryRoutesInspectReport {
|
|
18
|
+
[entryName: string]: {
|
|
19
|
+
routes: RouteInspectInfo[];
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare function generateRoutesInspectReport(api: CLIPluginAPI<AppTools>): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function makeLegalIdentifier(str: string): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NestedRouteForCli } from '@modern-js/types';
|
|
2
|
+
export declare const getRouteId: (componentPath: string, routesDir: string, entryName: string, isMainEntry: boolean) => string;
|
|
3
|
+
export declare const optimizeRoute: (routeTree: NestedRouteForCli) => NestedRouteForCli[];
|
|
4
|
+
export declare const walk: (options: {
|
|
5
|
+
dirname: string;
|
|
6
|
+
rootDir: string;
|
|
7
|
+
alias?: {
|
|
8
|
+
name: string;
|
|
9
|
+
basename: string;
|
|
10
|
+
};
|
|
11
|
+
entryName: string;
|
|
12
|
+
isMainEntry: boolean;
|
|
13
|
+
}) => Promise<NestedRouteForCli | NestedRouteForCli[] | null>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AppToolsContext } from '@modern-js/app-tools';
|
|
2
|
+
import type { NestedRouteForCli, PageRoute } from '@modern-js/types';
|
|
3
|
+
export declare function isTanstackRouterFrameworkEnabled(appContext: AppToolsContext): Promise<boolean>;
|
|
4
|
+
export declare function generateTanstackRouterTypesSourceForEntry(opts: {
|
|
5
|
+
appContext: AppToolsContext;
|
|
6
|
+
entryName: string;
|
|
7
|
+
routes: (NestedRouteForCli | PageRoute)[];
|
|
8
|
+
}): Promise<{
|
|
9
|
+
routerGenTs: string;
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AppNormalizedConfig, AppToolsContext } from '@modern-js/app-tools';
|
|
2
|
+
import type { Entrypoint, NestedRouteForCli, PageRoute, RouteLegacy, SSRMode } from '@modern-js/types';
|
|
3
|
+
export declare const routesForServer: ({ routesForServerLoaderMatches, }: {
|
|
4
|
+
routesForServerLoaderMatches: (NestedRouteForCli | PageRoute)[];
|
|
5
|
+
}) => string;
|
|
6
|
+
export declare const fileSystemRoutes: ({ metaName, routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, splitRouteChunks, isRscClientBundle, srcDirectory, internalSrcAlias, }: {
|
|
7
|
+
metaName: string;
|
|
8
|
+
routes: RouteLegacy[] | (NestedRouteForCli | PageRoute)[];
|
|
9
|
+
ssrMode?: SSRMode;
|
|
10
|
+
nestedRoutesEntry?: string;
|
|
11
|
+
entryName: string;
|
|
12
|
+
internalDirectory: string;
|
|
13
|
+
splitRouteChunks?: boolean;
|
|
14
|
+
isRscClientBundle?: boolean;
|
|
15
|
+
srcDirectory?: string;
|
|
16
|
+
internalSrcAlias?: string;
|
|
17
|
+
}) => Promise<string>;
|
|
18
|
+
export declare function ssrLoaderCombinedModule(entrypoints: Entrypoint[], entrypoint: Entrypoint, config: AppNormalizedConfig, appContext: AppToolsContext): string | null;
|
|
19
|
+
export declare const runtimeGlobalContext: ({ entryName, metaName, srcDirectory, nestedRoutesEntry, internalSrcAlias, globalApp, rscType, basename, }: {
|
|
20
|
+
entryName: string;
|
|
21
|
+
metaName: string;
|
|
22
|
+
srcDirectory: string;
|
|
23
|
+
nestedRoutesEntry?: string;
|
|
24
|
+
internalSrcAlias: string;
|
|
25
|
+
globalApp?: string | false;
|
|
26
|
+
rscType?: 'server' | 'client' | false;
|
|
27
|
+
basename?: string;
|
|
28
|
+
}) => Promise<string>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const walkDirectory: (dir: string) => string[];
|
|
2
|
+
export declare const isPageComponentFile: (filePath: string) => boolean;
|
|
3
|
+
export declare const replaceWithAlias: (base: string, filePath: string, alias: string) => any;
|
|
4
|
+
export declare const parseModule: ({ source, filename, }: {
|
|
5
|
+
source: string;
|
|
6
|
+
filename: string;
|
|
7
|
+
}) => Promise<readonly [imports: readonly import("es-module-lexer").ImportSpecifier[], exports: readonly import("es-module-lexer").ExportSpecifier[], facade: boolean, hasModuleSyntax: boolean]>;
|
|
8
|
+
export declare const hasLoader: (filename: string, source?: string) => Promise<boolean>;
|
|
9
|
+
export declare const hasAction: (filename: string, source?: string) => Promise<boolean>;
|
|
10
|
+
export declare const getServerLoadersFile: (internalDirectory: string, entryName: string) => string;
|
|
11
|
+
export declare const getServerCombinedModuleFile: (internalDirectory: string, entryName: string) => string;
|
|
12
|
+
export declare const getPathWithoutExt: (filename: string) => string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { NestedRouteForCli } from '@modern-js/types';
|
|
2
|
+
/**
|
|
3
|
+
* Process config-based routes: generate route id, normalize paths and discover related files.
|
|
4
|
+
* Data structure is unified to NestedRouteForCli, only metadata needs to be enriched.
|
|
5
|
+
*/
|
|
6
|
+
export declare function processConfigRoutes(configRoutes: NestedRouteForCli[], entryName: string, isMainEntry: boolean, configRoutesDir: string, alias?: {
|
|
7
|
+
name: string;
|
|
8
|
+
basename: string;
|
|
9
|
+
}): Promise<NestedRouteForCli[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Remove all `component` fields from a routes tree
|
|
12
|
+
* @param generatedRoutes - generated routes array
|
|
13
|
+
* @returns routes with `component` field removed
|
|
14
|
+
*/
|
|
15
|
+
export declare function normalizeRoutes(generatedRoutes: NestedRouteForCli[]): NestedRouteForCli[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AppToolsContext } from '@modern-js/app-tools';
|
|
2
|
+
import type { Entrypoint, NestedRouteForCli } from '@modern-js/types';
|
|
3
|
+
/**
|
|
4
|
+
* Type definitions for config-based routing
|
|
5
|
+
*/
|
|
6
|
+
export type RouteConfig = NestedRouteForCli;
|
|
7
|
+
export type RouteFunction = {
|
|
8
|
+
(component: string, path?: string, children?: RouteConfig[]): RouteConfig;
|
|
9
|
+
(component: string, children?: RouteConfig[]): RouteConfig;
|
|
10
|
+
};
|
|
11
|
+
export type LayoutFunction = {
|
|
12
|
+
(component: string, path?: string, children?: RouteConfig[]): RouteConfig;
|
|
13
|
+
(component: string, children?: RouteConfig[]): RouteConfig;
|
|
14
|
+
};
|
|
15
|
+
export type PageFunction = (component: string, path?: string) => RouteConfig;
|
|
16
|
+
export type WildcardFunction = (component: string, path?: string) => RouteConfig;
|
|
17
|
+
export interface RouteFunctions {
|
|
18
|
+
route: RouteFunction;
|
|
19
|
+
layout: LayoutFunction;
|
|
20
|
+
page: PageFunction;
|
|
21
|
+
$: WildcardFunction;
|
|
22
|
+
}
|
|
23
|
+
export type DefineRoutesFunction = (routesCallback: (routeFunctions: RouteFunctions, fileRoutes: RouteConfig[]) => RouteConfig[]) => (routeFunctions: RouteFunctions, fileRoutes: RouteConfig[]) => RouteConfig[];
|
|
24
|
+
export interface ConfigRouteFile {
|
|
25
|
+
entryName: string;
|
|
26
|
+
filePath: string;
|
|
27
|
+
routes: NestedRouteForCli[];
|
|
28
|
+
isMainEntry: boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare function findConfigRoutesFile(entrypoint: Entrypoint, appContext: AppToolsContext): Promise<string | null>;
|
|
31
|
+
export declare function parseConfigRoutesFile(filePath: string, entrypoint: Entrypoint, fileRoutes?: NestedRouteForCli[]): Promise<ConfigRouteFile>;
|
|
32
|
+
export declare function discoverAndParseConfigRoutes(entrypoint: Entrypoint, appContext: AppToolsContext, fileRoutes?: NestedRouteForCli[]): Promise<ConfigRouteFile | null>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const NESTED_ROUTES_DIR = "routes";
|
|
2
|
+
export declare const FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
|
|
3
|
+
export declare const LOADER_EXPORT_NAME = "loader";
|
|
4
|
+
export declare const ACTION_EXPORT_NAME = "action";
|
|
5
|
+
export declare const TEMP_LOADERS_DIR = "__loaders__";
|
|
6
|
+
export declare const FILE_SYSTEM_ROUTES_INDEX = "index";
|
|
7
|
+
export declare const FILE_SYSTEM_ROUTES_IGNORED_REGEX: RegExp;
|
|
8
|
+
export declare const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP: RegExp;
|
|
9
|
+
export declare const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
|
|
10
|
+
export declare const APP_CONFIG_NAME = "config";
|
|
11
|
+
export declare const APP_INIT_EXPORTED = "init";
|
|
12
|
+
export declare const NESTED_ROUTE: {
|
|
13
|
+
LAYOUT_FILE: string;
|
|
14
|
+
LAYOUT_CONFIG_FILE: string;
|
|
15
|
+
LAYOUT_LOADER_FILE: string;
|
|
16
|
+
LAYOUT_DATA_FILE: string;
|
|
17
|
+
LAYOUT_CLIENT_LOADER: string;
|
|
18
|
+
PAGE_FILE: string;
|
|
19
|
+
PAGE_CONFIG_FILE: string;
|
|
20
|
+
PAGE_LOADER_FILE: string;
|
|
21
|
+
PAGE_DATA_FILE: string;
|
|
22
|
+
PAGE_CLIENT_LOADER: string;
|
|
23
|
+
SPLATE_FILE: string;
|
|
24
|
+
SPLATE_CONFIG_FILE: string;
|
|
25
|
+
SPLATE_LOADER_FILE: string;
|
|
26
|
+
SPLATE_DATA_FILE: string;
|
|
27
|
+
SPLATE_CLIENT_DATA: string;
|
|
28
|
+
LOADING_FILE: string;
|
|
29
|
+
ERROR_FILE: string;
|
|
30
|
+
LOADER_FILE: string;
|
|
31
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Entrypoint } from '@modern-js/types';
|
|
2
|
+
export declare const ROUTES_DIR_META_KEY = "__modernRoutesDir";
|
|
3
|
+
export declare const ROUTES_OWNER_META_KEY = "__modernRoutesOwner";
|
|
4
|
+
export declare const BUILT_IN_ROUTES_OWNER = "@modern-js/plugin-router";
|
|
5
|
+
export type EntrypointWithRoutesMeta = Entrypoint & {
|
|
6
|
+
[ROUTES_DIR_META_KEY]?: string;
|
|
7
|
+
[ROUTES_OWNER_META_KEY]?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const getEntrypointRoutesDir: (entrypoint: {
|
|
10
|
+
[ROUTES_DIR_META_KEY]?: string;
|
|
11
|
+
nestedRoutesEntry?: string;
|
|
12
|
+
}) => string | null;
|
|
13
|
+
export declare const getEntrypointRoutesOwner: (entrypoint: {
|
|
14
|
+
[ROUTES_OWNER_META_KEY]?: string;
|
|
15
|
+
}) => string | null;
|
|
16
|
+
export declare const hasNestedRoutes: (dir: string, routesDir?: string) => any;
|
|
17
|
+
export declare const isRouteEntry: (dir: string, routesDir?: string) => string | false;
|
|
18
|
+
export declare const modifyEntrypoints: (entrypoints: Entrypoint[], routesDir?: string, routesOwner?: string) => EntrypointWithRoutesMeta[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AppNormalizedConfig, AppTools } from '@modern-js/app-tools';
|
|
2
|
+
import type { CLIPluginAPI } from '@modern-js/plugin';
|
|
3
|
+
import type { Entrypoint, NestedRouteForCli, PageRoute } from '@modern-js/types';
|
|
4
|
+
type GeneratedRoutesByEntry = Record<string, (NestedRouteForCli | PageRoute)[]>;
|
|
5
|
+
type RegenerateRoutesFn = (params: {
|
|
6
|
+
api: CLIPluginAPI<AppTools>;
|
|
7
|
+
appContext: ReturnType<CLIPluginAPI<AppTools>['getAppContext']>;
|
|
8
|
+
resolvedConfig: AppNormalizedConfig;
|
|
9
|
+
entrypoints: Entrypoint[];
|
|
10
|
+
}) => Promise<void>;
|
|
11
|
+
type HandleGeneratorEntryCodeOptions = {
|
|
12
|
+
entrypointsKey?: string;
|
|
13
|
+
generateCodeOptions?: {
|
|
14
|
+
enableTanstackTypes?: boolean;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
type HandleFileChangeOptions = {
|
|
18
|
+
includeEntry?: (entrypoint: Entrypoint) => boolean;
|
|
19
|
+
regenerate?: RegenerateRoutesFn;
|
|
20
|
+
entrypointsKey?: string;
|
|
21
|
+
};
|
|
22
|
+
type HandleModifyEntrypointsOptions = {
|
|
23
|
+
routesOwner?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare function handleModifyEntrypoints(entrypoints: Entrypoint[], routesDir?: string, options?: HandleModifyEntrypointsOptions): Promise<import("./entry").EntrypointWithRoutesMeta[]>;
|
|
26
|
+
export declare function handleGeneratorEntryCode(api: CLIPluginAPI<AppTools>, entrypoints: Entrypoint[], options?: HandleGeneratorEntryCodeOptions | string): Promise<GeneratedRoutesByEntry>;
|
|
27
|
+
export declare function handleFileChange(api: CLIPluginAPI<AppTools>, e: any, options?: HandleFileChangeOptions): Promise<void>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AppTools, CliPlugin } from '@modern-js/app-tools';
|
|
2
|
+
export { BUILT_IN_ROUTES_OWNER, getEntrypointRoutesDir, getEntrypointRoutesOwner, isRouteEntry, } from './entry';
|
|
3
|
+
export { handleFileChange, handleGeneratorEntryCode, handleModifyEntrypoints, } from './handler';
|
|
4
|
+
export declare const routerPlugin: () => CliPlugin<AppTools>;
|
|
5
|
+
export default routerPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './runtime';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Server Component that renders CSS link tags
|
|
4
|
+
* These will be serialized into RSC payload and automatically handled by React on client
|
|
5
|
+
* React will automatically hoist these link tags to the head
|
|
6
|
+
*/
|
|
7
|
+
export declare function CSSLinks({ cssFiles }: {
|
|
8
|
+
cssFiles: string[];
|
|
9
|
+
}): React.JSX.Element | null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { StaticHandlerContext } from '@modern-js/runtime-utils/router';
|
|
2
|
+
/**
|
|
3
|
+
* DeferredDataScripts only renders in server side,
|
|
4
|
+
* it doesn't need to be hydrated in client side.
|
|
5
|
+
*/
|
|
6
|
+
declare const DeferredDataScripts: (props?: {
|
|
7
|
+
nonce?: string;
|
|
8
|
+
useJsonScript?: boolean;
|
|
9
|
+
context: StaticHandlerContext;
|
|
10
|
+
}) => import("react").JSX.Element | null;
|
|
11
|
+
export default DeferredDataScripts;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type LinkProps as RouterLinkProps, type NavLinkProps as RouterNavLinkProps } from '@modern-js/runtime-utils/router';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Modified from https://github.com/remix-run/remix/blob/9a0601bd704d2f3ee622e0ddacab9b611eb0c5bc/packages/remix-react/components.tsx#L218
|
|
5
|
+
*
|
|
6
|
+
* MIT Licensed
|
|
7
|
+
* Author Michael Jackson
|
|
8
|
+
* Copyright 2021 Remix Software Inc.
|
|
9
|
+
* https://github.com/remix-run/remix/blob/2b5e1a72fc628d0408e27cf4d72e537762f1dc5b/LICENSE.md
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Defines the prefetching behavior of the link:
|
|
13
|
+
*
|
|
14
|
+
* - "intent": Fetched when the user focuses or hovers the link
|
|
15
|
+
* - "render": Fetched when the link is rendered
|
|
16
|
+
* - "none": Never fetched
|
|
17
|
+
*/
|
|
18
|
+
type PrefetchBehavior = 'intent' | 'render' | 'none';
|
|
19
|
+
export interface LinkProps extends RouterLinkProps {
|
|
20
|
+
prefetch?: PrefetchBehavior;
|
|
21
|
+
}
|
|
22
|
+
export interface NavLinkProps extends RouterNavLinkProps {
|
|
23
|
+
prefetch?: PrefetchBehavior;
|
|
24
|
+
}
|
|
25
|
+
declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
26
|
+
declare const NavLink: React.ForwardRefExoticComponent<NavLinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
27
|
+
export { Link, NavLink };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* setup promises for deferred data
|
|
3
|
+
* original function:
|
|
4
|
+
function setupDeferredPromise(routeId, key) {
|
|
5
|
+
_ROUTER_DATA.r = _ROUTER_DATA.r || {};
|
|
6
|
+
_ROUTER_DATA.r[routeId] = _ROUTER_DATA.r[routeId] || {};
|
|
7
|
+
const promise = new Promise(function (resolve, reject) {
|
|
8
|
+
_ROUTER_DATA.r[routeId][key] = {
|
|
9
|
+
resolve,
|
|
10
|
+
reject,
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
return promise;
|
|
14
|
+
};
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export declare const setupFnStr = "function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA.r[r]=_ROUTER_DATA.r[r]||{};return new Promise((function(A,R){_ROUTER_DATA.r[r][e]={resolve:A,reject:R}}))};";
|
|
18
|
+
/**
|
|
19
|
+
* resolve promises for deferred data
|
|
20
|
+
* original function:
|
|
21
|
+
function resolveDeferredPromise(routeId, key, data, error) {
|
|
22
|
+
if (error) {
|
|
23
|
+
_ROUTER_DATA.r[routeId][key].reject(error);
|
|
24
|
+
} else {
|
|
25
|
+
_ROUTER_DATA.r[routeId][key].resolve(data);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
*/
|
|
29
|
+
export declare const resolveFnStr = "function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};";
|
|
30
|
+
/**
|
|
31
|
+
* update data for pre resolved promises
|
|
32
|
+
* original function:
|
|
33
|
+
* function preResolvedDeferredPromise(data, error) {
|
|
34
|
+
if(typeof error !== 'undefined'){
|
|
35
|
+
return Promise.reject(new Error(error.message));
|
|
36
|
+
}else{
|
|
37
|
+
return Promise.resolve(data);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
*/
|
|
41
|
+
export declare const preResolvedFnStr = "function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resolve(e)};";
|
|
42
|
+
/**
|
|
43
|
+
* let initialScripts = '...';
|
|
44
|
+
* initialScripts += Object.entries(activeDeferreds)
|
|
45
|
+
.map(([routeId, deferredData]) => {
|
|
46
|
+
const pendingKeys = new Set(deferredData.pendingKeys);
|
|
47
|
+
const { deferredKeys } = deferredData;
|
|
48
|
+
const deferredKeyPromiseStr = deferredKeys
|
|
49
|
+
.map(key => {
|
|
50
|
+
if (pendingKeys.has(key)) {
|
|
51
|
+
deferredDataScripts.push(
|
|
52
|
+
<DeferredDataScript
|
|
53
|
+
nonce={props?.nonce}
|
|
54
|
+
key={`${routeId} | ${key}`}
|
|
55
|
+
data={deferredData.data[key]}
|
|
56
|
+
dataKey={key}
|
|
57
|
+
routeId={routeId}
|
|
58
|
+
/>,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
return `${JSON.stringify(key)}: _ROUTER_DATA.s(${JSON.stringify(
|
|
62
|
+
routeId,
|
|
63
|
+
)},${JSON.stringify(key)}) `;
|
|
64
|
+
} else {
|
|
65
|
+
const trackedPromise = deferredData.data[key] as TrackedPromise;
|
|
66
|
+
if (typeof trackedPromise._error !== 'undefined') {
|
|
67
|
+
const error = {
|
|
68
|
+
message: trackedPromise._error.message,
|
|
69
|
+
stack:
|
|
70
|
+
process.env.NODE_ENV !== 'production'
|
|
71
|
+
? trackedPromise._error.stack
|
|
72
|
+
: undefined,
|
|
73
|
+
};
|
|
74
|
+
return `${JSON.stringify(
|
|
75
|
+
key,
|
|
76
|
+
)}: _ROUTER_DATA.p(${undefined}, ${serializeJson(error)})`;
|
|
77
|
+
} else {
|
|
78
|
+
if (typeof trackedPromise._data === 'undefined') {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return `${JSON.stringify(key)}: _ROUTER_DATA.p(${serializeJson(
|
|
84
|
+
trackedPromise._data,
|
|
85
|
+
)})`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
.join(',\n');
|
|
90
|
+
|
|
91
|
+
return `Object.assign(_ROUTER_DATA.loaderData[${JSON.stringify(
|
|
92
|
+
routeId,
|
|
93
|
+
)}], {${deferredKeyPromiseStr}});`;
|
|
94
|
+
})
|
|
95
|
+
.join('\n');
|
|
96
|
+
*/
|
|
97
|
+
/**
|
|
98
|
+
* Abstracting the above logic to `mergeLoaderData`:
|
|
99
|
+
* function mergeLoaderData (routeIdJsonStr, deferredKeyPromiseManifests) {
|
|
100
|
+
const source = deferredKeyPromiseManifests.reduce(function(o, {key, routerDataFnName, routerDataFnArgs }) {
|
|
101
|
+
const args = routerDataFnArgs.map(arg => {
|
|
102
|
+
if (arg === 'undefined' || arg === null) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
return JSON.parse(arg);
|
|
106
|
+
});
|
|
107
|
+
return {...o, [key]: _ROUTER_DATA[routerDataFnName](...args)};
|
|
108
|
+
}, {});
|
|
109
|
+
Object.assign(_ROUTER_DATA.loaderData[routeIdJsonStr], source);
|
|
110
|
+
};
|
|
111
|
+
*/
|
|
112
|
+
export declare const mergeLoaderDataStr = "function mergeLoaderData(e,n){var r=n.reduce((function(e,{key:n,routerDataFnName:r,routerDataFnArgs:a}){var t=a.map((e=>{if(\"undefined\"!==e&&null!==e)return JSON.parse(e)}));return{...e,[n]:_ROUTER_DATA[r](...t)}}),{});_ROUTER_DATA.loaderData=_ROUTER_DATA.loaderData||{},_ROUTER_DATA.loaderData[e]=_ROUTER_DATA.loaderData[e]||{},Object.assign(_ROUTER_DATA.loaderData[e],r)}";
|
|
113
|
+
/**
|
|
114
|
+
* This original string is: ${setupFnStr};${resolveFnStr};${preResolvedFnStr};
|
|
115
|
+
* function mergeData (routeIdJsonStr, deferredKeyPromiseManifests) {
|
|
116
|
+
const source = deferredKeyPromiseManifests.reduce(function(o, {key, routerDataFnName, routerDataFnArgs }) {
|
|
117
|
+
return {...o, [key]: _ROUTER_DATA[routerDataFnName](...routerDataFnArgs)}
|
|
118
|
+
}, {});
|
|
119
|
+
Object.assign(_ROUTER_DATA.loaderData[routeIdJsonStr], source);
|
|
120
|
+
};
|
|
121
|
+
*/
|
|
122
|
+
export declare const initRouterDataAttrs = "_ROUTER_DATA.s = function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA.r[r]=_ROUTER_DATA.r[r]||{};return new Promise((function(A,R){_ROUTER_DATA.r[r][e]={resolve:A,reject:R}}))};_ROUTER_DATA.r = function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};_ROUTER_DATA.p = function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resolve(e)};function mergeLoaderData(e,n){var r=n.reduce((function(e,{key:n,routerDataFnName:r,routerDataFnArgs:a}){var t=a.map((e=>{if(\"undefined\"!==e&&null!==e)return JSON.parse(e)}));return{...e,[n]:_ROUTER_DATA[r](...t)}}),{});_ROUTER_DATA.loaderData=_ROUTER_DATA.loaderData||{},_ROUTER_DATA.loaderData[e]=_ROUTER_DATA.loaderData[e]||{},Object.assign(_ROUTER_DATA.loaderData[e],r)}";
|
|
123
|
+
/**
|
|
124
|
+
function runWindowFn() {
|
|
125
|
+
window[document.currentScript.getAttribute('data-fn-name')](...JSON.parse(document.currentScript.getAttribute('data-fn-args')))
|
|
126
|
+
}
|
|
127
|
+
function runRouterDataFn() {
|
|
128
|
+
_ROUTER_DATA[document.currentScript.getAttribute('data-fn-name')](...JSON.parse(document.currentScript.getAttribute('data-fn-args')))
|
|
129
|
+
}
|
|
130
|
+
function initRouterData(id) {
|
|
131
|
+
const ele = document.getElementById(id);
|
|
132
|
+
if (ele) {
|
|
133
|
+
try {
|
|
134
|
+
_ROUTER_DATA = JSON.parse(ele.textContent);
|
|
135
|
+
} catch(e) {
|
|
136
|
+
console.error("parse ".concat(id, " error"), t);
|
|
137
|
+
_ROUTER_DATA = {};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
initRouterData();
|
|
142
|
+
${initRouterDataAttrs}
|
|
143
|
+
*/
|
|
144
|
+
export declare const modernInline = "function runWindowFn(){window[document.currentScript.getAttribute(\"data-fn-name\")].apply(window,JSON.parse(document.currentScript.getAttribute(\"data-fn-args\")))}function runRouterDataFn(){_ROUTER_DATA[document.currentScript.getAttribute(\"data-fn-name\")].apply(_ROUTER_DATA,JSON.parse(document.currentScript.getAttribute(\"data-fn-args\")))}function initRouterData(e){var r=document.getElementById(e);if(r)try{_ROUTER_DATA=JSON.parse(r.textContent)}catch(r){console.error(\"parse \".concat(e,\" error\"),t),_ROUTER_DATA={}}};initRouterData('__MODERN_ROUTER_DATA__');_ROUTER_DATA.s = function s(r,e){_ROUTER_DATA.r=_ROUTER_DATA.r||{},_ROUTER_DATA.r[r]=_ROUTER_DATA.r[r]||{};return new Promise((function(A,R){_ROUTER_DATA.r[r][e]={resolve:A,reject:R}}))};_ROUTER_DATA.r = function r(e,r,o,A){A?_ROUTER_DATA.r[e][r].reject(A):_ROUTER_DATA.r[e][r].resolve(o)};_ROUTER_DATA.p = function p(e,r){return void 0!==r?Promise.reject(new Error(r.message)):Promise.resolve(e)};function mergeLoaderData(e,n){var r=n.reduce((function(e,{key:n,routerDataFnName:r,routerDataFnArgs:a}){var t=a.map((e=>{if(\"undefined\"!==e&&null!==e)return JSON.parse(e)}));return{...e,[n]:_ROUTER_DATA[r](...t)}}),{});_ROUTER_DATA.loaderData=_ROUTER_DATA.loaderData||{},_ROUTER_DATA.loaderData[e]=_ROUTER_DATA.loaderData[e]||{},Object.assign(_ROUTER_DATA.loaderData[e],r)}";
|
|
145
|
+
export declare const runRouterDataFnStr = "runRouterDataFn();";
|
|
146
|
+
export declare const runWindowFnStr = "runWindowFn();";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RouteObject } from '@modern-js/runtime-utils/router';
|
|
2
|
+
import type { TRuntimeContext } from '../../core/context/runtime';
|
|
3
|
+
import type { RouterLifecycleContext } from './lifecycle';
|
|
4
|
+
declare const modifyRoutes: import("@modern-js/plugin").SyncHook<(routes: RouteObject[]) => RouteObject[]>;
|
|
5
|
+
declare const onBeforeCreateRoutes: import("@modern-js/plugin").SyncHook<(context: TRuntimeContext) => void>;
|
|
6
|
+
declare const onBeforeCreateRouter: import("@modern-js/plugin").SyncHook<(context: RouterLifecycleContext) => void>;
|
|
7
|
+
declare const onAfterCreateRouter: import("@modern-js/plugin").SyncHook<(context: RouterLifecycleContext) => void>;
|
|
8
|
+
declare const onBeforeHydrateRouter: import("@modern-js/plugin").SyncHook<(context: RouterLifecycleContext) => void>;
|
|
9
|
+
declare const onAfterHydrateRouter: import("@modern-js/plugin").SyncHook<(context: RouterLifecycleContext) => void>;
|
|
10
|
+
export { modifyRoutes, onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBeforeCreateRoutes, onBeforeHydrateRouter, };
|
|
11
|
+
export type RouterExtendsHooks = {
|
|
12
|
+
modifyRoutes: typeof modifyRoutes;
|
|
13
|
+
onBeforeCreateRoutes: typeof onBeforeCreateRoutes;
|
|
14
|
+
onBeforeCreateRouter: typeof onBeforeCreateRouter;
|
|
15
|
+
onAfterCreateRouter: typeof onAfterCreateRouter;
|
|
16
|
+
onBeforeHydrateRouter: typeof onBeforeHydrateRouter;
|
|
17
|
+
onAfterHydrateRouter: typeof onAfterHydrateRouter;
|
|
18
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useRouteLoaderData as useRouteData } from '@modern-js/runtime-utils/router';
|
|
2
|
+
export * from '@modern-js/runtime-utils/router';
|
|
3
|
+
export type { LinkProps, NavLinkProps } from './PrefetchLink';
|
|
4
|
+
export { Link, NavLink } from './PrefetchLink';
|
|
5
|
+
export declare const useRouteLoaderData: typeof useRouteData;
|
|
6
|
+
export type { LoaderFunction, LoaderFunctionArgs } from './types';
|
|
7
|
+
export * from './withRouter';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RuntimePlugin } from '../../core';
|
|
2
|
+
import type { RouterExtendsHooks } from './hooks';
|
|
3
|
+
import type { RouterConfig, SingleRouteConfig } from './types';
|
|
4
|
+
export declare const routerPlugin: (userConfig?: Partial<RouterConfig>) => RuntimePlugin<{
|
|
5
|
+
extendHooks: RouterExtendsHooks;
|
|
6
|
+
}>;
|
|
7
|
+
export default routerPlugin;
|
|
8
|
+
export type { RouterExtendsHooks } from './hooks';
|
|
9
|
+
export { modifyRoutes } from './plugin';
|
|
10
|
+
export { renderRoutes } from './utils';
|
|
11
|
+
export type { RouterConfig, SingleRouteConfig };
|