@umijs/plugins 4.0.0-beta.8 → 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 (98) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -1
  3. package/dist/access.d.ts +1 -1
  4. package/dist/access.js +194 -4
  5. package/dist/{sass.d.ts → analytics.d.ts} +1 -1
  6. package/dist/analytics.js +118 -0
  7. package/dist/antd.d.ts +1 -1
  8. package/dist/antd.js +345 -157
  9. package/dist/{icons.d.ts → confetti.d.ts} +1 -1
  10. package/dist/confetti.js +64 -0
  11. package/dist/constants.d.ts +1 -0
  12. package/dist/constants.js +30 -0
  13. package/dist/dva.d.ts +4 -1
  14. package/dist/dva.js +302 -8
  15. package/dist/initial-state.d.ts +1 -1
  16. package/dist/initial-state.js +147 -4
  17. package/dist/layout.d.ts +1 -1
  18. package/dist/layout.js +754 -4
  19. package/dist/locale.d.ts +2 -1
  20. package/dist/locale.js +257 -4
  21. package/dist/mf.d.ts +2 -0
  22. package/dist/mf.js +358 -0
  23. package/dist/model.d.ts +1 -1
  24. package/dist/model.js +109 -4
  25. package/dist/moment2dayjs.d.ts +3 -0
  26. package/dist/moment2dayjs.js +125 -0
  27. package/dist/qiankun/constants.d.ts +5 -0
  28. package/dist/qiankun/constants.js +41 -0
  29. package/dist/qiankun/master.d.ts +6 -0
  30. package/dist/qiankun/master.js +236 -0
  31. package/dist/qiankun/slave.d.ts +3 -0
  32. package/dist/qiankun/slave.js +345 -0
  33. package/dist/qiankun.d.ts +1 -1
  34. package/dist/qiankun.js +51 -4
  35. package/dist/react-query.d.ts +3 -0
  36. package/dist/react-query.js +193 -0
  37. package/dist/request.d.ts +1 -1
  38. package/dist/request.js +384 -4
  39. package/dist/styled-components.d.ts +3 -0
  40. package/dist/styled-components.js +150 -0
  41. package/dist/tailwindcss.d.ts +3 -0
  42. package/dist/tailwindcss.js +106 -0
  43. package/dist/unocss.d.ts +3 -0
  44. package/dist/unocss.js +71 -0
  45. package/dist/utils/astUtils.d.ts +3 -0
  46. package/dist/utils/astUtils.js +49 -0
  47. package/dist/utils/localeUtils.d.ts +33 -0
  48. package/dist/utils/localeUtils.js +139 -0
  49. package/dist/utils/mfUtils.d.ts +14 -0
  50. package/dist/utils/mfUtils.js +56 -0
  51. package/dist/utils/modelUtils.d.ts +40 -0
  52. package/dist/utils/modelUtils.js +286 -0
  53. package/dist/utils/resolveProjectDep.d.ts +5 -0
  54. package/dist/utils/resolveProjectDep.js +40 -0
  55. package/dist/utils/withTmpPath.d.ts +6 -0
  56. package/dist/utils/withTmpPath.js +39 -0
  57. package/dist/valtio.d.ts +3 -0
  58. package/dist/valtio.js +81 -0
  59. package/libs/dva.tsx +45 -0
  60. package/libs/model.tsx +180 -0
  61. package/libs/qiankun/master/AntdErrorBoundary.tsx +34 -0
  62. package/libs/qiankun/master/AntdLoader.tsx +15 -0
  63. package/libs/qiankun/master/ErrorBoundary.tsx +7 -0
  64. package/libs/qiankun/master/MicroApp.tsx +327 -0
  65. package/libs/qiankun/master/MicroAppWithMemoHistory.tsx +43 -0
  66. package/libs/qiankun/master/common.ts +172 -0
  67. package/libs/qiankun/master/constants.ts +19 -0
  68. package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +45 -0
  69. package/libs/qiankun/master/masterRuntimePlugin.tsx +161 -0
  70. package/libs/qiankun/master/routeUtils.ts +26 -0
  71. package/libs/qiankun/master/types.ts +54 -0
  72. package/libs/qiankun/slave/MicroAppLink.tsx +122 -0
  73. package/libs/qiankun/slave/connectMaster.tsx +14 -0
  74. package/libs/qiankun/slave/constants.ts +5 -0
  75. package/libs/qiankun/slave/lifecycles.ts +164 -0
  76. package/libs/qiankun/slave/qiankunModel.ts +18 -0
  77. package/libs/qiankun/slave/slaveRuntimePlugin.ts +36 -0
  78. package/package.json +54 -24
  79. package/templates/antd/runtime.ts.tpl +170 -0
  80. package/templates/antd/types.d.ts.tpl +17 -0
  81. package/templates/locale/SelectLang.tpl +502 -0
  82. package/templates/locale/locale.tpl +82 -0
  83. package/templates/locale/localeExports.tpl +307 -0
  84. package/templates/locale/runtime.tpl +34 -0
  85. package/templates/mf/runtime.ts.tpl +149 -0
  86. package/dist/access.d.ts.map +0 -1
  87. package/dist/antd.d.ts.map +0 -1
  88. package/dist/dva.d.ts.map +0 -1
  89. package/dist/icons.d.ts.map +0 -1
  90. package/dist/icons.js +0 -5
  91. package/dist/initial-state.d.ts.map +0 -1
  92. package/dist/layout.d.ts.map +0 -1
  93. package/dist/locale.d.ts.map +0 -1
  94. package/dist/model.d.ts.map +0 -1
  95. package/dist/qiankun.d.ts.map +0 -1
  96. package/dist/request.d.ts.map +0 -1
  97. package/dist/sass.d.ts.map +0 -1
  98. package/dist/sass.js +0 -5
