dumi 2.0.0-alpha.1 → 2.0.0-alpha.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.
- package/dist/assetParsers/block.js +1 -1
- package/dist/client/theme-api/DumiDemoGrid.js +56 -6
- package/dist/client/theme-api/context.d.ts +2 -6
- package/dist/client/theme-api/index.d.ts +1 -0
- package/dist/client/theme-api/index.js +2 -1
- package/dist/client/theme-api/types.d.ts +27 -0
- package/dist/client/theme-api/useMatchedRouteMeta.d.ts +5 -0
- package/dist/client/theme-api/useMatchedRouteMeta.js +55 -0
- package/dist/client/tsconfig.json +2 -0
- package/dist/features/compile.js +20 -3
- package/dist/features/configPlugins/index.js +2 -1
- package/dist/features/configPlugins/schema.js +8 -2
- package/dist/features/locales.js +19 -7
- package/dist/features/meta.d.ts +3 -0
- package/dist/features/meta.js +77 -0
- package/dist/features/routes.js +17 -4
- package/dist/features/sideEffects/docSideEffectsWebpackPlugin.d.ts +14 -0
- package/dist/features/sideEffects/docSideEffectsWebpackPlugin.js +50 -0
- package/dist/features/sideEffects/index.d.ts +7 -0
- package/dist/features/sideEffects/index.js +47 -0
- package/dist/features/theme/index.js +5 -28
- package/dist/index.d.ts +8 -2
- package/dist/index.js +16 -3
- package/dist/loaders/markdown/index.d.ts +1 -1
- package/dist/loaders/markdown/index.js +22 -7
- package/dist/loaders/markdown/transformer/index.d.ts +6 -1
- package/dist/loaders/markdown/transformer/index.js +27 -3
- package/dist/loaders/markdown/transformer/rehypeDemo.d.ts +1 -1
- package/dist/loaders/markdown/transformer/rehypeDemo.js +41 -16
- package/dist/loaders/markdown/transformer/rehypeEmbed.d.ts +4 -0
- package/dist/loaders/markdown/transformer/rehypeEmbed.js +75 -0
- package/dist/loaders/markdown/transformer/rehypeRaw.js +9 -1
- package/dist/loaders/markdown/transformer/remarkMeta.d.ts +3 -0
- package/dist/loaders/markdown/transformer/remarkMeta.js +44 -0
- package/dist/preset.js +2 -0
- package/dist/types.d.ts +14 -6
- package/dist/utils.d.ts +11 -0
- package/dist/utils.js +25 -1
- package/package.json +11 -9
- package/theme-default/layouts/DocLayout/index.d.ts +3 -0
- package/theme-default/layouts/DocLayout/index.js +16 -0
- package/theme-default/slots/Content/index.d.ts +5 -0
- package/theme-default/slots/Content/index.js +13 -0
- package/theme-default/slots/Header/index.d.ts +3 -0
- package/theme-default/slots/Header/index.js +17 -0
- package/theme-default/slots/Logo/index.d.ts +3 -0
- package/theme-default/slots/Logo/index.js +7 -0
- package/theme-default/slots/Navbar/index.d.ts +3 -0
- package/theme-default/slots/Navbar/index.js +7 -0
- package/theme-default/slots/SearchBar/index.d.ts +3 -0
- package/theme-default/slots/SearchBar/index.js +9 -0
- package/theme-default/slots/Sidebar/index.d.ts +3 -0
- package/theme-default/slots/Sidebar/index.js +14 -0
|
@@ -37,14 +37,14 @@ function getPkgThemePath(api) {
|
|
|
37
37
|
return pkgThemeName && import_path.default.basename(require.resolve(`${pkgThemeName}/package.json`, { paths: [api.cwd] }));
|
|
38
38
|
}
|
|
39
39
|
var theme_default = (api) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const mdRouteFiles = [];
|
|
40
|
+
const localThemePath = import_path.default.join(api.cwd, import_constants.LOCAL_THEME_DIR);
|
|
41
|
+
const localThemeData = import_fs.default.existsSync(localThemePath) && (0, import_loader.default)(localThemePath);
|
|
43
42
|
const themeMapKeys = [
|
|
44
43
|
"layouts",
|
|
45
44
|
"builtins",
|
|
46
45
|
"slots"
|
|
47
46
|
];
|
|
47
|
+
let originalThemeData;
|
|
48
48
|
api.describe({ key: "dumi:theme" });
|
|
49
49
|
api.register({
|
|
50
50
|
key: "modifyAppData",
|
|
@@ -58,9 +58,7 @@ var theme_default = (api) => {
|
|
|
58
58
|
initialValue: pkgThemeData
|
|
59
59
|
});
|
|
60
60
|
api.service.themeData = originalThemeData;
|
|
61
|
-
|
|
62
|
-
if (import_fs.default.existsSync(localThemePath)) {
|
|
63
|
-
localThemeData = (0, import_loader.default)(localThemePath);
|
|
61
|
+
if (localThemeData) {
|
|
64
62
|
api.service.themeData = (0, import_plugin_utils.deepmerge)(originalThemeData, localThemeData, {
|
|
65
63
|
clone: true
|
|
66
64
|
});
|
|
@@ -94,14 +92,6 @@ var theme_default = (api) => {
|
|
|
94
92
|
memo.extraBabelIncludes.push(import_path.default.resolve(__dirname, "../../client/theme-api"));
|
|
95
93
|
return memo;
|
|
96
94
|
});
|
|
97
|
-
api.modifyRoutes((routes) => {
|
|
98
|
-
Object.values(routes).forEach((route) => {
|
|
99
|
-
if (route.file.endsWith(".md")) {
|
|
100
|
-
mdRouteFiles.push({ index: mdRouteFiles.length, file: route.file });
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
return routes;
|
|
104
|
-
});
|
|
105
95
|
api.onGenerateFiles(() => {
|
|
106
96
|
themeMapKeys.forEach((key) => {
|
|
107
97
|
Object.values(originalThemeData[key] || {}).forEach((item) => {
|
|
@@ -113,25 +103,12 @@ export { default } from '${item.source}';`
|
|
|
113
103
|
});
|
|
114
104
|
});
|
|
115
105
|
});
|
|
116
|
-
api.writeTmpFile({
|
|
117
|
-
noPluginDir: true,
|
|
118
|
-
path: "dumi/demos.ts",
|
|
119
|
-
content: import_plugin_utils.Mustache.render(`{{#mdRouteFiles}}
|
|
120
|
-
import demos{{{index}}} from '{{{file}}}?type=meta.demos';
|
|
121
|
-
{{/mdRouteFiles}}
|
|
122
|
-
|
|
123
|
-
export default {
|
|
124
|
-
{{#mdRouteFiles}}
|
|
125
|
-
...demos{{{index}}},
|
|
126
|
-
{{/mdRouteFiles}}
|
|
127
|
-
}`, { mdRouteFiles })
|
|
128
|
-
});
|
|
129
106
|
api.writeTmpFile({
|
|
130
107
|
noPluginDir: true,
|
|
131
108
|
path: "dumi/theme/ContextWrapper.tsx",
|
|
132
109
|
content: `import { Context } from 'dumi/theme';
|
|
133
110
|
import { useOutlet } from 'umi';
|
|
134
|
-
import demos from '../
|
|
111
|
+
import { demos } from '../meta';
|
|
135
112
|
import { locales } from '../locales/config';
|
|
136
113
|
|
|
137
114
|
export default function DumiContextWrapper() {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { IDumiConfig } from "./types";
|
|
2
|
+
declare let unistUtilVisit: typeof import('unist-util-visit');
|
|
3
|
+
export { IApi } from "./types";
|
|
4
|
+
export type { Root as HastRoot } from 'hast';
|
|
5
|
+
export * from 'umi';
|
|
6
|
+
export type { Plugin as UnifiedPlugin, Transformer as UnifiedTransformer, } from 'unified';
|
|
7
|
+
export { unistUtilVisit };
|
|
8
|
+
export declare const defineConfig: (config: IDumiConfig) => IDumiConfig;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,14 +16,25 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
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(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
17
21
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
22
|
|
|
19
23
|
// src/index.ts
|
|
20
24
|
var src_exports = {};
|
|
21
25
|
__export(src_exports, {
|
|
22
|
-
|
|
26
|
+
defineConfig: () => defineConfig,
|
|
27
|
+
unistUtilVisit: () => unistUtilVisit
|
|
23
28
|
});
|
|
24
29
|
module.exports = __toCommonJS(src_exports);
|
|
25
|
-
|
|
30
|
+
__reExport(src_exports, require("umi"), module.exports);
|
|
31
|
+
var unistUtilVisit;
|
|
32
|
+
(async () => {
|
|
33
|
+
unistUtilVisit = await import("unist-util-visit");
|
|
34
|
+
})();
|
|
35
|
+
var defineConfig = (config) => config;
|
|
26
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
-
0 && (module.exports = {
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
defineConfig,
|
|
39
|
+
unistUtilVisit
|
|
40
|
+
});
|
|
@@ -5,7 +5,7 @@ interface IMdLoaderDefaultModeOptions extends Omit<IMdTransformerOptions, 'fileA
|
|
|
5
5
|
builtins: IThemeLoadResult['builtins'];
|
|
6
6
|
}
|
|
7
7
|
interface IMdLoaderDemosModeOptions extends Omit<IMdLoaderDefaultModeOptions, 'builtins' | 'mode'> {
|
|
8
|
-
mode: '
|
|
8
|
+
mode: 'meta';
|
|
9
9
|
}
|
|
10
10
|
export declare type IMdLoaderOptions = IMdLoaderDefaultModeOptions | IMdLoaderDemosModeOptions;
|
|
11
11
|
export default function mdLoader(this: any, raw: string): void;
|
|
@@ -25,28 +25,42 @@ __export(markdown_exports, {
|
|
|
25
25
|
default: () => mdLoader
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(markdown_exports);
|
|
28
|
+
var import_utils = require("../../utils");
|
|
28
29
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
29
30
|
var import_transformer = __toESM(require("./transformer"));
|
|
30
31
|
function mdLoader(raw) {
|
|
31
32
|
const opts = this.getOptions();
|
|
32
33
|
const cb = this.async();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
let content = raw;
|
|
35
|
+
const params = new URLSearchParams(this.resourceQuery);
|
|
36
|
+
const range = params.get("range");
|
|
37
|
+
const regexp = params.get("regexp");
|
|
38
|
+
if (range) {
|
|
39
|
+
content = (0, import_utils.getFileRangeLines)(content, range);
|
|
40
|
+
} else if (regexp) {
|
|
41
|
+
content = (0, import_utils.getFileContentByRegExp)(content, regexp, this.resourcePath);
|
|
42
|
+
}
|
|
43
|
+
(0, import_transformer.default)(content, {
|
|
44
|
+
...import_plugin_utils.lodash.omit(opts, ["mode", "builtins"]),
|
|
36
45
|
fileAbsPath: this.resourcePath
|
|
37
46
|
}).then((ret) => {
|
|
38
|
-
if (opts.mode === "
|
|
47
|
+
if (opts.mode === "meta") {
|
|
48
|
+
const { demos, frontmatter = {} } = ret.meta;
|
|
39
49
|
cb(null, import_plugin_utils.Mustache.render(`import React from 'react';
|
|
40
50
|
|
|
41
|
-
export
|
|
51
|
+
export const demos = {
|
|
42
52
|
{{#demos}}
|
|
43
53
|
'{{{id}}}': {
|
|
44
54
|
component: {{{component}}},
|
|
45
55
|
asset: {{{renderAsset}}}
|
|
46
56
|
},
|
|
47
57
|
{{/demos}}
|
|
48
|
-
}
|
|
49
|
-
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const frontmatter = {{{frontmatter}}};
|
|
61
|
+
`, {
|
|
62
|
+
demos,
|
|
63
|
+
frontmatter: JSON.stringify(frontmatter),
|
|
50
64
|
renderAsset: function renderAsset() {
|
|
51
65
|
Object.keys(this.sources).forEach((file) => {
|
|
52
66
|
this.asset.dependencies[file].value = `{{{require('!!raw-loader!${this.sources[file]}?raw').default}}}`;
|
|
@@ -56,6 +70,7 @@ export default {
|
|
|
56
70
|
}));
|
|
57
71
|
} else {
|
|
58
72
|
cb(null, `${Object.values(opts.builtins).map((item) => `import ${item.specifier} from '${item.source}';`).join("\n")}
|
|
73
|
+
import React from 'react';
|
|
59
74
|
|
|
60
75
|
// export named function for fastRefresh
|
|
61
76
|
// ref: https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/docs/TROUBLESHOOTING.md#edits-always-lead-to-full-reload
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IParsedBlockAsset } from "../../../assetParsers/block";
|
|
2
|
-
import type {
|
|
2
|
+
import type { IRouteMeta } from "../../../client/theme-api";
|
|
3
|
+
import type { IDumiConfig, IDumiTechStack } from "../../../types";
|
|
3
4
|
import type { DataMap } from 'vfile';
|
|
4
5
|
declare module 'hast' {
|
|
5
6
|
interface Element {
|
|
@@ -21,12 +22,16 @@ declare module 'vfile' {
|
|
|
21
22
|
asset: IParsedBlockAsset['asset'];
|
|
22
23
|
sources: IParsedBlockAsset['sources'];
|
|
23
24
|
}[];
|
|
25
|
+
frontmatter: IRouteMeta;
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
export interface IMdTransformerOptions {
|
|
27
29
|
cwd: string;
|
|
28
30
|
fileAbsPath: string;
|
|
29
31
|
techStacks: IDumiTechStack[];
|
|
32
|
+
codeBlockMode: IDumiConfig['resolve']['codeBlockMode'];
|
|
33
|
+
extraRemarkPlugins?: IDumiConfig['extraRemarkPlugins'];
|
|
34
|
+
extraRehypePlugins?: IDumiConfig['extraRehypePlugins'];
|
|
30
35
|
}
|
|
31
36
|
export interface IMdTransformerResult {
|
|
32
37
|
content: string;
|
|
@@ -26,22 +26,46 @@ __export(transformer_exports, {
|
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(transformer_exports);
|
|
28
28
|
var import_rehypeDemo = __toESM(require("./rehypeDemo"));
|
|
29
|
+
var import_rehypeEmbed = __toESM(require("./rehypeEmbed"));
|
|
29
30
|
var import_rehypeIsolation = __toESM(require("./rehypeIsolation"));
|
|
30
31
|
var import_rehypeJsxify = __toESM(require("./rehypeJsxify"));
|
|
31
32
|
var import_rehypeRaw = __toESM(require("./rehypeRaw"));
|
|
32
33
|
var import_rehypeStrip = __toESM(require("./rehypeStrip"));
|
|
34
|
+
var import_remarkMeta = __toESM(require("./remarkMeta"));
|
|
35
|
+
function applyUnifiedPlugin(opts) {
|
|
36
|
+
const [plugin, options] = Array.isArray(opts.plugin) ? opts.plugin : [opts.plugin];
|
|
37
|
+
const mod = typeof plugin === "function" ? plugin : require(require.resolve(plugin, { paths: [opts.cwd] }));
|
|
38
|
+
const fn = mod.default || mod;
|
|
39
|
+
opts.processor.use(fn, options);
|
|
40
|
+
}
|
|
33
41
|
var transformer_default = async (raw, opts) => {
|
|
42
|
+
var _a, _b;
|
|
34
43
|
const { unified } = await import("unified");
|
|
35
44
|
const { default: remarkParse } = await import("remark-parse");
|
|
36
45
|
const { default: remarkFrontmatter } = await import("remark-frontmatter");
|
|
37
46
|
const { default: remarkBreaks } = await import("remark-breaks");
|
|
38
47
|
const { default: remarkGfm } = await import("remark-gfm");
|
|
39
48
|
const { default: remarkRehype } = await import("remark-rehype");
|
|
40
|
-
const
|
|
49
|
+
const processor = unified().use(remarkParse).use(remarkFrontmatter).use(import_remarkMeta.default).use(remarkBreaks).use(remarkGfm);
|
|
50
|
+
(_a = opts.extraRemarkPlugins) == null ? void 0 : _a.forEach((plugin) => applyUnifiedPlugin({
|
|
51
|
+
plugin,
|
|
52
|
+
processor,
|
|
53
|
+
cwd: opts.cwd
|
|
54
|
+
}));
|
|
55
|
+
processor.use(remarkRehype, { allowDangerousHtml: true }).use(import_rehypeRaw.default).use(import_rehypeStrip.default).use(import_rehypeEmbed.default, {
|
|
56
|
+
fileAbsPath: opts.fileAbsPath
|
|
57
|
+
}).use(import_rehypeDemo.default, {
|
|
41
58
|
techStacks: opts.techStacks,
|
|
42
59
|
cwd: opts.cwd,
|
|
43
|
-
fileAbsPath: opts.fileAbsPath
|
|
44
|
-
|
|
60
|
+
fileAbsPath: opts.fileAbsPath,
|
|
61
|
+
codeBlockMode: opts.codeBlockMode
|
|
62
|
+
}).use(import_rehypeIsolation.default);
|
|
63
|
+
(_b = opts.extraRehypePlugins) == null ? void 0 : _b.forEach((plugin) => applyUnifiedPlugin({
|
|
64
|
+
plugin,
|
|
65
|
+
processor,
|
|
66
|
+
cwd: opts.cwd
|
|
67
|
+
}));
|
|
68
|
+
const result = await processor.use(import_rehypeJsxify.default).process(raw);
|
|
45
69
|
return {
|
|
46
70
|
content: String(result.value),
|
|
47
71
|
meta: result.data
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Root } from 'hast';
|
|
2
2
|
import type { Transformer } from 'unified';
|
|
3
3
|
import type { IMdTransformerOptions } from '.';
|
|
4
|
-
declare type IRehypeDemoOptions = Pick<IMdTransformerOptions, 'techStacks' | 'cwd' | 'fileAbsPath'>;
|
|
4
|
+
declare type IRehypeDemoOptions = Pick<IMdTransformerOptions, 'techStacks' | 'cwd' | 'fileAbsPath' | 'codeBlockMode'>;
|
|
5
5
|
export default function rehypeDemo(opts: IRehypeDemoOptions): Transformer<Root>;
|
|
6
6
|
export {};
|
|
@@ -40,25 +40,25 @@ var DEMO_PROP_VALUE_KEY = "$demo-prop-value-key";
|
|
|
40
40
|
({ toString } = await import("mdast-util-to-string"));
|
|
41
41
|
({ isElement } = await import("hast-util-is-element"));
|
|
42
42
|
})();
|
|
43
|
-
function getCodeLang(node) {
|
|
44
|
-
var _a, _b;
|
|
43
|
+
function getCodeLang(node, opts) {
|
|
44
|
+
var _a, _b, _c, _d;
|
|
45
45
|
let lang = "";
|
|
46
46
|
if (typeof ((_a = node.properties) == null ? void 0 : _a.src) === "string") {
|
|
47
47
|
lang = import_path.default.extname(node.properties.src).slice(1);
|
|
48
|
-
} else if (Array.isArray((_b = node.properties) == null ? void 0 : _b.className)) {
|
|
48
|
+
} else if (Array.isArray((_b = node.properties) == null ? void 0 : _b.className) && (opts.codeBlockMode === "passive" ? / demo/.test(String((_c = node.data) == null ? void 0 : _c.meta)) : !/ pure/.test(String((_d = node.data) == null ? void 0 : _d.meta)))) {
|
|
49
49
|
lang = String(node.properties.className[0]).replace("language-", "");
|
|
50
50
|
}
|
|
51
51
|
return lang;
|
|
52
52
|
}
|
|
53
|
-
function getCodeId(cwd, fileAbsPath,
|
|
53
|
+
function getCodeId(cwd, fileAbsPath, localId, entityName) {
|
|
54
54
|
const prefix = entityName || (0, import_utils.getRoutePathFromFsPath)(import_path.default.relative(cwd, fileAbsPath)).replace(/\//g, "-");
|
|
55
|
-
return [prefix, "demo",
|
|
55
|
+
return [prefix, "demo", localId].filter(Boolean).join("-");
|
|
56
56
|
}
|
|
57
57
|
function tryMarkDemoNode(node, opts) {
|
|
58
58
|
var _a, _b;
|
|
59
59
|
let isDemoNode = Boolean((_a = node.data) == null ? void 0 : _a.techStack);
|
|
60
60
|
if (!isDemoNode) {
|
|
61
|
-
const lang = getCodeLang(node);
|
|
61
|
+
const lang = getCodeLang(node, opts);
|
|
62
62
|
const techStack = lang && opts.techStacks.find((ts) => ts.isSupported(node, lang));
|
|
63
63
|
if (techStack) {
|
|
64
64
|
isDemoNode = true;
|
|
@@ -118,38 +118,63 @@ function rehypeDemo(opts) {
|
|
|
118
118
|
if (isElement(node, "p") && ((_a = node.data) == null ? void 0 : _a[DEMO_NODE_CONTAINER])) {
|
|
119
119
|
const demosPropData = [];
|
|
120
120
|
node.children.forEach((codeNode) => {
|
|
121
|
+
var _a2;
|
|
121
122
|
if (isElement(codeNode, "code")) {
|
|
122
123
|
const codeType = codeNode.data.type;
|
|
123
124
|
const techStack = codeNode.data.techStack;
|
|
124
|
-
const codeId = getCodeId(opts.cwd, opts.fileAbsPath, index++);
|
|
125
125
|
const codeValue = toString(codeNode.children).trim();
|
|
126
126
|
const parseOpts = {
|
|
127
|
-
id:
|
|
127
|
+
id: "",
|
|
128
128
|
refAtomIds: [],
|
|
129
129
|
fileAbsPath: "",
|
|
130
130
|
entryPointCode: codeType === "external" ? void 0 : codeValue
|
|
131
131
|
};
|
|
132
132
|
const previewerProps = {};
|
|
133
133
|
let component = "";
|
|
134
|
-
if (
|
|
134
|
+
if (codeType === "external") {
|
|
135
135
|
parseOpts.fileAbsPath = import_path.default.resolve(import_path.default.dirname(opts.fileAbsPath), codeNode.properties.src);
|
|
136
|
+
parseOpts.id = getCodeId(opts.cwd, opts.fileAbsPath, import_path.default.parse(parseOpts.fileAbsPath).name);
|
|
136
137
|
component = `React.lazy(() => import('${(0, import_plugin_utils.winPath)(parseOpts.fileAbsPath)}?techStack=${techStack.name}'))`;
|
|
138
|
+
codeNode.properties.title = codeValue || void 0;
|
|
139
|
+
(_a2 = codeNode.properties).filePath ?? (_a2.filePath = (0, import_plugin_utils.winPath)(import_path.default.relative(opts.cwd, parseOpts.fileAbsPath)));
|
|
137
140
|
} else {
|
|
138
141
|
parseOpts.fileAbsPath = opts.fileAbsPath.replace(".md", ".tsx");
|
|
142
|
+
parseOpts.id = getCodeId(opts.cwd, opts.fileAbsPath, String(index++));
|
|
139
143
|
component = techStack.transformCode(codeValue, {
|
|
140
144
|
type: "code-block",
|
|
141
145
|
fileAbsPath: opts.fileAbsPath
|
|
142
146
|
});
|
|
143
147
|
}
|
|
144
148
|
deferrers.push((0, import_block.default)(parseOpts).then(async ({ asset, sources, frontmatter }) => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
149
|
+
var _a3;
|
|
150
|
+
const { src, className, ...restAttrs } = codeNode.properties || {};
|
|
151
|
+
if (restAttrs.title) {
|
|
152
|
+
asset.title = String(restAttrs.title);
|
|
148
153
|
}
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
Object.keys(restAttrs).forEach((key) => {
|
|
155
|
+
if (restAttrs[key] === "")
|
|
156
|
+
restAttrs[key] = true;
|
|
157
|
+
});
|
|
158
|
+
const originalProps = Object.assign({}, frontmatter, restAttrs);
|
|
159
|
+
Object.assign(previewerProps, await ((_a3 = techStack.generatePreviewerProps) == null ? void 0 : _a3.call(techStack, originalProps, {
|
|
160
|
+
type: codeType,
|
|
161
|
+
mdAbsPath: opts.fileAbsPath,
|
|
162
|
+
fileAbsPath: codeType === "external" ? parseOpts.fileAbsPath : void 0,
|
|
163
|
+
entryPointCode: parseOpts.entryPointCode
|
|
164
|
+
})) || originalProps);
|
|
165
|
+
if (previewerProps.description) {
|
|
166
|
+
const { unified } = await import("unified");
|
|
167
|
+
const { default: remarkParse } = await import("remark-parse");
|
|
168
|
+
const { default: remarkGfm } = await import("remark-gfm");
|
|
169
|
+
const { default: remarkRehype } = await import("remark-rehype");
|
|
170
|
+
const { default: rehypeStringify } = await import("rehype-stringify");
|
|
171
|
+
const { convert } = require("html-to-text");
|
|
172
|
+
const result = await unified().use(remarkParse).use(remarkGfm).use(remarkRehype, { allowDangerousHtml: true }).use(rehypeStringify).process(previewerProps.description);
|
|
173
|
+
previewerProps.description = String(result.value);
|
|
174
|
+
asset.description = convert(result.value, {
|
|
175
|
+
wordwrap: false
|
|
176
|
+
});
|
|
151
177
|
}
|
|
152
|
-
Object.assign(previewerProps, frontmatter, restAttrs);
|
|
153
178
|
return {
|
|
154
179
|
id: asset.id,
|
|
155
180
|
component,
|
|
@@ -158,7 +183,7 @@ function rehypeDemo(opts) {
|
|
|
158
183
|
};
|
|
159
184
|
}));
|
|
160
185
|
demosPropData.push({
|
|
161
|
-
demo: { id:
|
|
186
|
+
demo: { id: parseOpts.id },
|
|
162
187
|
previewerProps
|
|
163
188
|
});
|
|
164
189
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/loaders/markdown/transformer/rehypeEmbed.ts
|
|
23
|
+
var rehypeEmbed_exports = {};
|
|
24
|
+
__export(rehypeEmbed_exports, {
|
|
25
|
+
default: () => rehypeEmbed
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(rehypeEmbed_exports);
|
|
28
|
+
var import_path = __toESM(require("path"));
|
|
29
|
+
var import_url = __toESM(require("url"));
|
|
30
|
+
var visit;
|
|
31
|
+
(async () => {
|
|
32
|
+
({ visit } = await import("unist-util-visit"));
|
|
33
|
+
})();
|
|
34
|
+
function rehypeEmbed(opts) {
|
|
35
|
+
return async (tree) => {
|
|
36
|
+
visit(tree, "element", (node, idx, parent) => {
|
|
37
|
+
var _a;
|
|
38
|
+
if (node.tagName === "embed" && ((_a = node.properties) == null ? void 0 : _a.hasOwnProperty("src"))) {
|
|
39
|
+
const { src } = node.properties;
|
|
40
|
+
const parsed = import_url.default.parse((src == null ? void 0 : src.toString()) || "");
|
|
41
|
+
const absPath = import_path.default.resolve(import_path.default.parse(opts.fileAbsPath).dir, parsed.pathname);
|
|
42
|
+
if (absPath) {
|
|
43
|
+
const hash = decodeURIComponent(parsed.hash || "").replace("#", "");
|
|
44
|
+
const query = new URLSearchParams();
|
|
45
|
+
if (hash[0] === "L") {
|
|
46
|
+
query.append("range", hash);
|
|
47
|
+
} else if (hash.startsWith("RE-")) {
|
|
48
|
+
query.append("regexp", hash.substring(3));
|
|
49
|
+
}
|
|
50
|
+
const moduleReqPath = `${absPath}?${query}`;
|
|
51
|
+
switch (import_path.default.extname(parsed.pathname)) {
|
|
52
|
+
case ".md":
|
|
53
|
+
default:
|
|
54
|
+
parent == null ? void 0 : parent.children.splice(idx, 1, {
|
|
55
|
+
type: "element",
|
|
56
|
+
tagName: "React.Fragment",
|
|
57
|
+
children: [],
|
|
58
|
+
properties: {},
|
|
59
|
+
position: node.position,
|
|
60
|
+
JSXAttributes: [
|
|
61
|
+
{
|
|
62
|
+
type: "JSXAttribute",
|
|
63
|
+
name: "children",
|
|
64
|
+
value: `require('${moduleReqPath}').default()`
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {});
|
|
@@ -29,6 +29,7 @@ var raw;
|
|
|
29
29
|
var visit;
|
|
30
30
|
var COMPONENT_NAME_REGEX = /<[A-Z][a-zA-Z\d]*/g;
|
|
31
31
|
var COMPONENT_STUB_ATTR = "$tag-name";
|
|
32
|
+
var CODE_META_STUB_ATTR = "$code-meta";
|
|
32
33
|
(async () => {
|
|
33
34
|
({ visit } = await import("unist-util-visit"));
|
|
34
35
|
({ raw } = await import("hast-util-raw"));
|
|
@@ -36,19 +37,26 @@ var COMPONENT_STUB_ATTR = "$tag-name";
|
|
|
36
37
|
function rehypeRaw() {
|
|
37
38
|
return (tree, file) => {
|
|
38
39
|
visit(tree, (node) => {
|
|
40
|
+
var _a;
|
|
39
41
|
if (node.type === "raw" && COMPONENT_NAME_REGEX.test(node.value)) {
|
|
40
42
|
node.value = node.value.replace(COMPONENT_NAME_REGEX, (str) => {
|
|
41
43
|
const tagName = str.slice(1);
|
|
42
44
|
return `${str} ${COMPONENT_STUB_ATTR}="${tagName}"`;
|
|
43
45
|
});
|
|
46
|
+
} else if (node.type === "element" && ((_a = node.data) == null ? void 0 : _a.meta)) {
|
|
47
|
+
node.properties ?? (node.properties = {});
|
|
48
|
+
node.properties[CODE_META_STUB_ATTR] = node.data.meta;
|
|
44
49
|
}
|
|
45
50
|
});
|
|
46
51
|
const newTree = raw(tree, file);
|
|
47
52
|
visit(newTree, "element", (node) => {
|
|
48
|
-
var _a;
|
|
53
|
+
var _a, _b;
|
|
49
54
|
if ((_a = node.properties) == null ? void 0 : _a[COMPONENT_STUB_ATTR]) {
|
|
50
55
|
node.tagName = node.properties[COMPONENT_STUB_ATTR];
|
|
51
56
|
delete node.properties[COMPONENT_STUB_ATTR];
|
|
57
|
+
} else if ((_b = node.properties) == null ? void 0 : _b[CODE_META_STUB_ATTR]) {
|
|
58
|
+
node.data = { meta: node.properties[CODE_META_STUB_ATTR] };
|
|
59
|
+
delete node.properties[CODE_META_STUB_ATTR];
|
|
52
60
|
}
|
|
53
61
|
});
|
|
54
62
|
return newTree;
|
|
@@ -0,0 +1,44 @@
|
|
|
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(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/loaders/markdown/transformer/remarkMeta.ts
|
|
23
|
+
var remarkMeta_exports = {};
|
|
24
|
+
__export(remarkMeta_exports, {
|
|
25
|
+
default: () => remarkMeta
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(remarkMeta_exports);
|
|
28
|
+
var import_js_yaml = __toESM(require("js-yaml"));
|
|
29
|
+
var visit;
|
|
30
|
+
(async () => {
|
|
31
|
+
({ visit } = await import("unist-util-visit"));
|
|
32
|
+
})();
|
|
33
|
+
function remarkMeta() {
|
|
34
|
+
return (tree, file) => {
|
|
35
|
+
visit(tree, "yaml", (node) => {
|
|
36
|
+
try {
|
|
37
|
+
file.data.frontmatter = import_js_yaml.default.load(node.value);
|
|
38
|
+
} catch {
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {});
|
package/dist/preset.js
CHANGED
|
@@ -31,8 +31,10 @@ var preset_default = (api) => {
|
|
|
31
31
|
plugins: [
|
|
32
32
|
require.resolve("./registerMethods"),
|
|
33
33
|
require.resolve("./features/configPlugins"),
|
|
34
|
+
require.resolve("./features/sideEffects"),
|
|
34
35
|
require.resolve("./features/compile"),
|
|
35
36
|
require.resolve("./features/routes"),
|
|
37
|
+
require.resolve("./features/meta"),
|
|
36
38
|
require.resolve("./features/theme"),
|
|
37
39
|
require.resolve("./features/locales")
|
|
38
40
|
]
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IDumiDemoProps, ILocalesConfig } from "./client/theme-api";
|
|
1
2
|
import type { IThemeLoadResult } from "./features/theme/loader";
|
|
2
3
|
import type { IModify } from '@umijs/core';
|
|
3
4
|
import type { ExampleBlockAsset } from 'dumi-assets-types';
|
|
@@ -11,12 +12,14 @@ export interface IDumiConfig extends IUmiConfig {
|
|
|
11
12
|
type: string;
|
|
12
13
|
dir: string;
|
|
13
14
|
}[];
|
|
15
|
+
codeBlockMode: 'active' | 'passive';
|
|
14
16
|
};
|
|
15
|
-
locales:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
locales: ILocalesConfig;
|
|
18
|
+
/**
|
|
19
|
+
* extra unified plugins
|
|
20
|
+
*/
|
|
21
|
+
extraRemarkPlugins?: (string | Function | [string | Function, object])[];
|
|
22
|
+
extraRehypePlugins?: (string | Function | [string | Function, object])[];
|
|
20
23
|
}
|
|
21
24
|
export declare abstract class IDumiTechStack {
|
|
22
25
|
/**
|
|
@@ -41,7 +44,12 @@ export declare abstract class IDumiTechStack {
|
|
|
41
44
|
/**
|
|
42
45
|
* generator for return previewer props
|
|
43
46
|
*/
|
|
44
|
-
abstract generatePreviewerProps?(
|
|
47
|
+
abstract generatePreviewerProps?(props: IDumiDemoProps['previewerProps'], opts: {
|
|
48
|
+
type: Parameters<IDumiTechStack['transformCode']>[1]['type'];
|
|
49
|
+
mdAbsPath: string;
|
|
50
|
+
fileAbsPath?: string;
|
|
51
|
+
entryPointCode?: string;
|
|
52
|
+
}): Promise<IDumiDemoProps['previewerProps']> | IDumiDemoProps['previewerProps'];
|
|
45
53
|
}
|
|
46
54
|
export declare type IApi = IUmiApi & {
|
|
47
55
|
config: IDumiConfig;
|
package/dist/utils.d.ts
CHANGED
|
@@ -2,3 +2,14 @@
|
|
|
2
2
|
* get route path from file-system path
|
|
3
3
|
*/
|
|
4
4
|
export declare function getRoutePathFromFsPath(fsPath: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* get range lines of markdown file
|
|
7
|
+
*/
|
|
8
|
+
export declare const getFileRangeLines: (content: string, range: string) => string;
|
|
9
|
+
/**
|
|
10
|
+
* get file content by regular expression
|
|
11
|
+
* @param content source file content
|
|
12
|
+
* @param regexp regular expression string
|
|
13
|
+
* @param filePath source file path
|
|
14
|
+
*/
|
|
15
|
+
export declare const getFileContentByRegExp: (content: string, regexp: string, filePath: string) => string;
|