dumi 2.1.9 → 2.1.11
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/types.d.ts +22 -5
- package/dist/client/theme-api/useNavData.d.ts +2 -3
- package/dist/client/theme-api/useNavData.js +29 -4
- package/dist/client/theme-api/utils.d.ts +4 -3
- package/dist/client/theme-api/utils.js +4 -1
- package/dist/features/compile/index.js +1 -1
- package/dist/features/derivative.js +7 -0
- package/dist/features/tabs.d.ts +1 -0
- package/dist/features/tabs.js +5 -0
- package/dist/features/theme/index.js +16 -2
- package/dist/loaders/markdown/index.js +2 -0
- package/dist/loaders/markdown/transformer/index.d.ts +1 -1
- package/dist/loaders/markdown/transformer/index.js +1 -1
- package/dist/loaders/markdown/transformer/rehypeDemo.js +11 -6
- package/dist/loaders/markdown/transformer/rehypeLink.d.ts +1 -1
- package/dist/loaders/markdown/transformer/rehypeLink.js +18 -5
- package/dist/types.d.ts +5 -0
- package/package.json +1 -1
- package/theme-default/builtins/API/index.js +114 -7
|
@@ -160,14 +160,31 @@ export interface ISidebarGroup {
|
|
|
160
160
|
[key: string]: any;
|
|
161
161
|
}
|
|
162
162
|
export declare type SocialTypes = 'github' | 'weibo' | 'twitter' | 'gitlab' | 'facebook' | 'zhihu' | 'yuque' | 'linkedin';
|
|
163
|
+
export declare type INavItems = (INavItem & {
|
|
164
|
+
children?: INavItem[];
|
|
165
|
+
})[];
|
|
166
|
+
export declare type INav = INavItems | Record<string, INavItems>;
|
|
167
|
+
declare type IUserNavItem = Pick<INavItem, 'title' | 'link'>;
|
|
168
|
+
export declare type IUserNavMode = 'override' | 'append' | 'prepend';
|
|
169
|
+
export declare type IUserNavItems = (IUserNavItem & {
|
|
170
|
+
children?: IUserNavItem[];
|
|
171
|
+
})[];
|
|
172
|
+
export declare type IUserNavValue = IUserNavItems | Record<string, IUserNavItems>;
|
|
173
|
+
export declare type NavWithMode<T extends IUserNavValue> = {
|
|
174
|
+
/**
|
|
175
|
+
* 扩展导航的模式
|
|
176
|
+
* @description
|
|
177
|
+
* - 'override': 用 value 中配置的导航直接覆盖约定路由的导航
|
|
178
|
+
* - 'append': 将 value 中配置的导航追加到约定路由导航后面
|
|
179
|
+
* - 'prepend': 将 value 中配置的导航添加到约定路由导航前面
|
|
180
|
+
*/
|
|
181
|
+
mode: IUserNavMode;
|
|
182
|
+
value: T;
|
|
183
|
+
};
|
|
163
184
|
export interface IThemeConfig {
|
|
164
185
|
name?: string;
|
|
165
186
|
logo?: string | false;
|
|
166
|
-
nav?:
|
|
167
|
-
children?: INavItem[];
|
|
168
|
-
})[] | Record<string, (INavItem & {
|
|
169
|
-
children?: INavItem[];
|
|
170
|
-
})[]>;
|
|
187
|
+
nav?: IUserNavValue | NavWithMode<IUserNavValue>;
|
|
171
188
|
sidebar?: Record<string, ISidebarGroup[]>;
|
|
172
189
|
footer?: string | false;
|
|
173
190
|
prefersColor: {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import type { IUserNavItems } from './types';
|
|
1
2
|
/**
|
|
2
3
|
* hook for get nav data
|
|
3
4
|
*/
|
|
4
|
-
export declare const useNavData: () =>
|
|
5
|
-
children?: import("./types").INavItem[] | undefined;
|
|
6
|
-
})[];
|
|
5
|
+
export declare const useNavData: () => IUserNavItems;
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
|
|
7
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
8
|
+
|
|
1
9
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
10
|
|
|
3
11
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -12,7 +20,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
12
20
|
|
|
13
21
|
import { useFullSidebarData, useLocale, useSiteData } from 'dumi';
|
|
14
22
|
import { useState } from 'react';
|
|
15
|
-
import { pickRouteSortMeta, useLocaleDocRoutes, useRouteDataComparer } from "./utils";
|
|
23
|
+
import { getLocaleNav, pickRouteSortMeta, useLocaleDocRoutes, useRouteDataComparer } from "./utils";
|
|
16
24
|
|
|
17
25
|
/**
|
|
18
26
|
* hook for get nav data
|
|
@@ -29,7 +37,22 @@ export var useNavData = function useNavData() {
|
|
|
29
37
|
|
|
30
38
|
var _useState = useState(function () {
|
|
31
39
|
// use user config first
|
|
32
|
-
|
|
40
|
+
var userNavValue = [];
|
|
41
|
+
var mode;
|
|
42
|
+
|
|
43
|
+
if (themeConfig.nav) {
|
|
44
|
+
// 形如:{mode: "append", value: []}
|
|
45
|
+
if ('mode' in themeConfig.nav && typeof themeConfig.nav.mode === 'string') {
|
|
46
|
+
mode = themeConfig.nav.mode;
|
|
47
|
+
userNavValue = getLocaleNav(themeConfig.nav.value, locale);
|
|
48
|
+
} else if (!('mode' in themeConfig.nav)) {
|
|
49
|
+
// 形如:[] 或 {"zh-CN": []}
|
|
50
|
+
userNavValue = getLocaleNav(themeConfig.nav, locale);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!mode || mode === 'override') return userNavValue;
|
|
54
|
+
} // fallback to generate nav data from sidebar data
|
|
55
|
+
|
|
33
56
|
|
|
34
57
|
var data = Object.entries(sidebar).map(function (_ref) {
|
|
35
58
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
@@ -50,9 +73,11 @@ export var useNavData = function useNavData() {
|
|
|
50
73
|
link: groups[0].children[0].link,
|
|
51
74
|
activePath: link
|
|
52
75
|
};
|
|
53
|
-
});
|
|
76
|
+
});
|
|
77
|
+
data.sort(sidebarDataComparer); // TODO: 2-level nav data
|
|
54
78
|
|
|
55
|
-
|
|
79
|
+
if (mode === 'prepend') data.unshift.apply(data, _toConsumableArray(userNavValue));else if (mode === 'append') data.push.apply(data, _toConsumableArray(userNavValue));
|
|
80
|
+
return data;
|
|
56
81
|
}),
|
|
57
82
|
_useState2 = _slicedToArray(_useState, 1),
|
|
58
83
|
nav = _useState2[0];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { INavItem, IRouteMeta, IRoutesById } from './types';
|
|
1
|
+
import { useLayoutEffect } from 'react';
|
|
2
|
+
import type { ILocale, INav, INavItem, IRouteMeta, IRoutesById, IUserNavValue } from './types';
|
|
3
3
|
export declare const useLocaleDocRoutes: () => IRoutesById;
|
|
4
4
|
/**
|
|
5
5
|
* 在 react 18 中需要新的 render 方式,这个函数用来处理不同的 jsx 模式。
|
|
@@ -7,7 +7,7 @@ export declare const useLocaleDocRoutes: () => IRoutesById;
|
|
|
7
7
|
* @returns code string
|
|
8
8
|
*/
|
|
9
9
|
export declare const genReactRenderCode: (version: string) => string;
|
|
10
|
-
export declare const useIsomorphicLayoutEffect: typeof
|
|
10
|
+
export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
|
|
11
11
|
/**
|
|
12
12
|
* common comparer for sidebar/nav items
|
|
13
13
|
*/
|
|
@@ -21,3 +21,4 @@ export declare const useRouteDataComparer: <T extends {
|
|
|
21
21
|
* common util for pick meta to sort sidebar/nav items
|
|
22
22
|
*/
|
|
23
23
|
export declare const pickRouteSortMeta: (original: Partial<Pick<INavItem, 'order' | 'title'>>, field: 'nav' | 'group', fm: IRouteMeta['frontmatter']) => Partial<Pick<INavItem, "title" | "order">>;
|
|
24
|
+
export declare function getLocaleNav(nav: IUserNavValue | INav, locale: ILocale): import("./types").IUserNavItems;
|
|
@@ -55,7 +55,7 @@ var compile_default = (api) => {
|
|
|
55
55
|
resolve: api.config.resolve,
|
|
56
56
|
extraRemarkPlugins: api.config.extraRemarkPlugins,
|
|
57
57
|
extraRehypePlugins: api.config.extraRehypePlugins,
|
|
58
|
-
|
|
58
|
+
routes: api.appData.routes
|
|
59
59
|
};
|
|
60
60
|
memo.module.rule("dumi-md").type("javascript/auto").test(/\.md$/).oneOf("md-meta").resourceQuery(/meta$/).use("babel-loader").loader(babelInUmi.loader).options(babelInUmi.options).end().use("md-meta-loader").loader(loaderPath).options({
|
|
61
61
|
...loaderBaseOpts,
|
|
@@ -60,6 +60,13 @@ var derivative_default = (api) => {
|
|
|
60
60
|
if (((_b = api.userConfig.history) == null ? void 0 : _b.type) === "hash") {
|
|
61
61
|
import_plugin_utils.logger.warn("Hash history is temporarily incompatible, it is recommended to use browser history for now.");
|
|
62
62
|
}
|
|
63
|
+
const { themeConfig } = api.config;
|
|
64
|
+
if (themeConfig == null ? void 0 : themeConfig.nav) {
|
|
65
|
+
const hasOrder = !!JSON.stringify(themeConfig.nav).includes('"order":');
|
|
66
|
+
if (hasOrder) {
|
|
67
|
+
import_plugin_utils.logger.warn(`\`order\` is deprecated in \`themeConfig.nav\`, you can order them directly in config`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
63
70
|
try {
|
|
64
71
|
const tsconfig = require(import_path.default.join(api.cwd, "tsconfig.json"));
|
|
65
72
|
const expected = [".dumi/**/*"];
|
package/dist/features/tabs.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export interface IContentTab {
|
|
|
9
9
|
}
|
|
10
10
|
export declare function isTabRouteFile(file: string): boolean;
|
|
11
11
|
export declare function getTabKeyFromFile(file: string): string;
|
|
12
|
+
export declare function getHostForTabRouteFile(file: string): string;
|
|
12
13
|
/**
|
|
13
14
|
* plugin for add conventional tab and plugin tab into page content
|
|
14
15
|
*/
|
package/dist/features/tabs.js
CHANGED
|
@@ -23,6 +23,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
23
23
|
var tabs_exports = {};
|
|
24
24
|
__export(tabs_exports, {
|
|
25
25
|
default: () => tabs_default,
|
|
26
|
+
getHostForTabRouteFile: () => getHostForTabRouteFile,
|
|
26
27
|
getTabKeyFromFile: () => getTabKeyFromFile,
|
|
27
28
|
isTabRouteFile: () => isTabRouteFile
|
|
28
29
|
});
|
|
@@ -37,6 +38,9 @@ function isTabRouteFile(file) {
|
|
|
37
38
|
function getTabKeyFromFile(file) {
|
|
38
39
|
return file.match(/\$tab-([^.]+)/)[1];
|
|
39
40
|
}
|
|
41
|
+
function getHostForTabRouteFile(file) {
|
|
42
|
+
return file.replace(/\$tab-[^.]+\./, "");
|
|
43
|
+
}
|
|
40
44
|
var tabs_default = (api) => {
|
|
41
45
|
let tabsFromPlugins;
|
|
42
46
|
const routesTabMapping = {};
|
|
@@ -132,6 +136,7 @@ export const tabs = {
|
|
|
132
136
|
};
|
|
133
137
|
// Annotate the CommonJS export names for ESM import in node:
|
|
134
138
|
0 && (module.exports = {
|
|
139
|
+
getHostForTabRouteFile,
|
|
135
140
|
getTabKeyFromFile,
|
|
136
141
|
isTabRouteFile
|
|
137
142
|
});
|
|
@@ -115,8 +115,22 @@ var theme_default = (api) => {
|
|
|
115
115
|
memo.alias["dumi/theme-default"] = DEFAULT_THEME_PATH;
|
|
116
116
|
memo.extraBabelIncludes ?? (memo.extraBabelIncludes = []);
|
|
117
117
|
memo.extraBabelIncludes.push(import_path.default.resolve(__dirname, "../../client/theme-api"));
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
return memo;
|
|
119
|
+
});
|
|
120
|
+
api.chainWebpack((memo) => {
|
|
121
|
+
const lessRule = memo.module.rule("less");
|
|
122
|
+
["css", "css-modules"].forEach((rule) => {
|
|
123
|
+
Object.values(lessRule.oneOf(rule).uses.entries()).forEach((loader) => {
|
|
124
|
+
if (loader.get("loader").includes("less-loader")) {
|
|
125
|
+
loader.tap((opts) => {
|
|
126
|
+
var _a;
|
|
127
|
+
(_a = opts.lessOptions).modifyVars ?? (_a.modifyVars = {});
|
|
128
|
+
opts.lessOptions.modifyVars["dark-selector"] = `~'[${import_constants.PREFERS_COLOR_ATTR}="dark"]'`;
|
|
129
|
+
return opts;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
120
134
|
return memo;
|
|
121
135
|
});
|
|
122
136
|
api.onGenerateFiles(() => {
|
|
@@ -75,6 +75,8 @@ export const texts = {{{texts}}};
|
|
|
75
75
|
let { asset } = this;
|
|
76
76
|
const { sources } = this;
|
|
77
77
|
Object.keys(this.sources).forEach((file) => {
|
|
78
|
+
if (!asset.dependencies[file])
|
|
79
|
+
return;
|
|
78
80
|
asset = import_plugin_utils.lodash.cloneDeep(asset);
|
|
79
81
|
asset.dependencies[file].value = `{{{require('-!${sources[file]}?dumi-raw').default}}}`;
|
|
80
82
|
});
|
|
@@ -41,7 +41,7 @@ export interface IMdTransformerOptions {
|
|
|
41
41
|
resolve: IDumiConfig['resolve'];
|
|
42
42
|
extraRemarkPlugins?: IDumiConfig['extraRemarkPlugins'];
|
|
43
43
|
extraRehypePlugins?: IDumiConfig['extraRehypePlugins'];
|
|
44
|
-
|
|
44
|
+
routes: Record<string, IRoute>;
|
|
45
45
|
}
|
|
46
46
|
export interface IMdTransformerResult {
|
|
47
47
|
content: string;
|
|
@@ -81,7 +81,7 @@ var transformer_default = async (raw, opts) => {
|
|
|
81
81
|
resolver
|
|
82
82
|
}).use(import_rehypeSlug.default).use(import_rehypeLink.default, {
|
|
83
83
|
fileAbsPath: opts.fileAbsPath,
|
|
84
|
-
|
|
84
|
+
routes: opts.routes
|
|
85
85
|
}).use(rehypeAutolinkHeadings).use(import_rehypeIsolation.default).use(import_rehypeEnhancedTag.default).use(import_rehypeDesc.default).use(import_rehypeText.default);
|
|
86
86
|
(_b = opts.extraRehypePlugins) == null ? void 0 : _b.forEach((plugin) => applyUnifiedPlugin({
|
|
87
87
|
plugin,
|
|
@@ -100,13 +100,18 @@ function rehypeDemo(opts) {
|
|
|
100
100
|
if (isFirstChild) {
|
|
101
101
|
node.data ?? (node.data = {});
|
|
102
102
|
node.data[DEMO_NODE_CONTAINER] = true;
|
|
103
|
-
while (nextChild && (isElement(nextChild, "code") && tryMarkDemoNode(nextChild, opts) || isElement(nextChild, "br"))) {
|
|
104
|
-
splitFrom += 1;
|
|
105
|
-
nextChildIndex = splitFrom + 1;
|
|
106
|
-
nextChild = node.children[nextChildIndex];
|
|
107
|
-
}
|
|
108
103
|
if (!nextChild)
|
|
109
104
|
return SKIP;
|
|
105
|
+
while (nextChild) {
|
|
106
|
+
if (isElement(nextChild, "code") && tryMarkDemoNode(nextChild, opts) || isElement(nextChild, "br")) {
|
|
107
|
+
splitFrom += 1;
|
|
108
|
+
nextChildIndex = splitFrom + 1;
|
|
109
|
+
nextChild = node.children[nextChildIndex];
|
|
110
|
+
} else {
|
|
111
|
+
splitFrom += 1;
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
110
115
|
}
|
|
111
116
|
const splitChildren = node.children.splice(splitFrom);
|
|
112
117
|
parent.children.splice(nodeIndex + 1, 0, {
|
|
@@ -203,7 +208,7 @@ function rehypeDemo(opts) {
|
|
|
203
208
|
id: asset.id,
|
|
204
209
|
component,
|
|
205
210
|
asset: techStack.generateMetadata ? await techStack.generateMetadata(asset, techStackOpts) : asset,
|
|
206
|
-
sources
|
|
211
|
+
sources: techStack.generateSources ? await techStack.generateSources(sources, techStackOpts) : sources
|
|
207
212
|
};
|
|
208
213
|
}));
|
|
209
214
|
demosPropData.push({
|
|
@@ -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 IRehypeLinkOptions = Pick<IMdTransformerOptions, 'fileAbsPath' | '
|
|
4
|
+
declare type IRehypeLinkOptions = Pick<IMdTransformerOptions, 'fileAbsPath' | 'routes'>;
|
|
5
5
|
export default function rehypeLink(opts: IRehypeLinkOptions): Transformer<Root>;
|
|
6
6
|
export {};
|
|
@@ -25,6 +25,7 @@ __export(rehypeLink_exports, {
|
|
|
25
25
|
default: () => rehypeLink
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(rehypeLink_exports);
|
|
28
|
+
var import_tabs = require("../../../features/tabs");
|
|
28
29
|
var import_path = __toESM(require("path"));
|
|
29
30
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
30
31
|
var import_url = __toESM(require("url"));
|
|
@@ -40,16 +41,28 @@ function rehypeLink(opts) {
|
|
|
40
41
|
if (node.tagName === "a" && typeof ((_a = node.properties) == null ? void 0 : _a.href) === "string") {
|
|
41
42
|
const href = node.properties.href;
|
|
42
43
|
const parsedUrl = import_url.default.parse(href);
|
|
44
|
+
const hostAbsPath = (0, import_tabs.getHostForTabRouteFile)(opts.fileAbsPath);
|
|
43
45
|
if (parsedUrl.hostname)
|
|
44
46
|
return SKIP;
|
|
45
47
|
if (/\.md$/i.test(parsedUrl.pathname)) {
|
|
46
|
-
const {
|
|
47
|
-
const absPath = (0, import_plugin_utils.winPath)(import_path.default.resolve(
|
|
48
|
-
Object.keys(
|
|
49
|
-
if (
|
|
50
|
-
parsedUrl.pathname =
|
|
48
|
+
const { routes } = opts;
|
|
49
|
+
const absPath = (0, import_plugin_utils.winPath)(import_path.default.resolve(hostAbsPath, "..", parsedUrl.pathname));
|
|
50
|
+
Object.keys(routes).forEach((key) => {
|
|
51
|
+
if (routes[key].file === absPath) {
|
|
52
|
+
parsedUrl.pathname = routes[key].absPath;
|
|
51
53
|
}
|
|
52
54
|
});
|
|
55
|
+
} else if (/^\.?\.\//.test(parsedUrl.pathname) || /^(\w+:)?\/\//.test(parsedUrl.pathname)) {
|
|
56
|
+
const routes = Object.values(opts.routes);
|
|
57
|
+
const basePath = routes.find((route) => route.file === hostAbsPath).absPath;
|
|
58
|
+
const htmlTargetPath = import_url.default.resolve(basePath, parsedUrl.pathname);
|
|
59
|
+
const rr6TargetPath = (0, import_plugin_utils.winPath)(import_path.default.resolve(basePath, parsedUrl.pathname));
|
|
60
|
+
parsedUrl.pathname = htmlTargetPath;
|
|
61
|
+
if (routes.every((route) => route.absPath !== htmlTargetPath) && routes.some((route) => route.absPath === rr6TargetPath)) {
|
|
62
|
+
parsedUrl.pathname = rr6TargetPath;
|
|
63
|
+
import_plugin_utils.logger.warn(`Detected ambiguous link \`${href}\` in \`${opts.fileAbsPath}\`, please use \`./xxx.md\` file path instead of normal relative path, dumi will deprecate this behavior in the future.
|
|
64
|
+
See more: https://github.com/umijs/dumi/pull/1491`);
|
|
65
|
+
}
|
|
53
66
|
}
|
|
54
67
|
parent.children.splice(i, 1, {
|
|
55
68
|
type: "element",
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type AtomAssetsParser from "./assetParsers/atom";
|
|
2
|
+
import type { IParsedBlockAsset } from "./assetParsers/block";
|
|
2
3
|
import type { IDumiDemoProps } from "./client/theme-api/DumiDemo";
|
|
3
4
|
import type { ILocalesConfig, IThemeConfig } from "./client/theme-api/types";
|
|
4
5
|
import type { IContentTab } from "./features/tabs";
|
|
@@ -82,6 +83,10 @@ export declare abstract class IDumiTechStack {
|
|
|
82
83
|
* generator for return previewer props
|
|
83
84
|
*/
|
|
84
85
|
abstract generatePreviewerProps?(props: IDumiDemoProps['previewerProps'], opts: Parameters<NonNullable<IDumiTechStack['generateMetadata']>>[1]): Promise<IDumiDemoProps['previewerProps']> | IDumiDemoProps['previewerProps'];
|
|
86
|
+
/**
|
|
87
|
+
* generator for return file path of demo sources
|
|
88
|
+
*/
|
|
89
|
+
abstract generateSources?(sources: IParsedBlockAsset['sources'], opts: Parameters<NonNullable<IDumiTechStack['generateMetadata']>>[1]): Promise<IParsedBlockAsset['sources']> | IParsedBlockAsset['sources'];
|
|
85
90
|
}
|
|
86
91
|
export declare type IApi = IUmiApi & {
|
|
87
92
|
config: IDumiConfig & {
|
package/package.json
CHANGED
|
@@ -11,8 +11,115 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
11
11
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
12
|
|
|
13
13
|
import { useAtomAssets, useIntl, useRouteMeta } from 'dumi';
|
|
14
|
-
import React from 'react';
|
|
14
|
+
import React, { useEffect, useState } from 'react';
|
|
15
15
|
import Table from "../Table";
|
|
16
|
+
var HANDLERS = {
|
|
17
|
+
// entry method
|
|
18
|
+
toString: function toString(prop) {
|
|
19
|
+
if (typeof prop.type === 'string' && prop.type in this) {
|
|
20
|
+
// value from TypeMap
|
|
21
|
+
if ('enum' in prop) return this.enum(prop);
|
|
22
|
+
return this[prop.type](prop);
|
|
23
|
+
} else if (prop.type) {
|
|
24
|
+
// non-parsed type, such as ReactNode
|
|
25
|
+
return this.getValidClassName(prop) || prop.type;
|
|
26
|
+
} else if ('const' in prop) {
|
|
27
|
+
// const value
|
|
28
|
+
return prop.const;
|
|
29
|
+
} else if ('oneOf' in prop) {
|
|
30
|
+
// oneOf value
|
|
31
|
+
return this.oneOf(prop);
|
|
32
|
+
} // unknown type
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
return "unknown";
|
|
36
|
+
},
|
|
37
|
+
// type handlers
|
|
38
|
+
string: function string(prop) {
|
|
39
|
+
return prop.type;
|
|
40
|
+
},
|
|
41
|
+
number: function number(prop) {
|
|
42
|
+
return prop.type;
|
|
43
|
+
},
|
|
44
|
+
boolean: function boolean(prop) {
|
|
45
|
+
return prop.type;
|
|
46
|
+
},
|
|
47
|
+
any: function any(prop) {
|
|
48
|
+
return prop.type;
|
|
49
|
+
},
|
|
50
|
+
object: function object(prop) {
|
|
51
|
+
var _this = this;
|
|
52
|
+
|
|
53
|
+
var props = [];
|
|
54
|
+
Object.entries(prop.properties || {}).forEach(function (_ref) {
|
|
55
|
+
var _prop$required;
|
|
56
|
+
|
|
57
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
58
|
+
key = _ref2[0],
|
|
59
|
+
value = _ref2[1];
|
|
60
|
+
|
|
61
|
+
// skip nested object type
|
|
62
|
+
props.push("".concat(key).concat((_prop$required = prop.required) !== null && _prop$required !== void 0 && _prop$required.includes(key) ? '' : '?', ": ").concat(value.type === 'object' ? 'object' : _this.toString(value)));
|
|
63
|
+
});
|
|
64
|
+
return props.length ? "{ ".concat(props.join('; '), " }") : '{}';
|
|
65
|
+
},
|
|
66
|
+
array: function array(prop) {
|
|
67
|
+
if (prop.items) {
|
|
68
|
+
var className = this.getValidClassName(prop.items);
|
|
69
|
+
return className ? "".concat(className, "[]") : "".concat(this.toString(prop.items), "[]");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return 'any[]';
|
|
73
|
+
},
|
|
74
|
+
// FIXME: extract real type
|
|
75
|
+
element: function element(prop) {
|
|
76
|
+
return "<".concat(prop.componentName, " />");
|
|
77
|
+
},
|
|
78
|
+
// FIXME: extract real type
|
|
79
|
+
function: function _function(_ref3) {
|
|
80
|
+
var _this2 = this;
|
|
81
|
+
|
|
82
|
+
var signature = _ref3.signature;
|
|
83
|
+
return "".concat(signature.isAsync ? 'async ' : '', "(").concat(signature.arguments.map(function (arg) {
|
|
84
|
+
return "".concat(arg.key, ": ").concat(_this2.toString(arg));
|
|
85
|
+
}).join(', '), ") => ").concat(this.toString(signature.returnType));
|
|
86
|
+
},
|
|
87
|
+
// FIXME: extract real type
|
|
88
|
+
dom: function dom(prop) {
|
|
89
|
+
return "<".concat(prop.$$__body.id, " />");
|
|
90
|
+
},
|
|
91
|
+
// special handlers
|
|
92
|
+
enum: function _enum(prop) {
|
|
93
|
+
return prop.enum.map(function (v) {
|
|
94
|
+
return JSON.stringify(v);
|
|
95
|
+
}).join(' | ');
|
|
96
|
+
},
|
|
97
|
+
oneOf: function oneOf(prop) {
|
|
98
|
+
var _this3 = this;
|
|
99
|
+
|
|
100
|
+
return prop.oneOf.map(function (v) {
|
|
101
|
+
return _this3.getValidClassName(v) || _this3.toString(v);
|
|
102
|
+
}).join(' | ');
|
|
103
|
+
},
|
|
104
|
+
// utils
|
|
105
|
+
getValidClassName: function getValidClassName(prop) {
|
|
106
|
+
return 'className' in prop && typeof prop.className === 'string' && prop.className !== '__type' ? prop.className : null;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
var APIType = function APIType(prop) {
|
|
111
|
+
var _useState = useState(function () {
|
|
112
|
+
return HANDLERS.toString(prop);
|
|
113
|
+
}),
|
|
114
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
115
|
+
type = _useState2[0],
|
|
116
|
+
setType = _useState2[1];
|
|
117
|
+
|
|
118
|
+
useEffect(function () {
|
|
119
|
+
setType(HANDLERS.toString(prop));
|
|
120
|
+
}, [prop]);
|
|
121
|
+
return /*#__PURE__*/React.createElement("code", null, type);
|
|
122
|
+
};
|
|
16
123
|
|
|
17
124
|
var API = function API(props) {
|
|
18
125
|
var _definition$propsConf;
|
|
@@ -37,18 +144,18 @@ var API = function API(props) {
|
|
|
37
144
|
id: 'api.component.type'
|
|
38
145
|
})), /*#__PURE__*/React.createElement("th", null, intl.formatMessage({
|
|
39
146
|
id: 'api.component.default'
|
|
40
|
-
})))), /*#__PURE__*/React.createElement("tbody", null, definition && (_definition$propsConf = definition.propsConfig) !== null && _definition$propsConf !== void 0 && _definition$propsConf.properties ? Object.entries(definition.propsConfig.properties).map(function (
|
|
147
|
+
})))), /*#__PURE__*/React.createElement("tbody", null, definition && (_definition$propsConf = definition.propsConfig) !== null && _definition$propsConf !== void 0 && _definition$propsConf.properties ? Object.entries(definition.propsConfig.properties).map(function (_ref4) {
|
|
41
148
|
var _definition$propsConf2;
|
|
42
149
|
|
|
43
|
-
var
|
|
44
|
-
name =
|
|
45
|
-
prop =
|
|
150
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
|
151
|
+
name = _ref5[0],
|
|
152
|
+
prop = _ref5[1];
|
|
46
153
|
|
|
47
154
|
return /*#__PURE__*/React.createElement("tr", {
|
|
48
155
|
key: name
|
|
49
|
-
}, /*#__PURE__*/React.createElement("td", null, name), /*#__PURE__*/React.createElement("td", null, prop.description || '--'), /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement(
|
|
156
|
+
}, /*#__PURE__*/React.createElement("td", null, name), /*#__PURE__*/React.createElement("td", null, prop.description || '--'), /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement(APIType, prop)), /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement("code", null, (_definition$propsConf2 = definition.propsConfig.required) !== null && _definition$propsConf2 !== void 0 && _definition$propsConf2.includes(name) ? intl.formatMessage({
|
|
50
157
|
id: 'api.component.required'
|
|
51
|
-
}) : prop.default || '--')));
|
|
158
|
+
}) : JSON.stringify(prop.default) || '--')));
|
|
52
159
|
}) : /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("td", {
|
|
53
160
|
colSpan: 4
|
|
54
161
|
}, intl.formatMessage({
|