@umijs/plugins 4.0.0-beta.7 → 4.0.0-rc.2

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 (58) hide show
  1. package/README.md +4 -1
  2. package/dist/access.js +73 -1
  3. package/dist/{sass.d.ts → analytics.d.ts} +0 -0
  4. package/dist/analytics.js +67 -0
  5. package/dist/antd.js +89 -144
  6. package/dist/dva.d.ts +3 -0
  7. package/dist/dva.js +168 -4
  8. package/dist/initial-state.js +112 -1
  9. package/dist/layout.js +479 -1
  10. package/dist/locale.d.ts +1 -0
  11. package/dist/locale.js +199 -1
  12. package/dist/model.js +112 -1
  13. package/dist/moment2dayjs.d.ts +3 -0
  14. package/dist/moment2dayjs.js +96 -0
  15. package/dist/qiankun/constants.d.ts +5 -0
  16. package/dist/qiankun/constants.js +8 -0
  17. package/dist/qiankun/master.d.ts +6 -0
  18. package/dist/qiankun/master.js +114 -0
  19. package/dist/qiankun/slave.d.ts +3 -0
  20. package/dist/qiankun/slave.js +141 -0
  21. package/dist/qiankun.js +15 -1
  22. package/dist/request.js +300 -1
  23. package/dist/tailwindcss.d.ts +3 -0
  24. package/dist/tailwindcss.js +38 -0
  25. package/dist/unocss.d.ts +3 -0
  26. package/dist/unocss.js +57 -0
  27. package/dist/utils/astUtils.d.ts +3 -0
  28. package/dist/utils/astUtils.js +34 -0
  29. package/dist/utils/localeUtils.d.ts +33 -0
  30. package/dist/utils/localeUtils.js +135 -0
  31. package/dist/utils/modelUtils.d.ts +35 -0
  32. package/dist/utils/modelUtils.js +145 -0
  33. package/dist/utils/resolveProjectDep.d.ts +5 -0
  34. package/dist/utils/resolveProjectDep.js +15 -0
  35. package/dist/utils/withTmpPath.d.ts +6 -0
  36. package/dist/utils/withTmpPath.js +11 -0
  37. package/libs/dva.ts +10 -0
  38. package/libs/locale/SelectLang.tpl +478 -0
  39. package/libs/locale/locale.tpl +82 -0
  40. package/libs/locale/localeExports.tpl +271 -0
  41. package/libs/locale/runtime.tpl +33 -0
  42. package/libs/model.tsx +140 -0
  43. package/libs/qiankun/master/AntdErrorBoundary.tsx +34 -0
  44. package/libs/qiankun/master/AntdLoader.tsx +15 -0
  45. package/libs/qiankun/master/ErrorBoundary.tsx +7 -0
  46. package/libs/qiankun/master/MicroApp.tsx +262 -0
  47. package/libs/qiankun/master/MicroAppWithMemoHistory.tsx +43 -0
  48. package/libs/qiankun/master/common.ts +133 -0
  49. package/libs/qiankun/master/constants.ts +7 -0
  50. package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +45 -0
  51. package/libs/qiankun/master/masterRuntimePlugin.tsx +130 -0
  52. package/libs/qiankun/master/types.ts +44 -0
  53. package/libs/qiankun/slave/connectMaster.tsx +15 -0
  54. package/libs/qiankun/slave/lifecycles.ts +149 -0
  55. package/libs/qiankun/slave/qiankunModel.ts +19 -0
  56. package/libs/qiankun/slave/slaveRuntimePlugin.ts +21 -0
  57. package/package.json +35 -19
  58. package/dist/sass.js +0 -5
