@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.
Files changed (41) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/cli/index.js +224 -236
  3. package/dist/cjs/cli/utils.js +24 -48
  4. package/dist/cjs/deps/index.js +12 -35
  5. package/dist/cjs/index.js +26 -36
  6. package/dist/cjs/runtime/index.js +24 -44
  7. package/dist/cjs/runtime/loadable.js +46 -58
  8. package/dist/cjs/runtime/plugin.js +86 -82
  9. package/dist/cjs/runtime/useModuleApps.js +70 -56
  10. package/dist/cjs/runtime/utils/Context.js +18 -36
  11. package/dist/cjs/runtime/utils/MApp.js +88 -87
  12. package/dist/cjs/runtime/utils/apps.js +114 -94
  13. package/dist/cjs/runtime/utils/setExternal.js +23 -41
  14. package/dist/cjs/util.js +21 -40
  15. package/dist/esm/cli/index.js +409 -402
  16. package/dist/esm/cli/utils.js +25 -26
  17. package/dist/esm/deps/index.js +1 -2
  18. package/dist/esm/index.js +1 -2
  19. package/dist/esm/runtime/index.js +3 -4
  20. package/dist/esm/runtime/loadable.js +226 -210
  21. package/dist/esm/runtime/plugin.js +456 -426
  22. package/dist/esm/runtime/useModuleApps.js +49 -50
  23. package/dist/esm/runtime/utils/Context.js +1 -1
  24. package/dist/esm/runtime/utils/MApp.js +337 -316
  25. package/dist/esm/runtime/utils/apps.js +468 -442
  26. package/dist/esm/runtime/utils/setExternal.js +9 -9
  27. package/dist/esm/util.js +4 -5
  28. package/dist/esm-node/cli/index.js +209 -219
  29. package/dist/esm-node/cli/utils.js +15 -30
  30. package/dist/esm-node/deps/index.js +1 -4
  31. package/dist/esm-node/index.js +1 -4
  32. package/dist/esm-node/runtime/index.js +3 -10
  33. package/dist/esm-node/runtime/loadable.js +34 -31
  34. package/dist/esm-node/runtime/plugin.js +50 -33
  35. package/dist/esm-node/runtime/useModuleApps.js +12 -19
  36. package/dist/esm-node/runtime/utils/Context.js +2 -5
  37. package/dist/esm-node/runtime/utils/MApp.js +61 -40
  38. package/dist/esm-node/runtime/utils/apps.js +38 -44
  39. package/dist/esm-node/runtime/utils/setExternal.js +5 -5
  40. package/dist/esm-node/util.js +4 -9
  41. package/package.json +15 -11
@@ -1,32 +1,31 @@
1
- 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";
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
- 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");
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
- 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) || {};
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
- 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;
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
- 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 ");
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 };
@@ -1,2 +1 @@
1
- import { default as default2 } from "hoist-non-react-statics";
2
- export { default2 as hoistNonReactStatics };
1
+ export { default as hoistNonReactStatics } from "hoist-non-react-statics";
package/dist/esm/index.js CHANGED
@@ -1,3 +1,2 @@
1
- import { default as default2 } from "./runtime";
1
+ export { default } from "./runtime";
2
2
  export * from "./runtime";
3
- export { default2 as default };
@@ -1,4 +1,3 @@
1
- import { default as default2 } from "./plugin";
2
- import { useModuleApps, useModuleApp } from "./useModuleApps";
3
- import { default as default3, default as default4 } from "garfish";
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 _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;
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 _arrayWithHoles(arr) {
7
- if (Array.isArray(arr)) return arr;
8
+ function _array_with_holes(arr) {
9
+ if (Array.isArray(arr))
10
+ return arr;
8
11
  }
9
- function _defineProperty(obj, key, value) {
10
- if (key in obj) {
11
- Object.defineProperty(obj, key, {
12
- value: value,
13
- enumerable: true,
14
- configurable: true,
15
- writable: true
16
- });
17
- } else {
18
- obj[key] = value;
19
- }
20
- return obj;
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 _iterableToArrayLimit(arr, i) {
23
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
24
- if (_i == null) return;
25
- var _arr = [];
26
- var _n = true;
27
- var _d = false;
28
- var _s, _e;
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
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
31
- _arr.push(_s.value);
32
- if (i && _arr.length === i) break;
33
- }
34
- } catch (err) {
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
- return _arr;
50
+ }
51
+ return _arr;
45
52
  }
