@modern-js/plugin-garfish 1.3.0 → 1.3.1

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/.eslintrc.js +1 -1
  2. package/CHANGELOG.md +12 -0
  3. package/dist/js/modern/cli/index.js +190 -209
  4. package/dist/js/modern/cli/utils.js +1 -6
  5. package/dist/js/modern/index.js +2 -1
  6. package/dist/js/modern/runtime/index.js +2 -1
  7. package/dist/js/modern/runtime/loadable.js +36 -19
  8. package/dist/js/modern/runtime/plugin.js +14 -17
  9. package/dist/js/modern/runtime/utils/MApp.js +7 -10
  10. package/dist/js/modern/runtime/utils/apps.js +1 -4
  11. package/dist/js/node/cli/index.js +192 -213
  12. package/dist/js/node/cli/utils.js +1 -6
  13. package/dist/js/node/index.js +18 -3
  14. package/dist/js/node/runtime/index.js +25 -12
  15. package/dist/js/node/runtime/loadable.js +36 -19
  16. package/dist/js/node/runtime/plugin.js +11 -16
  17. package/dist/js/node/runtime/utils/MApp.js +7 -10
  18. package/dist/js/node/runtime/utils/apps.js +1 -4
  19. package/dist/js/treeshaking/cli/index.js +183 -199
  20. package/dist/js/treeshaking/cli/utils.js +2 -2
  21. package/dist/js/treeshaking/index.js +2 -1
  22. package/dist/js/treeshaking/runtime/index.js +2 -1
  23. package/dist/js/treeshaking/runtime/loadable.js +39 -25
  24. package/dist/js/treeshaking/runtime/plugin.js +15 -19
  25. package/dist/js/treeshaking/runtime/utils/MApp.js +23 -31
  26. package/dist/js/treeshaking/runtime/utils/apps.js +1 -2
  27. package/dist/types/cli/index.d.ts +1 -9
  28. package/dist/types/cli/utils.d.ts +1 -1
  29. package/dist/types/index.d.ts +2 -1
  30. package/dist/types/runtime/index.d.ts +3 -1
  31. package/dist/types/runtime/loadable.d.ts +2 -8
  32. package/dist/types/runtime/plugin.d.ts +29 -3
  33. package/dist/types/runtime/useModuleApps.d.ts +7 -9
  34. package/dist/types/runtime/utils/MApp.d.ts +1 -15
  35. package/dist/types/runtime/utils/apps.d.ts +1 -1
  36. package/package.json +20 -8
  37. package/tests/cli.test.tsx +21 -43
  38. package/tests/hooks.test.tsx +1 -0
  39. package/tests/index.test.tsx +6 -3
  40. package/tsconfig.json +3 -2
  41. package/tests/__snapshots__/cli.test.tsx.snap +0 -71
package/.eslintrc.js CHANGED
@@ -3,5 +3,5 @@ module.exports = {
3
3
  parserOptions: {
4
4
  project: require.resolve('./tsconfig.json'),
5
5
  },
6
- ignorePatterns: ['type.d.ts'],
6
+ ignorePatterns: ['type.d.ts', 'tests/**/*.tsx'],
7
7
  };
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @modern-js/plugin-garfish
2
2
 
3
+ ## 1.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 53aca274: modify garfish-plugin config type
8
+ - Updated dependencies [53aca274]
9
+ - Updated dependencies [78279953]
10
+ - Updated dependencies [e116ace5]
11
+ - Updated dependencies [4d72edea]
12
+ - @modern-js/core@1.4.1
13
+ - @modern-js/utils@1.3.1
14
+
3
15
  ## 1.3.0
4
16
 
5
17
  ### Minor Changes
@@ -1,15 +1,9 @@
1
- const _excluded = ["validateSchema", "externals", "componentKey"];
2
-
3
1
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
2
 
5
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
4
 
7
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
6
 
9
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
10
-
11
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
12
-
13
7
  import path from 'path';
14
8
  import { createRuntimeExportsUtils, getEntryOptions, PLUGIN_SCHEMAS } from '@modern-js/utils';
15
9
  import { createPlugin, useAppContext, useResolvedConfigContext } from '@modern-js/core';
@@ -40,244 +34,231 @@ function setRuntimeConfig(config, key, value) {
40
34
  }
41
35
  }
42
36
 