@@ -0,0 +1,5 @@
1
+ export declare function resolveProjectDep(opts: {
2
+ pkg: any;
3
+ cwd: string;
4
+ dep: string;
5
+ }): string | undefined;
@@ -0,0 +1,40 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/utils/resolveProjectDep.ts
20
+ var resolveProjectDep_exports = {};
21
+ __export(resolveProjectDep_exports, {
22
+ resolveProjectDep: () => resolveProjectDep
23
+ });
24
+ module.exports = __toCommonJS(resolveProjectDep_exports);
25
+ var import_path = require("path");
26
+ var import_plugin_utils = require("umi/plugin-utils");
27
+ function resolveProjectDep(opts) {
28
+ var _a, _b;
29
+ if (((_a = opts.pkg.dependencies) == null ? void 0 : _a[opts.dep]) || ((_b = opts.pkg.devDependencies) == null ? void 0 : _b[opts.dep])) {
30
+ return (0, import_path.dirname)(
31
+ import_plugin_utils.resolve.sync(`${opts.dep}/package.json`, {
32
+ basedir: opts.cwd
33
+ })
34
+ );
35
+ }
36
+ }
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ resolveProjectDep
40
+ });
@@ -0,0 +1,6 @@
1
+ import { IApi } from 'umi';
2
+ export declare function withTmpPath(opts: {
3
+ api: IApi;
4
+ path: string;
5
+ noPluginDir?: boolean;
6
+ }): string;
@@ -0,0 +1,39 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/utils/withTmpPath.ts
20
+ var withTmpPath_exports = {};
21
+ __export(withTmpPath_exports, {
22
+ withTmpPath: () => withTmpPath
23
+ });
24
+ module.exports = __toCommonJS(withTmpPath_exports);
25
+ var import_path = require("path");
26
+ var import_plugin_utils = require("umi/plugin-utils");
27
+ function withTmpPath(opts) {
28
+ return (0, import_plugin_utils.winPath)(
29
+ (0, import_path.join)(
30
+ opts.api.paths.absTmpPath,
31
+ opts.api.plugin.key && !opts.noPluginDir ? `plugin-${opts.api.plugin.key}` : "",
32
+ opts.path
33
+ )
34
+ );
35
+ }
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ withTmpPath
39
+ });
@@ -0,0 +1,3 @@
1
+ import { IApi } from 'umi';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
package/dist/valtio.js ADDED
@@ -0,0 +1,81 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/valtio.ts
30
+ var valtio_exports = {};
31
+ __export(valtio_exports, {
32
+ default: () => valtio_default
33
+ });
34
+ module.exports = __toCommonJS(valtio_exports);
35
+ var import_utils = require("@umijs/utils");
36
+ var import_path = require("path");
37
+ var valtio_default = (api) => {
38
+ api.describe({
39
+ key: "valtio",
40
+ config: {
41
+ schema({ zod }) {
42
+ return zod.object({});
43
+ }
44
+ },
45
+ enableBy: api.EnableBy.config
46
+ });
47
+ const libPath = (0, import_utils.winPath)(
48
+ (0, import_path.dirname)(require.resolve("@umijs/valtio/package.json"))
49
+ );
50
+ api.onGenerateFiles(() => {
51
+ api.writeTmpFile({
52
+ path: "index.ts",
53
+ content: `
54
+ export {
55
+ proxy,
56
+ useSnapshot,
57
+ snapshot,
58
+ subscribe,
59
+ subscribeKey,
60
+ proxyWithComputed,
61
+ proxyWithHistory,
62
+ proxyWithDevtools,
63
+ proxyMap,
64
+ proxySet,
65
+ derive,
66
+ underive,
67
+ useProxy,
68
+ ref,
69
+ watch,
70
+ } from '${libPath}';
71
+ `
72
+ });
73
+ });
74
+ api.modifyConfig((memo) => {
75
+ memo.alias = {
76
+ ...memo.alias,
77
+ "@umijs/valtio": libPath
78
+ };
79
+ return memo;
80
+ });
81
+ };
package/libs/dva.tsx ADDED
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ // @ts-ignore
3
+ import { create, saga, utils } from 'dva-core';
4
+ import {
5
+ connect,
6
+ Provider,
7
+ useDispatch,
8
+ useSelector,
9
+ useStore,
10
+ } from 'react-redux';
11
+ export { bindActionCreators } from 'redux';
12
+ export { create, saga, utils };
13
+ export { connect, Provider, useDispatch, useSelector, useStore };
14
+
15
+ export default function dva(opts: any) {
16
+ const app = create(opts, {
17
+ initialReducer: {},
18
+ setupApp() {},
19
+ });
20
+ const oldAppStart = app.start;
21
+ app.router = router;
22
+ app.start = start;
23
+ return app;
24
+
25
+ function router(router: any) {
26
+ app._router = router;
27
+ }
28
+
29
+ function start(elem: any) {
30
+ // old dva.start() supports passing arguments
31
+ if (typeof elem !== 'undefined') {
32
+ throw new Error('dva.start() should not be called with any arguments.');
33
+ }
34
+ if (!app._store) {
35
+ oldAppStart.call(app);
36
+ }
37
+ const store = app._store;
38
+ const router = app._router;
39
+ return (extraProps: any) => {
40
+ return (
41
+ <Provider store={store}>{router({ app, ...extraProps })}</Provider>
42
+ );
43
+ };
44
+ }
45
+ }
package/libs/model.tsx ADDED
@@ -0,0 +1,180 @@
1
+ // @ts-ignore
2
+ import type { models as rawModels } from '@@/plugin-model/model';
3
+ import isEqual from 'fast-deep-equal';
4
+ import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
5
+
6
+ type Models = typeof rawModels;
7
+
8
+ type GetNamespaces<M> = {
9
+ [K in keyof M]: M[K] extends { namespace: string }
10
+ ? M[K]['namespace']
11
+ : never;
12
+ }[keyof M];
13
+
14
+ type Namespaces = GetNamespaces<Models>;
15
+
16
+ // @ts-ignore
17
+ const Context = React.createContext<{ dispatcher: Dispatcher }>(null);
18
+
19
+ class Dispatcher {
20
+ callbacks: Record<Namespaces, Set<Function>> = {};
21
+ data: Record<Namespaces, unknown> = {};
22
+ update = (namespace: Namespaces) => {
23
+ if (this.callbacks[namespace]) {
24
+ this.callbacks[namespace].forEach((cb) => {
25
+ try {
26
+ const data = this.data[namespace];
27
+ cb(data);
28
+ } catch (e) {
29
+ cb(undefined);
30
+ }
31
+ });
32
+ }
33
+ };
34
+ }
35
+
36
+ interface ExecutorProps {
37
+ hook: () => any;
38
+ onUpdate: (val: any) => void;
39
+ namespace: string;
40
+ }
41
+
42
+ function Executor(props: ExecutorProps) {
43
+ const { hook, onUpdate, namespace } = props;
44
+
45
+ const updateRef = useRef(onUpdate);
46
+ const initialLoad = useRef(false);
47
+
48
+ let data: any;
49
+ try {
50
+ data = hook();
51
+ } catch (e) {
52
+ console.error(
53
+ `plugin-model: Invoking '${namespace || 'unknown'}' model failed:`,
54
+ e,
55
+ );
56
+ }
57
+
58
+ // 首次执行时立刻返回初始值
59
+ useMemo(() => {
60
+ updateRef.current(data);
61
+ }, []);
62
+
63
+ // React 16.13 后 update 函数用 useEffect 包裹
64
+ useEffect(() => {
65
+ if (initialLoad.current) {
66
+ updateRef.current(data);
67
+ } else {
68
+ initialLoad.current = true;
69
+ }
70
+ });
71
+
72
+ return null;
73
+ }
74
+
75
+ const dispatcher = new Dispatcher();
76
+
77
+ export function Provider(props: {
78
+ models: Record<string, any>;
79
+ children: React.ReactNode;
80
+ }) {
81
+ return (
82
+ <Context.Provider value={{ dispatcher }}>
83
+ {Object.keys(props.models).map((namespace) => {
84
+ return (
85
+ <Executor
86
+ key={namespace}
87
+ hook={props.models[namespace]}
88
+ namespace={namespace}
89
+ onUpdate={(val) => {
90
+ dispatcher.data[namespace] = val;
91
+ dispatcher.update(namespace);
92
+ }}
93
+ />
94
+ );
95
+ })}
96
+ {props.children}
97
+ </Context.Provider>
98
+ );
99
+ }
100
+
101
+ type GetModelByNamespace<M, N> = {
102
+ [K in keyof M]: M[K] extends { namespace: string; model: unknown }
103
+ ? M[K]['namespace'] extends N
104
+ ? M[K]['model'] extends (...args: any) => any
105
+ ? ReturnType<M[K]['model']>
106
+ : never
107
+ : never
108
+ : never;
109
+ }[keyof M];
110
+
111
+ type Model<N> = GetModelByNamespace<Models, N>;
112
+ type Selector<N, S> = (model: Model<N>) => S;
113
+
114
+ type SelectedModel<N, T> = T extends (...args: any) => any
115
+ ? ReturnType<NonNullable<T>>
116
+ : Model<N>;
117
+
118
+ export function useModel<N extends Namespaces>(namespace: N): Model<N>;
119
+
120
+ export function useModel<N extends Namespaces, S>(
121
+ namespace: N,
122
+ selector: Selector<N, S>,
123
+ ): SelectedModel<N, typeof selector>;
124
+
125
+ export function useModel<N extends Namespaces, S>(
126
+ namespace: N,
127
+ selector?: Selector<N, S>,
128
+ ): SelectedModel<N, typeof selector> {
129
+ const { dispatcher } = useContext<{ dispatcher: Dispatcher }>(Context);
130
+ const selectorRef = useRef(selector);
131
+ selectorRef.current = selector;
132
+ const [state, setState] = useState(() =>
133
+ selectorRef.current
134
+ ? selectorRef.current(dispatcher.data[namespace])
135
+ : dispatcher.data[namespace],
136
+ );
137
+ const stateRef = useRef<any>(state);
138
+ stateRef.current = state;
139
+
140
+ const isMount = useRef(false);
141
+ useEffect(() => {
142
+ isMount.current = true;
143
+ return () => {
144
+ isMount.current = false;
145
+ };
146
+ }, []);
147
+
148
+ useEffect(() => {
149
+ const handler = (data: any) => {
150
+ if (!isMount.current) {
151
+ // 如果 handler 执行过程中,组件被卸载了,则强制更新全局 data
152
+ // TODO: 需要加个 example 测试
153
+ setTimeout(() => {
154
+ dispatcher.data[namespace] = data;
155
+ dispatcher.update(namespace);
156
+ });
157
+ } else {
158
+ const currentState = selectorRef.current
159
+ ? selectorRef.current(data)
160
+ : data;
161
+ const previousState = stateRef.current;
162
+ if (!isEqual(currentState, previousState)) {
163
+ // 避免 currentState 拿到的数据是老的,从而导致 isEqual 比对逻辑有问题
164
+ stateRef.current = currentState;
165
+ setState(currentState);
166
+ }
167
+ }
168
+ };
169
+
170
+ dispatcher.callbacks[namespace] ||= new Set() as any; // rawModels 是 umi 动态生成的文件,导致前面 callback[namespace] 的类型无法推导出来,所以用 as any 来忽略掉
171
+ dispatcher.callbacks[namespace].add(handler);
172
+ dispatcher.update(namespace);
173
+
174
+ return () => {
175
+ dispatcher.callbacks[namespace].delete(handler);
176
+ };
177
+ }, [namespace]);
178
+
179
+ return state;
180
+ }
@@ -0,0 +1,34 @@
1
+ // @ts-nocheck
2
+ /* eslint-disable */
3
+ import { Button, Result } from 'antd';
4
+ import React from 'react';
5
+ import { getLocale } from 'umi';
6
+
7
+ const defaultLocale = 'en-US';
8
+
9
+ export const ErrorBoundary = ({ error }: { error: any }) => {
10
+ console.error(error);
11
+
12
+ const currentLocale = getLocale ? getLocale() : defaultLocale;
13
+
14
+ return (
15
+ <Result
16
+ status="500"
17
+ title={
18
+ currentLocale === defaultLocale
19
+ ? 'Whoops, something went wrong'
20
+ : '出错了'
21
+ }
22
+ subTitle={
23
+ currentLocale === defaultLocale
24
+ ? 'This page failed to load, please try again later'
25
+ : '页面加载失败,请稍后重试'
26
+ }
27
+ extra={
28
+ <Button type="primary" onClick={() => window.location.reload()}>
29
+ {currentLocale === defaultLocale ? 'Reload' : '再试一次'}
30
+ </Button>
31
+ }
32
+ />
33
+ );
34
+ };
@@ -0,0 +1,15 @@
1
+ // @ts-nocheck
2
+ /* eslint-disable */
3
+ import { Spin } from 'antd';
4
+ import React from 'react';
5
+
6
+ export default function AntdLoader(props: { loading: boolean }) {
7
+ const { loading } = props;
8
+ const style = {
9
+ position: 'absolute',
10
+ top: '50%',
11
+ left: '50%',
12
+ transform: 'translate(-50%, -50%)',
13
+ };
14
+ return <Spin spinning={loading} size="large" style={style} />;
15
+ }
@@ -0,0 +1,7 @@
1
+ // @ts-nocheck
2
+ /* eslint-disable */
3
+ import React from 'react';
4
+
5
+ export const ErrorBoundary = ({ error }: { error: any }) => (
6
+ <div>{error?.message}</div>
7
+ );