@modern-js/plugin-garfish 2.15.0 → 2.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 +15 -0
- package/dist/cjs/cli/index.js +224 -236
- package/dist/cjs/cli/utils.js +24 -48
- package/dist/cjs/deps/index.js +12 -35
- package/dist/cjs/index.js +26 -36
- package/dist/cjs/runtime/index.js +24 -44
- package/dist/cjs/runtime/loadable.js +46 -58
- package/dist/cjs/runtime/plugin.js +86 -82
- package/dist/cjs/runtime/useModuleApps.js +70 -56
- package/dist/cjs/runtime/utils/Context.js +18 -36
- package/dist/cjs/runtime/utils/MApp.js +88 -87
- package/dist/cjs/runtime/utils/apps.js +114 -94
- package/dist/cjs/runtime/utils/setExternal.js +23 -41
- package/dist/cjs/util.js +21 -40
- package/dist/esm/cli/index.js +409 -402
- package/dist/esm/cli/utils.js +25 -26
- package/dist/esm/deps/index.js +1 -2
- package/dist/esm/index.js +1 -2
- package/dist/esm/runtime/index.js +3 -4
- package/dist/esm/runtime/loadable.js +226 -210
- package/dist/esm/runtime/plugin.js +456 -426
- package/dist/esm/runtime/useModuleApps.js +49 -50
- package/dist/esm/runtime/utils/Context.js +1 -1
- package/dist/esm/runtime/utils/MApp.js +337 -316
- package/dist/esm/runtime/utils/apps.js +468 -442
- package/dist/esm/runtime/utils/setExternal.js +9 -9
- package/dist/esm/util.js +4 -5
- package/dist/esm-node/cli/index.js +209 -219
- package/dist/esm-node/cli/utils.js +15 -30
- package/dist/esm-node/deps/index.js +1 -4
- package/dist/esm-node/index.js +1 -4
- package/dist/esm-node/runtime/index.js +3 -10
- package/dist/esm-node/runtime/loadable.js +34 -31
- package/dist/esm-node/runtime/plugin.js +50 -33
- package/dist/esm-node/runtime/useModuleApps.js +12 -19
- package/dist/esm-node/runtime/utils/Context.js +2 -5
- package/dist/esm-node/runtime/utils/MApp.js +61 -40
- package/dist/esm-node/runtime/utils/apps.js +38 -44
- package/dist/esm-node/runtime/utils/setExternal.js +5 -5
- package/dist/esm-node/util.js +4 -9
- package/package.json +15 -11
package/dist/esm/cli/utils.js
CHANGED
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
var makeProvider = function() {
|
|
2
|
-
|
|
1
|
+
export var makeProvider = function() {
|
|
2
|
+
return "\nexport const provider = function ({basename, dom}) {\n return {\n render({basename, dom, props, appName}) {\n render({ props, basename, dom, appName });\n },\n destroy({ dom }) {\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n\n if (node) {\n if (IS_REACT18) {\n root.unmount();\n } else {\n unmountComponentAtNode(node);\n }\n }\n },\n SubModuleComponent: (props) => {\n const SubApp = render({props, basename});\n\n return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);\n },\n jupiter_submodule_app_key: (props) => {\n const SubApp = render({props, basename});\n\n return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);\n }\n }\n};\n\nif (typeof __GARFISH_EXPORTS__ !== 'undefined') {\n __GARFISH_EXPORTS__.provider = provider;\n}\n\nfunction canContinueRender ({ dom, appName }) {\n var renderByGarfish =\n typeof __GARFISH_EXPORTS__ !== 'undefined'\n || typeof window !== 'undefined' && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.some((app)=>app.appInfo.name === appName);\n let renderByProvider = dom || appName;\n if (renderByGarfish) {\n // Runs in the Garfish environment and is rendered by the provider\n if (renderByProvider) {\n return true;\n } else {\n // Runs in the Garfish environment and is not rendered by the provider\n return false;\n }\n } else {\n // Running in a non-Garfish environment\n return true;\n }\n}\n\nfunction generateRouterPlugin (basename,routerConfig) {\n if (basename) {\n routerConfig.basename = basename;\n if (routerConfig.supportHtml5History !== false) {\n if (!routerConfig.historyOptions) {\n routerConfig.historyOptions = {\n basename: basename\n };\n } else {\n routerConfig.historyOptions.basename = basename;\n }\n }\n }\n return router(routerConfig);\n}\n\nfunction generateRootDom ({ dom, props, basename }) {\n const mountNode = dom ? (dom.querySelector('#' + MOUNT_ID) || dom) : document.getElementById(MOUNT_ID);\n const mergedProps = {\n ...props,\n basename,\n }\n return { mountNode, props: mergedProps }\n}\n";
|
|
3
3
|
};
|
|
4
|
-
var makeRenderFunction = function(code) {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export var makeRenderFunction = function(code) {
|
|
5
|
+
var inGarfishToRender = "\n let { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};\n if (!canContinueRender({ dom, appName })) return null;\n const rootDomInfo = generateRootDom({dom, props, basename});\n let mountNode = rootDomInfo.mountNode;\n props = rootDomInfo.props;\n ";
|
|
6
|
+
return inGarfishToRender + code.replace("router(", "generateRouterPlugin(basename,").replace(/MOUNT_ID/g, "mountNode").replace("createApp({", "createApp({ props,").replace("bootstrap(AppWrapper, mountNode, root", "bootstrap(AppWrapper, mountNode, root = IS_REACT18 ? ReactDOM.createRoot(mountNode) : null").replace("customBootstrap(AppWrapper", "customBootstrap(AppWrapper, mountNode");
|
|
7
7
|
};
|
|
8
|
-
function getRuntimeConfig(config) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
export function getRuntimeConfig(config) {
|
|
9
|
+
var _config_runtime;
|
|
10
|
+
if (config === null || config === void 0 ? void 0 : (_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.features) {
|
|
11
|
+
var _config_runtime1;
|
|
12
|
+
return config === null || config === void 0 ? void 0 : (_config_runtime1 = config.runtime) === null || _config_runtime1 === void 0 ? void 0 : _config_runtime1.features;
|
|
13
|
+
}
|
|
14
|
+
return (config === null || config === void 0 ? void 0 : config.runtime) || {};
|
|
15
15
|
}
|
|
16
|
-
function setRuntimeConfig(config, key, value) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return void 0;
|
|
21
|
-
}
|
|
22
|
-
if ((config === null || config === void 0 ? void 0 : config.runtime) && (config === null || config === void 0 ? void 0 : config.runtime[key])) {
|
|
23
|
-
config.runtime[key] = value;
|
|
24
|
-
return void 0;
|
|
25
|
-
}
|
|
16
|
+
export function setRuntimeConfig(config, key, value) {
|
|
17
|
+
var _config_runtime, _config_runtime1;
|
|
18
|
+
if ((config === null || config === void 0 ? void 0 : (_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.features) && (config === null || config === void 0 ? void 0 : (_config_runtime1 = config.runtime) === null || _config_runtime1 === void 0 ? void 0 : _config_runtime1.features[key])) {
|
|
19
|
+
config.runtime.features[key] = value;
|
|
26
20
|
return void 0;
|
|
21
|
+
}
|
|
22
|
+
if ((config === null || config === void 0 ? void 0 : config.runtime) && (config === null || config === void 0 ? void 0 : config.runtime[key])) {
|
|
23
|
+
config.runtime[key] = value;
|
|
24
|
+
return void 0;
|
|
25
|
+
}
|
|
26
|
+
return void 0;
|
|
27
27
|
}
|
|
28
|
-
var generateAsyncEntry = function(code) {
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
export var generateAsyncEntry = function(code) {
|
|
29
|
+
var transformCode = code.replace("import('./bootstrap.js');", "if (!window.__GARFISH__) { import('./bootstrap.js'); }");
|
|
30
|
+
return "\n export const provider = async (...args) => {\n const exports = await import('./bootstrap');\n return exports.provider.apply(null, args);\n };\n ".concat(transformCode, "\n if (typeof __GARFISH_EXPORTS__ !== 'undefined') {\n __GARFISH_EXPORTS__.provider = provider;\n }\n ");
|
|
31
31
|
};
|
|
32
|
-
export { generateAsyncEntry, getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig };
|
package/dist/esm/deps/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { default2 as hoistNonReactStatics };
|
|
1
|
+
export { default as hoistNonReactStatics } from "hoist-non-react-statics";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export { default3 as Garfish, default2 as default, default4 as garfish, useModuleApp, useModuleApps };
|
|
1
|
+
export { default } from "./plugin";
|
|
2
|
+
export { useModuleApps, useModuleApp } from "./useModuleApps";
|
|
3
|
+
export { default as Garfish, default as garfish } from "garfish";
|
|
@@ -1,236 +1,252 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length)
|
|
3
|
+
len = arr.length;
|
|
4
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
5
|
+
arr2[i] = arr[i];
|
|
6
|
+
return arr2;
|
|
5
7
|
}
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
+
function _array_with_holes(arr) {
|
|
9
|
+
if (Array.isArray(arr))
|
|
10
|
+
return arr;
|
|
8
11
|
}
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
function _define_property(obj, key, value) {
|
|
13
|
+
if (key in obj) {
|
|
14
|
+
Object.defineProperty(obj, key, {
|
|
15
|
+
value,
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true
|
|
19
|
+
});
|
|
20
|
+
} else {
|
|
21
|
+
obj[key] = value;
|
|
22
|
+
}
|
|
23
|
+
return obj;
|
|
21
24
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
function _iterable_to_array_limit(arr, i) {
|
|
26
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
27
|
+
if (_i == null)
|
|
28
|
+
return;
|
|
29
|
+
var _arr = [];
|
|
30
|
+
var _n = true;
|
|
31
|
+
var _d = false;
|
|
32
|
+
var _s, _e;
|
|
33
|
+
try {
|
|
34
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
35
|
+
_arr.push(_s.value);
|
|
36
|
+
if (i && _arr.length === i)
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
} catch (err) {
|
|
40
|
+
_d = true;
|
|
41
|
+
_e = err;
|
|
42
|
+
} finally {
|
|
29
43
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
_d = true;
|
|
36
|
-
_e = err;
|
|
37
|
-
} finally{
|
|
38
|
-
try {
|
|
39
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
40
|
-
} finally{
|
|
41
|
-
if (_d) throw _e;
|
|
42
|
-
}
|
|
44
|
+
if (!_n && _i["return"] != null)
|
|
45
|
+
_i["return"]();
|
|
46
|
+
} finally {
|
|
47
|
+
if (_d)
|
|
48
|
+
throw _e;
|
|
43
49
|
}
|
|
44
|
-
|
|
50
|
+
}
|
|
51
|
+
return _arr;
|
|
45
52
|
}
|
|
46
|
-
function
|
|
47
|
-
|
|
53
|
+
function _non_iterable_rest() {
|
|
54
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
48
55
|
}
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
ownKeys.forEach(function(key) {
|
|
59
|
-
_defineProperty(target, key, source[key]);
|
|
60
|
-
});
|
|
56
|
+
function _object_spread(target) {
|
|
57
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
58
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
59
|
+
var ownKeys2 = Object.keys(source);
|
|
60
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
61
|
+
ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
62
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
63
|
+
}));
|
|
61
64
|
}
|
|
62
|
-
|
|
65
|
+
ownKeys2.forEach(function(key) {
|
|
66
|
+
_define_property(target, key, source[key]);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return target;
|
|
63
70
|
}
|
|
64
71
|
function ownKeys(object, enumerableOnly) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
keys.push.apply(keys, symbols);
|
|
72
|
+
var keys = Object.keys(object);
|
|
73
|
+
if (Object.getOwnPropertySymbols) {
|
|
74
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
75
|
+
if (enumerableOnly) {
|
|
76
|
+
symbols = symbols.filter(function(sym) {
|
|
77
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
78
|
+
});
|
|
74
79
|
}
|
|
75
|
-
|
|
80
|
+
keys.push.apply(keys, symbols);
|
|
81
|
+
}
|
|
82
|
+
return keys;
|
|
76
83
|
}
|
|
77
|
-
function
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
function _object_spread_props(target, source) {
|
|
85
|
+
source = source != null ? source : {};
|
|
86
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
87
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
88
|
+
} else {
|
|
89
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
90
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return target;
|
|
87
94
|
}
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
function _object_without_properties(source, excluded) {
|
|
96
|
+
if (source == null)
|
|
97
|
+
return {};
|
|
98
|
+
var target = _object_without_properties_loose(source, excluded);
|
|
99
|
+
var key, i;
|
|
100
|
+
if (Object.getOwnPropertySymbols) {
|
|
101
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
102
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
103
|
+
key = sourceSymbolKeys[i];
|
|
104
|
+
if (excluded.indexOf(key) >= 0)
|
|
105
|
+
continue;
|
|
106
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key))
|
|
107
|
+
continue;
|
|
108
|
+
target[key] = source[key];
|
|
100
109
|
}
|
|
101
|
-
|
|
110
|
+
}
|
|
111
|
+
return target;
|
|
102
112
|
}
|
|
103
|
-
function
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
function _object_without_properties_loose(source, excluded) {
|
|
114
|
+
if (source == null)
|
|
115
|
+
return {};
|
|
116
|
+
var target = {};
|
|
117
|
+
var sourceKeys = Object.keys(source);
|
|
118
|
+
var key, i;
|
|
119
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
120
|
+
key = sourceKeys[i];
|
|
121
|
+
if (excluded.indexOf(key) >= 0)
|
|
122
|
+
continue;
|
|
123
|
+
target[key] = source[key];
|
|
124
|
+
}
|
|
125
|
+
return target;
|
|
114
126
|
}
|
|
115
|
-
function
|
|
116
|
-
|
|
127
|
+
function _sliced_to_array(arr, i) {
|
|
128
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
117
129
|
}
|
|
118
|
-
function
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
130
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
131
|
+
if (!o)
|
|
132
|
+
return;
|
|
133
|
+
if (typeof o === "string")
|
|
134
|
+
return _array_like_to_array(o, minLen);
|
|
135
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
136
|
+
if (n === "Object" && o.constructor)
|
|
137
|
+
n = o.constructor.name;
|
|
138
|
+
if (n === "Map" || n === "Set")
|
|
139
|
+
return Array.from(n);
|
|
140
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
141
|
+
return _array_like_to_array(o, minLen);
|
|
125
142
|
}
|
|
126
|
-
import {
|
|
143
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
127
144
|
import { useState, useEffect, useCallback } from "react";
|
|
128
145
|
import { logger } from "../util";
|
|
129
146
|
var DEFAULT_LOADABLE = {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
147
|
+
delay: 200,
|
|
148
|
+
timeout: 1e4,
|
|
149
|
+
loading: null
|
|
133
150
|
};
|
|
134
|
-
function Loadable(WrapComponent) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
});
|
|
167
|
-
}, timeout);
|
|
168
|
-
}
|
|
169
|
-
return initState;
|
|
170
|
-
}), 2), state = _useState[0], setState = _useState[1];
|
|
171
|
-
var LoadingComponent = (_props_loadable = props.loadable) === null || _props_loadable === void 0 ? void 0 : _props_loadable.loading;
|
|
172
|
-
useEffect(function() {
|
|
173
|
-
logger("Loadable render state", {
|
|
174
|
-
state: state,
|
|
175
|
-
props: otherProps,
|
|
176
|
-
loadable: loadable,
|
|
177
|
-
defaultLoadable: defaultLoadable
|
|
178
|
-
});
|
|
179
|
-
return function() {
|
|
180
|
-
setStateWithMountCheck({
|
|
181
|
-
isLoading: false,
|
|
182
|
-
error: null
|
|
183
|
-
});
|
|
184
|
-
if (delayTimer) {
|
|
185
|
-
clearTimeout(delayTimer);
|
|
186
|
-
delayTimer = null;
|
|
187
|
-
}
|
|
188
|
-
if (timeoutTimer) {
|
|
189
|
-
clearTimeout(timeoutTimer);
|
|
190
|
-
timeoutTimer = null;
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
}, []);
|
|
194
|
-
var retry = useCallback(function() {
|
|
195
|
-
setState(_objectSpreadProps(_objectSpread({}, state), {
|
|
196
|
-
error: null,
|
|
197
|
-
isLoading: true,
|
|
198
|
-
timedOut: false
|
|
199
|
-
}));
|
|
200
|
-
}, [
|
|
201
|
-
state
|
|
202
|
-
]);
|
|
203
|
-
var setStateWithMountCheck = useCallback(function(newState) {
|
|
204
|
-
setState(function(state2) {
|
|
205
|
-
return _objectSpread({}, state2, newState);
|
|
206
|
-
});
|
|
207
|
-
}, [
|
|
208
|
-
state
|
|
209
|
-
]);
|
|
210
|
-
var showLoading = (state.isLoading || state.error) && LoadingComponent;
|
|
211
|
-
return /* @__PURE__ */ jsxs(Fragment, {
|
|
212
|
-
children: [
|
|
213
|
-
showLoading && /* @__PURE__ */ jsx(LoadingComponent, {
|
|
214
|
-
isLoading: state.isLoading,
|
|
215
|
-
pastDelay: state.pastDelay,
|
|
216
|
-
timedOut: state.timedOut,
|
|
217
|
-
error: state === null || state === void 0 ? void 0 : state.error,
|
|
218
|
-
retry: retry
|
|
219
|
-
}),
|
|
220
|
-
/* @__PURE__ */ jsx(WrapComponent, _objectSpread({
|
|
221
|
-
style: {
|
|
222
|
-
display: showLoading ? "none" : "block"
|
|
223
|
-
},
|
|
224
|
-
setLoadingState: function(props2) {
|
|
225
|
-
if (props2.error && !LoadingComponent) {
|
|
226
|
-
throw props2.error;
|
|
227
|
-
}
|
|
228
|
-
setStateWithMountCheck(props2);
|
|
229
|
-
}
|
|
230
|
-
}, otherProps))
|
|
231
|
-
]
|
|
151
|
+
export function Loadable(WrapComponent) {
|
|
152
|
+
return function(defaultLoadable) {
|
|
153
|
+
return function Lodable(props) {
|
|
154
|
+
var _props_loadable;
|
|
155
|
+
var _props_loadable1 = props.loadable, loadable = _props_loadable1 === void 0 ? defaultLoadable !== null && defaultLoadable !== void 0 ? defaultLoadable : DEFAULT_LOADABLE : _props_loadable1, otherProps = _object_without_properties(props, [
|
|
156
|
+
"loadable"
|
|
157
|
+
]);
|
|
158
|
+
var delayTimer = null;
|
|
159
|
+
var timeoutTimer = null;
|
|
160
|
+
var _useState = _sliced_to_array(useState(function() {
|
|
161
|
+
var delay = loadable.delay, timeout = loadable.timeout;
|
|
162
|
+
var initState = {
|
|
163
|
+
error: null,
|
|
164
|
+
pastDelay: false,
|
|
165
|
+
timedOut: false,
|
|
166
|
+
isLoading: false
|
|
167
|
+
};
|
|
168
|
+
if (typeof delay === "number") {
|
|
169
|
+
if (delay === 0) {
|
|
170
|
+
initState.pastDelay = true;
|
|
171
|
+
} else {
|
|
172
|
+
delayTimer = setTimeout(function() {
|
|
173
|
+
setStateWithMountCheck({
|
|
174
|
+
pastDelay: true
|
|
175
|
+
});
|
|
176
|
+
}, delay);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (typeof timeout === "number") {
|
|
180
|
+
timeoutTimer = setTimeout(function() {
|
|
181
|
+
setStateWithMountCheck({
|
|
182
|
+
timedOut: true
|
|
232
183
|
});
|
|
184
|
+
}, timeout);
|
|
185
|
+
}
|
|
186
|
+
return initState;
|
|
187
|
+
}), 2), state = _useState[0], setState = _useState[1];
|
|
188
|
+
var LoadingComponent = (_props_loadable = props.loadable) === null || _props_loadable === void 0 ? void 0 : _props_loadable.loading;
|
|
189
|
+
useEffect(function() {
|
|
190
|
+
logger("Loadable render state", {
|
|
191
|
+
state,
|
|
192
|
+
props: otherProps,
|
|
193
|
+
loadable,
|
|
194
|
+
defaultLoadable
|
|
195
|
+
});
|
|
196
|
+
return function() {
|
|
197
|
+
setStateWithMountCheck({
|
|
198
|
+
isLoading: false,
|
|
199
|
+
error: null
|
|
200
|
+
});
|
|
201
|
+
if (delayTimer) {
|
|
202
|
+
clearTimeout(delayTimer);
|
|
203
|
+
delayTimer = null;
|
|
204
|
+
}
|
|
205
|
+
if (timeoutTimer) {
|
|
206
|
+
clearTimeout(timeoutTimer);
|
|
207
|
+
timeoutTimer = null;
|
|
208
|
+
}
|
|
233
209
|
};
|
|
210
|
+
}, []);
|
|
211
|
+
var retry = useCallback(function() {
|
|
212
|
+
setState(_object_spread_props(_object_spread({}, state), {
|
|
213
|
+
error: null,
|
|
214
|
+
isLoading: true,
|
|
215
|
+
timedOut: false
|
|
216
|
+
}));
|
|
217
|
+
}, [
|
|
218
|
+
state
|
|
219
|
+
]);
|
|
220
|
+
var setStateWithMountCheck = useCallback(function(newState) {
|
|
221
|
+
setState(function(state2) {
|
|
222
|
+
return _object_spread({}, state2, newState);
|
|
223
|
+
});
|
|
224
|
+
}, [
|
|
225
|
+
state
|
|
226
|
+
]);
|
|
227
|
+
var showLoading = (state.isLoading || state.error) && LoadingComponent;
|
|
228
|
+
return /* @__PURE__ */ _jsxs(_Fragment, {
|
|
229
|
+
children: [
|
|
230
|
+
showLoading && /* @__PURE__ */ _jsx(LoadingComponent, {
|
|
231
|
+
isLoading: state.isLoading,
|
|
232
|
+
pastDelay: state.pastDelay,
|
|
233
|
+
timedOut: state.timedOut,
|
|
234
|
+
error: state === null || state === void 0 ? void 0 : state.error,
|
|
235
|
+
retry
|
|
236
|
+
}),
|
|
237
|
+
/* @__PURE__ */ _jsx(WrapComponent, _object_spread({
|
|
238
|
+
style: {
|
|
239
|
+
display: showLoading ? "none" : "block"
|
|
240
|
+
},
|
|
241
|
+
setLoadingState: function(props2) {
|
|
242
|
+
if (props2.error && !LoadingComponent) {
|
|
243
|
+
throw props2.error;
|
|
244
|
+
}
|
|
245
|
+
setStateWithMountCheck(props2);
|
|
246
|
+
}
|
|
247
|
+
}, otherProps))
|
|
248
|
+
]
|
|
249
|
+
});
|
|
234
250
|
};
|
|
251
|
+
};
|
|
235
252
|
}
|
|
236
|
-
export { Loadable };
|