@modern-js/runtime 2.49.2 → 2.49.3-alpha.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/dist/cjs/router/runtime/plugin.js +2 -2
- package/dist/cjs/router/runtime/plugin.node.js +2 -2
- package/dist/cjs/ssr/serverRender/renderToStream/bulidTemplate.before.js +7 -15
- package/dist/esm/router/runtime/plugin.js +2 -2
- package/dist/esm/router/runtime/plugin.node.js +2 -2
- package/dist/esm/ssr/serverRender/renderToStream/bulidTemplate.before.js +115 -132
- package/dist/esm-node/router/runtime/plugin.js +2 -2
- package/dist/esm-node/router/runtime/plugin.node.js +2 -2
- package/dist/esm-node/ssr/serverRender/renderToStream/bulidTemplate.before.js +8 -16
- package/dist/js/modern/cli/index.js +72 -0
- package/dist/js/modern/common.js +4 -0
- package/dist/js/modern/config.js +0 -0
- package/dist/js/modern/core/app-config.js +10 -0
- package/dist/js/modern/core/compatible.js +285 -0
- package/dist/js/modern/core/index.js +16 -0
- package/dist/js/modern/core/loader/index.js +4 -0
- package/dist/js/modern/core/loader/loaderManager.js +165 -0
- package/dist/js/modern/core/loader/useLoader.js +114 -0
- package/dist/js/modern/core/plugin.js +58 -0
- package/dist/js/modern/document/Body.js +23 -0
- package/dist/js/modern/document/DocumentContext.js +9 -0
- package/dist/js/modern/document/DocumentStructrueContext.js +11 -0
- package/dist/js/modern/document/Head.js +27 -0
- package/dist/js/modern/document/Html.js +78 -0
- package/dist/js/modern/document/Links.js +10 -0
- package/dist/js/modern/document/Root.js +33 -0
- package/dist/js/modern/document/Script.js +20 -0
- package/dist/js/modern/document/Scripts.js +10 -0
- package/dist/js/modern/document/cli/index.js +228 -0
- package/dist/js/modern/document/constants.js +49 -0
- package/dist/js/modern/document/index.js +10 -0
- package/dist/js/modern/exports/head.js +6 -0
- package/dist/js/modern/exports/loadable.js +6 -0
- package/dist/js/modern/exports/server.js +4 -0
- package/dist/js/modern/exports/styled.js +6 -0
- package/dist/js/modern/index.js +22 -0
- package/dist/js/modern/router/cli/index.js +120 -0
- package/dist/js/modern/router/index.js +7 -0
- package/dist/js/modern/router/runtime/DefaultNotFound.js +14 -0
- package/dist/js/modern/router/runtime/index.js +9 -0
- package/dist/js/modern/router/runtime/plugin.js +104 -0
- package/dist/js/modern/router/runtime/plugin.node.js +149 -0
- package/dist/js/modern/router/runtime/server.js +1 -0
- package/dist/js/modern/router/runtime/types.js +0 -0
- package/dist/js/modern/router/runtime/utils.js +196 -0
- package/dist/js/modern/router/runtime/withRouter.js +36 -0
- package/dist/js/modern/runtime-context.js +7 -0
- package/dist/js/modern/ssr/cli/babel-plugin-ssr-loader-id.js +130 -0
- package/dist/js/modern/ssr/cli/index.js +172 -0
- package/dist/js/modern/ssr/index.js +159 -0
- package/dist/js/modern/ssr/index.node.js +79 -0
- package/dist/js/modern/ssr/prefetch.js +69 -0
- package/dist/js/modern/ssr/react/index.js +6 -0
- package/dist/js/modern/ssr/react/nossr/index.js +14 -0
- package/dist/js/modern/ssr/react/prerender/index.js +108 -0
- package/dist/js/modern/ssr/react/prerender/type.js +0 -0
- package/dist/js/modern/ssr/react/prerender/util.js +96 -0
- package/dist/js/modern/ssr/react/withCallback/index.js +15 -0
- package/dist/js/modern/ssr/serverRender/helmet.js +44 -0
- package/dist/js/modern/ssr/serverRender/index.js +35 -0
- package/dist/js/modern/ssr/serverRender/renderToStream/buildTemplate.after.js +36 -0
- package/dist/js/modern/ssr/serverRender/renderToStream/buildTemplate.share.js +11 -0
- package/dist/js/modern/ssr/serverRender/renderToStream/bulidTemplate.before.js +61 -0
- package/dist/js/modern/ssr/serverRender/renderToStream/index.js +58 -0
- package/dist/js/modern/ssr/serverRender/renderToStream/loadable.js +24 -0
- package/dist/js/modern/ssr/serverRender/renderToStream/renderToPipe.js +94 -0
- package/dist/js/modern/ssr/serverRender/renderToStream/styledComponent.js +12 -0
- package/dist/js/modern/ssr/serverRender/renderToStream/template.js +22 -0
- package/dist/js/modern/ssr/serverRender/renderToStream/type.js +0 -0
- package/dist/js/modern/ssr/serverRender/renderToString/entry.js +171 -0
- package/dist/js/modern/ssr/serverRender/renderToString/index.js +52 -0
- package/dist/js/modern/ssr/serverRender/renderToString/loadable.js +48 -0
- package/dist/js/modern/ssr/serverRender/renderToString/reduce.js +8 -0
- package/dist/js/modern/ssr/serverRender/renderToString/styledComponent.js +11 -0
- package/dist/js/modern/ssr/serverRender/renderToString/template.js +58 -0
- package/dist/js/modern/ssr/serverRender/renderToString/type.js +9 -0
- package/dist/js/modern/ssr/serverRender/types.js +4 -0
- package/dist/js/modern/ssr/serverRender/utils.js +22 -0
- package/dist/js/modern/ssr/utils.js +81 -0
- package/dist/js/modern/state/cli/index.js +83 -0
- package/dist/js/modern/state/index.js +7 -0
- package/dist/js/modern/state/plugins.js +13 -0
- package/dist/js/modern/state/runtime/index.js +9 -0
- package/dist/js/modern/state/runtime/plugin.js +97 -0
- package/dist/js/modern/state/types.js +0 -0
- package/dist/js/node/cli/index.js +99 -0
- package/dist/js/node/common.js +27 -0
- package/dist/js/node/config.js +15 -0
- package/dist/js/node/core/app-config.js +34 -0
- package/dist/js/node/core/compatible.js +312 -0
- package/dist/js/node/core/index.js +47 -0
- package/dist/js/node/core/loader/index.js +33 -0
- package/dist/js/node/core/loader/loaderManager.js +195 -0
- package/dist/js/node/core/loader/useLoader.js +132 -0
- package/dist/js/node/core/plugin.js +80 -0
- package/dist/js/node/document/Body.js +43 -0
- package/dist/js/node/document/DocumentContext.js +38 -0
- package/dist/js/node/document/DocumentStructrueContext.js +40 -0
- package/dist/js/node/document/Head.js +51 -0
- package/dist/js/node/document/Html.js +101 -0
- package/dist/js/node/document/Links.js +33 -0
- package/dist/js/node/document/Root.js +57 -0
- package/dist/js/node/document/Script.js +40 -0
- package/dist/js/node/document/Scripts.js +33 -0
- package/dist/js/node/document/cli/index.js +240 -0
- package/dist/js/node/document/constants.js +86 -0
- package/dist/js/node/document/index.js +26 -0
- package/dist/js/node/exports/head.js +34 -0
- package/dist/js/node/exports/loadable.js +34 -0
- package/dist/js/node/exports/server.js +27 -0
- package/dist/js/node/exports/styled.js +34 -0
- package/dist/js/node/index.js +44 -0
- package/dist/js/node/router/cli/index.js +135 -0
- package/dist/js/node/router/index.js +37 -0
- package/dist/js/node/router/runtime/DefaultNotFound.js +37 -0
- package/dist/js/node/router/runtime/index.js +33 -0
- package/dist/js/node/router/runtime/plugin.js +127 -0
- package/dist/js/node/router/runtime/plugin.node.js +175 -0
- package/dist/js/node/router/runtime/server.js +17 -0
- package/dist/js/node/router/runtime/types.js +15 -0
- package/dist/js/node/router/runtime/utils.js +221 -0
- package/dist/js/node/router/runtime/withRouter.js +57 -0
- package/dist/js/node/runtime-context.js +31 -0
- package/dist/js/node/ssr/cli/babel-plugin-ssr-loader-id.js +139 -0
- package/dist/js/node/ssr/cli/index.js +190 -0
- package/dist/js/node/ssr/index.js +185 -0
- package/dist/js/node/ssr/index.node.js +107 -0
- package/dist/js/node/ssr/prefetch.js +90 -0
- package/dist/js/node/ssr/react/index.js +30 -0
- package/dist/js/node/ssr/react/nossr/index.js +43 -0
- package/dist/js/node/ssr/react/prerender/index.js +130 -0
- package/dist/js/node/ssr/react/prerender/type.js +15 -0
- package/dist/js/node/ssr/react/prerender/util.js +123 -0
- package/dist/js/node/ssr/react/withCallback/index.js +38 -0
- package/dist/js/node/ssr/serverRender/helmet.js +65 -0
- package/dist/js/node/ssr/serverRender/index.js +56 -0
- package/dist/js/node/ssr/serverRender/renderToStream/buildTemplate.after.js +65 -0
- package/dist/js/node/ssr/serverRender/renderToStream/buildTemplate.share.js +35 -0
- package/dist/js/node/ssr/serverRender/renderToStream/bulidTemplate.before.js +87 -0
- package/dist/js/node/ssr/serverRender/renderToStream/index.js +87 -0
- package/dist/js/node/ssr/serverRender/renderToStream/loadable.js +47 -0
- package/dist/js/node/ssr/serverRender/renderToStream/renderToPipe.js +111 -0
- package/dist/js/node/ssr/serverRender/renderToStream/styledComponent.js +35 -0
- package/dist/js/node/ssr/serverRender/renderToStream/template.js +45 -0
- package/dist/js/node/ssr/serverRender/renderToStream/type.js +15 -0
- package/dist/js/node/ssr/serverRender/renderToString/entry.js +196 -0
- package/dist/js/node/ssr/serverRender/renderToString/index.js +81 -0
- package/dist/js/node/ssr/serverRender/renderToString/loadable.js +71 -0
- package/dist/js/node/ssr/serverRender/renderToString/reduce.js +31 -0
- package/dist/js/node/ssr/serverRender/renderToString/styledComponent.js +34 -0
- package/dist/js/node/ssr/serverRender/renderToString/template.js +82 -0
- package/dist/js/node/ssr/serverRender/renderToString/type.js +32 -0
- package/dist/js/node/ssr/serverRender/types.js +27 -0
- package/dist/js/node/ssr/serverRender/utils.js +46 -0
- package/dist/js/node/ssr/utils.js +106 -0
- package/dist/js/node/state/cli/index.js +100 -0
- package/dist/js/node/state/index.js +37 -0
- package/dist/js/node/state/plugins.js +45 -0
- package/dist/js/node/state/runtime/index.js +40 -0
- package/dist/js/node/state/runtime/plugin.js +121 -0
- package/dist/js/node/state/types.js +15 -0
- package/dist/js/treeshaking/cli/index.js +186 -0
- package/dist/js/treeshaking/common.js +4 -0
- package/dist/js/treeshaking/config.js +1 -0
- package/dist/js/treeshaking/core/app-config.js +9 -0
- package/dist/js/treeshaking/core/compatible.js +485 -0
- package/dist/js/treeshaking/core/index.js +7 -0
- package/dist/js/treeshaking/core/loader/index.js +2 -0
- package/dist/js/treeshaking/core/loader/loaderManager.js +406 -0
- package/dist/js/treeshaking/core/loader/useLoader.js +188 -0
- package/dist/js/treeshaking/core/plugin.js +176 -0
- package/dist/js/treeshaking/document/Body.js +18 -0
- package/dist/js/treeshaking/document/DocumentContext.js +7 -0
- package/dist/js/treeshaking/document/DocumentStructrueContext.js +9 -0
- package/dist/js/treeshaking/document/Head.js +24 -0
- package/dist/js/treeshaking/document/Html.js +99 -0
- package/dist/js/treeshaking/document/Links.js +8 -0
- package/dist/js/treeshaking/document/Root.js +26 -0
- package/dist/js/treeshaking/document/Script.js +15 -0
- package/dist/js/treeshaking/document/Scripts.js +8 -0
- package/dist/js/treeshaking/document/cli/index.js +393 -0
- package/dist/js/treeshaking/document/constants.js +35 -0
- package/dist/js/treeshaking/document/index.js +10 -0
- package/dist/js/treeshaking/exports/head.js +4 -0
- package/dist/js/treeshaking/exports/loadable.js +4 -0
- package/dist/js/treeshaking/exports/server.js +4 -0
- package/dist/js/treeshaking/exports/styled.js +4 -0
- package/dist/js/treeshaking/index.js +3 -0
- package/dist/js/treeshaking/router/cli/index.js +148 -0
- package/dist/js/treeshaking/router/index.js +4 -0
- package/dist/js/treeshaking/router/runtime/DefaultNotFound.js +14 -0
- package/dist/js/treeshaking/router/runtime/index.js +6 -0
- package/dist/js/treeshaking/router/runtime/plugin.js +132 -0
- package/dist/js/treeshaking/router/runtime/plugin.node.js +390 -0
- package/dist/js/treeshaking/router/runtime/server.js +1 -0
- package/dist/js/treeshaking/router/runtime/types.js +1 -0
- package/dist/js/treeshaking/router/runtime/utils.js +260 -0
- package/dist/js/treeshaking/router/runtime/withRouter.js +67 -0
- package/dist/js/treeshaking/runtime-context.js +4 -0
- package/dist/js/treeshaking/ssr/cli/babel-plugin-ssr-loader-id.js +122 -0
- package/dist/js/treeshaking/ssr/cli/index.js +217 -0
- package/dist/js/treeshaking/ssr/index.js +315 -0
- package/dist/js/treeshaking/ssr/index.node.js +240 -0
- package/dist/js/treeshaking/ssr/prefetch.js +199 -0
- package/dist/js/treeshaking/ssr/react/index.js +3 -0
- package/dist/js/treeshaking/ssr/react/nossr/index.js +58 -0
- package/dist/js/treeshaking/ssr/react/prerender/index.js +237 -0
- package/dist/js/treeshaking/ssr/react/prerender/type.js +1 -0
- package/dist/js/treeshaking/ssr/react/prerender/util.js +108 -0
- package/dist/js/treeshaking/ssr/react/withCallback/index.js +16 -0
- package/dist/js/treeshaking/ssr/serverRender/helmet.js +42 -0
- package/dist/js/treeshaking/ssr/serverRender/index.js +169 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/buildTemplate.after.js +34 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/buildTemplate.share.js +7 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/bulidTemplate.before.js +115 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/index.js +165 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/loadable.js +22 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/renderToPipe.js +119 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/styledComponent.js +11 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/template.js +63 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/type.js +1 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToString/entry.js +393 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToString/index.js +165 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToString/loadable.js +56 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToString/reduce.js +10 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToString/styledComponent.js +9 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToString/template.js +156 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToString/type.js +7 -0
- package/dist/js/treeshaking/ssr/serverRender/types.js +2 -0
- package/dist/js/treeshaking/ssr/serverRender/utils.js +69 -0
- package/dist/js/treeshaking/ssr/utils.js +134 -0
- package/dist/js/treeshaking/state/cli/index.js +71 -0
- package/dist/js/treeshaking/state/index.js +4 -0
- package/dist/js/treeshaking/state/plugins.js +14 -0
- package/dist/js/treeshaking/state/runtime/index.js +5 -0
- package/dist/js/treeshaking/state/runtime/plugin.js +198 -0
- package/dist/js/treeshaking/state/types.js +1 -0
- package/dist/types/document/Html.d.ts +2 -2
- package/dist/types/router/runtime/plugin.d.ts +1 -1
- package/dist/types/router/runtime/plugin.node.d.ts +1 -1
- package/dist/types/router/runtime/types.d.ts +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _asyncToGenerator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
31
|
+
var f, y, t, g, _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function() {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
39
|
+
};
|
|
40
|
+
return(g = {
|
|
41
|
+
next: verb(0),
|
|
42
|
+
"throw": verb(1),
|
|
43
|
+
"return": verb(2)
|
|
44
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
45
|
+
return this;
|
|
46
|
+
}), g);
|
|
47
|
+
function verb(n) {
|
|
48
|
+
return function(v) {
|
|
49
|
+
return step([
|
|
50
|
+
n,
|
|
51
|
+
v
|
|
52
|
+
]);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function step(op) {
|
|
56
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
57
|
+
while(_)try {
|
|
58
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
59
|
+
if (y = 0, t) op = [
|
|
60
|
+
op[0] & 2,
|
|
61
|
+
t.value
|
|
62
|
+
];
|
|
63
|
+
switch(op[0]){
|
|
64
|
+
case 0:
|
|
65
|
+
case 1:
|
|
66
|
+
t = op;
|
|
67
|
+
break;
|
|
68
|
+
case 4:
|
|
69
|
+
_.label++;
|
|
70
|
+
return {
|
|
71
|
+
value: op[1],
|
|
72
|
+
done: false
|
|
73
|
+
};
|
|
74
|
+
case 5:
|
|
75
|
+
_.label++;
|
|
76
|
+
y = op[1];
|
|
77
|
+
op = [
|
|
78
|
+
0
|
|
79
|
+
];
|
|
80
|
+
continue;
|
|
81
|
+
case 7:
|
|
82
|
+
op = _.ops.pop();
|
|
83
|
+
_.trys.pop();
|
|
84
|
+
continue;
|
|
85
|
+
default:
|
|
86
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
87
|
+
_ = 0;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
91
|
+
_.label = op[1];
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
95
|
+
_.label = t[1];
|
|
96
|
+
t = op;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (t && _.label < t[2]) {
|
|
100
|
+
_.label = t[2];
|
|
101
|
+
_.ops.push(op);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
if (t[2]) _.ops.pop();
|
|
105
|
+
_.trys.pop();
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
op = body.call(thisArg, _);
|
|
109
|
+
} catch (e) {
|
|
110
|
+
op = [
|
|
111
|
+
6,
|
|
112
|
+
e
|
|
113
|
+
];
|
|
114
|
+
y = 0;
|
|
115
|
+
} finally{
|
|
116
|
+
f = t = 0;
|
|
117
|
+
}
|
|
118
|
+
if (op[0] & 5) throw op[1];
|
|
119
|
+
return {
|
|
120
|
+
value: op[0] ? op[1] : void 0,
|
|
121
|
+
done: true
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
import { jsx } from "react/jsx-runtime";
|
|
126
|
+
import { renderToStaticMarkup } from "react-dom/server";
|
|
127
|
+
import { run } from "@modern-js/utils/ssr";
|
|
128
|
+
import { ChunkExtractor } from "@loadable/server";
|
|
129
|
+
var prefetch = function() {
|
|
130
|
+
var _ref = _asyncToGenerator(function(App, context) {
|
|
131
|
+
return __generator(this, function(_state) {
|
|
132
|
+
return [
|
|
133
|
+
2,
|
|
134
|
+
run(context.ssrContext.request.headers, /*#__PURE__*/ _asyncToGenerator(function() {
|
|
135
|
+
var ref, ssrContext, loadableStats, extractor, loadersData;
|
|
136
|
+
return __generator(this, function(_state) {
|
|
137
|
+
switch(_state.label){
|
|
138
|
+
case 0:
|
|
139
|
+
ssrContext = context.ssrContext;
|
|
140
|
+
loadableStats = ssrContext.loadableStats;
|
|
141
|
+
if (loadableStats) {
|
|
142
|
+
extractor = new ChunkExtractor({
|
|
143
|
+
stats: loadableStats,
|
|
144
|
+
entrypoints: [
|
|
145
|
+
ssrContext.entryName
|
|
146
|
+
].filter(Boolean)
|
|
147
|
+
});
|
|
148
|
+
renderToStaticMarkup(extractor.collectChunks(/* @__PURE__ */ jsx(App, {
|
|
149
|
+
context: context
|
|
150
|
+
})));
|
|
151
|
+
} else {
|
|
152
|
+
renderToStaticMarkup(/* @__PURE__ */ jsx(App, {
|
|
153
|
+
context: context
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
if (!context.loaderManager.hasPendingLoaders()) {
|
|
157
|
+
return [
|
|
158
|
+
2,
|
|
159
|
+
{
|
|
160
|
+
initialData: context.initialData,
|
|
161
|
+
i18nData: context.__i18nData__
|
|
162
|
+
}
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
return [
|
|
166
|
+
4,
|
|
167
|
+
context.loaderManager.awaitPendingLoaders()
|
|
168
|
+
];
|
|
169
|
+
case 1:
|
|
170
|
+
loadersData = _state.sent();
|
|
171
|
+
Object.keys(loadersData).forEach(function(id) {
|
|
172
|
+
var data = loadersData[id];
|
|
173
|
+
if (data._error) {
|
|
174
|
+
ssrContext.logger.error("App Prefetch Loader", data._error);
|
|
175
|
+
ssrContext.metrics.emitCounter("app.prefetch.loader.error", 1);
|
|
176
|
+
delete data._error;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
return [
|
|
180
|
+
2,
|
|
181
|
+
{
|
|
182
|
+
loadersData: loadersData,
|
|
183
|
+
initialData: context.initialData,
|
|
184
|
+
i18nData: context.__i18nData__,
|
|
185
|
+
storeState: context === null || context === void 0 ? void 0 : (ref = context.store) === null || ref === void 0 ? void 0 : ref.getState()
|
|
186
|
+
}
|
|
187
|
+
];
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}))
|
|
191
|
+
];
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
return function prefetch(App, context) {
|
|
195
|
+
return _ref.apply(this, arguments);
|
|
196
|
+
};
|
|
197
|
+
}();
|
|
198
|
+
var prefetch_default = prefetch;
|
|
199
|
+
export { prefetch_default as default };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
function _arrayLikeToArray(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _arrayWithHoles(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function _iterableToArrayLimit(arr, i) {
|
|
10
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
11
|
+
if (_i == null) return;
|
|
12
|
+
var _arr = [];
|
|
13
|
+
var _n = true;
|
|
14
|
+
var _d = false;
|
|
15
|
+
var _s, _e;
|
|
16
|
+
try {
|
|
17
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
18
|
+
_arr.push(_s.value);
|
|
19
|
+
if (i && _arr.length === i) break;
|
|
20
|
+
}
|
|
21
|
+
} catch (err) {
|
|
22
|
+
_d = true;
|
|
23
|
+
_e = err;
|
|
24
|
+
} finally{
|
|
25
|
+
try {
|
|
26
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
27
|
+
} finally{
|
|
28
|
+
if (_d) throw _e;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return _arr;
|
|
32
|
+
}
|
|
33
|
+
function _nonIterableRest() {
|
|
34
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
35
|
+
}
|
|
36
|
+
function _slicedToArray(arr, i) {
|
|
37
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
38
|
+
}
|
|
39
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
40
|
+
if (!o) return;
|
|
41
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
42
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
43
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
44
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
45
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
46
|
+
}
|
|
47
|
+
import React, { useEffect, useState } from "react";
|
|
48
|
+
var csr = false;
|
|
49
|
+
var NoSSR = function(props) {
|
|
50
|
+
var ref = _slicedToArray(useState(csr), 2), isMounted = ref[0], setMounted = ref[1];
|
|
51
|
+
useEffect(function() {
|
|
52
|
+
csr = true;
|
|
53
|
+
setMounted(true);
|
|
54
|
+
});
|
|
55
|
+
var children = props.children;
|
|
56
|
+
return React.createElement(React.Fragment, null, isMounted ? children : null);
|
|
57
|
+
};
|
|
58
|
+
export { NoSSR };
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
function _assertThisInitialized(self) {
|
|
2
|
+
if (self === void 0) {
|
|
3
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
4
|
+
}
|
|
5
|
+
return self;
|
|
6
|
+
}
|
|
7
|
+
function _classCallCheck(instance, Constructor) {
|
|
8
|
+
if (!(instance instanceof Constructor)) {
|
|
9
|
+
throw new TypeError("Cannot call a class as a function");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function _defineProperties(target, props) {
|
|
13
|
+
for(var i = 0; i < props.length; i++){
|
|
14
|
+
var descriptor = props[i];
|
|
15
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
16
|
+
descriptor.configurable = true;
|
|
17
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
18
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
22
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
23
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
24
|
+
return Constructor;
|
|
25
|
+
}
|
|
26
|
+
function _defineProperty(obj, key, value) {
|
|
27
|
+
if (key in obj) {
|
|
28
|
+
Object.defineProperty(obj, key, {
|
|
29
|
+
value: value,
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
obj[key] = value;
|
|
36
|
+
}
|
|
37
|
+
return obj;
|
|
38
|
+
}
|
|
39
|
+
function _getPrototypeOf(o) {
|
|
40
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
41
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
42
|
+
};
|
|
43
|
+
return _getPrototypeOf(o);
|
|
44
|
+
}
|
|
45
|
+
function _inherits(subClass, superClass) {
|
|
46
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
47
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
48
|
+
}
|
|
49
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
50
|
+
constructor: {
|
|
51
|
+
value: subClass,
|
|
52
|
+
writable: true,
|
|
53
|
+
configurable: true
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
57
|
+
}
|
|
58
|
+
function _objectSpread(target) {
|
|
59
|
+
for(var i = 1; i < arguments.length; i++){
|
|
60
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
61
|
+
var ownKeys = Object.keys(source);
|
|
62
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
63
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
64
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
ownKeys.forEach(function(key) {
|
|
68
|
+
_defineProperty(target, key, source[key]);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return target;
|
|
72
|
+
}
|
|
73
|
+
function ownKeys(object, enumerableOnly) {
|
|
74
|
+
var keys = Object.keys(object);
|
|
75
|
+
if (Object.getOwnPropertySymbols) {
|
|
76
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
77
|
+
if (enumerableOnly) {
|
|
78
|
+
symbols = symbols.filter(function(sym) {
|
|
79
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
keys.push.apply(keys, symbols);
|
|
83
|
+
}
|
|
84
|
+
return keys;
|
|
85
|
+
}
|
|
86
|
+
function _objectSpreadProps(target, source) {
|
|
87
|
+
source = source != null ? source : {};
|
|
88
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
89
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
90
|
+
} else {
|
|
91
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
92
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return target;
|
|
96
|
+
}
|
|
97
|
+
function _possibleConstructorReturn(self, call) {
|
|
98
|
+
if (call && (_typeof(call) === "object" || typeof call === "function")) {
|
|
99
|
+
return call;
|
|
100
|
+
}
|
|
101
|
+
return _assertThisInitialized(self);
|
|
102
|
+
}
|
|
103
|
+
function _setPrototypeOf(o, p) {
|
|
104
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
105
|
+
o.__proto__ = p;
|
|
106
|
+
return o;
|
|
107
|
+
};
|
|
108
|
+
return _setPrototypeOf(o, p);
|
|
109
|
+
}
|
|
110
|
+
var _typeof = function(obj) {
|
|
111
|
+
"@swc/helpers - typeof";
|
|
112
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
113
|
+
};
|
|
114
|
+
function _isNativeReflectConstruct() {
|
|
115
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
116
|
+
if (Reflect.construct.sham) return false;
|
|
117
|
+
if (typeof Proxy === "function") return true;
|
|
118
|
+
try {
|
|
119
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
120
|
+
return true;
|
|
121
|
+
} catch (e) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function _createSuper(Derived) {
|
|
126
|
+
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
127
|
+
return function _createSuperInternal() {
|
|
128
|
+
var Super = _getPrototypeOf(Derived), result;
|
|
129
|
+
if (hasNativeReflectConstruct) {
|
|
130
|
+
var NewTarget = _getPrototypeOf(this).constructor;
|
|
131
|
+
result = Reflect.construct(Super, arguments, NewTarget);
|
|
132
|
+
} else {
|
|
133
|
+
result = Super.apply(this, arguments);
|
|
134
|
+
}
|
|
135
|
+
return _possibleConstructorReturn(this, result);
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
import withSideEffect from "react-side-effect";
|
|
139
|
+
import React, { createElement } from "react";
|
|
140
|
+
import { getOutermostProperty, aggKeysFromPropsList, exist, aggMatchesFromPropsList } from "./util";
|
|
141
|
+
var PROP_NAMES = {
|
|
142
|
+
INTERVAL: "interval",
|
|
143
|
+
STALE_LIMIT: "staleLimit",
|
|
144
|
+
LEVEL: "level",
|
|
145
|
+
INCLUDES: "includes",
|
|
146
|
+
EXCLUDES: "excludes",
|
|
147
|
+
FALLBACK: "fallback",
|
|
148
|
+
MATCHES: "matches"
|
|
149
|
+
};
|
|
150
|
+
var handleClientStateChange = function() {};
|
|
151
|
+
var mapStateOnServer = function(reduceProps) {
|
|
152
|
+
var defaultProps = {
|
|
153
|
+
interval: 10,
|
|
154
|
+
staleLimit: false,
|
|
155
|
+
level: 0,
|
|
156
|
+
includes: null,
|
|
157
|
+
excludes: null,
|
|
158
|
+
fallback: false,
|
|
159
|
+
matches: null
|
|
160
|
+
};
|
|
161
|
+
return Object.keys(defaultProps).reduce(function(props, key) {
|
|
162
|
+
var propKey = key;
|
|
163
|
+
var reduceProp = reduceProps[propKey];
|
|
164
|
+
var nextProps = props;
|
|
165
|
+
if (exist(reduceProp)) {
|
|
166
|
+
nextProps = _objectSpreadProps(_objectSpread({}, props), _defineProperty({}, propKey, reduceProp));
|
|
167
|
+
}
|
|
168
|
+
return nextProps;
|
|
169
|
+
}, defaultProps);
|
|
170
|
+
};
|
|
171
|
+
var reducePropsToState = function(propsList) {
|
|
172
|
+
var reduceProps = {
|
|
173
|
+
interval: getOutermostProperty(propsList, PROP_NAMES.INTERVAL),
|
|
174
|
+
staleLimit: getOutermostProperty(propsList, PROP_NAMES.STALE_LIMIT),
|
|
175
|
+
level: getOutermostProperty(propsList, PROP_NAMES.LEVEL),
|
|
176
|
+
includes: aggKeysFromPropsList(propsList, PROP_NAMES.INCLUDES),
|
|
177
|
+
excludes: aggKeysFromPropsList(propsList, PROP_NAMES.EXCLUDES),
|
|
178
|
+
fallback: getOutermostProperty(propsList, PROP_NAMES.FALLBACK),
|
|
179
|
+
matches: aggMatchesFromPropsList(propsList, PROP_NAMES.MATCHES)
|
|
180
|
+
};
|
|
181
|
+
return reduceProps;
|
|
182
|
+
};
|
|
183
|
+
function factory(Component) {
|
|
184
|
+
var _Component;
|
|
185
|
+
var Spr = /*#__PURE__*/ function(_superClass) {
|
|
186
|
+
"use strict";
|
|
187
|
+
_inherits(Spr, _superClass);
|
|
188
|
+
var _super = _createSuper(Spr);
|
|
189
|
+
function Spr() {
|
|
190
|
+
_classCallCheck(this, Spr);
|
|
191
|
+
return _super.apply(this, arguments);
|
|
192
|
+
}
|
|
193
|
+
_createClass(Spr, [
|
|
194
|
+
{
|
|
195
|
+
key: "verify",
|
|
196
|
+
value: function verify() {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
key: "render",
|
|
202
|
+
value: function render() {
|
|
203
|
+
var newProps = _objectSpread({}, this.props);
|
|
204
|
+
var validate = this.verify();
|
|
205
|
+
if (!validate) {
|
|
206
|
+
throw new Error("invalid props, check usage");
|
|
207
|
+
}
|
|
208
|
+
return createElement(Component, _objectSpread({}, newProps));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
], [
|
|
212
|
+
{
|
|
213
|
+
key: "canUseDOM",
|
|
214
|
+
get: function get() {
|
|
215
|
+
return Component.canUseDOM;
|
|
216
|
+
},
|
|
217
|
+
set: function set(canUseDOM) {
|
|
218
|
+
Component.canUseDOM = canUseDOM;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
]);
|
|
222
|
+
return Spr;
|
|
223
|
+
}(_Component = React.Component);
|
|
224
|
+
_defineProperty(Spr, "peek", Component.peek);
|
|
225
|
+
_defineProperty(Spr, "rewind", Component.rewind);
|
|
226
|
+
_defineProperty(Spr, "config", function() {
|
|
227
|
+
var mappedState = Component.rewind();
|
|
228
|
+
return mappedState;
|
|
229
|
+
});
|
|
230
|
+
return Spr;
|
|
231
|
+
}
|
|
232
|
+
var NullComponent = function() {
|
|
233
|
+
return null;
|
|
234
|
+
};
|
|
235
|
+
var SprSideEffects = withSideEffect(reducePropsToState, handleClientStateChange, mapStateOnServer)(NullComponent);
|
|
236
|
+
var PreRender = factory(SprSideEffects);
|
|
237
|
+
export { PreRender };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
var REQUEST_META = [
|
|
2
|
+
"header",
|
|
3
|
+
"query"
|
|
4
|
+
];
|
|
5
|
+
var getInnermostProperty = function getInnermostProperty2(propsList, propName) {
|
|
6
|
+
for(var i = propsList.length - 1; i >= 0; i--){
|
|
7
|
+
var props = propsList[i];
|
|
8
|
+
if (props.hasOwnProperty(propName)) {
|
|
9
|
+
return props[propName];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
};
|
|
14
|
+
var getOutermostProperty = function getOutermostProperty2(propsList, propName) {
|
|
15
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
16
|
+
try {
|
|
17
|
+
for(var _iterator = propsList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
18
|
+
var props = _step.value;
|
|
19
|
+
if (props.hasOwnProperty(propName)) {
|
|
20
|
+
return props[propName];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
} catch (err) {
|
|
24
|
+
_didIteratorError = true;
|
|
25
|
+
_iteratorError = err;
|
|
26
|
+
} finally{
|
|
27
|
+
try {
|
|
28
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
29
|
+
_iterator.return();
|
|
30
|
+
}
|
|
31
|
+
} finally{
|
|
32
|
+
if (_didIteratorError) {
|
|
33
|
+
throw _iteratorError;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
};
|
|
39
|
+
var aggKeysFromPropsList = function aggKeysFromPropsList2(propsList, propName) {
|
|
40
|
+
var initResult = REQUEST_META.reduce(function(result, next) {
|
|
41
|
+
var key = next;
|
|
42
|
+
result[key] = [];
|
|
43
|
+
return result;
|
|
44
|
+
}, {});
|
|
45
|
+
var res = propsList.filter(function(props) {
|
|
46
|
+
return usefulObject(props[propName]);
|
|
47
|
+
}).reduce(function(result, next) {
|
|
48
|
+
REQUEST_META.forEach(function(key) {
|
|
49
|
+
var prop = next[propName];
|
|
50
|
+
if ((prop === null || prop === void 0 ? void 0 : prop.hasOwnProperty(key)) && usefulArray(prop[key])) {
|
|
51
|
+
result[key] = unique(result[key].concat(prop[key]));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return result;
|
|
55
|
+
}, initResult);
|
|
56
|
+
return REQUEST_META.reduce(function(result, next) {
|
|
57
|
+
var ref;
|
|
58
|
+
var key = next;
|
|
59
|
+
if (result[key] && ((ref = result[key]) === null || ref === void 0 ? void 0 : ref.length) === 0) {
|
|
60
|
+
delete result[key];
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}, res);
|
|
64
|
+
};
|
|
65
|
+
var aggMatchesFromPropsList = function aggMatchesFromPropsList2(propsList, propName) {
|
|
66
|
+
var initResult = REQUEST_META.reduce(function(result, next) {
|
|
67
|
+
var key = next;
|
|
68
|
+
result[key] = {};
|
|
69
|
+
return result;
|
|
70
|
+
}, {});
|
|
71
|
+
var res = propsList.filter(function(props) {
|
|
72
|
+
return usefulObject(props[propName]);
|
|
73
|
+
}).reduce(function(result, next) {
|
|
74
|
+
REQUEST_META.forEach(function(key) {
|
|
75
|
+
var prop = next[propName];
|
|
76
|
+
if ((prop === null || prop === void 0 ? void 0 : prop.hasOwnProperty(key)) && usefulObject(prop[key])) {
|
|
77
|
+
result[key] = Object.assign(result[key], prop[key]);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return result;
|
|
81
|
+
}, initResult);
|
|
82
|
+
return REQUEST_META.reduce(function(result, next) {
|
|
83
|
+
var key = next;
|
|
84
|
+
if (result[key] && Object.keys(result[key]).length === 0) {
|
|
85
|
+
delete result[key];
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}, res);
|
|
89
|
+
};
|
|
90
|
+
function unique(arr) {
|
|
91
|
+
return Array.from(new Set(arr));
|
|
92
|
+
}
|
|
93
|
+
function usefulObject(target) {
|
|
94
|
+
if (!exist(target)) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
return target.constructor === Object && Object.keys(target).length > 0;
|
|
98
|
+
}
|
|
99
|
+
function usefulArray(target) {
|
|
100
|
+
if (!exist(target)) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
return Array.isArray(target) && target.length > 0;
|
|
104
|
+
}
|
|
105
|
+
function exist(target) {
|
|
106
|
+
return target != null;
|
|
107
|
+
}
|
|
108
|
+
export { aggKeysFromPropsList, aggMatchesFromPropsList, exist, getInnermostProperty, getOutermostProperty };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useRef, useLayoutEffect } from "react";
|
|
2
|
+
var WithCallback = function(param) {
|
|
3
|
+
var callback = param.callback, children = param.children;
|
|
4
|
+
var once = useRef(false);
|
|
5
|
+
useLayoutEffect(function() {
|
|
6
|
+
if (once.current) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
once.current = true;
|
|
10
|
+
callback();
|
|
11
|
+
}, [
|
|
12
|
+
callback
|
|
13
|
+
]);
|
|
14
|
+
return children;
|
|
15
|
+
};
|
|
16
|
+
export { WithCallback };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { EOL } from "os";
|
|
2
|
+
var RE_HTML_ATTR = /<html[^>]*>/;
|
|
3
|
+
var RE_BODY_ATTR = /<body[^>]*>/;
|
|
4
|
+
var RE_LAST_IN_HEAD = /<\/head>/;
|
|
5
|
+
var RE_TITLE = /<title[^>]*>([\s\S\n\r]*?)<\/title>/;
|
|
6
|
+
var TEST_TITLE_CONTENT = RegExp("(?<=<title[^>]*>)([\\s\\S\\n\\r]*?)([.|\\S])([\\s\\S\\n\\r]*?)(?=<\\/title>)");
|
|
7
|
+
function helmet(content, helmetData) {
|
|
8
|
+
var result = content;
|
|
9
|
+
var bodyAttributes = helmetData.bodyAttributes.toString();
|
|
10
|
+
if (bodyAttributes) {
|
|
11
|
+
result = result.replace(RE_BODY_ATTR, "<body ".concat(bodyAttributes, ">"));
|
|
12
|
+
}
|
|
13
|
+
var htmlAttributes = helmetData.htmlAttributes.toString();
|
|
14
|
+
if (htmlAttributes) {
|
|
15
|
+
result = result.replace(RE_HTML_ATTR, "<html ".concat(htmlAttributes, ">"));
|
|
16
|
+
}
|
|
17
|
+
var base = helmetData.base.toString();
|
|
18
|
+
var link = helmetData.link.toString();
|
|
19
|
+
var meta = helmetData.meta.toString();
|
|
20
|
+
var noscript = helmetData.noscript.toString();
|
|
21
|
+
var script = helmetData.script.toString();
|
|
22
|
+
var style = helmetData.style.toString();
|
|
23
|
+
var title = helmetData.title.toString();
|
|
24
|
+
var existTitleTag = RE_TITLE.test(content);
|
|
25
|
+
var shouldReplaceTitle = existTitleTag && TEST_TITLE_CONTENT.test(title.trim());
|
|
26
|
+
if (shouldReplaceTitle) {
|
|
27
|
+
result = result.replace(RE_TITLE, title);
|
|
28
|
+
}
|
|
29
|
+
var helmetStr = [
|
|
30
|
+
base,
|
|
31
|
+
link,
|
|
32
|
+
meta,
|
|
33
|
+
noscript,
|
|
34
|
+
script,
|
|
35
|
+
style,
|
|
36
|
+
!existTitleTag ? title : ""
|
|
37
|
+
].reduce(function(pre, cur) {
|
|
38
|
+
return pre + (cur.length > 0 ? " ".concat(cur).concat(EOL) : "");
|
|
39
|
+
}, "");
|
|
40
|
+
return result.replace(RE_LAST_IN_HEAD, "".concat(helmetStr, "</head>"));
|
|
41
|
+
}
|
|
42
|
+
export { helmet as default };
|