46
- function _nonIterableRest() {
47
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
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 _objectSpread(target) {
50
- for(var i = 1; i < arguments.length; i++){
51
- var source = arguments[i] != null ? arguments[i] : {};
52
- var ownKeys = Object.keys(source);
53
- if (typeof Object.getOwnPropertySymbols === "function") {
54
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
55
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
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
- return target;
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
- var keys = Object.keys(object);
66
- if (Object.getOwnPropertySymbols) {
67
- var symbols = Object.getOwnPropertySymbols(object);
68
- if (enumerableOnly) {
69
- symbols = symbols.filter(function(sym) {
70
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
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
- return keys;
80
+ keys.push.apply(keys, symbols);
81
+ }
82
+ return keys;
76
83
  }
77
- function _objectSpreadProps(target, source) {
78
- source = source != null ? source : {};
79
- if (Object.getOwnPropertyDescriptors) {
80
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
81
- } else {
82
- ownKeys(Object(source)).forEach(function(key) {
83
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
84
- });
85
- }
86
- return target;
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 _objectWithoutProperties(source, excluded) {
89
- if (source == null) return {};
90
- var target = _objectWithoutPropertiesLoose(source, excluded);
91
- var key, i;
92
- if (Object.getOwnPropertySymbols) {
93
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
94
- for(i = 0; i < sourceSymbolKeys.length; i++){
95
- key = sourceSymbolKeys[i];
96
- if (excluded.indexOf(key) >= 0) continue;
97
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
98
- target[key] = source[key];
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
- return target;
110
+ }
111
+ return target;
102
112
  }
103
- function _objectWithoutPropertiesLoose(source, excluded) {
104
- if (source == null) return {};
105
- var target = {};
106
- var sourceKeys = Object.keys(source);
107
- var key, i;
108
- for(i = 0; i < sourceKeys.length; i++){
109
- key = sourceKeys[i];
110
- if (excluded.indexOf(key) >= 0) continue;
111
- target[key] = source[key];
112
- }
113
- return target;
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 _slicedToArray(arr, i) {
116
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
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 _unsupportedIterableToArray(o, minLen) {
119
- if (!o) return;
120
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
121
- var n = Object.prototype.toString.call(o).slice(8, -1);
122
- if (n === "Object" && o.constructor) n = o.constructor.name;
123
- if (n === "Map" || n === "Set") return Array.from(n);
124
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
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 { Fragment, jsx, jsxs } from "react/jsx-runtime";
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
- delay: 200,
131
- timeout: 1e4,
132
- loading: null
147
+ delay: 200,
148
+ timeout: 1e4,
149
+ loading: null
133
150
  };
134
- function Loadable(WrapComponent) {
135
- return function(defaultLoadable) {
136
- return function Lodable(props) {
137
- var _props_loadable;
138
- var _props_loadable1 = props.loadable, loadable = _props_loadable1 === void 0 ? defaultLoadable !== null && defaultLoadable !== void 0 ? defaultLoadable : DEFAULT_LOADABLE : _props_loadable1, otherProps = _objectWithoutProperties(props, [
139
- "loadable"
140
- ]);
141
- var delayTimer = null;
142
- var timeoutTimer = null;
143
- var _useState = _slicedToArray(useState(function() {
144
- var delay = loadable.delay, timeout = loadable.timeout;
145
- var initState = {
146
- error: null,
147
- pastDelay: false,
148
- timedOut: false,
149
- isLoading: false
150
- };
151
- if (typeof delay === "number") {
152
- if (delay === 0) {
153
- initState.pastDelay = true;
154
- } else {
155
- delayTimer = setTimeout(function() {
156
- setStateWithMountCheck({
157
- pastDelay: true
158
- });
159
- }, delay);
160
- }
161
- }
162
- if (typeof timeout === "number") {
163
- timeoutTimer = setTimeout(function() {
164
- setStateWithMountCheck({
165
- timedOut: true
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 };