@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.
- package/LICENSE +21 -0
- package/README.md +4 -1
- package/dist/access.js +194 -4
- package/dist/analytics.d.ts +3 -0
- package/dist/analytics.js +118 -0
- package/dist/antd.js +345 -158
- package/dist/confetti.js +64 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +30 -0
- package/dist/dva.d.ts +3 -0
- package/dist/dva.js +302 -8
- package/dist/initial-state.js +147 -4
- package/dist/layout.js +754 -4
- package/dist/locale.d.ts +1 -0
- package/dist/locale.js +257 -4
- package/dist/mf.d.ts +2 -0
- package/dist/mf.js +358 -0
- package/dist/model.js +109 -4
- package/dist/moment2dayjs.js +125 -0
- package/dist/qiankun/constants.d.ts +5 -0
- package/dist/qiankun/constants.js +41 -0
- package/dist/qiankun/master.d.ts +6 -0
- package/dist/qiankun/master.js +236 -0
- package/dist/qiankun/slave.d.ts +3 -0
- package/dist/qiankun/slave.js +345 -0
- package/dist/qiankun.js +51 -4
- package/dist/react-query.d.ts +3 -0
- package/dist/react-query.js +193 -0
- package/dist/request.js +384 -4
- package/dist/styled-components.d.ts +3 -0
- package/dist/styled-components.js +150 -0
- package/dist/tailwindcss.d.ts +3 -0
- package/dist/tailwindcss.js +106 -0
- package/dist/unocss.d.ts +3 -0
- package/dist/unocss.js +71 -0
- package/dist/utils/astUtils.d.ts +3 -0
- package/dist/utils/astUtils.js +49 -0
- package/dist/utils/localeUtils.d.ts +33 -0
- package/dist/utils/localeUtils.js +139 -0
- package/dist/utils/mfUtils.d.ts +14 -0
- package/dist/utils/mfUtils.js +56 -0
- package/dist/utils/modelUtils.d.ts +40 -0
- package/dist/utils/modelUtils.js +286 -0
- package/dist/utils/resolveProjectDep.d.ts +5 -0
- package/dist/utils/resolveProjectDep.js +40 -0
- package/dist/utils/withTmpPath.d.ts +6 -0
- package/dist/utils/withTmpPath.js +39 -0
- package/dist/valtio.d.ts +3 -0
- package/dist/valtio.js +81 -0
- package/libs/dva.tsx +45 -0
- package/libs/model.tsx +180 -0
- package/libs/qiankun/master/AntdErrorBoundary.tsx +34 -0
- package/libs/qiankun/master/AntdLoader.tsx +15 -0
- package/libs/qiankun/master/ErrorBoundary.tsx +7 -0
- package/libs/qiankun/master/MicroApp.tsx +327 -0
- package/libs/qiankun/master/MicroAppWithMemoHistory.tsx +43 -0
- package/libs/qiankun/master/common.ts +172 -0
- package/libs/qiankun/master/constants.ts +19 -0
- package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +45 -0
- package/libs/qiankun/master/masterRuntimePlugin.tsx +161 -0
- package/libs/qiankun/master/routeUtils.ts +26 -0
- package/libs/qiankun/master/types.ts +54 -0
- package/libs/qiankun/slave/MicroAppLink.tsx +122 -0
- package/libs/qiankun/slave/connectMaster.tsx +14 -0
- package/libs/qiankun/slave/constants.ts +5 -0
- package/libs/qiankun/slave/lifecycles.ts +164 -0
- package/libs/qiankun/slave/qiankunModel.ts +18 -0
- package/libs/qiankun/slave/slaveRuntimePlugin.ts +36 -0
- package/package.json +46 -16
- package/templates/antd/runtime.ts.tpl +170 -0
- package/templates/antd/types.d.ts.tpl +17 -0
- package/templates/locale/SelectLang.tpl +502 -0
- package/templates/locale/locale.tpl +82 -0
- package/templates/locale/localeExports.tpl +307 -0
- package/templates/locale/runtime.tpl +34 -0
- package/templates/mf/runtime.ts.tpl +149 -0
- package/dist/icons.js +0 -5
- package/dist/sass.js +0 -5
- /package/dist/{icons.d.ts → confetti.d.ts} +0 -0
- /package/dist/{sass.d.ts → moment2dayjs.d.ts} +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-present ChenCheng (sorrycc@gmail.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
package/dist/access.js
CHANGED
|
@@ -1,5 +1,195 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
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/access.ts
|
|
30
|
+
var access_exports = {};
|
|
31
|
+
__export(access_exports, {
|
|
32
|
+
default: () => access_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(access_exports);
|
|
35
|
+
var import_fs = __toESM(require("fs"));
|
|
36
|
+
var import_path = require("path");
|
|
37
|
+
var import_withTmpPath = require("./utils/withTmpPath");
|
|
38
|
+
var access_default = (api) => {
|
|
39
|
+
api.describe({
|
|
40
|
+
config: {
|
|
41
|
+
schema({ zod }) {
|
|
42
|
+
return zod.record(zod.any());
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
enableBy: api.EnableBy.config
|
|
46
|
+
});
|
|
47
|
+
api.onGenerateFiles(async () => {
|
|
48
|
+
const hasAccessFile = ["js", "jsx", "ts", "tsx"].some(
|
|
49
|
+
(ext) => import_fs.default.existsSync((0, import_path.join)(api.paths.absSrcPath, `access.${ext}`))
|
|
50
|
+
);
|
|
51
|
+
api.writeTmpFile({
|
|
52
|
+
path: "runtime.tsx",
|
|
53
|
+
content: `
|
|
54
|
+
import React from 'react';${hasAccessFile ? `
|
|
55
|
+
import accessFactory from '@/access';
|
|
56
|
+
import { useModel } from '@@/plugin-model';
|
|
57
|
+
` : ""}
|
|
58
|
+
import { AccessContext } from './context';
|
|
59
|
+
|
|
60
|
+
function Provider(props) {${hasAccessFile ? `
|
|
61
|
+
const { initialState } = useModel('@@initialState');
|
|
62
|
+
const access = React.useMemo(() => accessFactory(initialState), [initialState]);
|
|
63
|
+
` : `
|
|
64
|
+
const access = {};
|
|
65
|
+
`}
|
|
66
|
+
return (
|
|
67
|
+
<AccessContext.Provider value={access}>
|
|
68
|
+
{ props.children }
|
|
69
|
+
</AccessContext.Provider>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function accessProvider(container) {
|
|
74
|
+
return <Provider>{ container }</Provider>;
|
|
75
|
+
}
|
|
76
|
+
`
|
|
77
|
+
});
|
|
78
|
+
api.writeTmpFile({
|
|
79
|
+
path: "index.tsx",
|
|
80
|
+
content: `
|
|
81
|
+
import React, { PropsWithChildren } from 'react';
|
|
82
|
+
import { AccessContext } from './context';
|
|
83
|
+
import type { IRoute } from '${api.appData.umi.importSource}';
|
|
84
|
+
|
|
85
|
+
export const useAccess = () => {
|
|
86
|
+
return React.useContext(AccessContext);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export interface AccessProps {
|
|
90
|
+
accessible: boolean;
|
|
91
|
+
fallback?: React.ReactNode;
|
|
92
|
+
}
|
|
93
|
+
export const Access: React.FC<PropsWithChildren<AccessProps>> = (props) => {
|
|
94
|
+
if (process.env.NODE_ENV === 'development' && typeof props.accessible !== 'boolean') {
|
|
95
|
+
throw new Error('[access] the \`accessible\` property on <Access /> should be a boolean');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return <>{ props.accessible ? props.children : props.fallback }</>;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export const useAccessMarkedRoutes = (routes: IRoute[]) => {
|
|
102
|
+
const access = useAccess();
|
|
103
|
+
const markdedRoutes: IRoute[] = React.useMemo(() => {
|
|
104
|
+
const process = (route, parentAccessCode, parentRoute) => {
|
|
105
|
+
let accessCode = route.access;
|
|
106
|
+
// 用父级的路由检测父级的 accessCode
|
|
107
|
+
let detectorRoute = route;
|
|
108
|
+
if (!accessCode && parentAccessCode) {
|
|
109
|
+
accessCode = parentAccessCode;
|
|
110
|
+
detectorRoute = parentRoute;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// set default status
|
|
114
|
+
route.unaccessible = ${api.config.access.strictMode ? "true" : "false"};
|
|
115
|
+
|
|
116
|
+
// check access code
|
|
117
|
+
if (typeof accessCode === 'string') {
|
|
118
|
+
const detector = access[accessCode];
|
|
119
|
+
|
|
120
|
+
if (typeof detector === 'function') {
|
|
121
|
+
route.unaccessible = !detector(detectorRoute);
|
|
122
|
+
} else if (typeof detector === 'boolean') {
|
|
123
|
+
route.unaccessible = !detector;
|
|
124
|
+
} else if (typeof detector === 'undefined') {
|
|
125
|
+
route.unaccessible = true;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// check children access code
|
|
130
|
+
if (route.children?.length) {
|
|
131
|
+
const isNoAccessibleChild = !route.children.reduce((hasAccessibleChild, child) => {
|
|
132
|
+
process(child, accessCode, route);
|
|
133
|
+
|
|
134
|
+
return hasAccessibleChild || !child.unaccessible;
|
|
135
|
+
}, false);
|
|
136
|
+
|
|
137
|
+
// make sure parent route is unaccessible if all children are unaccessible
|
|
138
|
+
if (isNoAccessibleChild) {
|
|
139
|
+
route.unaccessible = true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// check children access code
|
|
144
|
+
if (route.routes?.length) {
|
|
145
|
+
const isNoAccessibleChild = !route.routes.reduce((hasAccessibleChild, child) => {
|
|
146
|
+
process(child, accessCode, route);
|
|
147
|
+
|
|
148
|
+
return hasAccessibleChild || !child.unaccessible;
|
|
149
|
+
}, false);
|
|
150
|
+
|
|
151
|
+
// make sure parent route is unaccessible if all children are unaccessible
|
|
152
|
+
if (isNoAccessibleChild) {
|
|
153
|
+
route.unaccessible = true;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return route;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return routes.map(route => process(route));
|
|
161
|
+
}, [routes.length, access]);
|
|
162
|
+
|
|
163
|
+
return markdedRoutes;
|
|
164
|
+
}
|
|
165
|
+
`
|
|
166
|
+
});
|
|
167
|
+
api.writeTmpFile({
|
|
168
|
+
path: "context.ts",
|
|
169
|
+
content: `
|
|
170
|
+
import React from 'react';${hasAccessFile ? `
|
|
171
|
+
import { AccessInstance } from './types.d';
|
|
172
|
+
|
|
173
|
+
export const AccessContext = React.createContext<AccessInstance>(null);
|
|
174
|
+
` : `
|
|
175
|
+
export const AccessContext = React.createContext<any>(null);
|
|
176
|
+
`}
|
|
177
|
+
`
|
|
178
|
+
});
|
|
179
|
+
api.writeTmpFile({
|
|
180
|
+
path: "types.d.ts",
|
|
181
|
+
content: hasAccessFile ? `
|
|
182
|
+
import accessFactory from '@/access';
|
|
183
|
+
|
|
184
|
+
export type AccessInstance = ReturnType<typeof accessFactory>;
|
|
185
|
+
` : "export {}"
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
api.addRuntimePlugin(() => {
|
|
189
|
+
return [(0, import_withTmpPath.withTmpPath)({ api, path: "runtime.tsx" })];
|
|
190
|
+
});
|
|
191
|
+
api.addTmpGenerateWatcherPaths(() => [
|
|
192
|
+
(0, import_path.join)(api.paths.absSrcPath, "access.ts"),
|
|
193
|
+
(0, import_path.join)(api.paths.absSrcPath, "access.js")
|
|
194
|
+
]);
|
|
5
195
|
};
|
|
@@ -0,0 +1,118 @@
|
|
|
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/analytics.ts
|
|
20
|
+
var analytics_exports = {};
|
|
21
|
+
__export(analytics_exports, {
|
|
22
|
+
default: () => analytics_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(analytics_exports);
|
|
25
|
+
var analytics_default = (api) => {
|
|
26
|
+
const GA_KEY = process.env.GA_KEY;
|
|
27
|
+
const GA_V2_KEY = process.env.GA_V2_KEY;
|
|
28
|
+
const enableBy = (opts) => {
|
|
29
|
+
return opts.config.analytics || GA_KEY;
|
|
30
|
+
};
|
|
31
|
+
api.describe({
|
|
32
|
+
key: "analytics",
|
|
33
|
+
config: {
|
|
34
|
+
schema({ zod }) {
|
|
35
|
+
return zod.object({
|
|
36
|
+
baidu: zod.string(),
|
|
37
|
+
ga: zod.string(),
|
|
38
|
+
ga_v2: zod.string()
|
|
39
|
+
}).partial();
|
|
40
|
+
},
|
|
41
|
+
onChange: api.ConfigChangeType.reload
|
|
42
|
+
},
|
|
43
|
+
enableBy
|
|
44
|
+
});
|
|
45
|
+
const baiduTpl = (code) => {
|
|
46
|
+
return `
|
|
47
|
+
(function() {
|
|
48
|
+
var hm = document.createElement('script');
|
|
49
|
+
hm.src = '//hm.baidu.com/hm.js?${code}';
|
|
50
|
+
var s = document.getElementsByTagName('script')[0];
|
|
51
|
+
s.parentNode.insertBefore(hm, s);
|
|
52
|
+
})();
|
|
53
|
+
`;
|
|
54
|
+
};
|
|
55
|
+
const gaTpl = (code) => {
|
|
56
|
+
return `
|
|
57
|
+
(function(){
|
|
58
|
+
if (!location.port) {
|
|
59
|
+
(function (i, s, o, g, r, a, m) {
|
|
60
|
+
i['GoogleAnalyticsObject'] = r;
|
|
61
|
+
i[r] = i[r] || function () {
|
|
62
|
+
(i[r].q = i[r].q || []).push(arguments)
|
|
63
|
+
}, i[r].l = 1 * new Date();
|
|
64
|
+
a = s.createElement(o),
|
|
65
|
+
m = s.getElementsByTagName(o)[0];
|
|
66
|
+
a.async = 1;
|
|
67
|
+
a.src = g;
|
|
68
|
+
m.parentNode.insertBefore(a, m)
|
|
69
|
+
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
|
|
70
|
+
ga('create', '${code}', 'auto');
|
|
71
|
+
ga('send', 'pageview');
|
|
72
|
+
}
|
|
73
|
+
})();
|
|
74
|
+
`;
|
|
75
|
+
};
|
|
76
|
+
const gaV2Tpl = (code) => {
|
|
77
|
+
return `
|
|
78
|
+
window.dataLayer = window.dataLayer || [];
|
|
79
|
+
function gtag(){dataLayer.push(arguments);}
|
|
80
|
+
gtag('js', new Date());
|
|
81
|
+
gtag('config', '${code}');
|
|
82
|
+
`.trim();
|
|
83
|
+
};
|
|
84
|
+
api.addHTMLHeadScripts(() => {
|
|
85
|
+
const analytics = api.config.analytics || {};
|
|
86
|
+
const { baidu, ga = GA_KEY, ga_v2 = GA_V2_KEY } = analytics;
|
|
87
|
+
const scripts = [];
|
|
88
|
+
if (baidu) {
|
|
89
|
+
scripts.push({
|
|
90
|
+
content: "var _hmt = _hmt || [];"
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if (api.env !== "development") {
|
|
94
|
+
if (baidu) {
|
|
95
|
+
scripts.push({
|
|
96
|
+
content: baiduTpl(baidu)
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (ga) {
|
|
100
|
+
scripts.push({
|
|
101
|
+
content: gaTpl(ga)
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (ga_v2) {
|
|
105
|
+
scripts.push(
|
|
106
|
+
{
|
|
107
|
+
async: true,
|
|
108
|
+
src: `//www.googletagmanager.com/gtag/js?id=${ga_v2}`
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
content: gaV2Tpl(ga_v2)
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return scripts.filter(Boolean);
|
|
117
|
+
});
|
|
118
|
+
};
|