43
- export const initializer = _ref => {
44
- let {
45
- validateSchema,
46
- externals,
47
- componentKey
48
- } = _ref,
49
- otherLifeCycle = _objectWithoutProperties(_ref, _excluded);
50
-
51
- return () => {
52
- const configMap = new Map();
53
- let pluginsExportsUtils;
54
- let runtimeExportsUtils;
55
- return _objectSpread({
56
- resolvedConfig(config) {
57
- const {
58
- resolved
59
- } = config;
60
- const {
61
- masterApp,
62
- router
63
- } = getRuntimeConfig(resolved);
64
- const nConfig = {
65
- resolved: _objectSpread({}, resolved)
66
- };
67
-
68
- if (masterApp) {
69
- // basename does not exist use router's basename
70
- setRuntimeConfig(nConfig.resolved, 'masterApp', Object.assign(typeof masterApp === 'object' ? _objectSpread({}, masterApp) : {}, {
71
- basename: (router === null || router === void 0 ? void 0 : router.basename) || '/'
72
- }));
73
- }
37
+ const externals = {
38
+ 'react-dom': 'react-dom',
39
+ react: 'react'
40
+ };
41
+ export default createPlugin(() => {
42
+ const configMap = new Map();
43
+ let pluginsExportsUtils;
44
+ let runtimeExportsUtils;
45
+ return {
46
+ resolvedConfig(config) {
47
+ const {
48
+ resolved
49
+ } = config;
50
+ const {
51
+ masterApp,
52
+ router
53
+ } = getRuntimeConfig(resolved);
54
+ const nConfig = {
55
+ resolved: _objectSpread({}, resolved)
56
+ };
57
+
58
+ if (masterApp) {
59
+ // basename does not exist use router's basename
60
+ setRuntimeConfig(nConfig.resolved, 'masterApp', Object.assign(typeof masterApp === 'object' ? _objectSpread({}, masterApp) : {}, {
61
+ basename: (router === null || router === void 0 ? void 0 : router.basename) || '/'
62
+ }));
63
+ }
74
64
 
75
- logger(`resolvedConfig`, {
76
- runtime: nConfig.resolved.runtime,
77
- deploy: nConfig.resolved.deploy,
78
- server: nConfig.resolved.server
79
- });
80
- return nConfig;
81
- },
82
-
83
- config() {
84
- // eslint-disable-next-line react-hooks/rules-of-hooks
85
- const config = useAppContext();
86
- pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'plugins');
87
- runtimeExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'index');
88
- return {
89
- source: {
90
- alias: {
91
- '@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
92
- }
93
- },
94
- tools: {
95
- webpack: (webpackConfig, {
96
- chain,
97
- webpack
98
- }) => {
99
- var _resolvedConfig$deplo;
65
+ logger(`resolvedConfig`, {
66
+ runtime: nConfig.resolved.runtime,
67
+ deploy: nConfig.resolved.deploy,
68
+ server: nConfig.resolved.server
69
+ });
70
+ return nConfig;
71
+ },
72
+
73
+ config() {
74
+ // eslint-disable-next-line react-hooks/rules-of-hooks
75
+ const config = useAppContext();
76
+ pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'plugins');
77
+ runtimeExportsUtils = createRuntimeExportsUtils(config.internalDirectory, 'index');
78
+ return {
79
+ source: {
80
+ alias: {
81
+ '@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
82
+ }
83
+ },
84
+ tools: {
85
+ webpack: (webpackConfig, {
86
+ chain,
87
+ webpack
88
+ }) => {
89
+ var _resolvedConfig$deplo, _resolveWebpackConfig;
100
90
 
101
- const env = process.env.NODE_ENV; // eslint-disable-next-line react-hooks/rules-of-hooks
91
+ const env = process.env.NODE_ENV; // eslint-disable-next-line react-hooks/rules-of-hooks
102
92
 
103
- const resolvedConfig = useResolvedConfigContext();
93
+ const resolvedConfig = useResolvedConfigContext();
104
94
 
105
- if (resolvedConfig !== null && resolvedConfig !== void 0 && (_resolvedConfig$deplo = resolvedConfig.deploy) !== null && _resolvedConfig$deplo !== void 0 && _resolvedConfig$deplo.microFrontend) {
106
- var _resolvedConfig$deplo2, _resolvedConfig$deplo3;
95
+ if (resolvedConfig !== null && resolvedConfig !== void 0 && (_resolvedConfig$deplo = resolvedConfig.deploy) !== null && _resolvedConfig$deplo !== void 0 && _resolvedConfig$deplo.microFrontend) {
96
+ var _resolvedConfig$deplo2, _resolvedConfig$deplo3;
107
97
 
108
- chain.output.libraryTarget('umd');
98
+ chain.output.libraryTarget('umd');
109
99
 
110
- if (resolvedConfig.server.port) {
111
- chain.output.publicPath(env === 'development' ? `//localhost:${resolvedConfig.server.port}/` : webpackConfig.output.publicPath);
112
- } // add comments avoid sourcemap abnormal
100
+ if (resolvedConfig.server.port) {
101
+ chain.output.publicPath(env === 'development' ? `//localhost:${resolvedConfig.server.port}/` : webpackConfig.output.publicPath);
102
+ } // add comments avoid sourcemap abnormal
113
103
 
114
104
 
115
- chain.plugin('banner').use(webpack.BannerPlugin, [{
116
- banner: 'Micro front-end'
117
- }]);
118
- const {
119
- enableHtmlEntry = true,
120
- externalBasicLibrary = true
121
- } = typeof (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$deplo2 = resolvedConfig.deploy) === null || _resolvedConfig$deplo2 === void 0 ? void 0 : _resolvedConfig$deplo2.microFrontend) === 'object' ? resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$deplo3 = resolvedConfig.deploy) === null || _resolvedConfig$deplo3 === void 0 ? void 0 : _resolvedConfig$deplo3.microFrontend : {}; // external
105
+ chain.plugin('banner').use(webpack.BannerPlugin, [{
106
+ banner: 'Micro front-end'
107
+ }]);
108
+ const {
109
+ enableHtmlEntry = true,
110
+ externalBasicLibrary = true
111
+ } = typeof (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$deplo2 = resolvedConfig.deploy) === null || _resolvedConfig$deplo2 === void 0 ? void 0 : _resolvedConfig$deplo2.microFrontend) === 'object' ? resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$deplo3 = resolvedConfig.deploy) === null || _resolvedConfig$deplo3 === void 0 ? void 0 : _resolvedConfig$deplo3.microFrontend : {}; // external
122
112
 
123
- if (externalBasicLibrary) {
124
- chain.externals(externals);
125
- } // use html mode
113
+ if (externalBasicLibrary) {
114
+ chain.externals(externals);
115
+ } // use html mode
126
116
 
127
117
 
128
- if (!enableHtmlEntry) {
129
- chain.output.filename('index.js');
130
- chain.plugins.delete('html-main');
131
- chain.optimization.runtimeChunk(false);
132
- chain.optimization.splitChunks({
133
- chunks: 'async'
134
- });
135
- }
118
+ if (!enableHtmlEntry) {
119
+ chain.output.filename('index.js');
120
+ chain.plugins.delete('html-main');
121
+ chain.optimization.runtimeChunk(false);
122
+ chain.optimization.splitChunks({
123
+ chunks: 'async'
124
+ });
136
125
  }
137
-
138
- const resolveWebpackConfig = chain.toConfig();
139
- logger('webpackConfig', {
140
- output: resolveWebpackConfig.output,
141
- externals: resolveWebpackConfig.externals,
142
- env
143
- });
144
126
  }
145
- }
146
- };
147
- },
148
127
 
149
- addRuntimeExports() {
150
- const mfPackage = path.resolve(__dirname, '../../../../');
151
- const addExportStatement = `export { default as garfish } from '${mfPackage}'`;
152
- logger('exportStatement', addExportStatement);
153
- pluginsExportsUtils.addExport(addExportStatement);
154
- runtimeExportsUtils.addExport(`export * from '${mfPackage}'`);
155
- },
156
-
157
- validateSchema,
158
-
159
- modifyEntryImports({
160
- entrypoint,
161
- imports
162
- }) {
163
- // eslint-disable-next-line react-hooks/rules-of-hooks
164
- const resolvedConfig = useResolvedConfigContext(); // support legacy config
165
-
166
- const {
167
- masterApp
168
- } = getRuntimeConfig(resolvedConfig); // eslint-disable-next-line react-hooks/rules-of-hooks
169
-
170
- const {
171
- packageName
172
- } = useAppContext();
173
- const masterAppConfig = getEntryOptions(entrypoint.entryName, masterApp, resolvedConfig.runtimeByEntries, packageName);
174
- configMap.set(entrypoint.entryName, masterAppConfig);
175
-
176
- if (masterAppConfig) {
177
- imports.push({
178
- value: '@modern-js/runtime/plugins',
179
- specifiers: [{
180
- imported: 'garfish'
181
- }]
182
- });
128
+ const resolveWebpackConfig = chain.toConfig();
129
+ logger('webpackConfig', {
130
+ output: resolveWebpackConfig.output,
131
+ externals: resolveWebpackConfig.externals,
132
+ env,
133
+ alias: (_resolveWebpackConfig = resolveWebpackConfig.resolve) === null || _resolveWebpackConfig === void 0 ? void 0 : _resolveWebpackConfig.alias
134
+ });
135
+ }
183
136
  }
184
-
137
+ };
138
+ },
139
+
140
+ addRuntimeExports() {
141
+ const mfPackage = path.resolve(__dirname, '../../../../');
142
+ const addExportStatement = `export { default as garfish } from '${mfPackage}'`;
143
+ logger('exportStatement', addExportStatement);
144
+ pluginsExportsUtils.addExport(addExportStatement);
145
+ runtimeExportsUtils.addExport(`export * from '${mfPackage}'`);
146
+ },
147
+
148
+ validateSchema() {
149
+ return PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
150
+ },
151
+
152
+ modifyEntryImports({
153
+ entrypoint,
154
+ imports
155
+ }) {
156
+ // eslint-disable-next-line react-hooks/rules-of-hooks
157
+ const resolvedConfig = useResolvedConfigContext(); // support legacy config
158
+
159
+ const {
160
+ masterApp
161
+ } = getRuntimeConfig(resolvedConfig); // eslint-disable-next-line react-hooks/rules-of-hooks
162
+
163
+ const {
164
+ packageName
165
+ } = useAppContext();
166
+ const masterAppConfig = getEntryOptions(entrypoint.entryName, masterApp, resolvedConfig.runtimeByEntries, packageName);
167
+ configMap.set(entrypoint.entryName, masterAppConfig);
168
+
169
+ if (masterAppConfig) {
185
170
  imports.push({
186
- value: 'react-dom',
171
+ value: '@modern-js/runtime/plugins',
187
172
  specifiers: [{
188
- imported: 'unmountComponentAtNode'
189
- }, {
190
- imported: 'createPortal'
173
+ imported: 'garfish'
191
174
  }]
192
175
  });
193
- return {
194
- imports,
195
- entrypoint
196
- };
197
- },
176
+ }
177
+
178
+ imports.push({
179
+ value: 'react-dom',
180
+ specifiers: [{
181
+ imported: 'unmountComponentAtNode'
182
+ }, {
183
+ imported: 'createPortal'
184
+ }]
185
+ });
186
+ return {
187
+ imports,
188
+ entrypoint
189
+ };
190
+ },
191
+
192
+ modifyEntryRuntimePlugins({
193
+ entrypoint,
194
+ plugins
195
+ }) {
196
+ const masterAppConfig = configMap.get(entrypoint.entryName);
197
+
198
+ if (masterAppConfig) {
199
+ logger('garfishPlugin options', masterAppConfig);
200
+ plugins.push({
201
+ name: 'garfish',
202
+ args: 'masterApp',
203
+ options: JSON.stringify(masterAppConfig)
204
+ });
205
+ }
198
206
 
199
- modifyEntryRuntimePlugins({
207
+ return {
200
208
  entrypoint,
201
209
  plugins
202
- }) {
203
- const masterAppConfig = configMap.get(entrypoint.entryName);
204
-
205
- if (masterAppConfig) {
206
- logger('garfishPlugin options', masterAppConfig);
207
- plugins.push({
208
- name: 'garfish',
209
- args: 'masterApp',
210
- options: JSON.stringify(masterAppConfig)
211
- });
212
- }
210
+ };
211
+ },
213
212
 
214
- return {
215
- entrypoint,
216
- plugins
217
- };
218
- },
213
+ modifyEntryRenderFunction({
214
+ entrypoint,
215
+ code
216
+ }) {
217
+ var _config$deploy;
219
218
 
220
- modifyEntryRenderFunction({
221
- entrypoint,
222
- code
223
- }) {
224
- var _config$deploy;
225
-
226
- // eslint-disable-next-line react-hooks/rules-of-hooks
227
- const config = useResolvedConfigContext();
228
-
229
- if (!(config !== null && config !== void 0 && (_config$deploy = config.deploy) !== null && _config$deploy !== void 0 && _config$deploy.microFrontend)) {
230
- return {
231
- entrypoint,
232
- code
233
- };
234
- }
219
+ // eslint-disable-next-line react-hooks/rules-of-hooks
220
+ const config = useResolvedConfigContext();
235
221
 
236
- const nCode = makeRenderFunction(code);
237
- logger('makeRenderFunction', nCode);
222
+ if (!(config !== null && config !== void 0 && (_config$deploy = config.deploy) !== null && _config$deploy !== void 0 && _config$deploy.microFrontend)) {
238
223
  return {
239
224
  entrypoint,
240
- code: nCode
225
+ code
241
226
  };
242
- },
227
+ }
243
228
 
244
- modifyEntryExport({
229
+ const nCode = makeRenderFunction(code);
230
+ logger('makeRenderFunction', nCode);
231
+ return {
245
232
  entrypoint,
246
- exportStatement
247
- }) {
248
- var _resolvedConfig$deplo4;
249
-
250
- // eslint-disable-next-line react-hooks/rules-of-hooks
251
- const resolvedConfig = useResolvedConfigContext();
252
-
253
- if (resolvedConfig !== null && resolvedConfig !== void 0 && (_resolvedConfig$deplo4 = resolvedConfig.deploy) !== null && _resolvedConfig$deplo4 !== void 0 && _resolvedConfig$deplo4.microFrontend) {
254
- const exportStatementCode = makeProvider(componentKey);
255
- logger('exportStatement', exportStatementCode);
256
- return {
257
- entrypoint,
258
- exportStatement: exportStatementCode
259
- };
260
- }
261
-
233
+ code: nCode
234
+ };
235
+ },
236
+
237
+ modifyEntryExport({
238
+ entrypoint,
239
+ exportStatement
240
+ }) {
241
+ var _resolvedConfig$deplo4;
242
+
243
+ // eslint-disable-next-line react-hooks/rules-of-hooks
244
+ const resolvedConfig = useResolvedConfigContext();
245
+
246
+ if (resolvedConfig !== null && resolvedConfig !== void 0 && (_resolvedConfig$deplo4 = resolvedConfig.deploy) !== null && _resolvedConfig$deplo4 !== void 0 && _resolvedConfig$deplo4.microFrontend) {
247
+ const exportStatementCode = makeProvider();
248
+ logger('exportStatement', exportStatementCode);
262
249
  return {
263
250
  entrypoint,
264
- exportStatement
251
+ exportStatement: exportStatementCode
265
252
  };
266
253
  }
267
254
 
268
- }, otherLifeCycle);
255
+ return {
256
+ entrypoint,
257
+ exportStatement
258
+ };
259
+ }
260
+
269
261
  };
270
- };
271
- export default createPlugin(initializer({
272
- validateSchema() {
273
- return PLUGIN_SCHEMAS['@modern-js/plugin-garfish'];
274
- },
275
-
276
- externals: {
277
- 'react-dom': 'react-dom',
278
- react: 'react'
279
- },
280
- componentKey: 'dynamicComponent'
281
- }), {
262
+ }, {
282
263
  name: '@modern-js/plugin-garfish'
283
264
  });