@@ -0,0 +1,149 @@
1
+ // @ts-nocheck
2
+ /* eslint-disable */
3
+ import { getPluginManager } from '@@/core/plugin';
4
+ import ReactDOM from 'react-dom';
5
+ import { ApplyPluginsType } from 'umi';
6
+ import { setModelState } from './qiankunModel';
7
+
8
+ const noop = () => {};
9
+
10
+ type Defer = {
11
+ promise: Promise<any>;
12
+ resolve(value?: any): void;
13
+ };
14
+
15
+ // @ts-ignore
16
+ const defer: Defer = {};
17
+ defer.promise = new Promise((resolve) => {
18
+ defer.resolve = resolve;
19
+ });
20
+
21
+ let render = noop;
22
+ let hasMountedAtLeastOnce = false;
23
+
24
+ export default () => defer.promise;
25
+ export const clientRenderOptsStack: any[] = [];
26
+
27
+ // function normalizeHistory(
28
+ // history?: 'string' | Record<string, any>,
29
+ // base?: string,
30
+ // ) {
31
+ // let normalizedHistory: Record<string, any> = {};
32
+ // if (base) normalizedHistory.basename = base;
33
+ // if (history) {
34
+ // if (typeof history === 'string') {
35
+ // normalizedHistory.type = history;
36
+ // } else {
37
+ // normalizedHistory = history;
38
+ // }
39
+ // }
40
+ //
41
+ // return normalizedHistory;
42
+ // }
43
+
44
+ async function getSlaveRuntime() {
45
+ const config = await getPluginManager().applyPlugins({
46
+ key: 'qiankun',
47
+ type: ApplyPluginsType.modify,
48
+ initialValue: {},
49
+ async: true,
50
+ });
51
+ // 应用既是 master 又是 slave 的场景,运行时 slave 配置方式为 export const qiankun = { slave: {} }
52
+ const { slave } = config;
53
+ return slave || config;
54
+ }
55
+
56
+ export function genBootstrap(oldRender: typeof noop) {
57
+ return async (props: any) => {
58
+ const slaveRuntime = await getSlaveRuntime();
59
+ if (slaveRuntime.bootstrap) {
60
+ await slaveRuntime.bootstrap(props);
61
+ }
62
+ render = oldRender;
63
+ };
64
+ }
65
+
66
+ export function genMount(mountElementId: string) {
67
+ return async (props?: any) => {
68
+ // props 有值时说明应用是通过 lifecycle 被主应用唤醒的,而不是独立运行时自己 mount
69
+ if (typeof props !== 'undefined') {
70
+ setModelState(props);
71
+
72
+ const slaveRuntime = await getSlaveRuntime();
73
+ if (slaveRuntime.mount) {
74
+ await slaveRuntime.mount(props);
75
+ }
76
+
77
+ // 更新 clientRender 配置
78
+ const clientRenderOpts = {
79
+ // 默认开启
80
+ // 如果需要手动控制 loading,通过主应用配置 props.autoSetLoading false 可以关闭
81
+ callback: () => {
82
+ if (
83
+ props?.autoSetLoading &&
84
+ typeof props?.setLoading === 'function'
85
+ ) {
86
+ props.setLoading(false);
87
+ }
88
+
89
+ // // 支持将子应用的 history 回传给父应用
90
+ // if (typeof props?.onHistoryInit === 'function') {
91
+ // props.onHistoryInit(history);
92
+ // }
93
+ },
94
+ // 支持通过 props 注入 container 来限定子应用 mountElementId 的查找范围
95
+ // 避免多个子应用出现在同一主应用时出现 mount 冲突
96
+ rootElement:
97
+ props?.container?.querySelector(`#${mountElementId}`) ||
98
+ mountElementId,
99
+
100
+ // 当存在同一个 umi 子应用在同一个页面被多实例渲染的场景时(比如一个页面里,同时展示了这个子应用的多个路由页面)
101
+ // mount 钩子会被调用多次,但是具体什么时候对应的实例开始 render 则是不定的,即它调用 applyPlugins('modifyClientRenderOpts') 的时机是不确定的
102
+ // 为了保证每次 applyPlugins('modifyClientRenderOpts') 调用是生成正确的 history,我们需要这里通过闭包上下文维持 mount 调用时的一些配置信息
103
+ // FIXME 由于 umi history 是全局的,通过 import { history } from 'umi' 调用的永远都是最后一个调用 createHistory 产生的对象,所以这种场景下会存在子应用内部获取 history 时,获取到的是同一个 history 的问题。这种场景下就不能直接从 umi import history,而应该从组件的 props 中取
104
+ // getHistory() {
105
+ // // 动态改变 history
106
+ // const historyOptions = normalizeHistory(props.history, props.base);
107
+ // setCreateHistoryOptions(historyOptions);
108
+ //
109
+ // // FIXME 子应用嵌入模式下不支持热更
110
+ // return createHistory();
111
+ // },
112
+ };
113
+
114
+ clientRenderOptsStack.push(clientRenderOpts);
115
+ }
116
+
117
+ // 第一次 mount defer 被 resolve 后umi 会自动触发 render,非第一次 mount 则需手动触发
118
+ if (hasMountedAtLeastOnce) {
119
+ render();
120
+ } else {
121
+ defer.resolve();
122
+ }
123
+
124
+ hasMountedAtLeastOnce = true;
125
+ };
126
+ }
127
+
128
+ export function genUpdate() {
129
+ return async (props: any) => {
130
+ setModelState(props);
131
+ const slaveRuntime = await getSlaveRuntime();
132
+ if (slaveRuntime.update) {
133
+ await slaveRuntime.update(props);
134
+ }
135
+ };
136
+ }
137
+
138
+ export function genUnmount(mountElementId: string) {
139
+ return async (props: any) => {
140
+ const container = props?.container
141
+ ? props.container.querySelector(`#${mountElementId}`)
142
+ : document.getElementById(mountElementId);
143
+ if (container) {
144
+ ReactDOM.unmountComponentAtNode(container);
145
+ }
146
+ const slaveRuntime = await getSlaveRuntime();
147
+ if (slaveRuntime.unmount) await slaveRuntime.unmount(props);
148
+ };
149
+ }
@@ -0,0 +1,19 @@
1
+ // @ts-nocheck
2
+ /* eslint-disable */
3
+ import { useState } from 'react';
4
+
5
+ let initState: any;
6
+ let setModelState = (val: any) => {
7
+ initState = val;
8
+ };
9
+
10
+ export default () => {
11
+ const [state, setState] = useState(initState);
12
+ setModelState = (val: any) => {
13
+ initState = val;
14
+ setState(val);
15
+ };
16
+ return state;
17
+ };
18
+
19
+ export { setModelState };
@@ -0,0 +1,21 @@
1
+ // @ts-nocheck
2
+ /* eslint-disable */
3
+ import qiankunRender from './lifecycles';
4
+
5
+ export function render(oldRender: any) {
6
+ return qiankunRender().then(oldRender);
7
+ }
8
+
9
+ // export function modifyClientRenderOpts(memo: any) {
10
+ // // 每次应用 render 的时候会调 modifyClientRenderOpts,这时尝试从队列中取 render 的配置
11
+ // const clientRenderOpts = clientRenderOptsStack.shift();
12
+ // if (clientRenderOpts) {
13
+ // const history = clientRenderOpts.getHistory();
14
+ // delete clientRenderOpts.getHistory;
15
+ // clientRenderOpts.history = history;
16
+ // }
17
+ // return {
18
+ // ...memo,
19
+ // ...clientRenderOpts,
20
+ // };
21
+ // }
package/package.json CHANGED
@@ -1,37 +1,53 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.0-beta.7",
3
+ "version": "4.0.0-rc.2",
4
4
  "description": "@umijs/plugins",
