@umijs/plugins 4.0.0-beta.9 → 4.0.0-canary-20240513.3

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 (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -1
  3. package/dist/access.js +194 -4
  4. package/dist/analytics.d.ts +3 -0
  5. package/dist/analytics.js +118 -0
  6. package/dist/antd.js +345 -158
  7. package/dist/confetti.js +64 -0
  8. package/dist/constants.d.ts +1 -0
  9. package/dist/constants.js +30 -0
  10. package/dist/dva.d.ts +3 -0
  11. package/dist/dva.js +302 -8
  12. package/dist/initial-state.js +147 -4
  13. package/dist/layout.js +754 -4
  14. package/dist/locale.d.ts +1 -0
  15. package/dist/locale.js +257 -4
  16. package/dist/mf.d.ts +2 -0
  17. package/dist/mf.js +358 -0
  18. package/dist/model.js +109 -4
  19. package/dist/moment2dayjs.js +125 -0
  20. package/dist/qiankun/constants.d.ts +5 -0
  21. package/dist/qiankun/constants.js +41 -0
  22. package/dist/qiankun/master.d.ts +6 -0
  23. package/dist/qiankun/master.js +236 -0
  24. package/dist/qiankun/slave.d.ts +3 -0
  25. package/dist/qiankun/slave.js +345 -0
  26. package/dist/qiankun.js +51 -4
  27. package/dist/react-query.d.ts +3 -0
  28. package/dist/react-query.js +193 -0
  29. package/dist/request.js +384 -4
  30. package/dist/styled-components.d.ts +3 -0
  31. package/dist/styled-components.js +150 -0
  32. package/dist/tailwindcss.d.ts +3 -0
  33. package/dist/tailwindcss.js +106 -0
  34. package/dist/unocss.d.ts +3 -0
  35. package/dist/unocss.js +71 -0
  36. package/dist/utils/astUtils.d.ts +3 -0
  37. package/dist/utils/astUtils.js +49 -0
  38. package/dist/utils/localeUtils.d.ts +33 -0
  39. package/dist/utils/localeUtils.js +139 -0
  40. package/dist/utils/mfUtils.d.ts +14 -0
  41. package/dist/utils/mfUtils.js +56 -0
  42. package/dist/utils/modelUtils.d.ts +40 -0
  43. package/dist/utils/modelUtils.js +286 -0
  44. package/dist/utils/resolveProjectDep.d.ts +5 -0
  45. package/dist/utils/resolveProjectDep.js +40 -0
  46. package/dist/utils/withTmpPath.d.ts +6 -0
  47. package/dist/utils/withTmpPath.js +39 -0
  48. package/dist/valtio.d.ts +3 -0
  49. package/dist/valtio.js +81 -0
  50. package/libs/dva.tsx +45 -0
  51. package/libs/model.tsx +180 -0
  52. package/libs/qiankun/master/AntdErrorBoundary.tsx +34 -0
  53. package/libs/qiankun/master/AntdLoader.tsx +15 -0
  54. package/libs/qiankun/master/ErrorBoundary.tsx +7 -0
  55. package/libs/qiankun/master/MicroApp.tsx +327 -0
  56. package/libs/qiankun/master/MicroAppWithMemoHistory.tsx +43 -0
  57. package/libs/qiankun/master/common.ts +172 -0
  58. package/libs/qiankun/master/constants.ts +19 -0
  59. package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +45 -0
  60. package/libs/qiankun/master/masterRuntimePlugin.tsx +161 -0
  61. package/libs/qiankun/master/routeUtils.ts +26 -0
  62. package/libs/qiankun/master/types.ts +54 -0
  63. package/libs/qiankun/slave/MicroAppLink.tsx +122 -0
  64. package/libs/qiankun/slave/connectMaster.tsx +14 -0
  65. package/libs/qiankun/slave/constants.ts +5 -0
  66. package/libs/qiankun/slave/lifecycles.ts +164 -0
  67. package/libs/qiankun/slave/qiankunModel.ts +18 -0
  68. package/libs/qiankun/slave/slaveRuntimePlugin.ts +36 -0
  69. package/package.json +46 -16
  70. package/templates/antd/runtime.ts.tpl +170 -0
  71. package/templates/antd/types.d.ts.tpl +17 -0
  72. package/templates/locale/SelectLang.tpl +502 -0
  73. package/templates/locale/locale.tpl +82 -0
  74. package/templates/locale/localeExports.tpl +307 -0
  75. package/templates/locale/runtime.tpl +34 -0
  76. package/templates/mf/runtime.ts.tpl +149 -0
  77. package/dist/icons.js +0 -5
  78. package/dist/sass.js +0 -5
  79. /package/dist/{icons.d.ts → confetti.d.ts} +0 -0
  80. /package/dist/{sass.d.ts → moment2dayjs.d.ts} +0 -0
@@ -0,0 +1,82 @@
1
+ import React from 'react';
2
+ {{#Antd}}
3
+ import { ConfigProvider } from 'antd';
4
+ {{/Antd}}
5
+
6
+ {{#MomentLocales.length}}
7
+ import moment from '{{{momentPkgPath}}}';
8
+ {{#MomentLocales}}
9
+ import '{{{momentPkgPath}}}/locale/{{.}}';
10
+ {{/MomentLocales}}
11
+ {{/MomentLocales.length}}
12
+ import { RawIntlProvider, getLocale, getDirection , setIntl, getIntl, localeInfo, event, LANG_CHANGE_EVENT } from './localeExports';
13
+
14
+ {{#DefaultAntdLocales}}
15
+ import {{NormalizeAntdLocalesName}} from '{{{.}}}';
16
+ {{/DefaultAntdLocales}}
17
+
18
+
19
+
20
+ export function _onCreate() {
21
+ const locale = getLocale();
22
+ {{#MomentLocales.length}}
23
+ if (moment?.locale) {
24
+ moment.locale(localeInfo[locale]?.momentLocale || '{{{DefaultMomentLocale}}}');
25
+ }
26
+ {{/MomentLocales.length}}
27
+ setIntl(locale);
28
+ }
29
+
30
+ const useIsomorphicLayoutEffect =
31
+ typeof window !== 'undefined' &&
32
+ typeof window.document !== 'undefined' &&
33
+ typeof window.document.createElement !== 'undefined'
34
+ ? React.useLayoutEffect
35
+ : React.useEffect
36
+
37
+ export const _LocaleContainer = (props:any) => {
38
+ const initLocale = getLocale();
39
+ const [locale, setLocale] = React.useState(initLocale);
40
+ const [intl, setContainerIntl] = React.useState(() => getIntl(locale, true));
41
+
42
+ const handleLangChange = (locale:string) => {
43
+ {{#MomentLocales.length}}
44
+ if (moment?.locale) {
45
+ moment.locale(localeInfo[locale]?.momentLocale || 'en');
46
+ }
47
+ {{/MomentLocales.length}}
48
+ setLocale(locale);
49
+ setContainerIntl(getIntl(locale));
50
+ };
51
+
52
+ useIsomorphicLayoutEffect(() => {
53
+ event.on(LANG_CHANGE_EVENT, handleLangChange);
54
+ {{#Title}}
55
+ // avoid reset route title
56
+ if (typeof document !== 'undefined' && intl.messages['{{.}}']) {
57
+ document.title = intl.formatMessage({ id: '{{.}}' });
58
+ }
59
+ {{/Title}}
60
+ return () => {
61
+ event.off(LANG_CHANGE_EVENT, handleLangChange);
62
+ };
63
+ }, []);
64
+
65
+ {{#Antd}}
66
+ const defaultAntdLocale = {
67
+ {{#DefaultAntdLocales}}
68
+ ...{{NormalizeAntdLocalesName}},
69
+ {{/DefaultAntdLocales}}
70
+ }
71
+ const direction = getDirection();
72
+
73
+ return (
74
+ <ConfigProvider direction={direction} locale={localeInfo[locale]?.antd || defaultAntdLocale}>
75
+ <RawIntlProvider value={intl}>{props.children}</RawIntlProvider>
76
+ </ConfigProvider>
77
+ )
78
+ {{/Antd}}
79
+ {{^Antd}}
80
+ return <RawIntlProvider value={intl}>{props.children}</RawIntlProvider>;
81
+ {{/Antd}}
82
+ };
@@ -0,0 +1,307 @@
1
+ import {
2
+ createIntl,
3
+ IntlShape,
4
+ MessageDescriptor,
5
+ } from '{{{ reactIntlPkgPath }}}';
6
+ import { getPluginManager } from '../core/plugin';
7
+ import EventEmitter from '{{{EventEmitterPkg}}}';
8
+ // @ts-ignore
9
+ import warning from '{{{ warningPkgPath }}}';
10
+
11
+ export {
12
+ createIntl,
13
+ };
14
+ export {
15
+ FormattedDate,
16
+ FormattedDateParts,
17
+ FormattedDisplayName,
18
+ FormattedHTMLMessage,
19
+ FormattedList,
20
+ FormattedMessage,
21
+ FormattedNumber,
22
+ FormattedNumberParts,
23
+ FormattedPlural,
24
+ FormattedRelativeTime,
25
+ FormattedTime,
26
+ FormattedTimeParts,
27
+ IntlContext,
28
+ IntlProvider,
29
+ RawIntlProvider,
30
+ createIntlCache,
31
+ defineMessages,
32
+ injectIntl,
33
+ useIntl,
34
+ } from '{{{ reactIntlPkgPath }}}';
35
+
36
+ let g_intl: IntlShape;
37
+
38
+ const useLocalStorage = {{{UseLocalStorage}}};
39
+
40
+ // @ts-ignore
41
+ export const event = new EventEmitter();
42
+
43
+ export const LANG_CHANGE_EVENT = Symbol('LANG_CHANGE');
44
+
45
+ {{#LocaleList}}
46
+ {{#antdLocale}}
47
+ import {{lang}}{{country}}{{index}} from '{{{locale}}}';
48
+ {{/antdLocale}}
49
+ {{#paths}}
50
+ import lang_{{lang}}{{country}}{{index}} from "{{{path}}}";
51
+ {{/paths}}
52
+ {{/LocaleList}}
53
+
54
+ const flattenMessages=(
55
+ nestedMessages: Record<string, any>,
56
+ prefix = '',
57
+ ) => {
58
+ return Object.keys(nestedMessages).reduce(
59
+ (messages: Record<string, any>, key) => {
60
+ const value = nestedMessages[key];
61
+ const prefixedKey = prefix ? `${prefix}.${key}` : key;
62
+ if (typeof value === 'string') {
63
+ messages[prefixedKey] = value;
64
+ } else {
65
+ Object.assign(messages, flattenMessages(value, prefixedKey));
66
+ }
67
+ return messages;
68
+ },
69
+ {},
70
+ );
71
+ }
72
+
73
+ export const localeInfo: {[key: string]: any} = {
74
+ {{#LocaleList}}
75
+ '{{name}}': {
76
+ messages: {
77
+ {{#paths}}...flattenMessages(lang_{{lang}}{{country}}{{index}}),{{/paths}}
78
+ },
79
+ locale: '{{locale}}',
80
+ {{#Antd}}antd: {
81
+ {{#antdLocale}}
82
+ ...{{lang}}{{country}}{{index}},
83
+ {{/antdLocale}}
84
+ },{{/Antd}}
85
+ momentLocale: '{{momentLocale}}',
86
+ },
87
+ {{/LocaleList}}
88
+ };
89
+
90
+ /**
91
+ * 增加一个新的国际化语言
92
+ * @param name 语言的 key
93
+ * @param messages 对应的枚举对象
94
+ * @param extraLocales momentLocale, antd 国际化
95
+ */
96
+ export const addLocale = (
97
+ name: string,
98
+ messages: Object,
99
+ extraLocales: {
100
+ momentLocale:string;
101
+ antd: import('antd/es/locale').Locale
102
+ },
103
+ ) => {
104
+ if (!name) {
105
+ return;
106
+ }
107
+ // 可以合并
108
+ const mergeMessages = localeInfo[name]?.messages
109
+ ? Object.assign({}, localeInfo[name].messages, messages)
110
+ : messages;
111
+
112
+ // 用户只是追加 messages 时,extraLocales 可选
113
+ const { momentLocale = localeInfo[name]?.momentLocale, antd = localeInfo[name]?.antd } = extraLocales || {};
114
+ const locale = name.split('{{BaseSeparator}}')?.join('-')
115
+ localeInfo[name] = {
116
+ messages: mergeMessages,
117
+ locale,
118
+ momentLocale: momentLocale,
119
+ {{#Antd}}antd,{{/Antd}}
120
+ };
121
+ // 如果这是的 name 和当前的locale 相同需要重新设置一下,不然更新不了
122
+ if (locale === getLocale()) {
123
+ event.emit(LANG_CHANGE_EVENT, locale);
124
+ }
125
+ };
126
+
127
+ const applyRuntimeLocalePlugin = (initialValue: any) => {
128
+ return getPluginManager().applyPlugins({
129
+ key: 'locale',
130
+ type: 'modify',
131
+ initialValue
132
+ });
133
+ }
134
+
135
+ const _createIntl = (locale: string) => {
136
+ const runtimeLocale = applyRuntimeLocalePlugin(localeInfo[locale]);
137
+ const { cache, ...config } = runtimeLocale;
138
+ return createIntl(config, cache);
139
+ }
140
+
141
+ /**
142
+ * 获取当前的 intl 对象,可以在 node 中使用
143
+ * @param locale 需要切换的语言类型
144
+ * @param changeIntl 是否不使用 g_intl
145
+ * @returns IntlShape
146
+ */
147
+ export const getIntl = (locale?: string, changeIntl?: boolean) => {
148
+ // 如果全局的 g_intl 存在,且不是 setIntl 调用
149
+ if (g_intl && !changeIntl && !locale) {
150
+ return g_intl;
151
+ }
152
+ // 获取当前 locale
153
+ if (!locale) locale = getLocale();
154
+ // 如果存在于 localeInfo 中
155
+ if (locale&&localeInfo[locale]) {
156
+ return _createIntl(locale);
157
+ }
158
+ {{#ExistLocaleDir}}
159
+ // 不存在需要一个报错提醒
160
+ warning(
161
+ !locale||!!localeInfo[locale],
162
+ `The current popular language does not exist, please check the {{{LocaleDir}}} folder!`,
163
+ );
164
+ {{/ExistLocaleDir}}
165
+ // 使用 zh-CN
166
+ if (localeInfo[{{{ DefaultLocale }}}]) {
167
+ return _createIntl({{{ DefaultLocale }}});
168
+ }
169
+
170
+ // 如果还没有,返回一个空的
171
+ return createIntl({
172
+ locale: {{{ DefaultLocale }}},
173
+ messages: {}
174
+ });
175
+ };
176
+
177
+ /**
178
+ * 切换全局的 intl 的设置
179
+ * @param locale 语言的key
180
+ */
181
+ export const setIntl = (locale: string) => {
182
+ g_intl = getIntl(locale, true);
183
+ };
184
+
185
+ /**
186
+ * 获取当前选择的语言
187
+ * @returns string
188
+ */
189
+ export const getLocale = () => {
190
+ const runtimeLocale = applyRuntimeLocalePlugin({});
191
+ // runtime getLocale for user define
192
+ if (typeof runtimeLocale?.getLocale === 'function') {
193
+ return runtimeLocale.getLocale();
194
+ }
195
+ // please clear localStorage if you change the baseSeparator config
196
+ // because changing will break the app
197
+ const lang =
198
+ navigator.cookieEnabled && typeof localStorage !== 'undefined' && useLocalStorage
199
+ ? window.localStorage.getItem('umi_locale')
200
+ : '';
201
+ // support baseNavigator, default true
202
+ let browserLang;
203
+ {{#BaseNavigator}}
204
+ const isNavigatorLanguageValid =
205
+ typeof navigator !== 'undefined' && typeof navigator.language === 'string';
206
+ browserLang = isNavigatorLanguageValid
207
+ ? navigator.language.split('-').join('{{BaseSeparator}}')
208
+ : '';
209
+ {{/BaseNavigator}}
210
+ return lang || browserLang || {{{DefaultLocale}}};
211
+ };
212
+
213
+
214
+ /**
215
+ * 获取当前选择的方向
216
+ * @returns string
217
+ */
218
+ export const getDirection = () => {
219
+ const lang = getLocale();
220
+ // array with all prefixs for rtl langueges ex: ar-EG , he-IL
221
+ const rtlLangs = ['he', 'ar', 'fa', 'ku']
222
+ const direction = rtlLangs.filter(lng => lang.startsWith(lng)).length ? 'rtl' : 'ltr';
223
+ return direction;
224
+ };
225
+
226
+ /**
227
+ * 切换语言
228
+ * @param lang 语言的 key
229
+ * @param realReload 是否刷新页面,默认刷新
230
+ * @returns string
231
+ */
232
+ export const setLocale = (lang: string, realReload: boolean = true) => {
233
+ //const { pluginManager } = useAppContext();
234
+ //const runtimeLocale = pluginManagerapplyPlugins({
235
+ // key: 'locale',
236
+ // workaround: 不使用 ApplyPluginsType.modify 是为了避免循环依赖,与 fast-refresh 一起用时会有问题
237
+ // type: 'modify',
238
+ // initialValue: {},
239
+ //});
240
+
241
+ const updater = () => {
242
+ if (getLocale() !== lang) {
243
+ if (navigator.cookieEnabled && typeof window.localStorage !== 'undefined' && useLocalStorage) {
244
+ window.localStorage.setItem('umi_locale', lang || '');
245
+ }
246
+ setIntl(lang);
247
+ if (realReload) {
248
+ window.location.reload();
249
+ } else {
250
+ event.emit(LANG_CHANGE_EVENT, lang);
251
+ // chrome 不支持这个事件。所以人肉触发一下
252
+ if (window.dispatchEvent) {
253
+ const event = new Event('languagechange');
254
+ window.dispatchEvent(event);
255
+ }
256
+ }
257
+ }
258
+ }
259
+
260
+ //if (typeof runtimeLocale?.setLocale === 'function') {
261
+ // runtimeLocale.setLocale({
262
+ // lang,
263
+ // realReload,
264
+ // updater: updater,
265
+ // });
266
+ // return;
267
+ //}
268
+
269
+ updater();
270
+ };
271
+
272
+ let firstWaring = true;
273
+
274
+ /**
275
+ * intl.formatMessage 的语法糖
276
+ * @deprecated 使用此 api 会造成切换语言的时候无法自动刷新,请使用 useIntl 或 injectIntl
277
+ * @param descriptor { id : string, defaultMessage : string }
278
+ * @param values { [key:string] : string }
279
+ * @returns string
280
+ */
281
+ export const formatMessage: IntlShape['formatMessage'] = (
282
+ descriptor: MessageDescriptor,
283
+ values: any,
284
+ ) => {
285
+ if (firstWaring) {
286
+ warning(
287
+ false,
288
+ `Using this API will cause automatic refresh when switching languages, please use useIntl or injectIntl.
289
+
290
+ 使用此 api 会造成切换语言的时候无法自动刷新,请使用 useIntl 或 injectIntl。
291
+
292
+ http://j.mp/37Fkd5Q
293
+ `,
294
+ );
295
+ firstWaring = false;
296
+ }
297
+ if (!g_intl) {
298
+ setIntl(getLocale());
299
+ }
300
+ return g_intl.formatMessage(descriptor, values);
301
+ };
302
+
303
+ /**
304
+ * 获取语言列表
305
+ * @returns string[]
306
+ */
307
+ export const getAllLocales = () => Object.keys(localeInfo);
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ // @ts-ignore
3
+ import { _LocaleContainer } from './locale';
4
+ {{#Title}}
5
+ import { getIntl, getLocale } from './localeExports';
6
+ {{/Title}}
7
+ export function i18nProvider(container: Element) {
8
+ return React.createElement(_LocaleContainer, null, container);
9
+ }
10
+
11
+ {{#Title}}
12
+ export function patchRoutes({ routes }) {
13
+ // loop all route for patch title field
14
+ const intl = getIntl(getLocale());
15
+ const traverseRoute = (routes) => {
16
+ Object.keys(routes).forEach((key) => {
17
+ const route = routes[key];
18
+ if (route.title) {
19
+ route.locale = route.title;
20
+ const newTitle = intl.messages[route.title] ? intl.formatMessage({ id: route.title }, {}) : route.title;
21
+ route.name = intl.messages[route.title] ? intl.formatMessage({ id: route.title }, {}) : route.name;
22
+ route.title = newTitle;
23
+ }
24
+ if (route.routes) {
25
+ traverseRoute(route.routes);
26
+ }
27
+ if (route.children) {
28
+ traverseRoute(route.children);
29
+ }
30
+ })
31
+ }
32
+ traverseRoute(routes);
33
+ }
34
+ {{/Title}}
@@ -0,0 +1,149 @@
1
+ import { lazy, Suspense } from 'react'
2
+ import type { Component, ReactNode } from 'react'
3
+ const remotes = {
4
+ {{{ remoteCodeString }}}
5
+ };
6
+ const scriptLoadedMap: Record<string, Promise<void> | 0 | undefined> = {};
7
+
8
+ type MFModuleImportRequest = { entry: string; remoteName: string; moduleName: string; }
9
+ type MFModuleRegisterRequest = { entry: string; remoteName: string; aliasName?:string; }
10
+
11
+ export async function rawMfImport(opts: MFModuleImportRequest) {
12
+ await loadRemoteScriptWithCache(opts.remoteName, opts.entry);
13
+ return getRemoteModule(opts.remoteName, opts.moduleName);
14
+ }
15
+
16
+ export function registerMfRemote (opts: MFModuleRegisterRequest) {
17
+ const aliasName = opts.aliasName || opts.remoteName;
18
+ if( remotes[aliasName] ){
19
+ return console.warn(`registerMfRemote: ${aliasName} is already registered as`, remotes[aliasName]);
20
+ }
21
+ remotes[aliasName] ={
22
+ ...opts,
23
+ aliasName,
24
+ }
25
+ }
26
+
27
+ export async function safeMfImport(moduleSpecifier: any, fallback: any) {
28
+ try {
29
+ const i = moduleSpecifier.indexOf('/');
30
+ if (i < 0) {
31
+ console.error(
32
+ `safeMfImport: bad Module Name ${moduleSpecifier}, should match pattern 'remote/moduleName'`,
33
+ moduleSpecifier,
34
+ );
35
+
36
+ return fallback;
37
+ }
38
+
39
+ const aliasName = moduleSpecifier.slice(0, i);
40
+ const module = moduleSpecifier.slice(i + 1);
41
+ const entry = remotes[aliasName]?.entry;
42
+ const remoteName = remotes[aliasName]?.remoteName;
43
+
44
+ if(!entry){
45
+ console.error(
46
+ `safeMfImport: bad Module Name ${moduleSpecifier}, no remote for "aliasName"`,
47
+ moduleSpecifier,
48
+ );
49
+ return fallback;
50
+ }
51
+
52
+ await loadRemoteScriptWithCache(remoteName, entry);
53
+
54
+ return getRemoteModule(remoteName, module);
55
+ } catch (e) {
56
+ console.error('safeMfImport: Module', moduleSpecifier, 'failed', e);
57
+ return fallback;
58
+ }
59
+ }
60
+
61
+ async function loadScript(url): Promise<void> {
62
+ const element = document.createElement('script');
63
+ element.src = url;
64
+ element.type = 'text/javascript';
65
+ element.async = true;
66
+
67
+ const loadScriptQ = new Promise<void>((resolve, reject) => {
68
+ element.onload = () => {
69
+ document.head.removeChild(element);
70
+ resolve();
71
+ };
72
+ element.onerror = (e) => {
73
+ document.head.removeChild(element);
74
+ reject(e);
75
+ };
76
+ });
77
+ document.head.appendChild(element);
78
+
79
+ return loadScriptQ;
80
+ }
81
+
82
+ async function getRemoteModule(remoteName:string, moduleName: string): any {
83
+ // @ts-ignore
84
+ await __webpack_init_sharing__('default');
85
+ const container = window[remoteName]; // or get the container somewhere else
86
+ // Initialize the container, it may provide shared modules
87
+ // @ts-ignore
88
+ await container.init(__webpack_share_scopes__.default);
89
+ // @ts-ignore
90
+ const factory = await window[remoteName].get(`./${moduleName}`);
91
+ return factory();
92
+ }
93
+
94
+ async function loadRemoteScriptWithCache(remoteName:string, url: string): Promise<void> {
95
+
96
+ const loadCache = scriptLoadedMap[remoteName];
97
+ let scriptLoadQ: Promise<void> | null = null;
98
+
99
+ if(loadCache === 0){
100
+ // script Already loaded
101
+ return;
102
+ } else if(loadCache) {
103
+ await loadCache
104
+ }else{
105
+ let p = loadScript(url).then(()=>{
106
+ scriptLoadedMap[remoteName] = 0;
107
+ },(e)=>{
108
+ scriptLoadedMap[remoteName] = undefined;
109
+ throw e;
110
+ });
111
+ scriptLoadedMap[remoteName] = p;
112
+ await p;
113
+ }
114
+ }
115
+
116
+ type SafeRemoteComponentOpts ={
117
+ moduleSpecifier:string;
118
+ fallbackComponent: ComponentType<any>;
119
+ loadingElement: ReactNode
120
+ }
121
+
122
+ export function safeRemoteComponent<T extends ComponentType<any>>(opts: SafeRemoteComponentOpts): T {
123
+ const Lazy = lazy<T>(()=>safeMfImport(opts.moduleSpecifier, { default: opts.fallbackComponent }));
124
+ return (props)=> (<Suspense fallback={opts.loadingElement}>
125
+ <Lazy {...props} />
126
+ </Suspense>)
127
+ }
128
+
129
+ type RawRemoteComponentOpts ={
130
+ mfConfig:{
131
+ entry:string;
132
+ remoteName: string;
133
+ moduleName: string;
134
+ };
135
+ fallbackComponent: ComponentType<any>;
136
+ loadingElement: ReactNode;
137
+ }
138
+
139
+ export function safeRemoteComponentWithMfConfig<T extends ComponentType<any>>(opts: RawRemoteComponentOpts): T {
140
+ const Lazy = lazy<T>(()=>{
141
+ return rawMfImport(opts.mfConfig)
142
+ .catch(()=>{
143
+ return { default: opts.fallbackComponent };
144
+ })
145
+ })
146
+ return (props)=> (<Suspense fallback={opts.loadingElement}>
147
+ <Lazy {...props} />
148
+ </Suspense>)
149
+ }
package/dist/icons.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = (api) => {
4
- api;
5
- };
package/dist/sass.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = (api) => {
4
- api;
5
- };
File without changes
File without changes