@@ -1,4 +1,4 @@
1
- export const makeProvider = componentKey => `
1
+ export const makeProvider = () => `
2
2
  export const provider = function ({basename, dom, ...props}) {
3
3
  return {
4
4
  render({basename, dom}) {
@@ -17,11 +17,6 @@ export const makeProvider = componentKey => `
17
17
  SubModuleComponent: (props) => {
18
18
  const SubApp = render(props, basename);
19
19
 
20
- return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);
21
- },
22
- ${componentKey}: () => {
23
- const SubApp = render(props, basename);
24
-
25
20
  return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);
26
21
  }
27
22
  }
@@ -1 +1,2 @@
1
- export { default } from "./cli";
1
+ export { default } from "./runtime";
2
+ export * from "./runtime";
@@ -1,2 +1,3 @@
1
1
  export { default } from "./plugin";
2
- export * from "./useModuleApps";
2
+ export { useModuleApps, useMicroApps, useModuleApp } from "./useModuleApps";
3
+ export { default as Garfish } from 'garfish';
@@ -1,9 +1,15 @@
1
+ const _excluded = ["loadable"];
2
+
1
3
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
4
 
3
5
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
6
 
5
7
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
8
 
9
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
10
+
11
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
12
+
7
13
  // logical reference to https://github.com/jamiebuilds/react-loadable/blob/6201c5837b212d6244c57f3748f2b1375096beeb/src/index.js
8
14
  import React from 'react';
9
15
  import { logger } from "../util";
@@ -11,14 +17,11 @@ import { jsx as _jsx } from "react/jsx-runtime";
11
17
  import { Fragment as _Fragment } from "react/jsx-runtime";
12
18
  import { jsxs as _jsxs } from "react/jsx-runtime";
13
19
  export function Loadable(WrapComponent) {
14
- return function (defaultLoadingComponent) {
20
+ return function (defaultLoadable) {
15
21
  return class LoadableComponent extends React.Component {
16
22
  constructor(...args) {
17
23
  super(...args);
18
24
  this.state = {
19
- LoadingComponent: defaultLoadingComponent,
20
- timeout: 10000,
21
- delay: 200,
22
25
  error: null,
23
26
  pastDelay: false,
24
27
  timedOut: false,
@@ -42,19 +45,16 @@ export function Loadable(WrapComponent) {
42
45
  UNSAFE_componentWillMount() {
43
46
  this.mounted = true;
44
47
  const {
45
- loadingConfig
48
+ loadable = defaultLoadable || {
49
+ delay: 200,
50
+ timeout: 10000,
51
+ loading: null
52
+ }
46
53
  } = this.props;
47
-
48
- if (loadingConfig !== null && loadingConfig !== void 0 && loadingConfig.LoadingComponent) {
49
- this.setStateWithMountCheck({
50
- LoadingComponent: loadingConfig.LoadingComponent
51
- });
52
- }
53
-
54
54
  const {
55
55
  delay,
56
56
  timeout
57
- } = this.state;
57
+ } = loadable;
58
58
 
59
59
  if (typeof delay === 'number') {
60
60
  if (delay === 0) {
@@ -93,7 +93,6 @@ export function Loadable(WrapComponent) {
93
93
  return;
94
94
  }
95
95
 
96
- logger('Loadable state', this.state);
97
96
  this.setState(newState);
98
97
  }
99
98
 
@@ -103,17 +102,35 @@ export function Loadable(WrapComponent) {
103
102
  }
104
103
 
105
104
  render() {
106
- // eslint-disable-next-line @typescript-eslint/no-shadow
107
105
  const {
108
106
  isLoading,
109
107
  error,
110
108
  pastDelay,
111
- timedOut,
112
- LoadingComponent
109
+ timedOut
113
110
  } = this.state;
111
+
112
+ const _this$props = this.props,
113
+ {
114
+ loadable = defaultLoadable || {
115
+ delay: 200,
116
+ timeout: 10000,
117
+ loading: null
118
+ }
119
+ } = _this$props,
120
+ otherProps = _objectWithoutProperties(_this$props, _excluded);
121
+
122
+ const {
123
+ loading: LoadingComponent
124
+ } = loadable;
125
+ logger('Loadable render state', {
126
+ state: this.state,
127
+ props: otherProps,
128
+ loadable,
129
+ defaultLoadable
130
+ });
114
131
  const showLoading = (isLoading || error) && LoadingComponent;
115
132
  return /*#__PURE__*/_jsxs(_Fragment, {
116
- children: [showLoading && LoadingComponent && /*#__PURE__*/_jsx(LoadingComponent, {
133
+ children: [showLoading && /*#__PURE__*/_jsx(LoadingComponent, {
117
134
  isLoading: isLoading,
118
135
  pastDelay: pastDelay,
119
136
  timedOut: timedOut,
@@ -124,7 +141,7 @@ export function Loadable(WrapComponent) {
124
141
  display: showLoading ? 'none' : 'block'
125
142
  },
126
143
  setLoadingState: props => this.setStateWithMountCheck(props)
127
- }, this.props))]
144
+ }, otherProps))]
128
145
  });
129
146
  }
130
147