dumi 2.2.1 → 2.2.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/compiled/crates/swc_plugin_react_demo.wasm +0 -0
- package/dist/assetParsers/atom.js +15 -5
- package/dist/assetParsers/block.js +27 -9
- package/dist/cli.js +8 -1
- package/dist/client/pages/Demo/index.js +3 -8
- package/dist/client/theme-api/AtomRenderer.d.ts +2 -2
- package/dist/client/theme-api/AtomRenderer.js +19 -35
- package/dist/client/theme-api/DumiDemo.js +8 -13
- package/dist/client/theme-api/DumiDemoGrid.js +12 -26
- package/dist/client/theme-api/DumiPage.js +16 -34
- package/dist/client/theme-api/openCodeSandbox.js +18 -23
- package/dist/client/theme-api/openStackBlitz.js +6 -14
- package/dist/client/theme-api/types.d.ts +15 -12
- package/dist/client/theme-api/useAtomAssets.js +1 -2
- package/dist/client/theme-api/useLocale.js +10 -19
- package/dist/client/theme-api/useNavData.js +78 -103
- package/dist/client/theme-api/usePrefersColor.d.ts +2 -2
- package/dist/client/theme-api/usePrefersColor.js +39 -66
- package/dist/client/theme-api/useRouteMeta.js +9 -23
- package/dist/client/theme-api/useSidebarData.js +124 -158
- package/dist/client/theme-api/useSiteSearch/index.d.ts +1 -1
- package/dist/client/theme-api/useSiteSearch/index.js +24 -38
- package/dist/client/theme-api/useTabMeta.js +8 -19
- package/dist/client/theme-api/utils.d.ts +2 -2
- package/dist/client/theme-api/utils.js +33 -47
- package/dist/client/typings.d.ts +0 -5
- package/dist/features/assets.js +23 -4
- package/dist/features/autoAlias.js +8 -3
- package/dist/features/compile/babelLoaderCustomize.js +0 -2
- package/dist/features/compile/index.js +20 -9
- package/dist/features/configPlugins/index.js +3 -4
- package/dist/features/configPlugins/schema.d.ts +1 -1
- package/dist/features/configPlugins/schema.js +20 -3
- package/dist/features/derivative.js +54 -11
- package/dist/features/exportStatic.js +11 -7
- package/dist/features/exports.js +8 -3
- package/dist/features/html2sketch.js +7 -5
- package/dist/features/locales.js +53 -17
- package/dist/features/meta.js +23 -10
- package/dist/features/parser.js +17 -5
- package/dist/features/routes.js +63 -24
- package/dist/features/sideEffects/docSideEffectsWebpackPlugin.js +27 -16
- package/dist/features/sideEffects/index.js +13 -4
- package/dist/features/sitemap.js +17 -5
- package/dist/features/tabs.js +23 -11
- package/dist/features/theme/index.js +133 -38
- package/dist/features/theme/loader.js +23 -7
- package/dist/index.js +10 -2
- package/dist/loaders/demo/index.js +3 -3
- package/dist/loaders/markdown/index.d.ts +1 -1
- package/dist/loaders/markdown/index.js +36 -24
- package/dist/loaders/markdown/transformer/index.d.ts +2 -1
- package/dist/loaders/markdown/transformer/index.js +34 -17
- package/dist/loaders/markdown/transformer/rehypeDemo.d.ts +3 -1
- package/dist/loaders/markdown/transformer/rehypeDemo.js +125 -68
- package/dist/loaders/markdown/transformer/rehypeDesc.js +8 -3
- package/dist/loaders/markdown/transformer/rehypeEnhancedTag.js +8 -3
- package/dist/loaders/markdown/transformer/rehypeHighlightLine.js +8 -3
- package/dist/loaders/markdown/transformer/rehypeImg.js +8 -3
- package/dist/loaders/markdown/transformer/rehypeIsolation.js +36 -21
- package/dist/loaders/markdown/transformer/rehypeJsxify.js +8 -3
- package/dist/loaders/markdown/transformer/rehypeLink.d.ts +1 -1
- package/dist/loaders/markdown/transformer/rehypeLink.js +24 -9
- package/dist/loaders/markdown/transformer/rehypeRaw.d.ts +1 -1
- package/dist/loaders/markdown/transformer/rehypeRaw.js +20 -6
- package/dist/loaders/markdown/transformer/rehypeSlug.js +16 -3
- package/dist/loaders/markdown/transformer/rehypeStrip.js +8 -3
- package/dist/loaders/markdown/transformer/rehypeText.js +14 -5
- package/dist/loaders/markdown/transformer/remarkBreaks.js +16 -5
- package/dist/loaders/markdown/transformer/remarkContainer.js +28 -13
- package/dist/loaders/markdown/transformer/remarkEmbed.js +43 -21
- package/dist/loaders/markdown/transformer/remarkMeta.d.ts +3 -1
- package/dist/loaders/markdown/transformer/remarkMeta.js +39 -9
- package/dist/loaders/page/index.js +12 -4
- package/dist/loaders/pre-raw/index.js +0 -2
- package/dist/preset.js +8 -3
- package/dist/registerMethods.js +0 -2
- package/dist/service/dev.js +8 -1
- package/dist/service/printHelp.js +3 -1
- package/dist/techStacks/react.js +8 -3
- package/dist/types.d.ts +6 -6
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +15 -6
- package/package.json +11 -9
- package/theme-default/builtins/API/index.js +15 -36
- package/theme-default/builtins/Badge/index.js +0 -3
- package/theme-default/builtins/Container/index.js +6 -15
- package/theme-default/builtins/Previewer/index.js +1 -8
- package/theme-default/builtins/SourceCode/index.js +15 -27
- package/theme-default/builtins/Table/index.js +10 -25
- package/theme-default/builtins/Tree/index.js +13 -44
- package/theme-default/layouts/DocLayout/index.js +14 -27
- package/theme-default/locales/en-US.json +4 -0
- package/theme-default/locales/zh-CN.json +4 -0
- package/theme-default/slots/ColorSwitch/index.js +7 -22
- package/theme-default/slots/Content/index.js +5 -7
- package/theme-default/slots/Content/index.less +16 -1
- package/theme-default/slots/ContentFooter/index.d.ts +4 -0
- package/theme-default/slots/ContentFooter/index.js +93 -0
- package/theme-default/slots/ContentFooter/index.less +163 -0
- package/theme-default/slots/ContentTabs/index.d.ts +1 -1
- package/theme-default/slots/ContentTabs/index.js +5 -5
- package/theme-default/slots/Features/index.js +6 -11
- package/theme-default/slots/Footer/index.js +1 -4
- package/theme-default/slots/Header/index.js +7 -18
- package/theme-default/slots/HeaderExtra/index.js +0 -2
- package/theme-default/slots/Hero/index.js +2 -6
- package/theme-default/slots/HeroTitle/index.js +0 -2
- package/theme-default/slots/LangSwitch/index.js +23 -35
- package/theme-default/slots/Logo/index.js +1 -4
- package/theme-default/slots/Navbar/index.js +14 -29
- package/theme-default/slots/NavbarExtra/index.js +0 -2
- package/theme-default/slots/NotFound/index.js +0 -2
- package/theme-default/slots/PreviewerActions/index.js +13 -35
- package/theme-default/slots/PreviewerActionsExtra/index.js +0 -2
- package/theme-default/slots/RtlSwitch/index.js +6 -20
- package/theme-default/slots/RtlSwitch/index.less +5 -0
- package/theme-default/slots/SearchBar/Input.d.ts +1 -1
- package/theme-default/slots/SearchBar/Input.js +6 -5
- package/theme-default/slots/SearchBar/Mask.d.ts +1 -1
- package/theme-default/slots/SearchBar/Mask.js +0 -1
- package/theme-default/slots/SearchBar/index.js +20 -41
- package/theme-default/slots/SearchResult/index.d.ts +1 -1
- package/theme-default/slots/SearchResult/index.js +13 -36
- package/theme-default/slots/Sidebar/index.js +1 -4
- package/theme-default/slots/SocialIcon/index.d.ts +2 -2
- package/theme-default/slots/SocialIcon/index.js +1 -3
- package/theme-default/slots/Toc/index.js +12 -28
|
@@ -16,7 +16,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
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
|
+
));
|
|
20
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
28
|
|
|
22
29
|
// src/features/theme/index.ts
|
|
@@ -27,7 +34,9 @@ __export(theme_exports, {
|
|
|
27
34
|
module.exports = __toCommonJS(theme_exports);
|
|
28
35
|
var import_constants = require("../../constants");
|
|
29
36
|
var import_bundler_utils = require("@umijs/bundler-utils");
|
|
37
|
+
var import_child_process = require("child_process");
|
|
30
38
|
var import_fs = __toESM(require("fs"));
|
|
39
|
+
var import_hosted_git_info = __toESM(require("hosted-git-info"));
|
|
31
40
|
var import_path = __toESM(require("path"));
|
|
32
41
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
33
42
|
var import_derivative = require("../derivative");
|
|
@@ -35,11 +44,20 @@ var import_loader = __toESM(require("./loader"));
|
|
|
35
44
|
var DEFAULT_THEME_PATH = import_path.default.join(__dirname, "../../../theme-default");
|
|
36
45
|
function getPkgThemeName(api) {
|
|
37
46
|
if (process.env.DUMI_THEME) {
|
|
38
|
-
const envThemePkgPath = require.resolve(
|
|
47
|
+
const envThemePkgPath = require.resolve(
|
|
48
|
+
import_path.default.join(process.env.DUMI_THEME, "package.json"),
|
|
49
|
+
{ paths: [api.cwd] }
|
|
50
|
+
);
|
|
39
51
|
return require(envThemePkgPath).name;
|
|
40
52
|
}
|
|
41
|
-
const validDeps = Object.assign(
|
|
42
|
-
|
|
53
|
+
const validDeps = Object.assign(
|
|
54
|
+
{},
|
|
55
|
+
api.pkg.dependencies,
|
|
56
|
+
api.pkg.devDependencies
|
|
57
|
+
);
|
|
58
|
+
const pkgThemeName = Object.keys(validDeps).find(
|
|
59
|
+
(pkg) => pkg.split("/").pop().startsWith(import_constants.THEME_PREFIX)
|
|
60
|
+
);
|
|
43
61
|
return pkgThemeName;
|
|
44
62
|
}
|
|
45
63
|
function getPkgThemePath(api) {
|
|
@@ -47,10 +65,12 @@ function getPkgThemePath(api) {
|
|
|
47
65
|
if (process.env.DUMI_THEME) {
|
|
48
66
|
return import_path.default.resolve(api.cwd, process.env.DUMI_THEME);
|
|
49
67
|
}
|
|
50
|
-
return pkgThemeName && import_path.default.dirname(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
68
|
+
return pkgThemeName && import_path.default.dirname(
|
|
69
|
+
import_plugin_utils.resolve.sync(`${pkgThemeName}/package.json`, {
|
|
70
|
+
basedir: api.cwd,
|
|
71
|
+
preserveSymlinks: true
|
|
72
|
+
})
|
|
73
|
+
);
|
|
54
74
|
}
|
|
55
75
|
function getModuleExports(modulePath) {
|
|
56
76
|
return (0, import_bundler_utils.parseModuleSync)({
|
|
@@ -68,7 +88,10 @@ function checkMinor2ByPkg(pkg) {
|
|
|
68
88
|
var theme_default = (api) => {
|
|
69
89
|
const defaultThemeData = (0, import_loader.default)(DEFAULT_THEME_PATH);
|
|
70
90
|
const pkgThemePath = getPkgThemePath(api);
|
|
71
|
-
const pkgThemeData = (0, import_plugin_utils.deepmerge)(
|
|
91
|
+
const pkgThemeData = (0, import_plugin_utils.deepmerge)(
|
|
92
|
+
defaultThemeData,
|
|
93
|
+
pkgThemePath ? (0, import_loader.default)(import_path.default.join(pkgThemePath, "dist")) : {}
|
|
94
|
+
);
|
|
72
95
|
const localThemePath = import_path.default.join(api.cwd, import_constants.LOCAL_THEME_DIR);
|
|
73
96
|
const localThemeData = import_fs.default.existsSync(localThemePath) ? (0, import_loader.default)(localThemePath) : void 0;
|
|
74
97
|
const themeMapKeys = [
|
|
@@ -83,13 +106,18 @@ var theme_default = (api) => {
|
|
|
83
106
|
api.registerPlugins([plugin]);
|
|
84
107
|
}
|
|
85
108
|
});
|
|
86
|
-
(0, import_derivative.safeExcludeInMFSU)(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
109
|
+
(0, import_derivative.safeExcludeInMFSU)(
|
|
110
|
+
api,
|
|
111
|
+
[
|
|
112
|
+
"dumi/theme-default",
|
|
113
|
+
// for svgr
|
|
114
|
+
"@ant-design/icons-svg",
|
|
115
|
+
getPkgThemeName(api)
|
|
116
|
+
].filter(Boolean).map((pkg) => new RegExp(pkg))
|
|
117
|
+
);
|
|
91
118
|
api.register({
|
|
92
119
|
key: "modifyAppData",
|
|
120
|
+
// prepare themeData before umi appData, for generate layout routes
|
|
93
121
|
before: "appData",
|
|
94
122
|
async fn(memo) {
|
|
95
123
|
originalThemeData = await api.applyPlugins({
|
|
@@ -122,11 +150,14 @@ var theme_default = (api) => {
|
|
|
122
150
|
api.modifyAppData((memo) => {
|
|
123
151
|
memo._2LevelNavAvailable = checkMinor2ByPkg(api.pkg);
|
|
124
152
|
if (pkgThemePath && !memo._2LevelNavAvailable) {
|
|
125
|
-
memo._2LevelNavAvailable = checkMinor2ByPkg(
|
|
153
|
+
memo._2LevelNavAvailable = checkMinor2ByPkg(
|
|
154
|
+
require(import_path.default.join(pkgThemePath, "package.json"))
|
|
155
|
+
);
|
|
126
156
|
}
|
|
127
157
|
return memo;
|
|
128
158
|
});
|
|
129
159
|
api.modifyConfig((memo) => {
|
|
160
|
+
var _a, _b;
|
|
130
161
|
if (localThemeData) {
|
|
131
162
|
themeMapKeys.forEach((key) => {
|
|
132
163
|
Object.values(localThemeData[key] || {}).forEach((item) => {
|
|
@@ -135,10 +166,34 @@ var theme_default = (api) => {
|
|
|
135
166
|
});
|
|
136
167
|
}
|
|
137
168
|
memo.alias["dumi/theme"] = "dumi/theme-original";
|
|
138
|
-
memo.alias["dumi/theme-original"] = import_path.default.join(
|
|
169
|
+
memo.alias["dumi/theme-original"] = import_path.default.join(
|
|
170
|
+
api.paths.absTmpPath,
|
|
171
|
+
"dumi/theme"
|
|
172
|
+
);
|
|
139
173
|
memo.alias["dumi/theme-default"] = DEFAULT_THEME_PATH;
|
|
140
174
|
memo.extraBabelIncludes ?? (memo.extraBabelIncludes = []);
|
|
141
|
-
memo.extraBabelIncludes.push(
|
|
175
|
+
memo.extraBabelIncludes.push(
|
|
176
|
+
import_path.default.resolve(__dirname, "../../client/theme-api")
|
|
177
|
+
);
|
|
178
|
+
const repoUrl = ((_a = api.pkg.repository) == null ? void 0 : _a.url) || api.pkg.repository;
|
|
179
|
+
if (((_b = memo.themeConfig) == null ? void 0 : _b.editLink) !== false && typeof repoUrl === "string") {
|
|
180
|
+
const hostedGitIns = import_hosted_git_info.default.fromUrl(repoUrl);
|
|
181
|
+
let branch = "";
|
|
182
|
+
try {
|
|
183
|
+
branch = (0, import_child_process.execSync)("git branch --show-current", {
|
|
184
|
+
stdio: "pipe"
|
|
185
|
+
}).toString().trim();
|
|
186
|
+
} catch {
|
|
187
|
+
branch = "master";
|
|
188
|
+
}
|
|
189
|
+
if (hostedGitIns) {
|
|
190
|
+
memo.themeConfig ?? (memo.themeConfig = {});
|
|
191
|
+
memo.themeConfig.editLink = `${hostedGitIns.edit(
|
|
192
|
+
`${api.pkg.repository.directory || ""}/{filename}`,
|
|
193
|
+
{ committish: branch }
|
|
194
|
+
)}`;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
142
197
|
return memo;
|
|
143
198
|
});
|
|
144
199
|
api.chainWebpack((memo) => {
|
|
@@ -157,6 +212,45 @@ var theme_default = (api) => {
|
|
|
157
212
|
});
|
|
158
213
|
return memo;
|
|
159
214
|
});
|
|
215
|
+
api.onGenerateFiles({
|
|
216
|
+
// execute before umi tmpFiles plugin
|
|
217
|
+
stage: -Infinity,
|
|
218
|
+
fn() {
|
|
219
|
+
const { globalLoading } = api.appData;
|
|
220
|
+
const enableNProgress = !!api.config.themeConfig.nprogress;
|
|
221
|
+
api.appData.globalLoading = "@@/dumi/theme/loading";
|
|
222
|
+
api.writeTmpFile({
|
|
223
|
+
noPluginDir: true,
|
|
224
|
+
path: "dumi/theme/loading.tsx",
|
|
225
|
+
content: `${enableNProgress ? `import nprogress from '${(0, import_plugin_utils.winPath)(
|
|
226
|
+
import_path.default.dirname(require.resolve("nprogress/package"))
|
|
227
|
+
)}';
|
|
228
|
+
import './nprogress.css';` : ""}${globalLoading ? `
|
|
229
|
+
import UserLoading from '${globalLoading}';` : ""}
|
|
230
|
+
import React, { useLayoutEffect, type FC } from 'react';
|
|
231
|
+
import { useSiteData } from 'dumi';
|
|
232
|
+
|
|
233
|
+
const DumiLoading: FC = () => {
|
|
234
|
+
const { setLoading } = useSiteData();
|
|
235
|
+
|
|
236
|
+
useLayoutEffect(() => {
|
|
237
|
+
setLoading(true);${enableNProgress ? `
|
|
238
|
+
nprogress.start();` : ""}
|
|
239
|
+
|
|
240
|
+
return () => {
|
|
241
|
+
setLoading(false);${enableNProgress ? `
|
|
242
|
+
nprogress.done();` : ""}
|
|
243
|
+
}
|
|
244
|
+
}, []);
|
|
245
|
+
|
|
246
|
+
return ${globalLoading ? "<UserLoading />" : "null"};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export default DumiLoading;
|
|
250
|
+
`
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
});
|
|
160
254
|
api.onGenerateFiles(() => {
|
|
161
255
|
var _a, _b, _c, _d, _e;
|
|
162
256
|
themeMapKeys.forEach((key) => {
|
|
@@ -182,17 +276,14 @@ var theme_default = (api) => {
|
|
|
182
276
|
const entryExports = entryFile ? getModuleExports(entryFile) : [];
|
|
183
277
|
const hasDefaultExport = entryExports.includes("default");
|
|
184
278
|
const hasNamedExport = entryExports.some((exp) => exp !== "default");
|
|
185
|
-
const enableNProgress = !!api.config.themeConfig.nprogress;
|
|
186
279
|
api.writeTmpFile({
|
|
187
280
|
noPluginDir: true,
|
|
188
281
|
path: "dumi/theme/ContextWrapper.tsx",
|
|
189
282
|
content: `import React, { useState, useEffect, useRef } from 'react';
|
|
190
283
|
import { useOutlet, history } from 'dumi';
|
|
191
|
-
${
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
` : ""}
|
|
195
|
-
import { SiteContext } from '${(0, import_plugin_utils.winPath)(require.resolve("../../client/theme-api/context"))}';
|
|
284
|
+
import { SiteContext } from '${(0, import_plugin_utils.winPath)(
|
|
285
|
+
require.resolve("../../client/theme-api/context")
|
|
286
|
+
)}';
|
|
196
287
|
import { demos, components } from '../meta';
|
|
197
288
|
import { locales } from '../locales/config';${hasDefaultExport ? `
|
|
198
289
|
import entryDefaultExport from '${(0, import_plugin_utils.winPath)(entryFile)}';` : ""}${hasNamedExport ? `
|
|
@@ -213,12 +304,6 @@ export default function DumiContextWrapper() {
|
|
|
213
304
|
if (next.location.pathname !== prev.current) {
|
|
214
305
|
prev.current = next.location.pathname;
|
|
215
306
|
|
|
216
|
-
// mark loading when route change, page component will set false when loaded
|
|
217
|
-
setLoading(true);
|
|
218
|
-
|
|
219
|
-
// start nprogress
|
|
220
|
-
${enableNProgress ? `nprogress.start();` : ""}
|
|
221
|
-
|
|
222
307
|
// scroll to top when route changed
|
|
223
308
|
document.documentElement.scrollTo(0, 0);
|
|
224
309
|
}
|
|
@@ -227,7 +312,9 @@ export default function DumiContextWrapper() {
|
|
|
227
312
|
|
|
228
313
|
return (
|
|
229
314
|
<SiteContext.Provider value={{
|
|
230
|
-
pkg: ${JSON.stringify(
|
|
315
|
+
pkg: ${JSON.stringify(
|
|
316
|
+
import_plugin_utils.lodash.pick(api.pkg, ...Object.keys(import_constants.PICKED_PKG_FIELDS))
|
|
317
|
+
)},
|
|
231
318
|
historyType: "${((_a = api.config.history) == null ? void 0 : _a.type) || "browser"}",
|
|
232
319
|
entryExports,
|
|
233
320
|
demos,
|
|
@@ -236,7 +323,12 @@ export default function DumiContextWrapper() {
|
|
|
236
323
|
loading,
|
|
237
324
|
setLoading,
|
|
238
325
|
hostname: ${JSON.stringify((_b = api.config.sitemap) == null ? void 0 : _b.hostname)},
|
|
239
|
-
themeConfig: ${JSON.stringify(
|
|
326
|
+
themeConfig: ${JSON.stringify(
|
|
327
|
+
Object.assign(
|
|
328
|
+
import_plugin_utils.lodash.pick(api.config, "logo", "description", "title"),
|
|
329
|
+
api.config.themeConfig
|
|
330
|
+
)
|
|
331
|
+
)},
|
|
240
332
|
_2_level_nav_available: ${api.appData._2LevelNavAvailable},
|
|
241
333
|
}}>
|
|
242
334
|
{outlet}
|
|
@@ -344,16 +436,19 @@ export default function DumiContextWrapper() {
|
|
|
344
436
|
"modifyCodeSandboxData",
|
|
345
437
|
"modifyStackBlitzData"
|
|
346
438
|
]);
|
|
347
|
-
if (
|
|
439
|
+
if (
|
|
440
|
+
/*isTnpm*/
|
|
441
|
+
require("@umijs/core/package").__npminstall_done && import_fs.default.existsSync(localThemePath) && import_fs.default.lstatSync(localThemePath).isSymbolicLink()
|
|
442
|
+
) {
|
|
348
443
|
api.chainWebpack((memo) => {
|
|
349
444
|
const devThemeNodeModules = import_path.default.join(api.cwd, "../node_modules");
|
|
350
|
-
memo.snapshot(
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
445
|
+
memo.snapshot(
|
|
446
|
+
(0, import_plugin_utils.deepmerge)(memo.get("snapshot"), {
|
|
447
|
+
immutablePaths: [devThemeNodeModules],
|
|
448
|
+
managedPaths: [devThemeNodeModules]
|
|
449
|
+
})
|
|
450
|
+
);
|
|
354
451
|
return memo;
|
|
355
452
|
});
|
|
356
453
|
}
|
|
357
454
|
};
|
|
358
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
359
|
-
0 && (module.exports = {});
|
|
@@ -16,7 +16,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
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
|
+
));
|
|
20
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
28
|
|
|
22
29
|
// src/features/theme/loader.ts
|
|
@@ -29,7 +36,9 @@ var import_path = __toESM(require("path"));
|
|
|
29
36
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
30
37
|
function getComponentMapFromDir(globExp, dir) {
|
|
31
38
|
return import_plugin_utils.glob.sync(globExp, { cwd: dir }).reduce((ret, file) => {
|
|
32
|
-
const specifier = import_path.default.basename(
|
|
39
|
+
const specifier = import_path.default.basename(
|
|
40
|
+
(0, import_plugin_utils.winPath)(file).replace(/(\/index)?\.[a-z]+$/, "")
|
|
41
|
+
);
|
|
33
42
|
if (/^[A-Z\d]/.test(specifier)) {
|
|
34
43
|
ret[specifier] = {
|
|
35
44
|
specifier,
|
|
@@ -54,11 +63,18 @@ var loader_default = (dir) => {
|
|
|
54
63
|
name: import_path.default.basename(dir),
|
|
55
64
|
path: dir,
|
|
56
65
|
locales: getLocaleMapFromDir("locales/*.json", dir),
|
|
57
|
-
builtins: getComponentMapFromDir(
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
builtins: getComponentMapFromDir(
|
|
67
|
+
"builtins/{!(*.d),*/index}.{js,jsx,ts,tsx}",
|
|
68
|
+
dir
|
|
69
|
+
),
|
|
70
|
+
slots: getComponentMapFromDir(
|
|
71
|
+
"slots/{!(*.d),*/index}.{js,jsx,ts,tsx}",
|
|
72
|
+
dir
|
|
73
|
+
),
|
|
74
|
+
layouts: getComponentMapFromDir(
|
|
75
|
+
"layouts/{GlobalLayout,DocLayout,DemoLayout}{.,/index.}{js,jsx,ts,tsx}",
|
|
76
|
+
dir
|
|
77
|
+
),
|
|
60
78
|
...plugin ? { plugin: import_path.default.join(dir, plugin) } : {}
|
|
61
79
|
};
|
|
62
80
|
};
|
|
63
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
-
0 && (module.exports = {});
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
21
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
29
|
|
|
23
30
|
// src/index.ts
|
|
@@ -36,5 +43,6 @@ var defineConfig = (config) => config;
|
|
|
36
43
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
44
|
0 && (module.exports = {
|
|
38
45
|
defineConfig,
|
|
39
|
-
unistUtilVisit
|
|
46
|
+
unistUtilVisit,
|
|
47
|
+
...require("umi")
|
|
40
48
|
});
|
|
@@ -24,12 +24,12 @@ __export(demo_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(demo_exports);
|
|
25
25
|
function demoLoader(raw) {
|
|
26
26
|
const opts = this.getOptions();
|
|
27
|
-
const techStackName = new URLSearchParams(this.resourceQuery).get(
|
|
27
|
+
const techStackName = new URLSearchParams(this.resourceQuery).get(
|
|
28
|
+
"techStack"
|
|
29
|
+
);
|
|
28
30
|
const techStack = opts.techStacks.find((t) => t.name === techStackName);
|
|
29
31
|
return techStack.transformCode(raw, {
|
|
30
32
|
type: "external",
|
|
31
33
|
fileAbsPath: this.resourcePath
|
|
32
34
|
});
|
|
33
35
|
}
|
|
34
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
-
0 && (module.exports = {});
|
|
@@ -9,6 +9,6 @@ interface IMdLoaderDemosModeOptions extends Omit<IMdLoaderDefaultModeOptions, 'b
|
|
|
9
9
|
onResolveDemos?: (demos: NonNullable<IMdTransformerResult['meta']['demos']>) => void;
|
|
10
10
|
onResolveAtomMeta?: (atomId: string, meta: IMdTransformerResult['meta']['frontmatter']) => void;
|
|
11
11
|
}
|
|
12
|
-
export
|
|
12
|
+
export type IMdLoaderOptions = IMdLoaderDefaultModeOptions | IMdLoaderDemosModeOptions;
|
|
13
13
|
export default function mdLoader(this: any, content: string): void;
|
|
14
14
|
export {};
|
|
@@ -16,7 +16,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
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
|
+
));
|
|
20
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
28
|
|
|
22
29
|
// src/loaders/markdown/index.ts
|
|
@@ -51,7 +58,8 @@ function emit(opts, ret) {
|
|
|
51
58
|
if (frontmatter.atomId && opts.onResolveAtomMeta) {
|
|
52
59
|
opts.onResolveAtomMeta(frontmatter.atomId, frontmatter);
|
|
53
60
|
}
|
|
54
|
-
return import_plugin_utils.Mustache.render(
|
|
61
|
+
return import_plugin_utils.Mustache.render(
|
|
62
|
+
`import React from 'react';
|
|
55
63
|
|
|
56
64
|
export const demos = {
|
|
57
65
|
{{#demos}}
|
|
@@ -64,25 +72,27 @@ export const demos = {
|
|
|
64
72
|
export const frontmatter = {{{frontmatter}}};
|
|
65
73
|
export const toc = {{{toc}}};
|
|
66
74
|
export const texts = {{{texts}}};
|
|
67
|
-
`,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
`,
|
|
76
|
+
{
|
|
77
|
+
demos,
|
|
78
|
+
frontmatter: JSON.stringify(frontmatter),
|
|
79
|
+
toc: JSON.stringify(toc),
|
|
80
|
+
texts: JSON.stringify(texts),
|
|
81
|
+
renderAsset: function renderAsset() {
|
|
82
|
+
if (!("asset" in this))
|
|
83
|
+
return "null";
|
|
84
|
+
let { asset } = this;
|
|
85
|
+
const { sources } = this;
|
|
86
|
+
Object.keys(this.sources).forEach((file) => {
|
|
87
|
+
if (!asset.dependencies[file])
|
|
88
|
+
return;
|
|
89
|
+
asset = import_plugin_utils.lodash.cloneDeep(asset);
|
|
90
|
+
asset.dependencies[file].value = `{{{require('-!${sources[file]}?dumi-raw').default}}}`;
|
|
91
|
+
});
|
|
92
|
+
return JSON.stringify(asset, null, 2).replace(/"{{{|}}}"/g, "");
|
|
93
|
+
}
|
|
84
94
|
}
|
|
85
|
-
|
|
95
|
+
);
|
|
86
96
|
} else {
|
|
87
97
|
const isTabContent = (0, import_tabs.isTabRouteFile)(this.resourcePath);
|
|
88
98
|
return `${Object.values(opts.builtins).map((item) => `import ${item.specifier} from '${item.source}';`).join("\n")}
|
|
@@ -100,7 +110,9 @@ export default DumiMarkdownContent;`;
|
|
|
100
110
|
}
|
|
101
111
|
}
|
|
102
112
|
function getDepsCacheKey(deps = []) {
|
|
103
|
-
return JSON.stringify(
|
|
113
|
+
return JSON.stringify(
|
|
114
|
+
deps.map((file) => `${file}:${import_fs.default.statSync(file).mtimeMs}`)
|
|
115
|
+
);
|
|
104
116
|
}
|
|
105
117
|
var deferrer = {};
|
|
106
118
|
var depsMapping = {};
|
|
@@ -132,7 +144,9 @@ function mdLoader(content) {
|
|
|
132
144
|
fileAbsPath: (0, import_plugin_utils.winPath)(this.resourcePath)
|
|
133
145
|
});
|
|
134
146
|
deferrer[cacheKey].then((ret) => {
|
|
135
|
-
depsMapping[this.resourcePath] = ret.meta.embeds.concat(
|
|
147
|
+
depsMapping[this.resourcePath] = ret.meta.embeds.concat(
|
|
148
|
+
getDemoSourceFiles(ret.meta.demos)
|
|
149
|
+
);
|
|
136
150
|
const finalCacheKey = [
|
|
137
151
|
baseCacheKey,
|
|
138
152
|
getDepsCacheKey(depsMapping[this.resourcePath])
|
|
@@ -142,5 +156,3 @@ function mdLoader(content) {
|
|
|
142
156
|
delete deferrer[cacheKey];
|
|
143
157
|
}).catch(cb);
|
|
144
158
|
}
|
|
145
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
146
|
-
0 && (module.exports = {});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IParsedBlockAsset } from "../../../assetParsers/block";
|
|
2
|
-
import type { IRouteMeta } from "../../../client/theme-api/types";
|
|
2
|
+
import type { ILocalesConfig, IRouteMeta } from "../../../client/theme-api/types";
|
|
3
3
|
import type { IApi, IDumiConfig, IDumiTechStack } from "../../../types";
|
|
4
4
|
import type { IRoute } from 'umi';
|
|
5
5
|
import type { Data } from 'vfile';
|
|
@@ -42,6 +42,7 @@ export interface IMdTransformerOptions {
|
|
|
42
42
|
extraRemarkPlugins?: IDumiConfig['extraRemarkPlugins'];
|
|
43
43
|
extraRehypePlugins?: IDumiConfig['extraRehypePlugins'];
|
|
44
44
|
routes: Record<string, IRoute>;
|
|
45
|
+
locales: ILocalesConfig;
|
|
45
46
|
pkg: IApi['pkg'];
|
|
46
47
|
}
|
|
47
48
|
export interface IMdTransformerResult {
|
|
@@ -16,7 +16,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
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
|
+
));
|
|
20
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
28
|
|
|
22
29
|
// src/loaders/markdown/transformer/index.ts
|
|
@@ -58,7 +65,8 @@ function applyUnifiedPlugin(opts) {
|
|
|
58
65
|
opts.processor.use(fn, options);
|
|
59
66
|
}
|
|
60
67
|
var transformer_default = async (raw, opts) => {
|
|
61
|
-
var _a, _b;
|
|
68
|
+
var _a, _b, _c;
|
|
69
|
+
let fileLocaleLessPath = opts.fileAbsPath;
|
|
62
70
|
const { unified } = await import("unified");
|
|
63
71
|
const { default: remarkParse } = await import("remark-parse");
|
|
64
72
|
const { default: remarkFrontmatter } = await import("remark-frontmatter");
|
|
@@ -71,43 +79,52 @@ var transformer_default = async (raw, opts) => {
|
|
|
71
79
|
extensions: [".js", ".jsx", ".ts", ".tsx"],
|
|
72
80
|
alias: opts.alias
|
|
73
81
|
});
|
|
82
|
+
const fileLocale = (_a = opts.locales.find(
|
|
83
|
+
(locale) => opts.fileAbsPath.endsWith(`.${locale.id}.md`)
|
|
84
|
+
)) == null ? void 0 : _a.id;
|
|
85
|
+
if (fileLocale) {
|
|
86
|
+
fileLocaleLessPath = opts.fileAbsPath.replace(`.${fileLocale}.md`, ".md");
|
|
87
|
+
}
|
|
74
88
|
const processor = unified().use(remarkParse).use(import_remarkEmbed.default, { fileAbsPath: opts.fileAbsPath, alias: opts.alias }).use(remarkFrontmatter).use(import_remarkMeta.default, {
|
|
75
89
|
cwd: opts.cwd,
|
|
76
90
|
fileAbsPath: opts.fileAbsPath,
|
|
91
|
+
fileLocaleLessPath,
|
|
77
92
|
resolve: opts.resolve
|
|
78
93
|
}).use(remarkDirective).use(import_remarkContainer.default).use(remarkGfm);
|
|
79
94
|
if (keepSoftBreak(opts.pkg)) {
|
|
80
95
|
processor.use(import_remarkBreaks.default, { fileAbsPath: opts.fileAbsPath });
|
|
81
96
|
}
|
|
82
|
-
(
|
|
83
|
-
plugin
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
97
|
+
(_b = opts.extraRemarkPlugins) == null ? void 0 : _b.forEach(
|
|
98
|
+
(plugin) => applyUnifiedPlugin({
|
|
99
|
+
plugin,
|
|
100
|
+
processor,
|
|
101
|
+
cwd: opts.cwd
|
|
102
|
+
})
|
|
103
|
+
);
|
|
87
104
|
processor.use(remarkRehype, { allowDangerousHtml: true }).use(import_rehypeRaw.default, {
|
|
88
105
|
fileAbsPath: opts.fileAbsPath
|
|
89
|
-
}).use(import_rehypeHighlightLine.default, {
|
|
90
|
-
resolve: opts.resolve
|
|
91
|
-
}).use(rehypeRemoveComments, { removeConditional: true }).use(import_rehypeStrip.default).use(import_rehypeImg.default).use(import_rehypeDemo.default, {
|
|
106
|
+
}).use(import_rehypeHighlightLine.default).use(rehypeRemoveComments, { removeConditional: true }).use(import_rehypeStrip.default).use(import_rehypeImg.default).use(import_rehypeDemo.default, {
|
|
92
107
|
techStacks: opts.techStacks,
|
|
93
108
|
cwd: opts.cwd,
|
|
94
109
|
fileAbsPath: opts.fileAbsPath,
|
|
110
|
+
fileLocaleLessPath,
|
|
111
|
+
fileLocale,
|
|
95
112
|
resolve: opts.resolve,
|
|
96
113
|
resolver
|
|
97
114
|
}).use(import_rehypeSlug.default).use(import_rehypeLink.default, {
|
|
98
115
|
fileAbsPath: opts.fileAbsPath,
|
|
99
116
|
routes: opts.routes
|
|
100
117
|
}).use(rehypeAutolinkHeadings).use(import_rehypeIsolation.default).use(import_rehypeEnhancedTag.default).use(import_rehypeDesc.default).use(import_rehypeText.default);
|
|
101
|
-
(
|
|
102
|
-
plugin
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
118
|
+
(_c = opts.extraRehypePlugins) == null ? void 0 : _c.forEach(
|
|
119
|
+
(plugin) => applyUnifiedPlugin({
|
|
120
|
+
plugin,
|
|
121
|
+
processor,
|
|
122
|
+
cwd: opts.cwd
|
|
123
|
+
})
|
|
124
|
+
);
|
|
106
125
|
const result = await processor.use(import_rehypeJsxify.default).process(raw);
|
|
107
126
|
return {
|
|
108
127
|
content: String(result.value),
|
|
109
128
|
meta: result.data
|
|
110
129
|
};
|
|
111
130
|
};
|
|
112
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
-
0 && (module.exports = {});
|
|
@@ -5,8 +5,10 @@ import type { IMdTransformerOptions } from '.';
|
|
|
5
5
|
export declare const DEMO_PROP_VALUE_KEY = "$demo-prop-value-key";
|
|
6
6
|
export declare const DUMI_DEMO_TAG = "DumiDemo";
|
|
7
7
|
export declare const DUMI_DEMO_GRID_TAG = "DumiDemoGrid";
|
|
8
|
-
|
|
8
|
+
type IRehypeDemoOptions = Pick<IMdTransformerOptions, 'techStacks' | 'cwd' | 'fileAbsPath' | 'resolve'> & {
|
|
9
9
|
resolver: typeof sync;
|
|
10
|
+
fileLocaleLessPath: string;
|
|
11
|
+
fileLocale?: string;
|
|
10
12
|
};
|
|
11
13
|
export default function rehypeDemo(opts: IRehypeDemoOptions): Transformer<Root>;
|
|
12
14
|
export {};
|