5
+ "homepage": "https://github.com/umijs/umi-next/tree/master/packages/plugins#readme",
6
+ "bugs": "https://github.com/umijs/umi-next/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/umijs/umi-next"
10
+ },
11
+ "license": "MIT",
5
12
  "main": "dist/index.js",
6
13
  "types": "dist/index.d.ts",
7
14
  "files": [
8
- "dist"
15
+ "dist",
16
+ "libs"
9
17
  ],
10
18
  "scripts": {
11
19
  "build": "pnpm tsc",
12
20
  "build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
13
21
  "dev": "pnpm build -- --watch"
14
22
  },
15
- "repository": {
16
- "type": "git",
17
- "url": "https://github.com/umijs/umi-next"
18
- },
19
- "authors": [
20
- "chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
21
- ],
22
- "license": "MIT",
23
- "bugs": "https://github.com/umijs/umi-next/issues",
24
- "homepage": "https://github.com/umijs/umi-next/tree/master/packages/plugins#readme",
25
- "publishConfig": {
26
- "access": "public"
27
- },
28
23
  "dependencies": {
29
- "antd": "^4.16.13",
24
+ "@ahooksjs/use-request": "^2.0.0",
25
+ "@ant-design/icons": "^4.7.0",
26
+ "@ant-design/pro-layout": "^6.32.14",
27
+ "@umijs/bundler-utils": "4.0.0-rc.2",
28
+ "antd": "^4.18.7",
30
29
  "antd-dayjs-webpack-plugin": "^1.0.6",
30
+ "axios": "^0.26.0",
31
31
  "babel-plugin-import": "^1.13.3",
32
- "dayjs": "^1.10.7"
32
+ "dayjs": "^1.10.7",
33
+ "dva-core": "^2.0.4",
34
+ "event-emitter": "~0.3.5",
35
+ "fast-deep-equal": "3.1.3",
36
+ "lodash": "^4.17.21",
37
+ "moment": "^2.29.1",
38
+ "qiankun": "^2.6.3",
39
+ "react-intl": "3.12.1",
40
+ "react-redux": "^7.2.6",
41
+ "redux": "^4.1.2",
42
+ "warning": "^4.0.3"
33
43
  },
34
44
  "devDependencies": {
35
- "umi": "4.0.0-beta.7"
36
- }
45
+ "umi": "4.0.0-rc.2"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "authors": [
51
+ "chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
52
+ ]
37
53
  }
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
- };