@modern-js/runtime 1.4.4 → 1.16.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/CHANGELOG.md +65 -0
- package/dist/js/modern/cli/index.js +6 -6
- package/dist/js/modern/core/app-config.js +10 -0
- package/dist/js/modern/core/compatible.js +241 -0
- package/dist/js/modern/core/index.js +7 -0
- package/dist/js/modern/core/loader/index.js +1 -0
- package/dist/js/modern/core/loader/loaderManager.js +189 -0
- package/dist/js/modern/core/loader/useLoader.js +105 -0
- package/dist/js/modern/core/plugin.js +63 -0
- package/dist/js/modern/core/runtime-context.js +2 -0
- package/dist/js/modern/exports/styled.js +2 -2
- package/dist/js/modern/index.js +1 -1
- package/dist/js/modern/router/runtime/plugin.js +1 -1
- package/dist/js/modern/router/runtime/utils.js +3 -1
- package/dist/js/modern/ssr/index.js +34 -13
- package/dist/js/modern/ssr/index.node.js +1 -1
- package/dist/js/modern/ssr/prefetch.js +2 -2
- package/dist/js/modern/ssr/react/withCallback/index.js +17 -0
- package/dist/js/modern/ssr/serverRender/helmet.js +2 -2
- package/dist/js/modern/ssr/serverRender/index.js +1 -1
- package/dist/js/modern/ssr/serverRender/styledComponent.js +1 -1
- package/dist/js/modern/ssr/utils.js +9 -3
- package/dist/js/modern/state/runtime/plugin.js +1 -1
- package/dist/js/node/cli/index.js +5 -5
- package/dist/js/node/core/app-config.js +22 -0
- package/dist/js/node/core/compatible.js +271 -0
- package/dist/js/node/core/index.js +111 -0
- package/dist/js/node/core/loader/index.js +15 -0
- package/dist/js/node/core/loader/loaderManager.js +201 -0
- package/dist/js/node/core/loader/useLoader.js +118 -0
- package/dist/js/node/core/plugin.js +79 -0
- package/dist/js/node/core/runtime-context.js +11 -0
- package/dist/js/node/exports/styled.js +5 -5
- package/dist/js/node/index.js +10 -10
- package/dist/js/node/router/runtime/plugin.js +3 -3
- package/dist/js/node/router/runtime/utils.js +3 -1
- package/dist/js/node/ssr/index.js +37 -15
- package/dist/js/node/ssr/index.node.js +2 -2
- package/dist/js/node/ssr/react/withCallback/index.js +27 -0
- package/dist/js/node/ssr/serverRender/helmet.js +2 -2
- package/dist/js/node/ssr/serverRender/index.js +2 -2
- package/dist/js/node/ssr/serverRender/styledComponent.js +2 -2
- package/dist/js/node/ssr/utils.js +9 -3
- package/dist/js/node/state/runtime/plugin.js +3 -3
- package/dist/js/treeshaking/cli/index.js +6 -6
- package/dist/js/treeshaking/core/app-config.js +13 -0
- package/dist/js/treeshaking/core/compatible.js +297 -0
- package/dist/js/treeshaking/core/index.js +7 -0
- package/dist/js/treeshaking/core/loader/index.js +1 -0
- package/dist/js/treeshaking/core/loader/loaderManager.js +267 -0
- package/dist/js/treeshaking/core/loader/useLoader.js +107 -0
- package/dist/js/treeshaking/core/plugin.js +105 -0
- package/dist/js/treeshaking/core/runtime-context.js +2 -0
- package/dist/js/treeshaking/exports/styled.js +2 -2
- package/dist/js/treeshaking/index.js +1 -1
- package/dist/js/treeshaking/router/runtime/plugin.js +1 -1
- package/dist/js/treeshaking/router/runtime/utils.js +3 -1
- package/dist/js/treeshaking/ssr/index.js +45 -33
- package/dist/js/treeshaking/ssr/index.node.js +1 -1
- package/dist/js/treeshaking/ssr/prefetch.js +2 -2
- package/dist/js/treeshaking/ssr/react/withCallback/index.js +16 -0
- package/dist/js/treeshaking/ssr/serverRender/helmet.js +2 -2
- package/dist/js/treeshaking/ssr/serverRender/index.js +1 -1
- package/dist/js/treeshaking/ssr/serverRender/styledComponent.js +1 -1
- package/dist/js/treeshaking/ssr/utils.js +8 -3
- package/dist/js/treeshaking/state/runtime/plugin.js +1 -1
- package/dist/types/core/app-config.d.ts +6 -0
- package/dist/types/core/compatible.d.ts +17 -0
- package/dist/types/core/index.d.ts +9 -0
- package/dist/types/core/loader/index.d.ts +2 -0
- package/dist/types/core/loader/loaderManager.d.ts +57 -0
- package/dist/types/core/loader/useLoader.d.ts +54 -0
- package/dist/types/core/plugin.d.ts +215 -0
- package/dist/types/core/runtime-context.d.ts +13 -0
- package/dist/types/exports/styled.d.ts +2 -2
- package/dist/types/index.d.ts +4 -9
- package/dist/types/router/runtime/plugin.d.ts +1 -1
- package/dist/types/ssr/index.d.ts +2 -2
- package/dist/types/ssr/index.node.d.ts +1 -1
- package/dist/types/ssr/prefetch.d.ts +2 -2
- package/dist/types/ssr/react/nossr/index.d.ts +1 -1
- package/dist/types/ssr/react/withCallback/index.d.ts +5 -0
- package/dist/types/ssr/serverRender/entry.d.ts +1 -1
- package/dist/types/ssr/serverRender/index.d.ts +1 -1
- package/dist/types/ssr/serverRender/type.d.ts +1 -1
- package/dist/types/state/runtime/plugin.d.ts +2 -2
- package/lib/types.d.ts +10 -0
- package/package.json +39 -27
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// See https://github.com/reactwg/react-18/discussions/5#discussioncomment-2276079
|
|
2
|
+
import { useRef, useLayoutEffect } from 'react';
|
|
3
|
+
export var WithCallback = function WithCallback(_ref) {
|
|
4
|
+
var callback = _ref.callback,
|
|
5
|
+
children = _ref.children;
|
|
6
|
+
var once = useRef(false);
|
|
7
|
+
useLayoutEffect(function () {
|
|
8
|
+
if (once.current) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
once.current = true;
|
|
13
|
+
callback();
|
|
14
|
+
}, [callback]);
|
|
15
|
+
return children;
|
|
16
|
+
};
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
var RE_HTML_ATTR = /<html[^>]*>/;
|
|
3
3
|
var RE_BODY_ATTR = /<body[^>]*>/;
|
|
4
4
|
var RE_LAST_IN_HEAD = /<\/head>/;
|
|
5
|
-
var RE_TITLE = /<title[^>]*>([\s\S\n\r]*?)<\/title
|
|
6
|
-
var TEST_TITLE_CONTENT = /(?<=<title[^>]*>)([\s\S\n\r]*?)([.|\S])([\s\S\n\r]*?)(?=<\/title>)
|
|
5
|
+
var RE_TITLE = /<title[^>]*>([\s\S\n\r]*?)<\/title>/;
|
|
6
|
+
var TEST_TITLE_CONTENT = /(?<=<title[^>]*>)([\s\S\n\r]*?)([.|\S])([\s\S\n\r]*?)(?=<\/title>)/; // 通过 react-helmet 修改模板
|
|
7
7
|
|
|
8
8
|
export default function helmet(content, helmetData) {
|
|
9
9
|
var result = content;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
-
import { RuntimeContext } from '@modern-js/runtime-core';
|
|
4
3
|
import { run } from '@modern-js/utils/ssr';
|
|
4
|
+
import { RuntimeContext } from "../../core";
|
|
5
5
|
import { PreRender } from "../react/prerender";
|
|
6
6
|
import SSREntry from "./entry";
|
|
7
7
|
import { time } from "./measure";
|
|
@@ -22,20 +22,25 @@ var getQuery = function getQuery() {
|
|
|
22
22
|
key = _item$split2[0],
|
|
23
23
|
value = _item$split2[1];
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
if (key) {
|
|
26
|
+
res[key] = value;
|
|
27
|
+
}
|
|
28
|
+
|
|
26
29
|
return res;
|
|
27
30
|
}, {});
|
|
28
31
|
};
|
|
29
32
|
|
|
30
33
|
export var formatClient = function formatClient(request) {
|
|
34
|
+
var _request$headers, _request$headers2;
|
|
35
|
+
|
|
31
36
|
return {
|
|
32
37
|
params: request.params || {},
|
|
33
38
|
host: request.host || location.host,
|
|
34
39
|
pathname: request.pathname || location.pathname,
|
|
35
40
|
headers: request.headers || {},
|
|
36
41
|
cookieMap: request.cookieMap || {},
|
|
37
|
-
cookie: request.headers.cookie || document.cookie,
|
|
38
|
-
userAgent: request.headers['user-agent'] || navigator.userAgent,
|
|
42
|
+
cookie: ((_request$headers = request.headers) === null || _request$headers === void 0 ? void 0 : _request$headers.cookie) || document.cookie,
|
|
43
|
+
userAgent: ((_request$headers2 = request.headers) === null || _request$headers2 === void 0 ? void 0 : _request$headers2['user-agent']) || navigator.userAgent,
|
|
39
44
|
referer: request.referer || document.referrer,
|
|
40
45
|
query: request.query || getQuery(),
|
|
41
46
|
url: location.href
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import { useContext } from 'react';
|
|
3
|
-
import { RuntimeReactContext } from '@modern-js/runtime-core';
|
|
4
3
|
import { createStore } from '@modern-js-reduck/store';
|
|
5
4
|
import { Provider } from '@modern-js-reduck/react';
|
|
6
5
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
6
|
+
import { RuntimeReactContext } from "../../core";
|
|
7
7
|
import { isBrowser } from "../../common";
|
|
8
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
9
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
export interface AppConfig {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
}
|
|
5
|
+
export declare const getConfig: (Component: React.ComponentType<any>) => AppConfig | undefined;
|
|
6
|
+
export declare const defineConfig: (Component: React.ComponentType<any>, config: AppConfig) => React.ComponentType<any>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Plugin } from './plugin';
|
|
3
|
+
import { TRuntimeContext } from './runtime-context';
|
|
4
|
+
export declare type CreateAppOptions = {
|
|
5
|
+
plugins: Plugin[];
|
|
6
|
+
};
|
|
7
|
+
export declare const createApp: ({
|
|
8
|
+
plugins
|
|
9
|
+
}: CreateAppOptions) => (App?: React.ComponentType<any>) => React.ComponentType<any>;
|
|
10
|
+
interface HydrateFunc {
|
|
11
|
+
(container: Element | Document, initialChildren: React.ReactNode): void;
|
|
12
|
+
(initialChildren: React.ReactNode, container: Element | Document, callback?: () => void): void;
|
|
13
|
+
}
|
|
14
|
+
declare type BootStrap<T = unknown> = (App: React.ComponentType, id?: string | Record<string, any> | HTMLElement, root?: any, render?: (children: React.ReactNode, rootElement?: HTMLElement) => void, hydrate?: HydrateFunc) => Promise<T>;
|
|
15
|
+
export declare const bootstrap: BootStrap;
|
|
16
|
+
export declare const useRuntimeContext: () => TRuntimeContext;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { createPlugin, createRuntime, runtime, registerInit, registerPrefetch } from './plugin';
|
|
2
|
+
export type { Plugin } from './plugin';
|
|
3
|
+
export { defineConfig, getConfig } from './app-config';
|
|
4
|
+
export type { AppConfig } from './app-config';
|
|
5
|
+
export * from './compatible';
|
|
6
|
+
export type { TRuntimeContext, RuntimeContext } from './runtime-context';
|
|
7
|
+
export { RuntimeReactContext } from './runtime-context';
|
|
8
|
+
export * from './loader';
|
|
9
|
+
export * from '@modern-js/plugin';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { LoaderOptions } from './useLoader';
|
|
2
|
+
export declare enum LoaderStatus {
|
|
3
|
+
idle = 0,
|
|
4
|
+
loading = 1,
|
|
5
|
+
fulfilled = 2,
|
|
6
|
+
rejected = 3,
|
|
7
|
+
}
|
|
8
|
+
export declare type LoaderResult = {
|
|
9
|
+
loading: boolean;
|
|
10
|
+
reloading: boolean;
|
|
11
|
+
data: any;
|
|
12
|
+
error: any;
|
|
13
|
+
_error?: any;
|
|
14
|
+
};
|
|
15
|
+
declare const createLoader: (id: string, initialData: Partial<LoaderResult> | undefined, loaderFn: () => Promise<any>, skip?: boolean) => {
|
|
16
|
+
readonly result: {
|
|
17
|
+
loading: boolean;
|
|
18
|
+
reloading: boolean;
|
|
19
|
+
data: any;
|
|
20
|
+
error: any;
|
|
21
|
+
_error: any;
|
|
22
|
+
};
|
|
23
|
+
readonly promise: Promise<any> | null;
|
|
24
|
+
onChange: (handler: (status: LoaderStatus, result: LoaderResult) => void) => () => void;
|
|
25
|
+
load: () => Promise<any>;
|
|
26
|
+
};
|
|
27
|
+
declare type ManagerOption = {
|
|
28
|
+
/**
|
|
29
|
+
* whether current manage only exec static loader
|
|
30
|
+
*/
|
|
31
|
+
skipStatic?: boolean;
|
|
32
|
+
skipNonStatic?: boolean;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Create loaders manager. It's returned instance will add to context
|
|
36
|
+
* @param initialDataMap used to initialing loader data
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
export declare const createLoaderManager: (initialDataMap: Record<string, LoaderResult>, managerOptions?: ManagerOption) => {
|
|
40
|
+
hasPendingLoaders: () => boolean;
|
|
41
|
+
awaitPendingLoaders: () => Promise<Record<string, LoaderResult>>;
|
|
42
|
+
add: (loaderFn: () => Promise<any>, loaderOptions: LoaderOptions) => any;
|
|
43
|
+
get: (id: string) => {
|
|
44
|
+
readonly result: {
|
|
45
|
+
loading: boolean;
|
|
46
|
+
reloading: boolean;
|
|
47
|
+
data: any;
|
|
48
|
+
error: any;
|
|
49
|
+
_error: any;
|
|
50
|
+
};
|
|
51
|
+
readonly promise: Promise<any> | null;
|
|
52
|
+
onChange: (handler: (status: LoaderStatus, result: LoaderResult) => void) => () => void;
|
|
53
|
+
load: () => Promise<any>;
|
|
54
|
+
} | undefined;
|
|
55
|
+
};
|
|
56
|
+
export declare type Loader = ReturnType<typeof createLoader>;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { LoaderResult } from './loaderManager';
|
|
2
|
+
export interface SSRData {
|
|
3
|
+
loadersData: Record<string, LoaderResult | undefined>;
|
|
4
|
+
initialData?: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
export interface SSRContainer {
|
|
7
|
+
data?: SSRData;
|
|
8
|
+
}
|
|
9
|
+
declare global {
|
|
10
|
+
interface Window {
|
|
11
|
+
_SSR_DATA?: SSRContainer;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export interface LoaderOptions<Params = any, TData = any, TError extends Error = any> {
|
|
15
|
+
/**
|
|
16
|
+
* Revoke when loader excuted successfully.
|
|
17
|
+
*/
|
|
18
|
+
onSuccess?: (data: TData) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Revoke when loader ended with error
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
onError?: (error: TError) => void;
|
|
24
|
+
/**
|
|
25
|
+
* initialData to display once loader is ready.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
initialData?: TData;
|
|
29
|
+
/**
|
|
30
|
+
* whether skip loader
|
|
31
|
+
* if true, the loader will not exec.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
skip?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* User params, it will pass to loader's second parameter.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
params?: Params;
|
|
40
|
+
/**
|
|
41
|
+
* whether loader can exec on build phase.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
static?: boolean;
|
|
45
|
+
}
|
|
46
|
+
declare type LoaderFn<P = any, T = any> = (context: any, params: P) => Promise<T>;
|
|
47
|
+
declare const useLoader: <TData = any, Params = any, E = any>(loaderFn: LoaderFn<Params, TData>, options?: LoaderOptions<Params, any, any>) => {
|
|
48
|
+
reload: (params?: Params | undefined) => Promise<any> | undefined;
|
|
49
|
+
loading: boolean;
|
|
50
|
+
reloading: boolean;
|
|
51
|
+
data: TData;
|
|
52
|
+
error: E;
|
|
53
|
+
};
|
|
54
|
+
export default useLoader;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { Setup, ToThreads, CommonAPI, PluginOptions } from '@modern-js/plugin';
|
|
3
|
+
import type { RuntimeContext, TRuntimeContext } from './runtime-context';
|
|
4
|
+
export interface AppProps {}
|
|
5
|
+
declare const runtimeHooks: {
|
|
6
|
+
hoc: import("@modern-js/plugin").Pipeline<{
|
|
7
|
+
App: React.ComponentType<any>;
|
|
8
|
+
}, React.ComponentType<any>>;
|
|
9
|
+
provide: import("@modern-js/plugin").Pipeline<{
|
|
10
|
+
element: JSX.Element;
|
|
11
|
+
readonly props: AppProps;
|
|
12
|
+
readonly context: RuntimeContext;
|
|
13
|
+
}, JSX.Element>;
|
|
14
|
+
client: import("@modern-js/plugin").AsyncPipeline<{
|
|
15
|
+
App: React.ComponentType<any>;
|
|
16
|
+
readonly context?: RuntimeContext | undefined;
|
|
17
|
+
ModernRender: (App: React.ReactNode) => void;
|
|
18
|
+
ModernHydrate: (App: React.ReactNode, callback?: () => void) => void;
|
|
19
|
+
}, void>;
|
|
20
|
+
server: import("@modern-js/plugin").AsyncPipeline<{
|
|
21
|
+
App: React.ComponentType<any>;
|
|
22
|
+
readonly context?: RuntimeContext | undefined;
|
|
23
|
+
}, string>;
|
|
24
|
+
init: import("@modern-js/plugin").AsyncPipeline<{
|
|
25
|
+
context: RuntimeContext;
|
|
26
|
+
}, unknown>;
|
|
27
|
+
pickContext: import("@modern-js/plugin").Pipeline<{
|
|
28
|
+
context: RuntimeContext;
|
|
29
|
+
pickedContext: TRuntimeContext;
|
|
30
|
+
}, TRuntimeContext>;
|
|
31
|
+
};
|
|
32
|
+
/** All hooks of runtime plugin. */
|
|
33
|
+
|
|
34
|
+
export declare type RuntimeHooks = typeof runtimeHooks;
|
|
35
|
+
/** All hook callbacks of runtime plugin. */
|
|
36
|
+
|
|
37
|
+
export declare type RuntimeHookCallbacks = ToThreads<RuntimeHooks>;
|
|
38
|
+
/** All apis for runtime plugin. */
|
|
39
|
+
|
|
40
|
+
export declare type PluginAPI = CommonAPI<RuntimeHooks>;
|
|
41
|
+
/** Plugin options of a runtime plugin. */
|
|
42
|
+
|
|
43
|
+
export declare type Plugin = PluginOptions<RuntimeHooks, Setup<RuntimeHooks>>;
|
|
44
|
+
export declare const createRuntime: () => import("@modern-js/plugin").Manager<{
|
|
45
|
+
hoc: import("@modern-js/plugin").Pipeline<{
|
|
46
|
+
App: React.ComponentType<any>;
|
|
47
|
+
}, React.ComponentType<any>>;
|
|
48
|
+
provide: import("@modern-js/plugin").Pipeline<{
|
|
49
|
+
element: JSX.Element;
|
|
50
|
+
readonly props: AppProps;
|
|
51
|
+
readonly context: RuntimeContext;
|
|
52
|
+
}, JSX.Element>;
|
|
53
|
+
client: import("@modern-js/plugin").AsyncPipeline<{
|
|
54
|
+
App: React.ComponentType<any>;
|
|
55
|
+
readonly context?: RuntimeContext | undefined;
|
|
56
|
+
ModernRender: (App: React.ReactNode) => void;
|
|
57
|
+
ModernHydrate: (App: React.ReactNode, callback?: () => void) => void;
|
|
58
|
+
}, void>;
|
|
59
|
+
server: import("@modern-js/plugin").AsyncPipeline<{
|
|
60
|
+
App: React.ComponentType<any>;
|
|
61
|
+
readonly context?: RuntimeContext | undefined;
|
|
62
|
+
}, string>;
|
|
63
|
+
init: import("@modern-js/plugin").AsyncPipeline<{
|
|
64
|
+
context: RuntimeContext;
|
|
65
|
+
}, unknown>;
|
|
66
|
+
pickContext: import("@modern-js/plugin").Pipeline<{
|
|
67
|
+
context: RuntimeContext;
|
|
68
|
+
pickedContext: TRuntimeContext;
|
|
69
|
+
}, TRuntimeContext>;
|
|
70
|
+
}, Record<string, never>>;
|
|
71
|
+
/**
|
|
72
|
+
* register init hook. It would be revoked both ssr and csr.
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
declare const registerInit: (App: React.ComponentType, _init: (context: RuntimeContext) => any | Promise<any>) => void;
|
|
76
|
+
/**
|
|
77
|
+
* register prefetch hook. It would be revoked both ssr and csr.
|
|
78
|
+
* But if ssr success, It wont exec in csr again.
|
|
79
|
+
* If ssr prefetch failed, It will fallback to exec in csr.
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
declare const registerPrefetch: (App: React.ComponentType, prefetch: (context: RuntimeContext) => Promise<any>) => void;
|
|
83
|
+
export declare const runtime: import("@modern-js/plugin").Manager<{
|
|
84
|
+
hoc: import("@modern-js/plugin").Pipeline<{
|
|
85
|
+
App: React.ComponentType<any>;
|
|
86
|
+
}, React.ComponentType<any>>;
|
|
87
|
+
provide: import("@modern-js/plugin").Pipeline<{
|
|
88
|
+
element: JSX.Element;
|
|
89
|
+
readonly props: AppProps;
|
|
90
|
+
readonly context: RuntimeContext;
|
|
91
|
+
}, JSX.Element>;
|
|
92
|
+
client: import("@modern-js/plugin").AsyncPipeline<{
|
|
93
|
+
App: React.ComponentType<any>;
|
|
94
|
+
readonly context?: RuntimeContext | undefined;
|
|
95
|
+
ModernRender: (App: React.ReactNode) => void;
|
|
96
|
+
ModernHydrate: (App: React.ReactNode, callback?: () => void) => void;
|
|
97
|
+
}, void>;
|
|
98
|
+
server: import("@modern-js/plugin").AsyncPipeline<{
|
|
99
|
+
App: React.ComponentType<any>;
|
|
100
|
+
readonly context?: RuntimeContext | undefined;
|
|
101
|
+
}, string>;
|
|
102
|
+
init: import("@modern-js/plugin").AsyncPipeline<{
|
|
103
|
+
context: RuntimeContext;
|
|
104
|
+
}, unknown>;
|
|
105
|
+
pickContext: import("@modern-js/plugin").Pipeline<{
|
|
106
|
+
context: RuntimeContext;
|
|
107
|
+
pickedContext: TRuntimeContext;
|
|
108
|
+
}, TRuntimeContext>;
|
|
109
|
+
}, Record<string, never>>;
|
|
110
|
+
export declare const createPlugin: (setup?: Setup<{
|
|
111
|
+
hoc: import("@modern-js/plugin").Pipeline<{
|
|
112
|
+
App: React.ComponentType<any>;
|
|
113
|
+
}, React.ComponentType<any>>;
|
|
114
|
+
provide: import("@modern-js/plugin").Pipeline<{
|
|
115
|
+
element: JSX.Element;
|
|
116
|
+
readonly props: AppProps;
|
|
117
|
+
readonly context: RuntimeContext;
|
|
118
|
+
}, JSX.Element>;
|
|
119
|
+
client: import("@modern-js/plugin").AsyncPipeline<{
|
|
120
|
+
App: React.ComponentType<any>;
|
|
121
|
+
readonly context?: RuntimeContext | undefined;
|
|
122
|
+
ModernRender: (App: React.ReactNode) => void;
|
|
123
|
+
ModernHydrate: (App: React.ReactNode, callback?: () => void) => void;
|
|
124
|
+
}, void>;
|
|
125
|
+
server: import("@modern-js/plugin").AsyncPipeline<{
|
|
126
|
+
App: React.ComponentType<any>;
|
|
127
|
+
readonly context?: RuntimeContext | undefined;
|
|
128
|
+
}, string>;
|
|
129
|
+
init: import("@modern-js/plugin").AsyncPipeline<{
|
|
130
|
+
context: RuntimeContext;
|
|
131
|
+
}, unknown>;
|
|
132
|
+
pickContext: import("@modern-js/plugin").Pipeline<{
|
|
133
|
+
context: RuntimeContext;
|
|
134
|
+
pickedContext: TRuntimeContext;
|
|
135
|
+
}, TRuntimeContext>;
|
|
136
|
+
}, Record<string, never>> | undefined, options?: PluginOptions<{
|
|
137
|
+
hoc: import("@modern-js/plugin").Pipeline<{
|
|
138
|
+
App: React.ComponentType<any>;
|
|
139
|
+
}, React.ComponentType<any>>;
|
|
140
|
+
provide: import("@modern-js/plugin").Pipeline<{
|
|
141
|
+
element: JSX.Element;
|
|
142
|
+
readonly props: AppProps;
|
|
143
|
+
readonly context: RuntimeContext;
|
|
144
|
+
}, JSX.Element>;
|
|
145
|
+
client: import("@modern-js/plugin").AsyncPipeline<{
|
|
146
|
+
App: React.ComponentType<any>;
|
|
147
|
+
readonly context?: RuntimeContext | undefined;
|
|
148
|
+
ModernRender: (App: React.ReactNode) => void;
|
|
149
|
+
ModernHydrate: (App: React.ReactNode, callback?: () => void) => void;
|
|
150
|
+
}, void>;
|
|
151
|
+
server: import("@modern-js/plugin").AsyncPipeline<{
|
|
152
|
+
App: React.ComponentType<any>;
|
|
153
|
+
readonly context?: RuntimeContext | undefined;
|
|
154
|
+
}, string>;
|
|
155
|
+
init: import("@modern-js/plugin").AsyncPipeline<{
|
|
156
|
+
context: RuntimeContext;
|
|
157
|
+
}, unknown>;
|
|
158
|
+
pickContext: import("@modern-js/plugin").Pipeline<{
|
|
159
|
+
context: RuntimeContext;
|
|
160
|
+
pickedContext: TRuntimeContext;
|
|
161
|
+
}, TRuntimeContext>;
|
|
162
|
+
}, Setup<{
|
|
163
|
+
hoc: import("@modern-js/plugin").Pipeline<{
|
|
164
|
+
App: React.ComponentType<any>;
|
|
165
|
+
}, React.ComponentType<any>>;
|
|
166
|
+
provide: import("@modern-js/plugin").Pipeline<{
|
|
167
|
+
element: JSX.Element;
|
|
168
|
+
readonly props: AppProps;
|
|
169
|
+
readonly context: RuntimeContext;
|
|
170
|
+
}, JSX.Element>;
|
|
171
|
+
client: import("@modern-js/plugin").AsyncPipeline<{
|
|
172
|
+
App: React.ComponentType<any>;
|
|
173
|
+
readonly context?: RuntimeContext | undefined;
|
|
174
|
+
ModernRender: (App: React.ReactNode) => void;
|
|
175
|
+
ModernHydrate: (App: React.ReactNode, callback?: () => void) => void;
|
|
176
|
+
}, void>;
|
|
177
|
+
server: import("@modern-js/plugin").AsyncPipeline<{
|
|
178
|
+
App: React.ComponentType<any>;
|
|
179
|
+
readonly context?: RuntimeContext | undefined;
|
|
180
|
+
}, string>;
|
|
181
|
+
init: import("@modern-js/plugin").AsyncPipeline<{
|
|
182
|
+
context: RuntimeContext;
|
|
183
|
+
}, unknown>;
|
|
184
|
+
pickContext: import("@modern-js/plugin").Pipeline<{
|
|
185
|
+
context: RuntimeContext;
|
|
186
|
+
pickedContext: TRuntimeContext;
|
|
187
|
+
}, TRuntimeContext>;
|
|
188
|
+
}, Record<string, never>>> | undefined) => import("@modern-js/plugin").Plugin<{
|
|
189
|
+
hoc: import("@modern-js/plugin").Pipeline<{
|
|
190
|
+
App: React.ComponentType<any>;
|
|
191
|
+
}, React.ComponentType<any>>;
|
|
192
|
+
provide: import("@modern-js/plugin").Pipeline<{
|
|
193
|
+
element: JSX.Element;
|
|
194
|
+
readonly props: AppProps;
|
|
195
|
+
readonly context: RuntimeContext;
|
|
196
|
+
}, JSX.Element>;
|
|
197
|
+
client: import("@modern-js/plugin").AsyncPipeline<{
|
|
198
|
+
App: React.ComponentType<any>;
|
|
199
|
+
readonly context?: RuntimeContext | undefined;
|
|
200
|
+
ModernRender: (App: React.ReactNode) => void;
|
|
201
|
+
ModernHydrate: (App: React.ReactNode, callback?: () => void) => void;
|
|
202
|
+
}, void>;
|
|
203
|
+
server: import("@modern-js/plugin").AsyncPipeline<{
|
|
204
|
+
App: React.ComponentType<any>;
|
|
205
|
+
readonly context?: RuntimeContext | undefined;
|
|
206
|
+
}, string>;
|
|
207
|
+
init: import("@modern-js/plugin").AsyncPipeline<{
|
|
208
|
+
context: RuntimeContext;
|
|
209
|
+
}, unknown>;
|
|
210
|
+
pickContext: import("@modern-js/plugin").Pipeline<{
|
|
211
|
+
context: RuntimeContext;
|
|
212
|
+
pickedContext: TRuntimeContext;
|
|
213
|
+
}, TRuntimeContext>;
|
|
214
|
+
}, Record<string, never>>;
|
|
215
|
+
export { registerInit, registerPrefetch };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { createLoaderManager } from './loader/loaderManager';
|
|
3
|
+
import { runtime } from './plugin';
|
|
4
|
+
export interface RuntimeContext {
|
|
5
|
+
loaderManager: ReturnType<typeof createLoaderManager>;
|
|
6
|
+
runner: ReturnType<typeof runtime.init>;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}
|
|
9
|
+
export declare const RuntimeReactContext: import("react").Context<RuntimeContext>;
|
|
10
|
+
export interface TRuntimeContext {
|
|
11
|
+
initialData?: Record<string, unknown>;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import styled from '
|
|
1
|
+
import styled from 'styled-components';
|
|
2
2
|
export default styled;
|
|
3
|
-
export * from '
|
|
3
|
+
export * from 'styled-components';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import type { StateConfig } from './state';
|
|
2
2
|
import type { RouterConfig } from './router';
|
|
3
|
-
export type { RuntimeContext, TRuntimeContext } from '
|
|
4
|
-
export { createApp, createPlugin, useLoader, bootstrap, RuntimeReactContext, registerPrefetch, defineConfig, registerInit, useRuntimeContext } from '
|
|
5
|
-
|
|
3
|
+
export type { Plugin, RuntimeContext, TRuntimeContext, AppConfig } from './core';
|
|
4
|
+
export { createApp, createPlugin, useLoader, bootstrap, RuntimeReactContext, registerPrefetch, defineConfig, registerInit, useRuntimeContext } from './core';
|
|
5
|
+
export { StateConfig, RouterConfig };
|
|
6
|
+
declare module './core' {
|
|
6
7
|
interface AppConfig {
|
|
7
8
|
router?: RouterConfig | boolean;
|
|
8
9
|
state?: StateConfig | boolean;
|
|
9
10
|
}
|
|
10
|
-
}
|
|
11
|
-
declare module '@modern-js/core' {
|
|
12
|
-
interface RuntimeConfig {
|
|
13
|
-
router?: RouterConfig | boolean;
|
|
14
|
-
state?: StateConfig | boolean;
|
|
15
|
-
}
|
|
16
11
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { History, BrowserHistoryBuildOptions, HashHistoryBuildOptions } from 'history';
|
|
3
3
|
import { RouteProps } from 'react-router-dom';
|
|
4
|
-
import type { Plugin } from '
|
|
4
|
+
import type { Plugin } from '../../core';
|
|
5
5
|
declare global {
|
|
6
6
|
interface Window {
|
|
7
7
|
_SERVER_DATA?: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Plugin } from '
|
|
1
|
+
import type { Plugin } from '../core';
|
|
2
2
|
import { RenderLevel, SSRServerContext } from './serverRender/type';
|
|
3
|
-
declare module '
|
|
3
|
+
declare module '../core' {
|
|
4
4
|
interface RuntimeContext {
|
|
5
5
|
ssrContext: SSRServerContext;
|
|
6
6
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { RuntimeContext } from '
|
|
1
|
+
import { RuntimeContext } from '../core';
|
|
2
2
|
declare const prefetch: (App: React.ComponentType<any>, context: RuntimeContext) => Promise<{
|
|
3
3
|
initialData: any;
|
|
4
4
|
i18nData: any;
|
|
5
5
|
loadersData?: undefined;
|
|
6
6
|
storeState?: undefined;
|
|
7
7
|
} | {
|
|
8
|
-
loadersData: Record<string, import("
|
|
8
|
+
loadersData: Record<string, import("../core/loader/loaderManager").LoaderResult>;
|
|
9
9
|
initialData: any;
|
|
10
10
|
i18nData: any;
|
|
11
11
|
storeState: any;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export declare const NoSSR: (props: React.PropsWithChildren<
|
|
2
|
+
export declare const NoSSR: (props: React.PropsWithChildren<unknown>) => React.FunctionComponentElement<{}>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { RuntimeContext } from '@modern-js/runtime-core';
|
|
3
2
|
import type { BaseSSRServerContext } from '@modern-js/types';
|
|
3
|
+
import type { RuntimeContext } from '../../core';
|
|
4
4
|
export declare enum RenderLevel {
|
|
5
5
|
CLIENT_RENDER = 0,
|
|
6
6
|
SERVER_PREFETCH = 1,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createStore, Store } from '@modern-js-reduck/store';
|
|
2
|
-
import type { Plugin } from '
|
|
3
|
-
declare module '
|
|
2
|
+
import type { Plugin } from '../../core';
|
|
3
|
+
declare module '../../core' {
|
|
4
4
|
interface RuntimeContext {
|
|
5
5
|
store: Store;
|
|
6
6
|
}
|
package/lib/types.d.ts
ADDED