@umijs/renderer-react 4.2.6-alpha.6 → 4.2.6
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/appContext.d.ts +0 -1
- package/dist/appContext.js +1 -11
- package/dist/browser.d.ts +1 -16
- package/dist/browser.js +8 -41
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -1
- package/dist/server.d.ts +15 -3
- package/dist/server.js +45 -10
- package/dist/types.d.ts +1 -50
- package/package.json +1 -1
- package/dist/html.d.ts +0 -3
- package/dist/html.js +0 -170
package/dist/appContext.d.ts
CHANGED
|
@@ -23,5 +23,4 @@ export declare function useServerLoaderData<T extends ServerLoaderFunc = any>():
|
|
|
23
23
|
export declare function useClientLoaderData(): {
|
|
24
24
|
data: any;
|
|
25
25
|
};
|
|
26
|
-
export declare function useLoaderData<T extends ServerLoaderFunc = any>(): Awaited<ReturnType<T>>;
|
|
27
26
|
export {};
|
package/dist/appContext.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
3
|
var _excluded = ["element"];
|
|
@@ -26,7 +25,6 @@ export function useRouteProps() {
|
|
|
26
25
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
27
26
|
return props;
|
|
28
27
|
}
|
|
29
|
-
// @deprecated Please use `useLoaderData` instead.
|
|
30
28
|
export function useServerLoaderData() {
|
|
31
29
|
var routes = useSelectedRoutes();
|
|
32
30
|
var _useAppData2 = useAppData(),
|
|
@@ -49,6 +47,7 @@ export function useServerLoaderData() {
|
|
|
49
47
|
data = _React$useState2[0],
|
|
50
48
|
setData = _React$useState2[1];
|
|
51
49
|
React.useEffect(function () {
|
|
50
|
+
// @ts-ignore
|
|
52
51
|
if (!window.__UMI_LOADER_DATA__) {
|
|
53
52
|
// 支持 ssr 降级,客户端兜底加载 serverLoader 数据
|
|
54
53
|
Promise.all(routes.filter(function (route) {
|
|
@@ -76,19 +75,10 @@ export function useServerLoaderData() {
|
|
|
76
75
|
data: data
|
|
77
76
|
};
|
|
78
77
|
}
|
|
79
|
-
|
|
80
|
-
// @deprecated Please use `useLoaderData` instead.
|
|
81
78
|
export function useClientLoaderData() {
|
|
82
79
|
var route = useRouteData();
|
|
83
80
|
var appData = useAppData();
|
|
84
81
|
return {
|
|
85
82
|
data: appData.clientLoaderData[route.route.id]
|
|
86
83
|
};
|
|
87
|
-
}
|
|
88
|
-
export function useLoaderData() {
|
|
89
|
-
var serverLoaderData = useServerLoaderData();
|
|
90
|
-
var clientLoaderData = useClientLoaderData();
|
|
91
|
-
return {
|
|
92
|
-
data: _objectSpread(_objectSpread({}, serverLoaderData.data), clientLoaderData.data)
|
|
93
|
-
};
|
|
94
84
|
}
|
package/dist/browser.d.ts
CHANGED
|
@@ -18,26 +18,11 @@ export declare type RenderClientOpts = {
|
|
|
18
18
|
* @doc https://umijs.org/docs/api/config#runtimepublicpath
|
|
19
19
|
*/
|
|
20
20
|
runtimePublicPath?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* react dom 渲染的的目标节点 id
|
|
23
|
-
* @doc 一般不需要改,微前端的时候会变化
|
|
24
|
-
*/
|
|
25
|
-
mountElementId?: string;
|
|
26
21
|
/**
|
|
27
22
|
* react dom 渲染的的目标 dom
|
|
28
23
|
* @doc 一般不需要改,微前端的时候会变化
|
|
29
24
|
*/
|
|
30
25
|
rootElement?: HTMLElement;
|
|
31
|
-
__INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
|
|
32
|
-
/**
|
|
33
|
-
* 内部流程, 渲染特殊 app 节点, 不要使用!!!
|
|
34
|
-
*/
|
|
35
|
-
pureApp?: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* 内部流程, 渲染特殊 html 节点, 不要使用!!!
|
|
38
|
-
*/
|
|
39
|
-
pureHtml?: boolean;
|
|
40
|
-
};
|
|
41
26
|
/**
|
|
42
27
|
* 当前的路由配置
|
|
43
28
|
*/
|
|
@@ -88,4 +73,4 @@ export declare type RenderClientOpts = {
|
|
|
88
73
|
* @param {RenderClientOpts} opts - 插件相关的配置
|
|
89
74
|
* @returns void
|
|
90
75
|
*/
|
|
91
|
-
export declare function renderClient(opts: RenderClientOpts): (() =>
|
|
76
|
+
export declare function renderClient(opts: RenderClientOpts): (() => JSX.Element) | undefined;
|
package/dist/browser.js
CHANGED
|
@@ -7,7 +7,6 @@ import ReactDOM from 'react-dom/client';
|
|
|
7
7
|
import { matchRoutes, Router, useRoutes } from 'react-router-dom';
|
|
8
8
|
import { AppContext, useAppData } from "./appContext";
|
|
9
9
|
import { fetchServerLoader } from "./dataFetcher";
|
|
10
|
-
import { Html } from "./html";
|
|
11
10
|
import { createClientRoutes } from "./routes";
|
|
12
11
|
var root = null;
|
|
13
12
|
|
|
@@ -131,7 +130,9 @@ var getBrowser = function getBrowser(opts, routesElement) {
|
|
|
131
130
|
_useState2 = _slicedToArray(_useState, 2),
|
|
132
131
|
clientLoaderData = _useState2[0],
|
|
133
132
|
setClientLoaderData = _useState2[1];
|
|
134
|
-
var _useState3 = useState(
|
|
133
|
+
var _useState3 = useState(
|
|
134
|
+
// @ts-ignore
|
|
135
|
+
window.__UMI_LOADER_DATA__ || {}),
|
|
135
136
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
136
137
|
serverLoaderData = _useState4[0],
|
|
137
138
|
setServerLoaderData = _useState4[1];
|
|
@@ -179,13 +180,9 @@ var getBrowser = function getBrowser(opts, routesElement) {
|
|
|
179
180
|
});
|
|
180
181
|
}
|
|
181
182
|
}
|
|
182
|
-
var clientLoader = (_opts$routes$id = opts.routes[id]) === null || _opts$routes$id === void 0 ? void 0 : _opts$routes$id.clientLoader;
|
|
183
|
-
var hasClientLoader = !!clientLoader;
|
|
184
|
-
var hasServerLoader = (_opts$routes$id2 = opts.routes[id]) === null || _opts$routes$id2 === void 0 ? void 0 : _opts$routes$id2.hasServerLoader;
|
|
185
183
|
// server loader
|
|
186
184
|
// use ?. since routes patched with patchClientRoutes is not exists in opts.routes
|
|
187
|
-
|
|
188
|
-
if (!isFirst && hasServerLoader && !hasClientLoader && !window.__UMI_LOADER_DATA__) {
|
|
185
|
+
if (!isFirst && (_opts$routes$id = opts.routes[id]) !== null && _opts$routes$id !== void 0 && _opts$routes$id.hasServerLoader) {
|
|
189
186
|
fetchServerLoader({
|
|
190
187
|
id: id,
|
|
191
188
|
basename: basename,
|
|
@@ -202,32 +199,9 @@ var getBrowser = function getBrowser(opts, routesElement) {
|
|
|
202
199
|
}
|
|
203
200
|
// client loader
|
|
204
201
|
// onPatchClientRoutes 添加的 route 在 opts.routes 里是不存在的
|
|
205
|
-
var
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
var shouldHydrateOrNoServerLoader = hasClientLoader && clientLoader.hydrate || !hasServerLoader;
|
|
209
|
-
|
|
210
|
-
// Check if server loader data is missing in the global window object
|
|
211
|
-
var isServerLoaderDataMissing = hasServerLoader && !window.__UMI_LOADER_DATA__;
|
|
212
|
-
if (hasClientLoader && !hasClientLoaderDataInRoute && (shouldHydrateOrNoServerLoader || isServerLoaderDataMissing)) {
|
|
213
|
-
// ...
|
|
214
|
-
clientLoader({
|
|
215
|
-
serverLoader: function serverLoader() {
|
|
216
|
-
return fetchServerLoader({
|
|
217
|
-
id: id,
|
|
218
|
-
basename: basename,
|
|
219
|
-
cb: function cb(data) {
|
|
220
|
-
// setServerLoaderData when startTransition because if ssr is enabled,
|
|
221
|
-
// the component may being hydrated and setLoaderData will break the hydration
|
|
222
|
-
React.startTransition(function () {
|
|
223
|
-
setServerLoaderData(function (d) {
|
|
224
|
-
return _objectSpread(_objectSpread({}, d), {}, _defineProperty({}, id, data));
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
}).then(function (data) {
|
|
202
|
+
var clientLoader = (_opts$routes$id2 = opts.routes[id]) === null || _opts$routes$id2 === void 0 ? void 0 : _opts$routes$id2.clientLoader;
|
|
203
|
+
if (clientLoader && !clientLoaderData[id]) {
|
|
204
|
+
clientLoader().then(function (data) {
|
|
231
205
|
setClientLoaderData(function (d) {
|
|
232
206
|
return _objectSpread(_objectSpread({}, d), {}, _defineProperty({}, id, data));
|
|
233
207
|
});
|
|
@@ -273,14 +247,7 @@ export function renderClient(opts) {
|
|
|
273
247
|
// 为了测试,直接返回组件
|
|
274
248
|
if (opts.components) return Browser;
|
|
275
249
|
if (opts.hydrate) {
|
|
276
|
-
|
|
277
|
-
var metadata = window.__UMI_METADATA_LOADER_DATA__ || {};
|
|
278
|
-
var hydtateHtmloptions = {
|
|
279
|
-
metadata: metadata,
|
|
280
|
-
loaderData: loaderData,
|
|
281
|
-
mountElementId: opts.mountElementId
|
|
282
|
-
};
|
|
283
|
-
ReactDOM.hydrateRoot(opts.__INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.pureApp ? rootElement : document, /*#__PURE__*/React.createElement(Html, hydtateHtmloptions, /*#__PURE__*/React.createElement(Browser, null)));
|
|
250
|
+
ReactDOM.hydrateRoot(rootElement, /*#__PURE__*/React.createElement(Browser, null));
|
|
284
251
|
return;
|
|
285
252
|
}
|
|
286
253
|
if (ReactDOM.createRoot) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
export { createBrowserHistory, createHashHistory, createMemoryHistory, type History, } from 'history';
|
|
2
2
|
export { Helmet, HelmetProvider } from 'react-helmet-async';
|
|
3
3
|
export { createSearchParams, generatePath, matchPath, matchRoutes, Navigate, NavLink, Outlet, resolvePath, useLocation, useMatch, useNavigate, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useSearchParams, } from 'react-router-dom';
|
|
4
|
-
export { useAppData, useClientLoaderData,
|
|
4
|
+
export { useAppData, useClientLoaderData, useRouteProps, useSelectedRoutes, useServerLoaderData, } from './appContext';
|
|
5
5
|
export { renderClient, __getRoot } from './browser';
|
|
6
6
|
export { LinkWithPrefetch as Link } from './link';
|
|
7
7
|
export { useRouteData } from './routeContext';
|
|
8
|
-
export type { ClientLoader } from './types';
|
|
9
8
|
export { __useFetcher } from './useFetcher';
|
|
10
9
|
export { withRouter, type RouteComponentProps } from './withRouter';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { createBrowserHistory, createHashHistory, createMemoryHistory } from 'history';
|
|
2
2
|
export { Helmet, HelmetProvider } from 'react-helmet-async';
|
|
3
3
|
export { createSearchParams, generatePath, matchPath, matchRoutes, Navigate, NavLink, Outlet, resolvePath, useLocation, useMatch, useNavigate, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useSearchParams } from 'react-router-dom';
|
|
4
|
-
export { useAppData, useClientLoaderData,
|
|
4
|
+
export { useAppData, useClientLoaderData, useRouteProps, useSelectedRoutes, useServerLoaderData } from "./appContext";
|
|
5
5
|
export { renderClient, __getRoot } from "./browser";
|
|
6
6
|
export { LinkWithPrefetch as Link } from "./link";
|
|
7
7
|
export { useRouteData } from "./routeContext";
|
package/dist/server.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import type { IMetadata } from '@umijs/server/dist/types';
|
|
2
|
+
import { IRouteComponents, IRoutesById } from './types';
|
|
3
|
+
interface IHtmlProps {
|
|
4
|
+
routes: IRoutesById;
|
|
5
|
+
routeComponents: IRouteComponents;
|
|
6
|
+
pluginManager: any;
|
|
7
|
+
location: string;
|
|
8
|
+
loaderData: {
|
|
9
|
+
[routeKey: string]: any;
|
|
10
|
+
};
|
|
11
|
+
manifest: any;
|
|
12
|
+
metadata?: IMetadata;
|
|
13
|
+
}
|
|
14
|
+
export declare function getClientRootComponent(opts: IHtmlProps): Promise<JSX.Element>;
|
|
15
|
+
export {};
|
package/dist/server.js
CHANGED
|
@@ -5,7 +5,6 @@ import React from 'react';
|
|
|
5
5
|
import { StaticRouter } from 'react-router-dom/server';
|
|
6
6
|
import { AppContext } from "./appContext";
|
|
7
7
|
import { Routes } from "./browser";
|
|
8
|
-
import { Html } from "./html";
|
|
9
8
|
import { createClientRoutes } from "./routes";
|
|
10
9
|
// Get the root React component for ReactDOMServer.renderToString
|
|
11
10
|
export function getClientRootComponent(_x) {
|
|
@@ -18,18 +17,11 @@ function _getClientRootComponent() {
|
|
|
18
17
|
while (1) switch (_context.prev = _context.next) {
|
|
19
18
|
case 0:
|
|
20
19
|
basename = '/';
|
|
21
|
-
components = _objectSpread({}, opts.routeComponents);
|
|
20
|
+
components = _objectSpread({}, opts.routeComponents);
|
|
22
21
|
clientRoutes = createClientRoutes({
|
|
23
22
|
routesById: opts.routes,
|
|
24
23
|
routeComponents: components
|
|
25
24
|
});
|
|
26
|
-
opts.pluginManager.applyPlugins({
|
|
27
|
-
key: 'patchClientRoutes',
|
|
28
|
-
type: 'event',
|
|
29
|
-
args: {
|
|
30
|
-
routes: clientRoutes
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
25
|
rootContainer = /*#__PURE__*/React.createElement(StaticRouter, {
|
|
34
26
|
basename: basename,
|
|
35
27
|
location: opts.location
|
|
@@ -57,11 +49,54 @@ function _getClientRootComponent() {
|
|
|
57
49
|
}
|
|
58
50
|
}, rootContainer);
|
|
59
51
|
return _context.abrupt("return", /*#__PURE__*/React.createElement(Html, opts, app));
|
|
60
|
-
case
|
|
52
|
+
case 7:
|
|
61
53
|
case "end":
|
|
62
54
|
return _context.stop();
|
|
63
55
|
}
|
|
64
56
|
}, _callee);
|
|
65
57
|
}));
|
|
66
58
|
return _getClientRootComponent.apply(this, arguments);
|
|
59
|
+
}
|
|
60
|
+
function Html(_ref) {
|
|
61
|
+
var _metadata$keywords, _metadata$metas;
|
|
62
|
+
var children = _ref.children,
|
|
63
|
+
loaderData = _ref.loaderData,
|
|
64
|
+
manifest = _ref.manifest,
|
|
65
|
+
metadata = _ref.metadata;
|
|
66
|
+
// TODO: 处理 head 标签,比如 favicon.ico 的一致性
|
|
67
|
+
// TODO: root 支持配置
|
|
68
|
+
|
|
69
|
+
return /*#__PURE__*/React.createElement("html", {
|
|
70
|
+
lang: (metadata === null || metadata === void 0 ? void 0 : metadata.lang) || 'en'
|
|
71
|
+
}, /*#__PURE__*/React.createElement("head", null, /*#__PURE__*/React.createElement("meta", {
|
|
72
|
+
charSet: "utf-8"
|
|
73
|
+
}), /*#__PURE__*/React.createElement("meta", {
|
|
74
|
+
name: "viewport",
|
|
75
|
+
content: "width=device-width, initial-scale=1"
|
|
76
|
+
}), (metadata === null || metadata === void 0 ? void 0 : metadata.title) && /*#__PURE__*/React.createElement("title", null, metadata.title), (metadata === null || metadata === void 0 ? void 0 : metadata.description) && /*#__PURE__*/React.createElement("meta", {
|
|
77
|
+
name: "description",
|
|
78
|
+
content: metadata.description
|
|
79
|
+
}), (metadata === null || metadata === void 0 || (_metadata$keywords = metadata.keywords) === null || _metadata$keywords === void 0 ? void 0 : _metadata$keywords.length) && /*#__PURE__*/React.createElement("meta", {
|
|
80
|
+
name: "keywords",
|
|
81
|
+
content: metadata.keywords.join(',')
|
|
82
|
+
}), metadata === null || metadata === void 0 || (_metadata$metas = metadata.metas) === null || _metadata$metas === void 0 ? void 0 : _metadata$metas.map(function (em) {
|
|
83
|
+
return /*#__PURE__*/React.createElement("meta", {
|
|
84
|
+
key: em.name,
|
|
85
|
+
name: em.name,
|
|
86
|
+
content: em.content
|
|
87
|
+
});
|
|
88
|
+
}), manifest.assets['umi.css'] && /*#__PURE__*/React.createElement("link", {
|
|
89
|
+
rel: "stylesheet",
|
|
90
|
+
href: manifest.assets['umi.css']
|
|
91
|
+
})), /*#__PURE__*/React.createElement("body", null, /*#__PURE__*/React.createElement("noscript", {
|
|
92
|
+
dangerouslySetInnerHTML: {
|
|
93
|
+
__html: "<b>Enable JavaScript to run this app.</b>"
|
|
94
|
+
}
|
|
95
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
96
|
+
id: "root"
|
|
97
|
+
}, children), /*#__PURE__*/React.createElement("script", {
|
|
98
|
+
dangerouslySetInnerHTML: {
|
|
99
|
+
__html: "window.__UMI_LOADER_DATA__ = ".concat(JSON.stringify(loaderData))
|
|
100
|
+
}
|
|
101
|
+
})));
|
|
67
102
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { IhtmlPageOpts, ServerLoader } from '@umijs/server/dist/types';
|
|
3
2
|
import type { RouteMatch, RouteObject } from 'react-router-dom';
|
|
4
|
-
declare global {
|
|
5
|
-
interface Window {
|
|
6
|
-
__UMI_LOADER_DATA__: any;
|
|
7
|
-
__UMI_METADATA_LOADER_DATA__: any;
|
|
8
|
-
__UMI_BUILD_MANIFEST_DATA__: any;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
declare type ClientLoaderFunctionArgs = {
|
|
12
|
-
serverLoader: ServerLoader;
|
|
13
|
-
};
|
|
14
|
-
export declare type ClientLoader = ((args: ClientLoaderFunctionArgs) => Promise<any>) & {
|
|
15
|
-
hydrate?: boolean;
|
|
16
|
-
};
|
|
17
3
|
export interface IRouteSSRProps {
|
|
18
|
-
clientLoader?:
|
|
4
|
+
clientLoader?: () => Promise<any>;
|
|
19
5
|
hasServerLoader?: boolean;
|
|
20
6
|
}
|
|
21
7
|
export interface IRouteConventionExportProps {
|
|
@@ -47,38 +33,3 @@ export interface IRouteComponents {
|
|
|
47
33
|
export interface ILoaderData {
|
|
48
34
|
[routeKey: string]: any;
|
|
49
35
|
}
|
|
50
|
-
interface IHtmlHydrateOptions {
|
|
51
|
-
htmlPageOpts?: IhtmlPageOpts;
|
|
52
|
-
__INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?: {
|
|
53
|
-
pureApp: boolean;
|
|
54
|
-
pureHtml: boolean;
|
|
55
|
-
};
|
|
56
|
-
mountElementId?: string;
|
|
57
|
-
}
|
|
58
|
-
export interface IRootComponentOptions extends IHtmlHydrateOptions {
|
|
59
|
-
routes: IRoutesById;
|
|
60
|
-
routeComponents: IRouteComponents;
|
|
61
|
-
pluginManager: any;
|
|
62
|
-
location: string;
|
|
63
|
-
loaderData: {
|
|
64
|
-
[routeKey: string]: any;
|
|
65
|
-
};
|
|
66
|
-
manifest: any;
|
|
67
|
-
}
|
|
68
|
-
export interface IHtmlProps extends IHtmlHydrateOptions {
|
|
69
|
-
children?: React.ReactNode;
|
|
70
|
-
loaderData?: {
|
|
71
|
-
[routeKey: string]: any;
|
|
72
|
-
};
|
|
73
|
-
manifest?: any;
|
|
74
|
-
}
|
|
75
|
-
export declare type IScript = Partial<{
|
|
76
|
-
async: boolean;
|
|
77
|
-
charset: string;
|
|
78
|
-
content: string;
|
|
79
|
-
crossOrigin: string | null;
|
|
80
|
-
defer: boolean;
|
|
81
|
-
src: string;
|
|
82
|
-
type: string;
|
|
83
|
-
}> | string;
|
|
84
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/renderer-react",
|
|
3
|
-
"version": "4.2.6
|
|
3
|
+
"version": "4.2.6",
|
|
4
4
|
"description": "@umijs/renderer-react",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/renderer-react#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
package/dist/html.d.ts
DELETED
package/dist/html.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
4
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
5
|
-
var _excluded = ["content"],
|
|
6
|
-
_excluded2 = ["content"];
|
|
7
|
-
import React from 'react';
|
|
8
|
-
var RE_URL = /^(http:|https:)?\/\//;
|
|
9
|
-
function isUrl(str) {
|
|
10
|
-
return RE_URL.test(str) || str.startsWith('/') && !str.startsWith('/*') || str.startsWith('./') || str.startsWith('../');
|
|
11
|
-
}
|
|
12
|
-
var EnableJsScript = function EnableJsScript() {
|
|
13
|
-
return /*#__PURE__*/React.createElement("noscript", {
|
|
14
|
-
dangerouslySetInnerHTML: {
|
|
15
|
-
__html: "<b>Enable JavaScript to run this app.</b>"
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
var GlobalDataScript = function GlobalDataScript(props) {
|
|
20
|
-
var loaderData = props.loaderData,
|
|
21
|
-
htmlPageOpts = props.htmlPageOpts,
|
|
22
|
-
manifest = props.manifest;
|
|
23
|
-
return /*#__PURE__*/React.createElement("script", {
|
|
24
|
-
suppressHydrationWarning: true,
|
|
25
|
-
dangerouslySetInnerHTML: {
|
|
26
|
-
__html: "window.__UMI_LOADER_DATA__ = ".concat(JSON.stringify(loaderData || {}), "; window.__UMI_METADATA_LOADER_DATA__ = ").concat(JSON.stringify(htmlPageOpts || {}), "; window.__UMI_BUILD_MANIFEST_DATA__ = ").concat(JSON.stringify(manifest) || {})
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
function normalizeScripts(script) {
|
|
31
|
-
var extraProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
32
|
-
if (typeof script === 'string') {
|
|
33
|
-
return isUrl(script) ? _objectSpread({
|
|
34
|
-
src: script
|
|
35
|
-
}, extraProps) : {
|
|
36
|
-
content: script
|
|
37
|
-
};
|
|
38
|
-
} else if (_typeof(script) === 'object') {
|
|
39
|
-
return _objectSpread(_objectSpread({}, script), extraProps);
|
|
40
|
-
} else {
|
|
41
|
-
throw new Error("Invalid script type: ".concat(_typeof(script)));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function generatorStyle(style) {
|
|
45
|
-
return isUrl(style) ? {
|
|
46
|
-
type: 'link',
|
|
47
|
-
href: style
|
|
48
|
-
} : {
|
|
49
|
-
type: 'style',
|
|
50
|
-
content: style
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
var HydrateMetadata = function HydrateMetadata(props) {
|
|
54
|
-
var _htmlPageOpts$favicon, _htmlPageOpts$keyword, _htmlPageOpts$metas, _htmlPageOpts$links, _htmlPageOpts$styles, _htmlPageOpts$headScr;
|
|
55
|
-
var htmlPageOpts = props.htmlPageOpts;
|
|
56
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, (htmlPageOpts === null || htmlPageOpts === void 0 ? void 0 : htmlPageOpts.title) && /*#__PURE__*/React.createElement("title", null, htmlPageOpts.title), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$favicon = htmlPageOpts.favicons) === null || _htmlPageOpts$favicon === void 0 ? void 0 : _htmlPageOpts$favicon.map(function (favicon, key) {
|
|
57
|
-
return /*#__PURE__*/React.createElement("link", {
|
|
58
|
-
key: key,
|
|
59
|
-
rel: "shortcut icon",
|
|
60
|
-
href: favicon
|
|
61
|
-
});
|
|
62
|
-
}), (htmlPageOpts === null || htmlPageOpts === void 0 ? void 0 : htmlPageOpts.description) && /*#__PURE__*/React.createElement("meta", {
|
|
63
|
-
name: "description",
|
|
64
|
-
content: htmlPageOpts.description
|
|
65
|
-
}), (htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$keyword = htmlPageOpts.keywords) === null || _htmlPageOpts$keyword === void 0 ? void 0 : _htmlPageOpts$keyword.length) && /*#__PURE__*/React.createElement("meta", {
|
|
66
|
-
name: "keywords",
|
|
67
|
-
content: htmlPageOpts.keywords.join(',')
|
|
68
|
-
}), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$metas = htmlPageOpts.metas) === null || _htmlPageOpts$metas === void 0 ? void 0 : _htmlPageOpts$metas.map(function (em) {
|
|
69
|
-
return /*#__PURE__*/React.createElement("meta", {
|
|
70
|
-
key: em.name,
|
|
71
|
-
name: em.name,
|
|
72
|
-
content: em.content
|
|
73
|
-
});
|
|
74
|
-
}), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$links = htmlPageOpts.links) === null || _htmlPageOpts$links === void 0 ? void 0 : _htmlPageOpts$links.map(function (link, key) {
|
|
75
|
-
return /*#__PURE__*/React.createElement("link", _extends({
|
|
76
|
-
key: key
|
|
77
|
-
}, link));
|
|
78
|
-
}), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$styles = htmlPageOpts.styles) === null || _htmlPageOpts$styles === void 0 ? void 0 : _htmlPageOpts$styles.map(function (style, key) {
|
|
79
|
-
var _generatorStyle = generatorStyle(style),
|
|
80
|
-
type = _generatorStyle.type,
|
|
81
|
-
href = _generatorStyle.href,
|
|
82
|
-
content = _generatorStyle.content;
|
|
83
|
-
if (type === 'link') {
|
|
84
|
-
return /*#__PURE__*/React.createElement("link", {
|
|
85
|
-
key: key,
|
|
86
|
-
rel: "stylesheet",
|
|
87
|
-
href: href
|
|
88
|
-
});
|
|
89
|
-
} else if (type === 'style') {
|
|
90
|
-
return /*#__PURE__*/React.createElement("style", {
|
|
91
|
-
key: key
|
|
92
|
-
}, content);
|
|
93
|
-
}
|
|
94
|
-
}), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$headScr = htmlPageOpts.headScripts) === null || _htmlPageOpts$headScr === void 0 ? void 0 : _htmlPageOpts$headScr.map(function (script, key) {
|
|
95
|
-
var _normalizeScripts = normalizeScripts(script),
|
|
96
|
-
content = _normalizeScripts.content,
|
|
97
|
-
rest = _objectWithoutProperties(_normalizeScripts, _excluded);
|
|
98
|
-
return /*#__PURE__*/React.createElement("script", _extends({
|
|
99
|
-
dangerouslySetInnerHTML: {
|
|
100
|
-
__html: content
|
|
101
|
-
},
|
|
102
|
-
key: key
|
|
103
|
-
}, rest));
|
|
104
|
-
}));
|
|
105
|
-
};
|
|
106
|
-
export function Html(_ref) {
|
|
107
|
-
var _htmlPageOpts$scripts;
|
|
108
|
-
var children = _ref.children,
|
|
109
|
-
loaderData = _ref.loaderData,
|
|
110
|
-
manifest = _ref.manifest,
|
|
111
|
-
htmlPageOpts = _ref.htmlPageOpts,
|
|
112
|
-
__INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = _ref.__INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
|
|
113
|
-
mountElementId = _ref.mountElementId;
|
|
114
|
-
// TODO: 处理 head 标签,比如 favicon.ico 的一致性
|
|
115
|
-
// TODO: root 支持配置
|
|
116
|
-
if (__INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED !== null && __INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED !== void 0 && __INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.pureHtml) {
|
|
117
|
-
return /*#__PURE__*/React.createElement("html", null, /*#__PURE__*/React.createElement("head", null), /*#__PURE__*/React.createElement("body", null, /*#__PURE__*/React.createElement(EnableJsScript, null), /*#__PURE__*/React.createElement("div", {
|
|
118
|
-
id: mountElementId
|
|
119
|
-
}, children), /*#__PURE__*/React.createElement(GlobalDataScript, {
|
|
120
|
-
manifest: manifest,
|
|
121
|
-
loaderData: loaderData,
|
|
122
|
-
htmlPageOpts: htmlPageOpts
|
|
123
|
-
})));
|
|
124
|
-
}
|
|
125
|
-
if (__INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED !== null && __INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED !== void 0 && __INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.pureApp) {
|
|
126
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EnableJsScript, null), /*#__PURE__*/React.createElement("div", {
|
|
127
|
-
id: mountElementId
|
|
128
|
-
}, children), /*#__PURE__*/React.createElement(GlobalDataScript, {
|
|
129
|
-
manifest: manifest,
|
|
130
|
-
loaderData: loaderData,
|
|
131
|
-
htmlPageOpts: htmlPageOpts
|
|
132
|
-
}));
|
|
133
|
-
}
|
|
134
|
-
var serverBuildManifest = typeof window === 'undefined' ? manifest : window.__UMI_BUILD_MANIFEST_DATA__;
|
|
135
|
-
return (
|
|
136
|
-
/*#__PURE__*/
|
|
137
|
-
// FIXME: Resolve the hydrate warning for suppressHydrationWarning(3)
|
|
138
|
-
React.createElement("html", {
|
|
139
|
-
suppressHydrationWarning: true,
|
|
140
|
-
lang: (htmlPageOpts === null || htmlPageOpts === void 0 ? void 0 : htmlPageOpts.lang) || 'en'
|
|
141
|
-
}, /*#__PURE__*/React.createElement("head", null, /*#__PURE__*/React.createElement("meta", {
|
|
142
|
-
charSet: "utf-8"
|
|
143
|
-
}), /*#__PURE__*/React.createElement("meta", {
|
|
144
|
-
name: "viewport",
|
|
145
|
-
content: "width=device-width, initial-scale=1"
|
|
146
|
-
}), (serverBuildManifest === null || serverBuildManifest === void 0 ? void 0 : serverBuildManifest.assets['umi.css']) && /*#__PURE__*/React.createElement("link", {
|
|
147
|
-
suppressHydrationWarning: true,
|
|
148
|
-
rel: "stylesheet",
|
|
149
|
-
href: manifest === null || manifest === void 0 ? void 0 : manifest.assets['umi.css']
|
|
150
|
-
}), /*#__PURE__*/React.createElement(HydrateMetadata, {
|
|
151
|
-
htmlPageOpts: htmlPageOpts
|
|
152
|
-
})), /*#__PURE__*/React.createElement("body", null, /*#__PURE__*/React.createElement(EnableJsScript, null), /*#__PURE__*/React.createElement("div", {
|
|
153
|
-
id: mountElementId
|
|
154
|
-
}, children), /*#__PURE__*/React.createElement(GlobalDataScript, {
|
|
155
|
-
manifest: manifest,
|
|
156
|
-
loaderData: loaderData,
|
|
157
|
-
htmlPageOpts: htmlPageOpts
|
|
158
|
-
}), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$scripts = htmlPageOpts.scripts) === null || _htmlPageOpts$scripts === void 0 ? void 0 : _htmlPageOpts$scripts.map(function (script, key) {
|
|
159
|
-
var _normalizeScripts2 = normalizeScripts(script),
|
|
160
|
-
content = _normalizeScripts2.content,
|
|
161
|
-
rest = _objectWithoutProperties(_normalizeScripts2, _excluded2);
|
|
162
|
-
return /*#__PURE__*/React.createElement("script", _extends({
|
|
163
|
-
dangerouslySetInnerHTML: {
|
|
164
|
-
__html: content
|
|
165
|
-
},
|
|
166
|
-
key: key
|
|
167
|
-
}, rest));
|
|
168
|
-
})))
|
|
169
|
-
);
|
|
170
|
-
}
|