dumi 2.4.6 → 2.4.8-beta.1
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/client/theme-api/index.d.ts +1 -1
- package/dist/client/theme-api/index.js +1 -1
- package/dist/client/theme-api/types.d.ts +1 -1
- package/dist/client/theme-api/useRouteMeta.d.ts +12 -0
- package/dist/client/theme-api/useRouteMeta.js +12 -4
- package/dist/features/compile/index.js +0 -3
- package/dist/loaders/markdown/index.js +44 -8
- package/package.json +2 -2
- package/theme-default/locales/en-US.json +1 -0
- package/theme-default/locales/zh-CN.json +1 -0
- package/theme-default/slots/SocialIcon/index.js +3 -2
- package/theme-default/slots/SourceCodeEditor/index.js +2 -1
|
@@ -12,7 +12,7 @@ export { useLiveDemo } from './useLiveDemo';
|
|
|
12
12
|
export { useLocale } from './useLocale';
|
|
13
13
|
export { useNavData } from './useNavData';
|
|
14
14
|
export { usePrefersColor } from './usePrefersColor';
|
|
15
|
-
export { useRouteMeta } from './useRouteMeta';
|
|
15
|
+
export { useMatchedRoute, useRouteMeta } from './useRouteMeta';
|
|
16
16
|
export { useFullSidebarData, useSidebarData } from './useSidebarData';
|
|
17
17
|
export { useSiteSearch } from './useSiteSearch';
|
|
18
18
|
export { useTabMeta } from './useTabMeta';
|
|
@@ -11,7 +11,7 @@ export { useLiveDemo } from "./useLiveDemo";
|
|
|
11
11
|
export { useLocale } from "./useLocale";
|
|
12
12
|
export { useNavData } from "./useNavData";
|
|
13
13
|
export { usePrefersColor } from "./usePrefersColor";
|
|
14
|
-
export { useRouteMeta } from "./useRouteMeta";
|
|
14
|
+
export { useMatchedRoute, useRouteMeta } from "./useRouteMeta";
|
|
15
15
|
export { useFullSidebarData, useSidebarData } from "./useSidebarData";
|
|
16
16
|
export { useSiteSearch } from "./useSiteSearch";
|
|
17
17
|
export { useTabMeta } from "./useTabMeta";
|
|
@@ -174,7 +174,7 @@ export interface ISidebarGroup {
|
|
|
174
174
|
children: ISidebarItem[];
|
|
175
175
|
[key: string]: any;
|
|
176
176
|
}
|
|
177
|
-
export type SocialTypes = 'github' | 'weibo' | 'twitter' | 'gitlab' | 'facebook' | 'zhihu' | 'yuque' | 'linkedin';
|
|
177
|
+
export type SocialTypes = 'github' | 'weibo' | 'twitter' | 'x' | 'gitlab' | 'facebook' | 'zhihu' | 'yuque' | 'linkedin';
|
|
178
178
|
export type INavItems = (INavItem & {
|
|
179
179
|
children?: INavItem[];
|
|
180
180
|
})[];
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import type { IRouteMeta } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* hook for get matched route
|
|
4
|
+
* @internal internal use. Do not use in your production code.
|
|
5
|
+
*/
|
|
6
|
+
export declare const useMatchedRoute: () => {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
path?: string | undefined;
|
|
9
|
+
parentId?: string | undefined;
|
|
10
|
+
meta?: IRouteMeta | undefined;
|
|
11
|
+
id: string;
|
|
12
|
+
redirect?: string | undefined;
|
|
13
|
+
};
|
|
2
14
|
/**
|
|
3
15
|
* hook for get matched route meta
|
|
4
16
|
*/
|
|
@@ -73,9 +73,10 @@ function getCachedRouteMeta(route) {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* hook for get matched route
|
|
76
|
+
* hook for get matched route
|
|
77
|
+
* @internal internal use. Do not use in your production code.
|
|
77
78
|
*/
|
|
78
|
-
export var
|
|
79
|
+
export var useMatchedRoute = function useMatchedRoute() {
|
|
79
80
|
var _useRouteData = useRouteData(),
|
|
80
81
|
route = _useRouteData.route;
|
|
81
82
|
var _useLocation = useLocation(),
|
|
@@ -99,9 +100,16 @@ export var useRouteMeta = function useRouteMeta() {
|
|
|
99
100
|
_useState2 = _slicedToArray(_useState, 2),
|
|
100
101
|
matchedRoute = _useState2[0],
|
|
101
102
|
setMatchedRoute = _useState2[1];
|
|
102
|
-
var meta = getCachedRouteMeta(matchedRoute);
|
|
103
103
|
useIsomorphicLayoutEffect(function () {
|
|
104
104
|
setMatchedRoute(getter);
|
|
105
105
|
}, [clientRoutes.length, pathname]);
|
|
106
|
-
return
|
|
106
|
+
return matchedRoute;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* hook for get matched route meta
|
|
111
|
+
*/
|
|
112
|
+
export var useRouteMeta = function useRouteMeta() {
|
|
113
|
+
var route = useMatchedRoute();
|
|
114
|
+
return getCachedRouteMeta(route);
|
|
107
115
|
};
|
|
@@ -104,9 +104,6 @@ var compile_default = (api) => {
|
|
|
104
104
|
if (!babelInUmi)
|
|
105
105
|
return memo;
|
|
106
106
|
const loaderPath = require.resolve("../../loaders/markdown");
|
|
107
|
-
memo.resolve.byDependency.set("commonjs", {
|
|
108
|
-
conditionNames: ["require", "node", "import"]
|
|
109
|
-
});
|
|
110
107
|
const loaderBaseOpts = {
|
|
111
108
|
techStacks,
|
|
112
109
|
cwd: api.cwd,
|
|
@@ -49,6 +49,9 @@ function getDemoSourceFiles(demos = []) {
|
|
|
49
49
|
return ret;
|
|
50
50
|
}, []);
|
|
51
51
|
}
|
|
52
|
+
function isRelativePath(path2) {
|
|
53
|
+
return path2.startsWith("./") || path2.startsWith("../");
|
|
54
|
+
}
|
|
52
55
|
function emitDefault(opts, ret) {
|
|
53
56
|
const { frontmatter, demos } = ret.meta;
|
|
54
57
|
const isTabContent = (0, import_tabs.isTabRouteFile)(this.resourcePath);
|
|
@@ -89,9 +92,45 @@ export default DumiMarkdownContent;`;
|
|
|
89
92
|
}
|
|
90
93
|
function emitDemo(opts, ret) {
|
|
91
94
|
const { demos } = ret.meta;
|
|
95
|
+
const shareDepsMap = {};
|
|
96
|
+
const demoDepsMap = {};
|
|
97
|
+
demos == null ? void 0 : demos.forEach((demo) => {
|
|
98
|
+
var _a;
|
|
99
|
+
if ("resolveMap" in demo && "asset" in demo) {
|
|
100
|
+
const entryFileName = Object.keys(demo.asset.dependencies)[0];
|
|
101
|
+
demoDepsMap[_a = demo.id] ?? (demoDepsMap[_a] = {});
|
|
102
|
+
Object.keys(demo.resolveMap).forEach((key, index) => {
|
|
103
|
+
const specifier = `${demo.id.replace(/-/g, "_")}_deps_${index}`;
|
|
104
|
+
if (key !== entryFileName && !isRelativePath(key)) {
|
|
105
|
+
if (shareDepsMap[key]) {
|
|
106
|
+
demoDepsMap[demo.id][key] = shareDepsMap[key];
|
|
107
|
+
} else {
|
|
108
|
+
demoDepsMap[demo.id][key] = specifier;
|
|
109
|
+
shareDepsMap[key] = specifier;
|
|
110
|
+
}
|
|
111
|
+
} else if (isRelativePath(key)) {
|
|
112
|
+
demoDepsMap[demo.id][demo.resolveMap[key]] = specifier;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
const dedupedDemosDeps = Object.entries(demoDepsMap).reduce((acc, [, deps]) => {
|
|
118
|
+
return acc.concat(
|
|
119
|
+
Object.entries(deps).map(([key, specifier]) => {
|
|
120
|
+
const existingIndex = acc.findIndex((obj) => obj.key === key);
|
|
121
|
+
if (existingIndex === -1) {
|
|
122
|
+
return { key, specifier };
|
|
123
|
+
}
|
|
124
|
+
return void 0;
|
|
125
|
+
}).filter((item) => item !== void 0)
|
|
126
|
+
);
|
|
127
|
+
}, []);
|
|
92
128
|
return import_plugin_utils.Mustache.render(
|
|
93
129
|
`import React from 'react';
|
|
94
|
-
|
|
130
|
+
import '${(0, import_plugin_utils.winPath)(this.getDependencies()[0])}?watch=parent';
|
|
131
|
+
{{#dedupedDemosDeps}}
|
|
132
|
+
import * as {{{specifier}}} from '{{{key}}}';
|
|
133
|
+
{{/dedupedDemosDeps}}
|
|
95
134
|
export const demos = {
|
|
96
135
|
{{#demos}}
|
|
97
136
|
'{{{id}}}': {
|
|
@@ -106,6 +145,7 @@ export const demos = {
|
|
|
106
145
|
};`,
|
|
107
146
|
{
|
|
108
147
|
demos,
|
|
148
|
+
dedupedDemosDeps,
|
|
109
149
|
renderAsset: function renderAsset() {
|
|
110
150
|
if (!("asset" in this))
|
|
111
151
|
return "null";
|
|
@@ -127,14 +167,10 @@ export const demos = {
|
|
|
127
167
|
renderContext: function renderContext() {
|
|
128
168
|
if (!("resolveMap" in this) || !("asset" in this))
|
|
129
169
|
return "undefined";
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
(acc, [key, path2]) => ({
|
|
170
|
+
const context = Object.entries(demoDepsMap[this.id]).reduce(
|
|
171
|
+
(acc, [key, specifier]) => ({
|
|
133
172
|
...acc,
|
|
134
|
-
|
|
135
|
-
...key !== entryFileName ? {
|
|
136
|
-
[key]: `{{{require('${path2}')}}}`
|
|
137
|
-
} : {}
|
|
173
|
+
...{ [key]: `{{{${specifier}}}}` }
|
|
138
174
|
}),
|
|
139
175
|
{}
|
|
140
176
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dumi",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.8-beta.1",
|
|
4
4
|
"description": "📖 Documentation Generator of React Component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"generator",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
]
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@ant-design/icons-svg": "^4.2
|
|
62
|
+
"@ant-design/icons-svg": "^4.4.2",
|
|
63
63
|
"@makotot/ghostui": "^2.0.0",
|
|
64
64
|
"@stackblitz/sdk": "^1.9.0",
|
|
65
65
|
"@swc/core": "1.4.2",
|
|
@@ -2,8 +2,8 @@ import { ReactComponent as IconFacebook } from '@ant-design/icons-svg/inline-svg
|
|
|
2
2
|
import { ReactComponent as IconGitHub } from '@ant-design/icons-svg/inline-svg/outlined/github.svg';
|
|
3
3
|
import { ReactComponent as IconGitlab } from '@ant-design/icons-svg/inline-svg/outlined/gitlab.svg';
|
|
4
4
|
import { ReactComponent as IconLinkedin } from '@ant-design/icons-svg/inline-svg/outlined/linkedin.svg';
|
|
5
|
-
import { ReactComponent as IconTwitter } from '@ant-design/icons-svg/inline-svg/outlined/twitter.svg';
|
|
6
5
|
import { ReactComponent as IconWeiBo } from '@ant-design/icons-svg/inline-svg/outlined/weibo.svg';
|
|
6
|
+
import { ReactComponent as IconX } from '@ant-design/icons-svg/inline-svg/outlined/x.svg';
|
|
7
7
|
import { ReactComponent as IconYuque } from '@ant-design/icons-svg/inline-svg/outlined/yuque.svg';
|
|
8
8
|
import { ReactComponent as IconZhihu } from '@ant-design/icons-svg/inline-svg/outlined/zhihu.svg';
|
|
9
9
|
import React, { useMemo } from 'react';
|
|
@@ -12,7 +12,8 @@ import "./index.less";
|
|
|
12
12
|
var presetIconMap = {
|
|
13
13
|
github: IconGitHub,
|
|
14
14
|
weibo: IconWeiBo,
|
|
15
|
-
twitter:
|
|
15
|
+
twitter: IconX,
|
|
16
|
+
x: IconX,
|
|
16
17
|
gitlab: IconGitlab,
|
|
17
18
|
facebook: IconFacebook,
|
|
18
19
|
zhihu: IconZhihu,
|