dumi 2.0.0-alpha.3 → 2.0.0-beta.0
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/bin/dumi.js +2 -1
- package/dist/client/pages/404.d.ts +1 -0
- package/dist/client/pages/404.js +2 -0
- package/dist/client/pages/Demo.d.ts +3 -0
- package/dist/client/pages/Demo.js +17 -0
- package/dist/client/theme-api/DumiDemo.js +8 -5
- package/dist/client/theme-api/DumiDemoGrid.d.ts +1 -1
- package/dist/client/theme-api/DumiDemoGrid.js +9 -8
- package/dist/client/theme-api/context.d.ts +4 -2
- package/dist/client/theme-api/context.js +6 -3
- package/dist/client/theme-api/index.d.ts +8 -7
- package/dist/client/theme-api/index.js +7 -7
- package/dist/client/theme-api/types.d.ts +45 -14
- package/dist/client/theme-api/useLocale.d.ts +1 -0
- package/dist/client/theme-api/useLocale.js +31 -0
- package/dist/client/theme-api/useNavData.d.ts +1 -1
- package/dist/client/theme-api/useNavData.js +11 -11
- package/dist/client/theme-api/useRouteMeta.js +4 -1
- package/dist/client/theme-api/useSidebarData.js +11 -12
- package/dist/client/theme-api/utils.d.ts +0 -1
- package/dist/client/theme-api/utils.js +7 -25
- package/dist/client/tsconfig.json +2 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +3 -0
- package/dist/features/compile.js +1 -1
- package/dist/features/configPlugins/schema.js +1 -4
- package/dist/features/exports.d.ts +3 -0
- package/dist/features/exports.js +45 -0
- package/dist/features/locales.js +2 -2
- package/dist/features/meta.js +3 -2
- package/dist/features/routes.js +36 -3
- package/dist/features/theme/index.js +6 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/loaders/markdown/index.js +4 -2
- package/dist/loaders/markdown/transformer/index.d.ts +5 -2
- package/dist/loaders/markdown/transformer/index.js +5 -2
- package/dist/loaders/markdown/transformer/rehypeDemo.d.ts +3 -0
- package/dist/loaders/markdown/transformer/rehypeDemo.js +14 -6
- package/dist/loaders/markdown/transformer/rehypeEmbed.d.ts +9 -1
- package/dist/loaders/markdown/transformer/rehypeEmbed.js +16 -4
- package/dist/loaders/markdown/transformer/rehypeEnhancedTag.d.ts +3 -0
- package/dist/loaders/markdown/transformer/rehypeEnhancedTag.js +54 -0
- package/dist/loaders/markdown/transformer/rehypeIsolation.js +8 -2
- package/dist/loaders/markdown/transformer/rehypeRaw.js +2 -2
- package/dist/loaders/markdown/transformer/rehypeSlug.d.ts +4 -0
- package/dist/loaders/markdown/transformer/rehypeSlug.js +105 -0
- package/dist/loaders/markdown/transformer/remarkMeta.d.ts +4 -2
- package/dist/loaders/markdown/transformer/remarkMeta.js +24 -3
- package/dist/preset.js +1 -0
- package/dist/techStacks/react.js +0 -1
- package/dist/types.d.ts +2 -1
- package/package.json +18 -2
- package/theme-default/builtins/{Previewer.d.ts → Previewer/index.d.ts} +2 -1
- package/theme-default/builtins/Previewer/index.js +162 -0
- package/theme-default/builtins/Previewer/index.less +297 -0
- package/theme-default/builtins/SourceCode/index.d.ts +9 -0
- package/theme-default/builtins/SourceCode/index.js +87 -0
- package/theme-default/builtins/SourceCode/index.less +50 -0
- package/theme-default/layouts/DocLayout/index.d.ts +1 -0
- package/theme-default/layouts/DocLayout/index.js +20 -19
- package/theme-default/layouts/DocLayout/index.less +17 -0
- package/theme-default/locales/en-US.json +9 -1
- package/theme-default/locales/zh-CN.json +9 -1
- package/theme-default/slots/Content/heti.scss +4 -0
- package/theme-default/slots/Content/index.d.ts +2 -0
- package/theme-default/slots/Content/index.js +6 -5
- package/theme-default/slots/Content/index.less +39 -0
- package/theme-default/slots/Header/index.d.ts +1 -0
- package/theme-default/slots/Header/index.js +10 -7
- package/theme-default/slots/Header/index.less +22 -0
- package/theme-default/slots/LangSwitch/index.d.ts +4 -0
- package/theme-default/slots/LangSwitch/index.js +81 -0
- package/theme-default/slots/LangSwitch/index.less +13 -0
- package/theme-default/slots/Logo/index.d.ts +1 -0
- package/theme-default/slots/Logo/index.js +13 -1
- package/theme-default/slots/Logo/index.less +16 -0
- package/theme-default/slots/Navbar/index.d.ts +1 -0
- package/theme-default/slots/Navbar/index.js +20 -1
- package/theme-default/slots/Navbar/index.less +33 -0
- package/theme-default/slots/NotFound/index.d.ts +4 -0
- package/theme-default/slots/NotFound/index.js +20 -0
- package/theme-default/slots/NotFound/index.less +26 -0
- package/theme-default/slots/SearchBar/index.d.ts +1 -0
- package/theme-default/slots/SearchBar/index.js +35 -4
- package/theme-default/slots/SearchBar/index.less +63 -0
- package/theme-default/slots/Sidebar/index.d.ts +1 -0
- package/theme-default/slots/Sidebar/index.js +23 -8
- package/theme-default/slots/Sidebar/index.less +57 -0
- package/theme-default/slots/Toc/index.d.ts +4 -0
- package/theme-default/slots/Toc/index.js +33 -0
- package/theme-default/slots/Toc/index.less +37 -0
- package/theme-default/styles/utils.less +64 -0
- package/theme-default/styles/variables.less +13 -0
- package/theme-default/builtins/Previewer.js +0 -11
package/dist/features/meta.js
CHANGED
|
@@ -26,6 +26,7 @@ var import_plugin_utils = require("umi/plugin-utils");
|
|
|
26
26
|
var meta_default = (api) => {
|
|
27
27
|
const mdRouteFiles = [];
|
|
28
28
|
api.modifyRoutes((routes) => {
|
|
29
|
+
mdRouteFiles.length = 0;
|
|
29
30
|
Object.values(routes).forEach((route) => {
|
|
30
31
|
if (route.file.endsWith(".md")) {
|
|
31
32
|
mdRouteFiles.push({
|
|
@@ -42,7 +43,7 @@ var meta_default = (api) => {
|
|
|
42
43
|
noPluginDir: true,
|
|
43
44
|
path: "dumi/meta/index.ts",
|
|
44
45
|
content: import_plugin_utils.Mustache.render(`{{#mdRouteFiles}}
|
|
45
|
-
import { demos as d{{{index}}}, frontmatter as fm{{{index}}} } from '{{{file}}}?type=meta';
|
|
46
|
+
import { demos as d{{{index}}}, frontmatter as fm{{{index}}}, toc as toc{{{index}}} } from '{{{file}}}?type=meta';
|
|
46
47
|
{{/mdRouteFiles}}
|
|
47
48
|
|
|
48
49
|
export const demos = {
|
|
@@ -53,7 +54,7 @@ export const demos = {
|
|
|
53
54
|
|
|
54
55
|
export const routesMeta = {
|
|
55
56
|
{{#mdRouteFiles}}
|
|
56
|
-
'{{{id}}}': fm{{{index}}},
|
|
57
|
+
'{{{id}}}': { frontmatter: fm{{{index}}}, toc: toc{{{index}}} },
|
|
57
58
|
{{/mdRouteFiles}}
|
|
58
59
|
}`, { mdRouteFiles })
|
|
59
60
|
});
|
package/dist/features/routes.js
CHANGED
|
@@ -25,6 +25,7 @@ __export(routes_exports, {
|
|
|
25
25
|
default: () => routes_default
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(routes_exports);
|
|
28
|
+
var import_constants = require("../constants");
|
|
28
29
|
var import_core = require("@umijs/core");
|
|
29
30
|
var import_utils = require("@umijs/core/dist/route/utils");
|
|
30
31
|
var import_path = __toESM(require("path"));
|
|
@@ -41,7 +42,13 @@ function localizeUmiRoute(route, locales) {
|
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
var routes_default = (api) => {
|
|
45
|
+
var _a, _b, _c;
|
|
46
|
+
const extraWatchPaths = [
|
|
47
|
+
...((_b = (_a = api.userConfig.resolve) == null ? void 0 : _a.entityDirs) == null ? void 0 : _b.map(({ dir }) => dir)) || ["docs"],
|
|
48
|
+
...((_c = api.userConfig.resolve) == null ? void 0 : _c.docDirs) || []
|
|
49
|
+
].map((dir) => import_path.default.join(api.cwd, dir, "**/*.md"));
|
|
44
50
|
api.describe({ key: "dumi:routes" });
|
|
51
|
+
api.addTmpGenerateWatcherPaths(() => extraWatchPaths);
|
|
45
52
|
api.modifyConfig((memo) => {
|
|
46
53
|
memo.conventionRoutes = {
|
|
47
54
|
base: import_path.default.join(__dirname, "dumi-disable-default-routes")
|
|
@@ -52,8 +59,8 @@ var routes_default = (api) => {
|
|
|
52
59
|
if (api.userConfig.resolve) {
|
|
53
60
|
const keys = ["docDirs", "entityDirs"];
|
|
54
61
|
keys.forEach((key) => {
|
|
55
|
-
var
|
|
56
|
-
if (((
|
|
62
|
+
var _a2;
|
|
63
|
+
if (((_a2 = api.userConfig.resolve[key]) == null ? void 0 : _a2.length) === 0)
|
|
57
64
|
memo.resolve[key] = [];
|
|
58
65
|
});
|
|
59
66
|
}
|
|
@@ -66,11 +73,12 @@ var routes_default = (api) => {
|
|
|
66
73
|
}
|
|
67
74
|
return ret;
|
|
68
75
|
}, {});
|
|
69
|
-
const { DocLayout } = api.service.themeData.layouts;
|
|
76
|
+
const { DocLayout, DemoLayout } = api.service.themeData.layouts;
|
|
70
77
|
const { docDirs, entityDirs } = api.config.resolve;
|
|
71
78
|
const layoutRouteValues = Object.values(routes);
|
|
72
79
|
const lastLayoutId = layoutRouteValues.find(({ id }) => layoutRouteValues.every(({ parentId }) => id !== parentId)).id;
|
|
73
80
|
let docLayoutId = lastLayoutId;
|
|
81
|
+
let demoLayoutId = lastLayoutId;
|
|
74
82
|
if (DocLayout) {
|
|
75
83
|
docLayoutId = DocLayout.specifier;
|
|
76
84
|
routes[DocLayout.specifier] = {
|
|
@@ -82,6 +90,17 @@ var routes_default = (api) => {
|
|
|
82
90
|
isLayout: true
|
|
83
91
|
};
|
|
84
92
|
}
|
|
93
|
+
if (DemoLayout) {
|
|
94
|
+
demoLayoutId = DemoLayout.specifier;
|
|
95
|
+
routes[DemoLayout.specifier] = {
|
|
96
|
+
id: DemoLayout.specifier,
|
|
97
|
+
path: "/",
|
|
98
|
+
file: DemoLayout.source,
|
|
99
|
+
parentId: lastLayoutId,
|
|
100
|
+
absPath: "/",
|
|
101
|
+
isLayout: true
|
|
102
|
+
};
|
|
103
|
+
}
|
|
85
104
|
docDirs.forEach((dir) => {
|
|
86
105
|
const base = import_path.default.join(api.cwd, dir);
|
|
87
106
|
const dirRoutes = (0, import_core.getConventionRoutes)({
|
|
@@ -112,6 +131,20 @@ var routes_default = (api) => {
|
|
|
112
131
|
localizeUmiRoute(routes[routeId], api.config.locales);
|
|
113
132
|
});
|
|
114
133
|
});
|
|
134
|
+
routes["404"] = {
|
|
135
|
+
id: "404",
|
|
136
|
+
path: "*",
|
|
137
|
+
absPath: "/*",
|
|
138
|
+
parentId: docLayoutId,
|
|
139
|
+
file: require.resolve("../client/pages/404")
|
|
140
|
+
};
|
|
141
|
+
routes["demo-render"] = {
|
|
142
|
+
id: "demo-render",
|
|
143
|
+
path: `${import_constants.SP_ROUTE_PREFIX}demos/:id`,
|
|
144
|
+
absPath: `/${import_constants.SP_ROUTE_PREFIX}demos/:id`,
|
|
145
|
+
parentId: demoLayoutId,
|
|
146
|
+
file: require.resolve("../client/pages/Demo")
|
|
147
|
+
};
|
|
115
148
|
return routes;
|
|
116
149
|
});
|
|
117
150
|
api.addLayouts(() => {
|
|
@@ -52,7 +52,7 @@ var theme_default = (api) => {
|
|
|
52
52
|
async fn(memo) {
|
|
53
53
|
const defaultThemeData = (0, import_loader.default)(DEFAULT_THEME_PATH);
|
|
54
54
|
const pkgThemePath = getPkgThemePath(api);
|
|
55
|
-
const pkgThemeData = (0, import_plugin_utils.deepmerge)(defaultThemeData, pkgThemePath ? (0, import_loader.default)(pkgThemePath) : {});
|
|
55
|
+
const pkgThemeData = (0, import_plugin_utils.deepmerge)(defaultThemeData, pkgThemePath ? (0, import_loader.default)(import_path.default.join(pkgThemePath, "dist")) : {});
|
|
56
56
|
originalThemeData = await api.applyPlugins({
|
|
57
57
|
key: "modifyTheme",
|
|
58
58
|
initialValue: pkgThemeData
|
|
@@ -66,11 +66,11 @@ var theme_default = (api) => {
|
|
|
66
66
|
Object.assign(api.service.themeData.builtins, {
|
|
67
67
|
DumiDemo: {
|
|
68
68
|
specifier: "{ DumiDemo }",
|
|
69
|
-
source: "dumi
|
|
69
|
+
source: "dumi"
|
|
70
70
|
},
|
|
71
71
|
DumiDemoGrid: {
|
|
72
72
|
specifier: "{ DumiDemoGrid }",
|
|
73
|
-
source: "dumi
|
|
73
|
+
source: "dumi"
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
76
|
return memo;
|
|
@@ -106,8 +106,8 @@ export { default } from '${item.source}';`
|
|
|
106
106
|
api.writeTmpFile({
|
|
107
107
|
noPluginDir: true,
|
|
108
108
|
path: "dumi/theme/ContextWrapper.tsx",
|
|
109
|
-
content: `import {
|
|
110
|
-
import {
|
|
109
|
+
content: `import { useOutlet } from 'dumi';
|
|
110
|
+
import { SiteContext } from '${(0, import_plugin_utils.winPath)(require.resolve("../../client/theme-api/context"))}';
|
|
111
111
|
import { demos } from '../meta';
|
|
112
112
|
import { locales } from '../locales/config';
|
|
113
113
|
|
|
@@ -115,7 +115,7 @@ export default function DumiContextWrapper() {
|
|
|
115
115
|
const outlet = useOutlet();
|
|
116
116
|
|
|
117
117
|
return (
|
|
118
|
-
<
|
|
118
|
+
<SiteContext.Provider value={{ demos, locales, themeConfig: ${JSON.stringify(api.config.themeConfig)} }}>{outlet}</SiteContext.Provider>
|
|
119
119
|
);
|
|
120
120
|
}`
|
|
121
121
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { IDumiUserConfig } from "./types";
|
|
2
2
|
declare let unistUtilVisit: typeof import('unist-util-visit');
|
|
3
|
+
export * from 'umi';
|
|
4
|
+
export * from './client/theme-api';
|
|
3
5
|
export { IApi } from "./types";
|
|
4
6
|
export type { Root as HastRoot } from 'hast';
|
|
5
|
-
export * from 'umi';
|
|
6
7
|
export type { Plugin as UnifiedPlugin, Transformer as UnifiedTransformer, } from 'unified';
|
|
7
8
|
export { unistUtilVisit };
|
|
8
9
|
export declare const defineConfig: (config: IDumiUserConfig) => IDumiUserConfig;
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,7 @@ __export(src_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(src_exports);
|
|
30
30
|
__reExport(src_exports, require("umi"), module.exports);
|
|
31
|
+
__reExport(src_exports, require("./client/theme-api"), module.exports);
|
|
31
32
|
var unistUtilVisit;
|
|
32
33
|
(async () => {
|
|
33
34
|
unistUtilVisit = await import("unist-util-visit");
|
|
@@ -45,7 +45,8 @@ function mdLoader(raw) {
|
|
|
45
45
|
fileAbsPath: this.resourcePath
|
|
46
46
|
}).then((ret) => {
|
|
47
47
|
if (opts.mode === "meta") {
|
|
48
|
-
const { demos, frontmatter =
|
|
48
|
+
const { demos, frontmatter, toc, embeds = [] } = ret.meta;
|
|
49
|
+
embeds.forEach((file) => this.addDependency(file));
|
|
49
50
|
cb(null, import_plugin_utils.Mustache.render(`import React from 'react';
|
|
50
51
|
|
|
51
52
|
export const demos = {
|
|
@@ -56,11 +57,12 @@ export const demos = {
|
|
|
56
57
|
},
|
|
57
58
|
{{/demos}}
|
|
58
59
|
};
|
|
59
|
-
|
|
60
60
|
export const frontmatter = {{{frontmatter}}};
|
|
61
|
+
export const toc = {{{toc}}}
|
|
61
62
|
`, {
|
|
62
63
|
demos,
|
|
63
64
|
frontmatter: JSON.stringify(frontmatter),
|
|
65
|
+
toc: JSON.stringify(toc),
|
|
64
66
|
renderAsset: function renderAsset() {
|
|
65
67
|
Object.keys(this.sources).forEach((file) => {
|
|
66
68
|
this.asset.dependencies[file].value = `{{{require('!!raw-loader!${this.sources[file]}?raw').default}}}`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IParsedBlockAsset } from "../../../assetParsers/block";
|
|
2
|
-
import type { IRouteMeta } from "../../../client/theme-api";
|
|
2
|
+
import type { IRouteMeta } from "../../../client/theme-api/types";
|
|
3
3
|
import type { IDumiConfig, IDumiTechStack } from "../../../types";
|
|
4
4
|
import type { DataMap } from 'vfile';
|
|
5
5
|
declare module 'hast' {
|
|
@@ -22,12 +22,15 @@ declare module 'vfile' {
|
|
|
22
22
|
asset: IParsedBlockAsset['asset'];
|
|
23
23
|
sources: IParsedBlockAsset['sources'];
|
|
24
24
|
}[];
|
|
25
|
-
frontmatter: IRouteMeta;
|
|
25
|
+
frontmatter: IRouteMeta['frontmatter'];
|
|
26
|
+
toc: IRouteMeta['toc'];
|
|
27
|
+
embeds?: string[];
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
export interface IMdTransformerOptions {
|
|
29
31
|
cwd: string;
|
|
30
32
|
fileAbsPath: string;
|
|
33
|
+
parentAbsPath?: string;
|
|
31
34
|
techStacks: IDumiTechStack[];
|
|
32
35
|
codeBlockMode: IDumiConfig['resolve']['codeBlockMode'];
|
|
33
36
|
extraRemarkPlugins?: IDumiConfig['extraRemarkPlugins'];
|
|
@@ -27,9 +27,11 @@ __export(transformer_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(transformer_exports);
|
|
28
28
|
var import_rehypeDemo = __toESM(require("./rehypeDemo"));
|
|
29
29
|
var import_rehypeEmbed = __toESM(require("./rehypeEmbed"));
|
|
30
|
+
var import_rehypeEnhancedTag = __toESM(require("./rehypeEnhancedTag"));
|
|
30
31
|
var import_rehypeIsolation = __toESM(require("./rehypeIsolation"));
|
|
31
32
|
var import_rehypeJsxify = __toESM(require("./rehypeJsxify"));
|
|
32
33
|
var import_rehypeRaw = __toESM(require("./rehypeRaw"));
|
|
34
|
+
var import_rehypeSlug = __toESM(require("./rehypeSlug"));
|
|
33
35
|
var import_rehypeStrip = __toESM(require("./rehypeStrip"));
|
|
34
36
|
var import_remarkMeta = __toESM(require("./remarkMeta"));
|
|
35
37
|
function applyUnifiedPlugin(opts) {
|
|
@@ -46,7 +48,8 @@ var transformer_default = async (raw, opts) => {
|
|
|
46
48
|
const { default: remarkBreaks } = await import("remark-breaks");
|
|
47
49
|
const { default: remarkGfm } = await import("remark-gfm");
|
|
48
50
|
const { default: remarkRehype } = await import("remark-rehype");
|
|
49
|
-
const
|
|
51
|
+
const { default: rehypeAutolinkHeadings } = await import("rehype-autolink-headings");
|
|
52
|
+
const processor = unified().use(remarkParse).use(remarkFrontmatter).use(import_remarkMeta.default, { fileAbsPath: opts.fileAbsPath }).use(remarkBreaks).use(remarkGfm);
|
|
50
53
|
(_a = opts.extraRemarkPlugins) == null ? void 0 : _a.forEach((plugin) => applyUnifiedPlugin({
|
|
51
54
|
plugin,
|
|
52
55
|
processor,
|
|
@@ -59,7 +62,7 @@ var transformer_default = async (raw, opts) => {
|
|
|
59
62
|
cwd: opts.cwd,
|
|
60
63
|
fileAbsPath: opts.fileAbsPath,
|
|
61
64
|
codeBlockMode: opts.codeBlockMode
|
|
62
|
-
}).use(import_rehypeIsolation.default);
|
|
65
|
+
}).use(import_rehypeSlug.default, opts).use(rehypeAutolinkHeadings).use(import_rehypeIsolation.default).use(import_rehypeEnhancedTag.default);
|
|
63
66
|
(_b = opts.extraRehypePlugins) == null ? void 0 : _b.forEach((plugin) => applyUnifiedPlugin({
|
|
64
67
|
plugin,
|
|
65
68
|
processor,
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { Root } from 'hast';
|
|
2
2
|
import type { Transformer } from 'unified';
|
|
3
3
|
import type { IMdTransformerOptions } from '.';
|
|
4
|
+
export declare const DEMO_PROP_VALUE_KEY = "$demo-prop-value-key";
|
|
5
|
+
export declare const DUMI_DEMO_TAG = "DumiDemo";
|
|
6
|
+
export declare const DUMI_DEMO_GRID_TAG = "DumiDemoGrid";
|
|
4
7
|
declare type IRehypeDemoOptions = Pick<IMdTransformerOptions, 'techStacks' | 'cwd' | 'fileAbsPath' | 'codeBlockMode'>;
|
|
5
8
|
export default function rehypeDemo(opts: IRehypeDemoOptions): Transformer<Root>;
|
|
6
9
|
export {};
|
|
@@ -22,6 +22,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
// src/loaders/markdown/transformer/rehypeDemo.ts
|
|
23
23
|
var rehypeDemo_exports = {};
|
|
24
24
|
__export(rehypeDemo_exports, {
|
|
25
|
+
DEMO_PROP_VALUE_KEY: () => DEMO_PROP_VALUE_KEY,
|
|
26
|
+
DUMI_DEMO_GRID_TAG: () => DUMI_DEMO_GRID_TAG,
|
|
27
|
+
DUMI_DEMO_TAG: () => DUMI_DEMO_TAG,
|
|
25
28
|
default: () => rehypeDemo
|
|
26
29
|
});
|
|
27
30
|
module.exports = __toCommonJS(rehypeDemo_exports);
|
|
@@ -35,9 +38,11 @@ var toString;
|
|
|
35
38
|
var isElement;
|
|
36
39
|
var DEMO_NODE_CONTAINER = "$demo-container";
|
|
37
40
|
var DEMO_PROP_VALUE_KEY = "$demo-prop-value-key";
|
|
41
|
+
var DUMI_DEMO_TAG = "DumiDemo";
|
|
42
|
+
var DUMI_DEMO_GRID_TAG = "DumiDemoGrid";
|
|
38
43
|
(async () => {
|
|
39
44
|
({ visit, SKIP } = await import("unist-util-visit"));
|
|
40
|
-
({ toString } = await import("
|
|
45
|
+
({ toString } = await import("hast-util-to-string"));
|
|
41
46
|
({ isElement } = await import("hast-util-is-element"));
|
|
42
47
|
})();
|
|
43
48
|
function getCodeLang(node, opts) {
|
|
@@ -122,7 +127,7 @@ function rehypeDemo(opts) {
|
|
|
122
127
|
if (isElement(codeNode, "code")) {
|
|
123
128
|
const codeType = codeNode.data.type;
|
|
124
129
|
const techStack = codeNode.data.techStack;
|
|
125
|
-
const codeValue = toString(codeNode
|
|
130
|
+
const codeValue = toString(codeNode).trim();
|
|
126
131
|
const parseOpts = {
|
|
127
132
|
id: "",
|
|
128
133
|
refAtomIds: [],
|
|
@@ -191,11 +196,11 @@ function rehypeDemo(opts) {
|
|
|
191
196
|
replaceNodes.push(node);
|
|
192
197
|
node.children = [];
|
|
193
198
|
if (demosPropData.length === 1) {
|
|
194
|
-
node.tagName =
|
|
199
|
+
node.tagName = DUMI_DEMO_TAG;
|
|
195
200
|
node.data[DEMO_PROP_VALUE_KEY] = demosPropData[0];
|
|
196
201
|
node.JSXAttributes = [{ type: "JSXSpreadAttribute", argument: "" }];
|
|
197
202
|
} else {
|
|
198
|
-
node.tagName =
|
|
203
|
+
node.tagName = DUMI_DEMO_GRID_TAG;
|
|
199
204
|
node.data[DEMO_PROP_VALUE_KEY] = demosPropData;
|
|
200
205
|
node.JSXAttributes = [
|
|
201
206
|
{ type: "JSXAttribute", name: "items", value: "" }
|
|
@@ -213,10 +218,13 @@ function rehypeDemo(opts) {
|
|
|
213
218
|
} else {
|
|
214
219
|
node.JSXAttributes[0].argument = value;
|
|
215
220
|
}
|
|
216
|
-
delete node.data[DEMO_PROP_VALUE_KEY];
|
|
217
221
|
});
|
|
218
222
|
});
|
|
219
223
|
};
|
|
220
224
|
}
|
|
221
225
|
// Annotate the CommonJS export names for ESM import in node:
|
|
222
|
-
0 && (module.exports = {
|
|
226
|
+
0 && (module.exports = {
|
|
227
|
+
DEMO_PROP_VALUE_KEY,
|
|
228
|
+
DUMI_DEMO_GRID_TAG,
|
|
229
|
+
DUMI_DEMO_TAG
|
|
230
|
+
});
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Node, Root } from 'hast';
|
|
2
3
|
import type { Transformer } from 'unified';
|
|
4
|
+
import url from 'url';
|
|
3
5
|
import type { IMdTransformerOptions } from '.';
|
|
6
|
+
export declare type IEmbedNodeData = Node['data'] & {
|
|
7
|
+
tagName: string;
|
|
8
|
+
fileAbsPath: string;
|
|
9
|
+
query: InstanceType<typeof url.URLSearchParams>;
|
|
10
|
+
};
|
|
11
|
+
export declare const EMBED_TAG = "embed";
|
|
4
12
|
export default function rehypeEmbed(opts: Pick<IMdTransformerOptions, 'fileAbsPath'>): Transformer<Root>;
|
|
@@ -22,6 +22,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
// src/loaders/markdown/transformer/rehypeEmbed.ts
|
|
23
23
|
var rehypeEmbed_exports = {};
|
|
24
24
|
__export(rehypeEmbed_exports, {
|
|
25
|
+
EMBED_TAG: () => EMBED_TAG,
|
|
25
26
|
default: () => rehypeEmbed
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(rehypeEmbed_exports);
|
|
@@ -31,11 +32,12 @@ var visit;
|
|
|
31
32
|
(async () => {
|
|
32
33
|
({ visit } = await import("unist-util-visit"));
|
|
33
34
|
})();
|
|
35
|
+
var EMBED_TAG = "embed";
|
|
34
36
|
function rehypeEmbed(opts) {
|
|
35
|
-
return async (tree) => {
|
|
37
|
+
return async (tree, vFile) => {
|
|
36
38
|
visit(tree, "element", (node, idx, parent) => {
|
|
37
|
-
var _a;
|
|
38
|
-
if (node.tagName ===
|
|
39
|
+
var _a, _b;
|
|
40
|
+
if (node.tagName === EMBED_TAG && ((_a = node.properties) == null ? void 0 : _a.hasOwnProperty("src"))) {
|
|
39
41
|
const { src } = node.properties;
|
|
40
42
|
const parsed = import_url.default.parse((src == null ? void 0 : src.toString()) || "");
|
|
41
43
|
const absPath = import_path.default.resolve(import_path.default.parse(opts.fileAbsPath).dir, parsed.pathname);
|
|
@@ -48,6 +50,11 @@ function rehypeEmbed(opts) {
|
|
|
48
50
|
query.append("regexp", hash.substring(3));
|
|
49
51
|
}
|
|
50
52
|
const moduleReqPath = `${absPath}?${query}`;
|
|
53
|
+
const nodeData = {
|
|
54
|
+
tagName: EMBED_TAG,
|
|
55
|
+
fileAbsPath: absPath,
|
|
56
|
+
query
|
|
57
|
+
};
|
|
51
58
|
switch (import_path.default.extname(parsed.pathname)) {
|
|
52
59
|
case ".md":
|
|
53
60
|
default:
|
|
@@ -56,6 +63,7 @@ function rehypeEmbed(opts) {
|
|
|
56
63
|
tagName: "React.Fragment",
|
|
57
64
|
children: [],
|
|
58
65
|
properties: {},
|
|
66
|
+
data: nodeData,
|
|
59
67
|
position: node.position,
|
|
60
68
|
JSXAttributes: [
|
|
61
69
|
{
|
|
@@ -66,10 +74,14 @@ function rehypeEmbed(opts) {
|
|
|
66
74
|
]
|
|
67
75
|
});
|
|
68
76
|
}
|
|
77
|
+
(_b = vFile.data).embeds ?? (_b.embeds = []);
|
|
78
|
+
vFile.data.embeds.push(absPath);
|
|
69
79
|
}
|
|
70
80
|
}
|
|
71
81
|
});
|
|
72
82
|
};
|
|
73
83
|
}
|
|
74
84
|
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
-
0 && (module.exports = {
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
EMBED_TAG
|
|
87
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
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/rehypeEnhancedTag.ts
|
|
23
|
+
var rehypeEnhancedTag_exports = {};
|
|
24
|
+
__export(rehypeEnhancedTag_exports, {
|
|
25
|
+
default: () => rehypeEnhancedTag
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(rehypeEnhancedTag_exports);
|
|
28
|
+
var visit;
|
|
29
|
+
var isElement;
|
|
30
|
+
var toString;
|
|
31
|
+
(async () => {
|
|
32
|
+
({ visit } = await import("unist-util-visit"));
|
|
33
|
+
({ isElement } = await import("hast-util-is-element"));
|
|
34
|
+
({ toString } = await import("hast-util-to-string"));
|
|
35
|
+
})();
|
|
36
|
+
function rehypeEnhancedTag() {
|
|
37
|
+
return async (tree) => {
|
|
38
|
+
visit(tree, "element", (node, i, parent) => {
|
|
39
|
+
var _a, _b, _c;
|
|
40
|
+
if (node.tagName === "pre" && isElement((_a = node.children) == null ? void 0 : _a[0]) && node.children[0].tagName === "code") {
|
|
41
|
+
const className = ((_b = node.children[0].properties) == null ? void 0 : _b.className) || [];
|
|
42
|
+
const lang = (_c = className.join("").match(/language-(\w+)(?:$| )/)) == null ? void 0 : _c[1];
|
|
43
|
+
parent.children.splice(i, 1, {
|
|
44
|
+
type: "element",
|
|
45
|
+
tagName: "SourceCode",
|
|
46
|
+
properties: { lang },
|
|
47
|
+
children: [{ type: "text", value: toString(node.children[0]) }]
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {});
|
|
@@ -32,19 +32,25 @@ var visit;
|
|
|
32
32
|
function isDemoNode(node) {
|
|
33
33
|
return ["DumiDemo", "DumiDemoGrid"].includes(node.tagName);
|
|
34
34
|
}
|
|
35
|
+
function isReactComponent(node) {
|
|
36
|
+
return /^[A-Z].+/.test(node.tagName);
|
|
37
|
+
}
|
|
35
38
|
function rehypeIsolation() {
|
|
36
39
|
return (tree) => {
|
|
37
40
|
visit(tree, "root", (node) => {
|
|
38
41
|
node.children = node.children.reduce((nextChildren, current) => {
|
|
42
|
+
var _a, _b;
|
|
39
43
|
let prevSibling = nextChildren[nextChildren.length - 1];
|
|
40
44
|
if (isDemoNode(current)) {
|
|
41
45
|
nextChildren.push(current);
|
|
46
|
+
} else if (current.tagName === "p" && ((_a = current.children) == null ? void 0 : _a.length) === 1 && isReactComponent(current.children[0]) || isReactComponent(current)) {
|
|
47
|
+
nextChildren.push(current.tagName === "p" ? (_b = current.children) == null ? void 0 : _b[0] : current);
|
|
42
48
|
} else {
|
|
43
|
-
if (!prevSibling || isDemoNode(prevSibling)) {
|
|
49
|
+
if (!prevSibling || isDemoNode(prevSibling) || isReactComponent(prevSibling)) {
|
|
44
50
|
prevSibling = {
|
|
45
51
|
type: "element",
|
|
46
52
|
tagName: "div",
|
|
47
|
-
properties: { className: "markdown" },
|
|
53
|
+
properties: { className: ["markdown"] },
|
|
48
54
|
children: []
|
|
49
55
|
};
|
|
50
56
|
nextChildren.push(prevSibling);
|
|
@@ -35,7 +35,7 @@ var CODE_META_STUB_ATTR = "$code-meta";
|
|
|
35
35
|
({ raw } = await import("hast-util-raw"));
|
|
36
36
|
})();
|
|
37
37
|
function rehypeRaw() {
|
|
38
|
-
return (tree,
|
|
38
|
+
return (tree, vFile) => {
|
|
39
39
|
visit(tree, (node) => {
|
|
40
40
|
var _a;
|
|
41
41
|
if (node.type === "raw" && COMPONENT_NAME_REGEX.test(node.value)) {
|
|
@@ -48,7 +48,7 @@ function rehypeRaw() {
|
|
|
48
48
|
node.properties[CODE_META_STUB_ATTR] = node.data.meta;
|
|
49
49
|
}
|
|
50
50
|
});
|
|
51
|
-
const newTree = raw(tree,
|
|
51
|
+
const newTree = raw(tree, vFile);
|
|
52
52
|
visit(newTree, "element", (node) => {
|
|
53
53
|
var _a, _b;
|
|
54
54
|
if ((_a = node.properties) == null ? void 0 : _a[COMPONENT_STUB_ATTR]) {
|
|
@@ -0,0 +1,105 @@
|
|
|
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/rehypeSlug.ts
|
|
23
|
+
var rehypeSlug_exports = {};
|
|
24
|
+
__export(rehypeSlug_exports, {
|
|
25
|
+
default: () => rehypeSlug
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(rehypeSlug_exports);
|
|
28
|
+
var import_utils = require("../../../utils");
|
|
29
|
+
var import_fs = __toESM(require("fs"));
|
|
30
|
+
var import_github_slugger = __toESM(require("github-slugger"));
|
|
31
|
+
var import__ = __toESM(require("."));
|
|
32
|
+
var import_rehypeDemo = require("./rehypeDemo");
|
|
33
|
+
var import_rehypeEmbed = require("./rehypeEmbed");
|
|
34
|
+
var visit;
|
|
35
|
+
var toString;
|
|
36
|
+
var sharedSluggers = /* @__PURE__ */ new Map();
|
|
37
|
+
function getFileSlugger(fileAbsPath, parentAbsPath) {
|
|
38
|
+
if (parentAbsPath)
|
|
39
|
+
return sharedSluggers.get(parentAbsPath);
|
|
40
|
+
const slugger = new import_github_slugger.default();
|
|
41
|
+
sharedSluggers.set(fileAbsPath, slugger);
|
|
42
|
+
return slugger;
|
|
43
|
+
}
|
|
44
|
+
(async () => {
|
|
45
|
+
({ visit } = await import("unist-util-visit"));
|
|
46
|
+
({ toString } = await import("hast-util-to-string"));
|
|
47
|
+
})();
|
|
48
|
+
var HEADING_TAGS = ["h1", "h2", "h3", "h4", "h5", "h6"];
|
|
49
|
+
function rehypeSlug(opts) {
|
|
50
|
+
return async (tree, vFile) => {
|
|
51
|
+
const pathWithRandom = `${opts.fileAbsPath}?${Math.random()}`;
|
|
52
|
+
const slugger = getFileSlugger(pathWithRandom, opts.parentAbsPath);
|
|
53
|
+
const deferrers = [];
|
|
54
|
+
vFile.data.toc = [];
|
|
55
|
+
visit(tree, "element", (node) => {
|
|
56
|
+
var _a, _b, _c;
|
|
57
|
+
if (HEADING_TAGS.includes(node.tagName)) {
|
|
58
|
+
const title = toString(node);
|
|
59
|
+
const depth = Number(node.tagName.slice(1));
|
|
60
|
+
deferrers.push(() => {
|
|
61
|
+
const id = slugger.slug(title);
|
|
62
|
+
node.properties.id = id;
|
|
63
|
+
vFile.data.toc.push({ id, depth, title });
|
|
64
|
+
});
|
|
65
|
+
} else if (((_a = node.data) == null ? void 0 : _a.tagName) === import_rehypeEmbed.EMBED_TAG) {
|
|
66
|
+
const { fileAbsPath, query } = node.data;
|
|
67
|
+
let content = import_fs.default.readFileSync(fileAbsPath, "utf-8");
|
|
68
|
+
if (query.get("range")) {
|
|
69
|
+
content = (0, import_utils.getFileRangeLines)(content, query.get("range"));
|
|
70
|
+
} else if (query.get("regexp")) {
|
|
71
|
+
content = (0, import_utils.getFileContentByRegExp)(content, query.get("regexp"), fileAbsPath);
|
|
72
|
+
}
|
|
73
|
+
deferrers.push(async () => {
|
|
74
|
+
const {
|
|
75
|
+
meta: { toc }
|
|
76
|
+
} = await (0, import__.default)(content, {
|
|
77
|
+
...opts,
|
|
78
|
+
parentAbsPath: opts.parentAbsPath || pathWithRandom
|
|
79
|
+
});
|
|
80
|
+
vFile.data.toc.push(...toc);
|
|
81
|
+
});
|
|
82
|
+
} else if ([import_rehypeDemo.DUMI_DEMO_TAG, import_rehypeDemo.DUMI_DEMO_GRID_TAG].includes(node.tagName) && ((_b = node.data) == null ? void 0 : _b[import_rehypeDemo.DEMO_PROP_VALUE_KEY])) {
|
|
83
|
+
const demos = [].concat((_c = node.data) == null ? void 0 : _c[import_rehypeDemo.DEMO_PROP_VALUE_KEY]);
|
|
84
|
+
deferrers.push(() => {
|
|
85
|
+
demos.forEach(({ demo, previewerProps }) => {
|
|
86
|
+
var _a2, _b2;
|
|
87
|
+
if (!demo.inline && previewerProps.title) {
|
|
88
|
+
vFile.data.toc.push({
|
|
89
|
+
id: slugger.slug(demo.id),
|
|
90
|
+
depth: ((_b2 = (_a2 = vFile.data.frontmatter) == null ? void 0 : _a2.demo) == null ? void 0 : _b2.tocDepth) || 3,
|
|
91
|
+
title: previewerProps.title
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
for (let deferrer of deferrers) {
|
|
99
|
+
await deferrer();
|
|
100
|
+
}
|
|
101
|
+
sharedSluggers.delete(pathWithRandom);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import type { Root } from '
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
2
|
import type { Transformer } from 'unified';
|
|
3
|
-
export default function remarkMeta(
|
|
3
|
+
export default function remarkMeta(opts: {
|
|
4
|
+
fileAbsPath: string;
|
|
5
|
+
}): Transformer<Root>;
|